def forward(self, raw_audio: torch.FloatTensor) -> Tuple[torch.Tensor, torch.Tensor]:
    input_audio = raw_audio.permute(0, 2, 1).float()
    latent_states = []
    for level in range(self.levels):
        encoder = self.encoders[level]
        latent_state = encoder(input_audio)
        latent_states.append(latent_state[-1])
    _, music_tokens, commit_losses, _ = self.bottleneck(latent_states)
    dequantised_states = []
    for level in range(self.levels):
        decoder = self.decoders[level]
        dequantised_state = decoder(music_tokens[level:level + 1], all_levels=False)
        dequantised_states.append(dequantised_state.permute(0, 2, 1))
    commit_loss = sum(commit_losses)
    loss = self.commit * commit_loss
    return (dequantised_states, loss)

Forward pass of the VQ-VAE, encodes the `raw_audio` to latent states, which are then decoded for each level.
The commit loss, which ensure that the encoder's computed embeddings are close to the codebook vectors, is
computed.

Args:
raw_audio (`torch.FloatTensor`):
Audio input which will be encoded and decoded.

Returns:
`Tuple[torch.Tensor, torch.Tensor]`

Example:
```python
>>> from transformers import JukeboxVQVAE, set_seed
>>> import torch

>>> model = JukeboxVQVAE.from_pretrained("openai/jukebox-1b-lyrics").eval()
>>> set_seed(0)
>>> zs = [torch.randint(100, (4, 1))]
>>> model.decode(zs).shape
torch.Size([4, 8, 1])
```


def make_multi_lagger(lags, groupby_kwargs=None):

    laggers = [SingleLagger(l, groupby_kwargs=groupby_kwargs) for l in lags]
    feature_union = FeatureUnion([
        (repr(lagger), lagger) for lagger in laggers
    ])
    return feature_union

Return a union of transformers that apply different lags

Args:
lags (Collection[int]): collection of lags to apply
groupby_kwargs (dict): keyword arguments to pd.DataFrame.groupby


def profile_df(df):
    return IPython.core.display.HTML(pandas_profiling.ProfileReport(df).html.replace('bootstrap', 'nonexistent'))

Generate a profile of data in a dataframe.

Args:
df: the Pandas dataframe.


def GenerateLibSig(short_name):
    with _UTILITY_LOCK:
        utilities_used = ', '.join([utility for utility in sorted(_utility_registry)])
        _utility_registry.Clear()
    if utilities_used:
        return (' (%s, %s, %s, %s)' % (short_name, _COMMON_LIB_SIG, _PYTHON_VERSION, utilities_used))
    else:
        return (' (%s, %s, %s)' % (short_name, _COMMON_LIB_SIG, _PYTHON_VERSION))

Generates a library signature suitable for a user agent field.

Args:
short_name: The short, product-specific string name for the library.
Returns:
A library signature string to append to user-supplied user-agent value.


def run(argv=None, save_main_session=True, test_pipeline=None) -> PipelineResult:
    known_args, pipeline_args = parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
    model_handler = VertexAIModelHandlerJSON(endpoint_id=known_args.endpoint, project=known_args.project, location=known_args.location, experiment=known_args.experiment, network=known_args.vpc_network, private=known_args.private)
    pipeline = test_pipeline
    if not test_pipeline:
        pipeline = beam.Pipeline(options=pipeline_options)
    read_glob = pipeline | 'Get glob' >> beam.Create([known_args.input])
    read_image_name = read_glob | 'Get Image Paths' >> fileio.MatchAll()
    load_image = read_image_name | 'Read Image' >> beam.Map(lambda image_name: read_image(image_name.path))
    preprocess = load_image | 'Preprocess Image' >> beam.MapTuple(lambda img_name, img: (img_name, preprocess_image(img)))
    predictions = preprocess | 'RunInference' >> RunInference(KeyedModelHandler(model_handler))
    process_output = predictions | 'Process Predictions' >> beam.ParDo(PostProcessor())
    _ = process_output | 'WriteOutput' >> beam.io.WriteToText(known_args.output, shard_name_template='', append_trailing_newlines=True)
    result = pipeline.run()
    result.wait_until_finish()
    return result

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


def _generate_response(self, response: dict, request: dict) -> dict:

        response_template = deepcopy(self.response_template)
        response_template['sessionAttributes']['sessionId'] = request['session']['sessionId']

        for key, value in response_template.items():
            if key not in response.keys():
                response[key] = value

        return response

Populates generated response with additional data conforming Alexa response specification.

Args:
response: Raw user input extracted from Alexa request.
request: Alexa request.
Returns:
response: Response conforming Alexa response specification.


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]
    question_suffix = [self.question_token_id] + [self.convert_tokens_to_ids('.')]
    if token_ids_1 is None:
        return len(cls + token_ids_0 + sep) * [0]
    if self.padding_side == 'right':
        return len(cls + token_ids_0 + question_suffix + sep) * [0] + len(token_ids_1 + sep) * [1]
    else:
        return len(cls + token_ids_0 + sep) * [0] + len(token_ids_1 + question_suffix + sep) * [1]

