#NEWLINE# @ staticmethod #NEWLINE# def _gpu_mdmt( mat , diags ) : #NEWLINE# #INDENT# '\n        Performs the matrix multiplication M * D * M^T.\n\n        First tries to do this on the GPU. If this throws a MemoryError, it\n        falls back to the CPU, with a warning message.\n\n        Parameters\n        ----------\n        mat : WRITEME\n        diags : WRITEME\n        ' #NEWLINE# floatX = theano . config . floatX #NEWLINE# if ( not hasattr ( ZCA . _gpu_mdmt , 'theano_func' ) ) : #NEWLINE# #INDENT# t_mat = theano . tensor . matrix ( 'M' ) #NEWLINE# t_diags = theano . tensor . vector ( 'D' ) #NEWLINE# result = theano . tensor . dot ( ( mat * t_diags ) , t_mat . T ) #NEWLINE# ZCA . _gpu_mdmt . theano_func = theano . function ( [ t_mat , t_diags ] , result , allow_input_downcast = True ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( str ( mat . dtype ) != floatX ) : #NEWLINE# #INDENT# warnings . warn ( ( 'Implicitly converting mat from dtype=%s to %s for gpu' % ( mat . dtype , floatX ) ) ) #NEWLINE# #UNINDENT# if ( str ( diags . dtype ) != floatX ) : #NEWLINE# #INDENT# warnings . warn ( ( 'Implicitly converting diag from dtype=%s to %s for gpu' % ( diags . dtype , floatX ) ) ) #NEWLINE# #UNINDENT# return ZCA . _gpu_mdmt . theano_func ( mat , diags ) #NEWLINE# #UNINDENT# except MemoryError : #NEWLINE# #INDENT# warnings . warn ( 'M * D * M^T was too big to fit on GPU. Re-doing with CPU. Consider using THEANO_FLAGS="device=cpu" for your next preprocessor run' ) #NEWLINE# return numpy . dot ( ( mat * diags ) , mat . T )