# \#staticarrays

**URL:** https://discourse.julialang.org/tag/staticarrays/620.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [\`SparseArray\` types](https://discourse.julialang.org/t/sparsearray-types/138210)

<div class="topic-metadata">

**Author:** [@rokke](https://discourse.julialang.org/u/rokke)\
**Replies:** 5\
**Last updated:** [July 16, 2026, 6:56am UTC](https://discourse.julialang.org/t/sparsearray-types/138210 "2026-07-16T06:56:38Z")

</div>

SparseMatrixCSC currently has a documented type definition of: SparseMatrixCSC{Tv,Ti\<:Integer} \<: AbstractSparseMatrixCSC{Tv,Ti} but, if you try to actually make one, you will find in practice that it only has exactly …

---

## [ForwardDiff Lie brackets allocate with StaticArrays](https://discourse.julialang.org/t/forwarddiff-lie-brackets-allocate-with-staticarrays/137248)

<div class="topic-metadata">

**Author:** [@tremelow](https://discourse.julialang.org/u/tremelow)\
**Replies:** 0\
**Last updated:** [May 22, 2026, 9:34pm UTC](https://discourse.julialang.org/t/forwarddiff-lie-brackets-allocate-with-staticarrays/137248 "2026-05-22T21:34:52Z")

</div>

I’m working on a code where I need Lie brackets of Lie brackets, but computing the Jacobian of a Lie bracket allocates data. Here’s a MWE using StaticArrays using BenchmarkTools import ForwardDiff f(x::SVector{2,T}) wh…

---

## [Reinterpret between SVector{N,ComplexF64} and SVector{2N,Float64} without accessing internal fields](https://discourse.julialang.org/t/reinterpret-between-svector-n-complexf64-and-svector-2n-float64-without-accessing-internal-fields/136183)

<div class="topic-metadata">

**Author:** [@pmc4](https://discourse.julialang.org/u/pmc4)\
**Replies:** 8\
**Last updated:** [March 16, 2026, 1:11pm UTC](https://discourse.julialang.org/t/reinterpret-between-svector-n-complexf64-and-svector-2n-float64-without-accessing-internal-fields/136183 "2026-03-16T13:11:19Z")

</div>

Hi, everyone. I want to ask you if you know a better way of doing the following that does not imply accessing internal fields. Imagine I have a vector of complex numbers: julia\> v1 = \[1.0 + 0.5im, 4.8 - 9.0im\] 2-elemen…

---

## [Mutation attempt in \`ContinuousCallback\` when solving \`SDEProblem{StaticArraysCore.SVector{2, Float64}}\`](https://discourse.julialang.org/t/mutation-attempt-in-continuouscallback-when-solving-sdeproblem-staticarrayscore-svector-2-float64/136168)

<div class="topic-metadata">

**Author:** [@NoFishLikeIan](https://discourse.julialang.org/u/NoFishLikeIan)\
**Replies:** 1\
**Last updated:** [March 13, 2026, 11:37am UTC](https://discourse.julialang.org/t/mutation-attempt-in-continuouscallback-when-solving-sdeproblem-staticarrayscore-svector-2-float64/136168 "2026-03-13T11:37:29Z")

</div>

I have an SDE where the drift function f is defined out-of-place and the state is a StaticArrays.SVector. I need to terminate! the integration using a ContinuousCallback. This raises an error, as the StochasticDiffEq pac…

---

## [How can I implement a vector of StaticArrays as a variable in MTK?](https://discourse.julialang.org/t/how-can-i-implement-a-vector-of-staticarrays-as-a-variable-in-mtk/134962)

<div class="topic-metadata">

**Author:** [@pmc4](https://discourse.julialang.org/u/pmc4)\
**Replies:** 6\
**Last updated:** [January 11, 2026, 5:13pm UTC](https://discourse.julialang.org/t/how-can-i-implement-a-vector-of-staticarrays-as-a-variable-in-mtk/134962 "2026-01-11T17:13:01Z")

</div>

Hi everyone. After trying for weeks I would like to ask the community if what I’m trying to do is possible or whether I have arrived to a dead end. I’ve reduced it to a MWE. The system I want to solve in ModelingToolkit…

---

## [Static vectors of vectors slow?](https://discourse.julialang.org/t/static-vectors-of-vectors-slow/134720)

<div class="topic-metadata">

**Author:** [@rokke](https://discourse.julialang.org/u/rokke)\
**Replies:** 3\
**Last updated:** [December 24, 2025, 12:11pm UTC](https://discourse.julialang.org/t/static-vectors-of-vectors-slow/134720 "2025-12-24T12:11:17Z")

</div>

first, I introduce some very similar ways to represent some boring data, with reasonable benchmarks: julia\> a=SVector{3, MVector{3,Int}}(\[MVector{3,Int}(\[1,1,1\]),MVector{3,Int}(\[1,1,1\]),MVector{3,Int}(\[1,1,1\])\]) 3-eleme…

---

## [Convert or Reinterpret Between NamedTuple and SVector](https://discourse.julialang.org/t/convert-or-reinterpret-between-namedtuple-and-svector/134600)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 7\
**Last updated:** [December 17, 2025, 7:33pm UTC](https://discourse.julialang.org/t/convert-or-reinterpret-between-namedtuple-and-svector/134600 "2025-12-17T19:33:07Z")

</div>

My question is related to Vector to NamedTuple? Assume my NamedTuple contains only floating point values T and SVector{N, T} entries, e.g., using StaticArrays nt = ( a = rand(), b = SA\[1.0, 2.0 ,3.0\] ) Taking such a N…

---

## [Large difference in computation time of expv from 4\*4 matrix to 3\*3 matrix](https://discourse.julialang.org/t/large-difference-in-computation-time-of-expv-from-4-4-matrix-to-3-3-matrix/133376)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 3\
**Last updated:** [October 23, 2025, 12:13pm UTC](https://discourse.julialang.org/t/large-difference-in-computation-time-of-expv-from-4-4-matrix-to-3-3-matrix/133376 "2025-10-23T12:13:20Z")

</div>

Hi Guys, I tried to profile the performance of ExponentialUtilities on static array as matrix. I found there is a big jump from 33 matrix to 44 matrix. May I know why? Here is the script I used for the testing: using E…

---

## [Combining \`Optim\` and \`FieldVector\` from \`StaticArrays\`](https://discourse.julialang.org/t/combining-optim-and-fieldvector-from-staticarrays/131472)

<div class="topic-metadata">

**Author:** [@NoFishLikeIan](https://discourse.julialang.org/u/NoFishLikeIan)\
**Replies:** 3\
**Last updated:** [August 9, 2025, 10:15am UTC](https://discourse.julialang.org/t/combining-optim-and-fieldvector-from-staticarrays/131472 "2025-08-09T10:15:56Z")

</div>

I’m getting a MethodError in LBFGS when trying to use a custom mutable struct that inherits from FieldVector for an optimization problem. using StaticArrays using Optimization, OptimizationOptimJL mutable struct Point{…

---

## [Understanding typing rules](https://discourse.julialang.org/t/understanding-typing-rules/131087)

<div class="topic-metadata">

**Author:** [@benc](https://discourse.julialang.org/u/benc)\
**Replies:** 4\
**Last updated:** [July 28, 2025, 8:11am UTC](https://discourse.julialang.org/t/understanding-typing-rules/131087 "2025-07-28T08:11:32Z")

</div>

Hi, In the following expression using StaticArrays using Random Random.seed(42) a = SVector{2, Float64}(1.0, 2) b = a + rand(2) I was initially (incorrectly) expecting that b’s type would be SVector{2, Float64}. In…

---

## [Unexpected behaviour when using Pluto with StaticArrays](https://discourse.julialang.org/t/unexpected-behaviour-when-using-pluto-with-staticarrays/130690)

<div class="topic-metadata">

**Author:** [@azeredo-e](https://discourse.julialang.org/u/azeredo-e)\
**Replies:** 2\
**Last updated:** [July 14, 2025, 7:36am UTC](https://discourse.julialang.org/t/unexpected-behaviour-when-using-pluto-with-staticarrays/130690 "2025-07-14T07:36:52Z")

</div>

Hello everyone. I’ve found this weird behaviour when using StaticArrays within a begin … end block Pluto. I have this cell begin xᵢ = collect(range(0, 10, length=n)) |\> SVector{n} yᵢ = @SVector \[β₀ + β₁ \* i …

---

## [Adding an SMatrix](https://discourse.julialang.org/t/adding-an-smatrix/130202)

<div class="topic-metadata">

**Author:** [@matthiasbaitsch](https://discourse.julialang.org/u/matthiasbaitsch)\
**Replies:** 3\
**Last updated:** [June 25, 2025, 4:23pm UTC](https://discourse.julialang.org/t/adding-an-smatrix/130202 "2025-06-25T16:23:10Z")

</div>

Hi, the following code fails because Ke is immutable after adding the SMatrix. using StaticArrays Ke = zeros(3, 3) Ke += SA\[1 2 3; 4 3 2; 4 3 2\] Ke\[1, 1\] += 3 I wonder whether this is intended behaviour.

---

## [Modifying subentries in a Vector{SVector}, @set and reinterpret](https://discourse.julialang.org/t/modifying-subentries-in-a-vector-svector-set-and-reinterpret/130178)

<div class="topic-metadata">

**Author:** [@eldee](https://discourse.julialang.org/u/eldee)\
**Replies:** 1\
**Last updated:** [June 24, 2025, 7:41pm UTC](https://discourse.julialang.org/t/modifying-subentries-in-a-vector-svector-set-and-reinterpret/130178 "2025-06-24T19:41:58Z")

</div>

Hi, Most of the time it makes conceptually more sense to store some data as a Vector{SVector{Float64, 3}} v as opposed to a Matrix{Float64} M of size (3, n). However, this makes updating (sub)entries more difficult. I.…

---

## [ODE model with preallocated MVectors and still compatible with AD/stiff solvers?](https://discourse.julialang.org/t/ode-model-with-preallocated-mvectors-and-still-compatible-with-ad-stiff-solvers/129253)

<div class="topic-metadata">

**Author:** [@Michael\_Barmann](https://discourse.julialang.org/u/Michael_Barmann)\
**Replies:** 2\
**Last updated:** [May 22, 2025, 8:48pm UTC](https://discourse.julialang.org/t/ode-model-with-preallocated-mvectors-and-still-compatible-with-ad-stiff-solvers/129253 "2025-05-22T20:48:50Z")

</div>

I am writing an ODE model that describes the positions of a system of N interacting particles living in a 2D box. My ODE state vector u is an N x 2 array of numbers. Each call to the model updates a pre-allocated N x 2 a…

---

## [Collecting into either \`StaticArray\` or \`Array\`](https://discourse.julialang.org/t/collecting-into-either-staticarray-or-array/128669)

<div class="topic-metadata">

**Author:** [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Replies:** 0\
**Last updated:** [May 3, 2025, 4:50pm UTC](https://discourse.julialang.org/t/collecting-into-either-staticarray-or-array/128669 "2025-05-03T16:50:43Z")

</div>

I might have missed something in StaticArrays.jl. Is there an agreed type which can contain the length/multidimensional size of an iterator, either statically or dynamically, and which can be used to collect into either …

---

## [Why Are Statically Sized Arrays Immutable?](https://discourse.julialang.org/t/why-are-statically-sized-arrays-immutable/128331)

<div class="topic-metadata">

**Author:** [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Replies:** 30\
**Last updated:** [April 25, 2025, 3:06pm UTC](https://discourse.julialang.org/t/why-are-statically-sized-arrays-immutable/128331 "2025-04-25T15:06:20Z")

</div>

I often hear that StaticArrays.SArray is immutable because it is stack allocated. I’m sure this is a misunderstanding on my end, though, because stack allocated types in other languages can be mutated in other languages. …

---

## [Vector of MVectors](https://discourse.julialang.org/t/vector-of-mvectors/128275)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 9\
**Last updated:** [April 21, 2025, 10:55pm UTC](https://discourse.julialang.org/t/vector-of-mvectors/128275 "2025-04-21T22:55:18Z")

</div>

What am I doing wrong? I want to have a vector of MVectors, but each of them shall be different. using StaticArrays vec=zeros(MVector{3, Float64}, 4) vec\[1\] .= \[1,2,3\] vec has as output: \[1.0, 2.0, 3.0\] \[1.0, 2.0, 3…

---

## [Why does SMatrix allocate in this case?](https://discourse.julialang.org/t/why-does-smatrix-allocate-in-this-case/127808)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 3\
**Last updated:** [April 8, 2025, 2:12pm UTC](https://discourse.julialang.org/t/why-does-smatrix-allocate-in-this-case/127808 "2025-04-08T14:12:34Z")

</div>

Hello everyone, Suppose I have: using StaticArrays using Chairmarks N = 10 Dimensions = 2 DimensionsPlus = Dimensions + 1 FloatType = Float64 SVectors = rand(SVector{DimensionsPlus, FloatType}, N) MVectors =…

---

## [Subtyping FieldVector from StaticArrays.jl](https://discourse.julialang.org/t/subtyping-fieldvector-from-staticarrays-jl/127312)

<div class="topic-metadata">

**Author:** [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Replies:** 2\
**Last updated:** [March 25, 2025, 3:12pm UTC](https://discourse.julialang.org/t/subtyping-fieldvector-from-staticarrays-jl/127312 "2025-03-25T15:12:18Z")

</div>

I am using this approach in a couple of projects: julia\> import StaticArrays: FieldVector, Size, similar\_type julia\> struct Direction{T\<:AbstractFloat} \<: FieldVector{3, T} x::T y::T z:…

---

## [Writing code that works allocation-free on both vectors and SVectors](https://discourse.julialang.org/t/writing-code-that-works-allocation-free-on-both-vectors-and-svectors/127048)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 6\
**Last updated:** [March 17, 2025, 11:59am UTC](https://discourse.julialang.org/t/writing-code-that-works-allocation-free-on-both-vectors-and-svectors/127048 "2025-03-17T11:59:58Z")

</div>

I’d like to write generic code that operates on abstract vectors, and is non-allocating. A specific example is a function that subtracts the mean and normalizes a vector. This can be done in-place. However, the problem w…

---

## [Avoiding allocations in jacobian system](https://discourse.julialang.org/t/avoiding-allocations-in-jacobian-system/126376)

<div class="topic-metadata">

**Author:** [@AP9](https://discourse.julialang.org/u/AP9)\
**Replies:** 2\
**Last updated:** [February 27, 2025, 10:26am UTC](https://discourse.julialang.org/t/avoiding-allocations-in-jacobian-system/126376 "2025-02-27T10:26:06Z")

</div>

Why is the below function allocating, and how can I optimize it so it does not allocate? β = 100 S(x) = 1/(1+exp(-β\*x)) S\_prime(x) = β\*S(x)\*(1-S(x)) function jacobian\_system(u, p, n) ω, ω\_A, A = p x, y, s = u …

---

## [\`eigen\` with \`sortby\` does not work for \`StaticArrays\`](https://discourse.julialang.org/t/eigen-with-sortby-does-not-work-for-staticarrays/125682)

<div class="topic-metadata">

**Author:** [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Replies:** 1\
**Last updated:** [February 8, 2025, 12:29pm UTC](https://discourse.julialang.org/t/eigen-with-sortby-does-not-work-for-staticarrays/125682 "2025-02-08T12:29:59Z")

</div>

As reported in the following post, eigen can be called with a sortby argument to provide the output in a different order, e.g. in descending order of the eigenvalues’ real part instead of the default. However, this doe…

---

## [How to use size type as lower precision in Static Arrays?](https://discourse.julialang.org/t/how-to-use-size-type-as-lower-precision-in-static-arrays/125457)

<div class="topic-metadata">

**Author:** [@mj2984](https://discourse.julialang.org/u/mj2984)\
**Replies:** 1\
**Last updated:** [February 1, 2025, 2:24pm UTC](https://discourse.julialang.org/t/how-to-use-size-type-as-lower-precision-in-static-arrays/125457 "2025-02-01T14:24:52Z")

</div>

Currently Static Arrays throws an error if the size type is anything other than Int64. Considering the size of Arrays is much smaller, is it possible to support other types such as UInt8, Int8, etc?

---

## [StaticArrays solve symmetric linear system - seems typeinstable](https://discourse.julialang.org/t/staticarrays-solve-symmetric-linear-system-seems-typeinstable/124634)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 2\
**Last updated:** [January 10, 2025, 2:25pm UTC](https://discourse.julialang.org/t/staticarrays-solve-symmetric-linear-system-seems-typeinstable/124634 "2025-01-10T14:25:03Z")

</div>

Hi there, I am wondering why the following does not return a SVector, but allocates a normal Vector. Also warntype shows problems using StaticArrays using LinearAlgebra using Statistics function testme(xs=rand(20)) …

---

## [How to apply fft to an array of static arrays?](https://discourse.julialang.org/t/how-to-apply-fft-to-an-array-of-static-arrays/124127)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 4\
**Last updated:** [December 24, 2024, 6:58am UTC](https://discourse.julialang.org/t/how-to-apply-fft-to-an-array-of-static-arrays/124127 "2024-12-24T06:58:54Z")

</div>

I’d like to be able to do something like using StaticArrays, FFTW A = \[@SVector rand(ComplexF64, 3) for m ∈ 1:512\] fft(A) but FFTW.jl throws an error when I try it. Due to performance and ergonomic reasons, I really w…

---

## [Sample StaticVectors with Distributions.jl](https://discourse.julialang.org/t/sample-staticvectors-with-distributions-jl/123792)

<div class="topic-metadata">

**Author:** [@Joaquin\_Rodriguez](https://discourse.julialang.org/u/Joaquin_Rodriguez)\
**Replies:** 2\
**Last updated:** [December 13, 2024, 10:03pm UTC](https://discourse.julialang.org/t/sample-staticvectors-with-distributions-jl/123792 "2024-12-13T22:03:04Z")

</div>

I need to generate some random vectors with a custom distribution, and I would like to use the Distributions.jl API. However, my vectors are small StaticVectors and sampling from a distribution returns plain Vectors. As…

---

## [Static array multiplied by its adjoint seems to allocate](https://discourse.julialang.org/t/static-array-multiplied-by-its-adjoint-seems-to-allocate/123232)

<div class="topic-metadata">

**Author:** [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Replies:** 12\
**Last updated:** [December 2, 2024, 3:54pm UTC](https://discourse.julialang.org/t/static-array-multiplied-by-its-adjoint-seems-to-allocate/123232 "2024-12-02T15:54:39Z")

</div>

Hi there, I am writing out a likelihood estimation and I have run into some allocation issues when coding up the Hessian. Even though the Hessian function HLL seems to mirror what the gradient function ∇LL is doing. One…

---

## [Using a runtime-length \`SVector\` within a closure allocates memory](https://discourse.julialang.org/t/using-a-runtime-length-svector-within-a-closure-allocates-memory/123020)

<div class="topic-metadata">

**Author:** [@ferrolho](https://discourse.julialang.org/u/ferrolho)\
**Replies:** 6\
**Last updated:** [November 24, 2024, 5:40pm UTC](https://discourse.julialang.org/t/using-a-runtime-length-svector-within-a-closure-allocates-memory/123020 "2024-11-24T17:40:15Z")

</div>

Consider the Test struct below. julia\> using StaticArrays julia\> struct Test{T,V} x::Int v::V Test(x::Int, v::V) where {T\<:Real,V\<:AbstractVector{T}} = new{T,V}(x, v) end Let’s …

---

## [Allocations even when using StaticArrays.jl](https://discourse.julialang.org/t/allocations-even-when-using-staticarrays-jl/122775)

<div class="topic-metadata">

**Author:** [@johnmyslinski](https://discourse.julialang.org/u/johnmyslinski)\
**Replies:** 2\
**Last updated:** [November 18, 2024, 2:09pm UTC](https://discourse.julialang.org/t/allocations-even-when-using-staticarrays-jl/122775 "2024-11-18T14:09:43Z")

</div>

Hi All, In this below MRE I am still seeing some allocations when using @btime. Based on my understanding, I would expect to see 0 allocations. Am I misunderstanding something? Are the 8 allocations I see a byproduct …

---

## [Allocations MVectors](https://discourse.julialang.org/t/allocations-mvectors/121818)

<div class="topic-metadata">

**Author:** [@AdaemmerP](https://discourse.julialang.org/u/AdaemmerP)\
**Replies:** 10\
**Last updated:** [October 27, 2024, 10:38am UTC](https://discourse.julialang.org/t/allocations-mvectors/121818 "2024-10-27T10:38:56Z")

</div>

Why does this: m! = factorial(3) @btime MVector{$m!, Float64}(undef); 576.677 ns (10 allocations: 512 bytes) allocate ten times as much as this: @btime MVector{6, Float64}(undef); 4.148 ns (1 allocation: 64 bytes) I …

[Next page](https://discourse.julialang.org/tag/staticarrays/620.md?match_all_tags=true&page=1&tags%5B%5D=staticarrays)
