Arcane  v3.14.11.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TestArrayView.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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#include <gtest/gtest.h>
8
9#include "arccore/base/Span.h"
10#include "arccore/base/Span2.h"
11#include "arccore/base/ArrayView.h"
12#include "arccore/base/Array3View.h"
13#include "arccore/base/Array4View.h"
14
15#include <vector>
16#include <type_traits>
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21TEST(Array2View,Misc)
22{
23 using namespace Arccore;
24 int nb_x = 3;
25 int nb_y = 4;
26 std::vector<Int32> buf(nb_x*nb_y);
27 for( size_t i=0, n=buf.size(); i<n; ++i )
28 buf[i] = (Int32)(i+1);
29
30 ConstArray2View<Int32> v(buf.data(),nb_x,nb_y);
31 Integer global_index = 0;
32 for( Integer x=0, xn=v.dim1Size(); x<xn; ++x ){
33 for( Integer y=0, yn=v.dim2Size(); y<yn; ++y ){
34 ++global_index;
35 Int32 val1 = v[x][y];
36 Int32 val2 = v.item(x,y);
37 std::cout << " V=" << val1 << " x=" << x << " y=" << y;
38 ASSERT_TRUE(val1==val2) << "Difference values v1=" << val1 << " v2=" << val2;
39 ASSERT_TRUE(val1==global_index) << "Bad value v1=" << val1 << " expected=" << global_index;
40 ASSERT_EQ(v(x,y),val1);
41#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
42 bool is_ok = v[x,y]==val1;
43 ASSERT_TRUE(is_ok);
44#endif
45 }
46 }
47}
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52TEST(Array3View,Misc)
53{
54 using namespace Arccore;
55 int nb_x = 3;
56 int nb_y = 4;
57 int nb_z = 5;
58 std::vector<Int32> buf(nb_x*nb_y*nb_z);
59 for( size_t i=0, n=buf.size(); i<n; ++i )
60 buf[i] = (Int32)(i+1);
61
62 ConstArray3View<Int32> v(buf.data(),nb_x,nb_y,nb_z);
63 Integer global_index = 0;
64 for( Integer x=0, xn=v.dim1Size(); x<xn; ++x ){
65 for( Integer y=0, yn=v.dim2Size(); y<yn; ++y ){
66 for( Integer z=0, zn=v.dim3Size(); z<zn; ++z ){
67 ++global_index;
68 Int32 val1 = v[x][y][z];
69 Int32 val2 = v.item(x,y,z);
70 std::cout << " V=" << val1 << " x=" << x << " y=" << y << " z=" << z << '\n';
71 ASSERT_TRUE(val1==val2) << "Difference values v1=" << val1 << " v2=" << val2;
72 ASSERT_TRUE(val1==global_index) << "Bad value v1=" << val1 << " expected=" << global_index;
73 ASSERT_EQ(v(x,y,z),val1);
74#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
75 bool is_ok = v[x,y,z] == val1;
76 ASSERT_TRUE(is_ok);
77#endif
78 }
79 }
80 }
81}
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
86TEST(Array4View,Misc)
87{
88 using namespace Arccore;
89 int nb_x = 2;
90 int nb_y = 3;
91 int nb_z = 4;
92 int nb_a = 5;
93 std::vector<Int32> buf(nb_x*nb_y*nb_z*nb_a);
94 for( size_t i=0, n=buf.size(); i<n; ++i )
95 buf[i] = (Int32)(i+1);
96
97 ConstArray4View<Int32> v(buf.data(),nb_x,nb_y,nb_z,nb_a);
98 Integer global_index = 0;
99 for( Integer x=0, xn=v.dim1Size(); x<xn; ++x ){
100 for( Integer y=0, yn=v.dim2Size(); y<yn; ++y ){
101 for( Integer z=0, zn=v.dim3Size(); z<zn; ++z ){
102 for( Integer a=0, an=v.dim4Size(); a<an; ++a ){
103 ++global_index;
104 Int32 val1 = v[x][y][z][a];
105 Int32 val2 = v.item(x,y,z,a);
106 std::cout << " V=" << val1 << " x=" << x << " y=" << y << " z=" << z << " a=" << a << '\n';
107 ASSERT_TRUE(val1==val2) << "Difference values v1=" << val1 << " v2=" << val2;
108 ASSERT_TRUE(val1==global_index) << "Bad value v1=" << val1 << " expected=" << global_index;
109 ASSERT_EQ(v(x,y,z,a),val1);
110#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
111 bool is_ok = v[x,y,z,a] == val1;
112 ASSERT_TRUE(is_ok);
113#endif
114 }
115 }
116 }
117 }
118}
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123namespace
124{
125template<typename T> void
126_testIterator(T values)
127{
128 {
129 auto r1 = std::make_reverse_iterator(values.end());
130 auto r2 = std::make_reverse_iterator(values.begin());
131 for( ; r1!=r2; ++ r1 ){
132 std::cout << "RVALUE = " << *r1 << '\n';
133 }
134 }
135 {
136 auto r1 = values.rbegin();
137 ASSERT_EQ((*r1),7);
138 ++r1;
139 ASSERT_EQ((*r1),9);
140 ++r1;
141 ASSERT_EQ((*r1),4);
142 ++r1;
143 ASSERT_TRUE((r1==values.rend()));
144 }
145}
146
147}
148
149TEST(ArrayView,Iterator)
150{
151 using namespace Arccore;
152
153 std::vector<Arccore::Int32> vector_values = { 4, 9, 7 };
154 Integer vec_size = arccoreCheckArraySize(vector_values.size());
155
156 ArrayView<Int32> values1(vec_size,vector_values.data());
157 _testIterator(values1);
158
159 ConstArrayView<Int32> values2(vec_size,vector_values.data());
160 _testIterator(values2);
161
162 Span<Int32> values3(vector_values.data(),vector_values.size());
163 _testIterator(values3);
164
165 Span<const Int32> values4(vector_values.data(),vector_values.size());
166 _testIterator(values4);
167}
168
169/*---------------------------------------------------------------------------*/
170/*---------------------------------------------------------------------------*/
171
172TEST(Span,Convert)
173{
174 using namespace Arccore;
175 std::vector<Int64> vector_values = { 5, 7, 11 };
176 Int32 vector_size = static_cast<Int32>(vector_values.size());
177 ArrayView<Int64> a_view(vector_size,vector_values.data());
178 ASSERT_EQ(a_view.size(),vector_size) << "Bad a_view size";
179 ASSERT_EQ(a_view[0],vector_values[0]) << "Bad a_view[0]";
180 ASSERT_EQ(a_view[1],vector_values[1]) << "Bad a_view[1]";
181 ASSERT_EQ(a_view[2],vector_values[2]) << "Bad a_view[2]";
182
183 ConstArrayView<Int64> a_const_view(vector_size,vector_values.data());
184 ASSERT_EQ(a_const_view.size(),vector_size) << "Bad a_const_view size";
185 ASSERT_EQ(a_const_view[0],vector_values[0]) << "Bad a_const_view[0]";
186 ASSERT_EQ(a_const_view[1],vector_values[1]) << "Bad a_const_view[1]";
187 ASSERT_EQ(a_const_view[2],vector_values[2]) << "Bad a_const_view[2]";
188
189 Span<const Int64> a_const_span(vector_values.data(),vector_values.size());
190 Span<Int64> a_span(vector_values.data(),vector_values.size());
191 ByteConstSpan a_const_bytes = asBytes(a_const_span);
192 ByteSpan a_bytes = asWritableBytes(a_span);
193 ByteConstSpan a_const_bytes2 = asBytes(a_span);
194 //ByteSpan a_bytes2 = asWritableBytes(a_const_span);
195 ASSERT_EQ(a_const_bytes.size(),24) << "Bad a_const_bytes_size (1)";
196 ASSERT_EQ(a_const_bytes2.size(),24) << "Bad a_const_bytes2_size (1)";
197 ASSERT_EQ(a_bytes.size(),24) << "Bad a_bytes_size (2)";
198 Span<Int64> span2(a_view);
199 Span<const Int64> span3(a_view);
200 Span<const Int64> span4(a_const_view);
201 ASSERT_EQ(span2.size(),a_view.size()) << "Bad span2 size";
202 ASSERT_EQ(span3.size(),a_view.size()) << "Bad span3 size";
203 ASSERT_EQ(span4.size(),a_const_view.size()) << "Bad span4 size";
204 span3 = a_const_view;
205 span3 = a_view;
206 span2 = a_view;
207 ASSERT_EQ(span2.size(),a_view.size()) << "Bad span2 (2) size";
208 ASSERT_EQ(span3.size(),a_view.size()) << "Bad span3 (2) size";
209 std::cout << "View=" << a_view << '\n';
210 std::cout << "ConstView=" << a_const_view << '\n';
211 std::cout << "Span3=" << span3 << '\n';
212}
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
216
217// Vérifie que \a a1 et \a a2 sont identiques
218template<typename A1,typename A2>
219void _checkSame(A1& a1,A2& a2,const char* message)
220{
221 using namespace Arccore;
222 using size_type = typename A1::size_type;
223 Int64 s1 = a1.size();
224 Int64 s2 = a2.size();
225 ASSERT_EQ(s1,s2) << "Bad size " << message;
226 for( size_type i=0, n=a1.size(); i<n; ++i )
227 ASSERT_EQ(a1[i],a2[i]) << "Bad value[" << i << "]" << message;
228}
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
233// Vérifie que \a a1 et \a a2 sont identiques
234template<typename A1,typename A2>
235void _checkSame2(A1& a1,A2& a2,const char* message)
236{
237 using namespace Arccore;
238 using size_type = typename A1::size_type;
239 const Int64 s1_dim1 = a1.dim1Size();
240 const Int64 s2_dim1 = a2.dim1Size();
241 ASSERT_EQ(s1_dim1,s2_dim1) << "Bad size " << message;
242 const Int64 s1_dim2 = a1.dim2Size();
243 const Int64 s2_dim2 = a2.dim2Size();
244 ASSERT_EQ(s1_dim2,s2_dim2) << "Bad size " << message;
245 for( size_type i=0; i<s1_dim1; ++i )
246 for( size_type j=0; j<s1_dim2; ++j )
247 ASSERT_EQ(a1[i][j],a2[i][j]) << "Bad value[" << i << ',' << j << "]" << message;
248}
249
250/*---------------------------------------------------------------------------*/
251/*---------------------------------------------------------------------------*/
252
253TEST(ArrayView,StdArray)
254{
255 using namespace Arccore;
256 std::array<Int64,0> v0;
257 std::array<Int64,2> v1 { 5, 7 };
258 std::array<Int64,3> v2 { 2, 4, -2 };
259 std::array<const Int64,4> v3 { 9, 13, 32, 27 };
260
261 {
262 ArrayView<Int64> view0 { v0 };
263 _checkSame(view0,v0,"view0==v0");
264
265 ArrayView<Int64> view1 { v1 };
266 _checkSame(view1,v1,"view1==v1");
267
268 view0 = v2;
269 _checkSame(view0,v2,"view0==v2");
270 }
271
272 {
273 ConstArrayView<Int64> view0 { v0 };
274 _checkSame(view0,v0,"const view0==v0");
275
276 ConstArrayView<Int64> view1 { v1 };
277 _checkSame(view1,v1,"const view1==v1");
278
279 view0 = v2;
280 _checkSame(view0,v2,"const view0==v2");
281
282 ConstArrayView<Int64> view2 { v3 };
283 _checkSame(view2,v3,"const view2==v3");
284
285 view1 = v3;
286 _checkSame(view1,v3,"const view1==v3");
287 }
288}
289
290/*---------------------------------------------------------------------------*/
291/*---------------------------------------------------------------------------*/
292
293template<typename SpanType,typename ConstSpanType> void
294_testSpanStdArray()
295{
296 using namespace Arccore;
297 std::array<Int64,0> v0;
298 std::array<Int64,2> v1 { 5, 7 };
299 std::array<Int64,3> v2 { 2, 4, -2 };
300 std::array<const Int64,4> v3 { 9, 13, 32, 27 };
301
302 {
303 SpanType span0 { v0 };
304 _checkSame(span0,v0,"span0==v0");
305
306 SpanType span1 { v1 };
307 _checkSame(span1,v1,"span1==v1");
308
309 SpanType span2 { v1 };
310 ASSERT_TRUE(span1==span2);
311 ASSERT_FALSE(span1!=span2);
312
313 SpanType const_span2 { v1 };
314 ASSERT_TRUE(span1==const_span2);
315 ASSERT_FALSE(span1!=const_span2);
316
317 span0 = v2;
318 _checkSame(span0,v2,"span0==v2");
319 }
320
321 {
322 ConstSpanType span0 { v0 };
323 _checkSame(span0,v0,"const span0==v0");
324
325 ConstSpanType span1 { v1 };
326 _checkSame(span1,v1,"const span1==v1");
327
328 span0 = v2;
329 _checkSame(span0,v2,"const span0==v2");
330
331 ConstSpanType span2 { v3 };
332 _checkSame(span2,v3,"const span2==v3");
333
334 ConstSpanType span3 { v3 };
335 ASSERT_TRUE(span2==span3);
336 ASSERT_FALSE(span2!=span3);
337
338 span1 = v3;
339 _checkSame(span1,v3,"const span1==v3");
340 }
341 {
342 SpanType span1 { v1 };
343 ConstSpanType const_span1 { v1 };
344 ASSERT_TRUE(span1==const_span1);
345
346 SpanType span2 { v2 };
347 ConstSpanType const_span3 { v3 };
348 ASSERT_TRUE(span2!=const_span3);
349 }
350}
351
352/*---------------------------------------------------------------------------*/
353/*---------------------------------------------------------------------------*/
354
355TEST(Span, StdArray)
356{
357 using namespace Arccore;
358 _testSpanStdArray<Span<Int64>, Span<const Int64>>();
359
360 std::array<Int64, 0> v0;
361 std::array<Int64, 2> v1{ 5, 7 };
362 std::array<Int64, 3> v2{ 2, 4, -2 };
363 auto s0 = asSpan(v0);
364 _checkSame(s0, v0, "s0==v0");
365 auto s1 = asSpan(v1);
366 _checkSame(s1, v1, "s1==v1");
367 auto s2 = asSpan(v2);
368 _checkSame(s2, v2, "s2==v2");
369
370 auto sp0 = asSmallSpan(v0);
371 _checkSame(sp0, v0, "s0==v0");
372 auto sp1 = asSmallSpan(v1);
373 _checkSame(sp1, v1, "s1==v1");
374 auto sp2 = asSmallSpan(v2);
375 _checkSame(sp2, v2, "s2==v2");
376
377 {
378 Span<Int64> ss0(s0);
379 auto bytes = asBytes(ss0);
380 auto x = asSpan<Int64>(bytes);
381 ASSERT_EQ(x.data(), nullptr);
382 ASSERT_EQ(x.size(), 0);
383 }
384 {
385 SmallSpan<Int64> ssp0(sp0);
386 auto bytes = asBytes(ssp0);
387 auto x = asSmallSpan<Int64>(bytes);
388 ASSERT_EQ(x.data(), nullptr);
389 ASSERT_EQ(x.size(), 0);
390 }
391
392 {
393 auto bytes = asWritableBytes(s1);
394 auto x = asSpan<Int64>(bytes);
395 _checkSame(x, v1, "x==v1");
396 }
397
398 {
399 auto bytes = asWritableBytes(s2);
400 auto x = asSpan<Int64>(bytes);
401 _checkSame(x, v2, "x==v2");
402 x[2] = 5;
403 ASSERT_EQ(v2[2], 5);
404 }
405
406 {
407 auto bytes = asWritableBytes(sp2);
408 auto x = asSmallSpan<Int64>(bytes);
409 _checkSame(x, v2, "x==v2");
410 x[2] = 5;
411 ASSERT_EQ(v2[2], 5);
412 }
413
414 {
415 std::array<Int64,2> v1 { 5, 7 };
416 std::array<Int64,3> v2 { 2, 4, -2 };
417 Span<Int64,2> fixed_s1(v1);
418 Span<Int64,3> fixed_s2(v2);
419 ASSERT_FALSE(fixed_s1==fixed_s2);
420 ASSERT_TRUE(fixed_s1!=fixed_s2);
421
422 LargeSpan<const Int64> s1_a(s1);
425 ASSERT_FALSE(fb1==fb2);
426
427 std::array<Real, 3> v2r{ 2.0, 4.1, -2.3 };
428 SmallSpan<const Real> small2(v2r);
429 LargeSpan<const std::byte> small_fb2(asBytes(small2));
430
431 Span<Int64,DynExtent,-1> a4(v2.data()+1,v2.size()-1);
432 ASSERT_EQ(a4[-1],2);
433 }
434}
435
436/*---------------------------------------------------------------------------*/
437/*---------------------------------------------------------------------------*/
438
439TEST(SmallSpan,StdArray)
440{
441 using namespace Arccore;
442 _testSpanStdArray<SmallSpan<Int64>,SmallSpan<const Int64>>();
443}
444
445/*---------------------------------------------------------------------------*/
446/*---------------------------------------------------------------------------*/
447
448template<typename SpanType,typename ConstSpanType> void
449_testSpan2StdArray()
450{
451 using namespace Arccore;
452
453 std::array<Int64,6> v1 { 5, 7, 9, 32, -5, -6 };
454 std::array<Int64,5> v2 { 1, 9, 32, 41, -5 };
455 std::array<const Int64,12> v3 { 12, 33, 47, 55, 36, 13, 9, 7, 5, 1, 45, 38 };
456
457 SpanType s0 { };
458 SpanType s1 { v1.data(), 3, 2 };
459 SpanType s2 { v2.data(), 1, 5 };
460 ConstSpanType s3 { v3.data(), 4, 3 };
461
462 ASSERT_EQ(s1[2][1],s1(2,1));
463
464#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
465 {
466 bool is_ok = s1[2,1]==s1(2,1);
467 ASSERT_TRUE(is_ok);
468 }
469#endif
470
471 {
472 SpanType span0 { s0 };
473 _checkSame2(span0,s0,"span0==s0");
474
475 SpanType span1 { s1 };
476 _checkSame2(span1,s1,"span1==s1");
477
478 SpanType span2 { s1 };
479 ASSERT_TRUE(span1==span2);
480 ASSERT_FALSE(span1!=span2);
481
482 SpanType const_span2 { s1 };
483 ASSERT_TRUE(span1==const_span2);
484 ASSERT_FALSE(span1!=const_span2);
485 }
486
487 {
488 ConstSpanType span0 { s0 };
489 _checkSame2(span0,s0,"const span0==s0");
490
491 ConstSpanType span1 { s1 };
492 _checkSame2(span1,s1,"const span1==s1");
493
494 span0 = s2;
495 _checkSame2(span0,s2,"const span0==s2");
496
497 ConstSpanType span2 { s3 };
498 _checkSame2(span2,s3,"const span2==s3");
499
500 ConstSpanType span3 { s3 };
501 ASSERT_TRUE(span2==span3);
502 ASSERT_FALSE(span2!=span3);
503
504 span1 = s3;
505 _checkSame2(span1,s3,"const span1==s3");
506 }
507}
508
509/*---------------------------------------------------------------------------*/
510/*---------------------------------------------------------------------------*/
511
512TEST(Span2,StdArray)
513{
514 using namespace Arccore;
515 _testSpan2StdArray<Span2<Int64>,Span2<const Int64>>();
516}
517
518/*---------------------------------------------------------------------------*/
519/*---------------------------------------------------------------------------*/
520
521TEST(SmallSpan2,StdArray)
522{
523 using namespace Arccore;
524 _testSpan2StdArray<SmallSpan2<Int64>,SmallSpan2<const Int64>>();
525}
526
527/*---------------------------------------------------------------------------*/
528/*---------------------------------------------------------------------------*/
529
530template <typename ViewType> void
531_testSubViewInterval()
532{
533 using namespace Arccore;
534
535 std::array<Int64, 12> vlist{ 9, 13, 32, 27, 43, -5, 2, -7, 8, 11, 25, 48 };
536 ViewType view{ vlist };
537
538 {
539 ViewType null_view;
540 ViewType sub_view0{ view.subViewInterval(1, 0) };
541 ViewType sub_view1{ view.subViewInterval(-1, 2) };
542 ViewType sub_view2{ view.subViewInterval(2, 2) };
543 ViewType sub_view3{ view.subViewInterval(0, 0) };
544 std::cout << "SUBVIEW0=" << sub_view1 << '\n';
545 _checkSame(sub_view0, null_view, "sub_view0_null");
546 _checkSame(sub_view1, null_view, "sub_view1_null");
547 _checkSame(sub_view2, null_view, "sub_view2_null");
548 _checkSame(sub_view3, null_view, "sub_view3_null");
549 }
550
551 {
552 std::array<Int64, 4> vlist0{ 9, 13, 32, 27 };
553 std::array<Int64, 4> vlist1{ 43, -5, 2, -7 };
554 std::array<Int64, 4> vlist2{ 8, 11, 25, 48 };
555
556 ViewType sub_view0{ view.subViewInterval(0, 3) };
557 ViewType sub_view1{ view.subViewInterval(1, 3) };
558 ViewType sub_view2{ view.subViewInterval(2, 3) };
559 std::cout << "SUBVIEW1=" << sub_view1 << '\n';
560 _checkSame(sub_view0, vlist0, "sub_view0");
561 _checkSame(sub_view1, vlist1, "sub_view1");
562 _checkSame(sub_view2, vlist2, "sub_view2");
563 }
564
565 {
566 std::array<Int64, 2> vlist0{ 9, 13 };
567 std::array<Int64, 2> vlist1{ 32, 27 };
568 std::array<Int64, 2> vlist2{ 43, -5 };
569 std::array<Int64, 2> vlist3{ 2, -7 };
570 std::array<Int64, 4> vlist4{ 8, 11, 25, 48 };
571
572 ViewType sub_view0{ view.subViewInterval(0, 5) };
573 ViewType sub_view1{ view.subViewInterval(1, 5) };
574 ViewType sub_view2{ view.subViewInterval(2, 5) };
575 ViewType sub_view3{ view.subViewInterval(3, 5) };
576 ViewType sub_view4{ view.subViewInterval(4, 5) };
577 std::cout << "SUBVIEW2=" << sub_view1 << '\n';
578 _checkSame(sub_view0, vlist0, "sub_view0");
579 _checkSame(sub_view1, vlist1, "sub_view1");
580 _checkSame(sub_view2, vlist2, "sub_view2");
581 _checkSame(sub_view3, vlist3, "sub_view3");
582 _checkSame(sub_view4, vlist4, "sub_view4");
583 }
584}
585
586/*---------------------------------------------------------------------------*/
587/*---------------------------------------------------------------------------*/
588
589template <typename ViewType> void
590_testSubSpanInterval()
591{
592 using namespace Arccore;
593
594 std::array<Int64, 12> vlist{ 9, 13, 32, 27, 43, -5, 2, -7, 8, 11, 25, 48 };
595 ViewType view{ vlist };
596
597 {
598 ViewType null_view;
599 ViewType sub_view0{ view.subSpanInterval(1, 0) };
600 ViewType sub_view1{ view.subSpanInterval(-1, 2) };
601 ViewType sub_view2{ view.subSpanInterval(2, 2) };
602 ViewType sub_view3{ view.subSpanInterval(0, 0) };
603 std::cout << "SUBVIEW0=" << sub_view1 << '\n';
604 _checkSame(sub_view0, null_view, "sub_view0_null");
605 _checkSame(sub_view1, null_view, "sub_view1_null");
606 _checkSame(sub_view2, null_view, "sub_view2_null");
607 _checkSame(sub_view3, null_view, "sub_view3_null");
608 }
609
610 {
611 std::array<Int64, 4> vlist0{ 9, 13, 32, 27 };
612 std::array<Int64, 4> vlist1{ 43, -5, 2, -7 };
613 std::array<Int64, 4> vlist2{ 8, 11, 25, 48 };
614
615 ViewType sub_view0{ view.subSpanInterval(0, 3) };
616 ViewType sub_view1{ view.subSpanInterval(1, 3) };
617 ViewType sub_view2{ view.subSpanInterval(2, 3) };
618 std::cout << "SUBVIEW1=" << sub_view1 << '\n';
619 _checkSame(sub_view0, vlist0, "sub_view0");
620 _checkSame(sub_view1, vlist1, "sub_view1");
621 _checkSame(sub_view2, vlist2, "sub_view2");
622 }
623
624 {
625 std::array<Int64, 2> vlist0{ 9, 13 };
626 std::array<Int64, 2> vlist1{ 32, 27 };
627 std::array<Int64, 2> vlist2{ 43, -5 };
628 std::array<Int64, 2> vlist3{ 2, -7 };
629 std::array<Int64, 4> vlist4{ 8, 11, 25, 48 };
630
631 ViewType sub_view0{ view.subSpanInterval(0, 5) };
632 ViewType sub_view1{ view.subSpanInterval(1, 5) };
633 ViewType sub_view2{ view.subSpanInterval(2, 5) };
634 ViewType sub_view3{ view.subSpanInterval(3, 5) };
635 ViewType sub_view4{ view.subSpanInterval(4, 5) };
636 std::cout << "SUBVIEW2=" << sub_view1 << '\n';
637 _checkSame(sub_view0, vlist0, "sub_view0");
638 _checkSame(sub_view1, vlist1, "sub_view1");
639 _checkSame(sub_view2, vlist2, "sub_view2");
640 _checkSame(sub_view3, vlist3, "sub_view3");
641 _checkSame(sub_view4, vlist4, "sub_view4");
642 }
643}
644
645/*---------------------------------------------------------------------------*/
646/*---------------------------------------------------------------------------*/
647
648template <typename ViewType> void
649_testSubPartInterval()
650{
651 using namespace Arccore;
652
653 std::array<Int64, 12> vlist{ 9, 13, 32, 27, 43, -5, 2, -7, 8, 11, 25, 48 };
654 ViewType view{ vlist };
655
656 {
657 ViewType null_view;
658 ViewType sub_view0{ view.subPartInterval(1, 0) };
659 ViewType sub_view1{ view.subPartInterval(-1, 2) };
660 ViewType sub_view2{ view.subPartInterval(2, 2) };
661 ViewType sub_view3{ view.subPartInterval(0, 0) };
662 std::cout << "SUBVIEW0=" << sub_view1 << '\n';
663 _checkSame(sub_view0, null_view, "sub_view0_null");
664 _checkSame(sub_view1, null_view, "sub_view1_null");
665 _checkSame(sub_view2, null_view, "sub_view2_null");
666 _checkSame(sub_view3, null_view, "sub_view3_null");
667 }
668
669 {
670 std::array<Int64, 4> vlist0{ 9, 13, 32, 27 };
671 std::array<Int64, 4> vlist1{ 43, -5, 2, -7 };
672 std::array<Int64, 4> vlist2{ 8, 11, 25, 48 };
673
674 ViewType sub_view0{ view.subPartInterval(0, 3) };
675 ViewType sub_view1{ view.subPartInterval(1, 3) };
676 ViewType sub_view2{ view.subPartInterval(2, 3) };
677 std::cout << "SUBVIEW1=" << sub_view1 << '\n';
678 _checkSame(sub_view0, vlist0, "sub_view0");
679 _checkSame(sub_view1, vlist1, "sub_view1");
680 _checkSame(sub_view2, vlist2, "sub_view2");
681 }
682
683 {
684 std::array<Int64, 2> vlist0{ 9, 13 };
685 std::array<Int64, 2> vlist1{ 32, 27 };
686 std::array<Int64, 2> vlist2{ 43, -5 };
687 std::array<Int64, 2> vlist3{ 2, -7 };
688 std::array<Int64, 4> vlist4{ 8, 11, 25, 48 };
689
690 ViewType sub_view0{ view.subPartInterval(0, 5) };
691 ViewType sub_view1{ view.subPartInterval(1, 5) };
692 ViewType sub_view2{ view.subPartInterval(2, 5) };
693 ViewType sub_view3{ view.subPartInterval(3, 5) };
694 ViewType sub_view4{ view.subPartInterval(4, 5) };
695 std::cout << "SUBVIEW2=" << sub_view1 << '\n';
696 _checkSame(sub_view0, vlist0, "sub_view0");
697 _checkSame(sub_view1, vlist1, "sub_view1");
698 _checkSame(sub_view2, vlist2, "sub_view2");
699 _checkSame(sub_view3, vlist3, "sub_view3");
700 _checkSame(sub_view4, vlist4, "sub_view4");
701 }
702}
703
704/*---------------------------------------------------------------------------*/
705/*---------------------------------------------------------------------------*/
706
707TEST(ArrayView, SubViewInterval)
708{
709 using namespace Arccore;
710 _testSubViewInterval<ArrayView<Int64>>();
711 _testSubViewInterval<ConstArrayView<Int64>>();
712 _testSubSpanInterval<Span<Int64>>();
713 _testSubSpanInterval<SmallSpan<Int64>>();
714
715 _testSubPartInterval<ArrayView<Int64>>();
716 _testSubPartInterval<ConstArrayView<Int64>>();
717 _testSubPartInterval<Span<Int64>>();
718 _testSubPartInterval<SmallSpan<Int64>>();
719}
720
721TEST(ArrayView,Copyable)
722{
723 using namespace Arccore;
724 ASSERT_TRUE(std::is_trivially_copyable_v<ArrayView<int>>);
725 ASSERT_TRUE(std::is_trivially_copyable_v<ConstArrayView<int>>);
726
727 ASSERT_TRUE(std::is_trivially_copyable_v<Array2View<int>>);
728 ASSERT_TRUE(std::is_trivially_copyable_v<ConstArray2View<int>>);
729
730 ASSERT_TRUE(std::is_trivially_copyable_v<Array3View<int>>);
731 ASSERT_TRUE(std::is_trivially_copyable_v<ConstArray3View<int>>);
732
733 ASSERT_TRUE(std::is_trivially_copyable_v<Array4View<int>>);
734 ASSERT_TRUE(std::is_trivially_copyable_v<ConstArray4View<int>>);
735
736 ASSERT_TRUE(std::is_trivially_copyable_v<Span<int>>);
737 ASSERT_TRUE(std::is_trivially_copyable_v<Span<const int>>);
738
739 ASSERT_TRUE(std::is_trivially_copyable_v<Span2<int>>);
740 ASSERT_TRUE(std::is_trivially_copyable_v<Span2<const int>>);
741}
742
743/*---------------------------------------------------------------------------*/
744/*---------------------------------------------------------------------------*/
745
746namespace Arccore
747{
748template class ArrayView<Int32>;
749template class ConstArrayView<Int32>;
750template class ArrayView<double>;
751template class ConstArrayView<double>;
752
753template class Span<Int32>;
754template class Span<const Int32>;
755template class Span<double>;
756template class Span<const double>;
757
758template class SmallSpan<Int32>;
759template class SmallSpan<const Int32>;
760template class SmallSpan<double>;
761template class SmallSpan<const double>;
762
763template class Span<Int32,DynExtent,-1>;
764template class Span<const Int32,DynExtent,-1>;
765template class Span<double,DynExtent,-1>;
766template class Span<const double,DynExtent,-1>;
767
768template class SmallSpan<Int32,DynExtent,-1>;
769template class SmallSpan<const Int32,DynExtent,-1>;
770template class SmallSpan<double,DynExtent,-1>;
771template class SmallSpan<const double,DynExtent,-1>;
772
773template class Span<Int32,4>;
774template class Span<const Int32,5>;
775template class Span<double,6>;
776template class Span<const double,7>;
777
778template class SmallSpan<Int32,4>;
779template class SmallSpan<const Int32,5>;
780template class SmallSpan<double,6>;
781template class SmallSpan<const double,7>;
782
783template class Span<Int32,4,-1>;
784template class Span<const Int32,5,-1>;
785template class Span<double,6,-1>;
786template class Span<const double,7,-1>;
787
788template class SmallSpan<Int32,4,-1>;
789template class SmallSpan<const Int32,5,-1>;
790template class SmallSpan<double,6,-1>;
791template class SmallSpan<const double,7,-1>;
792
793template class Span2<Int32>;
794template class Span2<const Int32>;
795template class Span2<double>;
796template class Span2<const double>;
797
798template class SmallSpan2<Int32>;
799template class SmallSpan2<const Int32>;
800template class SmallSpan2<double>;
801template class SmallSpan2<const double>;
802} // namespace Arccore
803
804/*---------------------------------------------------------------------------*/
805/*---------------------------------------------------------------------------*/
#define ASSERT_FALSE(condition)
Vérifie que condition est faux.
Definition Assertion.h:138
#define ASSERT_TRUE(condition)
Vérifie que condition est vrai.
Definition Assertion.h:126
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Vue modifiable pour un tableau 2D.
Vue modifiable d'un tableau d'un type T.
Vue constante d'un tableau de type T.
Vue pour un tableau 2D dont la taille est un 'Int32'.
Definition Span2.h:233
Vue d'un tableau d'éléments de type T.
Definition Span.h:670
Vue pour un tableau 2D dont la taille est un 'Int64'.
Definition Span2.h:301
constexpr ARCCORE_HOST_DEVICE SizeType size() const noexcept
Retourne la taille du tableau.
Definition Span.h:209
Vue d'un tableau d'éléments de type T.
Definition Span.h:510
constexpr Int32 DynExtent
Constante pour indiquer que la dimension d'un tableau est dynamique.
Definition UtilsTypes.h:255
Espace de nom de Arccore.
Definition ArcaneTypes.h:24
constexpr Int32 DynExtent
Indique que la dimension d'un tableau est dynamique.
Definition BaseTypes.h:54
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.
detail::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets non modifiables.
Definition Span.h:881
SmallSpan< DataType > asSmallSpan(SmallSpan< std::byte, Extent > bytes)
Converti un SmallSpan<std::byte> en un SmallSpan<DataType>.
Definition Span.h:991
detail::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets modifiables.
Definition Span.h:916
std::int32_t Int32
Type entier signé sur 32 bits.
Span< DataType > asSpan(Span< std::byte, Extent > bytes)
Converti un Span<std::byte> en un Span<DataType>.
Definition Span.h:973