def encode_function_call(self, function_name, args):
    if (function_name not in self.function_data):
        raise ValueError('Unkown function {}'.format(function_name))
    description = self.function_data[function_name]
    function_selector = zpad(encode_int(description['prefix']), 4)
    arguments = encode_abi(description['encode_types'], args)
    return (function_selector + arguments)

Return the encoded function call.

Args:
function_name (str): One of the existing functions described in the
contract interface.
args (List[object]): The function arguments that wll be encoded and
used in the contract execution in the vm.

Return:
bin: The encoded function name and arguments so that it can be used
with the evm to execute a funcion call, the binary string follows
the Ethereum Contract ABI.


def __init__(self, features: List[np.ndarray], timestamps: np.ndarray, schema: Optional[Schema]=None) -> None:
    self.features = features
    self.timestamps = timestamps
    if schema is not None:
        self.check_schema(schema)

Initializes the IndexData object by checking and setting the features
and timestamps.

Raises:
ValueError: If features are not one-dimensional arrays.
ValueError: If the number of elements in features and timestamps
do not match.


def insert_arguments_into_match_query(compilation_result, arguments):

    if compilation_result.language != MATCH_LANGUAGE:
        raise AssertionError(u'Unexpected query output language: {}'.format(compilation_result))

    base_query = compilation_result.query
    argument_types = compilation_result.input_metadata

    sanitized_arguments = {
        key: _safe_match_argument(argument_types[key], value)
        for key, value in six.iteritems(arguments)
    }

    return base_query.format(**sanitized_arguments)

Insert the arguments into the compiled MATCH query to form a complete query.

Args:
compilation_result: a CompilationResult object derived from the GraphQL compiler
arguments: dict, mapping argument name to its value, for every parameter the query expects.

Returns:
string, a MATCH query with inserted argument data


def get_updates_for(self, inputs):
    warnings.warn('`layer.get_updates_for` is deprecated and will be removed in a future version. Please use `layer.updates` method instead.')
    return self.updates

Deprecated, do NOT use!

Retrieves updates relevant to a specific set of inputs.

Args:
inputs: Input tensor or list/tuple of input tensors.

Returns:
List of update ops of the layer that depend on `inputs`.


def load_method(path,method,class_name = None,instance_creator = None):

    module  = load_module(path)
    if class_name :

        class_type  = getattr(module, class_name)
        if instance_creator:
            ic_rest     = instance_creator
            nxt         = module
            while ('.' in ic_rest)  :
                nxt         = getattr(nxt    , instance_creator.split('.')[0])
                ic_rest     = '.'.join(ic_rest.split('.')[1:])
            instance = getattr(module, instance_creator)()
        else :
            instance = class_type()
        return getattr(instance , method)
    else :
        return getattr(module   , method)

Returns an instance of the method specified.
Args :
path            : The path to the module contianing the method or function.
method          : The name of the function.
class_name      : The name of the class if the funtion is a method.
instance_creator: The name of the method to return the class instance.


def compute_invariants(self, graph_file, input_format, invariants=Invariants.ALL, email=None, use_threads=False, callback=None):
    if (email is None):
        email = self.email
    if (input_format not in GraphFormats._any):
        raise ValueError('Invalid input format, {}.'.format(input_format))
    if (not (set(invariants) <= set(Invariants.ALL))):
        raise ValueError('Invariants must be a subset of Invariants.ALL.')
    if (use_threads and (callback is not None)):
        if (not hasattr(callback, '__call__')):
            raise ValueError('callback must be a function.')
        if (len(inspect.getargspec(callback).args) != 1):
            raise ValueError('callback must take exactly 1 argument.')
    url = 'graphupload/{}/{}/{}/'.format(email, input_format, '/'.join(invariants))
    if (' ' in url):
        raise ValueError('Arguments cannot have spaces in them.')
    if (not os.path.exists(graph_file)):
        raise ValueError('File {} does not exist.'.format(graph_file))
    if use_threads:
        upload_thread = threading.Thread(target=self._run_compute_invariants, args=[url, graph_file, callback])
        upload_thread.start()
    else:
        return self._run_compute_invariants(url, graph_file)
    return

Compute invariants from an existing GraphML file using the remote
grute graph services.

Arguments:
graph_file (str): The filename of the graphml file
input_format (str): One of grute.GraphFormats
invariants (str[]: Invariants.ALL)*: An array of grute.Invariants
to compute on the graph
email (str: self.email)*: The email to notify upon completion
use_threads (bool: False)*: Whether to use Python threads to run
computation in the background when waiting for the server to
return the invariants
callback (function: None)*: The function to run upon completion of
the call, if using threads. (Will not be called if use_threads
is set to False.)

Returns:
HTTP Response if use_threads is False. Otherwise, None

Raises:
ValueError: If the graph file does not exist, or if there are
issues with the passed arguments
RemoteDataUploadError: If there is an issue packing the file
RemoteError: If the server experiences difficulty computing invs


def _GetTableNames(self, database):

    table_names = []
    for esedb_table in database.tables:
      table_names.append(esedb_table.name)

    return table_names

Retrieves the table names in a database.

Args:
database (pyesedb.file): ESE database.

Returns:
list[str]: table names.


def plot_axis(self, ax, legend, ladder=False, default_width=1, match_only=None, colour=None, colour_function=None, cmap=None, default=None, width_field=None, **kwargs):
    default_c = None
    patches = []
    for iv in self.__list:
        origin = (0, iv.top.z)
        d = legend.get_decor(iv.primary, match_only=match_only)
        thick = (iv.base.z - iv.top.z)
        if ladder:
            if (width_field is not None):
                w = iv.data.get(width_field, 1)
                w = ((default_width * w) / self.max_field(width_field))
                default_c = 'gray'
            elif (legend is not None):
                w = (d.width or default_width)
                try:
                    w = ((default_width * w) / legend.max_width)
                except:
                    w = default_width
        else:
            w = default_width
        this_patch_kwargs = kwargs.copy()
        lw = this_patch_kwargs.pop('lw', 0)
        ec = this_patch_kwargs.pop('ec', 'k')
        fc = (this_patch_kwargs.pop('fc', None) or default_c or d.colour)
        if (colour is None):
            rect = mpl.patches.Rectangle(origin, w, thick, fc=fc, lw=lw, hatch=d.hatch, ec=ec, **this_patch_kwargs)
            ax.add_patch(rect)
        else:
            rect = mpl.patches.Rectangle(origin, w, thick, lw=lw, ec=ec, **this_patch_kwargs)
            patches.append(rect)
    if (colour is not None):
        cmap = (cmap or 'viridis')
        p = mpl.collections.PatchCollection(patches, cmap=cmap, lw=lw)
        p.set_array(self.get_data(colour, colour_function, default=default))
        ax.add_collection(p)
        cb = plt.colorbar(p)
        cb.outline.set_linewidth(0)
    return ax

Plotting, but only the Rectangles. You have to set up the figure.
Returns a matplotlib axis object.

Args:
ax (axis): The matplotlib axis to plot into.
legend (Legend): The Legend to use for colours, etc.
ladder (bool): Whether to use widths or not. Default False.
default_width (int): A width for the plot if not using widths.
Default 1.
match_only (list): A list of strings matching the attributes you
want to compare when plotting.
colour (str): Which data field to use for colours.
cmap (cmap): Matplotlib colourmap. Default ``viridis``.
default (float): The default (null) value.
width_field (str): The field to use for the width of the patches.
**kwargs are passed through to matplotlib's ``patches.Rectangle``.

Returns:
axis: The matplotlib.pyplot axis.


def localize_file(path_or_buffer):

    path_or_buffer = _stringify_path(path_or_buffer)

    if _is_url(path_or_buffer):
        req = urlopen(path_or_buffer)
        filename = os.path.basename(req.geturl())
        if os.path.splitext(filename)[-1] is not ".pdf":
            pid = os.getpid()
            filename = "{0}.pdf".format(pid)

        with open(filename, 'wb') as f:
            shutil.copyfileobj(req, f)

        return filename, True

    elif is_file_like(path_or_buffer):
        pid = os.getpid()
        filename = "{0}.pdf".format(pid)

        with open(filename, 'wb') as f:
            shutil.copyfileobj(path_or_buffer, f)

        return filename, True

    else:
        return os.path.expanduser(path_or_buffer), False

Ensure localize target file.

If the target file is remote, this function fetches into local storage.

Args:
path (str):
File path or file like object or URL of target file.

Returns:
filename (str): file name in local storage
temporary_file_flag (bool): temporary file flag


def stop_gradient(input_layer):
    if input_layer.is_sequence():
        result = [tf.stop_gradient(t) for t in input_layer.sequence]
        return input_layer.with_sequence(result)
    else:
        return tf.stop_gradient(input_layer)

Cuts off the gradient at this point.

This works on both sequence and regular Pretty Tensors.

Args:
input_layer: The input.
Returns:
A new Pretty Tensor of the same type with stop_gradient applied.


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

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

Clones the Layout, overriding data and parameters.

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

Returns:
Cloned Layout object


def get_peers(self, id=None, endpoint=None):

        return self._call_endpoint(GET_PEERS, id=id, endpoint=endpoint)

Get the current peers of a remote node
Args:
id: (int, optional) id to use for response tracking
endpoint: (RPCEndpoint, optional) endpoint to specify to use

Returns:
json object of the result or the error encountered in the RPC call


def _write_install_json(self, filename, install_json):

        if os.path.isfile(filename):
            with open(filename, 'w') as fh:
                json.dump(install_json, fh, indent=4, sort_keys=True)
        else:
            err = 'Could not write file: {}.'.format(filename)

            self.package_data['errors'].append(err)

Write install.json file.

Some projects have bundles App with multiple install.json files.  Typically these files are
prefixed with the App name (e.g., MyApp.install.json).

Args:
filename (str): The install.json file name.
install_json (dict): The contents of the install.json file.


def find_rootfs(conn, disk_root):
    rootfs = conn.inspect_os()
    if ((not rootfs) or (len(rootfs) > 1)):
        filesystems = conn.list_filesystems()
        if (disk_root in filesystems):
            rootfs = [disk_root]
        else:
            rootfs = [fs for fs in filesystems.keys() if (disk_root in fs)]
            if (not rootfs):
                raise GuestFSError('no root fs {0} could be found from list {1}'.format(disk_root, str(filesystems)))
    return sorted(rootfs)[0]

Find the image's device root filesystem, and return its path.

1. Use :func:`guestfs.GuestFS.inspect_os` method. If it returns more than
one root filesystem or None, try:
2. Find an exact match of `disk_root` from
:func:`guestfs.GuestFS.list_filesystems`, if none is found, try:
3. Return the device that has the substring `disk_root` contained in it,
from the output of :func:`guestfs.GuestFS.list_filesystems`.

Args:
conn(guestfs.GuestFS): Open GuestFS handle.
disk_root(str): Root device to search for. Note that by default, if
guestfs can deduce the filesystem, it will not be used.

Returns:
str: root device path

Raises:
:exc:`GuestFSError` if no root filesystem was found


def add_vectors(self, vectors):
    if isinstance(vectors[0], (list, np.ndarray)):
        for vec in vectors:
            self.vectors.append(vec)
    else:
        self.vectors.append(vectors)

Add a list of vectors to Bloch sphere.

Args:
vectors (array_like):
Array with vectors of unit length or smaller.


def inspect_task(self, task):

        url = self._url('/tasks/{0}', task)
        return self._result(self._get(url), True)

Retrieve information about a task.

Args:
task (str): Task ID

Returns:
(dict): Information about the task.

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


def check_candidate_exists(self, basepath, candidates):

        checked = []
        for item in candidates:
            abspath = os.path.join(basepath, item)
            if os.path.exists(abspath):
                checked.append(abspath)

        return checked

Check that at least one candidate exist into a directory.

Args:
basepath (str): Directory path where to search for candidate.
candidates (list): List of candidate file paths.

Returns:
list: List of existing candidates.


def __partial_trace_vec(vec, trace_systems, dimensions, reverse=True):
    if reverse:
        dimensions = dimensions[::(- 1)]
        trace_systems = ((len(dimensions) - 1) - np.array(trace_systems))
    rho = vec.reshape(dimensions)
    rho = np.tensordot(rho, rho.conj(), axes=(trace_systems, trace_systems))
    d = int(np.sqrt(np.product(rho.shape)))
    return rho.reshape(d, d)

Partial trace over subsystems of multi-partite vector.

Args:
vec (vector_like): complex vector N
trace_systems (list(int)): a list of subsystems (starting from 0) to
trace over.
dimensions (list(int)): a list of the dimensions of the subsystems.
If this is not set it will assume all
subsystems are qubits.
reverse (bool): ordering of systems in operator.
If True system-0 is the right most system in tensor product.
If False system-0 is the left most system in tensor product.

Returns:
ndarray: A density matrix with the appropriate subsystems traced over.


def Pack(cls, obj, version):
    if isinstance(obj, ServiceQuery):
        return str(obj)
    return obj

Pack the given object using AdWords-specific logic.

Args:
obj: an object to be packed for SOAP using AdWords-specific logic, if
applicable.
version: the version of the current API, e.g. 'v201809'

Returns:
The given object packed with AdWords-specific logic for SOAP, if
applicable. Otherwise, returns the given object unmodified.


def get_normalized_variable_map(scope_or_module, collection=tf.GraphKeys.GLOBAL_VARIABLES, context=None, group_sliced_variables=True):
    scope_name = get_variable_scope_name(scope_or_module)
    if (context is None):
        context = scope_or_module
    prefix = get_variable_scope_name(context)
    prefix_length = ((len(prefix) + 1) if prefix else 0)
    if (not _is_scope_prefix(scope_name, prefix)):
        raise ValueError("Scope '{}' is not prefixed by '{}'.".format(scope_name, prefix))
    variables = get_variables_in_scope(scope_name, collection)
    if (not group_sliced_variables):
        single_vars = variables
        grouped_vars = dict()
    else:
        (single_vars, grouped_vars) = _get_sliced_variables(variables)
    var_map = {var.op.name[prefix_length:]: var for var in single_vars}
    for (full_name, var_group) in grouped_vars.items():
        name = full_name[prefix_length:]
        if (name in var_map):
            raise ValueError(('Mixing slices and non-slices with the same name: ' + str(name)))
        var_map[name] = var_group
    return var_map

Builds map of `tf.Variable`s in scope or module with normalized names.

The names of the variables are normalized to remove the scope prefix.

Args:
scope_or_module: Scope or module to build map from.
collection: Collection to restrict query to. By default this is
`tf.Graphkeys.GLOBAL_VARIABLES`, which includes non-trainable variables
such as moving averages.
context: Scope or module, identical to or parent of `scope`. If given, this
will be used as the stripped prefix. By default `None`, which means
`context=scope`.
group_sliced_variables: Boolean, if set to True, sliced variables are
grouped together in the returned map; if set to False, each partition of
a sliced variable is a separate (key, value) pair.

Returns:
Dictionary mapping normalized variable name to `tf.Variable`, or a list
of `tf.Variables` if the variable is a sliced (partitioned) variable.

Raises:
ValueError: If `context` is given but is not a proper prefix of `scope`.


def submit_batch_prediction(job_request, job_id=None):
    if (job_id is None):
        job_id = ('prediction_' + datetime.datetime.now().strftime('%y%m%d_%H%M%S'))
    job = {'job_id': job_id, 'prediction_input': job_request}
    context = datalab.Context.default()
    cloudml = discovery.build('ml', 'v1', credentials=context.credentials)
    request = cloudml.projects().jobs().create(body=job, parent=('projects/' + context.project_id))
    request.headers['user-agent'] = 'GoogleCloudDataLab/1.0'
    request.execute()
    return Job(job_id)

Submit a batch prediction job.

Args:
job_request: the arguments of the training job in a dict. For example,
{
'version_name': 'projects/my-project/models/my-model/versions/my-version',
'data_format': 'TEXT',
'input_paths': ['gs://my_bucket/my_file.csv'],
'output_path': 'gs://my_bucket/predict_output',
'region': 'us-central1',
'max_worker_count': 1,
}
job_id: id for the training job. If None, an id based on timestamp will be generated.

Returns:
A Job object representing the batch prediction job.


def get_capacity_grav(self, min_voltage=None, max_voltage=None, use_overall_normalization=True):
    pairs_in_range = self._select_in_voltage_range(min_voltage, max_voltage)
    normalization_mass = (self.normalization_mass if (use_overall_normalization or (len(pairs_in_range) == 0)) else pairs_in_range[(- 1)].mass_discharge)
    return (sum([pair.mAh for pair in pairs_in_range]) / normalization_mass)

Get the gravimetric capacity of the electrode.

Args:
min_voltage (float): The minimum allowable voltage for a given
step.
max_voltage (float): The maximum allowable voltage allowable for a
given step.
use_overall_normalization (booL): If False, normalize by the
discharged state of only the voltage pairs matching the voltage
criteria. if True, use default normalization of the full
electrode path.

Returns:
Gravimetric capacity in mAh/g across the insertion path (a subset
of the path can be chosen by the optional arguments).


def publish_metric(self, metric_name, metric_value, epoch_seconds=None):
    if (epoch_seconds is None):
        epoch_seconds = self._reactor.seconds()
    self._client_factory.publish_metric(metric_name, metric_value, int(epoch_seconds))

Record a single hit on a given metric.

Args:
metric_name: The name of the metric to record with Carbon.
metric_value: The value to record with Carbon.
epoch_seconds: Optionally specify the time for the metric hit.

Returns:
None


def generate_algebra_inverse_sample(vlist, ops, solve_ops, min_depth, max_depth):
    side = random.randrange(2)
    left_depth = random.randrange((min_depth if side else 0), (max_depth + 1))
    right_depth = random.randrange((min_depth if (not side) else 0), (max_depth + 1))
    var_index = random.randrange(len(vlist))
    var = vlist[var_index]
    consts = (vlist[:var_index] + vlist[(var_index + 1):])
    left = random_expr_with_required_var(left_depth, (var if side else None), consts, ops)
    right = random_expr_with_required_var(right_depth, (var if (not side) else None), consts, ops)
    left_str = str(left)
    right_str = str(right)
    target = str(algebra_inverse_solve(left, right, var, solve_ops))
    sample = ('%s:%s=%s' % (var, left_str, right_str))
    return (sample, target)

Randomly generate an algebra inverse dataset sample.

Given an input equation and variable, produce the expression equal to the
variable.

Args:
vlist: Variable list. List of chars that can be used in the expression.
ops: List of ExprOp instances. The allowed operators for the expression.
solve_ops: See `solve_ops` documentation in `algebra_inverse_solve`.
min_depth: Expression trees will not have a smaller depth than this. 0 means
there is just a variable. 1 means there is one operation.
max_depth: Expression trees will not have a larger depth than this. To make
all trees have the same depth, set this equal to `min_depth`.

Returns:
sample: String representation of the input. Will be of the form
'solve_var:left_side=right_side'.
target: String representation of the solution.


def layer_preprocess(layer_input, hparams, layer_collection=None):

  assert "a" not in hparams.layer_preprocess_sequence, (
      "No residual connections allowed in hparams.layer_preprocess_sequence")
  assert "z" not in hparams.layer_preprocess_sequence, (
      "No residual connections allowed in hparams.layer_preprocess_sequence")
  return layer_prepostprocess(
      None,
      layer_input,
      sequence=hparams.layer_preprocess_sequence,
      dropout_rate=hparams.layer_prepostprocess_dropout,
      norm_type=hparams.norm_type,
      depth=None,
      epsilon=hparams.norm_epsilon,
      dropout_broadcast_dims=comma_separated_string_to_integer_list(
          getattr(hparams, "layer_prepostprocess_dropout_broadcast_dims", "")),
      default_name="layer_prepostprocess",
      layer_collection=layer_collection)

Apply layer preprocessing.

See layer_prepostprocess() for details.

A hyperparameters object is passed for convenience.  The hyperparameters
that may be used are:

layer_preprocess_sequence
layer_prepostprocess_dropout
norm_type
hidden_size
norm_epsilon

Args:
layer_input: a Tensor
hparams: a hyperparameters object.
layer_collection: A tensorflow_kfac.LayerCollection. Only used by the
KFAC optimizer. Default is None.

Returns:
a Tensor


def select_executor(elem, doc):
    executor = EXECUTORS['default']
    if ('cmd' in elem.attributes.keys()):
        executor = elem.attributes['cmd']
    elif ('runas' in elem.attributes.keys()):
        executor = EXECUTORS[elem.attributes['runas']]
    elif (elem.classes[0] != 'exec'):
        executor = EXECUTORS[elem.classes[0]]
    return executor

Determines the executor for the code in `elem.text`.

The elem attributes and classes select the executor in this order (highest
to lowest):
- custom commands (cmd=...)
- runas (runas=...) takes a key for the executors
- first element class (.class) determines language and thus executor

Args:
elem The AST element.
doc  The document.

Returns:
The command to execute code.


def build_single_handler_applications(paths, argvs=None):
    applications = {}
    argvs = ({} or argvs)
    for path in paths:
        application = build_single_handler_application(path, argvs.get(path, []))
        route = application.handlers[0].url_path()
        if (not route):
            if ('/' in applications):
                raise RuntimeError(("Don't know the URL path to use for %s" % path))
            route = '/'
        applications[route] = application
    return applications

Return a dictionary mapping routes to Bokeh applications built using
single handlers, for specified files or directories.

This function iterates over ``paths`` and ``argvs`` and calls
:func:`~bokeh.command.util.build_single_handler_application` on each
to generate the mapping.

Args:
path (seq[str]) : paths to files or directories for creating Bokeh
applications.

argvs (dict[str, list[str]], optional) : mapping of paths to command
line arguments to pass to the handler for each path

Returns:
dict[str, Application]

Raises:
RuntimeError


def price(self, market: pmd.ProcessedMarketData, name: Optional[str]=None):
    model = self._config.model or models.InterestRateModelType.HULL_WHITE_ONE_FACTOR
    name = name or self._name + '_price'
    with tf.name_scope(name):
        valuation_date = dateslib.convert_to_date_tensor(market.date)
        strike = self._swap.fixed_rate()
        expiry_time = dateslib.daycount_actual_365_fixed(start_date=valuation_date, end_date=self._expiry_date, dtype=self._dtype)
        if model == models.InterestRateModelType.HULL_WHITE_ONE_FACTOR:
            option_value = self._price_hull_white_1_factor(valuation_date, market, strike, expiry_time)
        else:
            raise ValueError('Unsupported model.')
        return option_value

Returns the present value of the swaption on the valuation date.

Args:
market: A instance of type `ProcessedMarketData` which contains the
necessary information for pricing the swaption.
name: Python str. The name to give to the ops created by this function.
Default value: `None` which maps to 'price'.

Returns:
A Rank `Tensor` of shape `batch_shape` containing the modeled price of
each  Swaption contract based on the input market data.

Raises:
ValueError: If an unsupported model is supplied to the function.


def _randomFloats(self, shape, low=0.0, high=1.0, dtype=dtypes.float32):
    val = np.random.random_sample(shape)
    diff = high - low
    val *= diff
    val += low
    return constant_op.constant(val, dtype=dtype)

Generate a tensor of random floating-point values.

Values will be continuously distributed in the range [low, high).

Note that we use numpy to generate random numbers and then feed the result
through a constant op to avoid the re-rolling of TensorFlow random ops on
each run in graph mode.

Args:
shape: The output shape.
low: Lower bound of random numbers generated, inclusive.
high: Upper bound of random numbers generated, exclusive.
dtype: The output dtype.

Returns:
A random tensor


def accumulate_from_superclasses(cls, propname):

    cachename = "__cached_all" + propname

    if cachename not in cls.__dict__:
        s = set()
        for c in inspect.getmro(cls):
            if issubclass(c, HasProps) and hasattr(c, propname):
                base = getattr(c, propname)
                s.update(base)
        setattr(cls, cachename, s)
    return cls.__dict__[cachename]

Traverse the class hierarchy and accumulate the special sets of names
``MetaHasProps`` stores on classes:

Args:
name (str) : name of the special attribute to collect.

Typically meaningful values are: ``__container_props__``,
``__properties__``, ``__properties_with_refs__``


def _PrintEventLabelsCounter(
      self, event_labels_counter, session_identifier=None):

    if not event_labels_counter:
      return

    title = 'Event tags generated per label'
    if session_identifier:
      title = '{0:s}: {1:s}'.format(title, session_identifier)

    table_view = views.ViewsFactory.GetTableView(
        self._views_format_type,
        column_names=['Label', 'Number of event tags'], title=title)

    for key, value in sorted(event_labels_counter.items()):
      if key == 'total':
        continue
      table_view.AddRow([key, value])

    try:
      total = event_labels_counter['total']
    except KeyError:
      total = 'N/A'

    table_view.AddRow(['Total', total])

    table_view.Write(self._output_writer)

Prints the event labels counter.

Args:
event_labels_counter (collections.Counter): number of event tags per
label.
session_identifier (Optional[str]): session identifier.


def __Build(leaves):

        if len(leaves) < 1:
            raise Exception('Leaves must have length')
        if len(leaves) == 1:
            return leaves[0]

        num_parents = int((len(leaves) + 1) / 2)
        parents = [MerkleTreeNode() for i in range(0, num_parents)]

        for i in range(0, num_parents):
            node = parents[i]
            node.LeftChild = leaves[i * 2]
            leaves[i * 2].Parent = node
            if (i * 2 + 1 == len(leaves)):
                node.RightChild = node.LeftChild
            else:
                node.RightChild = leaves[i * 2 + 1]
                leaves[i * 2 + 1].Parent = node

            hasharray = bytearray(node.LeftChild.Hash.ToArray() + node.RightChild.Hash.ToArray())
            node.Hash = UInt256(data=Crypto.Hash256(hasharray))

        return MerkleTree.__Build(parents)

Build the merkle tree.

Args:
leaves (list): items are of type MerkleTreeNode.

Returns:
MerkleTreeNode: the root node.


def get_contour_pd_plot(self):
    from scipy import interpolate
    from matplotlib import cm
    pd = self._pd
    entries = pd.qhull_entries
    data = np.array(pd.qhull_data)
    plt = self._get_2d_plot()
    data[(:, 0:2)] = triangular_coord(data[(:, 0:2)]).transpose()
    for (i, e) in enumerate(entries):
        data[(i, 2)] = self._pd.get_e_above_hull(e)
    gridsize = 0.005
    xnew = np.arange(0, 1.0, gridsize)
    ynew = np.arange(0, 1, gridsize)
    f = interpolate.LinearNDInterpolator(data[(:, 0:2)], data[(:, 2)])
    znew = np.zeros((len(ynew), len(xnew)))
    for (i, xval) in enumerate(xnew):
        for (j, yval) in enumerate(ynew):
            znew[(j, i)] = f(xval, yval)
    plt.contourf(xnew, ynew, znew, 1000, cmap=cm.autumn_r)
    plt.colorbar()
    return plt

Plot a contour phase diagram plot, where phase triangles are colored
according to degree of instability by interpolation. Currently only
works for 3-component phase diagrams.

Returns:
A matplotlib plot object.


def get_exe_info(dir_, flag_protected=False):

    ret = []

    ff = glob.glob(os.path.join(dir_, "*.py"))

    ff = [f for f in ff if flag_protected or not os.path.basename(f).startswith("_")]
    ff.sort()

    for f in ff:
        _, filename = os.path.split(f)
        flag_error = False
        flag_gui = None
        descr = "(no doc)"
        try:

            with open(f, "r") as h:
                flag_gui = "QApplication" in h.read()

            try:
                script_ = None
                script_ = import_module(f)
            except SystemExit:
                descr = "? (called sys.exit())"
            else:
                if script_.__doc__ is not None:
                    descr = script_.__doc__.strip().split("\n")[0]

        except Exception as e:
            flag_error = True
            descr = "*{0!s}*: {1!s}".format(e.__class__.__name__, str(e))

        if len(descr) == 0:
            descr = "(no doc)"

        ret.append(ExeInfo(filename, descr, flag_error, flag_gui))

    sisi_gra = [si for si in ret if si.flag_gui]
    sisi_cmd = [si for si in ret if not si.flag_gui]
    sisi_gra = sorted(sisi_gra, key=lambda x: x.filename)
    sisi_cmd = sorted(sisi_cmd, key=lambda x: x.filename)
    ret = sisi_cmd+sisi_gra

    return ret

Returns a list of ExeInfo objects, which represent Python scripts within dir_

Args:
dir_: string, path to directory
flag_protected: whether or not to include files starting with a '_'

Returns:
list of ExeInfo objects

The ExeInfo objects represent the ".py" files in directory dir_,


def __init__(self, value=None):

        super(ApplicationData, self).__init__(value, Tags.APPLICATION_DATA)

Construct an ApplicationData object.

Args:
value (str): A string representing data for a particular namespace.
Optional, defaults to None.


def get_country_by_id(self, country_id) -> 'Country':

        VALID_POSITIVE_INT.validate(country_id, 'get_country_by_id', exc=ValueError)
        if country_id not in self._countries_by_id.keys():
            for country in self.countries:

                if country.country_id == country_id:
                    return country
            raise ValueError(country_id)
        else:
            return self._countries_by_id[country_id]

Gets a country in this coalition by its ID

Args:
country_id: country Id

Returns: Country


def bind_to_storage_buffer(self, binding=0, *, offset=0, size=(- 1)) -> None:
    self.mglo.bind_to_storage_buffer(binding, offset, size)

Bind the buffer to a shader storage buffer.

Args:
binding (int): The shader storage binding.

Keyword Args:
offset (int): The offset.
size (int): The size. Value ``-1`` means all.


def swo_disable(self, port_mask):

        res = self._dll.JLINKARM_SWO_DisableTarget(port_mask)
        if res != 0:
            raise errors.JLinkException(res)
        return None

Disables ITM & Stimulus ports.

Args:
self (JLink): the ``JLink`` instance
port_mask (int): mask specifying which ports to disable

Returns:
``None``

Raises:
JLinkException: on error


def download_and_prep_data() -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
    mnist_dataset = tf.keras.datasets.mnist
    (tr_x, tr_y), (te_x, te_y) = mnist_dataset.load_data()
    tr_x = tr_x / 255.0
    te_x = te_x / 255.0
    return (tr_x, tr_y, te_x, te_y)

Download dataset and scale to [0, 1].

Returns:
tr_x: Training data.
tr_y: Training labels.
te_x: Testing data.
te_y: Testing labels.


def replace_dots_to_underscores_at_last(path):

    if path == '':
        return path
    bits = path.split('/')
    bits[-1] = bits[-1].replace('.', '_')
    return '/'.join(bits)

Remove dot ('.') while a dot is treated as a special character in backends

Args:
path (str): A target path string

Returns:
str


def refresh_role(self, role, file_hierarchy):

        if role not in self.cache:
            self.cache[role] = {}
        was_change = self._refresh_hierarchy_recursive(self.cache[role], file_hierarchy)
        if was_change:
            cf = open(self.cache_file, 'w')
            yaml.dump(self.cache, cf, Dumper=Dumper)
            cf.close()

Checks and refreshes (if needed) all assistants with given role.

Args:
role: role of assistants to refresh
file_hierarchy: hierarchy as returned by devassistant.yaml_assistant_loader.\
YamlAssistantLoader.get_assistants_file_hierarchy


def init_on_device(device: 'torch.device', include_buffers: bool=False):
    if include_buffers:
        with device:
            yield
        return
    old_register_parameter = nn.Module.register_parameter
    if include_buffers:
        old_register_buffer = nn.Module.register_buffer

    def register_empty_parameter(module, name, param):
        old_register_parameter(module, name, param)
        if param is not None:
            param_cls = type(module._parameters[name])
            kwargs = module._parameters[name].__dict__
            kwargs['requires_grad'] = param.requires_grad
            module._parameters[name] = param_cls(module._parameters[name].to(device), **kwargs)

    def register_empty_buffer(module, name, buffer, persistent=True):
        old_register_buffer(module, name, buffer, persistent=persistent)
        if buffer is not None:
            module._buffers[name] = module._buffers[name].to(device)
    if include_buffers:
        tensor_constructors_to_patch = {torch_function_name: getattr(torch, torch_function_name) for torch_function_name in ['empty', 'zeros', 'ones', 'full']}
    else:
        tensor_constructors_to_patch = {}

    def patch_tensor_constructor(fn):

        def wrapper(*args, **kwargs):
            kwargs['device'] = device
            return fn(*args, **kwargs)
        return wrapper
    try:
        nn.Module.register_parameter = register_empty_parameter
        if include_buffers:
            nn.Module.register_buffer = register_empty_buffer
        for torch_function_name in tensor_constructors_to_patch.keys():
            setattr(torch, torch_function_name, patch_tensor_constructor(getattr(torch, torch_function_name)))
        yield
    finally:
        nn.Module.register_parameter = old_register_parameter
        if include_buffers:
            nn.Module.register_buffer = old_register_buffer
        for torch_function_name, old_torch_function in tensor_constructors_to_patch.items():
            setattr(torch, torch_function_name, old_torch_function)

A context manager under which models are initialized with all parameters on the specified device.

Args:
device (`torch.device`):
Device to initialize all parameters on.
include_buffers (`bool`, *optional*):
Whether or not to also put all buffers on the meta device while initializing.

Example:

```python
import torch.nn as nn
from accelerate import init_on_device

with init_on_device(device=torch.device("cuda")):
tst = nn.Linear(100, 100)  # on `cuda` device
```


def add_child(self, child):
    if (not isinstance(child, Node)):
        raise TypeError('child must be a Node')
    self.children.append(child)
    child.parent = self

Add child to ``Node`` object

Args:
``child`` (``Node``): The child ``Node`` to be added


def m_seg(p1, p2, rad, dist):

    v = vector(p1, p2)
    m = unit(rotate(v, rad), dist)
    return translate(p1, m), translate(p2, m)

move segment by distance
Args:
p1, p2: point(x, y)
rad: relative direction angle(radian)
dist: distance
Return:
translated segment(p1, p2)


