FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor/test/test_xtensor_adaptor.cpp at master · xtensor-stack/xtensor · GitHub
xtensor-stack
xtensor
Repository navigation
Code
Issues
381
(381)
Pull requests
43
(43)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
xtensor
/
test
/
test_xtensor_adaptor.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
204 lines (178 loc) · 5.74 KB
Breadcrumbs
xtensor
/
test
/
test_xtensor_adaptor.cpp
Copy path
File metadata and controls
204 lines (178 loc) · 5.74 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
/*
**************************************************************************
* 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. *
***************************************************************************
*/
#
include
"
xtensor/containers/xtensor.hpp
"
#
include
"
test_common.hpp
"
#
include
"
test_common_macros.hpp
"
namespace
xt
{
using
vec_type = std::vector<
int
>;
using
adaptor_type = xtensor_adaptor<vec_type,
3
, layout_type::dynamic>;
using
storage_type = std::array<std::
size_t
,
3
>;
TEST
(xtensor_adaptor, shaped_constructor)
{
SUBCASE
(
"
row_major constructor
"
)
{
row_major_result<storage_type> rm;
vec_type v;
adaptor_type
a
(v, rm.
shape
(), layout_type::row_major);
compare_shape
(a, rm);
}
SUBCASE
(
"
column_major constructor
"
)
{
column_major_result<storage_type> cm;
vec_type v;
adaptor_type
a
(v, cm.
shape
(), layout_type::column_major);
compare_shape
(a, cm);
}
}
TEST
(xtensor_adaptor, strided_constructor)
{
central_major_result<storage_type> cmr;
vec_type v;
adaptor_type
a
(v, cmr.
shape
(), cmr.
strides
());
compare_shape
(a, cmr);
}
TEST
(xtensor_adaptor, copy_semantic)
{
central_major_result<storage_type> res;
int
value =
2
;
vec_type
v
(res.
size
(), value);
adaptor_type
a
(v, res.
shape
(), res.
strides
());
SUBCASE
(
"
copy constructor
"
)
{
adaptor_type
b
(a);
compare_shape
(a, b);
EXPECT_EQ
(a.
storage
(), b.
storage
());
}
SUBCASE
(
"
assignment operator
"
)
{
row_major_result<storage_type> r;
vec_type
v2
(r.
size
(),
0
);
adaptor_type
c
(v2, r.
shape
());
EXPECT_NE
(a.
storage
(), c.
storage
());
c = a;
compare_shape
(a, c);
EXPECT_EQ
(a.
storage
(), c.
storage
());
}
}
TEST
(xtensor_adaptor, move_semantic)
{
central_major_result<storage_type> res;
int
value =
2
;
vec_type
v
(res.
size
(), value);
adaptor_type
a
(v, res.
shape
(), res.
strides
());
SUBCASE
(
"
move constructor
"
)
{
adaptor_type
tmp
(a);
adaptor_type
b
(
std::move
(tmp));
compare_shape
(a, b);
EXPECT_EQ
(a.
storage
(), b.
storage
());
}
SUBCASE
(
"
move assignment
"
)
{
row_major_result<storage_type> r;
vec_type
v2
(r.
size
(),
0
);
adaptor_type
c
(v2, r.
shape
());
EXPECT_NE
(a.
storage
(), c.
storage
());
adaptor_type
tmp
(a);
c =
std::move
(tmp);
compare_shape
(a, c);
EXPECT_EQ
(a.
storage
(), c.
storage
());
}
}
TEST
(xtensor_adaptor, resize)
{
vec_type v;
adaptor_type
a
(v);
test_resize<adaptor_type, storage_type>(a);
}
TEST
(xtensor_adaptor, reshape)
{
vec_type v;
adaptor_type
a
(v);
test_reshape<adaptor_type, storage_type>(a);
}
#
if
!(defined(XTENSOR_ENABLE_ASSERT) && defined(XTENSOR_DISABLE_EXCEPTIONS))
TEST
(xtensor_adaptor, access)
{
vec_type v;
adaptor_type
a
(v);
test_access<adaptor_type, storage_type>(a);
}
#
endif
TEST
(xtensor_adaptor, unchecked)
{
vec_type v;
adaptor_type
a
(v);
test_unchecked<adaptor_type, storage_type>(a);
}
TEST
(xtensor_adaptor, at)
{
vec_type v;
adaptor_type
a
(v);
test_at<adaptor_type, storage_type>(a);
}
TEST
(xtensor_adaptor, indexed_access)
{
vec_type v;
adaptor_type
a
(v);
test_indexed_access<adaptor_type, storage_type>(a);
}
TEST
(xtensor_adaptor, broadcast_shape)
{
vec_type v;
xtensor_adaptor<vec_type,
4
>
a
(v);
test_broadcast
(a);
}
TEST
(xtensor_adaptor, iterator)
{
vec_type v;
using
adaptor_rm = xtensor_adaptor<vec_type,
3
, layout_type::row_major>;
using
adaptor_cm = xtensor_adaptor<vec_type,
3
, layout_type::column_major>;
adaptor_rm
arm
(v);
adaptor_cm
acm
(v);
test_iterator<adaptor_rm, adaptor_cm, storage_type>(arm, acm);
}
TEST
(xtensor_adaptor, fill)
{
vec_type v;
xtensor_adaptor<vec_type,
2
>
a
(v);
test_fill
(a);
}
TEST
(xtensor_adaptor, xiterator)
{
vec_type v;
adaptor_type
a
(v);
test_xiterator<adaptor_type, storage_type>(a);
}
TEST
(xtensor_adaptor, reverse_xiterator)
{
vec_type v;
adaptor_type
a
(v);
test_reverse_xiterator<adaptor_type, storage_type>(a);
}
TEST
(xtensor_adaptor, adapt_std_array)
{
std::array<
double
,
9
> a = {
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
xtensor_adaptor<
decltype
(a),
2
>
ad
(a, {
3
,
3
});
EXPECT_EQ
(
ad
(
1
,
1
),
5
.);
ad = ad *
2
;
EXPECT_EQ
(
ad
(
1
,
1
),
10
.);
}
TEST
(xtensor_adaptor, iterator_types)
{
using
vec_type = std::vector<
int
>;
using
tensor_type = xtensor_adaptor<vec_type,
2
>;
using
const_tensor_type = xtensor_adaptor<
const
vec_type,
2
>;
using
iterator = vec_type::iterator;
using
const_iterator = vec_type::const_iterator;
test_iterator_types<tensor_type, iterator, const_iterator>();
test_iterator_types<const_tensor_type, const_iterator, const_iterator>();
}
}
Back
|
FazBrowse Home
|
New Git URL