Skip to content

simoncblyth/np

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal NumPy array from C++

I searched and they were all excessively complicated for my taste, so I rolled my own:

Documentation of the NPY serialization format

NP.hh(+NPU.hh) provides a lightweight header only NPY writing/reading. Just copy into your project and #include "NP.hh" to use.

Tests of the header

cd tests
./go.sh 

Or do some manual testing:

clang NPTest.cc -std=c++11 -lc++ -o /tmp/NPTest 
gcc NPTest.cc -std=c++11 -lstdc++ -o /tmp/NPTest 
   ## build test executable using your compiler, 
   ## implementation is entirely in headers NP.hh and NPU.hh

/tmp/NPTest /tmp/a.npy  
   ## run test executable writing a test NumPy array to the path given

python -c "import numpy as np ; np.save('/tmp/b.npy', np.linspace(0,39,40,dtype=np.float32).reshape(-1,4) ) " 
   ## do the same thing from python using NumPy

ls -l /tmp/a.npy /tmp/b.npy
   ## check the byte sizes are the same 

diff /tmp/a.npy /tmp/b.npy
    ## check for a match 

xxd /tmp/a.npy
xxd /tmp/b.npy
    ## hexdump if there are differences 

python -c "import numpy as np ; print np.load('/tmp/a.npy') " 
   ## load and print the C++ written NumPy array  

python -c "import numpy as np ; print np.load('/tmp/b.npy') " 
   ## load and print the python written NumPy array  

A few references

About

Minimalistic load/save of simply typed(not structured) NumPy arrays from C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published