code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def forward(self, g_values: torch.Tensor, mask: torch.Tensor, labels: Optional[torch.Tensor]=None, loss_batch_weight=1, return_dict=False) -> BayesianWatermarkDetectorModelOutput:
likelihoods_watermarked = self.likelihood_model_watermarked(g_values)
likelihoods_unwatermarked = 0.5 * torch.ones_like(g_values)
... | Computes the watermarked posterior P(watermarked|g_values).
Args:
g_values (`torch.Tensor` of shape `(batch_size, seq_len, watermarking_depth, ...)`):
g-values (with values 0 or 1)
mask:
A binary array shape [batch_size, seq_len] indicating which g-values should be used. g-values with mask
value 0 are discarded.
Retu... | github-repos |
def _prepare_babi_data(tmp_dir, data_dir):
if not tf.gfile.Exists(data_dir):
tf.gfile.MakeDirs(data_dir)
file_path = os.path.join(tmp_dir, _TAR)
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
... | Downloads and extracts the dataset.
Args:
tmp_dir: temp directory to download and extract the dataset
data_dir: The base directory where data and vocab files are stored.
Returns:
tmp_dir: temp directory containing the raw data. | juraj-google-style |
def extractUnits(self, inp):
inp = self._preprocess(inp)
units = []
description = ""
for w in inp.split(' '):
if self.isValidUnit(w) or w == '/':
if description:
description += " "
description += w
else... | Collects all the valid units from an inp string. Works by
appending consecutive words from the string and cross-referncing
them with a set of valid units.
Args:
inp (str): Some text which hopefully contains descriptions
of different units.
Returns:
A list of strings, each entry in which is a valid quantities
unit. | juraj-google-style |
def get_servo_position(self):
data = []
data.append(0x09)
data.append(self.servoid)
data.append(RAM_READ_REQ)
data.append(CALIBRATED_POSITION_RAM)
data.append(BYTE2)
send_data(data)
rxdata = []
try:
rxdata = SERPORT.r... | Gets the current position of Herkulex
Args:
none
Returns:
int: position of the servo- 0 to 1023
Raises:
SerialException: Error occured while opening serial port | juraj-google-style |
def broadcast_recv(shape, dtype, group_size, group_key, instance_key, communication_hint='auto', timeout=0):
if group_size <= 1:
raise ValueError(f'Parameter `group_size` to broadcast_send must be at least 2. Received: {group_size}.')
return gen_collective_ops.collective_bcast_recv(shape=shape, T=dtype,... | Receives a broadcasts tensor, across devices.
Args:
shape: Shape of the tensor to be received.
dtype: Type of the tensor to be received.
group_size: one plus the number of receiving tensors, i.e. the total
number of devices participating. Each tensor must reside on a
different device.
group_key: an integer identifyin... | github-repos |
def make_full_document(text, title=None, preamp_decl={}, preamb_extra=None):
import utool as ut
doc_preamb = ut.codeblock('\n %\\documentclass{article}\n \\documentclass[10pt,twocolumn,letterpaper]{article}\n % \\usepackage[utf8]{inputenc}\n \\usepackage[T1]{fontenc}\n\n \\usepackage{times}\n ... | r"""
dummy preamble and document to wrap around latex fragment
Args:
text (str):
title (str):
Returns:
str: text_
CommandLine:
python -m utool.util_latex --test-make_full_document
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_latex import * # NOQA
>>> text = 'foo'
>>> title = 'title'
>>> preamp_decl = {}
>>> ... | codesearchnet |
def define_batch_env(constructor, num_agents, env_processes):
with tf.variable_scope('environments'):
if env_processes:
envs = [tools.wrappers.ExternalProcess(constructor) for _ in range(num_agents)]
else:
envs = [constructor() for _ in range(num_agents)]
batch_env = ... | Create environments and apply all desired wrappers.
Args:
constructor: Constructor of an OpenAI gym environment.
num_agents: Number of environments to combine in the batch.
env_processes: Whether to step environment in external processes.
Returns:
In-graph environments object. | codesearchnet |
def _load_methods(package):
global _methods
_methods[package] = None
from acorn.config import settings
from acorn.logging.descriptors import _obj_getattr
spack = settings(package)
if spack is not None:
if spack.has_section("analysis.methods"):
_methods[package] = {}... | Loads the mappings from method call result to analysis.
Args:
package (str): name of the package to load for. | juraj-google-style |
def _binary_2d_label_to_1d_sparse_value(labels):
indices = []
values = []
batch = 0
for row in labels:
label = 0
xi = 0
for x in row:
if x == 1:
indices.append([batch])
values.append(label)
xi += 1
else:
... | Convert dense 2D binary indicator to sparse ID.
Only 1 values in `labels` are included in result.
Args:
labels: Dense 2D binary indicator, shape [batch_size, num_classes]. Each
row must contain exactly 1 `1` value.
Returns:
`SparseTensorValue` of shape [batch_size]. Values are indices of `1` values
along the last di... | github-repos |
def allreduce_ring(xs, devices, reduction_fn_string="SUM"):
n = len(xs)
if len(devices) != n:
raise ValueError("devices must be a list of length len(xs)")
if n == 1:
return xs
shape = xs[0].shape.as_list()
size = None if None in shape else mtf.list_product(shape)
if size is None or size < 1024... | Compute the reduction of all Tensors and put the result everywhere.
Performance-optimized for a ring of devices.
Args:
xs: a list of n tf.Tensors
devices: a list of strings
reduction_fn_string: "SUM" or "MAX"
Returns:
a list of n Tensors
Raises:
ValueError: if devices is not a list of n strings | juraj-google-style |
def to_view(self, view_name):
from . import _view
return _view.View(view_name, self._context).create(self._sql) | Create a View from this Query.
Args:
view_name: the name of the View either as a string or a 3-part tuple
(projectid, datasetid, name).
Returns:
A View for the Query. | juraj-google-style |
def __init__(self, type, data):
if not isinstance(type, int):
raise TypeError("ext type is not type integer")
elif sys.version_info[0] == 3 and not isinstance(data, bytes):
raise TypeError("ext data is not type \'bytes\'")
elif sys.version_info[... | Construct a new Ext object.
Args:
type: application-defined type integer
data: application-defined data byte array
Example:
>>> foo = umsgpack.Ext(0x05, b"\x01\x02\x03")
>>> umsgpack.packb({u"special stuff": foo, u"awesome": True})
'\x82\xa7awesome\xc3\xadspecial stuff\xc7\x03\x05\x01\x02\x03'
>>> bar = umsgpack.unpa... | juraj-google-style |
def __init__(
self, summary=AverageSummary, alpha=1,
credibility=WeightedCredibility, reviewer=Reviewer, product=Product):
self.alpha = alpha
self.graph = nx.DiGraph()
self.reviewers = []
self.products = []
self._summary_cls = summary
sel... | Construct bipartite graph.
Args:
summary_type: specify summary type class, default value is AverageSummary.
alpha: used to compute weight of anomalous scores, default value is 1.
credibility: credibility class to be used in this graph.
(Default: WeightedCredibility)
reviewer: Class of reviewers.
product: Class of prod... | juraj-google-style |
def take_grad(self, num_required, name=None):
return gen_data_flow_ops.sparse_accumulator_take_gradient(self._accumulator_ref, num_required, dtype=self._dtype, name=name) | Attempts to extract the average gradient from the accumulator.
The operation blocks until sufficient number of gradients have been
successfully applied to the accumulator.
Once successful, the following actions are also triggered:
- Counter of accumulated gradients is reset to 0.
- Aggregated gradient is reset to 0 t... | github-repos |
def set_keras_mask(x, mask):
set_tensor_attr(x, '_keras_mask', mask) | Sets the Keras mask attribute for the given tensor in-place.
Args:
x: Input tensor.
mask: The mask tensor to be set. If `None`, the `_keras_mask` attribute
will be cleared. | github-repos |
def _CreateCommentsFromPrefix(comment_prefix, comment_lineno, comment_column, standalone=False):
comments = []
lines = comment_prefix.split('\n')
index = 0
while index < len(lines):
comment_block = []
while index < len(lines) and lines[index].lstrip().startswith('
comment_blo... | Create pytree nodes to represent the given comment prefix.
Args:
comment_prefix: (unicode) the text of the comment from the node's prefix.
comment_lineno: (int) the line number for the start of the comment.
comment_column: (int) the column for the start of the comment.
standalone: (bool) determines if the comment is s... | github-repos |
def set_symbols(self, symbols, functional=None, sym_potcar_map=None):
del self[:]
if sym_potcar_map:
for el in symbols:
self.append(PotcarSingle(sym_potcar_map[el]))
else:
for el in symbols:
p = PotcarSingle.from_symbol_and_functional(el, functional)
self.... | Initialize the POTCAR from a set of symbols. Currently, the POTCARs can
be fetched from a location specified in .pmgrc.yaml. Use pmg config
to add this setting.
Args:
symbols ([str]): A list of element symbols
functional (str): The functional to use. If None, the setting
PMG_DEFAULT_FUNCTIONAL in .pmgrc.yaml is used, ... | codesearchnet |
def from_schema(cls, schema: class_schema.Schema, module_name: str, name: str, qualname: Optional[str]=None, is_method: bool=True) -> 'Signature':
arg_names = list(schema.metadata.get('init_arg_list', []))
if arg_names and arg_names[-1].startswith('*'):
vararg_name = arg_names[-1][1:]
arg_names.... | Creates a signature from a schema object.
Args:
schema: A `pg.typing.Schema` object associated with a `pg.Object`.
module_name: Module name for the signature.
name: Function or method name of the signature.
qualname: Qualname of the signature.
is_method: If True, `self` will be added in the signature as the first
argu... | github-repos |
def index(self, text, terms=None, **kwargs):
self.clear()
terms = terms or text.terms.keys()
pairs = combinations(terms, 2)
count = comb(len(terms), 2)
for t1, t2 in bar(pairs, expected_size=count, every=1000):
score = text.score_b... | Index all term pair distances.
Args:
text (Text): The source text.
terms (list): Terms to index. | juraj-google-style |
def assert_call(self, expected, left, right):
name_map = {left: 'left', right: 'right'}
node, result = self._is_instance.call(self._node, None, function.Args((left, right), self.new_dict(), None, None))
self.assertIn(node, self._node.outgoing)
result_map = {}
for b in result.bindings:
terms ... | Check that call() returned the desired results.
Args:
expected: A dict from values to source sets, where a source set is
represented by the sorted binding names separated by spaces, for example
"left:0 right:1" would indicate binding #0 of variable "left" and
binding #1 of variable "right".
left: A Variable to use as ... | github-repos |
def upper_bound(fm, nr_subs=None, scale_factor=1):
nr_subs_total = len(np.unique(fm.SUBJECTINDEX))
if (not nr_subs):
nr_subs = (nr_subs_total - 1)
assert (nr_subs < nr_subs_total)
intersub_scores = []
for measure in range(len(measures.scores)):
res_dict = {}
result_vectors = ... | compute the inter-subject consistency upper bound for a fixmat.
Input:
fm : a fixmat instance
nr_subs : the number of subjects used for the prediction. Defaults
to the total number of subjects in the fixmat minus 1
scale_factor : the scale factor of the FDMs. Default is 1.
Returns:
A list of scores; the list contains ... | codesearchnet |
def parse_line(self, line):
toks = shlex.split(line)
return (toks[0], ([] if (len(toks) == 1) else toks[1:])) | Parse a line of input.
The input line is tokenized using the same rules as the way bash shell
tokenizes inputs. All quoting and escaping rules from the bash shell
apply here too.
The following cases are handled by __exec_line__():
1. Empty line.
2. The input line is completely made of whitespace characters.
3. The... | codesearchnet |
def __get_favorites(self, favorite_type, start=0, max_items=100):
if favorite_type not in (RADIO_SHOWS, RADIO_STATIONS):
favorite_type = SONOS_FAVORITES
response = self.contentDirectory.Browse([
('ObjectID',
'FV:2' if favorite_type is SONOS_FAVORITES
... | Helper method for `get_favorite_radio_*` methods.
Args:
favorite_type (str): Specify either `RADIO_STATIONS` or
`RADIO_SHOWS`.
start (int): Which number to start the retrieval from. Used for
paging.
max_items (int): The total number of results to return. | juraj-google-style |
def Contains(self, value):
self._awql = self._CreateSingleValueCondition(value, 'CONTAINS')
return self._query_builder | Sets the type of the WHERE clause as "contains".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | codesearchnet |
def ToDebugString(self, indentation_level=1):
indentation = ' ' * indentation_level
text_parts = ['{0:s}path segment index: {1:d}\n'.format(
indentation, self.path_segment_index)]
for path_segment, scan_object in self._path_segments.items():
text_parts.append('{0:s}path segment: {1:s}\... | Converts the path filter scan tree node into a debug string.
Args:
indentation_level: an integer containing the text indentation level.
Returns:
A string containing a debug representation of the path filter scan
tree node. | juraj-google-style |
def path_is_ignored(self, path):
try:
self.run('check-ignore', '--quiet', path)
except CommandError as e:
if (e.retcode == 1):
return False
else:
raise e
return True | Given a path, check if the path would be ignored.
Returns:
boolean | codesearchnet |
def file_content(self, file_content, update_if_exists=True):
if not self.can_update():
self._tcex.handle_error(910, [self.type])
self._data['fileContent'] = file_content
return self.tc_requests.upload(
self.api_type,
self.api_sub_type,
se... | Updates the file content.
Args:
file_content: The file_content to upload.
update_if_exists:
Returns: | juraj-google-style |
def list(name, default=None, allow_none=False, fallback=None, separator=','):
value = read(name, default, allow_none, fallback=fallback)
if isinstance(value, builtins.list):
return value
elif isinstance(value, builtins.str):
return _str_to_list(value, separator)
elif value is None a... | Get a list of strings or the default.
The individual list elements are whitespace-stripped.
Args:
name: The environment variable name
default: The default value to use if no environment variable is found
allow_none: If the return value can be `None` (i.e. optional)
separator: The list item separator character or patt... | juraj-google-style |
def get_metric_by_name(self, metric_name, **kwargs):
return self._get_object_by_name(self._METRIC_ENDPOINT_SUFFIX,
metric_name,
**kwargs) | get a metric by name
Args:
metric_name (string): name of metric
Returns:
dictionary of response | juraj-google-style |
def format_level_0_memory(memory):
formatted_memory = _list_to_complex_array(memory)
if not 2 <= len(formatted_memory.shape) <= 3:
raise QiskitError('Level zero memory is not of correct shape.')
return formatted_memory | Format an experiment result memory object for measurement level 0.
Args:
memory (list): Memory from experiment with `meas_level==1`. `avg` or
`single` will be inferred from shape of result memory.
Returns:
np.ndarray: Measurement level 0 complex numpy array
Raises:
QiskitError: If the returned numpy array does not h... | juraj-google-style |
def run_one_step(self, eig_init_vec_val, eig_num_iter_val, smooth_val, penalty_val, learning_rate_val):
step_feed_dict = {self.eig_init_vec_placeholder: eig_init_vec_val, self.eig_num_iter_placeholder: eig_num_iter_val, self.smooth_placeholder: smooth_val, self.penalty_placeholder: penalty_val, self.learning_rate: ... | Run one step of gradient descent for optimization.
Args:
eig_init_vec_val: Start value for eigen value computations
eig_num_iter_val: Number of iterations to run for eigen computations
smooth_val: Value of smoothness parameter
penalty_val: Value of penalty for the current step
learning_rate_val: Value of learning rate... | codesearchnet |
def print_error_messages_raylet(task_error_queue, threads_stopped):
while True:
if threads_stopped.is_set():
return
try:
(error, t) = task_error_queue.get(block=False)
except queue.Empty:
threads_stopped.wait(timeout=0.01)
continue
whil... | Prints message received in the given output queue.
This checks periodically if any un-raised errors occured in the background.
Args:
task_error_queue (queue.Queue): A queue used to receive errors from the
thread that listens to Redis.
threads_stopped (threading.Event): A threading event used to signal to
the thread t... | codesearchnet |
def to_hdf5(ramon, hdf5=None):
if issubclass(type(ramon), RAMONBase) is False:
raise InvalidRAMONError("Invalid RAMON supplied to ramon.to_hdf5.")
import h5py
import numpy
if hdf5 is None:
tmpfile = tempfile.NamedTemporaryFile(delete=False)
else:
tmpfile = hdf5
wi... | Exports a RAMON object to an HDF5 file object.
Arguments:
ramon (RAMON): A subclass of RAMONBase
hdf5 (str): Export filename
Returns:
hdf5.File
Raises:
InvalidRAMONError: if you pass a non-RAMON object | juraj-google-style |
def sync_entities(*model_objs):
if sync_entities.defer:
if not model_objs:
sync_entities.buffer[None] = None
else:
for model_obj in model_objs:
sync_entities.buffer[(model_obj.__class__, model_obj.pk)] = model_obj
... | Syncs entities
Args:
model_objs (List[Model]): The model objects to sync. If empty, all entities will be synced | juraj-google-style |
def __or__(self, other: 'TensorFluent') -> 'TensorFluent':
return self._binary_op(self, other, tf.logical_or, tf.bool) | Returns a TensorFluent for the or logical operator.
Args:
self: The first operand.
other: The second operand.
Returns:
A TensorFluent wrapping the operator's output. | juraj-google-style |
def wiki_2x2_base():
hparams = mtf_transformer.mtf_transformer_base_lm()
hparams.shared_embedding_and_softmax_weights = False
hparams.attention_dropout = 0.0
hparams.relu_dropout = 0.0
hparams.layer_prepostprocess_dropout = 0.0
hparams.max_length = 1024
hparams.batch_size = 32
hparams.le... | Set of architectural experiments - language model on wikipedia on a 2x2.
1 epoch = ~180k steps at batch size 32 - we may never finish an epoch!
Returns:
a hparams | codesearchnet |
class DetaHungarianMatcher(nn.Module):
def __init__(self, class_cost: float=1, bbox_cost: float=1, giou_cost: float=1):
super().__init__()
requires_backends(self, ['scipy'])
self.class_cost = class_cost
self.bbox_cost = bbox_cost
self.giou_cost = giou_cost
if class_c... | This class computes an assignment between the targets and the predictions of the network.
For efficiency reasons, the targets don't include the no_object. Because of this, in general, there are more
predictions than targets. In this case, we do a 1-to-1 matching of the best predictions, while the others are
un-matched... | github-repos |
def __init__(self, variable_name, inferred_type):
variable_name = ensure_unicode_string(variable_name)
super(Variable, self).__init__(variable_name, inferred_type)
self.variable_name = variable_name
self.inferred_type = inferred_type
self.validate() | Construct a new Variable object for the given variable name.
Args:
variable_name: string, should start with '$' and then obey variable naming rules
(see validate_safe_string())
inferred_type: GraphQL type object, specifying the inferred type of the variable
Returns:
new Variable object | juraj-google-style |
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_3):
if (kmip_version < enums.KMIPVersion.KMIP_1_3):
raise exceptions.VersionNotSupported('KMIP {} does not support the ProfileInformation object.'.format(kmip_version.value))
super(ProfileInformation, self).read(input_buffer, kmip_versio... | Read the data encoding the ProfileInformation structure and decode it
into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the ob... | codesearchnet |
def ReadClientMetadata(self, client_id):
result = self.MultiReadClientMetadata([client_id])
try:
return result[client_id]
except KeyError:
raise UnknownClientError(client_id) | Reads the ClientMetadata record for a single client.
Args:
client_id: A GRR client id string, e.g. "C.ea3b2b71840d6fa7".
Returns:
An rdfvalues.object.ClientMetadata object.
Raises:
UnknownClientError: if no client with corresponding id was found. | codesearchnet |
def _format_device(var):
if var.dtype.name.endswith('_ref'):
resource_var_annotation = '(legacy)'
else:
resource_var_annotation = '(resource)'
if var.device:
return '{} {}'.format(var.device, resource_var_annotation)
else:
return resource_var_annotation | Returns the device with an annotation specifying `ResourceVariable`.
"legacy" means a normal tf.Variable while "resource" means a ResourceVariable.
For example:
`(legacy)`
`(resource)`
`/job:learner/task:0/device:CPU:* (legacy)`
`/job:learner/task:0/device:CPU:* (resource)`
Args:
var: The Tensorflow Variable to prin... | codesearchnet |
def rename_dimension(x, old_name, new_name):
return reshape(x, x.shape.rename_dimension(old_name, new_name)) | Reshape a Tensor, renaming one dimension.
Args:
x: a Tensor
old_name: a string
new_name: a string
Returns:
a Tensor | codesearchnet |
def absolute_name(self, depth=0):
node, node_depth = self, self.depth
if depth < 1:
depth = node_depth
while node_depth > depth and node.package is not None:
node = node.package
node_depth -= 1
names = []
while node is not None:
... | Return the absolute name of the node.
Concatenate names from root to self within depth.
Args:
depth (int): maximum depth to go to.
Returns:
str: absolute name of the node (until given depth is reached). | juraj-google-style |
def economic_qs(K, epsilon=sqrt(finfo(float).eps)):
(S, Q) = eigh(K)
nok = (abs(max(Q[0].min(), Q[0].max(), key=abs)) < epsilon)
nok = (nok and (abs(max(K.min(), K.max(), key=abs)) >= epsilon))
if nok:
from scipy.linalg import eigh as sp_eigh
(S, Q) = sp_eigh(K)
ok = (S >= epsilon)
... | r"""Economic eigen decomposition for symmetric matrices.
A symmetric matrix ``K`` can be decomposed in
:math:`\mathrm Q_0 \mathrm S_0 \mathrm Q_0^\intercal + \mathrm Q_1\
\mathrm S_1 \mathrm Q_1^ \intercal`, where :math:`\mathrm S_1` is a zero
matrix with size determined by ``K``'s rank deficiency.
Args:
K (array_lik... | codesearchnet |
def generate_sample_set(self, tags=None):
if isinstance(tags, str):
tags = [tags]
md5_list = self.data_store.tag_match(tags)
return self.store_sample_set(md5_list) | Generate a sample_set that maches the tags or all if tags are not specified.
Args:
tags: Match samples against this tag list (or all if not specified)
Returns:
The sample_set of those samples matching the tags | codesearchnet |
def get_rbounds(step):
if step.geom is not None:
rcmb = step.geom.rcmb
else:
rcmb = step.sdat.par['geometry']['r_cmb']
if step.sdat.par['geometry']['shape'].lower() == 'cartesian':
rcmb = 0
rcmb = max(rcmb, 0)
return rcmb, rcmb + 1 | Radial or vertical position of boundaries.
Args:
step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData
instance.
Returns:
tuple of floats: radial or vertical positions of boundaries of the
domain. | juraj-google-style |
def ws004c(self, value=None):
if (value is not None):
try:
value = float(value)
except ValueError:
raise ValueError('value {} need to be of type float for field `ws004c`'.format(value))
self._ws004c = value | Corresponds to IDD Field `ws004c`
Args:
value (float): value for IDD Field `ws004c`
Unit: m/s
if `value` is None it will not be checked against the
specification and is assumed to be a missing value
Raises:
ValueError: if `value` is not a valid value | codesearchnet |
def read_cs_g0_contribution(self):
header_pattern = '^\\s+G\\=0 CONTRIBUTION TO CHEMICAL SHIFT \\(field along BDIR\\)\\s+$\\n^\\s+-{50,}$\\n^\\s+BDIR\\s+X\\s+Y\\s+Z\\s*$\\n^\\s+-{50,}\\s*$\\n'
row_pattern = ('(?:\\d+)\\s+' + '\\s+'.join((['([-]?\\d+\\.\\d+)'] * 3)))
footer_pattern = '\\s+-{50,}\\s*$'
se... | Parse the G0 contribution of NMR chemical shielding.
Returns:
G0 contribution matrix as list of list. | codesearchnet |
def get_atoms(structure, **kwargs):
if not structure.is_ordered:
raise ValueError("ASE Atoms only supports ordered structures")
symbols = [str(site.specie.symbol) for site in structure]
positions = [site.coords for site in structure]
cell = structure.lattice.matrix
... | Returns ASE Atoms object from pymatgen structure.
Args:
structure: pymatgen.core.structure.Structure
**kwargs: other keyword args to pass into the ASE Atoms constructor
Returns:
ASE Atoms object | juraj-google-style |
def get_redirect(paths):
if isinstance(paths, str):
paths = [paths]
for path in paths:
url, permanent = get_alias(path)
if url:
return redirect(url, 301 if permanent else 302)
url, permanent = current_app.get_path_regex(path)
if url:
return... | Get a redirect from a path or list of paths
Arguments:
paths -- either a single path string, or a list of paths to check
Returns: a flask.redirect() result | juraj-google-style |
def _recover_shape_information(self, inputs, outputs):
batch_size_value = inputs.get_shape()[0]
if self._data_format.startswith('NC'):
output_shape_value = ((batch_size_value, self.output_channels) + self.output_shape)
elif (self._data_format.startswith('N') and self._data_format.endswith('C')):
... | Recover output tensor shape value to enable shape inference.
The batch size of `inputs` isn't preserved by the convolution op. Calculate
what the proper output shape will be for `outputs`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
outputs: A Tensor of shape... | codesearchnet |
def to_string(cls, error_code):
if error_code == cls.ZONE_NOT_FOUND_ERROR:
return 'Zone not found'
return super(JLinkWriteErrors, cls).to_string(error_code) | Returns the string message for the given ``error_code``.
Args:
cls (JLinkWriteErrors): the ``JLinkWriteErrors`` class
error_code (int): error code to convert
Returns:
An error string corresponding to the error code.
Raises:
ValueError: if the error code is invalid. | juraj-google-style |
def GetPreviousNonBlankLine(clean_lines, linenum):
prevlinenum = (linenum - 1)
while (prevlinenum >= 0):
prevline = clean_lines.elided[prevlinenum]
if (not IsBlankLine(prevline)):
return (prevline, prevlinenum)
prevlinenum -= 1
return ('', (- 1)) | Return the most recent non-blank line and its line number.
Args:
clean_lines: A CleansedLines instance containing the file contents.
linenum: The number of the line to check.
Returns:
A tuple with two elements. The first element is the contents of the last
non-blank line before the current line, or the empty string ... | codesearchnet |
def process(self, body, url=None, sig=None):
self.request = RequestBody()
self.response = ResponseBody()
self.request.parse(body)
app_id = self.request.session.application.application_id
stamp = self.request.request.timestamp
if (not self.valid.request(app_id, body, stamp, url, sig)):
re... | Process request body given skill logic.
To validate a request, both, url and sig are required.
Attributes received through body will be automatically added to the
response.
Args:
body: str. HTTP request body.
url: str. SignatureCertChainUrl header value sent by request.
PEM-encoded X.509 certificate chain that Alexa... | codesearchnet |
def segment_to_vector(self, seg):
ft_dict = {ft: val for (val, ft) in self.fts(seg)}
return [ft_dict[name] for name in self.names] | Given a Unicode IPA segment, return a list of feature specificiations
in cannonical order.
Args:
seg (unicode): IPA consonant or vowel
Returns:
list: feature specifications ('+'/'-'/'0') in the order from
`FeatureTable.names` | juraj-google-style |
def from_maybe_serialized(source: Union[Any, str], value_type: Optional[Type[Any]]=None) -> Any:
if isinstance(source, str):
if source.endswith('.json'):
value = symbolic.load(source)
else:
value = symbolic.from_json_str(source)
else:
value = source
if value_t... | Load value from maybe serialized form (e.g. JSON file or JSON string).
Args:
source: Source of value. It can be value (non-string type) itself, or a
filepath, or a JSON string from where the value will be loaded.
value_type: An optional type to constrain the value.
Returns:
Value from source. | github-repos |
def _CalculateHashDataStream(self, file_entry, data_stream_name):
hash_context = hashlib.sha256()
try:
file_object = file_entry.GetFileObject(data_stream_name=data_stream_name)
except IOError as exception:
logging.warning((
'Unable to open path specification:\n{0:s}'
'w... | Calculates a message digest hash of the data of the file entry.
Args:
file_entry (dfvfs.FileEntry): file entry.
data_stream_name (str): name of the data stream.
Returns:
bytes: digest hash or None. | juraj-google-style |
def set_dataset_date(self, dataset_date, dataset_end_date=None, date_format=None):
parsed_date = self._parse_date(dataset_date, date_format)
if (dataset_end_date is None):
self.set_dataset_date_from_datetime(parsed_date)
else:
parsed_end_date = self._parse_date(dataset_end_date, date_format)... | Set dataset date from string using specified format. If no format is supplied, the function will guess.
For unambiguous formats, this should be fine.
Args:
dataset_date (str): Dataset date string
dataset_end_date (Optional[str]): Dataset end date string
date_format (Optional[str]): Date format. If None is given, will ... | codesearchnet |
def call(self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, causal_attention_mask: tf.Tensor, output_attentions: Optional[bool]=False) -> Tuple[tf.Tensor]:
residual = hidden_states
hidden_states = self.layer_norm1(hidden_states)
hidden_states, attn_weights = self.self_attn(hidden_states=hidden_state... | Args:
hidden_states (`tf.Tensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`tf.Tensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
`(config.encoder_attention_heads,)`.
output_attentions (`bool`, *optional*)... | github-repos |
def past_stop_threshold(stop_threshold, eval_metric):
if stop_threshold is None:
return False
if not isinstance(stop_threshold, numbers.Number):
raise ValueError("Threshold for checking stop conditions must be a number.")
if not isinstance(eval_metric, numbers.Number):
raise ValueError("Eval metri... | Return a boolean representing whether a model should be stopped.
Args:
stop_threshold: float, the threshold above which a model should stop
training.
eval_metric: float, the current value of the relevant metric to check.
Returns:
True if training should stop, False otherwise.
Raises:
ValueError: if either stop_thres... | juraj-google-style |
def __init__(self, value_set_codes_table: Optional[bigquery.TableReference]=None, value_set_codes_definitions: Optional[fhir_package.FhirPackageManager]=None) -> None:
self._value_set_codes_table = value_set_codes_table
self._value_set_codes_definitions = value_set_codes_definitions
self._use_resource_alias... | Creates a BigQuerySqlInterpreter.
Args:
value_set_codes_table: The name of the database table containing value set
code definitions. Used when building SQL for memberOf expressions. If
given, value set definitions needed for memberOf expressions will be
retrieved from this table if they can not be found in
`value_set_... | github-repos |
def get(self, blocking=True):
if self.closed:
raise PoolAlreadyClosedError('Connection pool is already closed.')
if (not self.limiter.acquire(blocking=blocking)):
return None
c = None
try:
c = self.idle_conns.pop()
except IndexError:
try:
c = self.connect_... | Gets a connection.
Args:
blocking: Whether to block when max_size connections are already in use.
If false, may return None.
Returns:
A connection to the database.
Raises:
PoolAlreadyClosedError: if close() method was already called on
this pool. | codesearchnet |
def create_multiple_expectations(df, columns, expectation_type, *args, **kwargs):
expectation = getattr(df, expectation_type)
results = list()
for column in columns:
results.append(expectation(column, *args, **kwargs))
return results | Creates an identical expectation for each of the given columns with the specified arguments, if any.
Args:
df (great_expectations.dataset): A great expectations dataset object.
columns (list): A list of column names represented as strings.
expectation_type (string): The expectation type.
Raises:
KeyError if the provi... | codesearchnet |
def load_model_from_hdf5(filepath, custom_objects=None, compile=True):
if h5py is None:
raise ImportError('`load_model` requires h5py.')
if not custom_objects:
custom_objects = {}
opened_new_file = not isinstance(filepath, h5py.File)
if opened_new_file:
f = h5py.File(filepath, mo... | Loads a model saved via `save_model_to_hdf5`.
Args:
filepath: One of the following:
- String, path to the saved model
- `h5py.File` object from which to load the model
custom_objects: Optional dictionary mapping names
(strings) to custom classes or functions to be
considered during deserialization.
compile: Boolean, w... | github-repos |
def _setup_transitions(tdef, states, prev=()):
trs = list(prev)
for transition in tdef:
if (len(transition) == 3):
(name, source, target) = transition
if (is_string(source) or isinstance(source, State)):
source = [source]
source = [states[src] for src ... | Create a TransitionList object from a 'transitions' Workflow attribute.
Args:
tdef: list of transition definitions
states (StateList): already parsed state definitions.
prev (TransitionList): transition definitions from a parent.
Returns:
TransitionList: the list of transitions defined in the 'tdef' argument. | codesearchnet |
def find_next_punctuation(text: str, start_idx=0):
for i in range(start_idx, len(text)):
if text[i] in ['.', '?', '!', '\n']:
return i
return None | Find the index of the next punctuation mark.
Args:
text (`str`):
String to examine
start_idx (`int`, *optional*)
Index where to start | github-repos |
def from_sub_model_configs(cls, semantic_config: BarkSemanticConfig, coarse_acoustics_config: BarkCoarseConfig, fine_acoustics_config: BarkFineConfig, codec_config: PretrainedConfig, **kwargs):
return cls(semantic_config=semantic_config.to_dict(), coarse_acoustics_config=coarse_acoustics_config.to_dict(), fine_acou... | Instantiate a [`BarkConfig`] (or a derived class) from bark sub-models configuration.
Returns:
[`BarkConfig`]: An instance of a configuration object | github-repos |
def _FormatHostname(self, event):
hostname = self._output_mediator.GetHostname(event)
return self._SanitizeField(hostname) | Formats the hostname.
Args:
event (EventObject): event.
Returns:
str: formatted hostname field. | juraj-google-style |
def _replace_deferred(self, arg, context):
if isinstance(arg, UnboundVariable):
return context[arg]
elif isinstance(arg, _DeferredLayer):
return arg._construct(context)
elif isinstance(arg, tuple):
return tuple((self._replace_deferred(x, context) for x in arg))
elif (isinst... | This replaces all deferred nodes (UnboundVariables and _DeferredLayers).
If arg is a sequence or a dict, then it's deferred values are also replaced.
Args:
arg: The argument to replace. If a list or a dict, then all items are also
replaced.
context: The context for this replacement.
Returns:
The replaced values or ar... | juraj-google-style |
def from_moy(cls, moy, leap_year=False):
if not leap_year:
num_of_minutes_until_month = (0, 44640, 84960, 129600, 172800, 217440,
260640, 305280, 349920, 393120, 437760,
480960, 525600)
else:
... | Create Ladybug Datetime from a minute of the year.
Args:
moy: An integer value 0 <= and < 525600 | juraj-google-style |
def _get_config_instance(group_or_term, session, **kwargs):
path = group_or_term._get_path()
cached = group_or_term._top._cached_configs.get(path)
if cached:
config = cached
created = False
else:
(config, created) = get_or_create(session, Config, **kwargs)
return (config, cre... | Finds appropriate config instance and returns it.
Args:
group_or_term (Group or Term):
session (Sqlalchemy session):
kwargs (dict): kwargs to pass to get_or_create.
Returns:
tuple of (Config, bool): | codesearchnet |
def intersects(self, rect, edges=False):
if ((self.bottom > rect.top) or (self.top < rect.bottom) or (self.left > rect.right) or (self.right < rect.left)):
return False
if (not edges):
if ((self.bottom == rect.top) or (self.top == rect.bottom) or (self.left == rect.right) or (self.right == rect.... | Detect intersections between this rectangle and rect.
Args:
rect (Rectangle): Rectangle to test for intersections.
edges (bool): Accept edge touching rectangles as intersects or not
Returns:
bool: True if the rectangles intersect, False otherwise | codesearchnet |
def DeregisterMountPoint(cls, mount_point):
if mount_point not in cls._mount_points:
raise KeyError('Mount point: {0:s} not set.'.format(mount_point))
del cls._mount_points[mount_point] | Deregisters a path specification mount point.
Args:
mount_point (str): mount point identifier.
Raises:
KeyError: if the corresponding mount point is not set. | juraj-google-style |
def path_get_origin(p: tcod.path.AStar) -> Tuple[(int, int)]:
x = ffi.new('int *')
y = ffi.new('int *')
lib.TCOD_path_get_origin(p._path_c, x, y)
return (x[0], y[0]) | Get the current origin position.
This point moves when :any:`path_walk` returns the next x,y step.
Args:
p (AStar): An AStar instance.
Returns:
Tuple[int, int]: An (x, y) point. | codesearchnet |
def check_required_tags_compliance(self, resource):
missing_tags = []
notes = []
resource_tags = {tag.key.lower(): tag.value for tag in resource.tags}
if resource.resource_type in self.alert_schedule:
target_accounts = self.alert_schedule[resource.resource... | Check whether a resource is compliance
Args:
resource: A single resource
Returns:
`(list, list)`
A tuple contains missing tags (if there were any) and notes | juraj-google-style |
def is_date(v) -> (bool, date):
if isinstance(v, date):
return True, v
try:
reg = r'^([0-9]{4})(?:-(0[1-9]|1[0-2])(?:-(0[1-9]|[1-2][0-9]|3[0-1])(?:T' \
r'([0-5][0-9])(?::([0-5][0-9])(?::([0-5][0-9]))?)?)?)?)?$'
match = re.match(reg, v)
... | Boolean function for checking if v is a date
Args:
v:
Returns: bool | juraj-google-style |
def clinvar_export(store, institute_id, case_name, variant_id):
(institute_obj, case_obj) = institute_and_case(store, institute_id, case_name)
pinned = [(store.variant(variant_id) or variant_id) for variant_id in case_obj.get('suspects', [])]
variant_obj = store.variant(variant_id)
return dict(today=str... | Gather the required data for creating the clinvar submission form
Args:
store(scout.adapter.MongoAdapter)
institute_id(str): Institute ID
case_name(str): case ID
variant_id(str): variant._id
Returns:
a dictionary with all the required data (case and variant level) to pre-fill in fields in the clinvar submission form | codesearchnet |
class ZoeDepthPreActResidualLayer(nn.Module):
def __init__(self, config):
super().__init__()
self.use_batch_norm = config.use_batch_norm_in_fusion_residual
use_bias_in_fusion_residual = config.use_bias_in_fusion_residual if config.use_bias_in_fusion_residual is not None else not self.use_ba... | ResidualConvUnit, pre-activate residual unit.
Args:
config (`[ZoeDepthConfig]`):
Model configuration class defining the model architecture. | github-repos |
def send(url, data):
validate(data)
return requests.post(url, json=data) | Sends an incoming message
Args:
url(str): the incoming hook url
data(dict): the sending data
Returns:
requests.Response | juraj-google-style |
def _open_streaming_interface(self, connection_id, callback):
try:
context = self.connections.get_context(connection_id)
except ArgumentError:
callback(connection_id, self.id, False, "Could not find connection information")
return
self._logger.info(... | Enable streaming interface for this IOTile device
Args:
connection_id (int): The unique identifier for the connection
callback (callback): Callback to be called when this command finishes
callback(conn_id, adapter_id, success, failure_reason) | juraj-google-style |
async def set_typing(self, typing=hangouts_pb2.TYPING_TYPE_STARTED):
try:
await self._client.set_typing(
hangouts_pb2.SetTypingRequest(
request_header=self._client.get_request_header(),
conversation_id=hangouts_pb2.Conversatio... | Set your typing status in this conversation.
Args:
typing: (optional) ``TYPING_TYPE_STARTED``, ``TYPING_TYPE_PAUSED``,
or ``TYPING_TYPE_STOPPED`` to start, pause, or stop typing,
respectively. Defaults to ``TYPING_TYPE_STARTED``.
Raises:
.NetworkError: If typing status cannot be set. | juraj-google-style |
def universal_transformer_basic(layer_inputs, step, hparams, ffn_unit, attention_unit):
(state, inputs, memory) = tf.unstack(layer_inputs, num=None, axis=0, name='unstack')
new_state = step_preprocess(state, step, hparams)
for i in range(hparams.num_inrecurrence_layers):
with tf.variable_scope(('rec... | Basic Universal Transformer.
This model is pretty similar to the vanilla transformer in which weights are
shared between layers. For some tasks, this simple idea brings a
generalization that is not achievable by playing with the size of the model
or drop_out parameters in the vanilla transformer.
Args:
layer_inputs:
... | codesearchnet |
def __call__(self, inputs, state, scope=None):
if scope is not None:
with vs.variable_scope(scope, custom_getter=self._rnn_get_variable) as scope:
return super(RNNCell, self).__call__(inputs, state, scope=scope)
else:
scope_attrname = 'rnncell_scope'
scope = getattr(self, sco... | Run this RNN cell on inputs, starting from the given state.
Args:
inputs: `2-D` tensor with shape `[batch_size, input_size]`.
state: if `self.state_size` is an integer, this should be a `2-D Tensor`
with shape `[batch_size, self.state_size]`. Otherwise, if
`self.state_size` is a tuple of integers, this should be a tu... | github-repos |
def _parse_header(self, data):
(magic, word_size, byte_order, version, osabi, abi_version, _), data = \
unpack('4sBBBBB7s', data[:16]), data[16:]
assert magic == self._ELF_MAGIC, 'Missing ELF magic'
assert word_size in (1, 2), 'Invalid word size'
assert byte_order ... | Parse the ELF header in ``data`` and populate the properties.
Args:
data(bytes): The ELF header. | juraj-google-style |
def _prepare_init_params_from_job_description(cls, job_details):
init_params = dict()
init_params['model_name'] = job_details['ModelName']
init_params['instance_count'] = job_details['TransformResources']['InstanceCount']
init_params['instance_type'] = job_details['TransformResources']['InstanceType']
... | Convert the transform job description to init params that can be handled by the class constructor
Args:
job_details (dict): the returned job details from a describe_transform_job API call.
Returns:
dict: The transformed init_params | codesearchnet |
def __init__(self, name=None, settings=None, instruments=None, scripts=None, log_function=None, data_path=None):
QObject.__init__(self)
self._script_class = self.__class__.__name__
if name is None:
name = self.__class__.__name__
self.name = name
self._ins... | executes scripts and stores script parameters and settings
Args:
name (optional): name of script, if not provided take name of function
settings (optional): a Parameter object that contains all the information needed in the script
instruments (optional): instruments used in the script
scripts (optional): sub_scripts ... | juraj-google-style |
def stop_standing_subprocess(proc):
logging.debug('Stopping standing subprocess %d', proc.pid)
_kill_process_tree(proc)
if proc.stdout:
proc.stdout.close()
if proc.stderr:
proc.stderr.close()
proc.wait()
logging.debug('Stopped standing subprocess %d', proc.pid) | Stops a subprocess started by start_standing_subprocess.
Before killing the process, we check if the process is running, if it has
terminated, Error is raised.
Catches and ignores the PermissionError which only happens on Macs.
Args:
proc: Subprocess to terminate.
Raises:
Error: if the subprocess could not be stopp... | github-repos |
def __init__(self, name='', declarations=None):
scopedef.scopedef_t.__init__(self, name)
if not declarations:
declarations = []
self._declarations = declarations | Creates an object that describes a C++ namespace declaration.
Args:
name (str): name of the namespace
declarations (list[declaration_t]): list of declarations | juraj-google-style |
def type_decisioner(marc_xml, mono_callback, multimono_callback, periodical_callback):
marc_xml = _read_content_or_path(marc_xml)
record = MARCXMLRecord(marc_xml)
if (record.is_monographic or record.is_single_unit):
return mono_callback()
elif record.is_multi_mono:
return multimono_callb... | Detect type of the `marc_xml`. Call proper callback.
Args:
marc_xml (str): Filename or XML string. Don't use ``\\n`` in case of
filename.
mono_callback (fn reference): Callback in case of monographic
publications.
multimono_callback (fn reference): Callback used in case of
multi-monographic publications.
periodical_ca... | codesearchnet |
def _deserialize_audience(audience_map):
for audience in audience_map.values():
condition_structure, condition_list = condition_helper.loads(audience.conditions)
audience.__dict__.update({
'conditionStructure': condition_structure,
'conditionList': condition_list
})
retu... | Helper method to de-serialize and populate audience map with the condition list and structure.
Args:
audience_map: Dict mapping audience ID to audience object.
Returns:
Dict additionally consisting of condition list and structure on every audience object. | juraj-google-style |
def call_servo(examples, serving_bundle):
parsed_url = urlparse('http:
channel = implementations.insecure_channel(parsed_url.hostname,
parsed_url.port)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
if serving_bundle.use_predict:
re... | Send an RPC request to the Servomatic prediction service.
Args:
examples: A list of examples that matches the model spec.
serving_bundle: A `ServingBundle` object that contains the information to
make the serving request.
Returns:
A ClassificationResponse or RegressionResponse proto. | juraj-google-style |
def whatIfOrder(self, contract: Contract, order: Order) -> OrderState:
return self._run(self.whatIfOrderAsync(contract, order)) | Retrieve commission and margin impact without actually
placing the order. The given order will not be modified in any way.
This method is blocking.
Args:
contract: Contract to test.
order: Order to test. | juraj-google-style |
def to_ast(self):
if self == STANDARD_OPTIONS:
return parser.parse_expression('ag__.STD')
template = '\n ag__.ConversionOptions(\n recursive=recursive_val,\n user_requested=user_requested_val,\n optional_features=optional_features_val,\n internal_convert_user_cod... | Returns a representation of this object as an AST node.
The AST node encodes a constructor that would create an object with the
same contents.
Returns:
ast.Node | github-repos |
def GetFeatureService(self, itemId, returnURLOnly=False):
admin = None
item = None
try:
admin = arcrest.manageorg.Administration(securityHandler=self._securityHandler)
if (self._securityHandler.valid == False):
self._valid = self._securityHandler.valid
self._message =... | Obtains a feature service by item ID.
Args:
itemId (str): The feature service's item ID.
returnURLOnly (bool): A boolean value to return the URL of the feature service. Defaults to ``False``.
Returns:
When ``returnURLOnly`` is ``True``, the URL of the feature service is returned.
When ``False``, the result from :py:f... | codesearchnet |
def limits(self, clip_negative=True):
min, max = dtype_range[self.as_numpy_dtype]
if clip_negative:
min = 0
return min, max | Return intensity limits, i.e. (min, max) tuple, of the dtype.
Args:
clip_negative : bool, optional
If True, clip the negative range (i.e. return 0 for min intensity)
even if the image dtype allows negative values.
Returns
min, max : tuple
Lower and upper intensity limits. | juraj-google-style |
def EnablePlugins(self, plugin_includes):
super(SyslogParser, self).EnablePlugins(plugin_includes)
self._plugin_by_reporter = {}
for plugin in self._plugins:
self._plugin_by_reporter[plugin.REPORTER] = plugin | Enables parser plugins.
Args:
plugin_includes (list[str]): names of the plugins to enable, where None
or an empty list represents all plugins. Note that the default plugin
is handled separately. | juraj-google-style |
def find_elements_by_name(self, name, update=False) -> Elements:
return self.find_elements(by=By.NAME, value=name, update=update) | Finds multiple elements by name.
Args:
name: The name of the elements to be found.
update: If the interface has changed, this option should be True.
Returns:
A list with elements if any was found. An empty list if not.
Raises:
NoSuchElementException - If the element wasn't found.
Usage:
elements = driver.find_eleme... | codesearchnet |
def _parse_description(self, config):
value = None
match = re.search('description (.+)$', config, re.M)
if match:
value = match.group(1)
return dict(description=value) | Scans the specified config block and returns the description value
Args:
config (str): The interface config block to scan
Returns:
dict: Returns a dict object with the description value retrieved
from the config block. If the description value is not
configured, None is returned as the value. The returned dict
is i... | codesearchnet |
def __init__(self, num_buckets: int, lower: float, upper: float):
if num_buckets < 2:
raise ValueError(f'num_buckets is {num_buckets}, must be at least 2 for simulated quantization.')
self.num_buckets = num_buckets
self.lower = lower
self.upper = upper | Simulated quantizaiton configuration.
Args:
num_buckets: The number of quantization buckets, must be atleast 2.
lower: The lower bound for the quantization range.
upper: The upper bound for the quantization range.
Returns:
`QuantizationConfig`.
Raises:
ValueError: if `num_buckets` is less than 2. | github-repos |
def set_config(self, key, value):
keyname = "config:" + key
self.kvstore.set(keyname, value) | Set a persistent config key to a value, stored in the registry
Args:
key (string): The key name
value (string): The key value | juraj-google-style |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.