Boost logo

Ublas :

From: Michele De Stefano (micdestefano_at_[hidden])
Date: 2007-09-18 02:55:08

I've already done what Mei Longyu asks (and Gunter Winkler has
partially answered the question).

If you instantiate a matrix m with the correct dimensions (M rows by
N columns), internally, there is a buffer M*N long. You can access to
the pointer to this buffer through

In fact, gives you access to the internal "unbounded array",
and the "begin" method returns the starting iterator to the unbounded
array. Into the Boost documentation of the unbounded array there is
written that the iterator is defined as pointer. So the iterator of an
unbounded array is exactly a pointer that points to a pre-allocated
buffer (and you can use this to do simple I/O operations with files,
or, for example, you can pass the matrix to a FORTRAN subroutine, if
the matrix storage is column_major ... but to do this probably is
better to use Boost Bindings).

The other way (i.e. serializing the matrix through
boost::serialization) is powerful but I think it has a drawback: it is
perfect is you always want to read/write the whole matrix, but it is
useless if you want to read/write sub-matrices (e.g. if you have a big
matrix on file, and you want to read a sub-matrix only).

Michele De Stefano

On 9/17/07, Gunter Winkler <guwi17_at_[hidden]> wrote:
> Am Montag, 17. September 2007 20:40 schrieb Mei, Longyu:
> > I want to write matrix data to a file. I am wondering is the matrix
> > memory layout is similar as vector which guarantee a continuous
> > memory location?
> >
> > If the matrix is also a continuous memory segement, I can just get
> > the start address (or a pointer of a matrix) and then get all data
> > from there until the size. Otherwise I need to have a temporary
> > memory location (which is duplicated memory consumption) to hold all
> > data before write.
> short answer: returns the underlying storage
>[0] ...[ ] is the data
> long answer:
> you can simply serialize the matrix using boost::serialization support.
> (You need the SVN head version of boost and ublas)
> Try
> mfg
> Gunter
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]