mikera.matrixx.impl.MatrixElementIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vectorz Show documentation
Show all versions of vectorz Show documentation
Fast double-precision vector and matrix maths library for Java, supporting N-dimensional numeric arrays.
package mikera.matrixx.impl;
import java.util.Iterator;
import java.util.NoSuchElementException;
import mikera.matrixx.AMatrix;
/**
* Iterator over matrix elements for an arbitrary matrix
*
* @author Mike
*/
public class MatrixElementIterator implements Iterator {
private final AMatrix source;
private int col=0;
private int row=0;
public MatrixElementIterator(AMatrix source) {
this.source=source;
// hack for matrices with zero elements
if (source.elementCount()==0) {
row=source.rowCount();
}
}
@Override
public boolean hasNext() {
return row=source.rowCount()) throw new NoSuchElementException();
int ox=col++;
int oy=row;
if (col>=source.columnCount()) {
col=0;
row++;
}
return source.unsafeGet(oy,ox);
}
@Override
public void remove() {
throw new UnsupportedOperationException("Cannot remove from MatrixElementIterator");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy