oseledets / ttpy

Python implementation of the TT-Toolbox
MIT License
240 stars 67 forks source link

Read vector #29

Open rborrelli opened 7 years ago

rborrelli commented 7 years ago

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 commented 6 years ago

@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 commented 4 years ago

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