def set_attribute(self, node: cfg.CFGNode, obj: abstract.BaseValue, name: str, value: cfg.Variable) -> cfg.CFGNode:
    if not self._check_writable(obj, name):
        return node
    if self.ctx.vm.frame is not None and obj is self.ctx.vm.frame.f_globals:
        for v in value.data:
            v.update_official_name(name)
    if isinstance(obj, abstract.Empty):
        return node
    elif isinstance(obj, abstract.Module):
        log.warning('Ignoring overwrite of %s.%s', obj.name, name)
        return node
    elif isinstance(obj, (abstract.StaticMethod, abstract.ClassMethod)):
        return self.set_attribute(node, obj.method, name, value)
    elif isinstance(obj, abstract.SimpleValue):
        return self._set_member(node, obj, name, value)
    elif isinstance(obj, abstract.BoundFunction):
        return self.set_attribute(node, obj.underlying, name, value)
    elif isinstance(obj, abstract.Unsolvable):
        return node
    elif isinstance(obj, abstract.Unknown):
        if name in obj.members:
            obj.members[name].PasteVariable(value, node)
        else:
            obj.members[name] = value.AssignToNewVariable(node)
        return node
    elif isinstance(obj, abstract.TypeParameterInstance):
        nodes = []
        for v in obj.instance.get_instance_type_parameter(obj.name).data:
            nodes.append(self.set_attribute(node, v, name, value))
        return self.ctx.join_cfg_nodes(nodes) if nodes else node
    elif isinstance(obj, abstract.Union):
        for option in obj.options:
            node = self.set_attribute(node, option, name, value)
        return node
    else:
        raise NotImplementedError(obj.__class__.__name__)

Set an attribute on an object.

The attribute might already have a Variable in it and in that case we cannot
overwrite it and instead need to add the elements of the new variable to the
old variable.

Args:
node: The current CFG node.
obj: The object.
name: The name of the attribute to set.
value: The Variable to store in it.

Returns:
A (possibly changed) CFG node.
Raises:
AttributeError: If the attribute cannot be set.
NotImplementedError: If attribute setting is not implemented for obj.


def svd(x, full_matrices=True, compute_uv=True):
    if any_symbolic_tensors((x,)):
        return SVD(full_matrices, compute_uv).symbolic_call(x)
    return _svd(x, full_matrices, compute_uv)

Computes the singular value decomposition of a matrix.

Args:
x: Input tensor of shape `(..., M, N)`.

Returns:
A tuple of three tensors: a tensor of shape `(..., M, M)` containing the
left singular vectors, a tensor of shape `(..., M, N)` containing the
singular values and a tensor of shape `(..., N, N)` containing the
right singular vectors.


async def is_change_done(self, zone, change_id):
    zone_id = self.get_managed_zone(zone)
    url = f'{self._base_url}/managedZones/{zone_id}/changes/{change_id}'
    resp = (await self.get_json(url))
    return (resp['status'] == self.DNS_CHANGES_DONE)

Check if a DNS change has completed.

Args:
zone (str): DNS zone of the change.
change_id (str): Identifier of the change.
Returns:
Boolean


def __lt__(self, other):

    if not isinstance(other, interface.DateTimeValues):
      raise ValueError('Other not an instance of DateTimeValues')

    if not isinstance(other, SemanticTime):
      return True

    return self._SORT_ORDER < other._SORT_ORDER

Determines if the date time values are less than other.

Args:
other (DateTimeValues): date time values to compare against.

Returns:
bool: True if the date time values are less than other.

Raises:
ValueError: if other is not an instance of DateTimeValues.


def get_nets_lacnic(self, response):
    nets = []
    for match in re.finditer('^(inetnum|inet6num|route):[^\\S\\n]+(.+?,[^\\S\\n].+|.+)$', response, re.MULTILINE):
        try:
            net = copy.deepcopy(BASE_NET)
            net_range = match.group(2).strip()
            try:
                net['range'] = net['range'] = ('{0} - {1}'.format(ip_network(net_range)[0].__str__(), ip_network(net_range)[(- 1)].__str__()) if ('/' in net_range) else net_range)
            except ValueError:
                net['range'] = net_range
            temp = []
            for addr in net_range.split(', '):
                count = addr.count('.')
                if ((count is not 0) and (count < 4)):
                    addr_split = addr.strip().split('/')
                    for i in range((count + 1), 4):
                        addr_split[0] += '.0'
                    addr = '/'.join(addr_split)
                temp.append(ip_network(addr.strip()).__str__())
            net['cidr'] = ', '.join(temp)
            net['start'] = match.start()
            net['end'] = match.end()
            nets.append(net)
        except ValueError:
            pass
    return nets

The function for parsing network blocks from LACNIC whois data.

Args:
response (:obj:`str`): The response from the LACNIC whois server.

Returns:
list of dict: Mapping of networks with start and end positions.

::

[{
'cidr' (str) - The network routing block
'start' (int) - The starting point of the network
'end' (int) - The endpoint point of the network
}]


def add_update(self, updates, inputs=None):
    if inputs is not None:
        tf_logging.warning('`add_update` `inputs` kwarg has been deprecated. You no longer need to pass a value to `inputs` as it is being automatically inferred.')
    call_context = base_layer_utils.call_context()
    if call_context.in_keras_graph:
        return
    if not call_context.frozen:
        for update in nest.flatten(updates):
            if callable(update):
                update()

Add update op(s), potentially dependent on layer inputs.

Weight updates (for instance, the updates of the moving mean and variance
in a BatchNormalization layer) may be dependent on the inputs passed
when calling a layer. Hence, when reusing the same layer on
different inputs `a` and `b`, some entries in `layer.updates` may be
dependent on `a` and some on `b`. This method automatically keeps track
of dependencies.

This call is ignored when eager execution is enabled (in that case, variable
updates are run on the fly and thus do not need to be tracked for later
execution).

Args:
updates: Update op, or list/tuple of update ops, or zero-arg callable
that returns an update op. A zero-arg callable should be passed in
order to disable running the updates by setting `trainable=False`
on this Layer, when executing in Eager mode.
inputs: Deprecated, will be automatically inferred.


def _GetArgsAndFlagsString(spec, metadata):
    args_with_no_defaults = spec.args[:len(spec.args) - len(spec.defaults)]
    args_with_defaults = spec.args[len(spec.args) - len(spec.defaults):]
    accepts_positional_args = metadata.get(decorators.ACCEPTS_POSITIONAL_ARGS)
    arg_and_flag_strings = []
    if args_with_no_defaults:
        if accepts_positional_args:
            arg_strings = [formatting.Underline(arg.upper()) for arg in args_with_no_defaults]
        else:
            arg_strings = [f'--{arg}={formatting.Underline(arg.upper())}' for arg in args_with_no_defaults]
        arg_and_flag_strings.extend(arg_strings)
    if args_with_defaults or spec.kwonlyargs or spec.varkw:
        arg_and_flag_strings.append('<flags>')
    if spec.varargs:
        varargs_underlined = formatting.Underline(spec.varargs.upper())
        varargs_string = f'[{varargs_underlined}]...'
        arg_and_flag_strings.append(varargs_string)
    return ' '.join(arg_and_flag_strings)

The args and flags string for showing how to call a function.

If positional arguments are accepted, the args will be shown as positional.
E.g. "ARG1 ARG2 [--flag=FLAG]"

If positional arguments are disallowed, the args will be shown with flags
syntax.
E.g. "--arg1=ARG1 [--flag=FLAG]"

Args:
spec: The full arg spec for the component to construct the args and flags
string for.
metadata: Metadata for the component, including whether it accepts
positional arguments.

Returns:
The constructed args and flags string.


def parse_document_id(chrom, pos, ref, alt, variant_type, case_id):

    return generate_md5_key([chrom, pos, ref, alt, variant_type, case_id])

Parse the unique document id for a variant.

This will always be unique in the database.

Args:
chrom(str)
pos(str)
ref(str)
alt(str)
variant_type(str): 'clinical' or 'research'
case_id(str): unqiue family id

Returns:
document_id(str): The unique document id in an md5 string


def classes_file(flag_leaf=False):

    if __flag_first:
        __setup()

    if not flag_leaf:
        return _classes_file

    return [cls for cls in _classes_file if cls not in _classes_file_superclass]

All known File* classes

Args:
flag_leaf: returns only classes that do not have subclasses
("leaf" nodes as in a class tree graph)


def _alt_inner_shape(self, new_inner_rank):
    if new_inner_rank == 0:
        raise ValueError('new_inner_rank cannot be zero')
    elif self.inner_rank == 0:
        raise ValueError('old inner_rank cannot be zero')
    elif new_inner_rank == self.inner_rank:
        return self.inner_shape
    elif new_inner_rank < self.inner_rank:
        if self._static_inner_shape.is_fully_defined():
            return _alt_inner_shape_from_tensor_shape(self._static_inner_shape, self.dtype, new_inner_rank)
        first_dimension = self._num_slices_in_dimension(-new_inner_rank)
        if new_inner_rank == 1:
            return array_ops.expand_dims(first_dimension, 0)
        remaining_dimensions = self.inner_shape[1 - new_inner_rank:]
        return array_ops.concat([array_ops.expand_dims(first_dimension, 0), remaining_dimensions], axis=0)
    else:
        assert new_inner_rank > self.inner_rank
        new_dimensions = new_inner_rank - self.inner_rank
        if any([not x.is_uniform() for x in self.row_partitions[-new_dimensions:]]):
            raise ValueError('Cannot get an inner shape over a ragged dimension')
        first_dimension = self._num_slices_in_dimension(-new_inner_rank)
        new_dimensions = new_inner_rank - self.inner_rank
        new_dims = [first_dimension] + [x.uniform_row_length() for x in self.row_partitions[-new_dimensions:]]
        return array_ops.concat([array_ops_stack.stack(new_dims), self.inner_shape[1:]], axis=0)

Get an alternative inner shape with higher or lower rank.

For the rank of the inner shape to be be higher, the last few ragged
dimensions must have uniform_row_length.

Args:
new_inner_rank: the new rank of the inner_shape

Returns:
A new inner_shape of rank new_inner_rank.


def QueueQueryTasks(self, queue, limit=1):

    prefix = DataStore.QUEUE_TASK_PREDICATE_PREFIX
    all_tasks = []

    for _, serialized, ts in self.ResolvePrefix(
        queue, prefix, timestamp=DataStore.ALL_TIMESTAMPS):
      task = rdf_flows.GrrMessage.FromSerializedString(serialized)
      task.leased_until = ts
      all_tasks.append(task)

    return all_tasks[:limit]

Retrieves tasks from a queue without leasing them.

This is good for a read only snapshot of the tasks.

Args:
queue: The task queue that this task belongs to, usually client.Queue()
where client is the ClientURN object you want to schedule msgs on.
limit: Number of values to fetch.

Returns:
A list of Task() objects.


def _GetAction(self, action, text):
    if ('airportdProcessDLILEvent' in action):
        interface = text.split()[0]
        return 'Interface {0:s} turn up.'.format(interface)
    if ('doAutoJoin' in action):
        match = self._CONNECTED_RE.match(text)
        if match:
            ssid = match.group(1)[1:(- 1)]
        else:
            ssid = 'Unknown'
        return 'Wifi connected to SSID {0:s}'.format(ssid)
    if ('processSystemPSKAssoc' in action):
        wifi_parameters = self._WIFI_PARAMETERS_RE.search(text)
        if wifi_parameters:
            ssid = wifi_parameters.group(1)
            bssid = wifi_parameters.group(2)
            security = wifi_parameters.group(3)
            if (not ssid):
                ssid = 'Unknown'
            if (not bssid):
                bssid = 'Unknown'
            if (not security):
                security = 'Unknown'
            return 'New wifi configured. BSSID: {0:s}, SSID: {1:s}, Security: {2:s}.'.format(bssid, ssid, security)
    return text

Parse the well known actions for easy reading.

Args:
action (str): the function or action called by the agent.
text (str): mac Wifi log text.

Returns:
str: a formatted string representing the known (or common) action.
If the action is not known the original log text is returned.


def _sign_threshold_signature_fulfillment(cls, input_, message, key_pairs):

        input_ = deepcopy(input_)
        message = sha3_256(message.encode())
        if input_.fulfills:
            message.update('{}{}'.format(
                input_.fulfills.txid, input_.fulfills.output).encode())

        for owner_before in set(input_.owners_before):

            ccffill = input_.fulfillment
            subffills = ccffill.get_subcondition_from_vk(
                base58.b58decode(owner_before))
            if not subffills:
                raise KeypairMismatchException('Public key {} cannot be found '
                                               'in the fulfillment'
                                               .format(owner_before))
            try:
                private_key = key_pairs[owner_before]
            except KeyError:
                raise KeypairMismatchException('Public key {} is not a pair '
                                               'to any of the private keys'
                                               .format(owner_before))

            for subffill in subffills:
                subffill.sign(
                    message.digest(), base58.b58decode(private_key.encode()))
        return input_

