Rotations
Plane (Givens) rotations in src/dense/lapack/rotations.
NextLA.lartg — Method
lartg(f::R, g::S) where {R,S}Generate a plane rotation (Givens rotation) such that:
[ c s ] * [ f ] = [ r ]
[ -conj(s) c ] [ g ] [ 0 ]where c is real and s may be real or complex. The scalar r has the phase of f when f is nonzero.
Arguments
f: Scalar element (real or complex)g: Scalar element (real or complex)
Returns
c: Real cosine of the rotations: Sine of the rotation (real or complex)r: Resulting scalar after applying the rotation
Algorithm
The implementation follows LAPACK's scaling strategy to avoid over/underflow when computing norms. For complex inputs, c is always real and s carries the phase so that r aligns with f.
Special cases:
- If
g == 0, thenc = 1,s = 0,r = f - If
f == 0, thenc = 0,s = conj(g)/abs(g),r = abs(g)
Note
This is a low-level LAPACK-style computational routine. Input validation should be performed by higher-level interfaces.
Examples
julia> x = rand(1024); y = rand(1024);
julia> c, s, r = NextLA.lartg(x[1], y[1]);
julia> xr = c * x + s * y; yr = -s * x + c * y; # rotate the pair of rows
julia> xr[1] ≈ r && abs(yr[1]) < 1e-12
true