def indicator(self, indicator_type=None, owner=None, **kwargs):
    if (not indicator_type):
        return Indicator(self.tcex, None, owner=owner, **kwargs)
    upper_indicator_type = indicator_type.upper()
    indicator = None
    if (upper_indicator_type == 'ADDRESS'):
        indicator = Address(self.tcex, kwargs.pop('ip', None), owner=owner, **kwargs)
    elif (upper_indicator_type == 'EMAILADDRESS'):
        indicator = EmailAddress(self.tcex, kwargs.pop('address', None), owner=owner, **kwargs)
    elif (upper_indicator_type == 'FILE'):
        indicator = File(self.tcex, **kwargs)
    elif (upper_indicator_type == 'HOST'):
        indicator = Host(self.tcex, kwargs.pop('hostname', None), owner=owner, **kwargs)
    elif (upper_indicator_type == 'URL'):
        indicator = URL(self.tcex, kwargs.pop('url', None), owner=owner, **kwargs)
    else:
        try:
            if (upper_indicator_type in self._custom_indicator_classes.keys()):
                custom_indicator_details = self._custom_indicator_classes[indicator_type]
                value_fields = custom_indicator_details.get('value_fields')
                c = getattr(module, custom_indicator_details.get('branch'))
                if (len(value_fields) == 1):
                    indicator = c(value_fields[0], owner=owner, **kwargs)
                elif (len(value_fields) == 2):
                    indicator = c(value_fields[0], value_fields[1], owner=owner, **kwargs)
                elif (len(value_fields) == 3):
                    indicator = c(value_fields[0], value_fields[2], owner=owner, **kwargs)
        except Exception:
            return None
    return indicator

Create the Indicator TI object.

Args:
owner:
indicator_type:
**kwargs:

Return:


def normalize_cluster_spec(cluster_spec):
    if isinstance(cluster_spec, (dict, cluster_pb2.ClusterDef)):
        return server_lib.ClusterSpec(cluster_spec)
    elif not isinstance(cluster_spec, server_lib.ClusterSpec):
        raise ValueError("`cluster_spec' should be dict or a `tf.train.ClusterSpec` or a `tf.train.ClusterDef` object")
    return cluster_spec

Makes `cluster_spec` into a `ClusterSpec` object.

Args:
cluster_spec: a dict, ClusterDef or ClusterSpec object specifying the
cluster configurations.

Returns:
a `ClusterSpec` object.

Raises:
ValueError: if `cluster_spec` is not a dict or a `ClusterSpec` or a
`ClusterDef`.


def apply_transform(self, x, transform_parameters):
    img_row_axis = self.row_axis - 1
    img_col_axis = self.col_axis - 1
    img_channel_axis = self.channel_axis - 1
    x = apply_affine_transform(x, transform_parameters.get('theta', 0), transform_parameters.get('tx', 0), transform_parameters.get('ty', 0), transform_parameters.get('shear', 0), transform_parameters.get('zx', 1), transform_parameters.get('zy', 1), row_axis=img_row_axis, col_axis=img_col_axis, channel_axis=img_channel_axis, fill_mode=self.fill_mode, cval=self.cval, order=self.interpolation_order)
    if transform_parameters.get('channel_shift_intensity') is not None:
        x = apply_channel_shift(x, transform_parameters['channel_shift_intensity'], img_channel_axis)
    if transform_parameters.get('flip_horizontal', False):
        x = flip_axis(x, img_col_axis)
    if transform_parameters.get('flip_vertical', False):
        x = flip_axis(x, img_row_axis)
    if transform_parameters.get('brightness') is not None:
        x = apply_brightness_shift(x, transform_parameters['brightness'], False)
    return x

Applies a transformation to an image according to given parameters.

Args:
x: 3D tensor, single image.
transform_parameters: Dictionary with string - parameter pairs
describing the transformation.
Currently, the following parameters
from the dictionary are used:
- `'theta'`: Float. Rotation angle in degrees.
- `'tx'`: Float. Shift in the x direction.
- `'ty'`: Float. Shift in the y direction.
- `'shear'`: Float. Shear angle in degrees.
- `'zx'`: Float. Zoom in the x direction.
- `'zy'`: Float. Zoom in the y direction.
- `'flip_horizontal'`: Boolean. Horizontal flip.
- `'flip_vertical'`: Boolean. Vertical flip.
- `'channel_shift_intensity'`: Float. Channel shift intensity.
- `'brightness'`: Float. Brightness shift intensity.

Returns:
A transformed version of the input (same shape).


def remove_snippet_client(self, name):
    if (name not in self._snippet_clients):
        raise Error(self._device, (MISSING_SNIPPET_CLIENT_MSG % name))
    client = self._snippet_clients.pop(name)
    client.stop_app()

Removes a snippet client from management.

Args:
name: string, the name of the snippet client to remove.

Raises:
Error: if no snippet client is managed under the specified name.


def get(self, name: str) -> Optional[ListEntry]:
    parts = name.split(self._delimiter)
    try:
        node = self._find(self._root, *parts)
    except KeyError:
        return None
    else:
        marked = self._marked.get(name)
        return ListEntry(name, node.exists, marked, bool(node.children))

Return the named entry in the list tree.

Args:
name: The entry name.


def offset(self, num_to_skip):
    return self.__class__(self._parent, projection=self._projection, field_filters=self._field_filters, orders=self._orders, limit=self._limit, offset=num_to_skip, start_at=self._start_at, end_at=self._end_at)

Skip to an offset in a query.

If the current query already has specified an offset, this will
overwrite it.

Args:
num_to_skip (int): The number of results to skip at the beginning
of query results. (Must be non-negative.)

Returns:
~.firestore_v1beta1.query.Query: An offset query. Acts as a
copy of the current query, modified with the newly added
"offset" field.


def get_minimal_fba_flux(self, objective):
    vs_wt = self._v_wt.set(self._model.reactions)
    zs = self._z.set(self._model.reactions)
    wt_obj_flux = self.get_fba_obj_flux(objective)
    with self.constraints() as constr:
        constr.add((zs >= vs_wt), (vs_wt >= (- zs)), (self._v_wt[objective] >= wt_obj_flux))
        self._prob.set_objective(self._z.sum(self._model.reactions))
        result = self._solve(lp.ObjectiveSense.Minimize)
    fba_fluxes = {}
    for key in self._model.reactions:
        fba_fluxes[key] = result.get_value(self._v_wt[key])
    return fba_fluxes

Find the FBA solution that minimizes all the flux values.

Maximize the objective flux then minimize all other fluxes
while keeping the objective flux at the maximum.

Args:
objective: The objective reaction that is maximized.

Returns:
A dictionary of all the reactions and their minimized fluxes.


def network_sets(self):
    if (not self.__network_sets):
        self.__network_sets = NetworkSets(self.__connection)
    return self.__network_sets

Gets the NetworkSets API client.

Returns:
NetworkSets:


def initialize_system_for_tpu_embedding(embedding_config: embedding_pb2.TPUEmbeddingConfiguration, job: Optional[Text]=None) -> ops.Operation:
    config_string = embedding_config.SerializeToString()
    with ops.device(_tpu_system_device_name(job)):
        return tpu_ops.configure_tpu_embedding(config=config_string)

Initializes a distributed TPU Embedding system for use with TensorFlow.

The following two are equivalent:
1. initialize_system() with embedding_config.
2. initialize_system() without embedding_config, then
initialize_system_for_tpu_embedding().
initialize_system() should not be called with embedding_config if
initialize_system_for_tpu_embedding() is meant to be called later.

Args:
embedding_config: a `TPUEmbeddingConfiguration` proto describing the desired
configuration of the hardware embedding lookup tables.
job: The job (the XXX in TensorFlow device specification /job:XXX) that
contains the TPU devices that will be initialized. If job=None it is
assumed there is only one job in the TensorFlow flock, and an error will
be returned if this assumption does not hold.

Returns:
A no-op.


def set_speech_ssml(self, ssml):

        self.response.outputSpeech.type = 'SSML'
        self.response.outputSpeech.ssml = ssml

Set response output speech as SSML type.

Args:
ssml: str. Response speech used when type is 'SSML', should be formatted
with Speech Synthesis Markup Language. Cannot exceed 8,000
characters.


def _nested_type_wrapper(fun):

    def wrapper(pickler, obj):
        if _is_nested_class(obj) and obj.__module__ != '__main__':
            containing_class_and_name = _find_containing_class(obj)
            if containing_class_and_name is not None:
                return pickler.save_reduce(getattr, containing_class_and_name, obj=obj)
        try:
            return fun(pickler, obj)
        except dill.dill.PicklingError:
            return pickler.save_reduce(dill.dill._create_type, (type(obj), obj.__name__, obj.__bases__, _dict_from_mappingproxy(obj.__dict__)), obj=obj)
    return wrapper

A wrapper for the standard pickler handler for class objects.

Args:
fun: Original pickler handler for type objects.

Returns:
A wrapper for type objects that handles nested classes.

The wrapper detects if an object being pickled is a nested class object.
For nested class object only it will save the containing class object so
the nested structure is recreated during unpickle.


def Sample(self, task, status):
    sample_time = time.time()
    sample = '{0:f}\t{1:s}\t{2:s}\n'.format(sample_time, task.identifier, status)
    self._WritesString(sample)

Takes a sample of the status of a task for profiling.

Args:
task (Task): a task.
status (str): status.


def _verify_spec_compatible(input_name, spec_name, input_, spec):
    assert isinstance(spec, tensor_spec.TensorSpec)
    if input is None:
        raise ValueError('{} cannot be None'.format(input_name))
    if isinstance(input_, (bool, int, float, str, np.ndarray)):
        input_ = tensor_conversion.convert_to_tensor_v2(input_)
    input_dtype = getattr(input_, 'dtype', None)
    if input_dtype != spec.dtype:
        input_dtype_str = 'no dtype' if input_dtype is None else str(input_dtype)
        raise TypeError('{} must have the same dtype as {}. Expected {}, got {}'.format(input_name, spec_name, spec.dtype, input_dtype_str))

Verifies that a symbol has a type compatible vith a given spec.

Here, compatibility is viewed in the general TensorFlow sense: that the dtypes
are the same after implicit conversion, if both are tensors.

This verifier ensures consistent treatment of types across AutoGraph.

Args:
input_name: A name to use for `input_` in error messages.
spec_name: A name to use for `spec` in error messages.
input_: Any, value to verify.
spec: TypeSpec that `input_` must be compatible with.

Raises:
ValueError if the two types have been determined not to be compatible.


def symlink_force(target, link_name):
    try:
        os.symlink(target, link_name)
    except OSError as e:
        if e.errno == errno.EEXIST:
            os.remove(link_name)
            os.symlink(target, link_name)
        else:
            raise e

Force symlink, equivalent of 'ln -sf'.

Args:
target: items to link to.
link_name: name of the link.


def query(self, minhash, size):

        for i, index in enumerate(self.indexes):
            u = self.uppers[i]
            if u is None:
                continue
            b, r = self._get_optimal_param(u, size)
            for key in index[r]._query_b(minhash, b):
                yield key

Giving the MinHash and size of the query set, retrieve
keys that references sets with containment with respect to
the query set greater than the threshold.

Args:
minhash (datasketch.MinHash): The MinHash of the query set.
size (int): The size (number of unique items) of the query set.

Returns:
`iterator` of keys.


