犰狳稀疏实矩阵乘法与复矢量 [英] Armadillo sparse real matrix multiplication with complex vector

查看:140
本文介绍了犰狳稀疏实矩阵乘法与复矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将稀疏实矩阵与复数矢量相乘,但是程序无法编译.如果我将向量更改为实数,或者将矩阵更改为稠密,那么一切都会进行.示例代码为:

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;

}

对解决方案有何建议?我正在使用Armadillo版本5.200.1.

Any recommendations for a solution? I'm using Armadillo version 5.200.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!

您可以通过在502454行中查看operator_times.hpp进行检查:如果将两个具有不同模板参数的对象相乘,则enable_if2模板参数中的布尔表达式将求值为false,因此消除了operator*重载的候选列表中的模板.

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.

这篇关于犰狳稀疏实矩阵乘法与复矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