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

explicit template instantiation

Tags: None
(comma "," separated)
rezar
Registered Member
Posts
6
Karma
0

explicit template instantiation

Fri Jun 01, 2012 10:15 am
Hi, I'm trying:
template class Matrix< double, Dynamic, Dynamic >;
and getting:
YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX

Is there a way to fix that?

EDIT: g++ 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)

Thank you.
manuels
Registered Member
Posts
47
Karma
0

Re: explicit template instantiation

Fri Jun 01, 2012 7:05 pm
what is the method you are calling?
rezar
Registered Member
Posts
6
Karma
0

Re: explicit template instantiation

Fri Jun 01, 2012 7:42 pm
I am _not_ calling any specific methods. Please Google "explicit template instantiation" to see what it does.

However, the error is apparently happening inside this function:
Code: Select all
EIGEN_STRONG_INLINE explicit Matrix(Index dim)
      : Base(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim)
{
       [....]
}
 

In Core/Matrix.h line 237.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: explicit template instantiation

Sat Jun 02, 2012 2:16 pm
This means you are calling a vector constructor, like:

Matrix<double,Dynamic,Dynamic> mat(10);

that is not allowed.
rezar
Registered Member
Posts
6
Karma
0

Re: explicit template instantiation

Sat Jun 02, 2012 5:53 pm
Thanks for trying to help, but...
Would you please read my posts first???

I am trying to do EXPLICIT TEMPLATE INSTANTIATION. I am NOT calling any methods.

This is my entire code (very short) which I'm compiling using
g++ -fno-implicit-templates -I ../eigen-3.05-6e7488e20373 -c templates.cpp

all.h:
Code: Select all

// #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <Eigen/Dense>
//#include <Eigen/Sparse>

using namespace std;
using namespace Eigen;

#define TYPE float



templates.cpp
Code: Select all
#include "all.h"

// typedef SparseMatrix<double> MT;
template class complex<TYPE>;
template class Matrix<TYPE, Dynamic, Dynamic>;
template class Matrix< complex<TYPE>, Dynamic, Dynamic >;

User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
okay, now I see your issue.The workaround is to turn the static assertions into runtime asserts by defining EIGEN_NO_STATIC_ASSERT before including Eigen. You can do this only in your cpp file doing explicit instantiation. Nevertheless, I'm afraid you won't be able get any benefits by explicitly instantiating Eigen's type. Recall that's an expression template library, so any expression defines new types...
rezar
Registered Member
Posts
6
Karma
0

Re: explicit template instantiation

Sat Jun 02, 2012 6:50 pm
ggael wrote: The workaround is to turn the static assertions into runtime asserts by defining EIGEN_NO_STATIC_ASSERT before including Eigen. You can do this only in your cpp file doing explicit instantiation. Nevertheless, I'm afraid you won't be able get any benefits by explicitly instantiating Eigen's type. Recall that's an expression template library, so any expression defines new types...


Great, it works! But you're absolutely right, I didn't think of that.
Hmm.. I wonder if there is some way to do this sort of thing; i.e. tell g++ to "follow" different plausible possibilities automatically.
But the main question seems answered, thanks a lot.


Bookmarks



Who is online

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