def get_special_tokens_mask(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None, already_has_special_tokens: bool=False) -> List[int]:
    if already_has_special_tokens:
        return super().get_special_tokens_mask(token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True)
    if token_ids_1 is not None:
        return [1] + [0] * len(token_ids_0) + [1] + [0] * len(token_ids_1)
    return [1] + [0] * len(token_ids_0)

Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `prepare_for_model` method.

Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
already_has_special_tokens (`bool`, *optional*, defaults to `False`):
Whether or not the token list is already formatted with special tokens for the model.

Returns:
`List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.


def hinge(y_true, y_pred):
    y_pred = ops.convert_to_tensor(y_pred)
    y_true = ops.cast(y_true, dtype=y_pred.dtype)
    y_true = ops.convert_to_tensor(y_true)
    y_true = convert_binary_labels_to_hinge(y_true)
    return ops.mean(ops.maximum(1.0 - y_true * y_pred, 0.0), axis=-1)

Computes the hinge loss between `y_true` & `y_pred`.

Formula:

```python
loss = mean(maximum(1 - y_true * y_pred, 0), axis=-1)
```

Args:
y_true: The ground truth values. `y_true` values are expected to be -1
or 1. If binary (0 or 1) labels are provided they will be converted
to -1 or 1 with shape = `[batch_size, d0, .. dN]`.
y_pred: The predicted values with shape = `[batch_size, d0, .. dN]`.

Returns:
Hinge loss values with shape = `[batch_size, d0, .. dN-1]`.

Example:

>>> y_true = np.random.choice([-1, 1], size=(2, 3))
>>> y_pred = np.random.random(size=(2, 3))
>>> loss = keras.losses.hinge(y_true, y_pred)


def decode(self, targets, encoder_outputs, attention_bias):
    with tf.name_scope('decode'):
        decoder_inputs = self.embedding_softmax_layer(targets)
        with tf.name_scope('shift_targets'):
            decoder_inputs = tf.pad(decoder_inputs, [[0, 0], [1, 0], [0, 0]])[(:, :(- 1), :)]
        with tf.name_scope('add_pos_encoding'):
            length = tf.shape(decoder_inputs)[1]
            decoder_inputs += model_utils.get_position_encoding(length, self.params.hidden_size)
        if self.train:
            mlperf_log.transformer_print(key=mlperf_log.MODEL_HP_LAYER_POSTPROCESS_DROPOUT, value=self.params.layer_postprocess_dropout)
            decoder_inputs = tf.nn.dropout(decoder_inputs, (1 - self.params.layer_postprocess_dropout))
        decoder_self_attention_bias = model_utils.get_decoder_self_attention_bias(length)
        outputs = self.decoder_stack(decoder_inputs, encoder_outputs, decoder_self_attention_bias, attention_bias)
        logits = self.embedding_softmax_layer.linear(outputs)
        return logits

Generate logits for each value in the target sequence.

Args:
targets: target values for the output sequence.
int tensor with shape [batch_size, target_length]
encoder_outputs: continuous representation of input sequence.
float tensor with shape [batch_size, input_length, hidden_size]
attention_bias: float tensor with shape [batch_size, 1, 1, input_length]

Returns:
float32 tensor with shape [batch_size, target_length, vocab_size]


def _allocate_subnets(self, conf):
    allocated_subnets = []
    try:
        for net_spec in conf.get('nets', {}).itervalues():
            if (net_spec['type'] != 'nat'):
                continue
            gateway = net_spec.get('gw')
            if gateway:
                allocated_subnet = self._subnet_store.acquire(self.paths.uuid(), gateway)
            else:
                allocated_subnet = self._subnet_store.acquire(self.paths.uuid())
                net_spec['gw'] = str(allocated_subnet.iter_hosts().next())
            allocated_subnets.append(allocated_subnet)
    except:
        self._subnet_store.release(allocated_subnets)
        raise
    return (allocated_subnets, conf)

Allocate all the subnets needed by the given configuration spec

Args:
conf (dict): Configuration spec where to get the nets definitions
from

Returns:
tuple(list, dict): allocated subnets and modified conf


def pair_wise_dice_loss(inputs: Tensor, labels: Tensor) -> Tensor:
    inputs = inputs.sigmoid().flatten(1)
    numerator = 2 * torch.matmul(inputs, labels.T)
    denominator = inputs.sum(-1)[:, None] + labels.sum(-1)[None, :]
    loss = 1 - (numerator + 1) / (denominator + 1)
    return loss

A pair wise version of the dice loss, see `dice_loss` for usage.

Args:
inputs (`torch.Tensor`):
A tensor representing a mask
labels (`torch.Tensor`):
A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
(0 for the negative class and 1 for the positive class).

Returns:
`torch.Tensor`: The computed loss between each pairs.


def unpack_rpc_payload(resp_format, payload):
    code = _create_argcode(resp_format, payload)
    return struct.unpack(code, payload)

Unpack an RPC payload according to resp_format.

Args:
resp_format (str): a struct format code (without the <) for the
parameter format for this RPC.  This format code may include the final
character V, which means that it expects a variable length bytearray.
payload (bytes): The binary payload that should be unpacked.

Returns:
list: A list of the unpacked payload items.


def compile_keywords(keywords):

    mdt = []
    cz_keywords = []
    en_keywords = []
    for keyword in keywords:
        keyword = keyword_to_info(keyword.encode("utf-8"))

        if not keyword:
            continue

        cz_keywords.append({
            "uid": keyword["uid"],
            "zahlavi": keyword["zahlavi"],
            "zdroj": "czenas",
        })

        if keyword.get("mdt"):
            mdt.append({
                "mdt": keyword["mdt"],
                "mrf": keyword["mrf"],
            })

        angl_ekvivalent = keyword.get("angl_ekvivalent")
        if angl_ekvivalent:
            en_keywords.append({
                "zahlavi": angl_ekvivalent,
                "zdroj": keyword.get("zdroj_angl_ekvivalentu") or "eczenas",
            })

    return mdt, cz_keywords, en_keywords

Translate `keywords` to full keyword records as they are used in Aleph.

Returns tuple with three lists, each of which is later used in different
part of the MRC/MARC record.

Args:
keywords (list): List of keyword strings.

Returns:
tuple: (mdt_list, cz_keyword_list, en_keyword_list)


def PushItem(self, item, block=True):
    try:
        self._queue.put(item, block=block)
    except Queue.Full as exception:
        raise errors.QueueFull(exception)

Pushes an item onto the queue.

Args:
item (object): item to add.
block (Optional[bool]): True to block the process when the queue is full.

Raises:
QueueFull: if the item could not be pushed the queue because it's full.


class FlaxBaseModelOutputWithPoolingAndNoAttention(ModelOutput):
    last_hidden_state: Optional[jnp.ndarray] = None
    pooler_output: Optional[jnp.ndarray] = None
    hidden_states: Optional[Tuple[jnp.ndarray]] = None

Base class for model's outputs that also contains a pooling of the last hidden states.

Args:
last_hidden_state (`jnp.ndarray` of shape `(batch_size, num_channels, height, width)`):
Sequence of hidden-states at the output of the last layer of the model.
pooler_output (`jnp.ndarray` of shape `(batch_size, hidden_size)`):
Last layer hidden-state after a pooling operation on the spatial dimensions.
hidden_states (`tuple(jnp.ndarray)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
Tuple of `jnp.ndarray` (one for the output of the embeddings, if the model has an embedding layer, + one
for the output of each layer) of shape `(batch_size, num_channels, height, width)`. Hidden-states of the
model at the output of each layer plus the optional initial embedding outputs.


