diff --git a/REQUIRE b/REQUIRE index 800cf92b9..b6cc633cf 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ -julia 0.6- +julia 0.5 +Compat 0.19.0 diff --git a/appveyor.yml b/appveyor.yml index 43045bd6e..b1a56438f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,8 +2,8 @@ environment: matrix: - JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" -# - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe" -# - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe" + - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe" + - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe" branches: only: diff --git a/src/FieldVector.jl b/src/FieldVector.jl index 167bac92d..20c295586 100644 --- a/src/FieldVector.jl +++ b/src/FieldVector.jl @@ -16,7 +16,7 @@ For example: z::Float64 end """ -abstract type FieldVector{T} <: StaticVector{T} end +@compat abstract type FieldVector{T} <: StaticVector{T} end # Is this a good idea?? Should people just define constructors that accept tuples? @inline (::Type{FV}){FV<:FieldVector}(x::Tuple) = FV(x...) diff --git a/src/ImmutableArrays.jl b/src/ImmutableArrays.jl index 402e36306..f34976778 100644 --- a/src/ImmutableArrays.jl +++ b/src/ImmutableArrays.jl @@ -1,31 +1,32 @@ module ImmutableArrays using ..StaticArrays - -Vector1{T} = SVector{1,T} -Vector2{T} = SVector{2,T} -Vector3{T} = SVector{3,T} -Vector4{T} = SVector{4,T} - -Matrix1x1{T} = SMatrix{1,1,T,1} -Matrix1x2{T} = SMatrix{1,2,T,2} -Matrix1x3{T} = SMatrix{1,3,T,3} -Matrix1x4{T} = SMatrix{1,4,T,4} - -Matrix2x1{T} = SMatrix{2,1,T,2} -Matrix2x2{T} = SMatrix{2,2,T,4} -Matrix2x3{T} = SMatrix{2,3,T,6} -Matrix2x4{T} = SMatrix{2,4,T,8} - -Matrix3x1{T} = SMatrix{3,1,T,3} -Matrix3x2{T} = SMatrix{3,2,T,6} -Matrix3x3{T} = SMatrix{3,3,T,9} -Matrix3x4{T} = SMatrix{3,4,T,12} - -Matrix4x1{T} = SMatrix{4,1,T,4} -Matrix4x2{T} = SMatrix{4,2,T,8} -Matrix4x3{T} = SMatrix{4,3,T,12} -Matrix4x4{T} = SMatrix{4,4,T,16} +using Compat + +@compat Vector1{T} = SVector{1,T} +@compat Vector2{T} = SVector{2,T} +@compat Vector3{T} = SVector{3,T} +@compat Vector4{T} = SVector{4,T} + +@compat Matrix1x1{T} = SMatrix{1,1,T,1} +@compat Matrix1x2{T} = SMatrix{1,2,T,2} +@compat Matrix1x3{T} = SMatrix{1,3,T,3} +@compat Matrix1x4{T} = SMatrix{1,4,T,4} + +@compat Matrix2x1{T} = SMatrix{2,1,T,2} +@compat Matrix2x2{T} = SMatrix{2,2,T,4} +@compat Matrix2x3{T} = SMatrix{2,3,T,6} +@compat Matrix2x4{T} = SMatrix{2,4,T,8} + +@compat Matrix3x1{T} = SMatrix{3,1,T,3} +@compat Matrix3x2{T} = SMatrix{3,2,T,6} +@compat Matrix3x3{T} = SMatrix{3,3,T,9} +@compat Matrix3x4{T} = SMatrix{3,4,T,12} + +@compat Matrix4x1{T} = SMatrix{4,1,T,4} +@compat Matrix4x2{T} = SMatrix{4,2,T,8} +@compat Matrix4x3{T} = SMatrix{4,3,T,12} +@compat Matrix4x4{T} = SMatrix{4,4,T,16} export Vector1, Vector2, Vector3, Vector4, Matrix1x1, Matrix1x2, Matrix1x3, Matrix1x4, diff --git a/src/MArray.jl b/src/MArray.jl index edbe0507a..acb4ec753 100644 --- a/src/MArray.jl +++ b/src/MArray.jl @@ -19,19 +19,19 @@ compiler (the element type may optionally also be specified). type MArray{Size, T, N, L} <: StaticArray{T, N} data::NTuple{L,T} - function MArray{Size,T,N,L}(x::NTuple{L,T}) where {Size,T,N,L} + function (::Type{MArray{Size,T,N,L}}){Size,T,N,L}(x::NTuple{L,T}) check_marray_parameters(Val{Size}, T, Val{N}, Val{L}) - new(x) + new{Size,T,N,L}(x) end - function MArray{Size,T,N,L}(x::NTuple{L,Any}) where {Size,T,N,L} + function (::Type{MArray{Size,T,N,L}}){Size,T,N,L}(x::NTuple{L,Any}) check_marray_parameters(Val{Size}, T, Val{N}, Val{L}) - new(convert_ntuple(T, x)) + new{Size,T,N,L}(convert_ntuple(T, x)) end - function MArray{Size,T,N,L}() where {Size,T,N,L} + function (::Type{MArray{Size,T,N,L}}){Size,T,N,L}() check_marray_parameters(Val{Size}, T, Val{N}, Val{L}) - new() + new{Size,T,N,L}() end end diff --git a/src/MMatrix.jl b/src/MMatrix.jl index e25595718..3bc59d7e9 100644 --- a/src/MMatrix.jl +++ b/src/MMatrix.jl @@ -18,19 +18,19 @@ unknown to the compiler (the element type may optionally also be specified). type MMatrix{S1, S2, T, L} <: StaticMatrix{T} data::NTuple{L, T} - function MMatrix{S1,S2,T,L}(d::NTuple{L,T}) where {S1,S2,T,L} + function (::Type{MMatrix{S1,S2,T,L}}){S1,S2,T,L}(d::NTuple{L,T}) check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L}) - new(d) + new{S1,S2,T,L}(d) end - function MMatrix{S1,S2,T,L}(d::NTuple{L,Any}) where {S1,S2,T,L} + function (::Type{MMatrix{S1,S2,T,L}}){S1,S2,T,L}(d::NTuple{L,Any}) check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L}) - new(convert_ntuple(T, d)) + new{S1,S2,T,L}(convert_ntuple(T, d)) end - function MMatrix{S1,S2,T,L}() where {S1,S2,T,L} + function (::Type{MMatrix{S1,S2,T,L}}){S1,S2,T,L}() check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L}) - new() + new{S1,S2,T,L}() end end diff --git a/src/MVector.jl b/src/MVector.jl index 67d511ba4..048c3beee 100644 --- a/src/MVector.jl +++ b/src/MVector.jl @@ -17,20 +17,20 @@ compiler (the element type may optionally also be specified). type MVector{S, T} <: StaticVector{T} data::NTuple{S, T} - function MVector{S,T}(in::NTuple{S, T}) where {S,T} - new(in) + function (::Type{MVector{S,T}}){S,T}(in::NTuple{S, T}) + new{S,T}(in) end - function MVector{S,T}(in::NTuple{S, Any}) where {S,T} - new(convert_ntuple(T,in)) + function (::Type{MVector{S,T}}){S,T}(in::NTuple{S, Any}) + new{S,T}(convert_ntuple(T,in)) end - function MVector{S,T}(in::T) where {S,T} - new((in,)) + function (::Type{MVector{S,T}}){S,T}(in::T) + new{S,T}((in,)) end - function MVector{S,T}() where {S,T} - new() + function (::Type{MVector{S,T}}){S,T}() + new{S,T}() end end diff --git a/src/SArray.jl b/src/SArray.jl index 9e65a4a8a..1e3b0a7ea 100644 --- a/src/SArray.jl +++ b/src/SArray.jl @@ -18,14 +18,14 @@ compiler (the element type may optionally also be specified). immutable SArray{Size, T, N, L} <: StaticArray{T, N} data::NTuple{L,T} - function SArray{Size,T,N,L}(x::NTuple{L,T}) where {Size,T,N,L} + function (::Type{SArray{Size,T,N,L}}){Size,T,N,L}(x::NTuple{L,T}) check_sarray_parameters(Val{Size}, T, Val{N}, Val{L}) - new(x) + new{Size,T,N,L}(x) end - function SArray{Size,T,N,L}(x::NTuple{L,Any}) where {Size,T,N,L} + function (::Type{SArray{Size,T,N,L}}){Size,T,N,L}(x::NTuple{L,Any}) check_sarray_parameters(Val{Size}, T, Val{N}, Val{L}) - new(convert_ntuple(T, x)) + new{Size,T,N,L}(convert_ntuple(T, x)) end end diff --git a/src/SMatrix.jl b/src/SMatrix.jl index 6ee577d83..18f439e60 100644 --- a/src/SMatrix.jl +++ b/src/SMatrix.jl @@ -17,14 +17,14 @@ unknown to the compiler (the element type may optionally also be specified). immutable SMatrix{S1, S2, T, L} <: StaticMatrix{T} data::NTuple{L, T} - function SMatrix{S1,S2,T,L}(d::NTuple{L,T}) where {S1,S2,T,L} + function (::Type{SMatrix{S1,S2,T,L}}){S1,S2,T,L}(d::NTuple{L,T}) check_smatrix_params(Val{S1}, Val{S2}, T, Val{L}) - new(d) + new{S1,S2,T,L}(d) end - function SMatrix{S1,S2,T,L}(d::NTuple{L,Any}) where {S1,S2,T,L} + function (::Type{SMatrix{S1,S2,T,L}}){S1,S2,T,L}(d::NTuple{L,Any}) check_smatrix_params(Val{S1}, Val{S2}, T, Val{L}) - new(convert_ntuple(T, d)) + new{S1,S2,T,L}(convert_ntuple(T, d)) end end @@ -66,7 +66,7 @@ end SMatrix{S1, S2, $T, L}(x) end end -SMatrixNoType{S1, S2, L, T} = SMatrix{S1, S2, T, L} +@compat SMatrixNoType{S1, S2, L, T} = SMatrix{S1, S2, T, L} @generated function (::Type{SMatrixNoType{S1, S2, L}}){S1,S2,L}(x::NTuple{L,Any}) T = promote_tuple_eltype(x) return quote diff --git a/src/SVector.jl b/src/SVector.jl index 01351f75e..8509e8201 100644 --- a/src/SVector.jl +++ b/src/SVector.jl @@ -16,12 +16,12 @@ compiler (the element type may optionally also be specified). immutable SVector{S, T} <: StaticVector{T} data::NTuple{S, T} - function SVector{S, T}(x::NTuple{S,T}) where {S, T} - new(x) + function (::Type{SVector{S, T}}){S, T}(x::NTuple{S,T}) + new{S, T}(x) end - function SVector{S, T}(x::NTuple{S,Any}) where {S, T} - new(convert_ntuple(T, x)) + function (::Type{SVector{S, T}}){S, T}(x::NTuple{S,Any}) + new{S, T}(convert_ntuple(T, x)) end end diff --git a/src/SizedArray.jl b/src/SizedArray.jl index 085cbce6a..2bb828f74 100644 --- a/src/SizedArray.jl +++ b/src/SizedArray.jl @@ -12,15 +12,15 @@ array may be reshaped. immutable SizedArray{S,T,N,M} <: StaticArray{T,N} data::Array{T,M} - function SizedArray{S,T,N,M}(a::Array) where {S,T,N,M} + function (::Type{SizedArray{S,T,N,M}}){S,T,N,M}(a::Array) if length(a) != prod(S) error("Dimensions $(size(a)) don't match static size $S") end - new(a) + new{S,T,N,M}(a) end - function SizedArray{S,T,N,M}() where {S,T,N,M} - new(Array{T,M}(S)) + function (::Type{SizedArray{S,T,N,M}}){S,T,N,M}() + new{S,T,N,M}(Array{T,M}(S)) end end @@ -73,14 +73,14 @@ similar_type{S,T,N,M,R}(::Type{SizedArray{S,T,N,M}}, ::Type{R}) = SizedArray{S,R @propagate_inbounds getindex(a::SizedArray, i::Int) = getindex(a.data, i) @propagate_inbounds setindex!(a::SizedArray, v, i::Int) = setindex!(a.data, v, i) -SizedVector{S,T,M} = SizedArray{S,T,1,M} +@compat SizedVector{S,T,M} = SizedArray{S,T,1,M} @pure size{S}(::Type{SizedVector{S}}) = S @inline (::Type{SizedVector{S}}){S,T,M}(a::Array{T,M}) = SizedArray{S,T,1,M}(a) @inline (::Type{SizedVector{S}}){S,T,L}(x::NTuple{L,T}) = SizedArray{S,T,1,1}(x) @inline (::Type{Vector})(sa::SizedVector) = sa.data @inline convert(::Type{Vector}, sa::SizedVector) = sa.data -SizedMatrix{S,T,M} = SizedArray{S,T,2,M} +@compat SizedMatrix{S,T,M} = SizedArray{S,T,2,M} @pure size{S}(::Type{SizedMatrix{S}}) = S @inline (::Type{SizedMatrix{S}}){S,T,M}(a::Array{T,M}) = SizedArray{S,T,2,M}(a) @inline (::Type{SizedMatrix{S}}){S,T,L}(x::NTuple{L,T}) = SizedArray{S,T,2,2}(x) diff --git a/src/StaticArrays.jl b/src/StaticArrays.jl index d48372492..efbf93293 100644 --- a/src/StaticArrays.jl +++ b/src/StaticArrays.jl @@ -10,6 +10,8 @@ import Base: @pure, @propagate_inbounds, getindex, setindex!, size, similar, sum, diff, prod, count, any, all, sumabs, sumabs2, minimum, maximum, extrema, mean, copy +using Compat + export StaticScalar, StaticArray, StaticVector, StaticMatrix export Scalar, SArray, SVector, SMatrix export MArray, MVector, MMatrix diff --git a/src/abstractarray.jl b/src/abstractarray.jl index b6d6da548..5f9b7dd06 100644 --- a/src/abstractarray.jl +++ b/src/abstractarray.jl @@ -1,4 +1,4 @@ -StaticScalar{T} = StaticArray{T,0} +@compat StaticScalar{T} = StaticArray{T,0} @pure length{T<:StaticArray}(a::T) = prod(size(a)) @pure length{T<:StaticArray}(a::Type{T}) = prod(size(a)) @@ -32,8 +32,7 @@ end 1 <= ii <= length(a) ? true : false end -Base.linearindexing(::StaticArray) = Base.LinearFast() -Base.linearindexing{T<:StaticArray}(::Type{T}) = Base.LinearFast() +@compat Base.IndexStyle{T<:StaticArray}(::Type{T}) = IndexLinear() # Default type search for similar_type """ diff --git a/src/core.jl b/src/core.jl index fda0be508..b3c60c466 100644 --- a/src/core.jl +++ b/src/core.jl @@ -34,10 +34,10 @@ additional fields, make sure the array data appears first. (see also `SVector`, `SMatrix`, `SArray`, `MVector`, `MMatrix`, `MArray` and `FieldVector`) """ -abstract type StaticArray{T, N} <: AbstractArray{T, N} end +@compat abstract type StaticArray{T, N} <: AbstractArray{T, N} end -StaticVector{T} = StaticArray{T, 1} -StaticMatrix{T} = StaticArray{T, 2} +@compat StaticVector{T} = StaticArray{T, 1} +@compat StaticMatrix{T} = StaticArray{T, 2} # People might not want to use Tuple for everything (TODO: check this with FieldVector...) # Generic case, with least 2 inputs diff --git a/src/traits.jl b/src/traits.jl index df8b17ab7..9508ccfd2 100644 --- a/src/traits.jl +++ b/src/traits.jl @@ -16,9 +16,9 @@ _det(::Size{(2,2)}, x::StaticMatrix) = x[1,1]*x[2,2] - x[1,2]*x[2,1] ``` """ immutable Size{S} - function Size{S}() where S + function (::Type{Size{S}}){S}() check_size(S) - new() + new{S}() end end diff --git a/src/util.jl b/src/util.jl index 8abb606ed..cabc174f3 100644 --- a/src/util.jl +++ b/src/util.jl @@ -1,5 +1,5 @@ # For convenience -TupleN{T,N} = NTuple{N,T} +@compat TupleN{T,N} = NTuple{N,T} # Cast any Tuple to an TupleN{T} @inline convert_ntuple{T}(::Type{T},d::T) = T # For zero-dimensional arrays diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 2ffb7cec5..21a259186 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -3,7 +3,7 @@ m = @SMatrix [1 2 3; 4 5 6; 7 8 9; 10 11 12] @test length(m) == 12 - @test Base.linearindexing(m) == Base.LinearFast() + @test IndexStyle(m) == IndexLinear() @test Base.isassigned(m, 2, 2) == true end diff --git a/test/fixed_size_arrays.jl b/test/fixed_size_arrays.jl index 628e29603..25a81a8e1 100644 --- a/test/fixed_size_arrays.jl +++ b/test/fixed_size_arrays.jl @@ -8,15 +8,15 @@ import StaticArrays.FixedSizeArrays: @fixed_vector @fixed_vector Point StaticVector -const Vec1d = Vec{1, Float64} -const Vec2d = Vec{2, Float64} -const Vec3d = Vec{3, Float64} -const Vec4d = Vec{4, Float64} -const Vec3f = Vec{3, Float32} - -const Mat2d = Mat{2,2, Float64, 4} -const Mat3d = Mat{3,3, Float64, 9} -const Mat4d = Mat{4,4, Float64, 16} +@compat const Vec1d = Vec{1, Float64} +@compat const Vec2d = Vec{2, Float64} +@compat const Vec3d = Vec{3, Float64} +@compat const Vec4d = Vec{4, Float64} +@compat const Vec3f = Vec{3, Float32} + +@compat const Mat2d = Mat{2,2, Float64, 4} +@compat const Mat3d = Mat{3,3, Float64, 9} +@compat const Mat4d = Mat{4,4, Float64, 16} immutable RGB{T} <: FieldVector{T} x::T diff --git a/test/runtests.jl b/test/runtests.jl index c685aca50..1407cf77b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using StaticArrays using Base.Test +using Compat @testset "StaticArrays" begin include("SVector.jl")