/**
 * Applies a Givens rotation (c, s) to two length-n vectors stored in the
 * same flat buffer at the given offsets. In-place:
 *
 *     v_i' =  c * v_i + s * v_j
 *     v_j' = -s * v_i + c * v_j
 *
 * Naming reflects the original use case (rotating two rows of a matrix),
 * but the helper is layout-agnostic: pass the offsets to two rows of a
 * row-major matrix, or to two columns of a column-major matrix — anything
 * where the pair of vectors lives in a single buffer.
 *
 * Avoids the header allocation that `.subarray(...)` would cost on every
 * call when this is invoked inside a tight QR-update loop.
 *
 * @param {Float64Array|Float32Array|number[]} buf flat buffer holding both vectors
 * @param {number} off_i starting offset of the first vector
 * @param {number} off_j starting offset of the second vector
 * @param {number} c
 * @param {number} s
 * @param {number} n number of elements to rotate
 */
export function givens_apply_rows_offset(buf, off_i, off_j, c, s, n) {
    for (let i = 0; i < n; ++i) {
        const a = buf[off_i + i];
        const b = buf[off_j + i];
        buf[off_i + i] = c * a + s * b;
        buf[off_j + i] = c * b - s * a;
    }
}
