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

Stop using LinearAlgebra.copy_oftype #626

Merged
merged 1 commit into from
Jan 4, 2021
Merged

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.
@@ -274,7 +274,7 @@ function mad(x; center=nothing, normalize::Union{Bool, Nothing}=nothing, constan
# Knowing the eltype allows allocating a single array able to hold both original values
# 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.

None yet

2 participants