@Override public Double defaultValue() { return v.defaultValue().doubleValue(); }
/** * Construct a new matrix. The consistency of the vectors will not be * checked! The defaultValue of all arrays must be equal and all values in * the array must be less than n. * * @param n The maximum value in the arrays * @param arr The rows of the matrix * @param using The factory for building new vectors */ public SparseMatrix(int n, Vector<N>[] arr, Factory<N> using) { this.arr = arr; this.m = arr.length; this.n = n; this.defaultValue = m > 0 ? arr[0].defaultValue().doubleValue() : 0.0; this.using = using; }
@Override public <M extends Number> double innerProduct(Vector<M> y) { assert (y.length() == data.length); if (y instanceof RealVector) { final RealVector y2 = (RealVector) y; double innerProduct = 0.0; for (int i = 0; i < data.length; i++) { innerProduct += data[i] * y2.data[i]; } return innerProduct; } else if (y.defaultValue().doubleValue() == 0.0) { double innerProduct = 0.0; for (Map.Entry<Integer, M> e : y.entrySet()) { innerProduct += data[e.getKey()] * e.getValue().doubleValue(); } return innerProduct; } else { double innerProduct = 0.0; for (int i = 0; i < data.length; i++) { innerProduct += data[i] * y.doubleValue(i); } return innerProduct; } }
@Override public <M extends Number> double innerProduct(Vector<M> y) { assert (y.length() == data.length); if (y instanceof IntVector) { final IntVector y2 = (IntVector) y; int innerProduct = 0; for (int i = 0; i < data.length; i++) { innerProduct += data[i] * y2.data[i]; } return innerProduct; } else if (y.defaultValue().doubleValue() == 0.0) { double innerProduct = 0.0; for (Map.Entry<Integer, M> e : y.entrySet()) { innerProduct += data[e.getKey()] * e.getValue().doubleValue(); } return innerProduct; } else { double innerProduct = 0.0; for (int i = 0; i < data.length; i++) { innerProduct += data[i] * y.doubleValue(i); } return innerProduct; } }
if (defaultValue == 0 || y.defaultValue().intValue() == 0) { int innerProduct = 0; if (this.size() <= y.size()) { return innerProduct + (n - notBothSparse) * defaultValue * y.defaultValue().intValue();
if (defaultValue == 0.0 || y.defaultValue().doubleValue() == 0.0) { double innerProduct = 0.0; if (this.size() <= y.size()) { return innerProduct + (n - notBothSparse) * defaultValue * y.defaultValue().doubleValue();