Skip to content

Commit fd7fc20

Browse files
authored
Improve cache, support FillArrays v0.7 (#52)
1 parent e063762 commit fd7fc20

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
99
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1010

1111
[compat]
12-
FillArrays = "0.6.3"
12+
FillArrays = "0.6.3,0.7"
1313
MacroTools = "0.4.5,0.5"
1414
StaticArrays = "0.8,0.9,0.10,0.11"
1515
julia = "1"

src/cache.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ end
5454
v
5555
end
5656

57+
_maximum(ax, I) = maximum(I)
58+
_maximum(ax, ::Colon) = maximum(ax)
59+
function getindex(A::CachedArray, I...)
60+
resizedata!(A, _maximum.(axes(A), I)...)
61+
A.data[I...]
62+
end
63+
64+
function getindex(A::CachedArray, I::CartesianIndex)
65+
resizedata!(A, Tuple(I)...)
66+
A.data[I]
67+
end
68+
5769

5870
## Array caching
5971

@@ -81,3 +93,9 @@ function resizedata!(B::CachedArray{T,N,Array{T,N}},nm::Vararg{Integer,N}) where
8193

8294
B
8395
end
96+
97+
colsupport(A::CachedMatrix, i) = colsupport(A.array, i)
98+
rowsupport(A::CachedMatrix, i) = rowsupport(A.array, i)
99+
100+
Base.replace_in_print_matrix(A::CachedMatrix, i::Integer, j::Integer, s::AbstractString) =
101+
i in colsupport(A,j) ? s : Base.replace_with_centered_mark(s)

src/linalg/mul.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ MulLayout(layouts) = ApplyLayout(*, layouts)
174174

175175

176176
_flatten(A::MulArray, B...) = _flatten(A.applied, B...)
177-
flatten(A::MulArray) = ApplyArray(*, flatten(A.applied))
177+
flatten(A::MulArray) = ApplyArray(flatten(A.applied))
178178

179179
*(A::MulMatrix, B::MulMatrix) = ApplyArray(*, A.args..., B.args...)
180180
*(A::MulMatrix, B::MulVector) = ApplyArray(*, A.args..., B.args...)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ end
123123
LazyArrays.resizedata!(C,8,8,8)
124124
@test all(C.data .=== Array(A)[1:8,1:8,1:8])
125125

126+
@test C[1:3,1,:] == A[1:3,1,:]
127+
126128
A = collect(1:5)
127129
C = cache(A)
128130
@test C isa Vector{Int}

0 commit comments

Comments
 (0)