Add static dimensions to `FixedSizeArray` via `FixedSizeArrayDims` #213
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
giordano
Supersedes #210, which added
StaticSizeArrayas a separate sibling type. Here the two are one type.Design
FixedSizeArray{T,N,Mem}is now an alias forFixedSizeArrayDims{T,N,NTuple{N,Int},Mem}. The new structFixedSizeArrayDims{T,N,D,Mem<:DenseVector{T}}(public, not exported) holds the memory backend and a tupledims::Dof dimensions. Each dimension can be dynamic, anIntstored in the array, or static, a compile-time constant which is part of the type and takes no space in the array: aValfromBase, or aStaticIntfrom 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 andVectorelement types declared with it are unaffected.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 twoIntdimensions, whileFixedSizeArrayDims{Float64}(undef, (Val(2), 3))keeps the static one.ValandStaticIntdimensions behave the same and can be mixed, e.g.(Val(2), static(3), n). They are kept as given, soTuple{Val{2}, Int}andTuple{StaticInt{2}, Int}are different dimensions types. AValof anotherIntegertype is converted to aValof anInt, and aValof anything else, e.g.Val(:a), throws anArgumentError.What is included
Construction:
undefconstructors, converting constructors andcollect_aswith an explicit dimensions type, andFixedSizeArrays.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),stridesandlengthfold to constants for static dimensions, and out-of-bounds accesses throwLightBoundsErrors.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,vecand indexing with ranges or colons returnFixedSizeArrays with all dimensions dynamic, so that the result type does not depend on the value of the shape.Extensions:
Static.jl: enables
StaticIntdimensions. It is a weak dependency, so loading FixedSizeArrays.jl stays fast;Valdimensions need no extension;StaticArrayInterface.jl: static sizes and strides for StrideArraysCore/LoopVectorization/Polyester, with
Valdimensions reported asStaticInts, anddeviceof the memory backend, also for plainFixedSizeArrays;Adapt.jl: arrays with static dimensions have their memory backend adapted and are wrapped again, e.g.
adapt(CuArray, a)is aFixedSizeArrayDimsbacked by aCuVector;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
FixedSizeArrayandFixedSizeArrayDimsagainstArray,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 withStaticInts;a section on
wrap.Changes for
FixedSizeArrayFixedSizeArrayis no longer the name of astruct:Base.typename(FixedSizeArray)isFixedSizeArrayDims.FixedSizeArray{Int, -1}now errors when the type is formed, because it would buildNTuple{-1,Int}. Onecollect_astest was adjusted.Cartesian
getindex/setindex!with severalIntindices 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 withsimilar(parent(a), T, (n,))instead of rebuilding the type fromMem.FixedSizeArrays.wrapnow accepts at most one:dimension, also forFixedSizeArrays.fill!loops over the memory backend (#200), so it vectorizes on Julia v1.13 and later.Testing
test/static_dims.jlcovers construction, indexing,similar/copy/fill!/copyto!/reshape, broadcasting and StaticArrayInterface for every memory backend, for bothValandStaticIntdimensions, and for mixes of the two.New FileCheck tests check that, with both
ValandStaticIntdimensions:sizein 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