def solveAsync(self, callback):

    def async_call():
        self._lock.acquire()
        try:
            self._impl.solve()
        except Exception:
            self._lock.release()
            raise
        else:
            self._lock.release()
            callback.run()
    Thread(target=async_call).start()

Solve the current model asynchronously.

Args:
callback: Callback to be executed when the solver is done.


def _copy_deploy_scripts_for_hosts(self, domains):
    with LogTask('Copying any deploy scripts'):
        for (host_name, host_spec) in domains.iteritems():
            host_metadata = host_spec.get('metadata', {})
            deploy_scripts = self._get_scripts(host_metadata)
            new_scripts = self._copy_delpoy_scripts(deploy_scripts)
            self._set_scripts(host_metadata=host_metadata, scripts=new_scripts)
    return domains

Copy the deploy scripts for all the domains into the prefix scripts dir

Args:
domains(dict): spec with the domains info as when loaded from the
initfile

Returns:
None


def Convert(self, metadata, grr_message, token=None):
    return self.BatchConvert([(metadata, grr_message)], token=token)

Converts GrrMessage into a set of RDFValues.

Args:
metadata: ExportedMetadata to be used for conversion.
grr_message: GrrMessage to be converted.
token: Security token.

Returns:
List or generator with resulting RDFValues.


def ParseRow(self, parser_mediator, row_offset, row):

    timestamp = self._ParseTimestamp(parser_mediator, row)
    if timestamp is None:
      return

    event_data = TrendMicroUrlEventData()
    event_data.offset = row_offset

    for field in (
        'credibility_rating', 'credibility_score', 'policy_identifier',
        'threshold', 'block_mode'):
      try:
        value = int(row[field], 10)
      except (ValueError, TypeError):
        value = None
      setattr(event_data, field, value)

    for field in ('url', 'group_name', 'group_code', 'application_name', 'ip'):
      setattr(event_data, field, row[field])

    event = time_events.DateTimeValuesEvent(
        timestamp, definitions.TIME_DESCRIPTION_WRITTEN)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a line of the log file and produces events.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
row_offset (int): line number of the row.
row (dict[str, str]): fields of a single row, as specified in COLUMNS.


def console_set_char_foreground(
    con: tcod.console.Console, x: int, y: int, col: Tuple[int, int, int]
) -> None:

    lib.TCOD_console_set_char_foreground(_console(con), x, y, col)

Change the foreground color of x,y to col.

Args:
con (Console): Any Console instance.
x (int): Character x position from the left.
y (int): Character y position from the top.
col (Union[Tuple[int, int, int], Sequence[int]]):
An (r, g, b) sequence or Color instance.

.. deprecated:: 8.4
Array access performs significantly faster than using this function.
See :any:`Console.fg`.


def is_function_or_method(obj):
    return (inspect.isfunction(obj) or inspect.ismethod(obj) or is_cython(obj))

Check if an object is a function or method.

Args:
obj: The Python object in question.

Returns:
True if the object is an function or method.


def position(x=None, y=None):
    (posx, posy) = platformModule._position()
    posx = int(posx)
    posy = int(posy)
    if (x is not None):
        posx = int(x)
    if (y is not None):
        posy = int(y)
    return Point(posx, posy)

Returns the current xy coordinates of the mouse cursor as a two-integer
tuple.

Args:
x (int, None, optional) - If not None, this argument overrides the x in
the return value.
y (int, None, optional) - If not None, this argument overrides the y in
the return value.

Returns:
(x, y) tuple of the current xy coordinates of the mouse cursor.


def delete(self, request):
    try:
        self.client.delete_object(Bucket=request.bucket, Key=request.object)
    except Exception as e:
        raise messages.S3ClientError(str(e), get_http_error_code(e))

Deletes given object from bucket
Args:
request: (DeleteRequest) input message
Returns:
(void) Void, otherwise will raise if an error occurs


def _ExtractMetadataFromFileEntry(self, mediator, file_entry, data_stream):
    if (file_entry.IsRoot() and (file_entry.type_indicator not in self._TYPES_WITH_ROOT_METADATA)):
        return
    if (data_stream and (not data_stream.IsDefault())):
        return
    display_name = mediator.GetDisplayName()
    logger.debug('[ExtractMetadataFromFileEntry] processing file entry: {0:s}'.format(display_name))
    self.processing_status = definitions.STATUS_INDICATOR_EXTRACTING
    if self._processing_profiler:
        self._processing_profiler.StartTiming('extracting')
    self._event_extractor.ParseFileEntryMetadata(mediator, file_entry)
    if self._processing_profiler:
        self._processing_profiler.StopTiming('extracting')
    self.processing_status = definitions.STATUS_INDICATOR_RUNNING

Extracts metadata from a file entry.

Args:
mediator (ParserMediator): mediates the interactions between
parsers and other components, such as storage and abort signals.
file_entry (dfvfs.FileEntry): file entry to extract metadata from.
data_stream (dfvfs.DataStream): data stream or None if the file entry
has no data stream.


def _CreateLineString(self, parent, coordinate_list):
    if (not coordinate_list):
        return None
    linestring = ET.SubElement(parent, 'LineString')
    tessellate = ET.SubElement(linestring, 'tessellate')
    tessellate.text = '1'
    if (len(coordinate_list[0]) == 3):
        altitude_mode = ET.SubElement(linestring, 'altitudeMode')
        altitude_mode.text = 'absolute'
    coordinates = ET.SubElement(linestring, 'coordinates')
    if (len(coordinate_list[0]) == 3):
        coordinate_str_list = [('%f,%f,%f' % t) for t in coordinate_list]
    else:
        coordinate_str_list = [('%f,%f' % t) for t in coordinate_list]
    coordinates.text = ' '.join(coordinate_str_list)
    return linestring

Create a KML LineString element.

The points of the string are given in coordinate_list. Every element of
coordinate_list should be one of a tuple (longitude, latitude) or a tuple
(longitude, latitude, altitude).

Args:
parent: The parent ElementTree.Element instance.
coordinate_list: The list of coordinates.

Returns:
The LineString ElementTree.Element instance or None if coordinate_list is
empty.


def repertoire(self, direction, mechanism, purview):

        system = self.system[direction]
        node_labels = system.node_labels

        if not set(purview).issubset(self.purview_indices(direction)):
            raise ValueError('{} is not a {} purview in {}'.format(
                fmt.fmt_mechanism(purview, node_labels), direction, self))

        if not set(mechanism).issubset(self.mechanism_indices(direction)):
            raise ValueError('{} is no a {} mechanism in {}'.format(
                fmt.fmt_mechanism(mechanism, node_labels), direction, self))

        return system.repertoire(direction, mechanism, purview)

Return the cause or effect repertoire function based on a direction.

Args:
direction (str): The temporal direction, specifiying the cause or
effect repertoire.


def _ScanFileSystemForWindowsDirectory(self, path_resolver):

    result = False
    for windows_path in self._WINDOWS_DIRECTORIES:
      windows_path_spec = path_resolver.ResolvePath(windows_path)

      result = windows_path_spec is not None
      if result:
        self._windows_directory = windows_path
        break

    return result

Scans a file system for a known Windows directory.

Args:
path_resolver (WindowsPathResolver): Windows path resolver.

Returns:
bool: True if a known Windows directory was found.


def _overrides(subcls, supercls, attr):
    if subcls and supercls and (supercls in subcls.mro):
        subcls = _base(subcls)
        supercls = _base(supercls)
        for cls in subcls.mro:
            if cls == supercls:
                break
            if isinstance(cls, mixin.LazyMembers):
                cls.load_lazy_attribute(attr)
            if isinstance(cls, abstract.SimpleValue) and attr in cls.members and cls.members[attr].bindings:
                return True
    return False

Check whether subcls_var overrides or newly defines the given attribute.

Args:
subcls: A potential subclass.
supercls: A potential superclass.
attr: An attribute name.

Returns:
True if subcls_var is a subclass of supercls_var and overrides or newly
defines the attribute. False otherwise.


def delete_additional_charge(self, recurring_billing_id):

        fmt = 'recurringBillItems/{}'.format(recurring_billing_id)
        return self.client._delete(self.url + fmt, headers=self.get_headers())

Remove an extra charge from an invoice.

Args:
recurring_billing_id: Identifier of the additional charge.

Returns:


def FillDeviceCapabilities(device, descriptor):

  preparsed_data = PHIDP_PREPARSED_DATA(0)
  ret = hid.HidD_GetPreparsedData(device, ctypes.byref(preparsed_data))
  if not ret:
    raise ctypes.WinError()

  try:
    caps = HidCapabilities()
    ret = hid.HidP_GetCaps(preparsed_data, ctypes.byref(caps))

    if ret != HIDP_STATUS_SUCCESS:
      raise ctypes.WinError()

    descriptor.usage = caps.Usage
    descriptor.usage_page = caps.UsagePage
    descriptor.internal_max_in_report_len = caps.InputReportByteLength
    descriptor.internal_max_out_report_len = caps.OutputReportByteLength

  finally:
    hid.HidD_FreePreparsedData(preparsed_data)

Fill out device capabilities.

Fills the HidCapabilitites of the device into descriptor.

Args:
device: A handle to the open device
descriptor: DeviceDescriptor to populate with the
capabilities

Returns:
none

Raises:
WindowsError when unable to obtain capabilitites.


def max_pooling1d(inputs, pool_size, strides, padding='valid', data_format='channels_last', name=None):
    warnings.warn('`tf.layers.max_pooling1d` is deprecated and will be removed in a future version. Please use `tf.keras.layers.MaxPooling1D` instead.')
    layer = MaxPooling1D(pool_size=pool_size, strides=strides, padding=padding, data_format=data_format, name=name)
    return layer.apply(inputs)

Max Pooling layer for 1D inputs.

Args:
inputs: The tensor over which to pool. Must have rank 3.
pool_size: An integer or tuple/list of a single integer,
representing the size of the pooling window.
strides: An integer or tuple/list of a single integer, specifying the
strides of the pooling operation.
padding: A string. The padding method, either 'valid' or 'same'.
Case-insensitive.
data_format: A string, one of `channels_last` (default) or `channels_first`.
The ordering of the dimensions in the inputs.
`channels_last` corresponds to inputs with shape
`(batch, length, channels)` while `channels_first` corresponds to
inputs with shape `(batch, channels, length)`.
name: A string, the name of the layer.

Returns:
The output tensor, of rank 3.

Raises:
ValueError: if eager execution is enabled.


def estCumPos(pos, chrom, offset=20000000):
    chromvals = SP.unique(chrom)
    chrom_pos = SP.zeros_like(chromvals)
    cum_pos = SP.zeros_like(pos)
    maxpos_cum = 0
    for (i, mychrom) in enumerate(chromvals):
        chrom_pos[i] = maxpos_cum
        i_chr = (chrom == mychrom)
        maxpos = (pos[i_chr].max() + offset)
        maxpos_cum += maxpos
        cum_pos[i_chr] = (chrom_pos[i] + pos[i_chr])
    return (cum_pos, chrom_pos)

compute the cumulative position of each variant given the position and the chromosome
Also return the starting cumulativeposition of each chromosome

Args:
pos:        scipy.array of basepair positions (on the chromosome)
chrom:      scipy.array of chromosomes
offset:     offset between chromosomes for cumulative position (default 20000000 bp)

Returns:
cum_pos:    scipy.array of cumulative positions
chrom_pos:  scipy.array of starting cumulative positions for each chromosme


def compute_ld(cur_geno, other_genotypes, r2=False):

    norm_cur = normalize_genotypes(cur_geno)

    norm_others = np.stack(
        tuple(normalize_genotypes(g) for g in other_genotypes),
        axis=1,
    )

    assert norm_cur.shape[0] == norm_others.shape[0]

    n = (
        ~np.isnan(norm_cur.reshape(norm_cur.shape[0], 1)) *
        ~np.isnan(norm_others)
    ).sum(axis=0)

    r = pd.Series(
        np.dot(
            np.nan_to_num(norm_cur), np.nan_to_num(norm_others) / n
        ),
        index=[g.variant.name for g in other_genotypes],
        name="r2" if r2 else "r",
    )

    r.loc[r > 1] = 1
    r.loc[r < -1] = -1

    if r2:
        return r ** 2
    else:
        return r

Compute LD between a marker and a list of markers.

Args:
cur_geno (Genotypes): The genotypes of the marker.
other_genotypes (list): A list of genotypes.

Returns:
numpy.array: An array containing the r or r**2 values between cur_geno
and other_genotypes.

Note:
The genotypes will automatically be normalized using (x - mean) / std.


def represent_as_string(iterable):

    keep = (".", "[", "]")
    return "".join(tuple(int_to_str_digit(i) if i not in keep
                   else i for i in iterable))

Represent a number in the form of a string.
(8, 6, 8, '.', 0, 15) -> "868.0F"

Args:
iterable - Number represented as an iterable container of digits.
Returns:
Number represented as a string of digits.

>>> represent_as_string((8, 6, 8, '.', 0, 15))
'868.0F'


def load(self, context):
    if (not ((context.flags.debugger_data_server_grpc_port > 0) or (context.flags.debugger_port > 0))):
        return None
    flags = context.flags
    try:
        import tensorflow
    except ImportError:
        raise ImportError('To use the debugger plugin, you need to have TensorFlow installed:\n  pip install tensorflow')
    try:
        from tensorboard.plugins.debugger import debugger_plugin as debugger_plugin_lib
        from tensorboard.plugins.debugger import interactive_debugger_plugin as interactive_debugger_plugin_lib
    except ImportError as e:
        (e_type, e_value, e_traceback) = sys.exc_info()
        message = (e.msg if hasattr(e, 'msg') else e.message)
        if ('grpc' in message):
            e_value = ImportError((message + '\n\nTo use the debugger plugin, you need to have gRPC installed:\n  pip install grpcio'))
        six.reraise(e_type, e_value, e_traceback)
    if (flags.debugger_port > 0):
        interactive_plugin = interactive_debugger_plugin_lib.InteractiveDebuggerPlugin(context)
        logger.info('Starting Interactive Debugger Plugin at gRPC port %d', flags.debugger_data_server_grpc_port)
        interactive_plugin.listen(flags.debugger_port)
        return interactive_plugin
    elif (flags.debugger_data_server_grpc_port > 0):
        noninteractive_plugin = debugger_plugin_lib.DebuggerPlugin(context)
        logger.info('Starting Non-interactive Debugger Plugin at gRPC port %d', flags.debugger_data_server_grpc_port)
        noninteractive_plugin.listen(flags.debugger_data_server_grpc_port)
        return noninteractive_plugin
    raise AssertionError()

Returns the debugger plugin, if possible.

Args:
context: The TBContext flags including `add_arguments`.

Returns:
A DebuggerPlugin instance or None if it couldn't be loaded.


def create_binary_descriptor(streamer):

    trigger = 0
    if streamer.automatic:
        trigger = 1
    elif streamer.with_other is not None:
        trigger = (1 << 7) | streamer.with_other

    return struct.pack("<8sHBBBx", streamer.dest.encode(), streamer.selector.encode(), trigger, streamer.KnownFormats[streamer.format], streamer.KnownTypes[streamer.report_type])

Create a packed binary descriptor of a DataStreamer object.

Args:
streamer (DataStreamer): The streamer to create a packed descriptor for

Returns:
bytes: A packed 14-byte streamer descriptor.


def _should_elide_opcode(op_items: list[tuple[int, Opcode]], i: int, python_version: tuple[int, int]):
    op = op_items[i][1]
    if python_version == (3, 11):
        return isinstance(op, JUMP_BACKWARD) and i + 1 < len(op_items) and isinstance(op_items[i + 1][1], END_ASYNC_FOR)
    return False

Returns `True` if the opcode on index `i` should be elided.

Opcodes should be elided if they don't contribute to type checking and cause
issues in the block graph.

Args:
op_items: List of (offset, opcode) tuples.
i: Index of opcode to check for elision.
python_version: Python version tuple.


def get_group(self, name, user_name=None):
    return self.service.get_group(name, user_name, self.url_prefix, self.auth, self.session, self.session_send_opts)

Get owner of group and the resources it's attached to.

Args:
name (string): Name of group to query.
user_name (optional[string]): Supply None if not interested in determining if user is a member of the given group.

Returns:
(dict): Keys include 'owner', 'name', 'resources'.

Raises:
requests.HTTPError on failure.


def identical_dataset_and_algorithm_tuner(self, additional_parents=None):
    return self._create_warm_start_tuner(additional_parents=additional_parents, warm_start_type=WarmStartTypes.IDENTICAL_DATA_AND_ALGORITHM)

Creates a new ``HyperparameterTuner`` by copying the request fields from the provided parent to the new
instance of ``HyperparameterTuner``. Followed by addition of warm start configuration with the type as
"IdenticalDataAndAlgorithm" and parents as the union of provided list of ``additional_parents`` and the ``self``

Args:
additional_parents (set{str}): Set of additional parents along with the self to be used in warm starting
the identical dataset and algorithm tuner.

Returns:
sagemaker.tuner.HyperparameterTuner: HyperparameterTuner instance which can be used to launch identical
dataset and algorithm tuning job.

Examples:
>>> parent_tuner = HyperparameterTuner.attach(tuning_job_name="parent-job-1")
>>> identical_dataset_algo_tuner = parent_tuner.identical_dataset_and_algorithm_tuner(
>>>                                                             additional_parents={"parent-job-2"})
Later On:
>>> identical_dataset_algo_tuner.fit(inputs={})


def logloss(y, p):

    p[p < EPS] = EPS
    p[p > 1 - EPS] = 1 - EPS
    return log_loss(y, p)

Bounded log loss error.

Args:
y (numpy.array): target
p (numpy.array): prediction

Returns:
bounded log loss error


def _get_augmented_label_matrix(self, L, higher_order=False):

        self.c_data = {}
        for i in range(self.m):
            self.c_data[i] = {
                "start_index": i * self.k,
                "end_index": (i + 1) * self.k,
                "max_cliques": set(
                    [
                        j
                        for j in self.c_tree.nodes()
                        if i in self.c_tree.node[j]["members"]
                    ]
                ),
            }

        L_ind = self._create_L_ind(L)

        if higher_order:
            L_aug = np.copy(L_ind)
            for item in chain(self.c_tree.nodes(), self.c_tree.edges()):
                if isinstance(item, int):
                    C = self.c_tree.node[item]
                    C_type = "node"
                elif isinstance(item, tuple):
                    C = self.c_tree[item[0]][item[1]]
                    C_type = "edge"
                else:
                    raise ValueError(item)
                members = list(C["members"])
                nc = len(members)

                if nc == 1:
                    C["start_index"] = members[0] * self.k
                    C["end_index"] = (members[0] + 1) * self.k

                else:
                    L_C = np.ones((self.n, self.k ** nc))
                    for i, vals in enumerate(product(range(self.k), repeat=nc)):
                        for j, v in enumerate(vals):
                            L_C[:, i] *= L_ind[:, members[j] * self.k + v]

                    if L_aug is not None:
                        C["start_index"] = L_aug.shape[1]
                        C["end_index"] = L_aug.shape[1] + L_C.shape[1]
                        L_aug = np.hstack([L_aug, L_C])
                    else:
                        C["start_index"] = 0
                        C["end_index"] = L_C.shape[1]
                        L_aug = L_C

                    id = tuple(members) if len(members) > 1 else members[0]
                    self.c_data[id] = {
                        "start_index": C["start_index"],
                        "end_index": C["end_index"],
                        "max_cliques": set([item]) if C_type == "node" else set(item),
                    }
            return L_aug
        else:
            return L_ind

Returns an augmented version of L where each column is an indicator
for whether a certain source or clique of sources voted in a certain
pattern.

Args:
L: An [n,m] scipy.sparse label matrix with values in {0,1,...,k}


def auto_model(layout, scan_length=None, one_vs_rest=False):
    base_name = split(layout.root)[(- 1)]
    tasks = layout.entities['task'].unique()
    task_models = []
    for task_name in tasks:
        model = OrderedDict()
        model['Name'] = '_'.join([base_name, task_name])
        model['Description'] = ('Autogenerated model for the %s task from %s' % (task_name, base_name))
        model['Input'] = {'Task': task_name}
        steps = []
        transformations = OrderedDict(Name='Factor', Input=['trial_type'])
        run = OrderedDict(Level='Run', Name='Run', Transformations=[transformations])
        run_nodes = load_variables(layout, task=task_name, levels=['run'], scan_length=scan_length)
        evs = []
        for n in run_nodes.nodes:
            evs.extend(n.variables['trial_type'].values.values)
        trial_types = np.unique(evs)
        trial_type_factors = [('trial_type.' + tt) for tt in trial_types]
        run['Transformations'].append(OrderedDict(Name='Convolve', Input=trial_type_factors))
        run_model = OrderedDict(X=trial_type_factors)
        run['Model'] = run_model
        if one_vs_rest:
            contrasts = []
            for (i, tt) in enumerate(trial_types):
                cdict = OrderedDict()
                if (len(trial_types) > 1):
                    cdict['Name'] = (('run_' + tt) + '_vs_others')
                else:
                    cdict['Name'] = ('run_' + tt)
                cdict['ConditionList'] = trial_type_factors
                weights = np.ones(len(trial_types))
                try:
                    weights[(trial_types != tt)] = ((- 1.0) / (len(trial_types) - 1))
                except ZeroDivisionError:
                    pass
                cdict['Weights'] = list(weights)
                cdict['Type'] = 't'
                contrasts.append(cdict)
            run['Contrasts'] = contrasts
        steps.append(run)
        if one_vs_rest:
            sessions = layout.get_sessions()
            if (len(sessions) > 1):
                contrast_names = [cc['Name'] for cc in steps[(- 1)]['Contrasts']]
                steps.append(_make_passthrough_contrast('Session', contrast_names))
            subjects = layout.get_subjects()
            if (len(subjects) > 1):
                contrast_names = [cc['Name'] for cc in steps[(- 1)]['Contrasts']]
                steps.append(_make_passthrough_contrast('Subject', contrast_names))
            contrast_names = [cc['Name'] for cc in steps[(- 1)]['Contrasts']]
            steps.append(_make_passthrough_contrast('Dataset', contrast_names))
        model['Steps'] = steps
        task_models.append(model)
    return task_models

Create a simple default model for each of the tasks in a BIDSLayout.
Contrasts each trial type against all other trial types and trial types
at the run level and then uses t-tests at each other level present to
aggregate these results up.

Args:
layout (BIDSLayout) A BIDSLayout instance
scan_length (Int) Scan length for loading event varibles in cases
where the scan length can not be read from the nifti.
Primarily for testing.
one_vs_rest (Bool) Set to True if you would like to autogenerate
contrasts of each trial type against everyother trialtype.

