code: def fuse_matmul_weight_bias(prog):
      """
      Convert matmul + add/sub to linear whenever possible.
  
      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)
  
      Inputs:
  
          prog: Program
      """
      for f_name, f in prog.functions.items():
          block_changed = True
          while block_changed:
              block_changed = fuse_matmul_weight_bias_block(f)
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/mil/passes/matmul_weight_bias_fusion.py
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
  from coremltools.converters.mil.mil import Builder
label_desc: Use image node_id 5 for calling a global function with example usage: fuse_matmul_weight_bias(prog) without return types