FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor-python/test/test_pyarray.cpp at master · Mbakaya/xtensor-python · GitHub
Mbakaya
xtensor-python
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
xtensor-python
/
test
/
test_pyarray.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
217 lines (188 loc) · 5.8 KB
Breadcrumbs
xtensor-python
/
test
/
test_pyarray.cpp
Copy path
File metadata and controls
217 lines (188 loc) · 5.8 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
/*
**************************************************************************
* Copyright (c) 2016, Johan Mabille and Sylvain Corlay *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
***************************************************************************
*/
#
include
"
gtest/gtest.h
"
#
include
"
xtensor-python/pyarray.hpp
"
#
include
"
xtensor/xarray.hpp
"
#
include
"
test_common.hpp
"
namespace
xt
{
using
container_type = std::vector<npy_intp>;
TEST
(pyarray, initializer_constructor)
{
pyarray<
int
> t
{{{
0
,
1
,
2
},
{
3
,
4
,
5
},
{
6
,
7
,
8
}},
{{
9
,
10
,
11
},
{
12
,
13
,
14
},
{
15
,
16
,
17
}}};
EXPECT_EQ
(t.
dimension
(),
3
);
EXPECT_EQ
(
t
(
0
,
0
,
1
),
1
);
EXPECT_EQ
(t.
shape
()[
0
],
2
);
}
TEST
(pyarray, shaped_constructor)
{
{
SCOPED_TRACE
(
"
row_major constructor
"
);
row_major_result<> rm;
pyarray<
int
>
ra
(rm.
m_shape
);
compare_shape
(ra, rm);
EXPECT_EQ
(layout_type::row_major, ra.
layout
());
}
{
SCOPED_TRACE
(
"
column_major constructor
"
);
column_major_result<> cm;
pyarray<
int
>
ca
(cm.
m_shape
, layout_type::column_major);
compare_shape
(ca, cm);
EXPECT_EQ
(layout_type::column_major, ca.
layout
());
}
}
TEST
(pyarray, strided_constructor)
{
central_major_result<> cmr;
pyarray<
int
>
cma
(cmr.
m_shape
, cmr.
m_strides
);
compare_shape
(cma, cmr);
}
TEST
(pyarray, valued_constructor)
{
{
SCOPED_TRACE
(
"
row_major valued constructor
"
);
row_major_result<> rm;
int
value =
2
;
pyarray<
int
>
ra
(rm.
m_shape
, value);
compare_shape
(ra, rm);
std::vector<
int
>
vec
(ra.
size
(), value);
EXPECT_TRUE
(
std::equal
(vec.
cbegin
(), vec.
cend
(), ra.
data
().
cbegin
()));
}
{
SCOPED_TRACE
(
"
column_major valued constructor
"
);
column_major_result<> cm;
int
value =
2
;
pyarray<
int
>
ca
(cm.
m_shape
, value, layout_type::column_major);
compare_shape
(ca, cm);
std::vector<
int
>
vec
(ca.
size
(), value);
EXPECT_TRUE
(
std::equal
(vec.
cbegin
(), vec.
cend
(), ca.
data
().
cbegin
()));
}
}
TEST
(pyarray, strided_valued_constructor)
{
central_major_result<> cmr;
int
value =
2
;
pyarray<
int
>
cma
(cmr.
m_shape
, cmr.
m_strides
, value);
compare_shape
(cma, cmr);
std::vector<
int
>
vec
(cma.
size
(), value);
EXPECT_TRUE
(
std::equal
(vec.
cbegin
(), vec.
cend
(), cma.
data
().
cbegin
()));
}
TEST
(pyarray, copy_semantic)
{
central_major_result<> res;
int
value =
2
;
pyarray<
int
>
a
(res.
m_shape
, res.
m_strides
, value);
{
SCOPED_TRACE
(
"
copy constructor
"
);
pyarray<
int
>
b
(a);
compare_shape
(a, b);
EXPECT_EQ
(a.
data
(), b.
data
());
a.
data
()[
0
] +=
1
;
EXPECT_NE
(a.
data
()[
0
], b.
data
()[
0
]);
}
{
SCOPED_TRACE
(
"
assignment operator
"
);
row_major_result<> r;
pyarray<
int
>
c
(r.
m_shape
,
0
);
EXPECT_NE
(a.
data
(), c.
data
());
c = a;
compare_shape
(a, c);
EXPECT_EQ
(a.
data
(), c.
data
());
a.
data
()[
0
] +=
1
;
EXPECT_NE
(a.
data
()[
0
], c.
data
()[
0
]);
}
}
TEST
(pyarray, move_semantic)
{
central_major_result<> res;
int
value =
2
;
pyarray<
int
>
a
(res.
m_shape
, res.
m_strides
, value);
{
SCOPED_TRACE
(
"
move constructor
"
);
pyarray<
int
>
tmp
(a);
pyarray<
int
>
b
(
std::move
(tmp));
compare_shape
(a, b);
EXPECT_EQ
(a.
data
(), b.
data
());
}
{
SCOPED_TRACE
(
"
move assignment
"
);
row_major_result<> r;
pyarray<
int
>
c
(r.
m_shape
,
0
);
EXPECT_NE
(a.
data
(), c.
data
());
pyarray<
int
>
tmp
(a);
c =
std::move
(tmp);
compare_shape
(a, c);
EXPECT_EQ
(a.
data
(), c.
data
());
}
}
TEST
(pyarray, extended_constructor)
{
xt::xarray<
int
> a1 = { {
1
,
2
},{
3
,
4
} };
xt::xarray<
int
> a2 = { {
1
,
2
},{
3
,
4
} };
pyarray<
int
> c = a1 + a2;
EXPECT_EQ
(
c
(
0
,
0
),
a1
(
0
,
0
) +
a2
(
0
,
0
));
EXPECT_EQ
(
c
(
0
,
1
),
a1
(
0
,
1
) +
a2
(
0
,
1
));
EXPECT_EQ
(
c
(
1
,
0
),
a1
(
1
,
0
) +
a2
(
1
,
0
));
EXPECT_EQ
(
c
(
1
,
1
),
a1
(
1
,
1
) +
a2
(
1
,
1
));
}
TEST
(pyarray, reshape)
{
pyarray<
int
> a;
test_reshape
(a);
pyarray<
int
> b = { {
1
,
2
}, {
3
,
4
} };
a.
reshape
(b.
shape
());
EXPECT_EQ
(a.
shape
(), b.
shape
());
}
TEST
(pyarray, transpose)
{
pyarray<
int
> a;
test_transpose
(a);
}
TEST
(pyarray, access)
{
pyarray<
int
> a;
test_access
(a);
}
TEST
(pyarray, indexed_access)
{
pyarray<
int
> a;
test_indexed_access
(a);
}
TEST
(pyarray, broadcast_shape)
{
pyarray<
int
> a;
test_broadcast
(a);
test_broadcast2
(a);
}
TEST
(pyarray, iterator)
{
pyarray<
int
> a;
pyarray<
int
> b;
test_iterator
(a, b);
}
TEST
(pyarray, initializer_list)
{
pyarray<
int
>
a0
(
1
);
pyarray<
int
>
a1
({
1
,
2
});
pyarray<
int
>
a2
({{
1
,
2
}, {
2
,
4
}, {
5
,
6
}});
EXPECT_EQ
(
1
,
a0
());
EXPECT_EQ
(
2
,
a1
(
1
));
EXPECT_EQ
(
4
,
a2
(
1
,
1
));
}
TEST
(pyarray, zerod)
{
pyarray<
int
> a;
EXPECT_EQ
(
0
,
a
());
}
}
Back
|
FazBrowse Home
|
New Git URL