[GIL] About `packed_channel_value` (possible improvement)

Hi, I took a look into "channel.hpp" and found that packed_channel_value is not very efficient in construction. There are: packed_channel_value(integer_t v) { _value = static_cast< integer_t >( v % num_values ); } // I have no idea why this exists, seems OK to remove it template <typename Scalar> packed_channel_value(Scalar v) { _value = static_cast< integer_t >( v ) % num_values; } IIUC, "v % num_values" above could be replaced with a much cheaper "v & low_bits_mask_t<NumBits>::sig_bits_fast". That is: packed_channel_value(integer_t v) : _value(v & low_bits_mask_t<NumBits>::sig_bits_fast) {} What do you think? Am I missing some point? Thanks.

Hi,
packed_channel_value(integer_t v) { _value = static_cast< integer_t >( v % num_values ); }
// I have no idea why this exists, seems OK to remove it template <typename Scalar> packed_channel_value(Scalar v) { _value = static_cast< integer_t >( v ) % num_values; }
I always thought we need that but some testing shows it's not needed. I'll remove it.
IIUC, "v % num_values" above could be replaced with a much cheaper "v & low_bits_mask_t<NumBits>::sig_bits_fast". That is:
packed_channel_value(integer_t v) : _value(v & low_bits_mask_t<NumBits>::sig_bits_fast) {}
What do you think? Am I missing some point?
I think, you're correct and I always wondered why we need num_values and num_value_t. I think it's obsolete and might have been created before low_bits_mask_t was available or the developers didn't knew about it. In any event I'll update the trunk later. First I wanna make sure the gil tests run through. Please let me know if you find any more redundancies. I'm happy to fix that. Thanks again, Christian

Hi,
// I have no idea why this exists, seems OK to remove it template <typename Scalar> packed_channel_value(Scalar v) { _value = static_cast< integer_t >( v ) % num_values; }
I always thought we need that but some testing shows it's not needed. I'll remove it.
Turns out this function is needed. For instance in channel_algorithm.hpp[449]. I'll leave it in for now. Christian

On Wed, Feb 13, 2013 at 6:13 PM, Christian Henning
Hi,
// I have no idea why this exists, seems OK to remove it template <typename Scalar> packed_channel_value(Scalar v) { _value = static_cast< integer_t >( v ) % num_values; }
I have uploaded the revised packed_channel_value class. Please have a look when you get a chance. Thanks, Christian

2013/2/15 Christian Henning
On Wed, Feb 13, 2013 at 6:13 PM, Christian Henning
wrote: Hi,
// I have no idea why this exists, seems OK to remove it template <typename Scalar> packed_channel_value(Scalar v) { _value
=
static_cast< integer_t >( v ) % num_values; }
I have uploaded the revised packed_channel_value class. Please have a look when you get a chance.
Ah, too bad, I just edited the file to get it work w/o that overload... Ok, I'll check it now. Thanks

Hi Christian,
2013/2/15 TONGARI
2013/2/15 Christian Henning
On Wed, Feb 13, 2013 at 6:13 PM, Christian Henning
wrote: Hi,
// I have no idea why this exists, seems OK to remove it template <typename Scalar> packed_channel_value(Scalar v) {
_value =
static_cast< integer_t >( v ) % num_values; }
I have uploaded the revised packed_channel_value class. Please have a look when you get a chance.
Ah, too bad, I just edited the file to get it work w/o that overload... Ok, I'll check it now.
Seems you haven't made any change to `channel.hpp`. Here's my patch for some possible improvement with care of not breaking the current API., I only tested the testcase `channel.cpp`. If you find any flaw or improper, please let me know. Thanks

2013/2/15 TONGARI
Hi Christian,
2013/2/15 TONGARI
2013/2/15 Christian Henning
On Wed, Feb 13, 2013 at 6:13 PM, Christian Henning
wrote: Hi,
// I have no idea why this exists, seems OK to remove it template <typename Scalar> packed_channel_value(Scalar v) {
_value =
static_cast< integer_t >( v ) % num_values; }
I have uploaded the revised packed_channel_value class. Please have a look when you get a chance.
Ah, too bad, I just edited the file to get it work w/o that overload... Ok, I'll check it now.
Seems you haven't made any change to `channel.hpp`. Here's my patch for some possible improvement with care of not breaking the current API., I only tested the testcase `channel.cpp`.
If you find any flaw or improper, please let me know.
Sorry, there's a fatal bug, please ignore the previous, here's the fixed one.

Hi,
Seems you haven't made any change to `channel.hpp`. Here's my patch for some possible improvement with care of not breaking the current API., I only tested the testcase `channel.cpp`.
If you find any flaw or improper, please let me know.
Sorry, there's a fatal bug, please ignore the previous, here's the fixed one.
Could you send privately me your channel.hpp. For some reason I cannot apply the patch with my subversion. Thanks!
participants (2)
-
Christian Henning
-
TONGARI