Skip to content

Commit

Permalink
Update for index traints changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Feb 20, 2017
1 parent fdeef49 commit d340f7d
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 84 deletions.
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6-
julia 0.5
Compat 0.19.0
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/FieldVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
51 changes: 26 additions & 25 deletions src/ImmutableArrays.jl
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/MMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ 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}
Expand Down
16 changes: 8 additions & 8 deletions src/MVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/SArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/SMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/SVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions src/SizedArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/StaticArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/abstractarray.jl
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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}) = Base.IndexLinear()

# Default type search for similar_type
"""
Expand Down
6 changes: 3 additions & 3 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/util.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 @compat(Base.IndexStyle(m)) == @compat(Base.IndexLinear())
@test Base.isassigned(m, 2, 2) == true
end

Expand Down
18 changes: 9 additions & 9 deletions test/fixed_size_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using StaticArrays
using Base.Test
using Compat

@testset "StaticArrays" begin
include("SVector.jl")
Expand Down

0 comments on commit d340f7d

Please sign in to comment.