def addUrlScheme(self, url):

        if not isinstance(url, str):
            raise TypeError('url must be a string value')

        if not url in self._urlSchemes:
            self._urlSchemes[url] = OEmbedUrlScheme(url)

Add a url scheme to this endpoint. It takes a url string and create
the OEmbedUrlScheme object internally.

Args:
url: The url string that represents a url scheme to add.


def text_search(self, search, *, limit=0, table='assets'):
    return backend.query.text_search(self.connection, search, limit=limit, table=table)

Return an iterator of assets that match the text search

Args:
search (str): Text search string to query the text index
limit (int, optional): Limit the number of returned documents.

Returns:
iter: An iterator of assets that match the text search.


def coldestmonth(self, value=None):
    if (value is not None):
        try:
            value = int(value)
        except ValueError:
            raise ValueError('value {} need to be of type int for field `coldestmonth`'.format(value))
        if (value < 1):
            raise ValueError('value need to be greater or equal 1 for field `coldestmonth`')
        if (value > 12):
            raise ValueError('value need to be smaller 12 for field `coldestmonth`')
    self._coldestmonth = value

Corresponds to IDD Field `coldestmonth`

Args:
value (int): value for IDD Field `coldestmonth`
value >= 1
value <= 12
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 decrypt(key, ciphertext):

    index = 0
    decrypted = ""
    for char in ciphertext:
        if char in string.punctuation + string.whitespace + string.digits:
            decrypted += char
            continue

        alphabet = string.ascii_uppercase if key[index].isupper() else string.ascii_lowercase
        decrypted += ''.join(shift.decrypt(int(alphabet.index(key[index])), char))
        index = (index + 1) % len(key)

    return decrypted

Decrypt Vigenere encrypted ``ciphertext`` using ``key``.

Example:
>>> decrypt("KEY", "RIJVS")
HELLO

Args:
key (iterable): The key to use
ciphertext (str): The text to decrypt

Returns:
Decrypted ciphertext


def do_tap(self, x, y):

        rx, ry = x/self.scale, y/self.scale
        self.session.tap(rx, ry)

Simulate click operation
Args:
x, y(int): position


def match_bitap(self, text, pattern, loc):

    s = self.match_alphabet(pattern)

    def match_bitapScore(e, x):

      accuracy = float(e) / len(pattern)
      proximity = abs(loc - x)
      if not self.Match_Distance:

        return proximity and 1.0 or accuracy
      return accuracy + (proximity / float(self.Match_Distance))

    score_threshold = self.Match_Threshold

    best_loc = text.find(pattern, loc)
    if best_loc != -1:
      score_threshold = min(match_bitapScore(0, best_loc), score_threshold)

      best_loc = text.rfind(pattern, loc + len(pattern))
      if best_loc != -1:
        score_threshold = min(match_bitapScore(0, best_loc), score_threshold)

    matchmask = 1 << (len(pattern) - 1)
    best_loc = -1

    bin_max = len(pattern) + len(text)

    last_rd = None
    for d in range(len(pattern)):

      bin_min = 0
      bin_mid = bin_max
      while bin_min < bin_mid:
        if match_bitapScore(d, loc + bin_mid) <= score_threshold:
          bin_min = bin_mid
        else:
          bin_max = bin_mid
        bin_mid = (bin_max - bin_min)

      bin_max = bin_mid
      start = max(1, loc - bin_mid + 1)
      finish = min(loc + bin_mid, len(text)) + len(pattern)

      rd = [0] * (finish + 2)
      rd[finish + 1] = (1 << d) - 1
      for j in range(finish, start - 1, -1):
        if len(text) <= j - 1:

          charMatch = 0
        else:
          charMatch = s.get(text[j - 1], 0)
        if d == 0:
          rd[j] = ((rd[j + 1] << 1) | 1) & charMatch
        else:
          rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) | (
              ((last_rd[j + 1] | last_rd[j]) << 1) | 1) | last_rd[j + 1]
        if rd[j] & matchmask:
          score = match_bitapScore(d, j - 1)

          if score <= score_threshold:

            score_threshold = score
            best_loc = j - 1
            if best_loc > loc:

              start = max(1, 2 * loc - best_loc)
            else:

              break

      if match_bitapScore(d + 1, loc) > score_threshold:
        break
      last_rd = rd
    return best_loc

Locate the best instance of 'pattern' in 'text' near 'loc' using the
Bitap algorithm.

Args:
text: The text to search.
pattern: The pattern to search for.
loc: The location to search around.

Returns:
Best match index or -1.


def get_concatenated_pdf_in_memory(
        pdf_plans: Iterable[PdfPlan],
        start_recto: bool = True) -> bytes:

    writer = PdfFileWriter()
    for pdfplan in pdf_plans:
        pdfplan.add_to_writer(writer, start_recto=start_recto)
    return pdf_from_writer(writer)

Concatenates PDFs and returns them as an in-memory binary PDF.

Args:
pdf_plans: iterable of :class:`PdfPlan` objects
start_recto: start a new right-hand page for each new PDF?

Returns:
concatenated PDF, as ``bytes``


def get_index_from_alias(alias_name, index_client=None):

    index_client = index_client or indices_client()
    if not index_client.exists_alias(name=alias_name):
        return None
    return list(index_client.get_alias(name=alias_name).keys())[0]

Retrieve the base index name from an alias

Args:
alias_name (str) Name of the alias
index_client (Elasticsearch.IndicesClient) an Elasticsearch index
client. Optional, will create one if not given

Returns: (str) Name of index


def model_fn_sharded(self, sharded_features):
    dp = self._data_parallelism
    datashard_to_features = self._to_features_per_datashard(sharded_features)
    if self.use_body_sharded():
        if (self.hparams.scheduled_sampling_prob > 0.0):
            raise NotImplementedError('Scheduled sampling for non-sharded body only.')
        transformed_features = dp(self.bottom, datashard_to_features)
        body_out = self.body_sharded(self._to_single_features_dict(transformed_features))
        (body_out, losses) = self._normalize_body_output(body_out)
        if ('training' in losses):
            log_info('Skipping T2TModel top and loss because training loss returned from body')
            sharded_logits = body_out
        elif isinstance(body_out, dict):
            sharded_logits = collections.OrderedDict()
            sharded_losses = collections.OrderedDict()
            for (k, v) in sorted(six.iteritems(body_out)):
                sharded_logits[k] = dp(self.top, v, datashard_to_features)
                sharded_losses[k] = dp(self.loss, sharded_logits[k], datashard_to_features)
            training_loss_dict = average_sharded_losses([({'training': l} for l in loss) for loss in sharded_losses.values()])
            losses.update(training_loss_dict)
        else:
            sharded_logits = dp(self.top, body_out, datashard_to_features)
            sharded_losses = dp(self.loss, sharded_logits, datashard_to_features)
            if isinstance(sharded_losses, tuple):
                (nums, dens) = sharded_losses
                sharded_losses = zip(nums, dens)
            training_loss_dict = average_sharded_losses([{'training': loss} for loss in sharded_losses])
            losses.update(training_loss_dict)
    else:
        (sharded_logits, sharded_losses) = dp(self.model_fn, datashard_to_features)
        (sharded_logits, sharded_losses) = dp(self.maybe_scheduled_sampling, datashard_to_features, sharded_logits, sharded_losses)
        if isinstance(sharded_logits[0], dict):
            temp_dict = {k: [] for (k, _) in six.iteritems(sharded_logits[0])}
            for (k, _) in six.iteritems(sharded_logits[0]):
                for l in sharded_logits:
                    temp_dict[k].append(l[k])
            sharded_logits = temp_dict
        losses = average_sharded_losses(sharded_losses)
    return (sharded_logits, losses)

Estimator model_fn sharded along batch dimension.

Args:
sharded_features: {str: [Tensor]}. Features sharded along batch dimension.
Each list is the same length (== number of shards).

Returns:
sharded_logits: [Tensor]. Logits for each shard of examples.
losses: {str: 0-D Tensor}. Loss averaged across shards.


def detect_changepoints(points, min_time, data_processor=acc_difference):

    data = data_processor(points)
    changepoints = pelt(normal_mean(data, np.std(data)), len(data))
    changepoints.append(len(points) - 1)

    result = []
    for start, end in pairwise(changepoints):
        time_diff = points[end].time_difference(points[start])
        if time_diff > min_time:
            result.append(start)

    result.append(0)

    result.append(len(points) - 1)
    return sorted(list(set(result)))

Detects changepoints on points that have at least a specific duration

Args:
points (:obj:`Point`)
min_time (float): Min time that a sub-segmented, bounded by two changepoints, must have
data_processor (function): Function to extract data to feed to the changepoint algorithm.
Defaults to `speed_difference`
Returns:
:obj:`list` of int: Indexes of changepoints


async def _get_async(self, url, session):

        data = None
        async with session.get(url) as resp:
            if resp.status == 200:
                data = await resp.json()
        return data

Asynchronous internal method used for GET requests

Args:
url (str): URL to fetch
session (obj): aiohttp client session for async loop

Returns:
data (obj): Individual URL request's response corountine


def get_user(self, user_id):
    try:
        return self._user_dict[user_id]
    except KeyError:
        logger.warning('UserList returning unknown User for UserID %s', user_id)
        return User(user_id, None, None, None, [], False)

Get a user by its ID.

Args:
user_id (~hangups.user.UserID): The ID of the user.

Raises:
KeyError: If no such user is known.

Returns:
:class:`~hangups.user.User` with the given ID.


def transform(self, new_frame):

        steps = self.__class__.steps(new_frame)

        orbit = self.orbit

        for _from, _to in steps:

            from_obj = _from(self.date, orbit)
            direct = "_to_%s" % _to

            if hasattr(from_obj, direct):
                rotation, offset = getattr(from_obj, direct)()
            else:
                to_obj = _to(self.date, orbit)
                inverse = "_to_%s" % _from
                if hasattr(to_obj, inverse):
                    rotation, offset = getattr(to_obj, inverse)()
                    rotation = rotation.T
                    offset = - offset
                else:
                    raise NotImplementedError("Unknown transformation {} to {}".format(_from, _to))

            if getattr(_from, "_rotation_before_translation", False):

                orbit = offset + (rotation @ orbit)
            else:
                orbit = rotation @ (offset + orbit)

        return orbit

Change the frame of the orbit

Args:
new_frame (str)
Return:
numpy.ndarray


def mutual_information(state, d0, d1=None):
    if (d1 is None):
        d1 = int((len(state) / d0))
    mi = entropy(partial_trace(state, [0], dimensions=[d0, d1]))
    mi += entropy(partial_trace(state, [1], dimensions=[d0, d1]))
    mi -= entropy(state)
    return mi

Compute the mutual information of a bipartite state.

Args:
state (array_like): a bipartite state-vector or density-matrix.
d0 (int): dimension of the first subsystem.
d1 (int or None): dimension of the second subsystem.

Returns:
float: The mutual information S(rho_A) + S(rho_B) - S(rho_AB).


def split_modpath(modpath, check=True):
    if six.PY2:
        if modpath.endswith('.pyc'):
            modpath = modpath[:(- 1)]
    modpath_ = abspath(expanduser(modpath))
    if check:
        if (not exists(modpath_)):
            if (not exists(modpath)):
                raise ValueError('modpath={} does not exist'.format(modpath))
            raise ValueError('modpath={} is not a module'.format(modpath))
        if (isdir(modpath_) and (not exists(join(modpath, '__init__.py')))):
            raise ValueError('modpath={} is not a module'.format(modpath))
    (full_dpath, fname_ext) = split(modpath_)
    _relmod_parts = [fname_ext]
    dpath = full_dpath
    while exists(join(dpath, '__init__.py')):
        (dpath, dname) = split(dpath)
        _relmod_parts.append(dname)
    relmod_parts = _relmod_parts[::(- 1)]
    rel_modpath = os.path.sep.join(relmod_parts)
    return (dpath, rel_modpath)