def download(branch=None, buildMod=False):

    gradlew = "./gradlew"
    if os.name == 'nt':
        gradlew = "gradlew.bat"

    if branch is None:
        branch = malmo_version

    subprocess.check_call(["git", "clone", "-b", branch, "https:

    os.chdir(malmo_install_dir)
    os.chdir("Minecraft")
    try:

        pathlib.Path("src/main/resources/version.properties").write_text("malmomod.version={}\n".format(malmo_version))

        if buildMod:
            subprocess.check_call([gradlew, "setupDecompWorkspace", "build", "testClasses", "-x", "test", "--stacktrace", "-Pversion={}"
                .format(malmo_version)])

        minecraft_dir = os.getcwd()
    finally:
        os.chdir("../..")

    if "MALMO_XSD_PATH" not in os.environ:
        print("Please make sure you set the MALMO_XSD_PATH environment variable to \"{}/Schemas\"!"
                 .format(str(pathlib.Path(malmo_install_dir).absolute())))
    return minecraft_dir

Download Malmo from github and optionaly build the Minecraft Mod.
Args:
branch: optional branch to clone. Default is release version.
buildMod: don't build the Mod unless build arg is given as True.
Returns:
The path for the Malmo Minecraft mod.


def search_globs(path, patterns):

    for pattern in (p for p in patterns if p):
        if pattern.startswith('/'):

            regex = fnmatch.translate(pattern[1:])
            regex = regex.replace('\\Z', '')

            temp_path = path[1:] if path.startswith('/') else path
            m = re.search(regex, temp_path)

            if m and m.start() == 0:
                return True

        else:
            regex = fnmatch.translate(pattern)
            regex = regex.replace('\\Z', '')

            if re.search(regex, path):
                return True

    return False

Test whether the given *path* contains any patterns in *patterns*

Args:
path (str):
A file path to test for matches.
patterns (list[str]):
A list of glob string patterns to test against. If *path* matches
any of those patters, it will return True.

Returns:
bool: **True** if the ``path`` matches any pattern in *patterns*.


def save(self, vleaf, fpath, cleanup=False, format=None):
    graph = self.create_graphviz_digraph(vleaf, format=format)
    graph.render(fpath, cleanup=cleanup)

Save the graph to a given file path.

Args:
vleaf (`nnabla.Variable`): End variable. All variables and functions which can be traversed from this variable are shown in the reuslt.
fpath (`str`): The file path used to save.
cleanup (`bool`): Clean up the source file after rendering. Default is False.
format (str):
Force overwrite ``format`` (``'pdf', 'png', ...)``) configuration.


def set_consistent(self, consistent_config):

        self.topology._add_job_control_plane()
        self.oport.operator.consistent(consistent_config)
        return self._make_placeable()

Indicates that the stream is the start of a consistent region.

Args:
consistent_config(consistent.ConsistentRegionConfig): the configuration of the consistent region.

Returns:
Stream: Returns this stream.

.. versionadded:: 1.11


def __init__(self, channel):

        self.ListVoices = channel.unary_unary(
            "/google.cloud.texttospeech.v1.TextToSpeech/ListVoices",
            request_serializer=google_dot_cloud_dot_texttospeech__v1_dot_proto_dot_cloud__tts__pb2.ListVoicesRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_texttospeech__v1_dot_proto_dot_cloud__tts__pb2.ListVoicesResponse.FromString,
        )
        self.SynthesizeSpeech = channel.unary_unary(
            "/google.cloud.texttospeech.v1.TextToSpeech/SynthesizeSpeech",
            request_serializer=google_dot_cloud_dot_texttospeech__v1_dot_proto_dot_cloud__tts__pb2.SynthesizeSpeechRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_texttospeech__v1_dot_proto_dot_cloud__tts__pb2.SynthesizeSpeechResponse.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def _get_course_content_from_ecommerce(course_id, site_code=None):

    api = get_ecommerce_client(site_code=site_code)
    try:
        api_response = api.courses(course_id).get()
    except Exception:
        logger.exception(
            'An error occurred while retrieving data for course run [%s] from the Catalog API.',
            course_id,
            exc_info=True
        )
        return {}

    return {
        'title': api_response.get('name'),
        'verification_deadline': api_response.get('verification_deadline')
    }

Get course information using the Ecommerce course api.

In case of error returns empty response.
Arguments:
course_id (str): course key of the course
site_code (str): site code

Returns:
course information from Ecommerce


def _inspect_summary_cache(self, cache, replica_id, step_num, output_stream, tensor_trace_order):

    def _inspect_tensor(tensor):

        if self._parameters.trace_mode == tensor_tracer_flags.TRACE_MODE_NAN_INF:
            return cond.cond(math_ops.greater(tensor, 0.0), lambda: 'has NaNs/Infs!', lambda: 'has no NaNs or Infs.')
        else:
            return tensor
    if not tensor_trace_order.traced_tensors:
        logging.warn('Inspect mode has no tensors in the cache to check.')
        return control_flow_ops.no_op
    if self._parameters.trace_mode == tensor_tracer_flags.TRACE_MODE_NAN_INF:
        step_has_nan_or_inf = math_ops.greater(math_ops.reduce_sum(cache), 0.0)
    else:
        step_has_nan_or_inf = math_ops.reduce_any(gen_math_ops.logical_or(gen_math_ops.is_nan(cache), gen_math_ops.is_inf(cache)))
    step_error_message = cond.cond(step_has_nan_or_inf, lambda: 'NaNs or Infs in the step!', lambda: 'No numerical issues have been found for the step.')
    if self._parameters.collect_summary_per_core:
        stats = ['\n\n', 'core:', replica_id, ',', 'step:', step_num, '-->', step_error_message, 'Printing tensors for mode:%s...' % self._parameters.trace_mode]
    else:
        stats = ['\n\n', 'step:', step_num, '-->', step_error_message, 'Printing tensors for mode:%s...' % self._parameters.trace_mode]
    for tensor_name, cache_idx in sorted(tensor_trace_order.tensorname_to_cache_idx.items(), key=lambda item: item[1]):
        if self._parameters.collect_summary_per_core:
            stats.extend(['\n', 'core:', replica_id, ',', 'step:', step_num, ',', tensor_name, '-->', _inspect_tensor(cache[cache_idx, 0])])
        else:
            stats.extend(['\n', 'step:', step_num, ',', tensor_name, '-->', _inspect_tensor(cache[cache_idx, 0])])
    return logging_ops.print_v2(*stats, summarize=-1, output_stream=output_stream)

Generates a print operation to print trace inspection.

Args:
cache: Tensor storing the trace results for the step.
replica_id: Tensor storing the replica id of the running core.
step_num: Step number.
output_stream: Where to print the outputs, e.g., file path, or sys.stderr.
tensor_trace_order: TensorTraceOrder object holding tensorname to id map.

Returns:
The Op to flush the cache to file.


def create_sketch(self, name, description):
    resource_url = '{0:s}/sketches/'.format(self.api_base_url)
    form_data = {'name': name, 'description': description}
    response = self.session.post(resource_url, json=form_data)
    response_dict = response.json()
    sketch_id = response_dict['objects'][0]['id']
    return sketch_id

Create a new sketch with the specified name and description.

Args:
name (str): Title of sketch
description (str): Description of sketch

Returns:
int: ID of created sketch


def from_mass_fractions(cls, mass_fractions, formula=None):

        mass_fractions = process_wildcard(mass_fractions)
        atomic_fractions = convert_mass_to_atomic_fractions(mass_fractions)
        if not formula:
            formula = generate_name(atomic_fractions)
        return cls(cls._key, mass_fractions, atomic_fractions, formula)

Creates a composition from a mass fraction :class:`dict`.

Args:
mass_fractions (dict): mass fraction :class:`dict`.
The keys are atomic numbers and the values weight fractions.
Wildcard are accepted, e.g. ``{5: '?', 25: 0.4}`` where boron
will get a mass fraction of 0.6.
formula (str): optional chemical formula for the composition.
If ``None``, a formula will be generated for the composition.


def ensure_proc_terminate(proc):
    if isinstance(proc, list):
        for p in proc:
            ensure_proc_terminate(p)
        return

    def stop_proc_by_weak_ref(ref):
        proc = ref()
        if (proc is None):
            return
        if (not proc.is_alive()):
            return
        proc.terminate()
        proc.join()
    assert isinstance(proc, mp.Process)
    atexit.register(stop_proc_by_weak_ref, weakref.ref(proc))

Make sure processes terminate when main process exit.

Args:
proc (multiprocessing.Process or list)


def exclude_from_weight_decay(self, var_list=None, var_names=None):
    if hasattr(self, '_built') and self._built:
        raise ValueError('`exclude_from_weight_decay()` can only be configured before the optimizer is built.')
    if var_list:
        self._exclude_from_weight_decay = set((self._var_key(variable) for variable in var_list))
    else:
        self._exclude_from_weight_decay = set()
    if var_names and len(var_names) > 0:
        self._exclude_from_weight_decay_pattern = re.compile('|'.join(set(var_names)))
    else:
        self._exclude_from_weight_decay_pattern = None
    self._exclude_from_weight_decay_cache = dict()

Exclude variables from weight decay.

This method must be called before the optimizer's `build` method is
called. You can set specific variables to exclude out, or set a list of
strings as the anchor words, if any of which appear in a variable's
name, then the variable is excluded.

Args:
var_list: A list of `Variable`s to exclude from weight decay.
var_names: A list of strings. If any string in `var_names` appear
in the model variable's name, then this model variable is
excluded from weight decay. For example, `var_names=['bias']`
excludes all bias variables from weight decay.


def send_message_event(self, room_id, event_type, content, txn_id=None,
                           timestamp=None):

        if not txn_id:
            txn_id = self._make_txn_id()

        path = "/rooms/%s/send/%s/%s" % (
            quote(room_id), quote(event_type), quote(str(txn_id)),
        )
        params = {}
        if timestamp:
            params["ts"] = timestamp
        return self._send("PUT", path, content, query_params=params)

Perform PUT /rooms/$room_id/send/$event_type

Args:
room_id (str): The room ID to send the message event in.
event_type (str): The event type to send.
content (dict): The JSON content to send.
txn_id (int): Optional. The transaction ID to use.
timestamp (int): Set origin_server_ts (For application services only)


def __init__(self, learning_rate, use_locking=False, name='GradientDescent'):
    super(GradientDescentOptimizer, self).__init__(use_locking, name)
    self._learning_rate = learning_rate
    self._learning_rate_tensor = None

Construct a new gradient descent optimizer.

Args:
learning_rate: A Tensor or a floating point value.  The learning
rate to use.
use_locking: If True use locks for update operations.
name: Optional name prefix for the operations created when applying
gradients. Defaults to "GradientDescent".

@compatibility(eager)
When eager execution is enabled, `learning_rate` can be a callable that
takes no arguments and returns the actual value to use. This can be useful
for changing these values across different invocations of optimizer
functions.
@end_compatibility


def __iadd__(self, values):

		self._check_type(values, '+=')
		self.extend(values)
		return self

Add all values to the end of self.

Args:
values (Iterable): Values to append
Raises:
ValueError: If any values are already present


def __init__(self, resolver_context, file_object=None):

    super(FileObjectIO, self).__init__(resolver_context)
    self._file_object = file_object
    self._file_object_set_in_init = bool(file_object)
    self._size = None

Initializes a file-like object.

Args:
resolver_context (Context): resolver context.
file_object (Optional[FileIO]): file-like object.


def _DictAsString(result, verbose=False):
    class_attrs = inspectutils.GetClassAttrsDict(result)
    result_visible = {key: value for key, value in result.items() if completion.MemberVisible(result, key, value, class_attrs=class_attrs, verbose=verbose)}
    if not result_visible:
        return '{}'
    longest_key = max((len(str(key)) for key in result_visible.keys()))
    format_string = f'{{key:{longest_key + 1}s}} {{value}}'
    lines = []
    for key, value in result.items():
        if completion.MemberVisible(result, key, value, class_attrs=class_attrs, verbose=verbose):
            line = format_string.format(key=f'{key}:', value=_OneLineResult(value))
            lines.append(line)
    return '\n'.join(lines)

Returns a dict as a string.

Args:
result: The dict to convert to a string
verbose: Whether to include 'hidden' members, those keys starting with _.
Returns:
A string representing the dict


def latest(self, **kwargs):

        path = self._get_id_path('latest')

        response = self._GET(path, kwargs)
        self._set_attrs_to_values(response)
        return response

Get the most newly created TV show. This is a live response
and will continuously change.

Args:
language: (optional) ISO 639 code.

Returns:
A dict respresentation of the JSON returned from the API.


def delete_device(self, auth_body, device_id):
    content = {'auth': auth_body}
    return self._send('DELETE', ('/devices/%s' % device_id), content=content)

Deletes the given device, and invalidates any access token associated with it.

NOTE: This endpoint uses the User-Interactive Authentication API.

Args:
auth_body (dict): Authentication params.
device_id (str): The device ID of the device to delete.


def SelectFieldPrompt(field_name, context_str, *options):
    option_format_str = '[ {} ] "{}"'
    option_dict = {}
    print(context_str)
    print('Please select one of the following options for field "{}"'.format(field_name))
    for (cnt, option) in enumerate(options):
        option_dict['{}'.format((cnt + 1))] = option
        if (not callable(option)):
            print(option_format_str.format((cnt + 1), u(str(option))))
        else:
            print(option_format_str.format((cnt + 1), option.__name__))
    choice = None
    while (choice not in option_dict):
        choice = input('option> ').strip()
    new_value = option_dict[choice]
    if callable(new_value):
        return new_value()
    else:
        return new_value

Prompts user to pick from provided options.

It is possible to provide a function as an option although it is
not yet tested.  This could allow a user to be prompted to provide
their own value rather than the listed options.

Args:
field_name (string): Name of the field.
context_str (string): Printed to give the user context.
options: Variable arguments, should be vobject Components
in a list. As retrieved from a vCard.contents dictionary.

Returns:
One of the options passed in.  Ideally always a list.


def construct(cls, name, range=None):

        other = Requirement(None)
        other.name_ = name
        other.range_ = VersionRange() if range is None else range
        return other

Create a requirement directly from an object name and VersionRange.

Args:
name: Object name string.
range: VersionRange object. If None, an unversioned requirement is
created.


def destringize(self, string):

        m = segment_destr_pattern.match(string)
        self.genome_id = int(m.group(1))
        self.chr_id = int(m.group(2))
        self.direction = m.group(3)
        self.left = int(m.group(4))
        self.right = int(m.group(5))

Get RNF values for this segment from its textual representation and
save them into this object.

Args:
string (str): Textual representation of a segment.


def delete(self, invoice_id, **kwargs):

        url = "{}/{}".format(self.base_url, invoice_id)
        return self.delete_url(url, {}, **kwargs)

Delete an invoice
You can delete an invoice which is in the draft state.

Args:
invoice_id : Id for delete the invoice
Returns:
The response is always be an empty array like this - []


def row_limits(self):
    return self._row_splits[1:]

Returns the limit indices for rows in this row partition.

These indices specify where the values for each row end.
`partition.row_limits()` is equal to `partition.row_splits()[:-1]`.

Returns:
A 1-D integer Tensor with shape `[self.nrows]`.
The returned tensor is nonnegative, and is sorted in ascending order.
`self.row_limits()[-1] == self.nvals()`.


def get_create_agent(agent_kwargs):

  def create_agent(sess, environment, summary_writer=None):

    return BatchDQNAgent(
        env_batch_size=environment.batch_size,
        sess=sess,
        num_actions=environment.action_space.n,
        summary_writer=summary_writer,
        tf_device="/gpu:*",
        **agent_kwargs)

  return create_agent

Factory for dopamine agent initialization.

Args:
agent_kwargs: dict of BatchDQNAgent parameters

Returns:
Function(sess, environment, summary_writer) -> BatchDQNAgent instance.


def isset(alias_name):

    warnings.warn('Will be removed in v1.0', DeprecationWarning, stacklevel=2)
    raw_value = read(alias_name, allow_none=True)
    if raw_value:
        if re.compile(r'.+:
            return True
        else:
            warnings.warn('"{0}_PORT={1}" does not look like a docker link.'.format(alias_name, raw_value), stacklevel=2)
            return False

    return False

Return a boolean if the docker link is set or not and is a valid looking docker link value.

Args:
alias_name: The link alias name


def get_namespace(self, name_seq):
    namespaces = self.namespaces
    result = []
    for name in name_seq:
        namespaces = namespaces.get(name)
        if (not namespaces):
            break
        result.append(name)
    return result

Returns the prefix of names from name_seq that are known namespaces.

Args:
name_seq: ['names', 'of', 'possible', 'namespace', 'to', 'find']

Returns:
['names', 'that', 'are', 'namespaces', 'possibly', 'empty', 'list']


def import_module(name):

    parts = name.split('.')
    path = None
    module_name = ''
    fhandle = None

    for index, part in enumerate(parts):
        module_name = part if index == 0 else '%s.%s' % (module_name, part)
        path = [path] if path is not None else path

        try:
            fhandle, path, descr = imp.find_module(part, path)
            if module_name in sys.modules:

                mod = sys.modules[module_name]
            else:
                mod = imp.load_module(module_name, fhandle, path, descr)
        finally:

            if fhandle:
                fhandle.close()

    return mod

Imports a module into the current runtime environment

This function emulates the Python import system that allows for
importing full path modules.  It will break down the module and
import each part (or skip if it is already loaded in cache).

Args:
name (str): The name of the module to import.  This should be
the full path of the module

Returns:
The module that was imported


def get_lacp_mode(self, name):
    members = self.get_members(name)
    if (not members):
        return DEFAULT_LACP_MODE
    for member in self.get_members(name):
        match = re.search('channel-group\\s\\d+\\smode\\s(?P<value>.+)', self.get_block(('^interface %s' % member)))
        return match.group('value')

Returns the LACP mode for the specified Port-Channel interface

Args:
name(str): The Port-Channel interface name to return the LACP
mode for from the configuration

Returns:
The configured LACP mode for the interface.  Valid mode values
are 'on', 'passive', 'active'


def zenith_luminance(self, value=9999.0):
    if (value is not None):
        try:
            value = float(value)
        except ValueError:
            raise ValueError('value {} need to be of type float for field `zenith_luminance`'.format(value))
        if (value < 0.0):
            raise ValueError('value need to be greater or equal 0.0 for field `zenith_luminance`')
    self._zenith_luminance = value

Corresponds to IDD Field `zenith_luminance`
will be missing if >= 9999

Args:
value (float): value for IDD Field `zenith_luminance`
Unit: Cd/m2
value >= 0.0
Missing value: 9999.0
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

Raises:
ValueError: if `value` is not a valid value


def reset_folder(self, folder):

        warnings.warn('This is a destructive action that cannot be undone.')
        self.post('reset', data={}, params={'folder': folder})

Erase the database index from a given folder and restart Syncthing.

Args:
folder (str): Folder ID.

Returns:
None


def get(self, attr: FetchAttribute) -> MaybeBytes:

        attr_name = attr.value.decode('ascii')
        method = getattr(self, '_get_' + attr_name.replace('.', '_'))
        return method(attr)

Return the bytes representation of the given message attribue.

Args:
attr: The fetch attribute.

Raises:
:class:`NotFetchable`


def UpdateNumberOfEventSources(
      self, number_of_consumed_sources, number_of_produced_sources):

    consumed_sources_delta = 0
    if number_of_consumed_sources is not None:
      if number_of_consumed_sources < self.number_of_consumed_sources:
        raise ValueError(
            'Number of consumed sources smaller than previous update.')

      consumed_sources_delta = (
          number_of_consumed_sources - self.number_of_consumed_sources)

      self.number_of_consumed_sources = number_of_consumed_sources
      self.number_of_consumed_sources_delta = consumed_sources_delta

    produced_sources_delta = 0
    if number_of_produced_sources is not None:
      if number_of_produced_sources < self.number_of_produced_sources:
        raise ValueError(
            'Number of produced sources smaller than previous update.')

      produced_sources_delta = (
          number_of_produced_sources - self.number_of_produced_sources)

      self.number_of_produced_sources = number_of_produced_sources
      self.number_of_produced_sources_delta = produced_sources_delta

    return consumed_sources_delta > 0 or produced_sources_delta > 0

Updates the number of event sources.

Args:
number_of_consumed_sources (int): total number of event sources consumed
by the process.
number_of_produced_sources (int): total number of event sources produced
by the process.

Returns:
bool: True if either number of event sources has increased.

Raises:
ValueError: if the consumed or produced number of event sources is
smaller than the value of the previous update.


def index_one(self, instance, force=False):

        if not self.is_indexed(instance) and not force:
            doc = self._as_document(instance)
            self._index_document(doc, force=force)
            logger.debug('{} indexed as\n {}'.format(instance.__class__, pformat(doc)))
            return True

        logger.debug('{} already indexed.'.format(instance.__class__))
        return False

Indexes exactly one object of the Ambry system.

Args:
instance (any): instance to index.
force (boolean): if True replace document in the index.

Returns:
boolean: True if document added to index, False if document already exists in the index.


def detect_suicidal_func(func):
    if func.is_constructor:
        return False
    if (func.visibility != 'public'):
        return False
    calls = [c.name for c in func.internal_calls]
    if (not (('suicide(address)' in calls) or ('selfdestruct(address)' in calls))):
        return False
    if func.is_protected():
        return False
    return True

Detect if the function is suicidal

Detect the public functions calling suicide/selfdestruct without protection
Returns:
(bool): True if the function is suicidal


Returns the object holds the test environment information.

Tests should modify this in the main process if needed, and it will be passed
to the worker processes each time a test case is run.

Returns:
a TestEnvironment object.


def get_ax_fig_plt(ax=None, **kwargs):

    import matplotlib.pyplot as plt
    if ax is None:
        fig = plt.figure(**kwargs)
        ax = fig.add_subplot(1, 1, 1)
    else:
        fig = plt.gcf()

    return ax, fig, plt

Helper function used in plot functions supporting an optional Axes argument.
If ax is None, we build the `matplotlib` figure and create the Axes else
we return the current active figure.

Args:
kwargs: keyword arguments are passed to plt.figure if ax is not None.

Returns:
ax: :class:`Axes` object
figure: matplotlib figure
plt: matplotlib pyplot module.


def _get_covariance(self, X):
    result = pd.DataFrame(index=range(len(X)))
    column_names = self.get_column_names(X)
    for column_name in column_names:
        column = self.get_column(X, column_name)
        distrib = self.distribs[column_name]
        cdf = distrib.cumulative_distribution(column)
        if (distrib.constant_value is not None):
            cdf = (np.ones(column.shape) - EPSILON)
        result = self.set_column(result, column_name, stats.norm.ppf(cdf))
    result = result[(result != np.inf).all(axis=1)]
    return pd.DataFrame(data=result).cov().values

Compute covariance matrix with transformed data.

Args:
X: `numpy.ndarray` or `pandas.DataFrame`.

Returns:
np.ndarray


def set_reprompt_text(self, text):
    self.response.reprompt.outputSpeech.type = 'PlainText'
    self.response.reprompt.outputSpeech.text = text

Set response reprompt output speech as plain text type.

Args:
text: str. Response speech used when type is 'PlainText'. Cannot
exceed 8,000 characters.


def _ensure_package_loaded(path, component):
    logger = logging.getLogger(__name__)
    packages = component.find_products('support_package')
    if (len(packages) == 0):
        return None
    elif (len(packages) > 1):
        raise ExternalError("Component had multiple products declared as 'support_package", products=packages)
    if ((len(path) > 2) and (':' in path[2:])):
        (path, _, _) = path.rpartition(':')
    package_base = packages[0]
    relative_path = os.path.normpath(os.path.relpath(path, start=package_base))
    if relative_path.startswith('..'):
        raise ExternalError('Component had python product output of support_package', package=package_base, product=path, relative_path=relative_path)
    if (not relative_path.endswith('.py')):
        raise ExternalError('Python product did not end with .py', path=path)
    relative_path = relative_path[:(- 3)]
    if (os.pathsep in relative_path):
        raise ExternalError('Python support wheels with multiple subpackages not yet supported', relative_path=relative_path)
    support_distro = component.support_distribution
    if (support_distro not in sys.modules):
        logger.debug('Creating dynamic support wheel package: %s', support_distro)
        (file, path, desc) = imp.find_module(os.path.basename(package_base), [os.path.dirname(package_base)])
        imp.load_module(support_distro, file, path, desc)
    return '{}.{}'.format(support_distro, relative_path)

Ensure that the given module is loaded as a submodule.

Returns:
str: The name that the module should be imported as.


def delete_request(profile, resource):
    url = get_url(profile, resource)
    headers = get_headers(profile)
    return requests.delete(url, headers=headers)

Do a DELETE request to Github's API.

Args:

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

resource
The part of a Github API URL that comes after ``.../:repo/git``.
For instance, for ``.../:repo/git/commits``, it's ``/commits``.

Returns:
The response returned by the ``requests`` library when it does the
POST request.


def get_candidates(self, input_ids: torch.LongTensor) -> Tuple[torch.LongTensor, Optional[torch.FloatTensor]]:
    max_new_tokens = int(self.num_assistant_tokens)
    if max_new_tokens == 0:
        return (input_ids, None)
    input_ids = input_ids.to(self.assistant_model.device)
    remove_from_pkv = 0
    assistant_input_ids, remove_from_pkv = self._prepare_assistant_input_ids(input_ids)
    self.prev_assistant_ids = assistant_input_ids
    min_new_tokens = max(min(max_new_tokens, self.main_model_min_length - assistant_input_ids.shape[-1]), 0)
    self._update_past_and_masks(assistant_input_ids, remove_from_pkv)
    generation_args = self._prepare_generation_args(assistant_input_ids, min_new_tokens, max_new_tokens)
    self.assistant_kwargs.pop('attention_mask', None)
    assistant_output = self.assistant_model.generate(**generation_args, **self.assistant_kwargs)
    new_target_ids = self._process_assistant_outputs(input_ids, assistant_output.sequences, assistant_input_ids)
    self.prev_target_ids_len = input_ids.shape[1]
    self.assistant_kwargs['past_key_values'] = assistant_output.past_key_values
    self.prev_assistant_ids = assistant_output.sequences
    if self.prev_target_ids_len >= new_target_ids.shape[1]:
        return (input_ids, None)
    return (new_target_ids, None)

Fetches the candidates to be tried for the current input.

Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. [What are input IDs?](../glossary#input-ids)

Return:
`torch.LongTensor` of shape `(batch_size, candidate_length)` containing the candidate sequences to be
assessed by the model and a `torch.FloatTensor` of shape `(batch_size, candidate_length,
vocabulary_size)` containing the logits associated to each candidate.


def diff_commonPrefix(self, text1, text2):
    if ((not text1) or (not text2) or (text1[0] != text2[0])):
        return 0
    pointermin = 0
    pointermax = min(len(text1), len(text2))
    pointermid = pointermax
    pointerstart = 0
    while (pointermin < pointermid):
        if (text1[pointerstart:pointermid] == text2[pointerstart:pointermid]):
            pointermin = pointermid
            pointerstart = pointermin
        else:
            pointermax = pointermid
        pointermid = (((pointermax - pointermin)
    return pointermid

Determine the common prefix of two strings.

Args:
text1: First string.
text2: Second string.

Returns:
The number of characters common to the start of each string.


def supervised_to_dict(dataset, text2self):

  def my_fn(inputs, targets):
    if text2self:
      return {"targets": targets}
    else:
      return {"inputs": inputs, "targets": targets}
  return dataset.map(my_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE)

Turns a supervised dataset into a dataset with a feature dictionary.

if text2self, then the features dictionary contains a "targets" key.
else, the features dictionary contains "inputs" and "targets" keys.

Args:
dataset: a tf.data.Dataset
text2self: a boolean
Returns:
a tf.data.Dataset


def _build(self, inputs, **normalization_build_kwargs):
    if ((self._normalization_ctor in {batch_norm.BatchNorm, batch_norm_v2.BatchNormV2}) and ('is_training' not in normalization_build_kwargs)):
        raise ValueError('Boolean is_training flag must be explicitly specified when using batch normalization.')
    self._input_shape = tuple(inputs.get_shape().as_list())
    net = inputs
    final_index = (len(self._layers) - 1)
    for (i, layer) in enumerate(self._layers):
        net = layer(net)
        if ((i != final_index) or self._normalize_final):
            if (self._normalization_ctor is not None):
                normalizer = self._normalization_ctor(name='batch_norm_{}'.format(i), **self._normalization_kwargs)
                net = normalizer(net, **util.remove_unsupported_kwargs(normalizer, normalization_build_kwargs))
            elif normalization_build_kwargs:
                tf.logging.warning('No normalization configured, but extra kwargs provided: {}'.format(normalization_build_kwargs))
        if ((i != final_index) or self._activate_final):
            net = self._activation(net)
    return net

Assembles the `ConvNet2D` and connects it to the graph.

Args:
inputs: A 4D Tensor of shape `[batch_size, input_height, input_width,
input_channels]`.
**normalization_build_kwargs: kwargs passed to the normalization module
at _build time.

Returns:
A 4D Tensor of shape `[batch_size, output_height, output_width,
output_channels[-1]]`.

Raises:
ValueError: If `is_training` is not explicitly specified when using
batch normalization.


def create_rag_adapter() -> EmbeddingTypeAdapter[Chunk, Chunk]:
    return EmbeddingTypeAdapter(input_fn=_extract_chunk_text, output_fn=_add_embedding_fn)

Creates adapter for converting between Chunk and Embedding types.

The adapter:
- Extracts text from Chunk.content.text for embedding
- Creates Embedding objects from model output
- Sets Embedding in Chunk.embedding

Returns:
EmbeddingTypeAdapter configured for RAG pipeline types


def random_expr_with_required_var(depth, required_var, optional_list, ops):
    if (not depth):
        if required_var:
            return required_var
        return str(optional_list[random.randrange(len(optional_list))])
    max_depth_side = random.randrange(2)
    other_side_depth = random.randrange(depth)
    required_var_side = random.randrange(2)
    left = random_expr_with_required_var(((depth - 1) if max_depth_side else other_side_depth), (required_var if required_var_side else None), optional_list, ops)
    right = random_expr_with_required_var(((depth - 1) if (not max_depth_side) else other_side_depth), (required_var if (not required_var_side) else None), optional_list, ops)
    op = ops[random.randrange(len(ops))]
    return ExprNode(left, right, op)

Generate a random expression tree with a required variable.

The required variable appears exactly once in the expression.

Args:
depth: At least one leaf will be this many levels down from the top.
required_var: A char. This char is guaranteed to be placed exactly once at
a leaf somewhere in the tree. This is the var to solve for.
optional_list: A list of chars. These chars are randomly selected as leaf
values. These are constant vars.
ops: A list of ExprOp instances.

Returns:
An ExprNode instance which is the root of the generated expression tree.


def execute_code_block(elem, doc):

    command = select_executor(elem, doc).split(' ')
    code = elem.text
    if 'plt' in elem.attributes or 'plt' in elem.classes:
        code = save_plot(code, elem)
    command.append(code)
    if 'args' in elem.attributes:
        for arg in elem.attributes['args'].split():
            command.append(arg)

    cwd = elem.attributes['wd'] if 'wd' in elem.attributes else None

    return subprocess.run(command,
                          encoding='utf8',
                          stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT,
                          cwd=cwd).stdout

Executes a code block by passing it to the executor.

Args:
elem The AST element.
doc  The document.

Returns:
The output of the command.


def transmit(self, payload, **kwargs):
    kwargs['app_label'] = 'sap_success_factors'
    kwargs['model_name'] = 'SapSuccessFactorsLearnerDataTransmissionAudit'
    kwargs['remote_user_id'] = 'sapsf_user_id'
    super(SapSuccessFactorsLearnerTransmitter, self).transmit(payload, **kwargs)

Send a completion status call to SAP SuccessFactors using the client.

Args:
payload: The learner completion data payload to send to SAP SuccessFactors


def decode_payload(cls, request):

    if request.headers.get(cls.PAYLOAD_VERSION_HEADER) != cls.PAYLOAD_VERSION:
      raise DeprecationWarning(
          "Task is generated by an older incompatible version of mapreduce. "
          "Please kill this job manually")
    return cls._decode_payload(request.body)

Decode task payload.

HugeTask controls its own payload entirely including urlencoding.
It doesn't depend on any particular web framework.

Args:
request: a webapp Request instance.

Returns:
A dict of str to str. The same as the params argument to __init__.

Raises:
DeprecationWarning: When task payload constructed from an older
incompatible version of mapreduce.


def warning(msg: str, *args, **kwargs) -> None:
    _DEFAULT_LOGGER.warning(msg, *args, **kwargs)

Logs warning message.

Args:
msg: Message with possible format string.
*args: Values for variables in the format string.
**kwargs: Keyword arguments for the logger.


def locked_put(self, credentials):
    entity = self._model.get_or_insert(self._key_name)
    setattr(entity, self._property_name, credentials)
    entity.put()
    if self._cache:
        self._cache.set(self._key_name, credentials.to_json())

Write a Credentials to the datastore.

Args:
credentials: Credentials, the credentials to store.


def GetArtifactDependencies(rdf_artifact, recursive=False, depth=1):
    deps = set()
    for source in rdf_artifact.sources:
        if (source.type in (rdf_artifacts.ArtifactSource.SourceType.ARTIFACT, rdf_artifacts.ArtifactSource.SourceType.ARTIFACT_GROUP)):
            if source.attributes.GetItem('names'):
                deps.update(source.attributes.GetItem('names'))
    if (depth > 10):
        raise RuntimeError('Max artifact recursion depth reached.')
    deps_set = set(deps)
    if recursive:
        for dep in deps:
            artifact_obj = REGISTRY.GetArtifact(dep)
            new_dep = GetArtifactDependencies(artifact_obj, True, depth=(depth + 1))
            if new_dep:
                deps_set.update(new_dep)
    return deps_set

Return a set of artifact dependencies.

Args:
rdf_artifact: RDF object artifact.
recursive: If True recurse into dependencies to find their dependencies.
depth: Used for limiting recursion depth.

Returns:
A set of strings containing the dependent artifact names.

Raises:
RuntimeError: If maximum recursion depth reached.


def __init__(self, predicate, if_true, if_false):

        super(TernaryConditional, self).__init__(predicate, if_true, if_false)
        self.predicate = predicate
        self.if_true = if_true
        self.if_false = if_false
        self.validate()

Construct an expression that evaluates a predicate and returns one of two results.

Args:
predicate: Expression to evaluate, and based on which to choose the returned value
if_true: Expression to return if the predicate was true
if_false: Expression to return if the predicate was false

Returns:
new TernaryConditional object


class FlaxDataCollatorForLanguageModeling:
    tokenizer: PreTrainedTokenizerBase
    mlm_probability: float = 0.15

    def __post_init__(self):
        if self.tokenizer.mask_token is None:
            raise ValueError('This tokenizer does not have a mask token which is necessary for masked language modeling. You should pass `mlm=False` to train on causal language modeling instead.')

    def __call__(self, examples: list[dict[str, np.ndarray]], pad_to_multiple_of: int) -> dict[str, np.ndarray]:
        batch = self.tokenizer.pad(examples, pad_to_multiple_of=pad_to_multiple_of, return_tensors=TensorType.NUMPY)
        special_tokens_mask = batch.pop('special_tokens_mask', None)
        batch['input_ids'], batch['labels'] = self.mask_tokens(batch['input_ids'], special_tokens_mask=special_tokens_mask)
        return batch

    def mask_tokens(self, inputs: np.ndarray, special_tokens_mask: Optional[np.ndarray]) -> tuple[np.ndarray, np.ndarray]:

        labels = inputs.copy()
        probability_matrix = np.full(labels.shape, self.mlm_probability)
        special_tokens_mask = special_tokens_mask.astype('bool')
        probability_matrix[special_tokens_mask] = 0.0
        masked_indices = np.random.binomial(1, probability_matrix).astype('bool')
        labels[~masked_indices] = -100
        indices_replaced = np.random.binomial(1, np.full(labels.shape, 0.8)).astype('bool') & masked_indices
        inputs[indices_replaced] = self.tokenizer.convert_tokens_to_ids(self.tokenizer.mask_token)
        indices_random = np.random.binomial(1, np.full(labels.shape, 0.5)).astype('bool')
        indices_random &= masked_indices & ~indices_replaced
        random_words = np.random.randint(self.tokenizer.vocab_size, size=labels.shape, dtype='i4')
        inputs[indices_random] = random_words[indices_random]
        return (inputs, labels)

Data collator used for language modeling. Inputs are dynamically padded to the maximum length of a batch if they
are not all of the same length.

Args:
tokenizer (:class:`~transformers.PreTrainedTokenizer` or :class:`~transformers.PreTrainedTokenizerFast`):
The tokenizer used for encoding the data.
mlm_probability (:obj:`float`, `optional`, defaults to 0.15):
The probability with which to (randomly) mask tokens in the input.

.. note::

For best performance, this data collator should be used with a dataset having items that are dictionaries or
BatchEncoding, with the :obj:`"special_tokens_mask"` key, as returned by a
:class:`~transformers.PreTrainedTokenizer` or a :class:`~transformers.PreTrainedTokenizerFast` with the
argument :obj:`return_special_tokens_mask=True`.


def is_mobile(user_agent):

    if user_agent:
        b = reg_b.search(user_agent)
        v = reg_v.search(user_agent[0:4])
        return b or v
    return False

Checks if the user browser from the given user agent is mobile.

Args:
user_agent: A given user agent.

Returns: True if the browser from the user agent is mobile.


def relocate(source, destination, move=False):

    venv = api.VirtualEnvironment(source)
    if not move:

        venv.relocate(destination)
        return None

    venv.move(destination)
    return None

Adjust the virtual environment settings and optional move it.

Args:
source (str): Path to the existing virtual environment.
destination (str): Desired path of the virtual environment.
move (bool): Whether or not to actually move the files. Default False.


def run(self, fetch_list, feed_dict=None, sess=None):
    if (tf.get_default_graph() != self._graph):
        raise ValueError('The current default graph is different from the graph used at construction time of RecurrentRunner.')
    if (feed_dict is None):
        all_feeds_dict = {}
    else:
        all_feeds_dict = dict(feed_dict)
    all_feeds_dict.update(self._state_feeds)
    all_fetches_list = list(fetch_list)
    all_fetches_list += self._state_fetches
    sess = (sess or tf.get_default_session())
    fetches = sess.run(all_fetches_list, all_feeds_dict)
    states = fetches[len(fetch_list):]
    for (i, s) in enumerate(states):
        self._state_feeds[self._state_feed_names[i]] = s
    return fetches[:len(fetch_list)]

Runs the graph with the provided feeds and fetches.

This function wraps sess.Run(), but takes care of state saving and
restoring by feeding in states and storing the new state values.
Args:
fetch_list: A list of requested output tensors.
feed_dict: A dictionary of feeds - see Session.Run(). Optional.
sess: The Tensorflow session to run. Can be None.
Returns:
The requested tensors as numpy arrays.
Raises:
ValueError: If the default graph during object construction was
different from the current default graph.


def update(self, resource, id_or_uri=None, timeout=-1):

        uri = resource.pop('uri', None)
        if not uri:
            if not id_or_uri:
                raise ValueError("URI was not provided")
            uri = self._client.build_uri(id_or_uri)
        return self._client.update(resource=resource, uri=uri, timeout=timeout)

Updates the specified alert resource.

Args:
resource (dict): Object to update.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: Updated alert.


def _Open(self, path_spec, mode='rb'):

    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    range_offset = getattr(path_spec, 'range_offset', None)
    if range_offset is None:
      raise errors.PathSpecError(
          'Unsupported path specification without encoding method.')

    range_size = getattr(path_spec, 'range_size', None)
    if range_size is None:
      raise errors.PathSpecError(
          'Unsupported path specification without encoding method.')

    self._range_offset = range_offset
    self._range_size = range_size

Opens the file system defined by path specification.

Args:
path_spec (PathSpec): a path specification.
mode (Optional[str]): file access mode. The default is 'rb' which
represents read-only binary.

Raises:
AccessError: if the access to open the file was denied.
IOError: if the file system could not be opened.
PathSpecError: if the path specification is incorrect.
ValueError: if the path specification is invalid.


def preprocess_input(x, data_format=None):
    return x

A placeholder method for backward compatibility.

The preprocessing logic has been included in the EfficientNetV2 model
implementation. Users are no longer required to call this method to
normalize the input data. This method does nothing and only kept as a
placeholder to align the API surface between old and new version of model.

Args:
x: A floating point `numpy.array` or a tensor.
data_format: Optional data format of the image tensor/array. Defaults to
None, in which case the global setting
`keras.backend.image_data_format()` is used
(unless you changed it, it defaults to "channels_last").{mode}

Returns:
Unchanged `numpy.array` or tensor.


def set_led(self, colorcode):
    data = []
    data.append(10)
    data.append(self.servoid)
    data.append(RAM_WRITE_REQ)
    data.append(LED_CONTROL_RAM)
    data.append(1)
    data.append(colorcode)
    send_data(data)

Set the LED Color of Herkulex

Args:
colorcode (int): The code for colors
(0x00-OFF
0x02-BLUE
0x03-CYAN
0x04-RED
0x05-ORANGE
0x06-VIOLET
0x07-WHITE


def _CheckAttribute(self, attribute, value):

    if not isinstance(attribute, Attribute):
      raise AttributeError("Attribute %s must be of type aff4.Attribute()" %
                           attribute)

    if not isinstance(value, attribute.attribute_type):
      raise ValueError("Value for attribute %s must be of type %s()" %
                       (attribute, attribute.attribute_type.__name__))

Check that the value is of the expected type.

Args:
attribute: An instance of Attribute().
value: An instance of RDFValue.

Raises:
ValueError: when the value is not of the expected type.
AttributeError: When the attribute is not of type Attribute().


def search(self, query, verbose=0):

        if verbose > 0:
            print("searching " + query)
        query = query.lower()
        qgram = ng(query, self.slb)
        qocument = set()
        for q in qgram:
            if q in self.ngrams.keys():
                for i in self.ngrams[q]:
                    qocument.add(i)
        self.qocument = qocument
        results = {}
        for i in qocument:
           for j in self.D[i].keys():
                if not j in results.keys():
                    results[j] = 0
                results[j] = results[j] + self.D[i][j]
        sorted_results = sorted(results.items(), key=operator.itemgetter(1), reverse=True)
        return [self.elements[f[0]] for f in sorted_results]

Searches files satisfying query

It first decompose the query in ngrams, then score each document containing
at least one ngram with the number. The ten document having the most ngrams
in common with the query are selected.

Args:
query (str): what to search;
results_number (int): number of results to return (default: 10)


def _open_tracing_interface(self, conn_id, callback):

        try:
            handle = self._find_handle(conn_id)
            services = self._connections[handle]['services']
        except (ValueError, KeyError):
            callback(conn_id, self.id, False, 'Connection closed unexpectedly before we could open the streaming interface')
            return

        self._command_task.async_command(['_enable_tracing', handle, services],
                                         self._on_interface_finished, {'connection_id': conn_id, 'callback': callback})

Enable the debug tracing interface for this IOTile device

Args:
conn_id (int): the unique identifier for the connection
callback (callback): Callback to be called when this command finishes
callback(conn_id, adapter_id, success, failure_reason)


def cut_spectrum(sp, l0, lf):

    if l0 >= lf:
        raise ValueError("l0 must be lower than lf")
    idx0 = np.argmin(np.abs(sp.x - l0))
    idx1 = np.argmin(np.abs(sp.x - lf))
    out = copy.deepcopy(sp)
    out.x = out.x[idx0:idx1]
    out.y = out.y[idx0:idx1]
    return out

Cuts spectrum given a wavelength interval, leaving origina intact

Args:
sp: Spectrum instance
l0: initial wavelength
lf: final wavelength

Returns:
Spectrum: cut spectrum


def get_ieee_rotation(structure, refine_rotation=True):

        sga = SpacegroupAnalyzer(structure)
        dataset = sga.get_symmetry_dataset()
        trans_mat = dataset['transformation_matrix']
        conv_latt = Lattice(np.transpose(np.dot(np.transpose(
            structure.lattice.matrix), np.linalg.inv(trans_mat))))
        xtal_sys = sga.get_crystal_system()

        vecs = conv_latt.matrix
        lengths = np.array(conv_latt.abc)
        angles = np.array(conv_latt.angles)
        rotation = np.zeros((3, 3))

        if xtal_sys == "cubic":
            rotation = [vecs[i] / lengths[i] for i in range(3)]

        elif xtal_sys == "tetragonal":
            rotation = np.array([vec / mag for (mag, vec) in
                                 sorted(zip(lengths, vecs),
                                        key=lambda x: x[0])])
            if abs(lengths[2] - lengths[1]) < abs(lengths[1] - lengths[0]):
                rotation[0], rotation[2] = rotation[2], rotation[0].copy()
            rotation[1] = get_uvec(np.cross(rotation[2], rotation[0]))

        elif xtal_sys == "orthorhombic":
            rotation = [vec / mag for (mag, vec) in sorted(zip(lengths, vecs))]
            rotation = np.roll(rotation, 2, axis=0)

        elif xtal_sys in ("trigonal", "hexagonal"):

            tf_index = np.argmin(abs(angles - 120.))
            non_tf_mask = np.logical_not(angles == angles[tf_index])
            rotation[2] = get_uvec(vecs[tf_index])
            rotation[0] = get_uvec(vecs[non_tf_mask][0])
            rotation[1] = get_uvec(np.cross(rotation[2], rotation[0]))

        elif xtal_sys == "monoclinic":

            u_index = np.argmax(abs(angles - 90.))
            n_umask = np.logical_not(angles == angles[u_index])
            rotation[1] = get_uvec(vecs[u_index])

            c = [vec / mag for (mag, vec) in
                 sorted(zip(lengths[n_umask], vecs[n_umask]))][0]
            rotation[2] = np.array(c)
            rotation[0] = np.cross(rotation[1], rotation[2])

        elif xtal_sys == "triclinic":
            rotation = [vec / mag for (mag, vec) in sorted(zip(lengths, vecs))]
            rotation[1] = get_uvec(np.cross(rotation[2], rotation[0]))
            rotation[0] = np.cross(rotation[1], rotation[2])

        rotation = SquareTensor(rotation)
        if refine_rotation:
            rotation = rotation.refine_rotation()

        return rotation

Given a structure associated with a tensor, determines
the rotation matrix for IEEE conversion according to
the 1987 IEEE standards.

Args:
structure (Structure): a structure associated with the
tensor to be converted to the IEEE standard
refine_rotation (bool): whether to refine the rotation
using SquareTensor.refine_rotation


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

        super(GetAttributesResponsePayload, self).read(
            input_buffer,
            kmip_version=kmip_version
        )
        local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

        if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
            unique_identifier = primitives.TextString(
                tag=enums.Tags.UNIQUE_IDENTIFIER
            )
            unique_identifier.read(local_buffer, kmip_version=kmip_version)
            self.unique_identifier = unique_identifier.value
        else:
            raise exceptions.InvalidKmipEncoding(
                "The GetAttributes response payload encoding is missing the "
                "unique identifier."
            )

        if kmip_version < enums.KMIPVersion.KMIP_2_0:
            self._attributes = list()
            while self.is_tag_next(enums.Tags.ATTRIBUTE, local_buffer):
                attribute = objects.Attribute()
                attribute.read(local_buffer, kmip_version=kmip_version)
                self._attributes.append(attribute)
        else:
            if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer):
                attributes = objects.Attributes()
                attributes.read(local_buffer, kmip_version=kmip_version)

                temp_attr = objects.convert_attributes_to_template_attribute(
                    attributes
                )
                self._attributes = temp_attr.attributes
            else:
                raise exceptions.InvalidKmipEncoding(
                    "The GetAttributes response payload encoding is missing "
                    "the attributes structure."
                )

        self.is_oversized(local_buffer)

Read the data encoding the GetAttributes response payload and decode
it into its constituent parts.

Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.


def get_install_value(self, value_name, wanted_type=None):
    try:
        (item_value, item_type) = self.__reg_query_value(self.__reg_uninstall_handle, value_name)
    except pywintypes.error as exc:
        if (exc.winerror == winerror.ERROR_FILE_NOT_FOUND):
            return None
        raise
    if (wanted_type and (item_type not in self.__reg_types[wanted_type])):
        item_value = None
    return item_value

For the uninstall section of the registry return the name value.

Args:
value_name (str): Registry value name.
wanted_type (str):
The type of value wanted if the type does not match
None is return. wanted_type support values are
``str`` ``int`` ``list`` ``bytes``.

Returns:
value: Value requested or None if not found.


def validate(self, graph):
    if (not nx.is_directed_acyclic_graph(graph)):
        raise DirectedAcyclicGraphInvalid(graph_name=self._name)

Validate the graph by checking whether it is a directed acyclic graph.

Args:
graph (DiGraph): Reference to a DiGraph object from NetworkX.

Raises:
DirectedAcyclicGraphInvalid: If the graph is not a valid dag.


def get_defaults(path):

    defaults = {}

    if os.path.isfile(path):
        with open(path) as f:

            for line in f:
                line = line.strip()
                if '=' not in line or line.startswith('
                    continue

                k, v = line.split('=', 1)
                v = v.strip('"').strip("'")

                defaults[k] = v
        return defaults
    else:
        return {}

Reads file for configuration defaults.

Arguments:
- path (str) Absolute filepath (usually ~/.licenser)

Returns:
- (dict) Defaults for name, email, license, .txt extension


def __init__(self, bits: List[int], energy_layers: List[tf.keras.layers.Layer], name: Union[None, str]=None):
    super().__init__(name=name)
    self._bits = energy_utils.check_bits(bits)
    self._energy_layers = energy_layers

Initializes a BitstringEnergy.

Args:
bits: Unique labels for the bits on which this distribution is supported.
energy_layers: Concatenation of these layers yields trainable map from
bitstrings to scalars.
name: Optional name for the model.


def _LiteralEval(value):
    root = ast.parse(value, mode='eval')
    if isinstance(root.body, ast.BinOp):
        raise ValueError(value)
    for node in ast.walk(root):
        for field, child in ast.iter_fields(node):
            if isinstance(child, list):
                for index, subchild in enumerate(child):
                    if isinstance(subchild, ast.Name):
                        child[index] = _Replacement(subchild)
            elif isinstance(child, ast.Name):
                replacement = _Replacement(child)
                setattr(node, field, replacement)
    return ast.literal_eval(root)

Parse value as a Python literal, or container of containers and literals.

First the AST of the value is updated so that bare-words are turned into
strings. Then the resulting AST is evaluated as a literal or container of
only containers and literals.

This allows for the YAML-like syntax {a: b} to represent the dict {'a': 'b'}

Args:
value: A string to be parsed as a literal or container of containers and
literals.
Returns:
The Python value representing the value arg.
Raises:
ValueError: If the value is not an expression with only containers and
literals.
SyntaxError: If the value string has a syntax error.


def from_grpc_status(status_code, message, **kwargs):

    error_class = exception_class_for_grpc_status(status_code)
    error = error_class(message, **kwargs)

    if error.grpc_status_code is None:
        error.grpc_status_code = status_code

    return error

Create a :class:`GoogleAPICallError` from a :class:`grpc.StatusCode`.

Args:
status_code (grpc.StatusCode): The gRPC status code.
message (str): The exception message.
kwargs: Additional arguments passed to the :class:`GoogleAPICallError`
constructor.

Returns:
GoogleAPICallError: An instance of the appropriate subclass of
:class:`GoogleAPICallError`.


def _get_contexts_for_squash(self, batch_signature):

        batch = self._batches_by_id[batch_signature].batch
        index = self._batches.index(batch)
        contexts = []
        txns_added_predecessors = []
        for b in self._batches[index::-1]:
            batch_is_valid = True
            contexts_from_batch = []
            for txn in b.transactions[::-1]:
                result = self._txn_results[txn.header_signature]
                if not result.is_valid:
                    batch_is_valid = False
                    break
                else:
                    txn_id = txn.header_signature
                    if txn_id not in txns_added_predecessors:
                        txns_added_predecessors.append(
                            self._txn_predecessors[txn_id])
                        contexts_from_batch.append(result.context_id)
            if batch_is_valid:
                contexts.extend(contexts_from_batch)

        return contexts

Starting with the batch referenced by batch_signature, iterate back
through the batches and for each valid batch collect the context_id.
At the end remove contexts for txns that are other txn's predecessors.

Args:
batch_signature (str): The batch to start from, moving back through
the batches in the scheduler

Returns:
(list): Context ids that haven't been previous base contexts.


def VerifyStructure(self, parser_mediator, line):

    try:
      structure = self._LINE.parseString(line)
    except pyparsing.ParseException:
      logger.debug('Not a SkyDrive old log file')
      return False

    day_of_month, month, year, hours, minutes, seconds, milliseconds = (
        structure.date_time)

    time_elements_tuple = (
        year, month, day_of_month, hours, minutes, seconds, milliseconds)

    try:
      dfdatetime_time_elements.TimeElementsInMilliseconds(
          time_elements_tuple=time_elements_tuple)
    except ValueError:
      logger.debug(
          'Not a SkyDrive old log file, invalid date and time: {0!s}'.format(
              structure.date_time))
      return False

    return True

Verify that this file is a SkyDrive old log file.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
line (str): line from a text file.

Returns:
bool: True if the line is in the expected format, False if not.


def filter_children(self, ctype: ContentType=None) -> List[SchemaNode]:
    if (ctype is None):
        ctype = self.content_type()
    return [c for c in self.children if ((not isinstance(c, (RpcActionNode, NotificationNode))) and ((c.content_type().value & ctype.value) != 0))]

Return receiver's children based on content type.

Args:
ctype: Content type.


def _process_book(html_chunk):

    title, url = _parse_title_url(html_chunk)
    book_format, pages, isbn = _parse_format_pages_isbn(html_chunk)

    pub = Publication(
        title=title,
        authors=_parse_authors(html_chunk),
        price=_parse_price(html_chunk),
        publisher="Grada"
    )

    pub.optionals.URL = url
    pub.optionals.ISBN = isbn
    pub.optionals.pages = pages
    pub.optionals.format = book_format
    pub.optionals.sub_title = _parse_subtitle(html_chunk)
    pub.optionals.description = _parse_description(html_chunk)

    return pub

Parse available informations about book from the book details page.

Args:
html_chunk (obj): HTMLElement containing slice of the page with
details.

Returns:
obj: :class:`structures.Publication` instance with book details.


def warning_handler(self, handler):
    if (not self.opened()):
        handler = (handler or util.noop)
        self._warning_handler = enums.JLinkFunctions.LOG_PROTOTYPE(handler)
        self._dll.JLINKARM_SetWarnOutHandler(self._warning_handler)

Setter for the warning handler function.

If the DLL is open, this function is a no-op, so it should be called
prior to calling ``open()``.

Args:
self (JLink): the ``JLink`` instance
handler (function): function to call on warning messages

Returns:
``None``


def circuit_to_instruction(circuit):
    instruction = Instruction(name=circuit.name, num_qubits=sum([qreg.size for qreg in circuit.qregs]), num_clbits=sum([creg.size for creg in circuit.cregs]), params=[])
    instruction.control = None

    def find_bit_position(bit):
        'find the index of a given bit (Register, int) within\n        a flat ordered list of bits of the circuit\n        '
        if isinstance(bit[0], QuantumRegister):
            ordered_regs = circuit.qregs
        else:
            ordered_regs = circuit.cregs
        reg_index = ordered_regs.index(bit[0])
        return (sum([reg.size for reg in ordered_regs[:reg_index]]) + bit[1])
    definition = circuit.data.copy()
    if (instruction.num_qubits > 0):
        q = QuantumRegister(instruction.num_qubits, 'q')
    if (instruction.num_clbits > 0):
        c = ClassicalRegister(instruction.num_clbits, 'c')
    definition = list(map((lambda x: (x[0], list(map((lambda y: (q, find_bit_position(y))), x[1])), list(map((lambda y: (c, find_bit_position(y))), x[2])))), definition))
    instruction.definition = definition
    return instruction

Build an ``Instruction`` object from a ``QuantumCircuit``.

The instruction is anonymous (not tied to a named quantum register),
and so can be inserted into another circuit. The instruction will
have the same string name as the circuit.

Args:
circuit (QuantumCircuit): the input circuit.

Return:
Instruction: an instruction equivalent to the action of the
input circuit. Upon decomposition, this instruction will
yield the components comprising the original circuit.


def random_string_generator(size=6, chars=string.ascii_uppercase):
    try:
        return ''.join((random.choice(chars) for _ in range(size)))
    except:
        (line, filename, synerror) = trace()
        raise ArcRestHelperError({'function': 'random_string_generator', 'line': line, 'filename': filename, 'synerror': synerror})
    finally:
        pass

Generates a random string from a set of characters.

Args:
size (int): The length of the resultant string. Defaults to 6.
chars (str): The characters to be used by :py:func:`random.choice`. Defaults to :py:const:`string.ascii_uppercase`.

Returns:
str: The randomly generated string.

Examples:
>>> arcresthelper.common.random_string_generator()
'DCNYWU'
>>> arcresthelper.common.random_string_generator(12, "arcREST")
'cESaTTEacTES'


def wait_for_job(self, job, poll=5):
    desc = _wait_until_training_done((lambda last_desc: _train_done(self.sagemaker_client, job, last_desc)), None, poll)
    self._check_job_status(job, desc, 'TrainingJobStatus')
    return desc

Wait for an Amazon SageMaker training job to complete.

Args:
job (str): Name of the training job to wait for.
poll (int): Polling interval in seconds (default: 5).

Returns:
(dict): Return value from the ``DescribeTrainingJob`` API.

Raises:
ValueError: If the training job fails.


def get_push_pop_stack():
    push = copy.deepcopy(PUSH_STACK)
    pop = copy.deepcopy(POP_STACK)
    anno.setanno(push, 'pop', pop)
    anno.setanno(push, 'gen_push', True)
    anno.setanno(pop, 'push', push)
    op_id = _generate_op_id()
    return (push, pop, op_id)

Create pop and push nodes for substacks that are linked.

Returns:
A push and pop node which have `push_func` and `pop_func` annotations
respectively, identifying them as such. They also have a `pop` and
`push` annotation respectively, which links the push node to the pop
node and vice versa.


def get_locations_list(self, lower_bound=0, upper_bound=None):
    real_upper_bound = upper_bound
    if (upper_bound is None):
        real_upper_bound = self.nbr_of_sub_locations()
    try:
        return self._locations_list[lower_bound:real_upper_bound]
    except:
        return list()

Return the internal location list.

Args:
lower_bound:
upper_bound:

Returns:


def serialize_to_display(self, doc_format='pretty-xml', *args, **kwargs):
    return super(ResourceMap, self).serialize(*args, format=doc_format, encoding=None, **kwargs).decode('utf-8')

Serialize ResourceMap to an XML doc that is pretty printed for display.

Args:
doc_format: str
One of: ``xml``, ``n3``, ``turtle``, ``nt``, ``pretty-xml``, ``trix``,
``trig`` and ``nquads``.

args and kwargs:
Optional arguments forwarded to rdflib.ConjunctiveGraph.serialize().

Returns:
str: Pretty printed Resource Map XML doc

Note:
Only the default, "xml", is automatically indexed by DataONE.


def _print_tensor_info(tensor_info, indent=0):
    indent_str = '  ' * indent

    def in_print(s):
        print(indent_str + s)
    in_print('    dtype: ' + {value: key for key, value in types_pb2.DataType.items()}[tensor_info.dtype])
    if tensor_info.tensor_shape.unknown_rank:
        shape = 'unknown_rank'
    else:
        dims = [str(dim.size) for dim in tensor_info.tensor_shape.dim]
        shape = ', '.join(dims)
        shape = '(' + shape + ')'
    in_print('    shape: ' + shape)
    in_print('    name: ' + tensor_info.name)

Prints details of the given tensor_info.

Args:
tensor_info: TensorInfo object to be printed.
indent: How far (in increments of 2 spaces) to indent each line output


def create_stub(generated_create_stub, channel=None, service_path=None, service_port=None, credentials=None, scopes=None, ssl_credentials=None):
    if (channel is None):
        target = '{}:{}'.format(service_path, service_port)
        if (credentials is None):
            credentials = _grpc_google_auth.get_default_credentials(scopes)
        channel = _grpc_google_auth.secure_authorized_channel(credentials, target, ssl_credentials=ssl_credentials)
    return generated_create_stub(channel)

Creates a gRPC client stub.

Args:
generated_create_stub (Callable): The generated gRPC method to create a
stub.
channel (grpc.Channel): A Channel object through which to make calls.
If None, a secure channel is constructed. If specified, all
remaining arguments are ignored.
service_path (str): The domain name of the API remote host.
service_port (int): The port on which to connect to the remote host.
credentials (google.auth.credentials.Credentials): The authorization
credentials to attach to requests. These credentials identify your
application to the service.
scopes (Sequence[str]): The OAuth scopes for this service. This
parameter is ignored if a credentials is specified.
ssl_credentials (grpc.ChannelCredentials): gRPC channel credentials
used to create a secure gRPC channel. If not specified, SSL
credentials will be created using default certificates.

Returns:
grpc.Client: A gRPC client stub.


def query(self, minhash, k):

        if k <= 0:
            raise ValueError("k must be positive")
        if len(minhash) < self.k*self.l:
            raise ValueError("The num_perm of MinHash out of range")
        results = set()
        r = self.k
        while r > 0:
            for key in self._query(minhash, r, self.l):
                results.add(key)
                if len(results) >= k:
                    return list(results)
            r -= 1
        return list(results)

Return the approximate top-k keys that have the highest
Jaccard similarities to the query set.

Args:
minhash (datasketch.MinHash): The MinHash of the query set.
k (int): The maximum number of keys to return.

Returns:
`list` of at most k keys.


def add_region_feature(self, start_resnum, end_resnum, feat_type=None, feat_id=None, qualifiers=None):

        if self.feature_file:
            raise ValueError('Feature file associated with sequence, please remove file association to append '
                             'additional features.')

        if not feat_type:
            feat_type = 'Manually added protein sequence region feature'
        newfeat = SeqFeature(location=FeatureLocation(start_resnum-1, end_resnum),
                             type=feat_type,
                             id=feat_id,
                             qualifiers=qualifiers)

        self.features.append(newfeat)

Add a feature to the features list describing a region of the protein sequence.

Args:
start_resnum (int): Start residue number of the protein sequence feature
end_resnum (int): End residue number of the protein sequence feature
feat_type (str, optional): Optional description of the feature type (ie. 'binding domain')
feat_id (str, optional): Optional ID of the feature type (ie. 'TM1')


def get_concept_item_mapping(self, concepts=None, lang=None):
    if (concepts is None):
        concepts = self.filter(active=True)
        if (lang is not None):
            concepts = concepts.filter(lang=lang)
    if (lang is None):
        languages = set([concept.lang for concept in concepts])
        if (len(languages) > 1):
            raise Exception('Concepts has multiple languages')
        lang = list(languages)[0]
    item_lists = Item.objects.filter_all_reachable_leaves_many([json.loads(concept.query) for concept in concepts], lang)
    return dict(zip([c.pk for c in concepts], item_lists))

Get mapping of concepts to items belonging to concept.

Args:
concepts (list of Concept): Defaults to None meaning all concepts
lang (str): language of concepts, if None use language of concepts

Returns:
dict: concept (int) -> list of item ids (int)


def convert_selu(params, w_name, scope_name, inputs, layers, weights, names):

    print('Converting selu ...')

    if names == 'short':
        tf_name = 'SELU' + random_string(4)
    elif names == 'keep':
        tf_name = w_name
    else:
        tf_name = w_name + str(random.random())

    selu = keras.layers.Activation('selu', name=tf_name)
    layers[scope_name] = selu(layers[inputs[0]])

Convert selu layer.

Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers


def spherical_vert(script, radius=1.0, center_pt=(0.0, 0.0, 0.0)):
    function = 'sqrt((x-{})^2+(y-{})^2+(z-{})^2)<={}'.format(center_pt[0], center_pt[1], center_pt[2], radius)
    vert_function(script, function=function)
    return None

Select all vertices within a spherical radius

Args:
radius (float): radius of the sphere
center_pt (3 coordinate tuple or list): center point of the sphere

Layer stack:
No impacts

MeshLab versions:
2016.12
1.3.4BETA


def recipe_bigquery_function(config, auth, function, dataset):
    bigquery(config, {'auth': auth, 'function': function, 'to': {'dataset': dataset}})

Add a custom function or table to a dataset.

Args:
auth (authentication) - Credentials used for writing function.
function (choice) - Function or table to create.
dataset (string) - Existing BigQuery dataset.


def apply_grads(self, grads, variables):
    ops = []
    for (grad, var) in zip(grads, variables):
        ops.extend(self.apply_grad(grad, var))
    if (not ops):
        return ops
    return variables[0].graph.combine_assignments(ops)

Apply gradients to variables.

Call this function externally instead of apply_grad().  This causes the
operations to be combined, which is necessary for stacking variables
see mtf.rewrite_stack_variables().

Args:
grads: a list of Tensor
variables: a list of Variables
Returns:
a list of Operations


def merge(self, dataset):

    def merge_data(source, dest):
        for (key, value) in source.items():
            if isinstance(value, dict):
                merge_data(value, dest.setdefault(key, {}))
            else:
                dest[key] = value
        return dest
    merge_data(dataset.data, self._data)
    for h in dataset.task_history:
        if (h not in self._task_history):
            self._task_history.append(h)

Merge the specified dataset on top of the existing data.

This replaces all values in the existing dataset with the values from the
given dataset.

Args:
dataset (TaskData): A reference to the TaskData object that should be merged
on top of the existing object.


def score_intersect(self, term1, term2, **kwargs):
    t1_kde = self.kde(term1, **kwargs)
    t2_kde = self.kde(term2, **kwargs)
    overlap = np.minimum(t1_kde, t2_kde)
    return np.trapz(overlap)

Compute the geometric area of the overlap between the kernel density
estimates of two terms.

Args:
term1 (str)
term2 (str)

Returns: float


def call(self, hidden_states: tf.Tensor, attention_mask: np.ndarray | tf.Tensor | None, layer_head_mask: tf.Tensor | None, training: Optional[bool]=False) -> tf.Tensor:
    residual = hidden_states
    hidden_states, self_attn_weights, _ = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, layer_head_mask=layer_head_mask)
    tf.debugging.assert_equal(shape_list(hidden_states), shape_list(residual), message=f'Self attn modified the shape of query {shape_list(residual)} to {shape_list(hidden_states)}')
    hidden_states = self.dropout(hidden_states, training=training)
    hidden_states = residual + hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    residual = hidden_states
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = self.activation_dropout(hidden_states, training=training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = self.dropout(hidden_states, training=training)
    hidden_states = residual + hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    return (hidden_states, self_attn_weights)

Args:
hidden_states (`tf.Tensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`tf.Tensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
layer_head_mask (`tf.Tensor`): mask for attention heads in a given layer of size
`(encoder_attention_heads,)`


def _ParseFileHeader(self, file_object):
    file_header_map = self._GetDataTypeMap('chrome_cache_data_block_file_header')
    try:
        (file_header, _) = self._ReadStructureFromFileObject(file_object, 0, file_header_map)
    except (ValueError, errors.ParseError) as exception:
        raise errors.ParseError('Unable to parse data block file header with error: {0!s}'.format(exception))
    if (file_header.signature != self._FILE_SIGNATURE):
        raise errors.ParseError('Unsupported data block file signature')
    format_version = '{0:d}.{1:d}'.format(file_header.major_version, file_header.minor_version)
    if (format_version not in ('2.0', '2.1')):
        raise errors.ParseError('Unsupported data block file format version: {0:s}'.format(format_version))
    if (file_header.block_size not in (256, 1024, 4096)):
        raise errors.ParseError('Unsupported data block file block size: {0:d}'.format(file_header.block_size))

Parses the file header.

Args:
file_object (dfvfs.FileIO): a file-like object to parse.

Raises:
ParseError: if the file header cannot be read.


def get_authorization_url(self, client_id=None, instance_id=None,
                              redirect_uri=None, region=None, scope=None,
                              state=None):

        client_id = client_id or self.client_id
        instance_id = instance_id or self.instance_id
        redirect_uri = redirect_uri or self.redirect_uri
        region = region or self.region
        scope = scope or self.scope
        state = state or str(uuid.uuid4())
        self.state = state
        return Request(
            'GET',
            self.auth_base_url,
            params={
                'client_id': client_id,
                'instance_id': instance_id,
                'redirect_uri': redirect_uri,
                'region': region,
                'response_type': 'code',
                'scope': scope,
                'state': state
            }
        ).prepare().url, state

Generate authorization URL.

Args:
client_id (str): OAuth2 client ID. Defaults to ``None``.
instance_id (str): App Instance ID. Defaults to ``None``.
redirect_uri (str): Redirect URI. Defaults to ``None``.
region (str): App Region. Defaults to ``None``.
scope (str): Permissions. Defaults to ``None``.
state (str): UUID to detect CSRF. Defaults to ``None``.

Returns:
str, str: Auth URL, state


def get_type(self):
    raise NotImplementedError('Base class should not be called directly!')

This function returns the type of the sniffer.

Returns:
The type (string) of the sniffer. Corresponds to the 'Type' key of
the sniffer configuration.


def create_heroku_connect_schema(using=DEFAULT_DB_ALIAS):
    connection = connections[using]
    with connection.cursor() as cursor:
        cursor.execute(_SCHEMA_EXISTS_QUERY, [settings.HEROKU_CONNECT_SCHEMA])
        schema_exists = cursor.fetchone()[0]
        if schema_exists:
            return False
        cursor.execute('CREATE SCHEMA %s;', [AsIs(settings.HEROKU_CONNECT_SCHEMA)])
    with connection.schema_editor() as editor:
        for model in get_heroku_connect_models():
            editor.create_model(model)
        editor.execute('CREATE EXTENSION IF NOT EXISTS "hstore";')
        from heroku_connect.models import TriggerLog, TriggerLogArchive
        for cls in [TriggerLog, TriggerLogArchive]:
            editor.create_model(cls)
    return True

Create Heroku Connect schema.

Note:
This function is only meant to be used for local development.
In a production environment the schema will be created by
Heroku Connect.

Args:
using (str): Alias for database connection.

Returns:
bool: ``True`` if the schema was created, ``False`` if the
schema already exists.


def parse_date(date_string, ignoretz=True):

    try:
        return parser.parse(date_string, ignoretz=ignoretz)
    except TypeError:
        return None

Parse a string as a date. If the string fails to parse, `None` will be returned instead

>>> parse_date('2017-08-15T18:24:31')
datetime.datetime(2017, 8, 15, 18, 24, 31)

Args:
date_string (`str`): Date in string format to parse
ignoretz (`bool`): If set ``True``, ignore time zones and return a naive :class:`datetime` object.

Returns:
`datetime`, `None`


def isubset(self, *keys):

        return ww.g((key, self[key]) for key in keys)

Return key, self[key] as generator for key in keys.

Raise KeyError if a key does not exist

Args:
keys: Iterable containing keys

Example:

>>> from ww import d
>>> list(d({1: 1, 2: 2, 3: 3}).isubset(1, 3))
[(1, 1), (3, 3)]


def init_cache(self, batch_size, max_length, encoder_outputs):
    decoder_input_ids = jnp.ones((batch_size, max_length), dtype='i4')
    decoder_attention_mask = jnp.ones_like(decoder_input_ids)
    decoder_position_ids = jnp.broadcast_to(jnp.arange(jnp.atleast_2d(decoder_input_ids).shape[-1]), decoder_input_ids.shape)

    def _decoder_forward(module, decoder_input_ids, decoder_attention_mask, decoder_position_ids, **kwargs):
        decoder_module = module._get_decoder_module()
        return decoder_module(decoder_input_ids, decoder_attention_mask, decoder_position_ids, **kwargs)
    init_variables = self.module.init(jax.random.PRNGKey(0), decoder_input_ids=decoder_input_ids, decoder_attention_mask=decoder_attention_mask, decoder_position_ids=decoder_position_ids, encoder_hidden_states=encoder_outputs[0], init_cache=True, method=_decoder_forward)
    return unfreeze(init_variables['cache'])

Args:
batch_size (`int`):
batch_size used for fast auto-regressive decoding. Defines the batch size of the initialized cache.
max_length (`int`):
maximum possible length for auto-regressive decoding. Defines the sequence length of the initialized
cache.
encoder_outputs (`Union[FlaxBaseModelOutput, tuple(tuple(jnp.ndarray)]`):
`encoder_outputs` consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*:
`attentions`). `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*)
is a sequence of hidden-states at the output of the last layer of the encoder. Used in the
cross-attention of the decoder.


def beam_sql(self, line: str, cell: Optional[str]=None) -> Optional[PValue]:
    input_str = line
    if cell:
        input_str += ' ' + cell
    parsed = self._parser.parse(input_str.strip().split())
    if not parsed:
        return
    output_name = parsed.output_name
    verbose = parsed.verbose
    query = parsed.query
    runner = parsed.runner
    if output_name and (not output_name.isidentifier()) or keyword.iskeyword(output_name):
        on_error('The output_name "%s" is not a valid identifier. Please supply a valid identifier that is not a Python keyword.', line)
        return
    if not query:
        on_error('Please supply the SQL query to be executed.')
        return
    if runner and runner not in _SUPPORTED_RUNNERS:
        on_error('Runner "%s" is not supported. Supported runners are %s.', runner, _SUPPORTED_RUNNERS)
        return
    query = ' '.join(query)
    found = find_pcolls(query, pcoll_by_name(), verbose=verbose)
    schemas = set()
    main_session = importlib.import_module('__main__')
    for _, pcoll in found.items():
        if not match_is_named_tuple(pcoll.element_type):
            on_error('PCollection %s of type %s is not a NamedTuple. See https:
            return
        register_coder_for_schema(pcoll.element_type, verbose=verbose)
        if hasattr(main_session, pcoll.element_type.__name__):
            schemas.add(pcoll.element_type)
    if runner in ('DirectRunner', None):
        collect_data_for_local_run(query, found)
        output_name, output, chain = apply_sql(query, output_name, found)
        chain.current.schemas = schemas
        cache_output(output_name, output)
        return output
    output_name, current_node, chain = apply_sql(query, output_name, found, False)
    current_node.schemas = schemas
    if runner == 'DataflowRunner':
        _ = chain.to_pipeline()
        _ = DataflowOptionsForm(output_name, pcoll_by_name()[output_name], verbose).display_for_input()
        return None
    else:
        raise ValueError('Unsupported runner %s.', runner)

The beam_sql line/cell magic that executes a Beam SQL.

Args:
line: the string on the same line after the beam_sql magic.
cell: everything else in the same notebook cell as a string. If None,
beam_sql is used as line magic. Otherwise, cell magic.

Returns None if running into an error or waiting for user input (running on
a selected runner remotely), otherwise a PValue as if a SqlTransform is
applied.


def get_experiment_from_key(self, experiment_key):
    experiment = self.experiment_key_map.get(experiment_key)
    if experiment:
        return experiment
    self.logger.error(('Experiment key "%s" is not in datafile.' % experiment_key))
    self.error_handler.handle_error(exceptions.InvalidExperimentException(enums.Errors.INVALID_EXPERIMENT_KEY_ERROR))
    return None

Get experiment for the provided experiment key.

Args:
experiment_key: Experiment key for which experiment is to be determined.

Returns:
Experiment corresponding to the provided experiment key.


def get_type_info(obj):

    if isinstance(obj, primitive_types):
        return ('primitive', type(obj).__name__)
    if isinstance(obj, sequence_types):
        return ('sequence', type(obj).__name__)
    if isinstance(obj, array_types):
        return ('array', type(obj).__name__)
    if isinstance(obj, key_value_types):
        return ('key-value', type(obj).__name__)
    if isinstance(obj, types.ModuleType):
        return ('module', type(obj).__name__)
    if isinstance(obj, (types.FunctionType, types.MethodType)):
        return ('function', type(obj).__name__)
    if isinstance(obj, type):
        if hasattr(obj, '__dict__'):
            return ('class', obj.__name__)
    if isinstance(type(obj), type):
        if hasattr(obj, '__dict__'):
            cls_name = type(obj).__name__
            if cls_name == 'classobj':
                cls_name = obj.__name__
                return ('class', '{}'.format(cls_name))
            if cls_name == 'instance':
                cls_name = obj.__class__.__name__
            return ('instance', '{} instance'.format(cls_name))

    return ('unknown', type(obj).__name__)

Get type information for a Python object

Args:
obj: The Python object

Returns:
tuple: (object type "catagory", object type name)


async def freeze(self, *args, **kwargs):
    uid = kwargs.get('uid', 0)
    coinid = kwargs.get('coinid')
    amount = kwargs.get('amount')
    address = kwargs.get('address')
    try:
        coinid = coinid.replace('TEST', '')
    except:
        pass
    try:
        uid = int(uid)
    except:
        return (await self.error_400('User id must be integer. '))
    try:
        amount = int(amount)
    except:
        return (await self.error_400('Amount must be integer. '))
    try:
        assert (amount > 0)
    except:
        return (await self.error_400('Amount must be positive integer. '))
    if ((not uid) and address):
        uid = (await self.get_uid_by_address(address=address, coinid=coinid))
        if isinstance(uid, dict):
            return uid
    database = self.client[self.collection]
    collection = database[coinid]
    balance = (await collection.find_one({'uid': uid}))
    if (not balance):
        return (await self.error_404(('Freeze. Balance with uid:%s and type:%s not found.' % (uid, coinid))))
    difference = (int(balance['amount_active']) - int(amount))
    if (difference < 0):
        return (await self.error_403('Freeze. Insufficient amount in the account'))
    amount_frozen = (int(balance['amount_frozen']) + int(amount))
    (await collection.find_one_and_update({'uid': uid}, {'$set': {'amount_active': str(difference), 'amount_frozen': str(amount_frozen)}}))
    result = (await collection.find_one({'uid': uid}))
    result['amount_frozen'] = int(result['amount_frozen'])
    result['amount_active'] = int(result['amount_active'])
    del result['_id']
    return result

Freeze users balance

Accepts:
- uid [integer] (users id from main server)
- coinid [string] (blockchain type in uppercase)
- amount [integer] (amount for freezing)

Returns:
- uid [integer] (users id from main server)
- coinid [string] (blockchain type in uppercase)
- amount_active [integer] (activae users amount)
- amount_frozen [integer] (frozen users amount)


def delete_panel(self, panel_obj):
    res = self.panel_collection.delete_one({'_id': panel_obj['_id']})
    LOG.warning(('Deleting panel %s, version %s' % (panel_obj['panel_name'], panel_obj['version'])))
    return res

Delete a panel by '_id'.

Args:
panel_obj(dict)

Returns:
res(pymongo.DeleteResult)


def unique_timestamps(self: EventSetOrNode) -> EventSetOrNode:
    from temporian.core.operators.unique_timestamps import unique_timestamps
    return unique_timestamps(self)

Removes events with duplicated timestamps from an
[`EventSet`][temporian.EventSet].

Returns a feature-less EventSet where each timestamp from the original
one only appears once. If the input is indexed, the unique operation is
applied independently for each index.

Usage example:
```python
>>> a = tp.event_set(timestamps=[5, 9, 9, 16], features={'f': [1,2,3,4]})
>>> b = a.unique_timestamps()
>>> b
indexes: []
features: []
events:
(3 events):
timestamps: [ 5. 9. 16.]
...

```

Returns:
EventSet without features with unique timestamps in the input.


def group_by_mimetype(content: ProcessorContent) -> dict[str, ProcessorContent]:
    grouped_content = {}
    for mimetype, part in content.items():
        if mimetype not in grouped_content:
            grouped_content[mimetype] = ProcessorContent()
        grouped_content[mimetype] += part
    return grouped_content

Groups content by mimetype.

The order of parts within each mimetype grouping is preserved, maintaining the
same order as they appeared in the original input `content`.

Args:
content: The content to group.

Returns:
A dictionary mapping mimetypes to ProcessorContent objects, with the same
order as in the original input `content`.


def compare_versions(ver1='', oper='==', ver2=''):

    if not ver1:
        raise SaltInvocationError('compare_version, ver1 is blank')
    if not ver2:
        raise SaltInvocationError('compare_version, ver2 is blank')

    if ver1 == 'latest':
        ver1 = six.text_type(sys.maxsize)
    if ver2 == 'latest':
        ver2 = six.text_type(sys.maxsize)

    if ver1 == 'Not Found':
        ver1 = '0.0.0.0.0'
    if ver2 == 'Not Found':
        ver2 = '0.0.0.0.0'

    return salt.utils.versions.compare(ver1, oper, ver2, ignore_epoch=True)

Compare software package versions

Args:
ver1 (str): A software version to compare
oper (str): The operand to use to compare
ver2 (str): A software version to compare

Returns:
bool: True if the comparison is valid, otherwise False

CLI Example:

.. code-block:: bash

salt '*' pkg.compare_versions 1.2 >= 1.3


def colored(cls, color, message):

        return getattr(cls, color.upper()) + message + cls.DEFAULT

Small function to wrap a string around a color

Args:
color (str): name of the color to wrap the string with, must be one
of the class properties
message (str): String to wrap with the color

Returns:
str: the colored string


def commit_author(sha1=''):
    with conf.within_proj_dir():
        cmd = 'git show -s --format="%an||%ae" {}'.format(sha1)
        result = shell.run(cmd, capture=True, never_pretend=True).stdout
        (name, email) = result.split('||')
        return Author(name, email)

Return the author of the given commit.

Args:
sha1 (str):
The sha1 of the commit to query. If not given, it will return the
sha1 for the current commit.
Returns:
Author: A named tuple ``(name, email)`` with the commit author details.