zdotc function

Complex zdotc(
  1. int N,
  2. Array<Complex> ZX_,
  3. int INCX,
  4. Array<Complex> ZY_,
  5. int INCY,
)

Implementation

Complex zdotc(
  final int N,
  final Array<Complex> ZX_,
  final int INCX,
  final Array<Complex> ZY_,
  final int INCY,
) {
  final ZX = ZX_.having();
  final ZY = ZY_.having();

  if (N <= 0) return Complex.zero;

  var ZTEMP = Complex.zero;
  if (INCX == 1 && INCY == 1) {
    // code for both increments equal to 1

    for (var I = 1; I <= N; I++) {
      ZTEMP += ZX[I].conjugate() * ZY[I];
    }
  } else {
    // code for unequal increments or equal increments
    // not equal to 1

    var IX = INCX < 0 ? (-N + 1) * INCX + 1 : 1;
    var IY = INCY < 0 ? (-N + 1) * INCY + 1 : 1;
    for (var I = 1; I <= N; I++) {
      ZTEMP += ZX[IX].conjugate() * ZY[IY];
      IX += INCX;
      IY += INCY;
    }
  }
  return ZTEMP;
}