/** * Creates a new instance of DenseVector * @param internalVector Internal MTJ-based vector that does the heavy lifting */ protected DenseVector( no.uib.cipr.matrix.DenseVector internalVector) { super( internalVector ); this.array = internalVector.getData(); }
public Vector apply(Vector b, Vector x) { if (!(x instanceof DenseVector) || !(b instanceof DenseVector)) throw new IllegalArgumentException("Vector must be DenseVectors"); double[] xd = ((DenseVector) x).getData(); double[] bd = ((DenseVector) b).getData(); for (int i = 0; i < invdiag.length; ++i) xd[i] = bd[i] * invdiag[i]; return x; }
@Override public DenseVector copy() { double[] data = Arrays.copyOfRange(wrapped.getData(), offset, offset + size); return new DenseVector(data, false); } }
@Override public Vector set(Vector y) { if (!(y instanceof DenseVector)) return super.set(y); checkSize(y); double[] yd = ((DenseVector) y).getData(); System.arraycopy(yd, 0, data, 0, size); return this; }
@Override public Matrix rank1(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.rank1(alpha, x, y); checkRank1(x, y); double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y) .getData(); BLAS.getInstance().dger(numRows, numColumns, alpha, xd, 1, yd, 1, data, Math.max(1, numRows)); return this; }
@Override public double dot(Vector y) { if (!(y instanceof DenseVector)) return super.dot(y); checkSize(y); double[] yd = ((DenseVector) y).getData(); double dot = 0.; for (int i = 0; i < size; ++i) dot += data[i] * yd[i]; return dot; }
@Override public double dot(Vector y) { if (!(y instanceof DenseVector)) return super.dot(y); checkSize(y); double[] yd = ((DenseVector) y).getData(); double ret = 0; for (int i = 0; i < used; ++i) ret += data[i] * yd[index[i]]; return ret; }
@Override public double dot(Vector y) { if (!(y instanceof DenseVector)) return super.dot(y); checkSize(y); double[] yd = ((DenseVector) y).getData(); double dot = 0.; for (int i = 0; i < size; ++i) dot += data[i] * yd[i]; return dot; }
@Override public Vector add(Vector y) { if (!(y instanceof DenseVector)) return super.add(y); checkSize(y); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < size; i++) data[i] += yd[i]; return this; }
@Override public Vector add(double alpha, Vector y) { if (!(y instanceof DenseVector)) return super.add(alpha, y); checkSize(y); if (alpha == 0) return this; double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < size; i++) data[i] += alpha * yd[i]; return this; }
@Override public Vector add(double alpha, Vector y) { if (!(y instanceof DenseVector)) return super.add(alpha, y); checkSize(y); if (alpha == 0) return this; double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < size; i++) data[i] += alpha * yd[i]; return this; }
@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(); BLAS.getInstance().dsymv(uplo.netlib(), numRows, alpha, data, Math.max(1, numRows), xd, 1, 1, yd, 1); 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(); BLAS.getInstance().dgemv(Transpose.NoTranspose.netlib(), numRows, numColumns, alpha, data, Math.max(numRows, 1), xd, 1, 1, yd, 1); return y; }
@Override public Matrix rank2(double alpha, Vector x, Vector y) { if (!(x instanceof DenseVector) || !(y instanceof DenseVector)) return super.rank2(alpha, x, y); checkRank2(x, y); double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y) .getData(); BLAS.getInstance().dsyr2(uplo.netlib(), numRows, alpha, xd, 1, yd, 1, data, Math.max(1, numRows)); return this; }
@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(); BLAS.getInstance().dgbmv(Transpose.NoTranspose.netlib(), numRows, numColumns, kl, ku, alpha, data, kl + ku + 1, xd, 1, 1, yd, 1); 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(); BLAS.getInstance().dspmv(uplo.netlib(), numRows, alpha, data, xd, 1, 1, yd, 1); 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(); BLAS.getInstance().dsbmv(uplo.netlib(), numRows, kd, alpha, data, kd + 1, xd, 1, 1, yd, 1); return y; }
@Override public Vector set(double alpha, Vector y) { if (!(y instanceof DenseVector)) return super.set(alpha, y); checkSize(y); if (alpha == 0) return zero(); double[] yd = ((DenseVector) y).getData(); for (int i = 0; i < size; ++i) data[i] = alpha * yd[i]; return this; }
@Override public Matrix rank1(double alpha, Vector x, Vector y) { if (x != y) throw new IllegalArgumentException("x != y"); if (!(x instanceof DenseVector)) return super.rank1(alpha, x, y); checkRank1(x, y); double[] xd = ((DenseVector) x).getData(); BLAS.getInstance().dsyr(uplo.netlib(), numRows, alpha, xd, 1, data, Math.max(1, numRows)); return this; }
@Override public Matrix rank1(double alpha, Vector x, Vector y) { if (x != y) throw new IllegalArgumentException("x != y"); if (!(x instanceof DenseVector)) return super.rank1(alpha, x, y); checkRank1(x, y); double[] xd = ((DenseVector) x).getData(); BLAS.getInstance().dspr(uplo.netlib(), numRows, alpha, xd, 1, data); return this; }