Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 1.53 KB

File metadata and controls

51 lines (32 loc) · 1.53 KB

Znpy

znpy provides Npy file reading and writing implementation in Zig.

Why?

In my recent project that involves working with large vector datasets, our old codebase use C++ implementation for reading npy files called cnpy. However, it does not support reading npy files with Fortran order arrays, slicing arrays, and I think the overall implementation is not very secure and robust. And since I decided to use Zig for the new codebase, I needed a Zig library that can read and write npy files efficiently. So I created znpy to fill this gap.

Features

  • Read and write Npy files
  • Create memory-owned arrays
  • Create array views from arrays with Numpy-style slicing
  • Print arrays to stdout in structured array format

Usage

Make sure Zig 0.16 is installed.

Run demos:

zig build demo_<demo_name>

Where <demo_name> is the name of a file in examples/ without the .zig extension (e.g., zig build demo_endian).

Run tests:

zig build test

To generate test npy files, you can use the provided Python script. Make sure to have uv installed.

Build the virtual environment and install dependencies:

uv sync

Run the script to generate npy files:

uv run main.py

Acknowledgements

  1. ndarray
  2. ndarray-npy