Java Code Examples for org.nd4j.linalg.api.buffer.DataType#isFPType()

The following examples show how to use org.nd4j.linalg.api.buffer.DataType#isFPType() . 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: BaseLossBp.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public List<DataType> calculateOutputDataTypes(List<DataType> inputDataTypes){
    Preconditions.checkState(inputDataTypes.get(0).isFPType(), "Input 0 (predictions) must be a floating point type; inputs datatypes are %s for %s",
            inputDataTypes, getClass());
    DataType dt0 = inputDataTypes.get(0);
    DataType dt1 = arg(1).dataType();
    DataType dt2 = arg(2).dataType();
    if(!dt1.isFPType())
        dt1 = dt0;
    if(!dt2.isFPType())
        dt2 = dt0;
    return Arrays.asList(dt0, dt1, dt2);
}
 
Example 2
Source File: MergeAvg.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public List<DataType> calculateOutputDataTypes(List<DataType> dataTypes){
    DataType first = dataTypes.get(0);
    for( int i=1; i<dataTypes.size(); i++ ){
        DataType dt = dataTypes.get(i);
        Preconditions.checkState(first == dt, "All inputs must have same datatype - got %s and %s for inputs 0 and %s respectively", first, dt, i);
    }
    //Output type is same as input types if FP, or default FP type otherwise
    if(first.isFPType()){
        return Collections.singletonList(first);
    } else {
        return Collections.singletonList(Nd4j.defaultFloatingPointType());
    }
}
 
Example 3
Source File: BaseReduceFloatOp.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public List<LongShapeDescriptor> calculateOutputShape(OpContext oc) {
    INDArray x = oc != null ? oc.getInputArray(0) : x();

    if(x == null)
        return Collections.emptyList();

    //Calculate reduction shape. Note that reduction on scalar - returns a scalar
    long[] reducedShape = x.rank() == 0 ? x.shape() : Shape.getReducedShape(x.shape(),dimensions, isKeepDims());
    DataType retType = arg().dataType();
    if(!retType.isFPType())
        retType = Nd4j.defaultFloatingPointType();
    return Collections.singletonList(LongShapeDescriptor.fromShape(reducedShape, retType));
}