FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor/test/test_xchunked_array.cpp at stable · 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
/
test
/
test_xchunked_array.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
126 lines (101 loc) · 3.28 KB
Breadcrumbs
xtensor
/
test
/
test_xchunked_array.cpp
Copy path
File metadata and controls
126 lines (101 loc) · 3.28 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
/*
**************************************************************************
* 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
"
gtest/gtest.h
"
#
include
"
xtensor/xbroadcast.hpp
"
#
include
"
xtensor/xchunked_array.hpp
"
#
include
"
xtensor/xcsv.hpp
"
#
include
"
xtensor/xnoalias.hpp
"
namespace
xt
{
using
in_memory_chunked_array = xchunked_array<xarray<xarray<
double
>>>;
TEST
(xchunked_array, indexed_access)
{
auto
a = chunked_array<
double
>({
10
,
10
,
10
}, {
2
,
3
,
4
});
std::vector<
size_t
> idx = {
3
,
9
,
8
};
double
val;
val =
1
.;
a[idx] = val;
ASSERT_EQ
(a[idx], val);
ASSERT_EQ
(
a
(
3
,
9
,
8
), val);
val =
2
.;
a
(
3
,
9
,
8
) = val;
ASSERT_EQ
(
a
(
3
,
9
,
8
), val);
ASSERT_EQ
(a[idx], val);
val =
3
.;
for
(
auto
& it: a)
it = val;
for
(
auto
it: a)
ASSERT_EQ
(it, val);
}
TEST
(xchunked_array, assign_expression)
{
std::vector<
size_t
> shape1 = {
2
,
2
,
2
};
std::vector<
size_t
> chunk_shape1 = {
2
,
3
,
4
};
auto
a1 = chunked_array<
double
>(shape1, chunk_shape1);
double
val;
val =
3
.;
a1 =
broadcast
(val, a1.
shape
());
for
(
const
auto
& v: a1)
{
EXPECT_EQ
(v, val);
}
std::vector<
size_t
> shape2 = {
32
,
10
,
10
};
auto
a2 = chunked_array<
double
>(shape2, chunk_shape1);
a2 =
broadcast
(val, a2.
shape
());
for
(
const
auto
& v: a2)
{
EXPECT_EQ
(v, val);
}
a2 += a2;
for
(
const
auto
& v: a2)
{
EXPECT_EQ
(v,
2
. * val);
}
a2 +=
2
.;
for
(
const
auto
& v: a2)
{
EXPECT_EQ
(v,
2
. * val +
2
.);
}
xarray<
double
> a3
{{
1
.,
2
.,
3
.},
{
4
.,
5
.,
6
.},
{
7
.,
8
.,
9
.}};
EXPECT_EQ
(
is_chunked
(a3),
false
);
std::vector<
size_t
> chunk_shape4 = {
2
,
2
};
auto
a4 =
chunked_array
(a3, chunk_shape4);
EXPECT_EQ
(
is_chunked
(a4),
true
);
double
i =
1
.;
for
(
const
auto
& v: a4)
{
EXPECT_EQ
(v, i);
i +=
1
.;
}
auto
a5 =
in_memory_chunked_array
(a4);
EXPECT_EQ
(
is_chunked
(a5),
true
);
for
(
const
auto
& v: a5.
chunk_shape
())
{
EXPECT_EQ
(v,
2
);
}
auto
a6 =
chunked_array
(a3);
EXPECT_EQ
(
is_chunked
(a6),
true
);
for
(
const
auto
& v: a6.
chunk_shape
())
{
EXPECT_EQ
(v,
3
);
}
}
TEST
(xchunked_array, noalias)
{
std::vector<std::
size_t
> shape = {
10
,
10
,
10
};
std::vector<std::
size_t
> chunk_shape = {
2
,
2
,
2
};
auto
a = chunked_array<
double
>(shape, chunk_shape);
xt::xarray<
double
> b =
arange
(
1000
).
reshape
({
10
,
10
,
10
});
noalias
(a) = b;
EXPECT_EQ
(a, b);
}
}
Back
|
FazBrowse Home
|
New Git URL