Java Code Examples for org.nd4j.autodiff.samediff.SameDiff#addArgsFor()

The following examples show how to use org.nd4j.autodiff.samediff.SameDiff#addArgsFor() . 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: BaseIndexAccumulation.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public BaseIndexAccumulation(SameDiff sameDiff,
                             SDVariable i_v,
                             int[] dimensions) {
    super(sameDiff,new Object[]{dimensions});
    if (i_v != null) {
        this.dimensions = dimensions;
        f().validateDifferentialFunctionsameDiff(i_v);
        sameDiff.addArgsFor(new SDVariable[]{i_v},this);
        if(Shape.isPlaceholderShape(i_v.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v.getVarName());
        }

        this.xVertexId = i_v.getVarName();
    } else {
        throw new IllegalArgumentException("Input not null variable.");
    }
}
 
Example 2
Source File: BaseScalarBoolOp.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public BaseScalarBoolOp(SameDiff sameDiff,
                        SDVariable i_v,
                        Number scalar,
                        boolean inPlace,
                        Object[] extraArgs) {
    super(sameDiff,inPlace,extraArgs);
    this.scalarValue = Nd4j.scalar(i_v.dataType(), scalar);
    if (i_v != null) {
        this.xVertexId = i_v.name();
        sameDiff.addArgsFor(new String[]{xVertexId},this);
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v, this);
    } else {
        throw new IllegalArgumentException("Input not null variable.");
    }

}
 
Example 3
Source File: BaseBroadcastBoolOp.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public BaseBroadcastBoolOp(SameDiff sameDiff,
                           SDVariable i_v1,
                           SDVariable i_v2,
                           boolean inPlace,
                           int[] dimension) {
    super(sameDiff, inPlace, new Object[]{i_v2});
    if (i_v1 != null && i_v2 != null) {
        this.sameDiff = sameDiff;
        this.inPlace = inPlace;
        this.dimension = dimension;
        sameDiff.addArgsFor(new SDVariable[]{i_v1,i_v2},this);

    } else {
        throw new IllegalArgumentException("Input not null variables.");
    }
}
 
Example 4
Source File: BaseScalarOp.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public BaseScalarOp(SameDiff sameDiff,
                    SDVariable i_v,
                    Number scalar,
                    boolean inPlace,
                    Object[] extraArgs) {
    super(sameDiff,inPlace,extraArgs);
    this.scalarValue = scalar;
    if (i_v != null) {
        this.xVertexId = i_v.getVarName();
        sameDiff.addArgsFor(new String[]{xVertexId},this);
        if(Shape.isPlaceholderShape(i_v.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v.getVarName());
        }
        f().validateDifferentialFunctionsameDiff(i_v);
    } else {
        throw new IllegalArgumentException("Input not null variable.");
    }

}
 
Example 5
Source File: BaseAccumulation.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public BaseAccumulation(SameDiff sameDiff,
                        SDVariable i_v,
                        SDVariable i_v2,
                        int[] dimensions,boolean keepDims) {
    super(sameDiff,new Object[]{dimensions});
    if (i_v != null) {
        if(dimensions == null || dimensions.length < 1)
            dimensions = new int[] {Integer.MAX_VALUE};

        this.dimensions = dimensions;

        this.xVertexId = i_v.getVarName();
        this.yVertexId = i_v2.getVarName();
        f().validateDifferentialFunctionsameDiff(i_v);
        f().validateDifferentialFunctionsameDiff(i_v2);
        this.keepDims = keepDims;
        sameDiff.addArgsFor(new String[]{xVertexId,yVertexId},this);

    } else {
        throw new IllegalArgumentException("Input not null variable.");
    }

}
 
Example 6
Source File: BaseBroadcastBoolOp.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public BaseBroadcastBoolOp(SameDiff sameDiff,
                           SDVariable i_v,
                           long[] shape,
                           boolean inPlace,
                           int[] dimension,
                           Object[] extraArgs) {
    super(sameDiff, inPlace, extraArgs);
    this.dimension = dimension;
    if (i_v != null) {
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v, this);
        sameDiff.addArgsFor(new SDVariable[]{i_v},this);


    } else {
        throw new IllegalArgumentException("Input not null variable.");
    }


}
 
Example 7
Source File: BaseBroadcastBoolOp.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public BaseBroadcastBoolOp(SameDiff sameDiff,
                           SDVariable i_v1,
                           SDVariable i_v2,
                           int[] dimension,
                           Object[] extraArgs) {
    super(sameDiff, extraArgs);
    this.dimension = dimension;
    if (i_v1 != null && i_v2 != null) {
        this.sameDiff = sameDiff;
        sameDiff.addArgsFor(new SDVariable[]{i_v1,i_v2},this);

    } else {
        throw new IllegalArgumentException("Input not null variables.");
    }


}
 
