def __init__(self, address="0.0.0.0/32", netmask=None):

        if '/' in address:
            address, netmask = address.split('/')
        else:
            netmask = 32 if netmask is None else netmask

        super().__init__(address)
        self.netmask = int(netmask)

Create an IPAddress with the parameters below.

Args:
address (str): IP Address using ipv4. Defaults to '0.0.0.0/32'


def replace_urls(status):
    text = status.text
    if (not has_url(status)):
        return text
    urls = [(e['indices'], e['expanded_url']) for e in status.entities['urls']]
    urls.sort(key=(lambda x: x[0][0]), reverse=True)
    for ((start, end), url) in urls:
        text = ((text[:start] + url) + text[end:])
    return text

Replace shorturls in a status with expanded urls.

Args:
status (tweepy.status): A tweepy status object

Returns:
str


def absolute_hinge_difference(arr1, arr2, min_diff=10, dtype=np.uint8):

  diff = np.abs(arr1.astype(np.int) - arr2, dtype=np.int)
  return np.maximum(diff - min_diff, 0).astype(dtype)

Point-wise, hinge loss-like, difference between arrays.

Args:
arr1: integer array to compare.
arr2: integer array to compare.
min_diff: minimal difference taken into consideration.
dtype: dtype of returned array.

Returns:
array


def mask_to_rgb(self, image: np.ndarray, palette: Optional[List[Tuple[int, int]]]=None, data_format: Optional[Union[str, ChannelDimension]]=None) -> np.ndarray:
    return mask_to_rgb(image, palette=palette, data_format=data_format)

Converts a segmentation map to RGB format.

Args:
image (`np.ndarray`):
Segmentation map with dimensions (height, width) where pixel values represent the class index.
palette (`List[Tuple[int, int]]`, *optional*, defaults to `None`):
Palette to use to convert the mask to RGB format. If unset, the mask is duplicated across the channel
dimension.
data_format (`ChannelDimension` or `str`, *optional*):
The channel dimension format for the output image. If unset, the channel dimension format of the input
image is used. Can be one of:
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.

Returns:
`np.ndarray`: The mask in RGB format.


def has_sample(self, md5):
    sample = self.get_sample(md5)
    return (True if sample else False)

Checks if data store has this sample.

Args:
md5: The md5 digest of the required sample.

Returns:
True if sample with this md5 is present, else False.


def number(digit):
    spoken = str(digit)
    if (spoken.startswith('8') or (spoken[:(len(spoken) % 3)] == '11')):
        article = 'an '
    else:
        article = 'a '
    if (spoken.endswith('1') and (spoken != '11')):
        suffix = 'st'
    elif (spoken.endswith('2') and (spoken != '12')):
        suffix = 'nd'
    elif (spoken.endswith('3') and (spoken != '13')):
        suffix = 'rd'
    else:
        suffix = 'th'
    if (digit > 999):
        prefix = (len(spoken) % 3)
        separated = spoken[:prefix]
        for n in range(prefix, len(spoken), 3):
            separated += (',' + spoken[n:(n + 3)])
        spoken = separated
    return ((article + spoken) + suffix)

Gets a spoken-word representation for a number.

Arguments:
digit (int): An integer to convert into spoken-word.

Returns:
A spoken-word representation for a digit,
including an article ('a' or 'an') and a suffix,
e.g. 1 -> 'a 1st', 11 -> "an 11th". Adittionally
delimits characters in pairs of three for values > 999.


def validate_definition(self, definition_name, dict_to_test, definition=None):
    if ((definition_name not in self.specification['definitions'].keys()) and (definition is None)):
        return False
    spec_def = (definition or self.specification['definitions'][definition_name])
    all_required_keys_present = all(((req in dict_to_test.keys()) for req in spec_def.get('required', {})))
    if (('required' in spec_def) and (not all_required_keys_present)):
        return False
    properties_dict = spec_def.get('properties', {})
    for (key, value) in dict_to_test.items():
        if (value is not None):
            if (key not in properties_dict):
                return False
            elif (not self._validate_type(properties_dict[key], value)):
                return False
    return True

Validate the given dict according to the given definition.

Args:
definition_name: name of the the definition.
dict_to_test: dict to test.

Returns:
True if the given dict match the definition, False otherwise.


def int64_user_distribution(namespace, name, metric, ptransform=None) -> metrics_pb2.MonitoringInfo:
    labels = create_labels(ptransform=ptransform, namespace=namespace, name=name)
    payload = _encode_distribution(coders.VarIntCoder(), metric.count, metric.sum, metric.min, metric.max)
    return create_monitoring_info(USER_DISTRIBUTION_URN, DISTRIBUTION_INT64_TYPE, payload, labels)

Return the distribution monitoring info for the URN, metric and labels.

Args:
urn: The URN of the monitoring info/metric.
metric: The DistributionData for the metric.
ptransform: The ptransform id used as a label.


def get_relative_import_files(module_file: Union[str, os.PathLike]) -> list[str]:
    no_change = False
    files_to_check = [module_file]
    all_relative_imports = []
    while not no_change:
        new_imports = []
        for f in files_to_check:
            new_imports.extend(get_relative_imports(f))
        module_path = Path(module_file).parent
        new_import_files = [str(module_path / m) for m in new_imports]
        new_import_files = [f for f in new_import_files if f not in all_relative_imports]
        files_to_check = [f'{f}.py' for f in new_import_files]
        no_change = len(new_import_files) == 0
        all_relative_imports.extend(files_to_check)
    return all_relative_imports

Get the list of all files that are needed for a given module. Note that this function recurses through the relative
imports (if a imports b and b imports c, it will return module files for b and c).

Args:
module_file (`str` or `os.PathLike`): The module file to inspect.

Returns:
`list[str]`: The list of all relative imports a given module needs (recursively), which will give us the list
of module files a given module needs.


def to_tensor_7(self) -> torch.Tensor:
    tensor = self._trans.new_zeros((*self.shape, 7))
    tensor[..., :4] = self._rots.get_quats()
    tensor[..., 4:] = self._trans
    return tensor

Converts a transformation to a tensor with 7 final columns, four for the quaternion followed by three for the
translation.

Returns:
A [*, 7] tensor representation of the transformation


def loads(self, config_str, as_defaults=False):

        self._rw.load_config_from_string(self._config, config_str, as_defaults=as_defaults)

Load configuration values from the specified source string.

Args:
config_str:
as_defaults (bool): if ``True``, contents of ``source`` will be treated as schema of configuration items.


class RunAggregationStrategy(beam.PTransform[beam.PCollection[NestedKeyedOutputT], beam.PCollection[NestedKeyedOutputT]]):

    def __init__(self, aggregation_strategy: Optional[AggregationFn], agg_model_id: str):
        self._aggregation_fn = aggregation_strategy
        self._agg_model_id = agg_model_id

    def expand(self, input: beam.PCollection[NestedKeyedOutputT]) -> beam.PCollection[NestedKeyedOutputT]:
        post_gbk = input | beam.MapTuple(lambda k, v: ((k, v[0]), v[1])) | beam.GroupByKey()
        if self._aggregation_fn is None:
            ret = post_gbk | beam.MapTuple(lambda k, v: (k[0], (k[1], AnomalyResult(example=v[0].example, predictions=[prediction for result in v for prediction in result.predictions]))))
            return ret
        aggregation_fn_spec = self._aggregation_fn.to_spec()
        aggregation_fn_spec.config['_run_init'] = True
        aggregation_fn = Specifiable.from_spec(aggregation_fn_spec)
        if isinstance(aggregation_fn, aggregations._AggModelIdMixin):
            aggregation_fn._set_agg_model_id_if_unset(self._agg_model_id)
        ret = post_gbk | beam.MapTuple(lambda k, v, agg=aggregation_fn: (k[0], (k[1], AnomalyResult(example=v[0].example, predictions=[agg.apply([prediction for result in v for prediction in result.predictions])]))))
        return ret

Applies an aggregation strategy to grouped anomaly detection results.

This PTransform aggregates anomaly predictions from multiple models or
data points using an `AggregationFn`. It handles both custom and simple
aggregation strategies.

Args:
aggregation_strategy: The `AggregationFn` to use.
agg_model_id: The model ID for aggregation.


def _update_size(self, size, future):
    with self._size_lock:
        if ((size > self._size) and future.done):
            self._size = size

Keep track of the file size during writing.

If specified size value is greater than the current size, update the
current size using specified value.

Used as callback in default "_flush" implementation for files supporting
random write access.

Args:
size (int): Size value.
future (concurrent.futures._base.Future): future.


async def on_message(message):

    server = message.server
    author = message.author
    channel = message.channel
    content = message.content

    data = datatools.get_data()

    if server is not None and author != channel.server.me:
        prefix = data["discord"]["servers"][server.id]["prefix"]

        if channel.server.me in message.mentions:
            await client.send_typing(channel)
            response = "The current server prefix is `{0}`. Type `{0}help` for help.".format(prefix)
            await client.send_message(channel, response)

        if content.startswith(prefix):

            package = content.split(" ")
            command = package[0][len(prefix):]
            args = package[1:]
            arg = ' '.join(args)

            if command not in ["prefix", "activate", "deactivate", "warnmax", "warn", "ban"]:
                return

            is_admin = author == server.owner
            for role in message.author.roles:
                if role.permissions.administrator:
                    is_admin = True

            if not is_admin:
                await client.send_typing(channel)
                reason = "You must have a role that has the permission 'Administrator'"
                embed = ui_embed.error(channel, "Insufficient Permissions", reason)
                await embed.send()
                return

            if command == "prefix" and args:
                new_prefix = arg.replace(" ", "").strip()
                data["discord"]["servers"][server.id]["prefix"] = new_prefix

                datatools.write_data(data)

                await client.send_typing(channel)
                embed = ui_embed.modify_prefix(channel, new_prefix)
                await embed.send()

            if command == "warnmax" and args:
                try:
                    warn_max = int(arg)
                    if warn_max > 0:
                        data["discord"]["servers"][server.id][_data.modulename]["warnings_max"] = warn_max
                        datatools.write_data(data)
                        await client.send_typing(channel)
                        embed = ui_embed.warning_max_changed(channel, warn_max)
                        await embed.send()
                    else:
                        reason = "Maximum warnings must be greater than 0"
                        embed = ui_embed.error(channel, "Error", reason)
                        await embed.send()
                except (ValueError, TypeError):
                    reason = "Warning maximum must be a number"
                    embed = ui_embed.error(channel, "Error", reason)
                    await embed.send()
                except Exception as e:
                    logger.exception(e)

            if command == "warn" and args:
                for user in message.mentions:
                    await api_manager.warn_user(channel, user)

            if command == "ban" and args:
                for user in message.mentions:
                    await api_manager.ban_user(channel, user)

            if command == "activate" and args:
                await api_manager.activate_module(channel, arg, True)
            elif command == "deactivate" and args:
                await api_manager.activate_module(channel, arg, False)

The on_message event handler for this module

Args:
message (discord.Message): Input message


def __init__(self, key, iv):

    self.key = key.RawBytes()
    self.iv = iv.RawBytes()

Init.

Args:
key: The key, a rdf_crypto.EncryptionKey instance.
iv: The iv, a rdf_crypto.EncryptionKey instance.


def list_datasets(self, get_global_public):
    appending = ''
    if get_global_public:
        appending = 'public'
    url = (self.url() + '/resource/{}dataset/'.format(appending))
    req = self.remote_utils.get_url(url)
    if (req.status_code is not 200):
        raise RemoteDataNotFoundError('Could not find {}'.format(req.text))
    else:
        return req.json()

Lists datasets in resources. Setting 'get_global_public' to 'True'
will retrieve all public datasets in cloud. 'False' will get user's
public datasets.

Arguments:
get_global_public (bool): True if user wants all public datasets in
cloud. False if user wants only their
public datasets.

Returns:
dict: Returns datasets in JSON format


def create_chebyshev_samples(order, dim=1):

    x_data = .5*numpy.cos(numpy.arange(order, 0, -1)*numpy.pi/(order+1)) + .5
    x_data = chaospy.quad.combine([x_data]*dim)
    return x_data.T

Chebyshev sampling function.

Args:
order (int):
The number of samples to create along each axis.
dim (int):
The number of dimensions to create samples for.

Returns:
samples following Chebyshev sampling scheme mapped to the
``[0, 1]^dim`` hyper-cube and ``shape == (dim, order)``.


def get_key_by_job_id(cls, mapreduce_id):
    return db.Key.from_path(cls.kind(), ('%s:%s' % (mapreduce_id, cls._KEY_NAME)))

Retrieves the Key for a mapreduce ID.

Args:
mapreduce_id: The job to fetch.

Returns:
Datastore Key for the command for the given job ID.


def verify_signature(public_key, signature, hash, hash_algo):
    hash_algo = _hash_algorithms[hash_algo]
    try:
        return (get_publickey(public_key).verify(signature, hash, padding.PKCS1v15(), utils.Prehashed(hash_algo)) is None)
    except InvalidSignature:
        return False

Verify the given signature is correct for the given hash and public key.

Args:
public_key (str): PEM encoded public key
signature (bytes): signature to verify
hash (bytes): hash of data
hash_algo (str): hash algorithm used

Returns:
True if the signature is valid, False otherwise


def csv_to_numpy(string_like, dtype=None):
    stream = StringIO(string_like)
    return np.genfromtxt(stream, dtype=dtype, delimiter=',')

Convert a CSV object to a numpy array.

Args:
string_like (str): CSV string.
dtype (dtype, optional):  Data type of the resulting array. If None, the dtypes will be determined by the
contents of each column, individually. This argument can only be used to
'upcast' the array.  For downcasting, use the .astype(t) method.
Returns:
(np.array): numpy array


def get_converter(in_type, out_type, *args, **kwargs):
    convs = pliers.converters.__all__
    out_type = listify(out_type)[::(- 1)]
    default_convs = config.get_option('default_converters')
    for ot in out_type:
        conv_str = ('%s->%s' % (in_type.__name__, ot.__name__))
        if (conv_str in default_convs):
            convs = (list(default_convs[conv_str]) + convs)
    for name in convs:
        cls = getattr(pliers.converters, name)
        if (not issubclass(cls, Converter)):
            continue
        available = (cls.available if issubclass(cls, EnvironmentKeyMixin) else True)
        if ((cls._input_type == in_type) and (cls._output_type in out_type) and available):
            conv = cls(*args, **kwargs)
            return conv
    return None

Scans the list of available Converters and returns an instantiation
of the first one whose input and output types match those passed in.

Args:
in_type (type): The type of input the converter must have.
out_type (type): The type of output the converter must have.
args, kwargs: Optional positional and keyword arguments to pass onto
matching Converter's initializer.


def convert_to_row_table(self, add_units=True):
    rtable = []
    if add_units:
        relavent_units = self.get_relavent_units()
    for row_index in range(self.start[0], self.end[0]):
        for column_index in range(self.start[1], self.end[1]):
            cell = self.table[row_index][column_index]
            if ((cell != None) and isinstance(cell, (int, float, long))):
                titles = self._find_titles(row_index, column_index)
                titles.append(cell)
                if add_units:
                    titles.append(relavent_units.get((row_index, column_index)))
                rtable.append(titles)
    if (not rtable):
        for row_index in range(self.start[0], self.end[0]):
            row = []
            rtable.append(row)
            for column_index in range(self.start[1], self.end[1]):
                row.append(self.table[row_index][column_index])
            if add_units:
                row.append(relavent_units.get((row_index, column_index)))
    return rtable

Converts the block into row titled elements. These elements are copied into the return
table, which can be much longer than the  original block.

Args:
add_units: Indicates if units should be appened to each row item.

Returns:
A row-titled table representing the data in the block.


def lowres_tensor(shape, underlying_shape, offset=None, sd=None):
    sd = (sd or 0.01)
    init_val = (sd * np.random.randn(*underlying_shape).astype('float32'))
    underlying_t = tf.Variable(init_val)
    t = resize_bilinear_nd(underlying_t, shape)
    if (offset is not None):
        if (not isinstance(offset, list)):
            offset = (len(shape) * [offset])
        for n in range(len(offset)):
            if (offset[n] is True):
                offset[n] = ((shape[n] / underlying_shape[n]) / 2)
            if (offset[n] is False):
                offset[n] = 0
            offset[n] = int(offset[n])
        padding = [(pad, 0) for pad in offset]
        t = tf.pad(t, padding, 'SYMMETRIC')
        begin = (len(shape) * [0])
        t = tf.slice(t, begin, shape)
    return t

Produces a tensor paramaterized by a interpolated lower resolution tensor.

This is like what is done in a laplacian pyramid, but a bit more general. It
can be a powerful way to describe images.

Args:
shape: desired shape of resulting tensor
underlying_shape: shape of the tensor being resized into final tensor
offset: Describes how to offset the interpolated vector (like phase in a
Fourier transform). If None, apply no offset. If a scalar, apply the same
offset to each dimension; if a list use each entry for each dimension.
If a int, offset by that much. If False, do not offset. If True, offset by
half the ratio between shape and underlying shape (analagous to 90
degrees).
sd: Standard deviation of initial tensor variable.

Returns:
A tensor paramaterized by a lower resolution tensorflow variable.


def _parse_control_fields(self, fields, tag_id='tag'):
    for field in fields:
        params = field.params
        if (tag_id not in params):
            continue
        self.controlfields[params[tag_id]] = field.getContent().strip()

Parse control fields.

Args:
fields (list): list of HTMLElements
tag_id (str):  parameter name, which holds the information, about
field name this is normally "tag", but in case of
oai_marc "id".


def get_public_api(api_mapping_files: Sequence[str], file_prefixes_to_strip: Sequence[str], packages_to_ignore: Sequence[str], output_package: str, module_prefix: str) -> PublicAPI:
    ea = exported_api.ExportedApi()
    for f in api_mapping_files:
        ea.read(f)
    v1_entrypoints_by_module = collections.defaultdict(set)
    v2_entrypoints_by_module = collections.defaultdict(set)

    def add_exported_symbols(api_names: list[str], s: exported_api.ExportedSymbol, entrypoints_by_module: Mapping[str, set[_Entrypoint]]):
        for api_name in api_names:
            index_of_last_dot = api_name.rfind('.')
            index_of_first_dot = api_name.find('.')
            module = output_package
            if index_of_first_dot + 1 < index_of_last_dot:
                module += f'.{api_name[index_of_first_dot + 1:index_of_last_dot]}'
            name = api_name[index_of_last_dot + 1:]
            entrypoints_by_module[module].add(_Entrypoint(module, name, s))
    for s in ea.symbols:
        if _should_skip_file(s.file_name, file_prefixes_to_strip, packages_to_ignore, module_prefix):
            continue
        add_exported_symbols(s.v1_apis, s, v1_entrypoints_by_module)
        add_exported_symbols(s.v2_apis, s, v2_entrypoints_by_module)
    v1_generated_imports_by_module = collections.defaultdict(set)
    v2_generated_imports_by_module = collections.defaultdict(set)

    def add_generated_imports(entrypoints_by_module: Mapping[str, set[_Entrypoint]], generated_imports_by_module: Mapping[str, set[str]]):
        for module in entrypoints_by_module:
            i = module.rfind('.')
            if i == -1:
                continue
            while i != -1:
                parent = module[:i]
                generated_imports_by_module[parent].add(module)
                module = parent
                i = module.rfind('.')
    add_generated_imports(v1_entrypoints_by_module, v1_generated_imports_by_module)
    add_generated_imports(v2_entrypoints_by_module, v2_generated_imports_by_module)
    docs_by_module = {}
    for d in ea.docs:
        for m in d.modules:
            if m in docs_by_module:
                raise DocExportedTwiceError(f'Docstring at {d.file_name}:{d.line_no} is registered for {m}, which already has a registered docstring.')
            docs_by_module[m] = d.docstring
    return PublicAPI(v1_entrypoints_by_module=v1_entrypoints_by_module, v2_entrypoints_by_module=v2_entrypoints_by_module, v1_generated_imports_by_module=v1_generated_imports_by_module, v2_generated_imports_by_module=v2_generated_imports_by_module, docs_by_module=docs_by_module)

Generates the structure of the public API from the given files.

Args:
api_mapping_files: List of files containing the exported API mappings and
docstrings.
file_prefixes_to_strip: A list of prefixes to strip from files when
determining the packages to ignore.
packages_to_ignore: A list of python packages that should be ignored when
searching for tf_exports.
output_package: The package to use for the imports.
module_prefix: A prefix to add to the non-generated imports.

Raises:
DocExportedTwiceError: Two docstrings are registered for the same module.

Returns:
The public API structure.


def valid_config_exists(config_path=CONFIG_PATH):

    if os.path.isfile(config_path):
        try:
            config = read_config(config_path)
            check_config(config)
        except (ConfigurationError, IOError):
            return False
    else:
        return False
    return True

Verify that a valid config file exists.

Args:
config_path (str): Path to the config file.

Returns:
boolean: True if there is a valid config file, false if not.


def default_pass_manager_simulator(basis_gates):
    pass_manager = PassManager()
    pass_manager.append(Unroller(basis_gates))
    pass_manager.append([RemoveResetInZeroState(), Depth(), FixedPoint('depth')], do_while=(lambda property_set: (not property_set['depth_fixed_point'])))
    return pass_manager

The default pass manager without a coupling map.

Args:
basis_gates (list[str]): list of basis gate names to unroll to.

Returns:
PassManager: A passmanager that just unrolls, without any optimization.


def decode(self, tx):
    if (not isinstance(self._service, BitcoinBlockrService)):
        raise NotImplementedError('Currently only supported for "blockr.io"')
    return self._service.decode(tx)

Decodes the given transaction.

Args:
tx: hex of transaction
Returns:
decoded transaction

.. note:: Only supported for blockr.io at the moment.


def are_same(self, path_1, path_2):
    if (path_1 == path_2):
        return True
    repo_1 = self.get_repository(path_1)
    repo_2 = self.get_repository(path_2)
    return (repo_1.uid == repo_2.uid)

Test that `path_1` and `path_2` refer to the same repository.

This is more reliable than testing that the strings match, since slightly
different strings might refer to the same repository (consider small
differences in a filesystem path for example, eg '//svr/foo', '/svr/foo').

Returns:
True if the paths refer to the same repository, False otherwise.


def potential_purviews(self, direction, mechanism):
    all_purviews = utils.powerset(self._node_indices)
    return irreducible_purviews(self.cm, direction, mechanism, all_purviews)

All purviews which are not clearly reducible for mechanism.

