def load_config_file(appdirs=DEFAULT_APPDIRS, file_name=DEFAULT_CONFIG_FILENAME, fallback_config_instance=None):
    if (not fallback_config_instance):
        fallback_config_instance = backend_config_to_configparser(get_default_backend_config(appdirs))
    config = SafeConfigParser()
    path = get_config_path(appdirs, file_name)
    if (not config.read(path)):
        config = write_config_file(fallback_config_instance, appdirs=appdirs, file_name=file_name)
    return config

Retrieve config information from file at default location.

If no config file is found a new one will be created either with ``fallback_config_instance``
as content or if none is provided with the result of ``get_default_backend_config``.

Args:
appdirs (HamsterAppDirs, optional): ``HamsterAppDirs`` instance storing app/user specific
path information.
file_name (text_type, optional): Name of the config file. Defaults to
``DEFAULT_CONFIG_FILENAME``.
fallback_config_instance (ConfigParser): Backend config that is to be used to populate the
config file that is created if no pre-existing one can be found.

Returns:
SafeConfigParser: Config loaded from file, either from the the  pre-existing config
file or the one created with fallback values.


def remove_regex(urls, regex):

    if not regex:
        return urls

    if not isinstance(urls, (list, set, tuple)):
        urls = [urls]

    try:
        non_matching_urls = [url for url in urls if not re.search(regex, url)]
    except TypeError:
        return []

    return non_matching_urls

Parse a list for non-matches to a regex.

Args:
urls: iterable of urls
regex: string regex to be parsed for

Returns:
list of strings not matching regex


def put_rpc(self, address, rpc_id, arg_payload, response):

        self._rpc_queue.put_nowait((address, rpc_id, arg_payload, response))

Place an RPC onto the RPC queue.

The rpc will be dispatched asynchronously by the background dispatch
task.  This method must be called from the event loop.  This method
does not block.

Args:
address (int): The address of the tile with the RPC
rpc_id (int): The id of the rpc you want to call
arg_payload (bytes): The RPC payload
respones (GenericResponse): The object to use to signal the result.


def _maybe_resolve_alias(alias, name_to_class, name_to_constant):
    if not isinstance(alias.type, pytd.NamedType):
        return alias
    if alias.type.name in _TYPING_SETS:
        return None
    if '.' not in alias.type.name:
        return alias
    parts = alias.type.name.split('.')
    if parts[0] not in name_to_class and parts[0] not in name_to_constant:
        return alias
    prev_value = None
    value = name_to_class.get(parts[0]) or name_to_constant[parts[0]]
    for part in parts[1:]:
        prev_value = value
        if isinstance(value, pytd.Constant):
            if not isinstance(value.type, pytd.NamedType) or value.type.name not in name_to_class:
                return alias
            value = name_to_class[value.type.name]
        if not isinstance(value, pytd.Class):
            return alias
        if part in value:
            value = value.Lookup(part)
        else:
            for base in value.bases:
                if base.name not in name_to_class:
                    return alias
                if part in name_to_class[base.name]:
                    value = name_to_class[base.name].Lookup(part)
                    break
            else:
                return alias
    if isinstance(value, pytd.Class):
        return pytd.Constant(alias.name, pytdgen.pytd_type(pytd.NamedType(alias.type.name)))
    elif isinstance(value, pytd.Function):
        return pytd.AliasMethod(value.Replace(name=alias.name), from_constant=isinstance(prev_value, pytd.Constant))
    else:
        return value.Replace(name=alias.name)

Resolve the alias if possible.

Args:
alias: A pytd.Alias
name_to_class: A class map used for resolution.
name_to_constant: A constant map used for resolution.

Returns:
None, if the alias pointed to an un-aliasable type.
The resolved value, if the alias was resolved.
The alias, if it was not resolved.


def exists(self, workflow_id):

        try:
            db = self._client[self.database]
            col = db[WORKFLOW_DATA_COLLECTION_NAME]
            return col.find_one({"_id": ObjectId(workflow_id)}) is not None

        except ConnectionFailure:
            raise DataStoreNotConnected()

Checks whether a document with the specified workflow id already exists.

Args:
workflow_id (str): The workflow id that should be checked.

Raises:
DataStoreNotConnected: If the data store is not connected to the server.

Returns:
bool: ``True`` if a document with the specified workflow id exists.


def print_gate(gate: Gate, ndigits: int = 2,
               file: TextIO = None) -> None:

    N = gate.qubit_nb
    gate_tensor = gate.vec.asarray()
    lines = []
    for index, amplitude in np.ndenumerate(gate_tensor):
        ket = "".join([str(n) for n in index[0:N]])
        bra = "".join([str(index[n]) for n in range(N, 2*N)])
        if round(abs(amplitude)**2, ndigits) > 0.0:
            lines.append('{} -> {} : {}'.format(bra, ket, amplitude))
    lines.sort(key=lambda x: int(x[0:N]))
    print('\n'.join(lines), file=file)

Pretty print a gate tensor

Args:
gate:
ndigits:
file: Stream to which to write. Defaults to stdout


def has_member(self, device_object):
    if (device_object.tag == 'computer'):
        container_search = 'computers/computer'
    elif (device_object.tag == 'mobile_device'):
        container_search = 'mobile_devices/mobile_device'
    else:
        raise ValueError
    return (len([device for device in self.findall(container_search) if (device.findtext('id') == device_object.id)]) is not 0)

Return bool whether group has a device as a member.

Args:
device_object (Computer or MobileDevice). Membership is
determined by ID, as names can be shared amongst devices.


def use_wrapped_call(layer, call_fn, default_training_value=None, return_method=False):
    expects_training_arg = layer_uses_training_bool(layer)
    if hasattr(call_fn, 'original_layer_call'):
        original_call = call_fn.original_layer_call
        call_fn = call_fn.__call__
    else:
        original_call = call_fn
    fn, arg_spec = maybe_add_training_arg(original_call, call_fn, expects_training_arg, default_training_value)

    def return_outputs_and_add_losses(*args, **kwargs):

        if return_method:
            args = args[1:]
        outputs, losses = fn(*args, **kwargs)
        layer.add_loss(losses, inputs=True)
        if context.executing_eagerly():
            for i in layer._flatten_layers():
                if i is not layer:
                    i._eager_losses = [base_layer_utils.REVIVED_LOSS_PLACEHOLDER]
        return outputs
    decorated = tf_decorator.make_decorator(target=call_fn, decorator_func=return_outputs_and_add_losses, decorator_argspec=arg_spec)
    if return_method:
        return types.MethodType(decorated, layer)
    else:
        return decorated

Creates fn that adds the losses returned by call_fn & returns the outputs.

Args:
layer: A Keras layer object
call_fn: tf.function that takes layer inputs (and possibly a training arg),
and returns a tuple of (outputs, list of losses).
default_training_value: Default value of the training kwarg. If `None`, the
default is `K.learning_phase()`.
return_method: Whether to return a method bound to the layer.

Returns:
function that calls call_fn and returns the outputs. Losses returned by
call_fn are added to the layer losses.


def convert_to_date_tensor(date_inputs):
    if isinstance(date_inputs, DateTensor):
        return date_inputs
    if hasattr(date_inputs, 'year'):
        return from_datetimes(date_inputs)
    if isinstance(date_inputs, np.ndarray):
        date_inputs = date_inputs.astype('datetime64[D]')
        return from_np_datetimes(date_inputs)
    if tf.is_tensor(date_inputs):
        return from_ordinals(date_inputs)
    if isinstance(date_inputs, collections.abc.Sequence):
        if not date_inputs:
            return from_ordinals([])
        test_element = date_inputs[0]
        if hasattr(test_element, 'year'):
            return from_datetimes(date_inputs)
        if isinstance(test_element, collections.abc.Sequence):
            return from_tuples(date_inputs)
        if len(date_inputs) == 3:
            return from_year_month_day(date_inputs[0], date_inputs[1], date_inputs[2])
    try:
        as_ordinals = tf.convert_to_tensor(date_inputs, dtype=tf.int32)
        return from_ordinals(as_ordinals)
    except ValueError as e:
        raise ValueError('Failed to convert inputs to DateTensor. Unrecognized format. Error: ' + e)

Converts supplied data to a `DateTensor` if possible.

Args:
date_inputs: One of the supported types that can be converted to a
DateTensor. The following input formats are supported. 1. Sequence of
`datetime.datetime`, `datetime.date`, or any other structure with data
attributes called 'year', 'month' and 'day'. 2. A numpy array of
`datetime64` type. 3. Sequence of (year, month, day) Tuples. Months are
1-based (with January as 1) and constants.Months enum may be used instead
of ints. Days are also 1-based. 4. A tuple of three int32 `Tensor`s
containing year, month and date as positive integers in that order. 5. A
single int32 `Tensor` containing ordinals (i.e. number of days since 31
Dec 0 with 1 being 1 Jan 1.)

Returns:
A `DateTensor` object representing the supplied dates.

Raises:
ValueError: If conversion fails for any reason.


def predict(self, x, add_intercept=False):

        if x.min() < self.start:
            raise Warning("x.min() < self.start")
        if x.max() > self.end:
            raise Warning("x.max() > self.end")

        return get_X_spline(x=x,
                            knots=self.knots,
                            n_bases=self.n_bases,
                            spline_order=self.spline_order,
                            add_intercept=add_intercept)

For some x, predict the bn(x) for each base

Arguments:
x: np.array; Vector of dimension 1
add_intercept: bool; should we add the intercept to the final array

Returns:
np.array, of shape (len(x), n_bases + (add_intercept))


def get_seqprop_within(self, chain_id, resnum, angstroms, only_protein=True, use_ca=False, custom_coord=None, return_resnums=False):
    (polypep, resnums) = self.get_polypeptide_within(chain_id=chain_id, resnum=resnum, angstroms=angstroms, use_ca=use_ca, only_protein=only_protein, custom_coord=custom_coord, return_resnums=True)
    chain_subseq = self.chains.get_by_id(chain_id).get_subsequence(resnums)
    if return_resnums:
        return (chain_subseq, resnums)
    else:
        return chain_subseq

Get a SeqProp object of the amino acids within X angstroms of the specified chain + residue number.

Args:
resnum (int): Residue number of the structure
chain_id (str): Chain ID of the residue number
angstroms (float): Radius of the search sphere
only_protein (bool): If only protein atoms (no HETATMS) should be included in the returned sequence
use_ca (bool): If the alpha-carbon atom should be used for searching, default is False (last atom of residue used)

Returns:
SeqProp: Sequence that represents the amino acids in the vicinity of your residue number.


def resolve_for(self, node, exact=None):

        from capybara.driver.node import Node
        from capybara.node.element import Element
        from capybara.node.simple import Simple

        @node.synchronize
        def resolve():
            if self.selector.format == "css":
                children = node._find_css(self.css())
            else:
                children = node._find_xpath(self.xpath(exact))

            def wrap(child):
                if isinstance(child, Node):
                    return Element(node.session, child, node, self)
                else:
                    return Simple(child)

            children = [wrap(child) for child in children]

            return Result(children, self)

        return resolve()

Resolves this query relative to the given node.

Args:
node (node.Base): The node relative to which this query should be resolved.
exact (bool, optional): Whether to exactly match text.

Returns:
list[Element]: A list of elements matched by this query.


def _string_from_ip_int(self, ip_int):

        octets = []
        for _ in xrange(4):
            octets.insert(0, str(ip_int & 0xFF))
            ip_int >>= 8
        return '.'.join(octets)

Turns a 32-bit integer into dotted decimal notation.

Args:
ip_int: An integer, the IP address.

Returns:
The IP address as a string in dotted decimal notation.


def get_event_q(self, event_name):
    self.lock.acquire()
    if ((not (event_name in self.event_dict)) or (self.event_dict[event_name] is None)):
        self.event_dict[event_name] = queue.Queue()
    self.lock.release()
    event_queue = self.event_dict[event_name]
    return event_queue

Obtain the queue storing events of the specified name.

If no event of this name has been polled, wait for one to.

Returns:
A queue storing all the events of the specified name.
None if timed out.

Raises:
queue.Empty: Raised if the queue does not exist and timeout has
passed.


def from_json(cls, data):
    optional_keys = {'wind_direction': 0, 'rain': False, 'snow_on_ground': False}
    assert ('wind_speed' in data), 'Required key "wind_speed" is missing!'
    for (key, val) in optional_keys.items():
        if (key not in data):
            data[key] = val
    return cls(data['wind_speed'], data['wind_direction'], data['rain'], data['snow_on_ground'])

Create a Wind Condition from a dictionary.

Args:
data = {
"wind_speed": float,
"wind_direction": float,
"rain": bool,
"snow_on_ground": bool}


def group_by(what, by):
    return proso.dict.group_keys_by_values({x: by(x) for x in what})

Take a list and apply the given function on each its value, then group the
values by the function results.

.. testsetup::

from proso.list import group_by

.. doctest::

>>> group_by([i for i in range(10)], by=lambda x: x % 2 == 0)
{False: [1, 3, 5, 7, 9], True: [0, 2, 4, 6, 8]}

Args:
what: a list which will be transformed
by: a function which will be applied on values of the given list

Returns:
dict: values groupped by the function results


def simple_two_objective_reward(example):
    num = int(example * 10) % 9 + 1
    return [num, 10 - num]

Reward for the trivial search space.

The reward (i.e. fitness) is a 2-element list. The goal of the search,
therefore, is to find the pareto frontier in simple_two_objective_pareto
function.

Args:
example: a materialized value.

Returns:
A 2-element list.


def __init__(
        self,
        batch_size=20,
        seq_len=10,
        min_pitch=24,
        max_pitch=108

    ):

        self.__batch_size = batch_size
        self.__seq_len = seq_len
        self.__dim = max_pitch - min_pitch

Init.

Args:
batch_size:         Batch size.
seq_len:            The length of sequneces.
The length corresponds to the number of `time` splited by `time_fraction`.

min_pitch:          The minimum of note number.
max_pitch:          The maximum of note number.


def isfile(self, path, follow_symlinks=True):
    return self._is_of_type(path, S_IFREG, follow_symlinks)

Determine if path identifies a regular file.

Args:
path: Path to filesystem object.

Returns:
`True` if path points to a regular file (following symlinks).

Raises:
TypeError: if path is None.


def do_decode(cls, obj, obj_type):
    if (inspect.isclass(obj_type) and issubclass(obj_type, ConjureBeanType)):
        return cls.decode_conjure_bean_type(obj, obj_type)
    elif (inspect.isclass(obj_type) and issubclass(obj_type, ConjureUnionType)):
        return cls.decode_conjure_union_type(obj, obj_type)
    elif (inspect.isclass(obj_type) and issubclass(obj_type, ConjureEnumType)):
        return cls.decode_conjure_enum_type(obj, obj_type)
    elif isinstance(obj_type, DictType):
        return cls.decode_dict(obj, obj_type.key_type, obj_type.value_type)
    elif isinstance(obj_type, ListType):
        return cls.decode_list(obj, obj_type.item_type)
    elif isinstance(obj_type, OptionalType):
        return cls.decode_optional(obj, obj_type.item_type)
    return cls.decode_primitive(obj, obj_type)

Decodes json into the specified type

Args:
obj: the json object to decode
element_type: a class object which is the type we're decoding into.


def prune_candidates(candidates):

    pruned = []

    for first, second in candidates:
        if first.__class__ is Linearization:
            nodes1 = first.curve.nodes
        else:
            nodes1 = first.nodes
        if second.__class__ is Linearization:
            nodes2 = second.curve.nodes
        else:
            nodes2 = second.nodes
        if convex_hull_collide(nodes1, nodes2):
            pruned.append((first, second))
    return pruned

Reduce number of candidate intersection pairs.

.. note::

This is a helper for :func:`_all_intersections`.

Uses more strict bounding box intersection predicate by forming the
actual convex hull of each candidate curve segment and then checking
if those convex hulls collide.

Args:
candidates (List): An iterable of pairs of curves (or
linearized curves).

Returns:
List: A pruned list of curve pairs.


def _tflearn_features(train_config, args):
    feature_columns = []
    target_name = train_config['target_column']
    key_name = train_config['key_column']
    for name in train_config['numerical_columns']:
        if ((name != target_name) and (name != key_name)):
            feature_columns.append(tf.contrib.layers.real_valued_column(name, dimension=1))
    for name in train_config['categorical_columns']:
        if ((name != target_name) and (name != key_name)):
            transform_config = train_config['transforms'].get(name, {})
            transform_name = transform_config.get('transform', None)
            if is_dnn_model(args.model_type):
                if (transform_name == 'embedding'):
                    sparse = tf.contrib.layers.sparse_column_with_integerized_feature(name, bucket_size=train_config['vocab_stats'][name]['n_classes'])
                    learn_feature = tf.contrib.layers.embedding_column(sparse, dimension=transform_config['embedding_dim'])
                elif ((transform_name == 'one_hot') or (transform_name is None)):
                    sparse = tf.contrib.layers.sparse_column_with_integerized_feature(name, bucket_size=train_config['vocab_stats'][name]['n_classes'])
                    learn_feature = tf.contrib.layers.one_hot_column(sparse)
                else:
                    raise ValueError(("Unknown transform name. Only 'embedding' and 'one_hot' transforms are supported. Got %s" % transform_name))
            elif is_linear_model(args.model_type):
                if ((transform_name == 'one_hot') or (transform_name is None)):
                    learn_feature = tf.contrib.layers.sparse_column_with_integerized_feature(name, bucket_size=train_config['vocab_stats'][name]['n_classes'])
                elif (transform_name == 'embedding'):
                    learn_feature = tf.contrib.layers.sparse_column_with_hash_bucket(name, hash_bucket_size=transform_config['embedding_dim'])
                else:
                    raise ValueError(("Unknown transform name. Only 'embedding' and 'one_hot' transforms are supported. Got %s" % transform_name))
            feature_columns.append(learn_feature)
    return feature_columns

Builds the tf.learn feature list.

All numerical features are just given real_valued_column because all the
preprocessing transformations are done in preprocess_input. Categoriacl
features are processed here depending if the vocab map (from string to int)
was applied in preprocess_input.

Args:
train_config: our train config object
args: command line args.

Returns:
List of TF lean feature columns.

Raises:
ValueError: if wrong transforms are used for the model type.


def for_all_test_methods(decorator, *args, **kwargs):

    def all_test_methods_impl(cls):

        for name in dir(cls):
            value = getattr(cls, name)
            if callable(value) and name.startswith('test') and (name != 'test_session'):
                setattr(cls, name, decorator(*args, **kwargs)(value))
        return cls
    return all_test_methods_impl

Generate class-level decorator from given method-level decorator.

It is expected for the given decorator to take some arguments and return
a method that is then called on the test method to produce a decorated
method.

Args:
decorator: The decorator to apply.
*args: Positional arguments
**kwargs: Keyword arguments
Returns: Function that will decorate a given classes test methods with the
decorator.


def decode(self, decoder_input_ids, encoder_outputs, encoder_attention_mask: Optional[jnp.ndarray]=None, decoder_attention_mask: Optional[jnp.ndarray]=None, decoder_position_ids: Optional[jnp.ndarray]=None, past_key_values: Optional[dict]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, train: bool=False, params: Optional[dict]=None, dropout_rng: PRNGKey=None):
    output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
    output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    return_dict = return_dict if return_dict is not None else self.config.return_dict
    encoder_hidden_states = encoder_outputs[0]
    if encoder_attention_mask is None:
        batch_size, sequence_length = encoder_hidden_states.shape[:2]
        encoder_attention_mask = jnp.ones((batch_size, sequence_length))
    batch_size, sequence_length = decoder_input_ids.shape
    if decoder_attention_mask is None:
        decoder_attention_mask = jnp.ones((batch_size, sequence_length))
    if decoder_position_ids is None:
        if past_key_values is not None:
            raise ValueError('Make sure to provide `decoder_position_ids` when passing `past_key_values`.')
        decoder_position_ids = jnp.broadcast_to(jnp.arange(sequence_length)[None, :], (batch_size, sequence_length))
    rngs = {}
    if dropout_rng is not None:
        rngs['dropout'] = dropout_rng
    params = {'params': params or self.params}
    if past_key_values:
        params['cache'] = past_key_values
        mutable = ['cache']
    else:
        mutable = False

    def _decoder_forward(module, decoder_input_ids, decoder_attention_mask, decoder_position_ids, encoder_hidden_states, **kwargs):
        projection_module = module._get_projection_module()
        decoder_module = module._get_decoder_module()
        if projection_module is not None:
            encoder_hidden_states = projection_module(encoder_hidden_states)
        return decoder_module(decoder_input_ids, decoder_attention_mask, decoder_position_ids, encoder_hidden_states=encoder_hidden_states, **kwargs)
    outputs = self.module.apply(params, decoder_input_ids=jnp.array(decoder_input_ids, dtype='i4'), decoder_attention_mask=jnp.array(decoder_attention_mask, dtype='i4'), decoder_position_ids=jnp.array(decoder_position_ids, dtype='i4'), encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=jnp.array(encoder_attention_mask, dtype='i4'), output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, deterministic=not train, rngs=rngs, mutable=mutable, method=_decoder_forward)
    if past_key_values is not None and return_dict:
        outputs, past = outputs
        outputs['past_key_values'] = unfreeze(past['cache'])
        return outputs
    elif past_key_values is not None and (not return_dict):
        outputs, past = outputs
        outputs = outputs[:1] + (unfreeze(past['cache']),) + outputs[1:]
    return outputs

Returns:

Example:

```python
>>> from transformers import FlaxSpeechEncoderDecoderModel
>>> import jax.numpy as jnp

>>> # initialize a wav2vec2-2-bart from pretrained wav2vec2 and bart models. Note that the cross-attention layers will be randomly initialized
>>> model = FlaxSpeechEncoderDecoderModel.from_encoder_decoder_pretrained(
...     "facebook/wav2vec2-large-lv60", "facebook/bart-large"
... )

>>> inputs = jnp.ones((2, 5000), dtype=jnp.float32)
>>> encoder_outputs = model.encode(inputs)

>>> decoder_start_token_id = model.config.decoder.bos_token_id
>>> decoder_input_ids = jnp.ones((inputs.shape[0], 1), dtype="i4") * decoder_start_token_id

>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
>>> logits = outputs.logits
```


def render_asset_html(self, path, tag_template):

        url = os.path.join(settings.STATIC_URL, path)

        return tag_template.format(url=url)

Render HTML tag for a given path.

Arguments:
path (string): Relative path from static directory.
tag_template (string): Template string for HTML tag.

Returns:
string: HTML tag with url from given path.


def create_sprite_image(examples):

    def generate_image_from_thubnails(thumbnails, thumbnail_dims):

      num_thumbnails = tf.shape(thumbnails)[0].eval()
      images_per_row = int(math.ceil(math.sqrt(num_thumbnails)))
      thumb_height = thumbnail_dims[0]
      thumb_width = thumbnail_dims[1]
      master_height = images_per_row * thumb_height
      master_width = images_per_row * thumb_width
      num_channels = 3
      master = np.zeros([master_height, master_width, num_channels])
      for idx, image in enumerate(thumbnails.eval()):
        left_idx = idx % images_per_row
        top_idx = int(math.floor(idx / images_per_row))
        left_start = left_idx * thumb_width
        left_end = left_start + thumb_width
        top_start = top_idx * thumb_height
        top_end = top_start + thumb_height
        master[top_start:top_end, left_start:left_end, :] = image
      return tf.image.encode_png(master)

    image_feature_name = 'image/encoded'
    sprite_thumbnail_dim_px = 32
    with tf.compat.v1.Session():
      keys_to_features = {
          image_feature_name:
              tf.FixedLenFeature((), tf.string, default_value=''),
      }
      parsed = tf.parse_example(examples, keys_to_features)
      images = tf.zeros([1, 1, 1, 1], tf.float32)
      i = tf.constant(0)
      thumbnail_dims = (sprite_thumbnail_dim_px,
                        sprite_thumbnail_dim_px)
      num_examples = tf.constant(len(examples))
      encoded_images = parsed[image_feature_name]

      def loop_body(i, encoded_images, images):
        encoded_image = encoded_images[i]
        image = tf.image.decode_jpeg(encoded_image, channels=3)
        resized_image = tf.image.resize(image, thumbnail_dims)
        expanded_image = tf.expand_dims(resized_image, 0)
        images = tf.cond(
            tf.equal(i, 0), lambda: expanded_image,
            lambda: tf.concat([images, expanded_image], 0))
        return i + 1, encoded_images, images

      loop_out = tf.while_loop(
          lambda i, encoded_images, images: tf.less(i, num_examples),
          loop_body, [i, encoded_images, images],
          shape_invariants=[
              i.get_shape(),
              encoded_images.get_shape(),
              tf.TensorShape(None)
          ])

      sprite = generate_image_from_thubnails(loop_out[2], thumbnail_dims)
      return sprite.eval()

Returns an encoded sprite image for use in Facets Dive.

Args:
examples: A list of serialized example protos to get images for.

Returns:
An encoded PNG.


def delete(self, rid, raise_on_error=True):

        return self.ds.delete(rid, raise_on_error)

Write cache data to the data store.

Args:
rid (str): The record identifier.
raise_on_error (bool): If True and not r.ok this method will raise a RunTimeError.

Returns:
object : Python request response.


def wrap_lines(self, text, indent_level, indent_size=4):
    indent = ((' ' * indent_size) * indent_level)
    lines = text.split('\n')
    wrapped_lines = []
    for line in lines:
        if (line == ''):
            wrapped_lines.append(line)
        else:
            wrapped_lines.append((indent + line))
    return '\n'.join(wrapped_lines)

Indent a multiline string

Args:
text (string): The string to indent
indent_level (int): The number of indent_size spaces to prepend
to each line
indent_size (int): The number of spaces to prepend for each indent
level

Returns:
string: The indented block of text


def concatenate(tup, axis=0):
    from distob import engine
    if (len(tup) is 0):
        raise ValueError('need at least one array to concatenate')
    first = tup[0]
    others = tup[1:]
    if (hasattr(first, 'concatenate') and hasattr(type(first), '__array_interface__')):
        return first.concatenate(others, axis)
    arrays = []
    for ar in tup:
        if isinstance(ar, DistArray):
            if (axis == ar._distaxis):
                arrays.extend(ar._subarrays)
            else:
                arrays.append(gather(ar))
        elif isinstance(ar, RemoteArray):
            arrays.append(ar)
        elif isinstance(ar, Remote):
            arrays.append(_remote_to_array(ar))
        elif hasattr(type(ar), '__array_interface__'):
            arrays.append(ar)
        else:
            arrays.append(np.array(ar))
    if all((isinstance(ar, np.ndarray) for ar in arrays)):
        return np.concatenate(arrays, axis)
    total_length = 0
    commonshape = list(arrays[0].shape)
    commonshape[axis] = None
    for ar in arrays:
        total_length += ar.shape[axis]
        shp = list(ar.shape)
        shp[axis] = None
        if (shp != commonshape):
            raise ValueError('incompatible shapes for concatenation')
    blocksize = (((total_length - 1)
    rarrays = []
    for ar in arrays:
        if isinstance(ar, DistArray):
            rarrays.extend(ar._subarrays)
        elif isinstance(ar, RemoteArray):
            rarrays.append(ar)
        else:
            da = _scatter_ndarray(ar, axis, blocksize)
            for ra in da._subarrays:
                rarrays.append(ra)
            del da
    del arrays
    eid = rarrays[0]._id.engine
    if all(((ra._id.engine == eid) for ra in rarrays)):
        if (eid == engine.eid):
            return concatenate([gather(r) for r in rarrays], axis)
        else:
            return call(concatenate, rarrays, axis)
    else:
        return DistArray(rarrays, axis)

Join a sequence of arrays together.
Will aim to join `ndarray`, `RemoteArray`, and `DistArray` without moving
their data, if they happen to be on different engines.

Args:
tup (sequence of array_like): Arrays to be concatenated. They must have
the same shape, except in the dimension corresponding to `axis`.
axis (int, optional): The axis along which the arrays will be joined.

Returns:
res: `ndarray`, if inputs were all local
`RemoteArray`, if inputs were all on the same remote engine
`DistArray`, if inputs were already scattered on different engines


def vmstats():
    spi = SYSTEM_PERFORMANCE_INFORMATION()
    retlen = ctypes.c_ulong()
    ctypes.windll.ntdll.NtQuerySystemInformation(2, ctypes.byref(spi), ctypes.sizeof(spi), ctypes.byref(retlen))
    ret = {}
    for field in spi._fields_:
        ret.update({field[0]: getattr(spi, field[0])})
    return ret

Return information about the virtual memory on the machine

Returns:
dict: A dictionary of virtual memory stats

CLI Example:

.. code-block:: bash

salt * status.vmstats


def logical_interconnect_groups(self):
    if (not self.__logical_interconnect_groups):
        self.__logical_interconnect_groups = LogicalInterconnectGroups(self.__connection)
    return self.__logical_interconnect_groups

Gets the LogicalInterconnectGroups API client.

Returns:
LogicalInterconnectGroups:


def info(self, show_defaults=False):
    pprinter = PrettyPrinter(show_options=True, show_defaults=show_defaults)
    print(pprinter.pprint(self._obj))

Prints a repr of the object including any applied options.

Args:
show_defaults: Whether to include default options


def __init__(self, elements=None):

        super(TermList, self).__init__()
        self._contents = set()
        try:
            for t in elements or []:
                super(TermList, self).append(t)
                self._contents.add(t.id)
        except AttributeError:
            raise TypeError('TermList can only contain Terms.')

Create a new `TermList`.

Arguments:
elements (collections.Iterable, optional): an Iterable
that yields `Term` objects.

Raises:
TypeError: when the given ``elements`` are not instances
of `Term`.


def set_card_simple(self, title, content):
    self.response.card.type = 'Simple'
    self.response.card.title = title
    self.response.card.content = content

Set response card as simple type.

title and content cannot exceed 8,000 characters.

Args:
title: str. Title of Simple or Standard type card.
content: str. Content of Simple type card.


def WriteFileHash(self, path, hash_value):
    string = '{0:s}\t{1:s}'.format(hash_value, path)
    encoded_string = self._EncodeString(string)
    print(encoded_string)

Writes the file path and hash to stdout.

Args:
path (str): path of the file.
hash_value (str): message digest hash calculated over the file data.


def start(self, use_atexit=True):

        assert not self._process

        _logger.debug('Starting process %s', self._proc_args)

        process_future = asyncio.create_subprocess_exec(
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            *self._proc_args
        )
        self._process = yield from process_future

        self._stderr_reader = asyncio.async(self._read_stderr())
        self._stdout_reader = asyncio.async(self._read_stdout())

        if use_atexit:
            atexit.register(self.close)

Start the executable.

Args:
use_atexit (bool): If True, the process will automatically be
terminated at exit.


def _checkBeginIndicesAnnotations(self, out, a):
    begin_line_num = 0
    while not out.lines[begin_line_num].startswith('array'):
        begin_line_num += 1
    element_index = 0
    for line_num in range(begin_line_num, len(out.lines)):
        line = out.lines[line_num]
        if '...' in line:
            raise ValueError('Unexpected found ellipses in line representing array')
        matches = re.finditer(self._ELEMENT_REGEX, line)
        for line_item_index, _ in enumerate(matches):
            subscripts = list(np.unravel_index(element_index, a.shape))
            if line_item_index == 0:
                self.assertEqual({tensor_format.BEGIN_INDICES_KEY: subscripts}, out.annotations[line_num])
            element_index += 1
    self.assertEqual(element_index, np.size(a))

Check the beginning-index annotations of an ndarray representation.

Args:
out: An instance of RichTextLines representing a numpy.ndarray.
a: The numpy.ndarray being represented.

Raises:
ValueError: if any ellipses ("...") are found in the lines representing
the array.


def add_datasets(self, datasets, datasets_to_check=None):
    if (datasets_to_check is None):
        datasets_to_check = self.get_datasets()
    alldatasetsadded = True
    for dataset in datasets:
        if (not self.add_dataset(dataset, datasets_to_check=datasets_to_check)):
            alldatasetsadded = False
    return alldatasetsadded

Add multiple datasets

Args:
datasets (List[Union[Dataset,Dict,str]]): A list of either dataset ids or dataset metadata from Dataset objects or dictionaries
datasets_to_check (List[Dataset]): List of datasets against which to check existence of dataset. Defaults to datasets in showcase.

Returns:
bool: True if all datasets added or False if any already present


def __init__(self, maximum_iterations=None, parallel_iterations=10, back_prop=True, swap_memory=False, name='while_context', grad_state=None, context_def=None, import_scope=None):
    if context_def:
        self._init_from_proto(context_def, import_scope=import_scope)
    else:
        ControlFlowContext.__init__(self)
        self._init_from_args(maximum_iterations, parallel_iterations, back_prop, swap_memory, name)
    self._grad_state = grad_state

"Creates a `WhileContext`.

Args:
maximum_iterations: Optional upper bound on number of loop iterations.
parallel_iterations: The number of iterations allowed to run in parallel.
back_prop: Whether backprop is enabled for this while loop.
swap_memory: Whether GPU-CPU memory swap is enabled for this loop.
name: Optional name prefix for the returned tensors.
grad_state: The gradient loop state.
context_def: Optional `WhileContextDef` protocol buffer to initialize the
`Whilecontext` python object from.
import_scope: Optional `string`. Name scope to add. Only used when
initialing from protocol buffer.


def GetPresetsByOperatingSystem(self, operating_system):
    preset_definitions = []
    for preset_definition in self._definitions.values():
        for preset_operating_system in preset_definition.operating_systems:
            if preset_operating_system.IsEquivalent(operating_system):
                preset_definitions.append(preset_definition)
    return preset_definitions

Retrieves preset definitions for a specific operating system.

Args:
operating_system (OperatingSystemArtifact): an operating system artifact
attribute container.

Returns:
list[PresetDefinition]: preset definition that correspond with the
operating system.


def zbar_function(fname, restype, *args):
    prototype = CFUNCTYPE(restype, *args)
    return prototype((fname, load_libzbar()))

Returns a foreign function exported by `zbar`.

Args:
fname (:obj:`str`): Name of the exported function as string.
restype (:obj:): Return type - one of the `ctypes` primitive C data
types.
*args: Arguments - a sequence of `ctypes` primitive C data types.

Returns:
cddl.CFunctionType: A wrapper around the function.


def __init__(self, file_path_prefix, coder, file_name_suffix='', num_shards=0, shard_name_template=None, mime_type='application/octet-stream', compression_type=CompressionTypes.AUTO, *, max_records_per_shard=None, max_bytes_per_shard=None, skip_if_empty=False):
    if not isinstance(file_path_prefix, (str, ValueProvider)):
        raise TypeError('file_path_prefix must be a string or ValueProvider;got %r instead' % file_path_prefix)
    if not isinstance(file_name_suffix, (str, ValueProvider)):
        raise TypeError('file_name_suffix must be a string or ValueProvider;got %r instead' % file_name_suffix)
    if not CompressionTypes.is_valid_compression_type(compression_type):
        raise TypeError('compression_type must be CompressionType object but was %s' % type(compression_type))
    if shard_name_template is None:
        shard_name_template = DEFAULT_SHARD_NAME_TEMPLATE
    elif shard_name_template == '':
        num_shards = 1
    if isinstance(file_path_prefix, str):
        file_path_prefix = StaticValueProvider(str, file_path_prefix)
    if isinstance(file_name_suffix, str):
        file_name_suffix = StaticValueProvider(str, file_name_suffix)
    self.file_path_prefix = file_path_prefix
    self.file_name_suffix = file_name_suffix
    self.num_shards = num_shards
    self.coder = coder
    self.shard_name_format = self._template_to_format(shard_name_template)
    self.shard_name_glob_format = self._template_to_glob_format(shard_name_template)
    self.compression_type = compression_type
    self.mime_type = mime_type
    self.max_records_per_shard = max_records_per_shard
    self.max_bytes_per_shard = max_bytes_per_shard
    self.skip_if_empty = skip_if_empty

Raises:
TypeError: if file path parameters are not a :class:`str` or
:class:`~apache_beam.options.value_provider.ValueProvider`, or if
**compression_type** is not member of
:class:`~apache_beam.io.filesystem.CompressionTypes`.
ValueError: if **shard_name_template** is not of expected
format.


def search(nasbench, search_model, algo, repeat_id, max_train_hours=5000000.0):
    nasbench.reset_budget_counters()
    times, best_valids, best_tests = ([0.0], [0.0], [0.0])
    valid_models = 0
    time_spent = 0
    start_time = time.time()
    last_report_time = start_time
    for model, feedback in pg.sample(search_model, algo, name=str(repeat_id)):
        spec = model()
        if nasbench.is_valid(spec):
            results = nasbench.query(spec)
            valid_models += 1
            feedback(results['validation_accuracy'])
            if results['validation_accuracy'] > best_valids[-1]:
                best_valids.append(results['validation_accuracy'])
                best_tests.append(results['test_accuracy'])
            else:
                best_valids.append(best_valids[-1])
                best_tests.append(best_tests[-1])
            time_spent, _ = nasbench.get_budget_counters()
            times.append(time_spent)
            if time_spent > max_train_hours:
                feedback.end_loop()
                break
        else:
            feedback.skip()
        if feedback.id % 100 == 0:
            now = time.time()
            print(f'Tried {feedback.id} models, valid {valid_models}, time_spent {time_spent}, elapse since last report: {now - last_report_time} seconds.')
            last_report_time = now
    print(f'Total time elapse: {time.time() - start_time} seconds.')
    return (times, best_valids, best_tests)

Define the search procedure.

Args:
nasbench: NASBench object.
search_model: which is a `model` object annotated with `oneof`.
algo: algorithm for search.
repeat_id: identifier of current repeat.
max_train_hours: max time budget to train the models, which is the sum
of training time queried from NAS-Bench.

Returns:
A tuple of (total time spent at step i for all steps,
best validation accuracy at step i for all steps,
best test accuracy at step i for all steps)


def ExtractEvents(self, parser_mediator, registry_key, **kwargs):

    event_data = windows_events.WindowsRegistryEventData()
    event_data.key_path = registry_key.path
    event_data.offset = registry_key.offset
    event_data.urls = self.URLS

    values_dict = {}
    for registry_value in registry_key.GetValues():
      value_name = registry_value.name or '(default)'

      if value_name == 'BootExecute':

        if registry_value.DataIsString():
          value_string = registry_value.GetDataAsObject()

        elif registry_value.DataIsMultiString():
          value_string = ''.join(registry_value.GetDataAsObject())

        elif registry_value.DataIsBinaryData():
          value_string = registry_value.GetDataAsObject()

        else:
          value_string = ''
          error_string = (
              'Key: {0:s}, value: {1:s}: unsupported value data type: '
              '{2:s}.').format(
                  registry_key.path, value_name,
                  registry_value.data_type_string)
          parser_mediator.ProduceExtractionWarning(error_string)

        event_data.regvalue = {'BootExecute': value_string}

        event = time_events.DateTimeValuesEvent(
            registry_key.last_written_time,
            definitions.TIME_DESCRIPTION_WRITTEN)
        parser_mediator.ProduceEventWithEventData(event, event_data)

      else:
        values_dict[value_name] = registry_value.GetDataAsObject()

    event_data.regvalue = values_dict

    event = time_events.DateTimeValuesEvent(
        registry_key.last_written_time, definitions.TIME_DESCRIPTION_WRITTEN)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts events from a Windows Registry key.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.


def GetOutputClass(cls, name):
    if (not isinstance(name, py2to3.STRING_TYPES)):
        raise ValueError('Name attribute is not a string.')
    name = name.lower()
    if (name not in cls._output_classes):
        raise KeyError('Name: [{0:s}] not registered as an output module.'.format(name))
    return cls._output_classes[name]

Retrieves the output class for a specific name.

Args:
name (str): name of the output module.

Returns:
type: output module class.

Raises:
KeyError: if there is no output class found with the supplied name.
ValueError: if name is not a string.


def poly_to_power_basis(bezier_coeffs):
    (num_coeffs,) = bezier_coeffs.shape
    if (num_coeffs == 1):
        return bezier_coeffs
    elif (num_coeffs == 2):
        (coeff0, coeff1) = bezier_coeffs
        return np.asfortranarray([coeff0, (coeff1 - coeff0)])
    elif (num_coeffs == 3):
        (coeff0, coeff1, coeff2) = bezier_coeffs
        return np.asfortranarray([coeff0, (2.0 * (coeff1 - coeff0)), ((coeff2 - (2.0 * coeff1)) + coeff0)])
    elif (num_coeffs == 4):
        (coeff0, coeff1, coeff2, coeff3) = bezier_coeffs
        return np.asfortranarray([coeff0, (3.0 * (coeff1 - coeff0)), (3.0 * ((coeff2 - (2.0 * coeff1)) + coeff0)), (((coeff3 - (3.0 * coeff2)) + (3.0 * coeff1)) - coeff0)])
    else:
        raise _helpers.UnsupportedDegree((num_coeffs - 1), supported=(0, 1, 2, 3))

Convert a B |eacute| zier curve to polynomial in power basis.

.. note::

This assumes, but does not verify, that the "B |eacute| zier
degree" matches the true degree of the curve. Callers can
guarantee this by calling :func:`.full_reduce`.

Args:
bezier_coeffs (numpy.ndarray): A 1D array of coefficients in
the Bernstein basis.

Returns:
numpy.ndarray: 1D array of coefficients in monomial basis.

Raises:
.UnsupportedDegree: If the degree of the curve is not among
0, 1, 2 or 3.


def SCM(root_dir, repo=None):
    if (Git.is_repo(root_dir) or Git.is_submodule(root_dir)):
        return Git(root_dir, repo=repo)
    return NoSCM(root_dir, repo=repo)

Returns SCM instance that corresponds to a repo at the specified
path.

Args:
root_dir (str): path to a root directory of the repo.
repo (dvc.repo.Repo): dvc repo instance that root_dir belongs to.

Returns:
dvc.scm.base.Base: SCM instance.


def _clone_functional_model(model, input_tensors=None, layer_fn=_clone_layer):
    if not isinstance(model, Model):
        raise ValueError('Expected `model` argument to be a `Model` instance, got ', model)
    if isinstance(model, Sequential):
        raise ValueError('Expected `model` argument to be a functional `Model` instance, got a `Sequential` instance instead:', model)
    if not model._is_graph_network:
        raise ValueError('Expected `model` argument to be a functional `Model` instance, but got a subclass model instead.')
    new_input_layers = {}
    if input_tensors is not None:
        input_tensors = nest.flatten(input_tensors)
        for i, input_tensor in enumerate(input_tensors):
            original_input_layer = model._input_layers[i]
            if not backend.is_keras_tensor(input_tensor):
                name = original_input_layer.name
                input_tensor = Input(tensor=input_tensor, name='input_wrapper_for_' + name)
                newly_created_input_layer = input_tensor._keras_history.layer
                new_input_layers[original_input_layer] = newly_created_input_layer
            else:
                new_input_layers[original_input_layer] = original_input_layer
    if not callable(layer_fn):
        raise ValueError('Expected `layer_fn` argument to be a callable.')
    model_configs, created_layers = _clone_layers_and_model_config(model, new_input_layers, layer_fn)
    input_tensors, output_tensors, created_layers = functional.reconstruct_from_config(model_configs, created_layers=created_layers)
    metrics_names = model.metrics_names
    model = Model(input_tensors, output_tensors, name=model.name)
    ancillary_layers = [layer for layer in created_layers.values() if layer not in model.layers]
    if ancillary_layers:
        new_nodes = nest.flatten([layer.inbound_nodes[1:] if functional._should_skip_first_node(layer) else layer.inbound_nodes for layer in created_layers.values()])
        _insert_ancillary_layers(model, ancillary_layers, metrics_names, new_nodes)
    return model

Clone a functional `Model` instance.

Model cloning is similar to calling a model on new inputs,
except that it creates new layers (and thus new weights) instead
of sharing the weights of the existing layers.

Input layers are always cloned.

Args:
model: Instance of `Model`.
input_tensors: optional list of input tensors
to build the model upon. If not provided,
placeholders will be created.
layer_fn: callable to be applied on non-input layers in the model. By
default it clones the layer. Another example is to preserve the layer
to share the weights. This is required when we create a per-replica
copy of the model with distribution strategy; we want the weights to
be shared but still feed inputs separately so we create new input
layers.

Returns:
An instance of `Model` reproducing the behavior
of the original model, on top of new inputs tensors,
using newly instantiated weights.

Raises:
ValueError: in case of invalid `model` argument value or `layer_fn`
argument value.


def wait_idle(self, timeout=1.0):

    async def _awaiter():
        background_work = {x.join() for x in self._work_queues}
        for event in self._events:
            if (not event.is_set()):
                background_work.add(event.wait())
        (_done, pending) = (await asyncio.wait(background_work, timeout=timeout))
        if (len(pending) > 0):
            raise TimeoutExpiredError('Timeout waiting for event loop to become idle', pending=pending)
    if self._on_emulation_thread():
        return asyncio.wait_for(_awaiter(), timeout=timeout)
    self.run_task_external(_awaiter())
    return None

Wait until the rpc queue is empty.

This method may be called either from within the event loop or from
outside of it.  If it is called outside of the event loop it will
block the calling thread until the rpc queue is temporarily empty.

If it is called from within the event loop it will return an awaitable
object that can be used to wait for the same condition.

The awaitable object will already have a timeout if the timeout
parameter is passed.

Args:
timeout (float): The maximum number of seconds to wait.


def reactions_to_files(model, dest, writer, split_subsystem):

    def safe_file_name(origin_name):
        safe_name = re.sub('\\W+', '_', origin_name, flags=re.UNICODE)
        safe_name = re.sub('_+', '_', safe_name.lower(), flags=re.UNICODE)
        safe_name = safe_name.strip('_')
        return safe_name
    common_reactions = []
    reaction_files = []
    if (not split_subsystem):
        common_reactions = sorted(model.reactions, key=(lambda r: r.id))
        if (len(common_reactions) > 0):
            reaction_file = 'reactions.yaml'
            with open(os.path.join(dest, reaction_file), 'w') as f:
                writer.write_reactions(f, common_reactions)
            reaction_files.append(reaction_file)
    else:
        subsystems = {}
        for reaction in sorted(model.reactions, key=(lambda r: r.id)):
            if ('subsystem' in reaction.properties):
                subsystem_file = safe_file_name(reaction.properties['subsystem'])
                subsystems.setdefault(subsystem_file, []).append(reaction)
            else:
                common_reactions.append(reaction)
        subsystem_folder = 'reactions'
        sub_existance = False
        for (subsystem_file, reactions) in iteritems(subsystems):
            if (len(reactions) < _MAX_REACTION_COUNT):
                for reaction in reactions:
                    common_reactions.append(reaction)
            elif (len(reactions) > 0):
                mkdir_p(os.path.join(dest, subsystem_folder))
                subsystem_file = os.path.join(subsystem_folder, '{}.yaml'.format(subsystem_file))
                with open(os.path.join(dest, subsystem_file), 'w') as f:
                    writer.write_reactions(f, reactions)
                reaction_files.append(subsystem_file)
                sub_existance = True
        reaction_files.sort()
        if sub_existance:
            reaction_file = os.path.join(subsystem_folder, 'other_reactions.yaml')
        else:
            reaction_file = 'reactions.yaml'
        if (len(common_reactions) > 0):
            with open(os.path.join(dest, reaction_file), 'w') as f:
                writer.write_reactions(f, common_reactions)
            reaction_files.append(reaction_file)
    return reaction_files

Turn the reaction subsystems into their own files.

If a subsystem has a number of reactions over the threshold, it gets its
own YAML file. All other reactions, those that don't have a subsystem or
are in a subsystem that falls below the threshold, get added to a common
reaction file.

Args:
model: :class:`psamm_import.model.MetabolicModel`.
dest: output path for model files.
writer: :class:`psamm.datasource.native.ModelWriter`.
split_subsystem: Divide reactions into multiple files by subsystem.


def expand_valid_values(valid_values):
    if ('${GROUP_TYPES}' in valid_values):
        valid_values.remove('${GROUP_TYPES}')
        valid_values.extend(['Adversary', 'Campaign', 'Document', 'Email', 'Event', 'Incident', 'Intrusion Set', 'Signature', 'Task', 'Threat'])
    elif ('${OWNERS}' in valid_values):
        valid_values.remove('${OWNERS}')
        valid_values.append('')
    elif ('${USERS}' in valid_values):
        valid_values.remove('${USERS}')
        valid_values.append('')
    return valid_values

Expand supported playbook variables to their full list.

Args:
valid_values (list): The list of valid values for Choice or MultiChoice inputs.

Returns:
List: An expanded list of valid values for Choice or MultiChoice inputs.


def AddContract(self, contract):
    if (not (contract.PublicKeyHash.ToBytes() in self._keys.keys())):
        raise Exception('Invalid operation - public key mismatch')
    self._contracts[contract.ScriptHash.ToBytes()] = contract
    if (contract.ScriptHash in self._watch_only):
        self._watch_only.remove(contract.ScriptHash)

Add a contract to the wallet.

Args:
contract (Contract): a contract of type neo.SmartContract.Contract.

Raises:
Exception: Invalid operation - public key mismatch.


def global_norm(t_list, name=None):
    if not isinstance(t_list, collections_abc.Sequence) or isinstance(t_list, str):
        raise TypeError(f'`t_list` should be a sequence of tensors. Received {type(t_list)}.')
    t_list = list(t_list)
    with ops.name_scope(name, 'global_norm', t_list) as name:
        values = [ops.convert_to_tensor(t.values if isinstance(t, indexed_slices.IndexedSlices) else t, name='t_%d' % i) if t is not None else t for i, t in enumerate(t_list)]
        half_squared_norms = []
        for v in values:
            if v is not None:
                with ops.colocate_with(v):
                    half_squared_norms.append(gen_nn_ops.l2_loss(v))
        half_squared_norm = math_ops.reduce_sum(array_ops_stack.stack(half_squared_norms))
        norm = math_ops.sqrt(half_squared_norm * constant_op.constant(2.0, dtype=half_squared_norm.dtype), name='global_norm')
    return norm

Computes the global norm of multiple tensors.

Given a tuple or list of tensors `t_list`, this operation returns the
global norm of the elements in all tensors in `t_list`. The global norm is
computed as:

`global_norm = sqrt(sum([l2norm(t)**2 for t in t_list]))`

Any entries in `t_list` that are of type None are ignored.

Args:
t_list: A tuple or list of mixed `Tensors`, `IndexedSlices`, or None.
name: A name for the operation (optional).

Returns:
A 0-D (scalar) `Tensor` of type `float`.

Raises:
TypeError: If `t_list` is not a sequence.


def stage_in(self, file, executor):
    if (file.scheme == 'ftp'):
        working_dir = self.dfk.executors[executor].working_dir
        stage_in_app = self._ftp_stage_in_app(executor=executor)
        app_fut = stage_in_app(working_dir, outputs=[file])
        return app_fut._outputs[0]
    elif ((file.scheme == 'http') or (file.scheme == 'https')):
        working_dir = self.dfk.executors[executor].working_dir
        stage_in_app = self._http_stage_in_app(executor=executor)
        app_fut = stage_in_app(working_dir, outputs=[file])
        return app_fut._outputs[0]
    elif (file.scheme == 'globus'):
        globus_ep = self._get_globus_endpoint(executor)
        stage_in_app = self._globus_stage_in_app()
        app_fut = stage_in_app(globus_ep, outputs=[file])
        return app_fut._outputs[0]
    else:
        raise Exception('Staging in with unknown file scheme {} is not supported'.format(file.scheme))

Transport the file from the input source to the executor.

This function returns a DataFuture.

Args:
- self
- file (File) : file to stage in
- executor (str) : an executor the file is going to be staged in to.
If the executor argument is not specified for a file
with 'globus' scheme, the file will be staged in to
the first executor with the "globus" key in a config.


def get_added_vocab(self) -> dict[str, int]:
    return {k.content: v for v, k in sorted(self.added_tokens_decoder.items(), key=lambda item: item[0])}

Returns the added tokens in the vocabulary as a dictionary of token to index.

Returns:
`Dict[str, int]`: The added tokens.


def DEFINE_alias(name, original_name, flag_values=FLAGS, module_name=None):

  if original_name not in flag_values:
    raise UnrecognizedFlagError(original_name)
  flag = flag_values[original_name]

  class _Parser(ArgumentParser):

    def parse(self, argument):
      flag.parse(argument)
      return flag.value

  class _FlagAlias(Flag):

    @property
    def value(self):
      return flag.value

    @value.setter
    def value(self, value):
      flag.value = value

  help_msg = 'Alias for --%s.' % flag.name

  DEFINE_flag(_FlagAlias(_Parser(), flag.serializer, name, flag.default,
                         help_msg, boolean=flag.boolean),
              flag_values, module_name)

Defines an alias flag for an existing one.

Args:
name: A string, name of the alias flag.
original_name: A string, name of the original flag.
flag_values: FlagValues object with which the flag will be registered.
module_name: A string, the name of the module that defines this flag.

Raises:
gflags.FlagError:
UnrecognizedFlagError: if the referenced flag doesn't exist.
DuplicateFlagError: if the alias name has been used by some existing flag.


def save(self, savefile):

        with open(str(savefile), 'wb') as f:
            self.write_to_fp(f)
            log.debug("Saved to %s", savefile)

Do the TTS API request and write result to file.

Args:
savefile (string): The path and file name to save the ``mp3`` to.

Raises:
:class:`gTTSError`: When there's an error with the API request.


def min_rank(series, ascending=True):

    ranks = series.rank(method='min', ascending=ascending)
    return ranks

Equivalent to `series.rank(method='min', ascending=ascending)`.

Args:
series: column to rank.

Kwargs:
ascending (bool): whether to rank in ascending order (default is `True`).


def compute_eos_token_mask(self, input_ids: torch.LongTensor, eos_token_id: int) -> torch.LongTensor:
    self._check_input_ids_shape(input_ids)
    noneos_masks = []
    all_eos_equated = input_ids == eos_token_id
    for eos_equated in all_eos_equated:
        nonzero_idx = torch.nonzero(eos_equated)
        noneos_mask = torch.ones_like(eos_equated)
        if nonzero_idx.shape[0] != 0:
            noneos_mask[nonzero_idx[0][0]:] = 0
        noneos_masks.append(noneos_mask)
    return torch.stack(noneos_masks, dim=0)

Computes repetitions mask.

1 stands for ngrams that don't contain EOS tokens and vice versa.

Args:
input_ids (`torch.LongTensor`):
Input token ids (batch_size, input_len).
eos_token_id (`int`):
EOS token ID.

Returns:
EOS token mask (batch_size, input_len).


def ucast_ip_mask(ip_addr_and_mask, return_tuple=True):

    regex_ucast_ip_and_mask = __re.compile("^((22[0-3])|(2[0-1][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))/((3[0-2])|([1-2]?[0-9]))$")
    if return_tuple:
        while not regex_ucast_ip_and_mask.match(ip_addr_and_mask):
            print("Not a good unicast IP and CIDR mask combo.")
            print("Please try again.")
            ip_addr_and_mask = input("Please enter a unicast IP address and mask in the follwing format x.x.x.x/x: ")
        ip_cidr_split = ip_addr_and_mask.split("/")
        ip_addr = ip_cidr_split[0]
        cidr = ip_cidr_split[1]
        return ip_addr, cidr
    elif not return_tuple:
        if not regex_ucast_ip_and_mask.match(ip_addr_and_mask):
            return False
        else:
            return True

Function to check if a address is unicast and that the CIDR mask is good
Args:
ip_addr_and_mask: Unicast IP address and mask in the following format 192.168.1.1/24
return_tuple: Set to True it returns a IP and mask in a tuple, set to False returns True or False

Returns: see return_tuple for return options


def _get_annotations(self, text, language=''):
    body = {'document': {'type': 'PLAIN_TEXT', 'content': text}, 'features': {'extract_syntax': True}, 'encodingType': 'UTF32'}
    if language:
        body['document']['language'] = language
    request = self.service.documents().annotateText(body=body)
    response = request.execute()
    tokens = response.get('tokens', [])
    language = response.get('language')
    return {'tokens': tokens, 'language': language}

Returns the list of annotations retrieved from the given text.

Args:
text (str): Input text.
language (:obj:`str`, optional): Language code.

Returns:
Results in a dictionary. :code:`tokens` contains the list of annotations
and :code:`language` contains the inferred language from the input.


def connect_direct(self, connection_string, no_rpc=False, force=False):
    if ((not force) and self.connected):
        raise HardwareError(("Cannot connect when we are already connected to '%s'" % self.connection_string))
    self._loop.run_coroutine(self.adapter.connect(0, connection_string))
    try:
        if no_rpc:
            self._logger.info('Not opening RPC interface on device %s', self.connection_string)
        else:
            self._loop.run_coroutine(self.adapter.open_interface(0, 'rpc'))
    except HardwareError as exc:
        self._logger.exception('Error opening RPC interface on device %s', connection_string)
        self._loop.run_coroutine(self.adapter.disconnect(0))
        raise exc
    except Exception as exc:
        self._logger.exception('Error opening RPC interface on device %s', connection_string)
        self._loop.run_coroutine(self.adapter.disconnect(0))
        raise HardwareError(('Could not open RPC interface on device due to an exception: %s' % str(exc))) from exc
    self.connected = True
    self.connection_string = connection_string
    self.connection_interrupted = False

Directly connect to a device using its stream specific connection string.

Normally, all connections to a device include opening the RPC
interface to send RPCs.  However, there are certain, very specific,
circumstances when you would not want to or be able to open the RPC
interface (such as when you are using the debug interface on a bare
MCU that has not been programmed yet).  In those cases you can pass
no_rpc=True to not attempt to open the RPC interface.  If you do not
open the RPC interface at connection time, there is no public
interface to open it later, so you must disconnect and reconnect to
the device in order to open the interface.

Args:
connection_string (str): The connection string that identifies the desired device.
no_rpc (bool): Do not open the RPC interface on the device (default=False).
force (bool): Whether to force another connection even if we think we are currently
connected.  This is for internal use and not designed to be set externally.


def _parse_exe_version_string(version_str):
    matcher = re.search('Python (\\d+\\.\\d+)\\.\\d+', version_str)
    if matcher:
        return utils.version_from_string(matcher.group(1))
    else:
        return None

Parse the version string of a Python executable.

Arguments:
version_str: Version string as emitted by running `PYTHON_EXE -V`

Returns:
Version as (major, minor) tuple, or None if it could not be determined.


def load(self, profile_args):

        for key, value in profile_args.items():
            self.add(key, value)

Load provided CLI Args.

Args:
args (dict): Dictionary of args in key/value format.


def highway_core_with_recurrent_dropout(hidden_size, num_layers, keep_prob=0.5, **kwargs):
    core = HighwayCore(hidden_size, num_layers, **kwargs)
    return (RecurrentDropoutWrapper(core, keep_prob), core)

Highway core with recurrent dropout.

Args:
hidden_size: (int) Hidden size dimensionality.
num_layers: (int) Number of highway layers.
keep_prob: the probability to keep an entry when applying dropout.
**kwargs: Extra keyword arguments to pass to the highway core.

Returns:
A tuple (train_core, test_core) where train_core is a higway core with
recurrent dropout enabled to be used for training and test_core is the
same highway core without recurrent dropout.


def __init__(self, name, annotation):

        self._name = name
        self._annotation = annotation

Initializer.

Args:
name: the name of the bound arg
annotation: an Annotation


def _has_extras(ctx):

    if not ctx.index.entries:
        return False

    return ctx.data_offset > 8 and ctx.data_offset > (ctx.signatures.offset_end + 8)

Determine if a MAR file has an additional section block or not.

It does this by looking at where file data starts in the file. If this
starts immediately after the signature data, then no additional sections are present.

Args:
ctx (context): construct parsing context

Returns:
True if the MAR file has an additional section block
False otherwise


def extract(self, text: str) -> List[Extraction]:

        doc = self._parser(text)

        extractions = list()
        for sent in doc.sents:
            this_extraction = Extraction(value=sent.text,
                                         extractor_name=self.name,
                                         start_token=sent[0],
                                         end_token=sent[-1],
                                         start_char=sent.text[0],
                                         end_char=sent.text[-1])
            extractions.append(this_extraction)

        return extractions

Splits text by sentences.

Args:
text (str): Input text to be extracted.

Returns:
List[Extraction]: the list of extraction or the empty list if there are no matches.


def __init__(self, issues = None):

		self._issues = []
		self._config = {}
		self._project = None
		self.issues = issues

Class constructor.

Args:
issues (list): List of `Issue` instances


def compute_delta(deps: List[str], imports: List[str], rule_dir: str, source_to_rules: SourceToRule, rule_name: str) -> Optional[DepsDelta]:
    issues = []
    adds = set()
    subs = set()
    expanded_deps = set([expand_dep(dep, rule_dir) for dep in deps])
    used_deps = set()
    for imp in imports:
        imp_items = tuple(imp.split('.'))
        if imp_items[0] in BUILT_IN_MODULES or imp in BUILT_IN_MODULES:
            continue
        possible_srcs = list_possible_source_of_import(imp_items)
        matching_possible_src = None
        for possible_src in possible_srcs:
            if possible_src in source_to_rules:
                matching_possible_src = possible_src
                break
        if matching_possible_src is None:
            issues.append(f'Cannot infer dependency for "{imp}". Possible source files: {possible_srcs}.')
            continue
        possible_deps = source_to_rules[matching_possible_src]
        if len(possible_deps) > 1:
            issues.append(f'Multiple possible rules for "{imp}"')
        if possible_deps[0] == expand_dep(':' + rule_name, rule_dir):
            continue
        if possible_deps[0] not in expanded_deps:
            adds.add(possible_deps[0])
        else:
            used_deps.add(possible_deps[0])
    for dep in expanded_deps:
        if dep in used_deps:
            continue
        subs.add(dep)
    if adds or subs or issues:
        return DepsDelta(adds=list(adds), subs=list(subs), issues=issues)
    else:
        return None

Computes the operation on the deps to support all the imports.

Args:
deps: Dependencies of the rule.
imports: Imports of the rule.
rule_dir: Path of the rule relative to the repo root.
source_to_rules: Mapping from all available source files to rules.


def add(name, **kwargs):

    if not info(name):
        comp_obj = _get_computer_object()
        try:
            new_group = comp_obj.Create('group', name)
            new_group.SetInfo()
            log.info('Successfully created group %s', name)
        except pywintypes.com_error as exc:
            msg = 'Failed to create group {0}. {1}'.format(
                name, win32api.FormatMessage(exc.excepinfo[5]))
            log.error(msg)
            return False
    else:
        log.warning('The group %s already exists.', name)
        return False
    return True

Add the specified group

Args:

name (str):
The name of the group to add

Returns:
bool: ``True`` if successful, otherwise ``False``

CLI Example:

.. code-block:: bash

salt '*' group.add foo


def get_class_attributes(cls):
    for (name, value) in cls.__dict__.items():
        if GenericStruct._is_pyof_attribute(value):
            (yield (name, value))

Return a generator for class attributes' names and value.

This method strict relies on the PEP 520 (Preserving Class Attribute
Definition Order), implemented on Python 3.6. So, if this behaviour
changes this whole lib can loose its functionality (since the
attributes order are a strong requirement.) For the same reason, this
lib will not work on python versions earlier than 3.6.

.. code-block:: python3

for name, value in self.get_class_attributes():
print("attribute name: {}".format(name))
print("attribute type: {}".format(value))

Returns:
generator: tuples with attribute name and value.


def inference(self, observed_arr):

        if observed_arr.ndim < 4:

            observed_arr = np.expand_dims(observed_arr, axis=1)
            self.__add_channel_flag = True
        else:
            self.__add_channel_flag = False

        return super().inference(observed_arr)

Draws samples from the `true` distribution.

Args:
observed_arr:     `np.ndarray` of observed data points.

Returns:
`np.ndarray` of inferenced.


def stop_dag(self, name=None):
    return self._client.send(Request(action='stop_dag', payload={'name': (name if (name is not None) else self._dag_name)})).success

Send a stop signal to the specified dag or the dag that hosts this task.

Args:
name str: The name of the dag that should be stopped. If no name is given the
dag that hosts this task is stopped.

Upon receiving the stop signal, the dag will not queue any new tasks and wait
for running tasks to terminate.

Returns:
bool: True if the signal was sent successfully.


def PrintResponse(batch_job_helper, response_xml):

  response = batch_job_helper.ParseResponse(response_xml)

  if 'rval' in response['mutateResponse']:
    for data in response['mutateResponse']['rval']:
      if 'errorList' in data:
        print 'Operation %s - FAILURE:' % data['index']
        print '\terrorType=%s' % data['errorList']['errors']['ApiError.Type']
        print '\ttrigger=%s' % data['errorList']['errors']['trigger']
        print '\terrorString=%s' % data['errorList']['errors']['errorString']
        print '\tfieldPath=%s' % data['errorList']['errors']['fieldPath']
        print '\treason=%s' % data['errorList']['errors']['reason']
      if 'result' in data:
        print 'Operation %s - SUCCESS.' % data['index']

Prints the BatchJobService response.

Args:
batch_job_helper: a BatchJobHelper instance.
response_xml: a string containing a response from the BatchJobService.


def compute_match(mapping, weight_dict):

    if veryVerbose:
        print("Computing match for mapping", file=DEBUG_LOG)
        print(mapping, file=DEBUG_LOG)
    if tuple(mapping) in match_triple_dict:
        if veryVerbose:
            print("saved value", match_triple_dict[tuple(mapping)], file=DEBUG_LOG)
        return match_triple_dict[tuple(mapping)]
    match_num = 0

    for i, m in enumerate(mapping):
        if m == -1:

            continue

        current_node_pair = (i, m)
        if current_node_pair not in weight_dict:
            continue
        if veryVerbose:
            print("node_pair", current_node_pair, file=DEBUG_LOG)
        for key in weight_dict[current_node_pair]:
            if key == -1:

                match_num += weight_dict[current_node_pair][key]
                if veryVerbose:
                    print("instance/attribute match", weight_dict[current_node_pair][key], file=DEBUG_LOG)

            elif key[0] < i:
                continue
            elif mapping[key[0]] == key[1]:
                match_num += weight_dict[current_node_pair][key]
                if veryVerbose:
                    print("relation match with", key, weight_dict[current_node_pair][key], file=DEBUG_LOG)
    if veryVerbose:
        print("match computing complete, result:", match_num, file=DEBUG_LOG)

    match_triple_dict[tuple(mapping)] = match_num
    return match_num

Given a node mapping, compute match number based on weight_dict.
Args:
mappings: a list of node index in AMR 2. The ith element (value j) means node i in AMR 1 maps to node j in AMR 2.
Returns:
matching triple number
Complexity: O(m*n) , m is the node number of AMR 1, n is the node number of AMR 2


def get_attributes(self, uid=None, attribute_names=None):
    if (uid is not None):
        if (not isinstance(uid, six.string_types)):
            raise TypeError('uid must be a string')
    if (attribute_names is not None):
        if (not isinstance(attribute_names, list)):
            raise TypeError('attribute_names must be a list of strings')
        else:
            for attribute_name in attribute_names:
                if (not isinstance(attribute_name, six.string_types)):
                    raise TypeError('attribute_names must be a list of strings')
    result = self.proxy.get_attributes(uid, attribute_names)
    status = result.result_status.value
    if (status == enums.ResultStatus.SUCCESS):
        return (result.uuid, result.attributes)
    else:
        reason = result.result_reason.value
        message = result.result_message.value
        raise exceptions.KmipOperationFailure(status, reason, message)

Get the attributes associated with a managed object.

If the uid is not specified, the appliance will use the ID placeholder
by default.

If the attribute_names list is not specified, the appliance will
return all viable attributes for the managed object.

Args:
uid (string): The unique ID of the managed object with which the
retrieved attributes should be associated. Optional, defaults
to None.
attribute_names (list): A list of string attribute names
indicating which attributes should be retrieved. Optional,
defaults to None.


def _truncate(self, processed_features: Union[dict[str, np.ndarray], BatchFeature], max_length: Optional[int]=None, pad_to_multiple_of: Optional[int]=None, truncation: Optional[bool]=None):
    if not truncation:
        return processed_features
    elif truncation and max_length is None:
        raise ValueError('When setting ``truncation=True``, make sure that ``max_length`` is defined.')
    required_input = processed_features[self.model_input_names[0]]
    if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
        max_length = (max_length
    needs_to_be_truncated = len(required_input) > max_length
    if needs_to_be_truncated:
        processed_features[self.model_input_names[0]] = processed_features[self.model_input_names[0]][:max_length]
        if 'attention_mask' in processed_features:
            processed_features['attention_mask'] = processed_features['attention_mask'][:max_length]
    return processed_features

Truncate inputs to predefined length or max length in the batch

Args:
processed_features(`Union[Dict[str, np.ndarray], BatchFeature]`):
Dictionary of input values (`np.ndarray[float]`) / input vectors (`List[np.ndarray[float]]`) or batch
of inputs values (`List[np.ndarray[int]]`) / input vectors (`List[np.ndarray[int]]`)
max_length (`int`, *optional*):
maximum length of the returned list and optionally padding length (see below)
pad_to_multiple_of (`int`, *optional*) :
Integer if set will pad the sequence to a multiple of the provided value. This is especially useful to
enable the use of Tensor Core on NVIDIA hardware with compute capability `>= 7.5` (Volta), or on TPUs
which benefit from having sequence lengths be a multiple of 128.
truncation (`bool`, *optional*):
Activates truncation to cut input sequences longer than `max_length` to `max_length`.


def decode_base64(data):

    data = bytes(data, encoding="ascii")
    missing_padding = len(data) % 4
    if missing_padding != 0:
        data += b'=' * (4 - missing_padding)
    return base64.b64decode(data)

Decodes a base64 string, with padding being optional

Args:
data: A base64 encoded string

Returns:
bytes: The decoded bytes


def formatted(self, func):

        other = EscapedString.__new__(EscapedString)
        other.strings = []

        for is_literal, value in self.strings:
            if not is_literal:
                value = func(value)
            other.strings.append((is_literal, value))
        return other

Return the string with non-literal parts formatted.

Args:
func (callable): Callable that translates a string into a
formatted string.

Returns:
`EscapedString` object.


def get_idx_types(rng_def, ranges):

    idx_types = rng_def.get('kds_esIndexType', []).copy()
    if not idx_types:
        nested = False
        for rng in ranges:
            if range_is_obj(rng, __MODULE__.rdfclass):
                nested = True
        if nested:
            idx_types.append('es_Nested')
    return idx_types

Returns the elasticsearch index types for the obj

args:
rng_def: the range defintion dictionay
ranges: rdfproperty ranges


def __generate_reference__(self, triple_map, **kwargs):

        raw_value = self.source.get(str(triple_map.reference))
        if raw_value is None or len(raw_value) < 1:
            return
        if hasattr(triple_map, "datatype"):
            if triple_map.datatype == NS_MGR.xsd.anyURI.rdflib:
                output = rdflib.URIRef(raw_value)
            else:
                output = rdflib.Literal(
                    raw_value,
                    datatype=triple_map.datatype)
        else:
            output = rdflib.Literal(raw_value)
        return output

Generates a RDF entity based on triple map

Args:
triple_map(SimpleNamespace): Triple Map


def check_tx(self, raw_transaction):
    self.abort_if_abci_chain_is_not_synced()
    logger.debug('check_tx: %s', raw_transaction)
    transaction = decode_transaction(raw_transaction)
    if self.bigchaindb.is_valid_transaction(transaction):
        logger.debug('check_tx: VALID')
        return ResponseCheckTx(code=CodeTypeOk)
    else:
        logger.debug('check_tx: INVALID')
        return ResponseCheckTx(code=CodeTypeError)

Validate the transaction before entry into
the mempool.

Args:
raw_tx: a raw string (in bytes) transaction.


def spliceext(filepath, s):

    root, ext = os.path.splitext(safepath(filepath))
    return root + s + ext

Add s into filepath before the extension

Args:
filepath (str, path): file path
s (str): string to splice

Returns:
str


def create_unit(self, name, unit):
    self._single_request('Units.Set', unitName=name, body={'desiredState': unit.desiredState, 'options': unit.options})
    return self.get_unit(name)

Create a new Unit in the cluster

Create and modify Unit entities to communicate to fleet the desired state of the cluster.
This simply declares what should be happening; the backend system still has to react to
the changes in this desired state. The actual state of the system is communicated with
UnitState entities.

Args:
name (str): The name of the unit to create
unit (Unit): The unit to submit to fleet

Returns:
Unit: The unit that was created

Raises:
fleet.v1.errors.APIError: Fleet returned a response code >= 400


def remove(self, future):
    if self._loop.get_debug():
        logger.debug('Removing %s from the linked list.', future)
    if (future.prev is None):
        assert (future is self.head)
        self.head = future.next
        if (self.head is None):
            self.tail = None
            if (not self.cancelled()):
                self.set_result(None)
        else:
            self.head.prev = None
    elif (future.next is None):
        assert (future is self.tail)
        self.tail = future.prev
        if (self.tail is None):
            self.head = None
            if (not self.cancelled()):
                self.set_result(None)
        else:
            self.tail.prev = None

Remove an object from the linked list.

Args:
future (PlasmaObjectFuture): A PlasmaObjectFuture instance.


def UnlockScanNode(self, path_spec):
    if (not self.HasScanNode(path_spec)):
        raise KeyError('Scan node does not exist.')
    if (path_spec not in self._locked_scan_nodes):
        raise KeyError('Scan node is not locked.')
    del self._locked_scan_nodes[path_spec]
    self._scan_nodes[path_spec].scanned = False

Marks a scan node as unlocked.

Args:
path_spec (PathSpec): path specification.

Raises:
KeyError: if the scan node does not exists or is not locked.


def user_avatar_url(username, size=64, default="retro"):

    openid = "http:
    return libravatar_url(openid=openid, size=size, default=default)

Get the avatar URL of the provided Fedora username.

The URL is returned from the Libravatar service.

Args:
username (str): The username to get the avatar of.
size (int): Size of the avatar in pixels (it's a square).
default (str): Default avatar to return if not found.
Returns:
str: The URL to the avatar image.


def __lt__(self, other):
    other = as_dimension(other)
    if self._value is None or other.value is None:
        return None
    else:
        return self._value < other.value

Returns True if `self` is known to be less than `other`.

Dimensions are compared as follows:

```python
(tf.compat.v1.Dimension(m)    < tf.compat.v1.Dimension(n))    == (m < n)
(tf.compat.v1.Dimension(m)    < tf.compat.v1.Dimension(None)) == None
(tf.compat.v1.Dimension(None) < tf.compat.v1.Dimension(n))    == None
(tf.compat.v1.Dimension(None) < tf.compat.v1.Dimension(None)) == None
```

Args:
other: Another Dimension.

Returns:
The value of `self.value < other.value` if both are known, otherwise
None.


class LabelSmoother:
    epsilon: float = 0.1
    ignore_index: int = -100

    def __call__(self, model_output, labels, shift_labels=False):
        logits = model_output['logits'] if isinstance(model_output, dict) else model_output[0]
        if shift_labels:
            logits = logits[..., :-1, :].contiguous()
            labels = labels[..., 1:].contiguous()
        log_probs = -nn.functional.log_softmax(logits, dim=-1)
        if labels.dim() == log_probs.dim() - 1:
            labels = labels.unsqueeze(-1)
        padding_mask = labels.eq(self.ignore_index)
        labels = torch.clamp(labels, min=0)
        nll_loss = log_probs.gather(dim=-1, index=labels)
        smoothed_loss = log_probs.sum(dim=-1, keepdim=True, dtype=torch.float32)
        nll_loss.masked_fill_(padding_mask, 0.0)
        smoothed_loss.masked_fill_(padding_mask, 0.0)
        num_active_elements = padding_mask.numel() - padding_mask.long().sum()
        nll_loss = nll_loss.sum() / num_active_elements
        smoothed_loss = smoothed_loss.sum() / (num_active_elements * log_probs.shape[-1])
        return (1 - self.epsilon) * nll_loss + self.epsilon * smoothed_loss

Adds label-smoothing on a pre-computed output from a Transformers model.

Args:
epsilon (`float`, *optional*, defaults to 0.1):
The label smoothing factor.
ignore_index (`int`, *optional*, defaults to -100):
The index in the labels to ignore when computing the loss.


def url(self, suffix=""):

        return super(neuroRemote,
                     self).url('{}/'.format(self._ext) + suffix)

Return a constructed URL, appending an optional suffix (uri path).

Arguments:
suffix (str : ""): The suffix to append to the end of the URL

Returns:
str: The complete URL


The statically known shape of the RaggedTensor.

Examples:

>>> rt = tf.ragged.constant([[0], [1, 2]])
>>> tf.type_spec_from_value(rt).shape
TensorShape([2, None])

>>> rt = tf.ragged.constant([[[0, 1]], [[1, 2], [3, 4]]], ragged_rank=1)
>>> tf.type_spec_from_value(rt).shape
TensorShape([2, None, 2])

Returns:
A `tf.TensorShape` containing the statically known shape of the
RaggedTensor. Ragged dimensions have a size of `None`.


def disconnect_container_from_network(self, container, net_id,
                                          force=False):

        data = {"Container": container}
        if force:
            if version_lt(self._version, '1.22'):
                raise InvalidVersion(
                    'Forced disconnect was introduced in API 1.22'
                )
            data['Force'] = force
        url = self._url("/networks/{0}/disconnect", net_id)
        res = self._post_json(url, data=data)
        self._raise_for_status(res)

Disconnect a container from a network.

Args:
container (str): container ID or name to be disconnected from the
network
net_id (str): network ID
force (bool): Force the container to disconnect from a network.
Default: ``False``


def py_hash(key, num_buckets):

    b, j = -1, 0

    if num_buckets < 1:
        raise ValueError('num_buckets must be a positive number')

    while j < num_buckets:
        b = int(j)
        key = ((key * long(2862933555777941757)) + 1) & 0xffffffffffffffff
        j = float(b + 1) * (float(1 << 31) / float((key >> 33) + 1))

    return int(b)

Generate a number in the range [0, num_buckets).

Args:
key (int): The key to hash.
num_buckets (int): Number of buckets to use.

Returns:
The bucket number `key` computes to.

Raises:
ValueError: If `num_buckets` is not a positive number.


def ParseLeakFilesTable(
      self, parser_mediator, database=None, table=None, **unused_kwargs):

    if database is None:
      raise ValueError('Missing database value.')

    if table is None:
      raise ValueError('Missing table value.')

    for esedb_record in table.records:
      if parser_mediator.abort:
        break

      record_values = self._GetRecordValues(
          parser_mediator, table.name, esedb_record)

      event_data = MsieWebCacheLeakFilesEventData()
      event_data.cached_filename = record_values.get('Filename', None)
      event_data.leak_identifier = record_values.get('LeakId', None)

      timestamp = record_values.get('CreationTime', None)
      if timestamp:
        date_time = dfdatetime_filetime.Filetime(timestamp=timestamp)
        event = time_events.DateTimeValuesEvent(
            date_time, definitions.TIME_DESCRIPTION_CREATION)
        parser_mediator.ProduceEventWithEventData(event, event_data)

Parses the LeakFiles table.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
database (Optional[pyesedb.file]): ESE database.
table (Optional[pyesedb.table]): table.

Raises:
ValueError: if the database or table value is missing.


def print_headers(head, outfile=None, silent=False):

    for header_line in head.print_header():

        if outfile:
            outfile.write(header_line+'\n')
        else:
            if not silent:
                print(header_line)
    return

Print the vcf headers.

If a result file is provided headers will be printed here, otherwise
they are printed to stdout.

Args:
head (HeaderParser): A vcf header object
outfile (FileHandle): A file handle
silent (Bool): If nothing should be printed.


def entityLabel(rdfGraph, anEntity, language=DEFAULT_LANGUAGE, getall=True):

    if getall:
        temp = []
        for o in rdfGraph.objects(anEntity, RDFS.label):
            temp += [o]
        return temp
    else:
        for o in rdfGraph.objects(anEntity, RDFS.label):
            if getattr(o, 'language') and getattr(o, 'language') == language:
                return o
        return ""

Returns the rdfs.label value of an entity (class or property), if existing.
Defaults to DEFAULT_LANGUAGE. Returns the RDF.Literal resource

Args:
language: 'en', 'it' etc..
getall: returns a list of all labels rather than a string


def update(self, node_spec):
    return self.client.api.update_node(self.id, self.version, node_spec)

Update the node's configuration.

Args:
node_spec (dict): Configuration settings to update. Any values
not provided will be removed. Default: ``None``

Returns:
`True` if the request went through.

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.

Example:

>>> node_spec = {'Availability': 'active',
'Name': 'node-name',
'Role': 'manager',
'Labels': {'foo': 'bar'}
}
>>> node.update(node_spec)


def get_tz(tz) -> str:

    from xbbg.const import exch_info

    if tz is None: return DEFAULT_TZ

    to_tz = tz
    if isinstance(tz, str):
        if hasattr(TimeZone, tz):
            to_tz = getattr(TimeZone, tz)
        else:
            exch = exch_info(ticker=tz)
            if 'tz' in exch.index:
                to_tz = exch.tz

    return to_tz

Convert tz from ticker / shorthands to timezone

Args:
tz: ticker or timezone shorthands

Returns:
str: Python timzone

Examples:
>>> get_tz('NY')
'America/New_York'
>>> get_tz(TimeZone.NY)
'America/New_York'
>>> get_tz('BHP AU Equity')
'Australia/Sydney'


def normalize_list_like_lines(generation):
    lines = generation.split('\n')
    output_lines = []
    for line_no, line in enumerate(lines):
        match = re.search('. ([-*]) ', line)
        if not match or line[0] not in ('-', '*'):
            output_lines.append(line)
            continue
        delim = match.group(1) + ' '
        splits = line.split(delim)[1:]
        replacement = ''
        delim1 = line[0] + ' '
        for i, item in enumerate(splits):
            level = 0
            potential_numeral, _, rest = item.strip().partition(' ')
            if not rest:
                continue
            if re.match('^[\\dixv]+((?:\\.[\\dixv])?)+$', potential_numeral, flags=re.I | re.M):
                level = potential_numeral.count('.')
            replacement += ('\n' if i > 0 else '') + '\t' * level + (delim if i > 0 or line_no == 0 else delim1) + item.strip()
        if line_no == len(lines) - 1:
            replacement += '\n'
        output_lines.append(replacement)
    return '\n'.join(output_lines)

Normalize lines in the given text that resemble list items. The function looks for lines that start optionally with
'-' or '*', possibly followed by Roman numerals or digits indicating nesting levels. The function reformats such
lines to make them more structured.

Args:
generation (str): The input text containing lines that need to be normalized.

Returns:
str: The input text with the list-like lines normalized.

Note:
The function uses regular expressions to identify and reformat the list-like lines. The patterns capture
optional bullet points, nesting levels indicated by numerals, and the actual list item content. The
normalization adjusts the bullet point style and nesting levels based on the captured patterns.


def find_bind_module(name, verbose=False):

    bindnames = get_bind_modules(verbose=verbose)
    bindfile = bindnames.get(name)

    if bindfile:
        return bindfile

    if not verbose:
        return None

    fuzzy_matches = get_close_pkgs(name, bindnames.keys())

    if fuzzy_matches:
        rows = [(x[0], bindnames[x[0]]) for x in fuzzy_matches]
        print "'%s' not found. Close matches:" % name
        print '\n'.join(columnise(rows))
    else:
        print "No matches."

    return None

Find the bind module matching the given name.

Args:
name (str): Name of package to find bind module for.
verbose (bool): If True, print extra output.

Returns:
str: Filepath to bind module .py file, or None if not found.


def forward(self, hidden: torch.Tensor):
    if self.mode == 'mix_channel':
        hidden = self.channel_feature_mixer(hidden)
    hidden = self.patch_mixer(hidden)
    hidden = self.feature_mixer(hidden)
    return hidden

Args:
hidden (`torch.Tensor` of shape `(batch_size, num_patches, d_model)`):
Input tensor to the layer.

Returns:
`torch.Tensor`: Transformed tensor.


def connected_emulators(self, host=enums.JLinkHost.USB):
    res = self._dll.JLINKARM_EMU_GetList(host, 0, 0)
    if (res < 0):
        raise errors.JLinkException(res)
    num_devices = res
    info = (structs.JLinkConnectInfo * num_devices)()
    num_found = self._dll.JLINKARM_EMU_GetList(host, info, num_devices)
    if (num_found < 0):
        raise errors.JLinkException(num_found)
    return list(info)[:num_found]

Returns a list of all the connected emulators.

Args:
self (JLink): the ``JLink`` instance
host (int): host type to search (default: ``JLinkHost.USB``)

Returns:
List of ``JLinkConnectInfo`` specifying the connected emulators.

Raises:
JLinkException: if fails to enumerate devices.


def get_config_parameter_boolean(config: ConfigParser, section: str, param: str, default: bool) -> bool:
    try:
        value = config.getboolean(section, param)
    except (TypeError, ValueError, NoOptionError):
        log.warning('Configuration variable {} not found or improper in section [{}]; using default of {!r}', param, section, default)
        value = default
    return value

Get Boolean parameter from ``configparser`` ``.INI`` file.

Args:
config: :class:`ConfigParser` object
section: section name within config file
param: name of parameter within section
default: default value
Returns:
parameter value, or default


def create_transformation(self, rotation=None, translation=None):
    mat = None
    if (rotation is not None):
        mat = Matrix44.from_eulers(Vector3(rotation))
    if (translation is not None):
        trans = matrix44.create_from_translation(Vector3(translation))
        if (mat is None):
            mat = trans
        else:
            mat = matrix44.multiply(mat, trans)
    return mat

Creates a transformation matrix woth rotations and translation.

Args:
rotation: 3 component vector as a list, tuple, or :py:class:`pyrr.Vector3`
translation: 3 component vector as a list, tuple, or :py:class:`pyrr.Vector3`

Returns:
A 4x4 matrix as a :py:class:`numpy.array`


def get_name(cls):
    global _registry_loaded
    if (not _registry_loaded):
        load_message_classes()
    try:
        return _class_to_schema_name[cls]
    except KeyError:
        raise TypeError('The class {} is not in the message registry, which indicates it is not in the current list of entry points for "fedora_messaging". Please check that the class has been added to your package\'s entry points.'.format(repr(cls)))

Retrieve the schema name associated with a message class.

Returns:
str: The schema name.

Raises:
TypeError: If the message class isn't registered. Check your entry point
for correctness.


def GetNotificationsForAllShards(self, queue):

    notifications_by_session_id = {}
    for queue_shard in self.GetAllNotificationShards(queue):
      self._GetUnsortedNotifications(
          queue_shard, notifications_by_session_id=notifications_by_session_id)

    return notifications_by_session_id.values()

Returns notifications for all shards of a queue at once.

Used by worker_test_lib.MockWorker to cover all shards with a single worker.

Args:
queue: usually rdfvalue.RDFURN("aff4:/W")

Returns:
List of rdf_flows.GrrNotification objects


def get_image_features(self, pixel_values: torch.FloatTensor, vision_feature_layers: Optional[Union[int, List[int]]]=None):
    vision_feature_layers = vision_feature_layers if vision_feature_layers is not None else self.config.vision_feature_layers
    image_outputs = self.vision_tower(pixel_values, output_hidden_states=True)
    if isinstance(vision_feature_layers, int):
        image_features = image_outputs.hidden_states[vision_feature_layers][:, 1:]
    else:
        image_features = [image_outputs.hidden_states[index][:, 1:] for index in vision_feature_layers]
        image_features = torch.cat(image_features, dim=-1)
    image_features = self.multi_modal_projector(image_features)
    return image_features

Obtains image last hidden states from the vision tower and apply multimodal projection.

Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, channels, height, width)`)
The tensors corresponding to the input images.
vision_feature_layers (`Union[int, List[int]]`):
The vision feature layer, or the list of indexes of the layers to select
the vision feature.
Returns:
image_features (`torch.Tensor`): Image feature tensor of shape `(num_images, image_length, embed_dim)`).


def get_reverse_dns(ip_address, cache=None, nameservers=None, timeout=2.0):
    hostname = None
    try:
        address = dns.reversename.from_address(ip_address)
        hostname = query_dns(address, 'PTR', cache=cache, nameservers=nameservers, timeout=timeout)[0]
    except dns.exception.DNSException:
        pass
    return hostname

Resolves an IP address to a hostname using a reverse DNS query

Args:
ip_address (str): The IP address to resolve
cache (ExpiringDict): Cache storage
nameservers (list): A list of one or more nameservers to use
(Cloudflare's public DNS resolvers by default)
timeout (float): Sets the DNS query timeout in seconds

Returns:
str: The reverse DNS hostname (if any)


def _aggregation_op(cls, op: Callable[([tf.Tensor, Optional[Sequence[int]]], tf.Tensor)], x: 'TensorFluent', vars_list: List[str]) -> 'TensorFluent':
    axis = cls._varslist2axis(x, vars_list)
    t = op(x.tensor, axis)
    scope = []
    for var in x.scope.as_list():
        if (var not in vars_list):
            scope.append(var)
    batch = x.batch
    return TensorFluent(t, scope, batch=batch)

Returns a TensorFluent for the aggregation `op` applied to fluent `x`.

Args:
op: The aggregation operation.
x: The input fluent.
vars_list: The list of variables to be aggregated over.

Returns:
A TensorFluent wrapping the aggregation operator's output.


def longest_existing_path(_path):
    existing_path = _path
    while True:
        _path_new = os.path.dirname(existing_path)
        if exists(_path_new):
            existing_path = _path_new
            break
        if (_path_new == existing_path):
            print('!!! [utool] This is a very illformated path indeed.')
            existing_path = ''
            break
        existing_path = _path_new
    return existing_path

r"""
Returns the longest root of _path that exists

Args:
_path (str):  path string

Returns:
str: _path -  path string

CommandLine:
python -m utool.util_path --exec-longest_existing_path

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_path import *  # NOQA
>>> import utool as ut
>>> target = dirname(ut.__file__)
>>> _path = join(target, 'nonexist/foobar')
>>> existing_path = longest_existing_path(_path)
>>> result = ('existing_path = %s' % (str(existing_path),))
>>> print(result)
>>> assert existing_path == target