<s> '''<STR_LIT>''' <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> import re <EOL> import inspect <EOL> import os <EOL> import shutil <EOL> import sys <EOL> if sys . version [ <NUM_LIT:0> ] == '<STR_LIT:2>' : <EOL> reload ( sys ) <EOL> sys . setdefaultencoding ( '<STR_LIT:utf8>' ) <EOL> from keras . layers import convolutional <EOL> from keras . layers import recurrent <EOL> from keras . layers import core <EOL> from keras . layers import noise <EOL> from keras . layers import normalization <EOL> from keras . layers import advanced_activations <EOL> from keras . layers import embeddings <EOL> from keras . layers import wrappers <EOL> from keras import optimizers <EOL> from keras import callbacks <EOL> from keras import models <EOL> from keras . engine import topology <EOL> from keras import objectives <EOL> from keras import backend <EOL> from keras import constraints <EOL> from keras import activations <EOL> from keras import regularizers <EOL> EXCLUDE = { <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> } <EOL> PAGES = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> models . Sequential . compile , <EOL> models . Sequential . fit , <EOL> models . Sequential . evaluate , <EOL> models . Sequential . predict , <EOL> models . Sequential . predict_classes , <EOL> models . Sequential . predict_proba , <EOL> models . Sequential . train_on_batch , <EOL> models . Sequential . test_on_batch , <EOL> models . Sequential . predict_on_batch , <EOL> models . Sequential . fit_generator , <EOL> models . Sequential . evaluate_generator , <EOL> ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> models . Model . compile , <EOL> models . Model . fit , <EOL> models . Model . evaluate , <EOL> models . Model . predict , <EOL> models . Model . train_on_batch , <EOL> models . Model . test_on_batch , <EOL> models . Model . predict_on_batch , <EOL> models . Model . fit_generator , <EOL> models . Model . evaluate_generator , <EOL> models . Model . get_layer , <EOL> ] <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> core . Dense , <EOL> core . Activation , <EOL> core . Dropout , <EOL> core . Flatten , <EOL> core . Reshape , <EOL> core . Permute , <EOL> core . RepeatVector , <EOL> topology . Merge , <EOL> core . Lambda , <EOL> core . ActivityRegularization , <EOL> core . Masking , <EOL> core . Highway , <EOL> core . MaxoutDense , <EOL> core . TimeDistributedDense , <EOL> ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> convolutional . Convolution1D , <EOL> convolutional . Convolution2D , <EOL> convolutional . Convolution3D , <EOL> convolutional . MaxPooling1D , <EOL> convolutional . MaxPooling2D , <EOL> convolutional . MaxPooling3D , <EOL> convolutional . AveragePooling1D , <EOL> convolutional . AveragePooling2D , <EOL> convolutional . AveragePooling3D , <EOL> convolutional . UpSampling1D , <EOL> convolutional . UpSampling2D , <EOL> convolutional . UpSampling3D , <EOL> convolutional . ZeroPadding1D , <EOL> convolutional . ZeroPadding2D , <EOL> convolutional . ZeroPadding3D , <EOL> ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> recurrent . Recurrent , <EOL> recurrent . SimpleRNN , <EOL> recurrent . GRU , <EOL> recurrent . LSTM , <EOL> ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> embeddings . Embedding , <EOL> ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> normalization . BatchNormalization , <EOL> ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ advanced_activations ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ noise ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ wrappers ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ optimizers ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ callbacks ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ backend ] , <EOL> } , <EOL> ] <EOL> ROOT = '<STR_LIT>' <EOL> def get_earliest_class_that_defined_member ( member , cls ) : <EOL> ancestors = get_classes_ancestors ( [ cls ] ) <EOL> result = None <EOL> for ancestor in ancestors : <EOL> if member in dir ( ancestor ) : <EOL> result = ancestor <EOL> if not result : <EOL> return cls <EOL> return result <EOL> def get_classes_ancestors ( classes ) : <EOL> ancestors = [ ] <EOL> for cls in classes : <EOL> ancestors += cls . __bases__ <EOL> filtered_ancestors = [ ] <EOL> for ancestor in ancestors : <EOL> if ancestor . __name__ in [ '<STR_LIT:object>' ] : <EOL> continue <EOL> filtered_ancestors . append ( ancestor ) <EOL> if filtered_ancestors : <EOL> return filtered_ancestors + get_classes_ancestors ( filtered_ancestors ) <EOL> else : <EOL> return filtered_ancestors <EOL> def get_function_signature ( function , method = True ) : <EOL> signature = inspect . getargspec ( function ) <EOL> defaults = signature . defaults <EOL> if method : <EOL> args = signature . args [ <NUM_LIT:1> : ] <EOL> else : <EOL> args = signature . args <EOL> if defaults : <EOL> kwargs = zip ( args [ - len ( defaults ) : ] , defaults ) <EOL> args = args [ : - len ( defaults ) ] <EOL> else : <EOL> kwargs = [ ] <EOL> st = '<STR_LIT>' % ( function . __module__ , function . __name__ ) <EOL> for a in args : <EOL> st += str ( a ) + '<STR_LIT:U+002CU+0020>' <EOL> for a , v in kwargs : <EOL> if type ( v ) == str : <EOL> v = '<STR_LIT>' + v + '<STR_LIT>' <EOL> st += str ( a ) + '<STR_LIT:=>' + str ( v ) + '<STR_LIT:U+002CU+0020>' <EOL> if kwargs or args : <EOL> return st [ : - <NUM_LIT:2> ] + '<STR_LIT:)>' <EOL> else : <EOL> return st + '<STR_LIT:)>' <EOL> def get_class_signature ( cls ) : <EOL> try : <EOL> class_signature = get_function_signature ( cls . __init__ ) <EOL> class_signature = class_signature . replace ( '<STR_LIT>' , cls . __name__ ) <EOL> except : <EOL> class_signature = cls . __module__ + '<STR_LIT:.>' + cls . __name__ + '<STR_LIT>' <EOL> return class_signature <EOL> def class_to_docs_link ( cls ) : <EOL> module_name = cls . __module__ <EOL> assert module_name [ : <NUM_LIT:6> ] == '<STR_LIT>' <EOL> module_name = module_name [ <NUM_LIT:6> : ] <EOL> link = ROOT + module_name . replace ( '<STR_LIT:.>' , '<STR_LIT:/>' ) + '<STR_LIT:#>' + cls . __name__ . lower ( ) <EOL> return link <EOL> def class_to_source_link ( cls ) : <EOL> module_name = cls . __module__ <EOL> assert module_name [ : <NUM_LIT:6> ] == '<STR_LIT>' <EOL> path = module_name . replace ( '<STR_LIT:.>' , '<STR_LIT:/>' ) <EOL> path += '<STR_LIT>' <EOL> line = inspect . getsourcelines ( cls ) [ - <NUM_LIT:1> ] <EOL> link = '<STR_LIT>' + path + '<STR_LIT>' + str ( line ) <EOL> return '<STR_LIT>' + link + '<STR_LIT:)>' <EOL> def code_snippet ( snippet ) : <EOL> result = '<STR_LIT>' <EOL> result += snippet + '<STR_LIT:\n>' <EOL> result += '<STR_LIT>' <EOL> return result <EOL> def process_class_docstring ( docstring ) : <EOL> docstring = re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> docstring ) <EOL> docstring = re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> docstring ) <EOL> docstring = docstring . replace ( '<STR_LIT:U+0020>' * <NUM_LIT:5> , '<STR_LIT>' ) <EOL> docstring = docstring . replace ( '<STR_LIT:U+0020>' * <NUM_LIT:3> , '<STR_LIT:\t>' ) <EOL> docstring = docstring . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> return docstring <EOL> def process_function_docstring ( docstring ) : <EOL> docstring = re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> docstring ) <EOL> docstring = re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> docstring ) <EOL> docstring = re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> docstring ) <EOL> docstring = docstring . replace ( '<STR_LIT:U+0020>' * <NUM_LIT:6> , '<STR_LIT>' ) <EOL> docstring = docstring . replace ( '<STR_LIT:U+0020>' * <NUM_LIT:4> , '<STR_LIT:\t>' ) <EOL> docstring = docstring . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> return docstring <EOL> print ( '<STR_LIT>' ) <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> shutil . rmtree ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> for subdir , dirs , fnames in os . walk ( '<STR_LIT>' ) : <EOL> for fname in fnames : <EOL> new_subdir = subdir . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not os . path . exists ( new_subdir ) : <EOL> os . makedirs ( new_subdir ) <EOL> if fname [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> fpath = os . path . join ( subdir , fname ) <EOL> new_fpath = fpath . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> shutil . copy ( fpath , new_fpath ) <EOL> print ( '<STR_LIT>' ) <EOL> for page_data in PAGES : <EOL> blocks = [ ] <EOL> classes = page_data . get ( '<STR_LIT>' , [ ] ) <EOL> for module in page_data . get ( '<STR_LIT>' , [ ] ) : <EOL> module_classes = [ ] <EOL> for name in dir ( module ) : <EOL> if name [ <NUM_LIT:0> ] == '<STR_LIT:_>' or name in EXCLUDE : <EOL> continue <EOL> module_member = getattr ( module , name ) <EOL> if inspect . isclass ( module_member ) : <EOL> cls = module_member <EOL> if cls . __module__ == module . __name__ : <EOL> if cls not in module_classes : <EOL> module_classes . append ( cls ) <EOL> module_classes . sort ( key = lambda x : id ( x ) ) <EOL> classes += module_classes <EOL> for cls in classes : <EOL> subblocks = [ ] <EOL> signature = get_class_signature ( cls ) <EOL> subblocks . append ( '<STR_LIT>' + class_to_source_link ( cls ) + '<STR_LIT>' ) <EOL> subblocks . append ( '<STR_LIT>' + cls . __name__ + '<STR_LIT:\n>' ) <EOL> subblocks . append ( code_snippet ( signature ) ) <EOL> docstring = cls . __doc__ <EOL> if docstring : <EOL> subblocks . append ( process_class_docstring ( docstring ) ) <EOL> blocks . append ( '<STR_LIT:\n>' . join ( subblocks ) ) <EOL> functions = page_data . get ( '<STR_LIT>' , [ ] ) <EOL> for module in page_data . get ( '<STR_LIT>' , [ ] ) : <EOL> module_functions = [ ] <EOL> for name in dir ( module ) : <EOL> if name [ <NUM_LIT:0> ] == '<STR_LIT:_>' or name in EXCLUDE : <EOL> continue <EOL> module_member = getattr ( module , name ) <EOL> if inspect . isfunction ( module_member ) : <EOL> function = module_member <EOL> if module . __name__ in function . __module__ : <EOL> if function not in module_functions : <EOL> module_functions . append ( function ) <EOL> module_functions . sort ( key = lambda x : id ( x ) ) <EOL> functions += module_functions <EOL> for function in functions : <EOL> subblocks = [ ] <EOL> signature = get_function_signature ( function , method = False ) <EOL> signature = signature . replace ( function . __module__ + '<STR_LIT:.>' , '<STR_LIT>' ) <EOL> subblocks . append ( '<STR_LIT>' + function . __name__ + '<STR_LIT:\n>' ) <EOL> subblocks . append ( code_snippet ( signature ) ) <EOL> docstring = function . __doc__ <EOL> if docstring : <EOL> subblocks . append ( process_function_docstring ( docstring ) ) <EOL> blocks . append ( '<STR_LIT>' . join ( subblocks ) ) <EOL> mkdown = '<STR_LIT>' . join ( blocks ) <EOL> page_name = page_data [ '<STR_LIT>' ] <EOL> path = os . path . join ( '<STR_LIT>' , page_name ) <EOL> if os . path . exists ( path ) : <EOL> template = open ( path ) . read ( ) <EOL> assert '<STR_LIT>' in template , ( '<STR_LIT>' + path + <EOL> '<STR_LIT>' ) <EOL> mkdown = template . replace ( '<STR_LIT>' , mkdown ) <EOL> print ( '<STR_LIT>' , path ) <EOL> else : <EOL> print ( '<STR_LIT>' , path ) <EOL> subdir = os . path . dirname ( path ) <EOL> if not os . path . exists ( subdir ) : <EOL> os . makedirs ( subdir ) <EOL> open ( path , '<STR_LIT:w>' ) . write ( mkdown ) </s>
