def test_cptensor_inner(): X1a = np.random.random([4, 3]) X2a = np.random.random([5, 3]) X1b = np.random.random([4, 2]) X2b = np.random.random([5, 2]) cpta = CPTensor([X1a, X2a], TensorBasis([CanonicalBasis(4), CanonicalBasis(5)])) cptb = CPTensor([X1b, X2b], TensorBasis([CanonicalBasis(4), CanonicalBasis(5)])) assert_equal(inner(cpta, cptb), inner(cpta.flatten(), cptb.flatten()))
def test_cptensor_mul(): X1 = np.random.random([4, 3]) X2 = np.random.random([5, 3]) s1 = 2.3 s2 = 3.7 cpt = CPTensor([X1, X2], TensorBasis([CanonicalBasis(4), CanonicalBasis(5)])) cptm = CPTensor([s1 * X1, s2 * X2], TensorBasis([CanonicalBasis(4), CanonicalBasis(5)])) assert_array_almost_equal(((s1 * s2) * cpt).flatten().as_array(), cptm.flatten().as_array())
def test_cptensor_as_array(): X1 = np.random.random([4, 3]) X2 = np.random.random([5, 3]) cpt = CPTensor([X1, X2], TensorBasis([CanonicalBasis(4), CanonicalBasis(5)])) assert_equal(cpt.flatten().as_array(), np.dot(X1, X2.T))