12#ifndef ARCCORE_BASE_SPAN2_H
13#define ARCCORE_BASE_SPAN2_H
18#include "arccore/base/TraceInfo.h"
64template <
typename T,
typename SizeType, SizeType Extent1, SizeType Extent2>
71 using ElementType = T;
72 using element_type = ElementType;
73 using value_type =
typename std::remove_cv<ElementType>::type;
74 using index_type = SizeType;
75 using difference_type = SizeType;
76 using size_type = SizeType;
77 using pointer = ElementType*;
78 using const_pointer =
typename std::add_const<ElementType*>::type;
79 using reference = ElementType&;
80 using const_reference =
const ElementType&;
81 using view_type =
typename detail::View2TypeT<ElementType>::view_type;
85 using is_same_const_type = std::enable_if_t<std::is_same_v<X, T> || std::is_same_v<std::add_const_t<X>, T>>;
90 ARCCORE_HOST_DEVICE
Span2Impl(pointer ptr, SizeType dim1_size, SizeType dim2_size)
92 , m_dim1_size(dim1_size)
93 , m_dim2_size(dim2_size)
99 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
106 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
116 constexpr ARCCORE_HOST_DEVICE SizeType
dim1Size()
const {
return m_dim1_size; }
118 constexpr ARCCORE_HOST_DEVICE SizeType
dim2Size()
const {
return m_dim2_size; }
120 constexpr ARCCORE_HOST_DEVICE SizeType
totalNbElement()
const {
return m_dim1_size * m_dim2_size; }
126 ARCCORE_CHECK_AT(i, m_dim1_size);
130 constexpr ARCCORE_HOST_DEVICE SpanImpl<ElementType, SizeType> operator()(
SizeType i)
const
132 ARCCORE_CHECK_AT(i, m_dim1_size);
133 return SpanImpl<ElementType, SizeType>(m_ptr + (m_dim2_size * i), m_dim2_size);
136 constexpr ARCCORE_HOST_DEVICE reference operator()(
SizeType i,
SizeType j)
const
138 ARCCORE_CHECK_AT2(i, j, m_dim1_size, m_dim2_size);
139 return m_ptr[(m_dim2_size * i) + j];
142#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
143 constexpr ARCCORE_HOST_DEVICE reference operator[](
SizeType i,
SizeType j)
const
145 ARCCORE_CHECK_AT2(i, j, m_dim1_size, m_dim2_size);
146 return m_ptr[(m_dim2_size * i) + j];
151 constexpr ARCCORE_HOST_DEVICE ElementType
item(SizeType i, SizeType j)
const
153 ARCCORE_CHECK_AT2(i, j, m_dim1_size, m_dim2_size);
154 return m_ptr[(m_dim2_size * i) + j];
158 constexpr ARCCORE_HOST_DEVICE ElementType
setItem(SizeType i, SizeType j,
const ElementType& value)
160 ARCCORE_CHECK_AT2(i, j, m_dim1_size, m_dim2_size);
161 m_ptr[(m_dim2_size * i) + j] = value;
173 return view_type(m_ptr, s1, s2);
192 constexpr ARCCORE_HOST_DEVICE ElementType*
data() {
return m_ptr; }
195 constexpr ARCCORE_HOST_DEVICE
const ElementType*
data()
const {
return m_ptr; }
200 template <
typename X, SizeType XExtent1, SizeType XExtent2,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
203 return Arcane::Impl::areEqual2D(rhs, lhs);
206 template <
typename X, SizeType XExtent1, SizeType XExtent2,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
209 return !Arcane::Impl::areEqual2D(rhs, lhs);
212 template <SizeType XExtent1, SizeType XExtent2>
215 return Arcane::Impl::areEqual2D(rhs, lhs);
218 template <SizeType XExtent1, SizeType XExtent2>
221 return !Arcane::Impl::areEqual2D(rhs, lhs);
226 ElementType* m_ptr =
nullptr;
227 SizeType m_dim1_size = 0;
228 SizeType m_dim2_size = 0;
242template <
class T, Int32 Extent1, Int32 Extent2>
244:
public Span2Impl<T, Int32, Extent1, Extent2>
246 friend class Span2<T>;
252 using size_type =
Int32;
253 using value_type =
typename BaseClass::value_type;
254 using pointer =
typename BaseClass::pointer;
255 using BaseClass::operator();
256 using BaseClass::operator[];
257 using ElementType =
typename BaseClass::ElementType;
261 using BaseClass::m_dim1_size;
262 using BaseClass::m_dim2_size;
263 using BaseClass::m_ptr;
269 : BaseClass(ptr, dim1_size, dim2_size)
281 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
286 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
293 ARCCORE_HOST_DEVICE SmallSpan<ElementType> operator[](
Int32 i)
const
295 ARCCORE_CHECK_AT(i, m_dim1_size);
296 return SmallSpan<ElementType>(m_ptr + (m_dim2_size * i), m_dim2_size);
299 ARCCORE_HOST_DEVICE SmallSpan<ElementType> operator()(
Int32 i)
const
301 ARCCORE_CHECK_AT(i, m_dim1_size);
302 return SmallSpan<ElementType>(m_ptr + (m_dim2_size * i), m_dim2_size);
317template <
class T, Int64 Extent1, Int64 Extent2>
319:
public Span2Impl<T, Int64, Extent1, Extent2>
325 using size_type =
Int64;
326 using value_type =
typename BaseClass::value_type;
327 using pointer =
typename BaseClass::pointer;
328 using BaseClass::operator();
329 using BaseClass::operator[];
330 using ElementType =
typename BaseClass::ElementType;
334 using BaseClass::m_dim1_size;
335 using BaseClass::m_dim2_size;
336 using BaseClass::m_ptr;
342 : BaseClass(ptr, dim1_size, dim2_size)
354 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
365 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
371 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
372 ARCCORE_HOST_DEVICE
Span2(
const SmallSpan2<X>& from)
378 ARCCORE_HOST_DEVICE Span<ElementType> operator[](
Int64 i)
const
380 ARCCORE_CHECK_AT(i, m_dim1_size);
381 return Span<ElementType>(m_ptr + (m_dim2_size * i), m_dim2_size);
384 ARCCORE_HOST_DEVICE Span<ElementType> operator()(
Int64 i)
const
386 ARCCORE_CHECK_AT(i, m_dim1_size);
387 return Span<ElementType>(m_ptr + (m_dim2_size * i), m_dim2_size);
Declarations of types for the 'base' component of Arccore.
Types and functions associated with the classes Array2View and ConstArray2View.
Mutable view for a 2D array.
View for a constant 2D array.
Constant view of an array of type T.
View for a 2D array whose size is an 'Int32'.
__host__ __device__ SmallSpan2()
Creates an empty 2D view.
__host__ __device__ SmallSpan2(pointer ptr, Int32 dim1_size, Int32 dim2_size)
Creates a 2D view of dimension [dim1_size][dim2_size].
SmallSpan2(const Array2View< value_type > &from)
Copy constructor from another view.
friend bool operator!=(const ThatClass &lhs, const Span2Impl< T, SizeType, XExtent1, XExtent2 > &rhs)
Inequality operator.
constexpr __host__ __device__ ElementType * data()
friend bool operator==(const ThatClass &lhs, const Span2Impl< X, SizeType, XExtent1, XExtent2 > &rhs)
Equality operator (valid if T is const but not X).
friend bool operator!=(const ThatClass &lhs, const Span2Impl< X, SizeType, XExtent1, XExtent2 > &rhs)
Inequality operator (valid if T is const but not X).
friend bool operator==(const ThatClass &lhs, const Span2Impl< T, SizeType, XExtent1, XExtent2 > &rhs)
Equality operator.
constexpr __host__ __device__ Int32 dim2Size() const
constexpr ElementType * unguardedBasePointer()
Pointer to the allocated memory.
std::enable_if_t< std::is_same_v< X, T >||std::is_same_v< std::add_const_t< X >, T > > is_same_const_type
Indicates if an 'X' or 'const X' can be converted to a 'T'.
constexpr ConstArrayView< value_type > constSmallView() const
Constant view of this view.
__host__ __device__ Span2Impl(pointer ptr, SizeType dim1_size, SizeType dim2_size)
Creates a 2D view of dimension [dim1_size][dim2_size].
constexpr view_type smallView()
Constant view of this view.
constexpr __host__ __device__ ElementType item(SizeType i, SizeType j) const
Value of the element [i][j].
Span2Impl()=default
Creates an empty 2D view.
constexpr __host__ __device__ SizeType totalNbElement() const
Total number of elements.
constexpr __host__ __device__ ElementType setItem(SizeType i, SizeType j, const ElementType &value)
Positions the element [i][j] at value.
constexpr __host__ __device__ const ElementType * data() const
Pointer to the allocated memory.
constexpr __host__ __device__ Int32 dim1Size() const
View for a 2D array whose size is an 'Int64'.
__host__ __device__ Span2(pointer ptr, Int64 dim1_size, Int64 dim2_size)
Creates a 2D view of dimension [dim1_size][dim2_size].
__host__ __device__ Span2()
Creates an empty 2D view.
Span2(const SmallSpan2< T > &from)
Copy constructor from a 'SmallSpan'.
Span2(const Array2View< value_type > &from)
Copy constructor from another view.
View of an array of elements of type T.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
constexpr __host__ __device__ Integer arccoreCheckArraySize(unsigned long long size)
Checks that size can be converted into an 'Integer' to serve as an array size. If possible,...
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
std::int32_t Int32
Signed integer type of 32 bits.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.).