From 5ac171b015bc379e274923d9b9fef8ea5191beb1 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Wed, 22 Jan 2020 09:56:48 +0100 Subject: [PATCH] Removed irrelevant test_pyarray_ref file --- test/test_pyarray_ref.cpp | 275 -------------------------------------- 1 file changed, 275 deletions(-) delete mode 100644 test/test_pyarray_ref.cpp diff --git a/test/test_pyarray_ref.cpp b/test/test_pyarray_ref.cpp deleted file mode 100644 index 995d858..0000000 --- a/test/test_pyarray_ref.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/*************************************************************************** -* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#include "gtest/gtest.h" - -#include "xtensor-python/pyarray_ref.hpp" - -#include "xtensor/xarray.hpp" -#include "xtensor/xview.hpp" - -#include "test_common.hpp" - -namespace xt -{ - using container_type = std::vector; - - template - using ndarray = pyarray_ref; - - void test1 (ndarrayconst& x) - { - ndarray y = x; - ndarray z = xt::zeros({10}); - } - - double compute(ndarray const& xs) - { - auto v = xt::view (xs, 0, xt::all()); - return v(0); - } - - TEST(pyarray_ref, initializer_constructor) - { - pyarray_ref t - {{{ 0, 1, 2}, - { 3, 4, 5}, - { 6, 7, 8}}, - {{ 9, 10, 11}, - {12, 13, 14}, - {15, 16, 17}}}; - - EXPECT_EQ(t.dimension(), 3); - EXPECT_EQ(t(0, 0, 1), 1); - EXPECT_EQ(t.shape()[0], 2); - } - - TEST(pyarray_ref, shaped_constructor) - { - { - SCOPED_TRACE("row_major constructor"); - row_major_result<> rm; - pyarray_ref ra(rm.m_shape); - compare_shape(ra, rm); - EXPECT_EQ(layout_type::row_major, ra.layout()); - } - - { - SCOPED_TRACE("column_major constructor"); - column_major_result<> cm; - pyarray_ref ca(cm.m_shape, layout_type::column_major); - compare_shape(ca, cm); - EXPECT_EQ(layout_type::column_major, ca.layout()); - } - } - - TEST(pyarray_ref, from_shape) - { - auto arr = pyarray_ref::from_shape({5, 2, 6}); - auto exp_shape = std::vector{5, 2, 6}; - EXPECT_TRUE(std::equal(arr.shape().begin(), arr.shape().end(), exp_shape.begin())); - EXPECT_EQ(arr.shape().size(), 3); - EXPECT_EQ(arr.size(), 5 * 2 * 6); - } - - TEST(pyarray_ref, strided_constructor) - { - central_major_result<> cmr; - pyarray_ref cma(cmr.m_shape, cmr.m_strides); - compare_shape(cma, cmr); - } - - TEST(pyarray_ref, valued_constructor) - { - { - SCOPED_TRACE("row_major valued constructor"); - row_major_result<> rm; - int value = 2; - pyarray_ref ra(rm.m_shape, value); - compare_shape(ra, rm); - std::vector vec(ra.size(), value); - EXPECT_TRUE(std::equal(vec.cbegin(), vec.cend(), ra.storage().cbegin())); - } - - { - SCOPED_TRACE("column_major valued constructor"); - column_major_result<> cm; - int value = 2; - pyarray_ref ca(cm.m_shape, value, layout_type::column_major); - compare_shape(ca, cm); - std::vector vec(ca.size(), value); - EXPECT_TRUE(std::equal(vec.cbegin(), vec.cend(), ca.storage().cbegin())); - } - } - - TEST(pyarray_ref, strided_valued_constructor) - { - central_major_result<> cmr; - int value = 2; - pyarray_ref cma(cmr.m_shape, cmr.m_strides, value); - compare_shape(cma, cmr); - std::vector vec(cma.size(), value); - EXPECT_TRUE(std::equal(vec.cbegin(), vec.cend(), cma.storage().cbegin())); - } - - TEST(pyarray_ref, copy_semantic) - { - central_major_result<> res; - int value = 2; - pyarray_ref a(res.m_shape, res.m_strides, value); - - { - SCOPED_TRACE("copy constructor"); - pyarray_ref b(a); - compare_shape(a, b); - EXPECT_EQ(a.storage(), b.storage()); - a.data()[0] += 1; - EXPECT_EQ(a.storage()[0], b.storage()[0]); - } - - { - SCOPED_TRACE("assignment operator"); - row_major_result<> r; - pyarray_ref c(r.m_shape, 0); - EXPECT_NE(a.storage(), c.storage()); - c = a; - compare_shape(a, c); - EXPECT_EQ(a.storage(), c.storage()); - a.data()[0] += 1; - EXPECT_EQ(a.storage()[0], c.storage()[0]); - } - } - - TEST(pyarray_ref, move_semantic) - { - central_major_result<> res; - int value = 2; - pyarray_ref a(res.m_shape, res.m_strides, value); - - { - SCOPED_TRACE("move constructor"); - pyarray_ref tmp(a); - pyarray_ref b(std::move(tmp)); - compare_shape(a, b); - EXPECT_EQ(a.storage(), b.storage()); - } - - { - SCOPED_TRACE("move assignment"); - row_major_result<> r; - pyarray_ref c(r.m_shape, 0); - EXPECT_NE(a.storage(), c.storage()); - pyarray_ref tmp(a); - c = std::move(tmp); - compare_shape(a, c); - EXPECT_EQ(a.storage(), c.storage()); - } - } - - TEST(pyarray_ref, extended_constructor) - { - xt::xarray a1 = { { 1, 2 },{ 3, 4 } }; - xt::xarray a2 = { { 1, 2 },{ 3, 4 } }; - pyarray_ref c = a1 + a2; - EXPECT_EQ(c(0, 0), a1(0, 0) + a2(0, 0)); - EXPECT_EQ(c(0, 1), a1(0, 1) + a2(0, 1)); - EXPECT_EQ(c(1, 0), a1(1, 0) + a2(1, 0)); - EXPECT_EQ(c(1, 1), a1(1, 1) + a2(1, 1)); - } - - TEST(pyarray_ref, resize) - { - pyarray_ref a; - test_resize(a); - - pyarray_ref b = { {1, 2}, {3, 4} }; - a.resize(b.shape()); - EXPECT_EQ(a.shape(), b.shape()); - } - - TEST(pyarray_ref, transpose) - { - pyarray_ref a; - test_transpose(a); - } - - TEST(pyarray_ref, access) - { - pyarray_ref a; - test_access(a); - } - - TEST(pyarray_ref, indexed_access) - { - pyarray_ref a; - test_indexed_access(a); - } - - TEST(pyarray_ref, broadcast_shape) - { - pyarray_ref a; - test_broadcast(a); - test_broadcast2(a); - } - - TEST(pyarray_ref, iterator) - { - pyarray_ref a; - pyarray_ref b; - test_iterator(a, b); - - pyarray_ref c; - bool truthy = std::is_same::value; - EXPECT_TRUE(truthy); - } - - TEST(pyarray_ref, initializer_list) - { - pyarray_ref a0(1); - pyarray_ref a1({1, 2}); - pyarray_ref a2({{1, 2}, {2, 4}, {5, 6}}); - EXPECT_EQ(1, a0()); - EXPECT_EQ(2, a1(1)); - EXPECT_EQ(4, a2(1, 1)); - } - - TEST(pyarray_ref, zerod) - { - pyarray_ref a; - EXPECT_EQ(0, a()); - } - - TEST(pyarray_ref, reshape) - { - pyarray_ref a = {{1,2,3}, {4,5,6}}; - auto ptr = a.data(); - a.reshape({1, 6}); - std::vector sc1({1, 6}); - EXPECT_TRUE(std::equal(sc1.begin(), sc1.end(), a.shape().begin()) && a.shape().size() == 2); - EXPECT_EQ(ptr, a.data()); - a.reshape({6}); - std::vector sc2 = {6}; - EXPECT_TRUE(std::equal(sc2.begin(), sc2.end(), a.shape().begin()) && a.shape().size() == 1); - EXPECT_EQ(ptr, a.data()); - } - - TEST(pyarray_ref, view) - { - xt::pyarray_ref arr = xt::zeros({ 10 }); - auto v = xt::view(arr, xt::all()); - EXPECT_EQ(v(0), 0.); - } - - TEST(pyarray_ref, zerod_copy) - { - xt::pyarray_ref arr = 2; - xt::pyarray_ref arr2(arr); - EXPECT_EQ(arr(), arr2()); - } -}