def test_addcmul_1d(self): t1 = TensorBase(np.array([1, 2, 3])) t2 = TensorBase(np.array([2, 3, 4])) mat = TensorBase(np.array([5])) out = syft.addcmul(t1, t2, mat, value=2) self.assertTrue(np.array_equal(out.data, [9, 17, 29]))
def test_addcmul_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.addcmul(t1, t2, mat, value=2) self.assertTrue(np.array_equal(out.data, [[4, 11], [5, 12]]))
def addcmul(self, tensor2, mat, value=1): """Performs the element-wise multiplication of tensor1 by tensor2, multiply the result by the scalar value and add it to mat.""" return syft.addcmul(self, tensor2, mat, value)