2

I'm wondering if it's possible to get the address of an individual element of a Boost uBLAS matrix?

That is

boost::numeric::ublas::matrix<char> bob(3,3);
some_function(&bob[2][2]);

Now, of course the second line won't work... but I'd like it to.

Any thoughts?

Thanks!

Richard
  • 56,349
  • 34
  • 180
  • 251

2 Answers2

3

Wouldn't using the address of the return value of the following operator be simpler? And independent of the matrix layout?

reference operator () (size_type i, size_type j)

For example:

some_function(&bob(2,2));
Anonymous
  • 18,162
  • 2
  • 41
  • 64
1

by default, the inner representation of a matrix is a row major 1D array.

some_function(&bob.data()[i*ncol+j] would work

pjumble
  • 16,880
  • 6
  • 43
  • 51
pem
  • 175
  • 1
  • 6
  • 1
    By default in uBLAS? Which part of the Boost uBLAS specification indicates that this will work? – Richard Apr 19 '12 at 04:55
  • m.data() Returns a reference to the underlying dense storage. http://www.boost.org/doc/libs/1_46_0/libs/numeric/ublas/doc/container_concept.htm#matrix. As for the storage, there are 2 types: row_major or column_major, default is row_major. I forgot where it was specified. I once called lapack routines with ublas matrix, as far as I am concerned, get the pointer of 1D array by m.data() works. – pem May 04 '12 at 08:50