code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def loss_masks(self, masks_queries_logits: Tensor, mask_labels: List[Tensor], indices: Tuple[np.array], num_masks: int) -> Dict[str, Tensor]:
src_idx = self._get_predictions_permutation_indices(indices)
tgt_idx = self._get_targets_permutation_indices(indices)
pred_masks = masks_queries_logits[src_idx]
t... | Compute the losses related to the masks using focal and dice loss.
Args:
masks_queries_logits (`torch.Tensor`):
A tensor of shape `batch_size, num_queries, height, width`
mask_labels (`torch.Tensor`):
List of mask labels of shape `(labels, height, width)`.
indices (`Tuple[np.array])`:
The indices computed by the Hunga... | github-repos |
def _get_configured_module(option_name, known_modules=None):
from furious.job_utils import path_to_reference
config = get_config()
option_value = config[option_name]
if not known_modules:
known_modules = {}
module_path = known_modules.get(option_value) or option_value
return... | Get the module specified by the value of option_name. The value of the
configuration option will be used to load the module by name from the known
module list or treated as a path if not found in known_modules.
Args:
option_name: name of persistence module
known_modules: dictionary of module names and module paths,
ie:... | juraj-google-style |
def __init__(self, variant_type='snv'):
super(VcfPlugin, self).__init__()
self.individual_objs = []
self.case_objs = []
self.variant_type = variant_type
logger.info("Setting variant type to {0}".format(variant_type))
self.variant_columns = ['CHROM', 'POS', 'ID... | Initialize a vcf adapter.
When instansiating all cases are found.
Args:
variant_type(str) : 'snv' or 'sv' | juraj-google-style |
def char_ngrams(s, n=3, token_fn=tokens.on_whitespace):
tokens = token_fn(s)
ngram_tuples = [__ngrams(t, n=min(len(t), n)) for t in tokens]
def unpack(l):
return sum(l, [])
def untuple(l):
return [''.join(t) for t in l]
return untuple(unpack(ngram_tuples)) | Character-level n-grams from within the words in a string.
By default, the word boundary is assumed to be whitespace. n-grams are
not taken across word boundaries, only within words.
If a word's length is less than or equal to n, the n-grams are simply a
list with the word itself.
>>> ng.char_ngrams('This is not a ... | codesearchnet |
def remove_waiter(self, waiter_handle):
spec, waiter = waiter_handle
self._remove_waiter(spec, waiter) | Remove a message callback.
This call will remove a callback previously registered using
every_match.
Args:
waiter_handle (object): The opaque handle returned by the
previous call to every_match(). | juraj-google-style |
def stop_dag(self, name=None):
return self._client.send(
Request(
action='stop_dag',
payload={'name': name if name is not None else self._dag_name}
)
).success | Send a stop signal to the specified dag or the dag that hosts this task.
Args:
name str: The name of the dag that should be stopped. If no name is given the
dag that hosts this task is stopped.
Upon receiving the stop signal, the dag will not queue any new tasks and wait
for running tasks to terminate.
Returns:
bool... | juraj-google-style |
def __init__(self, action_type=None, nw_addr=None):
super().__init__(action_type, length=8)
self.nw_addr = nw_addr | Create an ActionNWAddr with the optional parameters below.
Args:
action_type (:class:`~pyof.v0x01.common.action.ActionType`):
:attr:`~ActionType.OFPAT_SET_NW_SRC` or
:attr:`~ActionType.OFPAT_SET_NW_DST`.
nw_addr (int): IP Address. | juraj-google-style |
def InsertData(self, table_id, fd, schema, job_id):
configuration = {'schema': {'fields': schema}, 'destinationTable': {'projectId': self.project_id, 'tableId': table_id, 'datasetId': self.dataset_id}, 'sourceFormat': 'NEWLINE_DELIMITED_JSON'}
body = {'configuration': {'load': configuration}, 'jobReference': {'... | Insert data into a bigquery table.
If the table specified doesn't exist, it will be created with the specified
schema.
Args:
table_id: string table id
fd: open file descriptor containing the newline separated JSON
schema: BigQuery schema dict
job_id: string job id
Returns:
API response object on success, None on fai... | codesearchnet |
def __init__(self, fetches, contraction_fn):
self._unique_fetches = []
for fetch in fetches:
try:
self._unique_fetches.append(ops.get_default_graph().as_graph_element(fetch, allow_tensor=True, allow_operation=True))
except TypeError as e:
raise TypeError(f'Argument `fetch... | Creates an _ElementFetchMapper.
This is the fetch mapper used for leaves in the fetch struct. Because of
the expansions mechanism, a leaf can actually fetch more than one tensor.
Also note that the fetches here can be just strings (tensor or op names) or
any other object that the graph knows how to convert to a tens... | github-repos |
def view(value: Any, *, name: Optional[str]=None, root_path: Optional[utils.KeyPath]=None, view_id: str='html-tree-view', **kwargs) -> Content:
if isinstance(value, Content):
return value
with view_options(**kwargs) as options:
view_object = View.create(view_id)
return view_object.render... | Views an object through generating content based on a specific view.
Args:
value: The value to view.
name: The name of the value.
root_path: The root path of the value.
view_id: The ID of the view to use. See `pg.View.dir()` for all available
view IDs.
**kwargs: Additional keyword arguments passed to the view, wich
wi... | github-repos |
def inner_join(df, other, **kwargs):
(left_on, right_on, suffixes) = get_join_parameters(kwargs)
joined = df.merge(other, how='inner', left_on=left_on, right_on=right_on, suffixes=suffixes)
return joined | Joins on values present in both DataFrames.
Args:
df (pandas.DataFrame): Left DataFrame (passed in via pipe)
other (pandas.DataFrame): Right DataFrame
Kwargs:
by (str or list): Columns to join on. If a single string, will join
on that column. If a list of lists which contain strings or
integers, the right/left column... | codesearchnet |
def neighborhood_probability(self, threshold, radius, sigmas=None):
if (sigmas is None):
sigmas = [0]
weights = disk(radius)
filtered_prob = []
for sigma in sigmas:
filtered_prob.append(EnsembleConsensus(np.zeros(self.data.shape[1:], dtype=np.float32), 'neighbor_prob_r_{0:d}_s_{1:d}'.for... | Hourly probability of exceeding a threshold based on model values within a specified radius of a point.
Args:
threshold (float): probability of exceeding this threshold
radius (int): distance from point in number of grid points to include in neighborhood calculation.
sigmas (array of ints): Radii for Gaussian filter u... | codesearchnet |
def remove_codeblock_syntax_sentinals(code_text):
flags = (re.MULTILINE | re.DOTALL)
code_text_ = code_text
code_text_ = re.sub('^ *
code_text_ = re.sub('^ *
code_text_ = re.sub('^ *
code_text_ = code_text_.rstrip()
return code_text_ | r"""
Removes template comments and vim sentinals
Args:
code_text (str):
Returns:
str: code_text_ | codesearchnet |
def restores(self):
if (not self.__restores):
self.__restores = Restores(self.__connection)
return self.__restores | Gets the Restores API client.
Returns:
Restores: | codesearchnet |
def from_str(cls, label: str) -> int:
label_norm = label.replace('1', 'one').upper()
if (label_norm in cls.__members__):
return DecayType[label_norm]
else:
raise NotImplementedError | Convert given string label of decay type to special index
Args:
label: name of decay type.
Set of values: `"linear"`, `"cosine"`, `"exponential"`,
`"onecycle"`, `"trapezoid"`, `["polynomial", K]`, where K is a polynomial power
Returns:
index of decay type | codesearchnet |
def patch_so(srcs_dir: str) -> None:
to_patch = {'tensorflow/python/_pywrap_tensorflow_internal.so': '$ORIGIN/../../tensorflow/compiler/xla/tsl/python/lib/core', 'tensorflow/compiler/mlir/quantization/tensorflow/python/pywrap_function_lib.so': '$ORIGIN/../../../../../python', 'tensorflow/compiler/mlir/quantization/... | Patch .so files.
We must patch some of .so files otherwise auditwheel will fail.
Args:
srcs_dir: target directory with .so files to patch. | github-repos |
def _DrawTrips(self, triplist, colpar=''):
stations = []
if ((not self._stations) and triplist):
self._stations = self._CalculateYLines(self._TravelTimes(triplist))
if (not self._stations):
self._AddWarning('Failed to use traveltimes for graph')
self._stations = self._Cal... | Generates svg polylines for each transit trip.
Args:
# Class Trip is defined in transitfeed.py
[Trip, Trip, ...]
Returns:
# A string containing a polyline tag for each trip
' <polyline class="T" stroke="#336633" points="433,0 ...' | codesearchnet |
def oauth2decorator_from_clientsecrets(filename, scope, message=None, cache=None):
return OAuth2DecoratorFromClientSecrets(filename, scope, message=message, cache=cache) | Creates an OAuth2Decorator populated from a clientsecrets file.
Args:
filename: string, File name of client secrets.
scope: string or list of strings, scope(s) of the credentials being
requested.
message: string, A friendly string to display to the user if the
clientsecrets file is missing or invalid. The message may
... | codesearchnet |
def stop_loss_replace(self, accountID, orderID, **kwargs):
return self.replace(
accountID,
orderID,
order=StopLossOrderRequest(**kwargs)
) | Shortcut to replace a pending Stop Loss Order in an Account
Args:
accountID : The ID of the Account
orderID : The ID of the Stop Loss Order to replace
kwargs : The arguments to create a StopLossOrderRequest
Returns:
v20.response.Response containing the results from submitting
the request | juraj-google-style |
def create(window, root):
notifications = {}
_id = root.get_property("id")
from foxpuppet.windows.browser.notifications import addons
notifications.update(addons.NOTIFICATIONS)
return notifications.get(_id, BaseNotification)(window, root) | Create a notification object.
Args:
window (:py:class:`BrowserWindow`): Window object this region
appears in.
root
(:py:class:`~selenium.webdriver.remote.webelement.WebElement`):
WebDriver element object that serves as the root for the
notification.
Returns:
:py:class:`BaseNotification`: Firefox notification. | juraj-google-style |
def _load_data(self, resource, default=DEFAULT_VALUE_SAFEGUARD, **kwargs):
default_val = (default if (default != self.DEFAULT_VALUE_SAFEGUARD) else {})
try:
return (get_edx_api_data(api_config=CatalogIntegration.current(), resource=resource, api=self.client, **kwargs) or default_val)
except (Slumber... | Load data from API client.
Arguments:
resource(string): type of resource to load
default(any): value to return if API query returned empty result. Sensible values: [], {}, None etc.
Returns:
dict: Deserialized response from Course Catalog API | codesearchnet |
def attention_bias_proximal(length):
r = tf.to_float(tf.range(length))
diff = (tf.expand_dims(r, 0) - tf.expand_dims(r, 1))
return tf.expand_dims(tf.expand_dims((- tf.log1p(tf.abs(diff))), 0), 0) | Bias for self-attention to encourage attention to close positions.
Args:
length: an integer scalar.
Returns:
a Tensor with shape [1, 1, length, length] | codesearchnet |
def list_asgs_all(access_token, subscription_id):
endpoint = ''.join([get_rm_endpoint(),
'/subscriptions/', subscription_id,
'/providers/Microsoft.Network/virtualNetworks/',
'?api-version=', NETWORK_API])
return do_get(endpoint, access... | Get details about the application security groups for a resource group.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
Returns:
HTTP response. ASG JSON body. | juraj-google-style |
def text_colour_for_hex(hexx, percent=50, dark='
return (light if hex_is_dark(hexx, percent=percent) else dark) | Function to decide what colour to use for a given hex colour.
Args:
hexx (str): A hexadecimal colour, starting with '#'.
Returns:
bool: The colour's brightness is less than the given percent. | codesearchnet |
def symlink(src, link):
if (sys.getwindowsversion().major < 6):
raise SaltInvocationError('Symlinks are only supported on Windows Vista or later.')
if (not os.path.exists(src)):
raise SaltInvocationError('The given source path does not exist.')
if (not os.path.isabs(src)):
raise Salt... | Create a symbolic link to a file
This is only supported with Windows Vista or later and must be executed by
a user with the SeCreateSymbolicLink privilege.
The behavior of this function matches the Unix equivalent, with one
exception - invalid symlinks cannot be created. The source path must exist.
If it doesn't, an ... | codesearchnet |
def trace_set_buffer_capacity(self, size):
cmd = enums.JLinkTraceCommand.SET_CAPACITY
data = ctypes.c_uint32(size)
res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(data))
if (res == 1):
raise errors.JLinkException('Failed to set trace buffer size.')
r... | Sets the capacity for the trace buffer.
Args:
self (JLink): the ``JLink`` instance.
size (int): the new capacity for the trace buffer.
Returns:
``None`` | juraj-google-style |
def supported_tifs(self):
buf = ctypes.c_uint32()
self._dll.JLINKARM_TIF_GetAvailable(ctypes.byref(buf))
return buf.value | Returns a bitmask of the supported target interfaces.
Args:
self (JLink): the ``JLink`` instance
Returns:
Bitfield specifying which target interfaces are supported. | juraj-google-style |
def _ConvertAttributeContainerToDict(cls, attribute_container):
if (not isinstance(attribute_container, containers_interface.AttributeContainer)):
raise TypeError('{0:s} is not an attribute container type.'.format(type(attribute_container)))
container_type = getattr(attribute_container, 'CONTAINER_TYPE'... | Converts an attribute container object into a JSON dictionary.
The resulting dictionary of the JSON serialized objects consists of:
{
'__type__': 'AttributeContainer'
'__container_type__': ...
...
}
Here '__type__' indicates the object base type. In this case
'AttributeContainer'.
'__container_type__' indicates the ... | codesearchnet |
def parse_columns(lines):
data = []
index = []
for line in lines:
line = line.rstrip()
if line.startswith('
tmp = __parse_entry(line)
data.append(tmp[1])
index.append(tmp[0])
return DataFrame(data, index=index, columns=['description']) | Parse list of lines with columns description from SOFT file.
Args:
lines (:obj:`Iterable`): Iterator over the lines.
Returns:
:obj:`pandas.DataFrame`: Columns description. | codesearchnet |
def GetEventTagByIdentifier(self, identifier):
event_tag = self._GetAttributeContainerByIndex(self._CONTAINER_TYPE_EVENT_TAG, (identifier.row_identifier - 1))
if event_tag:
event_identifier = identifiers.SQLTableIdentifier(self._CONTAINER_TYPE_EVENT, event_tag.event_row_identifier)
event_tag.Set... | Retrieves a specific event tag.
Args:
identifier (SQLTableIdentifier): event tag identifier.
Returns:
EventTag: event tag or None if not available. | codesearchnet |
def kill_reporter(self, check_alive=True):
if PY3:
self._kill_process_type(
ray_constants.PROCESS_TYPE_REPORTER, check_alive=check_alive) | Kill the reporter.
Args:
check_alive (bool): Raise an exception if the process was already
dead. | juraj-google-style |
def csv_to_matrix(csv_file_path):
mtx = []
with open(csv_file_path) as csv_data_file:
for row in csv_data_file:
mtx.append(row.split(','))
return mtx | Load a CSV file into a Python matrix of strings.
Args:
csv_file_path: Full path to a valid CSV file (e.g. c:/ladybug/test.csv) | juraj-google-style |
def softplus(x, scale=1.0, name=None):
if scale == 1:
return tf.nn.softplus(x)
else:
with tf.name_scope(name, 'softplus', [x]):
scale = tf.convert_to_tensor(scale, dtype=x.dtype.base_dtype)
return tf.nn.softplus(x * scale) / scale | Computes softplus with a scale factor to sharpen of the hinge.
This is an alternate non-linearity to relu. It has a similar shape, but
it has a smooth transition from the linear part to 0.
Args:
x: A tensor.
scale: A float that sharpens the curve.
name: Optional name.
Returns:
y = log(1 + exp(scale * x)) / scale | juraj-google-style |
def prep_parallel(self, binary_args, other_args):
if self.length < 100:
raise Exception("Run this across 1 processor by setting num_processors kwarg to None.")
if self.num_processors == -1:
self.num_processors = mp.cpu_count()
split_val = int(np.ceil(self.length... | Prepare the parallel calculations
Prepares the arguments to be run in parallel.
It will divide up arrays according to num_splits.
Args:
binary_args (list): List of binary arguments for input into the SNR function.
other_args (tuple of obj): tuple of other args for input into parallel snr function. | juraj-google-style |
def __init__(self, job_id, context):
super(GCPJob, self).__init__(job_id)
if context is None:
context = google.datalab.Context.default()
self._context = context
self._api = self._create_api(context) | Initializes an instance of a Job.
Args:
job_id: the BigQuery job ID corresponding to this job.
context: a Context object providing project_id and credentials. | juraj-google-style |
def preprocess(self, raw_inputs):
image_arrays = []
for raw_im in raw_inputs:
im = raw_im.convert('L')
im = im.resize(MNIST_DIM, Image.ANTIALIAS)
arr = np.array(im)
image_arrays.append(arr)
inputs = np.array(image_arrays)
return (inputs.reshape(len(inputs), MNIST_DIM[0], ... | Convert images into the format required by our model.
Our model requires that inputs be grayscale (mode 'L'), be resized to
`MNIST_DIM`, and be represented as float32 numpy arrays in range
[0, 1].
Args:
raw_inputs (list of Images): a list of PIL Image objects
Returns:
array (float32): num images * height * width * n... | codesearchnet |
def _page_to_text(page):
start_pos = page.find(u'<text')
assert (start_pos != (- 1))
end_tag_pos = page.find(u'>', start_pos)
assert (end_tag_pos != (- 1))
end_tag_pos += len(u'>')
end_pos = page.find(u'</text>')
if (end_pos == (- 1)):
return u''
return page[end_tag_pos:end_pos] | Extract the text from a page.
Args:
page: a unicode string
Returns:
a unicode string | codesearchnet |
def rated_movies(self, **kwargs):
path = self._get_guest_session_id_path('rated_movies')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Get a list of rated moview for a specific guest session id.
Args:
page: (optional) Minimum 1, maximum 1000.
sort_by: (optional) 'created_at.asc' | 'created_at.desc'
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API. | codesearchnet |
def execute(self):
for name_context, spec in zip(self._map_task.name_contexts, self._map_task.operations):
op = create_operation(name_context, spec, self._counter_factory, None, self._state_sampler, test_shuffle_source=self._test_shuffle_source, test_shuffle_sink=self._test_shuffle_sink)
self._ops.a... | Executes all the operation_specs.Worker* instructions in a map task.
We update the map_task with the execution status, expressed as counters.
Raises:
RuntimeError: if we find more than on read instruction in task spec.
TypeError: if the spec parameter is not an instance of the recognized
operation_specs.Worker* class... | github-repos |
def _ragged_split(tensor, pieces):
shape = tensor.shape
if 1 != len(shape):
raise ValueError('input tensor must be 1D')
tensor_len = shape.dims[0].value
chunk_size = tensor_len
with ops.colocate_with(tensor):
if tensor_len != pieces * chunk_size:
assert pieces > 1
... | Like split for 1D tensors but allows case where len % pieces != 0.
Args:
tensor: `tf.Tensor` that must be 1D.
pieces: a positive integer specifying the number of pieces into which
tensor should be split.
Returns:
list of `tf.Tensor` of length pieces, which hold the values of
the input tensor, in order. The final tens... | github-repos |
class PatchTSMixerForRegressionOutput(ModelOutput):
loss: Optional[torch.FloatTensor] = None
regression_outputs: Optional[torch.FloatTensor] = None
last_hidden_state: Optional[torch.FloatTensor] = None
hidden_states: Optional[Tuple[torch.FloatTensor]] = None | Output type of [`PatchTSMixerForRegressionOutput`].
Args:
regression_outputs (`torch.FloatTensor` of shape `(batch_size, num_targets)`):
Prediction output from the regression head.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_input_channels, num_patches, d_model)`):
Backbone embeddings before pass... | github-repos |
def GetContainingWhileContext(ctxt, stop_ctxt=None):
while ctxt:
if ctxt.IsWhileContext() or ctxt == stop_ctxt:
return ctxt
ctxt = ctxt.outer_context
return None | Returns the first ancestor WhileContext of `ctxt`.
Returns `ctxt` if `ctxt` is a WhileContext, or None if `ctxt` is not in a
while loop.
Args:
ctxt: ControlFlowContext
stop_ctxt: ControlFlowContext, optional. If provided, the search will end
if it sees stop_ctxt.
Returns:
`ctxt` if `ctxt` is a WhileContext, the most... | github-repos |
def Create(conf, map_name, automount_mountpoint=None):
global _cache_implementations
if not _cache_implementations:
raise RuntimeError('no cache implementations exist')
cache_name = conf['name']
if cache_name not in _cache_implementations:
raise RuntimeError('cache not implemented: %r' %... | Cache creation factory method.
Args:
conf: a dictionary of configuration key/value pairs, including one
required attribute 'name'
map_name: a string identifying the map name to handle
automount_mountpoint: A string containing the automount mountpoint, used only
by automount maps.
Returns:
an instance of a Cache
Rais... | github-repos |
def structure_2_lmpdata(structure, ff_elements=None, atom_style="charge"):
s = structure.get_sorted_structure()
a, b, c = s.lattice.abc
m = s.lattice.matrix
xhi = a
xy = np.dot(m[1], m[0] / xhi)
yhi = np.sqrt(b ** 2 - xy ** 2)
xz = np.dot(m[2], m[0] / xhi)
yz = (np.dot(m[1], m[2]) ... | Converts a structure to a LammpsData object with no force field
parameters and topologies.
Args:
structure (Structure): Input structure.
ff_elements ([str]): List of strings of elements that must be
present due to force field settings but not necessarily in
the structure. Default to None.
atom_style (str): Choose betw... | juraj-google-style |
def lookup(self, keys, name=None):
with ops.name_scope(name, '%s_lookup_table_find' % self.name, [self.resource_handle, keys]):
keys = ops.convert_to_tensor(keys, dtype=self._key_dtype, name='keys')
with ops.colocate_with(self.resource_handle):
values = gen_lookup_ops.lookup_table_find_v... | Looks up `keys` in a table, outputs the corresponding values.
The `default_value` is used for keys not present in the table.
Args:
keys: Keys to look up. Can be a tensor of any shape. Must match the
table's key_dtype.
name: A name for the operation (optional).
Returns:
A tensor containing the values in the same shap... | github-repos |
def __init__(self, ball_radius=10, n_chains=4, chain_length=10, monomer=None):
super(Tnp, self).__init__()
if not monomer:
monomer = Bead(particle_kind='t')
n = 129
self.add(Sphere(n=n, radius=ball_radius, port_distance_from_surface=0.7), label="np")
... | Initialize a tethered nanoparticle.
Args:
ball_radius (float): Radius of the nanoparticle.
n_chains (int): Number of chains to attach to the nanoparticle.
chain_length (int): Length of the chains being attached.
monomer (Compound, optional): Type of chain being attached. | juraj-google-style |
def save_plot(self, filename, img_format="eps", ylim=None, units="thz"):
plt = self.get_plot(ylim=ylim, units=units)
plt.savefig(filename, format=img_format)
plt.close() | Save matplotlib plot to a file.
Args:
filename: Filename to write to.
img_format: Image format to use. Defaults to EPS.
ylim: Specifies the y-axis limits.
units: units for the frequencies. Accepted values thz, ev, mev, ha, cm-1, cm^-1. | juraj-google-style |
def upload_dict(s3_conn, s3_prefix, data_to_sync):
(bucket_name, prefix) = split_s3_path(s3_prefix)
bucket = s3_conn.get_bucket(bucket_name)
for (key, value) in data_to_sync.items():
full_name = '{}/{}.json'.format(prefix, key)
s3_key = boto.s3.key.Key(bucket=bucket, name=full_name)
... | Syncs a dictionary to an S3 bucket, serializing each value in the
dictionary as a JSON file with the key as its name.
Args:
s3_conn: (boto.s3.connection) an s3 connection
s3_prefix: (str) the destination prefix
data_to_sync: (dict) | codesearchnet |
def initial_sql(self, value):
self._initial_sql = value
if value is None:
try:
del self._connectionXML.attrib['one-time-sql']
except KeyError:
pass
else:
self._connectionXML.set('one-time-sql', value) | Set the connection's initial_sql property.
Args:
value: New initial_sql value. String.
Returns:
Nothing. | juraj-google-style |
def get_unbound_arg_names(arg_names, arg_binding_keys):
bound_arg_names = [abk._arg_name for abk in arg_binding_keys]
return [arg_name for arg_name in arg_names
if arg_name not in bound_arg_names] | Determines which args have no arg binding keys.
Args:
arg_names: a sequence of the names of possibly bound args
arg_binding_keys: a sequence of ArgBindingKey each of whose arg names is
in arg_names
Returns:
a sequence of arg names that is a (possibly empty, possibly non-proper)
subset of arg_names | juraj-google-style |
def add_file_to_tree(tree, file_path, file_contents, is_executable=False):
record = {
"path": file_path,
"mode": "100755" if is_executable else "100644",
"type": "blob",
"content": file_contents,
}
tree.append(record)
return tree | Add a file to a tree.
Args:
tree
A list of dicts containing info about each blob in a tree.
file_path
The path of the new file in the tree.
file_contents
The (UTF-8 encoded) contents of the new file.
is_executable
If ``True``, the new file will get executable permissions (0755).
Otherwise, it will get 0644 permiss... | juraj-google-style |
def save_prefixed_metrics(results, output_dir, file_name: str='all_results.json', metric_key_prefix: str='eval'):
for key in list(results.keys()):
if not key.startswith(f'{metric_key_prefix}_'):
results[f'{metric_key_prefix}_{key}'] = results.pop(key)
with open(os.path.join(output_dir, file_... | Save results while prefixing metric names.
Args:
results: (:obj:`dict`):
A dictionary of results.
output_dir: (:obj:`str`):
An output directory.
file_name: (:obj:`str`, `optional`, defaults to :obj:`all_results.json`):
An output file name.
metric_key_prefix: (:obj:`str`, `optional`, defaults to :obj:`eval`):
A metric ... | github-repos |
def full(shape, fill_value, dtype=None):
if any_symbolic_tensors((fill_value,)):
return Full(shape=shape, dtype=dtype).symbolic_call(fill_value)
return backend.numpy.full(shape, fill_value, dtype=dtype) | Return a new tensor of given shape and type, filled with `fill_value`.
Args:
shape: Shape of the new tensor.
fill_value: Fill value.
dtype: Desired data type of the tensor.
Returns:
Output tensor. | github-repos |
def safe_tag(self, tag, errors='strict'):
if tag is not None:
try:
tag = quote(self.s(tag, errors=errors), safe='~')[:128]
except KeyError as e:
warn = 'Failed converting tag to safetag ({})'.format(e)
self.log.war... | URL Encode and truncate tag to match limit (128 characters) of ThreatConnect API.
Args:
tag (string): The tag to be truncated
Returns:
(string): The truncated tag | juraj-google-style |
def _preprocess_params(cls, kwargs):
for attr, val in kwargs.items():
if cls.is_the_primary_key(attr) and cls._prevent_primary_key_initialization_:
del kwargs[attr]
continue
if val == "":
... | Returns a preprocessed dictionary of parameters.
Use this to filter the kwargs passed to `new`, `create`,
`build` methods.
Args:
**kwargs: a dictionary of parameters | juraj-google-style |
def make_innermost_setter(setter):
@functools.wraps(setter)
def _new_setter(kernel_results, *args, **kwargs):
'Wrapped setter.'
results_stack = []
while hasattr(kernel_results, 'inner_results'):
results_stack.append(kernel_results)
kernel_results = kernel_results... | Wraps a setter so it applies to the inner-most results in `kernel_results`.
The wrapped setter unwraps `kernel_results` and applies `setter` to the first
results without an `inner_results` attribute.
Args:
setter: A callable that takes the kernel results as well as some `*args` and
`**kwargs` and returns a modified c... | codesearchnet |
def make_2d_block_raster_mask(query_shape, memory_flange):
query_triangle = common_layers.ones_matrix_band_part(
np.prod(query_shape), np.prod(query_shape), -1, 0)
split_query_masks = tf.split(query_triangle, query_shape[0], axis=1)
mask_pieces = [
tf.concat(
[tf.ones([np.prod(que... | Creates a mask for 2d block raster scan.
The query mask can look to the left, top left, top, and top right, but
not to the right. Inside the query, we have the standard raster scan
masking.
Args:
query_shape: A tuple of ints (query_height, query_width)
memory_flange: A tuple of ints
(memory_flange_height, memory_flang... | juraj-google-style |
def _parse_slices(slicing_string):
parsed = []
for slice_string in slicing_string[1:-1].split(','):
indices = slice_string.split(':')
if len(indices) == 1:
parsed.append(int(indices[0].strip()))
elif 2 <= len(indices) <= 3:
parsed.append(slice(*[int(index.strip())... | Construct a tuple of slices from the slicing string.
The string must be a valid slicing string.
Args:
slicing_string: (str) Input slicing string to be parsed.
Returns:
tuple(slice1, slice2, ...)
Raises:
ValueError: If tensor_slicing is not a valid numpy ndarray slicing str. | github-repos |
def save_intraday(data: pd.DataFrame, ticker: str, dt, typ='TRADE'):
cur_dt = pd.Timestamp(dt).strftime('%Y-%m-%d')
logger = logs.get_logger(save_intraday, level='debug')
info = f'{ticker} / {cur_dt} / {typ}'
data_file = hist_file(ticker=ticker, dt=dt, typ=typ)
if (not data_file):
return
... | Check whether data is done for the day and save
Args:
data: data
ticker: ticker
dt: date
typ: [TRADE, BID, ASK, BID_BEST, ASK_BEST, BEST_BID, BEST_ASK]
Examples:
>>> os.environ['BBG_ROOT'] = 'xbbg/tests/data'
>>> sample = pd.read_parquet('xbbg/tests/data/aapl.parq')
>>> save_intraday(sample, 'AAPL US Equity', '2018-1... | codesearchnet |
def _TestGetItem(self, rt, slice_spec, expected, expected_shape=None):
tensor_slice_spec1 = _make_tensor_slice_spec(slice_spec, True)
tensor_slice_spec2 = _make_tensor_slice_spec(slice_spec, False)
value1 = rt.__getitem__(slice_spec)
value2 = rt.__getitem__(tensor_slice_spec1)
value3 = rt.__getitem_... | Helper function for testing RaggedTensor.__getitem__.
Checks that calling `rt.__getitem__(slice_spec) returns the expected value.
Checks three different configurations for each slice spec:
* Call __getitem__ with the slice spec as-is (with int values)
* Call __getitem__ with int values in the slice spec wrapped in
`t... | github-repos |
def get_num_bytes(self, batch: Sequence[pandas.DataFrame]) -> int:
return sum((df.memory_usage(deep=True).sum() for df in batch)) | Returns:
The number of bytes of data for a batch of Numpy arrays. | github-repos |
def coalescence_waiting_times(self, backward=True):
if (not isinstance(backward, bool)):
raise TypeError('backward must be a bool')
times = list()
lowest_leaf_dist = float('-inf')
for (n, d) in self.distances_from_root():
if (len(n.children) > 1):
times.append(d)
elif... | Generator over the waiting times of successive coalescence events
Args:
``backward`` (``bool``): ``True`` to go backward in time (i.e., leaves to root), otherwise ``False`` | codesearchnet |
def style_str(cls, style: Union[str, Dict[str, Any], None]) -> Optional[str]:
if not style:
return None
if isinstance(style, str):
return style
else:
assert isinstance(style, dict), style
return ''.join([f'{k.replace('_', '-')}:{v};' for k, v in style.items() if v is not None... | Gets a string representing an inline CSS style.
Args:
style: A single CSS style string, or a dictionary for CSS properties.
When dictionary form is used, underscore in the key name will be
replaced by dash in the generated CSS style string.
For example, `background_color` will be converted to `background-color`.
Retu... | github-repos |
def confab_conformers(self, forcefield='mmff94', freeze_atoms=None, rmsd_cutoff=0.5, energy_cutoff=50.0, conf_cutoff=100000, verbose=False):
if (self._obmol.GetDimension() != 3):
self.make3d()
else:
self.add_hydrogen()
ff = ob.OBForceField_FindType(forcefield)
if (ff == 0):
print... | Conformer generation based on Confab to generate all diverse low-energy
conformers for molecules. This is different from rotor_conformer or
gen3d_conformer as it aims to not simply to find a low energy
conformation but to generate several different conformations.
Args:
forcefield (str): Default is mmff94. Options are ... | codesearchnet |
def get_gradebook_id(self, gbuuid):
gradebook = self.get('gradebook', params={'uuid': gbuuid})
if ('data' not in gradebook):
failure_messsage = 'Error in get_gradebook_id for {0} - no data'.format(gradebook)
log.error(failure_messsage)
raise PyLmodUnexpectedData(failure_messsage)
ret... | Return gradebookid for a given gradebook uuid.
Args:
gbuuid (str): gradebook uuid, i.e. ``STELLAR:/project/gbngtest``
Raises:
PyLmodUnexpectedData: No gradebook id returned
requests.RequestException: Exception connection error
ValueError: Unable to decode response content
Returns:
str: value of gradebook id | codesearchnet |
def _collective_with_groups(self, x, mesh_axes, collective):
if not mesh_axes:
return x
x = x.to_laid_out_tensor()
if len(mesh_axes) == self.ndims:
return self.LaidOutTensor(collective(x.tensor_list, self._devices))
else:
groups = mtf.processor_groups(self.shape, mesh_axes)
... | Grouped collective, (across the given dimensions).
Args:
x: a LaidOutTensor
mesh_axes: a list of integers - the mesh dimensions to be reduced
collective: fn from list(tf.Tensor), list(device) -> list(tf.Tensor)
Returns:
a LaidOutTensor | juraj-google-style |
def render(engine, format, filepath, renderer=None, formatter=None, quiet=False):
(cmd, rendered) = command(engine, format, filepath, renderer, formatter)
run(cmd, capture_output=True, check=True, quiet=quiet)
return rendered | Render file with Graphviz ``engine`` into ``format``, return result filename.
Args:
engine: The layout commmand used for rendering (``'dot'``, ``'neato'``, ...).
format: The output format used for rendering (``'pdf'``, ``'png'``, ...).
filepath: Path to the DOT source file to render.
renderer: The output renderer use... | codesearchnet |
def findall_operations_with_gate_type(
self,
gate_type: Type[T_DESIRED_GATE_TYPE]
) -> Iterable[Tuple[int,
ops.GateOperation,
T_DESIRED_GATE_TYPE]]:
result = self.findall_operations(lambda operation: bool(
ops.op_ga... | Find the locations of all gate operations of a given type.
Args:
gate_type: The type of gate to find, e.g. XPowGate or
MeasurementGate.
Returns:
An iterator (index, operation, gate)'s for operations with the given
gate type. | juraj-google-style |
def is_flaky(max_attempts: int=5, wait_before_retry: Optional[float]=None, description: Optional[str]=None):
def decorator(test_func_ref):
@functools.wraps(test_func_ref)
def wrapper(*args, **kwargs):
retry_count = 1
while retry_count < max_attempts:
try:
... | To decorate flaky tests. They will be retried on failures.
Please note that our push tests use `pytest-rerunfailures`, which prompts the CI to rerun certain types of
failed tests. More specifically, if the test exception contains any substring in `FLAKY_TEST_FAILURE_PATTERNS`
(in `.circleci/create_circleci_config.py`)... | github-repos |
def datasets_list(self, project_id=None, max_results=0, page_token=None):
if project_id is None:
project_id = self._project_id
url = Api._ENDPOINT + (Api._DATASETS_PATH % (project_id, ''))
args = {}
if max_results != 0:
args['maxResults'] = max_results
if page_token is not None:
... | Issues a request to list the datasets in the project.
Args:
project_id: the project id to use to fetch the results; use None for the default project.
max_results: an optional maximum number of tables to retrieve.
page_token: an optional token to continue the retrieval.
Returns:
A parsed result object.
Raises:
Exceptio... | juraj-google-style |
def get_public_key_pem(cert_obj):
return cert_obj.public_key().public_bytes(
encoding=cryptography.hazmat.primitives.serialization.Encoding.PEM,
format=cryptography.hazmat.primitives.serialization.PublicFormat.PKCS1,
) | Extract public key from certificate as PEM encoded PKCS#1.
Args:
cert_obj: cryptography.Certificate
Returns:
bytes: PEM encoded PKCS#1 public key. | juraj-google-style |
def set_unrecognized_field(self, key, value, variant):
if (not isinstance(variant, Variant)):
raise TypeError(('Variant type %s is not valid.' % variant))
self.__unrecognized_fields[key] = (value, variant) | Set an unrecognized field, used when decoding a message.
Args:
key: The name or number used to refer to this unknown value.
value: The value of the field.
variant: Type information needed to interpret the value or re-encode
it.
Raises:
TypeError: If the variant is not an instance of messages.Variant. | codesearchnet |
def _conform_to_outputs(self, outputs, struct):
struct = map_to_output_names(outputs, self._output_names, struct)
struct = map_missing_dict_keys(outputs, struct)
if not nest.is_nested(struct) and nest.is_nested(outputs):
struct = nest.map_structure(lambda _: struct, outputs)
return struct | Convenience method to conform `struct` to `outputs` structure.
Mappings performed:
(1) Map a dict to a list of outputs, using the output names.
(2) Fill missing keys in a dict w/ `None`s.
(3) Map a single item to all outputs.
Args:
outputs: Model predictions.
struct: Arbitrary nested structure (e.g. of labels, sampl... | github-repos |
def seek(self, offset, whence=os.SEEK_SET):
if not self._is_open:
raise IOError('Not opened.')
if self._current_offset < 0:
raise IOError(
'Invalid current offset: {0:d} value less than zero.'.format(
self._current_offset))
if whence == os.SEEK_CUR:
offset +=... | Seeks to an offset within the file-like object.
Args:
offset (int): offset to seek to.
whence (Optional(int)): value that indicates whether offset is an absolute
or relative position within the file.
Raises:
IOError: if the seek failed.
OSError: if the seek failed. | juraj-google-style |
def replace(self, **kwargs):
init_kwargs = dict(job=self.job, replica=self.replica, task=self.task, device_type=self.device_type, device_index=self.device_index)
init_kwargs.update(kwargs)
return self.__class__(**init_kwargs) | Convenience method for making a new DeviceSpec by overriding fields.
For instance:
```
my_spec = DeviceSpec=(job="my_job", device="CPU")
my_updated_spec = my_spec.replace(device="GPU")
my_other_spec = my_spec.replace(device=None)
```
Args:
**kwargs: This method takes the same args as the DeviceSpec constructor
Retur... | github-repos |
def _validate_fhir_constraints(msg: message.Message, base_name: str, primitive_handler_: primitive_handler.PrimitiveHandler) -> None:
if annotation_utils.is_primitive_type(msg):
_ = primitive_handler_.primitive_wrapper_from_primitive(msg)
return
if proto_utils.is_message_type(msg, any_pb2.Any):
... | Iterates over fields of the provided message and validates constraints.
Args:
msg: The message to validate.
base_name: The root message name for recursive validation of nested message
fields.
primitive_handler_: Responsible for returning PrimitiveWrappers.
Raises:
fhir_errors.InvalidFhirError: In the event that a fie... | github-repos |
def _handle_stop_dag(self, request):
if ((request.payload['name'] is not None) and (request.payload['name'] not in self._stop_dags)):
self._stop_dags.append(request.payload['name'])
return Response(success=True, uid=request.uid) | The handler for the stop_dag request.
The stop_dag request adds a dag to the list of dags that should be stopped.
The dag will then stop queueing new tasks and will eventually stop running.
Args:
request (Request): Reference to a request object containing the
incoming request. The payload has to contain the
following... | codesearchnet |
def from_json(cls, json_data):
data = json.loads(_helpers._from_bytes(json_data))
if (data.get('token_expiry') and
not isinstance(data['token_expiry'], datetime.datetime)):
try:
data['token_expiry'] = datetime.datetime.strptime(
da... | Instantiate a Credentials object from a JSON description of it.
The JSON should have been produced by calling .to_json() on the object.
Args:
json_data: string or bytes, JSON to deserialize.
Returns:
An instance of a Credentials subclass. | juraj-google-style |
def RegionalWebhook(self, request, global_params=None):
config = self.GetMethodConfig('RegionalWebhook')
return self._RunMethod(config, request, global_params=global_params) | ReceiveRegionalWebhook is called when the API receives a regional GitHub webhook.
Args:
request: (CloudbuildLocationsRegionalWebhookRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(Empty) The response message. | github-repos |
def multinomial_sample(x, vocab_size=None, sampling_method="random",
temperature=1.0):
vocab_size = vocab_size or common_layers.shape_list(x)[-1]
if sampling_method == "random" and temperature > 0.0:
samples = tf.multinomial(tf.reshape(x, [-1, vocab_size]) / temperature, 1)
else:
... | Multinomial sampling from a n-dimensional tensor.
Args:
x: Tensor of shape [..., vocab_size]. Parameterizes logits of multinomial.
vocab_size: Number of classes in multinomial distribution.
sampling_method: String, "random" or otherwise deterministic.
temperature: Positive float.
Returns:
Tensor of shape [...]. | juraj-google-style |
def sawtooth(duration: int, amp: complex, period: float=None, phase: float=0, name: str=None) -> SamplePulse:
if (period is None):
period = duration
return _sampled_sawtooth_pulse(duration, amp, period, phase=phase, name=name) | Generates sawtooth wave `SamplePulse`.
Args:
duration: Duration of pulse. Must be greater than zero.
amp: Pulse amplitude. Wave range is [-amp, amp].
period: Pulse period, units of dt. If `None` defaults to single cycle.
phase: Pulse phase.
name: Name of pulse. | codesearchnet |
def delete(self, key):
try:
del self._collection(key)[key]
if len(self._collection(key)) == 0:
del self._items[str(key.path)]
except KeyError, e:
pass | Removes the object named by `key`.
Removes the object from the collection corresponding to ``key.path``.
Args:
key: Key naming the object to remove. | juraj-google-style |
def _protobuf_value_type(value):
if value.HasField("number_value"):
return api_pb2.DATA_TYPE_FLOAT64
if value.HasField("string_value"):
return api_pb2.DATA_TYPE_STRING
if value.HasField("bool_value"):
return api_pb2.DATA_TYPE_BOOL
return None | Returns the type of the google.protobuf.Value message as an api.DataType.
Returns None if the type of 'value' is not one of the types supported in
api_pb2.DataType.
Args:
value: google.protobuf.Value message. | juraj-google-style |
def _ParseEntryObjectOffsets(self, file_object, file_offset):
entry_array_object = self._ParseEntryArrayObject(file_object, file_offset)
entry_object_offsets = list(entry_array_object.entry_object_offsets)
while (entry_array_object.next_entry_array_offset != 0):
entry_array_object = self._ParseEntry... | Parses entry array objects for the offset of the entry objects.
Args:
file_object (dfvfs.FileIO): a file-like object.
file_offset (int): offset of the first entry array object relative to
the start of the file-like object.
Returns:
list[int]: offsets of the entry objects. | codesearchnet |
def expand_dims(x, axis=-1):
return array_ops.expand_dims(x, axis) | Adds a 1-sized dimension at index "axis".
Args:
x: A tensor or variable.
axis: Position where to add a new axis.
Returns:
A tensor with expanded dimensions. | github-repos |
def get_setting(name):
current_settings = get_settings(category='All')
for setting in current_settings:
if (name.lower() == setting.lower()):
return current_settings[setting]
raise KeyError('Invalid name: {0}'.format(name)) | Get the current configuration for the named audit setting
Args:
name (str): The name of the setting to retrieve
Returns:
str: The current configuration for the named setting
Raises:
KeyError: On invalid setting name
CommandExecutionError: If an error is encountered retrieving the settings
Usage:
.. code-block:: py... | codesearchnet |
def _build_ring_gather(input_tensors, devices, num_subchunks, pred_by_s_d, rank_by_s_d, red_op):
num_devices = len(input_tensors)
if num_devices == 0:
return []
if num_devices == 1:
return input_tensors
shape = input_tensors[0].shape
if 1 != len(shape):
raise ValueError('inpu... | Construct a subgraph for the first (reduction) pass of ring all-reduce.
Args:
input_tensors: a list of `tf.Tensor` 1D input tensors of same
shape and type.
devices: array of device name strings
num_subchunks: number of subchunks each device should process in one tick.
pred_by_s_d: as produced by _ring_permutations
ran... | github-repos |
def distance(self, method='haversine'):
distances = []
for segment in self:
if (len(segment) < 2):
distances.append([])
else:
distances.append(segment.distance(method))
return distances | Calculate distances between locations in segments.
Args:
method (str): Method used to calculate distance
Returns:
list of list of float: Groups of distance between points in
segments | codesearchnet |
def use_pcm(self, pcm_params=None, solvent_key="solvent", solvent_params=None,
radii_force_field=None):
self.params["pcm"] = dict()
self.params[solvent_key] = dict()
default_pcm_params = {"Theory": "SSVPE",
"vdwScale": 1.1,
... | Set the solvent model to PCM. Default parameters are trying to comply to
gaussian default value
Args:
pcm_params (dict): The parameters of "$pcm" section.
solvent_key (str): for versions < 4.2 the section name is "pcm_solvent"
solvent_params (dict): The parameters of solvent_key section
radii_force_field (str): The fo... | juraj-google-style |
def get_namespace(self, name_seq):
namespaces = self.namespaces
result = []
for name in name_seq:
namespaces = namespaces.get(name)
if not namespaces:
break
result.append(name)
return result | Returns the prefix of names from name_seq that are known namespaces.
Args:
name_seq: ['names', 'of', 'possible', 'namespace', 'to', 'find']
Returns:
['names', 'that', 'are', 'namespaces', 'possibly', 'empty', 'list'] | juraj-google-style |
def subscribe(self, requested_timeout=None, auto_renew=False):
class AutoRenewThread(threading.Thread):
'Used by the auto_renew code to renew a subscription from within\n a thread.\n\n '
def __init__(self, interval, stop_flag, sub, *args, **kwargs):
super(AutoRene... | Subscribe to the service.
If requested_timeout is provided, a subscription valid for that number
of seconds will be requested, but not guaranteed. Check
`timeout` on return to find out what period of validity is
actually allocated.
Note:
SoCo will try to unsubscribe any subscriptions which are still
subscribed on pro... | codesearchnet |
def _get_ami_dict(json_url):
LOG.info('Getting AMI from %s', json_url)
response = requests.get(json_url)
assert response.ok, 'Error getting ami info from {}'.format(json_url)
ami_dict = response.json()
LOG.debug('AMI json contents: %s', ami_dict)
return ami_dict | Get ami from a web url.
Args:
region (str): AWS Region to find AMI ID.
Returns:
dict: Contents in dictionary format. | codesearchnet |
def get_subset_counts(self, *keys):
if self.prepickle:
key_set = [pickle.dumps(key) for key in set(keys)]
else:
key_set = list(set(keys))
hashtables = [unordered_storage({'type': 'dict'}) for _ in
range(self.b)]
Hss = self.keys.getma... | Returns the bucket allocation counts (see :func:`~datasketch.MinHashLSH.get_counts` above)
restricted to the list of keys given.
Args:
keys (hashable) : the keys for which to get the bucket allocation
counts | juraj-google-style |
def poisson(data):
data = np.hstack(([0.0], np.array(data)))
cumm = np.cumsum(data)
def cost(s, t):
diff = cumm[t]-cumm[s]
if diff == 0:
return -2 * diff * (- np.log(t-s) - 1)
else:
return -2 * diff * (np.log(diff) - np.log(t-s) - 1)
return... | Creates a segment cost function for a time series with a
poisson distribution with changing mean
Args:
data (:obj:`list` of float): 1D time series data
Returns:
function: Function with signature
(int, int) -> float
where the first arg is the starting index, and the second
is the last arg. Returns the cost of that segm... | juraj-google-style |
def indicator(self, data):
try:
ip = ipaddress.ip_address(data)
except ValueError:
ip = ipaddress.ip_address(u'{}'.format(data))
if ip.version == 6:
data = ip.exploded
sections = []
for s in data.split(':'):
... | Update the request URI to include the Indicator for specific indicator retrieval.
Overload to handle formatting of ipv6 addresses
Args:
data (string): The indicator value | juraj-google-style |
def dbmax20years(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 `dbmax20years`'.format(value))
self._dbmax20years = value | Corresponds to IDD Field `dbmax20years`
20-year return period values for maximum extreme dry-bulb temperature
Args:
value (float): value for IDD Field `dbmax20years`
Unit: C
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... | codesearchnet |
def set_zone(timezone):
if timezone.lower() in mapper.win_to_unix:
win_zone = timezone
elif timezone.lower() in mapper.unix_to_win:
win_zone = mapper.get_win(timezone)
else:
raise CommandExecutionError('Invalid timezone passed: {0}'.format(timezone))
... | Sets the timezone using the tzutil.
Args:
timezone (str): A valid timezone
Returns:
bool: ``True`` if successful, otherwise ``False``
Raises:
CommandExecutionError: If invalid timezone is passed
CLI Example:
.. code-block:: bash
salt '*' timezone.set_zone 'America/Denver' | juraj-google-style |
def _binary_3d_label_to_sparse_value(labels):
indices = []
values = []
for d0, labels_d0 in enumerate(labels):
for d1, labels_d1 in enumerate(labels_d0):
d2 = 0
for class_id, label in enumerate(labels_d1):
if label == 1:
values.append(class... | Convert dense 3D binary indicator tensor to sparse tensor.
Only 1 values in `labels` are included in result.
Args:
labels: Dense 2D binary indicator tensor.
Returns:
`SparseTensorValue` whose values are indices along the last dimension of
`labels`. | github-repos |
def Get(self, project_id):
if project_id in self._emulators:
return self._emulators[project_id]
emulator = self.Create(project_id)
self._emulators[project_id] = emulator
return emulator | Returns an existing emulator instance for the provided project_id.
If an emulator instance doesn't yet exist, it creates one.
Args:
project_id: project ID
Returns:
a DatastoreEmulator | juraj-google-style |
def consume(self, message):
if (('jsonrpc' not in message) or (message['jsonrpc'] != JSONRPC_VERSION)):
log.warn('Unknown message type %s', message)
return
if ('id' not in message):
log.debug('Handling notification from client %s', message)
self._handle_notification(message['meth... | Consume a JSON RPC message from the client.
Args:
message (dict): The JSON RPC message sent by the client | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.