def _ReadParserPresetValues(self, preset_definition_values):

    if not preset_definition_values:
      raise errors.MalformedPresetError('Missing preset definition values.')

    name = preset_definition_values.get('name', None)
    if not name:
      raise errors.MalformedPresetError(
          'Invalid preset definition missing name.')

    parsers = preset_definition_values.get('parsers', None)
    if not parsers:
      raise errors.MalformedPresetError(
          'Invalid preset definition missing parsers.')

    parser_preset = ParserPreset(name, parsers)

    for operating_system_values in preset_definition_values.get(
        'operating_systems', []):
      operating_system = self._ReadOperatingSystemArtifactValues(
          operating_system_values)
      parser_preset.operating_systems.append(operating_system)

    return parser_preset

Reads a parser preset from a dictionary.

Args:
preset_definition_values (dict[str, object]): preset definition values.

Returns:
ParserPreset: a parser preset.

Raises:
MalformedPresetError: if the format of the preset definition is not set
or incorrect, or the preset of a specific operating system has already
been set.


def __init__(self, sess):
    _check_type(sess, (session.BaseSession, monitored_session.MonitoredSession))
    self.session = sess

Constructor.

Args:
sess: A tensorflow Session object.


def on_raw_update(
        self=None,
        group: int = 0
    ) -> callable:

        def decorator(func: callable) -> Tuple[Handler, int]:
            if isinstance(func, tuple):
                func = func[0].callback

            handler = pyrogram.RawUpdateHandler(func)

            if isinstance(self, int):
                return handler, group if self is None else group

            if self is not None:
                self.add_handler(handler, group)

            return handler, group

        return decorator

Use this decorator to automatically register a function for handling raw updates.
This does the same thing as :meth:`add_handler` using the :class:`RawUpdateHandler`.

Args:
group (``int``, *optional*):
The group identifier, defaults to 0.


def read_model(input_tflite_file):
    if not gfile.Exists(input_tflite_file):
        raise RuntimeError('Input file not found at %r\n' % input_tflite_file)
    with gfile.GFile(input_tflite_file, 'rb') as input_file_handle:
        model_bytearray = bytearray(input_file_handle.read())
    return read_model_from_bytearray(model_bytearray)

Reads a tflite model as a python object.

Args:
input_tflite_file: Full path name to the input tflite file

Raises:
RuntimeError: If input_tflite_file path is invalid.
IOError: If input_tflite_file cannot be opened.

Returns:
A python object corresponding to the input tflite file.


def _GetTypeIndicators(cls, signature_scanner, specification_store, remainder_list, path_spec, resolver_context=None):
    type_indicator_list = []
    file_object = resolver.Resolver.OpenFileObject(path_spec, resolver_context=resolver_context)
    scan_state = pysigscan.scan_state()
    try:
        signature_scanner.scan_file_object(scan_state, file_object)
        for scan_result in iter(scan_state.scan_results):
            format_specification = specification_store.GetSpecificationBySignature(scan_result.identifier)
            if (format_specification.identifier not in type_indicator_list):
                type_indicator_list.append(format_specification.identifier)
        for analyzer_helper in remainder_list:
            result = analyzer_helper.AnalyzeFileObject(file_object)
            if (result is not None):
                type_indicator_list.append(result)
    finally:
        file_object.close()
    return type_indicator_list

Determines if a file contains a supported format types.

Args:
signature_scanner (pysigscan.scanner): signature scanner.
specification_store (FormatSpecificationStore): specification store.
remainder_list (list[AnalyzerHelper]): remaining analyzer helpers that
do not have a format specification.
path_spec (PathSpec): path specification.
resolver_context (Optional[Context]): resolver context, where None
represents the built-in context which is not multi process safe.

Returns:
list[str]: supported format type indicators.


def delete_resource_group(access_token, subscription_id, rgname):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourcegroups/', rgname,
                        '?api-version=', RESOURCE_API])
    return do_delete(endpoint, access_token)

Delete the named resource group.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
rgname (str): Azure resource group name.

Returns:
HTTP response.


def parse_pyc_string(data):
    return pyc.loads(data)

Parse pyc data from a string.

Args:
data: pyc data

Returns:
An instance of pycnite.types.CodeTypeBase.


