<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> __author__ = "<STR_LIT>" <EOL> import sys <EOL> import types <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> _ , in_path , out_path = sys . argv <EOL> from pylearn2 . utils import serial <EOL> from theano import shared <EOL> model = serial . load ( in_path ) <EOL> already_fixed = { } <EOL> currently_fixing = [ ] <EOL> blacklist = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> blacklisted_keys = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> postponed_fixes = [ ] <EOL> class Placeholder ( object ) : <EOL> def __init__ ( self , id_to_sub ) : <EOL> self . id_to_sub = id_to_sub <EOL> class FieldFixer ( object ) : <EOL> def __init__ ( self , obj , field , fixed_field ) : <EOL> self . obj = obj <EOL> self . field = field <EOL> self . fixed_field = fixed_field <EOL> def apply ( self ) : <EOL> obj = self . obj <EOL> field = self . field <EOL> fixed_field = already_fixed [ self . fixed_field . id_to_sub ] <EOL> setattr ( obj , field , fixed_field ) <EOL> def fix ( obj , stacklevel = <NUM_LIT:0> ) : <EOL> prefix = '<STR_LIT>' . join ( [ '<STR_LIT:.>' ] * stacklevel ) <EOL> oid = id ( obj ) <EOL> canary_oid = oid <EOL> print ( prefix + '<STR_LIT>' + str ( oid ) ) <EOL> if oid in already_fixed : <EOL> return already_fixed [ oid ] <EOL> if oid in currently_fixing : <EOL> print ( '<STR_LIT>' + str ( oid ) ) <EOL> return Placeholder ( oid ) <EOL> currently_fixing . append ( oid ) <EOL> if hasattr ( obj , '<STR_LIT>' ) : <EOL> rval = shared ( obj . get_value ( ) ) <EOL> obj . __getstate__ = None <EOL> elif obj is None : <EOL> rval = None <EOL> elif isinstance ( obj , list ) : <EOL> print ( prefix + '<STR_LIT>' ) <EOL> rval = [ ] <EOL> for i , elem in enumerate ( obj ) : <EOL> print ( prefix + '<STR_LIT>' % i ) <EOL> fixed_elem = fix ( elem , stacklevel + <NUM_LIT:2> ) <EOL> if isinstance ( fixed_elem , Placeholder ) : <EOL> raise NotImplementedError ( ) <EOL> rval . append ( fixed_elem ) <EOL> elif isinstance ( obj , dict ) : <EOL> print ( prefix + '<STR_LIT>' ) <EOL> rval = obj <EOL> """<STR_LIT>""" <EOL> elif isinstance ( obj , tuple ) : <EOL> print ( prefix + '<STR_LIT>' ) <EOL> rval = [ ] <EOL> for i , elem in enumerate ( obj ) : <EOL> print ( prefix + '<STR_LIT>' % i ) <EOL> fixed_elem = fix ( elem , stacklevel + <NUM_LIT:2> ) <EOL> if isinstance ( fixed_elem , Placeholder ) : <EOL> raise NotImplementedError ( ) <EOL> rval . append ( fixed_elem ) <EOL> rval = tuple ( rval ) <EOL> elif isinstance ( obj , ( int , float , str ) ) : <EOL> rval = obj <EOL> else : <EOL> print ( prefix + '<STR_LIT>' ) <EOL> field_names = dir ( obj ) <EOL> for field in field_names : <EOL> if isinstance ( getattr ( obj , field ) , types . MethodType ) : <EOL> print ( prefix + '<STR_LIT>' % field ) <EOL> continue <EOL> if field in blacklist or ( field . startswith ( '<STR_LIT>' ) ) : <EOL> print ( prefix + '<STR_LIT>' % field ) <EOL> continue <EOL> print ( prefix + '<STR_LIT>' % field ) <EOL> updated_field = fix ( getattr ( obj , field ) , stacklevel + <NUM_LIT:2> ) <EOL> print ( prefix + '<STR_LIT>' % field ) <EOL> if isinstance ( updated_field , Placeholder ) : <EOL> postponed_fixes . append ( FieldFixer ( obj , field , updated_field ) ) <EOL> else : <EOL> try : <EOL> setattr ( obj , field , updated_field ) <EOL> except Exception as e : <EOL> print ( "<STR_LIT>" + str ( e ) ) <EOL> rval = obj <EOL> already_fixed [ oid ] = rval <EOL> print ( prefix + '<STR_LIT>' + str ( oid ) ) <EOL> assert canary_oid == oid <EOL> del currently_fixing [ currently_fixing . index ( oid ) ] <EOL> return rval <EOL> model = fix ( model ) <EOL> assert len ( currently_fixing ) == <NUM_LIT:0> <EOL> for fixer in postponed_fixes : <EOL> fixer . apply ( ) <EOL> serial . save ( out_path , model ) </s>
