Skip to content

Commit

Permalink
add copyto! and unsafe_copyto! (#448)
Browse files Browse the repository at this point in the history
* add copyto! and unsafe_copyto!

* make a copy to fix interaction with new lazy adjoint
  • Loading branch information
fredrikekre committed Jan 9, 2018
1 parent d0f2551 commit 8d6689e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `unshift!` and `shift!` are now `pushfirst!` and `popfirst!` ([#25100]).

* `copy!` and `unsafe_copy!` are now `copyto!` and `unsafe_copyto!` ([#24808]).

* `ipermute!` is now `invpermute!` ([#25168]).

## New macros
Expand Down Expand Up @@ -435,4 +437,4 @@ includes this fix. Find the minimum version from there.
[#25162]: https://github.com/JuliaLang/julia/issues/25162
[#25165]: https://github.com/JuliaLang/julia/issues/25165
[#25168]: https://github.com/JuliaLang/julia/issues/25168
[#25113]: https://github.com/JuliaLang/julia/issues/25113
[#25113]: https://github.com/JuliaLang/julia/issues/25113
7 changes: 7 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,13 @@ end
replace(s, first(pat_rep), last(pat_rep), count)
end

# 0.7.0-DEV.3057
@static if !isdefined(Base, :copyto!)
const copyto! = Base.copy!
const unsafe_copyto! = Base.unsafe_copy!
export copyto!, unsafe_copyto!
end

@static if VERSION < v"0.7.0-DEV.3025"
import Base: convert, ndims, getindex, size, length, eltype,
start, next, done, first, last
Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ no_specialize_kw2(@nospecialize(x::Integer=0)) = sin(2)

# 0.7
let M = [1 + 2im 3 + 4im; 5 + 6im 7 + 8im],
M2 = adjoint(M),
M2 = adjoint(copy(M)),
Mc = [1 - 2im 5 - 6im; 3 - 4im 7 - 8im]

@test adjoint(M) == Mc
Expand Down Expand Up @@ -1069,6 +1069,14 @@ let coolvec = [1,2,3]
@test popfirst!(coolvec) == 0
end

# 0.7.0-DEV.3057
let A = [0, 0, 0], B = [1, 2, 3]
@test copyto!(A, B) === A == B
end
let A = [0, 0, 0], B = [1, 2, 3]
@test unsafe_copyto!(A, 2, B, 1, 1) === A == [0, 1, 0]
end

# 0.7.0-DEV.3173
@test invpermute!(permute!([1, 2], 2:-1:1), 2:-1:1) == [1, 2]

Expand Down

0 comments on commit 8d6689e

Please sign in to comment.