Comments (12)
Hi Dirk, thanks. Carl has found an easy way to support compressed npz/npy and should patch cnpy soon.
To be continued.
Kind
from cnpy.
Dirk, you totally get a vote :) universal preference seems in favor of no extra dependencies, so I'll see if I can retool this to work with zlib
from cnpy.
@dirk: I thought libzip would be much easier, but zlib wasn't too bad bc there was already code to manually parse the zip headers/footers. I'd agree fewer/more common deps are more preferable for the reasons you outlined.
I put up some new code up that will load using zlib, no more dependencies on libzip. I tried a few examples with npy_compressed and it seemed ok. inefficient in how it allocates memory but I will fix that later.
from cnpy.
When trying to open a compressed npz/npy (generated by np.savez_compressed()) with cnpy I indeed got an exception:
cnpy.cpp:92: void cnpy::parse_npy_header(FILE*, unsigned int&, unsigned int*&, unsigned int&, bool&): Assertion `littleEndian' failed.
@eddelbuettel: do you mean you have some patch that would allow cnpy to open/read compressed npz/npy files ?
Kind
from cnpy.
Not npz but we handle npy -- as we can just rely on libz to read from a compressed stream. It's all over in the repo I linked to, including some test cases. But it is set up for R users so you may not be able to read everything easily but there is eg tests tests/ directory.
You could call R (ie via Rscript
) to have RcppCNPy read the compressed file and write it uncompressed...
from cnpy.
I pushed some code to read npz files using libzip, which is now a dependency. William do you mind giving it a go and see if it works for you?
Itd be preferable to use either zlib or libzip, not both, I'll have to look into this a little later
from cnpy.
I don't get to vote on what you do with CNPy ... but I have a weak preference for zlib because R already uses it. Else users of RcppCNPy will have to get libzip-dev to build. Which is probably only a minor nuisance as that should be common, but still "zlib is free" in our use case.
from cnpy.
Out of curiousity, is one of the two "easier" or "cheaper" for you? On Linux it doesn't really matter ...
from cnpy.
Hi Carl, thank you.
I ve just tested and it seems to work.
Now, like @eddelbuettel, I would also have a preference for removing the dependency to libzip.
Have you considered using some of these pure zlib solutions as for example "miniz": single self contained header, no library, no dependency:
https://github.com/richgel999/miniz
Cheers
W.
from cnpy.
I just used your code as source of inspiration to read/write NPZ files for xtensor: https://github.com/wolfv/xtensor-io/blob/master/include/xtensor-io/xnpz.hpp
It's got the added ability to compress the ZIP NPY files, and the zip contents modification date is initialized correctly :) With a bit of work it could be adapted for a non-xtensor use case, I guess ...
from cnpy.
@rogersce Hi Carl, I ve just tested and seems to work. Thank you.
In order to track upcoming changes/enhancements, what about adding a version in the sources: for example:
const versionMajor = 0;
const versionMinor = 1;
or creating a 1.0 branch ?
Kind
from cnpy.
@wolfv That's great! Glad it was useful. Writing out compressed NPY zips from C++ would be an awesome feature, when I get a chance I'll take a look at your code in depth and try to add that back into cnpy. Of course, if you think it could be done easily and want to submit a pull request, I wouldn't say no to that, either, haha :)
from cnpy.
Related Issues (20)
- Remove zlib dependency, MSVC compatbilty HOT 3
- No makefile in the "make" step HOT 1
- Undefined symbols for architecture x86_64 HOT 2
- Unable to read large npy
- Cannot read npz file
- cannot create std::vector larger than max_size()
- Would cnpy work with a vector of structs? HOT 3
- Not sure it's a issue or not. How could I parse std::string by using CNPY? HOT 2
- Undefined Symbol Error When Making
- Why is the data type not stored in NpyArray? HOT 1
- Why forcing little endian?
- cnpy does not support large numpy headers
- not support dict?
- Does it support uint32 type saving?
- "undefined symbol: inflate" for cnpy-static
- Feature request: support writing to memory streams
- Undefined reference to `cnpy::npy_load(std::string)' HOT 3
- Error with AddressSanitizer (container-overflow)
- How to save a opencv cv::Mat into .npy file
- npy file size limit HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cnpy.