FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor/include/xtensor/views/xview_utils.hpp at master · xtensor-stack/xtensor · GitHub
xtensor-stack
xtensor
Repository navigation
Code
Issues
381
(381)
Pull requests
44
(44)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
xtensor
/
include
/
xtensor
/
views
/
xview_utils.hpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
287 lines (239 loc) · 8.24 KB
Breadcrumbs
xtensor
/
include
/
xtensor
/
views
/
xview_utils.hpp
Copy path
File metadata and controls
287 lines (239 loc) · 8.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
**************************************************************************
* 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_VIEW_UTILS_HPP
#
define
XTENSOR_VIEW_UTILS_HPP
#
include
<
array
>
#
include
"
../core/xlayout.hpp
"
#
include
"
../core/xtensor_forward.hpp
"
#
include
"
../views/xslice.hpp
"
namespace
xt
{
/*
*******************************
* helper functions declaration *
*******************************
*/
//
number of integral types in the specified sequence of types
template
<
class
... S>
constexpr
std::
size_t
integral_count
();
//
number of integral types in the specified sequence of types before specified index
template
<
class
... S>
constexpr
std::
size_t
integral_count_before
(std::
size_t
i);
//
index in the specified sequence of types of the ith non-integral type
template
<
class
... S>
constexpr
std::
size_t
integral_skip
(std::
size_t
i);
//
number of newaxis types in the specified sequence of types
template
<
class
... S>
constexpr
std::
size_t
newaxis_count
();
//
number of newaxis types in the specified sequence of types before specified index
template
<
class
... S>
constexpr
std::
size_t
newaxis_count_before
(std::
size_t
i);
//
index in the specified sequence of types of the ith non-newaxis type
template
<
class
... S>
constexpr
std::
size_t
newaxis_skip
(std::
size_t
i);
template
<
class
S
,
class
It
>
inline
auto
get_slice_value
(
const
S& slice, It& it)
noexcept
{
if
constexpr
(is_xslice<S>::value)
{
return
slice
(
typename
S::size_type
(*it));
}
else
{
return
static_cast
<std::
size_t
>(slice);
}
}
/*
**********************
* view_temporary_type *
**********************
*/
namespace
detail
{
template
<
class
T
,
class
S
, layout_type L,
class
...
SL
>
struct
view_temporary_type_impl
{
using
type = xt::xarray<T, L>;
};
template
<
class
T
,
class
I
, std::
size_t
N, layout_type L,
class
...
SL
>
struct
view_temporary_type_impl
<T, std::array<I, N>, L,
SL
...>
{
using
type = xt::xtensor<T, N + newaxis_count<
SL
...>() - integral_count<
SL
...>(), L>;
};
}
template
<
class
E
,
class
...
SL
>
struct
view_temporary_type
{
using
type =
typename
detail::view_temporary_type_impl<
std::
decay_t
<
typename
E::value_type>,
typename
E::shape_type,
E::static_layout,
SL
...>::type;
};
template
<
class
E
,
class
...
SL
>
using
view_temporary_type_t
=
typename
view_temporary_type<E,
SL
...>::type;
/*
***********************
* count integral types *
***********************
*/
namespace
detail
{
template
<
class
T
,
class
... S>
struct
integral_count_impl
{
static
constexpr
std::
size_t
count
(std::
size_t
i)
noexcept
{
return
i
? (integral_count_impl<S...>::
count
(i -
1
)
+ (xtl::is_integral<std::
remove_reference_t
<T>>::value ?
1
:
0
))
:
0
;
}
};
template
<>
struct
integral_count_impl
<
void
>
{
static
constexpr
std::
size_t
count
(std::
size_t
/*
i
*/
)
noexcept
{
return
0
;
}
};
}
template
<
class
... S>
constexpr
std::
size_t
integral_count
()
{
return
detail::integral_count_impl<S...,
void
>::
count
(
sizeof
...(S));
}
template
<
class
... S>
constexpr
std::
size_t
integral_count_before
(std::
size_t
i)
{
return
detail::integral_count_impl<S...,
void
>::
count
(i);
}
/*
**********************
* count newaxis types *
**********************
*/
namespace
detail
{
template
<
class
T
>
struct
is_newaxis
: std::false_type
{
};
template
<
class
T
>
struct
is_newaxis
<xnewaxis<T>> : public std::true_type
{
};
template
<
class
T
>
constexpr
bool
is_newaxis_v = is_newaxis<T>::value;
template
<
class
T
,
class
... S>
struct
newaxis_count_impl
{
static
constexpr
std::
size_t
count
(std::
size_t
i)
noexcept
{
return
i
? (newaxis_count_impl<S...>::
count
(i -
1
)
+ (is_newaxis<std::
remove_reference_t
<T>>::value ?
1
:
0
))
:
0
;
}
};
template
<>
struct
newaxis_count_impl
<
void
>
{
static
constexpr
std::
size_t
count
(std::
size_t
/*
i
*/
)
noexcept
{
return
0
;
}
};
}
template
<
class
... S>
constexpr
std::
size_t
newaxis_count
()
{
return
detail::newaxis_count_impl<S...,
void
>::
count
(
sizeof
...(S));
}
template
<
class
... S>
constexpr
std::
size_t
newaxis_count_before
(std::
size_t
i)
{
return
detail::newaxis_count_impl<S...,
void
>::
count
(i);
}
/*
*********************************
* index of ith non-integral type *
*********************************
*/
namespace
detail
{
template
<
class
T
,
class
... S>
struct
integral_skip_impl
{
static
constexpr
std::
size_t
count
(std::
size_t
i)
noexcept
{
return
i ==
0
?
count_impl
() :
count_impl
(i);
}
private:
static
constexpr
std::
size_t
count_impl
(std::
size_t
i)
noexcept
{
return
1
+ (xtl::is_integral<std::
remove_reference_t
<T>>::value
? integral_skip_impl<S...>::
count
(i)
: integral_skip_impl<S...>::
count
(i -
1
));
}
static
constexpr
std::
size_t
count_impl
()
noexcept
{
return
xtl::is_integral<std::
remove_reference_t
<T>>::value
?
1
+ integral_skip_impl<S...>::
count
(
0
)
:
0
;
}
};
template
<>
struct
integral_skip_impl
<
void
>
{
static
constexpr
std::
size_t
count
(std::
size_t
i)
noexcept
{
return
i;
}
};
}
template
<
class
... S>
constexpr
std::
size_t
integral_skip
(std::
size_t
i)
{
return
detail::integral_skip_impl<S...,
void
>::
count
(i);
}
/*
********************************
* index of ith non-newaxis type *
********************************
*/
namespace
detail
{
template
<
class
T
,
class
... S>
struct
newaxis_skip_impl
{
static
constexpr
std::
size_t
count
(std::
size_t
i)
noexcept
{
return
i ==
0
?
count_impl
() :
count_impl
(i);
}
private:
static
constexpr
std::
size_t
count_impl
(std::
size_t
i)
noexcept
{
return
1
+ (is_newaxis<std::
remove_reference_t
<T>>::value
? newaxis_skip_impl<S...>::
count
(i)
: newaxis_skip_impl<S...>::
count
(i -
1
));
}
static
constexpr
std::
size_t
count_impl
()
noexcept
{
return
is_newaxis<std::
remove_reference_t
<T>>::value ?
1
+ newaxis_skip_impl<S...>::
count
(
0
)
:
0
;
}
};
template
<>
struct
newaxis_skip_impl
<
void
>
{
static
constexpr
std::
size_t
count
(std::
size_t
i)
noexcept
{
return
i;
}
};
}
template
<
class
... S>
constexpr
std::
size_t
newaxis_skip
(std::
size_t
i)
{
return
detail::newaxis_skip_impl<S...,
void
>::
count
(i);
}
}
#
endif
Back
|
FazBrowse Home
|
New Git URL