Is 'SVector' a keyword in julia?

In a package, I see a lot of ‘SVector’. It looks like a datatype. But I cannot find it by help.

help?> SVector
search: DenseVector SparseVector AbstractVector StridedVector AbstractSparseVector DenseVecOrMat

Couldn't find SVector
Perhaps you meant Vector, BitVector or Schur
  No documentation found.

  Binding SVector does not exist.

I cannot find the definition of SVector in the package neither.

this type is defined in StaticArrays.jl

it is not standard library but it may as well be, this type is very very popular to use.

4 Likes

It’s here in the docs, the section of the manual all should read:
https://docs.julialang.org/en/v1/manual/performance-tips/

By using the SVector type from StaticArrays.jl,

It’s been discussed to add it to Julia, as a type (not keyword), well that package, but it’s not strictly needed.

It’s understandable that the help doesn’t explain it but I think it should be considered to add it there as a hint, and some other info too.

2 Likes

JuliaHub’s package-ecosystem-wide docs search works pretty well - StaticArrays.SVector is the first search result. There’s also a symbol definition search I hadn’t noticed before, but it also unearthed the correct result as the first hit.

3 Likes

it is very popular now?

I do not see its big advantage actually. As the docs say, it is only faster than the standard ‘Array’ for matrices smaller than 10*10 in size.

I do know why that is worth the efforts.

that is a common size!

it’s very possible this is not a useful type for your use case, but there many use cases for which it is

1 Like

There are several scenarios where one needs to work with arrays of a known (often small) length, e.g. when working with spatial coordinates (say in three dimensions). In this case, the vectors may be of length 3, and linear operators may be 3x3 matrices (e.g. coordinate rotation matrices). These are common use cases where static arrays are used.

If this is not your use case, then you don’t need (and probably shouldn’t use) static arrays.

2 Likes

Probably the package has this line:

using StaticArrays

which imported symbols like SVector into your namespace. If readability is more valued than convenience, it could have been

import StaticArrays

in which case SVector should always be written as StaticArrays.SVector, so someone reading the code will not be left wondering. Another possibility is writing

using StaticArrays: SVector

in which case SVector can be used directly, but a reader can easily find the definition of SVector in the using statement.

Personally, I try to use the latter two versions whenever I write a package, and I only use the simple using statement for quickly trying things in the REPL or Jupyter notebooks.

2 Likes

In my simulations I get a 10 times speed-up… Many small vectors…

1 Like

My most common matrix sizes are 3x3 and 4x4. So, yeah, it’s actually amazingly useful.