Boost logo

Ublas :

Subject: [ublas] Misc implementation issues
From: Ernest Turro (ernest.turro_at_[hidden])
Date: 2009-03-02 10:11:10


Hello,

I've just started using ublas and have encountered several issues. I
was wondering if anyone would care to comment.

(1) resize() for compressed matrices with data preservation appears
not to be yet implemented. Instead, I'm creating a copy, resizing
without data preservation and then copying elements back:
         compressed_matrix<bool> temp(M); // make copy of M
         M.resize(m,n,false); // resize without data preservation
         for(boolMatIt1 i1 = temp.begin1(); i1 != temp.end1(); ++i1) {
           for (boolMatIt2 i2 = i1.begin(); i2 != i1.end(); ++i2) {
             M(i2.index1(),i2.index2())= *i2;
           }
         }
  Is someone working on finishing implementing resize()? Is the above
an efficient workaround for now?

(2) Multiplying a compressed matrix of ints times a vector of ints and
returning a vector of ints gives a runtime error (yet multiplying
times a vector of doubles and returning a vector of doubles is fine).
E.g. the following gives a runtime error:
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
using namespace boost::numeric::ublas;
typedef compressed_matrix<int> intMat;
int main() {
   intMat M(10,12);
   const vector<int> ones(12,1);
   vector<int> matches = prod(M, ones);
   return 0;
}
/* runtime error:
Check failed in file /opt/local/include/boost/numeric/ublas/detail/
vector_assign.hpp at line 370:
detail::expression_type_check (v, cv)
terminate called after throwing an instance of
'boost::numeric::ublas::external_logic'
   what(): external logic or bad condition of inputs
Abort trap
*/

(3) The axpy_prod(mat&, vec1&, vec2&) function seems to require that
mat is a square matrix but surely it should only require that
mat.size2() ==vec1.size()==vec2.size(). E.g. the following gives a
runtime error because M has dimension 10x12 (it works fine if
dimension is 12x12):

#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/operation.hpp>
using namespace boost::numeric::ublas;
typedef compressed_matrix<double> intMat;
int main() {
   intMat M(10,12);
   const vector<double> ones(12,1);
   vector<double> matches(12);
   axpy_prod(M, ones, matches);
   return 0;
}
/* runtime error:
Check failed in file /opt/local/include/boost/numeric/ublas/detail/
vector_assign.hpp at line 349:
v.size () == e ().size ()
terminate called after throwing an instance of
'boost::numeric::ublas::bad_size'
   what(): bad size
Abort trap
*/

-Ernest