def _compare_areas(self, datasets=None, compare_func=max):
    if (datasets is None):
        datasets = list(self.values())
    areas = []
    for ds in datasets:
        if isinstance(ds, BaseDefinition):
            areas.append(ds)
            continue
        elif (not isinstance(ds, DataArray)):
            ds = self[ds]
        area = ds.attrs.get('area')
        areas.append(area)
    areas = [x for x in areas if (x is not None)]
    if (not areas):
        raise ValueError('No dataset areas available')
    if (not all((isinstance(x, type(areas[0])) for x in areas[1:]))):
        raise ValueError("Can't compare areas of different types")
    elif isinstance(areas[0], AreaDefinition):
        first_pstr = areas[0].proj_str
        if (not all(((ad.proj_str == first_pstr) for ad in areas[1:]))):
            raise ValueError("Can't compare areas with different projections.")

        def key_func(ds):
            return (1.0 / ds.pixel_size_x)
    else:

        def key_func(ds):
            return ds.shape
    return compare_func(areas, key=key_func)

Get  for the provided datasets.

Args:
datasets (iterable): Datasets whose areas will be compared. Can
be either `xarray.DataArray` objects or
identifiers to get the DataArrays from the
current Scene. Defaults to all datasets.
This can also be a series of area objects,
typically AreaDefinitions.
compare_func (callable): `min` or `max` or other function used to
compare the dataset's areas.


def get_token(self):
    if (self.__token is not None):
        return self.__token
    url = 'https:
    creds = b64encode(':'.join([self.__key, self.__secret]).encode()).decode()
    headers = {'Authorization': ' '.join(['Basic', creds])}
    payload = {'grant_type': 'client_credentials'}
    r = requests.post(url, data=payload, headers=headers)
    self.__token = r.json()['access_token']
    return self.__token

Performs Neurio API token authentication using provided key and secret.

Note:
This method is generally not called by hand; rather it is usually
called as-needed by a Neurio Client object.

Returns:
string: the access token


def get_link(self, task_id):

        links = [x for x in self.links if x.task_id == task_id]
        if len(links) != 1:
            raise CoTError("No single Link matches task_id {}!\n{}".format(task_id, self.dependent_task_ids()))
        return links[0]

Get a ``LinkOfTrust`` by task id.

Args:
task_id (str): the task id to find.

Returns:
LinkOfTrust: the link matching the task id.

Raises:
CoTError: if no ``LinkOfTrust`` matches.


def __init__(self, dfindex, column, value, dtype, parentId):

        super(PandasCellPayload, self).__init__()
        self.dfindex = dfindex
        self.column = column
        self.value = value
        self.dtype = dtype
        self.parentId = parentId

store dataframe information in a pickable object

Args:
dfindex (pandas.index): index of the dragged data.
column (str): name of column to be dragged.
value (object): value on according position.
dtype (pandas dtype): data type of column.
parentId (str): hex(id(...)) of according DataFrameModel.


def is_attribute_valid(attribute_key, attribute_value):
    if (not isinstance(attribute_key, string_types)):
        return False
    if isinstance(attribute_value, (string_types, bool)):
        return True
    if isinstance(attribute_value, (numbers.Integral, float)):
        return is_finite_number(attribute_value)
    return False

Determine if given attribute is valid.

Args:
attribute_key: Variable which needs to be validated
attribute_value: Variable which needs to be validated

Returns:
False if attribute_key is not a string
False if attribute_value is not one of the supported attribute types
True otherwise


def cardinality(gym_space):
    if ((gym_space.dtype == np.float32) or (gym_space.dtype == np.float64)):
        tf.logging.error("Returning None for a float gym space's cardinality: ", gym_space)
        return None
    if isinstance(gym_space, Discrete):
        return gym_space.n
    if isinstance(gym_space, Box):
        return np.prod(((gym_space.high - gym_space.low) + 1))
    raise NotImplementedError

Number of elements that can be represented by the space.

Makes the most sense for Discrete or Box type with integral dtype, ex: number
of actions in an action space.

Args:
gym_space: The gym space.

Returns:
np.int64 number of observations that can be represented by this space, or
returns None when this doesn't make sense, i.e. float boxes etc.

Raises:
NotImplementedError when a space's cardinality makes sense but we haven't
implemented it.


def GetSubNodeByLocation(self, location):
    for sub_node in self.sub_nodes:
        sub_node_location = getattr(sub_node.path_spec, 'location', None)
        if (location == sub_node_location):
            return sub_node
    return None

Retrieves a sub scan node based on the location.

Args:
location (str): location that should match the location of the path
specification of a sub scan node.

Returns:
SourceScanNode: sub scan node or None if not available.


def security_label(self, name, description=None, color=None):

        label = SecurityLabel(name, description, color)
        for label_data in self._labels:
            if label_data.name == name:
                label = label_data
                break
        else:
            self._labels.append(label)
        return label

Return instance of SecurityLabel.

.. note:: The provided security label will be create if it doesn't exist. If the security
label already exists nothing will be changed.

Args:
name (str): The value for this security label.
description (str): A description for this security label.
color (str): A color (hex value) for this security label.

Returns:
obj: An instance of SecurityLabel.


def json_describe(o, fqdn, descriptor=None):
    if ((descriptor is None) or (not isinstance(descriptor, dict))):
        return {'fqdn': fqdn}
    else:
        result = {'fqdn': fqdn}
        for (attr, desc) in descriptor.items():
            if (attr == 'instance'):
                value = o
            elif ('.' in attr):
                value = o
                for cattr in attr.split('.'):
                    if hasattr(value, cattr):
                        value = getattr(value, cattr, '')
                    else:
                        break
            else:
                value = getattr(o, attr, '')
            if ('transform' in desc):
                for transform in desc['transform']:
                    if ('numpy' == transform[0:len('numpy')]):
                        value = _numpy_transform(transform, value)
                    elif ('scipy' == transform[0:len('scipy')]):
                        value = _scipy_transform(transform, value)
                    elif ('math' == transform[0:len('math')]):
                        value = _math_transform(transform, value)
                    elif ('self' in transform):
                        args = (desc['args'] if ('args' in desc) else [])
                        kwds = (desc['kwargs'] if ('kwargs' in desc) else {})
                        method = transform[len('self.'):]
                        value = _instance_transform(method, value, *args, **kwds)
            if ('slice' in desc):
                for (si, sl) in enumerate(desc['slice']):
                    if (':' in sl):
                        (name, slice) = sl.split(':')
                    else:
                        (name, slice) = (str(si), sl)
                    slvalue = value
                    for i in map(int, slice.split(',')):
                        slvalue = slvalue[i]
                    result[name] = _array_convert(slvalue)
            elif ('rename' in desc):
                result[desc['rename']] = _array_convert(value)
            else:
                result[attr] = _array_convert(value)
    return result

Describes the specified object using the directives in the JSON
`descriptor`, if available.

Args:
o: object to describe.
fqdn (str): fully-qualified domain name of the object.
descriptor (dict): keys are attributes of `o`; values are transform
functions to apply to the attribute so that only a single value is
returned.

Returns:
dict: keys are specific attributes tailored to the specific object type,
though `fqdn` is common to all descriptions; values are the corresponding
attribute values which are *simple* types that can easily be serialized to
JSON.


def Sens_t(poly, dist, **kws):
    dim = len(dist)
    if (poly.dim < dim):
        poly = chaospy.poly.setdim(poly, len(dist))
    zero = ([1] * dim)
    out = numpy.zeros(((dim,) + poly.shape), dtype=float)
    V = Var(poly, dist, **kws)
    for i in range(dim):
        zero[i] = 0
        out[i] = ((V - Var(E_cond(poly, zero, dist, **kws), dist, **kws)) / ((V + (V == 0)) ** (V != 0)))
        zero[i] = 1
    return out

Variance-based decomposition
AKA Sobol' indices

Total effect sensitivity index

Args:
poly (Poly):
Polynomial to find first order Sobol indices on.
dist (Dist):
The distributions of the input used in ``poly``.

Returns:
(numpy.ndarray) :
First order sensitivity indices for each parameters in ``poly``,
with shape ``(len(dist),) + poly.shape``.

Examples:
>>> x, y = chaospy.variable(2)
>>> poly = chaospy.Poly([1, x, y, 10*x*y])
>>> dist = chaospy.Iid(chaospy.Uniform(0, 1), 2)
>>> indices = chaospy.Sens_t(poly, dist)
>>> print(indices)
[[0.         1.         0.         0.57142857]
[0.         0.         1.         0.57142857]]


def sum(self, vars_list: List[str]) -> 'TensorFluent':
    operand = self
    if (operand.dtype == tf.bool):
        operand = operand.cast(tf.float32)
    return self._aggregation_op(tf.reduce_sum, operand, vars_list)

Returns the TensorFluent for the sum aggregation function.

Args:
vars_list: The list of variables to be aggregated over.

Returns:
A TensorFluent wrapping the sum aggregation function.


def download(s3_conn, out_filename, s3_path):

    bucket_name, prefix = split_s3_path(s3_path)
    bucket = s3_conn.get_bucket(bucket_name)
    key = boto.s3.key.Key(
        bucket=bucket,
        name=prefix
    )
    logging.info('loading from %s into %s', key, out_filename)
    key.get_contents_to_filename(out_filename, cb=log_download_progress)

Downloads the given s3_path

Args:
s3_conn (boto.s3.connection) a boto s3 connection
out_filename (str) local filename to save the file
s3_path (str) the source path on s3


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

Corresponds to IDD Field `dbmax05years`
5-year return period values for maximum extreme dry-bulb temperature

Args:
value (float): value for IDD Field `dbmax05years`
Unit: C
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

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


def parse_binary_descriptor(bindata, sensor_log=None):
    if (len(bindata) != 14):
        raise ArgumentError('Invalid length of binary data in streamer descriptor', length=len(bindata), expected=14, data=bindata)
    (dest_tile, stream_id, trigger, format_code, type_code) = struct.unpack('<8sHBBBx', bindata)
    dest_id = SlotIdentifier.FromEncoded(dest_tile)
    selector = DataStreamSelector.FromEncoded(stream_id)
    format_name = DataStreamer.KnownFormatCodes.get(format_code)
    type_name = DataStreamer.KnownTypeCodes.get(type_code)
    if (format_name is None):
        raise ArgumentError('Unknown format code', code=format_code, known_code=DataStreamer.KnownFormatCodes)
    if (type_name is None):
        raise ArgumentError('Unknown type code', code=type_code, known_codes=DataStreamer.KnownTypeCodes)
    with_other = None
    if (trigger & (1 << 7)):
        auto = False
        with_other = (trigger & ((1 << 7) - 1))
    elif (trigger == 0):
        auto = False
    elif (trigger == 1):
        auto = True
    else:
        raise ArgumentError('Unknown trigger type for streamer', trigger_code=trigger)
    return DataStreamer(selector, dest_id, format_name, auto, type_name, with_other=with_other, sensor_log=sensor_log)

Convert a binary streamer descriptor into a string descriptor.

Binary streamer descriptors are 20-byte binary structures that encode all
information needed to create a streamer.  They are used to communicate
that information to an embedded device in an efficent format.  This
function exists to turn such a compressed streamer description back into
an understandable string.

Args:
bindata (bytes): The binary streamer descriptor that we want to
understand.
sensor_log (SensorLog): Optional sensor_log to add this streamer to
a an underlying data store.

Returns:
DataStreamer: A DataStreamer object representing the streamer.

You can get a useful human readable string by calling str() on the
return value.


def WriteManyToPath(objs, filepath):

  with io.open(filepath, mode="w", encoding="utf-8") as filedesc:
    WriteManyToFile(objs, filedesc)

Serializes and writes given Python objects to a multi-document YAML file.

Args:
objs: An iterable of Python objects to serialize.
filepath: A path to the file into which the object is to be written.


