Search in sources :

Example 1 with ComplexNumber

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);
        }
    }
}
Also used : Quaternion(org.ojalgo.scalar.Quaternion) ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 2 with ComplexNumber

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);
}
Also used : ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 3 with ComplexNumber

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);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer) ComplexArray(org.ojalgo.array.ComplexArray) ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 4 with ComplexNumber

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);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer) ComplexArray(org.ojalgo.array.ComplexArray) ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 5 with ComplexNumber

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);
    }
}
Also used : ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Aggregations

ComplexNumber (org.ojalgo.scalar.ComplexNumber)53 Test (org.junit.jupiter.api.Test)20 NumberContext (org.ojalgo.type.context.NumberContext)16 DivideAndConquer (org.ojalgo.concurrent.DivideAndConquer)7 ComplexArray (org.ojalgo.array.ComplexArray)5 BigDecimal (java.math.BigDecimal)4 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)4 BasicMatrix (org.ojalgo.matrix.BasicMatrix)3 Householder (org.ojalgo.matrix.transformation.Householder)3 Tag (org.junit.jupiter.api.Tag)2 RationalMatrix (org.ojalgo.matrix.RationalMatrix)2 Solver (org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver)2 ComplexDenseStore (org.ojalgo.matrix.store.ComplexDenseStore)2 Normal (org.ojalgo.random.Normal)2 Quaternion (org.ojalgo.scalar.Quaternion)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Uniform (org.ojalgo.random.Uniform)1