Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would cnpy work with a vector of structs? #74

Open
TheTomer opened this issue May 20, 2021 · 3 comments
Open

Would cnpy work with a vector of structs? #74

TheTomer opened this issue May 20, 2021 · 3 comments

Comments

@TheTomer
Copy link

TheTomer commented May 20, 2021

Hi, I'm not sure how cnpy is supposed to work in the following case:
Let's say I have a vector of structs. The struct is made of an int field and a double field. The is supposed to be translated into a 2D matrix, with each column having a different variable type. How would you use cnpy to save that structure into a npy file?

In Python, with Numpy, it's possible to use a record array, as described in this thread.

@eedalong
Copy link

eedalong commented May 26, 2021

@TheTomer I am afraid cnpy can not work in this case, numpy use pickle to serialize array when your array is not a normal one

@TheTomer
Copy link
Author

Thanks @eedalong .
I ended up going with another approach, I've converted the structs vector into multiple vectors of the same type and saved them as an npz file. My only problem now is that I couldn't manage to save a vector of strings using cnpy.

@eedalong
Copy link

yeah,i guess that is because string'e length is variant, so if we want serialize a vector of strings, we need to serialize it as
[length1][string1][length2][string2][length3][string3]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants