Hyperbolic tangent activation function.

For example:

>>> a = tf.constant([-3.0,-1.0, 0.0,1.0,3.0], dtype = tf.float32)
>>> b = tf.keras.activations.tanh(a)
>>> b.numpy()
array([-0.9950547, -0.7615942,  0.,  0.7615942,  0.9950547], dtype=float32)

Args:
x: Input tensor.

Returns:
Tensor of same shape and dtype of input `x`, with tanh activation:
`tanh(x) = sinh(x)/cosh(x) = ((exp(x) - exp(-x))/(exp(x) + exp(-x)))`.


def __init__(self, value, ctype=None):

        if isinstance(value, str) and value == 'INFINITY':
            self._value = np.inf
        elif isinstance(value, str) and value == '-INFINITY':
            self._value = -np.inf
        else:
            self._value = np.array(value)
        self._ctype = ctype or dtype_to_ctype(self._value.dtype)
        self._mot_float_dtype = None

A kernel input scalar.

This will insert the given value directly into the kernel's source code, and will not load it as a buffer.

Args:
value (number): the number to insert into the kernel as a scalar.
ctype (str): the desired c-type for in use in the kernel, like ``int``, ``float`` or ``mot_float_type``.
If None it is implied from the value.


def prepare_data(data_dir, fileroot, block_pct_tokens_thresh=0.1):
    if (not (0.0 <= block_pct_tokens_thresh <= 1.0)):
        raise ValueError('block_pct_tokens_thresh must be in the range [0.0, 1.0]')
    html = read_html_file(data_dir, fileroot)
    blocks = read_gold_standard_blocks_file(data_dir, fileroot, split_blocks=True)
    content_blocks = []
    comments_blocks = []
    for block in blocks:
        block_split = block.split('\t')
        num_block_tokens = len(block_split[2].split())
        content_blocks.append((float(block_split[0]), num_block_tokens, block_split[3].split()))
        comments_blocks.append((float(block_split[1]), num_block_tokens, block_split[4].split()))
    parsed_content_blocks = _parse_content_or_comments_blocks(content_blocks, block_pct_tokens_thresh)
    parsed_comments_blocks = _parse_content_or_comments_blocks(comments_blocks, block_pct_tokens_thresh)
    return (html, parsed_content_blocks, parsed_comments_blocks)

Prepare data for a single HTML + gold standard blocks example, uniquely
identified by ``fileroot``.

Args:
data_dir (str)
fileroot (str)
block_pct_tokens_thresh (float): must be in [0.0, 1.0]

Returns:
Tuple[str, Tuple[np.array[int], np.array[int], List[str]], Tuple[np.array[int], np.array[int], List[str]]]:
The first element is simply the raw html as a string. The second and
third elements are 3-tuples for content and comments, respectively,
where the first element is a numpy array of 1s and 0s whose values
correspond to whether or not a given block is considered non-content
or not; the second element is a numpy integer array whose values are
the total number of tokens in each block; and the third element is
a flat list of content or comment tokens as strings, concatenated
from all blocks.

See Also:
:func:`prepare_all_data`


def run_multiple(self, eventLoops):
    self.nruns += len(eventLoops)
    return self.communicationChannel.put_multiple(eventLoops)

run the event loops in the background.

Args:
eventLoops (list): a list of event loops to run


def enqueue_tpu_embedding_integer_batch(batch, device_ordinal, mode_override=None, name=None):
    if mode_override is None:
        mode_override = 'unspecified'
    return gen_tpu_ops.enqueue_tpu_embedding_integer_batch(batch=batch, device_ordinal=device_ordinal, mode_override=mode_override, name=name)

A placeholder op for enqueueing embedding IDs to the TPU.

Args:
batch: A list of 1D tensors, one for each embedding table, containing the
indices into the tables.
device_ordinal: The TPU device to use. Should be >= 0 and less than the
number of TPU cores in the task on which the node is placed.
mode_override: A string input that overrides the mode specified in the
TPUEmbeddingConfiguration. Supported values are {'unspecified',
'inference', 'train', 'backward_pass_only'}. When set to 'unspecified',
the mode set in TPUEmbeddingConfiguration is used, otherwise mode_override
is used (optional).
name: A name for the operation (optional).

Returns:
An EnqueueTPUEmbeddingIntegerBatch operation.


def output_classes(self):
    return nest.map_structure(lambda component_spec: component_spec._to_legacy_output_classes(), self._element_spec)

Returns the class of each component of an element of this iterator.

The expected values are `tf.Tensor` and `tf.sparse.SparseTensor`.

Returns:
A (nested) structure of Python `type` objects corresponding to each
component of an element of this dataset.


def in_labelset(xmrs, nodeids, label=None):
    nodeids = set(nodeids)
    if (label is None):
        label = xmrs.ep(next(iter(nodeids))).label
    return nodeids.issubset(xmrs._vars[label]['refs']['LBL'])

Test if all nodeids share a label.

Args:
nodeids: iterable of nodeids
label (str, optional): the label that all nodeids must share
Returns:
bool: `True` if all nodeids share a label, otherwise `False`


def zpath(filename):

    for ext in ["", '.gz', '.GZ', '.bz2', '.BZ2', '.z', '.Z']:
        zfilename = "{}{}".format(filename, ext)
        if os.path.exists(zfilename):
            return zfilename
    return filename

Returns an existing (zipped or unzipped) file path given the unzipped
version. If no path exists, returns the filename unmodified.

Args:
filename: filename without zip extension

Returns:
filename with a zip extension (unless an unzipped version
exists). If filename is not found, the same filename is returned
unchanged.


def fillPelicanHole(site, username, password, tstat_name, start_time, end_time):
    start = datetime.strptime(start_time, _INPUT_TIME_FORMAT).replace(tzinfo=pytz.utc).astimezone(_pelican_time)
    end = datetime.strptime(end_time, _INPUT_TIME_FORMAT).replace(tzinfo=pytz.utc).astimezone(_pelican_time)
    heat_needs_fan = _lookupHeatNeedsFan(site, username, password, tstat_name)
    if (heat_needs_fan is None):
        return None
    history_blocks = []
    while (start < end):
        block_start = start
        block_end = min((start + timedelta(days=30)), end)
        blocks = _lookupHistoricalData(site, username, password, tstat_name, block_start, block_end)
        if (blocks is None):
            return None
        history_blocks.extend(blocks)
        start += timedelta(days=30, minutes=1)
    output_rows = []
    for block in history_blocks:
        runStatus = block.find('runStatus').text
        if runStatus.startswith('Heat'):
            fanState = (heatNeedsFan == 'Yes')
        else:
            fanState = (runStatus != 'Off')
        api_time = datetime.strptime(block.find('timestamp').text, '%Y-%m-%dT%H:%M').replace(tzinfo=_pelican_time)
        timestamp = int((api_time.timestamp() * (10 ** 9)))
        output_rows.append({'temperature': float(block.find('temperature').text), 'relative_humidity': float(block.find('humidity').text), 'heating_setpoint': float(block.find('heatSetting').text), 'cooling_setpoint': float(block.find('coolSetting').text), 'override': (block.find('setBy').text != 'Schedule'), 'fan': fanState, 'mode': _mode_name_mappings[block.find('system').text], 'state': _state_mappings.get(runStatus, 0), 'time': timestamp})
    df = pd.DataFrame(output_rows)
    df.drop_duplicates(subset='time', keep='first', inplace=True)
    return df

Fill a hole in a Pelican thermostat's data stream.

Arguments:
site -- The thermostat's Pelican site name
username -- The Pelican username for the site
password -- The Pelican password for the site
tstat_name -- The name of the thermostat, as identified by Pelican
start_time -- The start of the data hole in UTC, e.g. "2018-01-29 15:00:00"
end_time -- The end of the data hole in UTC, e.g. "2018-01-29 16:00:00"

Returns:
A Pandas dataframe with historical Pelican data that falls between the
specified start and end times.

Note that this function assumes the Pelican thermostat's local time zone is
US/Pacific. It will properly handle PST vs. PDT.


def getent(refresh=False):

    if 'group.getent' in __context__ and not refresh:
        return __context__['group.getent']

    ret = []

    results = _get_all_groups()

    for result in results:
        group = {'gid': __salt__['file.group_to_gid'](result.Name),
                'members': [_get_username(x) for x in result.members()],
                'name': result.Name,
                'passwd': 'x'}
        ret.append(group)
    __context__['group.getent'] = ret
    return ret

Return info on all groups

Args:

refresh (bool):
Refresh the info for all groups in ``__context__``. If False only
the groups in ``__context__`` will be returned. If True the
``__context__`` will be refreshed with current data and returned.
Default is False

Returns:
A list of groups and their information

CLI Example:

.. code-block:: bash

salt '*' group.getent


def get_sitej(self, site_index, image_index):

        atoms_n_occu = self.s[site_index].species
        lattice = self.s.lattice
        coords = self.s[site_index].frac_coords + self.offsets[image_index]
        return PeriodicSite(atoms_n_occu, coords, lattice)

Assuming there is some value in the connectivity array at indices
(1, 3, 12). sitei can be obtained directly from the input structure
(structure[1]). sitej can be obtained by passing 3, 12 to this function

Args:
site_index (int): index of the site (3 in the example)
image_index (int): index of the image (12 in the example)


def get_roles(self):
    prefix = (_IDENTITY_NS + _ROLE_NS)
    rolelist_list = [_create_from_bytes(d, identity_pb2.RoleList) for (_, d) in self._state_view.leaves(prefix=prefix)]
    roles = []
    for role_list in rolelist_list:
        for role in role_list.roles:
            roles.append(role)
    return sorted(roles, key=(lambda r: r.name))

Return all the Roles under the Identity namespace.

Returns:
(list): A list containing all the Roles under the Identity
namespace.


def get_items_by_ids(self, item_ids, item_type=None):

        urls = [urljoin(self.item_url, F"{i}.json") for i in item_ids]
        result = self._run_async(urls=urls)
        items = [Item(r) for r in result if r]
        if item_type:
            return [item for item in items if item.item_type == item_type]
        else:
            return items

Given a list of item ids, return all the Item objects

Args:
item_ids (obj): List of item IDs to query
item_type (str): (optional) Item type to filter results with

Returns:
List of `Item` objects for given item IDs and given item type


def parse_readable_time_str(time_str):

    def parse_positive_float(value_str):
        value = float(value_str)
        if value < 0:
            raise ValueError('Invalid time %s. Time value must be positive.' % value_str)
        return value
    time_str = time_str.strip()
    if time_str.endswith('us'):
        return int(parse_positive_float(time_str[:-2]))
    elif time_str.endswith('ms'):
        return int(parse_positive_float(time_str[:-2]) * 1000.0)
    elif time_str.endswith('s'):
        return int(parse_positive_float(time_str[:-1]) * 1000000.0)
    return int(parse_positive_float(time_str))

Parses a time string in the format N, Nus, Nms, Ns.

Args:
time_str: (`str`) string consisting of an integer time value optionally
followed by 'us', 'ms', or 's' suffix. If suffix is not specified,
value is assumed to be in microseconds. (e.g. 100us, 8ms, 5s, 100).

Returns:
Microseconds value.


def __init__(self, msg, exception_details=None):
    message = '%s with exceptions %s' % (msg, exception_details)
    super().__init__(message)
    self.exception_details = exception_details

Class representing the errors thrown in the batch file operations.
Args:
msg: Message string for the exception thrown
exception_details: Optional map of individual input to exception for
failed operations in batch. This parameter is optional so if specified
the user can assume that the all errors in the filesystem operation
have been reported. When the details are missing then the operation
may have failed anywhere so the user should use match to determine
the current state of the system.


