Skip to content

Commit

Permalink
optimization of trivial MulAddMap evaluate!
Browse files Browse the repository at this point in the history
The (0,1) AttachDirichletMap is just (A,b,c) -> c .

So we can avoid `mul!` in this case (but keep the `copyto!` for type
stability when c is real but b and d=cache[2] are complex).

I believe this is safe regarding type stability since
`return_cache(::AttachDirichletMap)` uses an eager `Base.*` to create
the `cache`, it does not rely on this evaluate.
  • Loading branch information
Antoinemarteau committed Nov 10, 2024
1 parent d443e8c commit e206e08
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Arrays/AlgebraMaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function evaluate!(cache,k::MulAddMap,a,b,c)
setsize!(cache,size(c))
d = cache.array
copyto!(d,c)
iszero(k.α) && isone(k.β) && return d
mul!(d,a,b,k.α,k.β)
d
end
Expand Down
3 changes: 2 additions & 1 deletion src/Fields/ArrayBlocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ function evaluate!(cache,k::MulAddMap,a::ArrayBlock,b::ArrayBlock,c::ArrayBlock)
_setsize_mul!(c1,a,b)
d = evaluate!(c2,unwrap_cached_array,c1)
copyto!(d,c)
iszero(k.α) && isone(k.β) && return d
mul!(d,a,b,k.α,k.β)
d
end
Expand Down Expand Up @@ -1517,4 +1518,4 @@ function Base.show(io::IO,o::ArrayBlockView)
end

LinearAlgebra.diag(a::MatrixBlockView) = view(a.array.array, diag(a.block_map))
LinearAlgebra.diag(a::MatrixBlock) = view(a.array,diag(CartesianIndices(a.array)))
LinearAlgebra.diag(a::MatrixBlock) = view(a.array,diag(CartesianIndices(a.array)))

0 comments on commit e206e08

Please sign in to comment.