mikera.matrixx.impl.VectorMatrixMN 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.List;
import mikera.matrixx.AMatrix;
import mikera.matrixx.Matrix;
import mikera.matrixx.Matrixx;
import mikera.vectorz.AVector;
import mikera.vectorz.Op;
import mikera.vectorz.Vectorz;
import mikera.vectorz.util.ErrorMessages;
/**
* A matrix implemented as a composition of M length N vectors
* @author Mike
*
*/
public class VectorMatrixMN extends AVectorMatrix {
private static final long serialVersionUID = -3660730676103956050L;
protected final AVector[] rowData;
public VectorMatrixMN(int rowCount, int columnCount) {
super(rowCount,columnCount);
this.rowData=new AVector[rowCount];
for (int i=0; i0)?rows[0].length():0);
this.rowData=rows;
}
/**
* Create a matrix from a list of rows
*
* @param rows
* @return
*/
public static VectorMatrixMN create(List> rows) {
int rc = rows.size();
AVector[] vs = new AVector[rc];
for (int i = 0; i < rc; i++) {
vs[i] = Vectorz.toVector(rows.get(i));
}
return VectorMatrixMN.wrap(vs);
}
public static VectorMatrixMN create(List> rows, int[] shape) {
int rc = rows.size();
AVector[] vs = new AVector[rc];
for (int i = 0; i < rc; i++) {
vs[i] = Vectorz.toVector(rows.get(i));
}
return VectorMatrixMN.wrap(vs);
}
public static VectorMatrixMN wrap(AVector[] rows) {
return new VectorMatrixMN(rows);
}
@Override
public void multiply(double factor) {
for (int i=0; i=rows)) throw new IndexOutOfBoundsException(ErrorMessages.invalidSlice(this, i));
rowData[i]=row;
}
@Override
public void swapRows(int i, int j) {
if (i!=j) {
AVector t=rowData[i];
rowData[i]=rowData[j];
rowData[j]=t;
}
}
@Override
public AVector getRow(int row) {
return rowData[row];
}
@Override
public double get(int row, int column) {
return rowData[row].get(column);
}
@Override
public void set(int row, int column, double value) {
rowData[row].set(column,value);
}
@Override
public double unsafeGet(int row, int column) {
return rowData[row].unsafeGet(column);
}
@Override
public void unsafeSet(int row, int column, double value) {
rowData[row].unsafeSet(column,value);
}
@Override
public void addAt(int i, int j, double d) {
rowData[i].addAt(j, d);
}
@Override
public void transform(AVector source, AVector dest) {
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy