Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MultiArray2View.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MultiArray2View.h (C) 2000-2025 */
9/* */
10/* View of a 2D array with multiple sizes. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_MULTIARRAY2VIEW_H
13#define ARCANE_UTILS_MULTIARRAY2VIEW_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arcane/utils/ArrayView.h"
19
20#include <type_traits>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
34template <class DataType>
36{
37 public:
38
41 : m_buffer(buf)
42 , m_indexes(indexes)
43 , m_sizes(sizes)
44 {}
45
46 MultiArray2View() = default;
47
48 public:
49
51 Int32 dim1Size() const { return m_sizes.size(); }
52
57 ARCANE_DEPRECATED_122 Int32 size() const { return dim1Size(); }
58
60 ConstArrayView<Int32> dim2Sizes() const { return m_sizes; }
61
63 Int32 totalNbElement() const { return m_buffer.size(); }
64
65 public:
66
69 {
70 return ArrayView<DataType>(this->m_sizes[i], &this->m_buffer[this->m_indexes[i]]);
71 }
72
74 {
75 return ConstArrayView<DataType>(this->m_sizes[i], this->m_buffer.data() + (this->m_indexes[i]));
76 }
77
78 private:
79
80 ArrayView<DataType> m_buffer;
81 ConstArrayView<Int32> m_indexes;
83};
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
91template <class DataType>
93{
94 private:
95
96 friend class MultiArray2<DataType>;
97
98 public:
99
103 : m_buffer(buf)
104 , m_indexes(indexes)
105 , m_sizes(sizes)
106 {}
107
110
111 public:
112
114 Int32 dim1Size() const { return m_sizes.size(); }
115
120 ARCANE_DEPRECATED_122 Int32 size() const { return dim1Size(); }
121
123 ConstArrayView<Int32> dim2Sizes() const { return m_sizes; }
124
126 Int32 totalNbElement() const { return m_buffer.size(); }
127
128 public:
129
132 {
133 return ConstArrayView<DataType>(this->m_sizes[i], this->m_buffer.data() + (this->m_indexes[i]));
134 }
135
136 private:
137
139 ConstArrayView<Int32> m_indexes;
140 ConstArrayView<Int32> m_sizes;
141};
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
152template <class DataType>
154{
155 private:
156
157 friend class MultiArray2<std::remove_cv_t<DataType>>;
158
159 public:
160
162 JaggedSmallSpan() = default;
163
164 private:
165
167 JaggedSmallSpan(SmallSpan<DataType> buf, SmallSpan<const Int32> indexes,
168 SmallSpan<const Int32> sizes)
169 : m_buffer(buf)
170 , m_indexes(indexes)
171 , m_sizes(sizes)
172 {}
173
174 public:
175
177 constexpr ARCCORE_HOST_DEVICE Int32 dim1Size() const { return m_sizes.size(); }
178
180 constexpr ARCCORE_HOST_DEVICE SmallSpan<const Int32> dim2Sizes() const { return m_sizes; }
181
183 constexpr ARCCORE_HOST_DEVICE Int32 totalNbElement() const { return m_buffer.size(); }
184
185 public:
186
188 constexpr ARCCORE_HOST_DEVICE SmallSpan<DataType> operator[](Int32 i) const
189 {
190 return m_buffer.subSpan(m_indexes[i], m_sizes[i]);
191 }
192
193 private:
194
195 SmallSpan<DataType> m_buffer;
196 SmallSpan<const Int32> m_indexes;
198};
199
200/*---------------------------------------------------------------------------*/
201/*---------------------------------------------------------------------------*/
202
203} // namespace Arcane
204
205/*---------------------------------------------------------------------------*/
206/*---------------------------------------------------------------------------*/
207
208#endif
Declarations of types used in Arcane.
Modifiable view of an array of type T.
Constant view of an array of type T.
ARCANE_DEPRECATED_122 Int32 size() const
Number of elements in the first dimension.
ConstMultiArray2View()=default
Empty view.
Int32 totalNbElement() const
Total number of elements in the array.
Int32 dim1Size() const
Number of elements in the first dimension.
ConstMultiArray2View(ConstArrayView< DataType > buf, ConstArrayView< Int32 > indexes, ConstArrayView< Int32 > sizes)
View on the array buf.
ConstArrayView< Int32 > dim2Sizes() const
Number of elements in the second dimension.
ConstArrayView< DataType > operator[](Int32 i) const
The i-th element of the array.
constexpr __host__ __device__ Int32 totalNbElement() const
Total number of elements in the array.
JaggedSmallSpan()=default
Empty view.
constexpr __host__ __device__ Int32 dim1Size() const
Number of elements in the first dimension.
constexpr __host__ __device__ SmallSpan< DataType > operator[](Int32 i) const
The i-th element of the array.
constexpr __host__ __device__ SmallSpan< const Int32 > dim2Sizes() const
Number of elements in the second dimension.
MultiArray2View(ArrayView< DataType > buf, ConstArrayView< Int32 > indexes, ConstArrayView< Int32 > sizes)
View on the array buf.
ConstArrayView< DataType > operator[](Int32 i) const
The i-th element of the array.
ArrayView< DataType > operator[](Int32 i)
The i-th element of the array.
Int32 totalNbElement() const
Total number of elements in the array.
Int32 dim1Size() const
Number of elements in the first dimension.
ARCANE_DEPRECATED_122 Int32 size() const
Number of elements in the first dimension.
MultiArray2View()=default
Empty view.
ConstArrayView< Int32 > dim2Sizes() const
Number of elements in the second dimension.
Base class for multi-sized 2D arrays.
Definition MultiArray2.h:60
View of an array of elements of type T.
Definition Span.h:805
constexpr __host__ __device__ SmallSpan< T, DynExtent > subSpan(Int32 abegin, Int32 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:899
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Signed integer type of 32 bits.