Splits the modpath into the dir that must be in PYTHONPATH for the module
to be imported and the modulepath relative to this directory.

Args:
modpath (str): module filepath
check (bool): if False, does not raise an error if modpath is a
directory and does not contain an `__init__.py` file.

Returns:
tuple: (directory, rel_modpath)

Raises:
ValueError: if modpath does not exist or is not a package

Example:
>>> from xdoctest import static_analysis
>>> modpath = static_analysis.__file__.replace('.pyc', '.py')
>>> modpath = abspath(modpath)
>>> dpath, rel_modpath = split_modpath(modpath)
>>> recon = join(dpath, rel_modpath)
>>> assert recon == modpath
>>> assert rel_modpath == join('xdoctest', 'static_analysis.py')


def generate_noise(self, noise_length: int, generator: Optional[np.random.Generator]=None) -> np.ndarray:
    if generator is None:
        generator = np.random.default_rng()
    noise_shape = (noise_length, self.model_in_channels)
    noise = generator.standard_normal(noise_shape, dtype=np.float32)
    return noise

Generates a random noise sequence of standard Gaussian noise for use in the `noise_sequence` argument of
[`UnivNetModel.forward`].

Args:
spectrogram_length (`int`):
The length (dim 0) of the generated noise.
model_in_channels (`int`, *optional*, defaults to `None`):
The number of features (dim 1) of the generated noise. This should correspond to the
`model_in_channels` of the [`UnivNetGan`] model. If not set, this will default to
`self.config.model_in_channels`.
generator (`numpy.random.Generator`, *optional*, defaults to `None`)
An optional `numpy.random.Generator` random number generator to control noise generation. If not set, a
new generator with fresh entropy will be created.

Returns:
`numpy.ndarray`: Array containing random standard Gaussian noise of shape `(noise_length,
model_in_channels)`.


def __init__(self, paths):

    if isinstance(paths, six.string_types):
      self._paths = [paths]
    else:
      self._paths = paths

Initializes an instance of a Summary.
Args:
path: a path or a list of paths to directories which hold TensorFlow events files.
Can be local path or GCS paths. Wild cards allowed.


def RegisterOutput(cls, output_class, disabled=False):
    output_name = output_class.NAME.lower()
    if disabled:
        class_dict = cls._disabled_output_classes
    else:
        class_dict = cls._output_classes
    if (output_name in class_dict):
        raise KeyError('Output class already set for name: {0:s}.'.format(output_class.NAME))
    class_dict[output_name] = output_class

Registers an output class.

The output classes are identified based on their NAME attribute.

Args:
output_class (type): output module class.
disabled (Optional[bool]): True if the output module is disabled due to
the module not loading correctly or not.

Raises:
KeyError: if output class is already set for the corresponding name.


def xmlrpc_feedback(self, app_id):

    return self.apns_service(app_id).read().addCallback(
      lambda r: decode_feedback(r))

Queries the Apple APNS feedback server for inactive app tokens. Returns
a list of tuples as (datetime_went_dark, token_str).

Arguments:
app_id   the app_id to query
Returns:
Feedback tuples like (datetime_expired, token_str)


def get_input_at(self, node_index):
    return self._get_node_attribute_at_index(node_index, 'input_tensors', 'input')

Retrieves the input tensor(s) of a layer at a given node.

Args:
node_index: Integer, index of the node
from which to retrieve the attribute.
E.g. `node_index=0` will correspond to the
first input node of the layer.

Returns:
A tensor (or list of tensors if the layer has multiple inputs).

Raises:
RuntimeError: If called in Eager mode.


def combine_with_wd_noise(f_n, amp_n, f_n_wd, amp_n_wd):
    amp_n_wd_interp = interpolate.interp1d(f_n_wd, amp_n_wd, bounds_error=False, fill_value=1e-30)
    amp_n_wd = amp_n_wd_interp(f_n)
    amp_n = ((amp_n * (amp_n >= amp_n_wd)) + (amp_n_wd * (amp_n < amp_n_wd)))
    return (f_n, amp_n)

Combine noise with wd noise.

Combines noise and white dwarf background noise based on greater
amplitude value at each noise curve step.

Args:
f_n (float array): Frequencies of noise curve.
amp_n (float array): Amplitude values of noise curve.
f_n_wd (float array): Frequencies of wd noise.
amp_n_wd (float array): Amplitude values of wd noise.

Returns:
(tuple of float arrays): Amplitude values of combined noise curve.


def request(self, endpoint, method='GET', headers=None, params=None, data=None):

        if not headers:
            headers = {}
        if method in ['POST', 'PATCH', 'PUT']:
            headers['Content-Type'] = 'application/json'
        url = '/'.join([self.api_url, 'v' + self.api_version, endpoint])
        data = json.dumps(data) if data else None
        try:
            response = requests.request(method=method, url=url, params=params, headers=headers, data=data)

        except requests.exceptions.Timeout as e:
            raise wp_exceptions.TimeoutError(e)
        except requests.exceptions.ConnectionError as e:
            raise wp_exceptions.ConnectionError(e)
        self._validate_response(method, response)
        return response

Send a request to the given Wunderlist API endpoint

Params:
endpoint -- API endpoint to send request to

Keyword Args:
headers -- headers to add to the request
method -- GET, PUT, PATCH, DELETE, etc.
params -- parameters to encode in the request
data -- data to send with the request


def mesh2fc(script, all_visible_layers=False):

    filter_xml = ''.join([
        '  <filter name="Transfer Color: Mesh to Face">\n',
        '    <Param name="allVisibleMesh" ',
        'value="%s" ' % str(all_visible_layers).lower(),
        'description="Apply to all Meshes" ',
        'type="RichBool" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    return None

Transfer mesh colors to face colors

Args:
script: the FilterScript object or script filename to write
the filter to.
all_visible_layers (bool): If true the color mapping is applied to all the meshes


def cast_to_str(obj):

    if isinstance(obj, str):
        return obj
    if isinstance(obj, Seq):
        return str(obj)
    if isinstance(obj, SeqRecord):
        return str(obj.seq)
    else:
        raise ValueError('Must provide a string, Seq, or SeqRecord object.')

Return a string representation of a Seq or SeqRecord.

Args:
obj (str, Seq, SeqRecord): Biopython Seq or SeqRecord

Returns:
str: String representation of the sequence


def _package_to_staging(staging_package_url):
    import google.datalab.ml as ml
    package_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))
    setup_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'master_setup.py'))
    tar_gz_path = os.path.join(staging_package_url, 'staging', 'trainer.tar.gz')
    print(('Building package and uploading to %s' % tar_gz_path))
    ml.package_and_copy(package_root, setup_path, tar_gz_path)
    return tar_gz_path

Repackage this package from local installed location and copy it to GCS.

Args:
staging_package_url: GCS path.


def add_variable(var, restore=True):

  collections = [MODEL_VARIABLES]
  if restore:
    collections.append(VARIABLES_TO_RESTORE)
  for collection in collections:
    if var not in tf.get_collection(collection):
      tf.add_to_collection(collection, var)

Adds a variable to the MODEL_VARIABLES collection.

Optionally it will add the variable to  the VARIABLES_TO_RESTORE collection.
Args:
var: a variable.
restore: whether the variable should be added to the
VARIABLES_TO_RESTORE collection.


def update_model_parameters(model: nn.Module) -> None:
    model._parameters = {}
    for name, module in model.named_modules():
        if name == '':
            continue
        param_name = name.replace('module.', '')
        if hasattr(module, 'weight') and module.weight is not None:
            model._parameters[f'{param_name}.weight'] = module.weight
        if hasattr(module, 'bias') and module.bias is not None:
            model._parameters[f'{param_name}.bias'] = module.bias

Update model._parameters using named_modules() to ensure all parameters are properly tracked.

Args:
model (nn.Module): The model to update parameters for


def parse_refresh(text):
    match = re.search('url\\s*=(.+)', text, re.IGNORECASE)
    if match:
        url = match.group(1)
        if url.startswith('"'):
            url = url.strip('"')
        elif url.startswith("'"):
            url = url.strip("'")
        return clean_link_soup(url)

Parses text for HTTP Refresh URL.

Returns:
str, None


def get_ports(self, id_or_uri, start=0, count=(- 1)):
    uri = self._client.build_subresource_uri(resource_id_or_uri=id_or_uri, subresource_path='ports')
    return self._client.get_all(start, count, uri=uri)

Gets all interconnect ports.

Args:
id_or_uri: Can be either the interconnect id or the interconnect uri.
start:
The first item to return, using 0-based indexing.
If not specified, the default is 0 - start with the first available item.
count:
The number of resources to return. A count of -1 requests all items.
The actual number of items in the response might differ from the requested
count if the sum of start and count exceeds the total number of items.

Returns:
list: All interconnect ports.


def inject_additional_input(layer, inputs, name, mode='concat'):
    layer_shape = common_layers.shape_list(layer)
    input_shape = common_layers.shape_list(inputs)
    zeros_mask = tf.zeros(layer_shape, dtype=tf.float32)
    if (mode == 'concat'):
        emb = encode_to_shape(inputs, layer_shape, name)
        layer = tf.concat(values=[layer, emb], axis=(- 1))
    elif (mode == 'multiplicative'):
        filters = layer_shape[(- 1)]
        input_reshaped = tf.reshape(inputs, [(- 1), 1, 1, input_shape[(- 1)]])
        input_mask = tf.layers.dense(input_reshaped, filters, name=name)
        input_broad = (input_mask + zeros_mask)
        layer *= input_broad
    elif (mode == 'multi_additive'):
        filters = layer_shape[(- 1)]
        input_reshaped = tf.reshape(inputs, [(- 1), 1, 1, input_shape[(- 1)]])
        input_mul = tf.layers.dense(input_reshaped, filters, name=(name + '_mul'))
        layer *= tf.nn.sigmoid(input_mul)
        input_add = tf.layers.dense(input_reshaped, filters, name=(name + '_add'))
        layer += input_add
    else:
        raise ValueError(('Unknown injection mode: %s' % mode))
    return layer

Injects the additional input into the layer.

Args:
layer: layer that the input should be injected to.
inputs: inputs to be injected.
name: TF scope name.
mode: how the infor should be added to the layer:
"concat" concats as additional channels.
"multiplicative" broadcasts inputs and multiply them to the channels.
"multi_additive" broadcasts inputs and multiply and add to the channels.

Returns:
updated layer.

Raises:
ValueError: in case of unknown mode.


def _get_prereq_datasets(self, comp_id, prereq_nodes, keepables, skip=False):
    prereq_datasets = []
    delayed_gen = False
    for prereq_node in prereq_nodes:
        prereq_id = prereq_node.name
        if ((prereq_id not in self.datasets) and (prereq_id not in keepables) and (not prereq_node.is_leaf)):
            self._generate_composite(prereq_node, keepables)
        if (prereq_id in self.datasets):
            prereq_datasets.append(self.datasets[prereq_id])
        elif ((not prereq_node.is_leaf) and (prereq_id in keepables)):
            delayed_gen = True
            continue
        elif (not skip):
            LOG.debug("Missing prerequisite for '{}': '{}'".format(comp_id, prereq_id))
            raise KeyError('Missing composite prerequisite')
        else:
            LOG.debug('Missing optional prerequisite for {}: {}'.format(comp_id, prereq_id))
    if delayed_gen:
        keepables.add(comp_id)
        keepables.update([x.name for x in prereq_nodes])
        LOG.debug("Delaying generation of %s because of dependency's delayed generation: %s", comp_id, prereq_id)
        if (not skip):
            LOG.debug("Missing prerequisite for '{}': '{}'".format(comp_id, prereq_id))
            raise KeyError('Missing composite prerequisite')
        else:
            LOG.debug('Missing optional prerequisite for {}: {}'.format(comp_id, prereq_id))
    return prereq_datasets

