forked from uTensor/uTensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tensorIdxImporterTests.hpp
74 lines (64 loc) · 1.72 KB
/
tensorIdxImporterTests.hpp
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
#ifndef UTENSOR_IDX_IMPORTER_TESTS
#define UTENSOR_IDX_IMPORTER_TESTS
#include "tensorIdxImporter.hpp"
#include "test.hpp"
class idxImporterTest : public Test {
public:
void ntoh32Test(void) {
testStart("ntoh32 test");
uint32_t input = 63;
timer_start();
uint32_t result = ntoh32(input);
timer_stop();
passed(result == 1056964608);
}
void ucharTest(void) {
testStart("uchar import test");
TensorIdxImporter t_import;
timer_start();
Tensor<unsigned char> t =
t_import.ubyte_import("/fs/testData/idxImport/uint8_4d_power2.idx");
timer_stop();
double result = sum(t);
passed(result == 4518);
}
void shortTest(void) {
testStart("short import test");
TensorIdxImporter t_import;
timer_start();
Tensor<short> t =
t_import.short_import("/fs/testData/idxImport/int16_4d_power2.idx");
timer_stop();
double result = sum(t);
passed(result == 270250);
}
void intTest(void) {
testStart("int import test");
TensorIdxImporter t_import;
timer_start();
Tensor<int> t =
t_import.int_import("/fs/testData/idxImport/int32_4d_power2.idx");
timer_stop();
double result = sum(t);
passed(result == 5748992600);
}
void floatTest(void) {
testStart("float import test");
TensorIdxImporter t_import;
timer_start();
Tensor<float> t =
t_import.float_import("/fs/testData/idxImport/float_4d_power2.idx");
timer_stop();
double result = sum(t);
DEBUG("***floating point test yielded: %.8e\r\n", (float)result);
passed((float)result == -1.0f);
}
void runAll(void) {
ntoh32Test();
ucharTest();
shortTest();
intTest();
floatTest();
}
};
#endif // UTENSOR_IDX_IMPORTER_TESTS