Skip to content

jw3126/AxisArrayConversion.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages