StaticArrays 0.12.0 - New static array literal syntax

Hi all, I’ve just released StaticArrays Release 0.12.0. I’d like to reach version 1.0 soon so we’ve been doing some cleanup in the last few months and working on a few long standing problems.

One is the issue of conveniently and unambiguously constructing short static arrays from their components. Base is privileged to have the Vector and Matrix literal syntaxes like [1,2,3] and [1 2; 3 4], but it’s hard to have something quite as nice in a package. We have the macros like @SMatrix but there’s a lot of them, they’re verbose and annoyingly non-extensible.

In version 0.12.0 we now have the special “SArray constructor” type SA:

julia> v = SA[1,2,3]
3-element SArray{Tuple{3},Int64,1,3} with indices SOneTo(3):
 1
 2
 3

julia> m = SA[1.0 2.0
              3.0 4.0]
2×2 SArray{Tuple{2,2},Float64,2,4} with indices SOneTo(2)×SOneTo(2):
 1.0  2.0
 3.0  4.0

This lets you construct SVector and SMatrix with almost the same syntax as Base. If you want a particular element type, there’s also the type aliases SA_F64 and SA_F32 for Float64 and Float32 eltypes, and you can specify your own eltypes with SA{T}. For example:

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}
SA{UInt8}[1,2]   isa  SVector{2,UInt8}

This doesn’t entirely solve the problem of creating other types of static array but it’s possible to use conversion; for example MMatrix(SA[1 2; 3 4]).

There’s also a lot of other fixes in this release thanks to many people (thanks especially to @mateuszbaran for jumping in and cheerfully fixing various long standing issues!). Another notable change is the generalization of FieldVector to arbitrary dimensional FieldArrays thanks to @CFBaptista.

36 Likes

Very neat implementation! It did not occur to me that one can use Base.typed_vcat & friends that way. Perhaps these functions should be documented in more detail in Base.

3 Likes

This looks great!

But my StaticArrays is stuck at v0.11.1.

How can discover why it’s not upgrading?

These seem to point to a Julia v0.6 script.

Try ] add StaticArrays@0.12.0 the output for which should tell you what’s holding you back.

3 Likes

Thanks!

The culprit seems to be LazyArrays:

(v1.2) pkg> add StaticArrays@0.12.0
  Updating registry at `C:\Users\plowman\.julia\registries\General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package LazyArrays [5078a376]:
 LazyArrays [5078a376] log:
 ├─possible versions are: [0.0.1, 0.1.0-0.1.1, 0.2.0-0.2.1, 0.3.0-0.3.2, 0.4.0, 0.5.0-0.5.2, 0.6.0, 0.7.0-0.7.1, 0.8.0-0.8.1, 0.9.0-0.9.1, 0.10.0, 0.11.0, 0.12.0-0.12.3, 0.13.0] or uninstalled
 ├─restricted to versions 0.13.0 by an explicit requirement, leaving only versions 0.13.0
 └─restricted by compatibility requirements with StaticArrays [90137ffa] to versions: [0.0.1, 0.1.0-0.1.1, 0.2.0-0.2.1, 0.3.0-0.3.2, 0.4.0, 0.5.0-0.5.2, 0.6.0, 0.7.0-0.7.1, 0.8.0-0.8.1, 0.9.0-0.9.1] or uninstalled — no versions left
   └─StaticArrays [90137ffa] log:
     ├─possible versions are: [0.8.0-0.8.3, 0.9.0-0.9.2, 0.10.0, 0.10.2-0.10.3, 0.11.0-0.11.1, 0.12.0] or uninstalled
     └─restricted to versions 0.12.0 by an explicit requirement, leaving only versions 0.12.0
1 Like

See https://github.com/JuliaArrays/LazyArrays.jl/pull/79

4 Likes