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

lpNorm on MatrixBase

Tags: None
(comma "," separated)
matthewlai
Registered Member
Posts
10
Karma
0

lpNorm on MatrixBase

Fri Jun 12, 2015 12:09 pm
Hello!

I am trying to take the lpNorm<1> of a matrix in a function that takes a MatrixBase argument.

For some reason, it gives me a syntax error, but works fine if I make the argument a concrete matrix type instead.

Any idea why that may be?

Smallest compilable code (this is OK) -
Code: Select all
#include <Eigen/Dense>

typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> MyMatrix;

void f(const MyMatrix &x)
{
        x.lpNorm<1>();
}

int main()
{
        f(MyMatrix::Zero(3, 3));
}


This gives me a syntax error:
Code: Select all
#include <Eigen/Dense>

typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> MyMatrix;

template <typename Derived>
void f(const Eigen::MatrixBase<Derived> &x)
{
        x.lpNorm<1>();
}

int main()
{
        f(MyMatrix::Zero(3, 3));
}


Code: Select all
test.cpp:8:14: error: expected expression
        x.lpNorm<1>();
                    ^
1 error generated.


Many thanks!

EDIT:

AH I figured it out. Need to use "template" keyword for disambiguation. Leaving this here for Googlers' benefit.

Code: Select all
#include <Eigen/Dense>

typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> MyMatrix;

template <typename Derived>
void f(const Eigen::MatrixBase<Derived> &x)
{
        x.template lpNorm<1>();
}

int main()
{
        f(MyMatrix::Zero(3, 3));
}


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]