You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it's still worth using similar because of the mutability argument. If the semantics of similar are broken for e.g. banded matrices, that's where they should be fixed.
julia>using BenchmarkTools
julia> A =ones(Bool, 100, 100);
julia>f(A) =similar(A, Float64)
f (generic function with 1 method)
julia>g(A) =1.0.* A
g (generic function with 1 method)
julia>@btimef($A);
342.742 ns (2 allocations:78.17 KiB)
julia>@btimeg($A);
13.408 μs (2 allocations:78.17 KiB)
In these two spots, I use
similar
to preallocate a structured Jacobian / Hessian.https://github.com/gdalle/DifferentiationInterface.jl/blob/88c48c1a66709bd1af84a378de06091092fbafd5/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian.jl#L176
https://github.com/gdalle/DifferentiationInterface.jl/blob/88c48c1a66709bd1af84a378de06091092fbafd5/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/hessian.jl#L125
Pros:
eltype
Cons:
I think it's still worth using
similar
because of the mutability argument. If the semantics ofsimilar
are broken for e.g. banded matrices, that's where they should be fixed.Related:
The text was updated successfully, but these errors were encountered: