nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SameDiff.java
public SDVariable var(final SDVariable arr) {
        if (variableMap.containsKey(arr.getVarName()) && variableMap.get(arr.getVarName()).getArr() != null)
            return variableMap.get(arr.getVarName());


        if (arr.getVarName() == null || arr.getVarName().length() < 1)
            throw new IllegalArgumentException("Name for variable must be defined");

        if (arr == null)
            throw new IllegalArgumentException("Array for " + arr.getVarName() + " must not be null");

        if (workspace == null)
            initWorkspace();

        final SDVariable ret = SDVariable.builder()
                .sameDiff(this)
                .shape(arr.getShape())
                .varName(arr.getVarName())
                .weightInitScheme(new NDArraySupplierInitScheme(new NDArraySupplierInitScheme.NDArraySupplier() {
                    @Override
                    public INDArray getArr() {
                        /**
                         * Pre allocate the array if it doesn't already exist.
                         * The reason we do this is to avoid race conditions with
                         * {@link #allocate()}
                         */
                        if (arr.getArr() == null) {
                            INDArray retArr = arr.getWeightInitScheme().create(arr.getShape());
                            associateArrayWithVariable(retArr, arr);
                        }
                        return arr.getArr();
                    }
                }))
                .build();


        variableMap.put(arr.getVarName(), ret);
        return ret;

    }
public SDVariable var(final SDVariable arr) {
        if (variableMap.containsKey(arr.getVarName()) && variableMap.get(arr.getVarName()).getArr() != null)
            return variableMap.get(arr.getVarName());


        if (arr.getVarName() == null || arr.getVarName().length() < 1)
            throw new IllegalArgumentException("Name for variable must be defined");

        if (arr == null)
            throw new IllegalArgumentException("Array for " + arr.getVarName() + " must not be null");

        if (workspace == null)
            initWorkspace();

        final SDVariable ret = SDVariable.builder()
                .sameDiff(this)
                .shape(arr.getShape())
                .varName(arr.getVarName())
                .weightInitScheme(new NDArraySupplierInitScheme(new NDArraySupplierInitScheme.NDArraySupplier() {
                    @Override
                    public INDArray getArr() {
                        /**
                         * Pre allocate the array if it doesn't already exist.
                         * The reason we do this is to avoid race conditions with
                         * {@link #allocate()}
                         */
                        if (arr.getArr() == null) {
                            INDArray retArr = arr.getWeightInitScheme().create(arr.getShape());
                            associateArrayWithVariable(retArr, arr);
                        }
                        return arr.getArr();
                    }
                }))
                .build();


        variableMap.put(arr.getVarName(), ret);
        return ret;

    }
public SDVariable var ( final SDVariable arr ) { if ( variableMap . containsKey ( arr . getVarName ( ) ) && variableMap . get ( arr . getVarName ( ) ) . getArr ( ) != null ) return variableMap . get ( arr . getVarName ( ) ) ; if ( arr . getVarName ( ) == null || arr . getVarName ( ) . length ( ) < 1 ) throw new IllegalArgumentException ( "Name for variable must be defined" ) ; if ( arr == null ) throw new IllegalArgumentException ( "Array for " + arr . getVarName ( ) + " must not be null" ) ; if ( workspace == null ) initWorkspace ( ) ; final SDVariable ret = SDVariable . builder ( ) . sameDiff ( this ) . shape ( arr . getShape ( ) ) . varName ( arr . getVarName ( ) ) . weightInitScheme ( new NDArraySupplierInitScheme ( new NDArraySupplierInitScheme . NDArraySupplier ( ) { @ Override public INDArray getArr ( ) { /**
                         * Pre allocate the array if it doesn't already exist.
                         * The reason we do this is to avoid race conditions with
                         * {@link #allocate()}
                         */ if ( arr . getArr ( ) == null ) { INDArray retArr = arr . getWeightInitScheme ( ) . create ( arr . getShape ( ) ) ; associateArrayWithVariable ( retArr , arr ) ; } return arr . getArr ( ) ; } } ) ) . build ( ) ; variableMap . put ( arr . getVarName ( ) , ret ) ; return ret ; }
Initialize a {@link SDVariable}
reference tying this variable to this
samediff instance.
<p>
{@link NDArraySupplierInitScheme} is used
to ensure that if the array is allocated anywhere
and {@link SameDiff} instance to exist as a copy of the variable.

@param arr
@return
Initialize a { @link SDVariable } reference tying this variable to this samediff instance . <p > { @link NDArraySupplierInitScheme } is used to ensure that if the array is allocated anywhere and { @link SameDiff } instance to exist as a copy of the variable .