Skip to content

refactor: introduce shared CABSSQ/ZABSSQ helpers for complex squared magnitude #1200

@nakatamaho

Description

@nakatamaho

Summary

This change replaces duplicated local ABSSQ statement-function definitions in
the complex Givens rotation related routines with shared external BLAS helpers:

  • CABSSQ for COMPLEX
  • ZABSSQ for DOUBLE COMPLEX

The following callers are updated:

  • BLAS/SRC/crotg.f90
  • BLAS/SRC/zrotg.f90
  • SRC/clartg.f90
  • SRC/zlartg.f90
  • SRC/clargv.f
  • SRC/zlargv.f

Motivation

Several BLAS/LAPACK routines currently carry identical local ABSSQ
statement-function definitions of the form:

  • REAL(x)**2 + AIMAG(x)**2
  • DBLE(x)**2 + DIMAG(x)**2

Centralizing this tiny helper reduces duplication, simplifies maintenance, and
also reduces reliance on local statement functions in the conversion pipeline.

Numerical behavior

This change is intended to preserve the original numerical behavior.

The helper formula is kept exactly in the same form as before:

  • CABSSQ(t) = REAL(t)**2 + AIMAG(t)**2
  • ZABSSQ(t) = DBLE(t)**2 + DIMAG(t)**2

In particular:

  • this patch does not replace the helper with ABS(t)**2
  • this patch does not move Blue-scaling logic into the helper
  • this patch does not change Blue constants, scaling thresholds, or branch structure

All Blue-scaling and safe-scaling logic remains local to the existing callers.

Notes

This is a refactoring change only.
If later review shows that loop-local statement functions are preferred over
external helpers for performance reasons, the same cleanup can be reworked into
an include-based statement-function form without changing the caller-side logic.

proposed implimentations

      REAL FUNCTION CABSSQ(T)
*
*  -- Shared helper for complex squared magnitude ------------------------
*     Returns REAL(T)**2 + AIMAG(T)**2.
*     This intentionally does not use ABS(T)**2 and does not perform any
*     scaling. Blue-scaling remains the responsibility of the caller.
*
      COMPLEX T
      CABSSQ = REAL(T)**2 + AIMAG(T)**2
      RETURN
      END
      DOUBLE PRECISION FUNCTION ZABSSQ(T)
*
*  -- Shared helper for double complex squared magnitude -----------------
*     Returns DBLE(T)**2 + DIMAG(T)**2.
*     This intentionally does not use ABS(T)**2 and does not perform any
*     scaling. Blue-scaling remains the responsibility of the caller.
*
      DOUBLE COMPLEX T
      ZABSSQ = DBLE(T)**2 + DIMAG(T)**2
      RETURN
      END

Before opening a PR, I would like to ask whether this approach looks acceptable.

If there are no objections to introducing shared CABSSQ / ZABSSQ helpers for this cleanup, I will prepare a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions