def test_EyeLike2D_bool_3(self): np_a = np.reshape(self.np_bool_a, (6, 8)) dc_a = dc.reshape(self.dc_bool_a, (6, 8)) npr = np.eye(6, 8, k=self.k) dcr = dc.eye_like(dc_a, self.k) np.testing.assert_allclose(npr.flatten(), np.array(dcr.data()).astype(np.bool), rtol=1e-3, atol=1e-3)
def test_EyeLike2D_int_2(self): np_a = np.reshape(self.np_int_a, (2, 24)) dc_a = dc.reshape(self.dc_int_a, (2, 24)) npr = np.eye(2, 24, k=self.k) dcr = dc.eye_like(dc_a, self.k) np.testing.assert_allclose(npr.flatten(), np.array(dcr.data()).astype(np.int), rtol=1e-3, atol=1e-3)
def test_EyeLike2D_double_1(self): np_a = np.reshape(self.np_double_a, (12, 4)) dc_a = dc.reshape(self.dc_double_a, (12, 4)) npr = np.eye(12, 4, k=self.k) dcr = dc.eye_like(dc_a, self.k) np.testing.assert_allclose(npr.flatten(), np.array(dcr.data()).astype(np.float64), rtol=1e-3, atol=1e-3)
def test_Elu2D(self): row = 8 column = 6 dc_a = dc.reshape(self.dc_a, (row, column)) npr = np.eye(row, column, self.k) dcr = dc.eye_like(dc_a, self.k) np.testing.assert_allclose(npr.flatten(), np.array(dcr.data()).astype(np.float32), rtol=1e-3, atol=1e-3)
# unittest.main() k = 2 len = 10 np_a = np.random.randn(len).astype(np.int8) dc_a = dc.array(list(np_a)) # print(np_a) # print(dc_a) row = 2 column = 5 np_b = np.reshape(np_a, (row, column)) dc_b = dc.reshape(dc_a, (row, column)) print(np_b) print(np.array(dc_b.data())) # print(np_a) # print(dc_a) npr = np.eye(row, column, k=k) dcr = dc.eye_like(dc_b, k) print(npr.flatten()) print(np.array(dcr.data())) print(npr) print(dcr)