7#include <gtest/gtest.h>
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"
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);
32 for(
Integer x=0, xn=v.dim1Size(); x<xn; ++x ){
33 for(
Integer y=0, yn=v.dim2Size(); y<yn; ++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;
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);
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 ){
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;
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);
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 ){
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;
125template<
typename T>
void
126_testIterator(T values)
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';
136 auto r1 = values.rbegin();
153 std::vector<Arccore::Int32> vector_values = { 4, 9, 7 };
157 _testIterator(values1);
160 _testIterator(values2);
162 Span<Int32> values3(vector_values.data(),vector_values.size());
163 _testIterator(values3);
166 _testIterator(values4);
175 std::vector<Int64> vector_values = { 5, 7, 11 };
176 Int32 vector_size =
static_cast<Int32>(vector_values.size());
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]";
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]";
190 Span<Int64> a_span(vector_values.data(),vector_values.size());
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)";
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;
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';
218template<
typename A1,
typename A2>
219void _checkSame(A1& a1,A2& a2,
const char* message)
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;
234template<
typename A1,
typename A2>
235void _checkSame2(A1& a1,A2& a2,
const char* message)
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;
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 };
263 _checkSame(view0,v0,
"view0==v0");
266 _checkSame(view1,v1,
"view1==v1");
269 _checkSame(view0,v2,
"view0==v2");
274 _checkSame(view0,v0,
"const view0==v0");
277 _checkSame(view1,v1,
"const view1==v1");
280 _checkSame(view0,v2,
"const view0==v2");
283 _checkSame(view2,v3,
"const view2==v3");
286 _checkSame(view1,v3,
"const view1==v3");
293template<
typename SpanType,
typename ConstSpanType>
void
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 };
303 SpanType span0 { v0 };
304 _checkSame(span0,v0,
"span0==v0");
306 SpanType span1 { v1 };
307 _checkSame(span1,v1,
"span1==v1");
309 SpanType span2 { v1 };
313 SpanType const_span2 { v1 };
318 _checkSame(span0,v2,
"span0==v2");
322 ConstSpanType span0 { v0 };
323 _checkSame(span0,v0,
"const span0==v0");
325 ConstSpanType span1 { v1 };
326 _checkSame(span1,v1,
"const span1==v1");
329 _checkSame(span0,v2,
"const span0==v2");
331 ConstSpanType span2 { v3 };
332 _checkSame(span2,v3,
"const span2==v3");
334 ConstSpanType span3 { v3 };
339 _checkSame(span1,v3,
"const span1==v3");
342 SpanType span1 { v1 };
343 ConstSpanType const_span1 { v1 };
346 SpanType span2 { v2 };
347 ConstSpanType const_span3 { v3 };
360 std::array<Int64, 0> v0;
361 std::array<Int64, 2> v1{ 5, 7 };
362 std::array<Int64, 3> v2{ 2, 4, -2 };
364 _checkSame(s0, v0,
"s0==v0");
366 _checkSame(s1, v1,
"s1==v1");
368 _checkSame(s2, v2,
"s2==v2");
371 _checkSame(sp0, v0,
"s0==v0");
373 _checkSame(sp1, v1,
"s1==v1");
375 _checkSame(sp2, v2,
"s2==v2");
380 auto x = asSpan<Int64>(bytes);
381 ASSERT_EQ(x.data(),
nullptr);
382 ASSERT_EQ(x.size(), 0);
387 auto x = asSmallSpan<Int64>(bytes);
388 ASSERT_EQ(x.data(),
nullptr);
389 ASSERT_EQ(x.size(), 0);
394 auto x = asSpan<Int64>(bytes);
395 _checkSame(x, v1,
"x==v1");
400 auto x = asSpan<Int64>(bytes);
401 _checkSame(x, v2,
"x==v2");
408 auto x = asSmallSpan<Int64>(bytes);
409 _checkSame(x, v2,
"x==v2");
415 std::array<Int64,2> v1 { 5, 7 };
416 std::array<Int64,3> v2 { 2, 4, -2 };
427 std::array<Real, 3> v2r{ 2.0, 4.1, -2.3 };
448template<
typename SpanType,
typename ConstSpanType>
void
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 };
458 SpanType s1 { v1.data(), 3, 2 };
459 SpanType s2 { v2.data(), 1, 5 };
460 ConstSpanType s3 { v3.data(), 4, 3 };
462 ASSERT_EQ(s1[2][1],s1(2,1));
464#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
466 bool is_ok = s1[2,1]==s1(2,1);
472 SpanType span0 { s0 };
473 _checkSame2(span0,s0,
"span0==s0");
475 SpanType span1 { s1 };
476 _checkSame2(span1,s1,
"span1==s1");
478 SpanType span2 { s1 };
482 SpanType const_span2 { s1 };
488 ConstSpanType span0 { s0 };
489 _checkSame2(span0,s0,
"const span0==s0");
491 ConstSpanType span1 { s1 };
492 _checkSame2(span1,s1,
"const span1==s1");
495 _checkSame2(span0,s2,
"const span0==s2");
497 ConstSpanType span2 { s3 };
498 _checkSame2(span2,s3,
"const span2==s3");
500 ConstSpanType span3 { s3 };
505 _checkSame2(span1,s3,
"const span1==s3");
530template <
typename ViewType>
void
531_testSubViewInterval()
535 std::array<Int64, 12> vlist{ 9, 13, 32, 27, 43, -5, 2, -7, 8, 11, 25, 48 };
536 ViewType view{ vlist };
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");
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 };
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");
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 };
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");
589template <
typename ViewType>
void
590_testSubSpanInterval()
594 std::array<Int64, 12> vlist{ 9, 13, 32, 27, 43, -5, 2, -7, 8, 11, 25, 48 };
595 ViewType view{ vlist };
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");
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 };
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");
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 };
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");
648template <
typename ViewType>
void
649_testSubPartInterval()
653 std::array<Int64, 12> vlist{ 9, 13, 32, 27, 43, -5, 2, -7, 8, 11, 25, 48 };
654 ViewType view{ vlist };
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");
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 };
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");
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 };
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");
710 _testSubViewInterval<ArrayView<Int64>>();
711 _testSubViewInterval<ConstArrayView<Int64>>();
712 _testSubSpanInterval<Span<Int64>>();
713 _testSubSpanInterval<SmallSpan<Int64>>();
715 _testSubPartInterval<ArrayView<Int64>>();
716 _testSubPartInterval<ConstArrayView<Int64>>();
717 _testSubPartInterval<Span<Int64>>();
718 _testSubPartInterval<SmallSpan<Int64>>();
785template class Span<double,6,-1>;
786template class Span<
const double,7,-1>;
791template class SmallSpan<
const double,7,-1>;
#define ASSERT_FALSE(condition)
Vérifie que condition est faux.
#define ASSERT_TRUE(condition)
Vérifie que condition est vrai.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Vue modifiable pour un tableau 2D.
Vue modifiable d'un tableau d'un type T.
Vue pour un tableau 2D constant.
Vue pour un tableau 3D constant.
Vue constante pour un tableau 4D.
Vue constante d'un tableau de type T.
Vue pour un tableau 2D dont la taille est un 'Int32'.
Vue d'un tableau d'éléments de type T.
Vue pour un tableau 2D dont la taille est un 'Int64'.
constexpr ARCCORE_HOST_DEVICE SizeType size() const noexcept
Retourne la taille du tableau.
Vue d'un tableau d'éléments de type T.
constexpr Int32 DynExtent
Constante pour indiquer que la dimension d'un tableau est dynamique.
Espace de nom de Arccore.
constexpr Int32 DynExtent
Indique que la dimension d'un tableau est dynamique.
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.
SmallSpan< DataType > asSmallSpan(SmallSpan< std::byte, Extent > bytes)
Converti un SmallSpan<std::byte> en un SmallSpan<DataType>.
detail::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets modifiables.
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>.