Tabnine Logo
SparseCCDoubleMatrix2D
Code IndexAdd Tabnine to your IDE (free)

How to use
SparseCCDoubleMatrix2D
in
cern.colt.matrix.tdouble.impl

Best Java code snippets using cern.colt.matrix.tdouble.impl.SparseCCDoubleMatrix2D (Showing top 20 results out of 315)

origin: rwl/ParallelColt

public DoubleMatrix2D getL() {
  if (L == null) {
    L = new SparseCCDoubleMatrix2D(N.L);
    if (rcMatrix) {
      L = ((SparseCCDoubleMatrix2D) L).getRowCompressed();
    }
  }
  return L.copy();
}
origin: rwl/ParallelColt

public DoubleMatrix2D assign(final cern.colt.function.tdouble.DoubleFunction function) {
  if (function instanceof cern.jet.math.tdouble.DoubleMult) { // x[i] = mult*x[i]
    final double alpha = ((cern.jet.math.tdouble.DoubleMult) function).multiplicator;
    if (alpha == 1)
      return this;
    if (alpha == 0)
      return assign(0);
    if (alpha != alpha)
      return assign(alpha); // the funny definition of isNaN(). This should better not happen.
    final double[] valuesE = dcs.x;
    int nz = cardinality();
    for (int j = 0; j < nz; j++) {
      valuesE[j] *= alpha;
    }
  } else {
    forEachNonZero(new cern.colt.function.tdouble.IntIntDoubleFunction() {
      public double apply(int i, int j, double value) {
        return function.apply(value);
      }
    });
  }
  return this;
}
origin: rwl/ParallelColt

  public double apply(int i, int j, double value) {
    setQuick(i, j, getQuick(i, j) + alpha * value);
    return value;
  }
});
origin: rwl/ParallelColt

int n = I.rows(), c = I.columns();
SparseRCMDoubleMatrix2D Ac = new SparseRCMDoubleMatrix2D(c, c);
DenseDoubleMatrix1D itaiV = new DenseDoubleMatrix1D(c, itaiCol, 0, 1, false);
int[] colptr = I.getColumnPointers();
int[] rowind = I.getRowIndexes();
double[] Idata = I.getValues();
  I.zMult(aiV, itaiV, 1, 0, true);
origin: net.sourceforge.parallelcolt/parallelcolt

