Skip to content

Commit fa75f5a

Browse files
authored
improve constant-propagation in interlace_bandwidths for Diagonal (#572)
* improve constant-propagation in interlace_bandwidths for Diagonal * Don't precompute size
1 parent e1e8cf9 commit fa75f5a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Operators/general/InterlaceOperator.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,32 @@ function __interlace_bandwidths_square(ops::Diagonal, bw = __interlace_ops_bandw
114114
l,u
115115
end
116116

117+
# this is a hack to get constant-propagation in the indexing operation
118+
_first(A) = A[1]
119+
_second(A) = A[2]
120+
121+
_first(A::Diagonal) = parent(A)[1]
122+
_second(A::Diagonal) = zero(eltype(A))
123+
124+
issquare(A) = size(A,1) == size(A,2)
125+
issquare(A::Diagonal) = true
126+
117127
Base.@constprop :aggressive function interlace_bandwidths(ops::AbstractMatrix{<:Operator},
118128
ds, rs,
119129
allbanded = all(isbanded, ops),
120130
bw = allbanded ? __interlace_ops_bandwidths(ops) : nothing)
121131

122-
p=size(ops,1)
123132
dsi = interlacer(ds)
124133
rsi = interlacer(rs)
125134

126-
if size(ops,2) == p && allbanded && # only support blocksize (1,) for now
135+
if issquare(ops) && allbanded && # only support blocksize (1,) for now
127136
all(i->isa(i,AbstractFill) && getindex_value(i) == 1, dsi.blocks) &&
128137
all(i->isa(i,AbstractFill) && getindex_value(i) == 1, rsi.blocks)
129138

130139
l,u = __interlace_bandwidths_square(ops, bw)
131-
elseif p == 1 && size(ops,2) == 2 && size(ops[1],2) == 1
140+
elseif size(ops,1) == 1 && size(ops,2) == 2 && size(_first(ops),2) == 1
132141
# special case for example
133-
l,u = max(bandwidth(ops[1],1),bandwidth(ops[2],1)-1),bandwidth(ops[2],2)+1
142+
l,u = max(bandwidth(_first(ops),1),bandwidth(_second(ops),1)-1),bandwidth(_second(ops),2)+1
134143
else
135144
l,u = (dimension(rs)-1,dimension(ds)-1) # not banded
136145
end

0 commit comments

Comments
 (0)