7#include <gtest/gtest.h>
9#include "arccore/base/PlatformUtils.h"
10#include "arccore/base/ArrayExtentsValue.h"
11#include "arccore/base/ArrayExtents.h"
13#include "arccore/base/ForLoopRanges.h"
33 std::array<Int32, 3> getIndices1(
Int32 index)
35 Int32 i2 = impl::fastmod(index, z);
37 Int32 i1 = impl::fastmod(index / fac, y);
39 Int32 i0 = index / fac;
40 return { i0, i1, i2 };
43 std::array<Int32, 3> getIndices2(
Int32 index)
45 Int32 i = index / (y * z);
51 std::array<Int32, 3> getIndices3(
Int32 index)
53 Int32 i = index /
static_cast<unsigned int>(y * z);
55 Int32 j = index /
static_cast<unsigned int>(z);
59 std::array<Int32, 3> getIndices4(
Int32 index)
61 UInt32 uz =
static_cast<unsigned int>(z);
70TEST(GetIndices, Versions)
75 Int32 total_size = n0 * n1 * n2;
78 for (Int32 i = 0; i < total_size; ++i) {
79 auto x = xv2.getIndices4(i);
80 auto y = xv.getIndices(i);
81 ASSERT_EQ(x[0], y[0]);
82 ASSERT_EQ(x[1], y[1]);
83 ASSERT_EQ(x[2], y[2]);
90 for (Int32 k = 0; k < nb_loop; ++k) {
91 for (Int32 i = 0; i < total_size; ++i) {
92 auto x = xv.getIndices(i);
93 total0 += x[0] + x[1] + x[2];
97 std::cerr <<
"TOTAL_0=" << total0 <<
" time0=" << t0 <<
"\n";
101 for (Int32 k = 0; k < nb_loop; ++k) {
102 for (Int32 i = 0; i < total_size; ++i) {
103 auto x = xv2.getIndices1(i);
104 total1 += x[0] + x[1] + x[2];
107 ASSERT_EQ(total0, total1);
109 std::cerr <<
"TOTAL_1=" << total1 <<
" time1=" << t1 <<
"\n";
113 for (Int32 k = 0; k < nb_loop; ++k) {
114 for (Int32 i = 0; i < total_size; ++i) {
115 auto x = xv2.getIndices2(i);
116 total2 += x[0] + x[1] + x[2];
119 ASSERT_EQ(total0, total2);
121 std::cerr <<
"TOTAL_2=" << total2 <<
" time2=" << t2 <<
"\n";
125 for (Int32 k = 0; k < nb_loop; ++k) {
126 for (Int32 i = 0; i < total_size; ++i) {
127 auto x = xv2.getIndices3(i);
128 total3 += x[0] + x[1] + x[2];
131 ASSERT_EQ(total0, total3);
133 std::cerr <<
"TOTAL_3=" << total3 <<
" time3=" << t3 <<
"\n";
137 for (Int32 k = 0; k < nb_loop; ++k) {
138 for (Int32 i = 0; i < total_size; ++i) {
139 auto x = xv2.getIndices4(i);
140 total4 += x[0] + x[1] + x[2];
143 ASSERT_EQ(total0, total4);
145 std::cerr <<
"TOTAL_4=" << total4 <<
" time3=" << t4 <<
"\n";
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::uint32_t UInt32
Type entier non signé sur 32 bits.
ARCCORE_BASE_EXPORT bool arccoreIsDebug()
Vrai si la macro ARCCORE_DEBUG est définie.
std::int32_t Int32
Type entier signé sur 32 bits.