def _CheckFileEntryType(self, file_entry):
    if (not self._file_entry_types):
        return None
    return (self._CheckIsDevice(file_entry) or self._CheckIsDirectory(file_entry) or self._CheckIsFile(file_entry) or self._CheckIsLink(file_entry) or self._CheckIsPipe(file_entry) or self._CheckIsSocket(file_entry))

Checks the file entry type find specifications.

Args:
file_entry (FileEntry): file entry.

Returns:
bool: True if the file entry matches the find specification, False if
not or None if no file entry type specification is defined.


def apply_operation(self, symmop, fractional=False):

        if not fractional:
            self._lattice = Lattice([symmop.apply_rotation_only(row)
                                     for row in self._lattice.matrix])

            def operate_site(site):
                new_cart = symmop.operate(site.coords)
                new_frac = self._lattice.get_fractional_coords(new_cart)
                return PeriodicSite(site.species, new_frac,
                                    self._lattice,
                                    properties=site.properties)

        else:
            new_latt = np.dot(symmop.rotation_matrix, self._lattice.matrix)
            self._lattice = Lattice(new_latt)

            def operate_site(site):
                return PeriodicSite(site.species,
                                    symmop.operate(site.frac_coords),
                                    self._lattice,
                                    properties=site.properties)

        self._sites = [operate_site(s) for s in self._sites]

Apply a symmetry operation to the structure and return the new
structure. The lattice is operated by the rotation matrix only.
Coords are operated in full and then transformed to the new lattice.

Args:
symmop (SymmOp): Symmetry operation to apply.
fractional (bool): Whether the symmetry operation is applied in
fractional space. Defaults to False, i.e., symmetry operation
is applied in cartesian coordinates.


def peek_all(self, model_class):
    if self._cache:
        return self._cache.get_records(model_class.__name__)
    else:
        return []

Return a list of models from the local cache.

Args:
model_class (:class:`cinder_data.model.CinderModel`): A subclass of
:class:`cinder_data.model.CinderModel` of your chosen model.

Returns:
list: A list of instances of you model_class or and empty list.


def get_interpolated_value(self, energy):
    f = {}
    for spin in self.densities.keys():
        f[spin] = get_linear_interpolated_value(self.energies, self.densities[spin], energy)
    return f

Returns interpolated density for a particular energy.

Args:
energy: Energy to return the density for.


async def vsetup(self, author):

        if self.vready:
            logger.warning("Attempt to init voice when already initialised")
            return

        if self.state != 'starting':
            logger.error("Attempt to init from wrong state ('{}'), must be 'starting'.".format(self.state))
            return

        self.logger.debug("Setting up voice")

        self.vchannel = author.voice.voice_channel
        if self.vchannel:
            self.statuslog.info("Connecting to voice")
            try:
                self.vclient = await client.join_voice_channel(self.vchannel)
            except discord.ClientException as e:
                logger.exception(e)
                self.statuslog.warning("I'm already connected to a voice channel.")
                return
            except discord.opus.OpusNotLoaded as e:
                logger.exception(e)
                logger.error("Could not load Opus. This is an error with your FFmpeg setup.")
                self.statuslog.error("Could not load Opus.")
                return
            except discord.DiscordException as e:
                logger.exception(e)
                self.statuslog.error("I couldn't connect to the voice channel. Check my permissions.")
                return
            except Exception as e:
                self.statuslog.error("Internal error connecting to voice, disconnecting.")
                logger.error("Error connecting to voice {}".format(e))
                return
        else:
            self.statuslog.error("You're not connected to a voice channel.")
            return

        self.vready = True

Creates the voice client

Args:
author (discord.Member): The user that the voice ui will seek


def get_variant_by_name(self, name):

        results = []

        try:
            for info, dosage in self._bgen.get_variant(name):
                results.append(Genotypes(
                    Variant(
                        info.name,
                        CHROM_STR_ENCODE.get(info.chrom, info.chrom),
                        info.pos,
                        [info.a1, info.a2],
                    ),
                    dosage,
                    reference=info.a1,
                    coded=info.a2,
                    multiallelic=False,
                ))

        except ValueError:
            logging.variant_name_not_found(name)

        return results

Get the genotype of a marker using it's name.

Args:
name (str): The name of the marker.

Returns:
list: A list of Genotypes.


def __ComputeEndByte(self, start, end=None, use_chunks=True):
    end_byte = end
    if ((start < 0) and (not self.total_size)):
        return end_byte
    if use_chunks:
        alternate = ((start + self.chunksize) - 1)
        if (end_byte is not None):
            end_byte = min(end_byte, alternate)
        else:
            end_byte = alternate
    if self.total_size:
        alternate = (self.total_size - 1)
        if (end_byte is not None):
            end_byte = min(end_byte, alternate)
        else:
            end_byte = alternate
    return end_byte

Compute the last byte to fetch for this request.

This is all based on the HTTP spec for Range and
Content-Range.

Note that this is potentially confusing in several ways:
* the value for the last byte is 0-based, eg "fetch 10 bytes
from the beginning" would return 9 here.
* if we have no information about size, and don't want to
use the chunksize, we'll return None.
See the tests for more examples.

Args:
start: byte to start at.
end: (int or None, default: None) Suggested last byte.
use_chunks: (bool, default: True) If False, ignore self.chunksize.

Returns:
Last byte to use in a Range header, or None.


def is_insert_grad_of_statement(node):

  tangent_calls = [anno.getanno(item.context_expr, 'func', None)
                   is utils.insert_grad_of for item in node.items]
  if all(tangent_calls):
    return True
  elif any(tangent_calls):
    raise ValueError
  else:
    return False

Check whether a context manager calls `insert_grad_of`.

Args:
node: The context manager node.

Returns:
Whether or not this node contains `insert_grad_of` calls.

Raises:
ValueError: If the `insert_grad_of` calls are mixed with other calls.


def add_to_cache(cls, remote_info, container):
    if (not isinstance(container, cls)):
        raise TypeError(('%r not an instance of %r, could not be added to cache.' % (container, cls)))
    if (remote_info in cls.__remote_info_cache):
        raise KeyError('Cache has collision but should not.')
    cls.__remote_info_cache[remote_info] = container

Adds a ResourceContainer to a cache tying it to a protorpc method.

Args:
remote_info: Instance of protorpc.remote._RemoteMethodInfo corresponding
to a method.
container: An instance of ResourceContainer.

Raises:
TypeError: if the container is not an instance of cls.
KeyError: if the remote method has been reference by a container before.
This created remote method should never occur because a remote method
is created once.


def AddIndex(self, path_segment_index):
    if (path_segment_index in self._weight_per_index):
        raise ValueError('Path segment index already set.')
    self._weight_per_index[path_segment_index] = 0

Adds a path segment index and sets its weight to 0.

Args:
path_segment_index: an integer containing the path segment index.

Raises:
ValueError: if the path segment weights already contains
the path segment index.


def _update_unenrolled_list(sailthru_client, email, course_url, unenroll):

    try:

        sailthru_response = sailthru_client.api_get("user", {"id": email, "fields": {"vars": 1}})
        if not sailthru_response.is_ok():
            error = sailthru_response.get_error()
            logger.error("Error attempting to read user record from Sailthru: %s", error.get_message())
            return not can_retry_sailthru_request(error)

        response_json = sailthru_response.json

        unenroll_list = []
        if response_json and "vars" in response_json and response_json["vars"] \
           and "unenrolled" in response_json["vars"]:
            unenroll_list = response_json["vars"]["unenrolled"]

        changed = False

        if unenroll:
            if course_url not in unenroll_list:
                unenroll_list.append(course_url)
                changed = True

        elif course_url in unenroll_list:
            unenroll_list.remove(course_url)
            changed = True

        if changed:

            sailthru_response = sailthru_client.api_post(
                'user', {'id': email, 'key': 'email', 'vars': {'unenrolled': unenroll_list}})

            if not sailthru_response.is_ok():
                error = sailthru_response.get_error()
                logger.error("Error attempting to update user record in Sailthru: %s", error.get_message())
                return not can_retry_sailthru_request(error)

        return True

    except SailthruClientError as exc:
        logger.exception("Exception attempting to update user record for %s in Sailthru - %s", email, text_type(exc))
        return False

Maintain a list of courses the user has unenrolled from in the Sailthru user record

Arguments:
sailthru_client (object): SailthruClient
email (str): user's email address
course_url (str): LMS url for course info page.
unenroll (boolean): True if unenrolling, False if enrolling

Returns:
False if retryable error, else True


def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    local_stream = BytearrayStream()
    if self._wrapping_method:
        self._wrapping_method.write(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('Invalid struct missing the wrapping method attribute.')
    if self._encryption_key_information:
        self._encryption_key_information.write(local_stream, kmip_version=kmip_version)
    if self._mac_signature_key_information:
        self._mac_signature_key_information.write(local_stream, kmip_version=kmip_version)
    if self._attribute_names:
        for unique_identifier in self._attribute_names:
            unique_identifier.write(local_stream, kmip_version=kmip_version)
    if self._encoding_option:
        self._encoding_option.write(local_stream, kmip_version=kmip_version)
    self.length = local_stream.length()
    super(KeyWrappingSpecification, self).write(output_stream, kmip_version=kmip_version)
    output_stream.write(local_stream.buffer)

Write the data encoding the KeyWrappingSpecification struct to a
stream.

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


def is_diagonal(matrix: np.ndarray, *, atol: float=1e-08) -> bool:
    matrix = np.copy(matrix)
    for i in range(min(matrix.shape)):
        matrix[(i, i)] = 0
    return tolerance.all_near_zero(matrix, atol=atol)

Determines if a matrix is a approximately diagonal.

A matrix is diagonal if i!=j implies m[i,j]==0.

Args:
matrix: The matrix to check.
atol: The per-matrix-entry absolute tolerance on equality.

Returns:
Whether the matrix is diagonal within the given tolerance.


def validate(self):
    for schema in (self.headers_schema, Message.headers_schema):
        _log.debug('Validating message headers "%r" with schema "%r"', self._headers, schema)
        jsonschema.validate(self._headers, schema)
    for schema in (self.body_schema, Message.body_schema):
        _log.debug('Validating message body "%r" with schema "%r"', self.body, schema)
        jsonschema.validate(self.body, schema)

Validate the headers and body with the message schema, if any.

In addition to the user-provided schema, all messages are checked against
the base schema which requires certain message headers and the that body
be a JSON object.

.. warning:: This method should not be overridden by sub-classes.

Raises:
jsonschema.ValidationError: If either the message headers or the message body
are invalid.
jsonschema.SchemaError: If either the message header schema or the message body
schema are invalid.


def fetch(self, payment_id, data={}, **kwargs):

        return super(Payment, self).fetch(payment_id, data, **kwargs)

Fetch Payment for given Id

Args:
payment_id : Id for which payment object has to be retrieved

Returns:
Payment dict for given payment Id


def switch_window(self, window_id: int):

    if window_id not in self.tmux_available_window_ids:
      for i in range(max(self.tmux_available_window_ids)+1, window_id+1):
        self._run_raw(f'tmux new-window -t {self.tmux_session} -d')

        tmux_window = self.tmux_session + ':' + str(i)
        cmd = shlex.quote(f'cd {self.taskdir}')
        tmux_cmd = f'tmux send-keys -t {tmux_window} {cmd} Enter'
        self._run_raw(tmux_cmd)
        self.tmux_available_window_ids.append(i)

    self.tmux_window_id = window_id

Switches currently active tmux window for given task. 0 is the default window
Args:
window_id: integer id of tmux window to use


def on_channel_open(self, channel):

        self.in_channel.exchange_declare(exchange='input_exc', type='topic', durable=True)
        channel.queue_declare(callback=self.on_input_queue_declare, queue=self.INPUT_QUEUE_NAME)

Input channel creation callback
Queue declaration done here

Args:
channel: input channel


class SquaredHinge(reduction_metrics.MeanMetricWrapper):

    def __init__(self, name='squared_hinge', dtype=None):
        super().__init__(fn=squared_hinge, name=name, dtype=dtype)
        self._direction = 'down'

    def get_config(self):
        return {'name': self.name, 'dtype': self.dtype}

Computes the hinge metric between `y_true` and `y_pred`.

`y_true` values are expected to be -1 or 1. If binary (0 or 1) labels are
provided we will convert them to -1 or 1.

Args:
name: (Optional) string name of the metric instance.
dtype: (Optional) data type of the metric result.

Example:

>>> m = keras.metrics.SquaredHinge()
>>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]])
>>> m.result()
1.86
>>> m.reset_state()
>>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]],
...                sample_weight=[1, 0])
>>> m.result()
1.46


