Opened 13 years ago
Last modified 13 years ago
#4045 new Feature Requests
MultiArray implementation from base, extents, strides
Reported by: | Owned by: | Ronald Garcia | |
---|---|---|---|
Milestone: | To Be Determined | Component: | multi_array |
Version: | Boost 1.42.0 | Severity: | Not Applicable |
Keywords: | Cc: |
Description
It would be useful to have a multi_array_ref constructor or some other MultiArray implementation that can accept explicit stride information rather than storage order information. The former is more flexible and can accomplish things the latter cannot (see example below).
I sent the following question to boost-users (http://lists.boost.org/boost-users/2010/03/57634.php):
I'd like to obtain an N-dimensional MultiArray implementation given a base pointer, N extents, and N strides. My use case requires padding the stride in one dimension in a way seemingly not obtainable taking views of the usual boost::multi_array_ref.
Code like the following would be ideal
boost::array<std::size_t,3> extents = { 2, 3, 4 }; boost::array<std::size_t,3> strides = { 1, 2, 7 }; // Note 7 not 6 boost::scoped_array<int> raw(new int[extents[2]*strides[2]]); using boost::detail::multi_array::multi_array_view; multi_array_view<int,3> a(raw.get(), extents, strides);
except that the appropriate constructor in multi_array_view is private (boost/multi_array/view.hpp:442). boost::detail::multi_array::sub_array would also be ideal if it's constructor was accessible (boost/multi_array/subarray.hpp:370). I can make either accessible by #defining BOOST_NO_MEMBER_TEMPLATE_FRIENDS, but that's evil.
Am I missing something in Boost.MultiArray? Or is there no publicly accessible way to provide a custom stride list?
I'd failed to notice that boost::multi_array_ref maintains its stride information in a protected member named stride_list_. I have achieved what I was after by subclassing and modifying stride_list_ directly.
From what I can read in the code, mutating stride_list_ underneath multi_array_ref should have no ill side effects. If it does, what are they? If not, would you please add a constructor to multi_array_ref that supports arbitrary strides by invoking the super_type's constructor and then modifying the stride list directly?