diff --git a/Project.toml b/Project.toml index 0004d6d..5403c13 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Derive" uuid = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a" authors = ["ITensor developers and contributors"] -version = "0.3.2" +version = "0.3.3" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/abstractarrayinterface.jl b/src/abstractarrayinterface.jl index c6fb83a..c10b649 100644 --- a/src/abstractarrayinterface.jl +++ b/src/abstractarrayinterface.jl @@ -69,8 +69,7 @@ using BroadcastMapConversion: map_function, map_args @interface interface::AbstractArrayInterface function Base.copyto!( dest::AbstractArray, bc::Broadcast.Broadcasted ) - @interface interface map!(map_function(bc), dest, map_args(bc)...) - return dest + return @interface interface map!(map_function(bc), dest, map_args(bc)...) end # This is defined in this way so we can rely on the Broadcast logic @@ -121,12 +120,22 @@ end return @interface interface all(isreal, a) end -@interface ::AbstractArrayInterface function Base.permutedims!( +@interface interface::AbstractArrayInterface function Base.permutedims!( a_dest::AbstractArray, a_src::AbstractArray, perm ) - # TODO: Should this be `@interface interface ...`? - a_dest .= PermutedDimsArray(a_src, perm) - return a_dest + return @interface interface map!(identity, a_dest, PermutedDimsArray(a_src, perm)) +end + +@interface interface::AbstractArrayInterface function Base.copyto!( + a_dest::AbstractArray, a_src::AbstractArray +) + return @interface interface map!(identity, a_dest, a_src) +end + +@interface interface::AbstractArrayInterface function Base.copy!( + a_dest::AbstractArray, a_src::AbstractArray +) + return @interface interface map!(identity, a_dest, a_src) end using LinearAlgebra: LinearAlgebra diff --git a/src/traits.jl b/src/traits.jl index 8fffa37..d74d7a0 100644 --- a/src/traits.jl +++ b/src/traits.jl @@ -17,6 +17,8 @@ function derive(::Val{:AbstractArrayOps}, type) Base.similar(::$type, ::Type, ::Tuple{Vararg{Int}}) Base.similar(::$type, ::Type, ::Tuple{Base.OneTo,Vararg{Base.OneTo}}) Base.copy(::$type) + Base.copy!(::AbstractArray, ::$type) + Base.copyto!(::AbstractArray, ::$type) Base.map(::Any, ::$type...) Base.map!(::Any, ::AbstractArray, ::$type...) Base.mapreduce(::Any, ::Any, ::$type...; kwargs...) diff --git a/test/basics/test_basics.jl b/test/basics/test_basics.jl index 581c3ef..f408320 100644 --- a/test/basics/test_basics.jl +++ b/test/basics/test_basics.jl @@ -81,4 +81,12 @@ elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) @test isreal(a) @test sum(a) == 33 @test mapreduce(x -> 2x, +, a) == 66 + + a = SparseArrayDOK{elt}(2, 2) + a[1, 2] = 12 + b = similar(a) + copyto!(b, a) + @test b == a + @test b[1, 2] == 12 + @test storedlength(b) == 1 end