[英]'candidate template ignored: substitution failure' error help, C++, Armadillo, rank(),
I was playing around with the C++ armadillo library without doing anything serious. 我在玩C ++ armadillo库时没有做任何认真的事情。 However, I'm getting an error I don't know to handle. 但是,我遇到了一个我不知道要处理的错误。 I'm only passingly familiar with c++, and I really don't know where to begin. 我只是非常熟悉c ++,而且我真的不知道从哪里开始。 Anyway here's my code, it's really simple, it just makes an nxn matrix from 1-6 , fills it up from 1 to n^2, and then (attempts to) print the rank: 无论如何,这是我的代码,它非常简单,它只是将1-6组成一个nxn矩阵,将其从1填充到n ^ 2,然后(试图)打印等级:
#include <iostream>
#include <armadillo>
#include <string>
using std::cout;
using std::to_string;
using std::string;
using namespace arma;
int main(int argc, char *argv[])
{
int x = 1;
int m,n = 0;
for (int i=1; i<7; i++)
{
umat M(i,i);
for (m=0; m<i; m++)
{
for (n=0; n<i; n++)
{
M(m,n) = (x+n+(i*m));
}
}
string s = "M(" + to_string(i) + "x" + to_string(i) + "):";
M.print(s);
uword r = rank(M);
cout << "rank(M): " << to_string( r ) << "\n";
cout << "\n";
}
return (0);
}
My terminal in/output is: 我的终端输入/输出是:
$ g++ -o matrix matrix.cpp -larmadillo
matrix.cpp:35:13: error: no matching function for call to 'rank'
uword r = rank(M);
^~~~
/usr/local/include/armadillo_bits/fn_rank.hpp:22:1: note: candidate template ignored: substitution
failure [with T1 = arma::Mat<unsigned int>]: no type named 'result' in
'arma::arma_blas_type_only<unsigned int>'
rank
^ 1 error generated.
According to the documentation for the Mat class , the rank()
function only works for matrices which have elements of type float
, double
, std::complex<float>
, std::complex<double>
. 根据Mat类的文档, rank()
函数仅适用于元素类型为float
, double
, std::complex<float>
, std::complex<double>
矩阵。
The umat
matrix type stores elements as unsigned integers. umat
矩阵类型将元素存储为无符号整数。 (The width of the integers is dependent on whether your OS is 32 or 64 bit and whether the compiler is using the old C++98 standard or the newer C++11 standard; see here ). (整数的宽度取决于您的OS是32位还是64位以及编译器使用的是旧的C ++ 98标准还是更新的C ++ 11标准;请参见此处 )。
So to get your code working, change umat
to mat
. 因此,为了使您的代码正常工作, umat
更改为mat
。 In other words, instead of umat M(i,i);
换句话说,代替umat M(i,i);
use mat M(i,i);
使用mat M(i,i);
If you really need to store data as integers in a umat
, use the conv_to()
function to convert the matrix before passing it to the rank()
function: 如果您确实需要在umat
数据存储为整数,请在将矩阵传递给rank()
函数之前,使用conv_to()
函数转换矩阵:
double r = rank( conv_to<mat>::from(M) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.