Garima Singh
Garima Singh

Reputation: 1490

Armadillo Lib (C++): find operation with sparse matrix (sp_mat class)

I am trying to use the find operator of armadillo in context of sparse matrix (class sp_mat).

It works fine in context of full matrix; but with the sparse matrix (d1 in the following example)

            mat  A  = randu<mat>(5,5);
            mat  B  = randu<mat>(5,5);
            uvec q2 = find(A != 0.5);

            uvec q1 = find(d1 != -0.5);   // d1 is a sparse matrix; ERROR REPORTED HERE

I get the following error:

Error   3   error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'arma::sp_mat' (or there is no acceptable conversion)

Could someone suggest how could I perform find operation?

and

Also, if there is a way to convert sparse matrix (class sp_mat) to full matrix (class mat)? I tried to use "conv_to" without any success.

Upvotes: 1

Views: 259

Answers (1)

mtall
mtall

Reputation: 3620

How to convert a sparse matrix to a dense matrix:

sp_mat A;
A.sprandu(20, 20, 0.1);

mat B(A);
B.print("B:");

The constructor for the mat class can take a sparse matrix as input, as listed in the documentation.

Upvotes: 4

Related Questions