code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def from_fn(cls, dna_spec: DNASpec, generator_fn: Callable[['DecisionPoint'], Union[List[int], float, str, 'DNA']]) -> 'DNA':
if not isinstance(dna_spec, DNASpec):
raise TypeError(f"Argument 'dna_spec' should be DNASpec type. Encountered {dna_spec}.")
if dna_spec.is_space:
children = []
... | Generate a DNA with user generator function.
Args:
dna_spec: The DNASpec for the DNA.
generator_fn: A callable object with signature:
`(decision_point) -> decision`
The decision_point is a `Choices` object or a `Float` object.
The returned decision should be:
* a list of integer or a DNA object for a `Choices` deci... | github-repos |
def generate_hyperband_schedule(self, R, eta):
schedule = []
s_max = int(math.floor(math.log(R, eta)))
for s in range(0, (s_max + 1)):
n = math.ceil((int(((s_max + 1) / (s + 1))) * (eta ** s)))
r = (R * (eta ** (- s)))
bracket = []
for i in range(0, (s + 1)):
n_i ... | Generate hyperband schedule according to the paper.
Args:
R: maximum resources per config.
eta: proportion of configruations to discard per
iteration of successive halving.
Returns: hyperband schedule, which is represented
as a list of brackets, where each bracket
contains a list of (num configurations,
num resources... | codesearchnet |
def generate_payload(self, command, data=None):
json_data = payload_dict[self.dev_type][command]['command']
if ('gwId' in json_data):
json_data['gwId'] = self.id
if ('devId' in json_data):
json_data['devId'] = self.id
if ('uid' in json_data):
json_data['uid'] = self.id
if ('t... | Generate the payload to send.
Args:
command(str): The type of command.
This is one of the entries from payload_dict
data(dict, optional): The data to be send.
This is what will be passed via the 'dps' entry | codesearchnet |
def __call__(self, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]], text_pair: Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]]=None, boxes: Optional[Union[List[List[int]], List[List[List[int]]]]]=None, word_labels: Optional[Union[List[int], List[List[int]]]]=None, add_spe... | Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
sequences with word-level normalized bounding boxes and optional labels.
Args:
text (`str`, `List[str]`, `List[List[str]]`):
The sequence or batch of sequences to be encoded. Each sequence can be a string, a list ... | github-repos |
def _get_bounds(self, layers):
extent_query = ('SELECT ST_EXTENT(the_geom) AS the_geom '
'FROM ({query}) AS t{idx}\n')
union_query = 'UNION ALL\n'.join(
[extent_query.format(query=layer.orig_query, idx=idx)
for idx, layer in enumerate(layers)
... | Return the bounds of all data layers involved in a cartoframes map.
Args:
layers (list): List of cartoframes layers. See `cartoframes.layers`
for all types.
Returns:
dict: Dictionary of northern, southern, eastern, and western bounds
of the superset of data layers. Keys are `north`, `south`,
`east`, and `west`. Units... | juraj-google-style |
def _check_registry_type(folder=None):
folder = _registry_folder(folder)
default_file = os.path.join(folder, 'registry_type.txt')
try:
with open(default_file, 'r') as infile:
data = infile.read()
data = data.strip()
ComponentRegistry.SetBackingStore(data)
exce... | Check if the user has placed a registry_type.txt file to choose the registry type
If a default registry type file is found, the DefaultBackingType and DefaultBackingFile
class parameters in ComponentRegistry are updated accordingly.
Args:
folder (string): The folder that we should check for a default registry type | codesearchnet |
def output_hist(self, output_hist: Hist, input_observable: Any, **kwargs: Dict[(str, Any)]) -> Union[(Hist, Any)]:
return output_hist | Return an output object. It should store the ``output_hist``.
Note:
The output object could just be the raw histogram.
Note:
This function is just a basic placeholder which returns the given output object (a histogram)
and likely should be overridden.
Args:
output_hist: The output histogram
input_observable (object)... | codesearchnet |
def HasDataStream(self, name, case_sensitive=True):
if not isinstance(name, py2to3.STRING_TYPES):
raise ValueError('Name is not a string.')
name_lower = name.lower()
for data_stream in self._GetDataStreams():
if data_stream.name == name:
return True
if not case_sensitive an... | Determines if the file entry has specific data stream.
Args:
name (str): name of the data stream.
case_sensitive (Optional[bool]): True if the name is case sensitive.
Returns:
bool: True if the file entry has the data stream.
Raises:
ValueError: if the name is not string. | juraj-google-style |
def generate_custom_cert_name(env='', region='', account='', certificate=None):
cert_name = None
template_kwargs = {'account': account, 'name': certificate}
try:
rendered_template = get_template(template_file='infrastructure/iam/tlscert_naming.json.j2', **template_kwargs)
tlscert_dict = json... | Generate a custom TLS Cert name based on a template.
Args:
env (str): Account environment name
region (str): AWS Region.
account (str): Account number for ARN.
certificate (str): Name of SSL certificate.
Returns:
str: Fully qualified ARN for SSL certificate.
None: Template doesn't exist. | codesearchnet |
def _post_process(self, feed_item, item):
campaign = self._campaign_dao.get(feed_item, required=True)
if campaign:
feed_item[FieldMap.CAMPAIGN_NAME] = campaign['name']
feed_item[FieldMap.CAMPAIGN_ID] = campaign['id'] | Updates the feed item with ids and names of related object so those can be updated in the Bulkdozer feed.
Args:
feed_item: The Bulkdozer feed item.
item: The CM newly created or updated object. | github-repos |
def _ConvertValueForCsv(self, pql_value):
if 'value' in pql_value:
field = pql_value['value']
elif 'values' in pql_value:
field = pql_value['values']
else:
field = None
if field:
if isinstance(field, list):
if all(AdManagerClassType(single_field) == AdManagerClassTy... | Sanitizes a field value from a Value object to a CSV suitable format.
Args:
pql_value: dict a dictionary containing the data for a single field of an
entity.
Returns:
str a CSV writer friendly value formatted by Value.Type. | juraj-google-style |
def create_resource_group(access_token, subscription_id, rgname, location):
endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', rgname, '?api-version=', RESOURCE_API])
rg_body = {'location': location}
body = json.dumps(rg_body)
return do_put(endpoint, body, acc... | Create a resource group in the specified location.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
rgname (str): Azure resource group name.
location (str): Azure data center location. E.g. westus.
Returns:
HTTP response. JSON body. | codesearchnet |
def request_parking(self, endpoint, url_args={}, **kwargs):
if (endpoint not in ENDPOINTS_PARKING):
return None
url = (URL_OPENBUS + ENDPOINTS_PARKING[endpoint])
lang = url_args.get('lang', 'ES')
address = url_args.get('address', '')
url = url.format(id_client=self._emt_id, passkey=self._emt... | Make a request to the given endpoint of the ``parking`` server.
This returns the plain JSON (dict) response which can then be parsed
using one of the implemented types.
Args:
endpoint (str): Endpoint to send the request to.
This string corresponds to the key in the ``ENDPOINTS`` dict.
url_args (dict): Dictionary for ... | codesearchnet |
def extract_tensors_from_dataset(dataset):
iterator = get_iterator(dataset)
inputs, targets, sample_weight = unpack_iterator_input(iterator)
return (inputs, targets, sample_weight) | Extract a tuple of tensors `inputs, targets, sample_weight` from a dataset.
Args:
dataset: Dataset instance.
Returns:
Tuple of tensors `x, y, weights`. `y` and `weights` entry may be None. | github-repos |
def linear(self, x):
with tf.name_scope('presoftmax_linear'):
batch_size = tf.shape(x)[0]
length = tf.shape(x)[1]
x = tf.reshape(x, [(- 1), self.hidden_size])
logits = tf.matmul(x, self.shared_weights, transpose_b=True)
return tf.reshape(logits, [batch_size, length, self.voca... | Computes logits by running x through a linear layer.
Args:
x: A float32 tensor with shape [batch_size, length, hidden_size]
Returns:
float32 tensor with shape [batch_size, length, vocab_size]. | codesearchnet |
def read(self, size=None):
data = b''
while ((size and len(data) < size) and
self._current_offset < self.uncompressed_data_size):
member = self._GetMemberForOffset(self._current_offset)
member_offset = self._current_offset - member.uncompressed_data_offset
data_read = member.Re... | Reads a byte string from the gzip file at the current offset.
The function will read a byte string up to the specified size or
all of the remaining data if no size was specified.
Args:
size (Optional[int]): number of bytes to read, where None is all
remaining data.
Returns:
bytes: data read.
Raises:
IOError: if the... | juraj-google-style |
def double(self, count: float) -> float:
return 2 * count | Returns the input multiplied by 2.
Args:
count: Input number that you want to double.
Returns:
A number that is the double of count. | github-repos |
def stylify(code: str) -> str:
has_indent = len(get_indent(code)) > 0
if has_indent:
code = f'class Bla:\n{code}'
formatted_code = run_ruff(code)
return formatted_code[len('class Bla:\n'):] if has_indent else formatted_code | Applies the ruff part of our `make style` command to some code. This formats the code using `ruff format`.
As `ruff` does not provide a python api this cannot be done on the fly.
Args:
code (`str`): The code to format.
Returns:
`str`: The formatted code. | github-repos |
def check_integrity(models):
messages = dict(error=[], warning=[])
for model in models:
validators = []
for name in dir(model):
if (not name.startswith('_check')):
continue
obj = getattr(model, name)
if getattr(obj, 'validator_type', None):
... | Apply validation and integrity checks to a collection of Bokeh models.
Args:
models (seq[Model]) : a collection of Models to test
Returns:
None
This function will emit log warning and error messages for all error or
warning conditions that are detected. For example, layouts without any
children will trigger a warnin... | codesearchnet |
def list_documents(project_id, knowledge_base_id):
import dialogflow_v2beta1 as dialogflow
client = dialogflow.DocumentsClient()
knowledge_base_path = client.knowledge_base_path(project_id,
knowledge_base_id)
print('Documents for Knowledge Id: {... | Lists the Documents belonging to a Knowledge base.
Args:
project_id: The GCP project linked with the agent.
knowledge_base_id: Id of the Knowledge base. | juraj-google-style |
def write_temp_bird_conf(dummy_ip_prefix,
config_file,
variable_name,
prefixes):
log = logging.getLogger(PROGRAM_NAME)
comment = ("
"REMOVED from the constant.".format(i=dummy_ip_prefix))
tm_file =... | Write in a temporary file the list of IP-Prefixes.
A failure to create and write the temporary file will exit main program.
Arguments:
dummy_ip_prefix (str): The dummy IP prefix, which must be always
config_file (str): The file name of bird configuration
variable_name (str): The name of the variable set in bird confi... | juraj-google-style |
def _WriteRow(self, output_writer, values):
maximum_row_width = self._MAXIMUM_WIDTH - self._column_width - 3
primary_format_string = '{{0:>{0:d}s}} : {{1:s}}\n'.format(
self._column_width)
secondary_format_string = '{{0:<{0:d}s}}{{1:s}}\n'.format(
self._column_width + 3)
... | Writes a row of values aligned to the column width.
Args:
output_writer (OutputWriter): output writer.
values (list[object]): values. | juraj-google-style |
def _AddProvidesEdges(self, rdf_artifact):
for attribute in rdf_artifact.provides:
self._AddEdge(rdf_artifact.name, attribute) | Add an edge for every attribute the given artifact provides.
This method adds a directed edge from the artifact node to every attribute
this artifact provides.
Args:
rdf_artifact: The artifact object. | juraj-google-style |
def __init__(self,
no_decomp: Callable[[ops.Operation], bool]=(lambda _: False)
) -> None:
super().__init__()
self.no_decomp = no_decomp | Construct the optimization pass.
Args:
no_decomp: A predicate that determines whether an operation should
be decomposed or not. Defaults to decomposing everything. | juraj-google-style |
def calc_digest(origin, algorithm='sha1', block_size=None):
try:
hashM = hashlib.new(algorithm)
except ValueError:
raise ValueError('hash algorithm not supported by the underlying platform: "{0}"'.format(algorithm))
while True:
chunk = (origin.read(block_size) if block_size else orig... | Calculate digest of a readable object
Args:
origin -- a readable object for which calculate digest
algorithn -- the algorithm to use. See ``hashlib.algorithms_available`` for supported algorithms.
block_size -- the size of the block to read at each iteration | codesearchnet |
def merge(self, ref_name: str):
if self.is_dirty():
LOGGER.error('repository is dirty; cannot merge: %s', ref_name)
sys.exit(-1)
LOGGER.info('merging ref: "%s" into branch: %s', ref_name, self.get_current_branch())
self.repo.git.merge(ref_name) | Merges two refs
Args:
ref_name: ref to merge in the current one | juraj-google-style |
async def dist(self, mesg):
if self.isfini:
return ()
ret = []
for func in self._syn_funcs.get(mesg[0], ()):
try:
ret.append((await s_coro.ornot(func, mesg)))
except asyncio.CancelledError:
raise
except Exception:
logger.exception('base %s ... | Distribute an existing event tuple.
Args:
mesg ((str,dict)): An event tuple.
Example:
await base.dist( ('foo',{'bar':'baz'}) ) | codesearchnet |
def check_initializers(initializers, keys):
if (initializers is None):
return {}
_assert_is_dictlike(initializers, valid_keys=keys)
keys = set(keys)
if (not (set(initializers) <= keys)):
extra_keys = (set(initializers) - keys)
raise KeyError('Invalid initializer keys {}, initiali... | Checks the given initializers.
This checks that `initializers` is a dictionary that only contains keys in
`keys`, and furthermore the entries in `initializers` are functions or
further dictionaries (the latter used, for example, in passing initializers
to modules inside modules) that must satisfy the same constraints.... | codesearchnet |
def is_file_on_local_server(self, text) -> Tuple[(Optional[Path], Optional[int], Optional[int])]:
lineno = None
colno = None
py_func = None
m = re.compile('(.*)\\:(\\d+)\\:(\\d+)$').match(text)
if m:
text = m.group(1)
lineno = m.group(2)
colno = m.group(3)
else:
m... | Test if the provided text matches a file on local server
Supports:
- absolute path
- relative path (using current working directory)
- file:line syntax
- file:line:colum syntax
Args:
text (str): candidate for file search
Returns
- Tuple(None, None, None) if the provided text does not match anything
- Tuple(file path... | codesearchnet |
class PoolFormerFastImageProcessorKwargs(DefaultFastImageProcessorKwargs):
crop_pct: Optional[float] | Args:
crop_pct (`float`, *optional*, defaults to `self.crop_pct`):
Percentage of the image to crop. Only has an effect if `do_resize` is set to `True`. | github-repos |
def run_node(self, node, stim):
if isinstance(node, string_types):
node = self.nodes[node]
result = node.transformer.transform(stim)
if node.is_leaf():
return listify(result)
stim = result
if ((len(node.children) > 1) and isgenerator(stim)):
stim = list(stim)
return list(... | Executes the Transformer at a specific node.
Args:
node (str, Node): If a string, the name of the Node in the current
Graph. Otherwise the Node instance to execute.
stim (str, stim, list): Any valid input to the Transformer stored
at the target node. | codesearchnet |
def load(self, cellpy_file, parent_level='CellpyData'):
try:
self.logger.debug('loading cellpy-file (hdf5):')
self.logger.debug(cellpy_file)
new_datasets = self._load_hdf5(cellpy_file, parent_level)
self.logger.debug('cellpy-file loaded')
except AttributeError:
new_datase... | Loads a cellpy file.
Args:
cellpy_file (path, str): Full path to the cellpy file.
parent_level (str, optional): Parent level | codesearchnet |
def from_str(cls, input_string, fmt, primitive=False, sort=False, merge_tol=0.0):
from pymatgen.io.cif import CifParser
from pymatgen.io.vasp import Poscar
from pymatgen.io.cssr import Cssr
from pymatgen.io.xcrysden import XSF
from pymatgen.io.atat import Mcsqs
fmt = fmt.lower()
if (fmt == '... | Reads a structure from a string.
Args:
input_string (str): String to parse.
fmt (str): A format specification.
primitive (bool): Whether to find a primitive cell. Defaults to
False.
sort (bool): Whether to sort the sites in accordance to the default
ordering criteria, i.e., electronegativity.
merge_tol (float): If thi... | codesearchnet |
def recalculate_concepts(self, concepts, lang=None):
if len(concepts) == 0:
return
if lang is None:
items = Concept.objects.get_concept_item_mapping(concepts=Concept.objects.filter(pk__in=set(flatten(concepts.values()))))
else:
items = Concept.object... | Recalculated given concepts for given users
Args:
concepts (dict): user id (int -> set of concepts to recalculate)
lang(Optional[str]): language used to get items in all concepts (cached).
Defaults to None, in that case are get items only in used concepts | juraj-google-style |
def get_note_list(self, data=True, since=None, tags=[]):
status = 0
ret = []
response_notes = {}
notes = {'index': []}
params = ('/index?limit=%s' % str(NOTE_FETCH_LENGTH))
if (since is not None):
params += ('&since=%s' % since)
if data:
params += '&data=true'
request = R... | Method to get the note list
The method can be passed optional arguments to limit the list to
notes containing a certain tag, or only updated since a certain
Simperium cursor. If omitted a list of all notes is returned.
By default data objects are returned. If data is set to false only
keys/ids and versions are return... | codesearchnet |
def parse_frequencies(variant, transcripts):
frequencies = {}
thousand_genomes_keys = ['1000GAF']
thousand_genomes_max_keys = ['1000G_MAX_AF']
exac_keys = ['EXACAF']
exac_max_keys = ['ExAC_MAX_AF', 'EXAC_MAX_AF']
gnomad_keys = ['GNOMADAF', 'GNOMAD_AF']
gnomad_max_keys = ['GNOMADA... | Add the frequencies to a variant
Frequencies are parsed either directly from keys in info fieds or from the
transcripts is they are annotated there.
Args:
variant(cyvcf2.Variant): A parsed vcf variant
transcripts(iterable(dict)): Parsed transcripts
Returns:
frequencies(dict): A dictionary with the relevant frequenci... | juraj-google-style |
def _ParseRecord(
self, parser_mediator, record_index, evt_record, recovered=False):
event_data = self._GetEventData(
parser_mediator, record_index, evt_record, recovered=recovered)
try:
creation_time = evt_record.get_creation_time_as_integer()
except OverflowError as exception:
... | Parses a Windows EventLog (EVT) record.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
record_index (int): event record index.
evt_record (pyevt.record): event record.
recovered (Optional[bool]): True if the record was recovered. | juraj-google-style |
def add_body_part(self, key, data, mime_type, size=None):
if isinstance(data, str):
size = len(data)
if hasattr(data, 'fileno'):
size = os.fstat(data.fileno())[stat.ST_SIZE]
if (size is None):
raise UnknownSize('Each part of the body must have a known size.')
if ('Content-Length'... | Adds data to the HTTP request body.
If more than one part is added, this is assumed to be a mime-multipart
request. This method is designed to create MIME 1.0 requests as specified
in RFC 1341.
Args:
data: str or a file-like object containing a part of the request body.
mime_type: str The MIME type describing the dat... | codesearchnet |
def from_string(contents):
lines = contents.split("\n")
num_sites = int(lines[0])
coords = []
sp = []
prop = []
coord_patt = re.compile(
r"(\w+)\s+([0-9\-\.]+)\s+([0-9\-\.]+)\s+([0-9\-\.]+)\s+" +
r"([0-9\-\.]+)"
)
for i in ... | Creates Zeo++ Voronoi XYZ object from a string.
from_string method of XYZ class is being redefined.
Args:
contents: String representing Zeo++ Voronoi XYZ file.
Returns:
ZeoVoronoiXYZ object | juraj-google-style |
def _remove_boring_lines(text):
lines = text.split('\n')
filtered = [line for line in lines if re.match('[a-zA-z"\']', line)]
return '\n'.join(filtered) | Remove lines that do not start with a letter or a quote.
From inspecting the data, this seems to leave in most prose and remove
most weird stuff.
Args:
text: a string
Returns:
a string | codesearchnet |
def create_deferred(self, func, input_layer, deferred_args, deferred_kwargs, name):
my_defaults = _defaults
def _with_method_complete(*args, **kwargs):
input_layer = args[0]
with input_layer.g.as_default(), defaults_scope(**my_defaults), tf.name_scope(name):
return input_layer._meth... | Creates a deferred node with captured scope.
Args:
func: The original function to call.
input_layer: The input_layer.
deferred_args: The arguments that will be used bythe deferred function.
deferred_kwargs: The keyword args for the deferred function.
name: The name of this layer.
Returns:
A _DeferredLayer that will ex... | codesearchnet |
def set_datastore_policy(self, func):
if (func is None):
func = self.default_datastore_policy
elif isinstance(func, bool):
func = (lambda unused_key, flag=func: flag)
self._datastore_policy = func | Set the context datastore policy function.
Args:
func: A function that accepts a Key instance as argument and returns
a bool indicating if it should use the datastore. May be None. | codesearchnet |
def qualNorm(data, qualitative):
genes, cells = data.shape
clusters = qualitative.shape[1]
output = np.zeros((genes, clusters))
missing_indices = []
qual_indices = []
thresholds = qualitative.min(1) + (qualitative.max(1) - qualitative.min(1))/2.0
for i in range(genes):
if qualit... | Generates starting points using binarized data. If qualitative data is missing for a given gene, all of its entries should be -1 in the qualitative matrix.
Args:
data (array): 2d array of genes x cells
qualitative (array): 2d array of numerical data - genes x clusters
Returns:
Array of starting positions for state es... | juraj-google-style |
def external_ids(self, **kwargs):
path = self._get_series_id_season_number_path('external_ids')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Get the external ids that we have stored for a TV season by season
number.
Args:
language: (optional) ISO 639 code.
Returns:
A dict respresentation of the JSON returned from the API. | juraj-google-style |
def bind_to_storage_buffer(self, binding=0, *, offset=0, size=-1) -> None:
self.mglo.bind_to_storage_buffer(binding, offset, size) | Bind the buffer to a shader storage buffer.
Args:
binding (int): The shader storage binding.
Keyword Args:
offset (int): The offset.
size (int): The size. Value ``-1`` means all. | juraj-google-style |
def _replace_variable_with_pattern(match):
positional = match.group("positional")
name = match.group("name")
template = match.group("template")
if name is not None:
if not template:
return _SINGLE_SEGMENT_PATTERN.format(name)
elif template == "**":
return _MU... | Replace a variable match with a pattern that can be used to validate it.
Args:
match (re.Match): A regular expression match
Returns:
str: A regular expression pattern that can be used to validate the
variable in an expanded path.
Raises:
ValueError: If an unexpected template expression is encountered. | juraj-google-style |
def count_params(x):
return np.prod(x.shape.as_list()) | Returns the static number of elements in a variable or tensor.
Args:
x: Variable or tensor.
Returns:
Integer, the number of scalars in `x`.
Example:
>>> kvar = tf.keras.backend.zeros((2,3))
>>> tf.keras.backend.count_params(kvar)
6
>>> tf.keras.backend.eval(kvar)
array([[0., 0., 0.],
[0., 0., 0.]], dtype=float3... | github-repos |
def from_bigquery(sql):
if isinstance(sql, bq.Query):
sql = sql._expanded_sql()
parts = sql.split('.')
if ((len(parts) == 1) or (len(parts) > 3) or any(((' ' in x) for x in parts))):
sql = (('(' + sql) + ')')
else:
sql = (('`' + sql) + '`')
metrics = Metrics(bigquery=sql)
... | Create a Metrics instance from a bigquery query or table.
Returns:
a Metrics instance.
Args:
sql: A BigQuery table name or a query. | codesearchnet |
def disassemble(self, start=None, end=None, arch_mode=None):
if (arch_mode is None):
arch_mode = self.binary.architecture_mode
curr_addr = (start if start else self.binary.ea_start)
end_addr = (end if end else self.binary.ea_end)
while (curr_addr < end_addr):
encoding = self.__fetch_inst... | Disassemble native instructions.
Args:
start (int): Start address.
end (int): End address.
arch_mode (int): Architecture mode.
Returns:
(int, Instruction, int): A tuple of the form (address, assembler instruction, instruction size). | codesearchnet |
def rec_new(self, val):
if (val not in self.things):
for child in val.children():
self.rec_new(child)
self.new(val)
return val | Recursively add a new value and its children to me.
Args:
val (LispVal): The value to be added.
Returns:
LispVal: The added value. | codesearchnet |
def set_name(self, name, anyway=False):
set_name(self.startEA, name, anyway=anyway) | Set Function Name.
Default behavior throws an exception when setting to a name that already exists in
the IDB. to make IDA automatically add a counter to the name (like in the GUI,)
use `anyway=True`.
Args:
name: Desired name.
anyway: `True` to set anyway. | juraj-google-style |
def get_timing_signal(length,
min_timescale=1,
max_timescale=1e4,
num_timescales=16):
positions = to_float(tf.range(length))
log_timescale_increment = (
math.log(max_timescale / min_timescale) / (num_timescales - 1))
inv_timescales = min_t... | Create Tensor of sinusoids of different frequencies.
Args:
length: Length of the Tensor to create, i.e. Number of steps.
min_timescale: a float
max_timescale: a float
num_timescales: an int
Returns:
Tensor of shape (length, 2*num_timescales) | juraj-google-style |
def dump(node, ast, annotate_fields=True, include_attributes=True, indent=' '):
def _format(node, level=0):
if isinstance(node, ast.AST):
fields = [(a, _format(b, level)) for a, b in ast.iter_fields(node)]
if include_attributes and node._attributes:
fields.... | Return a formatted dump of the tree in *node*.
This is mainly useful for debugging purposes. The returned string will show
the names and the values for fields. This makes the code impossible to
evaluate, so if evaluation is wanted *annotate_fields* must be set to False.
Attributes such as line numbers and column off... | github-repos |
def get(self, url, params=None, **kwargs):
return self.call_api('GET', url, params=params, **kwargs) | Call the API with a GET request.
Args:
url (str): Resource location relative to the base URL.
params (dict or None): Query-string parameters.
Returns:
ResultParser or ErrorParser. | codesearchnet |
def from_options(cls, options):
if cls != Environment:
raise NotImplementedError
portable_options = options.view_as(PortableOptions)
environment_type = portable_options.environment_type
if not environment_type:
environment_urn = common_urns.environments.DOCKER.urn
elif environment_ty... | Creates an Environment object from PortableOptions.
Args:
options: The PortableOptions object. | github-repos |
def implement(self, implementation, for_type=None, for_types=None):
unbound_implementation = self.__get_unbound_function(implementation)
for_types = self.__get_types(for_type, for_types)
for t in for_types:
self._write_lock.acquire()
try:
self.implementations.append((t, unbound_i... | Registers an implementing function for for_type.
Arguments:
implementation: Callable implementation for this type.
for_type: The type this implementation applies to.
for_types: Same as for_type, but takes a tuple of types.
for_type and for_types cannot both be passed (for obvious reasons.)
Raises:
ValueError | codesearchnet |
def _ParseApplicationPasswordRecord(self, parser_mediator, record):
key = record.get('_key_', None)
if not key or not key.startswith(b'ssgp'):
raise errors.ParseError((
'Unsupported application password record key value does not start '
'with: "ssgp".'))
event_data = Keychain... | Extracts the information from an application password record.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
record (dict[str, object]): database record.
Raises:
ParseError: if Internet password record cannot be parsed. | juraj-google-style |
def quaternion_from_axis_rotation(angle, axis):
out = np.zeros(4, dtype=float)
if axis == 'x':
out[1] = 1
elif axis == 'y':
out[2] = 1
elif axis == 'z':
out[3] = 1
else:
raise ValueError('Invalid axis input.')
out *= math.sin(angle/2.0)
out[0] = math.cos(... | Return quaternion for rotation about given axis.
Args:
angle (float): Angle in radians.
axis (str): Axis for rotation
Returns:
Quaternion: Quaternion for axis rotation.
Raises:
ValueError: Invalid input axis. | juraj-google-style |
def cancel(self, workflow_id):
self.logger.debug(('Canceling workflow: ' + workflow_id))
url = ('%(wf_url)s/%(wf_id)s/cancel' % {'wf_url': self.workflows_url, 'wf_id': workflow_id})
r = self.gbdx_connection.post(url, data='')
r.raise_for_status() | Cancels a running workflow.
Args:
workflow_id (str): Workflow id.
Returns:
Nothing | codesearchnet |
def parse_rdf_payload(self, data, headers):
if headers['Content-Type'].startswith('text/plain'):
logger.debug('text/plain Content-Type detected, using application/n-triples for parser')
parse_format = 'application/n-triples'
else:
parse_format = headers['Content-Type']
if (';charset'... | small function to parse RDF payloads from various repository endpoints
Args:
data (response.data): data from requests response
headers (response.headers): headers from requests response
Returns:
(rdflib.Graph): parsed graph | codesearchnet |
def build_plans(self):
if (not self.__build_plans):
self.__build_plans = BuildPlans(self.__connection)
return self.__build_plans | Gets the Build Plans API client.
Returns:
BuildPlans: | codesearchnet |
def testWithSkip(self, verify_fn, symbolic_checkpoint, num_skips):
def build_dataset():
def my_map(x):
if x == 0:
return dataset_ops.Dataset.from_tensor_slices([0, 1, 2, 3])
elif x == 1:
return dataset_ops.Dataset.from_tensor_slices([4, 5, 6, 7])
... | Test `.flat_map().skip()` checkpointing behavior.
`SkipInternal` and `GetNextInternal` are separate functions
but with slightly different implementations.
Therefore, we should test this op's behavior when used with `.skip()`.
Args:
verify_fn: Verify the correctness of this dataset's checkpointing.
symbolic_checkpoint... | github-repos |
def get_help_datapacks(filepath, prefix="!"):
help_contents = get_help_data(filepath)
datapacks = []
for d in help_contents:
heading = d
content = ""
if "commands" in d.lower():
for c in help_contents[d]:
if "name" not in c:
... | Load help text from a file and give it as datapacks
Args:
filepath (str): The file to load help text from
prefix (str): The prefix to use for commands
Returns:
datapacks (list): The datapacks from the file | juraj-google-style |
def filter_bboxes(bboxes, rows, cols, min_area=0.0, min_visibility=0.0):
resulting_boxes = []
for bbox in bboxes:
transformed_box_area = calculate_bbox_area(bbox, rows, cols)
bbox[:4] = np.clip(bbox[:4], 0, 1.0)
clipped_box_area = calculate_bbox_area(bbox, rows, cols)
if ((not tr... | Remove bounding boxes that either lie outside of the visible area by more then min_visibility
or whose area in pixels is under the threshold set by `min_area`. Also it crops boxes to final image size.
Args:
bboxes (list): List of bounding box with coordinates in the format used by albumentations
rows (int): Image rows... | codesearchnet |
def draw_text(img, text, position=(10, 10), font='FreeSans.ttf', font_size=14, color=(0, 0, 0)):
_check_pil()
font_files = _find_font_file(font)
if len(font_files) == 0:
logger.warn("Failed to lookup font '{}', falling back to default".format(font))
font = ImageFont.load_default()
... | Draws text over the image. Requires PIL.
Args:
img: The image to use.
text: The text string to overlay.
position: The text (x, y) position. (Default value = (10, 10))
font: The ttf or open type font to use. (Default value = 'FreeSans.ttf')
font_size: The text font size. (Default value = 12)
color: The (r, g, b) values... | juraj-google-style |
def clone_source_dir(source_dir, dest_dir):
if os.path.isdir(dest_dir):
print('removing', dest_dir)
shutil.rmtree(dest_dir)
shutil.copytree(source_dir, dest_dir) | Copies the source Protobuf files into a build directory.
Args:
source_dir (str): source directory of the Protobuf files
dest_dir (str): destination directory of the Protobuf files | juraj-google-style |
def calculate_mean_and_variance_from_sample_paths(samples, num_samples, dtype):
log_s = tf.math.log(samples)
mean = tf.reduce_mean(log_s, axis=-3, keepdims=True)
var = tf.reduce_mean((log_s - mean) ** 2, axis=-3, keepdims=True)
mean = tf.squeeze(mean, axis=[-1, -3])
var = tf.squeeze(var, axis=[-1, -... | Returns the mean and variance of log(`samples`).
Args:
samples: A real `Tensor` of shape [batch_shape, `num_samples`, num_times, 1]
containing the samples of random paths drawn from an Ito process.
num_samples: A scalar integer. The number of sample paths in `samples`.
dtype: The default dtype to use when converting v... | github-repos |
def add_multiple_servers(self, information, timeout=(- 1)):
uri = '{}/discovery'.format(self.URI)
return self.create(information, uri=uri, timeout=timeout) | Adds multiple rack-mount servers for management by the appliance. This API initiates the asynchronous addition of
supported server models.
Note: Servers in an enclosure are added by adding the enclosure resource. This is
only supported on appliances that support rack-mounted servers.
This is only supported for api ve... | codesearchnet |
def as_qubit_order(val: 'qubit_order_or_list.QubitOrderOrList') -> 'QubitOrder':
if isinstance(val, collections.Iterable):
return QubitOrder.explicit(val)
if isinstance(val, QubitOrder):
return val
raise ValueError("Don't know how to interpret <{}> as a Basis.".format(val)) | Converts a value into a basis.
Args:
val: An iterable or a basis.
Returns:
The basis implied by the value. | codesearchnet |
def map_(input_layer, fn):
if not input_layer.is_sequence():
raise ValueError('Can only map a sequence.')
return [fn(x) for x in input_layer] | Maps the given function across this sequence.
To map an entire template across the sequence, use the `as_fn` method on the
template.
Args:
input_layer: The input tensor.
fn: A function of 1 argument that is applied to each item in the sequence.
Returns:
A new sequence Pretty Tensor.
Raises:
ValueError: If the input_l... | juraj-google-style |
def is_closed(self):
old_training_data = self.training_data
self.training_data = {x: [] for x in self.sm_vector}
for t in self.smi_vector:
src_state = t[:-1]
symbol = t[-1:]
found = False
for dst_state in self.sm_vector:
if... | _check if the observation table is closed.
Args:
None
Returns:
tuple (bool, str): True if the observation table is closed and false otherwise.
If the table is not closed the escaping string is returned. | juraj-google-style |
def show(self, frame):
if (len(frame.shape) != 3):
raise ValueError('frame should have shape with only 3 dimensions')
if (not self.is_open):
self.open()
self._window.clear()
self._window.switch_to()
self._window.dispatch_events()
image = ImageData(frame.shape[1], frame.shape[0], ... | Show an array of pixels on the window.
Args:
frame (numpy.ndarray): the frame to show on the window
Returns:
None | codesearchnet |
def refresh(self, only_closed=False):
if only_closed:
opened = filter(self.__check_port, self.__closed)
self.__closed = self.__closed.difference(opened)
self.__ports = self.__ports.union(opened)
else:
ports = self.__closed.union(self.__ports)
... | refresh ports status
Args:
only_closed - check status only for closed ports | juraj-google-style |
def reset_index(self, **kwargs):
drop = kwargs.get('drop', False)
new_index = pandas.RangeIndex(len(self.index))
if (not drop):
if isinstance(self.index, pandas.MultiIndex):
new_column_names = pandas.Index(self.index.names)
new_columns = new_column_names.append(self.columns)
... | Removes all levels from index and sets a default level_0 index.
Returns:
A new QueryCompiler with updated data and reset index. | codesearchnet |
def calculate_parity(n):
if not is_natural(n):
raise ValueError('Expected n to be a positive integer.')
y = 0
n = abs(n)
while n:
y += n & 1
n = n >> 1
return y & 1 | Calculates and returns the parity of a number.
The parity of a number is ``1`` if the number has an odd number of ones
in its binary representation, otherwise ``0``.
Args:
n (int): the number whose parity to calculate
Returns:
``1`` if the number has an odd number of ones, otherwise ``0``.
Raises:
ValueError: if ``... | juraj-google-style |
def add_tile(self, tile_source, **kw):
tile_renderer = TileRenderer(tile_source=tile_source, **kw)
self.renderers.append(tile_renderer)
return tile_renderer | Adds new ``TileRenderer`` into ``Plot.renderers``
Args:
tile_source (TileSource) : a tile source instance which contain tileset configuration
Keyword Arguments:
Additional keyword arguments are passed on as-is to the tile renderer
Returns:
TileRenderer : TileRenderer | juraj-google-style |
def _dataset_merge_hdx_update(self, update_resources, update_resources_by_name, remove_additional_resources, create_default_views, hxl_update):
merge_two_dictionaries(self.data, self.old_data)
if ('resources' in self.data):
del self.data['resources']
updated_resources = self.old_data.get('resources'... | Helper method to check if dataset or its resources exist and update them
Args:
update_resources (bool): Whether to update resources
update_resources_by_name (bool): Compare resource names rather than position in list
remove_additional_resources (bool): Remove additional resources found in dataset (if updating)
create_... | codesearchnet |
def _add_query_parameter(url, name, value):
if (value is None):
return url
else:
return update_query_params(url, {name: value}) | Adds a query parameter to a url.
Replaces the current value if it already exists in the URL.
Args:
url: string, url to add the query parameter to.
name: string, query parameter name.
value: string, query parameter value.
Returns:
Updated query parameter. Does not update the url if value is None. | codesearchnet |
def index_resources(self):
if (not self.__index_resources):
self.__index_resources = IndexResources(self.__connection)
return self.__index_resources | Gets the Index Resources API client.
Returns:
IndexResources: | codesearchnet |
def FetchURNsForAllSignedBinaries(token
):
if _ShouldUseLegacyDatastore():
urns = []
aff4_roots = [GetAFF4PythonHackRoot(), GetAFF4ExecutablesRoot()]
for _, descendant_urns in aff4.FACTORY.RecursiveMultiListChildren(
aff4_roots):
urns.extend(descendant_urn... | Returns URNs for all signed binaries in the datastore.
Args:
token: ACL token to use with the legacy (non-relational) datastore. | juraj-google-style |
def Upgrade(self, aff4_class):
_ValidateAFF4Type(aff4_class)
if (self.__class__ == aff4_class):
return self
if (not isinstance(aff4_class, type)):
raise InstantiationError(('aff4_class=%s must be a type' % aff4_class))
if (not issubclass(aff4_class, AFF4Object)):
raise Instantiat... | Upgrades this object to the type specified.
AFF4 Objects can be upgraded on the fly to other type - As long as the new
type is derived from the current type. This feature allows creation of
placeholder objects which can later be upgraded to the fully featured
object.
Note: It is not allowed to downgrade an object if ... | codesearchnet |
def get_event(self, event_key):
event = self.event_key_map.get(event_key)
if event:
return event
self.logger.error(('Event "%s" is not in datafile.' % event_key))
self.error_handler.handle_error(exceptions.InvalidEventException(enums.Errors.INVALID_EVENT_KEY_ERROR))
return None | Get event for the provided event key.
Args:
event_key: Event key for which event is to be determined.
Returns:
Event corresponding to the provided event key. | codesearchnet |
def _events(self, using_url, filters=None, limit=None):
if not isinstance(limit, (int, NoneType)):
limit = None
if filters is None:
filters = []
if isinstance(filters, string_types):
filters = filters.split(',')
... | A long-polling method that queries Syncthing for events..
Args:
using_url (str): REST HTTP endpoint
filters (List[str]): Creates an "event group" in Syncthing to
only receive events that have been subscribed to.
limit (int): The number of events to query in the history
to catch up to the current state.
Returns:
gener... | juraj-google-style |
def time_pad(x, filter_size, dilations):
x_shape = common_layers.shape_list(x)
if filter_size == [1, 1, 1]:
return x
_, h, w = filter_size
eff_h = h + (h - 1)*(dilations[2] - 1)
eff_w = w + (w - 1)*(dilations[3] - 1)
a = (eff_h - 1)
b = (eff_w - 1)
c = filter_size[0] - 1
padding = [[0, 0]... | Pad left across time and pad valid across the spatial components.
Also concats a binary feature that indicates if a feature is padded or not.
Args:
x: 5-D Tensor, (NTHWC)
filter_size: list of ints
dilations: list of ints, dilations - 1 specifies the number of holes
between two filter elements.
Returns:
x_pad: 5-D Ten... | juraj-google-style |
def client(self, service_name, version, component, **kw):
service = _create_service_api(
self._credentials,
service_name,
version,
kw.get('developer_key'),
kw.get('cache_discovery', False),
self._http or _build_http())
ret... | Safely initialize a repository class to a property.
Args:
repository_class (class): The class to initialize.
version (str): The gcp service version for the repository.
Returns:
object: An instance of repository_class. | juraj-google-style |
def __init__(self, channel):
self.TranslateText = channel.unary_unary(
"/google.cloud.translation.v3beta1.TranslationService/TranslateText",
request_serializer=google_dot_cloud_dot_translation__v3beta1_dot_proto_dot_translation__service__pb2.TranslateTextRequest.SerializeToStrin... | Constructor.
Args:
channel: A grpc.Channel. | juraj-google-style |
def sendmail(subject, text, mailto, sender=None):
def user_at_host():
from socket import gethostname
return os.getlogin() + "@" + gethostname()
try:
sender = user_at_host() if sender is None else sender
except OSError:
sender = 'abipyscheduler@youknowwhere'
if... | Sends an e-mail with unix sendmail.
Args:
subject: String with the subject of the mail.
text: String with the body of the mail.
mailto: String or list of string with the recipients.
sender: string with the sender address.
If sender is None, username@hostname is used.
Returns:
Exit status | juraj-google-style |
def match_alphabet(self, pattern):
s = {}
for char in pattern:
s[char] = 0
for i in range(len(pattern)):
s[pattern[i]] |= 1 << (len(pattern) - i - 1)
return s | Initialise the alphabet for the Bitap algorithm.
Args:
pattern: The text to encode.
Returns:
Hash of character locations. | juraj-google-style |
def GetHashersInformation(cls):
hashers_information = []
for (_, hasher_class) in cls.GetHasherClasses():
description = getattr(hasher_class, 'DESCRIPTION', '')
hashers_information.append((hasher_class.NAME, description))
return hashers_information | Retrieves the hashers information.
Returns:
list[tuple]: containing:
str: hasher name.
str: hasher description. | codesearchnet |
def fft(x, axis=(- 1), padding_samples=0):
if (padding_samples > 0):
padded = np.concatenate([x, np.zeros((len(x), padding_samples), dtype=x.dtype)], axis=axis)
else:
padded = x
transformed = np.fft.rfft(padded, axis=axis, norm='ortho')
sr = audio_sample_rate(int((Seconds(1) / x.dimensio... | Apply an FFT along the given dimension, and with the specified amount of
zero-padding
Args:
x (ArrayWithUnits): an :class:`~zounds.core.ArrayWithUnits` instance
which has one or more :class:`~zounds.timeseries.TimeDimension`
axes
axis (int): The axis along which the fft should be applied
padding_samples (int): The num... | codesearchnet |
def FindMessageTypeByName(self, full_name):
full_name = _NormalizeFullyQualifiedName(full_name)
if full_name not in self._descriptors:
self._FindFileContainingSymbolInDb(full_name)
return self._descriptors[full_name] | Loads the named descriptor from the pool.
Args:
full_name: The full name of the descriptor to load.
Returns:
The descriptor for the named type.
Raises:
KeyError: if the message cannot be found in the pool. | juraj-google-style |
def list_vmss_vm_instance_view_pg(access_token, subscription_id, resource_group, vmss_name,
link=None):
if link is None:
endpoint = ''.join([get_rm_endpoint(),
'/subscriptions/', subscription_id,
'/resourceGroups/... | Gets one page of a paginated list of scale set VM instance views.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vmss_name (str): Name of the virtual machine scale set.
link (str): Optional link to URI to get ... | juraj-google-style |
def archs(self, as_list=False):
archs = self.arch_list().split('/')
if as_list:
return archs
return set(archs) | Return all of the architectures for this target.
Args:
as_list (bool): Return a list instead of the default set object.
Returns:
set or list: All of the architectures used in this TargetSettings object. | juraj-google-style |
def get(self, volume_id):
return self.prepare_model(self.client.api.inspect_volume(volume_id)) | Get a volume.
Args:
volume_id (str): Volume name.
Returns:
(:py:class:`Volume`): The volume.
Raises:
:py:class:`docker.errors.NotFound`
If the volume does not exist.
:py:class:`docker.errors.APIError`
If the server returns an error. | codesearchnet |
def get_label(self, label, params=None):
return self.label(label, action='GET', params=params) | Gets a security label from a Indicator/Group/Victim
Args:
label: The name of the Security Label
params: | juraj-google-style |
def get_course_and_course_run(self, course_run_id):
course_id = parse_course_key(course_run_id)
course = self.get_course_details(course_id)
course_run = None
if course:
course_run = None
course_runs = [course_run for course_run in course['course_runs'] if (course_run['key'] == course_run... | Return the course and course run metadata for the given course run ID.
Arguments:
course_run_id (str): The course run ID.
Returns:
tuple: The course metadata and the course run metadata. | codesearchnet |
async def send_message(
self, request: str, response_expected: bool, **kwargs: Any
) -> Response:
headers = dict(self.DEFAULT_HEADERS)
headers.update(kwargs.pop("headers", {}))
response = await self.client.fetch(
self.endpoint, method="POST", body=request, hea... | Transport the message to the server and return the response.
Args:
request: The JSON-RPC request string.
response_expected: Whether the request expects a response.
Returns:
A Response object. | juraj-google-style |
def ADOPT_module_key_flags(
module, flag_values=FLAGS):
if not isinstance(module, types.ModuleType):
raise Error('Expected a module object, not %r.' % (module,))
_internal_declare_key_flags(
[f.name for f in flag_values._GetKeyFlagsForModule(module.__name__)],
flag_values=flag_values)
... | Declares that all flags key to a module are key to the current module.
Args:
module: A module object.
flag_values: A FlagValues object. This should almost never need
to be overridden.
Raises:
Error: When given an argument that is a module name (a
string), instead of a module object. | juraj-google-style |
def calculate_dill_dG(seq_len, temp):
Th = 373.5
Ts = 385
temp += 273.15
dH = (4.0 * seq_len + 143) * 1000
dS = 13.27 * seq_len + 448
dCp = (0.049 * seq_len + 0.85) * 1000
dG = dH + dCp * (temp - Th) - temp * dS - temp * dCp * math.log(float(temp) / Ts)
return dG | Get free energy of unfolding (dG) using Dill method in units J/mol.
Args:
seq_len (int): Length of amino acid sequence
temp (float): Temperature in degrees C
Returns:
float: Free energy of unfolding dG (J/mol) | juraj-google-style |
def price(self, instrument, **kwargs):
request = Request('GET', '/v3/instruments/{instrument}/price')
request.set_path_param('instrument', instrument)
request.set_param('time', kwargs.get('time'))
response = self.ctx.request(request)
if (response.content_type is None):
return response
if... | Fetch a price for an instrument. Accounts are not associated in any way
with this endpoint.
Args:
instrument:
Name of the Instrument
time:
The time at which the desired price is in effect. The current
price is returned if no time is provided.
Returns:
v20.response.Response containing the results from submitting the
r... | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.