[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/arrayfire/arrayfire/feature/optional-graphics/test/gen_index.cpp [Back]  [Original]

/*******************************************************
 * 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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 

using af::dim4;
using af::dtype_traits;
using std::endl;
using std::get;
using std::ostream_iterator;
using std::string;
using std::stringstream;
using std::vector;

struct index_test {
    string filename_;
    dim4 dims_;
    index_test(string filename, dim4 dims) : filename_(filename), dims_(dims) {}
};

using index_params = std::tuple;

class IndexGeneralizedLegacy : public ::testing::TestWithParam {
    void SetUp() {
        index_params params = GetParam();
        vector numDims;
        vector in;
        vector tests;

        if (noDoubleTests(get(params))) return;
        if (noHalfTests(get(params))) return;

        if (noDoubleTests(get(params))) return;
        if (noHalfTests(get(params))) return;
        readTestsFromFile(get(params).filename_, numDims, in,
                                        tests);

        dim4 dims0 = numDims[0];
        dim4 dims1 = numDims[1];

        af_array inTmp = 0;
        ASSERT_SUCCESS(af_create_array(&inTmp, &(in[0].front()), dims0.ndims(),
                                       dims0.get(), f32));

        ASSERT_SUCCESS(af_cast(&inArray_, inTmp, get(params)));
        af_release_array(inTmp);

        af_array idxTmp = 0;
        ASSERT_SUCCESS(af_create_array(&idxTmp, &(in[1].front()), dims1.ndims(),
                                       dims1.get(), f32));
        ASSERT_SUCCESS(af_cast(&idxArray_, idxTmp, get(params)));
        af_release_array(idxTmp);

        vector hgold = tests[0];
        af_array goldTmp;
        af_create_array(&goldTmp, &hgold.front(), get(params).dims_.ndims(),
                        get(params).dims_.get(), f32);
        ASSERT_SUCCESS(af_cast(&gold_, goldTmp, get(params)));
        af_release_array(goldTmp);
    }

    void TearDown() {
        if (inArray_) { ASSERT_SUCCESS(af_release_array(inArray_)); }
        if (idxArray_) { ASSERT_SUCCESS(af_release_array(idxArray_)); }
        if (gold_) { ASSERT_SUCCESS(af_release_array(gold_)); }
    }

   public:
    IndexGeneralizedLegacy() : gold_(0), inArray_(0), idxArray_(0) {}

    af_array gold_;
    af_array inArray_;
    af_array idxArray_;
};

string testNameGenerator(
    const ::testing::TestParamInfo info) {
    stringstream ss;
    ss 

Web Proxy Viewer  |  New URL  |  Original Page