def reset_sequence(self, topic):

        if topic in self.queues:
            self.queues[topic].reset()

Reset the expected sequence number for a topic

If the topic is unknown, this does nothing.  This behaviour is
useful when you have wildcard topics that only create queues
once they receive the first message matching the topic.

Args:
topic (string): The topic to reset the packet queue on


def write_file(self, filename, file_format="xyz"):

        mol = pb.Molecule(self._obmol)
        return mol.write(file_format, filename, overwrite=True)

Uses OpenBabel to output all supported formats.

Args:
filename: Filename of file to output
file_format: String specifying any OpenBabel supported formats.


def intersect(self, other):

        operation = bool.__and__
        self.cross_product(other, operation)
        return  self

Constructs an unminimized DFA recognizing
the intersection of the languages of two given DFAs.
Args:
other (DFA): The other DFA that will be used
for the intersect operation
Returns:
Returns:
DFA: The resulting DFA


def raster_to_gtiff(tif, geotif, change_nodata=False, change_gdal_type=False):

        rst_file = RasterUtilClass.read_raster(tif)
        nodata = rst_file.noDataValue
        if change_nodata:
            if not MathClass.floatequal(rst_file.noDataValue, DEFAULT_NODATA):
                nodata = DEFAULT_NODATA
                rst_file.data[rst_file.data == rst_file.noDataValue] = DEFAULT_NODATA
        gdal_type = rst_file.dataType
        if change_gdal_type:
            gdal_type = GDT_Float32
        RasterUtilClass.write_gtiff_file(geotif, rst_file.nRows, rst_file.nCols, rst_file.data,
                                         rst_file.geotrans, rst_file.srs, nodata,
                                         gdal_type)

Converting Raster format to GeoTIFF.

Args:
tif: source raster file path.
geotif: output raster file path.
change_nodata: change NoDataValue to -9999 or not.
gdal_type (:obj:`pygeoc.raster.GDALDataType`): GDT_Float32 as default.
change_gdal_type: If True, output the Float32 data type.


def from_tensor(tensor, validate=True):
    tensor = tf.convert_to_tensor(tensor, dtype=tf.int32)
    return from_year_month_day(year=tensor[..., 0], month=tensor[..., 1], day=tensor[..., 2], validate=validate)

Creates DateTensor from a single tensor containing years, months and days.

This function is complementary to DateTensor.to_tensor: given an int32 Tensor
of shape (..., 3), creates a DateTensor. The three elements of the last
dimension are years, months and days, in this order.

Args:
tensor: Tensor of type int32 and shape (..., 3).
validate: Whether to validate the dates.

Returns:
DateTensor object.

#### Example

```python
tensor = tf.constant([[2015, 4, 15], [2017, 12, 30]], dtype=tf.int32)
date_tensor = tff.datetime.dates_from_tensor(tensor)
```


def _has_tf_decorator_attr(obj):
    return hasattr(obj, '_tf_decorator') and isinstance(getattr(obj, '_tf_decorator'), TFDecorator)

Checks if object has _tf_decorator attribute.

This check would work for mocked object as well since it would
check if returned attribute has the right type.

Args:
obj: Python object.


def get_attribute_label(
        self, main_type, sub_type, unique_id, attribute_id, label, owner=None, params=None
    ):

        return self.attribute_label(
            main_type, sub_type, unique_id, attribute_id, label, owner=owner, params=params
        )

Args:
owner:
main_type:
sub_type:
unique_id:
attribute_id:
label:
params:

Return:


def _collect_leaf_level_keys(cross):
    leaf_level_keys = []
    for k in cross.keys:
        if isinstance(k, _CrossedColumn):
            leaf_level_keys.extend(_collect_leaf_level_keys(k))
        else:
            leaf_level_keys.append(k)
    return leaf_level_keys

Collects base keys by expanding all nested crosses.

Args:
cross: A `_CrossedColumn`.

Returns:
A list of strings or `_CategoricalColumn` instances.


def _wait_time(self, shard_state, secs, now=datetime.datetime.now):

    assert shard_state.slice_start_time is not None
    delta = now() - shard_state.slice_start_time
    duration = datetime.timedelta(seconds=secs)
    if delta < duration:
      return util.total_seconds(duration - delta)
    else:
      return 0

Time to wait until slice_start_time is secs ago from now.

Args:
shard_state: shard state.
secs: duration in seconds.
now: a func that gets now.

Returns:
0 if no wait. A positive int in seconds otherwise. Always around up.


def wavelength_match(a, b):

        if type(a) == (type(b) or
                       isinstance(a, numbers.Number) and
                       isinstance(b, numbers.Number)):
            return a == b
        elif a is None or b is None:
            return False
        elif isinstance(a, (list, tuple)) and len(a) == 3:
            return a[0] <= b <= a[2]
        elif isinstance(b, (list, tuple)) and len(b) == 3:
            return b[0] <= a <= b[2]
        else:
            raise ValueError("Can only compare wavelengths of length 1 or 3")

Return if two wavelengths are equal.

Args:
a (tuple or scalar): (min wl, nominal wl, max wl) or scalar wl
b (tuple or scalar): (min wl, nominal wl, max wl) or scalar wl


async def play(self, author, text_channel, query, index=None, stop_current=False, shuffle=False):
    if (self.state == 'off'):
        self.state = 'starting'
        self.prev_queue = []
        (await self.set_topic(''))
        (await self.msetup(text_channel))
        (await self.enqueue(query, index, stop_current, shuffle))
        (await self.vsetup(author))
        self.state = ('ready' if (self.mready and self.vready) else 'off')
    else:
        (await self.enqueue(query, index, stop_current, shuffle))
    if (self.state == 'ready'):
        if (self.streamer is None):
            (await self.vplay())

The play command

Args:
author (discord.Member): The member that called the command
text_channel (discord.Channel): The channel where the command was called
query (str): The argument that was passed with the command
index (str): Whether to play next or at the end of the queue
stop_current (bool): Whether to stop the currently playing song
shuffle (bool): Whether to shuffle the queue after starting


def exists(self, path):
    return self._gcsIO().exists(path)

Check if the provided path exists on the FileSystem.

Args:
path: string path that needs to be checked.

Returns: boolean flag indicating if path exists


def get_label(self, main_type, sub_type, unique_id, label, owner=None, params=None):

        params = params or {}

        return self.label(
            main_type, sub_type, unique_id, label, action='GET', owner=owner, params=params
        )

Args:
owner:
main_type:
sub_type:
unique_id:
label:
params:

Return:


def routerify(obj):
    router = Router()
    for info in get_routing_attributes(obj):
        router.add_route(*info)
    obj.__growler_router = router
    return router

Scan through attributes of object parameter looking for any which
match a route signature.
A router will be created and added to the object with parameter.

Args:
obj (object): The object (with attributes) from which to
setup a router

Returns:
Router: The router created from attributes in the object.


def insert(self, optional_root_locations_path):
    encountered_simple_optional = False
    parent_location = self._root_location
    for optional_root_location in optional_root_locations_path:
        if encountered_simple_optional:
            raise AssertionError(u'Encountered simple optional root location {} in path, butfurther locations are present. This should not happen: {}'.format(optional_root_location, optional_root_locations_path))
        if (optional_root_location not in self._location_to_children):
            encountered_simple_optional = True
        else:
            self._location_to_children[parent_location].add(optional_root_location)
            parent_location = optional_root_location

Insert a path of optional Locations into the tree.

Each OptionalTraversalTree object contains child Location objects as keys mapping to
other OptionalTraversalTree objects.

Args:
optional_root_locations_path: list of optional root Locations all except the last
of which must be present in complex_optional_roots


def git_checkout(branch_name, create=False):

    log.info("Checking out <33>{}".format(branch_name))
    shell.run('git checkout {} {}'.format('-b' if create else '', branch_name))

Checkout or create a given branch

Args:
branch_name (str):
The name of the branch to checkout or create.
create (bool):
If set to **True** it will create the branch instead of checking it
out.


def get_submission_filenames(self, tournament=None, round_num=None):
    query = '\n          query {\n            user {\n              submissions {\n                filename\n                selected\n                round {\n                   tournament\n                   number\n                }\n              }\n            }\n          }\n        '
    data = self.raw_query(query, authorization=True)['data']['user']
    filenames = [{'round_num': item['round']['number'], 'tournament': item['round']['tournament'], 'filename': item['filename']} for item in data['submissions'] if item['selected']]
    if (round_num is not None):
        filenames = [f for f in filenames if (f['round_num'] == round_num)]
    if (tournament is not None):
        filenames = [f for f in filenames if (f['tournament'] == tournament)]
    filenames.sort(key=(lambda f: (f['round_num'], f['tournament'])))
    return filenames

Get filenames of the submission of the user.

Args:
tournament (int): optionally filter by ID of the tournament
round_num (int): optionally filter round number

Returns:
list: list of user filenames (`dict`)

Each filenames in the list as the following structure:

* filename (`str`)
* round_num (`int`)
* tournament (`int`)

Example:
>>> NumerAPI().get_submission_filenames(3, 111)
[{'filename': 'model57-dMpHpYMPIUAF.csv',
'round_num': 111,
'tournament': 3}]


def restore(self, state):

        reading = state.get(u'reading')
        if reading is not None:
            reading = IOTileReading.FromDict(reading)

        selector = DataStreamSelector.FromString(state.get(u'selector'))
        if self.selector != selector:
            raise ArgumentError("Attempted to restore a VirtualStreamWalker with a different selector",
                                selector=self.selector, serialized_data=state)

        self.reading = reading

Restore the contents of this virtual stream walker.

Args:
state (dict): The previously serialized state.

Raises:
ArgumentError: If the serialized state does not have
a matching selector.


def ProcessClientResourcesStats(self, client_id, status):
    if hasattr(status, 'child_session_id'):
        flow_path = status.child_session_id
    else:
        flow_path = ('aff4:/%s/flows/%s' % (status.client_id, status.flow_id))
    resources = rdf_client_stats.ClientResources()
    resources.client_id = client_id
    resources.session_id = flow_path
    resources.cpu_usage.user_cpu_time = status.cpu_time_used.user_cpu_time
    resources.cpu_usage.system_cpu_time = status.cpu_time_used.system_cpu_time
    resources.network_bytes_sent = status.network_bytes_sent
    self.context.usage_stats.RegisterResources(resources)

Process status message from a client and update the stats.

Args:
client_id: Client id.
status: The status object returned from the client.


def coordinate_filter(self, query, mongo_query):

        LOG.debug('Adding genomic coordinates to the query')
        chromosome = query['chrom']
        mongo_query['chromosome'] = chromosome

        if (query.get('start') and query.get('end')):
            mongo_query['position'] = {'$lte': int(query['end'])}
            mongo_query['end'] = {'$gte': int(query['start'])}

        return mongo_query

Adds genomic coordinated-related filters to the query object

Args:
query(dict): a dictionary of query filters specified by the users
mongo_query(dict): the query that is going to be submitted to the database

Returns:
mongo_query(dict): returned object contains coordinate filters


