简体   繁体   English

“候选模板被忽略:替换失败”错误帮助,C ++,犰狳,rank(),

[英]'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()函数仅适用于元素类型为floatdoublestd::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.

相关问题 “忽略候选模板:替换失败:”编译器错误? - "candidate template ignored: substitution failure:" compiler error? 候选模板被忽略:替换失败(clang但不是g ++错误) - candidate template ignored: substitution failure(error with clang but not g++) clang: 候选模板被忽略: 替换失败: typedef &#39;type&#39; 不能用类说明符引用 - clang: candidate template ignored: substitution failure: typedef 'type' cannot be referenced with a class specifier 忽略Clang候选模板:替换失败(也无法使用gcc编译,VC工作正常) - Clang candidate template ignored: substitution failure (also fails to compile with gcc, VC works fine) C ++候选模板传递lambda作为std :: function的参数时忽略错误 - C++ Candidate Template Ignored error when passing lambda as argument for std::function C ++使用模板进行整数类型,候选模板被忽略 - C++ working with templates for integral types, candidate template is ignored C ++-为什么忽略带有函数指针参数的候选模板? - C++ - Why is this candidate template with a function pointer parameter ignored? C ++模板替换错误 - c++ template substitution error C ++模板函数,替换失败跳过实现 - C++ template function, substitution failure skip the implementation C ++:候选模板被忽略:模板参数的显式指定参数无效 - C++: candidate template ignored: invalid explicitly-specified argument for template parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM