class_docstr: Convert ``matmul + add/sub`` to ``linear`` whenever possible.
  
  .. code-block::
  
      Given:
          %3 = matmul(x=%1, y=%2)  # %1 or %2 is const and rank 2 (weight)
          ...
          %5 = add(x=%3, y=%4) # %4 is const. add(x=%4, y=%3) is equivalent
                               # sub is similar.
  
      Result:
          # assuming %2 above is const and rank 2
          %5 = linear(x=%1, weight=%2, bias=%4)
class_docstr_tok: ["Convert","``","matmul","+","add\/sub","``","to","``","linear","``","whenever","possible",".","..","code-block",":",":","Given",":","%","3","=","matmul","(","x=","%","1",",","y=","%","2",")","#","%","1","or","%","2","is","const","and","rank","2","(","weight",")","...","%","5","=","add","(","x=","%","3",",","y=","%","4",")","#","%","4","is","const",".","add","(","x=","%","4",",","y=","%","3",")","is","equivalent","#","sub","is","similar",".","Result",":","#","assuming","%","2","above","is","const","and","rank","2","%","5","=","linear","(","x=","%","1",",","weight=","%","2",",","bias=","%","4",")"]
code: def _fuse_matmul_weight_bias_block(self, block):
      fusion_status = False
      for op in list(block.operations):
          for b in op.blocks:
              block_changed = True
              while block_changed:
                  block_changed = self._fuse_matmul_weight_bias_block(b)
          if len(op.blocks) > 0:
              # This op can't be matmul
              continue
  
          add_op = self._find_candidate_op(op)
  
          if add_op is not None:
              fusion_status = self._try_to_transform(op, add_op, block)
              # has to break as the downstream iterator is affected.
              if fusion_status:
                  return fusion_status
      return fusion_status
  
file_path: coremltools/coremltools/converters/mil/mil/passes/defs/optimize_linear.py
imports: import numpy
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Program
  from coremltools.converters.mil.mil.passes.graph_pass import AbstractGraphPass
  from coremltools.converters.mil.mil.passes.helper import block_context_manager
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
label_desc: Use image node_id 5 for calling the fuse_matmul_weight_bias obj's underlying member method code with example usage: obj._fuse_matmul_weight_bias_block(block) and returns: fusion_status, fusion_status