def test_indexed_matrix_6(): indices = [2, 3, 5, 7] matrix = IndexedMatrix(indices=indices) matrix.add_indices([6, 10]) # One of the indices does not exist, so this raises an Exception. matrix.remove_indices([5, 6, 9])
def test_indexed_matrix_5(): indices = [2, 3, 5, 7] matrix = IndexedMatrix(indices=indices) matrix.add_indices([6, 10]) assert matrix.shape == (6, 6) assert np.array_equal(matrix.indices, [2, 3, 5, 6, 7, 10]) matrix.remove_indices(7) assert matrix.shape == (5, 5) assert np.array_equal(matrix.indices, [2, 3, 5, 6, 10])
def test_indexed_matrix_8(): indices = [2, 3, 5, 7] matrix = IndexedMatrix(indices=indices, shape=(4, 4, 10)) x = np.random.rand(10) matrix[7, 7] = x assert np.array_equal(matrix[7, 7], x) assert np.array_equal(matrix[7, :][-1, :], x) assert np.array_equal(matrix[[2, 7], 7][-1, :], x) assert np.array_equal(matrix[[2, 5, 3], [2]], np.zeros((3, 1, 10))) assert np.array_equal(matrix[[2, 5, 3], 2], np.zeros((3, 10))) assert np.array_equal(matrix[[2], [2, 5, 3]], np.zeros((1, 3, 10))) assert np.array_equal(matrix[2, [2, 5, 3]], np.zeros((3, 10))) assert np.array_equal(matrix[[5, 7], [3, 2]], np.zeros((2, 2, 10))) matrix.remove_indices(5) assert matrix.to_array().shape == (3, 3, 10) assert np.array_equal(matrix[7, 7], x)