MCPcopy Create free account
hub / github.com/creatale/node-dv / randShuffle_

Function randShuffle_

deps/opencv/modules/core/src/rand.cpp:827–853  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

825{
826
827template<typename T> static void
828randShuffle_( Mat& _arr, RNG& rng, double iterFactor )
829{
830 int sz = _arr.rows*_arr.cols, iters = cvRound(iterFactor*sz);
831 if( _arr.isContinuous() )
832 {
833 T* arr = (T*)_arr.data;
834 for( int i = 0; i < iters; i++ )
835 {
836 int j = (unsigned)rng % sz, k = (unsigned)rng % sz;
837 std::swap( arr[j], arr[k] );
838 }
839 }
840 else
841 {
842 uchar* data = _arr.data;
843 size_t step = _arr.step;
844 int cols = _arr.cols;
845 for( int i = 0; i < iters; i++ )
846 {
847 int j1 = (unsigned)rng % sz, k1 = (unsigned)rng % sz;
848 int j0 = j1/cols, k0 = k1/cols;
849 j1 -= j0*cols; k1 -= k0*cols;
850 std::swap( ((T*)(data + step*j0))[j1], ((T*)(data + step*k0))[k1] );
851 }
852 }
853}
854
855typedef void (*RandShuffleFunc)( Mat& dst, RNG& rng, double iterFactor );
856

Callers

nothing calls this directly

Calls 3

cvRoundFunction · 0.85
swapFunction · 0.70
isContinuousMethod · 0.45

Tested by

no test coverage detected