def get_box_files(self, box_key):

		uri = '/'.join([self.api_uri,
						self.boxes_suffix,
						box_key,
						self.files_suffix
						])

		return self._req('get', uri)

Gets to file infos in a single box.
Args:
box_key		key for the file
return		(status code, list of file info dicts)


def set_dimension(tensor, axis, value):

  shape = tensor.shape.as_list()
  if shape[axis] not in (value, None):
    message = 'Cannot set dimension {} of tensor {} to {}; is already {}.'
    raise ValueError(message.format(axis, tensor.name, value, shape[axis]))
  shape[axis] = value
  tensor.set_shape(shape)

Set the length of a tensor along the specified dimension.

Args:
tensor: Tensor to define shape of.
axis: Dimension to set the static shape for.
value: Integer holding the length.

Raises:
ValueError: When the tensor already has a different length specified.


def send_file(self, file_name, remote_destination=None, **kwargs):
    if (not remote_destination):
        remote_destination = file_name
    return SubprocessTask((self._rsync_cmd() + ['-ut', file_name, ('%s:%s' % (self.hostname, remote_destination))]), **kwargs)

Send a file to a remote host with rsync.

Args:
file_name (str): The relative location of the file on the local
host.

remote_destination (str): The destination for the file on the remote
host. If `None`, will be assumed to be the same as
**file_name**. Default `None`.

**kwargs: Passed to ``SubprocessTask``'s init method.

Return:
``pyrem.task.SubprocessTask``: The resulting task.


def __len__(self):
    if not context.executing_eagerly():
        raise TypeError('`tf.data.Dataset` only supports `len` in eager mode. Use `tf.data.Dataset.cardinality()` instead.')
    length = self.cardinality()
    if length.numpy() == INFINITE:
        raise TypeError('The dataset is infinite.')
    if length.numpy() == UNKNOWN:
        raise TypeError('The dataset length is unknown.')
    return length

Returns the length of the dataset if it is known and finite.

This method requires that you are running in eager mode, and that the
length of the dataset is known and non-infinite. When the length may be
unknown or infinite, or if you are running in graph mode, use
`tf.data.Dataset.cardinality` instead.

Returns:
An integer representing the length of the dataset.

Raises:
RuntimeError: If the dataset length is unknown or infinite, or if eager
execution is not enabled.


def column(self, index_or_label):
    if (isinstance(index_or_label, str) and (index_or_label not in self.labels)):
        raise ValueError('The column "{}" is not in the table. The table contains these columns: {}'.format(index_or_label, ', '.join(self.labels)))
    if (isinstance(index_or_label, int) and (not (0 <= index_or_label < len(self.labels)))):
        raise ValueError('The index {} is not in the table. Only indices between 0 and {} are valid'.format(index_or_label, (len(self.labels) - 1)))
    return self._columns[self._as_label(index_or_label)]

Return the values of a column as an array.

table.column(label) is equivalent to table[label].

>>> tiles = Table().with_columns(
...     'letter', make_array('c', 'd'),
...     'count',  make_array(2, 4),
... )

>>> list(tiles.column('letter'))
['c', 'd']
>>> tiles.column(1)
array([2, 4])

Args:
label (int or str): The index or label of a column

Returns:
An instance of ``numpy.array``.

Raises:
``ValueError``: When the ``index_or_label`` is not in the table.


def sample(self, num_samples: int):
    return self._sample(num_samples)

Returns samples from the EBM corresponding to `self.energy`.

Args:
num_samples: Number of samples to draw from the EBM.


def minhash(self, v):

        if not isinstance(v, collections.Iterable):
            raise TypeError("Input vector must be an iterable")
        if not len(v) == self.dim:
            raise ValueError("Input dimension mismatch, expecting %d" % self.dim)
        if not isinstance(v, np.ndarray):
            v = np.array(v, dtype=np.float32)
        elif v.dtype != np.float32:
            v = v.astype(np.float32)
        hashvalues = np.zeros((self.sample_size, 2), dtype=np.int)
        vzeros = (v == 0)
        if vzeros.all():
            raise ValueError("Input is all zeros")
        v[vzeros] = np.nan
        vlog = np.log(v)
        for i in range(self.sample_size):
            t = np.floor((vlog / self.rs[i]) + self.betas[i])
            ln_y = (t - self.betas[i]) * self.rs[i]
            ln_a = self.ln_cs[i] - ln_y - self.rs[i]
            k = np.nanargmin(ln_a)
            hashvalues[i][0], hashvalues[i][1] = k, int(t[k])
        return WeightedMinHash(self.seed, hashvalues)

Create a new weighted MinHash given a weighted Jaccard vector.
Each dimension is an integer
frequency of the corresponding element in the multi-set represented
by the vector.

Args:
v (numpy.array): The Jaccard vector.


def load_pickle(file, encoding=None):
    if encoding:
        with open(file, 'rb') as f:
            return pickle.load(f, encoding=encoding)
    with open(file, 'rb') as f:
        return pickle.load(f)

Load a pickle file.

Args:
file (str): Path to pickle file

Returns:
object: Loaded object from pickle file


def _construct_adb_cmd(self, raw_name, args, shell):
    args = (args or '')
    name = raw_name.replace('_', '-')
    if shell:
        args = utils.cli_cmd_to_string(args)
        if self.serial:
            adb_cmd = ('"%s" -s "%s" %s %s' % (ADB, self.serial, name, args))
        else:
            adb_cmd = ('"%s" %s %s' % (ADB, name, args))
    else:
        adb_cmd = [ADB]
        if self.serial:
            adb_cmd.extend(['-s', self.serial])
        adb_cmd.append(name)
        if args:
            if isinstance(args, basestring):
                adb_cmd.append(args)
            else:
                adb_cmd.extend(args)
    return adb_cmd

Constructs an adb command with arguments for a subprocess call.

Args:
raw_name: string, the raw unsanitized name of the adb command to
format.
args: string or list of strings, arguments to the adb command.
See subprocess.Proc() documentation.
shell: bool, True to run this command through the system shell,
False to invoke it directly. See subprocess.Proc() docs.

Returns:
The adb command in a format appropriate for subprocess. If shell is
True, then this is a string; otherwise, this is a list of
strings.


def __init__(self, graduation_year):

        if graduation_year is None:
            self._number = 13
        else:
            self._number = settings.SENIOR_GRADUATION_YEAR - int(graduation_year) + 12

        if 9 <= self._number <= 12:
            self._name = Grade.names[self._number - 9]
        else:
            self._name = "graduate"

Initialize the Grade object.

Args:
graduation_year
The numerical graduation year of the user


def _expand_place_ids(self, terms):
    place_vids = []
    first_type = None
    for result in self.backend.identifier_index.search(terms):
        if (not first_type):
            first_type = result.type
        if (result.type != first_type):
            continue
        place_vids.append(result.vid)
    if place_vids:
        all_set = set(itertools.chain.from_iterable((iallval(GVid.parse(x)) for x in place_vids)))
        place_vids += list((str(x) for x in all_set))
        return place_vids
    else:
        return terms

Lookups all of the place identifiers to get gvids

Args:
terms (str or unicode): terms to lookup

Returns:
str or list: given terms if no identifiers found, otherwise list of identifiers.


def __init__(self, ports_to_serve):

        self._port_pool = _PortPool()
        self._total_allocations = 0
        self._denied_allocations = 0
        self._client_request_errors = 0
        for port in ports_to_serve:
            self._port_pool.add_port_to_free_pool(port)

Initialize a new port server.

Args:
ports_to_serve: A sequence of unique port numbers to test and offer
up to clients.


def all(self, data={}, **kwargs):
    return super(Settlement, self).all(data, **kwargs)

Fetch all Settlement entities

Returns:
Dictionary of Settlement data


def CaptureFrameLocals(self, frame):
    variables = {n: self.CaptureNamedVariable(n, v, 1, self.default_capture_limits) for (n, v) in six.viewitems(frame.f_locals)}
    nargs = frame.f_code.co_argcount
    if (frame.f_code.co_flags & inspect.CO_VARARGS):
        nargs += 1
    if (frame.f_code.co_flags & inspect.CO_VARKEYWORDS):
        nargs += 1
    frame_arguments = []
    for argname in frame.f_code.co_varnames[:nargs]:
        if (argname in variables):
            frame_arguments.append(variables.pop(argname))
    return (frame_arguments, list(six.viewvalues(variables)))

Captures local variables and arguments of the specified frame.

Args:
frame: frame to capture locals and arguments.

Returns:
(arguments, locals) tuple.


def safe_filename(filename, os_type='unix', no_control=True, ascii_only=True, case=None, encoding='utf8', max_length=None):
    assert isinstance(filename, str), 'Expect str. Got {}.'.format(type(filename))
    if (filename in ('.', os.curdir)):
        new_filename = '%2E'
    elif (filename in ('.', os.pardir)):
        new_filename = '%2E%2E'
    else:
        unix = (os_type == 'unix')
        windows = (os_type == 'windows')
        encoder_args = (unix, no_control, windows, ascii_only)
        if (encoder_args not in _encoder_cache):
            _encoder_cache[encoder_args] = PercentEncoder(unix=unix, control=no_control, windows=windows, ascii_=ascii_only)
        encoder = _encoder_cache[encoder_args]
        encoded_filename = filename.encode(encoding)
        new_filename = encoder.quote(encoded_filename).decode(encoding)
    if (os_type == 'windows'):
        if (new_filename[(- 1)] in ' .'):
            new_filename = '{0}{1:02X}'.format(new_filename[:(- 1)], new_filename[(- 1)])
    if (max_length and (len(new_filename) > max_length)):
        hash_obj = hashlib.sha1(new_filename.encode(encoding))
        new_length = max(0, (max_length - 8))
        new_filename = '{0}{1}'.format(new_filename[:new_length], hash_obj.hexdigest()[:8])
    if (case == 'lower'):
        new_filename = new_filename.lower()
    elif (case == 'upper'):
        new_filename = new_filename.upper()
    return new_filename

Return a safe filename or path part.

Args:
filename (str): The filename or path component.
os_type (str): If ``unix``, escape the slash. If ``windows``, escape
extra Windows characters.
no_control (bool): If True, escape control characters.
ascii_only (bool): If True, escape non-ASCII characters.
case (str): If ``lower``, lowercase the string. If ``upper``, uppercase
the string.
encoding (str): The character encoding.
max_length (int): The maximum length of the filename.

This function assumes that `filename` has not already been percent-encoded.

Returns:
str


def write(self, destination, filename, content):

        if not os.path.exists(destination):
            try:
                os.makedirs(destination)
            except:
                pass

        filepath = "%s/%s" % (destination, filename)

        f = open(filepath, "w+")
        f.write(content)
        f.close()

Write a file at the specific destination with the content.

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


