AxisArrayConversion

AxisArrayConversion.SimpleAxisArrayType
SimpleAxisArray

Simple AxisArray like type. Meant for demonstrations, testing and as an implementing examples.

This function is part of the public API and subject to SemVer guarantees.

AxisArrayConversion.check_consistencyMethod
check_consistency(axis_array_like)

Check that a NamedTuple represents an axis array like object. Also accepts AbstractArray inputs, which means a noop.

Examples

julia> using AxisArrayConversion: check_consistency

julia> check_consistency((axs=(1:2,), values=[1,2]))
ERROR: ArgumentError: Unexpected properties.
Expected exactly two properties `axes`, `values`
Got: `propertynames(nt) = (:axs, :values)
[...]


julia> check_consistency((axes=(1:2,), values=[1 2; 3 4]))
ERROR: ArgumentError: Inconsistent number of dimensions.
Expected: length(nt.axes) == ndims(nt.values)
Got: length(nt.axes)  = 1
ndims(nt.values) = 2
[...]

julia> check_consistency((axes=(1:2,), values=[1,2,3]))
ERROR: ArgumentError: Inconsistent size.
Expected: map(length, Tuple(nt.axes)) == size(nt.values)
Got: map(length, Tuple(nt.axes)) = (2,)
Got: size(nt.values) = (3,)
[...]

julia> check_consistency((axes=(1:2,), values=[1,2])) # works

julia> check_consistency([1,2,3]) # noop for AbstractArray

This function is part of the public API and subject to SemVer guarantees.

AxisArrayConversion.from_namedtupleMethod
from_namedtuple(::Type{T}, nt::NamedTuple)

Construct an instance of T from a NamedTuplent with propertynames (:axes, :values).

This function is part of the public API and subject to SemVer guarantees.

AxisArrayConversion.make_axissymbolsMethod
make_axissymbols(::Val{dim})::NTuple{dim, Symbol}

Create default names for dim many axes.

This function is considered private and may silently change or be removed.

AxisArrayConversion.name_axesMethod
name_axes(axes)::NamedTuple

Add names to axes or return them as is, if they already have names.

Examples

julia> using AxisArrayConversion: name_axes

julia> name_axes((1:3, ["a", "b"]))
(x1 = 1:3, x2 = ["a", "b"])

julia> name_axes((a=1:3, b=["a", "b"]))
(a = 1:3, b = ["a", "b"])

This function is part of the public API and subject to SemVer guarantees.

AxisArrayConversion.namedtupleFunction
namedtuple(arr)::NamedTuple{(:axes, :values)}

Create a NamedTuple from an array arr with axis data.

julia> using AxisArrayConversion: namedtuple

julia> namedtuple([1 2; 3 4])
(axes = (x1 = Base.OneTo(2), x2 = Base.OneTo(2)), values = [1 2; 3 4])

This function is part of the public API and subject to SemVer guarantees.

AxisArrayConversion.roottypeMethod
roottype(::Type{T})

Construct a more general variant of an AxisArray like type T. Typically by stripping all type parameters.

julia> using AxisArrayConversion: roottype

julia> roottype(Vector{Int})
Array

julia> roottype(typeof((a=1, b=2)))
NamedTuple

This function is part of the public API and subject to SemVer guarantees.

AxisArrayConversion.toMethod
to(SomeArray, ::OtherArray)::SomeArray

Construct an instance of SomeArray from an instance of OtherArray.

Examples

julia> using AxisArrayConversion: SimpleAxisArray, to

julia> to(SimpleAxisArray, (axes=(a=1:3,), values=[10,20,30]))
SimpleAxisArray(axes = (a = 1:3,), values = [10, 20, 30])

julia> arr = to(SimpleAxisArray, (axes=(a=1:3,), values=[10,20,30]))
SimpleAxisArray(axes = (a = 1:3,), values = [10, 20, 30])

julia> to(NamedTuple, arr)
(axes = (a = 1:3,), values = [10, 20, 30])

julia> to(NamedTuple, [1 2; 3 4])
(axes = (x1 = Base.OneTo(2), x2 = Base.OneTo(2)), values = [1 2; 3 4])

This function should not be overloaded. Instead namedtuple and from_namedtuple should be overloaded.

This function is part of the public API and subject to SemVer guarantees.