From 41669cd8dfeadce35db0c4e07ac7afe5d10fb957 Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Mon, 4 Jan 2021 11:56:17 +0100 Subject: [PATCH] Stop using LinearAlgebra.copy_oftype (#626) 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. --- src/scalarstats.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scalarstats.jl b/src/scalarstats.jl index c5e0bfee9..d00b91685 100644 --- a/src/scalarstats.jl +++ b/src/scalarstats.jl @@ -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)