def replace_in_file(filename: str, text_from: str, text_to: str) -> None:
    log.info('Amending {}: {} -> {}', filename, repr(text_from), repr(text_to))
    with open(filename) as infile:
        contents = infile.read()
    contents = contents.replace(text_from, text_to)
    with open(filename, 'w') as outfile:
        outfile.write(contents)

Replaces text in a file.

Args:
filename: filename to process (modifying it in place)
text_from: original text to replace
text_to: replacement text


async def client_event_handler(self, client_id, event_tuple, user_data):

        conn_string, event_name, event = event_tuple

        if event_name == 'report':
            report = event.serialize()
            report['encoded_report'] = base64.b64encode(report['encoded_report'])
            msg_payload = dict(connection_string=conn_string, serialized_report=report)
            msg_name = OPERATIONS.NOTIFY_REPORT
        elif event_name == 'trace':
            encoded_payload = base64.b64encode(event)
            msg_payload = dict(connection_string=conn_string, payload=encoded_payload)
            msg_name = OPERATIONS.NOTIFY_TRACE
        elif event_name == 'progress':
            msg_payload = dict(connection_string=conn_string, operation=event.get('operation'),
                               done_count=event.get('finished'), total_count=event.get('total'))
            msg_name = OPERATIONS.NOTIFY_PROGRESS
        elif event_name == 'device_seen':
            msg_payload = event
            msg_name = OPERATIONS.NOTIFY_DEVICE_FOUND
        elif event_name == 'broadcast':
            report = event.serialize()
            report['encoded_report'] = base64.b64encode(report['encoded_report'])
            msg_payload = dict(connection_string=conn_string, serialized_report=report)
            msg_name = OPERATIONS.NOTIFY_BROADCAST
        else:
            self._logger.debug("Not forwarding unknown event over websockets: %s", event_tuple)
            return

        try:
            self._logger.debug("Sending event %s: %s", msg_name, msg_payload)
            await self.server.send_event(user_data, msg_name, msg_payload)
        except websockets.exceptions.ConnectionClosed:
            self._logger.debug("Could not send notification because connection was closed for client %s", client_id)

Forward an event on behalf of a client.

This method is called by StandardDeviceServer when it has an event that
should be sent to a client.

Args:
client_id (str): The client that we should send this event to
event_tuple (tuple): The conn_string, event_name and event
object passed from the call to notify_event.
user_data (object): The user data passed in the call to
:meth:`setup_client`.


def RegisterRecordType(cls, record_class):

        record_type = record_class.MatchType()
        if record_type not in UpdateRecord.KNOWN_CLASSES:
            UpdateRecord.KNOWN_CLASSES[record_type] = []

        UpdateRecord.KNOWN_CLASSES[record_type].append(record_class)

Register a known record type in KNOWN_CLASSES.

Args:
record_class (UpdateRecord): An update record subclass.


def create_graph_from_data(self, data, **kwargs):

        self.arguments['{VERBOSE}'] = str(self.verbose).upper()
        results = self._run_ccdr(data, verbose=self.verbose)
        return nx.relabel_nodes(nx.DiGraph(results),
                                {idx: i for idx, i in enumerate(data.columns)})

Apply causal discovery on observational data using CCDr.

Args:
data (pandas.DataFrame): DataFrame containing the data

Returns:
networkx.DiGraph: Solution given by the CCDR algorithm.


def validate_instance(instance, options=None):

    if 'type' not in instance:
        raise ValidationError("Input must be an object with a 'type' property.")

    if not options:
        options = ValidationOptions()

    error_gens = []

    if instance['type'] == 'bundle' and 'objects' in instance:

        for sdo in instance['objects']:
            if 'type' not in sdo:
                raise ValidationError("Each object in bundle must have a 'type' property.")
            error_gens += _schema_validate(sdo, options)
    else:
        error_gens += _schema_validate(instance, options)

    must_checks = _get_musts(options)
    should_checks = _get_shoulds(options)
    output.info("Running the following additional checks: %s."
                % ", ".join(x.__name__ for x in chain(must_checks, should_checks)))
    try:
        errors = _iter_errors_custom(instance, must_checks, options)
        warnings = _iter_errors_custom(instance, should_checks, options)

        if options.strict:
            chained_errors = chain(errors, warnings)
            warnings = []
        else:
            chained_errors = errors
            warnings = [pretty_error(x, options.verbose) for x in warnings]
    except schema_exceptions.RefResolutionError:
        raise SchemaInvalidError('Invalid JSON schema: a JSON reference '
                                 'failed to resolve')

    error_gens += [(chained_errors, '')]

    error_list = []
    for gen, prefix in error_gens:
        for error in gen:
            msg = prefix + pretty_error(error, options.verbose)
            error_list.append(SchemaError(msg))

    if error_list:
        valid = False
    else:
        valid = True

    return ObjectValidationResults(is_valid=valid, object_id=instance.get('id', ''),
                                   errors=error_list, warnings=warnings)

Perform STIX JSON Schema validation against STIX input.

Find the correct schema by looking at the 'type' property of the
`instance` JSON object.

Args:
instance: A Python dictionary representing a STIX object with a
'type' property.
options: ValidationOptions instance with validation options for this
validation run.

Returns:
A dictionary of validation results


def extract_string_pairs_in_ib_file(file_path, special_ui_components_prefix):

    try:
        results = []
        xmldoc = minidom.parse(file_path)

        element_name_to_add_func = {'label': add_string_pairs_from_label_element,
                                    'button': add_string_pairs_from_button_element,
                                    'textField': add_string_pairs_from_text_field_element,
                                    'textView': add_string_pairs_from_text_view_element}

        for element_name in element_name_to_add_func:
            add_func = element_name_to_add_func[element_name]
            elements = xmldoc.getElementsByTagName(element_name)
            for element in elements:
                add_func(file_path, results, element, special_ui_components_prefix)

        jtl_brackets_find_results = re.findall(JTL_REGEX, open(file_path).read())
        unescaped_jtl_brackets_find_results = [(unescape(x), unescape(y)) for (x, y) in jtl_brackets_find_results]
        results += unescaped_jtl_brackets_find_results

        if len(results) > 0:
            results = [(None, os.path.basename(file_path))] + results
        return results

    except Exception, e:
        logging.warn("ERROR: Error processing %s (%s: %s)", file_path, type(e), str(e))
        return []

Extract the strings pairs (key and comment) from a xib file.

Args:
file_path (str): The path to the xib file.
special_ui_components_prefix (str):
If not None, extraction will not warn about internationalized UI components with this class prefix.

Returns:
list: List of tuples representing the string pairs.


def __init__(self, name, fn, dataFormat = DataFormats.DEFAULT):

    Aggregator.__init__(self, name)
    self.fn = fn

Creates a highlight aggregator - this will pick one of the values to highlight.

Args:
name: The name of this aggregator.
fn: Callable that takes (a, b) and returns True if b should be selected as the highlight, where as is the
previous chosen highlight.


def line_distance_similarity(p1a, p1b, p2a, p2b, T=CLOSE_DISTANCE_THRESHOLD):

    d1 = distance_similarity(p1a, p1b, p2a, T=T)
    d2 = distance_similarity(p1a, p1b, p2b, T=T)
    return abs(d1 + d2) * 0.5

Line distance similarity between two line segments

Args:
p1a ([float, float]): x and y coordinates. Line A start
p1b ([float, float]): x and y coordinates. Line A end
p2a ([float, float]): x and y coordinates. Line B start
p2b ([float, float]): x and y coordinates. Line B end
Returns:
float: between 0 and 1. Where 1 is very similar and 0 is completely different


def moma(self, wt_fluxes):

        reactions = set(self._adjustment_reactions())
        v = self._v

        obj_expr = 0
        for f_reaction, f_value in iteritems(wt_fluxes):
            if f_reaction in reactions:

                obj_expr += (f_value - v[f_reaction])**2

        self._prob.set_objective(obj_expr)
        self._solve(lp.ObjectiveSense.Minimize)

Minimize the redistribution of fluxes using Euclidean distance.

Minimizing the redistribution of fluxes using a quadratic objective
function. The distance is minimized by minimizing the sum of
(wild type - knockout)^2.

Args:
wt_fluxes: Dictionary of all the wild type fluxes that will be
used to find a close MOMA solution. Fluxes can be expiremental
or calculated using :meth: get_fba_flux(objective).


def set_of_vars(arg_plot):

    sovs = set(tuple((var + '+').split('+')[:2])
               for var in arg_plot.split(','))
    sovs.discard(('', ''))
    return sovs

Build set of needed field variables.

Each var is a tuple, first component is a scalar field, second component is
either:

- a scalar field, isocontours are added to the plot.
- a vector field (e.g. 'v' for the (v1,v2,v3) vector), arrows are added to
the plot.

Args:
arg_plot (str): string with variable names separated with
``,`` (figures), and ``+`` (same plot).
Returns:
set of str: set of needed field variables.


def _default_ising_beta_range(h, J):

    abs_h = [abs(hh) for hh in h.values() if hh != 0]
    abs_J = [abs(jj) for jj in J.values() if jj != 0]
    abs_biases = abs_h + abs_J

    if not abs_biases:
        return [0.1, 1.0]

    min_delta_energy = min(abs_biases)

    abs_bias_dict = {k: abs(v) for k, v in h.items()}
    for (k1, k2), v in J.items():
        abs_bias_dict[k1] += abs(v)
        abs_bias_dict[k2] += abs(v)

    max_delta_energy = max(abs_bias_dict.values())

    hot_beta = np.log(2) / max_delta_energy
    cold_beta = np.log(100) / min_delta_energy

    return [hot_beta, cold_beta]

Determine the starting and ending beta from h J

Args:
h (dict)

J (dict)

Assume each variable in J is also in h.

We use the minimum bias to give a lower bound on the minimum energy gap, such at the
final sweeps we are highly likely to settle into the current valley.


def get_mac_dot_app_dir(directory):

    return os.path.dirname(os.path.dirname(os.path.dirname(directory)))

Returns parent directory of mac .app

Args:

directory (str): Current directory

Returns:

(str): Parent directory of mac .app


def index(self, text, terms=None, **kwargs):
    self.clear()
    terms = (terms or text.terms.keys())
    pairs = combinations(terms, 2)
    count = comb(len(terms), 2)
    for (t1, t2) in bar(pairs, expected_size=count, every=1000):
        score = text.score_braycurtis(t1, t2, **kwargs)
        self.set_pair(t1, t2, score)

Index all term pair distances.

Args:
text (Text): The source text.
terms (list): Terms to index.


def get_checkpoint_path(model_path):
    if (os.path.basename(model_path) == model_path):
        model_path = os.path.join('.', model_path)
    if (os.path.basename(model_path) == 'checkpoint'):
        assert tfv1.gfile.Exists(model_path), model_path
        model_path = tf.train.latest_checkpoint(os.path.dirname(model_path))
    new_path = model_path
    if ('00000-of-00001' in model_path):
        new_path = model_path.split('.data')[0]
    elif model_path.endswith('.index'):
        new_path = model_path.split('.index')[0]
    if (new_path != model_path):
        logger.info('Checkpoint path {} is auto-corrected to {}.'.format(model_path, new_path))
        model_path = new_path
    assert (tfv1.gfile.Exists(model_path) or tfv1.gfile.Exists((model_path + '.index'))), model_path
    return model_path

Work around TF problems in checkpoint path handling.

