This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Error: "You mixed up matrices of different size"

Tags: None
(comma "," separated)
Helm21
Registered Member
Posts
2
Karma
0
Hello,

I tried to typedef my own Matrices, but the calculation with them fails.
I got the following static assert from eigen:

YOU_MIXED_UP_MATRICES_OF_DIFFERENT_SIZES

Here is the code:

BasisCalculation.h
Code: Select all
#include "Eigen"
#include "Core"

typedef Eigen::Matrix<double, 1, 8> EigenDemandVector;
typedef Eigen::Matrix<EigenDemandVector, Eigen::Dynamic, 1> EigenDemandVectorMatrix;

class BasicCalculation
{
public:
    BasicCalculation();

    static EigenDemandVector calc(EigenDemandVectorMatrix demandVectorMatrix);
};


BasisCalculation.cpp
Code: Select all
#include "BasicCalculation.h"

BasicCalculation::BasicCalculation()
{
}

EigenDemandVector BasicCalculation::calc(EigenDemandVectorMatrix demandVectorMatrix)
{
    EigenDemandVector ret=(EigenDemandVector)((demandVectorMatrix.cast<double>()).colwise().sum());
    ret/=demandVectorMatrix.rows();
    return ret;
}


EigenDemandVector is has alway 1 row and 8 cols.
Therefore EigenDemandVectorMatrix has 8 cols and x rows.
Summing colwise should result in a vector with 1 row and 8 cols (same size as EigenDemandVector).

Could anyone help me?
Cheers Helm
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
"demandVectorMatrix.cast<double>()" is invalid. You should rather use the following typedef:
Code: Select all
typedef Eigen::Matrix<double, Eigen::Dynamic, 8> EigenDemandVectorMatrix;

and
Code: Select all
return demandVectorMatrix.colwise().mean();
Helm21
Registered Member
Posts
2
Karma
0
Thank you very much, your solution runs!

You meant
ggael wrote:
Code: Select all
return demandVectorMatrix.colwise().sum();


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]