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

Save a matrix as file

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

Save a matrix as file

Sat Oct 16, 2010 7:01 am
Hello,

is there a simple method to save a MatrixXf and reload it on next program start?
I do some heavy computations and would like to save them.
I already tried writing the MatrixXf object to a stream, using something like:
Code: Select all
ofstream ofs("/tmp/matrix.dump", ios::binary);
ofs.write((char *)&featureArray, sizeof(featureArray));

where featureArray is of type MatrixXf
But this saves only 12byte for a 1000x300 matrix, and after loading there
are no elements in the matrix.

Ismael
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Save a matrix as file

Sat Oct 16, 2010 12:44 pm
We don't provide file IO, we only support printing to a c++ stream but no readback. You'll have to code that yourself!

if featureArray is of type MatrixXf, then instead of

ofs.write((char *)&featureArray, sizeof(featureArray));

you should do

ofs.write(featureArray.data(), featureArray.size() * sizeof(float));


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Save a matrix as file

Sat Oct 16, 2010 12:45 pm
note that a MatrixXf only contains 2 integer fields (numbers of rows and cols) and the array of coefficients. Nothing else.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
dzenanz
Registered Member
Posts
35
Karma
0
OS

Re: Save a matrix as file

Fri Oct 22, 2010 8:22 am
Hi,

if (or better say when) you find a solution, can you post it here? I am in the same position as you are (regarding saving and loading).

Regards,
Dženan


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient