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)
103 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
110 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
111 ARCCORE_HOST_DEVICE
Span2Impl(
const Span2<X>& from)
120 constexpr ARCCORE_HOST_DEVICE SizeType
dim1Size()
const {
return m_dim1_size; }
122 constexpr ARCCORE_HOST_DEVICE SizeType
dim2Size()
const {
return m_dim2_size; }
124 constexpr ARCCORE_HOST_DEVICE SizeType
totalNbElement()
const {
return m_dim1_size * m_dim2_size; }
130 ARCCORE_CHECK_AT(i, m_dim1_size);
134 constexpr ARCCORE_HOST_DEVICE SpanImpl<ElementType, SizeType> operator()(SizeType i)
const
136 ARCCORE_CHECK_AT(i, m_dim1_size);
137 return SpanImpl<ElementType, SizeType>(m_ptr + (m_dim2_size * i), m_dim2_size);
140 constexpr ARCCORE_HOST_DEVICE reference operator()(SizeType i, SizeType j)
const
142 ARCCORE_CHECK_AT2(i, j, m_dim1_size, m_dim2_size);
143 return m_ptr[(m_dim2_size * i) + j];
146#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
147 constexpr ARCCORE_HOST_DEVICE reference operator[](SizeType i, SizeType j)
const
149 ARCCORE_CHECK_AT2(i, j, m_dim1_size, m_dim2_size);
150 return m_ptr[(m_dim2_size * i) + j];
155 constexpr ARCCORE_HOST_DEVICE ElementType
item(SizeType i, SizeType j)
const
157 ARCCORE_CHECK_AT2(i, j, m_dim1_size, m_dim2_size);
158 return m_ptr[(m_dim2_size * i) + j];
162 constexpr ARCCORE_HOST_DEVICE ElementType
setItem(SizeType i, SizeType j,
const ElementType& value)
164 ARCCORE_CHECK_AT2(i, j, m_dim1_size, m_dim2_size);
165 m_ptr[(m_dim2_size * i) + j] = value;
177 return view_type(m_ptr, s1, s2);
196 constexpr ARCCORE_HOST_DEVICE ElementType*
data() {
return m_ptr; }
199 constexpr ARCCORE_HOST_DEVICE
const ElementType*
data()
const {
return m_ptr; }
204 template <
typename X, SizeType XExtent1, SizeType XExtent2,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
207 return impl::areEqual2D(rhs, lhs);
210 template <
typename X, SizeType XExtent1, SizeType XExtent2,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
213 return !impl::areEqual2D(rhs, lhs);
216 template <SizeType XExtent1, SizeType XExtent2>
219 return impl::areEqual2D(rhs, lhs);
222 template <SizeType XExtent1, SizeType XExtent2>
225 return !impl::areEqual2D(rhs, lhs);
231 SizeType m_dim1_size;
232 SizeType m_dim2_size;
246template <
class T, Int32 Extent1, Int32 Extent2>
248:
public Span2Impl<T, Int32, Extent1, Extent2>
250 friend class Span2<T>;
256 using size_type =
Int32;
257 using value_type =
typename BaseClass::value_type;
258 using pointer =
typename BaseClass::pointer;
259 using BaseClass::operator();
260 using BaseClass::operator[];
261 using ElementType =
typename BaseClass::ElementType;
265 using BaseClass::m_dim1_size;
266 using BaseClass::m_dim2_size;
267 using BaseClass::m_ptr;
273 : BaseClass(ptr, dim1_size, dim2_size)
285 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
290 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
297 ARCCORE_HOST_DEVICE SmallSpan<ElementType> operator[](
Int32 i)
const
299 ARCCORE_CHECK_AT(i, m_dim1_size);
300 return SmallSpan<ElementType>(m_ptr + (m_dim2_size * i), m_dim2_size);
303 ARCCORE_HOST_DEVICE SmallSpan<ElementType> operator()(
Int32 i)
const
305 ARCCORE_CHECK_AT(i, m_dim1_size);
306 return SmallSpan<ElementType>(m_ptr + (m_dim2_size * i), m_dim2_size);
321template <
class T, Int64 Extent1, Int64 Extent2>
323:
public Span2Impl<T, Int64, Extent1, Extent2>
329 using size_type =
Int64;
330 using value_type =
typename BaseClass::value_type;
331 using pointer =
typename BaseClass::pointer;
332 using BaseClass::operator();
333 using BaseClass::operator[];
334 using ElementType =
typename BaseClass::ElementType;
338 using BaseClass::m_dim1_size;
339 using BaseClass::m_dim2_size;
340 using BaseClass::m_ptr;
346 : BaseClass(ptr, dim1_size, dim2_size)
358 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
369 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
375 template <
typename X,
typename = std::enable_if_t<std::is_same_v<X, value_type>>>
376 ARCCORE_HOST_DEVICE
Span2(
const SmallSpan2<X>& from)
382 ARCCORE_HOST_DEVICE Span<ElementType> operator[](
Int64 i)
const
384 ARCCORE_CHECK_AT(i, m_dim1_size);
385 return Span<ElementType>(m_ptr + (m_dim2_size * i), m_dim2_size);
388 ARCCORE_HOST_DEVICE Span<ElementType> operator()(
Int64 i)
const
390 ARCCORE_CHECK_AT(i, m_dim1_size);
391 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()
Pointer to the allocated memory.
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__ SizeType dim2Size() const
Number of elements in the second dimension.
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].
constexpr __host__ __device__ SizeType totalNbElement() const
Total number of elements.
__host__ __device__ Span2Impl()
Creates an empty 2D view.
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__ SizeType dim1Size() const
Number of elements in the first dimension.
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.