@Override public boolean hasNext() { return element.getNextIndex() < SequentialAccessSparseVector.this.size(); }
public SequentialAccessSparseVector(SequentialAccessSparseVector other, boolean shallowCopy) { super(other.size()); values = shallowCopy ? other.values : other.values.clone(); }
@SuppressWarnings("CloneDoesntCallSuperClone") @Override public SequentialAccessSparseVector clone() { return new SequentialAccessSparseVector(size(), values.clone()); }
@Override public SequentialAccessSparseVector like() { return new SequentialAccessSparseVector(size(), values.getNumMappings()); }
public SequentialAccessSparseVector(SequentialAccessSparseVector other) { this(other.size(), other.getNumNondefaultElements()); values = other.values.clone(); }
@Override public SequentialAccessSparseVector vectorToTest(int size) { SequentialAccessSparseVector r = new SequentialAccessSparseVector(size); Random gen = RandomUtils.getRandom(); for (int i = 0; i < 3; i++) { r.set(gen.nextInt(r.size()), gen.nextGaussian()); } return r; }
@Test public void testAll() { SequentialAccessSparseVector x = new SequentialAccessSparseVector(CARDINALITY); for (int i = 0; i < x.size(); ++i) { x.setQuick(i, i); } SequentialAccessSparseVector y = new SequentialAccessSparseVector(x); System.out.printf("function %s; operation %s\n", function, operation); operation.assign(x, y, function); for (int i = 0; i < x.size(); ++i) { assertEquals(x.getQuick(i), function.apply(i, i), 0.0); } } }
public SequentialAccessSparseVector(SequentialAccessSparseVector other, boolean shallowCopy) { super(other.size()); values = shallowCopy ? other.values : other.values.clone(); }
public SequentialAccessSparseVector(SequentialAccessSparseVector other, boolean shallowCopy) { super(other.size()); values = shallowCopy ? other.values : other.values.clone(); }
@Override public boolean hasNext() { return element.getNextIndex() < SequentialAccessSparseVector.this.size(); }
@Override public SequentialAccessSparseVector clone() { return new SequentialAccessSparseVector(size(), values.clone()); }
@SuppressWarnings("CloneDoesntCallSuperClone") @Override public SequentialAccessSparseVector clone() { return new SequentialAccessSparseVector(size(), values.clone()); }
public SequentialAccessSparseVector(SequentialAccessSparseVector other) { this(other.size(), other.getNumNondefaultElements()); values = other.values.clone(); }
@Override public SequentialAccessSparseVector like() { return new SequentialAccessSparseVector(size(), values.getNumMappings()); }
public SequentialAccessSparseVector(SequentialAccessSparseVector other) { this(other.size(), other.getNumNondefaultElements()); values = other.values.clone(); }
@Override public SequentialAccessSparseVector like() { return new SequentialAccessSparseVector(size(), values.getNumMappings()); }
@Override public Vector minus(Vector that) { if (size() != that.size()) { throw new CardinalityException(size(), that.size()); } // Here we compute "that - this" since it's not fast to randomly access "this" // and then invert at the end Vector result = that.clone(); Iterator<Element> iter = this.iterateNonZero(); while (iter.hasNext()) { Element thisElement = iter.next(); int index = thisElement.index(); result.setQuick(index, that.getQuick(index) - thisElement.get()); } result.assign(Functions.NEGATE); return result; }
@Override public Vector assign(Vector other) { int size = size(); if (size != other.size()) { throw new CardinalityException(size, other.size()); } if (other instanceof SequentialAccessSparseVector) { values = ((SequentialAccessSparseVector)other).values.clone(); } else { values = new OrderedIntDoubleMapping(); Iterator<Element> othersElems = other.iterateNonZero(); while (othersElems.hasNext()) { Element elem = othersElems.next(); setQuick(elem.index(), elem.get()); } } return this; }