Skip to content

Commit 78c242c

Browse files
authored
refactor checkbounds methods (#227)
1 parent 0c31772 commit 78c242c

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/Operators/SubOperator.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
Vcheckbounds(A::Operator,kr::Colon) = nothing
22

3-
checkbounds(A::Operator,kr) =
4-
(maximum(kr) > length(A) || minimum(kr) < 1) && throw(BoundsError(A,kr))
3+
@inline function checkbounds(A, inds...)
4+
_checkbounds(A, inds...)::Bool || throw(BoundsError(A,inds))
5+
nothing
6+
end
7+
8+
_checkbounds(A::Operator,kr)::Bool =
9+
!(maximum(kr) > length(A) || minimum(kr) < 1)
510

611

7-
checkbounds(A::Operator,kr::Union{Colon,InfRanges},jr::Union{Colon,InfRanges}) = nothing
12+
_checkbounds(A::Operator,kr::Union{Colon,InfRanges},jr::Union{Colon,InfRanges})::Bool = true
813

9-
checkbounds(A::Operator,kr::Union{Colon,InfRanges},jr) =
10-
(maximum(jr) > size(A,2) || minimum(jr) < 1) && throw(BoundsError(A,(kr,jr)))
14+
_checkbounds(A::Operator,kr::Union{Colon,InfRanges},jr)::Bool =
15+
!(maximum(jr) > size(A,2) || minimum(jr) < 1)
1116

12-
checkbounds(A::Operator,kr,jr::Union{Colon,InfRanges}) =
13-
(maximum(kr) > size(A,1) || minimum(kr) < 1 ) && throw(BoundsError(A,(kr,jr)))
17+
_checkbounds(A::Operator,kr,jr::Union{Colon,InfRanges})::Bool =
18+
!(maximum(kr) > size(A,1) || minimum(kr) < 1 )
1419

15-
checkbounds(A::Operator,kr,jr) =
16-
(!isempty(kr) && (maximum(kr) > size(A,1) || minimum(kr) < 1)) ||
17-
(!isempty(jr) && (maximum(jr) > size(A,2) || minimum(jr) < 1)) &&
18-
throw(BoundsError(A,(kr,jr)))
20+
_checkbounds(A::Operator,kr,jr)::Bool =
21+
!(!isempty(kr) && (maximum(kr) > size(A,1) || minimum(kr) < 1)) ||
22+
(!isempty(jr) && (maximum(jr) > size(A,2) || minimum(jr) < 1))
1923

2024

21-
checkbounds(A::Operator,K::Block,J::Block) =
25+
_checkbounds(A::Operator,K::Block,J::Block)::Bool =
2226
1 first(K.n[1]) length(blocklengths(rangespace(A))) &&
2327
1 first(J.n[1]) length(blocklengths(domainspace(A)))
2428

25-
checkbounds(A::Operator,K::BlockRange{1},J::BlockRange{1}) =
29+
_checkbounds(A::Operator,K::BlockRange{1},J::BlockRange{1})::Bool =
2630
isempty(K) || isempty(J) ||
27-
checkbounds(A, Block(maximum(K.indices[1])), Block(maximum(J.indices[1])))
31+
_checkbounds(A, Block(maximum(K.indices[1])), Block(maximum(J.indices[1])))
2832

2933

3034

0 commit comments

Comments
 (0)