def remove_chain(self, name):
    if (name in self.chains):
        delattr(self.chains, name)
    else:
        raise ValueError('Chain with this name not found')

Remove chain from current shelve file

Args:
name: chain name


def add_keyword_from_file(self, keyword_file, encoding='utf-8'):
    if (not os.path.isfile(keyword_file)):
        raise IOError('Invalid file path {}'.format(keyword_file))
    with io.open(keyword_file, encoding=encoding) as f:
        for line in f:
            if ('=>' in line):
                (keyword, clean_name) = line.split('=>')
                self.add_keyword(keyword, clean_name.strip())
            else:
                keyword = line.strip()
                self.add_keyword(keyword)

To add keywords from a file

Args:
keyword_file : path to keywords file
encoding : specify the encoding of the file

Examples:
keywords file format can be like:

>>> # Option 1: keywords.txt content
>>> # java_2e=>java
>>> # java programing=>java
>>> # product management=>product management
>>> # product management techniques=>product management

>>> # Option 2: keywords.txt content
>>> # java
>>> # python
>>> # c++

>>> keyword_processor.add_keyword_from_file('keywords.txt')

Raises:
IOError: If `keyword_file` path is not valid


def Open(self, path_spec):
    self._file_system = resolver.Resolver.OpenFileSystem(path_spec)
    if (self._file_system is None):
        raise errors.VolumeSystemError('Unable to resolve path specification.')
    type_indicator = self._file_system.type_indicator
    if (type_indicator != definitions.TYPE_INDICATOR_TSK_PARTITION):
        raise errors.VolumeSystemError('Unsupported type indicator.')

Opens a volume defined by path specification.

Args:
path_spec (PathSpec): a path specification.

Raises:
VolumeSystemError: if the TSK partition virtual file system could not
be resolved.


def keras_layer_tracepoint(layer, checkpoint_name):
    try:
        outputs = layer.output
        if tensor_util.is_tf_type(outputs):
            trace_tensor(outputs, '%s' % checkpoint_name)
        else:
            idx = 0
            for output_tensor in outputs:
                if tensor_util.is_tf_type(outputs):
                    trace_tensor(output_tensor, '%s_%d' % (checkpoint_name, idx))
                idx += 1
    except AttributeError:
        pass
    except RuntimeError:
        pass
    return layer

An interface for adding the tensor outputs of a keras layer.

Encapsulates trace_tensor.

Args:
layer: A keras layer.
checkpoint_name: a string name for the checkpoint. This name has to be a
unique name if used within model comparison. The tensors that have the same
checkpoint identifier is compared in model comparison.

Returns:
The provided layer.


def LoadFromFile(cls, script_path):
    (_name, dev) = ComponentRegistry().load_extension(script_path, class_filter=VirtualTile, unique=True)
    return dev

Import a virtual tile from a file rather than an installed module

script_path must point to a python file ending in .py that contains exactly one
VirtualTile class definition.  That class is loaded and executed as if it
were installed.

To facilitate development, if there is a proxy object defined in the same
file, it is also added to the HardwareManager proxy registry so that it
can be found and used with the device.

Args:
script_path (string): The path to the script to load

Returns:
VirtualTile: A subclass of VirtualTile that was loaded from script_path


def __init__(self, **kwargs) -> None:

        self.epochs_done = 0
        self.batches_seen = 0
        self.train_examples_seen = 0

        super().__init__(save_path=kwargs.get("save_path"),
                         load_path=kwargs.get("load_path"),
                         mode=kwargs.get("mode"))

Initialize model using keyword parameters

Args:
kwargs (dict): Dictionary with model parameters


def encode(request, data):

        if data is None:
            return request

        request.add_header('Content-Type', 'application/json')
        request.data = json.dumps(data)

        return request

Add request content data to request body, set Content-type header.

Should be overridden by subclasses if not using JSON encoding.

Args:
request (HTTPRequest): The request object.
data (dict, None): Data to be encoded.

Returns:
HTTPRequest: The request object.


def evaluate_precision_recall(input_, labels, threshold=0.5, per_example_weights=None, name=PROVIDED, phase=Phase.train):
    _ = name
    (selected, sum_retrieved, sum_relevant) = _compute_precision_recall(input_, labels, threshold, per_example_weights)
    if (phase != Phase.train):
        dtype = tf.float32
        relevant_count = tf.get_variable('relevant_count', [], dtype, tf.zeros_initializer(), collections=[bookkeeper.GraphKeys.TEST_VARIABLES], trainable=False)
        retrieved_count = tf.get_variable('retrieved_count', [], dtype, tf.zeros_initializer(), collections=[bookkeeper.GraphKeys.TEST_VARIABLES], trainable=False)
        selected_count = tf.get_variable('selected_count', [], dtype, tf.zeros_initializer(), collections=[bookkeeper.GraphKeys.TEST_VARIABLES], trainable=False)
        with input_.g.device(selected_count.device):
            selected = tf.assign_add(selected_count, selected)
        with input_.g.device(retrieved_count.device):
            sum_retrieved = tf.assign_add(retrieved_count, sum_retrieved)
        with input_.g.device(relevant_count.device):
            sum_relevant = tf.assign_add(relevant_count, sum_relevant)
    return (tf.where(tf.equal(sum_retrieved, 0), tf.zeros_like(selected), (selected / sum_retrieved)), tf.where(tf.equal(sum_relevant, 0), tf.zeros_like(selected), (selected / sum_relevant)))

Computes the precision and recall of the prediction vs the labels.

Args:
input_: A rank 2 Tensor or a Pretty Tensor holding the result of the model.
labels: The target labels to learn as a float tensor.
threshold: The threshold to use to decide if the prediction is true.
per_example_weights: A Tensor with a weight per example.
name: An optional name.
phase: The phase of this model; non training phases compute a total across
all examples.
Returns:
Precision and Recall.


def remove_liers(points):
    result = [points[0]]
    for i in range(1, (len(points) - 2)):
        prv = points[(i - 1)]
        crr = points[i]
        nxt = points[(i + 1)]
        if ((prv.time <= crr.time) and (crr.time <= nxt.time)):
            result.append(crr)
    result.append(points[(- 1)])
    return result

Removes obvious noise points

Checks time consistency, removing points that appear out of order

Args:
points (:obj:`list` of :obj:`Point`)
Returns:
:obj:`list` of :obj:`Point`


def add_perm(self, subj_str, perm_str):
    self._assert_valid_permission(perm_str)
    self._perm_dict.setdefault(perm_str, set()).add(subj_str)

Add a permission for a subject.

Args:
subj_str : str
Subject for which to add permission(s)

perm_str : str
Permission to add. Implicitly adds all lower permissions. E.g., ``write``
will also add ``read``.


def transform_string_replace(source, needle, haystack, name=None):

    with ops.name_scope(name, "TransformStringReplace", [source]):
        source = convert_to_tensor_or_sparse_tensor(source, dtype=tf.string)
        if isinstance(source, tf.SparseTensor):
            result = tf.SparseTensor(
                indices=source.indices,
                values=ops_module.transform_string_replace(source.values, needle, haystack),
                dense_shape=source.dense_shape
            )
        else:
            result = ops_module.transform_string_replace(source, needle, haystack)

    return result

Replace all substrings from `needle` to corresponding strings in `haystack` with source.

Args:
source: `Tensor` or `SparseTensor` of any shape, source strings for replacing.
needle: List of strings to search in source
haystack: List of strings to replace with. Should have same length as `needle`.
name: A name for the operation (optional).
Returns:
`Tensor` or `SparseTensor` of same shape and size as input.


def inspect_network(self, net_id, verbose=None, scope=None):
    params = {}
    if (verbose is not None):
        if version_lt(self._version, '1.28'):
            raise InvalidVersion('verbose was introduced in API 1.28')
        params['verbose'] = verbose
    if (scope is not None):
        if version_lt(self._version, '1.31'):
            raise InvalidVersion('scope was introduced in API 1.31')
        params['scope'] = scope
    url = self._url('/networks/{0}', net_id)
    res = self._get(url, params=params)
    return self._result(res, json=True)

Get detailed information about a network.

Args:
net_id (str): ID of network
verbose (bool): Show the service details across the cluster in
swarm mode.
scope (str): Filter the network by scope (``swarm``, ``global``
or ``local``).


def _load_callwraps(packname, package):
    global _callwraps
    from acorn.config import settings
    from acorn.logging.descriptors import _obj_getattr
    spack = settings(packname)
    if (spack is not None):
        if spack.has_section('callwrap'):
            wrappings = dict(spack.items('callwrap'))
            for (fqdn, target) in wrappings.items():
                caller = _obj_getattr(package, target)
                _callwraps[fqdn] = caller

Loads the special call wrapping settings for functions in the specified
package. This allows the result of the original method call to be cast as a
different type, or passed to a different constructor before returning from
the wrapped function.

Args:
packname (str): name of the package to get config settings for.
package: actual package object.


def list_apps(site):
    ret = dict()
    ps_cmd = list()
    ps_cmd.append("Get-WebApplication -Site '{0}'".format(site))
    ps_cmd.append('| Select-Object applicationPool, path, PhysicalPath, preloadEnabled,')
    ps_cmd.append("@{ Name='name'; Expression={ $_.path.Split('/', 2)[-1] } },")
    ps_cmd.append("@{ Name='protocols'; Expression={ @( $_.enabledProtocols.Split(',')")
    ps_cmd.append('| Foreach-Object { $_.Trim() } ) } }')
    cmd_ret = _srvmgr(cmd=ps_cmd, return_json=True)
    try:
        items = salt.utils.json.loads(cmd_ret['stdout'], strict=False)
    except ValueError:
        raise CommandExecutionError('Unable to parse return data as Json.')
    for item in items:
        protocols = list()
        if isinstance(item['protocols'], dict):
            if ('value' in item['protocols']):
                protocols += item['protocols']['value']
        else:
            protocols.append(item['protocols'])
        ret[item['name']] = {'apppool': item['applicationPool'], 'path': item['path'], 'preload': item['preloadEnabled'], 'protocols': protocols, 'sourcepath': item['PhysicalPath']}
    if (not ret):
        log.warning('No apps found in output: %s', cmd_ret)
    return ret

Get all configured IIS applications for the specified site.

Args:
site (str): The IIS site name.

Returns: A dictionary of the application names and properties.

CLI Example:

.. code-block:: bash

salt '*' win_iis.list_apps site


def setOverrideLogLevel(lvl):
    if (lvl is None):
        return
    logging.info('Overriding log level globally to %s', lvl)
    lvl = getLevelName(lvl)
    global _overrideLogLevel
    _overrideLogLevel = lvl
    logging.getLogger('').setLevel(lvl)
    for loggerName in logging.Logger.manager.loggerDict:
        logger = logging.Logger.manager.loggerDict[loggerName]
        if isinstance(logger, logging.PlaceHolder):
            continue
        logger.setLevel(logging.NOTSET)

Override all logger filter levels to include lvl and above.

- Set root logger level
- iterates all existing loggers and sets their log level to ``NOTSET``.

Args:
lvl (string): Log level name.


