public Vector multAdd(Vector x, Vector y) { return multAdd(1, x, y); }
public Vector multAdd(Vector x, Vector y) { return multAdd(1, x, y); }
public Matrix multAdd(Matrix B, Matrix C) { return multAdd(1, B, C); }
public Matrix multAdd(Matrix B, Matrix C) { return multAdd(1, B, C); }
public Matrix mult(double alpha, Matrix B, Matrix C) { return multAdd(alpha, B, C.zero()); }
public Matrix mult(double alpha, Matrix B, Matrix C) { return multAdd(alpha, B, C.zero()); }
public Vector mult(double alpha, Vector x, Vector y) { return multAdd(alpha, x, y.zero()); }
public Vector mult(double alpha, Vector x, Vector y) { return multAdd(alpha, x, y.zero()); }
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < ind.length; ++i) { int row = ind[i] < 0 ? -ind[i] : 0; int column = ind[i] > 0 ? ind[i] : 0; double[] locDiag = diag[i]; for (int j = 0; j < locDiag.length; ++j, ++row, ++column) yd[row] += alpha * locDiag[j] * xd[column]; } return y; }
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < numRows; ++i) { double dot = 0; for (int j = rowPointer[i]; j < rowPointer[i + 1]; ++j) dot += data[j] * xd[columnIndex[j]]; yd[i] += alpha * dot; } return y; }
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < numRows; ++i) { double dot = 0; for (int j = rowPointer[i]; j < rowPointer[i + 1]; ++j) dot += data[j] * xd[columnIndex[j]]; yd[i] += alpha * dot; } return y; }
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < ind.length; ++i) { int row = ind[i] < 0 ? -ind[i] : 0; int column = ind[i] > 0 ? ind[i] : 0; double[] locDiag = diag[i]; for (int j = 0; j < locDiag.length; ++j, ++row, ++column) yd[row] += alpha * locDiag[j] * xd[column]; } return y; }
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y) .getData(); // y = 1/alpha * y y.scale(1 / alpha); // y = A*x + y for (int i = 0; i < numColumns; ++i) for (int j = columnPointer[i]; j < columnPointer[i + 1]; ++j) yd[rowIndex[j]] += data[j] * xd[i]; // y = alpha*y = alpha*A*x + y return y.scale(alpha); }
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y) .getData(); // y = 1/alpha * y y.scale(1 / alpha); // y = A*x + y for (int i = 0; i < numColumns; ++i) for (int j = columnPointer[i]; j < columnPointer[i + 1]; ++j) yd[rowIndex[j]] += data[j] * xd[i]; // y = alpha*y = alpha*A*x + y return y.scale(alpha); }
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); // y = 1/alpha * y y.scale(1. / alpha); // y = A*x + y for (int i = 0; i < numColumns; ++i) { SparseVector v = colD[i]; int[] index = v.getIndex(); double[] data = v.getData(); int length = v.getUsed(); for (int j = 0; j < length; ++j) yd[index[j]] += data[j] * xd[i]; } // y = alpha*y = alpha * A'x + y return y.scale(alpha); }
@Override public Vector multAdd(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.multAdd(alpha, x, y); checkMultAdd(x, y); double[] xd = ((DenseVector) x).getData(); double[] yd = ((DenseVector) y).getData(); // y = 1/alpha * y y.scale(1. / alpha); // y = A*x + y for (int i = 0; i < numColumns; ++i) { SparseVector v = colD[i]; int[] index = v.getIndex(); double[] data = v.getData(); int length = v.getUsed(); for (int j = 0; j < length; ++j) yd[index[j]] += data[j] * xd[i]; } // y = alpha*y = alpha * A'x + y return y.scale(alpha); }