Skip to content

Commit e1f68b1

Browse files
committed
merge master
2 parents ff6ebc4 + c4008ff commit e1f68b1

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

src/SUnitRange.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
# `Start` and `End` should be `Int`
2-
struct SUnitRange{Start, End, L} <: StaticVector{L, Int}
3-
function SUnitRange{Start, End, L}() where {Start, End, L}
4-
check_sunitrange_params(Start, End, L)
5-
new{Start, End, L}()
2+
struct SUnitRange{Start, L} <: StaticVector{L, Int}
3+
function SUnitRange{Start, L}() where {Start, L}
4+
check_sunitrange_params(L)
5+
new{Start, L}()
66
end
77
end
88

9-
@pure function check_sunitrange_params(a::Int, b::Int, c::Int)
10-
if max(0, b - a + 1) != c
11-
throw(DimensionMismatch("Static unit range $a:$b does not have length $c"))
9+
@pure function check_sunitrange_params(L::Int)
10+
if L < 0
11+
error("Static unit range length is negative")
1212
end
1313
end
1414

15-
function check_sunitrange_params(a, b, c)
15+
function check_sunitrange_params(L)
1616
throw(TypeError(:SUnitRange, "type parameters must be `Int`s", Tuple{Int, Int, Int}, Tuple{typeof(a), typeof(b), typeof(c)}))
1717
end
1818

19-
@pure SUnitRange{Start, End}() where {Start, End} = SUnitRange{Start, End, max(0, End - Start + 1)}()
20-
@pure SUnitRange(a::Int, b::Int) = SUnitRange{a, b}()
19+
@pure SUnitRange(a::Int, b::Int) = SUnitRange{a, max(0, b - a + 1)}()
2120

22-
@pure @propagate_inbounds function getindex(x::SUnitRange{Start,End}, i::Int) where {Start, End}
23-
@boundscheck if i < Start || i > End
21+
@pure @propagate_inbounds function getindex(x::SUnitRange{Start, L}, i::Int) where {Start, L}
22+
@boundscheck if i < Start || i >= (Start + L)
2423
throw(BoundsError(x, i))
2524
end
26-
return i
25+
return Start + i - 1
26+
end
27+
28+
# Shorten show for REPL use.
29+
show(io::IO, ::Type{SUnitRange}) = print(io, "SUnitRange")
30+
function show(io::IO, ::MIME"text/plain", ::SUnitRange{Start, L}) where {Start, L}
31+
print(io, "SUnitRange($Start,$(Start + L - 1))")
2732
end

test/SUnitRange.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@testset "SUnitRange" begin
2+
@test length(StaticArrays.SUnitRange(1,3)) === 3
3+
@test length(StaticArrays.SUnitRange(1,-10)) === 0
4+
5+
@test StaticArrays.SUnitRange(2,4)[2] === 3
6+
end

test/fixed_size_arrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ StaticArrays.similar_type{SV <: RGB, T}(::Type{SV}, ::Type{T}, ::Size{(3,)}) = R
3333
(Point{2, Float64}(1, NaN), true),
3434
(Vec{11, Float64}(NaN), true),
3535
(Point{2, Float32}(1, 1), false),
36-
(RGB{Float32}(NaN), true),
36+
(RGB{Float32}(NaN, NaN, NaN), true),
3737
)
38-
@test all(isnan, p) == r
38+
@test any(isnan, p) == r
3939
end
4040
end
4141

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using Base.Test
1010
include("MArray.jl")
1111
include("FieldVector.jl")
1212
include("Scalar.jl")
13+
include("SUnitRange.jl")
1314
include("custom_types.jl")
1415

1516
include("core.jl")
@@ -21,7 +22,7 @@ using Base.Test
2122
include("matrix_multiply.jl")
2223
include("det.jl")
2324
include("inv.jl")
24-
#include("solve.jl") # Strange inference / world-age error
25+
include("solve.jl") # Strange inference / world-age error
2526
include("eigen.jl")
2627
include("deque.jl")
2728
include("fixed_size_arrays.jl")

test/solve.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
@testset "Solving linear system" begin
22

3-
@testset "Problem size: $n x $n. Matrix type: $m. Element type: $elty" for n in (1,2,3,4),
3+
# I see an inference error in the combined testset below. I can't reproduce
4+
# at the REPL or in a function for individual n, etc... speculatively, it
5+
# might be reusing A, b with different types in the same (non-toplevel)
6+
# scope, for which I've come accross inference bugs in the past.
7+
8+
for n in (1,2,3,4),
9+
(m, v) in ((SMatrix{n,n}, SVector{n}), (MMatrix{n,n}, MVector{n})),
10+
elty in (Float64, Int)
11+
12+
eval(quote
13+
A = $elty.(rand(-99:2:99,$n,$n))
14+
b = A*ones($elty,$n)
15+
@test $m(A)\$v(b) A\b
16+
end)
17+
end
18+
19+
#=@testset "Problem size: $n x $n. Matrix type: $m. Element type: $elty" for n in (1,2,3,4),
420
(m, v) in ((SMatrix{n,n}, SVector{n}), (MMatrix{n,n}, MVector{n})),
521
elty in (Float64, Int)
622
723
A = elty.(rand(-99:2:99,n,n))
824
b = A*ones(elty,n)
925
@test m(A)\v(b) ≈ A\b
10-
end
26+
end =#
1127
end

0 commit comments

Comments
 (0)