Returns:
models (list) list of model dictionaries for each task


def remove(self, *dic):
    dicList = list(flatten(dic))
    for d in dicList:
        di = []
        for k in d:
            di.append(Pair(k, IntegerSingle(d[k])))
        dictSingle = DictSingle(di)
        self._remove([dictSingle], self.l)

remove a calendar config.

Args:
*dic (dict): dictionary with format {'Day': 12, 'Hour': 34} Avaliable keys are Month, Day, Weekday, Hour, Minute. *Note the uppercase.* You can use gen(), genMix() to generate complex config dictionary.


def lazy_property(fn):
    attr_name = ('_lazy_' + fn.__name__)

    @property
    @wraps(fn)
    def _lazy_property(self):
        if (not hasattr(self, attr_name)):
            setattr(self, attr_name, fn(self))
        return getattr(self, attr_name)
    return _lazy_property

Decorator that makes a property lazy-evaluated whilst preserving
docstrings.

Args:
fn (function): the property in question

Returns:
evaluated version of the property.


def __init__(self, fields):

        self.fields = {
            ensure_unicode_string(key): value
            for key, value in six.iteritems(fields)
        }

        super(ConstructResult, self).__init__(self.fields)
        self.validate()

Construct a ConstructResult object that maps the given field names to their expressions.

Args:
fields: dict, variable name string -> Expression
see rules for variable names in validate_safe_string().

Returns:
new ConstructResult object


def make_fixed_temp_multi_apec(kTs, name_template='apec%d', norm=None):
    total_model = None
    sub_models = []
    for (i, kT) in enumerate(kTs):
        component = ui.xsapec((name_template % i))
        component.kT = kT
        ui.freeze(component.kT)
        if (norm is not None):
            component.norm = norm
        sub_models.append(component)
        if (total_model is None):
            total_model = component
        else:
            total_model = (total_model + component)
    return (total_model, sub_models)

Create a model summing multiple APEC components at fixed temperatures.

*kTs*
An iterable of temperatures for the components, in keV.
*name_template* = 'apec%d'
A template to use for the names of each component; it is string-formatted
with the 0-based component number as an argument.
*norm* = None
An initial normalization to be used for every component, or None to use
the Sherpa default.
Returns:
A tuple ``(total_model, sub_models)``, where *total_model* is a Sherpa
model representing the sum of the APEC components and *sub_models* is
a list of the individual models.

This function creates a vector of APEC model components and sums them.
Their *kT* parameters are set and then frozen (using
:func:`sherpa.astro.ui.freeze`), so that upon exit from this function, the
amplitude of each component is the only free parameter.


def total_seconds(td):

    a_milli = 1000000.0
    td_ds = td.seconds + (td.days * 86400)
    td_micro = td.microseconds + (td_ds * a_milli)
    return td_micro / a_milli

For those with older versions of Python, a pure-Python
implementation of Python 2.7's :meth:`~datetime.timedelta.total_seconds`.

Args:
td (datetime.timedelta): The timedelta to convert to seconds.
Returns:
float: total number of seconds

>>> td = timedelta(days=4, seconds=33)
>>> total_seconds(td)
345633.0


def is_workdir(cls, path):
    try:
        cls(path=path).load()
    except MalformedWorkdir:
        return False
    return True

Check if the given path is a workdir

Args:
path(str): Path to check

Return:
bool: True if the given path is a workdir


def logical_xor(x1, x2):
    if any_symbolic_tensors((x1, x2)):
        return LogicalXor().symbolic_call(x1, x2)
    return backend.numpy.logical_xor(x1, x2)

Compute the truth value of `x1 XOR x2`, element-wise.

Args:
x1: First input tensor.
x2: Second input tensor.

Returns:
Output boolean tensor.


def ParseApplicationUsageRow(
      self, parser_mediator, query, row, **unused_kwargs):

    query_hash = hash(query)

    application_name = self._GetRowValue(query_hash, row, 'event')
    usage = 'Application {0:s}'.format(application_name)

    event_data = MacOSApplicationUsageEventData()
    event_data.application = self._GetRowValue(query_hash, row, 'app_path')
    event_data.app_version = self._GetRowValue(query_hash, row, 'app_version')
    event_data.bundle_id = self._GetRowValue(query_hash, row, 'bundle_id')
    event_data.count = self._GetRowValue(query_hash, row, 'number_times')
    event_data.query = query

    timestamp = self._GetRowValue(query_hash, row, 'last_time')
    date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(date_time, usage)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses an application usage row.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row.


def register_entry(self, navbar_kwargs):

        path = navbar_kwargs.pop('path')

        if not hasattr(path, '__iter__') or isinstance(path, basestring):
            path = [path]

        entry_group = self.navbar_entries

        for name, is_last in iter_islast(path):
            kwargs = deepcopy(navbar_kwargs)
            kwargs['name'] = name
            for existing_entry in entry_group:

                if existing_entry.name == name:
                    entry = existing_entry
                    if is_last:
                        entry.endpoint = kwargs['endpoint']
                    break
            else:

                if not is_last:
                    kwargs['endpoint'] = None
                entry = NavbarEntry(**kwargs)
                entry_group.add(entry)
            entry_group = entry.children

Register a navbar entry with the copilot.

Args:
navbar_kwargs (dict): Arguments passed to the
:class:`NavbarEntry` instance.


def AddContract(self, contract):
    super(UserWallet, self).AddContract(contract)
    try:
        db_contract = Contract.get(ScriptHash=contract.ScriptHash.ToBytes())
        db_contract.delete_instance()
    except Exception as e:
        logger.debug('contract does not exist yet')
    sh = bytes(contract.ScriptHash.ToArray())
    (address, created) = Address.get_or_create(ScriptHash=sh)
    address.IsWatchOnly = False
    address.save()
    db_contract = Contract.create(RawData=contract.ToArray(), ScriptHash=contract.ScriptHash.ToBytes(), PublicKeyHash=contract.PublicKeyHash.ToBytes(), Address=address, Account=self.__dbaccount)
    logger.debug(('Creating db contract %s ' % db_contract))
    db_contract.save()

Add a contract to the database.

Args:
contract(neo.SmartContract.Contract): a Contract instance.


