Ddot.java
package org.mklab.sdpj.gpack.blaswrap;
import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
/**
* @author koga
* @version $Revision$, 2009/04/24
* @param <RS> 実スカラーの型
* @param <RM> 実行列の型
* @param <CS> 複素スカラーの型
* @param <CM> 複素行列の型
*/
public class Ddot<RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> {
/**
* dot product(内積)の計算を行います。 引数で与えたパラメータ(配列等)は変更されません Forms the dot product of two vectors.
*
* @param size 成分の数
* @param x x
* @param incx x成分の指数の増分
* @param y y
* @param incy y成分の指数の増分
* @return 内積の値
*/
RS ddot(int size, RS[] x, int incx, RS[] y, int incy) {
final RS unit = x[0].createUnit();
RS ans = unit.createZero();
if (size <= 0) {
return ans;
}
if (incx == 1 && incy == 1) {
for (int i = 0; i < size; i++) {
ans = ans.add(x[i].multiply(y[i]));
}
return ans;
}
int ix = 0;
int iy = 0;
if (incx < 0) {
ix = (-size + 1) * incx;
}
if (incy < 0) {
iy = (-size + 1) * incy;
}
for (int i = 1; i <= size; ++i) {
ans = ans.add(x[ix].multiply(y[iy]));
ix += incx;
iy += incy;
}
return ans;
}
}