Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ Pkg.add("StaticArrays") # or Pkg.clone("https://github.com/JuliaArrays/StaticAr
using StaticArrays
using LinearAlgebra

# Use the convenience constructor type `SA` to create vectors and matrices
SA[1, 2, 3] isa SVector{3,Int}
SA_F64[1, 2, 3] isa SVector{3,Float64}
SA_F32[1, 2, 3] isa SVector{3,Float32}
SA[1 2; 3 4] isa SMatrix{2,2,Int}
SA_F64[1 2; 3 4] isa SMatrix{2,2,Float64}

# Create an SVector using various forms, using constructors, functions or macros
v1 = SVector(1, 2, 3)
v1.data === (1, 2, 3) # SVector uses a tuple for internal storage
Expand Down
7 changes: 7 additions & 0 deletions docs/src/pages/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Pkg.add("StaticArrays") # or Pkg.clone("https://github.com/JuliaArrays/StaticAr
using StaticArrays
using LinearAlgebra

# Use the convenience constructor type `SA` to create vectors and matrices
SA[1, 2, 3] isa SVector{3,Int}
SA_F64[1, 2, 3] isa SVector{3,Float64}
SA_F32[1, 2, 3] isa SVector{3,Float32}
SA[1 2; 3 4] isa SMatrix{2,2,Int}
SA_F64[1 2; 3 4] isa SMatrix{2,2,Float64}

# Create an SVector using various forms, using constructors, functions or macros
v1 = SVector(1, 2, 3)
v1.data === (1, 2, 3) # SVector uses a tuple for internal storage
Expand Down
2 changes: 1 addition & 1 deletion src/StaticArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export SHermitianCompact

export Size, Length

export SA
export SA, SA_F32, SA_F64
export @SVector, @SMatrix, @SArray
export @MVector, @MMatrix, @MArray

Expand Down
8 changes: 8 additions & 0 deletions src/initializers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ provided explicitly.
* `SA[1 2; 3 4]` creates a 2×2 SMatrix of `Int`s.
* `SA[1 2]` creates a 1×2 SMatrix of `Int`s.
* `SA{Float32}[1, 2]` creates a length-2 `SVector` of `Float32` elements.

A couple of helpful type aliases are also provided:

* `SA_F64[1, 2]` creates a lenght-2 `SVector` of `Float64` elements
* `SA_F32[1, 2]` creates a lenght-2 `SVector` of `Float32` elements
"""
struct SA{T} ; end

const SA_F32 = SA{Float32}
const SA_F64 = SA{Float64}

@inline similar_type(::Type{SA}, ::Size{S}) where {S} = SArray{Tuple{S...}}
@inline similar_type(::Type{SA{T}}, ::Size{S}) where {T,S} = SArray{Tuple{S...}, T}

Expand Down
6 changes: 6 additions & 0 deletions test/initializers.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@testset "Initialization with SA" begin

SA_test_ref(x) = SA[1,x,x]
SA_test_ref(x,T) = SA{T}[1,x,x]
@test @inferred(SA_test_ref(2)) === SVector{3,Int}((1,2,2))
Expand Down Expand Up @@ -31,3 +33,7 @@ SA_test_hvcat(x,T) = SA{T}[1 x x;
4 5]
@test_throws ArgumentError("SA[...] matrix rows of length (2, 3) are inconsistent") SA[1 2;
3 4 5]
@test SA_F64[1, 2] === SVector{2,Float64}((1,2))
@test SA_F32[1, 2] === SVector{2,Float32}((1,2))

end