AxisArrayConversion.jl

Author jw3126
Popularity
1 Star
Updated Last
2 Years Ago
Started In
December 2020

AxisArrayConversion

Stable Dev Build Status Coverage

AxisArrayConversion

AxisArrayConversion.jl allows converting between AxisArrays.jl like packages.

Supporting more arrays

Conversions between two array types is provided by using the path

MyArray -> NamedTuple -> OtherArray

This has multiple advantages:

  • For N array types, only 2N methods must be implemented.
  • Conversion can be implemented between packages that don't know about each other.

In order to support MyArray, the following must be implemented:

function AxisArrayConversion.namedtuple(arr::MyArray)
    ...
    return (axes=..., values=...)
end

function AxisArrayConversion.from_namedtuple(::Type{MyArray}, nt::NamedTuple)
    ... = nt.axes
    ... = nt.values
    return MyArray(...)
end

And now any fancy conversion should work

using MyArrays, OtherArrays
using AxisArrayConversion: to
using Test

ma = MyArrays(...)
oa = to(OtherArray, ma)
@test oa isa OtherArrays.OtherArray
@test ma == to(MyArray, oa)

Required Packages

Used By Packages

No packages found.