<s> from __future__ import absolute_import , print_function , division <EOL> import six . moves . cPickle as pickle <EOL> import os <EOL> import sys <EOL> import theano <EOL> from six import iteritems , itervalues <EOL> DISPLAY_DUPLICATE_KEYS = False <EOL> DISPLAY_MOST_FREQUENT_DUPLICATE_CCODE = False <EOL> dirs = [ ] <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> for compiledir in sys . argv [ <NUM_LIT:1> : ] : <EOL> dirs . extend ( [ os . path . join ( compiledir , d ) for d in os . listdir ( compiledir ) ] ) <EOL> else : <EOL> dirs = os . listdir ( theano . config . compiledir ) <EOL> dirs = [ os . path . join ( theano . config . compiledir , d ) for d in dirs ] <EOL> keys = { } <EOL> mods = { } <EOL> for dir in dirs : <EOL> key = None <EOL> try : <EOL> with open ( os . path . join ( dir , "<STR_LIT>" ) ) as f : <EOL> key = f . read ( ) <EOL> keys . setdefault ( key , <NUM_LIT:0> ) <EOL> keys [ key ] += <NUM_LIT:1> <EOL> del f <EOL> except IOError : <EOL> pass <EOL> try : <EOL> path = os . path . join ( dir , "<STR_LIT>" ) <EOL> if not os . path . exists ( path ) : <EOL> path = os . path . join ( dir , "<STR_LIT>" ) <EOL> with open ( path ) as f : <EOL> mod = f . read ( ) <EOL> mods . setdefault ( mod , ( ) ) <EOL> mods [ mod ] += ( key , ) <EOL> del mod <EOL> del f <EOL> del path <EOL> except IOError : <EOL> print ( dir , "<STR_LIT>" ) <EOL> pass <EOL> if DISPLAY_DUPLICATE_KEYS : <EOL> for k , v in iteritems ( keys ) : <EOL> if v > <NUM_LIT:1> : <EOL> print ( "<STR_LIT>" % ( v , pickle . loads ( k ) ) ) <EOL> nbs_keys = { } <EOL> for val in itervalues ( keys ) : <EOL> nbs_keys . setdefault ( val , <NUM_LIT:0> ) <EOL> nbs_keys [ val ] += <NUM_LIT:1> <EOL> nbs_mod = { } <EOL> nbs_mod_to_key = { } <EOL> more_than_one = <NUM_LIT:0> <EOL> for mod , kk in iteritems ( mods ) : <EOL> val = len ( kk ) <EOL> nbs_mod . setdefault ( val , <NUM_LIT:0> ) <EOL> nbs_mod [ val ] += <NUM_LIT:1> <EOL> if val > <NUM_LIT:1> : <EOL> more_than_one += <NUM_LIT:1> <EOL> nbs_mod_to_key [ val ] = kk <EOL> if DISPLAY_MOST_FREQUENT_DUPLICATE_CCODE : <EOL> m = max ( nbs_mod . keys ( ) ) <EOL> print ( "<STR_LIT>" ) <EOL> for kk in nbs_mod_to_key [ m ] : <EOL> kk = pickle . loads ( kk ) <EOL> print ( kk ) <EOL> print ( "<STR_LIT>" ) <EOL> l = list ( nbs_keys . items ( ) ) <EOL> l . sort ( ) <EOL> print ( l ) <EOL> print ( "<STR_LIT>" ) <EOL> l = list ( nbs_mod . items ( ) ) <EOL> l . sort ( ) <EOL> print ( l ) <EOL> total = sum ( len ( k ) for k in list ( mods . values ( ) ) ) <EOL> uniq = len ( mods ) <EOL> useless = total - uniq <EOL> print ( "<STR_LIT>" , total ) <EOL> print ( "<STR_LIT>" , uniq ) <EOL> print ( "<STR_LIT>" , more_than_one ) <EOL> print ( "<STR_LIT>" , useless , float ( useless ) / total * <NUM_LIT:100> , "<STR_LIT:%>" ) <EOL> print ( "<STR_LIT>" , len ( dirs ) ) </s>
