Skip to content

Commit bb637c8

Browse files
lkdvosclaude
andcommitted
Normalize One/Zero scalars before BLAS in mul!
`mul!(tC, tA, tB, α, β)` forwarded `VectorInterface.One`/`Zero` verbatim to LinearAlgebra's block `mul!`. Ordinary GEMM tolerates this, but a contraction of a tensor with its own adjoint dispatches to the HERK path, where `herk_wrapper!` calls `isreal` on the scalars and throws a `MethodError`. Map them to `true`/`false` first, which LinearAlgebra still recognizes as exact one and zero. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 4494902 commit bb637c8

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/tensors/linalg.jl‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,19 @@ function LinearAlgebra.tr(t::AbstractTensorMap)
326326
return s
327327
end
328328

329+
# LinearAlgebra's BLAS wrappers do not accept `VectorInterface.One`/`Zero`, e.g.
330+
# `herk_wrapper!` (hit by `mul!(C, A, A')`) calls `isreal` on the scalars.
331+
_blasscalar(α::Number) = α
332+
_blasscalar(::One) = true
333+
_blasscalar(::Zero) = false
334+
329335
# TensorMap multiplication
330336
function LinearAlgebra.mul!(
331337
tC::AbstractTensorMap, tA::AbstractTensorMap, tB::AbstractTensorMap, α = true, β = false
332338
)
333339
compose(space(tA), space(tB)) == space(tC) ||
334340
throw(SpaceMismatch(lazy"$(space(tC)) ≠ $(space(tA)) * $(space(tB))"))
341+
α, β = _blasscalar(α), _blasscalar(β)
335342

336343
@timeit_debug GLOBAL_TIMER "dense: matmul" begin
337344
iterC = blocks(tC)

0 commit comments

Comments
 (0)