https://github.com/tensorly/tensorly
Raw File
Tip revision: 75556ceca6d1a4af862e88d9a98923dc787742b0 authored by Aaron Meyer on 17 January 2023, 18:44:42 UTC
Moderately speeds up and adds testing for CP, PARAFAC2, and Tucker (#478)
Tip revision: 75556ce
_factorized_tensor.py
from . import backend as T
from . import tenalg
from collections.abc import Mapping
from abc import ABCMeta


class FactorizedTensor(Mapping, metaclass=ABCMeta):
    """Base Class for Tensors in Factorized form"""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def to_tensor(self):
        return NotImplementedError

    def to_unfolded(self, mode):
        return NotImplementedError

    def to_vec(self):
        return NotImplementedError

    def norm(self):
        """Norm l2 of the tensor"""
        return T.norm(self.to_tensor())

    def mode_dot(self, matrix_or_tensor, mode):
        return tenalg.mode_dot(self.to_tensor(), matrix_or_tensor, mode)
back to top