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

The following examples show how to use org.nd4j.linalg.factory.Nd4j#isExperimentalMode() . 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: CustomOpsTests.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoneInplaceOp5() {
    if (!Nd4j.isExperimentalMode())
        return;

    val arrayX = Nd4j.create(DataType.INT, 10, 10);
    val arrayY = Nd4j.create(DataType.FLOAT, 10, 10);

    arrayX.assign(4);
    arrayY.assign(2.0);

    val exp = Nd4j.create(DataType.FLOAT,10, 10).assign(6);

    CustomOp op = DynamicCustomOp.builder("add")
            .addInputs(arrayX, arrayY)
            .callInplace(false)
            .build();

    Nd4j.getExecutioner().exec(op);

    val res = op.getOutputArgument(0);
    assertEquals(DataType.FLOAT, res.dataType());
    assertEquals(exp, res);
}
 
Example 2
Source File: Shape.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public static DataType pickPairwiseDataType(@NonNull DataType typeX, @NonNull Number number) {
    if (!Nd4j.isExperimentalMode())
        return typeX;

    if (number instanceof Double) {
        return pickPairwiseDataType(typeX, DataType.DOUBLE);
    } else if (number instanceof Float) {
        return pickPairwiseDataType(typeX, DataType.FLOAT);
    } else if (number instanceof Long) {
        return pickPairwiseDataType(typeX, DataType.LONG);
    } else if (number instanceof Integer) {
        return pickPairwiseDataType(typeX, DataType.INT);
    } else if (number instanceof Short) {
        return pickPairwiseDataType(typeX, DataType.SHORT);
    } else if (number instanceof Byte) {
        return pickPairwiseDataType(typeX, DataType.BYTE);
    } else {
        throw new UnsupportedOperationException("Unknown Number used: [" + number.getClass().getCanonicalName() + "]");
    }
}
 
Example 3
Source File: Shape.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public static DataType pickPairwiseDataType(@NonNull DataType typeX, @NonNull DataType typeY) {
    if (!Nd4j.isExperimentalMode())
        return typeX;

    if (typeX == typeY)
        return typeX;

    val rX = isR(typeX);
    val rY = isR(typeY);

    // if X is float - use it
    if (rX && !rY)
        return typeX;

    // if Y is float - use it
    if (!rX && rY)
        return typeY;

    // if both data types are float - return biggest one
    if (rX && rY) {
        // if we allow precision boost, then we pick bigger data type
        if (Nd4j.isPrecisionBoostAllowed()) {
            return max(typeX, typeY);
        } else {
            // and we return first operand otherwise
            return typeX;
        }

    }

    // if that's not real type, we apply same rules
    if (!rX && !rY) {
        if (Nd4j.isPrecisionBoostAllowed()) {
            return max(typeX, typeY);
        } else {
            // and we return first operand otherwise
            return typeX;
        }
    }

    return typeX;
}