Get a composite's prerequisites, generating them if needed.

Args:
comp_id (DatasetID): DatasetID for the composite whose
prerequisites are being collected.
prereq_nodes (sequence of Nodes): Prerequisites to collect
keepables (set): `set` to update if any prerequisites can't
be loaded at this time (see
`_generate_composite`).
skip (bool): If True, consider prerequisites as optional and
only log when they are missing. If False,
prerequisites are considered required and will
raise an exception and log a warning if they can't
be collected. Defaults to False.

Raises:
KeyError: If required (skip=False) prerequisite can't be collected.


def _ProcessSources(
      self, source_path_specs, extraction_worker, parser_mediator,
      storage_writer, filter_find_specs=None):

    if self._processing_profiler:
      self._processing_profiler.StartTiming('process_sources')

    number_of_consumed_sources = 0

    self._UpdateStatus(
        definitions.STATUS_INDICATOR_COLLECTING, '',
        number_of_consumed_sources, storage_writer)

    display_name = ''
    path_spec_generator = self._path_spec_extractor.ExtractPathSpecs(
        source_path_specs, find_specs=filter_find_specs,
        recurse_file_system=False,
        resolver_context=parser_mediator.resolver_context)

    for path_spec in path_spec_generator:
      if self._abort:
        break

      display_name = parser_mediator.GetDisplayNameForPathSpec(path_spec)

      event_source = event_sources.FileEntryEventSource(path_spec=path_spec)
      storage_writer.AddEventSource(event_source)

      self._UpdateStatus(
          definitions.STATUS_INDICATOR_COLLECTING, display_name,
          number_of_consumed_sources, storage_writer)

    self._UpdateStatus(
        definitions.STATUS_INDICATOR_RUNNING, display_name,
        number_of_consumed_sources, storage_writer, force=True)

    if self._processing_profiler:
      self._processing_profiler.StartTiming('get_event_source')

    event_source = storage_writer.GetFirstWrittenEventSource()

    if self._processing_profiler:
      self._processing_profiler.StopTiming('get_event_source')

    while event_source:
      if self._abort:
        break

      self._ProcessPathSpec(
          extraction_worker, parser_mediator, event_source.path_spec)
      number_of_consumed_sources += 1

      if self._guppy_memory_profiler:
        self._guppy_memory_profiler.Sample()

      self._UpdateStatus(
          extraction_worker.processing_status, self._current_display_name,
          number_of_consumed_sources, storage_writer)

      if self._processing_profiler:
        self._processing_profiler.StartTiming('get_event_source')

      event_source = storage_writer.GetNextWrittenEventSource()

      if self._processing_profiler:
        self._processing_profiler.StopTiming('get_event_source')

    if self._abort:
      status = definitions.STATUS_INDICATOR_ABORTED
    else:
      status = definitions.STATUS_INDICATOR_COMPLETED

    self._UpdateStatus(
        status, '', number_of_consumed_sources, storage_writer, force=True)

    if self._processing_profiler:
      self._processing_profiler.StopTiming('process_sources')

Processes the sources.

Args:
source_path_specs (list[dfvfs.PathSpec]): path specifications of
the sources to process.
extraction_worker (worker.ExtractionWorker): extraction worker.
parser_mediator (ParserMediator): parser mediator.
storage_writer (StorageWriter): storage writer for a session storage.
filter_find_specs (Optional[list[dfvfs.FindSpec]]): find specifications
used in path specification extraction.


def __init__(self, xid=None, table_id=Table.OFPTT_ALL, config=3):

        super().__init__(xid)
        self.table_id = table_id

        self.config = config

Assing parameters to object attributes.

Args:
xid (int): :class:`~pyof.v0x04.common.header.Header`'s xid.
Defaults to random.
table_id (int): ID of the table, OFPTT_ALL indicates all tables.
config (int): Bitmap of OFPTC_* flags


def on_click(self, handler):

        self.on_event(ButtonClick, handler)
        self.on_event(MenuItemClick, handler)

Set up a handler for button or menu item clicks.

Args:
handler (func) : handler function to call when button is activated.

Returns:
None


def stimulus(self, stimulus):
    if (not isinstance(stimulus, SimulationStimulus)):
        stimulus = SimulationStimulus.FromString(stimulus)
    self.stimuli.append(stimulus)
    self.stimuli.sort(key=(lambda x: x.time))

Add a simulation stimulus at a given time.

A stimulus is a specific input given to the graph at a specific
time to a specific input stream.  The format for specifying a
stimulus is:
[time: ][system ]input X = Y
where X and Y are integers.

This will cause the simulator to inject this input at the given time.
If you specify a time of 0 seconds, it will happen before the simulation
starts.  Similarly, if you specify a time of 1 second it will also happen
before anything else since the simulations start with a tick value of 1.

The stimulus is injected before any other things happen at each new tick.

Args:
stimulus (str or SimulationStimulus): A prebuilt stimulus object or
a string description of the stimulus of the format:
[time: ][system ]input X = Y
where time is optional and defaults to 0 seconds if not specified.

Examples:
sim.stimulus('system input 10 = 15')
sim.stimulus('1 minute: input 1 = 5')


def add_user_role(self, user, role):

        self.service.add_user_role(
            user, role,
            self.url_prefix, self.auth, self.session, self.session_send_opts)

Add role to given user.

Args:
user (string): User name.
role (string): Role to assign.

Raises:
requests.HTTPError on failure.


def unbroadcast(array, like):

  unbroadcaster = unbroadcasters[type(array)]
  return unbroadcaster(array, like)

Reverse the broadcasting operation.

Args:
array: An array.
like: An array that could have been broadcasted to the shape of array.

Returns:
Tensor with certain dimensions summed to match the shape of `like`.


def _assert_sample_values_all_close(self, sess: session.Session, repr_ds_1: repr_dataset.RepresentativeDataset, repr_ds_2: repr_dataset.RepresentativeDataset) -> None:
    for sample_1, sample_2 in zip(repr_ds_1, repr_ds_2):
        self.assertCountEqual(sample_1.keys(), sample_2.keys())
        for input_key in sample_1:
            self._assert_tensorlike_all_close(sess, sample_1[input_key], sample_2[input_key])

Asserts that the sample values are "all close" between the two datasets.

This assumes that the order of corresponding samples is preserved and the
size of the two datasets are equal.

Args:
sess: Session instance used to evaluate any tf.Tensors.
repr_ds_1: A RepresentativeDataset.
repr_ds_2: A RepresentativeDataset.


def __call__(self, type_instruction):

        def _apply_converter(converter):

            @functools.wraps(converter)
            def _call_valid_converter(self, shift, instruction):

                if isinstance(instruction, type_instruction):
                    return converter(self, shift, instruction)
                else:
                    raise PulseError('Supplied instruction {0} '
                                     'is not of type {1}.'.format(instruction, type_instruction))

            self._bound_instructions[type_instruction] = _call_valid_converter
            return _call_valid_converter

        return _apply_converter

Converter decorator method.

Pulse instruction converter is defined for each instruction type,
and this decorator binds converter function to valid instruction type.

Args:
type_instruction (Instruction): valid pulse instruction class to the converter.


def _AlignDecryptedDataOffset(self, decrypted_data_offset):

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

    self._decrypter = self._GetDecrypter()
    self._decrypted_data = b''

    encrypted_data_offset = 0
    encrypted_data_size = self._file_object.get_size()

    while encrypted_data_offset < encrypted_data_size:
      read_count = self._ReadEncryptedData(self._ENCRYPTED_DATA_BUFFER_SIZE)
      if read_count == 0:
        break

      encrypted_data_offset += read_count

      if decrypted_data_offset < self._decrypted_data_size:
        self._decrypted_data_offset = decrypted_data_offset
        break

      decrypted_data_offset -= self._decrypted_data_size

Aligns the encrypted file with the decrypted data offset.

Args:
decrypted_data_offset (int): decrypted data offset.


def add_compound(self, compound):
    logger.debug('Adding compound {0} to variant {1}'.format(compound, self['variant_id']))
    self['compounds'].append(compound)

Add the information of a compound variant

This adds a compound dict to variant['compounds']

Args:
compound (dict): A compound dictionary


def __init__(self, project, throttle_rampup=True, hint_num_workers=_Mutate._DEFAULT_HINT_NUM_WORKERS):
    mutate_fn = WriteToDatastore._DatastoreWriteFn(project)
    super().__init__(mutate_fn, throttle_rampup, hint_num_workers)

Initialize the `WriteToDatastore` transform.

Args:
project: (:class:`str`) The ID of the project to write entities to.
throttle_rampup: Whether to enforce a gradual ramp-up.
hint_num_workers: A hint for the expected number of workers, used to
estimate appropriate limits during ramp-up throttling.


def __init__(self, scope, parent):

        CodeStatement.__init__(self, scope, parent)
        self.body = CodeBlock(scope, self, explicit=True)
        self.catches = []
        self.finally_body = CodeBlock(scope, self, explicit=True)

Constructor for try block structures.

Args:
scope (CodeEntity): The program scope where this object belongs.
parent (CodeEntity): This object's parent in the program tree.


def get_date(date, date_format=None):
    date_obj = datetime.datetime.now()
    if date:
        if date_format:
            date_obj = datetime.datetime.strptime(date, date_format)
        elif match_date(date):
            if (len(date.split('-')) == 3):
                date = date.split('-')
            elif (len(date.split(' ')) == 3):
                date = date.split(' ')
            elif (len(date.split('.')) == 3):
                date = date.split('.')
            else:
                date = date.split('/')
            date_obj = datetime.datetime(*(int(number) for number in date))
        else:
            raise ValueError(('Date %s is invalid' % date))
    return date_obj

Return a datetime object if there is a valid date

Raise exception if date is not valid
Return todays date if no date where added

Args:
date(str)
date_format(str)

Returns:
date_obj(datetime.datetime)


async def update(self, *, node_id: str, version: int, spec: Mapping[(str, Any)]) -> Mapping[(str, Any)]:
    params = {'version': version}
    if ('Role' in spec):
        assert (spec['Role'] in {'worker', 'manager'})
    if ('Availability' in spec):
        assert (spec['Availability'] in {'active', 'pause', 'drain'})
    response = (await self.docker._query_json('nodes/{node_id}/update'.format(node_id=node_id), method='POST', params=params, data=spec))
    return response

Update the spec of a node.

Args:
node_id: The ID or name of the node
version: version number of the node being updated
spec: fields to be updated


def get_random_voxels(dataset, n_voxels):

    voxels = np.arange(dataset.masker.n_vox_in_vol)
    np.random.shuffle(voxels)
    selected = voxels[0:n_voxels]
    return dataset.get_image_data(voxels=selected)

Returns mappable data for a random subset of voxels.

May be useful as a baseline in predictive analyses--e.g., to compare
performance of a more principled feature selection method with simple
random selection.

Args:
dataset: A Dataset instance
n_voxels: An integer specifying the number of random voxels to select.

Returns:
A 2D numpy array with (randomly-selected) voxels in rows and mappables
in columns.


def changeset_info(changeset):

    keys = [tag.attrib.get('k') for tag in changeset.getchildren()]
    keys += ['id', 'user', 'uid', 'bbox', 'created_at']
    values = [tag.attrib.get('v') for tag in changeset.getchildren()]
    values += [
        changeset.get('id'), changeset.get('user'), changeset.get('uid'),
        get_bounds(changeset), changeset.get('created_at')
        ]

    return dict(zip(keys, values))

Return a dictionary with id, user, user_id, bounds, date of creation
and all the tags of the changeset.

