Search in sources :

Example 6 with IComplexNumber

use of org.nd4j.linalg.api.complex.IComplexNumber in project nd4j by deeplearning4j.

the class ComplexNumberTests method testPowerFloat.

@Test
public void testPowerFloat() {
    IComplexDouble test = Nd4j.createDouble(1, 1);
    IComplexDouble test2 = Nd4j.createDouble(1, 1);
    IComplexNumber result = test.pow(test2);
    assertEquals(result.realComponent(), 0.2739572);
    assertEquals(result.imaginaryComponent(), 0.583700);
}
Also used : IComplexNumber(org.nd4j.linalg.api.complex.IComplexNumber) IComplexDouble(org.nd4j.linalg.api.complex.IComplexDouble) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 7 with IComplexNumber

use of org.nd4j.linalg.api.complex.IComplexNumber in project nd4j by deeplearning4j.

the class ComplexNumberTests method testPowerDouble.

@Test
public void testPowerDouble() {
    IComplexDouble test = Nd4j.createDouble(1, 1);
    IComplexDouble test2 = Nd4j.createDouble(1, 1);
    IComplexNumber result = test.pow(test2);
    assertEquals(result.realComponent(), 0.273957253830121);
    assertEquals(result.imaginaryComponent(), 0.5837007587586147);
}
Also used : IComplexNumber(org.nd4j.linalg.api.complex.IComplexNumber) IComplexDouble(org.nd4j.linalg.api.complex.IComplexDouble) Test(org.junit.Test) BaseNd4jTest(org.nd4j.linalg.BaseNd4jTest)

Example 8 with IComplexNumber

use of org.nd4j.linalg.api.complex.IComplexNumber in project nd4j by deeplearning4j.

the class Nd4j method sort.

/**
 * Sort an ndarray along a particular dimension
 *
 * @param ndarray   the ndarray to sort
 * @param dimension the dimension to sort
 * @return the sorted ndarray
 */
public static IComplexNDArray sort(IComplexNDArray ndarray, int dimension, boolean ascending) {
    for (int i = 0; i < ndarray.vectorsAlongDimension(dimension); i++) {
        IComplexNDArray vec = ndarray.vectorAlongDimension(i, dimension);
        IComplexNumber[] data = new IComplexNumber[vec.length()];
        for (int j = 0; j < vec.length(); j++) {
            data[j] = vec.getComplex(j);
        }
        if (ascending)
            Arrays.sort(data, new Comparator<IComplexNumber>() {

                @Override
                public int compare(IComplexNumber o1, IComplexNumber o2) {
                    return Double.compare(o1.asDouble().absoluteValue().doubleValue(), o2.asDouble().absoluteValue().doubleValue());
                }
            });
        else
            Arrays.sort(data, new Comparator<IComplexNumber>() {

                @Override
                public int compare(IComplexNumber o1, IComplexNumber o2) {
                    return -Double.compare(o1.asDouble().absoluteValue().doubleValue(), o2.asDouble().absoluteValue().doubleValue());
                }
            });
        for (int j = 0; j < vec.length(); j++) vec.putScalar(j, data[j]);
    }
    return ndarray;
}
Also used : IComplexNumber(org.nd4j.linalg.api.complex.IComplexNumber) IComplexNDArray(org.nd4j.linalg.api.complex.IComplexNDArray)

Aggregations

IComplexNumber (org.nd4j.linalg.api.complex.IComplexNumber)8 Test (org.junit.Test)5 IComplexDouble (org.nd4j.linalg.api.complex.IComplexDouble)5 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)4 IComplexNDArray (org.nd4j.linalg.api.complex.IComplexNDArray)3 Ignore (org.junit.Ignore)1