64 using ConstReferenceType =
typename UniqueArray<DataType>::ConstReferenceType;
65 using ThatClass = MultiArray2<DataType>;
69 MultiArray2() =
default;
78 MultiArray2(
const ThatClass& rhs) =
delete;
79 ThatClass& operator=(
const ThatClass& rhs) =
delete;
89 : m_buffer(do_clone ? rhs.m_buffer.clone() : rhs.m_buffer)
90 , m_indexes(do_clone ? rhs.m_indexes.clone() : rhs.m_indexes)
91 , m_sizes(do_clone ? rhs.m_sizes.clone() : rhs.m_sizes)
95 : m_buffer(aview.m_buffer)
96 , m_indexes(aview.m_indexes)
97 , m_sizes(aview.m_sizes)
100 explicit MultiArray2(
const MemoryAllocationOptions& allocation_options)
101 : m_buffer(allocation_options)
102 , m_indexes(allocation_options)
103 , m_sizes(allocation_options)
106 MultiArray2(
const MemoryAllocationOptions& allocation_options, ConstArrayView<Int32> sizes)
107 : MultiArray2(allocation_options)
114 ArrayView<DataType> operator[](
Integer i)
116 return ArrayView<DataType>(m_sizes[i], m_buffer.data() + (m_indexes[i]));
118 ConstArrayView<DataType> operator[](
Integer i)
const
120 return ConstArrayView<DataType>(m_sizes[i], m_buffer.data() + (m_indexes[i]));
142 return m_buffer[m_indexes[i] + j];
146 return m_buffer[m_indexes[i] + j];
150 return m_buffer.setAt(m_indexes[i] + j, v);
188 return { m_buffer.smallSpan(), m_indexes, m_sizes };
194 return { m_buffer, m_indexes, m_sizes };
200 return { m_buffer.constSmallSpan(), m_indexes, m_sizes };
206 return m_buffer.view();
212 return m_buffer.constView();
218 if (new_sizes.
empty()) {
234 void _resize(ConstArrayView<Int32> ar)
240 for (
Integer i = 0; i < size1; ++i)
245 if (total_size ==
totalNbElement() && size1 == m_indexes.size()) {
247 for (
Integer i = 0; i < size1; ++i)
248 if (m_sizes[i] != ar[i]) {
256 Integer old_size1 = m_indexes.size();
258 SharedArray<DataType> new_buffer(m_buffer.allocationOptions(), total_size);
261 if (old_size1 > size1)
264 for (
Integer i = 0; i < old_size1; ++i) {
266 Integer old_size2 = m_sizes[i];
267 if (old_size2 > size2)
269 ConstArrayView<DataType> cav(_value(i));
270 for (
Integer j = 0; j < old_size2; ++j)
271 new_buffer[index + j] = cav[j];
274 m_buffer = new_buffer;
276 m_indexes.resize(size1);
277 m_sizes.resize(size1);
278 for (
Integer i2 = 0, index2 = 0; i2 < size1; ++i2) {
280 m_indexes[i2] = index2;
288 void _copy(
const MultiArray2<DataType>& rhs,
bool do_clone)
290 m_buffer = do_clone ? rhs.m_buffer.clone() : rhs.m_buffer;
291 m_indexes = do_clone ? rhs.m_indexes.clone() : rhs.m_indexes;
292 m_sizes = do_clone ? rhs.m_sizes.clone() : rhs.m_sizes;
294 void _copy(ConstMultiArray2View<DataType> aview)
296 m_buffer = aview.m_buffer;
297 m_indexes = aview.m_indexes;
298 m_sizes = aview.m_sizes;
304 SharedArray<DataType> m_buffer;
306 SharedArray<Int32> m_indexes;
308 SharedArray<Int32> m_sizes;
373class UniqueMultiArray2
374:
public MultiArray2<DataType>
378 using ThatClass = UniqueMultiArray2<DataType>;
382 UniqueMultiArray2() =
default;
384 : MultiArray2<DataType>(sizes)
386 explicit UniqueMultiArray2(IMemoryAllocator* allocator)
387 : UniqueMultiArray2(MemoryAllocationOptions(allocator))
389 explicit UniqueMultiArray2(
const MemoryAllocationOptions& allocation_options)
390 : MultiArray2<DataType>(allocation_options)
392 UniqueMultiArray2(
const MemoryAllocationOptions& allocation_options,
394 : MultiArray2<DataType>(allocation_options, sizes)
397 : MultiArray2<DataType>(
view)
400 : MultiArray2<DataType>(rhs,
true)
402 UniqueMultiArray2(
const UniqueMultiArray2<DataType>& rhs)
403 : MultiArray2<DataType>(rhs,
true)
410 this->_copy(rhs,
true);
419 ThatClass& operator=(
const UniqueMultiArray2<DataType>& rhs)
422 this->_copy(rhs,
true);
425 ThatClass& operator=(
const MultiArray2<DataType>& rhs) =
delete;
430 UniqueMultiArray2<DataType>
clone()
const
432 return UniqueMultiArray2<DataType>(this->
constView());