Boost logo

Boost Users :

From: vladimir josef sykora (yg-boost-users_at_[hidden])
Date: 2003-03-26 05:25:58


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<>.
Since _all_ of ublas data containers provide iterators, I'm wondering why
the library doesn't provide algorithms that work on iterators? In this way
data structures and operators will be decoupled.
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;
  }

// 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<> ?
Regards,

--
vladimir josef sykora
morphochem AG
gmunder str. 37-37a
81379 muenchen
tel. ++49-89-78005-0
fax  ++49-89-78005-555
vladimir.sykora_at_[hidden]
http://www.morphochem.de

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