Boost logo

Ublas :

Subject: Re: [ublas] ublas::vector and a "random access" container concept? And ublas::matrix.
From: Andrew W. Steiner (awsteiner_at_[hidden])
Date: 2009-01-22 14:49:56


I was able to use operator[] successfully with ublas, see, e.g.

http://o2scl.svn.sourceforge.net/viewvc/o2scl/trunk/examples/ex_ublas.cpp

The code above actually uses a generic solver which internally requires
a QR decomposition for generic matrix and vector types.

Take care,
Andrew

On Thu, Jan 22, 2009 at 2:11 PM, <jesseperla_at_[hidden]> wrote:
> I have been writing a lot of generic code recently that needs to operate on
> boost::array, std::vector, and ublas::vector
>
> I have found the lack of operator[] for random element access to be a real
> pain for writing generic code, and it seems to be inconsistent with the
> others. I understand the rationale for not having operators[] on
> ublas::matrix, to be discussed later, but why cannot operator() and
> operator[] call the same code for ublas::vector? Am I missing something?
> Right now my workaround is to use .begin() and then use the random access
> iterator concept implemented by all of these iterators. But this is really
> ugly for many cases.
>
>
> For ublas::matrix. I am also having trouble writing generic code that works
> for normal C 2D arrays and with boost::multi_array. Here, boost::multi_array
> implements the [] operator which I assume passes back either a value or an
> iterator depending on the dimension. The result is that for both normal C
> and boost::multi_array, I can use the: mycontainer[0][1] notation. Now, I
> understand why ublas::matrix relies on the operator() for access, and why it
> is more efficient, but is there any way to also implement [] operators in a
> similar way to multi_array (passing back an iterator if called on the matrix
> and a value if called on the matrix column/row iterator)? This would make
> generic code a lot easier to write. Alternatively, is there an equivalent to
> the .begin() that works for both data structures? The problem I have is that
> the 2D iterator concept implemented by ublas::matrix is inconsistent with
> that implemented by multi_array.
>
> Thanks,
> Jesse
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>
>