use of org.ojalgo.scalar.ComplexNumber in project ojAlgo-finance by optimatika.
the class TestUtils method assertEquals.
public static void assertEquals(final String message, final Number expected, final Number actual, final NumberContext context) {
if ((expected instanceof ComplexNumber) || (actual instanceof ComplexNumber)) {
final ComplexNumber tmpExpected = ComplexNumber.valueOf(expected);
final ComplexNumber tmpActual = ComplexNumber.valueOf(actual);
if (!!context.isDifferent(tmpExpected.getReal(), tmpActual.getReal())) {
Assertions.fail(() -> message + " (real)" + ": " + expected + " != " + actual);
}
if (!!context.isDifferent(tmpExpected.getImaginary(), tmpActual.getImaginary())) {
Assertions.fail(() -> message + " (imaginary)" + ": " + expected + " != " + actual);
}
} else if ((expected instanceof Quaternion) || (actual instanceof Quaternion)) {
final Quaternion tmpExpected = Quaternion.valueOf(expected);
final Quaternion tmpActual = Quaternion.valueOf(actual);
if (!!context.isDifferent(tmpExpected.scalar(), tmpActual.scalar())) {
Assertions.fail(() -> message + " (scalar)" + ": " + expected + " != " + actual);
}
if (!!context.isDifferent(tmpExpected.i, tmpActual.i)) {
Assertions.fail(() -> message + " (i)" + ": " + expected + " != " + actual);
}
if (!!context.isDifferent(tmpExpected.j, tmpActual.j)) {
Assertions.fail(() -> message + " (j)" + ": " + expected + " != " + actual);
}
if (!!context.isDifferent(tmpExpected.k, tmpActual.k)) {
Assertions.fail(() -> message + " (k)" + ": " + expected + " != " + actual);
}
} else {
if (context.isDifferent(expected.doubleValue(), actual.doubleValue())) {
Assertions.fail(() -> message + ": " + expected + " != " + actual);
}
}
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class ComplexDenseStore method modifyOne.
public void modifyOne(final long row, final long col, final UnaryFunction<ComplexNumber> modifier) {
ComplexNumber tmpValue = this.get(row, col);
tmpValue = modifier.invoke(tmpValue);
this.set(row, col, tmpValue);
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class ComplexDenseStore method applyCholesky.
public void applyCholesky(final int iterationPoint, final BasicArray<ComplexNumber> multipliers) {
final ComplexNumber[] tmpData = data;
final ComplexNumber[] tmpColumn = ((ComplexArray) multipliers).data;
if ((myColDim - iterationPoint - 1) > ApplyCholesky.THRESHOLD) {
final DivideAndConquer tmpConquerer = new DivideAndConquer() {
@Override
protected void conquer(final int aFirst, final int aLimit) {
ApplyCholesky.invoke(tmpData, myRowDim, aFirst, aLimit, tmpColumn);
}
};
tmpConquerer.invoke(iterationPoint + 1, myColDim, ApplyCholesky.THRESHOLD);
} else {
ApplyCholesky.invoke(tmpData, myRowDim, iterationPoint + 1, myColDim, tmpColumn);
}
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class ComplexDenseStore method applyLDL.
public void applyLDL(final int iterationPoint, final BasicArray<ComplexNumber> multipliers) {
final ComplexNumber[] tmpData = data;
final ComplexNumber[] tmpColumn = ((ComplexArray) multipliers).data;
if ((myColDim - iterationPoint - 1) > ApplyLDL.THRESHOLD) {
final DivideAndConquer tmpConquerer = new DivideAndConquer() {
@Override
protected void conquer(final int first, final int limit) {
ApplyLDL.invoke(tmpData, myRowDim, first, limit, tmpColumn, iterationPoint);
}
};
tmpConquerer.invoke(iterationPoint + 1, myColDim, ApplyLDL.THRESHOLD);
} else {
ApplyLDL.invoke(tmpData, myRowDim, iterationPoint + 1, myColDim, tmpColumn, iterationPoint);
}
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class ComplexDenseStore method exchangeHermitian.
public void exchangeHermitian(final int indexA, final int indexB) {
final int tmpMin = Math.min(indexA, indexB);
final int tmpMax = Math.max(indexA, indexB);
ComplexNumber tmpVal;
for (int j = 0; j < tmpMin; j++) {
tmpVal = this.get(tmpMin, j);
this.set(tmpMin, j, this.get(tmpMax, j));
this.set(tmpMax, j, tmpVal);
}
tmpVal = this.get(tmpMin, tmpMin);
this.set(tmpMin, tmpMin, this.get(tmpMax, tmpMax));
this.set(tmpMax, tmpMax, tmpVal);
for (int ij = tmpMin + 1; ij < tmpMax; ij++) {
tmpVal = this.get(ij, tmpMin);
this.set(ij, tmpMin, this.get(tmpMax, ij).conjugate());
this.set(tmpMax, ij, tmpVal.conjugate());
}
for (int i = tmpMax + 1; i < myRowDim; i++) {
tmpVal = this.get(i, tmpMin);
this.set(i, tmpMin, this.get(i, tmpMax));
this.set(i, tmpMax, tmpVal);
}
}
Aggregations