def supports_suggested_actions(channel_id: str, button_cnt: int=100) -> bool:
    max_actions = {Channels.facebook: 10, Channels.skype: 10, Channels.line: 13, Channels.kik: 20, Channels.telegram: 100, Channels.slack: 100, Channels.emulator: 100, Channels.direct_line: 100, Channels.webchat: 100}
    return ((button_cnt <= max_actions[channel_id]) if (channel_id in max_actions) else False)

Determine if a number of Suggested Actions are supported by a Channel.

Args:
channel_id (str): The Channel to check the if Suggested Actions are supported in.
button_cnt (int, optional): Defaults to 100. The number of Suggested Actions to check for the Channel.

Returns:
bool: True if the Channel supports the button_cnt total Suggested Actions, False if the Channel does not support that number of Suggested Actions.


def _add_length_constrain(token_lst: List[Dict], lengths: List) -> List[Dict]:

        result = []
        for a_token in token_lst:
            for length in lengths:
                if type(length) == str and length and length.isdigit():
                    a_token[attrs.LENGTH] = int(length)
                    result.append(copy.deepcopy(a_token))
                elif type(length) == int:
                    a_token[attrs.LENGTH] = int(length)
                    result.append(copy.deepcopy(a_token))
        return result

Add length constrain for some token type, create cross production
Args:
token_lst: List[Dict]
lengths: List

Returns: List[Dict]


def memory_write16(self, addr, data, zone=None):
    return self.memory_write(addr, data, zone, 16)

Writes half-words to memory of a target system.

Args:
self (JLink): the ``JLink`` instance
addr (int): start address to write to
data (list): list of half-words to write
zone (str): optional memory zone to access

Returns:
Number of half-words written to target.

Raises:
JLinkException: on memory access error.


def create(self, path, mime_type='application/octet-stream', compression_type=CompressionTypes.AUTO) -> BinaryIO:
    dirname = os.path.dirname(path)
    if dirname:
        os.makedirs(os.path.dirname(path), exist_ok=True)
    return self._path_open(path, 'wb', mime_type, compression_type)

Returns a write channel for the given file path.

Args:
path: string path of the file object to be written to the system
mime_type: MIME type to specify the type of content in the file object
compression_type: Type of compression to be used for this object

Returns: file handle with a close function for the user to use


def __init__(self, component1=None, component2=None):

        if component1 is None and component2 is not None:
            component1 = component2
            component2 = None

        self._llhead = None
        self._lltail = None

        if isinstance(component1, CompositeBitarray):
            self._llhead = component1._llhead
            self._lltail = component1._lltail
            self._offset = component1._offset
            self._tailbitsused = component1._tailbitsused
            self._length = len(component1)
        else:
            self._llhead = self._lltail = _DLLNode(component1)
            self._offset = 0
            self._tailbitsused = len(component1)
            self._length = self._tailbitsused

        if component2 is not None:
            oldtail = self._lltail
            if isinstance(component2, CompositeBitarray):
                if self._lltail is component2._llhead:
                    if self._tail_end != component2._offset:
                        raise ProteusDataJoinError()

                    if component2._is_single_llnode:
                        self._tailbitsused += component2._tailbitsused
                    else:
                        self._tailbitsused = component2._tailbitsused
                    self._lltail = component2._lltail
                    self._length += len(component2)
                elif self._lltail.next is component2._llhead and\
                         self._tailoffset == 0 and\
                         component2._offset == 0:
                    self._lltail = component2._lltail
                    self._tailbitsused = component2._tailbitsused
                    self._length += len(component2)
                elif component2._llhead.prev is not None or\
                     self._lltail.next is not None or\
                     component2._offset or self._tailoffset or\
                     self._llhead is component2._lltail:

                    raise ProteusDataJoinError()
                else:
                    self._length += len(component2)
                    self._lltail.next = component2._llhead
                    self._lltail = component2._lltail
                    self._tailbitsused = component2._tailbitsused
            else:
                if self._tailoffset or self._lltail.next is not None:
                    raise ProteusDataJoinError()
                self._tailbitsused = len(component2)
                self._length += self._tailbitsused
                node = _DLLNode(component2)
                node.prev = self._lltail
                self._lltail = node

            if oldtail is not self._llhead or self._offset == 0:
                self._do_merge(oldtail)

Create a bitarray object that stores its components by reference).

Args:
*components: Any number of bitarray instances to store in this composition.


def NewEvent(type: str, id: UUID=None, data: JsonDict=None, metadata: JsonDict=None) -> NewEventData:
    return NewEventData((id or uuid4()), type, data, metadata)

Build the data structure for a new event.

Args:
type: An event type.
id: The uuid identifier for the event.
data: A dict containing data for the event. These data
must be json serializable.
metadata: A dict containing metadata about the event.
These must be json serializable.


def crt(self, mp, mq):

        u = (mq - mp) * self.p_inverse % self.q
        return mp + (u * self.p)

The Chinese Remainder Theorem as needed for decryption. Returns the solution modulo n=pq.

Args:
mp(int): the solution modulo p.
mq(int): the solution modulo q.


def save(self, representative_dataset: RepresentativeDatasetMapping) -> Mapping[str, _RepresentativeDatasetFile]:
    raise NotImplementedError('Method "save" is not implemented.')

Saves the representative dataset.

Args:
representative_dataset: RepresentativeDatasetMapping which is a
signature_def_key -> representative dataset mapping.


def handle_subscribed_event(self, event_obj, event_name):

        handler, args = self.handlers[event_name]
        self.executor.submit(handler, event_obj, *args)

Execute the registered handler of an event.

Retrieve the handler and its arguments, and execute the handler in a
new thread.

Args:
event_obj: Json object of the event.
event_name: Name of the event to call handler for.


def group_associations_types(self, group_type, api_entity=None, api_branch=None, params=None):

        if params is None:
            params = {}
        if not self.can_update():
            self._tcex.handle_error(910, [self.type])

        target = self._tcex.ti.group(group_type)

        for gat in self.tc_requests.group_associations_types(
            self.api_type,
            self.api_sub_type,
            self.unique_id,
            target,
            api_entity=api_entity,
            api_branch=api_branch,
            owner=self.owner,
            params=params,
        ):
            yield gat

Gets the group association from a Indicator/Group/Victim

Args:
group_type:
api_entity:
api_branch:
params:

Returns:


def _list_profile_sort_key(profile_datum, sort_by):
    if sort_by == SORT_OPS_BY_OP_NAME:
        return profile_datum.node_exec_stats.node_name
    elif sort_by == SORT_OPS_BY_OP_TYPE:
        return profile_datum.op_type
    elif sort_by == SORT_OPS_BY_LINE:
        return profile_datum.file_line_func
    elif sort_by == SORT_OPS_BY_OP_TIME:
        return profile_datum.op_time
    elif sort_by == SORT_OPS_BY_EXEC_TIME:
        return profile_datum.node_exec_stats.all_end_rel_micros
    else:
        return profile_datum.node_exec_stats.all_start_micros

Get a profile_datum property to sort by in list_profile command.

Args:
profile_datum: A `ProfileDatum` object.
sort_by: (string) indicates a value to sort by.
Must be one of SORT_BY* constants.

Returns:
profile_datum property to sort by.


def _process_counter_example(self, mma, w_string):

        w_string = self._find_bad_transition(mma, w_string)

        diff = len(w_string)
        same = 0
        while True:
            i = (same + diff) / 2
            access_string = self._run_in_hypothesis(mma, w_string, i)
            is_diff = self._check_suffix(w_string, access_string, i)
            if is_diff:
                diff = i
            else:
                same = i
            if diff - same == 1:
                break
        exp = w_string[diff:]

        self.observation_table.em_vector.append(exp)
        for row in self.observation_table.sm_vector + self.observation_table.smi_vector:
            self._fill_table_entry(row, exp)

Process a counterexample in the Rivest-Schapire way.
Args:
mma (DFA): The hypothesis automaton
w_string (str): The examined string to be consumed
Returns:
None


def raw_sql(cls, cur, query: str, values: tuple):
    (yield from cur.execute(query, values))
    return (yield from cur.fetchall())

Run a raw sql query

Args:
query : query string to execute
values : tuple of values to be used with the query

Returns:
result of query as list of named tuple


def pack_sequence_as(structure, flat_sequence):
    flat_sequence = list(flat_sequence)
    flattened_structure = nest.flatten(structure, expand_composites=True)
    if len(flattened_structure) != len(flat_sequence):
        raise ValueError('Mismatch in element count')
    for i in range(len(flat_sequence)):
        if isinstance(flattened_structure[i], tensor_array_ops.TensorArray):
            flat_sequence[i] = tensor_array_ops.build_ta_with_new_flow(old_ta=flattened_structure[i], flow=flat_sequence[i])
    return nest.pack_sequence_as(structure, flat_sequence, expand_composites=True)

Like `nest.pack_sequence_as` but also builds TensorArrays from flows.

Args:
structure: The structure to pack into. May contain Tensors,
CompositeTensors, or TensorArrays.
flat_sequence: An iterable containing tensors.

Returns:
A nested structure.

Raises:
AssertionError if `structure` and `flat_sequence` are not compatible.