def _compile_random_variable_expression(self, expr: Expression, scope: Dict[(str, TensorFluent)], batch_size: Optional[int]=None, noise: Optional[List[tf.Tensor]]=None) -> TensorFluent:
    etype = expr.etype
    args = expr.args
    if (etype[1] == 'KronDelta'):
        sample = self._compile_expression(args[0], scope, batch_size, noise)
    elif (etype[1] == 'Bernoulli'):
        mean = self._compile_expression(args[0], scope, batch_size, noise)
        (dist, sample) = TensorFluent.Bernoulli(mean, batch_size)
    elif (etype[1] == 'Uniform'):
        low = self._compile_expression(args[0], scope, batch_size, noise)
        high = self._compile_expression(args[1], scope, batch_size, noise)
        (dist, sample) = TensorFluent.Uniform(low, high, batch_size)
    elif (etype[1] == 'Normal'):
        if (noise is None):
            mean = self._compile_expression(args[0], scope, batch_size, noise)
            variance = self._compile_expression(args[1], scope, batch_size, noise)
            (dist, sample) = TensorFluent.Normal(mean, variance, batch_size)
        else:
            xi = noise.pop()
            xi = TensorFluent(xi, scope=[], batch=True)
            mean = self._compile_expression(args[0], scope, batch_size, noise)
            variance = self._compile_expression(args[1], scope, batch_size, noise)
            sample = (mean + (TensorFluent.sqrt(variance) * xi))
    elif (etype[1] == 'Laplace'):
        mean = self._compile_expression(args[0], scope, batch_size, noise)
        variance = self._compile_expression(args[1], scope, batch_size, noise)
        (dist, sample) = TensorFluent.Laplace(mean, variance, batch_size)
    elif (etype[1] == 'Gamma'):
        shape = self._compile_expression(args[0], scope, batch_size, noise)
        scale = self._compile_expression(args[1], scope, batch_size, noise)
        (dist, sample) = TensorFluent.Gamma(shape, scale, batch_size)
    elif (etype[1] == 'Exponential'):
        mean = self._compile_expression(args[0], scope, batch_size, noise)
        (dist, sample) = TensorFluent.Exponential(mean, batch_size)
    else:
        raise ValueError('Invalid random variable expression:\n{}.'.format(expr))
    return sample

Compile a random variable expression `expr` into a TensorFluent
in the given `scope` with optional batch size.

If `reparam` tensor is given, then it conditionally stops gradient
backpropagation at the batch level where `reparam` is False.

Args:
expr (:obj:`rddl2tf.expr.Expression`): A RDDL random variable expression.
scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope.
batch_size (Optional[size]): The batch size.

Returns:
:obj:`rddl2tf.fluent.TensorFluent`: The compiled expression as a TensorFluent.


def _check_id(entity, entity_type):
    if (entity is None):
        raise ParseError('{} ID missing'.format(entity_type))
    elif (not isinstance(entity, string_types)):
        msg = '{} ID must be a string, id was {}.'.format(entity_type, entity)
        if isinstance(entity, bool):
            msg += ' You may have accidentally used an ID value that YAML interprets as a boolean, such as "yes", "no", "on", "off", "true" or "false". To use this ID, you have to quote it with single or double quotes'
        raise ParseError(msg)
    elif (len(entity) == 0):
        raise ParseError('{} ID must not be empty'.format(entity_type))

Check whether the ID is valid.

First check if the ID is missing, and then check if it is a qualified
string type, finally check if the string is empty. For all checks, it
would raise a ParseError with the corresponding message.

Args:
entity: a string type object to be checked.
entity_type: a string that shows the type of entities to check, usually
`Compound` or 'Reaction'.


def _SkipFieldContents(tokenizer):

  if tokenizer.TryConsume(':') and not tokenizer.LookingAt(
      '{') and not tokenizer.LookingAt('<'):
    _SkipFieldValue(tokenizer)
  else:
    _SkipFieldMessage(tokenizer)

Skips over contents (value or message) of a field.

Args:
tokenizer: A tokenizer to parse the field name and values.


def get_memory_region(x, query_block_shape, memory_flange, q_indices):
    x_query_padded = pad_to_multiple_2d(x, query_block_shape)
    x_center = gather_blocks_2d(x_query_padded, q_indices)
    paddings = [[0, 0], [0, 0], [memory_flange[0], 0], [memory_flange[1], memory_flange[1]], [0, 0]]
    x_memory_padded = tf.pad(x_query_padded, paddings)
    left_x = None
    top_x = None
    if (memory_flange[1] > 0):
        left_x_region = x_memory_padded[(:, :, memory_flange[0]:, :(- (query_block_shape[1] + memory_flange[1])), :)]
        left_memory_shape = (query_block_shape[0], memory_flange[1])
        left_indices = gather_indices_2d(left_x_region, left_memory_shape, query_block_shape)
        left_x = gather_blocks_2d(left_x_region, left_indices)
    if (memory_flange[0] > 0):
        top_x_region = x_memory_padded[(:, :, :(- query_block_shape[0]), :, :)]
        top_memory_shape = (memory_flange[0], (query_block_shape[1] + (2 * memory_flange[1])))
        top_indices = gather_indices_2d(top_x_region, top_memory_shape, query_block_shape)
        top_x = gather_blocks_2d(top_x_region, top_indices)
    x_flange = None
    if ((top_x is not None) and (left_x is not None)):
        x_flange = tf.concat([top_x, left_x], axis=3)
    else:
        x_flange = (top_x if (top_x is not None) else left_x)
    return (x_flange, x_center)

Get the memory regions that surround a 2d query.

The memory regions will be the left and top right.

