def replace_vcf_info(keyword, annotation, variant_line=None, variant_dict=None):

    new_info = '{0}={1}'.format(keyword, annotation)

    logger.debug("Replacing the variant information {0}".format(new_info))

    fixed_variant = None
    new_info_list = []

    if variant_line:
        logger.debug("Adding information to a variant line")
        splitted_variant = variant_line.rstrip('\n').split('\t')
        logger.debug("Adding information to splitted variant line")
        old_info = splitted_variant[7]
        if old_info == '.':
            new_info_string = new_info
        else:
            splitted_info_string = old_info.split(';')
            for info in splitted_info_string:
                splitted_info_entry = info.split('=')
                if splitted_info_entry[0] == keyword:
                    new_info_list.append(new_info)
                else:
                    new_info_list.append(info)
            new_info_string = ';'.join(new_info_list)

        splitted_variant[7] = new_info_string

        fixed_variant = '\t'.join(splitted_variant)

    elif variant_dict:
        logger.debug("Adding information to a variant dict")
        old_info = variant_dict['INFO']

        if old_info == '.':
            variant_dict['INFO'] = new_info
        else:
            for info in old_info.split(';'):
                splitted_info_entry = info.split('=')
                if splitted_info_entry[0] == keyword:
                    new_info_list.append(new_info)
                else:
                    new_info_list.append(info)
            new_info_string = ';'.join(new_info_list)

        variant_dict['INFO'] = new_info_string
        fixed_variant = variant_dict

    return fixed_variant

Replace the information of a info field of a vcf variant line or a
variant dict.

Arguments:
variant_line (str): A vcf formatted variant line
variant_dict (dict): A variant dictionary
keyword (str): The info field key
annotation (str): If the annotation is a key, value pair
this is the string that represents the value

Returns:
variant_line (str): A annotated variant line


def parse(cls, args):

        try:
            (options, args) = cls.optparser.parse_args(args)
        except OptionParsingError as e:
            raise ParseError(e.msg, cls.optparser.format_help())
        except OptionParsingExit as e:
            return None

        SparkCommand.validate_program(options)
        SparkCommand.validate_script_location(options)
        SparkCommand.validate_cmdline(options)
        SparkCommand.validate_sql(options)

        if options.macros is not None:
            options.macros = json.loads(options.macros)

        v = vars(options)
        v["command_type"] = "SparkCommand"
        return v

Parse command line arguments to construct a dictionary of command
parameters that can be used to create a command

Args:
`args`: sequence of arguments

Returns:
Dictionary that can be used in create method

Raises:
ParseError: when the arguments are not correct


def add_field(self, key, field):

        self.inputs[key] = field
        container = HBox()
        container.style.update({'justify-content':'space-between', 'overflow':'auto', 'padding':'3px'})
        container.append(self.inputs[key], key=key)
        self.container.append(container, key=key)

Adds a field to the dialog with a unique identifier.

Note: You can access to the fields content calling the function GenericDialog.get_field(key).

Args:
key (str): The unique identifier for the field.
field (Widget): The widget to be added to the dialog, TextInput or any Widget for example.


def get_gcps(self):

        gcps = self.filehandle.gcps

        gcp_array = np.array([(p.row, p.col, p.x, p.y, p.z) for p in gcps[0]])

        ypoints = np.unique(gcp_array[:, 0])
        xpoints = np.unique(gcp_array[:, 1])

        gcp_lons = gcp_array[:, 2].reshape(ypoints.shape[0], xpoints.shape[0])
        gcp_lats = gcp_array[:, 3].reshape(ypoints.shape[0], xpoints.shape[0])
        gcp_alts = gcp_array[:, 4].reshape(ypoints.shape[0], xpoints.shape[0])

        return (xpoints, ypoints), (gcp_lons, gcp_lats, gcp_alts), gcps

Read GCP from the GDAL band.

Args:
band (gdal band): Measurement band which comes with GCP's
coordinates (tuple): A tuple with longitude and latitude arrays

Returns:
points (tuple): Pixel and Line indices 1d arrays
gcp_coords (tuple): longitude and latitude 1d arrays


def _testGradientSerDes(self, graph_fn):
    test_dir = self._get_test_dir('nested_control_flow')
    filename = os.path.join(test_dir, 'metafile')
    saver_ckpt = os.path.join(test_dir, 'saver.ckpt')
    with ops_lib.Graph().as_default():
        var = variable_v1.VariableV1(0.0)
        var_name = var.name
        output = graph_fn(var)
        output_name = output.name
        init_op = variables.global_variables_initializer()
        with session.Session() as sess:
            self.evaluate(init_op)
            self.evaluate(output)
            saver = saver_module.Saver()
            saver.save(sess, saver_ckpt)
            saver.export_meta_graph(filename)
        grad = gradients_impl.gradients([output], [var])
        no_constfold_config = config_pb2.ConfigProto()
        no_constfold_config.graph_options.rewrite_options.constant_folding = rewriter_config_pb2.RewriterConfig.OFF
        with session.Session(config=no_constfold_config) as sess:
            self.evaluate(init_op)
            expected_grad_value = self.evaluate(grad)
    context._reset_context()
    with ops_lib.Graph().as_default():
        with session.Session() as sess:
            saver = saver_module.import_meta_graph(filename)
            saver.restore(sess, saver_ckpt)
        var = ops_lib.get_default_graph().get_tensor_by_name(var_name)
        output = ops_lib.get_default_graph().get_tensor_by_name(output_name)
        grad = gradients_impl.gradients([output], [var])
        init_op = variables.global_variables_initializer()
        with session.Session(config=no_constfold_config) as sess:
            self.evaluate(init_op)
            actual_grad_value = self.evaluate(grad)
            self.assertEqual(expected_grad_value, actual_grad_value)

Tests that gradients can be computed after exporting and importing.

Builds a graph, exports it, and verifies that it can be imported and the
gradient can be built and run correctly.

Args:
graph_fn: takes a single float Tensor argument as input, outputs a single
Tensor


def __init__(self, device=''):
    global _RESOURCE_TRACKER_STACK
    for resource_tracker in _RESOURCE_TRACKER_STACK:
        resource_tracker.add_resource(self)
    super().__init__(device=device)

Initialize the `TrackableResource`.

Args:
device: A string indicating a required placement for this resource,
e.g. "CPU" if this resource must be created on a CPU device. A blank
device allows the user to place resource creation, so generally this
should be blank unless the resource only makes sense on one device.


def xfrange(start, stop, step=1, maxSize=-1):

    if start <= stop:
        stop, step = stop + 1, abs(step)
    else:
        stop, step = stop - 1, -abs(step)

    if maxSize >= 0:
        size = lenRange(start, stop, step)
        if size > maxSize:
            raise exceptions.MaxSizeException(
                "Size %d > %s (MAX_FRAME_SIZE)" % (size, maxSize))

    return (f for f in xrange(start, stop, step))

Returns a generator that yields the frames from start to stop, inclusive.
In other words it adds or subtracts a frame, as necessary, to return the
stop value as well, if the stepped range would touch that value.

Args:
start (int):
stop (int):
step (int): Note that the sign will be ignored
maxSize (int):

Returns:
generator:

Raises:
:class:`fileseq.exceptions.MaxSizeException`: if size is exceeded


def _get_value_from_match(self, key, match):

        value = match.groups(1)[0]
        clean_value = str(value).lstrip().rstrip()

        if clean_value == 'true':
            self._log.info('Got value of "%s" as boolean true.', key)
            return True

        if clean_value == 'false':
            self._log.info('Got value of "%s" as boolean false.', key)
            return False

        try:
            float_value = float(clean_value)
            self._log.info('Got value of "%s" as float "%f".',
                           key,
                           float_value)
            return float_value
        except ValueError:
            self._log.info('Got value of "%s" as string "%s".',
                           key,
                           clean_value)
            return clean_value

Gets the value of the property in the given MatchObject.

Args:
key (str):           Key of the property looked-up.
match (MatchObject): The matched property.

Return:
The discovered value, as a string or boolean.


def _descending_sort(values, axis, return_argsort=False):
    k = array_ops.shape(values)[axis]
    rank = array_ops.rank(values)
    static_rank = values.shape.ndims
    if axis == -1 or axis + 1 == values.get_shape().ndims:
        top_k_input = values
        transposition = None
    else:
        if axis < 0:
            axis += static_rank or rank
        if static_rank is not None:
            transposition = constant_op.constant(np.r_[np.arange(axis), [static_rank - 1], np.arange(axis + 1, static_rank - 1), [axis]], name='transposition')
        else:
            transposition = array_ops.tensor_scatter_update(math_ops.range(rank), [[axis], [rank - 1]], [rank - 1, axis])
        top_k_input = array_ops.transpose(values, transposition)
    values, indices = nn_ops.top_k(top_k_input, k)
    return_value = indices if return_argsort else values
    if transposition is not None:
        return_value = array_ops.transpose(return_value, transposition)
    return return_value

Sorts values in reverse using `top_k`.

Args:
values: Tensor of numeric values.
axis: Index of the axis which values should be sorted along.
return_argsort: If False, return the sorted values. If True, return the
indices that would sort the values.

Returns:
The sorted values.


def framesToFrameRange(frames, sort=True, zfill=0, compress=False):
    if compress:
        frames = unique(set(), frames)
    frames = list(frames)
    if (not frames):
        return ''
    if (len(frames) == 1):
        return pad(frames[0], zfill)
    if sort:
        frames.sort()
    return ','.join(FrameSet.framesToFrameRanges(frames, zfill))

Converts an iterator of frames into a
frame range string.

Args:
frames (collections.Iterable): sequence of frames to process
sort (bool): sort the sequence before processing
zfill (int): width for zero padding
compress (bool): remove any duplicates before processing

Returns:
str:


def deleteReplicationMetadata(
        self, pid, nodeId, serialVersion, vendorSpecific=None
    ):

        response = self.deleteReplicationMetadataResponse(
            pid, nodeId, serialVersion, vendorSpecific
        )
        return self._read_boolean_response(response)

See Also: deleteReplicationMetadataResponse()

Args:
pid:
nodeId:
serialVersion:
vendorSpecific:

Returns:


def add_timing_signal_1d_given_position(x, position, min_timescale=1.0, max_timescale=10000.0):
    channels = common_layers.shape_list(x)[2]
    num_timescales = (channels
    log_timescale_increment = (math.log((float(max_timescale) / float(min_timescale))) / (tf.to_float(num_timescales) - 1))
    inv_timescales = (min_timescale * tf.exp((tf.to_float(tf.range(num_timescales)) * (- log_timescale_increment))))
    scaled_time = (tf.expand_dims(tf.to_float(position), 2) * tf.expand_dims(tf.expand_dims(inv_timescales, 0), 0))
    signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=2)
    signal = tf.pad(signal, [[0, 0], [0, 0], [0, tf.mod(channels, 2)]])
    signal = common_layers.cast_like(signal, x)
    return (x + signal)

Adds sinusoids of diff frequencies to a Tensor, with timing position given.

Args:
x: a Tensor with shape [batch, length, channels]
position: a Tensor with shape [batch, length]
min_timescale: a float
max_timescale: a float

Returns:
a Tensor the same shape as x.


def _get_case_file_paths(tmp_dir, case, training_fraction=0.95):
    paths = tf.gfile.Glob(('%s/*.jpg' % tmp_dir))
    if (not paths):
        raise ValueError(('Search of tmp_dir (%s) ' % tmp_dir), 'for subimage paths yielded an empty list, ', "can't proceed with returning training/eval split.")
    split_index = int(math.floor((len(paths) * training_fraction)))
    if (split_index >= len(paths)):
        raise ValueError(('For a path list of size %s and a training_fraction of %s the resulting split_index of the paths list, %s, would leave no elements for the eval condition.' % (len(paths), training_fraction, split_index)))
    if case:
        return paths[:split_index]
    else:
        return paths[split_index:]

