def test_sum3(self): # [[m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2]] f_m_a = (Federated(self.sds, [fed1, fed2], [([0, 0], [dim, dim]), ([0, dim], [dim, dim * 2])]).sum().compute()) m1_m2 = m1.sum() + m2.sum() self.assertAlmostEqual(f_m_a, m1_m2)
def test_3(self): # [[m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2]] f_m1_m2 = Federated(self.sds, [fed1, fed2], [([0, 0], [dim, dim]), ([0, dim], [dim, dim * 2])]).compute() m1_m2 = np.concatenate((m1, m2), axis=1) res = np.allclose(f_m1_m2, m1_m2) self.assertTrue(res)
def test_sum3(self): # [[m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2]] f_m1_m2 = (Federated(self.sds, [fed1, fed2], [([0, 0], [dim, dim]), ([0, dim], [dim, dim * 2])]).sum().compute()) m1_m2 = np.concatenate((m1, m2), axis=1).sum() self.assertAlmostEqual(f_m1_m2, m1_m2)
def test_sum8(self): # [[ 0, 0, 0, 0, 0, 0, 0, 0] # [ 0, 0, 0, 0, 0, 0, 0, 0] # [ 0, 0, 0,m1,m1,m1,m1,m1] # [ 0, 0, 0,m1,m1,m1,m1,m1] # [ 0, 0, 0,m1,m1,m1,m1,m1] # [ 0, 0, 0,m1,m1,m1,m1,m1] # [ 0, 0, 0,m1,m1,m1,m1,m1]] f_m_a = (Federated(self.sds, [fed1], [([2, 3], [dim + 2, dim + 3])]).sum().compute()) m = m1.sum() self.assertAlmostEqual(f_m_a, m)
def test_5(self): # [[m1,m1,m1,m1,m1, 0, 0, 0, 0, 0] # [m1,m1,m1,m1,m1, 0, 0, 0, 0, 0] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [m1,m1,m1,m1,m1,m2,m2,m2,m2,m2] # [ 0, 0, 0, 0, 0,m2,m2,m2,m2,m2] # [ 0, 0, 0, 0, 0,m2,m2,m2,m2,m2]] f_m1_m2 = Federated(self.sds, [fed1, fed2], [([0, 0], [dim, dim]), ([2, dim], [dim + 2, dim * 2])]).compute() m1_p = np.concatenate((m1, np.zeros((2, dim)))) m2_p = np.concatenate((np.zeros((2, dim)), m2)) m1_m2 = np.concatenate((m1_p, m2_p), axis=1) res = np.allclose(f_m1_m2, m1_m2) self.assertTrue(res)
def test_8(self): # [[ 0, 0, 0, 0, 0, 0, 0, 0] # [ 0, 0, 0, 0, 0, 0, 0, 0] # [ 0, 0, 0,m1,m1,m1,m1,m1] # [ 0, 0, 0,m1,m1,m1,m1,m1] # [ 0, 0, 0,m1,m1,m1,m1,m1] # [ 0, 0, 0,m1,m1,m1,m1,m1] # [ 0, 0, 0,m1,m1,m1,m1,m1]] f_m1_m2 = Federated(self.sds, [fed1], [([2, 3], [dim + 2, dim + 3])]) f_m1_m2 = (f_m1_m2).compute() m1_m2 = np.zeros((dim + 2, dim + 3)) m1_m2[2:dim + 2, 3:dim + 3] = m1 res = np.allclose(f_m1_m2, m1_m2) if not res: print("Federated:") print(f_m1_m2) print("numpy:") print(m1_m2) self.assertTrue(res)
def test_2(self): f_m2 = Federated(self.sds, [fed2], [([0, 0], [dim, dim])]).compute() res = np.allclose(f_m2, m2) self.assertTrue(res)
def test_1(self): f_m1 = Federated(self.sds, [fed1], [([0, 0], [dim, dim])]).compute() res = np.allclose(f_m1, m1) self.assertTrue(res, "\n" + str(f_m1) + " is not equal to \n" + str(m1))
def test_sum2(self): f_m2 = (Federated(self.sds, [fed2], [([0, 0], [dim, dim])]).sum().compute()) m2_r = m2.sum() self.assertAlmostEqual(f_m2, m2_r)
def test_sum1(self): f_m1 = (Federated(self.sds, [fed1], [([0, 0], [dim, dim])]).sum().compute()) m1_r = m1.sum() self.assertAlmostEqual(f_m1, m1_r)
def test_1(self): f_m1 = Federated(self.sds, [fed1], [([0, 0], [dim, dim])]).compute() res = np.allclose(f_m1, m1) self.assertTrue(res)