Args:
direction (Direction): |CAUSE| or |EFFECT|.
mechanism (tuple[int]): The mechanism which all purviews are
checked for reducibility over.

Returns:
list[tuple[int]]: All purviews which are irreducible over
``mechanism``.


def _create_per_worker_resources(self, fn, args=None, kwargs=None):
    results = []
    for w in self._cluster.workers:
        results.append(w.create_resource(fn, args=args, kwargs=kwargs))
    return PerWorkerValues(tuple(results))

Synchronously create resources on the workers.

The resources are represented by
`tf.distribute.experimental.coordinator.RemoteValue`s.

Args:
fn: The function to be dispatched to all workers for execution
asynchronously.
args: Positional arguments for `fn`.
kwargs: Keyword arguments for `fn`.

Returns:
A `tf.distribute.experimental.coordinator.PerWorkerValues` object, which
wraps a tuple of `tf.distribute.experimental.coordinator.RemoteValue`
objects.


def repository_compare(self, from_, to, **kwargs):

        path = '/projects/%s/repository/compare' % self.get_id()
        query_data = {'from': from_, 'to': to}
        return self.manager.gitlab.http_get(path, query_data=query_data,
                                            **kwargs)

Return a diff between two branches/commits.

Args:
from_(str): Source branch/SHA
to(str): Destination branch/SHA
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server failed to perform the request

Returns:
str: The diff


def create_column_token_type_ids_from_sequences(self, query_ids: List[int], table_values: List[TableValue]) -> List[int]:
    table_column_ids = list(zip(*table_values))[1] if table_values else []
    return [0] * (1 + len(query_ids) + 1) + list(table_column_ids)

Creates the column token type IDs according to the query token IDs and a list of table values.

Args:
query_ids (`List[int]`): list of token IDs corresponding to the ID.
table_values (`List[TableValue]`): lift of table values, which are named tuples containing the
token value, the column ID and the row ID of said token.

Returns:
`List[int]`: List of ints containing the column token type IDs values.


def log_deprecated(name="", text="", eos=""):

    assert name or text
    if eos:
        eos = "after " + datetime(*map(int, eos.split("-"))).strftime("%d %b")
    if name:
        if eos:
            warn_msg = "%s will be deprecated %s. %s" % (name, eos, text)
        else:
            warn_msg = "%s was deprecated. %s" % (name, text)
    else:
        warn_msg = text
        if eos:
            warn_msg += " Legacy period ends %s" % eos
    logger.warn("[Deprecated] " + warn_msg)

Log deprecation warning.

Args:
name (str): name of the deprecated item.
text (str, optional): information about the deprecation.
eos (str, optional): end of service date such as "YYYY-MM-DD".


def compile_sgf(in_path, optimize=True, model=None):

    if model is None:
        model = DeviceModel()

    parser = SensorGraphFileParser()
    parser.parse_file(in_path)
    parser.compile(model)

    if optimize:
        opt = SensorGraphOptimizer()
        opt.optimize(parser.sensor_graph, model=model)

    return parser.sensor_graph

Compile and optionally optimize an SGF file.

Args:
in_path (str): The input path to the sgf file to compile.
optimize (bool): Whether to optimize the compiled result,
defaults to True if not passed.
model (DeviceModel): Optional device model if we are
compiling for a nonstandard device.  Normally you should
leave this blank.

Returns:
SensorGraph: The compiled sensorgraph object


def cast_naive_datetime_to_tz(dt, tz=UTC()):
    if has_tz(dt):
        return dt
    return dt.replace(tzinfo=tz)

If datetime is tz-naive, set it to ``tz``. If datetime is tz-aware, return it
unmodified.

Args:
dt : datetime
tz-naive or tz-aware datetime.

tz : datetime.tzinfo
The timezone to which to adjust tz-naive datetime.

Returns:
datetime
tz-aware datetime.

Warning:
This will change the actual moment in time that is represented if the datetime is
naive and represents a date and time not in ``tz``.

See Also:
``normalize_datetime_to_utc()``


def __init__(self, test=None, t_node=None, f_node=None):

        self.test = test
        self.t_node = t_node
        self.f_node = f_node

Construct a BoolTree object

Args:
test (bool): test for whether to traverse the true-node or the
false-node (`BoolTree.t_node` or `BoolTree.f_node`)
t_node (BoolTree/Int): node to follow if test is `True`
f_node (BoolTree/Int): node to follow if test is `False`


def _make_lcdproc(lcd_host, lcd_port, retry_config, charset=DEFAULT_LCDPROC_CHARSET, lcdd_debug=False):

    class ServerSpawner(utils.AutoRetryCandidate):
        'Spawn the server, using auto-retry.'

        @utils.auto_retry
        def connect(self):
            return lcdrunner.LcdProcServer(lcd_host, lcd_port, charset=charset, debug=lcdd_debug)
    spawner = ServerSpawner(retry_config=retry_config, logger=logger)
    try:
        return spawner.connect()
    except socket.error as e:
        logger.error('Unable to connect to lcdproc %s:%s : %r', lcd_host, lcd_port, e)
        raise SystemExit(1)

Create and connect to the LCDd server.

Args:
lcd_host (str): the hostname to connect to
lcd_prot (int): the port to connect to
charset (str): the charset to use when sending messages to lcdproc
lcdd_debug (bool): whether to enable full LCDd debug
retry_attempts (int): the number of connection attempts
retry_wait (int): the time to wait between connection attempts
retry_backoff (int): the backoff for increasing inter-attempt delay

Returns:
lcdproc.server.Server


def get_group(self, name, user_name=None):

        self.project_service.set_auth(self._token_project)
        return self.project_service.get_group(name, user_name)

Get information on the given group or whether or not a user is a member
of the group.

Args:
name (string): Name of group to query.
user_name (optional[string]): Supply None if not interested in
determining if user is a member of the given group.

Returns:
(mixed): Dictionary if getting group information or bool if a user
name is supplied.

Raises:
requests.HTTPError on failure.


def deregister(cls, name: str) -> None:
    if (name not in cls.available):
        raise ConnectionPluginNotRegistered(f'Connection {name!r} is not registered')
    cls.available.pop(name)

Deregisters a registered connection plugin by its name

Args:
name: name of the connection plugin to deregister

Raises:
:obj:`nornir.core.exceptions.ConnectionPluginNotRegistered`


def encode_configuration(self, did, eid, parameters):
    parameters = [{'parameterId': k, 'parameterValue': v} for (k, v) in parameters.items()]
    payload = {'parameters': parameters}
    req_headers = {'Accept': 'application/vnd.onshape.v1+json', 'Content-Type': 'application/json'}
    res = self._api.request('post', (((('/api/elements/d/' + did) + '/e/') + eid) + '/configurationencodings'), body=payload, headers=req_headers)
    return json.loads(res.content.decode('utf-8'))['encodedId']

Encode parameters as a URL-ready string

Args:
- did (str): Document ID
- eid (str): Element ID
- parameters (dict): key-value pairs of the parameters to be encoded
Returns:
- configuration (str): the url-ready configuration string.


def print_format_output(dataframe):
    print_df = pd.DataFrame()
    dropped_cols = []
    empty_cols = []
    for (i, col) in enumerate(dataframe):
        if dataframe[col].isnull().all():
            empty_cols += [col]
            continue
        print_df[col] = dataframe[col]
        test_table = tabulate(print_df, headers='keys', tablefmt='psql')
        if (str(test_table).index('\n') > TERM_WIDTH):
            print_df.drop(col, axis=1, inplace=True)
            dropped_cols += list(dataframe.columns)[i:]
            break
    table = tabulate(print_df, headers='keys', tablefmt='psql', showindex='never')
    print(table)
    if dropped_cols:
        print('Dropped columns:', dropped_cols)
        print('Please increase your terminal size to view remaining columns.')
    if empty_cols:
        print('Empty columns:', empty_cols)
    return (table, dropped_cols, empty_cols)

Prints output of given dataframe to fit into terminal.

Returns:
table (pd.DataFrame): Final outputted dataframe.
dropped_cols (list): Columns dropped due to terminal size.
empty_cols (list): Empty columns (dropped on default).


def from_version(cls, version, op=None):
    lower = None
    upper = None
    if (op is None):
        lower = _LowerBound(version, True)
        upper = _UpperBound(version.next(), False)
    elif (op in ('eq', '==')):
        lower = _LowerBound(version, True)
        upper = _UpperBound(version, True)
    elif (op in ('gt', '>')):
        lower = _LowerBound(version, False)
    elif (op in ('gte', '>=')):
        lower = _LowerBound(version, True)
    elif (op in ('lt', '<')):
        upper = _UpperBound(version, False)
    elif (op in ('lte', '<=')):
        upper = _UpperBound(version, True)
    else:
        raise VersionError(("Unknown bound operation '%s'" % op))
    bound = _Bound(lower, upper)
    range = cls(None)
    range.bounds = [bound]
    return range

Create a range from a version.

Args:
version: Version object. This is used as the upper/lower bound of
the range.
op: Operation as a string. One of 'gt'/'>', 'gte'/'>=', lt'/'<',
'lte'/'<=', 'eq'/'=='. If None, a bounded range will be created
that contains the version superset.

Returns:
`VersionRange` object.


def process(self, feed_item):
    if not feed_item.get(FieldMap.CAMPAIGN_CREATIVE_ASSOCIATION_ID, None):
        campaign = self.campaign_dao.get(feed_item, required=True)
        creative = self.creative_dao.get(feed_item, required=True)
        if campaign and creative:
            if campaign:
                feed_item[FieldMap.CAMPAIGN_ID] = campaign['id']
                feed_item[FieldMap.CAMPAIGN_NAME] = campaign['name']
            association = {'creativeId': str(creative['id'])}
            result = self._api().insert(profileId=self.profile_id, campaignId=str(campaign['id']), body=association).execute()
            feed_item[FieldMap.CAMPAIGN_CREATIVE_ASSOCIATION_ID] = '%s|%s' % (campaign['id'], creative['id'])
            return result
    return None

Processes a feed item by creating the creative association in DCM.

Args:
feed_item: Feed item representing the creative association from the
Bulkdozer feed.

Returns:
The newly created object from DCM.


def cancel(self, force=False):
    return self.rest_client._sc._delegator._cancel_job(self, force)

Cancel this job.

Args:
force (bool, optional): Forcefully cancel this job.

Returns:
bool: True if the job was cancelled, otherwise False if an error occurred.


def copy(reader, writer, start, stop, insertLocation=None, tsCol=None):
    assert (stop >= start)
    startRows = []
    copyRows = []
    ts = None
    inc = None
    if (tsCol is None):
        tsCol = reader.getTimestampFieldIdx()
    for (i, row) in enumerate(reader):
        if (ts is None):
            ts = row[tsCol]
        elif (inc is None):
            inc = (row[tsCol] - ts)
        if ((i >= start) and (i <= stop)):
            copyRows.append(row)
        startRows.append(row)
    if (insertLocation is None):
        insertLocation = (stop + 1)
    startRows[insertLocation:insertLocation] = copyRows
    for row in startRows:
        row[tsCol] = ts
        writer.appendRecord(row)
        ts += inc

Copies a range of values to a new location in the data set.

Args:
reader: A FileRecordStream object with input data.
writer: A FileRecordStream object to write output data to.
start: The first row in the range to copy.
stop: The last row in the range to copy.
insertLocation: The location to insert the copied range. If not specified,
the range is inserted immediately following itself.


