2011-02-11 86 views
2

我使用boost庫(1.44)和VC++ 2010.C++,boost :: numeric :: ublas :: mapped_matrix - 使用std :: tr1 :: unordered_map代替std :: map時的迭代問題

我發現了一些問題,下面的代碼,

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) 

這個測試失敗只有StorageUnorderedMap使用std :: tr1 :: unordered_map。 但insert_element()和find_element()測試全部通過。

+1

不可能告訴你的代碼。你初始化一個空的`StorageMap`並循環它。 – pmr 2011-06-30 18:43:57

回答

0

也許嘗試使用unordered_multimap。可能是因爲有相同的密鑰,一些插入失敗。然後計數不匹配。

相關問題