Skip to content

Commit 1c33912

Browse files
committed
Add JSON serialization and deserialization of xtensor containers
1 parent 039b838 commit 1c33912

File tree

15 files changed

+346
-10
lines changed

15 files changed

+346
-10
lines changed

.appveyor.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ platform:
55
- x86
66

77
image:
8-
- Visual Studio 2017
8+
- Visual Studio 2017
99
- Visual Studio 2015
1010

1111
environment:
@@ -15,7 +15,7 @@ environment:
1515
init:
1616
- "ECHO %MINICONDA%"
1717
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set VCVARPATH="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
18-
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set VCARGUMENT=%PLATFORM%
18+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set VCARGUMENT=%PLATFORM%
1919
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" if "%PLATFORM%" == "x64" set VCVARPATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
2020
- if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" if "%PLATFORM%" == "x86" set VCVARPATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
2121
- echo "%VCVARPATH% %VCARGUMENT%"
@@ -30,9 +30,10 @@ install:
3030
- conda update -q conda
3131
- conda info -a
3232
- conda install gtest cmake -c conda-forge
33-
- conda install xtl==0.4.1 -c QuantStack
33+
- conda install xtl==0.4.8 -c QuantStack
3434
- conda install xsimd -c QuantStack
35-
#- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DBUILD_TESTS=ON -DXTENSOR_USE_XSIMD=ON -DDISABLE_VS2017=ON .
35+
- conda install nlohmann_json -c QuantStack
36+
# - cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DBUILD_TESTS=ON -DXTENSOR_USE_XSIMD=ON -DDISABLE_VS2017=ON .
3637
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DBUILD_TESTS=ON -DDISABLE_VS2017=ON .
3738
- nmake test_xtensor_lib
3839
- cd test

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ install:
114114
- hash -r
115115
- conda config --set always_yes yes --set changeps1 no
116116
- conda update -q conda
117-
- conda install gtest cmake -c conda-forge
118-
- conda install xtl==0.4.1 -c QuantStack
117+
- conda install gtest cmake -c conda-forge
118+
- conda install xtl==0.4.8 -c QuantStack
119119
- conda install xsimd -c QuantStack
120+
- conda install nlohmann_json -c QuantStack
120121
# Testing
121122
- mkdir build
122123
- cd build

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ message(STATUS "Building xtensor v${${PROJECT_NAME}_VERSION}")
2929
# ============
3030

3131
find_package(xtl 0.4.1 REQUIRED)
32+
3233
message(STATUS "Found xtl: ${xtl_INCLUDE_DIRS}/xtl")
3334

35+
find_package(nlohmann_json 3.1.1)
36+
3437
# Build
3538
# =====
3639

@@ -59,6 +62,7 @@ set(XTENSOR_HEADERS
5962
${XTENSOR_INCLUDE_DIR}/xtensor/xio.hpp
6063
${XTENSOR_INCLUDE_DIR}/xtensor/xiterable.hpp
6164
${XTENSOR_INCLUDE_DIR}/xtensor/xiterator.hpp
65+
${XTENSOR_INCLUDE_DIR}/xtensor/xjson.hpp
6266
${XTENSOR_INCLUDE_DIR}/xtensor/xlayout.hpp
6367
${XTENSOR_INCLUDE_DIR}/xtensor/xmath.hpp
6468
${XTENSOR_INCLUDE_DIR}/xtensor/xnoalias.hpp

docs/source/api/io_index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht
2+
3+
Distributed under the terms of the BSD 3-Clause License.
4+
5+
The full license is in the file LICENSE, distributed with this software.
6+
7+
IO Operations
8+
=============
9+
10+
.. toctree::
11+
12+
xjson

docs/source/api/xjson.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht
2+
3+
Distributed under the terms of the BSD 3-Clause License.
4+
5+
The full license is in the file LICENSE, distributed with this software.
6+
7+
xjson
8+
=====
9+
10+
Defined in ``xtensor/xjson.hpp``
11+
12+
.. doxygenfunction:: xt::to_json(nlohmann::json&, const E&);
13+
:project: xtensor
14+
15+
.. doxygenfunction:: xt::from_json(nlohmann::json&, const E&);
16+
:project: xtensor

docs/source/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
Changelog
88
=========
99

10+
0.16.0
11+
------
12+
13+
- Support for JSON serialization and deserialization of xtensor expressions
14+
`#830 <https://github.com/QuantStack/xtensor/pull/830>`_.
15+
1016
0.15.9
1117
------
1218

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ for details.
7474
api/expression_index
7575
api/container_index
7676
api/function_index
77+
api/io_index
7778
api/xmath
7879

7980
.. toctree::

include/xtensor/xcontainer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ namespace xt
13111311
{
13121312
if (compute_size(shape) != this->size())
13131313
{
1314-
throw std::runtime_error("Cannot reshape with incorrect number of elements.");
1314+
throw std::runtime_error("Cannot reshape with incorrect number of elements. Do you mean to resize?");
13151315
}
13161316
if (layout == layout_type::dynamic || layout == layout_type::any)
13171317
{

include/xtensor/xeval.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ namespace xt
2020
template <class T>
2121
using is_container = std::is_base_of<xcontainer<std::remove_const_t<T>>, T>;
2222
}
23+
2324
/**
2425
* Force evaluation of xexpression.
2526
* @return xarray or xtensor depending on shape type
26-
*
27+
*
2728
* \code{.cpp}
2829
* xarray<double> a = {1,2,3,4};
2930
* auto&& b = xt::eval(a); // b is a reference to a, no copy!

include/xtensor/xexpression.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ namespace xt
113113
template <class E>
114114
using is_xexpression = detail::is_xexpression_impl<E>;
115115

116+
template <class E, class R = void>
117+
using enable_xexpression = typename std::enable_if<is_xexpression<E>::value, R>::type;
118+
116119
template <class E, class R = void>
117120
using disable_xexpression = typename std::enable_if<!is_xexpression<E>::value, R>::type;
118121

0 commit comments

Comments
 (0)