Obtain a list of image paths corresponding to training or eval case.

Args:
tmp_dir: str, the root path to which raw images were written, at the
top level having meta/ and raw/ subdirs.
case: bool, whether obtaining file paths for training (true) or eval
(false).
training_fraction: float, the fraction of the sub-image path list to
consider as the basis for training examples.

Returns:
list: A list of file paths.

Raises:
ValueError: if images not found in tmp_dir, or if training_fraction would
leave no examples for eval.


def mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs):

        axis = self._get_axis_number(axis) if axis is not None else 0
        data = self._validate_dtypes_sum_prod_mean(
            axis, numeric_only, ignore_axis=False
        )
        return data._reduce_dimension(
            data._query_compiler.mean(
                axis=axis,
                skipna=skipna,
                level=level,
                numeric_only=numeric_only,
                **kwargs
            )
        )

Computes mean across the DataFrame.

Args:
axis (int): The axis to take the mean on.
skipna (bool): True to skip NA values, false otherwise.

Returns:
The mean of the DataFrame. (Pandas series)


def read_file(filename):
    hits = glob.glob('**/{}'.format(filename), recursive=True)
    if (not len(hits)):
        pf.debug('No file "{}" found.'.format(filename))
        return ''
    elif (len(hits) > 1):
        pf.debug('File pattern "{}" ambiguous. Using first.'.format(filename))
    with open(hits[0], 'r') as f:
        return f.read()

Reads a file which matches the pattern `filename`.

Args:
filename The filename pattern

Returns:
The file content or the empty string, if the file is not found.


def write_plot(plot, filename, width=DEFAULT_PAGE_WIDTH, height=DEFAULT_PAGE_HEIGHT, unit=DEFAULT_PAGE_UNIT):

    svg = plot_to_svg(plot, width, height, unit)
    with open(filename, 'w') as outfile:
        outfile.write(svg)

Writes a plot SVG to a file.

Args:
plot (list): a list of layers to plot
filename (str): the name of the file to write
width (float): the width of the output SVG
height (float): the height of the output SVG
unit (str): the unit of the height and width


def filter_single_value(cls, part_info, error_msg=None):
    filtered = cls.filter_values(part_info)
    if (len(filtered) != 1):
        if (error_msg is None):
            error_msg = ('Expected a single %s, got %s of them' % (cls.__name__, len(filtered)))
        raise BadValueError(error_msg)
    return filtered[0]

Filter the part_info dict list looking for a single instance of our
class

Args:
part_info (dict): {part_name: [Info] or None} as returned from
Controller.run_hook()
error_msg (str, optional): Specific error message to show if
there isn't a single value

Returns:
info subclass of cls


def delete_load_balancer(access_token, subscription_id, resource_group, lb_name):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Network/loadBalancers/', lb_name, '?api-version=', NETWORK_API])
    return do_delete(endpoint, access_token)

Delete a load balancer.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
lb_name (str): Name of the load balancer.

Returns:
HTTP response.


def __init__(self, distribution, bijector=None, batch_shape=None, event_shape=None, validate_args=False, name=None):
    parameters = dict(locals())
    name = name or ('' if bijector is None else bijector.name) + distribution.name
    with ops.name_scope(name, values=[event_shape, batch_shape]) as name:
        self._zero = constant_op.constant(0, dtype=dtypes.int32, name='zero')
        self._empty = constant_op.constant([], dtype=dtypes.int32, name='empty')
        if bijector is None:
            bijector = identity_bijector.Identity(validate_args=validate_args)
        self._override_batch_shape = self._maybe_validate_shape_override(batch_shape, distribution.is_scalar_batch(), validate_args, 'batch_shape')
        self._is_batch_override = _logical_not(_logical_equal(_ndims_from_shape(self._override_batch_shape), self._zero))
        self._is_maybe_batch_override = bool(tensor_util.constant_value(self._override_batch_shape) is None or tensor_util.constant_value(self._override_batch_shape).size != 0)
        self._override_event_shape = self._maybe_validate_shape_override(event_shape, distribution.is_scalar_event(), validate_args, 'event_shape')
        self._is_event_override = _logical_not(_logical_equal(_ndims_from_shape(self._override_event_shape), self._zero))
        self._is_maybe_event_override = bool(tensor_util.constant_value(self._override_event_shape) is None or tensor_util.constant_value(self._override_event_shape).size != 0)
        self._needs_rotation = _logical_and(self._is_event_override, _logical_not(self._is_batch_override), _logical_not(distribution.is_scalar_batch()))
        override_event_ndims = _ndims_from_shape(self._override_event_shape)
        self._rotate_ndims = _pick_scalar_condition(self._needs_rotation, override_event_ndims, 0)
        self._reduce_event_indices = math_ops.range(self._rotate_ndims - override_event_ndims, self._rotate_ndims)
    self._distribution = distribution
    self._bijector = bijector
    super(TransformedDistribution, self).__init__(dtype=self._distribution.dtype, reparameterization_type=self._distribution.reparameterization_type, validate_args=validate_args, allow_nan_stats=self._distribution.allow_nan_stats, parameters=parameters, graph_parents=distribution._graph_parents + bijector.graph_parents, name=name)

Construct a Transformed Distribution.

Args:
distribution: The base distribution instance to transform. Typically an
instance of `Distribution`.
bijector: The object responsible for calculating the transformation.
Typically an instance of `Bijector`. `None` means `Identity()`.
batch_shape: `integer` vector `Tensor` which overrides `distribution`
`batch_shape`; valid only if `distribution.is_scalar_batch()`.
event_shape: `integer` vector `Tensor` which overrides `distribution`
`event_shape`; valid only if `distribution.is_scalar_event()`.
validate_args: Python `bool`, default `False`. When `True` distribution
parameters are checked for validity despite possibly degrading runtime
performance. When `False` invalid inputs may silently render incorrect
outputs.
name: Python `str` name prefixed to Ops created by this class. Default:
`bijector.name + distribution.name`.


def need(self, folder, page=None, perpage=None):
    assert (isinstance(page, int) or (page is None))
    assert (isinstance(perpage, int) or (perpage is None))
    return self.get('need', params={'folder': folder, 'page': page, 'perpage': perpage})

Returns lists of files which are needed by this device in order
for it to become in sync.

Args:
folder (str):
page (int): If defined applies pagination accross the
collection of results.
perpage (int): If defined applies pagination across the
collection of results.

Returns:
dict


def assert_zero_imag_part(x, message=None, name='assert_zero_imag_part'):
    with ops.name_scope(name, values=[x]):
        x = tensor_conversion.convert_to_tensor_v2_with_dispatch(x, name='x')
        dtype = x.dtype.base_dtype
        if dtype.is_floating:
            return control_flow_ops.no_op()
        zero = tensor_conversion.convert_to_tensor_v2_with_dispatch(0, dtype=dtype.real_dtype)
        return check_ops.assert_equal(zero, math_ops.imag(x), message=message)

Returns `Op` that asserts Tensor `x` has no non-zero imaginary parts.

Args:
x:  Numeric `Tensor`, real, integer, or complex.
message:  A string message to prepend to failure message.
name:  A name to give this `Op`.

Returns:
An `Op` that asserts `x` has no entries with modulus zero.


def get_test_config_container(params: Dict[str, Any], test_id: str, metric_name: str) -> TestConfigContainer:
    return TestConfigContainer(project=params['project'], metrics_dataset=params['metrics_dataset'], metrics_table=params['metrics_table'], metric_name=metric_name, test_id=test_id, test_description=params['test_description'], test_name=params.get('test_name', None), labels=params.get('labels', None))

Args:
params: Dict containing parameters to run change point analysis.
Returns:
TestConfigContainer object containing test config parameters.


def __new__(cls, stress_matrix):

        obj = super().__new__(cls, stress_matrix)
        return obj.view(cls)

Create a Stress object.  Note that the constructor uses __new__
rather than __init__ according to the standard method of
subclassing numpy ndarrays.

Args:
stress_matrix (3x3 array-like): the 3x3 array-like
representing the stress


def delete(self, ip_dest, next_hop, **kwargs):
    kwargs.update({'delete': True})
    return self._set_route(ip_dest, next_hop, **kwargs)

Delete a static route

Args:
ip_dest (string): The ip address of the destination in the
form of A.B.C.D/E
next_hop (string): The next hop interface or ip address
**kwargs['next_hop_ip'] (string): The next hop address on
destination interface
**kwargs['distance'] (string): Administrative distance for this
route
**kwargs['tag'] (string): Route tag
**kwargs['route_name'] (string): Route name

Returns:
True if the operation succeeds, otherwise False.


def list_json_files(directory, recursive=False):

    json_files = []

    for top, dirs, files in os.walk(directory):
        dirs.sort()

        paths = (os.path.join(top, f) for f in sorted(files))

        json_files.extend(x for x in paths if is_json(x))

        if not recursive:
            break

    return json_files

Return a list of file paths for JSON files within `directory`.

Args:
directory: A path to a directory.
recursive: If ``True``, this function will descend into all
subdirectories.

Returns:
A list of JSON file paths directly under `directory`.


def _find_shape_dtype(fields: Mapping[str, _FieldValue], nrows: Optional[tensor.Tensor], row_partitions: Optional[Sequence[RowPartition]]) -> dtypes.DType:
    field_dtypes = [_field_shape_dtype(v) for v in fields.values()]
    nrows_dtypes = [nrows.dtype] if isinstance(nrows, tensor.Tensor) else []
    rp_dtypes = [] if row_partitions is None else [rp.dtype for rp in row_partitions]
    all_dtypes = field_dtypes + nrows_dtypes + rp_dtypes
    if dtypes.int64 in all_dtypes:
        return dtypes.int64
    if dtypes.int32 in all_dtypes:
        return dtypes.int32
    return dtypes.int64

Return a consistent dtype for fields, nrows, & row_partitions.

In the future, the default will switch from int64 to int32, but for now,
we stick with int64.

Args:
fields: the fields of the StructuredTensor.
nrows: the nrows of the StructuredTensor
row_partitions: the row_partitions of the StructuredTensor.

Returns:
If anything requires int64, then return int64.
If int32 is explicitly specified, return int32. Otherwise, return int64.


def summarize_mean_in_nats_and_bits(inputs, units, name,
                                    nats_name_scope="nats",
                                    bits_name_scope="bits_per_dim"):

  mean = tf.reduce_mean(input_tensor=inputs)
  with tf.compat.v1.name_scope(nats_name_scope):
    tf.compat.v2.summary.scalar(
        name,
        mean,
        step=tf.compat.v1.train.get_or_create_global_step())
  with tf.compat.v1.name_scope(bits_name_scope):
    tf.compat.v2.summary.scalar(
        name,
        mean / units / tf.math.log(2.),
        step=tf.compat.v1.train.get_or_create_global_step())

Summarize the mean of a tensor in nats and bits per unit.

Args:
inputs: A tensor of values measured in nats.
units: The units of the tensor with which to compute the mean bits
per unit.
name: The name of the tensor.
nats_name_scope: The name scope of the nats summary.
bits_name_scope: The name scope of the bits summary.


def GetArchiveTypeIndicators(cls, path_spec, resolver_context=None):
    if ((cls._archive_remainder_list is None) or (cls._archive_store is None)):
        (specification_store, remainder_list) = cls._GetSpecificationStore(definitions.FORMAT_CATEGORY_ARCHIVE)
        cls._archive_remainder_list = remainder_list
        cls._archive_store = specification_store
    if (cls._archive_scanner is None):
        cls._archive_scanner = cls._GetSignatureScanner(cls._archive_store)
    return cls._GetTypeIndicators(cls._archive_scanner, cls._archive_store, cls._archive_remainder_list, path_spec, resolver_context=resolver_context)

Determines if a file contains a supported archive types.

Args:
path_spec (PathSpec): path specification.
resolver_context (Optional[Context]): resolver context, where None
represents the built-in context which is not multi process safe.

Returns:
list[str]: supported format type indicators.


def rename_edges(self, old_node_name, new_node_name):

        graph = self.graph
        for node, edges in graph.items():
            if node == old_node_name:
                graph[new_node_name] = copy(edges)
                del graph[old_node_name]

            else:
                if old_node_name in edges:
                    edges.remove(old_node_name)
                    edges.add(new_node_name)

Change references to a node in existing edges.

Args:
old_node_name (str): The old name for the node.
new_node_name (str): The new name for the node.


def l1_distance(t1, t2, name=None):
    with tf.name_scope(name, 'l1_distance', [t1, t2]) as scope:
        t1 = tf.convert_to_tensor(t1, name='t1')
        t2 = tf.convert_to_tensor(t2, name='t2')
        sub = tf.subtract(t1, t2)
        reduction_dim = _last_index(sub, 1)
        return tf.reduce_sum(tf.abs(sub), reduction_dim, name=scope)

l1 distance between t1 and t2.

Args:
t1: A tensor.
t2: A tensor that is the same size as t1.
name: Optional name for this op.
Returns:
The l1 distance between t1 and t2.


def status(self, workflow_id):
    self.logger.debug(('Get status of workflow: ' + workflow_id))
    url = ('%(wf_url)s/%(wf_id)s' % {'wf_url': self.workflows_url, 'wf_id': workflow_id})
    r = self.gbdx_connection.get(url)
    r.raise_for_status()
    return r.json()['state']

Checks workflow status.

Args:
workflow_id (str): Workflow id.

Returns:
Workflow status (str).


def del_rules(cls, *names, attr=None):

        if attr is None:
            attr = cls._rules_attr()
        if len(names) == 0:
            getattr(cls, attr)
            setattr(cls, attr, OrderedDict())
        else:
            for name in names:
                del getattr(cls, attr)[name]

Delete algebraic rules used by :meth:`create`

Remove the rules with the given `names`, or all rules if no names are
given

Args:
names (str): Names of rules to delete
attr (None or str): Name of the class attribute from which to
delete the rules. Cf. :meth:`add_rule`.

Raises:
KeyError: If any rules in `names` does not exist
AttributeError: If invalid `attr`


def substitute(self, var_map):

        if self in var_map:
            return var_map[self]
        return self._substitute(var_map)

Substitute sub-expressions

Args:
var_map (dict): Dictionary with entries of the form
``{expr: substitution}``


def image_transform(X, function, reshape_before=False, reshape_after=False, width=None, height=None, **kwargs):
    if (not callable(function)):
        function = import_object(function)
    elif (not callable(function)):
        raise ValueError('function must be a str or a callable')
    flat_image = (len(X[0].shape) == 1)
    if (reshape_before and flat_image):
        if (not (width and height)):
            side_length = math.sqrt(X.shape[1])
            if side_length.is_integer():
                side_length = int(side_length)
                width = side_length
                height = side_length
            else:
                raise ValueError('Image sizes must be given for non-square images')
    else:
        reshape_before = False
    new_X = []
    for image in X:
        if reshape_before:
            image = image.reshape((width, height))
        features = function(image, **kwargs)
        if reshape_after:
            features = np.reshape(features, X.shape[1])
        new_X.append(features)
    return np.array(new_X)

Apply a function image by image.

Args:
reshape_before: whether 1d array needs to be reshaped to a 2d image
reshape_after: whether the returned values need to be reshaped back to a 1d array
width: image width used to rebuild the 2d images. Required if the image is not square.
height: image height used to rebuild the 2d images. Required if the image is not square.


def __init__(self, prefix='/api/2/', **url_values):

        self._http = registry.http_handler
        self._prefix = prefix
        self._modified_fields = {}
        self._populated_fields = {}

        for field in url_values:
            if field in self.url_fields:
                setattr(self, field, url_values[field])
            else:
                self._handle_wrong_field(field, ATTR_TYPE_URL)

        self._is_initialized = True

Constructor.

Initializes various variables, setup the HTTP handler and
stores all values

Args:
prefix: The prefix of the urls.
Raises:
AttributeError: if not all values for parameters in `url_fields`
are passed


def track_progress(func, tasks, bar_width=50, **kwargs):
    if isinstance(tasks, tuple):
        assert (len(tasks) == 2)
        assert isinstance(tasks[0], collections_abc.Iterable)
        assert isinstance(tasks[1], int)
        task_num = tasks[1]
        tasks = tasks[0]
    elif isinstance(tasks, collections_abc.Iterable):
        task_num = len(tasks)
    else:
        raise TypeError('"tasks" must be an iterable object or a (iterator, int) tuple')
    prog_bar = ProgressBar(task_num, bar_width)
    results = []
    for task in tasks:
        results.append(func(task, **kwargs))
        prog_bar.update()
    sys.stdout.write('\n')
    return results

Track the progress of tasks execution with a progress bar.

Tasks are done with a simple for-loop.

Args:
func (callable): The function to be applied to each task.
tasks (list or tuple[Iterable, int]): A list of tasks or
(tasks, total num).
bar_width (int): Width of progress bar.

Returns:
list: The task results.


def fileSave(self, filePath=None, updatePath=False):

        if not filePath:
            filePath = self.filePath
        if not os.path.isfile(filePath):
            print("Data file '%s' does not exist, will create new file." % (filePath))
            if not os.path.exists(os.path.split(filePath)[0]):
                os.makedirs(os.path.split(filePath)[0])
        dataJsonString = json.dumps(self.data, indent=4, sort_keys=True)
        print("Writing to file '%s' ... " % (filePath), end="", flush=True)
        with open(filePath, "w") as fileout:
            fileout.write(dataJsonString)
        print("Wrote file!")
        if updatePath:
            self.filePath = filePath

Write the internal JSON data dictionary to a JSON data file.

If no file path is provided, the stored data file path will be used.

Args:
filePath (Optional[str]): A relative or absolute path to a
'.json' file. Defaults to None.
updatePath (Optional[bool]): Specifies whether or not to update
the stored data file path. Defaults to False.


def expand(self, tags, clique_scoring_func=None):
    lattice = Lattice()
    overlapping_spans = []

    def end_token_index():
        return max([t.get('end_token') for t in overlapping_spans])
    for i in xrange(len(tags)):
        tag = tags[i]
        if ((len(overlapping_spans) > 0) and (end_token_index() >= tag.get('start_token'))):
            overlapping_spans.append(tag)
        elif (len(overlapping_spans) > 1):
            cliques = list(self._sub_expand(overlapping_spans))
            if clique_scoring_func:
                cliques = sorted(cliques, key=(lambda e: ((- 1) * clique_scoring_func(e))))
            lattice.append(cliques)
            overlapping_spans = [tag]
        else:
            lattice.append(overlapping_spans)
            overlapping_spans = [tag]
    if (len(overlapping_spans) > 1):
        cliques = list(self._sub_expand(overlapping_spans))
        if clique_scoring_func:
            cliques = sorted(cliques, key=(lambda e: ((- 1) * clique_scoring_func(e))))
        lattice.append(cliques)
    else:
        lattice.append(overlapping_spans)
    return lattice.traverse()

This is the main function to expand tags into cliques

Args:
tags (list): a list of tags to find the cliques.
clique_scoring_func (func): a function that returns a float
value for the clique

Returns:
list : a list of cliques


def _safe_exec_func(self, func, *args):
    try:
        return func(*args)
    except signals.TestAbortAll:
        raise
    except Exception:
        logging.exception('Exception happened when executing %s in %s.', func.__name__, self.TAG)

Executes a function with exception safeguard.

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

Args:
func: Function to be executed.
args: Arguments to be passed to the function.

Returns:
Whatever the function returns.


def set_description(self, vrf_name, description=None, default=False, disable=False):
    cmds = self.command_builder('description', value=description, default=default, disable=disable)
    return self.configure_vrf(vrf_name, cmds)

Configures the VRF description

Args:
vrf_name (str): The VRF name to configure
description(str): The string to set the vrf description to
default (bool): Configures the vrf description to its default value
disable (bool): Negates the vrf description

Returns:
True if the operation was successful otherwise False


def erfinv(x, name='erfinv'):
    with ops.name_scope(name, values=[x]):
        x = ops.convert_to_tensor(x, name='x')
        if x.dtype.as_numpy_dtype not in [np.float32, np.float64]:
            raise TypeError('x.dtype=%s is not handled, see docstring for supported types.' % x.dtype)
        return ndtri((x + 1.0) / 2.0) / np.sqrt(2)

The inverse function for erf, the error function.

Args:
x: `Tensor` of type `float32`, `float64`.
name: Python string. A name for the operation (default="erfinv").

Returns:
x: `Tensor` with `dtype=x.dtype`.

Raises:
TypeError: if `x` is not floating-type.


def GetPresetByName(self, name):
    name = name.lower()
    return self._definitions.get(name, None)

Retrieves a specific preset definition by name.

Args:
name (str): name of the preset.

Returns:
ParserPreset: a parser preset or None if not available.


def len_header(filename):
    with open(filename, 'rb') as f:
        header_sub_count = 0
        eoh_found = False
        while (not eoh_found):
            header_sub = f.read(512)
            header_sub_count += 1
            if (b'HEADER_END' in header_sub):
                idx_end = (header_sub.index(b'HEADER_END') + len(b'HEADER_END'))
                eoh_found = True
                break
        idx_end = (((header_sub_count - 1) * 512) + idx_end)
    return idx_end

Return the length of the blimpy header, in bytes

Args:
filename (str): name of file to open

Returns:
idx_end (int): length of header, in bytes


def _kmc2_multiple_centers(self):
    first_shard = self._inputs[0]
    batch_size = array_ops.shape(first_shard)[0]
    max_to_sample = math_ops.cast(batch_size / self._kmc2_chain_length, dtype=dtypes.int32)
    num_to_sample = math_ops.maximum(math_ops.minimum(self._num_remaining, max_to_sample), 1)

    def _cond(i, _):

        return math_ops.less(i, num_to_sample)

    def _body(i, _):

        def _sample_random():

            new_center = array_ops.reshape(first_shard[0], [1, -1])
            if self._distance_metric == COSINE_DISTANCE:
                new_center = nn_impl.l2_normalize(new_center, dim=1)
            return new_center

        def _sample_kmc2_chain():

            start = i * self._kmc2_chain_length
            end = start + self._kmc2_chain_length
            subset = first_shard[start:end]
            _, distances = gen_clustering_ops.nearest_neighbors(subset, self._cluster_centers, 1)
            new_center_index = gen_clustering_ops.kmc2_chain_initialization(array_ops.squeeze(distances), self._seed)
            newly_sampled_center = array_ops.reshape(subset[new_center_index], [1, -1])
            if self._distance_metric == COSINE_DISTANCE:
                newly_sampled_center = nn_impl.l2_normalize(newly_sampled_center, dim=1)
            return array_ops.concat([self._cluster_centers, newly_sampled_center], 0)
        new_centers = cond.cond(math_ops.equal(self._num_selected, 0), _sample_random, _sample_kmc2_chain)
        assigned_centers = state_ops.assign(self._cluster_centers, new_centers, validate_shape=False)
        if self._cluster_centers_updated is not self._cluster_centers:
            assigned_centers = state_ops.assign(self._cluster_centers_updated, assigned_centers, validate_shape=False)
        return (i + 1, self._num_clusters - array_ops.shape(assigned_centers)[0])
    _, num_remaining = while_loop.while_loop(_cond, _body, [0, 0])
    return num_remaining

