/** {@inheritDoc} */
 public OpenMapRealVector subtract(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   OpenMapRealVector res = new OpenMapRealVector(this);
   for (int i = 0; i < v.length; i++) {
     if (entries.containsKey(i)) {
       res.setEntry(i, entries.get(i) - v[i]);
     } else {
       res.setEntry(i, -v[i]);
     }
   }
   return res;
 }
 /**
  * Optimized method to add two OpenMapRealVectors.
  *
  * @param v Vector to add with
  * @return The sum of <code>this</code> with <code>v</code>
  * @throws IllegalArgumentException If the dimensions don't match
  */
 public OpenMapRealVector add(OpenMapRealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   OpenMapRealVector res = (OpenMapRealVector) 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} */
 public OpenMapRealVector append(double[] a) {
   OpenMapRealVector res = new OpenMapRealVector(this, a.length);
   for (int i = 0; i < a.length; i++) {
     res.setEntry(i + virtualSize, a[i]);
   }
   return res;
 }
 /** {@inheritDoc} */
 public void setSubVector(int index, double[] v) throws MatrixIndexException {
   checkIndex(index);
   checkIndex(index + v.length - 1);
   for (int i = 0; i < v.length; i++) {
     setEntry(i + index, v[i]);
   }
 }
 /** {@inheritDoc} */
 public OpenMapRealVector add(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   OpenMapRealVector res = new OpenMapRealVector(getDimension());
   for (int i = 0; i < v.length; i++) {
     res.setEntry(i, v[i] + getEntry(i));
   }
   return res;
 }
 /**
  * Optimized method to append a OpenMapRealVector.
  *
  * @param v vector to append
  * @return The result of appending <code>v</code> to self
  */
 public OpenMapRealVector append(OpenMapRealVector v) {
   OpenMapRealVector res = new OpenMapRealVector(this, v.getDimension());
   Iterator iter = v.entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     res.setEntry(iter.key() + virtualSize, iter.value());
   }
   return res;
 }
 /** {@inheritDoc} */
 public OpenMapRealVector ebeMultiply(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   OpenMapRealVector res = new OpenMapRealVector(this);
   Iterator iter = res.entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     res.setEntry(iter.key(), iter.value() * v[iter.key()]);
   }
   return res;
 }
 /** {@inheritDoc} */
 public OpenMapRealVector ebeDivide(RealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   OpenMapRealVector res = new OpenMapRealVector(this);
   Iterator iter = res.entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     res.setEntry(iter.key(), iter.value() / v.getEntry(iter.key()));
   }
   return res;
 }
 /** {@inheritDoc} */
 public OpenMapRealVector getSubVector(int index, int n) throws MatrixIndexException {
   checkIndex(index);
   checkIndex(index + n - 1);
   OpenMapRealVector res = new OpenMapRealVector(n);
   int end = index + n;
   Iterator iter = entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     int key = iter.key();
     if (key >= index && key < end) {
       res.setEntry(key - index, iter.value());
     }
   }
   return res;
 }
 /** {@inheritDoc} */
 public OpenMapRealVector mapLogToSelf() {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, Math.log(getEntry(i)));
   }
   return this;
 }
 /** {@inheritDoc} */
 public OpenMapRealVector mapInvToSelf() {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, 1.0 / getEntry(i));
   }
   return this;
 }
 /** {@inheritDoc} */
 public OpenMapRealVector mapAddToSelf(double d) {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, getEntry(i) + d);
   }
   return this;
 }
 /** {@inheritDoc} */
 public OpenMapRealVector append(double d) {
   OpenMapRealVector res = new OpenMapRealVector(this, 1);
   res.setEntry(virtualSize, d);
   return res;
 }
 /** {@inheritDoc} */
 public void set(double value) {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, value);
   }
 }