<s> import ctypes as ct <EOL> from quagga . context import Context <EOL> class GradientReversalBlock ( object ) : <EOL> def __init__ ( self , x , scale_factor = <NUM_LIT:1.0> ) : <EOL> self . context = Context ( x . device_id ) <EOL> device_id = self . context . device_id <EOL> self . output = x <EOL> if x . bpropagable : <EOL> _ , self . dL_dx = x . register_usage ( device_id , device_id ) <EOL> self . scale_factor = ct . c_float ( - scale_factor ) <EOL> def bprop ( self ) : <EOL> self . dL_dx . scale ( self . context , self . scale_factor ) </s>
