<s> from . . node import NestedNode <EOL> from . . import backend as T <EOL> def Repeat ( node , n_repeats ) : <EOL> assert n_repeats > <NUM_LIT:0> , "<STR_LIT>" <EOL> new_node = node . copy ( ) <EOL> for i in range ( n_repeats - <NUM_LIT:1> ) : <EOL> new_node = new_node . chain ( node . copy ( ) ) <EOL> return new_node <EOL> MLP = Repeat <EOL> def Last ( node ) : <EOL> return node [ - <NUM_LIT:1> ] <EOL> def First ( node ) : <EOL> return node [ <NUM_LIT:0> ] <EOL> def Freeze ( node ) : <EOL> return node . freeze ( ) <EOL> def Unfreeze ( node ) : <EOL> return node . unfreeze ( ) <EOL> class Norm ( NestedNode ) : <EOL> def __init__ ( self , node , type = '<STR_LIT>' ) : <EOL> super ( Norm , self ) . __init__ ( node ) <EOL> self . type = type <EOL> def _infer ( self , shape_in ) : <EOL> assert isinstance ( shape_in , int ) <EOL> return ( ) <EOL> def forward ( self , X , ** kwargs ) : <EOL> X = self . node . forward ( X , ** kwargs ) <EOL> assert isinstance ( X . get_shape_out ( ) , int ) <EOL> if self . type == '<STR_LIT>' : <EOL> out = T . sum ( T . pow ( X . get_data ( ) , <NUM_LIT:2> ) , axis = - <NUM_LIT:1> ) <EOL> else : <EOL> raise NotImplementedError ( self . type ) <EOL> return X . next ( out , ( ) ) </s>
