code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def GetDefinitionByName(self, name):
lookup_name = name.lower()
if lookup_name not in self._definitions:
lookup_name = self._aliases.get(name, None)
return self._definitions.get(lookup_name, None) | Retrieves a specific data type definition by name.
Args:
name (str): name of the data type definition.
Returns:
DataTypeDefinition: data type definition or None if not available. | juraj-google-style |
def grabEmails(emails=None, emailsFile=None, nicks=None, nicksFile=None, domains=EMAIL_DOMAINS, excludeDomains=[]):
email_candidates = []
if emails != None:
email_candidates = emails
elif emailsFile != None:
with open(emailsFile, "r") as iF:
email_candidates = iF.r... | Method that generates a list of emails.
Args:
-----
emails: Any premade list of emails.
emailsFile: Filepath to the emails file (one per line).
nicks: A list of aliases.
nicksFile: Filepath to the aliases file (one per line).
domains: Domains where the aliases will be tested.
excludeDomains: Domains to be excluded fro... | juraj-google-style |
def custom_object_save(obj: Any, folder: Union[str, os.PathLike], config: Optional[dict]=None) -> list[str]:
if obj.__module__ == '__main__':
logger.warning(f"We can't save the code defining {obj} in {folder} as it's been defined in __main__. You should put this code in a separate module so we can include i... | Save the modeling files corresponding to a custom model/configuration/tokenizer etc. in a given folder. Optionally
adds the proper fields in a config.
Args:
obj (`Any`): The object for which to save the module files.
folder (`str` or `os.PathLike`): The folder where to save.
config (`PretrainedConfig` or dictionary, `... | github-repos |
def gc_velocity_update(particle, social, state):
gbest = state.swarm[gbest_idx(state.swarm)].position
if not np.array_equal(gbest, particle.position):
return std_velocity(particle, social, state)
rho = state.params['rho']
inertia = state.params['inertia']
v_max = state.params['v_max']
... | Guaranteed convergence velocity update.
Args:
particle: cipy.algorithms.pso.Particle: Particle to update the velocity
for.
social: cipy.algorithms.pso.Particle: The social best for the particle.
state: cipy.algorithms.pso.State: The state of the PSO algorithm.
Returns:
numpy.ndarray: the calculated velocity. | juraj-google-style |
def parseTree(self, root, state: ParseState) -> List[Dict]:
if root.tag in self.AST_TAG_HANDLERS:
return self.AST_TAG_HANDLERS[root.tag](root, state)
elif root.tag in self.libRtns:
return self.process_libRtn(root, state)
else:
prog = []
... | Parses the XML ast tree recursively to generate a JSON AST
which can be ingested by other scripts to generate Python
scripts.
Args:
root: The current root of the tree.
state: The current state of the tree defined by an object of the
ParseState class.
Returns:
ast: A JSON ast that defines the structure of the Fortran ... | juraj-google-style |
def ParseArguments(args):
try:
(opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', 'counting=', 'filter=', 'root=', 'repository=', 'linelength=', 'extensions=', 'exclude=', 'headers=', 'quiet', 'recursive'])
except getopt.GetoptError:
PrintUsage('Invalid arguments.')
... | Parses the command line arguments.
This may set the output format and verbosity level as side-effects.
Args:
args: The command line arguments:
Returns:
The list of filenames to lint. | codesearchnet |
def return_item_count_on_page(self, page=1, total_items=1):
up_to_page = ((page - 1) * self.page_items)
if total_items > up_to_page:
count = total_items - up_to_page
if count >= self.page_items:
retur... | Return the number of items on page.
Args:
* page = The Page to test for
* total_items = the total item count
Returns:
* Integer - Which represents the calculated number of items on page. | juraj-google-style |
def setPANID(self, xPAN):
print '%s call setPANID' % self.port
print xPAN
panid = ''
try:
if not isinstance(xPAN, str):
panid = str(hex(xPAN))
print panid
cmd = WPANCTL_CMD + 'setprop -s Network:PANID %s' % panid
... | set Thread Network PAN ID
Args:
xPAN: a given PAN ID in hex format
Returns:
True: successful to set the Thread Network PAN ID
False: fail to set the Thread Network PAN ID | juraj-google-style |
def _transition_instrumentation_block(self, instrumentation_block, new_state=_InstrumentationBlockStates.UNKNOWN):
formatters = self._create_formatters(instrumentation_block, new_state)
for formatter in formatters:
test_record = formatter.create_test_record(self.TAG)
if test_record:
... | Transitions and finishes the current instrumentation block.
Args:
instrumentation_block: _InstrumentationBlock, the current
instrumentation block to finish.
new_state: _InstrumentationBlockState, the next state for the
parser to transition to.
Returns:
The new instrumentation block to use for storing parsed
instrumen... | github-repos |
def store_to_file(self, filename):
with tf.gfile.Open(filename, 'w') as f:
for i in range(len(self._id_to_token)):
f.write((self._id_to_token[i] + '\n')) | Write vocab file to disk.
Vocab files have one token per line. The file ends in a newline. Reserved
tokens are written to the vocab file as well.
Args:
filename: Full path of the file to store the vocab to. | codesearchnet |
def broadcast_to_rank(self, rank):
if self.rank is None:
raise ValueError('Unable to broadcast: self.rank is unknown')
dims_to_add = rank - self.rank
if dims_to_add < 0:
raise ValueError('Unable to broadcast: rank=%d must be greater than self.rank=%d.' % (rank, self.rank))
elif dims_to_a... | Adds leading size-1 dimensions to broadcast `self` to the given rank.
E.g., if `shape1` is `[3, (D2), 4]`, then `shape1.broadcast_to_rank(5)`
is `[1, 1, 3, (D2), 4]`.
Args:
rank: The rank for the returned shape.
Returns:
A RaggedTensorDynamicShape with `rank` dimensions, whose inner dimensions
have the same size as ... | github-repos |
def modify_user_power_levels(self, users=None, users_default=None):
try:
content = self.client.api.get_power_levels(self.room_id)
if users_default:
content['users_default'] = users_default
if users:
if ('users' in content):
content['users'].update(user... | Modify the power level for a subset of users
Args:
users(dict): Power levels to assign to specific users, in the form
{"@name0:host0": 10, "@name1:host1": 100, "@name3:host3", None}
A level of None causes the user to revert to the default level
as specified by users_default.
users_default(int): Default power level for... | codesearchnet |
def _InsertNodeAt(new_node, target, after=False):
if new_node.parent is not None:
raise RuntimeError('inserting node which already has a parent', (new_node, new_node.parent))
parent_of_target = target.parent
if parent_of_target is None:
raise RuntimeError('expected target node to have a pare... | Underlying implementation for node insertion.
Arguments:
new_node: a new node to insert (this node should not be in the tree).
target: the target node.
after: if True, new_node is inserted after target. Otherwise, it's inserted
before target.
Returns:
nothing
Raises:
RuntimeError: if the tree is corrupted, or the in... | github-repos |
def _restore_resources(resources):
resources = deepcopy(resources)
for resource in resources:
schema = resource['schema']
for fk in schema.get('foreignKeys', []):
(_, name) = _restore_path(fk['reference']['resource'])
fk['reference']['resource'] = name
return resource... | Restore schemas from being compatible with storage schemas.
Foreign keys related operations.
Args:
list: resources from storage
Returns:
list: restored resources | codesearchnet |
def _get_sorted_methods(self, methods):
if (not methods):
return methods
def _sorted_methods_comparison(method_info1, method_info2):
"Sort method info by path and http_method.\n\n Args:\n method_info1: Method name and info for the first method to compare.\n method_info2: Meth... | Get a copy of 'methods' sorted the way they would be on the live server.
Args:
methods: JSON configuration of an API's methods.
Returns:
The same configuration with the methods sorted based on what order
they'll be checked by the server. | codesearchnet |
def port_remove(br, port, if_exists=True):
param_if_exists = _param_if_exists(if_exists)
if port and not br:
cmd = 'ovs-vsctl {1}del-port {0}'.format(port, param_if_exists)
else:
cmd = 'ovs-vsctl {2}del-port {0} {1}'.format(br, port, param_if_exists)
result = __salt__['cmd.run_all'... | Deletes port.
Args:
br: A string - bridge name (If bridge is None, port is removed from whatever bridge contains it)
port: A string - port name.
if_exists: Bool, if False - attempting to delete a por that does not exist returns False. (Default True)
Returns:
True on success, else False.
.. versionadded:: 2016.3.0... | juraj-google-style |
def file_path(path=None, payload=None, objectInput=None):
f = path if path else write_payload(payload, objectInput)
if not os.path.exists(f):
msg = "File {!r} does not exist".format(f)
log.exception(msg)
raise TikaAppFilePathError(msg)
return f | Given a file path, payload or file object, it writes file on disk and
returns the temp path.
Args:
path (string): path of real file
payload(string): payload in base64 of file
objectInput (object): file object/standard input to analyze
Returns:
Path of file | juraj-google-style |
def load(path):
with open(path, 'r') as fobj:
analytics = Analytics(info=json.load(fobj))
os.unlink(path)
return analytics | Loads analytics report from json file specified by path.
Args:
path (str): path to json file with analytics report. | codesearchnet |
def _compute_version_info():
ray_version = ray.__version__
python_version = '.'.join(map(str, sys.version_info[:3]))
pyarrow_version = pyarrow.__version__
return (ray_version, python_version, pyarrow_version) | Compute the versions of Python, pyarrow, and Ray.
Returns:
A tuple containing the version information. | codesearchnet |
def create_position_ids_from_input_ids(self, input_ids):
mask = tf.cast(tf.math.not_equal(input_ids, self.padding_idx), dtype=input_ids.dtype)
incremental_indices = tf.math.cumsum(mask, axis=1) * mask
return incremental_indices + self.padding_idx | Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding
symbols are ignored. This is modified from fairseq's `utils.make_positions`.
Args:
input_ids: tf.Tensor
Returns: tf.Tensor | github-repos |
def _parse_field_value(self, field: descriptor.FieldDescriptor, json_value: Any) -> message.Message:
if field.type != descriptor.FieldDescriptor.TYPE_MESSAGE:
raise ValueError(f'Error in FHIR proto definition, field: {field.full_name} is not a message.')
if field.message_type.full_name == any_pb2.Any.DE... | Returns a new Message described by the FieldDescriptor and json_value.
Args:
field: The FieldDescriptor of the Message instance to create.
json_value: The JSON value representation to merge into the newly created
Message.
Returns:
A new Message as described by the provided FieldDescriptor merged with the
contents of ... | github-repos |
def center_crop(self, image: 'torch.Tensor', crop_size: dict[str, int], size: dict[str, int], **kwargs) -> 'torch.Tensor':
if size.height is None or size.width is None:
raise ValueError(f"The size dictionary must have keys 'height' and 'width'. Got {size.keys()}")
height, width = image.shape[-2:]
mi... | Center crop an image to `(size["height"] / crop_size["height"] * min_dim, size["width"] / crop_size["width"] *
min_dim)`. Where `min_dim = min(size["height"], size["width"])`.
If the input size is smaller than `crop_size` along any edge, the image will be padded with zeros and then
center cropped.
Args:
image (`"torc... | github-repos |
async def remember(self, request, user_id):
ticket = self._new_ticket(request, user_id)
await self.remember_ticket(request, ticket) | Called to store the userid for a request.
This function creates a ticket from the request and user_id, and calls
the abstract function remember_ticket() to store the ticket.
Args:
request: aiohttp Request object.
user_id: String representing the user_id to remember | juraj-google-style |
def read_handler(Model, name=None, **kwds):
async def action_handler(service, action_type, payload, props, **kwds):
if (action_type == get_crud_action('read', (name or Model))):
message_props = {}
if ('correlation_id' in props):
message_props['correlation_id'] = prop... | This factory returns an action handler that responds to read requests
by resolving the payload as a graphql query against the internal schema.
Args:
Model (nautilus.BaseModel): The model to delete when the action
received.
Returns:
function(type, payload): The action handler for this model | codesearchnet |
def set_contrast(self, contrast):
self._contrast = contrast
self.x_spread = (2 * (1.0 - contrast))
self.y_spread = (2.0 - (2 * (1.0 - contrast)))
self._build_cdict() | Adjusts the image contrast.
Contrast refers to the rate of change of color with color level.
At low contrast, color changes gradually over many intensity
levels, while at high contrast it can change rapidly within a
few levels
Args:
contrast: float
A number between 0 and 1. Note that upon initialization the
colormap... | codesearchnet |
def all_reduce(self, input_tensor: core.TensorLike, control_input: Optional[Union[core.TensorLike, ops.Operation]]=None, options: Optional[collective_util.Options]=None) -> core.Tensor:
instance_key = self._next_instance_key()
options = self._options.merge(options)
ordering_token = self._get_ordering_token(... | All-reduce a dense tensor.
Args:
input_tensor: a dense tensor. It must have the same shape on all replicas.
control_input: if not None, add control edges between control_input and
the all-reduce.
options: an optional tf.distribute.experimental.CommunicationOptions. If
provided, it overrides the default options.
Retur... | github-repos |
def _PromptUserForEncryptedVolumeCredential(
self, scan_context, locked_scan_node, output_writer):
credentials = credentials_manager.CredentialsManager.GetCredentials(
locked_scan_node.path_spec)
if locked_scan_node.type_indicator == (
definitions.TYPE_INDICATOR_APFS_CONTAINER):... | Prompts the user to provide a credential for an encrypted volume.
Args:
scan_context (SourceScannerContext): the source scanner context.
locked_scan_node (SourceScanNode): the locked scan node.
output_writer (StdoutWriter): the output writer. | juraj-google-style |
def __init__(self, num_embeddings, num_additional_embeddings, embedding_dim, partially_freeze: Optional[bool]=False, dtype=None, **kwargs) -> None:
super().__init__(input_dim=num_embeddings, output_dim=embedding_dim, dtype=dtype, **kwargs)
self.num_embeddings = num_embeddings
self.num_additional_embeddings ... | Args:
num_embeddings (`int`):
Size of the dictionary of embeddings
num_additional_embeddings (`int`):
Number of additional embeddings. Only useful when you `partially_freeze=True`.
embedding_dim (`int`):
The size of each embedding vector
partially_freeze: (`bool`, *optional*, defaults to `False`):
If `True`, the regula... | github-repos |
def maybe_do_strip(node: node_def_pb2.NodeDef) -> None:
if node.op == 'Assert' or node.op == 'PrintV2':
node.op = 'NoOp'
erase_regular_node_attributes(node)
new_inputs = []
for inp in node.input:
if not is_control_input(inp):
new_inputs.append(as_control_d... | Strips the graph from Assert and CheckNumerics ops.
For Assert ops, this function also rewrites all of the inputs to the nodes
that were transformed by making them into control dependencies. It also
removes all of the regular node attributes, that is all node attributes
that do not start with `_`.
For CheckNumerics o... | github-repos |
def address_to_ip(address):
address_parts = address.split(':')
ip_address = socket.gethostbyname(address_parts[0])
if (ip_address == '127.0.0.1'):
ip_address = get_node_ip_address()
return ':'.join(([ip_address] + address_parts[1:])) | Convert a hostname to a numerical IP addresses in an address.
This should be a no-op if address already contains an actual numerical IP
address.
Args:
address: This can be either a string containing a hostname (or an IP
address) and a port or it can be just an IP address.
Returns:
The same address but with the hostn... | codesearchnet |
def args_to_dict(args):
arguments = dict()
for arg in args.split(','):
key, value = arg.split('=')
arguments[key] = value
return arguments | Convert command line arguments in a comma separated string to a dictionary
Args:
args (str): Command line arguments
Returns:
DictUpperBound[str,str]: Dictionary of arguments | juraj-google-style |
def is_valid_embedding(emb, source, target):
for _ in diagnose_embedding(emb, source, target):
return False
return True | A simple (bool) diagnostic for minor embeddings.
See :func:`diagnose_embedding` for a more detailed diagnostic / more information.
Args:
emb (dict): a dictionary mapping source nodes to arrays of target nodes
source (graph or edgelist): the graph to be embedded
target (graph or edgelist): the graph being embedded int... | juraj-google-style |
def __init__(self, kwargs):
PanCloudError.__init__(
self, "{}".format(", ".join(kwargs.keys()))
) | Convert kwargs to CSV string.
Args:
kwargs (dict): Key-word arguments. | juraj-google-style |
def _get_fbeta_score(true_positives, selected, relevant, beta=1):
precision = 1
if selected > 0:
precision = true_positives / selected
if beta == 0:
return precision
recall = 1
if relevant > 0:
recall = true_positives / relevant
if precision > 0 and recall > 0:
beta2 = beta * beta
ret... | Compute Fbeta score.
Args:
true_positives: Number of true positive ngrams.
selected: Number of selected ngrams.
relevant: Number of relevant ngrams.
beta: 0 gives precision only, 1 gives F1 score, and Inf gives recall only.
Returns:
Fbeta score. | juraj-google-style |
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_2_0):
if (kmip_version < enums.KMIPVersion.KMIP_2_0):
raise exceptions.VersionNotSupported('KMIP {} does not support the ObjectDefaults object.'.format(kmip_version.value))
super(ObjectDefaults, self).read(input_buffer, kmip_version=kmip_v... | Read the data encoding the ObjectDefaults structure and decode it into
its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object... | codesearchnet |
def _GetLineNumberPrefix(self, error, show_number=True):
prefix_with_number = ' {} | '.format(error.position.line)
if show_number:
return prefix_with_number
return re.sub('\\d', ' ', prefix_with_number) | Returns a prefix to annotate a line with a line number.
Args:
error: The ErrorInfo to get the line number from.
show_number: Whether to show or hide the number (hiding the number is
useful to get a prefix with the same width and formatting). | github-repos |
def describe_field(field_definition):
field_descriptor = FieldDescriptor()
field_descriptor.name = field_definition.name
field_descriptor.number = field_definition.number
field_descriptor.variant = field_definition.variant
if isinstance(field_definition, messages.EnumField):
field_descriptor... | Build descriptor for Field instance.
Args:
field_definition: Field instance to provide descriptor for.
Returns:
Initialized FieldDescriptor instance describing the Field instance. | codesearchnet |
def _ParseMRUListValue(self, registry_key):
mrulist_value = registry_key.GetValueByName('MRUList')
if (not mrulist_value):
return None
mrulist_entries_map = self._GetDataTypeMap('mrulist_entries')
context = dtfabric_data_maps.DataTypeMapContext(values={'data_size': len(mrulist_value.data)})
... | Parses the MRUList value in a given Registry key.
Args:
registry_key (dfwinreg.WinRegistryKey): Windows Registry key that contains
the MRUList value.
Returns:
mrulist_entries: MRUList entries or None if not available. | codesearchnet |
def _Execute(statements, context, callback, trace):
if trace:
trace.exec_depth += 1
for (i, statement) in enumerate(statements):
if isinstance(statement, six.string_types):
callback(statement)
else:
try:
(func, args) = statement
fun... | Execute a bunch of template statements in a ScopedContext.
Args:
callback: Strings are "written" to this callback function.
trace: Trace object, or None
This is called in a mutually recursive fashion. | codesearchnet |
def _AddParentDirectories(self, path):
path_segments = self.file_system.SplitPath(path)
for segment_index in range(len(path_segments)):
parent_path = self.file_system.JoinPath(path_segments[:segment_index])
file_entry = self.file_system.GetFileEntryByPath(parent_path)
if file_entry and no... | Adds the parent directories of a path to the fake file system.
Args:
path (str): path of the file within the fake file system.
Raises:
ValueError: if a parent directory is already set and is not a directory. | juraj-google-style |
def _seed2key(a):
def int32s_to_int64(a):
a = math_ops.bitwise_or(math_ops.cast(a[0], dtypes.uint64), math_ops.left_shift(math_ops.cast(a[1], dtypes.uint64), constant_op.constant(32, dtypes.uint64)))
a = math_ops.cast(a, dtypes.int64)
return a
return tf_np.asarray(int32s_to_int... | Converts an RNG seed to an RNG key.
Args:
a: an RNG seed, a tensor of shape [2] and dtype `tf.int32`.
Returns:
an RNG key, an ndarray of shape [] and dtype `np.int64`. | github-repos |
def run_board(args):
init_config(args)
from backend.collector import CollectorService
service = CollectorService(
args.logdir,
args.reload_interval,
standalone=False,
log_level=args.log_level)
service.run()
logger.info("Try to start automlboard on po... | Run main entry for AutoMLBoard.
Args:
args: args parsed from command line | juraj-google-style |
def _tokenize_field_path(path):
pos = 0
get_token = TOKENS_REGEX.match
match = get_token(path)
while match is not None:
type_ = match.lastgroup
value = match.group(type_)
yield value
pos = match.end()
match = get_token(path, pos)
if pos != len(path):
... | Lex a field path into tokens (including dots).
Args:
path (str): field path to be lexed.
Returns:
List(str): tokens | juraj-google-style |
def __init__(self, shape, dtype, minimum, maximum, name=None):
super(BoundedTensorSpec, self).__init__(shape, dtype, name)
if minimum is None:
raise ValueError('`minimum` can not be None.')
if maximum is None:
raise ValueError('`maximum` can not be None.')
try:
minimum_shape = np... | Initializes a new `BoundedTensorSpec`.
Args:
shape: Value convertible to `tf.TensorShape`. The shape of the tensor.
dtype: Value convertible to `tf.DType`. The type of the tensor values.
minimum: Number or sequence specifying the minimum element bounds
(inclusive). Must be broadcastable to `shape`.
maximum: Number or ... | github-repos |
def get_many(self, type: Type[T], query: Mapping[str, Any], context: PipelineContext = None) -> Iterable[T]:
pass | Gets a query from the data source, which contains a request for multiple objects.
Args:
query: The query being requested (contains a request for multiple objects).
context: The context for the extraction (mutable).
Returns:
The requested objects. | juraj-google-style |
def Register(self, a, b, migrated_entity):
if (a is not None):
self.a_merge_map[a] = migrated_entity
a._migrated_entity = migrated_entity
if (b is not None):
self.b_merge_map[b] = migrated_entity
b._migrated_entity = migrated_entity | Registers a merge mapping.
If a and b are both not None, this means that entities a and b were merged
to produce migrated_entity. If one of a or b are not None, then it means
it was not merged but simply migrated.
The effect of a call to register is to update a_merge_map and b_merge_map
according to the merge. Also t... | codesearchnet |
def save_summaries_secs(self):
return self._save_summaries_secs | Return the delay between summary computations.
Returns:
A timestamp. | github-repos |
def maybe_get_static_value(x, dtype=None):
if (x is None):
return x
try:
x_ = tf.get_static_value(x)
except TypeError:
x_ = x
if ((x_ is None) or (dtype is None)):
return x_
return np.array(x_, dtype) | Helper which tries to return a static value.
Given `x`, extract it's value statically, optionally casting to a specific
dtype. If this is not possible, None is returned.
Args:
x: `Tensor` for which to extract a value statically.
dtype: Optional dtype to cast to.
Returns:
Statically inferred value if possible, otherw... | codesearchnet |
def keywords(self):
path = self._get_id_path('keywords')
response = self._GET(path)
self._set_attrs_to_values(response)
return response | Get the plot keywords for a specific movie id.
Returns:
A dict representation of the JSON returned from the API. | codesearchnet |
def get(self, key, **ctx_options):
options = _make_ctx_options(ctx_options)
use_cache = self._use_cache(key, options)
if use_cache:
self._load_from_cache_if_available(key)
use_datastore = self._use_datastore(key, options)
if (use_datastore and
isinstance(self._conn, datastore_rpc... | Return a Model instance given the entity key.
It will use the context cache if the cache policy for the given
key is enabled.
Args:
key: Key instance.
**ctx_options: Context options.
Returns:
A Model instance if the key exists in the datastore; None otherwise. | juraj-google-style |
def allreduce_grads(all_grads, average):
if (get_tf_version_tuple() <= (1, 12)):
from tensorflow.contrib import nccl
else:
from tensorflow.python.ops import nccl_ops as nccl
nr_tower = len(all_grads)
if (nr_tower == 1):
return all_grads
new_all_grads = []
for grads in zip... | All-reduce average the gradients among K devices. Results are broadcasted to all devices.
Args:
all_grads (K x N): List of list of gradients. N is the number of variables.
average (bool): average gradients or not.
Returns:
K x N: same as input, but each grad is replaced by the average over K devices. | codesearchnet |
def tensor_dim_to_mesh_dim_size(layout, mesh_shape, tensor_dim):
layout_rules = convert_to_layout_rules(layout)
mesh_shape = convert_to_shape(mesh_shape)
mesh_axis = layout_rules.tensor_dimension_to_mesh_axis(tensor_dim, mesh_shape)
if mesh_axis is None:
return 1
else:
return mesh_shape.dims[mesh_a... | How many ways does a tensor dimension get split.
This is used to "cheat" when building the mtf graph and peek at how a
tensor dimension will be split. Returns 1 if the tensor dimension is not
split.
Args:
layout: an input to convert_to_layout_rules
mesh_shape: an input to convert_to_shape
tensor_dim: a Dimension
Re... | juraj-google-style |
def _MakeSavedModelV1(self, run_params):
saved_model_dir = trt_test.TfTrtIntegrationTestBase._MakeSavedModelV1(self, run_params)
saved_model_proto = loader_impl.parse_saved_model(saved_model_dir)
new_saved_model = saved_model_pb2.SavedModel()
new_saved_model.CopyFrom(saved_model_proto)
new_meta_grap... | Write the saved model as an input for testing.
In addition to creating a SavedModel like its parent method, this method
replaces this SavedModel by adding TF-TRT conversion parameters as function
attributes to each function in the SavedModel.
Args:
run_params: The current test run parameters.
Returns:
The directory ... | github-repos |
def _CreateQueryAccessHelper(self):
h = CheckAccessHelper('query')
h.Allow('aff4:/users/*', self._IsHomeDir)
h.Allow('aff4:/cron')
h.Allow('aff4:/cron/*')
h.Allow('aff4:/hunts')
h.Allow('aff4:/hunts/*')
h.Allow('aff4:/ACL')
h.Allow('aff4:/ACL/*')
h.Allow(self.CLIENT_URN_PATTERN)
... | Creates a CheckAccessHelper for controlling query access.
This function and _CreateReadAccessHelper essentially define GRR's ACL
policy. Please refer to these 2 functions to either review or modify
GRR's ACLs.
Query access gives you the ability to find objects in the tree without
knowing their URN, using ListChildren... | codesearchnet |
def _parse_ports(port_values: dict) -> dict:
endpoints = {}
for port_element in port_values:
target_port = port_element.split(':')
for port in target_port:
endpoints[int(port)] = int(port)
endpoint_spec = docker.types.EndpointSpec(ports=endpoints)
return endpoint_spec | Parse ports key.
Args:
port_values (dict): ports configuration values
Returns:
dict, Ports specification which contains exposed ports | codesearchnet |
class FuzzedExponentialIntervals(object):
def __init__(self, initial_delay_secs, num_retries, factor=2, fuzz=0.5, max_delay_secs=60 * 60 * 1, stop_after_secs=None):
self._initial_delay_secs = initial_delay_secs
if num_retries > 10000:
raise ValueError('num_retries parameter cannot excee... | Iterable for intervals that are exponentially spaced, with fuzzing.
On iteration, yields retry interval lengths, in seconds. Every iteration over
this iterable will yield differently fuzzed interval lengths, as long as fuzz
is nonzero.
Args:
initial_delay_secs: The delay before the first retry, in seconds.
num_retrie... | github-repos |
def text_pb(tag, data, description=None):
try:
tensor = tensor_util.make_tensor_proto(data, dtype=np.object)
except TypeError as e:
raise TypeError('tensor must be of type string', e)
summary_metadata = metadata.create_summary_metadata(display_name=None, description=description)
summary ... | Create a text tf.Summary protobuf.
Arguments:
tag: String tag for the summary.
data: A Python bytestring (of type bytes), a Unicode string, or a numpy data
array of those types.
description: Optional long-form description for this summary, as a `str`.
Markdown is supported. Defaults to empty.
Raises:
TypeError: If th... | codesearchnet |
def summarize(self, highlight=None):
lines = [RL('Command-line configuration:', 'bold'), RL('')]
for name, val in self._config.items():
highlight_attr = 'bold' if name == highlight else None
line = RL(' ')
line += RL(name, ['underline', highlight_attr])
line += RL(': ')
... | Get a text summary of the config.
Args:
highlight: A property name to highlight in the output.
Returns:
A `RichTextLines` output. | github-repos |
class MeanMetricWrapper(Mean):
def __init__(self, fn, name=None, dtype=None, **kwargs):
super().__init__(name=name, dtype=dtype)
self._fn = fn
self._fn_kwargs = kwargs
if self._fn in losses.ALL_OBJECTS or (hasattr(self._fn, '__class__') and self._fn.__class__ in losses.ALL_OBJECTS):... | Wrap a stateless metric function with the `Mean` metric.
You could use this class to quickly build a mean metric from a function. The
function needs to have the signature `fn(y_true, y_pred)` and return a
per-sample loss array. `MeanMetricWrapper.result()` will return
the average metric value across all samples seen s... | github-repos |
def _data_format_resolver(data_format, resolver_dict):
try:
data_format = DataFormat(data_format)
except ValueError:
supported_formats = ', '.join(
["'{}'".format(f.value) for f in DataFormat])
raise ValueError(("'data_format' must be one of {formats}. Given "
... | Resolve a value from :attr:`resolver_dict` based on the
:attr:`data_format`.
Args:
data_format (:class:`~.DataFormat` or str): The data format;
must be a member of :class:`~.DataFormat` or a string
equivalent.
resolver_dict (dict): the resolving dict. Can hold any value
for any of the valid :attr:`data_format` strings... | juraj-google-style |
def assemble_config(partition: Partition, manifest: Manifest) -> Config:
name, params, out = partition
out.kwargs.update(params)
out.subsection_name = name
location = prepare_target_name(out)
user = out.user_id
manifest.schedule(out.config_name, out.dataset, out.selection, location, user)
lo... | Assemble the configuration for a single partition.
For each cross product of the 'selection' sections, the output dictionary
will overwrite parameters from the extra param subsections, evenly cycling
through each subsection.
For example:
{ 'parameters': {... 'api_key': KKKKK1, ... }, ... }
{ 'parameters': {... 'api_k... | github-repos |
def word_error_rate(ref: Sequence[T], hyp: Sequence[T]) -> float:
if (len(ref) == 0):
raise EmptyReferenceException('Cannot calculating word error rate against a length 0 reference sequence.')
distance = min_edit_distance(ref, hyp)
return ((100 * float(distance)) / len(ref)) | Calculate the word error rate of a sequence against a reference.
Args:
ref: The gold-standard reference sequence
hyp: The hypothesis to be evaluated against the reference.
Returns:
The word error rate of the supplied hypothesis with respect to the
reference string.
Raises:
persephone.exceptions.EmptyReferenceExcepti... | codesearchnet |
def pars_in_groups(self):
pargp = self.par_groups
allpars = dict()
for cpg in pargp:
allpars[cpg] = [i for i in self.parameter_data.loc[((self.parameter_data.pargp == cpg), 'parnme')]]
return allpars | return a dictionary of parameter names in each parameter group.
Returns:
dictionary | codesearchnet |
def update_failover_dns_record(env, zone_id, **kwargs):
client = boto3.Session(profile_name=env).client('route53')
response = {}
hosted_zone_info = client.get_hosted_zone(Id=zone_id)
zone_name = hosted_zone_info['HostedZone']['Name'].rstrip('.')
dns_name = kwargs.get('dns_name')
failover_state =... | Create a Failover Route53 alias record in _env_ zone.
Args:
env (str): Deployment environment.
zone_id (str): Route53 zone id.
Keyword Args:
dns_name (str): FQDN of application's dns entry to add/update.
dns_ttl (int): DNS time-to-live (ttl)
elb_aws_dns (str): DNS A Record of ELB from AWS
elb_dns_zone_id (str): Zone ... | codesearchnet |
def GetContainingCondContext(ctxt):
while ctxt:
if ctxt.IsCondContext():
return ctxt
ctxt = ctxt.outer_context
return None | Returns the first ancestor CondContext of `ctxt`.
Returns `ctxt` if `ctxt` is a CondContext, or None if `ctxt` is not in a cond.
Args:
ctxt: ControlFlowContext
Returns:
`ctxt` if `ctxt` is a CondContext, the most nested CondContext containing
`ctxt`, or None if `ctxt` is not in a cond. | github-repos |
def space(self, newlines=1):
space = Space()
for line in range(newlines):
space.add_line('\n')
self._container.structure.insert(self._idx, space)
self._idx += 1
return self | Creates a vertical space of newlines
Args:
newlines (int): number of empty lines
Returns:
self for chaining | codesearchnet |
def get_figure(new_fig=True, subplot='111', params=None):
_get_plt()
if new_fig:
fig = plt.figure()
else:
fig = plt.gcf()
params = dict_if_none(params)
if isinstance(subplot, (tuple, list)):
ax = fig.add_subplot(*subplot, **params)
else:
ax = fig.add_subplot(subpl... | Function to be used for viewing - plotting,
to initialize the matplotlib figure - axes.
Args:
new_fig(bool): Defines if a new figure will be created, if false current figure is used
subplot (tuple or matplolib subplot specifier string): Create axes with these parameters
params (dict): extra options passed to add_subpl... | codesearchnet |
def _get_descending_key(gettime=time.time):
now_descending = int(((_FUTURE_TIME - gettime()) * 100))
request_id_hash = os.environ.get('REQUEST_ID_HASH')
if (not request_id_hash):
request_id_hash = str(random.getrandbits(32))
return ('%d%s' % (now_descending, request_id_hash)) | Returns a key name lexically ordered by time descending.
This lets us have a key name for use with Datastore entities which returns
rows in time descending order when it is scanned in lexically ascending order,
allowing us to bypass index building for descending indexes.
Args:
gettime: Used for testing.
Returns:
A s... | codesearchnet |
def clipped_zoom(img, zoom_factor):
h = img.shape[0]
ch = int(np.ceil(h / float(zoom_factor)))
top_h = (h - ch)
w = img.shape[1]
cw = int(np.ceil(w / float(zoom_factor)))
top_w = (w - cw)
img = tfds.core.lazy_imports.scipy.ndimage.zoom(
img[top_h:top_h + ch, top_w:top_w + cw], (zoom_factor, z... | Zoom image with clipping.
Zoom the central part of the image and clip extra pixels.
Args:
img: numpy array, uncorrupted image.
zoom_factor: numpy array, a sequence of float numbers for zoom factor.
Returns:
numpy array, zoomed image after clipping. | juraj-google-style |
def get_torch_dataloader(self):
raise NotImplementedError | Get a Torch `DataLoader` for the `DataAdapter`.
Returns:
A Torch `DataLoader`. | github-repos |
def str_to_etree(xml_str, encoding='utf-8'):
parser = xml.etree.ElementTree.XMLParser(encoding=encoding)
return xml.etree.ElementTree.fromstring(xml_str, parser=parser) | Deserialize API XML doc to an ElementTree.
Args:
xml_str: bytes
DataONE API XML doc
encoding: str
Decoder to use when converting the XML doc ``bytes`` to a Unicode str.
Returns:
ElementTree: Matching the API version of the XML doc. | juraj-google-style |
def __init__(self, dtensor_components: Tuple[tensor.Tensor], global_element_spec: tensor_spec.TensorSpec, layouts: Any):
[self._iterator_resource_dtensor] = dtensor_components
self._global_element_spec = global_element_spec
self._layouts = layouts
self._layouts_str = nest.map_structure(lambda layout: la... | Initializes a distributed iterator for DTensor datasets.
This iterator encapsulates tf.data iterators for the underlying devices, and
treats it as a packed DTensor of iterator resource tensors.
Args:
dtensor_components: a tuple containing the underlying iterator resources
packed into a DTensor. This is expected to be... | github-repos |
def dict_take(dict_, keys, default=util_const.NoParam):
if (default is util_const.NoParam):
for key in keys:
(yield dict_[key])
else:
for key in keys:
(yield dict_.get(key, default)) | r"""
Generates values from a dictionary
Args:
dict_ (Mapping): a dictionary to take from
keys (Iterable): the keys to take
default (object, optional): if specified uses default if keys are missing
CommandLine:
python -m ubelt.util_dict dict_take_gen
Example:
>>> import ubelt as ub
>>> dict_ = {1: 'a', 2: 'b', 3: 'c'... | codesearchnet |
def Log(self, format_str, *args):
format_str = utils.SmartUnicode(format_str)
status = format_str
if args:
try:
status = (format_str % args)
except TypeError:
logging.error('Tried to log a format string with the wrong number of arguments: %s', format_str)
logging.... | Logs the message using the hunt's standard logging.
Args:
format_str: Format string
*args: arguments to the format string
Raises:
RuntimeError: on parent missing logs_collection | codesearchnet |
def sell(self, product_id, order_type, **kwargs):
return self.place_order(product_id, 'sell', order_type, **kwargs) | Place a sell order.
This is included to maintain backwards compatibility with older versions
of cbpro-Python. For maximum support from docstrings and function
signatures see the order type-specific functions place_limit_order,
place_market_order, and place_stop_order.
Args:
product_id (str): Product to order (eg. 'BT... | codesearchnet |
def __init__(self, getter, verbose=False):
self._count = 0
self._getter = getter
self._verbose = verbose | Initializes a contextual switch for a custom getter.
Args:
getter: The custom getter which we may want to switch on.
verbose: Log out every time a variable is fetched, and whether or not
`getter` is used.
Returns:
A custom getter which can also be used as a context manager.
Entering the context enables the custom get... | juraj-google-style |
def get_request_data(self, path, action, body=None):
body = body or ''
path_name, path_spec = self.get_path_spec(path)
response = {}
if path_spec is not None and action in path_spec.keys():
for status_code in path_spec[action]['responses'].keys():
... | Get the default data and status code of the given path + action request.
Args:
path: path of the request.
action: action of the request(get, post, delete...)
body: body sent, used to sent it back for post request.
Returns:
A tuple with the default response data and status code
In case of default status_code, use 0 | juraj-google-style |
def authenticate(self, user, password):
request = Request(AUTH_URL)
request.add_header('X-Simperium-API-Key', API_KEY)
if sys.version_info < (3, 3):
request.add_data(json.dumps({'username': user, 'password': password}))
else:
request.data = json.dumps({'... | Method to get simplenote auth token
Arguments:
- user (string): simplenote email address
- password (string): simplenote password
Returns:
Simplenote API token as string | juraj-google-style |
def get_file_diff(tree, files_to_diff):
config.LOGGER.info("\nChecking if files exist on Kolibri Studio...")
file_diff = tree.get_file_diff(files_to_diff)
return file_diff | get_file_diff: Download files from nodes
Args:
tree (ChannelManager): manager to handle communication to Kolibri Studio
Returns: list of files that are not on Kolibri Studio | juraj-google-style |
def read_samples(self, sr=None, offset=0, duration=None):
with self.container.open_if_needed(mode='r') as cnt:
(samples, native_sr) = cnt.get(self.key)
start_sample_index = int((offset * native_sr))
if (duration is None):
end_sample_index = samples.shape[0]
else:
... | Return the samples from the track in the container.
Uses librosa for resampling, if needed.
Args:
sr (int): If ``None``, uses the sampling rate given by the file,
otherwise resamples to the given sampling rate.
offset (float): The time in seconds, from where to start reading
the samples (rel. to the file start).
durat... | codesearchnet |
def is_tensor_final(self, tensor_name):
tensor = self._name_to_tensor(tensor_name)
return tensor in self._final_tensors | Whether a tensor is a final output of the computation.
Args:
tensor_name: a string, name of a tensor in the graph.
Returns:
a boolean indicating whether the tensor was a final output. | juraj-google-style |
def numeric_function_clean_dataframe(self, axis):
result = None
query_compiler = self
if ((not axis) and (len(self.index) == 0)):
result = pandas.Series(dtype=np.int64)
nonnumeric = [col for (col, dtype) in zip(self.columns, self.dtypes) if (not is_numeric_dtype(dtype))]
if (len(nonnumeric) ... | Preprocesses numeric functions to clean dataframe and pick numeric indices.
Args:
axis: '0' if columns and '1' if rows.
Returns:
Tuple with return value(if any), indices to apply func to & cleaned Manager. | codesearchnet |
def execute(self, asm_instr):
self.ir_emulator.registers[self.ip] = (asm_instr.address + asm_instr.size)
if self.arch_info.instr_is_syscall(asm_instr):
raise Syscall()
return self.__execute(asm_instr) | Execute an assembler instruction.
Args:
asm_instr (X86Instruction): A instruction to execute.
Returns:
A int. The address of the next instruction to execute. | codesearchnet |
def get_member_slackuid(self, slack):
members = self.__con__.search_s(
CSHMember.__ldap_user_ou__,
ldap.SCOPE_SUBTREE,
"(slackuid=%s)" % slack,
['ipaUniqueID'])
if members:
return CSHMember(
self,
... | Get a CSHMember object.
Arguments:
slack -- the Slack UID of the member
Returns:
None if the Slack UID provided does not correspond to a CSH Member | juraj-google-style |
def detect(self, text):
t = text.encode('utf-8')
(reliable, index, top_3_choices) = cld2.detect(t, bestEffort=False)
if (not reliable):
self.reliable = False
(reliable, index, top_3_choices) = cld2.detect(t, bestEffort=True)
if (not self.quiet):
if (not reliable):
... | Decide which language is used to write the text.
The method tries first to detect the language with high reliability. If
that is not possible, the method switches to best effort strategy.
Args:
text (string): A snippet of text, the longer it is the more reliable we
can detect the language used to write the text. | codesearchnet |
def created(cls, data=None):
if cls.expose_status:
cls.response.content_type = 'application/json'
cls.response._status_line = '201 Created'
return cls(201, data=data).to_json | Shortcut API for HTTP 201 `Created` response.
Args:
data (object): Response key/value data.
Returns:
WSResponse Instance. | codesearchnet |
def search_users(self, user):
user_url = "%s/%s/%s" % (self.url, "user", user)
response = self.jss.get(user_url)
return LDAPUsersResults(self.jss, response) | Search for LDAP users.
Args:
user: User to search for. It is not entirely clear how the
JSS determines the results- are regexes allowed, or
globbing?
Returns:
LDAPUsersResult object.
Raises:
Will raise a JSSGetError if no results are found. | juraj-google-style |
def create_volume(self, name=None, driver=None, driver_opts=None, labels=None):
url = self._url('/volumes/create')
if ((driver_opts is not None) and (not isinstance(driver_opts, dict))):
raise TypeError('driver_opts must be a dictionary')
data = {'Name': name, 'Driver': driver, 'DriverOpts': driver_... | Create and register a named volume
Args:
name (str): Name of the volume
driver (str): Name of the driver used to create the volume
driver_opts (dict): Driver options as a key-value dictionary
labels (dict): Labels to set on the volume
Returns:
(dict): The created volume reference object
Raises:
:py:class:`docker.err... | codesearchnet |
def add(TargetGroup, NewMember, Config=None, Args=None):
r
Member = Task(NewMember, Args or {}, Config or {}) if isfunction(NewMember) else Group(NewMember, Config or {})
ParentMembers = TargetGroup.__ec_member__.Members
ParentMembers[Member.Config['name']] = Member
alias = Member.Config.get('alias')
if ... | r"""Adds members to an existing group.
Args:
TargetGroup (Group): The target group for the addition.
NewMember (Group / Task): The member to be added.
Config (dict): The config for the member.
Args (OrderedDict): ArgConfig for the NewMember, if it's a task (optional). | juraj-google-style |
def blocksearch(block, name):
if hasattr(block, 'tokens'):
for b in block.tokens[1]:
b = (b if hasattr(b, 'raw') and b.raw() == name else blocksearch(
b, name))
if b:
return b
return False | Recursive search for name in block (inner blocks)
Args:
name (str): search term
Returns:
Block OR False | juraj-google-style |
def print_all_configs(configs, missing, warning):
print_text = ''
llen = 65
for i, row in enumerate(configs):
if i != 0:
print_text += '-' * llen + '\n'
if isinstance(row[1], list):
val = ', '.join(row[1])
else:
val = row[1]
print_text += '... | Prints the status and info on all configurations in a table format.
Args:
configs: List of all configurations found.
missing: List of all configurations that are missing.
warning: List of all configurations found with warnings. | github-repos |
def matches(node, pattern):
if isinstance(pattern, str):
pattern = parser.parse_str(pattern)
matcher = PatternMatcher(pattern)
matcher.visit(node)
return matcher.matches | Basic pattern matcher for AST.
The pattern may contain wildcards represented by the symbol '_'. A node
matches a pattern if for every node in the tree, either there is a node of
the same type in pattern, or a Name node with id='_'.
Args:
node: ast.AST
pattern: ast.AST
Returns:
bool | github-repos |
def _set_auditpol_data(option, value):
auditpol_values = {'None': 'No Auditing',
'0': 'No Auditing',
'1': 'Success',
'2': 'Failure',
'3': 'Success and Failure'}
defaults = _get_audit_defaults(option)
return __ut... | Helper function that updates the current applied settings to match what has
just been set in the audit.csv files. We're doing it this way instead of
running `gpupdate`
Args:
option (str): The name of the option to set
value (str): The value to set. ['None', '0', '1', '2', '3']
Returns:
bool: ``True`` if successful, o... | juraj-google-style |
def xml(self, xml):
self._request.xml = xml
self.add_matcher(matcher('XMLMatcher', xml)) | Defines a XML body value to match.
Arguments:
xml (str|regex): body XML to match.
Returns:
self: current Mock instance. | codesearchnet |
def __init__(self, saved_model_dir, saved_model_tags, saved_model_exported_names, experimental_debug_info_func=None):
super(TFLiteSavedModelConverter, self).__init__(experimental_debug_info_func)
self.saved_model_dir = saved_model_dir
self._saved_model_tags = saved_model_tags
self._saved_model_exported_... | Constructor for TFLiteConverter.
Args:
saved_model_dir: Directory of the SavedModel.
saved_model_tags: Set of tags identifying the MetaGraphDef within the
SavedModel to analyze. All tags in the tag set must be present. (default
{tf.saved_model.SERVING}).
saved_model_exported_names: Names to be exported when the saved ... | github-repos |
class PatchTSMixerBlock(nn.Module):
def __init__(self, config: PatchTSMixerConfig):
super().__init__()
num_layers = config.num_layers
self.mixers = nn.ModuleList([PatchTSMixerLayer(config=config) for _ in range(num_layers)])
def forward(self, hidden_state, output_hidden_states: bool=Fa... | The main computing framework of the `PatchTSMixer` model.
Args:
config (`PatchTSMixerConfig`):
Configuration. | github-repos |
def from_text_vision_configs(cls, text_config: XCLIPTextConfig, vision_config: XCLIPVisionConfig, **kwargs):
return cls(text_config=text_config.to_dict(), vision_config=vision_config.to_dict(), **kwargs) | Instantiate a [`XCLIPConfig`] (or a derived class) from xclip text model configuration and xclip vision model
configuration.
Returns:
[`XCLIPConfig`]: An instance of a configuration object | github-repos |
def dimension_values(self, dimension, expanded=True, flat=True):
index = self.get_dimension_index(dimension)
if index == 0:
return np.array([self.x])
elif index == 1:
return np.array([self.y])
else:
return super(Arrow, self).dimension_values(d... | Return the values along the requested dimension.
Args:
dimension: The dimension to return values for
expanded (bool, optional): Whether to expand values
flat (bool, optional): Whether to flatten array
Returns:
NumPy array of values along the requested dimension | juraj-google-style |
def from_string(key_pem, is_x509_cert):
key_pem = _helpers._to_bytes(key_pem)
if is_x509_cert:
pubkey = crypto.load_certificate(crypto.FILETYPE_PEM, key_pem)
else:
pubkey = crypto.load_privatekey(crypto.FILETYPE_PEM, key_pem)
return OpenSSLVerifier(pubkey... | Construct a Verified instance from a string.
Args:
key_pem: string, public key in PEM format.
is_x509_cert: bool, True if key_pem is an X509 cert, otherwise it
is expected to be an RSA key in PEM format.
Returns:
Verifier instance.
Raises:
OpenSSL.crypto.Error: if the key_pem can't be parsed. | juraj-google-style |
def write(self, data):
self._check_open()
if (not isinstance(data, str)):
raise TypeError(('Expected str but got %s.' % type(data)))
if (not data):
return
self._buffer.append(data)
self._buffered += len(data)
self._offset += len(data)
if (self._buffered >= self._flushsize):
... | Write some bytes.
Args:
data: data to write. str.
Raises:
TypeError: if data is not of type str. | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.