Skip to content

Conversation

@nalimilan
Copy link
Member

This undocumented function does not actually ensure that the result is mutable.
Use the same approach as Base.copymutable, which relies only on public API.

This avoids breakage due to JuliaLang/julia#28956 (see this log).

This undocumented function does not actually ensure that the result is mutable.
Use the same approach as `Base.copymutable`, which relies only on public API.
# and differences from the center, instead of two arrays
S = isconcretetype(T) ? promote_type(T, typeof(middle(zero(T)))) : T
x2 = x isa AbstractArray ? LinearAlgebra.copy_oftype(x, S) : collect(S, x)
x2 = x isa AbstractArray ? copyto!(similar(x, S), x) : collect(S, x)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this change assumes that when S == T, copyto!(similar(x, S), x) is as fast as copy(x). Not sure whether that holds: I could add another branch to ensure that this simple case is fast.

@andreasnoack
Copy link
Member

I'm mainly curious about what motivated this change. Is it worth adding as a test case?

@nalimilan
Copy link
Member Author

That's mainly to avoid breakage if JuliaLang/julia#28956 gets merged. There's no hurry. But in general it sounds better to avoid depending on unexported and undocumented functions from the stdlib.

@andreasnoack andreasnoack merged commit 41669cd into master Jan 4, 2021
@andreasnoack andreasnoack deleted the nl/copy_oftype branch January 4, 2021 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants