Created
April 12, 2013 16:26
-
-
Save dfilimon/5373271 to your computer and use it in GitHub Desktop.
Vector iteration Mahout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testVectorIteration() { | |
Vector vector = new SequentialAccessSparseVector(100); | |
vector.set(0, 1); | |
vector.set(2, 2); | |
vector.set(4, 3); | |
vector.set(6, 4); | |
Iterator<Vector.Element> vectorIterator = vector.iterateNonZero(); | |
Vector.Element element = null; | |
int i = 0; | |
while (vectorIterator.hasNext()) { | |
if (i % 2 == 0) { | |
element = vectorIterator.next(); | |
} | |
System.out.printf("%d %d %f\n", i, element.index(), element.get()); | |
++i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently you can't hold on to a copy of Element when iterating, all your references will share same offset. I'd suggest to change SequentialAccessSparseVector.java