Adds new initial cluster centers using the k-MC2 algorithm.

In each call to the op, the provided batch is split into subsets based on
the specified `kmc2_chain_length`. On each subset, a single Markov chain of
the k-MC2 algorithm is used to add *one* new center cluster center. If there
are less than `kmc2_chain_length` points in the subset, a single center is
added using one Markov chain on the full input. It is assumed that the
provided batch has previously been randomly permuted. Otherwise, k-MC2 may
return suboptimal centers.

Returns:
An op that adds new cluster centers.


def create_from_binary(cls, binary_view):

        attr_type, attr_len, non_resident, name_len, name_offset, flags, attr_id, \
        content_len, content_offset, indexed_flag = cls._REPR.unpack(binary_view[:cls._REPR.size])

        if name_len:
            name = binary_view[name_offset:name_offset+(2*name_len)].tobytes().decode("utf_16_le")
        else:
            name = None

        nw_obj = cls((AttrTypes(attr_type), attr_len, bool(non_resident), AttrFlags(flags), attr_id, name),
                        (content_len, content_offset, indexed_flag))

        return nw_obj

Creates a new object AttributeHeader from a binary stream. The binary
stream can be represented by a byte string, bytearray or a memoryview of the
bytearray.

Args:
binary_view (memoryview of bytearray) - A binary stream with the
information of the attribute

Returns:
AttributeHeader: New object using hte binary stream as source


def entry_from_raw(self, rval: RawEntry, jptr: JSONPointer = "") -> EntryValue:

        return super().from_raw(rval, jptr)

Transform a raw (leaf-)list entry into the cooked form.

Args:
rval: raw entry (scalar or object)
jptr: JSON pointer of the entry

Raises:
NonexistentSchemaNode: If a member inside `rval` is not defined
in the schema.
RawTypeError: If a scalar value inside `rval` is of incorrect type.


def _color_level(str_, level):

    fore_color, back_color, styles = _get_style_from_config(level)
    return _color(str_, fore_color, back_color, styles)

Return the string wrapped with the appropriate styling for the message
level.  The styling will be determined based on the rez configuration.

Args:
str_ (str): The string to be wrapped.
level (str): The message level. Should be one of 'critical', 'error',
'warning', 'info' or 'debug'.

Returns:
str: The string styled with the appropriate escape sequences.


def is10(msg):

    if allzeros(msg):
        return False

    d = hex2bin(data(msg))

    if d[0:8] != '00010000':
        return False

    if bin2int(d[9:14]) != 0:
        return False

    if d[14] == '1' and bin2int(d[16:23]) < 5:
        return False
    if d[14] == '0' and bin2int(d[16:23]) > 4:
        return False

    return True

Check if a message is likely to be BDS code 1,0

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

Returns:
bool: True or False


def _process_path_prefix(path_prefix):

  _validate_path(path_prefix)
  if not _GCS_PATH_PREFIX_REGEX.match(path_prefix):
    raise ValueError('Path prefix should have format /bucket, /bucket/, '
                     'or /bucket/prefix but got %s.' % path_prefix)
  bucket_name_end = path_prefix.find('/', 1)
  bucket = path_prefix
  prefix = None
  if bucket_name_end != -1:
    bucket = path_prefix[:bucket_name_end]
    prefix = path_prefix[bucket_name_end + 1:] or None
  return bucket, prefix

Validate and process a Google Cloud Stoarge path prefix.

Args:
path_prefix: a Google Cloud Storage path prefix of format '/bucket/prefix'
or '/bucket/' or '/bucket'.

Raises:
ValueError: if path is invalid.

Returns:
a tuple of /bucket and prefix. prefix can be None.


def generate_samples(order, domain=1, rule='R', antithetic=None):
    logger = logging.getLogger(__name__)
    logger.debug('generating random samples using rule %s', rule)
    rule = rule.upper()
    if isinstance(domain, int):
        dim = domain
        trans = (lambda x_data: x_data)
    elif isinstance(domain, (tuple, list, numpy.ndarray)):
        domain = numpy.asfarray(domain)
        if (len(domain.shape) < 2):
            dim = 1
        else:
            dim = len(domain[0])
        trans = (lambda x_data: (((domain[1] - domain[0]) * x_data.T) + domain[0]).T)
    else:
        dist = domain
        dim = len(dist)
        trans = dist.inv
    if (antithetic is not None):
        from .antithetic import create_antithetic_variates
        antithetic = numpy.array(antithetic, dtype=bool).flatten()
        if ((antithetic.size == 1) and (dim > 1)):
            antithetic = numpy.repeat(antithetic, dim)
        size = numpy.sum((1 * numpy.array(antithetic)))
        order_saved = order
        order = int(numpy.log((order - dim)))
        order = (order if (order > 1) else 1)
        while ((order ** dim) < order_saved):
            order += 1
        trans_ = trans
        trans = (lambda x_data: trans_(create_antithetic_variates(x_data, antithetic)[(:, :order_saved)]))
    assert (rule in SAMPLERS), 'rule not recognised'
    sampler = SAMPLERS[rule]
    x_data = trans(sampler(order=order, dim=dim))
    logger.debug('order: %d, dim: %d -> shape: %s', order, dim, x_data.shape)
    return x_data

Sample generator.

Args:
order (int):
Sample order. Determines the number of samples to create.
domain (Dist, int, numpy.ndarray):
Defines the space where the samples are generated. If integer is
provided, the space ``[0, 1]^domain`` will be used. If array-like
object is provided, a hypercube it defines will be used. If
distribution, the domain it spans will be used.
rule (str):
rule for generating samples. The various rules are listed in
:mod:`chaospy.distributions.sampler.generator`.
antithetic (tuple):
Sequence of boolean values. Represents the axes to mirror using
antithetic variable.


def leaky_relu(x, name=None):
    with tf.name_scope(name, 'leaky_relu', [x]) as scope:
        x = tf.convert_to_tensor(x, name='x')
        return tf.where(tf.less(x, 0.0), (0.01 * x), x, name=scope)

Creates a leaky_relu.

This is an alternate non-linearity to relu. The leaky part of the relu may
prevent dead Neurons in a model since the gradient doesn't go completely to
0.

Args:
x: The input tensor.
name: Optional name for this op.
Returns:
x if x > 0 otherwise 0.01 * x.


def from_textfile(cls, textfile, workers=1, job_size=1000):
    c = Counter()
    if isinstance(textfile, string_types):
        textfile = TextFile(textfile)
    for result in textfile.apply(count, workers, job_size):
        c.update(result)
    return CountedVocabulary(word_count=c)

Count the set of words appeared in a text file.

Args:
textfile (string): The name of the text file or `TextFile` object.
min_count (integer): Minimum number of times a word/token appeared in the document
to be considered part of the vocabulary.
workers (integer): Number of parallel workers to read the file simulatenously.
job_size (integer): Size of the batch send to each worker.
most_frequent (integer): if no min_count is specified, consider the most frequent k words for the vocabulary.

Returns:
A vocabulary of the most frequent words appeared in the document.


def format_and_is_storage(path):
    if (not hasattr(path, 'read')):
        path = fsdecode(path).replace('\\', '/')
        return (path, is_storage(path))
    return (path, True)

Checks if path is storage and format it.

If path is an opened file-like object, returns is storage as True.

Args:
path (path-like object or file-like object):

Returns:
tuple: str or file-like object (Updated path),
bool (True if is storage).


def save_replay(self, replay_data, replay_dir, prefix=None):
    if (not prefix):
        replay_filename = ''
    elif (os.path.sep in prefix):
        raise ValueError(("Prefix '%s' contains '%s', use replay_dir instead." % (prefix, os.path.sep)))
    else:
        replay_filename = (prefix + '_')
    now = datetime.datetime.utcnow().replace(microsecond=0)
    replay_filename += ('%s.SC2Replay' % now.isoformat('-').replace(':', '-'))
    replay_dir = self.abs_replay_path(replay_dir)
    if (not gfile.Exists(replay_dir)):
        gfile.MakeDirs(replay_dir)
    replay_path = os.path.join(replay_dir, replay_filename)
    with gfile.Open(replay_path, 'wb') as f:
        f.write(replay_data)
    return replay_path

Save a replay to a directory, returning the path to the replay.

Args:
replay_data: The result of controller.save_replay(), ie the binary data.
replay_dir: Where to save the replay. This can be absolute or relative.
prefix: Optional prefix for the replay filename.

Returns:
The full path where the replay is saved.

Raises:
ValueError: If the prefix contains the path seperator.


def update_from_yaml(self, path=join('config', 'hdx_dataset_static.yml')):

        super(Dataset, self).update_from_yaml(path)
        self.separate_resources()

Update dataset metadata with static metadata from YAML file

Args:
path (str): Path to YAML dataset metadata. Defaults to config/hdx_dataset_static.yml.

Returns:
None


def fastcc(model, epsilon, solver):

    reaction_set = set(model.reactions)
    subset = set(reaction_id for reaction_id in reaction_set
                 if model.limits[reaction_id].lower >= 0)

    logger.info('Checking {} irreversible reactions...'.format(len(subset)))
    logger.debug('|J| = {}, J = {}'.format(len(subset), subset))

    p = FastcoreProblem(model, solver, epsilon=epsilon)
    p.lp7(subset)

    consistent_subset = set(
        reaction_id for reaction_id in model.reactions
        if abs(p.get_flux(reaction_id)) >= 0.999 * epsilon)

    logger.debug('|A| = {}, A = {}'.format(
        len(consistent_subset), consistent_subset))

    for reaction in subset - consistent_subset:

        yield reaction

    subset = (reaction_set - subset) - consistent_subset

    logger.info('Checking reversible reactions...')
    logger.debug('|J| = {}, J = {}'.format(len(subset), subset))

    flipped = False
    singleton = False
    while len(subset) > 0:
        logger.info('{} reversible reactions left to check...'.format(
            len(subset)))
        if singleton:
            reaction = next(iter(subset))
            subset_i = {reaction}

            logger.debug('LP3 on {}'.format(subset_i))
            p.maximize({reaction: -1 if p.is_flipped(reaction) else 1})
        else:
            subset_i = subset

            logger.debug('LP7 on {}'.format(subset_i))
            p.lp7(subset_i)

        consistent_subset.update(
            reaction_id for reaction_id in subset
            if abs(p.get_flux(reaction_id) >= 0.999 * epsilon))

        logger.debug('|A| = {}, A = {}'.format(
            len(consistent_subset), consistent_subset))

        if not subset.isdisjoint(consistent_subset):
            subset -= consistent_subset
            logger.debug('|J| = {}, J = {}'.format(len(subset), subset))
            flipped = False
        else:

            subset_rev_i = subset_i & model.reversible
            if flipped or len(subset_rev_i) == 0:
                flipped = False
                if singleton:
                    subset -= subset_rev_i
                    for reaction in subset_rev_i:
                        logger.info('Inconsistent: {}'.format(reaction))
                        yield reaction
                else:
                    singleton = True
            else:
                p.flip(subset_rev_i)
                flipped = True
                logger.info('Flipped {} reactions'.format(len(subset_rev_i)))

Check consistency of model reactions.

Yield all reactions in the model that are not part of the consistent
subset.

Args:
model: :class:`MetabolicModel` to solve.
epsilon: Flux threshold value.
solver: LP solver instance to use.


