<s> from chainer import cuda <EOL> from chainer import function <EOL> from chainer import utils <EOL> from chainer . utils import type_check <EOL> import numpy <EOL> class ClippedReLU ( function . Function ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , z ) : <EOL> if not isinstance ( z , float ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> assert z > <NUM_LIT:0> <EOL> self . cap = z <EOL> def check_type_forward ( self , in_types ) : <EOL> type_check . expect ( in_types . size ( ) == <NUM_LIT:1> ) <EOL> x_type , = in_types <EOL> type_check . expect ( x_type . dtype == numpy . float32 ) <EOL> def forward_cpu ( self , x ) : <EOL> return utils . force_array ( numpy . minimum ( <EOL> numpy . maximum ( <NUM_LIT:0> , x [ <NUM_LIT:0> ] ) , self . cap ) ) . astype ( numpy . float32 ) , <EOL> def backward_cpu ( self , x , gy ) : <EOL> return utils . force_array ( <EOL> gy [ <NUM_LIT:0> ] * ( <NUM_LIT:0> < x [ <NUM_LIT:0> ] ) * ( x [ <NUM_LIT:0> ] < self . cap ) ) . astype ( numpy . float32 ) , <EOL> def forward_gpu ( self , x ) : <EOL> return cuda . elementwise ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) ( x [ <NUM_LIT:0> ] , self . cap ) , <EOL> def backward_gpu ( self , x , gy ) : <EOL> gx = cuda . elementwise ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ( x [ <NUM_LIT:0> ] , gy [ <NUM_LIT:0> ] , self . cap ) <EOL> return gx , <EOL> def clipped_relu ( x , z = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> return ClippedReLU ( z ) ( x ) </s>
