parameters: (node, reverse_channels)
return_statement: return True
docstring: r"""
          BEFORE                              AFTER
  
            previous_op                                       previous_op'
                |                                                 |
          ReverseChannels  previous_op'    previous_op     ReverseChannels
                       \     /                        \     /
                       Eltwise                        Eltwise
                                                        |
                                                  ReverseChannels
  
          returns boolean value whatever we should continue propagating current ReverseChannels operation down or not
docstring_summary: r"""
          BEFORE                              AFTER
docstring_tokens: r BEFORE AFTER
function: def pass_rc_through_eltwise(node, reverse_channels):
          r"""
          BEFORE                              AFTER
  
            previous_op                                       previous_op'
                |                                                 |
          ReverseChannels  previous_op'    previous_op     ReverseChannels
                       \     /                        \     /
                       Eltwise                        Eltwise
                                                        |
                                                  ReverseChannels
  
          returns boolean value whatever we should continue propagating current ReverseChannels operation down or not
          """
          before_shape = reverse_channels.out_port(0).data.get_shape()
  
          port_axis = []
          for idx, port in node.in_ports().items():
              if port.get_connection().get_source().node.id == reverse_channels.id:
                  continue
              shape = port.data.get_shape()
              non_one_dims = np.where(shape != 1)[0]
              if shape[reverse_channels.axis] == 1:
                  continue  # nothing to flip for this input
              if len(non_one_dims) == 1 and shape[non_one_dims.item()] == reverse_channels.order.size:
                  new_axis = non_one_dims.item()
              elif np.array_equal(before_shape, shape):
                  new_axis = reverse_channels.axis
              else:
                  # shape has multiple non-one values and shape is not fully broadcasted to value port shape
                  # it is safe not to propagate reverse channels
                  return False
              port_axis.append((port, new_axis))
  
          # reversing eltwise inputs where applicable
          for port, axis in port_axis:
              ric_copy = reverse_channels.copy_node({'axis': mo_array(axis), 'order': mo_array(reverse_channels.order)})
  
              src = port.get_connection().get_source()
              port.get_connection().set_source(ric_copy.out_port(0))
              src.disconnect()
              src.connect(ric_copy.in_port(0))
  
          # detaching reverse_channels node from the graph
          reverse_channels.out_port(0).get_connection().set_source(
              reverse_channels.in_port(0).get_connection().get_source())
          reverse_channels.in_port(0).disconnect()
  
          # propagating reverse_channels node to the output port of eltwise
          node.out_port(0).get_connection().set_source(reverse_channels.out_port(0))
          node.out_port(0).disconnect()
          node.out_port(0).connect(reverse_channels.in_port(0))
  
          # propagated reverse_channels successfully through current node, will continue propagation
          return True
function_tokens: def pass_rc_through_eltwise ( node , reverse_channels ) : before_shape = reverse_channels . out_port ( 0 ) . data . get_shape ( ) port_axis = [ ] for idx , port in node . in_ports ( ) . items ( ) : if port . get_connection ( ) . get_source ( ) . node . id == reverse_channels . id : continue shape = port . data . get_shape ( ) non_one_dims = np . where ( shape != 1 ) [ 0 ] if shape [ reverse_channels . axis ] == 1 : continue # nothing to flip for this input if len ( non_one_dims ) == 1 and shape [ non_one_dims . item ( ) ] == reverse_channels . order . size : new_axis = non_one_dims . item ( ) elif np . array_equal ( before_shape , shape ) : new_axis = reverse_channels . axis else : # shape has multiple non-one values and shape is not fully broadcasted to value port shape # it is safe not to propagate reverse channels return False port_axis . append ( ( port , new_axis ) ) # reversing eltwise inputs where applicable for port , axis in port_axis : ric_copy = reverse_channels . copy_node ( { 'axis' : mo_array ( axis ) , 'order' : mo_array ( reverse_channels . order ) } ) src = port . get_connection ( ) . get_source ( ) port . get_connection ( ) . set_source ( ric_copy . out_port ( 0 ) ) src . disconnect ( ) src . connect ( ric_copy . in_port ( 0 ) ) # detaching reverse_channels node from the graph reverse_channels . out_port ( 0 ) . get_connection ( ) . set_source ( reverse_channels . in_port ( 0 ) . get_connection ( ) . get_source ( ) ) reverse_channels . in_port ( 0 ) . disconnect ( ) # propagating reverse_channels node to the output port of eltwise node . out_port ( 0 ) . get_connection ( ) . set_source ( reverse_channels . out_port ( 0 ) ) node . out_port ( 0 ) . disconnect ( ) node . out_port ( 0 ) . connect ( reverse_channels . in_port ( 0 ) ) # propagated reverse_channels successfully through current node, will continue propagation return True