-
Notifications
You must be signed in to change notification settings - Fork 5
/
ra-6.cc
88 lines (76 loc) · 3.38 KB
/
ra-6.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// -*- mode: c++; coding: utf-8 -*-
// ra-ra/test - Regression test (3).
// (c) Daniel Llorens - 2014-2015
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option) any
// later version.
// Regression test for a bug with > 2 non-beatable selectors. The bug was due to
// bad assumptions in ra::Iota::adv() and ra::Ptr::adv().
#include "ra/test.hh"
using std::cout, std::endl, ra::TestRecorder;
int main()
{
int N = 4;
ra::Big<float, 3> A({N, N, N}, ra::_2 + ra::_1*4 + ra::_0*16);
ra::Big<float, 2> B({N, N}, ra::_1 + ra::_0*4);
ra::Big<float, 1> C({N}, ra::_0);
cout << "A: " << N << endl;
cout << "B: " << N << endl;
cout << "C: " << N << endl;
// beatable.
auto i = ra::iota(2, 1);
// making unbeatable on purpose, but still depends on Iota's internal counter.
auto j = ra::map([](int i) { return i; }, i);
// naturally unbeatable.
ra::Small<int, 2> k { 1, 2 };
auto l = std::array<int, 2> { 1, 2 };
auto ll = ra::ptr(l);
// auto ll = ra::ptr(std::array<int, 2> { 1, 2 }); // FIXME find a way to forbid this [ra9]
cout << "X0: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, i, i, i) << endl;
cout << "X1: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, j, j, j) << endl;
cout << "X2: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, k, k, k) << endl;
cout << "X3: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, ra::ptr(l), ra::ptr(l), ra::ptr(l)) << endl;
cout << "X4: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, l, l, l) << endl;
cout << "X5: " << ra::from([](int i, int j, int k) { return ra::Small<int, 3>{i, j, k}; }, ll, ll, ll) << endl;
cout << endl;
cout << "Y0: " << ra::from(A, i, i, i) << endl;
cout << "Y1: " << ra::from(A, j, j, j) << endl;
cout << "Y2: " << ra::from(A, k, k, k) << endl;
cout << "Y3: " << ra::from(A, ra::ptr(l), ra::ptr(l), ra::ptr(l)) << endl;
cout << "Y4: " << ra::from(A, l, l, l) << endl;
cout << "Y5: " << ra::from(A, ll, ll, ll) << endl;
cout << B(i, i) << endl;
TestRecorder tr(std::cout);
tr.section("subs 1");
{
ra::Small<int, 2> ref1 {1, 2};
tr.test_eq(ref1, C(i));
tr.test_eq(ref1, C(j));
tr.test_eq(ref1, C(k));
tr.test_eq(ref1, C(ra::ptr(l)));
tr.info("ll").test_eq(ref1, C(ll));
}
tr.section("subs 2");
{
ra::Small<int, 2, 2> ref2 {5, 6, 9, 10};
tr.test_eq(ref2, B(i, i));
tr.test_eq(ref2, B(j, j));
tr.test_eq(ref2, B(k, k));
tr.test_eq(ref2, B(ra::ptr(l), ra::ptr(l)));
tr.test_eq(ref2, B(l, l));
tr.info("ll").test_eq(ref2, B(ll, ll));
}
// TODO have a proper rank / shape match error when comparing these with ref3
tr.section("subs 3");
{
ra::Small<int, 2, 2, 2> ref3 {21, 22, 25, 26, 37, 38, 41, 42};
tr.test_eq(ref3, A(i, i, i));
tr.test_eq(ref3, A(j, j, j));
tr.test_eq(ref3, A(k, k, k));
tr.test_eq(ref3, A(ra::ptr(l), ra::ptr(l), ra::ptr(l)));
tr.test_eq(ref3, A(l, l, l));
tr.info("ll").test_eq(ref3, A(ll, ll, ll));
}
return tr.summary();
}