Skip to content

Reuse ExpvCache workspaces in complex-t expv! - #315

Open
Kulraj69 wants to merge 1 commit into
SciML:masterfrom
Kulraj69:fix-complex-t-expv-cache
Open

Kulraj69 wants to merge 1 commit into
SciML:masterfrom
Kulraj69:fix-complex-t-expv-cache

Conversation

@Kulraj69

Copy link
Copy Markdown

Partially fixes #314 (source 1: the general/Arnoldi branch).

The complex-t expv! method took only the Hessenberg buffer from ExpvCache and then called exponential!(t * cache, expmethod). That allocated t * H and a fresh Padé workspace on every call. Now, when the cache eltype can hold t * H (e.g. ExpvCache{ComplexF64}), it does what the real-t method does: get_expcache!, then lmul!(t, Hcopy), then _exponential! with the cached workspace. The first column goes into cache.expcol. Caches that can't hold the product (e.g. ExpvCache{Float64} with a real non-Hermitian H) keep the old allocating path, so results don't change.

The issue's benchmark (n = 200, m = 30, Julia 1.13.4):

before after
Arnoldi, ExpvCache{ComplexF64}, t = 0.01 64 B 64 B
Arnoldi, ExpvCache{ComplexF64}, t = -0.01im 162,376 B 128 B

I left the Hermitian/Lanczos branch (source 2, the ~18 KB from eigen!(SymTridiagonal(...)) and its temporaries) out of this PR. It is a separate change that would move symtridiag_eigen! buffers into ExpvCache.

Tests: a new testset in test/basictests.jl checks complex-t results against exp(t * A) * b for Arnoldi and Lanczos, with no cache, a small (resized) cache and a real-eltype fallback cache. It also checks that the cached Padé workspace is reused, that warmed complex-t allocations stay close to real-t allocations, the zero-vector case and the invalid-cache error. GROUP=Core and GROUP=QA pass locally, and Runic and typos are clean.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expv! with complex t allocates despite a preallocated ExpvCache

1 participant