问题
I'm trying to multiply a sparse real matrix with a complex vector but the program does not compile. If I change the vector to real or the matrix to dense, then everything goes through. A sample code is:
#define ARMA_64BIT_WORD
#include <armadillo>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace arma;
int main(){
size_t n(5);
vec vR(randu<vec>(n)), vI(randu<vec>(n)); //Create random complex vector 'v'
cx_vec v(vR, vI);
std::cout<<"\n\tMultiplying real matrix with complex vector:"<<std::endl;
mat R = randu<mat>(n,n);
R*v; // -------------> COMPILES
std::cout<<"\n\tMultiplying real sparse matrix with complex vector:"<<std::endl;
sp_mat Rs = sprandu<sp_mat>(n,n,0.2);
Rs*v; // ------------> DOES NOT COMPILE
return 0;
}
Any recommendations for a solution? I'm using Armadillo version 5.200.1.
回答1:
I've had the same problem with multiplying two sparse matrices of different numeric type (see here). It seems that multiplying a sparse object with any other non-scalar type (be it sparse or dense) only works for equal numeric types for now. I am hoping they will implement that soon!
You can check by looking into operator_times.hpp
at lines 502
and 454
: the boolean expression in the enable_if2
template argument will evaluate to false
if two objects with different template parameters are multiplied, hence eliminating that template from the list of candidates for the operator*
overload.
来源:https://stackoverflow.com/questions/30465731/armadillo-sparse-real-matrix-multiplication-with-complex-vector