Example #1
0
 private OpenMapRealMatrix createSparseMatrix(double[][] data) {
   OpenMapRealMatrix matrix = new OpenMapRealMatrix(data.length, data[0].length);
   for (int row = 0; row < data.length; row++) {
     for (int col = 0; col < data[row].length; col++) {
       matrix.setEntry(row, col, data[row][col]);
     }
   }
   return matrix;
 }
 /**
  * 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;
 }
Example #3
0
  /**
   * Compute this minus <code>m</code>.
   *
   * @param m matrix to be subtracted
   * @return this - m
   * @throws IllegalArgumentException if m is not the same size as this
   */
  public OpenMapRealMatrix subtract(OpenMapRealMatrix m) throws IllegalArgumentException {

    // safety check
    MatrixUtils.checkAdditionCompatible(this, m);

    final OpenMapRealMatrix out = new OpenMapRealMatrix(this);
    for (OpenIntToDoubleHashMap.Iterator iterator = m.entries.iterator(); iterator.hasNext(); ) {
      iterator.advance();
      final int row = iterator.key() / columnDimension;
      final int col = iterator.key() - row * columnDimension;
      out.setEntry(row, col, getEntry(row, col) - iterator.value());
    }

    return out;
  }