Eigen3 C ++矩阵库:通过在静态大小的Matrix类型

时间:2018-02-25 16:09:38

标签: c++ templates matrix eigen eigen3

我在这个论坛上有点新意,所以请原谅我,以防我做错了。

我试图使用C ++矩阵库Eigen3.3.4(标签5a0156e40febif我没错。)

我试图用它做一些模板编程,我的一些调用没有得到编译器的解决。我当然做错了什么,但由于我没有看到明确的答案,我提出了一个帖子。

我试图使用Matrix模板类的块方法重载(具有两个模板参数和两个整数参数的类)。我试图在一个模板化的类中使用它来提取一个参数块。

当使用别名类型(即typedef' ed)时,***。块(Z,T)不能解析OKAY,而使用具体类型的临时参数它可以正常工作。我在同一个对象中使用std :: tuple进行参数打包。

目标是接到以下电话:

std::get<3>(my_tuple).block<3,4>(0,1)

用作函数,方法或构造函数中的参数。任何解决方法都可以。

我设法在以下代码中重现了这个问题(至少我是这么认为的。)

#include <iostream>
#include <Eigen/Dense>

class MyTypeSource
{
public:
    typedef Eigen::Matrix<double, 5, 5> CFULL_matrix_format;
    typedef Eigen::Matrix<double, 3, 3> SUB_format;
};

template<typename Source>
class MyTypeDest
{
public:
    typedef typename Source::CFULL_matrix_format CFULL_matrix_format;
    typedef typename Source::SUB_format SUB_format;

    typedef
        std::tuple<CFULL_matrix_format>
        SecondaryObject;

    MyTypeDest(const CFULL_matrix_format & in_data) :
        _local(in_data)
    {

    }

    // The problems appears to be there...
    void dispSUB() const
    {
        Eigen::Matrix<double, 5, 5> copy_with_raw_type = std::get<0>(_local);

        CFULL_matrix_format copy_with_aliased_type     = std::get<0>(_local);

        // THIS DOESN'T COMPILE/FUNCTION !
        //        std::cout   << "========================================"
        //                    << std::endl
        //                    << Eigen::Matrix3d(std::get<0>(_local).block<3,3>(0, 0))
        //                    << std::endl
        //                    << "========================================"
        //                    << std::endl;

        // ALTHOUGH "CFULL_matrix_format copy_with_aliased_type" AND "Eigen::Matrix<double, 5, 5> copy_with_raw_type" SHOULD BE THE SAME,
        // DESPITE THE FACT THAT TYPEID DISPLAYS THE SAME TYPE NAME FOR BOTH ELEMENTS (AND TYPES)
        //                                       ==================
        //
        // => THIS CALL DOESN'T COMPILE,
        //        std::cout   << "========================================"
        //                    << std::endl
        //                    << copy_with_aliased_type.block<3,3>(0, 0)
        //                    << std::endl
        //                    << "========================================"
        //                    << std::endl;

        // => WHEREAS THIS ONE DOES, AND FUNCTIONS !
                std::cout   << "========================================"
                            << std::endl
                            << copy_with_raw_type.block<3,3>(0, 0)
                            << std::endl
                            << "========================================"
                            << std::endl;

        // THE SAME OCCURS WHEN TRYING TO USE THE BLOCK VALUE AS AN ARGUMENT INTO A METHOD/FUNCTION CALL
    }

    CFULL_matrix_format getFULL() const
    {
        return std::get<0>(_local);
    }

private:
    SecondaryObject _local;
};

int main()
{
    Eigen::Matrix<double, 5, 5> my_matrix;
    my_matrix     <<    1.0,   2.0,   3.0,   4.0,   5.0,
                        5.0,   6.0,   8.0,  10.0,  12.0,
                       10.0,  12.0,  15.0,  20.0,  25.0,
                       12.0,  17.0,  22.0,  27.0,  32.0,
                       24.0,  37.0,  39.0,  14.0,   7.0;

    MyTypeDest<MyTypeSource> object(my_matrix);

    std::cout     << "========================================"
                  << std::endl
                  << object.getFULL()
                  << std::endl;

    std::cout     << "========================================"
                  << std::endl
                  << my_matrix.block<3, 3>(0, 0)
                  << std::endl;

    object.dispSUB();
}

Copiler是g ++ - 4.8在64位14.04下--std = c ++ 11模式;编译器错误代码是:

test_file.cpp: In member function ‘void MyTypeDest<Source>::dispSUB() const’:
test_file.cpp:51:29: error: invalid operands of types ‘int’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’
                     << std::endl
                             ^
test_file.cpp: In instantiation of ‘void MyTypeDest<Source>::dispSUB() const [with Source = MyTypeSource]’:
test_file.cpp:96:20:   required from here
test_file.cpp:38:65: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator<’
                     << Eigen::Matrix3d(std::get<0>(_local).block<3,3>(0, 0))
                                                             ^
test_file.cpp:50:21: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ and ‘<unresolved overloaded function type>’)
                     << copy_with_aliased_type.block<3,3>(0, 0)
                     ^

还有更多。我只关注前三名。在我看来它并不能识别阻止呼叫。

我肯定做了些蠢事。我就是这样,请告诉我。

非常感谢任何帮助,非常感谢。

0 个答案:

没有答案
相关问题