#NEWLINE# def perform( self , node , inp , out_ ) : #NEWLINE# #INDENT# ( x , shp ) = inp #NEWLINE# ( out , ) = out_ #NEWLINE# if ( len ( shp ) != self . ndim ) : #NEWLINE# #INDENT# raise ValueError ( ( 'shape argument to GpuReshape.perform has incorrect length %i, should be %i' % ( len ( shp ) , self . ndim ) ) , shp ) #NEWLINE# #UNINDENT# if ( shp . prod ( ) != x . size ) : #NEWLINE# #INDENT# ss = 1 #NEWLINE# nb_m1 = 0 #NEWLINE# for i in shp : #NEWLINE# #INDENT# if ( i == ( - 1 ) ) : #NEWLINE# #INDENT# nb_m1 += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ss *= node #NEWLINE# #UNINDENT# #UNINDENT# if ( nb_m1 > 1 ) : #NEWLINE# #INDENT# raise ValueError ( 'Only one -1 is accepted in the new shape' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( nb_m1 == 1 ) : #NEWLINE# #INDENT# if ( ( x . size % ss ) != 0 ) : #NEWLINE# #INDENT# raise ValueError ( 'When using -1 in new shape, the computed new shape must be an multiple of the original shape.' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'total size of new array must be unchanged' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# out [ 0 ] = x . reshape ( tuple ( shp ) )