Create the token type IDs corresponding to the sequences passed. [What are token type
IDs?](../glossary#token-type-ids)

Should be overridden in a subclass if the model has a special way of building those.

Args:
token_ids_0 (`List[int]`): The first tokenized sequence.
token_ids_1 (`List[int]`, *optional*): The second tokenized sequence.

Returns:
`List[int]`: The token type ids.


def read_folder(directory):

    res = []
    for filename in os.listdir(directory):
        with io.open(os.path.join(directory, filename), encoding="utf-8") as f:
            content = f.read()
            res.append(content)
    return res

read text files in directory and returns them as array

Args:
directory: where the text files are

Returns:
Array of text


class VptqConfig(QuantizationConfigMixin):

    def __init__(self, enable_proxy_error: bool=False, config_for_layers: Dict[str, Any]={}, shared_layer_config: Dict[str, Any]={}, modules_to_not_convert: Optional[List]=None, **kwargs):
        self.quant_method = QuantizationMethod.VPTQ
        self.enable_proxy_error = enable_proxy_error
        self.config_for_layers: Dict[str, Any] = config_for_layers
        self.shared_layer_config: Dict[str, Any] = shared_layer_config
        self.modules_to_not_convert = modules_to_not_convert
        self.post_init()

    def post_init(self):

        for layer_name, layer_param in self.config_for_layers.items():
            VptqLayerConfig(**layer_param)
        if self.enable_proxy_error is True:
            raise ValueError('enable_proxy_error should always be False until we support training')

This is a wrapper class about `vptq` parameters.

Args:
enable_proxy_error (`bool`, *optional*, defaults to `False`): calculate proxy error for each layer
config_for_layers (`Dict`, *optional*, defaults to `{}`): quantization params for each layer
shared_layer_config (`Dict`, *optional*, defaults to `{}`): shared quantization params among layers
modules_to_not_convert (`list`, *optional*, default to `None`):
The list of modules to not quantize, useful for quantizing models that explicitly require to have
some modules left in their original precision (e.g. Whisper encoder, Llava encoder, Mixtral gate layers).
kwargs (`Dict[str, Any]`, *optional*):
Additional parameters from which to initialize the configuration object.


def set_Tc(self, Tc, T=None):
    if isinstance(Tc, Iterable):
        if (len(Tc) == len(T)):
            x = np.concatenate(([(- ttconf.BIG_NUMBER)], T, [ttconf.BIG_NUMBER]))
            y = np.concatenate(([Tc[0]], Tc, [Tc[(- 1)]]))
            self.Tc = interp1d(x, y)
        else:
            self.logger('need Tc values and Timepoints of equal length', 2, warn=True)
            self.Tc = interp1d([(- ttconf.BIG_NUMBER), ttconf.BIG_NUMBER], [1e-05, 1e-05])
    else:
        self.Tc = interp1d([(- ttconf.BIG_NUMBER), ttconf.BIG_NUMBER], [(Tc + ttconf.TINY_NUMBER), (Tc + ttconf.TINY_NUMBER)])
    self.calc_integral_merger_rate()

initialize the merger model with a coalescent time

Args:
- Tc:   a float or an iterable, if iterable another argument T of same shape is required
- T:    an array like of same shape as Tc that specifies the time pivots corresponding to Tc
Returns:
- None


def post_transform(self, args):

        args = args[1:] if args and args[0] == 'az' else args

        post_transform_commands = []
        for i, arg in enumerate(args):

            if is_alias_command(['create'], args) and i > 0 and args[i - 1] in ['-c', '--command']:
                post_transform_commands.append(arg)
            else:
                post_transform_commands.append(os.path.expandvars(arg))

        AliasManager.write_alias_config_hash(self.alias_config_hash)
        AliasManager.write_collided_alias(self.collided_alias)

        return post_transform_commands

Inject environment variables, and write hash to alias hash file after transforming alias to commands.

Args:
args: A list of args to post-transform.


def readinto(self, b):

        if not self._readable:
            raise UnsupportedOperation('read')

        with self._seek_lock:

            seek = self._seek

            queue = self._read_queue
            if seek == 0:

                self._preload_range()

            size = len(b)
            if size:

                b_view = memoryview(b)
                size_left = size
            else:

                b_view = b
                size_left = -1
            b_end = 0

            buffer_size = self._buffer_size
            while size_left > 0 or size_left == -1:

                start = seek % buffer_size
                queue_index = seek - start

                try:
                    buffer = queue[queue_index]
                except KeyError:

                    break

                with handle_os_exceptions():
                    try:
                        queue[queue_index] = buffer = buffer.result()

                    except AttributeError:
                        pass
                buffer_view = memoryview(buffer)
                data_size = len(buffer)

                if not data_size:
                    break

                if size_left != -1:
                    end = start + size_left
                else:
                    end = data_size - start

                if end >= data_size:

                    end = data_size

                    del queue[queue_index]

                    index = queue_index + buffer_size * self._max_buffers
                    if index < self._size:
                        queue[index] = self._workers.submit(
                            self._read_range, index, index + buffer_size)

                read_size = end - start
                if size_left != -1:
                    size_left -= read_size
                seek += read_size

                b_start = b_end
                b_end = b_start + read_size

                b_view[b_start:b_end] = buffer_view[start:end]

            self._seek = seek
            self._raw.seek(seek)

        return b_end

Read bytes into a pre-allocated, writable bytes-like object b,
and return the number of bytes read.

Args:
b (bytes-like object): buffer.

Returns:
int: number of bytes read


def _get_jwt_for_audience(self, audience):
    (token, expiry) = self._cache.get(audience, (None, None))
    if ((token is None) or (expiry < _helpers.utcnow())):
        (token, expiry) = self._make_jwt_for_audience(audience)
        self._cache[audience] = (token, expiry)
    return token

Get a JWT For a given audience.

If there is already an existing, non-expired token in the cache for
the audience, that token is used. Otherwise, a new token will be
created.

Args:
audience (str): The intended audience.

Returns:
bytes: The encoded JWT.


def transform_array_to_list(array):
    if ((array.dtype.kind in ('u', 'i', 'f')) and (~ np.isfinite(array)).any()):
        transformed = array.astype('object')
        transformed[np.isnan(array)] = 'NaN'
        transformed[np.isposinf(array)] = 'Infinity'
        transformed[np.isneginf(array)] = '-Infinity'
        return transformed.tolist()
    elif ((array.dtype.kind == 'O') and pd and pd.isnull(array).any()):
        transformed = array.astype('object')
        transformed[pd.isnull(array)] = 'NaN'
        return transformed.tolist()
    return array.tolist()

Transforms a NumPy array into a list of values

Args:
array (np.nadarray) : the NumPy array series to transform

Returns:
list or dict


def interp_color(a, b, f):
    a_ = (a.redF(), a.greenF(), a.blueF())
    b_ = (b.redF(), b.greenF(), b.blueF())
    a_ = [(x * (1 - f)) for x in a_]
    b_ = [(x * f) for x in b_]
    c = [(x + y) for (x, y) in zip(a_, b_)]
    return QtGui.QColor.fromRgbF(*c)

Interpolate between two colors.

Returns:
`QColor` object.


def return_handler(self, call_node, function_nodes, saved_function_call_index, first_node):
    if any((isinstance(node, YieldNode) for node in function_nodes)):
        rhs_prefix = 'yld_'
    elif any((isinstance(node, ConnectToExitNode) for node in function_nodes)):
        rhs_prefix = 'ret_'
    else:
        return
    LHS = ((CALL_IDENTIFIER + 'call_') + str(saved_function_call_index))
    RHS = (rhs_prefix + get_call_names_as_string(call_node.func))
    return_node = RestoreNode(((LHS + ' = ') + RHS), LHS, [RHS], line_number=call_node.lineno, path=self.filenames[(- 1)])
    return_node.first_node = first_node
    self.nodes[(- 1)].connect(return_node)
    self.nodes.append(return_node)

Handle the return from a function during a function call.

Args:
call_node(ast.Call) : The node that calls the definition.
function_nodes(list[Node]): List of nodes of the function being called.
saved_function_call_index(int): Unique number for each call.
first_node(EntryOrExitNode or RestoreNode): Used to connect previous statements to this function.


def add(self, files):
    if (files.__class__.__name__ == 'str'):
        self._files.append(files)
    else:
        self._files.extend(files)

Adds files to check.

Args:
files: List of files to check.


def FromDictionary(cls, msg_dict):
    level = msg_dict.get('level')
    msg = msg_dict.get('message')
    now = msg_dict.get('now_time')
    created = msg_dict.get('created_time')
    count = msg_dict.get('count', 1)
    msg_id = msg_dict.get('id', 0)
    new_msg = ServiceMessage(level, msg, msg_id, created, now)
    if (count > 1):
        new_msg.count = count
    return new_msg

Create from a dictionary with kv pairs.

Args:
msg_dict (dict): A dictionary with information as created by to_dict()

Returns:
ServiceMessage: the converted message


def check(self):
    if (not isinstance(self.parsed_yaml, dict)):
        msg = 'In {0}:\n'.format(self.sourcefile)
        msg += 'Assistants and snippets must be Yaml mappings, not "{0}"!'.format(self.parsed_yaml)
        raise exceptions.YamlTypeError(msg)
    self._check_fullname(self.sourcefile)
    self._check_description(self.sourcefile)
    self._check_section_names(self.sourcefile)
    self._check_project_type(self.sourcefile)
    self._check_args(self.sourcefile)
    self._check_files(self.sourcefile)
    self._check_dependencies(self.sourcefile)
    self._check_run(self.sourcefile)

Checks whether loaded yaml is well-formed according to syntax defined for
version 0.9.0 and later.

Raises:
YamlError: (containing a meaningful message) when the loaded Yaml
is not well formed


def stack(xs, dim_name, axis=0, name=None):

  ret = StackOperation(xs, dim_name, axis, name).outputs[0]
  return ret

Stack multiple Tensors to make a new dimension.

Args:
xs: a list of Tensors with identical shapes.
dim_name: a string (name of the new dimension)
axis: an integer (index of the new dimension in the output shape)
name: an optional string

Returns:
a Tensor


def _send(self, email_message):
    pre_send.send(self.__class__, message=email_message)
    if (not email_message.recipients()):
        return False
    from_email = sanitize_address(email_message.from_email, email_message.encoding)
    recipients = [sanitize_address(addr, email_message.encoding) for addr in email_message.recipients()]
    message = email_message.message().as_bytes(linesep='\r\n')
    try:
        result = self.conn.send_raw_email(Source=from_email, Destinations=recipients, RawMessage={'Data': message})
        message_id = result['MessageId']
        post_send.send(self.__class__, message=email_message, message_id=message_id)
    except ClientError:
        if (not self.fail_silently):
            raise
        return False
    return True

Sends an individual message via the Amazon SES HTTP API.

Args:
email_message: A single Django EmailMessage object.
Returns:
True if the EmailMessage was sent successfully, otherwise False.
Raises:
ClientError: An interaction with the Amazon SES HTTP API
failed.


def __init__(self, location, resource_pool):

        super(FileSystemPackageRepository, self).__init__(location, resource_pool)

        global _settings
        _settings = config.plugins.package_repository.filesystem

        self.register_resource(FileSystemPackageFamilyResource)
        self.register_resource(FileSystemPackageResource)
        self.register_resource(FileSystemVariantResource)

        self.register_resource(FileSystemCombinedPackageFamilyResource)
        self.register_resource(FileSystemCombinedPackageResource)
        self.register_resource(FileSystemCombinedVariantResource)

        self.get_families = lru_cache(maxsize=None)(self._get_families)
        self.get_family = lru_cache(maxsize=None)(self._get_family)
        self.get_packages = lru_cache(maxsize=None)(self._get_packages)
        self.get_variants = lru_cache(maxsize=None)(self._get_variants)
        self.get_file = lru_cache(maxsize=None)(self._get_file)

Create a filesystem package repository.

Args:
location (str): Path containing the package repository.


def extraterrestrial_direct_normal_radiation(self, value=9999.0):

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

        self._extraterrestrial_direct_normal_radiation = value

Corresponds to IDD Field `extraterrestrial_direct_normal_radiation`

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

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


def add(self, information, timeout=(- 1)):
    return self._client.create(information, timeout=timeout)

Adds a data center resource based upon the attributes specified.

Args:
information: Data center information
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: Added data center.


def SetLines(self, lines):

    (self._cli_lines, self._cli_cols) = TerminalSize()

    if lines:
      self._cli_lines = int(lines)

Set number of screen lines.

Args:
lines: An int, number of lines. If None, use terminal dimensions.

Raises:
ValueError, TypeError: Not a valid integer representation.


def calc_padding(fmt, align):
    remain = (struct.calcsize(fmt) % align)
    if (remain == 0):
        return ''
    return ('x' * (align - remain))

Calculate how many padding bytes needed for ``fmt`` to be aligned to
``align``.

Args:
fmt (str): :mod:`struct` format.
align (int): alignment (2, 4, 8, etc.)

Returns:
str: padding format (e.g., various number of 'x').

>>> calc_padding('b', 2)
'x'

>>> calc_padding('b', 3)
'xx'


def run(self, dag):
    for node in dag.threeQ_or_more_gates():
        rule = node.op.definition
        if (not rule):
            raise QiskitError(('Cannot unroll all 3q or more gates. No rule to expand instruction %s.' % node.op.name))
        decomposition = DAGCircuit()
        decomposition.add_qreg(rule[0][1][0][0])
        for inst in rule:
            decomposition.apply_operation_back(*inst)
        decomposition = self.run(decomposition)
        dag.substitute_node_with_dag(node, decomposition)
    return dag

Expand 3+ qubit gates using their decomposition rules.

Args:
dag(DAGCircuit): input dag
Returns:
DAGCircuit: output dag with maximum node degrees of 2
Raises:
QiskitError: if a 3q+ gate is not decomposable


def write(self, auth, resource, value, options={}, defer=False):

        return self._call('write', auth, [resource, value, options], defer)

Writes a single value to the resource specified.

Args:
auth: cik for authentication.
resource: resource to write to.
value: value to write
options: options.


Holds the output of the image processor specific `__call__` methods.

This class is derived from a python dictionary and can be used as a dictionary.

Args:
data (`dict`):
Dictionary of lists/arrays/tensors returned by the __call__ method ('pixel_values', etc.).
tensor_type (`Union[None, str, TensorType]`, *optional*):
You can give a tensor_type here to convert the lists of integers in PyTorch/TensorFlow/Numpy Tensors at
initialization.


def _force_edge_active(self, seqs: List[List[GridQubit]], edge: EDGE,
                           sample_bool: Callable[[], bool]
                           ) -> List[List[GridQubit]]:

        n0, n1 = edge

        seqs = list(seqs)

        i0, j0 = index_2d(seqs, n0)
        i1, j1 = index_2d(seqs, n1)
        s0 = seqs[i0]
        s1 = seqs[i1]

        if i0 != i1:

            part = [s0[:j0], s0[j0 + 1:]], [s1[:j1], s1[j1 + 1:]]

            del seqs[max(i0, i1)]
            del seqs[min(i0, i1)]

            c0 = 0 if not part[0][1] else 1 if not part[0][
                0] else sample_bool()
            if c0:
                part[0][c0].reverse()

            c1 = 0 if not part[1][1] else 1 if not part[1][
                0] else sample_bool()
            if not c1:
                part[1][c1].reverse()

            seqs.append(part[0][c0] + [n0, n1] + part[1][c1])

            other = [1, 0]
            seqs.append(part[0][other[c0]])
            seqs.append(part[1][other[c1]])
        else:

            if j0 > j1:
                j0, j1 = j1, j0
                n0, n1 = n1, n0

            head = s0[:j0]
            inner = s0[j0 + 1:j1]
            tail = s0[j1 + 1:]

            del seqs[i0]

            if sample_bool():

                if sample_bool():
                    seqs.append(inner + [n1, n0] + head[::-1])
                    seqs.append(tail)
                else:
                    seqs.append(tail[::-1] + [n1, n0] + inner)
                    seqs.append(head)
            else:

                seqs.append(head + [n0, n1] + tail)
                seqs.append(inner)

        return [e for e in seqs if e]

Move which forces given edge to appear on some sequence.

Args:
seqs: List of linear sequences covering chip.
edge: Edge to be activated.
sample_bool: Callable returning random bool.

Returns:
New list of linear sequences with given edge on some of the
sequences.


def make_bubble_surface(dims=DEFAULT_DIMS, repeat=3):
    gradients = make_gradients(dims)
    return (np.sin((((gradients[0] - 0.5) * repeat) * np.pi)) * np.sin((((gradients[1] - 0.5) * repeat) * np.pi)))

Makes a surface from the product of sine functions on each axis.

Args:
dims (pair): the dimensions of the surface to create
repeat (int): the frequency of the waves is set to ensure this many
repetitions of the function

Returns:
surface: A surface.


def starts_with_prefix_in_list(text, prefixes):
    for prefix in prefixes:
        if text.startswith(prefix):
            return True
    return False

Return True if the given string starts with one of the prefixes in the given list, otherwise
return False.

Arguments:
text (str): Text to check for prefixes.
prefixes (list): List of prefixes to check for.

Returns:
bool: True if the given text starts with any of the given prefixes, otherwise False.


def wait_for_registration(self, processor_type):

        with self._condition:
            self._condition.wait_for(lambda: (
                processor_type in self
                or self._cancelled_event.is_set()))
            if self._cancelled_event.is_set():
                raise WaitCancelledException()

Waits for a particular processor type to register or until
is_cancelled is True. is_cancelled cannot be part of this class
since we aren't cancelling all waiting for a processor_type,
but just this particular wait.

Args:
processor_type (ProcessorType): The family, and version of
the transaction processor.

Returns:
None


def list_group_maintainers(self, name):

        self.project_service.set_auth(self._token_project)
        return self.project_service.list_group_maintainers(name)

Get the maintainers of a group.

Args:
name (string): Name of group to query.

Returns:
(list[string]): List of maintainer names.

Raises:
requests.HTTPError on failure.


def paginator(limit, offset, record_count, base_uri, page_nav_tpl='&limit={}&offset={}'):

    total_pages = int(math.ceil(record_count / limit))

    next_cond = limit + offset <= record_count
    prev_cond = offset >= limit

    next_page = base_uri + page_nav_tpl.format(limit, offset + limit) if next_cond else None

    prev_page = base_uri + page_nav_tpl.format(limit, offset - limit) if prev_cond else None

    return OrderedDict([
        ('total_count', record_count),
        ('total_pages', total_pages),
        ('next_page', next_page),
        ('prev_page', prev_page)
    ])

Compute pagination info for collection filtering.

Args:
limit (int): Collection filter limit.
offset (int): Collection filter offset.
record_count (int): Collection filter total record count.
base_uri (str): Collection filter base uri (without limit, offset)
page_nav_tpl (str): Pagination template.

Returns:
A mapping of pagination info.


def list_hierarchy(class_name, bases):
    class_list = [Uri(class_name)]
    for base in bases:
        if (base.__name__ not in IGNORE_CLASSES):
            class_list.append(Uri(base.__name__))
    return list([i for i in set(class_list)])

Creates a list of the class hierarchy

Args:
-----
class_name: name of the current class
bases: list/tuple of bases for the current class


def annotate(self, gpl, annotation_column, gpl_on='ID', gsm_on='ID_REF', in_place=False):
    if isinstance(gpl, GPL):
        annotation_table = gpl.table
    elif isinstance(gpl, DataFrame):
        annotation_table = gpl
    else:
        raise TypeError('gpl should be a GPL object or a pandas.DataFrame')
    annotated = self.table.merge(annotation_table[[gpl_on, annotation_column]], left_on=gsm_on, right_on=gpl_on)
    del annotated[gpl_on]
    if in_place:
        self.table = annotated
        return None
    else:
        return annotated

Annotate GSM with provided GPL

Args:
gpl (:obj:`pandas.DataFrame`): A Platform or DataFrame to annotate with
annotation_column (str`): Column in a table for annotation
gpl_on (:obj:`str`): Use this column in GSM to merge. Defaults to "ID".
gsm_on (:obj:`str`): Use this column in GPL to merge.
Defaults to "ID_REF".
in_place (:obj:`bool`): Substitute table in GSM by new annotated
table. Defaults to False.

Returns:
:obj:`pandas.DataFrame` or :obj:`None`: Annotated table or None

Raises:
TypeError: GPL should be GPL or pandas.DataFrame


def getall(self, key, default=[]):

        return self.data[key] if key in self.data else default

Return the list of all values for the specified key.

Arguments:
key (object): Key
default (list): Default value to return if the key does not
exist, defaults to ``[]``, i.e. an empty list.

Returns:
list: List of all values for the specified key if the key
exists, ``default`` otherwise.


def __init__(self, vendor=None, body=b''):

        super().__init__()
        self.vendor = vendor
        self.body = body

Create instance attributes.

Args:
vendor (int): 32-bit vendor ID.
body (bytes): Vendor-defined body


def __init__(self, paginator, number, items):

        self.paginator = paginator
        self.number = number
        self.number0 = number - 1
        self.items = items
        self.count = len(items)

        self.total_items = paginator.total_items
        self.items_per_page = paginator.items_per_page
        self.total_pages = paginator.total_pages
        self.page_range = paginator.page_range
        self.start_page = paginator.start_page
        self.last_page = paginator.last_page

Constructor.

Args:
paginator: The parent paginator object.
number: The number of this page (starting from 1).
items: A list of items to belong to this page.


def authorize(self, scheme, **params):
    if (scheme not in self.schemes):
        return False
    for (field, value) in iteritems(params):
        setattr(self, field, value)
        if ((field in self.schemes[scheme][u'params'].keys()) and value):
            self.schemes[scheme][u'params'][field] = value
    return True

Store credentials required to satisfy a given auth scheme.

Args:
scheme (str): The name of the Authentication scheme.
**params: parameters for the specified scheme.

Returns:
True if parameters are set successfully (note that this doesn't mean
the credentials are valid)
False if the scheme specified is not supported


def add_site(self, site):

        start_angle = 0
        radius = 0
        total_occu = 0

        for specie, occu in site.species.items():
            radius += occu * (specie.ionic_radius
                              if isinstance(specie, Specie)
                                 and specie.ionic_radius
                              else specie.average_ionic_radius)
            total_occu += occu

        vis_radius = 0.2 + 0.002 * radius

        for specie, occu in site.species.items():
            if not specie:
                color = (1, 1, 1)
            elif specie.symbol in self.el_color_mapping:
                color = [i / 255 for i in self.el_color_mapping[specie.symbol]]
            mapper = self.add_partial_sphere(site.coords, vis_radius, color,
                                             start_angle, start_angle + 360 * occu)
            self.mapper_map[mapper] = [site]
            start_angle += 360 * occu

        if total_occu < 1:
            mapper = self.add_partial_sphere(site.coords, vis_radius, (1,1,1),
                                             start_angle, start_angle + 360 * (1 - total_occu))
            self.mapper_map[mapper] = [site]

Add a site to the render window. The site is displayed as a sphere, the
color of which is determined based on the element. Partially occupied
sites are displayed as a single element color, though the site info
still shows the partial occupancy.

Args:
site: Site to add.


def info_gen(self, code, message, compressed=False):
    if ('COMPRESS=GZIP' in message):
        return self.__info_gzip_gen()
    if compressed:
        return self.__info_yenczlib_gen()
    return self.__info_plain_gen()

Dispatcher for the info generators.

Determines which __info_*_gen() should be used based on the supplied
parameters.

Args:
code: The status code for the command response.
message: The status message for the command reponse.
compressed: Force decompression. Useful for xz* commands.

Returns:
An info generator.


def fsync(self, file_des):

        if 0 <= file_des < NR_STD_STREAMS:
            self.filesystem.raise_os_error(errno.EINVAL)
        file_object = self.filesystem.get_open_file(file_des)
        if self.filesystem.is_windows_fs:
            if (not hasattr(file_object, 'allow_update') or
                    not file_object.allow_update):
                self.filesystem.raise_os_error(
                    errno.EBADF, file_object.file_path)

Perform fsync for a fake file (in other words, do nothing).

Args:
file_des: The file descriptor of the open file.

Raises:
OSError: file_des is an invalid file descriptor.
TypeError: file_des is not an integer.


def __call__(self, user_lo_config):

        lo_config = {}

        q_los = self.get_qubit_los(user_lo_config)
        if q_los:
            lo_config['qubit_lo_freq'] = q_los
        m_los = self.get_meas_los(user_lo_config)
        if m_los:
            lo_config['meas_lo_freq'] = m_los

        return self.qobj_model(**lo_config)

Return PulseQobjExperimentConfig

Args:
user_lo_config (LoConfig): A dictionary of LOs to format.

Returns:
PulseQobjExperimentConfig: qobj.


def tersoff_potential(self, structure):
    bv = BVAnalyzer()
    el = [site.specie.symbol for site in structure]
    valences = bv.get_valences(structure)
    el_val_dict = dict(zip(el, valences))
    gin = 'species \n'
    qerfstring = 'qerfc\n'
    for key in el_val_dict.keys():
        if ((key != 'O') and ((el_val_dict[key] % 1) != 0)):
            raise SystemError('Oxide has mixed valence on metal')
        specie_string = (((key + ' core ') + str(el_val_dict[key])) + '\n')
        gin += specie_string
        qerfstring += (((key + ' ') + key) + ' 0.6000 10.0000 \n')
    gin += '
    met_oxi_ters = TersoffPotential().data
    for key in el_val_dict.keys():
        if (key != 'O'):
            metal = (((key + '(') + str(int(el_val_dict[key]))) + ')')
            ters_pot_str = met_oxi_ters[metal]
            gin += ters_pot_str
    gin += qerfstring
    return gin

Generate the species, tersoff potential lines for an oxide structure

Args:
structure: pymatgen.core.structure.Structure


def __init__( self, initial_site ):

        Atom.atom_number += 1
        self.number = Atom.atom_number
        self._site = initial_site

        if self._site.occupation == 0:
            self._site.occupation = self.number
            self._site.is_occupied = True
            self._site.atom = self
        else:
            raise ValueError( "This site is already occupied by atom {}".format( initial_site.occupation ) )
        self.reset()

Initialise an Atom instance.

Args:
initial_site (Site): Lattice site initially occupied by this Atom.

Returns:
None


def ed25519_public_key_to_string(key):
    return base64.b64encode(key.public_bytes(encoding=serialization.Encoding.Raw, format=serialization.PublicFormat.Raw), None).decode('utf-8')

Convert an ed25519 public key to a base64-encoded string.

Args:
key (Ed25519PublicKey): the key to write to the file.

Returns:
str: the key representation as a str


def split(self, path):
    return os.path.split(os.path.abspath(path))

Splits the given path into two parts.

Splits the path into a pair (head, tail) such that tail contains the last
component of the path and head contains everything up to that.

Args:
path: path as a string
Returns:
a pair of path components as strings.


def raise_on_errors(errors, level=logging.CRITICAL):
    if errors:
        log.log(level, '\n'.join(errors))
        raise CoTError('\n'.join(errors))

Raise a CoTError if errors.

Helper function because I had this code block everywhere.

Args:
errors (list): the error errors
level (int, optional): the log level to use.  Defaults to logging.CRITICAL

Raises:
CoTError: if errors is non-empty


def post_slack_message(message=None, channel=None, username=None, icon_emoji=None):
    LOG.debug('Slack Channel: %s\nSlack Message: %s', channel, message)
    slack = slacker.Slacker(SLACK_TOKEN)
    try:
        slack.chat.post_message(channel=channel, text=message, username=username, icon_emoji=icon_emoji)
        LOG.info('Message posted to %s', channel)
    except slacker.Error:
        LOG.info('error posted message to %s', channel)

Format the message and post to the appropriate slack channel.

Args:
message (str): Message to post to slack
channel (str): Desired channel. Must start with #


def ParseFileObject(self, parser_mediator, file_object):
    filename = parser_mediator.GetFilename()
    file_size = file_object.get_size()
    if (file_size <= 0):
        raise errors.UnableToParseFile('File size: {0:d} bytes is less equal 0.'.format(file_size))
    if (file_size > 50000000):
        raise errors.UnableToParseFile('File size: {0:d} bytes is larger than 50 MB.'.format(file_size))
    top_level_object = self.GetTopLevel(file_object)
    if (not top_level_object):
        raise errors.UnableToParseFile('Unable to parse: {0:s} skipping.'.format(filename))
    matching_plugin = None
    for plugin in self._plugins:
        try:
            plugin.UpdateChainAndProcess(parser_mediator, plist_name=filename, top_level=top_level_object)
            matching_plugin = plugin
        except errors.WrongPlistPlugin as exception:
            logger.debug('Wrong plugin: {0:s} for: {1:s}'.format(exception.args[0], exception.args[1]))
    if ((not matching_plugin) and self._default_plugin):
        self._default_plugin.UpdateChainAndProcess(parser_mediator, plist_name=filename, top_level=top_level_object)

Parses a plist file-like object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): a file-like object.

Raises:
UnableToParseFile: when the file cannot be parsed.


def pnl_upsert(self, asset_manager_id, pnls):

        self.logger.info('Upsert PnL for - Asset Manager: %s', asset_manager_id)
        pnls = [pnls] if not isinstance(pnls, list) else pnls

        json_pnls = [pnl.to_interface() for pnl in pnls]
        url = '%s/pnls/%s' % (self.endpoint, asset_manager_id)
        response = self.session.put(url, json=json_pnls)
        if response.ok:
            results = []
            for pnl_result in response.json():
                results.append(json_to_pnl(pnl_result))
            self.logger.info('Upserted %s PnL records', len(results))
            return results
        else:
            self.logger.error(response.text)
            response.raise_for_status()

Upsert a list of pnls. Note: this performs a full update
of existing records with matching keys, so the passed in
pnl objects should be complete.

Args:
asset_manager_id (int): the id of the asset manager owning the pnl
pnls (list): list of pnl objects to upsert


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

Determines if the file entry has specific data stream.

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

Returns:
bool: True if the file entry has the data stream.

Raises:
ValueError: if the name is not string.


def get_firmware(self):
    uri = '{}/firmware'.format(self.data['uri'])
    return self._helper.do_get(uri)

Get the firmware inventory of a server.

Note:
This method is available for API version 300 or later.

Returns:
dict: Server Hardware firmware.


def stop(name, file=sys.stderr):
    if is_enabled():
        elapsed = (time() - __TIMERS[name])
        if (elapsed > 60):
            elapsed_str = '{:.1f} m'.format((elapsed / 60))
        elif (elapsed > 1):
            elapsed_str = '{:.1f} s'.format(elapsed)
        else:
            elapsed_str = '{:.1f} ms'.format((elapsed * 1000))
        del __TIMERS[name]
        print('[prof]', name, elapsed_str, file=file)
    return is_enabled()

Stop a profiling timer.

Arguments:

name (str): The name of the timer to stop. If no name is given, stop
the global anonymous timer.

Returns:

bool: Whether or not profiling is enabled.

Raises:

KeyError: If the named timer does not exist.


def _ReadAttributeValueDateTime(self, attribute_values_data, record_offset, attribute_values_data_offset, attribute_value_offset):
    if (attribute_value_offset == 0):
        return None
    data_type_map = self._GetDataTypeMap('keychain_date_time')
    file_offset = ((record_offset + attribute_values_data_offset) + attribute_value_offset)
    attribute_value_offset -= (attribute_values_data_offset + 1)
    attribute_value_data = attribute_values_data[attribute_value_offset:]
    try:
        date_time_attribute_value = self._ReadStructureFromByteStream(attribute_value_data, file_offset, data_type_map)
    except (ValueError, errors.ParseError) as exception:
        raise errors.ParseError('Unable to map date time attribute value data at offset: 0x{0:08x} with error: {1!s}'.format(file_offset, exception))
    return date_time_attribute_value.date_time.rstrip('\x00')

Reads a date time attribute value.

Args:
attribute_values_data (bytes): attribute values data.
record_offset (int): offset of the record relative to the start of
the file.
attribute_values_data_offset (int): offset of the attribute values data
relative to the start of the record.
attribute_value_offset (int): offset of the attribute relative to
the start of the record.

Returns:
str: date and time values.

Raises:
ParseError: if the attribute value cannot be read.


def get_current_state(self, clearConfig: bool = False):

        json_state = self.download_configuration()

        if "errorCode" in json_state:
            LOGGER.error(
                "Could not get the current configuration. Error: %s",
                json_state["errorCode"],
            )
            return False

        if clearConfig:
            self.devices = []
            self.clients = []
            self.groups = []
            self.rules = []
            self.functionalHomes = []

        js_home = json_state["home"]

        self.from_json(js_home)

        self._get_devices(json_state)
        self._get_clients(json_state)
        self._get_groups(json_state)

        self._get_functionalHomes(js_home)
        self._load_functionalChannels()

        return True

downloads the current configuration and parses it into self

Args:
clearConfig(bool): if set to true, this function will remove all old objects
from self.devices, self.client, ... to have a fresh config instead of reparsing them


def GetBalance(self, wallet, address, as_string=False):

        addr = PromptUtils.parse_param(address, wallet)
        if isinstance(addr, UInt160):
            addr = addr.Data
        sb = ScriptBuilder()
        sb.EmitAppCallWithOperationAndArgs(self.ScriptHash, 'balanceOf', [addr])

        tx, fee, results, num_ops, engine_success = test_invoke(sb.ToArray(), wallet, [])
        if engine_success:
            try:
                val = results[0].GetBigInteger()
                precision_divisor = pow(10, self.decimals)
                balance = Decimal(val) / Decimal(precision_divisor)
                if as_string:
                    formatter_str = '.%sf' % self.decimals
                    balance_str = format(balance, formatter_str)
                    return balance_str
                return balance
            except Exception as e:
                logger.error("could not get balance: %s " % e)
                traceback.print_stack()
        else:
            addr_str = Crypto.ToAddress(UInt160(data=addr))
            logger.error(
                f"Could not get balance of address {addr_str} for token contract {self.ScriptHash}. VM execution failed. Make sure the contract exists on the network and that it adheres to the NEP-5 standard")

        return 0

Get the token balance.

Args:
wallet (neo.Wallets.Wallet): a wallet instance.
address (str): public address of the account to get the token balance of.
as_string (bool): whether the return value should be a string. Default is False, returning an integer.

Returns:
int/str: token balance value as int (default), token balanace as string if `as_string` is set to True. 0 if balance retrieval failed.


def SetStorageWriter(self, storage_writer):
    self._storage_writer = storage_writer
    self._last_event_data_hash = None
    self._last_event_data_identifier = None

Sets the storage writer.

Args:
storage_writer (StorageWriter): storage writer.


def read_reply(self) -> Reply:
    _logger.debug('Read reply')
    reply = Reply()
    while True:
        line = (yield from self._connection.readline())
        if (line[(- 1):] != b'\n'):
            raise NetworkError('Connection closed.')
        self._data_event_dispatcher.notify_read(line)
        reply.parse(line)
        if (reply.code is not None):
            break
    return reply

Read a reply from the stream.

Returns:
.ftp.request.Reply: The reply

Coroutine.


def ChunkedAttentionSelector(x, params, selector=None, **kwargs):
    del params, kwargs
    selector = (selector or (lambda x: ([] if (x < 1) else [(x - 1)])))
    (triples, masks) = zip(*x)
    (queries, keys, values) = zip(*triples)
    result = []
    for i in range(len(x)):
        selected = selector(i)
        new_key_list = [keys[j] for j in selected]
        new_key = np.concatenate((new_key_list + [keys[i]]), axis=1)
        new_value = np.concatenate(([values[j] for j in selected] + [values[i]]), axis=1)
        new_mask_shapes = [(1, queries[i].shape[1], key.shape[1]) for key in new_key_list]
        cur_mask = masks[i]
        new_mask_list = [np.ones(s, dtype=cur_mask.dtype) for s in new_mask_shapes]
        new_mask = np.concatenate((new_mask_list + [cur_mask]), axis=2)
        result.append(((queries[i], new_key, new_value), new_mask))
    return tuple(result)

Select which chunks to attend to in chunked attention.

Args:
x: inputs, a list of elements of the form (q, k, v), mask for each chunk.
params: parameters (unused).
selector: a function from chunk_number -> list of chunk numbers that says
which other chunks should be appended to the given one (previous if None).
**kwargs: unused other arguments.

Returns:
a list of elements of the form (q, k', v'), mask' where k', v' and mask' are
concatenations of k, v and identity-extended masks from selected chunks.


def query_parameter(binding_key):
    pbk = ParsedBindingKey(binding_key)
    if (pbk.config_key not in _CONFIG):
        err_str = "Configurable '{}' has no bound parameters."
        raise ValueError(err_str.format(pbk.given_selector))
    if (pbk.arg_name not in _CONFIG[pbk.config_key]):
        err_str = "Configurable '{}' has no value bound for parameter '{}'."
        raise ValueError(err_str.format(pbk.given_selector, pbk.arg_name))
    return _CONFIG[pbk.config_key][pbk.arg_name]

Returns the currently bound value to the specified `binding_key`.

The `binding_key` argument should look like
'maybe/some/scope/maybe.moduels.configurable_name.parameter_name'. Note that
this will not include default parameters.

Args:
binding_key: The parameter whose value should be set.

Returns:
The value bound to the configurable/parameter combination given in
`binding_key`.

Raises:
ValueError: If no function can be found matching the configurable name
specified by `biding_key`, or if the specified parameter name is
blacklisted or not in the function's whitelist (if present) or if there is
no value bound for the queried parameter or configurable.


def char_matches(s1, s2, n=3):
    return __matches(s1, s2, char_ngrams, n=n)

Character-level n-grams that match between two strings

Args:
s1: a string
s2: another string
n: an int for the n in n-gram

Returns:
set: the n-grams found in both strings


def registration_backend(backend=None, namespace=None):

    backend = backend or ORGS_REGISTRATION_BACKEND
    class_module, class_name = backend.rsplit(".", 1)
    mod = import_module(class_module)
    return getattr(mod, class_name)(namespace=namespace)

Returns a specified registration backend

Args:
backend: dotted path to the registration backend class
namespace: URL namespace to use

Returns:
an instance of an RegistrationBackend


def build(self):
    self._import_submodules()
    module_text_map = {}
    footer_text_map = {}
    for dest_module, dest_name_to_imports in self._module_imports.items():
        imports_list = [get_canonical_import(imports) for _, imports in dest_name_to_imports.items()]
        if self._lazy_loading:
            module_text_map[dest_module] = _LAZY_LOADING_MODULE_TEXT_TEMPLATE % '\n'.join(sorted(imports_list))
        else:
            module_text_map[dest_module] = '\n'.join(sorted(imports_list))
    root_module_footer = ''
    if not self._lazy_loading:
        underscore_names_str = ', '.join(("'%s'" % name for name in sorted(self._underscore_names_in_root)))
        root_module_footer = "\n_names_with_underscore = [%s]\n__all__ = [_s for _s in dir() if not _s.startswith('_')]\n__all__.extend([_s for _s in _names_with_underscore])\n" % underscore_names_str
    if self._api_version == 1 or self._lazy_loading:
        for dest_module, _ in self._module_imports.items():
            deprecation = 'False'
            has_lite = 'False'
            if self._api_version == 1:
                if not dest_module.startswith(_COMPAT_MODULE_PREFIX):
                    deprecation = 'True'
            if not dest_module and 'lite' in self._module_imports and self._lazy_loading:
                has_lite = 'True'
            if self._lazy_loading:
                public_apis_name = '_PUBLIC_APIS'
            else:
                public_apis_name = 'None'
            footer_text_map[dest_module] = _DEPRECATION_FOOTER % (dest_module, public_apis_name, deprecation, has_lite)
    return (module_text_map, footer_text_map, root_module_footer)

Get a map from destination module to __init__.py code for that module.

Returns:
A dictionary where
key: (string) destination module (for e.g. tf or tf.consts).
value: (string) text that should be in __init__.py files for
corresponding modules.


def builtin_timescale(cls, name):
    names = {'isc': TIMESCALE__ISC, 'usgs_isc': TIMESCALE__USGS_ISC, 'dnag': TIMESCALE__DNAG}
    return cls.from_csv(text=names[name.lower()])

Generate a default timescale legend. No arguments.

Returns:
Legend: The timescale stored in `defaults.py`.


def scatter_add(self, sparse_delta, use_locking=False, name=None):
    raise NotImplementedError

Adds `tf.IndexedSlices` to this variable.

Args:
sparse_delta: `tf.IndexedSlices` to be added to this variable.
use_locking: If `True`, use locking during the operation.
name: the name of the operation.

Returns:
The updated variable.

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


def _parse_datetime(self, value):

        offset = 0
        pattern = r"\s+([+-]{1}\d+)\Z"
        matches = re.search(pattern, value)
        if matches:
            value = re.sub(pattern, '', value)
            offset = datetime.timedelta(hours=int(matches.group(1))/100)
        return datetime.datetime.strptime(value, "%Y/%m/%d %H:%M:%S") - offset

Parses a datetime string from "YYYY/MM/DD HH:MM:SS +HHMM" format

Args:
value (str): String

Returns:
datetime. Datetime


def _aggregate_grads(gradients):
    assert gradients, 'No gradients to aggregate'
    if len(gradients) == 1:
        return gradients[0]
    if all((isinstance(g, tensor_lib.Tensor) for g in gradients)):
        return gen_math_ops.add_n(gradients)
    else:
        assert all((isinstance(g, (tensor_lib.Tensor, indexed_slices.IndexedSlices)) for g in gradients))
        return backprop_util.AggregateIndexedSlicesGradients(gradients)

Aggregate gradients from multiple sources.

Args:
gradients: A list of 'Tensor' or 'IndexedSlices' gradients.

Returns:
If 'gradients' only has 'Tensor', returns an aggregated 'Tensor'.
Otherwise returns an aggregated 'IndexedSlices'.


def _batched_mask_to_box_tf(masks: 'tf.Tensor'):
    if tf.size(masks) == 0:
        return tf.zeros([*masks.shape[:-2], 4])
    shape = shape_list(masks)
    height, width = shape[-2:]
    in_height = tf.reduce_max(masks, axis=-1)
    in_height_coords = in_height * tf.range(height)[None, :]
    bottom_edges = tf.reduce_max(in_height_coords, axis=-1)
    in_height_coords = in_height_coords + height * ~in_height
    top_edges = tf.reduce_min(in_height_coords, axis=-1)
    in_width, _ = tf.reduce_max(masks, axis=-2)
    in_width_coords = in_width * tf.range(width)[None, :]
    right_edges, _ = tf.reduce_max(in_width_coords, axis=-1)
    in_width_coords = in_width_coords + width * ~in_width
    left_edges, _ = tf.reduce_min(in_width_coords, axis=-1)
    empty_filter = (right_edges < left_edges) | (bottom_edges < top_edges)
    out = tf.stack([left_edges, top_edges, right_edges, bottom_edges], axis=-1)
    out = out * tf.expand_dims(~empty_filter, -1)
    out = tf.reshape(out, *shape[:-2], 4)
    return out

Computes the bounding boxes around the given input masks. The bounding boxes are in the XYXY format which
corresponds the following required indices:
- LEFT: left hand side of the bounding box
- TOP: top of the bounding box
- RIGHT: right of the bounding box
- BOTTOM: bottom of the bounding box

Return [0,0,0,0] for an empty mask. For input shape channel_1 x channel_2 x ... x height x width, the output shape
is channel_1 x channel_2 x ... x 4.

Args:
- masks (`tf.Tensor` of shape `(batch, nb_mask, height, width)`)


def move(self, destination):
    self.relocate(destination)
    shutil.move(self.path, destination)
    self._path = destination

Reconfigure and move the virtual environment to another path.

Args:
destination (str): The target path of the virtual environment.

Note:
Unlike `relocate`, this method *will* move the virtual to the
given path.


def bessel_y0(x, name=None):
    with ops.name_scope(name, 'bessel_y0', [x]):
        return gen_special_math_ops.bessel_y0(x)

Computes the Bessel y0 function of `x` element-wise.

Modified Bessel function of order 0.

>>> tf.math.special.bessel_y0([0.5, 1., 2., 4.]).numpy()
array([-0.44451873,  0.08825696,  0.51037567, -0.01694074], dtype=float32)

Args:
x: A `Tensor` or `SparseTensor`. Must be one of the following types: `half`,
`float32`, `float64`.
name: A name for the operation (optional).

Returns:
A `Tensor` or `SparseTensor`, respectively. Has the same type as `x`.

@compatibility(scipy)
Equivalent to scipy.special.y0
@end_compatibility


def xcompile(source_code, args=0, optimize=True):

    code = crianza.compile(crianza.parse(source_code), optimize=optimize)
    return crianza.native.compile(code, args=args)

Parses Crianza source code and returns a native Python function.

Args:
args: The resulting function's number of input parameters.

Returns:
A callable Python function.


def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]]=None, output_attentions: Optional[bool]=None, **kwargs: Unpack[FlashAttentionKwargs]) -> Tuple[torch.FloatTensor]:
    residual = hidden_states
    hidden_states = self.attention_norm(hidden_states)
    hidden_states, attn_weights = self.attention(hidden_states=hidden_states, attention_mask=attention_mask, position_embeddings=position_embeddings, output_attentions=output_attentions, **kwargs)
    hidden_states = residual + hidden_states
    residual = hidden_states
    hidden_states = self.ffn_norm(hidden_states)
    hidden_states = self.feed_forward(hidden_states)
    hidden_states = residual + hidden_states
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (attn_weights,)
    return outputs

Args:
hidden_states (`torch.FloatTensor`):
Input to the layer of shape `(batch, seq_len, embed_dim)`.
attention_mask (`torch.FloatTensor`):
Attention mask of shape `(batch, 1, q_len, k_v_seq_len)` where padding elements are indicated by very large negative values.
output_attentions (`bool`, *optional*, defaults to `False`):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.


def run_restore_ops(self, session=None):
    raise AssertionError('No checkpoint specified, so no restore ops are available (save_path=None to Saver.restore).')

For consistency with `CheckpointLoadStatus`.

Use `initialize_or_restore` for initializing if no checkpoint was passed
to `Saver.restore` and restoring otherwise.

Args:
session: Not used.


def collapse_short_branches(self, threshold):

        if not isinstance(threshold,float) and not isinstance(threshold,int):
            raise RuntimeError("threshold must be an integer or a float")
        elif threshold < 0:
            raise RuntimeError("threshold cannot be negative")
        q = deque(); q.append(self.root)
        while len(q) != 0:
            next = q.popleft()
            if next.edge_length is None or next.edge_length <= threshold:
                if next.is_root():
                    next.edge_length = None
                elif not next.is_leaf():
                    parent = next.parent; parent.remove_child(next)
                    for c in next.children:
                        parent.add_child(c)
            q.extend(next.children)

Collapse internal branches (not terminal branches) with length less than or equal to ``threshold``. A branch length of ``None`` is considered 0

Args:
``threshold`` (``float``): The threshold to use when collapsing branches


def _file_exists_in_gcs(gcs_file_path, credentials=None):
    gcs_service = _get_storage_service(credentials)
    (bucket_name, object_name) = gcs_file_path[len('gs:
    request = gcs_service.objects().get(bucket=bucket_name, object=object_name, projection='noAcl')
    try:
        request.execute()
        return True
    except errors.HttpError:
        return False

Check whether the file exists, in GCS.

Args:
gcs_file_path: The target file path; should have the 'gs://' prefix.
credentials: Optional credential to be used to load the file from gcs.

Returns:
True if the file's there.


def Deserialize(self, reader):

        super(Block, self).Deserialize(reader)

        self.Transactions = []
        byt = reader.ReadVarInt()
        transaction_length = byt

        if transaction_length < 1:
            raise Exception('Invalid format')

        for i in range(0, transaction_length):
            tx = Transaction.DeserializeFrom(reader)
            self.Transactions.append(tx)

        if MerkleTree.ComputeRoot([tx.Hash for tx in self.Transactions]) != self.MerkleRoot:
            raise Exception("Merkle Root Mismatch")

Deserialize full object.

Args:
reader (neo.IO.BinaryReader):


def remove_room_alias(self, room_alias):

        try:
            self.api.remove_room_alias(room_alias)
            return True
        except MatrixRequestError:
            return False

Remove mapping of an alias

Args:
room_alias(str): The alias to be removed.

Returns:
bool: True if the alias is removed, False otherwise.


def validate(self, profile):
    ij = self.load_install_json(profile.get('install_json'))
    print('{}{}Profile: "{}".'.format(c.Style.BRIGHT, c.Fore.BLUE, profile.get('profile_name')))
    for arg in self.profile_settings_args_install_json(ij, None):
        if (profile.get('args', {}).get('app', {}).get(arg) is None):
            print('{}{}Input "{}" not found.'.format(c.Style.BRIGHT, c.Fore.YELLOW, arg))

Check to see if any args are "missing" from profile.

Validate all args from install.json are in the profile.  This can be helpful to validate
that any new args added to App are included in the profiles.

.. Note:: This method does not work with layout.json Apps.

Args:
profile (dict): The current profile to validate.


def create_alias(target_path, alias_path):

    if platform.system() == 'Windows' and not alias_path.endswith('.lnk'):
        alias_path += '.lnk'
    if os.path.lexists(alias_path):
        os.remove(alias_path)
    if platform.system() == 'Windows':
        from win32com import client
        shell = client.Dispatch('WScript.Shell')
        shortcut = shell.CreateShortCut(alias_path)
        shortcut.Targetpath = target_path
        shortcut.save()
    else:
        os.symlink(target_path, alias_path)

Creates an alias at 'alias_path' pointing to the file 'target_path'.

On Unix, this is implemented via symlink. On Windows, this is done by
creating a Windows shortcut file.

Args:
target_path: Destination path that the alias should point to.
alias_path: Path at which to create the new alias.


def get_named_parent(decl):

    if not decl:
        return None

    parent = decl.parent
    while parent and (not parent.name or parent.name == '::'):
        parent = parent.parent
    return parent

Returns a reference to a named parent declaration.

Args:
decl (declaration_t): the child declaration

Returns:
declaration_t: the declaration or None if not found.


def _MergeEntities(self, a, b):
    distance = transitfeed.ApproximateDistanceBetweenStops(a, b)
    if (distance > self.largest_stop_distance):
        raise MergeError(('Stops are too far apart: %.1fm (largest_stop_distance is %.1fm).' % (distance, self.largest_stop_distance)))
    scheme = {'stop_id': self._MergeIdentical, 'stop_name': self._MergeIdenticalCaseInsensitive, 'zone_id': self._MergeIdentical, 'location_type': self._MergeIdentical}
    return self._SchemedMerge(scheme, a, b)

Merges two stops.

For the stops to be merged, they must have:
- the same stop_id
- the same stop_name (case insensitive)
- the same zone_id
- locations less than largest_stop_distance apart
The other attributes can have arbitary changes. The merged attributes are
taken from the new stop.

Args:
a: The first stop.
b: The second stop.

Returns:
The merged stop.

Raises:
MergeError: The stops could not be merged.


def get_value(self, query):

        indices = self.get_dimension_indices(query)
        index = self.get_value_index(indices)
        value = self.get_value_by_index(index)
        return value

Converts a dimension/category list of dicts into a data value \
in three steps.

Args:
query(list): list of dicts with the desired query.

Returns:
value(float): numeric data value.


def regex_to_sql_like(regex_text: str, single_wildcard: str='_', zero_or_more_wildcard: str='%') -> List[str]:

    def append_to_all(new_content: str) -> None:
        nonlocal results
        results = [(r + new_content) for r in results]

    def split_and_append(new_options: List[str]) -> None:
        nonlocal results
        newresults = []
        for option in new_options:
            newresults.extend([(r + option) for r in results])
        results = newresults

    def deduplicate_wildcards(text: str) -> str:
        while ((zero_or_more_wildcard + zero_or_more_wildcard) in text):
            text = text.replace((zero_or_more_wildcard + zero_or_more_wildcard), zero_or_more_wildcard)
        return text
    working = regex_text
    results = [zero_or_more_wildcard]
    while working:
        if working.startswith('.*'):
            append_to_all(zero_or_more_wildcard)
            working = working[2:]
        elif working.startswith('['):
            close_bracket = working.index(']')
            bracketed = working[1:close_bracket]
            option_groups = bracketed.split('|')
            options = [c for group in option_groups for c in group]
            split_and_append(options)
            working = working[(close_bracket + 1):]
        elif ((len(working) > 1) and (working[1] == '?')):
            split_and_append(['', working[0]])
            working = working[2:]
        elif working.startswith('.'):
            append_to_all(single_wildcard)
            working = working[1:]
        else:
            append_to_all(working[0])
            working = working[1:]
    append_to_all(zero_or_more_wildcard)
    results = [deduplicate_wildcards(r) for r in results]
    return results

Converts regular expression text to a reasonably close fragment
for the SQL ``LIKE`` operator.

NOT PERFECT, but works for current built-in regular expressions.

Args:
regex_text: regular expression text to work with
single_wildcard: SQL single wildcard, typically an underscore
zero_or_more_wildcard: SQL "zero/one/many" wildcard, probably always
a percent symbol

Returns:
string for an SQL string literal

Raises:
:exc:`ValueError` for some regex text that it doesn't understand
properly


def aside_view_declaration(self, view_name):

        if view_name in self._combined_asides:
            return getattr(self, self._combined_asides[view_name])
        else:
            return None

Find and return a function object if one is an aside_view for the given view_name

Aside methods declare their view provision via @XBlockAside.aside_for(view_name)
This function finds those declarations for a block.

Arguments:
view_name (string): the name of the view requested.

Returns:
either the function or None


def build_sql_statement(self) -> str:
    builders = self._view.get_select_expressions()
    from_expressions = [f'`{self._dataset}`.{self._table_name}']
    where_expressions = self._build_where_expressions(self._view.get_constraint_expressions())
    if not builders:
        return self._build_sql_statement(['*'], from_expressions, where_expressions)
    sql_statement = ''
    next_from_expressions = []
    child_builders = []
    columns_selected = []
    while builders or next_from_expressions:
        select_expressions, next_from_expressions = self._build_select_and_next_from_expressions(builders, child_builders, columns_selected)
        sql_statement = self._build_sql_statement(select_expressions, from_expressions, where_expressions)
        from_expressions = [f'({sql_statement})']
        from_expressions.extend(next_from_expressions)
        where_expressions = []
        builders = tuple(child_builders)
        child_builders = []
    return sql_statement

Build SQL statement.

Returns:
SQL string representation of the view


def write_dot_file(G, filename):

    with io.open(filename, "w") as fh:
        fh.write("strict digraph DependencyDiagram {\n")
        edge_list = G.edges()
        node_list = set(G.nodes())
        if edge_list:
            for edge in sorted(edge_list):
                source, targ = edge
                node_list = node_list - set(source)
                node_list = node_list - set(targ)
                line = '"{}" -> "{}";\n'
                fh.write(line.format(source, targ))

        if node_list:
            for node in sorted(node_list):
                line = '"{}"\n'.format(node)
                fh.write(line)
        fh.write("}")

Writes the graph G in dot file format for graphviz visualization.

Args:
a Networkx graph
A filename to name the dot files


def apply_transform(self, data: OperationInputT, output_column_name: str) -> dict[str, OperationOutputT]:

Define any processing logic in the apply_transform() method.
processing logics are applied on inputs and returns a transformed
output.
Args:
inputs: input data.


def unapprove(self, **kwargs):

        path = '%s/%s/unapprove' % (self.manager.path, self.get_id())
        data = {}

        server_data = self.manager.gitlab.http_post(path, post_data=data,
                                                    **kwargs)
        self._update_attrs(server_data)

Unapprove the merge request.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabMRApprovalError: If the unapproval failed


def __request_finish(self, queue_item, new_requests, request_failed=False):
    if self.__stopping:
        return
    del self.__threads[queue_item.get_hash()]
    if request_failed:
        new_queue_items = []
        self.queue.move(queue_item, QueueItem.STATUS_ERRORED)
    else:
        self.routing.increase_route_count(queue_item.request)
        new_queue_items = self.__add_scraped_requests_to_queue(queue_item, new_requests)
        self.queue.move(queue_item, QueueItem.STATUS_FINISHED)
    try:
        action = self.__options.callbacks.request_after_finish(self.queue, queue_item, new_queue_items)
    except Exception as e:
        action = None
        print(e)
        print(traceback.format_exc())
    queue_item.decompose()
    if (action == CrawlerActions.DO_STOP_CRAWLING):
        self.__should_stop = True
    if ((action == CrawlerActions.DO_CONTINUE_CRAWLING) or (action is None)):
        self.__should_spawn_new_requests = True

Called when the crawler finished the given queue item.

Args:
queue_item (:class:`nyawc.QueueItem`): The request/response pair that finished.
new_requests list(:class:`nyawc.http.Request`): All the requests that were found during this request.
request_failed (bool): True if the request failed (if needs to be moved to errored).


def _get_authenticated_client(self, wsdl):
    return zeep.Client((wsdl % quote(self.username)), transport=zeep.Transport(session=self._get_authenticated_session()))

Return an authenticated SOAP client.

Returns:
zeep.Client: Authenticated API client.


def parse(cls, json_value: Union[int, float, str, List[Any], Tuple[Any], None], spec: Optional[DNASpec]=None) -> 'DNA':
    return DNA(json_value, spec=spec)

Parse DNA from a nested structure of numbers.

Deprecated: use `DNA.__init__` instead.

Args:
json_value: A nested structure of numbers.
spec: DNA spec that will be applied to current DNA tree.

Returns:
an instance of DNA object.

Raises:
ValueError: Bad format for json_value or parsed DNA does not conform to
the DNA spec.


class TFGPT2Tokenizer(keras.layers.Layer):

    def __init__(self, vocab: Dict[str, int], merges: List[str], max_length: Optional[int]=None, pad_token_id: Optional[int]=None):
        super().__init__()
        self.pad_token_id = pad_token_id
        self.max_length = max_length
        self.vocab = vocab
        self.merges = merges
        self.tf_tokenizer = BytePairTokenizer(vocab, merges, sequence_length=max_length)

    @classmethod
    def from_tokenizer(cls, tokenizer: GPT2Tokenizer, *args, **kwargs):

        merges = [' '.join(m) for m in tokenizer.bpe_ranks.keys()]
        vocab = tokenizer.get_vocab()
        return cls(vocab, merges, *args, **kwargs)

    @classmethod
    def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], *init_inputs, **kwargs):

        tokenizer = GPT2Tokenizer.from_pretrained(pretrained_model_name_or_path, *init_inputs, **kwargs)
        return cls.from_tokenizer(tokenizer, *init_inputs, **kwargs)

    @classmethod
    def from_config(cls, config):

        return cls(**config)

    def get_config(self):
        return {'vocab': self.vocab, 'merges': self.merges, 'max_length': self.max_length, 'pad_token_id': self.pad_token_id}

    def call(self, x, max_length: Optional[int]=None):
        input_ids = self.tf_tokenizer(x)
        attention_mask = tf.ones_like(input_ids)
        if self.pad_token_id is not None:
            max_length = max_length if max_length is not None else self.max_length
            if max_length is not None:
                input_ids, attention_mask = pad_model_inputs(input_ids, max_seq_length=max_length, pad_value=self.pad_token_id)
        return {'attention_mask': attention_mask, 'input_ids': input_ids}

This is an in-graph tokenizer for GPT2. It should be initialized similarly to other tokenizers, using the
`from_pretrained()` method. It can also be initialized with the `from_tokenizer()` method, which imports settings
from an existing standard tokenizer object.

In-graph tokenizers, unlike other Hugging Face tokenizers, are actually Keras layers and are designed to be run
when the model is called, rather than during preprocessing. As a result, they have somewhat more limited options
than standard tokenizer classes. They are most useful when you want to create an end-to-end model that goes
straight from `tf.string` inputs to outputs.

Args:
vocab (Dict[str, int]): Vocabulary dict for Byte Pair Tokenizer
merges (List[str]): Merges list for Byte Pair Tokenizer


def signature_summary(self, default_values=False):
    summary = f'{self._function_type!r}'
    if default_values:
        summary += '\nDefaults:'
        if self.default_values:
            for name, value in self.default_values.items():
                summary += f'\n  {name}: {value!r}'
        else:
            summary += '\n  None'
    return summary

Returns a string summarizing this function's signature.

Args:
default_values: If true, then include default values in the signature.

Returns:
A `string`.


def get_variables(self, include_submodules=False, include_nontrainable=False):

        if include_nontrainable:
            model_variables = [self.all_variables[key] for key in sorted(self.all_variables)]

            states_preprocessing_variables = [
                variable for name in sorted(self.states_preprocessing)
                for variable in self.states_preprocessing[name].get_variables()
            ]
            model_variables += states_preprocessing_variables

            actions_exploration_variables = [
                variable for name in sorted(self.actions_exploration)
                for variable in self.actions_exploration[name].get_variables()
            ]
            model_variables += actions_exploration_variables

            if self.reward_preprocessing is not None:
                reward_preprocessing_variables = self.reward_preprocessing.get_variables()
                model_variables += reward_preprocessing_variables

        else:
            model_variables = [self.variables[key] for key in sorted(self.variables)]

        return model_variables

Returns the TensorFlow variables used by the model.

Args:
include_submodules: Includes variables of submodules (e.g. baseline, target network)
if true.
include_nontrainable: Includes non-trainable variables if true.

Returns:
List of variables.


def format_search_results(self, search_results):

        formatted_lines = []

        for search_result in search_results:
            lines = self._format_search_result(search_result)
            formatted_lines.extend(lines)

        return formatted_lines

Format search results.

Args:
search_results (list of `ResourceSearchResult`): Search to format.

Returns:
List of 2-tuple: Text and color to print in.


def load_lines(filename):

    with open(filename, 'r', encoding='utf-8') as f:
        return [line.rstrip('\n') for line in f.readlines()]

Load a text file as an array of lines.

Args:
filename: Path to the input file.

Returns:
An array of strings, each representing an individual line.


def check_layout(tensor: tensor_lib.Tensor, layout: layout_lib.Layout) -> None:
    if fetch_layout(tensor) != layout:
        raise ValueError('Layout of tensor: ' + str(fetch_layout(tensor)) + ', did not match expected layout: ' + str(layout))

Asserts that the layout of the DTensor is `layout`.

Args:
tensor: A DTensor whose layout is to be checked.
layout: The `Layout` to compare against.

Raises:
ValueError: If the layout of `tensor` does not match the supplied `layout`.


def get_user(
        self, identified_with, identifier, req, resp, resource, uri_kwargs
    ):

        stored_value = self.kv_store.get(
            self._get_storage_key(identified_with, identifier)
        )
        if stored_value is not None:
            user = self.serialization.loads(stored_value.decode())
        else:
            user = None

        return user

Get user object for given identifier.

Args:
identified_with (object): authentication middleware used
to identify the user.
identifier: middleware specifix user identifier (string or tuple
in case of all built in authentication middleware classes).

Returns:
dict: user object stored in Redis if it exists, otherwise ``None``


def select_all(self, serial_numbers):

        sheet = self.table
        col = self.db_sheet_cols.id
        rows = sheet.loc[:, col].isin(serial_numbers)
        return sheet.loc[rows, :]

Select rows for identification for a list of serial_number.

Args:
serial_numbers: list (or ndarray) of serial numbers

Returns:
pandas.DataFrame


def from_table(table, fields=None):

    if fields is None:
      fields = '*'
    elif isinstance(fields, list):
      fields = ','.join(fields)
    return Query('SELECT %s FROM %s' % (fields, table._repr_sql_()))

Return a Query for the given Table object

Args:
table: the Table object to construct a Query out of
fields: the fields to return. If None, all fields will be returned. This can be a string
which will be injected into the Query after SELECT, or a list of field names.

Returns:
A Query object that will return the specified fields from the records in the Table.


def create_window(size=None, samples=16, *, fullscreen=False, title=None, threaded=True) -> Window:

    if size is None:
        width, height = 1280, 720

    else:
        width, height = size

    if samples < 0 or (samples & (samples - 1)) != 0:
        raise Exception('Invalid number of samples: %d' % samples)

    window = Window.__new__(Window)
    window.wnd = glwnd.create_window(width, height, samples, fullscreen, title, threaded)
    return window

Create the main window.

Args:
size (tuple): The width and height of the window.
samples (int): The number of samples.

Keyword Args:
fullscreen (bool): Fullscreen?
title (bool): The title of the window.
threaded (bool): Threaded?

Returns:
Window: The main window.


def _check_wires_list(self, wires, node):

        if len(set(wires)) != len(wires):
            raise DAGCircuitError("duplicate wires")

        wire_tot = len(node.qargs) + len(node.cargs)
        if node.condition is not None:
            wire_tot += node.condition[0].size

        if len(wires) != wire_tot:
            raise DAGCircuitError("expected %d wires, got %d"
                                  % (wire_tot, len(wires)))

Check that a list of wires is compatible with a node to be replaced.

- no duplicate names
- correct length for operation
Raise an exception otherwise.

Args:
wires (list[register, index]): gives an order for (qu)bits
in the input circuit that is replacing the node.
node (DAGNode): a node in the dag

Raises:
DAGCircuitError: if check doesn't pass.


def recipe_archive(config, auth_write, archive_days, archive_bucket, archive_path, archive_delete):
    archive(config, {'auth': auth_write, 'days': archive_days, 'storage': {'bucket': archive_bucket, 'path': archive_path}, 'delete': archive_delete})

Wipe old information from a Storage bucket based on last update time.

Args:
auth_write (authentication) - Credentials used for writing data.
archive_days (integer) - NA
archive_bucket (string) - NA
archive_path (string) - NA
archive_delete (boolean) - NA


def clean(decrypted: bytes) -> str:
    r
    last = decrypted[-1]
    if isinstance(last, int):
        return decrypted[:-last].decode('utf8')
    return decrypted[:-ord(last)].decode('utf8')

r"""Strip padding from decrypted value.

Remove number indicated by padding
e.g. if last is '\x0e' then ord('\x0e') == 14, so take off 14.

Args:
decrypted: decrypted value
Returns:
Decrypted stripped of junk padding


def delete_existing_policy(self, scaling_policy, server_group):

        self.log.info("Deleting policy %s on %s", scaling_policy['policyName'], server_group)
        delete_dict = {
            "application":
            self.app,
            "description":
            "Delete scaling policy",
            "job": [{
                "policyName": scaling_policy['policyName'],
                "serverGroupName": server_group,
                "credentials": self.env,
                "region": self.region,
                "provider": "aws",
                "type": "deleteScalingPolicy",
                "user": "foremast-autoscaling-policy"
            }]
        }
        wait_for_task(json.dumps(delete_dict))

Given a scaling_policy and server_group, deletes the existing scaling_policy.
Scaling policies need to be deleted instead of upserted for consistency.

Args:
scaling_policy (json): the scaling_policy json from Spinnaker that should be deleted
server_group (str): the affected server_group


def save_output_in_cache(name, filename, output):

    cache_filename = _get_cache_filename(name, filename)
    with _open_for_write(cache_filename) as f:
        f.write(output)

Saves output in the cache location.

Args:
name: string: name of the linter.
filename: string: path of the filename for which we are saving the output.
output: string: full output (not yet filetered) of the lint command.


def _GetEventLogProviderKey(self, log_source):

    table_names = ['event_log_providers']
    column_names = ['event_log_provider_key']
    condition = 'log_source == "{0:s}"'.format(log_source)

    values_list = list(self._database_file.GetValues(
        table_names, column_names, condition))

    number_of_values = len(values_list)
    if number_of_values == 0:
      return None

    if number_of_values == 1:
      values = values_list[0]
      return values['event_log_provider_key']

    raise RuntimeError('More than one value found in database.')

Retrieves the Event Log provider key.

Args:
log_source (str): Event Log source.

Returns:
str: Event Log provider key or None if not available.

Raises:
RuntimeError: if more than one value is found in the database.


def _close_on_stop(self, sess, cancel_op, coord):
    coord.wait_for_stop()
    try:
        sess.run(cancel_op)
    except Exception as e:
        logging.vlog(1, 'Ignored exception: %s', str(e))

Close the queue when the Coordinator requests stop.

Args:
sess: A Session.
cancel_op: The Operation to run.
coord: Coordinator.


def PushAttributeContainer(self, serialized_data):

    self._list.append(serialized_data)
    self.data_size += len(serialized_data)
    self.next_sequence_number += 1

Pushes a serialized attribute container onto the list.

Args:
serialized_data (bytes): serialized attribute container data.


def encode_message(self, message):
    message.check_initialized()
    return json.dumps(message, cls=MessageJSONEncoder, protojson_protocol=self)

Encode Message instance to JSON string.

Args:
Message instance to encode in to JSON string.

Returns:
String encoding of Message instance in protocol JSON format.

Raises:
messages.ValidationError if message is not initialized.


def populate_sites( self, number_of_atoms, selected_sites=None ):

        if number_of_atoms > self.number_of_sites:
            raise ValueError
        if selected_sites:
            atoms = [ atom.Atom( initial_site = site ) for site in random.sample( [ s for s in self.sites if s.label in selected_sites ], number_of_atoms ) ]
        else:
            atoms = [ atom.Atom( initial_site = site ) for site in random.sample( self.sites, number_of_atoms ) ]
        self.number_of_occupied_sites = number_of_atoms
        return atoms

Populate the lattice sites with a specific number of atoms.

Args:
number_of_atoms (Int): The number of atoms to populate the lattice sites with.
selected_sites (:obj:List, optional): List of site labels if only some sites are to be occupied. Defaults to None.

Returns:
None


def exists(self, filename):
    if is_package(filename):
        filepath = os.path.join(self.connection['mount_point'], 'Packages', filename)
    else:
        filepath = os.path.join(self.connection['mount_point'], 'Scripts', filename)
    return os.path.exists(filepath)

Report whether a file exists on the distribution point.

Determines file type by extension.

Args:
filename: Filename you wish to check. (No path! e.g.:
"AdobeFlashPlayer-14.0.0.176.pkg")


def compiler_ir_generator(stage='hlo', device_name=None, platform_name=None):
    if device_name is not None:
        if platform_name is not None:
            raise ValueError('device_name and platform_name cannot be provided at the same time.')
        warnings.warn('device_name is being deprecated. Use platform_name.')
    device_name = maybe_get_device_name(device_name)
    res_bytes = context.context().get_compiler_ir(device_name=device_name, platform_name=platform_name, function_name=fn_name, flat_args=filtered_flat_specs, captured_inputs=concrete_fn.captured_inputs, stage=stage)
    if stage in ('stablehlo_serialized', 'hlo_serialized', 'optimized_hlo_serialized', 'optimized_hlo_proto_serialized'):
        return res_bytes
    else:
        return res_bytes.decode('utf-8')

Gets the compiler IR bytes.

Args:
stage: The exported stage for the given function.
device_name: The name of the device with the form as
"/job:localhost/replica:0/task:0/device:CPU:0", "/device:TPU:0" etc.
When this is used, actual device is needed for getting the compiler IR.
platform_name: The name of the platform, e.g. "TPU". See the comment in
`get_compiler_ir` in `context.py`.

Returns:
The compiler IR bytes.


def is_connectable(host: str, port: Union[(int, str)]) -> bool:
    socket_ = None
    try:
        socket_ = socket.create_connection((host, port), 1)
        result = True
    except socket.timeout:
        result = False
    finally:
        if socket_:
            socket_.close()
    return result

Tries to connect to the device to see if it is connectable.

Args:
host: The host to connect.
port: The port to connect.

Returns:
True or False.


def GetTSKVsPartByPathSpec(tsk_volume, path_spec):

  location = getattr(path_spec, 'location', None)
  part_index = getattr(path_spec, 'part_index', None)
  start_offset = getattr(path_spec, 'start_offset', None)
  partition_index = None

  if part_index is None:
    if location is not None:
      if location.startswith('/p'):
        try:
          partition_index = int(location[2:], 10) - 1
        except ValueError:
          pass

      if partition_index is None or partition_index < 0:
        location = None

    if location is None and start_offset is None:
      return None, None

  bytes_per_sector = TSKVolumeGetBytesPerSector(tsk_volume)
  current_part_index = 0
  current_partition_index = 0
  tsk_vs_part = None

  tsk_vs_part_list = list(tsk_volume)
  number_of_tsk_vs_parts = len(tsk_vs_part_list)

  if number_of_tsk_vs_parts > 0:
    if (part_index is not None and
        (part_index < 0 or part_index >= number_of_tsk_vs_parts)):
      return None, None

    for tsk_vs_part in tsk_vs_part_list:
      if TSKVsPartIsAllocated(tsk_vs_part):
        if partition_index is not None:
          if partition_index == current_partition_index:
            break
        current_partition_index += 1

      if part_index is not None and part_index == current_part_index:
        break

      if start_offset is not None:
        start_sector = TSKVsPartGetStartSector(tsk_vs_part)

        if start_sector is not None:
          start_sector *= bytes_per_sector
          if start_sector == start_offset:
            break

      current_part_index += 1

  if tsk_vs_part is None or current_part_index >= number_of_tsk_vs_parts:
    return None, None

  if not TSKVsPartIsAllocated(tsk_vs_part):
    current_partition_index = None
  return tsk_vs_part, current_partition_index

Retrieves the TSK volume system part object from the TSK volume object.

Args:
tsk_volume (pytsk3.Volume_Info): TSK volume information.
path_spec (PathSpec): path specification.

Returns:
tuple: contains:

pytsk3.TSK_VS_PART_INFO: TSK volume system part information or
None on error.
int: partition index or None if not available.


def getUserSid(username):
    if six.PY2:
        username = _to_unicode(username)
    domain = win32api.GetComputerName()
    if (username.find('\\') != (- 1)):
        domain = username.split('\\')[0]
        username = username.split('\\')[(- 1)]
    domain = domain.upper()
    return win32security.ConvertSidToStringSid(win32security.LookupAccountName(None, ((domain + '\\') + username))[0])

Get the Security ID for the user

Args:
username (str): The user name for which to look up the SID

Returns:
str: The user SID

CLI Example:

.. code-block:: bash

salt '*' user.getUserSid jsnuffy


def get_scheduler(name: Union[str, SchedulerType], optimizer: Optimizer, num_warmup_steps: Optional[int]=None, num_training_steps: Optional[int]=None, scheduler_specific_kwargs: Optional[dict]=None):
    name = SchedulerType(name)
    schedule_func = TYPE_TO_SCHEDULER_FUNCTION[name]
    if optimizer is not None and isinstance(optimizer, LayerWiseDummyOptimizer):
        optimizer_dict = optimizer.optimizer_dict
        scheduler_dict = {}
        for param in optimizer_dict.keys():
            scheduler_dict[param] = get_scheduler(name, optimizer=optimizer_dict[param], num_warmup_steps=num_warmup_steps, num_training_steps=num_training_steps, scheduler_specific_kwargs=scheduler_specific_kwargs)

        def scheduler_hook(param):
            scheduler_dict[param].step()
        for param in optimizer_dict.keys():
            if param.requires_grad:
                param.register_post_accumulate_grad_hook(scheduler_hook)
        return LayerWiseDummyScheduler(optimizer_dict=optimizer_dict, lr=optimizer.defaults['lr'])
    if name == SchedulerType.CONSTANT:
        return schedule_func(optimizer)
    if scheduler_specific_kwargs is None:
        scheduler_specific_kwargs = {}
    if name == SchedulerType.REDUCE_ON_PLATEAU:
        return schedule_func(optimizer, **scheduler_specific_kwargs)
    if num_warmup_steps is None:
        raise ValueError(f'{name} requires `num_warmup_steps`, please provide that argument.')
    if name == SchedulerType.CONSTANT_WITH_WARMUP:
        return schedule_func(optimizer, num_warmup_steps=num_warmup_steps)
    if name == SchedulerType.INVERSE_SQRT:
        return schedule_func(optimizer, num_warmup_steps=num_warmup_steps)
    if name == SchedulerType.WARMUP_STABLE_DECAY:
        return schedule_func(optimizer, num_warmup_steps=num_warmup_steps, num_training_steps=num_training_steps, **scheduler_specific_kwargs)
    if num_training_steps is None:
        raise ValueError(f'{name} requires `num_training_steps`, please provide that argument.')
    return schedule_func(optimizer, num_warmup_steps=num_warmup_steps, num_training_steps=num_training_steps, **scheduler_specific_kwargs)

Unified API to get any scheduler from its name.

Args:
name (`str` or `SchedulerType`):
The name of the scheduler to use.
optimizer (`torch.optim.Optimizer`):
The optimizer that will be used during training.
num_warmup_steps (`int`, *optional*):
The number of warmup steps to do. This is not required by all schedulers (hence the argument being
optional), the function will raise an error if it's unset and the scheduler type requires it.
num_training_steps (`int``, *optional*):
The number of training steps to do. This is not required by all schedulers (hence the argument being
optional), the function will raise an error if it's unset and the scheduler type requires it.
scheduler_specific_kwargs (`dict`, *optional*):
Extra parameters for schedulers such as cosine with restarts. Mismatched scheduler types and scheduler
parameters will cause the scheduler function to raise a TypeError.


def platform_config_dir():
    if LINUX:
        dpath_ = os.environ.get('XDG_CONFIG_HOME', '~/.config')
    elif DARWIN:
        dpath_ = '~/Library/Application Support'
    elif WIN32:
        dpath_ = os.environ.get('APPDATA', '~/AppData/Roaming')
    else:
        raise NotImplementedError(('Unknown Platform  %r' % (sys.platform,)))
    dpath = normpath(expanduser(dpath_))
    return dpath

Returns a directory which should be writable for any application
This should be used for persistent configuration files.

Returns:
PathLike : path to the cahce dir used by the current operating system


def map_uniprot_resnum_to_pdb(uniprot_resnum, chain_id, sifts_file):
    parser = etree.XMLParser(ns_clean=True)
    tree = etree.parse(sifts_file, parser)
    root = tree.getroot()
    my_pdb_resnum = None
    my_pdb_annotation = False
    ent = '.
    for chain in root.findall(ent):
        if (chain.attrib['entityId'] == chain_id):
            ures = ('.
            my_uniprot_residue = chain.findall(ures)
            if (len(my_uniprot_residue) == 1):
                parent = my_uniprot_residue[0].getparent()
                pres = '.
                my_pdb_residue = parent.findall(pres)
                my_pdb_resnum = int(my_pdb_residue[0].attrib['dbResNum'])
                anno = '.
                my_pdb_annotation = parent.findall(anno)
                if (len(my_pdb_annotation) == 1):
                    my_pdb_annotation = my_pdb_annotation[0].text
                    if (my_pdb_annotation == 'Not_Observed'):
                        my_pdb_annotation = False
                else:
                    my_pdb_annotation = True
            else:
                return (None, False)
    return (my_pdb_resnum, my_pdb_annotation)

Map a UniProt residue number to its corresponding PDB residue number.

This function requires that the SIFTS file be downloaded,
and also a chain ID (as different chains may have different mappings).

Args:
uniprot_resnum (int): integer of the residue number you'd like to map
chain_id (str): string of the PDB chain to map to
sifts_file (str): Path to the SIFTS XML file

Returns:
(tuple): tuple containing:

mapped_resnum (int): Mapped residue number
is_observed (bool): Indicates if the 3D structure actually shows the residue


def wait_for_tx(self, tx, max_seconds=120):

    tx_hash = None
    if isinstance(tx, (str, UInt256)):
        tx_hash = str(tx)
    elif isinstance(tx, Transaction):
        tx_hash = tx.Hash.ToString()
    else:
        raise AttributeError("Supplied tx is type '%s', but must be Transaction or UInt256 or str" % type(tx))

    wait_event = Event()
    time_start = time.time()

    while True:

        _tx, height = Blockchain.Default().GetTransaction(tx_hash)
        if height > -1:
            return True

        wait_event.wait(3)

        seconds_passed = time.time() - time_start
        if seconds_passed > max_seconds:
            raise TxNotFoundInBlockchainError("Transaction with hash %s not found after %s seconds" % (tx_hash, int(seconds_passed)))

Wait for tx to show up on blockchain

Args:
tx (Transaction or UInt256 or str): Transaction or just the hash
max_seconds (float): maximum seconds to wait for tx to show up. default: 120

Returns:
True: if transaction was found

Raises:
AttributeError: if supplied tx is not Transaction or UInt256 or str
TxNotFoundInBlockchainError: if tx is not found in blockchain after max_seconds


def get_icloud_folder_location():
    yosemite_icloud_path = '~/Library/Mobile Documents/com~apple~CloudDocs/'
    icloud_home = os.path.expanduser(yosemite_icloud_path)
    if (not os.path.isdir(icloud_home)):
        error('Unable to find your iCloud Drive =(')
    return str(icloud_home)

Try to locate the iCloud Drive folder.

Returns:
(str) Full path to the iCloud Drive folder.


def kms_encrypt(value, key, aws_config=None):
    aws_config = (aws_config or {})
    aws = boto3.session.Session(**aws_config)
    client = aws.client('kms')
    enc_res = client.encrypt(KeyId=key, Plaintext=value)
    return n(b64encode(enc_res['CiphertextBlob']))

Encrypt and value with KMS key.

Args:
value (str): value to encrypt
key (str): key id or alias
aws_config (optional[dict]): aws credentials
dict of arguments passed into boto3 session
example:
aws_creds = {'aws_access_key_id': aws_access_key_id,
'aws_secret_access_key': aws_secret_access_key,
'region_name': 'us-east-1'}

Returns:
str: encrypted cipher text


def transform_table(self, table, table_meta, missing=None):

        if missing is None:
            missing = self.missing

        else:
            self.missing = missing
            warnings.warn(DEPRECATION_MESSAGE.format('transform_table'), DeprecationWarning)

        content = {}
        columns = []
        table_name = table_meta['name']

        for field in table_meta['fields']:
            column_name = field['name']

            if missing and table[column_name].isnull().any():
                null_transformer = transformers.NullTransformer(field)
                clean_column = null_transformer.fit_transform(table[column_name])
                null_name = '?' + column_name
                columns.append(null_name)
                content[null_name] = clean_column[null_name].values
                column = clean_column[column_name]

            else:
                column = table[column_name].to_frame()

            transformer = self.transformers[(table_name, column_name)]
            content[column_name] = transformer.transform(column)[column_name].values
            columns.append(column_name)

        return pd.DataFrame(content, columns=columns)

Apply the stored transformers to `table`.

Args:
table(pandas.DataFrame):     Contents of the table to be transformed.

table_meta(dict):   Metadata for the given table.

missing(bool):      Wheter or not use NullTransformer to handle missing values.

Returns:
pandas.DataFrame: Transformed table.


def recipe_dcm_run(config, auth_read, account, report_id, report_name):
    dcm(config, {'auth': auth_read, 'report_run_only': True, 'report': {'account': account, 'report_id': report_id, 'name': report_name}})

Trigger a CM report run

Args:
auth_read (authentication) - Credentials used for reading data.
account (integer) - CM network id.
report_id (integer) - CM report id, empty if using name.
report_name (string) - CM report name, empty if using id instead.


def AssignTasksToClient(self, client_id):

    rules = data_store.REL_DB.ReadAllForemanRules()
    if not rules:
      return 0

    last_foreman_run = self._GetLastForemanRunTime(client_id)

    latest_rule_creation_time = max(rule.creation_time for rule in rules)

    if latest_rule_creation_time <= last_foreman_run:
      return 0

    self._SetLastForemanRunTime(client_id, latest_rule_creation_time)

    relevant_rules = []
    expired_rules = False

    now = rdfvalue.RDFDatetime.Now()

    for rule in rules:
      if rule.expiration_time < now:
        expired_rules = True
        continue
      if rule.creation_time <= last_foreman_run:
        continue

      relevant_rules.append(rule)

    actions_count = 0
    if relevant_rules:
      client_data = data_store.REL_DB.ReadClientFullInfo(client_id)
      if client_data is None:
        return

      for rule in relevant_rules:
        if rule.Evaluate(client_data):
          actions_count += self._RunAction(rule, client_id)

    if expired_rules:
      data_store.REL_DB.RemoveExpiredForemanRules()

    return actions_count

Examines our rules and starts up flows based on the client.

Args:
client_id: Client id of the client for tasks to be assigned.

Returns:
Number of assigned tasks.