Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define copyto!/copy! #16

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Derive"
uuid = "a07dfc7f-7d04-4eb5-84cc-a97f051f655a"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.3.2"
version = "0.3.3"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
21 changes: 15 additions & 6 deletions src/abstractarrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
@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)...)

Check warning on line 72 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L72

Added line #L72 was not covered by tests
end

# This is defined in this way so we can rely on the Broadcast logic
Expand Down Expand Up @@ -121,12 +120,22 @@
return @interface interface all(isreal, a)
end

@interface ::AbstractArrayInterface function Base.permutedims!(
@interface interface::AbstractArrayInterface function Base.permutedims!(

Check warning on line 123 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L123

Added line #L123 was not covered by tests
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))

Check warning on line 126 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L126

Added line #L126 was not covered by tests
end

@interface interface::AbstractArrayInterface function Base.copyto!(

Check warning on line 129 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L129

Added line #L129 was not covered by tests
a_dest::AbstractArray, a_src::AbstractArray
)
return @interface interface map!(identity, a_dest, a_src)

Check warning on line 132 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L132

Added line #L132 was not covered by tests
end

@interface interface::AbstractArrayInterface function Base.copy!(

Check warning on line 135 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L135

Added line #L135 was not covered by tests
a_dest::AbstractArray, a_src::AbstractArray
)
return @interface interface map!(identity, a_dest, a_src)

Check warning on line 138 in src/abstractarrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/abstractarrayinterface.jl#L138

Added line #L138 was not covered by tests
end

using LinearAlgebra: LinearAlgebra
Expand Down
2 changes: 2 additions & 0 deletions src/traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
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)

Check warning on line 21 in src/traits.jl

View check run for this annotation

Codecov / codecov/patch

src/traits.jl#L20-L21

Added lines #L20 - L21 were not covered by tests
Base.map(::Any, ::$type...)
Base.map!(::Any, ::AbstractArray, ::$type...)
Base.mapreduce(::Any, ::Any, ::$type...; kwargs...)
Expand Down
8 changes: 8 additions & 0 deletions test/basics/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading