code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def create_korobov_samples(order, dim, base=17797):
values = numpy.empty(dim)
values[0] = 1
for idx in range(1, dim):
values[idx] = ((base * values[(idx - 1)]) % (order + 1))
grid = numpy.mgrid[(:dim, :(order + 1))]
out = (((values[grid[0]] * (grid[1] + 1)) / (order + 1.0)) % 1.0)
return... | Create Korobov lattice samples.
Args:
order (int):
The order of the Korobov latice. Defines the number of
samples.
dim (int):
The number of dimensions in the output.
base (int):
The number based used to calculate the distribution of values.
Returns (numpy.ndarray):
Korobov lattice with ``shape == (dim, order)`` | codesearchnet |
def action(elem, doc):
if isinstance(elem, pf.CodeBlock):
doc.listings_counter += 1
elems = [elem] if 'hide' not in elem.classes else []
if 'file' in elem.attributes:
elem.text = read_file(elem.attributes['file'])
filename = trimpath(elem.attributes)
... | Processes pf.CodeBlocks.
For details and a specification of how each command should behave,
check the example files (especially the md and pdf)!
Args:
elem: The element to process.
doc: The document.
Returns:
A changed element or None. | juraj-google-style |
def list_tensors(self, args, screen_info=None):
_ = screen_info
parsed = self._arg_parsers['list_tensors'].parse_args(args)
output = []
filter_strs = []
if parsed.op_type_filter:
op_type_regex = re.compile(parsed.op_type_filter)
filter_strs.append('Op type regex filter: "%s"' % parse... | Command handler for list_tensors.
List tensors dumped during debugged Session.run() call.
Args:
args: Command-line arguments, excluding the command prefix, as a list of
str.
screen_info: Optional dict input containing screen information such as
cols.
Returns:
Output text lines as a RichTextLines object.
Raises:
Val... | github-repos |
def _get_language_modeling_inputs(filename,
delimiter="\n",
repeat=1,
append_space_to_final_punctionation=True):
with tf.gfile.Open(filename) as f:
text = f.read()
inputs = text.split(delimiter)
if not inp... | Read a file of partial texts to continue.
The purpose of append_space_to_final_punctionation is that SubwordTokenizer
groups punctuation and the ensuing space in the same token. Adding a space
causes the token to be completed.
Args:
filename: a string
delimiter: a string
repeat: an integer - we repeat the entire fil... | juraj-google-style |
def CollectFromKnowledgeBase(cls, knowledge_base):
for preprocess_plugin in cls._knowledge_base_plugins.values():
logger.debug('Running knowledge base preprocessor plugin: {0:s}'.format(
preprocess_plugin.__class__.__name__))
try:
preprocess_plugin.Collect(knowledge_base)
ex... | Collects values from knowledge base values.
Args:
knowledge_base (KnowledgeBase): to fill with preprocessing information. | juraj-google-style |
def scale(reader, writer, column, start, stop, multiple):
for (i, row) in enumerate(reader):
if ((i >= start) and (i <= stop)):
row[column] = (type(multiple)(row[column]) * multiple)
writer.appendRecord(row) | Multiplies a value over a range of rows.
Args:
reader: A FileRecordStream object with input data.
writer: A FileRecordStream object to write output data to.
column: The column of data to modify.
start: The first row in the range to modify.
end: The last row in the range to modify.
multiple: The value to scale/multipl... | codesearchnet |
def combine_samples(self, md5_list, filename, type_tag):
total_bytes = ''
for md5 in md5_list:
total_bytes += self.get_sample(md5)['sample']['raw_bytes']
self.remove_sample(md5)
return self.store_sample(total_bytes, filename, type_tag) | Combine samples together. This may have various use cases the most significant
involving a bunch of sample 'chunks' got uploaded and now we combine them together
Args:
md5_list: The list of md5s to combine, order matters!
filename: name of the file (used purely as meta data not for lookup)
type_tag: ('exe','pcap','pdf... | codesearchnet |
def get_stdout(self, workflow_id, task_id):
url = ('%(wf_url)s/%(wf_id)s/tasks/%(task_id)s/stdout' % {'wf_url': self.workflows_url, 'wf_id': workflow_id, 'task_id': task_id})
r = self.gbdx_connection.get(url)
r.raise_for_status()
return r.text | Get stdout for a particular task.
Args:
workflow_id (str): Workflow id.
task_id (str): Task id.
Returns:
Stdout of the task (string). | codesearchnet |
def convert_maxpool3(params, w_name, scope_name, inputs, layers, weights, names):
print('Converting pooling ...')
if (names == 'short'):
tf_name = ('P' + random_string(7))
elif (names == 'keep'):
tf_name = w_name
else:
tf_name = (w_name + str(random.random()))
if ('kernel_sha... | Convert 3d Max pooling.
Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers | codesearchnet |
def from_file(cls, weafile, timestep=1, is_leap_year=False):
assert os.path.isfile(weafile), 'Failed to find {}'.format(weafile)
location = Location()
with open(weafile, readmode) as weaf:
first_line = weaf.readline()
assert first_line.startswith('place'), 'Failed to find place in header. {}... | Create wea object from a wea file.
Args:
weafile:Full path to wea file.
timestep: An optional integer to set the number of time steps per hour.
Default is 1 for one value per hour. If the wea file has a time step
smaller than an hour adjust this input accordingly.
is_leap_year: A boolean to indicate if values are repr... | codesearchnet |
def operate_multi(self, points):
points = np.array(points)
affine_points = np.concatenate([points, np.ones((points.shape[:(- 1)] + (1,)))], axis=(- 1))
return np.inner(affine_points, self.affine_matrix)[(..., :(- 1))] | Apply the operation on a list of points.
Args:
points: List of Cartesian coordinates
Returns:
Numpy array of coordinates after operation | codesearchnet |
def get_variant_by_name(self, name):
try:
geno, i = self.bed.get_geno_marker(name, return_index=True)
except ValueError:
if name in self.bed.get_duplicated_markers():
return [
self.g... | Get the genotype of a marker using it's name.
Args:
name (str): The name of the marker.
Returns:
list: A list of Genotypes (only one for PyPlink, see note below).
Note
====
From PyPlink version 1.3.2 and onwards, each name is unique in the
dataset. Hence, we can use the 'get_geno_marker' function and be
sure only on... | juraj-google-style |
def wait_running(self, timeout=None):
flag = self._running.wait(timeout)
if (flag is False):
raise TimeoutExpiredError('Timeout waiting for thread to start running') | Wait for the thread to pass control to its routine.
Args:
timeout (float): The maximum amount of time to wait | codesearchnet |
def __init__(self,
status=enums.ResultStatus.OPERATION_FAILED,
reason=enums.ResultReason.GENERAL_FAILURE,
message='A general failure occurred.'):
super(KmipError, self).__init__(message)
self.status = status
self.reason = reason | Create a KmipError exception.
Args:
status (ResultStatus): An enumeration detailing the result outcome.
reason (ResultReason): An enumeration giving the status rationale.
message (string): A string containing more information about the
error. | juraj-google-style |
def validate(data):
text = data.get('text')
if ((not isinstance(text, _string_types)) or (len(text) == 0)):
raise ValueError('text field is required and should not be empty')
if (('markdown' in data) and (not (type(data['markdown']) is bool))):
raise ValueError('markdown field should be bool... | Validates incoming data
Args:
data(dict): the incoming data
Returns:
True if the data is valid
Raises:
ValueError: the data is not valid | codesearchnet |
def refreshSkypeToken(self):
(self.tokens['skype'], self.tokenExpiry['skype']) = SkypeRefreshAuthProvider(self).auth(self.tokens['skype'])
self.getRegToken() | Take the existing Skype token and refresh it, to extend the expiry time without other credentials.
Raises:
.SkypeAuthException: if the login request is rejected
.SkypeApiException: if the login form can't be processed | codesearchnet |
def generate(self, text):
if not text:
raise Exception("No text to speak")
if len(text) >= self.MAX_CHARS:
raise Exception("Number of characters must be less than 2000")
params = self.__params.copy()
params["text"] = text
self._data = requests.g... | Try to get the generated file.
Args:
text: The text that you want to generate. | juraj-google-style |
def check_filepath(self, path, filename):
settings_path = os.path.join(path, filename)
if ((not os.path.exists(settings_path)) or (not os.path.isfile(settings_path))):
msg = 'Unable to find settings file: {}'
raise SettingsBackendError(msg.format(settings_path))
return settings_path | Check and return the final filepath to settings
Args:
path (str): Directory path where to search for settings file.
filename (str): Filename to use to search for settings file.
Raises:
boussole.exceptions.SettingsBackendError: If determined filepath
does not exists or is a directory.
Returns:
string: Settings file p... | codesearchnet |
def is_subset(self, other):
if isinstance(other, _basebag):
for (elem, count) in self.counts():
if (not (count <= other.count(elem))):
return False
else:
for elem in self:
if ((self.count(elem) > 1) or (elem not in other)):
return False
... | Check that every element in self has a count <= in other.
Args:
other (Set) | codesearchnet |
def grid_reload_from_ids(oargrid_jobids):
gk = get_api_client()
jobs = []
for (site, job_id) in oargrid_jobids:
jobs.append(gk.sites[site].jobs[job_id])
return jobs | Reload all running or pending jobs of Grid'5000 from their ids
Args:
oargrid_jobids (list): list of ``(site, oar_jobid)`` identifying the
jobs on each site
Returns:
The list of python-grid5000 jobs retrieved | codesearchnet |
def EncryptPrivateKey(self, decrypted):
aes = AES.new(self._master_key, AES.MODE_CBC, self._iv)
return aes.encrypt(decrypted) | Encrypt the provided plaintext with the initialized private key.
Args:
decrypted (byte string): the plaintext to be encrypted.
Returns:
bytes: the ciphertext. | juraj-google-style |
def vocabulary_size(self):
if tf.executing_eagerly():
return int(self.lookup_table.size().numpy()) + self._token_start_index()
else:
return self.lookup_table.size() + self._token_start_index() | Gets the current size of the layer's vocabulary.
Returns:
The integer size of the vocabulary, including optional mask and oov
indices. | github-repos |
def build_current_graph():
graph = SQLStateGraph()
for (app_name, config) in apps.app_configs.items():
try:
module = import_module('.'.join((config.module.__name__, SQL_CONFIG_MODULE)))
sql_items = module.sql_items
except (ImportError, AttributeError):
continu... | Read current state of SQL items from the current project state.
Returns:
(SQLStateGraph) Current project state graph. | codesearchnet |
def rename(self, source_file_names, destination_file_names):
err_msg = 'source_file_names and destination_file_names should be equal in length'
assert len(source_file_names) == len(destination_file_names), err_msg
gcs_batches = []
gcs_current_batch = []
for src, dest in zip(source_file_names, destin... | Rename the files at the source list to the destination list.
Source and destination lists should be of the same size.
Args:
source_file_names: List of file paths that need to be moved
destination_file_names: List of destination_file_names for the files
Raises:
``BeamIOError``: if any of the rename operations fail | github-repos |
def _get_imports_for_module(module: str, output_package: str, symbols_by_module: Mapping[str, set[_Entrypoint]], generated_imports_by_module: Mapping[str, set[str]], file_prefixes_to_strip: Sequence[str], module_prefix: str, use_lazy_loading: bool, subpackage_rewrite: Optional[str]) -> str:
content = ''
symbol_... | Returns the imports for a module.
Args:
module: The module to get imports for.
output_package: The package to use for the imports.
symbols_by_module: The symbols that should be exposed by each module.
generated_imports_by_module: The sub-modules that should be exposed by each
module.
file_prefixes_to_strip: The prefix... | github-repos |
def parse_gptl(file_path, var_list):
timing_result = dict()
if os.path.isfile(file_path):
with open(file_path, 'r') as f:
for var in var_list:
for line in f:
if var in line:
timing_result[var] = float(line.split()[4])/int(line.... | Read a GPTL timing file and extract some data.
Args:
file_path: the path to the GPTL timing file
var_list: a list of strings to look for in the file
Returns:
A dict containing key-value pairs of the livvkit
and the times associated with them | juraj-google-style |
def register(self, user_dict):
endpoint = os.path.join(self._config.get('napps', 'api'), 'users', '')
res = self.make_request(endpoint, method='POST', json=user_dict)
return res.content.decode('utf-8') | Send an user_dict to NApps server using POST request.
Args:
user_dict(dict): Dictionary with user attributes.
Returns:
result(string): Return the response of Napps server. | juraj-google-style |
def add_to_submission(self, submission_id, submission_objects):
LOG.info("Adding new variants and case data to clinvar submission '%s'", submission_id)
for var_obj in submission_objects[0]:
try:
result = self.clinvar_collection.insert_one(var_obj)
self.clinvar_submission_collecti... | Adds submission_objects to clinvar collection and update the coresponding submission object with their id
Args:
submission_id(str) : id of the submission to be updated
submission_objects(tuple): a tuple of 2 elements coresponding to a list of variants and a list of case data objects to add to submission
Returns:
upda... | codesearchnet |
def __init__(self, input_energy):
self._energy = input_energy
self._num_bits = input_energy.num_bits
self._parameters = dict(input_energy=input_energy)
self._index_proposal_probs = tf.Variable([0.0] * self._num_bits, trainable=False)
self._index_proposal_dist = tfp.distributions.Categorical(probs=se... | Initializes a GibbsWithGradientsKernel.
Args:
input_energy: The parameterized energy function which helps define the
acceptance probabilities of the Markov chain. | github-repos |
def get_nets_radb(self, response, is_http=False):
nets = []
if is_http:
regex = 'route(?:6)?:[^\\S\\n]+(?P<val>.+?)<br>'
else:
regex = '^route(?:6)?:[^\\S\\n]+(?P<val>.+|.+)$'
for match in re.finditer(regex, response, re.MULTILINE):
try:
net = copy.deepcopy(BASE_NET)
... | The function for parsing network blocks from ASN origin data.
Args:
response (:obj:`str`): The response from the RADB whois/http
server.
is_http (:obj:`bool`): If the query is RADB HTTP instead of whois,
set to True. Defaults to False.
Returns:
list: A list of network block dictionaries
::
[{
'cidr' (str) - The ass... | codesearchnet |
def dapply(self, fn, pairwise=False, symmetric=True, diagonal=False, block=None, **kwargs):
search_keys = [k for (k, v) in kwargs.items() if (isinstance(v, list) and (len(v) > 1))]
functions = util.make_list(fn)
search = list(product(functions, util.dict_product(kwargs)))
results = []
for (fn, kw) i... | Apply function to each step object in the index
Args:
fn: function to apply. If a list then each function is applied
pairwise: whether to apply the function to pairs of steps
symmetric, diagonal, block: passed to apply_pairwise when pairwise=True
kwargs: a keyword arguments to pass to each function. Arguments
with lis... | codesearchnet |
def model_custom_sink(simplekv, KVs, final_table_name_no_ptransform, final_table_name_with_ptransform):
final_table_name = final_table_name_no_ptransform
with beam.Pipeline(options=PipelineOptions()) as pipeline:
kvs = pipeline | 'CreateKVs' >> beam.Create(KVs)
kvs | 'WriteToSimpleKV' >> beam.io... | Demonstrates creating a new custom sink and using it in a pipeline.
Uses the new sink in an example pipeline.
Additionally demonstrates how a sink should be implemented using a
``PTransform``. This is the recommended way to develop sinks that are to be
distributed to a large number of end users.
This method runs two... | github-repos |
def hgnc_genes(self, hgnc_symbol, build='37', search=False):
LOG.debug("Fetching genes with symbol %s" % hgnc_symbol)
if search:
full_query = self.hgnc_collection.find({
'$or': [
{'aliases': hgnc_symbol},
{'hgnc_id... | Fetch all hgnc genes that match a hgnc symbol
Check both hgnc_symbol and aliases
Args:
hgnc_symbol(str)
build(str): The build in which to search
search(bool): if partial searching should be used
Returns:
result() | juraj-google-style |
def filter_pyfqn(cls, value, relative_to=0):
def collect_packages(element, packages):
parent = element.eContainer()
if parent:
collect_packages(parent, packages)
packages.append(element.name)
packages = []
collect_packages(value, pac... | Returns Python form of fully qualified name.
Args:
relative_to: If greater 0, the returned path is relative to the first n directories. | juraj-google-style |
def _AddOption(self, name):
if name in [option.name for option in self.options]:
raise TextFSMTemplateError('Duplicate option "%s"' % name)
try:
option = self._options_cls.GetOption(name)(self)
except AttributeError:
raise TextFSMTemplateError('Unknown option "%s"' % name)... | Add an option to this Value.
Args:
name: (str), the name of the Option to add.
Raises:
TextFSMTemplateError: If option is already present or
the option does not exist. | juraj-google-style |
def end_block(self, request_end_block):
self.abort_if_abci_chain_is_not_synced()
chain_shift = 0 if self.chain is None else self.chain['height']
height = request_end_block.height + chain_shift
self.new_height = height
logger.debug(f'Updating pre-com... | Calculate block hash using transaction ids and previous block
hash to be stored in the next block.
Args:
height (int): new height of the chain. | juraj-google-style |
def list_groups(name):
if six.PY2:
name = _to_unicode(name)
ugrp = set()
try:
user = info(name)['groups']
except KeyError:
return False
for group in user:
ugrp.add(group.strip(' *'))
return sorted(list(ugrp)) | Return a list of groups the named user belongs to
Args:
name (str): The user name for which to list groups
Returns:
list: A list of groups to which the user belongs
CLI Example:
.. code-block:: bash
salt '*' user.list_groups foo | juraj-google-style |
def convert(self, vroot, entry_variables):
self.graph_info = GraphInfo(vroot)
self.entry_variables = entry_variables
with nn.parameter_scope(self.name):
for t, func in enumerate(self.graph_info.funcs):
if func.name in self.inner_prod_functions:
... | All functions are replaced with the same `new` function.
Args:
vroot (:obj:`Variable`): NNabla Variable
entry_variables (:obj:`Variable`): Entry variable from which the conversion starts. | juraj-google-style |
def get_index_from_alias(alias_name, index_client=None):
index_client = (index_client or indices_client())
if (not index_client.exists_alias(name=alias_name)):
return None
return list(index_client.get_alias(name=alias_name).keys())[0] | Retrieve the base index name from an alias
Args:
alias_name (str) Name of the alias
index_client (Elasticsearch.IndicesClient) an Elasticsearch index
client. Optional, will create one if not given
Returns: (str) Name of index | codesearchnet |
def format(self, info_dict, delimiter='/'):
def dfs(father, path, acc):
if isinstance(father, list):
for child in father:
dfs(child, path, acc)
elif isinstance(father, collections.Mapping):
for child in (sorted(father.items(), key=itemgetter(0)),):
... | This formatter will take a data structure that
represent a tree and will print all the paths
from the root to the leaves
in our case it will print each value and the keys
that needed to get to it, for example:
vm0:
net: lago
memory: 1024
will be output as:
vm0/net/lago
vm0/memory/1024
Args:
info_dict (dict): infor... | codesearchnet |
def retrieve_taf(station_icao) -> typing.Tuple[typing.Union[str, None], typing.Union[str, None]]:
url = _BASE_TAF_URL.format(station=station_icao)
with requests.get(url) as resp:
if not resp.ok:
return f'unable to obtain TAF for station {station_icao}\n' \
f'Got to "h... | Retrieves a TAF string from an online database
Args:
station_icao: ICAO of the station
Returns:
tuple of error, metar_str | juraj-google-style |
def renderJsonReadsSince(self, timestamp, meter):
result = ""
try:
connection = sqlite3.connect(self.m_connection_string)
connection.row_factory = self.dict_factory
select_cursor = connection.cursor()
select_cursor.execute("select * from Meter_Rea... | Simple since Time_Stamp query returned as JSON records.
Args:
timestamp (int): Epoch time in seconds.
meter (str): 12 character meter address to query
Returns:
str: JSON rendered read records. | juraj-google-style |
def _ConvertBool(value, require_str):
if require_str:
if (value == 'true'):
return True
elif (value == 'false'):
return False
else:
raise ParseError('Expected "true" or "false", not {0}.'.format(value))
if (not isinstance(value, bool)):
raise P... | Convert a boolean value.
Args:
value: A scalar value to convert.
require_str: If True, value must be a str.
Returns:
The bool parsed.
Raises:
ParseError: If a boolean value couldn't be consumed. | codesearchnet |
def url_assembler(query_string, no_redirect=0, no_html=0, skip_disambig=0):
params = [('q', query_string.encode("utf-8")), ('format', 'json')]
if no_redirect:
params.append(('no_redirect', 1))
if no_html:
params.append(('no_html', 1))
if skip_disambig:
params.append(('skip_... | Assembler of parameters for building request query.
Args:
query_string: Query to be passed to DuckDuckGo API.
no_redirect: Skip HTTP redirects (for !bang commands). Default - False.
no_html: Remove HTML from text, e.g. bold and italics. Default - False.
skip_disambig: Skip disambiguation (D) Type. Default - False.
Re... | juraj-google-style |
def read_header(self, file_handle, nextdata_offset=0):
header = {'FCS format': file_handle.read(6)}
file_handle.read(4)
for field in ('text start', 'text end', 'data start', 'data end', 'analysis start',
'analysis end'):
s = file_handle.read(8)
... | Read the header of the FCS file.
The header specifies where the annotation, data and analysis are located inside the binary
file.
Args:
file_handle: buffer containing FCS file.
nextdata_offset: byte offset of a set header from file start specified by $NEXTDATA | juraj-google-style |
def __init__(self, default: typing.Any=MISSING_VALUE, annotation: typing.Any=MISSING_VALUE, transform: typing.Optional[typing.Callable[[typing.Any], typing.Any]]=None, frozen: bool=False):
super().__init__(object, default, transform, is_noneable=True, frozen=frozen)
self._annotation = annotation | Constructor.
Args:
default: (Optional) default value of this spec.
annotation: (Optional) external provided type annotation.
transform: (Optional) user-defined function to be called on the input
of `apply`. It could be used as a type converter or a custom
validator which may raise errors.
frozen: If True, values other... | github-repos |
def apply_sql(query: str, output_name: Optional[str], found: Dict[str, beam.PCollection], run: bool=True) -> Tuple[str, Union[PValue, SqlNode], SqlChain]:
output_name = _generate_output_name(output_name, query, found)
query, sql_source, chain = _build_query_components(query, found, output_name, run)
if run:... | Applies a SqlTransform with the given sql and queried PCollections.
Args:
query: The SQL query executed in the magic.
output_name: (optional) The output variable name in __main__ module.
found: The PCollections with variable names found to be used in the query.
run: Whether to prepare the SQL pipeline for a local run ... | github-repos |
def add_peer_parser(subparsers, parent_parser):
parser = subparsers.add_parser(
'peer',
help='Displays information about validator peers',
description="Provides a subcommand to list a validator's peers")
grand_parsers = parser.add_subparsers(title='subcommands',
... | Adds argument parser for the peer command
Args:
subparsers: Add parsers to this subparser object
parent_parser: The parent argparse.ArgumentParser object | juraj-google-style |
def list_load_balancers(access_token, subscription_id):
endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Network/', '/loadBalancers?api-version=', NETWORK_API])
return do_get(endpoint, access_token) | List the load balancers in a subscription.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
Returns:
HTTP response. JSON body of load balancer list with properties. | codesearchnet |
def from_snl(cls, snl):
hist = []
for h in snl.history:
d = h.description
d['_snl'] = {'url': h.url, 'name': h.name}
hist.append(d)
return cls(snl.structure, history=hist) | Create TransformedStructure from SNL.
Args:
snl (StructureNL): Starting snl
Returns:
TransformedStructure | juraj-google-style |
def sampler(dataframe, modulo, column='client_id', sample_id=42):
return dataframe.withColumn('sampler', udf((lambda key: ((crc32((key or '')) & 4294967295) % modulo)))(column)).where(('sampler = %s' % sample_id)).drop('sampler') | Collect a sample of clients given an input column
Filter dataframe based on the modulus of the CRC32 of a given string
column matching a given sample_id. if dataframe has already been filtered
by sample_id, then modulo should be a multiple of 100, column should be
"client_id", and the given sample_id should match the ... | codesearchnet |
def Append(self, value, timestamp):
timestamp = self._NormalizeTime(timestamp)
if (self.data and (timestamp < self.data[(- 1)][1])):
raise RuntimeError('Next timestamp must be larger.')
self.data.append([value, timestamp]) | Adds value at timestamp.
Values must be added in order of increasing timestamp.
Args:
value: An observed value.
timestamp: The timestamp at which value was observed.
Raises:
RuntimeError: If timestamp is smaller than the previous timstamp. | codesearchnet |
def make_job(name: str = '',
run_name: str = '',
num_tasks: int = 0,
install_script: str = '',
**kwargs
) -> backend.Job:
return _backend.make_job(name=name, run_name=run_name, num_tasks=num_tasks,
install_script=install_sc... | Create a job using current backend. Blocks until all tasks are up and initialized.
Args:
name: name of the job
run_name: name of the run (auto-assigned if empty)
num_tasks: number of tasks
install_script: bash-runnable script
**kwargs:
Returns:
backend.Job | juraj-google-style |
def filter_by_conditional_statement(self, statement):
_filt_values, _filt_datetimes = self._filter_by_statement(statement)
collection = HourlyDiscontinuousCollection(
self.header.duplicate(), _filt_values, _filt_datetimes)
collection._validated_a_period = True
return... | Filter the Data Collection based on a conditional statement.
Args:
statement: A conditional statement as a string (e.g. a > 25 and a%5 == 0).
The variable should always be named as 'a' (without quotations).
Return:
A new Data Collection containing only the filtered data | juraj-google-style |
def FindModuleDefiningFlag(self, flagname, default=None):
registered_flag = self.FlagDict().get(flagname)
if registered_flag is None:
return default
for module, flags in six.iteritems(self.FlagsByModuleDict()):
for flag in flags:
if (flag.name == registere... | Return the name of the module defining this flag, or default.
Args:
flagname: Name of the flag to lookup.
default: Value to return if flagname is not defined. Defaults
to None.
Returns:
The name of the module which registered the flag with this name.
If no such module exists (i.e. no flag with this name exists),
we r... | juraj-google-style |
def requestB(self):
work_context = self.getContext()
self.setContext('request[v4B]')
self.m_serial_port.write((('2f3f'.decode('hex') + self.m_meter_address) + '3031210d0a'.decode('hex')))
self.m_raw_read_b = self.m_serial_port.getResponse(self.getContext())
unpacked_read_b = self.unpackStruct(self.m... | Issue a B read on V4 meter.
Returns:
bool: True if CRC match at end of call. | codesearchnet |
def similar_filter_r(self, sentence_list):
result_list = []
recursive_list = []
try:
self.nlp_base.tokenize(sentence_list[0])
subject_token = self.nlp_base.token
result_list.append(sentence_list[0])
if len(sentence_list) > 1:
... | Filter mutually similar sentences.
Args:
sentence_list: The list of sentences.
Returns:
The list of filtered sentences. | juraj-google-style |
def redirect_stdout(new_stdout):
(old_stdout, sys.stdout) = (sys.stdout, new_stdout)
try:
(yield None)
finally:
sys.stdout = old_stdout | Redirect the stdout
Args:
new_stdout (io.StringIO): New stdout to use instead | codesearchnet |
def _ParseStorageMediaImageOptions(self, options):
self._partitions = getattr(options, 'partitions', None)
if self._partitions:
try:
self._ParseVolumeIdentifiersString(self._partitions, prefix='p')
except ValueError:
raise errors.BadConfigOption('Unsupported partitions')
... | Parses the storage media image options.
Args:
options (argparse.Namespace): command line arguments.
Raises:
BadConfigOption: if the options are invalid. | codesearchnet |
def __init__(self, paths=None, separator='/'):
if not paths:
raise errors.FormatError('Missing directory value.')
super(DirectorySourceType, self).__init__()
self.paths = paths
self.separator = separator | Initializes a source type.
Args:
paths (Optional[str]): paths relative to the root of the file system.
separator (Optional[str]): path segment separator.
Raises:
FormatError: when paths is not set. | juraj-google-style |
def start_workflow(name, config, *, queue=DefaultJobQueueName.Workflow, clear_data_store=True, store_args=None):
try:
wf = Workflow.from_name(name, queue=queue, clear_data_store=clear_data_store, arguments=store_args)
except DirectedAcyclicGraphInvalid as e:
raise WorkflowDefinitionError(workflo... | Start a single workflow by sending it to the workflow queue.
Args:
name (str): The name of the workflow that should be started. Refers to the
name of the workflow file without the .py extension.
config (Config): Reference to the configuration object from which the
settings for the workflow are retrieved.
queue (str): ... | codesearchnet |
def format_trigger(self, stream):
src = u'value'
if self.use_count:
src = u'count'
return u"{}({}) {} {}".format(src, stream, self.comp_string, self.reference) | Create a user understandable string like count(stream) >= X.
Args:
stream (DataStream): The stream to use to format ourselves.
Returns:
str: The formatted string | juraj-google-style |
def write_xml(xml_str, output_loc=None, filename=None):
if not xml_str:
raise Dump2PolarionException("No data to write.")
filename_fin = _get_filename(output_loc=output_loc, filename=filename)
with io.open(filename_fin, "w", encoding="utf-8") as xml_file:
xml_file.write(get_unicode_str... | Outputs the XML content (string) into a file.
If `output_loc` is supplied and it's a file (not directory), the output
will be saved there and the `filename` is ignored.
Args:
xml_str: string with XML document
output_loc: file or directory for saving the file
filename: file name that will be used if `output_loc` is di... | juraj-google-style |
def from_tuple(cls, queries):
domain = cls()
join_with = cls.AND
for query in queries:
if (query in [cls.OR, cls.AND]):
join_with = query
else:
domain.add_query(query, join_with)
return domain | Create a ``Domain`` given a set of complex query tuples.
Args:
queries (iter): An iterator of complex queries. Each iteration
should contain either:
* A data-set compatible with :func:`~domain.Domain.add_query`
* A string to switch the join type
Example::
[('subject', 'Test1'),
'OR',
('subject', 'Test2')',
('subjec... | codesearchnet |
def is40(msg):
if allzeros(msg):
return False
d = hex2bin(data(msg))
if wrongstatus(d, 1, 2, 13):
return False
if wrongstatus(d, 14, 15, 26):
return False
if wrongstatus(d, 27, 28, 39):
return False
if wrongstatus(d, 48, 49, 51):
return Fa... | Check if a message is likely to be BDS code 4,0
Args:
msg (String): 28 bytes hexadecimal message string
Returns:
bool: True or False | juraj-google-style |
def _GroupByArguments(self, signatures):
groups = {}
for sig in signatures:
stripped_signature = sig.Replace(return_type=None, exceptions=None)
ret = groups.get(stripped_signature)
if not ret:
ret = _ReturnsAndExceptions()
groups[stripped_signature] = ret
... | Groups signatures by arguments.
Arguments:
signatures: A list of function signatures (Signature instances).
Returns:
A dictionary mapping signatures (without return and exceptions) to
a tuple of return values and exceptions. | github-repos |
def get_length(self, y):
lens = [self.find_pad_index(row) for row in y]
return lens | Get true length of y.
Args:
y (list): padded list.
Returns:
lens: true length of y.
Examples:
>>> y = [[1, 0, 0], [1, 1, 0], [1, 1, 1]]
>>> self.get_length(y)
[1, 2, 3] | codesearchnet |
def get_cpu_vendor(cls, family, arch='x86'):
props = cls.get_cpu_props(family, arch)
vendor = 'generic'
try:
vendor = props.xpath('vendor/@name')[0]
except IndexError:
pass
return vendor | Get CPU vendor, if vendor is not available will return 'generic'
Args:
family(str): CPU family
arch(str): CPU arch
Returns:
str: CPU vendor if found otherwise 'generic' | codesearchnet |
def link_cloud(self, username=None, password=None, device_id=None):
reg = ComponentRegistry()
domain = self.get('cloud:server')
if (username is None):
prompt_str = 'Please enter your IOTile.cloud email: '
username = input(prompt_str)
if (password is None):
prompt_str = 'Please en... | Create and store a token for interacting with the IOTile Cloud API.
You will need to call link_cloud once for each virtualenv that
you create and want to use with any api calls that touch iotile cloud.
Note that this method is called on a ConfigManager instance
If you do not pass your username or password it will be... | codesearchnet |
def get_path(self, key, rel_to_cwd=False, rel_to_conf=False):
if key in self.__cli:
path = self.__cli[key]
from_conf = False
else:
path = self.__config.get(key)
from_conf = True
if not isinstance(path, str):
return None
... | Retrieve a path from the config, resolving it against
the invokation directory or the configuration file directory,
depending on whether it was passed through the command-line
or the configuration file.
Args:
key: str, the key to lookup the path with
Returns:
str: The path, or `None` | juraj-google-style |
def _checkBool(inputvalue, description='inputvalue'):
_checkString(description, minlength=1, description='description string')
if (not isinstance(inputvalue, bool)):
raise TypeError('The {0} must be boolean. Given: {1!r}'.format(description, inputvalue)) | Check that the given inputvalue is a boolean.
Args:
* inputvalue (boolean): The value to be checked.
* description (string): Used in error messages for the checked inputvalue.
Raises:
TypeError, ValueError | codesearchnet |
def request(http, uri, method='GET', body=None, headers=None, redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None):
http_callable = getattr(http, 'request', http)
return http_callable(uri, method=method, body=body, headers=headers, redirections=redirections, connection_type=connection_type) | Make an HTTP request with an HTTP object and arguments.
Args:
http: httplib2.Http, an http object to be used to make requests.
uri: string, The URI to be requested.
method: string, The HTTP method to use for the request. Defaults
to 'GET'.
body: string, The payload / body in HTTP request. By default
there is no payloa... | codesearchnet |
def fill_memory_slot(memory, value, index):
mask = tf.to_float(
tf.one_hot(index,
tf.shape(memory)[0])[:, None, None, None])
fill_memory = (1 - mask) * memory + mask * value[None, ...]
return fill_memory | Fills the memory slot at a particular index with the given value.
Args:
memory: a 4-d tensor [memory_size, batch, length, channel] containing
the state of all steps
value: a 3-d tensor [batch, length, channel] as the sate
index: integer in [0, memory_size)
Returns:
filled memory | juraj-google-style |
def upload_blob(self, did, wid, filepath='./blob.json'):
chars = string.ascii_letters + string.digits
boundary_key = ''.join(random.choice(chars) for i in range(8))
mimetype = mimetypes.guess_type(filepath)[0]
encoded_filename = os.path.basename(filepath)
file_content_... | Uploads a file to a new blob element in the specified doc.
Args:
- did (str): Document ID
- wid (str): Workspace ID
- filepath (str, default='./blob.json'): Blob element location
Returns:
- requests.Response: Onshape response data | juraj-google-style |
def show_abierrors(self, nids=None, stream=sys.stdout):
lines = []
app = lines.append
for task in self.iflat_tasks(status=self.S_ABICRITICAL, nids=nids):
header = "=== " + task.qout_file.path + "==="
app(header)
report = task.get_event_report()
... | Write to the given stream the list of ABINIT errors for all tasks whose status is S_ABICRITICAL.
Args:
nids: optional list of node identifiers used to filter the tasks.
stream: File-like object. Default: sys.stdout | juraj-google-style |
def add_showcase(self, showcase, showcases_to_check=None):
dataset_showcase = self._get_dataset_showcase_dict(showcase)
if showcases_to_check is None:
showcases_to_check = self.get_showcases()
for showcase in showcases_to_check:
if dataset_showcase['show... | Add dataset to showcase
Args:
showcase (Union[Showcase,Dict,str]): Either a showcase id or showcase metadata from a Showcase object or dictionary
showcases_to_check (List[Showcase]): list of showcases against which to check existence of showcase. Defaults to showcases containing dataset.
Returns:
bool: True if the sh... | juraj-google-style |
def _create_filters(col_params, extractors):
result = []
for (col_param, extractor) in zip(col_params, extractors):
a_filter = _create_filter(col_param, extractor)
if a_filter:
result.append(a_filter)
return result | Creates filters for the given col_params.
Args:
col_params: List of ListSessionGroupsRequest.ColParam protobufs.
extractors: list of extractor functions of the same length as col_params.
Each element should extract the column described by the corresponding
element of col_params.
Returns:
A list of filter functions. Ea... | codesearchnet |
def query(self, query):
path = self.path(query.key)
if os.path.exists(path):
filenames = os.listdir(path)
filenames = list(set(filenames) - set(self.ignore_list))
filenames = map(lambda f: os.path.join(path, f), filenames)
iterable = self._read_object_gen(filenames)
else:
... | Returns an iterable of objects matching criteria expressed in `query`
FSDatastore.query queries all the `.obj` files within the directory
specified by the query.key.
Args:
query: Query object describing the objects to return.
Raturns:
Cursor with all objects matching criteria | juraj-google-style |
def receive(host, timeout):
parameters = settings.get_amqp_settings()[host]
queues = parameters["queues"]
queues = dict(map(lambda (x, y): (y, x), queues.items()))
queue = queues[parameters["out_key"]]
channel = _get_channel(host, timeout)
for method_frame, properties, body in channel.c... | Print all messages in queue.
Args:
host (str): Specified --host.
timeout (int): How log should script wait for message. | juraj-google-style |
def follow(self, chars):
chars = chars.lower()
node = self.node
for char in chars:
node = cgaddag.gdg_follow_edge(self.gdg, node, char.encode("ascii"))
if not node:
raise KeyError(char)
return Node(self.gdg, node) | Traverse the GADDAG to the node at the end of the given characters.
Args:
chars: An string of characters to traverse in the GADDAG.
Returns:
The Node which is found by traversing the tree. | juraj-google-style |
def update_state(self, y_true, y_pred, sample_weight=None):
y_true = math_ops.cast(y_true, self._dtype)
y_pred = math_ops.cast(y_pred, self._dtype)
y_pred, y_true = losses_utils.squeeze_or_expand_dimensions(y_pred, y_true)
error_sq = math_ops.squared_difference(y_pred, y_true)
return super(RootMeanS... | Accumulates root mean squared error statistics.
Args:
y_true: The ground truth values.
y_pred: The predicted values.
sample_weight: Optional weighting of each example. Defaults to 1. Can be a
`Tensor` whose rank is either 0, or the same rank as `y_true`, and must
be broadcastable to `y_true`.
Returns:
Update op. | github-repos |
def add_user(
self, user,
first_name=None, last_name=None,
email=None, password=None
):
self.project_service.set_auth(self._token_project)
self.project_service.add_user(
user, first_name, last_name, email, password) | Add a new user.
Args:
user (string): User name.
first_name (optional[string]): User's first name. Defaults to None.
last_name (optional[string]): User's last name. Defaults to None.
email: (optional[string]): User's email address. Defaults to None.
password: (optional[string]): User's password. Defaults to None.
... | juraj-google-style |
def get_compound_bodies(node):
if isinstance(node, (ast.Module, ast.FunctionDef, ast.ClassDef, ast.With)):
return [node.body]
elif isinstance(node, (ast.If, ast.While, ast.For)):
return [node.body, node.orelse]
elif PY2 and isinstance(node, ast.TryFinally):
return [node.body, no... | Returns a list of bodies of a compound statement node.
Args:
node: AST node.
Returns:
A list of bodies of the node. If the given node does not represent
a compound statement, an empty list is returned. | juraj-google-style |
def disk(radius, alias_blur=0.1, dtype=np.float32):
if radius <= 8:
length = np.arange(-8, 8 + 1)
ksize = (3, 3)
else:
length = np.arange(-radius, radius + 1)
ksize = (5, 5)
x_axis, y_axis = np.meshgrid(length, length)
aliased_disk = np.array((x_axis**2 + y_axis**2) <= radius**2, dtype=dtype)... | Generating a Gaussian blurring kernel with disk shape.
Generating a Gaussian blurring kernel with disk shape using cv2 API.
Args:
radius: integer, radius of blurring kernel.
alias_blur: float, standard deviation of Gaussian blurring.
dtype: data type of kernel
Returns:
cv2 object of the Gaussian blurring kernel. | juraj-google-style |
def AllBalancesZeroOrLess(self):
for (key, fixed8) in self.Balances.items():
if (fixed8.value > 0):
return False
return True | Flag indicating if all balances are 0 or less.
Returns:
bool: True if all balances are <= 0. False, otherwise. | codesearchnet |
def merge_vert(script, threshold=0.0):
filter_xml = ''.join([' <filter name="Merge Close Vertices">\n', ' <Param name="Threshold" ', 'value="{}" '.format(threshold), 'description="Merging distance" ', 'min="0" ', 'max="1" ', 'type="RichAbsPerc" ', '/>\n', ' </filter>\n'])
util.write_filter(script, filter_x... | Merge together all the vertices that are nearer than the specified
threshold. Like a unify duplicate vertices but with some tolerance.
Args:
script: the FilterScript object or script filename to write
the filter to.
threshold (float): Merging distance. All the vertices that are closer
than this threshold are merged to... | codesearchnet |
def add_forwarding_rules(self, forwarding_rules):
rules_dict = [rule.__dict__ for rule in forwarding_rules]
return self.get_data(
"load_balancers/%s/forwarding_rules/" % self.id,
type=POST,
params={"forwarding_rules": rules_dict}
) | Adds new forwarding rules to a LoadBalancer.
Args:
forwarding_rules (obj:`list`): A list of `ForwrdingRules` objects | juraj-google-style |
def send_message_for_lane_change(sender, **kwargs):
current = kwargs['current']
owners = kwargs['possible_owners']
if 'lane_change_invite' in current.task_data:
msg_context = current.task_data.pop('lane_change_invite')
else:
msg_context = DEFAULT_LANE_CHANGE_INVITE_MSG
wfi = WF... | Sends a message to possible owners of the current workflows
next lane.
Args:
**kwargs: ``current`` and ``possible_owners`` are required.
sender (User): User object | juraj-google-style |
def get_backend_engine(self, name, **kwargs):
if (name not in self._engines):
msg = 'Given settings backend is unknowed: {}'
raise SettingsBackendError(msg.format(name))
return self._engines[name](**kwargs) | Get backend engine from given name.
Args:
(string): Path to validate.
Raises:
boussole.exceptions.SettingsBackendError: If given backend name
does not match any available engine.
Returns:
object: Instance of selected backend engine. | codesearchnet |
def reset(self):
self.number_of_hops = 0
self.dr = np.array([0.0, 0.0, 0.0])
self.summed_dr2 = 0.0
self.sites_visited = [self._site.number] | Reinitialise the stored displacements, number of hops, and list of sites visited for this `Atom`.
Args:
None
Returns:
None | codesearchnet |
def set_notifier_path(self, notifier, path):
assert self.notifier is Model.notifier or notifier is Model.notifier, \
"Already have a notifier %s path %s" % (self.notifier, self.path)
self.notifier = notifier
self.path = path
for na... | Sets the notifier, and the path from the path from block root
Args:
notifier (Notifier): The Notifier to tell when endpoint data changes
path (list): The absolute path to get to this object | juraj-google-style |
def _log_to_stderr(self, record):
old_stream = self.stream
self.stream = sys.stderr
try:
super(PythonHandler, self).emit(record)
finally:
self.stream = old_stream | Emits the record to stderr.
This temporarily sets the handler stream to stderr, calls
StreamHandler.emit, then reverts the stream back.
Args:
record: logging.LogRecord, the record to log. | codesearchnet |
def plot_spectra_pages_pdf(ss, pdf_filename='pages.pdf', setup=_default_setup):
logger = a99.get_python_logger()
(xmin, xmax, ymin_, ymax, xspan, yspan) = calc_max_min(ss)
ymin = (ymin_ if (setup.ymin is None) else setup.ymin)
num_pages = len(ss)
a99.format_BLB()
pdf = matplotlib.backends.backen... | Plots spectra into a PDF file, one spectrum per page.
Splits into several pieces of width
Args:
ss: list of Spectrum objects
pdf_filename: name of output file | codesearchnet |
def combine_results(results):
total, inside = (sum((r[0] for r in results)), sum((r[1] for r in results)))
return (total, inside, 4 * float(inside) / total) | Combiner function to sum up trials and compute the estimate.
Args:
results: An iterable of 3-tuples (total trials, inside trials, ignored).
Returns:
A 3-tuple containing the sum of total trials, sum of inside trials, and
the probability computed from the two numbers. | github-repos |
def get(cls):
results = {}
hierarchy = cls.__hierarchy
hierarchy.reverse()
for storeMethod in hierarchy:
cls.merger.merge(results, storeMethod.get())
return results | Get values gathered from the previously set hierarchy.
Respects the order in which sources are set, the first source set
has the highest priority, overrides values with the same key that
exist in sources with lower priority.
Returns:
dict: The dictionary containing values gathered from all set sources. | codesearchnet |
def rep1(parser: Union[(Parser, Sequence[Input])]) -> RepeatedOnceParser:
if isinstance(parser, str):
parser = lit(parser)
return RepeatedOnceParser(parser) | Match a parser one or more times repeatedly.
This matches ``parser`` multiple times in a row. If it matches as least
once, it returns a list of values from each time ``parser`` matched. If it
does not match ``parser`` at all, it fails.
Args:
parser: Parser or literal | codesearchnet |
def coord_list_mapping_pbc(subset, superset, atol=1e-08):
atol = (np.array([1.0, 1.0, 1.0]) * atol)
return cuc.coord_list_mapping_pbc(subset, superset, atol) | Gives the index mapping from a subset to a superset.
Superset cannot contain duplicate matching rows
Args:
subset, superset: List of frac_coords
Returns:
list of indices such that superset[indices] = subset | codesearchnet |
def _send_group_coordinator_request(self):
node_id = self._client.least_loaded_node()
if (node_id is None):
return Future().failure(Errors.NoBrokersAvailable())
elif (not self._client.ready(node_id, metadata_priority=False)):
e = Errors.NodeNotReadyError(node_id)
return Future().fail... | Discover the current coordinator for the group.
Returns:
Future: resolves to the node id of the coordinator | codesearchnet |
def ParseOptions(cls, options, configuration_object):
if not isinstance(configuration_object, tools.CLITool):
raise errors.BadConfigObject(
'Configuration object is not an instance of CLITool')
status_view_mode = cls._ParseStringOption(
options, 'status_view_mode',
default_... | Parses and validates options.
Args:
options (argparse.Namespace): parser options.
configuration_object (CLITool): object to be configured by the argument
helper.
Raises:
BadConfigObject: when the configuration object is of the wrong type. | juraj-google-style |
def mirror(self):
reverse_circ = self.copy(name=(self.name + '_mirror'))
reverse_circ.data = []
for (inst, qargs, cargs) in reversed(self.data):
reverse_circ.data.append((inst.mirror(), qargs, cargs))
return reverse_circ | Mirror the circuit by reversing the instructions.
This is done by recursively mirroring all instructions.
It does not invert any gate.
Returns:
QuantumCircuit: the mirrored circuit | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.