def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, current_tokens: torch.LongTensor, beam_group_idx: int) -> torch.FloatTensor:
    batch_size = current_tokens.shape[0]
    group_start_idx = beam_group_idx * self._num_sub_beams
    group_end_idx = min(group_start_idx + self._num_sub_beams, self._num_beams)
    group_size = group_end_idx - group_start_idx
    vocab_size = scores.shape[-1]
    if group_start_idx == 0:
        return scores
    scores_processed = scores.clone()
    for batch_idx in range(batch_size):
        previous_group_tokens = current_tokens[batch_idx * self._num_beams:batch_idx * self._num_beams + group_start_idx]
        token_frequency = torch.bincount(previous_group_tokens, minlength=vocab_size).to(scores.device)
        scores_processed[batch_idx * group_size:(batch_idx + 1) * group_size] -= self._diversity_penalty * token_frequency
    return scores_processed

Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. [What are input IDs?](../glossary#input-ids)
scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`):
Prediction scores of a language modeling head. These can be logits for each vocabulary when not using
beam search or log softmax for each vocabulary token when using beam search
current_tokens (`torch.LongTensor` of shape `(batch_size)`):
Indices of input sequence tokens in the vocabulary, corresponding to the tokens selected by the other
beam groups in the current generation step.
beam_group_idx (`int`):
The index of the beam group currently being processed.

Return:
`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`:
The processed prediction scores.


def inspect_config(self, id):
    url = self._url('/configs/{0}', id)
    return self._result(self._get(url), True)

Retrieve config metadata

Args:
id (string): Full ID of the config to inspect

Returns (dict): A dictionary of metadata

Raises:
:py:class:`docker.errors.NotFound`
if no config with that ID exists


def assert_no_garbage_created(f: _F) -> _F:

    def decorator(self: 'TensorFlowTestCase', **kwargs):

        gc.disable()
        previous_debug_flags = gc.get_debug()
        gc.set_debug(gc.DEBUG_UNCOLLECTABLE)
        gc.collect()
        previous_garbage = len(gc.garbage)
        result = f(self, **kwargs)
        gc.collect()
        new_garbage = len(gc.garbage)
        if new_garbage > previous_garbage:
            for i, obj in enumerate(gc.garbage[previous_garbage:]):
                if getattr(obj, '__module__', '') == 'ast':
                    new_garbage -= 3
        if new_garbage > previous_garbage:
            logging.error("The decorated test created work for Python's garbage collector, likely due to a reference cycle. New objects in cycle(s):")
            for i, obj in enumerate(gc.garbage[previous_garbage:]):
                try:
                    logging.error('Object %d of %d', i, len(gc.garbage) - previous_garbage)

                    def _safe_object_str(obj) -> str:
                        return '<%s %d>' % (obj.__class__.__name__, id(obj))
                    logging.error('  Object type: %s', _safe_object_str(obj))
                    logging.error('  Referrer types: %s', ', '.join([_safe_object_str(ref) for ref in gc.get_referrers(obj)]))
                    logging.error('  Referent types: %s', ', '.join([_safe_object_str(ref) for ref in gc.get_referents(obj)]))
                    logging.error('  Object attribute names: %s', dir(obj))
                    logging.error('  Object __str__:')
                    logging.error(obj)
                    logging.error('  Object __repr__:')
                    logging.error(repr(obj))
                except Exception:
                    logging.error('(Exception while printing object)')
        if new_garbage > previous_garbage:
            for i in range(previous_garbage, new_garbage):
                if _find_reference_cycle(gc.garbage, i):
                    break
        self.assertEqual(previous_garbage, new_garbage)
        gc.set_debug(previous_debug_flags)
        gc.enable()
        return result
    return decorator

Test method decorator to assert that no garbage has been created.

Note that this decorator sets DEBUG_SAVEALL, which in some Python interpreters
cannot be un-set (i.e. will disable garbage collection for any other unit
tests in the same file/shard).

Args:
f: The function to decorate.

Returns:
The decorated function.


def _get_full_name(self, node):
    curr = node
    items = []
    while not isinstance(curr, ast.Name):
        if not isinstance(curr, ast.Attribute):
            return None
        items.append(curr.attr)
        curr = curr.value
    items.append(curr.id)
    return '.'.join(reversed(items))

Traverse an Attribute node to generate a full name, e.g., "tf.foo.bar".

This is the inverse of `full_name_node`.

Args:
node: A Node of type Attribute.

Returns:
a '.'-delimited full-name or None if node was not Attribute or Name.
i.e. `foo()+b).bar` returns None, while `a.b.c` would return "a.b.c".


def domain_tag(self, domains):
    api_name = 'opendns-domain_tag'
    fmt_url_path = u'domains/{0}/latest_tags'
    return self._multi_get(api_name, fmt_url_path, domains)

Get the data range when a domain is part of OpenDNS block list.

Args:
domains: an enumerable of strings domain names
Returns:
An enumerable of string with period, category, and url


def _TravelTimes(self,triplist,index=0):

    def DistanceInTravelTime(dep_secs, arr_secs):
      t_dist = arr_secs-dep_secs
      if t_dist<0:
        t_dist = self._DUMMY_SEPARATOR
      return t_dist

    if not triplist:
      return []

    if 0 < index < len(triplist):
      trip = triplist[index]
    else:
      trip = triplist[0]

    t_dists2 = [DistanceInTravelTime(stop[3],tail[2]) for (stop,tail)
                 in itertools.izip(trip.GetTimeStops(),trip.GetTimeStops()[1:])]
    return t_dists2

Calculate distances and plot stops.

Uses a timetable to approximate distances
between stations

Args:
# Class Trip is defined in transitfeed.py
triplist: [Trip, Trip, ...]
# (Optional) Index of Triplist prefered for timetable Calculation
index: 3

Returns:
# One integer for each pair of stations
# indicating the approximate distance
[0,33,140, ... ,X]


def get_function_name(function: Any) -> str:
    return str(function.__qualname__.split('.')[0])

Get the original name of a function, removing module paths.

Args:
* function: function instance

Returns:
* Actual name of function


def run(argv=None, save_main_session=True, test_pipeline=None) -> PipelineResult:
    known_args, pipeline_args = parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
    model_loader = KeyedModelHandler(TFModelHandlerNumpy(model_uri=known_args.model_path, model_type=ModelType.SAVED_WEIGHTS, create_model_fn=get_model))
    pipeline = test_pipeline
    if not test_pipeline:
        pipeline = beam.Pipeline(options=pipeline_options)
    label_pixel_tuple = pipeline | 'ReadFromInput' >> beam.io.ReadFromText(known_args.input) | 'PreProcessInputs' >> beam.Map(process_input)
    predictions = label_pixel_tuple | 'RunInference' >> RunInference(model_loader) | 'PostProcessOutputs' >> beam.ParDo(PostProcessor())
    _ = predictions | 'WriteOutput' >> beam.io.WriteToText(known_args.output, shard_name_template='', append_trailing_newlines=True)
    result = pipeline.run()
    result.wait_until_finish()
    return result

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


def get_numeric_value(event_tags, logger=None):
    logger_message_debug = None
    numeric_metric_value = None
    if (event_tags is None):
        logger_message_debug = 'Event tags is undefined.'
    elif (not isinstance(event_tags, dict)):
        logger_message_debug = 'Event tags is not a dictionary.'
    elif (NUMERIC_METRIC_TYPE not in event_tags):
        logger_message_debug = 'The numeric metric key is not in event tags.'
    else:
        numeric_metric_value = event_tags[NUMERIC_METRIC_TYPE]
        try:
            if isinstance(numeric_metric_value, (numbers.Integral, float, str)):
                cast_numeric_metric_value = float(numeric_metric_value)
                if ((not isinstance(cast_numeric_metric_value, float)) or math.isnan(cast_numeric_metric_value) or math.isinf(cast_numeric_metric_value)):
                    logger_message_debug = 'Provided numeric value {} is in an invalid format.'.format(numeric_metric_value)
                    numeric_metric_value = None
                elif isinstance(numeric_metric_value, bool):
                    logger_message_debug = 'Provided numeric value is a boolean, which is an invalid format.'
                    numeric_metric_value = None
                else:
                    numeric_metric_value = cast_numeric_metric_value
            else:
                logger_message_debug = 'Numeric metric value is not in integer, float, or string form.'
                numeric_metric_value = None
        except ValueError:
            logger_message_debug = 'Value error while casting numeric metric value to a float.'
            numeric_metric_value = None
    if (logger and logger_message_debug):
        logger.log(enums.LogLevels.DEBUG, logger_message_debug)
    if (numeric_metric_value is not None):
        if logger:
            logger.log(enums.LogLevels.INFO, 'The numeric metric value {} will be sent to results.'.format(numeric_metric_value))
    elif logger:
        logger.log(enums.LogLevels.WARNING, 'The provided numeric metric value {} is in an invalid format and will not be sent to results.'.format(numeric_metric_value))
    return numeric_metric_value

A smart getter of the numeric value from the event tags.

Args:
event_tags: A dictionary of event tags.
logger: Optional logger.

Returns:
A float numeric metric value is returned when the provided numeric
metric value is in the following format:
- A string (properly formatted, e.g., no commas)
- An integer
- A float or double
None is returned when the provided numeric metric values is in
the following format:
- None
- A boolean
- inf, -inf, nan
- A string not properly formatted (e.g., '1,234')
- Any values that cannot be cast to a float (e.g., an array or dictionary)


def speech_speaker(self):
    if self.speaker:
        return self.speaker
    elif self.parent:
        return self.parent.speech_speaker()
    else:
        return None

Retrieves the speaker of the audio or video file associated with the element.

The source is inherited from ancestor elements if none is specified. For this reason, always use this method rather than access the ``src`` attribute directly.

Returns:
str or None if not found


def hdg60(msg):
    d = hex2bin(data(msg))
    if (d[0] == '0'):
        return None
    sign = int(d[1])
    value = bin2int(d[2:12])
    if sign:
        value = (value - 1024)
    hdg = ((value * 90) / 512.0)
    if (hdg < 0):
        hdg = (360 + hdg)
    return round(hdg, 3)

Megnetic heading of aircraft

Args:
msg (String): 28 bytes hexadecimal message (BDS60) string

Returns:
float: heading in degrees to megnetic north (from 0 to 360)


def load(filename):
    if (not os.path.exists(filename)):
        LOG.error("load object - File '%s' does not exist.", filename)
        return None
    obj = None
    with open(filename, 'rb') as obj_file:
        obj = dill.load(obj_file)
    return obj

Load a pickled obj from the filesystem.

You better know what you expect from the given pickle, because we don't check it.

Args:
filename (str): The filename we load the object from.

Returns:
The object we were able to unpickle, else None.


def mount_share(share_path):

    sh_url = CFURLCreateWithString(None, share_path, None)

    open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}

    mount_options = {NetFS.kNetFSAllowSubMountsKey: True}

    result, output = NetFS.NetFSMountURLSync(sh_url, None, None, None,
                                             open_options, mount_options, None)

    if result != 0:
        raise Exception('Error mounting url "%s": %s' % (share_path, output))

    return str(output[0])

Mounts a share at /Volumes

Args:
share_path: String URL with all auth info to connect to file share.

Returns:
The mount point or raises an error.


def atmospheric_station_pressure(self, value=999999):
    if (value is not None):
        try:
            value = int(value)
        except ValueError:
            raise ValueError('value {} need to be of type int for field `atmospheric_station_pressure`'.format(value))
        if (value <= 31000):
            raise ValueError('value need to be greater 31000 for field `atmospheric_station_pressure`')
        if (value >= 120000):
            raise ValueError('value need to be smaller 120000 for field `atmospheric_station_pressure`')
    self._atmospheric_station_pressure = value

Corresponds to IDD Field `atmospheric_station_pressure`

Args:
value (int): value for IDD Field `atmospheric_station_pressure`
Unit: Pa
value > 31000
value < 120000
Missing value: 999999
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


def _parse_cli_args(argv):
    parser = argparse.ArgumentParser(description='Mobly Suite Executable.')
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-c', '--config', type=str, metavar='<PATH>', help='Path to the test configuration file.')
    group.add_argument('-l', '--list_tests', action='store_true', help='Print the names of the tests defined in a script without executing them.')
    parser.add_argument('--tests', '--test_case', nargs='+', type=str, metavar='[ClassA[_test_suffix][.test_a] ClassB[_test_suffix][.test_b] ...]', help='A list of test classes and optional tests to execute. Note: test_suffix based names are only supported when running by suite class')
    parser.add_argument('-tb', '--test_bed', nargs='+', type=str, metavar='[<TEST BED NAME1> <TEST BED NAME2> ...]', help='Specify which test beds to run tests on.')
    parser.add_argument('-v', '--verbose', action='store_true', help='Set console logger level to DEBUG')
    if not argv:
        argv = sys.argv[1:]
    return parser.parse_known_args(argv)[0]

Parses cli args that are consumed by Mobly.

Args:
argv: A list that is then parsed as cli args. If None, defaults to cli
input.

Returns:
Namespace containing the parsed args.


def get_nonmonotonic_neurites(neuron, tol=1e-6):

    return [n for n in neuron.neurites if not is_monotonic(n, tol)]

Get neurites that are not monotonic

Args:
neurite(Neurite): neurite to operate on
tol(float): the tolerance or the ratio

Returns:
list of neurites that do not satisfy monotonicity test


def init_state(self, node):
    raise NotImplementedError('Subclasses must implement this.')

State initialization function.

Optional to overload.

An in/out state slot will be created for each node in the graph. Subclasses
must overload this to control what that is initialized to.

Args:
node: Node


def register_agent(self, host, sweep_id=None, project_name=None):
    mutation = gql('\n        mutation CreateAgent(\n            $host: String!\n            $projectName: String!,\n            $entityName: String!,\n            $sweep: String!\n        ) {\n            createAgent(input: {\n                host: $host,\n                projectName: $projectName,\n                entityName: $entityName,\n                sweep: $sweep,\n            }) {\n                agent {\n                    id\n                }\n            }\n        }\n        ')
    if (project_name is None):
        project_name = self.settings('project')

    def no_retry_400(e):
        if (not isinstance(e, requests.HTTPError)):
            return True
        if (e.response.status_code != 400):
            return True
        body = json.loads(e.response.content)
        raise UsageError(body['errors'][0]['message'])
    response = self.gql(mutation, variable_values={'host': host, 'entityName': self.settings('entity'), 'projectName': project_name, 'sweep': sweep_id}, check_retry_fn=no_retry_400)
    return response['createAgent']['agent']

Register a new agent

Args:
host (str): hostname
persistent (bool): long running or oneoff
sweep (str): sweep id
project_name: (str): model that contains sweep


def _make_tags_vector(self, tags, bucket_length=None) -> np.ndarray:
    bucket_length = (bucket_length or len(tags))
    answer = np.zeros(shape=(bucket_length,), dtype=np.int32)
    for (i, tag) in enumerate(tags):
        answer[i] = self.tags.tok2idx(tag)
    return answer

Transforms a sentence of tags to Numpy array, which will be the network target.

Args:
tags: input sentence of tags
bucket_length: the width of the bucket

Returns:
A 2d array, answer[i][j] contains the index of j-th tag in i-th input sentence.


def byte_adaptor(fbuffer):
    if six.PY3:
        strings = fbuffer.read().decode('latin-1')
        fbuffer = six.StringIO(strings)
        return fbuffer
    else:
        return fbuffer

provides py3 compatibility by converting byte based
file stream to string based file stream

Arguments:
fbuffer: file like objects containing bytes

Returns:
string buffer


def accepts_scalar_input(func):

    @ignores_exc_tb(outer_wrapper=False)
    def wrp_asi(self, input_, *args, **kwargs):
        if util_iter.isiterable(input_):
            return func(self, input_, *args, **kwargs)
        else:
            ret = func(self, [input_], *args, **kwargs)
            if (ret is not None):
                return ret[0]
    wrp_asi = preserve_sig(wrp_asi, func)
    return wrp_asi

DEPRICATE in favor of accepts_scalar_input2
only accepts one input as vector

accepts_scalar_input is a decorator which expects to be used on class
methods.  It lets the user pass either a vector or a scalar to a function,
as long as the function treats everything like a vector. Input and output
is sanitized to the user expected format on return.

Args:
func (func):

Returns:
func: wrp_asi

CommandLine:
python -m utool.util_decor --test-accepts_scalar_input

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_decor import *  # NOQA
>>> @accepts_scalar_input
... def foobar(self, list_):
...     return [x + 1 for x in list_]
>>> self = None  # dummy self because this decorator is for classes
>>> assert 2 == foobar(self, 1)
>>> assert [2, 3] == foobar(self, [1, 2])


def ExamineEvent(self, mediator, event):

    if self._session_end_timestamp is None:
      self._session_end_timestamp = (
          event.timestamp + self._maximum_pause_microseconds)
      self._events_per_session.append(0)

    if event.timestamp > self._session_end_timestamp:
      self._session_counter += 1
      self._events_per_session.append(0)

    self._session_end_timestamp = (
        event.timestamp + self._maximum_pause_microseconds)

    self._events_per_session[-1] += 1

    label = 'session_{0:d}'.format(self._session_counter)
    event_tag = self._CreateEventTag(event, self._EVENT_TAG_COMMENT, [label])
    mediator.ProduceEventTag(event_tag)
    self._number_of_event_tags += 1

Analyzes an EventObject and tags it as part of a session.

Args:
mediator (AnalysisMediator): mediates interactions between analysis
plugins and other components, such as storage and dfvfs.
event (EventObject): event to examine.


def findSequenceOnDisk(cls, pattern, strictPadding=False):
    seq = cls(pattern)
    if ((seq.frameRange() == '') and (seq.padding() == '')):
        if os.path.isfile(pattern):
            return seq
    patt = seq.format('{dirname}{basename}*{extension}')
    ext = seq.extension()
    basename = seq.basename()
    pad = seq.padding()
    globbed = iglob(patt)
    if (pad and strictPadding):
        globbed = cls._filterByPaddingNum(globbed, seq.zfill())
        pad = cls.conformPadding(pad)
    matches = cls.yield_sequences_in_list(globbed)
    for match in matches:
        if ((match.basename() == basename) and (match.extension() == ext)):
            if (pad and strictPadding):
                match.setPadding(pad)
            return match
    msg = 'no sequence found on disk matching {0}'
    raise FileSeqException(msg.format(pattern))

Search for a specific sequence on disk.

The padding characters used in the `pattern` are used to filter the
frame values of the files on disk (if `strictPadding` is True).

Examples:
Find sequence matching basename and extension, and a wildcard for
any frame.
returns bar.1.exr bar.10.exr, bar.100.exr, bar.1000.exr, inclusive

>>> findSequenceOnDisk("seq/bar@@@@.exr")

Find exactly 4-padded sequence, i.e. seq/bar1-100#.exr
returns only frames bar1000.exr through bar9999.exr

>>> findSequenceOnDisk("seq/bar#.exr", strictPadding=True)

Args:
pattern (str): the sequence pattern being searched for
strictPadding (bool): if True, ignore files with padding length different from `pattern`

Returns:
str:

Raises:
:class:`.FileSeqException`: if no sequence is found on disk


def __init__(self,
               queues=queues_config.WORKER_LIST,
               threadpool_prefix="grr_threadpool",
               threadpool_size=None,
               token=None):

    logging.info("started worker with queues: %s", str(queues))
    self.queues = queues

    self.queued_flows = utils.TimeBasedCache(max_size=10, max_age=60)

    if token is None:
      raise RuntimeError("A valid ACLToken is required.")

    if threadpool_size is None:
      threadpool_size = config.CONFIG["Threadpool.size"]

    self.thread_pool = threadpool.ThreadPool.Factory(
        threadpool_prefix, min_threads=2, max_threads=threadpool_size)

    self.thread_pool.Start()

    self.token = token
    self.last_active = 0
    self.last_mh_lease_attempt = rdfvalue.RDFDatetime.FromSecondsSinceEpoch(0)

    self.well_known_flows = flow.WellKnownFlow.GetAllWellKnownFlows(token=token)

Constructor.

Args:
queues: The queues we use to fetch new messages from.
threadpool_prefix: A name for the thread pool used by this worker.
threadpool_size: The number of workers to start in this thread pool.
token: The token to use for the worker.

Raises:
RuntimeError: If the token is not provided.


def resize_file(fobj, diff, BUFFER_SIZE=(2 ** 16)):
    fobj.seek(0, 2)
    filesize = fobj.tell()
    if (diff < 0):
        if ((filesize + diff) < 0):
            raise ValueError
        fobj.truncate((filesize + diff))
    elif (diff > 0):
        try:
            while diff:
                addsize = min(BUFFER_SIZE, diff)
                fobj.write((b'\x00' * addsize))
                diff -= addsize
            fobj.flush()
        except IOError as e:
            if (e.errno == errno.ENOSPC):
                fobj.truncate(filesize)
            raise

Resize a file by `diff`.

New space will be filled with zeros.

Args:
fobj (fileobj)
diff (int): amount of size to change
Raises:
IOError


def func_str(func, args=[], kwargs={}, type_aliases=[], packed=False, packkw=None, truncate=False):
    import utool as ut
    truncatekw = {}
    argrepr_list = ([] if (args is None) else ut.get_itemstr_list(args, nl=False, truncate=truncate, truncatekw=truncatekw))
    kwrepr_list = ([] if (kwargs is None) else ut.dict_itemstr_list(kwargs, explicit=True, nl=False, truncate=truncate, truncatekw=truncatekw))
    repr_list = (argrepr_list + kwrepr_list)
    argskwargs_str = ', '.join(repr_list)
    _str = ('%s(%s)' % (meta_util_six.get_funcname(func), argskwargs_str))
    if packed:
        packkw_ = dict(textwidth=80, nlprefix='    ', break_words=False)
        if (packkw is not None):
            packkw_.update(packkw_)
        _str = packstr(_str, **packkw_)
    return _str

string representation of function definition

Returns:
str: a representation of func with args, kwargs, and type_aliases

Args:
func (function):
args (list): argument values (default = [])
kwargs (dict): kwargs values (default = {})
type_aliases (list): (default = [])
packed (bool): (default = False)
packkw (None): (default = None)

Returns:
str: func_str

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

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import *  # NOQA
>>> func = byte_str
>>> args = [1024, 'MB']
>>> kwargs = dict(precision=2)
>>> type_aliases = []
>>> packed = False
>>> packkw = None
>>> _str = func_str(func, args, kwargs, type_aliases, packed, packkw)
>>> result = _str
>>> print(result)
byte_str(1024, 'MB', precision=2)


def business_days_in_period(self, date_tensor, period_tensor):
    pass

Calculates number of business days in a period.

Includes the dates in `date_tensor`, but excludes final dates resulting from
addition of `period_tensor`.

Args:
date_tensor: DateTensor of starting dates.
period_tensor: PeriodTensor, should be broadcastable to `date_tensor`.

Returns:
An int32 Tensor with the number of business days in given periods that
start at given dates.


def consume(generator):
    if hasattr(generator, '__next__'):
        return list(generator)
    if (not PY_35):
        raise RuntimeError('paco: asynchronous iterator protocol not supported')
    buf = []
    while True:
        try:
            buf.append((yield from generator.__anext__()))
        except StopAsyncIteration:
            break
    return buf

Helper function to consume a synchronous or asynchronous generator.

Arguments:
generator (generator|asyncgenerator): generator to consume.

Returns:
list


def _detect_encoding(data=None):
    import locale
    enc_list = ['utf-8', 'latin-1', 'iso8859-1', 'iso8859-2', 'utf-16', 'cp720']
    code = locale.getpreferredencoding(False)
    if (data is None):
        return code
    if (code.lower() not in enc_list):
        enc_list.insert(0, code.lower())
    for c in enc_list:
        try:
            for line in data:
                line.decode(c)
        except (UnicodeDecodeError, UnicodeError, AttributeError):
            continue
        return c
    print('Encoding not detected. Please pass encoding value manually')

Return the default system encoding. If data is passed, try
to decode the data with the default system encoding or from a short
list of encoding types to test.

Args:
data - list of lists
Returns:
enc - system encoding


def process_runway_configs(runway_dir=''):
    LOG.info('Processing application.json files from local directory "%s".', runway_dir)
    file_lookup = FileLookup(runway_dir=runway_dir)
    app_configs = process_configs(file_lookup, 'application-master-{env}.json', 'pipeline.json')
    return app_configs

Read the _application.json_ files.

Args:
runway_dir (str): Name of runway directory with app.json files.

Returns:
collections.defaultdict: Configurations stored for each environment
found.


def has_service_by_name(self, name):
    return name in self._service_objects

Checks if the manager has a service registered with a specific name.

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

Returns:
True if a service is registered with the specified name, False
otherwise.


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

Request detailed information about the execution status of a stage of the job. EXPERIMENTAL. This API is subject to change or removal without notice.

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


def __init__(self, count, string_length):

    self._count = count
    self._string_length = string_length

Initialize input reader.

Args:
count: number of entries this shard should generate.
string_length: the length of generated random strings.


def dummyctrl(self, r, ctrl):
    dv = DummyVertex(r)
    (dv.view.w, dv.view.h) = (self.dw, self.dh)
    self.grx[dv] = dv
    dv.ctrl = ctrl
    ctrl[r] = dv
    self.layers[r].append(dv)
    return dv

creates a DummyVertex at rank r inserted in the ctrl dict
of the associated edge and layer.

Arguments:
r (int): rank value
ctrl (dict): the edge's control vertices

Returns:
DummyVertex : the created DummyVertex.


def UpdateNumberOfEventReports(
      self, number_of_consumed_reports, number_of_produced_reports):

    consumed_reports_delta = 0
    if number_of_consumed_reports is not None:
      if number_of_consumed_reports < self.number_of_consumed_reports:
        raise ValueError(
            'Number of consumed reports smaller than previous update.')

      consumed_reports_delta = (
          number_of_consumed_reports - self.number_of_consumed_reports)

      self.number_of_consumed_reports = number_of_consumed_reports
      self.number_of_consumed_reports_delta = consumed_reports_delta

    produced_reports_delta = 0
    if number_of_produced_reports is not None:
      if number_of_produced_reports < self.number_of_produced_reports:
        raise ValueError(
            'Number of produced reports smaller than previous update.')

      produced_reports_delta = (
          number_of_produced_reports - self.number_of_produced_reports)

      self.number_of_produced_reports = number_of_produced_reports
      self.number_of_produced_reports_delta = produced_reports_delta

    return consumed_reports_delta > 0 or produced_reports_delta > 0

Updates the number of event reports.

Args:
number_of_consumed_reports (int): total number of event reports consumed
by the process.
number_of_produced_reports (int): total number of event reports produced
by the process.

Returns:
bool: True if either number of event reports has increased.

Raises:
ValueError: if the consumed or produced number of event reports is
smaller than the value of the previous update.


def add_string_pairs_from_button_element(xib_file, results, button, special_ui_components_prefix):
    button_entry_comment = extract_element_internationalized_comment(button)
    if (button_entry_comment is None):
        return
    for state in button.getElementsByTagName('state'):
        state_name = state.attributes['key'].value
        state_entry_comment = (((button_entry_comment + ' - ') + state_name) + ' state of button')
        if (not add_string_pairs_from_attributed_ui_element(results, state, state_entry_comment)):
            try:
                button_entry_key = state.attributes['title'].value
            except KeyError:
                try:
                    button_entry_key = state.getElementsByTagName('string')[0].firstChild.nodeValue
                except Exception:
                    continue
            results.append((button_entry_key, state_entry_comment))
    warn_if_element_not_of_class(button, 'Button', special_ui_components_prefix)

Adds strings pairs from a button xib element.

Args:
xib_file (str): Path to the xib file.
results (list): The list to add the results to.
button(element): The button element from the xib, to extract the string pairs from.
special_ui_components_prefix(str): A custom prefix for internationalize component to allow (default is only JT)


def _build(self, inputs):
    shape_inputs = inputs.get_shape().as_list()
    rank = len(shape_inputs)
    max_dim = (np.max(self._dims) + 1)
    if (rank < max_dim):
        raise ValueError('Rank of inputs must be at least {}.'.format(max_dim))
    full_begin = ([0] * rank)
    full_size = ([(- 1)] * rank)
    for (dim, begin, size) in zip(self._dims, self._begin, self._size):
        full_begin[dim] = begin
        full_size[dim] = size
    return tf.slice(inputs, begin=full_begin, size=full_size)

Connects the SliceByDim module into the graph.

Args:
inputs: `Tensor` to slice. Its rank must be greater than the maximum
dimension specified in `dims` (plus one as python is 0 indexed).

Returns:
The sliced tensor.

Raises:
ValueError: If `inputs` tensor has insufficient rank.


def _add_future(cls, future):

    if cls._local._activated:
      cls._local._in_order_futures.add(future)

Adds a future to the list of in-order futures thus far.

Args:
future: The future to add to the list.


def _PrintStorageInformationAsJSON(self, storage_reader):

    serializer = json_serializer.JSONAttributeContainerSerializer
    storage_counters = self._CalculateStorageCounters(storage_reader)
    storage_counters_json = json.dumps(storage_counters)
    self._output_writer.Write('{')
    self._output_writer.Write('"storage_counters": {0:s}'.format(
        storage_counters_json))
    self._output_writer.Write(',\n')
    self._output_writer.Write(' "sessions": {')
    for index, session in enumerate(storage_reader.GetSessions()):
      json_string = serializer.WriteSerialized(session)
      if index != 0:
        self._output_writer.Write(',\n')
      self._output_writer.Write('"session_{0:s}": {1:s} '.format(
          session.identifier, json_string))
    self._output_writer.Write('}}')

Writes a summary of sessions as machine-readable JSON.

Args:
storage_reader (StorageReader): storage reader.


def _request(self, domain, type_name, search_command, db_method, body=None):

        headers = {'Content-Type': 'application/json', 'DB-Method': db_method}
        search_command = self._clean_datastore_path(search_command)
        url = '/v2/exchange/db/{}/{}/{}'.format(domain, type_name, search_command)
        r = self.tcex.session.post(url, data=body, headers=headers, params=self._params)

        data = []
        status = 'Failed'
        if not r.ok or 'application/json' not in r.headers.get('content-type', ''):
            self.tcex.handle_error(350, [r.status_code, r.text])
        data = r.json()
        status = 'Success'

        return {'data': data, 'response': r, 'status': status}

Make the API request for a Data Store CRUD operation

Args:
domain (string): One of 'local', 'organization', or 'system'.
type_name (string): This is a free form index type name. The ThreatConnect API will use
this resource verbatim.
search_command (string): Search command to pass to ES.
db_method (string): The DB method 'DELETE', 'GET', 'POST', or 'PUT'
body (dict): JSON body


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

        def operate_site(site):
            new_cart = symmop.operate(site.coords)
            new_frac = self._lattice.get_fractional_coords(new_cart)
            return PeriodicSite(site.species, new_frac, self._lattice, properties=site.properties)
    else:
        new_latt = np.dot(symmop.rotation_matrix, self._lattice.matrix)
        self._lattice = Lattice(new_latt)

        def operate_site(site):
            return PeriodicSite(site.species, symmop.operate(site.frac_coords), self._lattice, properties=site.properties)
    self._sites = [operate_site(s) for s in self._sites]

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

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


def GetMessages(self, formatter_mediator, event):

    if self.DATA_TYPE != event.data_type:
      raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
          event.data_type))

    event_values = event.CopyToDict()

    primary_url = event_values['primary_url']
    secondary_url = event_values['secondary_url']

    if primary_url == '':
      subject = 'local file'

    elif secondary_url in (primary_url, '*'):
      subject = primary_url

    elif secondary_url == '':
      subject = '{0:s} embedded in local file'.format(primary_url)

    else:
      subject = '{0:s} embedded in {1:s}'.format(primary_url, secondary_url)

    event_values['subject'] = subject

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

Args:
formatter_mediator (FormatterMediator): mediates the interactions
between formatters and other components, such as storage and Windows
EventLog resources.
event (EventObject): event.

Returns:
tuple(str, str): formatted message string and short message string.

Raises:
WrongFormatter: if the event object cannot be formatted by the formatter.


def remove(self, key):
    data = self._load_file()
    del data[key]
    self._save_file(data)

Remove a key from the data store

Args:
key (string): The key to remove

Raises:
KeyError: if the key was not found


def _from_tensor_list_helper(decode_fn, element_spec, tensor_list):
    flat_specs = nest.flatten(element_spec)
    flat_spec_lengths = [len(spec._flat_tensor_specs) for spec in flat_specs]
    if sum(flat_spec_lengths) != len(tensor_list):
        raise ValueError('Expected {} tensors but got {}.'.format(sum(flat_spec_lengths), len(tensor_list)))
    i = 0
    flat_ret = []
    for component_spec, num_flat_values in zip(flat_specs, flat_spec_lengths):
        value = tensor_list[i:i + num_flat_values]
        flat_ret.append(decode_fn(component_spec, value))
        i += num_flat_values
    return nest.pack_sequence_as(element_spec, flat_ret)

Returns an element constructed from the given spec and tensor list.

Args:
decode_fn: Method that constructs an element component from the element spec
component and a tensor list.
element_spec: A nested structure of `tf.TypeSpec` objects representing to
element type specification.
tensor_list: A list of tensors to use for constructing the value.

Returns:
An element constructed from the given spec and tensor list.

Raises:
ValueError: If the number of tensors needed to construct an element for
the given spec does not match the given number of tensors.


def decode_csv(csv_string, column_names):

  import csv
  r = next(csv.reader([csv_string]))
  if len(r) != len(column_names):
    raise ValueError('csv line %s does not have %d columns' % (csv_string, len(column_names)))
  return {k: v for k, v in zip(column_names, r)}

Parse a csv line into a dict.

Args:
csv_string: a csv string. May contain missing values "a,,c"
column_names: list of column names

Returns:
Dict of {column_name, value_from_csv}. If there are missing values,
value_from_csv will be ''.


def assertAllInRange(self, target, lower_bound, upper_bound, open_lower_bound=False, open_upper_bound=False):
    target = self._GetNdArray(target)
    if not (np.issubdtype(target.dtype, np.floating) or np.issubdtype(target.dtype, np.integer)):
        raise AssertionError('The value of %s does not have an ordered numeric type, instead it has type: %s' % (target, target.dtype))
    nan_subscripts = np_where(np.isnan(target))
    if np.size(nan_subscripts):
        raise AssertionError('%d of the %d element(s) are NaN. Subscripts(s) and value(s) of the NaN element(s):\n' % (len(nan_subscripts[0]), np.size(target)) + '\n'.join(self._format_subscripts(nan_subscripts, target)))
    range_str = ('(' if open_lower_bound else '[') + str(lower_bound) + ', ' + str(upper_bound) + (')' if open_upper_bound else ']')
    violations = np.less_equal(target, lower_bound) if open_lower_bound else np.less(target, lower_bound)
    violations = np.logical_or(violations, np.greater_equal(target, upper_bound) if open_upper_bound else np.greater(target, upper_bound))
    violation_subscripts = np_where(violations)
    if np.size(violation_subscripts):
        raise AssertionError('%d of the %d element(s) are outside the range %s. ' % (len(violation_subscripts[0]), np.size(target), range_str) + 'Subscript(s) and value(s) of the offending elements:\n' + '\n'.join(self._format_subscripts(violation_subscripts, target)))

Assert that elements in a Tensor are all in a given range.

Args:
target: The numpy `ndarray`, or anything that can be converted into a
numpy `ndarray` (including Tensor).
lower_bound: lower bound of the range
upper_bound: upper bound of the range
open_lower_bound: (`bool`) whether the lower bound is open (i.e., > rather
than the default >=)
open_upper_bound: (`bool`) whether the upper bound is open (i.e., < rather
than the default <=)

Raises:
AssertionError:
if the value tensor does not have an ordered numeric type (float* or
int*), or
if there are nan values, or
if any of the elements do not fall in the specified range.


def get_structure_seqs(pdb_file, file_type):

    my_structure = StructureIO(pdb_file)
    model = my_structure.first_model

    structure_seqs = {}

    for chain in model:
        chain_seq = ''
        tracker = 0

        for res in chain.get_residues():

            if Polypeptide.is_aa(res, standard=True):
                full_id = res.get_full_id()
                end_tracker = full_id[3][1]
                i_code = full_id[3][2]
                aa = Polypeptide.three_to_one(res.get_resname())

                if end_tracker != (tracker + 1):
                    if i_code != ' ':
                        chain_seq += aa
                        tracker = end_tracker + 1
                        continue
                    else:
                        chain_seq += 'X' * (end_tracker - tracker - 1)

                chain_seq += aa
                tracker = end_tracker

            else:
                continue

        structure_seqs[chain.get_id()] = chain_seq

    return structure_seqs

Get a dictionary of a PDB file's sequences.

Special cases include:
- Insertion codes. In the case of residue numbers like "15A", "15B", both residues are written out. Example: 9LPR
- HETATMs. Currently written as an "X", or unknown amino acid.

Args:
pdb_file: Path to PDB file

Returns:
dict: Dictionary of:
{chain_id: sequence}


def _GetDateValuesWithEpoch(self, number_of_days, date_time_epoch):

    return self._GetDateValues(
        number_of_days, date_time_epoch.year, date_time_epoch.month,
        date_time_epoch.day_of_month)

Determines date values.

Args:
number_of_days (int): number of days since epoch.
date_time_epoch (DateTimeEpoch): date and time of the epoch.

Returns:
tuple[int, int, int]: year, month, day of month.


def __init__(self, endpoint_name, sagemaker_session=None):

        super(PyTorchPredictor, self).__init__(endpoint_name, sagemaker_session, npy_serializer, numpy_deserializer)

Initialize an ``PyTorchPredictor``.

Args:
endpoint_name (str): The name of the endpoint to perform inference on.
sagemaker_session (sagemaker.session.Session): Session object which manages interactions with
Amazon SageMaker APIs and any other AWS services needed. If not specified, the estimator creates one
using the default AWS configuration chain.


def astimezone(self, tzinfo):

    assert self.tzinfo is not None

    tzinfo = _tzinfome(tzinfo)

    d = self.asdatetime(naive=False).astimezone(tzinfo)
    return type(self)(d)

Returns a version of this timestamp converted to the given timezone.

Args:
tzinfo: Either a datetime.tzinfo object or a string (which will be looked
up in pytz.

Returns:
A datetime_tz object in the given timezone.


def noise_new(dim: int, h: float=NOISE_DEFAULT_HURST, l: float=NOISE_DEFAULT_LACUNARITY, random: Optional[tcod.random.Random]=None) -> tcod.noise.Noise:
    return tcod.noise.Noise(dim, hurst=h, lacunarity=l, seed=random)

Return a new Noise instance.

Args:
dim (int): Number of dimensions.  From 1 to 4.
h (float): The hurst exponent.  Should be in the 0.0-1.0 range.
l (float): The noise lacunarity.
random (Optional[Random]): A Random instance, or None.

Returns:
Noise: The new Noise instance.


def RepackTemplate(self, template_path, output_dir, upload=False, token=None, sign=False, context=None, signed_template=False):
    orig_config = config.CONFIG
    repack_config = RepackConfig()
    print(('Repacking template: %s' % template_path))
    config.CONFIG = repack_config.GetConfigFromTemplate(template_path)
    result_path = None
    try:
        repack_context = config.CONFIG['Template.build_context']
        if context:
            repack_context.extend(context)
        output_path = os.path.join(output_dir, config.CONFIG.Get('ClientRepacker.output_filename', context=repack_context))
        print(('Using context: %s and labels: %s' % (repack_context, config.CONFIG.Get('Client.labels', context=repack_context))))
        try:
            signer = None
            if sign:
                signer = self.GetSigner(repack_context)
            builder_obj = self.GetRepacker(context=repack_context, signer=signer)
            builder_obj.signed_template = signed_template
            result_path = builder_obj.MakeDeployableBinary(template_path, output_path)
        except Exception:
            logging.exception('Repacking template %s failed:', template_path)
        if result_path:
            print(('Repacked into %s' % result_path))
            if upload:
                from grr_response_server import maintenance_utils
                client_platform = config.CONFIG.Get('Client.platform', context=repack_context)
                repack_basename = config.CONFIG.Get('ClientRepacker.output_basename', context=repack_context)
                repack_extension = config.CONFIG.Get('ClientBuilder.output_extension', context=repack_context)
                repack_filename = (repack_basename + repack_extension)
                binary_urn = rdfvalue.RDFURN('aff4:/config/executables').Add(client_platform).Add('installers').Add(repack_filename)
                maintenance_utils.UploadSignedConfigBlob(open(result_path, 'rb').read(((100 * 1024) * 1024)), binary_urn, client_context=repack_context, token=token)
        else:
            print(('Failed to repack %s.' % template_path))
    finally:
        config.CONFIG = orig_config
    return result_path

Repack binaries based on the configuration.

We repack all templates in the templates directory. We expect to find only
functioning templates, all other files should be removed. Each template
contains a build.yaml that specifies how it was built and how it should be
repacked.

Args:
template_path: template path string
output_dir: Output files will be put in this directory.
upload: If specified we also upload the repacked binary into the
token: Token to use when uploading to the datastore.
sign: If true, we want to digitally sign the installer.
context: Array of context strings
signed_template: If true, the libraries in the template are already
signed. This is only used for windows when repacking the template
multiple times.

Returns:
A list of output installers generated.


def upload(self, title, description='', keywords='', developer_tags=None, access_control=AccessControl.Public):
    if (not self.authenticated):
        raise ApiError(_('Authentication is required'))
    my_media_group = gdata.media.Group(title=gdata.media.Title(text=title), description=gdata.media.Description(description_type='plain', text=description), keywords=gdata.media.Keywords(text=keywords), category=[gdata.media.Category(text='Autos', scheme='http:
    extension = self._access_control(access_control, my_media_group)
    video_entry = gdata.youtube.YouTubeVideoEntry(media=my_media_group, extension_elements=extension)
    if developer_tags:
        video_entry.AddDeveloperTags(developer_tags)
    response = Api.yt_service.GetFormUploadToken(video_entry)
    post_url = response[0]
    youtube_token = response[1]
    return {'post_url': post_url, 'youtube_token': youtube_token}

Browser based upload
Creates the video entry and meta data to initiate a browser upload

Authentication is needed

Params:
title: string
description: string
keywords: comma seperated string
developer_tags: tuple

Return:
dict contains post_url and youtube_token. i.e { 'post_url': post_url, 'youtube_token': youtube_token }

Raises:
ApiError: on no authentication


def get_modname_from_modpath(module_fpath):

    modsubdir_list = get_module_subdir_list(module_fpath)
    modname = '.'.join(modsubdir_list)
    modname = modname.replace('.__init__', '').strip()
    modname = modname.replace('.__main__', '').strip()
    return modname

returns importable name from file path

get_modname_from_modpath

Args:
module_fpath (str): module filepath

Returns:
str: modname

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_path import *  # NOQA
>>> import utool as ut
>>> module_fpath = ut.util_path.__file__
>>> modname = ut.get_modname_from_modpath(module_fpath)
>>> result = modname
>>> print(result)
utool.util_path


def get_and_setattr(cls, id, **kwargs):

        model = cls.get(id)
        for k, v in cls._preprocess_params(kwargs).items():
            setattr(model, k, v)
        return model

Returns an updated instance of the service's model class.

Args:
model: the model to update
**kwargs: update parameters


def __add_action(self, relative_directory, action):
    generator_action_container = self.__actions.retrieve_element_or_default(relative_directory, None)
    if (generator_action_container is None):
        generator_action_container = GeneratorActionContainer()
        generator_action_container.add_generator_action(action)
        self.__actions.add_element(location=relative_directory, element=generator_action_container)
    else:
        generator_action_container.add_generator_action(action)

Add action into the dictionary of actions.

Args:
relative_directory:
action:


class OneFormerTransformerDecoderOutput(BaseModelOutput):
    object_queries: Optional[torch.FloatTensor] = None
    contrastive_logits: Optional[torch.FloatTensor] = None
    prediction_masks: Optional[torch.FloatTensor] = None
    prediction_class: Optional[torch.FloatTensor] = None
    auxiliary_predictions: Optional[Tuple[Dict[str, torch.FloatTensor]]] = None

Base class for outputs of the Transformer decoder. This class adds attributes for class predictions, mask
predictions and contrastive logits to BaseModelOutputWithCrossAttentions.

Args:
object_logits (`torch.FloatTensor` of shape `(batch_size, num_queries, hidden_dim)`):
Queries representation for the region proposals.
contrastive_logits (`torch.FloatTensor` of shape `(batch_size, num_queries, hidden_dim)`):
Queries representation for the contrastive loss.
prediction_masks (`torch.FloatTensor` of shape `(batch_size, num_queries, height, width)`):
Mask predictions from last layer of the transformer decoder.
prediction_class (`torch.FloatTensor` of shape `(batch_size, num_queries, num_classes+1)`):
Class predictions from last layer of the transformer decoder.
auxiliary_predictions (Tuple of Dict of `str, torch.FloatTensor`, *optional*):
Tuple of class and mask predictions from each layer of the transformer decoder.


def _get_clang_major_version(path_to_clang: str) -> int:
    logging.info('Running echo __clang_major__ | %s -E -P -', path_to_clang)
    clang_version_proc = subprocess.run([path_to_clang, '-E', '-P', '-'], input='__clang_major__', check=True, capture_output=True, text=True)
    major_version = int(clang_version_proc.stdout)
    logging.info('%s reports major version %s.', path_to_clang, major_version)
    return major_version

Gets the major version of the clang at `path_to_clang`.

Args:
path_to_clang: Path to a clang executable

Returns:
The major version.


def create_transaction(self, to_account):

        from_account = self.statement_import.bank_account

        transaction = Transaction.objects.create()
        Leg.objects.create(
            transaction=transaction, account=from_account, amount=+(self.amount * -1)
        )
        Leg.objects.create(transaction=transaction, account=to_account, amount=-(self.amount * -1))

        transaction.date = self.date
        transaction.save()

        self.transaction = transaction
        self.save()
        return transaction

Create a transaction for this statement amount and account, into to_account

This will also set this StatementLine's ``transaction`` attribute to the newly
created transaction.

Args:
to_account (Account): The account the transaction is into / out of.

Returns:
Transaction: The newly created (and committed) transaction.


def push_image(registry, image):

    values = {
        'registry': registry,
        'image': image['name'],
    }

    log.info("Pushing <33>{registry}<35>/{image}".format(**values))
    shell.run('docker push {registry}/{image}'.format(**values))

Push the given image to selected repository.

Args:
registry (str):
The name of the registry we're pushing to. This is the address of
the repository without the protocol specification (no http(s)://)
image (dict[str, Any]):
The dict containing the information about the image. This is the
same dictionary as defined in DOCKER_IMAGES variable.


def get_available_versions(self, project_name):
    available_versions = self.pypi_client.package_releases(project_name)
    if (not available_versions):
        available_versions = self.pypi_client.package_releases(project_name.capitalize())
    return dict(((self._parse_version(version), version) for version in available_versions))

Query PyPI to see if package has any available versions.

Args:
project_name (str): The name the project on PyPI.

Returns:
dict: Where keys are tuples of parsed versions and values are the
versions returned by PyPI.


def CreateUnit(self, parent=None, value=None, bid_amount=None):

    unit = {
        'xsi_type': 'ProductPartition',
        'partitionType': 'UNIT'
    }

    if parent is not None:
      unit['parentCriterionId'] = parent['id']
      unit['caseValue'] = value

    if bid_amount is not None and bid_amount > 0:

      bidding_strategy_configuration = {
          'bids': [{
              'xsi_type': 'CpcBid',
              'bid': {
                  'xsi_type': 'Money',
                  'microAmount': str(bid_amount)
              }
          }]
      }

      adgroup_criterion = {
          'xsi_type': 'BiddableAdGroupCriterion',
          'biddingStrategyConfiguration': bidding_strategy_configuration
      }
    else:
      adgroup_criterion = {
          'xsi_type': 'NegativeAdGroupCriterion'
      }

    adgroup_criterion['adGroupId'] = self.adgroup_id
    adgroup_criterion['criterion'] = unit

    self.CreateAddOperation(adgroup_criterion)

    return unit

Creates a unit node.

Args:
parent: The node that should be this node's parent.
value: The value being partitioned on.
bid_amount: The amount to bid for matching products, in micros.
Returns:
A new unit node.


def postings(self, quarter, stats_counter=None):
    logging.info('Finding postings for %s', quarter)
    for posting in self._iter_postings(quarter):
        transformed = self._transform(posting)
        transformed['id'] = '{}_{}'.format(self.partner_id, self._id(posting))
        if stats_counter:
            stats_counter.track(input_document=posting, output_document=transformed)
        (yield transformed)

Yield job postings in common schema format

Args:
quarter (str) The quarter, in format '2015Q1'
stats_counter (object, optional) A counter that can track both
input and output documents using a 'track' method.


def getOrderedLinks(self, session):
    streamLinks = session.query(StreamLink).filter((StreamLink.channelInputFile == self)).order_by(StreamLink.linkNumber).all()
    return streamLinks

Retrieve the links in the order of the link number.

Args:
session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session object bound to PostGIS enabled database.

Returns:
list: A list of :class:`.StreamLink` objects.


def ParseFileObject(self, parser_mediator, file_object):

    msiecf_file = pymsiecf.file()
    msiecf_file.set_ascii_codepage(parser_mediator.codepage)

    try:
      msiecf_file.open_file_object(file_object)
    except IOError as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to open file with error: {0!s}'.format(exception))
      return

    try:
      self._ParseItems(parser_mediator, msiecf_file)
    finally:
      msiecf_file.close()

Parses a MSIE Cache File (MSIECF) file-like object.

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


def convert_constant(params, w_name, scope_name, inputs, layers, weights, names):

    print('Converting constant ...')

    params_list = params['value'].numpy()

    def target_layer(x, value=params_list):
        return tf.constant(value.tolist(), shape=value.shape)

    lambda_layer = keras.layers.Lambda(target_layer)
    layers[scope_name + '_np'] = params_list
    layers[scope_name] = lambda_layer(layers[list(layers.keys())[0]])

Convert constant layer.

Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers


def verify_certs_chain(certs_chain: List[crypto.X509], amazon_cert: crypto.X509) -> bool:
    store = crypto.X509Store()
    for cert in certs_chain:
        store.add_cert(cert)
    default_verify_paths = ssl.get_default_verify_paths()
    default_verify_file = default_verify_paths.cafile
    default_verify_file = (Path(default_verify_file).resolve() if default_verify_file else None)
    default_verify_path = default_verify_paths.capath
    default_verify_path = (Path(default_verify_path).resolve() if default_verify_path else None)
    ca_files = ([ca_file for ca_file in default_verify_path.iterdir()] if default_verify_path else [])
    if default_verify_file:
        ca_files.append(default_verify_file)
    for ca_file in ca_files:
        ca_file: Path
        if ca_file.is_file():
            with ca_file.open('r', encoding='ascii') as crt_f:
                ca_certs_txt = crt_f.read()
                ca_certs = extract_certs(ca_certs_txt)
                for cert in ca_certs:
                    store.add_cert(cert)
    ssl_context = ssl.create_default_context()
    der_certs = ssl_context.get_ca_certs(binary_form=True)
    pem_certs = '\n'.join([ssl.DER_cert_to_PEM_cert(der_cert) for der_cert in der_certs])
    ca_certs = extract_certs(pem_certs)
    for ca_cert in ca_certs:
        store.add_cert(ca_cert)
    store_context = crypto.X509StoreContext(store, amazon_cert)
    try:
        store_context.verify_certificate()
        result = True
    except crypto.X509StoreContextError:
        result = False
    return result

Verifies if Amazon and additional certificates creates chain of trust to a root CA.

Args:
certs_chain: List of pycrypto X509 intermediate certificates from signature chain URL.
amazon_cert: Pycrypto X509 Amazon certificate.

Returns:
result: True if verification was successful, False if not.


def ffn_expert_fn(input_size, hidden_sizes, output_size, hidden_activation=tf.nn.relu):

    def my_fn(x):
        layer_sizes = (([input_size] + hidden_sizes) + [output_size])
        for i in range((1 + len(hidden_sizes))):
            w = tf.get_variable(('w_%d' % i), layer_sizes[i:(i + 2)], tf.float32)
            x = tf.matmul(x, w)
            if (i < len(hidden_sizes)):
                x = hidden_activation(x)
            if (layer_sizes[i] != input_size):
                x *= ((layer_sizes[i] / float(input_size)) ** (- 0.5))
        return x
    return my_fn

Returns a function that creates a feed-forward network.

Use this function to create the expert_fn argument to distributed_moe.

Args:
input_size: an integer
hidden_sizes: a list of integers
output_size: an integer
hidden_activation: a unary function.

Returns:
a unary function


def Sample(self, profile_name, used_memory):

    sample_time = time.time()
    sample = '{0:f}\t{1:s}\t{2:d}\n'.format(
        sample_time, profile_name, used_memory)
    self._WritesString(sample)

Takes a sample for profiling.

Args:
profile_name (str): name of the profile to sample.
used_memory (int): amount of used memory in bytes.


def DeserializeFromBufer(buffer, offset=0):

        mstream = StreamManager.GetStream(buffer)
        reader = BinaryReader(mstream)
        tx = Transaction.DeserializeFrom(reader)

        StreamManager.ReleaseStream(mstream)
        return tx

Deserialize object instance from the specified buffer.

Args:
buffer (bytes, bytearray, BytesIO): (Optional) data to create the stream from.
offset: UNUSED

Returns:
Transaction:


class FastSpeech2ConformerEncoder(nn.Module):

    def __init__(self, config: FastSpeech2ConformerConfig, module_config, use_encoder_input_layer=False):
        super().__init__()
        self.embed = None
        if use_encoder_input_layer:
            self.embed = nn.Embedding(num_embeddings=config.vocab_size, embedding_dim=config.hidden_size, padding_idx=0)
        self.pos_enc = FastSpeech2ConformerRelPositionalEncoding(config, module_config)
        self.conformer_layers = nn.ModuleList([FastSpeech2ConformerEncoderLayer(config, module_config) for _ in range(module_config['layers'])])

    def forward(self, input_tensor: torch.LongTensor, attention_mask: Optional[bool]=None, output_hidden_states: Optional[bool]=None, output_attentions: Optional[bool]=False, return_dict: Optional[bool]=None):

        feature_representation = input_tensor
        if self.embed is not None:
            feature_representation = self.embed(feature_representation)
        hidden_states, pos_emb = self.pos_enc(feature_representation)
        all_hidden_states = () if output_hidden_states else None
        all_self_attentions = () if output_attentions else None
        for conformer_layer in self.conformer_layers:
            if output_hidden_states:
                all_hidden_states = all_hidden_states + (hidden_states,)
            layer_outputs = conformer_layer(hidden_states, pos_emb, attention_mask, output_attentions)
            hidden_states = layer_outputs[0]
            if output_attentions:
                all_self_attentions = all_self_attentions + (layer_outputs[1],)
        if output_hidden_states:
            all_hidden_states = all_hidden_states + (hidden_states,)
        if not return_dict:
            return tuple((v for v in [hidden_states, all_hidden_states, all_self_attentions] if v is not None))
        return BaseModelOutput(last_hidden_state=hidden_states, hidden_states=all_hidden_states, attentions=all_self_attentions)

FastSpeech2ConformerEncoder encoder module.

Args:
config (`FastSpeech2ConformerConfig`):
FastSpeech2ConformerConfig instance.
module_config (`dict`):
Dictionary containing the encoder or decoder module configuration from the `FastSpeech2ConformerConfig`.
use_encoder_input_layer (`bool`, *optional*, defaults to `False`):
Input layer type.


async def leave(self):
    is_group_conversation = (self._conversation.type == hangouts_pb2.CONVERSATION_TYPE_GROUP)
    try:
        if is_group_conversation:
            (await self._client.remove_user(hangouts_pb2.RemoveUserRequest(request_header=self._client.get_request_header(), event_request_header=self._get_event_request_header())))
        else:
            (await self._client.delete_conversation(hangouts_pb2.DeleteConversationRequest(request_header=self._client.get_request_header(), conversation_id=hangouts_pb2.ConversationId(id=self.id_), delete_upper_bound_timestamp=parsers.to_timestamp(datetime.datetime.now(tz=datetime.timezone.utc)))))
    except exceptions.NetworkError as e:
        logger.warning('Failed to leave conversation: {}'.format(e))
        raise

Leave this conversation.

Raises:
.NetworkError: If conversation cannot be left.


def _DrawTrips(self,triplist,colpar=""):

    stations = []
    if not self._stations and triplist:
      self._stations = self._CalculateYLines(self._TravelTimes(triplist))
      if not self._stations:
        self._AddWarning("Failed to use traveltimes for graph")
        self._stations = self._CalculateYLines(self._Uniform(triplist))
        if not self._stations:
          self._AddWarning("Failed to calculate station distances")
          return

    stations = self._stations
    tmpstrs = []
    servlist = []
    for t in triplist:
      if not colpar:
        if t.service_id not in servlist:
          servlist.append(t.service_id)
        shade = int(servlist.index(t.service_id) * (200/len(servlist))+55)
        color = "
      else:
        color=colpar

      start_offsets = [0]
      first_stop = t.GetTimeStops()[0]

      for j,freq_offset in enumerate(start_offsets):
        if j>0 and not colpar:
          color="purple"
        scriptcall = 'onmouseover="LineClick(\'%s\',\'Trip %s starting %s\')"' % (t.trip_id,
            t.trip_id, transitfeed.FormatSecondsSinceMidnight(t.GetStartTime()))
        tmpstrhead = '<polyline class="T" id="%s" stroke="%s" %s points="' % \
          (str(t.trip_id),color, scriptcall)
        tmpstrs.append(tmpstrhead)

        for i, s in enumerate(t.GetTimeStops()):
          arr_t = s[0]
          dep_t = s[1]
          if arr_t is None or dep_t is None:
            continue
          arr_x = int(arr_t/3600.0 * self._hour_grid) - self._hour_grid * self._offset
          dep_x = int(dep_t/3600.0 * self._hour_grid) - self._hour_grid * self._offset
          tmpstrs.append("%s,%s " % (int(arr_x+20), int(stations[i]+20)))
          tmpstrs.append("%s,%s " % (int(dep_x+20), int(stations[i]+20)))
        tmpstrs.append('" />')
    return "".join(tmpstrs)

Generates svg polylines for each transit trip.

Args:
# Class Trip is defined in transitfeed.py
[Trip, Trip, ...]

Returns:
# A string containing a polyline tag for each trip
' <polyline class="T" stroke="#336633" points="433,0 ...'


def _parse_frange_part(frange):

        match = FRANGE_RE.match(frange)
        if not match:
            msg = 'Could not parse "{0}": did not match {1}'
            raise ParseException(msg.format(frange, FRANGE_RE.pattern))
        start, end, modifier, chunk = match.groups()
        start = int(start)
        end = int(end) if end is not None else start

        if end > start and chunk is not None and int(chunk) < 0:
            msg = 'Could not parse "{0}: chunk can not be negative'
            raise ParseException(msg.format(frange))

        chunk = abs(int(chunk)) if chunk is not None else 1

        if chunk == 0:
            msg = 'Could not parse "{0}": chunk cannot be 0'
            raise ParseException(msg.format(frange))
        return start, end, modifier, chunk

Internal method: parse a discrete frame range part.

Args:
frange (str): single part of a frame range as a string
(ie "1-100x5")

Returns:
tuple: (start, end, modifier, chunk)

Raises:
:class:`.ParseException`: if the frame range can
not be parsed


def __init__(self):

        super(JLinkSWOSpeedInfo, self).__init__()
        self.SizeofStruct = ctypes.sizeof(self)
        self.Interface = enums.JLinkSWOInterfaces.UART

Initializes the J-Link SWO Speed Information instance.

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

Returns:
``None``


def __init__(self, save_path):
    reader = py_checkpoint_reader.NewCheckpointReader(save_path)
    try:
        object_graph_string = reader.get_tensor(base.OBJECT_GRAPH_PROTO_KEY)
    except errors_impl.NotFoundError as not_found_error:
        raise ValueError(f'The specified checkpoint "{save_path}" does not appear to be object-based (saved with TF2) since it is missing the key "{base.OBJECT_GRAPH_PROTO_KEY}". Likely it was created with the TF1 name-based saver and does not contain an object dependency graph.') from not_found_error
    object_graph_proto = trackable_object_graph_pb2.TrackableObjectGraph()
    object_graph_proto.ParseFromString(object_graph_string)
    self._object_graph_proto = object_graph_proto

Configure the checkpoint view.

Args:
save_path: The path to the checkpoint.

Raises:
ValueError: If the save_path does not lead to a TF2 checkpoint.


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

Update an association between a GCP project and a GitHub Enterprise server.

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


def explore_package(module_name):

    packages = []
    loader = pkgutil.get_loader(module_name)
    for sub_module in pkgutil.walk_packages([os.path.dirname(loader.get_filename())],
                                            prefix=module_name + '.'):
        _, sub_module_name, _ = sub_module
        packages.append(sub_module_name)

    return packages

returns all the packages in the module

Args:
module_name: name of module

Returns: