idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
32,500
def _update_ps ( self , es ) : if not self . is_initialized_base : self . initialize_base ( es ) if self . _ps_updated_iteration == es . countiter : return if es . countiter <= es . itereigenupdated : assert es . countiter >= es . itereigenupdated _print_warning ( 'distribution transformation (B and D) have been update...
update the isotropic evolution path
32,501
def stop ( self , check = True ) : if ( check and self . countiter > 0 and self . opts [ 'termination_callback' ] and self . opts [ 'termination_callback' ] != str ( self . opts [ 'termination_callback' ] ) ) : self . callbackstop = self . opts [ 'termination_callback' ] ( self ) return self . _stopdict ( self , check ...
return a dictionary with the termination status . With check == False the termination conditions are not checked and the status might not reflect the current situation .
32,502
def random_rescale_to_mahalanobis ( self , x ) : x -= self . mean if any ( x ) : x *= sum ( self . randn ( len ( x ) ) ** 2 ) ** 0.5 / self . mahalanobis_norm ( x ) x += self . mean return x
change x like for injection all on genotypic level
32,503
def prepare_injection_directions ( self ) : if hasattr ( self , 'pop_injection_directions' ) and self . pop_injection_directions : ValueError ( "Looks like a bug in calling order/logics" ) ary = [ ] if ( isinstance ( self . adapt_sigma , CMAAdaptSigmaTPA ) or self . opts [ 'mean_shift_line_samples' ] ) : ary . append (...
provide genotypic directions for TPA and selective mirroring with no specific length normalization to be used in the coming iteration .
32,504
def inject ( self , solutions ) : if not hasattr ( self , 'pop_injection_directions' ) : self . pop_injection_directions = [ ] for solution in solutions : if len ( solution ) != self . N : raise ValueError ( 'method `inject` needs a list or array' + ( ' each el with dimension (`len`) %d' % self . N ) ) self . pop_injec...
inject a genotypic solution . The solution is used as direction relative to the distribution mean to compute a new candidate solution returned in method ask_geno which in turn is used in method ask .
32,505
def result_pretty ( self , number_of_runs = 0 , time_str = None , fbestever = None ) : if fbestever is None : fbestever = self . best . f s = ( ' after %i restart' + ( 's' if number_of_runs > 1 else '' ) ) % number_of_runs if number_of_runs else '' for k , v in self . stop ( ) . items ( ) : print ( 'termination on %s=%...
pretty print result .
32,506
def clip_or_fit_solutions ( self , pop , idx ) : for k in idx : self . repair_genotype ( pop [ k ] )
make sure that solutions fit to sample distribution this interface will probably change .
32,507
def repair_genotype ( self , x , copy_if_changed = False ) : x = array ( x , copy = False ) mold = array ( self . mean , copy = False ) if 1 < 3 : upper_length = self . N ** 0.5 + 2 * self . N / ( self . N + 2 ) fac = self . mahalanobis_norm ( x - mold ) / upper_length if fac > 1 : if copy_if_changed : x = ( x - mold )...
make sure that solutions fit to the sample distribution this interface will probably change .
32,508
def decompose_C ( self ) : if self . opts [ 'CMA_diagonal' ] : _print_warning ( "this might fail with CMA_diagonal option on" , iteration = self . countiter ) print ( self . opts [ 'CMA_diagonal' ] ) self . C = ( self . C + self . C . T ) / 2 self . dC = np . diag ( self . C ) . copy ( ) self . D , self . B = self . op...
eigen - decompose self . C and update self . dC self . C self . B .
32,509
def feedForResume ( self , X , function_values ) : if self . countiter > 0 : _print_warning ( 'feed should generally be used with a new object instance' ) if len ( X ) != len ( function_values ) : raise _Error ( 'number of solutions ' + str ( len ( X ) ) + ' and number function values ' + str ( len ( function_values ) ...
Given all previous candidate solutions and their respective function values the state of a CMAEvolutionStrategy object can be reconstructed from this history . This is the purpose of function feedForResume .
32,510
def defaults ( ) : return dict ( ( str ( k ) , str ( v ) ) for k , v in cma_default_options . items ( ) )
return a dictionary with default option values and description
32,511
def check ( self , options = None ) : self . check_values ( options ) self . check_attributes ( options ) self . check_values ( options ) return self
check for ambiguous keys and move attributes into dict
32,512
def init ( self , dict_or_str , val = None , warn = True ) : self . check ( dict_or_str ) dic = dict_or_str if val is not None : dic = { dict_or_str : val } for key , val in dic . items ( ) : key = self . corrected_key ( key ) if key not in CMAOptions . defaults ( ) : if warn : print ( 'Warning in cma.CMAOptions.init()...
initialize one or several options .
32,513
def complement ( self ) : self . check ( ) for key in CMAOptions . defaults ( ) : if key not in self : self [ key ] = CMAOptions . defaults ( ) [ key ] return self
add all missing options with their default values
32,514
def settable ( self ) : return CMAOptions ( [ i for i in list ( self . items ( ) ) if i [ 0 ] in CMAOptions . versatile_options ( ) ] )
return the subset of those options that are settable at any time .
32,515
def eval ( self , key , default = None , loc = None , correct_key = True ) : if correct_key : key = self . corrected_key ( key ) self [ key ] = self ( key , default , loc ) return self [ key ]
Evaluates and sets the specified option value in environment loc . Many options need N to be defined in loc some need popsize .
32,516
def evalall ( self , loc = None , defaults = None ) : self . check ( ) if defaults is None : defaults = cma_default_options if 'N' in loc : popsize = self ( 'popsize' , defaults [ 'popsize' ] , loc ) for k in list ( self . keys ( ) ) : k = self . corrected_key ( k ) self . eval ( k , defaults [ k ] , { 'N' : loc [ 'N' ...
Evaluates all option values in environment loc .
32,517
def match ( self , s = '' ) : match = s . lower ( ) res = { } for k in sorted ( self ) : s = str ( k ) + '=\'' + str ( self [ k ] ) + '\'' if match in s . lower ( ) : res [ k ] = self [ k ] return CMAOptions ( res , unchecked = True )
return all options that match in the name or the description with string s case is disregarded .
32,518
def data ( self ) : d = { } for name in self . key_names : d [ name ] = self . __dict__ . get ( name , None ) return d
return dictionary with data .
32,519
def register ( self , es , append = None , modulo = None ) : if not isinstance ( es , CMAEvolutionStrategy ) : raise TypeError ( "only class CMAEvolutionStrategy can be " + "registered for logging" ) self . es = es if append is not None : self . append = append if modulo is not None : self . modulo = modulo self . regi...
register a CMAEvolutionStrategy instance for logging append = True appends to previous data logged under the same name by default previous data are overwritten .
32,520
def save_to ( self , nameprefix , switch = False ) : if not nameprefix or not isinstance ( nameprefix , basestring ) : raise _Error ( 'filename prefix must be a nonempty string' ) if nameprefix == self . default_prefix : raise _Error ( 'cannot save to default name "' + nameprefix + '...", chose another name' ) if namep...
saves logger data to a different set of files for switch = True also the loggers name prefix is switched to the new value
32,521
def select_data ( self , iteration_indices ) : dat = self iteridx = iteration_indices dat . f = dat . f [ np . where ( [ x in iteridx for x in dat . f [ : , 0 ] ] ) [ 0 ] , : ] dat . D = dat . D [ np . where ( [ x in iteridx for x in dat . D [ : , 0 ] ] ) [ 0 ] , : ] try : iteridx = list ( iteridx ) iteridx . append ( ...
keep only data of iteration_indices
32,522
def plot_correlations ( self , iabscissa = 1 ) : if not hasattr ( self , 'corrspec' ) : self . load ( ) if len ( self . corrspec ) < 2 : return self x = self . corrspec [ : , iabscissa ] y = self . corrspec [ : , 6 : ] ys = self . corrspec [ : , : 6 ] from matplotlib . pyplot import semilogy , hold , text , grid , axis...
spectrum of correlation matrix and largest correlation
32,523
def _enter_plotting ( self , fontsize = 9 ) : self . original_fontsize = pyplot . rcParams [ 'font.size' ] pyplot . rcParams [ 'font.size' ] = fontsize pyplot . hold ( False ) pyplot . ioff ( )
assumes that a figure is open
32,524
def downsampling ( self , factor = 10 , first = 3 , switch = True , verbose = True ) : newprefix = self . name_prefix + 'down' for name in self . file_names : f = open ( newprefix + name + '.dat' , 'w' ) iline = 0 cwritten = 0 for line in open ( self . name_prefix + name + '.dat' ) : if iline < first or iline % factor ...
rude downsampling of a CMADataLogger data file by factor keeping also the first first entries . This function is a stump and subject to future changes . Return self .
32,525
def update_measure ( self ) : lam = len ( self . fit ) idx = np . argsort ( self . fit + self . fitre ) ranks = np . argsort ( idx ) . reshape ( ( 2 , lam ) ) rankDelta = ranks [ 0 ] - ranks [ 1 ] - np . sign ( ranks [ 0 ] - ranks [ 1 ] ) r = np . arange ( 1 , 2 * lam ) limits = [ 0.5 * ( Mh . prctile ( np . abs ( r - ...
updated noise level measure using two fitness lists self . fit and self . fitre return self . noiseS all_individual_measures .
32,526
def indices ( self , fit ) : lam_reev = 1.0 * ( self . lam_reeval if self . lam_reeval else 2 + len ( fit ) / 20 ) lam_reev = int ( lam_reev ) + ( ( lam_reev % 1 ) > np . random . rand ( ) ) choice = 1 if choice == 1 : n_first = lam_reev - lam_reev // 2 sort_idx = np . argsort ( array ( fit , copy = False ) [ n_first :...
return the set of indices to be reevaluated for noise measurement .
32,527
def plot ( self , plot_cmd = None , tf = lambda y : y ) : if not plot_cmd : plot_cmd = self . plot_cmd colors = 'bgrcmyk' pyplot . hold ( False ) res = self . res flatx , flatf = self . flattened ( ) minf = np . inf for i in flatf : minf = min ( ( minf , min ( flatf [ i ] ) ) ) addf = 1e-9 - minf if minf <= 1e-9 else 0...
plot the data we have return self
32,528
def save ( self , name = None ) : import pickle name = name if name else self . name fun = self . func del self . func pickle . dump ( self , open ( name + '.pkl' , "wb" ) ) self . func = fun return self
save to file
32,529
def load ( self , name = None ) : import pickle name = name if name else self . name s = pickle . load ( open ( name + '.pkl' , 'rb' ) ) self . res = s . res return self
load from file
32,530
def loglikelihood ( self , x , previous = False ) : if previous and hasattr ( self , 'lastiter' ) : sigma = self . lastiter . sigma Crootinv = self . lastiter . _Crootinv xmean = self . lastiter . mean D = self . lastiter . D elif previous and self . countiter > 1 : raise _Error ( 'no previous distribution parameters s...
return log - likelihood of x regarding the current sample distribution
32,531
def noisysphere ( self , x , noise = 2.10e-9 , cond = 1.0 , noise_offset = 0.10 ) : return self . elli ( x , cond = cond ) * ( 1 + noise * np . random . randn ( ) / len ( x ) ) + noise_offset * np . random . rand ( )
noise = 10 does not work with default popsize noise handling does not help
32,532
def cigar ( self , x , rot = 0 , cond = 1e6 , noise = 0 ) : if rot : x = rotate ( x ) x = [ x ] if isscalar ( x [ 0 ] ) else x f = [ ( x [ 0 ] ** 2 + cond * sum ( x [ 1 : ] ** 2 ) ) * np . exp ( noise * np . random . randn ( 1 ) [ 0 ] / len ( x ) ) for x in x ] return f if len ( f ) > 1 else f [ 0 ]
Cigar test objective function
32,533
def tablet ( self , x , rot = 0 ) : if rot and rot is not fcts . tablet : x = rotate ( x ) x = [ x ] if isscalar ( x [ 0 ] ) else x f = [ 1e6 * x [ 0 ] ** 2 + sum ( x [ 1 : ] ** 2 ) for x in x ] return f if len ( f ) > 1 else f [ 0 ]
Tablet test objective function
32,534
def elli ( self , x , rot = 0 , xoffset = 0 , cond = 1e6 , actuator_noise = 0.0 , both = False ) : if not isscalar ( x [ 0 ] ) : return [ self . elli ( xi , rot ) for xi in x ] if rot : x = rotate ( x ) N = len ( x ) if actuator_noise : x = x + actuator_noise * np . random . randn ( N ) ftrue = sum ( cond ** ( np . ara...
Ellipsoid test objective function
32,535
def elliconstraint ( self , x , cfac = 1e8 , tough = True , cond = 1e6 ) : N = len ( x ) f = sum ( cond ** ( np . arange ( N ) [ - 1 : : - 1 ] / ( N - 1 ) ) * x ** 2 ) cvals = ( x [ 0 ] + 1 , x [ 0 ] + 1 + 100 * x [ 1 ] , x [ 0 ] + 1 - 100 * x [ 1 ] ) if tough : f += cfac * sum ( max ( 0 , c ) for c in cvals ) else : f...
ellipsoid test objective function with constraints
32,536
def rosen ( self , x , alpha = 1e2 ) : x = [ x ] if isscalar ( x [ 0 ] ) else x f = [ sum ( alpha * ( x [ : - 1 ] ** 2 - x [ 1 : ] ) ** 2 + ( 1. - x [ : - 1 ] ) ** 2 ) for x in x ] return f if len ( f ) > 1 else f [ 0 ]
Rosenbrock test objective function
32,537
def diffpow ( self , x , rot = 0 ) : N = len ( x ) if rot : x = rotate ( x ) return sum ( np . abs ( x ) ** ( 2. + 4. * np . arange ( N ) / ( N - 1. ) ) ) ** 0.5
Diffpow test objective function
32,538
def ridgecircle ( self , x , expo = 0.5 ) : a = len ( x ) s = sum ( x ** 2 ) return ( ( s - a ) ** 2 ) ** ( expo / 2 ) + s / a + sum ( x ) / a
happy cat by HG Beyer
32,539
def rastrigin ( self , x ) : if not isscalar ( x [ 0 ] ) : N = len ( x [ 0 ] ) return [ 10 * N + sum ( xi ** 2 - 10 * np . cos ( 2 * np . pi * xi ) ) for xi in x ] N = len ( x ) return 10 * N + sum ( x ** 2 - 10 * np . cos ( 2 * np . pi * x ) )
Rastrigin test objective function
32,540
def schwefelmult ( self , x , pen_fac = 1e4 ) : y = [ x ] if isscalar ( x [ 0 ] ) else x N = len ( y [ 0 ] ) f = array ( [ 418.9829 * N - 1.27275661e-5 * N - sum ( x * np . sin ( np . abs ( x ) ** 0.5 ) ) + pen_fac * sum ( ( abs ( x ) > 500 ) * ( abs ( x ) - 500 ) ** 2 ) for x in y ] ) return f if len ( f ) > 1 else f ...
multimodal Schwefel function with domain - 500 .. 500
32,541
def lincon ( self , x , theta = 0.01 ) : if x [ 0 ] < 0 : return np . NaN return theta * x [ 1 ] + x [ 0 ]
ridge like linear function with one linear constraint
32,542
def rosen_nesterov ( self , x , rho = 100 ) : f = 0.25 * ( x [ 0 ] - 1 ) ** 2 f += rho * sum ( ( x [ 1 : ] - 2 * x [ : - 1 ] ** 2 + 1 ) ** 2 ) return f
needs exponential number of steps in a non - increasing f - sequence .
32,543
def bukin ( self , x ) : s = 0 for k in xrange ( ( 1 + len ( x ) ) // 2 ) : z = x [ 2 * k ] y = x [ min ( ( 2 * k + 1 , len ( x ) - 1 ) ) ] s += 100 * np . abs ( y - 0.01 * z ** 2 ) ** 0.5 + 0.01 * np . abs ( z + 10 ) return s
Bukin function from Wikipedia generalized simplistically from 2 - D .
32,544
def check_offset ( self ) : for d in range ( self . dmps ) : if ( self . y0 [ d ] == self . goal [ d ] ) : self . goal [ d ] += 1e-4
Check to see if initial position and goal are the same if they are offset slightly so that the forcing term is not 0
32,545
def rollout ( self , timesteps = None , ** kwargs ) : self . reset_state ( ) if timesteps is None : if kwargs . has_key ( 'tau' ) : timesteps = int ( self . timesteps / kwargs [ 'tau' ] ) else : timesteps = self . timesteps y_track = np . zeros ( ( timesteps , self . dmps ) ) dy_track = np . zeros ( ( timesteps , self ...
Generate a system trial no feedback is incorporated .
32,546
def reset_state ( self ) : self . y = self . y0 . copy ( ) self . dy = np . zeros ( self . dmps ) self . ddy = np . zeros ( self . dmps ) self . cs . reset_state ( )
Reset the system state
32,547
def step ( self , tau = 1.0 , state_fb = None ) : cs_args = { 'tau' : tau , 'error_coupling' : 1.0 } if state_fb is not None : state_fb = state_fb . reshape ( 1 , self . dmps ) dist = np . sqrt ( np . sum ( ( state_fb - self . y ) ** 2 ) ) cs_args [ 'error_coupling' ] = 1.0 / ( 1.0 + 10 * dist ) x = self . cs . step ( ...
Run the DMP system for a single timestep .
32,548
def step ( weights , duration ) : dt = duration / len ( weights ) def activate ( t , dt ) : return 0 <= t < dt return ( lambda t : sum ( [ w * activate ( t - i * dt , dt ) for i , w in enumerate ( weights ) ] ) )
This function creates a sum of boxcar functions .
32,549
def cartesian ( n , states ) : length = 1. / n pos_x = hstack ( ( states [ 0 ] , zeros ( n ) ) ) pos_y = zeros ( n + 1 ) for j in arange ( 1 , n + 1 ) : pos_x [ j ] = pos_x [ j - 1 ] + length * cos ( states [ j ] ) pos_y [ j ] = pos_y [ j - 1 ] + length * sin ( states [ j ] ) pos = hstack ( ( pos_x , pos_y ) ) return p...
This function computes cartesians coordinates from the states returned by the simulate function .
32,550
def build_swagger_data ( self , loader ) : if self . is_built : return self . is_built = True self . _required = [ ] self . _parameters = { } if not self . _swagger_data : return elif loader is not None : data = loader . resolve_data ( self . _swagger_data ) . copy ( ) else : data = self . _swagger_data for param in da...
Prepare data when schema loaded
32,551
async def validate ( self , request : web . Request ) : parameters = { } files = { } errors = self . errors_factory ( ) body = None if request . method in request . POST_METHODS : try : body = await self . _content_receiver . receive ( request ) except ValueError as e : errors [ request . content_type ] . add ( str ( e...
Returns parameters extract from request and multidict errors
32,552
def include ( self , spec , * , basePath = None , operationId_mapping = None , name = None ) : data = self . _file_loader . load ( spec ) if basePath is None : basePath = data . get ( 'basePath' , '' ) if name is not None : d = dict ( data ) d [ 'basePath' ] = basePath self . _swagger_data [ name ] = d swagger_data = {...
Adds a new specification to a router
32,553
def setup ( self , app : web . Application ) : if self . app is app : raise ValueError ( 'The router is already configured ' 'for this application' ) self . app = app routes = sorted ( ( ( r . name , ( r , r . url_for ( ) . human_repr ( ) ) ) for r in self . routes ( ) ) , key = utils . sort_key ) exists = set ( ) for ...
Installation routes to app . router
32,554
def template ( template_name , * , app_key = APP_KEY , encoding = 'utf-8' , status = 200 ) : def wrapper ( func ) : @ functools . wraps ( func ) async def wrapped ( * args , ** kwargs ) : if asyncio . iscoroutinefunction ( func ) : coro = func else : coro = asyncio . coroutine ( func ) context = await coro ( * args , *...
Decorator compatible with aiohttp_apiset router
32,555
def get_collection ( source , name , collection_format , default ) : if collection_format in COLLECTION_SEP : separator = COLLECTION_SEP [ collection_format ] value = source . get ( name , None ) if value is None : return default return value . split ( separator ) if collection_format == 'brackets' : return source . ge...
get collection named name from the given source that formatted accordingly to collection_format .
32,556
def add_get ( self , * args , ** kwargs ) : return self . add_route ( hdrs . METH_GET , * args , ** kwargs )
Shortcut for add_route with method GET
32,557
def add ( self , * args , ** kwargs ) : for arg in args : if isinstance ( arg , str ) : self . _operations . append ( self . _from_str ( arg ) ) else : self . _operations . append ( arg ) if kwargs : self . _operations . append ( kwargs )
Add new mapping from args and kwargs
32,558
def str_repr ( klass ) : if PY2 : klass . __unicode__ = klass . __str__ klass . __str__ = lambda self : self . __unicode__ ( ) . encode ( 'utf-8' ) klass . __repr__ = lambda self : '<%s: %r>' % ( self . __class__ . __name__ , str ( self ) ) return klass
Implements string conversion methods for the given class .
32,559
def _clean_slice ( key , length ) : if key . step is not None : raise NotImplementedError ( 'Cell slice with step is not supported.' ) start , stop = key . start , key . stop if start is None : start = 0 if stop is None : stop = length if not isinstance ( start , integer_types ) : raise TypeError ( 'Cell indices must b...
Validates and normalizes a cell range slice .
32,560
def _clean_index ( key , length ) : if not isinstance ( key , integer_types ) : raise TypeError ( 'Cell indices must be integers, %s given.' % type ( key ) . __name__ ) if - length <= key < 0 : return key + length elif 0 <= key < length : return key else : raise IndexError ( 'Cell index out of range.' )
Validates and normalizes a cell range index .
32,561
def _col_name ( index ) : for exp in itertools . count ( 1 ) : limit = 26 ** exp if index < limit : return '' . join ( chr ( ord ( 'A' ) + index // ( 26 ** i ) % 26 ) for i in range ( exp - 1 , - 1 , - 1 ) ) index -= limit
Converts a column index to a column name .
32,562
def __set_title ( self , value ) : self . _target . setPropertyValue ( self . _has_axis_title_property , True ) target = self . _get_title_target ( ) target . setPropertyValue ( 'String' , text_type ( value ) )
Sets title of this axis .
32,563
def ranges ( self ) : ranges = self . _target . getRanges ( ) return map ( SheetAddress . _from_uno , ranges )
Returns a list of addresses with source data .
32,564
def diagram ( self ) : target = self . _embedded . getDiagram ( ) target_type = target . getDiagramType ( ) cls = _DIAGRAM_TYPES . get ( target_type , Diagram ) return cls ( target )
Diagram - inner content of this chart .
32,565
def change_type ( self , cls ) : target_type = cls . _type target = self . _embedded . createInstance ( target_type ) self . _embedded . setDiagram ( target ) return cls ( target )
Change type of diagram in this chart .
32,566
def create ( self , name , position , ranges = ( ) , col_header = False , row_header = False ) : rect = self . _uno_rect ( position ) ranges = self . _uno_ranges ( ranges ) self . _create ( name , rect , ranges , col_header , row_header ) return self [ name ]
Creates and inserts a new chart .
32,567
def get_target ( self , row , col , row_count , col_count ) : target = self . _target if self . row + row_count > self . max_row_count or self . col + col_count > self . max_col_count : row_delta = row - self . row if row + self . row_count <= self . max_row_count else 0 col_delta = col - self . col if col + self . col...
Moves cursor to the specified position and returns in .
32,568
def __set_value ( self , value ) : array = ( ( self . _clean_value ( value ) , ) , ) return self . _get_target ( ) . setDataArray ( array )
Sets cell value to a string or number based on the given value .
32,569
def __set_formula ( self , formula ) : array = ( ( self . _clean_formula ( formula ) , ) , ) return self . _get_target ( ) . setFormulaArray ( array )
Sets a formula in this cell .
32,570
def __set_values ( self , values ) : array = tuple ( tuple ( self . _clean_value ( col ) for col in row ) for row in values ) self . _get_target ( ) . setDataArray ( array )
Sets values in this cell range from an iterable of iterables .
32,571
def __set_formulas ( self , formulas ) : array = tuple ( tuple ( self . _clean_formula ( col ) for col in row ) for row in formulas ) self . _get_target ( ) . setFormulaArray ( array )
Sets formulas in this cell range from an iterable of iterables .
32,572
def __get_values ( self ) : array = self . _get_target ( ) . getDataArray ( ) return tuple ( itertools . chain . from_iterable ( array ) )
Gets values in this cell range as a tuple .
32,573
def __set_values ( self , values ) : array = tuple ( ( self . _clean_value ( v ) , ) for v in values ) self . _get_target ( ) . setDataArray ( array )
Sets values in this cell range from an iterable .
32,574
def __get_formulas ( self ) : array = self . _get_target ( ) . getFormulaArray ( ) return tuple ( itertools . chain . from_iterable ( array ) )
Gets formulas in this cell range as a tuple .
32,575
def __set_formulas ( self , formulas ) : array = tuple ( ( self . _clean_formula ( v ) , ) for v in formulas ) self . _get_target ( ) . setFormulaArray ( array )
Sets formulas in this cell range from an iterable .
32,576
def create ( self , name , index = None ) : if index is None : index = len ( self ) self . _create ( name , index ) return self [ name ]
Creates a new sheet with the given name .
32,577
def copy ( self , old_name , new_name , index = None ) : if index is None : index = len ( self ) self . _copy ( old_name , new_name , index ) return self [ new_name ]
Copies an old sheet with the old_name to a new sheet with new_name .
32,578
def save ( self , path = None , filter_name = None ) : if path is None : try : self . _target . store ( ) except _IOException as e : raise IOError ( e . Message ) return url = uno . systemPathToFileUrl ( os . path . abspath ( path ) ) if filter_name : format_filter = uno . createUnoStruct ( 'com.sun.star.beans.Property...
Saves this document to a local file system .
32,579
def get_locale ( self , language = None , country = None , variant = None ) : locale = uno . createUnoStruct ( 'com.sun.star.lang.Locale' ) if language : locale . Language = language if country : locale . Country = country if variant : locale . Variant = variant formats = self . _target . getNumberFormats ( ) return Lo...
Returns locale which can be used for access to number formats .
32,580
def sheets ( self ) : try : return self . _sheets except AttributeError : target = self . _target . getSheets ( ) self . _sheets = SpreadsheetCollection ( self , target ) return self . _sheets
Collection of sheets in this document .
32,581
def date_from_number ( self , value ) : if not isinstance ( value , numbers . Real ) : return None delta = datetime . timedelta ( days = value ) return self . _null_date + delta
Converts a float value to corresponding datetime instance .
32,582
def date_to_number ( self , date ) : if isinstance ( date , datetime . datetime ) : delta = date - self . _null_date elif isinstance ( date , datetime . date ) : delta = date - self . _null_date . date ( ) else : raise TypeError ( date ) return delta . days + delta . seconds / ( 24.0 * 60 * 60 )
Converts a date or datetime instance to a corresponding float value .
32,583
def time_from_number ( self , value ) : if not isinstance ( value , numbers . Real ) : return None delta = datetime . timedelta ( days = value ) minutes , second = divmod ( delta . seconds , 60 ) hour , minute = divmod ( minutes , 60 ) return datetime . time ( hour , minute , second )
Converts a float value to corresponding time instance .
32,584
def time_to_number ( self , time ) : if not isinstance ( time , datetime . time ) : raise TypeError ( time ) return ( ( time . second / 60.0 + time . minute ) / 60.0 + time . hour ) / 24.0
Converts a time instance to a corresponding float value .
32,585
def _null_date ( self ) : try : return self . __null_date except AttributeError : number_settings = self . _target . getNumberFormatSettings ( ) d = number_settings . getPropertyValue ( 'NullDate' ) self . __null_date = datetime . datetime ( d . Year , d . Month , d . Day ) return self . __null_date
Returns date which is represented by a integer 0 .
32,586
def create_spreadsheet ( self ) : desktop = self . cls ( self . hostname , self . port , self . pipe ) return desktop . create_spreadsheet ( )
Creates a new spreadsheet document .
32,587
def vcontoursf1D ( self , x1 , x2 , nx , levels , labels = False , decimals = 0 , color = None , nudge = 1e-6 , newfig = True , figsize = None , layout = True , ax = None ) : naq = self . aq . naq xflow = np . linspace ( x1 + nudge , x2 - nudge , nx ) Qx = np . empty ( ( naq , nx ) ) for i in range ( nx ) : Qx [ : , i ...
Vertical contour for 1D model
32,588
def discharge ( self ) : Q = np . zeros ( self . aq . naq ) Q [ self . layers ] = self . parameters [ : , 0 ] return Q
Discharge per unit length
32,589
def discharge ( self ) : rv = np . zeros ( self . aq [ 0 ] . naq ) Qls = self . parameters [ : , 0 ] * self . dischargeinf ( ) Qls . shape = ( self . nls , self . nlayers , self . order + 1 ) Qls = np . sum ( Qls , 2 ) for i , q in enumerate ( Qls ) : rv [ self . layers [ i ] ] += q return rv
Discharge of the element in each layer
32,590
def findlayer ( self , z ) : if z > self . z [ 0 ] : modellayer , ltype = - 1 , 'above' layernumber = None elif z < self . z [ - 1 ] : modellayer , ltype = len ( self . layernumber ) , 'below' layernumber = None else : modellayer = np . argwhere ( ( z <= self . z [ : - 1 ] ) & ( z >= self . z [ 1 : ] ) ) [ 0 , 0 ] laye...
Returns layer - number layer - type and model - layer - number
32,591
def remove_element ( self , e ) : if e . label is not None : self . elementdict . pop ( e . label ) self . elementlist . remove ( e )
Remove element e from model
32,592
def read_plink ( file_prefix , verbose = True ) : r from dask . array import concatenate file_prefixes = sorted ( glob ( file_prefix ) ) if len ( file_prefixes ) == 0 : file_prefixes = [ file_prefix . replace ( "*" , "" ) ] file_prefixes = sorted ( _clean_prefixes ( file_prefixes ) ) fn = [ ] for fp in file_prefixes : ...
r Read PLINK files into Pandas data frames .
32,593
def read_files ( * files ) : text = "" for single_file in files : content = read ( single_file ) text = text + content + "\n" return text
Read files into setup
32,594
def read ( afile ) : the_relative_file = os . path . join ( HERE , afile ) with codecs . open ( the_relative_file , 'r' , 'utf-8' ) as opened_file : content = filter_out_test_code ( opened_file ) content = "" . join ( list ( content ) ) return content
Read a file into setup
32,595
def main ( ) : parser = create_parser ( ) options = vars ( parser . parse_args ( ) ) HASH_STORE . IGNORE_CACHE_FILE = options [ constants . LABEL_FORCE ] moban_file = options [ constants . LABEL_MOBANFILE ] load_engine_factory_and_engines ( ) if moban_file is None : moban_file = mobanfile . find_default_moban_file ( ) ...
program entry point
32,596
def create_parser ( ) : parser = argparse . ArgumentParser ( prog = constants . PROGRAM_NAME , description = constants . PROGRAM_DESCRIPTION ) parser . add_argument ( "-cd" , "--%s" % constants . LABEL_CONFIG_DIR , help = "the directory for configuration file lookup" , ) parser . add_argument ( "-c" , "--%s" % constant...
construct the program options
32,597
def handle_moban_file ( moban_file , options ) : moban_file_configurations = load_data ( None , moban_file ) if moban_file_configurations is None : raise exceptions . MobanfileGrammarException ( constants . ERROR_INVALID_MOBAN_FILE % moban_file ) if ( constants . LABEL_TARGETS not in moban_file_configurations and const...
act upon default moban file
32,598
def handle_command_line ( options ) : options = merge ( options , constants . DEFAULT_OPTIONS ) engine = plugins . ENGINES . get_engine ( options [ constants . LABEL_TEMPLATE_TYPE ] , options [ constants . LABEL_TMPL_DIRS ] , options [ constants . LABEL_CONFIG_DIR ] , ) if options [ constants . LABEL_TEMPLATE ] is None...
act upon command options
32,599
def by_symbol ( symbol , country_code = None ) : res = _data ( ) [ 'symbol' ] . get ( symbol ) if res : tmp_res = [ ] for d in res : if country_code in d . countries : tmp_res += [ d ] if tmp_res : return tmp_res if country_code is None : return res
Get list of possible currencies for symbol ; filter by country_code