Args:
changeset: the XML string of the changeset.


def SetWriteBack(self, filename):

    try:
      self.writeback = self.LoadSecondaryConfig(filename)
      self.MergeData(self.writeback.RawData(), self.writeback_data)
    except IOError as e:

      logging.error("Unable to read writeback file: %s", e)
      return
    except Exception as we:

      if os.path.exists(filename):
        try:
          b = filename + ".bak"
          os.rename(filename, b)
          logging.warning("Broken writeback (%s) renamed to: %s", we, b)
        except Exception as e:
          logging.error("Unable to rename broken writeback: %s", e)
      raise we
    logging.debug("Configuration writeback is set to %s", filename)

Sets the config file which will receive any modifications.

The main config file can be made writable, but directing all Set()
operations into a secondary location. This secondary location will
receive any updates and will override the options for this file.

Args:
filename: A filename which will receive updates. The file is parsed first
and merged into the raw data from this object.


def _add_should_use_warning(x, error_in_function=False, warn_in_eager=False):
    if x is None or (isinstance(x, list) and (not x)):
        return x
    if context.executing_eagerly() and (not warn_in_eager):
        return x
    if ops.inside_function() and (not error_in_function):
        return x
    try:
        raise ValueError()
    except ValueError:
        stack_frame = sys.exc_info()[2].tb_frame.f_back
    tf_should_use_helper = _TFShouldUseHelper(type_=type(x), repr_=repr(x), stack_frame=stack_frame, error_in_function=error_in_function, warn_in_eager=warn_in_eager)
    return _get_wrapper(x, tf_should_use_helper)

Wraps object x so that if it is never used, a warning is logged.

Args:
x: Python object.
error_in_function: Python bool.  If `True`, a `RuntimeError` is raised
if the returned value is never used when created during `tf.function`
tracing.
warn_in_eager: Python bool. If `True` raise warning if in Eager mode as well
as graph mode.

Returns:
An instance of `TFShouldUseWarningWrapper` which subclasses `type(x)`
and is a very shallow wrapper for `x` which logs access into `x`.


def encode(self, tf_graph_predictions):
    row = []
    for col in self._header:
        row.append(str(tf_graph_predictions[col]))
    return ','.join(row)

Encodes the graph json prediction into csv.

Args:
tf_graph_predictions: python dict.

Returns:
csv string.


def get_service(self, uuid):
    if (uuid in self.services):
        return self.services[uuid]
    if (pp_hex(uuid) in self.services):
        return self.services[pp_hex(uuid)]
    return None

Lookup information about a given GATT service.

Args:
uuid (str): a string containing the hex-encoded service UUID

Returns:
None if an error occurs, otherwise a :class:`Service` object.


def _type_digest(self, config: bool) -> Dict[str, Any]:

        res = {"base": self.yang_type()}
        if self.name is not None:
            res["derived"] = self.name
        return res

Return receiver's type digest.

Args:
config: Specifies whether the type is on a configuration node.


def __init__(self, names):

    super(NamesFileEntryFilter, self).__init__()
    self._names = names

Initializes a names-based file entry filter.

Args:
names (list[str]): names.


def get_rows_to_keep(gctoo, rid=None, row_bool=None, ridx=None, exclude_rid=None):

    if rid is not None:
        assert type(rid) == list, "rid must be a list. rid: {}".format(rid)

        rows_to_keep = [gctoo_row for gctoo_row in gctoo.data_df.index if gctoo_row in rid]

        num_missing_rids = len(rid) - len(rows_to_keep)
        if num_missing_rids != 0:
            logger.info("{} rids were not found in the GCT.".format(num_missing_rids))

    elif row_bool is not None:

        assert len(row_bool) == gctoo.data_df.shape[0], (
            "row_bool must have length equal to gctoo.data_df.shape[0]. " +
            "len(row_bool): {}, gctoo.data_df.shape[0]: {}".format(
                len(row_bool), gctoo.data_df.shape[0]))
        rows_to_keep = gctoo.data_df.index[row_bool].values

    elif ridx is not None:

        assert type(ridx[0]) is int, (
            "ridx must be a list of integers. ridx[0]: {}, " +
            "type(ridx[0]): {}").format(ridx[0], type(ridx[0]))

        assert max(ridx) <= gctoo.data_df.shape[0], (
            "ridx contains an integer larger than the number of rows in " +
            "the GCToo. max(ridx): {}, gctoo.data_df.shape[0]: {}").format(
                max(ridx), gctoo.data_df.shape[0])

        rows_to_keep = gctoo.data_df.index[ridx].values

    else:
        rows_to_keep = gctoo.data_df.index.values

    if exclude_rid is not None:

        rows_to_keep = [row_to_keep for row_to_keep in rows_to_keep if row_to_keep not in exclude_rid]

    return rows_to_keep

Figure out based on the possible row inputs which rows to keep.

Args:
gctoo (GCToo object):
rid (list of strings):
row_bool (boolean array):
ridx (list of integers):
exclude_rid (list of strings):

Returns:
rows_to_keep (list of strings): row ids to be kept


def get_sessions(self, app_path):
    if (app_path not in self._applications):
        raise ValueError(('Application %s does not exist on this server' % app_path))
    return list(self._applications[app_path].sessions)

Gets all currently active sessions for an application.

Args:
app_path (str) :
The configured application path for the application to return
sessions for.

Returns:
list[ServerSession]


def from_file(cls, filename, directory=None, format=None, engine=None, encoding=File._encoding):
    filepath = os.path.join((directory or ''), filename)
    if (encoding is None):
        encoding = locale.getpreferredencoding()
    with io.open(filepath, encoding=encoding) as fd:
        source = fd.read()
    return cls(source, filename, directory, format, engine, encoding)

Return an instance with the source string read from the given file.

Args:
filename: Filename for loading/saving the source.
directory: (Sub)directory for source loading/saving and rendering.
format: Rendering output format (``'pdf'``, ``'png'``, ...).
engine: Layout command used (``'dot'``, ``'neato'``, ...).
encoding: Encoding for loading/saving the source.


def pad_to_multiple_2d(x, block_shape):

  old_shape = x.get_shape().dims
  last = old_shape[-1]
  if len(old_shape) == 4:
    height_padding = -common_layers.shape_list(x)[1] % block_shape[0]
    width_padding = -common_layers.shape_list(x)[2] % block_shape[1]
    paddings = [[0, 0], [0, height_padding], [0, width_padding], [0, 0]]
  elif len(old_shape) == 5:
    height_padding = -common_layers.shape_list(x)[2] % block_shape[0]
    width_padding = -common_layers.shape_list(x)[3] % block_shape[1]
    paddings = [[0, 0], [0, 0], [0, height_padding], [0, width_padding], [0, 0]]

  padded_x = tf.pad(x, paddings)
  padded_shape = padded_x.get_shape().as_list()
  padded_shape = padded_shape[:-1] + [last]
  padded_x.set_shape(padded_shape)
  return padded_x

Making sure x is a multiple of shape.

Args:
x: a [batch, heads, h, w, depth] or [batch, h, w, depth] tensor
block_shape: a 2-d list of integer shapes

Returns:
padded_x: a [batch, heads, h, w, depth] or [batch, h, w, depth] tensor


def from_text_vision_configs(cls, text_config: CLIPSegTextConfig, vision_config: CLIPSegVisionConfig, **kwargs):
    return cls(text_config=text_config.to_dict(), vision_config=vision_config.to_dict(), **kwargs)

Instantiate a [`CLIPSegConfig`] (or a derived class) from clipseg text model configuration and clipseg vision
model configuration.

Returns:
[`CLIPSegConfig`]: An instance of a configuration object


def abs_horz_pos(self, amount):

        n1 = amount%256
        n2 = amount/256
        self.send(chr(27)+'${n1}{n2}'.format(n1=chr(n1), n2=chr(n2)))

Calling this function sets the absoulte print position for the next data, this is
the position from the left margin.

Args:
amount: desired positioning. Can be a number from 0 to 2362. The actual positioning
is calculated as (amount/60)inches from the left margin.
Returns:
None
Raises:
None


def enable_graph_building_optimization(fn: _F) -> _F:

    def wrapper(*args, **kwargs):
        if flags.config().graph_building_optimization.value():
            return fn(*args, **kwargs)
        flags.config().graph_building_optimization.reset(True)
        try:
            return fn(*args, **kwargs)
        finally:
            flags.config().graph_building_optimization.reset(False)
    return wrapper

Decorator for enabling graph_building_optimization on a test.

This function returns a decorator intended to be applied to test methods in
a `tf.test.TestCase` class. Doing so will enable graph_building_optimization,
execute the test, then reset the feature flag to its default value.

Example:

class MyTest(test.TestCase):

@enable_graph_building_optimization
def testFoo(self):
...

Args:
fn: the function to be wrapped.

Returns:
The wrapped function.


def __init__(self, item_type=None, min_length=None, max_length=None, empty=True):

        super(SetTypeChecker, self).__init__(
            iter_type=set, item_type=item_type, min_length=min_length, max_length=max_length, empty=empty
        )

Initialization method.

Args:
item_type (type): the type of the items inside the set.
min_length (int): minimum length of the set (included).
max_length (int): maximum length of the set (included).
empty (bool): whether empty set is allowed.


def cut_cuboid(self, a=20, b=None, c=None, origin=None, outside_sliced=True, preserve_bonds=False):
    if (origin is None):
        origin = np.zeros(3)
    elif pd.api.types.is_list_like(origin):
        origin = np.array(origin, dtype='f8')
    else:
        origin = self.loc[(origin, ['x', 'y', 'z'])]
    b = (a if (b is None) else b)
    c = (a if (c is None) else c)
    sides = np.array([a, b, c])
    pos = self.loc[(:, ['x', 'y', 'z'])]
    if outside_sliced:
        molecule = self[(((pos - origin) / (sides / 2)).max(axis=1) < 1.0)]
    else:
        molecule = self[(((pos - origin) / (sides / 2)).max(axis=1) > 1.0)]
    if preserve_bonds:
        molecule = self._preserve_bonds(molecule)
    return molecule

Cut a cuboid specified by edge and radius.

Args:
a (float): Value of the a edge.
b (float): Value of the b edge. Takes value of a if None.
c (float): Value of the c edge. Takes value of a if None.
origin (list): Please note that you can also pass an
integer. In this case it is interpreted as the index
of the atom which is taken as origin.
outside_sliced (bool): Atoms outside/inside the sphere are
cut away.
preserve_bonds (bool): Do not cut covalent bonds.

Returns:
Cartesian:


def add_node(self, node_id, name, labels):

        self.neo_db.add_node(node_id, name, labels)

Add a node to the graph with name and labels.
Args:
node_id: the unique node_id e.g. 'www.evil4u.com'
name: the display name of the node e.g. 'evil4u'
labels: a list of labels e.g. ['domain','evil']
Returns:
Nothing


def _create_gates(self, inputs, memory):

    num_gates = 2 * self._calculate_gate_size()

    memory = tf.tanh(memory)
    inputs = basic.BatchFlatten()(inputs)
    gate_inputs = basic.BatchApply(basic.Linear(num_gates), n_dims=1)(inputs)
    gate_inputs = tf.expand_dims(gate_inputs, axis=1)
    gate_memory = basic.BatchApply(basic.Linear(num_gates))(memory)
    gates = tf.split(gate_memory + gate_inputs, num_or_size_splits=2, axis=2)
    input_gate, forget_gate = gates

    input_gate = tf.sigmoid(input_gate + self._input_bias)
    forget_gate = tf.sigmoid(forget_gate + self._forget_bias)

    return input_gate, forget_gate

Create input and forget gates for this step using `inputs` and `memory`.

Args:
inputs: Tensor input.
memory: The current state of memory.

