def verify_link_ed25519_cot_signature(chain, link, unsigned_path, signature_path):
    if chain.context.config['verify_cot_signature']:
        log.debug('Verifying the {} {} {} ed25519 chain of trust signature'.format(link.name, link.task_id, link.worker_impl))
        signature = read_from_file(signature_path, file_type='binary', exception=CoTError)
        binary_contents = read_from_file(unsigned_path, file_type='binary', exception=CoTError)
        errors = []
        verify_key_seeds = chain.context.config['ed25519_public_keys'].get(link.worker_impl, [])
        for seed in verify_key_seeds:
            try:
                verify_key = ed25519_public_key_from_string(seed)
                verify_ed25519_signature(verify_key, binary_contents, signature, "{} {}: {} ed25519 cot signature doesn't verify against {}: %(exc)s".format(link.name, link.task_id, link.worker_impl, seed))
                log.debug('{} {}: ed25519 cot signature verified.'.format(link.name, link.task_id))
                break
            except ScriptWorkerEd25519Error as exc:
                errors.append(str(exc))
        else:
            errors = (errors or ['{} {}: Unknown error verifying ed25519 cot signature. worker_impl {} verify_keys {}'.format(link.name, link.task_id, link.worker_impl, verify_key_seeds)])
            message = '\n'.join(errors)
            raise CoTError(message)
    link.cot = load_json_or_yaml(unsigned_path, is_path=True, exception=CoTError, message='{} {}: Invalid unsigned cot json body! %(exc)s'.format(link.name, link.task_id))

Verify the ed25519 signatures of the chain of trust artifacts populated in ``download_cot``.

Populate each link.cot with the chain of trust json body.

Args:
chain (ChainOfTrust): the chain of trust to add to.

Raises:
(CoTError, ScriptWorkerEd25519Error): on signature verification failure.


def unpack_archive(*components, **kwargs) -> str:
    path = fs.abspath(*components)
    compression = kwargs.get('compression', 'bz2')
    dir = kwargs.get('dir', fs.dirname(path))
    fs.cd(dir)
    tar = tarfile.open(path, ('r:' + compression))
    tar.extractall()
    tar.close()
    fs.cdpop()
    return dir

Unpack a compressed archive.

Arguments:
*components (str[]): Absolute path.
**kwargs (dict, optional): Set "compression" to compression type.
Default: bz2. Set "dir" to destination directory. Defaults to the
directory of the archive.

Returns:
str: Path to directory.


def __frontend_limit_descriptor(self, api_info):
    if (api_info.frontend_limits is None):
        return None
    descriptor = {}
    for (propname, descname) in (('unregistered_user_qps', 'unregisteredUserQps'), ('unregistered_qps', 'unregisteredQps'), ('unregistered_daily', 'unregisteredDaily')):
        if (getattr(api_info.frontend_limits, propname) is not None):
            descriptor[descname] = getattr(api_info.frontend_limits, propname)
    rules = self.__frontend_limit_rules_descriptor(api_info)
    if rules:
        descriptor['rules'] = rules
    return descriptor

Builds a frontend limit descriptor from API info.

Args:
api_info: An _ApiInfo object.

Returns:
A dictionary with frontend limit information.


def Deserialize(self, reader):

        self.PrevHash = reader.ReadUInt256()
        self.PrevIndex = reader.ReadUInt16()

Deserialize full object.

Args:
reader (neo.IO.BinaryReader):


def _guess_format_from_extension(ext):

    ext = ext.strip('.')

    formats = []
    for fmt in FILE_FORMATS:
        if ext in FILE_FORMATS[fmt]:
            formats.append(fmt)

    if formats == [] or len(formats) > 1:
        return False

    return formats[0]

Guess the appropriate data type from file extension.

Arguments:
ext:        The file extension (period optional)

Returns:
String. The format (without leading period),
or False if none was found or couldn't be guessed


def handle_upnp_error(self, xml_error):
    xml_error = xml_error.encode('utf-8')
    error = XML.fromstring(xml_error)
    log.debug('Error %s', xml_error)
    error_code = error.findtext('.
    if (error_code is not None):
        description = self.UPNP_ERRORS.get(int(error_code), '')
        raise SoCoUPnPException(message='UPnP Error {} received: {} from {}'.format(error_code, description, self.soco.ip_address), error_code=error_code, error_description=description, error_xml=xml_error)
    else:
        log.error('Unknown error received from %s', self.soco.ip_address)
        raise UnknownSoCoException(xml_error)

Disect a UPnP error, and raise an appropriate exception.

Args:
xml_error (str):  a unicode string containing the body of the
UPnP/SOAP Fault response. Raises an exception containing the
error code.


def get_signature_def(meta_graph, signature_key):
    signature_def_map = meta_graph.signature_def
    signature_def_keys = set(signature_def_map.keys())
    logging.info('The given SavedModel MetaGraphDef contains SignatureDefs with the following keys: %s', signature_def_keys)
    if signature_key not in signature_def_keys:
        raise ValueError("No '{}' in the SavedModel's SignatureDefs. Possible values are '{}'.".format(signature_key, ','.join(signature_def_keys)))
    return signature_def_map[signature_key]

Get the signature def from meta_graph with given signature_key.

Args:
meta_graph: meta_graph_def.
signature_key: signature_def in the meta_graph_def.

Returns:
The signature_def used for tflite conversion.

Raises:
ValueError: Given signature_key is not valid for this meta_graph.


def get_m49_from_iso3(cls, iso3, use_live=True, exception=None):
    countriesdata = cls.countriesdata(use_live=use_live)
    m49 = countriesdata['m49iso3'].get(iso3)
    if (m49 is not None):
        return m49
    if (exception is not None):
        raise exception
    return None

Get M49 from ISO3 code

Args:
iso3 (str): ISO3 code for which to get M49 code
use_live (bool): Try to get use latest data from web rather than file in package. Defaults to True.
exception (Optional[ExceptionUpperBound]): An exception to raise if country not found. Defaults to None.

Returns:
Optional[int]: M49 code


def agent_version(self, value):

        if value == self._defaults['ai.internal.agentVersion'] and 'ai.internal.agentVersion' in self._values:
            del self._values['ai.internal.agentVersion']
        else:
            self._values['ai.internal.agentVersion'] = value

The agent_version property.

Args:
value (string). the property value.


def byte_str(nBytes, unit='bytes', precision=2):
    if unit.lower().startswith('b'):
        nUnit = nBytes
    elif unit.lower().startswith('k'):
        nUnit = (nBytes / (2.0 ** 10))
    elif unit.lower().startswith('m'):
        nUnit = (nBytes / (2.0 ** 20))
    elif unit.lower().startswith('g'):
        nUnit = (nBytes / (2.0 ** 30))
    elif unit.lower().startswith('t'):
        nUnit = (nBytes / (2.0 ** 40))
    else:
        raise NotImplementedError(('unknown nBytes=%r unit=%r' % (nBytes, unit)))
    return ((repr2(nUnit, precision=precision) + ' ') + unit)

representing the number of bytes with the chosen unit

Returns:
str


def report_error(self, read_tuple_name, error_name, wrong="", message="", warning=False):

        if (not self.report_only_first) or (error_name not in self.reported_errors):
            print("\t".join(["error" if warning == False else "warning", read_tuple_name, error_name, wrong, message]))
        self.reported_errors.add(error_name)
        if warning:
            self.warning_has_been_reported = True
        else:
            self.error_has_been_reported = True

Report an error.

Args:
read_tuple_name (): Name of the read tuple.
error_name (): Name of the error.
wrong (str): What is wrong.
message (str): Additional msessage to be printed.
warning (bool): Warning (not an error).


def activate_absence_with_duration(self, duration: int):

        data = {"duration": duration}
        return self._restCall(
            "home/heating/activateAbsenceWithDuration", json.dumps(data)
        )

activates the absence mode for a given time

Args:
duration(int): the absence duration in minutes


def wb004(self, value=None):
    if (value is not None):
        try:
            value = float(value)
        except ValueError:
            raise ValueError('value {} need to be of type float for field `wb004`'.format(value))
    self._wb004 = value

Corresponds to IDD Field `wb004`
Wet-bulb temperature corresponding to 0.4% annual cumulative frequency of occurrence

Args:
value (float): value for IDD Field `wb004`
Unit: C
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


async def download_cot(chain):

    artifact_tasks = []

    for link in chain.links:
        task_id = link.task_id
        parent_dir = link.cot_dir
        urls = []

        unsigned_url = get_artifact_url(chain.context, task_id, 'public/chain-of-trust.json')
        urls.append(unsigned_url)
        if chain.context.config['verify_cot_signature']:
            urls.append(
                get_artifact_url(chain.context, task_id, 'public/chain-of-trust.json.sig')
            )

        artifact_tasks.append(
            asyncio.ensure_future(
                download_artifacts(
                    chain.context, urls, parent_dir=parent_dir,
                    valid_artifact_task_ids=[task_id]
                )
            )
        )

    artifacts_paths = await raise_future_exceptions(artifact_tasks)

    for path in artifacts_paths:
        sha = get_hash(path[0])
        log.debug("{} downloaded; hash is {}".format(path[0], sha))

Download the signed chain of trust artifacts.

Args:
chain (ChainOfTrust): the chain of trust to add to.

Raises:
BaseDownloadError: on failure.


def rtm(self, url: Optional[str]=None, bot_id: Optional[str]=None) -> Iterator[events.Event]:
    while True:
        bot_id = (bot_id or self._find_bot_id())
        url = (url or self._find_rtm_url())
        for event in self._incoming_from_rtm(url, bot_id):
            (yield event)
        url = None

Iterate over event from the RTM API

Args:
url: Websocket connection url
bot_id: Connecting bot ID

Returns:
:class:`slack.events.Event` or :class:`slack.events.Message`


class InputExample:
    guid: str
    text_a: str
    text_b: Optional[str] = None
    label: Optional[str] = None

    def to_json_string(self):

        return json.dumps(dataclasses.asdict(self), indent=2) + '\n'

A single training/test example for simple sequence classification.

Args:
guid: Unique id for the example.
text_a: string. The untokenized text of the first sequence. For single
sequence tasks, only this sequence must be specified.
text_b: (Optional) string. The untokenized text of the second sequence.
Only must be specified for sequence pair tasks.
label: (Optional) string. The label of the example. This should be
specified for train and dev examples, but not for test examples.


def _use_gl(objs):

    from ..models.plots import Plot
    return _any(objs, lambda obj: isinstance(obj, Plot) and obj.output_backend == "webgl")

Whether a collection of Bokeh objects contains a plot requesting WebGL

Args:
objs (seq[Model or Document]) :

Returns:
bool


def _encode_slice_definition(self, root_builder: expressions.Builder, slice_: _fhir_path_data_types.Slice) -> List[validation_pb2.SqlRequirement]:
    if slice_.relative_path:
        slice_builder = self._get_new_child_builder(root_builder, slice_.relative_path)
    else:
        slice_builder = root_builder
    if slice_builder is None:
        return []
    element_constraints = []
    for rule_path, rule_def in slice_.slice_rules:
        if not rule_def.HasField('fixed') and (not rule_def.HasField('pattern')):
            continue
        slice_element_builder = root_builder
        for path_component in rule_path.split('.'):
            slice_element_builder = slice_element_builder.__getattr__(path_component)
            if slice_element_builder.return_type.returns_polymorphic():
                type_codes = _utils.element_type_codes(slice_element_builder.return_type.root_element_definition)
                if len(type_codes) > 1:
                    self._error_reporter.report_fhir_path_error(cast(Any, rule_def).path.value, str(slice_element_builder), f'Element `{slice_element_builder}` in slice `{cast(Any, slice_.slice_def).id.value}` is a choice type with more than one choice which is not currently supported.')
                    return []
                slice_element_builder = slice_element_builder.ofType(type_codes[0])
        fixed_constraint = self._constraint_for_fixed_slice_element(slice_element_builder, rule_def)
        if fixed_constraint is not None:
            element_constraints.append(fixed_constraint)
        pattern_constraint = self._constraint_for_pattern_slice_element(slice_element_builder, rule_def)
        if pattern_constraint is not None:
            element_constraints.append(pattern_constraint)
    if not element_constraints:
        return []
    element_predicate = functools.reduce(operator.and_, element_constraints)
    elements_in_slice = slice_builder.where(element_predicate)
    slice_constraints = []
    min_size: int = cast(Any, slice_.slice_def).min.value
    max_size: str = cast(Any, slice_.slice_def).max.value
    if str(min_size) == max_size:
        slice_constraints.append(elements_in_slice.count() == min_size)
    else:
        if min_size == 1:
            slice_constraints.append(elements_in_slice.exists())
        elif min_size > 1:
            slice_constraints.append(elements_in_slice.count() >= min_size)
        if max_size.isdigit():
            slice_constraints.append(elements_in_slice.count() <= int(max_size))
    if not slice_constraints:
        return []
    slice_constraint = functools.reduce(operator.and_, slice_constraints)
    constraint_sql = self._encode_fhir_path_builder_constraint(slice_constraint, None)
    if constraint_sql is None:
        return []
    slice_id = cast(Any, slice_.slice_def).id.value
    slice_path = self._abs_path_invocation(root_builder)
    slice_name = cast(Any, slice_.slice_def).slice_name.value
    column_name = f'{_path_to_sql_column_name(slice_path)}_{_path_to_sql_column_name(slice_id)}_slice_cardinality'
    description = f'Slice {slice_id} requires at least {min_size} and at most {max_size} elements in {slice_builder} to conform to slice {slice_name}.'
    return [validation_pb2.SqlRequirement(column_name=column_name, sql_expression=constraint_sql.sql, fhir_path_sql_expression=constraint_sql.fhir_path_sql, severity=validation_pb2.ValidationSeverity.SEVERITY_ERROR, type=validation_pb2.ValidationType.VALIDATION_TYPE_CARDINALITY, element_path=root_builder.node.get_root_node().to_fhir_path(), description=description, fhir_path_key=column_name.replace('_', '-'), fhir_path_expression=constraint_sql.builder.fhir_path, fields_referenced_by_expression=sorted(constraint_sql.builder.node.find_paths_referenced()))]

Encodes constraints for slices.

Args:
root_builder: The builder representing a path to the structure definition
defining the slice.
slice_: A slice defined by the structure definition at `root_builder`.

Returns:
A constraint enforcing the cardinality of `slice_` if `slice_` imposes a
non-zero or non-* min or max cardinality. Otherwise, an empty list.


def Convert(self, metadata, stat_entry, token=None):

    if stat_entry.pathspec.pathtype != rdf_paths.PathSpec.PathType.REGISTRY:
      return []

    result = ExportedRegistryKey(
        metadata=metadata,
        urn=stat_entry.AFF4Path(metadata.client_urn),
        last_modified=stat_entry.st_mtime)

    if (stat_entry.HasField("registry_type") and
        stat_entry.HasField("registry_data")):

      result.type = stat_entry.registry_type

      data = stat_entry.registry_data.GetValue()
      if isinstance(data, bytes):
        result.data = data
      else:
        result.data = str(data).encode("utf-8")

    return [result]

Converts StatEntry to ExportedRegistryKey.

Does nothing if StatEntry corresponds to a file and not a registry entry.

Args:
metadata: ExportedMetadata to be used for conversion.
stat_entry: StatEntry to be converted.
token: Security token.

Returns:
List or generator with resulting RDFValues. Empty list if StatEntry
corresponds to a file and not to a registry entry.


def __init__(self, on_exception=Exception, limit=5, interval=None,
                 validator=None):

        self.attempts = 0
        self._on_exception = on_exception

        self._setup_limit(limit)
        self._setup_interval(interval)
        self._setup_validator(validator)

Configure how a function should be retried.

Args:
on_exception (BaseException): The exception to catch. Use this to
set which exception and it's subclasses to catch.
limit ()


def _handle_agg_function(gb, agg_func, agg_name, *args, **kwargs):
    if _is_associative(agg_func):
        return _liftable_agg(agg_func)(gb, *args, **kwargs)
    elif _is_liftable_with_sum(agg_func):
        return _liftable_agg(agg_func, postagg_meth='sum')(gb, *args, **kwargs)
    elif _is_unliftable(agg_func):
        return _unliftable_agg(agg_func)(gb, *args, **kwargs)
    elif callable(agg_func):
        return DeferredDataFrame(expressions.ComputedExpression(agg_name, lambda gb_val: gb_val.agg(agg_func, *args, **kwargs), [gb._expr], requires_partition_by=partitionings.Index(), preserves_partition_by=partitionings.Singleton()))
    else:
        raise NotImplementedError(f'GroupBy.agg(func={agg_func!r})')

Handles the aggregation logic based on the function type passed.

Args:
gb: The groupby instance (DeferredGroupBy).
agg_name: The name/label of the aggregation function.
fn: The aggregation function to apply.
*args: Additional arguments to pass to the aggregation function.
**kwargs: Keyword arguments to pass to the aggregation function.

Returns:
A DeferredDataFrame or the result of the aggregation function.

Raises:
NotImplementedError: If the aggregation function type is unsupported.


def register_ops_if_needed(graph_ops):
    missing_ops = (graph_ops - set(op_def_registry.get_registered_ops().keys()))
    if (not missing_ops):
        return
    p_buffer = c_api.TF_GetAllOpList()
    cpp_op_list = op_def_pb2.OpList()
    cpp_op_list.ParseFromString(c_api.TF_GetBuffer(p_buffer))
    cpp_registry_ops = {op.name: op for op in cpp_op_list.op}
    missing_op_list = op_def_pb2.OpList()
    for missing_op in missing_ops:
        if (missing_op not in cpp_registry_ops):
            logging.info('Op %s is missing from both the python and C++ registry.', missing_op)
        else:
            missing_op_list.op.extend([cpp_registry_ops[missing_op]])
            logging.info('Adding op %s from c++ registry to python registry.', missing_op)
    op_def_registry.register_op_list(missing_op_list)
    if (not (missing_ops <= set(cpp_registry_ops.keys()))):
        raise RuntimeError(('Graph ops missing from the python registry (%s) are also absent from the c++ registry.' % missing_ops.difference(set(cpp_registry_ops.keys()))))

Register graph ops absent in op_def_registry, if present in c++ registry.

Args:
graph_ops: set with graph op names to register.

Raises:
RuntimeError: if `graph_ops` contains ops that are not in either python or
c++ registry.


async def dist(self, mesg):

        if self.isfini:
            return ()

        ret = []
        for func in self._syn_funcs.get(mesg[0], ()):

            try:
                ret.append(await s_coro.ornot(func, mesg))
            except asyncio.CancelledError:
                raise
            except Exception:
                logger.exception('base %s error with mesg %s', self, mesg)

        for func in self._syn_links:
            try:
                ret.append(await func(mesg))
            except asyncio.CancelledError:
                raise
            except Exception:
                logger.exception('base %s error with mesg %s', self, mesg)

        return ret

Distribute an existing event tuple.

Args:
mesg ((str,dict)):  An event tuple.

Example:

await base.dist( ('foo',{'bar':'baz'}) )


def extract_tree_with(self, labels, suppress_unifurcations=True):
    return self.extract_tree(labels, False, suppress_unifurcations)

Extract a copy of this ``Tree`` with only the leaves labeled by the strings in ``labels``

Args:
``leaves`` (``set``): Set of leaf labels to include.

``suppress_unifurcations`` (``bool``): ``True`` to suppress unifurcations, otherwise ``False``

Returns:
Tree: Copy of this Tree, including only the leaves labeled by the strings in ``labels``


def _clone_layers_and_model_config(model, input_layers, layer_fn):
    created_layers = {}

    def _copy_layer(layer):
        if layer in input_layers:
            created_layers[layer.name] = input_layers[layer]
        elif layer in model._input_layers:
            created_layers[layer.name] = InputLayer(**layer.get_config())
        else:
            created_layers[layer.name] = layer_fn(layer)
        return {}
    config = functional.get_network_config(model, serialize_layer_fn=_copy_layer)
    return (config, created_layers)

Clones all layers, and returns the model config without serializing layers.

This function ensures that only the node graph is retrieved when getting the
model config. The `layer_fn` used to clone layers might not rely on
`layer.get_config()`, so some custom layers do not define `get_config`.
Trying to retrieve the config results in errors.

Args:
model: A Functional model.
input_layers: Dictionary mapping input layers in `model` to new input layers
layer_fn: Function used to clone all non-input layers.

Returns:
Model config object, and a dictionary of newly created layers.


def _convert_validators_to_mapping(validators):
    validators_mapping = {}
    for validator in validators:
        if (not isinstance(validator['check'], collections.Hashable)):
            check = json.dumps(validator['check'])
        else:
            check = validator['check']
        key = (check, validator['comparator'])
        validators_mapping[key] = validator
    return validators_mapping

convert validators list to mapping.

Args:
validators (list): validators in list

Returns:
dict: validators mapping, use (check, comparator) as key.

Examples:
>>> validators = [
{"check": "v1", "expect": 201, "comparator": "eq"},
{"check": {"b": 1}, "expect": 200, "comparator": "eq"}
]
>>> _convert_validators_to_mapping(validators)
{
("v1", "eq"): {"check": "v1", "expect": 201, "comparator": "eq"},
('{"b": 1}', "eq"): {"check": {"b": 1}, "expect": 200, "comparator": "eq"}
}


def get(self, secret_id):
    return self.prepare_model(self.client.api.inspect_secret(secret_id))

Get a secret.

Args:
secret_id (str): Secret ID.

Returns:
(:py:class:`Secret`): The secret.

Raises:
:py:class:`docker.errors.NotFound`
If the secret does not exist.
:py:class:`docker.errors.APIError`
If the server returns an error.


def filing_history(self, num, transaction=None, **kwargs):

        baseuri = self._BASE_URI + "company/{}/filing-history".format(num)
        if transaction is not None:
            baseuri += "/{}".format(transaction)
        res = self.session.get(baseuri, params=kwargs)
        self.handle_http_error(res)
        return res

Search for a company's filling history by company number.

Args:
num (str): Company number to search on.

transaction (Optional[str]): Filing record number.
kwargs (dict): additional keywords passed into
requests.session.get params keyword.


def binary_arguments_to_tensors(x1, x2):

  if not isinstance(x1, Tensor) and not isinstance(x2, Tensor):
    raise ValueError("at least one of x1 and x2 must be an mtf Tensor")
  elif isinstance(x1, Tensor) and isinstance(x2, Tensor):
    return x1, x2
  elif isinstance(x1, Tensor):
    return x1, import_tf_tensor(
        x1.mesh, tf.convert_to_tensor(x2, dtype=x1.dtype), Shape([]))
  else:
    return import_tf_tensor(x2.mesh, tf.convert_to_tensor(x1, dtype=x2.dtype),
                            Shape([])), x2

Convert argument of a binary operation to Tensors.

Args:
x1: a Tensor or something convertible to a tf Scalar
x2: a Tensor or something convertible to a tf Scalar

Returns:
new_x1: a Tensor
new_x2: a Tensor

Raises:
ValueError: on failure


def _stride(stride_spec):

  if stride_spec is None:
    return [1, 1, 1, 1]
  elif isinstance(stride_spec, tf.compat.integral_types):
    return [1, stride_spec, stride_spec, 1]
  elif len(stride_spec) == 1:
    return [1, stride_spec[0], stride_spec[0], 1]
  elif len(stride_spec) == 2:
    return [1, stride_spec[0], stride_spec[1], 1]
  else:
    assert len(stride_spec) == 4
    return stride_spec

Expands the stride spec into a length 4 list.

Args:
stride_spec: If length 0, 1 or 2 then assign the inner dimensions, otherwise
return stride_spec if it is length 4.
Returns:
A length 4 list.


def to_str(self, separator=''):
    if self.closed():
        raise ValueError('Attempt to call to_str() on a closed Queryable.')
    return str(separator).join(self.select(str))

Build a string from the source sequence.

The elements of the query result will each coerced to a string and then
the resulting strings concatenated to return a single string. This
allows the natural processing of character sequences as strings. An
optional separator which will be inserted between each item may be
specified.

Note: this method uses immediate execution.

Args:
separator: An optional separator which will be coerced to a string
and inserted between each source item in the resulting string.

Returns:
A single string which is the result of stringifying each element
and concatenating the results into a single string.

Raises:
TypeError: If any element cannot be coerced to a string.
TypeError: If the separator cannot be coerced to a string.
ValueError: If the Queryable is closed.


def properties(self, value):

        if value == self._defaults['properties'] and 'properties' in self._values:
            del self._values['properties']
        else:
            self._values['properties'] = value

The properties property.

Args:
value (hash). the property value.


def report_line(zipfilename: str, contentsfilename: str, line: str,
                show_inner_file: bool) -> None:

    if show_inner_file:
        print("{} [{}]: {}".format(zipfilename, contentsfilename, line))
    else:
        print("{}: {}".format(zipfilename, line))

Prints a line from a file, with the ``.zip`` filename and optionally also
the inner filename.

Args:
zipfilename: filename of the ``.zip`` file
contentsfilename: filename of the inner file
line: the line from the inner file
show_inner_file: if ``True``, show both filenames; if ``False``, show
just the ``.zip`` filename


def _send(self, **req_kwargs):

        auth_token = self._auth.getAuthToken()
        if auth_token is None:
            raise exception.LoginException('Not logged in')

        req_kwargs.setdefault('headers', {
            'Authorization': 'OAuth ' + auth_token
        })

        return self._session.request(**req_kwargs)

Send an authenticated request to a Google API.

Args:
**req_kwargs: Arbitrary keyword arguments to pass to Requests.

Return:
requests.Response: The raw response.

Raises:
LoginException: If :py:meth:`login` has not been called.


def _CheckGrayscaleImage(image, require_static=True):
    try:
        if image.get_shape().ndims is None:
            image_shape = image.get_shape().with_rank(2)
        else:
            image_shape = image.get_shape().with_rank_at_least(2)
    except ValueError:
        raise ValueError('A grayscale image (shape %s) must be at least two-dimensional.' % image.shape)
    if require_static and (not image_shape.is_fully_defined()):
        raise ValueError("'image' must be fully defined.")
    if image_shape.is_fully_defined():
        if image_shape[-1] != 1:
            raise ValueError('Last dimension of a grayscale image should be size 1.')
    if not image_shape.is_fully_defined():
        return [check_ops.assert_equal(array_ops.shape(image)[-1], 1, message='Last dimension of a grayscale image should be size 1.'), check_ops.assert_greater_equal(array_ops.rank(image), 3, message='A grayscale image must be at least two-dimensional.')]
    else:
        return []

Assert that we are working with properly shaped grayscale image.

Args:
image: >= 2-D Tensor of size [*, 1]
require_static: Boolean, whether static shape is required.

Raises:
ValueError: if image.shape is not a [>= 2] vector or if
last dimension is not size 1.

Returns:
An empty list, if `image` has fully defined dimensions. Otherwise, a list
containing an assert op is returned.


def post_process_video_grounding(self, logits, video_durations):
    start, end = (round(logits.tolist()[0][0] * video_durations, 1), round(logits.tolist()[0][1] * video_durations, 1))
    return (start, end)

Compute the time of the video.

Args:
logits (`torch.Tensor`):
The logits output of TvpForVideoGrounding.
video_durations (`float`):
The video's duration.

Returns:
start (`float`):
The start time of the video.
end (`float`):
The end time of the video.


def get_commit_tree(profile, sha):

    data = commits.get_commit(profile, sha)
    tree = data.get("tree")
    sha = tree.get("sha")
    return sha

Get the SHA of a commit's tree.

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.

sha
The SHA of a commit.

Returns:
The SHA of the commit's tree.


def diffusion_mds(means, weights, d, diffusion_rounds=10):
    for i in range(diffusion_rounds):
        weights = (weights * weights)
        weights = (weights / weights.sum(0))
    X = dim_reduce(means, weights, d)
    if (X.shape[0] == 2):
        return X.dot(weights)
    else:
        return X.T.dot(weights)

Dimensionality reduction using MDS, while running diffusion on W.

Args:
means (array): genes x clusters
weights (array): clusters x cells
d (int): desired dimensionality

Returns:
W_reduced (array): array of shape (d, cells)


def WaitUntilDone(self, timeout=None):

    utils.Poll(
        generator=self.GetState,
        condition=lambda s: s != self.__class__.STATE_RUNNING,
        timeout=timeout)
    self.target_file = self.target_file.Get()
    return self

Wait until the operation is done.

Args:
timeout: timeout in seconds. None means default timeout (1 hour).
0 means no timeout (wait forever).
Returns:
Operation object with refreshed target_file.
Raises:
PollTimeoutError: if timeout is reached.


def _compile_arithmetic_expression(self,
                                       expr: Expression,
                                       scope: Dict[str, TensorFluent],
                                       batch_size: Optional[int] = None,
                                       noise: Optional[List[tf.Tensor]] = None) -> TensorFluent:

        etype = expr.etype
        args = expr.args

        if len(args) == 1:
            etype2op = {
                '+': lambda x: x,
                '-': lambda x: -x
            }

            if etype[1] not in etype2op:
                raise ValueError('Invalid binary arithmetic expression:\n{}'.format(expr))

            op = etype2op[etype[1]]
            x = self._compile_expression(args[0], scope, batch_size, noise)
            fluent = op(x)

        else:
            etype2op = {
                '+': lambda x, y: x + y,
                '-': lambda x, y: x - y,
                '*': lambda x, y: x * y,
                '/': lambda x, y: x / y,
            }

            if etype[1] not in etype2op:
                raise ValueError('Invalid binary arithmetic expression:\n{}'.format(expr))

            op = etype2op[etype[1]]
            x = self._compile_expression(args[0], scope, batch_size, noise)
            y = self._compile_expression(args[1], scope, batch_size, noise)
            fluent = op(x, y)

        return fluent

Compile an arithmetic expression `expr` into a TensorFluent
in the given `scope` with optional batch size.

Args:
expr (:obj:`rddl2tf.expr.Expression`): A RDDL arithmetic expression.
scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope.
batch_size (Optional[size]): The batch size.

Returns:
:obj:`rddl2tf.fluent.TensorFluent`: The compiled expression as a TensorFluent.


def _check_etag(self, etag):
    if (etag is None):
        return
    elif (self._etag is None):
        self._etag = etag
    elif (self._etag != etag):
        raise ValueError('File on GCS has changed while reading.')

Check if etag is the same across requests to GCS.

If self._etag is None, set it. If etag is set, check that the new
etag equals the old one.

In the __init__ method, we fire one HEAD and one GET request using
ndb tasklet. One of them would return first and set the first value.

Args:
etag: etag from a GCS HTTP response. None if etag is not part of the
response header. It could be None for example in the case of GCS
composite file.

Raises:
ValueError: if two etags are not equal.


def stop_site(name):
    ps_cmd = ['Stop-WebSite', "'{0}'".format(name)]
    cmd_ret = _srvmgr(ps_cmd)
    return (cmd_ret['retcode'] == 0)

Stop a Web Site in IIS.

.. versionadded:: 2017.7.0

Args:
name (str): The name of the website to stop.

Returns:
bool: True if successful, otherwise False

CLI Example:

.. code-block:: bash

salt '*' win_iis.stop_site name='My Test Site'


def assignSchedule(self, schedule, period, hour, minute, tariff):
    if ((schedule not in range(Extents.Schedules)) or (period not in range(Extents.Tariffs)) or (hour < 0) or (hour > 23) or (minute < 0) or (minute > 59) or (tariff < 0)):
        ekm_log(('Out of bounds in Schedule_' + str((schedule + 1))))
        return False
    period += 1
    idx_min = ('Min_' + str(period))
    idx_hour = ('Hour_' + str(period))
    idx_rate = ('Tariff_' + str(period))
    if (idx_min not in self.m_schedule_params):
        ekm_log(('Incorrect index: ' + idx_min))
        return False
    if (idx_hour not in self.m_schedule_params):
        ekm_log(('Incorrect index: ' + idx_hour))
        return False
    if (idx_rate not in self.m_schedule_params):
        ekm_log(('Incorrect index: ' + idx_rate))
        return False
    self.m_schedule_params[idx_rate] = tariff
    self.m_schedule_params[idx_hour] = hour
    self.m_schedule_params[idx_min] = minute
    self.m_schedule_params['Schedule'] = schedule
    return True

Assign one schedule tariff period to meter bufffer.

Args:
schedule (int): A :class:`~ekmmeters.Schedules` value or in range(Extents.Schedules).
tariff (int): :class:`~ekmmeters.Tariffs` value or in range(Extents.Tariffs).
hour (int): Hour from 0-23.
minute (int): Minute from 0-59.
tariff (int): Rate value.

Returns:
bool: True on completed assignment.


def disease_term(self, disease_identifier):
    query = {}
    try:
        disease_identifier = int(disease_identifier)
        query['disease_nr'] = disease_identifier
    except ValueError:
        query['_id'] = disease_identifier
    return self.disease_term_collection.find_one(query)

Return a disease term

Checks if the identifier is a disease number or a id

Args:
disease_identifier(str)

Returns:
disease_obj(dict)


def get_pool_context(self):
    context = {self.current.lane_id: self.current.role, 'self': self.current.role}
    for (lane_id, role_id) in self.current.pool.items():
        if role_id:
            context[lane_id] = lazy_object_proxy.Proxy((lambda : self.role_model(super_context).objects.get(role_id)))
    return context

Builds context for the WF pool.

Returns:
Context dict.


def semantic_eq(node1, node2):

        if 'barrier' == node1.name == node2.name:
            return set(node1.qargs) == set(node2.qargs)
        return node1.data_dict == node2.data_dict

Check if DAG nodes are considered equivalent, e.g. as a node_match for nx.is_isomorphic.

Args:
node1 (DAGNode): A node to compare.
node2 (DAGNode): The other node to compare.

Return:
Bool: If node1 == node2


def match(self, name):

        if self.method == Ex.Method.PREFIX:
            return name.startswith(self.value)
        elif self.method == Ex.Method.SUFFIX:
            return name.endswith(self.value)
        elif self.method == Ex.Method.CONTAINS:
            return self.value in name
        elif self.method == Ex.Method.EXACT:
            return self.value == name
        elif self.method == Ex.Method.REGEX:
            return re.search(self.value, name)
        return False

Check if given name matches.

Args:
name (str): name to check.

Returns:
bool: matches name.


class Rescaling(TFDataLayer):

    def __init__(self, scale, offset=0.0, **kwargs):
        super().__init__(**kwargs)
        self.scale = scale
        self.offset = offset
        self.supports_masking = True

    def call(self, inputs):
        dtype = self.compute_dtype
        scale = self.backend.cast(self.scale, dtype)
        offset = self.backend.cast(self.offset, dtype)
        scale_shape = self.backend.core.shape(scale)
        if len(scale_shape) > 0 and backend.image_data_format() == 'channels_first':
            scale = self.backend.numpy.reshape(scale, scale_shape + (1,) * (3 - len(scale_shape)))
        return self.backend.cast(inputs, dtype) * scale + offset

    def compute_output_shape(self, input_shape):
        return input_shape

    def get_config(self):
        config = super().get_config()
        config.update({'scale': serialization_lib.serialize_keras_object(self.scale), 'offset': serialization_lib.serialize_keras_object(self.offset)})
        return config

    @classmethod
    def from_config(cls, config, custom_objects=None):
        config = config.copy()
        config['scale'] = serialization_lib.deserialize_keras_object(config['scale'], custom_objects=custom_objects)
        config['offset'] = serialization_lib.deserialize_keras_object(config['offset'], custom_objects=custom_objects)
        return cls(**config)

A preprocessing layer which rescales input values to a new range.

This layer rescales every value of an input (often an image) by multiplying
by `scale` and adding `offset`.

For instance:

1. To rescale an input in the `[0, 255]` range
to be in the `[0, 1]` range, you would pass `scale=1./255`.

2. To rescale an input in the `[0, 255]` range to be in the `[-1, 1]` range,
you would pass `scale=1./127.5, offset=-1`.

The rescaling is applied both during training and inference. Inputs can be
of integer or floating point dtype, and by default the layer will output
floats.

**Note:** This layer is safe to use inside a `tf.data` pipeline
(independently of which backend you're using).

Args:
scale: Float, the scale to apply to the inputs.
offset: Float, the offset to apply to the inputs.
**kwargs: Base layer keyword arguments, such as `name` and `dtype`.


def render(self, container, descender, state, space_below=0, first_line_only=False):
    indent_first = (float(self.get_style('indent_first', container)) if state.initial else 0)
    line_width = float(container.width)
    line_spacing = self.get_style('line_spacing', container)
    text_align = self.get_style('text_align', container)
    tab_stops = self.get_style('tab_stops', container)
    if (not tab_stops):
        tab_width = (2 * self.get_style('font_size', container))
        tab_stops = DefaultTabStops(tab_width)
    saved_state = copy(state)
    prev_state = copy(state)
    max_line_width = 0

    def typeset_line(line, last_line=False):
        "Typeset `line` and, if no exception is raised, update the\n            paragraph's internal rendering state."
        nonlocal state, saved_state, max_line_width, descender, space_below
        max_line_width = max(max_line_width, line.cursor)
        advance = (line.ascender(container) if (descender is None) else line_spacing.advance(line, descender, container))
        descender = line.descender(container)
        line.advance = advance
        total_advance = ((advance + (space_below if last_line else 0)) - descender)
        if (container.remaining_height < total_advance):
            raise EndOfContainer(saved_state)
        assert container.advance2(advance)
        line.typeset(container, text_align, last_line)
        assert container.advance2((- descender))
        state.initial = False
        saved_state = copy(state)
        return Line(tab_stops, line_width, container, significant_whitespace=self.significant_whitespace)
    first_line = line = Line(tab_stops, line_width, container, indent_first, self.significant_whitespace)
    while True:
        try:
            word = state.next_word()
        except StopIteration:
            break
        try:
            if (not line.append_word(word)):
                for (first, second) in word.hyphenate(container):
                    if line.append_word(first):
                        state.prepend_word(second)
                        break
                else:
                    state = prev_state
                line = typeset_line(line)
                if first_line_only:
                    break
                continue
        except NewLineException:
            line.append(word.glyphs_span)
            line = typeset_line(line, last_line=True)
            if first_line_only:
                break
        prev_state = copy(state)
    if line:
        typeset_line(line, last_line=True)
    if (self._width(container) == FlowableWidth.AUTO):
        if (text_align == TextAlign.CENTER):
            container.left -= (float((container.width - max_line_width)) / 2)
        if (text_align == TextAlign.RIGHT):
            container.left -= float((container.width - max_line_width))
    return (max_line_width, first_line.advance, descender)

Typeset the paragraph

The paragraph is typeset in the given container starting below the
current cursor position of the container. When the end of the container
is reached, the rendering state is preserved to continue setting the
rest of the paragraph when this method is called with a new container.

Args:
container (Container): the container to render to
descender (float or None): descender height of the preceeding line
state (ParagraphState): the state where rendering will continue
first_line_only (bool): typeset only the first line


def __init__(self, sender, persistence_path=''):

        if persistence_path and PersistQueue is None:
            raise ValueError('persistence_path argument requires persist-queue dependency to be installed')
        elif persistence_path:
            self._queue = PersistQueue(persistence_path)
        else:
            self._queue = Queue()

        self._persistence_path = persistence_path
        self._max_queue_length = 500
        self._sender = sender
        if sender:
            self._sender.queue = self

Initializes a new instance of the class.

Args:
sender (:class:`SenderBase`) the sender object that will be used in conjunction with this queue.
persistence_path (str) if set, persist the queue on disk into the provided directory.


def __init__(self, output_path, open_function=open):
    self._output_path = output_path
    self._open_function = open_function
    self._old_enabled = None

Initialize.

Args:
output_path: The path for the metrics data.  If empty, no metrics are
collected.
open_function: A custom file opening function.


def get_credentials(self):
    return ReadOnlyCredentials(self.access_token, self.client_id, self.client_secret, self.refresh_token)

Get read-only credentials.

Returns:
class: Read-only credentials.


def set(self, option, value=None):

        option = self._container.optionxform(option)
        if option in self.options():
            self.__getitem__(option).value = value
        else:
            self.__setitem__(option, value)
        return self

Set an option for chaining.

Args:
option (str): option name
value (str): value, default None


def measures(*measurements, **kwargs):

    def _maybe_make(meas):
        'Turn strings into Measurement objects if necessary.'
        if isinstance(meas, Measurement):
            return meas
        elif isinstance(meas, six.string_types):
            return Measurement(meas, **kwargs)
        raise InvalidMeasurementType('Expected Measurement or string', meas)
    if (kwargs and (len(measurements) != 1)):
        raise InvalidMeasurementType('If @measures kwargs are provided, a single measurement name must be provided as a positional arg first.')
    if ('outcome' in kwargs):
        raise ValueError('Cannot specify outcome in measurement declaration!')
    measurements = [_maybe_make(meas) for meas in measurements]

    def decorate(wrapped_phase):
        'Phase decorator to be returned.'
        phase = phase_descriptor.PhaseDescriptor.wrap_or_copy(wrapped_phase)
        duplicate_names = (set((m.name for m in measurements)) & set((m.name for m in phase.measurements)))
        if duplicate_names:
            raise DuplicateNameError('Measurement names duplicated', duplicate_names)
        phase.measurements.extend(measurements)
        return phase
    return decorate

Decorator-maker used to declare measurements for phases.

See the measurements module docstring for examples of usage.

Args:
measurements: Measurement objects to declare, or a string name from which
to create a Measurement.
kwargs: Keyword arguments to pass to Measurement constructor if we're
constructing one.  Note that if kwargs are provided, the length
of measurements must be 1, and that value must be a string containing
the measurement name.  For valid kwargs, see the definition of the
Measurement class.

Returns:
A decorator that declares the measurement(s) for the decorated phase.


def _parse_request_arguments(self, request):
    inference_addresses = request.args.get('inference_address').split(',')
    model_names = request.args.get('model_name').split(',')
    model_versions = request.args.get('model_version').split(',')
    model_signatures = request.args.get('model_signature').split(',')
    if (len(model_names) != len(inference_addresses)):
        raise common_utils.InvalidUserInputError(('Every model should have a ' + 'name and address.'))
    return (inference_addresses, model_names, model_versions, model_signatures)

Parses comma separated request arguments

Args:
request: A request that should contain 'inference_address', 'model_name',
'model_version', 'model_signature'.

Returns:
A tuple of lists for model parameters


def get_terminal_size():
    try:
        from IPython import get_ipython
        ipython = get_ipython()
        from ipykernel import zmqshell
        if isinstance(ipython, zmqshell.ZMQInteractiveShell):
            return (79, 24)
    except Exception:
        pass
    try:
        import shutil
        (w, h) = shutil.get_terminal_size()
        if (w and h):
            return ((w - 1), h)
    except Exception:
        pass
    try:
        w = int(os.environ.get('COLUMNS'))
        h = int(os.environ.get('LINES'))
        if (w and h):
            return (w, h)
    except Exception:
        pass
    try:
        import blessings
        terminal = blessings.Terminal()
        w = terminal.width
        h = terminal.height
        if (w and h):
            return (w, h)
    except Exception:
        pass
    try:
        (w, h) = _get_terminal_size_linux()
        if (w and h):
            return (w, h)
    except Exception:
        pass
    try:
        (w, h) = _get_terminal_size_windows()
        if (w and h):
            return (w, h)
    except Exception:
        pass
    try:
        (w, h) = _get_terminal_size_tput()
        if (w and h):
            return (w, h)
    except Exception:
        pass
    return (79, 24)

Get the current size of your terminal

Multiple returns are not always a good idea, but in this case it greatly
simplifies the code so I believe it's justified. It's not the prettiest
function but that's never really possible with cross-platform code.

Returns:
width, height: Two integers containing width and height


def find_mip(self, direction, mechanism, purview, allow_neg=False):
    alpha_min = float('inf')
    probability = self.probability(direction, mechanism, purview)
    for partition in mip_partitions(mechanism, purview, self.node_labels):
        partitioned_probability = self.partitioned_probability(direction, partition)
        alpha = log2((probability / partitioned_probability))
        if (utils.eq(alpha, 0) or ((alpha < 0) and (not allow_neg))):
            return AcRepertoireIrreducibilityAnalysis(state=self.mechanism_state(direction), direction=direction, mechanism=mechanism, purview=purview, partition=partition, probability=probability, partitioned_probability=partitioned_probability, node_labels=self.node_labels, alpha=0.0)
        if ((abs(alpha_min) - abs(alpha)) > constants.EPSILON):
            alpha_min = alpha
            acria = AcRepertoireIrreducibilityAnalysis(state=self.mechanism_state(direction), direction=direction, mechanism=mechanism, purview=purview, partition=partition, probability=probability, partitioned_probability=partitioned_probability, node_labels=self.node_labels, alpha=alpha_min)
    return acria

Find the ratio minimum information partition for a mechanism
over a purview.

Args:
direction (str): |CAUSE| or |EFFECT|
mechanism (tuple[int]): A mechanism.
purview (tuple[int]): A purview.

Keyword Args:
allow_neg (boolean): If true, ``alpha`` is allowed to be negative.
Otherwise, negative values of ``alpha`` will be treated as if
they were 0.

Returns:
AcRepertoireIrreducibilityAnalysis: The irreducibility analysis for
the mechanism.


def del_hparam(self, name):
    if hasattr(self, name):
        delattr(self, name)
        del self._hparam_types[name]

Removes the hyperparameter with key 'name'.

Does nothing if it isn't present.

Args:
name: Name of the hyperparameter.


def __squid_to_guid(self, squid):

        if not squid:
            return ''
        squid_match = self.__squid_pattern.match(squid)
        guid = ''
        if squid_match is not None:
            guid = '{' +\
                squid_match.group(1)[::-1]+'-' +\
                squid_match.group(2)[::-1]+'-' +\
                squid_match.group(3)[::-1]+'-' +\
                squid_match.group(4)[::-1]+squid_match.group(5)[::-1] + '-'
            for index in range(6, 12):
                guid += squid_match.group(index)[::-1]
            guid += '}'
        return guid

Squished GUID (SQUID) to GUID.

A SQUID is a Squished/Compressed version of a GUID to use up less space
in the registry.

Args:
squid (str): Squished GUID.

Returns:
str: the GUID if a valid SQUID provided.


def persist_experiment(experiment):

    from benchbuild.utils.schema import Experiment, Session

    session = Session()

    cfg_exp = experiment.id
    LOG.debug("Using experiment ID stored in config: %s", cfg_exp)
    exps = session.query(Experiment).filter(Experiment.id == cfg_exp)
    desc = str(CFG["experiment_description"])
    name = experiment.name

    if exps.count() == 0:
        newe = Experiment()
        newe.id = cfg_exp
        newe.name = name
        newe.description = desc
        session.add(newe)
        ret = newe
    else:
        exps.update({'name': name, 'description': desc})
        ret = exps.first()

    try:
        session.commit()
    except IntegrityError:
        session.rollback()
        persist_experiment(experiment)

    return (ret, session)

Persist this experiment in the benchbuild database.

Args:
experiment: The experiment we want to persist.


def __init__(self):

        super(JLinkSpeedInfo, self).__init__()
        self.SizeOfStruct = ctypes.sizeof(self)

Initializes the ``JLinkSpeedInfo`` instance.

Sets the size of the structure.

Args:
self (JLinkSpeedInfo): the ``JLinkSpeedInfo`` instance

Returns:
``None``


def connect_sync(self, connection_id, connection_string):
    calldone = threading.Event()
    results = {}

    def connect_done(callback_connid, callback_adapterid, callback_success, failure_reason):
        results['success'] = callback_success
        results['failure_reason'] = failure_reason
        calldone.set()
    self.connect_async(connection_id, connection_string, connect_done)
    calldone.wait()
    return results

Synchronously connect to a device

Args:
connection_id (int): A unique identifier that will refer to this connection
connection_string (string): A DeviceAdapter specific string that can be used to connect to
a device using this DeviceAdapter.

Returns:
dict: A dictionary with two elements
'success': a bool with the result of the connection attempt
'failure_reason': a string with the reason for the failure if we failed


def _get_programs_dict():
    global __programs_dict
    if (__programs_dict is not None):
        return __programs_dict
    d = __programs_dict = OrderedDict()
    for pkgname in COLLABORATORS_S:
        try:
            package = importlib.import_module(pkgname)
        except ImportError:
            continue
        path_ = os.path.join(os.path.split(package.__file__)[0], 'scripts')
        bulk = a99.get_exe_info(path_, flag_protected=True)
        d[pkgname] = {'description': a99.get_obj_doc0(package), 'exeinfo': bulk}
    return __programs_dict

Builds and returns programs dictionary

This will have to import the packages in COLLABORATORS_S in order to get their absolute path.

Returns:
dictionary: {"packagename": [ExeInfo0, ...], ...}

"packagename" examples: "f311.explorer", "numpy"


def add_comment(self, line):
    if (not isinstance(self.last_item, Comment)):
        comment = Comment(self._structure)
        self._structure.append(comment)
    self.last_item.add_line(line)
    return self

Add a Comment object to the section

Used during initial parsing mainly

Args:
line (str): one line in the comment


def from_dim_sizes(dim_sizes):
    with ops.name_scope(None, 'RaggedTensorDynamicShapeFromDimensionSizes', [dim_sizes]):
        dim_sizes = tuple((ops.convert_to_tensor(size, preferred_dtype=dtypes.int64, name='dim_sizes') for size in dim_sizes))
        inner_split = 0
        for dim, dim_size in enumerate(dim_sizes):
            if dim_size.shape.ndims == 1:
                inner_split = dim + 1
            elif dim_size.shape.ndims != 0:
                raise ValueError('Each dim_size must be a scalar or a vector')
        return RaggedTensorDynamicShape(dim_sizes[:inner_split], dim_sizes[inner_split:])

Constructs a ragged shape from a list of dimension sizes.

This list contains a single tensor for each dimension, where the tensor
is a scalar if the dimension is uniform, or a vector if the dimension is
ragged.

Args:
dim_sizes: List of int32 or int64 scalars or vectors.

Returns:
A RaggedTensorDynamicShape.


def basis(sample_paths, time_index):
    sample_paths = tf.convert_to_tensor(sample_paths, name='sample_paths')
    if sample_paths.shape.rank == 3:
        sample_paths = tf.expand_dims(sample_paths, axis=0)
    shape = tf.shape(sample_paths)
    num_samples = shape[1]
    batch_size = shape[0]
    dim = sample_paths.shape[-1]
    slice_samples = tf.slice(sample_paths, [0, 0, time_index, 0], [batch_size, num_samples, 1, dim])
    samples_centered = slice_samples - tf.math.reduce_mean(slice_samples, axis=1, keepdims=True)
    grid = tf.range(degree + 1, dtype=samples_centered.dtype)
    grid = tf.meshgrid(*dim * [grid])
    grid = tf.reshape(tf.stack(grid, -1), [-1, dim])
    basis_expansion = tf.reduce_prod(samples_centered ** grid, axis=-1)
    return tf.transpose(basis_expansion, [0, 2, 1])

Computes polynomial basis expansion at the given sample points.

Args:
sample_paths: A `Tensor` of either `flaot32` or `float64` dtype and of
either shape `[num_samples, num_times, dim]` or
`[batch_size, num_samples, num_times, dim]`.
time_index: An integer scalar `Tensor` that corresponds to the time
coordinate at which the basis function is computed.

Returns:
A `Tensor`s of shape `[batch_size, (degree + 1)**dim, num_samples]`.


def TotalFees(self):
    amount = Fixed8.Zero()
    for tx in self.Transactions:
        amount += tx.SystemFee()
    return amount

Get the total transaction fees in the block.

Returns:
Fixed8:


def parse_table_data(lines):
    data = '\n'.join([i.rstrip() for i in lines if ((not i.startswith(('^', '!', '
    if data:
        return read_csv(StringIO(data), index_col=None, sep='\t')
    else:
        return DataFrame()

Parse list of lines from SOFT file into DataFrame.

Args:
lines (:obj:`Iterable`): Iterator over the lines.

Returns:
:obj:`pandas.DataFrame`: Table data.


def depth_soil_density(self, value=None):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError(
                    'value {} need to be of type float '
                    'for field `depth_soil_density`'.format(value))

        self._depth_soil_density = value

Corresponds to IDD Field `depth_soil_density`

Args:
value (float): value for IDD Field `depth_soil_density`
Unit: kg/m3
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 _remove_files(files):

    logger.debug("Request for file removal (_remove_files()).")

    for fn in files:
        if os.path.exists(fn):
            logger.debug("Removing '%s'." % fn)
            os.remove(fn)

Remove all given files.

Args:
files (list): List of filenames, which will be removed.


def set_seed(seed: int, deterministic: bool=False):
    random.seed(seed)
    np.random.seed(seed)
    if is_torch_available():
        torch.manual_seed(seed)
        torch.cuda.manual_seed_all(seed)
        if deterministic:
            torch.use_deterministic_algorithms(True)
    if is_torch_mlu_available():
        torch.mlu.manual_seed_all(seed)
    if is_torch_musa_available():
        torch.musa.manual_seed_all(seed)
    if is_torch_npu_available():
        torch.npu.manual_seed_all(seed)
    if is_torch_hpu_available():
        torch.hpu.manual_seed_all(seed)
    if is_torch_xpu_available():
        torch.xpu.manual_seed_all(seed)
    if is_tf_available():
        import tensorflow as tf
        tf.random.set_seed(seed)
        if deterministic:
            tf.config.experimental.enable_op_determinism()

Helper function for reproducible behavior to set the seed in `random`, `numpy`, `torch` and/or `tf` (if installed).

Args:
seed (`int`):
The seed to set.
deterministic (`bool`, *optional*, defaults to `False`):
Whether to use deterministic algorithms where available. Can slow down training.


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_structure(atoms, cls=None):

        symbols = atoms.get_chemical_symbols()
        positions = atoms.get_positions()
        lattice = atoms.get_cell()

        cls = Structure if cls is None else cls
        return cls(lattice, symbols, positions,
                   coords_are_cartesian=True)

Returns pymatgen structure from ASE Atoms.

Args:
atoms: ASE Atoms object
cls: The Structure class to instantiate (defaults to pymatgen structure)

Returns:
Equivalent pymatgen.core.structure.Structure


def Verify(self):
    return getattr(self, self._KEY) is not None

We can properly index this instance into a Map.

Returns:
True if the value in the attribute named by self._KEY for this class
is not None.  False otherwise.


def set_epsilon(value):
    global _EPSILON
    _EPSILON = value

Sets the value of the fuzz factor used in numeric expressions.

Args:
value: float. New value of epsilon.

Example:
>>> tf.keras.backend.epsilon()
1e-07
>>> tf.keras.backend.set_epsilon(1e-5)
>>> tf.keras.backend.epsilon()
1e-05
>>> tf.keras.backend.set_epsilon(1e-7)


def __init__(self, state_handler: sdk_worker.CachingStateHandler, transform_id: str, key_coder: coders.Coder, window_coder: coders.Coder) -> None:
    self._state_handler = state_handler
    self._transform_id = transform_id
    self._key_coder = key_coder
    self._window_coder = window_coder
    self._timers_info: Dict[str, TimerInfo] = {}
    self._all_states: Dict[tuple, FnApiUserRuntimeStateTypes] = {}

Initialize a ``FnApiUserStateContext``.

Args:
state_handler: A StateServicer object.
transform_id: The name of the PTransform that this context is associated.
key_coder: Coder for the key type.
window_coder: Coder for the window type.


def __le__(self, other: 'TensorFluent') -> 'TensorFluent':

        return self._binary_op(self, other, tf.less_equal, tf.float32)

Returns a TensorFluent for the less-than-or-equal relational operator.

Args:
self: The first operand.
other: The second operand.


def _handle_emailauth(maildomain='', message=''):
    print('SteamGuard requires email authentication...')
    emailauth = input(('Please enter the code sent to your mail address at "%s": ' % maildomain))
    emailauth.upper()
    return emailauth

Called when SteamGuard requires authentication via e-mail.
Asks the user to enter the code.

Args:
maildomain: Optional. The mail domain of the e-mail address the SteamGuard
code is send to.
message: Optional. A message from Steam service.

Returns:
A string containing the code.


def load_transcripts(adapter, transcripts_lines=None, build='37', ensembl_genes=None):

    ensembl_genes = ensembl_genes or adapter.ensembl_genes(build)

    if transcripts_lines is None:
        transcripts_lines = fetch_ensembl_transcripts(build=build)

    transcripts_dict = parse_transcripts(transcripts_lines)
    for ens_tx_id in list(transcripts_dict):
        parsed_tx = transcripts_dict[ens_tx_id]

        ens_gene_id = parsed_tx['ensembl_gene_id']

        gene_obj = ensembl_genes.get(ens_gene_id)

        if not gene_obj:
            transcripts_dict.pop(ens_tx_id)
            LOG.debug("Gene %s does not exist in build %s", ens_gene_id, build)
            continue

        parsed_tx['hgnc_id'] = gene_obj['hgnc_id']

        parsed_tx['primary_transcripts'] = set(gene_obj.get('primary_transcripts', []))

    ref_seq_transcripts = 0
    nr_primary_transcripts = 0
    nr_transcripts = len(transcripts_dict)

    transcript_objs = []

    with progressbar(transcripts_dict.values(), label="Building transcripts", length=nr_transcripts) as bar:
        for tx_data in bar:

            tx_data['is_primary'] = False
            primary_transcripts = tx_data['primary_transcripts']
            refseq_identifier = None
            refseq_identifiers = []
            for category in TRANSCRIPT_CATEGORIES:
                identifiers = tx_data[category]
                if not identifiers:
                    continue

                for refseq_id in identifiers:

                    refseq_identifiers.append(refseq_id)
                    ref_seq_transcripts += 1

                    if refseq_id in primary_transcripts:
                        refseq_identifier = refseq_id
                        tx_data['is_primary'] = True
                        nr_primary_transcripts += 1

                    if not refseq_identifier:
                        refseq_identifier = refseq_id

            if refseq_identifier:
                tx_data['refseq_id'] = refseq_identifier
            if refseq_identifiers:
                tx_data['refseq_identifiers'] = refseq_identifiers

            tx_obj = build_transcript(tx_data, build)
            transcript_objs.append(tx_obj)

    LOG.info("Loading transcripts...")
    if len(transcript_objs) > 0:
        adapter.load_transcript_bulk(transcript_objs)

    LOG.info('Number of transcripts in build %s: %s', build, nr_transcripts)
    LOG.info('Number of transcripts with refseq identifier: %s', ref_seq_transcripts)
    LOG.info('Number of primary transcripts: %s', nr_primary_transcripts)

    return transcript_objs

Load all the transcripts

Transcript information is from ensembl.

Args:
adapter(MongoAdapter)
transcripts_lines(iterable): iterable with ensembl transcript lines
build(str)
ensembl_genes(dict): Map from ensembl_id -> HgncGene

Returns:
transcript_objs(list): A list with all transcript objects


def from_mapping(cls, mapping):
    out = cls()
    for (elem, count) in mapping.items():
        out._set_count(elem, count)
    return out

Create a bag from a dict of elem->count.

Each key in the dict is added if the value is > 0.

Raises:
ValueError: If any count is < 0.


def __init__(self, input_reader=None, output_writer=None):

    super(ImageExportTool, self).__init__(
        input_reader=input_reader, output_writer=output_writer)
    self._abort = False
    self._artifact_definitions_path = None
    self._artifact_filters = None
    self._artifacts_registry = None
    self._custom_artifacts_path = None
    self._destination_path = None
    self._digests = {}
    self._filter_collection = file_entry_filters.FileEntryFilterCollection()
    self._filter_file = None
    self._path_spec_extractor = extractors.PathSpecExtractor()
    self._process_memory_limit = None
    self._resolver_context = context.Context()
    self._skip_duplicates = True
    self._source_type = None

    self.has_filters = False
    self.list_signature_identifiers = False

Initializes the CLI tool object.

Args:
input_reader (Optional[InputReader]): input reader, where None indicates
that the stdin input reader should be used.
output_writer (Optional[OutputWriter]): output writer, where None
indicates that the stdout output writer should be used.


def get_tld(url):

        if url not in URLHelper.__cache:
            URLHelper.__cache[url] = urlparse(url)

        parts = URLHelper.__cache[url].netloc.split(".")

        if len(parts) == 1:
            return ""
        else:
            return parts[-1]

Get the tld of the given URL.

Args:
url (str): The URL to get the tld from.

Returns:
str: The tld


def update_subscription(self, *, subscription_id, credit_card_token):

        payload = {
            "creditCardToken": credit_card_token
        }
        fmt = 'subscriptions/{}'.format(subscription_id)
        return self.client._put(self.url + fmt, json=payload, headers=self.get_headers())

Update information associated with the specified subscription. At the moment it is only possible
to update the token of the credit card to which the charge of the subscription is made.

Args:
subscription_id: Identification of the subscription.
credit_card_token:

Returns:


def calculate_part_visibility(self, ports):

        source_port_lookup = {}
        for part_name, port_infos in SourcePortInfo.filter_parts(ports).items():
            for port_info in port_infos:
                source_port_lookup[port_info.connected_value] = (
                    part_name, port_info.port)

        for part_name, port_infos in SinkPortInfo.filter_parts(
                ports).items():
            for port_info in port_infos:
                if port_info.value != port_info.disconnected_value:
                    conn_part, port = source_port_lookup.get(
                        port_info.value, (None, None))
                    if conn_part and port == port_info.port:
                        if conn_part not in self.part_visibility:
                            self.part_visibility[conn_part] = True
                        if part_name not in self.part_visibility:
                            self.part_visibility[part_name] = True

Calculate what is connected to what

Args:
ports: {part_name: [PortInfo]} from other ports


def point_dist2(p1, p2):

    v = vector(p1, p2)
    return np.dot(v, v)

compute the square of the euclidian distance between two 3D points

Args:
p1, p2: indexable objects with
indices 0, 1, 2 corresponding to 3D cartesian coordinates.
Returns:
The square of the euclidian distance between the points.


def _print_task_data(self, task):
    print(' {0:s} ({1:s})'.format(task['name'], task['id']))
    paths = task.get('saved_paths', [])
    if (not paths):
        return
    for path in paths:
        if path.endswith('worker-log.txt'):
            continue
        if path.endswith('{0:s}.log'.format(task.get('id'))):
            continue
        if path.startswith('/'):
            continue
        print(('   ' + path))

Pretty-prints task data.

Args:
task: Task dict generated by Turbinia.


def read(self, length, timeout):

    self._read_messages_until_true(
        lambda: self._buffer_size and self._buffer_size >= length, timeout)

    with self._read_buffer_lock:
      data, push_back = ''.join(self._read_buffer), ''
      if length:
        data, push_back = data[:length], data[length:]
      self._read_buffer.clear()
      self._buffer_size = len(push_back)
      if push_back:
        self._read_buffer.appendleft(push_back)
    return data

Read 'length' bytes from this stream transport.

Args:
length: If not 0, read this many bytes from the stream, otherwise read all
available data (at least one byte).
timeout: timeouts.PolledTimeout to use for this read operation.

Returns:
The bytes read from this stream.


def parse_mip_analysis(mip_config_raw: dict, qcmetrics_raw: dict, sampleinfo_raw: dict) -> dict:

    outdata = _define_output_dict()

    _config(mip_config_raw, outdata)
    _qc_metrics(outdata, qcmetrics_raw)
    _qc_sample_info(outdata, sampleinfo_raw)

    return outdata

Parse the output analysis files from MIP for adding info
to trend database

Args:
mip_config_raw (dict): raw YAML input from MIP analysis config file
qcmetrics_raw (dict): raw YAML input from MIP analysis qc metric file
sampleinfo_raw (dict): raw YAML input from MIP analysis qc sample info file
Returns:
dict: parsed data


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

Returns boolean features, `True` in the NaN elements of the
[`EventSet`][temporian.EventSet].

Note that for `int` and `bool` this will always be `False` since those types
don't support NaNs. It only makes actual sense to use on `float` (or
`tp.float32`) features.

See also `evset.notnan()`.

Example:
```python
>>> a = tp.event_set(
...     timestamps=[1, 2, 3],
...     features={"M":[np.nan, 5., np.nan], "N":  [-1, 0, 5]},
... )
>>> b = a.isnan()
>>> b
indexes: ...
'M': [ True False True]
'N': [False False False]
...

>>> # Count nans
>>> b["M"].cast(int).cumsum()
indexes: ...
timestamps: [1. 2. 3.]
'M': [1 1 2]
...

```

Returns:
EventSet with boolean features.


def _MergeDifferentId(self):
    for a in self._GetIter(self.feed_merger.a_schedule):
        for b in self._GetIter(self.feed_merger.b_schedule):
            try:
                self._Add(a, b, self._MergeEntities(a, b))
                self._num_merged += 1
            except MergeError:
                continue
    for a in self._GetIter(self.feed_merger.a_schedule):
        if (a not in self.feed_merger.a_merge_map):
            self._num_not_merged_a += 1
            newid = self._HasId(self.feed_merger.b_schedule, self._GetId(a))
            self._Add(a, None, self._Migrate(a, self.feed_merger.a_schedule, newid))
    for b in self._GetIter(self.feed_merger.b_schedule):
        if (b not in self.feed_merger.b_merge_map):
            self._num_not_merged_b += 1
            newid = self._HasId(self.feed_merger.a_schedule, self._GetId(b))
            self._Add(None, b, self._Migrate(b, self.feed_merger.b_schedule, newid))
    return self._num_merged

Tries to merge all possible combinations of entities.

This tries to merge every entity in the old schedule with every entity in
the new schedule. Unlike _MergeSameId, the ids do not need to match.
However, _MergeDifferentId is much slower than _MergeSameId.

This method makes use of various methods like _Merge and _Migrate which
are not implemented in the abstract DataSetMerger class. These method
should be overwritten in a subclass to allow _MergeSameId to work with
different entity types.

Returns:
The number of merged entities.


def categorytree(self, category, depth=5):

    def __cat_tree_rec(cat, depth, tree, level, categories, links):
        ' recursive function to build out the tree '
        tree[cat] = dict()
        tree[cat]['depth'] = level
        tree[cat]['sub-categories'] = dict()
        tree[cat]['links'] = list()
        tree[cat]['parent-categories'] = list()
        parent_cats = list()
        if (cat not in categories):
            tries = 0
            while True:
                if (tries > 10):
                    raise MediaWikiCategoryTreeError(cat)
                try:
                    pag = self.page('{0}:{1}'.format(self.category_prefix, cat))
                    categories[cat] = pag
                    parent_cats = categories[cat].categories
                    links[cat] = self.categorymembers(cat, results=None, subcategories=True)
                    break
                except PageError:
                    raise PageError('{0}:{1}'.format(self.category_prefix, cat))
                except KeyboardInterrupt:
                    raise
                except Exception:
                    tries = (tries + 1)
                    time.sleep(1)
        else:
            parent_cats = categories[cat].categories
        tree[cat]['parent-categories'].extend(parent_cats)
        tree[cat]['links'].extend(links[cat][0])
        if (depth and (level >= depth)):
            for ctg in links[cat][1]:
                tree[cat]['sub-categories'][ctg] = None
        else:
            for ctg in links[cat][1]:
                __cat_tree_rec(ctg, depth, tree[cat]['sub-categories'], (level + 1), categories, links)
    if (not isinstance(category, list)):
        cats = [category]
    else:
        cats = category
    if ((len(cats) == 1) and ((cats[0] is None) or (cats[0] == ''))):
        msg = "CategoryTree: Parameter 'category' must either be a list of one or more categories or a string; provided: '{}'".format(category)
        raise ValueError(msg)
    if ((depth is not None) and (depth < 1)):
        msg = "CategoryTree: Parameter 'depth' must be either None (for the full tree) or be greater than 0"
        raise ValueError(msg)
    results = dict()
    categories = dict()
    links = dict()
    for cat in cats:
        if ((cat is None) or (cat == '')):
            continue
        __cat_tree_rec(cat, depth, results, 0, categories, links)
    return results

Generate the Category Tree for the given categories

Args:
category(str or list of strings): Category name(s)
depth(int): Depth to traverse the tree
Returns:
dict: Category tree structure
Note:
Set depth to **None** to get the whole tree
Note:
Return Data Structure: Subcategory contains the same \
recursive structure

>>> {
'category': {
'depth': Number,
'links': list,
'parent-categories': list,
'sub-categories': dict
}
}

.. versionadded:: 0.3.10


def find_synonym(self, word):
    if (word and self.synonyms):
        reverse_lookup = {}
        for (k, v) in self.synonyms.items():
            for i in v:
                reverse_lookup[i.lower()] = k.lower()
        if (word.lower() in reverse_lookup):
            return reverse_lookup[word.lower()]
    return word

Given a string and a dict of synonyms, returns the 'preferred'
word. Case insensitive.

Args:
word (str): A word.

Returns:
str: The preferred word, or the input word if not found.

Example:
>>> syn = {'snake': ['python', 'adder']}
>>> find_synonym('adder', syn)
'snake'
>>> find_synonym('rattler', syn)
'rattler'

TODO:
Make it handle case, returning the same case it received.


def _set_label(self, which, label, **kwargs):

        prop_default = {
            'fontsize': 18,
        }

        for prop, default in prop_default.items():
            kwargs[prop] = kwargs.get(prop, default)

        setattr(self.label, which, label)
        setattr(self.label, which + '_kwargs', kwargs)
        return

Private method for setting labels.

Args:
which (str): The indicator of which part of the plots
to adjust. This currently handles `xlabel`/`ylabel`,
and `title`.
label (str): The label to be added.
fontsize (int, optional): Fontsize for associated label. Default
is None.


def enable_store_parameters_in_results(kernel):
    kernel_stack = []
    while (hasattr(kernel, 'parameters') and ('inner_kernel' in kernel.parameters)):
        kernel_stack.append(kernel)
        kernel = kernel.parameters['inner_kernel']

    def _recreate_kernel(kernel, parameters):
        new_parameters = kernel.parameters.copy()
        new_parameters.update(parameters)
        if ('store_parameters_in_results' in new_parameters):
            new_parameters['store_parameters_in_results'] = True
        with deprecation.silence():
            return type(kernel)(**new_parameters)
    if hasattr(kernel, 'parameters'):
        kernel = _recreate_kernel(kernel, {})
    for outer_kernel in reversed(kernel_stack):
        outer_kernel = _recreate_kernel(outer_kernel, {'inner_kernel': kernel})
        kernel = outer_kernel
    return kernel

Enables the `store_parameters_in_results` parameter in a chain of kernels.

This is a temporary utility for use during the transition period of the
parameter storage methods.

Args:
kernel: A TransitionKernel.

Returns:
kernel: The same kernel, but recreated with `store_parameters_in_results`
recursively set to `True` in its parameters and its inner kernels (as
appropriate).


def __validate_args(self, func_name, args, kwargs):
    from pyvalid.validators import Validator
    for (i, (arg_name, accepted_values)) in enumerate(self.accepted_args):
        if (i < len(args)):
            value = args[i]
        elif (arg_name in kwargs):
            value = kwargs[arg_name]
        elif (i in self.optional_args):
            continue
        else:
            raise InvalidArgumentNumberError(func_name)
        is_valid = False
        for accepted_val in accepted_values:
            is_validator = (isinstance(accepted_val, Validator) or (isinstance(accepted_val, MethodType) and hasattr(accepted_val, '__func__') and isinstance(accepted_val.__func__, Validator)))
            if is_validator:
                is_valid = accepted_val(value)
            elif isinstance(accepted_val, type):
                is_valid = isinstance(value, accepted_val)
            else:
                is_valid = (value == accepted_val)
            if is_valid:
                break
        if (not is_valid):
            ord_num = self.__ordinal((i + 1))
            raise ArgumentValidationError(ord_num, func_name, value, accepted_values)

Compare value of each required argument with list of
accepted values.

Args:
func_name (str): Function name.
args (list): Collection of the position arguments.
kwargs (dict): Collection of the keyword arguments.

Raises:
InvalidArgumentNumberError: When position or count of the arguments
is incorrect.
ArgumentValidationError: When encountered unexpected argument
value.


def get_video_transcript_data(video_id, language_code):

    video_transcript = VideoTranscript.get_or_none(video_id, language_code)
    if video_transcript:
        try:
            return dict(file_name=video_transcript.filename, content=video_transcript.transcript.file.read())
        except Exception:
            logger.exception(
                '[edx-val] Error while retrieving transcript for video=%s -- language_code=%s',
                video_id,
                language_code
            )
            raise

Get video transcript data

Arguments:
video_id(unicode): An id identifying the Video.
language_code(unicode): it will be the language code of the requested transcript.

Returns:
A dict containing transcript file name and its content.


def compile_date(self):

        result = self._dll.JLINKARM_GetCompileDateTime()
        return ctypes.cast(result, ctypes.c_char_p).value.decode()

Returns a string specifying the date and time at which the DLL was
translated.

Args:
self (JLink): the ``JLink`` instance

Returns:
Datetime string.


def load(self, spec):

        if spec.template is not None:
            return self.loader.unicode(spec.template, spec.template_encoding)

        path = self._find(spec)

        return self.loader.read(path, spec.template_encoding)

Find and return the template associated to a TemplateSpec instance.

Returns the template as a unicode string.

Arguments:

spec: a TemplateSpec instance.


def get_extended_attention_mask(self, attention_mask: torch.Tensor, input_shape: Tuple[int], device: torch.device, has_query: bool=False) -> torch.Tensor:
    if attention_mask.dim() == 3:
        extended_attention_mask = attention_mask[:, None, :, :]
    elif attention_mask.dim() == 2:
        extended_attention_mask = attention_mask[:, None, None, :]
    else:
        raise ValueError(f'Wrong shape for input_ids (shape {input_shape}) or attention_mask (shape {attention_mask.shape})')
    extended_attention_mask = extended_attention_mask.to(dtype=self.dtype)
    extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0
    return extended_attention_mask

Makes broadcastable attention and causal masks so that future and masked tokens are ignored.

Arguments:
attention_mask (`torch.Tensor`):
Mask with ones indicating tokens to attend to, zeros for tokens to ignore.
input_shape (`Tuple[int]`):
The shape of the input to the model.
device: (`torch.device`):
The device of the input to the model.

Returns:
`torch.Tensor` The extended attention mask, with a the same dtype as `attention_mask.dtype`.


def validate_element(self, value):
    if (not isinstance(value, self.type)):
        if (isinstance(value, six.integer_types) and (self.type == float)):
            return float(value)
        if (value is None):
            if self.required:
                raise ValidationError('Required field is missing')
        else:
            try:
                name = self.name
            except AttributeError:
                raise ValidationError(('Expected type %s for %s, found %s (type %s)' % (self.type, self.__class__.__name__, value, type(value))))
            else:
                raise ValidationError(('Expected type %s for field %s, found %s (type %s)' % (self.type, name, value, type(value))))
    return value

Validate single element of field.

This is different from validate in that it is used on individual
values of repeated fields.

Args:
value: Value to validate.

Returns:
The value casted in the expected type.

Raises:
ValidationError if value is not expected type.


def CheckTrailingSemicolon(filename, clean_lines, linenum, error):
    line = clean_lines.elided[linenum]
    match = Match('^(.*\\)\\s*)\\{', line)
    if match:
        closing_brace_pos = match.group(1).rfind(')')
        opening_parenthesis = ReverseCloseExpression(clean_lines, linenum, closing_brace_pos)
        if (opening_parenthesis[2] > (- 1)):
            line_prefix = opening_parenthesis[0][0:opening_parenthesis[2]]
            macro = Search('\\b([A-Z_][A-Z0-9_]*)\\s*$', line_prefix)
            func = Match('^(.*\\])\\s*$', line_prefix)
            if ((macro and (macro.group(1) not in ('TEST', 'TEST_F', 'MATCHER', 'MATCHER_P', 'TYPED_TEST', 'EXCLUSIVE_LOCKS_REQUIRED', 'SHARED_LOCKS_REQUIRED', 'LOCKS_EXCLUDED', 'INTERFACE_DEF'))) or (func and (not Search('\\boperator\\s*\\[\\s*\\]', func.group(1)))) or Search('\\b(?:struct|union)\\s+alignas\\s*$', line_prefix) or Search('\\bdecltype$', line_prefix) or Search('\\s+=\\s*$', line_prefix)):
                match = None
        if (match and (opening_parenthesis[1] > 1) and Search('\\]\\s*$', clean_lines.elided[(opening_parenthesis[1] - 1)])):
            match = None
    else:
        match = Match('^(.*(?:else|\\)\\s*const)\\s*)\\{', line)
        if (not match):
            prevline = GetPreviousNonBlankLine(clean_lines, linenum)[0]
            if (prevline and Search('[;{}]\\s*$', prevline)):
                match = Match('^(\\s*)\\{', line)
    if match:
        (endline, endlinenum, endpos) = CloseExpression(clean_lines, linenum, len(match.group(1)))
        if ((endpos > (- 1)) and Match('^\\s*;', endline[endpos:])):
            raw_lines = clean_lines.raw_lines
            ParseNolintSuppressions(filename, raw_lines[(endlinenum - 1)], (endlinenum - 1), error)
            ParseNolintSuppressions(filename, raw_lines[endlinenum], endlinenum, error)
            error(filename, endlinenum, 'readability/braces', 4, "You don't need a ; after a }")

Looks for redundant trailing semicolon.

Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found.


def _parameter_net(self, theta, kernel_shape=9):

        with argscope(FullyConnected, nl=tf.nn.leaky_relu):
            net = FullyConnected('fc1', theta, 64)
            net = FullyConnected('fc2', net, 128)

        pred_filter = FullyConnected('fc3', net, kernel_shape ** 2, nl=tf.identity)
        pred_filter = tf.reshape(pred_filter, [BATCH, kernel_shape, kernel_shape, 1], name="pred_filter")
        logger.info('Parameter net output: {}'.format(pred_filter.get_shape().as_list()))
        return pred_filter

Estimate filters for convolution layers

Args:
theta: angle of filter
kernel_shape: size of each filter

Returns:
learned filter as [B, k, k, 1]


def _concat(self):
    if len(self._variable_list) == 1:
        with ops.name_scope(None):
            return array_ops.identity(self._variable_list[0], name=self._name)
    partition_axes = self._partition_axes()
    if len(partition_axes) > 1:
        raise NotImplementedError('Cannot concatenate along more than one dimension: %s.  Multi-axis partition concat is not supported' % str(partition_axes))
    partition_ix = partition_axes[0]
    with ops.name_scope(self._name + '/ConcatPartitions/'):
        concatenated = array_ops.concat(self._variable_list, partition_ix)
    with ops.name_scope(None):
        return array_ops.identity(concatenated, name=self._name)

Returns the overall concatenated value as a `Tensor`.

This is different from using the partitioned variable directly as a tensor
(through tensor conversion and `as_tensor`) in that it creates a new set of
operations that keeps the control dependencies from its scope.

Returns:
`Tensor` containing the concatenated value.


def to_dict(self):
    d = {}
    d[TestResultEnums.RECORD_NAME] = self.test_name
    d[TestResultEnums.RECORD_CLASS] = self.test_class
    d[TestResultEnums.RECORD_BEGIN_TIME] = self.begin_time
    d[TestResultEnums.RECORD_END_TIME] = self.end_time
    d[TestResultEnums.RECORD_RESULT] = self.result
    d[TestResultEnums.RECORD_UID] = self.uid
    d[TestResultEnums.RECORD_SIGNATURE] = self.signature
    d[TestResultEnums.RECORD_RETRY_PARENT] = self.retry_parent.signature if self.retry_parent else None
    d[TestResultEnums.RECORD_PARENT] = {'parent': self.parent[0].signature, 'type': self.parent[1].value} if self.parent else None
    d[TestResultEnums.RECORD_EXTRAS] = self.extras
    d[TestResultEnums.RECORD_DETAILS] = self.details
    d[TestResultEnums.RECORD_TERMINATION_SIGNAL_TYPE] = self.termination_signal_type
    d[TestResultEnums.RECORD_EXTRA_ERRORS] = {key: value.to_dict() for key, value in self.extra_errors.items()}
    d[TestResultEnums.RECORD_STACKTRACE] = self.stacktrace
    return d

Gets a dictionary representating the content of this class.

Returns:
A dictionary representating the content of this class.


def status(self, order_id):

        self.logger.debug('Get status of order ' + order_id)
        url = '%(base_url)s/order/%(order_id)s' % {
            'base_url': self.base_url, 'order_id': order_id
        }
        r = self.gbdx_connection.get(url)
        r.raise_for_status()
        return r.json().get("acquisitions", {})

Checks imagery order status. There can be more than one image per
order and this function returns the status of all images
within the order.

Args:
order_id (str): The id of the order placed.

Returns:
List of dictionaries, one per image. Each dictionary consists
of the keys 'acquisition_id', 'location' and 'state'.


def remove_sites_from_neighbours( self, remove_labels ):

        if type( remove_labels ) is str:
            remove_labels = [ remove_labels ]
        self.neighbours = set( n for n in self.neighbours if n.label not in remove_labels )

Removes sites from the set of neighbouring sites if these have labels in remove_labels.

Args:
Remove_labels (List) or (Str): List of Site labels to be removed from the cluster neighbour set.

Returns:
None


def dimension_values(self, dimension, expanded=True, flat=True):

        index = self.get_dimension_index(dimension)
        if index == 0:
            return np.array([self.data if np.isscalar(self.data) else self.data[index]])
        elif index == 1:
            return [] if np.isscalar(self.data) else np.array([self.data[1]])
        else:
            return super(Annotation, self).dimension_values(dimension)

Return the values along the requested dimension.

Args:
dimension: The dimension to return values for
expanded (bool, optional): Whether to expand values
flat (bool, optional): Whether to flatten array

Returns:
NumPy array of values along the requested dimension


def Match(self, file_entry):

    if not file_entry:
      return False

    filename = file_entry.name.lower()
    return filename == self._filename

Determines if a file entry matches the filter.

Args:
file_entry (dfvfs.FileEntry): a file entry.

Returns:
bool: True if the file entry matches the filter.


def _build_request(self, verb, verb_arguments):

        method = getattr(self._component, verb)

        method_args = {str(k): v for k, v in verb_arguments.items()}
        return method(**method_args)

Builds HttpRequest object.

Args:
verb (str): Request verb (ex. insert, update, delete).
verb_arguments (dict): Arguments to be passed with the request.

Returns:
httplib2.HttpRequest: HttpRequest to be sent to the API.


def extract_lookups(value):

    lookups = set()
    if isinstance(value, basestring):
        lookups = lookups.union(extract_lookups_from_string(value))
    elif isinstance(value, list):
        for v in value:
            lookups = lookups.union(extract_lookups(v))
    elif isinstance(value, dict):
        for v in value.values():
            lookups = lookups.union(extract_lookups(v))
    return lookups

Recursively extracts any stack lookups within the data structure.

Args:
value (one of str, list, dict): a structure that contains lookups to
output values

Returns:
list: list of lookups if any


def _validate_chain_strength(sampler, chain_strength):

    properties = sampler.properties

    if 'extended_j_range' in properties:
        max_chain_strength = - min(properties['extended_j_range'])
    elif 'j_range' in properties:
        max_chain_strength = - min(properties['j_range'])
    else:
        raise ValueError("input sampler should have 'j_range' and/or 'extended_j_range' property.")

    if chain_strength is None:
        chain_strength = max_chain_strength
    elif chain_strength > max_chain_strength:
        raise ValueError("Provided chain strength exceedds the allowed range.")

    return chain_strength

Validate the provided chain strength, checking J-ranges of the sampler's children.

Args:
chain_strength (float) The provided chain strength.  Use None to use J-range.

Returns (float):
A valid chain strength, either provided or based on available J-range.  Positive finite float.


def __init__(self, counter_factory, state_sampler):
    self._counter_factory = counter_factory
    self._state_sampler = state_sampler
    self._latest_step = None
    self.bytes_read_counter = None
    self.scoped_state = None

Create a new IO read counter.

Args:
counter_factory: A counters.CounterFactory to create byte counters.
state_sampler: A statesampler.StateSampler to transition into read states.


def partial_tile(cls, tile_assignment):
    if not isinstance(tile_assignment, _np.ndarray):
        raise TypeError('PartialTile assignment must be of type np.ndarray')
    dims = list(tile_assignment.shape)
    flattened_devices = tile_assignment.reshape(-1, order='C')
    return Sharding(proto=xla_data_pb2.OpSharding(type=xla_data_pb2.OpSharding.OTHER, tile_assignment_dimensions=dims, tile_assignment_devices=list(flattened_devices), replicate_on_last_tile_dim=True))

Returns a partially tiled sharding attribute.

This is similar to tile(), but tile_assignment has one more dimension than
the tensor, and tiles in the last dimension of tile_assignment are
replicated.

Args:
tile_assignment: An np.ndarray describing the topology of the tiling and
which device will compute which part of the topology.

Raises:
TypeError: tile_assignment was not of np.array type.


def has_no_error(state, incorrect_msg='Your code generated an error. Fix it and try again!'):
    if state.reporter.get_errors():
        state.do_test(incorrect_msg)
    return state

Check whether the submission did not generate a runtime error.

Simply use ``Ex().has_no_error()`` in your SCT whenever you want to check for errors.
By default, after the entire SCT finished executing, ``sqlwhat`` will check
for errors before marking the exercise as correct. You can disable this behavior
by using ``Ex().allow_error()``.

Args:
incorrect_msg: If specified, this overrides the automatically generated feedback message
in case the student's query did not return a result.


def entry_point(__func: Callable) -> Callable:

    if __func.__module__ == '__main__':
        import sys
        sys.exit(__func())
    else:
        return __func

Execute function when module is run directly.

Note:
This allows fall through for importing modules that use it.

Args:
__func: Function to run


def cmd_startstop(options):

    statelu = {"start": "stopped", "stop": "running"}
    options.inst_state = statelu[options.command]
    debg.dprint("toggle set state: ", options.inst_state)
    (i_info, param_str) = gather_data(options)
    (tar_inst, tar_idx) = determine_inst(i_info, param_str, options.command)
    response = awsc.startstop(tar_inst, options.command)
    responselu = {"start": "StartingInstances", "stop": "StoppingInstances"}
    filt = responselu[options.command]
    resp = {}
    state_term = ('CurrentState', 'PreviousState')
    for i, j in enumerate(state_term):
        resp[i] = response["{0}".format(filt)][0]["{0}".format(j)]['Name']
    print("Current State: {}{}{}  -  Previous State: {}{}{}\n".
          format(C_STAT[resp[0]], resp[0], C_NORM,
                 C_STAT[resp[1]], resp[1], C_NORM))

Start or Stop the specified instance.

Finds instances that match args and instance-state expected by the
command.  Then, the target instance is determined, the action is
performed on the instance, and the eturn information is displayed.

Args:
options (object): contains args and data from parser.


def predict_proba(self, a, b, idx=0, **kwargs):
    return self.predict_dataset(DataFrame([[a, b]], columns=['A', 'B']))

Use Jarfo to predict the causal direction of a pair of vars.

Args:
a (numpy.ndarray): Variable 1
b (numpy.ndarray): Variable 2
idx (int): (optional) index number for printing purposes

Returns:
float: Causation score (Value : 1 if a->b and -1 if b->a)


def _handle_message(self, message, handle_wrte=True):
    if (message.command == 'OKAY'):
        self._set_or_check_remote_id(message.arg0)
        if (not self._expecting_okay):
            raise usb_exceptions.AdbProtocolError('%s received unexpected OKAY: %s', self, message)
        self._expecting_okay = False
    elif (message.command == 'CLSE'):
        self.closed_state = self.ClosedState.CLOSED
    elif (not handle_wrte):
        raise usb_exceptions.AdbProtocolError('%s received WRTE before OKAY/CLSE: %s', self, message)
    else:
        with self._read_buffer_lock:
            self._read_buffer.append(message.data)
            self._buffer_size += len(message.data)

Handle a message that was read for this stream.

For each message type, this means:
OKAY: Check id's and make sure we are expecting an OKAY.  Clear the
self._expecting_okay flag so any pending write()'s know.
CLSE: Set our internal state to closed.
WRTE: Add the data read to our internal read buffer.  Note we don't
return the actual data because it may not be this thread that needs it.

Args:
message: Message that was read.
handle_wrte: If True, we can handle WRTE messages, otherwise raise.

Raises:
AdbProtocolError: If we get a WRTE message but handle_wrte is False.


def parse_date(value):
    if (not value):
        return None
    if isinstance(value, datetime.date):
        return value
    return parse_datetime(value).date()

Attempts to parse `value` into an instance of ``datetime.date``. If
`value` is ``None``, this function will return ``None``.

Args:
value: A timestamp. This can be a string, datetime.date, or
datetime.datetime value.


def get_enabled_references(self, datas, meta_references):

        references = OrderedDict()

        for section in meta_references:
            references[section] = self.get_reference(datas, section)

        return references

Get enabled manifest references declarations.

Enabled references are defined through meta references declaration,
every other references are ignored.

Arguments:
datas (dict): Data where to search for reference declarations.
This is commonly the fully parsed manifest.
meta_references (list): List of enabled reference names.

Returns:
collections.OrderedDict: Serialized enabled references datas.


def setup_gpu(required_gpus):
    if required_gpus == 0:
        return
    available_gpus = tf.config.experimental.list_physical_devices('GPU')
    if not available_gpus:
        raise ValueError('requires at least one physical GPU')
    if len(available_gpus) >= required_gpus:
        tf.config.set_visible_devices(available_gpus[:required_gpus])
    else:
        num_logical_gpus = required_gpus - len(available_gpus) + 1
        logical_gpus = [tf.config.LogicalDeviceConfiguration(memory_limit=256) for _ in range(num_logical_gpus)]
        tf.config.set_logical_device_configuration(available_gpus[0], logical_gpus)

Sets up the GPU devices.

If there're more available GPUs than needed, it hides the additional ones. If
there're less, it creates logical devices. This is to make sure the tests see
a fixed number of GPUs regardless of the environment.

Args:
required_gpus: an integer. The number of GPUs required.

Raises:
ValueError: if num_gpus is larger than zero but no GPU is available.