#NEWLINE# def sample_gpu( self , shape ) : #NEWLINE# #INDENT# ps = cuda . cupy . random . uniform ( size = shape , dtype = numpy . float32 ) #NEWLINE# vs = cuda . elementwise ( 'T ps, raw T threshold , raw S values, int32 b' , 'int32 vs' , '\n            T pb = ps * b;\n            int index = __float2int_rd(pb);\n            // fill_uniform sometimes returns 1.0, so we need to check index\n            if (index >= b) {\n              index = 0;\n            }\n            int lr = threshold[index] < pb - index;\n            vs = values[index * 2 + lr];\n            ' , 'walker_alias_sample' ) ( ps , self . threshold , self . values , len ( self . threshold ) ) #NEWLINE# return vs