Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scalarstats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

c = center === nothing ? median!(x2) : center
if isconcretetype(T)
x2 .= abs.(x2 .- c)
Expand Down