public boolean matches(SameDiff sameDiff, DifferentialFunction rootFn){

        if(!root.matches(sameDiff, rootFn)){
            return false;
        }

        SDVariable[] inputs = rootFn.args();
        int inCount = inputs == null ? 0 : inputs.length;
        if(inputCount != null){
            if(inCount != this.inputCount)
                return false;
        }

        SDVariable[] outputs = rootFn.outputVariables();
        int outCount = outputs == null ? 0 : outputs.length;
        if(outputCount != null){
            if(outCount != outputCount)
                return false;
        }

        for(Map<Integer,OpPredicate> m : Arrays.asList(opInputMatchPredicates, opInputSubgraphPredicates)) {
            for (Map.Entry<Integer, OpPredicate> e : m.entrySet()) {
                int inNum = e.getKey();
                if (inNum >= inCount) {
                    return false;
                }

                SDVariable in = inputs[inNum];
                DifferentialFunction df = sameDiff.getVariableOutputFunction(in.getVarName());
                if (df == null || !e.getValue().matches(sameDiff, df)) {
                    return false;
                }
            }
        }

        return true;
    }
public boolean matches ( SameDiff sameDiff , DifferentialFunction rootFn ) { if ( ! root . matches ( sameDiff , rootFn ) ) { return false ; } SDVariable [ ] inputs = rootFn . args ( ) ; int inCount = inputs == null ? 0 : inputs . length ; if ( inputCount != null ) { if ( inCount != this . inputCount ) return false ; } SDVariable [ ] outputs = rootFn . outputVariables ( ) ; int outCount = outputs == null ? 0 : outputs . length ; if ( outputCount != null ) { if ( outCount != outputCount ) return false ; } for ( Map < Integer , OpPredicate > m : Arrays . asList ( opInputMatchPredicates , opInputSubgraphPredicates ) ) { for ( Map . Entry < Integer , OpPredicate > e : m . entrySet ( ) ) { int inNum = e . getKey ( ) ; if ( inNum >= inCount ) { return false ; } SDVariable in = inputs [ inNum ] ; DifferentialFunction df = sameDiff . getVariableOutputFunction ( in . getVarName ( ) ) ; if ( df == null || ! e . getValue ( ) . matches ( sameDiff , df ) ) { return false ; } } } return true ; }
Determine if the subgraph, starting with the root function, matches the predicate

@param sameDiff SameDiff instance the function belongs to
@param rootFn   Function that defines the root of the subgraph
@return True if the subgraph mathes the predicate