code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def get_new_profile_template(self):
uri = '{}/new-profile-template'.format(self.data['uri'])
return self._helper.do_get(uri) | Retrieves the profile template for a given server profile.
Returns:
dict: Server profile template. | codesearchnet |
def dump(self, content, filepath, indent=4):
with open(filepath, 'w') as fp:
json.dump(content, fp, indent=indent) | Dump settings content to filepath.
Args:
content (str): Settings content.
filepath (str): Settings file location. | juraj-google-style |
def get_range(self, start=None, stop=None):
return self.from_iterable(self.ranges(start, stop)) | Return a RangeMap for the range start to stop.
Returns:
A RangeMap | codesearchnet |
def get_module(module_abs_import):
logger.debug('starting')
logger.debug(f'loading module {module_abs_import}')
try:
imported_module = importlib.import_module(module_abs_import)
logger.debug('done')
return imported_module
except ModuleNotFoundError as err:
msg = f"The mod... | Use importlib to get the module dynamically.
Get instance of the module specified by the module_abs_import.
This means that module_abs_import must be resolvable from this package.
Args:
module_abs_import: string. Absolute name of module to import.
Raises:
PyModuleNotFoundError: if module not found. | codesearchnet |
def migrate_indexes(aggregate_indexes=None, forensic_indexes=None):
version = 2
if (aggregate_indexes is None):
aggregate_indexes = []
if (forensic_indexes is None):
forensic_indexes = []
for aggregate_index_name in aggregate_indexes:
if (not Index(aggregate_index_name).exists())... | Updates index mappings
Args:
aggregate_indexes (list): A list of aggregate index names
forensic_indexes (list): A list of forensic index names | codesearchnet |
def CheckGlobalStatic(filename, clean_lines, linenum, error):
line = clean_lines.elided[linenum]
if (((linenum + 1) < clean_lines.NumLines()) and (not Search('[;({]', line))):
line += clean_lines.elided[(linenum + 1)].strip()
match = Match('((?:|static +)(?:|const +))string +([a-zA-Z0-9_:]+)\\b(.*)'... | Check for unsafe global or static objects.
Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found. | codesearchnet |
def _grad_variance(self):
grad_var_ops = []
tensor_to_avg = []
for (t, g) in zip(self._vars, self._grad):
if isinstance(g, tf.IndexedSlices):
tensor_to_avg.append(tf.reshape(tf.unsorted_segment_sum(g.values, g.indices, g.dense_shape[0]), shape=t.get_shape()))
else:
te... | Estimate of gradient Variance.
Returns:
C_t ops. | codesearchnet |
def ReadFileObject(self, definitions_registry, file_object):
last_definition_object = None
error_location = None
error_message = None
try:
yaml_generator = yaml.safe_load_all(file_object)
for yaml_definition in yaml_generator:
definition_object = self._ReadDefinition(
... | Reads data type definitions from a file-like object into the registry.
Args:
definitions_registry (DataTypeDefinitionsRegistry): data type definitions
registry.
file_object (file): file-like object to read from.
Raises:
FormatError: if the definitions values are missing or if the format is
incorrect. | juraj-google-style |
def _build_select_and_next_from_expressions(self, builders: Tuple[column_expression_builder.ColumnExpressionBuilder, ...], child_builders: MutableSequence[column_expression_builder.ColumnExpressionBuilder], columns_selected: MutableSequence[str]) -> Tuple[MutableSequence[str], MutableSequence[str]]:
select_expressi... | Build select expressions and next from expressions from the builders.
Args:
builders: the immutable current builders to compute select expressions.
child_builders: collects the current given builders' children for the next
round.
columns_selected: accumulatively collects columns which has already been
handled complete... | github-repos |
def node_attributes(self, node_name, device_name=None):
if not self._debug_graphs:
raise LookupError('No partition graphs have been loaded.')
device_name = self._infer_device_name(device_name, node_name)
return self._debug_graphs[device_name].node_attributes[node_name] | Get the attributes of a node.
Args:
node_name: Name of the node in question.
device_name: (`str`) name of the device. If there is only one device or if
node_name exists on only one device, this argument is optional.
Returns:
Attributes of the node.
Raises:
LookupError: If no partition graphs have been loaded. | github-repos |
def cudnn_bi_gru(units, n_hidden, seq_lengths=None, n_layers=1, trainable_initial_states=False, name='cudnn_bi_gru', reuse=False):
with tf.variable_scope(name, reuse=reuse):
if (seq_lengths is None):
seq_lengths = (tf.ones([tf.shape(units)[0]], dtype=tf.int32) * tf.shape(units)[1])
with ... | Fast CuDNN Bi-GRU implementation
Args:
units: tf.Tensor with dimensions [B x T x F], where
B - batch size
T - number of tokens
F - features
n_hidden: dimensionality of hidden state
seq_lengths: number of tokens in each sample in the batch
n_layers: number of layers
trainable_initial_states: whether to create a special... | codesearchnet |
def print_args(output=sys.stdout):
def decorator(func):
@wraps(func)
def _(*args, **kwargs):
output.write(
"Args: {0}, KwArgs: {1}\n".format(str(args), str(kwargs)))
return func(*args, **kwargs)
return _
return decorator | Decorate a function so that print arguments before calling it.
Args:
output: writable to print args. (Default: sys.stdout) | juraj-google-style |
def _AnalyzeEvents(self, storage_writer, analysis_plugins, event_filter=None):
self._status = definitions.STATUS_INDICATOR_RUNNING
self._number_of_consumed_events = 0
self._number_of_consumed_reports = 0
self._number_of_consumed_sources = 0
self._number_of_consumed_warnings = 0
self._number... | Analyzes events in a plaso storage.
Args:
storage_writer (StorageWriter): storage writer.
analysis_plugins (dict[str, AnalysisPlugin]): analysis plugins that
should be run and their names.
event_filter (Optional[FilterObject]): event filter.
Returns:
collections.Counter: counter containing information about the event... | juraj-google-style |
def submodules(self):
submodules = []
submodules.extend(self.modules)
for p in self.packages:
submodules.extend(p.submodules)
return submodules | Property to return all sub-modules of the node, recursively.
Returns:
list of Module: the sub-modules. | codesearchnet |
def MakePmfFromList(t, name=''):
hist = MakeHistFromList(t)
d = hist.GetDict()
pmf = Pmf(d, name)
pmf.Normalize()
return pmf | Makes a PMF from an unsorted sequence of values.
Args:
t: sequence of numbers
name: string name for this PMF
Returns:
Pmf object | juraj-google-style |
def send_command(self, command, arg=None):
if arg is not None:
command = '%s:%s' % (command, arg)
self._write(six.StringIO(command), len(command)) | Sends a command to the device.
Args:
command: The command to send.
arg: Optional argument to the command. | juraj-google-style |
def delete_items_by_index(list_, index_list, copy=False):
if copy:
list_ = list_[:]
index_list_ = [((len(list_) + x) if (x < 0) else x) for x in index_list]
index_list_ = sorted(index_list_, reverse=True)
for index in index_list_:
del list_[index]
return list_ | Remove items from ``list_`` at positions specified in ``index_list``
The original ``list_`` is preserved if ``copy`` is True
Args:
list_ (list):
index_list (list):
copy (bool): preserves original list if True
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_list import * # NOQA
>>> list_ = [8, 1, 8, 1, 6, 6, 3, 4, ... | codesearchnet |
def __optimize_deconvolution_layer(self, learning_rate, epoch):
params_list = []
grads_list = []
for i in range(len(self.__deconvolution_layer_list)):
if self.__deconvolution_layer_list[i].delta_weight_arr.shape[0] > 0:
params_list.append(self.__deconvolutio... | Back propagation for Deconvolution layer.
Args:
learning_rate: Learning rate.
epoch: Now epoch. | juraj-google-style |
def convert_attribute_name_to_tag(value):
if (not isinstance(value, six.string_types)):
raise ValueError('The attribute name must be a string.')
for entry in attribute_name_tag_table:
if (value == entry[0]):
return entry[1]
raise ValueError("Unrecognized attribute name: '{}'".for... | A utility function that converts an attribute name string into the
corresponding attribute tag.
For example: 'State' -> enums.Tags.STATE
Args:
value (string): The string name of the attribute.
Returns:
enum: The Tags enumeration value that corresponds to the attribute
name string.
Raises:
ValueError: if the attribu... | codesearchnet |
def aggregate_groups(self, ct_agg, nr_groups, skip_key, carray_factor, groupby_cols, agg_ops, dtype_dict, bool_arr=None):
for col in groupby_cols:
result_array = ctable_ext.groupby_value(self[col], carray_factor, nr_groups, skip_key)
if (bool_arr is not None):
result_array = np.delete(re... | Perform aggregation and place the result in the given ctable.
Args:
ct_agg (ctable): the table to hold the aggregation
nr_groups (int): the number of groups (number of rows in output table)
skip_key (int): index of the output row to remove from results (used for filtering)
carray_factor: the carray for each row in the... | codesearchnet |
def Decompress(self, compressed_data):
try:
uncompressed_data = self._zlib_decompressor.decompress(compressed_data)
remaining_compressed_data = getattr(
self._zlib_decompressor, 'unused_data', b'')
except zlib.error as exception:
raise errors.BackEndError((
'Unable to... | Decompresses the compressed data.
Args:
compressed_data (bytes): compressed data.
Returns:
tuple(bytes, bytes): uncompressed data and remaining compressed data.
Raises:
BackEndError: if the zlib compressed stream cannot be decompressed. | juraj-google-style |
def emulate(self, context=None, start=None, end=None, arch_mode=None, hooks=None, max_instrs=None, print_asm=False):
if (arch_mode is not None):
self._load(arch_mode=arch_mode)
context = (context if context else {})
start_addr = (start if start else self.binary.ea_start)
end_addr = (end if end e... | Emulate native code.
Args:
context (dict): Processor context (register and/or memory).
start (int): Start address.
end (int): End address.
arch_mode (int): Architecture mode.
hooks (dict): Hooks by address.
max_instrs (int): Maximum number of instructions to execute.
print_asm (bool): Print asm.
Returns:
dict: Proces... | codesearchnet |
def learn(self, grad_arr):
encoder_delta_arr, _, encoder_grads_list = self.__encoder_decoder_controller.encoder.hidden_back_propagate(
grad_arr[:, -1]
)
encoder_grads_list.insert(0, None)
encoder_grads_list.insert(0, None)
self.__encoder_decoder_controller.e... | Update this Discriminator by ascending its stochastic gradient.
Args:
grad_arr: `np.ndarray` of gradients.
Returns:
`np.ndarray` of delta or gradients. | juraj-google-style |
def _txn_is_in_valid_batch(self, txn_id):
batch = self._batches_by_txn_id[txn_id]
return all((self._txn_results[sig].is_valid for sig in set(self._txn_results).intersection((txn.header_signature for txn in batch.transactions)))) | Returns whether the transaction is in a valid batch.
Args:
txn_id (str): The transaction header signature.
Returns:
(bool): True if the txn's batch is valid, False otherwise. | codesearchnet |
def _get_next_empty_bitmap(self):
for (i, byte) in enumerate(self._bitmap):
if (byte != 255):
for offset in range(8):
if (not (byte & (1 << offset))):
return ((i * 8) + offset) | Returns the next empty entry.
Returns:
int: The value of the empty entry | codesearchnet |
def get_wf_from_path(self, path):
with open(path) as fp:
content = fp.read()
return [(os.path.basename(os.path.splitext(path)[0]), content), ] | load xml from given path
Args:
path: diagram path
Returns: | juraj-google-style |
def chhome(name, home, **kwargs):
if six.PY2:
name = _to_unicode(name)
home = _to_unicode(home)
kwargs = salt.utils.args.clean_kwargs(**kwargs)
persist = kwargs.pop('persist', False)
if kwargs:
salt.utils.args.invalid_kwargs(kwargs)
if persist:
log.info('Ignorin... | Change the home directory of the user, pass True for persist to move files
to the new home directory if the old home directory exist.
Args:
name (str): The name of the user whose home directory you wish to change
home (str): The new location of the home directory
Returns:
bool: True if successful, otherwise False
C... | juraj-google-style |
def tf_step(
self,
time,
variables,
arguments,
fn_loss,
**kwargs
):
unperturbed_loss = fn_loss(**arguments)
perturbations = [tf.random_normal(shape=util.shape(variable)) * self.learning_rate for variable in variables]
applied... | Creates the TensorFlow operations for performing an optimization step.
Args:
time: Time tensor.
variables: List of variables to optimize.
arguments: Dict of arguments for callables, like fn_loss.
fn_loss: A callable returning the loss of the current model.
**kwargs: Additional arguments, not used.
Returns:
List of de... | juraj-google-style |
def get_all(self, attrs: Iterable[FetchAttribute]) -> Sequence[Tuple[(FetchAttribute, MaybeBytes)]]:
ret: List[Tuple[(FetchAttribute, MaybeBytes)]] = []
for attr in attrs:
try:
ret.append((attr.for_response, self.get(attr)))
except NotFetchable:
pass
return ret | Return a list of tuples containing the attribute iself and the bytes
representation of that attribute from the message.
Args:
attrs: The fetch attributes. | codesearchnet |
def top_rated(self, **kwargs):
path = self._get_path('top_rated')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Get the list of top rated movies. By default, this list will only
include movies that have 10 or more votes. This list refreshes every
day.
Args:
page: (optional) Minimum value of 1. Expected value is an integer.
language: (optional) ISO 639-1 code.
Returns:
A dict representation of the JSON returned from the API. | juraj-google-style |
def get_registry_data(self, name, auth_config=None):
return RegistryData(image_name=name, attrs=self.client.api.inspect_distribution(name, auth_config), client=self.client, collection=self) | Gets the registry data for an image.
Args:
name (str): The name of the image.
auth_config (dict): Override the credentials that are found in the
config for this request. ``auth_config`` should contain the
``username`` and ``password`` keys to be valid.
Returns:
(:py:class:`RegistryData`): The data object.
Raises:
:... | codesearchnet |
def gru_feedfwd(a_t, h_prev, filters, name=None):
with tf.variable_scope(name, default_name='GRU', values=[a_t, h_prev]):
z_t = tf.sigmoid((tpu_conv1d(a_t, filters, 1, padding='SAME', name='W_z') + tpu_conv1d(h_prev, filters, 1, padding='SAME', name='U_z')))
r_t = tf.sigmoid((tpu_conv1d(a_t, filters... | position-wise Feed-fwd GRU gates following the MPNN.
Args:
a_t: Tensor of shape [batch, length, depth] of current input
h_prev: Tensor of shape [batch, length, depth] of prev input
filters: an integer specifying number of dimensions of the filters
name: A string
Returns:
h_t: [batch, length, filters] hidden state | codesearchnet |
def node(self, force_new_node: bool=False) -> EventSetNode:
if self._internal_node is not None and (not force_new_node):
return self._internal_node
self._internal_node = create_node_with_new_reference(schema=self._schema, name=self._name)
return self._internal_node | Creates an [`EventSetNode`][temporian.EventSetNode] able to consume
this EventSet.
If called multiple times with `force_new_node=False` (default), the same
node is returned.
Usage example:
```python
>>> my_evset = tp.event_set(
... timestamps=[1, 2, 3, 4],
... features={
... "feature_1": [0.5, 0.6, np... | github-repos |
def acquire(self, blocking=True, timeout=-1):
result = self.lock.acquire(blocking, timeout)
return result | Acquire the :attr:`lock`
Args:
blocking (bool): See :meth:`threading.Lock.acquire`
timeout (float): See :meth:`threading.Lock.acquire`
Returns:
bool: :obj:`True` if the lock was acquired, otherwise :obj:`False` | juraj-google-style |
def module_import(module_path):
try:
module = __import__(module_path)
components = module_path.split('.')
for component in components[1:]:
module = getattr(module, component)
return module
except ImportError:
raise BadModulePathError(('Unable to find module "%... | Imports the module indicated in name
Args:
module_path: string representing a module path such as
'app.config' or 'app.extras.my_module'
Returns:
the module matching name of the last component, ie: for
'app.extras.my_module' it returns a
reference to my_module
Raises:
BadModulePathError if the module is not found | codesearchnet |
def unpause(self, container):
url = self._url('/containers/{0}/unpause', container)
res = self._post(url)
self._raise_for_status(res) | Unpause all processes within a container.
Args:
container (str): The container to unpause | codesearchnet |
def _in_gae_environment():
if (SETTINGS.env_name is not None):
return (SETTINGS.env_name in ('GAE_PRODUCTION', 'GAE_LOCAL'))
try:
import google.appengine
except ImportError:
pass
else:
server_software = os.environ.get(_SERVER_SOFTWARE, '')
if server_software.start... | Detects if the code is running in the App Engine environment.
Returns:
True if running in the GAE environment, False otherwise. | codesearchnet |
async def destroy_tournament(self, t: Tournament):
(await self.connection('DELETE', 'tournaments/{}'.format(t.id)))
if (t in self.tournaments):
self.tournaments.remove(t) | completely removes a tournament from Challonge
|methcoro|
Note:
|from_api| Deletes a tournament along with all its associated records. There is no undo, so use with care!
Raises:
APIException | codesearchnet |
def index_last_dim_with_indices(x, indices):
assert (len(x.shape) == (len(indices.shape) + 1))
x_shape = shape_list(x)
vocab_size = x_shape[(- 1)]
flat_x = tf.reshape(x, [list_product(x_shape[:(- 1)]), vocab_size])
flat_indices = tf.reshape(indices, [list_product(x_shape[:(- 1)])])
idx = tf.stac... | Use indices to index into the last axis of x.
This can be useful for recovering the actual probabilities of a sample from a
probability distribution.
Args:
x: Tensor, n-d.
indices: Tensor, (n-1)-d, where the dimension sizes match the first (n-1)
dimensions of x. The values of indices will be used to index into the la... | codesearchnet |
def derive_field_name(self, field_name):
cls = type(self)
return cls(
self[0],
self[1],
self[2],
field_name,
self[4],
self[5]
) | Derives a new event from this one setting the ``field_name`` attribute.
Args:
field_name (Union[amazon.ion.symbols.SymbolToken, unicode]): The field name to set.
Returns:
IonEvent: The newly generated event. | juraj-google-style |
def call(self, input_ids: TFModelInputType=None, attention_mask: tf.Tensor | None=None, decoder_input_ids: tf.Tensor | None=None, decoder_attention_mask: tf.Tensor | None=None, decoder_position_ids: tf.Tensor | None=None, head_mask: tf.Tensor | None=None, decoder_head_mask: tf.Tensor | None=None, cross_attn_head_mask: ... | labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
(masked), the loss is only computed for the toke... | github-repos |
def validate_gcs_path(path, require_object):
bucket, key = datalab.storage._bucket.parse_name(path)
if bucket is None:
raise Exception('Invalid GCS path "%s"' % path)
if require_object and key is None:
raise Exception('It appears the GCS path "%s" is a bucket path but not an object path' % path) | Check whether a given path is a valid GCS path.
Args:
path: the config to check.
require_object: if True, the path has to be an object path but not bucket path.
Raises:
Exception if the path is invalid | juraj-google-style |
def ensure_app_config_dir(appname, *args):
from ubelt import util_path
dpath = get_app_config_dir(appname, *args)
util_path.ensuredir(dpath)
return dpath | Calls `get_app_config_dir` but ensures the directory exists.
Args:
appname (str): the name of the application
*args: any other subdirectories may be specified
SeeAlso:
get_app_config_dir
Example:
>>> import ubelt as ub
>>> dpath = ub.ensure_app_config_dir('ubelt')
>>> assert exists(dpath) | juraj-google-style |
def read_graph_from_string(txt):
if (not txt.startswith('{')):
return read_dot(txt)
def conv(value):
if isinstance(value, basestring):
return (('"' + value) + '"')
else:
return value
doc = literal_eval(txt)
g = digraph()
for (attrs, values) in doc.get... | Read a graph from a string, either in dot format, or our own
compressed format.
Returns:
`pygraph.digraph`: Graph object. | codesearchnet |
def to_json_file(self, json_file_path: Union[str, os.PathLike]):
with open(json_file_path, 'w', encoding='utf-8') as writer:
writer.write(self.to_json_string()) | Save this instance to a JSON file.
Args:
json_file_path (`str` or `os.PathLike`):
Path to the JSON file in which this processor instance's parameters will be saved. | github-repos |
def run(cls, **kwargs):
err_pointer, tmp_pointer, new_bytes = 0, 0, 0
print_logs_live = kwargs.pop("print_logs_live", None)
cmd = cls.create(**kwargs)
sighandler = SignalHandler()
while not Command.is_done(cmd.status):
if sighandler.received_ter... | Create a command object by issuing a POST request to the /command endpoint
Waits until the command is complete. Repeatedly polls to check status
Args:
`**kwargs`: keyword arguments specific to command type
Returns:
Command object | juraj-google-style |
def get_all_if_deleted(self):
with self._lock:
results = {}
for (add, fut) in self._state.items():
if self._contains_and_deleted(add):
results[add] = fut.result()
return results | Return all the addresses deleted in the context.
Useful in the squash method.
Returns:
(dict of str to bytes): The addresses and bytes that have
been deleted in the context. | codesearchnet |
def normalize(self, inplace=False):
if inplace:
nrm = self.norm()
self.data /= nrm
return None
nrm = self.norm()
data_copy = np.array(self.data, copy=True)
data_copy /= nrm
return Quaternion(data_copy) | Normalizes a Quaternion to unit length
so that it represents a valid rotation.
Args:
inplace (bool): Do an inplace normalization.
Returns:
Quaternion: Normalized quaternion. | codesearchnet |
def get_contacts(self):
for (jid, item) in self.roster.items.items():
try:
self._contacts[jid.bare()].update(item.export_as_json())
except KeyError:
self._contacts[jid.bare()] = item.export_as_json()
return self._contacts | Returns list of contacts
Returns:
dict: the roster of contacts | codesearchnet |
def absl_to_standard(level):
if (not isinstance(level, int)):
raise TypeError('Expect an int level, found {}'.format(type(level)))
if (level < ABSL_FATAL):
level = ABSL_FATAL
if (level <= ABSL_DEBUG):
return ABSL_TO_STANDARD[level]
return ((STANDARD_DEBUG - level) + 1) | Converts an integer level from the absl value to the standard value.
Args:
level: int, an absl.logging level.
Raises:
TypeError: Raised when level is not an integer.
Returns:
The corresponding integer level for use in standard logging. | codesearchnet |
def create_asset_delivery_policy(access_token, ams_account, key_delivery_url):
path = '/AssetDeliveryPolicies'
endpoint = ''.join([ams_rest_endpoint, path])
body = (('{ \t\t"Name":"AssetDeliveryPolicy", \t\t"AssetDeliveryProtocol":"4", \t\t"AssetDeliveryPolicyType":"3", \t\t"AssetDeliveryConfiguration":"[{ ... | Create Media Service Asset Delivery Policy.
Args:
access_token (str): A valid Azure authentication token.
ams_account (str): Media Service Account.
Returns:
HTTP response. JSON body. | codesearchnet |
def authenticate(json_path=None):
msg = 'budou.authentication() is deprecated. Please use budou.get_parser() to obtain a parser instead.'
warnings.warn(msg, DeprecationWarning)
parser = get_parser('nlapi', credentials_path=json_path)
return parser | Gets a Natural Language API parser by authenticating the API.
**This method is deprecated.** Please use :obj:`budou.get_parser` to obtain a
parser instead.
Args:
json_path (:obj:`str`, optional): The file path to the service account's
credentials.
Returns:
Parser. (:obj:`budou.parser.NLAPIParser`) | codesearchnet |
def get_compiler_ir(self, device_name, platform_name, function_name, flat_args, captured_inputs, stage='hlo'):
return pywrap_tfe.TF_GetCompilerIr(self._context_handle, function_name, stage, device_name, flat_args, captured_inputs, platform_name) | Get the compiler IR bytes.
Args:
device_name: The name of the device with the form as
"/job:localhost/replica:0/task:0/device:CPU:0", "/device:TPU:0" etc.
When this is used, actual device is needed for getting the compiler IR.
platform_name: The name of the platform, e.g. "TPU". When this is used,
first we find a devi... | github-repos |
def copy_scoped_meta_graph(from_scope, to_scope, from_graph=None, to_graph=None):
from_graph = from_graph or ops.get_default_graph()
to_graph = to_graph or ops.get_default_graph()
if from_graph == to_graph and from_scope == to_scope:
raise ValueError(f"'from_scope' and 'to_scope' need to be differen... | Copies a sub-meta_graph from one scope to another.
Args:
from_scope: `String` name scope containing the subgraph to be copied.
to_scope: `String` name scope under which the copied subgraph will reside.
from_graph: Optional `Graph` from which to copy the subgraph. If `None`, the
default graph is use.
to_graph: Optional... | github-repos |
def df(self):
import pandas as pd
return pd.concat([w.df(uwi=True) for w in self]) | Makes a pandas DataFrame containing Curve data for all the wells
in the Project. The DataFrame has a dual index of well UWI and
curve Depths. Requires `pandas`.
Args:
No arguments.
Returns:
`pandas.DataFrame`. | juraj-google-style |
def eval_algorithm(curr, prev):
if curr['close'] > prev['close']:
v = curr['volume']
elif curr['close'] < prev['close']:
v = curr['volume'] * -1
else:
v = 0
return prev['obv'] + v | Evaluates OBV
Args:
curr: Dict of current volume and close
prev: Dict of previous OBV and close
Returns:
Float of OBV | juraj-google-style |
def create(self, name, nopassword=None, secret=None, encryption=None):
if (secret is not None):
return self.create_with_secret(name, secret, encryption)
elif (nopassword is True):
return self.create_with_nopassword(name)
else:
raise TypeError('either "nopassword" or "secret" must be ... | Creates a new user on the local system.
Creating users requires either a secret (password) or the nopassword
keyword to be specified.
Args:
name (str): The name of the user to craete
nopassword (bool): Configures the user to be able to authenticate
without a password challenage
secret (str): The secret (password) t... | codesearchnet |
def parse_mapping(mapping_file: Optional[str]) -> configparser.ConfigParser:
LOGGER.debug('Parsing mapping file. Command line: %s', mapping_file)
def parse(mapping_file):
config = configparser.ConfigParser()
config.read_file(mapping_file)
return config
if (mapping_file is not None):... | Parse the file containing the mappings from hosts to pass entries.
Args:
mapping_file:
Name of the file to parse. If ``None``, the default file from the
XDG location is used. | codesearchnet |
def identity(n, dtype=None):
return backend.numpy.identity(n, dtype=dtype) | Return the identity tensor.
The identity tensor is a square tensor with ones on the main diagonal and
zeros elsewhere.
Args:
n: Number of rows (and columns) in the `n x n` output tensor.
dtype: Data type of the output tensor.
Returns:
The identity tensor. | github-repos |
def get(self, file_path, ref, **kwargs):
file_path = file_path.replace('/', '%2F')
return GetMixin.get(self, file_path, ref=ref, **kwargs) | Retrieve a single file.
Args:
file_path (str): Path of the file to retrieve
ref (str): Name of the branch, tag or commit
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the file could not be retrieved
Returns:
object: Th... | juraj-google-style |
def _copy_hdxobjects(self, hdxobjects, hdxobjectclass, attribute_to_copy=None):
newhdxobjects = list()
for hdxobject in hdxobjects:
newhdxobjectdata = copy.deepcopy(hdxobject.data)
newhdxobject = hdxobjectclass(newhdxobjectdata, configuration=self.configuration)... | Helper function to make a deep copy of a supplied list of HDX objects
Args:
hdxobjects (List[T <= HDXObject]): list of HDX objects to copy
hdxobjectclass (type): Type of the HDX Objects to be copied
attribute_to_copy (Optional[str]): An attribute to copy over from the HDX object. Defaults to None.
Returns:
List[T <= ... | juraj-google-style |
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. | juraj-google-style |
def __init__(self, maxsize=0):
self._maxsize = maxsize
self._queue = collections.deque()
self._closed = False
self._mutex = threading.Lock()
self._not_empty = threading.Condition(self._mutex)
self._not_full = threading.Condition(self._mutex) | Create a queue object with a given maximum size.
Args:
maxsize: int size of queue. If <= 0, the queue size is infinite. | github-repos |
def _future_command_unlocked(self, cmd):
future = self._loop.create_future()
asyncio_loop = self._loop.get_loop()
def _done_callback(result):
retval = result['return_value']
if not result['result']:
future.set_exception(HardwareError("Error exe... | Run command as a coroutine and return a future.
Args:
loop (BackgroundEventLoop): The loop that we should attach
the future too.
cmd (list): The command and arguments that we wish to call.
Returns:
asyncio.Future: An awaitable future with the result of the operation. | juraj-google-style |
def _get_tables(self, base_dir):
table_dict = {}
for table in self.metadata['tables']:
if table['use']:
relative_path = os.path.join(base_dir, self.metadata['path'], table['path'])
data_table = pd.read_csv(relative_path)
pii_fields = self._get_pii_fields(table)
... | Load the contents of meta_file and the corresponding data.
If fields containing Personally Identifiable Information are detected in the metadata
they are anonymized before asign them into `table_dict`.
Args:
base_dir(str): Root folder of the dataset files.
Returns:
dict: Mapping str -> tuple(pandas.DataFrame, dict) | codesearchnet |
def initialize_environments(self, batch_size=1):
assert batch_size >= 1
self._batch_size = batch_size
self._envs = [gym.make(self.base_env_name) for _ in range(batch_size)]
if self._env_wrapper_fn is not None:
self._envs = list(map(self._env_wrapper_fn, self._envs))
if se... | Initializes the environments and trajectories.
Subclasses can override this if they don't want a default implementation
which initializes `batch_size` environments, but must take care to
initialize self._trajectories (this is checked in __init__ anyways).
Args:
batch_size: (int) Number of `self.base_env_name` envs to... | juraj-google-style |
def files_comments_add(self, *, comment: str, file: str, **kwargs) -> SlackResponse:
kwargs.update({"comment": comment, "file": file})
return self.api_call("files.comments.add", json=kwargs) | Add a comment to an existing file.
Args:
comment (str): The body of the comment.
e.g. 'Everyone should take a moment to read this file.'
file (str): The file id. e.g. 'F1234467890' | juraj-google-style |
def rjust_text(text, width=80, indent=0, subsequent=None):
text = re.sub(r"\s+", " ", text).strip()
if subsequent is None:
subsequent = indent
wrapper = TextWrapper(
width=width,
break_long_words=False,
replace_whitespace=True,
initial_indent=" " * (indent + subs... | Wrap text and adjust it to right border.
Same as L{wrap_text} with the difference that the text is aligned against
the right text border.
Args:
text (str): Text to wrap and align.
width (int): Maximum number of characters per line.
indent (int): Indentation of the first line.
subsequent (int or None): Indentation of ... | juraj-google-style |
def _CheckWindowsRegistryKeyPath(self, filename, artifact_definition, key_path):
result = True
key_path_segments = key_path.lower().split('\\')
if (key_path_segments[0] == '%%current_control_set%%'):
result = False
logging.warning('Artifact definition: {0:s} in file: {1:s} contains Windows R... | Checks if a path is a valid Windows Registry key path.
Args:
filename (str): name of the artifacts definition file.
artifact_definition (ArtifactDefinition): artifact definition.
key_path (str): Windows Registry key path to validate.
Returns:
bool: True if the Windows Registry key path is valid. | codesearchnet |
def parse_uri(self, uri=None):
if (not uri):
return rdflib.term.URIRef(self.root)
elif (type(uri) == str):
if ((type(uri) == str) and (not uri.startswith('http'))):
return rdflib.term.URIRef(('%s%s' % (self.root, uri)))
else:
return rdflib.term.URIRef(uri)
eli... | parses and cleans up possible uri inputs, return instance of rdflib.term.URIRef
Args:
uri (rdflib.term.URIRef,str): input URI
Returns:
rdflib.term.URIRef | codesearchnet |
def deep_update(original, new_dict, new_keys_allowed, whitelist):
for (k, value) in new_dict.items():
if (k not in original):
if (not new_keys_allowed):
raise Exception('Unknown config parameter `{}` '.format(k))
if isinstance(original.get(k), dict):
if (k in ... | Updates original dict with values from new_dict recursively.
If new key is introduced in new_dict, then if new_keys_allowed is not
True, an error will be thrown. Further, for sub-dicts, if the key is
in the whitelist, then new subkeys can be introduced.
Args:
original (dict): Dictionary with default values.
new_dict (... | codesearchnet |
def List(self, request, global_params=None):
config = self.GetMethodConfig('List')
return self._RunMethod(config, request, global_params=global_params) | Lists all projects to which you have been granted any project role.
Args:
request: (BigqueryProjectsListRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(ProjectList) The response message. | github-repos |
def tf_step(self, time, variables, **kwargs):
fn_loss = kwargs['fn_loss']
if (variables is None):
variables = tf.trainable_variables
return tf.gradients(fn_loss, variables) | Creates the TensorFlow operations for performing an optimization step on the given variables, including
actually changing the values of the variables.
Args:
time: Time tensor. Not used for this optimizer.
variables: List of variables to optimize.
**kwargs:
fn_loss : loss function tensor to differentiate.
Returns:
Lis... | codesearchnet |
def compute_average_oxidation_state(site):
try:
avg_oxi = sum([sp.oxi_state * occu
for sp, occu in site.species.items()
if sp is not None])
return avg_oxi
except AttributeError:
pass
try:
return site.charge
except Attribu... | Calculates the average oxidation state of a site
Args:
site: Site to compute average oxidation state
Returns:
Average oxidation state of site. | juraj-google-style |
def max_zoom(self):
zoom_levels = [map_layer.max_zoom for map_layer in self.layers]
return max(zoom_levels) | Get the maximal zoom level of all layers.
Returns:
int: the maximum of all zoom levels of all layers
Raises:
ValueError: if no layers exist | codesearchnet |
def get(self, name):
name = str(name)
if (name not in self._properties):
raise ArgumentError('Unknown property in DeviceModel', name=name)
return self._properties[name] | Get a device model property.
Args:
name (str): The name of the property to get | codesearchnet |
def __init__(self, key, committed, attempted):
self.key = key
self.committed = committed
self.attempted = attempted | Initializes ``MetricResult``.
Args:
key: A ``MetricKey`` object.
committed: Metric data that has been committed (e.g. logical updates)
attempted: Metric data that has been attempted (e.g. physical updates) | github-repos |
def extract_certs(certs_txt: str) -> List[crypto.X509]:
pattern = r'-----BEGIN CERTIFICATE-----.+?-----END CERTIFICATE-----'
certs_txt = re.findall(pattern, certs_txt, flags=re.DOTALL)
certs = [crypto.load_certificate(crypto.FILETYPE_PEM, cert_txt) for cert_txt in certs_txt]
return certs | Extracts pycrypto X509 objects from SSL certificates chain string.
Args:
certs_txt: SSL certificates chain string.
Returns:
result: List of pycrypto X509 objects. | juraj-google-style |
def _pad_batch(self, images: list['torch.Tensor'], return_tensors: Optional[Union[str, TensorType]]) -> tuple:
max_size = get_max_height_width(images)
grouped_images, grouped_images_index = group_images_by_shape(images)
processed_images = {}
processed_masks = {}
for shape, stacked_images in grouped_... | Pad a batch of images to the same size based on the maximum dimensions.
Args:
images (`list[torch.Tensor]`): List of images to pad.
return_tensors (`str` or `TensorType`, *optional*): The type of tensors to return.
Returns:
`tuple`: Tuple containing padded images and pixel masks. | github-repos |
def geotiff(self, **kwargs):
if ('proj' not in kwargs):
kwargs['proj'] = self.proj
return to_geotiff(self, **kwargs) | Creates a geotiff on the filesystem
Args:
path (str): optional, path to write the geotiff file to, default is ./output.tif
proj (str): optional, EPSG string of projection to reproject to
spec (str): optional, if set to 'rgb', write out color-balanced 8-bit RGB tif
bands (list): optional, list of bands to export. If sp... | codesearchnet |
def _GetUsernameFromProfilePath(self, path):
while path and path[-1] == '\\':
path = path[:-1]
if path:
_, _, path = path.rpartition('\\')
return path | Retrieves the username from a Windows profile path.
Trailing path path segment are ignored.
Args:
path (str): a Windows path with '\\' as path segment separator.
Returns:
str: basename which is the last path segment. | juraj-google-style |
def on_value_event(self, event):
raise NotImplementedError('on_value_event() is not implemented in the base servicer class') | Callback for Event proto received through the gRPC stream.
This Event proto carries a Tensor in its summary.value[0] field.
Args:
event: The Event proto from the stream to be processed. | github-repos |
def multi_rouge_n(sequences, scores_ids, n=2):
ngrams = [_get_word_ngrams(n, sequence) for sequence in sequences]
counts = [len(ngram) for ngram in ngrams]
scores = []
for (hyp_id, ref_id) in scores_ids:
evaluated_ngrams = ngrams[hyp_id]
evaluated_count = counts[hyp_id]
reference... | Efficient way to compute highly repetitive scoring
i.e. sequences are involved multiple time
Args:
sequences(list[str]): list of sequences (either hyp or ref)
scores_ids(list[tuple(int)]): list of pairs (hyp_id, ref_id)
ie. scores[i] = rouge_n(scores_ids[i][0],
scores_ids[i][1])
Returns:
scores: list of length `len(s... | codesearchnet |
def decode(self, encoded):
encoded = super().decode(encoded)
return self.tokenizer.decode([self.itos[index] for index in encoded]) | Decodes a tensor into a sequence.
Args:
encoded (torch.Tensor): Encoded sequence.
Returns:
str: Sequence decoded from ``encoded``. | juraj-google-style |
def phase_uniquizer(all_phases):
measurement_name_maker = UniqueNameMaker(
itertools.chain.from_iterable(
phase.measurements.keys() for phase in all_phases
if phase.measurements))
attachment_names = list(itertools.chain.from_iterable(
phase.attachments.keys() for phase in all_phas... | Makes the names of phase measurement and attachments unique.
This function will make the names of measurements and attachments unique.
It modifies the input all_phases.
Args:
all_phases: the phases to make unique
Returns:
the phases now modified. | juraj-google-style |
def _shape_invariant_to_type_spec(self, shape):
raise NotImplementedError(f'{type(self).__name__}._shape_invariant_to_type_spec') | Returns a TypeSpec given a shape invariant (used by `tf.while_loop`).
Args:
shape: A `tf.TensorShape` object. The shape invariant for this
`CompositeTensor`, or `None` if a default shape invariant should be used
(based on the value of this `CompositeTensor`).
Returns:
A nested structure whose values are `tf.TensorSh... | github-repos |
def determine_action(self, issue):
resource_type = self.resource_types[issue.resource.resource_type_id]
issue_alert_schedule = self.alert_schedule[resource_type] if \
resource_type in self.alert_schedule \
else self.alert_schedule['*']
action_item = {
... | Determine the action we should take for the issue
Args:
issue: Issue to determine action for
Returns:
`dict` | juraj-google-style |
def navbar(self):
window = BaseWindow(self.selenium, self.selenium.current_window_handle)
with self.selenium.context(self.selenium.CONTEXT_CHROME):
el = self.selenium.find_element(*self._nav_bar_locator)
return NavBar(window, el) | Provide access to the Navigation Bar.
Returns:
:py:class:`NavBar`: FoxPuppet NavBar object. | codesearchnet |
def save_image(tensor, filename, nrow=8, padding=2, pad_value=0):
from PIL import Image
grid = make_grid(tensor, nrow=nrow, padding=padding, pad_value=pad_value)
im = Image.fromarray(pre_pillow_float_img_process(grid))
im.save(filename) | Save a given Tensor into an image file.
Args:
tensor (Tensor or list): Image to be saved. If given a mini-batch tensor,
saves the tensor as a grid of images by calling ``make_grid``.
**kwargs: Other arguments are documented in ``make_grid``. | codesearchnet |
def from_stat_file(cls, statfile, timestep=1, is_leap_year=False):
stat = STAT(statfile)
def check_missing(opt_data, data_name):
if (opt_data == []):
raise ValueError('Stat file contains no optical data.')
for (i, x) in enumerate(opt_data):
if (x is None):
... | Create an ASHRAE Revised Clear Sky wea object from the monthly sky
optical depths in a .stat file.
Args:
statfile: Full path to the .stat file.
timestep: An optional integer to set the number of time steps per
hour. Default is 1 for one value per hour.
is_leap_year: A boolean to indicate if values are representing a l... | codesearchnet |
def params(self):
payload = self.payload
d = {}
for (i, p) in enumerate(payload['currentConfiguration']):
type_name = p['typeName']
cp = payload['configurationParameters'][i]['message']
name = cp['parameterName']
if (type_name == 'BTMParameterQuantity'):
try:
... | Get the params of response data from the API.
Returns:
- d (dict): Dictionary mapping of all configuration values | codesearchnet |
def conv_json(self, uri_format='sparql_uri', add_ids=False):
def convert_item(ivalue):
' converts an idividual value to a json value\n\n Args:\n ivalue: value of the item to convert\n\n Returns:\n JSON serializable value\n '
nvalue = iv... | converts the class to a json compatable python dictionary
Args:
uri_format('sparql_uri','pyuri'): The format that uri values will
be returned
Returns:
dict: a json compatabile python dictionary | codesearchnet |
def declare(self, name, description=None, **kwargs):
if (not self._is_valid_key(name)):
raise self.InvalidKeyError('Invalid key name, must begin with a lowercase letter', name)
if (name in self._declarations):
raise self.KeyAlreadyDeclaredError('Configuration key already declared', name)
sel... | Declare a configuration key with the given name.
Args:
name: Configuration key to declare, must not have been already declared.
description: If provided, use this as the description for this key.
**kwargs: Other kwargs to pass to the Declaration, only default_value
is currently supported. | codesearchnet |
def __contains__(self, k):
chain = ChainMap(self.scopes, self.globals)
return chain.__contains__(k) | Check whether a variable has been assigned to.
This is **not** the same kind of element-of as described in the
class documentation.
Args:
k (str): The name of the variable to check.
Returns:
bool: Whether or not the variable has been assigned to. | juraj-google-style |
def put(value):
worker = global_worker
worker.check_connected()
with profiling.profile("ray.put"):
if worker.mode == LOCAL_MODE:
return value
object_id = ray._raylet.compute_put_id(
worker.current_task_id,
worker.task_context.put_index,
... | Store an object in the object store.
Args:
value: The Python object to be stored.
Returns:
The object ID assigned to this value. | juraj-google-style |
def convert_one(self, op: ops.Operation) -> ops.OP_TREE:
if not isinstance(op, ops.GateOperation):
raise TypeError("{!r} is not a gate operation.".format(op))
if is_native_ion_gate(op.gate):
return [op]
if isinstance(op.gate, ops.HPowGate) and... | Convert a single (one- or two-qubit) operation
into ion trap native gates
Args:
op: gate operation to be converted
Returns:
the desired operation implemented with ion trap gates | juraj-google-style |
def get_project_id():
if (os.name == 'nt'):
command = _CLOUD_SDK_WINDOWS_COMMAND
else:
command = _CLOUD_SDK_POSIX_COMMAND
try:
output = subprocess.check_output(((command,) + _CLOUD_SDK_CONFIG_COMMAND), stderr=subprocess.STDOUT)
except (subprocess.CalledProcessError, OSError, IOEr... | Gets the project ID from the Cloud SDK.
Returns:
Optional[str]: The project ID. | codesearchnet |
def get_metadata_attribute(self, metaname):
metadata_value = self.metadata.get(metaname, None)
if metadata_value is None:
raise NoMetadataException(
"No metadata attribute named %s" % metaname)
if not isinstance(metadata_value, list):
raise TypeEr... | Get the metadata attribute by the name.
Args:
metaname (:obj:`str`): Name of the attribute
Returns:
:obj:`list` or :obj:`str`: Value(s) of the requested metadata
attribute
Raises:
NoMetadataException: Attribute error
TypeError: Metadata should be a list | juraj-google-style |
def has_basal_dendrite(neuron, min_number=1, treefun=_read_neurite_type):
types = [treefun(n) for n in neuron.neurites]
return CheckResult((types.count(NeuriteType.basal_dendrite) >= min_number)) | Check if a neuron has basal dendrites
Arguments:
neuron(Neuron): The neuron object to test
min_number: minimum number of basal dendrites required
treefun: Optional function to calculate the tree type of neuron's
neurites
Returns:
CheckResult with result | codesearchnet |
def get_all_profiles(store='local'):
return {'Domain Profile': get_all_settings(profile='domain', store=store), 'Private Profile': get_all_settings(profile='private', store=store), 'Public Profile': get_all_settings(profile='public', store=store)} | Gets all properties for all profiles in the specified store
Args:
store (str):
The store to use. This is either the local firewall policy or the
policy defined by local group policy. Valid options are:
- lgpo
- local
Default is ``local``
Returns:
dict: A dictionary containing the specified settings for each profil... | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.