Skip to content

import_data not treating 2-way array data as having 'F' ordering #455

@dmdunla

Description

@dmdunla

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.0

I 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:

  1. Implement import_factor in import_data; OR
  2. Change the line above to fac = np.asfortranarray(np.reshape(fac, np.array(fac_shape))); OR
  3. Change the format of ktensor factor matrices to follow the flattened array format for "tensor" and "matrix" file types used by export_data and import_data. This would be a break from the TTB for MATLAB format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions