FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
xtensor/test/test_xjson.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_xjson.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (56 loc) · 1.84 KB
Breadcrumbs
xtensor
/
test
/
test_xjson.cpp
Copy path
File metadata and controls
65 lines (56 loc) · 1.84 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
/*
**************************************************************************
* 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
<
string
>
#
include
"
xtensor/xarray.hpp
"
#
include
"
xtensor/xtensor.hpp
"
#
include
"
xtensor/xjson.hpp
"
#
include
"
xtensor/xview.hpp
"
namespace
xt
{
TEST
(xjson, xarray_to_json)
{
xt::xarray<
double
> t =
{{{
1
,
2
},
{
3
,
4
}},
{{
1
,
2
},
{
3
,
4
}}};
nlohmann::json jl = t;
std::string s = jl.
dump
();
EXPECT_EQ
(s,
"
[[[1.0,2.0],[3.0,4.0]],[[1.0,2.0],[3.0,4.0]]]
"
);
}
TEST
(xjson, xarray_from_json)
{
nlohmann::json j =
"
[[[1.0,2.0],[3.0,4.0]],[[1.0,2.0],[3.0,4.0]]]
"
_json;
auto
arr = j.
get
<xt::xarray<
double
>>();
auto
ref = xt::xarray<
double
>(
{{{
1
,
2
},
{
3
,
4
}},
{{
1
,
2
},
{
3
,
4
}}});
EXPECT_TRUE
(
all
(
equal
(arr, ref)));
}
TEST
(xjson, xview_from_json)
{
xt::xarray<
double
> arr =
{{{
1
,
2
},
{
3
,
4
}},
{{
1
,
2
},
{
3
,
4
}}};
auto
v =
xt::view
(arr,
0
);
auto
j =
"
[[10.0,10.0],[10.0,10.0]]
"
_json;
from_json
(j, v);
auto
ref = xt::xarray<
double
>(
{{{
10
,
10
},
{
10
,
10
}},
{{
1
,
2
},
{
3
,
4
}}});
EXPECT_TRUE
(
all
(
equal
(arr, ref)));
}
}
Back
|
FazBrowse Home
|
New Git URL