Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do the following (array type is container/iterator range concept):</p> <pre><code>ublas::matrix&lt;douple&gt; A; foreach (double &amp; element, A.data()) { } </code></pre> <p>However, this will not work for slices: your best solution is to write an iterator for them.</p> <p>Here is an example of using <code>multi_array</code> to provide storage of a custom class. Perhaps you could do the same:</p> <pre><code>template&lt;size_t N, typename T&gt; struct tensor_array : boost::multi_array_ref&lt;T,N&gt; { typedef boost::multi_array_ref&lt;T,N&gt; base_type; typedef T value_type; typedef T&amp; reference; typedef const T&amp; const_reference; tensor_array() : base_type(NULL, extents()) { // std::cout &lt;&lt; "create" &lt;&lt; std::endl; } template&lt;class A&gt; tensor_array(const A &amp;dims) : base_type(NULL, extents()) { //std::cout &lt;&lt; "create" &lt;&lt; std::endl; resize(dims); } template&lt;typename U&gt; void resize(const U (&amp;dims)[N]) { boost::array&lt;U,N&gt; dims_; std::copy(dims, dims + N, dims_.begin()); resize(dims_); } template&lt;typename U&gt; void resize(const boost::array&lt;U,N&gt; &amp;dims) { size_t size = 1; boost::array&lt;size_t,N&gt; shape; for (size_t i = 0; i &lt; N; ++i) { size *= dims[i]; shape[N-(i+1)] = dims[i]; } data_.clear(); data_.resize(size, 0); // update base_type parent set_base_ptr(&amp;data_[0]); this-&gt;num_elements_ = size; reshape(shape); } size_t size() const { return data_.size(); } size_t size(size_t i) const { return this-&gt;shape()[N-(i+1)]; } tensor_array&amp; fill(const T &amp;value) { std::fill(data_.begin(), data_.end(), value); return *this; } private: typedef boost::detail::multi_array::extent_gen&lt;N&gt; extents; std::vector&lt;T&gt; data_; }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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