leimao / xtensor-Numpy-Examples

Processing Numpy Arrays In C++ Using xtensor

Home Page:https://leimao.github.io/blog/CPP-Npy-Load-Save-xtensor/

Repository from Github https://github.comleimao/xtensor-Numpy-ExamplesRepository from Github https://github.comleimao/xtensor-Numpy-Examples

xtensor Numpy Examples

Introduction

In some use cases, we would like to load and save Numpy files in C++ applications. This repository provides examples to load and save Numpy files using the xtensor library.

Usages

Build Docker Image

To build the Docker image, please run the following command.

$ docker build -f docker/xtensor.Dockerfile --tag xtensor:24.04 .

Run Docker Container

To run the Docker container, please run the following command.

$ docker run -it --rm -v $(pwd):/mnt -w /mnt xtensor:24.04

Build and Run Examples

To build the examples, please run the following commands.

$ cmake -B build
$ cmake --build build --config Release --parallel

To run the examples, please run the following commands.

$ mkdir -p data

# Save npy file from Python
$ python python/save_npy.py --npy_file_path data/npy_data_from_python.npy
# Verify npy file from Python
$ python python/load_npy.py --npy_file_path data/npy_data_from_python.npy
# Verify npy file from C++
$ ./build/src/load_npy data/npy_data_from_python.npy

# Save npy file from C++
$ ./build/src/save_npy data/npy_data_from_cpp.npy
# Verify npy file from Python
$ python python/load_npy.py --npy_file_path data/npy_data_from_cpp.npy
# Verify npy file from C++
$ ./build/src/load_npy data/npy_data_from_cpp.npy

References

About

Processing Numpy Arrays In C++ Using xtensor

https://leimao.github.io/blog/CPP-Npy-Load-Save-xtensor/

License:MIT License


Languages

Language:C++ 34.3%Language:Dockerfile 33.5%Language:Python 22.5%Language:CMake 9.7%