← Back to Pull requests

Add static dimensions to `FixedSizeArray` via `FixedSizeArrayDims` #213

Closed
unknown closed this pull request without merging on Oct 20, 2026 20:56 UTC
View on GitHub
unknown unknown commented on Oct 15, 2026 08:58 UTC
Author

Supersedes #210, which added StaticSizeArray as a separate sibling type. Here the two are one type.

Design

FixedSizeArray{T,N,Mem} is now an alias for FixedSizeArrayDims{T,N,NTuple{N,Int},Mem}. The new struct FixedSizeArrayDims{T,N,D,Mem<:DenseVector{T}} (public, not exported) holds the memory backend and a tuple dims::D of dimensions. Each dimension can be dynamic, an Int stored in the array, or static, a compile-time constant which is part of the type and takes no space in the array: a Val from Base, or a StaticInt from Static.jl. E.g. (Val(5), Val(4), n) or (static(5), static(4), n).

Julia has no default type parameters, so the struct needs a name of its own for the three-parameter FixedSizeArray{T,N,Mem} to stay a concrete type. It has the same layout as before, so struct fields and Vector element types declared with it are unaffected.

julia> using FixedSizeArrays; using FixedSizeArrays: FixedSizeArrayDims

julia> nelements = 3;

julia> u = FixedSizeArrayDims{Float64}(undef, (Val(5), Val(4), nelements));

julia> size(u, 1)  # a compile-time constant
5

julia> a = FixedSizeArrayDims{Float64, 2, Tuple{Val{2}, Int}}([1 2 3; 4 5 6]);  # copy from a matrix

julia> v = collect(1.0:12.0);

julia> c = FixedSizeArrays.wrap(FixedSizeArrayDims, v, (Val(2), Val(3), :));  # `:` computed from the length of `v`

When the type of the array fixes the dimensions type, the dimensions given to a constructor are converted to it: FixedSizeArray{Float64}(undef, (Val(2), 3)) has two Int dimensions, while FixedSizeArrayDims{Float64}(undef, (Val(2), 3)) keeps the static one.

Val and StaticInt dimensions behave the same and can be mixed, e.g. (Val(2), static(3), n). They are kept as given, so Tuple{Val{2}, Int} and Tuple{StaticInt{2}, Int} are different dimensions types. A Val of another Integer type is converted to a Val of an Int, and a Val of anything else, e.g. Val(:a), throws an ArgumentError.

What is included

Construction: undef constructors, converting constructors and collect_as with an explicit dimensions type, and FixedSizeArrays.wrap(FixedSizeArrayDims, parent, dims).
Indexing: Cartesian indexing computes the linear index as a sum of strided terms; a stride is a constant as long as the dimensions before it are static. size(a, d), strides and length fold to constants for static dimensions, and out-of-bounds accesses throw LightBoundsErrors.
Which operations keep the static dimensions:
kept: similar(a), similar(a, T), similar(typeof(a), size), copy, and in-place operations (copyto!, fill!, .=, rand!);
dropped: similar(a, T, size), out-of-place broadcasting, map, reductions, reshape, vec and indexing with ranges or colons return FixedSizeArrays with all dimensions dynamic, so that the result type does not depend on the value of the shape.
Extensions:
Static.jl: enables StaticInt dimensions. It is a weak dependency, so loading FixedSizeArrays.jl stays fast; Val dimensions need no extension;
StaticArrayInterface.jl: static sizes and strides for StrideArraysCore/LoopVectorization/Polyester, with Val dimensions reported as StaticInts, and device of the memory backend, also for plain FixedSizeArrays;
Adapt.jl: arrays with static dimensions have their memory backend adapted and are wrapped again, e.g. adapt(CuArray, a) is a FixedSizeArrayDims backed by a CuVector; FixedSizeArrays are converted as a whole, as before;
MPI.jl and Random: now apply to arrays with static dimensions too.
Docs: the README and the manual now present the two kinds of arrays:
a "Which one should I use?" section;
a comparison section covering both FixedSizeArray and FixedSizeArrayDims against Array, MArray/SArray, HybridArrays and StrideArraysCore;
a usage section on static dimensions: construction, and which operations keep them. The examples use Vals, with one example showing the same array with StaticInts;
a section on wrap.

Changes for FixedSizeArray

FixedSizeArray is no longer the name of a struct: Base.typename(FixedSizeArray) is FixedSizeArrayDims.
FixedSizeArray{Int, -1} now errors when the type is formed, because it would build NTuple{-1,Int}. One collect_as test was adjusted.
Cartesian getindex/setindex! with several Int indices use the new strided linear index computation for all arrays, not only those with static dimensions.
similar(a, T, size) now creates the memory backend with similar(parent(a), T, (n,)) instead of rebuilding the type from Mem.
FixedSizeArrays.wrap now accepts at most one : dimension, also for FixedSizeArrays.
fill! loops over the memory backend (#200), so it vectorizes on Julia v1.13 and later.

Testing

test/static_dims.jl covers construction, indexing, similar/copy/fill!/copyto!/reshape, broadcasting and StaticArrayInterface for every memory backend, for both Val and StaticInt dimensions, and for mixes of the two.
New FileCheck tests check that, with both Val and StaticInt dimensions:
size in a static dimension is constant-folded;
Cartesian indexing has exactly one bounds check, none under @inbounds, and uses the static sizes;
in-place broadcasting and fill! have no bounds checks and vectorize.
MPI and Adapt tests cover arrays with static dimensions.
CI passes on Julia 1.10, 1.11, 1, pre and nightly, with and without --check-bounds=yes, and the docs build with doctests is clean.

🤖 Generated with Claude Code

Diff: 650 lines (+487 / -163) across 8 files Reviewer: giordano Review duration: 7918m
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #213"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 52% (MEDIUM) · Higher = larger blast radius
52%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 20.5% · Safe to merge
20.5%