def __init__(self, auto_recurse=True):

    super(SourceAnalyzer, self).__init__()
    self._auto_recurse = auto_recurse
    self._encode_errors = 'strict'
    self._preferred_encoding = locale.getpreferredencoding()
    self._source_scanner = source_scanner.SourceScanner()

Initializes a source analyzer.

Args:
auto_recurse (Optional[bool]): True if the scan should automatically
recurse as far as possible.


def wtime_to_minutes(time_string):

    hours, mins, seconds = time_string.split(':')
    total_mins = int(hours) * 60 + int(mins)
    if total_mins < 1:
        logger.warning("Time string '{}' parsed to {} minutes, less than 1".format(time_string, total_mins))
    return total_mins

wtime_to_minutes

Convert standard wallclock time string to minutes.

Args:
- Time_string in HH:MM:SS format

Returns:
(int) minutes


def delete_duplicates(seq):
    seen = set()
    seen_add = seen.add
    return [x for x in seq if (not ((x in seen) or seen_add(x)))]

Remove duplicates from an iterable, preserving the order.

Args:
seq: Iterable of various type.

Returns:
list: List of unique objects.


def _kl_bernoulli_bernoulli(a, b, name=None):
    with ops.name_scope(name, 'kl_bernoulli_bernoulli', values=[a.logits, b.logits]):
        delta_probs0 = nn.softplus(-b.logits) - nn.softplus(-a.logits)
        delta_probs1 = nn.softplus(b.logits) - nn.softplus(a.logits)
        return math_ops.sigmoid(a.logits) * delta_probs0 + math_ops.sigmoid(-a.logits) * delta_probs1

Calculate the batched KL divergence KL(a || b) with a and b Bernoulli.

Args:
a: instance of a Bernoulli distribution object.
b: instance of a Bernoulli distribution object.
name: (optional) Name to use for created operations.
default is "kl_bernoulli_bernoulli".

Returns:
Batchwise KL(a || b)


def __init__(self, parent=None):

        super(DelimiterValidator, self).__init__(parent)
        re = QtCore.QRegExp('\S{1}')
        self.setRegExp(re)

Constructs the object with the given parent.

Args:
parent (QObject, optional): Causes the objected to be owned
by `parent` instead of Qt. Defaults to `None`.


def from_bytes_list(cls, function_descriptor_list):

        assert isinstance(function_descriptor_list, list)
        if len(function_descriptor_list) == 0:

            return FunctionDescriptor.for_driver_task()
        elif (len(function_descriptor_list) == 3
              or len(function_descriptor_list) == 4):
            module_name = ensure_str(function_descriptor_list[0])
            class_name = ensure_str(function_descriptor_list[1])
            function_name = ensure_str(function_descriptor_list[2])
            if len(function_descriptor_list) == 4:
                return cls(module_name, function_name, class_name,
                           function_descriptor_list[3])
            else:
                return cls(module_name, function_name, class_name)
        else:
            raise Exception(
                "Invalid input for FunctionDescriptor.from_bytes_list")

Create a FunctionDescriptor instance from list of bytes.

This function is used to create the function descriptor from
backend data.

Args:
cls: Current class which is required argument for classmethod.
function_descriptor_list: list of bytes to represent the
function descriptor.

Returns:
The FunctionDescriptor instance created from the bytes list.


def create_attribute_model(self, initial_value=None):
    attr = self.attribute_class(meta=self, value=initial_value)
    return attr

Make an AttributeModel instance of the correct type for this Meta

Args:
initial_value: The initial value the Attribute should take

Returns:
AttributeModel: The created attribute model instance


def PublishMultipleEvents(cls, events, token=None):
    event_name_map = registry.EventRegistry.EVENT_NAME_MAP
    for (event_name, messages) in iteritems(events):
        if (not isinstance(event_name, string_types)):
            raise ValueError(('Event names should be string, got: %s' % type(event_name)))
        for msg in messages:
            if (not isinstance(msg, rdfvalue.RDFValue)):
                raise ValueError('Can only publish RDFValue instances.')
        for event_cls in event_name_map.get(event_name, []):
            event_cls().ProcessMessages(messages, token=token)

Publishes multiple messages at once.

Args:
events: A dict with keys being event names and values being lists of
messages.
token: ACL token.

Raises:
ValueError: If the message is invalid. The message must be a Semantic
Value (instance of RDFValue) or a full GrrMessage.


def score_cosine(self, term1, term2, **kwargs):
    t1_kde = self.kde(term1, **kwargs)
    t2_kde = self.kde(term2, **kwargs)
    return (1 - distance.cosine(t1_kde, t2_kde))

Compute a weighting score based on the cosine distance between the
kernel density estimates of two terms.

Args:
term1 (str)
term2 (str)

Returns: float


def get(self, key, default=None):
    retval = self.__getitem__(key)
    if (not retval):
        retval = default
    return retval

Get a value from the dictionary.

Args:
key (str): The dictionary key.
default (any): The default to return if the key is not in the
dictionary. Defaults to None.

Returns:
str or any: The dictionary value or the default if the key is not
in the dictionary.


def find_modules():
    tf_modules = []
    for name, module in sys.modules.items():
        for package in PACKAGES:
            if name.startswith(package):
                tf_modules.append(module)
    return tf_modules

Finds all the modules in the core package imported.

Returns:
A list containing all the modules in tensorflow.python.


def __new__(cls, name, value_type, default=NO_DEFAULT):
    try:
        validate_field_value_type(value_type, allow_forward_references=True)
    except TypeError as e:
        raise TypeError(f'In field {name!r}: {e}') from e
    if default is not cls.NO_DEFAULT:
        default = _convert_value(default, value_type, (f'default value for {name}',), _ConversionContext.DEFAULT)
    return super(ExtensionTypeField, cls).__new__(cls, name, value_type, default)

Constructs a new ExtensionTypeField containing metadata for a single field.

Args:
name: The name of the new field (`str`).  May not be a reserved name.
value_type: A python type expression constraining what values this field
can take.
default: The default value for the new field, or `NO_DEFAULT` if this
field has no default value.

Returns:
A new `ExtensionTypeField`.

Raises:
TypeError: If the type described by `value_type` is not currently
supported by `tf.ExtensionType`.
TypeError: If `default` is specified and its type does not match
`value_type`.


def _clean_options(method, provided_options):

    provided_options = provided_options or {}
    default_options = get_minimizer_options(method)

    result = {}

    for name, default in default_options.items():
        if name in provided_options:
            result[name] = provided_options[name]
        else:
            result[name] = default_options[name]
    return result

Clean the given input options.

This will make sure that all options are present, either with their default values or with the given values,
and that no other options are present then those supported.

Args:
method (str): the method name
provided_options (dict): the given options

Returns:
dict: the resulting options dictionary


def _get_acorn(self, method, *items):

    if method == "slice":
        r = np.ndarray.__acornext__.__getslice__(self, *items)
    else:
        r = np.ndarray.__acornext__.__getitem__(self, *items)

    if not (decorating or streamlining):
        from acorn.logging.decoration import (pre, post, _fqdn)
        if method == "slice":
            fqdn = "numpy.ndarray.__getslice__"
        else:
            fqdn = "numpy.ndarray.__getitem__"
        preres = pre(fqdn, np.ndarray, 5, self, *items)
        entry, bound, ekey = preres

        post(fqdn, "numpy", r, entry, np.ndarray, ekey)
    return r

Gets either a slice or an item from an array. Used for the __getitem__
and __getslice__ special methods of the sub-classed array.

Args:
method (str): on of ['slice', 'item'].


def _get_physical_indices(self, state: RequestState, logical_indices: List[int]) -> List[int]:
    request_id = state.request_id
    block_table = self._block_tables.get(request_id)
    if not block_table:
        raise ValueError(f'No block table found for request {request_id}')
    block_size = self.block_size
    physical_indices = []
    for idx in logical_indices:
        block_idx = idx
        block_offset = idx % block_size
        if block_idx >= len(block_table):
            raise IndexError(f'Logical index {idx} maps to block index {block_idx} which is out of bounds for request {request_id}')
        physical_block_num = block_table[block_idx]
        physical_index = physical_block_num * block_size + block_offset
        physical_indices.append(physical_index)
    return physical_indices

Maps logical sequence indices to physical cache indices using the block table, using PyTorch.

Args:
request_id: The request ID.
logical_indices: A list of logical indices.

Returns:
A list of physical indices.

Raises:
ValueError: If no block table is found for the request ID.
IndexError: If a logical index maps to a block index that is out of bounds.


def all_segs_matching_fts(self, fts):

        matching_segs = []
        for seg, pairs in self.segments:
            if set(fts) <= set(pairs):
                matching_segs.append(seg)
        return sorted(matching_segs, key=lambda x: len(x), reverse=True)

Return segments matching a feature mask, both as (value, feature)
tuples (sorted in reverse order by length).

Args:
fts (list): feature mask as (value, feature) tuples.

Returns:
list: segments matching `fts`, sorted in reverse order by length


def console_map_string_to_font(s: str, fontCharX: int, fontCharY: int) -> None:
    lib.TCOD_console_map_string_to_font_utf(_unicode(s), fontCharX, fontCharY)

Remap a string of codes to a contiguous set of tiles.

Args:
s (AnyStr): A string of character codes to map to new values.
The null character `'\\x00'` will prematurely end this
function.
fontCharX (int): The starting X tile coordinate on the loaded tileset.
0 is the leftmost tile.
fontCharY (int): The starting Y tile coordinate on the loaded tileset.
0 is the topmost tile.


def _check_bits(self, args, amap):

        for wire in args:
            if wire not in amap:
                raise DAGCircuitError("(qu)bit %s[%d] not found" %
                                      (wire[0].name, wire[1]))

Check the values of a list of (qu)bit arguments.

For each element of args, check that amap contains it.

Args:
args (list): (register,idx) tuples
amap (dict): a dictionary keyed on (register,idx) tuples

Raises:
DAGCircuitError: if a qubit is not contained in amap


def delete(self, dash_id):

        removed_info = dict(
            time_modified = r_db.zscore(config.DASH_ID_KEY, dash_id),
            meta = r_db.hget(config.DASH_META_KEY, dash_id),
            content = r_db.hget(config.DASH_CONTENT_KEY, dash_id))
        r_db.zrem(config.DASH_ID_KEY, dash_id)
        r_db.hdel(config.DASH_META_KEY, dash_id)
        r_db.hdel(config.DASH_CONTENT_KEY, dash_id)
        return {'removed_info': removed_info}

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

Actually, just remove it to a specfied place in database.

Args:
dash_id: dashboard id.

Returns:
Redirect to home page.


def deserialize_block(value):

        block = Block()
        block.ParseFromString(value)
        return BlockWrapper(
            block=block)

Deserialize a byte string into a BlockWrapper

Args:
value (bytes): the byte string to deserialze

Returns:
BlockWrapper: a block wrapper instance


def prepare_policy_template(self, scaling_type, period_sec, server_group):
    template_kwargs = {'app': self.app, 'env': self.env, 'region': self.region, 'server_group': server_group, 'period_sec': period_sec, 'scaling_policy': self.settings['asg']['scaling_policy']}
    if (scaling_type == 'scale_up'):
        template_kwargs['operation'] = 'increase'
        template_kwargs['comparisonOperator'] = 'GreaterThanThreshold'
        template_kwargs['scalingAdjustment'] = 1
    elif (scaling_type == 'scale_down'):
        cur_threshold = int(self.settings['asg']['scaling_policy']['threshold'])
        self.settings['asg']['scaling_policy']['threshold'] = floor((cur_threshold * 0.5))
        template_kwargs['operation'] = 'decrease'
        template_kwargs['comparisonOperator'] = 'LessThanThreshold'
        template_kwargs['scalingAdjustment'] = (- 1)
    rendered_template = get_template(template_file='infrastructure/autoscaling_policy.json.j2', **template_kwargs)
    self.log.info('Creating a %s policy in %s for %s', scaling_type, self.env, self.app)
    wait_for_task(rendered_template)
    self.log.info('Successfully created a %s policy in %s for %s', scaling_type, self.env, self.app)