Example 8
Source File: BaseIndexAccumulation.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public BaseIndexAccumulation(SameDiff sameDiff,
                             SDVariable i_v,
                             SDVariable i_v2,
                             boolean keepDims,
                             int[] dimensions) {
    super(sameDiff,null);
    if (i_v != null) {
        this.dimensions = dimensions;
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v, this);
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v2, this);
        this.xVertexId = i_v.name();
        this.yVertexId = i_v2.name();
        sameDiff.addArgsFor(new SDVariable[]{i_v,i_v2},this);
    } else {
        throw new IllegalArgumentException("Input not null variable.");
    }
    this.keepDims = keepDims;
    defineDimensions(dimensions);
}
 
Example 9
Source File: BaseBroadcastOp.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public BaseBroadcastOp(SameDiff sameDiff,
                       SDVariable i_v1,
                       SDVariable i_v2,
                       int[] dimension,
                       Object[] extraArgs) {
    super(sameDiff, extraArgs);
    this.dimension = dimension;
    if (i_v1 != null && i_v2 != null) {
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v1, this);
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v2, this);

        this.sameDiff = sameDiff;
        sameDiff.addArgsFor(new SDVariable[]{i_v1,i_v2},this);

    } else {
        throw new IllegalArgumentException("Input not null variables.");
    }


}
 
Example 10
Source File: BaseTransformOp.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public BaseTransformOp(SameDiff sameDiff,
                       SDVariable i_v,
                       long[] shape,
                       boolean inPlace,
                       Object[] extraArgs) {
    super(sameDiff,inPlace,extraArgs);

    if (i_v != null) {
        f().validateDifferentialFunctionsameDiff(i_v);
        this.xVertexId = i_v.getVarName();
        sameDiff.addArgsFor(new SDVariable[]{i_v},this);
        if(i_v.getShape() != null) {
            this.n = ArrayUtil.prod(i_v.getShape());
        }

        if(Shape.isPlaceholderShape(i_v.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v.getVarName());
        }


    } else {
        throw new IllegalArgumentException("Input must not null variable.");
    }

}
 
Example 11
Source File: BaseTransformOp.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public BaseTransformOp(SameDiff sameDiff,
                       SDVariable i_v1,
                       SDVariable i_v2,
                       boolean inPlace) {
    super(sameDiff,inPlace,new Object[] {i_v2});
    if (i_v1 != null && i_v2 != null) {
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v1, this);
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v2, this);
        this.sameDiff = sameDiff;
        this.inPlace = inPlace;
        this.xVertexId = i_v1.name();
        this.yVertexId = i_v2.name();
        sameDiff.addArgsFor(new SDVariable[]{i_v1,i_v2},this);
    } else {
        throw new IllegalArgumentException("Input not null variables.");
    }


}
 
Example 12
Source File: BaseBroadcastOp.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public BaseBroadcastOp(SameDiff sameDiff,
                       SDVariable i_v,
                       long[] shape,
                       boolean inPlace,
                       int[] dimension,
                       Object[] extraArgs) {
    super(sameDiff, inPlace, extraArgs);
    this.dimension = dimension;
    if (i_v != null) {
        f().validateDifferentialFunctionsameDiff(i_v);
        sameDiff.addArgsFor(new SDVariable[]{i_v},this);


    } else {
        throw new IllegalArgumentException("Input not null variable.");
    }


}
 
Example 13
Source File: BaseTransformOp.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public BaseTransformOp(SameDiff sameDiff,
                       SDVariable i_v1,
                       SDVariable i_v2,
                       Object[] extraArgs) {
    super(sameDiff,extraArgs);
    if (i_v1 != null && i_v2 != null) {

        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v1, this);
        SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v2, this);
        this.sameDiff = sameDiff;
        this.xVertexId = i_v1.name();
        this.yVertexId = i_v2.name();
        sameDiff.addArgsFor(new SDVariable[]{i_v1,i_v2},this);
    } else {
        throw new IllegalArgumentException("Input not null variables.");
    }

}
 
Example 14
Source File: BaseBroadcastOp.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public BaseBroadcastOp(SameDiff sameDiff,
                       SDVariable i_v1,
                       SDVariable i_v2,
                       boolean inPlace,
                       int[] dimension) {
    super(sameDiff, inPlace, new Object[]{i_v2});
    if (i_v1 != null && i_v2 != null) {
        f().validateDifferentialFunctionsameDiff(i_v1);
        f().validateDifferentialFunctionsameDiff(i_v2);
        this.sameDiff = sameDiff;
        this.inPlace = inPlace;
        this.dimension = dimension;
        if(Shape.isPlaceholderShape(i_v1.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v1.getVarName());
        }

        if(Shape.isPlaceholderShape(i_v2.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v2.getVarName());
        }
        sameDiff.addArgsFor(new SDVariable[]{i_v1,i_v2},this);

    } else {
        throw new IllegalArgumentException("Input not null variables.");
    }

}
 
