All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mikera.matrixx.impl.MatrixElementIterator Maven / Gradle / Ivy

Go to download

Fast double-precision vector and matrix maths library for Java, supporting N-dimensional numeric arrays.

There is a newer version: 0.67.0
Show newest version
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