static double getValue(SparseMat& M, const int* idx, RNG& rng) { int d = M.dims(); size_t hv = 0, *phv = 0; if( (unsigned)rng % 2 ) { hv = d == 2 ? M.hash(idx[0], idx[1]) : d == 3 ? M.hash(idx[0], idx[1], idx[2]) : M.hash(idx); phv = &hv; } const uchar* ptr = d == 2 ? M.ptr(idx[0], idx[1], false, phv) : d == 3 ? M.ptr(idx[0], idx[1], idx[2], false, phv) : M.ptr(idx, false, phv); return !ptr ? 0 : M.type() == CV_32F ? *(float*)ptr : M.type() == CV_64F ? *(double*)ptr : 0; }
static void setValue(SparseMat& M, const int* idx, double value, RNG& rng) { int d = M.dims(); size_t hv = 0, *phv = 0; if( (unsigned)rng % 2 ) { hv = d == 2 ? M.hash(idx[0], idx[1]) : d == 3 ? M.hash(idx[0], idx[1], idx[2]) : M.hash(idx); phv = &hv; } uchar* ptr = d == 2 ? M.ptr(idx[0], idx[1], true, phv) : d == 3 ? M.ptr(idx[0], idx[1], idx[2], true, phv) : M.ptr(idx, true, phv); if( M.type() == CV_32F ) *(float*)ptr = (float)value; else if( M.type() == CV_64F ) *(double*)ptr = value; else CV_Error(CV_StsUnsupportedFormat, ""); }