【问题标题】:Eigen C++ Assertion Failed特征 C++ 断言失败
【发布时间】:2016-12-02 06:32:18
【问题描述】:

我有一个名为 v 的 Eigen MatrixXd 对象,在尝试访问此矩阵内容时遇到了一些问题。当我只在控制台上打印内容时(如代码中所示),效果也一样好。当我尝试使用内容时,出现错误:

断言失败:(row >= 0 && row = 0 && col

    ChosenPoint ** points = new ChosenPoint*[width];
    for (int i = 0; i < width; i++)
    {
        points[i] = new ChosenPoint[height];
        for (int j = 0; j < height; j++)
        {
            points[i][j].setPoint(i, j, false);
            points[i][j].setNumberOfFrames(numberOfFrames);
        }
    }

Matrix<double, 2, 1> v = (aT * a).inverse() * aT * b;
if (v.rows() == 2 && v.cols() == 1)
{
     points[x][y].setFlow(v(0,0), v(1,0), frame);
}

还有我的 ChosenPoint 课程:

typedef struct point
{
    double x;
    double y;
    bool isValid;
 } point;

 class ChosenPoint 
{
public: 
ChosenPoint()
{

}

~ChosenPoint()
{
}

void setNumberOfFrames(int numberOfFrames)
{
    this->flow = new point[numberOfFrames];

    for (int i = 0; i < numberOfFrames; i++)
    {
        point f;
        f.x = 0.0;
        f.y = 0.0;
        this->flow[i] = f;
    }
}

void setPoint(int x, int y, bool isValid)
{
    this->pt.x = (double) x;
    this->pt.y = (double) y;
    this->pt.isValid = isValid;
}

point getPoint()
{
    return this->pt;
}

point* getFlow()
{
    return this->flow;
}

void setFlow(double &xFlow, double &yFlow, int &position)
{
    this->flow[position].x = xFlow;
    this->flow[position].y = yFlow;
}

void updateFlow(int position)
{
    this->flow[position].x = 2*this->flow[position].x;
    this->flow[position].y = 2*this->flow[position].y;
}

void updateFlow(double xFlow, double yFlow, int position)
{
    this->flow[position].x = xFlow;
    this->flow[position].y = yFlow;
}

point pt;
point *flow;

};

【问题讨论】:

  • 你的问题可能和points有关
  • 如果我使用 points[p].setArray(0.0,0.0) 或任何其他双精度,也可以正常工作。错误指向 Eigen 的某些东西,不是吗?
  • 你能提供一个minimal reproducible example吗?

标签: c++ matrix matrix-multiplication eigen


【解决方案1】:

我的错。问题在于我在项目中使用的其他矩阵之一,我花了一段时间才弄清楚。不幸的是,当这种情况发生时,Eigen 似乎并没有真正的帮助:

我有 2 个矩阵(A 和 B)。有问题的矩阵是 A(不知何故,一些数据没有加载到矩阵中)。但是当我将 A 和 B 相乘时,它生成了一个新的矩阵 C,它有一些有效的结果(我所有的理智检查都没有用)。我承认我对 Eigen 了解不多。

无论如何,希望这对像我这样的更多人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多