Skip to content

Commit cc07a2c

Browse files
committed
Make tests C++03 complient.
Removed most C++11 features from the unit tests. This is done so that we can compile using the older libstdc++ library on OSX which is based on GCC 4.2. This library is a requirement for CUDA on OSX.
1 parent c772e25 commit cc07a2c

47 files changed

Lines changed: 594 additions & 523 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/af/seq.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ typedef struct af_seq {
1515
double step;
1616
} af_seq;
1717

18+
AFAPI
19+
af_seq
20+
af_make_seq(double begin, double end, double step);
21+
1822
static const af_seq af_span = {1, 1, 0};
1923

2024
#ifdef __cplusplus

src/api/c/index.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,9 @@ af_err af_lookup(af_array *out, const af_array in, const af_array indices, const
110110

111111
return AF_SUCCESS;
112112
}
113+
114+
af_seq
115+
af_make_seq(double begin, double end, double step) {
116+
af_seq seq = {begin, end, step};
117+
return seq;
118+
}

src/api/c/median.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static T median(const af_array& in)
2929
const Array<T> input = getArray<T>(in);
3030
dim_type nElems = input.elements();
3131
double mid = (nElems + 1) / 2;
32-
af_seq mdSpan[1]= {mid-1, mid, 1};
32+
af_seq mdSpan[1]= {af_make_seq(mid-1, mid, 1)};
3333
dim4 dims(nElems, 1, 1, 1);
3434

3535
af_array temp = 0;
@@ -65,7 +65,7 @@ static af_array median(const af_array& in, dim_type dim)
6565
af_array left = 0;
6666

6767
af_seq slices[4] = {af_span, af_span, af_span, af_span};
68-
slices[dim] = {mid-1, mid-1, 1};
68+
slices[dim] = af_make_seq(mid-1.0, mid-1.0, 1.0);
6969

7070
AF_CHECK(af_index(&left, getHandle<T>(sortedIn), input.ndims(), slices));
7171

@@ -76,7 +76,7 @@ static af_array median(const af_array& in, dim_type dim)
7676
// ((mid-1)+mid)/2 is our guy
7777
dim4 dims = input.dims();
7878
af_array right = 0;
79-
slices[dim] = {mid, mid, 1};
79+
slices[dim] = af_make_seq(mid, mid, 1.0);
8080

8181
AF_CHECK(af_index(&right, getHandle<T>(sortedIn), dims.ndims(), slices));
8282

