def delete(script, layer_num=None):

    filter_xml = '  <filter name="Delete Current Mesh"/>\n'
    if isinstance(script, mlx.FilterScript):
        if (layer_num is None) or (layer_num == script.current_layer()):
            util.write_filter(script, filter_xml)
            script.del_layer(script.current_layer())
        else:
            cur_layer = script.current_layer()
            change(script, layer_num)
            util.write_filter(script, filter_xml)
            if layer_num < script.current_layer():
                change(script, cur_layer - 1)
            else:
                change(script, cur_layer)
            script.del_layer(layer_num)
    else:
        util.write_filter(script, filter_xml)
    return None

Delete layer

Args:
script: the mlx.FilterScript object or script filename to write
the filter to.
layer_num (int): the number of the layer to delete. Default is the
current layer. Not supported on the file base API.

Layer stack:
Deletes a layer
will change current layer if deleted layer is lower in the stack

MeshLab versions:
2016.12
1.3.4BETA


def post_command(self, command, args):
    self._loop.log_coroutine(self.send_command(command, args, Verifier()))

Post a command asynchronously and don't wait for a response.

There is no notification of any error that could happen during
command execution.  A log message will be generated if an error
occurred.  The command's response is discarded.

This method is thread-safe and may be called from inside or ouside
of the background event loop.  If there is no websockets connection,
no error will be raised (though an error will be logged).

Args:
command (string): The command name
args (dict): Optional arguments


