FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor/test/test_xvectorize.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_xvectorize.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
80 lines (71 loc) · 2.23 KB
Breadcrumbs
xtensor
/
test
/
test_xvectorize.cpp
Copy path
File metadata and controls
80 lines (71 loc) · 2.23 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
/*
**************************************************************************
* 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/xarray.hpp
"
#
include
"
xtensor/core/xvectorize.hpp
"
#
include
"
test_common_macros.hpp
"
namespace
xt
{
double
f1
(
double
d1,
double
d2)
{
return
d1 + d2;
}
using
shape_type = dynamic_shape<
size_t
>;
TEST
(xvectorize, function)
{
auto
vecf1 =
vectorize
(f1);
shape_type shape = {
3
,
2
};
xarray<
double
>
a
(shape,
1.5
);
xarray<
double
>
b
(shape,
2.3
);
xarray<
double
> c =
vecf1
(a, b);
EXPECT_EQ
(
a
(
0
,
0
) +
b
(
0
,
0
),
c
(
0
,
0
));
}
TEST
(xvectorize, lambda)
{
auto
lambda = [](
double
d1,
double
d2)
{
return
d1 + d2;
};
auto
vec_lambda =
vectorize
(lambda);
shape_type shape = {
3
,
2
};
xarray<
double
>
a
(shape,
1.5
);
xarray<
double
>
b
(shape,
2.3
);
xarray<
double
> c =
vec_lambda
(a, b);
EXPECT_EQ
(
a
(
0
,
0
) +
b
(
0
,
0
),
c
(
0
,
0
));
}
struct
func
{
inline
double
operator
()(
double
d1,
double
d2)
const
{
return
d1 + d2;
}
};
TEST
(xvectorize, functor)
{
func f;
auto
vecfunc =
vectorize
(f);
shape_type shape = {
3
,
2
};
xarray<
double
>
a
(shape,
1.5
);
xarray<
double
>
b
(shape,
2.3
);
xarray<
double
> c =
vecfunc
(a, b);
EXPECT_EQ
(
a
(
0
,
0
) +
b
(
0
,
0
),
c
(
0
,
0
));
}
TEST
(xvectorize, noargument)
{
auto
vecfunc =
vectorize
(
[]
{
return
double
(
1
.);
}
);
shape_type shape = {
3
,
2
};
xarray<
double
>
a
(shape,
1.5
);
a =
vecfunc
();
EXPECT_EQ
(
size_t
(
0
), a.
dimension
());
}
}
Back
|
FazBrowse Home
|
New Git URL