views:

24

answers:

0

I'm trying to build a class that eases the use of the boost boost::numeric::ublas::matrix. Thus I've got:

using namespace boost::numeric::ublas;
typedef matrix<double> matrix_t;

class Tensor : public matrix_t {

  public:
    Tensor (const int M, const int N) : matrix_t(M, N) { } 
    virtual ~Tensor() { } 

    Tensor SubMatrix (const int start1, const int size1, const int start2, const int size2) const;

    void Print() const;

}; // tensor

And I further define the SubMatrix() as follows:

Tensor Tensor::SubMatrix (const int start1, const int size1, const int start2, const int size2) const {

  matrix_slice<matrix_t> s (this, slice(start1, 1, size1), slice(start2, 1, size2));
  Tensor t (matrix_expression<matrix_t> (s));

  return t;
}  

I'd like to be able to easily create new Tensors by grabbing sub-matrices from within a Tensor. The compiler is complaining with the following:

g++ -ftemplate-depth-100 -Drestrict= -Wall -Wno-deprecated -g3 -ggdb -Wall -D_GLIBCXX_DEBUG  -I/home/eshamay/md/src -I/home/eshamay/share/include -I/usr/include -I/usr/local/include -I/home/eshamay/src/boost-1_43_0  -L/home/eshamay/share/lib -L/home/eshamay/src/lapack-3.2.1 -lconfig++  -c -o morita2002.o morita2002.cpp
morita2002.cpp: In member function ‘morita::math::Tensor morita::math::Tensor::SubMatrix(int, int, int, int) const’:
morita2002.cpp:109: error: no matching function for call to ‘boost::numeric::ublas::matrix_slice<boost::numeric::ublas::matrix<double, boost::numeric::ublas::          basic_row_major<long unsigned int, long int>, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > > >::matrix_slice(const morita::math::Tensor* const,  boost::numeric::ublas::slice, boost::numeric::ublas::slice)’
/usr/include/boost/numeric/ublas/matrix_proxy.hpp:3192: note: candidates are: boost::numeric::ublas::matrix_slice<E>::matrix_slice(const typename boost::mpl::          if_<boost::is_const<T>, typename M::const_closure_type, typename M::closure_type>::type&, const boost::numeric::ublas::basic_slice<typename A::size_type, typename A::      difference_type>&, const boost::numeric::ublas::basic_slice<typename A::size_type, typename A::difference_type>&, int) [with M = boost::numeric::ublas::matrix<double,      boost::numeric::ublas::basic_row_major<long unsigned int, long int>, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >]
/usr/include/boost/numeric/ublas/matrix_proxy.hpp:3183: note:                 boost::numeric::ublas::matrix_slice<E>::matrix_slice(M&, const boost::numeric::ublas::    basic_slice<typename A::size_type, typename A::difference_type>&, const boost::numeric::ublas::basic_slice<typename A::size_type, typename A::difference_type>&) [with M =  boost::numeric::ublas::matrix<double, boost::numeric::ublas::basic_row_major<long unsigned int, long int>, boost::numeric::ublas::unbounded_array<double, std::             allocator<double> > >]
/usr/include/boost/numeric/ublas/matrix_proxy.hpp:3155: note:                 boost::numeric::ublas::matrix_slice<boost::numeric::ublas::matrix<double, boost::numeric::ublas::basic_row_major<long unsigned int, long int>, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > > >::matrix_slice(const boost::numeric::ublas::matrix_slice<boost::numeric::ublas::matrix<double, boost::numeric::ublas::basic_row_major<long unsigned int, long int>, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > > >&)
morita2002.cpp:112: error: conversion from ‘morita::math::Tensor (*)(boost::numeric::ublas::matrix_expression<boost::numeric::ublas::matrix<double, boost::numeric::    ublas::basic_row_major<long unsigned int, long int>, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > > >)’ to non-scalar type ‘morita::math::       Tensor’ requested

After attempting a number of variations to appease the compiler, I'm stumped. What's the issue, and why can't I just create the matrix_slice the way it's written?