code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def forward(self, hidden: torch.Tensor):
residual = hidden
hidden = self.norm(hidden)
hidden = self.mlp(hidden)
if self.gated_attn:
hidden = self.gating_block(hidden)
out = hidden + residual
return out | Args:
hidden (`torch.Tensor` of shape `(batch_size, num_patches, d_model)`):
Input tensor to the layer.
Returns:
`torch.Tensor`: Transformed tensor. | github-repos |
def loop(self, xy, yx):
if len(xy) > 0:
self.iter += self.runs_per_iter
if self.iter < 2:
return True
t_test, self.p_value = ttest_ind(xy, yx, equal_var=False)
if self.p_value > self.threshold and self.iter < self.max_iter:
return True
... | Tests the loop condition based on the new results and the
parameters.
Args:
xy (list): list containing all the results for one set of samples
yx (list): list containing all the results for the other set.
Returns:
bool: True if the loop has to continue, False otherwise. | juraj-google-style |
def visit_boolean_op(self, boolean_logic: _evaluation.BooleanOperatorNode) -> _sql_data_types.Select:
lhs_result = self.visit(boolean_logic.left)
rhs_result = self.visit(boolean_logic.right)
if lhs_result.sql_data_type != _sql_data_types.Boolean:
lhs_result = lhs_result.is_not_null()
if rhs_resu... | Translates a FHIRPath Boolean logic operation to Spark SQL.
Note that evaluation for Boolean logic is only supported for Boolean
operands of scalar cardinality.
Args:
boolean_logic: The FHIRPath AST `BooleanLogic` node.
Returns:
A compiled Spark SQL expression. | github-repos |
def swd_read32(self, offset):
value = self._dll.JLINK_SWD_GetU32(offset)
return ctypes.c_uint32(value).value | Gets a unit of ``32`` bits from the input buffer.
Args:
self (JLink): the ``JLink`` instance
offset (int): the offset (in bits) from which to start reading
Returns:
The integer read from the input buffer. | juraj-google-style |
def restore_state(self, state, name=None):
if self._reader_ref.dtype == dtypes.resource:
return gen_io_ops.reader_restore_state_v2(self._reader_ref, state, name=name)
else:
return gen_io_ops.reader_restore_state(self._reader_ref, state, name=name) | Restore a reader to a previously saved state.
Not all Readers support being restored, so this can produce an
Unimplemented error.
Args:
state: A string Tensor.
Result of a SerializeState of a Reader with matching type.
name: A name for the operation (optional).
Returns:
The created Operation. | github-repos |
def getsource(classorfunc):
if _isbuiltin(classorfunc):
return ''
try:
source = inspect.getsource(classorfunc)
except TypeError:
source = getsourcefallback(classorfunc)
declaration = []
lines = source.splitlines()
if (PY2 and (not isinstance(source, unicode))):
en... | Return the source code for a class or function.
Notes:
Returned source will not include any decorators for the object.
This will only return the explicit declaration of the object, not any dependencies
Args:
classorfunc (type or function): the object to get the source code for
Returns:
str: text of source code (with... | codesearchnet |
def __init__(self, sdat):
self._isteps = {}
self._all_isteps_known = False
super().__init__(sdat) | Initialization of instances:
Args:
sdat (:class:`StagyyData`): the StagyyData instance owning the
:class:`_Snaps` instance.
Attributes:
sdat (:class:`StagyyData`): the StagyyData instance owning the
:class:`_Snaps` instance. | juraj-google-style |
def get_path(self, origX, origY, destX, destY):
return super(AStar, self).get_path(origX, origY, destX, destY) | Get the shortest path from origXY to destXY.
Returns:
List[Tuple[int, int]]: Returns a list walking the path from orig
to dest.
This excludes the starting point and includes the destination.
If no path is found then an empty list is returned. | codesearchnet |
def train_model(self, train_op, cost_to_log, num_steps, feed_vars=(), feed_data=None, print_every=100):
costs = [train_op]
if (isinstance(cost_to_log, collections.Sequence) and (not isinstance(cost_to_log, six.string_types))):
costs.extend(cost_to_log)
else:
costs.append(cost_to_log)
ret... | Trains the given model.
Args:
train_op: The training operation.
cost_to_log: A cost to log.
num_steps: Number of batches to run.
feed_vars: A list or tuple of the variables that will be fed.
feed_data: A generator that produces tuples of the same length as
feed_vars.
print_every: Print and save every so many steps.
Re... | codesearchnet |
def _on_status_message(self, sequence, topic, message):
self._logger.debug("Received message on (topic=%s): %s" % (topic, message))
try:
conn_key = self._find_connection(topic)
except ArgumentError:
self._logger.warn("Dropping message that does not correspond w... | Process a status message received
Args:
sequence (int): The sequence number of the packet received
topic (string): The topic this message was received on
message (dict): The message itself | juraj-google-style |
def get_variables_in_scope(scope, collection=tf.GraphKeys.TRAINABLE_VARIABLES):
scope_name = get_variable_scope_name(scope)
if scope_name:
scope_name = (re.escape(scope_name) + '/')
return tuple(tf.get_collection(collection, scope_name)) | Returns a tuple `tf.Variable`s in a scope for a given collection.
Args:
scope: `tf.VariableScope` or string to retrieve variables from.
collection: Collection to restrict query to. By default this is
`tf.Graphkeys.TRAINABLE_VARIABLES`, which doesn't include non-trainable
variables such as moving averages.
Returns:
A ... | codesearchnet |
def decode_body(headers: MutableMapping, body: bytes) -> dict:
(type_, encoding) = parse_content_type(headers)
decoded_body = body.decode(encoding)
if (type_ == 'application/json'):
payload = json.loads(decoded_body)
elif (decoded_body == 'ok'):
payload = {'ok': True}
else:
p... | Decode the response body
For 'application/json' content-type load the body as a dictionary
Args:
headers: Response headers
body: Response body
Returns:
decoded body | codesearchnet |
def get_model(self, model, model_id):
return self._store.find_record(self._get_model_class(model), int(model_id)) | Get a single model from the server.
Args:
model (string): The class as a string.
model_id (string): The integer ID as a string.
Returns:
:class:`cinder_data.model.CinderModel`: A instance of the model. | juraj-google-style |
def replace_all(self, replacements):
for override in replacements:
assert isinstance(override, PTransformOverride)
self._replace(override)
for override in replacements:
self._check_replacement(override) | Dynamically replaces PTransforms in the currently populated hierarchy.
Currently this only works for replacements where input and output types
are exactly the same.
TODO: Update this to also work for transform overrides where input and
output types are different.
Args:
replacements (List[~apache_beam.pipeline.PTrans... | github-repos |
def make_fout(fout='./tmp', fmt='pcap'):
if (fmt == 'pcap'):
from pcapkit.dumpkit import PCAP as output
elif (fmt == 'plist'):
from dictdumper import PLIST as output
elif (fmt == 'json'):
from dictdumper import JSON as output
elif (fmt == 'tree'):
from dictdumper import T... | Make root path for output.
Positional arguments:
* fout -- str, root path for output
* fmt -- str, output format
Returns:
* output -- dumper of specified format | codesearchnet |
def find_template_filename(self, template_name):
def next_file():
filename = (self.path / template_name)
(yield filename)
try:
exts = self.default_file_extensions
except AttributeError:
return
strfilename = str(filename)
for ext in exts:
... | Searches for a file matching the given template name.
If found, this method returns the pathlib.Path object of the found
template file.
Args:
template_name (str): Name of the template, with or without a file
extension.
Returns:
pathlib.Path: Path to the matching filename. | codesearchnet |
def swd_sync(self, pad=False):
if pad:
self._dll.JLINK_SWD_SyncBytes()
else:
self._dll.JLINK_SWD_SyncBits()
return None | Causes a flush to write all data remaining in output buffers to SWD
device.
Args:
self (JLink): the ``JLink`` instance
pad (bool): ``True`` if should pad the data to full byte size
Returns:
``None`` | codesearchnet |
def set_viewbox(self, x, y, w, h):
self.attributes['viewBox'] = "%s %s %s %s" % (x, y, w, h)
self.attributes['preserveAspectRatio'] = 'none' | Sets the origin and size of the viewbox, describing a virtual view area.
Args:
x (int): x coordinate of the viewbox origin
y (int): y coordinate of the viewbox origin
w (int): width of the viewbox
h (int): height of the viewbox | juraj-google-style |
def dropout(x, keep_prob, noise_shape=None, name=None):
noise_shape = convert_to_shape(noise_shape)
if noise_shape is None:
noise_shape = x.shape
with tf.variable_scope(name, default_name="dropout"):
if keep_prob == 1.0:
return x
noise = cast(less(random_uniform(
x.mesh, noise_shape, ... | Dropout layer.
Args:
x: a Tensor
keep_prob: a float between 0.0 and 1.0
noise_shape: an optional Shape (a subset of x.shape)
name: an optional string
Returns:
a Tensor | juraj-google-style |
def create_chapter_from_url(self, url, title=None):
try:
request_object = requests.get(url, headers=self.request_headers, allow_redirects=False)
except (requests.exceptions.MissingSchema, requests.exceptions.ConnectionError):
raise ValueError(('%s is an invalid url or no network connection' % ur... | Creates a Chapter object from a url. Pulls the webpage from the
given url, sanitizes it using the clean_function method, and saves
it as the content of the created chapter. Basic webpage loaded
before any javascript executed.
Args:
url (string): The url to pull the content of the created Chapter
from
title (Option[str... | codesearchnet |
def _verify_and_get_subgroup_size(self, group_assignment, num_shards):
if not group_assignment:
return None
if not (isinstance(group_assignment, list) and all((isinstance(i, list) for i in group_assignment))):
raise ValueError(f'Argument `group_assignment` must be a list of lists. Received: {gro... | Verify group_assignment and get the subgroup size".
Args:
group_assignment: list of group ids for applying the optimizer
to subgroups.
num_shards: The number of TPU shards.
Returns:
The size of one subgroup in group_assignment.
Raises:
ValueError: If group_assignment is invalid. | github-repos |
def mtr_tr_dense(sz):
n = 2 ** sz
hparams = mtf_bitransformer_base()
hparams.d_model = 1024
hparams.max_length = 256
hparams.batch_size = 128
hparams.d_ff = int(4096 * n)
hparams.d_kv = 128
hparams.encoder_num_heads = int(8 * n)
hparams.decoder_num_heads = int(8 * n)
hparams.learning_rate_deca... | Series of machine translation models.
All models are trained on sequences of 256 tokens.
You can use the dataset translate_enfr_wmt32k_packed.
154000 steps = 3 epochs.
Args:
sz: an integer
Returns:
a hparams | juraj-google-style |
def sample_id(self, lon):
if self.grid == 'WAC':
sample = np.rint(float(self.SAMPLE_PROJECTION_OFFSET) + 1.0 +
(lon * np.pi / 180.0 - float(self.CENTER_LONGITUDE)) *
self.A_AXIS_RADIUS *
np.cos(self.CENTE... | Return the corresponding sample
Args:
lon (int): longidute in degree
Returns:
Correponding sample | juraj-google-style |
def shutdown(cluster_info, queues=['input']):
def _shutdown(iter):
host = util.get_ip_address()
executor_id = util.read_executor_id()
mgr = _get_manager(cluster_info, host, executor_id)
for node in cluster_info:
if node['host'] == host and node['executor_id'] == executor_id:
... | Stops all TensorFlow nodes by feeding ``None`` into the multiprocessing.Queues.
Args:
:cluster_info: node reservation information for the cluster (e.g. host, executor_id, pid, ports, etc).
:queues: *INTERNAL_USE*
Returns:
A nodeRDD.mapPartitions() function | juraj-google-style |
def from_string(cls, key, key_id=None):
key = _helpers.from_bytes(key)
(marker_id, key_bytes) = pem.readPemBlocksFromFile(six.StringIO(key), _PKCS1_MARKER, _PKCS8_MARKER)
if (marker_id == 0):
private_key = rsa.key.PrivateKey.load_pkcs1(key_bytes, format='DER')
elif (marker_id == 1):
(key... | Construct an Signer instance from a private key in PEM format.
Args:
key (str): Private key in PEM format.
key_id (str): An optional key id used to identify the private key.
Returns:
google.auth.crypt.Signer: The constructed signer.
Raises:
ValueError: If the key cannot be parsed as PKCS#1 or PKCS#8 in
PEM format. | codesearchnet |
def AsCode(self, indent_per_depth=2):
indent = ' ' * indent_per_depth * self.depth
tokens_str = ' '.join((tok.value for tok in self._tokens))
return indent + tokens_str | Return a "code" representation of this line.
The code representation shows how the line would be printed out as code.
TODO(eliben): for now this is rudimentary for debugging - once we add
formatting capabilities, this method will have other uses (not all tokens
have spaces around them, for example).
Arguments:
inden... | github-repos |
def real(input, name=None):
with ops.name_scope(name, 'Real', [input]) as name:
input = ops.convert_to_tensor(input, name='input')
if input.dtype.is_complex:
real_dtype = input.dtype.real_dtype
return gen_math_ops.real(input, Tout=real_dtype, name=name)
elif input.dty... | Returns the real part of a complex (or real) tensor.
Given a tensor `input`, this operation returns a tensor of type `float` that
is the real part of each element in `input` considered as a complex number.
For example:
```python
x = tf.constant([-2.25 + 4.75j, 3.25 + 5.75j])
tf.math.real(x) # [-2.25, 3.25]
```
If ... | github-repos |
def _gen_condition(cls, initial, new_public_keys):
try:
threshold = len(new_public_keys)
except TypeError:
threshold = None
if (isinstance(new_public_keys, list) and (len(new_public_keys) > 1)):
ffill = ThresholdSha256(threshold=threshold)
reduce(cls._gen_condition, new_publi... | Generates ThresholdSha256 conditions from a list of new owners.
Note:
This method is intended only to be used with a reduce function.
For a description on how to use this method, see
:meth:`~.Output.generate`.
Args:
initial (:class:`cryptoconditions.ThresholdSha256`):
A Condition representing the overall root.
new_pu... | codesearchnet |
def ParseText(self, text, eof=True):
lines = []
if text:
lines = text.splitlines()
for line in lines:
self._CheckLine(line)
if (self._cur_state_name in ('End', 'EOF')):
break
if ((self._cur_state_name != 'End') and ('EOF' not in self.states) and eof):
self._Ap... | Passes CLI output through FSM and returns list of tuples.
First tuple is the header, every subsequent tuple is a row.
Args:
text: (str), Text to parse with embedded newlines.
eof: (boolean), Set to False if we are parsing only part of the file.
Suppresses triggering EOF state.
Raises:
TextFSMError: An error occurred... | codesearchnet |
def outer(vector1, vector2=None):
if (vector2 is None):
vector2 = np.array(vector1).conj()
else:
vector2 = np.array(vector2).conj()
return np.outer(vector1, vector2) | Construct the outer product of two vectors.
The second vector argument is optional, if absent the projector
of the first vector will be returned.
Args:
vector1 (ndarray): the first vector.
vector2 (ndarray): the (optional) second vector.
Returns:
np.array: The matrix |v1><v2|. | codesearchnet |
def truncate(text, length=255):
lines = []
i = 0
while i < len(text) - 1:
try:
lines.append(text[i:i+length])
i += length
except IndexError as e:
lines.append(text[i:])
return lines | Splits the message into a list of strings of of length `length`
Args:
text (str): The text to be divided
length (int, optional): The length of the chunks of text. \
Defaults to 255.
Returns:
list: Text divided into chunks of length `length` | juraj-google-style |
def close(self, suppress_warning: bool = False) -> None:
if self._file is None:
if not suppress_warning:
logging.warn("Connection to %s is already closed", self.filename)
else:
self._file.close()
self._file = None
self.layers = None
self.ra = None
self.row_attrs = None
self.c... | Close the connection. After this, the connection object becomes invalid. Warns user if called after closing.
Args:
suppress_warning: Suppresses warning message if True (defaults to false) | juraj-google-style |
def ProduceExtractionWarning(self, message, path_spec=None):
if (not self._storage_writer):
raise RuntimeError('Storage writer not set.')
if ((not path_spec) and self._file_entry):
path_spec = self._file_entry.path_spec
parser_chain = self.GetParserChain()
warning = warnings.ExtractionWa... | Produces an extraction warning.
Args:
message (str): message of the warning.
path_spec (Optional[dfvfs.PathSpec]): path specification, where None
will use the path specification of current file entry set in
the mediator.
Raises:
RuntimeError: when storage writer is not set. | codesearchnet |
def from_timestamp_pb(cls, stamp):
microseconds = int(stamp.seconds * 1e6)
bare = from_microseconds(microseconds)
return cls(
bare.year,
bare.month,
bare.day,
bare.hour,
bare.minute,
bare.second,
nanosec... | Parse RFC 3339-compliant timestamp, preserving nanoseconds.
Args:
stamp (:class:`~google.protobuf.timestamp_pb2.Timestamp`): timestamp message
Returns:
:class:`DatetimeWithNanoseconds`:
an instance matching the timestamp message | juraj-google-style |
def exists(self, path=None, client_kwargs=None, assume_exists=None):
try:
self.head(path, client_kwargs)
except ObjectNotFoundError:
return False
except ObjectPermissionError:
if (assume_exists is None):
raise
return assume_exists
return True | Return True if path refers to an existing path.
Args:
path (str): Path or URL.
client_kwargs (dict): Client arguments.
assume_exists (bool or None): This value define the value to return
in the case there is no enough permission to determinate the
existing status of the file. If set to None, the permission
exception i... | codesearchnet |
def _maybe_init_tags(self, run_id, tag_to_metadata):
cursor = self._db.cursor()
cursor.execute('SELECT tag_name, tag_id FROM Tags WHERE run_id = ?',
(run_id,))
tag_to_id = {row[0]: row[1] for row in cursor.fetchall()
if row[0] in tag_to_metadata}
new_ta... | Returns a tag-to-ID map for the given tags, creating rows if needed.
Args:
run_id: the ID of the run to which these tags belong.
tag_to_metadata: map of tag name to SummaryMetadata for the tag. | juraj-google-style |
def run_in_v1_v2(device_to_use: Optional[str]=None, assert_no_eager_garbage: bool=False) -> Callable[[Callable[..., Any]], Callable[..., None]]:
def decorator(f: Callable[..., Any]) -> Callable[..., None]:
decorator_tag = 'wrapped_with_v1_v2_decorator'
if hasattr(f, decorator_tag):
retu... | Execute the decorated test in v1 and v2 modes.
The overall execution is similar to that of `run_in_graph_and_eager_mode`.
Args:
device_to_use: A string in the following format: "/device:CPU:0".
assert_no_eager_garbage: If True, sets DEBUG_SAVEALL on the garbage
collector and asserts that no extra garbage has been cre... | github-repos |
def symlink(self, link_target, path, dir_fd=None):
link_target = self._path_with_dir_fd(link_target, self.symlink, dir_fd)
self.filesystem.create_symlink(path, link_target, create_missing_dirs=False) | Creates the specified symlink, pointed at the specified link target.
Args:
link_target: The target of the symlink.
path: Path to the symlink to create.
dir_fd: If not `None`, the file descriptor of a directory,
with `link_target` being relative to this directory.
New in Python 3.3.
Raises:
OSError: if the file alrea... | codesearchnet |
def convert_saved_model_v1(saved_model_path, exported_names, tags, lift_variables, include_variables_in_initializers, upgrade_legacy=True, show_debug_info=False):
return pywrap_mlir.experimental_convert_saved_model_v1_to_mlir(saved_model_path, exported_names, tags, lift_variables, include_variables_in_initializers,... | Converts a v1 SavedModel to MLIR module.
Args:
saved_model_path: Path to SavedModel.
exported_names: Names to export.
tags: MetaGraphDef to be loaded is identified by the supplied tags.
lift_variables: Whether to promote tf.VarHandleOp to resource arguments.
include_variables_in_initializers: Keeps the variables in in... | github-repos |
def _find_extraneous_saver_nodes(graph_def, saver_def):
nodes = {node_def.name: (set((tensor.get_op_name(x) for x in node_def.input)), node_def.op) for node_def in graph_def.node}
retain_scope_save = None
retain_scope_restore = None
if saver_def is not None:
save_op_name = tensor.get_op_name(sav... | Identifies any nodes in the graph_def related to unused Savers.
This approach assumes that each Saver is cleanly isolated in its own name
scope, so we need only identify the scopes associated with extraneous Savers
and return all the nodes in those scopes.
Args:
graph_def: a GraphDef proto to evaluate.
saver_def: a S... | github-repos |
def get_data_for_sensors(macs=[], search_duratio_sec=5, bt_device=''):
log.info('Get latest data for sensors. Stop with Ctrl+C.')
log.info('Stops automatically in %ss', search_duratio_sec)
log.info('MACs: %s', macs)
datas = dict()
for new_data in RuuviTagSensor._get_r... | Get lates data for sensors in the MAC's list.
Args:
macs (array): MAC addresses
search_duratio_sec (int): Search duration in seconds. Default 5
bt_device (string): Bluetooth device id
Returns:
dict: MAC and state of found sensors | juraj-google-style |
def discover(names=None, pattern=['*.py'], skip='efp', dry_run=False, blacklist=None, name_greps=None,
manual_reset=False, delete_history=False, max_devices=0,
continue_from=None, result_file='./result.json', auto_reboot=False, keep_explorer=False,
add_all_devices=False):
... | Discover all test cases and skip those passed
Args:
pattern (str): Pattern to match case modules, refer python's unittest
documentation for more details
skip (str): types cases to skip | juraj-google-style |
def wait_at_barrier(self, barrier_id, timeout_in_ms):
ensure_initialized()
pywrap_tfe.TFE_WaitAtBarrier(self._context_handle, barrier_id, timeout_in_ms) | Blocks until all coordinated tasks are at the barrier.
The barrier may fail if it times out or if one of the tasks is unhealthy.
Args:
barrier_id: Unique string identifying the barrier.
timeout_in_ms: Duration before the barrier times out and fails. | github-repos |
def enableSync(self, url, definition=None):
adminFS = AdminFeatureService(url=url, securityHandler=self._securityHandler)
cap = str(adminFS.capabilities)
existingDef = {}
enableResults = 'skipped'
if ('Sync' in cap):
return 'Sync is already enabled'
else:
capItems = cap.split(','... | Enables Sync capability for an AGOL feature service.
Args:
url (str): The URL of the feature service.
definition (dict): A dictionary containing valid definition values. Defaults to ``None``.
Returns:
dict: The result from :py:func:`arcrest.hostedservice.service.AdminFeatureService.updateDefinition`. | codesearchnet |
def _get(self, url, params=None):
if not params:
params = {}
params.update({'login': self.login, 'key': self.key})
response_json = requests.get(self.api_url + url, params).json()
return self._process_response(response_json) | Used by every other method, it makes a GET request with the given params.
Args:
url (str): relative path of a specific service (account_info, ...).
params (:obj:`dict`, optional): contains parameters to be sent in the GET request.
Returns:
dict: results of the response of the GET request. | juraj-google-style |
def __init__(self, tcex):
self._tcex = tcex
self._is_organization = False
self._notification_type = None
self._recipients = None
self._priority = 'Low' | Initialize the Class properties.
Args:
tcex (obj): An instance of TcEx object. | juraj-google-style |
def find_nearest_color_hexstr(hexdigits, color_table=None, method='euclid'):
triplet = []
try:
if len(hexdigits) == 3:
for digit in hexdigits:
digit = int(digit, 16)
triplet.append((digit * 16) + digit)
elif len(hexdigits) == 6:
triple... | Given a three or six-character hex digit string, return the nearest
color index.
Arguments:
hexdigits: a three/6 digit hex string, e.g. 'b0b', '123456'
Returns:
int, None: index, or None on error. | juraj-google-style |
def from_values_indices(cls, values, indices, populate=False, structure=None, voigt_rank=None, vsym=True, verbose=False):
indices = np.array(indices)
if voigt_rank:
shape = (([3] * (voigt_rank % 2)) + ([6] * (voigt_rank
else:
shape = (np.ceil((np.max((indices + 1), axis=0) / 3.0)) * 3)
... | Creates a tensor from values and indices, with options
for populating the remainder of the tensor.
Args:
values (floats): numbers to place at indices
indices (array-likes): indices to place values at
populate (bool): whether to populate the tensor
structure (Structure): structure to base population
or fit_to_structure... | codesearchnet |
def env_valid(env):
if env not in EFConfig.ENV_LIST:
raise ValueError("unknown env: {}; env must be one of: ".format(env) + ", ".join(EFConfig.ENV_LIST))
return True | Given an env, determine if it's valid
Args:
env: the env to check
Returns:
True if the env is valid
Raises:
ValueError with message if the env is not valid | juraj-google-style |
def proj_path(*path_parts):
path_parts = path_parts or ['.']
if not os.path.isabs(path_parts[0]):
proj_path = _find_proj_root()
if proj_path is not None:
path_parts = [proj_path] + list(path_parts)
return os.path.normpath(os.path.join(*path_parts)) | Return absolute path to the repo dir (root project directory).
Args:
path (str):
The path relative to the project root (pelconf.yaml).
Returns:
str: The given path converted to an absolute path. | juraj-google-style |
def fix_report(self, report, errors='drop', prefer='before'):
if (not isinstance(report, SignedListReport)):
raise ArgumentError('Report must be a SignedListReport', report=report)
if (errors not in ('drop',)):
raise ArgumentError("Unknown errors handler: {}, supported=['drop']".format(errors))
... | Perform utc assignment on all readings in a report.
The returned report will have all reading timestamps in UTC. This only
works on SignedListReport objects. Note that the report should
typically have previously been added to the UTC assigner using
add_report or no reference points from the report will be used.
Args... | codesearchnet |
def render_html(root, options=0, extensions=None):
if extensions is None:
extensions = _cmark.ffi.NULL
raw_result = _cmark.lib.cmark_render_html(
root, options, extensions)
return _cmark.ffi.string(raw_result).decode('utf-8') | Render a given syntax tree as HTML.
Args:
root (Any): The reference to the root node of the syntax tree.
options (int): The cmark options.
extensions (Any): The reference to the syntax extensions, generally
from :func:`parser_get_syntax_extensions`
Returns:
str: The rendered HTML. | juraj-google-style |
def _find_metric_value(session_or_group, metric_name):
for metric_value in session_or_group.metric_values:
if (metric_value.name.tag == metric_name.tag and
metric_value.name.group == metric_name.group):
return metric_value | Returns the metric_value for a given metric in a session or session group.
Args:
session_or_group: A Session protobuffer or SessionGroup protobuffer.
metric_name: A MetricName protobuffer. The metric to search for.
Returns:
A MetricValue protobuffer representing the value of the given metric or
None if no such metric ... | juraj-google-style |
def retry(self, **kwargs):
path = '%s/%s/retry' % (self.manager.path, self.get_id())
self.manager.gitlab.http_post(path) | Retry the job.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabJobRetryError: If the job could not be retried | juraj-google-style |
def __init__(self, agent, environment, repeat_actions=1, history=None, id_=0):
super(ParallelRunner, self).__init__(agent, environment, repeat_actions, history)
self.id = id_
self.current_timestep = None
self.episode_actions = []
self.num_parallel = self.agent.execu... | Initialize a single Runner object (one Agent/one Environment).
Args:
id_ (int): The ID of this Runner (for distributed TF runs). | juraj-google-style |
def setDirname(self, dirname):
sep = utils._getPathSep(dirname)
if not dirname.endswith(sep):
dirname += sep
self._dir = utils.asString(dirname) | Set a new directory name for the sequence.
Args:
dirname (str): the new directory name | juraj-google-style |
def slice_batch_indices(indices):
num_in_full_batch = num_full_batches * batch_size
first_k_indices = array_ops.slice(indices, [0], [num_in_full_batch])
first_k_indices = array_ops.reshape(first_k_indices, [num_full_batches, batch_size])
flat_dataset = dataset_ops.DatasetV2.from_tensor_slices(first_k_in... | Convert a Tensor of indices into a dataset of batched indices.
This step can be accomplished in several ways. The most natural is to
slice the Tensor in a Dataset map. (With a condition on the upper index to
handle the partial batch.) However it turns out that coercing the Tensor
into a shape which is divisible by the... | github-repos |
def WriteEventBody(self, event):
inode = getattr(event, 'inode', None)
if inode is None:
event.inode = 0
try:
message, _ = self._output_mediator.GetFormattedMessages(event)
except errors.WrongFormatter:
message = None
if message:
event.message = message
json_dict ... | Writes the body of an event object to the output.
Args:
event (EventObject): event. | juraj-google-style |
def getVariable(self, name):
return lock_and_call((lambda : Variable(self._impl.getVariable(name))), self._lock) | Get the variable with the corresponding name.
Args:
name: Name of the variable to be found.
Raises:
TypeError: if the specified variable does not exist. | codesearchnet |
def convert_gemm(params, w_name, scope_name, inputs, layers, weights, names):
print('Converting Linear ...')
if (names == 'short'):
tf_name = ('FC' + random_string(6))
elif (names == 'keep'):
tf_name = w_name
else:
tf_name = (w_name + str(random.random()))
bias_name = '{0}.bi... | Convert Linear.
Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers | codesearchnet |
def getUserSid(username):
if six.PY2:
username = _to_unicode(username)
domain = win32api.GetComputerName()
if username.find('\\') != -1:
domain = username.split('\\')[0]
username = username.split('\\')[-1]
domain = domain.upper()
return win32security.ConvertSidToStringS... | Get the Security ID for the user
Args:
username (str): The user name for which to look up the SID
Returns:
str: The user SID
CLI Example:
.. code-block:: bash
salt '*' user.getUserSid jsnuffy | juraj-google-style |
def imdb(limit=None, shuffle=True):
movie_review_url = 'http:
path = keras.utils.get_file(
'aclImdb.tar.gz', movie_review_url, extract=True)[:-7]
X_train, y_train = read_pos_neg_data(path, 'train', limit)
X_test, y_test = read_pos_neg_data(path, 'test', limit)
if shuffle:
... | Downloads (and caches) IMDB Moview Reviews. 25k training data, 25k test data
Args:
limit: get only first N items for each class
Returns:
[X_train, y_train, X_test, y_test] | juraj-google-style |
def _run(self, data, store, signal, context, *, success_callback=None, stop_callback=None, abort_callback=None):
if (data is None):
data = MultiTaskData()
data.add_dataset(self._name)
try:
if (self._callback_init is not None):
self._callback_init(data, store, signal, context)... | The internal run method that decorates the public run method.
This method makes sure data is being passed to and from the task.
Args:
data (MultiTaskData): The data object that has been passed from the
predecessor task.
store (DataStoreDocument): The persistent data store object that allows the
task to store data for... | codesearchnet |
def __readCommissioningLogs(self, durationInSeconds):
self.logThreadStatus = self.logStatus['running']
logs = Queue()
t_end = time.time() + durationInSeconds
while time.time() < t_end:
time.sleep(0.3)
if self.logThreadStatus == self.logStatus['pauseReq']... | read logs during the commissioning process
Args:
durationInSeconds: time duration for reading commissioning logs
Returns:
Commissioning logs | juraj-google-style |
def random(length: int = 8, chars: str = digits + ascii_lowercase) -> Iterator[str]:
while True:
yield "".join([choice(chars) for _ in range(length)]) | A random string.
Not unique, but has around 1 in a million chance of collision (with the default 8
character length). e.g. 'fubui5e6'
Args:
length: Length of the random string.
chars: The characters to randomly choose from. | juraj-google-style |
def incoming_args(self, nodeid):
_vars = self._vars
ep = self._eps[nodeid]
lbl = ep[2]
iv = ep[3].get(IVARG_ROLE)
in_args_list = []
if iv in _vars:
for role, nids in _vars[iv]['refs'].items():
if role != IVARG... | Return the arguments that target *nodeid*.
Valid arguments include regular variable arguments and scopal
(label-selecting or HCONS) arguments. MOD/EQ
links and intrinsic arguments are not included.
Args:
nodeid: the nodeid of the EP that is the arguments' target
Returns:
dict: `{source_nodeid: {rargname: value}}` | juraj-google-style |
def setSingleStep(self, singleStep):
if (not isinstance(singleStep, int)):
raise TypeError('Argument is not of type int')
self._singleStep = abs(singleStep)
return self._singleStep | setter to _singleStep. converts negativ values to positiv ones.
Args:
singleStep (int): new _singleStep value. converts negativ values to positiv ones.
Raises:
TypeError: If the given argument is not an integer.
Returns:
int or long: the absolute value of the given argument. | codesearchnet |
def __init__(self, parent=None, iconSize=QtCore.QSize(36, 36)):
super(DataTableWidget, self).__init__(parent)
self._iconSize = iconSize
self.initUi() | Constructs the object with the given parent.
Args:
parent (QObject, optional): Causes the objected to be owned
by `parent` instead of Qt. Defaults to `None`.
iconSize (QSize, optional): Size of edit buttons. Defaults to QSize(36, 36). | juraj-google-style |
def PushEvent(self, timestamp, event_data):
heap_values = (timestamp, event_data)
heapq.heappush(self._heap, heap_values)
self.data_size += len(event_data) | Pushes a serialized event onto the heap.
Args:
timestamp (int): event timestamp, which contains the number of
micro seconds since January 1, 1970, 00:00:00 UTC.
event_data (bytes): serialized event. | juraj-google-style |
def connected_client(self):
future = self.get_connected_client()
cb = functools.partial(self._connected_client_release_cb, future)
return ContextManagerFuture(future, cb) | Returns a ContextManagerFuture to be yielded in a with statement.
Returns:
A ContextManagerFuture object.
Examples:
>>> with (yield pool.connected_client()) as client:
# client is a connected tornadis.Client instance
# it will be automatically released to the pool thanks to
# the "with" keyword
reply = yield client.c... | codesearchnet |
def _record_purchase(sailthru_client, email, item, purchase_incomplete, message_id, options):
try:
sailthru_response = sailthru_client.purchase(email, [item],
incomplete=purchase_incomplete, message_id=message_id,
... | Record a purchase in Sailthru
Arguments:
sailthru_client (object): SailthruClient
email (str): user's email address
item (dict): Sailthru required information about the course
purchase_incomplete (boolean): True if adding item to shopping cart
message_id (str): Cookie used to identify marketing campaign
options (dict)... | juraj-google-style |
def generate_enum_doc(enum_descriptor, locations, path, name_prefix=''):
print(make_subsection((name_prefix + enum_descriptor.name)))
location = locations[path]
if location.HasField('leading_comments'):
print(textwrap.dedent(location.leading_comments))
row_tuples = []
for (value_index, value... | Generate doc for an enum.
Args:
enum_descriptor: descriptor_pb2.EnumDescriptorProto instance for enum
to generate docs for.
locations: Dictionary of location paths tuples to
descriptor_pb2.SourceCodeInfo.Location instances.
path: Path tuple to the enum definition.
name_prefix: Optional prefix for this enum's name. | codesearchnet |
def remove_variable(self, v):
if (v not in self):
return
adj = self.adj
while adj[v]:
self.remove_interaction(v, next(iter(adj[v])))
del self.linear[v]
try:
del self._counterpart
if ((self.vartype is not Vartype.BINARY) and hasattr(self, '_binary')):
del s... | Remove variable v and all its interactions from a binary quadratic model.
Args:
v (variable):
The variable to be removed from the binary quadratic model.
Notes:
If the specified variable is not in the binary quadratic model, this function does nothing.
Examples:
This example creates an Ising model and then removes o... | 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(',')
if (not self.blocking):
self.blocking = True
while s... | 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... | codesearchnet |
def build_or_reuse_placeholder(tensor_spec):
g = tfv1.get_default_graph()
name = tensor_spec.name
try:
tensor = g.get_tensor_by_name((name + ':0'))
assert ('Placeholder' in tensor.op.type), 'Tensor {} exists but is not a placeholder!'.format(name)
assert tensor_spec.is_compatible_wit... | Build a tf.placeholder from the metadata in the given tensor spec, or return an existing one.
Args:
tensor_spec (tf.TensorSpec):
Returns:
tf.Tensor: | codesearchnet |
def eval_rs(gains, losses):
count = len(gains) + len(losses)
avg_gains = stats.avg(gains, count=count) if gains else 1
avg_losses = stats.avg(losses,count=count) if losses else 1
if avg_losses == 0:
return avg_gains
else:
return avg_gain... | Evaluates the RS variable in RSI algorithm
Args:
gains: List of price gains.
losses: List of prices losses.
Returns:
Float of average gains over average losses. | juraj-google-style |
def Parse(self, conditions, host_data):
result = CheckResult(check_id=self.check_id)
methods = self.SelectChecks(conditions)
result.ExtendAnomalies([m.Parse(conditions, host_data) for m in methods])
return result | Runs methods that evaluate whether collected host_data has an issue.
Args:
conditions: A list of conditions to determine which Methods to trigger.
host_data: A map of artifacts and rdf data.
Returns:
A CheckResult populated with Anomalies if an issue exists. | codesearchnet |
def _get_degree(num_nodes):
d_float = (0.5 * (np.sqrt(((8.0 * num_nodes) + 1.0)) - 3.0))
d_int = int(np.round(d_float))
if (((d_int + 1) * (d_int + 2)) == (2 * num_nodes)):
return d_int
else:
raise ValueError(num_nodes, 'not a triangular number') | Get the degree of the current surface.
Args:
num_nodes (int): The number of control points for a
B |eacute| zier surface.
Returns:
int: The degree :math:`d` such that :math:`(d + 1)(d + 2)/2`
equals ``num_nodes``.
Raises:
ValueError: If ``num_nodes`` isn't a triangular number. | codesearchnet |
def build(cls, name: str, param_names: tuple[str, ...], posonly_count: int, varargs_name: str | None, kwonly_params: tuple[str, ...], kwargs_name: str | None, defaults: 'dict[str, cfg.Variable]', annotations: dict[str, Any], ctx: 'context.Context') -> 'SimpleFunction':
annotations = dict(annotations)
for n in i... | Returns a SimpleFunction.
Args:
name: Name of the function as a string
param_names: Tuple of parameter names as strings. This DOES include
positional-only parameters and does NOT include keyword-only parameters.
posonly_count: Number of positional-only parameters.
varargs_name: The "args" in "*args". String or None.
k... | github-repos |
def _compile_internal(computation, inputs=None):
if inputs is None:
inputs = []
if not isinstance(inputs, collections_abc.Sequence):
raise TypeError('inputs must be a list')
flat_inputs = nest.flatten(inputs)
flat_inputs = [ops.convert_to_tensor(x) for x in flat_inputs]
cluster_name ... | Builds graph operators that compiles and symbolically executes computation.
Args:
computation: A Python function that builds the computation to compile and
execute.
inputs: A list of inputs or `None` (equivalent to an empty list). Each input
can be a nested structure containing values that are convertible to
tensors. ... | github-repos |
def delete_file(self, file_id):
if not is_valid_uuid(file_id):
raise StorageArgumentException(
'Invalid UUID for file_id: {0}'.format(file_id))
self._authenticated_request \
.to_endpoint('file/{}/'.format(file_id)) \
.delete() | Delete a file.
Args:
file_id (str): The UUID of the file to delete.
Returns:
None
Raises:
StorageArgumentException: Invalid arguments
StorageForbiddenException: Server response code 403
StorageNotFoundException: Server response code 404
StorageException: other 400-600 error codes | juraj-google-style |
async def getTempCoreProx(mods=None):
acm = genTempCoreProxy(mods)
prox = (await acm.__aenter__())
object.__setattr__(prox, '_acm', acm)
async def onfini():
(await prox._acm.__aexit__(None, None, None))
prox.onfini(onfini)
return prox | Get a Telepath Proxt to a Cortex instance which is backed by a temporary Cortex.
Args:
mods (list): A list of additional CoreModules to load in the Cortex.
Notes:
The Proxy returned by this should be fini()'d to tear down the temporary Cortex.
Returns:
s_telepath.Proxy | codesearchnet |
def unpack_rpc_payload(resp_format, payload):
code = _create_argcode(resp_format, payload)
return struct.unpack(code, payload) | Unpack an RPC payload according to resp_format.
Args:
resp_format (str): a struct format code (without the <) for the
parameter format for this RPC. This format code may include the final
character V, which means that it expects a variable length bytearray.
payload (bytes): The binary payload that should be unpacked.... | juraj-google-style |
def output_shapes(self):
return nest.map_structure(lambda component_spec: component_spec._to_legacy_output_shapes(), self.element_spec) | Returns the shape of each component of an element of this dataset.
Returns:
A (nested) structure of `tf.TensorShape` objects corresponding to each
component of an element of this dataset. | github-repos |
def GetFilter(cls, filter_name):
try:
filt_cls = cls.GetPlugin(filter_name)
except KeyError:
raise DefinitionError("Filter %s does not exist." % filter_name)
return filt_cls() | Return an initialized filter. Only initialize filters once.
Args:
filter_name: The name of the filter, as a string.
Returns:
an initialized instance of the filter.
Raises:
DefinitionError if the type of filter has not been defined. | juraj-google-style |
def fts_match_any(self, fts, inv):
return any([self.fts_match(fts, s) for s in inv]) | Return `True` if any segment in `inv` matches the features in `fts`
Args:
fts (list): a collection of (value, feature) tuples
inv (list): a collection of IPA segments represented as Unicode
strings
Returns:
bool: `True` if any segment in `inv` matches the features in `fts` | codesearchnet |
async def verify_scriptworker_task(chain, obj):
errors = []
if obj.worker_impl != "scriptworker":
errors.append("{} {} must be run from scriptworker!".format(obj.name, obj.task_id))
raise_on_errors(errors) | Verify the signing trust object.
Currently the only check is to make sure it was run on a scriptworker.
Args:
chain (ChainOfTrust): the chain we're operating on
obj (ChainOfTrust or LinkOfTrust): the trust object for the signing task. | juraj-google-style |
def _process_tensor_event_in_chunks(self, event, tensor_chunks):
value = event.summary.value[0]
debugger_plugin_metadata = json.loads(compat.as_text(value.metadata.plugin_data.content))
device_name = debugger_plugin_metadata['device']
num_chunks = debugger_plugin_metadata['numChunks']
chunk_index = ... | Possibly reassemble event chunks.
Due to gRPC's message size limit, a large tensor can be encapsulated in
multiple Event proto chunks to be sent through the debugger stream. This
method keeps track of the chunks that have arrived, reassemble all chunks
corresponding to a tensor when they have arrived and return the re... | github-repos |
def _ParseDataStreamWithParser(self, parser_mediator, parser, file_entry, data_stream_name):
file_object = file_entry.GetFileObject(data_stream_name=data_stream_name)
if (not file_object):
raise RuntimeError('Unable to retrieve file-like object from file entry.')
try:
self._ParseFileEntryWit... | Parses a data stream of a file entry with a specific parser.
Args:
parser_mediator (ParserMediator): parser mediator.
parser (BaseParser): parser.
file_entry (dfvfs.FileEntry): file entry.
data_stream_name (str): data stream name.
Raises:
RuntimeError: if the file-like object is missing. | codesearchnet |
def options(self, section):
if (not self.has_section(section)):
raise NoSectionError(section) from None
return self.__getitem__(section).options() | Returns list of configuration options for the named section.
Args:
section (str): name of section
Returns:
list: list of option names | codesearchnet |
def pipelines(self):
if (not self.response):
return set()
elif ((self._pipelines is None) and self.response):
self._pipelines = set()
for group in self.response.payload:
for pipeline in group['pipelines']:
self._pipelines.add(pipeline['name'])
return self.... | Returns a set of all pipelines from the last response
Returns:
set: Response success: all the pipelines available in the response
Response failure: an empty set | codesearchnet |
def commutes(m1: np.ndarray, m2: np.ndarray, *, rtol: float=1e-05, atol: float=1e-08) -> bool:
return ((m1.shape[0] == m1.shape[1]) and (m1.shape == m2.shape) and np.allclose(m1.dot(m2), m2.dot(m1), rtol=rtol, atol=atol)) | Determines if two matrices approximately commute.
Two matrices A and B commute if they are square and have the same size and
AB = BA.
Args:
m1: One of the matrices.
m2: The other matrix.
rtol: The per-matrix-entry relative tolerance on equality.
atol: The per-matrix-entry absolute tolerance on equality.
Returns:
Whe... | codesearchnet |
def read_label_file(path):
labels = []
for record in textfile.read_separated_lines_generator(path, separator='\t', max_columns=3):
value = ''
if len(record) > 2:
value = str(record[2])
labels.append([float(_clean_time(record[0])), float(_clean_time(record[1])), value]... | Read the labels from an audacity label file.
Args:
path (str): Path to the label file.
Returns:
list: List of labels (start [sec], end [sec], label)
Example::
>>> read_label_file('/path/to/label/file.txt')
[
[0.0, 0.2, 'sie'],
[0.2, 2.2, 'hallo']
] | juraj-google-style |
def dumps(self, with_defaults=False):
return self._rw.dump_config_to_string(self._config, with_defaults=with_defaults) | Generate a string representing all the configuration values.
Args:
with_defaults (bool): if ``True``, values of items with no custom values will be included in the output
if they have a default value set. | codesearchnet |
def join(self, other):
if self.contains(other):
return True
if other.contains(self):
self.x = other.x
self.y = other.y
self.width = other.width
self.height = other.height
return True
if (not self.intersects(other, edges=True)):
return False
if ((se... | Try to join a rectangle to this one, if the result is also a rectangle
and the operation is successful and this rectangle is modified to the union.
Arguments:
other (Rectangle): Rectangle to join
Returns:
bool: True when successfully joined, False otherwise | codesearchnet |
def find_elements_by_id(self, id_, update=False) -> Elements:
return self.find_elements(by=By.ID, value=id_, update=update) | Finds multiple elements by id.
Args:
id_: The id 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_elements_b... | juraj-google-style |
def Record(self, obj):
if (len(self._visit_recorder_objects) >= _MAX_VISIT_OBJECTS):
return False
obj_id = id(obj)
if (obj_id in self._visit_recorder_objects):
return False
self._visit_recorder_objects[obj_id] = obj
return True | Records the object as visited.
Args:
obj: visited object.
Returns:
True if the object hasn't been previously visited or False if it has
already been recorded or the quota has been exhausted. | codesearchnet |
class GroupViTTextEncoder(nn.Module):
def __init__(self, config: GroupViTTextConfig):
super().__init__()
self.config = config
self.layers = nn.ModuleList([GroupViTEncoderLayer(config) for _ in range(config.num_hidden_layers)])
self.gradient_checkpointing = False
def forward(sel... | Transformer encoder consisting of `config.num_hidden_layers` self-attention layers. Each layer is a
[`GroupViTEncoderLayer`].
Args:
config: GroupViTTextConfig | github-repos |
def index_in_block(self, channel_index: int) -> int:
if channel_index < 0 or channel_index >= self.cdim:
raise ValueError()
struct = self.block_structure
if len(struct) == 1:
return channel_index, 0
i = 1
while sum(struct[:i]) <= channel_index a... | Return the index a channel has within the subblock it belongs to
I.e., only for reducible circuits, this gives a result different from
the argument itself.
Args:
channel_index (int): The index of the external channel
Raises:
ValueError: for an invalid `channel_index` | juraj-google-style |
def get_weights_of_nn_sites(self, structure, n):
return [e['weight'] for e in self.get_nn_info(structure, n)] | Get weight associated with each near neighbor of site with
index n in structure.
Args:
structure (Structure): input structure.
n (integer): index of site for which to determine the weights.
Returns:
weights (list of floats): near-neighbor weights. | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.