#NEWLINE# @ staticmethod #NEWLINE# def extract_type_tens( expression ) : #NEWLINE# #INDENT# '\n        Extract from a ``TensExpr`` all elements of this type.\n\n        Returns two tensor expressions:\n\n        * the first contains all ``TensorHead`` of this type.\n        * the second contains all remaining.\n\n\n        ' #NEWLINE# if isinstance ( expression , Tensor ) : #NEWLINE# #INDENT# sp = [ expression ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( expression , TensMul ) : #NEWLINE# #INDENT# sp = expression . args #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'wrong type' ) #NEWLINE# #UNINDENT# #UNINDENT# new_expr = S . One #NEWLINE# residual_expr = S . One #NEWLINE# for i in sp : #NEWLINE# #INDENT# if ( isinstance ( i , Tensor ) and isinstance ( i . args [ 0 ] , GammaMatrixHead ) ) : #NEWLINE# #INDENT# new_expr *= i #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# residual_expr *= i #NEWLINE# #UNINDENT# #UNINDENT# return ( new_expr , residual_expr )