Java Code Examples for org.nd4j.linalg.factory.Nd4j#createFloat()

The following examples show how to use org.nd4j.linalg.factory.Nd4j#createFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComplexNumberTests.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testScalarFloat() {
    IComplexFloat test = Nd4j.createFloat(1, 1);
    test.addi(1);
    assertEquals(2, test.realComponent().floatValue(), 1e-1);
    assertEquals(1, test.imaginaryComponent(), 1e-1);
    test.subi(1);
    assertEquals(1, test.realComponent().floatValue(), 1e-1);
    assertEquals(getFailureMessage(), 1, test.imaginaryComponent(), 1e-1);
    test.muli(2);
    assertEquals(2, test.realComponent().floatValue(), 1e-1);
    assertEquals(2, test.imaginaryComponent(), 1e-1);
    test.divi(2);
    assertEquals(1, test.realComponent().floatValue(), 1e-1);
    assertEquals(1, test.imaginaryComponent(), 1e-1);
    test.addi(Nd4j.createDouble(1, 1));
    assertEquals(2, test.realComponent().floatValue(), 1e-1);
    assertEquals(2, test.imaginaryComponent(), 1e-1);
    test.rdivi(1);
    assertEquals(0.25d, test.realComponent().floatValue(), 1e-1);
    assertEquals(-0.25d, test.imaginaryComponent(), 1e-1);
}
 
Example 2
Source File: BaseCudaDataBuffer.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public IComplexFloat getComplexFloat(long i) {
    return Nd4j.createFloat(getFloat(i), getFloat(i + 1));
}
 
Example 3
Source File: ComplexNumberTests.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testExponentFloat() {
    IComplexFloat test = Nd4j.createFloat(1, 1);
    assertEquals(test.realComponent(), 1.468694, 1e-3);
    assertEquals(test.imaginaryComponent(), 2.2873552, 1e-3);
}
 
Example 4
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the exp of a complex number:
 * Let r be the realComponent component and i be the imaginary
 * Let ret be the complex number returned
 * ret -> exp(r) * cos(i), exp(r) * sin(i)
 * where the first number is the realComponent component
 * and the second number is the imaginary component
 *
 * @param d the number to getFromOrigin the exp of
 * @return the exponential of this complex number
 */
public static IComplexFloat exp(IComplexFloat d) {
    return Nd4j.createFloat((float) FastMath.exp(d.realComponent()) * (float) FastMath.cos(d.imaginaryComponent()),
                    (float) FastMath.exp(d.realComponent()) * (float) FastMath.sin(d.imaginaryComponent()));
}