Skip to content

Commit d3cb0ad

Browse files
committed
TEST: Test for logical assignment
1 parent 0cee88b commit d3cb0ad

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

test/gen_assign.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,58 @@ TEST(ArrayAssign, CPP_ASSIGN_INDEX)
257257
delete[] hAO;
258258
delete[] hIdx;
259259
}
260+
261+
TEST(ArrayAssign, CPP_ASSIGN_INDEX_LOGICAL)
262+
{
263+
try {
264+
using af::array;
265+
266+
const int num = 20000;
267+
268+
array a = af::randu(num);
269+
float *hAO = a.host<float>();
270+
271+
array a_copy = a;
272+
array idx = where(a < 0.5);
273+
const int len = idx.elements();
274+
array b = af::randu(len);
275+
a(a < 0.5) = b;
276+
277+
float *hA = a.host<float>();
278+
float *hB = b.host<float>();
279+
float *hAC = a_copy.host<float>();
280+
uint *hIdx = idx.host<uint>();
281+
282+
for (int i = 0; i < num; i++) {
283+
284+
int j = 0;
285+
while(j < len) {
286+
287+
// If index found, value should match B
288+
if ((int)hIdx[j] == i) {
289+
ASSERT_EQ(hA[i], hB[j]);
290+
break;
291+
}
292+
j++;
293+
}
294+
295+
// If index not found, value should match original
296+
if (j >= len) {
297+
ASSERT_EQ(hA[i], hAO[i]);
298+
}
299+
}
300+
301+
// hAC should not be modified, i.e. same as original
302+
for (int i = 0; i < num; i++) {
303+
ASSERT_EQ(hAO[i], hAC[i]);
304+
}
305+
306+
delete[] hA;
307+
delete[] hB;
308+
delete[] hAC;
309+
delete[] hAO;
310+
delete[] hIdx;
311+
} catch(af::exception &ex) {
312+
FAIL() << ex.what() << std::endl;
313+
}
314+
}

0 commit comments

Comments
 (0)