Skip to content

Commit 2de6b4c

Browse files
authored
improve type inference in caching (#396)
* improve type inference in caching * fix CachedOperator for blockbanded * Add comments
1 parent be0d5fa commit 2de6b4c

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.8.2"
3+
version = "0.8.3"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Caching/banded.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
function CachedOperator(::Type{BandedMatrix},op::Operator;padding::Bool=false)
2-
l,u=bandwidths(op)
3-
padding && (u+=l)
4-
data = BandedMatrix{eltype(op)}(undef, (0,0), (l,u))
5-
CachedOperator(op,data,size(data),domainspace(op),rangespace(op),(-l,u),padding)
2+
bw = bandwidths(op)
3+
l = first(bw)
4+
# working on the tuples directly instead of the components helps with type-stability
5+
padding && (bw = bw .+ (0,l))
6+
data = BandedMatrix{eltype(op)}(undef, (0,0), bw)
7+
CachedOperator(op,data,size(data),domainspace(op),rangespace(op), bw .* (-1,1),padding)
68
end
79

810

src/Caching/bandedblockbanded.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11

22
function CachedOperator(::Type{BandedBlockBandedMatrix}, op::Operator)
3-
l,u = blockbandwidths(op)
4-
λ,μ = subblockbandwidths(op)
3+
lu = blockbandwidths(op)
4+
λμ = subblockbandwidths(op)
5+
# working on the tuples directly instead of the components helps with type-stability
56
data = BandedBlockBandedMatrix{eltype(op)}(undef,
67
blocklengths(rangespace(op))[1:0],blocklengths(domainspace(op))[1:0],
7-
(l,u), (λ,μ))
8+
lu, λμ)
89

9-
CachedOperator(op,data,size(data),domainspace(op),rangespace(op),(-l,u),false)
10+
CachedOperator(op,data,size(data),domainspace(op),rangespace(op),lu .* (-1,1),false)
1011
end
1112

1213
# Grow cached operator

src/Caching/blockbanded.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ diagblockshift(op::Operator) = diagblockshift(blocklengths(domainspace(op)),bloc
7171

7272

7373
function CachedOperator(::Type{BlockBandedMatrix},op::Operator;padding::Bool=false)
74-
l,u=blockbandwidths(op)
75-
padding && (u+=l+diagblockshift(op))
76-
data=BlockBandedMatrix{eltype(op)}(undef,
77-
Vector{Int}(), Vector{Int}(),
78-
(l,u))
79-
CachedOperator(op,data,(0,0),domainspace(op),rangespace(op),(-l,u),padding)
74+
lu=blockbandwidths(op)
75+
l = first(lu)
76+
if padding # working on the tuple helps with type-stability
77+
lu = lu .+ (0,l+diagblockshift(op))
78+
end
79+
data = BlockBandedMatrix{eltype(op)}(undef, Int[], Int[], lu)
80+
CachedOperator(op,data,(0,0),domainspace(op),rangespace(op),lu .* (-1,1),padding)
8081
end
8182

8283

0 commit comments

Comments
 (0)