Is it possible to reduce the allocation in replace missing value?

There some things that are a little strange in this MWE.

  1. The vector A simply cannot have -Inf, Inf, or NaN. So you are always just testing how a pass that do not replace anything should go.
  2. The 0 literal is interpreted as Int (which is an alias for either Int32 or Int64 in your system), so there is probably an automatic conversion (maybe optimized away) to the 0.0, otherwise replace! should not work, as it changes the vector in place and you cannot save a Int in a Vector{Float64} without converting.
  3. rand returns a Vector{Float64} such type simply cannot have missing values, another red flag is the number of allocations, there is no reason for replace! to allocate anything, I believe what is happening here is that something inside replace! became type-unstable because of the strange types in the pairs, ideally all pairs should have a Float64 in the right and the left side, unless your vector is a Vector{Float64,Missing}.
1 Like