def _reload_config(self, reload_original_config):

        if reload_original_config:
            self.original_config = self.running_config
            self.original_config.set_name('original')

        paths = self.running_config.get_paths()

        self.running_config = FortiConfig('running', vdom=self.vdom)

        for path in paths:
            self.load_config(path, empty_candidate=True)

This command will update the running config from the live device.

Args:
* reload_original_config:
* If ``True`` the original config will be loaded with the running config before reloading the\
original config.
* If ``False`` the original config will remain untouched.


def get_list(self, key, pipeline=False):
    if pipeline:
        return self._pipeline.lrange(key, 0, (- 1))
    return self._db.lrange(key, 0, (- 1))

Get all the value in the list stored at key.

Args:
key (str): Key where the list is stored.
pipeline (bool): True, start a transaction block. Default false.

Returns:
list: values in the list ordered by list index


def update_state(self, y_true, y_pred, sample_weight=None):
    y_true = ops.convert_to_tensor(y_true, dtype=self._dtype)
    y_pred = ops.convert_to_tensor(y_pred, dtype=self._dtype)
    y_true, y_pred = squeeze_or_expand_to_same_rank(y_true, y_pred)
    if not self._built:
        self._build(y_true.shape, y_pred.shape)
    if sample_weight is None:
        sample_weight = 1
    sample_weight = ops.convert_to_tensor(sample_weight, dtype=self.dtype)
    if len(sample_weight.shape) == 1:
        sample_weight = ops.expand_dims(sample_weight, axis=1)
    sample_weight = ops.broadcast_to(sample_weight, ops.shape(y_true))
    weighted_y_true = y_true * ops.cast(sample_weight, y_true.dtype)
    self.sum.assign(self.sum + ops.sum(weighted_y_true, axis=0))
    self.squared_sum.assign(self.squared_sum + ops.sum(y_true * weighted_y_true, axis=0))
    self.total_mse.assign(self.total_mse + ops.sum((y_true - y_pred) ** 2 * ops.cast(sample_weight, y_true.dtype), axis=0))
    self.count.assign(self.count + ops.sum(sample_weight, axis=0))
    self.num_samples.assign(self.num_samples + ops.size(y_true))

Accumulates root mean squared error statistics.

Args:
y_true: The ground truth values.
y_pred: The predicted values.
sample_weight: Optional weighting of each example. Can
be a `Tensor` whose rank is either 0, or the same rank as
`y_true`, and must be broadcastable to `y_true`.
Defaults to `1`.

Returns:
Update op.


def _check_if_fenced(self, name):

        if name in object.__getattribute__(self, '_attributes_to_fence'):
            raise TranspilerAccessError("The fenced %s has the property %s protected" %
                                        (type(object.__getattribute__(self, '_wrapped')), name))

Checks if the attribute name is in the list of attributes to protect. If so, raises
TranspilerAccessError.

Args:
name (string): the attribute name to check

Raises:
TranspilerAccessError: when name is the list of attributes to protect.


def __init__(self, jids, _id = None):

        super(GetStatusesIqProtocolEntity, self).__init__(self.__class__.XMLNS, _id, _type = "get", to = YowConstants.WHATSAPP_SERVER)
        self.setGetStatusesProps(jids)

Request the statuses of users. Should be sent once after login.

Args:
- jids: A list of jids representing the users whose statuses you are
trying to get.


def generate_version(max_major: int=1, max_minor: int=7, max_patch: int=15) -> str:
    major = randint(0, max_major)
    minor = randint(0, max_minor)
    patch = randint(0, max_patch)
    return '{:d}.{:d}.{:d}'.format(major, minor, patch)

Select a random version.

Args:
max_major (int, optional) maximum major version
max_minor (int, optional) maximum minor version
max_patch (int, optional) maximum patch version

Returns:
str, Version String


def _bind_length_scalar_handlers(tids, scalar_factory, lns=_NON_ZERO_LENGTH_LNS):

    handler = partial(_length_scalar_handler, scalar_factory)
    return _bind_length_handlers(tids, handler, lns)

Binds a set of scalar handlers for an inclusive range of low-nibble values.

Args:
tids (Sequence[int]): The Type IDs to bind to.
scalar_factory (Callable): The factory for the scalar parsing function.
This function can itself return a function representing a thunk to defer the
scalar parsing or a direct value.
lns (Sequence[int]): The low-nibble lengths to bind to.


def CopyAttributesFromSessionCompletion(self, session_completion):
    if (self.identifier != session_completion.identifier):
        raise ValueError('Session identifier mismatch.')
    self.aborted = session_completion.aborted
    if session_completion.analysis_reports_counter:
        self.analysis_reports_counter = session_completion.analysis_reports_counter
    self.completion_time = session_completion.timestamp
    if session_completion.event_labels_counter:
        self.event_labels_counter = session_completion.event_labels_counter
    if session_completion.parsers_counter:
        self.parsers_counter = session_completion.parsers_counter

Copies attributes from a session completion.

Args:
session_completion (SessionCompletion): session completion attribute
container.

Raises:
ValueError: if the identifier of the session completion does not match
that of the session.


def fuzzy_index_match(possiblities, label, **kwargs):
    possibilities = list(possiblities)
    if isinstance(label, basestring):
        return fuzzy_get(possibilities, label, **kwargs)
    if isinstance(label, int):
        return possibilities[label]
    if isinstance(label, list):
        return [fuzzy_get(possibilities, lbl) for lbl in label]

Find the closest matching column label, key, or integer indexed value

Returns:
type(label): sequence of immutable objects corresponding to best matches to each object in label
if label is an int returns the object (value) in the list of possibilities at that index
if label is a str returns the closest str match in possibilities

>>> from collections import OrderedDict as odict
>>> fuzzy_index_match(pd.DataFrame(pd.np.random.randn(9,4), columns=list('ABCD'), index=range(9)), 'b')
'B'
>>> fuzzy_index_match(odict(zip('12345','ABCDE')), 'r2d2')
'2'
>>> fuzzy_index_match(odict(zip('12345','ABCDE')), 1)
'2'
>>> fuzzy_index_match(odict(zip('12345','ABCDE')), -1)
'5'
>>> fuzzy_index_match(odict(zip(range(4),'FOUR')), -4)
0


def pdb_downloader_and_metadata(self, outdir=None, pdb_file_type=None, force_rerun=False):
    if (not pdb_file_type):
        pdb_file_type = self.pdb_file_type
    counter = 0
    for g in tqdm(self.genes):
        pdbs = g.protein.pdb_downloader_and_metadata(outdir=outdir, pdb_file_type=pdb_file_type, force_rerun=force_rerun)
        if pdbs:
            counter += len(pdbs)
    log.info('Updated PDB metadata dataframe. See the "df_pdb_metadata" attribute for a summary dataframe.')
    log.info('Saved {} structures total'.format(counter))

Download ALL mapped experimental structures to each protein's structures directory.

Args:
outdir (str): Path to output directory, if GEM-PRO directories were not set or other output directory is
desired
pdb_file_type (str): Type of PDB file to download, if not already set or other format is desired
force_rerun (bool): If files should be re-downloaded if they already exist


def _scrub_method_name(self, method_name):
    if (method_name not in self._scrubbed_method_names):
        self._scrubbed_method_names[method_name] = scrub_method_name(method_name)
    return self._scrubbed_method_names[method_name]

Scrubs a method name, returning result from local cache if available.

This method wraps fitparse.utils.scrub_method_name and memoizes results,
as scrubbing a method name is expensive.

Args:
method_name: Method name to scrub.

Returns:
Scrubbed method name.


def __init__(self, scope, parent, name, result, paren=False):

        CodeEntity.__init__(self, scope, parent)
        self.name = name
        self.result = result
        self.parenthesis = paren

Constructor for expressions.

Args:
scope (CodeEntity): The program scope where this object belongs.
parent (CodeEntity): This object's parent in the program tree.
name (str): The name of the expression in the program.
result (str): The return type of the expression in the program.

Kwargs:
paren (bool): Whether the expression is enclosed in parentheses.


def wrap_embedded_keyvalue(self, data):

        if data is not None:
            try:
                data = u'{}'.format(data)

            except UnicodeEncodeError:

                pass

            variables = []
            for v in re.finditer(self._vars_keyvalue_embedded, data):
                variables.append(v.group(0))

            for var in set(variables):

                variable_string = re.search(self._variable_parse, var).group(0)

                data = data.replace(var, '": "{}"'.format(variable_string))
        return data

Wrap keyvalue embedded variable in double quotes.

Args:
data (string): The data with embedded variables.

Returns:
(string): Results retrieved from DB


def _remove(self, removeList, selfValue):

        for removeValue in removeList:
            print(removeValue, removeList)

            removeEverything(removeValue, selfValue)

Remove elements from a list by matching the elements in the other list.

This method only looks inside current instance's value, not recursive.
There is no need for a recursive one anyway.
Match by == operation.

Args:
removeList (list): The list of matching elements.
selfValue (list): The list you remove value from. Usually ``self.value``


def valid(self, value, include_name=True):

		return super(Tree, self).valid(value, include_name and [self._name] or [])

Valid

Checks if a value is valid based on the instance's values

Arguments:
value {mixed} -- The value to validate
include_name {bool} -- If true, Tree's name will be prepended to
all error keys

Returns:
bool


def position(self, partition):
    if (not isinstance(partition, TopicPartition)):
        raise TypeError('partition must be a TopicPartition namedtuple')
    assert self._subscription.is_assigned(partition), 'Partition is not assigned'
    offset = self._subscription.assignment[partition].position
    if (offset is None):
        self._update_fetch_positions([partition])
        offset = self._subscription.assignment[partition].position
    return offset

Get the offset of the next record that will be fetched

Arguments:
partition (TopicPartition): Partition to check

Returns:
int: Offset


def merge(self, other):
    for attr in self.attrs:
        if (not (getattr(other, attr, None) is None)):
            setattr(self, attr, getattr(other, attr))
    if other.raw:
        if (not self.raw):
            self.raw = {}
        self.raw.update(other.raw)

Copy properties from other into self, skipping ``None`` values.  Also merges the raw data.

Args:
other (SkypeObj): second object to copy fields from


def GetOutputClass(cls, name):

    if not isinstance(name, py2to3.STRING_TYPES):
      raise ValueError('Name attribute is not a string.')

    name = name.lower()
    if name not in cls._output_classes:
      raise KeyError(
          'Name: [{0:s}] not registered as an output module.'.format(name))

    return cls._output_classes[name]

Retrieves the output class for a specific name.

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

Returns:
type: output module class.

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


def getexcfo(e):

    tb = sys.exc_info()[2]
    tbinfo = traceback.extract_tb(tb)
    path, line, name, src = '', '', '', None
    if tbinfo:
        path, line, name, sorc = tbinfo[-1]
    retd = {
        'msg': str(e),
        'file': path,
        'line': line,
        'name': name,
        'src': src
    }

    if isinstance(e, s_exc.SynErr):
        retd['syn:err'] = e.errinfo

    return (e.__class__.__name__, retd)

Get an err tufo from an exception.

Args:
e (Exception): An Exception (or Exception subclass).

Notes:
This can be called outside of the context of an exception handler,
however details such as file, line, function name and source may be
missing.

Returns:
((str, dict)):


def functional_from_config(cls, config, custom_objects=None):
    created_layers = {}
    unprocessed_nodes = {}

    def add_unprocessed_node(layer, node_data):

        if layer not in unprocessed_nodes:
            unprocessed_nodes[layer] = [node_data]
        else:
            unprocessed_nodes[layer].append(node_data)

    def process_node(layer, node_data):

        args, kwargs = deserialize_node(node_data, created_layers)
        layer(*args, **kwargs)

    def process_layer(layer_data):

        layer_name = layer_data['name']
        if 'module' not in layer_data:
            layer = saving_utils.model_from_config(layer_data, custom_objects=custom_objects)
        else:
            layer = serialization_lib.deserialize_keras_object(layer_data, custom_objects=custom_objects)
        if not isinstance(layer, Operation):
            raise ValueError(f'Unexpected object from deserialization, expected a layer or operation, got a {type(layer)}')
        created_layers[layer_name] = layer
        inbound_nodes_data = layer_data['inbound_nodes']
        for node_data in inbound_nodes_data:
            add_unprocessed_node(layer, node_data)
    functional_config = {}
    for key in ['layers', 'input_layers', 'output_layers']:
        functional_config[key] = config.pop(key)
    for key in ['name', 'trainable']:
        if key in config:
            functional_config[key] = config.pop(key)
        else:
            functional_config[key] = None
    for layer_data in functional_config['layers']:
        process_layer(layer_data)
    while unprocessed_nodes:
        for layer_data in functional_config['layers']:
            layer = created_layers[layer_data['name']]
            if layer in unprocessed_nodes:
                node_data_list = unprocessed_nodes[layer]
                node_index = 0
                while node_index < len(node_data_list):
                    node_data = node_data_list[node_index]
                    try:
                        process_node(layer, node_data)
                    except IndexError:
                        break
                    node_index += 1
                if node_index < len(node_data_list):
                    unprocessed_nodes[layer] = node_data_list[node_index:]
                else:
                    del unprocessed_nodes[layer]
    name = functional_config['name']
    trainable = functional_config['trainable']

    def get_tensor(layer_name, node_index, tensor_index):
        assert layer_name in created_layers
        layer = created_layers[layer_name]
        if isinstance(layer, Functional):
            node_index -= 1
        layer_output_tensors = layer._inbound_nodes[node_index].output_tensors
        return layer_output_tensors[tensor_index]

    def map_tensors(tensors):
        if isinstance(tensors, list) and len(tensors) == 3 and isinstance(tensors[0], str):
            return get_tensor(*tensors)
        if isinstance(tensors, dict):
            return {k: map_tensors(v) for k, v in tensors.items()}
        if isinstance(tensors, tuple):
            return tuple([map_tensors(v) for v in tensors])
        return [map_tensors(v) for v in tensors]
    input_tensors = map_tensors(functional_config['input_layers'])
    output_tensors = map_tensors(functional_config['output_layers'])
    return cls(inputs=input_tensors, outputs=output_tensors, name=name, trainable=trainable, **config)

Instantiates a Functional model from its config (from `get_config()`).

Args:
cls: Class of the model, e.g. a custom subclass of `Model`.
config: Output of `get_config()` for the original model instance.
custom_objects: Optional dict of custom objects.

Returns:
An instance of `cls`.


def get_security_group_id(name='', env='', region=''):

    vpc_id = get_vpc_id(env, region)

    LOG.info('Find %s sg in %s [%s] in %s', name, env, region, vpc_id)

    url = '{0}/securityGroups/{1}/{2}/{3}?vpcId={4}'.format(API_URL, env, region, name, vpc_id)
    response = requests.get(url, verify=GATE_CA_BUNDLE, cert=GATE_CLIENT_CERT)
    assert response.ok

    result = response.json()
    try:
        security_group_id = result['id']
    except KeyError:
        msg = 'Security group ({0}) not found'.format(name)
        raise SpinnakerSecurityGroupError(msg)

    LOG.info('Found: %s', security_group_id)
    return security_group_id

Get a security group ID.

Args:
name (str): Security Group name to find.
env (str): Deployment environment to search.
region (str): AWS Region to search.

Returns:
str: ID of Security Group, e.g. sg-xxxx.

Raises:
AssertionError: Call to Gate API was not successful.
SpinnakerSecurityGroupError: Security Group _name_ was not found for
_env_ in _region_.


def stage_redis(self, variable, data):

        if isinstance(data, int):
            data = str(data)

        if variable.endswith('Binary'):
            try:
                data = base64.b64decode(data)
            except binascii.Error:
                msg = 'The Binary staging data for variable {} is not properly base64 encoded.'
                msg = msg.format(variable)
                sys.exit(msg)
        elif variable.endswith('BinaryArray'):
            if isinstance(data, string_types):
                data = json.loads(data)

            try:

                decoded_data = []
                for d in data:
                    d_decoded = base64.b64decode(d)
                    decoded_data.append(d_decoded)
                data = decoded_data
            except binascii.Error:
                msg = 'The BinaryArray staging data for variable {} is not properly base64 encoded.'
                msg = msg.format(variable)
                sys.exit(msg)
        self.log.info(u'[stage] Creating variable {}'.format(variable))
        self.tcex.playbook.create(variable, data)

Stage data in Redis.

Args:
variable (str): The Redis variable name.
data (dict|list|str): The data to store in Redis.


def id_by_index(index, resources):

        if index < 0 or index >= len(resources):
            return ''

        try:
            return resources[index].header_signature
        except AttributeError:
            return resources[index].address

Helper method to fetch the id or address of a resource by its index

Args:
resources (list of objects): The resources to be paginated
index (integer): The index of the target resource

Returns:
str: The address or header_signature of the resource,
returns an empty string if not found


def __init__(self, base_fd, handlers, pathspec=None, progress_callback=None):

    del pathspec
    self.base_fd = base_fd
    self.progress_callback = progress_callback
    self._handlers = handlers
    if base_fd is None:
      self.pathspec = rdf_paths.PathSpec()
    else:

      self.pathspec = base_fd.pathspec.Copy()
    self.metadata = {}

Constructor.

Args:
base_fd: A handler to the predecessor handler.
handlers: A mapping from rdf_paths.PathSpec.PathType to classes
implementing VFSHandler.
pathspec: The pathspec to open.
progress_callback: A callback to indicate that the open call is still
working but needs more time.

Raises:
IOError: if this handler can not be instantiated over the
requested path.


def _merge_input_ids_with_input_values(self, input_ids: Optional[torch.Tensor]=None, input_values: Optional[torch.Tensor]=None, input_values_cutoffs: Optional[torch.Tensor]=None, labels: Optional[torch.Tensor]=None) -> Optional[torch.Tensor]:
    inputs_embeds = self.embed_text_tokens(input_ids)
    if input_values is not None:
        input_values_cutoffs = nn.functional.pad(input_values_cutoffs, (1, 0))
        audio_lengths = input_values_cutoffs[input_values_cutoffs >= 0].diff()
        audio_lengths = audio_lengths[audio_lengths > 0]
        input_values_mask = torch.arange(input_values_cutoffs.max(), device=input_values.device).expand(len(audio_lengths), -1)
        input_values_mask = input_values_mask < audio_lengths.unsqueeze(1)
        with torch.no_grad():
            audio_tokens_list = []
            for batch_input_values, batch_input_values_cutoffs in zip(input_values, input_values_cutoffs):
                batch_input_values_cutoffs = batch_input_values_cutoffs[batch_input_values_cutoffs >= 0]
                for i in range(batch_input_values_cutoffs.shape[0] - 1):
                    start_idx = batch_input_values_cutoffs[i]
                    end_idx = batch_input_values_cutoffs[i + 1]
                    audio_batch = batch_input_values[..., start_idx:end_idx]
                    codec_outputs = self.codec_model.encode(audio_batch.unsqueeze(0))
                    codebook_ids = codec_outputs.audio_codes.transpose(1, -1)
                    audio_tokens_list.append(codebook_ids[0])
            max_audio_frames = max((el.shape[0] for el in audio_tokens_list))
            batched_audio_token_ids = torch.stack([nn.functional.pad(el, (0, 0, 0, max_audio_frames - el.shape[0])) for el in audio_tokens_list])
            audio_codes_mask = self.codec_model.get_audio_codes_mask(input_values_mask)
        audio_token_id = self.config.audio_token_id
        audio_token_mask = input_ids == audio_token_id
        audio_embeds = self.backbone_model.embed_tokens(batched_audio_token_ids)
        inputs_embeds[audio_token_mask] = audio_embeds[audio_codes_mask]
        audio_eos_frame_ids = torch.ones((1, 1, self.config.num_codebooks), device=input_ids.device, dtype=torch.long) * self.config.codebook_eos_token_id
        audio_eos_embeds = self.backbone_model.embed_tokens(audio_eos_frame_ids).squeeze(1)
        audio_eos_token_mask = input_ids == self.config.audio_eos_token_id
        inputs_embeds[audio_eos_token_mask] = audio_eos_embeds.repeat(audio_eos_token_mask.sum(), 1)
        if labels is not None:
            labels_expanded = labels.unsqueeze(-1).repeat(1, 1, self.config.num_codebooks)
            labels_expanded[audio_token_mask] = batched_audio_token_ids[audio_codes_mask]
            labels_expanded[audio_eos_token_mask] = audio_eos_frame_ids
            depth_decoder_ignore_frames_idxs = (labels == -101).nonzero(as_tuple=True)
            labels_expanded[depth_decoder_ignore_frames_idxs[0], depth_decoder_ignore_frames_idxs[1], 1:] = -100
            labels = labels_expanded
    return {'inputs_embeds': inputs_embeds, 'labels': labels}

Merges the input_ids and input_values to produce a single inputs_embeds tensor:
1 - Infers the codec model on the input_values to retreive codebook token.
2 - Embeds codebook tokens and places them at the correct positions in the inputs_embeds tensor.
3 - If labels are provided, expands them to match codebook dimensions and position the target codebook tokens in the inputs_embeds tensor.

Args:
input_ids (`torch.Tensor` of shape `(batch_size, sequence_length)`):
The input ids to embed.
input_values (`torch.Tensor` of shape `(batch_size, channels, audio_sequence_length)`):
The audio input values to embed.
input_values_cutoffs (`torch.Tensor` of shape `(batch_size, max_num_audio)`):
The cutoffs of the audio input values relative to its batch index, padded with -1 when no audio.


def GetDataStream(self, name, case_sensitive=True):
    if (not isinstance(name, py2to3.STRING_TYPES)):
        raise ValueError('Name is not a string.')
    name_lower = name.lower()
    matching_data_stream = None
    for data_stream in self._GetDataStreams():
        if (data_stream.name == name):
            return data_stream
        if ((not case_sensitive) and (data_stream.name.lower() == name_lower)):
            if (not matching_data_stream):
                matching_data_stream = data_stream
    return matching_data_stream

Retrieves a data stream by name.

Args:
name (str): name of the data stream.
case_sensitive (Optional[bool]): True if the name is case sensitive.

Returns:
DataStream: a data stream or None if not available.

Raises:
ValueError: if the name is not string.


def get(self):
    return dict(interfaces=self.interfaces.getall(), instances=self.instances.getall())

Returns the spanning-tree configuration as a dict object

The dictionary object represents the entire spanning-tree
configuration derived from the nodes running config.  This
includes both globally configuration attributes as well as
interfaces and instances.  See the StpInterfaces and StpInstances
classes for the key/value pair definitions.

Note:
See the individual classes for detailed message structures

Returns:
A Python dictionary object of key/value pairs the represent
the entire supported spanning-tree configuration::

{
"mode": [mstp, none],
"interfaces": {...},
"instances": {...}
}