Renders scaling policy templates based on configs and variables.
After rendering, POSTs the json to Spinnaker for creation.

Args:
scaling_type (str): ``scale_up`` or ``scaling_down``. Type of policy
period_sec (int): Period of time to look at metrics for determining scale
server_group (str): The name of the server group to render template for


def repr(tick, pack=False):

    if tick == 0x7fffffffffffffff:
        return '?'

    dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(milliseconds=tick)
    millis = dt.microsecond / 1000
    if pack:
        return '%d%.2d%.2d%.2d%.2d%.2d%.3d' % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, millis)
    return '%d/%.2d/%.2d %.2d:%.2d:%.2d.%.3d' % (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, millis)

Return a date string for an epoch-millis timestamp.

Args:
tick (int): The timestamp in milliseconds since the epoch.

Returns:
(str):  A date time string


def lookup_imagenet_labels(indices):
    global _CLASS_INDEX
    if (_CLASS_INDEX is None):
        with open(os.path.join(os.path.dirname(__file__), '../../resources/imagenet_class_index.json')) as f:
            _CLASS_INDEX = json.load(f)
    indices = listify(indices)
    return [_CLASS_INDEX[str(idx)][1] for idx in indices]

Utility function to return the image net label for the final `dense` layer output index.

Args:
indices: Could be a single value or an array of indices whose labels should be looked up.

Returns:
Image net label corresponding to the image category.


def map_tensor_fn(self, fn: Callable[[torch.Tensor], torch.Tensor]) -> Rotation:
    if self._rot_mats is not None:
        rot_mats = self._rot_mats.view(self._rot_mats.shape[:-2] + (9,))
        rot_mats = torch.stack(list(map(fn, torch.unbind(rot_mats, dim=-1))), dim=-1)
        rot_mats = rot_mats.view(rot_mats.shape[:-1] + (3, 3))
        return Rotation(rot_mats=rot_mats, quats=None)
    elif self._quats is not None:
        quats = torch.stack(list(map(fn, torch.unbind(self._quats, dim=-1))), dim=-1)
        return Rotation(rot_mats=None, quats=quats, normalize_quats=False)
    else:
        raise ValueError('Both rotations are None')

Apply a Tensor -> Tensor function to underlying rotation tensors, mapping over the rotation dimension(s). Can
be used e.g. to sum out a one-hot batch dimension.

Args:
fn:
A Tensor -> Tensor function to be mapped over the Rotation
Returns:
The transformed Rotation object


def __init__(self, string=None):

    super(SemanticTime, self).__init__()
    self._string = string

Initializes a semantic time.

Args:
string (str): semantic representation of the time, such as:
"Never", "Not set".


def _get_contrib_features(module):

    if isinstance(module, types.ModuleType):

        if hasattr(module, '__path__'):
            yield from _get_contrib_features_from_package(module)
        else:
            yield _get_contrib_feature_from_module(module)
    else:
        raise ValueError('Input is not a module')

Get contributed features from within given module

Be very careful with untrusted code. The module/package will be
walked, every submodule will be imported, and all the code therein will be
executed. But why would you be trying to import from an untrusted package
anyway?

Args:
contrib (module): module (standalone or package) that contains feature
definitions

Returns:
List[Feature]: list of features


def WritePreprocessingInformation(self, knowledge_base):

    self._RaiseIfNotWritable()

    if self.storage_type != definitions.STORAGE_TYPE_SESSION:
      raise IOError('Preprocess information not supported by storage type.')

    system_configuration = knowledge_base.GetSystemConfigurationArtifact()

    self._WriteAttributeContainer(system_configuration)

Writes preprocessing information.

Args:
knowledge_base (KnowledgeBase): contains the preprocessing information.

Raises:
IOError: if the storage type does not support writing preprocess
information or the storage file is closed or read-only.
OSError: if the storage type does not support writing preprocess
information or the storage file is closed or read-only.


def _to_row_partitions_and_nvals_from_lengths(lengths: Sequence[Union[int, Sequence[int]]], dtype=None) -> Tuple[Sequence[RowPartition], int]:
    size_so_far = lengths[0]
    result = []
    for current_lengths in lengths[1:]:
        if isinstance(current_lengths, int):
            nrows = size_so_far
            nvals = current_lengths * nrows
            size_so_far = nvals
            result.append(RowPartition.from_uniform_row_length(current_lengths, nvals, nrows=nrows, dtype_hint=dtype))
        else:
            if size_so_far != len(current_lengths):
                raise ValueError('Shape not consistent.')
            result.append(RowPartition.from_row_lengths(current_lengths, dtype_hint=dtype))
            size_so_far = sum(current_lengths)
    return (result, size_so_far)

Allow ragged and uniform shapes to be specified.

For example, [2, [2,1], 2] represents a shape like:
[[[0, 0], [0, 0]], [[0, 0]]]

Args:
lengths: a list of integers and lists of integers.
dtype: dtype of the shape (tf.int32 or tf.int64)

Returns:
a sequence of RowPartitions, and the number of values of the last partition.


def CreateSessionStart(self):
    session_start = SessionStart()
    session_start.artifact_filters = self.artifact_filters
    session_start.command_line_arguments = self.command_line_arguments
    session_start.debug_mode = self.debug_mode
    session_start.enabled_parser_names = self.enabled_parser_names
    session_start.filter_file = self.filter_file
    session_start.identifier = self.identifier
    session_start.parser_filter_expression = self.parser_filter_expression
    session_start.preferred_encoding = self.preferred_encoding
    session_start.preferred_time_zone = self.preferred_time_zone
    session_start.product_name = self.product_name
    session_start.product_version = self.product_version
    session_start.timestamp = self.start_time
    return session_start

Creates a session start.

Returns:
SessionStart: session start attribute container.


def plot_grid(step):

    rad = get_rprof(step, 'r')[0]
    drad = get_rprof(step, 'dr')[0]
    _, unit = step.sdat.scale(1, 'm')
    if unit:
        unit = ' ({})'.format(unit)
    fig, (ax1, ax2) = plt.subplots(2, sharex=True)
    ax1.plot(rad, '-ko')
    ax1.set_ylabel('$r$' + unit)
    ax2.plot(drad, '-ko')
    ax2.set_ylabel('$dr$' + unit)
    ax2.set_xlim([-0.5, len(rad) - 0.5])
    ax2.set_xlabel('Cell number')
    misc.saveplot(fig, 'grid', step.istep)

Plot cell position and thickness.

The figure is call grid_N.pdf where N is replace by the step index.

Args:
step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData
instance.


def all_devices(cl_device_type=None, platform=None):
    if isinstance(cl_device_type, str):
        cl_device_type = device_type_from_string(cl_device_type)
    runtime_list = []
    if (platform is None):
        platforms = cl.get_platforms()
    else:
        platforms = [platform]
    for platform in platforms:
        if cl_device_type:
            devices = platform.get_devices(device_type=cl_device_type)
        else:
            devices = platform.get_devices()
        for device in devices:
            if device_supports_double(device):
                env = CLEnvironment(platform, device)
                runtime_list.append(env)
    return runtime_list

Get multiple device environments, optionally only of the indicated type.

This will only fetch devices that support double point precision.

Args:
cl_device_type (cl.device_type.* or string): The type of the device we want,
can be a opencl device type or a string matching 'GPU' or 'CPU'.
platform (opencl platform): The opencl platform to select the devices from

Returns:
list of CLEnvironment: List with the CL device environments.