def _process_example_section(func_documentation, func, parent_class, class_name, model_name_lowercase, config_class, checkpoint, indent_level):
    from transformers.models import auto as auto_module
    example_docstring = ''
    if func_documentation is not None and (match := re.search('(?m)^([ \\t]*)(?=Example)', func_documentation)):
        example_docstring = func_documentation[match.start():]
        example_docstring = '\n' + set_min_indent(example_docstring, indent_level + 4)
    elif parent_class is None and model_name_lowercase is not None:
        task = f'({'|'.join(PT_SAMPLE_DOCSTRINGS.keys())})'
        model_task = re.search(task, class_name)
        CONFIG_MAPPING = auto_module.configuration_auto.CONFIG_MAPPING
        if (checkpoint_example := checkpoint) is None:
            try:
                checkpoint_example = get_checkpoint_from_config_class(CONFIG_MAPPING[model_name_lowercase])
            except KeyError:
                if model_name_lowercase in HARDCODED_CONFIG_FOR_MODELS:
                    CONFIG_MAPPING_NAMES = auto_module.configuration_auto.CONFIG_MAPPING_NAMES
                    config_class_name = HARDCODED_CONFIG_FOR_MODELS[model_name_lowercase]
                    if config_class_name in CONFIG_MAPPING_NAMES.values():
                        model_name_for_auto_config = [k for k, v in CONFIG_MAPPING_NAMES.items() if v == config_class_name][0]
                        if model_name_for_auto_config in CONFIG_MAPPING:
                            checkpoint_example = get_checkpoint_from_config_class(CONFIG_MAPPING[model_name_for_auto_config])
        if model_task is not None:
            if checkpoint_example is not None:
                example_annotation = ''
                task = model_task.group()
                example_annotation = PT_SAMPLE_DOCSTRINGS[task].format(model_class=class_name, checkpoint=checkpoint_example, expected_output='...', expected_loss='...', qa_target_start_index=14, qa_target_end_index=15, mask='<mask>')
                example_docstring = set_min_indent(example_annotation, indent_level + 4)
            else:
                print(f"🚨 No checkpoint found for {class_name}.{func.__name__}. Please add a `checkpoint` arg to `auto_docstring` or add one in {config_class}'s docstring")
        else:
            for name_model_list_for_task in MODELS_TO_PIPELINE:
                model_list_for_task = getattr(auto_module.modeling_auto, name_model_list_for_task)
                if class_name in model_list_for_task.values():
                    pipeline_name = MODELS_TO_PIPELINE[name_model_list_for_task]
                    example_annotation = PIPELINE_TASKS_TO_SAMPLE_DOCSTRINGS[pipeline_name].format(model_class=class_name, checkpoint=checkpoint_example, expected_output='...', expected_loss='...', qa_target_start_index=14, qa_target_end_index=15)
                    example_docstring = set_min_indent(example_annotation, indent_level + 4)
                    break
    return example_docstring

Process the example section of the docstring.

Args:
func_documentation (`str`): Existing function documentation (manually specified in the docstring)
func (`function`): Function being processed
parent_class (`class`): Parent class of the function
class_name (`str`): Name of the class
model_name_lowercase (`str`): Lowercase model name
config_class (`str`): Config class for the model
checkpoint: Checkpoint to use in examples
indent_level (`int`): Indentation level


def gff3_verifier(entries, line=None):

    regex = r'^[a-zA-Z0-9.:^*$@!+_?-|]+\t.+\t.+\t\d+\t\d+\t' \
            + r'\d*\.?\d*\t[+-.]\t[.0-2]\t.+{0}$'.format(os.linesep)
    delimiter = r'\t'

    for entry in entries:
        try:
            entry_verifier([entry.write()], regex, delimiter)
        except FormatError as error:

            if line:
                intro = 'Line {0}'.format(str(line))
            elif error.part == 0:
                intro = 'Entry with source {0}'.format(entry.source)
            else:
                intro = 'Entry with Sequence ID {0}'.format(entry.seqid)

            if error.part == 0:
                msg = '{0} has no Sequence ID'.format(intro)
            elif error.part == 1:
                msg = '{0} has no source'.format(intro)
            elif error.part == 2:
                msg = '{0} has non-numerical characters in type'.format(intro)
            elif error.part == 3:
                msg = '{0} has non-numerical characters in ' \
                      'start position'.format(intro)
            elif error.part == 4:
                msg = '{0} has non-numerical characters in ' \
                      'end position'.format(intro)
            elif error.part == 5:
                msg = '{0} has non-numerical characters in score'.format(intro)
            elif error.part == 6:
                msg = '{0} strand not in [+-.]'.format(intro)
            elif error.part == 7:
                msg = '{0} phase not in [.0-2]'.format(intro)
            elif error.part == 8:
                msg = '{0} has no attributes'.format(intro)
            else:
                msg = 'Unknown Error: Likely a Bug'
            raise FormatError(message=msg)

        if line:
            line += 1

Raises error if invalid GFF3 format detected

Args:
entries (list): A list of GFF3Entry instances

line (int): Line number of first entry

Raises:
FormatError: Error when GFF3 format incorrect with descriptive message


def parse_object_like_triples(self):
    self.rdf.triples = SimpleNamespace()
    for (s, p, o) in self.rdf.graph:
        (ns_prefix, ns_uri, predicate) = self.rdf.graph.compute_qname(p)
        if (not hasattr(self.rdf.triples, ns_prefix)):
            setattr(self.rdf.triples, ns_prefix, SimpleNamespace())
        if (not hasattr(getattr(self.rdf.triples, ns_prefix), predicate)):
            setattr(getattr(self.rdf.triples, ns_prefix), predicate, [])
        getattr(getattr(self.rdf.triples, ns_prefix), predicate).append(o)

method to parse triples from self.rdf.graph for object-like
access

Args:
None

Returns:
None: sets self.rdf.triples


def match_next_flag(tt_flags, pos):
    match = _FLAG_DOUBLE_QUOTE_PAT.match(tt_flags, pos)
    if match:
        return (match, True)
    match = _FLAG_SINGLE_QUOTE_PAT.match(tt_flags, pos)
    if match:
        return (match, True)
    match = _FLAG_NO_QUOTE_PAT.match(tt_flags, pos)
    if match:
        return (match, True)
    match = _FLAG_NO_EQUAL_PAT.match(tt_flags, pos)
    if match:
        return (match, False)
    return (None, False)

Returns the match for the next TensorTracer flag.

Args:
tt_flags: a string that contains the flags.
pos: where in flags to start the search.

Returns:
A pair where the first element is the regular-expression
match found and the second element indicates if the match
has a value.


def _AnsiCmd(command_list):

  if not isinstance(command_list, list):
    raise ValueError('Invalid list: %s' % command_list)

  for sgr in command_list:
    if sgr.lower() not in SGR:
      raise ValueError('Invalid or unsupported SGR name: %s' % sgr)

  command_str = [str(SGR[x.lower()]) for x in command_list]

  return '\033[%sm' % (';'.join(command_str))

Takes a list of SGR values and formats them as an ANSI escape sequence.

Args:
command_list: List of strings, each string represents an SGR value.
e.g. 'fg_blue', 'bg_yellow'

Returns:
The ANSI escape sequence.

Raises:
ValueError: if a member of command_list does not map to a valid SGR value.


def charges(self, num, charge_id=None, **kwargs):
    baseuri = (self._BASE_URI + 'company/{}/charges'.format(num))
    if (charge_id is not None):
        baseuri += '/{}'.format(charge_id)
        res = self.session.get(baseuri, params=kwargs)
    else:
        res = self.session.get(baseuri, params=kwargs)
    self.handle_http_error(res)
    return res

Search for charges against a company by company number.

Args:
num (str): Company number to search on.
transaction (Optional[str]): Filing record number.
kwargs (dict): additional keywords passed into
requests.session.get params keyword.


def write(self, destination, filename, content):
    if (not os.path.exists(destination)):
        try:
            os.makedirs(destination)
        except:
            pass
    filepath = ('%s/%s' % (destination, filename))
    f = open(filepath, 'w+')
    f.write(content)
    f.close()

Write a file at the specific destination with the content.

Args:
destination (string): the destination location
filename (string): the filename that will be written
content (string): the content of the filename


def get_key_flags_for_module(self, module):

    if not isinstance(module, str):
      module = module.__name__

    key_flags = self._get_flags_defined_by_module(module)

    for flag in self.key_flags_by_module_dict().get(module, []):
      if flag not in key_flags:
        key_flags.append(flag)
    return key_flags

Returns the list of key flags for a module.

Args:
module: module|str, the module to get key flags from.

Returns:
[Flag], a new list of Flag instances.  Caller may update this list as
desired: none of those changes will affect the internals of this
FlagValue instance.


def contains(self, sub):

        sub = sub.lower()
        found_words = set()

        res = cgaddag.gdg_contains(self.gdg, sub.encode(encoding="ascii"))
        tmp = res

        while tmp:
            word = tmp.contents.str.decode("ascii")
            found_words.add(word)
            tmp = tmp.contents.next

        cgaddag.gdg_destroy_result(res)
        return list(found_words)

Find all words containing a substring.

Args:
sub: A substring to be searched for.

Returns:
A list of all words found.


def get(self, txn_id):
    if (txn_id not in self._receipt_db):
        raise KeyError('Unknown transaction id {}'.format(txn_id))
    txn_receipt_bytes = self._receipt_db[txn_id]
    txn_receipt = TransactionReceipt()
    txn_receipt.ParseFromString(txn_receipt_bytes)
    return txn_receipt

Returns the TransactionReceipt

Args:
txn_id (str): the id of the transaction for which the receipt
should be retrieved.

Returns:
TransactionReceipt: The receipt for the given transaction id.

Raises:
KeyError: if the transaction id is unknown.


def mt_excel_files(store, case_obj, temp_excel_dir):
    today = datetime.datetime.now().strftime('%Y-%m-%d')
    samples = case_obj.get('individuals')
    query = {'chrom': 'MT'}
    mt_variants = list(store.variants(case_id=case_obj['_id'], query=query, nr_of_variants=(- 1), sort_key='position'))
    written_files = 0
    for sample in samples:
        sample_id = sample['individual_id']
        sample_lines = export_mt_variants(variants=mt_variants, sample_id=sample_id)
        document_name = ('.'.join([case_obj['display_name'], sample_id, today]) + '.xlsx')
        workbook = Workbook(os.path.join(temp_excel_dir, document_name))
        Report_Sheet = workbook.add_worksheet()
        row = 0
        for (col, field) in enumerate(MT_EXPORT_HEADER):
            Report_Sheet.write(row, col, field)
        for (row, line) in enumerate(sample_lines, 1):
            for (col, field) in enumerate(line):
                Report_Sheet.write(row, col, field)
        workbook.close()
        if os.path.exists(os.path.join(temp_excel_dir, document_name)):
            written_files += 1
    return written_files

Collect MT variants and format line of a MT variant report
to be exported in excel format

Args:
store(adapter.MongoAdapter)
case_obj(models.Case)
temp_excel_dir(os.Path): folder where the temp excel files are written to

Returns:
written_files(int): the number of files written to temp_excel_dir


def DisableInterfaces(interface):
    set_tested_versions = ['vista', '2008']
    set_args = ['/c', 'netsh', 'set', 'interface', interface, 'DISABLED']
    host_version = platform.platform().lower()
    for version in set_tested_versions:
        if (host_version.find(version) != (- 1)):
            res = client_utils_common.Execute('cmd', set_args, time_limit=(- 1), bypass_whitelist=True)
            return res
    return ('', 'Command not available for this version.', 99, '')

Tries to disable an interface.  Only works on Vista and 7.

Args:
interface: Name of the interface to disable.

Returns:
res which is a tuple of (stdout, stderr, exit_status, time_taken).


