Boost logo

Ublas :

Subject: Re: [ublas] poll: what's your uBLAS I/O usage ?
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-06-03 03:45:47

Hey Jesse,

> I think that for now, it is reasonable to expect an in memory copy for
> non-contiguous data (or column-major). So perhaps I can get iterators
> on the data which would work for strides > 1? Is there a bindings method
> to get a generic iterator that I could use for std::copy to a contiguous
> chunk of memory? Is this what the linear_iterator is for? If so, how do
> I get it for an arbitrary matrix and vector? I couldn't figure out the
> right combination of tags/etc.

the linear_iterator is meant to work with any linear memory layout, i.e.,

I think the following works, also for any kind of view, in pseudo code,

some_matrix M;
begin( column( M, i ) ) ... end( column( M, i ) )
begin( row( M, i ) ) ... end( row( M, i ) )

but what's defunctional at the moment is double-nested loop-stuff, i.e., an
iterator that doesn't return a pointer to data but iterates over

begin_row( M ) ... end_row( M ) |r| {
  begin( r ) ... end( r )

then, once this works, we could take it one step further, to assure that the
inner loop contains contiguous blocks of data,

begin_major( M ) ... end_major( M ) |vec| {
  ... do stuff with begin_value / end_value of vec; contiguous data

> My basic strategy would be:
> 1) If stride > 1 for either dimension, then do a std::copy with generic
> iterators.
> 2) If storage ordering is column major, then do a transpose. (order with 1
> could be reversed depending on what trans() does)
> 3) Write the data with the API, then free the allocated memory

Perhaps I am missing something, but don't we also need resizing capabilities
to be able to make stuff work with I/O?

> Am I missing something here when I think that storing the trans of a
> fortran ordered matrix (of arbitrary strides) with an API that expects C
> storage will end up correct in matlab?

Sounds right to me.

> Thanks. I was kind of confused with the begin() and end() for matrices
> and exactly what I should be passing for the tags. And I wasn't sure if
> these returned an iterator throw rows/columns or pointers to the
> underlying
> data storage. Any hints for this?

Hopefully the above answers this piece.

> I couldn't figure out what the trans() did exactly. Can I:
> 1) trans() my structure if column major
> 2) Ask it for a linear iterator to go through the data and do my copy?
> With the linear iterator now going through in the right order?

Trans flips all necessary strides/sizes and stuff so that it seems you are
dealing with a transposed matrix. So what you say should work,

begin( column( trans( M ), i ) ) ... end( column( trans( M ), i ) )
begin( row( trans( M ), i ) ) ... end( row( trans( M ), i ) )

> Thanks for your help. Hopefully this can be a test case for the bindings.

Thanks for the feedback! I'm quite busy with other stuff right now, I've put
the iterator stuff on the todo-list.