[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/arrayfire/arrayfire/feature/optional-graphics/test/diagonal.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 

using af::array;
using af::constant;
using af::deviceGC;
using af::diag;
using af::dim4;
using af::exception;
using af::max;
using af::seq;
using af::span;
using af::sum;
using std::abs;
using std::vector;

template
class Diagonal : public ::testing::Test {};

typedef ::testing::Types
    TestTypes;
TYPED_TEST_SUITE(Diagonal, TestTypes);

TYPED_TEST(Diagonal, Create) {
    SUPPORTED_TYPE_CHECK(TypeParam);
    try {
        static const int size = 1000;
        vector input(size * size);
        for (int i = 0; i < size; i++) { input[i] = i; }
        for (int jj = 10; jj < size; jj += 100) {
            array data(jj, &input.front(), afHost);
            array out = diag(data, 0, false);

            vector h_out(out.elements());
            out.host(&h_out.front());

            for (int i = 0; i < (int)out.dims(0); i++) {
                for (int j = 0; j < (int)out.dims(1); j++) {
                    if (i == j)
                        ASSERT_EQ(input[i], h_out[i * out.dims(0) + j]);
                    else
                        ASSERT_EQ(TypeParam(0), h_out[i * out.dims(0) + j]);
                }
            }
        }
    } catch (const exception& ex) { FAIL() 

Web Proxy Viewer  |  New URL  |  Original Page