org.ojalgo.matrix.transformation.HouseholderRow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ojalgo Show documentation
Show all versions of ojalgo Show documentation
oj! Algorithms - ojAlgo - is Open Source Java code that has to do with mathematics, linear algebra and optimisation.
package org.ojalgo.matrix.transformation;
import org.ojalgo.function.aggregator.Aggregator;
import org.ojalgo.function.constant.PrimitiveMath;
import org.ojalgo.matrix.store.MatrixStore;
import org.ojalgo.matrix.store.PhysicalStore;
import org.ojalgo.scalar.PrimitiveScalar;
import org.ojalgo.structure.Access2D.RowView;
import org.ojalgo.type.NumberDefinition;
final class HouseholderRow> extends RowView implements HouseholderReference {
private int myFirst = 0;
private final MatrixStore myStore;
private transient Householder myWorker = null;
public HouseholderRow(final MatrixStore store) {
super(store);
myStore = store;
}
@Override
public long count() {
return myStore.countColumns();
}
@Override
public double doubleValue(final long index) {
if (index > myFirst) {
return myStore.doubleValue(this.row(), index);
}
if (index == myFirst) {
return PrimitiveMath.ONE;
} else {
return PrimitiveMath.ZERO;
}
}
public int first() {
return myFirst;
}
@Override
public N get(final long index) {
if (index > myFirst) {
return myStore.get(this.row(), index);
}
if (index == myFirst) {
return myStore.physical().scalar().one().get();
} else {
return myStore.physical().scalar().zero().get();
}
}
@SuppressWarnings("unchecked")
public > P getWorker(final PhysicalStore.Factory factory) {
if (myWorker == null) {
myWorker = factory.makeHouseholder((int) this.count());
}
return (P) myWorker;
}
public boolean isZero() {
double largest = NumberDefinition.doubleValue(myStore.aggregateRow(this.row(), myFirst + 1L, Aggregator.LARGEST));
return PrimitiveScalar.isSmall(PrimitiveMath.ONE, largest);
}
public void point(final long row, final long col) {
this.goToRow(row);
myFirst = (int) col;
}
}