Skip to content

Commit 6d044d1

Browse files
authored
disallow infinite operators in Zeros matrix constructors (#406)
1 parent 8dbc982 commit 6d044d1

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/ApproxFunBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import BandedMatrices: bandrange, inbands_setindex!, bandwidth,
7272
colstart, colstop, colrange, rowstart, rowstop, rowrange,
7373
bandwidths, _BandedMatrix, BandedMatrix, isbanded
7474

75-
import BlockArrays: blocksize, block, blockaxes, blockindex
75+
import BlockArrays: blocksize, block, blockaxes, blockindex, blocklengths
7676
import BlockBandedMatrices: blockbandwidth, blockbandwidths, blockcolstop,
7777
blockcolrange, blockcolstart, blockrowstop, blockrowstart,
7878
subblockbandwidth, subblockbandwidths, _BlockBandedMatrix,

src/Operators/Operator.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -733,20 +733,32 @@ copyto!(dest::AbstractMatrix, src::Operator) = copyto!(dest, AbstractMatrix(src)
733733

734734
# this is for operators that implement copy via axpy!
735735

736-
BandedMatrix(::Type{Zeros}, V::Operator) = BandedMatrix(Zeros{eltype(V)}(size(V)), bandwidths(V))
737-
Matrix(::Type{Zeros}, V::Operator) = Matrix(Zeros{eltype(V)}(size(V)))
738-
BandedBlockBandedMatrix(::Type{Zeros}, V::Operator) =
736+
function BandedMatrix(::Type{Zeros}, V::Operator)
737+
all(isfinite, size(V)) || throw(ArgumentError("operator must be finite"))
738+
BandedMatrix(Zeros{eltype(V)}(size(V)), bandwidths(V))
739+
end
740+
function Matrix(::Type{Zeros}, V::Operator)
741+
all(isfinite, size(V)) || throw(ArgumentError("operator must be finite"))
742+
Matrix(Zeros{eltype(V)}(size(V)))
743+
end
744+
function BandedBlockBandedMatrix(::Type{Zeros}, V::Operator)
745+
all(isfinite, size(V)) || throw(ArgumentError("operator must be finite"))
739746
BandedBlockBandedMatrix(Zeros{eltype(V)}(size(V)),
740747
blocklengths(rangespace(V)), blocklengths(domainspace(V)),
741748
blockbandwidths(V), subblockbandwidths(V))
742-
BlockBandedMatrix(::Type{Zeros}, V::Operator) =
749+
end
750+
function BlockBandedMatrix(::Type{Zeros}, V::Operator)
751+
all(isfinite, size(V)) || throw(ArgumentError("operator must be finite"))
743752
BlockBandedMatrix(Zeros{eltype(V)}(size(V)),
744753
AbstractVector{Int}(blocklengths(rangespace(V))),
745754
AbstractVector{Int}(blocklengths(domainspace(V))),
746755
blockbandwidths(V))
747-
RaggedMatrix(::Type{Zeros}, V::Operator) =
756+
end
757+
function RaggedMatrix(::Type{Zeros}, V::Operator)
758+
all(isfinite, size(V)) || throw(ArgumentError("operator must be finite"))
748759
RaggedMatrix(Zeros{eltype(V)}(size(V)),
749760
Int[max(0,colstop(V,j)) for j=1:size(V,2)])
761+
end
750762

751763

752764
convert_axpy!(::Type{MT}, S::Operator) where {MT <: AbstractMatrix} =

0 commit comments

Comments
 (0)