Skip to content

Fix conjugation of A in complex GEADD - #6309

Open
proffitteoy wants to merge 2 commits into
OpenMathLib:developfrom
proffitteoy:fix/geadd-conjugate-a
Open

proffitteoy wants to merge 2 commits into
OpenMathLib:developfrom
proffitteoy:fix/geadd-conjugate-a

Conversation

@proffitteoy

@proffitteoy proffitteoy commented Dec 4, 2026 •

Copy link
Copy Markdown

cblas_cgeadd and cblas_zgeadd recognize CblasConjNoTrans and CblasConjTrans, but the interface discards the conjugation flag before calling the kernel. As a result, ConjNoTrans behaves like NoTrans, and ConjTrans behaves like Trans.

The kernel currently receives only a transpose flag. This patch preserves transpose and conjugation independently using two bits in the existing internal argument. The ordinary AXPBY path is unchanged for non-conjugating operations; conjugating operations use a separate complex arithmetic path, including the existing zero-alpha and zero-beta behavior.

For a minimal counterexample, take A = [i], initialize a separate C = [i], and set alpha = beta = 1/2, transA = ConjTrans and transC = NoTrans. This computes the self-adjoint part (A + A*)/2, which should be zero, but the original implementation returns [i].

#include <stdio.h>
#include "cblas.h"

int main(void)
{
    double a[2] = {0.0, 1.0};
    double c[2] = {0.0, 1.0};
    double alpha[2] = {0.5, 0.0};
    double beta[2] = {0.5, 0.0};

    cblas_zgeadd(CblasColMajor, CblasConjTrans, CblasNoTrans,
                1, 1, alpha, a, 1, beta, c, 1);
    printf("H=%.1f%+.1fi\n", c[0], c[1]);
    return c[0] != 0.0 || c[1] != 0.0;
}

The Fortran interface also needs a mapping for conjugation without transposition. I used R/r for this operation, following the convention in OMATCOPY, while C/c performs conjugate transposition. GEADD did not previously document the R/r mode, so I'd appreciate feedback on this convention before removing the draft status.

I added independent regression tests to both existing cgeadd and zgeadd test files. They cover row- and column-major CBLAS calls, rectangular matrices with padded leading dimensions, both conjugating modes, complex coefficients, zero coefficients with NaN inputs, and the Fortran ABI entry points. The tests also check that A remains unchanged.

@proffitteoy
proffitteoy marked this pull request as ready for review December 4, 2026 11:56

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.

1 participant