<s> import numpy as np <EOL> from scipy import weave <EOL> class LocalMaximumDetector : <EOL> def __init__ ( self , max_length = <NUM_LIT> ) : <EOL> self . max_length = max_length <EOL> self . maxes = np . zeros ( ( max_length , <NUM_LIT:2> ) , dtype = np . int ) <EOL> self . vals = np . zeros ( ( max_length , ) , dtype = np . float ) <EOL> def __call__ ( self , mat , threshold = None , sort_results = True ) : <EOL> '''<STR_LIT>''' <EOL> maxes = self . maxes <EOL> vals = self . vals <EOL> r , c = mat . shape <EOL> max_length = self . max_length <EOL> if threshold != None : <EOL> count = weave . inline ( <EOL> '''<STR_LIT>''' , <EOL> arg_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:max_length>' , '<STR_LIT>' , '<STR_LIT:r>' , '<STR_LIT:c>' ] , <EOL> type_converters = weave . converters . blitz , <EOL> ) <EOL> else : <EOL> count = weave . inline ( <EOL> '''<STR_LIT>''' , <EOL> arg_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:max_length>' , '<STR_LIT:r>' , '<STR_LIT:c>' ] , <EOL> type_converters = weave . converters . blitz , <EOL> ) <EOL> if sort_results == False : <EOL> return maxes [ : count , : ] . copy ( ) , vals [ : count ] . copy ( ) <EOL> order = np . argsort ( vals [ : count ] ) [ : : - <NUM_LIT:1> ] <EOL> maxes = maxes [ order ] <EOL> vals = vals [ order ] <EOL> return maxes , vals </s>
