Skip to content

Commit dc110b2

Browse files
authored
replace_in_print_matrix for RaggedMatrix (#351)
1 parent 052f16e commit dc110b2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/LinearAlgebra/RaggedMatrix.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ colstop(A::RaggedMatrix,j::Integer) = min(A.cols[j+1]-A.cols[j],size(A,1))
3939

4040
Base.IndexStyle(::Type{RM}) where {RM<:RaggedMatrix} = IndexCartesian()
4141

42+
@inline function incol(A, k, j, ind = A.cols[j]+k-1)
43+
ind < A.cols[j+1]
44+
end
45+
4246
function getindex(A::RaggedMatrix,k::Int,j::Int)
4347
if k>size(A,1) || k < 1 || j>size(A,2) || j < 1
4448
throw(BoundsError(A,(k,j)))
4549
end
4650

47-
if A.cols[j]+k-1 < A.cols[j+1]
48-
A.data[A.cols[j]+k-1]
51+
ind = A.cols[j]+k-1
52+
if incol(A, k, j, ind)
53+
A.data[ind]
4954
else
5055
zero(eltype(A))
5156
end
@@ -56,8 +61,9 @@ function Base.setindex!(A::RaggedMatrix,v,k::Int,j::Int)
5661
throw(BoundsError(A,(k,j)))
5762
end
5863

59-
if A.cols[j]+k-1 < A.cols[j+1]
60-
A.data[A.cols[j]+k-1]=v
64+
ind = A.cols[j]+k-1
65+
if incol(A, k, j, ind)
66+
A.data[ind]=v
6167
elseif v 0
6268
throw(BoundsError(A,(k,j)))
6369
end
@@ -131,6 +137,9 @@ end
131137

132138
RaggedMatrix(A::AbstractMatrix, colns::AbstractVector{Int}) = RaggedMatrix{eltype(A)}(A, colns)
133139

140+
function Base.replace_in_print_matrix(A::RaggedMatrix,i::Integer,j::Integer,s::AbstractString)
141+
incol(A, i, j) ? s : Base.replace_with_centered_mark(s)
142+
end
134143

135144
## BLAS
136145

0 commit comments

Comments
 (0)