Make ` Array{T}(undef, ...) ` fill with a value for debugging?

OK, I feel really dumb. This can be written much more concisely like this:

using IRTools: @dynamo, IR, recurse!, xcall
using IRTools.Inner: Variable, Statement

_nan(T::Type{<:AbstractFloat}) = T(NaN)
_nan(T) = T(false)

debug_array(::Type{<:Array{T}}, ::UndefInitializer, dims...) where T = fill(_nan(T), dims...)

@dynamo function debug_array(a...)
    ir = IR(a...)
    ir === nothing && return
    recurse!(ir)
    return ir
end

It even works in the BandedMatrix case

5 Likes