public DoubleMatrix2D assign(DoubleMatrix2D source) {
  if (source == this)
    return this; // nothing to do
  checkShape(source);
    System.arraycopy(other.getColumnPointers(), 0, this.dcs.p, 0, columns + 1);
    int nzmax = other.getRowIndexes().length;
    if (dcs.nzmax < nzmax) {
      dcs.i = new int[nzmax];
      dcs.x = new double[nzmax];
    System.arraycopy(other.getRowIndexes(), 0, this.dcs.i, 0, nzmax);
    System.arraycopy(other.getValues(), 0, this.dcs.x, 0, nzmax);
    rowIndexesSorted = other.rowIndexesSorted;
  } else if (source instanceof SparseRCDoubleMatrix2D) {
    rowIndexesSorted = true;
  } else {
    assign(0);
    source.forEachNonZero(new cern.colt.function.tdouble.IntIntDoubleFunction() {
      public double apply(int i, int j, double value) {
origin: rwl/ParallelColt

if (C == null) {
  if (B instanceof SparseCCDoubleMatrix2D) {
    C = new SparseCCDoubleMatrix2D(rowsA, p, (rowsA * p));
  } else {
    C = new DenseDoubleMatrix2D(rowsA, p);
  throw new IllegalArgumentException("Matrix2D inner dimensions must agree:" + toStringShort() + ", "
      + (transposeB ? B.viewDice() : B).toStringShort());
if (C.rows() != rowsA || C.columns() != p)
  throw new IllegalArgumentException("Incompatible result matrix: " + toStringShort() + ", "
      + (transposeB ? B.viewDice() : B).toStringShort() + ", " + C.toStringShort());
if (this == C || B == C)
  SparseCCDoubleMatrix2D AA;
  if (transposeA) {
    AA = getTranspose();
  } else {
    AA = this;
  SparseCCDoubleMatrix2D AA;
  if (transposeA) {
    AA = getTranspose();
  } else {
    AA = this;
    BB = BB.getTranspose();
    CC.assign(cern.jet.math.tdouble.DoubleFunctions.mult(alpha));
origin: net.sourceforge.parallelcolt/parallelcolt

public DoubleMatrix2D like(int rows, int columns) {
  return new SparseCCDoubleMatrix2D(rows, columns);
}
origin: net.sourceforge.parallelcolt/parallelcolt

/**
 * 
 * Returns the triangular factor, <tt>L'</tt>.
 * 
 * @return <tt>L'</tt>
 */
public DoubleMatrix2D getLtranspose() {
  if (L == null) {
    L = new SparseCCDoubleMatrix2D(N.L);
    if (rcMatrix) {
      L = ((SparseCCDoubleMatrix2D) L).getRowCompressed();
    }
  }
  if (rcMatrix) {
    return ((SparseRCDoubleMatrix2D) L).getTranspose();
  } else {
    return ((SparseCCDoubleMatrix2D) L).getTranspose();
  }
}
origin: net.sourceforge.parallelcolt/parallelcolt

  columnIndexesSorted = other.columnIndexesSorted;
} else if (source instanceof SparseCCDoubleMatrix2D) {
  SparseCCDoubleMatrix2D other = ((SparseCCDoubleMatrix2D) source).getTranspose();
  rowPointers = other.getColumnPointers();
  columnIndexes = other.getRowIndexes();
  values = other.getValues();
  columnIndexesSorted = true;
} else {
origin: net.sourceforge.parallelcolt/parallelcolt

/**
 * Creates the interpolation (prolongation) matrix based on the
 * non-smoothed aggregates
 */
private SparseCCDoubleMatrix2D createInterpolationMatrix(int[] pt, int c) {
  SparseCCMDoubleMatrix2D If = new SparseCCMDoubleMatrix2D(pt.length, c);
  for (int i = 0; i < pt.length; ++i)
    if (pt[i] != -1)
      If.setQuick(i, pt[i], 1);
  return (SparseCCDoubleMatrix2D) (new SparseCCDoubleMatrix2D(If.rows(), If.columns()).assign(If));
}
origin: net.sourceforge.parallelcolt/parallelcolt

/**
 * Creates the interpolation (prolongation) matrix based on the smoothed
 * aggregates
 */
private SparseCCDoubleMatrix2D createInterpolationMatrix(List<Map<Integer, Double>> P, int n) {
  // Determine the sparsity pattern of I
  int c = P.size();
  //            int[][] nz = new int[c][];
  //            for (int j = 0; j < c; ++j) {
  //
  //                Map<Integer, Double> Pj = P.get(j);
  //                nz[j] = new int[Pj.size()];
  //
  //                int l = 0;
  //                for (int k : Pj.keySet())
  //                    nz[j][l++] = k;
  //            }
  I = new SparseCCDoubleMatrix2D(n, c);
  // Populate it with numerical entries
  for (int j = 0; j < c; ++j) {
    Map<Integer, Double> Pj = P.get(j);
    for (Map.Entry<Integer, Double> e : Pj.entrySet())
      I.setQuick(e.getKey(), j, e.getValue());
  }
  return I;
}
origin: net.sourceforge.parallelcolt/parallelcolt

public DoubleMatrix2D assign(final DoubleMatrix2D y, cern.colt.function.tdouble.DoubleDoubleFunction function) {
  checkShape(y);
    final double alpha = ((cern.jet.math.tdouble.DoublePlusMultFirst) function).multiplicator;
    if (alpha == 0)
      return assign(y);
    y.forEachNonZero(new cern.colt.function.tdouble.IntIntDoubleFunction() {
      public double apply(int i, int j, double value) {
        valuesA[k] *= y.getQuick(i, j);
        if (valuesA[k] == 0)
          remove(i, j);
        valuesA[k] /= y.getQuick(i, j);
        if (valuesA[k] == 0)
          remove(i, j);
origin: net.sourceforge.parallelcolt/parallelcolt

if (A instanceof SparseRCDoubleMatrix2D) {
  rcMatrix = true;
  dcs = ((SparseRCDoubleMatrix2D) A).getColumnCompressed().elements();
} else {
  dcs = (Dcs) A.elements();
origin: net.sourceforge.parallelcolt/parallelcolt

rcMatrix = true;
if (m >= n) {
  dcs = ((SparseRCDoubleMatrix2D) A).getColumnCompressed().elements();
} else {
  dcs = ((SparseRCDoubleMatrix2D) A).getColumnCompressed().getTranspose().elements();
  dcs = (Dcs) A.elements();
} else {
  dcs = ((SparseCCDoubleMatrix2D) A).getTranspose().elements();
origin: rwl/ParallelColt

    + ((transposeA ? viewDice() : this).toStringShort()) + ", " + y.toStringShort() + ", "
    + z.toStringShort());
if ((nthreads > 1) && (cardinality() >= ConcurrencyUtils.getThreadsBeginN_2D())) {
  nthreads = 2;
  Future<?>[] futures = new Future[nthreads];
if ((nthreads > 1) && (cardinality() >= ConcurrencyUtils.getThreadsBeginN_2D())) {
  Future<?>[] futures = new Future[nthreads];
  int k = columns / nthreads;
origin: net.sourceforge.parallelcolt/parallelcolt

public DoubleMatrix2D assign(double value) {
  if (value == 0) {
    Arrays.fill(dcs.i, 0);
    Arrays.fill(dcs.p, 0);
    Arrays.fill(dcs.x, 0);
  } else {
    int nnz = cardinality();
    for (int i = 0; i < nnz; i++) {
      dcs.x[i] = value;
    }
  }
  return this;
}
origin: net.sourceforge.parallelcolt/parallelcolt

  public double apply(int i, int j, double value) {
    dense.setQuick(i, j, getQuick(i, j));
    return value;
  }
});
origin: net.sourceforge.parallelcolt/parallelcolt

/**
 * Returns the infinity norm of matrix <tt>A</tt>, which is the maximum
 * absolute row sum.
 */
public double normInfinity(DoubleMatrix2D A) {
  DoubleProperty.DEFAULT.checkSparse(A);
  double norm;
  if (A instanceof SparseRCDoubleMatrix2D) {
    norm = normInfinityRC((SparseRCDoubleMatrix2D) A);
  } else {
    norm = normInfinityRC(((SparseCCDoubleMatrix2D) A).getRowCompressed());
  }
  return norm;
}
origin: net.sourceforge.parallelcolt/parallelcolt

/**
 * Returns a new matrix that has the same elements as this matrix, but is in
 * a dense form. This method creates a new object (not a view), so changes
 * in the returned matrix are NOT reflected in this matrix.
 * 
 * @return this matrix in a dense form
 */
public DenseDoubleMatrix2D getDense() {
  final DenseDoubleMatrix2D dense = new DenseDoubleMatrix2D(rows, columns);
  forEachNonZero(new cern.colt.function.tdouble.IntIntDoubleFunction() {
    public double apply(int i, int j, double value) {
      dense.setQuick(i, j, getQuick(i, j));
      return value;
    }
  });
  return dense;
}
origin: rwl/ParallelColt

/**
 * Constructs a matrix with a copy of the given values. <tt>values</tt> is
 * required to have the form <tt>values[row][column]</tt> and have exactly
 * the same number of columns in every row.
 * <p>
 * The values are copied. So subsequent changes in <tt>values</tt> are not
 * reflected in the matrix, and vice-versa.
 * 
 * @param values
 *            The values to be filled into the new matrix.
 * @throws IllegalArgumentException
 *             if
 *             <tt>for any 1 &lt;= row &lt; values.length: values[row].length != values[row-1].length</tt>
 *             .
 */
public SparseCCDoubleMatrix2D(double[][] values) {
  this(values.length, values[0].length);
  assign(values);
}
cern.colt.matrix.tdouble.implSparseCCDoubleMatrix2D

Javadoc

Sparse column-compressed 2-d matrix holding double elements. First see the package summary and javadoc tree view to get the broad picture.

Implementation:

Internally uses the standard sparse column-compressed format.
Note that this implementation is not synchronized.

Cells that

  • are never set to non-zero values do not use any memory.
  • switch from zero to non-zero state do use memory.
  • switch back from non-zero to zero state also do use memory. Their memory is not automatically reclaimed. Reclamation can be triggered via #trimToSize().

Time complexity:

Getting a cell value takes time O(log nzr) where nzr is the number of non-zeros of the touched row. This is usually quick, because typically there are only few nonzeros per row. So, in practice, get has expected constant time. Setting a cell value takes worst-case time O(nz) where nzr is the total number of non-zeros in the matrix. This can be extremely slow, but if you traverse coordinates properly (i.e. upwards), each write is done much quicker:

 
// rather quick 
matrix.assign(0); 
for (int column = 0; column < columns; column++) { 
for (int row = 0; row < rows; row++) { 
if (someCondition) 
matrix.setQuick(row, column, someValue); 
} 
} 
// poor 
matrix.assign(0); 
for (int column = columns; --column >= 0;) { 
for (int row = rows; --row >= 0;) { 
if (someCondition) 
matrix.setQuick(row, column, someValue); 
} 
} 
If for whatever reasons you can't iterate properly, consider to create an empty dense matrix, store your non-zeros in it, then call sparse.assign(dense). Under the circumstances, this is still rather quick.

Fast iteration over non-zeros can be done via #forEachNonZero, which supplies your function with row, column and value of each nonzero. Although the internally implemented version is a bit more sophisticated, here is how a quite efficient user-level matrix-vector multiplication could look like:

 
// Linear algebraic y = A * x 
A.forEachNonZero(new cern.colt.function.IntIntDoubleFunction() { 
public double apply(int row, int column, double value) { 
y.setQuick(row, y.getQuick(row) + value * x.getQuick(column)); 
return value; 
} 
}); 

Here is how a a quite efficient user-level combined scaling operation could look like:

 
// Elementwise A = A + alpha*B 
B.forEachNonZero(new cern.colt.function.IntIntDoubleFunction() { 
public double apply(int row, int column, double value) { 
A.setQuick(row, column, A.getQuick(row, column) + alpha * value); 
return value; 
} 
}); 
Method #assign(DoubleMatrix2D,cern.colt.function.tdouble.DoubleDoubleFunction)does just that if you supply cern.jet.math.tdouble.DoubleFunctions#plusMultSecond as argument.

Most used methods

  • <init>
    Constructs a matrix with a copy of the given values. values is required to have the form values[row]
  • assign
  • cardinality
  • checkShape
  • columns
  • elements
  • forEachNonZero
  • getColumnPointers
    Returns column pointers
  • getQuick
  • getRowCompressed
    Returns a new matrix that has the same elements as this matrix, but is in a row-compressed form. Thi
  • getRowIndexes
    Returns row indexes;
  • getTranspose
    Returns a new matrix that is the transpose of this matrix. This method creates a new object (not a v
  • getRowIndexes,
  • getTranspose,
  • getValues,
  • insert,
  • remove,
  • rows,
  • searchFromTo,
  • setQuick,
  • setUp,
  • toStringShort

Popular in Java

  • Running tasks concurrently on multiple threads
  • getApplicationContext (Context)
  • setRequestProperty (URLConnection)
  • onRequestPermissionsResult (Fragment)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • JLabel (javax.swing)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now