-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
add Future.copy! function #25144
add Future.copy! function #25144
Conversation
base/future.jl
Outdated
|
||
function copy!(dst::AbstractArray, src::AbstractArray) | ||
size(dst) == size(src) || throw(ArgumentError( | ||
"arrays must have the same dimension for copy! (condiser using `copyto!`)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misspelling of consider. And isn't it rather "same size" than "same dimension"?
FWIW I like |
I like |
I also definitely prefer |
f906d5c
to
7496c0e
Compare
So I hadn't thought about it earlier, but making |
I will merge some day next week, if no objection and no one beats me to it. |
stdlib/Future/src/Future.jl
Outdated
|
||
function copy!(dst::AbstractArray, src::AbstractArray) | ||
size(dst) == size(src) || throw(ArgumentError( | ||
"arrays must have the same dimension for copy! (condiser using `copyto!`)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider is still misspelled.
7496c0e
to
6b19fff
Compare
This implements the suggestion proposed in #24808 to have
Future.copy!
available in Base right now, which will be moved toBase
for 1.0. Unfortunately, the nameFuture
is already taken, so I temporarily named itNext
till a decision is taken for the name.I implemented this new version of
copy!
in a conservative way:copy!(a, b)
works only ifa
andb
are in the same abstract hierachy, i.e arrays with arrays, sets with sets etc. We could be even more strict by requiringa
andb
to be of the same type, but that doesn't seem useful. One caveat is that we don't necessarily havea==b
after the call, because for example[1, 2] != 1:2
orSet(1) != BitSet(1)
. But my understanding is that we would like to have these examples be equal.A less conservative approach would be to allow copying any iterable into the destination, but I feel this is much more debatable, as in this case there is no way we will have equality of
a
andb
after the call, e.g. incopy!(rand(2, 3), rand(3, 2))
, the 2 arguments don't have the same shape. Or incopy!(Set(1), rand(2, 3))
we don't even have the same kind of collection. My feeling is that this use-case is kind of in betweencopy!
andcopyto!
, so I would prefer to not rush with this one and take the time to think about it. In the meantime, it's seems enough to suggest simple alternatives, likeunion!(empty!(Set(1)), rand(2, 3))
, orcopyto!(rand(2, 3), rand(3, 2))
.