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

Add JSON initialization methods #17

Closed
watzon opened this issue Mar 19, 2020 · 2 comments
Closed

Add JSON initialization methods #17

watzon opened this issue Mar 19, 2020 · 2 comments

Comments

@watzon
Copy link

watzon commented Mar 19, 2020

It would be great to have the ability to convert a Tensor to JSON and vice versa. I know I can go the Tensor -> Array -> JSON route, but it should be pretty simple to add.

@christopherzimmerman
Copy link
Member

There isn't even a good way to convert a Tensor to Array right now. I need to work on some serializers, I'll probably get around to this when I actually implement reading/writing from files.

@christopherzimmerman
Copy link
Member

Closed by #23

I handle the one dimensional case only, but you can pass a shape, so to store N-dimensional just store the shape separately.

json_str = "[1, 2, 3]"

puts Tensor(Int32).from_json(json_str, [3])
# [1, 2, 3]

puts Tensor.random(0...10, [3]).to_json
# [7,6,2]

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