Search in sources :

Example 11 with DivideAndConquer

use of org.ojalgo.concurrent.DivideAndConquer in project ojAlgo by optimatika.

the class HouseholderHermitian method invoke.

public static void invoke(final BigDecimal[] data, final Householder.Big householder, final BigDecimal[] worker) {
    final BigDecimal[] tmpVector = householder.vector;
    final int tmpFirst = householder.first;
    final int tmpLength = tmpVector.length;
    final BigDecimal tmpBeta = householder.beta;
    final int tmpCount = tmpLength - tmpFirst;
    if (tmpCount > MultiplyHermitianAndVector.THRESHOLD) {
        final DivideAndConquer tmpConqurer = new DivideAndConquer() {

            @Override
            protected void conquer(final int first, final int limit) {
                MultiplyHermitianAndVector.invoke(worker, first, limit, data, tmpVector, tmpFirst);
            }
        };
        tmpConqurer.invoke(tmpFirst, tmpLength, MultiplyHermitianAndVector.THRESHOLD);
    } else {
        MultiplyHermitianAndVector.invoke(worker, tmpFirst, tmpLength, data, tmpVector, tmpFirst);
    }
    BigDecimal tmpVal = BigMath.ZERO;
    for (int c = tmpFirst; c < tmpLength; c++) {
        // tmpVal += tmpVector[c] * worker[c];
        tmpVal = tmpVal.add(tmpVector[c].multiply(worker[c]));
    }
    // tmpVal *= (tmpBeta / TWO);
    tmpVal = BigFunction.DIVIDE.invoke(tmpVal.multiply(tmpBeta), BigMath.TWO);
    for (int c = tmpFirst; c < tmpLength; c++) {
        // worker[c] = tmpBeta * (worker[c] - (tmpVal * tmpVector[c]));
        worker[c] = tmpBeta.multiply(worker[c].subtract(tmpVal.multiply(tmpVector[c])));
    }
    if (tmpCount > HermitianRank2Update.THRESHOLD) {
        final DivideAndConquer tmpConqurer = new DivideAndConquer() {

            @Override
            protected void conquer(final int first, final int limit) {
                HermitianRank2Update.invoke(data, first, limit, tmpVector, worker);
            }
        };
        tmpConqurer.invoke(tmpFirst, tmpLength, HermitianRank2Update.THRESHOLD);
    } else {
        HermitianRank2Update.invoke(data, tmpFirst, tmpLength, tmpVector, worker);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer) BigDecimal(java.math.BigDecimal)

Example 12 with DivideAndConquer

use of org.ojalgo.concurrent.DivideAndConquer in project ojAlgo by optimatika.

the class HouseholderHermitian method invoke.

public static <N extends Number & Scalar<N>> void invoke(final N[] data, final Householder.Generic<N> householder, final N[] worker, final Scalar.Factory<N> scalar) {
    final N[] tmpVector = householder.vector;
    final int tmpFirst = householder.first;
    final int tmpLength = tmpVector.length;
    final N tmpBeta = householder.beta;
    final int tmpCount = tmpLength - tmpFirst;
    if (tmpCount > MultiplyHermitianAndVector.THRESHOLD) {
        final DivideAndConquer tmpConqurer = new DivideAndConquer() {

            @Override
            protected void conquer(final int first, final int limit) {
                MultiplyHermitianAndVector.invoke(worker, first, limit, data, tmpVector, tmpFirst, scalar);
            }
        };
        tmpConqurer.invoke(tmpFirst, tmpLength, MultiplyHermitianAndVector.THRESHOLD);
    } else {
        MultiplyHermitianAndVector.invoke(worker, tmpFirst, tmpLength, data, tmpVector, tmpFirst, scalar);
    }
    Scalar<N> tmpVal = scalar.zero();
    for (int c = tmpFirst; c < tmpLength; c++) {
        // tmpVal += tmpVector[c] * worker[c];
        tmpVal = tmpVal.add(tmpVector[c].conjugate().multiply(worker[c]));
    }
    // tmpVal *= (tmpBeta / TWO);
    tmpVal = tmpVal.multiply(tmpBeta).divide(PrimitiveMath.TWO);
    for (int c = tmpFirst; c < tmpLength; c++) {
        // worker[c] = tmpBeta * (worker[c] - (tmpVal * tmpVector[c]));
        worker[c] = tmpBeta.multiply(worker[c].subtract(tmpVal.multiply(tmpVector[c]))).get();
    }
    if (tmpCount > HermitianRank2Update.THRESHOLD) {
        final DivideAndConquer tmpConqurer = new DivideAndConquer() {

            @Override
            protected void conquer(final int first, final int limit) {
                HermitianRank2Update.invoke(data, first, limit, tmpVector, worker);
            }
        };
        tmpConqurer.invoke(tmpFirst, tmpLength, HermitianRank2Update.THRESHOLD);
    } else {
        HermitianRank2Update.invoke(data, tmpFirst, tmpLength, tmpVector, worker);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer)

Example 13 with DivideAndConquer

use of org.ojalgo.concurrent.DivideAndConquer in project ojAlgo by optimatika.

the class HouseholderHermitian method invoke.

public static void invoke(final double[] data, final Householder.Primitive householder, final double[] worker) {
    final double[] tmpVector = householder.vector;
    final int tmpFirst = householder.first;
    final int tmpLength = tmpVector.length;
    final double tmpBeta = householder.beta;
    final int tmpCount = tmpLength - tmpFirst;
    if (tmpCount > MultiplyHermitianAndVector.THRESHOLD) {
        final DivideAndConquer tmpConqurer = new DivideAndConquer() {

            @Override
            protected void conquer(final int first, final int limit) {
                MultiplyHermitianAndVector.invoke(worker, first, limit, data, tmpVector, tmpFirst);
            }
        };
        tmpConqurer.invoke(tmpFirst, tmpLength, MultiplyHermitianAndVector.THRESHOLD);
    } else {
        MultiplyHermitianAndVector.invoke(worker, tmpFirst, tmpLength, data, tmpVector, tmpFirst);
    }
    double tmpVal = PrimitiveMath.ZERO;
    for (int c = tmpFirst; c < tmpLength; c++) {
        tmpVal += tmpVector[c] * worker[c];
    }
    tmpVal *= (tmpBeta / PrimitiveMath.TWO);
    for (int c = tmpFirst; c < tmpLength; c++) {
        worker[c] = tmpBeta * (worker[c] - (tmpVal * tmpVector[c]));
    }
    if (tmpCount > HermitianRank2Update.THRESHOLD) {
        final DivideAndConquer tmpConqurer = new DivideAndConquer() {

            @Override
            protected void conquer(final int first, final int limit) {
                HermitianRank2Update.invoke(data, first, limit, tmpVector, worker);
            }
        };
        tmpConqurer.invoke(tmpFirst, tmpLength, HermitianRank2Update.THRESHOLD);
    } else {
        HermitianRank2Update.invoke(data, tmpFirst, tmpLength, tmpVector, worker);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer)

Example 14 with DivideAndConquer

use of org.ojalgo.concurrent.DivideAndConquer in project ojAlgo by optimatika.

the class PrimitiveDenseStore method fillMatching.

@Override
public void fillMatching(final Access1D<Double> left, final BinaryFunction<Double> function, final Access1D<Double> right) {
    final int matchingCount = (int) FunctionUtils.min(this.count(), left.count(), right.count());
    if (myColDim > FillMatchingDual.THRESHOLD) {
        final DivideAndConquer tmpConquerer = new DivideAndConquer() {

            @Override
            protected void conquer(final int first, final int limit) {
                Primitive64Array.invoke(data, first, limit, 1, left, function, right);
            }
        };
        tmpConquerer.invoke(0, matchingCount, FillMatchingDual.THRESHOLD * FillMatchingDual.THRESHOLD);
    } else {
        Primitive64Array.invoke(data, 0, matchingCount, 1, left, function, right);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer)

Example 15 with DivideAndConquer

use of org.ojalgo.concurrent.DivideAndConquer in project ojAlgo by optimatika.

the class PrimitiveDenseStore method transformLeft.

public void transformLeft(final Householder<Double> transformation, final int firstColumn) {
    final Householder.Primitive tmpTransf = PrimitiveDenseStore.cast(transformation);
    final double[] tmpData = data;
    final int tmpRowDim = myRowDim;
    final int tmpColDim = myColDim;
    if ((tmpColDim - firstColumn) > HouseholderLeft.THRESHOLD) {
        final DivideAndConquer tmpConquerer = new DivideAndConquer() {

            @Override
            public void conquer(final int first, final int limit) {
                HouseholderLeft.invoke(tmpData, tmpRowDim, first, limit, tmpTransf);
            }
        };
        tmpConquerer.invoke(firstColumn, tmpColDim, HouseholderLeft.THRESHOLD);
    } else {
        HouseholderLeft.invoke(tmpData, tmpRowDim, firstColumn, tmpColDim, tmpTransf);
    }
}
Also used : DivideAndConquer(org.ojalgo.concurrent.DivideAndConquer) Householder(org.ojalgo.matrix.transformation.Householder)

Aggregations

DivideAndConquer (org.ojalgo.concurrent.DivideAndConquer)46 Householder (org.ojalgo.matrix.transformation.Householder)8 BigDecimal (java.math.BigDecimal)7 ComplexNumber (org.ojalgo.scalar.ComplexNumber)7 BigArray (org.ojalgo.array.BigArray)3 ComplexArray (org.ojalgo.array.ComplexArray)3 Primitive64Array (org.ojalgo.array.Primitive64Array)3