def merge_config(config: Mapping[(str, Any)], override_config: Mapping[(str, Any)]=None, override_config_fn: str=None) -> Mapping[(str, Any)]:
    if override_config_fn:
        with open(override_config_fn, 'r') as f:
            override_config = yaml.load(f, Loader=yaml.SafeLoader)
    if (not override_config):
        log.info('Missing override_config')
    return functools.reduce(rec_merge, (config, override_config))

Override config with additional configuration in override_config or override_config_fn

Used in script to merge CLI options with Config

Args:
config: original configuration
override_config: new configuration to override/extend current config
override_config_fn: new configuration filename as YAML file


def _cast_to_known_type(name):
    if name is None:
        return None
    return name.rstrip('.')

Canonicalizes a string representing a type if possible.

# TODO(dbieber): Support additional canonicalization, such as string/str, and
# boolean/bool.

Example:
_cast_to_known_type("str.") == "str"

Args:
name: A string representing a type, or None.
Returns:
A canonicalized version of the type string.


def __init__(self, text_encoder_config=None, **kwargs):

    super(MultiNLIConfig, self).__init__(**kwargs)
    self.text_encoder_config = (
        text_encoder_config or tfds.features.text.TextEncoderConfig())

BuilderConfig for MultiNLI.

Args:
text_encoder_config: `tfds.features.text.TextEncoderConfig`, configuration
for the `tfds.features.text.TextEncoder` used for the features feature.
**kwargs: keyword arguments forwarded to super.


def __init__(self, value=None):

        super(ExtensionType, self).__init__(value, Tags.EXTENSION_TYPE)

Construct an ExtensionType object.

Args:
value (Types): A number representing a Types enumeration value,
indicating the type of the extended Object. Optional, defaults
to None.


def add_data(self, data):
    if ((self.data_size - self.data_index) < len(data)):
        return Error.DESTINATION_BUFFER_TOO_SMALL
    if (self.in_progress is not None):
        self.in_progress.data += data
    return Error.NO_ERROR

Add data to the currently in progress entry.

Args:
data (bytes): The data that we want to add.

Returns:
int: An error code


def get_xnp(self, x: Array, *, strict: bool=True):
    if self.is_jax(x):
        return self.jnp
    elif self.is_tf(x):
        return self.tnp
    elif self.is_np(x):
        return np
    elif self.is_torch(x):
        return self.torch
    elif not strict and isinstance(x, _ARRAY_LIKE_TYPES):
        return np
    else:
        raise TypeError(f'Cannot infer the numpy module from array: {type(x).__name__}')

Returns the numpy module associated with the given array.

Args:
x: Either tf, jax or numpy array.
strict: If `False`, default to `np.array` if the array can't be infered (
to support array-like: list, tuple,...)

Returns:
The numpy module.


async def attach_file(self, file_path: str, description: str = None) -> Attachment:

        with open(file_path, 'rb') as f:
            return await self._attach(f.read(), description)

add a file as an attachment

|methcoro|

Warning:
|unstable|

Args:
file_path: path to the file you want to add
description: *optional* description for your attachment

Returns:
Attachment:

Raises:
ValueError: file_path must not be None
APIException


def future(self, request, timeout=None, metadata=None, credentials=None):
    return _utils.wrap_future_call(self._inner.future(request, timeout, metadata, credentials), self._loop, self._executor)

Asynchronously invokes the underlying RPC.

Args:
request: The request value for the RPC.
timeout: An optional duration of time in seconds to allow for the RPC.
metadata: Optional :term:`metadata` to be transmitted to the
service-side of the RPC.
credentials: An optional CallCredentials for the RPC.

Returns:
An object that is both a Call for the RPC and a Future. In the event of
RPC completion, the return Call-Future's result value will be the
response message of the RPC. Should the event terminate with non-OK
status, the returned Call-Future's exception value will be an RpcError.


def is60(msg):

    if allzeros(msg):
        return False

    d = hex2bin(data(msg))

    if wrongstatus(d, 1, 2, 12):
        return False

    if wrongstatus(d, 13, 14, 23):
        return False

    if wrongstatus(d, 24, 25, 34):
        return False

    if wrongstatus(d, 35, 36, 45):
        return False

    if wrongstatus(d, 46, 47, 56):
        return False

    ias = ias60(msg)
    if ias is not None and ias > 500:
        return False

    mach = mach60(msg)
    if mach is not None and mach > 1:
        return False

    vr_baro = vr60baro(msg)
    if vr_baro is not None and abs(vr_baro) > 6000:
        return False

    vr_ins = vr60ins(msg)
    if vr_ins is not None and abs(vr_ins) > 6000:
        return False

    return True

Check if a message is likely to be BDS code 6,0

Args:
msg (String): 28 bytes hexadecimal message string

Returns:
bool: True or False


def comment(self, text, comment_prefix='

        comment = Comment(self._container)
        if not text.startswith(comment_prefix):
            text = "{} {}".format(comment_prefix, text)
        if not text.endswith('\n'):
            text = "{}{}".format(text, '\n')
        comment.add_line(text)
        self._container.structure.insert(self._idx, comment)
        self._idx += 1
        return self

Creates a comment block

Args:
text (str): content of comment without #
comment_prefix (str): character indicating start of comment

Returns:
self for chaining


class TFConvNextLayer(keras.layers.Layer):

    def __init__(self, config, dim, drop_path=0.0, **kwargs):
        super().__init__(**kwargs)
        self.dim = dim
        self.config = config
        self.dwconv = keras.layers.Conv2D(filters=dim, kernel_size=7, padding='same', groups=dim, kernel_initializer=get_initializer(config.initializer_range), bias_initializer='zeros', name='dwconv')
        self.layernorm = keras.layers.LayerNormalization(epsilon=1e-06, name='layernorm')
        self.pwconv1 = keras.layers.Dense(units=4 * dim, kernel_initializer=get_initializer(config.initializer_range), bias_initializer='zeros', name='pwconv1')
        self.act = get_tf_activation(config.hidden_act)
        self.pwconv2 = keras.layers.Dense(units=dim, kernel_initializer=get_initializer(config.initializer_range), bias_initializer='zeros', name='pwconv2')
        self.drop_path = TFConvNextDropPath(drop_path, name='drop_path') if drop_path > 0.0 else keras.layers.Activation('linear', name='drop_path')

    def build(self, input_shape: tf.TensorShape=None):
        self.layer_scale_parameter = self.add_weight(shape=(self.dim,), initializer=keras.initializers.Constant(value=self.config.layer_scale_init_value), trainable=True, name='layer_scale_parameter') if self.config.layer_scale_init_value > 0 else None
        if self.built:
            return
        self.built = True
        if getattr(self, 'dwconv', None) is not None:
            with tf.name_scope(self.dwconv.name):
                self.dwconv.build([None, None, None, self.dim])
        if getattr(self, 'layernorm', None) is not None:
            with tf.name_scope(self.layernorm.name):
                self.layernorm.build([None, None, None, self.dim])
        if getattr(self, 'pwconv1', None) is not None:
            with tf.name_scope(self.pwconv1.name):
                self.pwconv1.build([None, None, self.dim])
        if getattr(self, 'pwconv2', None) is not None:
            with tf.name_scope(self.pwconv2.name):
                self.pwconv2.build([None, None, 4 * self.dim])
        if getattr(self, 'drop_path', None) is not None:
            with tf.name_scope(self.drop_path.name):
                self.drop_path.build(None)

    def call(self, hidden_states, training=False):
        input = hidden_states
        x = self.dwconv(hidden_states)
        x = self.layernorm(x)
        x = self.pwconv1(x)
        x = self.act(x)
        x = self.pwconv2(x)
        if self.layer_scale_parameter is not None:
            x = self.layer_scale_parameter * x
        x = input + self.drop_path(x, training=training)
        return x

This corresponds to the `Block` class in the original implementation.

There are two equivalent implementations: [DwConv, LayerNorm (channels_first), Conv, GELU,1x1 Conv]; all in (N, C,
H, W) (2) [DwConv, Permute to (N, H, W, C), LayerNorm (channels_last), Linear, GELU, Linear]; Permute back

The authors used (2) as they find it slightly faster in PyTorch. Since we already permuted the inputs to follow
NHWC ordering, we can just apply the operations straight-away without the permutation.

Args:
config ([`ConvNextConfig`]): Model configuration class.
dim (`int`): Number of input channels.
drop_path (`float`): Stochastic depth rate. Default: 0.0.


def __str__(self):
    duplicates = []

    def AppendDuplicateItem(item, count):
        if count == 1:
            duplicates.append('{0!r}'.format(item))
        else:
            duplicates.append('{0!r} [{1} copies]'.format(item, count))
    with self._lock:
        for item, count in six.iteritems(self._d):
            AppendDuplicateItem(item, count)
        for item, count in zip(self._unhashable_items, self._unhashable_counts):
            AppendDuplicateItem(item, count)
    return '[{0}]'.format(', '.join(duplicates))

Returns the string representation of the duplicate counts.

Items occurring more than once are accompanied by their count.
Otherwise the count is implied to be 1.

For example, if the internal dict is {2: 1, 3: 4, 'abc': 1}, this returns
the string "[{2, 3 [4 copies], 'abc'}]".

Returns:
String, the counts of duplicate items.


def WriteEventMACBGroup(self, event_macb_group):
    output_values = self._GetOutputValues(event_macb_group[0])
    timestamp_descriptions = [event.timestamp_desc for event in event_macb_group]
    output_values[3] = self._output_mediator.GetMACBRepresentationFromDescriptions(timestamp_descriptions)
    output_values[6] = '; '.join(timestamp_descriptions)
    self._WriteOutputValues(output_values)

Writes an event MACB group to the output.

Args:
event_macb_group (list[EventObject]): event MACB group.


def __content_type_matches(self, content_type, available_content_types):
    if (content_type is None):
        return False
    if (content_type in available_content_types):
        return True
    for available_content_type in available_content_types:
        if (available_content_type in content_type):
            return True
    return False

Check if the given content type matches one of the available content types.

Args:
content_type (str): The given content type.
available_content_types list(str): All the available content types.

Returns:
bool: True if a match was found, False otherwise.


def search(self, search_phrase, limit=None):

        search_phrase = search_phrase.replace('-', '_')
        query, query_params = self._make_query_from_terms(search_phrase)

        self._parsed_query = (query, query_params)

        connection = self.backend.library.database.connection

        connection.connection.create_function('rank', 1, _make_rank_func((1., .1, 0, 0)))

        logger.debug('Searching datasets using `{}` query.'.format(query))
        results = connection.execute(query,
                                     **query_params).fetchall()

        datasets = defaultdict(DatasetSearchResult)
        for result in results:
            vid, score = result
            datasets[vid] = DatasetSearchResult()
            datasets[vid].vid = vid
            datasets[vid].b_score = score

        logger.debug('Extending datasets with partitions.')
        for partition in self.backend.partition_index.search(search_phrase):
            datasets[partition.dataset_vid].p_score += partition.score
            datasets[partition.dataset_vid].partitions.add(partition)
        return list(datasets.values())

Finds datasets by search phrase.

Args:
search_phrase (str or unicode):
limit (int, optional): how many results to return. None means without limit.

Returns:
list of DatasetSearchResult instances.


def set_input_embeddings(self, value):
    main_layer = getattr(self, self.base_model_prefix)
    if main_layer is None:
        raise NotImplementedError('The model does not implements the base_model_prefix attribute.')
    try:
        main_layer.set_input_embeddings(value)
    except AttributeError:
        logger.info('Building the model')
        self.build_in_name_scope()
        main_layer.set_input_embeddings(value)

Set model's input embeddings

Args:
value (`tf.Variable`):
The new weights mapping hidden states to vocabulary.


def _pad_input(self, inputs):
    if all(((p == self._conv_op_padding) for p in self._padding)):
        return inputs
    assert (self._conv_op_padding == VALID)

    def pad_amount(kernel_size, rate, padding):
        'Pre- and post-padding required for a particular axis before conv op.'
        effective_kernel_size = int((((kernel_size - 1) * rate) + 1))
        if (padding == FULL):
            return [(effective_kernel_size - 1), (effective_kernel_size - 1)]
        if (padding == CAUSAL):
            return [(effective_kernel_size - 1), 0]
        if (padding == REVERSE_CAUSAL):
            return [0, (effective_kernel_size - 1)]
        if (padding == SAME):
            return [((effective_kernel_size - 1)
        return [0, 0]
    paddings = map(pad_amount, self._kernel_shape, self._rate, self._padding)
    if self._data_format.startswith('NC'):
        paddings = ([[0, 0], [0, 0]] + list(paddings))
    else:
        paddings = (([[0, 0]] + list(paddings)) + [[0, 0]])
    return tf.pad(inputs, paddings)

Pad input in case the desired padding type requires it.

VALID and SAME padding types are directly supported by tensorflow
convolution ops, so don't require us to pad input ourselves, at least
in cases where the same method is used for all dimensions.

Other padding types (FULL, CAUSAL, REVERSE_CAUSAL) aren't directly supported
by conv ops but can be implemented by using VALID and padding the input
appropriately ourselves.

If different padding types are used for different dimensions, we use VALID
but pad the input ourselves along any dimensions that require other padding
types.

Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.

Returns:
inputs: The `inputs` argument that has had any required padding added.


def convert_new_publication_info_to_old(publication_infos):

    def _needs_a_hidden_pubnote(journal_title, journal_volume):
        return (
            journal_title in _JOURNALS_THAT_NEED_A_HIDDEN_PUBNOTE and
            journal_volume in _JOURNALS_THAT_NEED_A_HIDDEN_PUBNOTE[journal_title]
        )

    result = []

    for publication_info in publication_infos:
        _publication_info = copy.deepcopy(publication_info)
        journal_title = _publication_info.get('journal_title')

        try:
            journal_title = _JOURNALS_RENAMED_NEW_TO_OLD[journal_title]
            _publication_info['journal_title'] = journal_title
            result.append(_publication_info)
            continue
        except KeyError:
            pass

        journal_volume = _publication_info.get('journal_volume')
        year = _publication_info.get('year')

        if (journal_title in _JOURNALS_WITH_YEAR_ADDED_TO_VOLUME and year and
                journal_volume and len(journal_volume) == 2):
            two_digit_year = str(year)[2:]
            _publication_info['journal_volume'] = ''.join([two_digit_year, journal_volume])
            result.append(_publication_info)
            continue

        if journal_title and journal_volume:
            match = _RE_TITLE_ENDS_WITH_A_LETTER.match(journal_title)
            if match and _needs_a_hidden_pubnote(journal_title, journal_volume):
                _publication_info['journal_title'] = match.group('title')
                _publication_info['journal_volume'] = journal_volume + match.group('letter')
                result.append(_publication_info)
                _publication_info = copy.deepcopy(publication_info)
                _publication_info['hidden'] = True
                _publication_info['journal_title'] = match.group('title')
                _publication_info['journal_volume'] = match.group('letter') + journal_volume
            elif match and journal_title not in _JOURNALS_ALREADY_ENDING_WITH_A_LETTER:
                _publication_info['journal_title'] = match.group('title')
                _publication_info['journal_volume'] = match.group('letter') + journal_volume

        result.append(_publication_info)

    return result

Convert back a ``publication_info`` value from the new format to the old.

Does the inverse transformation of :func:`convert_old_publication_info_to_new`,
to be used whenever we are sending back records from Labs to Legacy.

Args:
publication_infos: a ``publication_info`` in the new format.

Returns:
list(dict): a ``publication_info`` in the old format.


def _ParseKeysFromFindSpecs(self, parser_mediator, win_registry, find_specs):

    searcher = dfwinreg_registry_searcher.WinRegistrySearcher(win_registry)
    for registry_key_path in iter(searcher.Find(find_specs=find_specs)):
      if parser_mediator.abort:
        break

      registry_key = searcher.GetKeyByPath(registry_key_path)
      self._ParseKey(parser_mediator, registry_key)

Parses the Registry keys from FindSpecs.

Args:
parser_mediator (ParserMediator): parser mediator.
win_registry (dfwinreg.WinRegistryKey): root Windows Registry key.
find_specs (dfwinreg.FindSpecs): Keys to search for.


def init(deb1, deb2=False):

    global DEBUG
    global DEBUGALL
    DEBUG = deb1
    DEBUGALL = deb2

Initialize DEBUG and DEBUGALL.

Allows other modules to set DEBUG and DEBUGALL, so their
call to dprint or dprintx generate output.

Args:
deb1 (bool): value of DEBUG to set
deb2 (bool): optional - value of DEBUGALL to set,
defaults to False.


def _instance_transform(fqdn, o, *args, **kwargs):

    return _package_transform(o, fqdn, start=0, *args, **kwargs)

Applies an instance method with name `fqdn` to `o`.

Args:
fqdn (str): fully-qualified domain name of the object.
o: object to apply instance method to.


def _forward_log_det_jacobian(self, x):
    raise NotImplementedError('forward_log_det_jacobian not implemented.')

Subclass implementation of `forward_log_det_jacobian` public function.

In particular, this method differs from the public function, in that it
does not take `event_ndims`. Thus, this implements the minimal Jacobian
determinant calculation (i.e. over `forward_min_event_ndims`).

Args:
x: `Tensor`. The input to the "forward_log_det_jacobian" evaluation.

Returns:
forward_log_det_jacobian: `Tensor`, if this bijector is injective.
If not injective, returns the k-tuple containing jacobians for the
unique `k` points `(x1, ..., xk)` such that `g(xi) = y`.


def get_url_distribution(self, params=None):
    params = (params or {})
    all_responses = {}
    api_name = 'virustotal-url-distribution'
    response_chunks = self._request_reports(list(params.keys()), list(params.values()), 'url/distribution')
    self._extract_response_chunks(all_responses, response_chunks, api_name)
    return all_responses

Retrieves a live feed with the latest URLs submitted to VT.

Args:
resources: a dictionary with name and value for optional arguments
Returns:
A dict with the VT report.


def _generate_fix_length_rpc_response(response_length, template='{"id": 0, "result": "%s", "error": null, "callback": null}'):
    result_length = response_length - (len(template) - 2)
    if result_length < 0:
        raise ValueError(f'The response_length should be no smaller than template_length + 2. Got response_length {response_length}, template_length {len(template)}.')
    chars = string.ascii_letters + string.digits
    return template % ''.join((random.choice(chars) for _ in range(result_length)))

Generates an RPC response string with specified length.

This function generates a random string and formats the template with the
generated random string to get the response string. This function formats
the template with printf style string formatting.

Args:
response_length: int, the length of the response string to generate.
template: str, the template used for generating the response string.

Returns:
The generated response string.

Raises:
ValueError: if the specified length is too small to generate a response.


def switch_opt(default, shortname, help_msg):
    return ConfOpt(bool(default), True, shortname, dict(action=internal.Switch), True, help_msg, None)

Define a switchable ConfOpt.

This creates a boolean option. If you use it in your CLI, it can be
switched on and off by prepending + or - to its name: +opt / -opt.

Args:
default (bool): the default value of the swith option.
shortname (str): short name of the option, no shortname will be used if
it is set to None.
help_msg (str): short description of the option.

Returns:
:class:`~loam.manager.ConfOpt`: a configuration option with the given
properties.


def _Aff4Size(aff4_obj):

  if not isinstance(aff4_obj, aff4.AFF4Stream):
    message = "Expected an instance of `%s` but received `%s`"
    raise TypeError(message % (aff4.AFF4Stream, type(aff4_obj)))

  return int(aff4_obj.Get(aff4_obj.Schema.SIZE))

Retrieves the total size in bytes of an AFF4 object.

Args:
aff4_obj: An AFF4 stream instance to retrieve size for.

Returns:
An integer representing number of bytes.

Raises:
TypeError: If `aff4_obj` is not an instance of AFF4 stream.


def plot_spectra_pieces_pdf(ss, aint=10, pdf_filename='pieces.pdf', setup=_default_setup):

    import f311.explorer as ex

    xmin, xmax, ymin_, ymax, _, yspan = calc_max_min(ss)
    ymin = ymin_ if setup.ymin is None else setup.ymin

    num_pages = int(math.ceil((xmax-xmin)/aint))

    a99.format_BLB()

    pdf = matplotlib.backends.backend_pdf.PdfPages(pdf_filename)
    logger = a99.get_python_logger()

    for h in range(num_pages):
        fig = plt.figure()
        lambda0 = xmin+h*aint
        lambda1 = lambda0+aint
        logger.info("Printing page {0:d}/{1:d} ([{2:g}, {3:g}])".format(h+1, num_pages, lambda0, lambda1))
        for i, s in enumerate(ss):
            s_cut = ex.cut_spectrum(s, lambda0, lambda1)
            ax = plt.gca()
            ax.plot(s_cut.x, s_cut.y, label=s.title)
        if setup.flag_xlabel and setup.fmt_xlabel:
            plt.xlabel('Wavelength (interval: [{0:g}, {1:g}])'.format(lambda0, lambda1))
        xspan = lambda1-lambda0
        ax.set_xlim([lambda0 - xspan * _T, lambda1 + xspan * _T])
        ax.set_ylim([ymin - yspan * _T, ymax + yspan * _T])
        if setup.flag_legend:
            leg = plt.legend(loc=0)
            a99.format_legend(leg)
        plt.tight_layout()
        pdf.savefig(fig)
        plt.close()

    pdf.close()
    logger.info("File {0!s} successfully created.".format(pdf_filename))

Plots spectra, overlapped, in small wavelength intervals into a PDF file,
one interval per page of the PDF file.

Args:
ss: list of Spectrum objects
aint: wavelength interval for each plot
pdf_filename: name of output file
setup: PlotSpectrumSetup object

**Note** overrides setup.fmt_xlabel; leaves y-labell and title blank


def fcoe_networks(self):
    if (not self.__fcoe_networks):
        self.__fcoe_networks = FcoeNetworks(self.__connection)
    return self.__fcoe_networks

Gets the FcoeNetworks API client.

Returns:
FcoeNetworks:


def _should_record_summaries_internal(default_state):
    if _summary_state.writer is None:
        return constant_op.constant(False)
    if not callable(_summary_state.is_recording):
        static_cond = tensor_util.constant_value(_summary_state.is_recording)
        if static_cond is not None and (not static_cond):
            return constant_op.constant(False)
    resolve = lambda x: x() if callable(x) else x
    cond_distributed = resolve(_summary_state.is_recording_distribution_strategy)
    cond = resolve(_summary_state.is_recording)
    if cond is None:
        cond = default_state
    return math_ops.logical_and(cond_distributed, cond)

Returns boolean Tensor if summaries should/shouldn't be recorded.

Now the summary condition is decided by logical "and" of below conditions:
First, summary writer must be set. Given this constraint is met,
ctx.summary_recording and ctx.summary_recording_distribution_strategy.
The former one is usually set by user, and the latter one is controlled
by DistributionStrategy (tf.distribute.ReplicaContext).

Args:
default_state: can be True or False. The default summary behavior when
summary writer is set and the user does not specify
ctx.summary_recording and ctx.summary_recording_distribution_strategy
is True.


def parse(self, filepath, content):
    try:
        parsed = json.loads(content)
    except ValueError:
        msg = 'No JSON object could be decoded from file: {}'
        raise SettingsBackendError(msg.format(filepath))
    return parsed

Parse opened settings content using JSON parser.

Args:
filepath (str): Settings object, depends from backend
content (str): Settings content from opened file, depends from
backend.

Raises:
boussole.exceptions.SettingsBackendError: If parser can not decode
a valid JSON object.

Returns:
dict: Dictionnary containing parsed setting elements.


def random_indexes(max_index, subset_size=None, seed=None, rng=None):
    subst_ = np.arange(0, max_index)
    rng = ensure_rng((seed if (rng is None) else rng))
    rng.shuffle(subst_)
    if (subset_size is None):
        subst = subst_
    else:
        subst = subst_[0:min(subset_size, max_index)]
    return subst

random unrepeated indicies

Args:
max_index (?):
subset_size (None): (default = None)
seed (None): (default = None)
rng (RandomState):  random number generator(default = None)

Returns:
?: subst

CommandLine:
python -m utool.util_numpy --exec-random_indexes

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_numpy import *  # NOQA
>>> max_index = 10
>>> subset_size = None
>>> seed = None
>>> rng = np.random.RandomState(0)
>>> subst = random_indexes(max_index, subset_size, seed, rng)
>>> result = ('subst = %s' % (str(subst),))
>>> print(result)


def build_rectangle_dict(self, north, west, south, east, stroke_color='
    rectangle = {'stroke_color': stroke_color, 'stroke_opacity': stroke_opacity, 'stroke_weight': stroke_weight, 'fill_color': fill_color, 'fill_opacity': fill_opacity, 'bounds': {'north': north, 'west': west, 'south': south, 'east': east}}
    return rectangle

Set a dictionary with the javascript class Rectangle parameters

This function sets a default drawing configuration if the user just
pass the rectangle bounds, but also allows to set each parameter
individually if the user wish so.

Args:
north (float): The north latitude bound
west (float): The west longitude bound
south (float): The south latitude bound
east (float): The east longitude bound
stroke_color (str): Sets the color of the rectangle border using
hexadecimal color notation
stroke_opacity (float): Sets the opacity of the rectangle border
in percentage. If stroke_opacity = 0, the border is transparent
stroke_weight (int): Sets the stroke girth in pixels.
fill_color (str): Sets the color of the rectangle fill using
hexadecimal color notation
fill_opacity (float): Sets the opacity of the rectangle fill


def CheckFile(self, path):

    print('Checking: {0:s}'.format(path))

    definitions_registry = registry.DataTypeDefinitionsRegistry()
    definitions_reader = reader.YAMLDataTypeDefinitionsFileReader()
    result = False

    try:
      definitions_reader.ReadFile(definitions_registry, path)
      result = True

    except KeyError as exception:
      logging.warning((
          'Unable to register data type definition in file: {0:s} with '
          'error: {1:s}').format(path, exception))

    except errors.FormatError as exception:
      logging.warning(
          'Unable to validate file: {0:s} with error: {1:s}'.format(
              path, exception))

    return result

Validates the definition in a file.

Args:
path (str): path of the definition file.

Returns:
bool: True if the file contains valid definitions.


def CreatePriceTableRow(header, description, final_url, price_in_micros, currency_code, price_unit, final_mobile_url=None):
    table_row = {'header': header, 'description': description, 'finalUrls': {'urls': [final_url]}, 'price': {'money': {'microAmount': price_in_micros}, 'currencyCode': currency_code}, 'priceUnit': price_unit, 'xsi_type': 'PriceTableRow'}
    if final_mobile_url:
        table_row['finalMobileUrls'] = {'urls': [final_mobile_url]}
    return table_row

Helper function to generate a single row of a price table.

Args:
header: A str containing the header text of this row.
description: A str description of this row in the price table.
final_url: A str containing the final URL after all cross domain redirects.
price_in_micros: An int indicating the price of the given currency in
micros.
currency_code: A str indicating the currency code being used.
price_unit: A str enum indicating the price unit for this row.
final_mobile_url: A str containing the final mobile URL after all cross
domain redirects.

Returns:
A dictionary containing the contents of the generated price table row.


def is_method_call(func, types=(), methods=()):

    return (
        isinstance(func, astroid.BoundMethod)
        and isinstance(func.bound, astroid.Instance)
        and (func.bound.name in types if types else True)
        and (func.name in methods if methods else True)
    )

Determines if a BoundMethod node represents a method call.

Args:
func (astroid.BoundMethod): The BoundMethod AST node to check.
types (Optional[String]): Optional sequence of caller type names to restrict check.
methods (Optional[String]): Optional sequence of method names to restrict check.

Returns:
bool: true if the node represents a method call for the given type and
method names, False otherwise.


def next_in_buffer(self, target_buffer: collections.deque[_T]) -> _T:
    if bool(target_buffer):
        return target_buffer.popleft()
    for item in self._input_stream:
        which_buffer = self._select_buffer(item)
        if which_buffer is None:
            continue
        if which_buffer is target_buffer:
            return item
        if isinstance(which_buffer, collections.deque):
            which_buffer.append(item)
            continue
        if isinstance(which_buffer, tuple):
            return_item: bool = False
            for buffer in which_buffer:
                if buffer is target_buffer:
                    return_item = True
                else:
                    buffer.append(item)
            if return_item:
                return item
            continue
        T = TypeVar('T', bound=_T)
        ExpectedTypes = Union[collections.deque[T], tuple[collections.deque[T], ...], None]
        raise TypeError(f'`{self._select_buffer}` returned a value of type `{type(which_buffer).__name__}`; expected one of `{ExpectedTypes}`.')
    raise StopIteration()

Returns the next item in the sub-stream corresponding to `target_buffer`.

Args:
target_buffer: The queue backing the sub-stream whose next element should
be returned.

Returns:
If `target_buffer` is nonempty, the next element of `target_buffer`.
Otherwise, the next element of `self._input_stream` that would have been
added to `target_buffer`.

Raises:
StopIteration: If `target_buffer` and `self._input_stream` are both empty.


def get_inner_template(self, language, template_type, indentation, key, val):
    inner_templates = {'php': {'iterable': ('%s%s => array \n%s( \n%s%s),\n' % (indentation, key, indentation, val, indentation)), 'singular': ('%s%s => %s, \n' % (indentation, key, val))}, 'javascript': {'iterable': ('%s%s : {\n%s\n%s},\n' % (indentation, key, val, indentation)), 'singular': ('%s%s: %s,\n' % (indentation, key, val))}, 'ocaml': {'iterable': ('%s[| (%s, (\n%s\n%s))|] ;;\n' % (indentation, key, val, indentation)), 'singular': ('%s(%s, %s);\n' % (indentation, key, val))}}
    return inner_templates[language][template_type]

Gets the requested template for the given language.

Args:
language: string, the language of the template to look for.

template_type: string, 'iterable' or 'singular'.
An iterable template is needed when the value is an iterable
and needs more unpacking, e.g. list, tuple. A singular template
is needed when unpacking is complete and the value is singular,
e.g. string, int, float.

indentation: int, the indentation level.

key: multiple types, the array key.

val: multiple types, the array values

Returns:
string, template formatting for arrays by language.


def multisorted(items, *keys):
    if (len(keys) == 0):
        keys = [asc()]
    for key in reversed(keys):
        items = sorted(items, key=key.func, reverse=key.reverse)
    return items

Sort by multiple attributes.

Args:
items: An iterable series to be sorted.
*keys: Key objects which extract key values from the items.
The first key will be the most significant, and the
last key the least significant. If no key functions
are provided, the items will be sorted in ascending
natural order.
Returns:
A list of items sorted according to keys.


def move(self, fromaccount, toaccount, amount, minconf=1):
    amount = Decimal(amount).quantize(self.quantum, rounding=ROUND_HALF_EVEN)
    return self.rpc.call('move', fromaccount, toaccount, float(str(amount)), minconf)

Send coins between accounts in the same wallet.

If the receiving account does not exist, it is automatically
created (but not automatically assigned an address).

Args:
fromaccount (str): origin account
toaccount (str): destination account
amount (str or Decimal): amount to send (8 decimal points)
minconf (int): ensure the account has a valid balance using this
many confirmations (default=1)

Returns:
bool: True if the coins are moved successfully, False otherwise


def _serialization_helper(self, ray_forking):

        if ray_forking:
            actor_handle_id = compute_actor_handle_id(
                self._ray_actor_handle_id, self._ray_actor_forks)
        else:
            actor_handle_id = self._ray_actor_handle_id

        state = {
            "actor_id": self._ray_actor_id,
            "actor_handle_id": actor_handle_id,
            "module_name": self._ray_module_name,
            "class_name": self._ray_class_name,
            "actor_cursor": self._ray_actor_cursor,
            "actor_method_names": self._ray_actor_method_names,
            "method_signatures": self._ray_method_signatures,
            "method_num_return_vals": self._ray_method_num_return_vals,

            "actor_creation_dummy_object_id": self.
            _ray_actor_creation_dummy_object_id,
            "actor_method_cpus": self._ray_actor_method_cpus,
            "actor_driver_id": self._ray_actor_driver_id,
            "ray_forking": ray_forking
        }

        if ray_forking:
            self._ray_actor_forks += 1
            new_actor_handle_id = actor_handle_id
        else:

            new_actor_handle_id = ActorHandleID(_random_string())

        self._ray_new_actor_handles.append(new_actor_handle_id)

        return state

This is defined in order to make pickling work.

Args:
ray_forking: True if this is being called because Ray is forking
the actor handle and false if it is being called by pickling.

Returns:
A dictionary of the information needed to reconstruct the object.


def _format_value(value):
    literal = repr(value)
    try:
        if (parse_value(literal) == value):
            return literal
    except SyntaxError:
        pass
    return None

Returns `value` in a format parseable by `parse_value`, or `None`.

Simply put, This function ensures that when it returns a string value, the
following will hold:

parse_value(_format_value(value)) == value

Args:
value: The value to format.

Returns:
A string representation of `value` when `value` is literally representable,
or `None`.


def _CleanupUnregisteredFlagFromModuleDicts(self, flag_obj):

    if self._FlagIsRegistered(flag_obj):
      return
    for flags_by_module_dict in (self.FlagsByModuleDict(),
                                 self.FlagsByModuleIdDict(),
                                 self.KeyFlagsByModuleDict()):
      for flags_in_module in six.itervalues(flags_by_module_dict):

        while flag_obj in flags_in_module:
          flags_in_module.remove(flag_obj)

Cleanup unregistered flags from all module -> [flags] dictionaries.

If flag_obj is registered under either its long name or short name, it
won't be removed from the dictionaries.

Args:
flag_obj: A flag object.


def metar_to_speech(metar: str) -> str:

        LOGGER.info('getting speech text from METAR: %s', metar)
        metar_data, metar_units = emiz.avwx.metar.parse_in(metar)
        speech = emiz.avwx.speech.metar(metar_data, metar_units)
        speech = str(speech).replace('Altimeter', 'Q N H')
        LOGGER.debug('resulting speech: %s', speech)
        return speech

Creates a speakable text from a METAR

Args:
metar: METAR string to use

Returns: speakable METAR for TTS


def _parse_octet(self, octet_str):

        if not self._DECIMAL_DIGITS.issuperset(octet_str):
            raise ValueError
        octet_int = int(octet_str, 10)

        if octet_int > 255 or (octet_str[0] == '0' and len(octet_str) > 1):
            raise ValueError
        return octet_int

Convert a decimal octet into an integer.

Args:
octet_str: A string, the number to parse.

Returns:
The octet as an integer.

Raises:
ValueError: if the octet isn't strictly a decimal from [0..255].


def ashrae_clear_sky(altitudes, month, sky_clearness=1):
    MONTHLY_A = [1202, 1187, 1164, 1130, 1106, 1092, 1093, 1107, 1136, 1166, 1190, 1204]
    MONTHLY_B = [0.141, 0.142, 0.149, 0.164, 0.177, 0.185, 0.186, 0.182, 0.165, 0.152, 0.144, 0.141]
    dir_norm_rad = []
    dif_horiz_rad = []
    for (i, alt) in enumerate(altitudes):
        if (alt > 0):
            try:
                dir_norm = (MONTHLY_A[(month - 1)] / math.exp((MONTHLY_B[(month - 1)] / math.sin(math.radians(alt)))))
                diff_horiz = ((0.17 * dir_norm) * math.sin(math.radians(alt)))
                dir_norm_rad.append((dir_norm * sky_clearness))
                dif_horiz_rad.append((diff_horiz * sky_clearness))
            except OverflowError:
                dir_norm_rad.append(0)
                dif_horiz_rad.append(0)
        else:
            dir_norm_rad.append(0)
            dif_horiz_rad.append(0)
    return (dir_norm_rad, dif_horiz_rad)

Calculate solar flux for an original ASHRAE Clear Sky

Args:
altitudes: A list of solar altitudes in degrees
month: An integer (1-12) indicating the month the altitudes belong to
sky_clearness: A factor that will be multiplied by the output of
the model. This is to help account for locations where clear,
dry skies predominate (e.g., at high elevations) or,
conversely, where hazy and humid conditions are frequent. See
Threlkeld and Jordan (1958) for recommended values. Typical
values range from 0.95 to 1.05 and are usually never more
than 1.2. Default is set to 1.0.

Returns:
dir_norm_rad: A list of direct normal radiation values for each
of the connected altitudes in W/m2.
dif_horiz_rad: A list of diffuse horizontall radiation values for each
of the connected altitudes in W/m2.


async def delete(self, service_id: str) -> bool:

        await self.docker._query(
            "services/{service_id}".format(service_id=service_id), method="DELETE"
        )
        return True

Remove a service

Args:
service_id: ID or name of the service

Returns:
True if successful


def connect_output(self, node):
    if (len(self.outputs) == self.max_outputs):
        raise TooManyOutputsError('Attempted to connect too many nodes to the output of a node', max_outputs=self.max_outputs, stream=self.stream)
    self.outputs.append(node)

Connect another node to our output.

This downstream node will automatically be triggered when we update
our output.

Args:
node (SGNode): The node that should receive our output


def validate(self):
    if (not isinstance(self.enum, enumeration.EnumMeta)):
        raise TypeError('enumeration type {0} must be of type EnumMeta'.format(self.enum))
    if (self.value is not None):
        if (not isinstance(self.value, self.enum)):
            raise TypeError('enumeration {0} must be of type {1}'.format(self.value, self.enum))
        if (type(self.value.value) not in six.integer_types):
            raise TypeError('enumeration value must be an int')
        elif (self.value.value > Enumeration.MAX):
            raise ValueError('enumeration value greater than accepted max')
        elif (self.value.value < Enumeration.MIN):
            raise ValueError('enumeration value less than accepted min')

Verify that the value of the Enumeration is valid.

Raises:
TypeError: if the enum is not of type Enum
ValueError: if the value is not of the expected Enum subtype or if
the value cannot be represented by an unsigned 32-bit integer


def delete(self, key):

    self._cur_batch.delete(key)
    self._num_mutations += 1
    if self._num_mutations >= MAX_MUTATIONS_IN_BATCH:
      self.commit()
      self.begin()

Adds deletion of the entity with given key to the mutation buffer.

If mutation buffer reaches its capacity then this method commit all pending
mutations from the buffer and emties it.

Args:
key: key of the entity which should be deleted


def get_step_by_name(self, name):
    self._validate_step_name(name)
    name = str(name)
    try:
        return self.all_upstream_steps[name]
    except KeyError as e:
        msg = 'No Step with name "{}" found. You have following Steps: {}'.format(name, list(self.all_upstream_steps.keys()))
        raise StepError(msg) from e

Extracts step by name from the pipeline.

Extracted Step is a fully functional pipeline as well.
All upstream Steps are already defined.

Args:
name (str): name of the step to be fetched
Returns:
Step (obj): extracted step


def fromRaw(cls, skype=None, raw={}):
    return cls(skype, raw, **cls.rawToFields(raw))

Create a new instance based on the raw properties of an API response.

This can be overridden to automatically create subclass instances based on the raw content.

Args:
skype (Skype): parent Skype instance
raw (dict): raw object, as provided by the API

Returns:
SkypeObj: the new class instance


def if_callable_call_with_formatted_string(callback, formattable_string, *args):
    try:
        formatted_string = formattable_string.format(*args)
    except IndexError:
        raise ValueError('Mismatch metween amount of insertion points in the formattable string\nand the amount of args given.')
    if callable(callback):
        callback(formatted_string)

If the callback is callable, format the string with the args and make a call.
Otherwise, do nothing.

Args:
callback (function): May or may not be callable.
formattable_string (str): A string with '{}'s inserted.
*args: A variable amount of arguments for the string formatting. Must correspond to the
amount of '{}'s in 'formattable_string'.
Raises:
ValueError


def np2str(value):
    if (hasattr(value, 'dtype') and issubclass(value.dtype.type, (np.string_, np.object_)) and (value.size == 1)):
        value = np.asscalar(value)
        if (not isinstance(value, str)):
            value = value.decode()
        return value
    else:
        raise ValueError('Array is not a string type or is larger than 1')

Convert an `numpy.string_` to str.

Args:
value (ndarray): scalar or 1-element numpy array to convert

Raises:
ValueError: if value is array larger than 1-element or it is not of
type `numpy.string_` or it is not a numpy array


def shape_internal(input, name=None, optimize=True, out_type=None):
    with ops.name_scope(name, 'Shape', [input]) as name:
        if isinstance(input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
            if not out_type:
                out_type = dtypes.int32
            return gen_math_ops.cast(input.dense_shape, out_type)
        else:
            if not context.executing_eagerly():
                input = ops.convert_to_tensor(input)
                input_shape = input.get_shape()
                if optimize and input_shape.is_fully_defined():
                    if not out_type:
                        return constant_op._tensor_shape_tensor_conversion_function(input_shape)
                    return constant(input_shape.as_list(), out_type, name=name)
            if not out_type:
                out_type = dtypes.int32
            return gen_array_ops.shape(input, name=name, out_type=out_type)

Returns the shape of a tensor.

If `out_type` is not specified and the shape is fully known, then we look at
the dimension values to determine whether to return an int32 or int64 tensor.
If the shape is not fully known, we default to int32.

Args:
input: A `Tensor` or `SparseTensor`.
name: A name for the operation (optional).
optimize: if true, encode the shape as a constant when possible.
out_type: (Optional) The specified output type of the operation (`int32` or
`int64`). Defaults to tf.int32.

Returns:
A `Tensor` of type `out_type`.


def update(self, scope, at=0):

        if hasattr(scope, '_mixins') and not at:
            self._mixins.update(scope._mixins)
        self[at]['__variables__'].update(scope[at]['__variables__'])
        self[at]['__blocks__'].extend(scope[at]['__blocks__'])
        self[at]['__names__'].extend(scope[at]['__names__'])

Update scope. Add another scope to this one.
Args:
scope (Scope): Scope object
Kwargs:
at (int): Level to update


def click_nowait(self, pattern, action='click', desc=None, **match_kwargs):

        point = self.match(pattern, **match_kwargs)
        if not point or not point.matched:
            return None

        func = getattr(self, action)
        func(*point.pos)
        return point

Return immediately if no image found

Args:
- pattern (str or Pattern): filename or an opencv image object.
- action (str): click or long_click

Returns:
Click point or None


def guess_peb_size(path):
    file_offset = 0
    offsets = []
    f = open(path, 'rb')
    f.seek(0, 2)
    file_size = (f.tell() + 1)
    f.seek(0)
    for _ in range(0, file_size, FILE_CHUNK_SZ):
        buf = f.read(FILE_CHUNK_SZ)
        for m in re.finditer(UBI_EC_HDR_MAGIC, buf):
            start = m.start()
            if (not file_offset):
                file_offset = start
                idx = start
            else:
                idx = (start + file_offset)
            offsets.append(idx)
        file_offset += FILE_CHUNK_SZ
    f.close()
    occurances = {}
    for i in range(0, len(offsets)):
        try:
            diff = (offsets[i] - offsets[(i - 1)])
        except:
            diff = offsets[i]
        if (diff not in occurances):
            occurances[diff] = 0
        occurances[diff] += 1
    most_frequent = 0
    block_size = None
    for offset in occurances:
        if (occurances[offset] > most_frequent):
            most_frequent = occurances[offset]
            block_size = offset
    return block_size

Determine the most likely block size

Arguments:
Str:path    -- Path to file.

Returns:
Int         -- PEB size.

Searches file for Magic Number, picks most
common length between them.


def set_raw_datadir(self, directory=None):

        if directory is None:
            self.logger.info("no directory name given")
            return
        if not os.path.isdir(directory):
            self.logger.info(directory)
            self.logger.info("directory does not exist")
            return
        self.raw_datadir = directory

Set the directory containing .res-files.

Used for setting directory for looking for res-files.@
A valid directory name is required.

Args:
directory (str): path to res-directory

Example:
>>> d = CellpyData()
>>> directory = "MyData/Arbindata"
>>> d.set_raw_datadir(directory)


def AddSymbolicLink(self, path, linked_path):

    if self.file_system.FileEntryExistsByPath(path):
      raise ValueError('Path: {0:s} already set.'.format(path))

    self._AddParentDirectories(path)
    self.file_system.AddFileEntry(
        path, file_entry_type=definitions.FILE_ENTRY_TYPE_LINK,
        link_data=linked_path)

Adds a symbolic link to the fake file system.

Args:
path (str): path of the symbolic link within the fake file system.
linked_path (str): path that is linked.

Raises:
ValueError: if the path is already set.


def equals(self, actual_seq):
    try:
        expected = dict([(element, None) for element in self._expected_seq])
        actual = dict([(element, None) for element in actual_seq])
    except TypeError:
        expected = list(self._expected_seq)
        actual = list(actual_seq)
        expected.sort()
        actual.sort()
    return (expected == actual)

Check to see whether actual_seq has same elements as expected_seq.

Args:
actual_seq: sequence

Returns:
bool


def add_mount_point(self, path, total_size=None):

        path = self.absnormpath(path)
        if path in self.mount_points:
            self.raise_os_error(errno.EEXIST, path)
        self._last_dev += 1
        self.mount_points[path] = {
            'idev': self._last_dev, 'total_size': total_size, 'used_size': 0
        }

        root_dir = (self.root if path == self.root.name
                    else self.create_dir(path))
        root_dir.st_dev = self._last_dev
        return self.mount_points[path]

Add a new mount point for a filesystem device.
The mount point gets a new unique device number.

Args:
path: The root path for the new mount path.

total_size: The new total size of the added filesystem device
in bytes. Defaults to infinite size.

Returns:
The newly created mount point dict.

Raises:
OSError: if trying to mount an existing mount point again.


def _process_path_prefix(path_prefix):
    _validate_path(path_prefix)
    if (not _GCS_PATH_PREFIX_REGEX.match(path_prefix)):
        raise ValueError(('Path prefix should have format /bucket, /bucket/, or /bucket/prefix but got %s.' % path_prefix))
    bucket_name_end = path_prefix.find('/', 1)
    bucket = path_prefix
    prefix = None
    if (bucket_name_end != (- 1)):
        bucket = path_prefix[:bucket_name_end]
        prefix = (path_prefix[(bucket_name_end + 1):] or None)
    return (bucket, prefix)

Validate and process a Google Cloud Stoarge path prefix.

Args:
path_prefix: a Google Cloud Storage path prefix of format '/bucket/prefix'
or '/bucket/' or '/bucket'.

Raises:
ValueError: if path is invalid.

Returns:
a tuple of /bucket and prefix. prefix can be None.


def automatic_gamma_density(structure, kppa):

        latt = structure.lattice
        lengths = latt.abc
        ngrid = kppa / structure.num_sites

        mult = (ngrid * lengths[0] * lengths[1] * lengths[2]) ** (1 / 3)
        num_div = [int(round(mult / l)) for l in lengths]

        num_div = [i if i > 0 else 1 for i in num_div]

        num_div = [i + i % 2 if i <= 8 else i - i % 2 + 1 for i in num_div]

        style = Kpoints.supported_modes.Gamma

        comment = "pymatgen 4.7.6+ generated KPOINTS with grid density = " + \
                  "{} / atom".format(kppa)
        num_kpts = 0
        return Kpoints(comment, num_kpts, style, [num_div], [0, 0, 0])

Returns an automatic Kpoint object based on a structure and a kpoint
density. Uses Gamma centered meshes always. For GW.

Algorithm:
Uses a simple approach scaling the number of divisions along each
reciprocal lattice vector proportional to its length.

Args:
structure:
Input structure
kppa:
Grid density


def parse_bucket_info(domain):

    match = RGX_BUCKET.match(domain)
    if match:
        data = match.groupdict()
        return data['bucket'], data['region'] or 'us-east-1'

Parse a domain name to gather the bucket name and region for an S3 bucket. Returns a tuple
(bucket_name, bucket_region) if a valid domain name, else `None`

>>> parse_bucket_info('www.riotgames.com.br.s3-website-us-west-2.amazonaws.com')
('www.riotgames.com.br', 'us-west-2')

Args:
domain (`str`): Domain name to parse

Returns:
:obj:`list` of `str`: `str`,`None`


def register(config_class, slow_tokenizer_class=None, fast_tokenizer_class=None, exist_ok=False):
    if slow_tokenizer_class is None and fast_tokenizer_class is None:
        raise ValueError('You need to pass either a `slow_tokenizer_class` or a `fast_tokenizer_class')
    if slow_tokenizer_class is not None and issubclass(slow_tokenizer_class, PreTrainedTokenizerFast):
        raise ValueError('You passed a fast tokenizer in the `slow_tokenizer_class`.')
    if fast_tokenizer_class is not None and issubclass(fast_tokenizer_class, PreTrainedTokenizer):
        raise ValueError('You passed a slow tokenizer in the `fast_tokenizer_class`.')
    if slow_tokenizer_class is not None and fast_tokenizer_class is not None and issubclass(fast_tokenizer_class, PreTrainedTokenizerFast) and (fast_tokenizer_class.slow_tokenizer_class != slow_tokenizer_class):
        raise ValueError(f'The fast tokenizer class you are passing has a `slow_tokenizer_class` attribute that is not consistent with the slow tokenizer class you passed (fast tokenizer has {fast_tokenizer_class.slow_tokenizer_class} and you passed {slow_tokenizer_class}. Fix one of those so they match!')
    if config_class in TOKENIZER_MAPPING._extra_content:
        existing_slow, existing_fast = TOKENIZER_MAPPING[config_class]
        if slow_tokenizer_class is None:
            slow_tokenizer_class = existing_slow
        if fast_tokenizer_class is None:
            fast_tokenizer_class = existing_fast
    TOKENIZER_MAPPING.register(config_class, (slow_tokenizer_class, fast_tokenizer_class), exist_ok=exist_ok)

Register a new tokenizer in this mapping.

Args:
config_class ([`PretrainedConfig`]):
The configuration corresponding to the model to register.
slow_tokenizer_class ([`PretrainedTokenizer`], *optional*):
The slow tokenizer to register.
fast_tokenizer_class ([`PretrainedTokenizerFast`], *optional*):
The fast tokenizer to register.


def __call__(self, images: ImageInput=None, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]=None, audio=None, videos=None, **kwargs: Unpack[InstructBlipProcessorKwargs]) -> BatchFeature:
    if images is None and text is None:
        raise ValueError('You have to specify at least images or text.')
    output_kwargs = self._merge_kwargs(InstructBlipProcessorKwargs, tokenizer_init_kwargs=self.tokenizer.init_kwargs, **kwargs)
    encoding = BatchFeature()
    if text is not None:
        if isinstance(text, str):
            text = [text]
        elif not isinstance(text, list) and (not isinstance(text[0], str)):
            raise ValueError('Invalid input text. Please provide a string, or a list of strings')
        return_tensors = output_kwargs['text_kwargs'].pop('return_tensors', None)
        _text_encoding = self.tokenizer(text, **output_kwargs['text_kwargs'], return_tensors=None)
        output_kwargs['text_kwargs']['return_tensors'] = return_tensors
        if self.num_query_tokens is not None and images is not None:
            text_encoding = {}
            image_tokens = self.image_token.content * self.num_query_tokens
            image_token_encoding = self.tokenizer([image_tokens] * len(text), add_special_tokens=False, return_tensors=None)
            for k in _text_encoding:
                text_encoding[k] = [img_encoding + txt_encoding for img_encoding, txt_encoding in zip(image_token_encoding[k], _text_encoding[k])]
        else:
            text_encoding = _text_encoding
            if images is not None:
                logger.warning_once('Expanding inputs for image tokens in InstructBLIP should be done in processing. Please follow instruction here (https:
        text_encoding = BatchEncoding(text_encoding, tensor_type=return_tensors)
        encoding.update(text_encoding)
        qformer_text_encoding = self.qformer_tokenizer(text, **output_kwargs['text_kwargs'])
        encoding['qformer_input_ids'] = qformer_text_encoding.pop('input_ids')
        encoding['qformer_attention_mask'] = qformer_text_encoding.pop('attention_mask')
    if images is not None:
        image_encoding = self.image_processor(images, **output_kwargs['images_kwargs'])
        encoding.update(image_encoding)
    return encoding

This method uses [`BlipImageProcessor.__call__`] method to prepare image(s) for the model, and
[`BertTokenizerFast.__call__`] to prepare text for the model.

Please refer to the docstring of the above two methods for more information.
Args:
images (`ImageInput`):
The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
tensor. Both channels-first and channels-last formats are supported.
text (`TextInput`, `PreTokenizedInput`, `List[TextInput]`, `List[PreTokenizedInput]`):
The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
(pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
`is_split_into_words=True` (to lift the ambiguity with a batch of sequences).


def StopTaskStorage(self, abort=False):

    if self._storage_type != definitions.STORAGE_TYPE_SESSION:
      raise IOError('Unsupported storage type.')

    if os.path.isdir(self._merge_task_storage_path):
      if abort:
        shutil.rmtree(self._merge_task_storage_path)
      else:
        os.rmdir(self._merge_task_storage_path)

    if os.path.isdir(self._processed_task_storage_path):
      if abort:
        shutil.rmtree(self._processed_task_storage_path)
      else:
        os.rmdir(self._processed_task_storage_path)

    if os.path.isdir(self._task_storage_path):
      if abort:
        shutil.rmtree(self._task_storage_path)
      else:
        os.rmdir(self._task_storage_path)

    self._merge_task_storage_path = None
    self._processed_task_storage_path = None
    self._task_storage_path = None

Removes the temporary path for the task storage.

The results of tasks will be lost on abort.

Args:
abort (bool): True to indicate the stop is issued on abort.

Raises:
IOError: if the storage type is not supported.
OSError: if the storage type is not supported.


def extract_version(exepath, version_arg, word_index=(- 1), version_rank=3):
    if isinstance(version_arg, basestring):
        version_arg = [version_arg]
    args = ([exepath] + version_arg)
    (stdout, stderr, returncode) = _run_command(args)
    if returncode:
        raise RezBindError(('failed to execute %s: %s\n(error code %d)' % (exepath, stderr, returncode)))
    stdout = stdout.strip().split('\n')[0].strip()
    log(("extracting version from output: '%s'" % stdout))
    try:
        strver = stdout.split()[word_index]
        toks = strver.replace('.', ' ').replace('-', ' ').split()
        strver = '.'.join(toks[:version_rank])
        version = Version(strver)
    except Exception as e:
        raise RezBindError(("failed to parse version from output '%s': %s" % (stdout, str(e))))
    log(("extracted version: '%s'" % str(version)))
    return version

Run an executable and get the program version.

Args:
exepath: Filepath to executable.
version_arg: Arg to pass to program, eg "-V". Can also be a list.
word_index: Expect the Nth word of output to be the version.
version_rank: Cap the version to this many tokens.

Returns:
`Version` object.


def change_wavelength(self, wavelength):

        for name, slab in self.slabs.items():
            const_args = slab._const_args
            mat_args = slab._mat_params

            const_args[8] = wavelength

            s = Slab(*const_args)
            for mat_arg in mat_args:
                s.add_material(*mat_arg)

            self.slabs[name] = s

        self._wl = wavelength

Changes the wavelength of the structure.

This will affect the mode solver and potentially
the refractive indices used (provided functions
were provided as refractive indices).

Args:
wavelength (float): The new wavelength.


def remove_file_from_tree(tree, file_path):
    match = None
    for item in tree:
        if (item.get('path') == file_path):
            match = item
            break
    if match:
        tree.remove(match)
    return tree

Remove a file from a tree.

Args:

tree
A list of dicts containing info about each blob in a tree.

file_path
The path of a file to remove from a tree.

Returns:
The provided tree, but with the item matching the specified
file_path removed.


def get_folder_details(self, folder):
    if (not is_valid_uuid(folder)):
        raise StorageArgumentException('Invalid UUID for folder: {0}'.format(folder))
    return self._authenticated_request.to_endpoint('folder/{}/'.format(folder)).return_body().get()

Get information on a given folder.

Args:
folder (str): The UUID of the requested folder.

Returns:
A dictionary of the folder details if found::

{
u'created_by': u'303447',
u'created_on': u'2017-03-21T14:06:32.293902Z',
u'description': u'',
u'entity_type': u'folder',
u'modified_by': u'303447',
u'modified_on': u'2017-03-21T14:06:32.293967Z',
u'name': u'myfolder',
u'parent': u'3abd8742-d069-44cf-a66b-2370df74a682',
u'uuid': u'2516442e-1e26-4de1-8ed8-94523224cc40'
}

Raises:
StorageArgumentException: Invalid arguments
StorageForbiddenException: Server response code 403
StorageNotFoundException: Server response code 404
StorageException: other 400-600 error codes


def intent(method):

    def wrapper(self, *args, **kwargs):
        try:
            return method(self, *args, **kwargs)
        except exceptions.MatrixError as e:
            if isinstance(e.original_exception,
                          matrix_client.errors.MatrixRequestError):
                self._handle_request_exception(e)

                return method(self, *args, **kwargs)
            else:
                raise e

    return wrapper

Helps object methods handle MatrixRequestError.

Args:
method(function): Object method to be wrapped

Method's object must have _handle_request_exception method that deals with
specific status codes and errcodes.


def cluster_from_file(filename):
    atoms_string = Atoms.atoms_string_from_file(filename)
    line_list = [l.split() for l in atoms_string.splitlines()[3:]]
    coords = []
    symbols = []
    for l in line_list:
        if l:
            coords.append([float(i) for i in l[:3]])
            symbols.append(l[4])
    return Molecule(symbols, coords)

Parse the feff input file and return the atomic cluster as a Molecule
object.

Args:
filename (str): path the feff input file

Returns:
Molecule: the atomic cluster as Molecule object. The absorbing atom
is the one at the origin.


def Decrypt(self, encrypted_data):

    index_split = -(len(encrypted_data) % DES3.block_size)
    if index_split:
      remaining_encrypted_data = encrypted_data[index_split:]
      encrypted_data = encrypted_data[:index_split]
    else:
      remaining_encrypted_data = b''

    decrypted_data = self._des3_cipher.decrypt(encrypted_data)

    return decrypted_data, remaining_encrypted_data

Decrypts the encrypted data.

Args:
encrypted_data (bytes): encrypted data.

Returns:
tuple[bytes, bytes]: decrypted data and remaining encrypted data.


def append_memory_pdf_to_writer(input_pdf: bytes,
                                writer: PdfFileWriter,
                                start_recto: bool = True) -> None:

    if not input_pdf:
        return
    if start_recto and writer.getNumPages() % 2 != 0:
        writer.addBlankPage()

    infile = io.BytesIO(input_pdf)
    reader = PdfFileReader(infile)
    for page_num in range(reader.numPages):
        writer.addPage(reader.getPage(page_num))

Appends a PDF (as bytes in memory) to a PyPDF2 writer.

Args:
input_pdf: the PDF, as ``bytes``
writer: the writer
start_recto: start a new right-hand page?


def _add_ragged_partition(values, partition, tensor_dict, row_splits_dtype, validate):
    if isinstance(partition, RaggedFeature.UniformRowLength):
        if isinstance(values, ragged_tensor.RaggedTensor):
            length = ops.convert_to_tensor(partition.length, dtype=row_splits_dtype)
            return ragged_tensor.RaggedTensor.from_uniform_row_length(values, length, validate=validate)
        else:
            return array_ops.reshape(values, array_ops.concat([[-1, partition.length], array_ops.shape(values)[1:]], axis=0))
    else:
        partition_t = math_ops.cast(tensor_dict[partition.key], row_splits_dtype)
        if isinstance(partition, RaggedFeature.RowSplits):
            return ragged_tensor.RaggedTensor.from_row_splits(values, partition_t, validate=validate)
        elif isinstance(partition, RaggedFeature.RowLengths):
            return ragged_tensor.RaggedTensor.from_row_lengths(values, partition_t, validate=validate)
        elif isinstance(partition, RaggedFeature.RowStarts):
            return ragged_tensor.RaggedTensor.from_row_starts(values, partition_t, validate=validate)
        elif isinstance(partition, RaggedFeature.RowLimits):
            return ragged_tensor.RaggedTensor.from_row_limits(values, partition_t, validate=validate)
        elif isinstance(partition, RaggedFeature.ValueRowIds):
            return ragged_tensor.RaggedTensor.from_value_rowids(values, partition_t, validate=validate)
        raise ValueError(f'Unhandled partition type {partition!r}')

Creates a RaggedTensor from a values tensor and a partition tensor.

Args:
values: The values tensor for the new RaggedTensor.
partition: The partition configuration object.  Specifies the key that
should be used to look up the partition tensor (unless partition is a
RaggedFeature.UniformRowLength, in which case there is no partition
tensor).
tensor_dict: The dictionary mapping keys to tensors.
row_splits_dtype: The dtype for the partition tensor.
validate: Whether to validate that the values form a valid RaggedTensor.

Returns:
A new RaggedTensor formed from the values and partition tensors.


def constraint(self):
    raise NotImplementedError

Returns the constraint function associated with this variable.

Returns:
The constraint function that was passed to the variable constructor.
Can be `None` if no constraint was passed.


def parse_docs(docs, marks):
    if (docs is None):
        return {}
    indexs = []
    for mark in marks:
        i = docs.find(mark)
        if (i >= 0):
            indexs.append(i)
    if (not indexs):
        return {'$desc': textwrap.dedent(docs).strip()}
    start = min(indexs)
    start = docs.rfind('\n', 0, start)
    yamltext = textwrap.dedent(docs[(start + 1):])
    meta = yaml.load(yamltext)
    meta['$desc'] = textwrap.dedent(docs[:start]).strip()
    return meta

Parse YAML syntax content from docs

If docs is None, return {}
If docs has no YAML content, return {"$desc": docs}
Else, parse YAML content, return {"$desc": docs, YAML}

Args:
docs (str): docs to be parsed
marks (list): list of which indicate YAML content starts
Returns:
A dict contains information of docs


def state(self):
    try:
        return libvirt_utils.Domain.resolve_state(self.raw_state())
    except vm_plugin.LagoVMDoesNotExistError:
        return 'down'
    except vm_plugin.LagoFailedToGetVMStateError:
        return 'failed to get state'
    except KeyError:
        return 'unknown state'

Return a small description of the current status of the domain

Returns:
str: small description of the domain status, 'down' if it's not
found at all.


def histogram(self, tag, values, bins, step=None):

    if step is None:
      step = self._step
    else:
      self._step = step
    values = onp.array(values)
    bins = onp.array(bins)
    values = onp.reshape(values, -1)
    counts, limits = onp.histogram(values, bins=bins)

    cum_counts = onp.cumsum(onp.greater(counts, 0, dtype=onp.int32))
    start, end = onp.searchsorted(
        cum_counts, [0, cum_counts[-1] - 1], side='right')
    start, end = int(start), int(end) + 1
    counts = (
        counts[start -
               1:end] if start > 0 else onp.concatenate([[0], counts[:end]]))
    limits = limits[start:end + 1]
    sum_sq = values.dot(values)
    histo = HistogramProto(
        min=values.min(),
        max=values.max(),
        num=len(values),
        sum=values.sum(),
        sum_squares=sum_sq,
        bucket_limit=limits.tolist(),
        bucket=counts.tolist())
    summary = Summary(value=[Summary.Value(tag=tag, histo=histo)])
    self.add_summary(summary, step)

Saves histogram of values.

Args:
tag: str: label for this data
values: ndarray: will be flattened by this routine
bins: number of bins in histogram, or array of bins for onp.histogram
step: int: training step


def color_palette_dict(self, alpha=0.35):

        color_dict = {}
        for hkl in self.all_slab_entries.keys():
            rgb_indices = [0, 1, 2]
            color = [0, 0, 0, 1]
            random.shuffle(rgb_indices)
            for i, ind in enumerate(rgb_indices):
                if i == 2:
                    break
                color[ind] = np.random.uniform(0, 1)

            clean_list = np.linspace(0, 1, len(self.all_slab_entries[hkl]))
            for i, clean in enumerate(self.all_slab_entries[hkl].keys()):
                c = copy.copy(color)
                c[rgb_indices[2]] = clean_list[i]
                color_dict[clean] = c

                for ads_entry in self.all_slab_entries[hkl][clean]:
                    c_ads = copy.copy(c)
                    c_ads[3] = alpha
                    color_dict[ads_entry] = c_ads

        return color_dict

Helper function to assign each facet a unique color using a dictionary.

Args:
alpha (float): Degree of transparency

return (dict): Dictionary of colors (r,g,b,a) when plotting surface
energy stability. The keys are individual surface entries where
clean surfaces have a solid color while the corresponding adsorbed
surface will be transparent.


def load_spacy_rule(file_path: str) -> Dict:

        with open(file_path) as fp:
            return json.load(fp)

A spacy rule file is a json file.

Args:
file_path (str): path to a text file containing a spacy rule sets.

Returns: Dict as the representation of spacy rules


def _validate_tensor_info(self, tensor_info):
    if tensor_info is None:
        raise AssertionError('All TensorInfo protos used in the SignatureDefs must have the name and dtype fields set.')
    if tensor_info.WhichOneof('encoding') is None:
        raise AssertionError(f"Invalid `tensor_info`: {tensor_info}. All TensorInfo protos used in the SignatureDefs must have one of the 'encoding' fields (e.g., name or coo_sparse) set.")
    if tensor_info.WhichOneof('encoding') == 'composite_tensor':
        for component in tensor_info.composite_tensor.components:
            self._validate_tensor_info(component)
    elif tensor_info.dtype == types_pb2.DT_INVALID:
        raise AssertionError(f'Invalid `tensor_info`: {tensor_info}. All TensorInfo protos used in the SignatureDefs must have the dtype field set.')

Validates the `TensorInfo` proto.

Checks if the `encoding` (`name` or `coo_sparse` or `type_spec`) and
`dtype` fields exist and are non-empty.

Args:
tensor_info: `TensorInfo` protocol buffer to validate.

Raises:
AssertionError: If the `encoding` or `dtype` fields of the supplied
`TensorInfo` proto are not populated.


def list(self):
    import IPython
    data = [{'name': version['name'].split()[(- 1)], 'deploymentUri': version['deploymentUri'], 'createTime': version['createTime']} for version in self.get_iterator()]
    IPython.display.display(datalab.utils.commands.render_dictionary(data, ['name', 'deploymentUri', 'createTime']))

List versions under the current model in a table view.

Raises:
Exception if it is called in a non-IPython environment.


def Audio(self, run, tag):
    accumulator = self.GetAccumulator(run)
    return accumulator.Audio(tag)

Retrieve the audio events associated with a run and tag.

Args:
run: A string name of the run for which values are retrieved.
tag: A string name of the tag for which values are retrieved.

Raises:
KeyError: If the run is not found, or the tag is not available for
the given run.

Returns:
An array of `event_accumulator.AudioEvents`.


def __init__(self, name: Union[str, bytes], bound_context: context.Context, function_type: function_type_lib.FunctionType, children: Optional[List['AtomicFunction']]=None, call_options: CallOptions=CallOptions(), cached_graph: Optional[func_graph_module.FuncGraph]=None):
    self._name = compat.as_bytes(name)
    self._bound_context = bound_context
    self._function_type = function_type
    self._children = children if children else []
    self._call_options = call_options
    self._cached_definition = None
    self._cached_graph = cached_graph
    self._generated_graph = None
    ref_key = (self._bound_context.function_scope_id, self.name)
    if ref_key not in RUNTIME_FUNCTION_REFS:
        RUNTIME_FUNCTION_REFS[ref_key] = 1
    else:
        RUNTIME_FUNCTION_REFS[ref_key] += 1

Construct a new AtomicFunction.

Args:
name: str/bytes name of the runtime function in the bound context.
bound_context: interface to the runtime for the AtomicFunction.
function_type: input/output contract for the AtomicFunction
children: list of AtomicFunctions that are needed to call this one.
call_options: extra configuration options for the call.
cached_graph: FuncGraph that this AtomicFunction was generated from (if
known). Otherwise it will lazily construct a new corresponding FuncGraph
if ever needed.


def persist_as_png(structure_dict, filepath):
    graph = _create_graph(structure_dict)
    graph.write(filepath, format='png')

Saves pipeline diagram to disk as png file.

Args:
structure_dict (dict): dict returned by
:func:`~steppy.base.Step.upstream_structure`
filepath (str): filepath to which the png with pipeline visualization should be persisted


def close_position(self, repay_only):
    params = {'repay_only': repay_only}
    return self._send_message('post', '/position/close', data=json.dumps(params))

Close position.

Args:
repay_only (bool): Undocumented by cbpro.

Returns:
Undocumented


def load_b26_file(file_name):
    assert os.path.exists(file_name)
    with open(file_name, 'r') as infile:
        data = yaml.safe_load(infile)
    return data

loads a .b26 file into a dictionary

Args:
file_name:

Returns: dictionary with keys instrument, scripts, probes


def assign(self, value, use_locking=False, name=None, read_value=True):
    raise NotImplementedError

Assigns a new value to the variable.

This is essentially a shortcut for `assign(self, value)`.

Args:
value: A `Tensor`. The new value for this variable.
use_locking: If `True`, use locking during the assignment.
name: The name of the operation to be created
read_value: if True, will return something which evaluates to the new
value of the variable; if False will return the assign op.

Returns:
The updated variable. If `read_value` is false, instead returns None in
Eager mode and the assign op in graph mode.


def reset_dtensor_device(is_async: bool) -> None:
    global _dtensor_singleton
    device = dtensor_device.DTensorDevice(meshes=[], is_async=is_async)
    _dtensor_singleton = device

Resets the Eager execution device for DTensor.

This function is only intended for testing and diagnostics.

Args:
is_async: If True, the device uses async execution.


def ping(self, timeout=12):
    self.conn('POST', '{0}/users/ME/endpoints/{1}/active'.format(self.conn.msgsHost, self.id), auth=SkypeConnection.Auth.RegToken, json={'timeout': timeout})

Send a keep-alive request for the endpoint.

Args:
timeout (int): maximum amount of time for the endpoint to stay active


def list_container_services_sub(access_token, subscription_id):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.ContainerService/ContainerServices',
                        '?api-version=', ACS_API])
    return do_get(endpoint, access_token)

List the container services in a subscription.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.

Returns:
HTTP response. JSON model.


def save_scatter_table(self, fn, description=''):
    data = {'description': description, 'time': datetime.now(), 'psd_scatter': (self.num_points, self.D_max, self._psd_D, self._S_table, self._Z_table, self._angular_table, self._m_table, self.geometries), 'version': tmatrix_aux.VERSION}
    pickle.dump(data, file(fn, 'w'), pickle.HIGHEST_PROTOCOL)

Save the scattering lookup tables.

Save the state of the scattering lookup tables to a file.
This can be loaded later with load_scatter_table.

Other variables will not be saved, but this does not matter because
the results of the computations are based only on the contents
of the table.

Args:
fn: The name of the scattering table file.
description (optional): A description of the table.


def filter_by_doys(self, doys):

        _filt_values = []
        _filt_datetimes = []
        for i, d in enumerate(self.datetimes):
            if d in doys:
                _filt_datetimes.append(d)
                _filt_values.append(self._values[i])
        _filt_header = self.header.duplicate()
        return DailyCollection(_filt_header, _filt_values, _filt_datetimes)

Filter the Data Collection based on a list of days of the year (as integers).

Args:
doys: A List of days of the year [1..365]

Return:
A new Data Collection with filtered data


def set_sleep_timer(self, sleep_time_seconds):
    try:
        if (sleep_time_seconds is None):
            sleep_time = ''
        else:
            sleep_time = format(datetime.timedelta(seconds=int(sleep_time_seconds)))
        self.avTransport.ConfigureSleepTimer([('InstanceID', 0), ('NewSleepTimerDuration', sleep_time)])
    except SoCoUPnPException as err:
        if ('Error 402 received' in str(err)):
            raise ValueError('invalid sleep_time_seconds, must be integer                     value between 0 and 86399 inclusive or None')
        raise
    except ValueError:
        raise ValueError('invalid sleep_time_seconds, must be integer                 value between 0 and 86399 inclusive or None')

Sets the sleep timer.

Args:
sleep_time_seconds (int or NoneType): How long to wait before
turning off speaker in seconds, None to cancel a sleep timer.
Maximum value of 86399

Raises:
SoCoException: Upon errors interacting with Sonos controller
ValueError: Argument/Syntax errors


def is_remote_added(remote):
    out = __salt__['cmd.run_all']((FLATPAK_BINARY_NAME + ' remotes'))
    lines = out.splitlines()
    for item in lines:
        i = re.split('\\t+', item.rstrip('\t'))
        if (i[0] == remote):
            return True
    return False

Determines if a remote exists.

Args:
remote (str): The remote's name.

Returns:
bool: True if the remote has already been added.

CLI Example:

.. code-block:: bash

salt '*' flatpak.is_remote_added flathub


def get_output_mask_at(self, node_index):
    output = self.get_output_at(node_index)
    if isinstance(output, list):
        return [getattr(x, '_keras_mask', None) for x in output]
    else:
        return getattr(output, '_keras_mask', None)

Retrieves the output mask tensor(s) of a layer at a given node.

Args:
node_index: Integer, index of the node
from which to retrieve the attribute.
E.g. `node_index=0` will correspond to the
first time the layer was called.

Returns:
A mask tensor
(or list of tensors if the layer has multiple outputs).


def register_access_db(fullfilename: str, dsn: str, description: str) -> bool:

    directory = os.path.dirname(fullfilename)
    return create_sys_dsn(
        access_driver,
        SERVER="",
        DESCRIPTION=description,
        DSN=dsn,
        DBQ=fullfilename,
        DefaultDir=directory
    )

(Windows only.)
Registers a Microsoft Access database with ODBC.

Args:
fullfilename: filename of the existing database
dsn: ODBC data source name to create
description: description of the database

Returns:
bool: was the DSN created?


def get_data_files_path():
    return _os.path.dirname(_inspect.getfile(_sys._getframe(1)))

Get a direct path to the data files colocated with the script.

Returns:
The directory where files specified in data attribute of py_test
and py_binary are stored.


def FixValue(value):
    if value.startswith('"') and value.endswith('"') or (value.startswith("'") and value.endswith("'")):
        value = value[1:-1]
    try:
        value = int(value)
    except ValueError:
        try:
            value = float(value)
        except ValueError:
            return value
    return value

Helper function to fix values loaded from a config file.

Currently we strip bracketed quotes as well as convert numbers to
floats for configuration parameters expecting numerical data types.

Args:
value: value to be converted

Returns:
fixed value


def run_step(self, context):
    logger.debug('starting')
    self.set_step_input_context(context)
    if self.while_decorator:
        self.while_decorator.while_loop(context, self.run_foreach_or_conditional)
    else:
        self.run_foreach_or_conditional(context)
    logger.debug('done')

Run a single pipeline step.

Args:
context: (pypyr.context.Context) The pypyr context. This arg will
mutate.


def verify_certs_chain(certs_chain: List[crypto.X509], amazon_cert: crypto.X509) -> bool:

    store = crypto.X509Store()

    for cert in certs_chain:
        store.add_cert(cert)

    default_verify_paths = ssl.get_default_verify_paths()

    default_verify_file = default_verify_paths.cafile
    default_verify_file = Path(default_verify_file).resolve() if default_verify_file else None

    default_verify_path = default_verify_paths.capath
    default_verify_path = Path(default_verify_path).resolve() if default_verify_path else None

    ca_files = [ca_file for ca_file in default_verify_path.iterdir()] if default_verify_path else []
    if default_verify_file:
        ca_files.append(default_verify_file)

    for ca_file in ca_files:
        ca_file: Path
        if ca_file.is_file():
            with ca_file.open('r', encoding='ascii') as crt_f:
                ca_certs_txt = crt_f.read()
                ca_certs = extract_certs(ca_certs_txt)
                for cert in ca_certs:
                    store.add_cert(cert)

    ssl_context = ssl.create_default_context()
    der_certs = ssl_context.get_ca_certs(binary_form=True)
    pem_certs = '\n'.join([ssl.DER_cert_to_PEM_cert(der_cert) for der_cert in der_certs])
    ca_certs = extract_certs(pem_certs)
    for ca_cert in ca_certs:
        store.add_cert(ca_cert)

    store_context = crypto.X509StoreContext(store, amazon_cert)

    try:
        store_context.verify_certificate()
        result = True
    except crypto.X509StoreContextError:
        result = False

    return result

Verifies if Amazon and additional certificates creates chain of trust to a root CA.

Args:
certs_chain: List of pycrypto X509 intermediate certificates from signature chain URL.
amazon_cert: Pycrypto X509 Amazon certificate.

Returns:
result: True if verification was successful, False if not.


def solution(swarm):

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

Determines the global best particle in the swarm.

Args:
swarm: iterable: an iterable that yields all particles in the swarm.

Returns:
cipy.algorithms.pso.Particle: The best particle in the swarm when
comparing the best_fitness values of the particles.


def is_native_xmon_op(op: ops.Operation) -> bool:
    return (isinstance(op, ops.GateOperation) and is_native_xmon_gate(op.gate))

Check if the gate corresponding to an operation is a native xmon gate.

Args:
op: Input operation.

Returns:
True if the operation is native to the xmon, false otherwise.


def get_img_shape(img):

    if isinstance(img, np.ndarray):
        shape = img.shape
    else:
        shape = K.int_shape(img)

    if K.image_data_format() == 'channels_last':
        shape = list(shape)
        shape.insert(1, shape[-1])
        shape = tuple(shape[:-1])
    return shape

Returns image shape in a backend agnostic manner.

Args:
img: An image tensor of shape: `(channels, image_dims...)` if data_format='channels_first' or
`(image_dims..., channels)` if data_format='channels_last'.

Returns:
Tuple containing image shape information in `(samples, channels, image_dims...)` order.


def verify_sans(amazon_cert: crypto.X509) -> bool:

    cert_extentions = [amazon_cert.get_extension(i) for i in range(amazon_cert.get_extension_count())]
    subject_alt_names = ''

    for extention in cert_extentions:
        if 'subjectAltName' in str(extention.get_short_name()):
            subject_alt_names = extention.__str__()
            break

    result = 'echo-api.amazon.com' in subject_alt_names

    return result

Verifies Subject Alternative Names (SANs) for Amazon certificate.

Args:
amazon_cert: Pycrypto X509 Amazon certificate.

Returns:
result: True if verification was successful, False if not.


def swo_disable(self, port_mask):
    res = self._dll.JLINKARM_SWO_DisableTarget(port_mask)
    if (res != 0):
        raise errors.JLinkException(res)
    return None

Disables ITM & Stimulus ports.

Args:
self (JLink): the ``JLink`` instance
port_mask (int): mask specifying which ports to disable

Returns:
``None``

Raises:
JLinkException: on error


def _validate_testbed_name(name):

    if not name:
        raise MoblyConfigError("Test bed names can't be empty.")
    name = str(name)
    for char in name:
        if char not in utils.valid_filename_chars:
            raise MoblyConfigError(
                'Char "%s" is not allowed in test bed names.' % char)

Validates the name of a test bed.

Since test bed names are used as part of the test run id, it needs to meet
certain requirements.

Args:
name: The test bed's name specified in config file.

Raises:
MoblyConfigError: The name does not meet any criteria.


def _replace_variable_with_pattern(match):
    positional = match.group('positional')
    name = match.group('name')
    template = match.group('template')
    if (name is not None):
        if (not template):
            return _SINGLE_SEGMENT_PATTERN.format(name)
        elif (template == '**'):
            return _MULTI_SEGMENT_PATTERN.format(name)
        else:
            return _generate_pattern_for_template(template)
    elif (positional == '*'):
        return _SINGLE_SEGMENT_PATTERN
    elif (positional == '**'):
        return _MULTI_SEGMENT_PATTERN
    else:
        raise ValueError('Unknown template expression {}'.format(match.group(0)))

Replace a variable match with a pattern that can be used to validate it.

Args:
match (re.Match): A regular expression match

Returns:
str: A regular expression pattern that can be used to validate the
variable in an expanded path.

Raises:
ValueError: If an unexpected template expression is encountered.


def _get_app_path(url):
    app_path = urlparse(url).path.rstrip('/')
    if (not app_path.startswith('/')):
        app_path = ('/' + app_path)
    return app_path

Extract the app path from a Bokeh server URL

Args:
url (str) :

Returns:
str


def upsert_variant(self, variant_obj):

        LOG.debug("Upserting variant %s", variant_obj['_id'])
        try:
            result = self.variant_collection.insert_one(variant_obj)
        except DuplicateKeyError as err:
            LOG.debug("Variant %s already exists in database", variant_obj['_id'])
            result = self.variant_collection.find_one_and_update(
                {'_id': variant_obj['_id']},
                {
                    '$set': {
                        'compounds': variant_obj.get('compounds',[])
                    }
                }
            )
            variant = self.variant_collection.find_one({'_id': variant_obj['_id']})
        return result

Load a variant object, if the object already exists update compounds.

Args:
variant_obj(dict)

Returns:
result


def _conditional_patch(src: symbolic.Symbolic, condition: Callable[[utils.KeyPath, Any, symbolic.Symbolic], bool], value: Any=None, value_fn: Optional[Callable[[Any], Any]]=None, skip_notification: Optional[bool]=None) -> Any:
    if value_fn is not None and value is not None:
        raise ValueError('Either `value` or `value_fn` should be specified.')

    def _fn(k, v, p):
        if condition(k, v, p):
            return value_fn(v) if value_fn else value
        return v
    return src.rebind(_fn, raise_on_no_change=False, skip_notification=skip_notification)

Recursive patch values on condition.

Args:
src: symbolic value to patch.
condition: Callable object with signature (key_path, value, parent) which
returns whether a field should be patched.
value: New value for field that satisfy `condition`.
value_fn: Callable object that produces new value based on old value.
If not None, `value` must be None.
skip_notification: If True, `on_change` event will not be triggered for this
operation. If None, the behavior is decided by `pg.notify_on_rebind`.
Please see `symbolic.Symbolic.rebind` for details.

Returns:
`src` after being patched.


def find_ruuvitags(bt_device=''):
    log.info('Finding RuuviTags. Stop with Ctrl+C.')
    datas = dict()
    for new_data in RuuviTagSensor._get_ruuvitag_datas(bt_device=bt_device):
        if (new_data[0] in datas):
            continue
        datas[new_data[0]] = new_data[1]
        log.info(new_data[0])
        log.info(new_data[1])
    return datas

Find all RuuviTags. Function will print the mac and the state of the sensors when found.
Function will execute as long as it is stopped. Stop ecexution with Crtl+C.

Returns:
dict: MAC and state of found sensors


def on_core_metadata_event(self, event):
    core_metadata = json.loads(event.log_message.message)
    input_names = ','.join(core_metadata['input_names'])
    output_names = ','.join(core_metadata['output_names'])
    target_nodes = ','.join(core_metadata['target_nodes'])
    self._run_key = RunKey(input_names, output_names, target_nodes)
    if (not self._graph_defs):
        self._graph_defs_arrive_first = False
    else:
        for device_name in self._graph_defs:
            self._add_graph_def(device_name, self._graph_defs[device_name])
    self._outgoing_channel.put(_comm_metadata(self._run_key, event.wall_time))
    logger.info('on_core_metadata_event() waiting for client ack (meta)...')
    self._incoming_channel.get()
    logger.info('on_core_metadata_event() client ack received (meta).')

Implementation of the core metadata-carrying Event proto callback.

Args:
event: An Event proto that contains core metadata about the debugged
Session::Run() in its log_message.message field, as a JSON string.
See the doc string of debug_data.DebugDumpDir.core_metadata for details.


def n_feature_hash(feature, dims, seeds):
    vec = np.zeros(sum(dims))
    offset = 0
    for (seed, dim) in zip(seeds, dims):
        vec[offset:(offset + dim)] = feature_hash(feature, dim, seed)
        offset += dim
    return vec

N-hot-encoded feature hashing.

Args:
feature (str): Target feature represented as string.
dims (list of int): Number of dimensions for each hash value.
seeds (list of float): Seed of each hash function (mmh3).

Returns:
numpy 1d array: n-hot-encoded feature vector for `s`.


def listen(self):

        self.listening = True
        if self.threading:
            from threading import Thread
            self.listen_thread = Thread(target=self.listen_loop)
            self.listen_thread.daemon = True
            self.listen_thread.start()

            self.scheduler_thread = Thread(target=self.scheduler)
            self.scheduler_thread.daemon = True
            self.scheduler_thread.start()

        else:
            self.listen_loop()

Starts the listen loop. If threading is enabled, then the loop will
be started in its own thread.

Args:
None

Returns:
None


def assemble_transition_model_from_gradable_adjectives(self):

        df = pd.read_sql_table("gradableAdjectiveData", con=engine)
        gb = df.groupby("adjective")

        rs = gaussian_kde(
            flatMap(
                lambda g: gaussian_kde(get_respdevs(g[1]))
                .resample(self.res)[0]
                .tolist(),
                gb,
            )
        ).resample(self.res)[0]

        for edge in self.edges(data=True):
            edge[2]["ConditionalProbability"] = constructConditionalPDF(
                gb, rs, edge
            )
            edge[2]["βs"] = np.tan(
                edge[2]["ConditionalProbability"].resample(self.res)[0]
            )

Add probability distribution functions constructed from gradable
adjective data to the edges of the analysis graph data structure.

Args:
adjective_data
res


def scan_and_connect(self, devnames, timeout=DEF_TIMEOUT, calibration=True):
    responses = self.scan_devices(devnames, timeout)
    for dev in devnames:
        if (dev not in responses):
            logger.error('Failed to find device {} during scan'.format(dev))
            return (False, [])
    return self.connect([responses.get_device(dev) for dev in devnames], calibration)

Scan for and then connect to a set of one or more SK8s.

This method is intended to be a simple way to combine the steps of
running a BLE scan, checking the results and connecting to one or more
devices. When called, a scan is started for a period equal to `timeout`,
and a list of devices is collected. If at any point during the scan all of
the supplied devices are detected, the scan will be ended immediately.

After the scan has completed, the method will only proceed to creating
connections if the scan results contain all the specified devices.

Args:
devnames (list): a list of device names (1 or more)
timeout (float): a time period in seconds to run the scanning process
(will be terminated early if all devices in `devnames` are discovered)

Returns:
Returns the same results as :meth:`connect`.


def params(self, params):
    url = furl(self._request.rawurl)
    url = url.add(params)
    self._request.url = url.url
    self.add_matcher(matcher('QueryMatcher', params))

Defines a set of URL query params to match.

Arguments:
params (dict): set of params to match.

Returns:
self: current Mock instance.


def occupations(self, site_label):
    return sum(((atom.site.label == site_label) for atom in self.atoms))

Number of these atoms occupying a specific site type.

Args:
site_label (Str): Label for the site type being considered.

Returns:
(Int): Number of atoms occupying sites of type `site_label`.


def __init__(self, memspace='private', memtype='mot_float_type'):

        super().__init__(
            memtype,
            self.__class__.__name__ + '_' + memspace + '_' + memtype,
            [],
            resource_filename('mot', 'data/opencl/euclidian_norm.cl'),
            var_replace_dict={'MEMSPACE': memspace, 'MEMTYPE': memtype})

A CL functions for calculating the Euclidian distance between n values.

Args:
memspace (str): The memory space of the memtyped array (private, constant, global).
memtype (str): the memory type to use, double, float, mot_float_type, ...


def goto_step(self, inst: InstanceNode) -> InstanceNode:

        try:
            return inst._entry(
                inst.value.index(self.parse_value(inst.schema_node)))
        except ValueError:
            raise NonexistentInstance(inst.json_pointer(),
                                      f"entry '{self.value!s}'") from None

Return member instance of `inst` addressed by the receiver.

Args:
inst: Current instance.


def cc(project, detect_project=False):
    from benchbuild.utils import cmd
    cc_name = str(CFG['compiler']['c'])
    wrap_cc(cc_name, compiler(cc_name), project, detect_project=detect_project)
    return cmd['./{}'.format(cc_name)]

Return a clang that hides CFLAGS and LDFLAGS.

This will generate a wrapper script in the current directory
and return a complete plumbum command to it.

Args:
cflags: The CFLAGS we want to hide.
ldflags: The LDFLAGS we want to hide.
func (optional): A function that will be pickled alongside the compiler.
It will be called before the actual compilation took place. This
way you can intercept the compilation process with arbitrary python
code.

Returns (benchbuild.utils.cmd):
Path to the new clang command.


def _eig_complex_symmetric(M: np.ndarray) -> Tuple[(np.ndarray, np.ndarray)]:
    if (not np.allclose(M, M.transpose())):
        raise np.linalg.LinAlgError('Not a symmetric matrix')
    max_attempts = 16
    for _ in range(max_attempts):
        c = np.random.uniform(0, 1)
        matrix = ((c * M.real) + ((1 - c) * M.imag))
        (_, eigvecs) = np.linalg.eigh(matrix)
        eigvecs = np.array(eigvecs, dtype=complex)
        eigvals = np.diag(((eigvecs.transpose() @ M) @ eigvecs))
        reconstructed = ((eigvecs @ np.diag(eigvals)) @ eigvecs.transpose())
        if np.allclose(M, reconstructed):
            return (eigvals, eigvecs)
    raise np.linalg.LinAlgError('Cannot diagonalize complex symmetric matrix.')

Diagonalize a complex symmetric  matrix. The eigenvalues are
complex, and the eigenvectors form an orthogonal matrix.

Returns:
eigenvalues, eigenvectors


def construct(cls, name, version=None):
    other = VersionedObject(None)
    other.name_ = name
    other.version_ = (Version() if (version is None) else version)
    return other

Create a VersionedObject directly from an object name and version.

Args:
name: Object name string.
version: Version object.


def GetUpdateTimestamp(self):
    return self._last_update_timestamp

Return last update timestamp of this map.

Returns:
An int containing seconds since epoch, or None.


def properties(lines):
    results = {}
    for (i, line) in enumerate(lines):
        type_ = line[3:6]
        if (type_ not in ['CHG', 'RAD', 'ISO']):
            continue
        count = int(line[6:9])
        results[type_] = []
        for j in range(count):
            idx = int(line[(10 + (j * 8)):(13 + (j * 8))])
            val = int(line[(14 + (j * 8)):(17 + (j * 8))])
            results[type_].append((idx, val))
    return results

Parse properties block

Returns:
dict: {property_type: (atom_index, value)}


def collect_changes(self):
    file_diffs = self._collect_file_diffs()
    (candidate_feature_diffs, valid_init_diffs, inadmissible_diffs) = self._categorize_file_diffs(file_diffs)
    new_feature_info = self._collect_feature_info(candidate_feature_diffs)
    return CollectedChanges(file_diffs, candidate_feature_diffs, valid_init_diffs, inadmissible_diffs, new_feature_info)

Collect file and feature changes

Steps
1. Collects the files that have changed in this pull request as
compared to a comparison branch.
2. Categorize these file changes into admissible or inadmissible file
changes. Admissible file changes solely contribute python files to
the contrib subdirectory.
3. Collect features from admissible new files.

Returns:
CollectedChanges


def _IsTestFilename(filename):

  if (filename.endswith('_test.cc') or
      filename.endswith('_unittest.cc') or
      filename.endswith('_regtest.cc')):
    return True
  else:
    return False

Determines if the given filename has a suffix that identifies it as a test.

Args:
filename: The input filename.

Returns:
True if 'filename' looks like a test, False otherwise.