def addmm(self, tensor2, mat, beta=1, alpha=1): """Performs ((Mat*Beta)+((Tensor1@Tensor2)*Alpha)) and returns the result as a Tensor Tensor1.Tensor2 is performed as Matrix product of two array The behavior depends on the arguments in the following way. *If both tensors are 1-dimensional, their dot product is returned. *If both arguments are 2-D they are multiplied like conventional matrices. *If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly. *If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed. *If the second argument is 1-D, it is promoted to a matrix by appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed. """ return syft.addmm(self, tensor2, mat, beta, alpha)
def test_addmm_2d(self): t1 = TensorBase(np.array([[1, 2], [1, 2]])) t2 = TensorBase(np.array([[1, 2], [1, 2]])) mat = TensorBase(np.array([[2, 3], [3, 4]])) out = syft.addmm(t1, t2, mat, beta=2, alpha=2) self.assertTrue(np.array_equal(out.data, [[10, 18], [12, 20]]))
def test_addmm_1d(self): t1 = TensorBase(np.array([1, 2, 3])) t2 = TensorBase(np.array([2, 3, 4])) mat = TensorBase(np.array([5])) out = syft.addmm(t1, t2, mat, beta=2, alpha=2) self.assertTrue(np.array_equal(out.data, [50]))