mingw使用Eigen库时出现未知错误

时间:2017-10-16 18:38:00

标签: c++ eigen

背景

我正在用C ++将最小二乘算法编写成一个类,我想确保我所做的是最有效和最快的。我使用Eigen库来编写所有子例程来为美式期权合约定价。我还没有完成算法,但我完成了大部分子程序,并测试它们以确保它们正常工作。

问题:

当我在Eclipse上构建它时,我从Eigen得到了这个未知错误:

gsub("(.*\\-\\d*)[a-z]*", "\\1", s, ignore.case = TRUE)

我不确定问题是什么。

这是我的头文件:

c:\mingw\include\c++\6.2.0\eigen\src/Core/PlainObjectBase.h:774:7: error: static assertion failed: FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED
       EIGEN_STATIC_ASSERT(is_integer,

以下是相关的.cpp文件:

#include <vector>
#include <Eigen/Dense>
#include <Eigen/Geometry>




#ifndef LSM_H
#define LSM_H




class LSM {
public:
    // Overload Constructor
    LSM(const double, const double, const double, const int, const int, const double, const double, const int, const int);

    // Destructor
    ~LSM();

    // Generate the Laguerre Polynomials
    Eigen::MatrixXd Laguerre(Eigen::VectorXd, const int);

    // Generate Gaussian noise


    // Generate M paths of stock prices (Geometric Brownian Motion)
    Eigen::VectorXd GBM(const int, const int, const double, const double, const double, const double, const double);

    // Generate time paths
    Eigen::VectorXd timepaths(const double, const double, const double);

    // Payoff of call option
    Eigen::VectorXd callPayoff(Eigen::VectorXd, const double);

    // Payoff of put option
    Eigen::VectorXd putPayoff(Eigen::VectorXd, const double);

    // Find function for finding the paths that are in the money (call option)
    Eigen::VectorXd Findcallpath(Eigen::VectorXd, const double);

    // Find function for finding the paths that are in the money (put option)
    Eigen::VectorXd Findputpath(Eigen::VectorXd, const double);

    // Find price of call given path
    Eigen::VectorXd Findcallprices(Eigen::VectorXd, Eigen::VectorXd);

    // Find price of put given path
    Eigen::VectorXd Findputprices(Eigen::VectorXd, Eigen::VectorXd);

    // Find return of call (stock price - strike price)
    Eigen::VectorXd Findcallreturn(Eigen::VectorXd, const double);

    // Find return of put (strike price - stock price)
    Eigen::VectorXd Findputreturn(Eigen::VectorXd, const double);

    // Using Two-sided Jacobi SVD decomposition of a rectangular matrix
    Eigen::VectorXd Jacobi(Eigen::MatrixXd, Eigen::VectorXd);






private:
    // Member variables
    double new_r;
    double new_q;
    double new_sigma;
    int new_T;
    int new_N;
    double new_K;
    double new_S0;
    int new_M;
    int new_R;

};






#endif

1 个答案:

答案 0 :(得分:1)

您只需按照编译器错误消息查找代码中的违规行,该行位于函数LSM::timepaths中,您将传递一个双精度来构造VectorXd

VectorXd LSM::timepaths(const double min, const double max, const double N)
{
   VectorXd m(N + 1);
   [...] 

应该是:

VectorXd m(int(N) + 1);

对于记录,在.cpp文件中复制代码后,编译器会说:

../eigen/Eigen/src/Core/PlainObjectBase.h:779:27: error: no member named 'FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED' in 'Eigen::internal::static_assertion<false>'
                          FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
                          ^
../eigen/Eigen/src/Core/Matrix.h:296:22: note: in instantiation of function template specialization 'Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::_init1<double>' requested here
      Base::template _init1<T>(x);
                    ^
foo.cpp:166:21: note: in instantiation of function template specialization 'Eigen::Matrix<double, -1, 1, 0, -1, 1>::Matrix<double>' requested here
    Eigen::VectorXd m(N + 1);
                    ^

这不能更明确。

编辑:还有更多问题,例如使用double索引VectorXd:

Eigen::VectorXd C, S, path;
C(i) = S(path(i));

请使用Eigen::VectorXistd::vector<int>来保存索引。

相关问题