|
| 1 | +/*************************************************************************** |
| 2 | +* Copyright (c) Wolf Vollprecht, Johan Mabille and Sylvain Corlay * |
| 3 | +* Copyright (c) QuantStack * |
| 4 | +* * |
| 5 | +* Distributed under the terms of the BSD 3-Clause License. * |
| 6 | +* * |
| 7 | +* The full license is in the file LICENSE, distributed with this software. * |
| 8 | +****************************************************************************/ |
| 9 | + |
| 10 | +#include <limits> |
| 11 | + |
| 12 | +#include "gtest/gtest.h" |
| 13 | +#include "xtensor-r/rtensor.hpp" |
| 14 | +#include "xtensor-r/rarray.hpp" |
| 15 | +#include "xtensor/xarray.hpp" |
| 16 | +#include "xtensor/xtensor.hpp" |
| 17 | + |
| 18 | +namespace xt |
| 19 | +{ |
| 20 | + template <class E, std::enable_if_t<!xt::has_fixed_rank_t<E>::value, int> = 0> |
| 21 | + inline bool sfinae_has_fixed_rank(E&&) |
| 22 | + { |
| 23 | + return false; |
| 24 | + } |
| 25 | + |
| 26 | + template <class E, std::enable_if_t<xt::has_fixed_rank_t<E>::value, int> = 0> |
| 27 | + inline bool sfinae_has_fixed_rank(E&&) |
| 28 | + { |
| 29 | + return true; |
| 30 | + } |
| 31 | + |
| 32 | + TEST(sfinae, fixed_rank) |
| 33 | + { |
| 34 | + xt::rarray<int> a = {{9, 9, 9}, {9, 9, 9}}; |
| 35 | + xt::rtensor<int, 1> b = {9, 9}; |
| 36 | + xt::rtensor<int, 2> c = {{9, 9}, {9, 9}}; |
| 37 | + |
| 38 | + EXPECT_TRUE(sfinae_has_fixed_rank(a) == false); |
| 39 | + EXPECT_TRUE(sfinae_has_fixed_rank(b) == true); |
| 40 | + EXPECT_TRUE(sfinae_has_fixed_rank(c) == true); |
| 41 | + } |
| 42 | + |
| 43 | + TEST(sfinae, get_rank) |
| 44 | + { |
| 45 | + xt::rtensor<double, 1> A = xt::zeros<double>({2}); |
| 46 | + xt::rtensor<double, 2> B = xt::zeros<double>({2, 2}); |
| 47 | + xt::rarray<double> C = xt::zeros<double>({2, 2}); |
| 48 | + |
| 49 | + EXPECT_TRUE(xt::get_rank<decltype(A)>::value == 1ul); |
| 50 | + EXPECT_TRUE(xt::get_rank<decltype(B)>::value == 2ul); |
| 51 | + EXPECT_TRUE(xt::get_rank<decltype(C)>::value == SIZE_MAX); |
| 52 | + } |
| 53 | +} |
0 commit comments