def AddProcessingOptions(self, argument_group):

    argument_group.add_argument(
        '--single_process', '--single-process', dest='single_process',
        action='store_true', default=False, help=(
            'Indicate that the tool should run in a single process.'))

    argument_helper_names = ['temporary_directory', 'workers', 'zeromq']
    if self._CanEnforceProcessMemoryLimit():
      argument_helper_names.append('process_resources')
    helpers_manager.ArgumentHelperManager.AddCommandLineArguments(
        argument_group, names=argument_helper_names)

Adds the processing options to the argument group.

Args:
argument_group (argparse._ArgumentGroup): argparse argument group.


def indent_xml(elem, level=0, more_sibs=False):
    i = '\n'
    pad = '    '
    if level:
        i += ((level - 1) * pad)
    num_kids = len(elem)
    if num_kids:
        if ((not elem.text) or (not elem.text.strip())):
            elem.text = (i + pad)
            if level:
                elem.text += pad
        count = 0
        for kid in elem:
            if (kid.tag == 'data'):
                kid.text = '*DATA*'
            indent_xml(kid, (level + 1), (count < (num_kids - 1)))
            count += 1
        if ((not elem.tail) or (not elem.tail.strip())):
            elem.tail = i
            if more_sibs:
                elem.tail += pad
    elif (level and ((not elem.tail) or (not elem.tail.strip()))):
        elem.tail = i
        if more_sibs:
            elem.tail += pad

Indent an xml element object to prepare for pretty printing.

To avoid changing the contents of the original Element, it is
recommended that a copy is made to send to this function.

Args:
elem: Element to indent.
level: Int indent level (default is 0)
more_sibs: Bool, whether to anticipate further siblings.


def AddNewSpecification(self, identifier):

    if identifier in self._format_specifications:
      raise KeyError(
          'Format specification {0:s} is already defined in store.'.format(
              identifier))

    self._format_specifications[identifier] = FormatSpecification(identifier)

    return self._format_specifications[identifier]

Adds a new format specification.

Args:
identifier (str): format identifier, which should be unique for the store.

Returns:
FormatSpecification: format specification.

Raises:
KeyError: if the store already contains a specification with
the same identifier.


def createGroup(self, group, vendorSpecific=None):

        response = self.createGroupResponse(group, vendorSpecific)
        return self._read_boolean_response(response)

See Also: createGroupResponse()

Args:
group:
vendorSpecific:

Returns:


def __init__(self, pyregf_key, key_path=''):

    super(REGFWinRegistryKey, self).__init__(key_path=key_path)
    self._pyregf_key = pyregf_key

Initializes a Windows Registry key object.

Args:
pyregf_key (pyregf.key): pyregf key object.
key_path (Optional[str]): Windows Registry key path.


class TFBaseModelOutputWithPoolingAndNoAttention(ModelOutput):
    last_hidden_state: Optional[tf.Tensor] = None
    pooler_output: Optional[tf.Tensor] = None
    hidden_states: Optional[Tuple[tf.Tensor, ...]] = None

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

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

Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.


def run_step(context):
    logger.debug('started')
    context.assert_key_has_value(key='contextClear', caller=__name__)
    for k in context['contextClear']:
        logger.debug(f'removing {k} from context')
        context.pop(k, None)
        logger.info(f'removed {k} from context')
    logger.debug('done')

Remove specified keys from context.

Args:
Context is a dictionary or dictionary-like.
context['contextClear'] must exist. It's a dictionary.
Will iterate context['contextClear'] and remove those keys from
context.

For example, say input context is:
key1: value1
key2: value2
key3: value3
key4: value4
contextClear:
- key2
- key4
- contextClear

This will result in return context:
key1: value1
key3: value3


def GetEntries(self, parser_mediator, top_level=None, **unused_kwargs):
    for (root, key, datetime_value) in interface.RecurseKey(top_level):
        if (not isinstance(datetime_value, datetime.datetime)):
            continue
        event_data = plist_event.PlistTimeEventData()
        event_data.key = key
        event_data.root = root
        event = time_events.PythonDatetimeEvent(datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
        parser_mediator.ProduceEventWithEventData(event, event_data)

Simple method to exact date values from a Plist.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
top_level (dict[str, object]): plist top-level key.


def CreateWithLock(self, urn, aff4_type, token=None, age=NEWEST_TIME, force_new_version=True, blocking=True, blocking_lock_timeout=10, blocking_sleep_interval=1, lease_time=100):
    if (not data_store.AFF4Enabled()):
        raise NotImplementedError('AFF4 data store has been disabled.')
    transaction = self._AcquireLock(urn, blocking=blocking, blocking_lock_timeout=blocking_lock_timeout, blocking_sleep_interval=blocking_sleep_interval, lease_time=lease_time)
    return self.Create(urn, aff4_type, mode='rw', token=token, age=age, force_new_version=force_new_version, transaction=transaction)

Creates a new object and locks it.

Similar to OpenWithLock below, this creates a locked object. The difference
is that when you call CreateWithLock, the object does not yet have to exist
in the data store.

Args:
urn: The object to create.
aff4_type: The desired type for this object.
token: The Security Token to use for opening this item.
age: The age policy used to build this object. Only makes sense when mode
has "r".
force_new_version: Forces the creation of a new object in the data_store.
blocking: When True, wait and repeatedly try to grab the lock.
blocking_lock_timeout: Maximum wait time when sync is True.
blocking_sleep_interval: Sleep time between lock grabbing attempts. Used
when blocking is True.
lease_time: Maximum time the object stays locked. Lock will be considered
released when this time expires.

Returns:
An AFF4 object of the desired type and mode.

Raises:
AttributeError: If the mode is invalid.


def from_config(cls, config):

    config = config.copy()
    function_keys = [
        'kernel_posterior_fn',
        'kernel_posterior_tensor_fn',
        'kernel_prior_fn',
        'kernel_divergence_fn',
        'bias_posterior_fn',
        'bias_posterior_tensor_fn',
        'bias_prior_fn',
        'bias_divergence_fn',
    ]
    for function_key in function_keys:
      serial = config[function_key]
      function_type = config.pop(function_key + '_type')
      if serial is not None:
        config[function_key] = tfp_layers_util.deserialize_function(
            serial,
            function_type=function_type)
    return cls(**config)

Creates a layer from its config.

This method is the reverse of `get_config`, capable of instantiating the
same layer from the config dictionary.

Args:
config: A Python dictionary, typically the output of `get_config`.

Returns:
layer: A layer instance.


def HandleNetworkInterfaces(self, result):
    network_interfaces = self._ExtractInterfaceMetadata(result)
    if self.network_setup_enabled:
        self.network_setup.EnableNetworkInterfaces([interface.name for interface in network_interfaces[1:]])
    for interface in network_interfaces:
        if self.ip_forwarding_enabled:
            self.ip_forwarding.HandleForwardedIps(interface.name, interface.forwarded_ips, interface.ip)

Called when network interface metadata changes.

Args:
result: dict, the metadata response with the network interfaces.


def scatter_max(self, sparse_delta, use_locking=False, name=None):
    if not isinstance(sparse_delta, indexed_slices.IndexedSlices):
        raise TypeError('sparse_delta is not IndexedSlices: %s' % sparse_delta)
    return gen_state_ops.scatter_max(self._variable, sparse_delta.indices, sparse_delta.values, use_locking=use_locking, name=name)

Updates this variable with the max of `tf.IndexedSlices` and itself.

Args:
sparse_delta: `tf.IndexedSlices` to use as an argument of max with this
variable.
use_locking: If `True`, use locking during the operation.
name: the name of the operation.

Returns:
A `Tensor` that will hold the new value of this variable after
the scattered maximization has completed.

Raises:
TypeError: if `sparse_delta` is not an `IndexedSlices`.


def join(self, other, *args, **kwarg):
    event = Event(*args, **kwarg)
    if self.intersects(other):
        if self.starts_within(other):
            event.begin = other.begin
        else:
            event.begin = self.begin
        if self.ends_within(other):
            event.end = other.end
        else:
            event.end = self.end
        return event
    raise ValueError("Cannot join {} with {}: they don't intersect.".format(self, other))

Create a new event which covers the time range of two intersecting events

All extra parameters are passed to the Event constructor.

Args:
other: the other event

Returns:
a new Event instance


def apply_func_to_select_indices(self, axis, func, indices, keep_remaining=False):
    if (self.partitions.size == 0):
        return np.array([[]])
    if isinstance(indices, dict):
        dict_indices = indices
        indices = list(indices.keys())
    else:
        dict_indices = None
    if (not isinstance(indices, list)):
        indices = [indices]
    partitions_dict = self._get_dict_of_block_index(axis, indices, ordered=(not keep_remaining))
    if (not axis):
        partitions_for_apply = self.partitions.T
    else:
        partitions_for_apply = self.partitions
    if (dict_indices is not None):

        def local_to_global_idx(partition_id, local_idx):
            if (partition_id == 0):
                return local_idx
            if (axis == 0):
                cumulative_axis = np.cumsum(self.block_widths)
            else:
                cumulative_axis = np.cumsum(self.block_lengths)
            return (cumulative_axis[(partition_id - 1)] + local_idx)
        if (not keep_remaining):
            result = np.array([self._apply_func_to_list_of_partitions(func, partitions_for_apply[o_idx], func_dict={i_idx: dict_indices[local_to_global_idx(o_idx, i_idx)] for i_idx in list_to_apply if (i_idx >= 0)}) for (o_idx, list_to_apply) in partitions_dict])
        else:
            result = np.array([(partitions_for_apply[i] if (i not in partitions_dict) else self._apply_func_to_list_of_partitions(func, partitions_for_apply[i], func_dict={idx: dict_indices[local_to_global_idx(i, idx)] for idx in partitions_dict[i] if (idx >= 0)})) for i in range(len(partitions_for_apply))])
    elif (not keep_remaining):
        result = np.array([self._apply_func_to_list_of_partitions(func, partitions_for_apply[idx], internal_indices=list_to_apply) for (idx, list_to_apply) in partitions_dict])
    else:
        result = np.array([(partitions_for_apply[i] if (i not in partitions_dict) else self._apply_func_to_list_of_partitions(func, partitions_for_apply[i], internal_indices=partitions_dict[i])) for i in range(len(partitions_for_apply))])
    return (self.__constructor__(result.T) if (not axis) else self.__constructor__(result))

Applies a function to select indices.

Note: Your internal function must take a kwarg `internal_indices` for
this to work correctly. This prevents information leakage of the
internal index to the external representation.

Args:
axis: The axis to apply the func over.
func: The function to apply to these indices.
indices: The indices to apply the function to.
keep_remaining: Whether or not to keep the other partitions.
Some operations may want to drop the remaining partitions and
keep only the results.

Returns:
A new BaseFrameManager object, the type of object that called this.


def bucket(self, experiment, user_id, bucketing_id):
    if (not experiment):
        return None
    if (experiment.groupPolicy in GROUP_POLICIES):
        group = self.config.get_group(experiment.groupId)
        if (not group):
            return None
        user_experiment_id = self.find_bucket(bucketing_id, experiment.groupId, group.trafficAllocation)
        if (not user_experiment_id):
            self.config.logger.info(('User "%s" is in no experiment.' % user_id))
            return None
        if (user_experiment_id != experiment.id):
            self.config.logger.info(('User "%s" is not in experiment "%s" of group %s.' % (user_id, experiment.key, experiment.groupId)))
            return None
        self.config.logger.info(('User "%s" is in experiment %s of group %s.' % (user_id, experiment.key, experiment.groupId)))
    variation_id = self.find_bucket(bucketing_id, experiment.id, experiment.trafficAllocation)
    if variation_id:
        variation = self.config.get_variation_from_id(experiment.key, variation_id)
        self.config.logger.info(('User "%s" is in variation "%s" of experiment %s.' % (user_id, variation.key, experiment.key)))
        return variation
    self.config.logger.info(('User "%s" is in no variation.' % user_id))
    return None

For a given experiment and bucketing ID determines variation to be shown to user.

Args:
experiment: Object representing the experiment for which user is to be bucketed.
user_id: ID for user.
bucketing_id: ID to be used for bucketing the user.

Returns:
Variation in which user with ID user_id will be put in. None if no variation.


def from_np_datetimes(np_datetimes):
    ordinals = tf.constant(np_datetimes, dtype=tf.int32) + _ORDINAL_OF_1_1_1970
    return from_ordinals(ordinals, validate=False)

Creates DateTensor from a Numpy array of dtype datetime64.

Args:
np_datetimes: Numpy array of dtype datetime64.

Returns:
DateTensor object.

#### Example

```python
import datetime
import numpy as np

date_tensor_np = np.array(
[[datetime.date(2019, 3, 25), datetime.date(2020, 6, 2)],
[datetime.date(2020, 9, 15), datetime.date(2020, 12, 27)]],
dtype=np.datetime64)

date_tensor = tff.datetime.dates_from_np_datetimes(date_tensor_np)
```


def read_from_hdx(identifier, configuration=None):

        showcase = Showcase(configuration=configuration)
        result = showcase._load_from_hdx('showcase', identifier)
        if result:
            return showcase
        return None

Reads the showcase given by identifier from HDX and returns Showcase object

Args:
identifier (str): Identifier of showcase
configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration.

Returns:
Optional[Showcase]: Showcase object if successful read, None if not


def fit(self, **kwargs):
    if (self.fit_method is not None):
        fit_args = self._fit_params.copy()
        fit_args.update(kwargs)
        getattr(self.instance, self.fit_method)(**fit_args)

Call the fit method of the primitive.

The given keyword arguments will be passed directly to the `fit`
method of the primitive instance specified in the JSON annotation.

If any of the arguments expected by the produce method had been
given during the MLBlock initialization, they will be passed as well.

If the fit method was not specified in the JSON annotation, or if
the primitive is a simple function, this will be a noop.

Args:
**kwargs: Any given keyword argument will be directly passed
to the primitive fit method.

Raises:
TypeError: A `TypeError` might be raised if any argument not
expected by the primitive fit method is given.


def _get_candidates(self):
    candidates = np.where((self.dpp_vector == 0))
    return (None if (len(candidates[0]) == 0) else candidates[0])

Finds the pipelines that are not yet tried.

Returns:
np.array: Indices corresponding to columns in ``dpp_matrix`` that haven't been tried on
``X``. ``None`` if all pipelines have been tried on X.


def bounter(size_mb=None, need_iteration=True, need_counts=True, log_counting=None):
    if (not need_counts):
        return CardinalityEstimator()
    if (size_mb is None):
        raise ValueError('Max size in MB must be provided.')
    if need_iteration:
        if log_counting:
            raise ValueError('Log counting is only supported with CMS implementation (need_iteration=False).')
        return HashTable(size_mb=size_mb)
    else:
        return CountMinSketch(size_mb=size_mb, log_counting=log_counting)

Factory method for bounter implementation.

Args:
size_mb (int): Desired memory footprint of the counter.
need_iteration (Bool): With `True`, create a `HashTable` implementation which can
iterate over inserted key/value pairs.
With `False`, create a `CountMinSketch` implementation which performs better in limited-memory scenarios,
but does not support iteration over elements.
need_counts (Bool): With `True`, construct the structure normally. With `False`, ignore all remaining
parameters and create a minimalistic cardinality counter based on hyperloglog which only takes 64KB memory.
log_counting (int): Counting to use with `CountMinSketch` implementation. Accepted values are
`None` (default counting with 32-bit integers), 1024 (16-bit), 8 (8-bit).
See `CountMinSketch` documentation for details.
Raise ValueError if not `None `and `need_iteration` is `True`.


def mouse_event_callback(self, window, xpos, ypos):

        self.example.mouse_position_event(xpos, ypos)

Mouse event callback from glfw.
Translates the events forwarding them to :py:func:`cursor_event`.

Args:
window: The window
xpos: viewport x pos
ypos: viewport y pos


def _modeIsValid(self, mode):
    try:
        return (mode in self.modes.keys())
    except AttributeError as e:
        if (mode in self.isValidMode.keys()):
            if (mode in self.isValidMode.keys()):
                return True
    return False

Verification of whether the mode is a correct option to be used.

Args:
-----
mode: Mode to be executed.

Return:
-------
True if the mode exists in the three main folders.


def _build_url_filters(cls, session: AppSession):
    args = session.args
    filters = [(HTTPSOnlyFilter() if args.https_only else SchemeFilter()), RecursiveFilter(enabled=args.recursive, page_requisites=args.page_requisites), FollowFTPFilter(follow=args.follow_ftp)]
    if args.no_parent:
        filters.append(ParentFilter())
    if (args.domains or args.exclude_domains):
        filters.append(BackwardDomainFilter(args.domains, args.exclude_domains))
    if (args.hostnames or args.exclude_hostnames):
        filters.append(HostnameFilter(args.hostnames, args.exclude_hostnames))
    if args.tries:
        filters.append(TriesFilter(args.tries))
    if ((args.level and args.recursive) or args.page_requisites_level):
        filters.append(LevelFilter(args.level, inline_max_depth=args.page_requisites_level))
    if (args.accept_regex or args.reject_regex):
        filters.append(RegexFilter(args.accept_regex, args.reject_regex))
    if (args.include_directories or args.exclude_directories):
        filters.append(DirectoryFilter(args.include_directories, args.exclude_directories))
    if (args.accept or args.reject):
        filters.append(BackwardFilenameFilter(args.accept, args.reject))
    return filters

Create the URL filter instances.

Returns:
A list of URL filter instances


def CheckAddressState(self, script_hash):

        for key, contract in self._contracts.items():
            if contract.ScriptHash.ToBytes() == script_hash.ToBytes():
                return AddressState.InWallet
        for watch in self._watch_only:
            if watch == script_hash:
                return AddressState.InWallet | AddressState.WatchOnly
        return AddressState.NoState

Determine the address state of the provided script hash.

Args:
script_hash (UInt160): a script hash to determine the address state of.

Returns:
AddressState: the address state.


def convert(self):
    saved_model_convert_result = self._convert_as_saved_model()
    if saved_model_convert_result:
        return saved_model_convert_result
    return super(TFLiteKerasModelConverter, self).convert()

Converts a Keras model based on instance variables.

Returns:
The converted data in serialized format, either a TFLite Flatbuffer or
a Graphviz graph depending on value in `output_format`.

Raises:
ValueError:
Input shape is not specified.
None value for dimension in input_tensor.


def clean_registration_ids(self, registration_ids=[]):

        valid_registration_ids = []
        for registration_id in registration_ids:
            details = self.registration_info_request(registration_id)
            if details.status_code == 200:
                valid_registration_ids.append(registration_id)
        return valid_registration_ids

Checks registration ids and excludes inactive ids

Args:
registration_ids (list, optional): list of ids to be cleaned

Returns:
list: cleaned registration ids


def GetKeyByPath(self, key_path):

    key_path_upper = key_path.upper()
    if key_path_upper.startswith(self._key_path_prefix_upper):
      relative_key_path = key_path[self._key_path_prefix_length:]
    elif key_path.startswith(definitions.KEY_PATH_SEPARATOR):
      relative_key_path = key_path
      key_path = ''.join([self._key_path_prefix, key_path])
    else:
      return None

    try:
      regf_key = self._regf_file.get_key_by_path(relative_key_path)
    except IOError:
      regf_key = None
    if not regf_key:
      return None

    return REGFWinRegistryKey(regf_key, key_path=key_path)

Retrieves the key for a specific path.

Args:
key_path (str): Windows Registry key path.

Returns:
WinRegistryKey: Registry key or None if not available.


def _AddsAnalysisProcessStatusTableRow(self, process_status, table_view):
    used_memory = self._FormatSizeInUnitsOf1024(process_status.used_memory)
    events = ''
    if ((process_status.number_of_consumed_events is not None) and (process_status.number_of_consumed_events_delta is not None)):
        events = '{0:d} ({1:d})'.format(process_status.number_of_consumed_events, process_status.number_of_consumed_events_delta)
    event_tags = ''
    if ((process_status.number_of_produced_event_tags is not None) and (process_status.number_of_produced_event_tags_delta is not None)):
        event_tags = '{0:d} ({1:d})'.format(process_status.number_of_produced_event_tags, process_status.number_of_produced_event_tags_delta)
    reports = ''
    if ((process_status.number_of_produced_reports is not None) and (process_status.number_of_produced_reports_delta is not None)):
        reports = '{0:d} ({1:d})'.format(process_status.number_of_produced_reports, process_status.number_of_produced_reports_delta)
    table_view.AddRow([process_status.identifier, process_status.pid, process_status.status, used_memory, events, event_tags, reports])

Adds an analysis process status table row.

Args:
process_status (ProcessStatus): processing status.
table_view (CLITabularTableView): table view.


def crop_image_to_patches(self, images: 'torch.Tensor', min_patches: int, max_patches: int, use_thumbnail: bool=True, patch_size: Optional[Union[Tuple, int, dict]]=None, interpolation: Optional['F.InterpolationMode']=None):
    patch_size_height, patch_size_width = (patch_size.height, patch_size.width)
    original_height, original_width = images.shape[-2:]
    num_columns, num_rows = get_optimal_tiled_canvas((original_height, original_width), (patch_size_height, patch_size_width), min_patches, max_patches)
    target_width = patch_size_width * num_columns
    target_height = patch_size_height * num_rows
    num_blocks = num_columns * num_rows
    resized_image = self.resize(images, SizeDict(height=target_height, width=target_width), interpolation=interpolation)
    processed_images = []
    for i in range(num_blocks):
        column = i % num_columns
        row = i
        box = (column * patch_size_width, row * patch_size_height, (column + 1) * patch_size_width, (row + 1) * patch_size_height)
        patch_image = resized_image[..., box[1]:box[3], box[0]:box[2]]
        processed_images.append(patch_image)
    if use_thumbnail and len(processed_images) != 1:
        thumbnail_img = self.resize(images, patch_size, interpolation=interpolation)
        processed_images.append(thumbnail_img)
    processed_images = torch.stack(processed_images, dim=0).transpose(0, 1).contiguous()
    return processed_images

Crop the images to patches and return a list of cropped images.
The number of patches and their grid arrangement are determined by the original image size,
the target patch size and the minimum and maximum number of patches.
The aspect ratio of the patches grid is chosen to be the closest to the original image aspect ratio.

Args:
images (`torch.Tensor`):
The images to be cropped.
min_patches (`int`):
The minimum number of patches to be extracted from the image.
max_patches (`int`):
The maximum number of patches to be extracted from the image.
use_thumbnail (`bool`, *optional*, defaults to `True`):
Whether to add a thumbnail image to the list of cropped patches.
patch_size (`int`, `Tuple[int, int]`, `dict`, *optional*):
The size of the output patches.
The format of the image data. If `None`, the format is inferred from the input image.

Returns:
List[`PIL.Image.Image`] or List[np.ndarray]: The list of cropped images.


def get_parameter_bounds(self, include_frozen=False):

        if include_frozen:
            return self.parameter_bounds
        return list(p
                    for p, f in zip(self.parameter_bounds, self.unfrozen_mask)
                    if f)

Get a list of the parameter bounds

Args:
include_frozen (Optional[bool]): Should the frozen parameters be
included in the returned value? (default: ``False``)


def do_hook_actions(self, actions, hook_type):
    logger.log_debug('call {} hook actions.'.format(hook_type))
    for action in actions:
        if (isinstance(action, dict) and (len(action) == 1)):
            (var_name, hook_content) = list(action.items())[0]
            hook_content_eval = self.session_context.eval_content(hook_content)
            logger.log_debug('assignment with hook: {} = {} => {}'.format(var_name, hook_content, hook_content_eval))
            self.session_context.update_test_variables(var_name, hook_content_eval)
        else:
            logger.log_debug('call hook function: {}'.format(action))
            self.session_context.eval_content(action)

call hook actions.

Args:
actions (list): each action in actions list maybe in two format.

format1 (dict): assignment, the value returned by hook function will be assigned to variable.
{"var": "${func()}"}
format2 (str): only call hook functions.
${func()}

hook_type (enum): setup/teardown


def __dir__() -> list[str]:
    return ['__all__', 'LAZY_MODULES', 'print_current_imports']

`lazy_imports` public API.

Because `globals()` contains hundreds of symbols, we overwrite `dir(module)`
to avoid poluting the namespace during auto-completion.

Returns:
public symbols


def reqs(amend: bool=False, stage: bool=False):
    changed_files = CTX.repo.changed_files()
    if (('requirements.txt' in changed_files) or ('requirements-dev.txt' in changed_files)):
        LOGGER.error('Requirements have changed; cannot update them')
        sys.exit((- 1))
    _write_reqs(amend, stage)

Write requirements files

Args:
amend: amend last commit with changes
stage: stage changes


def _transform_col(self, x, i):
    labels = self.label_encoder._transform_col(x, i)
    label_max = self.label_encoder.label_maxes[i]
    index = np.array(range(len(labels)))
    i = index[(labels > 0)]
    j = (labels[(labels > 0)] - 1)
    if (len(i) > 0):
        return sparse.coo_matrix((np.ones_like(i), (i, j)), shape=(x.shape[0], label_max))
    else:
        return None

Encode one categorical column into sparse matrix with one-hot-encoding.

Args:
x (pandas.Series): a categorical column to encode
i (int): column index

Returns:
X (scipy.sparse.coo_matrix): sparse matrix encoding a categorical
variable into dummy variables


def _gen_sentence(self, assetid_body_tuple):
    (asset_id, body) = assetid_body_tuple
    text = self._process(body)
    sentence = LabeledSentence(text, labels=[('DOC_%s' % str(asset_id))])
    return sentence

Takes an assetid_body_tuple and returns a Doc2Vec LabeledSentence

Args:
assetid_body_tuple (tuple): (assetid, bodytext) pair


def use_spec(self, spec: DNASpec) -> 'DNA':
    if not isinstance(spec, DNASpec):
        raise ValueError(f"Argument 'spec' must be a `pg.DNASpec` object. Encountered: {spec!r}.")
    if self._spec is spec:
        return self

    def _use_spec_for_child_choices(spec: DNASpec, children: List[DNA]):

        assert spec.is_categorical, spec
        if spec.num_choices != len(children):
            raise ValueError(f'Number of choices ({spec.num_choices}) does not match with the number of child values (len(children)). Spec: {spec!r}, Children: {children!r}.')
        for i, child in enumerate(children):
            subchoice = spec.subchoice(i)
            child.use_spec(subchoice)
        child_values = [c.value for c in children]
        if spec.sorted and sorted(child_values) != child_values:
            raise ValueError(f'Child values {child_values!r} are not sorted. Spec: {spec!r}.')
        if spec.distinct and len(set(child_values)) != len(child_values):
            raise ValueError(f'Child values {child_values!r} are not distinct. Spec: {spec!r}.')
    while spec.is_space and len(spec.elements) == 1:
        spec = spec.elements[0]
    if spec.is_space:
        if self.value is not None:
            raise ValueError(f'DNA value type mismatch. Value: {self.value}, Spec: {spec!r}.')
        if len(spec.elements) != len(self.children):
            raise ValueError(f'Length of DNA child values ({len(self.children)}) is different from the number of elements ({len(spec.elements)}) in Spec: {spec!r}.')
        for i, elem_spec in enumerate(spec.elements):
            self.children[i].use_spec(elem_spec)
    elif spec.is_categorical:
        if spec.num_choices == 1:
            if not isinstance(self.value, int):
                raise ValueError(f'DNA value type mismatch. Value: {self.value}, Spec: {spec!r}.')
            if self.value >= len(spec.candidates):
                raise ValueError(f'Value of DNA is out of range according to the DNA spec. Value: {self.value}, Spec: {spec!r}.')
            chosen_candidate = spec.candidates[self.value]
            assert chosen_candidate.is_space, chosen_candidate
            if not chosen_candidate.elements and self.children:
                raise ValueError(f'There is no DNA spec for child DNA values. Child values: {self.children}.')
            if len(chosen_candidate.elements) > 1:
                if len(chosen_candidate.elements) != len(self.children):
                    raise ValueError(f'Number of elements in child templates ({len(chosen_candidate.elements)}) does not match with the length of children ({len(self.children)}) from DNA: {self!r}, Spec: {chosen_candidate}.')
                for i, elem_spec in enumerate(chosen_candidate.elements):
                    self.children[i].use_spec(elem_spec)
            elif len(chosen_candidate.elements) == 1:
                sub_spec = chosen_candidate
                while sub_spec.is_space and len(sub_spec.elements) == 1:
                    sub_spec = sub_spec.elements[0]
                if sub_spec.is_numerical or sub_spec.is_custom_decision_point:
                    if len(self.children) != 1:
                        raise ValueError(f'Encountered more than 1 value.Child value: {self.children}, Spec: {sub_spec}.')
                    self.children[0].use_spec(sub_spec)
                else:
                    assert sub_spec.is_categorical, sub_spec
                    _use_spec_for_child_choices(sub_spec, self.children)
        else:
            if self.value is not None:
                raise ValueError(f'Cannot apply multi-choice DNA spec on value {self.value}: {spec!r}.')
            _use_spec_for_child_choices(spec, self.children)
    elif spec.is_numerical:
        if not isinstance(self.value, float):
            raise ValueError(f'DNA value type mismatch. Value: {self.value}, Spec: {spec!r}.')
        if self.value < spec.min_value:
            raise ValueError(f'DNA value should be no less than {spec.min_value}. Encountered {self.value}, Spec: {spec!r}.')
        if self.value > spec.max_value:
            raise ValueError(f'DNA value should be no greater than {spec.max_value}. Encountered {self.value}, Spec: {spec!r}.')
    else:
        assert spec.is_custom_decision_point, spec
        if not isinstance(self.value, str):
            raise ValueError(f'DNA value type mismatch, Value: {self.value!r}, Spec: {spec!r}.')
    self._spec = spec
    return self

Use a DNA spec for this node and children recursively.

Args:
spec: DNA spec.

Returns:
Self.

Raises:
ValueError: current DNA tree does not conform to the DNA spec.


def data_file(file_fmt, info=None, **kwargs):
    if isinstance(info, dict):
        kwargs['hash_key'] = hashlib.sha256(json.dumps(info).encode('utf-8')).hexdigest()
        kwargs.update(info)
    return utils.fstr(fmt=file_fmt, **kwargs)

Data file name for given infomation

Args:
file_fmt: file format in terms of f-strings
info: dict, to be hashed and then pass to f-string using 'hash_key'
these info will also be passed to f-strings
**kwargs: arguments for f-strings

Returns:
str: data file name


def _SkipFieldMessage(tokenizer):

  if tokenizer.TryConsume('<'):
    delimiter = '>'
  else:
    tokenizer.Consume('{')
    delimiter = '}'

  while not tokenizer.LookingAt('>') and not tokenizer.LookingAt('}'):
    _SkipField(tokenizer)

  tokenizer.Consume(delimiter)

Skips over a field message.

Args:
tokenizer: A tokenizer to parse the field name and values.


def get_callable_name(func):
    try:
        return meta_util_six.get_funcname(func)
    except AttributeError:
        if isinstance(func, type):
            return repr(func).replace("<type '", '').replace("'>", '')
        elif hasattr(func, '__name__'):
            return func.__name__
        else:
            raise NotImplementedError(('cannot get func_name of func=%rtype(func)=%r' % (func, type(func))))

Works on must functionlike objects including str, which has no func_name

Args:
func (function):

Returns:
str:

CommandLine:
python -m utool.util_str --exec-get_callable_name

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import *  # NOQA
>>> func = len
>>> result = get_callable_name(func)
>>> print(result)
len


def _CreateLogicalLines(tokens):
    formatted_tokens = []
    prev_tok = None
    for tok in tokens:
        tok = TokenInfo(*tok)
        if prev_tok and prev_tok.line.rstrip().endswith('\\') and (prev_tok.start[0] < tok.start[0]):
            ctok = TokenInfo(type=CONTINUATION, string='\\', start=(prev_tok.start[0], prev_tok.start[1] + 1), end=(prev_tok.end[0], prev_tok.end[0] + 2), line=prev_tok.line)
            ctok.lineno = ctok.start[0]
            ctok.column = ctok.start[1]
            ctok.value = '\\'
            formatted_tokens.append(format_token.FormatToken(ctok, 'CONTINUATION'))
        tok.lineno = tok.start[0]
        tok.column = tok.start[1]
        tok.value = tok.string
        formatted_tokens.append(format_token.FormatToken(tok, token.tok_name[tok.type]))
        prev_tok = tok
    logical_lines, cur_logical_line = ([], [])
    depth = 0
    for tok in formatted_tokens:
        if tok.type == tokenize.ENDMARKER:
            break
        if tok.type == tokenize.NEWLINE:
            logical_lines.append(logical_line.LogicalLine(depth, cur_logical_line))
            cur_logical_line = []
        elif tok.type == tokenize.INDENT:
            depth += 1
        elif tok.type == tokenize.DEDENT:
            depth -= 1
        elif tok.type == tokenize.NL:
            pass
        else:
            if cur_logical_line and (not tok.type == tokenize.COMMENT) and (cur_logical_line[0].type == tokenize.COMMENT):
                logical_lines.append(logical_line.LogicalLine(depth, cur_logical_line))
                cur_logical_line = []
            cur_logical_line.append(tok)
    for line in logical_lines:
        previous = line.first
        bracket_stack = [previous] if previous.OpensScope() else []
        for tok in line.tokens[1:]:
            tok.previous_token = previous
            previous.next_token = tok
            previous = tok
            if tok.OpensScope():
                bracket_stack.append(tok)
            elif tok.ClosesScope():
                bracket_stack[-1].matching_bracket = tok
                tok.matching_bracket = bracket_stack.pop()
    return logical_lines

Separate tokens into logical lines.

Arguments:
tokens: (list of tokenizer.TokenInfo) Tokens generated by tokenizer.

Returns:
A list of LogicalLines.


def DecompressMessageList(cls, packed_message_list):
    compression = packed_message_list.compression
    if (compression == rdf_flows.PackedMessageList.CompressionType.UNCOMPRESSED):
        data = packed_message_list.message_list
    elif (compression == rdf_flows.PackedMessageList.CompressionType.ZCOMPRESSION):
        try:
            data = zlib.decompress(packed_message_list.message_list)
        except zlib.error as e:
            raise DecodingError(('Failed to decompress: %s' % e))
    else:
        raise DecodingError('Compression scheme not supported')
    try:
        result = rdf_flows.MessageList.FromSerializedString(data)
    except rdfvalue.DecodeError:
        raise DecodingError('RDFValue parsing failed.')
    return result

Decompress the message data from packed_message_list.

Args:
packed_message_list: A PackedMessageList rdfvalue with some data in it.

Returns:
a MessageList rdfvalue.

Raises:
DecodingError: If decompression fails.


def add_method(self, m, **kwargs):

        if isinstance(m, types.FunctionType):
            self['function', id(m)] = m
        else:
            f, obj = get_method_vars(m)
            wrkey = (f, id(obj))
            self[wrkey] = obj

Add an instance method or function

Args:
m: The instance method or function to store


def map_parser_to_rules(parser_name: str) -> Tuple[TypeParser, RulesMap]:
    parser: TypeParser
    usable_rules: dict[str, RuleWrapper]
    if parser_name == 'parse_str':
        parser = Parsers['parse_str']
        usable_rules = TextRules
    elif parser_name == 'parse_int':
        parser = Parsers['parse_int']
        usable_rules = NumericRules
    elif parser_name == 'parse_float':
        parser = Parsers['parse_float']
        usable_rules = NumericRules
    else:
        raise ValueError('Invalid parser specified.')
    parser.__name__ = parser_name
    return (parser, usable_rules)

Check if the chosen parser exists and return the matching
parser function and available rule mappings.

Args:
* parser: string

Returns: Tuple, with
* TypeParser: Func that parses Any to Type
* RulesMap: Dict of rule name to rule wrapper

Raises:
* ValueError: if non-existent parser name provided


def make_edge_vectors(adjacency_matrix, num_edge_types, depth, name=None):

  with tf.variable_scope(name, default_name="edge_vectors"):
    att_adj_vectors_shape = [num_edge_types, depth]
    adjacency_matrix_shape = common_layers.shape_list(adjacency_matrix)
    adj_vectors = (
        tf.get_variable(
            "adj_vectors",
            att_adj_vectors_shape,
            initializer=tf.random_normal_initializer(0, depth**-0.5)) *
        (depth**0.5))

    adjacency_matrix_one_hot = tf.one_hot(adjacency_matrix, num_edge_types)

    att_adj_vectors = tf.matmul(
        tf.reshape(tf.to_float(adjacency_matrix_one_hot), [-1, num_edge_types]),
        adj_vectors)
    return tf.reshape(att_adj_vectors,
                      [adjacency_matrix_shape[0], adjacency_matrix_shape[1],
                       adjacency_matrix_shape[2], depth])

Gets edge vectors for the edge types in the adjacency matrix.

Args:
adjacency_matrix: A [batch, num_nodes, num_nodes] tensor of ints.
num_edge_types: Number of different edge types
depth: Number of channels
name: a string
Returns:
A [batch, num_nodes, num_nodes, depth] vector of tensors


def get_pattern_actual_step(self, patternnumber):
    _checkPatternNumber(patternnumber)
    address = _calculateRegisterAddress('actualstep', patternnumber)
    return self.read_register(address, 0)

Get the 'actual step' parameter for a given pattern.

Args:
patternnumber (integer): 0-7

Returns:
The 'actual step' parameter (int).


def constant_value(pred):
    if isinstance(pred, tensor.Tensor):
        return tensor_util.constant_value(pred)
    if pred in {0, 1}:
        return bool(pred)
    if isinstance(pred, bool):
        return pred
    if isinstance(pred, variables.Variable):
        return None
    raise TypeError('`pred` must be a Tensor, or a Python bool, or 1 or 0. Found instead: %s' % type(pred))

Return the bool value for `pred`, or None if `pred` had a dynamic value.

Args:
pred: A scalar, either a Python bool or a TensorFlow boolean variable
or tensor, or the Python integer 1 or 0.

Returns:
True or False if `pred` has a constant boolean value, None otherwise.

Raises:
TypeError: If `pred` is not a Variable, Tensor or bool, or Python
integer 1 or 0.


def _convert_from_saved_model(self, graph_def):
    self._save_conversion_params_metric(graph_def)
    quant_mode = QuantizationMode(self.optimizations, self.target_spec, self.representative_dataset, graph_def, self._experimental_disable_per_channel, self.experimental_new_dynamic_range_quantizer, self._experimental_low_bit_qat, self._experimental_full_integer_quantization_bias_type, self._experimental_variable_quantization, self._experimental_strict_qdq)
    self._validate_inference_input_output_types(quant_mode)
    converter_kwargs = {'enable_tflite_resource_variables': self.experimental_enable_resource_variables}
    converter_kwargs.update(self._get_base_converter_args())
    converter_kwargs.update(quant_mode.converter_flags())
    result = _convert_saved_model(**converter_kwargs)
    return self._optimize_tflite_model(result, quant_mode, _build_conversion_flags(**converter_kwargs).debug_options, quant_io=self.experimental_new_quantizer)

Helper method that converts saved model.

Args:
graph_def: GraphDef object for the model, used only for stats.

Returns:
The converted TFLite model.


def describe(self, **kwargs):
    description = {'label': self.label, 'details': inspect.cleandoc(self.details), 'required': self.required, 'many': self.many, 'spec': self.spec, 'default': self.default, 'type': (self.type or 'unspecified')}
    description.update(kwargs)
    return description

Describe this parameter instance for purpose of self-documentation.

Args:
kwargs (dict): dictionary of additional description items for
extending default description

Returns:
dict: dictionary of description items

Suggested way for overriding description fields or extending it with
additional items is calling super class method with new/overriden
fields passed as keyword arguments like following:

.. code-block:: python

class DummyParam(BaseParam):
def description(self, **kwargs):
super().describe(is_dummy=True, **kwargs)


def console_from_file(filename: str) -> tcod.console.Console:

    return tcod.console.Console._from_cdata(
        lib.TCOD_console_from_file(filename.encode("utf-8"))
    )

Return a new console object from a filename.

The file format is automactially determined.  This can load REXPaint `.xp`,
ASCII Paint `.apf`, or Non-delimited ASCII `.asc` files.

Args:
filename (Text): The path to the file, as a string.

Returns: A new :any`Console` instance.


def untar(file_path, extract_folder=None):
    file_path = Path(file_path)
    if (extract_folder is None):
        extract_folder = file_path.parent
    extract_folder = Path(extract_folder)
    tar = tarfile.open(file_path)
    tar.extractall(extract_folder)
    tar.close()

Simple tar archive extractor

Args:
file_path: path to the tar file to be extracted
extract_folder: folder to which the files will be extracted


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

Calls WHOIS Email end point

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


def _gen_rpc_request(self, rpc_id, rpc_func_name, *args, **kwargs):
    data = {'id': rpc_id, 'method': rpc_func_name, 'params': args}
    if kwargs:
        data['kwargs'] = kwargs
    return json.dumps(data, sort_keys=True)

Generates the JSON RPC request.

In the generated JSON string, the fields are sorted by keys in ascending
order.

Args:
rpc_id: int, the id of this RPC.
rpc_func_name: str, the name of the snippet function to execute
on the server.
*args: any, the positional arguments of the RPC.
**kwargs: any, the keyword arguments of the RPC.

Returns:
A string of the JSON RPC request.


def load_local_config(filename):
    if (not filename):
        return imp.new_module('local_pylint_config')
    module = imp.load_source('local_pylint_config', filename)
    return module

Loads the pylint.config.py file.

Args:
filename (str): The python file containing the local configuration.

Returns:
module: The loaded Python module.


def threshold(image, block_size=DEFAULT_BLOCKSIZE, mask=None):

    if mask is None:
        mask = np.zeros(image.shape[:2], dtype=np.uint8)
        mask[:] = 255

    if len(image.shape) > 2 and image.shape[2] == 4:
        image = cv2.cvtColor(image, cv2.COLOR_BGRA2GRAY)
    res = _calc_block_mean_variance(image, mask, block_size)
    res = image.astype(np.float32) - res.astype(np.float32) + 255
    _, res = cv2.threshold(res, 215, 255, cv2.THRESH_BINARY)
    return res

Applies adaptive thresholding to the given image.

Args:
image: BGRA image.
block_size: optional int block_size to use for adaptive thresholding.
mask: optional mask.
Returns:
Thresholded image.


def dict_from_file(filename, key_type=str):

    mapping = {}
    with open(filename, 'r') as f:
        for line in f:
            items = line.rstrip('\n').split()
            assert len(items) >= 2
            key = key_type(items[0])
            val = items[1:] if len(items) > 2 else items[1]
            mapping[key] = val
    return mapping

Load a text file and parse the content as a dict.

Each line of the text file will be two or more columns splited by
whitespaces or tabs. The first column will be parsed as dict keys, and
the following columns will be parsed as dict values.

Args:
filename(str): Filename.
key_type(type): Type of the dict's keys. str is user by default and
type conversion will be performed if specified.

Returns:
dict: The parsed contents.


def set_cellpy_datadir(self, directory=None):
    if (directory is None):
        self.logger.info('no directory name given')
        return
    if (not os.path.isdir(directory)):
        self.logger.info('directory does not exist')
        return
    self.cellpy_datadir = directory

Set the directory containing .hdf5-files.

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

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

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


def transpose(self, *args, **kwargs):
    new_data = self.data.transpose(*args, **kwargs)
    new_manager = self.__constructor__(new_data, self.columns, self.index)
    new_manager._is_transposed = (self._is_transposed ^ 1)
    return new_manager

Transposes this DataManager.

Returns:
Transposed new DataManager.


def get_transition_chempots(self, element):
    if (element not in self.elements):
        raise ValueError('get_transition_chempots can only be called with elements in the phase diagram.')
    critical_chempots = []
    for facet in self.facets:
        chempots = self._get_facet_chempots(facet)
        critical_chempots.append(chempots[element])
    clean_pots = []
    for c in sorted(critical_chempots):
        if (len(clean_pots) == 0):
            clean_pots.append(c)
        elif (abs((c - clean_pots[(- 1)])) > PhaseDiagram.numerical_tol):
            clean_pots.append(c)
    clean_pots.reverse()
    return tuple(clean_pots)

Get the critical chemical potentials for an element in the Phase
Diagram.

Args:
element: An element. Has to be in the PD in the first place.

Returns:
A sorted sequence of critical chemical potentials, from less
negative to more negative.


def save(self, branch, commit_message, **kwargs):

        self.branch = branch
        self.commit_message = commit_message
        self.file_path = self.file_path.replace('/', '%2F')
        super(ProjectFile, self).save(**kwargs)

Save the changes made to the file to the server.

The object is updated to match what the server returns.

Args:
branch (str): Branch in which the file will be updated
commit_message (str): Message to send with the commit
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabUpdateError: If the server cannot perform the request


def __format_error(self, error_list_tag):
    error = {'domain': self.domain(), 'reason': self.reason(), 'message': self.message()}
    error.update((self.extra_fields() or {}))
    return {'error': {error_list_tag: [error], 'code': self.status_code(), 'message': self.message()}}

Format this error into a JSON response.

Args:
error_list_tag: A string specifying the name of the tag to use for the
error list.

Returns:
A dict containing the reformatted JSON error response.


async def download_cot_artifacts(chain):
    upstream_artifacts = chain.task['payload'].get('upstreamArtifacts', [])
    all_artifacts_per_task_id = get_all_artifacts_per_task_id(chain, upstream_artifacts)
    mandatory_artifact_tasks = []
    optional_artifact_tasks = []
    for (task_id, paths) in all_artifacts_per_task_id.items():
        for path in paths:
            coroutine = asyncio.ensure_future(download_cot_artifact(chain, task_id, path))
            if is_artifact_optional(chain, task_id, path):
                optional_artifact_tasks.append(coroutine)
            else:
                mandatory_artifact_tasks.append(coroutine)
    mandatory_artifacts_paths = (await raise_future_exceptions(mandatory_artifact_tasks))
    (succeeded_optional_artifacts_paths, failed_optional_artifacts) = (await get_results_and_future_exceptions(optional_artifact_tasks))
    if failed_optional_artifacts:
        log.warning('Could not download {} artifacts: {}'.format(len(failed_optional_artifacts), failed_optional_artifacts))
    return (mandatory_artifacts_paths + succeeded_optional_artifacts_paths)

Call ``download_cot_artifact`` in parallel for each "upstreamArtifacts".

Optional artifacts are allowed to not be downloaded.

Args:
chain (ChainOfTrust): the chain of trust object

Returns:
list: list of full paths to downloaded artifacts. Failed optional artifacts
aren't returned

Raises:
CoTError: on chain of trust sha validation error, on a mandatory artifact
BaseDownloadError: on download error on a mandatory artifact


def update_media_assetfile(access_token, parent_asset_id, asset_id, content_length, name):
    path = '/Files'
    full_path = ''.join([path, "('", asset_id, "')"])
    full_path_encoded = urllib.parse.quote(full_path, safe='')
    endpoint = ''.join([ams_rest_endpoint, full_path_encoded])
    body = (((((((('{ \t\t"ContentFileSize": "' + str(content_length)) + '", \t\t"Id": "') + asset_id) + '", \t\t"MimeType": "video/mp4", \t\t"Name": "') + name) + '", \t\t"ParentAssetId": "') + parent_asset_id) + '" \t}')
    return do_ams_patch(endpoint, full_path_encoded, body, access_token)

Update Media Service Asset File.

Args:
access_token (str): A valid Azure authentication token.
parent_asset_id (str): A Media Service Asset Parent Asset ID.
asset_id (str): A Media Service Asset Asset ID.
content_length (str): A Media Service Asset Content Length.
name (str): A Media Service Asset name.

Returns:
HTTP response. JSON body.


def load_glossary(file_path: str, read_json=False) -> List[str]:

        if read_json:
            if file_path.endswith(".gz"):
                return json.load(gzip.open(file_path))
            return json.load(open(file_path))

        return open(file_path).read().splitlines()

A glossary is a text file, one entry per line.

Args:
file_path (str): path to a text file containing a glossary.
read_json (bool): set True if the glossary is in json format
Returns: List of the strings in the glossary.


def typify(value, type_hint=None):
    if isinstance(value, string_types):
        value = value.strip()
    elif (type_hint is None):
        return value
    if isiterable(type_hint):
        if (isinstance(type_hint, type) and issubclass(type_hint, Enum)):
            try:
                return type_hint(value)
            except ValueError:
                return type_hint[value]
        type_hint = set(type_hint)
        if (not (type_hint - NUMBER_TYPES_SET)):
            return numberify(value)
        elif (not (type_hint - STRING_TYPES_SET)):
            return text_type(value)
        elif (not (type_hint - {bool, NoneType})):
            return boolify(value, nullable=True)
        elif (not (type_hint - (STRING_TYPES_SET | {bool}))):
            return boolify(value, return_string=True)
        elif (not (type_hint - (STRING_TYPES_SET | {NoneType}))):
            value = text_type(value)
            return (None if (value.lower() == 'none') else value)
        elif (not (type_hint - {bool, int})):
            return typify_str_no_hint(text_type(value))
        else:
            raise NotImplementedError()
    elif (type_hint is not None):
        try:
            return (boolify(value) if (type_hint == bool) else type_hint(value))
        except ValueError as e:
            raise TypeCoercionError(value, text_type(e))
    else:
        return typify_str_no_hint(value)

Take a primitive value, usually a string, and try to make a more relevant type out of it.
An optional type_hint will try to coerce the value to that type.

Args:
value (Any): Usually a string, not a sequence
type_hint (type or Tuple[type]):

Examples:
>>> typify('32')
32
>>> typify('32', float)
32.0
>>> typify('32.0')
32.0
>>> typify('32.0.0')
'32.0.0'
>>> [typify(x) for x in ('true', 'yes', 'on')]
[True, True, True]
>>> [typify(x) for x in ('no', 'FALSe', 'off')]
[False, False, False]
>>> [typify(x) for x in ('none', 'None', None)]
[None, None, None]


def d_hkl(self, miller_index: Vector3Like) -> float:

        gstar = self.reciprocal_lattice_crystallographic.metric_tensor
        hkl = np.array(miller_index)
        return 1 / ((dot(dot(hkl, gstar), hkl.T)) ** (1 / 2))

Returns the distance between the hkl plane and the origin

Args:
miller_index ([h,k,l]): Miller index of plane

Returns:
d_hkl (float)


def GetGtfsClassByFileName(self, filename):

    if filename not in self._file_mapping:
      return None
    mapping = self._file_mapping[filename]
    class_list = mapping['classes']
    if len(class_list) > 1:
      raise problems.NonStandardMapping(filename)
    else:
      return self._class_mapping[class_list[0]]

Returns the transitfeed class corresponding to a GTFS file.

Args:
filename: The filename whose class is to be returned

Raises:
NonStandardMapping if the specified filename has more than one
corresponding class


def piece_size(model_file=None, model_proto=None, name=None):

  return _gen_sentencepiece_processor_op.sentencepiece_get_piece_size(
      model_file=model_file, model_proto=model_proto, name=name)

Returns the piece size (vocabulary size).

Args:
model_file: The sentencepiece model file path.
model_proto: The sentencepiece model serialized proto.
Either `model_file` or `model_proto` must be set.
name: The name argument that is passed to the op function.
Returns:
A scalar representing the vocabulary size.


def create_token_type_ids_from_sequences(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
    sep = [self.sep_token_id]
    cls = [self.cls_token_id]
    if token_ids_1 is None:
        return len(cls + token_ids_0 + sep) * [0]
    return len(cls + token_ids_0 + sep + sep + token_ids_1 + sep) * [0]

Create a mask from the two sequences passed to be used in a sequence-pair classification task. BART does not
make use of token type ids, therefore a list of zeros is returned.

Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of zeros.


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

    super(FakeFileEntry, self).__init__(
        resolver_context, file_system, path_spec, is_root=is_root,
        is_virtual=True)
    self._date_time = dfdatetime_fake_time.FakeTime()
    self._name = None
    self.entry_type = file_entry_type

Initializes a file entry.

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


def stats(data):
    return {'len': len(data), 'mean': np.mean(data), 'sum': np.sum(data), 'std': np.std(data), 'min': np.min(data), 'max': np.max(data)}

Dictionary with summary stats for data

Returns:
dicitonary with length, mean, sum, standard deviation,\
min and max of data


def user(self, user: str) -> 'ChildHTTPAPI':
    if self.is_real_user:
        raise ValueError("Can't get child of real user")
    try:
        return self.children[user]
    except KeyError:
        child = ChildHTTPAPI(user, self)
        self.children[user] = child
        return child

Get a child HTTPAPI instance.

Args:
user: The Matrix ID of the user whose API to get.

Returns:
A HTTPAPI instance that always uses the given Matrix ID.


def _make_inc_temp(self, suffix="", prefix="", directory_name="/tmp/ray"):

        directory_name = os.path.expanduser(directory_name)
        index = self._incremental_dict[suffix, prefix, directory_name]

        while index < tempfile.TMP_MAX:
            if index == 0:
                filename = os.path.join(directory_name, prefix + suffix)
            else:
                filename = os.path.join(directory_name,
                                        prefix + "." + str(index) + suffix)
            index += 1
            if not os.path.exists(filename):

                self._incremental_dict[suffix, prefix, directory_name] = index
                return filename

        raise FileExistsError(errno.EEXIST,
                              "No usable temporary filename found")

Return a incremental temporary file name. The file is not created.

Args:
suffix (str): The suffix of the temp file.
prefix (str): The prefix of the temp file.
directory_name (str) : The base directory of the temp file.

Returns:
A string of file name. If there existing a file having
the same name, the returned name will look like
"{directory_name}/{prefix}.{unique_index}{suffix}"


def get_index_mapping(index):

    mappings_dir = get_setting("mappings_dir")
    filename = "%s.json" % index
    path = os.path.join(mappings_dir, filename)
    with open(path, "r") as f:
        return json.load(f)

Return the JSON mapping file for an index.

Mappings are stored as JSON files in the mappings subdirectory of this
app. They must be saved as {{index}}.json.

Args:
index: string, the name of the index to look for.


def handle_encodnig(html):

    encoding = _get_encoding(
        dhtmlparser.parseString(
            html.split("</head>")[0]
        )
    )

    if encoding == "utf-8":
        return html

    return html.decode(encoding).encode("utf-8")

Look for encoding in given `html`. Try to convert `html` to utf-8.

Args:
html (str): HTML code as string.

Returns:
str: HTML code encoded in UTF.


def __init__(self, name, buckets, description, *labels):
    super(Sampler, self).__init__('Sampler', _sampler_methods, len(labels), name, buckets.buckets, description, *labels)

Creates a new Sampler.

Args:
name: name of the new metric.
buckets: bucketing strategy of the new metric.
description: description of the new metric.
*labels: The label list of the new metric.


def propagate(self, date):

        if self.propagator.orbit is not self:
            self.propagator.orbit = self

        return self.propagator.propagate(date)

Propagate the orbit to a new date

Args:
date (Date)
Return:
Orbit


def _MakeParseFn(fn, metadata):
    fn_spec = inspectutils.GetFullArgSpec(fn)
    num_required_args = len(fn_spec.args) - len(fn_spec.defaults)
    required_kwonly = set(fn_spec.kwonlyargs) - set(fn_spec.kwonlydefaults)

    def _ParseFn(args):

        kwargs, remaining_kwargs, remaining_args = _ParseKeywordArgs(args, fn_spec)
        parsed_args, kwargs, remaining_args, capacity = _ParseArgs(fn_spec.args, fn_spec.defaults, num_required_args, kwargs, remaining_args, metadata)
        if fn_spec.varargs or fn_spec.varkw:
            capacity = True
        extra_kw = set(kwargs) - set(fn_spec.kwonlyargs)
        if fn_spec.varkw is None and extra_kw:
            raise FireError('Unexpected kwargs present:', extra_kw)
        missing_kwonly = set(required_kwonly) - set(kwargs)
        if missing_kwonly:
            raise FireError('Missing required flags:', missing_kwonly)
        if fn_spec.varargs is not None:
            varargs, remaining_args = (remaining_args, [])
        else:
            varargs = []
        for index, value in enumerate(varargs):
            varargs[index] = _ParseValue(value, None, None, metadata)
        varargs = parsed_args + varargs
        remaining_args += remaining_kwargs
        consumed_args = args[:len(args) - len(remaining_args)]
        return ((varargs, kwargs), consumed_args, remaining_args, capacity)
    return _ParseFn

Creates a parse function for fn.

Args:
fn: The function or class to create the parse function for.
metadata: Additional metadata about the component the parse function is for.
Returns:
A parse function for fn. The parse function accepts a list of arguments
and returns (varargs, kwargs), remaining_args. The original function fn
can then be called with fn(*varargs, **kwargs). The remaining_args are
the leftover args from the arguments to the parse function.


def tetragonal(a: float, c: float):
    return Lattice.from_parameters(a, a, c, 90, 90, 90)

Convenience constructor for a tetragonal lattice.

Args:
a (float): *a* lattice parameter of the tetragonal cell.
c (float): *c* lattice parameter of the tetragonal cell.

Returns:
Tetragonal lattice of dimensions a x a x c.


def _GetFieldAttributes(field):
    if (not isinstance(field, messages.Field)):
        raise TypeError(('Field %r to be copied not a ProtoRPC field.' % (field,)))
    positional_args = []
    kwargs = {'required': field.required, 'repeated': field.repeated, 'variant': field.variant, 'default': field._Field__default}
    if isinstance(field, messages.MessageField):
        kwargs.pop('default')
        if (not isinstance(field, message_types.DateTimeField)):
            positional_args.insert(0, field.message_type)
    elif isinstance(field, messages.EnumField):
        positional_args.insert(0, field.type)
    return (positional_args, kwargs)

Decomposes field into the needed arguments to pass to the constructor.

This can be used to create copies of the field or to compare if two fields
are "equal" (since __eq__ is not implemented on messages.Field).

Args:
field: A ProtoRPC message field (potentially to be copied).

Raises:
TypeError: If the field is not an instance of messages.Field.

Returns:
A pair of relevant arguments to be passed to the constructor for the field
type. The first element is a list of positional arguments for the
constructor and the second is a dictionary of keyword arguments.


def f(options, expected_tf_failures=0):
    test_parameters = [{'ksize': [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 3, 4, 1]], 'strides': [[1, 1, 1, 1, 1], [1, 2, 1, 2, 1], [1, 2, 2, 4, 1]], 'input_shape': [[1, 1, 1, 1, 1], [1, 16, 15, 14, 1], [3, 16, 15, 14, 3]], 'padding': ['SAME', 'VALID'], 'data_format': ['NDHWC']}]

    def build_graph(parameters):
        input_tensor = tf.compat.v1.placeholder(dtype=tf.float32, name='input', shape=parameters['input_shape'])
        out = pool_op(input_tensor, ksize=parameters['ksize'], strides=parameters['strides'], data_format=parameters['data_format'], padding=parameters['padding'])
        return ([input_tensor], [out])

    def build_inputs(parameters, sess, inputs, outputs):
        input_values = create_tensor_data(tf.float32, parameters['input_shape'])
        return ([input_values], sess.run(outputs, feed_dict=dict(zip(inputs, [input_values]))))
    extra_convert_options = ExtraConvertOptions()
    extra_convert_options.allow_custom_ops = True
    make_zip_of_tests(options, test_parameters, build_graph, build_inputs, extra_convert_options, expected_tf_failures=expected_tf_failures)

Actual function that generates examples.

Args:
options: An Options instance.
expected_tf_failures: number of expected tensorflow failures.


def run(argv=None, save_main_session=True):
    known_args, pipeline_args = parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
    with beam.Pipeline(options=pipeline_options) as pipeline:
        _ = pipeline | 'Read Data' >> beam.io.ReadFromText(known_args.input) | 'Split data to make List' >> beam.Map(lambda x: x.split(',')) | 'Filter rows' >> beam.Filter(custom_filter) | 'Create Key' >> beam.ParDo(CreateKey()) | 'Group by education' >> beam.GroupByKey() | 'Prepare Data' >> beam.ParDo(PrepareDataforTraining()) | 'Train Model' >> beam.ParDo(TrainModel()) | 'Save' >> fileio.WriteToFiles(path=known_args.output, sink=ModelSink())

Args:
argv: Command line arguments defined for this example.
save_main_session: Used for internal testing.


def GetFormattedEventObject(cls, event):
    time_string = timelib.Timestamp.CopyToIsoFormat(event.timestamp)
    lines_of_text = [('+-' * 40), '[Timestamp]:', '  {0:s}'.format(time_string)]
    pathspec = getattr(event, 'pathspec', None)
    if pathspec:
        lines_of_text.append('[Pathspec]:')
        attribute_string = pathspec.comparable.replace('\n', '\n  ')
        attribute_string = '  {0:s}\n'.format(attribute_string)
        lines_of_text.append(attribute_string)
    lines_of_text.append('[Reserved attributes]:')
    out_additional = ['[Additional attributes]:']
    for (attribute_name, attribute_value) in sorted(event.GetAttributes()):
        if (attribute_name not in definitions.RESERVED_VARIABLE_NAMES):
            attribute_string = '  {{{0!s}}} {1!s}'.format(attribute_name, attribute_value)
            out_additional.append(attribute_string)
        elif (attribute_name not in ('pathspec', 'tag')):
            attribute_string = '  {{{0!s}}} {1!s}'.format(attribute_name, attribute_value)
            lines_of_text.append(attribute_string)
    lines_of_text.append('')
    out_additional.append('')
    lines_of_text.extend(out_additional)
    return '\n'.join(lines_of_text)

Retrieves a string representation of the event.

Args:
event (EventObject): event.

Returns:
str: string representation of the event.


def ParseIfaddrs(ifaddrs):
    precondition.AssertOptionalType(ifaddrs, ctypes.POINTER(Ifaddrs))
    ifaces = {}
    for ifaddr in IterIfaddrs(ifaddrs):
        ifname = ctypes.string_at(ifaddr.ifa_name).decode('utf-8')
        iface = ifaces.setdefault(ifname, rdf_client_network.Interface())
        iface.ifname = ifname
        if (not ifaddr.ifa_addr):
            continue
        sockaddr = ctypes.cast(ifaddr.ifa_addr, ctypes.POINTER(Sockaddr))
        iffamily = sockaddr.contents.sa_family
        if (iffamily == AF_INET):
            sockaddrin = ctypes.cast(ifaddr.ifa_addr, ctypes.POINTER(Sockaddrin))
            address = rdf_client_network.NetworkAddress()
            address.address_type = rdf_client_network.NetworkAddress.Family.INET
            address.packed_bytes = struct.pack('=L', sockaddrin.contents.sin_addr)
            iface.addresses.append(address)
        elif (iffamily == AF_INET6):
            sockaddrin = ctypes.cast(ifaddr.ifa_addr, ctypes.POINTER(Sockaddrin6))
            address = rdf_client_network.NetworkAddress()
            address.address_type = rdf_client_network.NetworkAddress.Family.INET6
            address.packed_bytes = bytes(list(sockaddrin.contents.sin6_addr))
            iface.addresses.append(address)
        elif (iffamily == AF_LINK):
            sockaddrdl = ctypes.cast(ifaddr.ifa_addr, ctypes.POINTER(Sockaddrdl))
            nlen = sockaddrdl.contents.sdl_nlen
            alen = sockaddrdl.contents.sdl_alen
            iface.mac_address = bytes(sockaddrdl.contents.sdl_data[nlen:(nlen + alen)])
        else:
            raise ValueError(('Unexpected socket address family: %s' % iffamily))
    return itervalues(ifaces)

Parses contents of the intrusive linked list of `ifaddrs`.

Args:
ifaddrs: A pointer to the first node of `ifaddrs` linked list. Can be NULL.

Returns:
An iterator over instances of `rdf_client_network.Interface`.


def block_matrix(A, B, C, D):
    r
    return vstackm((hstackm((A, B)), hstackm((C, D))))

r"""Generate the operator matrix with quadrants

.. math::

\begin{pmatrix} A B \\ C D \end{pmatrix}

Args:
A (Matrix): Matrix of shape ``(n, m)``
B (Matrix): Matrix of shape ``(n, k)``
C (Matrix): Matrix of shape ``(l, m)``
D (Matrix): Matrix of shape ``(l, k)``

Returns:
Matrix: The combined block matrix ``[[A, B], [C, D]]``.


def convert(in_file, out_file, in_fmt="", out_fmt=""):

    in_file = os.path.expanduser(in_file)
    out_file = os.path.expanduser(out_file)

    if not os.path.exists(in_file):
        raise IOError("Input file {0} does not exist, stopping..."
                      .format(in_file))

    in_fmt = in_fmt.lower() or _guess_format_from_extension(
        in_file.split('.')[-1].lower())
    out_fmt = out_fmt.lower() or _guess_format_from_extension(
        out_file.split('.')[-1].lower())

    if not in_fmt or not out_fmt:
        raise ValueError("Cannot determine conversion formats.")
        return False

    if in_fmt is out_fmt:

        shutil.copyfileobj(in_file, out_file)
        return out_file

    if in_fmt == 'hdf5':
        from . import hdf5
        data = hdf5.load(in_file)
    elif in_fmt == 'tiff':
        from . import tiff
        data = tiff.load(in_file)
    elif in_fmt == 'png':
        from . import png
        data = png.load(in_file)
    else:
        return _fail_pair_conversion(in_fmt, out_fmt)

    if out_fmt == 'hdf5':
        from . import hdf5
        return hdf5.save(out_file, data)
    elif out_fmt == 'tiff':
        from . import tiff
        return tiff.save(out_file, data)
    elif out_fmt == 'png':
        from . import png
        return png.export_png(out_file, data)
    else:
        return _fail_pair_conversion(in_fmt, out_fmt)

    return _fail_pair_conversion(in_fmt, out_fmt)

Converts in_file to out_file, guessing datatype in the absence of
in_fmt and out_fmt.

Arguments:
in_file:    The name of the (existing) datafile to read
out_file:   The name of the file to create with converted data
in_fmt:     Optional. The format of incoming data, if not guessable
out_fmt:    Optional. The format of outgoing data, if not guessable

Returns:
String. Output filename


def handle(self, handler, req, resp, **kwargs):
    params = self.require_params(req)
    if getattr(self, '_with_context', False):
        handler = partial(handler, context=req.context)
    (meta, content) = self.require_meta_and_content(handler, params, **kwargs)
    self.make_body(resp, params, meta, content)
    return content

Handle given resource manipulation flow in consistent manner.

This mixin is intended to be used only as a base class in new flow
mixin classes. It ensures that regardless of resource manunipulation
semantics (retrieve, get, delete etc.) the flow is always the same:

1. Decode and validate all request parameters from the query string
using ``self.require_params()`` method.
2. Use ``self.require_meta_and_content()`` method to construct ``meta``
and ``content`` dictionaries that will be later used to create
serialized response body.
3. Construct serialized response body using ``self.body()`` method.

Args:
handler (method): resource manipulation method handler.
req (falcon.Request): request object instance.
resp (falcon.Response): response object instance to be modified.
**kwargs: additional keyword arguments retrieved from url
template.

Returns:
Content dictionary (preferably resource representation).


def set_current(self, current):
    self.current = current
    self.input = current.input
    self.output = current.output
    self.cmd = current.task_data['cmd']
    if (self.cmd and (NEXT_CMD_SPLITTER in self.cmd)):
        (self.cmd, self.next_cmd) = self.cmd.split(NEXT_CMD_SPLITTER)
    else:
        self.next_cmd = None

Creates some aliases for attributes of ``current``.

Args:
current: :attr:`~zengine.engine.WFCurrent` object.


def plogdet(K):
    egvals = eigvalsh(K)
    return npsum(log(egvals[(egvals > epsilon)]))

r"""Log of the pseudo-determinant.

It assumes that ``K`` is a positive semi-definite matrix.

Args:
K (array_like): matrix.

Returns:
float: log of the pseudo-determinant.


def query_string_to_dict(query):

        query_params = {}

        for key_value in query.split("&"):
            key_value_pair = key_value.split("=", 1)

            key = key_value_pair[0] if len(key_value_pair) >= 1 else ""
            value = key_value_pair[1] if len(key_value_pair) == 2 else ""

            query_params[key] = value

        return query_params

Convert a string to a query dict.

Args:
query (str): The query string.

Returns:
obj: The key value object with query params.

Note:
This method does the same as urllib.parse.parse_qsl except
that it doesn't actually decode the values.