def forward(self, s: torch.Tensor, s_initial: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
    s_initial = self.relu(s_initial)
    s_initial = self.linear_initial(s_initial)
    s = self.relu(s)
    s = self.linear_in(s)
    s = s + s_initial
    for l in self.layers:
        s = l(s)
    s = self.relu(s)
    s = self.linear_out(s)
    s = s.view(s.shape[:-1] + (-1, 2))
    unnormalized_s = s
    norm_denom = torch.sqrt(torch.clamp(torch.sum(s ** 2, dim=-1, keepdim=True), min=self.config.epsilon))
    s = s / norm_denom
    return (unnormalized_s, s)

Args:
s:
[*, C_hidden] single embedding
s_initial:
[*, C_hidden] single embedding as of the start of the StructureModule
Returns:
[*, no_angles, 2] predicted angles


def _take_screenshot(self, screenshot=False, name_prefix='unknown'):
    if isinstance(screenshot, bool):
        if (not screenshot):
            return
        return self._save_screenshot(name_prefix=name_prefix)
    if isinstance(screenshot, Image.Image):
        return self._save_screenshot(screen=screenshot, name_prefix=name_prefix)
    raise TypeError(('invalid type for func _take_screenshot: ' + type(screenshot)))

This is different from _save_screenshot.
The return value maybe None or the screenshot path

Args:
screenshot: bool or PIL image


class ZoeDepthNeck(nn.Module):

    def __init__(self, config):
        super().__init__()
        self.config = config
        if config.backbone_config is not None and config.backbone_config.model_type in ['swinv2']:
            self.reassemble_stage = None
        else:
            self.reassemble_stage = ZoeDepthReassembleStage(config)
        self.convs = nn.ModuleList()
        for channel in config.neck_hidden_sizes:
            self.convs.append(nn.Conv2d(channel, config.fusion_hidden_size, kernel_size=3, padding=1, bias=False))
        self.fusion_stage = ZoeDepthFeatureFusionStage(config)

    def forward(self, hidden_states: List[torch.Tensor], patch_height, patch_width) -> List[torch.Tensor]:

        if not isinstance(hidden_states, (tuple, list)):
            raise TypeError('hidden_states should be a tuple or list of tensors')
        if len(hidden_states) != len(self.config.neck_hidden_sizes):
            raise ValueError('The number of hidden states should be equal to the number of neck hidden sizes.')
        if self.reassemble_stage is not None:
            hidden_states = self.reassemble_stage(hidden_states, patch_height, patch_width)
        features = [self.convs[i](feature) for i, feature in enumerate(hidden_states)]
        output = self.fusion_stage(features)
        return (output, features[-1])

ZoeDepthNeck. A neck is a module that is normally used between the backbone and the head. It takes a list of tensors as
input and produces another list of tensors as output. For ZoeDepth, it includes 2 stages:

* ZoeDepthReassembleStage
* ZoeDepthFeatureFusionStage.

Args:
config (dict): config dict.


def dispatch(self, request, start_response):
    dispatched_response = self.dispatch_non_api_requests(request, start_response)
    if (dispatched_response is not None):
        return dispatched_response
    try:
        return self.call_backend(request, start_response)
    except errors.RequestError as error:
        return self._handle_request_error(request, error, start_response)

Handles dispatch to apiserver handlers.

This typically ends up calling start_response and returning the entire
body of the response.

Args:
request: An ApiRequest, the request from the user.
start_response: A function with semantics defined in PEP-333.

Returns:
A string, the body of the response.


def UploadSignedBinary(source_path, binary_type, platform, upload_subdirectory=''):
    file_size = os.path.getsize(source_path)
    if (file_size > _MAX_SIGNED_BINARY_BYTES):
        raise BinaryTooLargeError(('File [%s] is of size %d (bytes), which exceeds the allowed maximum of %d bytes.' % (source_path, file_size, _MAX_SIGNED_BINARY_BYTES)))
    context = [('Platform:%s' % platform.title()), 'Client Context']
    signing_key = grr_config.CONFIG.Get('PrivateKeys.executable_signing_private_key', context=context)
    root_api = maintenance_utils.InitGRRRootAPI()
    binary_path = '/'.join([platform.lower(), upload_subdirectory, os.path.basename(source_path)])
    binary = root_api.GrrBinary(binary_type, binary_path)
    with open(source_path, 'rb') as fd:
        binary.Upload(fd, sign_fn=binary.DefaultUploadSigner(private_key=signing_key.GetRawPrivateKey()))
    print(('Uploaded %s to %s' % (binary_type, binary_path)))

Signs a binary and uploads it to the datastore.

Args:
source_path: Path to the binary to upload.
binary_type: Type of the binary, e.g python-hack or executable.
platform: Client platform where the binary is intended to be run.
upload_subdirectory: Path of a subdirectory to upload the binary to,
relative to the canonical path for binaries of the given type and
platform.

Raises:
BinaryTooLargeError: If the binary to upload is too large.


def ceil(cls, x: 'TensorFluent') -> 'TensorFluent':

        return cls._unary_op(x, tf.ceil, tf.float32)

Returns a TensorFluent for the ceil function.

Args:
x: The input fluent.

Returns:
A TensorFluent wrapping the ceil function.


def port_create_vxlan(br, port, id, remote, dst_port=None):
    dst_port = ((' options:dst_port=' + six.text_type(dst_port)) if (0 < dst_port <= 65535) else '')
    if (not (0 <= id < (2 ** 64))):
        return False
    elif (not __salt__['dig.check_ip'](remote)):
        return False
    elif (not bridge_exists(br)):
        return False
    elif (port in port_list(br)):
        cmd = 'ovs-vsctl set interface {0} type=vxlan options:remote_ip={1} options:key={2}{3}'.format(port, remote, id, dst_port)
        result = __salt__['cmd.run_all'](cmd)
        return _retcode_to_bool(result['retcode'])
    else:
        cmd = 'ovs-vsctl add-port {0} {1} -- set interface {1} type=vxlan options:remote_ip={2} options:key={3}{4}'.format(br, port, remote, id, dst_port)
        result = __salt__['cmd.run_all'](cmd)
        return _retcode_to_bool(result['retcode'])

Virtual eXtensible Local Area Network - creates VXLAN tunnel between endpoints.

Args:
br: A string - bridge name.
port: A string - port name.
id: An integer - unsigned 64-bit number, tunnel's key.
remote: A string - remote endpoint's IP address.
dst_port: An integer - port to use when creating tunnelport in the switch.

Returns:
True on success, else False.

.. versionadded:: 2016.3.0

CLI Example:
.. code-block:: bash

salt '*' openvswitch.port_create_vxlan br0 vx1 5001 192.168.1.10 8472


def delete(self, wait_for_deletion=True):

    if self.exists():
      try:
        self._api.objects_delete(self._bucket, self._key)
      except Exception as e:
        raise e
      if wait_for_deletion:
        for _ in range(_MAX_POLL_ATTEMPTS):
          objects = Objects(self._bucket, prefix=self.key, delimiter='/',
                            context=self._context)
          if any(o.key == self.key for o in objects):
            time.sleep(_POLLING_SLEEP)
            continue
          break
        else:
          logging.error('Failed to see object deletion after %d attempts.',
                        _MAX_POLL_ATTEMPTS)

Deletes this object from its bucket.

Args:
wait_for_deletion: If True, we poll until this object no longer appears in
objects.list operations for this bucket before returning.

Raises:
Exception if there was an error deleting the object.


def ch_duration(self, *channels: List[Channel]) -> int:
    return self.timeslots.ch_duration(*channels)

Return duration of supplied channels.

Args:
*channels: Supplied channels


def remove_species(self, species):

        new_sites = []
        species = [get_el_sp(s) for s in species]

        for site in self._sites:
            new_sp_occu = {sp: amt for sp, amt in site.species.items()
                           if sp not in species}
            if len(new_sp_occu) > 0:
                new_sites.append(PeriodicSite(
                    new_sp_occu, site.frac_coords, self._lattice,
                    properties=site.properties))
        self._sites = new_sites

Remove all occurrences of several species from a structure.

Args:
species: Sequence of species to remove, e.g., ["Li", "Na"].


def fetch(self, refund_id, data={}, **kwargs):
    return super(Refund, self).fetch(refund_id, data, **kwargs)

Refund object for given paymnet Id

Args:
refund_id : Refund Id for which refund has to be retrieved

Returns:
Refund dict for given refund Id


def _extract_options(config, options, *args):

    extract = {}
    for key in args:
        if key not in args:
            continue
        extract[key] = config[key]
        option = getattr(options, key, None)
        if option is not None:
            extract[key] = option
    return extract

Extract options values from a configparser, optparse pair.

Options given on command line take precedence over options read in the
configuration file.

Args:
config (dict): option values read from a config file through
configparser
options (optparse.Options): optparse 'options' object containing options
values from the command line
*args (str tuple): name of the options to extract


def _BuildEventData(self, record):

    event_data = FseventsdEventData()
    event_data.path = record.path
    event_data.flags = record.event_flags
    event_data.event_identifier = record.event_identifier

    event_data.node_identifier = getattr(record, 'node_identifier', None)

    return event_data

Builds an FseventsdData object from a parsed structure.

Args:
record (dls_record_v1|dls_record_v2): parsed record structure.

Returns:
FseventsdEventData: event data attribute container.


def _compile_batch_fluents(self, fluents: List[Tuple[(str, TensorFluent)]], batch_size: int) -> Sequence[tf.Tensor]:
    batch_fluents = []
    with self.graph.as_default():
        for (name, fluent) in fluents:
            name_scope = utils.identifier(name)
            with tf.name_scope(name_scope):
                t = tf.stack(([fluent.tensor] * batch_size))
            batch_fluents.append(t)
    return tuple(batch_fluents)

Compiles `fluents` into tensors with given `batch_size`.

Returns:
Sequence[tf.Tensor]: A tuple of tensors with first dimension
corresponding to the batch size.


def CreateGRRTempFileVFS(filename=None, lifetime=0, mode='w+b', suffix=''):
    fd = CreateGRRTempFile(filename=filename, lifetime=lifetime, mode=mode, suffix=suffix)
    pathspec = rdf_paths.PathSpec(path=fd.name, pathtype=rdf_paths.PathSpec.PathType.TMPFILE)
    return (fd, pathspec)

Creates a GRR VFS temp file.

This function is analogous to CreateGRRTempFile but returns an open VFS handle
to the newly created file. Arguments are the same as for CreateGRRTempFile:

Args:
filename: The name of the file to use. Note that setting both filename and
directory name is not allowed.

lifetime: time in seconds before we should delete this tempfile.

mode: The mode to open the file.

suffix: optional suffix to use for the temp file

Returns:
An open file handle to the new file and the corresponding pathspec.


def run_benchmark(self, shape=(100, 100), ragged_rank=None, dtype=dtypes.float32, fill=None, default_shape=(), output_shape=None, min_iters=1000):
    if ragged_rank is None:
        ragged_rank = len(shape) - 1
    if fill is None:
        fill = [0.8 for _ in shape]
    rt_input = self._generateRaggedTensor(shape, ragged_rank, dtype, fill)
    default_value = constant_op.constant(self._generateRaggedTensor(default_shape, 0, dtype), dtype=dtype)
    mbs = np.prod(shape) / 2 ** 20
    with session.Session(config=benchmark.benchmark_config()) as sess:
        extras = {'shape': shape, 'ragged_rank': ragged_rank, 'dtype': dtype, 'fill': fill, 'default_shape': default_shape}
        rt = ragged_factory_ops.constant(rt_input, dtype, ragged_rank=ragged_rank)
        splits_rt_placeholder = ragged_factory_ops.placeholder(dtype, ragged_rank, shape[ragged_rank + 1:])
        splits_feed_dict = {splits_rt_placeholder: sess.run(rt)}
        rowids_feed_dict = {}
        rowids_rt_placeholder = rebuild_ragged_tensor_with_value_rowids(rt, rowids_feed_dict, sess)
        run_op_benchmark_kwargs = dict(sess=sess, store_memory_usage=True, min_iters=min_iters, burn_iters=max(5, min_iters
        ragged_to_tensor_with_splits = splits_rt_placeholder.to_tensor(default_value=default_value)
        self.run_op_benchmark(op_or_tensor=ragged_to_tensor_with_splits.op, name='ragged_to_tensor_with_splits', feed_dict=splits_feed_dict, **run_op_benchmark_kwargs)
        ragged_to_tensor_with_rowids = rowids_rt_placeholder.to_tensor(default_value=default_value)
        self.run_op_benchmark(op_or_tensor=ragged_to_tensor_with_rowids.op, name='ragged_to_tensor_with_rowids', feed_dict=rowids_feed_dict, **run_op_benchmark_kwargs)

Run a benchmark with the specified configuration parameters.

Args:
shape: Bounding box for the input ragged tensor.
ragged_rank: Ragged rank for the input ragged tensor.  Defaults to
`len(shape)-1`.
dtype: Data type for the input ragged tensor.
fill: How full each dimension should be (0-1).  Corresponds 1:1 with
`shape`.  Defaults to 0.8 for each dimension.
default_shape: Shape for the default (padding) value.
output_shape: Output shape -- ragged tensor will be padded or cropped to
this shape.
min_iters: Minimum iterations for benchmark.


def _agg_with_no_function(gb, *args, **kwargs):
    if not kwargs:
        raise ValueError('No aggregation functions specified')
    result_columns, result_frames = ([], [])
    for col_name, (input_col, agg_fn) in kwargs.items():
        frame = _handle_agg_function(gb[input_col], agg_fn, f'agg_{col_name}', *args)
        result_frames.append(frame)
        result_columns.append(col_name)
    return DeferredDataFrame(expressions.ComputedExpression('agg', lambda *results: pd.concat(results, axis=1, keys=result_columns), [frame._expr for frame in result_frames], requires_partition_by=partitionings.Index(), preserves_partition_by=partitionings.Singleton()))

Applies aggregation functions to the grouped data based on the provided
keyword arguments and combines the results into a single DataFrame.

Args:
gb: The groupby instance (DeferredGroupBy).
*args: Additional positional arguments passed to the aggregation funcs.
**kwargs: A dictionary where each key is the column name to aggregate,
the value is a tuple containing the input column name and
the aggregation function to apply.

Returns:
DeferredDataFrame: A DataFrame that contains the aggregated results of
all specified columns.

Raises:
ValueError: If no aggregation functions are provided in the `kwargs`.
NotImplementedError: If the aggregation function type is unsupported.


def expand_test_config(op_list, test_configs):
    test_configurations = []
    for op_info in op_list:
        test_index = 0
        for added_test_config in test_configs:
            test_config = op_info.copy()
            test_config.update(added_test_config)
            test_config['testcase_name'] = op_info['testcase_name'] + '_' + str(test_index)
            test_index += 1
            test_configurations.append(test_config)
    return test_configurations

Returns a list of test case args that covers ops and test_configs.

The list is a Cartesian product between op_list and test_configs.

Args:
op_list: A list of dicts, with items keyed by 'testcase_name' and 'op'.
Available lists are defined later in this module.
test_configs: A list of dicts, additional kwargs to be appended for each
test parameters.

Returns:
test_configurations: a list of test parameters that covers all
provided ops in op_list and args in test_configs.


def insert_model_in_doc_toc(old_model_patterns, new_model_patterns):
    toc_file = REPO_PATH / 'docs' / 'source' / 'en' / '_toctree.yml'
    with open(toc_file, 'r', encoding='utf8') as f:
        content = yaml.safe_load(f)
    api_idx = 0
    while content[api_idx]['title'] != 'API':
        api_idx += 1
    api_doc = content[api_idx]['sections']
    model_idx = 0
    while api_doc[model_idx]['title'] != 'Models':
        model_idx += 1
    model_doc = api_doc[model_idx]['sections']
    old_model_type = old_model_patterns.model_type
    section_idx = 0
    while section_idx < len(model_doc):
        sections = [entry['local'] for entry in model_doc[section_idx]['sections']]
        if f'model_doc/{old_model_type}' in sections:
            break
        section_idx += 1
    if section_idx == len(model_doc):
        old_model = old_model_patterns.model_name
        new_model = new_model_patterns.model_name
        print(f'Did not find {old_model} in the table of content, so you will need to add {new_model} manually.')
        return
    toc_entry = {'local': f'model_doc/{new_model_patterns.model_type}', 'title': new_model_patterns.model_name}
    model_doc[section_idx]['sections'].append(toc_entry)
    model_doc[section_idx]['sections'] = sorted(model_doc[section_idx]['sections'], key=lambda s: s['title'].lower())
    api_doc[model_idx]['sections'] = model_doc
    content[api_idx]['sections'] = api_doc
    with open(toc_file, 'w', encoding='utf-8') as f:
        f.write(yaml.dump(content, allow_unicode=True))

Insert the new model in the doc TOC, in the same section as the old model.

Args:
old_model_patterns (`ModelPatterns`): The patterns for the old model.
new_model_patterns (`ModelPatterns`): The patterns for the new model.


def register_obj_processors(self, obj_processors):

        self.obj_processors = obj_processors
        self.type_convertors.update(obj_processors)

Object processors are callables that will be called after
each successful model object construction.
Those callables receive model object as its parameter.
Registration of new object processors will replace previous.

Args:
obj_processors(dict): A dictionary where key=class name,
value=callable


def coarse_graining(network, state, internal_indices):
    max_phi = float('-inf')
    max_coarse_grain = CoarseGrain((), ())
    for coarse_grain in all_coarse_grains(internal_indices):
        try:
            subsystem = MacroSubsystem(network, state, internal_indices, coarse_grain=coarse_grain)
        except ConditionallyDependentError:
            continue
        phi = compute.phi(subsystem)
        if ((phi - max_phi) > constants.EPSILON):
            max_phi = phi
            max_coarse_grain = coarse_grain
    return (max_phi, max_coarse_grain)

Find the maximal coarse-graining of a micro-system.

Args:
network (Network): The network in question.
state (tuple[int]): The state of the network.
internal_indices (tuple[int]): Nodes in the micro-system.

Returns:
tuple[int, CoarseGrain]: The phi-value of the maximal |CoarseGrain|.


def __init__(self, keys, values, key_dtype=None, value_dtype=None, name=None):
    if not context.executing_eagerly() and ops.get_default_graph()._get_control_flow_context() is not None:
        with ops.init_scope():
            self._keys = ops.convert_to_tensor(keys, dtype=key_dtype, name='keys')
            self._values = ops.convert_to_tensor(values, dtype=value_dtype, name='values')
    else:
        self._keys = ops.convert_to_tensor(keys, dtype=key_dtype, name='keys')
        self._values = ops.convert_to_tensor(values, dtype=value_dtype, name='values')
    self._name = name if name is not None else 'key_value_init'
    if context.executing_eagerly():
        self._name += str(ops.uid())
    super(KeyValueTensorInitializer, self).__init__(self._keys.dtype, self._values.dtype)

Constructs a table initializer object based on keys and values tensors.

Args:
keys: The tensor for the keys.
values: The tensor for the values.
key_dtype: The `keys` data type. Used when `keys` is a python array.
value_dtype: The `values` data type. Used when `values` is a python array.
name: A name for the operation (optional).


def get_pytype_kwargs(self, args: argparse.Namespace) -> _ArgDict:
    return {k: getattr(args, k) for k in self.pytype_single_args}

Return a set of kwargs to pass to pytype.config.Options.

Args:
args: an argparse.Namespace.

Returns:
A dict of kwargs with pytype_single args as keys.


def get_structure_by_material_id(self, material_id, final=True, conventional_unit_cell=False):
    prop = ('final_structure' if final else 'initial_structure')
    data = self.get_data(material_id, prop=prop)
    if conventional_unit_cell:
        data[0][prop] = SpacegroupAnalyzer(data[0][prop]).get_conventional_standard_structure()
    return data[0][prop]

Get a Structure corresponding to a material_id.

Args:
material_id (str): Materials Project material_id (a string,
e.g., mp-1234).
final (bool): Whether to get the final structure, or the initial
(pre-relaxation) structure. Defaults to True.
conventional_unit_cell (bool): Whether to get the standard
conventional unit cell

Returns:
Structure object.


def _getargspec(func):
    argspec = _getspec(func)
    args = list(argspec.args)
    if argspec.varargs:
        args += [argspec.varargs]
    if argspec[2]:
        args += [argspec[2]]
    return _ArgSpec(args, argspec.varargs, argspec[2])

Return a Python 3-like argspec object.

Note:
args contains varargs and varkw if they exist. This behavior differs
from getargspec and getfullargspec.

Args:
func: The function to inspect.

Returns:
A named tuple with three parameters:
args: All named arguments, including varargs and varkw if they are
not None.
varargs: The name of the *args variable. May be None.
varkw: The name of the **kwargs variable. May be None.


def tell(self):
    self._check_open_file()
    if self._flushes_after_tell():
        self.flush()
    if (not self._append):
        return self._io.tell()
    if self._read_whence:
        write_seek = self._io.tell()
        self._io.seek(self._read_seek, self._read_whence)
        self._read_seek = self._io.tell()
        self._read_whence = 0
        self._io.seek(write_seek)
    return self._read_seek

Return the file's current position.

Returns:
int, file's current position in bytes.


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 _hash_outputs(self, index, sighash_type):
    if (sighash_type == shared.SIGHASH_ALL):
        outputs = ByteData()
        for tx_out in self.tx_outs:
            outputs += tx_out.to_bytes()
        return utils.hash256(outputs.to_bytes())
    elif ((sighash_type == shared.SIGHASH_SINGLE) and (index < len(self.tx_outs))):
        return utils.hash256(self.tx_outs[index].to_bytes())
    else:
        raise NotImplementedError('I refuse to implement the SIGHASH_SINGLE bug.')

BIP143 hashOutputs implementation

Args:
index        (int): index of input being signed
sighash_type (int): SIGHASH_SINGLE or SIGHASH_ALL
Returns:
(bytes): the hashOutputs, a 32 byte hash


def process_configs(file_lookup, app_config_format, pipeline_config):

    app_configs = collections.defaultdict(dict)
    for env in ENVS:
        file_json = app_config_format.format(env=env)
        try:
            env_config = file_lookup.json(filename=file_json)
            app_configs[env] = apply_region_configs(env_config)
        except FileNotFoundError:
            LOG.critical('Application configuration not available for %s.', env)
            continue

    try:
        app_configs['pipeline'] = file_lookup.json(filename=pipeline_config)
    except FileNotFoundError:
        LOG.warning('Unable to process pipeline.json. Using defaults.')
        app_configs['pipeline'] = {'env': ['stage', 'prod']}

    LOG.debug('Application configs:\n%s', app_configs)
    return app_configs

Processes the configs from lookup sources.

Args:
file_lookup (FileLookup): Source to look for file/config
app_config_format (str): The format for application config files.
pipeline_config (str): Name/path of the pipeline config

Returns:
dict: Retreived application config


def stage(self, startimage, newimage):
    client = utils.get_client()
    cprint(('  Copying file from "%s:/%s" \n                 to "%s:
    cachedir = self._setcache(client)
    cacherelpath = os.path.relpath(cachedir, TMPDIR)
    if (os.path.exists(cachedir) and (not os.path.exists(os.path.join(cachedir, 'content.tar')))):
        shutil.rmtree(cachedir)
    if (not os.path.exists(cachedir)):
        print((' * Creating cache at %s' % cacherelpath))
        container = client.containers.create(self.sourceimage)
        try:
            (tarfile_stream, tarfile_stats) = container.get_archive(self.sourcepath)
        except docker.errors.NotFound:
            raise errors.MissingFileError(('Cannot copy file "%s" from image "%s" - it does not exist!' % (self.sourcepath, self.sourceimage)))
        tempdir = tempfile.mkdtemp(dir=BUILD_TEMPDIR)
        with open(os.path.join(tempdir, 'content.tar'), 'wb') as localfile:
            for chunk in tarfile_stream:
                localfile.write(chunk)
        os.mkdir(cachedir)
        os.rename(tempdir, cachedir)
    else:
        print(('  Using cached files from %s' % cacherelpath))
    dockerfile = ('FROM %s\nADD content.tar %s' % (startimage, self.destpath))
    with open(os.path.join(cachedir, 'Dockerfile'), 'w') as df:
        df.write(dockerfile)
    buildargs = dict(path=cachedir, tag=newimage, decode=True)
    utils.set_build_cachefrom(self.cache_from, buildargs, client)
    stream = client.api.build(**buildargs)
    try:
        utils.stream_docker_logs(stream, newimage)
    except ValueError as e:
        raise errors.BuildError(dockerfile, e.args[0], build_args=buildargs)

Copies the file from source to target

Args:
startimage (str): name of the image to stage these files into
newimage (str): name of the created image


def unpack(container, path):

    from benchbuild.utils.run import run
    from benchbuild.utils.uchroot import no_args

    path = local.path(path)
    c_filename = local.path(container.filename)
    name = c_filename.basename

    if not path.exists():
        path.mkdir()

    with local.cwd(path):
        Wget(container.remote, name)

        uchroot = no_args()
        uchroot = uchroot["-E", "-A", "-C", "-r", "/", "-w",
                          os.path.abspath("."), "--"]

        has_erlent = bash[
            "-c", "tar --list -f './{0}' | grep --silent '.erlent'".format(
                name)]
        has_erlent = (has_erlent & TF)

        untar = local["/bin/tar"]["xf", "./" + name]
        if not has_erlent:
            untar = uchroot[untar]

        run(untar["--exclude=dev/*"])
        if not os.path.samefile(name, container.filename):
            rm(name)
        else:
            LOG.warning("File contents do not match: %s != %s", name,
                        container.filename)
        cp(container.filename + ".hash", path)

Unpack a container usable by uchroot.

Method that checks if a directory for the container exists,
checks if erlent support is needed and then unpacks the
container accordingly.

Args:
path: The location where the container is, that needs to be unpacked.


def _process_transcode(self, item, feed_item):
    if feed_item.get('transcode_config', None):
        if not 'videoSettings' in item:
            item['videoSettings'] = {}
        if not 'transcodeSettings' in item['videoSettings']:
            item['videoSettings']['transcodeSettings'] = {}
        item['videoSettings']['transcodeSettings']['enabledVideoFormats'] = self.video_format_dao.translate_transcode_config(feed_item['transcode_config'])
        if not item['videoSettings']['transcodeSettings']['enabledVideoFormats']:
            raise Exception('Specified transcode profile did not match any placement level transcode settings in Campaign Manager')

Updates / creates transcode configuration for the placement.

This method updates the CM placement object with transcoding configuration
from the feed.

Args:
item: The CM placement object to update.
feed_item: The Bulkdozer feed item with the transcode configurations.


def _dropout_sparse_coo_matrix(sparse_matrix, rate, min_dropout_rate, max_dropout_rate):
    if (min_dropout_rate is None):
        min_dropout_rate = FLAGS.min_dropout_rate
    if (max_dropout_rate is None):
        max_dropout_rate = FLAGS.max_dropout_rate
    if (min_dropout_rate > max_dropout_rate):
        raise ValueError(('min_dropout_rate (%f) should be less or equal to max_dropout_rate (%f)' % (min_dropout_rate, max_dropout_rate)))
    max_frac = (1.0 - min_dropout_rate)
    min_frac = (1.0 - max_dropout_rate)
    sampling_rate = (1.0 - rate)
    sampled_fraction = min(max(sampling_rate, min_frac), max_frac)
    if (sampled_fraction != sampling_rate):
        logging.warning('Minimum sampling rate is %2f.', min_frac)
        logging.warning('Maximum sampling rate is %2f.', max_frac)
        logging.warning('Desired sampling rate is %2f.', sampling_rate)
        logging.warning('Desired sampling rate %2f clipped to %2f.', sampling_rate, sampled_fraction)
    num_sampled = min(max(int((sparse_matrix.nnz * sampled_fraction)), 1), sparse_matrix.nnz)
    sampled_indices = np.random.choice(sparse_matrix.nnz, size=num_sampled, replace=False)
    return sparse.coo_matrix((sparse_matrix.data[sampled_indices], (sparse_matrix.row[sampled_indices], sparse_matrix.col[sampled_indices])), shape=sparse_matrix.shape)

Drop values from a sparse matrix encoded as a SciPy coo matrix.

Args:
sparse_matrix: a SciPy coo sparse matrix.
rate: if rate > 0 then non-zero elements of the input matrix
will be droped uniformly at random.
min_dropout_rate: minimum value for the dropout rate. If None
FLAGS.min_dropout_rate is used. If dropout_rate is lower than
min_dropout_rate it will clipped to min_dropout_rate.
max_dropout_rate: minimum value for the dropout rate. If None
FLAGS.max_dropout_rate is used. If dropout_rate is greater than
max_dropout_rate it will clipped to max_dropout_rate.

Returns:
A SciPy coo matrix containing those non zero elements that have not been
dropped out.


def AsDict(self, dt=True):
    data = {}
    if self.name:
        data['name'] = self.name
        data['mlkshk_url'] = self.mlkshk_url
    if self.profile_image_url:
        data['profile_image_url'] = self.profile_image_url
    if self.id:
        data['id'] = self.id
    if self.about:
        data['about'] = self.about
    if self.website:
        data['website'] = self.website
    if self.shakes:
        data['shakes'] = [shk.AsDict(dt=dt) for shk in self.shakes]
    data['shake_count'] = self.shake_count
    return data

A dict representation of this User instance.

The return value uses the same key names as the JSON representation.

Args:
dt (bool): If True, return dates as python datetime objects. If
False, return dates as ISO strings.

Return:
A dict representing this User instance


def _refresh(self, _):
    from google.appengine.api import app_identity
    try:
        (token, _) = app_identity.get_access_token(self._scopes)
    except app_identity.Error as e:
        raise exceptions.CredentialsError(str(e))
    self.access_token = token

Refresh self.access_token.

Args:
_: (ignored) A function matching httplib2.Http.request's signature.


def _parse_and_verify(self, candidate, offset):

        try:

            if (not fullmatch(_MATCHING_BRACKETS, candidate) or _PUB_PAGES.search(candidate)):
                return None

            if self.leniency >= Leniency.VALID:

                if (offset > 0 and
                    not _LEAD_PATTERN.match(candidate)):
                    previous_char = self.text[offset - 1]

                    if (self._is_invalid_punctuation_symbol(previous_char) or
                        self._is_latin_letter(previous_char)):
                        return None
                last_char_index = offset + len(candidate)
                if last_char_index < len(self.text):
                    next_char = self.text[last_char_index]
                    if (self._is_invalid_punctuation_symbol(next_char) or
                        self._is_latin_letter(next_char)):
                        return None

            numobj = parse(candidate, self.preferred_region, keep_raw_input=True)
            if _verify(self.leniency, numobj, candidate, self):

                numobj.country_code_source = CountryCodeSource.UNSPECIFIED
                numobj.raw_input = None
                numobj.preferred_domestic_carrier_code = None
                return PhoneNumberMatch(offset, candidate, numobj)
        except NumberParseException:

            pass
        return None

Parses a phone number from the candidate using phonenumberutil.parse and
verifies it matches the requested leniency. If parsing and verification succeed, a
corresponding PhoneNumberMatch is returned, otherwise this method returns None.

Arguments:
candidate -- The candidate match.
offset -- The offset of candidate within self.text.
Returns the parsed and validated phone number match, or None.


def ensure_opened(self, timeout):
    self._handle_message(self.adb_connection.read_for_stream(self, timeout), handle_wrte=False)
    return self.is_open()

Ensure this stream transport was successfully opened.

Checks to make sure we receive our initial OKAY message.  This must be
called after creating this AdbStreamTransport and before calling read() or
write().

Args:
timeout: timeouts.PolledTimeout to use for this operation.

Returns:
True if this stream was successfully opened, False if the service was
not recognized by the remote endpoint.  If False is returned, then this
AdbStreamTransport will be already closed.

Raises:
AdbProtocolError: If we receive a WRTE message instead of OKAY/CLSE.


def __init__(self, input_dim, minval, maxval, **kwargs):

    super(NGram, self).__init__(**kwargs)
    self.input_dim = input_dim
    self.minval = minval
    self.maxval = maxval

Constructs layer.

Args:
input_dim: int > 0. Size of the vocabulary, i.e. maximum integer index +
1.
minval: Lowest inclusive value of n for computing n-grams. For example,
setting it to 1 will compute starting from unigrams.
maxval: Highest non-inclusive value of n for computing n-grams. For
example, setting it to 3 will compute at most bigrams.
**kwargs: kwargs of parent class.


def _set_default_attr(self, default_attr):
    for (attr, val) in six.iteritems(default_attr):
        if (getattr(self, attr, None) is None):
            setattr(self, attr, val)

Sets default attributes when None.

Args:
default_attr: dict. Key-val of attr, default-value.


def add_to_collections(names, value) -> None:
    get_default_graph().add_to_collections(names, value)

Wrapper for `Graph.add_to_collections()` using the default graph.

See `tf.Graph.add_to_collections`
for more details.

Args:
names: The key for the collections. The `GraphKeys` class contains many
standard names for collections.
value: The value to add to the collections.

@compatibility(eager)
Collections are only supported in eager when variables are created inside
an EagerVariableStore (e.g. as part of a layer or template).
@end_compatibility


def edit_distance(string1, string2):
    import utool as ut
    try:
        import Levenshtein
    except ImportError as ex:
        ut.printex(ex, 'pip install python-Levenshtein')
        raise
    import utool as ut
    isiter1 = ut.isiterable(string1)
    isiter2 = ut.isiterable(string2)
    strs1 = (string1 if isiter1 else [string1])
    strs2 = (string2 if isiter2 else [string2])
    distmat = [[Levenshtein.distance(str1, str2) for str2 in strs2] for str1 in strs1]
    if (not isiter2):
        distmat = ut.take_column(distmat, 0)
    if (not isiter1):
        distmat = distmat[0]
    return distmat

Edit distance algorithm. String1 and string2 can be either
strings or lists of strings

pip install python-Levenshtein

Args:
string1 (str or list):
string2 (str or list):

CommandLine:
python -m utool.util_alg edit_distance --show

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_alg import *  # NOQA
>>> import utool as ut
>>> string1 = 'hello world'
>>> string2 = ['goodbye world', 'rofl', 'hello', 'world', 'lowo']
>>> edit_distance(['hello', 'one'], ['goodbye', 'two'])
>>> edit_distance('hello', ['goodbye', 'two'])
>>> edit_distance(['hello', 'one'], 'goodbye')
>>> edit_distance('hello', 'goodbye')
>>> distmat = edit_distance(string1, string2)
>>> result = ('distmat = %s' % (ut.repr2(distmat),))
>>> print(result)
>>> [7, 9, 6, 6, 7]


def _should_retry_apk_install(error_msg: str) -> bool:
    return 'INSTALL_FAILED_INSUFFICIENT_STORAGE' in error_msg

Decides whether we should retry adb install.

Args:
error_msg: string, the error message of an adb install failure.

Returns:
True if a retry is warranted; False otherwise.


def profile_update_schema(profile):
    if (profile.get('autoclear') is None):
        print('{}{}Profile Update: Adding new "autoclear" parameter.'.format(c.Style.BRIGHT, c.Fore.YELLOW))
        profile['autoclear'] = True
    for validation in (profile.get('validations') or []):
        if (validation.get('data_type') is None):
            print('{}{}Profile Update: Adding new "data_type" parameter.'.format(c.Style.BRIGHT, c.Fore.YELLOW))
            validation['data_type'] = 'redis'
    if ((profile.get('install_json') is not None) and (profile.get('script') is not None)):
        print('{}{}Removing deprecated "script" parameter.'.format(c.Style.BRIGHT, c.Fore.YELLOW))
        profile.pop('script')

Update profile to latest schema.

Args:
profile (dict): The dictionary containting the profile settings.


def get_comments(self, sharekey=None):
    if (not sharekey):
        raise Exception("You must specify a sharekey of the file youwant to 'like'.")
    endpoint = '/api/sharedfile/{0}/comments'.format(sharekey)
    data = self._make_request('GET', endpoint=endpoint)
    return [Comment.NewFromJSON(c) for c in data['comments']]

Retrieve comments on a SharedFile

Args:
sharekey (str): Sharekey for the file from which you want to return
the set of comments.

Returns:
List of Comment objects.


def run_ppm_server(pdb_file, outfile, force_rerun=False):

    if ssbio.utils.force_rerun(outfile=outfile, flag=force_rerun):
        url = 'http:
        files = {'userfile': open(pdb_file, 'rb')}
        r = requests.post(url, files=files)
        info = r.text

        with open(outfile, 'w') as f:
            f.write(info)

    else:

        with open(outfile, 'r') as f:
            info = f.read()

    t = info.replace('\n', '')
    tt = t.replace('\r', '')
    ttt = tt.replace('\t', '')

    soup = BeautifulSoup(ttt, "lxml")

    tables = soup.find_all("table", attrs={"class": "data"})

    info_dict = {}

    table_index = 0
    for t in tables:
        data_index = 0

        for data in t.find_all('tr', attrs={"class": "row1"}):
            data_list = list(data.strings)

            if table_index == 0:
                info_dict['Depth/Hydrophobic Thickness'] = data_list[0]
                info_dict['deltaG_transfer'] = data_list[2]
                info_dict['Tilt Angle'] = data_list[3]

            if table_index == 1 and data_index == 0:
                info_dict['Embedded_residues_Tilt'] = data_list[0]
                info_dict['Embedded_residues'] = data_list[1]

            if table_index == 1 and data_index == 1:
                info_dict['Transmembrane_secondary_structure_segments_Tilt'] = data_list[0]
                info_dict['Transmembrane_secondary_structure_segments'] = data_list[1]

            if table_index == 2:
                info_dict['Output Messages'] = data_list[1]

            if table_index == 3:
                baseurl = 'http:
                a = data.find('a', href=True)
                download_url = baseurl + a['href'].replace('./', '')
                info_dict['Output file download link'] = download_url

            data_index += 1
        table_index += 1

    return info_dict

Run the PPM server from OPM to predict transmembrane residues.

Args:
pdb_file (str): Path to PDB file
outfile (str): Path to output HTML results file
force_rerun (bool): Flag to rerun PPM if HTML results file already exists

Returns:
dict: Dictionary of information from the PPM run, including a link to download the membrane protein file


def add_signature(key, inputs, outputs):

  _check_dict_maps_to_tensors_or_sparse_tensors(inputs)
  _check_dict_maps_to_tensors_or_sparse_tensors(outputs)
  input_info = {
      input_name: tf_v1.saved_model.utils.build_tensor_info(tensor)
      for input_name, tensor in inputs.items()
  }
  output_info = {
      output_name: tf_v1.saved_model.utils.build_tensor_info(tensor)
      for output_name, tensor in outputs.items()
  }
  signature = tf_v1.saved_model.signature_def_utils.build_signature_def(
      input_info, output_info)
  tf_v1.add_to_collection(_SIGNATURE_COLLECTION, (key, signature))

Adds a signature to current graph.

Args:
key: Signature key as a string.
inputs: Signature inputs as a map from string to Tensor or SparseTensor.
outputs: Signature outputs as a map from string to Tensor or SparseTensor.
(Recall that a Variable is not a Tensor, but Variable.value() is.)

Raises:
TypeError: if the arguments have the wrong types.


def read_cs_core_contribution(self):
    header_pattern = '^\\s+Core NMR properties\\s*$\\n\\n^\\s+typ\\s+El\\s+Core shift \\(ppm\\)\\s*$\\n^\\s+-{20,}$\\n'
    row_pattern = '\\d+\\s+(?P<element>[A-Z][a-z]?\\w?)\\s+(?P<shift>[-]?\\d+\\.\\d+)'
    footer_pattern = '\\s+-{20,}\\s*$'
    self.read_table_pattern(header_pattern, row_pattern, footer_pattern, postprocess=str, last_one_only=True, attribute_name='cs_core_contribution')
    core_contrib = {d['element']: float(d['shift']) for d in self.data['cs_core_contribution']}
    self.data['cs_core_contribution'] = core_contrib

Parse the core contribution of NMR chemical shielding.

Returns:
G0 contribution matrix as list of list.


def _example_number_anywhere_for_type(num_type):

    for region_code in SUPPORTED_REGIONS:
        example_numobj = example_number_for_type(region_code, num_type)
        if example_numobj is not None:
            return example_numobj

    for country_calling_code in COUNTRY_CODES_FOR_NON_GEO_REGIONS:
        metadata = PhoneMetadata.metadata_for_nongeo_region(country_calling_code, None)
        desc = _number_desc_by_type(metadata, num_type)
        if desc is not None and desc.example_number is not None:
            try:
                return parse(_PLUS_SIGN + unicod(country_calling_code) + desc.example_number, UNKNOWN_REGION)
            except NumberParseException:
                pass

    return None

Gets a valid number for the specified number type (it may belong to any country).

Arguments:
num_type -- The type of number that is needed.

Returns a valid number for the specified type. Returns None when the
metadata does not contain such information. This should only happen when
no numbers of this type are allocated anywhere in the world anymore.


def _scroll(clicks, x=None, y=None):

    startx, starty = _position()
    width, height = _size()

    if x is None:
        x = startx
    else:
        if x < 0:
            x = 0
        elif x >= width:
            x = width - 1
    if y is None:
        y = starty
    else:
        if y < 0:
            y = 0
        elif y >= height:
            y = height - 1

    try:
        _sendMouseEvent(MOUSEEVENTF_WHEEL, x, y, dwData=clicks)
    except (PermissionError, OSError):
            pass

Send the mouse vertical scroll event to Windows by calling the
mouse_event() win32 function.

Args:
clicks (int): The amount of scrolling to do. A positive value is the mouse
wheel moving forward (scrolling up), a negative value is backwards (down).
x (int): The x position of the mouse event.
y (int): The y position of the mouse event.

Returns:
None


def alltoall_ring(xs, devices, split_axis, concat_axis):

  n = len(xs)
  if n == 1:
    return xs

  parts = [[None] * n for i in xrange(n)]
  def my_split(x, size_splits):
    total_size = tf.shape(x)[split_axis]
    part_size = total_size
    return tf.split(x, [s * part_size for s in size_splits], axis=split_axis)
  forward_message_size = (n - 1)
  backward_message_size = (n - 1) - forward_message_size
  forward_messages = [None] * n
  backward_messages = [None] * n
  for i in xrange(n):
    with tf.device(devices[i]):
      if i >= backward_message_size:
        a, b, c, d = my_split(
            xs[i], [i - backward_message_size,
                    backward_message_size, 1, n - i - 1])
        backward_messages[i] = b
        parts[i][i] = c
        forward_messages[i] = tf.concat([d, a], axis=split_axis)
      else:
        a, b, c, d = my_split(
            xs[i], [i, 1, forward_message_size, backward_message_size - i])
        backward_messages[i] = tf.concat([d, a], axis=split_axis)
        parts[i][i] = b
        forward_messages[i] = c
  for step in xrange(1, max(forward_message_size, backward_message_size) + 1):
    new_forward_messages = [None] * n
    new_backward_messages = [None] * n
    for i in xrange(n):
      with tf.device(devices[i]):
        if forward_message_size > 0:
          parts[i][(i - step) % n], new_forward_messages[i] = my_split(
              forward_messages[(i - 1) % n], [1, forward_message_size - 1])
        if backward_message_size > 0:
          new_backward_messages[i], parts[i][(i + step) % n] = my_split(
              backward_messages[(i + 1) % n], [backward_message_size - 1, 1])
    forward_message_size -= 1
    backward_message_size -= 1
    forward_messages = new_forward_messages
    backward_messages = new_backward_messages
  return mtf.parallel(devices, tf.concat, parts, axis=[concat_axis] * n)

MPI alltoall operation.

Performance-optimized for a ring of devices.

Args:
xs: a list of n tf.Tensors
devices: a list of n strings
split_axis: an integer
concat_axis: an integer

Returns:
a list of n Tensors


def AddValue(self, name, number, aliases=None, description=None):

    if name in self.values_per_name:
      raise KeyError('Value with name: {0:s} already exists.'.format(name))

    if number in self.values_per_number:
      raise KeyError('Value with number: {0!s} already exists.'.format(number))

    for alias in aliases or []:
      if alias in self.values_per_alias:
        raise KeyError('Value with alias: {0:s} already exists.'.format(alias))

    enumeration_value = EnumerationValue(
        name, number, aliases=aliases, description=description)

    self.values.append(enumeration_value)
    self.values_per_name[name] = enumeration_value
    self.values_per_number[number] = enumeration_value

    for alias in aliases or []:
      self.values_per_alias[alias] = enumeration_value

Adds an enumeration value.

Args:
name (str): name.
number (int): number.
aliases (Optional[list[str]]): aliases.
description (Optional[str]): description.

Raises:
KeyError: if the enumeration value already exists.


def _updateEncoding(self, index):

        encoding = self._encodingComboBox.itemText(index)
        encoding = encoding.lower()

        self._encodingKey = _calculateEncodingKey(encoding)
        self._previewFile()

Changes the value of the encoding combo box to the value of given index.

This method is also a `SLOT`.
After the encoding is changed, the file will be reloaded and previewed.

Args:
index (int): An valid index of the combo box.


def PC_varExplained(Y,standardized=True):

    if standardized:
        Y-=Y.mean(0)
        Y/=Y.std(0)
    covY = sp.cov(Y)
    S,U = linalg.eigh(covY+1e-6*sp.eye(covY.shape[0]))
    S = S[::-1]
    rv = np.array([S[0:i].sum() for i in range(1,S.shape[0])])
    rv/= S.sum()
    return rv

Run PCA and calculate the cumulative fraction of variance
Args:
Y: phenotype values
standardize: if True, phenotypes are standardized
Returns:
var: cumulative distribution of variance explained


def read(self, size=None):

    if not self._database_object:
      raise IOError('Not opened.')

    if self._current_offset < 0:
      raise IOError('Invalid offset value out of bounds.')

    if size == 0 or self._current_offset >= self._size:
      return b''

    if size is None:
      size = self._size
    if self._current_offset + size > self._size:
      size = self._size - self._current_offset

    start_offset = self._current_offset
    self._current_offset += size
    return self._blob[start_offset:self._current_offset]

Reads a byte string from the file-like object at the current offset.

The function will read a byte string of the specified size or
all of the remaining data if no size was specified.

Args:
size (Optional[int]): number of bytes to read, where None is all
remaining data.

Returns:
bytes: data read.

Raises:
IOError: if the read failed.
OSError: if the read failed.


def __init__(self, fp, encoding, chunk_size):

        self.path = fp.name
        self.encoding = encoding
        self.chunk_size = chunk_size
        self.__fp = fp
        self.__buf = BufferWorkSpace(self.__fp, self.chunk_size)

Constructor for FileReadBackwardsIterator

Args:
fp (File): A file that we wish to start reading backwards from
encoding (str): Encoding of the file
chunk_size (int): How many bytes to read at a time


def reset(self, ms=0, halt=True):

        self._dll.JLINKARM_SetResetDelay(ms)

        res = self._dll.JLINKARM_Reset()
        if res < 0:
            raise errors.JLinkException(res)
        elif not halt:
            self._dll.JLINKARM_Go()

        return res

Resets the target.

This method resets the target, and by default toggles the RESET and
TRST pins.

Args:
self (JLink): the ``JLink`` instance
ms (int): Amount of milliseconds to delay after reset (default: 0)
halt (bool): if the CPU should halt after reset (default: True)

Returns:
Number of bytes read.


def play(self, **kwargs):
    path = ('%s/%s/play' % (self.manager.path, self.get_id()))
    self.manager.gitlab.http_post(path)

Trigger a job explicitly.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabJobPlayError: If the job could not be triggered


def l1_loss(tensor, weight=1.0, scope=None):

  with tf.name_scope(scope, 'L1Loss', [tensor]):
    weight = tf.convert_to_tensor(weight,
                                  dtype=tensor.dtype.base_dtype,
                                  name='loss_weight')
    loss = tf.multiply(weight, tf.reduce_sum(tf.abs(tensor)), name='value')
    tf.add_to_collection(LOSSES_COLLECTION, loss)
    return loss

Define a L1Loss, useful for regularize, i.e. lasso.

Args:
tensor: tensor to regularize.
weight: scale the loss by this factor.
scope: Optional scope for name_scope.

Returns:
the L1 loss op.


def deep_get(d, *keys, default=None):
    for key in keys:
        try:
            d = d[key]
        except (KeyError, IndexError, TypeError):
            return default
    return d

Recursive safe search in a dictionary of dictionaries.

Args:
d: the dictionary to work with
*keys: the list of keys to work with
default: the default value to return if the recursive search did not succeed

Returns:
The value wich was found recursively in d, or default if the search did not succeed

Example:

>>> d = {"user": {"id": 1, "login": "foo"}, "date": "2016-04-27"}
>>> deep_get(d, "user", "login")
"foo"
>>> deep_get(d, "user")
{"id": 1, "login": "foo"}
>>> deep_get(d, "user", "name")
None
>>> deep_get(d, "user", "name", default="bar")
"bar"


def _update_indexed_slices_param(graph, loop_vars, init_slices, input_slices, output_slices, old_output_slices):
    structured_idx = _get_tensor_index_in_iterable(graph.structured_outputs, old_output_slices)
    flat_idx = _get_tensor_index_in_iterable(graph.outputs, func_graph.flatten(old_output_slices)[0])
    graph.structured_outputs[structured_idx] = output_slices
    graph.outputs = func_graph.flatten(graph.structured_outputs)
    graph.inputs = graph.inputs[:flat_idx] + _flatten(input_slices) + graph.inputs[flat_idx + 1:]
    return loop_vars[:flat_idx] + _flatten(init_slices) + loop_vars[flat_idx + 1:]

Updates graph with new IndexedSlices input/output.

Updates graph's metadata to output the gradient computation defined by
init_slices, input_slices, and output_slices, instead of outputting
old_output_slices. Also returns a new version of loop_vars with init_slices
replacing the old input.

Args:
graph: _WhileBodyGradFuncGraph.
loop_vars: the inputs to graph.
init_slices: the new IndexedSlices to use as input to graph.
input_slices: the new IndexedSlices in graph that should be fed by
init_slices.
output_slices: the new IndexedSlices in graph that should be the
corresponding output to input_slices.
old_output_slices: the IndexedSlices in graph that are currently being
output.

Returns:
New loop_vars to pass to graph.


def _normal_a_cell(ip, p, filters, block_id=None):
    channel_dim = 1 if backend.image_data_format() == 'channels_first' else -1
    with backend.name_scope(f'normal_A_block_{block_id}'):
        p = _adjust_block(p, ip, filters, block_id)
        h = layers.Activation('relu')(ip)
        h = layers.Conv2D(filters, (1, 1), strides=(1, 1), padding='same', name=f'normal_conv_1_{block_id}', use_bias=False, kernel_initializer='he_normal')(h)
        h = layers.BatchNormalization(axis=channel_dim, momentum=0.9997, epsilon=0.001, name=f'normal_bn_1_{block_id}')(h)
        with backend.name_scope('block_1'):
            x1_1 = _separable_conv_block(h, filters, kernel_size=(5, 5), block_id=f'normal_left1_{block_id}')
            x1_2 = _separable_conv_block(p, filters, block_id=f'normal_right1_{block_id}')
            x1 = layers.add([x1_1, x1_2], name=f'normal_add_1_{block_id}')
        with backend.name_scope('block_2'):
            x2_1 = _separable_conv_block(p, filters, (5, 5), block_id=f'normal_left2_{block_id}')
            x2_2 = _separable_conv_block(p, filters, (3, 3), block_id=f'normal_right2_{block_id}')
            x2 = layers.add([x2_1, x2_2], name=f'normal_add_2_{block_id}')
        with backend.name_scope('block_3'):
            x3 = layers.AveragePooling2D((3, 3), strides=(1, 1), padding='same', name=f'normal_left3_{block_id}')(h)
            x3 = layers.add([x3, p], name=f'normal_add_3_{block_id}')
        with backend.name_scope('block_4'):
            x4_1 = layers.AveragePooling2D((3, 3), strides=(1, 1), padding='same', name=f'normal_left4_{block_id}')(p)
            x4_2 = layers.AveragePooling2D((3, 3), strides=(1, 1), padding='same', name=f'normal_right4_{block_id}')(p)
            x4 = layers.add([x4_1, x4_2], name=f'normal_add_4_{block_id}')
        with backend.name_scope('block_5'):
            x5 = _separable_conv_block(h, filters, block_id=f'normal_left5_{block_id}')
            x5 = layers.add([x5, h], name=f'normal_add_5_{block_id}')
        x = layers.concatenate([p, x1, x2, x3, x4, x5], axis=channel_dim, name=f'normal_concat_{block_id}')
    return (x, ip)

Adds a Normal cell for NASNet-A (Fig. 4 in the paper).

Args:
ip: Input tensor `x`
p: Input tensor `p`
filters: Number of output filters
block_id: String block_id

Returns:
A Keras tensor


def get_unconditional_inputs(self, num_samples=1, return_tensors='pt'):
    inputs = self.tokenizer([''] * num_samples, return_tensors=return_tensors, return_attention_mask=True)
    inputs['attention_mask'][:] = 0
    return inputs

Helper function to get null inputs for unconditional generation, enabling the model to be used without the
feature extractor or tokenizer.

Args:
num_samples (int, *optional*):
Number of audio samples to unconditionally generate.

Example:
```python
>>> from transformers import MusicgenMelodyForConditionalGeneration, MusicgenMelodyProcessor

>>> model = MusicgenMelodyForConditionalGeneration.from_pretrained("facebook/musicgen-melody")

>>> # get the unconditional (or 'null') inputs for the model
>>> processor = MusicgenMelodyProcessor.from_pretrained("facebook/musicgen-melody")
>>> unconditional_inputs = processor.get_unconditional_inputs(num_samples=1)

>>> audio_samples = model.generate(**unconditional_inputs, max_new_tokens=256)
```


def plot_waterfall(self, f_start=None, f_stop=None, if_id=0, logged=True, cb=True, MJD_time=False, **kwargs):
    (plot_f, plot_data) = self.grab_data(f_start, f_stop, if_id)
    if (self.header[b'foff'] < 0):
        plot_data = plot_data[(..., ::(- 1))]
        plot_f = plot_f[::(- 1)]
    if logged:
        plot_data = db(plot_data)
    (dec_fac_x, dec_fac_y) = (1, 1)
    if (plot_data.shape[0] > MAX_IMSHOW_POINTS[0]):
        dec_fac_x = int((plot_data.shape[0] / MAX_IMSHOW_POINTS[0]))
    if (plot_data.shape[1] > MAX_IMSHOW_POINTS[1]):
        dec_fac_y = int((plot_data.shape[1] / MAX_IMSHOW_POINTS[1]))
    plot_data = rebin(plot_data, dec_fac_x, dec_fac_y)
    try:
        plt.title(self.header[b'source_name'])
    except KeyError:
        plt.title(self.filename)
    extent = self._calc_extent(plot_f=plot_f, plot_t=self.timestamps, MJD_time=MJD_time)
    plt.imshow(plot_data, aspect='auto', origin='lower', rasterized=True, interpolation='nearest', extent=extent, cmap='viridis', **kwargs)
    if cb:
        plt.colorbar()
    plt.xlabel('Frequency [MHz]')
    if MJD_time:
        plt.ylabel('Time [MJD]')
    else:
        plt.ylabel('Time [s]')

Plot waterfall of data

Args:
f_start (float): start frequency, in MHz
f_stop (float): stop frequency, in MHz
logged (bool): Plot in linear (False) or dB units (True),
cb (bool): for plotting the colorbar
kwargs: keyword args to be passed to matplotlib imshow()


def add_asset(self, asset_type, asset_name):

        if not self.can_update():
            self._tcex.handle_error(910, [self.type])

        if asset_type == 'PHONE':
            return self.tc_requests.add_adversary_phone_asset(
                self.api_type, self.api_sub_type, self.unique_id, asset_name
            )
        if asset_type == 'HANDLER':
            return self.tc_requests.add_adversary_handler_asset(
                self.api_type, self.api_sub_type, self.unique_id, asset_name
            )
        if asset_type == 'URL':
            return self.tc_requests.add_adversary_url_asset(
                self.api_type, self.api_sub_type, self.unique_id, asset_name
            )
        self._tcex.handle_error(
            925, ['asset_type', 'assets', 'asset_type', 'asset_type', asset_type]
        )
        return None

Add an asset to the adversary
Args:
asset_type: (str) Either PHONE, HANDLER, or URL
asset_name: (str) the value for the asset

Returns:


def composite_scheme_step(first_scheme_steps, first_scheme, second_scheme):

    def step_fn(time, next_time, coord_grid, value_grid, boundary_conditions, second_order_coeff_fn, first_order_coeff_fn, zeroth_order_coeff_fn, inner_second_order_coeff_fn, inner_first_order_coeff_fn, num_steps_performed, dtype=None, name=None):

        name = name or 'composite_scheme_step'

        def scheme(*args, **kwargs):
            return tf.cond(num_steps_performed < first_scheme_steps, lambda: first_scheme(*args, **kwargs), lambda: second_scheme(*args, **kwargs))
        return parabolic_equation_step(time, next_time, coord_grid, value_grid, boundary_conditions, second_order_coeff_fn, first_order_coeff_fn, zeroth_order_coeff_fn, inner_second_order_coeff_fn, inner_first_order_coeff_fn, time_marching_scheme=scheme, dtype=dtype, name=name)
    return step_fn

Composes two time marching schemes.

Applies a step of parabolic PDE solver using `first_scheme` if number of
performed steps is less than `first_scheme_steps`, and using `second_scheme`
otherwise.

Args:
first_scheme_steps: A Python integer. Number of steps to apply
`first_scheme` on.
first_scheme: First time marching scheme (see `time_marching_scheme`
argument of `parabolic_equation_step`).
second_scheme: Second time marching scheme (see `time_marching_scheme`
argument of `parabolic_equation_step`).

Returns:
Callable to be used in finite-difference PDE solvers (see fd_solvers.py).


def is_unused(input, model_file=None, model_proto=None, name=None):
    return _gen_sentencepiece_processor_op.sentencepiece_get_piece_type(input, model_file=model_file, model_proto=model_proto, name=name, piece_type=2)

Returns true if input id is unused piece.

Args:
input: An arbitrary tensor of int32.
model_file: The sentencepiece model file path.
model_proto: The sentencepiece model serialized proto.
Either `model_file` or `model_proto` must be set.
name: The name argument that is passed to the op function.
Returns:
A tensor of bool with the same shape as input.


def new_contract_proxy(self, contract_interface, contract_address: Address):
    return ContractProxy(self, contract=self.new_contract(contract_interface, contract_address))

Return a proxy for interacting with a smart contract.

Args:
contract_interface: The contract interface as defined by the json.
address: The contract's address.


def _maybe_add_call_warning(self, node, full_name, name):
    warned = False
    if isinstance(node.func, ast.Attribute):
        warned = self._maybe_add_warning(node, '*.' + name)
    arg_warnings = self._get_applicable_dict('function_arg_warnings', full_name, name)
    variadic_args = uses_star_args_or_kwargs_in_call(node)
    for (kwarg, arg), (level, warning) in sorted(arg_warnings.items()):
        present, _ = get_arg_value(node, kwarg, arg) or variadic_args
        if present:
            warned = True
            warning_message = warning.replace('<function name>', full_name or name)
            template = '%s called with %s argument, requires manual check: %s'
            if variadic_args:
                template = '%s called with *args or **kwargs that may include %s, requires manual check: %s'
            self.add_log(level, node.lineno, node.col_offset, template % (full_name or name, kwarg, warning_message))
    return warned

Print a warning when specific functions are called with selected args.

The function _print_warning_for_function matches the full name of the called
function, e.g., tf.foo.bar(). This function matches the function name that
is called, as long as the function is an attribute. For example,
`tf.foo.bar()` and `foo.bar()` are matched, but not `bar()`.

Args:
node: ast.Call object
full_name: The precomputed full name of the callable, if one exists, None
otherwise.
name: The precomputed name of the callable, if one exists, None otherwise.

Returns:
Whether an error was recorded.


def sample_uniform(domain, rng):

  if isinstance(domain, hp.IntInterval):
    return rng.randint(domain.min_value, domain.max_value)
  elif isinstance(domain, hp.RealInterval):
    return rng.uniform(domain.min_value, domain.max_value)
  elif isinstance(domain, hp.Discrete):
    return rng.choice(domain.values)
  else:
    raise TypeError("unknown domain type: %r" % (domain,))

Sample a value uniformly from a domain.

Args:
domain: An `IntInterval`, `RealInterval`, or `Discrete` domain.
rng: A `random.Random` object; defaults to the `random` module.

Raises:
TypeError: If `domain` is not a known kind of domain.
IndexError: If the domain is empty.


def prefer_static_rank(x):
    return prefer_static_value(array_ops.rank(x))

Return static rank of tensor `x` if available, else `tf.rank(x)`.

Args:
x: `Tensor` (already converted).

Returns:
Numpy array (if static rank is obtainable), else `Tensor`.


def multi_process(func, data, num_process=None, verbose=True, **args):
    assert isinstance(data, pd.DataFrame), 'Input data must be a pandas.DataFrame instance'
    if (num_process is None):
        num_process = multiprocessing.cpu_count()
    tasks = multiprocessing.JoinableQueue()
    results = multiprocessing.Queue()
    error_queue = multiprocessing.Queue()
    start_time = time.time()
    num_task = len(data)
    for i in range(num_task):
        tasks.put(data.iloc[(i, :)])
    for i in range(num_process):
        tasks.put(None)
    logger.info('Create {} processes'.format(num_process))
    consumers = [Consumer(func, tasks, results, error_queue, **args) for i in range(num_process)]
    for w in consumers:
        w.start()
    task_tracker = TaskTracker(tasks, verbose)
    task_tracker.start()
    tasks.join()
    num_error = error_queue.qsize()
    if (num_error > 0):
        for i in range(num_error):
            logger.error(error_queue.get())
        raise RuntimeError('Multi process jobs failed')
    else:
        result_table = []
        while num_task:
            result_table.append(results.get())
            num_task -= 1
        df_results = pd.DataFrame(result_table)
        logger.info('Jobs finished in {0:.2f}s'.format((time.time() - start_time)))
        return df_results

Function to use multiprocessing to process pandas Dataframe.

This function applies a function on each row of the input DataFrame by
multiprocessing.

Args:
func (function): The function to apply on each row of the input
Dataframe. The func must accept pandas.Series as the first
positional argument and return a pandas.Series.
data (pandas.DataFrame): A DataFrame to be processed.
num_process (int, optional): The number of processes to run in
parallel. Defaults to be the number of CPUs of the computer.
verbose (bool, optional): Set to False to disable verbose output.
args (dict): Keyword arguments to pass as keywords arguments to `func`
return:
A dataframe containing the results


def create_summary_metadata(hparams_plugin_data_pb):
    if (not isinstance(hparams_plugin_data_pb, plugin_data_pb2.HParamsPluginData)):
        raise TypeError(('Needed an instance of plugin_data_pb2.HParamsPluginData. Got: %s' % type(hparams_plugin_data_pb)))
    content = plugin_data_pb2.HParamsPluginData()
    content.CopyFrom(hparams_plugin_data_pb)
    content.version = PLUGIN_DATA_VERSION
    return tf.compat.v1.SummaryMetadata(plugin_data=tf.compat.v1.SummaryMetadata.PluginData(plugin_name=PLUGIN_NAME, content=content.SerializeToString()))

Returns a summary metadata for the HParams plugin.

Returns a summary_pb2.SummaryMetadata holding a copy of the given
HParamsPluginData message in its plugin_data.content field.
Sets the version field of the hparams_plugin_data_pb copy to
PLUGIN_DATA_VERSION.

Args:
hparams_plugin_data_pb: the HParamsPluginData protobuffer to use.


def appendDirectory(self, directory, projectFilePath):

        lines = []
        with open(projectFilePath, 'r') as original:
            for l in original:
                lines.append(l)

        with open(projectFilePath, 'w') as new:
            for line in lines:
                card = {}
                try:
                    card = self._extractCard(line)

                except:
                    card = self._extractDirectoryCard(line)

                numSpaces = max(2, 25 - len(card['name']))

                if card['value'] is None:
                    rewriteLine = '%s\n' % (card['name'])
                else:
                    if card['name'] == 'WMS':
                        rewriteLine = '%s %s\n' % (card['name'], card['value'])

                    elif card['name'] == 'PROJECT_PATH':
                        filePath = '"%s"' % os.path.normpath(directory)
                        rewriteLine = '%s%s%s\n' % (card['name'], ' ' * numSpaces, filePath)

                    elif '"' in card['value']:
                        filename = card['value'].strip('"')
                        filePath = '"%s"' % os.path.join(directory, filename)
                        rewriteLine = '%s%s%s\n' % (card['name'], ' ' * numSpaces, filePath)

                    else:
                        rewriteLine = '%s%s%s\n' % (card['name'], ' ' * numSpaces, card['value'])

                new.write(rewriteLine)

Append directory to relative paths in project file. By default, the project file paths are read and written as
relative paths. Use this method to prepend a directory to all the paths in the project file.

Args:
directory (str): Directory path to prepend to file paths in project file.
projectFilePath (str): Path to project file that will be modified.


def hexagonal(a: float, c: float):
    return Lattice.from_parameters(a, a, c, 90, 90, 120)

Convenience constructor for a hexagonal lattice.

Args:
a (float): *a* lattice parameter of the hexagonal cell.
c (float): *c* lattice parameter of the hexagonal cell.

Returns:
Hexagonal lattice of dimensions a x a x c.


class MaxNumBoundingBoxes(BaseImagePreprocessingLayer):

    def __init__(self, max_number, fill_value=-1, **kwargs):
        super().__init__(**kwargs)
        self.max_number = int(max_number)
        self.fill_value = int(fill_value)

    def transform_images(self, images, transformation=None, training=True):
        return images

    def transform_labels(self, labels, transformation=None, training=True):
        return labels

    def transform_bounding_boxes(self, bounding_boxes, transformation, training=True):
        ops = self.backend
        boxes = bounding_boxes['boxes']
        labels = bounding_boxes['labels']
        boxes_shape = ops.shape(boxes)
        batch_size = boxes_shape[0]
        num_boxes = boxes_shape[1]
        pad_size = ops.numpy.maximum(ops.numpy.subtract(self.max_number, num_boxes), 0)
        boxes = boxes[:, :self.max_number, ...]
        boxes = ops.numpy.pad(boxes, [[0, 0], [0, pad_size], [0, 0]], constant_values=self.fill_value)
        labels = labels[:, :self.max_number]
        labels = ops.numpy.pad(labels, [[0, 0], [0, pad_size]], constant_values=self.fill_value)
        boxes = ops.numpy.reshape(boxes, [batch_size, self.max_number, 4])
        labels = ops.numpy.reshape(labels, [batch_size, self.max_number])
        bounding_boxes = bounding_boxes.copy()
        bounding_boxes['boxes'] = boxes
        bounding_boxes['labels'] = labels
        return bounding_boxes

    def transform_segmentation_masks(self, segmentation_masks, transformation=None, training=True):
        return self.transform_images(segmentation_masks)

    def compute_output_shape(self, input_shape):
        if isinstance(input_shape, dict) and 'bounding_boxes' in input_shape:
            input_keys = set(input_shape['bounding_boxes'].keys())
            extra_keys = input_keys - set(('boxes', 'labels'))
            if extra_keys:
                raise KeyError(f'There are unsupported keys in `bounding_boxes`: {list(extra_keys)}. Only `boxes` and `labels` are supported.')
            boxes_shape = list(input_shape['bounding_boxes']['boxes'])
            boxes_shape[1] = self.max_number
            labels_shape = list(input_shape['bounding_boxes']['labels'])
            labels_shape[1] = self.max_number
            input_shape['bounding_boxes']['boxes'] = boxes_shape
            input_shape['bounding_boxes']['labels'] = labels_shape
        return input_shape

    def get_config(self):
        config = super().get_config()
        config.update({'max_number': self.max_number})
        return config

Ensure the maximum number of bounding boxes.

Args:
max_number: Desired output number of bounding boxes.
padding_value: The padding value of the `boxes` and `labels` in
`bounding_boxes`. Defaults to `-1`.


def _parse_name(self, name):
    if name.endswith('_float32_vars'):
        error_msg = "Policies ending in '_float32_vars' have been removed from TensorFlow."
        if name in ('infer_float32_vars', 'infer_with_float32_vars'):
            error_msg += " Please use the 'mixed_float16' or 'mixed_bfloat16' policy instead."
        elif name == 'float16_with_float32_vars':
            error_msg += " Please use the 'mixed_float16' policy instead."
        elif name == 'bfloat16_with_float32_vars':
            error_msg += " Please use the 'mixed_bfloat16' policy instead."
        error_msg += " Got policy name: '%s'" % name
        raise ValueError(error_msg)
    if name == 'mixed_float16':
        return ('float16', 'float32')
    elif name == 'mixed_bfloat16':
        return ('bfloat16', 'float32')
    elif name == '_infer':
        return (None, None)
    try:
        dtype = dtypes.as_dtype(name).name
    except TypeError:
        error = "Cannot convert value %s to a mixed precision Policy. Valid policies include 'mixed_float16', 'mixed_bfloat16', and the name of any dtype such as 'float32'." % (name,)
        raise ValueError(error)
    return (dtype, dtype)

Parses a Policy name into a compute and variable dtype.

Args:
name: The name of the policy:

Returns:
The (compute_dtype, variable_dtype) pair.


def snapshot(self, at):
    if (self._name_parts.decorator != ''):
        raise Exception('Cannot use snapshot() on an already decorated table')
    value = Table._convert_decorator_time(at)
    return Table(('%s@%s' % (self._full_name, str(value))), context=self._context)

Return a new Table which is a snapshot of this table at the specified time.

Args:
at: the time of the snapshot. This can be a Python datetime (absolute) or timedelta
(relative to current time). The result must be after the table was created and no more
than seven days in the past. Passing None will get a reference the oldest snapshot.

Note that using a datetime will get a snapshot at an absolute point in time, while
a timedelta will provide a varying snapshot; any queries issued against such a Table
will be done against a snapshot that has an age relative to the execution time of the
query.

Returns:
A new Table object referencing the snapshot.

Raises:
An exception if this Table is already decorated, or if the time specified is invalid.


def fit(fqdn, result, *argl, **argd):

    global _machines
    out = None
    if len(argl) > 0:
        machine = argl[0]

        key = id(machine)
        _machines[key] = (machine, argl[0], argl[1])

        if isclassifier(machine):
            out = classify_fit(fqdn, result, *argl, **argd)
        elif isregressor(machine):
            out = regress_fit(fqdn, result, *argl, **argd)

    return out

Analyzes the result of a generic fit operation performed by `sklearn`.

Args:
fqdn (str): full-qualified name of the method that was called.
result: result of calling the method with `fqdn`.
argl (tuple): positional arguments passed to the method call.
argd (dict): keyword arguments passed to the method call.


def Parse(self, parser_mediator, file_object):

    if not file_object:
      raise errors.UnableToParseFile('Invalid file object')

    if self._INITIAL_FILE_OFFSET is not None:
      file_object.seek(self._INITIAL_FILE_OFFSET, os.SEEK_SET)

    parser_mediator.AppendToParserChain(self)
    try:
      self.ParseFileObject(parser_mediator, file_object)
    finally:
      parser_mediator.PopFromParserChain()

Parses a single file-like object.

Args:
parser_mediator (ParserMediator): a parser mediator.
file_object (dvfvs.FileIO): a file-like object to parse.

Raises:
UnableToParseFile: when the file cannot be parsed.


def _joint_covariances(self):
    with tf.name_scope('covariance_joint'):
        with tf.control_dependencies(self.runtime_assertions):
            initial_latent_cov = _broadcast_to_shape(self.initial_state_prior.covariance(), tf.concat([self.batch_shape_tensor(), [self.latent_size, self.latent_size]], axis=0))
        initial_observation_cov = _propagate_cov(initial_latent_cov, self.get_observation_matrix_for_timestep(self.initial_step), self.get_observation_noise_for_timestep(self.initial_step))
        cov_step = build_kalman_cov_step(self.get_transition_matrix_for_timestep, self.get_transition_noise_for_timestep, self.get_observation_matrix_for_timestep, self.get_observation_noise_for_timestep)
        (latent_covs, observation_covs) = tf.scan(cov_step, elems=tf.range((self.initial_step + 1), self.final_step), initializer=(initial_latent_cov, initial_observation_cov))
        latent_covs = tf.concat([initial_latent_cov[(tf.newaxis, ...)], latent_covs], axis=0)
        observation_covs = tf.concat([initial_observation_cov[(tf.newaxis, ...)], observation_covs], axis=0)
        latent_covs = distribution_util.move_dimension(latent_covs, 0, (- 3))
        observation_covs = distribution_util.move_dimension(observation_covs, 0, (- 3))
        return (latent_covs, observation_covs)

Compute prior covariances for all variables via dynamic programming.

Returns:
latent_covs: Prior covariance matrices of latent states `z_t`, as
a `Tensor` of shape `batch_shape + [num_timesteps,
latent_size, latent_size]`
observation_covs: Prior covariance matrices of observations
`x_t`, as a `Tensor` of shape `batch_shape + [num_timesteps,
observation_size, observation_size]`


def strace_data_store_event(self, operation, address, address_range=0):
    cmd = enums.JLinkStraceCommand.TRACE_EVENT_SET
    event_info = structs.JLinkStraceEventInfo()
    event_info.Type = enums.JLinkStraceEvent.DATA_STORE
    event_info.Op = operation
    event_info.Addr = int(address)
    event_info.AddrRangeSize = int(address_range)
    handle = self._dll.JLINK_STRACE_Control(cmd, ctypes.byref(event_info))
    if (handle < 0):
        raise errors.JLinkException(handle)
    return handle

Sets an event to trigger trace logic when data write access is made.

Args:
self (JLink): the ``JLink`` instance.
operation (int): one of the operations in ``JLinkStraceOperation``.
address (int): the address of the store data.
address_range (int): optional range of address to trigger event on.

Returns:
An integer specifying the trace event handle.  This handle should be
retained in order to clear the event at a later time.

Raises:
JLinkException: on error.


def intersect(self, other):

        intersection = Rect()
        if lib.SDL_IntersectRect(self._ptr, self._ptr, intersection._ptr):
            return intersection
        else:
            return None

Calculate the intersection of this rectangle and another rectangle.

Args:
other (Rect): The other rectangle.

Returns:
Rect: The intersection of this rectangle and the given other rectangle, or None if there is no such
intersection.