Returns:
input_gate: A LSTM-like insert gate.
forget_gate: A LSTM-like forget gate.


def triggered(self, walker):
    if self.use_count:
        comp_value = walker.count()
    else:
        if (walker.count() == 0):
            return False
        comp_value = walker.peek().value
    return self.comp_function(comp_value, self.reference)

Check if this input is triggered on the given stream walker.

Args:
walker (StreamWalker): The walker to check

Returns:
bool: Whether this trigger is triggered or not


def pretty_print(node):

        for pre, _, node in RenderTree(node):
            print('{}{}'.format(pre, node.name))

漂亮地打印一个节点

Args:
node (TYPE): Description


def value_loss(value_net_apply, value_net_params, observations, rewards, reward_mask, gamma=0.99):
    (B, T) = rewards.shape
    assert ((B, (T + 1)) == observations.shape[:2])
    value_prediction = value_net_apply(observations, value_net_params)
    assert ((B, (T + 1), 1) == value_prediction.shape)
    return value_loss_given_predictions(value_prediction, rewards, reward_mask, gamma)

Computes the value loss.

Args:
value_net_apply: value net apply function with signature (params, ndarray of
shape (B, T+1) + OBS) -> ndarray(B, T+1, 1)
value_net_params: params of value_net_apply.
observations: np.ndarray of shape (B, T+1) + OBS
rewards: np.ndarray of shape (B, T) of rewards.
reward_mask: np.ndarray of shape (B, T), the mask over rewards.
gamma: float, discount factor.

Returns:
The average L2 value loss, averaged over instances where reward_mask is 1.


def create_output_excerpts_all(self, test_info):
    excerpt_paths = {}

    def create_output_excerpts_for_one(service):
        if not service.is_alive:
            return
        paths = service.create_output_excerpts(test_info)
        excerpt_paths[service.alias] = paths
    self.for_each(create_output_excerpts_for_one)
    return excerpt_paths

Creates output excerpts from all services.

This calls `create_output_excerpts` on all registered services.

Args:
test_info: RuntimeTestInfo, the test info associated with the scope
of the excerpts.

Returns:
Dict, keys are the names of the services, values are the paths to
the excerpt files created by the corresponding services.


def _clean_isbn(isbn):

    if isinstance(isbn, basestring):
        isbn = list(isbn.lower())

        isbn = filter(lambda x: x.isdigit() or x == "x", isbn)

    return map(lambda x: 10 if x == "x" else int(x), isbn)

Remove all non-digit and non "x" characters from given string.

Args:
isbn (str): isbn string, which will be cleaned.

Returns:
list: array of numbers (if "x" is found, it is converted to 10).


def __init__(self, option_strings, dest, nargs=None, **kwargs):

        if nargs is not None:
            raise ValueError('nargs not allowed for ThreadCheck')

        super(CheckThreads, self).__init__(option_strings, dest, **kwargs)

Initialize class and spawn self as Base Class w/o nargs

Args:
option_strings (list): list of str giving command line flags that
call this action

dest (str): Namespace reference to value

nargs (str): number of args as special char or int

**kwargs (various): optional arguments to pass to super call


def bridge_to_vlan(br):
    cmd = 'ovs-vsctl br-to-vlan {0}'.format(br)
    result = __salt__['cmd.run_all'](cmd)
    if (result['retcode'] != 0):
        return False
    return int(result['stdout'])

Returns the VLAN ID of a bridge.

Args:
br: A string - bridge name

Returns:
VLAN ID of the bridge. The VLAN ID is 0 if the bridge is not a fake
bridge.  If the bridge does not exist, False is returned.

CLI Example:

.. code-block:: bash

salt '*' openvswitch.bridge_to_parent br0


def proto_refactor(proto_filename, namespace, namespace_path):
    with open(proto_filename) as f:
        data = f.read()
        if (not re.search('syntax = "proto2"', data)):
            insert_syntax = 'syntax = "proto2";\n'
            data = (insert_syntax + data)
        substitution = 'import "{}/\\1";'.format(namespace_path)
        data = re.sub('import\\s+"([^"]+\\.proto)"\\s*;', substitution, data)
        return data

This method refactors a Protobuf file to import from a namespace
that will map to the desired python package structure. It also ensures
that the syntax is set to "proto2", since protoc complains without it.

Args:
proto_filename (str): the protobuf filename to be refactored
namespace (str): the desired package name (i.e. "dropsonde.py2")
namespace_path (str): the desired path corresponding to the package
name (i.e. "dropsonde/py2")


def authenticate_device(self, api_token, device_token, email=None, user_url=None, override=False, fetch=True):
    if (self.context.has_auth_params('Gem-Device') and (not override)):
        raise OverrideError('Gem-Device')
    if ((not api_token) or (not device_token) or ((not email) and (not user_url)) or (not self.context.authorize('Gem-Device', api_token=api_token, user_email=email, user_url=user_url, device_token=device_token))):
        raise AuthUsageError(self.context, 'Gem-Device')
    if fetch:
        user = (self.user(email) if email else self.user())
        return user.refresh()
    else:
        return True

Set credentials for Device authentication.

Args:
api_token (str): Token issued to your Application through the Gem
Developer Console.
device_token (str): Physical device identifier. You will receive this
from a user.devices.create call or from users.create.
email (str, optional): User's email address, required if user_url is
not provided.
user_url (str, optional): User's Gem url.
override (boolean, optional): Replace existing Application credentials.
fetch (boolean, optional): Return the authenticated User.

Returns:
An User object if `fetch` is True.


def extract_objects(self, fname, type_filter=None):

    objects = []
    if fname in self.object_cache:
      objects = self.object_cache[fname]
    else:
      with io.open(fname, 'rt', encoding='utf-8') as fh:
        text = fh.read()
        objects = parse_verilog(text)
        self.object_cache[fname] = objects

    if type_filter:
      objects = [o for o in objects if isinstance(o, type_filter)]

    return objects

Extract objects from a source file

Args:
fname(str): Name of file to read from
type_filter (class, optional): Object class to filter results
Returns:
List of objects extracted from the file.


def Process(self, parser_mediator, root_item=None, **kwargs):
    super(SummaryInformationOLECFPlugin, self).Process(parser_mediator, **kwargs)
    if (not root_item):
        raise ValueError('Root item not set.')
    (root_creation_time, root_modification_time) = self._GetTimestamps(root_item)
    for item_name in self.REQUIRED_ITEMS:
        item = root_item.get_sub_item_by_name(item_name)
        if (not item):
            continue
        summary_information = OLECFSummaryInformation(item)
        event_data = summary_information.GetEventData(data_type='olecf:summary_info')
        event_data.name = 'Summary Information'
        for (property_name, date_time) in iter(summary_information.date_time_properties.items()):
            date_time_description = self._DATE_TIME_DESCRIPTIONS.get(property_name, definitions.TIME_DESCRIPTION_UNKNOWN)
            event = OLECFSummaryInformationEvent(date_time, date_time_description)
            parser_mediator.ProduceEventWithEventData(event, event_data)
        if root_creation_time:
            date_time = dfdatetime_filetime.Filetime(timestamp=root_creation_time)
            event = OLECFSummaryInformationEvent(date_time, definitions.TIME_DESCRIPTION_CREATION)
            parser_mediator.ProduceEventWithEventData(event, event_data)
        if root_modification_time:
            date_time = dfdatetime_filetime.Filetime(timestamp=root_modification_time)
            event = OLECFSummaryInformationEvent(date_time, definitions.TIME_DESCRIPTION_MODIFICATION)
            parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a summary information OLECF item.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
root_item (Optional[pyolecf.item]): root item of the OLECF file.

Raises:
ValueError: If the root item is not set.


def clone(self, *args, **overrides):

        clone = super(NdLayout, self).clone(*args, **overrides)
        clone._max_cols = self._max_cols
        clone.id = self.id
        return clone

Clones the NdLayout, overriding data and parameters.

Args:
data: New data replacing the existing data
shared_data (bool, optional): Whether to use existing data
new_type (optional): Type to cast object to
*args: Additional arguments to pass to constructor
**overrides: New keyword arguments to pass to constructor

Returns:
Cloned NdLayout object


def get_class(class_key):

    if class_key not in CLASSES:
        for basecls in (MediaMetadata, MediaCollection):
            if class_key.startswith(basecls.__name__):

                class_name = 'MS' + class_key.replace(basecls.__name__, '')
                if sys.version_info[0] == 2:
                    class_name = class_name.encode('ascii')
                CLASSES[class_key] = type(class_name, (basecls,), {})
                _LOG.info('Class %s created', CLASSES[class_key])
    return CLASSES[class_key]

Form a music service data structure class from the class key

Args:
class_key (str): A concatenation of the base class (e.g. MediaMetadata)
and the class name

Returns:
class: Subclass of MusicServiceItem


def GetChangeAddress(self, from_addr=None):

        if from_addr is not None:
            for contract in self._contracts.values():
                if contract.ScriptHash == from_addr:
                    return contract.ScriptHash

        for contract in self._contracts.values():
            if contract.IsStandard:
                return contract.ScriptHash

        if len(self._contracts.values()):
            for k, v in self._contracts.items():
                return v

        raise Exception("Could not find change address")

Get the address where change is send to.

Args:
from_address (UInt160): (optional) from address script hash.

Raises:
Exception: if change address could not be found.

Returns:
UInt160: script hash.


def pull_file(self, remote_source, local_dir):
    local_dest = ((local_dir + '/') + os.path.basename(remote_source))
    try:
        os.makedirs(local_dir)
    except OSError as e:
        if (e.errno != errno.EEXIST):
            logger.exception('Failed to create script_dir: {0}'.format(script_dir))
            raise BadScriptPath(e, self.hostname)
    if os.path.exists(local_dest):
        logger.exception('Remote file copy will overwrite a local file:{0}'.format(local_dest))
        raise FileExists(None, self.hostname, filename=local_dest)
    try:
        self.sftp_client.get(remote_source, local_dest)
    except Exception as e:
        logger.exception('File pull failed')
        raise FileCopyException(e, self.hostname)
    return local_dest

Transport file on the remote side to a local directory

Args:
- remote_source (string): remote_source
- local_dir (string): Local directory to copy to

Returns:
- str: Local path to file

Raises:
- FileExists : Name collision at local directory.
- FileCopyException : FileCopy failed.


def distance(self, physical_qubit1, physical_qubit2):

        if physical_qubit1 not in self.physical_qubits:
            raise CouplingError("%s not in coupling graph" % (physical_qubit1,))
        if physical_qubit2 not in self.physical_qubits:
            raise CouplingError("%s not in coupling graph" % (physical_qubit2,))
        if self._dist_matrix is None:
            self._compute_distance_matrix()
        return self._dist_matrix[physical_qubit1, physical_qubit2]

Returns the undirected distance between physical_qubit1 and physical_qubit2.

Args:
physical_qubit1 (int): A physical qubit
physical_qubit2 (int): Another physical qubit

Returns:
int: The undirected distance

Raises:
CouplingError: if the qubits do not exist in the CouplingMap


def __init__(self, message):

        super(KeyFormatTypeNotSupported, self).__init__(
            reason=enums.ResultReason.KEY_FORMAT_TYPE_NOT_SUPPORTED,
            message=message
        )

Create a KeyFormatTypeNotSupported exception.

Args:
message (string): A string containing information about the error.


def _add_open_file(self, file_obj):
    if self._free_fd_heap:
        open_fd = heapq.heappop(self._free_fd_heap)
        self.open_files[open_fd] = [file_obj]
        return open_fd
    self.open_files.append([file_obj])
    return (len(self.open_files) - 1)

Add file_obj to the list of open files on the filesystem.
Used internally to manage open files.

The position in the open_files array is the file descriptor number.

Args:
file_obj: File object to be added to open files list.

Returns:
File descriptor number for the file object.


def __init__(self, address=None, port=None, services=0, timestamp=int(datetime.utcnow().timestamp())):

        self.Address = address
        self.Port = port
        self.Services = services
        self.Timestamp = timestamp

Create an instance.

Args:
address (str):
port (int):
services (int):
timestamp (int):


def manufacturer(self):

        buf = ctypes.cast(self.sManu, ctypes.c_char_p).value
        return buf.decode() if buf else None

Returns the name of the manufacturer of the device.

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

Returns:
Manufacturer name.


def Query(self, query):
    cursor = self._database.cursor()
    cursor.execute(query)
    return cursor

Queries the database.

Args:
query (str): SQL query.

Returns:
sqlite3.Cursor: results.

Raises:
sqlite3.DatabaseError: if querying the database fails.


def setDocuments(self, documenting_pid, documented_pid):
    self._check_initialized()
    documenting_id = self.getObjectByPid(documenting_pid)
    documented_id = self.getObjectByPid(documented_pid)
    self.add((documenting_id, CITO.documents, documented_id))

Add a CiTO, the Citation Typing Ontology, triple asserting that
``documenting_pid`` documents ``documented_pid``.

Adds assertion: ``documenting_pid cito:documents documented_pid``

Args:
documenting_pid: str
PID of a Science Object that documents ``documented_pid``.

documented_pid: str
PID of a Science Object that is documented by ``documenting_pid``.


def device_slug_to_id(slug):

    if not isinstance(slug, str):
        raise ArgumentError("Invalid device slug that is not a string", slug=slug)

    try:
        device_slug = IOTileDeviceSlug(slug, allow_64bits=False)
    except ValueError:
        raise ArgumentError("Unable to recognize {} as a device id".format(slug))

    return device_slug.get_id()

Convert a d-- device slug to an integer.

Args:
slug (str): A slug in the format d--XXXX-XXXX-XXXX-XXXX

Returns:
int: The device id as an integer

Raises:
ArgumentError: if there is a malformed slug


def tpu_batch_size_per_shard(self, model_hparams):
    if (self.batch_size_means_tokens and (not model_hparams.use_fixed_batch_size)):
        return (model_hparams.batch_size
    else:
        return model_hparams.batch_size

Batch size in examples per TPU core.

Args:
model_hparams: model hyperparameters
Returns:
an integer


def export(self, top=True):

        out = []
        if top:
            out.append(self._internal_name)
        out.append(self._to_str(self.leapyear_observed))
        out.append(self._to_str(self.daylight_saving_start_day))
        out.append(self._to_str(self.daylight_saving_end_day))
        out.append(str(len(self.holidays)))
        for obj in self.holidays:
            out.append(obj.export(top=False))
        return ",".join(out)

Exports object to its string representation.

Args:
top (bool):  if True appends `internal_name` before values.
All non list objects should be exported with value top=True,
all list objects, that are embedded in as fields inlist objects
should be exported with `top`=False

Returns:
str: The objects string representation


def __init__(self, seg_prefix, last_seg_index):

    self._EOF = False
    self._offset = 0

    self._seg_prefix = seg_prefix
    self._last_seg_index = last_seg_index
    self._seg_index = -1
    self._seg_valid_length = None
    self._seg = None
    self._next_seg()

Init.

Instances are pickle safe.

Args:
seg_prefix: filename prefix for all segs. It is expected
seg_prefix + index = seg filename.
last_seg_index: the last index of all segs. int.


def get_tokens(tokens):

    tokens = tokens[1:-1]
    ret = []
    start = 0
    stack = 0
    for i in range(len(tokens)):
        if tokens[i] == '(':
            if stack == 0:
                start = i
            stack += 1
        elif tokens[i] == ')':
            stack -= 1
            if stack < 0:
                raise Exception('Bracket mismatch: ' + str(tokens))
            if stack == 0:
                ret.append(get_tokens(tokens[start:i + 1]))
        else:
            if stack == 0:
                ret.append(tokens[i])
    if stack != 0:
        raise Exception('Bracket mismatch: ' + str(tokens))
    return ret

Recursively gets tokens from a match list

Args:
tokens : List of tokens ['(', 'S', '(', 'NP', ')', ')']
Returns:
Stack of tokens


def transform_wrap_with(source, left, right, name=None):

    with ops.name_scope(name, "TransformWrapWith", [source]):
        source = convert_to_tensor_or_sparse_tensor(source, dtype=tf.string)
        if isinstance(source, tf.SparseTensor):
            result = tf.SparseTensor(
                indices=source.indices,
                values=ops_module.transform_wrap_with(source.values, left, right),
                dense_shape=source.dense_shape
            )
        else:
            result = ops_module.transform_wrap_with(source, left, right)

        return result

Wrap source strings with "left" and "right" strings

Args:
source: `Tensor` or `SparseTensor` of any shape, strings to replace digits.
left: Scalar string to add in the beginning
right: Scalar string to add in the ending
name: A name for the operation (optional).
Returns:
`SparseTensor` of same shape and size as input.


def _create_candidates(self, n=1000):

        if self.grid:
            return self._candidates_from_grid(n)

        else:
            return self._random_candidates(n)

Generate random hyperparameter vectors

Args:
n (int, optional): number of candidates to generate. Defaults to 1000.

Returns:
candidates (np.array): Array of candidate hyperparameter vectors with shape
(n_samples, len(tunables))


def _pack_iterator_resource_dtensor(datasets: List[Tuple[int, data_types.DatasetV2]], layouts: Any, mesh: layout_lib.Mesh, num_local_devices_per_replica: int):
    host_mesh_devices = mesh.host_mesh().local_devices()
    device_idx = 0
    iterators = []
    for _, dataset in datasets:
        for idx in range(num_local_devices_per_replica):
            with ops.device_v2(host_mesh_devices[device_idx]):
                device_dataset = dataset.shard(num_shards=num_local_devices_per_replica, index=idx)
                iterators.append(iter(device_dataset))
            device_idx += 1
    if device_idx != len(host_mesh_devices):
        raise ValueError(f'The `datasets` argument does not have the correct number of underlying datasets, found {device_idx} but expected {len(host_mesh_devices)}.')
    host_layouts = nest.map_structure(lambda l: layout_lib.Layout(l.sharding_specs, mesh.host_mesh()), layouts)
    iterator_resources = [it._iterator_resource for it in iterators]
    d_iterator_resource = api.pack(iterator_resources, layout_lib.Layout.replicated(mesh=mesh.host_mesh(), rank=0))
    api._dtensor_device().set_iterator_element_layouts(d_iterator_resource, nest.flatten(host_layouts))
    return d_iterator_resource

Creates a DTensor iterator resource for the per-replica datasets.

Given a list of replica ID to tf.data.Dataset mappings, this function creates
iterators for each device and then packs the underlying iterator resource
tensors into a single DTensor. This resource tensor is used by the
IteratorGetNext op to retrieve the next element in the dataset.

Args:
datasets: a list of tuples of each unique local replica ID to the dataset
object whose elements will be placed on the devices corresponding to that
replica.
layouts: a structure of DTensor layouts to be applied to the elements
returned by the underlying iterators. This can be a single layout or
(possibly nested) tuples or dictionaries of layouts, and the structure
must match the structure of the iterator elements.
mesh: the DTensor mesh to place the iterator batches on.
num_local_devices_per_replica: the number of devices in each data-parallel
replica.

Returns:
A DTensor of the underlying iterator resource tensors.


def _from_to_as_term(self, frm, to):
    from_year = ''
    to_year = ''

    def year_or_empty(prefix, year, suffix):
        try:
            return ((prefix + str(int(year))) + suffix)
        except (ValueError, TypeError):
            return ''
    if frm:
        from_year = year_or_empty('', frm, ' ')
    if to:
        to_year = year_or_empty(' ', to, '')
    if (bool(from_year) or bool(to_year)):
        return '[{}TO{}]'.format(from_year, to_year)
    else:
        return None

Turns from and to into the query format.

Args:
frm (str): from year
to (str): to year

Returns:
FTS query str with years range.


def file_copy(filename, settings):

        for k, v in settings.items():
            if k.startswith("dest"):
                shutil.copyfile(filename, v)

Copies a file. {'_file_copy': {'dest': 'new_file_name'}}

Args:
filename (str): Filename.
settings (dict): Must be {"dest": path of new file}


class Pix2StructProcessor(ProcessorMixin):
    attributes = ['image_processor', 'tokenizer']
    image_processor_class = 'Pix2StructImageProcessor'
    tokenizer_class = ('T5Tokenizer', 'T5TokenizerFast')

    def __init__(self, image_processor, tokenizer):
        tokenizer.return_token_type_ids = False
        super().__init__(image_processor, tokenizer)

    def __call__(self, images=None, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]=None, audio=None, videos=None, **kwargs: Unpack[Pix2StructProcessorKwargs]) -> Union[BatchEncoding, BatchFeature]:

        if images is None and text is None:
            raise ValueError('You have to specify either images or text.')
        output_kwargs = self._merge_kwargs(Pix2StructProcessorKwargs, tokenizer_init_kwargs=self.tokenizer.init_kwargs, **kwargs)
        add_special_tokens = output_kwargs['text_kwargs'].pop('add_special_tokens', None)
        if images is None and (not self.image_processor.is_vqa):
            output_kwargs['text_kwargs']['add_special_tokens'] = add_special_tokens if add_special_tokens is not None else True
            self.current_processor = self.tokenizer
            text_encoding = self.tokenizer(text=text, **output_kwargs['text_kwargs'])
            return text_encoding
        if not self.image_processor.is_vqa:
            encoding_image_processor = self.image_processor(images, **output_kwargs['images_kwargs'])
        else:
            output_kwargs['images_kwargs'].setdefault('header_text', text)
            encoding_image_processor = self.image_processor(images, **output_kwargs['images_kwargs'])
        if text is not None and (not self.image_processor.is_vqa):
            output_kwargs['text_kwargs']['add_special_tokens'] = add_special_tokens if add_special_tokens is not None else False
            text_encoding = self.tokenizer(text=text, **output_kwargs['text_kwargs'])
            if 'attention_mask' in text_encoding:
                text_encoding['decoder_attention_mask'] = text_encoding.pop('attention_mask')
            if 'input_ids' in text_encoding:
                text_encoding['decoder_input_ids'] = text_encoding.pop('input_ids')
        else:
            text_encoding = None
        if text_encoding is not None:
            encoding_image_processor.update(text_encoding)
        return encoding_image_processor

    def batch_decode(self, *args, **kwargs):

        return self.tokenizer.batch_decode(*args, **kwargs)

    def decode(self, *args, **kwargs):

        return self.tokenizer.decode(*args, **kwargs)

    @property
    def model_input_names(self):
        tokenizer_input_names = self.tokenizer.model_input_names
        image_processor_input_names = self.image_processor.model_input_names
        return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))

Constructs a PIX2STRUCT processor which wraps a BERT tokenizer and PIX2STRUCT image processor into a single
processor.

[`Pix2StructProcessor`] offers all the functionalities of [`Pix2StructImageProcessor`] and [`T5TokenizerFast`]. See
the docstring of [`~Pix2StructProcessor.__call__`] and [`~Pix2StructProcessor.decode`] for more information.

