Skip to content

Commit 71e51a0

Browse files
committed
Fix cache colsupport
1 parent f217b55 commit 71e51a0

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/cache.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ function resizedata!(B::CachedArray{T,N,Array{T,N}},nm::Vararg{Integer,N}) where
118118
end
119119

120120

121-
_minimum(a) = isempty(a) ? length(a)+1 : minimum(a)
122-
_maximum(a) = isempty(a) ? 0 : maximum(a)
123-
convexunion(a::AbstractVector, b::AbstractVector) = min(_minimum(a),_minimum(b)):max(_maximum(a),_maximum(b))
121+
function convexunion(a::AbstractVector, b::AbstractVector)
122+
isempty(a) && return b
123+
isempty(b) && return a
124+
min(minimum(a),minimum(b)):max(maximum(a),maximum(b))
125+
end
124126

125-
colsupport(A::CachedMatrix, i) = convexunion(colsupport(A.array, i),colsupport(A.data,i))
127+
colsupport(A::CachedMatrix, i) = i  size(A.data,2) ? convexunion(colsupport(A.array, i),colsupport(A.data,i)) : colsupport(A.array, i)
126128
colsupport(A::CachedVector, i) = convexunion(colsupport(A.array, i),colsupport(A.data,i))
127-
rowsupport(A::CachedMatrix, i) = convexunion(rowsupport(A.array, i),rowsupport(A.data,i))
129+
rowsupport(A::CachedMatrix, i) = i  size(A.data,1) ? convexunion(rowsupport(A.array, i),rowsupport(A.data,i)) : rowsupport(A.array, i)
128130

129131
Base.replace_in_print_matrix(A::CachedMatrix, i::Integer, j::Integer, s::AbstractString) =
130132
i in colsupport(A,j) ? s : Base.replace_with_centered_mark(s)

test/runtests.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ end
165165
@test_throws BoundsError C[3,1]
166166
@test_throws BoundsError C[7]
167167
end
168+
169+
@testset "colsupport past size" begin
170+
C = cache(Zeros(5,5)); C[5,1];
171+
@test colsupport(C,3) == 1:0
172+
end
168173
end
169174

170175
@testset "Diff and Cumsum" begin
@@ -207,8 +212,8 @@ end
207212
Z = Zeros(5)
208213
@test rowsupport(Z,1) === colsupport(Z,1) === 1:0
209214
@test_broken cache(D)
210-
C = cache(Array,D)
211-
@test colsupport(C,2) === 1:2
215+
C = cache(Array,D);
216+
@test colsupport(C,2) === 2:2
212217
@test colsupport(C,1) === 1:1
213218
@test colsupport(cache(Zeros(5,5)),1) == 1:0
214219
C = cache(Zeros(5));
@@ -219,4 +224,7 @@ end
219224
LazyArrays.zero!(C)
220225
@test colsupport(C,1) == 1:3
221226
@test C == zeros(5)
227+
228+
# bug from BandedMartrices.jl
229+
@test LazyArrays.convexunion(7:10,9:8) == LazyArrays.convexunion(9:8,7:10) == 7:10
222230
end

0 commit comments

Comments
 (0)