犰狳 - 矩阵乘法误差

时间:2015-05-04 22:07:51

标签: matrix-multiplication armadillo

我正在尝试使用Armadillo进行简单的矩阵乘法:

mat33 MatA, MatB, MatC;

MatA = MatB * MatC;

并发生此错误:

 C:\...SFunction.cpp:21: error: C2666: 'arma::Mat<eT>::operator =' : 3 overloads have similar conversions
    with
    [
        eT=double
    ]
    c:\...\include\armadillo\armadillo_bits/Mat_bones.hpp(724): could be 'const arma::Mat<eT> &arma::Mat<eT>::fixed<fixed_n_rows,fixed_n_cols>::operator =(const arma::Mat<eT>::fixed<fixed_n_rows,fixed_n_cols> &)'
    with
    [
        eT=double,
        fixed_n_rows=3,
        fixed_n_cols=3
    ]
    c:\...\include\armadillo\armadillo_bits/Mat_bones.hpp(82): or       'const arma::Mat<eT> &arma::Mat<eT>::operator =(const arma::Mat<eT> &)'
    with
    [
        eT=double
    ]
    c:\...\include\armadillo\armadillo_bits/Mat_meat.hpp(4652): or       'const arma::Mat<eT> &arma::Mat<eT>::operator =<arma::mat33,arma::mat33,arma::glue_times>(const arma::Glue<T1,T2,glue_type> &)'
    with
    [
        eT=double,
        T1=arma::mat33,
        T2=arma::mat33,
        glue_type=arma::glue_times
    ]
    while trying to match the argument list '(arma::mat33, const arma::Glue<T1,T2,glue_type>)'
    with
    [
        T1=arma::mat33,
        T2=arma::mat33,
        glue_type=arma::glue_times
    ]

但是,当我将代码更改为:

mat33 MatA, MatB, MatC;

MatA = mat33(MatB * MatC);
一切都很好。这是进行矩阵乘法并将结果保存到其他矩阵的正确方法吗?还是有另一种更简单的方法?

1 个答案:

答案 0 :(得分:1)

为什么使用 mat33 (固定大小)?

您可以使用普通的 mat 类。在这种情况下,乘法是无缝的

mat MatA(3,3), MatB(3,3), MatC(3,3); //or MatC;
// fill MatA, MatB
MatC = MatA * MatB