https://github.com/tensorly/tensorly
Revision 85427096a1ab6600caa7d98bed93768566bb2a2f authored by Jean Kossaifi on 30 September 2020, 15:50:06 UTC, committed by Jean Kossaifi on 30 September 2020, 15:50:06 UTC
1 parent b405e84
Raw File
Tip revision: 85427096a1ab6600caa7d98bed93768566bb2a2f authored by Jean Kossaifi on 30 September 2020, 15:50:06 UTC
Tucker decomposition: option to provide init + fix core
Tip revision: 8542709
testing.py
import numpy as np

from tensorly import backend as T


def assert_array_equal(a, b, *args, **kwargs):
    np.testing.assert_array_equal(T.to_numpy(a), T.to_numpy(b),
                                  *args, **kwargs)


def assert_array_almost_equal(a, b, *args, **kwargs):
    np.testing.assert_array_almost_equal(T.to_numpy(a), T.to_numpy(b),
                                         *args, **kwargs)


def assert_equal(actual, desired, *args, **kwargs):
    def _tensor_to_numpy(x):
        if T.is_tensor(x):
            x = T.to_numpy(x)
            return x[0] if x.shape == (1,) else x
        return x

    np.testing.assert_equal(_tensor_to_numpy(actual),
                            _tensor_to_numpy(desired),
                            *args, **kwargs)


assert_ = np.testing.assert_
assert_raises = np.testing.assert_raises
back to top