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

swap problem

Tags: None
(comma "," separated)
jakjohnson
Registered Member
Posts
5
Karma
0

swap problem

Sat Oct 15, 2011 9:31 am
Hi,

I need to swap some large Eigen matrices (many times), say matrices m1 and m2. Using the standard c++ swap(m1,m2) works fine, but is slow because it does a copy.
When I use Eigen's swap routine m1.swap(m2), it works on small test cases, but becomes wrong for large matrices and many swaps!
The only possible explanation I have is that in order to use fftw, I allocate with fftw_malloc
Code: Select all
    m1f = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n1*n2);

and then map to eigen
Code: Select all
   MatrixXcd m1 = MatrixXcd::Map(reinterpret_cast<complex<double>*>(m1f), n1, n2);

I also use #define EIGEN_DEFAULT_TO_ROW_MAJOR because fftw expects row-major format.
Could the mapping be a problem, and is there a way to solve this?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: swap problem

Mon Oct 17, 2011 8:18 pm
m1.swap(m2) with m1 and m2 Eigen::Matrix<> objects of the same type with "Dynamic" sizes does a fast shallow copy, i.e., only swap the pointers. Perhaps you tried with fixed size objects??
jakjohnson
Registered Member
Posts
5
Karma
0

Re: swap problem

Tue Oct 18, 2011 7:25 am
youre right, I was mixing some fixed-size objects, and the problem is not the eigen swap at all. sorry, and thanks for your help!


Bookmarks



Who is online

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