signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def list_domains ( ) :
'''Return a list of the salt _ id names of all available Vagrant VMs on
this host without regard to the path where they are defined .
CLI Example :
. . code - block : : bash
salt ' * ' vagrant . list _ domains - - log - level = info
The log shows information about all known Vagrant ... | vms = [ ]
cmd = 'vagrant global-status'
reply = __salt__ [ 'cmd.shell' ] ( cmd )
log . info ( '--->\n%s' , reply )
for line in reply . split ( '\n' ) : # build a list of the text reply
tokens = line . strip ( ) . split ( )
try :
_ = int ( tokens [ 0 ] , 16 )
# valid id numbers are hexadecimal
... |
def _create_variant ( self , start , end , ref , alt , fsext_len = None , is_dup = False , acc = None , is_ambiguous = False , is_sub = False , is_ext = False , is_no_protein = False , is_init_met = False ) :
"""Creates a SequenceVariant object""" | if is_init_met :
posedit = AARefAlt ( ref = ref , alt = alt , init_met = True )
elif is_ambiguous :
posedit = None
else :
interval = Interval ( start = start , end = end )
# Note - order matters
if is_no_protein :
edit = '0'
elif is_sub :
edit = AASub ( ref = ref , alt = alt )
... |
def _ExtractGoogleSearchQuery ( self , url ) :
"""Extracts a search query from a Google URL .
Google Drive : https : / / drive . google . com / drive / search ? q = query
Google Search : https : / / www . google . com / search ? q = query
Google Sites : https : / / sites . google . com / site / . * / system /... | if 'search' not in url or 'q=' not in url :
return None
line = self . _GetBetweenQEqualsAndAmpersand ( url )
if not line :
return None
return line . replace ( '+' , ' ' ) |
def _get_compute_func ( self , nmr_samples , thinning , return_output ) :
"""Get the MCMC algorithm as a computable function .
Args :
nmr _ samples ( int ) : the number of samples we will draw
thinning ( int ) : the thinning factor we want to use
return _ output ( boolean ) : if the kernel should return out... | cl_func = '''
void compute(global uint* rng_state,
global mot_float_type* current_chain_position,
global mot_float_type* current_log_likelihood,
global mot_float_type* current_log_prior,
ulong iteration_offs... |
def add_column ( self , col , icol , update_error = True ) :
"""Attempts to add a single column of : math : ` A ` to the Nystroem approximation and updates the local matrices
Parameters
col : ndarray ( ( N , ) , dtype = float )
new column of : math : ` A `
icol : int
index of new column within : math : ` ... | # convenience access
k = self . _k
d = self . _d
R = self . _R_k
Winv = self . _W_k_inv
b_new = col [ self . _columns ] [ : , None ]
d_new = d [ icol ]
q_new = R [ : , icol ] [ : , None ]
# calculate R _ new
schur_complement = d_new - np . dot ( b_new . T , q_new )
# Schur complement
if np . isclose ( schur_complement ... |
def delete ( self , * labels ) :
'''Delete ` labels ` from the store , which involves deleting two
records for each : class : ` Label ` .
: rtype : None
: raises : : exc : ` KeyError ` if any of the ` labels ` could not be found .''' | deletes = [ ]
for label in labels :
k1 , k2 = self . _keys_from_label ( label )
deletes . append ( k1 )
deletes . append ( k2 )
self . kvl . delete ( self . TABLE , * deletes ) |
def scale ( self ) :
"""What is a representitive number that reflects the magnitude
of the world holding the paths , for numerical comparisons .
Returns
scale : float
Approximate size of the world holding this path""" | # use vertices peak - peak rather than exact extents
scale = float ( ( self . vertices . ptp ( axis = 0 ) ** 2 ) . sum ( ) ** .5 )
return scale |
def update_attribute_toolbar ( self , key = None ) :
"""Updates the attribute toolbar
Parameters
key : 3 - tuple of Integer , defaults to current cell
\t Cell to which attributes the attributes toolbar is updated""" | if key is None :
key = self . actions . cursor
post_command_event ( self , self . ToolbarUpdateMsg , key = key , attr = self . code_array . cell_attributes [ key ] ) |
def set_value ( self , dry_wet : LeakSensorState ) :
"""Set the value of the state to dry or wet .""" | value = 0
if dry_wet == self . _dry_wet_type :
value = 1
self . _update_subscribers ( value ) |
def get_prediction_score ( self , node_id ) :
"""Return the prediction score ( if leaf node ) or None if its an
intermediate node .
Parameters
node _ id : id of the node to get the prediction value .
Returns
float or None : returns float value of prediction if leaf node and None
if not .
Examples
. ... | _raise_error_if_not_of_type ( node_id , [ int , long ] , "node_id" )
_numeric_param_check_range ( "node_id" , node_id , 0 , self . num_nodes - 1 )
node = self . nodes [ node_id ]
return None if node . is_leaf is False else node . value |
def _send_message_to_topic ( self , topic , message , correlation_id = None ) :
"""Send a message to RabbitMQ based on the routing key ( topic ) .
Parameters
topic : str
The routing key ( topic ) where the message should be sent to .
message : FranzEvent
The message to be sent .
Raises
franz . Invalid... | exchange = self . get_exchange_name ( topic )
self . _channel . exchange_declare ( exchange = exchange , exchange_type = 'topic' , durable = True , )
self . _channel . basic_publish ( exchange , topic , self . serialize_message ( message ) , properties = self . get_properties ( correlation_id = correlation_id ) , ) |
def Iaax ( mt , x , * args ) :
"""( Iä ) x : Returns the present value of annuity - certain at the beginning of the first year
and increasing linerly . Arithmetically increasing annuity - anticipatory""" | return Sx ( mt , x ) / Dx ( mt , x ) |
def zkronv ( ttA , ttB ) :
"""Do kronecker product between vectors ttA and ttB .
Look about kronecker at : https : / / en . wikipedia . org / wiki / Kronecker _ product
For details about operation refer : https : / / arxiv . org / abs / 1802.02839
: param ttA : first TT - vector ;
: param ttB : second TT - ... | Al = _vector . vector . to_list ( ttA )
Bl = _vector . vector . to_list ( ttB )
Hl = [ _np . kron ( B , A ) for ( A , B ) in zip ( Al , Bl ) ]
return _vector . vector . from_list ( Hl ) |
def _check_servers ( self ) :
"""Check the servers variable and convert in a valid tuple form""" | new_servers = [ ]
def check_format ( server ) :
if server . scheme not in [ "thrift" , "http" , "https" ] :
raise RuntimeError ( "Unable to recognize protocol: \"%s\"" % _type )
if server . scheme == "thrift" :
if not thrift_connect :
raise RuntimeError ( "If you want to use thrift, ... |
def port_profile_vlan_profile_switchport_access_mac_vlan_classification_access_vlan_access_mac_address ( self , ** kwargs ) :
"""Auto Generated Code""" | config = ET . Element ( "config" )
port_profile = ET . SubElement ( config , "port-profile" , xmlns = "urn:brocade.com:mgmt:brocade-port-profile" )
name_key = ET . SubElement ( port_profile , "name" )
name_key . text = kwargs . pop ( 'name' )
vlan_profile = ET . SubElement ( port_profile , "vlan-profile" )
switchport =... |
def register_event ( self ) :
"""注册事件""" | event_bus = Environment . get_instance ( ) . event_bus
event_bus . prepend_listener ( EVENT . PRE_BEFORE_TRADING , self . _pre_before_trading )
event_bus . prepend_listener ( EVENT . POST_SETTLEMENT , self . _post_settlement ) |
def sendMessage ( self , message , thread_id = None , thread_type = ThreadType . USER ) :
"""Deprecated . Use : func : ` fbchat . Client . send ` instead""" | return self . send ( Message ( text = message ) , thread_id = thread_id , thread_type = thread_type ) |
def get_driver ( self , desired_capabilities = None ) :
"""Creates a Selenium driver on the basis of the configuration file
upon which this object was created .
: param desired _ capabilities : Capabilities that the caller
desires to override . This have priority over those
capabilities that are set by the ... | override_caps = desired_capabilities or { }
desired_capabilities = self . config . make_selenium_desired_capabilities ( )
desired_capabilities . update ( override_caps )
browser_string = self . config . browser
chromedriver_version = None
if self . remote :
driver = self . remote_service . build_driver ( desired_ca... |
def sample_greedy ( self ) :
"""Sample a point in the leaf with the max progress .""" | if self . leafnode :
return self . sample_bounds ( )
else :
lp = self . lower . max_leaf_progress
gp = self . greater . max_leaf_progress
maxp = max ( lp , gp )
if self . sampling_mode [ 'multiscale' ] :
tp = self . progress
if tp > maxp :
return self . sample_bounds ( )
... |
def get_instance ( self , payload ) :
"""Build an instance of CredentialListInstance
: param dict payload : Payload response from the API
: returns : twilio . rest . trunking . v1 . trunk . credential _ list . CredentialListInstance
: rtype : twilio . rest . trunking . v1 . trunk . credential _ list . Credent... | return CredentialListInstance ( self . _version , payload , trunk_sid = self . _solution [ 'trunk_sid' ] , ) |
def set ( self , key , value ) :
"""Set the value of a key
Args :
key ( string ) : The key used to store this value
value ( string ) : The value to store""" | data = self . _load_file ( )
data [ key ] = value
self . _save_file ( data ) |
def _gauss_legendre ( order , composite = 1 ) :
"""Backend function .""" | inner = numpy . ones ( order + 1 ) * 0.5
outer = numpy . arange ( order + 1 ) ** 2
outer = outer / ( 16 * outer - 4. )
banded = numpy . diag ( numpy . sqrt ( outer [ 1 : ] ) , k = - 1 ) + numpy . diag ( inner ) + numpy . diag ( numpy . sqrt ( outer [ 1 : ] ) , k = 1 )
vals , vecs = numpy . linalg . eig ( banded )
absci... |
def dist_2 ( x0 , y0 , x1 , y1 ) :
r"""Return the squared distance between two points .
This is faster than calculating distance but should
only be used with comparable ratios .
Parameters
x0 : float
Starting x coordinate
y0 : float
Starting y coordinate
x1 : float
Ending x coordinate
y1 : float... | d0 = x1 - x0
d1 = y1 - y0
return d0 * d0 + d1 * d1 |
def takes_kwargs ( obj ) -> bool :
"""Checks whether a provided object takes in any positional arguments .
Similar to takes _ arg , we do this for both the _ _ init _ _ function of
the class or a function / method
Otherwise , we raise an error""" | if inspect . isclass ( obj ) :
signature = inspect . signature ( obj . __init__ )
elif inspect . ismethod ( obj ) or inspect . isfunction ( obj ) :
signature = inspect . signature ( obj )
else :
raise ConfigurationError ( f"object {obj} is not callable" )
return bool ( any ( [ p . kind == inspect . Paramete... |
def _write ( self , value ) :
"""rename to write and import inspect to debut the callstack""" | if ' ' in value :
s = inspect . stack ( )
fn = s [ 1 ] . function
super ( ) . write ( '%%DEBUG {} %%' . format ( fn ) )
super ( ) . write ( value ) |
def _wrap_result ( data , columns , index_col = None , coerce_float = True , parse_dates = None ) :
"""Wrap result set of query in a DataFrame .""" | frame = DataFrame . from_records ( data , columns = columns , coerce_float = coerce_float )
frame = _parse_date_columns ( frame , parse_dates )
if index_col is not None :
frame . set_index ( index_col , inplace = True )
return frame |
def move_todo_item ( self , item_id , to ) :
"""Changes the position of an item within its parent list . It does not
currently support reparenting an item . Position 1 is at the top of the
list . Moving an item beyond the end of the list puts it at the bottom
of the list .""" | path = '/todos/move_item/%u' % item_id
req = ET . Element ( 'request' )
ET . SubElement ( req , 'to' ) . text = str ( int ( to ) )
return self . _request ( path , req ) |
def _runDeferredFunctions ( deferredFunctions ) :
"""Invoke the specified deferred functions and return a list of names of functions that
raised an exception while being invoked .
: param list [ DeferredFunction ] deferredFunctions : the DeferredFunctions to run
: rtype : list [ str ]""" | failures = [ ]
for deferredFunction in deferredFunctions :
try :
deferredFunction . invoke ( )
except :
failures . append ( deferredFunction . name )
logger . exception ( '%s failed.' , deferredFunction )
return failures |
def from_wire ( wire , keyring = None , request_mac = '' , xfr = False , origin = None , tsig_ctx = None , multi = False , first = True , question_only = False , one_rr_per_rrset = False ) :
"""Convert a DNS wire format message into a message
object .
@ param keyring : The keyring to use if the message is signe... | m = Message ( id = 0 )
m . keyring = keyring
m . request_mac = request_mac
m . xfr = xfr
m . origin = origin
m . tsig_ctx = tsig_ctx
m . multi = multi
m . first = first
reader = _WireReader ( wire , m , question_only , one_rr_per_rrset )
reader . read ( )
return m |
def p12d_local ( vertices , lame , mu ) :
"""Local stiffness matrix for P1 elements in 2d .""" | assert ( vertices . shape == ( 3 , 2 ) )
A = np . vstack ( ( np . ones ( ( 1 , 3 ) ) , vertices . T ) )
PhiGrad = inv ( A ) [ : , 1 : ]
# gradients of basis functions
R = np . zeros ( ( 3 , 6 ) )
R [ [ [ 0 ] , [ 2 ] ] , [ 0 , 2 , 4 ] ] = PhiGrad . T
R [ [ [ 2 ] , [ 1 ] ] , [ 1 , 3 , 5 ] ] = PhiGrad . T
C = mu * np . ar... |
def parse_component_type ( self , node ) :
"""Parses < ComponentType >
@ param node : Node containing the < ComponentType > element
@ type node : xml . etree . Element
@ raise ParseError : Raised when the component type does not have a
name .""" | try :
name = node . lattrib [ 'name' ]
except :
self . raise_error ( '<ComponentType> must specify a name' )
if 'extends' in node . lattrib :
extends = node . lattrib [ 'extends' ]
else :
extends = None
if 'description' in node . lattrib :
description = node . lattrib [ 'description' ]
else :
de... |
def find_spec ( self , fullname , path , target = None ) :
"""Claims modules that are under ipynb . fs""" | if fullname . startswith ( self . package_prefix ) :
for path in self . _get_paths ( fullname ) :
if os . path . exists ( path ) :
return ModuleSpec ( name = fullname , loader = self . loader_class ( fullname , path ) , origin = path , is_package = ( path . endswith ( '__init__.ipynb' ) or path ... |
def _emit_error ( cls , message ) :
"""Print an error message to STDERR .""" | sys . stderr . write ( 'ERROR: {message}\n' . format ( message = message ) )
sys . stderr . flush ( ) |
def absent ( name , user = None ) :
'''Verify that the specified ruby is not installed with rbenv . Rbenv
is installed if necessary .
name
The version of ruby to uninstall
user : None
The user to run rbenv as .
. . versionadded : : 0.17.0
. . versionadded : : 0.16.0''' | ret = { 'name' : name , 'result' : None , 'comment' : '' , 'changes' : { } }
if name . startswith ( 'ruby-' ) :
name = re . sub ( r'^ruby-' , '' , name )
ret = _check_rbenv ( ret , user )
if ret [ 'result' ] is False :
ret [ 'result' ] = True
ret [ 'comment' ] = 'Rbenv not installed, {0} not either' . forma... |
def mu_so ( species , motif , spin_state ) :
"""Calculates the spin - only magnetic moment for a
given species . Only supports transition metals .
: param species : str or Species
: param motif : " oct " or " tet "
: param spin _ state : " high " or " low "
: return : spin - only magnetic moment in Bohr m... | try :
sp = get_el_sp ( species )
n = sp . get_crystal_field_spin ( coordination = motif , spin_config = spin_state )
# calculation spin - only magnetic moment for this number of unpaired spins
return np . sqrt ( n * ( n + 2 ) )
except AttributeError :
return None |
def parse ( self , tokenized ) : # pylint : disable = invalid - name
"""Parses input , which is a list of tokens .""" | table , trees = _parse ( tokenized , self . grammar )
# Check if the parse succeeded .
if all ( r . lhs != self . start for r in table [ ( 0 , len ( tokenized ) - 1 ) ] ) :
raise ParseError ( 'Parsing failed.' )
parse = trees [ ( 0 , len ( tokenized ) - 1 ) ] [ self . start ]
return self . _to_tree ( revert_cnf ( p... |
def lies_on_circle ( self , center , radius ) :
'''Tests whether the arc circle ' s center and radius match the given ones within < tol > tolerance .
> > > a = Arc ( ( 0 , 0 ) , 1 , 0 , 0 , False )
> > > a . lies _ on _ circle ( ( tol / 2 , tol / 2 ) , 1 + tol / 2)
True
> > > a . lies _ on _ circle ( ( tol ... | return np . all ( abs ( np . asarray ( center ) - self . center ) < tol ) and abs ( radius - self . radius ) < tol |
def get_events_attendees ( self , event_ids ) :
"""Get the attendees of the identified events .
Parameters
event _ ids
List of IDs of events to get attendees for .
Returns
List of tuples of ( event id , ` ` pythonkc _ meetups . types . MeetupMember ` ` ) .
Exceptions
* PythonKCMeetupsBadJson
* Pytho... | query = urllib . urlencode ( { 'key' : self . _api_key , 'event_id' : ',' . join ( event_ids ) } )
url = '{0}?{1}' . format ( RSVPS_URL , query )
data = self . _http_get_json ( url )
rsvps = data [ 'results' ]
return [ ( rsvp [ 'event' ] [ 'id' ] , parse_member_from_rsvp ( rsvp ) ) for rsvp in rsvps if rsvp [ 'response... |
def contact_addresses ( self ) :
"""Provides a reference to contact addresses used by this server .
Obtain a reference to manipulate or iterate existing contact
addresses : :
> > > from smc . elements . servers import ManagementServer
> > > mgt _ server = ManagementServer . objects . first ( )
> > > for c... | return MultiContactAddress ( href = self . get_relation ( 'contact_addresses' ) , type = self . typeof , name = self . name ) |
def synchronised ( func ) :
"""Synchronisation decorator .""" | # pylint : disable = E0213
def Wrapper ( main_obj , * args , ** kwargs ) :
main_obj . _lock . acquire ( )
# pylint : disable = W0212
try :
return func ( main_obj , * args , ** kwargs )
# pylint : disable = E1102
finally :
main_obj . _lock . release ( )
# pylint : disable = W0212
... |
def _randomize_subject_list ( data_list , random ) :
"""Randomly permute the voxels of a subject list .
The method shuffles the subject one by one in place according to
the random type . If RandomType . NORANDOM , return the original list .
Parameters
data _ list : list of 2D array in shape [ nVxels , nTRs ... | if random == RandomType . REPRODUCIBLE :
for i in range ( len ( data_list ) ) :
_randomize_single_subject ( data_list [ i ] , seed = i )
elif random == RandomType . UNREPRODUCIBLE :
for data in data_list :
_randomize_single_subject ( data ) |
def is_sql_equal ( sqls1 , sqls2 ) :
"""Find out equality of two SQL items .
See https : / / docs . djangoproject . com / en / 1.8 / ref / migration - operations / # runsql .
Args :
sqls1 , sqls2 : SQL items , have the same format as supported by Django ' s RunSQL operation .
Returns :
( bool ) ` True ` i... | is_seq1 = isinstance ( sqls1 , ( list , tuple ) )
is_seq2 = isinstance ( sqls2 , ( list , tuple ) )
if not is_seq1 :
sqls1 = ( sqls1 , )
if not is_seq2 :
sqls2 = ( sqls2 , )
if len ( sqls1 ) != len ( sqls2 ) :
return False
for sql1 , sql2 in zip ( sqls1 , sqls2 ) :
sql1 , params1 = _sql_params ( sql1 )
... |
def _shrink ( self ) :
"""Shrinks the dynamic table to be at or below maxsize""" | cursize = self . _current_size
while cursize > self . _maxsize :
name , value = self . dynamic_entries . pop ( )
cursize -= table_entry_size ( name , value )
self . _current_size = cursize |
def get_pathext ( default_pathext = None ) :
"""Returns the path extensions from environment or a default""" | if default_pathext is None :
default_pathext = os . pathsep . join ( [ '.COM' , '.EXE' , '.BAT' , '.CMD' ] )
pathext = os . environ . get ( 'PATHEXT' , default_pathext )
return pathext |
def repeat ( self , repeats , * args , ** kwargs ) :
"""Repeat elements of an array .
See Also
numpy . ndarray . repeat""" | nv . validate_repeat ( args , kwargs )
values = self . _data . repeat ( repeats )
return type ( self ) ( values . view ( 'i8' ) , dtype = self . dtype ) |
def tensormul ( tensor0 : BKTensor , tensor1 : BKTensor , indices : typing . List [ int ] ) -> BKTensor :
r"""Generalization of matrix multiplication to product tensors .
A state vector in product tensor representation has N dimension , one for
each contravariant index , e . g . for 3 - qubit states
: math : ... | # Note : This method is the critical computational core of QuantumFlow
# We currently have two implementations , one that uses einsum , the other
# using matrix multiplication
# numpy :
# einsum is much faster particularly for small numbers of qubits
# tensorflow :
# Little different is performance , but einsum would r... |
def get_home_position ( boatd = None ) :
'''Get the current home position from boatd .
: returns : The configured home position
: rtype : Points''' | if boatd is None :
boatd = Boatd ( )
content = boatd . get ( '/waypoints' )
home = content . get ( 'home' , None )
if home is not None :
lat , lon = home
return Point ( lat , lon )
else :
return None |
async def get_object ( source , * args ) :
"""Get object asynchronously .
: param source : mode class or query to get object from
: param args : lookup parameters
: return : model instance or raises ` ` peewee . DoesNotExist ` ` if object not
found""" | warnings . warn ( "get_object() is deprecated, Manager.get() " "should be used instead" , DeprecationWarning )
if isinstance ( source , peewee . Query ) :
query = source
model = query . model
else :
query = source . select ( )
model = source
# Return first object from query
for obj in ( await select ( q... |
def _inhibitColumnsWithLateral ( self , overlaps , lateralConnections ) :
"""Performs an experimentatl local inhibition . Local inhibition is
iteratively performed on a column by column basis .""" | n , m = self . shape
y = np . zeros ( n )
s = self . sparsity
L = lateralConnections
desiredWeight = self . codeWeight
inhSignal = np . zeros ( n )
sortedIndices = np . argsort ( overlaps , kind = 'mergesort' ) [ : : - 1 ]
currentWeight = 0
for i in sortedIndices :
if overlaps [ i ] < self . _stimulusThreshold :
... |
def passageLoop ( parent , new_tree , xpath1 , xpath2 = None , preceding_siblings = False , following_siblings = False ) :
"""Loop over passages to construct and increment new tree given a parent and XPaths
: param parent : Parent on which to perform xpath
: param new _ tree : Parent on which to add nodes
: p... | current_1 , queue_1 = __formatXpath__ ( xpath1 )
if xpath2 is None : # In case we need what is following or preceding our node
result_1 , loop = performXpath ( parent , current_1 )
if loop is True :
queue_1 = xpath1
central = None
has_no_queue = len ( queue_1 ) == 0
# For each sibling , when... |
def get_element_dt ( self , el_name , tz = None , el_idx = 0 ) :
"""Return the text of the selected element as a ` ` datetime . datetime ` ` object .
The element text must be a ISO8601 formatted datetime
Args :
el _ name : str
Name of element to use .
tz : datetime . tzinfo
Timezone in which to return t... | return iso8601 . parse_date ( self . get_element_by_name ( el_name , el_idx ) . text , tz ) |
def index_model ( index_name , adapter ) :
'''Indel all objects given a model''' | model = adapter . model
log . info ( 'Indexing {0} objects' . format ( model . __name__ ) )
qs = model . objects
if hasattr ( model . objects , 'visible' ) :
qs = qs . visible ( )
if adapter . exclude_fields :
qs = qs . exclude ( * adapter . exclude_fields )
docs = iter_qs ( qs , adapter )
docs = iter_for_index... |
def get_subregions ( self , iso_code ) :
"""Returns subregion calendar classes for given region iso _ code .
> > > registry = IsoRegistry ( )
> > > # assuming calendars registered are : DE , DE - HH , DE - BE
> > > registry . get _ subregions ( ' DE ' )
{ ' DE - HH ' : < class ' workalendar . europe . germa... | items = OrderedDict ( )
for key , value in self . region_registry . items ( ) :
code_elements , is_subregion = self . _code_elements ( key )
if is_subregion and code_elements [ 0 ] == iso_code :
items [ key ] = value
return items |
def add ( self , tensor , tf_sess = None , key = None , ** kwargs ) :
"""Adds a new root * tensor * for a * key * which , if * None * , defaults to a consecutive number .
When * tensor * is not an instance of : py : class : ` Tensor ` but an instance of
` ` tensorflow . Tensor ` ` , it is converted first . In t... | if not isinstance ( tensor , Tensor ) :
tensor = Tensor ( tensor , tf_sess , ** kwargs )
if key is None :
if len ( self . roots ) == 0 :
key = 0
else :
key = max ( self . roots . keys ( ) ) + 1
self . roots [ key ] = tensor |
def __option ( self ) :
"""Check and return option from section from configuration . Option name is equal to option prefix
: return : tuple of section name and option prefix""" | section = self . section ( )
option = self . option_prefix ( )
if self . config ( ) . has_option ( section , option ) is False :
raise NoOptionError ( option , section )
return section , option |
def read_raw_samples ( self , fields , thin_start = None , thin_interval = None , thin_end = None , iteration = None , walkers = None , flatten = True ) :
"""Base function for reading samples .
Parameters
fields : list
The list of field names to retrieve . Must be names of datasets in
the ` ` samples _ grou... | if isinstance ( fields , ( str , unicode ) ) :
fields = [ fields ]
# walkers to load
if walkers is not None :
widx = numpy . zeros ( self . nwalkers , dtype = bool )
widx [ walkers ] = True
nwalkers = widx . sum ( )
else :
widx = slice ( 0 , None )
nwalkers = self . nwalkers
# get the slice to u... |
def great_circle_Npoints ( lonlat1r , lonlat2r , N ) :
"""N points along the line joining lonlat1 and lonlat2""" | ratio = np . linspace ( 0.0 , 1.0 , N ) . reshape ( - 1 , 1 )
xyz1 = lonlat2xyz ( lonlat1r [ 0 ] , lonlat1r [ 1 ] )
xyz2 = lonlat2xyz ( lonlat2r [ 0 ] , lonlat2r [ 1 ] )
mids = ratio * xyz2 + ( 1.0 - ratio ) * xyz1
norm = np . sqrt ( ( mids ** 2 ) . sum ( axis = 1 ) )
xyzN = mids / norm . reshape ( - 1 , 1 )
lonlatN = ... |
def from_latlon ( latitude , longitude , force_zone_number = None , force_zone_letter = None ) :
"""This function convert Latitude and Longitude to UTM coordinate
Parameters
latitude : float
Latitude between 80 deg S and 84 deg N , e . g . ( - 80.0 to 84.0)
longitude : float
Longitude between 180 deg W an... | if not in_bounds ( latitude , - 80.0 , 84.0 ) :
raise OutOfRangeError ( 'latitude out of range (must be between 80 deg S and 84 deg N)' )
if not in_bounds ( longitude , - 180.0 , 180.0 ) :
raise OutOfRangeError ( 'longitude out of range (must be between 180 deg W and 180 deg E)' )
if force_zone_number is not No... |
def DeleteNodeTags ( r , node , tags , dry_run = False ) :
"""Delete tags from a node .
@ type node : str
@ param node : node to remove tags from
@ type tags : list of str
@ param tags : tags to remove from the node
@ type dry _ run : bool
@ param dry _ run : whether to perform a dry run
@ rtype : int... | query = { "tag" : tags , "dry-run" : dry_run , }
return r . request ( "delete" , "/2/nodes/%s/tags" % node , query = query ) |
def create_media_asset ( access_token , name , options = "0" ) :
'''Create Media Service Asset .
Args :
access _ token ( str ) : A valid Azure authentication token .
name ( str ) : Media Service Asset Name .
options ( str ) : Media Service Options .
Returns :
HTTP response . JSON body .''' | path = '/Assets'
endpoint = '' . join ( [ ams_rest_endpoint , path ] )
body = '{"Name": "' + name + '", "Options": "' + str ( options ) + '"}'
return do_ams_post ( endpoint , path , body , access_token ) |
def get_rendered_transform_path ( self ) :
"""Generates a rendered transform path
that is calculated from all parents .
: return :""" | path = self . transform_path
parent = self . parent
while parent is not None :
path = "{0}/{1}" . format ( parent . transform_path , path )
parent = parent . parent
return path |
def get_base_ami ( awsclient , owners ) :
"""DEPRECATED ! ! !
return the latest version of our base AMI
we can ' t use tags for this , so we have only the name as resource
note : this functionality is deprecated since this only works for " old "
baseami .""" | client_ec2 = awsclient . get_client ( 'ec2' )
image_filter = [ { 'Name' : 'state' , 'Values' : [ 'available' , ] } , ]
latest_ts = maya . MayaDT ( 0 ) . datetime ( naive = True )
latest_version = StrictVersion ( '0.0.0' )
latest_id = None
for i in client_ec2 . describe_images ( Owners = owners , Filters = image_filter ... |
def saveXml ( self , xml ) :
"""Saves the data for this tree to the inputed xml entry .
: param xml | < xml . etree . ElementTree . Element >
: return < bool > success""" | if xml is None :
return False
# save the grouping enabled information
xml . set ( 'groupingActive' , nativestring ( self . isGroupingActive ( ) ) )
# save the grouping information
if self . groupBy ( ) :
xml . set ( 'grouping' , ',' . join ( self . groupBy ( ) ) )
# save standard tree options
return super ( XOr... |
def create_project ( self , key , name = None , assignee = None , type = "Software" , template_name = None ) :
"""Create a project with the specified parameters .
: param key : Mandatory . Must match JIRA project key requirements , usually only 2-10 uppercase characters .
: type : str
: param name : If not sp... | if assignee is None :
assignee = self . current_user ( )
if name is None :
name = key
possible_templates = [ 'Basic' , 'JIRA Classic' , 'JIRA Default Schemes' , 'Basic software development' ]
if template_name is not None :
possible_templates = [ template_name ]
# https : / / confluence . atlassian . com / j... |
async def on_raw_333 ( self , message ) :
"""Topic setter and time on channel join .""" | target , channel , setter , timestamp = message . params
if not self . in_channel ( channel ) :
return
# No need to sync user since this is most likely outdated info .
self . channels [ channel ] [ 'topic_by' ] = self . _parse_user ( setter ) [ 0 ]
self . channels [ channel ] [ 'topic_set' ] = datetime . datetime .... |
def get_version ( package_name , ignore_cache = False ) :
"""Get the version which is currently configured by the package""" | if ignore_cache :
with microcache . temporarily_disabled ( ) :
found = helpers . regex_in_package_file ( VERSION_SET_REGEX , '_version.py' , package_name , return_match = True )
else :
found = helpers . regex_in_package_file ( VERSION_SET_REGEX , '_version.py' , package_name , return_match = True )
if f... |
def parse ( self ) :
"""Parse our project file and return : class : ` Project ` object or raise : exc : ` ParseException ` .""" | log . debug ( "Parsing Compass .MAK file %s ..." , self . makfilename )
base_location = None
linked_files = [ ]
file_params = set ( )
def parse_linked_file ( value ) :
log . debug ( "Parsing linked file: %s" , value )
value = value . rstrip ( ';' )
toks = value . split ( ',' , 1 )
if len ( toks ) == 1 ... |
def etcal ( et , lenout = _default_len_out ) :
"""Convert from an ephemeris epoch measured in seconds past
the epoch of J2000 to a calendar string format using a
formal calendar free of leapseconds .
http : / / naif . jpl . nasa . gov / pub / naif / toolkit _ docs / C / cspice / etcal _ c . html
: param et ... | lenout = ctypes . c_int ( lenout )
string = stypes . stringToCharP ( lenout )
if hasattr ( et , "__iter__" ) :
strings = [ ]
for t in et :
libspice . etcal_c ( t , lenout , string )
checkForSpiceError ( None )
strings . append ( stypes . toPythonString ( string ) )
return strings
els... |
def compute_nb_samples ( in_prefix ) :
"""Check the number of samples .
: param in _ prefix : the prefix of the input file .
: type in _ prefix : str
: returns : the number of sample in ` ` prefix . fam ` ` .""" | file_name = in_prefix + ".tfam"
nb = None
with open ( file_name , 'rb' ) as input_file :
nb = len ( input_file . readlines ( ) )
return nb |
def v_grammar_unique_defs ( ctx , stmt ) :
"""Verify that all typedefs and groupings are unique
Called for every statement .
Stores all typedefs in stmt . i _ typedef , groupings in stmt . i _ grouping""" | defs = [ ( 'typedef' , 'TYPE_ALREADY_DEFINED' , stmt . i_typedefs ) , ( 'grouping' , 'GROUPING_ALREADY_DEFINED' , stmt . i_groupings ) ]
if stmt . parent is None :
defs . extend ( [ ( 'feature' , 'FEATURE_ALREADY_DEFINED' , stmt . i_features ) , ( 'identity' , 'IDENTITY_ALREADY_DEFINED' , stmt . i_identities ) , ( ... |
def mecanum_drivetrain ( lr_motor , rr_motor , lf_motor , rf_motor , x_wheelbase = 2 , y_wheelbase = 3 , speed = 5 , deadzone = None , ) :
""". . deprecated : : 2018.2.0
Use : class : ` MecanumDrivetrain ` instead""" | return MecanumDrivetrain ( x_wheelbase , y_wheelbase , speed , deadzone ) . get_vector ( lr_motor , rr_motor , lf_motor , rf_motor ) |
def _fillna ( expr , value ) :
"""Fill null with value .
: param expr : sequence or scalar
: param value : value to fill into
: return : sequence or scalar""" | if isinstance ( expr , SequenceExpr ) :
return FillNa ( _input = expr , _fill_value = value , _data_type = expr . dtype )
elif isinstance ( expr , Scalar ) :
return FillNa ( _input = expr , _fill_value = value , _value_type = expr . dtype ) |
def mklabel ( device , label_type ) :
'''Create a new disklabel ( partition table ) of label _ type .
Type should be one of " aix " , " amiga " , " bsd " , " dvh " , " gpt " , " loop " , " mac " ,
" msdos " , " pc98 " , or " sun " .
CLI Example :
. . code - block : : bash
salt ' * ' partition . mklabel / ... | if label_type not in set ( [ 'aix' , 'amiga' , 'bsd' , 'dvh' , 'gpt' , 'loop' , 'mac' , 'msdos' , 'pc98' , 'sun' ] ) :
raise CommandExecutionError ( 'Invalid label_type passed to partition.mklabel' )
cmd = ( 'parted' , '-m' , '-s' , device , 'mklabel' , label_type )
out = __salt__ [ 'cmd.run' ] ( cmd , python_shell... |
def register_plugins ( self ) :
"""Load plugins listed in config variable ' PLUGINS ' .""" | registered = set ( )
for plugin_fqdn in chain ( self . APP_PLUGINS , self . config [ "PLUGINS" ] ) :
if plugin_fqdn not in registered :
self . register_plugin ( plugin_fqdn )
registered . add ( plugin_fqdn ) |
def convert_advanced_relu ( builder , layer , input_names , output_names , keras_layer ) :
"""Convert an ReLU layer with maximum value from keras to coreml .
Parameters
keras _ layer : layer
A keras layer object .
builder : NeuralNetworkBuilder
A neural network builder object .""" | # Get input and output names
input_name , output_name = ( input_names [ 0 ] , output_names [ 0 ] )
if keras_layer . max_value is None :
builder . add_activation ( layer , 'RELU' , input_name , output_name )
return
# No direct support of RELU with max - activation value - use negate and
# clip layers
relu_output... |
def parents ( self , node , relations = None ) :
"""Return all direct parents of specified node .
Wraps networkx by default .
Arguments
node : string
identifier for node in ontology
relations : list of strings
list of relation ( object property ) IDs used to filter""" | g = self . get_graph ( )
if node in g :
parents = list ( g . predecessors ( node ) )
if relations is None :
return parents
else :
rset = set ( relations )
return [ p for p in parents if len ( self . child_parent_relations ( node , p , graph = g ) . intersection ( rset ) ) > 0 ]
else ... |
def parse_encoding ( fp ) :
"""Deduce the encoding of a Python source file ( binary mode ) from magic
comment .
It does this in the same way as the ` Python interpreter ` _ _
. . _ _ : http : / / docs . python . org / ref / encodings . html
The ` ` fp ` ` argument should be a seekable file object in binary ... | pos = fp . tell ( )
fp . seek ( 0 )
try :
line1 = fp . readline ( )
has_bom = line1 . startswith ( codecs . BOM_UTF8 )
if has_bom :
line1 = line1 [ len ( codecs . BOM_UTF8 ) : ]
m = _PYTHON_MAGIC_COMMENT_re . match ( line1 . decode ( 'ascii' , 'ignore' ) )
if not m :
try :
... |
def add_qtl_to_map ( qtlfile , mapfile , outputfile = 'map_with_qtls.csv' ) :
"""This function adds to a genetic map for each marker the number
of significant QTLs found .
: arg qtlfile , the output from MapQTL transformed to a csv file via
' parse _ mapqtl _ file ' which contains the closest markers .
: ar... | qtl_list = read_input_file ( qtlfile , ',' )
map_list = read_input_file ( mapfile , ',' )
map_list [ 0 ] . append ( '# QTLs' )
markers = [ ]
markers . append ( map_list [ 0 ] )
qtl_cnt = 0
for marker in map_list [ 1 : ] :
markers . append ( add_qtl_to_marker ( marker , qtl_list [ 1 : ] ) )
qtl_cnt = qtl_cnt + i... |
def get_webhook_url ( deployment_name , space = 'default' , data_source = 'webhook' , token_manager = None , app_url = defaults . APP_URL , ** fields ) :
"""return the webhook URL for posting webhook data to""" | import_url = data_engine . get_import_data_url ( deployment_name , app_url = app_url , token_manager = token_manager )
api_key = deployments . get_apikey ( deployment_name , token_manager = token_manager , app_url = app_url )
fields_string = '&' . join ( [ '%s=%s' % ( key , value ) for ( key , value ) in fields . items... |
def _add_nonce ( self , response ) :
"""Store a nonce from a response we received .
: param twisted . web . iweb . IResponse response : The HTTP response .
: return : The response , unmodified .""" | nonce = response . headers . getRawHeaders ( REPLAY_NONCE_HEADER , [ None ] ) [ 0 ]
with LOG_JWS_ADD_NONCE ( raw_nonce = nonce ) as action :
if nonce is None :
raise errors . MissingNonce ( response )
else :
try :
decoded_nonce = Header . _fields [ 'nonce' ] . decode ( nonce . decode... |
def include_callback_query_chat_id ( fn = pair , types = 'all' ) :
""": return :
a pair producer that enables static callback query capturing
across seeder and delegator .
: param types :
` ` all ` ` or a list of chat types ( ` ` private ` ` , ` ` group ` ` , ` ` channel ` ` )""" | @ _ensure_seeders_list
def p ( seeders , delegator_factory , * args , ** kwargs ) :
return fn ( seeders + [ per_callback_query_chat_id ( types = types ) ] , delegator_factory , * args , include_callback_query = True , ** kwargs )
return p |
def _load_clublogXML ( self , url = "https://secure.clublog.org/cty.php" , apikey = None , cty_file = None ) :
"""Load and process the ClublogXML file either as a download or from file""" | if self . _download :
cty_file = self . _download_file ( url = url , apikey = apikey )
else :
cty_file = self . _lib_filename
header = self . _extract_clublog_header ( cty_file )
cty_file = self . _remove_clublog_xml_header ( cty_file )
cty_dict = self . _parse_clublog_xml ( cty_file )
self . _entities = cty_di... |
def convert_to_flat ( self , builder ) :
"""In this conversion , we always want to return a valid flatbuffer pointer even if all the
contents are blank because sometimes we need to put empty car states into the car list
to make the indices line up .""" | physics_offset = None if self . physics is None else self . physics . convert_to_flat ( builder )
DesiredCarState . DesiredCarStateStart ( builder )
if physics_offset is not None :
DesiredCarState . DesiredCarStateAddPhysics ( builder , physics_offset )
if self . boost_amount is not None :
DesiredCarState . Des... |
def otherwise ( self , value ) :
"""Evaluates a list of conditions and returns one of multiple possible result expressions .
If : func : ` Column . otherwise ` is not invoked , None is returned for unmatched conditions .
See : func : ` pyspark . sql . functions . when ` for example usage .
: param value : a l... | v = value . _jc if isinstance ( value , Column ) else value
jc = self . _jc . otherwise ( v )
return Column ( jc ) |
def structs2pandas ( structs ) :
"""convert ctypes structure or structure array to pandas data frame""" | try :
import pandas
records = list ( structs2records ( structs ) )
df = pandas . DataFrame . from_records ( records )
# TODO : do this for string columns , for now just for id
# How can we check for string columns , this is not nice :
# df . columns [ df . dtypes = = object ]
if 'id' in df :... |
def format_timestamp ( ts ) :
"""Format the UTC timestamp for Elasticsearch
eg . 2014-07-09T08:37:18.000Z
@ see https : / / docs . python . org / 2 / library / time . html # time . strftime""" | tz_info = tz . tzutc ( )
return datetime . fromtimestamp ( ts , tz = tz_info ) . strftime ( "%Y-%m-%dT%H:%M:%S.000Z" ) |
def std_err ( self ) :
"""Standard error of the estimate ( SEE ) . A scalar .
For standard errors of parameters , see _ se _ all , se _ alpha , and se _ beta .""" | return np . sqrt ( np . sum ( np . square ( self . resids ) , axis = 0 ) / self . df_err ) |
def inflate_long ( s , always_positive = False ) :
"turns a normalized byte string into a long - int ( adapted from Crypto . Util . number )" | out = 0L
negative = 0
if not always_positive and ( len ( s ) > 0 ) and ( ord ( s [ 0 ] ) >= 0x80 ) :
negative = 1
if len ( s ) % 4 :
filler = '\x00'
if negative :
filler = '\xff'
s = filler * ( 4 - len ( s ) % 4 ) + s
for i in range ( 0 , len ( s ) , 4 ) :
out = ( out << 32 ) + struct . unpa... |
async def shutdown ( sig , loop ) :
"""Gracefully cancel current tasks when app receives a shutdown signal .""" | logging . info ( f'Received exit signal {sig.name}...' )
tasks = [ task for task in asyncio . Task . all_tasks ( ) if task is not asyncio . tasks . Task . current_task ( ) ]
for task in tasks :
logging . debug ( f'Cancelling task: {task}' )
task . cancel ( )
results = await asyncio . gather ( * tasks , return_e... |
def add_vertex ( self , v ) :
"""Add a vertex to the graph . The vertex must implement _ _ hash _ _ and _ _ eq _ _ as it will be stored in a set .
: param v : vertex
: return : graph owned vertex""" | if v not in self . adjacency :
self . adjacency [ v ] = Vertex ( v )
return self . adjacency [ v ] . vertex |
def get_start_and_end_time ( self , ref = None ) :
"""Specific function to get start time and end time for MonthDateDaterange
: param ref : time in seconds
: type ref : int
: return : tuple with start and end time
: rtype : tuple ( int , int )""" | now = time . localtime ( ref )
if self . syear == 0 :
self . syear = now . tm_year
day_start = find_day_by_offset ( self . syear , self . smon , self . smday )
start_time = get_start_of_day ( self . syear , self . smon , day_start )
if self . eyear == 0 :
self . eyear = now . tm_year
day_end = find_day_by_offse... |
def searchAccount ( searchTerm , book ) :
"""Searches through account names""" | print ( "Search results:\n" )
found = False
# search
for account in book . accounts : # print ( account . fullname )
# name
if searchTerm . lower ( ) in account . fullname . lower ( ) :
print ( account . fullname )
found = True
if not found :
print ( "Search term not found in account names." ) |
def merge_moments ( m_a , m_a2 , m_a3 , m_a4 , n_a , m_b , m_b2 , m_b3 , m_b4 , n_b ) :
'''Merge moments of two samples A and B .
parameters are
m _ a , . . . , m _ a4 = first through fourth moment of sample A
n _ a = size of sample A
m _ b , . . . , m _ b4 = first through fourth moment of sample B
n _ b ... | delta = m_b - m_a
delta_2 = delta * delta
delta_3 = delta * delta_2
delta_4 = delta * delta_3
n_x = n_a + n_b
m_x = m_a + delta * n_b / n_x
m_x2 = m_a2 + m_b2 + delta_2 * n_a * n_b / n_x
m_x3 = m_a3 + m_b3 + delta_3 * n_a * n_b * ( n_a - n_b ) + 3 * delta * ( n_a * m_2b - n_b * m_2a ) / n_x
m_x4 = ( m_a4 + m_b4 + delta... |
def analyze ( segments , analysis , lookup = dict ( bipa = { } , dolgo = { } ) ) :
"""Test a sequence for compatibility with CLPA and LingPy .
: param analysis : Pass a ` TranscriptionAnalysis ` instance for cumulative reporting .""" | # raise a ValueError in case of empty segments / strings
if not segments :
raise ValueError ( 'Empty sequence.' )
# test if at least one element in ` segments ` has information
# ( helps to catch really badly formed input , such as [ ' \ n ' ]
if not [ segment for segment in segments if segment . strip ( ) ] :
... |
def set_grads ( params , params_with_grad ) :
"""Copies gradients from param _ with _ grad to params
: param params : dst parameters
: param params _ with _ grad : src parameters""" | for param , param_w_grad in zip ( params , params_with_grad ) :
if param . grad is None :
param . grad = torch . nn . Parameter ( torch . empty_like ( param ) )
param . grad . data . copy_ ( param_w_grad . grad . data ) |
def _build_map ( self ) :
"""Read the map file at path .""" | if gf . is_py2_narrow_build ( ) :
self . log_warn ( u"Running on a Python 2 narrow build: be aware that Unicode chars above 0x10000 cannot be replaced correctly." )
self . trans_map = { }
with io . open ( self . file_path , "r" , encoding = "utf-8" ) as file_obj :
contents = file_obj . read ( ) . replace ( u"\t... |
def retrieveVals ( self ) :
"""Retrieve values for graphs .""" | if self . _stats is None :
serverInfo = MemcachedInfo ( self . _host , self . _port , self . _socket_file )
stats = serverInfo . getStats ( )
else :
stats = self . _stats
if stats is None :
raise Exception ( "Undetermined error accesing stats." )
stats [ 'set_hits' ] = stats . get ( 'total_items' )
if s... |
def reset_service_group ( self , loadbal_id , group_id ) :
"""Resets all the connections on the service group .
: param int loadbal _ id : The id of the loadbal
: param int group _ id : The id of the service group to reset""" | _filter = { 'virtualServers' : { 'id' : utils . query_filter ( group_id ) } }
virtual_servers = self . lb_svc . getVirtualServers ( id = loadbal_id , filter = _filter , mask = 'serviceGroups' )
actual_id = virtual_servers [ 0 ] [ 'serviceGroups' ] [ 0 ] [ 'id' ]
svc = self . client [ 'Network_Application_Delivery_Contr... |
def compute_dataset_statistics ( dataset_path , output_path , config ) :
"""Compute the statistics of fields of a TensorDataset
Parameters
dataset _ path : str
path to the dataset
output _ dir : str
where to save the data
config : : obj : ` YamlConfig `
parameters for the analysis""" | # parse config
analysis_fields = config [ 'analysis_fields' ]
num_percentiles = config [ 'num_percentiles' ]
thresholds = config [ 'thresholds' ]
log_rate = config [ 'log_rate' ]
num_bins = config [ 'num_bins' ]
font_size = config [ 'font_size' ]
line_width = config [ 'line_width' ]
dpi = config [ 'dpi' ]
# create data... |
def get_fobj ( fname , mode = 'w+' ) :
"""Obtain a proper file object .
Parameters
fname : string , file object , file descriptor
If a string or file descriptor , then we create a file object . If
* fname * is a file object , then we do nothing and ignore the specified
* mode * parameter .
mode : str
... | if is_string_like ( fname ) :
fobj = open ( fname , mode )
close = True
elif hasattr ( fname , 'write' ) : # fname is a file - like object , perhaps a StringIO ( for example )
fobj = fname
close = False
else : # assume it is a file descriptor
fobj = os . fdopen ( fname , mode )
close = False
ret... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.