/** {@inheritDoc} */ @Override public OpenMapRealVector mapAdd(double d) { return copy().mapAddToSelf(d); }
/** {@inheritDoc} */ @Override public OpenMapRealVector unitVector() throws MathArithmeticException { OpenMapRealVector res = copy(); res.unitize(); return res; }
/** * Optimized method to add two OpenMapRealVectors. * It copies the larger vector, then iterates over the smaller. * * @param v Vector to add. * @return the sum of {@code this} and {@code v}. * @throws DimensionMismatchException if the dimensions do not match. */ public OpenMapRealVector add(OpenMapRealVector v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); boolean copyThis = entries.size() > v.entries.size(); OpenMapRealVector res = copyThis ? this.copy() : v.copy(); Iterator iter = copyThis ? v.entries.iterator() : entries.iterator(); OpenIntToDoubleHashMap randomAccess = copyThis ? entries : v.entries; while (iter.hasNext()) { iter.advance(); int key = iter.key(); if (randomAccess.containsKey(key)) { res.setEntry(key, randomAccess.get(key) + iter.value()); } else { res.setEntry(key, iter.value()); } } return res; }
/** * Optimized method to subtract OpenMapRealVectors. * * @param v Vector to subtract from {@code this}. * @return the difference of {@code this} and {@code v}. * @throws DimensionMismatchException if the dimensions do not match. */ public OpenMapRealVector subtract(OpenMapRealVector v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); OpenMapRealVector res = copy(); Iterator iter = v.getEntries().iterator(); while (iter.hasNext()) { iter.advance(); int key = iter.key(); if (entries.containsKey(key)) { res.setEntry(key, entries.get(key) - iter.value()); } else { res.setEntry(key, -iter.value()); } } return res; }
/** {@inheritDoc} */ @Override public OpenMapRealVector mapAdd(double d) { return copy().mapAddToSelf(d); }
/** {@inheritDoc} */ @Override public OpenMapRealVector mapAdd(double d) { return copy().mapAddToSelf(d); }
/** {@inheritDoc} */ @Override public OpenMapRealVector unitVector() throws MathArithmeticException { OpenMapRealVector res = copy(); res.unitize(); return res; }
/** {@inheritDoc} */ @Override public OpenMapRealVector unitVector() throws MathArithmeticException { OpenMapRealVector res = copy(); res.unitize(); return res; }
/** * Optimized method to add two OpenMapRealVectors. * It copies the larger vector, then iterates over the smaller. * * @param v Vector to add. * @return the sum of {@code this} and {@code v}. * @throws DimensionMismatchException if the dimensions do not match. */ public OpenMapRealVector add(OpenMapRealVector v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); boolean copyThis = entries.size() > v.entries.size(); OpenMapRealVector res = copyThis ? this.copy() : v.copy(); Iterator iter = copyThis ? v.entries.iterator() : entries.iterator(); OpenIntToDoubleHashMap randomAccess = copyThis ? entries : v.entries; while (iter.hasNext()) { iter.advance(); int key = iter.key(); if (randomAccess.containsKey(key)) { res.setEntry(key, randomAccess.get(key) + iter.value()); } else { res.setEntry(key, iter.value()); } } return res; }
/** * Optimized method to add two OpenMapRealVectors. * It copies the larger vector, then iterates over the smaller. * * @param v Vector to add. * @return the sum of {@code this} and {@code v}. * @throws DimensionMismatchException if the dimensions do not match. */ public OpenMapRealVector add(OpenMapRealVector v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); boolean copyThis = entries.size() > v.entries.size(); OpenMapRealVector res = copyThis ? this.copy() : v.copy(); Iterator iter = copyThis ? v.entries.iterator() : entries.iterator(); OpenIntToDoubleHashMap randomAccess = copyThis ? entries : v.entries; while (iter.hasNext()) { iter.advance(); int key = iter.key(); if (randomAccess.containsKey(key)) { res.setEntry(key, randomAccess.get(key) + iter.value()); } else { res.setEntry(key, iter.value()); } } return res; }
/** * Optimized method to subtract OpenMapRealVectors. * * @param v Vector to subtract from {@code this}. * @return the difference of {@code this} and {@code v}. * @throws DimensionMismatchException if the dimensions do not match. */ public OpenMapRealVector subtract(OpenMapRealVector v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); OpenMapRealVector res = copy(); Iterator iter = v.getEntries().iterator(); while (iter.hasNext()) { iter.advance(); int key = iter.key(); if (entries.containsKey(key)) { res.setEntry(key, entries.get(key) - iter.value()); } else { res.setEntry(key, -iter.value()); } } return res; }
/** * Optimized method to subtract OpenMapRealVectors. * * @param v Vector to subtract from {@code this}. * @return the difference of {@code this} and {@code v}. * @throws DimensionMismatchException if the dimensions do not match. */ public OpenMapRealVector subtract(OpenMapRealVector v) throws DimensionMismatchException { checkVectorDimensions(v.getDimension()); OpenMapRealVector res = copy(); Iterator iter = v.getEntries().iterator(); while (iter.hasNext()) { iter.advance(); int key = iter.key(); if (entries.containsKey(key)) { res.setEntry(key, entries.get(key) - iter.value()); } else { res.setEntry(key, -iter.value()); } } return res; }