Skip to content

Latest commit

 

History

History
45 lines (38 loc) · 1.07 KB

README.md

File metadata and controls

45 lines (38 loc) · 1.07 KB

TNPY

tnpy is a C++17 library for reading and writing numpy .npy files.

Compilation

Prerequisites

The library requires C++17 compiler and cmake 3.21+.

host$ docker run -it --rm -v $PWD:/mnt ubuntu:22.04
docker# apt update && apt install cmake g++

Compile tnpy

docker# mkdir /tmp/build && cd /tmp/build && cmake /mnt && make -j4

Usage

#include "npy.hpp"

#include <fstream>

int main() {
  {
    // read
    std::ifstream File("input.npy");
    tnpy::Npy InNpy(File);
    std::vector<uint32_t> const Shape = InNpy.shape();
    tnpy::Npy::DataOrder const Order  = InNpy.order();
    tnpy::Npy::dtype_t const DType    = InNpy.dtype();
  }

  {
    // write
    std::vector<uint32_t> const Shape{2, 1};
    std::vector<float> const    Data{1., 1.};
    tnpy::Npy OutNpy(Shape, Data);
    std::ofstream("output.npy") << OutNpy;
  }
}

Known issues

  • Only subset of python data types is supported
  • big endian is not supported