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

Read vector #29

Open
rborrelli opened this issue Dec 2, 2016 · 2 comments
Open

Read vector #29

rborrelli opened this issue Dec 2, 2016 · 2 comments

Comments

@rborrelli
Copy link

rborrelli commented Dec 2, 2016

Hi, it seems that the python interface for reading a vector/matrix in TT format from a file is missing but all the fortran subroutines are implemented. The write() interface is fine. Is it possible to read a vector written with the write() method?

Raffaele

@daskol
Copy link
Collaborator

daskol commented Dec 17, 2017

@rborrelli There is not any interface for serialization tt.tensor to and deserialization from file. The presence of fortran subroutines do not motivate serialization interface since fortran code compiled directly to shared object(or dynamic linked library on Windows) which is imported later. All this stuff allow invoke fortran subroutines from python code directly. Here is details how it works.

In despite that there is not built-in ability to (de)serialize TT-formated tensor one can use to_list and from_list static methods in following way.

import numpy as np
import tt

A = tt.tensor(...)  # tensor object
np.savez('tensor.npz', *B.to_list())  # store into tensor.npz
B = tt.tensor.from_list(np.load('tensor.npz').items())  # load from tensor.npz

@rborrelli
Copy link
Author

Hi, sorry, for waking up this pretty old message but the solution you suggested seems to have some problem.
The deserialization indeed gives me the following error:

File "/home/lello/anaconda3/lib/python3.7/site-packages/tt/core/vector.py", line 96, in from_list
cr = _np.concatenate((cr, a[i].flatten(order)))
TypeError: 'ItemsView' object is not subscriptable

Raffaele

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