def render_trees(trees, path_composer):

    trees = list(trees)

    def create_pub_cache(trees):

        sub_pubs_uuids = sum((x.collect_publications() for x in trees), [])

        uuid_mapping = {
            uuid: search_pubs_by_uuid(uuid)
            for uuid in set(sub_pubs_uuids)
        }

        return {
            uuid: pub[0]
            for uuid, pub in uuid_mapping.iteritems()
            if pub
        }

    pub_cache = create_pub_cache(trees)

    def render_tree(tree, ind=1):

        if not tree.is_public:
            return ""

        rendered_tree = SimpleTemplate(TREE_TEMPLATE).render(
            tree=tree,
            render_tree=render_tree,
            ind=ind,
            path_composer=path_composer,
            pub_cache=pub_cache,
        )

        ind_txt = ind * "  "
        return ind_txt + ("\n" + ind_txt).join(rendered_tree.splitlines())

    parent = tree_handler().get_parent(trees[0])
    link_up = path_composer(parent) if parent else None

    return SimpleTemplate(TREES_TEMPLATE).render(
        trees=trees,
        render_tree=render_tree,
        link_up=link_up,
    )

Render list of `trees` to HTML.

Args:
trees (list): List of :class:`.Tree`.
path_composer (fn reference): Function used to compose paths from UUID.
Look at :func:`.compose_tree_path` from :mod:`.web_tools`.

Returns:
str: HTML representation of trees.


def _ParseRecord(self, parser_mediator, text_file_object):
    try:
        title = text_file_object.readline()
    except UnicodeDecodeError:
        parser_mediator.ProduceExtractionWarning('unable to read and decode title')
        return False
    if (not title):
        return False
    try:
        url = text_file_object.readline()
    except UnicodeDecodeError:
        parser_mediator.ProduceExtractionWarning('unable to read and decode url')
        return False
    try:
        timestamp = text_file_object.readline()
    except UnicodeDecodeError:
        parser_mediator.ProduceExtractionWarning('unable to read and decode timestamp')
        return False
    try:
        popularity_index = text_file_object.readline()
    except UnicodeDecodeError:
        parser_mediator.ProduceExtractionWarning('unable to read and decode popularity index')
        return False
    event_data = OperaGlobalHistoryEventData()
    event_data.url = url.strip()
    title = title.strip()
    if (title != event_data.url):
        event_data.title = title
    popularity_index = popularity_index.strip()
    try:
        event_data.popularity_index = int(popularity_index, 10)
    except ValueError:
        parser_mediator.ProduceExtractionWarning('unable to convert popularity index: {0:s}'.format(popularity_index))
    if (event_data.popularity_index < 0):
        event_data.description = 'First and Only Visit'
    else:
        event_data.description = 'Last Visit'
    timestamp = timestamp.strip()
    try:
        timestamp = int(timestamp, 10)
    except ValueError:
        parser_mediator.ProduceExtractionWarning('unable to convert timestamp: {0:s}'.format(timestamp))
        timestamp = None
    if (timestamp is None):
        date_time = dfdatetime_semantic_time.SemanticTime('Invalid')
    else:
        date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_LAST_VISITED)
    parser_mediator.ProduceEventWithEventData(event, event_data)
    return True

Parses an Opera global history record.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
text_file_object (dfvfs.TextFile): text file.

Returns:
bool: True if the record was successfully parsed.


def add_fileobj(self, fileobj, path, compress, flags=None):
    f = file_iter(fileobj)
    flags = (flags or (os.stat(path) & 511))
    return self.add_stream(f, path, compress, flags)

Add the contents of a file object to the MAR file.

Args:
fileobj (file-like object): open file object
path (str): name of this file in the MAR file
compress (str): One of 'xz', 'bz2', or None. Defaults to None.
flags (int): permission of this file in the MAR file. Defaults to the permissions of `path`


def _get_ops_in_metagraph(meta_graph_def):
    return set(meta_graph_lib.ops_used_by_graph_def(meta_graph_def.graph_def))

Returns a set of the ops in the MetaGraph.

Returns the set of all the ops used in the MetaGraphDef indicated by the
tag_set stored in SavedModel directory.

Args:
meta_graph_def: MetaGraphDef to list the ops of.

Returns:
A set of ops.


def create(self, name, command_to_run, description='', environment_variables=None, required_arguments=None, required_arguments_default_values=None, extra_data_to_post=None):
    if (environment_variables is None):
        environment_variables = []
    if (required_arguments is None):
        required_arguments = []
    if (required_arguments_default_values is None):
        required_arguments_default_values = {}
    request_url = (self._client.base_api_url + self.list_url)
    data_to_post = {'name': name, 'description': description, 'command_to_run': command_to_run, 'environment_variables': json.dumps(environment_variables), 'required_arguments': json.dumps(required_arguments), 'required_arguments_default_values': json.dumps(required_arguments_default_values)}
    if (extra_data_to_post is not None):
        data_to_post.update(extra_data_to_post)
    response = self._client.session.post(request_url, data=data_to_post)
    self.validate_request_success(response_text=response.text, request_url=request_url, status_code=response.status_code, expected_status_code=HTTP_201_CREATED)
    return self.response_data_to_model_instance(response.json())

Create a task type.

Args:
name (str): The name of the task.
command_to_run (str): The command to run to execute the task.
description (str, optional): The description of the task type.
environment_variables (list, optional): The environment
variables required on the host to execute the task.
required_arguments (list, optional): The argument names for
the task type.
required_arguments_default_values (dict, optional): Default
values for the tasks required arguments.
extra_data_to_post (dict, optional): Extra key-value pairs
to add to the request data. This is useful for
subclasses which require extra parameters.

Returns:
:class:`saltant.models.base_task_instance.BaseTaskType`:
A task type model instance representing the task type
just created.


def add_phenotype(self, institute, case, user, link, hpo_term=None, omim_term=None, is_group=False):
    hpo_results = []
    try:
        if hpo_term:
            hpo_results = [hpo_term]
        elif omim_term:
            LOG.debug('Fetching info for mim term {0}'.format(omim_term))
            disease_obj = self.disease_term(omim_term)
            if disease_obj:
                for hpo_term in disease_obj.get('hpo_terms', []):
                    hpo_results.append(hpo_term)
        else:
            raise ValueError('Must supply either hpo or omim term')
    except ValueError as e:
        raise e
    existing_terms = set((term['phenotype_id'] for term in case.get('phenotype_terms', [])))
    updated_case = case
    phenotype_terms = []
    for hpo_term in hpo_results:
        LOG.debug('Fetching info for hpo term {0}'.format(hpo_term))
        hpo_obj = self.hpo_term(hpo_term)
        if (hpo_obj is None):
            raise ValueError(('Hpo term: %s does not exist in database' % hpo_term))
        phenotype_id = hpo_obj['_id']
        description = hpo_obj['description']
        if (phenotype_id not in existing_terms):
            phenotype_term = dict(phenotype_id=phenotype_id, feature=description)
            phenotype_terms.append(phenotype_term)
            LOG.info('Creating event for adding phenotype term for case {0}'.format(case['display_name']))
            self.create_event(institute=institute, case=case, user=user, link=link, category='case', verb='add_phenotype', subject=case['display_name'], content=phenotype_id)
        if is_group:
            updated_case = self.case_collection.find_one_and_update({'_id': case['_id']}, {'$addToSet': {'phenotype_terms': {'$each': phenotype_terms}, 'phenotype_groups': {'$each': phenotype_terms}}}, return_document=pymongo.ReturnDocument.AFTER)
        else:
            updated_case = self.case_collection.find_one_and_update({'_id': case['_id']}, {'$addToSet': {'phenotype_terms': {'$each': phenotype_terms}}}, return_document=pymongo.ReturnDocument.AFTER)
    LOG.debug('Case updated')
    return updated_case

Add a new phenotype term to a case

Create a phenotype term and event with the given information

Args:
institute (Institute): A Institute object
case (Case): Case object
user (User): A User object
link (str): The url to be used in the event
hpo_term (str): A hpo id
omim_term (str): A omim id
is_group (bool): is phenotype term a group?


def EnumValueName(self, enum, value):
    return self.enum_types_by_name[enum].values_by_number[value].name

Returns the string name of an enum value.

This is just a small helper method to simplify a common operation.

Args:
enum: string name of the Enum.
value: int, value of the enum.

Returns:
string name of the enum value.

Raises:
KeyError if either the Enum doesn't exist or the value is not a valid
value for the enum.


def handle(self, connection_id, message_content):
    try:
        request = self._request_proto()
        request.ParseFromString(message_content)
    except DecodeError:
        LOGGER.info('Protobuf %s failed to deserialize', request)
        return self._wrap_result(self._status.INTERNAL_ERROR)
    try:
        response = self._respond(request)
    except _ResponseFailed as e:
        response = e.status
    return self._wrap_result(response)

Handles parsing incoming requests, and wrapping the final response.

Args:
connection_id (str): ZMQ identity sent over ZMQ socket
message_content (bytes): Byte encoded request protobuf to be parsed

Returns:
HandlerResult: result to be sent in response back to client


def solve(self, print_solution=False):
    self._cp_solver = cp_model.CpSolver()
    status = self._cp_solver.Solve(self._model)
    if (status != cp_model.OPTIMAL):
        if (status == cp_model.FEASIBLE):
            logging.warning('A potentially suboptimal solution was found.')
        else:
            logging.error('Solver returned status %d.', status)
            raise SolverError('The solver could not solve the problem and returned status {}.'.format(status))
    if print_solution:
        print_cp_model_solution.print_solution(self._model, self._cp_solver)
    layout = []
    for mtf_dimension_name in self._layout_validator.splittable_mtf_dimension_names:
        for mesh_dimension_name in self._layout_validator.mesh_dimension_name_to_size:
            value = self._cp_solver.Value(self._global_vars[(mtf_dimension_name, mesh_dimension_name)])
            if value:
                layout.append(((mtf_dimension_name + ':') + mesh_dimension_name))
    layout.sort()
    return ';'.join(layout)

Solves the current integer program and returns the computed layout.

Args:
print_solution: An optional boolean indicating whether to print the full
solution in human-readable format.

Returns:
The computed layout (as a string).

Raises:
SolverError: the internal solver could not find a solution, or the
solution found is infeasible.


def _get_energy(self, x):

        return self.pd.get_hull_energy(self.comp1 * x + self.comp2 * (1-x)) - \
            self.e1 * x - self.e2 * (1-x)

Computes reaction energy in eV/atom at mixing ratio x : (1-x) for
self.comp1 : self.comp2.

Args:
x (float): Mixing ratio x of reactants, a float between 0 and 1.

Returns:
Reaction energy.


def estimate_size(self) -> Optional[int]:
    raise NotImplementedError

Estimates the size of source in bytes.

An estimate of the total size (in bytes) of the data that would be read
from this source. This estimate is in terms of external storage size,
before performing decompression or other processing.

Returns:
estimated size of the source if the size can be determined, ``None``
otherwise.


def GetEventTagByIdentifier(self, identifier):

    event_tag = self._GetAttributeContainerByIndex(
        self._CONTAINER_TYPE_EVENT_TAG, identifier.row_identifier - 1)
    if event_tag:
      event_identifier = identifiers.SQLTableIdentifier(
          self._CONTAINER_TYPE_EVENT, event_tag.event_row_identifier)
      event_tag.SetEventIdentifier(event_identifier)

      del event_tag.event_row_identifier

    return event_tag

