FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor/test/test_xassign.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_xassign.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
177 lines (143 loc) · 3.87 KB
Breadcrumbs
xtensor
/
test
/
test_xassign.cpp
Copy path
File metadata and controls
177 lines (143 loc) · 3.87 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
/*
**************************************************************************
* 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
<
iterator
>
#
include
<
type_traits
>
#
include
<
vector
>
#
include
"
xtensor/containers/xarray.hpp
"
#
include
"
xtensor/containers/xtensor.hpp
"
#
include
"
xtensor/core/xassign.hpp
"
#
include
"
xtensor/core/xnoalias.hpp
"
#
include
"
xtensor/misc/xmanipulation.hpp
"
#
include
"
test_common.hpp
"
#
include
"
test_common_macros.hpp
"
//
a dummy shape *not derived* from std::vector but compatible
template
<
class
T
>
class
my_vector
{
private:
using
vector_type = std::vector<T>;
public:
using
value_type = T;
using
size_type =
typename
vector_type::size_type;
template
<
class
U
>
my_vector
(std::initializer_list<U> vals)
: m_data(vals.begin(), vals.end())
{
}
my_vector
(
const
std::
size_t
size =
0
,
const
T& val = T())
: m_data(size, val)
{
}
auto
resize
(
const
std::
size_t
size)
{
return
m_data.
resize
(size);
}
auto
size
()
const
{
return
m_data.
size
();
}
auto
cend
()
const
{
return
m_data.
cend
();
}
auto
cbegin
()
const
{
return
m_data.
cbegin
();
}
auto
end
()
{
return
m_data.
end
();
}
auto
end
()
const
{
return
m_data.
end
();
}
auto
begin
()
{
return
m_data.
begin
();
}
auto
begin
()
const
{
return
m_data.
begin
();
}
auto
rbegin
()
const
{
return
std::make_reverse_iterator
(
end
());
}
auto
rend
()
const
{
return
std::make_reverse_iterator
(
begin
());
}
auto
empty
()
const
{
return
m_data.
empty
();
}
auto
&
back
()
{
return
m_data.
back
();
}
const
auto
&
back
()
const
{
return
m_data.
back
();
}
auto
&
front
()
{
return
m_data.
front
();
}
const
auto
&
front
()
const
{
return
m_data.
front
();
}
auto
&
operator
[](
const
std::
size_t
i)
{
return
m_data[i];
}
const
auto
&
operator
[](
const
std::
size_t
i)
const
{
return
m_data[i];
}
private:
std::vector<T> m_data;
};
namespace
xt
{
template
<
class
T
,
class
C_T
>
struct
rebind_container
<T, my_vector<
C_T
>>
{
using
type = my_vector<T>;
};
TEST
(xassign, mix_shape_types)
{
{
//
xarray like with custom shape
using
my_xarray = xt::xarray_container<std::vector<
int
>, xt::layout_type::row_major, my_vector<std::
size_t
>>;
auto
a =
my_xarray::from_shape
({
1
,
3
});
auto
b = xt::xtensor<
int
,
2
>::
from_shape
({
2
,
3
});
xt::noalias
(a) += b;
EXPECT_EQ
(a.
dimension
(),
2
);
EXPECT_EQ
(a.
shape
(
0
),
2
);
EXPECT_EQ
(a.
shape
(
1
),
3
);
}
{
//
xarray like with custom shape
using
my_xarray = xt::xarray_container<std::vector<
int
>, xt::layout_type::row_major, my_vector<std::
size_t
>>;
auto
a =
my_xarray::from_shape
({
3
});
auto
b = xt::xtensor<
int
,
2
>::
from_shape
({
2
,
3
});
xt::noalias
(a) += b;
EXPECT_EQ
(a.
dimension
(),
2
);
EXPECT_EQ
(a.
shape
(
0
),
2
);
EXPECT_EQ
(a.
shape
(
1
),
3
);
}
}
TEST
(xassign, fixed_dimension_mismatch)
{
auto
a = xt::xtensor<
float
,
1
>::
from_shape
({
2
});
XT_ASSERT_THROW
(a =
xt::expand_dims
(a,
0
), std::runtime_error);
}
}
Back
|
FazBrowse Home
|
New Git URL