forked from xtensor-stack/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxlayout.hpp
More file actions
97 lines (84 loc) · 3.1 KB
/
Copy pathxlayout.hpp
File metadata and controls
97 lines (84 loc) · 3.1 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* 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. *
****************************************************************************/
#ifndef XTENSOR_LAYOUT_HPP
#define XTENSOR_LAYOUT_HPP
// Do not include anything else here.
// xlayout.hpp is included in xtensor_forward.hpp
// and we don't want to bring other headers to it.
#include "xtensor_config.hpp"
namespace xt
{
/*! layout_type enum for xcontainer based xexpressions */
enum class layout_type
{
/*! dynamic layout_type: you can resize to row major, column major, or use custom strides */
dynamic = 0x00,
/*! layout_type compatible with all others */
any = 0xFF,
/*! row major layout_type */
row_major = 0x01,
/*! column major layout_type */
column_major = 0x02
};
/**
* Implementation of the following logical table:
*
* @verbatim
| d | a | r | c |
--+---+---+---+---+
d | d | d | d | d |
a | d | a | r | c |
r | d | r | r | d |
c | d | c | d | c |
d = dynamic, a = any, r = row_major, c = column_major.
@endverbatim
* Using bitmasks to avoid nested if-else statements.
*
* @param args the input layouts.
* @return the output layout, computed with the previous logical table.
*/
template <class... Args>
constexpr layout_type compute_layout(Args... args) noexcept;
constexpr layout_type default_assignable_layout(layout_type l) noexcept;
/******************
* Implementation *
******************/
namespace detail
{
constexpr layout_type compute_layout_impl() noexcept
{
return layout_type::any;
}
constexpr layout_type compute_layout_impl(layout_type l) noexcept
{
return l;
}
constexpr layout_type compute_layout_impl(layout_type lhs, layout_type rhs) noexcept
{
using type = std::underlying_type_t<layout_type>;
return layout_type(static_cast<type>(lhs) & static_cast<type>(rhs));
}
template <class... Args>
constexpr layout_type compute_layout_impl(layout_type lhs, Args... args) noexcept
{
return compute_layout_impl(lhs, compute_layout_impl(args...));
}
}
template <class... Args>
constexpr layout_type compute_layout(Args... args) noexcept
{
return detail::compute_layout_impl(args...);
}
constexpr layout_type default_assignable_layout(layout_type l) noexcept
{
return (l == layout_type::row_major || l == layout_type::column_major) ?
l : XTENSOR_DEFAULT_LAYOUT;
}
}
#endif