Skip to content

Commit

Permalink
Add more precompiled types
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Apr 28, 2021
1 parent 8bbf3ef commit 9a20a88
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
*.exe
*.out
*.app

# Generated header
include/xtensor-zarr/xtensor_zarr_config_cling.hpp
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ find_dependency(xtl REQUIRED)
# =====

set(XTENSOR_ZARR_HEADERS
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor_zarr_config.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_hierarchy.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_node.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_group.hpp
Expand All @@ -97,6 +96,8 @@ set(XTENSOR_ZARR_HEADERS
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_common.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_compressor.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_chunked_array.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor_zarr_config.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor_zarr_config_cling.hpp
)

add_library(xtensor-zarr-gdal SHARED
Expand Down Expand Up @@ -209,7 +210,12 @@ endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

set(XTENSOR_ZARR_GDAL_INSTALL_LIBRARY_DIR "\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\"")
set(XTENSOR_ZARR_INSTALL_LIBRARY_DIR "\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\"")

configure_file (
"${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor_zarr_config_cling.hpp.in"
"${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor_zarr_config_cling.hpp"
)

install(TARGETS xtensor-zarr-gdal
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
4 changes: 1 addition & 3 deletions binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ dependencies:
- jupyterlab_widgets=1.0.0
- ffmpeg=4.3.1 # openimageio is being added as a runtime requirement to xtensor-io
- widgetsnbextension
- xtensor=0.23.7
- xtensor-io=0.12.6
- zarray=0.0.6
- xtensor-zarr=0.0.5
- cppcolormap=1.3.0
- bash_kernel
- nlohmann_json
Expand Down
113 changes: 113 additions & 0 deletions examples/xtensor-zarr-gdal.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "61829be3-6fab-4500-8d88-7c61ad7b8747",
"metadata": {},
"outputs": [],
"source": [
"#include \"xtensor/xio.hpp\"\n",
"#include \"xtensor-io/xio_blosc.hpp\"\n",
"#include \"xtensor-zarr/xzarr_hierarchy.hpp\"\n",
"#include \"xtensor-zarr/xzarr_compressor.hpp\"\n",
"#include \"xtensor-zarr/xzarr_gdal_store.hpp\"\n",
"#include \"xtensor-zarr/xtensor_zarr_config_cling.hpp\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e2aac83c-691b-4bfb-a345-ac72708168fe",
"metadata": {},
"outputs": [],
"source": [
"xt::xzarr_register_compressor<xt::xzarr_gdal_store, xt::xio_blosc_config>();\n",
"std::vector<size_t> shape = {4, 4};\n",
"std::vector<size_t> chunk_shape = {2, 2};\n",
"nlohmann::json attrs = {{\"question\", \"life\"}, {\"answer\", 42}};\n",
"std::size_t pool_size = 1;\n",
"double fill_value = 6.6;\n",
"std::string zarr_version = \"3\";\n",
"xt::xzarr_gdal_store store(\"/vsimem/test.zr\" + zarr_version);\n",
"auto h1 = xt::create_zarr_hierarchy(store, zarr_version);\n",
"xt::xzarr_create_array_options<xt::xio_blosc_config> o;\n",
"o.chunk_memory_layout = 'C';\n",
"o.chunk_separator = '/';\n",
"o.attrs = attrs;\n",
"o.chunk_pool_size = pool_size;\n",
"o.fill_value = fill_value;\n",
"auto z1 = h1.create_array(\"/arthur/dent\", shape, chunk_shape, \"<f8\", o);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cffbab84-ec62-4641-a644-ee85f545a345",
"metadata": {},
"outputs": [],
"source": [
"xt::xarray<double> a1 = xt::arange(0, 16).reshape({4, 4});"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4fc286dd-3809-4c19-88ef-62541fbedb8b",
"metadata": {},
"outputs": [],
"source": [
"noalias(z1) = a1;"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63f4c900-6b55-4f6e-884e-8e0aa57e6145",
"metadata": {},
"outputs": [],
"source": [
"auto a2 = z1.get_array<double>();\n",
"a2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9386a0ed-4a3d-4626-856d-e60f3d5c32ad",
"metadata": {},
"outputs": [],
"source": [
"auto h2 = xt::get_zarr_hierarchy(store);\n",
"auto z2 = h2.get_array(\"/arthur/dent\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "935f7a10-6fab-4ac3-bd3a-15e0b28a3c08",
"metadata": {},
"outputs": [],
"source": [
"auto a3 = z2.get_array<double>();\n",
"a3"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "C++14",
"language": "C++14",
"name": "xcpp14"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
18 changes: 18 additions & 0 deletions include/xtensor-zarr/xtensor_zarr_config_cling.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/***************************************************************************
* Copyright (c) 2017, Sylvain Corlay and Johan Mabille *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XTENSOR_ZARR_CONFIG_CLING_HPP
#define XTENSOR_ZARR_CONFIG_CLING_HPP

#pragma cling add_include_path("@XTENSOR_ZARR_INCLUDE_DIR@")
#pragma cling add_library_path(@XTENSOR_ZARR_INSTALL_LIBRARY_DIR@)
#pragma cling load("libxtensor-zarr-gdal")
#pragma cling load("libgdal")
#pragma cling load("libblosc")

#endif
13 changes: 12 additions & 1 deletion include/xtensor-zarr/xzarr_hierarchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "xzarr_file_system_store.hpp"
#include "xzarr_gdal_store.hpp"
#include "xtensor_zarr_config.hpp"
#include "xtensor-io/xio_gzip.hpp"
#include "xtensor-io/xio_zlib.hpp"
#include "xtensor-io/xio_blosc.hpp"

namespace xt
{
Expand Down Expand Up @@ -224,7 +227,15 @@ namespace xt
* precompiled types *
*********************/

extern template class xzarr_hierarchy<xzarr_gdal_store>;
extern template void xzarr_register_compressor<xzarr_gdal_store, xio_gzip_config>();
extern template void xzarr_register_compressor<xzarr_gdal_store, xio_zlib_config>();
extern template void xzarr_register_compressor<xzarr_gdal_store, xio_blosc_config>();
extern template class xchunked_array_factory<xzarr_gdal_store>;

extern template void xzarr_register_compressor<xzarr_file_system_store, xio_gzip_config>();
extern template void xzarr_register_compressor<xzarr_file_system_store, xio_zlib_config>();
extern template void xzarr_register_compressor<xzarr_file_system_store, xio_blosc_config>();
extern template class xchunked_array_factory<xzarr_file_system_store>;
}

#endif
10 changes: 9 additions & 1 deletion src/xtensor-zarr-gdal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@

namespace xt
{
template class XTENSOR_ZARR_API xzarr_hierarchy<xzarr_gdal_store>;
template XTENSOR_ZARR_API void xzarr_register_compressor<xzarr_gdal_store, xio_gzip_config>();
template XTENSOR_ZARR_API void xzarr_register_compressor<xzarr_gdal_store, xio_zlib_config>();
template XTENSOR_ZARR_API void xzarr_register_compressor<xzarr_gdal_store, xio_blosc_config>();
template class XTENSOR_ZARR_API xchunked_array_factory<xzarr_gdal_store>;

template XTENSOR_ZARR_API void xzarr_register_compressor<xzarr_file_system_store, xio_gzip_config>();
template XTENSOR_ZARR_API void xzarr_register_compressor<xzarr_file_system_store, xio_zlib_config>();
template XTENSOR_ZARR_API void xzarr_register_compressor<xzarr_file_system_store, xio_blosc_config>();
template class XTENSOR_ZARR_API xchunked_array_factory<xzarr_file_system_store>;
}

0 comments on commit 9a20a88

Please sign in to comment.