/** {@inheritDoc} */
 public double getLInfDistance(RealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   if (v instanceof OpenMapRealVector) {
     return getLInfDistance((OpenMapRealVector) v);
   }
   return getLInfDistance(v.getData());
 }
 /** {@inheritDoc} */
 public OpenMapRealVector add(RealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   if (v instanceof OpenMapRealVector) {
     return add((OpenMapRealVector) v);
   }
   return add(v.getData());
 }
 /** {@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;
 }
 /** {@inheritDoc} */
 public double getL1Distance(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   double max = 0;
   for (int i = 0; i < v.length; i++) {
     double delta = Math.abs(getEntry(i) - v[i]);
     max += delta;
   }
   return max;
 }
 /** {@inheritDoc} */
 public double getDistance(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   double res = 0;
   for (int i = 0; i < v.length; i++) {
     double delta = entries.get(i) - v[i];
     res += delta * delta;
   }
   return Math.sqrt(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 double dotProduct(RealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   double res = 0;
   Iterator iter = entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     res += v.getEntry(iter.key()) * iter.value();
   }
   return res;
 }
 /** {@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;
 }
 /** {@inheritDoc} */
 public double dotProduct(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   double res = 0;
   Iterator iter = entries.iterator();
   while (iter.hasNext()) {
     int idx = iter.key();
     double value = 0;
     if (idx < v.length) {
       value = v[idx];
     }
     res += value * iter.value();
   }
   return res;
 }
 /** {@inheritDoc} */
 public RealMatrix outerProduct(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   RealMatrix res = new OpenMapRealMatrix(virtualSize, virtualSize);
   Iterator iter = entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     int row = iter.key();
     double value = iter.value();
     for (int col = 0; col < virtualSize; col++) {
       res.setEntry(row, col, value * v[col]);
     }
   }
   return res;
 }
 /**
  * Optimized method to compute the outer product.
  *
  * @param v The vector to comput the outer product on
  * @return The outer product of <code>this</code> and <code>v</code>
  * @throws IllegalArgumentException If the dimensions don't match
  */
 public OpenMapRealMatrix outerproduct(OpenMapRealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   OpenMapRealMatrix res = new OpenMapRealMatrix(virtualSize, virtualSize);
   Iterator iter = entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     Iterator iter2 = v.getEntries().iterator();
     while (iter2.hasNext()) {
       iter2.advance();
       res.setEntry(iter.key(), iter2.key(), iter.value() * iter2.value());
     }
   }
   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 RealMatrix outerProduct(RealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   if (v instanceof OpenMapRealVector) {
     return outerproduct((OpenMapRealVector) v);
   }
   RealMatrix res = new OpenMapRealMatrix(virtualSize, virtualSize);
   Iterator iter = entries.iterator();
   while (iter.hasNext()) {
     iter.advance();
     int row = iter.key();
     for (int col = 0; col < virtualSize; col++) {
       res.setEntry(row, col, iter.value() * v.getEntry(col));
     }
   }
   return res;
 }
 /** {@inheritDoc} */
 public OpenMapRealVector projection(double[] v) throws IllegalArgumentException {
   checkVectorDimensions(v.length);
   return (OpenMapRealVector) projection(new OpenMapRealVector(v));
 }
 /** {@inheritDoc} */
 public RealVector projection(RealVector v) throws IllegalArgumentException {
   checkVectorDimensions(v.getDimension());
   return v.mapMultiply(dotProduct(v) / v.dotProduct(v));
 }