[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/AMD-Ecosystem/arrayfire/master/test/convolve.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 

using af::array;
using af::cdouble;
using af::cfloat;
using af::dim4;
using af::dtype_traits;
using std::abs;
using std::endl;
using std::string;
using std::vector;

template
class Convolve : public ::testing::Test {
   public:
    virtual void SetUp() {}
};

// create a list of types to be tested
typedef ::testing::Types
    TestTypes;

// register the type list
TYPED_TEST_SUITE(Convolve, TestTypes);

template
void convolveTest(string pTestFile, int baseDim, bool expand) {
    SUPPORTED_TYPE_CHECK(T);

    vector numDims;
    vector in;
    vector tests;

    readTests(pTestFile, numDims, in, tests);

    dim4 sDims        = numDims[0];
    dim4 fDims        = numDims[1];
    af_array signal   = 0;
    af_array filter   = 0;
    af_array outArray = 0;

    ASSERT_SUCCESS(af_create_array(&signal, &(in[0].front()), sDims.ndims(),
                                   sDims.get(),
                                   (af_dtype)dtype_traits::af_type));
    ASSERT_SUCCESS(af_create_array(&filter, &(in[1].front()), fDims.ndims(),
                                   fDims.get(),
                                   (af_dtype)dtype_traits::af_type));

    af_conv_mode mode = expand ? AF_CONV_EXPAND : AF_CONV_DEFAULT;
    switch (baseDim) {
        case 1:
            ASSERT_SUCCESS(
                af_convolve1(&outArray, signal, filter, mode, AF_CONV_AUTO));
            break;
        case 2:
            ASSERT_SUCCESS(
                af_convolve2(&outArray, signal, filter, mode, AF_CONV_AUTO));
            break;
        case 3:
            ASSERT_SUCCESS(
                af_convolve3(&outArray, signal, filter, mode, AF_CONV_AUTO));
            break;
    }

    vector currGoldBar = tests[0];
    size_t nElems         = currGoldBar.size();
    vector outData(nElems);

    ASSERT_SUCCESS(af_get_data_ptr((void *)&outData.front(), outArray));

    for (size_t elIter = 0; elIter < nElems; ++elIter) {
        ASSERT_EQ(currGoldBar[elIter], outData[elIter])
            

Web Proxy Viewer  |  New URL  |  Original Page