-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Currently, the pyttb.import_data method works as intended when reading in ktensors that were saved to file using pyttb.export_data, but a warning is issued stating that the input is not in 'F' order when instatiating a ktensor from the data read in:
>>> import pyttb as ttb
>>> import numpy as np
>>> K = ttb.ktensor(factor_matrices=[np.arange(1,11).astype(float).reshape((5,2),order='F'), np.arange(1,9).astype(float).reshape((4,2),order='F'), np.arange(1,7).astype(float).reshape((3,2),order='F')])
>>> ttb.export_data(K,'Ktemp.tns')
>>> K2 = ttb.import_data('Ktemp.tns')
WARNING:root:Selected no copy, but input factor matrices aren't F ordered so must copy.
>>> (K2-K).norm()
0.0I think we should not have such a warning, as user cannot do anything about it; this is an issue with the internals of export_data/import_data. I believe the problem is here in import_data:
fac = np.reshape(fac, np.array(fac_shape))The data is exported and imported corrected as being in 'F' order, but export_data exports the factor matrices using the internal method export_factor (equivalent to the TTB for MATLAB method) and import_data imports the factor matrices using the internal method import_array, which assumes the data resides in the files as a flattened array (one value per line), yet export_factor formats the factor matrices in the file per row of the matrix (which then leads to memory order specification requirements to work correctly).
Suggested remedies:
- Implement
import_factorinimport_data; OR - Change the line above to
fac = np.asfortranarray(np.reshape(fac, np.array(fac_shape))); OR - Change the format of ktensor factor matrices to follow the flattened array format for "tensor" and "matrix" file types used by
export_dataandimport_data. This would be a break from the TTB for MATLAB format.