nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/autodiff/samediff/SameDiff.java
public void updateVariableName(String varName, String withName) {
        SDVariable oldVarNameRef = getVariable(varName);
        variableMap.remove(oldVarNameRef.getVarName());
        val oldVarName = varName;
        oldVarNameRef.setVarName(withName);
        variableMap.put(withName, oldVarNameRef);


        for (val reverseValues : outgoingArgsReverse.entrySet()) {
            for (int i = 0; i < reverseValues.getValue().length; i++) {
                if (reverseValues.getValue()[i].equals(oldVarName)) {
                    reverseValues.getValue()[i] = withName;
                }
            }
        }


        for (val reverseValues : incomingArgsReverse.entrySet()) {
            for (int i = 0; i < reverseValues.getValue().length; i++) {
                if (reverseValues.getValue()[i].equals(oldVarName)) {
                    reverseValues.getValue()[i] = withName;
                }
            }
        }

        if (variableNameToArr.containsKey(oldVarName)) {
            val arr = variableNameToArr.remove(oldVarName);
            variableNameToArr.put(withName, arr);
        }


        if (variableNameToShape.containsKey(oldVarName)) {
            val shape = variableNameToShape.remove(oldVarName);
            variableNameToShape.put(withName, shape);
        }


        if (gradients.containsKey(oldVarName)) {
            val grad = gradients.remove(oldVarName);
            gradients.put(withName, grad);
        }

        if (forwardVarForGrad.containsKey(oldVarName)) {
            val forwardGrad = forwardVarForGrad.remove(oldVarName);
            forwardVarForGrad.put(withName, forwardGrad);
        }

        if (placeHolderMap.containsKey(oldVarName)) {
            val placeholders = placeHolderMap.remove(oldVarName);
            placeHolderMap.put(withName, placeholders);
        }


        if (functionsArgsFor.containsKey(oldVarName)) {
            val funcs = functionsArgsFor.remove(oldVarName);
            for (val func : funcs) {
                if (func instanceof BaseOp) {
                    BaseOp baseOp = (BaseOp) func;
                    if (baseOp.getXVertexId() != null && baseOp.getXVertexId().equals(oldVarName)) {
                        baseOp.setXVertexId(withName);
                    }

                    if (baseOp.getYVertexId() != null && baseOp.getYVertexId().equals(oldVarName)) {
                        baseOp.setYVertexId(withName);
                    }

                    if (baseOp.getZVertexId() != null && baseOp.getZVertexId().equals(oldVarName)) {
                        baseOp.setZVertexId(withName);
                    }

                }
            }

            functionsArgsFor.put(withName, funcs);
        }


        if (functionOutputFor.containsKey(oldVarName)) {
            val funcs = functionOutputFor.remove(oldVarName);
            for (val func : funcs) {
                if (func instanceof BaseOp) {
                    BaseOp baseOp = (BaseOp) func;
                    if (baseOp.getXVertexId() != null && baseOp.getXVertexId().equals(oldVarName)) {
                        baseOp.setXVertexId(withName);
                    }

                    if (baseOp.getYVertexId() != null && baseOp.getYVertexId().equals(oldVarName)) {
                        baseOp.setYVertexId(withName);
                    }

                    if (baseOp.getZVertexId() != null && baseOp.getZVertexId().equals(oldVarName)) {
                        baseOp.setZVertexId(withName);
                    }

                }
            }

            functionOutputFor.put(withName, funcs);
        }

        variableMap.remove(oldVarName);


    }
public void updateVariableName(String varName, String withName) {
        SDVariable oldVarNameRef = getVariable(varName);
        variableMap.remove(oldVarNameRef.getVarName());
        val oldVarName = varName;
        oldVarNameRef.setVarName(withName);
        variableMap.put(withName, oldVarNameRef);


        for (val reverseValues : outgoingArgsReverse.entrySet()) {
            for (int i = 0; i < reverseValues.getValue().length; i++) {
                if (reverseValues.getValue()[i].equals(oldVarName)) {
                    reverseValues.getValue()[i] = withName;
                }
            }
        }


        for (val reverseValues : incomingArgsReverse.entrySet()) {
            for (int i = 0; i < reverseValues.getValue().length; i++) {
                if (reverseValues.getValue()[i].equals(oldVarName)) {
                    reverseValues.getValue()[i] = withName;
                }
            }
        }

        if (variableNameToArr.containsKey(oldVarName)) {
            val arr = variableNameToArr.remove(oldVarName);
            variableNameToArr.put(withName, arr);
        }


        if (variableNameToShape.containsKey(oldVarName)) {
            val shape = variableNameToShape.remove(oldVarName);
            variableNameToShape.put(withName, shape);
        }


        if (gradients.containsKey(oldVarName)) {
            val grad = gradients.remove(oldVarName);
            gradients.put(withName, grad);
        }

        if (forwardVarForGrad.containsKey(oldVarName)) {
            val forwardGrad = forwardVarForGrad.remove(oldVarName);
            forwardVarForGrad.put(withName, forwardGrad);
        }

        if (placeHolderMap.containsKey(oldVarName)) {
            val placeholders = placeHolderMap.remove(oldVarName);
            placeHolderMap.put(withName, placeholders);
        }


        if (functionsArgsFor.containsKey(oldVarName)) {
            val funcs = functionsArgsFor.remove(oldVarName);
            for (val func : funcs) {
                if (func instanceof BaseOp) {
                    BaseOp baseOp = (BaseOp) func;
                    if (baseOp.getXVertexId() != null && baseOp.getXVertexId().equals(oldVarName)) {
                        baseOp.setXVertexId(withName);
                    }

                    if (baseOp.getYVertexId() != null && baseOp.getYVertexId().equals(oldVarName)) {
                        baseOp.setYVertexId(withName);
                    }

                    if (baseOp.getZVertexId() != null && baseOp.getZVertexId().equals(oldVarName)) {
                        baseOp.setZVertexId(withName);
                    }

                }
            }

            functionsArgsFor.put(withName, funcs);
        }


        if (functionOutputFor.containsKey(oldVarName)) {
            val funcs = functionOutputFor.remove(oldVarName);
            for (val func : funcs) {
                if (func instanceof BaseOp) {
                    BaseOp baseOp = (BaseOp) func;
                    if (baseOp.getXVertexId() != null && baseOp.getXVertexId().equals(oldVarName)) {
                        baseOp.setXVertexId(withName);
                    }

                    if (baseOp.getYVertexId() != null && baseOp.getYVertexId().equals(oldVarName)) {
                        baseOp.setYVertexId(withName);
                    }

                    if (baseOp.getZVertexId() != null && baseOp.getZVertexId().equals(oldVarName)) {
                        baseOp.setZVertexId(withName);
                    }

                }
            }

            functionOutputFor.put(withName, funcs);
        }

        variableMap.remove(oldVarName);


    }