def get_address_coords(self, address):
    url = ('https:
    r = requests.get(url)
    r.raise_for_status()
    results = r.json()['results']
    lat = results[0]['geometry']['location']['lat']
    lng = results[0]['geometry']['location']['lng']
    return (lat, lng)

Use the google geocoder to get latitude and longitude for an address string

Args:
address: any address string

Returns:
A tuple of (lat,lng)


def __init__(self, latent_size):

    super(ProbabilisticGrammarVariational, self).__init__()
    self.latent_size = latent_size
    self.encoder_net = tf.keras.Sequential([
        tf.keras.layers.Conv1D(64, 3, padding="SAME"),
        tf.keras.layers.BatchNormalization(),
        tf.keras.layers.Activation(tf.nn.elu),
        tf.keras.layers.Conv1D(128, 3, padding="SAME"),
        tf.keras.layers.BatchNormalization(),
        tf.keras.layers.Activation(tf.nn.elu),
        tf.keras.layers.Dropout(0.1),
        tf.keras.layers.GlobalAveragePooling1D(),
        tf.keras.layers.Dense(latent_size * 2, activation=None),
    ])

Constructs a variational posterior for a probabilistic grammar.

Args:
latent_size: Number of dimensions in the latent code.


def resolve(node, source_info, graphs, resolver):
    visitor = FunctionVisitor(source_info, graphs, resolver)
    node = visitor.visit(node)
    return node

Performs type inference.

Args:
node: ast.AST
source_info: transformer.SourceInfo
graphs: Dict[ast.FunctionDef, cfg.Graph]
resolver: Resolver

Returns:
ast.AST


def complain(distribution_name):

    try:
        pkg_resources.get_distribution(distribution_name)
        warnings.warn(
            "The {pkg} distribution is now obsolete. "
            "Please `pip uninstall {pkg}`. "
            "In the future, this warning will become an ImportError.".format(
                pkg=distribution_name
            ),
            DeprecationWarning,
        )
    except pkg_resources.DistributionNotFound:
        pass

Issue a warning if `distribution_name` is installed.

In a future release, this method will be updated to raise ImportError
rather than just send a warning.

Args:
distribution_name (str): The name of the obsolete distribution.


def create_migration_template(name):

    assert name, 'Name of the migration can not be empty.'
    from . import migrations

    package = migrations
    prefix = package.__name__ + '.'
    all_versions = []
    for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
        version = int(modname.split('.')[-1].split('_')[0])
        all_versions.append(version)

    next_number = max(all_versions) + 1

    next_migration_name = '{}_{}.py'.format(next_number, name)
    migration_fullname = os.path.join(package.__path__[0], next_migration_name)

    with open(migration_fullname, 'w') as f:
        f.write(MIGRATION_TEMPLATE)
    return migration_fullname

Creates migration file. Returns created file name.
Args:
name (str): name of the migration.

Returns:
str: name of the migration file.


def ipv4_lstrip_zeros(address):

    obj = address.strip().split('.')

    for x, y in enumerate(obj):

        obj[x] = y.split('/')[0].lstrip('0')
        if obj[x] in ['', None]:
            obj[x] = '0'

    return '.'.join(obj)

The function to strip leading zeros in each octet of an IPv4 address.

Args:
address (:obj:`str`): An IPv4 address.

Returns:
str: The modified IPv4 address.


def std(x, axis=None, keepdims=False):
    if x.dtype.base_dtype == dtypes_module.bool:
        x = math_ops.cast(x, floatx())
    return math_ops.reduce_std(x, axis=axis, keepdims=keepdims)

Standard deviation of a tensor, alongside the specified axis.

It is an alias to `tf.math.reduce_std`.

Args:
x: A tensor or variable. It should have numerical dtypes. Boolean type
inputs will be converted to float.
axis: An integer, the axis to compute the standard deviation. If `None`
(the default), reduces all dimensions. Must be in the range
`[-rank(x), rank(x))`.
keepdims: A boolean, whether to keep the dimensions or not.
If `keepdims` is `False`, the rank of the tensor is reduced
by 1. If `keepdims` is `True`, the reduced dimension is retained with
length 1.

Returns:
A tensor with the standard deviation of elements of `x` with same dtype.
Boolean type input will be converted to float.


def contains(self, time: datetime.datetime,
                 inclusive: bool = True) -> bool:

        if inclusive:
            return self.start <= time <= self.end
        else:
            return self.start < time < self.end

Does the interval contain a momentary time?

Args:
time: the ``datetime.datetime`` to check
inclusive: use inclusive rather than exclusive range checks?


def add(self, key, value):

        if isinstance(value, list):

            for val in value:
                self._add_arg_python(key, val)
        elif isinstance(value, dict):
            err = 'Dictionary types are not currently supported for field.'
            print('{}{}{}'.format(c.Style.BRIGHT, c.Fore.RED, err))
        else:
            mask = False
            env_var = re.compile(r'^\$env\.(.*)$')
            envs_var = re.compile(r'^\$envs\.(.*)$')

            if env_var.match(str(value)):

                env_key = env_var.match(str(value)).groups()[0]
                value = os.environ.get(env_key, value)
            elif envs_var.match(str(value)):

                env_key = envs_var.match(str(value)).groups()[0]
                value = os.environ.get(env_key, value)
                mask = True
            self._add_arg(key, value, mask)

Add CLI Arg to lists value.

Args:
key (string): The CLI Args key (e.g., --name).
value (string): The CLI Args value (e.g., bob).


def gen_sl_transform_matricies(area_multiple):

    return [np.array(((i, j), (0, area_multiple / i)))
            for i in get_factors(area_multiple)
            for j in range(area_multiple

Generates the transformation matricies that convert a set of 2D
vectors into a super lattice of integer area multiple as proven
in Cassels:

Cassels, John William Scott. An introduction to the geometry of
numbers. Springer Science & Business Media, 2012.

Args:
area_multiple(int): integer multiple of unit cell area for super
lattice area

Returns:
matrix_list: transformation matricies to covert unit vectors to
super lattice vectors


def read(self, nodes=None, **kwargs):

        if nodes is None:
            required_nodes = self.wishlist - set(self.datasets.keys())
            nodes = self.dep_tree.leaves(nodes=required_nodes)
        return self._read_datasets(nodes, **kwargs)

Load datasets from the necessary reader.

Args:
nodes (iterable): DependencyTree Node objects
**kwargs: Keyword arguments to pass to the reader's `load` method.

Returns:
DatasetDict of loaded datasets


def cctop_submit(seq_str):
    url = 'http:
    r = requests.post(url)
    jobid = r.text.split('ID: ')[1]
    return jobid

Submit a protein sequence string to CCTOP and return the job ID.

Args:
seq_str (str): Protein sequence as a string

Returns:
dict: Job ID on the CCTOP server


def KernelVersion():
    rtl_osversioninfoexw = RtlOSVersionInfoExw()
    try:
        RtlGetVersion(rtl_osversioninfoexw)
    except OSError:
        return 'unknown'
    return ('%d.%d.%d' % (rtl_osversioninfoexw.dwMajorVersion, rtl_osversioninfoexw.dwMinorVersion, rtl_osversioninfoexw.dwBuildNumber))

Gets the kernel version as string, eg. "5.1.2600".

Returns:
The kernel version, or "unknown" in the case of failure.


def __init__(self, resolver_context, file_system, path_spec, is_root=False):

    location = getattr(path_spec, 'location', None)

    is_windows_device = False
    if platform.system() == 'Windows' and location:
      try:

        is_windows_device = pysmdev.check_device(location)
      except IOError:
        pass

    stat_info = None
    if not is_windows_device and location:

      try:
        stat_info = os.lstat(location)
      except OSError as exception:
        raise errors.BackEndError(
            'Unable to retrieve stat object with error: {0!s}'.format(
                exception))

    super(OSFileEntry, self).__init__(
        resolver_context, file_system, path_spec, is_root=is_root,
        is_virtual=False)
    self._is_windows_device = is_windows_device
    self._name = None
    self._stat_info = stat_info

    if is_windows_device:
      self.entry_type = definitions.FILE_ENTRY_TYPE_DEVICE

    elif stat_info:

      is_link = os.path.islink(location)

      if stat.S_ISLNK(stat_info.st_mode) or is_link:
        self.entry_type = definitions.FILE_ENTRY_TYPE_LINK
      elif stat.S_ISREG(stat_info.st_mode):
        self.entry_type = definitions.FILE_ENTRY_TYPE_FILE
      elif stat.S_ISDIR(stat_info.st_mode):
        self.entry_type = definitions.FILE_ENTRY_TYPE_DIRECTORY
      elif (stat.S_ISCHR(stat_info.st_mode) or
            stat.S_ISBLK(stat_info.st_mode)):
        self.entry_type = definitions.FILE_ENTRY_TYPE_DEVICE
      elif stat.S_ISFIFO(stat_info.st_mode):
        self.entry_type = definitions.FILE_ENTRY_TYPE_PIPE
      elif stat.S_ISSOCK(stat_info.st_mode):
        self.entry_type = definitions.FILE_ENTRY_TYPE_SOCKET

Initializes a file entry.

Args:
resolver_context (Context): resolver context.
file_system (FileSystem): file system.
path_spec (PathSpec): path specification.
is_root (Optional[bool]): True if the file entry is the root file entry
of the corresponding file system.

Raises:
BackEndError: If an OSError comes up it is caught and an
BackEndError error is raised instead.


def IsNTFS(self):
    tsk_fs_type = self.GetFsType()
    return (tsk_fs_type in [pytsk3.TSK_FS_TYPE_NTFS, pytsk3.TSK_FS_TYPE_NTFS_DETECT])

Determines if the file system is NTFS.

Returns:
bool: True if the file system is NTFS.


def _package_path(package):
    from os import path
    confdir = config_dir()
    return path.join(confdir, '{}.cfg'.format(package))

Returns the full path to the default package configuration file.

Args:
package (str): name of the python package to return a path for.


def prepend_block(self, node, reverse=False):
    if (not isinstance(node, grammar.STATEMENTS)):
        raise ValueError
    if reverse:
        self.to_prepend_block[(- 1)].appendleft(node)
    else:
        self.to_prepend_block[(- 1)].append(node)

Prepend a statement to the current block.

Args:
node: The statement to prepend.
reverse: When called multiple times, this flag determines whether the
statement should be prepended or appended to the already inserted
statements.

Raises:
ValueError: If the given node is not a statement.


def __init__(self, swap, expiry_date=None, dtype=None, name=None):
    self._name = name or 'swaption'
    with tf.name_scope(self._name):
        self._dtype = dtype
        self._expiry_date = dates.convert_to_date_tensor(expiry_date)
        self._swap = swap

Initialize a batch of European swaptions.

Args:
swap: An instance of `InterestRateSwap` specifying the interest rate
swaps underlying the swaptions. The batch size of the swaptions being
created would be the same as the batch size of the `swap`.
expiry_date: An optional rank 1 `DateTensor` specifying the expiry dates
for each swaption. The shape of the input should be the same as the
batch size of the `swap` input.
Default value: None in which case the option expity date is the same as
the start date of each underlying swap.
dtype: `tf.Dtype`. If supplied the dtype for the real variables or ops
either supplied to the Swaption object or created by the Swaption
object.
Default value: None which maps to the default dtype inferred by
TensorFlow.
name: Python str. The name to give to the ops created by this class.
Default value: `None` which maps to 'swaption'.


def _music_lib_search(self, search, start, max_items):
    response = self.contentDirectory.Browse([('ObjectID', search), ('BrowseFlag', 'BrowseDirectChildren'), ('Filter', '*'), ('StartingIndex', start), ('RequestedCount', max_items), ('SortCriteria', '')])
    metadata = {}
    for tag in ['NumberReturned', 'TotalMatches', 'UpdateID']:
        metadata[camel_to_underscore(tag)] = int(response[tag])
    return (response, metadata)

Perform a music library search and extract search numbers.

You can get an overview of all the relevant search prefixes (like
'A:') and their meaning with the request:

.. code ::

response = device.contentDirectory.Browse([
('ObjectID', '0'),
('BrowseFlag', 'BrowseDirectChildren'),
('Filter', '*'),
('StartingIndex', 0),
('RequestedCount', 100),
('SortCriteria', '')
])

Args:
search (str): The ID to search.
start (int): The index of the forst item to return.
max_items (int): The maximum number of items to return.

Returns:
tuple: (response, metadata) where response is the returned metadata
and metadata is a dict with the 'number_returned',
'total_matches' and 'update_id' integers


def get_metric_values(self):
    group_names = self.properties.get('metric-groups', None)
    if (not group_names):
        group_names = self.manager.get_metric_values_group_names()
    ret = []
    for group_name in group_names:
        try:
            mo_val = self.manager.get_metric_values(group_name)
            ret_item = (group_name, mo_val)
            ret.append(ret_item)
        except ValueError:
            pass
    return ret

Get the faked metrics, for all metric groups and all resources that
have been prepared on the manager object of this context object.

Returns:

iterable of tuple (group_name, iterable of values): The faked
metrics, in the order they had been added, where:

group_name (string): Metric group name.

values (:class:~zhmcclient.FakedMetricObjectValues`):
The metric values for one resource at one point in time.


def emit_code_from_ir(sql_query_tree, compiler_metadata):

    context = CompilationContext(
        query_path_to_selectable=dict(),
        query_path_to_location_info=sql_query_tree.query_path_to_location_info,
        query_path_to_output_fields=sql_query_tree.query_path_to_output_fields,
        query_path_to_filters=sql_query_tree.query_path_to_filters,
        query_path_to_node=sql_query_tree.query_path_to_node,
        compiler_metadata=compiler_metadata,
    )

    return _query_tree_to_query(sql_query_tree.root, context)

Return a SQLAlchemy Query from a passed SqlQueryTree.

Args:
sql_query_tree: SqlQueryTree, tree representation of the query to emit.
compiler_metadata: SqlMetadata, SQLAlchemy specific metadata.

Returns:
SQLAlchemy Query


def get_paginated_catalogs(self, querystring=None):
    return self._load_data(self.CATALOGS_ENDPOINT, default=[], querystring=querystring, traverse_pagination=False, many=False)

Return a paginated list of course catalogs, including name and ID.

Returns:
dict: Paginated response containing catalogs available for the user.


def _find_mapreduce_yaml(start, checked):

  dir = start
  while dir not in checked:
    checked.add(dir)
    for mr_yaml_name in MR_YAML_NAMES:
      yaml_path = os.path.join(dir, mr_yaml_name)
      if os.path.exists(yaml_path):
        return yaml_path
    dir = os.path.dirname(dir)
  return None

Traverse the directory tree identified by start until a directory already
in checked is encountered or the path of mapreduce.yaml is found.

Checked is present both to make loop termination easy to reason about and so
that the same directories do not get rechecked.

Args:
start: the path to start in and work upward from
checked: the set of already examined directories

Returns:
the path of mapreduce.yaml file or None if not found.


def set_calibration(self, enabled, imus):
    if (len(imus) == 0):
        imus = list(range(MAX_IMUS))
    for i in imus:
        if ((i < 0) or (i >= MAX_IMUS)):
            logger.warn('Invalid IMU index {} in set_calibration'.format(i))
            continue
        self.imus[i]._use_calibration = enabled

Set calibration state for attached IMUs.

Args:
enabled (bool): True to apply calibration to IMU data (if available).
False to output uncalibrated data.
imus (list): indicates which IMUs the calibration state should be set on.
Empty list or [0, 1, 2, 3, 4] will apply to all IMUs, [0, 1] only to
first 2 IMUs, etc.


def write_byte(self, value):
    if isinstance(value, bytes):
        self.stream.write(value)
    elif isinstance(value, str):
        self.stream.write(value.encode('utf-8'))
    elif isinstance(value, int):
        self.stream.write(bytes([value]))

Write a single byte to the stream.

Args:
value (bytes, str or int): value to write to the stream.


def SetPreferredLanguageIdentifier(self, language_identifier):

    if not isinstance(language_identifier, py2to3.STRING_TYPES):
      raise ValueError('Language identifier is not a string.')

    values = language_ids.LANGUAGE_IDENTIFIERS.get(
        language_identifier.lower(), None)
    if not values:
      raise KeyError('Language identifier: {0:s} is not defined.'.format(
          language_identifier))
    self._language_identifier = language_identifier
    self._lcid = values[0]

Sets the preferred language identifier.

Args:
language_identifier (str): language identifier string such as "en-US"
for US English or "is-IS" for Icelandic.

Raises:
KeyError: if the language identifier is not defined.
ValueError: if the language identifier is not a string type.


def combine_with_wd_noise(f_n, amp_n, f_n_wd, amp_n_wd):

    amp_n_wd_interp = interpolate.interp1d(f_n_wd, amp_n_wd, bounds_error=False, fill_value=1e-30)

    amp_n_wd = amp_n_wd_interp(f_n)

    amp_n = amp_n*(amp_n >= amp_n_wd) + amp_n_wd*(amp_n < amp_n_wd)
    return f_n, amp_n

Combine noise with wd noise.

Combines noise and white dwarf background noise based on greater
amplitude value at each noise curve step.

Args:
f_n (float array): Frequencies of noise curve.
amp_n (float array): Amplitude values of noise curve.
f_n_wd (float array): Frequencies of wd noise.
amp_n_wd (float array): Amplitude values of wd noise.

Returns:
(tuple of float arrays): Amplitude values of combined noise curve.


def open(self, mode=None):

        if mode is None:
            mode = self.mode
        elif mode not in ['r', 'w', 'a']:
            raise ValueError('Invalid mode! Modes: [\'a\', \'r\', \'w\']')

        if self._file is None:
            self._file = h5py.File(self.path, mode=mode)

Open the container file.

Args:
mode (str): Either 'r' for read-only, 'w' for truncate and write or
'a' for append. (default: 'a').
If ``None``, uses ``self.mode``.


def write_gff_file(self, outfile, force_rerun=False):

        if ssbio.utils.force_rerun(outfile=outfile, flag=force_rerun):
            with open(outfile, "w") as out_handle:
                GFF.write([self], out_handle)

        self.feature_path = outfile

Write a GFF file for the protein features, ``features`` will now load directly from this file.

Args:
outfile (str): Path to new FASTA file to be written to
force_rerun (bool): If an existing file should be overwritten


def get_sari_score(source_ids, prediction_ids, list_of_targets, max_gram_size=4, beta_for_deletion=0):
    addition_scores = []
    keep_scores = []
    deletion_scores = []
    for n in range(1, (max_gram_size + 1)):
        source_counts = _get_ngram_counter(source_ids, n)
        prediction_counts = _get_ngram_counter(prediction_ids, n)
        target_counts = collections.Counter()
        weighted_target_counts = collections.Counter()
        num_nonempty_targets = 0
        for target_ids_i in list_of_targets:
            target_counts_i = _get_ngram_counter(target_ids_i, n)
            if target_counts_i:
                weighted_target_counts += target_counts_i
                num_nonempty_targets += 1
        for gram in weighted_target_counts.keys():
            weighted_target_counts[gram] /= num_nonempty_targets
            target_counts[gram] = 1
        keep_scores.append(get_keep_score(source_counts, prediction_counts, weighted_target_counts))
        deletion_scores.append(get_deletion_score(source_counts, prediction_counts, weighted_target_counts, beta_for_deletion))
        addition_scores.append(get_addition_score(source_counts, prediction_counts, target_counts))
    avg_keep_score = (sum(keep_scores) / max_gram_size)
    avg_addition_score = (sum(addition_scores) / max_gram_size)
    avg_deletion_score = (sum(deletion_scores) / max_gram_size)
    sari = (((avg_keep_score + avg_addition_score) + avg_deletion_score) / 3.0)
    return (sari, avg_keep_score, avg_addition_score, avg_deletion_score)

Compute the SARI score for a single prediction and one or more targets.

Args:
source_ids: a list / np.array of SentencePiece IDs
prediction_ids: a list / np.array of SentencePiece IDs
list_of_targets: a list of target ID lists / np.arrays
max_gram_size: int. largest n-gram size we care about (e.g. 3 for unigrams,
bigrams, and trigrams)
beta_for_deletion: beta for deletion F score.

Returns:
the SARI score and its three components: add, keep, and deletion scores


def get_text_features(self, input_ids: Optional[torch.Tensor]=None, attention_mask: Optional[torch.Tensor]=None, token_type_ids: Optional[torch.Tensor]=None, position_ids: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None) -> torch.FloatTensor:
    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.use_return_dict
    text_outputs = self.text_model(input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids, position_ids=position_ids, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict)
    pooled_output = text_outputs[0][:, 0, :]
    text_features = self.text_projection(pooled_output)
    return text_features

Returns:
text_features (`torch.FloatTensor` of shape `(batch_size, output_dim`): The text embeddings obtained by
applying the projection layer to the final [CLS] hidden state of Text-Transformer.

Examples:

```python
>>> from transformers import AutoTokenizer, ChineseCLIPModel

>>> model = ChineseCLIPModel.from_pretrained("OFA-Sys/chinese-clip-vit-base-patch16")
>>> tokenizer = AutoTokenizer.from_pretrained("OFA-Sys/chinese-clip-vit-base-patch16")

>>> inputs = tokenizer(["杰尼龟", "妙蛙种子", "小火龙", "皮卡丘"], padding=True, return_tensors="pt")
>>> text_features = model.get_text_features(**inputs)
>>> text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)
```


def add_update_users(self, users, capacity=None):

        if not isinstance(users, list):
            raise HDXError('Users should be a list!')
        for user in users:
            self.add_update_user(user, capacity)

Add new or update existing users in organization with new metadata. Capacity eg. member, admin
must be supplied either within the User object or dictionary or using the capacity argument (which takes
precedence).

Args:
users (List[Union[User,Dict,str]]): A list of either user ids or users metadata from User objects or dictionaries
capacity (Optional[str]): Capacity of users eg. member, admin. Defaults to None.

Returns:
None


def replace_drive_enclosure(self, information):

        uri = "{}/replaceDriveEnclosure".format(self.data["uri"])
        result = self._helper.create(information, uri)
        self.refresh()

        return result

When a drive enclosure has been physically replaced, initiate the replacement operation that enables the
new drive enclosure to take over as a replacement for the prior drive enclosure. The request requires
specification of both the serial numbers of the original drive enclosure and its replacement to be provided.

Args:
information: Options to replace the drive enclosure.

Returns:
dict: SAS Logical Interconnect.


def load(nifti_filename):

    nifti_filename = os.path.expanduser(nifti_filename)

    try:
        data = nib.load(nifti_filename)
        img = data.get_data()

    except Exception as e:
        raise ValueError("Could not load file {0} for conversion."
                         .format(nifti_filename))
        raise

    return img

Import a nifti file into a numpy array. TODO:  Currently only
transfers raw data for compatibility with annotation and ND formats

Arguments:
nifti_filename (str):  A string filename of a nifti datafile

Returns:
A numpy array with data from the nifti file


def confirm(question):
    if FORCE_YES:
        return True
    while True:
        answer = input((question + ' <Yes|No>')).lower()
        if ((answer == 'yes') or (answer == 'y')):
            confirmed = True
            break
        if ((answer == 'no') or (answer == 'n')):
            confirmed = False
            break
    return confirmed

Ask the user if he really want something to happen.

Args:
question(str): What can happen

Returns:
(boolean): Confirmed or not


def set_size(self, height=220, width=350, height_threshold=120, width_threshold=160):
    self.set_integer('height', height)
    self.set_integer('width', width)
    self.set_integer('small_height_threshold', height_threshold)
    self.set_integer('small_width_threshold', width_threshold)

Set the size of the chart.

Args:
height (int): height in pixels.
width (int): width in pixels.
height_threshold (int): height threshold in pixels
width_threshold (int): width threshold in pixesls


def _lookup_tensor_name(self, tensor):
    return self._tensor_aliases.get(tensor.name, tensor.name)

Look up the name of a graph tensor.

This method maps the name of a debugger-generated Identity or
DebugIdentityV2 tensor to the name of the original instrumented tensor,
if `tensor` is such a debugger-created tensor.
Otherwise, it returns the name of `tensor` as is.

Args:
tensor: The graph tensor to look up the name for.

Returns:
Name of the original instrumented tensor as known to the debugger.


def get_variantid(variant_obj, family_id):

    new_id = parse_document_id(
        chrom=variant_obj['chromosome'],
        pos=str(variant_obj['position']),
        ref=variant_obj['reference'],
        alt=variant_obj['alternative'],
        variant_type=variant_obj['variant_type'],
        case_id=family_id,
    )
    return new_id

Create a new variant id.

Args:
variant_obj(dict)
family_id(str)

Returns:
new_id(str): The new variant id


def __is_json_error(self, status, headers):
    content_header = headers.get('content-type', '')
    (content_type, unused_params) = cgi.parse_header(content_header)
    return (status.startswith('400') and (content_type.lower() in _ALL_JSON_CONTENT_TYPES))

Determine if response is an error.

Args:
status: HTTP status code.
headers: Dictionary of (lowercase) header name to value.

Returns:
True if the response was an error, else False.


def get_size(self, value=None):

        if value is None:
            return sum(cls_val.get_size(obj_val) for obj_val, cls_val in
                       self._get_attributes())
        elif isinstance(value, type(self)):
            return value.get_size()
        else:
            msg = "{} is not an instance of {}".format(value,
                                                       type(self).__name__)
            raise PackException(msg)

Calculate the total struct size in bytes.

For each struct attribute, sum the result of each one's ``get_size()``
method.

Args:
value: In structs, the user can assign other value instead of a
class' instance.

Returns:
int: Total number of bytes used by the struct.

Raises:
Exception: If the struct is not valid.


def _GetNetworkInfo(self, signatures_key):

    network_info = {}
    for category in signatures_key.GetSubkeys():
      for signature in category.GetSubkeys():
        profile_guid_value = signature.GetValueByName('ProfileGuid')
        if profile_guid_value:
          profile_guid = profile_guid_value.GetDataAsObject()
        else:
          continue

        default_gateway_mac_value = signature.GetValueByName(
            'DefaultGatewayMac')
        if default_gateway_mac_value:
          default_gateway_mac = ':'.join([
              '{0:02x}'.format(octet)
              for octet in bytearray(default_gateway_mac_value.data)])
        else:
          default_gateway_mac = None

        dns_suffix_value = signature.GetValueByName('DnsSuffix')
        if dns_suffix_value:
          dns_suffix = dns_suffix_value.GetDataAsObject()
        else:
          dns_suffix = None

        network_info[profile_guid] = (default_gateway_mac, dns_suffix)

    return network_info

Retrieves the network info within the signatures subkey.

Args:
signatures_key (dfwinreg.WinRegistryKey): a Windows Registry key.

Returns:
dict[str, tuple]: a tuple of default_gateway_mac and dns_suffix per
profile identifier (GUID).


def setup(self, check_all=None, exclude_private=None,
              exclude_uppercase=None, exclude_capitalized=None,
              exclude_unsupported=None, excluded_names=None,
              minmax=None, dataframe_format=None):

        assert self.shellwidget is not None

        self.check_all = check_all
        self.exclude_private = exclude_private
        self.exclude_uppercase = exclude_uppercase
        self.exclude_capitalized = exclude_capitalized
        self.exclude_unsupported = exclude_unsupported
        self.excluded_names = excluded_names
        self.minmax = minmax
        self.dataframe_format = dataframe_format

        if self.editor is not None:
            self.editor.setup_menu(minmax)
            self.editor.set_dataframe_format(dataframe_format)
            self.exclude_private_action.setChecked(exclude_private)
            self.exclude_uppercase_action.setChecked(exclude_uppercase)
            self.exclude_capitalized_action.setChecked(exclude_capitalized)
            self.exclude_unsupported_action.setChecked(exclude_unsupported)
            self.refresh_table()
            return

        self.editor = RemoteCollectionsEditorTableView(
                        self,
                        data=None,
                        minmax=minmax,
                        shellwidget=self.shellwidget,
                        dataframe_format=dataframe_format)

        self.editor.sig_option_changed.connect(self.sig_option_changed.emit)
        self.editor.sig_files_dropped.connect(self.import_data)
        self.editor.sig_free_memory.connect(self.sig_free_memory.emit)

        self.setup_option_actions(exclude_private, exclude_uppercase,
                                  exclude_capitalized, exclude_unsupported)

        self.tools_layout = QHBoxLayout()
        toolbar = self.setup_toolbar()
        for widget in toolbar:
            self.tools_layout.addWidget(widget)
        self.tools_layout.addStretch()
        self.setup_options_button()

        layout = create_plugin_layout(self.tools_layout, self.editor)
        self.setLayout(layout)

        self.sig_option_changed.connect(self.option_changed)

Setup the namespace browser with provided settings.

Args:
dataframe_format (string): default floating-point format for
DataFrame editor


def _verify_static_batch_size_equality(tensors, columns):
    expected_batch_size = None
    for i in range(0, len(tensors)):
        if tensors[i].shape.dims[0].value is not None:
            if expected_batch_size is None:
                bath_size_column_index = i
                expected_batch_size = tensors[i].shape.dims[0]
            elif not expected_batch_size.is_compatible_with(tensors[i].shape.dims[0]):
                raise ValueError('Batch size (first dimension) of each feature must be same. Batch size of columns ({}, {}): ({}, {})'.format(columns[bath_size_column_index].name, columns[i].name, expected_batch_size, tensors[i].shape.dims[0]))

Validates that the first dim (batch size) of all tensors are equal or None.

Args:
tensors: list of tensors to check.
columns: list of feature columns matching tensors. Will be used for error
messaging.

Raises:
ValueError: if one of the tensors has a variant batch size


def whois_emails(self, emails):

        api_name = 'opendns-whois-emails'
        fmt_url_path = u'whois/emails/{0}'
        return self._multi_get(api_name, fmt_url_path, emails)

Calls WHOIS Email end point

Args:
emails: An enumerable of string Emails
Returns:
A dict of {email: domain_result}


def __init__(self, grammar, latent_size, num_units):

    super(ProbabilisticGrammar, self).__init__()
    self.grammar = grammar
    self.latent_size = latent_size
    self.lstm = tf.compat.v1.nn.rnn_cell.LSTMCell(num_units)
    self.output_layer = tf.keras.layers.Dense(len(grammar.production_rules))

Constructs a probabilistic grammar.

Args:
grammar: An object representing a grammar. It has members
`nonterminal_symbols`, `alphabet`, `production_rules`, and
`start_symbol`, and a method `mask` determining (in)valid
production rules given a symbol.
latent_size: Number of dimensions in the latent code.
num_units: Number of units in the LSTM cell.


async def enqueue(self, query, queue_index=None, stop_current=False, shuffle=False):

        if query is None or query == "":
            return

        self.statuslog.info("Parsing {}".format(query))
        self.logger.debug("Enqueueing from query")

        indexnum = None
        if queue_index is not None:
            try:
                indexnum = int(queue_index) - 1
            except TypeError:
                self.statuslog.error("Play index argument must be a number")
                return
            except ValueError:
                self.statuslog.error("Play index argument must be a number")
                return

        if not self.vready:
            self.parse_query(query, indexnum, stop_current, shuffle)
        else:
            parse_thread = threading.Thread(
                target=self.parse_query,
                args=[query, indexnum, stop_current, shuffle])

            parse_thread.start()

Queues songs based on either a YouTube search or a link

Args:
query (str): Either a search term or a link
queue_index (str): The queue index to enqueue at (None for end)
stop_current (bool): Whether to stop the current song after the songs are queued
shuffle (bool): Whether to shuffle the added songs


def get_associated_profiles(self):

        uri = "{}/associatedProfiles".format(self.data['uri'])
        return self._helper.do_get(uri)

Gets the URIs of profiles which are using an Ethernet network.

Args:
id_or_uri: Can be either the logical interconnect group id or the logical interconnect group uri

Returns:
list: URIs of the associated profiles.


def gbest_idx(swarm):

    best = 0
    cmp = comparator(swarm[best].best_fitness)
    for (idx, particle) in enumerate(swarm):
        if cmp(particle.best_fitness, swarm[best].best_fitness):
            best = idx
    return best

gbest Neighbourhood topology function.

Args:
swarm: list: The list of particles.

Returns:
int: The index of the gbest particle.


def _parse_query_key(self, key, val, is_escaped):

        if key.endswith('__contains'):
            key = key[:-10]
            val = self._parse_query_modifier('contains', val, is_escaped)
        elif key.endswith('__range'):
            key = key[:-7]
            val = self._parse_query_modifier('range', val, is_escaped)
        elif key.endswith('__startswith'):
            key = key[:-12]
            val = self._parse_query_modifier('startswith', val, is_escaped)
        elif key.endswith('__endswith'):
            key = key[:-10]
            val = self._parse_query_modifier('endswith', val, is_escaped)

        elif key.endswith('__lt'):
            key = key[:-4]
            val = self._parse_query_modifier('lt', val, is_escaped)

        elif key.endswith('__gt'):
            key = key[:-4]
            val = self._parse_query_modifier('gt', val, is_escaped)

        elif key.endswith('__lte'):
            key = key[:-5]
            val = self._parse_query_modifier('lte', val, is_escaped)

        elif key.endswith('__gte'):
            key = key[:-5]
            val = self._parse_query_modifier('gte', val, is_escaped)
        elif key != 'NOKEY' and not is_escaped:
            val = self._escape_query(val)
        return key, val

Strips query modifier from key and call's the appropriate value modifier.

Args:
key (str): Query key
val: Query value

Returns:
Parsed query key and value.


def set_device_policy(device_policy):
    if device_policy == 'silent':
        context.context().device_policy = context.DEVICE_PLACEMENT_SILENT
    elif device_policy == 'silent_for_int32':
        context.context().device_policy = context.DEVICE_PLACEMENT_SILENT_FOR_INT32
    elif device_policy == 'warn':
        context.context().device_policy = context.DEVICE_PLACEMENT_WARN
    elif device_policy == 'explicit':
        context.context().device_policy = context.DEVICE_PLACEMENT_EXPLICIT
    elif device_policy is None:
        context.context().device_policy = None
    else:
        raise ValueError(f'Invalid argument `device_policy`: {device_policy!r}. Please refer to https:

Sets the current thread device policy.

The device policy controls how operations requiring inputs on a specific
device (e.g., on GPU:0) handle inputs on a different device (e.g. GPU:1).

When using the default, an appropriate policy will be picked automatically.
The default policy may change over time.

This function only sets the device policy for the current thread. Any
subsequently started thread will again use the default policy.

Args:
device_policy: A device policy.
Valid values:
- None: Switch to a system default.
- 'warn': Copies the tensors which are not on the right device and logs a
warning.
- 'explicit': Raises an error if the placement is not as required.
- 'silent': Silently copies the tensors. Note that this may hide
performance problems as there is no notification provided when
operations are blocked on the tensor being copied between devices.
- 'silent_for_int32': silently copies `int32` tensors, raising errors on
the other ones.

Raises:
ValueError: If an invalid `device_policy` is passed.


def WriteUInt160(self, value):
    if (type(value) is UInt160):
        value.Serialize(self)
    else:
        raise Exception('value must be UInt160 instance ')

Write a UInt160 type to the stream.

Args:
value (UInt160):

Raises:
Exception: when `value` is not of neocore.UInt160 type.


def CopyFrom(self, other_msg):

    if self is other_msg:
      return
    self.Clear()
    self.MergeFrom(other_msg)

Copies the content of the specified message into the current message.

The method clears the current message and then merges the specified
message using MergeFrom.

Args:
other_msg: Message to copy into the current one.


def _update_section_state(line_info, state):
    section_updated = False
    google_section_permitted = _google_section_permitted(line_info, state)
    google_section = google_section_permitted and _google_section(line_info)
    if google_section:
        state.section.format = Formats.GOOGLE
        state.section.title = google_section
        line_info.remaining = _get_after_google_header(line_info)
        line_info.remaining_raw = line_info.remaining
        section_updated = True
    rst_section = _rst_section(line_info)
    if rst_section:
        state.section.format = Formats.RST
        state.section.title = rst_section
        line_info.remaining = _get_after_directive(line_info)
        line_info.remaining_raw = line_info.remaining
        section_updated = True
    numpy_section = _numpy_section(line_info)
    if numpy_section:
        state.section.format = Formats.NUMPY
        state.section.title = numpy_section
        line_info.remaining = ''
        line_info.remaining_raw = line_info.remaining
        section_updated = True
    if section_updated:
        state.section.new = True
        state.section.indentation = line_info.indentation
        state.section.line1_indentation = line_info.next.indentation
    else:
        state.section.new = False

Uses line_info to determine the current section of the docstring.

Updates state and line_info.remaining.

Args:
line_info: Information about the current line.
state: The state of the parser.


def load_qrandom():
    fname = 'datasets/qrandom.npy'
    with pkg_resources.resource_stream(__name__, fname) as f:
        return np.load(f)

Loads a set of 10000 random numbers generated by qrandom.

This dataset can be used when you want to do some limited tests with "true"
random data without an internet connection.

Returns:
int array
the dataset


def output_reference(self, name):
    if (name not in self.output_names):
        raise ValueError('Invalid output "{}"'.format(name))
    return Reference(step_name=self.name_in_workflow, output_name=name)

Return a reference to the given output for use in an input
of a next Step.

For a Step named `echo` that has an output called `echoed`, the
reference `echo/echoed` is returned.

Args:
name (str): the name of the Step output
Raises:
ValueError: The name provided is not a valid output name for this
Step.


def __init__(self, graph_def, input_tensors, output_tensors, input_arrays_with_shape=None, output_arrays=None, experimental_debug_info_func=None):
    super(TFLiteConverter, self).__init__(graph_def, input_tensors, output_tensors, input_arrays_with_shape, output_arrays, experimental_debug_info_func)

Constructor for TFLiteConverter.

Args:
graph_def: Frozen TensorFlow GraphDef.
input_tensors: List of input tensors. Type and shape are computed using
`foo.shape` and `foo.dtype`.
output_tensors: List of output tensors (only .name is used from this).
input_arrays_with_shape: Tuple of strings representing input tensor names
and list of integers representing input shapes (e.g., [("foo" : [1, 16,
16, 3])]). Use only when graph cannot be loaded into TensorFlow and when
`input_tensors` and `output_tensors` are None. (default None)
output_arrays: List of output tensors to freeze graph with. Use only when
graph cannot be loaded into TensorFlow and when `input_tensors` and
`output_tensors` are None. (default None)
experimental_debug_info_func: An experimental function to retrieve the
graph debug info for a set of nodes from the `graph_def`.

Raises:
ValueError: Invalid arguments.


def coder_benchmark_factory(coder, generate_fn):

    class CoderBenchmark(object):

        def __init__(self, num_elements_per_benchmark):
            self._coder = coders.IterableCoder(coder)
            self._list = [generate_fn() for _ in range(num_elements_per_benchmark)]

        def __call__(self):
            _ = self._coder.decode(self._coder.encode(self._list))
    CoderBenchmark.__name__ = '%s, %s' % (generate_fn.__name__, str(coder))
    return CoderBenchmark

Creates a benchmark that encodes and decodes a list of elements.

Args:
coder: coder to use to encode an element.
generate_fn: a callable that generates an element.


def _pack(formatstring, value):

    _checkString(formatstring, description='formatstring', minlength=1)

    try:
        result = struct.pack(formatstring, value)
    except:
        errortext = 'The value to send is probably out of range, as the num-to-bytestring conversion failed.'
        errortext += ' Value: {0!r} Struct format code is: {1}'
        raise ValueError(errortext.format(value, formatstring))

    if sys.version_info[0] > 2:
        return str(result, encoding='latin1')
    return result

Pack a value into a bytestring.

Uses the built-in :mod:`struct` Python module.

Args:
* formatstring (str): String for the packing. See the :mod:`struct` module for details.
* value (depends on formatstring): The value to be packed

Returns:
A bytestring (str).

Raises:
ValueError

Note that the :mod:`struct` module produces byte buffers for Python3,
but bytestrings for Python2. This is compensated for automatically.


def __init__(self, xid=None, command=None, flags=None, meter_id=None,
                 bands=None):

        super().__init__(xid)
        self.command = command
        self.flags = flags
        self.meter_id = meter_id
        self.bands = bands

Create a MeterMod with the optional parameters below.

Args:
xid (int): Headers transaction id. Defaults to random.
command (MeterModCommand): One of OFPMC_*.
flags (MeterFlags): One of OFPMF_*.
meter_id (int): Meter instance.
bands (MeterBandHeader): The bands length is inferred from the
length field in the header.


def _einsum_v1_parse_and_resolve_equation(equation, input_shapes):
    equation = equation.replace(' ', '')
    match = re.match('^([a-zA-Z,.]+)(->[a-zA-Z.]*)?$', equation)
    if not match:
        raise ValueError(f'Indices have incorrect format. Received: {equation}.')
    input_axis_labels = match.group(1).split(',')
    output_axis_labels = match.group(2)[2:] if match.group(2) else None
    if len(input_shapes) != len(input_axis_labels):
        raise ValueError(f'Got {len(input_shapes)} arguments for equation "{equation}", expecting {len(input_axis_labels)}.')
    ellipsis_axes = ''
    if '...' in equation:
        unused = ''.join((c for c in string.ascii_letters if c not in ''.join(input_axis_labels)))
        for i, ax in enumerate(input_axis_labels):
            if '...' in ax:
                parts = ax.split('...')
                if len(parts) != 2:
                    raise ValueError(f'Unable to resolve ellipsis. Excess number found: {len(parts) - 1} vs 1.')
                if input_shapes[i].ndims is None:
                    raise ValueError('Unable to statically infer ellipsis axes. The input shapes has a dynamic dimensionality.')
                n = input_shapes[i].ndims - len(''.join(parts))
                if n < 0:
                    raise ValueError('Ellipses lengths do not match.')
                if len(unused) < n:
                    raise ValueError('Unable to resolve ellipsis, too many distinct labels.')
                replace_axes = unused[-n:] if n > 0 else ''
                input_axis_labels[i] = input_axis_labels[i].replace('...', replace_axes)
                if len(replace_axes) > len(ellipsis_axes):
                    ellipsis_axes = replace_axes
        if any(('.' in ax for ax in input_axis_labels)):
            raise ValueError(f'Period "." found outside of ellipsis in input {input_axis_labels}.')
        if output_axis_labels is not None:
            output_axis_labels = output_axis_labels.replace('...', ellipsis_axes)
            if '.' in output_axis_labels:
                raise ValueError(f'Period "." found outside of ellipsis in output {output_axis_labels}.')
    if output_axis_labels is None:
        axis_labels = set(''.join(input_axis_labels)) - set(ellipsis_axes)
        indices = ''.join(sorted(axis_labels))
        counts = {ax: 0 for ax in indices}
        for axes_ in input_axis_labels:
            for ax in axes_:
                if ax not in ellipsis_axes:
                    counts[ax] += 1
        output_axis_labels = ellipsis_axes + ''.join(sorted((ax for ax in axis_labels if counts[ax] == 1)))
    return (input_axis_labels, output_axis_labels)

Helper for einsum() that splits/resolves inputs & outputs.

Args:
equation: Equation string given as argument to einsum().
input_shapes: List of the shapes of all inputs given to einsum()

Returns:
input_axis_labels, output_axis_labels where:
input_axis_labels: List of length len(input_shapes) of strings
representing the character label for each dimension of each given input,
resolving any broadcast (...) axes,
output_axis_labels: A string of character labels for each axes of output
tensor, filling in missing output subscripts and broadcast axes.

Raises:
ValueError: If equation is in the uncorrect format, incorrect number of
inputs given or broadcast axes "..." or output axes could not be resolved.


def update(self, rid, data, raise_on_error=True):

        cache_data = {'cache-date': self._dt_to_epoch(datetime.now()), 'cache-data': data}
        return self.ds.put(rid, cache_data, raise_on_error)

Write updated cache data to the DataStore.

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

Returns:
object : Python request response.


def ExtractEvents(
      self, parser_mediator, registry_key, codepage='cp1252', **kwargs):

    self._ParseMRUListKey(parser_mediator, registry_key, codepage=codepage)

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.
codepage (Optional[str]): extended ASCII string codepage.


def expected_h(nvals, fit="RANSAC"):

  rsvals = [expected_rs(n) for n in nvals]
  poly = poly_fit(np.log(nvals), np.log(rsvals), 1, fit=fit)
  return poly[0]

Uses expected_rs to calculate the expected value for the Hurst exponent h
based on the values of n used for the calculation.

Args:
nvals (iterable of int):
the values of n used to calculate the individual (R/S)_n

KWargs:
fit (str):
the fitting method to use for the line fit, either 'poly' for normal
least squares polynomial fitting or 'RANSAC' for RANSAC-fitting which
is more robust to outliers

Returns:
float:
expected h for white noise


def _ParsePlistKeyValue(self, knowledge_base, name, value):

    if not knowledge_base.GetValue('keyboard_layout'):
      if name in self._PLIST_KEYS:
        if isinstance(value, (list, tuple)):
          value = value[0]

        _, _, keyboard_layout = value.rpartition('.')

        knowledge_base.SetValue('keyboard_layout', keyboard_layout)

Parses a plist key value.

Args:
knowledge_base (KnowledgeBase): to fill with preprocessing information.
name (str): name of the plist key.
value (str): value of the plist key.


def _log_device_compatibility_check(policy_name, gpu_details_list):
    if policy_name != 'mixed_float16':
        return
    supported_device_strs = []
    unsupported_device_strs = []
    for details in gpu_details_list:
        name = details.get('device_name', 'Unknown GPU')
        cc = details.get('compute_capability')
        if cc:
            device_str = '%s, compute capability %s.%s' % (name, cc[0], cc[1])
            if cc >= (7, 0):
                supported_device_strs.append(device_str)
            else:
                unsupported_device_strs.append(device_str)
        else:
            unsupported_device_strs.append(name + ', no compute capability (probably not an Nvidia GPU)')
    if unsupported_device_strs:
        warning_str = _COMPAT_CHECK_WARNING_PREFIX + '\n'
        if supported_device_strs:
            warning_str += 'Some of your GPUs may run slowly with dtype policy mixed_float16 because they do not all have compute capability of at least 7.0. Your GPUs:\n'
        elif len(unsupported_device_strs) == 1:
            warning_str += 'Your GPU may run slowly with dtype policy mixed_float16 because it does not have compute capability of at least 7.0. Your GPU:\n'
        else:
            warning_str += 'Your GPUs may run slowly with dtype policy mixed_float16 because they do not have compute capability of at least 7.0. Your GPUs:\n'
        for device_str in _dedup_strings(supported_device_strs + unsupported_device_strs):
            warning_str += '  ' + device_str + '\n'
        warning_str += 'See https:
        warning_str += _COMPAT_CHECK_WARNING_SUFFIX
        tf_logging.warning(warning_str)
    elif not supported_device_strs:
        tf_logging.warning('%s\nThe dtype policy mixed_float16 may run slowly because this machine does not have a GPU. Only Nvidia GPUs with compute capability of at least 7.0 run quickly with mixed_float16.\n%s' % (_COMPAT_CHECK_WARNING_PREFIX, _COMPAT_CHECK_WARNING_SUFFIX))
    elif len(supported_device_strs) == 1:
        tf_logging.info('%s\nYour GPU will likely run quickly with dtype policy mixed_float16 as it has compute capability of at least 7.0. Your GPU: %s' % (_COMPAT_CHECK_OK_PREFIX, supported_device_strs[0]))
    else:
        tf_logging.info('%s\nYour GPUs will likely run quickly with dtype policy mixed_float16 as they all have compute capability of at least 7.0' % _COMPAT_CHECK_OK_PREFIX)

Logs a compatibility check if the devices support the policy.

Currently only logs for the policy mixed_float16.

Args:
policy_name: The name of the dtype policy.
gpu_details_list: A list of dicts, one dict per GPU. Each dict
is the device details for a GPU, as returned by
`tf.config.experimental.get_device_details()`.


def load(self, validate=True):
    self._load()
    try:
        self.config = self._load_config(self.system_config_file)
        user = self._load_config(self.global_config_file)
        config = self._load_config(self.config_file)
        local = self._load_config(self.config_local_file)
        for conf in [user, config, local]:
            self.config = self._merge(self.config, conf)
        if validate:
            self.config = Schema(self.SCHEMA).validate(self.config)
        self.config = configobj.ConfigObj(self.config, write_empty_values=True)
        self.config.filename = self.config_file
        self._resolve_paths(self.config, self.config_file)
    except Exception as ex:
        raise ConfigError(ex)

Loads config from all the config files.

Args:
validate (bool): optional flag to tell dvc if it should validate
the config or just load it as is. 'True' by default.

Raises:
dvc.config.ConfigError: thrown if config has invalid format.


def __init__(self, url, access_token, index,
                 source="parsedmarc", verify=True, timeout=60):

        url = urlparse(url)
        self.url = "{0}:
                                                                   url.netloc)
        self.access_token = access_token.lstrip("Splunk ")
        self.index = index
        self.host = socket.getfqdn()
        self.source = source
        self.session = requests.Session()
        self.timeout = timeout
        self.session.verify = verify
        self._common_data = dict(host=self.host, source=self.source,
                                 index=self.index)

        self.session.headers = {
            "User-Agent": "parsedmarc/{0}".format(__version__),
            "Authorization": "Splunk {0}".format(self.access_token)
        }

Initializes the HECClient
Args:
url (str): The URL of the HEC
access_token (str): The HEC access token
index (str): The name of the index
source (str): The source name
verify (bool): Verify SSL certificates
timeout (float): Number of seconds to wait for the server to send
data before giving up


def comment(data, what):
    data = data.splitlines()
    data = map((lambda x: (('
    return '\n'.join(data)

Comments line containing `what` in string `data`.

Args:
data (str): Configuration file in string.
what (str): Line which will be commented out.

Returns:
str: Configuration file with commented `what`.


def expect_false(condition, msg, extras=None):
    try:
        asserts.assert_false(condition, msg, extras)
    except signals.TestSignal as e:
        logging.exception('Expected a `False` value, got `True`.')
        recorder.add_error(e)

Expects an expression evaluates to False.

If the expectation is not met, the test is marked as fail after its
execution finishes.

Args:
expr: The expression that is evaluated.
msg: A string explaining the details in case of failure.
extras: An optional field for extra information to be included in test
result.


def markdown_to_text(body):

    md = markdown.markdown(body, extensions=[
        'markdown.extensions.extra'
    ])

    soup = BeautifulSoup(md, 'html.parser')

    return soup.get_text()

Converts markdown to text.

Args:
body: markdown (or plaintext, or maybe HTML) input

Returns:
Plaintext with all tags and frills removed


def __init__(self, event_timestamp, duration=5):

    super(TimeSlice, self).__init__()
    self.duration = duration
    self.event_timestamp = event_timestamp

Initializes the time slice.

Args:
event_timestamp (int): event timestamp of the time slice or None.
duration (Optional[int]): duration of the time slice in minutes.
The default is 5, which represent 2.5 minutes before and 2.5 minutes
after the event timestamp.


def attention_mask_ignore_padding(inputs, dtype=tf.float32):
    inputs = rename_length_to_memory_length(inputs)
    return (mtf.cast(mtf.equal(inputs, 0), dtype) * (- 1000000000.0))

Bias for encoder-decoder attention.

Args:
inputs: a mtf.Tensor with shape [..., length_dim]
dtype: a tf.dtype

Returns:
a mtf.Tensor with shape [..., memory_length_dim]


def clean(self, force: bool=False):
    with (yield from self._lock):
        for connection in tuple(self.ready):
            if (force or connection.closed()):
                connection.close()
                self.ready.remove(connection)

Clean closed connections.

Args:
force: Clean connected and idle connections too.

Coroutine.


def protocol_version_to_kmip_version(value):

    if not isinstance(value, ProtocolVersion):
        return None

    if value.major == 1:
        if value.minor == 0:
            return enums.KMIPVersion.KMIP_1_0
        elif value.minor == 1:
            return enums.KMIPVersion.KMIP_1_1
        elif value.minor == 2:
            return enums.KMIPVersion.KMIP_1_2
        elif value.minor == 3:
            return enums.KMIPVersion.KMIP_1_3
        elif value.minor == 4:
            return enums.KMIPVersion.KMIP_1_4
        else:
            return None
    else:
        return None

Convert a ProtocolVersion struct to its KMIPVersion enumeration equivalent.

Args:
value (ProtocolVersion): A ProtocolVersion struct to be converted into
a KMIPVersion enumeration.

Returns:
KMIPVersion: The enumeration equivalent of the struct. If the struct
cannot be converted to a valid enumeration, None is returned.


def get(name):
    for matcher in matchers:
        if ((matcher.__name__ == name) or (getattr(matcher, 'name', None) == name)):
            return matcher

Returns a matcher instance by class or alias name.

Arguments:
name (str): matcher class name or alias.

Returns:
matcher: found matcher instance, otherwise ``None``.


def key_prefix(self) -> str:
    return self.__class__.__qualname__

Prefix for key to avoid collisions from different Processors.

Defaults to classname. Processor() should override this if, for example, it
accepts arguments that change output of __call__.

Returns:
Prefix that will be added to key.


def NewFromJSON(data):
    if data.get('shakes', None):
        shakes = [Shake.NewFromJSON(shk) for shk in data.get('shakes')]
    else:
        shakes = None
    return User(id=data.get('id', None), name=data.get('name', None), profile_image_url=data.get('profile_image_url', None), about=data.get('about', None), website=data.get('website', None), shakes=shakes)

Create a new User instance from a JSON dict.

Args:
data (dict): JSON dictionary representing a user.

Returns:
A User instance.


def apply(self, func, **kwargs):

        oid = self.oid
        self.call_queue.append((func, kwargs))

        def call_queue_closure(oid_obj, call_queues):
            for func, kwargs in call_queues:
                if isinstance(func, ray.ObjectID):
                    func = ray.get(func)
                if isinstance(kwargs, ray.ObjectID):
                    kwargs = ray.get(kwargs)

                oid_obj = func(oid_obj, **kwargs)

            return oid_obj

        oid = deploy_ray_func.remote(
            call_queue_closure, oid, kwargs={"call_queues": self.call_queue}
        )
        self.call_queue = []

        return PyarrowOnRayFramePartition(oid)

Apply a function to the object stored in this partition.

Note: It does not matter if func is callable or an ObjectID. Ray will
handle it correctly either way. The keyword arguments are sent as a
dictionary.

Args:
func: The function to apply.

Returns:
A RayRemotePartition object.


def _GetStatus(self, two_factor=False):

    params = ['status']
    if two_factor:
      params += ['--twofactor']
    retcode = self._RunOsLoginControl(params)
    if retcode is None:
      if self.oslogin_installed:
        self.logger.warning('OS Login not installed.')
        self.oslogin_installed = False
      return None

    self.oslogin_installed = True
    if not os.path.exists(constants.OSLOGIN_NSS_CACHE):
      return False
    return not retcode

Check whether OS Login is installed.

Args:
two_factor: bool, True if two factor should be enabled.

Returns:
bool, True if OS Login is installed.


def from_representation(self, representation):
    object_dict = {}
    failed = {}
    for (name, field) in self.fields.items():
        if (name not in representation):
            continue
        try:
            if ((not isinstance(representation[name], (list, tuple))) and field.many):
                raise ValueError('field should be sequence')
            source = _source(name, field)
            value = representation[name]
            if field.many:
                if (not field.allow_null):
                    object_dict[source] = [field.from_representation(single_value) for single_value in value]
                else:
                    object_dict[source] = [(field.from_representation(single_value) if (single_value is not None) else None) for single_value in value]
            elif (not field.allow_null):
                object_dict[source] = field.from_representation(value)
            else:
                object_dict[source] = (field.from_representation(value) if value else None)
        except ValueError as err:
            failed[name] = str(err)
    if failed:
        try:
            self.validate(object_dict)
            raise DeserializationError()
        except DeserializationError as err:
            err.failed = failed
            raise
    return object_dict

Convert given representation dict into internal object.

Internal object is simply a dictionary of values with respect to field
sources.

This does not check if all required fields exist or values are
valid in terms of value validation
(see: :meth:`BaseField.validate()`) but still requires all of passed
representation values to be well formed representation (success call
to ``field.from_representation``).

In case of malformed representation it will run additional validation
only to provide a full detailed exception about all that might be
wrong with provided representation.

Args:
representation (dict): dictionary with field representation values

Raises:
DeserializationError: when at least one representation field
is not formed as expected by field object. Information
about additional forbidden/missing/invalid fields is provided
as well.


def _average_precision(self, rec, prec):

        mrec = np.concatenate(([0.], rec, [1.]))
        mpre = np.concatenate(([0.], prec, [0.]))

        for i in range(mpre.size - 1, 0, -1):
            mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])

        i = np.where(mrec[1:] != mrec[:-1])[0]

        ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])
        return ap

calculate average precision

Params:
----------
rec : numpy.array
cumulated recall
prec : numpy.array
cumulated precision
Returns:
----------
ap as float


def old_tracer_correlation( self ):

        if self.has_run:
            return self.atoms.sum_dr_squared() / float( self.number_of_jumps )
        else:
            return None

Deprecated tracer correlation factor for this simulation.

Args:
None

Returns:
(Float): The tracer correlation factor, f.

Notes:
This function assumes that the jump distance between sites has
been normalised to a=1. If the jump distance is not equal to 1
then the value returned by this function should be divided by a^2.
Even better, use `self.tracer_correlation`.


def listen_now_items(self):
    response = self._call(mc_calls.ListenNowGetListenNowItems)
    listen_now_item_list = response.body.get('listennow_items', [])
    listen_now_items = defaultdict(list)
    for item in listen_now_item_list:
        type_ = f"{ListenNowItemType(item['type']).name}s"
        listen_now_items[type_].append(item)
    return dict(listen_now_items)

Get a listing of Listen Now items.

Note:
This does not include situations;
use the :meth:`situations` method instead.

Returns:
dict: With ``albums`` and ``stations`` keys of listen now items.


def get_instance_type_parameter(self, name: str, node: 'cfg.CFGNode | None'=None):
    del name
    if node is None:
        node = self.ctx.root_node
    return self.ctx.new_unsolvable(node)

Get a cfg.Variable of the instance's values for the type parameter.

Treating self as an abstract.Instance, gets the variable of its values for
the given type parameter. For the real implementation, see
SimpleValue.get_instance_type_parameter.

Args:
name: The name of the type parameter.
node: Optionally, the current CFG node.

Returns:
A Variable which may be empty.


def concept(self, mechanism, purviews=False, cause_purviews=False, effect_purviews=False):
    log.debug('Computing concept %s...', mechanism)
    if (not mechanism):
        log.debug('Empty concept; returning null concept')
        return self.null_concept
    cause = self.mic(mechanism, purviews=(cause_purviews or purviews))
    effect = self.mie(mechanism, purviews=(effect_purviews or purviews))
    log.debug('Found concept %s', mechanism)
    return Concept(mechanism=mechanism, cause=cause, effect=effect, subsystem=self)

Return the concept specified by a mechanism within this subsytem.

Args:
mechanism (tuple[int]): The candidate set of nodes.

Keyword Args:
purviews (tuple[tuple[int]]): Restrict the possible purviews to
those in this list.
cause_purviews (tuple[tuple[int]]): Restrict the possible cause
purviews to those in this list. Takes precedence over
``purviews``.
effect_purviews (tuple[tuple[int]]): Restrict the possible effect
purviews to those in this list. Takes precedence over
``purviews``.

Returns:
Concept: The pair of maximally irreducible cause/effect repertoires
that constitute the concept specified by the given mechanism.


def longest_one_seg_prefix(self, word):
    match = self.seg_regex.match(word)
    if match:
        return match.group(0)
    else:
        return ''

Return longest IPA Unicode prefix of `word`

Args:
word (unicode): word as IPA string

Returns:
unicode: longest single-segment prefix of `word`


def initialize_from_assignments(assignments, k, max_assign_weight=0.75):

    cells = len(assignments)
    init_W = np.zeros((k, cells))
    for i, a in enumerate(assignments):

        init_W[a, i] = max_assign_weight
        for a2 in range(k):
            if a2!=a:
                init_W[a2, i] = (1-max_assign_weight)/(k-1)
    return init_W/init_W.sum(0)

Creates a weight initialization matrix from Poisson clustering assignments.

Args:
assignments (array): 1D array of integers, of length cells
k (int): number of states/clusters
max_assign_weight (float, optional): between 0 and 1 - how much weight to assign to the highest cluster. Default: 0.75

Returns:
init_W (array): k x cells


def cmd2(command, shell=False, detatch=False, verbose=False, verbout=None):

    import shlex
    if isinstance(command, (list, tuple)):
        raise ValueError('command tuple not supported yet')
    args = shlex.split(command, posix=not WIN32)
    if verbose is True:
        verbose = 2
    if verbout is None:
        verbout = verbose >= 1
    if verbose >= 2:
        print('+=== START CMD2 ===')
        print('Command:')
        print(command)
        if verbout:
            print('----')
            print('Stdout:')
    proc = subprocess.Popen(args, stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT, shell=shell,
                            universal_newlines=True)
    if detatch:
        info = {'proc': proc}
    else:
        write_fn = sys.stdout.write
        flush_fn = sys.stdout.flush
        logged_out = []
        for line in _run_process(proc):

            line_ = line if six.PY2 else line
            if len(line_) > 0:
                if verbout:
                    write_fn(line_)
                    flush_fn()
                logged_out.append(line)
        try:
            from utool import util_str

            out = ''.join(logged_out)
        except UnicodeDecodeError:
            from utool import util_str
            logged_out = util_str.ensure_unicode_strlist(logged_out)

            out = ''.join(logged_out)

        (out_, err) = proc.communicate()
        ret = proc.wait()
        info = {
            'out': out,
            'err': err,
            'ret': ret,
        }
    if verbose >= 2:
        print('L___ END CMD2 ___')
    return info

Trying to clean up cmd

Args:
command (str): string command
shell (bool): if True, process is run in shell
detatch (bool): if True, process is run in background
verbose (int): verbosity mode
verbout (bool): if True, `command` writes to stdout in realtime.
defaults to True iff verbose > 0

Returns:
dict: info - information about command status


def expand_value_set_definition(self, value_set: value_set_pb2.ValueSet) -> value_set_pb2.ValueSet:
    base_url, request_url = _expansion_request_url_for_value_set_url(value_set.url.value)
    request_json = json_format.print_fhir_to_json_string(value_set).encode('utf-8')
    session_ = self.create_session()
    session_.headers.update({'Accept': 'application/json', 'Content-Type': 'application/json'})
    auth = self.auth_per_terminology_server.get(base_url)
    if auth is not None:
        if isinstance(auth, tuple) and len(auth) == 2:
            logging.debug('Using Basic auth for auth')
            session_.auth = auth
        else:
            logging.debug('Using Bearer token for auth')
            session_.headers['Authorization'] = auth
    logging.info('Expanding value set url: %s version: %s using terminology service: %s', value_set.url.value, value_set.version.value, base_url)
    with session_ as session:

        def request_func(offset: int) -> requests.Response:
            return session.post(request_url, data=request_json, params={'offset': offset})
        expanded_value_set = _paginate_expand_value_set_request(request_func, value_set.url.value, value_set.version.value)
    logging.info('Retrieved %d codes for value set url: %s version: %s using terminology service: %s', len(expanded_value_set.expansion.contains), value_set.url.value, value_set.version.value, base_url)
    return expanded_value_set

Expands the value set definition using a terminology server.

Requests an expansion of the given value set from the appropriate
terminology server. Attempts to expand arbitrary value sets by passing their
entire definition to the terminology service for expansion.

If possible, requests expansion from the domain associated with the value
set's URL. If the value set URL is not associated with a known terminology
service, uses the tx.fhir.org service as it is able to expand value sets
defined outside its own specifications.

Retrieves the current definition of the value set from the terminology
service as well as its expansion.

Args:
value_set: The value set to expand.

Returns:
The current definition of the value set from the server with its expanded
codes present.


def get(cls, resource_id):

        res = Resource.get(resource_id)
        return cls(res) if res else None

Returns the class object identified by `resource_id`

Args:
resource_id (str): Unique EC2 Instance ID to load from database

Returns:
EC2 Instance object if found, else None


def plot_heatmap(data, title='Heatmap', show_legend=True, show_labels=True, label_fmt='.2f', vmin=None, vmax=None, figsize=None, label_color='w', cmap='RdBu', **kwargs):
    (fig, ax) = plt.subplots(figsize=figsize)
    heatmap = ax.pcolor(data, vmin=vmin, vmax=vmax, cmap=cmap)
    ax.invert_yaxis()
    if (title is not None):
        plt.title(title)
    if show_legend:
        fig.colorbar(heatmap)
    if show_labels:
        vals = data.values
        for x in range(data.shape[0]):
            for y in range(data.shape[1]):
                plt.text((x + 0.5), (y + 0.5), format(vals[(y, x)], label_fmt), horizontalalignment='center', verticalalignment='center', color=label_color)
    plt.yticks(np.arange(0.5, len(data.index), 1), data.index)
    plt.xticks(np.arange(0.5, len(data.columns), 1), data.columns)
    return plt

Plot a heatmap using matplotlib's pcolor.

Args:
* data (DataFrame): DataFrame to plot. Usually small matrix (ex.
correlation matrix).
* title (string): Plot title
* show_legend (bool): Show color legend
* show_labels (bool): Show value labels
* label_fmt (str): Label format string
* vmin (float): Min value for scale
* vmax (float): Max value for scale
* cmap (string): Color map
* kwargs: Passed to matplotlib's pcolor


def render_policy_template(account_number='', app='coreforrest', env='dev', group='forrest', items=None, pipeline_settings=None, region='us-east-1', service=''):
    statements = []
    rendered_service_policy = get_template('infrastructure/iam/{0}.json.j2'.format(service), account_number=account_number, app=app, env=env, group=group, region=region, items=items, settings=pipeline_settings)
    try:
        statement_block = json.loads(rendered_service_policy)
        statements.append(statement_block)
    except ValueError:
        LOG.debug('Need to make %s template into list.', service)
        statements = json.loads('[{0}]'.format(rendered_service_policy))
    LOG.debug('Rendered IAM Policy statements: %s', statements)
    return statements

Render IAM Policy template.

To support multiple statement blocks, JSON objects can be separated by a
comma. This function attempts to turn any invalid JSON into a valid list
based on this comma separated assumption.

Args:
account_number (str): AWS Account number.
app (str): Name of Spinnaker Application.
env (str): Environment/Account in AWS
group (str):A Application group/namespace
items (list): Resource names used to create a Policy per Resource.
region (str): AWS region.
pipeline_settings (dict): Settings from *pipeline.json*.
service (str): Name of cloud service to find matching IAM Policy
template.

Returns:
list: IAM Policy :obj:`dict` statements for the given service.


def parse(self, argument):
    if isinstance(argument, list):
        return argument
    elif (not argument):
        return []
    else:
        if self._comma_compat:
            argument = argument.replace(',', ' ')
        return argument.split()

Parses argument as whitespace-separated list of strings.

It also parses argument as comma-separated list of strings if requested.

Args:
argument: string argument passed in the commandline.

Returns:
[str], the parsed flag value.


def must_run_on_cpu(node, pin_variables_on_cpu=False):
    if isinstance(node, ops.Operation):
        node_def = node.node_def
    else:
        assert isinstance(node, node_def_pb2.NodeDef)
        node_def = node
    if pin_variables_on_cpu and _is_variable_op(node_def.op):
        return True
    if node_def.op == 'Const':
        dtype = node_def.attr['dtype'].type
        if dtype == dtypes.string or dtype == dtypes.int32:
            return True
    if node_def.op in ['DynamicStitch', 'ParallelDynamicStitch']:
        dtype = node_def.attr['T'].type
        if dtype == dtypes.int32:
            return True
    if node_def.op in ['Cast']:
        dtype = node_def.attr['SrcT'].type
        if dtype == dtypes.int32:
            return True
    return False

Returns True if the given node_def must run on CPU, otherwise False.

Args:
node: The node to be assigned to a device. Could be either an ops.Operation
or NodeDef.
pin_variables_on_cpu: If True, this function will return False if node_def
represents a variable-related op.

Returns:
True if the given node must run on CPU, otherwise False.


def master(self, task_type=None, task_id=None, rpc_layer=None):
    if task_type is not None and task_id is not None:
        master = self.cluster_spec().task_address(task_type, task_id)
        return format_master_url(master, rpc_layer or self._rpc_layer)
    return self._cluster_resolvers[0].master(rpc_layer=rpc_layer)

Returns the master address to use when creating a session.

This usually returns the master from the first ClusterResolver passed in,
but you can override this by specifying the task_type and task_id.

Note: this is only useful for TensorFlow 1.x.

Args:
task_type: (Optional) The type of the TensorFlow task of the master.
task_id: (Optional) The index of the TensorFlow task of the master.
rpc_layer: (Optional) The RPC protocol for the given cluster.

Returns:
The name or URL of the session master.


def clean_all(G, settings):
    quiet = settings['quiet']
    recon = settings['recon']
    sprint = settings['sprint']
    error = settings['error']
    all_outputs = []
    for node in G.nodes(data=True):
        if ('output' in node[1]):
            for item in get_all_outputs(node[1]):
                all_outputs.append(item)
    all_outputs.append('.shastore')
    retcode = 0
    for item in sorted(all_outputs):
        if os.path.isfile(item):
            if recon:
                sprint('Would remove file: {}'.format(item))
                continue
            sprint("Attempting to remove file '{}'", level='verbose')
            try:
                os.remove(item)
                sprint('Removed file', level='verbose')
            except:
                errmes = "Error: file '{}' failed to be removed"
                error(errmes.format(item))
                retcode = 1
    if ((not retcode) and (not recon)):
        sprint('All clean', color=True)
    return retcode

Removes all the output files from all targets. Takes
the graph as the only argument

Args:
The networkx graph object
The settings dictionary

Returns:
0 if successful
1 if removing even one file failed


def language_from_str(language_def, metamodel):

    if type(language_def) is not text:
        raise TextXError("textX accepts only unicode strings.")

    if metamodel.debug:
        metamodel.dprint("*** PARSING LANGUAGE DEFINITION ***")

    if metamodel.debug in textX_parsers:
        parser = textX_parsers[metamodel.debug]
    else:

        parser = ParserPython(textx_model, comment_def=comment,
                              ignore_case=False,
                              reduce_tree=False,
                              memoization=metamodel.memoization,
                              debug=metamodel.debug,
                              file=metamodel.file)

        textX_parsers[metamodel.debug] = parser

    try:
        parse_tree = parser.parse(language_def)
    except NoMatch as e:
        line, col = parser.pos_to_linecol(e.position)
        raise TextXSyntaxError(text(e), line, col)

    lang_parser = visit_parse_tree(parse_tree,
                                   TextXVisitor(parser, metamodel))

    metamodel.validate()

    lang_parser.metamodel = metamodel
    metamodel._parser_blueprint = lang_parser

    if metamodel.debug:

        PMDOTExporter().exportFile(
            lang_parser.parser_model,
            "{}_parser_model.dot".format(metamodel.rootcls.__name__))

    return lang_parser

Constructs parser and initializes metamodel from language description
given in textX language.

Args:
language_def (str): A language description in textX.
metamodel (TextXMetaModel): A metamodel to initialize.

Returns:
Parser for the new language.


def __add__(self, r):
    if not isinstance(r, TestResult):
        raise TypeError('Operand %s of type %s is not a TestResult.' % (r, type(r)))
    sum_result = TestResult()
    for name in sum_result.__dict__:
        r_value = getattr(r, name)
        l_value = getattr(self, name)
        if isinstance(r_value, list):
            setattr(sum_result, name, l_value + r_value)
    return sum_result

Overrides '+' operator for TestResult class.

The add operator merges two TestResult objects by concatenating all of
their lists together.

Args:
r: another instance of TestResult to be added

Returns:
A TestResult instance that's the sum of two TestResult instances.


def panel(self, panel_id):

        if not isinstance(panel_id, ObjectId):
            panel_id = ObjectId(panel_id)
        panel_obj = self.panel_collection.find_one({'_id': panel_id})
        return panel_obj

Fetch a gene panel by '_id'.

Args:
panel_id (str, ObjectId): str or ObjectId of document ObjectId

Returns:
dict: panel object or `None` if panel not found


def get_labels(self, **query_params):
    labels = self.get_labels_json(self.base_uri, query_params=query_params)
    labels_list = []
    for label_json in labels:
        labels_list.append(self.create_label(label_json))
    return labels_list

Get the labels attached to this board. Returns a label of Label
objects.

Returns:
list(Label): The labels attached to this board


def CreateExtensionSetting(client, feed_items, campaign_feed, feed_item_ids,
                           platform_restrictions=None):

  campaign_extension_setting_service = client.GetService(
      'CampaignExtensionSettingService', 'v201809')

  extension_feed_items = [{
      CreateSitelinkFeedItem(feed_items, feed_item_id)
  } for feed_item_id in feed_item_ids]

  extension_setting = {
      'extensions': extension_feed_items
  }

  if platform_restrictions:
    extension_setting['platformRestrictions'] = platform_restrictions

  campaign_extension_setting = {
      'campaignId': campaign_feed['campaignId'],
      'extensionType': 'SITELINK',
      'extensionSetting': extension_setting
  }

  operation = {
      'operand': campaign_extension_setting,
      'operator': 'ADD'
  }

  campaign_extension_setting_service.mutate([operation])

Creates the extension setting for a list of Feed Items.

Args:
client: an AdWordsClient instance.
feed_items: the list of all Feed Items.
campaign_feed: the original Campaign Feed.
feed_item_ids: the Ids of the feed items for which extension settings should
be created.
platform_restrictions: an optional Platform Restriction for the Feed items.


def get(self, center, target, date):
    if ((center.index, target.index) in self.segments):
        (pos, vel) = self.segments[(center.index, target.index)].compute_and_differentiate(date.jd)
        sign = 1
    else:
        (pos, vel) = self.segments[(target.index, center.index)].compute_and_differentiate(date.jd)
        sign = (- 1)
    if (len(pos) == 3):
        pv = np.concatenate((pos, (vel / S_PER_DAY)))
    elif (len(pos) == 6):
        pv = np.array(pos)
    else:
        raise JplError('Unknown state vector format')
    return ((sign * pv) * 1000)

Retrieve the position and velocity of a target with respect to a center

Args:
center (Target):
target (Target):
date (Date):
Return:
numpy.array: length-6 array position and velocity (in m and m/s) of the
target, with respect to the center


def variable_summaries(vars_, groups=None, scope='weights'):

  groups = groups or {r'all': r'.*'}
  grouped = collections.defaultdict(list)
  for var in vars_:
    for name, pattern in groups.items():
      if re.match(pattern, var.name):
        name = re.sub(pattern, name, var.name)
        grouped[name].append(var)
  for name in groups:
    if name not in grouped:
      tf.logging.warn("No variables matching '{}' group.".format(name))
  summaries = []

  for name, vars_ in grouped.items():
    vars_ = [tf.reshape(var, [-1]) for var in vars_]
    vars_ = tf.concat(vars_, 0)
    summaries.append(tf.summary.histogram(scope + '/' + name, vars_))
  return tf.summary.merge(summaries)

Create histogram summaries for the provided variables.

Summaries can be grouped via regexes matching variables names.

Args:
vars_: List of variables to summarize.
groups: Mapping of name to regex for grouping summaries.
scope: Name scope for this operation.

Returns:
Summary tensor.


def _gen(self, optimized, splitstring):

        self.resolved = {}

        for nt in self.grammar.grammar_nonterminals_map:
            for i in self.grammar.grammar_nonterminals_map[nt]:
                if self.grammar.grammar_rules[i][0] not in self.resolved\
                        and not isinstance(self.grammar.grammar_rules[i][1], (set, tuple)):
                    if self.grammar.grammar_rules[i][1] != '@empty_set' \
                            and self.grammar.grammar_rules[i][1] in self.grammar.grammar_terminals:

                        if splitstring:
                            self.resolved[
                                self.grammar.grammar_rules[i][0]] = self.grammar.grammar_rules[i][1]
                        else:
                            if self.grammar.grammar_rules[i][1] == '&':
                                self.resolved[self.grammar.grammar_rules[i][0]] = ' '
                            else:
                                self.resolved[
                                    self.grammar.grammar_rules[i][0]] = self.grammar.grammar_rules[i][1]

                        if self._checkfinal(self.grammar.grammar_rules[i][0]):
                            return self.resolved[self.grammar.grammar_rules[i][0]]
                        if self.grammar.grammar_rules[i][0] not in self.bfs_queue:
                            self.bfs_queue.append(self.grammar.grammar_rules[i][0])
                    if self.grammar.grammar_rules[i][1] == '@empty_set':
                        self.resolved[self.grammar.grammar_rules[i][0]] = ''

                        self.bfs_queue.append(self.grammar.grammar_rules[i][0])
                    if optimized and self._check_self_to_empty(
                            self.grammar.grammar_rules[i][1]):
                        self.resolved[self.grammar.grammar_rules[i][0]] = ''

                        if self.grammar.grammar_rules[i][0] not in self.bfs_queue:
                            self.bfs_queue.append(self.grammar.grammar_rules[i][0])

        change = 1
        while change:
            change = 0
            if not change:
                ret = self._check_self_nonterminals(optimized)
                if ret == 1:
                    change = 1
                elif ret != 0:
                    return ret
            if not change:
                while not change and len(self.bfs_queue) > 0:
                    myntr = self.bfs_queue.pop()
                    ret = self._check_self_replicate(myntr)
                    if ret == 1:
                        change = 1
                    elif ret != 0:
                        return ret
                    if optimized and self._check_intemediate(
                            myntr, self.maxstate):
                        change = 1
                        break

Generates a new random object generated from the nonterminal
Args:
optimized (bool): mode of operation - if enabled not all
CNF rules are included (mitigate O(n^3))
splitstring (bool): A boolean for enabling or disabling
Returns:
str: The generated string


def _case_helper(cond_fn, pred_fn_pairs, default, exclusive, name, allow_python_preds=False, **cond_kwargs):
    predicates, actions = _case_verify_and_canonicalize_args(pred_fn_pairs, exclusive, name, allow_python_preds)
    with ops.name_scope(name, 'case', [predicates]):
        if default is None:
            default, predicates, actions = _case_create_default_action(predicates, actions)
        fn = default
        for predicate, action in reversed(list(zip(predicates, actions))):
            fn = functools.partial(cond_fn, predicate, true_fn=action, false_fn=fn, **cond_kwargs)
        if exclusive:
            with ops.control_dependencies([_assert_at_most_n_true(predicates, n=1, msg='Input error: exclusive=True')]):
                return fn()
        else:
            return fn()

Implementation of case that allows for different cond functions.

Args:
cond_fn: method that has signature and semantics of `cond` above.
pred_fn_pairs: Dict or list of pairs of a boolean scalar tensor, and a
callable which returns a list of tensors.
default: Optional callable that returns a list of tensors.
exclusive: True iff at most one predicate is allowed to evaluate to `True`.
name: A name for this operation (optional).
allow_python_preds: if true, pred_fn_pairs may contain Python bools in
addition to boolean Tensors
**cond_kwargs: keyword arguments that will be passed to `cond_fn`.

Returns:
The tensors returned by the first pair whose predicate evaluated to True, or
those returned by `default` if none does.

Raises:
TypeError: If `pred_fn_pairs` is not a list/dictionary.
TypeError: If `pred_fn_pairs` is a list but does not contain 2-tuples.
TypeError: If `fns[i]` is not callable for any i, or `default` is not
callable.


def __init__(self, package, ad):

        super(SnippetClient, self).__init__(app_name=package, ad=ad)
        self.package = package
        self._ad = ad
        self._adb = ad.adb
        self._proc = None

Initializes a SnippetClient.

Args:
package: (str) The package name of the apk where the snippets are
defined.
ad: (AndroidDevice) the device object associated with this client.


def BreachDepressions(dem, in_place=False, topology='D8'):
    if (type(dem) is not rdarray):
        raise Exception('A richdem.rdarray or numpy.ndarray is required!')
    if (topology not in ['D8', 'D4']):
        raise Exception('Unknown topology!')
    if (not in_place):
        dem = dem.copy()
    _AddAnalysis(dem, 'BreachDepressions(dem)')
    demw = dem.wrap()
    if (topology == 'D8'):
        _richdem.rdBreachDepressionsD8(demw)
    elif (topology == 'D4'):
        _richdem.rdBreachDepressionsD4(demw)
    dem.copyFromWrapped(demw)
    if (not in_place):
        return dem

Breaches all depressions in a DEM.

Args:
dem     (rdarray): An elevation model
in_place (bool):   If True, the DEM is modified in place and there is
no return; otherwise, a new, altered DEM is returned.
topology (string): A topology indicator

Returns:
DEM without depressions.


def Parse(self, value):

    value_line = value.split(' ')
    if len(value_line) < 3:
      raise TextFSMTemplateError('Expect at least 3 tokens on line.')

    if not value_line[2].startswith('('):

      options = value_line[1]
      for option in options.split(','):
        self._AddOption(option)

      [option.OnCreateOptions() for option in self.options]

      self.name = value_line[2]
      self.regex = ' '.join(value_line[3:])
    else:

      self.name = value_line[1]
      self.regex = ' '.join(value_line[2:])

    if len(self.name) > self.max_name_len:
      raise TextFSMTemplateError(
          "Invalid Value name '%s' or name too long." % self.name)

    if (not re.match(r'^\(.*\)$', self.regex) or
        self.regex.count('(') != self.regex.count(')')):
      raise TextFSMTemplateError(
          "Value '%s' must be contained within a '()' pair." % self.regex)

    self.template = re.sub(r'^\(', '(?P<%s>' % self.name, self.regex)

Parse a 'Value' declaration.

Args:
value: String line from a template file, must begin with 'Value '.

Raises:
TextFSMTemplateError: Value declaration contains an error.


def allreduce(self, x, mesh_axes, reduction_fn_string):

    if not mesh_axes:
      return x
    x = x.to_laid_out_tensor()
    if reduction_fn_string == "SUM":
      group_assignment = self._create_group_assignment(mesh_axes)
      group_size = len(group_assignment[0])
      tf_in = x.one_slice
      dtype = tf_in.dtype
      if dtype == tf.float32:
        cast_to_float32 = False
      elif dtype == tf.bfloat16:
        cast_to_float32 = (
            group_size > self._allreduce_in_bfloat16_max_group_size)
      else:
        tf.logging.info("Casting %s to float32 for allreduce" % tf_in.dtype)
        cast_to_float32 = True
      if cast_to_float32:
        tf_in = tf.cast(tf_in, tf.float32)
      tf_out = tpu_ops.cross_replica_sum(tf_in, group_assignment)
      if cast_to_float32:
        tf_out = tf.cast(tf_out, dtype)
      return self.LaidOutTensor([tf_out])
    else:
      for axis in mesh_axes:
        x = self.allconcat(x, axis, 0, stack=True)
        x = self.LaidOutTensor(
            [mtf.reduction_fn(reduction_fn_string)(x.one_slice, 0)])
      return x

Grouped allreduce, (summed across the given dimensions).

Args:
x: a LaidOutTensor
mesh_axes: a list of integers
reduction_fn_string: "SUM"
Returns:
a LaidOutTensor
Raises:
ValueError: if the reduction is not yet implemented.


def do_ams_patch(endpoint, path, body, access_token):

    headers = {"Content-Type": json_acceptformat,
               "DataServiceVersion": dsversion_min,
               "MaxDataServiceVersion": dsversion_max,
               "Accept": json_acceptformat,
               "Accept-Charset" : charset,
               "Authorization": "Bearer " + access_token,
               "x-ms-version" : xmsversion}
    response = requests.patch(endpoint, data=body, headers=headers, allow_redirects=False)

    if response.status_code == 301:
        redirected_url = ''.join([response.headers['location'], path])
        response = requests.patch(redirected_url, data=body, headers=headers)
    return response

Do a AMS PATCH request and return JSON.
Args:
endpoint (str): Azure Media Services Initial Endpoint.
path (str): Azure Media Services Endpoint Path.
body  (str): Azure Media Services Content Body.
access_token (str): A valid Azure authentication token.

Returns:
HTTP response. JSON body.


def list_sku_versions(access_token, subscription_id, location, publisher, offer, sku):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.Compute/',
                        'locations/', location,
                        '/publishers/', publisher,
                        '/artifacttypes/vmimage/offers/', offer,
                        '/skus/', sku,
                        '/versions?api-version=', COMP_API])
    return do_get(endpoint, access_token)

List available versions for a given publisher's sku.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
location (str): Azure data center location. E.g. westus.
publisher (str): VM image publisher. E.g. MicrosoftWindowsServer.
offer (str): VM image offer. E.g. WindowsServer.
sku (str): VM image sku. E.g. 2016-Datacenter.

Returns:
HTTP response with JSON list of versions.