@SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException") @Override public Vector clone() { DelegatingVector r; try { r = (DelegatingVector) super.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException("Clone not supported for DelegatingVector, shouldn't be possible"); } // delegate points to original without this r.delegate = delegate.clone(); return r; }
@Override public Vector clone() { VectorView r = (VectorView) super.clone(); r.vector = vector.clone(); r.offset = offset; return r; }
@SuppressWarnings("CloneDoesntCallSuperClone") @Override public NamedVector clone() { return new NamedVector(delegate.clone(), name); }
@Override public Matrix clone() { SparseColumnMatrix clone = (SparseColumnMatrix) super.clone(); clone.columnVectors = new Vector[columnVectors.length]; for (int i = 0; i < columnVectors.length; i++) { clone.columnVectors[i] = columnVectors[i].clone(); } return clone; }
@Override public Matrix clone() { SparseRowMatrix clone = (SparseRowMatrix) super.clone(); clone.rowVectors = new Vector[rowVectors.length]; for (int i = 0; i < rowVectors.length; i++) { clone.rowVectors[i] = rowVectors[i].clone(); } return clone; }
public SparseMatrix(int rows, int columns, Map<Integer, Vector> rowVectors, boolean shallow) { // Why this is passing in a map? iterating it is pretty inefficient as opposed to simple lists... super(rows, columns); this.rowVectors = new Int2ObjectOpenHashMap<>(); if (shallow) { for (Map.Entry<Integer, Vector> entry : rowVectors.entrySet()) { this.rowVectors.put(entry.getKey().intValue(), entry.getValue()); } } else { for (Map.Entry<Integer, Vector> entry : rowVectors.entrySet()) { this.rowVectors.put(entry.getKey().intValue(), entry.getValue().clone()); } } }
@Override public synchronized EigenStatus verify(VectorIterable corpus, Vector vector) { if (!finished && !started) { // not yet started or finished, so start! status = new EigenStatus(-1, 0); Vector vectorCopy = vector.clone(); threadPool.execute(new VerifierRunnable(corpus, vectorCopy)); started = true; } if (finished) { finished = false; } return status; }
public SparseColumnMatrix(int rows, int columns, Vector[] columnVectors, boolean shallow) { super(rows, columns); if (shallow) { this.columnVectors = columnVectors; } else { this.columnVectors = columnVectors.clone(); for (int col = 0; col < columnSize(); col++) { this.columnVectors[col] = this.columnVectors[col].clone(); } } }
private static Vector createOptimizedCopy(Vector vector) { Vector result; if (vector.isDense()) { result = vector.like().assign(vector, Functions.SECOND_LEFT_ZERO); } else { result = vector.clone(); } return result; }
public SparseRowMatrix(int rows, int columns, Vector[] vectors, boolean shallowCopy, boolean randomAccess) { super(rows, columns); this.randomAccessRows = randomAccess; this.rowVectors = vectors.clone(); for (int row = 0; row < rows; row++) { if (vectors[row] == null) { // TODO: this can't be right to change the argument vectors[row] = randomAccess ? new RandomAccessSparseVector(numCols(), 10) : new SequentialAccessSparseVector(numCols(), 10); } this.rowVectors[row] = shallowCopy ? vectors[row] : vectors[row].clone(); } }
private OpenIntObjectHashMap<Vector> asRowVectors(Matrix matrix) { OpenIntObjectHashMap<Vector> rows = new OpenIntObjectHashMap<>(); for (int row = 0; row < matrix.numRows(); row++) { rows.put(row, matrix.viewRow(row).clone()); } return rows; }
Vector other = m.viewRow(r.nextInt(numRows)); if (other != null && other.getLengthSquared() > 0) { m.assignRow(c, other.clone());
@Test public void testCopy() { Vector copy = test.clone(); for (int i = 0; i < test.size(); i++) { assertEquals("copy [" + i + ']', test.get(i), copy.get(i), EPSILON); } }
@Test public void testCopy() throws Exception { Vector copy = test.clone(); for (int i = 0; i < test.size(); i++) { assertEquals("copy [" + i + ']', test.get(i), copy.get(i), EPSILON); } }
@Test public void testDot2() { Vector test2 = test.clone(); test2.set(1, 0.0); test2.set(3, 0.0); assertEquals(3.3 * 3.3, test2.dot(test), EPSILON); }
@Override public Matrix assign(Matrix other, DoubleDoubleFunction function) { //TODO generalize to other kinds of functions if (Functions.PLUS.equals(function) && other instanceof SparseMatrix) { int rows = rowSize(); if (rows != other.rowSize()) { throw new CardinalityException(rows, other.rowSize()); } int columns = columnSize(); if (columns != other.columnSize()) { throw new CardinalityException(columns, other.columnSize()); } SparseMatrix otherSparse = (SparseMatrix) other; for(ObjectIterator<Entry<Vector>> fastIterator = otherSparse.rowVectors.int2ObjectEntrySet().fastIterator(); fastIterator.hasNext();) { final Entry<Vector> entry = fastIterator.next(); final int rowIndex = entry.getIntKey(); Vector row = rowVectors.get(rowIndex); if (row == null) { rowVectors.put(rowIndex, entry.getValue().clone()); } else { row.assign(entry.getValue(), Functions.PLUS); } } return this; } else { return super.assign(other, function); } }
@Test public void testIteratorSet() { Vector clone = test.clone(); for (Element e : clone.nonZeroes()) { e.set(e.get() * 2.0); } for (Element e : clone.nonZeroes()) { assertEquals(test.get(e.index()) * 2.0, e.get(), EPSILON); } clone = test.clone(); for (Element e : clone.all()) { e.set(e.get() * 2.0); } for (Element e : clone.all()) { assertEquals(test.get(e.index()) * 2.0, e.get(), EPSILON); } }
if (currentState.getActivationDenominatorSquared() == 0) { pseudoEigen.assign(trainingVector, new PlusMult(1)); currentState.setHelperVector(currentState.currentTrainingProjection().clone()); double helperNorm = currentState.getHelperVector().norm(2); currentState.setActivationDenominatorSquared(trainingVectorNorm * trainingVectorNorm - helperNorm * helperNorm);
Vector v3 = v1.clone();
protected AbstractCluster(Vector point, int id2) { setNumObservations(0); setTotalObservations(0); setCenter(point.clone()); setRadius(center.like()); setS0(0); setS1(center.like()); setS2(center.like()); this.id = id2; }