def test_entry(): B = MatrixSlice(X, (a, b), (c, d)) assert B[0, 0] == X[a, c] assert B[k, l] == X[a + k, c + l] pytest.raises(IndexError, lambda: MatrixSlice(X, 1, (2, 5))[1, 0]) assert X[1::2, :][1, 3] == X[1 + 2, 3] assert X[:, 1::2][3, 1] == X[3, 1 + 2]
def test_slicing(): assert X[1:5, 2:4] == MatrixSlice(X, (1, 5), (2, 4)) assert X[1, 2:4] == MatrixSlice(X, 1, (2, 4)) assert X[1:5, :].shape == (4, X.shape[1]) assert X[:, 1:5].shape == (X.shape[0], 4) assert X[::2, ::2].shape == (floor(n / 2), floor(m / 2)) assert X[2, :] == MatrixSlice(X, 2, (0, m)) assert X[k, :] == MatrixSlice(X, k, (0, m))
def test_indexing(): A = MatrixSymbol('A', n, m) A[1, 2] A[l, k] A[l + 1, k + 1] assert A[:] == MatrixSlice(A, (0, n, 1), (0, m, 1))
def test_indexing(): A = MatrixSymbol('A', n, m) assert isinstance(A[1, 2], MatrixElement) assert isinstance(A[l, k], MatrixElement) assert isinstance(A[l+1, k+1], MatrixElement) assert A[:] == MatrixSlice(A, (0, n, 1), (0, m, 1))
def test_inputs(): assert MatrixSlice(X, 1, (2, 5)) == MatrixSlice(X, (1, 2), (2, 5)) assert MatrixSlice(X, 1, (2, 5)).shape == (1, 3)
def test_on_diag(): assert not MatrixSlice(X, (a, b), (c, d)).on_diag assert MatrixSlice(X, (a, b), (a, b)).on_diag
def test_shape(): B = MatrixSlice(X, (a, b), (c, d)) assert B.shape == (b - a, d - c)