Skip to content

Commit

Permalink
Use new inner constructor and type declaration syntax and
Browse files Browse the repository at this point in the history
consequently drop 0.5 support.
  • Loading branch information
andreasnoack committed Feb 17, 2017
1 parent 1be47cc commit fdeef49
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 66 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.5
julia 0.6-
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 FieldVector{T} <: StaticVector{T}
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
48 changes: 24 additions & 24 deletions src/ImmutableArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ module ImmutableArrays

using ..StaticArrays

typealias Vector1{T} SVector{1,T}
typealias Vector2{T} SVector{2,T}
typealias Vector3{T} SVector{3,T}
typealias Vector4{T} SVector{4,T}

typealias Matrix1x1{T} SMatrix{1,1,T,1}
typealias Matrix1x2{T} SMatrix{1,2,T,2}
typealias Matrix1x3{T} SMatrix{1,3,T,3}
typealias Matrix1x4{T} SMatrix{1,4,T,4}

typealias Matrix2x1{T} SMatrix{2,1,T,2}
typealias Matrix2x2{T} SMatrix{2,2,T,4}
typealias Matrix2x3{T} SMatrix{2,3,T,6}
typealias Matrix2x4{T} SMatrix{2,4,T,8}

typealias Matrix3x1{T} SMatrix{3,1,T,3}
typealias Matrix3x2{T} SMatrix{3,2,T,6}
typealias Matrix3x3{T} SMatrix{3,3,T,9}
typealias Matrix3x4{T} SMatrix{3,4,T,12}

typealias Matrix4x1{T} SMatrix{4,1,T,4}
typealias Matrix4x2{T} SMatrix{4,2,T,8}
typealias Matrix4x3{T} SMatrix{4,3,T,12}
typealias Matrix4x4{T} SMatrix{4,4,T,16}
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}

export Vector1, Vector2, Vector3, Vector4,
Matrix1x1, Matrix1x2, Matrix1x3, Matrix1x4,
Expand Down
6 changes: 3 additions & 3 deletions src/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ compiler (the element type may optionally also be specified).
type MArray{Size, T, N, L} <: StaticArray{T, N}
data::NTuple{L,T}

function MArray(x::NTuple{L,T})
function MArray{Size,T,N,L}(x::NTuple{L,T}) where {Size,T,N,L}
check_marray_parameters(Val{Size}, T, Val{N}, Val{L})
new(x)
end

function MArray(x::NTuple{L,Any})
function MArray{Size,T,N,L}(x::NTuple{L,Any}) where {Size,T,N,L}
check_marray_parameters(Val{Size}, T, Val{N}, Val{L})
new(convert_ntuple(T, x))
end

function MArray()
function MArray{Size,T,N,L}() where {Size,T,N,L}
check_marray_parameters(Val{Size}, T, Val{N}, Val{L})
new()
end
Expand Down
6 changes: 3 additions & 3 deletions src/MMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ 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(d::NTuple{L,T})
function MMatrix{S1,S2,T,L}(d::NTuple{L,T}) where {S1,S2,T,L}
check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L})
new(d)
end

function MMatrix(d::NTuple{L,Any})
function MMatrix{S1,S2,T,L}(d::NTuple{L,Any}) where {S1,S2,T,L}
check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L})
new(convert_ntuple(T, d))
end

function MMatrix()
function MMatrix{S1,S2,T,L}() where {S1,S2,T,L}
check_MMatrix_params(Val{S1}, Val{S2}, T, Val{L})
new()
end
Expand Down
8 changes: 4 additions & 4 deletions src/MVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ compiler (the element type may optionally also be specified).
type MVector{S, T} <: StaticVector{T}
data::NTuple{S, T}

function MVector(in::NTuple{S, T})
function MVector{S,T}(in::NTuple{S, T}) where {S,T}
new(in)
end

function MVector(in::NTuple{S, Any})
function MVector{S,T}(in::NTuple{S, Any}) where {S,T}
new(convert_ntuple(T,in))
end

function MVector(in::T)
function MVector{S,T}(in::T) where {S,T}
new((in,))
end

function MVector()
function MVector{S,T}() where {S,T}
new()
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/SArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ compiler (the element type may optionally also be specified).
immutable SArray{Size, T, N, L} <: StaticArray{T, N}
data::NTuple{L,T}

function SArray(x::NTuple{L,T})
function SArray{Size,T,N,L}(x::NTuple{L,T}) where {Size,T,N,L}
check_sarray_parameters(Val{Size}, T, Val{N}, Val{L})
new(x)
end