src/api/cpp/reduce.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace af
9797
{ \
9898
double rval, ival; \
9999
AF_THROW(af_##fn##_all(&rval, &ival, in.get())); \
100-
T out = {(Tr)rval, (Tr)ival}; \
100+
T out((Tr)rval, (Tr)ival); \
101101
return out; \
102102
} \
103103

@@ -146,7 +146,7 @@ namespace af
146146
{ \
147147
double rval, ival; \
148148
AF_THROW(af_i##fn##_all(&rval, &ival, idx, in.get())); \
149-
*val = {(Tr)rval, (Tr)ival}; \
149+
*val = T((Tr)rval, (Tr)ival); \
150150
} \
151151

152152
#define INSTANTIATE(fn) \

test/approx1.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class Approx1 : public ::testing::Test
3030
{
3131
public:
3232
virtual void SetUp() {
33-
subMat0.push_back({0, 4, 1});
34-
subMat0.push_back({2, 6, 1});
35-
subMat0.push_back({0, 2, 1});
33+
subMat0.push_back(af_make_seq(0, 4, 1));
34+
subMat0.push_back(af_make_seq(2, 6, 1));
35+
subMat0.push_back(af_make_seq(0, 2, 1));
3636
}
3737
vector<af_seq> subMat0;
3838
};
@@ -44,14 +44,14 @@ typedef ::testing::Types<float, double, cfloat, cdouble> TestTypes;
4444
TYPED_TEST_CASE(Approx1, TestTypes);
4545

4646
template<typename T>
47-
void approx1Test(string pTestFile, const unsigned resultIdx, const af_interp_type method, bool isSubRef = false, const vector<af_seq> * seqv = nullptr)
47+
void approx1Test(string pTestFile, const unsigned resultIdx, const af_interp_type method, bool isSubRef = false, const vector<af_seq> * seqv = NULL)
4848
{
4949
if (noDoubleTests<T>()) return;
5050

5151
typedef typename af::dtype_traits<T>::base_type BT;
5252
vector<af::dim4> numDims;
53-
vector<vector<BT>> in;
54-
vector<vector<T>> tests;
53+
vector<vector<BT> > in;
54+
vector<vector<T> > tests;
5555
readTests<BT, T, float>(pTestFile,numDims,in,tests);
5656

5757
af::dim4 idims = numDims[0];
@@ -115,8 +115,8 @@ void approx1ArgsTest(string pTestFile, const unsigned resultIdx, const af_interp
115115
if (noDoubleTests<T>()) return;
116116
typedef typename af::dtype_traits<T>::base_type BT;
117117
vector<af::dim4> numDims;
118-
vector<vector<BT>> in;
119-
vector<vector<T>> tests;
118+
vector<vector<BT> > in;
119+
vector<vector<T> > tests;
120120
readTests<BT, T, float>(pTestFile,numDims,in,tests);
121121

122122
af::dim4 idims = numDims[0];
@@ -155,8 +155,8 @@ void approx1ArgsTestPrecision(string pTestFile, const unsigned resultIdx, const
155155
{
156156
if (noDoubleTests<T>()) return;
157157
vector<af::dim4> numDims;
158-
vector<vector<T>> in;
159-
vector<vector<T>> tests;
158+
vector<vector<T> > in;
159+
vector<vector<T> > tests;
160160
readTests<T, T, float>(pTestFile,numDims,in,tests);
161161

162162
af::dim4 idims = numDims[0];
@@ -203,8 +203,8 @@ TEST(Approx1, CPP)
203203
const af_interp_type method = AF_INTERP_LINEAR;
204204
#define BT af::dtype_traits<float>::base_type
205205
vector<af::dim4> numDims;
206-
vector<vector<BT>> in;
207-
vector<vector<float>> tests;
206+
vector<vector<BT> > in;
207+
vector<vector<float> > tests;
208208
readTests<BT, float, float>(string(TEST_DIR"/approx/approx1.test"),numDims,in,tests);
209209

210210
af::dim4 idims = numDims[0];

test/approx2.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class Approx2 : public ::testing::Test
3030
{
3131
public:
3232
virtual void SetUp() {
33-
subMat0.push_back({0, 4, 1});
34-
subMat0.push_back({2, 6, 1});
35-
subMat0.push_back({0, 2, 1});
33+
subMat0.push_back(af_make_seq(0, 4, 1));
34+
subMat0.push_back(af_make_seq(2, 6, 1));
35+
subMat0.push_back(af_make_seq(0, 2, 1));
3636
}
3737
vector<af_seq> subMat0;
3838
};
@@ -44,13 +44,13 @@ typedef ::testing::Types<float, double, cfloat, cdouble> TestTypes;
4444
TYPED_TEST_CASE(Approx2, TestTypes);
4545

4646
template<typename T>
47-
void approx2Test(string pTestFile, const unsigned resultIdx, const af_interp_type method, bool isSubRef = false, const vector<af_seq> * seqv = nullptr)
47+
void approx2Test(string pTestFile, const unsigned resultIdx, const af_interp_type method, bool isSubRef = false, const vector<af_seq> * seqv = NULL)
4848
{
4949
if (noDoubleTests<T>()) return;
5050
typedef typename af::dtype_traits<T>::base_type BT;
5151
vector<af::dim4> numDims;
52-
vector<vector<BT>> in;
53-
vector<vector<T>> tests;
52+
vector<vector<BT> > in;
53+
vector<vector<T> > tests;
5454
readTests<BT, T, float>(pTestFile,numDims,in,tests);
5555

5656
af::dim4 idims = numDims[0];
@@ -120,8 +120,8 @@ void approx2ArgsTest(string pTestFile, const unsigned resultIdx, const af_interp
120120
if (noDoubleTests<T>()) return;
121121
typedef typename af::dtype_traits<T>::base_type BT;
122122
vector<af::dim4> numDims;
123-
vector<vector<BT>> in;
124-
vector<vector<T>> tests;
123+
vector<vector<BT> > in;
124+
vector<vector<T> > tests;
125125
readTests<BT, T, float>(pTestFile,numDims,in,tests);
126126

127127
af::dim4 idims = numDims[0];
@@ -165,8 +165,8 @@ void approx2ArgsTestPrecision(string pTestFile, const unsigned resultIdx, const
165165
{
166166
if (noDoubleTests<T>()) return;
167167
vector<af::dim4> numDims;
168-
vector<vector<T>> in;
169-
vector<vector<T>> tests;
168+
vector<vector<T> > in;
169+
vector<vector<T> > tests;
170170
readTests<T, T, float>(pTestFile,numDims,in,tests);
171171

172172
af::dim4 idims = numDims[0];
@@ -218,8 +218,8 @@ TEST(Approx2, CPP)
218218
const unsigned resultIdx = 1;
219219
#define BT af::dtype_traits<float>::base_type
220220
vector<af::dim4> numDims;
221-
vector<vector<BT>> in;
222-
vector<vector<float>> tests;
221+
vector<vector<BT> > in;
222+
vector<vector<float> > tests;
223223
readTests<BT, float, float>(string(TEST_DIR"/approx/approx2.test"),numDims,in,tests);
224224

225225
af::dim4 idims = numDims[0];

test/assign.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,45 @@ class ArrayAssign : public ::testing::Test
2323
{
2424
public:
2525
virtual void SetUp() {
26-
subMat1D.push_back({5,20,1});
26+
subMat1D.push_back(af_make_seq(5,20,1));
2727

28-
subMat2D.push_back({1,2,1});
29-
subMat2D.push_back({1,2,1});
28+
subMat2D.push_back(af_make_seq(1,2,1));
29+
subMat2D.push_back(af_make_seq(1,2,1));
3030

31-
subMat3D.push_back({3,4,1});
32-
subMat3D.push_back({0,1,1});
33-
subMat3D.push_back({1,2,1});
31+
subMat3D.push_back(af_make_seq(3,4,1));
32+
subMat3D.push_back(af_make_seq(0,1,1));
33+
subMat3D.push_back(af_make_seq(1,2,1));
3434

35-
subMat4D.push_back({3,4,1});
36-
subMat4D.push_back({0,1,1});
37-
subMat4D.push_back({0,1,1});
38-
subMat4D.push_back({1,2,1});
35+
subMat4D.push_back(af_make_seq(3,4,1));
36+
subMat4D.push_back(af_make_seq(0,1,1));
37+
subMat4D.push_back(af_make_seq(0,1,1));
38+
subMat4D.push_back(af_make_seq(1,2,1));
3939

40-
subMat1D_to_2D.push_back({1,2,1});
41-
subMat1D_to_2D.push_back({1,1,1});
40+
subMat1D_to_2D.push_back(af_make_seq(1,2,1));
41+
subMat1D_to_2D.push_back(af_make_seq(1,1,1));
4242

43-
subMat1D_to_3D.push_back({5,20,1});
44-
subMat1D_to_3D.push_back({1,1,1});
45-
subMat1D_to_3D.push_back({2,2,1});
43+
subMat1D_to_3D.push_back(af_make_seq(5,20,1));
44+
subMat1D_to_3D.push_back(af_make_seq(1,1,1));
45+
subMat1D_to_3D.push_back(af_make_seq(2,2,1));
4646

47-
subMat2D_to_3D.push_back({3,4,1});
48-
subMat2D_to_3D.push_back({0,1,1});
49-
subMat2D_to_3D.push_back({1,1,1});
47+
subMat2D_to_3D.push_back(af_make_seq(3,4,1));
48+
subMat2D_to_3D.push_back(af_make_seq(0,1,1));
49+
subMat2D_to_3D.push_back(af_make_seq(1,1,1));
5050

51-
subMat1D_to_4D.push_back({3,4,1});
52-
subMat1D_to_4D.push_back({0,0,1});
53-
subMat1D_to_4D.push_back({0,0,1});
54-
subMat1D_to_4D.push_back({1,1,1});
51+
subMat1D_to_4D.push_back(af_make_seq(3,4,1));
52+
subMat1D_to_4D.push_back(af_make_seq(0,0,1));
53+
subMat1D_to_4D.push_back(af_make_seq(0,0,1));
54+
subMat1D_to_4D.push_back(af_make_seq(1,1,1));
5555

56-
subMat2D_to_4D.push_back({3,4,1});
57-
subMat2D_to_4D.push_back({0,1,1});
58-
subMat2D_to_4D.push_back({0,0,1});
59-
subMat2D_to_4D.push_back({1,1,1});
56+
subMat2D_to_4D.push_back(af_make_seq(3,4,1));
57+
subMat2D_to_4D.push_back(af_make_seq(0,1,1));
58+
subMat2D_to_4D.push_back(af_make_seq(0,0,1));
59+
subMat2D_to_4D.push_back(af_make_seq(1,1,1));
6060

61-
subMat3D_to_4D.push_back({3,4,1});
62-
subMat3D_to_4D.push_back({0,1,1});
63-
subMat3D_to_4D.push_back({0,1,1});
64-
subMat3D_to_4D.push_back({1,1,1});
61+
subMat3D_to_4D.push_back(af_make_seq(3,4,1));
62+
subMat3D_to_4D.push_back(af_make_seq(0,1,1));
63+
subMat3D_to_4D.push_back(af_make_seq(0,1,1));
64+
subMat3D_to_4D.push_back(af_make_seq(1,1,1));
6565
}
6666
vector<af_seq> subMat1D;
6767

@@ -91,8 +91,8 @@ void assignTest(string pTestFile, const vector<af_seq> *seqv)
9191
if (noDoubleTests<outType>()) return;
9292

9393
vector<af::dim4> numDims;
94-
vector<vector<inType>> in;
95-
vector<vector<outType>> tests;
94+
vector<vector<inType> > in;
95+
vector<vector<outType> > tests;
9696

9797
readTests<inType, outType, int>(pTestFile, numDims, in, tests);
9898

@@ -188,7 +188,7 @@ TEST(ArrayAssign, InvalidArgs)
188188
af_array outArray = 0;
189189

190190
vector<af_seq> seqv;
191-
seqv.push_back({5,14,1});
191+
seqv.push_back(af_make_seq(5,14,1));
192192

193193
ASSERT_EQ(AF_ERR_ARG, af_assign(&outArray,
194194
lhsArray, seqv.size(), &seqv.front(), rhsArray));
@@ -218,12 +218,12 @@ TEST(ArrayAssign, CPP)
218218
using af::array;
219219

220220
vector<af_seq> seqv;
221-
seqv.push_back({1,2,1});
222-
seqv.push_back({1,2,1});
221+
seqv.push_back(af_make_seq(1,2,1));
222+
seqv.push_back(af_make_seq(1,2,1));
223223

224224
vector<af::dim4> numDims;
225-
vector<vector<float>> in;
226-
vector<vector<float>> tests;
225+
vector<vector<float> > in;
226+
vector<vector<float> > tests;
227227

228228
readTests<float, float, int>(string(TEST_DIR"/assign/2d_to_2d.test"), numDims, in, tests);
229229

test/bilateral.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <string>
1515
#include <vector>
1616
#include <cmath>
17-
#include <type_traits>
1817
#include <testHelpers.hpp>
1918

2019
using std::string;
@@ -91,11 +90,11 @@ void bilateralDataTest(string pTestFile)
9190
{
9291
if (noDoubleTests<inType>()) return;
9392

94-
typedef typename std::conditional<std::is_same<inType, double>::value, double, float>::type outType;
93+
typedef typename cond_type<is_same<inType, double>::value, double, float>::type outType;
9594

9695
vector<af::dim4> numDims;
97-
vector<vector<inType>> in;
98-
vector<vector<outType>> tests;
96+
vector<vector<inType> > in;
97+
vector<vector<outType> > tests;
9998

10099
readTests<inType, outType, float>(pTestFile, numDims, in, tests);
101100

@@ -167,8 +166,8 @@ TEST(Bilateral, CPP)
167166
using af::array;
168167

169168
vector<af::dim4> numDims;
170-
vector<vector<float>> in;
171-
vector<vector<float>> tests;
169+
vector<vector<float> > in;
170+
vector<vector<float> > tests;
172171

173172
readTests<float, float, float>(string(TEST_DIR"/bilateral/rectangle.test"), numDims, in, tests);
174173

test/binary.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ af::array randgen(const int num, af::dtype ty)
3535
return tmp;
3636
}
3737

38+
template<typename T>
39+
cfloat
40+
operator-(cfloat a, cfloat b) {
41+
return a;
42+
}
3843

3944
#define BINARY_TESTS(Ta, Tb, Tc, func) \
4045
TEST(BinaryTests, Test_##func##_##Ta##_##Tb) \

test/blas.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ void MatMulCheck(string TestFile)
4040
using std::vector;
4141
vector<af::dim4> numDims;
4242

43-
vector<vector<T>> hData;
44-
vector<vector<T>> tests;
43+
vector<vector<T> > hData;
44+
vector<vector<T> > tests;
4545
readTests<T,T,int>(TestFile, numDims, hData, tests);
4646

4747
af_array a, aT, b, bT;
@@ -135,8 +135,8 @@ void cppMatMulCheck(string TestFile)
135135
using std::vector;
136136
vector<af::dim4> numDims;
137137

138-
vector<vector<T>> hData;
139-
vector<vector<T>> tests;
138+
vector<vector<T> > hData;
139+
vector<vector<T> > tests;
140140
readTests<T,T,int>(TestFile, numDims, hData, tests);
141141

142142
af::array a(numDims[0], &hData[0].front());

0 commit comments

Comments
 (0)