diff --git a/src/similar_convert_copy.jl b/src/similar_convert_copy.jl index d8cecc02..1a43265d 100644 --- a/src/similar_convert_copy.jl +++ b/src/similar_convert_copy.jl @@ -55,6 +55,12 @@ end function Base.convert(::Type{ComponentArray{T1,N,A1,Ax1}}, x::ComponentArray{T2,N,A2,Ax2}) where {T1,T2,N,A1,A2,Ax1,Ax2} return T1.(x) end +function Base.convert(::Type{ComponentArray{T,N,A1,Ax}}, x::ComponentArray{T,N,A2,Ax}) where {T,N,A1,A2,Ax} + return x +end +function Base.convert(::Type{ComponentArray{T,N,A,Ax}}, x::ComponentArray{T,N,A,Ax}) where {T,N,A,Ax} + return x +end Base.convert(T::Type{<:Array}, x::ComponentArray) = convert(T, getdata(x)) Base.convert(::Type{Cholesky{T1,Matrix{T1}}}, x::Cholesky{T2,<:ComponentArray}) where {T1,T2} = Cholesky(Matrix{T1}(x.factors), x.uplo, x.info) diff --git a/test/runtests.jl b/test/runtests.jl index da0acf1d..8b9c6c6b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using ComponentArrays using BenchmarkTools using ForwardDiff +using Tracker using InvertedIndices using LabelledArrays using LinearAlgebra @@ -400,6 +401,10 @@ end @test convert(Array, ca) == getdata(ca) @test convert(Matrix{Float32}, cmat) isa Matrix{Float32} + + tr = Tracker.param(ca) + ca_ = convert(typeof(ca), tr) + @test ca_.a == ca.a end @testset "Broadcasting" begin