MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / reduce_by_key_test

Function reduce_by_key_test

test/reduce.cpp:643–715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

641}
642
643void reduce_by_key_test(std::string test_fn) {
644 vector<dim4> numDims;
645 vector<vector<float>> data;
646 vector<vector<float>> tests;
647 readTests<float, float, float>(test_fn, numDims, data, tests);
648
649 for (size_t t = 0; t < numDims.size() / 2; ++t) {
650 dim4 kdim = numDims[t * 2];
651 dim4 vdim = numDims[t * 2 + 1];
652
653 vector<int> in_keys(data[t * 2].begin(), data[t * 2].end());
654 vector<float> in_vals(data[t * 2 + 1].begin(), data[t * 2 + 1].end());
655
656 af_array inKeys = 0;
657 af_array inVals = 0;
658 af_array outKeys = 0;
659 af_array outVals = 0;
660 ASSERT_EQ(
661 AF_SUCCESS,
662 af_create_array(&inKeys, &in_keys.front(), kdim.ndims(), kdim.get(),
663 (af_dtype)af::dtype_traits<int>::af_type));
664 ASSERT_EQ(
665 AF_SUCCESS,
666 af_create_array(&inVals, &in_vals.front(), vdim.ndims(), vdim.get(),
667 (af_dtype)af::dtype_traits<float>::af_type));
668
669 vector<int> currGoldKeys(tests[t * 2].begin(), tests[t * 2].end());
670 vector<float> currGoldVals(tests[t * 2 + 1].begin(),
671 tests[t * 2 + 1].end());
672
673 // Run sum
674 ASSERT_EQ(AF_SUCCESS,
675 af_sum_by_key(&outKeys, &outVals, inKeys, inVals, 0));
676
677 dim_t ok0, ok1, ok2, ok3;
678 dim_t ov0, ov1, ov2, ov3;
679 af_get_dims(&ok0, &ok1, &ok2, &ok3, outKeys);
680 af_get_dims(&ov0, &ov1, &ov2, &ov3, outVals);
681
682 // Get result
683 vector<int> outKeysVec(ok0 * ok1 * ok2 * ok3);
684 vector<float> outValsVec(ov0 * ov1 * ov2 * ov3);
685
686 ASSERT_EQ(AF_SUCCESS,
687 af_get_data_ptr((void *)&outKeysVec.front(), outKeys));
688 ASSERT_EQ(AF_SUCCESS,
689 af_get_data_ptr((void *)&outValsVec.front(), outVals));
690
691 size_t nElems = currGoldKeys.size();
692 if (std::equal(currGoldKeys.begin(), currGoldKeys.end(),
693 outKeysVec.begin()) == false) {
694 for (size_t elIter = 0; elIter < nElems; ++elIter) {
695 EXPECT_NEAR(currGoldKeys[elIter], outKeysVec[elIter], 1e-4)
696 << "at: " << elIter << endl;
697 EXPECT_NEAR(currGoldVals[elIter], outValsVec[elIter], 1e-4)
698 << "at: " << elIter << endl;
699 }
700 for (int i = 0; i < (int)nElems; i++) {

Callers 1

TESTFunction · 0.85

Calls 7

af_sum_by_keyFunction · 0.85
af_create_arrayFunction · 0.50
af_get_dimsFunction · 0.50
af_get_data_ptrFunction · 0.50
af_release_arrayFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected