- changed status to resolved
dataObject.rand returns INT_MIN value for datatype int32
Issue #180
resolved
The code
a = dataObject.rand([10,10], 'int32')
returns the value INT_MIN (-2**31) for all values instead of a uniform distribution in the range [-2**31, 2**31-1), which is the desired case.
The problem is the underlying implementation of cv::randu which is responsible for this.
A solution will be to limit the value range for the underlying call of cv::randu to [-2**30, 2**30-1) and then make a 2nd loop over all values and calculate:
value = (value << 1) + cv::RNG::uniform(0,2);
This will multipliy the original value by 2 (bitshift) and add a uniformly distributed value 0 or 1.
Comments (1)
-
reporter - Log in to comment
fixes issue 180: workaround to provide a correct (but not very efficient) implementation for dataObject.rand(...,"int32"). This only affects the int32 datatype both in Python and C++.
→ <<cset 8b96a89a3f80>>