/** * Compacts the vector */ public void compact() { int nz = Matrices.cardinality(this); // catches zero entries if (nz < data.length) { int[] newIndex = new int[nz]; double[] newData = new double[nz]; // Copy only non-zero entries for (int i = 0, j = 0; i < data.length; ++i) if (data[i] != 0.) { newIndex[j] = index[i]; newData[j] = data[i]; j++; } data = newData; index = newIndex; used = data.length; } }
/** * Compacts the vector */ public void compact() { int nz = Matrices.cardinality(this); // catches zero entries if (nz < data.length) { int[] newIndex = new int[nz]; double[] newData = new double[nz]; // Copy only non-zero entries for (int i = 0, j = 0; i < data.length; ++i) if (data[i] != 0.) { newIndex[j] = index[i]; newData[j] = data[i]; j++; } data = newData; index = newIndex; used = data.length; } }
@Override public String toString() { // Output into coordinate format. Indices start from 1 instead of 0 Formatter out = new Formatter(); out.format("%10d %19d\n", size, Matrices.cardinality(this)); int i = 0; for (VectorEntry e : this) { if (e.get() != 0) out.format("%10d % .12e\n", e.index() + 1, e.get()); if (++i == 100) { out.format("...\n"); break; } } return out.toString(); }
@Override public String toString() { // Output into coordinate format. Indices start from 1 instead of 0 Formatter out = new Formatter(); out.format("%10d %19d\n", size, Matrices.cardinality(this)); int i = 0; for (VectorEntry e : this) { if (e.get() != 0) out.format("%10d % .12e\n", e.index() + 1, e.get()); if (++i == 100) { out.format("...\n"); break; } } return out.toString(); }
@Override public String toString() { // Output into coordinate format. Indices start from 1 instead of 0 Formatter out = new Formatter(); out.format("%10d %10d %19d%n", numRows, numColumns, Matrices.cardinality(this)); int i = 0; for (MatrixEntry e : this) { if (e.get() != 0) out.format("%10d %10d % .12e\n", e.row() + 1, e.column() + 1, e.get()); if (++i == 100) { out.format("...\n"); break; } } return out.toString(); }
@Override public String toString() { // Output into coordinate format. Indices start from 1 instead of 0 Formatter out = new Formatter(); out.format("%10d %10d %19d\n", numRows, numColumns, Matrices.cardinality(this)); int i = 0; for (MatrixEntry e : this) { if (e.get() != 0) out.format("%10d %10d % .12e\n", e.row() + 1, e.column() + 1, e.get()); if (++i == 100) { out.format("...\n"); break; } } return out.toString(); }
/** * Constructor for SparseVector, and copies the contents from the supplied * vector. * * @param x * Vector to copy from * @param deep * True if a deep copy is to be made. If the copy is shallow, * <code>x</code> must be a <code>SparseVector</code> */ public SparseVector(Vector x, boolean deep) { super(x); if (deep) { int nz = Matrices.cardinality(x); data = new double[nz]; index = new int[nz]; set(x); } else { SparseVector xs = (SparseVector) x; data = xs.getData(); index = xs.getIndex(); used = xs.getUsed(); } }
/** * Constructor for SparseVector, and copies the contents from the supplied * vector. * * @param x * Vector to copy from * @param deep * True if a deep copy is to be made. If the copy is shallow, * <code>x</code> must be a <code>SparseVector</code> */ public SparseVector(Vector x, boolean deep) { super(x); if (deep) { int nz = Matrices.cardinality(x); data = new double[nz]; index = new int[nz]; set(x); } else { SparseVector xs = (SparseVector) x; data = xs.getData(); index = xs.getIndex(); used = xs.getUsed(); } }
int nnz = Matrices.cardinality(J); log.debug("Nnz time: "+(System.currentTimeMillis()-t4));
int nonZero = Matrices.cardinality(aVector);
int nonZero = Matrices.cardinality(aVector);
int nonZero = Matrices.cardinality(aVector);
used = Matrices.cardinality(vec);
used = Matrices.cardinality(vec);
used = Matrices.cardinality(vec);