Args:
model_path: a user-input path
Returns:
str: the argument that can be passed to NewCheckpointReader


def create_config(sections, section_contents):
    (sections_length, section_contents_length) = (len(sections), len(section_contents))
    if (sections_length != section_contents_length):
        raise ValueError('Mismatch between argument lengths.\nlen(sections) = {}\nlen(section_contents) = {}'.format(sections_length, section_contents_length))
    config = configparser.ConfigParser()
    for (section, section_content) in zip(sections, section_contents):
        config[section] = section_content
    return config

Create a config file from the provided sections and key value pairs.

Args:
sections (List[str]): A list of section keys.
key_value_pairs (Dict[str, str]): A list of of dictionaries. Must be as long as
the list of sections. That is to say, if there are two sections, there should be two
dicts.
Returns:
configparser.ConfigParser: A ConfigParser.
Raises:
ValueError


def Aggregated(self, request, global_params=None):
    config = self.GetMethodConfig('Aggregated')
    return self._RunMethod(config, request, global_params=global_params)

List the jobs of a project across all regions. **Note:** This method doesn't support filtering the list of jobs by name.

Args:
request: (DataflowProjectsJobsAggregatedRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(ListJobsResponse) The response message.


def _date_to_datetime(value):
    if (not isinstance(value, datetime.date)):
        raise TypeError(('Cannot convert to datetime expected date value; received %s' % value))
    return datetime.datetime(value.year, value.month, value.day)

Convert a date to a datetime for Cloud Datastore storage.

Args:
value: A datetime.date object.

Returns:
A datetime object with time set to 0:00.


def get_by_alias(self, alias):

        if alias not in self._aliases:
            raise DataInvalidAlias('A dataset with alias {} does not exist'.format(alias))

        return self.get_by_index(self._aliases[alias])

Return a dataset by its alias.

Args:
alias (str): The alias of the dataset that should be returned.

Raises:
DataInvalidAlias: If the alias does not represent a valid dataset.


def PyParseJoinList(string, location, tokens):

  join_list = []
  for token in tokens:
    try:
      join_list.append(str(token))
    except UnicodeDecodeError:
      join_list.append(repr(token))

  tokens[0] = ''.join(join_list)
  del tokens[1:]

Return a joined token from a list of tokens.

This is a callback method for pyparsing setParseAction that modifies
the returned token list to join all the elements in the list to a single
token.

Args:
string (str): original string.
location (int): location in the string where the match was made.
tokens (list[str]): extracted tokens, where the string to be converted
is stored.


def rep(parser: Union[(Parser, Sequence[Input])]) -> RepeatedParser:
    if isinstance(parser, str):
        parser = lit(parser)
    return RepeatedParser(parser)

Match a parser zero or more times repeatedly.

This matches ``parser`` multiple times in a row. A list is returned
containing the value from each match. If there are no matches, an empty list
is returned.

Args:
parser: Parser or literal


def _normalize_pattern(pattern):

        if pattern.startswith('regex:'):
            pattern_type = 'regex'
            pattern = pattern[len('regex:'):]
        elif pattern.startswith('wildcard:'):
            pattern_type = 'wildcard'
            pattern = pattern[len('wildcard:'):]
        elif pattern.startswith('literal:'):
            pattern_type = 'literal'
            pattern = pattern[len('literal:'):]
        elif RegexRoute.like(pattern):
            pattern_type = 'regex'
        elif WildcardRoute.like(pattern):
            pattern_type = 'wildcard'
        else:
            pattern_type = 'literal'
        return pattern_type, pattern

Return a normalized form of the pattern.

Normalize the pattern by removing pattern type prefix if it
exists in the pattern. Then return the pattern type and the
pattern as a tuple of two strings.

Arguments:
pattern (str): Route pattern to match request paths

Returns:
tuple: Ruple of pattern type (str) and pattern (str)


def trunc_normal_tf_(tensor: torch.Tensor, mean: float=0.0, std: float=1.0, a: float=-2.0, b: float=2.0) -> torch.Tensor:
    with torch.no_grad():
        _trunc_normal_(tensor, 0, 1.0, a, b)
        tensor.mul_(std).add_(mean)

Fills the input Tensor with values drawn from a truncated
normal distribution. The values are effectively drawn from the
normal distribution :math:`\mathcal{N}(     ext{mean},      ext{std}^2)`
with values outside :math:`[a, b]` redrawn until they are within
the bounds. The method used for generating the random values works
best when :math:`a \leq     ext{mean} \leq b`.

NOTE: this 'tf' variant behaves closer to Tensorflow / JAX impl where the
bounds [a, b] are applied when sampling the normal distribution with mean=0, std=1.0
and the result is subsequently scaled and shifted by the mean and std args.

Args:
tensor: an n-dimensional `torch.Tensor`
mean: the mean of the normal distribution
std: the standard deviation of the normal distribution
a: the minimum cutoff value
b: the maximum cutoff value


def serialize_example(transformed_json_data, info_dict):

  import six
  import tensorflow as tf

  def _make_int64_list(x):
    return tf.train.Feature(int64_list=tf.train.Int64List(value=x))
  def _make_bytes_list(x):
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=x))
  def _make_float_list(x):
    return tf.train.Feature(float_list=tf.train.FloatList(value=x))

  if sorted(six.iterkeys(transformed_json_data)) != sorted(six.iterkeys(info_dict)):
    raise ValueError('Keys do not match %s, %s' % (list(six.iterkeys(transformed_json_data)),
                     list(six.iterkeys(info_dict))))

  ex_dict = {}
  for name, info in six.iteritems(info_dict):
    if info['dtype'] == tf.int64:
      ex_dict[name] = _make_int64_list(transformed_json_data[name])
    elif info['dtype'] == tf.float32:
      ex_dict[name] = _make_float_list(transformed_json_data[name])
    elif info['dtype'] == tf.string:
      ex_dict[name] = _make_bytes_list(transformed_json_data[name])
    else:
      raise ValueError('Unsupported data type %s' % info['dtype'])

  ex = tf.train.Example(features=tf.train.Features(feature=ex_dict))
  return ex.SerializeToString()

Makes a serialized tf.example.

Args:
transformed_json_data: dict of transformed data.
info_dict: output of feature_transforms.get_transfrormed_feature_info()

Returns:
The serialized tf.example version of transformed_json_data.


def handle_document_error(self, item_session: ItemSession) -> Actions:
    self._waiter.increment()
    self._statistics.errors[ServerError] += 1
    action = self.handle_response(item_session)
    if (action == Actions.NORMAL):
        item_session.set_status(Status.error)
    return action

Callback for when the document only describes an server error.

Returns:
A value from :class:`.hook.Actions`.


def sort_prefixes(orig, prefixes='@+'):

    new = ''
    for prefix in prefixes:
        if prefix in orig:
            new += prefix
    return new

Returns a sorted list of prefixes.

Args:
orig (str): Unsorted list of prefixes.
prefixes (str): List of prefixes, from highest-priv to lowest.


def send_tpu_embedding_gradients(inputs, config, learning_rates=None, name=None):
    if learning_rates is None:
        learning_rates = []
    return gen_tpu_ops.send_tpu_embedding_gradients(inputs=inputs, learning_rates=learning_rates, config=config, name=name)

A placeholder op for feeding per-sample gradients to the embedding layer.

Args:
inputs: A TensorList of gradients with which to update embedding tables.
This argument has the same length and shapes as the return value of
RecvTPUEmbeddingActivations, but contains gradients of the model's loss
with respect to the embedding activations. The embedding tables are
updated from these gradients via the optimizers specified in the TPU
embedding configuration given to tpu.initialize_system.
config: Serialized TPUEmbeddingConfiguration proto.
learning_rates: A TensorList of float32 scalars, one for each dynamic
learning rate tag: see the comments in
//third_party/tensorflow/core/protobuf/tpu/
optimization_parameters.proto. Multiple tables can share the same
dynamic learning rate tag as specified in the configuration. If the
learning rates for all tables are constant, this list should be empty.
name: A name for the operation (optional).

Returns:
A SendTPUEmbeddingGradients operation.


def shift(self, time: int) -> 'Timeslot':
    return Timeslot(self.interval.shift(time), self.channel)

Return a new Timeslot shifted by `time`.

Args:
time: time to be shifted


def protein_only_and_noH(self, keep_ligands=None, force_rerun=False):
    log.debug('{}: running protein receptor isolation...'.format(self.id))
    if (not self.dockprep_path):
        return ValueError('Please run dockprep')
    receptor_mol2 = op.join(self.dock_dir, '{}_receptor.mol2'.format(self.id))
    receptor_noh = op.join(self.dock_dir, '{}_receptor_noH.pdb'.format(self.id))
    prly_com = op.join(self.dock_dir, 'prly.com')
    if ssbio.utils.force_rerun(flag=force_rerun, outfile=receptor_noh):
        with open(prly_com, 'w') as f:
            f.write('open {}\n'.format(self.dockprep_path))
            keep_str = 'delete ~protein'
            if keep_ligands:
                keep_ligands = ssbio.utils.force_list(keep_ligands)
                for res in keep_ligands:
                    keep_str += ' & ~:{} '.format(res)
            keep_str = (keep_str.strip() + '\n')
            f.write(keep_str)
            f.write('write format mol2 0 {}\n'.format(receptor_mol2))
            f.write('delete element.H\n')
            f.write('write format pdb 0 {}\n'.format(receptor_noh))
        cmd = 'chimera --nogui {}'.format(prly_com)
        os.system(cmd)
        os.remove(prly_com)
    if (ssbio.utils.is_non_zero_file(receptor_mol2) and ssbio.utils.is_non_zero_file(receptor_noh)):
        self.receptormol2_path = receptor_mol2
        self.receptorpdb_path = receptor_noh
        log.debug('{}: successful receptor isolation (mol2)'.format(self.receptormol2_path))
        log.debug('{}: successful receptor isolation (pdb)'.format(self.receptorpdb_path))
    else:
        log.critical('{}: protein_only_and_noH failed to run on dockprep file'.format(self.dockprep_path))

Isolate the receptor by stripping everything except protein and specified ligands.

Args:
keep_ligands (str, list): Ligand(s) to keep in PDB file
force_rerun (bool): If method should be rerun even if output file exists


def limit(self, accountID, **kwargs):

        return self.create(
            accountID,
            order=LimitOrderRequest(**kwargs)
        )

Shortcut to create a Limit Order in an Account

Args:
accountID : The ID of the Account
kwargs : The arguments to create a LimitOrderRequest

Returns:
v20.response.Response containing the results from submitting
the request


def unexpected_disconnect(self, conn_or_internal_id):

        data = {
            'id': conn_or_internal_id
        }

        action = ConnectionAction('force_disconnect', data, sync=False)
        self._actions.put(action)

Notify that there was an unexpected disconnection of the device.

Any in progress operations are canceled cleanly and the device is transitioned
to a disconnected state.

Args:
conn_or_internal_id (string, int): Either an integer connection id or a string
internal_id


def copy_update(pb_message, **kwds):
    result = pb_message.__class__()
    result.CopyFrom(pb_message)
    for (k, v) in kwds.items():
        setattr(result, k, v)
    return result

Returns a copy of the PB object, with some fields updated.

Args:
pb_message:
**kwds:

Returns:


def _extract_nn_info(self, structure, nns):
    if (self.targets is None):
        targets = structure.composition.elements
    else:
        targets = self.targets
    siw = []
    max_weight = max((nn[self.weight] for nn in nns.values()))
    for nstats in nns.values():
        site = nstats['site']
        if ((nstats[self.weight] > (self.tol * max_weight)) and self._is_in_targets(site, targets)):
            nn_info = {'site': site, 'image': self._get_image(structure, site), 'weight': (nstats[self.weight] / max_weight), 'site_index': self._get_original_site(structure, site)}
            if self.extra_nn_info:
                poly_info = nstats
                del poly_info['site']
                nn_info['poly_info'] = poly_info
            siw.append(nn_info)
    return siw

Given Voronoi NNs, extract the NN info in the form needed by NearestNeighbors

Args:
structure (Structure): Structure being evaluated
nns ([dicts]): Nearest neighbor information for a structure
Returns:
(list of tuples (Site, array, float)): See nn_info


def orthologize(ast, bo, species_id: str):
    if (not species_id):
        bo.validation_messages.append(('WARNING', 'No species id was provided for orthologization'))
        return ast
    if isinstance(ast, NSArg):
        if ast.orthologs:
            if ast.orthologs.get(species_id, None):
                orthologized_nsarg_val = ast.orthologs[species_id]['decanonical']
                (ns, value) = orthologized_nsarg_val.split(':')
                ast.change_nsvalue(ns, value)
                ast.canonical = ast.orthologs[species_id]['canonical']
                ast.decanonical = ast.orthologs[species_id]['decanonical']
                ast.orthologized = True
                bo.ast.species.add((species_id, ast.orthologs[species_id]['species_label']))
            else:
                bo.ast.species.add((ast.species_id, ast.species_label))
                bo.validation_messages.append(('WARNING', f'No ortholog found for {ast.namespace}:{ast.value}'))
        elif ast.species_id:
            bo.ast.species.add((ast.species_id, ast.species_label))
    if hasattr(ast, 'args'):
        for arg in ast.args:
            orthologize(arg, bo, species_id)
    return ast

Recursively orthologize BEL Entities in BEL AST using API endpoint

NOTE: - will take first ortholog returned in BEL.bio API result (which may return more than one ortholog)

Args:
ast (BEL): BEL AST
endpoint (str): endpoint url with a placeholder for the term_id

Returns:
BEL: BEL AST


