Spurious memory allocations within function

You forgot to add where {T} after your function signature. The signature should be

function f3(::Type{T}, M::Matrix{T}, n::Int64, k::Int64) where {T}

(though frankly, you don’t need ::Type{T}, since T is already in Matrix{T}).

You may have to restart your REPL to see the effect, though.

Also, don’t do this:

Remove the type assertion, just write V = zeros(T, n).

1 Like