Signs a ThresholdSha256.

Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`) The Input to be signed.
message (str): The message to be signed
key_pairs (dict): The keys to sign the Transaction with.


def find_common_root(elements):

    if not elements:
        raise UserWarning("Can't find common root - no elements suplied.")

    root_path = el_to_path_vector(elements.pop())

    for el in elements:
        el_path = el_to_path_vector(el)

        root_path = common_vector_root(root_path, el_path)

        if not root_path:
            raise UserWarning(
                "Vectors without common root:\n%s" % str(el_path)
            )

    return root_path

Find root which is common for all `elements`.

Args:
elements (list): List of double-linked HTMLElement objects.

Returns:
list: Vector of HTMLElement containing path to common root.


def assert_equal_flattened(self, expected_results, actual_results):
    self.assertEqual(len(expected_results), len(actual_results))
    for i, expected_result in enumerate(expected_results):
        final_result = []
        actual_result = actual_results[i]
        for val in actual_result:
            final_result.extend(val.numpy())
        self.assertAllEqual(expected_result, final_result)

Asserts that flattened results are equal.

Due to the number of replicas in the strategy, the output may have a
different structure and needs to be flattened for comparison.

Args:
expected_results: The results expected as a result of a computation.
actual_results: The actual results of a computation.


def set_file_to_upload(self, file_to_upload):

        if 'url' in self.data:
            del self.data['url']
        self.file_to_upload = file_to_upload

Delete any existing url and set the file uploaded to the local path provided

Args:
file_to_upload (str): Local path to file to upload

Returns:
None


def single_gate_matrix(gate, params=None):
    (theta, phi, lam) = map(float, single_gate_params(gate, params))
    return np.array([[np.cos((theta / 2)), ((- np.exp((1j * lam))) * np.sin((theta / 2)))], [(np.exp((1j * phi)) * np.sin((theta / 2))), (np.exp(((1j * phi) + (1j * lam))) * np.cos((theta / 2)))]])

Get the matrix for a single qubit.

Args:
gate(str): the single qubit gate name
params(list): the operation parameters op['params']
Returns:
array: A numpy array representing the matrix


def _prepare_host_call_fn(self, processed_t_fetches, op_fetches, graph, graph_summary_tag):
    if self._parameters.trace_dir is None:
        raise ValueError('Provide a trace_dir for tensor tracer in summary mode. --trace_dir=/model/dir')

    def _write_cache(step, event_file_suffix=None, **kwargs):

        file_suffix = _TT_EVENT_FILE_SUFFIX
        if event_file_suffix is not None:
            file_suffix = string_ops.string_join([file_suffix, event_file_suffix], separator='.')
        summary_write_ops = []
        summary_writer = summary.create_file_writer_v2(self._parameters.trace_dir, filename_suffix=file_suffix, max_queue=_TT_SUMMARY_MAX_QUEUE)
        graph.add_to_collection(TENSOR_TRACER_SUMMARY_COLLECTION, summary_writer)
        step_value = step[0]
        dt = step_value.dtype
        if dt.__ne__(dtypes.int64) and dt.__ne__(dtypes.uint64) and dt.__ne__(dtypes.float64):
            step_value = math_ops.cast(step_value, dtypes.int64)
        with summary_writer.as_default():
            summary_metadata = summary_pb2.SummaryMetadata(plugin_data=summary_pb2.SummaryMetadata.PluginData(plugin_name=_TT_TENSORBOARD_PLUGIN_NAME))
            for key, value in kwargs.items():
                if not self._parameters.collect_summary_per_core:
                    if key == _TT_SUMMARY_TAG and value.shape.as_list()[0] != 1:
                        value = self.aggregate_global_cache(value)
                with ops.control_dependencies([summary_writer.init()]):
                    summary_write_ops.append(summary.write(_TT_SUMMARY_TAG + '/' + key + '.' + graph_summary_tag, value, metadata=summary_metadata, step=step_value))
        return control_flow_ops.group(summary_write_ops)
    global_step = training_util.get_or_create_global_step()
    step = array_ops.reshape(global_step, [1])
    self._host_call_fn = {}
    host_call_deps = op_fetches + [tensor.op for tensor in processed_t_fetches]
    caches_to_write = {}
    with ops.control_dependencies(host_call_deps):
        all_caches = self._cache_variable_for_graph(graph)
        for cache_name, cache_variable in all_caches.items():
            new_cache_shape = [1]
            new_cache_shape.extend(cache_variable.shape.as_list())
            cache = array_ops.reshape(cache_variable, new_cache_shape)
            caches_to_write[cache_name] = cache
    caches_to_write['step'] = step
    self._host_call_fn[_TT_HOSTCALL_KEY] = (_write_cache, caches_to_write)

Creates a host call function that will write the cache as tb summary.

Args:
processed_t_fetches: List of tensor provided to session.run.
op_fetches: List of operations provided to session.run.
graph: TensorFlow graph.
graph_summary_tag: the summary_tag name for the given graph.
Raises:
ValueError if trace_dir is not set.


def warn_once(self, msg, msg_name=None):
    assert isinstance(msg, str)
    msg_name = (msg_name if msg_name else msg)
    if (msg_name not in warnings_given):
        warnings.warn(msg)
    warnings_given.add(msg_name)

Prints a warning statement just once

Args:
msg: The warning message
msg_name: [optional] The name of the warning. If None, the msg_name
will be the msg itself.


def from_lasio(cls, l, remap=None, funcs=None):
    params = {}
    funcs = (funcs or {})
    funcs['location'] = str
    for (field, (sect, code)) in las_fields['location'].items():
        params[field] = utils.lasio_get(l, sect, code, remap=remap, funcs=funcs)
    return cls(params)

Make a Location object from a lasio object. Assumes we're starting
with a lasio object, l.

Args:
l (lasio).
remap (dict): Optional. A dict of 'old': 'new' LAS field names.
funcs (dict): Optional. A dict of 'las field': function() for
implementing a transform before loading. Can be a lambda.

Returns:
Location. An instance of this class.


def get_port(self, id_or_uri, port_id_or_uri):
    uri = self._client.build_subresource_uri(id_or_uri, port_id_or_uri, 'ports')
    return self._client.get(uri)

Gets an interconnect port.

Args:
id_or_uri: Can be either the interconnect id or uri.
port_id_or_uri: The interconnect port id or uri.

Returns:
dict: The interconnect port.


def _offset(value):

    o = int(value)
    if o == 0:
        return 0
    a = abs(o)
    s = a*36+(a%100)*24
    return (o

Parse timezone to offset in seconds.

Args:
value: A timezone in the '+0000' format. An integer would also work.

Returns:
The timezone offset from GMT in seconds as an integer.


def _is_trivial(node):
    trivial_node_types = (gast.Name, bool, str, gast.Add, gast.Sub, gast.Mult, gast.Div, gast.Mod, gast.Pow, gast.LShift, gast.RShift, gast.BitOr, gast.BitXor, gast.BitAnd, gast.FloorDiv, gast.Invert, gast.Not, gast.UAdd, gast.USub, gast.Eq, gast.NotEq, gast.Lt, gast.LtE, gast.Gt, gast.GtE, gast.Is, gast.IsNot, gast.In, gast.NotIn, gast.expr_context)
    if isinstance(node, trivial_node_types) and (not _is_py2_name_constant(node)):
        return True
    if gast_util.is_ellipsis(node):
        return True
    return False

Returns whether to consider the given node 'trivial'.

The definition of 'trivial' is a node that can't meaningfully be pulled out
into its own assignment statement.

This is surprisingly difficult to do robustly across versions of Python and
gast, as the parsing of constants has changed, if I may, constantly.

Args:
node: An AST node to check for triviality

Returns:
trivial: A Python `bool` indicating whether the node is trivial.


def _process_image(filename, coder):
    with tf.gfile.FastGFile(filename, 'r') as f:
        image_data = f.read()
    if _is_png(filename):
        print(('Converting PNG to JPEG for %s' % filename))
        image_data = coder.png_to_jpeg(image_data)
    elif _is_cmyk(filename):
        print(('Converting CMYK to RGB for %s' % filename))
        image_data = coder.cmyk_to_rgb(image_data)
    image = coder.decode_jpeg(image_data)
    assert (len(image.shape) == 3)
    height = image.shape[0]
    width = image.shape[1]
    assert (image.shape[2] == 3)
    return (image_data, height, width)

Process a single image file.

Args:
filename: string, path to an image file e.g., '/path/to/example.JPG'.
coder: instance of ImageCoder to provide TensorFlow image coding utils.
Returns:
image_buffer: string, JPEG encoding of RGB image.
height: integer, image height in pixels.
width: integer, image width in pixels.


def with_dependencies(self, checks):
    pass

Add dependencies to a _LayerBroadcaster.

Args:
checks: a list of ops that need to be run before any tensors from the
Broadcaster are used.

Returns:
a copy of this _LayerBroadcaster with dependencies added.


def catch(func, *args, **kwargs):

    try:
        func(*args, **kwargs)
    except Exception as e:
        return e

Call the supplied function with the supplied arguments,
catching and returning any exception that it throws.

Arguments:
func: the function to run.
*args: positional arguments to pass into the function.
**kwargs: keyword arguments to pass into the function.
Returns:
If the function throws an exception, return the exception.
If the function does not throw an exception, return None.


def uses_star_args_or_kwargs_in_call(node):
    return uses_star_args_in_call(node) or uses_star_kwargs_in_call(node)

Check if an ast.Call node uses arbitrary-length *args or **kwargs.

This function works with the AST call node format of Python3.5+
as well as the different AST format of earlier versions of Python.

Args:
node: The ast.Call node to check arg values for.

Returns:
True if the node uses starred variadic positional args or keyword args.
False if it does not.


def _get_userprofile_from_registry(user, sid):

    profile_dir = __utils__['reg.read_value'](
        'HKEY_LOCAL_MACHINE',
        'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\{0}'.format(sid),
        'ProfileImagePath'
    )['vdata']
    log.debug(
        'user %s with sid=%s profile is located at "%s"',
        user, sid, profile_dir
    )
    return profile_dir

In case net user doesn't return the userprofile we can get it from the
registry

Args:
user (str): The user name, used in debug message

sid (str): The sid to lookup in the registry

Returns:
str: Profile directory


def _ReadRecordSchemaInformation(self, tables, file_object, record_offset):

    _ = self._ReadRecordHeader(file_object, record_offset)

    attribute_value_offsets = self._ReadRecordAttributeValueOffset(
        file_object, record_offset + 24, 2)

    if attribute_value_offsets != (0x21, 0x25):
      raise errors.ParseError('Unsupported record attribute value offsets')

    file_offset = file_object.tell()
    data_type_map = self._GetDataTypeMap('keychain_record_schema_information')

    record_values, _ = self._ReadStructureFromFileObject(
        file_object, file_offset, data_type_map)

    relation_name = record_values.relation_name.decode('ascii')

    table = KeychainDatabaseTable()
    table.relation_identifier = record_values.relation_identifier
    table.relation_name = relation_name

    tables[table.relation_identifier] = table

    table = tables.get(self._RECORD_TYPE_CSSM_DL_DB_SCHEMA_INFO, None)
    if not table:
      raise errors.ParseError('Missing CSSM_DL_DB_SCHEMA_INFO table.')

    record = collections.OrderedDict({
        'RelationID': record_values.relation_identifier,
        'RelationName': relation_name})

    table.records.append(record)

Reads a schema information (CSSM_DL_DB_SCHEMA_INFO) record.

Args:
tables (dict[int, KeychainDatabaseTable]): tables per identifier.
file_object (file): file-like object.
record_offset (int): offset of the record relative to the start of
the file.

Raises:
ParseError: if the record cannot be read.


def submit_data(self, batch_id, halt_on_error=True):

        if self.halt_on_batch_error is not None:
            halt_on_error = self.halt_on_batch_error

        content = self.data

        self._batch_data_count = len(content.get('group')) + len(content.get('indicator'))
        self.tcex.log.info('Batch Size: {:,}'.format(self._batch_data_count))
        if content.get('group') or content.get('indicator'):
            headers = {'Content-Type': 'application/octet-stream'}
            try:
                r = self.tcex.session.post(
                    '/v2/batch/{}'.format(batch_id), headers=headers, json=content
                )
            except Exception as e:
                self.tcex.handle_error(10520, [e], halt_on_error)
            if not r.ok or 'application/json' not in r.headers.get('content-type', ''):
                self.tcex.handle_error(10525, [r.status_code, r.text], halt_on_error)
            return r.json()
        return {}

Submit Batch request to ThreatConnect API.
Args:
batch_id (string): The batch id of the current job.


def get_snippet_client(self, name):
    if name in self._snippet_clients:
        return self._snippet_clients[name]

Gets the snippet client managed under a given name.

Args:
name: string, the name of the snippet client under management.

Returns:
SnippetClient.


def replace_method_name(self, signature_key, method_name, tags=None):
    if not signature_key:
        raise ValueError('`signature_key` must be defined.')
    if not method_name:
        raise ValueError('`method_name` must be defined.')
    if tags is not None and (not isinstance(tags, list)):
        tags = [tags]
    found_match = False
    for meta_graph_def in self._saved_model.meta_graphs:
        if tags is None or set(tags) == set(meta_graph_def.meta_info_def.tags):
            if signature_key not in meta_graph_def.signature_def:
                raise ValueError(f"MetaGraphDef associated with tags {tags} does not have a signature_def with key: '{signature_key}'. This means either you specified the wrong signature key or forgot to put the signature_def with the corresponding key in your SavedModel.")
            meta_graph_def.signature_def[signature_key].method_name = method_name
            found_match = True
    if not found_match:
        raise ValueError(f'MetaGraphDef associated with tags {tags} could not be found in SavedModel. This means either you specified invalid tags or your SavedModel does not have a MetaGraphDef with the specified tags.')

Replaces the method_name in the specified signature_def.

This will match and replace multiple sig defs iff tags is None (i.e when
multiple `MetaGraph`s have a signature_def with the same key).
If tags is not None, this will only replace a single signature_def in the
`MetaGraph` with matching tags.

Args:
signature_key: Key of the signature_def to be updated.
method_name: new method_name to replace the existing one.
tags: A tag or sequence of tags identifying the `MetaGraph` to update. If
None, all meta graphs will be updated.
Raises:
ValueError: if signature_key or method_name are not defined or
if no metagraphs were found with the associated tags or
if no meta graph has a signature_def that matches signature_key.


def retry_handler(retries=0, delay=timedelta(), conditions=[]):

    delay_in_seconds = delay.total_seconds()
    return partial(retry_loop, retries, delay_in_seconds, conditions)

A simple wrapper function that creates a handler function by using
on the retry_loop function.

Args:
retries (Integral): The number of times to retry if a failure occurs.
delay (timedelta, optional, 0 seconds): A timedelta representing
the amount time to delay between retries.
conditions (list): A list of retry conditions.
Returns:
function: The retry_loop function partialed.


def _batch_rp_spec(rp_spec: RowPartitionSpec, batch_size: Optional[int]) -> RowPartitionSpec:
    if batch_size is None:
        return RowPartitionSpec(uniform_row_length=rp_spec.uniform_row_length, dtype=rp_spec.dtype)
    nrows = None if rp_spec.nrows is None else rp_spec.nrows * batch_size
    nvals = None if rp_spec.nvals is None else rp_spec.nvals * batch_size
    return RowPartitionSpec(nrows=nrows, nvals=nvals, uniform_row_length=rp_spec.uniform_row_length, dtype=rp_spec.dtype)

Batches a RowPartitionSpec.

Given a RowPartitionSpec and a batch_size, create a RowPartitionSpec that
will be the spec for the concatenation of batch_size RowPartitions.

A RowPartition can be considered a transformation from a list of a given
length to a list of lists. Assume rp_a is a map from list_a to nlist_a,
And rp_b is a map from list_b to nlist_b. concat(rp_a, rp_b) is a
transform of concat(list_a, list_b) to concat(nlist_a, nlist_b).

If batch_size is None, then have the spec be able to handle an arbitrary
number of RowPartitions.

Args:
rp_spec: a RowPartitionSpec for all the RowPartitions to be concatenated.
batch_size: the number of rp_specs to be concatenated.

Returns:
a batched RowPartitionSpec.


def exhaustive_iri_check(self, ontology: pd.DataFrame, iri_predicate: str, diff: bool=True) -> Tuple[list]:
    (inside, outside) = ([], [])
    header = (['Index'] + list(ontology.columns))
    for row in ontology.itertuples():
        row = {header[i]: val for (i, val) in enumerate(row)}
        entity_iri = row[iri_predicate]
        if isinstance(entity_iri, list):
            if (len(entity_iri) != 0):
                exit('Need to have only 1 iri in the cell from the onotology.')
            else:
                entity_iri = entity_iri[0]
        ilx_row = self.iri2row.get(entity_iri)
        if ilx_row:
            inside.append({'external_ontology_row': row, 'ilx_rows': [ilx_row]})
        else:
            outside.append(row)
    if diff:
        diff = self.__exhaustive_diff(inside)
        return (inside, outside, diff)
    return (inside, outside)

All entities with conflicting iris gets a full diff to see if they belong

Args:
ontology: pandas DataFrame created from an ontology where the colnames are predicates
and if classes exist it is also thrown into a the colnames.
iri_predicate: usually in qname form and is the colname of the DataFrame for iri
Default is "iri" for graph2pandas module
diff: complete exhaustive diff if between curie matches... will take FOREVER if there are a lot -> n^2
Returns:
inside: entities that are inside of InterLex
outside: entities NOT in InterLex
diff (optional): List[List[dict]]... so complicated but usefull diff between matches only


def detect_language(index_page):
    dom = dhtmlparser.parseString(index_page)
    clean_content = dhtmlparser.removeTags(dom)
    lang = None
    try:
        lang = langdetect.detect(clean_content)
    except UnicodeDecodeError:
        lang = langdetect.detect(clean_content.decode('utf-8'))
    return SourceString(lang, source='langdetect')

Detect `languages` using `langdetect` library.

Args:
index_page (str): HTML content of the page you wish to analyze.

Returns:
obj: One :class:`.SourceString` object.


def check_integrity(sakefile, settings):

    sprint = settings["sprint"]
    error = settings["error"]
    sprint("Call to check_integrity issued", level="verbose")
    if not sakefile:
        error("Sakefile is empty")
        return False

    if len(sakefile.keys()) != len(set(sakefile.keys())):
        error("Sakefile contains duplicate targets")
        return False
    for target in sakefile:
        if target == "all":
            if not check_target_integrity(target, sakefile["all"], all=True):
                error("Failed to accept target 'all'")
                return False
            continue
        if "formula" not in sakefile[target]:
            if not check_target_integrity(target, sakefile[target],
                                          meta=True):
                errmes = "Failed to accept meta-target '{}'".format(target)
                error(errmes)
                return False
            for atom_target in sakefile[target]:
                if atom_target == "help":
                    continue
                if not check_target_integrity(atom_target,
                                              sakefile[target][atom_target],
                                              parent=target):
                    errmes = "Failed to accept target '{}'\n".format(
                                                                atom_target)
                    error(errmes)
                    return False
            continue
        if not check_target_integrity(target, sakefile[target]):
            errmes = "Failed to accept target '{}'\n".format(target)
            error(errmes)
            return False
    return True

Checks the format of the sakefile dictionary
to ensure it conforms to specification

Args:
A dictionary that is the parsed Sakefile (from sake.py)
The setting dictionary (for print functions)
Returns:
True if the Sakefile is conformant
False if not


class AriaSharedExpertsMLP(nn.Module):

    def __init__(self, config: AriaTextConfig):
        super().__init__()
        self.config = config
        self.hidden_size = config.hidden_size
        self.intermediate_size = config.intermediate_size * config.moe_num_shared_experts
        self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
        self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
        self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=config.mlp_bias)
        self.act_fn = ACT2FN[config.hidden_act]

    def forward(self, x):
        down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
        return down_proj

Shared Expert MLP for shared experts.

Unlike routed experts, shared experts process all tokens without routing.
This class reconfigures the intermediate size in comparison to the LlamaMLP.

Args:
config (`AriaTextConfig`): Configuration object for the Aria language model.


def notify_rollover(self, stream):

        self.offset -= 1

        if not self.matches(stream):
            return

        if self._count == 0:
            raise InternalError("BufferedStreamWalker out of sync with storage engine, count was wrong.")

        self._count -= 1

Notify that a reading in the given stream was overwritten.

Args:
stream (DataStream): The stream that had overwritten data.


def get_dihedral(self, i: int, j: int, k: int, l: int) -> float:

        v1 = self[k].coords - self[l].coords
        v2 = self[j].coords - self[k].coords
        v3 = self[i].coords - self[j].coords
        v23 = np.cross(v2, v3)
        v12 = np.cross(v1, v2)
        return math.degrees(math.atan2(np.linalg.norm(v2) * np.dot(v1, v23),
                                       np.dot(v12, v23)))

Returns dihedral angle specified by four sites.

Args:
i: Index of first site
j: Index of second site
k: Index of third site
l: Index of fourth site

Returns:
Dihedral angle in degrees.


def _extend_object(parent, n, o, otype, fqdn):
    from inspect import ismodule, isclass
    pmodule = (parent if (ismodule(parent) or isclass(parent)) else None)
    try:
        if (otype == 'methods'):
            setattr(o.__func__, '__acornext__', None)
        else:
            setattr(o, '__acornext__', None)
        fqdn = _fqdn(o, recheck=True, pmodule=pmodule)
        return o
    except (TypeError, AttributeError):
        okey = id(o)
        if (okey not in _extended_objs):
            xobj = _create_extension(o, otype, fqdn, pmodule)
            fqdn = _fqdn(xobj, recheck=True, pmodule=pmodule)
            if (xobj is not None):
                _extended_objs[okey] = xobj
        try:
            setattr(parent, n, _extended_objs[okey])
            return _extended_objs[okey]
        except KeyError:
            msg.warn('Object extension failed: {} ({}).'.format(o, otype))

Extends the specified object if it needs to be extended. The method
attempts to add an attribute to the object; if it fails, a new object is
created that inherits all of `o` attributes, but is now a regular object
that can have attributes set.

Args:
parent: has `n` in its `__dict__` attribute.
n (str): object name attribute.
o (list): object instances to be extended.
otype (str): object types; one of ["classes", "functions", "methods",
"modules"].
fqdn (str): fully qualified name of the package that the object belongs
to.


def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    super(Nonce, self).read(input_stream, kmip_version=kmip_version)
    local_stream = BytearrayStream(input_stream.read(self.length))
    if self.is_tag_next(enums.Tags.NONCE_ID, local_stream):
        self._nonce_id = primitives.ByteString(tag=enums.Tags.NONCE_ID)
        self._nonce_id.read(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('Nonce encoding missing the nonce ID.')
    if self.is_tag_next(enums.Tags.NONCE_VALUE, local_stream):
        self._nonce_value = primitives.ByteString(tag=enums.Tags.NONCE_VALUE)
        self._nonce_value.read(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('Nonce encoding missing the nonce value.')
    self.is_oversized(local_stream)

Read the data encoding the Nonce struct and decode it into its
constituent parts.

Args:
input_stream (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 will be decoded. Optional,
defaults to KMIP 1.0.

Raises:
ValueError: Raised if the nonce ID or nonce value is missing from
the encoding.


def layer_statistics_dump(self, file: IO[str]) -> None:
    fields = ['op_name', 'tensor_idx'] + list(self._layer_debug_metrics.keys())
    if self._debug_options.layer_direct_compare_metrics is not None:
        fields += list(self._debug_options.layer_direct_compare_metrics.keys())
    fields += ['scale', 'zero_point', 'tensor_name']
    writer = csv.DictWriter(file, fields)
    writer.writeheader()
    if self.layer_statistics:
        for name, metrics in self.layer_statistics.items():
            data = metrics.copy()
            data['tensor_name'], _ = self._get_operand_name_and_index(name)
            data['tensor_idx'] = self._numeric_verify_op_details[name]['inputs'][0]
            data['op_name'] = self._quant_interpreter._get_op_details(self._defining_op[data['tensor_idx']])['op_name']
            details = self._quant_interpreter._get_tensor_details(data['tensor_idx'], subgraph_index=0)
            data['scale'], data['zero_point'] = (details['quantization_parameters']['scales'][0], details['quantization_parameters']['zero_points'][0])
            writer.writerow(data)

Dumps layer statistics into file, in csv format.

Args:
file: file, or file-like object to write.


def parse_procheck(quality_directory):
    procheck_summaries = glob.glob(os.path.join(quality_directory, '*.sum'))
    if (len(procheck_summaries) == 0):
        return pd.DataFrame()
    all_procheck = {}
    for summ in procheck_summaries:
        structure_id = os.path.basename(summ).split('.sum')[0]
        procheck_dict = {}
        with open(summ) as f_in:
            lines = (line.rstrip() for line in f_in)
            lines = (line for line in lines if line)
            for line in lines:
                if (len(line.split()) > 1):
                    if (line.split()[1] == 'Ramachandran'):
                        procheck_dict['procheck_rama_favored'] = percentage_to_float(line.split()[3])
                        procheck_dict['procheck_rama_allowed'] = percentage_to_float(line.split()[5])
                        procheck_dict['procheck_rama_allowed_plus'] = percentage_to_float(line.split()[7])
                        procheck_dict['procheck_rama_disallowed'] = percentage_to_float(line.split()[9])
                    if (line.split()[1] == 'G-factors'):
                        procheck_dict['procheck_gfac_dihedrals'] = line.split()[3]
                        procheck_dict['procheck_gfac_covalent'] = line.split()[5]
                        procheck_dict['procheck_gfac_overall'] = line.split()[7]
        all_procheck[structure_id] = procheck_dict
    DF_PROCHECK = pd.DataFrame.from_dict(all_procheck, orient='index')
    return DF_PROCHECK

Parses all PROCHECK files in a directory and returns a Pandas DataFrame of the results

Args:
quality_directory: path to directory with PROCHECK output (.sum files)

Returns:
Pandas DataFrame: Summary of PROCHECK results


def parse_config_file(config_file, skip_unknown=False):
    for (reader, existence_check) in _FILE_READERS:
        if existence_check(config_file):
            with reader(config_file) as f:
                parse_config(f, skip_unknown=skip_unknown)
                return
    raise IOError('Unable to open file: {}'.format(config_file))

Parse a Gin config file.

Args:
config_file: The path to a Gin config file.
skip_unknown: A boolean indicating whether unknown configurables and imports
should be skipped instead of causing errors (alternatively a list of
configurable names to skip if unknown). See `parse_config` for additional
details.

Raises:
IOError: If `config_file` cannot be read using any register file reader.


def user_activity_stats(self, username, format=None):
    request_url = '{}/api/0/user/{}/activity/stats'.format(self.instance, username)
    payload = {}
    if (username is not None):
        payload['username'] = username
    if (format is not None):
        payload['format'] = format
    return_value = self._call_api(request_url, params=payload)
    return return_value

Retrieve the activity stats about a specific user over the last year.

Params:
username (string): filters the username of the user whose activity you are interested in.
format (string): Allows changing the of the date/time returned from iso format
to unix timestamp Can be: timestamp or isoformat
Returns:
dict: A dictionary of activities done by a given user for all the projects
for a given Pagure instance.


def transform(self, column):
    self.check_data_type()
    return pd.DataFrame({self.col_name: np.exp(column[self.col_name])})

Applies an exponential to values to turn them positive numbers.

Args:
column (pandas.DataFrame): Data to transform.

Returns:
pd.DataFrame


def create(self, master_course_id, coach_email, max_students_allowed, title, modules=None):

        payload = {
            'master_course_id': master_course_id,
            'coach_email': coach_email,
            'max_students_allowed': max_students_allowed,
            'display_name': title,
        }

        if modules is not None:
            payload['course_modules'] = modules

        resp = self.requester.post(
            parse.urljoin(self.base_url, '/api/ccx/v0/ccx/'),
            json=payload
        )

        try:
            resp.raise_for_status()
        except:
            log.error(resp.json())
            raise

        return resp.json()['ccx_course_id']

Creates a CCX

Args:
master_course_id (str): edx course id of the master course
coach_email (str): email of the user to make a coach. This user must exist on edx.
max_students_allowed (int): Maximum number of students to allow in this ccx.
title (str): Title of the CCX to be created
modules (optional list): A list of locator_ids (str) for the modules to enable.

Returns:
ccx_id (str): The ID of the ccx.


def pylint_check(files):
    files = fs.wrap_paths(files)
    cfg_path = conf.get_path('lint.pylint_cfg', 'ops/tools/pylint.ini')
    pylint_cmd = 'pylint --rcfile {} {}'.format(cfg_path, files)
    return shell.run(pylint_cmd, exit_on_error=False).return_code

Run code checks using pylint.

Args:
files (list[str]):
A list of files to check

Returns:
bool: **True** if all files passed the checks, **False** otherwise.


def simplify(self, eps, max_dist_error, max_speed_error, topology_only=False):
    if topology_only:
        self.points = drp(self.points, eps)
    else:
        self.points = spt(self.points, max_dist_error, max_speed_error)
    return self

In-place segment simplification

See `drp` and `compression` modules

Args:
eps (float): Distance threshold for the `drp` function
max_dist_error (float): Max distance error, in meters
max_speed_error (float): Max speed error, in km/h
topology_only (bool, optional): True to only keep topology, not considering
times when simplifying. Defaults to False.
Returns:
:obj:`Segment`


def _ReadString(
      self, file_object, file_offset, data_type_map, description):

    element_data_size = (
        data_type_map._element_data_type_definition.GetByteSize())
    elements_terminator = (
        data_type_map._data_type_definition.elements_terminator)

    byte_stream = []

    element_data = file_object.read(element_data_size)
    byte_stream.append(element_data)
    while element_data and element_data != elements_terminator:
      element_data = file_object.read(element_data_size)
      byte_stream.append(element_data)

    byte_stream = b''.join(byte_stream)

    return self._ReadStructureFromByteStream(
        byte_stream, file_offset, data_type_map, description)

Reads a string.

Args:
file_object (FileIO): file-like object.
file_offset (int): offset of the data relative from the start of
the file-like object.
data_type_map (dtfabric.DataTypeMap): data type map of the string.
description (str): description of the string.

Returns:
object: structure values object.

Raises:
FileFormatError: if the string cannot be read.
ValueError: if file-like object or date type map are invalid.


def check_causatives(self, case_obj=None, institute_obj=None):

        institute_id = case_obj['owner'] if case_obj else institute_obj['_id']
        institute_causative_variant_ids = self.get_causatives(institute_id)
        if len(institute_causative_variant_ids) == 0:
            return []

        if case_obj:

            case_causative_ids = set(case_obj.get('causatives', []))
            institute_causative_variant_ids = list(
                set(institute_causative_variant_ids).difference(case_causative_ids)
            )

        query = self.variant_collection.find(
            {'_id': {'$in': institute_causative_variant_ids}},
            {'variant_id': 1}
        )
        positional_variant_ids = [item['variant_id'] for item in query]

        filters = {'variant_id': {'$in': positional_variant_ids}}
        if case_obj:
            filters['case_id'] = case_obj['_id']
        else:
            filters['institute'] = institute_obj['_id']
        return self.variant_collection.find(filters)

Check if there are any variants that are previously marked causative

Loop through all variants that are marked 'causative' for an
institute and check if any of the variants are present in the
current case.

Args:
case_obj (dict): A Case object
institute_obj (dict): check across the whole institute

Returns:
causatives(iterable(Variant))


def move_bulk(self, from_statuses, to_status):

        for status in from_statuses:
            from_status_items = self.__get_var("items_" + status)
            self.__set_var("items_" + status, OrderedDict())

            to_status_items = self.__get_var("items_" + to_status)
            to_status_items.update(from_status_items)

Move a bulk of request/response pairs to another status

Args:
from_statuses list(str): The statuses to move from
to_status (str): The status to move to


def get_by(self, field, value):
    firmwares = self.get_all()
    matches = []
    for item in firmwares:
        if (item.get(field) == value):
            matches.append(item)
    return matches

Gets the list of firmware baseline resources managed by the appliance. Optional parameters can be used to
filter the list of resources returned.

The search is case-insensitive.

Args:
field: Field name to filter.
value: Value to filter.

Returns:
list: List of firmware baseline resources.


def cuda(self) -> Rotation:
    if self._rot_mats is not None:
        return Rotation(rot_mats=self._rot_mats.cuda(), quats=None)
    elif self._quats is not None:
        return Rotation(rot_mats=None, quats=self._quats.cuda(), normalize_quats=False)
    else:
        raise ValueError('Both rotations are None')

Analogous to the cuda() method of torch Tensors

Returns:
A copy of the Rotation in CUDA memory


def entry_verifier(entries, regex, delimiter):
    cregex = re.compile(regex)
    python_version = int(sys.version.split('.')[0])
    decoder = ('unicode-escape' if (python_version == 3) else 'string-escape')
    dedelimiter = codecs.decode(delimiter, decoder)
    for entry in entries:
        match = re.match(cregex, entry)
        if (not match):
            split_regex = regex.split(delimiter)
            split_entry = entry.split(dedelimiter)
            part = 0
            for (regex_segment, entry_segment) in zip(split_regex, split_entry):
                if (not (regex_segment[0] == '^')):
                    regex_segment = ('^' + regex_segment)
                if (not (regex_segment[(- 1)] == '$')):
                    regex_segment += '$'
                if (not re.match(regex_segment, entry_segment)):
                    raise FormatError(template=regex_segment, subject=entry_segment, part=part)
                part += 1

Checks each entry against regex for validity,

If an entry does not match the regex, the entry and regex
are broken down by the delimiter and each segment is analyzed
to produce an accurate error message.

Args:
entries (list): List of entries to check with regex

regex (str): Regular expression to compare entries with

delimiter (str): Character to split entry and regex by, used to check
parts of entry and regex to narrow in on the error

Raises:
FormatError: Class containing regex match error data

Example:
>>> regex = r'^>.+\\n[ACGTU]+\\n$'
>>> entry = [r'>entry1\\nAGGGACTA\\n']
>>> entry_verifier(entry, regex, '\\n')


def rebuild_ragged_tensor_with_value_rowids(rt, feed_dict=None, sess=None):
    if isinstance(rt, ragged_tensor.RaggedTensor):
        values = rebuild_ragged_tensor_with_value_rowids(rt.values, feed_dict, sess)
        rowids = rt.value_rowids()
        nrows = rt.nrows()
        if feed_dict is not None:
            rowids_ph = make_placeholder(rowids)
            nrows_ph = make_placeholder(nrows)
            feed_dict[rowids_ph] = sess.run(rowids)
            feed_dict[nrows_ph] = sess.run(nrows)
            rowids, nrows = (rowids_ph, nrows_ph)
        return ragged_tensor.RaggedTensor.from_value_rowids(values, rowids, nrows)
    else:
        if feed_dict is not None:
            rt_ph = make_placeholder(rt)
            feed_dict[rt_ph] = sess.run(rt)
            rt = rt_ph
        return rt

Returns a copy of `rt`, built using `from_value_rowids`.

This ensures that RaggedTensor._cached_value_rowids is populated, which
triggers a different code-path for converting ragged tensors to tensors.

If `feed_dict` and `sess` are specified, then build the new `RaggedTensor`
using placeholder tensors, and populate a feed dictionary that can be used
to feed the placeholders.

Args:
rt: The RaggedTensor to copy.
feed_dict: If specified, then build the new `RaggedTensor` using
placeholders, and populate this dict with entries to feed those
placeholders.
sess: A session used to evaluate tensors; required if feed_dict is
specified.

Returns:
A copy of `rt`, built using `from_value_rowids`.


def find_and_replace_userids(self, text):
    match = True
    pattern = re.compile('<@([A-Z0-9]{9})>')
    while match:
        match = pattern.search(text)
        if match:
            name = self.get_user_display_name(match.group(1))
            text = re.sub(re.compile(match.group(0)), ('@' + name), text)
    return text

Finds occurrences of Slack userids and attempts to replace them with
display names.

Args:
text (string): The message text
Returns:
string: The message text with userids replaced.


def _ws_on_close(self, ws: websocket.WebSocketApp):

        self.connected = False
        self.logger.error('Websocket closed')
        self._reconnect_websocket()

Callback for closing the websocket connection

Args:
ws: websocket connection (now closed)


def usergroups_users_list(self, *, usergroup: str, **kwargs) -> SlackResponse:
    self._validate_xoxp_token()
    kwargs.update({'usergroup': usergroup})
    return self.api_call('usergroups.users.list', http_verb='GET', params=kwargs)

List all users in a User Group

Args:
usergroup (str): The encoded ID of the User Group to update.
e.g. 'S0604QSJC'


def object_graph_key_mapping(checkpoint_path):
    reader = py_checkpoint_reader.NewCheckpointReader(checkpoint_path)
    object_graph_string = reader.get_tensor(trackable.OBJECT_GRAPH_PROTO_KEY)
    object_graph_proto = trackable_object_graph_pb2.TrackableObjectGraph()
    object_graph_proto.ParseFromString(object_graph_string)
    names_to_keys = {}
    for node in object_graph_proto.nodes:
        for attribute in node.attributes:
            names_to_keys[attribute.full_name] = attribute.checkpoint_key
    return names_to_keys

Return name to key mappings from the checkpoint.

Args:
checkpoint_path: string, path to object-based checkpoint

Returns:
Dictionary mapping tensor names to checkpoint keys.


def _VerifyValues(self, tensor_in_sizes, depthwise_filter_in_sizes, pointwise_filter_in_sizes, stride, padding, expected, data_format='NHWC'):
    with self.cached_session():
        t1 = self._InitValues(tensor_in_sizes)
        f1 = self._InitValues(depthwise_filter_in_sizes)
        f1.set_shape(depthwise_filter_in_sizes)
        f2 = self._InitValues(pointwise_filter_in_sizes)
        real_t1 = t1
        strides = [1, stride, stride, 1]
        if data_format == 'NCHW':
            real_t1 = array_ops.transpose(t1, [0, 3, 1, 2])
            strides = [1, 1, stride, stride]
            if isinstance(padding, list):
                padding = [padding[0], padding[3], padding[1], padding[2]]
        conv = nn_impl.separable_conv2d(real_t1, f1, f2, strides=strides, padding=padding, data_format=data_format)
        if data_format == 'NCHW':
            conv = array_ops.transpose(conv, [0, 2, 3, 1])
        value = self.evaluate(conv)
    tf_logging.debug('value = %s', value)
    self.assertArrayNear(expected, np.ravel(value), 0.002)
    self.assertShapeEqual(value, conv)

Verifies the output values of the separable convolution function.

Args:
tensor_in_sizes: Input tensor dimensions.
depthwise_filter_in_sizes: Depthwise filter tensor dimensions.
pointwise_filter_in_sizes: Pointwise filter tensor dimensions.
stride: Stride.
padding: Padding type.
expected: An array containing the expected operation outputs.
data_format: string data format for input tensor.


def _letter_map(word):

    lmap = {}
    for letter in word:
        try:
            lmap[letter] += 1
        except KeyError:
            lmap[letter] = 1
    return lmap

Creates a map of letter use in a word.

Args:
word: a string to create a letter map from

Returns:
a dictionary of {letter: integer count of letter in word}


def __findFirstMissing(self, array, start, end):
    if (start > end):
        return (end + 1)
    if (start != array[start]):
        return start
    mid = int(((start + end) / 2))
    if (array[mid] == mid):
        return self.__findFirstMissing(array, (mid + 1), end)
    return self.__findFirstMissing(array, start, mid)

Find the smallest elements missing in a sorted array.

Returns:
int: The smallest element missing.


def write_file(
    task: Task,
    filename: str,
    content: str,
    append: bool = False,
    dry_run: Optional[bool] = None,
) -> Result:

    diff = _generate_diff(filename, content, append)

    if not task.is_dry_run(dry_run):
        mode = "a+" if append else "w+"
        with open(filename, mode=mode) as f:
            f.write(content)

    return Result(host=task.host, diff=diff, changed=bool(diff))

Write contents to a file (locally)

Arguments:
dry_run: Whether to apply changes or not
filename: file you want to write into
content: content you want to write
append: whether you want to replace the contents or append to it

Returns:
Result object with the following attributes set:
* changed (``bool``):
* diff (``str``): unified diff


def get_instances(serials):
    objs = []
    for s in serials:
        objs.append(Monsoon(serial=s))
    return objs

Create Monsoon instances from a list of serials.

Args:
serials: A list of Monsoon (integer) serials.

Returns:
A list of Monsoon objects.


def with_eager_op_as_function(cls: Optional[type[_T]]=None, only_as_function: bool=False) -> Union[Callable[[type[_T]], type[_T]], type[_T]]:

    def decorator(cls: type[_T]) -> type[_T]:
        return cls
    if cls is not None:
        return decorator(cls)
    return decorator

Returns the same class. This will be removed once all usages are removed.

Args:
cls: class to decorate.
only_as_function: unused argument.

Returns:
cls


def send_messages(cls, http_request, message_requests):
    deduplicated_messages = set(message_requests)
    for (msg_type, text) in deduplicated_messages:
        message_function = getattr(messages, msg_type)
        message_function(http_request, text)

Deduplicate any outgoing message requests, and send the remainder.

Args:
http_request: The HTTP request in whose response we want to embed the messages
message_requests: A list of undeduplicated messages in the form of tuples of message type
and text- for example, ('error', 'Something went wrong')


def __setitem__(self, keyword, clean_name=None):

        status = False
        if not clean_name and keyword:
            clean_name = keyword

        if keyword and clean_name:
            if not self.case_sensitive:
                keyword = keyword.lower()
            current_dict = self.keyword_trie_dict
            for letter in keyword:
                current_dict = current_dict.setdefault(letter, {})
            if self._keyword not in current_dict:
                status = True
                self._terms_in_trie += 1
            current_dict[self._keyword] = clean_name
        return status

To add keyword to the dictionary
pass the keyword and the clean name it maps to.

Args:
keyword : string
keyword that you want to identify

clean_name : string
clean term for that keyword that you would want to get back in return or replace
if not provided, keyword will be used as the clean name also.

Examples:
>>> keyword_processor['Big Apple'] = 'New York'


def _ParseItem(self, parser_mediator, olecf_item):
    result = False
    event_data = OLECFItemEventData()
    event_data.name = olecf_item.name
    event_data.offset = 0
    event_data.size = olecf_item.size
    (creation_time, modification_time) = self._GetTimestamps(olecf_item)
    if creation_time:
        date_time = dfdatetime_filetime.Filetime(timestamp=creation_time)
        event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_CREATION)
        parser_mediator.ProduceEventWithEventData(event, event_data)
        result = True
    if modification_time:
        date_time = dfdatetime_filetime.Filetime(timestamp=modification_time)
        event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_MODIFICATION)
        parser_mediator.ProduceEventWithEventData(event, event_data)
        result = True
    for sub_item in olecf_item.sub_items:
        if self._ParseItem(parser_mediator, sub_item):
            result = True
    return result

Parses an OLECF item.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
olecf_item (pyolecf.item): OLECF item.

Returns:
bool: True if an event was produced.


def calculate_columns(sequence):
    columns = {}
    for row in sequence:
        for key in row.keys():
            if (key not in columns):
                columns[key] = len(key)
            value_length = len(str(row[key]))
            if (value_length > columns[key]):
                columns[key] = value_length
    return columns

Find all row names and the maximum column widths.

Args:
columns (dict): the keys are the column name and the value the max length.

Returns:
dict: column names (key) and widths (value).


def path_get_destination(p: tcod.path.AStar) -> Tuple[int, int]:

    x = ffi.new("int *")
    y = ffi.new("int *")
    lib.TCOD_path_get_destination(p._path_c, x, y)
    return x[0], y[0]

Get the current destination position.

Args:
p (AStar): An AStar instance.
Returns:
Tuple[int, int]: An (x, y) point.


def IsTensorFlowEventsFile(path):
    if (not path):
        raise ValueError('Path must be a nonempty string')
    return ('tfevents' in tf.compat.as_str_any(os.path.basename(path)))

Check the path name to see if it is probably a TF Events file.

Args:
path: A file path to check if it is an event file.

Raises:
ValueError: If the path is an empty string.

Returns:
If path is formatted like a TensorFlowEventsFile.


def calculate_positions(self, first_bee_val, second_bee_val, value_range):

        value = first_bee_val + np.random.uniform(-1, 1) \
            * (first_bee_val - second_bee_val)
        if value_range[0] == 'int':
            value = int(value)
        if value > value_range[1][1]:
            value = value_range[1][1]
        if value < value_range[1][0]:
            value = value_range[1][0]

        return value

Calculate the new value/position for two given bee values

Args:
first_bee_val (int or float): value from the first bee
second_bee_val (int or float): value from the second bee
value_ranges (tuple): "(value type, (min_val, max_val))" for the
given value

Returns:
int or float: new value


def has_no_fat_ends(neuron, multiple_of_mean=2.0, final_point_count=5):
    bad_ids = []
    for leaf in _nf.iter_sections(neuron.neurites, iterator_type=Tree.ileaf):
        mean_radius = np.mean(leaf.points[1:][((- final_point_count):, COLS.R)])
        if ((mean_radius * multiple_of_mean) <= leaf.points[((- 1), COLS.R)]):
            bad_ids.append((leaf.id, leaf.points[(- 1):]))
    return CheckResult((len(bad_ids) == 0), bad_ids)

Check if leaf points are too large

Arguments:
neuron(Neuron): The neuron object to test
multiple_of_mean(float): how many times larger the final radius
has to be compared to the mean of the final points
final_point_count(int): how many points to include in the mean

Returns:
CheckResult with result list of ids of bad sections

Note:
A fat end is defined as a leaf segment whose last point is larger
by a factor of `multiple_of_mean` than the mean of the points in
`final_point_count`


def unwrap_or_else(self, op: Callable[[E], U]) -> Union[T, U]:

        return cast(T, self._val) if self._is_ok else op(cast(E, self._val))

Returns the sucess value in the :class:`Result` or computes a default
from the error value.

Args:
op: The function to computes default with.

Returns:
The success value in the :class:`Result` if it is
a :meth:`Result.Ok` value, otherwise ``op(E)``.

Examples:
>>> Ok(1).unwrap_or_else(lambda e: e * 10)
1
>>> Err(1).unwrap_or_else(lambda e: e * 10)
10


def get_record(self, name, record_id):

        if name in self._cache:
            if record_id in self._cache[name]:
                return self._cache[name][record_id]

Retrieve a record with a given type name and record id.

Args:
name (string): The name which the record is stored under.
record_id (int): The id of the record requested.

Returns:
:class:`cinder_data.model.CinderModel`: The cached model.


def _make_tensor_slice_spec(slice_spec, use_constant=True):

    def make_piece_scalar(piece):
        if isinstance(piece, int):
            scalar = constant_op.constant(piece)
            if use_constant:
                return scalar
            else:
                return array_ops.placeholder_with_default(scalar, [])
        elif isinstance(piece, slice):
            return slice(make_piece_scalar(piece.start), make_piece_scalar(piece.stop), make_piece_scalar(piece.step))
        else:
            return piece
    if isinstance(slice_spec, tuple):
        return tuple((make_piece_scalar(piece) for piece in slice_spec))
    else:
        return make_piece_scalar(slice_spec)

Wraps all integers in an extended slice spec w/ a tensor.

This function is used to help test slicing when the slice spec contains
tensors, rather than integers.

Args:
slice_spec: The extended slice spec.
use_constant: If true, then wrap each integer with a tf.constant.  If false,
then wrap each integer with a tf.placeholder.

Returns:
A copy of slice_spec, but with each integer i replaced with tf.constant(i).


def list_folder(cls, session, mailbox, folder):

        return cls(
            '/mailboxes/%d/folders/%s/conversations.json' % (
                mailbox.id, folder.id,
            ),
            session=session,
        )

Return conversations in a specific folder of a mailbox.

Args:
session (requests.sessions.Session): Authenticated session.
mailbox (helpscout.models.Mailbox): Mailbox that folder is in.
folder (helpscout.models.Folder): Folder to list.

Returns:
RequestPaginator(output_type=helpscout.models.Conversation):
Conversations iterator.


def leapfrog_step(leapfrog_step_state: LeapFrogStepState, step_size: FloatTensor, target_log_prob_fn: PotentialFn, kinetic_energy_fn: PotentialFn) -> Tuple[(LeapFrogStepState, LeapFrogStepExtras)]:
    state = leapfrog_step_state.state
    state_grads = leapfrog_step_state.state_grads
    momentum = leapfrog_step_state.momentum
    step_size = maybe_broadcast_structure(step_size, state)
    state = tf.nest.map_structure(tf.convert_to_tensor, state)
    momentum = tf.nest.map_structure(tf.convert_to_tensor, momentum)
    state = tf.nest.map_structure(tf.convert_to_tensor, state)
    if (state_grads is None):
        (_, _, state_grads) = call_and_grads(target_log_prob_fn, state)
    else:
        state_grads = tf.nest.map_structure(tf.convert_to_tensor, state_grads)
    momentum = tf.nest.map_structure((lambda m, sg, s: (m + ((0.5 * sg) * s))), momentum, state_grads, step_size)
    (kinetic_energy, kinetic_energy_extra, momentum_grads) = call_and_grads(kinetic_energy_fn, momentum)
    state = tf.nest.map_structure((lambda x, mg, s: (x + (mg * s))), state, momentum_grads, step_size)
    (target_log_prob, state_extra, state_grads) = call_and_grads(target_log_prob_fn, state)
    momentum = tf.nest.map_structure((lambda m, sg, s: (m + ((0.5 * sg) * s))), momentum, state_grads, step_size)
    return (LeapFrogStepState(state, state_grads, momentum), LeapFrogStepExtras(target_log_prob, state_extra, kinetic_energy, kinetic_energy_extra))

Leapfrog `TransitionOperator`.

Args:
leapfrog_step_state: LeapFrogStepState.
step_size: Step size, structure broadcastable to the `target_log_prob_fn`
state.
target_log_prob_fn: Target log prob fn.
kinetic_energy_fn: Kinetic energy fn.

Returns:
leapfrog_step_state: LeapFrogStepState.
leapfrog_step_extras: LeapFrogStepExtras.


def remove_team_member(self, account_id=None, email_address=None):
    return self._add_remove_team_member(self.TEAM_REMOVE_MEMBER_URL, email_address, account_id)

Remove a user from your Team

Args:

account_id (str):       The id of the account of the user to remove from your team.

email_address (str):    The email address of the account to remove from your team. The account id prevails if both account_id and email_address are provided.

Returns:
A Team object


def find_function(self, context, funname):

        if funname in self.builtins:
            return self.builtins[funname]

        func = None
        if isinstance(context, dict):
            if funname in context:
                func = context[funname]

                if isinstance(func, str):
                    func = self._deferred_add(func)
                    context[funname] = func
        elif hasattr(context, funname):
            func = getattr(context, funname)

        if func is None:
            raise NotFoundError("Function not found", function=funname)

        return func

Find a function in the given context by name.

This function will first search the list of builtins and if the
desired function is not a builtin, it will continue to search
the given context.

Args:
context (object): A dict or class that is a typedargs context
funname (str): The name of the function to find

Returns:
callable: The found function.


def __init__(self, source_shape, target_shape, layer_broadcasters, dtype=None):
    if not isinstance(source_shape, DynamicRaggedShape):
        raise TypeError('source_shape is not a DynamicRaggedShape')
    if not isinstance(target_shape, DynamicRaggedShape):
        raise TypeError('target_shape is not a DynamicRaggedShape')
    if not isinstance(layer_broadcasters, list):
        raise TypeError('layer_broadcasters not a list: ' + str(layer_broadcasters))
    for bc in layer_broadcasters:
        if not isinstance(bc, _LayerBroadcaster):
            raise TypeError('Not a LayerBroadcaster: ' + str(bc))
    dtype = _find_dtype(source_shape, dtype)
    dtype = _find_dtype(target_shape, dtype)
    dtype = _find_dtype_iterable(layer_broadcasters, dtype)
    dtype = _find_dtype(dtypes.int64, dtype)
    self._source_shape = source_shape.with_dtype(dtype)
    self._target_shape = target_shape.with_dtype(dtype)
    self._layer_broadcasters = [x.with_dtype(dtype) for x in layer_broadcasters]

Create a broadcaster.

Do not call directly.
The source_shape, target_shape, and layer_broadcasters are converted
to have the same dtype.

Note: source_shape.rank and target_shape.rank must be known.
Args:
source_shape: the source DynamicRaggedShape
target_shape: the target DynamicRaggedShape
layer_broadcasters: List[_LayerBroadcaster] of length source_shape.rank.
dtype: the preferred dtype of the broadcaster.

Raises:
TypeError: if the input types don't match.


def input_list_parser(infile_list):

    final_list_of_files = []

    for x in infile_list:

        if op.isdir(x):
            os.chdir(x)
            final_list_of_files.extend(glob.glob('*'))

        if op.isfile(x):
            final_list_of_files.append(x)

    return final_list_of_files

Always return a list of files with varying input.

>>> input_list_parser(['/path/to/folder/'])
['/path/to/folder/file1.txt', '/path/to/folder/file2.txt', '/path/to/folder/file3.txt']

>>> input_list_parser(['/path/to/file.txt'])
['/path/to/file.txt']

>>> input_list_parser(['file1.txt'])
['file1.txt']

Args:
infile_list: List of arguments

Returns:
list: Standardized list of files


def add_listener_policy(self, json_data):
    env = boto3.session.Session(profile_name=self.env, region_name=self.region)
    elbclient = env.client('elb')
    stickiness = {}
    elb_settings = self.properties['elb']
    if elb_settings.get('ports'):
        ports = elb_settings['ports']
        for listener in ports:
            if listener.get('stickiness'):
                stickiness = self.add_stickiness()
                LOG.info('Stickiness Found: %s', stickiness)
                break
    for job in json.loads(json_data)['job']:
        for listener in job['listeners']:
            policies = []
            ext_port = listener['externalPort']
            if listener['listenerPolicies']:
                policies.extend(listener['listenerPolicies'])
            if stickiness.get(ext_port):
                policies.append(stickiness.get(ext_port))
            if policies:
                LOG.info('Adding listener policies: %s', policies)
                elbclient.set_load_balancer_policies_of_listener(LoadBalancerName=self.app, LoadBalancerPort=ext_port, PolicyNames=policies)

Attaches listerner policies to an ELB

Args:
json_data (json): return data from ELB upsert


def make_body(self, resp, params, meta, content):
    response = {'meta': meta, 'content': content}
    resp.content_type = 'application/json'
    resp.body = json.dumps(response, indent=((params['indent'] or None) if ('indent' in params) else None))

Construct response body in ``resp`` object using JSON serialization.

Args:
resp (falcon.Response): response object where to include
serialized body
params (dict): dictionary of parsed parameters
meta (dict): dictionary of metadata to be included in 'meta'
section of response
content (dict): dictionary of response content (resource
representation) to be included in 'content' section of response

Returns:
None


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.TransactionalConnection)):
        use_memcache = False
    else:
        use_memcache = self._use_memcache(key, options)
    ns = key.namespace()
    memcache_deadline = None
    if use_memcache:
        mkey = (self._memcache_prefix + key.urlsafe())
        memcache_deadline = self._get_memcache_deadline(options)
        mvalue = (yield self.memcache_get(mkey, for_cas=use_datastore, namespace=ns, use_cache=True, deadline=memcache_deadline))
        if use_cache:
            self._load_from_cache_if_available(key)
        if (mvalue not in (_LOCKED, None)):
            cls = model.Model._lookup_model(key.kind(), self._conn.adapter.default_model)
            pb = entity_pb.EntityProto()
            try:
                pb.MergePartialFromString(mvalue)
            except ProtocolBuffer.ProtocolBufferDecodeError:
                logging.warning(('Corrupt memcache entry found with key %s and namespace %s' % (mkey, ns)))
                mvalue = None
            else:
                entity = cls._from_pb(pb)
                entity._key = key
                if use_cache:
                    self._cache[key] = entity
                raise tasklets.Return(entity)
        if ((mvalue is None) and use_datastore):
            (yield self.memcache_set(mkey, _LOCKED, time=_LOCK_TIME, namespace=ns, use_cache=True, deadline=memcache_deadline))
            (yield self.memcache_gets(mkey, namespace=ns, use_cache=True, deadline=memcache_deadline))
    if (not use_datastore):
        raise tasklets.Return(None)
    if use_cache:
        entity = (yield self._get_batcher.add_once(key, options))
    else:
        entity = (yield self._get_batcher.add(key, options))
    if (entity is not None):
        if (use_memcache and (mvalue != _LOCKED)):
            pbs = entity._to_pb(set_key=False).SerializePartialToString()
            if (len(pbs) <= memcache.MAX_VALUE_SIZE):
                timeout = self._get_memcache_timeout(key, options)
                (yield self.memcache_cas(mkey, pbs, time=timeout, namespace=ns, deadline=memcache_deadline))
    if use_cache:
        self._cache[key] = entity
    raise tasklets.Return(entity)

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.


def from_epsg_code(code):

    code = str(code)
    proj4 = utils.crscode_to_string("epsg", code, "proj4")
    crs = from_proj4(proj4)
    return crs

Load crs object from epsg code, via spatialreference.org.
Parses based on the proj4 representation.

Arguments:

- *code*: The EPSG code as an integer.

Returns:

- A CS instance of the indicated type.


def from_value(value: Any, context: trace.TracingContext=None) -> trace.TraceType:
    if context is None:
        context = InternalTracingContext()
    if context.is_legacy_signature and isinstance(value, trace.TraceType):
        return value
    elif isinstance(value, trace.SupportsTracingProtocol):
        generated_type = value.__tf_tracing_type__(context)
        if not isinstance(generated_type, trace.TraceType):
            raise TypeError('Expected an instance of TraceType for Tracing Protocol call to ' + str(value) + ' but got ' + str(generated_type))
        return generated_type
    if isinstance(value, weakref.ref):
        raise TypeError(f'weakref input {value} not supported for tf.function.')
    if hasattr(value, '__wrapped__'):
        return from_value(value.__wrapped__, context)
    if isinstance(value, list):
        return default_types.List(*(from_value(c, context) for c in value))
    if isinstance(value, tuple):
        if util.is_namedtuple(value):
            named_tuple_type = type(value)
            return default_types.NamedTuple.from_type_and_attributes(named_tuple_type, tuple((from_value(c, context) for c in value)))
        else:
            return default_types.Tuple(*(from_value(c, context) for c in value))
    if isinstance(value, collections.abc.Mapping):
        mapping_type = type(value)
        return default_types.Dict({k: from_value(value[k], context) for k in value}, mapping_type)
    if util.is_attrs(value):
        return default_types.Attrs.from_type_and_attributes(type(value), tuple((from_value(getattr(value, a.name), context) for a in value.__attrs_attrs__)))
    if util.is_np_ndarray(value):
        ndarray = value.__array__()
        return default_types.TENSOR(ndarray.shape, ndarray.dtype)
    if isinstance(value, custom_nest_protocol.CustomNestProtocol):
        metadata, components = value.__tf_flatten__()
        return custom_nest_trace_type.CustomNestTraceType(type(value), metadata, tuple((from_value(c, context) for c in components)))
    try:
        ref = weakref.ref(value)
        if ref is None:
            raise TypeError(f'Deleted objects are not valid tf.function arguments, Got {value!r}')
        else:
            return default_types.Weakref(ref)
    except TypeError:
        try:
            return default_types.Literal(value)
        except:
            raise TypeError(f'Could not generate a generic TraceType for {value!r}.Please verify that it is immutable/hashable. Otherwise, consider implementing the Tracing Protocol for it.')

Returns a TraceType corresponding to the value based on the context.

Args:
value: The value to generate a TraceType for.
context: The TracingContext to be shared during protocol calls.

Returns:
A TraceType object representing the given value.


def get_input_params(distribution_strategy, num_samples, steps, batch_size, mode=None):
    use_per_replica_batch = not dist_utils.global_batch_size_supported(distribution_strategy)
    if context.executing_eagerly():
        allow_partial_batch = mode != ModeKeys.TRAIN or not backend.is_tpu_strategy(distribution_strategy)
    else:
        allow_partial_batch = mode == ModeKeys.TRAIN or ((mode == ModeKeys.PREDICT or mode == ModeKeys.TEST) and backend.is_tpu_strategy(distribution_strategy))
    if steps is None:
        if batch_size is None:
            global_batch_size = min(num_samples, 32)
        else:
            global_batch_size = batch_size
            if use_per_replica_batch:
                global_batch_size *= distribution_strategy.num_replicas_in_sync
        if allow_partial_batch:
            steps = np.ceil(num_samples / global_batch_size).astype(int)
        else:
            if num_samples % global_batch_size:
                raise ValueError('The number of samples %s is not divisible by batch size %s.' % (num_samples, global_batch_size))
            steps = num_samples
    elif batch_size is None:
        if num_samples % steps:
            raise ValueError('The number of samples %s is not divisible by steps %s. Please change the number of steps to a value that can consume all the samples' % (num_samples, steps))
        global_batch_size = num_samples
    else:
        global_batch_size = batch_size
        if use_per_replica_batch:
            global_batch_size *= distribution_strategy.num_replicas_in_sync
        min_num_samples = global_batch_size * steps
        if allow_partial_batch:
            min_num_samples = global_batch_size * (steps - 1) + 1 if steps > 1 else 0
        if num_samples < min_num_samples:
            raise ValueError('Number of samples %s is less than samples required for specified batch_size %s and steps %s' % (num_samples, global_batch_size, steps))
    if use_per_replica_batch:
        if global_batch_size % distribution_strategy.num_replicas_in_sync:
            raise ValueError('The batch size (%s) could not be sharded evenly across the sync replicas (%s) in the distribution strategy.' % (global_batch_size, distribution_strategy.num_replicas_in_sync))
        batch_size = global_batch_size
    else:
        batch_size = global_batch_size
    return (steps, batch_size)

Calculate the number of batches and steps/steps_per_epoch.

Args:
distribution_strategy: The DistributionStrategy used to compile the model.
num_samples: The number of samples from which we determine the batch size
and steps.
steps:  The specified number of steps.
batch_size: The specified batch_size.
mode: ModeKey representing whether input will be used for training,
evaluation, or prediction. This is used to relax the constraints on
consuming all the training samples to keep compatibility till we support
partial batches. If none, then partial batches are not allowed.

Returns:
steps: The steps or steps_per_epoch argument depending on if a user is
calling `fit`, `evaluate` or `predict`. If the is_training flag is set
we don't require the number of samples to be used completely.
batch_size: The batch size to be used in model iterations.

Raises:
ValueError: If the number of batches or steps evaluates to 0.


def aliased_as(self, name):
    stream = copy.copy(self)
    stream._alias = name
    return stream

Create an alias of this stream.

Returns an alias of this stream with name `name`.
When invocation of an SPL operator requires an
:py:class:`~streamsx.spl.op.Expression` against
an input port this can be used to ensure expression
matches the input port alias regardless of the name
of the actual stream.

Example use where the filter expression for a ``Filter`` SPL operator
uses ``IN`` to access input tuple attribute ``seq``::

s = ...
s = s.aliased_as('IN')

params =  {'filter': op.Expression.expression('IN.seq % 4ul == 0ul')}
f = op.Map('spl.relational::Filter', stream, params = params)

Args:
name(str): Name for returned stream.

Returns:
Stream: Alias of this stream with ``name`` equal to `name`.

.. versionadded:: 1.9


def clip_by_value(x, min, max):
    from .function_bases import maximum2 as maximum2_base
    from .function_bases import minimum2 as minimum2_base
    return minimum2_base(maximum2_base(x, min), max)

r"""Clip inputs by values.

.. math::

y = \begin{cases}
max & (x > max) \\
x & (otherwise) \\
min & (x < min)
\end{cases}.

Args:
x (Variable): An input variable.
min (Variable): A min variable by which `x` is clipped. Note that the shape of `min` must be the same as `x`'s.
max (Variable): A max variable by which `x` is clipped. Note that the shape of `max` must be the same as `x`'s

Returns:
~nnabla.Variable: N-D array.


def read_uint32(self, little_endian=True):

        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.unpack('%sI' % endian, 4)

Read 4 bytes as an unsigned integer value from the stream.

Args:
little_endian (bool): specify the endianness. (Default) Little endian.

Returns:
int:


def StringEscape(self, string, match, **_):

    precondition.AssertType(string, Text)

    if self.current_expression.operator == "regexp":
      self.string += compatibility.UnescapeString(string)
    elif match.group(1) in "\\'\"rnbt":
      self.string += compatibility.UnescapeString(string)
    else:
      raise ParseError("Invalid escape character %s." % string)

Escape backslashes found inside a string quote.

Backslashes followed by anything other than [\'"rnbt] will raise an Error.

Args:
string: The string that matched.
match: The match object (m.group(1) is the escaped code)

Raises:
ParseError: For strings other than those used to define a regexp, raise an
error if the escaped string is not one of [\'"rnbt].


def _self_suppression(iou, _, iou_sum, iou_threshold):
    batch_size = array_ops.shape(iou)[0]
    can_suppress_others = math_ops.cast(array_ops.reshape(math_ops.reduce_max(iou, 1) < iou_threshold, [batch_size, -1, 1]), iou.dtype)
    iou_after_suppression = array_ops.reshape(math_ops.cast(math_ops.reduce_max(can_suppress_others * iou, 1) < iou_threshold, iou.dtype), [batch_size, -1, 1]) * iou
    iou_sum_new = math_ops.reduce_sum(iou_after_suppression, [1, 2])
    return [iou_after_suppression, math_ops.reduce_any(iou_sum - iou_sum_new > iou_threshold), iou_sum_new, iou_threshold]

Suppress boxes in the same tile.

Compute boxes that cannot be suppressed by others (i.e.,
can_suppress_others), and then use them to suppress boxes in the same tile.

Args:
iou: a tensor of shape [batch_size, num_boxes_with_padding] representing
intersection over union.
iou_sum: a scalar tensor.
iou_threshold: a scalar tensor.

Returns:
iou_suppressed: a tensor of shape [batch_size, num_boxes_with_padding].
iou_diff: a scalar tensor representing whether any box is supressed in
this step.
iou_sum_new: a scalar tensor of shape [batch_size] that represents
the iou sum after suppression.
iou_threshold: a scalar tensor.


def path2route(path: SchemaPath) -> SchemaRoute:

        if path == "/" or path == "":
            return []
        nlist = path.split("/")
        prevns = None
        res = []
        for n in (nlist[1:] if path[0] == "/" else nlist):
            p, s, loc = n.partition(":")
            if s:
                if p == prevns:
                    raise InvalidSchemaPath(path)
                res.append((loc, p))
                prevns = p
            elif prevns:
                res.append((p, prevns))
            else:
                raise InvalidSchemaPath(path)
        return res

Translate a schema/data path to a schema/data route.

Args:
path: Schema path.

Raises:
InvalidSchemaPath: Invalid path.


def __init__(self, description=None, default=None, required=False):

        self.__doc__ = description
        self._default = default
        self._value = default
        self._required = bool(required)

Initialize the option with some basic metadata.

Args:
description (str, optional): A human readable description of what
the option represents.
default (optional): The default value to use if unset.
required (bool, optional): Whether or not the value must be set.


def raiseError(cls, message):

        error_message = "[error] %s" % message
        if cls.__raise_exception__:
            raise Exception(error_message)

        cls.colorprint(error_message, Fore.RED)
        sys.exit(1)

Print an error message

Args:
message: the message to print


def setup_remoteckan(self, remoteckan=None, **kwargs):
    if (remoteckan is None):
        self._remoteckan = self.create_remoteckan(self.get_hdx_site_url(), full_agent=self.get_user_agent(), **kwargs)
    else:
        self._remoteckan = remoteckan

Set up remote CKAN from provided CKAN or by creating from configuration

Args:
remoteckan (Optional[ckanapi.RemoteCKAN]): CKAN instance. Defaults to setting one up from configuration.

Returns:
None


def get_create_batch_env_fun(batch_env_fn, time_limit):

  def create_env_fun(game_name=None, sticky_actions=None):
    del game_name, sticky_actions
    batch_env = batch_env_fn(in_graph=False)
    batch_env = ResizeBatchObservation(batch_env)
    batch_env = DopamineBatchEnv(batch_env, max_episode_steps=time_limit)
    return batch_env

  return create_env_fun

Factory for dopamine environment initialization function.

Args:
batch_env_fn: function(in_graph: bool) -> batch environment.
time_limit: time steps limit for environment.

Returns:
function (with optional, unused parameters) initializing environment.


async def send(self, metric):

        message = json.dumps(metric).encode('utf-8')
        await self.loop.create_datagram_endpoint(
            lambda: UDPClientProtocol(message),
            remote_addr=(self.ip, self.port))

Transform metric to JSON bytestring and send to server.

Args:
metric (dict): Complete metric to send as JSON.


def ExpandUsersVariablePath(cls, path, path_separator, user_accounts):

    path_segments = path.split(path_separator)
    return cls._ExpandUsersVariablePathSegments(
        path_segments, path_separator, user_accounts)

Expands a path with a users variable, e.g. %%users.homedir%%.

Args:
path (str): path with users variable.
path_separator (str): path segment separator.
user_accounts (list[UserAccountArtifact]): user accounts.

Returns:
list[str]: paths for which the users variables have been expanded.


def decompose_space(H, A):

    return OperatorTrace.create(
        OperatorTrace.create(A, over_space=H.operands[-1]),
        over_space=ProductSpace.create(*H.operands[:-1]))

Simplifies OperatorTrace expressions over tensor-product spaces by
turning it into iterated partial traces.

Args:
H (ProductSpace): The full space.
A (Operator):

Returns:
Operator: Iterative partial trace expression


def selection_error_control(self, form_info):
    (keys, names) = self.return_selected_form_items(form_info['ChannelList'])
    chosen_channels_number = len(keys)
    if (form_info['new_channel'] and (chosen_channels_number < 2)):
        return (False, _(u'You should choose at least two channel to merge operation at a new channel.'))
    elif (form_info['existing_channel'] and (chosen_channels_number == 0)):
        return (False, _(u'You should choose at least one channel to merge operation with existing channel.'))
    elif (form_info['find_chosen_channel'] and (chosen_channels_number != 1)):
        return (False, _(u'You should choose one channel for split operation.'))
    return (True, None)

It controls the selection from the form according
to the operations, and returns an error message
if it does not comply with the rules.

Args:
form_info: Channel or subscriber form from the user

Returns: True or False
error message


def require(self, entity_type, attribute_name=None):
    if (not attribute_name):
        attribute_name = entity_type
    self.requires += [(entity_type, attribute_name)]
    return self

The intent parser should require an entity of the provided type.

Args:
entity_type(str): an entity type
attribute_name(str): the name of the attribute on the parsed intent. Defaults to match entity_type.

Returns:
self: to continue modifications.


def get_ilo_sso_url(self, ip=None):

        uri = "{}/iloSsoUrl".format(self.data["uri"])

        if ip:
            uri = "{}?ip={}".format(uri, ip)

        return self._helper.do_get(uri)

Retrieves the URL to launch a Single Sign-On (SSO) session for the iLO web interface. If the server hardware is
unsupported, the resulting URL will not use SSO and the iLO web interface will prompt for credentials.
This is not supported on G7/iLO3 or earlier servers.

Args:
ip: IP address or host name of the server's iLO management processor

Returns:
URL


def get_members(cls, session, team_or_id):

        if isinstance(team_or_id, Person):
            team_or_id = team_or_id.id
        return cls(
            '/teams/%d/members.json' % team_or_id,
            session=session,
            out_type=User,
        )

List the members for the team.

Args:
team_or_id (helpscout.models.Person or int): Team or the ID of
the team to get the folders for.

Returns:
RequestPaginator(output_type=helpscout.models.Users): Users
iterator.


def from_prev_calc(cls, prev_calc_dir, mode='gap', reciprocal_density=50, copy_chgcar=True, **kwargs):
    (vasprun, outcar) = get_vasprun_outcar(prev_calc_dir)
    prev_structure = get_structure_from_prev_run(vasprun, outcar, sym_prec=0)
    added_kpoints = []
    if (mode.lower() == 'gap'):
        bs = vasprun.get_band_structure()
        (vbm, cbm) = (bs.get_vbm()['kpoint'], bs.get_cbm()['kpoint'])
        if vbm:
            added_kpoints.append(vbm.frac_coords)
        if cbm:
            added_kpoints.append(cbm.frac_coords)
    files_to_transfer = {}
    if copy_chgcar:
        chgcars = sorted(glob.glob(str((Path(prev_calc_dir) / 'CHGCAR*'))))
        if chgcars:
            files_to_transfer['CHGCAR'] = str(chgcars[(- 1)])
    return cls(structure=prev_structure, added_kpoints=added_kpoints, reciprocal_density=reciprocal_density, mode=mode, files_to_transfer=files_to_transfer, **kwargs)

Generate a set of Vasp input files for HSE calculations from a
directory of previous Vasp run. if mode=="gap", it explicitly adds VBM
and CBM of the prev run to the k-point list of this run.

Args:
prev_calc_dir (str): Directory containing the outputs
(vasprun.xml and OUTCAR) of previous vasp run.
mode (str): Either "uniform", "gap" or "line"
reciprocal_density (int): density of k-mesh
copy_chgcar (bool): whether to copy CHGCAR of previous run
\\*\\*kwargs: All kwargs supported by MPHSEBSStaticSet,
other than prev_structure which is determined from the previous
calc dir.


def _HashBlock(self, block, start, end):
    for finger in self.fingers:
        expected_range = finger.CurrentRange()
        if (expected_range is None):
            continue
        if ((start > expected_range.start) or ((start == expected_range.start) and (end > expected_range.end)) or ((start < expected_range.start) and (end > expected_range.start))):
            raise RuntimeError('Cutting across fingers.')
        if (start == expected_range.start):
            finger.HashBlock(block)

_HashBlock feeds data blocks into the hashers of fingers.

This function must be called before adjusting fingers for next
interval, otherwise the lack of remaining ranges will cause the
block not to be hashed for a specific finger.

Start and end are used to validate the expected ranges, to catch
unexpected use of that logic.

Args:
block: The data block.
start: Beginning offset of this block.
end: Offset of the next byte after the block.

Raises:
RuntimeError: If the provided and expected ranges don't match.


def testConcreteFunctionFlatSignatureError(self, conc_args=(), conc_kwargs=None, call_args=(), call_kwargs=None, error='.*', exception=TypeError):
    conc_args = conc_args() if callable(conc_args) else conc_args
    conc_kwargs = conc_kwargs() if callable(conc_kwargs) else conc_kwargs or {}
    call_args = call_args() if callable(call_args) else call_args
    call_kwargs = call_kwargs() if callable(call_kwargs) else call_kwargs or {}
    self.assertIsInstance(conc_args, tuple)
    self.assertIsInstance(call_args, tuple)
    self.assertIsInstance(conc_kwargs, dict)
    self.assertIsInstance(call_kwargs, dict)

    @polymorphic_function.function
    def func(x, y=5, *varargs, **kwargs):
        del y, varargs, kwargs
        return x
    conc = func.get_concrete_function(*conc_args, **conc_kwargs)
    with self.assertRaisesRegex(exception, error):
        self.evaluate(conc._call_with_flat_signature(call_args, call_kwargs))

Tests for errors in the flat signature.

Args:
conc_args: Positional arguments used for get_concrete_function.
conc_kwargs: Keyword arguments used for get_concrete_function.
call_args: Positional arguments used to call the function.
call_kwargs: Keyword arguments used to call the function.
error: Expected exception message.
exception: Expected exception type.