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

The following examples show how to use org.nd4j.linalg.factory.Nd4j#createDouble() . 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 testScalar() {
    IComplexDouble test = Nd4j.createDouble(1, 1);
    test.addi(1);
    assertEquals(2, test.realComponent().doubleValue(), 1e-1);
    assertEquals(1, test.imaginaryComponent(), 1e-1);
    test.subi(1);
    assertEquals(1, test.realComponent().doubleValue(), 1e-1);
    assertEquals(getFailureMessage(), 1, test.imaginaryComponent(), 1e-1);
    test.muli(2);
    assertEquals(2, test.realComponent().doubleValue(), 1e-1);
    assertEquals(2, test.imaginaryComponent(), 1e-1);
    test.divi(2);
    assertEquals(1, test.realComponent().doubleValue(), 1e-1);
    assertEquals(1, test.imaginaryComponent(), 1e-1);
    test.addi(Nd4j.createDouble(1, 1));
    assertEquals(2, test.realComponent().doubleValue(), 1e-1);
    assertEquals(2, test.imaginaryComponent(), 1e-1);
    test.rdivi(1);
    assertEquals(0.5d, test.realComponent().doubleValue(), 1e-1);
    assertEquals(2.0d, test.imaginaryComponent(), 1e-1);
}
 
Example 2
Source File: ComplexNumberTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: ComplexNumberTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: ComplexNumberTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogarithmFloat() {
    IComplexDouble test = Nd4j.createDouble(1, 1);
    IComplexDouble test2 = Nd4j.createDouble(1, 1);
    IComplexNumber result = test.pow(test2);
    assertEquals(result.realComponent(), 0.3465736);
    assertEquals(result.imaginaryComponent(), 0.7853982);
}
 
Example 5
Source File: ComplexNumberTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogarithmDouble() {
    IComplexDouble test = Nd4j.createDouble(1, 1);
    IComplexDouble test2 = Nd4j.createDouble(1, 1);
    IComplexNumber result = test.pow(test2);
    assertEquals(result.realComponent(), 0.3465735902799727);
    assertEquals(result.imaginaryComponent(), 0.7853981633974483);
}
 
Example 6
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Compute complex conj (in-place).
 */
@Override
public IComplexNDArray conji() {
    IComplexNDArray reshaped = linearView();
    IComplexDouble c = Nd4j.createDouble(0.0, 0);
    for (int i = 0; i < length(); i++) {
        IComplexNumber conj = reshaped.getComplex(i, c).conj();
        reshaped.putScalar(i, conj);

    }
    return this;
}
 
Example 7
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public IComplexNDArray hermitian() {
    IComplexNDArray result = Nd4j.createComplex(shape());

    IComplexDouble c = Nd4j.createDouble(0, 0);

    for (int i = 0; i < slices(); i++)
        for (int j = 0; j < columns(); j++)
            result.putScalar(j, i, getComplex(i, j, c).conji());
    return result;
}
 
Example 8
Source File: ComplexNumberTests.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testExponentDouble() {
    IComplexDouble test = Nd4j.createDouble(1, 1);
    assertEquals(test.realComponent(), 1.4686939399158851, 1e-3);
    assertEquals(test.imaginaryComponent(), 2.2873552871788423, 1e-3);
}
 
Example 9
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public static IComplexNumber round(IComplexNumber num) {
    return Nd4j.createDouble(Math.round(num.realComponent().doubleValue()),
                    Math.round(num.imaginaryComponent().doubleValue()));
}
 
Example 10
Source File: BaseCudaDataBuffer.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public IComplexDouble getComplexDouble(long i) {
    return Nd4j.createDouble(getDouble(i), getDouble(i + 1));
}
 
Example 11
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the tanh of a complex number
 *
 * @param num the tanh of a complex number
 * @return the tanh of a complex number
 */
public static IComplexNumber tanh(IComplexNumber num) {
    Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).tanh();
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}
 
Example 12
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the absolute value of the given complex number
 *
 * @param num the number to getScalar the absolute value for
 * @return the absolute value of this complex number
 */
public static IComplexNumber sqrt(IComplexNumber num) {
    Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).sqrt();
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}
 
Example 13
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the  log value of the given complex number
 *
 * @param num the number to getScalar the absolute value for
 * @return the absolute value of this complex number
 */
public static IComplexNumber log(IComplexNumber num) {
    Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).log();
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}
 
Example 14
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the  log value of the given complex number
 *
 * @param num the number to getScalar the absolute value for
 * @return the absolute value of this complex number
 */
public static IComplexNumber neg(IComplexNumber num) {
    Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).negate();
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}
 
Example 15
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the  floor value of the given complex number
 *
 * @param num the number to getScalar the absolute value for
 * @return the absolute value of this complex number
 */
public static IComplexNumber floor(IComplexNumber num) {
    Complex c = new Complex(FastMath.floor(num.realComponent().doubleValue()),
                    FastMath.floor(num.imaginaryComponent().doubleValue()));
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}
 
Example 16
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the  ceiling value of the given complex number
 *
 * @param num the number to getScalar the absolute value for
 * @return the absolute value of this complex number
 */
public static IComplexNumber ceil(IComplexNumber num) {
    Complex c = new Complex(FastMath.ceil(num.realComponent().doubleValue()),
                    FastMath.ceil(num.imaginaryComponent().doubleValue()));
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}
 
Example 17
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the  sin value of the given complex number
 *
 * @param num the number to getScalar the absolute value for
 * @return the absolute value of this complex number
 */
public static IComplexNumber sin(IComplexNumber num) {
    Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).sin();
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}
 
Example 18
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the cos of a complex number
 *
 * @param num the tanh of a complex number
 * @return the tanh of a complex number
 */
public static IComplexNumber cos(IComplexNumber num) {
    Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).cos();
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}
 
Example 19
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 IComplexDouble exp(IComplexDouble d) {
    return Nd4j.createDouble(FastMath.exp(d.realComponent()) * FastMath.cos(d.imaginaryComponent()),
                    FastMath.exp(d.realComponent()) * FastMath.sin(d.imaginaryComponent()));
}
 
Example 20
Source File: ComplexUtil.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Return the  sin value of the given complex number
 *
 * @param num the number to getScalar the absolute value for
 * @return the absolute value of this complex number
 */
public static IComplexNumber atan(IComplexNumber num) {
    Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).atan();
    return Nd4j.createDouble(c.getReal(), c.getImaginary());
}