YAXArrays.jl icon indicating copy to clipboard operation
YAXArrays.jl copied to clipboard

Request for clarification: rebuilding/copying YAXArray structure?

Open ConnectedSystems opened this issue 1 year ago • 0 comments

In this section of the docs on handling axes names it is stated:

WARNING To get the axes of a YAXArray use the dims function instead of the caxes function

and

INFO Also, use DD.rebuild(ax, values) instead of axcopy(ax, values) to copy an axes with the same name but different values.

There are two issues.

First, the indicated functions either do not exist or are not exported:

using YAXArrays

yax = YAXArray(ones(10,10))

dims(yax)
# ERROR: UndefVarError: `dims` not defined
# Stacktrace:
# [1] top-level scope
#   @ REPL[26]:1

# This works
YAXArrays.DD.dims(yax)
# ↓ Dim_1 Sampled{Int64} Base.OneTo(10) ForwardOrdered Regular Points,
# → Dim_2 Sampled{Int64} Base.OneTo(10) ForwardOrdered Regular Points

Second, it is not clear what is expected in place of ax. At first glance, it appears it should be the output from YAXArrays.DD.dims(), but that doesn't seem to be the case:

YAXArrays.DD.rebuild(YAXArrays.DD.dims(yax), rand(10,10))
# ERROR: MethodError: no method matching rebuild(::Tuple{Dim{…}, Dim{…}}, ::Matrix{Float64})
# Closest candidates are:
#   rebuild(::DimensionalData.AbstractDimStack, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)
#    @ DimensionalData C:\Users\tiwanaga\.julia\packages\DimensionalData\BoJag\src\stack\stack.jl:61
#   rebuild(::DimensionalData.AbstractDimStack, ::Any, ::Any, ::Any, ::Any, ::Any)
#    @ DimensionalData C:\Users\tiwanaga\.julia\packages\DimensionalData\BoJag\src\stack\stack.jl:61
#   rebuild(::DimensionalData.AbstractDimStack, ::Any, ::Any, ::Any, ::Any)
#    @ DimensionalData C:\Users\tiwanaga\.julia\packages\DimensionalData\BoJag\src\stack\stack.jl:61

What I'm actually trying to do is create a copy of the YAXArray structure, holding Int64 instead of Floats. i.e., same dims/axes, but the values are different and of a different type.

yax = YAXArray(ones(10,10))
# How do I convert to YAXArray{Int64, 2, Matrix{Int64}, ...} ?

ConnectedSystems avatar Jul 11 '24 23:07 ConnectedSystems