Args:
x: A tensor with shape [batch, heads, height, width, depth]
query_block_shape: a 2-d tuple of integers
memory_flange: a 2-d tuple of integers
q_indices: a tensor of indices for each of the center blocks.
[num_blocks, block_length]
Returns:
x_flange: A tensor of shape [batch, heads, #blocks, block_length, depth]


def _parse_query(self, source):

        if self.OBJECTFILTER_WORDS.search(source):
            syntax_ = "objectfilter"
        else:
            syntax_ = None

        return query.Query(source, syntax=syntax_)

Parse one of the rules as either objectfilter or dottysql.

Example:
_parse_query("5 + 5")
# Returns Sum(Literal(5), Literal(5))

Arguments:
source: A rule in either objectfilter or dottysql syntax.

Returns:
The AST to represent the rule.


def get_atten(self, idx=0):
    if (not self.is_open):
        raise attenuator.Error(('Connection to attenuator at %s is not open!' % self._telnet_client.host))
    if (((idx + 1) > self.path_count) or (idx < 0)):
        raise IndexError('Attenuator index out of range!', self.path_count, idx)
    atten_val_str = self._telnet_client.cmd(('CHAN:%s:ATT?' % (idx + 1)))
    atten_val = float(atten_val_str)
    return atten_val

This function returns the current attenuation from an attenuator at a
given index in the instrument.

Args:
idx: This zero-based index is the identifier for a particular
attenuator in an instrument.

Raises:
Error: The underlying telnet connection to the instrument is not
open.

Returns:
A float that is the current attenuation value.


def _validate_signatures(signature_def_map: _SignatureDefMap, exported_graph: ops.Graph) -> _SignatureDefMap:
    for signature_key, signature_def in signature_def_map.items():
        for tensor_info in signature_def.inputs.values():
            try:
                exported_graph.get_tensor_by_name(tensor_info.name)
            except KeyError as exc:
                try:
                    prefixed_name = signature_key + '_' + tensor_info.name
                    exported_graph.get_tensor_by_name(prefixed_name)
                    tensor_info.name = prefixed_name
                except KeyError:
                    raise ValueError('Cannot find the input tensor with name %s in the graph.' % tensor_info.name) from exc
        for tensor_info in signature_def.outputs.values():
            try:
                exported_graph.get_tensor_by_name(tensor_info.name)
            except KeyError as exc:
                try:
                    prefixed_name = signature_key + '_' + tensor_info.name
                    exported_graph.get_tensor_by_name(prefixed_name)
                    tensor_info.name = prefixed_name
                except KeyError:
                    raise ValueError('Cannot find the output tensor with name %s in the graph.' % tensor_info.name) from exc
    return signature_def_map

Validates if the tensor names in signatures are consistent with the graph.

This function checks if the input and output tensor names in the signatures
exist if the graph. The output tensor names might change during conversion,
we try to fix that with `_restore_output_tensor_names`. Besides, if there
are duplicated tensor names, they we will be prefixed with the signature name.
However, if that doesn't work the signatures can't be used with the converted
graph.

Args:
signature_def_map: the signatures to validate.
exported_graph: The PTQ-exported GraphDef.

Returns:
The signatures with tensor names prefixed with signature name if necessary.

Raises:
ValueError: Iff the signatures are not consistent with the graph.


def info_qry(tickers, flds) -> str:

    full_list = '\n'.join([f'tickers: {tickers[:8]}'] + [
        f'         {tickers[n:(n + 8)]}' for n in range(8, len(tickers), 8)
    ])
    return f'{full_list}\nfields:  {flds}'

Logging info for given tickers and fields

Args:
tickers: tickers
flds: fields

Returns:
str

Examples:
>>> print(info_qry(
...     tickers=['NVDA US Equity'], flds=['Name', 'Security_Name']
... ))
tickers: ['NVDA US Equity']
fields:  ['Name', 'Security_Name']


def get_dependent_projects(self, recursive=True):
    projects = {}
    for (name, ref) in list(self.dependencies.items()):
        try:
            prj = self.vcp.projects[name]
        except KeyError:
            logger.error("Unknown project '%s' in project '%s' dependencies!", name, self.name)
            continue
        projects[name] = prj
        if recursive:
            projects.update(prj.get_dependent_projects())
    return projects

Get the dependencies of the Project

Args:
recursive (bool): add the dependant project's dependencies too

Returns:
dict of project name and project instances


def _two_element_tuple(int_or_tuple):
    if isinstance(int_or_tuple, (list, tuple)):
        if (len(int_or_tuple) != 2):
            raise ValueError(('Must be a list with 2 elements: %s' % int_or_tuple))
        return (int(int_or_tuple[0]), int(int_or_tuple[1]))
    if isinstance(int_or_tuple, int):
        return (int(int_or_tuple), int(int_or_tuple))
    if isinstance(int_or_tuple, tf.TensorShape):
        if (len(int_or_tuple) == 2):
            return (int_or_tuple[0], int_or_tuple[1])
    raise ValueError('Must be an int, a list with 2 elements or a TensorShape of length 2')

Converts `int_or_tuple` to height, width.

Several of the functions that follow accept arguments as either
a tuple of 2 integers or a single integer.  A single integer
indicates that the 2 values of the tuple are the same.

This functions normalizes the input value by always returning a tuple.

Args:
int_or_tuple: A list of 2 ints, a single int or a tf.TensorShape.

Returns:
A tuple with 2 values.

Raises:
ValueError: If `int_or_tuple` it not well formed.


def on_predict_begin(self, logs=None):
    logs = self._process_logs(logs)
    for callback in self.callbacks:
        callback.on_predict_begin(logs)

Calls the 'on_predict_begin` methods of its callbacks.

Args:
logs: Dict. Currently no data is passed to this argument for this method
but that may change in the future.


def value(self):
    if (not self.is_value_set):
        raise MeasurementNotSetError('Measurement not yet set', self.name)
    return [(dimensions + (value,)) for (dimensions, value) in six.iteritems(self.value_dict)]

The values stored in this record.

Returns:
A list of tuples; the last element of each tuple will be the measured
value, the other elements will be the associated coordinates.  The tuples
are output in the order in which they were set.


def post(self, url, params=None, data=None, files=None, **kwargs):
    return self.call_api('POST', url, params=params, data=data, files=files, **kwargs)

Call the API with a POST request.

Args:
url (str): Resource location relative to the base URL.
params (dict or None): Query-string parameters.
data (dict or None): Request body contents.
files (dict or None: Files to be passed to the request.

Returns:
An instance of ResultParser or ErrorParser.


def get_lambda_alias_arn(app, account, region):

    session = boto3.Session(profile_name=account, region_name=region)
    lambda_client = session.client('lambda')

    lambda_aliases = lambda_client.list_aliases(FunctionName=app)

    matched_alias = None
    for alias in lambda_aliases['Aliases']:
        if alias['Name'] == account:
            lambda_alias_arn = alias['AliasArn']
            LOG.info('Found ARN for alias %s for function %s', account, app)
            matched_alias = lambda_alias_arn
            break
    else:
        fatal_message = 'Lambda alias {0} of function {1} not found'.format(account, app)
        LOG.fatal(fatal_message)
        raise LambdaAliasDoesNotExist(fatal_message)
    return matched_alias

Get lambda alias ARN. Assumes that account name is equal to alias name.

Args:
account (str): AWS account name.
region (str): Region name, e.g. us-east-1
app (str): Lambda function name

Returns:
str: ARN for requested lambda alias


def fromcube(cube, template):

    array = dc.zeros_like(template)

    y, x = array.y.values, array.x.values
    gy, gx = cube.y.values, cube.x.values
    iy = interp1d(gy, np.arange(len(gy)))(y)
    ix = interp1d(gx, np.arange(len(gx)))(x)

    for ch in range(len(cube.ch)):
        array[:,ch] = map_coordinates(cube.values[:,:,ch], (ix, iy))

    return array

Covert a decode cube to a decode array.

Args:
cube (decode.cube): Decode cube to be cast.
template (decode.array): Decode array whose shape the cube is cast on.

Returns:
decode array (decode.array): Decode array.

Notes:
This functions is under development.


def insert(self, part):
    params = {k: str(v) for (k, v) in part.params.items()}
    res = c.create_assembly_instance(self.uri.as_dict(), part.uri.as_dict(), params)
    return res

Insert a part into this assembly.

Args:
- part (onshapepy.part.Part) A Part instance that will be inserted.

Returns:
- requests.Response: Onshape response data


def get_function(rule, domain, normalize, **parameters):
    from ...distributions.baseclass import Dist
    if isinstance(domain, Dist):
        (lower, upper) = domain.range()
        parameters['dist'] = domain
    else:
        (lower, upper) = numpy.array(domain)
    parameters['lower'] = lower
    parameters['upper'] = upper
    quad_function = QUAD_FUNCTIONS[rule]
    parameters_spec = inspect.getargspec(quad_function)[0]
    parameters_spec = {key: None for key in parameters_spec}
    del parameters_spec['order']
    for key in parameters_spec:
        if (key in parameters):
            parameters_spec[key] = parameters[key]

    def _quad_function(order, *args, **kws):
        'Implementation of quadrature function.'
        params = parameters_spec.copy()
        params.update(kws)
        (abscissas, weights) = quad_function(order, *args, **params)
        if ((rule in UNORMALIZED_QUADRATURE_RULES) and normalize):
            if isinstance(domain, Dist):
                if (len(domain) == 1):
                    weights *= domain.pdf(abscissas).flatten()
                else:
                    weights *= domain.pdf(abscissas)
            weights /= numpy.sum(weights)
        return (abscissas, weights)
    return _quad_function

Create a quadrature function and set default parameter values.

Args:
rule (str):
Name of quadrature rule defined in ``QUAD_FUNCTIONS``.
domain (Dist, numpy.ndarray):
Defines ``lower`` and ``upper`` that is passed quadrature rule. If
``Dist``, ``domain`` is renamed to ``dist`` and also
passed.
normalize (bool):
In the case of distributions, the abscissas and weights are not
tailored to a distribution beyond matching the bounds. If True, the
samples are normalized multiplying the weights with the density of
the distribution evaluated at the abscissas and normalized
afterwards to sum to one.
parameters (:py:data:typing.Any):
Redefining of the parameter defaults. Only add parameters that the
quadrature rule expect.
Returns:
(:py:data:typing.Callable):
Function that can be called only using argument ``order``.


def extract_equalities(self):
    raise NotImplementedError()

Find all equalities that appear in this term.

Returns:
A sequence of tuples of a string (variable name) and a string (value or
variable name).


def getLogger(self, component_name: str = None) -> logging.Logger:

        logger_name = self.root + (component_name if component_name else 'generic')
        _logger = self.loggers.get(logger_name)
        if not _logger:
            _logger = logging.getLogger(logger_name)

            stdio_handler = logging.StreamHandler()
            stdio_handler.setFormatter(LogFormatter())
            stdio_handler.setLevel(logging.INFO)
            _logger.addHandler(stdio_handler)
            _logger.setLevel(logging.DEBUG)
            self.loggers[logger_name] = _logger
        return _logger

Get the logger instance matching ``component_name`` or create a new one if non-existent.

Args:
component_name: a neo-python component name. e.g. network, vm, db

Returns:
a logger for the specified component.


def exhaustive_label_check(self, ontology: pd.DataFrame, label_predicate='rdfs:label', diff: bool=True) -> Tuple[list]:
    (inside, outside) = ([], [])
    header = (['Index'] + list(ontology.columns))
    for row in ontology.itertuples():
        row = {header[i]: val for (i, val) in enumerate(row)}
        label_obj = row[label_predicate]
        if isinstance(label_obj, list):
            if (len(label_obj) != 1):
                exit('Need to have only 1 label in the cell from the onotology.')
            else:
                label_obj = label_obj[0]
        entity_label = self.local_degrade(label_obj)
        ilx_rows = self.label2rows.get(entity_label)
        if ilx_rows:
            inside.append({'external_ontology_row': row, 'ilx_rows': ilx_rows})
        else:
            outside.append(row)
    if diff:
        diff = self.__exhaustive_diff(inside)
        return (inside, outside, diff)
    return (inside, outside)

All entities with conflicting labels gets a full diff

Args:
ontology: pandas DataFrame created from an ontology where the colnames are predicates
and if classes exist it is also thrown into a the colnames.
label_predicate: usually in qname form and is the colname of the DataFrame for the label
diff: complete exhaustive diff if between curie matches... will take FOREVER if there are a lot -> n^2
Returns:
inside: entities that are inside of InterLex
outside: entities NOT in InterLex
diff (optional): List[List[dict]]... so complicated but usefull diff between matches only


def set(self, value):
    pywrap_tfe.TFE_MonitoringIntGaugeCellSet(self._cell, value)

Atomically set the value.

Args:
value: integer value.


def assertAllInSet(self, target, expected_set):
    target = self._GetNdArray(target)
    diff = np.setdiff1d(target.flatten(), list(expected_set))
    if np.size(diff):
        raise AssertionError('%d unique element(s) are not in the set %s: %s' % (np.size(diff), expected_set, diff))

Assert that elements of a Tensor are all in a given closed set.

Args:
target: The numpy `ndarray`, or anything that can be converted into a
numpy `ndarray` (including Tensor).
expected_set: (`list`, `tuple` or `set`) The closed set that the elements
of the value of `target` are expected to fall into.

Raises:
AssertionError:
if any of the elements do not fall into `expected_set`.


def send_heartbeat(self, name):

        return self._loop.run_coroutine(self._client.send_heartbeat(name))

Send a heartbeat for a service.

Args:
name (string): The name of the service to send a heartbeat for


def GetFileEntryByPathSpec(self, path_spec):

    return gzip_file_entry.GzipFileEntry(
        self._resolver_context, self, path_spec, is_root=True, is_virtual=True)

Retrieves a file entry for a path specification.

Args:
path_spec (PathSpec): path specification.

Returns:
GzipFileEntry: a file entry or None if not available.


def transform(self, sents):

        def convert(tokens):
            return torch.tensor([self.vocab.stoi[t] for t in tokens], dtype=torch.long)

        if self.vocab is None:
            raise Exception(
                "Must run .fit() for .fit_transform() before " "calling .transform()."
            )

        seqs = sorted([convert(s) for s in sents], key=lambda x: -len(x))
        X = torch.LongTensor(pad_sequence(seqs, batch_first=True))
        return X

Converts lists of tokens into a Tensor of embedding indices.

Args:
sents: A list of lists of tokens (representing sentences)
NOTE: These sentences should already be marked using the
mark_entities() helper.
Returns:
X: A Tensor of shape (num_items, max_seq_len)


def assert_equal(first, second, msg=None, extras=None):

    my_msg = None
    try:
        _pyunit_proxy.assertEqual(first, second)
    except AssertionError as e:
        my_msg = str(e)
        if msg:
            my_msg = "%s %s" % (my_msg, msg)

    if my_msg is not None:
        raise signals.TestFailure(my_msg, extras=extras)

Assert the equality of objects, otherwise fail the test.

Error message is "first != second" by default. Additional explanation can
be supplied in the message.

Args:
first: The first object to compare.
second: The second object to compare.
msg: A string that adds additional info about the failure.
extras: An optional field for extra information to be included in
test result.


def HandleGetBlocksMessageReceived(self, payload):
    if (not self.leader.ServiceEnabled):
        return
    inventory = IOHelper.AsSerializableWithType(payload, 'neo.Network.Payloads.GetBlocksPayload.GetBlocksPayload')
    if (not inventory):
        return
    blockchain = BC.Default()
    hash = inventory.HashStart[0]
    if (not blockchain.GetHeader(hash)):
        return
    hashes = []
    hcount = 0
    while ((hash != inventory.HashStop) and (hcount < 500)):
        hash = blockchain.GetNextBlockHash(hash)
        if (hash is None):
            break
        hashes.append(hash)
        hcount += 1
    if (hcount > 0):
        self.SendSerializedMessage(Message('inv', InvPayload(type=InventoryType.Block, hashes=hashes)))

Process a GetBlocksPayload payload.

Args:
payload (neo.Network.Payloads.GetBlocksPayload):


def run_from_cli(self, args):

        if args['--dump-config']:
            self._config.print_config()
        else:
            stdout, stderr = self.lint(args['<path>'])
            self.print_results(stdout, stderr)

Read arguments, run and print results.

Args:
args (dict): Arguments parsed by docopt.


def SetWeight(self, path_segment_index, weight):

    if path_segment_index not in self._weight_per_index:
      raise ValueError('Path segment index not set.')

    self._weight_per_index[path_segment_index] = weight

    if weight not in self._indexes_per_weight:
      self._indexes_per_weight[weight] = []

    self._indexes_per_weight[weight].append(path_segment_index)

Sets a weight for a specific path segment index.

Args:
path_segment_index: an integer containing the path segment index.
weight: an integer containing the weight.

Raises:
ValueError: if the path segment weights do not contain
the path segment index.


def MessageToDict(message, including_default_value_fields=False, preserving_proto_field_name=False):
    printer = _Printer(including_default_value_fields, preserving_proto_field_name)
    return printer._MessageToJsonObject(message)

Converts protobuf message to a JSON dictionary.

Args:
message: The protocol buffers message instance to serialize.
including_default_value_fields: If True, singular primitive fields,
repeated fields, and map fields will always be serialized.  If
False, only serialize non-empty fields.  Singular message fields
and oneof fields are not affected by this option.
preserving_proto_field_name: If True, use the original proto field
names as defined in the .proto file. If False, convert the field
names to lowerCamelCase.

Returns:
A dict representation of the JSON formatted protocol buffer message.


def has_code(state, text, pattern=True, not_typed_msg=None):
    if (not not_typed_msg):
        if pattern:
            not_typed_msg = 'Could not find the correct pattern in your code.'
        else:
            not_typed_msg = ('Could not find the following text in your code: %r' % text)
    student_code = state.student_code
    _msg = state.build_message(not_typed_msg)
    state.do_test(StringContainsTest(student_code, text, pattern, Feedback(_msg, state)))
    return state

Test the student code.

Tests if the student typed a (pattern of) text. It is advised to use ``has_equal_ast()`` instead of ``has_code()``,
as it is more robust to small syntactical differences that don't change the code's behavior.

Args:
text (str): the text that is searched for
pattern (bool): if True (the default), the text is treated as a pattern. If False, it is treated as plain text.
not_typed_msg (str): feedback message to be displayed if the student did not type the text.

:Example:

Student code and solution code::

y = 1 + 2 + 3

SCT::

# Verify that student code contains pattern (not robust!!):
Ex().has_code(r"1\\s*\\+2\\s*\\+3")


def single_node_env(args):
    if isinstance(args, list):
        sys.argv = args
    elif args.argv:
        sys.argv = args.argv
    num_gpus = (args.num_gpus if ('num_gpus' in args) else 1)
    util.single_node_env(num_gpus)

Sets up environment for a single-node TF session.

Args:
:args: command line arguments as either argparse args or argv list


def convert_n_to_tensor_or_composite(values, dtype=None, name=None) -> list[Union[EagerTensor, SymbolicTensor, composite_tensor.CompositeTensor, type(None)]]:
    return internal_convert_n_to_tensor_or_composite(values=values, dtype=dtype, name=name, as_ref=False)

Converts `values` to a list of `Output` or `CompositeTensor` objects.

Any `CompositeTensor` objects in `values` are returned unmodified.

Args:
values: A list of `None`, `CompositeTensor``, or objects that can be
consumed by `convert_to_tensor()`.
dtype: (Optional.) The required `DType` of the returned `Tensor`s or
`CompositeTensor`s.
name: (Optional.) A name prefix to used when a new `Tensor` is created, in
which case element `i` will be given the name `name + '_' + i`.

Returns:
A list of `Tensor` and/or `CompositeTensor` objects.

Raises:
TypeError: If no conversion function is registered for an element in
`values`.
RuntimeError: If a registered conversion function returns an invalid
value.


def tf_record_iterator(path, options=None):
    compression_type = TFRecordOptions.get_compression_type_string(options)
    return _pywrap_record_io.RecordIterator(path, compression_type)

An iterator that read the records from a TFRecords file.

Args:
path: The path to the TFRecords file.
options: (optional) A TFRecordOptions object.

Returns:
An iterator of serialized TFRecords.

Raises:
IOError: If `path` cannot be opened for reading.


def asdatetime(self, naive=True):
    args = (list(self.timetuple()[0:6]) + [self.microsecond])
    if (not naive):
        args.append(self.tzinfo)
    return datetime.datetime(*args)

Return this datetime_tz as a datetime object.

Args:
naive: Return *without* any tz info.

Returns:
This datetime_tz as a datetime object.


def tags(self, main_type, sub_type, unique_id, owner=None, filters=None, params=None):

        params = params or {}

        if owner:
            params['owner'] = owner
        if filters and filters.filters:
            params['filters'] = filters.filters_string
        if not sub_type:
            url = '/v2/{}/{}/tags'.format(main_type, unique_id)
        else:
            url = '/v2/{}/{}/{}/tags'.format(main_type, sub_type, unique_id)

        for t in self._iterate(url, params, 'tag'):
            yield t

Args:
main_type:
sub_type:
unique_id:
owner:
filters:
params:

Return:


def extract(self, accumulator):
    pass

Convert an accumulator into a dict of output values.

Args:
accumulator: The accumulator to convert.

Returns:
A dict of ndarrays representing the data in this accumulator.


def calculate_rouge(pred_lns: list[str], tgt_lns: list[str], use_stemmer=True, rouge_keys=ROUGE_KEYS, return_precision_and_recall=False, bootstrap_aggregation=True, newline_sep=True) -> dict:
    scorer = rouge_scorer.RougeScorer(rouge_keys, use_stemmer=use_stemmer)
    aggregator = scoring.BootstrapAggregator()
    for pred, tgt in zip(tgt_lns, pred_lns):
        if newline_sep:
            pred = add_newline_to_end_of_each_sentence(pred)
            tgt = add_newline_to_end_of_each_sentence(tgt)
        scores = scorer.score(pred, tgt)
        aggregator.add_scores(scores)
    if bootstrap_aggregation:
        result = aggregator.aggregate()
        if return_precision_and_recall:
            return extract_rouge_mid_statistics(result)
        else:
            return {k: round(v.mid.fmeasure * 100, 4) for k, v in result.items()}
    else:
        return aggregator._scores

Calculate rouge using rouge_scorer package.

Args:
pred_lns: list of summaries generated by model
tgt_lns: list of groundtruth summaries (e.g. contents of val.target)
use_stemmer:  Bool indicating whether Porter stemmer should be used to
strip word suffixes to improve matching.
rouge_keys:  which metrics to compute, defaults to rouge1, rouge2, rougeL, rougeLsum
return_precision_and_recall: (False) whether to also return precision and recall.
bootstrap_aggregation: whether to do the typical bootstrap resampling of scores. Defaults to True, if False
this function returns a collections.defaultdict[metric: list of values for each observation for each subscore]``
newline_sep:(default=True) whether to add newline between sentences. This is essential for calculation rougeL
on multi sentence summaries (CNN/DM dataset).

Returns:
Dict[score: value] if aggregate else defaultdict(list) keyed by rouge_keys


def close(self, child):

        c = self.children[child]

        if c.children is not None and len(c.children) != 0:
            c.flatten()

        if c.value != 0. and not np.isnan(c.value):
            c.allocate(-c.value)

Close a child position - alias for rebalance(0, child). This will also
flatten (close out all) the child's children.

Args:
* child (str): Child, specified by name.


def _choose_random_edge(self, edges: Set[EDGE]) -> Optional[EDGE]:
    if edges:
        index = self._rand.randint(len(edges))
        for e in edges:
            if (not index):
                return e
            index -= 1
    return None

Picks random edge from the set of edges.

Args:
edges: Set of edges to pick from.

Returns:
Random edge from the supplied set, or None for empty set.


def get_signature_request_file(self, signature_request_id, path_or_file=None, file_type=None, filename=None):
    request = self._get_request()
    url = (self.SIGNATURE_REQUEST_DOWNLOAD_PDF_URL + signature_request_id)
    if file_type:
        url += ('?file_type=%s' % file_type)
    return request.get_file(url, (path_or_file or filename))

Download the PDF copy of the current documents

Args:

signature_request_id (str): Id of the signature request

path_or_file (str or file): A writable File-like object or a full path to save the PDF file to.

filename (str):             [DEPRECATED] Filename to save the PDF file to. This should be a full path.

file_type (str):            Type of file to return. Either "pdf" for a single merged document or "zip" for a collection of individual documents. Defaults to "pdf" if not specified.

Returns:
True if file is downloaded and successfully written, False otherwise.


def compute_k(self, memory_antecedent):

    if self.shared_kv:
      raise ValueError("compute_k cannot be called with shared_kv")
    ret = mtf.einsum(
        [memory_antecedent, self.wk], reduced_dims=[self.memory_input_dim])
    if self.combine_dims:
      ret = mtf.replace_dimensions(ret, ret.shape.dims[-1], self.k_dims)
    return ret

Compute key Tensor k.

Args:
memory_antecedent: a Tensor with dimensions
{memory_input_dim} + other_dims
Returns:
a Tensor with dimensions
memory_heads_dims + {key_dim} + other_dims


def intersect(self, other):

        lowest_stop = min(self.stop_hz, other.stop_hz)
        highest_start = max(self.start_hz, other.start_hz)
        return FrequencyBand(highest_start, lowest_stop)

Return the intersection between this frequency band and another.

Args:
other (FrequencyBand): the instance to intersect with

Examples::
>>> import zounds
>>> b1 = zounds.FrequencyBand(500, 1000)
>>> b2 = zounds.FrequencyBand(900, 2000)
>>> intersection = b1.intersect(b2)
>>> intersection.start_hz, intersection.stop_hz
(900, 1000)


def drop(self, index=None, columns=None):

        if self._is_transposed:
            return self.transpose().drop(index=columns, columns=index).transpose()
        if index is None:
            new_data = self.data
            new_index = self.index
        else:

            def delitem(df, internal_indices=[]):
                return df.drop(index=df.index[internal_indices])

            numeric_indices = list(self.index.get_indexer_for(index))
            new_data = self.data.apply_func_to_select_indices(
                1, delitem, numeric_indices, keep_remaining=True
            )

            new_index = self.index[~self.index.isin(index)]
        if columns is None:
            new_columns = self.columns
            new_dtypes = self.dtypes
        else:

            def delitem(df, internal_indices=[]):
                return df.drop(columns=df.columns[internal_indices])

            numeric_indices = list(self.columns.get_indexer_for(columns))
            new_data = new_data.apply_func_to_select_indices(
                0, delitem, numeric_indices, keep_remaining=True
            )

            new_columns = self.columns[~self.columns.isin(columns)]
            new_dtypes = self.dtypes.drop(columns)
        return self.__constructor__(new_data, new_index, new_columns, new_dtypes)

Remove row data for target index and columns.

Args:
index: Target index to drop.
columns: Target columns to drop.

Returns:
A new QueryCompiler.


def transform_preds(coords: np.ndarray, center: np.ndarray, scale: np.ndarray, output_size: np.ndarray) -> np.ndarray:
    if coords.shape[1] not in (2, 4, 5):
        raise ValueError('Coordinates need to have either 2, 4 or 5 dimensions.')
    if len(center) != 2:
        raise ValueError('Center needs to have 2 elements, one for x and one for y.')
    if len(scale) != 2:
        raise ValueError('Scale needs to consist of a width and height')
    if len(output_size) != 2:
        raise ValueError('Output size needs to consist of a height and width')
    scale = scale * 200.0
    scale_y = scale[1] / (output_size[0] - 1.0)
    scale_x = scale[0] / (output_size[1] - 1.0)
    target_coords = np.ones_like(coords)
    target_coords[:, 0] = coords[:, 0] * scale_x + center[0] - scale[0] * 0.5
    target_coords[:, 1] = coords[:, 1] * scale_y + center[1] - scale[1] * 0.5
    return target_coords

Get final keypoint predictions from heatmaps and apply scaling and
translation to map them back to the image.

Note:
num_keypoints: K

Args:
coords (`np.ndarray` of shape `(num_keypoints, ndims)`):

* If ndims=2, corrds are predicted keypoint location.
* If ndims=4, corrds are composed of (x, y, scores, tags)
* If ndims=5, corrds are composed of (x, y, scores, tags,
flipped_tags)

center (`np.ndarray` of shape `(2,)`):
Center of the bounding box (x, y).
scale (`np.ndarray` of shape `(2,)`):
Scale of the bounding box wrt original image of width and height.
output_size (`np.ndarray` of shape `(2,)`):
Size of the destination heatmaps in (height, width) format.

Returns:
np.ndarray: Predicted coordinates in the images.


def SetValue(self, value, raise_on_error=True):
    type_mappings = [(Text, 'string'), (bytes, 'data'), (bool, 'boolean'), (int, 'integer'), (long, 'integer'), (dict, 'dict'), (float, 'float')]
    if (value is None):
        self.none = 'None'
    elif isinstance(value, rdfvalue.RDFValue):
        self.rdf_value.data = value.SerializeToString()
        self.rdf_value.age = int(value.age)
        self.rdf_value.name = value.__class__.__name__
    elif isinstance(value, (list, tuple)):
        self.list.content.Extend([DataBlob().SetValue(v, raise_on_error=raise_on_error) for v in value])
    elif isinstance(value, set):
        self.set.content.Extend([DataBlob().SetValue(v, raise_on_error=raise_on_error) for v in value])
    elif isinstance(value, dict):
        self.dict.FromDict(value, raise_on_error=raise_on_error)
    else:
        for (type_mapping, member) in type_mappings:
            if isinstance(value, type_mapping):
                setattr(self, member, value)
                return self
        message = ('Unsupported type for ProtoDict: %s' % type(value))
        if raise_on_error:
            raise TypeError(message)
        setattr(self, 'string', message)
    return self

Receives a value and fills it into a DataBlob.

Args:
value: value to set
raise_on_error: if True, raise if we can't serialize.  If False, set the
key to an error string.

Returns:
self
Raises:
TypeError: if the value can't be serialized and raise_on_error is True


def get_json_shift(year, month, day, unit, count, period, symbol):
    epochs = date.get_end_start_epochs(year, month, day, 'last', unit, count)
    return chart_json(epochs['shifted'], epochs['initial'], period, symbol)[0]

Gets JSON from shifted date by the Poloniex API

Args:
year: Int between 1 and 9999.
month: Int between 1 and 12.
day: Int between 1 and 31.
unit: String of time period unit for count argument.
How far back to check historical market data.
Valid values: 'hour', 'day', 'week', 'month', 'year'
count: Int of units.
How far back to check historical market data.
period: Int defining width of each chart candlestick in seconds.
symbol: String of currency pair, like a ticker symbol.

Returns: JSON, list of dates where each entry is a dict of raw market data.


def use_init_args(init_arg_list: Sequence[str]) -> pg_typing.Decorator:

    def _decorator(cls):
        cls.update_schema([], extend=True, init_arg_list=init_arg_list)
        return cls
    return typing.cast(pg_typing.Decorator, _decorator)

Decorator for updating the `__init__` signature of a `pg.Object` subclass.

Examples::

@pg.use_init_args(['x', 'y', '*z'])
class Foo(pg.Object):
y: int
x: str
z: list[int]

f = Foo('abc', 1, 2, 3)
assert f.x == 'abc'
assert f.y == 1
assert f.z == [2, 3]

Args:
init_arg_list: A sequence of attribute names that will be used as the
positional arguments of `__init__`. The last element could be the name of
a list-type attribute, indicating it's used as `*args`. Keyword-only
arguments are not needed to be present in this list, which will be figured
out automatically based on class' schema.

Returns:
a decorator function that updates the `__init__` signature.


def clone_graph_nodes(inputs, outputs):
    nodes_to_clone = find_nodes_by_inputs_and_outputs(inputs, outputs)
    cloned_inputs = []
    cloned_outputs = []
    kt_id_mapping = {}
    op_id_mapping = {}
    for kt_input in tree.flatten(inputs):
        if is_input_keras_tensor(kt_input):
            cloned_inputs.append(kt_input)
            kt_id_mapping[id(kt_input)] = kt_input
        else:
            cloned_input = Input(batch_shape=kt_input.shape, dtype=kt_input.dtype, sparse=kt_input.sparse, name=kt_input.name + 'CLONE')
            cloned_inputs.append(cloned_input)
            kt_id_mapping[id(kt_input)] = cloned_input
            op_id_mapping[id(kt_input._keras_history[0])] = cloned_input._keras_history[0]
    cloned_inputs = tree.pack_sequence_as(inputs, cloned_inputs)
    for kt_output in tree.flatten(outputs):
        cpy = clone_single_keras_tensor(kt_output)
        cpy._keras_history = kt_output._keras_history
        cloned_outputs.append(cpy)
        kt_id_mapping[id(kt_output)] = cpy
    cloned_outputs = tree.pack_sequence_as(outputs, cloned_outputs)
    for node in nodes_to_clone:
        if id(node.operation) in op_id_mapping:
            operation = op_id_mapping[id(node.operation)]
        else:
            operation = node.operation
        output_copy = clone_keras_tensors(node.output_tensors, kt_id_mapping)
        if not isinstance(operation, InputLayer):
            call_args_copy = clone_keras_tensors(node.arguments.args, kt_id_mapping)
            call_kwargs_copy = clone_keras_tensors(node.arguments.kwargs, kt_id_mapping)
        else:
            call_args_copy = ()
            call_kwargs_copy = {}
        Node(operation, call_args=call_args_copy, call_kwargs=call_kwargs_copy, outputs=output_copy)
    return (cloned_inputs, cloned_outputs)

Clone the `Node` between the inputs and output tensors.

This function is used to create a new functional model from any intermediate
Keras tensors. The clone of the nodes mimic the behavior of reconstructing
the functional graph network by re-executing all the `__call__()` methods.
The cloned nodes will be appended to the layers.

Note that a new `keras.Input` will be created for any items in the
`inputs`

Args:
inputs: A nested structure of `KerasTensor` instances.
outputs: A nested structure of `KerasTensor` instances.

Returns:
A pair of inputs and outputs, with cloned `KerasTensor` instances.
They can be used to create a new functional model.


def __init__(self, mxid, Api):

        self.mxid = mxid
        self.user_api = Api(identity=mxid)
        self.api = Api()
        self._rooms = {}

Instantiates MatrixUser object.

Args:
mxid(str): User id (e.g. @me:example.createRoom)
Api(func): Generates api for calls to the server.


def get_initializer(initializer_range: float=0.02) -> keras.initializers.TruncatedNormal:
    return keras.initializers.TruncatedNormal(stddev=initializer_range)

Creates a `keras.initializers.TruncatedNormal` with the given range.

Args:
initializer_range (*float*, defaults to 0.02): Standard deviation of the initializer range.

Returns:
`keras.initializers.TruncatedNormal`: The truncated normal initializer.


def generate_query_key(self, serializer):
    rewritten = []
    last = (len(self.field) - 1)
    s = serializer
    field = None
    for (i, field_name) in enumerate(self.field):
        fields = s.fields
        if (field_name not in fields):
            fields = getattr(s, 'get_all_fields', (lambda : {}))()
        if (field_name == 'pk'):
            rewritten.append('pk')
            continue
        if (field_name not in fields):
            raise ValidationError(('Invalid filter field: %s' % field_name))
        field = fields[field_name]
        model_field_name = (field.source or field_name)
        model_field = get_model_field(s.get_model(), model_field_name)
        if isinstance(model_field, RelatedObject):
            model_field_name = model_field.field.related_query_name()
        rewritten.append(model_field_name)
        if (i == last):
            break
        s = getattr(field, 'serializer', None)
        if isinstance(s, serializers.ListSerializer):
            s = s.child
        if (not s):
            raise ValidationError(('Invalid nested filter field: %s' % field_name))
    if self.operator:
        rewritten.append(self.operator)
    return ('__'.join(rewritten), field)

Get the key that can be passed to Django's filter method.

To account for serialier field name rewrites, this method
translates serializer field names to model field names
by inspecting `serializer`.

For example, a query like `filter{users.events}` would be
returned as `users__events`.

Arguments:
serializer: A DRF serializer

Returns:
A filter key.


def bleu_score(logits, labels):

  predictions = tf.to_int32(tf.argmax(logits, axis=-1))

  bleu = tf.py_func(compute_bleu, (labels, predictions), tf.float32)
  return bleu, tf.constant(1.0)

Approximate BLEU score computation between labels and predictions.

An approximate BLEU scoring method since we do not glue word pieces or
decode the ids and tokenize the output. By default, we use ngram order of 4
and use brevity penalty. Also, this does not have beam search.

Args:
logits: Tensor of size [batch_size, length_logits, vocab_size]
labels: Tensor of size [batch-size, length_labels]

Returns:
bleu: int, approx bleu score


def firmware_outdated(self):

        datefmt = ' %b %d %Y %H:%M:%S'

        compat_date = self.compatible_firmware_version.split('compiled')[1]
        compat_date = datetime.datetime.strptime(compat_date, datefmt)

        fw_date = self.firmware_version.split('compiled')[1]
        fw_date = datetime.datetime.strptime(fw_date, datefmt)
        return (compat_date > fw_date)

Returns whether the J-Link's firmware version is older than the one
that the DLL is compatible with.

Note:
This is not the same as calling ``not jlink.firmware_newer()``.

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

Returns:
``True`` if the J-Link's firmware is older than the one supported by
the DLL, otherwise ``False``.


def ParseRow(self, parser_mediator, row_offset, row):

    try:
      timestamp = self._ConvertToTimestamp(
          row['date'], row['time'], parser_mediator.timezone)
    except errors.TimestampError as exception:
      parser_mediator.ProduceExtractionWarning(
          'Unable to parse time string: [{0:s} {1:s}] with error {2:s}'.format(
              repr(row['date']), repr(row['time']), exception))
      return

    if timestamp is None:
      return

    event_data = McafeeAVEventData()
    event_data.action = row['action']
    event_data.filename = row['filename']
    event_data.offset = row_offset
    event_data.rule = row['rule']
    event_data.status = row['status']
    event_data.trigger_location = row['trigger_location']
    event_data.username = row['username']

    event = time_events.TimestampEvent(
        timestamp, definitions.TIME_DESCRIPTION_WRITTEN)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a line of the log file and produces events.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
row_offset (int): line number of the row.
row (dict[str, str]): fields of a single row, as specified in COLUMNS.


def unpack_userparams(self, req_param_names=None, opt_param_names=None, **kwargs):
    req_param_names = req_param_names or []
    opt_param_names = opt_param_names or []
    for k, v in kwargs.items():
        if k in self.user_params:
            v = self.user_params[k]
        setattr(self, k, v)
    for name in req_param_names:
        if hasattr(self, name):
            continue
        if name not in self.user_params:
            raise Error('Missing required user param "%s" in test configuration.' % name)
        setattr(self, name, self.user_params[name])
    for name in opt_param_names:
        if hasattr(self, name):
            continue
        if name in self.user_params:
            setattr(self, name, self.user_params[name])
        else:
            logging.warning('Missing optional user param "%s" in configuration, continue.', name)

An optional function that unpacks user defined parameters into
individual variables.

After unpacking, the params can be directly accessed with self.xxx.

If a required param is not provided, an exception is raised. If an
optional param is not provided, a warning line will be logged.

To provide a param, add it in the config file or pass it in as a kwarg.
If a param appears in both the config file and kwarg, the value in the
config file is used.

User params from the config file can also be directly accessed in
self.user_params.

Args:
req_param_names: A list of names of the required user params.
opt_param_names: A list of names of the optional user params.
**kwargs: Arguments that provide default values.
e.g. unpack_userparams(required_list, opt_list, arg_a='hello')
self.arg_a will be 'hello' unless it is specified again in
required_list or opt_list.

Raises:
Error: A required user params is not provided.


def cprint(
    text,
    fg=Color.normal,
    bg=Color.normal,
    fg_dark=False,
    bg_dark=False,
    underlined=False,
    parse=False,
):

    if parse:
        color_re = Color.color_re()
        lines = text.splitlines()
        count = len(lines)
        for i, line in enumerate(lines):
            previous = 0
            end = len(line)
            for match in color_re.finditer(line):
                sys.stdout.write(line[previous : match.start()])
                d = match.groupdict()
                set_color(
                    d["color"], fg_dark=False if d["dark"] is None else True
                )
                previous = match.end()
            sys.stdout.write(
                line[previous:end]
                + ("\n" if (i < (count - 1) or text[-1] == "\n") else "")
            )
    else:
        set_color(fg, bg, fg_dark, bg_dark, underlined)
        sys.stdout.write(text)
        set_color()

Print string in to stdout using colored font.

See L{set_color} for more details about colors.

Args:
text (str): Text that needs to be printed.


def get_padding_bias(x):

  with tf.name_scope("attention_bias"):
    padding = get_padding(x)
    attention_bias = padding * _NEG_INF
    attention_bias = tf.expand_dims(
        tf.expand_dims(attention_bias, axis=1), axis=1)
  return attention_bias

Calculate bias tensor from padding values in tensor.

Bias tensor that is added to the pre-softmax multi-headed attention logits,
which has shape [batch_size, num_heads, length, length]. The tensor is zero at
non-padding locations, and -1e9 (negative infinity) at padding locations.

Args:
x: int tensor with shape [batch_size, length]

Returns:
Attention bias tensor of shape [batch_size, 1, 1, length].


def create_datastore_write_config(mapreduce_spec):
    force_writes = parse_bool(mapreduce_spec.params.get('force_writes', 'false'))
    if force_writes:
        return datastore_rpc.Configuration(force_writes=force_writes)
    else:
        return datastore_rpc.Configuration()

Creates datastore config to use in write operations.

Args:
mapreduce_spec: current mapreduce specification as MapreduceSpec.

Returns:
an instance of datastore_rpc.Configuration to use for all write
operations in the mapreduce.


def image_from_console(console: tcod.console.Console) -> tcod.image.Image:

    return tcod.image.Image._from_cdata(
        ffi.gc(
            lib.TCOD_image_from_console(_console(console)),
            lib.TCOD_image_delete,
        )
    )

Return an Image with a Consoles pixel data.

This effectively takes a screen-shot of the Console.

Args:
console (Console): Any Console instance.


def jaccard_sim(features1, features2):
    set1 = set(features1)
    set2 = set(features2)
    try:
        return (len(set1.intersection(set2)) / float(max(len(set1), len(set2))))
    except ZeroDivisionError:
        return 0

Compute similarity between two sets using Jaccard similarity.

Args:
features1: list of PE Symbols.
features2: list of PE Symbols.

Returns:
Returns an int.


def GetTestConfigs():
    test_configs = [('NDHWC', False), ('NDHWC', True)]
    if test.is_gpu_available(cuda_only=True):
        test_configs += [('NCDHW', True)]
    return test_configs

Get all the valid tests configs to run.

Returns:
all the valid test configs as tuples of data_format and use_gpu.


def state_scope(self, state_fluents: Sequence[tf.Tensor]) -> Dict[str, TensorFluent]:

        return dict(zip(self.rddl.domain.state_fluent_ordering, state_fluents))

Returns a partial scope with current state-fluents.

Args:
state_fluents (Sequence[tf.Tensor]): The current state fluents.

Returns:
A mapping from state fluent names to :obj:`rddl2tf.fluent.TensorFluent`.


def use_color(setting):

    if setting not in COLOR_CHOICES:
        raise InvalidColorSetting(setting)

    return (
        setting == 'always' or
        (setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)
    )

Choose whether to use color based on the command argument.

Args:
setting - Either `auto`, `always`, or `never`


def _format_output(content, typ):

    if "csv" in str(typ):
        return _format_csv(content, delimiter=",")

    if "tsv" in str(typ):
        return _format_csv(content, delimiter="\t")

    return content

Tabularize the content according to its type.

Args:
content (str): The content of a metric.
typ (str): The type of metric -- (raw|json|tsv|htsv|csv|hcsv).

Returns:
str: Content in a raw or tabular format.


def DEFINE_list(
    name, default, help, flag_values=FLAGS, **args):

  parser = ListParser()
  serializer = CsvListSerializer(',')
  DEFINE(parser, name, default, help, flag_values, serializer, **args)

Registers a flag whose value is a comma-separated list of strings.

The flag value is parsed with a CSV parser.

Args:
name: A string, the flag name.
default: The default value of the flag.
help: A help string.
flag_values: FlagValues object with which the flag will be registered.
**args: Dictionary with extra keyword args that are passed to the
Flag __init__.


def encode_plus(self, text: Union[TextInput, PreTokenizedInput], text_pair: Optional[PreTokenizedInput]=None, xpaths: Optional[List[List[int]]]=None, node_labels: Optional[List[int]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, stride: int=0, pad_to_multiple_of: Optional[int]=None, padding_side: Optional[str]=None, return_tensors: Optional[Union[str, TensorType]]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_offsets_mapping: bool=False, return_length: bool=False, verbose: bool=True, **kwargs) -> BatchEncoding:
    padding_strategy, truncation_strategy, max_length, kwargs = self._get_padding_truncation_strategies(padding=padding, truncation=truncation, max_length=max_length, pad_to_multiple_of=pad_to_multiple_of, verbose=verbose, **kwargs)
    return self._encode_plus(text=text, xpaths=xpaths, text_pair=text_pair, node_labels=node_labels, add_special_tokens=add_special_tokens, padding_strategy=padding_strategy, truncation_strategy=truncation_strategy, max_length=max_length, stride=stride, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)

Tokenize and prepare for the model a sequence or a pair of sequences. .. warning:: This method is deprecated,
`__call__` should be used instead.

Args:
text (`str`, `List[str]`, `List[List[str]]`):
The first sequence to be encoded. This can be a string, a list of strings or a list of list of strings.
text_pair (`List[str]` or `List[int]`, *optional*):
Optional second sequence to be encoded. This can be a list of strings (words of a single example) or a
list of list of strings (words of a batch of examples).


def print(self, format=TEXT, output=sys.stdout, **kwargs):
    if (format is None):
        format = TEXT
    if (format == TEXT):
        print(self._to_text(**kwargs), file=output)
    elif (format == CSV):
        print(self._to_csv(**kwargs), file=output)
    elif (format == JSON):
        print(self._to_json(**kwargs), file=output)

Print the object in a file or on standard output by default.

Args:
format (str): output format (csv, json or text).
output (file):
descriptor to an opened file (default to standard output).
**kwargs (): additional arguments.


class UnitNorm(Constraint):

    def __init__(self, axis=0):
        self.axis = axis

    @doc_controls.do_not_generate_docs
    def __call__(self, w):
        return w / (backend.epsilon() + backend.sqrt(math_ops.reduce_sum(math_ops.square(w), axis=self.axis, keepdims=True)))

    @doc_controls.do_not_generate_docs
    def get_config(self):
        return {'axis': self.axis}

Constrains the weights incident to each hidden unit to have unit norm.

Also available via the shortcut function `tf.keras.constraints.unit_norm`.

Args:
axis: integer, axis along which to calculate weight norms.
For instance, in a `Dense` layer the weight matrix
has shape `(input_dim, output_dim)`,
set `axis` to `0` to constrain each weight vector
of length `(input_dim,)`.
In a `Conv2D` layer with `data_format="channels_last"`,
the weight tensor has shape
`(rows, cols, input_depth, output_depth)`,
set `axis` to `[0, 1, 2]`
to constrain the weights of each filter tensor of size
`(rows, cols, input_depth)`.


def generate_text(self, generation_type='markov'):

        assert generation_type in ['markov', 'hmm', 'hmm_past']
        if generation_type == "markov":
            return self._text_generator(next_token=self._generate_next_token)
        elif generation_type == "hmm":
            return self._text_generator(next_token=self._generate_next_token_hmm, emit=self._emitHMM)
        elif generation_type == "hmm_past":
            return self._text_generator(next_token=self._generate_next_token_hmm, emit=self._emitHMM_with_past)

Generates sentences from a given corpus
Args:
generation_type: 'markov' | 'hmm' | 'hmm_past'
Returns:
Properly formatted string of generated sentences


def simple_pattern_exists_in_gcs(file_pattern, credentials=None):
    if ('*' not in file_pattern):
        return _file_exists_in_gcs(file_pattern, credentials)
    if (not file_pattern.startswith('gs:
        raise ValueError('file name must start with gs:
    gcs_service = _get_storage_service(credentials)
    (bucket_name, prefix) = file_pattern[len('gs:
    if ('*' in bucket_name):
        raise ValueError('Wildcards may not appear in the bucket name')
    assert ('*' in prefix)
    prefix_no_wildcard = prefix[:prefix.index('*')]
    request = gcs_service.objects().list(bucket=bucket_name, prefix=prefix_no_wildcard)
    response = request.execute()
    if ('items' not in response):
        return False
    items_list = [i['name'] for i in response['items']]
    return any((fnmatch.fnmatch(i, prefix) for i in items_list))

True iff an object exists matching the input GCS pattern.

The GCS pattern must be a full object reference or a "simple pattern" that
conforms to the dsub input and output parameter restrictions:

* No support for **, ? wildcards or [] character ranges
* Wildcards may only appear in the file name

Args:
file_pattern: eg. 'gs://foo/ba*'
credentials: Optional credential to be used to load the file from gcs.

Raises:
ValueError: if file_pattern breaks the rules.

Returns:
True iff a file exists that matches that pattern.


def destroy_connection(self, connection):

        log.debug("Destroying connection at <{0}>".format(hex(id(connection))))
        self._decontextualise_connection(connection)
        connection.unbind()

Destroys a connection. Removes the connection from the appcontext, and
unbinds it.

Args:
connection (ldap3.Connection):  The connnection to destroy


def AddProcessingOptions(self, argument_group):
    argument_group.add_argument('--single_process', '--single-process', dest='single_process', action='store_true', default=False, help='Indicate that the tool should run in a single process.')
    argument_helper_names = ['temporary_directory', 'workers', 'zeromq']
    if self._CanEnforceProcessMemoryLimit():
        argument_helper_names.append('process_resources')
    helpers_manager.ArgumentHelperManager.AddCommandLineArguments(argument_group, names=argument_helper_names)

Adds the processing options to the argument group.

Args:
argument_group (argparse._ArgumentGroup): argparse argument group.


def CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error):
    line = clean_lines.elided[linenum]
    match = Match('^(.*[^ ({>]){', line)
    if match:
        leading_text = match.group(1)
        (endline, endlinenum, endpos) = CloseExpression(clean_lines, linenum, len(match.group(1)))
        trailing_text = ''
        if (endpos > (- 1)):
            trailing_text = endline[endpos:]
        for offset in xrange((endlinenum + 1), min((endlinenum + 3), (clean_lines.NumLines() - 1))):
            trailing_text += clean_lines.elided[offset]
        if ((not Match('^[\\s}]*[{.;,)<>\\]:]', trailing_text)) and (not _IsType(clean_lines, nesting_state, leading_text))):
            error(filename, linenum, 'whitespace/braces', 5, 'Missing space before {')
    if Search('}else', line):
        error(filename, linenum, 'whitespace/braces', 5, 'Missing space before else')
    if Search(':\\s*;\\s*$', line):
        error(filename, linenum, 'whitespace/semicolon', 5, 'Semicolon defining empty statement. Use {} instead.')
    elif Search('^\\s*;\\s*$', line):
        error(filename, linenum, 'whitespace/semicolon', 5, 'Line contains only semicolon. If this should be an empty statement, use {} instead.')
    elif (Search('\\s+;\\s*$', line) and (not Search('\\bfor\\b', line))):
        error(filename, linenum, 'whitespace/semicolon', 5, 'Extra space before last semicolon. If this should be an empty statement, use {} instead.')

Checks for horizontal spacing near commas.

Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
nesting_state: A NestingState instance which maintains information about
the current stack of nested blocks being parsed.
error: The function to call with any errors found.


Called at the end of evaluation or validation.

Subclasses should override for any actions to run.

Args:
logs: Dict. Currently the output of the last call to
`on_test_batch_end()` is passed to this argument for this method
but that may change in the future.