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);
}
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);
}
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;
}
Aggregations