def export(self, path, variables_saver=None):
    proto = saved_model_pb2.SavedModel()
    proto.CopyFrom(self._proto)
    assets_map = _make_assets_key_collection(proto, path)
    self._save_all_assets(path, assets_map)
    self._save_variables(path, variables_saver)
    self._save_proto(path, proto)

Exports to SavedModel directory.

Args:
path: path where to export the SavedModel to.
variables_saver: lambda that receives a directory path where to
export checkpoints of variables.


def get_string(self, ionicstep_start=1,
                   ionicstep_end=None,
                   significant_figures=8):

        from pymatgen.io.vasp import Poscar
        if (ionicstep_start < 1):
            raise Exception('Start ionic step cannot be less than 1')
        if (ionicstep_end is not None and
                ionicstep_start < 1):
            raise Exception('End ionic step cannot be less than 1')
        latt = self.structures[0].lattice
        if np.linalg.det(latt.matrix) < 0:
            latt = Lattice(-latt.matrix)
        lines = [self.comment, "1.0", str(latt)]
        lines.append(" ".join(self.site_symbols))
        lines.append(" ".join([str(x) for x in self.natoms]))
        format_str = "{{:.{0}f}}".format(significant_figures)
        ionicstep_cnt = 1
        output_cnt = 1
        for cnt, structure in enumerate(self.structures):
            ionicstep_cnt = cnt + 1
            if ionicstep_end is None:
                if (ionicstep_cnt >= ionicstep_start):
                    lines.append("Direct configuration=" +
                                 ' ' * (7 - len(str(output_cnt))) + str(output_cnt))
                    for (i, site) in enumerate(structure):
                        coords = site.frac_coords
                        line = " ".join([format_str.format(c) for c in coords])
                        lines.append(line)
                    output_cnt += 1
            else:
                if ionicstep_start <= ionicstep_cnt < ionicstep_end:
                    lines.append("Direct configuration=" +
                                 ' ' * (7 - len(str(output_cnt))) + str(output_cnt))
                    for (i, site) in enumerate(structure):
                        coords = site.frac_coords
                        line = " ".join([format_str.format(c) for c in coords])
                        lines.append(line)
                    output_cnt += 1
        return "\n".join(lines) + "\n"

Write  Xdatcar class into a file
Args:
filename (str): Filename of output XDATCAR file.
ionicstep_start (int): Starting number of ionic step.
ionicstep_end (int): Ending number of ionic step.


def _create_forward(out_node):

  retval = out_node.body[0].body[-1]
  if len(retval.value.elts) == 1:
    retval.value = retval.value.elts[0]
  return out_node

Create a user-friendly forward function.

Ensures that a single value instead of a tuple is returned if the user asked
for the gradient with respect to only one input.

Args:
out_node: The function definition AST.

Returns:
The function definition with potentially changed return statement.