function SArray(x::NTuple{L,Any})
function SArray{Size,T,N,L}(x::NTuple{L,Any}) where {Size,T,N,L}
check_sarray_parameters(Val{Size}, T, Val{N}, Val{L})
new(convert_ntuple(T, x))
end
Expand Down
6 changes: 3 additions & 3 deletions src/SMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ 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(d::NTuple{L,T})
function SMatrix{S1,S2,T,L}(d::NTuple{L,T}) where {S1,S2,T,L}
check_smatrix_params(Val{S1}, Val{S2}, T, Val{L})
new(d)
end

function SMatrix(d::NTuple{L,Any})
function SMatrix{S1,S2,T,L}(d::NTuple{L,Any}) where {S1,S2,T,L}
check_smatrix_params(Val{S1}, Val{S2}, T, Val{L})
new(convert_ntuple(T, d))
end
Expand Down Expand Up @@ -66,7 +66,7 @@ end
SMatrix{S1, S2, $T, L}(x)
end
end
typealias SMatrixNoType{S1, S2, L, T} SMatrix{S1, S2, T, L}
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
Expand Down
4 changes: 2 additions & 2 deletions src/SVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ compiler (the element type may optionally also be specified).
immutable SVector{S, T} <: StaticVector{T}
data::NTuple{S, T}

function SVector(x::NTuple{S,T})
function SVector{S, T}(x::NTuple{S,T}) where {S, T}
new(x)
end

function SVector(x::NTuple{S,Any})
function SVector{S, T}(x::NTuple{S,Any}) where {S, T}
new(convert_ntuple(T, x))
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/SizedArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ array may be reshaped.
immutable SizedArray{S,T,N,M} <: StaticArray{T,N}
data::Array{T,M}

function SizedArray(a::Array)
function SizedArray{S,T,N,M}(a::Array) where {S,T,N,M}
if length(a) != prod(S)
error("Dimensions $(size(a)) don't match static size $S")
end
new(a)
end

function SizedArray()
function SizedArray{S,T,N,M}() where {S,T,N,M}
new(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)

typealias SizedVector{S,T,M} SizedArray{S,T,1,M}
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

typealias SizedMatrix{S,T,M} SizedArray{S,T,2,M}
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: 1 addition & 1 deletion src/abstractarray.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
typealias StaticScalar{T} StaticArray{T,0}
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
10 changes: 5 additions & 5 deletions src/core.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
abstract StaticArray{T, N} <: DenseArray{T, N}
typealias StaticVector{T} StaticArray{T, 1}
typealias StaticMatrix{T} StaticArray{T, 2}
StaticVector{T} = StaticArray{T, 1}
StaticMatrix{T} = StaticArray{T, 2}
`StaticArray`s are Julia arrays with fixed, known size.
Expand Down 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 StaticArray{T, N} <: AbstractArray{T, N}
abstract type StaticArray{T, N} <: AbstractArray{T, N} end

typealias StaticVector{T} StaticArray{T, 1}
typealias StaticMatrix{T} StaticArray{T, 2}
StaticVector{T} = StaticArray{T, 1}
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
2 changes: 0 additions & 2 deletions src/matrix_multiply.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Base: *, Ac_mul_B, A_mul_Bc, Ac_mul_Bc, At_mul_B, A_mul_Bt, At_mul_Bt
import Base: A_mul_B!, Ac_mul_B!, A_mul_Bc!, Ac_mul_Bc!, At_mul_B!, A_mul_Bt!, At_mul_Bt!

typealias BlasEltypes Union{Float64, Float32, Complex{Float64}, Complex{Float32}}

# Idea inspired by https://github.com/JuliaLang/julia/pull/18218
promote_matprod{T1,T2}(::Type{T1}, ::Type{T2}) = typeof(zero(T1)*zero(T2) + zero(T1)*zero(T2))

Expand Down
2 changes: 1 addition & 1 deletion src/traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _det(::Size{(2,2)}, x::StaticMatrix) = x[1,1]*x[2,2] - x[1,2]*x[2,1]
```
"""
immutable Size{S}
function Size()
function Size{S}() where S
check_size(S)
new()
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
typealias TupleN{T,N} NTuple{N,T}
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
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

typealias Vec1d Vec{1, Float64}
typealias Vec2d Vec{2, Float64}
typealias Vec3d Vec{3, Float64}
typealias Vec4d Vec{4, Float64}
typealias Vec3f Vec{3, Float32}

typealias Mat2d Mat{2,2, Float64, 4}
typealias Mat3d Mat{3,3, Float64, 9}
typealias Mat4d Mat{4,4, Float64, 16}
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}

immutable RGB{T} <: FieldVector{T}
x::T
Expand Down

0 comments on commit fdeef49

Please sign in to comment.