def test_structure_tensor_3d_rc_only(): cube = cp.zeros((5, 5, 5)) with pytest.raises(ValueError): structure_tensor(cube, sigma=0.1, order="xy") A_elems_rc = structure_tensor(cube, sigma=0.1, order="rc") A_elems_none = structure_tensor(cube, sigma=0.1) for a_rc, a_none in zip(A_elems_rc, A_elems_none): assert_array_equal(a_rc, a_none)
def test_structure_tensor_orders(): square = cp.zeros((5, 5)) square[2, 2] = 1 with expected_warnings(["the default order of the structure"]): A_elems_default = structure_tensor(square, sigma=0.1) A_elems_xy = structure_tensor(square, sigma=0.1, order="xy") A_elems_rc = structure_tensor(square, sigma=0.1, order="rc") for elem_xy, elem_def in zip(A_elems_xy, A_elems_default): assert_array_equal(elem_xy, elem_def) for elem_xy, elem_rc in zip(A_elems_xy, A_elems_rc[::-1]): assert_array_equal(elem_xy, elem_rc)
def test_structure_tensor_3d(): cube = cp.zeros((5, 5, 5)) cube[2, 2, 2] = 1 A_elems = structure_tensor(cube, sigma=0.1) assert_equal(len(A_elems), 6) assert_array_equal( A_elems[0][:, 1, :], cp.asarray([ [0, 0, 0, 0, 0], [0, 1, 4, 1, 0], [0, 0, 0, 0, 0], [0, 1, 4, 1, 0], [0, 0, 0, 0, 0], ]), ) assert_array_equal( A_elems[0][1], cp.asarray([ [0, 0, 0, 0, 0], [0, 1, 4, 1, 0], [0, 4, 16, 4, 0], [0, 1, 4, 1, 0], [0, 0, 0, 0, 0], ]), ) assert_array_equal( A_elems[3][2], cp.asarray([ [0, 0, 0, 0, 0], [0, 4, 16, 4, 0], [0, 0, 0, 0, 0], [0, 4, 16, 4, 0], [0, 0, 0, 0, 0], ]), )
def test_structure_tensor(): square = cp.zeros((5, 5)) square[2, 2] = 1 Arr, Arc, Acc = structure_tensor(square, sigma=0.1, order="rc") assert_array_equal( Acc, cp.asarray([ [0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 4, 0, 4, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], ]), ) assert_array_equal( Arc, cp.asarray([ [0, 0, 0, 0, 0], # noqa [0, 1, 0, -1, 0], # noqa [0, 0, 0, -0, 0], # noqa [0, -1, -0, 1, 0], # noqa [0, 0, 0, 0, 0], # noqa ]), ) assert_array_equal( Arr, cp.asarray([ [0, 0, 0, 0, 0], [0, 1, 4, 1, 0], [0, 0, 0, 0, 0], [0, 1, 4, 1, 0], [0, 0, 0, 0, 0], ]), )
def test_structure_tensor_eigvals(): square = cp.zeros((5, 5)) square[2, 2] = 1 Arr, Arc, Acc = structure_tensor(square, sigma=0.1) with expected_warnings(["deprecation warning: "]): l1, l2 = structure_tensor_eigvals(Arr, Arc, Acc) assert_array_equal( l1, cp.asarray([ [0, 0, 0, 0, 0], [0, 2, 4, 2, 0], [0, 4, 0, 4, 0], [0, 2, 4, 2, 0], [0, 0, 0, 0, 0], ]), ) assert_array_equal( l2, cp.asarray([ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ]), )
def test_structure_tensor_eigenvalues(): square = cp.zeros((5, 5)) square[2, 2] = 1 A_elems = structure_tensor(square, sigma=0.1, order="rc") l1, l2 = structure_tensor_eigenvalues(A_elems) assert_array_equal( l1, np.array([ [0, 0, 0, 0, 0], [0, 2, 4, 2, 0], [0, 4, 0, 4, 0], [0, 2, 4, 2, 0], [0, 0, 0, 0, 0], ]), ) assert_array_equal( l2, np.array([ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ]), )
def test_structure_tensor(): square = cp.zeros((5, 5)) square[2, 2] = 1 Axx, Axy, Ayy = structure_tensor(square, sigma=0.1) assert_array_equal( Axx, cp.asarray([ [0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 4, 0, 4, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0], ]), ) assert_array_equal( Axy, cp.asarray([ [0, 0, 0, 0, 0], # noqa [0, 1, 0, -1, 0], # noqa [0, 0, 0, -0, 0], # noqa [0, -1, -0, 1, 0], # noqa [0, 0, 0, 0, 0], # noqa ]), ) assert_array_equal( Ayy, cp.asarray([ [0, 0, 0, 0, 0], [0, 1, 4, 1, 0], [0, 0, 0, 0, 0], [0, 1, 4, 1, 0], [0, 0, 0, 0, 0], ]), )
def test_structure_tensor_eigvals(): square = cp.zeros((5, 5)) square[2, 2] = 1 Axx, Axy, Ayy = structure_tensor(square, sigma=0.1) l1, l2 = structure_tensor_eigvals(Axx, Axy, Ayy) assert_array_equal( l1, cp.asarray([ [0, 0, 0, 0, 0], [0, 2, 4, 2, 0], [0, 4, 0, 4, 0], [0, 2, 4, 2, 0], [0, 0, 0, 0, 0], ]), ) assert_array_equal( l2, cp.asarray([ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ]), )