def get_resize_output_image_size(input_image: np.ndarray, size: Union[int, Tuple[int, int], List[int]], max_size: Optional[int]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> Tuple[int, int]:
    image_size = get_image_size(input_image, input_data_format)
    if isinstance(size, (list, tuple)):
        return size
    return get_size_with_aspect_ratio(image_size, size, max_size)

Computes the output image size given the input image size and the desired output size. If the desired output size
is a tuple or list, the output image size is returned as is. If the desired output size is an integer, the output
image size is computed by keeping the aspect ratio of the input image size.

Args:
input_image (`np.ndarray`):
The image to resize.
size (`int` or `Tuple[int, int]` or `List[int]`):
The desired output size.
max_size (`int`, *optional*):
The maximum allowed output size.
input_data_format (`ChannelDimension` or `str`, *optional*):
The channel dimension format of the input image. If not provided, it will be inferred from the input image.


def apply_operation(self, symmop):

        def operate_site(site):
            new_cart = symmop.operate(site.coords)
            return Site(site.species, new_cart,
                        properties=site.properties)

        self._sites = [operate_site(s) for s in self._sites]

Apply a symmetry operation to the molecule.

Args:
symmop (SymmOp): Symmetry operation to apply.


def chdir(self, target_directory):

        target_directory = self.filesystem.resolve_path(
            target_directory, allow_fd=True)
        self.filesystem.confirmdir(target_directory)
        directory = self.filesystem.resolve(target_directory)

        if not is_root() and not directory.st_mode | PERM_EXE:
            self.filesystem.raise_os_error(errno.EACCES, directory)
        self.filesystem.cwd = target_directory

Change current working directory to target directory.

Args:
target_directory: The path to new current working directory.

Raises:
OSError: if user lacks permission to enter the argument directory
or if the target is not a directory.


def _resolve_non_literal_route(self, method, path):

        for route_dict in (self._wildcard, self._regex):
            if method in route_dict:
                for route in reversed(route_dict[method]):
                    callback_data = route.match(path)
                    if callback_data is not None:
                        return callback_data
        return None

Resolve a request to a wildcard or regex route handler.

Arguments:
method (str): HTTP method name, e.g. GET, POST, etc.
path (str): Request path

Returns:
tuple or None: A tuple of three items:

1. Route handler (callable)
2. Positional arguments (list)
3. Keyword arguments (dict)

``None`` if no route matches the request.


def message(self, tree, spins, subtheta, auxvars):

        energy_sources = set()
        for v, children in tree.items():
            aux = auxvars[v]

            assert all(u in spins for u in self._ancestors[v])

            def energy_contributions():
                yield subtheta.linear[v]

                for u, bias in subtheta.adj[v].items():
                    if u in spins:
                        yield SpinTimes(spins[u], bias)

            plus_energy = Plus(energy_contributions())
            minus_energy = SpinTimes(-1, plus_energy)

            if children:

                spins[v] = 1
                plus_energy = Plus(plus_energy, self.message(children, spins, subtheta, auxvars))
                spins[v] = -1
                minus_energy = Plus(minus_energy, self.message(children, spins, subtheta, auxvars))
                del spins[v]

            m = FreshSymbol(REAL)

            ancestor_aux = {auxvars[u] if spins[u] > 0 else Not(auxvars[u])
                            for u in self._ancestors[v]}
            plus_aux = And({aux}.union(ancestor_aux))
            minus_aux = And({Not(aux)}.union(ancestor_aux))

            self.assertions.update({LE(m, plus_energy),
                                    LE(m, minus_energy),
                                    Implies(plus_aux, GE(m, plus_energy)),
                                    Implies(minus_aux, GE(m, minus_energy))
                                    })

            energy_sources.add(m)

        return Plus(energy_sources)

Determine the energy of the elimination tree.

Args:
tree (dict): The current elimination tree
spins (dict): The current fixed spins
subtheta (dict): Theta with spins fixed.
auxvars (dict): The auxiliary variables for the given spins.

Returns:
The formula for the energy of the tree.


def create_streaming_endpoint(access_token, name, description="New Streaming Endpoint", \
scale_units="1"):

    path = '/StreamingEndpoints'
    endpoint = ''.join([ams_rest_endpoint, path])
    body = '{ \
		"Id":null, \
		"Name":"' + name + '", \
		"Description":"' + description + '", \
		"Created":"0001-01-01T00:00:00", \
		"LastModified":"0001-01-01T00:00:00", \
		"State":null, \
		"HostName":null, \
		"ScaleUnits":"' + scale_units + '", \
		"CrossSiteAccessPolicies":{ \
			"ClientAccessPolicy":"<access-policy><cross-domain-access><policy><allow-from http-request-headers=\\"*\\"><domain uri=\\"http:
			"CrossDomainPolicy":"<?xml version=\\"1.0\\"?><!DOCTYPE cross-domain-policy SYSTEM \\"http:
		} \
	}'
    return do_ams_post(endpoint, path, body, access_token)

Create Media Service Streaming Endpoint.

Args:
access_token (str): A valid Azure authentication token.
name (str): A Media Service Streaming Endpoint Name.
description (str): A Media Service Streaming Endpoint Description.
scale_units (str): A Media Service Scale Units Number.

Returns:
HTTP response. JSON body.


def as_dict(self, verbosity=0):

        species_list = []
        for spec, occu in self._species.items():
            d = spec.as_dict()
            del d["@module"]
            del d["@class"]
            d["occu"] = occu
            species_list.append(d)

        d = {"species": species_list,
             "abc": [float(c) for c in self._frac_coords],
             "lattice": self._lattice.as_dict(verbosity=verbosity),
             "@module": self.__class__.__module__,
             "@class": self.__class__.__name__}

        if verbosity > 0:
            d["xyz"] = [float(c) for c in self.coords]
            d["label"] = self.species_string

        d["properties"] = self.properties
        return d

Json-serializable dict representation of PeriodicSite.

Args:
verbosity (int): Verbosity level. Default of 0 only includes the
matrix representation. Set to 1 for more details such as
cartesian coordinates, etc.


def init_database(connection=None, dbname=None):

    connection = connection or connect()
    dbname = dbname or bigchaindb.config['database']['name']

    create_database(connection, dbname)
    create_tables(connection, dbname)

Initialize the configured backend for use with BigchainDB.

Creates a database with :attr:`dbname` with any required tables
and supporting indexes.

Args:
connection (:class:`~bigchaindb.backend.connection.Connection`): an
existing connection to use to initialize the database.
Creates one if not given.
dbname (str): the name of the database to create.
Defaults to the database name given in the BigchainDB
configuration.


def save_imgs(x, fname):
    n = x.shape[0]
    fig = figure.Figure(figsize=(n, 1), frameon=False)
    canvas = backend_agg.FigureCanvasAgg(fig)
    for i in range(n):
        ax = fig.add_subplot(1, n, (i + 1))
        ax.imshow(x[i].squeeze(), interpolation='none', cmap=cm.get_cmap('binary'))
        ax.axis('off')
    canvas.print_figure(fname, format='png')
    print(('saved %s' % fname))

Helper method to save a grid of images to a PNG file.

Args:
x: A numpy array of shape [n_images, height, width].
fname: The filename to write to (including extension).


