diff --git a/docs/src/pages/api.md b/docs/src/pages/api.md index f57aaaec..1718be6e 100644 --- a/docs/src/pages/api.md +++ b/docs/src/pages/api.md @@ -36,7 +36,7 @@ functions). A container with arbitrarily many dimensions is defined as `struct SArray{Size,T,N,L} <: StaticArray{Size,T,N}`, where `Size = Tuple{S1, S2, ...}` is a tuple of `Int`s. You can easily construct one with -the `@SArray` macro, supporting all the features of `@SVector` and `@SMatrix` +the `@SArray` macro (or the short-form `@sa` macro), supporting all the features of `@SVector` and `@SMatrix` (but with arbitrary dimension). The main reason `SVector` and `SMatrix` are defined is to make it easier to diff --git a/docs/src/pages/quickstart.md b/docs/src/pages/quickstart.md index 69cce42f..245cdffb 100644 --- a/docs/src/pages/quickstart.md +++ b/docs/src/pages/quickstart.md @@ -29,6 +29,10 @@ m5 = SMatrix{2,2}([1 3 ; 2 4]) # Array conversions must specify size # Higher-dimensional support a = @SArray randn(2, 2, 2, 2, 2, 2) +# Short-form macro for static vectors or matrices +m6 = @sa [1 2; 3 4] +m7 = @sa[1 2; 3 4] * @sa[5, 6] # without space or parenthesis, requires Julia v0.7 or above + # Supports all the common operations of AbstractArray v7 = v1 + v2 v8 = sin.(v3) diff --git a/src/SArray.jl b/src/SArray.jl index c820d3ef..dee7ac4b 100644 --- a/src/SArray.jl +++ b/src/SArray.jl @@ -253,6 +253,8 @@ macro SArray(ex) end end +macro sa(ex); esc(:(@SArray($ex))); end + function promote_rule(::Type{<:SArray{S,T,N,L}}, ::Type{<:SArray{S,U,N,L}}) where {S,T,U,N,L} SArray{S,promote_type(T,U),N,L} end diff --git a/src/StaticArrays.jl b/src/StaticArrays.jl index 6b083b4e..08e1d3a3 100644 --- a/src/StaticArrays.jl +++ b/src/StaticArrays.jl @@ -27,7 +27,7 @@ export SDiagonal export Size, Length -export @SVector, @SMatrix, @SArray +export @SVector, @SMatrix, @SArray, @sa export @MVector, @MMatrix, @MArray export similar_type diff --git a/test/SArray.jl b/test/SArray.jl index 25f560e5..37f863bb 100644 --- a/test/SArray.jl +++ b/test/SArray.jl @@ -89,6 +89,9 @@ # Non-square comprehensions built from SVectors - see #76 @test @SArray([1 for x = SVector(1,2), y = SVector(1,2,3)]) == ones(2,3) + + # @SArray short-form macro + @test @macroexpand(@sa([a b; c d])) == @macroexpand(@SArray([a b; c d])) end @testset "Methods" begin