FixedSizeArrays.jl
FixedSizeArrays.jl
is a package for the Julia programming language which implements mutable fixed-size arrays (FixedSizeArray
), which means the length of the array can not change after construction and is amenable to be constant-propagated at compile-time when possible.
FixedSizeArrays supports the standard array interfaces, so things like broadcasting, matrix multiplication, other linear algebra operations, similar
, copyto!
or map
should just work.
Use the constructors to convert from other array types. Use collect_as
to convert from arbitrary iterators.
Comparison with other array types
Array
from Base
While Base
's Array
is a convenient multi-dimensional container for continuous data, a fixed-size array is what is employed in most linear algebra applications, where the size of tensors typically does not change. Here is a comparison between Array
and FixedSizeArray
:
Array
is dynamic (or growable) which means the size of anArray
can be changed after construction. The size of aFixedSizeArray
cannot be changed;- the above property of
FixedSizeArray
s enables certain compiler optimizations in some cases where the size of aFixedSizeArray
is known at compile-time. The dynamic property ofArray
s limits the optimization opportunities, which makesArray
s less likely to be optimized as efficiently asFixedSizeArray
s.
You can see a showcase of performance/memory advantages of FixedSizeArray
over Array
in this evolving discussion.
MArray
from StaticArrays.jl
FixedSizeArray
is an alternative implementation to MArray
from StaticArrays.jl
.
Main differences between FixedSizeArray
and MArray
are:
FixedSizeArray
is based on theMemory
type introduced in Julia v1.11,MArray
is backed by tuples, which are not efficient for long arrays ($\gg 100$ elements);- the size of the array is part of the type parameters of
MArray
, this isn't the case forFixedSizeArray
, where the size is only a constant field of the data structure.
There are applications where it may be desirable to dispatch on the size of an array, in that case FixedSizeArray
would not be a good fit and you may consider using MArray
instead.
FixedSizeArray
is not a direct replacement for SArray
: in addition to having the size as part of the type parameters, SArray
is immutable, instead the elements of a FixedSizeArray
can be changed at any point.
What about the other package with same name?
This package is not related to a package with the same name by @SimonDanisch
. That, earlier, package was one of the StaticArrays.jl-like packages in the pre-v1 days of Julia: https://github.com/SimonDanisch/FixedSizeArrays.jl.