Skip to content

Commit 976722f

Browse files
committed
Add short-form macro for SArray construction
1 parent bb51021 commit 976722f

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

docs/src/pages/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ functions).
3636
A container with arbitrarily many dimensions is defined as
3737
`struct SArray{Size,T,N,L} <: StaticArray{Size,T,N}`, where
3838
`Size = Tuple{S1, S2, ...}` is a tuple of `Int`s. You can easily construct one with
39-
the `@SArray` macro, supporting all the features of `@SVector` and `@SMatrix`
39+
the `@SArray` macro (or the short-form `@sa` macro), supporting all the features of `@SVector` and `@SMatrix`
4040
(but with arbitrary dimension).
4141

4242
The main reason `SVector` and `SMatrix` are defined is to make it easier to

docs/src/pages/quickstart.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ m5 = SMatrix{2,2}([1 3 ; 2 4]) # Array conversions must specify size
2929
# Higher-dimensional support
3030
a = @SArray randn(2, 2, 2, 2, 2, 2)
3131

32+
# Short-form macro for static vectors or matrices
33+
m6 = @sa [1 2; 3 4]
34+
m7 = @sa[1 2; 3 4] * @sa[5, 6] # without space or parenthesis, requires Julia v0.7 or above
35+
3236
# Supports all the common operations of AbstractArray
3337
v7 = v1 + v2
3438
v8 = sin.(v3)

src/SArray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ macro SArray(ex)
253253
end
254254
end
255255

256+
macro sa(ex); esc(:(@SArray($ex))); end
257+
256258
function promote_rule(::Type{<:SArray{S,T,N,L}}, ::Type{<:SArray{S,U,N,L}}) where {S,T,U,N,L}
257259
SArray{S,promote_type(T,U),N,L}
258260
end

src/StaticArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export SDiagonal
2727

2828
export Size, Length
2929

30-
export @SVector, @SMatrix, @SArray
30+
export @SVector, @SMatrix, @SArray, @sa
3131
export @MVector, @MMatrix, @MArray
3232

3333
export similar_type

test/SArray.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989

9090
# Non-square comprehensions built from SVectors - see #76
9191
@test @SArray([1 for x = SVector(1,2), y = SVector(1,2,3)]) == ones(2,3)
92+
93+
# @SArray short-form macro
94+
@test @macroexpand(@sa([a b; c d])) == @macroexpand(@SArray([a b; c d]))
9295
end
9396

9497
@testset "Methods" begin

0 commit comments

Comments
 (0)