Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing a subslice of a boost matrix in a helper class
    text
    copied!<p>I'm trying to build a class that eases the use of the boost boost::numeric::ublas::matrix. Thus I've got:</p> <pre><code>using namespace boost::numeric::ublas; typedef matrix&lt;double&gt; 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 </code></pre> <p>And I further define the <code>SubMatrix()</code> as follows:</p> <pre><code>Tensor Tensor::SubMatrix (const int start1, const int size1, const int start2, const int size2) const { matrix_slice&lt;matrix_t&gt; s (this, slice(start1, 1, size1), slice(start2, 1, size2)); Tensor t (matrix_expression&lt;matrix_t&gt; (s)); return t; } </code></pre> <p>I'd like to be able to easily create new <code>Tensor</code>s by grabbing sub-matrices from within a <code>Tensor</code>. The compiler is complaining with the following:</p> <pre><code>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&lt;boost::numeric::ublas::matrix&lt;double, boost::numeric::ublas:: basic_row_major&lt;long unsigned int, long int&gt;, boost::numeric::ublas::unbounded_array&lt;double, std::allocator&lt;double&gt; &gt; &gt; &gt;::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&lt;E&gt;::matrix_slice(const typename boost::mpl:: if_&lt;boost::is_const&lt;T&gt;, typename M::const_closure_type, typename M::closure_type&gt;::type&amp;, const boost::numeric::ublas::basic_slice&lt;typename A::size_type, typename A:: difference_type&gt;&amp;, const boost::numeric::ublas::basic_slice&lt;typename A::size_type, typename A::difference_type&gt;&amp;, int) [with M = boost::numeric::ublas::matrix&lt;double, boost::numeric::ublas::basic_row_major&lt;long unsigned int, long int&gt;, boost::numeric::ublas::unbounded_array&lt;double, std::allocator&lt;double&gt; &gt; &gt;] /usr/include/boost/numeric/ublas/matrix_proxy.hpp:3183: note: boost::numeric::ublas::matrix_slice&lt;E&gt;::matrix_slice(M&amp;, const boost::numeric::ublas:: basic_slice&lt;typename A::size_type, typename A::difference_type&gt;&amp;, const boost::numeric::ublas::basic_slice&lt;typename A::size_type, typename A::difference_type&gt;&amp;) [with M = boost::numeric::ublas::matrix&lt;double, boost::numeric::ublas::basic_row_major&lt;long unsigned int, long int&gt;, boost::numeric::ublas::unbounded_array&lt;double, std:: allocator&lt;double&gt; &gt; &gt;] /usr/include/boost/numeric/ublas/matrix_proxy.hpp:3155: note: boost::numeric::ublas::matrix_slice&lt;boost::numeric::ublas::matrix&lt;double, boost::numeric::ublas::basic_row_major&lt;long unsigned int, long int&gt;, boost::numeric::ublas::unbounded_array&lt;double, std::allocator&lt;double&gt; &gt; &gt; &gt;::matrix_slice(const boost::numeric::ublas::matrix_slice&lt;boost::numeric::ublas::matrix&lt;double, boost::numeric::ublas::basic_row_major&lt;long unsigned int, long int&gt;, boost::numeric::ublas::unbounded_array&lt;double, std::allocator&lt;double&gt; &gt; &gt; &gt;&amp;) morita2002.cpp:112: error: conversion from ‘morita::math::Tensor (*)(boost::numeric::ublas::matrix_expression&lt;boost::numeric::ublas::matrix&lt;double, boost::numeric:: ublas::basic_row_major&lt;long unsigned int, long int&gt;, boost::numeric::ublas::unbounded_array&lt;double, std::allocator&lt;double&gt; &gt; &gt; &gt;)’ to non-scalar type ‘morita::math:: Tensor’ requested </code></pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload