Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/axis.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}

Expand All @@ -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}()
Expand Down
25 changes: 25 additions & 0 deletions src/compat/static_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/Autodiff/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion test/Downstream/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion test/GPU/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/Reactant/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion test/qa/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions test/qa/qa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading