Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ArrayViewCommon.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* ArrayViewCommon.h (C) 2000-2023 */
9/* */
10/* Déclarations communes aux classes ArrayView, ConstArrayView et Span. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_BASE_ARRAYVIEWCOMMON_H
13#define ARCCORE_BASE_ARRAYVIEWCOMMON_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/ArrayIterator.h"
18
19#include <iostream>
20
21// 'assert' est nécessaire pour le code accélérateur
22#include <assert.h>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arccore::impl
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
34template<typename ViewType> ARCCORE_HOST_DEVICE
35auto subViewInterval(ViewType view,
36 typename ViewType::size_type index,
37 typename ViewType::size_type nb_interval) -> ViewType
38{
39 using size_type = typename ViewType::size_type;
40 if (nb_interval<=0)
41 return ViewType();
42 if (index<0 || index>=nb_interval)
43 return ViewType();
44 size_type n = view.size();
45 size_type isize = n / nb_interval;
46 size_type ibegin = index * isize;
47 // Pour le dernier interval, prend les elements restants
48 if ((index+1)==nb_interval)
49 isize = n - ibegin;
50 return ViewType::create(view.data()+ibegin,isize);
51}
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
62template<typename ViewType> inline void
63dumpArray(std::ostream& o,ViewType val,int max_print)
64{
65 using size_type = typename ViewType::size_type;
66 size_type n = val.size();
67 if (max_print>0 && n>max_print){
68 // N'affiche que les (max_print/2) premiers et les (max_print/2) derniers
69 // sinon si le tableau est très grand cela peut générer des
70 // sorties listings énormes.
71 size_type z = (max_print/2);
72 size_type z2 = n - z;
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] << '"';
79 }
80 else{
81 for( size_type i=0; i<n; ++i ){
82 if (i!=0)
83 o << ' ';
84 o << "[" << i << "]=\"" << val[i] << '"';
85 }
86 }
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
93template<typename ViewType> inline bool
94areEqual(ViewType rhs, ViewType lhs)
95{
96 using size_type = typename ViewType::size_type;
97 if (rhs.size()!=lhs.size())
98 return false;
99 size_type s = rhs.size();
100 for( size_type i=0; i<s; ++i ){
101 if (rhs[i]!=lhs[i])
102 return false;
103 }
104 return true;
105}
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
111template<typename View2DType> inline bool
112areEqual2D(View2DType rhs, View2DType lhs)
113{
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())
118 return false;
119 if (dim2_size!=lhs.dim2Size())
120 return false;
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))
124 return false;
125 }
126 }
127 return true;
128}
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132
134extern "C++" ARCCORE_BASE_EXPORT void
135arccoreThrowTooBigInteger [[noreturn]] (std::size_t size);
136
137extern "C++" ARCCORE_BASE_EXPORT void
138arccoreThrowTooBigInt64 [[noreturn]] (std::size_t size);
139
140extern "C++" ARCCORE_BASE_EXPORT void
141arccoreThrowNegativeSize [[noreturn]] (Int64 size);
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
147inline constexpr ARCCORE_HOST_DEVICE void
148arccoreCheckIsPositive(Int64 size)
149{
150 if (size<0){
151#ifdef ARCCORE_DEVICE_CODE
152 assert("'size' is negative");
153#else
154 impl::arccoreThrowNegativeSize(size);
155#endif
156 }
157}
158
160inline constexpr ARCCORE_HOST_DEVICE void
161arccoreCheckIsValidInteger(Int64 size)
162{
163 if (size>=ARCCORE_INTEGER_MAX){
164#ifdef ARCCORE_DEVICE_CODE
165 assert("'size' is bigger than ARCCORE_INTEGER_MAX");
166#else
167 impl::arccoreThrowTooBigInteger(size);
168#endif
169 }
170}
171
173inline constexpr ARCCORE_HOST_DEVICE void
174arccoreCheckIsValidInt64(size_t size)
175{
176 if (size>=ARCCORE_INT64_MAX){
177#ifdef ARCCORE_DEVICE_CODE
178 assert("'size' is bigger than ARCCORE_INT64_MAX");
179#else
180 impl::arccoreThrowTooBigInt64(size);
181#endif
182 }
183}
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188} // End namespace Arccore::impl
189
190namespace Arccore
191{
192
193/*---------------------------------------------------------------------------*/
194/*---------------------------------------------------------------------------*/
201inline constexpr ARCCORE_HOST_DEVICE Integer
202arccoreCheckArraySize(unsigned long long size)
203{
204 impl::arccoreCheckIsValidInteger(size);
205 return static_cast<Integer>(size);
206}
207
214inline constexpr Integer
216{
217 impl::arccoreCheckIsValidInteger(size);
218 impl::arccoreCheckIsPositive(size);
219 return static_cast<Integer>(size);
220}
221
228inline constexpr ARCCORE_BASE_EXPORT Integer
229arccoreCheckArraySize(unsigned long size)
230{
231 impl::arccoreCheckIsValidInteger(size);
232 return static_cast<Integer>(size);
233}
234
242inline constexpr ARCCORE_HOST_DEVICE Integer
244{
245 impl::arccoreCheckIsValidInteger(size);
246 impl::arccoreCheckIsPositive(size);
247 return static_cast<Integer>(size);
248}
249
256inline constexpr ARCCORE_HOST_DEVICE Integer
257arccoreCheckArraySize(unsigned int size)
258{
259 impl::arccoreCheckIsValidInteger(size);
260 return static_cast<Integer>(size);
261}
262
269inline constexpr ARCCORE_HOST_DEVICE Integer
271{
272 impl::arccoreCheckIsValidInteger(size);
273 impl::arccoreCheckIsPositive(size);
274 return static_cast<Integer>(size);
275}
276
284inline constexpr ARCCORE_HOST_DEVICE Int64
286{
287 impl::arccoreCheckIsValidInt64(size);
288 return static_cast<Int64>(size);
289}
290
291/*---------------------------------------------------------------------------*/
292/*---------------------------------------------------------------------------*/
293
294template<typename IntType> class ArraySizeChecker;
295
297template<>
299{
300 public:
301 template<typename SizeType> ARCCORE_HOST_DEVICE
302 static Int32 check(SizeType size)
303 {
304 return arccoreCheckArraySize(size);
305 }
306};
307
309template<>
311{
312 public:
313 static ARCCORE_HOST_DEVICE Int64 check(std::size_t size)
314 {
315 return arccoreCheckLargeArraySize(size);
316 }
317};
318
319/*---------------------------------------------------------------------------*/
320/*---------------------------------------------------------------------------*/
321
322}
323
324/*---------------------------------------------------------------------------*/
325/*---------------------------------------------------------------------------*/
326
327#endif
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Espace de nom de Arccore.
Definition ArcaneTypes.h:24
constexpr ARCCORE_HOST_DEVICE Integer arccoreCheckArraySize(unsigned long long size)
Vérifie que size peut être converti dans un 'Integer' pour servir de taille à un tableau....
Int32 Integer
Type représentant un entier.
std::int64_t Int64
Type entier signé sur 64 bits.
constexpr ARCCORE_HOST_DEVICE Int64 arccoreCheckLargeArraySize(size_t size)
Vérifie que size peut être converti dans un 'Int64' pour servir de taille à un tableau.
std::int32_t Int32
Type entier signé sur 32 bits.
void dumpArray(std::ostream &o, ConstArrayView< T > val, int max_print)
Affiche sur le flot o les valeurs du tableau val.
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition rapidjson.h:385