public void estimate(final Access1D<?> x, final Access1D<?> y) { final int tmpRowDim = (int) Math.min(x.count(), y.count()); final int tmpColDim = this.size(); final PhysicalStore<ComplexNumber> tmpBody = ComplexDenseStore.FACTORY.makeZero(tmpRowDim, tmpColDim); final PhysicalStore<ComplexNumber> tmpRHS = ComplexDenseStore.FACTORY.makeZero(tmpRowDim, 1); for (int i = 0; i < tmpRowDim; i++) { ComplexNumber tmpX = ComplexNumber.ONE; final ComplexNumber tmpXfactor = ComplexNumber.valueOf((Number) x.get(i)); final ComplexNumber tmpY = ComplexNumber.valueOf((Number) y.get(i)); for (int j = 0; j < tmpColDim; j++) { tmpBody.set(i, j, tmpX); tmpX = tmpX.multiply(tmpXfactor); } tmpRHS.set(i, 0, tmpY); } final QR<ComplexNumber> tmpQR = QR.makeComplex(); tmpQR.decompose(tmpBody); this.set(tmpQR.solve(tmpRHS)); }
public ComplexNumber integrate(final ComplexNumber fromPoint, final ComplexNumber toPoint) { final PolynomialFunction<ComplexNumber> tmpPrim = this.buildPrimitive(); final ComplexNumber tmpFromVal = tmpPrim.invoke(fromPoint); final ComplexNumber tmpToVal = tmpPrim.invoke(toPoint); return tmpToVal.subtract(tmpFromVal); }
public ComplexNumber invoke(final ComplexNumber arg) { int tmpPower = this.degree(); ComplexNumber retVal = this.get(tmpPower); while (--tmpPower >= 0) { retVal = this.get(tmpPower).add(arg.multiply(retVal)); } return retVal; }
public static void invoke( final ComplexNumber[] aData, final Householder.Complex aHouseholder, final ComplexNumber[] aWorker) { final ComplexNumber[] tmpVector = aHouseholder.vector; final int tmpFirst = aHouseholder.first; final int tmpLength = tmpVector.length; final ComplexNumber tmpBeta = aHouseholder.beta; final int tmpCount = tmpLength - tmpFirst; if (tmpCount > THRESHOLD) { final DivideAndConquer tmpConqurer = new DivideAndConquer() { @Override protected void conquer(final int aFirst, final int aLimit) { MultiplyHermitianAndVector.invoke( aWorker, aFirst, aLimit, aData, tmpVector, tmpFirst); } }; tmpConqurer.invoke(tmpFirst, tmpLength, THRESHOLD); } else { MultiplyHermitianAndVector.invoke(aWorker, tmpFirst, tmpLength, aData, tmpVector, tmpFirst); } ComplexNumber tmpVal = ComplexNumber.ZERO; for (int c = tmpFirst; c < tmpLength; c++) { // tmpVal += tmpVector[c] * aWorker[c]; tmpVal = tmpVal.add(tmpVector[c].conjugate().multiply(aWorker[c])); } // tmpVal *= (tmpBeta / TWO); tmpVal = ComplexFunction.DIVIDE.invoke(tmpVal.multiply(tmpBeta), ComplexNumber.TWO); for (int c = tmpFirst; c < tmpLength; c++) { // aWorker[c] = tmpBeta * (aWorker[c] - (tmpVal * tmpVector[c])); aWorker[c] = tmpBeta.multiply(aWorker[c].subtract(tmpVal.multiply(tmpVector[c]))); } if (tmpCount > THRESHOLD) { final DivideAndConquer tmpConqurer = new DivideAndConquer() { @Override protected void conquer(final int aFirst, final int aLimit) { HermitianRank2Update.invoke(aData, aFirst, aLimit, tmpVector, aWorker); } }; tmpConqurer.invoke(tmpFirst, tmpLength, THRESHOLD); } else { HermitianRank2Update.invoke(aData, tmpFirst, tmpLength, tmpVector, aWorker); } }
@Override protected void setUp() throws Exception { super.setUp(); final int tmpRowDim = Uniform.randomInteger(1, 9); final int tmpColDim = Uniform.randomInteger(1, 9); final BasicMatrix tmpBase = NonPhysicalTest.makeRandomMatrix(tmpRowDim, tmpColDim); final int tmpRowIndex = Uniform.randomInteger(tmpRowDim); final int tmpColumnIndex = Uniform.randomInteger(tmpColDim); final BigDecimal tmpElement = BigMath.PI; final MatrixStore<BigDecimal> aBase = BigDenseStore.FACTORY.copy((Access2D<?>) tmpBase); // myBigStore = new // SuperimposedMatrixStore<BigDecimal>(BigDenseStore.FACTORY.copyMatrix(tmpBase), tmpRowIndex, // tmpColumnIndex, tmpElement); // myComplexStore = new // SuperimposedMatrixStore<ComplexNumber>(ComplexDenseStore.FACTORY.copyMatrix(tmpBase), // tmpRowIndex, tmpColumnIndex, ComplexNumber.makeReal(tmpElement.doubleValue())); // myPrimitiveStore = new // SuperimposedMatrixStore<Double>(PrimitiveDenseStore.FACTORY.copyMatrix(tmpBase), tmpRowIndex, // tmpColumnIndex, tmpElement.doubleValue()); myBigStore = new SuperimposedStore<BigDecimal>( aBase, tmpRowIndex, tmpColumnIndex, new SingleStore<BigDecimal>(aBase.factory(), tmpElement)); final MatrixStore<ComplexNumber> aBase1 = ComplexDenseStore.FACTORY.copy((Access2D<?>) tmpBase); myComplexStore = new SuperimposedStore<ComplexNumber>( aBase1, tmpRowIndex, tmpColumnIndex, new SingleStore<ComplexNumber>( aBase1.factory(), ComplexNumber.valueOf(tmpElement.doubleValue()))); final MatrixStore<Double> aBase2 = PrimitiveDenseStore.FACTORY.copy((Access2D<?>) tmpBase); myPrimitiveStore = new SuperimposedStore<Double>( aBase2, tmpRowIndex, tmpColumnIndex, new SingleStore<Double>(aBase2.factory(), tmpElement.doubleValue())); }
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())) { Assert.failNotEquals(message + " (real)", expected, actual); } if (!!context.isDifferent(tmpExpected.getImaginary(), tmpActual.getImaginary())) { Assert.failNotEquals(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())) { Assert.failNotEquals(message + " (scalar)", expected, actual); } if (!!context.isDifferent(tmpExpected.i, tmpActual.i)) { Assert.failNotEquals(message + " (i)", expected, actual); } if (!!context.isDifferent(tmpExpected.j, tmpActual.j)) { Assert.failNotEquals(message + " (j)", expected, actual); } if (!!context.isDifferent(tmpExpected.k, tmpActual.k)) { Assert.failNotEquals(message + " (k)", expected, actual); } } else { if (context.isDifferent(expected.doubleValue(), actual.doubleValue())) { Assert.failNotEquals(message, expected, actual); } } }
public static void assertEquals( final double expected, final ComplexNumber actual, final NumberContext context) { TestUtils.assertEquals("ComplexNumber.re", expected, actual.doubleValue(), context); TestUtils.assertEquals("ComplexNumber.im", PrimitiveMath.ZERO, actual.i, context); }
public void set(final Access1D<?> someCoefficient) { final int tmpLimit = (int) Math.min(this.size(), someCoefficient.count()); for (int p = 0; p < tmpLimit; p++) { this.set(p, ComplexNumber.valueOf((Number) someCoefficient.get(p))); } }
@Override protected Rotation<ComplexNumber>[] rotations( final PhysicalStore<ComplexNumber> aStore, final int aLowInd, final int aHighInd, final Rotation<ComplexNumber>[] retVal) { final ComplexNumber a00 = aStore.get(aLowInd, aLowInd); final ComplexNumber a01 = aStore.get(aLowInd, aHighInd); final ComplexNumber a10 = aStore.get(aHighInd, aLowInd); final ComplexNumber a11 = aStore.get(aHighInd, aHighInd); final ComplexNumber x = a00.add(a11); final ComplexNumber y = a10.subtract(a01); ComplexNumber t; // tan, cot or something temporary // Symmetrise - Givens final ComplexNumber cg; // cos Givens final ComplexNumber sg; // sin Givens if (ComplexNumber.isSmall(PrimitiveMath.ONE, y)) { cg = x.signum(); sg = ComplexNumber.ZERO; } else if (ComplexNumber.isSmall(PrimitiveMath.ONE, x)) { sg = y.signum(); cg = ComplexNumber.ZERO; } else if (y.compareTo(x) == 1) { t = x.divide(y); // cot sg = y.signum().divide(ComplexFunction.SQRT1PX2.invoke(t)); cg = sg.multiply(t); } else { t = y.divide(x); // tan cg = x.signum().divide(ComplexFunction.SQRT1PX2.invoke(t)); sg = cg.multiply(t); } final ComplexNumber b00 = cg.multiply(a00).add(sg.multiply(a10)); final ComplexNumber b11 = cg.multiply(a11).subtract(sg.multiply(a01)); final ComplexNumber b2 = cg.multiply(a01.add(a10)).add(sg.multiply(a11.subtract(a00))); // b01 + b10 t = b11.subtract(b00).divide(b2); t = t.signum().divide(ComplexFunction.SQRT1PX2.invoke(t).add(t.norm())); // Annihilate - Jacobi final ComplexNumber cj = ComplexFunction.SQRT1PX2.invoke(t).invert(); // Cos Jacobi final ComplexNumber sj = cj.multiply(t); // Sin Jacobi retVal[1] = new Rotation.Complex(aLowInd, aHighInd, cj, sj); // Jacobi retVal[0] = new Rotation.Complex( aLowInd, aHighInd, cj.multiply(cg).add(sj.multiply(sg)), cj.multiply(sg).subtract(sj.multiply(cg))); // Givens - Jacobi return retVal; }