public void updateVariableName ( String varName , String withName ) { SDVariable oldVarNameRef = getVariable ( varName ) ; variableMap . remove ( oldVarNameRef . getVarName ( ) ) ; val oldVarName = varName ; oldVarNameRef . setVarName ( withName ) ; variableMap . put ( withName , oldVarNameRef ) ; for ( val reverseValues : outgoingArgsReverse . entrySet ( ) ) { for ( int i = 0 ; i < reverseValues . getValue ( ) . length ; i ++ ) { if ( reverseValues . getValue ( ) [ i ] . equals ( oldVarName ) ) { reverseValues . getValue ( ) [ i ] = withName ; } } } for ( val reverseValues : incomingArgsReverse . entrySet ( ) ) { for ( int i = 0 ; i < reverseValues . getValue ( ) . length ; i ++ ) { if ( reverseValues . getValue ( ) [ i ] . equals ( oldVarName ) ) { reverseValues . getValue ( ) [ i ] = withName ; } } } if ( variableNameToArr . containsKey ( oldVarName ) ) { val arr = variableNameToArr . remove ( oldVarName ) ; variableNameToArr . put ( withName , arr ) ; } if ( variableNameToShape . containsKey ( oldVarName ) ) { val shape = variableNameToShape . remove ( oldVarName ) ; variableNameToShape . put ( withName , shape ) ; } if ( gradients . containsKey ( oldVarName ) ) { val grad = gradients . remove ( oldVarName ) ; gradients . put ( withName , grad ) ; } if ( forwardVarForGrad . containsKey ( oldVarName ) ) { val forwardGrad = forwardVarForGrad . remove ( oldVarName ) ; forwardVarForGrad . put ( withName , forwardGrad ) ; } if ( placeHolderMap . containsKey ( oldVarName ) ) { val placeholders = placeHolderMap . remove ( oldVarName ) ; placeHolderMap . put ( withName , placeholders ) ; } if ( functionsArgsFor . containsKey ( oldVarName ) ) { val funcs = functionsArgsFor . remove ( oldVarName ) ; for ( val func : funcs ) { if ( func instanceof BaseOp ) { BaseOp baseOp = ( BaseOp ) func ; if ( baseOp . getXVertexId ( ) != null && baseOp . getXVertexId ( ) . equals ( oldVarName ) ) { baseOp . setXVertexId ( withName ) ; } if ( baseOp . getYVertexId ( ) != null && baseOp . getYVertexId ( ) . equals ( oldVarName ) ) { baseOp . setYVertexId ( withName ) ; } if ( baseOp . getZVertexId ( ) != null && baseOp . getZVertexId ( ) . equals ( oldVarName ) ) { baseOp . setZVertexId ( withName ) ; } } } functionsArgsFor . put ( withName , funcs ) ; } if ( functionOutputFor . containsKey ( oldVarName ) ) { val funcs = functionOutputFor . remove ( oldVarName ) ; for ( val func : funcs ) { if ( func instanceof BaseOp ) { BaseOp baseOp = ( BaseOp ) func ; if ( baseOp . getXVertexId ( ) != null && baseOp . getXVertexId ( ) . equals ( oldVarName ) ) { baseOp . setXVertexId ( withName ) ; } if ( baseOp . getYVertexId ( ) != null && baseOp . getYVertexId ( ) . equals ( oldVarName ) ) { baseOp . setYVertexId ( withName ) ; } if ( baseOp . getZVertexId ( ) != null && baseOp . getZVertexId ( ) . equals ( oldVarName ) ) { baseOp . setZVertexId ( withName ) ; } } } functionOutputFor . put ( withName , funcs ) ; } variableMap . remove ( oldVarName ) ; }
Update the opName for the variable
with the given vertex id

@param varName  the vertex id to update
@param withName thew new opName
Update the opName for the variable with the given vertex id