mirror of
https://github.com/boostorg/multi_array.git
synced 2025-05-11 21:33:52 +00:00
Checkpoint. Reformulated construction of multi_array from
(const_)multi_array_ref. Precursor to changing all other multi_array-from-other-array constructors. [SVN r22022]
This commit is contained in:
parent
4b6abe8513
commit
d9bbf46213
@ -89,8 +89,13 @@ public:
|
||||
explicit multi_array() :
|
||||
super_type((T*)initial_base_,
|
||||
c_storage_order(),
|
||||
#if 0
|
||||
detail::multi_array::make_default_array<index,NumDims>(),
|
||||
detail::multi_array::make_default_array<size_type,NumDims>()) {
|
||||
detail::multi_array::make_default_array<size_type,NumDims>()
|
||||
#else
|
||||
0,0
|
||||
#endif
|
||||
) {
|
||||
allocate_space();
|
||||
}
|
||||
|
||||
@ -163,43 +168,27 @@ public:
|
||||
//
|
||||
// A multi_array is constructible from any multi_array_ref, subarray, or
|
||||
// array_view object. The following constructors ensure that.
|
||||
// (Q: Should these be 'explicit'?)
|
||||
//
|
||||
|
||||
|
||||
#if 0
|
||||
template <typename OPtr>
|
||||
multi_array(const const_multi_array_ref<T,NumDims,OPtr>& rhs,
|
||||
const general_storage_order<NumDims>& so = c_storage_order()) :
|
||||
super_type(rhs,so) {
|
||||
allocate_space();
|
||||
// RG: This can be done more efficiently using data,num_elements
|
||||
std::copy(rhs.begin(),rhs.end(),this->begin());
|
||||
}
|
||||
#else
|
||||
template <typename OPtr>
|
||||
multi_array(const const_multi_array_ref<T,NumDims,OPtr>& rhs,
|
||||
const general_storage_order<NumDims>& so = c_storage_order())
|
||||
: super_type(0,so,rhs.index_base_list_,rhs.extent_list_)
|
||||
: super_type(0,so,rhs.index_bases(),rhs.shape())
|
||||
{
|
||||
init_multi_array_ref(rhs.shape());
|
||||
allocate_space();
|
||||
// RG: This can be done more efficiently using data,num_elements
|
||||
std::copy(rhs.begin(),rhs.end(),this->begin());
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
// See note for the constructor from sub_array<T,NumDims>&.
|
||||
// I am assuming that the following constructor is required as well
|
||||
multi_array(const
|
||||
multi_array_ref<T,NumDims>& rhs,
|
||||
const general_storage_order<NumDims>& so = c_storage_order()) :
|
||||
super_type(rhs,so) {
|
||||
allocate_space();
|
||||
// RG: This can be done more efficiently using data,num_elements
|
||||
// Warning! storage order may change, hence the following copy technique.
|
||||
std::copy(rhs.begin(),rhs.end(),this->begin());
|
||||
}
|
||||
|
||||
// This constructor is necessary because of more exact template matches.
|
||||
// enable-if?
|
||||
multi_array(const multi_array_ref<T,NumDims>& rhs,
|
||||
const general_storage_order<NumDims>& so = c_storage_order())
|
||||
: super_type(0,so,rhs.index_bases(),rhs.shape())
|
||||
{
|
||||
allocate_space();
|
||||
// Warning! storage order may change, hence the following copy technique.
|
||||
std::copy(rhs.begin(),rhs.end(),this->begin());
|
||||
}
|
||||
|
||||
template <typename OPtr>
|
||||
multi_array(const detail::multi_array::
|
||||
|
@ -80,21 +80,12 @@ public:
|
||||
// make const_multi_array_ref a friend of itself
|
||||
template <typename,std::size_t,typename>
|
||||
friend class const_multi_array_ref;
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
// RG - this is used to ease constructing a multiarray from a
|
||||
// const_multi_array_ref. It may be better to use the MultiArray concept
|
||||
// to devise a more generic method than this.
|
||||
// make multi_array a friend
|
||||
template <typename,std::size_t,typename>
|
||||
friend class multi_array;
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// This ensures that const_multi_array_ref types with different TPtr
|
||||
// types can convert to each other
|
||||
template <typename OPtr>
|
||||
const_multi_array_ref(const const_multi_array_ref<T,NumDims,
|
||||
OPtr>& other)
|
||||
const_multi_array_ref(const const_multi_array_ref<T,NumDims,OPtr>& other)
|
||||
: base_(other.base_), storage_(other.storage_),
|
||||
extent_list_(other.extent_list_),
|
||||
stride_list_(other.stride_list_),
|
||||
@ -320,8 +311,6 @@ public:
|
||||
}
|
||||
|
||||
|
||||
// This ensures that const_multi_array_ref types with different TPtr
|
||||
// types can convert to each other
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
protected:
|
||||
#else
|
||||
@ -339,13 +328,25 @@ public:
|
||||
explicit
|
||||
const_multi_array_ref(TPtr base,
|
||||
const storage_order_type& so,
|
||||
const index_list& index_base_list,
|
||||
const size_list& extent_list) :
|
||||
base_(base), index_base_list_(index_base_list), storage_(so),
|
||||
origin_offset_(0), directional_offset_(0)
|
||||
const index * index_bases,
|
||||
const size_type* extents) :
|
||||
base_(base), storage_(so), origin_offset_(0), directional_offset_(0)
|
||||
{
|
||||
init_multi_array_ref(extent_list.begin());
|
||||
}
|
||||
// If index_bases or extents is null, then initialize the corresponding
|
||||
// private data to zeroed lists.
|
||||
if(index_bases) {
|
||||
boost::copy_n(index_bases,NumDims,index_base_list_.begin());
|
||||
} else {
|
||||
std::fill_n(index_base_list_.begin(),NumDims,0);
|
||||
}
|
||||
if(extents) {
|
||||
init_multi_array_ref(extents);
|
||||
} else {
|
||||
boost::array<index,NumDims> extent_list;
|
||||
extent_list.assign(0);
|
||||
init_multi_array_ref(extent_list.begin());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// RG - const_multi_array should be PUBLICLy constructible from:
|
||||
@ -357,22 +358,8 @@ public:
|
||||
// Special constructors for constructing a multi_array object from another
|
||||
// array type defined by the library. The new multi_array can specify its
|
||||
// own new storage order.
|
||||
|
||||
|
||||
template <typename OPtr>
|
||||
const_multi_array_ref(const const_multi_array_ref<T,NumDims,OPtr>& rhs,
|
||||
const general_storage_order<NumDims>& so,
|
||||
detail::multi_array::deep_copy_marker const&)
|
||||
: base_(0),
|
||||
storage_(so),
|
||||
origin_offset_(0), directional_offset_(0),
|
||||
num_elements_(rhs.num_elements())
|
||||
{
|
||||
using boost::copy_n;
|
||||
copy_n(rhs.index_bases(),rhs.num_dimensions(),index_base_list_.begin());
|
||||
init_multi_array_ref(rhs.shape());
|
||||
}
|
||||
|
||||
// RG! - these go away!
|
||||
|
||||
template <typename OPtr>
|
||||
const_multi_array_ref(
|
||||
@ -673,9 +660,9 @@ protected:
|
||||
// This is only supplied to support multi_array's default constructor
|
||||
explicit multi_array_ref(T* base,
|
||||
const storage_order_type& so,
|
||||
const index_list& index_base_list,
|
||||
const size_list& extent_list) :
|
||||
super_type(base,so,index_base_list,extent_list) { }
|
||||
const index* index_bases,
|
||||
const size_type* extents) :
|
||||
super_type(base,so,index_bases,extents) { }
|
||||
|
||||
|
||||
//
|
||||
@ -683,12 +670,6 @@ protected:
|
||||
// array types
|
||||
//
|
||||
|
||||
template <typename OPtr>
|
||||
multi_array_ref(const const_multi_array_ref<T,NumDims,OPtr>& rhs,
|
||||
const general_storage_order<NumDims>& so)
|
||||
: super_type(rhs,so,detail::multi_array::deep_copy_marker()) {}
|
||||
|
||||
|
||||
template <typename OPtr>
|
||||
multi_array_ref(const detail::multi_array::
|
||||
const_sub_array<T,NumDims,OPtr>& rhs,
|
||||
|
Loading…
x
Reference in New Issue
Block a user