Updated by Alexander Shishkov about 13 years ago
There seems to be a problem with the clear() method and all methods that call clear(): I noticed that the iterator on a just cleared sparse mat is not empty. Looking into the debugger revealed that the hash table is not cleared. Trying to trace into the clear() method revealed that the actual method is never called. I observed this with 2.3.1 on a Mac OS X 10.7.2 withh gcc 4.2.
The following code works if and only if the commented line remains commented out:
int main (int argc, const char * argv[])
{
int sizesr2 = {10, 20};
cv::SparseMat_<float> v(2,sizes);
v.ref(2,4) = 7.0f;
//v.clear();
cv::SparseMatIterator_<float> i = v.begin();
cv::SparseMatIterator_<float> ie = v.end();
for (; i != ie; ++i)
std::cout << *i;
std::cout << '\n';
return 0;
}
Commenting out v.clear(), I would expect the hash table to be cleared and the iterator to be on an empty set, i.e., never executed. This is not the case and any iterator on SparseMat [[SparseMat]] needs to be embraced by
if (my_matrix.nzcount()) {
...
}
The following code works if and only if the commented line remains commented out:
int main (int argc, const char * argv[])
{
int sizesr2 = {10, 20};
cv::SparseMat_<float> v(2,sizes);
v.ref(2,4) = 7.0f;
//v.clear();
cv::SparseMatIterator_<float> i = v.begin();
cv::SparseMatIterator_<float> ie = v.end();
for (; i != ie; ++i)
std::cout << *i;
std::cout << '\n';
return 0;
}
Commenting out v.clear(), I would expect the hash table to be cleared and the iterator to be on an empty set, i.e., never executed. This is not the case and any iterator on SparseMat [[SparseMat]] needs to be embraced by
if (my_matrix.nzcount()) {
...
}