-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathtest_sfinae.cpp
53 lines (45 loc) · 1.89 KB
/
test_sfinae.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/***************************************************************************
* 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 <limits>
#include "gtest/gtest.h"
#include "xtensor-python/pytensor.hpp"
#include "xtensor-python/pyarray.hpp"
#include "xtensor/containers/xarray.hpp"
#include "xtensor/containers/xtensor.hpp"
namespace xt
{
template <class E, std::enable_if_t<!xt::has_fixed_rank_t<E>::value, int> = 0>
inline bool sfinae_has_fixed_rank(E&&)
{
return false;
}
template <class E, std::enable_if_t<xt::has_fixed_rank_t<E>::value, int> = 0>
inline bool sfinae_has_fixed_rank(E&&)
{
return true;
}
TEST(sfinae, fixed_rank)
{
xt::pyarray<size_t> a = {{9, 9, 9}, {9, 9, 9}};
xt::pytensor<size_t, 1> b = {9, 9};
xt::pytensor<size_t, 2> c = {{9, 9}, {9, 9}};
EXPECT_TRUE(sfinae_has_fixed_rank(a) == false);
EXPECT_TRUE(sfinae_has_fixed_rank(b) == true);
EXPECT_TRUE(sfinae_has_fixed_rank(c) == true);
}
TEST(sfinae, get_rank)
{
xt::pytensor<double, 1> A = xt::zeros<double>({2});
xt::pytensor<double, 2> B = xt::zeros<double>({2, 2});
xt::pyarray<double> C = xt::zeros<double>({2, 2});
EXPECT_TRUE(xt::get_rank<decltype(A)>::value == 1ul);
EXPECT_TRUE(xt::get_rank<decltype(B)>::value == 2ul);
EXPECT_TRUE(xt::get_rank<decltype(C)>::value == SIZE_MAX);
}
}