Boost logo

Boost Users :

From: jhr.walter_at_[hidden]
Date: 2003-03-28 06:25:40


----- Original Message -----
From: vladimir josef sykora
To: boost-users_at_[hidden]
Sent: Wednesday, March 26, 2003 11:25 AM
Subject: [Boost-Users] [uBLAS] operations thoughts

> Hello,
> Had a quick look into uBLAS library, and noted the incompatibility between
> std::vector<> and ublas' binary operations. For example, I have an
> ublas::matrix<> and wanted to multiply it by a std::vector<>.

I'd tend to recommend to use ublas::vector<> instead for the basic linear
algebra. One can use std::vector as ublas::vector's storage container if
needed.

> Since _all_ of ublas data containers provide iterators, I'm wondering why
> the library doesn't provide algorithms that work on iterators?

Because the signatures of the algorithms are more complex then.

> In this way
> data structures and operators will be decoupled.

Container and operators are decoupled through proxies (views?) like
vector_range<> and matrix_range<>. One could imagine these as tuples of
iterators.

> For example, to do the product between a matrix and a vector:
>
> ********* untested code *********
> template <class MatrixRowIterator, class MatrixColIterator, class
> InputIterator, class OutputIterator>
> OutputIterator prod(MatrixRowIterator first_row, MatrixRowIterator
> last_row,
> MatrixColIterator, InputIterator first_vec, OutputIterator result) {
> InputIterator cp_first=first_vec;
> while(first_row!=last_row) {
> typename MatrixRowIterator::value_type val(0);
> MatrixColIterator first_col, last_col;
> first_col=first_row.begin();
> last_col=first_row.end();
> while(first_col!=last_col) val+= *first_col++ * *first_vec++;
> *result++ = val;
> ++first_row;
> first_vec=cp_first;
> }
> return result;
> }

I'd write this kind of code, if I'd have to implement new algorithms.

> // user side :
> prod(umatrix.begin1(), umatrix.end1(), umatrix.begin2(),
std_vector.begin(),
> std::back_inserter(std_vector_result));
>
> This of course with the respective preconditions.
>
> Also, wouldn't be a good idea to provide copy c'tor and operators
accepting
> std::vector<> for the ublas::vector<> ?

I'll have to think about it.

Thanks,

Joerg


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net