<s> import numpy as np <EOL> from . . import backend as T <EOL> from . . node import Node <EOL> class Reshape ( Node ) : <EOL> def __init__ ( self , shape_in , shape_out = None ) : <EOL> super ( Reshape , self ) . __init__ ( ) <EOL> if shape_out is None : <EOL> self . shape_in = None <EOL> self . shape_out = shape_in <EOL> else : <EOL> self . shape_in = shape_in <EOL> self . shape_out = shape_out <EOL> def can_initialize ( self ) : <EOL> return True <EOL> def _infer ( self , shape_in ) : <EOL> return self . shape_out <EOL> def _forward ( self , X ) : <EOL> shape_out = self . get_shape_out ( ) <EOL> if isinstance ( shape_out , tuple ) : <EOL> shape_out = list ( shape_out ) <EOL> elif not isinstance ( shape_out , list ) : <EOL> shape_out = [ shape_out ] <EOL> return T . reshape ( X , [ - <NUM_LIT:1> ] + shape_out ) <EOL> class Flatten ( Node ) : <EOL> def can_initialize ( self ) : <EOL> return True <EOL> def _infer ( self , shape_in ) : <EOL> return np . product ( shape_in ) <EOL> def _forward ( self , X ) : <EOL> return T . flatten ( X ) <EOL> def to_str ( self ) : <EOL> return "<STR_LIT>" % ( self . get_shape_in ( ) , self . get_shape_out ( ) ) </s>
