特征模板函数正确声明

时间:2020-06-30 13:11:04

标签: c++ templates eigen

我正在尝试创建模板化的本征函数,但是显然我无法获得正确的结构。我有:

Utils.hpp

background-color: rgba(#ff0000, 0.5);

Utils.tpl

#pragma once

#include <Eigen/Core>
#include <vector>

class Utils
{
public:
    Utils(){};
    ~Utils(){};
    
    template <typename Derived>
    void removeZeroRows(Eigen::EigenBase<Derived> &M, double epsilon);
};
    
#include "Utils.tpl"

调用者:

template <typename Derived>
void removeZeroRows(Eigen::EigenBase<Derived> &M, double epsilon)
{

    long asls = M.rows();
    long aslz = {};
    for (long i = 0; i < asls; i++)
    {
        if (M.row(i).isZero(epsilon))
            aslz++;
    }
    asls = asls - aslz;

    Eigen::EigenBase<Derived> MNZ(asls, M.cols());

    for (long i = 0, j = 0; i < asls; i++)
    {
        if (!M.row(i).isZero(epsilon))
        {
            MNZ.row(j) = M.row(i);
            j++;
        }
    }

    M = MNZ;
};

在构建时会出现错误:

VectorXi STC;
STC = ST;
utils->removeZeroRows(STC, epsilon);

and

MatrixXd ECL;
ECL.resize(size, 3);
ECL.setZero();

utils->removeZeroRows(ECL, epsilon);

有人可以解密吗?我究竟做错了什么? 谢谢

(完全愚蠢)大部分,代码,填充物,大部分,代码,填充物,大部分,代码,填充物,大部分,代码,填充物,大部分,代码,填充物,大部分,代码,填充物...

0 个答案:

没有答案
相关问题