def CreateSharedBudget(client):
    budget_service = client.GetService('BudgetService', version='v201809')
    budget = {'name': ('Shared Interplanetary Budget
    operation = {'operator': 'ADD', 'operand': budget}
    response = budget_service.mutate([operation])
    return response['value'][0]

Creates an explicit budget to be used only to create the Campaign.

Args:
client: AdWordsClient the client to run the example with.

Returns:
dict An object representing a shared budget.


def map_into_course(self, course_key):

        return self.replace(usage_key=self.usage_key.map_into_course(course_key))

Return a new :class:`UsageKey` or :class:`AssetKey` representing this usage inside the
course identified by the supplied :class:`CourseKey`. It returns the same type as
`self`

Args:
course_key (:class:`CourseKey`): The course to map this object into.

Returns:
A new :class:`CourseObjectMixin` instance.


def generate_mediation_matrix(dsm):
    cat = dsm.categories
    ent = dsm.entities
    size = dsm.size[0]
    if (not cat):
        cat = (['appmodule'] * size)
    packages = [e.split('.')[0] for e in ent]
    mediation_matrix = [[0 for _ in range(size)] for _ in range(size)]
    for i in range(0, size):
        for j in range(0, size):
            if (cat[i] == 'framework'):
                if (cat[j] == 'framework'):
                    mediation_matrix[i][j] = (- 1)
                else:
                    mediation_matrix[i][j] = 0
            elif (cat[i] == 'corelib'):
                if ((cat[j] in ('framework', 'corelib')) or ent[i].startswith((packages[j] + '.')) or (i == j)):
                    mediation_matrix[i][j] = (- 1)
                else:
                    mediation_matrix[i][j] = 0
            elif (cat[i] == 'applib'):
                if ((cat[j] in ('framework', 'corelib', 'applib')) or ent[i].startswith((packages[j] + '.')) or (i == j)):
                    mediation_matrix[i][j] = (- 1)
                else:
                    mediation_matrix[i][j] = 0
            elif (cat[i] == 'appmodule'):
                if ((cat[j] in ('framework', 'corelib', 'applib', 'broker', 'data')) or ent[i].startswith((packages[j] + '.')) or (i == j)):
                    mediation_matrix[i][j] = (- 1)
                else:
                    mediation_matrix[i][j] = 0
            elif (cat[i] == 'broker'):
                if ((cat[j] in ('appmodule', 'corelib', 'framework')) or ent[i].startswith((packages[j] + '.')) or (i == j)):
                    mediation_matrix[i][j] = (- 1)
                else:
                    mediation_matrix[i][j] = 0
            elif (cat[i] == 'data'):
                if ((cat[j] == 'framework') or (i == j)):
                    mediation_matrix[i][j] = (- 1)
                else:
                    mediation_matrix[i][j] = 0
            else:
                raise DesignStructureMatrixError(('Mediation matrix value NOT generated for %s:%s' % (i, j)))
    return mediation_matrix

Generate the mediation matrix of the given matrix.

Rules for mediation matrix generation:

Set -1 for items NOT to be considered
Set 0 for items which MUST NOT be present
Set 1 for items which MUST be present

Each module has optional dependencies to itself.

- Framework has optional dependency to all framework items (-1),
and to nothing else.
- Core libraries have dependencies to framework.
Dependencies to other core libraries are tolerated.
- Application libraries have dependencies to framework.
Dependencies to other core or application libraries are tolerated.
No dependencies to application modules.
- Application modules have dependencies to framework and libraries.
Dependencies to other application modules
should be mediated over a broker.
Dependencies to data are tolerated.
- Data have no dependencies at all
(but framework/libraries would be tolerated).

Args:
dsm (:class:`DesignStructureMatrix`): the DSM to generate
the mediation matrix for.


def coordinate_tensor(shape, axis):

  if axis < 0:
    axis = tf.size(shape) + axis

  r = tf.range(shape[axis])
  r_shape = tf.one_hot(
      axis, tf.size(shape), on_value=-1, off_value=1, dtype=tf.int32)
  return tf.zeros(shape, dtype=tf.int32) + tf.reshape(r, r_shape)

Return a tensor with given shape containing coordinate along given axis.

Args:
shape: a Tensor representing the shape of the output Tensor
axis: an integer

Returns:
A tensor with shape shape and type tf.int32, where each elements its
coordinate along the given axis.


def duplicated_initializer(tc, init, graph_seed, shape=None):
    if shape is None:
        shape = [100]
    with tc.test_session(graph=ops.Graph()):
        random_seed.set_random_seed(graph_seed)
        t1 = init(shape).eval()
        t2 = init(shape).eval()
        return np.allclose(t1, t2, rtol=1e-15, atol=1e-15)

Tests duplicated random initializer within the same graph.

This test generates two random kernels from the same initializer to the same
graph, and checks if the results are close enough. Even given the same global,
seed, two different instances of random kernels should generate different
results.

Args:
tc: An instance of TensorFlowTestCase.
init: An Initializer that generates a tensor of a given shape
graph_seed: A graph-level seed to use.
shape: Shape of the tensor to initialize or `None` to use a vector of length
100.

Returns:
True or False as determined by test.


def calc_control_outputs(self, graph):
    control_outputs = {}
    for op in graph.get_operations():
        for control_input in op.control_inputs:
            if control_input not in control_outputs:
                control_outputs[control_input] = set()
            control_outputs[control_input].add(op)
    return control_outputs

Returns the map of control_outputs for a given graph.

Args:
graph: The graph to parse.

Returns:
A map of the control outputs.


def generate_token(key, user_id, action_id='', when=None):
    digester = hmac.new(_helpers._to_bytes(key, encoding='utf-8'))
    digester.update(_helpers._to_bytes(str(user_id), encoding='utf-8'))
    digester.update(DELIMITER)
    digester.update(_helpers._to_bytes(action_id, encoding='utf-8'))
    digester.update(DELIMITER)
    when = _helpers._to_bytes(str((when or int(time.time()))), encoding='utf-8')
    digester.update(when)
    digest = digester.digest()
    token = base64.urlsafe_b64encode(((digest + DELIMITER) + when))
    return token

Generates a URL-safe token for the given user, action, time tuple.

Args:
key: secret key to use.
user_id: the user ID of the authenticated user.
action_id: a string identifier of the action they requested
authorization for.
when: the time in seconds since the epoch at which the user was
authorized for this action. If not set the current time is used.

Returns:
A string XSRF protection token.


def get_completions(self, context_word, prefix):
    if context_word not in self._comp_dict:
        return (None, None)
    comp_items = self._comp_dict[context_word]
    comp_items = sorted([item for item in comp_items if item.startswith(prefix)])
    return (comp_items, self._common_prefix(comp_items))

Get the tab completions given a context word and a prefix.

Args:
context_word: The context word.
prefix: The prefix of the incomplete word.

Returns:
(1) None if no registered context matches the context_word.
A list of str for the matching completion items. Can be an empty list
of a matching context exists, but no completion item matches the
prefix.
(2) Common prefix of all the words in the first return value. If the
first return value is None, this return value will be None, too. If
the first return value is not None, i.e., a list, this return value
will be a str, which can be an empty str if there is no common
prefix among the items of the list.


def sap_sid_nr(broker):
    insts = broker[DefaultSpecs.saphostctrl_listinstances].content
    hn = broker[DefaultSpecs.hostname].content[0].split('.')[0].strip()
    results = set()
    for ins in insts:
        ins_splits = ins.split(' - ')
        if (ins_splits[2].strip() == hn):
            results.add((ins_splits[0].split()[(- 1)].lower(), ins_splits[1].strip()))
    return list(results)

Get the SID and Instance Number

Typical output of saphostctrl_listinstances::
# /usr/sap/hostctrl/exe/saphostctrl -function ListInstances
Inst Info : SR1 - 01 - liuxc-rhel7-hana-ent - 749, patch 418, changelist 1816226

Returns:
(list): List of tuple of SID and Instance Number.


def Serialize(self, writer):

        writer.WriteUInt256(self.PrevHash)
        writer.WriteUInt16(self.PrevIndex)

Serialize object.

Args:
writer (neo.IO.BinaryWriter):


def make_block(cls, header: str='', content: str | dict[str, Any] | list[Any] | tuple[Any, ...]=(), *, braces: Union[str, tuple[str, str]]='(', equal: str='=', limit: int=20) -> str:
    if isinstance(braces, str):
        braces = _BRACE_TO_BRACES[braces]
    brace_start, brace_end = braces
    if isinstance(content, str):
        content = [content]
    if isinstance(content, dict):
        parts = [f'{k}{equal}{pretty_repr(v)}' for k, v in content.items()]
    elif isinstance(content, (list, tuple)):
        parts = [pretty_repr(v) for v in content]
    else:
        raise TypeError(f'Invalid fields {type(content)}')
    collapse = len(parts) <= 1
    if any(('\n' in p for p in parts)):
        collapse = False
    elif sum((len(p) for p in parts)) <= limit:
        collapse = True
    lines = cls()
    lines += f'{header}{brace_start}'
    with lines.indent():
        if collapse:
            lines += ', '.join(parts)
        else:
            for p in parts:
                lines += f'{p},'
    lines += f'{brace_end}'
    return lines.join(collapse=collapse)

Util function to create a code block.

Example:

```python
epy.Lines.make_block('A', {}) == 'A()'
epy.Lines.make_block('A', {'x': '1'}) == 'A(x=1)'
epy.Lines.make_block('A', {'x': '1', 'y': '2'}) == '''A(
x=1,
y=2,
)'''
```

Pattern is as:

```
{header}{braces[0]}
{k}={v},
...
{braces[1]}
```

Args:
header: Prefix before the brace
content: Dict of key to values. One line will be displayed per item if
`len(content) > 1`. Otherwise the code is collapsed
braces: Brace type (`(`, `[`, `{`), can be tuple for custom open/close.
equal: The separator (`=`, `: `)
limit: Strings smaller than this will be collapsed

Returns:
The block string


def reduce_concat(self, x):
    return self.reduce(lambda y: y, x)

Performs a concat reduction on `x` across pfor iterations.

Note that this currently may not work inside a control flow construct.
Args:
x: an unvectorized Tensor.

Returns:
A Tensor that has rank one higher than `x`. The value is the vectorized
version of `x`, i.e. stacking the value of `x` across different pfor
iterations.


def store_state(node, reaching, defined, stack):
    defs = [def_ for def_ in reaching if (not isinstance(def_[1], gast.arguments))]
    if (not len(defs)):
        return node
    (reaching, original_defs) = zip(*defs)
    assignments = []
    for id_ in (set(reaching) - defined):
        assignments.append(quoting.quote('{} = None'.format(id_)))
    store = []
    load = []
    for (id_, def_) in zip(reaching, original_defs):
        if (isinstance(def_, gast.Assign) and ('tangent.Stack()' in quoting.unquote(def_.value))):
            (push, pop, op_id) = get_push_pop_stack()
        else:
            (push, pop, op_id) = get_push_pop()
        store.append(template.replace('push(_stack, val, op_id)', push=push, val=id_, _stack=stack, op_id=op_id))
        load.append(template.replace('val = pop(_stack, op_id)', pop=pop, val=id_, _stack=stack, op_id=op_id))
    (body, return_) = (node.body[0].body[:(- 1)], node.body[0].body[(- 1)])
    node.body[0].body = (((assignments + body) + store) + [return_])
    node.body[1].body = (load[::(- 1)] + node.body[1].body)
    return node

Push the final state of the primal onto the stack for the adjoint.

Python's scoping rules make it possible for variables to not be defined in
certain blocks based on the control flow path taken at runtime. In order to
make sure we don't try to push non-existing variables onto the stack, we
defined these variables explicitly (by assigning `None` to them) at the
beginning of the function.

All the variables that reach the return statement are pushed onto the
stack, and in the adjoint they are popped off in reverse order.

Args:
node: A module with the primal and adjoint function definitions as returned
by `reverse_ad`.
reaching: The variable definitions that reach the end of the primal.
defined: The variables defined at the end of the primal.
stack: The stack node to use for storing and restoring state.

Returns:
node: A node with the requisite pushes and pops added to make sure that
state is transferred between primal and adjoint split motion calls.


def new(self, user_id, tokens=None, user_data=None, valid_until=None, client_ip=None, encoding='utf-8'):
    if (valid_until is None):
        valid_until = (int(time.time()) + TicketFactory._DEFAULT_TIMEOUT)
    else:
        valid_until = int(valid_until)
    user_id = ulp.quote(user_id)
    token_str = ''
    if tokens:
        token_str = ','.join((ulp.quote(t) for t in tokens))
    user_str = ('' if (not user_data) else ulp.quote(user_data))
    ip = (self._DEFAULT_IP if (client_ip is None) else ip_address(client_ip))
    data0 = ((bytes([ip.version]) + ip.packed) + pack('>I', valid_until))
    data1 = '\x00'.join((user_id, token_str, user_str)).encode(encoding)
    digest = self._hexdigest(data0, data1)
    parts = ('{0}{1:08x}{2}'.format(digest, valid_until, user_id), token_str, user_str)
    return '!'.join(parts)

Creates a new authentication ticket.

Args:
user_id: User id to store in ticket (stored in plain text)
tokens: Optional sequence of token strings to store in the ticket
(stored in plain text).
user_data: Optional user data to store in the ticket (string like
object stored in plain text)
valid_until: Expiration time of ticket as a integer (typically
time.time() + seconds).
client_ip: Optional string or ip_address.IPAddress of the client.
encoding: Optional encoding type that is used when hashing the
strings passed to the function

Returns:
A ticket string that can later be used to identify the user


def _truncate_float(matchobj, format_str='0.2g'):
    if matchobj.group(0):
        return format(float(matchobj.group(0)), format_str)
    return ''

Truncate long floats

Args:
matchobj (re.Match): contains original float
format_str (str): format specifier
Returns:
str: returns truncated float


def rtt_control(self, command, config):
    config_byref = (ctypes.byref(config) if (config is not None) else None)
    res = self._dll.JLINK_RTTERMINAL_Control(command, config_byref)
    if (res < 0):
        raise errors.JLinkRTTException(res)
    return res

Issues an RTT Control command.

All RTT control is done through a single API call which expects
specifically laid-out configuration structures.

Args:
self (JLink): the ``JLink`` instance
command (int): the command to issue (see enums.JLinkRTTCommand)
config (ctypes type): the configuration to pass by reference.

Returns:
An integer containing the result of the command.


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

    if not path_spec:
      raise ValueError('Missing path specification.')

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

    self._gzip_file_object = resolver.Resolver.OpenFileObject(
        path_spec.parent, resolver_context=self._resolver_context)
    file_size = self._gzip_file_object.get_size()

    self._gzip_file_object.seek(0, os.SEEK_SET)

    uncompressed_data_offset = 0
    next_member_offset = 0

    while next_member_offset < file_size:
      member = gzipfile.GzipMember(
          self._gzip_file_object, next_member_offset, uncompressed_data_offset)
      uncompressed_data_offset = (
          uncompressed_data_offset + member.uncompressed_data_size)
      self._members_by_end_offset[uncompressed_data_offset] = member
      self.uncompressed_data_size += member.uncompressed_data_size
      next_member_offset = member.member_end_offset

Opens the file-like object defined by path specification.

Args:
path_spec (Optional[PathSpec]): path specification.
mode (Optional[str]): file access mode.

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


def get_overlaps(self, offset, length):
    if (''.join([chunk.word for chunk in self])[offset] == ' '):
        offset += 1
    index = 0
    result = ChunkList()
    for chunk in self:
        if ((offset < (index + len(chunk.word))) and (index < (offset + length))):
            result.append(chunk)
        index += len(chunk.word)
    return result

Returns chunks overlapped with the given range.

Args:
offset (int): Begin offset of the range.
length (int): Length of the range.

Returns:
Overlapped chunks. (:obj:`budou.chunk.ChunkList`)


def GetLogdirSubdirectories(path):

  if not tf.io.gfile.exists(path):

    return ()

  if not tf.io.gfile.isdir(path):
    raise ValueError('GetLogdirSubdirectories: path exists and is not a '
                     'directory, %s' % path)

  if IsCloudPath(path):

    logger.info(
        'GetLogdirSubdirectories: Starting to list directories via glob-ing.')
    traversal_method = ListRecursivelyViaGlobbing
  else:

    logger.info(
        'GetLogdirSubdirectories: Starting to list directories via walking.')
    traversal_method = ListRecursivelyViaWalking

  return (
      subdir
      for (subdir, files) in traversal_method(path)
      if any(IsTensorFlowEventsFile(f) for f in files)
  )

Obtains all subdirectories with events files.

The order of the subdirectories returned is unspecified. The internal logic
that determines order varies by scenario.

Args:
path: The path to a directory under which to find subdirectories.

Returns:
A tuple of absolute paths of all subdirectories each with at least 1 events
file directly within the subdirectory.

Raises:
ValueError: If the path passed to the method exists and is not a directory.


def get_lambda_arn(app, account, region):
    session = boto3.Session(profile_name=account, region_name=region)
    lambda_client = session.client('lambda')
    lambda_arn = None
    paginator = lambda_client.get_paginator('list_functions')
    for lambda_functions in paginator.paginate():
        for lambda_function in lambda_functions['Functions']:
            if (lambda_function['FunctionName'] == app):
                lambda_arn = lambda_function['FunctionArn']
                LOG.debug('Lambda ARN for lambda function %s is %s.', app, lambda_arn)
                break
        if lambda_arn:
            break
    if (not lambda_arn):
        LOG.fatal('Lambda function with name %s not found in %s %s', app, account, region)
        raise LambdaFunctionDoesNotExist('Lambda function with name {0} not found in {1} {2}'.format(app, account, region))
    return lambda_arn

Get lambda ARN.

Args:
account (str): AWS account name.
region (str): Region name, e.g. us-east-1
app (str): Lambda function name

Returns:
str: ARN for requested lambda function


def register_recipe(cls, recipe):
    recipe_name = recipe.contents['name']
    cls._recipe_classes[recipe_name] = (recipe.contents, recipe.args, recipe.__doc__)

Registers a dftimewolf recipe.

Args:
recipe: imported python module representing the recipe.


def index_of(self, file_path, line_number, called_function_name, called_file_path, called_function_start_line):
    location_key = (file_path, called_function_name, line_number)
    if location_key in self._location_key_to_location:
        location = self._location_key_to_location[location_key]
        return location.id
    else:
        location_index = len(self._location_key_to_location) + 1
        location = profile_pb2.Location()
        location.id = location_index
        self._location_key_to_location[location_key] = location
        line = location.line.add()
        line.function_id = self._functions.index_of(called_file_path, called_function_name, called_function_start_line)
        line.line = line_number
        return location_index

Returns index of the location, adding the location if needed.

Args:
file_path: (string) Path to file that makes the call.
line_number: (integer) Call line number.
called_function_name: (string) Function name of the function called at
`file_path` and `line_number`.
called_file_path: (string) Path to file where the called function is
defined.
called_function_start_line: (integer) Start line number of called
function definition in `called_file_path` file.

Returns:
Index of location.


def on_value_event(self, event):

    if not event.summary.value:
      logger.info('The summary of the event lacks a value.')
      return None

    watch_key = event.summary.value[0].node_name
    tensor_value = debug_data.load_tensor_from_event(event)
    device_name = _extract_device_name_from_event(event)
    node_name, output_slot, debug_op = (
        event.summary.value[0].node_name.split(':'))
    maybe_base_expanded_node_name = (
        self._run_states.get_maybe_base_expanded_node_name(node_name,
                                                           self._run_key,
                                                           device_name))
    self._tensor_store.add(watch_key, tensor_value)
    self._outgoing_channel.put(_comm_tensor_data(
        device_name, node_name, maybe_base_expanded_node_name, output_slot,
        debug_op, tensor_value, event.wall_time))

    logger.info('on_value_event(): waiting for client ack (tensors)...')
    self._incoming_channel.get()
    logger.info('on_value_event(): client ack received (tensor).')

    if self._is_debug_node_in_breakpoints(event.summary.value[0].node_name):
      logger.info('Sending empty EventReply for breakpoint: %s',
                      event.summary.value[0].node_name)

      return debug_service_pb2.EventReply()
    return None

Records the summary values based on an updated message from the debugger.

Logs an error message if writing the event to disk fails.

Args:
event: The Event proto to be processed.


def create(self, name, description='', whitelisted_container_task_types=None, whitelisted_executable_task_types=None):
    if (whitelisted_container_task_types is None):
        whitelisted_container_task_types = []
    if (whitelisted_executable_task_types is None):
        whitelisted_executable_task_types = []
    request_url = (self._client.base_api_url + self.list_url)
    data_to_post = {'name': name, 'description': description, 'whitelisted_container_task_types': whitelisted_container_task_types, 'whitelisted_executable_task_types': whitelisted_executable_task_types}
    response = self._client.session.post(request_url, data=data_to_post)
    self.validate_request_success(response_text=response.text, request_url=request_url, status_code=response.status_code, expected_status_code=HTTP_201_CREATED)
    return self.response_data_to_model_instance(response.json())

Create a task whitelist.

Args:
name (str): The name of the task whitelist.
description (str, optional): A description of the task whitelist.
whitelisted_container_task_types (list, optional): A list of
whitelisted container task type IDs.
whitelisted_executable_task_types (list, optional): A list
of whitelisted executable task type IDs.

Returns:
:class:`saltant.models.task_whitelist.TaskWhitelist`:
A task whitelist model instance representing the task
whitelist just created.


def __eq__(self, other):

        if isinstance(other, DocumentReference):
            return self._client == other._client and self._path == other._path
        else:
            return NotImplemented

Equality check against another instance.

Args:
other (Any): A value to compare against.

Returns:
Union[bool, NotImplementedType]: Indicating if the values are
equal.


def create_profiler_ui(graph, run_metadata, ui_type='readline', on_ui_exit=None, config=None):
    del config
    analyzer = ProfileAnalyzer(graph, run_metadata)
    cli = ui_factory.get_ui(ui_type, on_ui_exit=on_ui_exit)
    cli.register_command_handler('list_profile', analyzer.list_profile, analyzer.get_help('list_profile'), prefix_aliases=['lp'])
    cli.register_command_handler('print_source', analyzer.print_source, analyzer.get_help('print_source'), prefix_aliases=['ps'])
    return cli

Create an instance of ReadlineUI based on a `tf.Graph` and `RunMetadata`.

Args:
graph: Python `Graph` object.
run_metadata: A `RunMetadata` protobuf object.
ui_type: (str) requested UI type, e.g., "readline".
on_ui_exit: (`Callable`) the callback to be called when the UI exits.
config: An instance of `cli_config.CLIConfig`.

Returns:
(base_ui.BaseUI) A BaseUI subtype object with a set of standard analyzer
commands and tab-completions registered.


def exit_hook(callable, once=True):
  r
  if once and callable in ExitHooks:
    return

  ExitHooks.append(callable)

r"""A decorator that makes the decorated function to run while ec exits.

Args:
callable (callable): The target callable.
once (bool): Avoids adding a func to the hooks, if it has been added already. Defaults to True.

Note:
Hooks are processedd in a LIFO order.


def generate(cache_fn):
    if (not os.path.exists(cache_fn)):
        ((print >> sys.stderr), ("Can't access `%s`!" % cache_fn))
        sys.exit(1)
    with SqliteDict(cache_fn) as db:
        for item in _pick_keywords(db):
            (yield item)

Go thru `cache_fn` and filter keywords. Store them in `keyword_list.json`.

Args:
cache_fn (str): Path to the file with cache.

Returns:
list: List of :class:`KeywordInfo` objects.


def definition_package(cls):
    outer_definition = cls.message_definition()
    if (not outer_definition):
        return util.get_package_for_module(cls.__module__)
    return outer_definition.definition_package()

Helper method for creating creating the package of a definition.

Returns:
Name of package that definition belongs to.


def shift_time(start_time, mins) -> str:
    s_time = pd.Timestamp(start_time)
    e_time = (s_time + (np.sign(mins) * pd.Timedelta(f'00:{abs(mins)}:00')))
    return e_time.strftime('%H:%M')

Shift start time by mins

Args:
start_time: start time in terms of HH:MM string
mins: number of minutes (+ / -)

Returns:
end time in terms of HH:MM string


def findall_operations_with_gate_type(self, gate_type: Type[T_DESIRED_GATE_TYPE]) -> Iterable[Tuple[(int, ops.GateOperation, T_DESIRED_GATE_TYPE)]]:
    result = self.findall_operations((lambda operation: bool(ops.op_gate_of_type(operation, gate_type))))
    for (index, op) in result:
        gate_op = cast(ops.GateOperation, op)
        (yield (index, gate_op, cast(T_DESIRED_GATE_TYPE, gate_op.gate)))

Find the locations of all gate operations of a given type.

Args:
gate_type: The type of gate to find, e.g. XPowGate or
MeasurementGate.

Returns:
An iterator (index, operation, gate)'s for operations with the given
gate type.


def image_data_format():
    return _IMAGE_DATA_FORMAT

Return the default image data format convention.

Returns:
A string, either `'channels_first'` or `'channels_last'`.

Example:

>>> keras.config.image_data_format()
'channels_last'


def create_write_transform(self) -> beam.PTransform[Chunk, Any]:
    raise NotImplementedError(type(self))

Creates a PTransform that writes embeddings to the vector database.

Returns:
A PTransform that accepts PCollection[Chunk] and writes the chunks'
embeddings and metadata to the configured vector database.
The transform should handle:
- Converting Chunk format to database schema
- Setting up database connection/client
- Writing with appropriate batching/error handling


def load(cls, campaign_dir, ns_path=None, runner_type='Auto', optimized=True, check_repo=True):
    if (ns_path is not None):
        ns_path = os.path.abspath(ns_path)
    campaign_dir = os.path.abspath(campaign_dir)
    db = DatabaseManager.load(campaign_dir)
    script = db.get_script()
    runner = None
    if (ns_path is not None):
        runner = CampaignManager.create_runner(ns_path, script, runner_type, optimized)
    return cls(db, runner, check_repo)

Load an existing simulation campaign.

Note that specifying an ns-3 installation is not compulsory when using
this method: existing results will be available, but in order to run
additional simulations it will be necessary to specify a
SimulationRunner object, and assign it to the CampaignManager.

Args:
campaign_dir (str): path to the directory in which to save the
simulation campaign database.
ns_path (str): path to the ns-3 installation to employ in this
campaign.
runner_type (str): implementation of the SimulationRunner to use.
Value can be: SimulationRunner (for running sequential
simulations locally), ParallelRunner (for running parallel
simulations locally), GridRunner (for running simulations using
a DRMAA-compatible parallel task scheduler).
optimized (bool): whether to configure the runner to employ an
optimized ns-3 build.


def ReadFromFile(self, path):
    self._definitions = {}
    with open(path, 'r') as file_object:
        for preset_definition in self._ReadPresetsFromFileObject(file_object):
            self._definitions[preset_definition.name] = preset_definition

Reads parser and parser plugin presets from a file.

Args:
path (str): path of file that contains the the parser and parser plugin
presets configuration.

Raises:
MalformedPresetError: if one or more plugin preset definitions are
malformed.


def _invalid_triple_quote(self, quote, row, col=None):

        self.add_message(
            'invalid-triple-quote',
            line=row,
            args=(quote, TRIPLE_QUOTE_OPTS.get(self.config.triple_quote)),
            **self.get_offset(col)
        )

Add a message for an invalid triple quote.

Args:
quote: The quote characters that were found.
row: The row number the quote characters were found on.
col: The column the quote characters were found on.


def get_image_features(self, pixel_values: torch.FloatTensor, image_sizes: torch.Tensor, vision_feature_layer: Optional[Union[int, List[int]]]=None, vision_feature_select_strategy: Optional[str]=None):
    vision_feature_layer = vision_feature_layer if vision_feature_layer is not None else self.config.vision_feature_layer
    vision_feature_select_strategy = vision_feature_select_strategy if vision_feature_select_strategy is not None else self.config.vision_feature_select_strategy
    image_num_patches = [image_size_to_num_patches(image_size=imsize, grid_pinpoints=self.config.image_grid_pinpoints, patch_size=self.config.vision_config.image_size) for imsize in image_sizes]
    if pixel_values.dim() == 5:
        _pixel_values_list = [pix_val[:num_patch] for pix_val, num_patch in zip(pixel_values, image_num_patches)]
        pixel_values = torch.cat(_pixel_values_list, dim=0)
    elif pixel_values.dim() != 4:
        raise ValueError(f'pixel_values of shape {pixel_values.shape}, expect to be of 4 or 5 dimensions')
    image_features = self.vision_tower(pixel_values, output_hidden_states=True)
    if isinstance(vision_feature_layer, int):
        selected_image_feature = image_features.hidden_states[vision_feature_layer]
    else:
        hs_pool = [image_features.hidden_states[layer_idx] for layer_idx in vision_feature_layer]
        selected_image_feature = torch.cat(hs_pool, dim=-1)
    if vision_feature_select_strategy == 'default':
        selected_image_feature = selected_image_feature[:, 1:]
    elif vision_feature_select_strategy == 'full':
        selected_image_feature = selected_image_feature
    image_features = self.multi_modal_projector(selected_image_feature)
    image_features = torch.split(image_features, image_num_patches, dim=0)
    image_features, feature_lens = self.pack_image_features(image_features, image_sizes, vision_feature_select_strategy, image_newline=self.image_newline)
    return image_features

Obtains image last hidden states from the vision tower and apply multimodal projection.

Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, num_patches, channels, height, width)`)
The tensors corresponding to the input images.
image_sizes (`torch.Tensor` of shape `(num_images, 2)`)
Actual image size of each images (H, W).
vision_feature_layer (`Union[int, List[int]]`, *optional*):
The index of the layer to select the vision feature. If multiple indices are provided,
the vision feature of the corresponding indices will be concatenated to form the
vision features.
vision_feature_select_strategy (`str`, *optional*):
The feature selection strategy used to select the vision feature from the vision backbone.
Can be one of `"default"` or `"full"`
Returns:
image_features (List[`torch.Tensor`]): List of image feature tensor, each contains all the visual feature of all patches
and are of shape `(num_patches, image_length, embed_dim)`).


def merge_config(
    config: Mapping[str, Any],
    override_config: Mapping[str, Any] = None,
    override_config_fn: str = None,
) -> Mapping[str, Any]:

    if override_config_fn:
        with open(override_config_fn, "r") as f:
            override_config = yaml.load(f, Loader=yaml.SafeLoader)

    if not override_config:
        log.info("Missing override_config")

    return functools.reduce(rec_merge, (config, override_config))

Override config with additional configuration in override_config or override_config_fn

Used in script to merge CLI options with Config

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


def replace(self, i, species, coords=None, coords_are_cartesian=False, properties=None):
    if (coords is None):
        frac_coords = self[i].frac_coords
    elif coords_are_cartesian:
        frac_coords = self._lattice.get_fractional_coords(coords)
    else:
        frac_coords = coords
    new_site = PeriodicSite(species, frac_coords, self._lattice, properties=properties)
    self._sites[i] = new_site

Replace a single site. Takes either a species or a dict of species and
occupations.

Args:
i (int): Index of the site in the _sites list.
species (species-like): Species of replacement site
coords (3x1 array): Coordinates of replacement site. If None,
the current coordinates are assumed.
coords_are_cartesian (bool): Whether coordinates are cartesian.
Defaults to False.
properties (dict): Properties associated with the site.


def rename_next_state_fluent(name: str) -> str:
    i = name.index('/')
    functor = name[:(i - 1)]
    arity = name[(i + 1):]
    return '{}/{}'.format(functor, arity)

Returns next state fluent canonical name.

Args:
name (str): The current state fluent name.

Returns:
str: The next state fluent name.


def add_update(self, updates, inputs=None):
    if inputs is not None:
        tf_logging.warning('`add_update` `inputs` kwarg has been deprecated. You no longer need to pass a value to `inputs` as it is being automatically inferred.')
    call_context = base_layer_utils.call_context()
    if distribute_lib.has_strategy() and distribute_lib.in_cross_replica_context() and (not call_context.saving):
        return
    updates = generic_utils.to_list(updates)
    if call_context.in_call:
        relevant_inputs = call_context.inputs
    else:
        inbound_nodes = getattr(self, '_inbound_nodes', [])
        relevant_inputs = [node.input_tensors for node in inbound_nodes]

    def process_update(x):

        if callable(x):
            update = lambda: process_update(x())
            return update()
        elif isinstance(x, ops.Operation):
            update = x
        elif hasattr(x, 'op'):
            update = x.op
        else:
            update = tensor_conversion.convert_to_tensor_v2_with_dispatch(x)
        reachable = tf_utils.get_reachable_from_inputs(relevant_inputs, [update])
        update._unconditional_update = update not in reachable
        return update
    updates = [process_update(x) for x in updates]
    self._updates.extend(updates)

Add update op(s), potentially dependent on layer inputs.

Weight updates (for instance, the updates of the moving mean and variance
in a BatchNormalization layer) may be dependent on the inputs passed
when calling a layer. Hence, when reusing the same layer on
different inputs `a` and `b`, some entries in `layer.updates` may be
dependent on `a` and some on `b`. This method automatically keeps track
of dependencies.

The `get_updates_for` method allows to retrieve the updates relevant to a
specific set of inputs.

This call is ignored when eager execution is enabled (in that case, variable
updates are run on the fly and thus do not need to be tracked for later
execution).

Args:
updates: Update op, or list/tuple of update ops, or zero-arg callable
that returns an update op. A zero-arg callable should be passed in
order to disable running the updates by setting `trainable=False`
on this Layer, when executing in Eager mode.
inputs: Deprecated, will be automatically inferred.


def get_module_functions(modules):
    module_fns = set()
    for module in modules:
        for key in dir(module):
            attr = getattr(module, key)
            if isinstance(attr, (types.BuiltinFunctionType, types.FunctionType, numpy.ufunc)):
                module_fns.add(attr)
    return module_fns

Finds functions that do not have implemented derivatives.

Args:
modules: A list of Python modules. Functions contained in these modules
will be checked for membership in 'implemented', and if not found,
will be added to an 'unimplemented' set
implemented: A Python object containing implemented derivatives. A function
should be checkable for membership using the `fn in implemented` syntax.

Returns:
module_fns: A set of functions, builtins or ufuncs in `modules`.


def unarchive_user(self, user_id):
    url = (self.record_url + '/unarchive')
    res = requests.patch(url=url, json={'user_id': user_id}, headers=HEADERS, verify=False)
    self.write_response_html_to_file(res, 'bob.html')
    res.raise_for_status()

Unarchives the user with the specified user ID.

Args:
user_id: `int`. The ID of the user to unarchive.

Returns:
`NoneType`: None.


def numeric_summary(tensor):

    def _counts_summary(counts, skip_zeros=True, total_count=None):

        if skip_zeros:
            counts = [(count_key, count_val) for count_key, count_val in counts if count_val]
        max_common_len = 0
        for count_key, count_val in counts:
            count_val_str = str(count_val)
            common_len = max(len(count_key) + 1, len(count_val_str) + 1)
            max_common_len = max(common_len, max_common_len)
        key_line = debugger_cli_common.RichLine('|')
        val_line = debugger_cli_common.RichLine('|')
        for count_key, count_val in counts:
            count_val_str = str(count_val)
            key_line += _pad_string_to_length(count_key, max_common_len)
            val_line += _pad_string_to_length(count_val_str, max_common_len)
        key_line += ' |'
        val_line += ' |'
        if total_count is not None:
            total_key_str = 'total'
            total_val_str = str(total_count)
            max_common_len = max(len(total_key_str) + 1, len(total_val_str))
            total_key_str = _pad_string_to_length(total_key_str, max_common_len)
            total_val_str = _pad_string_to_length(total_val_str, max_common_len)
            key_line += total_key_str + ' |'
            val_line += total_val_str + ' |'
        return debugger_cli_common.rich_text_lines_from_rich_line_list([key_line, val_line])
    if not isinstance(tensor, np.ndarray) or not np.size(tensor):
        return debugger_cli_common.RichTextLines(['No numeric summary available due to empty tensor.'])
    elif np.issubdtype(tensor.dtype, np.floating) or np.issubdtype(tensor.dtype, np.complexfloating) or np.issubdtype(tensor.dtype, np.integer):
        counts = [('nan', np.sum(np.isnan(tensor))), ('-inf', np.sum(np.isneginf(tensor))), ('-', np.sum(np.logical_and(tensor < 0.0, np.logical_not(np.isneginf(tensor))))), ('0', np.sum(tensor == 0.0)), ('+', np.sum(np.logical_and(tensor > 0.0, np.logical_not(np.isposinf(tensor))))), ('+inf', np.sum(np.isposinf(tensor)))]
        output = _counts_summary(counts, total_count=np.size(tensor))
        valid_array = tensor[np.logical_not(np.logical_or(np.isinf(tensor), np.isnan(tensor)))]
        if np.size(valid_array):
            stats = [('min', np.min(valid_array)), ('max', np.max(valid_array)), ('mean', np.mean(valid_array)), ('std', np.std(valid_array))]
            output.extend(_counts_summary(stats, skip_zeros=False))
        return output
    elif tensor.dtype == np.bool_:
        counts = [('False', np.sum(tensor == 0)), ('True', np.sum(tensor > 0))]
        return _counts_summary(counts, total_count=np.size(tensor))
    else:
        return debugger_cli_common.RichTextLines(['No numeric summary available due to tensor dtype: %s.' % tensor.dtype])

Get a text summary of a numeric tensor.

This summary is only available for numeric (int*, float*, complex*) and
Boolean tensors.

Args:
tensor: (`numpy.ndarray`) the tensor value object to be summarized.

Returns:
The summary text as a `RichTextLines` object. If the type of `tensor` is not
numeric or Boolean, a single-line `RichTextLines` object containing a
warning message will reflect that.


def ReadPathInfoHistory(self, client_id, path_type, components):
    histories = self.ReadPathInfosHistories(client_id, path_type, [components])
    return histories[components]

Reads a collection of hash and stat entry for given path.

Args:
client_id: An identifier string for a client.
path_type: A type of a path to retrieve path history for.
components: A tuple of path components corresponding to path to retrieve
information for.

Returns:
A list of `rdf_objects.PathInfo` ordered by timestamp in ascending order.


def _data_from_df(df):
    _df = df.copy()
    if isinstance(df.columns, pd.MultiIndex):
        try:
            _df.columns = ['_'.join(col) for col in _df.columns.values]
        except TypeError:
            raise TypeError('Could not flatten MultiIndex columns. use string column names or flatten manually')
    if isinstance(df.columns, pd.CategoricalIndex):
        _df.columns = df.columns.tolist()
    index_name = ColumnDataSource._df_index_name(df)
    if (index_name == 'index'):
        _df.index = pd.Index(_df.index.values)
    else:
        _df.index = pd.Index(_df.index.values, name=index_name)
    _df.reset_index(inplace=True)
    tmp_data = {c: v.values for (c, v) in _df.iteritems()}
    new_data = {}
    for (k, v) in tmp_data.items():
        new_data[k] = v
    return new_data

Create a ``dict`` of columns from a Pandas ``DataFrame``,
suitable for creating a ColumnDataSource.

Args:
df (DataFrame) : data to convert

Returns:
dict[str, np.array]


def DotProductAttention(query, key, value, mask, dropout, mode, rng):
    depth = np.shape(query)[(- 1)]
    dots = (np.matmul(query, np.swapaxes(key, (- 1), (- 2))) / np.sqrt(depth))
    if (mask is not None):
        dots = np.where(mask, dots, (- 1000000000.0))
    dots = np.exp((dots - backend.logsumexp(dots, axis=(- 1), keepdims=True)))
    if (dropout >= 1.0):
        raise ValueError('Dropout rates must be lower than 1.')
    if ((dropout is not None) and (dropout > 0.0) and (mode == 'train')):
        keep = backend.random.bernoulli(rng, (1.0 - dropout), dots.shape)
        dots = np.where(keep, (dots / (1.0 - dropout)), 0)
    out = np.matmul(dots, value)
    return out

Core dot product self-attention.

Args:
query: array of representations
key: array of representations
value: array of representations
mask: attention-mask, gates attention
dropout: float: dropout rate
mode: 'eval' or 'train': whether to use dropout
rng: JAX PRNGKey: subkey for disposable use

Returns:
Self attention for q, k, v arrays.


def __init__(self,
                 intervals: List[Interval] = None,
                 no_overlap: bool = True,
                 no_contiguous: bool = True) -> None:

        self.intervals = [] if intervals is None else list(intervals)
        self.no_overlap = no_overlap
        self.no_contiguous = no_contiguous
        for i in self.intervals:
            if not isinstance(i, Interval):
                raise TypeError(
                    "IntervalList creation failed: contents are not all "
                    "Interval: {}".format(repr(self.intervals)))
        self._tidy()

Creates the :class:`IntervalList`.

Args:
intervals: optional list of :class:`Interval` objects to
incorporate into the :class:`IntervalList`
no_overlap: merge intervals that overlap (now and on subsequent
addition)?
no_contiguous: if ``no_overlap`` is set, merge intervals that are
contiguous too?


def rebuild_tree(cls, session, tree_id):
    session.query(cls).filter_by(tree_id=tree_id).update({cls.left: 0, cls.right: 0, cls.level: 0})
    top = session.query(cls).filter_by(parent_id=None).filter_by(tree_id=tree_id).one()
    top.left = left = 1
    top.right = right = 2
    top.level = level = cls.get_default_level()

    def recursive(children, left, right, level):
        level = (level + 1)
        for (i, node) in enumerate(children):
            same_level_right = children[(i - 1)].right
            left = (left + 1)
            if (i > 0):
                left = (left + 1)
            if same_level_right:
                left = (same_level_right + 1)
            right = (left + 1)
            node.left = left
            node.right = right
            parent = node.parent
            j = 0
            while parent:
                parent.right = ((right + 1) + j)
                parent = parent.parent
                j += 1
            node.level = level
            recursive(node.children, left, right, level)
    recursive(top.children, left, right, level)

This method rebuid tree.

Args:
session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session
tree_id (int or str): id of tree

Example:

* :mod:`sqlalchemy_mptt.tests.cases.get_tree.test_rebuild`


def Format(self, format_string, rdf):
    result = []
    for (literal_text, field_name, _, _) in self.parse(format_string):
        if literal_text:
            result.append(literal_text)
        if (field_name is not None):
            rslts = []
            objs = self.expander(rdf, field_name)
            for o in objs:
                rslts.extend(self.FanOut(o))
            result.append(','.join(rslts))
    return ''.join(result)

Apply string formatting templates to rdf data.

Uses some heuristics to coerce rdf values into a form compatible with string
formatter rules. Repeated items are condensed into a single comma separated
list. Unlike regular string.Formatter operations, we use objectfilter
expansion to fully acquire the target attribute in one pass, rather than
recursing down each element of the attribute tree.

Args:
format_string: A format string specification.
rdf: The rdf value to be formatted.

Returns:
A string of formatted data.


def path_in_cache(self, filename, metahash):

        cpath = self._genpath(filename, metahash)
        if os.path.exists(cpath):
            return cpath
        else:
            raise CacheMiss

Generates the path to a file in the mh cache.

The generated path does not imply the file's existence!

Args:
filename: Filename relative to buildroot
rule: A targets.SomeBuildRule object
metahash: hash object


def build_from_token_counts(self, token_counts, min_count, num_iterations=4):
    self._init_alphabet_from_tokens(six.iterkeys(token_counts))
    self._init_subtokens_from_list(list(self._alphabet))
    if (min_count < 1):
        min_count = 1
    for i in xrange(num_iterations):
        subtoken_counts = collections.defaultdict(int)
        for (token, count) in six.iteritems(token_counts):
            escaped_token = _escape_token(token, self._alphabet)
            subtokens = self._escaped_token_to_subtoken_strings(escaped_token)
            start = 0
            for subtoken in subtokens:
                for end in xrange((start + 1), (len(escaped_token) + 1)):
                    new_subtoken = escaped_token[start:end]
                    subtoken_counts[new_subtoken] += count
                start += len(subtoken)
        len_to_subtoken_strings = []
        for (subtoken_string, count) in six.iteritems(subtoken_counts):
            lsub = len(subtoken_string)
            if (count >= min_count):
                while (len(len_to_subtoken_strings) <= lsub):
                    len_to_subtoken_strings.append(set())
                len_to_subtoken_strings[lsub].add(subtoken_string)
        new_subtoken_strings = []
        for lsub in xrange((len(len_to_subtoken_strings) - 1), 0, (- 1)):
            subtoken_strings = len_to_subtoken_strings[lsub]
            for subtoken_string in subtoken_strings:
                count = subtoken_counts[subtoken_string]
                if (count >= min_count):
                    if (subtoken_string not in self._alphabet):
                        new_subtoken_strings.append((count, subtoken_string))
                    for l in xrange(1, lsub):
                        subtoken_counts[subtoken_string[:l]] -= count
        new_subtoken_strings.extend(((subtoken_counts.get(a, 0), a) for a in self._alphabet))
        new_subtoken_strings.sort(reverse=True)
        self._init_subtokens_from_list([subtoken for (_, subtoken) in new_subtoken_strings])

Train a SubwordTextTokenizer based on a dictionary of word counts.

Args:
token_counts: a dictionary of Unicode strings to int.
min_count: an integer - discard subtokens with lower counts.
num_iterations: an integer; how many iterations of refinement.


def interruptRead(self, endpoint, size, timeout = 100):
        r
        return self.dev.read(endpoint, size, timeout)

r"""Performs a interrupt read request to the endpoint specified.

Arguments:
endpoint: endpoint number.
size: number of bytes to read.
timeout: operation timeout in milliseconds. (default: 100)
Returns a tuple with the data read.


def get_values(js_dict, value='value'):

    values = js_dict[value]
    if type(values) is list:
        if type(values[0]) is not dict or tuple:
            return values

    values = {int(key): value for (key, value) in values.items()}

    if js_dict.get('size'):
        max_val = np.prod(np.array((js_dict['size'])))
    else:
        max_val = np.prod(np.array((js_dict['dimension']['size'])))
    vals = max_val * [None]
    for (key, value) in values.items():
        vals[key] = value

    values = vals
    return values

Get values from input data.

Args:
js_dict (dict): dictionary containing dataset data and metadata.
value (string, optional): name of the value column. Defaults to 'value'.

Returns:
values (list): list of dataset values.


def run(func, keys, max_procs=None, show_proc=False, affinity=None, **kwargs):

    if max_procs is None: max_procs = cpu_count()
    kw_arr = saturate_kwargs(keys=keys, **kwargs)
    if len(kw_arr) == 0: return

    if isinstance(affinity, int):
        win32process.SetProcessAffinityMask(win32api.GetCurrentProcess(), affinity)

    task_queue = queue.Queue()
    while len(kw_arr) > 0:
        for _ in range(max_procs):
            if len(kw_arr) == 0: break
            kw = kw_arr.pop(0)
            p = Process(target=func, kwargs=kw)
            p.start()
            sys.stdout.flush()
            task_queue.put(p)
            if show_proc:
                signature = ', '.join([f'{k}={v}' for k, v in kw.items()])
                print(f'[{func.__name__}] ({signature})')
        while not task_queue.empty():
            p = task_queue.get()
            p.join()

Provide interface for multiprocessing

Args:
func: callable functions
keys: keys in kwargs that want to use process
max_procs: max number of processes
show_proc: whether to show process
affinity: CPU affinity
**kwargs: kwargs for func


class PerceiverOneHotPreprocessor(AbstractPreprocessor):

    def __init__(self, config: PerceiverConfig) -> None:
        super().__init__()
        self.config: PerceiverConfig = config

    @property
    def num_channels(self) -> int:
        return self.config.num_labels

    def forward(self, inputs: torch.Tensor, pos: Optional[torch.Tensor]=None, network_input_is_1d: bool=True):
        inputs = inputs[:, None, :]
        return (inputs, None, inputs)

One-hot preprocessor for Perceiver Encoder. Can be used to add a dummy index dimension to the input.

Args:
config ([`PerceiverConfig`]):
Model configuration.


def copy_count_a(input_a, *other_inputs, **kwargs):
    count = input_a.count()
    input_a.skip_all()
    for input_x in other_inputs:
        input_x.skip_all()
    return [IOTileReading(0, 0, count)]

Copy the latest reading from input a into the output.

All other inputs are skipped to that after this function
runs there are no readings left in any of the input walkers
even if no output is generated.

Returns:
list(IOTileReading)


def ParseShadowEntry(self, line):

    fields = ("login", "passwd", "last_change", "min_age", "max_age",
              "warn_time", "inactivity", "expire", "reserved")
    if line:
      rslt = dict(zip(fields, line.split(":")))
      pw_entry = self.shadow.setdefault(rslt["login"], rdf_client.PwEntry())
      pw_entry.store = self.shadow_store
      pw_entry.hash_type = self.GetHashType(rslt["passwd"])

      last_change = rslt.get("last_change")
      if last_change:
        pw_entry.age = int(last_change)
      max_age = rslt.get("max_age")
      if max_age:
        pw_entry.max_age = int(max_age)

Extract the user accounts in /etc/shadow.

Identifies the users in /etc/shadow and several attributes of their account,
including how their password is crypted and password aging characteristics.

Args:
line: An entry of the shadow file.