def _prefix_from_prefix_string(self, prefixlen_str):

        try:
            if not _BaseV4._DECIMAL_DIGITS.issuperset(prefixlen_str):
                raise ValueError
            prefixlen = int(prefixlen_str)
            if not (0 <= prefixlen <= self._max_prefixlen):
               raise ValueError
        except ValueError:
            raise NetmaskValueError('%s is not a valid prefix length' %
                                    prefixlen_str)
        return prefixlen

Turn a prefix length string into an integer.

Args:
prefixlen_str: A decimal string containing the prefix length.

Returns:
The prefix length as an integer.

Raises:
NetmaskValueError: If the input is malformed or out of range.


def add_permissions(self, grp_name, resource, permissions):

        self.project_service.set_auth(self._token_project)
        self.project_service.add_permissions(grp_name, resource, permissions)

Add additional permissions for the group associated with the resource.

Args:
grp_name (string): Name of group.
resource (intern.resource.boss.Resource): Identifies which data
model object to operate on.
permissions (list): List of permissions to add to the given resource

Raises:
requests.HTTPError on failure.


def _GetImportTimestamps(self, pefile_object):

    import_timestamps = []
    if not hasattr(pefile_object, 'DIRECTORY_ENTRY_IMPORT'):
      return import_timestamps
    for importdata in pefile_object.DIRECTORY_ENTRY_IMPORT:
      dll_name = getattr(importdata, 'dll', '')
      try:
        dll_name = dll_name.decode('ascii')
      except UnicodeDecodeError:
        dll_name = dll_name.decode('ascii', errors='replace')
      if not dll_name:
        dll_name = '<NO DLL NAME>'

      timestamp = getattr(importdata.struct, 'TimeDateStamp', 0)
      if timestamp:
        import_timestamps.append([dll_name, timestamp])
    return import_timestamps

Retrieves timestamps from the import directory, if available.

Args:
pefile_object (pefile.PE): pefile object.

Returns:
list[int]: import timestamps.


def __call__(self, *args, **kwargs) -> Any:

Calls the functor.

Args:
*args: Any positional arguments.
**kwargs: Any keyword arguments.

Returns:
Any value.


def group_alleles_by_start_end_Xbp(arr, bp=28):

    starts = arr[:,0:bp]
    ends = arr[:,-bp:]
    starts_ends_idxs = defaultdict(list)
    l, seq_len = arr.shape
    for i in range(l):
        start_i = starts[i]
        end_i = ends[i]
        start_i_str = ''.join([str(x) for x in start_i])
        end_i_str = ''.join([str(x) for x in end_i])
        starts_ends_idxs[start_i_str + end_i_str].append(i)
    return starts_ends_idxs

Group alleles by matching ends

Args:
arr (numpy.array): 2D int matrix of alleles
bp (int): length of ends to group by

Returns:
dict of lists: key of start + end strings to list of indices of alleles with matching ends


def _update_in_hdx(self, object_type, id_field_name, file_to_upload=None, **kwargs):

        self._check_load_existing_object(object_type, id_field_name)

        self._merge_hdx_update(object_type, id_field_name, file_to_upload, **kwargs)

Helper method to check if HDX object exists in HDX and if so, update it

Args:
object_type (str): Description of HDX object type (for messages)
id_field_name (str): Name of field containing HDX object identifier
file_to_upload (Optional[str]): File to upload to HDX
**kwargs: See below
operation (string): Operation to perform eg. patch. Defaults to update.

Returns:
None


def update_variant_rank(self, case_obj, variant_type='clinical', category='snv'):
    variants = self.variant_collection.find({'case_id': case_obj['_id'], 'category': category, 'variant_type': variant_type}).sort('rank_score', pymongo.DESCENDING)
    LOG.info('Updating variant_rank for all variants')
    requests = []
    for (index, var_obj) in enumerate(variants):
        if (len(requests) > 5000):
            try:
                self.variant_collection.bulk_write(requests, ordered=False)
                requests = []
            except BulkWriteError as err:
                LOG.warning('Updating variant rank failed')
                raise err
        operation = pymongo.UpdateOne({'_id': var_obj['_id']}, {'$set': {'variant_rank': (index + 1)}})
        requests.append(operation)
    try:
        self.variant_collection.bulk_write(requests, ordered=False)
    except BulkWriteError as err:
        LOG.warning('Updating variant rank failed')
        raise err
    LOG.info('Updating variant_rank done')

Updates the manual rank for all variants in a case

Add a variant rank based on the rank score
Whenever variants are added or removed from a case we need to update the variant rank

Args:
case_obj(Case)
variant_type(str)


def remove_repeated_comments(node):
    last_comment = {'text': None}
    for _node in gast.walk(node):
        if anno.hasanno(_node, 'comment'):
            comment = anno.getanno(_node, 'comment')
            if (comment['text'] == last_comment['text']):
                anno.delanno(_node, 'comment')
            last_comment = comment
    return node

Remove comments that repeat themselves.

Multiple statements might be annotated with the same comment. This way if one
of the statements is deleted during optimization passes, the comment won't be
lost. This pass removes sequences of identical comments, leaving only the
first one.

Args:
node: An AST

Returns:
An AST where comments are not repeated in sequence.


def get_attr(self, name):
    fields = ('s', 'i', 'f', 'b', 'type', 'shape', 'tensor', 'func')
    try:
        with c_api_util.tf_buffer() as buf:
            pywrap_tf_session.TF_OperationGetAttrValueProto(self._c_op, name, buf)
            data = pywrap_tf_session.TF_GetBuffer(buf)
    except errors.InvalidArgumentError as e:
        raise ValueError(e.message)
    x = attr_value_pb2.AttrValue()
    x.ParseFromString(data)
    oneof_value = x.WhichOneof('value')
    if oneof_value is None:
        return []
    if oneof_value == 'list':
        for f in fields:
            if getattr(x.list, f):
                if f == 'type':
                    return [dtypes.as_dtype(t) for t in x.list.type]
                else:
                    return list(getattr(x.list, f))
        return []
    if oneof_value == 'type':
        return dtypes.as_dtype(x.type)
    assert oneof_value in fields, 'Unsupported field type in ' + str(x)
    return getattr(x, oneof_value)

Returns the value of the attr of this op with the given `name`.

Args:
name: The name of the attr to fetch.

Returns:
The value of the attr, as a Python object.

Raises:
ValueError: If this op does not have an attr with the given `name`.


def path_new_using_function(w: int, h: int, func: Callable[([int, int, int, int, Any], float)], userData: Any=0, dcost: float=1.41) -> tcod.path.AStar:
    return tcod.path.AStar(tcod.path._EdgeCostFunc((func, userData), (w, h)), dcost)

Return a new AStar using the given callable function.

Args:
w (int): Clipping width.
h (int): Clipping height.
func (Callable[[int, int, int, int, Any], float]):
userData (Any):
dcost (float): A multiplier for the cost of diagonal movement.
Can be set to 0 to disable diagonal movement.
Returns:
AStar: A new AStar instance.


def commandline_parser(parser=None, arguments=None):
    if parser is None:
        parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=textwrap.dedent('        Command line to execute all tasks in a recipe once. ( Common Entry Point )\n\n        This script dispatches all the tasks in a JSON recipe to handlers in sequence.\n        For each task, it calls a subprocess to execute the JSON instructions, waits\n        for the process to complete and dispatches the next task, until all tasks are\n        complete or a critical failure ( exception ) is raised.\n\n        If an exception is raised in any task, all following tasks are not executed by design.\n\n        Example: python run.py [path to recipe file]\n        Caution: This script does NOT check if the last job finished, potentially causing overruns.\n        Notes:\n          - To avoid running the entire script when debugging a single task, the command line\n            can easily replace "all" with the name of any "task" in the json.  For example\n            python tool/recipe.py scripts/say_hello.json\n\n          - Can be easily replaced with the following to run only the "hello" task:\n            python task/hello/run.py scripts/say_hello.json\n\n          - Or specified further to run only the second hello task:\n            python task/hello/run.py scripts/say_hello.json -i 2\n\n    '))
    if arguments is None:
        parser.add_argument('json', help='Path to recipe json file to load.')
    elif '-j' in arguments:
        parser.add_argument('--json', '-j', help='Path to recipe json file to load.')
    if arguments is None or '-p' in arguments:
        parser.add_argument('--project', '-p', help='Cloud ID of Google Cloud Project.', default=None)
    if arguments is None or '-k' in arguments:
        parser.add_argument('--key', '-k', help='API Key of Google Cloud Project.', default=None)
    if arguments is None or '-u' in arguments:
        parser.add_argument('--user', '-u', help='Path to USER credentials json file.', default=None)
    if arguments is None or '-s' in arguments:
        parser.add_argument('--service', '-s', help='Path to SERVICE credentials json file.', default=None)
    if arguments is None or '-c' in arguments:
        parser.add_argument('--client', '-c', help='Path to CLIENT credentials json file.', default=None)
    if arguments is None or '-t' in arguments:
        parser.add_argument('--task', '-t', help='Task number of the task to run starting at 1.', default=None, type=int)
    if arguments is None or '-v' in arguments:
        parser.add_argument('--verbose', '-v', help='Print all the steps as they happen.', action='store_true')
    if arguments is None or '-f' in arguments:
        parser.add_argument('--force', '-force', help='Not used but included for compatiblity with another script.', action='store_true')
    if arguments is None or '-tp' in arguments:
        parser.add_argument('--trace_print', '-tp', help='Execution trace written to stdout.', action='store_true')
    if arguments is None or '-tf' in arguments:
        parser.add_argument('--trace_file', '-tf', help='Execution trace written to file.', action='store_true')
    if arguments is None or '-ni' in arguments:
        parser.add_argument('--no_input', '-ni', help='Raise exception if fields requiring input are in recipe.', action='store_true')
    return parser

Used in StarThinker scripts as entry point for command line calls.

Defines standard parameters used by almost every entry point.

Usage example:

```
import argparse
from starthinker.util.configuration import commandline_parser

if __name__ == "__main__":

# custom parameters
parser = argparse.ArgumentParser()
parser.add_argument('custom', help='custom parameter to be added.')

# initialize project
commandline_parser(parser=parser, ['-c', '-u'])

# access arguments
print(args.client)
```

Args:
* parser: (ArgumentParser) optional custom argument parser
* arguments: (String) optional list of parameters to use when invoking, all set if None

Returns:
ArgumentParser - parser with added parameters


def view_quick_save_page(name=None):
    response.set_header('Cache-control', 'no-cache')
    response.set_header('Pragma', 'no-cache')
    if (request.method == 'PUT'):
        if (name is None):
            if (len(request.forms.filename) > 0):
                name = request.forms.filename
        if (name is not None):
            filename = '{0}.rst'.format(name)
            file_handle = open(filename, 'w')
            content = request.body.read()
            content = content.decode('utf-8')
            file_handle.write(content.encode('utf-8'))
            file_handle.close()
            return 'OK'
        else:
            return abort(404)

Quick save a page.

.. note:: this is a bottle view

* this view must be called with the PUT method
write the new page content to the file, and not not commit or redirect

Keyword Arguments:
:name: (str) -- name of the rest file (without the .rst extension)

Returns:
bottle response object (200 OK)


def load_module_functions(module):

    module_functions = {}

    for name, item in vars(module).items():
        if validator.is_function(item):
            module_functions[name] = item

    return module_functions

load python module functions.

Args:
module: python module

Returns:
dict: functions mapping for specified python module

{
"func1_name": func1,
"func2_name": func2
}


def _load_from_file_object(self, f):

    subtoken_strings = []
    for line in f:
      s = line.strip()

      if ((s.startswith("'") and s.endswith("'")) or
          (s.startswith("\"") and s.endswith("\""))):
        s = s[1:-1]
      subtoken_strings.append(native_to_unicode(s))
    self._init_subtokens_from_list(subtoken_strings)
    self._init_alphabet_from_tokens(subtoken_strings)

Load from a file object.

Args:
f: File object to load vocabulary from


def scheduled_sample_count(ground_truth_x,
                           generated_x,
                           batch_size,
                           scheduled_sample_var):

  num_ground_truth = scheduled_sample_var
  idx = tf.random_shuffle(tf.range(batch_size))
  ground_truth_idx = tf.gather(idx, tf.range(num_ground_truth))
  generated_idx = tf.gather(idx, tf.range(num_ground_truth, batch_size))

  ground_truth_examps = tf.gather(ground_truth_x, ground_truth_idx)
  generated_examps = tf.gather(generated_x, generated_idx)

  output = tf.dynamic_stitch([ground_truth_idx, generated_idx],
                             [ground_truth_examps, generated_examps])

  if isinstance(batch_size, int):
    output.set_shape([batch_size] + common_layers.shape_list(output)[1:])
  return output

Sample batch with specified mix of groundtruth and generated data points.

Args:
ground_truth_x: tensor of ground-truth data points.
generated_x: tensor of generated data points.
batch_size: batch size
scheduled_sample_var: number of ground-truth examples to include in batch.
Returns:
New batch with num_ground_truth sampled from ground_truth_x and the rest
from generated_x.


class ViltFastImageProcessorKwargs(DefaultFastImageProcessorKwargs):
    do_pad: Optional[bool]
    size_divisor: Optional[int]
    rescale_factor: Optional[float]

Args:
do_pad (`bool`, *optional*, defaults to `True`):
Whether to pad the image. If `True`, will pad the images in the batch to the largest height and width
in the batch. Padding will be applied to the bottom and right with zeros.
size_divisor (`int`, *optional*, defaults to 32):
The size to make the height and width divisible by.
rescale_factor (`float`, *optional*, defaults to 1/255):
The factor to rescale the image by.


def fetch_all_messages(self, conn, directory, readonly):

        conn.select(directory, readonly)

        message_data = []

        typ, data = conn.search(None, 'All')

        for num in data[0].split():

            typ, data = conn.fetch(num, '(RFC822)')

            for response_part in data:

                if isinstance(response_part, tuple):

                    email_parser = email.parser.BytesFeedParser()
                    email_parser.feed(response_part[1])

                    msg = email_parser.close()

                    body = self.get_body(msg)
                    subject = self.get_subject(msg)

                    message_data.append((subject, body))

        return message_data

Fetches all messages at @conn from @directory.

Params:
conn        IMAP4_SSL connection
directory   The IMAP directory to look for
readonly    readonly mode, true or false
Returns:
List of subject-body tuples


def _compute_intersection(boxes1, boxes2):
    y_min1, x_min1, y_max1, x_max1 = ops.split(boxes1[..., :4], 4, axis=-1)
    y_min2, x_min2, y_max2, x_max2 = ops.split(boxes2[..., :4], 4, axis=-1)
    boxes2_rank = len(boxes2.shape)
    perm = [1, 0] if boxes2_rank == 2 else [0, 2, 1]
    intersect_ymax = ops.minimum(y_max1, ops.transpose(y_max2, perm))
    intersect_ymin = ops.maximum(y_min1, ops.transpose(y_min2, perm))
    intersect_xmax = ops.minimum(x_max1, ops.transpose(x_max2, perm))
    intersect_xmin = ops.maximum(x_min1, ops.transpose(x_min2, perm))
    intersect_height = intersect_ymax - intersect_ymin
    intersect_width = intersect_xmax - intersect_xmin
    zeros_t = ops.cast(0, intersect_height.dtype)
    intersect_height = ops.maximum(zeros_t, intersect_height)
    intersect_width = ops.maximum(zeros_t, intersect_width)
    return intersect_height * intersect_width

Computes intersection area between two sets of boxes.

Args:
boxes1: [N, 4] or [batch_size, N, 4] float Tensor boxes.
boxes2: [M, 4] or [batch_size, M, 4] float Tensor boxes.
Returns:
a [N, M] or [batch_size, N, M] float Tensor.


def _iter_errors_custom(instance, checks, options):
    for v_function in checks:
        try:
            result = v_function(instance)
        except TypeError:
            result = v_function(instance, options)
        if isinstance(result, Iterable):
            for x in result:
                (yield x)
        elif (result is not None):
            (yield result)
    for field in instance:
        if (type(instance[field]) is list):
            for obj in instance[field]:
                if _is_stix_obj(obj):
                    for err in _iter_errors_custom(obj, checks, options):
                        (yield err)

Perform additional validation not possible merely with JSON schemas.

Args:
instance: The STIX object to be validated.
checks: A sequence of callables which do the checks.  Each callable
may be written to accept 1 arg, which is the object to check,
or 2 args, which are the object and a ValidationOptions instance.
options: ValidationOptions instance with settings affecting how
validation should be done.


def _eval_once(saver, summary_writer, top_1_op, top_5_op, summary_op):
    with tf.Session() as sess:
        ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir)
        if (ckpt and ckpt.model_checkpoint_path):
            print('ckpt.model_checkpoint_path: {0}'.format(ckpt.model_checkpoint_path))
            saver.restore(sess, ckpt.model_checkpoint_path)
            global_step = ckpt.model_checkpoint_path.split('/')[(- 1)].split('-')[(- 1)]
            print(('Successfully loaded model from %s at step=%s.' % (ckpt.model_checkpoint_path, global_step)))
        else:
            print('No checkpoint file found')
            return
        coord = tf.train.Coordinator()
        try:
            threads = []
            for qr in tf.get_collection(tf.GraphKeys.QUEUE_RUNNERS):
                threads.extend(qr.create_threads(sess, coord=coord, daemon=True, start=True))
            num_iter = int(math.ceil((FLAGS.num_examples / FLAGS.batch_size)))
            count_top_1 = 0.0
            count_top_5 = 0.0
            total_sample_count = (num_iter * FLAGS.batch_size)
            step = 0
            print(('%s: starting evaluation on (%s).' % (datetime.now(), FLAGS.subset)))
            start_time = time.time()
            while ((step < num_iter) and (not coord.should_stop())):
                (top_1, top_5) = sess.run([top_1_op, top_5_op])
                count_top_1 += np.sum(top_1)
                count_top_5 += np.sum(top_5)
                step += 1
                if ((step % 20) == 0):
                    duration = (time.time() - start_time)
                    sec_per_batch = (duration / 20.0)
                    examples_per_sec = (FLAGS.batch_size / sec_per_batch)
                    print(('%s: [%d batches out of %d] (%.1f examples/sec; %.3fsec/batch)' % (datetime.now(), step, num_iter, examples_per_sec, sec_per_batch)))
                    start_time = time.time()
            precision_at_1 = (count_top_1 / total_sample_count)
            recall_at_5 = (count_top_5 / total_sample_count)
            print(('%s: precision @ 1 = %.4f recall @ 5 = %.4f [%d examples]' % (datetime.now(), precision_at_1, recall_at_5, total_sample_count)))
            summary = tf.Summary()
            summary.ParseFromString(sess.run(summary_op))
            summary.value.add(tag='Precision @ 1', simple_value=precision_at_1)
            summary.value.add(tag='Recall @ 5', simple_value=recall_at_5)
            summary_writer.add_summary(summary, global_step)
        except Exception as e:
            coord.request_stop(e)
        coord.request_stop()
        coord.join(threads, stop_grace_period_secs=10)

Runs Eval once.

Args:
saver: Saver.
summary_writer: Summary writer.
top_1_op: Top 1 op.
top_5_op: Top 5 op.
summary_op: Summary op.


def next(self):
    try:
        entry = {}
        row = self._csv_reader.next()
        for i in range(0, len(row)):
            entry[self._headers[i]] = row[i]
        return entry
    except Exception as e:
        self._file.close()
        raise e

Gets next entry as a dictionary.

Returns:
object - Object key/value pair representing a row.
{key1: value1, key2: value2, ...}


def add_to_tensor(self, mat, name='add_to_tensor'):
    return self._possibly_broadcast_batch_shape(mat)

Add matrix represented by this operator to `mat`.  Equiv to `I + mat`.

Args:
mat:  `Tensor` with same `dtype` and shape broadcastable to `self`.
name:  A name to give this `Op`.

Returns:
A `Tensor` with broadcast shape and same `dtype` as `self`.


def __init__(self, plugin_callback, plugin_dir = 'workers'):

        self.plugin_callback = plugin_callback
        self.plugin_dir = plugin_dir
        self.load_all_plugins()

        self.watcher = dir_watcher.DirWatcher(self.plugin_path)
        self.watcher.register_callbacks(self.on_created, self.on_modified, self.on_deleted)
        self.watcher.start_monitoring()

Initialize the Plugin Manager for Workbench.

Args:
plugin_callback: The callback for plugin. This is called when plugin is added.
plugin_dir: The dir where plugin resides.


def get_configuration(head, update, head_source=None):

    head_source = (head_source or get_head_source(head))
    update_source = get_acquisition_source(update)

    if not is_arxiv_and_publisher(head_source, update_source) and is_manual_merge(head, update):
        return ManualMergeOperations

    if head_source == 'arxiv':
        if update_source == 'arxiv':
            return ArxivOnArxivOperations
        else:
            return PublisherOnArxivOperations
    else:
        if update_source == 'arxiv':
            return ArxivOnPublisherOperations
        else:
            return PublisherOnPublisherOperations

This function return the right configuration for the inspire_merge
function in according to the given sources. Both parameters can not be None.

Params:
head(dict): the HEAD record
update(dict): the UPDATE record
head_source(string): the source of the HEAD record

Returns:
MergerConfigurationOperations: an object containing
the rules needed to merge HEAD and UPDATE


def to_string(self):

        def filt(x):
            return '+'+x[0] in PROJ4_PARAMS.keys() and x[1] is not False

        items = []
        for k, v in sorted(filter(filt, self.items())):
            items.append(
                "+" + "=".join(
                    map(str, filter(
                        lambda y: (y or y == 0) and y is not True, (k, v)))))
        return " ".join(items)

Turn a CRS dict into a PROJ.4 string. Mapping keys are tested against
``all_proj_keys`` list. Values of ``True`` are omitted, leaving the key
bare: {'no_defs': True} -> "+no_defs" and items where the value is
otherwise not a str, int, or float are omitted.

Args:
crs: A CRS dict as used in Location.

Returns:
str. The string representation.


def dump_table_as_insert_sql(engine: Engine,
                             table_name: str,
                             fileobj: TextIO,
                             wheredict: Dict[str, Any] = None,
                             include_ddl: bool = False,
                             multirow: bool = False) -> None:

    log.info("dump_data_as_insert_sql: table_name={}", table_name)
    writelines_nl(fileobj, [
        SEP1,
        sql_comment("Data for table: {}".format(table_name)),
        SEP2,
        sql_comment("Filters: {}".format(wheredict)),
    ])
    dialect = engine.dialect
    if not dialect.supports_multivalues_insert:
        multirow = False
    if multirow:
        log.warning("dump_data_as_insert_sql: multirow parameter substitution "
                    "not working yet")
        multirow = False

    meta = MetaData(bind=engine)
    log.debug("... retrieving schema")
    table = Table(table_name, meta, autoload=True)
    if include_ddl:
        log.debug("... producing DDL")
        dump_ddl(table.metadata, dialect_name=engine.dialect.name,
                 fileobj=fileobj)

    log.debug("... fetching records")

    query = select(table.columns)
    if wheredict:
        for k, v in wheredict.items():
            col = table.columns.get(k)
            query = query.where(col == v)

    cursor = engine.execute(query)
    if multirow:
        row_dict_list = []
        for r in cursor:
            row_dict_list.append(dict(r))

        if row_dict_list:
            statement = table.insert().values(row_dict_list)

            insert_str = get_literal_query(statement, bind=engine)

            writeline_nl(fileobj, insert_str)
        else:
            writeline_nl(fileobj, sql_comment("No data!"))
    else:
        found_one = False
        for r in cursor:
            found_one = True
            row_dict = dict(r)
            statement = table.insert(values=row_dict)

            insert_str = get_literal_query(statement, bind=engine)

            writeline_nl(fileobj, insert_str)
        if not found_one:
            writeline_nl(fileobj, sql_comment("No data!"))
    writeline_nl(fileobj, SEP2)
    log.debug("... done")

