CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
operation_unit_test.cc
Go to the documentation of this file.
1// -*- C++ -*-
12#include <cstdlib>
13#include <iostream>
14
15#include "gtest/gtest.h"
16
17#include "ranges/ranges.h"
18#include "operation/operation.h"
19#include "array/array.h"
20#include "test_numbers.h"
21
22namespace
23{
24 using namespace CNORXZ;
25 using Test::Numbers;
26
27 class OpCont_CR_Test : public ::testing::Test
28 {
29 protected:
30
31 OpCont_CR_Test()
32 {
33 mSize = 7;
34 const SizeT off = 10;
35 mData1 = Numbers::get(off, mSize);
36 mData2 = Numbers::get(off + mSize*2, mSize);
37 auto cr = CRangeFactory(mSize).create();
38 mCI1 = std::make_shared<CIndex>(cr);
39 mCI2 = std::make_shared<CIndex>(cr);
40 mOp1.init(mCI1);
41 mOp2.init(mData1.data(), mCI1);
42 mOp3.init(mCI2);
43 mOp4.init(mData2.data(), mCI2);
44 }
45
46 SizeT mSize;
47 Vector<Double> mData1;
48 Vector<Double> mData2;
49 Sptr<CIndex> mCI1;
50 Sptr<CIndex> mCI2;
55 };
56
57 class OpCont_CR_CR_Test : public ::testing::Test
58 {
59 protected:
60
61 typedef MIndex<CIndex,CIndex> MCCI;
62
63 OpCont_CR_CR_Test()
64 {
65 mSize1 = 7;
66 mSize2 = 11;
67 SizeT off = 20;
68 mData1 = Numbers::get(off, mSize1);
69 mData2 = Numbers::get(off += mSize1 , mSize2);
70 mData11 = Numbers::get(off += mSize2, mSize1*mSize2);
71 mData12 = Numbers::get(off += mSize1*mSize2, mSize1*mSize2);
72 auto cr1 = CRangeFactory(mSize1).create();
73 auto cr2 = CRangeFactory(mSize2).create();
74 mCI1i = std::make_shared<CIndex>(cr1);
75 mCI1j = std::make_shared<CIndex>(cr1);
76 mCI2i = std::make_shared<CIndex>(cr2);
77 mCI2j = std::make_shared<CIndex>(cr2);
78 mCC1i1j = mindexPtr(mCI1i*mCI1j);
79 mCC1j1i = mindexPtr(mCI1j*mCI1i);
80 //mCC1i2i = mindexPtr(mCI1i*mCI2i);
81 //mCC1j2i = mindexPtr(mCI1j*mCI2i);
82 mOC1i1j.init(mCC1i1j);
83 mOR1j1i.init(mData11.data(), mCC1j1i);
84 mOR1i1j.init(mData12.data(), mCC1i1j);
85 }
86
87 SizeT mSize1;
88 SizeT mSize2;
89 Vector<Double> mData1;
90 Vector<Double> mData2;
91 Vector<Double> mData11;
92 Vector<Double> mData12;
93 Sptr<CIndex> mCI1i;
94 Sptr<CIndex> mCI1j;
95 Sptr<CIndex> mCI2i;
96 Sptr<CIndex> mCI2j;
97 Sptr<MCCI> mCC1i1j;
98 Sptr<MCCI> mCC1j1i;
99 //Sptr<MCCI> mCC1i2i;
100 //Sptr<MCCI> mCC1j2i;
101 OpCont<double,MCCI> mOC1i1j;
102 COpRoot<double,MCCI> mOR1j1i;
103 COpRoot<double,MCCI> mOR1i1j;
104 //COpRoot<double,MCCI> mOR1j2i;
105 //COpRoot<double,MCCI> mOR1i2i;
106 };
107
108 class OpCont_CR_CR_Test2 : public ::testing::Test
109 {
110 protected:
111
115
116 OpCont_CR_CR_Test2()
117 {
118 mSize1 = 11;
119 mSize2 = 12;
120 SizeT off = 20;
121 //mData1 = Numbers::get(off, mSize1);
122 //mData2 = Numbers::get(off += mSize1 , mSize2);
123 mData21 = Numbers::get(off += mSize2, mSize1*mSize2);
124 mData12 = Numbers::get(off += mSize1*mSize2, mSize1*mSize2);
125 auto cr1 = CRangeFactory(mSize1).create();
126 auto cr2 = CRangeFactory(mSize2).create();
127 mCI1i = std::make_shared<CIndex>(cr1);
128 mCI1j = std::make_shared<CIndex>(cr1);
129 mCI2i = std::make_shared<CIndex>(cr2);
130 mCI2j = std::make_shared<CIndex>(cr2);
131 auto ipack1 = mCI1i*eplex<4,1,2>(mCI2j);
132 auto iform1 = gmformat(UPos(mCI2j->lmax().val()),UPos(4),SPos<1>());
133 mCC1i2j = gmindexPtr( iform1, ipack1 );
134 //mCC1i2j = mindexPtr(mCI1i*eplex<4,1,2>(mCI2j));
135 mCC2j1i = mindexPtr(eplex<4,1,2>(mCI2j)*mCI1i);
136 mOC1i2j.init(mCC1i2j);
137 mOR2j1i.init(mData21.data(), mCC2j1i);
138 mOR1i2j.init(mData12.data(), mCC1i2j);
139 }
140
141 SizeT mSize1;
142 SizeT mSize2;
143 Vector<Double> mData12;
144 Vector<Double> mData21;
145 Vector<Double> mData11_1;
146 Vector<Double> mData11_2;
147 Sptr<CIndex> mCI1i;
148 Sptr<CIndex> mCI1j;
149 Sptr<CIndex> mCI2i;
150 Sptr<CIndex> mCI2j;
151 Sptr<MCCI1x> mCC1i2j;
152 Sptr<MCCI2> mCC2j1i;
153 OpCont<double,MCCI1x> mOC1i2j;
154 COpRoot<double,MCCI2> mOR2j1i;
156 };
157
158 TEST_F(OpCont_CR_Test, Basics)
159 {
160 EXPECT_EQ(mOp2.data(), mData1.data());
161 EXPECT_EQ(mOp4.data(), mData2.data());
162 auto rs11 = mOp1.rootSteps(mCI1->id());
163 auto rs21 = mOp2.rootSteps(mCI1->id());
164 auto rs31 = mOp3.rootSteps(mCI1->id());
165 auto rs41 = mOp4.rootSteps(mCI1->id());
166 auto rs12 = mOp1.rootSteps(mCI2->id());
167 auto rs22 = mOp2.rootSteps(mCI2->id());
168 auto rs32 = mOp3.rootSteps(mCI2->id());
169 auto rs42 = mOp4.rootSteps(mCI2->id());
170 EXPECT_EQ(rs11.val(), 1u);
171 EXPECT_EQ(rs21.val(), 1u);
172 EXPECT_EQ(rs31.val(), 0u);
173 EXPECT_EQ(rs41.val(), 0u);
174 EXPECT_EQ(rs12.val(), 0u);
175 EXPECT_EQ(rs22.val(), 0u);
176 EXPECT_EQ(rs32.val(), 1u);
177 EXPECT_EQ(rs42.val(), 1u);
178 }
179
180 TEST_F(OpCont_CR_Test, Assignment)
181 {
182 mOp1 = mOp2;
183 mOp3 = mOp4;
184 for(SizeT i = 0; i != mSize; ++i){
185 EXPECT_EQ(mOp1.data()[i], mOp2.data()[i]);
186 EXPECT_EQ(mOp3.data()[i], mOp4.data()[i]);
187 }
188 mOp1 = mOp4;
189 mOp3 = mOp2;
190 for(SizeT i = 0; i != mSize; ++i){
191 EXPECT_EQ(mOp1.data()[i], mOp4.data()[0]);
192 EXPECT_EQ(mOp3.data()[i], mOp2.data()[0]);
193 }
194 }
195
196 TEST_F(OpCont_CR_Test, PlusAssign)
197 {
198 Vector<Double> z(mSize, 0);
199 mOp1.init(mCI1, z);
200 mOp3.init(mCI2, z);
201 mOp1 += mOp2;
202 mOp3 += mOp4;
203 for(SizeT i = 0; i != mSize; ++i){
204 EXPECT_EQ(mOp1.data()[i], mOp2.data()[i]);
205 EXPECT_EQ(mOp3.data()[i], mOp4.data()[i]);
206 }
207 mOp1.init(mCI1, z);
208 mOp3.init(mCI2, z);
209 mOp1 = mOp4;
210 mOp3 = mOp2;
211 for(SizeT i = 0; i != mSize; ++i){
212 EXPECT_EQ(mOp1.data()[i], mOp4.data()[0]);
213 EXPECT_EQ(mOp3.data()[i], mOp2.data()[0]);
214 }
215 }
216
217 TEST_F(OpCont_CR_CR_Test, Basics)
218 {
219 EXPECT_EQ(mOC1i1j.rootSteps(mCI1i->id()).val(), mCI1j->pmax().val());
220 EXPECT_EQ(mOC1i1j.rootSteps(mCI1j->id()).val(), 1u);
221 EXPECT_EQ(mOR1j1i.rootSteps(mCI1i->id()).val(), 1u);
222 EXPECT_EQ(mOR1j1i.rootSteps(mCI1j->id()).val(), mCI1i->pmax().val());
223 }
224
225 TEST_F(OpCont_CR_CR_Test, Assignment)
226 {
227 mOC1i1j = mOR1j1i;
228 for(SizeT i = 0; i != mCI1i->pmax().val(); ++i){
229 for(SizeT j = 0; j != mCI1j->pmax().val(); ++j){
230 const SizeT jS = mCI1j->pmax().val();
231 const SizeT iS = mCI1i->pmax().val();
232 EXPECT_EQ(mOC1i1j.data()[i*jS+j], mOR1j1i.data()[j*iS+i]);
233 }
234 }
235 }
236
237 TEST_F(OpCont_CR_CR_Test, Multiply)
238 {
239 mOC1i1j = mOR1j1i * mOR1i1j;
240 for(SizeT i = 0; i != mCI1i->pmax().val(); ++i){
241 for(SizeT j = 0; j != mCI1j->pmax().val(); ++j){
242 const SizeT jS = mCI1j->pmax().val();
243 const SizeT iS = mCI1i->pmax().val();
244 EXPECT_EQ(mOC1i1j.data()[i*jS+j], mOR1j1i.data()[j*iS+i] * mOR1i1j.data()[i*jS+j]);
245 }
246 }
247 }
248
249 TEST_F(OpCont_CR_CR_Test2, Assignment)
250 {
251 EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<0>{}]->id() ).val(), 1u );
252 EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<1>{}]->id() ).val(), 44u );
253 EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<2>{}]->id() ).val(), 11u );
254
255 mOC1i2j = mOR2j1i;
256
257 for(SizeT i = 0; i != mCI1i->pmax().val(); ++i){
258 for(SizeT j = 0; j != mCI2j->pmax().val(); ++j){
259 const SizeT jS = mCI2j->pmax().val();
260 const SizeT iS = mCI1i->pmax().val();
261 EXPECT_EQ(mOC1i2j.data()[i*jS+j], mOR2j1i.data()[j*iS+i]);
262 }
263 }
264
265 }
266
267 TEST_F(OpCont_CR_CR_Test2, Multiply)
268 {
269 EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<0>{}]->id() ).val(), 1u );
270 EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<1>{}]->id() ).val(), 44u );
271 EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<2>{}]->id() ).val(), 11u );
272
273 EXPECT_EQ( mCC1i2j->stepSize( mCC1i2j->pack()[CSizeT<0>{}]->id() ).val(), 12u );
274 EXPECT_EQ( mCC1i2j->stepSize( mCC1i2j->pack()[CSizeT<1>{}]->id() ).val(), 4u );
275 EXPECT_EQ( mCC1i2j->stepSize( mCC1i2j->pack()[CSizeT<2>{}]->id() ).val(), 1u );
276
277 mOC1i2j = mOR2j1i * mOR1i2j;
278 for(SizeT i = 0; i != mCI1i->pmax().val(); ++i){
279 for(SizeT j = 0; j != mCI2j->pmax().val(); ++j){
280 const SizeT jS = mCI2j->pmax().val();
281 const SizeT iS = mCI1i->pmax().val();
282 EXPECT_EQ(mOC1i2j.data()[i*jS+j], mOR2j1i.data()[j*iS+i] * mOR1i2j.data()[i*jS+j]);
283 }
284 }
285 }
286}
Array main header.
constexpr decltype(auto) gmindexPtr(const FormatT &bs, const SPack< Indices... > &pack)
Definition mrange.cc.h:635
uint64_t SizeT
Definition types.h:38
std::vector< T, Allocator< T > > Vector
Definition types.h:310
std::integral_constant< SizeT, N > CSizeT
Definition types.h:81
Sptr< Range > rangeCast(const RangePtr r)
constexpr decltype(auto) gmformat(const PosT &... ps)
constexpr decltype(auto) mindexPtr(const SPack< Indices... > &pack)
Definition mrange.cc.h:629
std::shared_ptr< T > Sptr
Definition types.h:48
Operation main header.
Ranges main header.
Test numbers utilities.