ttpy icon indicating copy to clipboard operation
ttpy copied to clipboard

Read vector

Open rborrelli opened this issue 9 years ago • 2 comments

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

rborrelli avatar Dec 02 '16 08:12 rborrelli

@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

daskol avatar Dec 17 '17 21:12 daskol

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

rborrelli avatar Aug 09 '20 12:08 rborrelli