forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompare.cpp
More file actions
54 lines (48 loc) · 1.93 KB
/
compare.cpp
File metadata and controls
54 lines (48 loc) · 1.93 KB
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
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <gtest/gtest.h>
#include <testHelpers.hpp>
#include <af/arith.h>
#include <af/array.h>
#include <af/data.h>
using af::array;
using af::dtype_traits;
using af::randu;
using std::vector;
template<typename T>
class Compare : public ::testing::Test {};
typedef ::testing::Types<float, double, uint, int, intl, uintl, uchar, short,
ushort>
TestTypes;
TYPED_TEST_CASE(Compare, TestTypes);
#define COMPARE(OP, Name) \
TYPED_TEST(Compare, Test_##Name) { \
typedef TypeParam T; \
SUPPORTED_TYPE_CHECK(T); \
const int num = 1 << 20; \
af_dtype ty = (af_dtype)dtype_traits<T>::af_type; \
array a = randu(num, ty); \
array b = randu(num, ty); \
array c = a OP b; \
vector<T> ha(num), hb(num); \
vector<char> hc(num); \
a.host(&ha[0]); \
b.host(&hb[0]); \
c.host(&hc[0]); \
for (int i = 0; i < num; i++) { \
char res = ha[i] OP hb[i]; \
ASSERT_EQ((int)res, (int)hc[i]); \
} \
}
COMPARE(==, eq)
COMPARE(!=, ne)
COMPARE(<=, le)
COMPARE(>=, ge)
COMPARE(<, lt)
COMPARE(>, gt)