Skip to content

Commit

Permalink
Stop using LinearAlgebra.copy_oftype (#626)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nalimilan authored Jan 4, 2021
1 parent 11d91ab commit 41669cd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/scalarstats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,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)
c = center === nothing ? median!(x2) : center
if isconcretetype(T)
x2 .= abs.(x2 .- c)
Expand Down

0 comments on commit 41669cd

Please sign in to comment.