Skip to content

Commit e178b30

Browse files
authored
Merge pull request #188 from DanielVandH/boundserror
Give index information to BoundsError in getindex for splines
2 parents cba0322 + d243564 commit e178b30

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/bases/splines.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ axes(B::Spline{o}) where o =
2828
==(A::Spline{o}, B::Spline{o}) where o = A.points == B.points
2929

3030
function getindex(B::LinearSpline{T}, x::Number, k::Int) where T
31-
x axes(B,1) && 1 k  size(B,2)|| throw(BoundsError())
31+
@boundscheck (x axes(B,1) && 1 k  size(B,2)) || throw(BoundsError(B, (x, k)))
3232

3333
p = B.points
3434
n = length(p)
@@ -41,7 +41,7 @@ function getindex(B::LinearSpline{T}, x::Number, k::Int) where T
4141
end
4242

4343
function getindex(B::HeavisideSpline{T}, x::Number, k::Int) where T
44-
x axes(B,1) && 1 k  size(B,2)|| throw(BoundsError())
44+
@boundscheck (x axes(B,1) && 1 k  size(B,2)) || throw(BoundsError(B, (x, k)))
4545

4646
p = B.points
4747
p[k] < x < p[k+1] && return one(T)
@@ -51,7 +51,7 @@ function getindex(B::HeavisideSpline{T}, x::Number, k::Int) where T
5151
end
5252

5353
function getindex(B::Spline{-1,T}, x::Number, k::Int) where T
54-
x axes(B,1) && 1 k size(B,2)|| throw(BoundsError())
54+
@boundscheck (x axes(B,1) && 1 k size(B,2)) || throw(BoundsError(B, (x, k)))
5555

5656
p = B.points
5757
p[k+1] == x && return convert(T,Inf)

test/test_splines.jl

+14-14
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import ContinuumArrays: basis, AdjointBasisLayout, ExpansionLayout, BasisLayout,
1010
@test axes(H) (axes(H,1),axes(H,2)) (Inclusion(1..3), Base.OneTo(2))
1111
@test size(H) (size(H,1),size(H,2)) (ℵ₁, 2)
1212

13-
@test_throws BoundsError H[0.1, 1]
13+
@test_throws BoundsError(H, (0.1, 1)) H[0.1, 1]
1414
@test H[1.1,1] H'[1,1.1] transpose(H)[1,1.1] 1.0
1515
@test H[2.1,1] H'[1,2.1] transpose(H)[1,2.1] 0.0
1616
@test H[1.1,2] 0.0
1717
@test H[2.1,2] 1.0
18-
@test_throws BoundsError H[2.1,3]
19-
@test_throws BoundsError H'[3,2.1]
20-
@test_throws BoundsError transpose(H)[3,2.1]
21-
@test_throws BoundsError H[3.1,2]
18+
@test_throws BoundsError(H, (2.1, 3)) H[2.1,3]
19+
@test_throws BoundsError(H, (2.1, 3)) H'[3,2.1]
20+
@test_throws BoundsError(H, (2.1, 3)) transpose(H)[3,2.1]
21+
@test_throws BoundsError(H, (3.1, 2)) H[3.1,2]
2222

2323
@test all(H[[1.1,2.1], 1] .=== H'[1,[1.1,2.1]] .=== transpose(H)[1,[1.1,2.1]] .=== [1.0,0.0])
2424
@test all(H[1.1,1:2] .=== H[1.1,:] .=== [1.0,0.0])
2525
@test all(H[[1.1,2.1], 1:2] .=== [1.0 0.0; 0.0 1.0])
2626

27-
@test_throws BoundsError H[[0.1,2.1], 1]
27+
@test_throws BoundsError(H, ([0.1, 2.1], 1)) H[[0.1,2.1], 1]
2828
@test MemoryLayout(typeof(H)) == BasisLayout()
2929
@test ApplyStyle(*, typeof(H), typeof([1,2])) isa MulStyle
3030

@@ -52,19 +52,19 @@ import ContinuumArrays: basis, AdjointBasisLayout, ExpansionLayout, BasisLayout,
5252
L = LinearSpline([1,2,3])
5353
@test size(L) == (ℵ₁, 3)
5454

55-
@test_throws BoundsError L[0.1, 1]
55+
@test_throws BoundsError(L, (0.1, 1)) L[0.1, 1]
5656
@test L[1.1,1] == L'[1,1.1] == transpose(L)[1,1.1] 0.9
5757
@test L[2.1,1] === L'[1,2.1] === transpose(L)[1,2.1] === 0.0
5858
@test L[1.1,2] 0.1
5959
@test L[2.1,2] 0.9
6060
@test L[2.1,3] == L'[3,2.1] == transpose(L)[3,2.1] 0.1
61-
@test_throws BoundsError L[3.1,2]
61+
@test_throws BoundsError(L, (3.1, 2)) L[3.1,2]
6262

6363
@test L[[1.1,2.1], 1] == L'[1,[1.1,2.1]] == transpose(L)[1,[1.1,2.1]] [0.9,0.0]
6464
@test L[1.1,1:2] [0.9,0.1]
6565
@test L[[1.1,2.1], 1:2] [0.9 0.1; 0.0 0.9]
6666

67-
@test_throws BoundsError L[[0.1,2.1], 1]
67+
@test_throws BoundsError(L, ([0.1, 2.1], 1)) L[[0.1,2.1], 1]
6868
end
6969

7070
@testset "Expansion" begin
@@ -254,7 +254,7 @@ import ContinuumArrays: basis, AdjointBasisLayout, ExpansionLayout, BasisLayout,
254254
@test B1 isa SubQuasiArray{Float64,1}
255255
@test size(B1) == (ℵ₁,)
256256
@test B1[0.1] == L[0.1,1]
257-
@test_throws BoundsError B1[2.2]
257+
@test_throws BoundsError(B1, (2.2,)) B1[2.2]
258258

259259
B = view(L,:,1:2)
260260
@test B isa SubQuasiArray{Float64,2}
@@ -267,8 +267,8 @@ import ContinuumArrays: basis, AdjointBasisLayout, ExpansionLayout, BasisLayout,
267267
@test L[:,2:3] isa SubQuasiArray
268268
@test axes(L[:,2:3]) (Inclusion(1..4), Base.OneTo(2))
269269
@test L[:,2:3][1.1,1] == L[1.1,2]
270-
@test_throws BoundsError L[0.1,1]
271-
@test_throws BoundsError L[1.1,0]
270+
@test_throws BoundsError(L, (0.1, 1)) L[0.1,1]
271+
@test_throws BoundsError(L, (1.1, 0)) L[1.1,0]
272272

273273
@test MemoryLayout(typeof(L[:,2:3])) isa SubBasisLayout
274274
@test L\L[:,2:3] isa BandedMatrix
@@ -600,8 +600,8 @@ import ContinuumArrays: basis, AdjointBasisLayout, ExpansionLayout, BasisLayout,
600600
@test isinf(S[1,1])
601601
@test iszero(S[1,2])
602602
@test iszero(S[0,:])
603-
@test_throws BoundsError S[0.1,0]
604-
@test_throws BoundsError S[-1,1]
603+
@test_throws BoundsError(S, (0.1, 0)) S[0.1,0]
604+
@test_throws BoundsError(S, (-1, 1)) S[-1,1]
605605

606606
@test S \ diff(H) == diagm(0 => fill(-1,4), 1 => fill(1, 4))[1:end-1,:]
607607

0 commit comments

Comments
 (0)