def __diff_internal(self):
    assert (self.p > 0), 'order of Bspline must be > 0'
    t = self.knot_vector
    p = self.p
    Bi = Bspline(t[:(- 1)], (p - 1))
    Bip1 = Bspline(t[1:], (p - 1))
    numer1 = (+ p)
    numer2 = (- p)
    denom1 = (t[p:(- 1)] - t[:(- (p + 1))])
    denom2 = (t[(p + 1):] - t[1:(- p)])
    with np.errstate(divide='ignore', invalid='ignore'):
        ci = np.where((denom1 != 0.0), (numer1 / denom1), 0.0)
        cip1 = np.where((denom2 != 0.0), (numer2 / denom2), 0.0)
    return ((ci, Bi), (cip1, Bip1))

Differentiate a B-spline once, and return the resulting coefficients and Bspline objects.

This preserves the Bspline object nature of the data, enabling recursive implementation
of higher-order differentiation (see `diff`).

The value of the first derivative of `B` at a point `x` can be obtained as::

def diff1(B, x):
terms = B.__diff_internal()
return sum( ci*Bi(x) for ci,Bi in terms )

Returns:
tuple of tuples, where each item is (coefficient, Bspline object).

See:
`diff`: differentiation of any order >= 0


def get_values(self, k, v):

    metadata = self.metadata
    values = []
    if metadata != None:
      if k in metadata:
        for metav in metadata[k]:
          if v in metav:
            values.append(metav[v])
    return values

Get a list of values from the key value metadata attribute.

Args:
k (str):
Key in :class:`api.results`.metadata
v (str):
Values from each item in the key of :class:`api.results`.metadata

Returns:
A list containing all the ``v`` values in the ``k`` key for the  :class:`api.results`.metadata attribute.