def CreateSmartCampaign(client, budget_id, merchant_id):
    campaign_service = client.GetService('CampaignService', version='v201809')
    campaign = {'name': ('Shopping campaign
    campaign_operations = [{'operator': 'ADD', 'operand': campaign}]
    result = campaign_service.mutate(campaign_operations)['value'][0]
    print(('Smart Shopping campaign with name "%s" and ID "%s" was added.' % (result['name'], result['id'])))
    return result['id']

Adds a new Smart Shopping campaign.

Args:
client: an AdWordsClient instance.
budget_id: the str ID of the budget to be associated with the Shopping
campaign.
merchant_id: the str ID of the merchant account to be associated with the
Shopping campaign.
Returns:
A campaign ID.


def update_course(self, course, enterprise_customer, enterprise_context):
    course['course_runs'] = self.update_course_runs(course_runs=(course.get('course_runs') or []), enterprise_customer=enterprise_customer, enterprise_context=enterprise_context)
    marketing_url = course.get('marketing_url')
    if marketing_url:
        query_parameters = dict(enterprise_context, **utils.get_enterprise_utm_context(enterprise_customer))
        course.update({'marketing_url': utils.update_query_parameters(marketing_url, query_parameters)})
    course.update(enterprise_context)
    return course

Update course metadata of the given course and return updated course.

Arguments:
course (dict): Course Metadata returned by course catalog API
enterprise_customer (EnterpriseCustomer): enterprise customer instance.
enterprise_context (dict): Enterprise context to be added to course runs and URLs..

Returns:
(dict): Updated course metadata


def beam_row_from_dict(row: dict, schema):
    if not isinstance(schema, (bigquery.TableSchema, bigquery.TableFieldSchema)):
        schema = get_bq_tableschema(schema)
    beam_row = {}
    for field in schema.fields:
        name = field.name
        mode = field.mode.upper()
        type = field.type.upper()
        if name not in row and mode != 'REQUIRED':
            row[name] = None
        value = row[name]
        if type in ['RECORD', 'STRUCT'] and value:
            if mode == 'REPEATED':
                list_of_beam_rows = []
                for record in value:
                    list_of_beam_rows.append(beam_row_from_dict(record, field))
                beam_row[name] = list_of_beam_rows
            else:
                beam_row[name] = beam_row_from_dict(value, field)
        else:
            beam_row[name] = value
    return apache_beam.pvalue.Row(**beam_row)

Converts a dictionary row to a Beam Row.
Nested records and lists are supported.

Args:
row (dict):
The row to convert.
schema (str, dict, ~apache_beam.io.gcp.internal.clients.bigquery.bigquery_v2_messages.TableSchema):
The table schema. Will be used to help convert the row.

Returns:
~apache_beam.pvalue.Row: The converted row.


def match(self, message: Message) -> bool:
    if self.template:
        return self.template.match(message)
    return True

Matches a message with the behaviour's template

Args:
message(spade.message.Message): the message to match with

Returns:
bool: wheter the messaged matches or not


def write_data(worksheet, data):

    if not data:
        return

    if isinstance(data, list):
        rows = data
    else:
        rows = [data]

    if isinstance(rows[0], dict):
        keys = get_keys(rows)
        worksheet.append([utilities.convert_snake_to_title_case(key) for key in keys])
        for row in rows:
            values = [get_value_from_row(row, key) for key in keys]
            worksheet.append(values)
    elif isinstance(rows[0], list):
        for row in rows:
            values = [utilities.normalize_cell_value(value) for value in row]
            worksheet.append(values)
    else:
        for row in rows:
            worksheet.append([utilities.normalize_cell_value(row)])

Writes data into worksheet.

Args:
worksheet: worksheet to write into
data: data to be written


def crop_and_resize(image, boxes, box_ind, crop_size, pad_border=True):

    assert isinstance(crop_size, int), crop_size
    boxes = tf.stop_gradient(boxes)

    if pad_border:

        image = tf.pad(image, [[0, 0], [0, 0], [1, 1], [1, 1]], mode='SYMMETRIC')
        boxes = boxes + 1

    @under_name_scope()
    def transform_fpcoor_for_tf(boxes, image_shape, crop_shape):

        x0, y0, x1, y1 = tf.split(boxes, 4, axis=1)

        spacing_w = (x1 - x0) / tf.cast(crop_shape[1], tf.float32)
        spacing_h = (y1 - y0) / tf.cast(crop_shape[0], tf.float32)

        imshape = [tf.cast(image_shape[0] - 1, tf.float32), tf.cast(image_shape[1] - 1, tf.float32)]
        nx0 = (x0 + spacing_w / 2 - 0.5) / imshape[1]
        ny0 = (y0 + spacing_h / 2 - 0.5) / imshape[0]

        nw = spacing_w * tf.cast(crop_shape[1] - 1, tf.float32) / imshape[1]
        nh = spacing_h * tf.cast(crop_shape[0] - 1, tf.float32) / imshape[0]

        return tf.concat([ny0, nx0, ny0 + nh, nx0 + nw], axis=1)

    image_shape = tf.shape(image)[2:]
    boxes = transform_fpcoor_for_tf(boxes, image_shape, [crop_size, crop_size])
    image = tf.transpose(image, [0, 2, 3, 1])
    ret = tf.image.crop_and_resize(
        image, boxes, tf.cast(box_ind, tf.int32),
        crop_size=[crop_size, crop_size])
    ret = tf.transpose(ret, [0, 3, 1, 2])
    return ret

Aligned version of tf.image.crop_and_resize, following our definition of floating point boxes.

Args:
image: NCHW
boxes: nx4, x1y1x2y2
box_ind: (n,)
crop_size (int):
Returns:
n,C,size,size


def cn_occupation_energy( self, delta_occupation=None ):

        nn_occupations = self.site_specific_nn_occupation()
        if delta_occupation:
            for site in delta_occupation:
                assert( site in nn_occupations )
                nn_occupations[ site ] += delta_occupation[ site ]
        return sum( [ self.cn_occupation_energies[ s ][ n ] for s, n in nn_occupations.items() ] )

The coordination-number dependent energy for this site.

Args:
delta_occupation (:obj:Dict(Str:Int), optional): A dictionary of a change in (site-type specific) coordination number, e.g. { 'A' : 1, 'B' : -1 }.
If this is not None, the coordination-number dependent energy is calculated including these changes in neighbour-site occupations. Defaults to None

Returns:
(Float): The coordination-number dependent energy for this site.


def set_optimizer_experimental_options(self, options):
    self._optimizer_experimental_options.update(options)
    self._thread_local_data.function_call_options = None

Set experimental options for the optimizer.

Args:
options: Dictionary of options to modify


def update(self, span: typing.Tuple[(int, int)], line_type: LineType) -> None:
    (first_block_line, last_block_line) = span
    for i in range(first_block_line, (last_block_line + 1)):
        try:
            self.__setitem__(i, line_type)
        except ValueError as error:
            raise ValidationError((i + self.fn_offset), 1, 'AAA99 {}'.format(error))

Updates line types for a block's span.

Args:
span: First and last relative line number of a Block.
line_type: The type of line to update to.

Raises:
ValidationError: A special error on collision. This prevents Flake8
from crashing because it is converted to a Flake8 error tuple,
but it indicates to the user that something went wrong with
processing the function.


def torus(script, major_radius=3.0, minor_radius=1.0, inner_diameter=None, outer_diameter=None, major_segments=48, minor_segments=12, color=None):
    if ((inner_diameter is not None) and (outer_diameter is not None)):
        major_radius = ((inner_diameter + outer_diameter) / 4)
        minor_radius = (major_radius - (inner_diameter / 2))
    filter_xml = ''.join(['  <filter name="Torus">\n', '    <Param name="hRadius" ', ('value="%s" ' % major_radius), 'description="Horizontal Radius" ', 'type="RichFloat" ', '/>\n', '    <Param name="vRadius" ', ('value="%s" ' % minor_radius), 'description="Vertical Radius" ', 'type="RichFloat" ', '/>\n', '    <Param name="hSubdiv" ', ('value="%d" ' % major_segments), 'description="Horizontal Subdivision" ', 'type="RichInt" ', '/>\n', '    <Param name="vSubdiv" ', ('value="%d" ' % minor_segments), 'description="Vertical Subdivision" ', 'type="RichInt" ', '/>\n', '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, FilterScript):
        script.add_layer('Torus', change_layer=True)
    if (color is not None):
        vert_color.function(script, color=color)
    return None

Create a torus mesh

Args:
major_radius (float, (optional)): radius from the origin to the
center of the cross sections
minor_radius (float, (optional)): radius of the torus cross
section
inner_diameter (float, (optional)): inner diameter of torus. If
both inner_diameter and outer_diameter are provided then
these will override major_radius and minor_radius.,
outer_diameter (float, (optional)): outer diameter of torus. If
both inner_diameter and outer_diameter are provided then
these will override major_radius and minor_radius.
major_segments (int (optional)): number of segments for the main
ring of the torus
minor_segments (int (optional)): number of segments for the minor
ring of the torus
color (str (optional)): color name to apply vertex colors to the
newly created mesh

Returns:
None


def validate(tmpl, path):
    pattern = (_generate_pattern_for_template(tmpl) + '$')
    return (True if (re.match(pattern, path) is not None) else False)

Validate a path against the path template.

.. code-block:: python

>>> validate('users/*/messages/*', 'users/me/messages/123')
True
>>> validate('users/*/messages/*', 'users/me/drafts/123')
False
>>> validate('/v1/{name=shelves/*/books/*}', /v1/shelves/1/books/3)
True
>>> validate('/v1/{name=shelves/*/books/*}', /v1/shelves/1/tapes/3)
False

Args:
tmpl (str): The path template.
path (str): The expanded path.

Returns:
bool: True if the path matches.


def format_image_annotations_as_coco(image_id: str, categories: list[int], areas: list[float], bboxes: list[tuple[float]]) -> dict:
    annotations = []
    for category, area, bbox in zip(categories, areas, bboxes):
        formatted_annotation = {'image_id': image_id, 'category_id': category, 'iscrowd': 0, 'area': area, 'bbox': list(bbox)}
        annotations.append(formatted_annotation)
    return {'image_id': image_id, 'annotations': annotations}

Format one set of image annotations to the COCO format

Args:
image_id (str): image id. e.g. "0001"
categories (List[int]): list of categories/class labels corresponding to provided bounding boxes
areas (List[float]): list of corresponding areas to provided bounding boxes
bboxes (List[Tuple[float]]): list of bounding boxes provided in COCO format
([center_x, center_y, width, height] in absolute coordinates)

Returns:
dict: {
"image_id": image id,
"annotations": list of formatted annotations
}


def wait(animation='elipses', text='', speed=0.2):

    def decorator(func):
        func.animation = animation
        func.speed = speed
        func.text = text

        @wraps(func)
        def wrapper(*args, **kwargs):
            animation = func.animation
            text = func.text
            if ((not isinstance(animation, (list, tuple))) and (not hasattr(animations, animation))):
                text = (animation if (text == '') else text)
                animation = 'elipses'
            wait = Wait(animation=animation, text=text, speed=func.speed)
            wait.start()
            try:
                ret = func(*args, **kwargs)
            finally:
                wait.stop()
            sys.stdout.write('\n')
            return ret
        return wrapper
    return decorator

Decorator for adding wait animation to long running
functions.

Args:
animation (str, tuple): String reference to animation or tuple
with custom animation.
speed (float): Number of seconds each cycle of animation.

Examples:
>>> @animation.wait('bar')
>>> def long_running_function():
>>>     ... 5 seconds later ...
>>>     return


def clear(self, name=None):
    if name is None:
        name = '%s_clear' % self._name
    return gen_data_flow_ops.stage_clear(name=name, shared_name=self._name, dtypes=self._dtypes, capacity=self._capacity, memory_limit=self._memory_limit)

Clears the staging area.

Args:
name: A name for the operation (optional)

Returns:
The created op


def asserts_truth(func):
    if re.match('_[^_]', func.__name__):
        raise AttributeError('@asserts_truth may not be applied to methods beginning with "_".')

    def AssertThat(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except TruthAssertionError as truth_assertion:
            if hasattr(truth_assertion, 'with_traceback'):
                truth_assertion.with_traceback(None)
                raise truth_assertion
            raise
    return AssertThat

Decorator for every public method that might raise TruthAssertionError.

Args:
func: the function to be decorated.

Returns:
The decorated function. In Python 2, the function behaves identically.
Otherwise, if that function raises a TruthAssertionError, then that error
is re-raised with a modified, minimal traceback.

Raises:
AttributeError: if attempted to be applied to a method whose name begins
with a single '_'. This decorator's purpose is to reduce the traceback
depth of exceptions raised by nested calls in this library, so that the
failing assertion has only two frames: the original AssertThat() call,
and the "raise truth_assertion" in the decorated function.
Annotating inner method calls is contrary to that goal.


def _import_module_by_name(self, module_name) -> _AST | None:
    existing = self._modules.get_existing_ast(module_name)
    if existing:
        return existing
    assert path_utils.sep not in module_name, (path_utils.sep, module_name)
    log.debug('Trying to import %r', module_name)
    mod = self._load_builtin('builtins', module_name)
    if mod:
        return mod
    mod_ast = None
    default = None
    mod_info = self._module_loader.find_import(module_name)
    if mod_info:
        if mod_info.file_exists:
            mod_ast = self.load_module(mod_info)
            assert mod_ast is not None, mod_info.filename
        else:
            mod_ast = self._create_empty(mod_info)
        if mod_info.is_default_pyi():
            default = self._modules.get(module_name)
            del self._modules[module_name]
        elif module_name in _ALWAYS_PREFER_TYPESHED:
            del self._modules[module_name]
        else:
            return mod_ast
    mod = self._load_builtin('stdlib', module_name)
    if mod:
        return mod
    mod = self._load_builtin('third_party', module_name)
    if mod:
        return mod
    if mod_ast:
        assert default
        self._modules[module_name] = default
        return mod_ast
    return None

Load a name like 'sys' or 'foo.bar.baz'.

Args:
module_name: The name of the module. May contain dots.

Returns:
The parsed file, instance of pytd.TypeDeclUnit, or None if we
the module wasn't found.


def CreateClass(cls, data_type_definition):

    cls._ValidateDataTypeDefinition(data_type_definition)

    class_definition = cls._CreateClassTemplate(data_type_definition)

    namespace = {
        '__builtins__' : {
            'object': builtins.object,
            'super': builtins.super},
        '__name__': '{0:s}'.format(data_type_definition.name)}

    if sys.version_info[0] >= 3:

      namespace['__builtins__']['__build_class__'] = builtins.__build_class__

    exec(class_definition, namespace)

    return namespace[data_type_definition.name]

Creates a new structure values class.

Args:
data_type_definition (DataTypeDefinition): data type definition.

Returns:
class: structure values class.


def parse(source):

    if isinstance(source, str):
        return parse_stream(six.StringIO(source))
    else:
        return parse_stream(source)

Parses source code returns an array of instructions suitable for
optimization and execution by a Machine.

Args:
source: A string or stream containing source code.


def load_genes(path):

    with open(path, 'rt') as f:
        lines = [ x.split('\t')[:2] for x in f if not x.startswith('hgnc') ]

    transcripts = {}
    for symbol, tx in lines:
        if symbol not in transcripts:
            transcripts[symbol] = []
        transcripts[symbol].append(tx)

    return transcripts

load a file listing gene and transcript IDs

Args:
path: path to file containing gene IDs and transcript IDs e.g.
gene_1    transcript_1.1    length_1    denovo_count
gene_2    transcript_2.1    length_3    denovo_count

Returns:
dict of transcripts eg {'CTC1': ["ENST00000315684", "ENST00000485511"]}


def delete(self, customer_id, token_id, data={}, **kwargs):

        url = "{}/{}/tokens/{}".format(self.base_url, customer_id, token_id)
        return self.delete_url(url, data, **kwargs)

Delete Given Token For a Customer

Args:
customer_id : Customer Id for which tokens have to be deleted
token_id    : Id for which TOken object has to be deleted
Returns:
Dict for deleted token


def delete(self, resource_id):
    endpoint = '{}/{}'.format(self.endpoint, resource_id)
    response = self.api.execute('DELETE', endpoint)
    if (not response.ok):
        raise Error.parse(response.json())
    return self._cls.parse(response.json())

Deletes an existing resource

Args:
resource_id - int - The resource ID to be deleted


def dict_of_sets_add(dictionary, key, value):
    set_objs = dictionary.get(key, set())
    set_objs.add(value)
    dictionary[key] = set_objs

Add value to a set in a dictionary by key

Args:
dictionary (DictUpperBound): Dictionary to which to add values
key (Any): Key within dictionary
value (Any): Value to add to set in dictionary

Returns:
None


def validate_all_keys(obj_name, obj, validation_fun):

    for key, value in obj.items():
        validation_fun(obj_name, key)
        if isinstance(value, dict):
            validate_all_keys(obj_name, value, validation_fun)

Validate all (nested) keys in `obj` by using `validation_fun`.

Args:
obj_name (str): name for `obj` being validated.
obj (dict): dictionary object.
validation_fun (function): function used to validate the value
of `key`.

Returns:
None: indicates validation successful

Raises:
ValidationError: `validation_fun` will raise this error on failure


def path_status(path, filename='', status=None, verbosity=0):

    status = status or {}
    if not filename:
        dir_path, filename = os.path.split()
    else:
        dir_path = path
    full_path = os.path.join(dir_path, filename)
    if verbosity > 1:
        print(full_path)
    status['name'] = filename
    status['path'] = full_path
    status['dir'] = dir_path
    status['type'] = []
    try:
        status['size'] = os.path.getsize(full_path)
        status['accessed'] = datetime.datetime.fromtimestamp(os.path.getatime(full_path))
        status['modified'] = datetime.datetime.fromtimestamp(os.path.getmtime(full_path))
        status['created'] = datetime.datetime.fromtimestamp(os.path.getctime(full_path))
        status['mode'] = os.stat(full_path).st_mode
        if os.path.ismount(full_path):
            status['type'] += ['mount-point']
        elif os.path.islink(full_path):
            status['type'] += ['symlink']
        if os.path.isfile(full_path):
            status['type'] += ['file']
        elif os.path.isdir(full_path):
            status['type'] += ['dir']
        if not status['type']:
            if os.stat.S_ISSOCK(status['mode']):
                status['type'] += ['socket']
            elif os.stat.S_ISCHR(status['mode']):
                status['type'] += ['special']
            elif os.stat.S_ISBLK(status['mode']):
                status['type'] += ['block-device']
            elif os.stat.S_ISFIFO(status['mode']):
                status['type'] += ['pipe']
        if not status['type']:
            status['type'] += ['unknown']
        elif status['type'] and status['type'][-1] == 'symlink':
            status['type'] += ['broken']
    except OSError:
        status['type'] = ['nonexistent'] + status['type']
        if verbosity > -1:
            warnings.warn("Unable to stat path '{}'".format(full_path))
    status['type'] = '->'.join(status['type'])

    return status

Retrieve the access, modify, and create timetags for a path along with its size

Arguments:
path (str): full path to the file or directory to be statused
status (dict): optional existing status to be updated/overwritten with new status values

Returns:
dict: {'size': bytes (int), 'accessed': (datetime), 'modified': (datetime), 'created': (datetime)}


def _PrintTasksInformation(self, storage_reader):
    table_view = views.ViewsFactory.GetTableView(self._views_format_type, title='Tasks')
    for (task_start, _) in storage_reader.GetSessions():
        start_time = timelib.Timestamp.CopyToIsoFormat(task_start.timestamp)
        task_identifier = uuid.UUID(hex=task_start.identifier)
        task_identifier = '{0!s}'.format(task_identifier)
        table_view.AddRow([task_identifier, start_time])
    table_view.Write(self._output_writer)

Prints information about the tasks.

Args:
storage_reader (StorageReader): storage reader.


def forward(self, hidden_states: torch.FloatTensor, attention_masks: Optional[torch.BoolTensor]=None, position_embeddings: Optional[torch.FloatTensor]=None) -> Tuple[torch.FloatTensor, torch.FloatTensor]:
    if attention_masks.dim() == 3 and attention_masks.shape[0] == hidden_states.shape[0]:
        attention_masks = attention_masks[:, None, :, :]
        attention_masks = attention_masks.repeat(1, self.num_heads, 1, 1)
        dtype = hidden_states.dtype
        attention_masks = attention_masks.to(dtype=dtype)
        attention_masks = (1.0 - attention_masks) * torch.finfo(dtype).min
    queries = keys = self.with_pos_embed(hidden_states, position_embeddings)
    attention_output, attention_weights = self.self_attn(queries=queries, keys=keys, values=hidden_states, attention_mask=attention_masks, output_attentions=True)
    attention_output = nn.functional.dropout(attention_output, p=self.dropout, training=self.training)
    hidden_states = hidden_states + attention_output
    hidden_states = self.layer_norm_before(hidden_states)
    residual = hidden_states
    hidden_states = self.activation(self.fc1(hidden_states))
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = hidden_states + residual
    hidden_states = self.layer_norm_after(hidden_states)
    return (hidden_states, attention_weights)

Text self-attention to enhance projection of text features generated by
the text encoder (AutoModel based on text_config) within GroundingDinoEncoderLayer

Args:
hidden_states (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_dim)`):
Text features generated by the text encoder.
attention_masks (`torch.BoolTensor`, *optional*):
Attention mask for text self-attention. False for real tokens and True for padding tokens.
position_embeddings (`torch.FloatTensor`, *optional*):
Position embeddings to be added to the hidden states.

Returns:
`tuple(torch.FloatTensor)` comprising two elements:
- **hidden_states** (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`) --
Output of the text self-attention layer.
- **attention_weights** (`torch.FloatTensor` of shape `(batch_size, num_heads, sequence_length,
sequence_length)`) --
Attention weights of the text self-attention layer.


def _getH2singleTrait(self, K, verbose=None):

        verbose = dlimix.getVerbose(verbose)

        varg  = sp.zeros(self.P)
        varn  = sp.zeros(self.P)
        fixed = sp.zeros((1,self.P))

        for p in range(self.P):
            y = self.Y[:,p:p+1]

            I  = sp.isnan(y[:,0])
            if I.sum()>0:
                y  = y[~I,:]
                _K = K[~I,:][:,~I]
            else:
                _K  = copy.copy(K)
            lmm = dlimix.CLMM()
            lmm.setK(_K)
            lmm.setSNPs(sp.ones((y.shape[0],1)))
            lmm.setPheno(y)
            lmm.setCovs(sp.zeros((y.shape[0],1)))
            lmm.setVarcompApprox0(-20, 20, 1000)
            lmm.process()
            delta = sp.exp(lmm.getLdelta0()[0,0])
            Vtot  = sp.exp(lmm.getLSigma()[0,0])

            varg[p] = Vtot
            varn[p] = delta*Vtot
            fixed[:,p] = lmm.getBetaSNP()

            if verbose: print(p)

        sth = {}
        sth['varg']  = varg
        sth['varn']  = varn
        sth['fixed'] = fixed

        return sth

Internal function for parameter initialization
estimate variance components and fixed effect using a linear mixed model with an intercept and 2 random effects (one is noise)
Args:
K:        covariance matrix of the non-noise random effect term


def insert_system(cur, system_name, encoded_data=None):
    if (encoded_data is None):
        encoded_data = {}
    if ('system_name' not in encoded_data):
        encoded_data['system_name'] = system_name
    insert = 'INSERT OR IGNORE INTO system(system_name) VALUES (:system_name);'
    cur.execute(insert, encoded_data)

Insert a system name into the cache.

Args:
cur (:class:`sqlite3.Cursor`):
An sqlite3 cursor. This function is meant to be run within a :obj:`with` statement.

system_name (str):
The unique name of a system

encoded_data (dict, optional):
If a dictionary is provided, it will be populated with the serialized data. This is
useful for preventing encoding the same information many times.


def energy_prof(step):

    diff, rad = diffs_prof(step)
    adv, _ = advts_prof(step)
    return (diff + np.append(adv, 0)), rad

Energy flux.

This computation takes sphericity into account if necessary.

Args:
step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData
instance.
Returns:
tuple of :class:`numpy.array`: the energy flux and the radial position
at which it is evaluated.


def trace_read(self, offset, num_items):
    buf_size = ctypes.c_uint32(num_items)
    buf = (structs.JLinkTraceData * num_items)()
    res = self._dll.JLINKARM_TRACE_Read(buf, int(offset), ctypes.byref(buf_size))
    if (res == 1):
        raise errors.JLinkException('Failed to read from trace buffer.')
    return list(buf)[:int(buf_size.value)]

Reads data from the trace buffer and returns it.

Args:
self (JLink): the ``JLink`` instance.
offset (int): the offset from which to start reading from the trace
buffer.
num_items (int): number of items to read from the trace buffer.

Returns:
A list of ``JLinkTraceData`` instances corresponding to the items
read from the trace buffer.  Note that this list may have size less
than ``num_items`` in the event that there are not ``num_items``
items in the trace buffer.

Raises:
JLinkException: on error.


def set_redirect(self, url, status=HttpStatusCodes.HTTP_303):
    self.set_status(status)
    self.set_content('')
    self.set_header(HttpResponseHeaders.LOCATION, url)

Helper method to set a redirect response.

Args:
url (:obj:`str`): URL to redirect to
status (:obj:`str`, optional): Status code of the response


def _check_keyword_parentheses(self, tokens, start):
    if (self._inside_brackets(':') and (tokens[start][1] == 'for')):
        self._pop_token()
    if (tokens[(start + 1)][1] != '('):
        return
    found_and_or = False
    depth = 0
    keyword_token = str(tokens[start][1])
    line_num = tokens[start][2][0]
    for i in range(start, (len(tokens) - 1)):
        token = tokens[i]
        if (token[0] == tokenize.NL):
            return
        if (token[1] == '('):
            depth += 1
        elif (token[1] == ')'):
            depth -= 1
            if depth:
                continue
            if ((tokens[(i + 1)][1] in (':', ')', ']', '}', 'in')) or (tokens[(i + 1)][0] in (tokenize.NEWLINE, tokenize.ENDMARKER, tokenize.COMMENT))):
                if (i == (start + 2)):
                    return
                if (keyword_token == 'not'):
                    if (not found_and_or):
                        self.add_message('superfluous-parens', line=line_num, args=keyword_token)
                elif (keyword_token in ('return', 'yield')):
                    self.add_message('superfluous-parens', line=line_num, args=keyword_token)
                elif (keyword_token not in self._keywords_with_parens):
                    if (not found_and_or):
                        self.add_message('superfluous-parens', line=line_num, args=keyword_token)
            return
        elif (depth == 1):
            if (token[1] == ','):
                return
            if (token[1] in ('and', 'or')):
                found_and_or = True
            elif (token[1] == 'yield'):
                return
            elif (token[1] == 'for'):
                return

Check that there are not unnecessary parens after a keyword.

Parens are unnecessary if there is exactly one balanced outer pair on a
line, and it is followed by a colon, and contains no commas (i.e. is not a
tuple).

Args:
tokens: list of Tokens; the entire list of Tokens.
start: int; the position of the keyword in the token list.


def user_list_membership(self, username, member_type='USER', recursive=True, max_return_count=999):
    return self.client.service.getUserListMembership(username, member_type, recursive, max_return_count, self.proxy_id)

Get info for lists a user is a member of.

This is similar to :meth:`user_lists` but with a few differences:

#. It returns list info objects instead of list names.
#. It has an option to fully resolve a user's list hierarchy. That
is, if a user is a member of a nested list, this method can
retrieve both the nested list and the parent lists that contain
the nested list.

Args:
username (str): The MIT username of the user
member_type(str): The type of user, "USER" or "STRING"
recursive(bool): Whether to fully resolve the list hierarchy
max_return_count(int): limit the number of items returned

Returns:
list of dicts: info dicts, one per list.


def handle_run_exception(self, pipeline_key, pipeline_func, e):
    if isinstance(e, Retry):
        retry_message = str(e)
        logging.warning('User forced retry for pipeline ID "%s" of %r: %s', pipeline_key.name(), pipeline_func, retry_message)
        self.transition_retry(pipeline_key, retry_message)
    elif isinstance(e, Abort):
        abort_message = str(e)
        logging.warning('User forced abort for pipeline ID "%s" of %r: %s', pipeline_key.name(), pipeline_func, abort_message)
        pipeline_func.abort(abort_message)
    else:
        retry_message = ('%s: %s' % (e.__class__.__name__, str(e)))
        logging.exception('Generator %r
        self.transition_retry(pipeline_key, retry_message)
    return pipeline_func.task_retry

Handles an exception raised by a Pipeline's user code.

Args:
pipeline_key: The pipeline that raised the error.
pipeline_func: The class path name of the Pipeline that was running.
e: The exception that was raised.

Returns:
True if the exception should be re-raised up through the calling stack
by the caller of this method.


def add_group_coordinator(self, group, response):

        log.debug("Updating coordinator for %s: %s", group, response)
        error_type = Errors.for_code(response.error_code)
        if error_type is not Errors.NoError:
            log.error("GroupCoordinatorResponse error: %s", error_type)
            self._groups[group] = -1
            return False

        node_id = response.coordinator_id
        coordinator = BrokerMetadata(
            response.coordinator_id,
            response.host,
            response.port,
            None)

        if node_id not in self._brokers:
            self._brokers[node_id] = coordinator

        else:
            node = self._brokers[node_id]
            if coordinator.host != node.host or coordinator.port != node.port:
                log.error("GroupCoordinator metadata conflicts with existing"
                          " broker metadata. Coordinator: %s, Broker: %s",
                          coordinator, node)
                self._groups[group] = node_id
                return False

        log.info("Group coordinator for %s is %s", group, coordinator)
        self._groups[group] = node_id
        return True

Update with metadata for a group coordinator

Arguments:
group (str): name of group from GroupCoordinatorRequest
response (GroupCoordinatorResponse): broker response

Returns:
bool: True if metadata is updated, False on error


def percent_point(self, U):
    self.check_fit()
    return norm.ppf(U, loc=self.mean, scale=self.std)

Given a cumulated distribution value, returns a value in original space.

Arguments:
U: `np.ndarray` of shape (n, 1) and values in [0,1]

Returns:
`np.ndarray`: Estimated values in original space.


def update_refresh_state(self, id_or_uri, refresh_state_data):

        uri = self._client.build_uri(id_or_uri) + "/refreshState"
        return self._client.update(refresh_state_data, uri=uri)

Refreshes a given intelligent power delivery device.

Args:
id_or_uri:
Can be either the power device id or the uri
refresh_state_data:
Power device refresh request

Returns:
str: The power state


def get_effect_class(self, effect_name: str, package_name: str=None) -> Type['Effect']:
    return self._project.get_effect_class(effect_name, package_name=package_name)

Get an effect class by the class name

Args:
effect_name (str): Name of the effect class

Keyword Args:
package_name (str): The package the effect belongs to. This is optional and only
needed when effect class names are not unique.

Returns:
:py:class:`Effect` class


def _split_result_for_readers(axis, num_splits, df):
    splits = split_result_of_axis_func_pandas(axis, num_splits, df)
    if (not isinstance(splits, list)):
        splits = [splits]
    return splits

Splits the DataFrame read into smaller DataFrames and handles all edge cases.

Args:
axis: Which axis to split over.
num_splits: The number of splits to create.
df: The DataFrame after it has been read.

Returns:
A list of pandas DataFrames.


def _build_predicate_for_coding_in_value_set(self, expanded_value_set: value_set_pb2.ValueSet, coding_column: Optional[_sql_data_types.Identifier]=None) -> _sql_data_types.StandardSqlExpression:
    codes_per_system = {}
    for concept in expanded_value_set.expansion.contains:
        codes_per_system.setdefault(concept.system.value, []).append(concept.code.value)
    codes_per_system = list(codes_per_system.items())
    codes_per_system.sort(key=operator.itemgetter(0))
    for _, codes in codes_per_system:
        codes.sort()
    if coding_column is None:
        code_col = _sql_data_types.Identifier('code', _sql_data_types.String)
        system_col = _sql_data_types.Identifier('system', _sql_data_types.String)
    else:
        code_col = coding_column.dot('code', _sql_data_types.String)
        system_col = coding_column.dot('system', _sql_data_types.String)
    code_system_predicates = []
    for system, codes in codes_per_system:
        system = _sql_data_types.RawExpression('"%s"' % system, _sql_data_types.String)
        codes = [_sql_data_types.RawExpression('"%s"' % code, _sql_data_types.String) for code in codes]
        code_system_predicates.append(system_col.eq_(system).and_(code_col.in_(codes)))
    return functools.reduce(lambda acc, pred: acc.or_(pred), code_system_predicates)

Builds a predicate asserting the coding column is bound to the value_set.

Ensures that the codings contained in `coding_column` are codings found in
`expanded_value_set`.
Produces SQL like:
(`coding_column`.system = system1 AND `coding_column`.code IN (
code1, code2)) OR
(`coding_column`.system = system2 AND `coding_column`.code IN (
code3, code4))

Args:
expanded_value_set: The expanded value set containing the coding values to
assert membership against.
coding_column: The column containing the coding values. If given, columns
`coding_column`.system and `coding_column`.code will be referenced in
the predicate. If not given, columns 'system' and 'code' will be
referenced.

Returns:
The SQL for the value set binding predicate.


def load_hgnc_bulk(self, gene_objs):
    LOG.info('Loading gene bulk with length %s', len(gene_objs))
    try:
        result = self.hgnc_collection.insert_many(gene_objs)
    except (DuplicateKeyError, BulkWriteError) as err:
        raise IntegrityError(err)
    return result

Load a bulk of hgnc gene objects

Raises IntegrityError if there are any write concerns

Args:
gene_objs(iterable(scout.models.hgnc_gene))

Returns:
result (pymongo.results.InsertManyResult)


def set_sig_figs(n=4):

    u.default_format = '.' + str(n) + 'g'
    pd.options.display.float_format = ('{:,.' + str(n) + '}').format

Set the number of significant figures used to print Pint, Pandas, and
NumPy quantities.

Args:
n (int): Number of significant figures to display.


def firmware_version(self):
    buf = (ctypes.c_char * self.MAX_BUF_SIZE)()
    self._dll.JLINKARM_GetFirmwareString(buf, self.MAX_BUF_SIZE)
    return ctypes.string_at(buf).decode()

Returns a firmware identification string of the connected J-Link.

It consists of the following:
- Product Name (e.g. J-Link)
- The string: compiled
- Compile data and time.
- Optional additional information.

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

Returns:
Firmware identification string.


def label(self, input_grid):
    unset = 0
    (high_labels, num_labels) = label((input_grid > self.high_thresh))
    region_ranking = np.argsort(maximum(input_grid, high_labels, index=np.arange(1, (num_labels + 1))))[::(- 1)]
    output_grid = np.zeros(input_grid.shape, dtype=int)
    stack = []
    for rank in region_ranking:
        label_num = (rank + 1)
        (label_i, label_j) = np.where((high_labels == label_num))
        for i in range(label_i.size):
            if (output_grid[(label_i[i], label_j[i])] == unset):
                stack.append((label_i[i], label_j[i]))
        while (len(stack) > 0):
            index = stack.pop()
            output_grid[index] = label_num
            for i in range((index[0] - 1), (index[0] + 2)):
                for j in range((index[1] - 1), (index[1] + 2)):
                    if ((0 <= i < output_grid.shape[0]) and (0 <= j < output_grid.shape[1])):
                        if ((input_grid[(i, j)] > self.low_thresh) and (output_grid[(i, j)] == unset)):
                            stack.append((i, j))
    return output_grid

Label input grid with hysteresis method.

Args:
input_grid: 2D array of values.

Returns:
Labeled output grid.


def _apply(self, ctx: ExtensionContext) -> Any:
    (_, external_path) = ctx.node
    return ctx.mentor.load_yaml(self.locator(external_path, (cast(str, ctx.document) if Validator.is_file(document=ctx.document) else None)))

Loads a yaml fragment from an external file.

Args:
ctx: The processing context.

Returns:
The external resource as a python dictionary. The fragment is already send through
the processor as well.


def unhide_tool(self, context_name, tool_name):
    data = self._context(context_name)
    hidden_tools = data['hidden_tools']
    if (tool_name in hidden_tools):
        hidden_tools.remove(tool_name)
        self._flush_tools()

Unhide a tool so that it may be exposed in a suite.

Note that unhiding a tool doesn't guarantee it can be seen - a tool of
the same name from a different context may be overriding it.

Args:
context_name (str): Context containing the tool.
tool_name (str): Name of tool to unhide.


def _send_offset_commit_request(self, offsets):
    assert (self.config['api_version'] >= (0, 8, 1)), 'Unsupported Broker API'
    assert all(map((lambda k: isinstance(k, TopicPartition)), offsets))
    assert all(map((lambda v: isinstance(v, OffsetAndMetadata)), offsets.values()))
    if (not offsets):
        log.debug('No offsets to commit')
        return Future().success(None)
    node_id = self.coordinator()
    if (node_id is None):
        return Future().failure(Errors.GroupCoordinatorNotAvailableError)
    offset_data = collections.defaultdict(dict)
    for (tp, offset) in six.iteritems(offsets):
        offset_data[tp.topic][tp.partition] = offset
    if self._subscription.partitions_auto_assigned():
        generation = self.generation()
    else:
        generation = Generation.NO_GENERATION
    if ((self.config['api_version'] >= (0, 9)) and (generation is None)):
        return Future().failure(Errors.CommitFailedError())
    if (self.config['api_version'] >= (0, 9)):
        request = OffsetCommitRequest[2](self.group_id, generation.generation_id, generation.member_id, OffsetCommitRequest[2].DEFAULT_RETENTION_TIME, [(topic, [(partition, offset.offset, offset.metadata) for (partition, offset) in six.iteritems(partitions)]) for (topic, partitions) in six.iteritems(offset_data)])
    elif (self.config['api_version'] >= (0, 8, 2)):
        request = OffsetCommitRequest[1](self.group_id, (- 1), '', [(topic, [(partition, offset.offset, (- 1), offset.metadata) for (partition, offset) in six.iteritems(partitions)]) for (topic, partitions) in six.iteritems(offset_data)])
    elif (self.config['api_version'] >= (0, 8, 1)):
        request = OffsetCommitRequest[0](self.group_id, [(topic, [(partition, offset.offset, offset.metadata) for (partition, offset) in six.iteritems(partitions)]) for (topic, partitions) in six.iteritems(offset_data)])
    log.debug('Sending offset-commit request with %s for group %s to %s', offsets, self.group_id, node_id)
    future = Future()
    _f = self._client.send(node_id, request)
    _f.add_callback(self._handle_offset_commit_response, offsets, future, time.time())
    _f.add_errback(self._failed_request, node_id, request, future)
    return future

Commit offsets for the specified list of topics and partitions.

This is a non-blocking call which returns a request future that can be
polled in the case of a synchronous commit or ignored in the
asynchronous case.

Arguments:
offsets (dict of {TopicPartition: OffsetAndMetadata}): what should
be committed

Returns:
Future: indicating whether the commit was successful or not


def _AssignVar(self, matched, value):

    _value = self._GetValue(value)
    if _value is not None:
        _value.AssignVar(matched.group(value))

Assigns variable into current record from a matched rule.

If a record entry is a list then append, otherwise values are replaced.

Args:
matched: (regexp.match) Named group for each matched value.
value: (str) The matched value.


def __init__(self, latitude, longitude, units='metric',
                 angle='degrees', timezone=0, time=None):

        super(TimedPoint, self).__init__(latitude, longitude, units, angle,
                                         timezone)
        self.time = time

Initialise a new ``TimedPoint`` object.

Args:
latitude (float, tuple or list): Location's latitude
longitude (float, tuple or list): Location's longitude
angle (str): Type for specified angles
units (str): Units type to be used for distances
timezone (int): Offset from UTC in minutes
time (datetime.datetime): Time associated with the location


def _find_countour_yaml(start, checked, names=None):
    extensions = []
    if names:
        for name in names:
            if (not os.path.splitext(name)[1]):
                extensions.append((name + '.yaml'))
                extensions.append((name + '.yml'))
    yaml_names = (((names or []) + CONTOUR_YAML_NAMES) + extensions)
    directory = start
    while (directory not in checked):
        checked.add(directory)
        for fs_yaml_name in yaml_names:
            yaml_path = os.path.join(directory, fs_yaml_name)
            if os.path.exists(yaml_path):
                return yaml_path
        directory = os.path.dirname(directory)
    return

Traverse the directory tree identified by start
until a directory already in checked is encountered or the path
of countour.yaml is found.

Checked is present both to make the loop termination easy
to reason about and so the same directories do not get
rechecked

Args:
start: the path to start looking in and work upward from
checked: the set of already checked directories

Returns:
the path of the countour.yaml file or None if it is not found


def _convert_id_to_token(self, token_id: int) -> list:
    token_type_value = self.decoder.get(token_id, f'{self.unk_token}_TOKEN_TIME')
    token_type_value = token_type_value.split('_')
    token_type, value = ('_'.join(token_type_value[1:]), int(token_type_value[0]))
    return [token_type, value]

Decodes the token ids generated by the transformer into notes.

Args:
token_id (`int`):
This denotes the ids generated by the transformers to be converted to Midi tokens.

Returns:
`List`: A list consists of token_type (`str`) and value (`int`).


def compare(array, other, op, ty_str):
    weld_obj = WeldObject(encoder_, decoder_)
    array_var = weld_obj.update(array)
    if isinstance(array, WeldObject):
        array_var = array.obj_id
        weld_obj.dependencies[array_var] = array
    if (isinstance(other, str) or isinstance(other, WeldObject)):
        other_var = weld_obj.update(other)
        if isinstance(other, WeldObject):
            other_var = tmp.obj_id
            weld_obj.dependencies[other_var] = other
    else:
        other_var = ('%s(%s)' % (ty_str, str(other)))
    weld_template = '\n       map(\n         %(array)s,\n         |a: %(ty)s| a %(op)s %(other)s\n       )\n    '
    weld_obj.weld_code = (weld_template % {'array': array_var, 'other': other_var, 'op': op, 'ty': ty_str})
    return weld_obj

Performs passed-in comparison op between every element in the passed-in
array and other, and returns an array of booleans.

Args:
array (WeldObject / Numpy.ndarray): Input array
other (WeldObject / Numpy.ndarray): Second input array
op (str): Op string used for element-wise comparison (== >= <= !=)
ty (WeldType): Type of each element in the input array

Returns:
A WeldObject representing this computation


def Insert(self, key, value, row_index):

        if row_index < 0:
            row_index += len(self)

        if not 0 <= row_index < len(self):
            raise IndexError('Index "%s" is out of bounds.' % row_index)

        new_row = Row()
        for idx in self.header:
            if self.index(idx) == row_index:
                new_row[key] = value
            new_row[idx] = self[idx]
        self._keys = new_row.header
        self._values = new_row.values
        del new_row
        self._BuildIndex()

Inserts new values at a specified offset.

Args:
key: string for header value.
value: string for a data value.
row_index: Offset into row for data.

Raises:
IndexError: If the offset is out of bands.


def get_resources(self):
    json_resources = self.rest_client.make_request(self.resource_url)['resources']
    return [RestResource(resource, self.rest_client) for resource in json_resources]

Retrieves a list of all known Streams high-level REST resources.

Returns:
:py:obj:`list` of :py:class:`~.rest_primitives.RestResource`: List of all Streams high-level REST resources.


def update_configuration(self, configuration):
    return self._client.update(configuration, uri=(self.URI + '/configuration'))

Updates the metrics configuration with the new values. Overwrites the existing configuration.

Args:
configuration (dict):
Dictionary with a list of objects which contain frequency, sample interval, and source type for each
resource-type.

Returns:
dict: The current configuration for which metrics are being relayed.


def _add_consequences(self, variant_obj, raw_variant_line):
    consequences = []
    for consequence in SO_TERMS:
        if (consequence in raw_variant_line):
            consequences.append(consequence)
    variant_obj.consequences = consequences

Add the consequences found for a variant

Args:
variant_obj (puzzle.models.Variant)
raw_variant_line (str): A raw vcf variant line


def unknown_shape(rank=None, **kwargs) -> 'TensorShape':
    if rank is None and 'ndims' in kwargs:
        rank = kwargs.pop('ndims')
    if kwargs:
        raise TypeError('Unknown argument: %s' % kwargs)
    if rank is None:
        return TensorShape(None)
    else:
        return TensorShape([Dimension(None)] * rank)

Returns an unknown TensorShape, optionally with a known rank.

Args:
rank: (Optional) If specified, the number of dimensions in the shape.
**kwargs: For backwards compatibility.

Returns:
An unknown TensorShape.

Raises:
TypeError: In case of invalid arguments.


def get_dimension_type(self, dim):

        dim = self.get_dimension(dim)
        if dim is None:
            return None
        elif dim.type is not None:
            return dim.type
        elif dim in self.vdims:
            return np.float64
        return self.interface.dimension_type(self, dim)

Get the type of the requested dimension.

Type is determined by Dimension.type attribute or common
type of the dimension values, otherwise None.

Args:
dimension: Dimension to look up by name or by index

Returns:
Declared type of values along the dimension


def add_arc(self, src, dst, char):

        if src not in self.automaton.states():
            self.add_state()
        arc = fst.Arc(self.isyms[char], self.osyms[char],  fst.Weight.One(self.automaton.weight_type()), dst)
        self.automaton.add_arc(src, arc)

Adds a new Arc
Args:
src (int): The source state identifier
dst (int): The destination state identifier
char (str): The character for the transition
Returns:
None


def run(self):
    cmd = list(self.vasp_cmd)
    if self.auto_gamma:
        vi = VaspInput.from_directory('.')
        kpts = vi['KPOINTS']
        if ((kpts.style == Kpoints.supported_modes.Gamma) and (tuple(kpts.kpts[0]) == (1, 1, 1))):
            if ((self.gamma_vasp_cmd is not None) and which(self.gamma_vasp_cmd[(- 1)])):
                cmd = self.gamma_vasp_cmd
            elif which((cmd[(- 1)] + '.gamma')):
                cmd[(- 1)] += '.gamma'
    logger.info('Running {}'.format(' '.join(cmd)))
    with open(self.output_file, 'w') as f_std, open(self.stderr_file, 'w', buffering=1) as f_err:
        p = subprocess.Popen(cmd, stdout=f_std, stderr=f_err)
    return p

Perform the actual VASP run.

Returns:
(subprocess.Popen) Used for monitoring.


def _from_base_type(self, value):

        if not value:
            return None
        try:

            credentials = client.Credentials.new_from_json(value)
        except ValueError:
            credentials = None
        return credentials

Converts our stored JSON string back to the desired type.

Args:
value: A value from the datastore to be converted to the
desired type.

Returns:
A deserialized Credentials (or subclass) object, else None if
the value can't be parsed.


def from_row_and_group(row: int, group: int):
    for sym in _pt_data.keys():
        el = Element(sym)
        if ((el.row == row) and (el.group == group)):
            return el
    raise ValueError('No element with this row and group!')

Returns an element from a row and group number.

Args:
row (int): Row number
group (int): Group number

.. note::
The 18 group number system is used, i.e., Noble gases are group 18.


def intersection(self, *others):
    result = self.__copy__()
    _elements = result._elements
    _total = result._total
    for other in map(self._as_mapping, others):
        for (element, multiplicity) in list(_elements.items()):
            new_multiplicity = other.get(element, 0)
            if (new_multiplicity < multiplicity):
                if (new_multiplicity > 0):
                    _elements[element] = new_multiplicity
                    _total -= (multiplicity - new_multiplicity)
                else:
                    del _elements[element]
                    _total -= multiplicity
    result._total = _total
    return result

r"""Return a new multiset with elements common to the multiset and all others.

>>> ms = Multiset('aab')
>>> sorted(ms.intersection('abc'))
['a', 'b']

You can also use the ``&`` operator for the same effect. However, the operator version
will only accept a set as other operator, not any iterable, to avoid errors.

>>> ms = Multiset('aab')
>>> sorted(ms & Multiset('aaac'))
['a', 'a']

For a variant of the operation which modifies the multiset in place see
:meth:`intersection_update`.

Args:
others: The other sets intersect with the multiset. Can also be any :class:`~typing.Iterable`\[~T]
or :class:`~typing.Mapping`\[~T, :class:`int`] which are then converted to :class:`Multiset`\[~T].

Returns:
The multiset resulting from the intersection of the sets.


def yesno(question, default=None):

    if default is not None:
        if isinstance(default, bool):
            pass
        else:
            default_ = default.upper()
            if default_ not in ('Y', 'YES', 'N', 'NO'):
                raise RuntimeError("Invalid default value: '{}'".format(default))
            default = default_ in ('Y', 'YES')

    while True:
        ans = input("{} ({}/{})? ".format(question, "Y" if default == True else "y",
                                         "N" if default == False else "n")).upper()
        if ans == "" and default is not None:
            ret = default
            break
        elif ans in ("N", "NO"):
            ret = False
            break
        elif ans in ("Y", "YES"):
            ret = True
            break
    return ret

Asks a yes/no question

Args:
question: string **without** the question mark and without the options.
Example: 'Create links'
default: default option. Accepted values are 'Y', 'YES', 'N', 'NO' or lowercase versions of
these valus (this argument is case-insensitive)

Returns:
bool: True if user answered Yes, False otherwise


def assign(self, droplet_id):

        return self.get_data(
            "floating_ips/%s/actions/" % self.ip,
            type=POST,
            params={"type": "assign", "droplet_id": droplet_id}
        )

Assign a FloatingIP to a Droplet.

Args:
droplet_id: int - droplet id


def get_attr_info(binary_view):

    global _ATTR_BASIC

    attr_type, attr_len, non_resident = _ATTR_BASIC.unpack(binary_view[:9])

    return (AttrTypes(attr_type), attr_len, bool(non_resident))

Gets basic information from a binary stream to allow correct processing of
the attribute header.

This function allows the interpretation of the Attribute type, attribute length
and if the attribute is non resident.

Args:
binary_view (memoryview of bytearray) - A binary stream with the
information of the attribute

Returns:
An tuple with the attribute type, the attribute length, in bytes, and
if the attribute is resident or not.


def state_fluent_variables(self) -> FluentParamsList:
    fluents = self.domain.state_fluents
    ordering = self.domain.state_fluent_ordering
    return self._fluent_params(fluents, ordering)

Returns the instantiated state fluents in canonical order.

Returns:
Sequence[Tuple[str, List[str]]]: A tuple of pairs of fluent name
and a list of instantiated fluents represented as strings.


def ndtr(x, name='ndtr'):
    with ops.name_scope(name, values=[x]):
        x = ops.convert_to_tensor(x, name='x')
        if x.dtype.as_numpy_dtype not in [np.float32, np.float64]:
            raise TypeError('x.dtype=%s is not handled, see docstring for supported types.' % x.dtype)
        return _ndtr(x)

Normal distribution function.

Returns the area under the Gaussian probability density function, integrated
from minus infinity to x:

```
1       / x
ndtr(x)  = ----------  |    exp(-0.5 t**2) dt
sqrt(2 pi)  /-inf

= 0.5 (1 + erf(x / sqrt(2)))
= 0.5 erfc(x / sqrt(2))
```

Args:
x: `Tensor` of type `float32`, `float64`.
name: Python string. A name for the operation (default="ndtr").

Returns:
ndtr: `Tensor` with `dtype=x.dtype`.

Raises:
TypeError: if `x` is not floating-type.


def _rnn_scan(self, hidden_states: torch.Tensor, recurrent_gate: torch.Tensor, reset: torch.Tensor, recurrent_states: Union[torch.Tensor, None], acc_dtype: torch.dtype=torch.float32) -> Tuple[torch.Tensor, torch.Tensor]:
    recurrent_gate = recurrent_gate * ~reset
    if hidden_states.shape[1] == 1:
        if recurrent_states is None:
            return (hidden_states, hidden_states[:, 0].type(acc_dtype))
        else:
            contextualized_states = recurrent_gate.type(acc_dtype) * recurrent_states[:, None].to(recurrent_gate.device)
            contextualized_states += hidden_states.type(acc_dtype)
            return (contextualized_states.type(hidden_states.dtype), contextualized_states[:, -1])
    else:
        if recurrent_states is None:
            recurrent_states = torch.zeros(hidden_states[:, 0].shape, dtype=acc_dtype, device=hidden_states.device)
        contextualized_states = torch.zeros_like(hidden_states)
        for t in range(hidden_states.shape[1]):
            recurrent_states = recurrent_gate[:, t].type(acc_dtype) * recurrent_states.to(recurrent_gate.device)
            recurrent_states = recurrent_states + hidden_states[:, t].type(acc_dtype)
            contextualized_states[:, t] = recurrent_states.type(hidden_states.dtype)
    return (contextualized_states, recurrent_states)

Runs the recurrence of a linear RNN.

Args:
hidden_states: The input sequence.
recurrent_gate: The diagonal of the recurrence matrix `A`.
reset: Indicator of document boundaries, e.g. when to reset the hidden state
of the RNN.
recurrent_states: The initial hidden state.
acc_dtype: The data type for the accumulation.

Returns:
The output of the linear recurrence.


def _remove_hidden_parts(projected_surface):

    surface = np.copy(projected_surface)
    surface[~_make_occlusion_mask(projected_surface)] = np.nan
    return surface

Removes parts of a projected surface that are not visible.

Args:
projected_surface (surface): the surface to use

Returns:
surface: A projected surface.


def master(self, task_type=None, task_id=None, rpc_layer=None):
    session_master = _get_value_in_tfconfig(_SESSION_MASTER_KEY)
    if session_master is not None:
        return session_master
    cluster_spec = self.cluster_spec()
    if not cluster_spec.jobs or (len(cluster_spec.jobs) == 1 and len(cluster_spec.job_tasks(cluster_spec.jobs[0])) == 1):
        return ''
    task_type = task_type if task_type is not None else self.task_type
    task_id = task_id if task_id is not None else self.task_id
    rpc_layer = rpc_layer if rpc_layer is not None else self.rpc_layer
    return format_master_url(cluster_spec.task_address(task_type, task_id), rpc_layer)

Returns the master address to use when creating a TensorFlow session.

Note: this is only useful for TensorFlow 1.x.

Args:
task_type: (String, optional) Overrides and sets the task_type of the
master.
task_id: (Integer, optional) Overrides and sets the task id of the
master.
rpc_layer: (String, optional) Overrides and sets the protocol over which
TensorFlow nodes communicate with each other.

Returns:
The address of the master.

Raises:
RuntimeError: If the task_type or task_id is not specified and the
`TF_CONFIG` environment variable does not contain a task section.