Reads a table from the database, and writes SQL to replicate the table's
data to the output ``fileobj``.

Args:
engine: SQLAlchemy :class:`Engine`
table_name: name of the table
fileobj: file-like object to write to
wheredict: optional dictionary of ``{column_name: value}`` to use as
``WHERE`` filters
include_ddl: if ``True``, include the DDL to create the table as well
multirow: write multi-row ``INSERT`` statements


def recipe_trends_places_to_bigquery_via_query(config, auth_write, secret, key, places_dataset, places_query, places_legacy, destination_dataset, destination_table):
    twitter(config, {'auth': auth_write, 'secret': secret, 'key': key, 'trends': {'places': {'single_cell': True, 'bigquery': {'dataset': places_dataset, 'query': places_query, 'legacy': places_legacy}}}, 'out': {'bigquery': {'dataset': destination_dataset, 'table': destination_table}}})

Move using a WOEID query.

Args:
auth_write (authentication) - Credentials used for writing data.
secret (string) - NA
key (string) - NA
places_dataset (string) - NA
places_query (string) - NA
places_legacy (boolean) - NA
destination_dataset (string) - NA
destination_table (string) - NA


def index_sample(self, md5, index_name):

        generator = self.stream_sample(md5)
        for row in generator:
            self.indexer.index_data(row, index_name)

Index a stored sample with the Indexer.
Args:
md5: the md5 of the sample
index_name: the name of the index
Returns:
Nothing


def easeInOutElastic(n, amplitude=1, period=0.5):
    _checkRange(n)
    n *= 2
    if (n < 1):
        return (easeInElastic(n, amplitude=amplitude, period=period) / 2)
    else:
        return ((easeOutElastic((n - 1), amplitude=amplitude, period=period) / 2) + 0.5)

An elastic tween function wobbles towards the midpoint.

Args:
n (float): The time progress, starting at 0.0 and ending at 1.0.

Returns:
(float) The line progress, starting at 0.0 and ending at 1.0. Suitable for passing to getPointOnLine().


def _get_weights(max_length):

  weights = [1]
  for i in range(1, max_length):
    weights.append(weights[i-1] * len(_ALPHABET) + 1)
  weights.reverse()
  return weights

Get weights for each offset in str of certain max length.

Args:
max_length: max length of the strings.

Returns:
A list of ints as weights.

Example:
If max_length is 2 and alphabet is "ab", then we have order "", "a", "aa",
"ab", "b", "ba", "bb". So the weight for the first char is 3.


async def delete(
        self, name: str, *, force: bool = False, noprune: bool = False
    ) -> List:

        params = {"force": force, "noprune": noprune}
        response = await self.docker._query_json(
            "images/{name}".format(name=name), "DELETE", params=params
        )
        return response

Remove an image along with any untagged parent
images that were referenced by that image

Args:
name: name/id of the image to delete
force: remove the image even if it is being used
by stopped containers or has other tags
noprune: don't delete untagged parent images

Returns:
List of deleted images


def scrape(text, ptype=None):
    for (ruletype, rule, info) in scrape_types:
        if (ptype and (ptype != ruletype)):
            continue
        regx = regexes.get(ruletype)
        for valu in regx.findall(text):
            (yield (ruletype, valu))

Scrape types from a blob of text and return node tuples.

Args:
text (str): Text to scrape.
ptype (str): Optional ptype to scrape. If present, only scrape rules which match the provided type.

Returns:
(str, str): Yield tuples of type, valu strings.


def adjust_target_dtype(self, torch_dtype: 'torch.dtype') -> 'torch.dtype':
    return torch_dtype

Override this method if you want to adjust the `target_dtype` variable used in `from_pretrained`
to compute the device_map in case the device_map is a `str`. E.g. for bitsandbytes we force-set `target_dtype`
to `torch.int8` and for 4-bit we pass a custom enum `accelerate.CustomDtype.int4`.

Args:
torch_dtype (`torch.dtype`, *optional*):
The torch_dtype that is used to compute the device_map.


