Reputation: 914
I'm using the Armadillo C++ linear algebra library, and I'm trying to figure out how to convert an sp_mat
sparse matrix object to a standard mat
dense matrix.
Looking at the internal code doc, sp_mat
and mat
don't share a common parent class, which leads me to believe there isn't a way to cast an sp_mat
as a mat
. By the way, conv_to<mat>::from(sp_mat x)
doesn't work.
Perhaps there's a tricky way to do this using one of the advanced mat
constructors? For example, somehow create a mat of zeros and pass the locations and values of non-zero elements in the sp_mat
.
Does anyone know of an efficient method to do this? Thanks in advance.
Upvotes: 0
Views: 2143
Reputation: 3620
Casting works perfectly fine:
sp_mat X(2,2);
mat Y(X);
Y.print("Y:");
Upvotes: 4