2

I'm using the boost library(1.44) and VC++ 2010.

I found some problem with below code,

using namespace boost::numeric;
typedef double value_type;

typedef ublas::mapped_matrix<value_type> StorageMap;
typedef ublas::mapped_matrix<value_type, ublas::row_major, std::tr1::unordered_map<size_t, value_type> > StorageUnorderedMap;

StorageMap mat; //<== (1) 
//StorageUnorderedMap mat; //<== (2)

//Looping over non-zero elements of sparse matrix.
size_t numElemLoop= 0;
for(auto it1= mat.begin1(); it1 != mat.end1(); ++it1)
{
    for(auto it2= it1.begin(); it2 != it1.end(); ++it2)
    ++numElemLoop;
}

assert(mat.nnz() == numElemLoop); //<== (3)

This test failed for only StorageUnorderedMap using std::tr1::unordered_map. But insert_element() and find_element() test passed for all.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
bob
  • 21
  • 1
  • 1
    Impossible to tell with your code. You initialize an empty `StorageMap` and loop over it. – pmr Jun 30 '11 at 18:43

1 Answers1

0

Perhaps try to use unordered_multimap. It could be that some insertions fail because of equal keys. Then the counts will not match up.

emsr
  • 15,539
  • 6
  • 49
  • 62