Доступ к подлисе буст-матрицы в классе помощника - PullRequest
1 голос
/ 19 июня 2010

Я пытаюсь создать класс, который облегчает использование boost boost :: numeric :: ublas :: matrix. Таким образом, я получил:

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

И я дополнительно определяю SubMatrix() следующим образом:

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;
}  

Я бы хотел иметь возможность легко создавать новые Tensor s, захватывая подматрицы из Tensor Компилятор жалуется на следующее:

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

После нескольких попыток утешить компилятор, я в тупике. В чем проблема, и почему я не могу просто создать matrix_slice так, как он написан?

1 Ответ

1 голос
/ 11 февраля 2011

matrix_slice требует ссылки в качестве первого аргумента, в то время как вы даете ему указатель (this).Вместо этого попробуйте использовать *this.

Кроме того, поскольку у вас SubMatrix метод имеет квалификатор const, тип * это будет matrix_t const&, поэтому вы должны использовать matrix_slice<matrix_t const>.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...