def test_moore_neighbors_sum_random_versus_roll(self): arr = tst_arr() add_global_noise(0.5, tst_dim(), arr) l = cy.roll_columns(1, tst_dim(), arr) r = cy.roll_columns(-1, tst_dim(), arr) u = cy.roll_rows(1, tst_dim(), arr) d = cy.roll_rows(-1, tst_dim(), arr) NB = np.asarray(l) + np.asarray(r) + np.asarray(u) + np.asarray(d) NB2 = moore_neighbors_array(tst_dim(), arr) testing.assert_array_equal(NB, NB2)
def test_neumann_neighbors_sum_CP_random_versus_roll(self): arr = tst_arr() add_global_noise(0.5, tst_dim(), arr) l = cy.roll_columns(1, tst_dim(), arr) r = cy.roll_columns(-1, tst_dim(), arr) u = cy.roll_rows(1, tst_dim(), arr) d = cy.roll_rows(-1, tst_dim(), arr) ul = cy.roll_rows(1, tst_dim(), l) dl = cy.roll_rows(-1, tst_dim(), l) ur = cy.roll_rows(1, tst_dim(), r) dr = cy.roll_rows(-1, tst_dim(), r) NB = np.asarray(l) + np.asarray(r) + np.asarray(u) + np.asarray(d) +\ np.asarray(ul) + np.asarray(ur) + np.asarray(dl) + np.asarray(dr) NB2 = neumann_neighbors_array(tst_dim(), arr) testing.assert_array_equal(NB, NB2)
def test_moore_neighbors_same_random_versus_roll(self): arr = tst_arr() add_global_noise(0.5, tst_dim(), arr) l = cy.roll_columns(1, tst_dim(), arr) r = cy.roll_columns(-1, tst_dim(), arr) u = cy.roll_rows(1, tst_dim(), arr) d = cy.roll_rows(-1, tst_dim(), arr) NB = np.asarray(l) + np.asarray(r) + np.asarray(u) + np.asarray(d) NB2 = np.zeros_like(arr) pos = array.array('i', [0, 0]) for i in range(tst_dim()[0]): for j in range(tst_dim()[1]): pos[0] = i pos[1] = j NB2[i, j] = moore_neighbors_same_CP(pos, tst_dim(), arr) if not arr[i, j]: NB[i, j] = 4 - NB[i, j] testing.assert_array_equal(NB, NB2)
def test_roll_columns_back(self): arrout = cy.roll_columns(-1, tst_dim(), tst_arr()) arrout = cy.roll_columns(-1, tst_dim(), arrout) testing.assert_array_equal(arrout, np.roll(tst_arr(), -2, axis=1))
def test_roll_columns_forward(self): arrout = cy.roll_columns(1, tst_dim(), tst_arr()) arrout = cy.roll_columns(1, tst_dim(), arrout) testing.assert_array_equal(arrout, np.roll(tst_arr(), 2, axis=1))