typedef boost::numeric::ublas::compressed_matrix<float>::iterator1 it1_t;
typedef boost::numeric::ublas::compressed_matrix<float>::iterator2 it2_t;
<pre name="code" class="cpp">boost::numeric::ublas::compressed_matrix<float> At(dim,dim);
my_time time;
time.tic();
int count = 0;
int index = 0;
for(it1_t it1=diff_x.begin1(); it1 != diff_x.end1(); it1++)
for(it2_t it2 = it1.begin(); it2 != it1.end(); it2++)
{
count++;
At(it2.index2(),it2.index2()) -= label_diff*alpha*pow(*it2,2);
At(it2.index2(),it2.index2()) = MAX(0.0,At(it2.index2(),it2.index2()));
}
cout<<"count is: "<<count<<endl;
time.toc();
the code is change the value in diagonal of matrix, we test two different sparse data, the output show below:
dim is: 29890095
count is: 54
time is: 68229 us
dim is: 180
count is: 79
time is: 18 us
We can get that, the element we retrieve is in a same magnitude, but the time has a difference over several magnitude.