def _render_list(self, items, empty='
<empty>
'):

    if not items or len(items) == 0:
      self._segments.append(empty)
      return
    self._segments.append('
')
    for o in items:
      self._segments.append('
')
      self._segments.append(str(o))
      self._segments.append('
')
    self._segments.append('
')

Renders an HTML list with the specified list of strings.

Args:
items: the iterable collection of objects to render.
empty: what to render if the list is None or empty.


def _index_matrix(layout: layout_lib.Layout, elem_spec: tensor_spec.TensorSpec) -> tensor.Tensor:
    matrix = []
    for dim in layout.mesh.dim_names:
        row = [0]
        for layout_idx, spec in enumerate(layout.sharding_specs[1:]):
            if spec == layout_lib.UNSHARDED or spec != dim:
                row.append(0)
            else:
                row.append(elem_spec.shape[layout_idx]
        matrix.append(row)
    return constant_op.constant(matrix, dtype=dtypes.int32)

Computes a utility matrix to derive device-based slice offsets.

This function builds a matrix of shape `[mesh.rank, layout.rank]` for each
dataset element. This matrix can be used to slice the DTensor components
returned by the iterator according to the local device that component is to be
placed on. This can be done by multiplying the device offsets of shape
`[1, mesh.rank]` with this index matrix to get a `[1, layout.rank]` shape
tensor containing the slice offsets.

Note: the index on the batch dim is always 0 since sharding on the batch
dimension is handled by either tf.data.Dataset's shard transformation (in the
single-client case) or tf.data service's distribute function (in the
multi-client case). If there is no sharding on the batch dimension (or any
other dimension), the slice index remains 0.

Args:
layout: the layout of the dataset element.
elem_spec: the spec of the dataset element.

Returns:
The index matrix as a tensor.


def __call__(self, shape, dtype=None, **kwargs):
    del kwargs
    return constant_op.constant(self.value, dtype=_get_dtype(dtype), shape=shape)

Returns a tensor object initialized to `self.value`.

Args:
shape: Shape of the tensor.
dtype: Optional dtype of the tensor. If not specified,
`tf.keras.backend.floatx()` is used,
which default to `float32` unless you configured it otherwise
(via `tf.keras.backend.set_floatx(float_dtype)`).
**kwargs: Additional keyword arguments.


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 infer_location(
            self,
            location_query,
            max_distance,
            google_key,
            foursquare_client_id,
            foursquare_client_secret,
            limit
        ):

        self.location_from = infer_location(
            self.points[0],
            location_query,
            max_distance,
            google_key,
            foursquare_client_id,
            foursquare_client_secret,
            limit
        )
        self.location_to = infer_location(
            self.points[-1],
            location_query,
            max_distance,
            google_key,
            foursquare_client_id,
            foursquare_client_secret,
            limit
        )

        return self

In-place location inferring

See infer_location function

Args:
Returns:
:obj:`Segment`: self


def _ParseSystemTime(self, byte_stream):

    systemtime_map = self._GetDataTypeMap('systemtime')

    try:
      systemtime = self._ReadStructureFromByteStream(
          byte_stream, 0, systemtime_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.ParseError(
          'Unable to parse SYSTEMTIME value with error: {0!s}'.format(
              exception))

    system_time_tuple = (
        systemtime.year, systemtime.month, systemtime.weekday,
        systemtime.day_of_month, systemtime.hours, systemtime.minutes,
        systemtime.seconds, systemtime.milliseconds)

    if system_time_tuple == self._EMPTY_SYSTEM_TIME_TUPLE:
      return None

    try:
      return dfdatetime_systemtime.Systemtime(
          system_time_tuple=system_time_tuple)
    except ValueError:
      raise errors.ParseError(
          'Invalid SYSTEMTIME value: {0!s}'.format(system_time_tuple))

Parses a SYSTEMTIME date and time value from a byte stream.

Args:
byte_stream (bytes): byte stream.

Returns:
dfdatetime.Systemtime: SYSTEMTIME date and time value or None if no
value is set.

Raises:
ParseError: if the SYSTEMTIME could not be parsed.


def check(self, namespace, level, explicit=False):

        return (self.get_permissions(namespace, explicit=explicit) & level) != 0

Checks if the permset has permission to the specified namespace
at the specified level

Arguments:

namespace -- permissioning namespace (str)
level -- permissioning level (int) (PERM_READ for example)
explicit -- require explicitly set permissions to the provided namespace

Returns:

bool


def bitwise_invert(x):
    if any_symbolic_tensors((x,)):
        return BitwiseInvert().symbolic_call(x)
    return backend.numpy.bitwise_invert(x)

Compute bit-wise inversion, or bit-wise NOT, element-wise.

Computes the bit-wise NOT of the underlying binary representation of the
integers in the input arrays. This ufunc implements the C/Python operator
`~`.

Args:
x: Input integer tensor.

Returns:
Result tensor.


def convert_to_tf_dataset_compatible(cls, x):
    return x

Convert a tensor to something compatible with `tf.data.Dataset`.

This can be a NumPy array, `tf.Tensor` or any other type of tensor that
`tf.data.Dataset.from_tensors` can consume.
Only called on a full array as provided by the user.

Args:
x: the tensor to convert.
Returns: converted version tensor.


def take_quality_screenshot(self, screenshot_name):
    self.info_log('Taking a quality screenshot...')
    if self.test_instance._runner_dir:
        _screenshot_name = ('%s.png' % string_to_filename(screenshot_name))
        relative_path = os.path.join(self.test_instance._quality_screenshot_relative_dir, _screenshot_name)
        full_path = os.path.join(self.test_instance._quality_screenshot_dir, _screenshot_name)
        self._driver.save_screenshot(full_path)
        with DbSessionContext(BROME_CONFIG['database']['mongo_database_name']) as session:
            capabilities = {'browserName': self.capabilities['browserName'], 'platform': self.capabilities['platform'], 'version': self.capabilities['version']}
            quality_screenshot = Testqualityscreenshot()
            quality_screenshot.timestamp = utcnow()
            quality_screenshot.browser_capabilities = capabilities
            quality_screenshot.browser_id = self.get_id()
            quality_screenshot.file_path = relative_path
            quality_screenshot.location = 'local_file_system'
            quality_screenshot.root_path = self.test_instance._runner.root_test_result_dir
            quality_screenshot.extra_data = {}
            quality_screenshot.title = screenshot_name
            quality_screenshot.test_instance_id = self.test_instance._test_instance_id
            quality_screenshot.test_batch_id = self.test_instance._test_batch_id
            session.save(quality_screenshot, safe=True)
        self.debug_log(('Quality screenshot taken (%s)' % full_path))

Take a quality screenshot

Use the screenshot_name args when you want to take a
screenshot for reference

Args:
screenshot_name (str) the name of the screenshot


def get_features_range(model_settings):
    if model_settings['preprocess'] == 'average':
        features_min = 0.0
        features_max = 127.5
    elif model_settings['preprocess'] == 'mfcc':
        features_min = -247.0
        features_max = 30.0
    elif model_settings['preprocess'] == 'micro':
        features_min = 0.0
        features_max = 26.0
    else:
        raise Exception('Unknown preprocess mode "%s" (should be "mfcc", "average", or "micro")' % model_settings['preprocess'])
    return (features_min, features_max)

Returns the expected min/max for generated features.

Args:
model_settings: Information about the current model being trained.

Returns:
Min/max float pair holding the range of features.

Raises:
Exception: If preprocessing mode isn't recognized.


def address(self, ip, **kwargs):
    indicator_obj = Address(ip, **kwargs)
    return self._indicator(indicator_obj)

Add Address data to Batch object.

Args:
ip (str): The value for this Indicator.
confidence (str, kwargs): The threat confidence for this Indicator.
date_added (str, kwargs): The date timestamp the Indicator was created.
last_modified (str, kwargs): The date timestamp the Indicator was last modified.
rating (str, kwargs): The threat rating for this Indicator.
xid (str, kwargs): The external id for this Indicator.

Returns:
obj: An instance of Address.


def build_backend(self, backend_node):
    proxy_name = backend_node.backend_header.proxy_name.text
    config_block_lines = self.__build_config_block(backend_node.config_block)
    return config.Backend(name=proxy_name, config_block=config_block_lines)

parse `backend` sections

Args:
backend_node (TreeNode): Description

Returns:
config.Backend: an object


def _get_trainable_state(self):
    layers = self._flatten_layers(include_self=False, recursive=False)
    trainable_state = {self: self.trainable}
    for l in layers:
        trainable_state.update(l._get_trainable_state())
    return trainable_state

Get the `trainable` state of each sublayer.

Returns:
A dict mapping all sublayers to their `trainable` value.


def __init__(self, shape, dtype=dtypes.float32, name=None):
    self._shape = tensor_shape.TensorShape(shape)
    self._dtype = dtypes.as_dtype(dtype)
    self._name = name

Creates a TensorSpec.

Args:
shape: Value convertible to `tf.TensorShape`. The shape of the tensor.
dtype: Value convertible to `tf.DType`. The type of the tensor values.
name: Optional name for the Tensor.

Raises:
TypeError: If shape is not convertible to a `tf.TensorShape`, or dtype is
not convertible to a `tf.DType`.


def tensor_layout(self, arg):

    if isinstance(arg, Tensor):
      arg = arg.shape
    return self.layout_rules.tensor_layout(arg, self.shape)

Compute TensorLayout for a Tensor or a Shape.

Args:
arg: Tensor or Shape.

Returns:
TensorLayout.


def evaluated_variants(self, case_id):

        query = {
            '$and': [
                {'case_id': case_id},
                {
                    '$or': [
                        {'acmg_classification': {'$exists': True}},
                        {'manual_rank': {'$exists': True}},
                        {'dismiss_variant': {'$exists': True}},
                    ]
                }
            ],
        }

        variants = {}
        for var in self.variant_collection.find(query):
            variants[var['variant_id']] = self.add_gene_info(var)

        event_query = {
            '$and': [
                {'case': case_id},
                {'category': 'variant'},
                {'verb': 'comment'},
            ]
        }

        comment_variants = {event['variant_id'] for event in self.event_collection.find(event_query)}

        for var_id in comment_variants:

            if var_id in variants:
                continue

            variant_obj = self.variant(var_id, case_id=case_id)

            if not variant_obj:
                continue

            variant_obj['is_commented'] = True
            variants[var_id] = variant_obj

        return variants.values()

Returns variants that has been evaluated

Return all variants, snvs/indels and svs from case case_id
which have a entry for 'acmg_classification', 'manual_rank', 'dismiss_variant'
or if they are commented.

Args:
case_id(str)

Returns:
variants(iterable(Variant))


def __autofill_form_data(self, form_data, elements):
    for element in elements:
        if (not (element['name'] in form_data)):
            continue
        if (not (len(form_data[element['name']]) is 0)):
            continue
        if (element.name == 'textarea'):
            form_data[element['name']] = RandomInputHelper.get_for_type('textarea')
            continue
        if element.has_attr('type'):
            form_data[element['name']] = RandomInputHelper.get_for_type(element['type'])

Autofill empty form data with random data.

Args:
form_data (obj): The {key: value} form data
elements list(obj): Soup elements.

Returns:
obj: The {key: value}


def _validate_paths_for_modules(self, actual_paths, expected_paths, file_to_update_on_error):
    self.assertTrue(actual_paths)
    self.assertTrue(expected_paths)
    missing_paths = expected_paths - actual_paths
    extra_paths = actual_paths - expected_paths
    missing_paths = ["'%s'" % path for path in missing_paths]
    extra_paths = ["'%s'" % path for path in extra_paths]
    self.assertFalse(missing_paths, 'Please add %s to %s.' % (',\n'.join(sorted(missing_paths)), file_to_update_on_error))
    self.assertFalse(extra_paths, 'Redundant paths, please remove %s in %s.' % (',\n'.join(sorted(extra_paths)), file_to_update_on_error))

Validates that actual_paths match expected_paths.

Args:
actual_paths: */__init__.py file paths listed in file_to_update_on_error.
expected_paths: */__init__.py file paths that we need to create for
TensorFlow API.
file_to_update_on_error: File that contains list of */__init__.py files.
We include it in error message printed if the file list needs to be
updated.


def _initialize_splittable_dimensions(self, mtf_graph):
    all_mtf_dimension_names = set()
    for mtf_operation in mtf_graph.operations:
        for mtf_tensor in mtf_operation.outputs:
            for mtf_dimension in mtf_tensor.shape.dims:
                if (not re.match('_anonymous_\\d*', mtf_dimension.name)):
                    all_mtf_dimension_names.add(mtf_dimension.name)
    unsplittable_mtf_dimension_names = set()
    for mtf_operation in mtf_graph.operations:
        unsplittable_mtf_dimension_names.update(mtf_operation.unsplittable_dims)
    return (all_mtf_dimension_names - unsplittable_mtf_dimension_names)

Initializer for self._splittable_mtf_dimension_names.

Args:
mtf_graph: an mtf.Graph.

Returns:
A set(string) of the names of Mesh TensorFlow dimensions that may be
assigned in a layout.


def init_app(self, app):
    app.config.setdefault('FEDORA_BASE_URL', 'http:
    if hasattr(app, 'teardown_appcontext'):
        app.teardown_appcontext(self.teardown)
    else:
        app.teardown_request(self.teardown)

Initializes a Flask app object for the extension.

Args:
app(Flask): Flask app


def __init__(self, **kwargs):

        try:
            self.UIStatusMsg = ''
            self.mac = kwargs.get('EUI')
            self.port = kwargs.get('SerialPort')
            self.handle = None
            self.AutoDUTEnable = False
            self._is_net = False
            self.logStatus = {'stop':'stop', 'running':'running', "pauseReq":'pauseReq', 'paused':'paused'}
            self.joinStatus = {'notstart':'notstart', 'ongoing':'ongoing', 'succeed':'succeed', "failed":'failed'}
            self.logThreadStatus = self.logStatus['stop']
            self.intialize()
        except Exception, e:
            ModuleHelper.WriteIntoDebugLogger("initialize() Error: " + str(e))

initialize the serial port and default network parameters
Args:
**kwargs: Arbitrary keyword arguments
Includes 'EUI' and 'SerialPort'


def _extract_from(raw_json, pandas_options=None):

    data_frames = []
    if pandas_options is None:
        pandas_options = {}

    columns = pandas_options.pop('columns', None)
    columns, header_line_number = _convert_pandas_csv_options(pandas_options, columns)

    for table in raw_json:
        list_data = [[np.nan if not e['text'] else e['text'] for e in row] for row in table['data']]
        _columns = columns

        if isinstance(header_line_number, int) and not columns:
            _columns = list_data.pop(header_line_number)
            _columns = ['' if e is np.nan else e for e in _columns]

        data_frames.append(pd.DataFrame(data=list_data, columns=_columns, **pandas_options))

    return data_frames

Extract tables from json.

Args:
raw_json (list):
Decoded list from tabula-java JSON.
pandas_options (dict optional):
pandas options for `pd.DataFrame()`


def GetLVMLogicalVolumeByPathSpec(self, path_spec):
    volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec)
    if (volume_index is None):
        return None
    return self._vslvm_volume_group.get_logical_volume(volume_index)

Retrieves a LVM logical volume for a path specification.

Args:
path_spec (PathSpec): path specification.

Returns:
pyvslvm.logical_volume: a LVM logical volume or None if not available.


def is_valid_bibtex(reference):

    sio = StringIO(remove_non_ascii(reference))
    parser = bibtex.Parser()
    errors.set_strict_mode(False)
    bib_data = parser.parse_stream(sio)
    return len(bib_data.entries) > 0

Use pybtex to validate that a reference is in proper BibTeX format

Args:
reference: A String reference in BibTeX format.

Returns:
Boolean indicating if reference is valid bibtex.


def _get_stop_shutdown_common_args(self, vm_names):

        vms_to_stop = self.get_vms(vm_names).values()

        if not vm_names:
            log_msg = '{} prefix'
            nets = self._nets.values()
        else:
            log_msg = '{} specified VMs'
            nets = self._get_unused_nets(vms_to_stop)

        return vms_to_stop, nets, log_msg

Get the common arguments for stop and shutdown commands
Args:
vm_names (list of str): The names of the requested vms
Returns
list of plugins.vm.VMProviderPlugin:
vms objects that should be stopped
list of virt.Network: net objects that should be stopped
str: log message
Raises:
utils.LagoUserException: If a vm name doesn't exist


def exp2(value: types.IntTensor) -> types.IntTensor:
    shape = get_shape(value)
    dtype = value.dtype
    max_allowed_value = tf.constant(8 * dtype.size, shape=shape, dtype=dtype)
    if not dtype.is_unsigned:
        max_allowed_value -= 1
    return tf.where(tf.greater_equal(value, max_allowed_value), tf.constant(dtype.max, shape=shape, dtype=dtype), tf.bitwise.left_shift(tf.constant(1, shape=shape, dtype=dtype), value))

Returns the point-wise base-2 exponentiation of a given `Tensor`.

Args:
value: Positive scalar `Tensor` of integers.

#### Examples

```python
import tensorflow as tf
import tf_quant_finance as tff

# Example: Computing the base-2 exponentiation of a range.

tff.math.qmc.utils.exp2(tf.range(0, 5))
# ==> tf.Tensor([1, 2, 4, 8, 16], shape=(5,), dtype=int32)
```

Returns:
`Tensor` with the same `shape` and `dtype` as `value` equal to `1 << value`.


def legend(self, values):

        if not isinstance(values, list):
            raise TypeError("legend must be a list of labels")

        self.options["legend"] = values

Set the legend labels.

Args:
values (list): list of labels.

Raises:
ValueError: legend must be a list of labels.


def kill_test_logger(logger):
    for h in list(logger.handlers):
        logger.removeHandler(h)
        if isinstance(h, logging.FileHandler):
            h.close()

Cleans up a test logger object by removing all of its handlers.

Args:
logger: The logging object to clean up.


def add_dir(self, path, compress):
    if (not os.path.isdir(path)):
        raise ValueError('{} is not a directory'.format(path))
    for (root, dirs, files) in os.walk(path):
        for f in files:
            self.add_file(os.path.join(root, f), compress)

Add all files under directory `path` to the MAR file.

Args:
path (str): path to directory to add to this MAR file
compress (str): One of 'xz', 'bz2', or None. Defaults to None.


def accept(self, visitor: 'FhirPathAstBaseVisitor', **kwargs: Any) -> Any:

Delegates a 'visit' to the `AbstractSyntaxTree` node.

The provided `visitor` can be used to perform arbitrary operations on the
visited node. Arbitrary key/value arguments can be leveraged to provide
additional stateful information.

Args:
visitor: A visitor that traverses the FHIRPath abstract syntax tree.
**kwargs: Arbitrary key/value arguments accompanying the visitor.

Returns:
`Any` value that is a byproduct of the visit.


def threshold(image, block_size=DEFAULT_BLOCKSIZE, mask=None):
    if (mask is None):
        mask = np.zeros(image.shape[:2], dtype=np.uint8)
        mask[:] = 255
    if ((len(image.shape) > 2) and (image.shape[2] == 4)):
        image = cv2.cvtColor(image, cv2.COLOR_BGRA2GRAY)
    res = _calc_block_mean_variance(image, mask, block_size)
    res = ((image.astype(np.float32) - res.astype(np.float32)) + 255)
    (_, res) = cv2.threshold(res, 215, 255, cv2.THRESH_BINARY)
    return res

Applies adaptive thresholding to the given image.

Args:
image: BGRA image.
block_size: optional int block_size to use for adaptive thresholding.
mask: optional mask.
Returns:
Thresholded image.


def get_group_by_id(self, group_id: str) -> typing.Optional['Group']:
    VALID_POSITIVE_INT.validate(group_id, 'get_group_by_id', exc=ValueError)
    for group in self.groups:
        if (group.group_id == group_id):
            return group
    return None

Gets a group by id

Args:
group_id: group id

Returns: Group


def get_by(self, field, value, uri=None):
    if (not field):
        logger.exception(RESOURCE_CLIENT_INVALID_FIELD)
        raise ValueError(RESOURCE_CLIENT_INVALID_FIELD)
    if (not uri):
        uri = self._uri
    self.__validate_resource_uri(uri)
    logger.debug(('Get by (uri = %s, field = %s, value = %s)' % (uri, field, str(value))))
    filter = '"{0}=\'{1}\'"'.format(field, value)
    results = self.get_all(filter=filter, uri=uri)
    if ('.' not in field):
        results = [item for item in results if (str(item.get(field, '')).lower() == value.lower())]
    return results

This function uses get_all passing a filter.

The search is case-insensitive.

Args:
field: Field name to filter.
value: Value to filter.
uri: Resource uri.

Returns:
dict


def add_spectrum(self, label, spectrum, color=None):

        self._spectra[label] = spectrum
        self.colors.append(
            color or
            self.colors_cycle[len(self._spectra) % len(self.colors_cycle)])

Adds a Spectrum for plotting.

Args:
label (str): Label for the Spectrum. Must be unique.
spectrum: Spectrum object
color (str): This is passed on to matplotlib. E.g., "k--" indicates
a dashed black line. If None, a color will be chosen based on
the default color cycle.


def parse_device_list(device_list_str, key=None):
    try:
        clean_lines = str(device_list_str, 'utf-8').strip().split('\n')
    except UnicodeDecodeError:
        logging.warning('unicode decode error, origin str: %s', device_list_str)
        raise
    results = []
    for line in clean_lines:
        tokens = line.strip().split('\t')
        if len(tokens) == 2 and (key is None or tokens[1] == key):
            results.append(tokens[0])
    return results

Parses a byte string representing a list of devices.

The string is generated by calling either adb or fastboot. The tokens in
each string is tab-separated.

Args:
device_list_str: Output of adb or fastboot.
key: The token that signifies a device in device_list_str. Only devices
with the specified key in device_list_str are parsed, such as 'device' or
'fastbootd'. If not specified, all devices listed are parsed.

Returns:
A list of android device serial numbers.


def get_network_usage(access_token, subscription_id, location):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Network/locations/', location, '/usages?api-version=', NETWORK_API])
    return do_get(endpoint, access_token)

List network usage and limits for a location.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
location (str): Azure data center location. E.g. westus.

Returns:
HTTP response. JSON body of network usage.


def dense_relu_dense(x,
                     hidden_channels,
                     dropout=0.0,
                     dropout_broadcast_dims=None,
                     master_dtype=tf.float32,
                     slice_dtype=tf.float32, name=None):

  with tf.variable_scope(name, default_name="dense_relu_dense"):
    io_channels = x.shape.dims[-1]
    h = dense(x, hidden_channels,
              use_bias=False, activation=mtf.relu,
              master_dtype=master_dtype, slice_dtype=slice_dtype, name="wi")
    if dropout != 0.0:
      h = mtf.dropout(h, 1.0 - dropout,
                      noise_shape=h.shape - dropout_broadcast_dims)
    return dense(h, io_channels, use_bias=False, activation=None,
                 master_dtype=master_dtype, slice_dtype=slice_dtype,
                 name="wo")

Hidden layer with ReLU activation followed by linear projection.

The output has the same number of channels as the input.

Args:
x: a mtf.Tensor
hidden_channels: a mtf.Dimension - channels in the hidden layer
dropout: an optional float
dropout_broadcast_dims: an optional list of mtf.Dimension
master_dtype: a tf.dtype
slice_dtype: a tf.dtype
name: an optional string

Returns:
a mtf.Tensor with the same shape as x.


def notify(self, notices):
    issues_html = get_template('unattached_ebs_volume.html')
    issues_text = get_template('unattached_ebs_volume.txt')
    for (recipient, issues) in list(notices.items()):
        if issues:
            message_html = issues_html.render(issues=issues)
            message_text = issues_text.render(issues=issues)
            send_notification(subsystem=self.name, recipients=[recipient], subject=self.subject, body_html=message_html, body_text=message_text)

Send notifications to the users via. the provided methods

Args:
notices (:obj:`dict` of `str`: `dict`): List of the notifications to send

Returns:
`None`


def from_str(cls, label: str) -> int:

        label_norm = label.replace('1', 'one').upper()
        if label_norm in cls.__members__:
            return DecayType[label_norm]
        else:
            raise NotImplementedError

Convert given string label of decay type to special index

Args:
label: name of decay type.
Set of values: `"linear"`, `"cosine"`, `"exponential"`,
`"onecycle"`, `"trapezoid"`, `["polynomial", K]`, where K is a polynomial power

Returns:
index of decay type


def open_readable(self, name):

        assert compat.is_native(name)
        out = SpooledTemporaryFile(max_size=self.MAX_SPOOL_MEM, mode="w+b")
        self.ftp.retrbinary(
            "RETR {}".format(name), out.write, FtpTarget.DEFAULT_BLOCKSIZE
        )
        out.seek(0)
        return out

Open cur_dir/name for reading.

Note: we read everything into a buffer that supports .read().

Args:
name (str): file name, located in self.curdir
Returns:
file-like (must support read() method)


def set_of_vars(arg_plot):
    sovs = set((tuple((var + '+').split('+')[:2]) for var in arg_plot.split(',')))
    sovs.discard(('', ''))
    return sovs

Build set of needed field variables.

Each var is a tuple, first component is a scalar field, second component is
either:

- a scalar field, isocontours are added to the plot.
- a vector field (e.g. 'v' for the (v1,v2,v3) vector), arrows are added to
the plot.

Args:
arg_plot (str): string with variable names separated with
``,`` (figures), and ``+`` (same plot).
Returns:
set of str: set of needed field variables.


def forward(self, query: torch.LongTensor, key: Optional[torch.Tensor], value: Optional[torch.Tensor], attn_bias: Optional[torch.Tensor], key_padding_mask: Optional[torch.Tensor]=None, need_weights: bool=True, attn_mask: Optional[torch.Tensor]=None, before_softmax: bool=False, need_head_weights: bool=False) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
    if need_head_weights:
        need_weights = True
    tgt_len, bsz, embedding_dim = query.size()
    src_len = tgt_len
    if not embedding_dim == self.embedding_dim:
        raise AssertionError(f'The query embedding dimension {embedding_dim} is not equal to the expected embedding_dim {self.embedding_dim}.')
    if not list(query.size()) == [tgt_len, bsz, embedding_dim]:
        raise AssertionError('Query size incorrect in Graphormer, compared to model dimensions.')
    if key is not None:
        src_len, key_bsz, _ = key.size()
        if not torch.jit.is_scripting():
            if key_bsz != bsz or value is None or (not (src_len, bsz == value.shape[:2])):
                raise AssertionError('The batch shape does not match the key or value shapes provided to the attention.')
    q = self.q_proj(query)
    k = self.k_proj(query)
    v = self.v_proj(query)
    q *= self.scaling
    q = q.contiguous().view(tgt_len, bsz * self.num_heads, self.head_dim).transpose(0, 1)
    if k is not None:
        k = k.contiguous().view(-1, bsz * self.num_heads, self.head_dim).transpose(0, 1)
    if v is not None:
        v = v.contiguous().view(-1, bsz * self.num_heads, self.head_dim).transpose(0, 1)
    if k is None or not k.size(1) == src_len:
        raise AssertionError('The shape of the key generated in the attention is incorrect')
    if key_padding_mask is not None and key_padding_mask.dim() == 0:
        key_padding_mask = None
    if key_padding_mask is not None:
        if key_padding_mask.size(0) != bsz or key_padding_mask.size(1) != src_len:
            raise AssertionError('The shape of the generated padding mask for the key does not match expected dimensions.')
    attn_weights = torch.bmm(q, k.transpose(1, 2))
    attn_weights = self.apply_sparse_mask(attn_weights, tgt_len, src_len, bsz)
    if list(attn_weights.size()) != [bsz * self.num_heads, tgt_len, src_len]:
        raise AssertionError('The attention weights generated do not match the expected dimensions.')
    if attn_bias is not None:
        attn_weights += attn_bias.view(bsz * self.num_heads, tgt_len, src_len)
    if attn_mask is not None:
        attn_mask = attn_mask.unsqueeze(0)
        attn_weights += attn_mask
    if key_padding_mask is not None:
        attn_weights = attn_weights.view(bsz, self.num_heads, tgt_len, src_len)
        attn_weights = attn_weights.masked_fill(key_padding_mask.unsqueeze(1).unsqueeze(2).to(torch.bool), float('-inf'))
        attn_weights = attn_weights.view(bsz * self.num_heads, tgt_len, src_len)
    if before_softmax:
        return (attn_weights, v)
    attn_weights_float = torch.nn.functional.softmax(attn_weights, dim=-1)
    attn_weights = attn_weights_float.type_as(attn_weights)
    attn_probs = self.attention_dropout_module(attn_weights)
    if v is None:
        raise AssertionError('No value generated')
    attn = torch.bmm(attn_probs, v)
    if list(attn.size()) != [bsz * self.num_heads, tgt_len, self.head_dim]:
        raise AssertionError('The attention generated do not match the expected dimensions.')
    attn = attn.transpose(0, 1).contiguous().view(tgt_len, bsz, embedding_dim)
    attn: torch.Tensor = self.out_proj(attn)
    attn_weights = None
    if need_weights:
        attn_weights = attn_weights_float.contiguous().view(bsz, self.num_heads, tgt_len, src_len).transpose(1, 0)
        if not need_head_weights:
            attn_weights = attn_weights.mean(dim=0)
    return (attn, attn_weights)

Args:
key_padding_mask (Bytetorch.Tensor, optional): mask to exclude
keys that are pads, of shape `(batch, src_len)`, where padding elements are indicated by 1s.
need_weights (bool, optional): return the attention weights,
averaged over heads (default: False).
attn_mask (Bytetorch.Tensor, optional): typically used to
implement causal attention, where the mask prevents the attention from looking forward in time
(default: None).
before_softmax (bool, optional): return the raw attention
weights and values before the attention softmax.
need_head_weights (bool, optional): return the attention
weights for each head. Implies *need_weights*. Default: return the average attention weights over all
heads.


def _prefix_from_ip_int(cls, ip_int):

        trailing_zeroes = _count_righthand_zero_bits(ip_int,
                                                     cls._max_prefixlen)
        prefixlen = cls._max_prefixlen - trailing_zeroes
        leading_ones = ip_int >> trailing_zeroes
        all_ones = (1 << prefixlen) - 1
        if leading_ones != all_ones:
            byteslen = cls._max_prefixlen
            details = _compat_to_bytes(ip_int, byteslen, 'big')
            msg = 'Netmask pattern %r mixes zeroes & ones'
            raise ValueError(msg % details)
        return prefixlen

Return prefix length from the bitwise netmask.

Args:
ip_int: An integer, the netmask in expanded bitwise format

Returns:
An integer, the prefix length.

Raises:
ValueError: If the input intermingles zeroes & ones


def Sign(self, data, signing_key, verify_key=None):

    if signing_key.KeyLen() < 2048:
      logging.warning("signing key is too short.")

    self.signature = signing_key.Sign(data)
    self.signature_type = self.SignatureType.RSA_PKCS1v15

    self.digest = hashlib.sha256(data).digest()
    self.digest_type = self.HashType.SHA256
    self.data = data

    if verify_key is None:
      verify_key = signing_key.GetPublicKey()

    self.Verify(verify_key)

    return self

Use the data to sign this blob.

Args:
data: String containing the blob data.
signing_key: The key to sign with.
verify_key: Key to verify with. If None we assume the signing key also
contains the public key.

Returns:
self for call chaining.


def FanOut(self, obj, parent=None):
    if (parent and (obj == parent)):
        results = [utils.SmartUnicode(obj).strip()]
    elif isinstance(obj, (string_types, rdf_structs.EnumNamedValue)):
        results = [utils.SmartUnicode(obj).strip()]
    elif isinstance(obj, rdf_protodict.DataBlob):
        results = self.FanOut(obj.GetValue())
    elif isinstance(obj, (collections.Mapping, rdf_protodict.Dict)):
        results = []
        for (k, v) in iteritems(obj):
            expanded_v = [utils.SmartUnicode(r) for r in self.FanOut(v)]
            results.append(('%s:%s' % (utils.SmartUnicode(k), ','.join(expanded_v))))
    elif isinstance(obj, (collections.Iterable, rdf_structs.RepeatedFieldHelper)):
        results = []
        for rslt in [self.FanOut(o, obj) for o in obj]:
            results.extend(rslt)
    else:
        results = [utils.SmartUnicode(obj).strip()]
    return results

Expand values from various attribute types.

Strings are returned as is.
Dictionaries are returned with a key string, and an expanded set of values.
Other iterables are expanded until they flatten out.
Other items are returned in string format.

Args:
obj: The object to expand out.
parent: The parent object: Used to short-circuit infinite recursion.

Returns:
a list of expanded values as strings.


def add(self, index, var):

        import nnabla as nn
        from nnabla.utils.image_utils import imsave
        if index != 0 and (index + 1) % self.interval != 0:
            return
        if isinstance(var, nn.Variable):
            data = var.d.copy()
        elif isinstance(var, nn.NdArray):
            data = var.data.copy()
        else:
            assert isinstance(var, np.ndarray)
            data = var.copy()
        assert data.ndim > 2
        channels = data.shape[-3]
        data = data.reshape(-1, *data.shape[-3:])
        data = data[:min(data.shape[0], self.num_images)]
        data = self.normalize_method(data)
        if channels > 3:
            data = data[:, :3]
        elif channels == 2:
            data = np.concatenate(
                [data, np.ones((data.shape[0], 1) + data.shape[-2:])], axis=1)
        path_tmpl = os.path.join(self.save_dir, '{:06d}-{}.png')
        for j in range(min(self.num_images, data.shape[0])):
            img = data[j].transpose(1, 2, 0)
            if img.shape[-1] == 1:
                img = img[..., 0]
            path = path_tmpl.format(index, '{:03d}'.format(j))
            imsave(path, img)
        if self.verbose:
            logger.info("iter={} {{{}}} are written to {}.".format(
                index, self.name, path_tmpl.format(index, '*')))

Add a minibatch of images to the monitor.

Args:
index (int): Index.
var (:obj:`~nnabla.Variable`, :obj:`~nnabla.NdArray`, or :obj:`~numpy.ndarray`):
A minibatch of images with ``(N, ..., C, H, W)`` format.
If C == 2, blue channel is appended with ones. If C > 3,
the array will be sliced to remove C > 3 sub-array.


def send_request(self, request, correlation_id=None):
    log.debug('Sending request %s', request)
    if (correlation_id is None):
        correlation_id = self._next_correlation_id()
    header = RequestHeader(request, correlation_id=correlation_id, client_id=self._client_id)
    message = b''.join([header.encode(), request.encode()])
    size = Int32.encode(len(message))
    data = (size + message)
    self.bytes_to_send.append(data)
    if request.expect_response():
        ifr = (correlation_id, request)
        self.in_flight_requests.append(ifr)
    return correlation_id

Encode and queue a kafka api request for sending.

Arguments:
request (object): An un-encoded kafka request.
correlation_id (int, optional): Optionally specify an ID to
correlate requests with responses. If not provided, an ID will
be generated automatically.

Returns:
correlation_id


def get_all_entries(self, charge_to_discharge=True):
    all_entries = list(self.get_stable_entries())
    all_entries.extend(self.get_unstable_entries())
    fsrt = (lambda e: e.composition.get_atomic_fraction(self.working_ion))
    all_entries = sorted([e for e in all_entries], key=fsrt)
    return (all_entries if charge_to_discharge else all_entries.reverse())

Return all entries input for the electrode.

Args:
charge_to_discharge:
order from most charge to most discharged state? Defaults to
True.

Returns:
A list of all entries in the electrode (both stable and unstable),
ordered by amount of the working ion.


def get_meta_graph_def(saved_model_dir, tag_set):
    with session.Session(graph=ops.Graph()) as sess:
        return loader.load(sess, tag_set, saved_model_dir)

Validate saved_model and extract MetaGraphDef.

Args:
saved_model_dir: saved_model path to convert.
tag_set: Set of tag(s) of the MetaGraphDef to load.

Returns:
The meta_graph_def used for tflite conversion.

Raises:
ValueError: No valid MetaGraphDef for given tag_set.


def verbosity_arg(value):
    value = value.upper()
    if value == 'DEBUG':
        return tf.compat.v1.logging.DEBUG
    elif value == 'INFO':
        return tf.compat.v1.logging.INFO
    elif value == 'WARN':
        return tf.compat.v1.logging.WARN
    elif value == 'ERROR':
        return tf.compat.v1.logging.ERROR
    elif value == 'FATAL':
        return tf.compat.v1.logging.FATAL
    else:
        raise argparse.ArgumentTypeError('Not an expected value')

Parses verbosity argument.

Args:
value: A member of tf.logging.
Raises:
ArgumentTypeError: Not an expected value.


def stats(self, *args):
    result = self._fetch_cmd(b'stats', args, False)
    for (key, value) in six.iteritems(result):
        converter = STAT_TYPES.get(key, int)
        try:
            result[key] = converter(value)
        except Exception:
            pass
    return result

The memcached "stats" command.

The returned keys depend on what the "stats" command returns.
A best effort is made to convert values to appropriate Python
types, defaulting to strings when a conversion cannot be made.

Args:
*arg: extra string arguments to the "stats" command. See the
memcached protocol documentation for more information.

Returns:
A dict of the returned stats.


def GetMap(self, cache_filename=None):
    raise NotImplementedError('%s must implement this method!' % self.__class__.__name__)

Returns the map from the cache.

Must be implemented by the child class!

Args:
cache_filename:  optional extra info used by the child class

Raises:
NotImplementedError:  We should have been implemented by child.


def dropout_no_scaling(x, keep_prob):

  if keep_prob == 1.0:
    return x
  mask = tf.less(tf.random_uniform(tf.shape(x)), keep_prob)
  return x * cast_like(mask, x)

Like tf.nn.dropout, but does not scale up.  Works on integers also.

Args:
x: a Tensor
keep_prob: a floating point number

Returns:
Tensor of the same shape as x.


def set(self, name: str, value: Any) -> None:

        self.agent.set(name, value)

Stores a knowledge item in the agent knowledge base.

Args:
name (str): name of the item
value (Any): value of the item


def _check_format_string(self, node, format_arg):
    num_args = _count_supplied_tokens(node.args[(format_arg + 1):])
    if (not num_args):
        return
    format_string = node.args[format_arg].value
    if (not isinstance(format_string, str)):
        required_num_args = 0
    else:
        try:
            if (self._format_style == 'old'):
                (keyword_args, required_num_args, _, _) = utils.parse_format_string(format_string)
                if keyword_args:
                    return
            elif (self._format_style == 'new'):
                (keyword_arguments, implicit_pos_args, explicit_pos_args) = utils.parse_format_method_string(format_string)
                keyword_args_cnt = len(set((k for (k, l) in keyword_arguments if (not isinstance(k, int)))))
                required_num_args = ((keyword_args_cnt + implicit_pos_args) + explicit_pos_args)
        except utils.UnsupportedFormatCharacter as ex:
            char = format_string[ex.index]
            self.add_message('logging-unsupported-format', node=node, args=(char, ord(char), ex.index))
            return
        except utils.IncompleteFormatString:
            self.add_message('logging-format-truncated', node=node)
            return
    if (num_args > required_num_args):
        self.add_message('logging-too-many-args', node=node)
    elif (num_args < required_num_args):
        self.add_message('logging-too-few-args', node=node)

Checks that format string tokens match the supplied arguments.

Args:
node (astroid.node_classes.NodeNG): AST node to be checked.
format_arg (int): Index of the format string in the node arguments.


class FlaubertSQuADHead(nn.Module):

    def __init__(self, config: FlaubertConfig):
        super().__init__()
        self.start_n_top = config.start_n_top
        self.end_n_top = config.end_n_top
        self.start_logits = FlaubertPoolerStartLogits(config)
        self.end_logits = FlaubertPoolerEndLogits(config)
        self.answer_class = FlaubertPoolerAnswerClass(config)

    @auto_docstring
    def forward(self, hidden_states: torch.FloatTensor, start_positions: Optional[torch.LongTensor]=None, end_positions: Optional[torch.LongTensor]=None, cls_index: Optional[torch.LongTensor]=None, is_impossible: Optional[torch.LongTensor]=None, p_mask: Optional[torch.FloatTensor]=None, return_dict: bool=False) -> Union[FlaubertSquadHeadOutput, Tuple[torch.FloatTensor]]:

        start_logits = self.start_logits(hidden_states, p_mask=p_mask)
        if start_positions is not None and end_positions is not None:
            for x in (start_positions, end_positions, cls_index, is_impossible):
                if x is not None and x.dim() > 1:
                    x.squeeze_(-1)
            end_logits = self.end_logits(hidden_states, start_positions=start_positions, p_mask=p_mask)
            loss_fct = CrossEntropyLoss()
            start_loss = loss_fct(start_logits, start_positions)
            end_loss = loss_fct(end_logits, end_positions)
            total_loss = (start_loss + end_loss) / 2
            if cls_index is not None and is_impossible is not None:
                cls_logits = self.answer_class(hidden_states, start_positions=start_positions, cls_index=cls_index)
                loss_fct_cls = nn.BCEWithLogitsLoss()
                cls_loss = loss_fct_cls(cls_logits, is_impossible)
                total_loss += cls_loss * 0.5
            return FlaubertSquadHeadOutput(loss=total_loss) if return_dict else (total_loss,)
        else:
            bsz, slen, hsz = hidden_states.size()
            start_log_probs = nn.functional.softmax(start_logits, dim=-1)
            start_top_log_probs, start_top_index = torch.topk(start_log_probs, self.start_n_top, dim=-1)
            start_top_index_exp = start_top_index.unsqueeze(-1).expand(-1, -1, hsz)
            start_states = torch.gather(hidden_states, -2, start_top_index_exp)
            start_states = start_states.unsqueeze(1).expand(-1, slen, -1, -1)
            hidden_states_expanded = hidden_states.unsqueeze(2).expand_as(start_states)
            p_mask = p_mask.unsqueeze(-1) if p_mask is not None else None
            end_logits = self.end_logits(hidden_states_expanded, start_states=start_states, p_mask=p_mask)
            end_log_probs = nn.functional.softmax(end_logits, dim=1)
            end_top_log_probs, end_top_index = torch.topk(end_log_probs, self.end_n_top, dim=1)
            end_top_log_probs = end_top_log_probs.view(-1, self.start_n_top * self.end_n_top)
            end_top_index = end_top_index.view(-1, self.start_n_top * self.end_n_top)
            start_states = torch.einsum('blh,bl->bh', hidden_states, start_log_probs)
            cls_logits = self.answer_class(hidden_states, start_states=start_states, cls_index=cls_index)
            if not return_dict:
                return (start_top_log_probs, start_top_index, end_top_log_probs, end_top_index, cls_logits)
            else:
                return FlaubertSquadHeadOutput(start_top_log_probs=start_top_log_probs, start_top_index=start_top_index, end_top_log_probs=end_top_log_probs, end_top_index=end_top_index, cls_logits=cls_logits)

A SQuAD head inspired by XLNet.

Args:
config ([`FlaubertConfig`]):
The config used by the model, will be used to grab the `hidden_size` of the model and the `layer_norm_eps`
to use.