Retrieves a specific event tag.

Args:
identifier (SQLTableIdentifier): event tag identifier.

Returns:
EventTag: event tag or None if not available.


def setMood(self, mood):

        self.conn("POST", "{0}/users/{1}/profile/partial".format(SkypeConnection.API_USER, self.userId),
                  auth=SkypeConnection.Auth.SkypeToken, json={"payload": {"mood": mood or ""}})
        self.user.mood = SkypeUser.Mood(plain=mood) if mood else None

Update the activity message for the current user.

Args:
mood (str): new mood message


def get_legacy_output_types(dataset_or_iterator):
    return nest.map_structure(lambda component_spec: component_spec._to_legacy_output_types(), get_structure(dataset_or_iterator))

Returns the output shapes for elements of the input dataset / iterator.

Args:
dataset_or_iterator: A `tf.data.Dataset` or `tf.data.Iterator`.

Returns:
A (nested) structure of `tf.DType` objects matching the structure of
dataset / iterator elements and specifying the shape of the individual
components.

@compatibility(TF2)
This is a legacy API for inspecting the type signature of dataset elements. In
TF 2, you should use the `tf.data.Dataset.element_spec` attribute instead.
@end_compatibility


def get_num_of_video_patches(self, num_frames: int, height: int, width: int, videos_kwargs=None):
    min_pixels = videos_kwargs.get('min_pixels', None) or self.size['shortest_edge']
    max_pixels = videos_kwargs.get('max_pixels', None) or self.size['longest_edge']
    patch_size = videos_kwargs.get('patch_size', None) or self.patch_size
    merge_size = videos_kwargs.get('merge_size', None) or self.merge_size
    temporal_patch_size = videos_kwargs.get('temporal_patch_size', None) or self.temporal_patch_size
    factor = patch_size * merge_size
    resized_height, resized_width = smart_resize(height, width, factor, min_pixels=min_pixels, max_pixels=max_pixels)
    grid_h, grid_w = (resized_height
    grid_t = num_frames
    return grid_t * grid_h * grid_w

A utility that returns number of video patches a given video size.

Args:
num_frames (`int`):
Number of frames in the input video.
height (`int`):
Height of the input video.
width (`int`):
Width of the input video.
videos_kwargs (`dict`, *optional*)
Any kwargs to override defaults of the video processor.
Returns:
`Tuple(int, int)`: Number of placeholder tokens required and number of patches per image.


def __init__(self, values, row_splits):
    if not (isinstance(row_splits, (np.ndarray, np.generic)) and row_splits.dtype in (np.int64, np.int32) and (row_splits.ndim == 1)):
        raise TypeError('row_splits must be a 1D int32 or int64 numpy array')
    if not isinstance(values, (np.ndarray, np.generic, RaggedTensorValue)):
        raise TypeError('values must be a numpy array or a RaggedTensorValue')
    if isinstance(values, RaggedTensorValue) and row_splits.dtype != values.row_splits.dtype:
        raise ValueError('row_splits and values.row_splits must have the same dtype')
    self._values = values
    self._row_splits = row_splits

Creates a `RaggedTensorValue`.

Args:
values: A numpy array of any type and shape; or a RaggedTensorValue.
row_splits: A 1-D int32 or int64 numpy array.


def _resolve_non_literal_route(self, method, path):
    for route_dict in (self._wildcard, self._regex):
        if (method in route_dict):
            for route in reversed(route_dict[method]):
                callback_data = route.match(path)
                if (callback_data is not None):
                    return callback_data
    return None

Resolve a request to a wildcard or regex route handler.

Arguments:
method (str): HTTP method name, e.g. GET, POST, etc.
path (str): Request path

Returns:
tuple or None: A tuple of three items:

1. Route handler (callable)
2. Positional arguments (list)
3. Keyword arguments (dict)

``None`` if no route matches the request.


def heightmap_get_normal(hm: np.ndarray, x: float, y: float, waterLevel: float) -> Tuple[(float, float, float)]:
    cn = ffi.new('float[3]')
    lib.TCOD_heightmap_get_normal(_heightmap_cdata(hm), x, y, cn, waterLevel)
    return tuple(cn)

Return the map normal at given coordinates.

Args:
hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
x (float): The x coordinate.
y (float): The y coordinate.
waterLevel (float): The heightmap is considered flat below this value.

Returns:
Tuple[float, float, float]: An (x, y, z) vector normal.


def create_normal_matrix(self, modelview):
    normal_m = Matrix33.from_matrix44(modelview)
    normal_m = normal_m.inverse
    normal_m = normal_m.transpose()
    return normal_m

Creates a normal matrix from modelview matrix

Args:
modelview: The modelview matrix

Returns:
A 3x3 Normal matrix as a :py:class:`numpy.array`


def setup(self, artifacts, use_tsk, reason, grr_server_url, grr_username, grr_password, approvers=None, verify=True):
    super(GRRHuntArtifactCollector, self).setup(reason, grr_server_url, grr_username, grr_password, approvers=approvers, verify=verify)
    self.artifacts = [item.strip() for item in artifacts.strip().split(',')]
    if (not artifacts):
        self.state.add_error('No artifacts were specified.', critical=True)
    self.use_tsk = use_tsk

Initializes a GRR Hunt artifact collector.

Args:
artifacts: str, comma-separated list of GRR-defined artifacts.
use_tsk: toggle for use_tsk flag.
reason: justification for GRR access.
grr_server_url: GRR server URL.
grr_username: GRR username.
grr_password: GRR password.
approvers: str, comma-separated list of GRR approval recipients.
verify: boolean, whether to verify the GRR server's x509 certificate.


def delete_snl(self, snl_ids):
    try:
        payload = {'ids': json.dumps(snl_ids)}
        response = self.session.post('{}/snl/delete'.format(self.preamble), data=payload)
        if (response.status_code in [200, 400]):
            resp = json.loads(response.text, cls=MontyDecoder)
            if resp['valid_response']:
                if resp.get('warning'):
                    warnings.warn(resp['warning'])
                return resp
            else:
                raise MPRestError(resp['error'])
        raise MPRestError('REST error with status code {} and error {}'.format(response.status_code, response.text))
    except Exception as ex:
        raise MPRestError(str(ex))

Delete earlier submitted SNLs.

.. note::

As of now, this MP REST feature is open only to a select group of
users. Opening up submissions to all users is being planned for
the future.

Args:
snl_ids: List of SNL ids.

Raises:
MPRestError


def _ensure_servable(input_tensors, names_to_output_tensor_infos):
    plain_input_tensors = nest.flatten(input_tensors, expand_composites=True)
    graph = op_selector.get_unique_graph(plain_input_tensors)
    output_tensors = [utils.get_tensor_from_tensor_info(tensor, graph=graph) for tensor in names_to_output_tensor_infos.values()]
    plain_output_tensors = nest.flatten(output_tensors, expand_composites=True)
    dependency_ops = op_selector.get_backward_walk_ops(plain_output_tensors, stop_at_ts=plain_input_tensors)
    fed_tensors = object_identity.ObjectIdentitySet(plain_input_tensors)
    for dependency_op in dependency_ops:
        if _must_be_fed(dependency_op) and (not all((output in fed_tensors for output in dependency_op.outputs))):
            input_tensor_names = [tensor.name for tensor in plain_input_tensors]
            output_tensor_keys = list(names_to_output_tensor_infos.keys())
            output_tensor_names = [tensor.name for tensor in plain_output_tensors]
            dependency_path = op_selector.show_path(dependency_op, plain_output_tensors, plain_input_tensors)
            raise ValueError(f"The signature's input tensors {input_tensor_names} are insufficient to compute its output keys {output_tensor_keys} (respectively, tensors {output_tensor_names}) because of the dependency on `{dependency_op.name}` which is not given as a signature input, as illustrated by the following dependency path: {dependency_path}")

Check that the signature outputs don't depend on unreachable placeholders.

Args:
input_tensors: An iterable of `Tensor`s specified as the signature's inputs.
names_to_output_tensor_infos: An mapping from output names to respective
`TensorInfo`s corresponding to the signature's output tensors.

Raises:
ValueError: If any of the signature's outputs depend on placeholders not
provided as signature's inputs.


def __discover_node(self, node, depth):

        if (node == None):
            return

        if (depth >= self.max_depth):
            return

        if (node.discovered > 0):
            return
        node.discovered = 1

        if (node.ip[0] == '0.0.0.0'):
            return

        if (node.snmpobj.success == 0):
            return

        dcodes = DCODE_STEP_INTO
        if (depth == 0):
            dcodes |= DCODE_ROOT
        self.__print_step(node.ip[0], node.name, depth, dcodes)

        snmpobj = node.snmpobj

        valid_neighbors = []

        cdp_neighbors  = node.get_cdp_neighbors()
        lldp_neighbors = node.get_lldp_neighbors()
        neighbors      = cdp_neighbors + lldp_neighbors
        if (len(neighbors) == 0):
            return

        for n in neighbors:

            if (n.remote_ip == None):
                n.remote_ip = '0.0.0.0'

            acl_action = self.__match_node_acl(n.remote_ip, n.remote_name)
            if (acl_action == 'deny'):

                continue

            dcodes = DCODE_DISCOVERED
            child = None
            if (acl_action == 'include'):

                child    = natlas_node()
                child.ip = [n.remote_ip]
                dcodes  |= DCODE_INCLUDE
            else:

                child, query_result = self.__query_node(n.remote_ip, n.remote_name)

            if (child.snmpobj.success == 0):
                child.name = util.shorten_host_name(n.remote_name, self.config.host_domains)
                dcodes  |= DCODE_ERR_SNMP

            acl_action = self.__match_node_acl(n.remote_ip, n.remote_name, n.remote_plat, n.remote_ios, child.serial)
            if (acl_action == 'deny'):
                continue

            if (query_result == NODE_NEW):
                self.nodes.append(child)
                if (acl_action == 'leaf'):          dcodes |= DCODE_LEAF
                if (n.discovered_proto == 'cdp'):   dcodes |= DCODE_CDP
                if (n.discovered_proto == 'lldp'):  dcodes |= DCODE_LLDP
                self.__print_step(n.remote_ip, n.remote_name, depth+1, dcodes)

            child.plat = n.remote_plat
            child.ios  = n.remote_ios

            n.node = child
            self.__add_link(node, n)

            if ((query_result == NODE_NEW) & (acl_action != 'leaf') & (acl_action != 'include')):
                valid_neighbors.append(child)

        for n in valid_neighbors:
            self.__discover_node(n, depth+1)

Given a node, recursively enumerate its adjacencies
until we reach the specified depth (>0).

Args:
node:   natlas_node object to enumerate.
depth:  The depth left that we can go further away from the root.


def listen(self, message_consumer):

        while not self._rfile.closed:
            request_str = self._read_message()

            if request_str is None:
                break

            try:
                message_consumer(json.loads(request_str.decode('utf-8')))
            except ValueError:
                log.exception("Failed to parse JSON message %s", request_str)
                continue

Blocking call to listen for messages on the rfile.

Args:
message_consumer (fn): function that is passed each message as it is read off the socket.


def db_update_record(self, table_name, column, value):

        sql = 'UPDATE {} SET {} = \'{}\''.format(table_name, column, value)
        cur = self.db_conn.cursor()
        cur.execute(sql)

Insert records into DB.

Args:
table_name (str): The name of the table.
column (str): The column name in which the value is to be updated.
value (str): The value to update in the column.


def _build_shuffle_scatter(reduced_shards, dst_devices):
    num_devices = len(dst_devices)
    out_tensors = []
    for d in range(0, num_devices):
        with ops.device(dst_devices[d]):
            out_tensors.append(array_ops.concat(reduced_shards, 0))
    return out_tensors

Build the scatter phase of shuffle all-reduce.

Args:
reduced_shards:  list of `tf.Tensor` fully reduced shards
dst_devices: list of names of devices at which the fully-reduced value
should be reconstituted.

Returns:
list of `tf.Tensor` scattered tensors.


def parse_instrumentation_options(self, parameters=None):
    if parameters is None:
        return {}
    filtered_parameters = {}
    for parameter_key, parameter_value in parameters.items():
        if parameter_key.startswith(self.DEFAULT_INSTRUMENTATION_OPTION_PREFIX):
            option_key = parameter_key[len(self.DEFAULT_INSTRUMENTATION_OPTION_PREFIX):]
            filtered_parameters[option_key] = parameter_value
    return filtered_parameters

Returns the options for the instrumentation test from user_params.

By default, this method assume that the correct instrumentation options
all start with DEFAULT_INSTRUMENTATION_OPTION_PREFIX.

Args:
parameters: dict, the key value pairs representing an assortment
of parameters including instrumentation options. Usually,
this argument will be from self.user_params.

Returns:
A dictionary of options/parameters for the instrumentation tst.


def _get_input_readers(self, state):
    serialized_input_readers_key = (self._SERIALIZED_INPUT_READERS_KEY % state.key().id_or_name())
    serialized_input_readers = model._HugeTaskPayload.get_by_key_name(serialized_input_readers_key, parent=state)
    input_reader_class = state.mapreduce_spec.mapper.input_reader_class()
    split_param = state.mapreduce_spec.mapper
    if issubclass(input_reader_class, map_job.InputReader):
        split_param = map_job.JobConfig._to_map_job_config(state.mapreduce_spec, os.environ.get('HTTP_X_APPENGINE_QUEUENAME'))
    if (serialized_input_readers is None):
        readers = input_reader_class.split_input(split_param)
    else:
        readers = [input_reader_class.from_json_str(_json) for _json in json.loads(zlib.decompress(serialized_input_readers.payload))]
    if (not readers):
        return (None, None)
    state.mapreduce_spec.mapper.shard_count = len(readers)
    state.active_shards = len(readers)
    if (serialized_input_readers is None):
        serialized_input_readers = model._HugeTaskPayload(key_name=serialized_input_readers_key, parent=state)
        readers_json_str = [i.to_json_str() for i in readers]
        serialized_input_readers.payload = zlib.compress(json.dumps(readers_json_str))
    return (readers, serialized_input_readers)

Get input readers.

Args:
state: a MapreduceState model.

Returns:
A tuple: (a list of input readers, a model._HugeTaskPayload entity).
The payload entity contains the json serialized input readers.
(None, None) when input reader inplitting returned no data to process.


def diff_str(a: str | object, b: str | object) -> str:
    if not isinstance(a, str):
        a = pretty_repr(a).split('\n')
    if not isinstance(b, str):
        b = pretty_repr(b).split('\n')
    diff = difflib.ndiff(a, b)
    return '\n'.join(diff)

Pretty diff between 2 objects.

Args:
a: Object/str to compare
b: Object/str to compare

Returns:
The diff string


def volatility(self, strike: types.FloatTensor, expiry_dates: Optional[types.DateTensor]=None, expiry_times: Optional[types.FloatTensor]=None, term: Optional[types.Period]=None) -> types.FloatTensor:
    del term
    if expiry_dates is not None and expiry_times is not None:
        raise ValueError('Unexpected inputs: Both expiry_dates and expiry times are specified')
    if expiry_times is None:
        expiry_dates = dateslib.convert_to_date_tensor(expiry_dates)
        expiries = self._day_count_fn(start_date=self._valuation_date, end_date=expiry_dates, dtype=self._dtype)
    else:
        expiries = tf.convert_to_tensor(expiry_times, dtype=self._dtype)
    strike = tf.convert_to_tensor(strike, dtype=self._dtype, name='strike')
    return self._interpolator(expiries, strike)

Returns the interpolated volatility on a specified set of expiries.

Args:
strike: The strikes for which the interpolation is desired.
expiry_dates: Optional input specifying the expiry dates for which
interpolation is desired. The user should supply either `expiry_dates`
or `expiry_times` for interpolation.
expiry_times: Optional real `Tensor` containing the time to expiration
for which interpolation is desired. The user should supply either
`expiry_dates` or `expiry_times` for interpolation.
term: Optional input specifying the term of the underlying rate for
which the interpolation is desired. Relevant for interest rate implied
volatility data.

Returns:
A `Tensor` of the same shape as `expiry` with the interpolated volatility
from the volatility surface.

Raises:
ValueError is both `expiry_dates` and `expiry_times`  are specified.


def load_disease_term(self, disease_obj):

        LOG.debug("Loading disease term %s into database", disease_obj['_id'])
        try:
            self.disease_term_collection.insert_one(disease_obj)
        except DuplicateKeyError as err:
            raise IntegrityError("Disease term %s already exists in database".format(disease_obj['_id']))

        LOG.debug("Disease term saved")

Load a disease term into the database

Args:
disease_obj(dict)


def get_ref(profile, ref):

    resource = "/refs/" + ref
    data = api.get_request(profile, resource)
    return prepare(data)

Fetch a ref.

Args:

profile
A profile generated from ``simplygithub.authentication.profile``.
Such profiles tell this module (i) the ``repo`` to connect to,
and (ii) the ``token`` to connect with.

ref
The ref to fetch, e.g., ``heads/my-feature-branch``.

Returns
A dict with data about the ref.


def _parse_trunk_groups(self, config):

        values = TRUNK_GROUP_RE.findall(config)
        return dict(trunk_groups=values)

_parse_trunk_groups scans the provided configuration block and
extracts all the vlan trunk groups.  If no trunk groups are configured
an empty List is returned as the vlaue.  The return dict is intended
to be merged into the response dict.

Args:
config (str): The vlan configuration block form the node's
running configuration

Returns:
dict: resource dict attribute


def lower_and_check_unique(dict_to_check):
    if (dict_to_check == None):
        return None
    else:
        to_return = {}
        for key in dict_to_check:
            new_key = key.lower()
            if (new_key == 'jobtype'):
                new_key = 'job_type'
            if (new_key in to_return):
                raise Exception((('Multiple instances of key ' + new_key) + ' found!'))
            else:
                try:
                    to_return[new_key] = dict_to_check.get(key).lower()
                except AttributeError:
                    to_return[new_key] = dict_to_check.get(key)
        return to_return

Takes a dictionary and makes all the keys lower case. Also replaces
"jobtype" with "job_type" just so that key specifically can be called
elsewhere without ambiguity. Finally, ensures that multiple identical
keys, that differed only due to different capitalizations, are not
present. If there are multiple equivalent keys, an Exception is raised.

Args:
dict_to_check (dict): The dictionary to check and standardize

Returns:
to_return (dict): An identical dictionary but with all keys made
lower case and no identical keys present.


def top_1_tpu(inputs):
    inputs_max = tf.reduce_max(inputs, axis=(- 1), keepdims=True)
    mask = tf.to_int32(tf.equal(inputs_max, inputs))
    index = (tf.range(tf.shape(inputs)[(- 1)]) * mask)
    return (tf.squeeze(inputs_max, (- 1)), tf.reduce_max(index, axis=(- 1)))

find max and argmax over the last dimension.

Works well on TPU

Args:
inputs: A tensor with shape [..., depth]

Returns:
values: a Tensor with shape [...]
indices: a Tensor with shape [...]


def _from_yang_library(self, yang_lib: Dict[(str, Any)]) -> None:
    try:
        for item in yang_lib['ietf-yang-library:modules-state']['module']:
            name = item['name']
            rev = item['revision']
            mid = (name, rev)
            mdata = ModuleData(mid)
            self.modules[mid] = mdata
            if (item['conformance-type'] == 'implement'):
                if (name in self.implement):
                    raise MultipleImplementedRevisions(name)
                self.implement[name] = rev
            mod = self._load_module(name, rev)
            mdata.statement = mod
            if ('feature' in item):
                mdata.features.update(item['feature'])
            locpref = mod.find1('prefix', required=True).argument
            mdata.prefix_map[locpref] = mid
            if ('submodule' in item):
                for s in item['submodule']:
                    sname = s['name']
                    smid = (sname, s['revision'])
                    sdata = ModuleData(mid)
                    self.modules[smid] = sdata
                    mdata.submodules.add(smid)
                    submod = self._load_module(*smid)
                    sdata.statement = submod
                    bt = submod.find1('belongs-to', name, required=True)
                    locpref = bt.find1('prefix', required=True).argument
                    sdata.prefix_map[locpref] = mid
    except KeyError as e:
        raise BadYangLibraryData(('missing ' + str(e))) from None
    self._process_imports()
    self._check_feature_dependences()

Set the schema structures from YANG library data.

Args:
yang_lib: Dictionary with YANG library data.

Raises:
BadYangLibraryData: If YANG library data is invalid.
FeaturePrerequisiteError: If a pre-requisite feature isn't
supported.
MultipleImplementedRevisions: If multiple revisions of an
implemented module are listed in YANG library.
ModuleNotFound: If a YANG module wasn't found in any of the
directories specified in `mod_path`.


def count(self, event):

        return len(self._listeners[event]) + len(self._once[event])

Get the number of listeners for the event.

Args:
event (str): The event for which to count all listeners.

The resulting count is a combination of listeners added using
'on'/'add_listener' and 'once'.


def get_all_voronoi_polyhedra(self, structure):
    if (len(structure) == 1):
        return [self.get_voronoi_polyhedra(structure, 0)]
    if (self.targets is None):
        targets = structure.composition.elements
    else:
        targets = self.targets
    sites = [x.to_unit_cell() for x in structure]
    indices = [(i, 0, 0, 0) for (i, _) in enumerate(structure)]
    all_neighs = structure.get_all_neighbors(self.cutoff, include_index=True, include_image=True)
    for neighs in all_neighs:
        sites.extend([x[0] for x in neighs])
        indices.extend([((x[2],) + x[3]) for x in neighs])
    indices = np.array(indices, dtype=np.int)
    (indices, uniq_inds) = np.unique(indices, return_index=True, axis=0)
    sites = np.array(sites)[uniq_inds]
    (root_images,) = np.nonzero((np.abs(indices[(:, 1:)]).max(axis=1) == 0))
    del indices
    qvoronoi_input = [s.coords for s in sites]
    voro = Voronoi(qvoronoi_input)
    return [self._extract_cell_info(structure, i, sites, targets, voro, self.compute_adj_neighbors) for i in root_images.tolist()]

Get the Voronoi polyhedra for all site in a simulation cell

Args:
structure (Structure): Structure to be evaluated
Returns:
A dict of sites sharing a common Voronoi facet with the site
n mapped to a directory containing statistics about the facet:
- solid_angle - Solid angle subtended by face
- angle_normalized - Solid angle normalized such that the
faces with the largest
- area - Area of the facet
- face_dist - Distance between site n and the facet
- volume - Volume of Voronoi cell for this face
- n_verts - Number of vertices on the facet


def render_diagram(root_task, out_base, max_param_len=20, horizontal=False, colored=False):
    import re
    import codecs
    import subprocess
    from ozelot import config
    from ozelot.etl.tasks import get_task_name, get_task_param_string
    lines = [u'digraph G {']
    if horizontal:
        lines.append(u'rankdir=LR;')

    def get_id(task):
        s = ((get_task_name(task) + '_') + get_task_param_string(task))
        return re.sub('\\W+', '', re.sub(' ', '_', s))
    existing_nodes = set()
    existing_edges = set()

    def _build(task, parent_id=None):
        tid = get_id(task)
        if (tid not in existing_nodes):
            params = task.to_str_params()
            param_list = ''
            for (k, v) in params.items():
                if (len(v) > max_param_len):
                    v = (v[:max_param_len] + '...')
                param_list += '
{:s}	{:s}
'.format(k, v)
            label = (('

{:s}
'.format(get_task_name(task)) + param_list) + '
')
            style = getattr(task, 'diagram_style', [])
            if colored:
                color = ', color="{:s}"'.format(('green' if task.complete() else 'red'))
            else:
                color = ''
            lines.append(u'{name:s} [label=< {label:s} >, shape="rect" {color:s}, style="{style:s}"];\n'.format(name=tid, label=label, color=color, style=','.join(style)))
            existing_nodes.add(tid)
            for req in task.requires():
                _build(req, parent_id=tid)
        if ((parent_id is not None) and ((tid, parent_id) not in existing_edges)):
            lines.append(u'{source:s} -> {target:s};\n'.format(source=tid, target=parent_id))
    _build(root_task)
    lines.append(u'}')
    with codecs.open((out_base + '.dot'), 'w', encoding='utf-8') as f:
        f.write(u'\n'.join(lines))
    if (not hasattr(config, 'DOT_EXECUTABLE')):
        raise RuntimeError("Please configure the 'DOT_EXECUTABLE' variable in your 'project_config.py'")
    if (not os.path.exists(config.DOT_EXECUTABLE)):
        raise IOError(("Could not find file pointed to by 'DOT_EXECUTABLE': " + str(config.DOT_EXECUTABLE)))
    subprocess.check_call([config.DOT_EXECUTABLE, '-T', 'png', '-o', (out_base + '.png'), (out_base + '.dot')])

Render a diagram of the ETL pipeline

All upstream tasks (i.e. requirements) of :attr:`root_task` are rendered.

Nodes are, by default, styled as simple rects. This style is augmented by any
:attr:`diagram_style` attributes of the tasks.

.. note:: This function requires the 'dot' executable from the GraphViz package to be installed
and its location configured in your `project_config.py` variable :attr:`DOT_EXECUTABLE`.

Args:
root_task (luigi.Task): Task instance that defines the 'upstream root' of the pipeline
out_base (str): base output file name (file endings will be appended)
max_param_len (int): Maximum shown length of task parameter values
horizontal (bool): If True, layout graph left-to-right instead of top-to-bottom
colored (bool): If True, show task completion status by color of nodes


def from_Z(z: int):
    for (sym, data) in _pt_data.items():
        if (data['Atomic no'] == z):
            return Element(sym)
    raise ValueError(('No element with this atomic number %s' % z))

Get an element from an atomic number.

Args:
z (int): Atomic number

Returns:
Element with atomic number z.


def parse_zip(zipfilename: str, regex: Pattern, invert_match: bool, files_with_matches: bool, files_without_match: bool, grep_inner_file_name: bool, show_inner_file: bool) -> None:
    assert (not (files_without_match and files_with_matches))
    report_lines = ((not files_without_match) and (not files_with_matches))
    report_hit_lines = (report_lines and (not invert_match))
    report_miss_lines = (report_lines and invert_match)
    log.debug(('Checking ZIP: ' + zipfilename))
    found_in_zip = False
    try:
        with ZipFile(zipfilename, 'r') as zf:
            for contentsfilename in zf.namelist():
                log.debug(('... checking file: ' + contentsfilename))
                if grep_inner_file_name:
                    found_in_filename = bool(regex.search(contentsfilename))
                    found_in_zip = (found_in_zip or found_in_filename)
                    if (files_with_matches and found_in_zip):
                        report_hit_filename(zipfilename, contentsfilename, show_inner_file)
                        return
                    if ((report_hit_lines and found_in_filename) or (report_miss_lines and (not found_in_filename))):
                        report_line(zipfilename, contentsfilename, contentsfilename, show_inner_file)
                else:
                    try:
                        with zf.open(contentsfilename, 'r') as file:
                            try:
                                for line in file.readlines():
                                    found_in_line = bool(regex.search(line))
                                    found_in_zip = (found_in_zip or found_in_line)
                                    if (files_with_matches and found_in_zip):
                                        report_hit_filename(zipfilename, contentsfilename, show_inner_file)
                                        return
                                    if ((report_hit_lines and found_in_line) or (report_miss_lines and (not found_in_line))):
                                        report_line(zipfilename, contentsfilename, line, show_inner_file)
                            except EOFError:
                                pass
                    except RuntimeError as e:
                        log.warning('RuntimeError whilst processing {} [{}]: probably encrypted contents; error was {!r}', zipfilename, contentsfilename, e)
    except (zlib.error, BadZipFile) as e:
        log.debug('Invalid zip: {}; error was {!r}', zipfilename, e)
    if (files_without_match and (not found_in_zip)):
        report_miss_filename(zipfilename)

Implement a "grep within an OpenXML file" for a single OpenXML file, which
is by definition a ``.zip`` file.

Args:
zipfilename: name of the OpenXML (zip) file
regex: regular expression to match
invert_match: find files that do NOT match, instead of ones that do?
files_with_matches: show filenames of files with a match?
files_without_match: show filenames of files with no match?
grep_inner_file_name: search the names of "inner" files, rather than
their contents?
show_inner_file: show the names of the "inner" files, not just the
"outer" (OpenXML) file?


def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, object_queries: Optional[torch.Tensor]=None, output_attentions: bool=False):
    residual = hidden_states
    hidden_states, attn_weights = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, object_queries=object_queries, output_attentions=output_attentions)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    residual = hidden_states
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = nn.functional.dropout(hidden_states, p=self.activation_dropout, training=self.training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    if self.training:
        if torch.isinf(hidden_states).any() or torch.isnan(hidden_states).any():
            clamp_value = torch.finfo(hidden_states.dtype).max - 1000
            hidden_states = torch.clamp(hidden_states, min=-clamp_value, max=clamp_value)
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (attn_weights,)
    return outputs

Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, target_len, source_len)` where padding elements are indicated by very large negative
values.
object_queries (`torch.FloatTensor`, *optional*):
Object queries (also called content embeddings), to be added to the hidden states.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.


def check_correct(state, check, diagnose):
    feedback = None
    try:
        multi(state, check)
    except TestFail as e:
        feedback = e.feedback
    try:
        multi(state, diagnose)
    except TestFail as e:
        if ((feedback is not None) or state.force_diagnose):
            feedback = e.feedback
    if (feedback is not None):
        state.report(feedback)
    return state

Allows feedback from a diagnostic SCT, only if a check SCT fails.

Args:
state: State instance describing student and solution code. Can be omitted if used with Ex().
check: An sct chain that must succeed.
diagnose: An sct chain to run if the check fails.

:Example:
The SCT below tests whether students query result is correct, before running diagnostic SCTs.. ::

Ex().check_correct(
check_result(),
check_node('SelectStmt')
)


def evaluate_rpn(rpn):
    vals_stack = []
    for item in rpn:
        if (item in _ALL_OPS):
            v2 = vals_stack.pop()
            if (item in _UNARY_OPS):
                res = _UNARY_OPS[item](v2)
            elif (item in _BIN_OPS):
                v1 = vals_stack.pop()
                res = _BIN_OPS[item](v1, v2)
            else:
                raise ValueError(('%s not in unary_ops or bin_ops' % str(item)))
            vals_stack.append(res)
        else:
            vals_stack.append(item)
    assert (len(vals_stack) == 1)
    assert isinstance(vals_stack[0], bool)
    return vals_stack[0]

Evaluates the RPN form produced my map2rpn.

Returns:
bool


def _peer_bfd_tx(self, **kwargs):

        method_name = 'rbridge_id_router_router_bgp_router_bgp_attributes_' \
                      'neighbor_neighbor_ips_neighbor_addr_bfd_interval_min_tx'
        bfd_tx = getattr(self._rbridge, method_name)
        config = bfd_tx(**kwargs)
        if kwargs['delete']:
            tag = 'min-tx'
            config.find('.
        return config

Return the BFD minimum transmit interval XML.

You should not use this method.
You probably want `BGP.bfd`.

Args:
peer_ip (str): Peer IPv4 address for BFD setting.
min_tx (str): BFD transmit interval in milliseconds (300, 500, etc)
delete (bool): Remove the configuration if ``True``.

Returns:
XML to be passed to the switch.

Raises:
None


def append(self, data):

        if isinstance(data, list) and len(data) > 0:
            self.nodes.append(data)
        else:
            self.nodes.append([data])

Appends items or lists to the Lattice

Args:
data (item,list) : The Item or List to be added to the Lattice


def v4_int_to_packed(address):

    if address > _BaseV4._ALL_ONES:
        raise ValueError('Address too large for IPv4')
    return Bytes(struct.pack('!I', address))

The binary representation of this address.

Args:
address: An integer representation of an IPv4 IP address.

Returns:
The binary representation of this address.

Raises:
ValueError: If the integer is too large to be an IPv4 IP
address.


def __init__(self, pipeline: Union[beam_runner_api_pb2.Pipeline, beam.Pipeline], default_vertex_attrs={'shape': 'box'}, default_edge_attrs=None, render_option=None):
    self._lock = threading.Lock()
    self._graph: pydot.Dot = None
    self._pipeline_instrument = None
    if isinstance(pipeline, beam.Pipeline):
        self._pipeline_instrument = inst.PipelineInstrument(pipeline, pipeline._options)
        self._pipeline_instrument.preprocess()
    if isinstance(pipeline, beam_runner_api_pb2.Pipeline):
        self._pipeline_proto = pipeline
    elif isinstance(pipeline, beam.Pipeline):
        self._pipeline_proto = pipeline.to_runner_api()
    else:
        raise TypeError('pipeline should either be a %s or %s, while %s is given' % (beam_runner_api_pb2.Pipeline, beam.Pipeline, type(pipeline)))
    self._consumers: DefaultDict[str, List[str]] = collections.defaultdict(list)
    self._producers: Dict[str, str] = {}
    for transform_id, transform_proto in self._top_level_transforms():
        for pcoll_id in transform_proto.inputs.values():
            self._consumers[pcoll_id].append(transform_id)
        for pcoll_id in transform_proto.outputs.values():
            self._producers[pcoll_id] = transform_id
    default_vertex_attrs = default_vertex_attrs or {'shape': 'box'}
    if 'color' not in default_vertex_attrs:
        default_vertex_attrs['color'] = 'blue'
    if 'fontcolor' not in default_vertex_attrs:
        default_vertex_attrs['fontcolor'] = 'blue'
    vertex_dict, edge_dict = self._generate_graph_dicts()
    self._construct_graph(vertex_dict, edge_dict, default_vertex_attrs, default_edge_attrs)
    self._renderer = pipeline_graph_renderer.get_renderer(render_option)

Constructor of PipelineGraph.

Examples:
graph = pipeline_graph.PipelineGraph(pipeline_proto)
graph.get_dot()

or

graph = pipeline_graph.PipelineGraph(pipeline)
graph.get_dot()

Args:
pipeline: (Pipeline proto) or (Pipeline) pipeline to be rendered.
default_vertex_attrs: (Dict[str, str]) a dict of default vertex attributes
default_edge_attrs: (Dict[str, str]) a dict of default edge attributes
render_option: (str) this parameter decides how the pipeline graph is
rendered. See display.pipeline_graph_renderer for available options.


def getaccountaddress(self, user_id=''):
    address = self.rpc.call('getaccountaddress', user_id)
    self.logger.debug('Your', self.coin, 'address is', address)
    return address

Get the coin address associated with a user id.

If the specified user id does not yet have an address for this
coin, then generate one.

Args:
user_id (str): this user's unique identifier

Returns:
str: Base58Check address for this account


def init_from_dataset_and_submissions_write_to_datastore(
      self, dataset_batches, attack_submission_ids):

    batches_x_attacks = itertools.product(dataset_batches.data.keys(),
                                          attack_submission_ids)
    for idx, (dataset_batch_id, attack_id) in enumerate(batches_x_attacks):
      adv_batch_id = ADVERSARIAL_BATCH_ID_PATTERN.format(idx)
      self.add_batch(adv_batch_id,
                     {'dataset_batch_id': dataset_batch_id,
                      'submission_id': attack_id})
    self.write_to_datastore()

Init list of adversarial batches from dataset batches and submissions.

Args:
dataset_batches: instances of DatasetBatches
attack_submission_ids: iterable with IDs of all (targeted and nontargeted)
attack submissions, could be obtains as
CompetitionSubmissions.get_all_attack_ids()


def hasReservation(self, pid, subject, vendorSpecific=None):

        response = self.hasReservationResponse(pid, subject, vendorSpecific)
        return self._read_boolean_404_response(response)

See Also: hasReservationResponse()

Args:
pid:
subject:
vendorSpecific:

Returns:


def _init_summary_op(self, summary_op=USE_DEFAULT):
    if summary_op is Supervisor.USE_DEFAULT:
        summary_op = self._get_first_op_from_collection(ops.GraphKeys.SUMMARY_OP)
        if summary_op is None:
            summary_op = _summary.merge_all()
            if summary_op is not None:
                ops.add_to_collection(ops.GraphKeys.SUMMARY_OP, summary_op)
    self._summary_op = summary_op

Initializes summary_op.

Args:
summary_op: An Operation that returns a Summary for the event logs. If set
to USE_DEFAULT, create an op that merges all the summaries.


def ReadFrom(self, byte_stream):
    try:
        return self._struct.unpack_from(byte_stream)
    except (TypeError, struct.error) as exception:
        raise IOError('Unable to read byte stream with error: {0!s}'.format(exception))

Read values from a byte stream.

Args:
byte_stream (bytes): byte stream.

Returns:
tuple[object, ...]: values copies from the byte stream.

Raises:
IOError: if byte stream cannot be read.
OSError: if byte stream cannot be read.


def resume():
    t = timer()
    if f.t.stopped:
        raise StoppedError('Cannot resume stopped timer.')
    if (not f.t.paused):
        raise PausedError('Cannot resume timer that is not paused.')
    f.t.paused = False
    f.t.start_t = t
    f.t.last_t = t
    return t

Resume a paused timer, re-activating it.  Subsequent time accumulates in
the total.

Returns:
float: The current time.

Raises:
PausedError: If timer was not in paused state.
StoppedError: If timer was already stopped.


def _translate(pattern, case_sensitive=True):

    if not case_sensitive:
        pattern = pattern.lower()
    i, n = 0, len(pattern)
    res = ""
    while i < n:
        c = pattern[i]
        i = i + 1
        if c == "*":
            res = res + "[^/]*"
        elif c == "?":
            res = res + "."
        elif c == "[":
            j = i
            if j < n and pattern[j] == "!":
                j = j + 1
            if j < n and pattern[j] == "]":
                j = j + 1
            while j < n and pattern[j] != "]":
                j = j + 1
            if j >= n:
                res = res + "\\["
            else:
                stuff = pattern[i:j].replace("\\", "\\\\")
                i = j + 1
                if stuff[0] == "!":
                    stuff = "^" + stuff[1:]
                elif stuff[0] == "^":
                    stuff = "\\" + stuff
                res = "%s[%s]" % (res, stuff)
        else:
            res = res + re.escape(c)
    return res

Translate a wildcard pattern to a regular expression.

There is no way to quote meta-characters.

Arguments:
pattern (str): A wildcard pattern.
case_sensitive (bool): Set to `False` to use a case
insensitive regex (default `True`).

Returns:
str: A regex equivalent to the given pattern.


def dapply(self, fn, pairwise=False, symmetric=True, diagonal=False, block=None, **kwargs):

    search_keys = [k for k, v in kwargs.items() if isinstance(v, list) and len(v) > 1]
    functions = util.make_list(fn)
    search = list(product(functions, util.dict_product(kwargs)))

    results = []
    for fn, kw in search:
        if not pairwise:
            r = self.index.to_series().apply(lambda step: fn(step, **kw))
        else:
            r = apply_pairwise(self, fn,
                               symmetric=symmetric, diagonal=diagonal, block=block,
                               **kw)

        name = [] if len(functions) == 1 else [fn.__name__]
        name += util.dict_subset(kw, search_keys).values()

        if isinstance(r, pd.DataFrame):
            columns = pd.MultiIndex.from_tuples(
                    [tuple(name + util.make_list(c)) for c in r.columns])
            r.columns = columns
        else:
            r.name = tuple(name)
        results.append(r)

    if len(results) > 1:
        result = pd.concat(results, axis=1)

        column_names = [] if len(functions) == 1 else [None]
        column_names += search_keys
        column_names += [None]*(len(result.columns.names)-len(column_names))
        result.columns.names = column_names

        return StepFrame(result)
    else:
        result = results[0]
        if isinstance(result, pd.DataFrame):
            return StepFrame(result)
        else:
            result.name = functions[0].__name__
            return StepSeries(result)

Apply function to each step object in the index

Args:
fn: function to apply. If a list then each function is applied
pairwise: whether to apply the function to pairs of steps
symmetric, diagonal, block: passed to apply_pairwise when pairwise=True
kwargs: a keyword arguments to pass to each function. Arguments
with list value are grid searched using util.dict_product.

Returns: a StepFrame or StepSeries


def _validate_inputs(self, graph_def, input_tensors):
    self._save_conversion_params_metric(graph_def)
    self._quant_mode = QuantizationMode(self.optimizations, self.target_spec, self.representative_dataset, graph_def, self._experimental_disable_per_channel, self.experimental_new_dynamic_range_quantizer, self._experimental_low_bit_qat, self._experimental_full_integer_quantization_bias_type, self._experimental_variable_quantization, self._experimental_strict_qdq)
    self._validate_inference_input_output_types(self._quant_mode)
    if not self._is_unknown_shapes_allowed():
        for tensor in input_tensors:
            shape_list = tensor.shape.as_list()
            if None in shape_list[1:]:
                raise ValueError("None is only supported in the 1st dimension. Tensor '{0}' has invalid shape '{1}'.".format(_get_tensor_name(tensor), shape_list))
            elif shape_list and shape_list[0] is None:
                shape = tensor.shape.as_list()
                shape[0] = 1
                tensor.set_shape(shape)
    if self._trackable_obj is None or not hasattr(self._trackable_obj, 'graph_debug_info'):
        self._debug_info = _get_debug_info(_build_debug_info_func(self._funcs[0].graph), graph_def)
    else:
        self._debug_info = _get_debug_info(_convert_debug_info_func(self._trackable_obj.graph_debug_info), graph_def)

Validate the input parameters.

Args:
graph_def: The TensorFlow GraphDef.
input_tensors: List of input tensors.

Raise:
ValueError: Input shape is not specified. Invalid quantization parameters.


def size(input: ragged_tensor.Ragged, out_type=dtypes.int32, name=None):
    if ragged_tensor.is_ragged(input):
        return array_ops.size(input.flat_values, out_type=out_type, name=name)
    else:
        return array_ops.size(input, out_type=out_type, name=name)

Returns the size of a potentially ragged tensor.

The size of a ragged tensor is the size of its inner values.

#### Example:

>>> tf.size(tf.ragged.constant([[1, 2], [3]])).numpy().item()
3

Args:
input: A potentially ragged `Tensor`.
out_type: The numeric output type for the operation.
name: A name for the operation (optional).

Returns:
A Tensor of type `out_type`.


def __init__(self, meter_id=Meter.OFPM_ALL):

        super().__init__(InstructionType.OFPIT_METER)
        self.meter_id = meter_id

Create a InstructionMeter with the optional parameters below.

Args:
meter_id (int): Meter instance.


def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):

        super(RevocationReason, self).read(istream, kmip_version=kmip_version)
        tstream = BytearrayStream(istream.read(self.length))

        self.revocation_code = RevocationReasonCode()
        self.revocation_code.read(tstream, kmip_version=kmip_version)

        if self.is_tag_next(Tags.REVOCATION_MESSAGE, tstream):
            self.revocation_message = TextString()
            self.revocation_message.read(tstream, kmip_version=kmip_version)

        self.is_oversized(tstream)
        self.validate()

Read the data encoding the RevocationReason object and decode it
into its constituent parts.

Args:
istream (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.


def GetMessages(self, formatter_mediator, event):

    if self.DATA_TYPE != event.data_type:
      raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
          event.data_type))

    event_values = event.CopyToDict()

    event_type = event_values.get('event_type', None)
    if event_type is not None:
      event_values['event_type'] = self.GetEventTypeString(event_type)

    severity = event_values.get('severity', None)
    if severity is not None:
      event_values['severity'] = self.GetSeverityString(severity)

    source_name = event_values.get('source_name', None)
    message_identifier = event_values.get('message_identifier', None)
    strings = event_values.get('strings', [])
    if source_name and message_identifier:
      message_string = formatter_mediator.GetWindowsEventMessage(
          source_name, message_identifier)
      if message_string:
        try:
          event_values['message_string'] = message_string.format(*strings)
        except IndexError:

          pass

    message_strings = []
    for string in strings:
      message_strings.append('\'{0:s}\''.format(string))
    message_string = ', '.join(message_strings)
    event_values['strings'] = '[{0:s}]'.format(message_string)

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

Args:
formatter_mediator (FormatterMediator): mediates the interactions between
formatters and other components, such as storage and Windows EventLog
resources.
event (EventObject): event.

Returns:
tuple(str, str): formatted message string and short message string.

Raises:
WrongFormatter: if the event object cannot be formatted by the formatter.


def GetValueByPath(self, path_segments):
    key = self.root_key
    for path_segment in path_segments:
        if isinstance(key, dict):
            try:
                key = key[path_segment]
            except KeyError:
                return None
        elif isinstance(key, list):
            try:
                list_index = int(path_segment, 10)
            except ValueError:
                return None
            key = key[list_index]
        else:
            return None
        if (not key):
            return None
    return key

Retrieves a plist value by path.

Args:
path_segments (list[str]): path segment strings relative to the root
of the plist.

Returns:
object: The value of the key specified by the path or None.