12#ifndef ARCCORE_BASE_ARRAYVIEWCOMMON_H
13#define ARCCORE_BASE_ARRAYVIEWCOMMON_H
17#include "arccore/base/ArrayIterator.h"
34template <
typename ViewType> ARCCORE_HOST_DEVICE
auto subViewInterval(ViewType view,
35 typename ViewType::size_type index,
36 typename ViewType::size_type nb_interval) -> ViewType
38 using size_type =
typename ViewType::size_type;
41 if (index < 0 || index >= nb_interval)
43 size_type n = view.size();
44 size_type isize = n / nb_interval;
45 size_type ibegin = index * isize;
47 if ((index + 1) == nb_interval)
49 return ViewType::create(view.data() + ibegin, isize);
62template <
typename ViewType>
inline void
63dumpArray(std::ostream& o, ViewType val,
int max_print)
65 using size_type =
typename ViewType::size_type;
66 size_type n = val.size();
67 if (max_print > 0 && n > max_print) {
71 size_type z = (max_print / 2);
73 o <<
"[0]=\"" << val[0] <<
'"';
74 for (size_type i = 1; i < z; ++i)
75 o <<
" [" << i <<
"]=\"" << val[i] <<
'"';
76 o <<
" ... ... (skipping indexes " << z <<
" to " << z2 <<
" ) ... ... ";
77 for (size_type i = (z2 + 1); i < n; ++i)
78 o <<
" [" << i <<
"]=\"" << val[i] <<
'"';
81 for (size_type i = 0; i < n; ++i) {
84 o <<
"[" << i <<
"]=\"" << val[i] <<
'"';
93template <
typename ViewType>
inline bool
94areEqual(ViewType rhs, ViewType lhs)
96 using size_type =
typename ViewType::size_type;
97 if (rhs.size() != lhs.size())
99 size_type s = rhs.size();
100 for (size_type i = 0; i < s; ++i) {
101 if (rhs[i] != lhs[i])
111template <
typename View2DType>
inline bool
112areEqual2D(View2DType rhs, View2DType lhs)
114 using size_type =
typename View2DType::size_type;
115 const size_type dim1_size = rhs.dim1Size();
116 const size_type dim2_size = rhs.dim2Size();
117 if (dim1_size != lhs.dim1Size())
119 if (dim2_size != lhs.dim2Size())
121 for (size_type i = 0; i < dim1_size; ++i) {
122 for (size_type j = 0; j < dim2_size; ++j) {
123 if (rhs(i, j) != lhs(i, j))
134extern "C++" ARCCORE_BASE_EXPORT
void
135arccoreThrowTooBigInteger [[noreturn]] (std::size_t size);
137extern "C++" ARCCORE_BASE_EXPORT
void
138arccoreThrowTooBigInt64 [[noreturn]] (std::size_t size);
140extern "C++" ARCCORE_BASE_EXPORT
void
141arccoreThrowNegativeSize [[noreturn]] (
Int64 size);
147inline constexpr ARCCORE_HOST_DEVICE
void
148arccoreCheckIsPositive(
Int64 size)
151#ifdef ARCCORE_DEVICE_CODE
152 assert(
"'size' is negative");
154 impl::arccoreThrowNegativeSize(size);
160inline constexpr ARCCORE_HOST_DEVICE
void
161arccoreCheckIsValidInteger(
Int64 size)
164#ifdef ARCCORE_DEVICE_CODE
165 assert(
"'size' is bigger than ARCCORE_INTEGER_MAX");
167 impl::arccoreThrowTooBigInteger(size);
173inline constexpr ARCCORE_HOST_DEVICE
void
174arccoreCheckIsValidInt64(
size_t size)
176 if (size >= ARCCORE_INT64_MAX) {
177#ifdef ARCCORE_DEVICE_CODE
178 assert(
"'size' is bigger than ARCCORE_INT64_MAX");
180 impl::arccoreThrowTooBigInt64(size);
202inline constexpr ARCCORE_HOST_DEVICE
Integer
205 impl::arccoreCheckIsValidInteger(size);
206 return static_cast<Integer>(size);
218 impl::arccoreCheckIsValidInteger(size);
219 impl::arccoreCheckIsPositive(size);
220 return static_cast<Integer>(size);
229inline constexpr ARCCORE_BASE_EXPORT
Integer
232 impl::arccoreCheckIsValidInteger(size);
233 return static_cast<Integer>(size);
243inline constexpr ARCCORE_HOST_DEVICE
Integer
246 impl::arccoreCheckIsValidInteger(size);
247 impl::arccoreCheckIsPositive(size);
248 return static_cast<Integer>(size);
257inline constexpr ARCCORE_HOST_DEVICE
Integer
260 impl::arccoreCheckIsValidInteger(size);
261 return static_cast<Integer>(size);
270inline constexpr ARCCORE_HOST_DEVICE
Integer
273 impl::arccoreCheckIsValidInteger(size);
274 impl::arccoreCheckIsPositive(size);
275 return static_cast<Integer>(size);
285inline constexpr ARCCORE_HOST_DEVICE Int64
288 impl::arccoreCheckIsValidInt64(size);
289 return static_cast<Int64>(size);
303 template <
typename SizeType> ARCCORE_HOST_DEVICE
static Int32 check(SizeType size)
315 static ARCCORE_HOST_DEVICE
Int64 check(std::size_t size)
329namespace Arccore::impl
331using Arcane::impl::arccoreCheckIsPositive;
332using Arcane::impl::arccoreCheckIsValidInt64;
333using Arcane::impl::arccoreCheckIsValidInteger;
334using Arcane::impl::arccoreThrowNegativeSize;
335using Arcane::impl::arccoreThrowTooBigInt64;
336using Arcane::impl::arccoreThrowTooBigInteger;
337using Arcane::impl::areEqual;
338using Arcane::impl::areEqual2D;
339using Arcane::impl::dumpArray;
340using Arcane::impl::subViewInterval;
#define ARCCORE_INTEGER_MAX
Macro indicating the maximum value that the Integer type can take.
-- 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.
constexpr __host__ __device__ Int64 arccoreCheckLargeArraySize(size_t size)
Checks that size can be converted into an 'Int64' to serve as an array size.
std::int32_t Int32
Signed integer type of 32 bits.