Example 15
Source File: BaseIndexAccumulation.java    From nd4j with Apache License 2.0 6 votes vote down vote up
public BaseIndexAccumulation(SameDiff sameDiff,
                             SDVariable i_v,
                             SDVariable i_v2,
                             int[] dimensions) {
    super(sameDiff,new Object[]{dimensions});
    if (i_v != null) {
        this.dimensions = dimensions;
        f().validateDifferentialFunctionsameDiff(i_v);
        f().validateDifferentialFunctionsameDiff(i_v2);
        this.xVertexId = i_v.getVarName();
        this.yVertexId = i_v2.getVarName();
        sameDiff.addArgsFor(new SDVariable[]{i_v,i_v2},this);

        if(Shape.isPlaceholderShape(i_v.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v.getVarName());
        }

        if(Shape.isPlaceholderShape(i_v2.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v2.getVarName());
        }
    } else {
        throw new IllegalArgumentException("Input not null variable.");
    }
}
 
Example 16
Source File: BaseScalarOp.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public BaseScalarOp(SameDiff sameDiff,
                    @NonNull SDVariable i_v,
                    Number scalar,
                    boolean inPlace,
                    Object[] extraArgs) {
    super(sameDiff,inPlace,extraArgs);
    this.scalarValue = Nd4j.scalar(i_v.dataType(), scalar);
    this.xVertexId = i_v.name();
    sameDiff.addArgsFor(new String[]{xVertexId},this);
    SameDiffUtils.validateDifferentialFunctionSameDiff(sameDiff, i_v, this);
}
 
Example 17
Source File: DepthwiseConv2D.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Builder(builderMethodName = "builder")
public DepthwiseConv2D(SameDiff sameDiff,
                       SDVariable[] inputFunctions,
                       INDArray[] inputArrays, INDArray[] outputs,
                       Conv2DConfig config) {
    super(null, inputArrays, outputs);
    this.sameDiff = sameDiff;
    this.config = config;
    addArgs();
    sameDiff.putFunctionForId(this.getOwnName(), this);    //Normally called in DynamicCustomOp constructor, via setInstanceId - but sameDiff field is null at that point
    sameDiff.addArgsFor(inputFunctions, this);
}
 
Example 18
Source File: BaseTransformOp.java    From nd4j with Apache License 2.0 5 votes vote down vote up
public BaseTransformOp(SameDiff sameDiff,
                       SDVariable i_v1,
                       SDVariable i_v2,
                       boolean inPlace) {
    super(sameDiff,inPlace,new Object[] {i_v2});
    if (i_v1 != null && i_v2 != null) {
        f().validateDifferentialFunctionsameDiff(i_v1);
        f().validateDifferentialFunctionsameDiff(i_v2);
        this.sameDiff = sameDiff;
        this.inPlace = inPlace;
        this.xVertexId = i_v1.getVarName();
        this.yVertexId = i_v2.getVarName();
        sameDiff.addArgsFor(new SDVariable[]{i_v1,i_v2},this);
        if(Shape.isPlaceholderShape(i_v1.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v1.getVarName());
        }

        if(Shape.isPlaceholderShape(i_v2.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v2.getVarName());
        }
        if(i_v1.getShape() != null)
            this.n = ArrayUtil.prod(i_v1.getShape());


    } else {
        throw new IllegalArgumentException("Input not null variables.");
    }


}
 
Example 19
Source File: BaseRandomOp.java    From nd4j with Apache License 2.0 5 votes vote down vote up
public BaseRandomOp(SameDiff sameDiff,
                        SDVariable i_v) {
    if (i_v != null) {
        this.sameDiff = sameDiff;
        this.xVertexId = i_v.getVarName();
        sameDiff.addArgsFor(new String[]{xVertexId},this);
        if(Shape.isPlaceholderShape(i_v.getShape())) {
            sameDiff.addPropertyToResolve(this,i_v.getVarName());
        }
    } else {
        throw new IllegalArgumentException("Input can't be null.");
    }
}
 
Example 20
Source File: DifferentialFunction.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Add the various arguments for
 * this function
 * @param sameDiff
 * @param inPlace
 * @param args
 */
public DifferentialFunction(SameDiff sameDiff, boolean inPlace, SDVariable[] args) {
    this.sameDiff = sameDiff;
    this.inPlace = inPlace;
    setInstanceId();
    if(sameDiff != null) {
        sameDiff.addArgsFor(args, this);
        for (int i = 0; i < args.length; i++) {
            if (args[i].isPlaceHolder()) {
                sameDiff.addPropertyToResolve(this, args[i].getVarName());
            }
        }
    }
}