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",")"]
docstr: Transpose the last 2 dims.
  
  - ``v``: (Var, must be a tensor).
  - ``before_op``: (Operation) The op right before the newly added ``transpose`` op.
  - ``name``: Name for the ``transpose`` op if provided.
docstr_tok: ["Transpose","the","last","2","dims",".","-","``","v","``",":","(","Var",",","must","be","a","tensor",")",".","-","``","before_op","``",":","(","Operation",")","The","op","right","before","the","newly","added","``","transpose","``","op",".","-","``","name","``",":","Name","for","the","``","transpose","``","op","if","provided","."]
code: def _transpose(v, before_op, name=None):
      """
      Transpose the last 2 dims.
  
      - ``v``: (Var, must be a tensor).
      - ``before_op``: (Operation) The op right before the newly added ``transpose`` op.
      - ``name``: Name for the ``transpose`` op if provided.
      """
      perm = list(range(v.rank))
      perm[-2], perm[-1] = perm[-1], perm[-2]
  
      if name is None:
          return mb.transpose(x=v, perm=perm, before_op=before_op)
      else:
          return mb.transpose(
              x=v, perm=perm, before_op=before_op, name=name
          )
  
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 3 for calling the fuse_matmul_weight_bias obj's underlying member method code with example usage: obj._transpose(v, before_op, name) and returns: mb, mb