def unwrap_arguments(xml_response):
    xml_response = xml_response.encode('utf-8')
    try:
        tree = XML.fromstring(xml_response)
    except XML.ParseError:
        filtered = illegal_xml_re.sub('', xml_response.decode('utf-8')).encode('utf-8')
        tree = XML.fromstring(filtered)
    action_response = tree.find('{http:
    return dict(((i.tag, (i.text or '')) for i in action_response))

Extract arguments and their values from a SOAP response.

Args:
xml_response (str):  SOAP/xml response text (unicode,
not utf-8).
Returns:
dict: a dict of ``{argument_name: value}`` items.


def StartService(service_name):

  try:
    win32serviceutil.StartService(service_name)
    logging.info("Service '%s' started.", service_name)
  except pywintypes.error as e:
    if getattr(e, "winerror", None) == winerror.ERROR_SERVICE_DOES_NOT_EXIST:
      logging.debug("Tried to start '%s', but the service is not installed.",
                    service_name)
    else:
      logging.exception("Encountered error trying to start '%s':", service_name)

Start a Windows service with the given name.

Args:
service_name: string The name of the service to be started.


def local_variables(scope=None):
    return ops.get_collection(ops.GraphKeys.LOCAL_VARIABLES, scope)

Returns local variables.

Local variables - per process variables, usually not saved/restored to
checkpoint and used for temporary or intermediate values.
For example, they can be used as counters for metrics computation or
number of epochs this machine has read data.
The `tf.contrib.framework.local_variable()` function automatically adds the
new variable to `GraphKeys.LOCAL_VARIABLES`.
This convenience function returns the contents of that collection.

An alternative to local variables are global variables. See
`tf.compat.v1.global_variables`

Args:
scope: (Optional.) A string. If supplied, the resulting list is filtered to
include only items whose `name` attribute matches `scope` using
`re.match`. Items without a `name` attribute are never returned if a scope
is supplied. The choice of `re.match` means that a `scope` without special
tokens filters by prefix.

Returns:
A list of local `Variable` objects.


def get_dialect_name(mixed: Union[(SQLCompiler, Engine, Dialect)]) -> str:
    dialect = get_dialect(mixed)
    return dialect.name

Finds the name of the SQLAlchemy dialect in use.

Args:
mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or
:class:`Dialect` object

Returns: the SQLAlchemy dialect name being used


def are_debian_packages_installed(packages: List[str]) -> Dict[str, bool]:

    assert len(packages) >= 1
    require_executable(DPKG_QUERY)
    args = [
        DPKG_QUERY,
        "-W",

        "-f=${Package} ${Status}\n",
    ] + packages
    completed_process = subprocess.run(args,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       check=False)
    encoding = sys.getdefaultencoding()
    stdout = completed_process.stdout.decode(encoding)
    stderr = completed_process.stderr.decode(encoding)
    present = OrderedDict()
    for line in stdout.split("\n"):
        if line:
            words = line.split()
            assert len(words) >= 2
            package = words[0]
            present[package] = "installed" in words[1:]
    for line in stderr.split("\n"):
        if line:
            words = line.split()
            assert len(words) >= 2
            package = words[-1]
            present[package] = False
    log.debug("Debian package presence: {}", present)
    return present

Check which of a list of Debian packages are installed, via ``dpkg-query``.

Args:
packages: list of Debian package names

Returns:
dict: mapping from package name to boolean ("present?")


def load_raw_type(self, typ: type[Any]) -> abstract.BaseValue:
    if typ is type(None):
        return self.consts[None]
    pytd_node = self._pytd_loader.lookup_pytd(typ.__module__, typ.__name__)
    return self._load_pytd_node(pytd_node)

Converts a raw type to an abstract value.

For convenience, this method can also be called via ctx.types[typ].

Args:
typ: The type.

Returns:
The abstract representation of the type. For example, when passed `int`,
this function returns `abstract.SimpleClass(int)`.


def build_schedule(inputs: Optional[Set[EventSetNode]], outputs: Set[EventSetNode], verbose: int=0) -> Schedule:
    graph = infer_graph(inputs, outputs)
    schedule = Schedule(input_nodes=graph.inputs)
    if verbose >= 2:
        print('Graph:\n', graph, file=sys.stderr)
    ready_ops: List[Operator] = []
    ready_ops_set: Set[Operator] = set()
    node_to_op: Dict[EventSetNode, List[Operator]] = defaultdict(lambda: [])
    op_to_num_pending_inputs: Dict[Operator, int] = defaultdict(lambda: 0)
    for op in graph.operators:
        num_pending_inputs = 0
        for input_node in op.inputs.values():
            node_to_op[input_node].append(op)
            if input_node in graph.inputs:
                continue
            num_pending_inputs += 1
        if num_pending_inputs == 0:
            ready_ops.append(op)
            ready_ops_set.add(op)
        else:
            op_to_num_pending_inputs[op] = num_pending_inputs
    ready_ops.sort(key=lambda op: op._internal_ordered_id, reverse=True)
    while ready_ops:
        op = ready_ops.pop()
        ready_ops_set.remove(op)
        released_nodes = []
        for input in op.inputs.values():
            if input in outputs:
                continue
            if input not in node_to_op:
                continue
            input_usage = node_to_op[input]
            input_usage.remove(op)
            if not input_usage:
                released_nodes.append(input)
                del node_to_op[input]
        schedule.steps.append(ScheduleStep(op=op, released_nodes=released_nodes))
        for output in op.outputs.values():
            if output not in node_to_op:
                continue
            for new_op in node_to_op[output]:
                assert new_op in op_to_num_pending_inputs
                num_missing_inputs = op_to_num_pending_inputs[new_op] - 1
                op_to_num_pending_inputs[new_op] = num_missing_inputs
                assert num_missing_inputs >= 0
                if num_missing_inputs == 0:
                    ready_ops.append(new_op)
                    ready_ops_set.add(new_op)
                    del op_to_num_pending_inputs[new_op]
    assert not op_to_num_pending_inputs
    return schedule

Calculates which operators need to be executed in which order to compute
a set of output EventSetNodes given a set of input EventSetNodes.

This implementation is based on Kahn's algorithm.

Args:
inputs: Input EventSetNodes.
outputs: Output EventSetNodes.
verbose: If >0, prints details about the execution on the standard error
output. The larger the number, the more information is displayed.

Returns:
Tuple of:
- Ordered list of operators, such that the first operator should be
computed before the second, second before the third, etc.
- Mapping of EventSetNode name inputs to EventSetNodes. The keys are the string
values in the `inputs` argument, and the values are the EventSetNodes
corresponding to each one. If a value was already an EventSetNode, it won't
be present in the returned dictionary.


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

    query_hash = hash(query)

    event_data = WindowsTimelineGenericEventData()

    payload_json_bytes = bytes(self._GetRowValue(query_hash, row, 'Payload'))
    payload_json_string = payload_json_bytes.decode('utf-8')

    appid_entries_string = self._GetRowValue(query_hash, row, 'AppId')

    payload = json.loads(payload_json_string)
    appid_entries = json.loads(appid_entries_string)

    package_id_locations = [
        'packageId', 'x_exe_path', 'windows_win32', 'windows_universal',
        'alternateId']
    for location in package_id_locations:
      for entry in appid_entries:
        if entry['platform'] == location and entry['application'] != '':
          event_data.package_identifier = entry['application']
          break
      if event_data.package_identifier is None:

        break

    if 'description' in payload:
      event_data.description = payload['description']
    else:
      event_data.description = ''

    if 'appDisplayName' in payload and payload['appDisplayName'] != '':
      event_data.application_display_name = payload['appDisplayName']
    elif 'displayText' in payload and payload['displayText'] != '':

      event_data.application_display_name = payload['displayText']

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

Parses a generic windows timeline row.

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


def description(self, description):

        self._data['description'] = description
        request = self._base_request
        request['description'] = description
        return self._tc_requests.update(request, owner=self.owner)

Updates the security labels description.

Args:
description:


def create_single_token(self, *, payer_id, name, identification_number, payment_method, number, expiration_date):

        payload = {
            "language": self.client.language.value,
            "command": PaymentCommand.CREATE_TOKEN.value,
            "merchant": {
                "apiLogin": self.client.api_login,
                "apiKey": self.client.api_key
            },
            "creditCardToken": {
                "payerId": payer_id,
                "name": name,
                "identificationNumber": identification_number,
                "paymentMethod": payment_method,
                "number": number,
                "expirationDate": expiration_date
            },
            "test": self.client.is_test
        }
        return self.client._post(self.url, json=payload)

Using this feature you can register a customer’s credit card data and get a token sequential number.

Args:
payer_id:
name:
identification_number:
payment_method:
number:
expiration_date:

Returns:


def avg(vals, count=None):
    sum = 0
    for v in vals:
        sum += v
    if (count is None):
        count = len(vals)
    return (float(sum) / count)

Returns the average value

Args:
vals: List of numbers to calculate average from.
count: Int of total count that vals was part of.

Returns:
Float average value throughout a count.


def CopyToProto(self, proto):

    if (self.file is not None and
        self._serialized_start is not None and
        self._serialized_end is not None):
      proto.ParseFromString(self.file.serialized_pb[
          self._serialized_start:self._serialized_end])
    else:
      raise Error('Descriptor does not contain serialization.')

Copies this to the matching proto in descriptor_pb2.

Args:
proto: An empty proto instance from descriptor_pb2.

Raises:
Error: If self couldnt be serialized, due to to few constructor arguments.


def DeserializeForImport(self, reader):

        super(Block, self).Deserialize(reader)

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

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

        if len(self.Transactions) < 1:
            raise Exception('Invalid format %s ' % self.Index)

Deserialize full object.

Args:
reader (neo.IO.BinaryReader):


def _handle_problem_status(self, message, future):

        try:
            _LOGGER.trace("Handling response: %r", message)
            _LOGGER.debug("Handling response for %s with status %s", message.get('id'), message.get('status'))

            if 'error_code' in message and 'error_msg' in message:
                raise SolverFailureError(message['error_msg'])

            if 'status' not in message:
                raise InvalidAPIResponseError("'status' missing in problem description response")
            if 'id' not in message:
                raise InvalidAPIResponseError("'id' missing in problem description response")

            future.id = message['id']
            future.remote_status = status = message['status']

            with future._single_cancel_lock:

                if future._cancel_requested:
                    if not future._cancel_sent and status == self.STATUS_PENDING:

                        self._cancel(message['id'], future)

                    future._cancel_sent = True

            if not future.time_received and message.get('submitted_on'):
                future.time_received = parse_datetime(message['submitted_on'])

            if not future.time_solved and message.get('solved_on'):
                future.time_solved = parse_datetime(message['solved_on'])

            if not future.eta_min and message.get('earliest_estimated_completion'):
                future.eta_min = parse_datetime(message['earliest_estimated_completion'])

            if not future.eta_max and message.get('latest_estimated_completion'):
                future.eta_max = parse_datetime(message['latest_estimated_completion'])

            if status == self.STATUS_COMPLETE:

                if 'answer' in message:
                    future._set_message(message)

                else:
                    self._load(future)
            elif status in self.ANY_STATUS_ONGOING:

                self._poll(future)
            elif status == self.STATUS_CANCELLED:

                raise CanceledFutureError()
            else:

                errmsg = message.get('error_message', 'An unknown error has occurred.')
                if 'solver is offline' in errmsg.lower():
                    raise SolverOfflineError(errmsg)
                else:
                    raise SolverFailureError(errmsg)

        except Exception as error:

            future._set_error(error, sys.exc_info())

Handle the results of a problem submission or results request.

This method checks the status of the problem and puts it in the correct queue.

Args:
message (dict): Update message from the SAPI server wrt. this problem.
future `Future`: future corresponding to the problem

Note:
This method is always run inside of a daemon thread.


def _read_range(self, start, end=0):

        try:
            with _handle_client_error():
                response = self._client.get_object(
                    Range=self._http_range(start, end), **self._client_kwargs)

        except _ClientError as exception:
            if exception.response['Error']['Code'] == 'InvalidRange':

                return bytes()
            raise

        return response['Body'].read()

Read a range of bytes in stream.

Args:
start (int): Start stream position.
end (int): End stream position.
0 To not specify end.

Returns:
bytes: number of bytes read


def merge(self, other):
    if (not isinstance(other, Ontology)):
        raise TypeError("'merge' requires an Ontology as argument, not {}".format(type(other)))
    self.terms.update(other.terms)
    self._empty_cache()
    self.adopt()
    self.reference()

Merge another ontology into the current one.

Raises:
TypeError: When argument is not an Ontology object.

Example:
>>> from pronto import Ontology
>>> nmr = Ontology('tests/resources/nmrCV.owl', False)
>>> po = Ontology('tests/resources/po.obo.gz', False)
>>> 'NMR:1000271' in nmr
True
>>> 'NMR:1000271' in po
False
>>> po.merge(nmr)
>>> 'NMR:1000271' in po
True


def decode(self, decoder_input_ids, encoder_outputs, encoder_attention_mask: Optional[jnp.ndarray]=None, decoder_attention_mask: Optional[jnp.ndarray]=None, decoder_position_ids: Optional[jnp.ndarray]=None, past_key_values: Optional[dict]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, train: bool=False, params: Optional[dict]=None, dropout_rng: PRNGKey=None):
    output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
    output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    return_dict = return_dict if return_dict is not None else self.config.return_dict
    encoder_hidden_states = encoder_outputs[0]
    if encoder_attention_mask is None:
        batch_size, sequence_length = encoder_hidden_states.shape[:2]
        encoder_attention_mask = jnp.ones((batch_size, sequence_length))
    batch_size, sequence_length = decoder_input_ids.shape
    if decoder_attention_mask is None:
        decoder_attention_mask = jnp.ones((batch_size, sequence_length))
    if decoder_position_ids is None:
        if past_key_values is not None:
            raise ValueError('Make sure to provide `decoder_position_ids` when passing `past_key_values`.')
        decoder_position_ids = jnp.broadcast_to(jnp.arange(sequence_length)[None, :], (batch_size, sequence_length))
    rngs = {}
    if dropout_rng is not None:
        rngs['dropout'] = dropout_rng
    inputs = {'params': params or self.params}
    if past_key_values:
        inputs['cache'] = past_key_values
        mutable = ['cache']
    else:
        mutable = False

    def _decoder_forward(module, decoder_input_ids, decoder_attention_mask, decoder_position_ids, **kwargs):
        decoder_module = module._get_decoder_module()
        return decoder_module(decoder_input_ids, decoder_attention_mask, decoder_position_ids, **kwargs)
    outputs = self.module.apply(inputs, decoder_input_ids=jnp.array(decoder_input_ids, dtype='i4'), decoder_attention_mask=jnp.array(decoder_attention_mask, dtype='i4'), decoder_position_ids=jnp.array(decoder_position_ids, dtype='i4'), encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=jnp.array(encoder_attention_mask, dtype='i4'), output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, deterministic=not train, rngs=rngs, mutable=mutable, method=_decoder_forward)
    if past_key_values is not None and return_dict:
        outputs, past = outputs
        outputs['past_key_values'] = unfreeze(past['cache'])
        return outputs
    elif past_key_values is not None and (not return_dict):
        outputs, past = outputs
        outputs = outputs[:1] + (unfreeze(past['cache']),) + outputs[1:]
    return outputs

Returns:

Example:

```python
>>> import jax.numpy as jnp
>>> from transformers import AutoTokenizer, FlaxBlenderbotSmallForConditionalGeneration

>>> model = FlaxBlenderbotSmallForConditionalGeneration.from_pretrained("facebook/blenderbot_small-90M")
>>> tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot_small-90M")

>>> text = "My friends are cool but they eat too many carbs."
>>> inputs = tokenizer(text, max_length=1024, return_tensors="np")
>>> encoder_outputs = model.encode(**inputs)

>>> decoder_start_token_id = model.config.decoder_start_token_id
>>> decoder_input_ids = jnp.ones((inputs.input_ids.shape[0], 1), dtype="i4") * decoder_start_token_id

>>> outputs = model.decode(decoder_input_ids, encoder_outputs)
>>> last_decoder_hidden_states = outputs.last_hidden_state
```


def _QueryHashes(self, digests):

    url_parameters = {'apikey': self._api_key, 'resource': ', '.join(digests)}

    try:
      json_response = self.MakeRequestAndDecodeJSON(
          self._VIRUSTOTAL_API_REPORT_URL, 'GET', params=url_parameters)
    except errors.ConnectionError as exception:
      json_response = None
      logger.error('Unable to query VirusTotal with error: {0!s}.'.format(
          exception))

    return json_response

Queries VirusTotal for a specfic hashes.

Args:
digests (list[str]): hashes to look up.

Returns:
dict[str, object]: JSON response or None on error.


def run(argv=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('--input', dest='input', default='gs:
    parser.add_argument('--output', dest='output', help='Output file to write results to.', required=True)
    known_args, pipeline_args = parser.parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    pipeline_options.view_as(SetupOptions).save_main_session = True
    with beam.Pipeline(options=pipeline_options) as p:
        p | ReadFromAvro(known_args.input) | beam.Filter(lambda record: all((record[k] is not None for k in ('hvfhs_license_num', 'trip_miles', 'trip_time', 'base_passenger_fare', 'tips', 'driver_pay'))) and any((record[k] is not None for k in ('request_datetime', 'on_scene_datetime', 'pickup_datetime', 'dropoff_datetime')))) | beam.ParDo(CreateKeyWithServiceAndDay()) | beam.CombinePerKey(CalculatePricePerAttribute()) | beam.Map(flatten_group) | WriteToAvro(known_args.output, SCHEMA, file_name_suffix='.avro')

Runs the New York City trips pipeline.

Args:
argv: Pipeline options as a list of arguments.


def as_dataframe(self, pattern='*', max_rows=None):

    data = []
    for i, resource in enumerate(self.list(pattern)):
      if max_rows is not None and i >= max_rows:
        break
      labels = ', '. join([l.key for l in resource.labels])
      data.append([resource.type, resource.display_name, labels])

    return pandas.DataFrame(data, columns=self._DISPLAY_HEADERS)

Creates a pandas dataframe from the descriptors that match the filters.

Args:
pattern: An optional pattern to further filter the descriptors. This can
include Unix shell-style wildcards. E.g. ``"aws*"``, ``"*cluster*"``.
max_rows: The maximum number of descriptors to return. If None, return
all.

Returns:
A pandas dataframe containing matching resource descriptors.


def setup(self, disk_name, project, turbinia_zone):

    if project is None or turbinia_zone is None:
      self.state.add_error(
          'project or turbinia_zone are not all specified, bailing out',
          critical=True)
      return

    self.disk_name = disk_name
    self.project = project
    self.turbinia_zone = turbinia_zone

    try:
      turbinia_config.LoadConfig()
      self.turbinia_region = turbinia_config.TURBINIA_REGION
      self.instance = turbinia_config.PUBSUB_TOPIC
      if turbinia_config.PROJECT != self.project:
        self.state.add_error(
            'Specified project {0:s} does not match Turbinia configured '
            'project {1:s}. Use gcp_turbinia_import recipe to copy the disk '
            'into the same project.'.format(
                self.project, turbinia_config.PROJECT), critical=True)
        return
      self._output_path = tempfile.mkdtemp()
      self.client = turbinia_client.TurbiniaClient()
    except TurbiniaException as e:
      self.state.add_error(e, critical=True)
      return

Sets up the object attributes.

Args:
disk_name (string): Name of the disk to process
project (string): The project containing the disk to process
turbinia_zone (string): The zone containing the disk to process


def persist_project(project):
    from benchbuild.utils.schema import Project, Session
    session = Session()
    projects = session.query(Project).filter((Project.name == project.name)).filter((Project.group_name == project.group))
    name = project.name
    desc = project.__doc__
    domain = project.domain
    group_name = project.group
    version = (project.version() if callable(project.version) else project.version)
    try:
        src_url = project.src_uri
    except AttributeError:
        src_url = 'unknown'
    if (projects.count() == 0):
        newp = Project()
        newp.name = name
        newp.description = desc
        newp.src_url = src_url
        newp.domain = domain
        newp.group_name = group_name
        newp.version = version
        session.add(newp)
    else:
        newp_value = {'name': name, 'description': desc, 'src_url': src_url, 'domain': domain, 'group_name': group_name, 'version': version}
        projects.update(newp_value)
    session.commit()
    return (projects, session)

Persist this project in the benchbuild database.

Args:
project: The project we want to persist.


def drawdown_details(drawdown, index_type=pd.DatetimeIndex):

    is_zero = drawdown == 0

    start = ~is_zero & is_zero.shift(1)
    start = list(start[start == True].index)

    end = is_zero & (~is_zero).shift(1)
    end = list(end[end == True].index)

    if len(start) is 0:
        return None

    if len(end) is 0:
        end.append(drawdown.index[-1])

    if start[0] > end[0]:
        start.insert(0, drawdown.index[0])

    if start[-1] > end[-1]:
        end.append(drawdown.index[-1])

    result = pd.DataFrame(
        columns=('Start', 'End', 'Length', 'drawdown'),
        index=range(0, len(start))
    )

    for i in range(0, len(start)):
        dd = drawdown[start[i]:end[i]].min()

        if index_type is pd.DatetimeIndex:
            result.iloc[i] = (start[i], end[i], (end[i] - start[i]).days, dd)
        else:
            result.iloc[i] = (start[i], end[i], (end[i] - start[i]), dd)

    return result

Returns a data frame with start, end, days (duration) and
drawdown for each drawdown in a drawdown series.

.. note::

days are actual calendar days, not trading days

Args:
* drawdown (pandas.Series): A drawdown Series
(can be obtained w/ drawdown(prices).
Returns:
* pandas.DataFrame -- A data frame with the following
columns: start, end, days, drawdown.


def modify_lattice(self, new_lattice):

        self._lattice = new_lattice
        for site in self._sites:
            site.lattice = new_lattice

Modify the lattice of the structure.  Mainly used for changing the
basis.

Args:
new_lattice (Lattice): New lattice


def get_image_features(self, pixel_values: torch.FloatTensor, return_attentions: Optional[bool]=False, interpolate_pos_encoding: Optional[bool]=False):
    vision_model_output = self.vision_model(pixel_values=pixel_values, interpolate_pos_encoding=interpolate_pos_encoding)
    image_embeds = self.vision_model.model.post_layernorm(vision_model_output[0])
    image_embeds = nn.functional.normalize(image_embeds, dim=-1)
    image_embeds, projection_attentions = self.image_to_text_projection(image_embeds)
    if return_attentions:
        return (image_embeds, projection_attentions)
    return image_embeds

Encodes images into continuous embeddings that can be forwarded to the language model.

Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
The tensors corresponding to the input images.
return_attentions (`bool`, *optional*, defaults to `False`):
Whether to return `projection_attentions` or not.
interpolate_pos_encoding (`bool`, *optional*, defaults to `False`):
Whether to interpolate positional embeddings or not.


def compile_initial_state(self, batch_size: Optional[int] = None) -> Sequence[tf.Tensor]:

        with self.graph.as_default():
            with tf.name_scope('initial_state'):
                self._initialize_initial_state_fluents()
                if batch_size is None:
                    return self.initial_state_fluents
                return self._compile_batch_fluents(self.initial_state_fluents, batch_size)

Returns a tuple of tensors representing the initial state fluents.

Args:
batch_size (Optional[int]): The batch size.

Returns:
Sequence[tf.Tensor]: A tuple of tensors.


def extractUnits(self, inp):
    inp = self._preprocess(inp)
    units = []
    description = ''
    for w in inp.split(' '):
        if (self.isValidUnit(w) or (w == '/')):
            if description:
                description += ' '
            description += w
        else:
            if description:
                units.append(description)
            description = ''
    if description:
        units.append(description)
    return units

Collects all the valid units from an inp string. Works by
appending consecutive words from the string and cross-referncing
them with a set of valid units.

Args:
inp (str): Some text which hopefully contains descriptions
of different units.

Returns:
A list of strings, each entry in which is a valid quantities
unit.


def _ApproxTopKGradient(op: ops.Operation, grad, _):
    idx_shape = op.outputs[1].shape
    lifted_idx_shape = idx_shape + [1]
    flat_shape_len = functools.reduce(operator.mul, idx_shape)
    rank = idx_shape.rank
    reduction_dim = op.get_attr('reduction_dimension')
    if reduction_dim < 0:
        reduction_dim = rank + reduction_dim

    def GetLiftedIdx(d):
        if d == reduction_dim:
            return array_ops.reshape(op.outputs[1], lifted_idx_shape)
        iota_len = idx_shape[d]
        iota_shape = list(itertools.repeat(1, rank + 1))
        iota_shape[d] = iota_len
        iota = array_ops.reshape(math_ops.range(iota_len), iota_shape)
        return array_ops.broadcast_to(iota, lifted_idx_shape)
    lifted_idx = array_ops.concat(list((GetLiftedIdx(d) for d in range(rank))), axis=rank)
    flat_idx = array_ops.reshape(lifted_idx, [flat_shape_len, rank])
    flat_grad = array_ops.reshape(grad, [flat_shape_len])
    return array_ops.scatter_nd(flat_idx, flat_grad, op.inputs[0].shape)

Return the gradients for ApproxTopK.

Args:
op: The ApproxTopK for which we need to generate gradients.
grad: The gradients for backprop.

Returns:
Scattered gradient based on the top-k indices.


def CreateSignatureScanner(cls, specification_store):
    scanner_object = pysigscan.scanner()
    for format_specification in specification_store.specifications:
        for signature in format_specification.signatures:
            pattern_offset = signature.offset
            if (pattern_offset is None):
                signature_flags = pysigscan.signature_flags.NO_OFFSET
            elif (pattern_offset < 0):
                pattern_offset *= (- 1)
                signature_flags = pysigscan.signature_flags.RELATIVE_FROM_END
            else:
                signature_flags = pysigscan.signature_flags.RELATIVE_FROM_START
            scanner_object.add_signature(signature.identifier, pattern_offset, signature.pattern, signature_flags)
    return scanner_object

Creates a signature scanner for format specifications with signatures.

Args:
specification_store (FormatSpecificationStore): format specifications
with signatures.

Returns:
pysigscan.scanner: signature scanner.


def __init__(self, channel):

    self.Alarm = channel.unary_unary(
        '/etcdserverpb.Maintenance/Alarm',
        request_serializer=rpc__pb2.AlarmRequest.SerializeToString,
        response_deserializer=rpc__pb2.AlarmResponse.FromString,
        )
    self.Status = channel.unary_unary(
        '/etcdserverpb.Maintenance/Status',
        request_serializer=rpc__pb2.StatusRequest.SerializeToString,
        response_deserializer=rpc__pb2.StatusResponse.FromString,
        )
    self.Defragment = channel.unary_unary(
        '/etcdserverpb.Maintenance/Defragment',
        request_serializer=rpc__pb2.DefragmentRequest.SerializeToString,
        response_deserializer=rpc__pb2.DefragmentResponse.FromString,
        )
    self.Hash = channel.unary_unary(
        '/etcdserverpb.Maintenance/Hash',
        request_serializer=rpc__pb2.HashRequest.SerializeToString,
        response_deserializer=rpc__pb2.HashResponse.FromString,
        )
    self.HashKV = channel.unary_unary(
        '/etcdserverpb.Maintenance/HashKV',
        request_serializer=rpc__pb2.HashKVRequest.SerializeToString,
        response_deserializer=rpc__pb2.HashKVResponse.FromString,
        )
    self.Snapshot = channel.unary_stream(
        '/etcdserverpb.Maintenance/Snapshot',
        request_serializer=rpc__pb2.SnapshotRequest.SerializeToString,
        response_deserializer=rpc__pb2.SnapshotResponse.FromString,
        )
    self.MoveLeader = channel.unary_unary(
        '/etcdserverpb.Maintenance/MoveLeader',
        request_serializer=rpc__pb2.MoveLeaderRequest.SerializeToString,
        response_deserializer=rpc__pb2.MoveLeaderResponse.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def __init__(self, fname):

        self.file = fname
        self.folder = os.path.dirname(fname)
        self.tree = ET.parse(fname)
        self.root = self.tree.getroot()
        self.name = self.root.get("model")
        self.worldbody = self.create_default_element("worldbody")
        self.actuator = self.create_default_element("actuator")
        self.asset = self.create_default_element("asset")
        self.equality = self.create_default_element("equality")
        self.contact = self.create_default_element("contact")
        self.default = self.create_default_element("default")
        self.resolve_asset_dependency()

Loads a mujoco xml from file.

Args:
fname (str): path to the MJCF xml file.


def dump(self, file, payload):
    json.dump(payload, file, indent=2, ensure_ascii=False)

Dump json oject to open file output.

Writes json with 2 spaces indentation.

Args:
file: Open file-like object. Must be open for writing.
payload: The Json object to write to file.

Returns:
None.


def create_folder(self, name, parent_folder_id=0):
    return self.__request('POST', 'folders', data={'name': name, 'parent': {'id': unicode(parent_folder_id)}})

Create a folder

If the folder exists, a BoxError will be raised.

Args:
folder_id (int): Name of the folder.

parent_folder_id (int): ID of the folder where to create the new one.

Returns:
dict. Response from Box.

Raises:
BoxError: An error response is returned from Box (status_code >= 400).

BoxHttpResponseError: Response from Box is malformed.

requests.exceptions.*: Any connection related problem.


def draw_line(self, x1, y1, x2, y2):
    check_int_err(lib.SDL_RenderDrawLine(self._ptr, x1, y1, x2, y2))

Draw a line on the current rendering target.

Args:
x1 (int): The x coordinate of the start point.
y1 (int): The y coordinate of the start point.
x2 (int): The x coordinate of the end point.
y2 (int): The y coordinate of the end point.

Raises:
SDLError: If an error is encountered.


def from_rtm(cls, raw_event: MutableMapping) -> 'Event':
    if raw_event['type'].startswith('message'):
        return Message(raw_event)
    else:
        return Event(raw_event)

Create an event with data coming from the RTM API.

If the event type is a message a :class:`slack.events.Message` is returned.

Args:
raw_event: JSON decoded data from the RTM API

Returns:
:class:`slack.events.Event` or :class:`slack.events.Message`


def describe_images(self, idaho_image_results):

        results = idaho_image_results['results']

        results = [r for r in results if 'IDAHOImage' in r['type']]
        self.logger.debug('Describing %s IDAHO images.' % len(results))

        catids = set([r['properties']['catalogID'] for r in results])

        description = {}

        for catid in catids:

            description[catid] = {}
            description[catid]['parts'] = {}
            images = [r for r in results if r['properties']['catalogID'] == catid]
            for image in images:
                description[catid]['sensorPlatformName'] = image['properties']['sensorPlatformName']
                part = int(image['properties']['vendorDatasetIdentifier'].split(':')[1][-3:])
                color = image['properties']['colorInterpretation']
                bucket = image['properties']['tileBucketName']
                identifier = image['identifier']
                boundstr = image['properties']['footprintWkt']

                try:
                    description[catid]['parts'][part]
                except:
                    description[catid]['parts'][part] = {}

                description[catid]['parts'][part][color] = {}
                description[catid]['parts'][part][color]['id'] = identifier
                description[catid]['parts'][part][color]['bucket'] = bucket
                description[catid]['parts'][part][color]['boundstr'] = boundstr

        return description

Describe the result set of a catalog search for IDAHO images.

Args:
idaho_image_results (dict): Result set of catalog search.
Returns:
results (json): The full catalog-search response for IDAHO images
corresponding to the given catID.


def inspect(logdir='', event_file='', tag=''):

  print(PRINT_SEPARATOR +
        'Processing event files... (this can take a few minutes)\n' +
        PRINT_SEPARATOR)
  inspection_units = get_inspection_units(logdir, event_file, tag)

  for unit in inspection_units:
    if tag:
      print('Event statistics for tag {} in {}:'.format(tag, unit.name))
    else:

      print('These tags are in {}:'.format(unit.name))
      print_dict(get_unique_tags(unit.field_to_obs))
      print(PRINT_SEPARATOR)
      print('Event statistics for {}:'.format(unit.name))

    print_dict(get_dict_to_print(unit.field_to_obs), show_missing=(not tag))
    print(PRINT_SEPARATOR)

Main function for inspector that prints out a digest of event files.

Args:
logdir: A log directory that contains event files.
event_file: Or, a particular event file path.
tag: An optional tag name to query for.

Raises:
ValueError: If neither logdir and event_file are given, or both are given.


def get_output_shape_at(self, node_index):
    return self._get_node_attribute_at_index(node_index, 'output_shapes', 'output shape')

Retrieves the output shape(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 time the layer was called.

Returns:
A shape tuple
(or list of shape tuples if the layer has multiple outputs).

Raises:
RuntimeError: If called in Eager mode.


def node_defs(self):
    return self._node_defs

All the node defs in the graph to be converted.

Returns:
A map from node name to the NodeDef for all NodeDefs in the graph, as well
as all control flow NodeDefs in the functions.


def _get_local_folder(self, root=None):
    if (root is None):
        root = Path()
    for folders in (['.'], [self.user, self.napp]):
        kytos_json = ((root / Path(*folders)) / 'kytos.json')
        if kytos_json.exists():
            with kytos_json.open() as file_descriptor:
                meta = json.load(file_descriptor)
                username = meta.get('username', meta.get('author'))
                if ((username == self.user) and (meta.get('name') == self.napp)):
                    return kytos_json.parent
    raise FileNotFoundError('kytos.json not found.')

Return local NApp root folder.

Search for kytos.json in _./_ folder and _./user/napp_.

Args:
root (pathlib.Path): Where to begin searching.

Return:
pathlib.Path: NApp root folder.

Raises:
FileNotFoundError: If there is no such local NApp.


def assert_present(self, selector, testid=None, **kwargs):
    self.info_log(('Assert present selector(%s) testid(%s)' % (selector, testid)))
    wait_until_present = kwargs.get('wait_until_present', BROME_CONFIG['proxy_driver']['wait_until_present_before_assert_present'])
    self.debug_log(('effective wait_until_present: %s' % wait_until_present))
    if wait_until_present:
        element = self.wait_until_present(selector, raise_exception=False)
    else:
        element = self.is_present(selector)
    if element:
        if (testid is not None):
            self.create_test_result(testid, True)
        return True
    else:
        if (testid is not None):
            self.create_test_result(testid, False)
        return False

Assert that the element is present in the dom

Args:
selector (str): the selector used to find the element
test_id (str): the test_id or a str

Kwargs:
wait_until_present (bool)

Returns:
bool: True is the assertion succeed; False otherwise.


def open(self, mode='r', encoding=None):

        access_type = self._get_access_type(mode)

        if encoding is None:
            encoding = self.encoding

        if access_type == 'b':
            if not self._isbytes:
                content = self._contents.encode(encoding)
            else:
                content = self._contents
            return io.BytesIO(content)
        else:
            assert access_type == 't'
            if PYVERSION == 2 and self._isbytes:
                return io.BytesIO(self._contents)
            elif self._isbytes:
                content = self._contents.decode(encoding)
            else:
                content = self._contents
            return io.StringIO(content)

Return file-like object

Args:
mode (str): access mode (only reading modes are supported)
encoding (str): encoding type (only for binary access)

Returns:
io.BytesIO OR io.TextIOWrapper: buffer accessing the file as bytes or characters


def get_permissions(self, grp_name, resource):

        self.project_service.set_auth(self._token_project)
        return self.project_service.get_permissions(grp_name, resource)

Get permissions associated the group has with the given resource.

Args:
grp_name (string): Name of group.
resource (intern.resource.boss.Resource): Identifies which data
model object to operate on.

Returns:
(list): List of permissions.

Raises:
requests.HTTPError on failure.


def patch_mask(patch: dict) -> dict:

    def _patch_mask(body: dict) -> list:

        mask = set()
        if isinstance(body, dict):
            for parent, value in body.items():
                children = _patch_mask(value)
                if children and parent not in ('budgetSegments', 'partnerCosts'):
                    for child in children:
                        mask.add(parent + '.' + child)
                else:
                    mask.add(parent)
        elif isinstance(body, (list, tuple)):
            for value in body:
                mask.update(_patch_mask(value))
        return list(mask)
    mask = ','.join(_patch_mask(patch['parameters'].get('body')))
    if mask:
        patch['parameters']['updateMask'] = mask
    return patch

Adds an update mask to a patch based on keys in patch.

Operates under assumption that all fields prsent in update will be updated.
Immediately wraps a nested function to perform actual patch logic using generator.

Args:
patch: {
"operation": IGNORED,
"action": IGNORED,
"partner": IGNORED,
"advertiser": IGNORED,
"campaign": IGNORED,
"parameters": {
"body": { PATCH IS CONSTRUCTED FROM THIS }
}
}

Returns:
Patch with ['parameters']['updateMask'] added.


def break_before_sequence(chunks: typing.List[str], sequence: str) -> typing.List[str]:
    chunks = utils.SEP.join(chunks).replace(sequence, utils.SEP + sequence).split(utils.SEP)
    chunks = [chunk for chunk in chunks if len(chunk) > 0]
    return chunks

Breaks chunks before a specified character sequence appears.

Args:
chunks (List[str]): Chunks to break.
sequence (str): A character sequence to break chunks before.

Returns:
Processed chunks.


def from_structures(structures, transformations=None, extend_collection=0):
    tstruct = [TransformedStructure(s, []) for s in structures]
    return StandardTransmuter(tstruct, transformations, extend_collection)

Alternative constructor from structures rather than
TransformedStructures.

Args:
structures: Sequence of structures
transformations: New transformations to be applied to all
structures
extend_collection: Whether to use more than one output structure
from one-to-many transformations. extend_collection can be a
number, which determines the maximum branching for each
transformation.

Returns:
StandardTransmuter


def get_attribute_list(self, uid=None):
    batch_item = self._build_get_attribute_list_batch_item(uid)
    request = self._build_request_message(None, [batch_item])
    response = self._send_and_receive_message(request)
    results = self._process_batch_items(response)
    return results[0]

Send a GetAttributeList request to the server.

Args:
uid (string): The ID of the managed object with which the retrieved
attribute names should be associated.

Returns:
result (GetAttributeListResult): A structure containing the results
of the operation.


def add_severity(self, name, value):

        logger.debug("Adding severity {0} with value {1} to variant {2}".format(
            name, value, self['variant_id']))
        self['severities'].append({name: value})

Add a severity to the variant

Args:
name (str): The name of the severity
value : The value of the severity


def center_of_mass(self, time):
    if (self.start_time <= time <= self.end_time):
        diff = (time - self.start_time)
        valid = np.flatnonzero((self.masks[diff] != 0))
        if (valid.size > 0):
            com_x = ((1.0 / self.timesteps[diff].ravel()[valid].sum()) * np.sum((self.timesteps[diff].ravel()[valid] * self.x[diff].ravel()[valid])))
            com_y = ((1.0 / self.timesteps[diff].ravel()[valid].sum()) * np.sum((self.timesteps[diff].ravel()[valid] * self.y[diff].ravel()[valid])))
        else:
            com_x = np.mean(self.x[diff])
            com_y = np.mean(self.y[diff])
    else:
        com_x = None
        com_y = None
    return (com_x, com_y)

Calculate the center of mass at a given timestep.

Args:
time: Time at which the center of mass calculation is performed

Returns:
The x- and y-coordinates of the center of mass.


def get_block_iter(self, start_block=None, start_block_num=None, reverse=True):
    start = None
    if start_block_num:
        if (len(start_block_num) < 2):
            raise ValueError('Invalid start block num')
        if (start_block_num[:2] != '0x'):
            raise ValueError('Invalid start block num')
        start = int(start_block_num, 16)
    elif start_block:
        start = start_block.block_num
    return _BlockStoreIter(self.pointer, start, reverse)

Returns an iterator that traverses blocks in block number order.

Args:
start_block (:obj:`BlockWrapper`): the block from which traversal
begins
start_block_num (str): a starting block number, in hex, from where
traversal begins; only used if no starting_block is provided

reverse (bool): If True, traverse the blocks in from most recent
to oldest block. Otherwise, it traverse the blocks in the
opposite order.

Returns:
An iterator of block wrappers

Raises:
ValueError: If start_block or start_block_num do not specify a
valid block


def _infer_mutants_handler(self, request):

    try:
      if request.method != 'GET':
        logger.error('%s requests are forbidden.', request.method)
        return http_util.Respond(request, {'error': 'invalid non-GET request'},
                                 'application/json', code=405)

      example_index = int(request.args.get('example_index', '0'))
      feature_name = request.args.get('feature_name')
      examples = (self.examples if example_index == -1
          else [self.examples[example_index]])

      (inference_addresses, model_names, model_versions,
          model_signatures) = self._parse_request_arguments(request)

      serving_bundles = []
      for model_num in xrange(len(inference_addresses)):
        serving_bundles.append(inference_utils.ServingBundle(
            inference_addresses[model_num],
            model_names[model_num],
            request.args.get('model_type'),
            model_versions[model_num],
            model_signatures[model_num],
            request.args.get('use_predict') == 'true',
            request.args.get('predict_input_tensor'),
            request.args.get('predict_output_tensor')))

      viz_params = inference_utils.VizParams(
          request.args.get('x_min'), request.args.get('x_max'),
          self.examples[0:NUM_EXAMPLES_TO_SCAN], NUM_MUTANTS,
          request.args.get('feature_index_pattern'))
      json_mapping = inference_utils.mutant_charts_for_feature(
          examples, feature_name, serving_bundles, viz_params)
      return http_util.Respond(request, json_mapping, 'application/json')
    except common_utils.InvalidUserInputError as e:
      return http_util.Respond(request, {'error': e.message},
                               'application/json', code=400)

Returns JSON for the `vz-line-chart`s for a feature.

Args:
request: A request that should contain 'feature_name', 'example_index',
'inference_address', 'model_name', 'model_type', 'model_version', and
'model_signature'.

Returns:
A list of JSON objects, one for each chart.


def persist_time(run, session, timings):

    from benchbuild.utils import schema as s

    for timing in timings:
        session.add(
            s.Metric(name="time.user_s", value=timing[0], run_id=run.id))
        session.add(
            s.Metric(name="time.system_s", value=timing[1], run_id=run.id))
        session.add(
            s.Metric(name="time.real_s", value=timing[2], run_id=run.id))

Persist the run results in the database.

Args:
run: The run we attach this timing results to.
session: The db transaction we belong to.
timings: The timing measurements we want to store.


def set_computer_desc(desc=None):
    if six.PY2:
        desc = _to_unicode(desc)
    system_info = win32net.NetServerGetInfo(None, 101)
    if (desc is None):
        return False
    system_info['comment'] = desc
    try:
        win32net.NetServerSetInfo(None, 101, system_info)
    except win32net.error as exc:
        (number, context, message) = exc.args
        log.error('Failed to update system')
        log.error('nbr: %s', number)
        log.error('ctx: %s', context)
        log.error('msg: %s', message)
        return False
    return {'Computer Description': get_computer_desc()}

Set the Windows computer description

Args:

desc (str):
The computer description

Returns:
str: Description if successful, otherwise ``False``

CLI Example:

.. code-block:: bash

salt 'minion-id' system.set_computer_desc 'This computer belongs to Dave!'


def __init__(self, logger, gccxml_cvs_revision=None, castxml_format=None):

        if castxml_format is not None and gccxml_cvs_revision is not None:
            raise RuntimeError("Setting both gccxml_cvs_revision and"
                               "castxml_format is not allowed!")

        self._is_castxml1 = False
        self._is_castxml = False
        self._is_gccxml = False

        if castxml_format is not None:
            self._xml_generator_version = self.__castxml
            self._xml_output_version = castxml_format
            self._is_castxml = True
            self._is_castxml1 = True
        elif gccxml_cvs_revision is not None:
            self._xml_generator_version, self._xml_output_version = \
                self.__extract_versions(logger, gccxml_cvs_revision)
            self._is_gccxml = "GCC-XML" in self._xml_generator_version
            self._is_castxml = "CastXML" in self._xml_generator_version
        else:
            raise RuntimeError("Either castxml_format or gccxml_cvs_revision"
                               "need to be defined!")

Create a new xml_generators object.

Args:
logger (logging.Logger) : a logger for debugging output
gccxml_cvs_revision (str|None): the xml output version
castxml_format (str|None): the xml output version


def ParseFileDownloadedRow(self, parser_mediator, query, row, **unused_kwargs):
    query_hash = hash(query)
    event_data = ChromeHistoryFileDownloadedEventData()
    event_data.full_path = self._GetRowValue(query_hash, row, 'target_path')
    event_data.offset = self._GetRowValue(query_hash, row, 'id')
    event_data.query = query
    event_data.received_bytes = self._GetRowValue(query_hash, row, 'received_bytes')
    event_data.total_bytes = self._GetRowValue(query_hash, row, 'total_bytes')
    event_data.url = self._GetRowValue(query_hash, row, 'url')
    timestamp = self._GetRowValue(query_hash, row, 'start_time')
    date_time = dfdatetime_webkit_time.WebKitTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_FILE_DOWNLOADED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a file downloaded row.

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


def export_analytics_data_to_excel(data, output_file_name, result_info_key, identifier_keys):
    workbook = create_excel_workbook(data, result_info_key, identifier_keys)
    workbook.save(output_file_name)
    print('Saved Excel file to {}'.format(output_file_name))

Creates an Excel file containing data returned by the Analytics API

Args:
data: Analytics API data as a list of dicts
output_file_name: File name for output Excel file (use .xlsx extension).


def copy_script(self, filename, id_=(- 1)):
    for repo in self._children:
        repo.copy_script(filename, id_)

Copy a script to all repositories.

Takes into account whether a JSS has been migrated. See the
individual DistributionPoint types for more information.

Args:
filename: String path to the local file to copy.
id_: Integer ID you wish to associate script with for a JDS
or CDP only. Default is -1, which is used for creating
a new script object in the database.


def check_integrity(sakefile, settings):
    sprint = settings['sprint']
    error = settings['error']
    sprint('Call to check_integrity issued', level='verbose')
    if (not sakefile):
        error('Sakefile is empty')
        return False
    if (len(sakefile.keys()) != len(set(sakefile.keys()))):
        error('Sakefile contains duplicate targets')
        return False
    for target in sakefile:
        if (target == 'all'):
            if (not check_target_integrity(target, sakefile['all'], all=True)):
                error("Failed to accept target 'all'")
                return False
            continue
        if ('formula' not in sakefile[target]):
            if (not check_target_integrity(target, sakefile[target], meta=True)):
                errmes = "Failed to accept meta-target '{}'".format(target)
                error(errmes)
                return False
            for atom_target in sakefile[target]:
                if (atom_target == 'help'):
                    continue
                if (not check_target_integrity(atom_target, sakefile[target][atom_target], parent=target)):
                    errmes = "Failed to accept target '{}'\n".format(atom_target)
                    error(errmes)
                    return False
            continue
        if (not check_target_integrity(target, sakefile[target])):
            errmes = "Failed to accept target '{}'\n".format(target)
            error(errmes)
            return False
    return True

Checks the format of the sakefile dictionary
to ensure it conforms to specification

Args:
A dictionary that is the parsed Sakefile (from sake.py)
The setting dictionary (for print functions)
Returns:
True if the Sakefile is conformant
False if not


def _batch_prepare_for_model(self, batch_text_or_text_pairs, is_pair: Optional[bool]=None, boxes: Optional[List[List[int]]]=None, word_labels: Optional[List[List[int]]]=None, add_special_tokens: bool=True, padding_strategy: PaddingStrategy=PaddingStrategy.DO_NOT_PAD, truncation_strategy: TruncationStrategy=TruncationStrategy.DO_NOT_TRUNCATE, max_length: Optional[int]=None, stride: int=0, pad_to_multiple_of: Optional[int]=None, padding_side: Optional[str]=None, return_tensors: Optional[str]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_length: bool=False, verbose: bool=True) -> BatchEncoding:
    batch_outputs = {}
    for idx, example in enumerate(zip(batch_text_or_text_pairs, boxes)):
        batch_text_or_text_pair, boxes_example = example
        outputs = self.prepare_for_model(batch_text_or_text_pair[0] if is_pair else batch_text_or_text_pair, batch_text_or_text_pair[1] if is_pair else None, boxes_example, word_labels=word_labels[idx] if word_labels is not None else None, add_special_tokens=add_special_tokens, padding=PaddingStrategy.DO_NOT_PAD.value, truncation=truncation_strategy.value, max_length=max_length, stride=stride, pad_to_multiple_of=None, padding_side=None, return_attention_mask=False, return_token_type_ids=return_token_type_ids, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_length=return_length, return_tensors=None, prepend_batch_axis=False, verbose=verbose)
        for key, value in outputs.items():
            if key not in batch_outputs:
                batch_outputs[key] = []
            batch_outputs[key].append(value)
    batch_outputs = self.pad(batch_outputs, padding=padding_strategy.value, max_length=max_length, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_attention_mask=return_attention_mask)
    batch_outputs = BatchEncoding(batch_outputs, tensor_type=return_tensors)
    return batch_outputs

Prepares a sequence of input id, or a pair of sequences of inputs ids so that it can be used by the model. It
adds special tokens, truncates sequences if overflowing while taking into account the special tokens and
manages a moving window (with user defined stride) for overflowing tokens

Args:
batch_ids_pairs: list of tokenized input ids or input ids pairs


def do_reset_ids(concatenated_meta_df, data_df, concat_direction):
    if (concat_direction == 'horiz'):
        assert concatenated_meta_df.index.equals(data_df.columns), 'cids in concatenated_meta_df do not agree with cids in data_df.'
        reset_ids_in_meta_df(concatenated_meta_df)
        data_df.columns = pd.Index(concatenated_meta_df.index.values)
    elif (concat_direction == 'vert'):
        assert concatenated_meta_df.index.equals(data_df.index), 'rids in concatenated_meta_df do not agree with rids in data_df.'
        reset_ids_in_meta_df(concatenated_meta_df)
        data_df.index = pd.Index(concatenated_meta_df.index.values)

Reset ids in concatenated metadata and data dfs to unique integers and
save the old ids in a metadata column.

Note that the dataframes are modified in-place.

Args:
concatenated_meta_df (pandas df)
data_df (pandas df)
concat_direction (string): 'horiz' or 'vert'

Returns:
None (dfs modified in-place)


def ws_db996(self, value=None):
    if (value is not None):
        try:
            value = float(value)
        except ValueError:
            raise ValueError('value {} need to be of type float for field `ws_db996`'.format(value))
    self._ws_db996 = value

Corresponds to IDD Field `ws_db996`
Mean wind speed coincident with 99.6% dry-bulb temperature

Args:
value (float): value for IDD Field `ws_db996`
Unit: m/s
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 Mult(self, x, factor):

        self.d[x] = self.d.get(x, 0) * factor

Scales the freq/prob associated with the value x.

Args:
x: number value
factor: how much to multiply by


def _finish_disconnection_action(self, action):

        success = action.data['success']
        conn_key = action.data['id']

        if self._get_connection_state(conn_key) != self.Disconnecting:
            self._logger.error("Invalid finish_disconnection action on a connection whose state is not Disconnecting, conn_key=%s", str(conn_key))
            return

        data = self._get_connection(conn_key)
        callback = data['callback']

        conn_id = data['conn_id']
        int_id = data['int_id']

        if success is False:
            reason = action.data['reason']
            if reason is None:
                reason = "No reason was given"

            data['state'] = self.Idle
            data['microstate'] = None
            data['callback'] = None
            callback(conn_id, self.id, False, reason)
        else:
            del self._connections[conn_id]
            del self._int_connections[int_id]
            callback(conn_id, self.id, True, None)

Finish a disconnection attempt

There are two possible outcomes:
- if we were successful at disconnecting, we transition to disconnected
- if we failed at disconnecting, we transition back to idle

Args:
action (ConnectionAction): the action object describing what we are
disconnecting from and what the result of the operation was


def load_case(self, config_data, update=False):

        institute_obj = self.institute(config_data['owner'])
        if not institute_obj:
            raise IntegrityError("Institute '%s' does not exist in database" % config_data['owner'])

        parsed_case = parse_case(config=config_data)

        case_obj = build_case(parsed_case, self)

        old_caseid = '-'.join([case_obj['owner'], case_obj['display_name']])
        old_case = self.case(old_caseid)
        if old_case:
            LOG.info("Update case id for existing case: %s -> %s", old_caseid, case_obj['_id'])
            self.update_caseid(old_case, case_obj['_id'])
            update = True

        existing_case = self.case(case_obj['_id'])
        if existing_case and not update:
            raise IntegrityError("Case %s already exists in database" % case_obj['_id'])

        files = [
            {'file_name': 'vcf_snv', 'variant_type': 'clinical', 'category': 'snv'},
            {'file_name': 'vcf_sv', 'variant_type': 'clinical', 'category': 'sv'},
            {'file_name': 'vcf_cancer', 'variant_type': 'clinical', 'category': 'cancer'},
            {'file_name': 'vcf_str', 'variant_type': 'clinical', 'category': 'str'}
        ]

        try:
            for vcf_file in files:

                if not case_obj['vcf_files'].get(vcf_file['file_name']):
                    LOG.debug("didn't find {}, skipping".format(vcf_file['file_name']))
                    continue

                variant_type = vcf_file['variant_type']
                category = vcf_file['category']
                if update:
                    self.delete_variants(
                        case_id=case_obj['_id'],
                        variant_type=variant_type,
                        category=category
                    )
                self.load_variants(
                    case_obj=case_obj,
                    variant_type=variant_type,
                    category=category,
                    rank_threshold=case_obj.get('rank_score_threshold', 0),
                )

        except (IntegrityError, ValueError, ConfigError, KeyError) as error:
            LOG.warning(error)

        if existing_case and update:
            self.update_case(case_obj)
        else:
            LOG.info('Loading case %s into database', case_obj['display_name'])
            self._add_case(case_obj)

        return case_obj

Load a case into the database

Check if the owner and the institute exists.

Args:
config_data(dict): A dictionary with all the necessary information
update(bool): If existing case should be updated

Returns:
case_obj(dict)


def call(self, url, method=None, args=None):
    if (not args):
        args = {}
    if (sys.version_info.major == 3):
        data = urllib.parse.urlparse(url)
        path = (data.path.rstrip('/') + '/')
        _args = dict(urllib.parse.parse_qs(data.query, keep_blank_values=True))
    elif (sys.version_info.major == 2):
        data = urlparse.urlparse(url)
        path = (data.path.rstrip('/') + '/')
        _args = dict(urlparse.parse_qs(data.query, keep_blank_values=True))
    for elem in self._data_store:
        pattern = elem['pattern']
        function = elem['function']
        _method = elem['method']
        type_cast = elem['type_cast']
        result = re.match(pattern, path)
        if (result and (_method == method)):
            _args = dict(_args, **result.groupdict())
            for (key, val) in _args.items():
                if (isinstance(_args[key], list) and (len(_args[key]) == 1)):
                    _args[key] = _args[key][0]
            for (key, val) in type_cast.items():
                if (key not in _args):
                    continue
                if (not _args[key]):
                    continue
                if isinstance(_args[key], list):
                    for (i, _val) in enumerate(_args[key]):
                        _args[key][i] = self._cast(_val, val)
                else:
                    _args[key] = self._cast(_args[key], val)
            requiered_args = self._get_function_args(function)
            for (key, val) in args.items():
                if (key in requiered_args):
                    _args[key] = val
            return function(**_args)
    return None

Calls the first function matching the urls pattern and method.

Args:
url (str): Url for which to call a matching function.
method (str, optional): The method used while registering a
function.
Defaults to None
args (dict, optional): Additional args to be passed to the
matching function.

Returns:
The functions return value or `None` if no function was called.


def get_alpha(self, x: int, y: int) -> int:

        return lib.TCOD_image_get_alpha(self.image_c, x, y)

Get the Image alpha of the pixel at x, y.

Args:
x (int): X pixel of the image.  Starting from the left at 0.
y (int): Y pixel of the image.  Starting from the top at 0.

Returns:
int: The alpha value of the pixel.
With 0 being fully transparent and 255 being fully opaque.


def _compute_nfp_real(l, u, counts, sizes):

    if l > u:
        raise ValueError("l must be less or equal to u")
    return np.sum((float(sizes[u])-sizes[l:u+1])/float(sizes[u])*counts[l:u+1])

Computes the expected number of false positives caused by using
u to approximate set sizes in the interval [l, u], using the real
set size distribution.

Args:
l: the lower bound on set sizes.
u: the upper bound on set sizes.
counts: the complete distribution of set sizes.
sizes: the complete domain of set sizes.

Return (float): the expected number of false positives.


def GetMessages(self, formatter_mediator, event):

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

    event_values = event.CopyToDict()

    page_transition_type = event_values.get('page_transition_type', None)
    if page_transition_type is not None:
      page_transition, page_transition_long = self._PAGE_TRANSITIONS.get(
          page_transition_type, self._UNKNOWN_PAGE_TRANSITION)

      if page_transition_long:
        event_values['page_transition'] = '{0:s} - {1:s}'.format(
            page_transition, page_transition_long)
      else:
        event_values['page_transition'] = page_transition

    visit_source = event_values.get('visit_source', None)
    if visit_source is not None:
      event_values['visit_source'] = self._VISIT_SOURCE.get(
          visit_source, 'UNKNOWN')

    extras = []

    url_hidden = event_values.get('url_hidden', False)
    if url_hidden:
      extras.append('(url hidden)')

    typed_count = event_values.get('typed_count', 0)
    if typed_count == 0:
      extras.append('(URL not typed directly - no typed count)')
    elif typed_count == 1:
      extras.append('(type count {0:d} time)'.format(typed_count))
    else:
      extras.append('(type count {0:d} times)'.format(typed_count))

    event_values['extra'] = ' '.join(extras)

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

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

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

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


def validate(cls, job_config):

    if job_config.input_reader_cls != cls:
      raise errors.BadReaderParamsError(
          "Expect input reader class %r, got %r." %
          (cls, job_config.input_reader_cls))

Validates relevant parameters.

This method can validate fields which it deems relevant.

Args:
job_config: an instance of map_job.JobConfig.

Raises:
errors.BadReaderParamsError: required parameters are missing or invalid.


def register_game(game_name, game_mode="NoFrameskip-v4"):

  if game_name not in ATARI_GAMES:
    raise ValueError("Game %s not in ATARI_GAMES" % game_name)
  if game_mode not in ATARI_GAME_MODES:
    raise ValueError("Unknown ATARI game mode: %s." % game_mode)
  camel_game_name = misc_utils.snakecase_to_camelcase(game_name) + game_mode

  cls = type("Gym%sRandom" % camel_game_name,
             (T2TGymEnv,), {"base_env_name": camel_game_name})
  registry.register_problem(cls)

Create and register problems for the game.

Args:
game_name: str, one of the games in ATARI_GAMES, e.g. "bank_heist".
game_mode: the frame skip and sticky keys config.

Raises:
ValueError: if game_name or game_mode are wrong.


def diff(self, container):

        return self._result(
            self._get(self._url("/containers/{0}/changes", container)), True
        )

Inspect changes on a container's filesystem.

Args:
container (str): The container to diff

Returns:
(str)

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def bogoliubov_trans(p, q, theta):
    expo = (((- 4) * theta) / np.pi)
    (yield cirq.X(p))
    (yield cirq.S(p))
    (yield (cirq.ISWAP(p, q) ** expo))
    (yield (cirq.S(p) ** 1.5))
    (yield cirq.X(p))

r"""The 2-mode Bogoliubov transformation is mapped to two-qubit operations.
We use the identity X S^\dag X S X = Y X S^\dag Y S X = X to transform
the Hamiltonian XY+YX to XX+YY type. The time evolution of the XX + YY
Hamiltonian can be expressed as a power of the iSWAP gate.

Args:
p: the first qubit
q: the second qubit
theta: The rotational angle that specifies the Bogoliubov
transformation, which is a function of the kinetic energy and
the superconducting gap.


def extract(self, text: str, confidence=0.5, filter=['Person', 'Place', 'Organisation']) -> List[Extraction]:

        filter = ','.join(filter)
        search_data = [('confidence', confidence),
                       ('text', text),
                       ('types', filter)]
        search_headers = {'Accept': 'application/json'}
        r = requests.post(self._search_url,
                          data=search_data,
                          headers=search_headers)
        results = r.json()

        last_results = self._combiner(results)
        return last_results

Extract with the input text, confidence and fields filter to be used.
Args:
text (str): text input to be annotated
confidence (float): the confidence of the annotation
filter (List[str]): the fields that to be extracted

Returns:
List[Extraction]


def _convert_to_ragged_tensor_values(value):
    if _is_supported_ragged_values_type(value):
        return value
    else:
        return convert_to_tensor_or_ragged_tensor(value, name='values')

Converts value to supported RaggedTensor value.

* If `value` is an object of supported value type, then return it as-is.
* Otherwise convert it to Tensor or RaggedTensor.

Args:
value: An object of `Tensor`, `RaggedTensor` or registered RaggedTensor
value types, or an object whose type has a registered `Tensor` conversion
function.

Returns:
An object of `Tensor`, `RaggedTensor` or registered RaggedTensor
value types


def _determine_api_url(self, platform, service, action):

        base_uri = settings.BASE_PAL_URL.format(platform)
        if service == "Recurring":
            api_version = settings.API_RECURRING_VERSION
        elif service == "Payout":
            api_version = settings.API_PAYOUT_VERSION
        else:
            api_version = settings.API_PAYMENT_VERSION
        return '/'.join([base_uri, service, api_version, action])

This returns the Adyen API endpoint based on the provided platform,
service and action.

Args:
platform (str): Adyen platform, ie 'live' or 'test'.
service (str): API service to place request through.
action (str): the API action to perform.


def __init_subclass__(cls, user_cls=None):
    utils.ensure_explicit_method_override(cls.__init__, '`pg.Object.__init__` is a PyGlove managed method. For setting up the class initialization logic, please override `_on_bound()` or `_on_init()`. If you do have a need to override `__init__` and know the implications, please decorate your overridden method with `@pg.explicit_method_override`.')
    setattr(cls, '__serialization_key__', cls.__type_name__)
    super().__init_subclass__()
    user_cls = user_cls or cls
    if user_cls.auto_schema:
        base_schema_list = []
        for base_cls in user_cls.__bases__:
            base_schema = getattr(base_cls, '__schema__', None)
            if isinstance(base_schema, pg_typing.Schema):
                base_schema_list.append(base_schema)
        new_fields = user_cls._infer_fields_from_annotations()
        cls_schema = pg_typing.create_schema(new_fields, base_schema_list=base_schema_list, allow_nonconst_keys=True, metadata={}, for_cls=user_cls)
        user_cls._update_default_values_from_class_attributes(cls_schema)
        if new_fields:
            cls_schema.metadata['init_arg_list'] = None
        user_cls.apply_schema(cls_schema)

Initializes subclass.

`pg.Object` allows child classes to explicit call
`pg.Object.__init_subclass__` in their `__init_subclass__`, to bypass other
classes' `__init__subclass__` in multi-inheritance use cases.

Example:

class Subclass(pg.Object, UserClass):
def __init_subclass__(cls):
# This bypasses UserClass.__init_subclass__
pg.Object.__init_subclass__(cls)

Args:
user_cls: The source class that calls this class method.


def depth_january_average_ground_temperature(self, value=None):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError(
                    'value {} need to be of type float '
                    'for field `depth_january_average_ground_temperature`'.format(value))

        self._depth_january_average_ground_temperature = value

Corresponds to IDD Field `depth_january_average_ground_temperature`

Args:
value (float): value for IDD Field `depth_january_average_ground_temperature`
Unit: C
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