-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathMapTest.cpp
112 lines (93 loc) · 4.16 KB
/
MapTest.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright 2021 The DAPHNE Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <runtime/local/datagen/GenGivenVals.h>
#include <runtime/local/datastructures/DenseMatrix.h>
#include <runtime/local/kernels/CheckEq.h>
#include <runtime/local/kernels/Map.h>
#include <tags.h>
#include <catch.hpp>
#include <vector>
#define TYPES double, float, int64_t, int32_t, int8_t, uint64_t, uint8_t
template <class DTRes, class DTArg> void checkMap(const DTArg *arg, const DTRes *exp, void *func) {
DTRes *res = nullptr;
map(res, arg, func, nullptr);
CHECK(*res == *exp);
DataObjectFactory::destroy(res);
}
template <typename VTarg, typename VTres> VTres mult3func(VTarg arg) { return static_cast<VTres>(arg) * 3; }
template <template <typename VT> class DT, class VTarg, class VTres> void checkMult3Map() {
using DTArg = DT<VTarg>;
using DTRes = DT<VTres>;
void *mult3funcPtr = reinterpret_cast<void *>(&mult3func<VTarg, VTres>);
auto m1 = genGivenVals<DTArg>(3, {
0,
1,
2,
1,
2,
3,
3,
4,
5,
});
auto mult3_res1 = genGivenVals<DTRes>(3, {
0,
3,
6,
3,
6,
9,
9,
12,
15,
});
auto m2 = genGivenVals<DTArg>(2, {
1,
0,
2,
0,
3,
1,
2,
0,
});
auto mult3_res2 = genGivenVals<DTRes>(2, {
3,
0,
6,
0,
9,
3,
6,
0,
});
auto m3 = genGivenVals<DTArg>(3, {1, 5, 3});
auto mult3_res3 = genGivenVals<DTRes>(3, {3, 15, 9});
checkMap(m1, mult3_res1, mult3funcPtr);
checkMap(m2, mult3_res2, mult3funcPtr);
checkMap(m3, mult3_res3, mult3funcPtr);
DataObjectFactory::destroy(m1, m2, m3, mult3_res1, mult3_res2, mult3_res3);
}
template <template <typename VT> class DT, typename VTarg, typename VTres1, typename... VTresN>
std::enable_if_t<(sizeof...(VTresN) > 0)> checkMult3Map() {
checkMult3Map<DT, VTarg, VTres1>();
checkMult3Map<DT, VTarg, VTresN...>();
}
TEMPLATE_TEST_CASE("Map element-wise dense matrix", TAG_KERNELS, TYPES) {
// Test all combination of types in TYPES
checkMult3Map<DenseMatrix, TestType, TYPES>();
checkMult3Map<Matrix, TestType, TYPES>();
}