diff --git a/src/axis.jl b/src/axis.jl index 3dfa8e49..0de458aa 100644 --- a/src/axis.jl +++ b/src/axis.jl @@ -1,3 +1,9 @@ +""" + AbstractAxis{IdxMap} + +Abstract supertype for axis metadata used by `ComponentArray` to map component +names and shaped views onto positions in the wrapped array. +""" abstract type AbstractAxis{IdxMap} end @inline indexmap(::AbstractAxis{IdxMap}) where {IdxMap} = IdxMap @@ -53,6 +59,22 @@ function Axis(symbols::Union{AbstractVector{Symbol}, NTuple{N, Symbol}}) where { end Axis(symbols::Vararg{Symbol}) = Axis(symbols) +""" + FlatAxis() + +Axis marker for an unnamed, flat dimension of a `ComponentArray`. + +# Examples + +```jldoctest +julia> using ComponentArrays + +julia> x = ComponentArray(reshape(1:4, 2, 2), Axis(row = 1:2), FlatAxis()); + +julia> getaxes(x) +(Axis(row = 1:2,), FlatAxis()) +``` +""" const FlatAxis = Axis{NamedTuple()} const NullorFlatAxis = Union{NullAxis, FlatAxis} @@ -67,6 +89,23 @@ struct ShapedAxis{Shape} <: AbstractAxis{nothing} end # ShapedAxis(::Tuple{<:Int}) = FlatAxis() Base.length(::ShapedAxis{Shape}) where {Shape} = prod(Shape) +""" + Shaped1DAxis(shape::Tuple{<:Integer}) + +Axis marker for a one-dimensional array component. `ShapedAxis((n,))` returns a +`Shaped1DAxis` so vector-valued components keep their one-dimensional shape. + +# Examples + +```jldoctest +julia> using ComponentArrays + +julia> ax = Shaped1DAxis((3,)); + +julia> size(ax) +(3,) +``` +""" struct Shaped1DAxis{Shape} <: AbstractAxis{nothing} end ShapedAxis(shape::Tuple{<:Int}) = Shaped1DAxis{shape}() Shaped1DAxis(shape::Tuple{<:Int}) = Shaped1DAxis{shape}() diff --git a/src/compat/static_arrays.jl b/src/compat/static_arrays.jl index e984361d..cf36fe3b 100644 --- a/src/compat/static_arrays.jl +++ b/src/compat/static_arrays.jl @@ -16,6 +16,31 @@ _maybe_SArray(x, vals...) = x return :(_maybe_SArray(ca.$s, $(Val(length(comp_ind.idx))), $(comp_ind.ax))) end +""" + @static_unpack lhs = rhs + +Unpack fields from a `ComponentVector`, converting plain array fields to +`StaticArrays` values when their sizes are known from the component axes. +Scalar fields and nested `ComponentArray`s are returned unchanged. + +# Examples + +```jldoctest +julia> using ComponentArrays, StaticArrays + +julia> x = ComponentVector(a = 5, b = [4, 1]); + +julia> @static_unpack a, b = x; + +julia> a +5 + +julia> b +2-element SVector{2, Int64} with indices SOneTo(2): + 4 + 1 +``` +""" macro static_unpack(expr) @assert expr.head == :(=) "Unpack expression must have an equals sign for assignment" lhs, rhs = expr.args diff --git a/src/utils.jl b/src/utils.jl index 579dd35b..e10768d6 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,5 +1,18 @@ @deprecate fastindices(i::Tuple) Val.(i) @deprecate fastindices(i...) Val.((i...,)) +@doc """ + fastindices(i...) + fastindices(i::Tuple) + +Deprecated helper for converting symbolic indices to `Val` wrappers. Use `Val` +constructors directly instead. + +# Examples + +```julia +Val.((:a, :b)) +``` +""" fastindices # Make a Val if input isn't already one toval(x::Val) = x diff --git a/test/Autodiff/Project.toml b/test/Autodiff/Project.toml index e603f4a8..2e885ea8 100644 --- a/test/Autodiff/Project.toml +++ b/test/Autodiff/Project.toml @@ -22,7 +22,7 @@ Mooncake = "0.5.26" Optimisers = "0.4.7" ReverseDiff = "1.16.2" SafeTestsets = "0.0.1, 0.1" -SciMLTesting = "1" +SciMLTesting = "2.1" Test = "1" Tracker = "0.2.38" Zygote = "0.7.10" diff --git a/test/Downstream/Project.toml b/test/Downstream/Project.toml index 9698fa05..4daf9825 100644 --- a/test/Downstream/Project.toml +++ b/test/Downstream/Project.toml @@ -13,6 +13,6 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] LabelledArrays = "1.17.0" SafeTestsets = "0.0.1, 0.1" -SciMLTesting = "1" +SciMLTesting = "2.1" Test = "1" Unitful = "1.27.0" diff --git a/test/GPU/Project.toml b/test/GPU/Project.toml index e34a43b4..211b26db 100644 --- a/test/GPU/Project.toml +++ b/test/GPU/Project.toml @@ -9,5 +9,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] JLArrays = "0.3.0" SafeTestsets = "0.0.1, 0.1" -SciMLTesting = "1" +SciMLTesting = "2.1" Test = "1" diff --git a/test/Project.toml b/test/Project.toml index b32ca9e4..f602a13b 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -25,7 +25,7 @@ InvertedIndices = "1.3.1" LabelledArrays = "1.19.0" OffsetArrays = "1.17.0" SafeTestsets = "0.0.1, 0.1" -SciMLTesting = "1" +SciMLTesting = "2.1" StaticArrays = "1.9.18" Test = "1" Tracker = "0.2.38" diff --git a/test/Reactant/Project.toml b/test/Reactant/Project.toml index 1fc0b70a..6c98d3b9 100644 --- a/test/Reactant/Project.toml +++ b/test/Reactant/Project.toml @@ -8,5 +8,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] Reactant = "0.2.198" SafeTestsets = "0.0.1, 0.1" -SciMLTesting = "1" +SciMLTesting = "2.1" Test = "1" diff --git a/test/qa/Project.toml b/test/qa/Project.toml index 5f35553b..649e8823 100644 --- a/test/qa/Project.toml +++ b/test/qa/Project.toml @@ -8,5 +8,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] JET = "0.9, 0.10, 0.11" SafeTestsets = "0.0.1, 0.1" -SciMLTesting = "1.6" +SciMLTesting = "2.1" Test = "1" diff --git a/test/qa/qa.jl b/test/qa/qa.jl index 43d0c166..b3255e84 100644 --- a/test/qa/qa.jl +++ b/test/qa/qa.jl @@ -4,6 +4,7 @@ using JET run_qa( ComponentArrays; explicit_imports = true, + api_docs_kwargs = (; rendered = true), # ComponentArrays has real method ambiguities and unbound type parameters in its # vcat/hcat/getindex/Axis overloads; these are long-standing design realities, not # tracked-broken placeholders, so disable the sub-checks rather than fail.