def change(script, layer_num=None):

    if layer_num is None:
        if isinstance(script, mlx.FilterScript):
            layer_num = script.last_layer()
        else:
            layer_num = 0
    filter_xml = ''.join([
        '  <filter name="Change the current layer">\n',
        '    <Param name="mesh" ',
        'value="{:d}" '.format(layer_num),
        'description="Mesh" ',
        'type="RichMesh" ',
        '/>\n',
        '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, mlx.FilterScript):
        script.set_current_layer(layer_num)

    return None

Change the current layer by specifying the new layer number.

Args:
script: the mlx.FilterScript object or script filename to write
the filter to.
layer_num (int): the number of the layer to change to. Default is the
last layer if script is a mlx.FilterScript object; if script is a
filename the default is the first layer.

Layer stack:
Modifies current layer

MeshLab versions:
2016.12
1.3.4BETA


def push(self, x):
    self._queue.append(x)

Adds a new value to the data window.

Args:
x: The value to be added to the window.


def _shuffle_single(fname, extra_fn=None):
    records = read_records(fname)
    random.shuffle(records)
    if (extra_fn is not None):
        records = extra_fn(records)
    out_fname = fname.replace(UNSHUFFLED_SUFFIX, '')
    write_records(records, out_fname)
    tf.gfile.Remove(fname)

Shuffle a single file of records.

Args:
fname: a string
extra_fn: an optional function from list of TFRecords to list of TFRecords
to be called after shuffling.


def poll(self, timeout=None):

        p = select.poll()
        p.register(self._fd, select.POLLIN | select.POLLPRI)
        events = p.poll(int(timeout * 1000))

        if len(events) > 0:
            return True

        return False

Poll for data available for reading from the serial port.

`timeout` can be positive for a timeout in seconds, 0 for a
non-blocking poll, or negative or None for a blocking poll. Default is
a blocking poll.

Args:
timeout (int, float, None): timeout duration in seconds.

Returns:
bool: ``True`` if data is available for reading from the serial port, ``False`` if not.


def update_variant_compounds(self, variant, variant_objs = None):

        compound_objs = []
        for compound in variant.get('compounds', []):
            not_loaded = True
            gene_objs = []

            if variant_objs:
                variant_obj = variant_objs.get(compound['variant'])
            else:
                variant_obj = self.variant_collection.find_one({'_id': compound['variant']})
            if variant_obj:

                not_loaded = False
                compound['rank_score'] = variant_obj['rank_score']
                for gene in variant_obj.get('genes', []):
                    gene_obj = {
                        'hgnc_id': gene['hgnc_id'],
                        'hgnc_symbol': gene.get('hgnc_symbol'),
                        'region_annotation': gene.get('region_annotation'),
                        'functional_annotation': gene.get('functional_annotation'),
                    }
                    gene_objs.append(gene_obj)
                    compound['genes'] = gene_objs

            compound['not_loaded'] = not_loaded
            compound_objs.append(compound)

        return compound_objs

Update compounds for a variant.

This will add all the necessary information of a variant on a compound object.

Args:
variant(scout.models.Variant)
variant_objs(dict): A dictionary with _ids as keys and variant objs as values.

Returns:
compound_objs(list(dict)): A dictionary with updated compound objects.


def einsum_vecmul_index(gate_indices, number_of_qubits):
    (mat_l, mat_r, tens_lin, tens_lout) = _einsum_matmul_index_helper(gate_indices, number_of_qubits)
    return ('{mat_l}{mat_r}, '.format(mat_l=mat_l, mat_r=mat_r) + '{tens_lin}->{tens_lout}'.format(tens_lin=tens_lin, tens_lout=tens_lout))

Return the index string for Numpy.eignsum matrix-vector multiplication.

The returned indices are to perform a matrix multiplication A.v where
the matrix A is an M-qubit matrix, vector v is an N-qubit vector, and
M <= N, and identity matrices are implied on the subsystems where A has no
support on v.

Args:
gate_indices (list[int]): the indices of the right matrix subsystems
to contract with the left matrix.
number_of_qubits (int): the total number of qubits for the right matrix.

Returns:
str: An indices string for the Numpy.einsum function.


def is_dsub_operation(op):

  if not is_pipeline(op):
    return False

  for name in ['dsub-version', 'job-id', 'job-name', 'user-id']:
    if not get_label(op, name):
      return False

  return True

Determine if a pipelines operation is a dsub request.

We don't have a rigorous way to identify an operation as being submitted
by dsub. Our best option is to check for certain fields that have always
been part of dsub operations.

- labels: job-id, job-name, and user-id have always existed. The dsub-version
label has always existed for the google-v2 provider.

Args:
op: a pipelines operation.

Returns:
Boolean, true if the pipeline run was generated by dsub.


def get_export_outputs(export_outputs, predictions):
    if export_outputs is None:
        default_output = export_output_lib.PredictOutput(predictions)
        export_outputs = {signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: default_output}
    if not isinstance(export_outputs, dict):
        raise TypeError('export_outputs must be dict, given: {}'.format(export_outputs))
    for v in export_outputs.values():
        if not isinstance(v, export_output_lib.ExportOutput):
            raise TypeError('Values in export_outputs must be ExportOutput objects. Given: {}'.format(export_outputs))
    _maybe_add_default_serving_output(export_outputs)
    return export_outputs

Validate export_outputs or create default export_outputs.

Args:
export_outputs: Describes the output signatures to be exported to
`SavedModel` and used during serving. Should be a dict or None.
predictions:  Predictions `Tensor` or dict of `Tensor`.

Returns:
Valid export_outputs dict

Raises:
TypeError: if export_outputs is not a dict or its values are not
ExportOutput instances.


def set_timer(self, num_secs):

        status = self.status()
        devices = status['dps']
        devices_numbers = list(devices.keys())
        devices_numbers.sort()
        dps_id = devices_numbers[-1]

        payload = self.generate_payload(SET, {dps_id:num_secs})

        data = self._send_receive(payload)
        log.debug('set_timer received data=%r', data)
        return data

Set a timer.

Args:
num_secs(int): Number of seconds


def plane_xz(size=(10, 10), resolution=(10, 10)) -> VAO:

    sx, sz = size
    rx, rz = resolution
    dx, dz = sx / rx, sz / rz
    ox, oz = -sx / 2, -sz / 2

    def gen_pos():
        for z in range(rz):
            for x in range(rx):
                yield ox + x * dx
                yield 0
                yield oz + z * dz

    def gen_uv():
        for z in range(rz):
            for x in range(rx):
                yield x / (rx - 1)
                yield 1 - z / (rz - 1)

    def gen_normal():
        for _ in range(rx * rz):
            yield 0.0
            yield 1.0
            yield 0.0

    def gen_index():
        for z in range(rz - 1):
            for x in range(rx - 1):

                yield z * rz + x + 1
                yield z * rz + x
                yield z * rz + x + rx

                yield z * rz + x + 1
                yield z * rz + x + rx
                yield z * rz + x + rx + 1

    pos_data = numpy.fromiter(gen_pos(), dtype=numpy.float32)
    uv_data = numpy.fromiter(gen_uv(), dtype=numpy.float32)
    normal_data = numpy.fromiter(gen_normal(), dtype=numpy.float32)
    index_data = numpy.fromiter(gen_index(), dtype=numpy.uint32)

    vao = VAO("plane_xz", mode=moderngl.TRIANGLES)

    vao.buffer(pos_data, '3f', ['in_position'])
    vao.buffer(uv_data, '2f', ['in_uv'])
    vao.buffer(normal_data, '3f', ['in_normal'])

    vao.index_buffer(index_data, index_element_size=4)

    return vao

Generates a plane on the xz axis of a specific size and resolution.
Normals and texture coordinates are also included.

Args:
size: (x, y) tuple
resolution: (x, y) tuple

Returns:
A :py:class:`demosys.opengl.vao.VAO` instance


def log2(x):
    if any_symbolic_tensors((x,)):
        return Log2().symbolic_call(x)
    return backend.numpy.log2(x)

Base-2 logarithm of `x`, element-wise.

Args:
x: Input tensor.

Returns:
Output tensor, element-wise base-2 logarithm of `x`.


def _ProcessEvent(self, mediator, event):
    try:
        self._analysis_plugin.ExamineEvent(mediator, event)
    except Exception as exception:
        self.SignalAbort()
        if self._debug_output:
            logger.warning('Unhandled exception while processing event object.')
            logger.exception(exception)

Processes an event.

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


def get_default_padding(self):
    high = ((1024 * 10) + (self.size
    low = (1024 + (self.size
    if (self.padding >= 0):
        if (self.padding > high):
            return low
        return self.padding
    else:
        return low

The default implementation which tries to select a reasonable
amount of padding and which might change in future versions.

Returns:
int: Amount of padding after saving


def get_definition_directive(self, node, directive, arg, default):
    defs = anno.getanno(node, anno.Static.ORIG_DEFINITIONS, ())
    if not defs:
        return default
    arg_values_found = []
    for def_ in defs:
        if directive in def_.directives and arg in def_.directives[directive]:
            arg_values_found.append(def_.directives[directive][arg])
    if not arg_values_found:
        return default
    if len(arg_values_found) == 1:
        return arg_values_found[0]
    first_value = arg_values_found[0]
    for other_value in arg_values_found[1:]:
        if not ast_util.matches(first_value, other_value):
            qn = anno.getanno(node, anno.Basic.QN)
            raise ValueError('%s has ambiguous annotations for %s(%s): %s, %s' % (qn, directive.__name__, arg, parser.unparse(other_value).strip(), parser.unparse(first_value).strip()))
    return first_value

Returns the unique directive argument for a symbol.

See lang/directives.py for details on directives.

Example:
# Given a directive in the code:
ag.foo_directive(bar, baz=1)

# One can write for an AST node Name(id='bar'):
get_definition_directive(node, ag.foo_directive, 'baz')

Args:
node: ast.AST, the node representing the symbol for which the directive
argument is needed.
directive: Callable[..., Any], the directive to search.
arg: str, the directive argument to return.
default: Any

Raises:
ValueError: if conflicting annotations have been found


def integers(start, count):

    if count < 0:
        raise ValueError("integers() count cannot be negative")
    return query(irange(start, start + count))

Generates in sequence the integral numbers within a range.

Note: This method uses deferred execution.

Args:
start: The first integer in the sequence.
count: The number of sequential integers to generate.

Returns:
A Queryable over the specified range of integers.

Raises:
ValueError: If count is negative.


def find(self, id):

        url = "{}/{}/{}".format(__endpoint__, self.type.RESOURCE, id)
        response = RestClient.get(url)[self.type.RESOURCE[:-1]]
        return self.type(response)

Get a resource by its id

Args:
id (string): Resource id
Returns:
object: Instance of the resource type


def call(self, inputs, **kwargs):
    return inputs

This is where the layer's logic lives.

Args:
inputs: Input tensor, or list/tuple of input tensors.
**kwargs: Additional keyword arguments.

Returns:
A tensor or list/tuple of tensors.


def status(self, job_ids):

        if job_ids:
            self._status()
        return [self.resources[jid]['status'] for jid in job_ids]

Get the status of a list of jobs identified by the job identifiers
returned from the submit request.

Args:
- job_ids (list) : A list of job identifiers

Returns:
- A list of status from ['PENDING', 'RUNNING', 'CANCELLED', 'COMPLETED',
'FAILED', 'TIMEOUT'] corresponding to each job_id in the job_ids list.

Raises:
- ExecutionProviderException or its subclasses


def verify_abort(func, *args, **kwargs):

    expected_exception = kwargs.pop("expected_exception", runez.system.AbortException)
    with CaptureOutput() as logged:
        try:
            value = func(*args, **kwargs)
            assert False, "%s did not raise, but returned %s" % (func, value)

        except expected_exception:
            return str(logged)

Convenient wrapper around functions that should exit or raise an exception

Example:
assert "Can't create folder" in verify_abort(ensure_folder, "/dev/null/not-there")

Args:
func (callable): Function to execute
*args: Args to pass to 'func'
**kwargs: Named args to pass to 'func'

Returns:
(str): Chatter from call to 'func', if it did indeed raise


def prepare_background_data(self):
    self.background_data = []
    background_dir = os.path.join(self.data_dir, BACKGROUND_NOISE_DIR_NAME)
    if not gfile.Exists(background_dir):
        return self.background_data
    with tf.compat.v1.Session(graph=tf.Graph()) as sess:
        wav_filename_placeholder = tf.compat.v1.placeholder(tf.string, [])
        wav_loader = io_ops.read_file(wav_filename_placeholder)
        wav_decoder = tf.audio.decode_wav(wav_loader, desired_channels=1)
        search_path = os.path.join(self.data_dir, BACKGROUND_NOISE_DIR_NAME, '*.wav')
        for wav_path in gfile.Glob(search_path):
            wav_data = sess.run(wav_decoder, feed_dict={wav_filename_placeholder: wav_path}).audio.flatten()
            self.background_data.append(wav_data)
        if not self.background_data:
            raise Exception('No background wav files were found in ' + search_path)

Searches a folder for background noise audio, and loads it into memory.

It's expected that the background audio samples will be in a subdirectory
named '_background_noise_' inside the 'data_dir' folder, as .wavs that match
the sample rate of the training data, but can be much longer in duration.

If the '_background_noise_' folder doesn't exist at all, this isn't an
error, it's just taken to mean that no background noise augmentation should
be used. If the folder does exist, but it's empty, that's treated as an
error.

Returns:
List of raw PCM-encoded audio samples of background noise.

Raises:
Exception: If files aren't found in the folder.


def load_file_to_str(path):
    with open(path, 'rt') as f:
        string = f.read().replace(linesep, '')
    if (not string):
        raise LoadError(('%s file is empty!' % path))
    return string

Load file into a string removing newlines

Args:
path (str): Path to file

Returns:
str: String contents of file


def sort_dependencies(self, image, dependencies=None):
    if (dependencies is None):
        dependencies = OrderedDict()
    if (image in dependencies):
        return
    requires = self.ymldefs[image].get('requires', [])
    for dep in requires:
        self.sort_dependencies(dep, dependencies)
    dependencies[image] = None
    return dependencies.keys()

Topologically sort the docker commands by their requirements

Note:
Circular "requires" dependencies are assumed to have already been checked in
get_external_base_image, they are not checked here

Args:
image (str): process this docker image's dependencies
dependencies (OrderedDict): running cache of sorted dependencies (ordered dict)

Returns:
List[str]: list of dependencies a topologically-sorted build order


def histogram(self, tag, values, bins, step=None):
    if (step is None):
        step = self._step
    else:
        self._step = step
    values = onp.array(values)
    bins = onp.array(bins)
    values = onp.reshape(values, (- 1))
    (counts, limits) = onp.histogram(values, bins=bins)
    cum_counts = onp.cumsum(onp.greater(counts, 0, dtype=onp.int32))
    (start, end) = onp.searchsorted(cum_counts, [0, (cum_counts[(- 1)] - 1)], side='right')
    (start, end) = (int(start), (int(end) + 1))
    counts = (counts[(start - 1):end] if (start > 0) else onp.concatenate([[0], counts[:end]]))
    limits = limits[start:(end + 1)]
    sum_sq = values.dot(values)
    histo = HistogramProto(min=values.min(), max=values.max(), num=len(values), sum=values.sum(), sum_squares=sum_sq, bucket_limit=limits.tolist(), bucket=counts.tolist())
    summary = Summary(value=[Summary.Value(tag=tag, histo=histo)])
    self.add_summary(summary, step)

Saves histogram of values.

Args:
tag: str: label for this data
values: ndarray: will be flattened by this routine
bins: number of bins in histogram, or array of bins for onp.histogram
step: int: training step


def __replaceSpecialValues(self, decisions):
    error = []
    for (row, line) in enumerate(decisions):
        if ('.' in line):
            for (i, element) in enumerate(line):
                if (row == 0):
                    error.append("Row: {}colume: {}==> don't have parent value".format(str(row).ljust(4), str(i).ljust(4)))
                if (element == self.__parentSymbol):
                    if (decisions[(row - 1)][i] == '.'):
                        error.append("Row: {}Colume: {}==> don't have parent value".format(str(row).ljust(4), str(i).ljust(4)))
                    decisions[row][i] = decisions[(row - 1)][i]
    if error:
        view.Tli.showErrors('ReplaceSpecialValuesError', error)
    else:
        return decisions

Will replace special values in decisions array.

Args:
decisions (array of array of str): Standard decision array format.
Raises:
ValueError: Row element don't have parent value.

Returns:
New decision array with updated values.


def iter_archive(self, resource):

    if isinstance(resource, six.string_types):
      resource = resource_lib.Resource(path=resource)
    return extractor.iter_archive(resource.path, resource.extract_method)

Returns iterator over files within archive.

**Important Note**: caller should read files as they are yielded.
Reading out of order is slow.

Args:
resource: path to archive or `tfds.download.Resource`.

Returns:
Generator yielding tuple (path_within_archive, file_obj).


def _flatten_tensors(tensors):
    if not tensors:
        raise ValueError('tensors cannot be empty')
    shape = tensors[0].shape
    for tensor in tensors:
        shape = shape.merge_with(tensor.shape)
    if not shape.is_fully_defined():
        raise ValueError('Tensors must have statically known shape.')
    if len(shape) != 1:
        reshaped = []
        for t in tensors:
            with ops.colocate_with(t):
                reshaped.append(array_ops.reshape(t, [-1]))
        tensors = reshaped
    return (tensors, shape)

Check tensors for isomorphism and flatten.

Args:
tensors: list of `tf.Tensor` which must all have the same shape.

Returns:
tensors: a list of `tf.Tensor` which are flattened (1D) views of tensors
shape: the original shape of each element of input tensors

Raises:
ValueError: tensors are empty or non-isomorphic or have unknown shape.


def get_kerberos_ticket(username, password):
    cache = ('/tmp/ion-%s' % uuid.uuid4())
    logger.debug("Setting KRB5CCNAME to 'FILE:{}'".format(cache))
    os.environ['KRB5CCNAME'] = ('FILE:' + cache)
    try:
        realm = settings.CSL_REALM
        kinit = pexpect.spawnu('/usr/bin/kinit {}@{}'.format(username, realm), timeout=settings.KINIT_TIMEOUT)
        kinit.expect(':')
        kinit.sendline(password)
        returned = kinit.expect([pexpect.EOF, 'password:'])
        if (returned == 1):
            logger.debug('Password for {}@{} expired, needs reset'.format(username, realm))
            return 'reset'
        kinit.close()
        exitstatus = kinit.exitstatus
    except pexpect.TIMEOUT:
        KerberosAuthenticationBackend.kinit_timeout_handle(username, realm)
        exitstatus = 1
    if (exitstatus != 0):
        try:
            realm = settings.AD_REALM
            kinit = pexpect.spawnu('/usr/bin/kinit {}@{}'.format(username, realm), timeout=settings.KINIT_TIMEOUT)
            kinit.expect(':')
            kinit.sendline(password)
            returned = kinit.expect([pexpect.EOF, 'password:'])
            if (returned == 1):
                return False
            kinit.close()
            exitstatus = kinit.exitstatus
        except pexpect.TIMEOUT:
            KerberosAuthenticationBackend.kinit_timeout_handle(username, realm)
            exitstatus = 1
    if ('KRB5CCNAME' in os.environ):
        subprocess.check_call(['kdestroy', '-c', os.environ['KRB5CCNAME']])
        del os.environ['KRB5CCNAME']
    if (exitstatus == 0):
        logger.debug('Kerberos authorized {}@{}'.format(username, realm))
        return True
    else:
        logger.debug('Kerberos failed to authorize {}'.format(username))
        return False

Attempts to create a Kerberos ticket for a user.

Args:
username
The username.
password
The password.

Returns:
Boolean indicating success or failure of ticket creation


def post_process(self, dir_name, d):
    logger.info('Post-processing dir:{}'.format(dir_name))
    fullpath = os.path.abspath(dir_name)
    transformations = {}
    filenames = glob.glob(os.path.join(fullpath, 'transformations.json*'))
    if (len(filenames) >= 1):
        with zopen(filenames[0], 'rt') as f:
            transformations = json.load(f)
            try:
                m = re.match('(\\d+)-ICSD', transformations['history'][0]['source'])
                if m:
                    d['icsd_id'] = int(m.group(1))
            except Exception as ex:
                logger.warning('Cannot parse ICSD from transformations file.')
                pass
    else:
        logger.warning('Transformations file does not exist.')
    other_parameters = transformations.get('other_parameters')
    new_tags = None
    if other_parameters:
        new_tags = other_parameters.pop('tags', None)
        new_author = other_parameters.pop('author', None)
        if new_author:
            d['author'] = new_author
        if (not other_parameters):
            transformations.pop('other_parameters')
    d['transformations'] = transformations
    filenames = glob.glob(os.path.join(fullpath, 'custodian.json*'))
    if (len(filenames) >= 1):
        with zopen(filenames[0], 'rt') as f:
            d['custodian'] = json.load(f)
    try:
        run_stats = {}
        for filename in glob.glob(os.path.join(fullpath, 'OUTCAR*')):
            outcar = Outcar(filename)
            i = (1 if re.search('relax2', filename) else 0)
            taskname = ('relax2' if re.search('relax2', filename) else 'relax1')
            d['calculations'][i]['output']['outcar'] = outcar.as_dict()
            run_stats[taskname] = outcar.run_stats
    except:
        logger.error('Bad OUTCAR for {}.'.format(fullpath))
    try:
        overall_run_stats = {}
        for key in ['Total CPU time used (sec)', 'User time (sec)', 'System time (sec)', 'Elapsed time (sec)']:
            overall_run_stats[key] = sum([v[key] for v in run_stats.values()])
        run_stats['overall'] = overall_run_stats
    except:
        logger.error('Bad run stats for {}.'.format(fullpath))
    d['run_stats'] = run_stats
    if self.use_full_uri:
        d['dir_name'] = get_uri(dir_name)
    if new_tags:
        d['tags'] = new_tags
    logger.info(('Post-processed ' + fullpath))

Simple post-processing for various files other than the vasprun.xml.
Called by generate_task_doc. Modify this if your runs have other
kinds of processing requirements.

Args:
dir_name:
The dir_name.
d:
Current doc generated.


def argsort(*args, **kwargs):
    if ((len(args) == 1) and isinstance(args[0], dict)):
        dict_ = args[0]
        index_list = list(dict_.keys())
        value_list = list(dict_.values())
        return sortedby2(index_list, value_list)
    else:
        index_list = list(range(len(args[0])))
        return sortedby2(index_list, *args, **kwargs)

like np.argsort but for lists

Args:
*args: multiple lists to sort by
**kwargs:
reverse (bool): sort order is descending if True else acscending

CommandLine:
python -m utool.util_list argsort

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_list import *  # NOQA
>>> result = ut.argsort({'a': 3, 'b': 2, 'c': 100})
>>> print(result)


def items(self, prefix=None, delimiter=None):
    return _item.Items(self._name, prefix, delimiter, context=self._context)

Get an iterator for the items within this bucket.

Args:
prefix: an optional prefix to match items.
delimiter: an optional string to simulate directory-like semantics. The returned items
will be those whose names do not contain the delimiter after the prefix. For
the remaining items, the names will be returned truncated after the delimiter
with duplicates removed (i.e. as pseudo-directories).
Returns:
An iterable list of items within this bucket.


def add_primitives_path(path):
    if (path not in _PRIMITIVES_PATHS):
        if (not os.path.isdir(path)):
            raise ValueError('Invalid path: {}'.format(path))
        LOGGER.debug('Adding new primitives path %s', path)
        _PRIMITIVES_PATHS.insert(0, os.path.abspath(path))

Add a new path to look for primitives.

The new path will be inserted in the first place of the list,
so any primitive found in this new folder will take precedence
over any other primitive with the same name that existed in the
system before.

Args:
path (str): path to add

Raises:
ValueError: A `ValueError` will be raised if the path is not valid.


def zero_state(self, batch_size, dtype):
    state_size = self.state_size
    is_eager = context.executing_eagerly()
    if is_eager and _hasattr(self, '_last_zero_state'):
        last_state_size, last_batch_size, last_dtype, last_output = getattr(self, '_last_zero_state')
        if last_batch_size == batch_size and last_dtype == dtype and (last_state_size == state_size):
            return last_output
    with backend.name_scope(type(self).__name__ + 'ZeroState'):
        output = _zero_state_tensors(state_size, batch_size, dtype)
    if is_eager:
        self._last_zero_state = (state_size, batch_size, dtype, output)
    return output

Return zero-filled state tensor(s).

Args:
batch_size: int, float, or unit Tensor representing the batch size.
dtype: the data type to use for the state.

Returns:
If `state_size` is an int or TensorShape, then the return value is a
`N-D` tensor of shape `[batch_size, state_size]` filled with zeros.

If `state_size` is a nested list or tuple, then the return value is
a nested list or tuple (of the same structure) of `2-D` tensors with
the shapes `[batch_size, s]` for each s in `state_size`.


def clean_headers(headers):
    clean = {}
    try:
        for (k, v) in six.iteritems(headers):
            if (not isinstance(k, six.binary_type)):
                k = str(k)
            if (not isinstance(v, six.binary_type)):
                v = str(v)
            clean[_helpers._to_bytes(k)] = _helpers._to_bytes(v)
    except UnicodeEncodeError:
        from oauth2client.client import NonAsciiHeaderError
        raise NonAsciiHeaderError(k, ': ', v)
    return clean

Forces header keys and values to be strings, i.e not unicode.

The httplib module just concats the header keys and values in a way that
may make the message header a unicode string, which, if it then tries to
contatenate to a binary request body may result in a unicode decode error.

Args:
headers: dict, A dictionary of headers.

Returns:
The same dictionary but with all the keys converted to strings.


def _get_linear_trajectory(x0, velocity, t):
    x0 = tf.convert_to_tensor(x0)
    velocity = tf.convert_to_tensor(velocity)
    t = tf.convert_to_tensor(t)
    if (x0.shape.ndims != 1):
        raise ValueError('x0 must be a rank 1 tensor')
    if (velocity.shape.ndims != 1):
        raise ValueError('velocity must be a rank 1 tensor')
    if (t.shape.ndims != 1):
        raise ValueError('t must be a rank 1 tensor')
    x0 = tf.expand_dims(x0, axis=0)
    velocity = tf.expand_dims(velocity, axis=0)
    dx = (velocity * tf.expand_dims(t, axis=(- 1)))
    linear_trajectories = (x0 + dx)
    assert (linear_trajectories.shape.ndims == 2), 'linear_trajectories should be a rank 2 tensor'
    return linear_trajectories

Construct a linear trajectory from x0.

Args:
x0: N-D float tensor.
velocity: N-D float tensor
t: [sequence_length]-length float tensor

Returns:
x: [sequence_length, ndims] float tensor.


def get_item(self, *key):

        item = self._get_item_or_section(key)
        if not item.is_item:
            raise RuntimeError('{} is a section, not an item'.format(key))
        return item

The recommended way of retrieving an item by key when extending configmanager's behaviour.
Attribute and dictionary key access is configurable and may not always return items
(see PlainConfig for example), whereas this method will always return the corresponding
Item as long as NOT_FOUND hook callbacks don't break this convention.

Args:
*key

Returns:
item (:class:`.Item`):


def export_msdt(self, filename):
    fmt = ('csv' if filename.lower().endswith('.csv') else 'dat')
    delimiter = (', ' if (fmt == 'csv') else ' ')
    with open(filename, 'wt') as f:
        if (fmt == 'dat'):
            f.write('
        f.write(delimiter.join(['t', 'MSD', 'MSD_a', 'MSD_b', 'MSD_c', 'MSCD']))
        f.write('\n')
        for (dt, msd, msdc, mscd) in zip(self.dt, self.msd, self.msd_components, self.mscd):
            f.write(delimiter.join([('%s' % v) for v in (([dt, msd] + list(msdc)) + [mscd])]))
            f.write('\n')

Writes MSD data to a csv file that can be easily plotted in other
software.

Args:
filename (str): Filename. Supported formats are csv and dat. If
the extension is csv, a csv file is written. Otherwise,
a dat format is assumed.


def convert_to_shape(x):
    if (x is None):
        return None
    if isinstance(x, Shape):
        return x
    if isinstance(x, str):
        x = _parse_string_to_list_of_pairs(x, seconds_to_int=True)
    return Shape(x)

Converts input to a Shape.

Args:
x: Shape, str, or None.

Returns:
Shape or None.

Raises:
ValueError: If x cannot be converted to a Shape.


def _ReduceParserFilters(cls, includes, excludes):
    if ((not includes) or (not excludes)):
        return
    for parser_name in set(includes).intersection(excludes):
        if (includes[parser_name] == excludes[parser_name]):
            logger.warning('Parser {0:s} was in both the inclusion and exclusion lists. Ignoring included parser.'.format(parser_name))
            includes.pop(parser_name)
            continue
        plugin_includes = includes[parser_name]
        plugin_excludes = excludes[parser_name]
        intersection = set(plugin_includes).intersection(plugin_excludes)
        if (not intersection):
            continue
        logger.warning('Parser {0:s} plugins: {1:s} in both the inclusion and exclusion lists. Ignoring included plugins.'.format(parser_name, ', '.join(intersection)))
        plugins_list = list(set(plugin_includes).difference(intersection))
        includes[parser_name] = plugins_list
    parsers_to_pop = []
    for parser_name in excludes:
        if (parser_name in includes):
            continue
        logger.warning('The excluded parser: {0:s} is not associated with the included parsers: {1:s}. Ignoring excluded parser.'.format(parser_name, ', '.join(includes.keys())))
        parsers_to_pop.append(parser_name)
    for parser_name in parsers_to_pop:
        excludes.pop(parser_name)

Reduces the parsers and plugins to include and exclude.

If an intersection is found, the parser or plugin is removed from
the inclusion set. If a parser is not in inclusion set there is no need
to have it in the exclusion set.

Args:
includes (dict[str, BaseParser]): included parsers and plugins by name.
excludes (dict[str, BaseParser]): excluded parsers and plugins by name.


def playback_trajectory(env, ep_dir):

    xml_path = os.path.join(ep_dir, "model.xml")
    with open(xml_path, "r") as f:
        env.reset_from_xml_string(f.read())

    state_paths = os.path.join(ep_dir, "state_*.npz")

    t = 0
    for state_file in sorted(glob(state_paths)):
        print(state_file)
        dic = np.load(state_file)
        states = dic["states"]
        for state in states:
            env.sim.set_state_from_flattened(state)
            env.sim.forward()
            env.render()
            t += 1
            if t % 100 == 0:
                print(t)

Playback data from an episode.

Args:
ep_dir: The path to the directory containing data for an episode.


def remove_node(self, node_id, force=False):
    url = self._url('/nodes/{0}', node_id)
    params = {'force': force}
    res = self._delete(url, params=params)
    self._raise_for_status(res)
    return True

Remove a node from the swarm.

Args:
node_id (string): ID of the node to be removed.
force (bool): Force remove an active node. Default: `False`

Raises:
:py:class:`docker.errors.NotFound`
If the node referenced doesn't exist in the swarm.

:py:class:`docker.errors.APIError`
If the server returns an error.
Returns:
`True` if the request was successful.


def from_dict(d):

        i = Tags()
        for k, v in d.items():
            if k not in ("@module", "@class"):
                i[k] = v
        return i

Creates Tags object from a dictionary.

Args:
d: Dict of feff parameters and values.

Returns:
Tags object


def _get_ngram_counter(ids, n):
    ids = [token_id for token_id in ids if (token_id != 0)]
    ngram_list = [tuple(ids[i:(i + n)]) for i in range(((len(ids) + 1) - n))]
    ngrams = set(ngram_list)
    counts = collections.Counter()
    for ngram in ngrams:
        counts[ngram] = 1
    return counts

Get a Counter with the ngrams of the given ID list.

Args:
ids: np.array or a list corresponding to a single sentence
n: n-gram size

Returns:
collections.Counter with ID tuples as keys and 1s as values.


def first(self):

    def _transform(xs):
        try:
            return [six.next(iter(xs))]
        except StopIteration:
            return []
    return self.transform(_transform, 'first')

Return a Query that selects only the first element of this Query.
If no elements are available, returns a query with no results.

Example usage:

.. code:: python

>> q = Query(lambda: list(range(5)))
>> q.first.results
[0]

Returns:
Query


def _define_loop(graph, eval_steps):

  loop = tools.Loop(
      None, graph.step, graph.should_log, graph.do_report, graph.force_reset)
  loop.add_phase(
      'eval', graph.done, graph.score, graph.summary, eval_steps,
      report_every=eval_steps,
      log_every=None,
      checkpoint_every=None,
      feed={graph.is_training: False})
  return loop

Create and configure an evaluation loop.

Args:
graph: Object providing graph elements via attributes.
eval_steps: Number of evaluation steps per epoch.

Returns:
Loop object.


def option(self, key, value=None, **kwargs):
    if (not isinstance(self._container, Section)):
        raise ValueError('Options can only be added inside a section!')
    option = Option(key, value, container=self._container, **kwargs)
    option.value = value
    self._container.structure.insert(self._idx, option)
    self._idx += 1
    return self

Creates a new option inside a section

Args:
key (str): key of the option
value (str or None): value of the option
**kwargs: are passed to the constructor of :class:`Option`

Returns:
self for chaining


def _reraise_with_traceback(f):

    def wrap(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except Exception as e:
            traceback_str = traceback.format_exc()
            e.traceback = traceback_str
            raise e

    return wrap

Call the function normally. But if the function raises an error, attach the str(traceback)
into the function.traceback attribute, then reraise the error.
Args:
f: The function to run.

Returns: A function that wraps f, attaching the traceback if an error occurred.


def diff_commonPrefix(self, text1, text2):

    if not text1 or not text2 or text1[0] != text2[0]:
      return 0

    pointermin = 0
    pointermax = min(len(text1), len(text2))
    pointermid = pointermax
    pointerstart = 0
    while pointermin < pointermid:
      if text1[pointerstart:pointermid] == text2[pointerstart:pointermid]:
        pointermin = pointermid
        pointerstart = pointermin
      else:
        pointermax = pointermid
      pointermid = (pointermax - pointermin)
    return pointermid

Determine the common prefix of two strings.

Args:
text1: First string.
text2: Second string.

Returns:
The number of characters common to the start of each string.


def postprocess_image(x, rows, cols, hparams):
    batch = common_layers.shape_list(x)[0]
    x = tf.reshape(x, [batch, rows, cols, hparams.hidden_size])
    likelihood = getattr(hparams, 'likelihood', DistributionType.CAT)
    if (likelihood == DistributionType.DMOL):
        depth = (hparams.num_mixtures * 10)
        targets = tf.layers.dense(x, depth, use_bias=False, activation=None, name='output_conv')
    else:
        depth = 256
        targets = tf.layers.dense(x, depth, use_bias=True, activation=None, name='output_conv')
    if ((hparams.mode == tf.estimator.ModeKeys.PREDICT) and hparams.block_raster_scan):
        y = targets
        yshape = common_layers.shape_list(y)
        block_length = hparams.query_shape[0]
        block_width = hparams.query_shape[1]
        y = tf.reshape(y, [batch, (yshape[1]
        yshape = common_layers.shape_list(y)
        y_blocks = tf.reshape(y, [batch, yshape[1], yshape[2], (yshape[3]
        targets = tf.transpose(y_blocks, [0, 1, 3, 2, 4, 5])
    return targets

Postprocessing after decoding.

Args:
x: Tensor of shape [batch, ...], where ... can be any rank such that the
number of elements in x is batch * rows * cols * hparams.hidden_size.
rows: Integer representing number of rows in a 2-D data point.
cols: Integer representing number of columns in a 2-D data point.
hparams: HParams set.

Returns:
Tensor of shape [batch, rows, cols, depth], where depth is
hparams.num_mixtures * 10 if hparams.likelihood is DMOL, otherwise 256. In
the special case of inference and block raster scan order, it is a Tensor
of shape [batch, num_blocks_rows, num_block_cols, block_length, block_width,
depth].


def enable(self, information, id_or_uri, timeout=(- 1)):
    uri = self._client.build_uri(id_or_uri)
    return self._client.update(information, uri, timeout=timeout)

Enables or disables a range.

Args:
information (dict): Information to update.
id_or_uri: ID or URI of range.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: Updated resource.


def cosine_similarity(y_true, y_pred, axis=-1):
    y_pred = ops.convert_to_tensor(y_pred)
    y_true = ops.convert_to_tensor(y_true, dtype=y_pred.dtype)
    y_true, y_pred = squeeze_or_expand_to_same_rank(y_true, y_pred)
    y_pred = normalize(y_pred, axis=axis)
    y_true = normalize(y_true, axis=axis)
    return ops.sum(y_true * y_pred, axis=axis)

Computes the cosine similarity between labels and predictions.

Formula:

```python
loss = sum(l2_norm(y_true) * l2_norm(y_pred))
```

Args:
y_true: Tensor of true targets.
y_pred: Tensor of predicted targets.
axis: Axis along which to determine similarity. Defaults to `-1`.

Returns:
Cosine similarity tensor.

Example:

>>> y_true = [[0., 1.], [1., 1.], [1., 1.]]
>>> y_pred = [[1., 0.], [1., 1.], [-1., -1.]]
>>> loss = keras.losses.cosine_similarity(y_true, y_pred, axis=-1)
[0., 0.99999994, -0.99999994]


def read(self, viewport=None, components=3, *, attachment=0, alignment=1, dtype='f1') -> bytes:
    return self.mglo.read(viewport, components, attachment, alignment, dtype)

Read the content of the framebuffer.

Args:
viewport (tuple): The viewport.
components (int): The number of components to read.

Keyword Args:
attachment (int): The color attachment.
alignment (int): The byte alignment of the pixels.
dtype (str): Data type.

Returns:
bytes


def get_outputs_filtered(self, owner, spent=None):

        outputs = self.fastquery.get_outputs_by_public_key(owner)
        if spent is None:
            return outputs
        elif spent is True:
            return self.fastquery.filter_unspent_outputs(outputs)
        elif spent is False:
            return self.fastquery.filter_spent_outputs(outputs)

Get a list of output links filtered on some criteria

Args:
owner (str): base58 encoded public_key.
spent (bool): If ``True`` return only the spent outputs. If
``False`` return only unspent outputs. If spent is
not specified (``None``) return all outputs.

Returns:
:obj:`list` of TransactionLink: list of ``txid`` s and ``output`` s
pointing to another transaction's condition


def convert_to_tensors(self, tensor_type: Optional[Union[str, TensorType]]=None):
    if tensor_type is None:
        return self
    is_tensor, as_tensor = self._get_is_as_tensor_fns(tensor_type)
    for key, value in self.items():
        try:
            if not is_tensor(value):
                tensor = as_tensor(value)
                self[key] = tensor
        except:
            if key == 'overflowing_values':
                raise ValueError('Unable to create tensor returning overflowing values of different lengths. ')
            raise ValueError("Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length.")
    return self

Convert the inner content to tensors.

Args:
tensor_type (`str` or [`~utils.TensorType`], *optional*):
The type of tensors to use. If `str`, should be one of the values of the enum [`~utils.TensorType`]. If
`None`, no modification is done.


def joinpaths(self, *paths):

        if sys.version_info >= (3, 6):
            paths = [os.fspath(path) for path in paths]
        if len(paths) == 1:
            return paths[0]
        if self.is_windows_fs:
            return self._join_paths_with_drive_support(*paths)
        joined_path_segments = []
        sep = self._path_separator(paths[0])
        for path_segment in paths:
            if self._starts_with_root_path(path_segment):

                joined_path_segments = [path_segment]
            else:
                if (joined_path_segments and
                        not joined_path_segments[-1].endswith(sep)):
                    joined_path_segments.append(sep)
                if path_segment:
                    joined_path_segments.append(path_segment)
        return self._matching_string(paths[0], '').join(joined_path_segments)

Mimic os.path.join using the specified path_separator.

Args:
*paths:  (str) Zero or more paths to join.

Returns:
(str) The paths joined by the path separator, starting with
the last absolute path in paths.


def requires(self, require=None):

		if require is None:
			return self._requires

		if not isinstance(require, dict):
			raise ValueError('__require__')

		for k,v in iteritems(require):

			if k not in self._nodes:
				raise ValueError('__require__[%s]' % str(k))

			if isinstance(v, basestring):
				v = [v]

			elif not isinstance(v, (tuple,list)):
				raise ValueError('__require__[%s]' % str(k))

			for s in v:
				if s not in self._nodes:
					raise ValueError('__require__[%s]: %s' % (str(k), str(v)))

			self._requires[k] = v

Requires

Sets the require rules used to validate the Parent

Arguments:
require {dict} -- A dictionary expressing requirements of fields

Raises:
ValueError

Returns:
None


def ip_mask(ip_addr_and_mask, return_tuple=True):

    regex_ip_and_mask = __re.compile("^((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))/((3[0-2])|([1-2]?[0-9]))$")
    if return_tuple:
        while not regex_ip_and_mask.match(ip_addr_and_mask):
            print("Not a good IP and CIDR mask combo.")
            print("Please try again.")
            ip_addr_and_mask = input("Please enter a IP address and mask in the follwing format x.x.x.x/x: ")
        ip_cidr_split = ip_addr_and_mask.split("/")
        ip_addr = ip_cidr_split[0]
        cidr = ip_cidr_split[1]
        return ip_addr, cidr
    elif not return_tuple:
        if not regex_ip_and_mask.match(ip_addr_and_mask):
            return False
        else:
            return True

Function to check if a address and CIDR mask is good
Args:
ip_addr_and_mask: IP address and mask in the following format 192.168.1.1/24
return_tuple: Set to True it returns a IP and mask in a tuple, set to False returns True or False

Returns: see return_tuple for return options


def set_weights(self, weights):
    params = self.weights
    if len(params) != len(weights):
        raise ValueError('Length of the specified weight list (' + str(len(weights)) + ') does not match the number of weights of the optimizer (' + str(len(params)) + ')')
    weight_value_tuples = []
    param_values = backend.batch_get_value(params)
    for pv, p, w in zip(param_values, params, weights):
        if pv.shape != w.shape:
            raise ValueError('Optimizer weight shape ' + str(pv.shape) + ' not compatible with provided weight shape ' + str(w.shape))
        weight_value_tuples.append((p, w))
    backend.batch_set_value(weight_value_tuples)

Sets the weights of the optimizer, from Numpy arrays.

Should only be called after computing the gradients
(otherwise the optimizer has no weights).

Args:
weights: a list of Numpy arrays. The number of arrays and their shape
must match number of the dimensions of the weights of the optimizer
(i.e. it should match the output of `get_weights`).

Raises:
ValueError: in case of incompatible weight shapes.


def get_inst_info(qry_string):

    qry_prefix = "EC2C.describe_instances("
    qry_real = qry_prefix + qry_string + ")"
    qry_results = eval(qry_real)
    return qry_results

Get details for instances that match the qry_string.

Execute a query against the AWS EC2 client object, that is
based on the contents of qry_string.

Args:
qry_string (str): the query to be used against the aws ec2 client.
Returns:
qry_results (dict): raw information returned from AWS.


def is_scalar(value):
    return (np.isscalar(value) or (isinstance(value, np.ndarray) and (len(np.squeeze(value).shape) == 0)))

Test if the given value is a scalar.

This function also works with memory mapped array values, in contrast to the numpy is_scalar method.

Args:
value: the value to test for being a scalar value

Returns:
boolean: if the given value is a scalar or not


def _obj_to_path(obj):

  if obj is None:
    return obj

  if inspect.isclass(obj) or inspect.isfunction(obj):
    fetched = getattr(sys.modules[obj.__module__], obj.__name__, None)
    if fetched is None:
      raise ValueError(
          "Object %r must be defined on the top level of a module." % obj)
    return "%s.%s" % (obj.__module__, obj.__name__)
  raise TypeError("Unexpected type %s." % type(obj))

Returns the fully qualified path to the object.

Args:
obj: obj must be a new style top level class, or a top level function.
No inner function or static method.

Returns:
Fully qualified path to the object.

Raises:
TypeError: when argument obj has unsupported type.
ValueError: when obj can't be discovered on the top level.


def get_sequence_length_feature_key_name_from_feature_key_name(feature_name):
    return feature_name + _SEQUENCE_FEATURE_LENGTH_POSTFIX

Gets the name of the sequence length feature from that of the base feature.

Args:
feature_name: The feature key of a sequence column.

Returns:
A string which is the feature key for the associated feature length column.


def _output_dir(
        self,
        ext,
        is_instance=False,
        interpolatable=False,
        autohinted=False,
        is_variable=False,
    ):

        assert not (is_variable and any([is_instance, interpolatable]))

        if is_variable:
            dir_prefix = "variable_"
        elif is_instance:
            dir_prefix = "instance_"
        else:
            dir_prefix = "master_"
        dir_suffix = "_interpolatable" if interpolatable else ""
        output_dir = dir_prefix + ext + dir_suffix
        if autohinted:
            output_dir = os.path.join("autohinted", output_dir)
        return output_dir

Generate an output directory.

Args:
ext: extension string.
is_instance: The output is instance font or not.
interpolatable: The output is interpolatable or not.
autohinted: The output is autohinted or not.
is_variable: The output is variable font or not.
Return:
output directory string.


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

    print('Converting elementwise_sub ...')
    model0 = layers[inputs[0]]
    model1 = layers[inputs[1]]

    if names == 'short':
        tf_name = 'S' + random_string(7)
    elif names == 'keep':
        tf_name = w_name
    else:
        tf_name = w_name + str(random.random())

    sub = keras.layers.Subtract(name=tf_name)
    layers[scope_name] = sub([model0, model1])

Convert elementwise subtraction.

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


def _flag_value_as_list(self, wanted_flag_name):
    string_value_list = []
    found, flag_value = self.get_flag_value(wanted_flag_name)
    if found:
        assert flag_value is not None
        string_value_list = flag_value.split(',')
    return string_value_list

Returns the string list of a TensorTracer flag.

Args:
wanted_flag_name: the name of the flag we are looking for.

Returns:
The list value of the flag.


def map_shape_structure(func, structure):
    return tree_impl.map_shape_structure(func, structure)

Variant of keras.tree.map_structure that operates on shape tuples.

Tuples containing ints and Nones are considered shapes and passed to `func`.

Args:
structure: Arbitrarily nested structure.

Returns:
The same structure with `func` applied.


def detect_response_encoding(response, is_html=False, peek=131072):

    encoding = get_heading_encoding(response)

    encoding = wpull.string.detect_encoding(
        wpull.util.peek_file(response.body, peek), encoding=encoding, is_html=is_html
    )

    _logger.debug(__('Got encoding: {0}', encoding))

    return encoding

Return the likely encoding of the response document.

Args:
response (Response): An instance of :class:`.http.Response`.
is_html (bool): See :func:`.util.detect_encoding`.
peek (int): The maximum number of bytes of the document to be analyzed.

Returns:
``str``, ``None``: The codec name.


def _build_case(branch_index, branch_graphs, branch_inputs, name=None, lower_using_switch_merge=None):
    _make_indexed_slices_indices_types_match(_CASE, branch_graphs)
    _check_same_outputs(_CASE, branch_graphs)
    case_inputs = _make_inputs_match(branch_graphs, branch_inputs)
    stateful_ops = []
    for bg in branch_graphs:
        stateful_ops.extend([op for op in bg.get_operations() if auto_control_deps.op_is_stateful(op)])
    if stateful_ops:
        op_fn = gen_functional_ops.case
    else:
        op_fn = gen_functional_ops.stateless_case
    with ops.control_dependencies(sum((list(bg.function_captures.control) for bg in branch_graphs), [])):

        def _make_op(inputs):
            case_op, tensors = util.get_op_and_outputs(op_fn(branch_index, inputs, [t.dtype for t in branch_graphs[0].outputs], [util.create_new_tf_function(g) for g in branch_graphs], output_shapes=_get_output_shapes(*[g.outputs for g in branch_graphs]), name=name))
            _copy_handle_data(tensors, *[g.outputs for g in branch_graphs])
            if case_op is not None:
                util.maybe_set_lowering_attr(case_op, lower_using_switch_merge)
                util.maybe_propagate_compile_time_consts_in_xla(case_op)
                _set_read_only_resource_inputs_attr(case_op, branch_graphs)
                case_op.graph.prevent_fetching(case_op)
                for i, bg in enumerate(branch_graphs):
                    bg.outer_graph = ops.get_default_graph()
                    setattr(case_op, '_branch_graph_{}'.format(i), bg)
            return tensors
        tensors = util.run_as_function_for_tape_gradients(_make_op, case_inputs)
    tensors = [array_ops.identity(t) for t in tensors]
    return _pack_sequence_as(branch_graphs[0].structured_outputs, tensors)

Creates an `Case` op from `branch_index`, branch graphs and inputs.

Note that this modifies `branch_graphs` to make the inputs match, and to
output all intermediates values so they're available for the gradient
computation.

`branch_graphs` need not have the same input types, but they must
have the same output types.

Args:
branch_index: integer Tensor
branch_graphs: List of FuncGraph
branch_inputs: List of lists of Tensors to be passed to corresponding
branch_graph as input.
name: the name for the Case op.
lower_using_switch_merge: Lower this op using switch merge ops (optional).

Returns:
A list of Tensors which are the outputs of the Case op. Does not include
added intermediate outputs.


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

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

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


def Process(self, parser_mediator, plist_name, top_level, **kwargs):

    if not plist_name.startswith(self.PLIST_PATH):
      raise errors.WrongPlistPlugin(self.NAME, plist_name)
    super(AppleAccountPlugin, self).Process(
        parser_mediator, plist_name=self.PLIST_PATH, top_level=top_level)

Check if it is a valid Apple account plist file name.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
plist_name (str): name of the plist.
top_level (dict[str, object]): plist top-level key.


def _parse_ospf_process_id(self, config):
    match = re.search('^router ospf (\\d+)', config)
    return dict(ospf_process_id=int(match.group(1)))

Parses config file for the OSPF proc ID

Args:
config(str):  Running configuration
Returns:
dict: key: ospf_process_id (int)


def __init__(self, action, *, payload=None):

        self.action = action
        self.payload = payload if payload is not None else {}
        self.uid = uuid.uuid4()

Initialise the request object.

Args:
action (str): A string representing the requested action that should be
executed by the server.
payload (dict): A dictionary with data that is available to the action.


def replace_symbols(text, form='NFKD', excluded=None, replacement=''):
    if (excluded is None):
        excluded = set()
    categories = set(['Mn', 'Sc', 'Sk', 'Sm', 'So'])
    return ''.join(((c if ((unicodedata.category(c) not in categories) or (c in excluded)) else replacement) for c in unicodedata.normalize(form, text)))

Replace symbols in text.

Removes symbols from input text or replaces them with a
string if specified.

Args:
text: The text to be processed.
form: Unicode form.
excluded: Set of unicode characters to exclude.
replacement: New text that will replace symbols.

Returns:
The text without symbols.


def pop(self, name, defval=None):
    valu = self.info.pop(name, defval)
    lkey = (self.pref + name.encode('utf8'))
    self.slab.pop(lkey, db=self.db)
    return valu

Pop a name from the SlabDict.

Args:
name (str): The name to remove.
defval (obj): The default value to return if the name is not present.

Returns:
object: The object stored in the SlabDict, or defval if the object was not present.


def _embedding_dim(vocab_size):
    if ((not vocab_size) or (vocab_size <= 0)):
        raise ValueError(('Invalid vocab_size %g.' % vocab_size))
    return int(round((6.0 * math.sqrt(math.sqrt(vocab_size)))))

Calculate a reasonable embedding size for a vocabulary.

Rule of thumb is 6 * 4th root of vocab_size.

Args:
vocab_size: Size of the input vocabulary.
Returns:
The embedding size to use.
Raises:
ValueError: if `vocab_size` is invalid.


def mlir_sparsify(input_data_str):
    return wrap_converter.wrapped_experimental_mlir_sparsify(input_data_str)

Sparsify `input_data_str` to encode sparse tensor with proper format.

Args:
input_data_str: Input data in serialized form (e.g. a TFLITE model).

Returns:
Sparsified model in serialized form (e.g. a TFLITE model).


def _eager_run_fn(fn: PartFn, part: _T) -> AsyncIterable[_T]:
    q = asyncio.Queue[_T | _FinishedT]()

    async def call_fn():
        async for c in fn(part):
            q.put_nowait(c)
        q.put_nowait(_Finished)
    context.create_task(call_fn())

    async def result_iter():
        while (c := (await q.get())) is not _Finished:
            yield c
    return result_iter()

Executes fn on part in an asyncio.task.

Must be called called in an async context. It eagerly schedules a task on
the event loop to execute the whole of `fn` on the part. Results from the
AsyncIterable returned by `fn` can be retrieved via the AsyncIterable returned
by this method.

Args:
fn: the part function to execute on the part.
part: the part to execute the function on.

Returns:
An AsyncIterable that can be used to retrieve the results of `fn` on `part`
in order.

NOTE: this method is non-blocking.


def trading_dates(start, end, calendar='US'):

    kw = dict(start=pd.Timestamp(start, tz='UTC').date(), end=pd.Timestamp(end, tz='UTC').date())
    us_cal = getattr(sys.modules[__name__], f'{calendar}TradingCalendar')()
    return pd.bdate_range(**kw).drop(us_cal.holidays(**kw))

Trading dates for given exchange

Args:
start: start date
end: end date
calendar: exchange as string

Returns:
pd.DatetimeIndex: datetime index

Examples:
>>> bus_dates = ['2018-12-24', '2018-12-26', '2018-12-27']
>>> trd_dates = trading_dates(start='2018-12-23', end='2018-12-27')
>>> assert len(trd_dates) == len(bus_dates)
>>> assert pd.Series(trd_dates == pd.DatetimeIndex(bus_dates)).all()


def unbroadcast_numpy_to(array, shape):

  axis = create_unbroadcast_axis(shape, numpy.shape(array))
  return numpy.reshape(numpy.sum(array, axis=axis), shape)

Reverse the broadcasting operation.

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

Returns:
Array with dimensions summed to match `shape`.


def post(fqdn, package, result, entry, bound, ekey, *argl, **argd):
    global _atdepth_call, _cstack_call
    _cstack_call.pop()
    if (len(_cstack_call) == 0):
        _atdepth_call = False
    r = _post_call(_atdepth_call, package, fqdn, result, entry, bound, ekey, argl, argd)
    return r

Adds logging for the post-call result of calling the method externally.

Args:
fqdn (str): fully-qualified domain name of the function being logged.
package (str): name of the package we are logging for. Usually the first
element of `fqdn.split('.')`.
result: returned from calling the method we are logging.
entry (dict): one of the values returned by :func:`pre`.
bound (bool): true if the method is bound.
ekey (str): key under which to store the entry in the database.


def earliest_date(dates, full_date=False):

    min_date = min(PartialDate.loads(date) for date in dates)
    if not min_date.month and full_date:
        min_date.month = 1
    if not min_date.day and full_date:
        min_date.day = 1
    return min_date.dumps()

Return the earliest among the schema-compliant dates.

This is a convenience wrapper around :ref:`PartialDate`, which should be
used instead if more features are needed.

Args:
dates(list): List of dates from which oldest/earliest one will be returned
full_date(bool): Adds month and/or day as "01" if they are missing
Returns:
str: Earliest date from provided list


def get_pattern_step_time(self, patternnumber, stepnumber):

        _checkPatternNumber(patternnumber)
        _checkStepNumber(stepnumber)

        address = _calculateRegisterAddress('time', patternnumber, stepnumber)
        return self.read_register(address, 0)

Get the step time.

Args:
* patternnumber (integer): 0-7
* stepnumber (integer): 0-7

Returns:
The step time (int??).


def assemble(cls, header_json, metadata_json, content_json):

        try:
            header = json_decode(header_json)
        except ValueError:
            raise MessageError("header could not be decoded")

        try:
            metadata = json_decode(metadata_json)
        except ValueError:
            raise MessageError("metadata could not be decoded")

        try:
            content = json_decode(content_json)
        except ValueError:
            raise MessageError("content could not be decoded")

        msg = cls(header, metadata, content)

        msg._header_json = header_json
        msg._metadata_json = metadata_json
        msg._content_json = content_json

        return msg

Creates a new message, assembled from JSON fragments.

Args:
header_json (``JSON``) :

metadata_json (``JSON``) :

content_json (``JSON``) :

Returns:
Message subclass

Raises:
MessageError


def _remove_squeezable_dimensions(labels, predictions, weights=None, expected_rank_diff=0):
    labels, predictions = confusion_matrix.remove_squeezable_dimensions(labels, predictions, expected_rank_diff=expected_rank_diff)
    if weights is not None:
        weights = ops.convert_to_tensor(weights)
        labels_rank = labels.get_shape().ndims
        weights_shape = weights.get_shape()
        weights_rank = weights_shape.ndims
        if labels_rank is not None and weights_rank is not None:
            rank_diff = weights_rank - labels_rank
            if rank_diff == 1:
                weights = array_ops.squeeze(weights, [-1])
            return (labels, predictions, weights)
        rank_diff = array_ops.rank(weights) - array_ops.rank(labels)
        if weights_rank is None or (weights_rank > 0 and weights_shape.dims[-1].is_compatible_with(1)):
            weights = cond.cond(math_ops.equal(1, rank_diff), lambda: array_ops.squeeze(weights, [-1]), lambda: weights)
    return (labels, predictions, weights)

Internal version of _remove_squeezable_dimensions which handles weights.

Squeezes `predictions` and `labels` if their ranks differ from expected by
exactly 1.
Squeezes `weights` if its rank is 1 more than the new rank of `predictions`

This will use static shape if available. Otherwise, it will add graph
operations, which could result in a performance hit.

Args:
labels: Label values, a `Tensor` whose dimensions match `predictions`.
predictions: Predicted values, a `Tensor` of arbitrary dimensions.
weights: Optional weight `Tensor`. It will be squeezed if it's not scalar,
and its rank is 1 more than the new rank of `labels`.
expected_rank_diff: Expected result of `rank(predictions) - rank(labels)`.

Returns:
Tuple of `predictions`, `labels` and `weights`, possibly with the last
dimension squeezed.


def fleet_id_to_slug(did):

    try:
        fleet_slug = IOTileFleetSlug(did)
    except ValueError:
        raise ArgumentError("Unable to recognize {} as a fleet id".format(did))

    return str(fleet_slug)

Converts a fleet id into a correct fleet slug.

Args:
did (long) : A fleet id
did (string) : A device slug in the form of XXXX, XXXX-XXXX-XXXX, g--XXXX, g--XXXX-XXXX-XXXX
Returns:
str: The device slug in the g--XXXX-XXXX-XXX format
Raises:
ArgumentError: if the ID is not in the [1, 16**12] range, or if not a valid string


def partitions_for_topic(self, topic):

        if topic not in self._partitions:
            return None
        return set(self._partitions[topic].keys())

Return set of all partitions for topic (whether available or not)

Arguments:
topic (str): topic to check for partitions

Returns:
set: {partition (int), ...}


def _get_fields(mcs, bases, namespace):
    fields = [(name, namespace.pop(name)) for (name, attribute) in list(namespace.items()) if isinstance(attribute, BaseField)]
    for base in reversed(bases):
        if hasattr(base, mcs._fields_storage_key):
            fields = (list(getattr(base, mcs._fields_storage_key).items()) + fields)
    return OrderedDict(fields)

Create fields dictionary to be used in resource class namespace.

Pop all field objects from attributes dict (namespace) and store them
under _field_storage_key atrribute. Also collect all fields from base
classes in order that ensures fields can be overriden.

Args:
bases: all base classes of created serializer class
namespace (dict): namespace as dictionary of attributes


def _load_chunk(dat_path, cat_path, info_path):
    dat_array = read_binary_matrix(dat_path)
    dat_array = np.expand_dims(dat_array, (- 1))
    cat_array = read_binary_matrix(cat_path)
    info_array = read_binary_matrix(info_path)
    info_array = np.copy(info_array)
    info_array[(:, 2)] = (info_array[(:, 2)] / 2)
    return (dat_array, cat_array, info_array)

Loads a data chunk as specified by the paths.

Args:
dat_path: Path to dat file of the chunk.
cat_path: Path to cat file of the chunk.
info_path: Path to info file of the chunk.

Returns:
Tuple with the dat, cat, info_arrays.


def plogdet(K):
    r
    egvals = eigvalsh(K)
    return npsum(log(egvals[egvals > epsilon]))

r"""Log of the pseudo-determinant.

It assumes that ``K`` is a positive semi-definite matrix.

Args:
K (array_like): matrix.

Returns:
float: log of the pseudo-determinant.


def make_fake_movie(nframes, mask_shape=(64, 64), mask_center=None, bg_intensity=0.1, mask_sigma=10, dt=0.02, rate=1.0, tau=1.0, sigma=0.001, seed=None):
    gen = np.random.RandomState(seed)
    n = gen.poisson((rate * dt), size=nframes)
    gamma = np.exp(((- dt) / tau))
    c = signal.lfilter(np.r_[1], np.r_[(1, (- gamma))], n, axis=0)
    (nr, nc) = mask_shape
    npix = (nr * nc)
    if (mask_center is None):
        mask_center = ((nc
    (a, b) = mask_center
    (y, x) = np.ogrid[(:nr, :nc)]
    xs = ((x - a) ** 2.0)
    ys = ((y - b) ** 2.0)
    twoss = (2.0 * (mask_sigma ** 2.0))
    alpha = np.exp(((- 1) * ((xs / twoss) + (ys / twoss)))).ravel()
    alpha /= alpha.sum()
    beta = (gen.randn(npix) * bg_intensity)
    lamb = rate
    epsilon = (gen.randn(npix, nframes) * sigma)
    F = (((c[(None, :)] * alpha[(:, None)]) + beta[(:, None)]) + epsilon)
    theta = (sigma, alpha, beta, lamb, gamma)
    return (F, c, n, theta)

Generate 2D fake fluorescence movie

Arguments:
---------------------------------------------------------------------------
nframes:        number of timebins to simulate
mask_shape:     tuple (nrows, ncols), shape of a single movie frame
mask_center:    tuple (x, y), pixel coords of cell center
bg_intensity:   scalar, amplitude of (static) baseline fluorescence
mask_sigma:     scalar, standard deviation of Gaussian mask
dt:             timestep (s)
rate:           mean spike rate (Hz)
tau:            time constant of decay in calcium concentration (s)
sigma:          SD of additive noise on fluorescence
seed:           Seed for RNG

Returns:
---------------------------------------------------------------------------
F:          fluorescence [npixels, nframes]
c:          calcium concentration [nframes,]
n:          spike train [nframes,]
theta:      tuple of true model parameters:
(sigma, alpha, beta, lambda, gamma)


def single_slice_dim(self, shape):
    if not isinstance(shape, (tuple, list)):
        raise TypeError('`shape` must be a sequence (like tuple or list) instead of ' + type(shape).__name__)
    if len(shape) != len(self.full_shape):
        raise ValueError('Expected equal length, but received shape={} of length {} while self.full_shape={} is of length {}.'.format(shape, len(shape), self.full_shape, len(self.full_shape)))
    for i in range(len(shape)):
        if self.var_offset[i] + shape[i] > self.full_shape[i]:
            raise ValueError('With self.var_offset={}, a partition of shape={} would exceed self.full_shape={} in dimension {}.'.format(self.var_offset, shape, self.full_shape, i))
    slice_dim = None
    for i in range(len(shape)):
        if shape[i] == self.full_shape[i]:
            continue
        if slice_dim is not None:
            raise ValueError('Cannot use single_slice_dim() with shape={} and self.full_shape={} since slice dim could be either dimension {} or {}.'.format(shape, self.full_shape, i, slice_dim))
        slice_dim = i
    return slice_dim

Returns the slice dim when the variable is partitioned only in one dim.

Args:
shape: Tuple or list of `int` indicating the shape of one specific
variable partition.

Returns:
`int` representing the dimension that the variable is partitioned in, or
`None` if the variable doesn't seem to be partitioned at all.

Raises:
TypeError: If `shape` is not a sequence.
ValueError: If `shape` is not the same length as `self.full_shape`. If
the variable is partitioned in more than one dimension.


def __setitem__(self, key: Union[str, int], value: Any) -> None:
    if not hasattr(self, '_sym_parent'):
        return
    if base.treats_as_sealed(self):
        raise base.WritePermissionError(self._error_message('Cannot modify field of a sealed Dict.'))
    if not base.writtable_via_accessors(self):
        raise base.WritePermissionError(self._error_message("Cannot modify Dict field by attribute or key while accessor_writable is set to False. Use 'rebind' method instead."))
    update = self._set_item_without_permission_check(key, value)
    if flags.is_change_notification_enabled() and update:
        self._notify_field_updates([update])

Set item in this Dict.

Args:
key: String key. (Please be noted that key path is not supported.)
value: Value to be inserted.

Raises:
WritePermissionError: when Dict cannot be modified by accessor or
is sealed.
KeyError: Key is not allowed according to the value spec.
ValueError: Value is not acceptable according to the value spec.


def put(self, dash_id=0):
    data = request.get_json()
    updated = self._update_dash(dash_id, data)
    return build_response(dict(data=updated, code=200))

Update a dash meta and content, return updated dash content.

Args:
dash_id: dashboard id.

Returns:
A dict containing the updated content of that dashboard, not include the meta info.


def get_student_current_grades(self, username, course_ids=None):
    if (course_ids is None):
        enrollments_client = CourseEnrollments(self.requester, self.base_url)
        enrollments = enrollments_client.get_student_enrollments()
        course_ids = list(enrollments.get_enrolled_course_ids())
    all_current_grades = []
    for course_id in course_ids:
        try:
            all_current_grades.append(self.get_student_current_grade(username, course_id))
        except HTTPError as error:
            if (error.response.status_code >= 500):
                raise
    return CurrentGradesByUser(all_current_grades)

Returns a CurrentGradesByUser object with the user current grades.

Args:
username (str): an edx user's username
course_ids (list): a list of edX course ids.

Returns:
CurrentGradesByUser: object representing the student current grades


def _construct_location_to_filter_list(match_query):
    location_to_filters = {}
    for match_traversal in match_query.match_traversals:
        for match_step in match_traversal:
            current_filter = match_step.where_block
            if (current_filter is not None):
                current_location = match_step.as_block.location
                location_to_filters.setdefault(current_location, []).append(current_filter)
    return location_to_filters

Return a dict mapping location -> list of filters applied at that location.

Args:
match_query: MatchQuery object from which to extract location -> filters dict

Returns:
dict mapping each location in match_query to a list of
Filter objects applied at that location


def remove_all_servers(self):
    for server_id in list(self._servers.keys()):
        self.remove_server(server_id)

Remove all registered WBEM servers from the subscription manager. This
also unregisters listeners from these servers and removes all owned
indication subscriptions, owned indication filters, and owned listener
destinations.

Raises:

Exceptions raised by :class:`~pywbem.WBEMConnection`.


def humanize_time_delta(sec):
    if (sec < 0):
        logger.warn('humanize_time_delta() obtains negative seconds!')
        return '{:.3g} seconds'.format(sec)
    if (sec == 0):
        return '0 second'
    time = (datetime(2000, 1, 1) + timedelta(seconds=int(sec)))
    units = ['day', 'hour', 'minute', 'second']
    vals = [int((sec
    if (sec < 60):
        vals[(- 1)] = sec

    def _format(v, u):
        return '{:.3g} {}{}'.format(v, u, ('s' if (v > 1) else ''))
    ans = []
    for (v, u) in zip(vals, units):
        if (v > 0):
            ans.append(_format(v, u))
    return ' '.join(ans)

Humanize timedelta given in seconds

Args:
sec (float): time difference in seconds. Must be positive.

Returns:
str - time difference as a readable string

Example:

.. code-block:: python

print(humanize_time_delta(1))                                   # 1 second
print(humanize_time_delta(60 + 1))                              # 1 minute 1 second
print(humanize_time_delta(87.6))                                # 1 minute 27 seconds
print(humanize_time_delta(0.01))                                # 0.01 seconds
print(humanize_time_delta(60 * 60 + 1))                         # 1 hour 1 second
print(humanize_time_delta(60 * 60 * 24 + 1))                    # 1 day 1 second
print(humanize_time_delta(60 * 60 * 24 + 60 * 2 + 60*60*9 + 3)) # 1 day 9 hours 2 minutes 3 seconds


def delete_nsg_rule(access_token, subscription_id, resource_group, nsg_name, nsg_rule_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Network/networkSecurityGroups/', nsg_name,
                        '/securityRules/', nsg_rule_name,
                        '?api-version=', NETWORK_API])
    return do_delete(endpoint, access_token)

Delete network security group rule.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
nsg_name (str): Name of the Network Security Group.
nsg_rule_name (str): Name of the NSG rule.

Returns:
HTTP response.


def help_members(obj, use_other=False):
    import utool as ut
    attrnames = dir(obj)
    attr_list = [getattr(obj, attrname) for attrname in attrnames]
    attr_types = ut.lmap(ut.type_str, map(type, attr_list))
    (unique_types, groupxs) = ut.group_indices(attr_types)
    type_to_items = ut.dzip(unique_types, ut.apply_grouping(attr_list, groupxs))
    type_to_itemname = ut.dzip(unique_types, ut.apply_grouping(attrnames, groupxs))
    memtypes = ['instancemethod']
    func_mems = ut.dict_subset(type_to_items, memtypes, [])
    func_list = ut.flatten(func_mems.values())
    defsig_list = []
    num_unbound_args_list = []
    num_args_list = []
    for func in func_list:
        argspec = ut.get_func_argspec(func)
        args = argspec.args
        unbound_args = get_unbound_args(argspec)
        defsig = ut.func_defsig(func)
        defsig_list.append(defsig)
        num_unbound_args_list.append(len(unbound_args))
        num_args_list.append(len(args))
    group = ut.hierarchical_group_items(defsig_list, [num_unbound_args_list, num_args_list])
    print(repr(obj))
    print(ut.repr3(group, strvals=True))
    if use_other:
        other_mems = ut.delete_keys(type_to_items.copy(), memtypes)
        other_mems_attrnames = ut.dict_subset(type_to_itemname, other_mems.keys())
        named_other_attrs = ut.dict_union_combine(other_mems_attrnames, other_mems, (lambda x, y: list(zip(x, y))))
        print(ut.repr4(named_other_attrs, nl=2, strvals=True))

r"""
Inspects members of a class

Args:
obj (class or module):

CommandLine:
python -m utool.util_inspect help_members

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_inspect import *  # NOQA
>>> import utool as ut
>>> obj = ut.DynStruct
>>> result = help_members(obj)
>>> print(result)


def is_supergroup(self, subgroup):

        warnings.warn("This is not fully functional. Only trivial subsets are "
                      "tested right now. ")
        return set(subgroup.symmetry_ops).issubset(self.symmetry_ops)

True if this group is a supergroup of the supplied group.

Args:
subgroup (SymmetryGroup): Subgroup to test.

Returns:
True if this group is a supergroup of the supplied group.


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

Updates the security labels description.

Args:
description:


def _exec_procedure_func(self, func, tr_record):
    func_name = func.__name__
    procedure_name = func_name[1:] if func_name[0] == '_' else func_name
    with self._log_test_stage(procedure_name):
        try:
            func(copy.deepcopy(tr_record))
        except signals.TestAbortSignal:
            raise
        except Exception as e:
            logging.exception('Exception happened when executing %s for %s.', procedure_name, self.current_test_info.name)
            tr_record.add_error(procedure_name, e)

Executes a procedure function like on_pass, on_fail etc.

This function will alter the 'Result' of the test's record if
exceptions happened when executing the procedure function, but
prevents procedure functions from altering test records themselves
by only passing in a copy.

This will let signals.TestAbortAll through so abort_all works in all
procedure functions.

Args:
func: The procedure function to be executed.
tr_record: The TestResultRecord object associated with the test
executed.


def solid_named(self, name):
    check.str_param(name, 'name')
    if (name not in self._solid_dict):
        raise DagsterInvariantViolationError('Pipeline {pipeline_name} has no solid named {name}.'.format(pipeline_name=self.name, name=name))
    return self._solid_dict[name]

Return the solid named "name". Throws if it does not exist.

Args:
name (str): Name of solid

Returns:
SolidDefinition: SolidDefinition with correct name.


def parse_objective_coefficient(entry):

    for parameter in entry.kinetic_law_reaction_parameters:
        pid, name, value, units = parameter
        if (pid == 'OBJECTIVE_COEFFICIENT' or
                name == 'OBJECTIVE_COEFFICIENT'):
            return value

    return None

Return objective value for reaction entry.

Detect objectives that are specified using the non-standardized
kinetic law parameters which are used by many pre-FBC SBML models. The
objective coefficient is returned for the given reaction, or None if
undefined.

Args:
entry: :class:`SBMLReactionEntry`.


def sample_frame_indices(clip_len, frame_sample_rate, seg_len):
    converted_len = int(clip_len * frame_sample_rate)
    end_idx = np.random.randint(converted_len, seg_len)
    start_idx = end_idx - converted_len
    indices = np.linspace(start_idx, end_idx, num=clip_len)
    indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)
    return indices

Sample a given number of frame indices from the video.

Args:
clip_len (`int`): Total number of frames to sample.
frame_sample_rate (`int`): Sample every n-th frame.
seg_len (`int`): Maximum allowed index of sample's last frame.

Returns:
indices (`List[int]`): List of sampled frame indices


def get_plugin(self, identifier, cls=None):
    if (((cls is None) or (cls == 'provider')) and (identifier in self.available_providers)):
        return self.available_providers[identifier]
    elif (((cls is None) or (cls == 'checker')) and (identifier in self.available_checkers)):
        return self.available_checkers[identifier]
    return Config.load_local_plugin(identifier)

Return the plugin corresponding to the given identifier and type.

Args:
identifier (str): identifier of the plugin.
cls (str): one of checker / provider.

Returns:
Checker/Provider: plugin class.


def smoothing_cross_entropy_factored(a, b, labels, confidence):

  num_splits = 16
  vocab_size = shape_list(b)[0]
  labels = approximate_split(labels, num_splits)
  a = approximate_split(a, num_splits)
  parts = []
  for part in range(num_splits):
    with tf.control_dependencies(parts[-1:]):
      logits = tf.matmul(a[part], b, transpose_b=True)
      parts.append(
          smoothing_cross_entropy(logits, labels[part], vocab_size, confidence))
  return tf.concat(parts, 0)

Memory-efficient computation of smoothing cross-entropy.

Avoids realizing the entire logits matrix at once.

Args:
a: a Tensor with shape [batch, inner_dim]
b: a Tensor with shape [vocab_size, inner_dim]
labels: an integer Tensor with shape [batch]
confidence: a float

Returns:
A Tensor with shape [batch]


def _finalize_func(string_handle):
    iterator_resource = gen_dataset_ops.iterator_from_string_handle_v2(string_handle, **self._input_dataset._flat_structure)
    with ops.control_dependencies([resource_variable_ops.destroy_resource_op(iterator_resource, ignore_lookup_error=True)]):
        return array_ops.constant(0, dtypes.int64)

Destroys the iterator resource created.

Args:
string_handle: An iterator string handle created by _init_func
Returns:
Tensor constant 0


def _add_scalar(self, scalar):

        encoded = EncodedNumber.encode(self.public_key, scalar,
                                       max_exponent=self.exponent)

        return self._add_encoded(encoded)

Returns E(a + b), given self=E(a) and b.

Args:
scalar: an int or float b, to be added to `self`.

Returns:
EncryptedNumber: E(a + b), calculated by encrypting b and
taking the product of E(a) and E(b) modulo
:attr:`~PaillierPublicKey.n` ** 2.

Raises:
ValueError: if scalar is out of range or precision.


def maybe_download_and_extract_dataset(self, data_url, dest_directory):
    if not data_url:
        return
    if not gfile.Exists(dest_directory):
        os.makedirs(dest_directory)
    filename = data_url.split('/')[-1]
    filepath = os.path.join(dest_directory, filename)
    if not gfile.Exists(filepath):

        def _progress(count, block_size, total_size):
            sys.stdout.write('\r>> Downloading %s %.1f%%' % (filename, float(count * block_size) / float(total_size) * 100.0))
            sys.stdout.flush()
        try:
            filepath, _ = urllib.request.urlretrieve(data_url, filepath, _progress)
        except:
            tf.compat.v1.logging.error('Failed to download URL: {0} to folder: {1}. Please make sure you have enough free space and an internet connection'.format(data_url, filepath))
            raise
        print()
        statinfo = os.stat(filepath)
        tf.compat.v1.logging.info('Successfully downloaded {0} ({1} bytes)'.format(filename, statinfo.st_size))
        tarfile.open(filepath, 'r:gz').extractall(dest_directory)

Download and extract data set tar file.

If the data set we're using doesn't already exist, this function
downloads it from the TensorFlow.org website and unpacks it into a
directory.
If the data_url is none, don't download anything and expect the data
directory to contain the correct files already.

Args:
data_url: Web location of the tar file containing the data set.
dest_directory: File path to extract data to.


def _prepare_feed_values(model, inputs, targets, sample_weights, mode):
    strategy = model._distribution_strategy
    inputs, targets, sample_weights = _get_input_from_iterator(inputs, model)
    if backend.is_tpu_strategy(strategy):
        if sample_weights is not None:
            raise ValueError('TPUStrategy does not support sample weights.')
    if isinstance(inputs, dict):
        inputs = [inputs[key] for key in model._feed_input_names]
    if is_distributing_by_cloning(model):
        inputs = flatten_per_replica_values(strategy, inputs)
        targets = flatten_per_replica_values(strategy, targets)
        inputs, targets = nest.map_structure(training_utils_v1.standardize_single_array, (inputs, targets))
    else:
        inputs = training_utils_v1.ModelInputs(inputs).as_list()
    if mode == ModeKeys.PREDICT:
        sample_weights = []
        targets = []
    elif sample_weights is not None and is_distributing_by_cloning(model):
        if context.executing_eagerly() and (not model._compile_distribution):
            raise NotImplementedError('`sample_weight` is not supported when using tf.distribute.Strategy in eager mode and cloning=True.')
        sample_weights = flatten_per_replica_values(strategy, sample_weights)
    ins = [inputs, targets, sample_weights]
    return tuple(ins)

Prepare feed values to the model execution function.

Args:
model: Model to prepare feed values for.
inputs: List or dict of model inputs.
targets: Optional list of model targets.
sample_weights: Optional list of sample weight arrays.
mode: One of ModeKeys.TRAIN/ModeKeys.TEST/ModeKeys.PREDICT.

Returns:
Feed values for the model in the given mode.


def _get_num_nvidia_gpus():
    try:
        return len(os.environ['CUDA_VISIBLE_DEVICES'].split(','))
    except KeyError:
        pass
    try:
        output = subprocess.check_output(['nvidia-smi', '--list-gpus'], encoding='utf-8')
        return sum((l.startswith('GPU ') for l in output.strip().split('\n')))
    except subprocess.CalledProcessError as e:
        raise RuntimeError('Could not get number of GPUs from nvidia-smi. Maybe it is missing?\nOutput: %s' % e.output)

Gets the number of NVIDIA GPUs by using CUDA_VISIBLE_DEVICES and nvidia-smi.

Returns:
Number of GPUs available on the node
Raises:
RuntimeError if executing nvidia-smi failed


def _init_volume_service(self, version):
    volume_cfg = self._load_config_section(CONFIG_VOLUME_SECTION)
    self._token_volume = volume_cfg[CONFIG_TOKEN]
    proto = volume_cfg[CONFIG_PROTOCOL]
    host = volume_cfg[CONFIG_HOST]
    self._volume = VolumeService(host, version)
    self._volume.base_protocol = proto
    self._volume.set_auth(self._token_volume)

Method to initialize the Volume Service from the config data

Args:
version (string): Version of Boss API to use.

Returns:
None

Raises:
(KeyError): if given invalid version.


def post_process_travis_macos(journal_filename):
    travis_build_dir = os.environ.get('TRAVIS_BUILD_DIR', '')
    with open(journal_filename, 'r') as file_obj:
        content = file_obj.read()
    processed = content.replace(travis_build_dir, '${TRAVIS_BUILD_DIR}')
    with open(journal_filename, 'w') as file_obj:
        file_obj.write(processed)

Post-process a generated journal file on Travis macOS.

Args:
journal_filename (str): The name of the journal file.


def predict(self, documents, **kwargs):

        if isinstance(documents, (str, bytes, unicode_, np.unicode_)):
            return self._predict_one(documents, **kwargs)
        else:
            return np.concatenate([self._predict_one(doc, **kwargs) for doc in documents])

Predict class (content=1 or not-content=0) of the blocks in one or many
HTML document(s).

Args:
documents (str or List[str]): HTML document(s)

Returns:
``np.ndarray`` or List[``np.ndarray``]: array of binary predictions
for content (1) or not-content (0).


def handle_subscribe(self, request, path):

        ret = []
        if path:

            name = path[0]
            if name not in self.children:
                self.children[name] = NotifierNode(
                    getattr(self.data, name, None), self)
            ret += self.children[name].handle_subscribe(request, path[1:])
        else:

            serialized = serialize_object(self.data)
            if request.delta:
                self.delta_requests.append(request)
                ret.append(request.delta_response([[[], serialized]]))
            else:
                self.update_requests.append(request)
                ret.append(request.update_response(serialized))
        return ret

Add to the list of request to notify, and notify the initial value of
the data held

Args:
request (Subscribe): The subscribe request
path (list): The relative path from ourself

Returns:
list: [(callback, Response)] that need to be called


def format_sec_to_dhm(sec):
    (rem_int, s_int) = divmod(int(sec), 60)
    (rem_int, m_int) = divmod(rem_int, 60)
    (d_int, h_int) = divmod(rem_int, 24)
    return '{}d{:02d}h{:02d}m'.format(d_int, h_int, m_int)

Format seconds to days, hours, minutes.

Args:
sec: float or int
Number of seconds in a period of time

Returns:
Period of time represented as a string on the form ``0d:00h:00m``.


def get_data(self, url, *args, **kwargs):
    res = self._conn.get(url, headers=self._prepare_headers(**kwargs))
    if (res.status_code == 200):
        return res.text
    else:
        return None

Gets data from url as text

Returns content under the provided url as text

Args:
**url**: address of the wanted data

.. versionadded:: 0.3.2
**additional_headers**: (optional) Additional headers
to be used with request

Returns:
string


def __init__(self, root, attached_dependencies=None):
    trackable_view.TrackableView.__init__(self, root)
    self._root_ref = root if isinstance(root, weakref.ref) else weakref.ref(root)
    self._attached_dependencies = attached_dependencies

Configure the graph view.

Args:
root: A `Trackable` object whose variables (including the variables of
dependencies, recursively) should be saved. May be a weak reference.
attached_dependencies: List of dependencies to attach to the root object.
Used when saving a Checkpoint with a defined root object. To avoid
reference cycles, this should use the WeakTrackableReference class.


def set_defaults(self, defaults: Sequence[cfg.Variable]) -> 'PyTDSignature':
    defaults = list(defaults)
    params = []
    for param in reversed(self.pytd_sig.params):
        if defaults:
            defaults.pop()
            params.append(pytd.Parameter(name=param.name, type=param.type, kind=param.kind, optional=True, mutated_type=param.mutated_type))
        else:
            params.append(pytd.Parameter(name=param.name, type=param.type, kind=param.kind, optional=False, mutated_type=param.mutated_type))
    new_sig = pytd.Signature(params=tuple(reversed(params)), starargs=self.pytd_sig.starargs, starstarargs=self.pytd_sig.starstarargs, return_type=self.pytd_sig.return_type, exceptions=self.pytd_sig.exceptions, template=self.pytd_sig.template)
    self.pytd_sig = new_sig
    self.param_types = [self.ctx.convert.constant_to_value(p.type, subst=datatypes.AliasingDict(), node=self.ctx.root_node) for p in self.pytd_sig.params]
    self.signature = function.Signature.from_pytd(self.ctx, self.name, self.pytd_sig)
    return self

Set signature's default arguments. Requires rebuilding PyTD signature.

Args:
defaults: An iterable of function argument defaults.

Returns:
Self with an updated signature.


def add_roles(self, databaseName, roleNames, collectionName=None):

        for roleName in roleNames:
            self.add_role(databaseName, roleName, collectionName)

Add multiple roles

Args:
databaseName (str): Database Name
roleNames (list of RoleSpecs): roles

Keyword Args:
collectionName (str): Collection

Raises:
ErrRoleException: role not compatible with the databaseName and/or collectionName


def PrintMessage(self, message):
    fields = message.ListFields()
    if self.use_index_order:
        fields.sort(key=(lambda x: x[0].index))
    for (field, value) in fields:
        if _IsMapEntry(field):
            for key in sorted(value):
                entry_submsg = field.message_type._concrete_class(key=key, value=value[key])
                self.PrintField(field, entry_submsg)
        elif (field.label == descriptor.FieldDescriptor.LABEL_REPEATED):
            for element in value:
                self.PrintField(field, element)
        else:
            self.PrintField(field, value)

Convert protobuf message to text format.

Args:
message: The protocol buffers message.


def unsubscribe(self, subscription, max=None):
    if (max is None):
        self._send(('UNSUB %d' % subscription.sid))
        self._subscriptions.pop(subscription.sid)
    else:
        subscription.max = max
        self._send(('UNSUB %d %s' % (subscription.sid, max)))

Unsubscribe will remove interest in the given subject. If max is
provided an automatic Unsubscribe that is processed by the server
when max messages have been received

Args:
subscription (pynats.Subscription): a Subscription object
max (int=None): number of messages


def describe_file_set(modules):
    descriptor = FileSet()
    file_descriptors = []
    for module in modules:
        file_descriptors.append(describe_file(module))
    if file_descriptors:
        descriptor.files = file_descriptors
    return descriptor

Build a file set from a specified Python modules.

Args:
modules: Iterable of Python module to describe.

Returns:
Initialized FileSet instance describing the modules.


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

Corresponds to IDD Field `month`

Args:
value (int): value for IDD Field `month`
value >= 1
value <= 12
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


def defaults(cls, *options, **kwargs):
    if (kwargs and (len(kwargs) != 1) and (list(kwargs.keys())[0] != 'backend')):
        raise Exception('opts.defaults only accepts "backend" keyword argument')
    cls._linemagic(cls._expand_options(merge_options_to_dict(options)), backend=kwargs.get('backend'))

Set default options for a session.

Set default options for a session. whether in a Python script or
a Jupyter notebook.

Args:
*options: Option objects used to specify the defaults.
backend:  The plotting extension the options apply to


def create(cls, hashing_algorithm=HashingAlgorithmEnum.SHA_256, digest_value=b'', key_format_type=KeyFormatTypeEnum.RAW):
    algorithm = HashingAlgorithm(hashing_algorithm)
    value = DigestValue(bytearray(digest_value))
    format_type = KeyFormatType(key_format_type)
    return Digest(hashing_algorithm=algorithm, digest_value=value, key_format_type=format_type)

Construct a Digest object from provided digest values.

Args:
hashing_algorithm (HashingAlgorithm): An enumeration representing
the hash algorithm used to compute the digest. Optional,
defaults to HashingAlgorithm.SHA_256.
digest_value (byte string): The bytes of the digest hash. Optional,
defaults to the empty byte string.
key_format_type (KeyFormatType): An enumeration representing the
format of the key corresponding to the digest. Optional,
defaults to KeyFormatType.RAW.

Returns:
Digest: The newly created Digest.

Example:
>>> x = Digest.create(HashingAlgorithm.MD5, b'\x00',
... KeyFormatType.RAW)
>>> x.hashing_algorithm
HashingAlgorithm(value=HashingAlgorithm.MD5)
>>> x.digest_value
DigestValue(value=bytearray(b'\x00'))
>>> x.key_format_type
KeyFormatType(value=KeyFormatType.RAW)


def get_kpoint_weights(self, kpoints, atol=1e-5):

        kpts = np.array(kpoints)
        shift = []
        mesh = []
        for i in range(3):
            nonzero = [i for i in kpts[:, i] if abs(i) > 1e-5]
            if len(nonzero) != len(kpts):

                if not nonzero:
                    mesh.append(1)
                else:
                    m = np.abs(np.round(1/np.array(nonzero)))
                    mesh.append(int(max(m)))
                shift.append(0)
            else:

                m = np.abs(np.round(0.5/np.array(nonzero)))
                mesh.append(int(max(m)))
                shift.append(1)

        mapping, grid = spglib.get_ir_reciprocal_mesh(
            np.array(mesh), self._cell, is_shift=shift, symprec=self._symprec)
        mapping = list(mapping)
        grid = (np.array(grid) + np.array(shift) * (0.5, 0.5, 0.5)) / mesh
        weights = []
        mapped = defaultdict(int)
        for k in kpoints:
            for i, g in enumerate(grid):
                if np.allclose(pbc_diff(k, g), (0, 0, 0), atol=atol):
                    mapped[tuple(g)] += 1
                    weights.append(mapping.count(mapping[i]))
                    break
        if (len(mapped) != len(set(mapping))) or (
                not all([v == 1 for v in mapped.values()])):
            raise ValueError("Unable to find 1:1 corresponding between input "
                             "kpoints and irreducible grid!")
        return [w/sum(weights) for w in weights]

Calculate the weights for a list of kpoints.

Args:
kpoints (Sequence): Sequence of kpoints. np.arrays is fine. Note
that the code does not check that the list of kpoints
provided does not contain duplicates.
atol (float): Tolerance for fractional coordinates comparisons.

Returns:
List of weights, in the SAME order as kpoints.