Args:
image_processor (`Pix2StructImageProcessor`):
An instance of [`Pix2StructImageProcessor`]. The image processor is a required input.
tokenizer (Union[`T5TokenizerFast`, `T5Tokenizer`]):
An instance of ['T5TokenizerFast`] or ['T5Tokenizer`]. The tokenizer is a required input.


def UploadImageAsset(client, url):

  asset_service = client.GetService('AssetService', version='v201809')

  image_request = requests.get(url)

  image_asset = {
      'xsi_type': 'ImageAsset',
      'imageData': image_request.content,

  }

  operation = {
      'operator': 'ADD',
      'operand': image_asset
  }

  result = asset_service.mutate([operation])

  return result['value'][0]['assetId']

Uploads the image from the specified url.

Args:
client: An AdWordsClient instance.
url: The image URL.

Returns:
The ID of the uploaded image.


def __init__(self, selenium, handle):

        self.selenium = selenium
        self.handle = handle
        self.wait = WebDriverWait(self.selenium, timeout=10)

Create a BaseWindow object.

Args:
selenium:
(:py:class:`~selenium.webdriver.remote.webdriver.WebDriver`):
Firefox WebDriver object.
handle: (str): WebDriver Firefox window handle.


def _GetChromeWebStorePage(self, extension_identifier):
    web_store_url = self._WEB_STORE_URL.format(xid=extension_identifier)
    try:
        response = requests.get(web_store_url)
    except (requests.ConnectionError, requests.HTTPError) as exception:
        logger.warning('[{0:s}] unable to retrieve URL: {1:s} with error: {2!s}'.format(self.NAME, web_store_url, exception))
        return None
    return response.text

Retrieves the page for the extension from the Chrome store website.

Args:
extension_identifier (str): Chrome extension identifier.

Returns:
str: page content or None.


def parse_delta(__string: str) -> datetime.timedelta:
    if (not __string):
        return datetime.timedelta(0)
    match = re.fullmatch('\n        P\n        ((?P<days>\\d+)D)?\n        T?\n        ((?P<hours>\\d{1,2})H)?\n        ((?P<minutes>\\d{1,2})M)?\n        ((?P<seconds>\\d{1,2})?((?:\\.(?P<microseconds>\\d+))?S)?)\n    ', __string, re.VERBOSE)
    if (not match):
        raise ValueError('Unable to parse delta {!r}'.format(__string))
    match_dict = {k: (int(v) if v else 0) for (k, v) in match.groupdict().items()}
    return datetime.timedelta(**match_dict)

Parse ISO-8601 duration string.

Args:
__string: Duration string to parse
Returns:
Parsed delta object


def find_all(self, predicate):

        for _nid, entry in self._registry.items():
            if predicate(entry):
                yield entry

Returns a generator that produces a sequence of Entry objects for which the predicate returned True.
Args:
predicate:  A callable that returns a value coercible to bool.


def from_rotation_and_translation_and_time_reversal(
            rotation_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)),
            translation_vec=(0, 0, 0), time_reversal=1, tol=0.1):

        symmop = SymmOp.from_rotation_and_translation(rotation_matrix=rotation_matrix,
                                                      translation_vec=translation_vec,
                                                      tol=tol)
        return MagSymmOp.from_symmop(symmop, time_reversal)

Creates a symmetry operation from a rotation matrix, translation
vector and time reversal operator.

Args:
rotation_matrix (3x3 array): Rotation matrix.
translation_vec (3x1 array): Translation vector.
time_reversal (int): Time reversal operator, +1 or -1.
tol (float): Tolerance to determine if rotation matrix is valid.

Returns:
MagSymmOp object


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

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

    if path_spec.parent.type_indicator != (
        definitions.TYPE_INDICATOR_APFS_CONTAINER):
      raise errors.PathSpecError(
          'Unsupported path specification not type APFS container.')

    apfs_container_file_system = resolver.Resolver.OpenFileSystem(
        path_spec.parent, resolver_context=self._resolver_context)

    fsapfs_volume = apfs_container_file_system.GetAPFSVolumeByPathSpec(
        path_spec.parent)
    if not fsapfs_volume:
      raise IOError('Unable to retrieve APFS volume')

    try:
      is_locked = not apfs_helper.APFSUnlockVolume(
          fsapfs_volume, path_spec.parent, resolver.Resolver.key_chain)
    except IOError as exception:
      raise IOError('Unable to unlock APFS volume with error: {0!s}'.format(
          exception))

    if is_locked:
      raise IOError('Unable to unlock APFS volume.')

    self._fsapfs_volume = fsapfs_volume

Opens the file system defined by path specification.

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

Raises:
AccessError: if the access to open the file was denied.
IOError: if the APFS volume could not be retrieved or unlocked.
OSError: if the APFS volume could not be retrieved or unlocked.
PathSpecError: if the path specification is incorrect.
ValueError: if the path specification is invalid.


def generate_secret(length=32):

  alphabet = string.ascii_letters + string.digits
  random_bytes = os.urandom(length)
  indices = [int(len(alphabet) * (ord(byte) / 256.0)) for byte in random_bytes]
  return "".join([alphabet[index] for index in indices])

Generate a random secret consisting of mixed-case letters and numbers
Args:
length (int): Length of the generated password
Returns:
a randomly generated secret string
Raises:
None


def get_jwt_dict(jwt_bu64):
    jwt_tup = get_jwt_tup(jwt_bu64)
    try:
        jwt_dict = json.loads(jwt_tup[0].decode('utf-8'))
        jwt_dict.update(json.loads(jwt_tup[1].decode('utf-8')))
        jwt_dict['_sig_sha1'] = hashlib.sha1(jwt_tup[2]).hexdigest()
    except TypeError as e:
        raise JwtException('Decode failed. error="{}"'.format(e))
    return jwt_dict

Parse Base64 encoded JWT and return as a dict.

- JWTs contain a set of values serialized to a JSON dict. This decodes the JWT and
returns it as a dict containing Unicode strings.
- In addition, a SHA1 hash is added to the dict for convenience.

Args:
jwt_bu64: bytes
JWT, encoded using a a URL safe flavor of Base64.

Returns:
dict: Values embedded in and derived from the JWT.


def FromDict(cls, obj):

        timestamp = obj.get('timestamp')
        if timestamp is not None:
            import dateutil.parser
            timestamp = dateutil.parser.parse(timestamp)

        return IOTileEvent(obj.get('device_timestamp'), obj.get('stream'), obj.get('extra_data'),
                           obj.get('data'), reading_id=obj.get('streamer_local_id'), reading_time=timestamp)

Create an IOTileEvent from the result of a previous call to asdict().

Args:
obj (dict): A dictionary produced by a call to IOTileEvent.asdict()

Returns:
IOTileEvent: The converted IOTileEvent object.


def _compute_dynamic_ntk_parameters(config: Optional[PretrainedConfig]=None, device: Optional['torch.device']=None, seq_len: Optional[int]=None, **rope_kwargs) -> tuple['torch.Tensor', float]:
    if config is not None and len(rope_kwargs) > 0:
        raise ValueError(f'Unexpected arguments: `**rope_kwargs` and `config` are mutually exclusive in `_compute_dynamic_ntk_parameters`, got `rope_kwargs`={rope_kwargs} and `config`={config}')
    if len(rope_kwargs) > 0:
        base = rope_kwargs['base']
        dim = rope_kwargs['dim']
        max_position_embeddings = rope_kwargs['max_position_embeddings']
        factor = rope_kwargs['factor']
    elif config is not None:
        base = config.rope_theta
        partial_rotary_factor = config.partial_rotary_factor if hasattr(config, 'partial_rotary_factor') else 1.0
        head_dim = getattr(config, 'head_dim', config.hidden_size
        dim = int(head_dim * partial_rotary_factor)
        max_position_embeddings = config.max_position_embeddings
        factor = config.rope_scaling['factor']
    attention_factor = 1.0
    seq_len = seq_len if seq_len is not None and seq_len > max_position_embeddings else max_position_embeddings
    base = base * (factor * seq_len / max_position_embeddings - (factor - 1)) ** (dim / (dim - 2))
    inv_freq = 1.0 / base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
    return (inv_freq, attention_factor)

Computes the inverse frequencies with NTK scaling. Credits to the Reddit users /u/bloc97 and /u/emozilla
Args:
config ([`~transformers.PretrainedConfig`]):
The model configuration.
device (`torch.device`):
The device to use for initialization of the inverse frequencies.
seq_len (`int`, *optional*):
The current sequence length, used to update the dynamic RoPE at inference time.
rope_kwargs (`Dict`, *optional*):
BC compatibility with the previous RoPE class instantiation, will be removed in v4.45.
Returns:
Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
post-processing scaling factor applied to the computed cos/sin (unused in this type of RoPE).


def _large_compatible_negative(tensor_type):
    if tensor_type == dtypes.float16:
        return dtypes.float16.min
    return -1000000000.0

Large negative number as Tensor.

This function is necessary because the standard value for epsilon
in this module (-1e9) cannot be represented using tf.float16

Args:
tensor_type: a dtype to determine the type.

Returns:
a large negative number.


def create(self, model_name):
    body = {'name': model_name}
    parent = ('projects/' + self._project_id)
    return self._api.projects().models().create(body=body, parent=parent).execute()

Create a model.

Args:
model_name: the short name of the model, such as "iris".
Returns:
If successful, returns informaiton of the model, such as
{u'regions': [u'us-central1'], u'name': u'projects/myproject/models/mymodel'}
Raises:
If the model creation failed.


def get_victim_network_asset(self, main_type, sub_type, unique_id, asset_id, params=None):

        params = params or {}

        return self.victim_network_asset(main_type, sub_type, unique_id, asset_id, params=params)

Args:
main_type:
sub_type:
unique_id:
asset_id:
params:

Return:


def read_hdf(cls,path,key=None):

        df = pd.read_hdf(path,key)
        df['scored_calls'] = df['scored_calls'].apply(lambda x: json.loads(x))
        df['channel_values'] = df['channel_values'].apply(lambda x: json.loads(x))
        df['regions'] = df['regions'].apply(lambda x: json.loads(x))
        df['phenotype_calls'] = df['phenotype_calls'].apply(lambda x: json.loads(x))
        df['neighbors'] = df['neighbors'].apply(lambda x: json.loads(x))
        df['neighbors'] = df['neighbors'].apply(lambda x:
                np.nan if not isinstance(x,dict) else dict(zip([int(y) for y in x.keys()],x.values()))
            )
        df['frame_shape'] = df['frame_shape'].apply(lambda x: tuple(json.loads(x)))
        df = cls(df)
        f = h5py.File(path,'r')
        mpp = f[key].attrs["microns_per_pixel"]
        if not np.isnan(mpp): df.microns_per_pixel = mpp
        f.close()
        return df

Read a CellDataFrame from an hdf5 file.

Args:
path (str): the path to read from
key (str): the name of the location to read from

Returns:
CellDataFrame


def run_local(self, commands):
    process = subprocess.Popen(commands.get('cli_command'), shell=self.shell, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (out, err) = process.communicate()
    self.run_display_app_output(out)
    self.run_display_app_errors(err)
    return self.run_exit_code(process.returncode)

Run the App on local system.

Args:
commands (dict): A dictionary of the CLI commands.

Returns:
int: The exit code of the subprocess command.


def _file_exists_in_gcs(gcs_file_path, credentials=None):

  gcs_service = _get_storage_service(credentials)

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

Check whether the file exists, in GCS.

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

Returns:
True if the file's there.


def build(self, grad_list, get_opt_fn):

        assert len(grad_list) == len(self.towers)
        DataParallelBuilder._check_grad_list(grad_list)

        self.grads = aggregate_grads(grad_list, colocation=True)

        opt = get_opt_fn()
        if self.ps_device == 'cpu':
            with tf.device('/cpu:0'):
                train_op = opt.apply_gradients(self.grads, name='train_op')
        else:
            train_op = opt.apply_gradients(self.grads, name='train_op')
        return train_op

Reduce the gradients, apply them with the optimizer,
and set self.grads to a list of (g, v), containing the averaged gradients.

Args:
grad_list ([[(grad, var), ...], ...]): #GPU lists to be reduced. Each is the gradients computed on each GPU.
get_opt_fn (-> tf.train.Optimizer): callable which returns an optimizer

Returns:
tf.Operation: the training op


def FromTimestampToDateTime(ts):
    return datetime.datetime.utcfromtimestamp(ts)

Converts internal nss_cache timestamp to datetime object.

Args:
ts: number of seconds since epoch
Returns:
datetime object


def getatime(self, path):
    try:
        file_obj = self.filesystem.resolve(path)
    except IOError:
        self.filesystem.raise_os_error(errno.ENOENT)
    return file_obj.st_atime

Returns the last access time of the fake file.

Note: Access time is not set automatically in fake filesystem
on access.

Args:
path: the path to fake file.

Returns:
(int, float) the access time of the fake file in number of seconds
since the epoch.

Raises:
OSError: if the file does not exist.


def decode_response(status: int, headers: MutableMapping, body: bytes) -> dict:

    data = decode_body(headers, body)
    raise_for_status(status, headers, data)
    raise_for_api_error(headers, data)

    return data

Decode incoming response

Args:
status: Response status
headers: Response headers
body: Response body

Returns:
Response data


def linear_extrapolation_plot(log_prob_adv_array, y, file_name,
                              min_epsilon=-10, max_epsilon=10,
                              num_points=21):

  import matplotlib
  matplotlib.use('Agg')
  import matplotlib.pyplot as plt

  figure = plt.figure()
  figure.canvas.set_window_title('Cleverhans: Linear Extrapolation Plot')

  correct_idx = np.argmax(y, axis=0)
  fig = plt.figure()
  plt.xlabel('Epsilon')
  plt.ylabel('Logits')
  x_axis = np.linspace(min_epsilon, max_epsilon, num_points)
  plt.xlim(min_epsilon - 1, max_epsilon + 1)
  for i in range(y.shape[0]):
    if i == correct_idx:
      ls = '-'
      linewidth = 5
    else:
      ls = '--'
      linewidth = 2
    plt.plot(
        x_axis,
        log_prob_adv_array[:, i],
        ls=ls,
        linewidth=linewidth,
        label='{}'.format(i))
  plt.legend(loc='best', fontsize=14)
  plt.show()
  fig.savefig(file_name)
  plt.clf()
  return figure

Generate linear extrapolation plot.

Args:
log_prob_adv_array: Numpy array containing log probabilities
y: Tf placeholder for the labels
file_name: Plot filename
min_epsilon: Minimum value of epsilon over the interval
max_epsilon: Maximum value of epsilon over the interval
num_points: Number of points used to interpolate


def next_id(self, channel):
    if (channel not in self.topics):
        self.topics[channel] = 0
        return 0
    self.topics[channel] += 1
    return self.topics[channel]

Get the next sequence number for a named channel or topic

If channel has not been sent to next_id before, 0 is returned
otherwise next_id returns the last id returned + 1.

Args:
channel (string): The name of the channel to get a sequential
id for.

Returns:
int: The next id for this channel


def match(self, request):
    for test in self.filters:
        if (not test(request, self)):
            return False
    for mapper in self.mappers:
        request = mapper(request, self)
        if (not request):
            raise ValueError('map function must return a request object')
    match_errors = []
    for mock in self.mocks[:]:
        try:
            (matches, errors) = mock.match(request.copy())
            if len(errors):
                match_errors += errors
            if matches:
                return mock
        except PookExpiredMock:
            self.mocks.remove(mock)
    if (not self.should_use_network(request)):
        msg = 'pook error!\n\n'
        msg += '=> Cannot match any mock for the following request:\n{}'.format(request)
        if self.debug:
            err = '\n\n'.join([str(err) for err in match_errors])
            if err:
                msg += '\n\n=> Detailed matching errors:\n{}\n'.format(err)
        raise PookNoMatches(msg)
    self.unmatched_reqs.append(request)

Matches a given Request instance contract against the registered mocks.

If a mock passes all the matchers, its response will be returned.

Arguments:
request (pook.Request): Request contract to match.

Raises:
pook.PookNoMatches: if networking is disabled and no mock matches
with the given request contract.

Returns:
pook.Response: the mock response to be used by the interceptor.


def _SanitizeField(self, field):

    if self._FIELD_DELIMITER and isinstance(field, py2to3.STRING_TYPES):
      return field.replace(self._FIELD_DELIMITER, ' ')
    return field

Sanitizes a field for output.

This method removes the field delimiter from the field string.

Args:
field (str): field value.

Returns:
str: formatted field value.


def _get_facet_chempots(self, facet):

        complist = [self.qhull_entries[i].composition for i in facet]
        energylist = [self.qhull_entries[i].energy_per_atom for i in facet]
        m = [[c.get_atomic_fraction(e) for e in self.elements] for c in
             complist]
        chempots = np.linalg.solve(m, energylist)
        return dict(zip(self.elements, chempots))

Calculates the chemical potentials for each element within a facet.

Args:
facet: Facet of the phase diagram.

Returns:
{ element: chempot } for all elements in the phase diagram.


def read_struct(fstream):

    line = fstream.readline().strip()
    fragments = line.split(",")
    fragments = [x for x in fragments if x is not None]
    partition = dict()
    if not len(fragments) >= 3:
        return None

    partition["struct"] = fragments[0]
    partition["info"] = fragments[1]
    partition["num_lines"] = fragments[2]

    struct = None
    if partition is not None and partition["struct"] == "STRUCT":
        num_lines = int(partition["num_lines"].strip())
        struct = {}
        for _ in range(num_lines):
            cols = fetch_cols(fstream)
            struct.update({cols[0]: cols[1:]})
    return struct

Read a likwid struct from the text stream.

Args:
fstream: Likwid's filestream.

Returns (dict(str: str)):
A dict containing all likwid's struct info as key/value pairs.


def transmit(self, payload, **kwargs):

        kwargs['app_label'] = 'sap_success_factors'
        kwargs['model_name'] = 'SapSuccessFactorsLearnerDataTransmissionAudit'
        kwargs['remote_user_id'] = 'sapsf_user_id'
        super(SapSuccessFactorsLearnerTransmitter, self).transmit(payload, **kwargs)

Send a completion status call to SAP SuccessFactors using the client.

Args:
payload: The learner completion data payload to send to SAP SuccessFactors


def paths_referenced_by(node: AbstractSyntaxTree) -> Collection[str]:
    context, paths = _paths_referenced_by(node)
    paths = set(paths)
    if context is not None:
        paths.add(context)
    return paths

Finds paths for any fields referenced in the given tree.

For example, given the expression 'a.b.where(c > d.e)' returns paths
['a.b', 'a.b.c', 'a.b.d.e']

Args:
node: The abstract syntax tree to search for paths.

Returns:
A collections of paths referenced in the AST.


def create_model(self, ModelName, PrimaryContainer, *args, **kwargs):
    LocalSagemakerClient._models[ModelName] = _LocalModel(ModelName, PrimaryContainer)

Create a Local Model Object

Args:
ModelName (str): the Model Name
PrimaryContainer (dict): a SageMaker primary container definition


def get_input_embeddings(self) -> nn.Module:
    base_model = getattr(self, self.base_model_prefix, self)
    if base_model is not self:
        return base_model.get_input_embeddings()
    else:
        raise NotImplementedError

Returns the model's input embeddings.

Returns:
`nn.Module`: A torch module mapping vocabulary to hidden states.


def _decorate(self, decorator):
    if self._variable_creation_config is not None or self._no_variable_creation_config is not None:
        raise ValueError('Functions cannot be decorated after they have been traced.')
    self._python_function = decorator(self._python_function)
    self._function_type, self._default_values = function_type_utils.make_function_type(self._python_function, self.input_signature)

Allows the captured Python function to be decorated in place.

This method is only safe to call when the Function has not been called by a
user. It makes sense to use this method to push a decorator into the
function rather than wrapping the function in the decorator.

We use this in tf.Module to allow user annotated `tf.functions` to remain as
`Function` objects but still automatically enter the Module name_scope
when they are evaluated like all other methods.

Args:
decorator: A callable accepting a single argument which is the function
to decorate and returning a callable result.

Raises:
ValueError: If the function has been called a ValueError is raised.


def default_filename(ext):
    if (ext == 'py'):
        raise RuntimeError("asked for a default filename with 'py' extension")
    filename = detect_current_filename()
    if (filename is None):
        return temp_filename(ext)
    basedir = (dirname(filename) or getcwd())
    if (_no_access(basedir) or _shares_exec_prefix(basedir)):
        return temp_filename(ext)
    (name, _) = splitext(basename(filename))
    return join(basedir, ((name + '.') + ext))

Generate a default filename with a given extension, attempting to use
the filename of the currently running process, if possible.

If the filename of the current process is not available (or would not be
writable), then a temporary file with the given extension is returned.

Args:
ext (str) : the desired extension for the filename

Returns:
str

Raises:
RuntimeError
If the extensions requested is ".py"


def _convert_oauth2_credentials(credentials):

    new_credentials = google.oauth2.credentials.Credentials(
        token=credentials.access_token,
        refresh_token=credentials.refresh_token,
        token_uri=credentials.token_uri,
        client_id=credentials.client_id,
        client_secret=credentials.client_secret,
        scopes=credentials.scopes)

    new_credentials._expires = credentials.token_expiry

    return new_credentials

Converts to :class:`google.oauth2.credentials.Credentials`.

Args:
credentials (Union[oauth2client.client.OAuth2Credentials,
oauth2client.client.GoogleCredentials]): The credentials to
convert.

Returns:
google.oauth2.credentials.Credentials: The converted credentials.


def __init__(self, path_spec=None):

    super(EventSource, self).__init__()
    self.data_type = self.DATA_TYPE
    self.file_entry_type = None
    self.path_spec = path_spec

Initializes an event source.

Args:
path_spec (Optional[dfvfs.PathSpec]): path specification.


def t2t_train(model_name, dataset_name, data_dir=None, output_dir=None, config_file=None, config=None):
    if (model_name not in _MODEL_REGISTRY):
        raise ValueError(('Model %s not in registry. Available models:\n * %s.' % (model_name, '\n * '.join(_MODEL_REGISTRY.keys()))))
    model_class = _MODEL_REGISTRY[model_name]()
    gin.bind_parameter('train_fn.model_class', model_class)
    gin.bind_parameter('train_fn.dataset', dataset_name)
    gin.parse_config_files_and_bindings(config_file, config)
    train_fn(data_dir, output_dir=output_dir)

Main function to train the given model on the given dataset.

Args:
model_name: The name of the model to train.
dataset_name: The name of the dataset to train on.
data_dir: Directory where the data is located.
output_dir: Directory where to put the logs and checkpoints.
config_file: the gin configuration file to use.
config: string (in gin format) to override gin parameters.


def pretty_print(input_word, anagrams, by_length=False):
    scores = {}
    if by_length:
        noun = 'tiles'
        for (word, score) in anagrams:
            try:
                scores[len(word)].append('{0} ({1:d})'.format(word, score))
            except KeyError:
                scores[len(word)] = ['{0} ({1:d})'.format(word, score)]
    else:
        noun = 'points'
        for (word, score) in anagrams:
            try:
                scores[score].append(word)
            except KeyError:
                scores[score] = [word]
    print('Anagrams for {0}{1}:'.format(input_word, (' (score)' * by_length)))
    if (not valid_scrabble_word(input_word)):
        print('{0} is not possible in Scrabble.'.format(input_word))
    for (key, value) in sorted(scores.items(), reverse=True):
        print('{0:d} {1}: {2}'.format(key, noun, ', '.join(value)))

Prints the anagram results sorted by score to stdout.

Args:
input_word: the base word we searched on
anagrams: generator of (word, score) from anagrams_in_word
by_length: a boolean to declare printing by length instead of score