4949Base. deepcopy (x:: ComponentArray ) = ComponentArray (deepcopy (getdata (x)), getaxes (x))
5050
5151
52- Base. convert (:: Type{CA} , A:: AbstractArray ) where CA<: ComponentArray = ComponentArray (A, getaxes (CA))
53- Base. convert (:: Type{CA} , x:: ComponentArray ) where CA<: ComponentArray = ComponentArray (getdata (x), getaxes (CA))
52+ function Base. convert (:: Type{ComponentArray{T,N,AA,Ax}} , A:: AbstractArray ) where {T,N,AA,Ax}
53+ return ComponentArray {Ax} (A)
54+ end
55+ function Base. convert (:: Type{ComponentArray{T,N,A,Ax1}} , x:: ComponentArray{T,N,A,Ax2} ) where {T,N,A,Ax1,Ax2}
56+ return x
57+ end
58+ function Base. convert (:: Type{ComponentArray{T1,N,A1,Ax1}} , x:: ComponentArray{T2,N,A2,Ax2} ) where {T1,T2,N,A1,A2,Ax1,Ax2}
59+ return T1 .(x)
60+ end
5461Base. convert (:: Type{<:Array} , x:: ComponentArray ) = convert (Array, getdata (x))
5562
5663
@@ -78,20 +85,14 @@ Base.NamedTuple(x::ComponentVector) = _namedtuple(x)
7885
7986
8087# # AbstractAxis conversion and promotion
81- # Base.convert(TypeAx::Type{<:Ax1}, ::Ax2) where {Ax1<:AbstractAxis,Ax2<:AbstractAxis} = promote_type(TypeAx,Ax2)()
82- # Base.convert(::Type{Ax1}, ax::Ax2) where {Ax1<:AbstractAxis,Ax2<:AbstractAxis} = Ax1()
83-
84- # Could not figure out promote_rule for these.
85- Base. promote (ax:: AbstractAxis , :: NullAxis ) = ax
86- Base. promote (ax:: AbstractAxis , :: FlatAxis ) = ax
87- Base. promote (:: NullAxis , ax:: AbstractAxis ) = ax
88- Base. promote (:: FlatAxis , ax:: AbstractAxis ) = ax
89- Base. promote (:: FlatAxis , :: NullAxis ) = FlatAxis ()
90- Base. promote (:: NullAxis , :: FlatAxis ) = FlatAxis ()
91- Base. promote (:: FlatAxis , :: FlatAxis ) = FlatAxis ()
92- Base. promote (:: NullAxis , :: NullAxis ) = NullAxis ()
93- Base. promote (ax:: Ax , :: Ax ) where {Ax<: AbstractAxis } = ax
94- function Base. promote (ax1:: AbstractAxis , ax2:: AbstractAxis )
95- @warn " Tried to promote dissimilar axes of types $(typeof (ax1)) and $(typeof (ax2)) . Falling back to FlatAxis."
96- return FlatAxis ()
97- end
88+ Base. convert (:: Type{Ax} , :: AbstractAxis ) where {Ax<: AbstractAxis } = Ax ()
89+ Base. convert (:: Type{Ax} , ax:: AbstractAxis ) where {Ax<: VarAxes } = convert .(typeof .(getaxes (Ax)), (ax,))
90+
91+ Base. promote_rule (AA:: Type{<:Axis} , :: Type{<:NullAxis} ) = AA
92+ Base. promote_rule (AA:: Type{<:Axis} , :: Type{<:FlatAxis} ) = AA
93+ Base. promote_rule (FA:: Type{FlatAxis} , :: Type{NullAxis} ) = FA
94+ Base. promote_rule (FA:: Type{FlatAxis} , :: Type{FlatAxis} ) = FA
95+ Base. promote_rule (NA:: Type{NullAxis} , :: Type{NullAxis} ) = NA
96+ function Base. promote_rule (A1:: Type{<:VarAxes} , A2:: Type{<:VarAxes} )
97+ ax = first .(promote .(getaxes (A1), getaxes (A2))) |> typeof
98+ end
0 commit comments