tensorly icon indicating copy to clipboard operation
tensorly copied to clipboard

Modifying returns for decompositions without breaking compatibility with older version

Open cohenjer opened this issue 3 years ago • 0 comments

Problem description

Right now in tensorly, functions such as parafac return a cp_tensor when no error return is requested, and a tuple cp_tensor, err when error return is requested. While this behavior is not ideal (one must be vary when toogling on and off error returns since the output format change), it works fine currently. However, adding new returns such as time or something provided by a callback function (see #368) is a pain if we need to add new conditions checking which return is required. E.g. what if the user wants to return timings but not error, and then changes his mind ? The output of parafac would be something like cp_tensor, time in the first call but cp_tensor, err in the second call.

Possible solutions

Looking at what other libraries with similar functionalities do (e.g, scipy, scikit-learn), both use object-oriented programming where the outputs of the algorithms are stored as attributes of some class instance (a returns class instance in scipy, and the model class itself in scikit-learn). While we do have classes for decomposition algorithms in tensorly, using these classes to store the output of algorithms would mean a drastic change in the way we handle returns.

Another solution would be to return a tuple cp_tensor, dictionary with the dictionary containing all requested informations (error, time, anything computed by a callback function...).

In fact I think we should support both options, to facilitate a transition to object-oriented programming.

cohenjer avatar Feb 11 '22 09:02 cohenjer