7#include <gtest/gtest.h>
9#include "arccore/base/PlatformUtils.h"
10#include "arccore/base/ArrayExtentsValue.h"
11#include "arccore/base/ArrayExtents.h"
31 std::array<Int32, 3> getIndices1(
Int32 index)
33 Int32 i2 = Impl::fastmod(index, z);
35 Int32 i1 = Impl::fastmod(index / fac, y);
37 Int32 i0 = index / fac;
38 return { i0, i1, i2 };
41 std::array<Int32, 3> getIndices2(
Int32 index)
43 Int32 i = index / (y * z);
49 std::array<Int32, 3> getIndices3(
Int32 index)
51 Int32 i = index /
static_cast<unsigned int>(y * z);
53 Int32 j = index /
static_cast<unsigned int>(z);
57 std::array<Int32, 3> getIndices4(
Int32 index)
59 UInt32 uz =
static_cast<unsigned int>(z);
68TEST(GetIndices, Versions)
73 Int32 total_size = n0 * n1 * n2;
76 for (Int32 i = 0; i < total_size; ++i) {
77 auto x = xv2.getIndices4(i);
78 auto y = xv.getIndices(i);
79 ASSERT_EQ(x[0], y[0]);
80 ASSERT_EQ(x[1], y[1]);
81 ASSERT_EQ(x[2], y[2]);
88 for (Int32 k = 0; k < nb_loop; ++k) {
89 for (Int32 i = 0; i < total_size; ++i) {
90 auto x = xv.getIndices(i);
91 total0 += x[0] + x[1] + x[2];
95 std::cerr <<
"TOTAL_0=" << total0 <<
" time0=" << t0 <<
"\n";
99 for (Int32 k = 0; k < nb_loop; ++k) {
100 for (Int32 i = 0; i < total_size; ++i) {
101 auto x = xv2.getIndices1(i);
102 total1 += x[0] + x[1] + x[2];
105 ASSERT_EQ(total0, total1);
107 std::cerr <<
"TOTAL_1=" << total1 <<
" time1=" << t1 <<
"\n";
111 for (Int32 k = 0; k < nb_loop; ++k) {
112 for (Int32 i = 0; i < total_size; ++i) {
113 auto x = xv2.getIndices2(i);
114 total2 += x[0] + x[1] + x[2];
117 ASSERT_EQ(total0, total2);
119 std::cerr <<
"TOTAL_2=" << total2 <<
" time2=" << t2 <<
"\n";
123 for (Int32 k = 0; k < nb_loop; ++k) {
124 for (Int32 i = 0; i < total_size; ++i) {
125 auto x = xv2.getIndices3(i);
126 total3 += x[0] + x[1] + x[2];
129 ASSERT_EQ(total0, total3);
131 std::cerr <<
"TOTAL_3=" << total3 <<
" time3=" << t3 <<
"\n";
135 for (Int32 k = 0; k < nb_loop; ++k) {
136 for (Int32 i = 0; i < total_size; ++i) {
137 auto x = xv2.getIndices4(i);
138 total4 += x[0] + x[1] + x[2];
141 ASSERT_EQ(total0, total4);
143 std::cerr <<
"TOTAL_4=" << total4 <<
" time3=" << t4 <<
"\n";
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
bool arccoreIsDebug()
True if the ARCCORE_DEBUG macro is defined.
std::uint32_t UInt32
Unsigned integer type of 32 bits.
std::int32_t Int32
Signed integer type of 32 bits.