def get_oneformer_resize_output_image_size(image: np.ndarray, size: Union[int, Tuple[int, int], List[int], Tuple[int]], max_size: Optional[int]=None, default_to_square: bool=True, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> tuple:
    output_size = get_resize_output_image_size(input_image=image, size=size, default_to_square=default_to_square, max_size=max_size, input_data_format=input_data_format)
    return output_size

Computes the output size given the desired size.

Args:
image (`np.ndarray`):
The input image.
size (`int` or `Tuple[int, int]` or `List[int]` or `Tuple[int]`):
The size of the output image.
max_size (`int`, *optional*):
The maximum size of the output image.
default_to_square (`bool`, *optional*, defaults to `True`):
Whether to default to square if no size is provided.
input_data_format (`ChannelDimension` or `str`, *optional*):
The channel dimension format of the input image. If unset, will use the inferred format from the input.

Returns:
`Tuple[int, int]`: The output size.


def exec_iteration(self, counter, context, step_method):
    logger.debug('starting')
    context['whileCounter'] = counter
    logger.info(f'while: running step with counter {counter}')
    step_method(context)
    logger.debug(f'while: done step {counter}')
    result = False
    if self.stop:
        result = context.get_formatted_as_type(self.stop, out_type=bool)
    logger.debug('done')
    return result

Run a single loop iteration.

This method abides by the signature invoked by poll.while_until_true,
which is to say (counter, *args, **kwargs). In a normal execution
chain, this method's args passed by self.while_loop where context
and step_method set. while_until_true injects counter as a 1st arg.

Args:
counter. int. loop counter, which number of iteration is this.
context: (pypyr.context.Context) The pypyr context. This arg will
mutate - after method execution will contain the new
updated context.
step_method: (method/function) This is the method/function that
will execute on every loop iteration. Signature is:
function(context)

Returns:
bool. True if self.stop evaluates to True after step execution,
False otherwise.


def top_stories(self, raw=False, limit=None):
    top_stories = self._get_stories('topstories', limit)
    if raw:
        top_stories = [story.raw for story in top_stories]
    return top_stories

Returns list of item ids of current top stories

Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to represent all
objects in raw json.

Returns:
`list` object containing ids of top stories.


def import_laid_out_tensor(mesh, laid_out_tensor, shape, name=None):

  return ImportLaidOutTensorOperation(
      mesh, laid_out_tensor, convert_to_shape(shape), name=name).outputs[0]

Import a laid_out_tensor.

For expert users.
The input must be laid out appropriately given the eventual MeshImpl,
and layout.

Args:
mesh: a Mesh
laid_out_tensor: a LaidOutTensor
shape: a mtf.Shape
name: an optional string

Returns:
a mtf.Tensor


def validate(self):
    if (self.value is not None):
        if (type(self.value) not in six.integer_types):
            raise TypeError('expected (one of): {0}, observed: {1}'.format(six.integer_types, type(self.value)))
        elif (self.value > Interval.MAX):
            raise ValueError('interval value greater than accepted max')
        elif (self.value < Interval.MIN):
            raise ValueError('interval value less than accepted min')

Verify that the value of the Interval is valid.

Raises:
TypeError: if the value is not of type int or long
ValueError: if the value cannot be represented by an unsigned
32-bit integer


def compute_area_key(features, max_area_width, max_area_height=1, height=1, mode='mean', training=True, name=None):
    tf.logging.info('area_attention mode=%s', mode)
    (area_mean, area_std, _, area_heights, area_widths) = compute_area_features(features, max_area_width=max_area_width, max_area_height=max_area_height, height=height)
    if (mode == 'mean'):
        return area_mean
    elif (mode == 'max'):
        (area_max, _, _) = basic_pool(features, max_area_width=max_area_width, max_area_height=max_area_height, height=height)
        return area_max
    elif (mode == 'sample'):
        if training:
            area_mean += (area_std * tf.random_normal(tf.shape(area_std)))
        return area_mean
    with tf.variable_scope(name, default_name='combine_area_features', values=[area_mean, area_std, area_heights, area_widths]):
        depth = common_layers.shape_list(area_mean)[(- 1)]
        height_embed = tf.nn.embedding_lookup(params=tf.get_variable('area_height_emb', [max_area_height, (depth
        width_embed = tf.nn.embedding_lookup(params=tf.get_variable('area_width_emb', [max_area_width, (depth
        size_embed = tf.concat([height_embed, width_embed], (- 1))
        if (mode == 'concat'):
            feature_concat = tf.concat([area_mean, area_std, size_embed], (- 1))
        elif (mode == 'max_concat'):
            (area_max, _, _) = basic_pool(features, max_area_width=max_area_width, max_area_height=max_area_height, height=height)
            feature_concat = tf.concat([area_max, size_embed], (- 1))
        elif (mode == 'sum'):
            feature_concat = ((size_embed + area_mean) + area_std)
        elif (mode == 'sample_concat'):
            if training:
                area_mean += (area_std * tf.random_normal(tf.shape(area_std)))
            feature_concat = tf.concat([area_mean, size_embed], (- 1))
        elif (mode == 'sample_sum'):
            if training:
                area_mean += (area_std * tf.random_normal(tf.shape(area_std)))
            feature_concat = (area_mean + size_embed)
        else:
            raise ValueError(('Unsupported area key mode=%s' % mode))
        feature_hidden = tf.layers.dense(inputs=feature_concat, units=depth, activation=tf.nn.relu)
        area_key = tf.layers.dense(feature_hidden, units=depth)
        return area_key

Computes the key for each area.

Args:
features: a Tensor in a shape of [batch_size, height * width, depth].
max_area_width: the max width allowed for an area.
max_area_height: the max height allowed for an area.
height: the height of the image.
mode: whether to combine different area features or only use
the vector mean of each area, which can be "mean", "concat", "sum",
"sample_concat", and "sample_sum".
training: indicating if it is in the training mode.
name: the name for setting the variable scope.
Returns:
area_key: a Tensor in the shape of [batch_size, num_areas, depth]


def del_method(self, m):
    if (isinstance(m, types.FunctionType) and (not iscoroutinefunction(m))):
        wrkey = ('function', id(m))
    else:
        (f, obj) = get_method_vars(m)
        wrkey = (f, id(obj))
    if (wrkey in self):
        del self[wrkey]

Remove an instance method or function if it exists

Args:
m: The instance method or function to remove


def to_dict(self) -> dict[str, Any]:
    output = copy.deepcopy(self.__dict__)
    if hasattr(self.__class__, 'model_type'):
        output['model_type'] = self.__class__.model_type
    output['transformers_version'] = __version__
    for key, value in output.items():
        if isinstance(value, PretrainedConfig):
            value = value.to_dict()
            del value['transformers_version']
        output[key] = value
    self._remove_keys_not_serialized(output)
    if hasattr(self, 'quantization_config'):
        output['quantization_config'] = self.quantization_config.to_dict() if not isinstance(self.quantization_config, dict) else self.quantization_config
    self.dict_torch_dtype_to_str(output)
    return output

Serializes this instance to a Python dictionary.

Returns:
`Dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance.


class TFDebertaV2XSoftmax(keras.layers.Layer):

    def __init__(self, axis=-1, **kwargs):
        super().__init__(**kwargs)
        self.axis = axis

    def call(self, inputs: tf.Tensor, mask: tf.Tensor):
        rmask = tf.logical_not(tf.cast(mask, tf.bool))
        output = tf.where(rmask, tf.cast(float('-inf'), dtype=self.compute_dtype), inputs)
        output = stable_softmax(tf.cast(output, dtype=tf.float32), self.axis)
        output = tf.where(rmask, 0.0, output)
        return output

Masked Softmax which is optimized for saving memory

Args:
input (`tf.Tensor`): The input tensor that will apply softmax.
mask (`tf.Tensor`): The mask matrix where 0 indicate that element will be ignored in the softmax calculation.
dim (int): The dimension that will apply softmax


def _build_nccl_hybrid(input_tensors, red_op, upper_level_f):
    input_tensors, shape = _flatten_tensors(input_tensors)
    devices = [t.device for t in input_tensors]
    per_worker_devices, per_worker_values = _split_by_task(devices, input_tensors)
    num_workers = len(per_worker_devices)
    up_values = [None for w in range(0, num_workers)]
    up_devices = up_values[:]
    down_values = up_values[:]
    for w in range(0, num_workers):
        worker_values = build_nccl_all_reduce(per_worker_values[w], red_op)
        with ops.control_dependencies(worker_values):
            with ops.device(worker_values[0].device):
                up_values[w] = array_ops.identity(worker_values[0])
            up_devices[w] = per_worker_devices[w][0]
    level_2_output = upper_level_f(up_values)
    for w in range(0, num_workers):
        dst_tensors = []
        with ops.device(per_worker_devices[w][0]):
            broadcast_src = nccl_ops.broadcast(array_ops.identity(level_2_output[w]))
        for d in per_worker_devices[w]:
            with ops.device(d):
                dst_tensors.append(array_ops.identity(broadcast_src))
        down_values[w] = dst_tensors
    output_tensors = [v for sublist in down_values for v in sublist]
    if len(shape) != 1:
        output_tensors = _reshape_tensors(output_tensors, shape)
    return output_tensors

Construct a subgraph for NCCL hybrid all-reduce.

Args:
input_tensors: list of `tf.Tensor` of same-shape and type values to
be reduced.
red_op: binary elementwise reduction operator.
upper_level_f: function for reducing one value per worker, across
workers.

Returns:
list of `tf.Tensor` of reduced values.

Raises:
ValueError: inputs not well-formed.


def _unary_assert_doc(sym, sym_name):

    def _decorator(func):

        opname = func.__name__
        cap_sym_name = sym_name.capitalize()
        func.__doc__ = '\n    Assert the condition `x {sym}` holds element-wise.\n\n    When running in graph mode, you should add a dependency on this operation\n    to ensure that it runs. Example of adding a dependency to an operation:\n\n    ```python\n    with tf.control_dependencies([tf.debugging.{opname}(x, y)]):\n      output = tf.reduce_sum(x)\n    ```\n\n    {sym_name} means, for every element `x[i]` of `x`, we have `x[i] {sym}`.\n    If `x` is empty this is trivially satisfied.\n\n    Args:\n      x:  Numeric `Tensor`.\n      data:  The tensors to print out if the condition is False.  Defaults to\n        error message and first few entries of `x`.\n      summarize: Print this many entries of each tensor.\n      message: A string to prefix to the default message.\n      name: A name for this operation (optional).  Defaults to "{opname}".\n\n    Returns:\n      Op that raises `InvalidArgumentError` if `x {sym}` is False.\n      @compatibility(eager)\n        returns None\n      @end_compatibility\n\n    Raises:\n      InvalidArgumentError: if the check can be performed immediately and\n        `x {sym}` is False. The check can be performed immediately during\n        eager execution or if `x` is statically known.\n    '.format(sym=sym, sym_name=cap_sym_name, opname=opname)
        return func
    return _decorator

Common docstring for assert_* ops that evaluate a unary predicate over every element of a tensor.

Args:
sym: Mathematical symbol for the check performed on each element, i.e. "> 0"
sym_name: English-language name for the op described by sym

Returns:
Decorator that adds the appropriate docstring to the function for symbol
`sym`.


def get_tensor_mtf_dimension_names(self, tensor_name):
    tensor = self._name_to_tensor(tensor_name)
    if isinstance(tensor, mtf.Tensor):
        return tensor.shape.dimension_names
    else:
        return []

The Mesh TensorFlow dimensions associated with a tensor.

Args:
tensor_name: a string, name of a tensor in the graph.

Returns:
a [string], the names of Mesh TensorFlow dimensions.


def register_peer(self, connection_id, endpoint):
    with self._lock:
        if (len(self._peers) < self._maximum_peer_connectivity):
            self._peers[connection_id] = endpoint
            self._topology.set_connection_status(connection_id, PeerStatus.PEER)
            LOGGER.debug('Added connection_id %s with endpoint %s, connected identities are now %s', connection_id, endpoint, self._peers)
        else:
            raise PeeringException('At maximum configured number of peers: {} Rejecting peering request from {}.'.format(self._maximum_peer_connectivity, endpoint))
    public_key = self.peer_to_public_key(connection_id)
    if public_key:
        self._consensus_notifier.notify_peer_connected(public_key)

Registers a connected connection_id.

Args:
connection_id (str): A unique identifier which identifies an
connection on the network server socket.
endpoint (str): The publically reachable endpoint of the new
peer


def __init__(self, pfor: 'PFor', op: ops.Operation, inputs):
    self.pfor = pfor
    self._op = op
    self._inputs = inputs

Creates a _PforInput object.

Args:
pfor: PFor converter object.
op: the Operation object that is being converted.
inputs: list of WrappedTensor objects representing converted values of the
inputs of `op`.


def search_messages(self, *, query: str, **kwargs) -> SlackResponse:
    self._validate_xoxp_token()
    kwargs.update({'query': query})
    return self.api_call('search.messages', http_verb='GET', params=kwargs)

Searches for messages matching a query.

Args:
query (str): Search query. May contains booleans, etc.
e.g. 'pickleface'


def construct_end_message(self):
    app_count = self.dfk.task_count
    site_count = len([x for x in self.dfk.config.executors if x.managed])
    app_fails = len([t for t in self.dfk.tasks if (self.dfk.tasks[t]['status'] in FINAL_FAILURE_STATES)])
    message = {'uuid': self.uuid, 'end': time.time(), 't_apps': app_count, 'sites': site_count, 'c_time': None, 'failed': app_fails, 'test': self.test_mode}
    return json.dumps(message)

Collect the final run information at the time of DFK cleanup.

Returns:
- Message dict dumped as json string, ready for UDP


def bounded_trie(namespace: Union[Type, str], name: str) -> 'Metrics.DelegatingBoundedTrie':
    namespace = Metrics.get_namespace(namespace)
    return Metrics.DelegatingBoundedTrie(MetricName(namespace, name))

Obtains or creates a Bounded Trie metric.

Args:
namespace: A class or string that gives the namespace to a metric
name: A string that gives a unique name to a metric

Returns:
A BoundedTrie object.


def recode_sam_reads(sam_fn, fastq_rnf_fo, fai_fo, genome_id, number_of_read_tuples=(10 ** 9), simulator_name=None, allow_unmapped=False):
    fai_index = rnftools.utils.FaIdx(fai_fo)
    read_tuple_id_width = len(format(number_of_read_tuples, 'x'))
    fq_creator = rnftools.rnfformat.FqCreator(fastq_fo=fastq_rnf_fo, read_tuple_id_width=read_tuple_id_width, genome_id_width=2, chr_id_width=fai_index.chr_id_width, coor_width=fai_index.coor_width, info_reads_in_tuple=True, info_simulator=simulator_name)
    cigar_reg_shift = re.compile('([0-9]+)([MDNP=X])')
    reverse_complement_dict = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C', 'N': 'N'}
    read_tuple_id = 0
    last_read_tuple_name = None
    with pysam.AlignmentFile(sam_fn, check_header=False) as samfile:
        for alignment in samfile:
            if ((alignment.query_name != last_read_tuple_name) and (last_read_tuple_name is not None)):
                read_tuple_id += 1
            last_read_tuple_name = alignment.query_name
            if alignment.is_unmapped:
                rnftools.utils.error("SAM files used for conversion should not contain unaligned segments. This condition is broken by read tuple '{}' in file '{}'.".format(alignment.query_name, sam_fn), program='RNFtools', subprogram='MIShmash', exception=NotImplementedError)
            if alignment.is_reverse:
                direction = 'R'
                bases = ''.join([reverse_complement_dict[nucl] for nucl in alignment.seq[::(- 1)]])
                qualities = str(alignment.qual[::(- 1)])
            else:
                direction = 'F'
                bases = alignment.seq[:]
                qualities = str(alignment.qual[:])
            if (fai_index.dict_chr_ids != {}):
                chr_id = fai_index.dict_chr_ids[samfile.getrname(alignment.reference_id)]
            else:
                chr_id = '0'
            left = (int(alignment.reference_start) + 1)
            right = (left - 1)
            for (steps, operation) in cigar_reg_shift.findall(alignment.cigarstring):
                right += int(steps)
            segment = rnftools.rnfformat.Segment(genome_id=genome_id, chr_id=chr_id, direction=direction, left=left, right=right)
            fq_creator.add_read(read_tuple_id=read_tuple_id, bases=bases, qualities=qualities, segments=[segment])
    fq_creator.flush_read_tuple()

Transform a SAM file to RNF-compatible FASTQ.

Args:
sam_fn (str): SAM/BAM file - file name.
fastq_rnf_fo (str): Output FASTQ file - file object.
fai_fo (str): FAI index of the reference genome - file object.
genome_id (int): Genome ID for RNF.
number_of_read_tuples (int): Expected number of read tuples (to set width of read tuple id).
simulator_name (str): Name of the simulator. Used for comment in read tuple name.
allow_unmapped (bool): Allow unmapped reads.

Raises:
NotImplementedError


def name_scope(name):
    return ops.name_scope_v2(name)

A context manager for use when defining a Python op.

This context manager pushes a name scope, which will make the name of all
operations added within it have a prefix.

For example, to define a new Python op called `my_op`:

def my_op(a):
with tf.name_scope("MyOp") as scope:
a = tf.convert_to_tensor(a, name="a")
# Define some computation that uses `a`.
return foo_op(..., name=scope)

When executed, the Tensor `a` will have the name `MyOp/a`.

Args:
name: The prefix to use on all names created within the name scope.

Returns:
Name scope context manager.


def apply_step(self, variables, deltas):

        if len(variables) != len(deltas):
            raise TensorForceError("Invalid variables and deltas lists.")
        return tf.group(
            *(tf.assign_add(ref=variable, value=delta) for variable, delta in zip(variables, deltas))
        )

Applies the given (and already calculated) step deltas to the variable values.

Args:
variables: List of variables.
deltas: List of deltas of same length.

Returns:
The step-applied operation. A tf.group of tf.assign_add ops.


def cancelHistoricalData(self, bars: BarDataList):

        self.client.cancelHistoricalData(bars.reqId)
        self.wrapper.endSubscription(bars)

Cancel the update subscription for the historical bars.

Args:
bars: The bar list that was obtained from ``reqHistoricalData``
with a keepUpToDate subscription.


def find_all_hinted_output_nodes(session=None, graph_def=None):
    if session is not None and graph_def is not None:
        raise ValueError('Provide only one of session and graph_def.')
    hinted_outputs_nodes = []
    if session is not None:
        hints = _find_all_hints_in_nodes(session.graph_def.node)
    elif graph_def is not None:
        hints = _find_all_hints_in_nodes(graph_def.node)
    for hint in hints.values():
        _, output_nodes = hint.flattened_inputs_and_outputs()
        hinted_outputs_nodes.extend(output_nodes)
    return hinted_outputs_nodes

Find all Ophints output nodes in the graph.

This is used to get all the output nodes those are ophinted, it is important
for operation like convert_variables_to_constants keep all ophints structure.
Note: only one of session or graph_def should be used, not both.
Why this can be useful? Some TensorFlow ops (e.g. bidirectional rnn), can
generate multiple outputs for unfused subgraph. If not all output nodes are
consumed, graph optimization can potentially drop the unused nodes and cause
ophints in an invalid states (due to missing ophinted output nodes). So it's
important for us to find all those hinted output nodes and make sure they're
not discarded away.

Args:
session: A TensorFlow session that contains the graph to convert.
graph_def: A graph def that we should convert.

Returns:
A list of OpHints output nodes.
Raises:
ValueError: If both session and graph_def are provided.


def _ParseRegisteredDLLs(self, parser_mediator, registry_key):
    notify_key = registry_key.GetSubkeyByName('Notify')
    if (not notify_key):
        return
    for subkey in notify_key.GetSubkeys():
        for trigger in self._TRIGGERS:
            handler_value = subkey.GetValueByName(trigger)
            if (not handler_value):
                continue
            values_dict = {'Application': subkey.name, 'Handler': handler_value.GetDataAsObject(), 'Trigger': trigger}
            command_value = subkey.GetValueByName('DllName')
            if command_value:
                values_dict['Command'] = command_value.GetDataAsObject()
            event_data = windows_events.WindowsRegistryEventData()
            event_data.key_path = subkey.path
            event_data.offset = subkey.offset
            event_data.regvalue = values_dict
            event_data.source_append = ': Winlogon'
            event = time_events.DateTimeValuesEvent(subkey.last_written_time, definitions.TIME_DESCRIPTION_WRITTEN)
            parser_mediator.ProduceEventWithEventData(event, event_data)

Parses the registered DLLs that receive event notifications.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.


def alt40fms(msg):
    d = hex2bin(data(msg))
    if (d[13] == '0'):
        return None
    alt = (bin2int(d[14:26]) * 16)
    return alt

Selected altitude, FMS

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

Returns:
int: altitude in feet


def optimize(self, init_method='default', inference=None, n_times=10, perturb=False, pertSize=0.001, verbose=None):
    assert (init_method in ['default', 'random', None]), 'VarianceDecomposition: specified init_method not valid'
    if (init_method == 'default'):
        self._init_params_default()
    if ((init_method is not 'random') and (not perturb)):
        n_times = 1
    if (inference is None):
        inference = self._det_inference()
    else:
        self._check_inference(inference)
    self._inference = inference
    if (self.gp is None):
        self._initGP()
    params0 = self.gp.getParams()
    for i in range(n_times):
        if (init_method == 'random'):
            params = {'covar': sp.randn(params0['covar'].shape[0])}
            self.gp.setParams(params)
        elif perturb:
            params = {'covar': (params0['covar'] + (pertSize * sp.randn(params0['covar'].shape[0])))}
            self.gp.setParams(params)
        (conv, info) = self.gp.optimize()
        if conv:
            break
    if verbose:
        if (conv == False):
            print('No local minimum found for the tested initialization points')
        else:
            print(('Local minimum found at iteration %d' % i))
    return conv

Train the model using the specified initialization strategy

Args:
init_method:    initialization strategy:
'default': variance is equally split across the different random effect terms. For mulit-trait models the empirical covariance between traits is used
'random': variance component parameters (scales) are sampled from a normal distribution with mean 0 and std 1,
None: no initialization is considered. Initial parameters can be specifies by using the single covariance getTraitCovarfun()
inference:      inference gp method, by default algebrically efficient inference (i.e., gp2kronSum, gp2KronSumLR, gp3KronSumLR) will be used when possible.
For models with high a standard inference scheme (gp_base) will be used.
n_times:        number of restarts to converge
perturb:        if true, the initial point (if random initializaiton is not being used) is perturbed with gaussian noise for each restart (default, False)
perturbSize:    std of the gassian noise used to perturb the initial point
verbose:        print if convergence is achieved and how many restarted were needed


def docker_list(registry_pass):

    registry = conf.get('docker.registry', None)

    if registry is None:
        log.err("You must define docker.registry conf variable to list images")
        sys.exit(-1)

    registry_user = conf.get('docker.registry_user', None)

    if registry_user is None:
        registry_user = click.prompt("Username")

    rc = client.RegistryClient(registry, registry_user, registry_pass)
    images = {x: rc.list_tags(x) for x in rc.list_images()}

    shell.cprint("<32>Images in <34>{} <32>registry:", registry)
    for image, tags in images.items():
        shell.cprint('  <92>{}', image)
        for tag in tags:
            shell.cprint('      <90>{}:<35>{}', image, tag)

List docker images stored in the remote registry.

Args:
registry_pass (str):
Remote docker registry password.


def DownloadFile(file_obj, target_path, buffer_size=BUFFER_SIZE):

  logging.info(u"Downloading: %s to: %s", file_obj.urn, target_path)

  target_file = open(target_path, "wb")
  file_obj.Seek(0)
  count = 0

  data_buffer = file_obj.Read(buffer_size)
  while data_buffer:
    target_file.write(data_buffer)
    data_buffer = file_obj.Read(buffer_size)
    count += 1
    if not count % 3:
      logging.debug(u"Downloading: %s: %s done", file_obj.urn,
                    utils.FormatNumberAsString(count * buffer_size))
  target_file.close()

Download an aff4 file to the local filesystem overwriting it if it exists.

Args:
file_obj: An aff4 object that supports the file interface (Read, Seek)
target_path: Full path of file to write to.
buffer_size: Read in chunks this size.


def should_generate_summaries():
    name_scope = tf.contrib.framework.get_name_scope()
    if (name_scope and ('while/' in name_scope)):
        return False
    if tf.get_variable_scope().reuse:
        return False
    return True

Is this an appropriate context to generate summaries.

Returns:
a boolean


def _ifft(self, x):
    x_complex = _to_complex(x)
    return _IFFT_OP[self.block_depth](x_complex)

IFFT along the last self.block_depth dimensions of x.

Args:
x: `Tensor` with floating or complex dtype.  Should be in the form
returned by self._vectorize_then_blockify.

Returns:
`Tensor` with `dtype` `complex64`.


async def retry_create_artifact(*args, **kwargs):

    await retry_async(
        create_artifact,
        retry_exceptions=(
            ScriptWorkerRetryException,
            aiohttp.ClientError
        ),
        args=args,
        kwargs=kwargs
    )

Retry create_artifact() calls.

Args:
*args: the args to pass on to create_artifact
**kwargs: the args to pass on to create_artifact


def Read(f):

  try:
    yaml_data = yaml.load(f)
  except yaml.YAMLError as e:
    raise ParseError('%s' % e)
  except IOError as e:
    raise YAMLLoadError('%s' % e)

  _CheckData(yaml_data)

  try:
    return Config(
        yaml_data.get('blacklist', ()),
        yaml_data.get('whitelist', ('*')))
  except UnicodeDecodeError as e:
    raise YAMLLoadError('%s' % e)

Reads and returns Config data from a yaml file.

Args:
f: Yaml file to parse.

Returns:
Config object as defined in this file.

Raises:
Error (some subclass): If there is a problem loading or parsing the file.


def __init__(self, issuers_to_provider_ids, jwks_supplier, cache_capacity=200):

        self._issuers_to_provider_ids = issuers_to_provider_ids
        self._jwks_supplier = jwks_supplier

        arguments = {u"capacity": cache_capacity}
        expiration_time = datetime.timedelta(minutes=5)
        self._cache = cache.make_region().configure(u"lru_cache",
                                                    arguments=arguments,
                                                    expiration_time=expiration_time)

Construct an instance of AuthTokenDecoder.

Args:
issuers_to_provider_ids: a dictionary mapping from issuers to provider
IDs defined in the service configuration.
jwks_supplier: an instance of JwksSupplier that supplies JWKS based on
issuer.
cache_capacity: the cache_capacity with default value of 200.


def list_insights_components(access_token, subscription_id, resource_group):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/microsoft.insights/', '/components?api-version=', INSIGHTS_COMPONENTS_API])
    return do_get(endpoint, access_token)

List the Microsoft Insights components in a resource group.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.

Returns:
HTTP response. JSON body of components.


def get_dict_to_print(field_to_obs):

  def compressed_steps(steps):
    return {'num_steps': len(set(steps)),
            'min_step': min(steps),
            'max_step': max(steps),
            'last_step': steps[-1],
            'first_step': steps[0],
            'outoforder_steps': get_out_of_order(steps)}

  def full_steps(steps):
    return {'steps': steps, 'outoforder_steps': get_out_of_order(steps)}

  output = {}
  for field, observations in field_to_obs.items():
    if not observations:
      output[field] = None
      continue

    steps = [x['step'] for x in observations]
    if field in SHORT_FIELDS:
      output[field] = compressed_steps(steps)
    if field in LONG_FIELDS:
      output[field] = full_steps(steps)

  return output

Transform the field-to-obs mapping into a printable dictionary.

Args:
field_to_obs: Dict that maps string field to `Observation` list.

Returns:
A dict with the keys and values to print to console.


def get_metadata_as_dict(self, user_id=None, source=None):
    if ((self.metadata is None) or (self.metadata == '')):
        return {}
    metadata_dict = (self.metadata if isinstance(self.metadata, dict) else json.loads(self.metadata))
    metadata_keys = [m.lower() for m in metadata_dict]
    if ((user_id is not None) and ('user_id' not in metadata_keys)):
        metadata_dict['user_id'] = six.text_type(user_id)
    if ((source is not None) and ('source' not in metadata_keys)):
        metadata_dict['source'] = six.text_type(source)
    return {k: six.text_type(v) for (k, v) in metadata_dict.items()}

Convert a metadata json string into a dictionary.

Args:
user_id (int): Optional: Insert user_id into the metadata if specified
source (string): Optional: Insert source (the name of the app typically) into the metadata if necessary.

Returns:
dict: THe metadata as a python dictionary


def do_get_next(endpoint, access_token):
    headers = {'Authorization': ('Bearer ' + access_token)}
    headers['User-Agent'] = get_user_agent()
    looping = True
    value_list = []
    vm_dict = {}
    while looping:
        get_return = requests.get(endpoint, headers=headers).json()
        if (not ('value' in get_return)):
            return get_return
        if (not ('nextLink' in get_return)):
            looping = False
        else:
            endpoint = get_return['nextLink']
        value_list += get_return['value']
    vm_dict['value'] = value_list
    return vm_dict

Do an HTTP GET request, follow the nextLink chain and return JSON.

Args:
endpoint (str): Azure Resource Manager management endpoint.
access_token (str): A valid Azure authentication token.

Returns:
HTTP response. JSON body.