def GetEntries(self, parser_mediator, match=None, **unused_kwargs):
    backup_alias_map = self._GetDataTypeMap('timemachine_backup_alias')
    destinations = match.get('Destinations', [])
    for destination in destinations:
        backup_alias_data = destination.get('BackupAlias', b'')
        try:
            backup_alias = self._ReadStructureFromByteStream(backup_alias_data, 0, backup_alias_map)
            alias = backup_alias.string
        except (ValueError, errors.ParseError) as exception:
            parser_mediator.ProduceExtractionWarning('unable to parse backup alias value with error: {0!s}'.format(exception))
            alias = 'Unknown alias'
        destination_identifier = (destination.get('DestinationID', None) or 'Unknown device')
        event_data = plist_event.PlistTimeEventData()
        event_data.desc = 'TimeMachine Backup in {0:s} ({1:s})'.format(alias, destination_identifier)
        event_data.key = 'item/SnapshotDates'
        event_data.root = '/Destinations'
        snapshot_dates = destination.get('SnapshotDates', [])
        for datetime_value in snapshot_dates:
            event = time_events.PythonDatetimeEvent(datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
            parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts relevant TimeMachine entries.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS.


def macro_tpm_sbs(self, state_by_state_micro_tpm):
    validate.tpm(state_by_state_micro_tpm, check_independence=False)
    mapping = self.make_mapping()
    num_macro_states = (2 ** len(self.macro_indices))
    macro_tpm = np.zeros((num_macro_states, num_macro_states))
    micro_states = range((2 ** len(self.micro_indices)))
    micro_state_transitions = itertools.product(micro_states, repeat=2)
    for (previous_state, current_state) in micro_state_transitions:
        macro_tpm[(mapping[previous_state], mapping[current_state])] += state_by_state_micro_tpm[(previous_state, current_state)]
    return np.array([distribution.normalize(row) for row in macro_tpm])

Create a state-by-state coarse-grained macro TPM.

Args:
micro_tpm (nd.array): The state-by-state TPM of the micro-system.

Returns:
np.ndarray: The state-by-state TPM of the macro-system.


def get_or_create_from_ip(ip):
    data = ip_api_handler.get(ip)
    if (data and any((v for v in data.values()))):
        if ((data.get('ip_address', None) is None) or (not data['ip_address'])):
            data['ip_address'] = ip
        return IPInfo.objects.get_or_create(**data)
    return (None, False)

Get or create an entry using obtained information from an IP.

Args:
ip (str): IP address xxx.xxx.xxx.xxx.

Returns:
ip_info: an instance of IPInfo.


def _split_by_task(devices, values):
    num_devices = len(devices)
    if num_devices != len(values):
        raise ValueError('len(devices) must equal len(values)')
    per_task_devices = collections.OrderedDict()
    per_task_values = collections.OrderedDict()
    for d in range(num_devices):
        d_spec = device_lib.DeviceSpec.from_string(devices[d])
        if not hasattr(d_spec, 'task') or d_spec.task is None:
            assert False, 'failed to parse device %s' % devices[d]
        index = (d_spec.job or 'localhost', d_spec.replica or 0, d_spec.task)
        if index not in per_task_devices:
            per_task_devices[index] = []
            per_task_values[index] = []
        per_task_devices[index].append(devices[d])
        per_task_values[index].append(values[d])
    return (list(per_task_devices.values()), list(per_task_values.values()))

Partition devices and values by common task.

Args:
devices: list of device name strings
values: list of `tf.Tensor` of same length as devices.

Returns:
(per_task_devices, per_task_values) where both values are
lists of lists with isomorphic structure: the outer list is
indexed by task, and the inner list has length of the number
of values belonging to that task.  per_task_devices contains
the specific devices to which the values are local, and
per_task_values contains the corresponding values.

Raises:
ValueError: devices must be same length as values.


def get_copy_pool():
    global _COPY_POOL
    if _COPY_POOL is None:
        _COPY_POOL = multiprocessing.pool.ThreadPool(_COPY_THREADS)
        atexit.register(_COPY_POOL.close)
    return _COPY_POOL

Shared threadpool for copying arrays.

Pool instantiation takes ~ 2ms, so a singleton pool is used rather than
creating a pool per SliceAggregator.

Returns:
The global copy threadpool.


def add_ast_fn(d, spec, parent_function=None):

    if d["type"] == "Function":
        ast_fn = Function(d["function"]["name"], spec, parent_function=parent_function)
        for arg in d["args"]:
            if arg["type"] == "Function":
                ast_fn.add_argument(add_ast_fn(arg, spec, parent_function=ast_fn))
            elif arg["type"] == "NSArg":
                ast_fn.add_argument(
                    NSArg(arg["nsarg"]["ns"], arg["nsarg"]["ns_val"], ast_fn)
                )
            elif arg["type"] == "StrArg":
                ast_fn.add_argument(StrArg(arg["arg"], ast_fn))
    return ast_fn

Convert dict AST to object AST Function

Args:
ast_fn: AST object Function
d: AST as dictionary
spec: BEL Specification

Return:
ast_fn


class PatchTSMixerForPredictionHead(nn.Module):

    def __init__(self, config: PatchTSMixerConfig, distribution_output=None):
        super().__init__()
        self.prediction_channel_indices = config.prediction_channel_indices
        if self.prediction_channel_indices is not None:
            self.prediction_channel_indices.sort()
        self.dropout_layer = nn.Dropout(config.head_dropout)
        if distribution_output is None:
            self.base_forecast_block = nn.Linear(config.num_patches * config.d_model, config.prediction_length)
        else:
            self.base_forecast_block = distribution_output.get_parameter_projection(config.num_patches * config.d_model)
        self.flatten = nn.Flatten(start_dim=-2)

    def forward(self, hidden_features):

        hidden_features = self.flatten(hidden_features)
        hidden_features = self.dropout_layer(hidden_features)
        forecast = self.base_forecast_block(hidden_features)
        if isinstance(forecast, tuple):
            forecast = tuple((z.transpose(-1, -2) for z in forecast))
        else:
            forecast = forecast.transpose(-1, -2)
        if self.prediction_channel_indices is not None:
            if isinstance(forecast, tuple):
                forecast = tuple((z[..., self.prediction_channel_indices] for z in forecast))
            else:
                forecast = forecast[..., self.prediction_channel_indices]
        return forecast

Prediction Head for Forecasting

Args:
config (`PatchTSMixerConfig`):
Configuration.


def greater_than_evaluator(self, index):
    condition_name = self.condition_data[index][0]
    condition_value = self.condition_data[index][1]
    user_value = self.attributes.get(condition_name)
    if (not validator.is_finite_number(condition_value)):
        self.logger.warning(audience_logs.UNKNOWN_CONDITION_VALUE.format(self._get_condition_json(index)))
        return None
    if (not self.is_value_a_number(user_value)):
        self.logger.warning(audience_logs.UNEXPECTED_TYPE.format(self._get_condition_json(index), type(user_value), condition_name))
        return None
    if (not validator.is_finite_number(user_value)):
        self.logger.warning(audience_logs.INFINITE_ATTRIBUTE_VALUE.format(self._get_condition_json(index), condition_name))
        return None
    return (user_value > condition_value)

Evaluate the given greater than match condition for the user attributes.

Args:
index: Index of the condition to be evaluated.

Returns:
Boolean:
- True if the user attribute value is greater than the condition value.
- False if the user attribute value is less than or equal to the condition value.
None: if the condition value isn't finite or the user attribute value isn't finite.


def compress_pdf(filepath, output_path, ghostscript_binary):
    if (not filepath.endswith(PDF_EXTENSION)):
        raise ValueError(('Filename must end with .pdf!\n%s does not.' % filepath))
    try:
        file_size = os.stat(filepath).st_size
        if (file_size < FILE_SIZE_LOWER_LIMIT):
            LOGGER.info(NOT_COMPRESSING.format(filepath, file_size, FILE_SIZE_LOWER_LIMIT))
            process = subprocess.Popen(['cp', filepath, output_path])
        else:
            LOGGER.info(COMPRESSING.format(filepath))
            process = subprocess.Popen([ghostscript_binary, '-sDEVICE=pdfwrite', '-dCompatabilityLevel=1.4', '-dPDFSETTINGS=/ebook', '-dNOPAUSE', '-dQUIET', '-dBATCH', ('-sOutputFile=%s' % output_path), filepath])
    except FileNotFoundError:
        msg = GS_NOT_INSTALLED.format(ghostscript_binary)
        raise FileNotFoundError(msg)
    process.communicate()
    LOGGER.info(FILE_DONE.format(output_path))

Compress a single PDF file.

Args:
filepath (str): Path to the PDF file.
output_path (str): Output path.
ghostscript_binary (str): Name/alias of the Ghostscript binary.

Raises:
ValueError
FileNotFoundError


def traverse_ancestors(self, include_self=True):
    if (not isinstance(include_self, bool)):
        raise TypeError('include_self must be a bool')
    if include_self:
        c = self
    else:
        c = self.parent
    while (c is not None):
        (yield c)
        c = c.parent

Traverse over the ancestors of this ``Node``

Args:
``include_self`` (``bool``): ``True`` to include self in the traversal, otherwise ``False``


def depth_renderbuffer(self, size, *, samples=0) -> 'Renderbuffer':

        res = Renderbuffer.__new__(Renderbuffer)
        res.mglo, res._glo = self.mglo.depth_renderbuffer(size, samples)
        res._size = size
        res._components = 1
        res._samples = samples
        res._dtype = 'f4'
        res._depth = True
        res.ctx = self
        res.extra = None
        return res

:py:class:`Renderbuffer` objects are OpenGL objects that contain images.
They are created and used specifically with :py:class:`Framebuffer` objects.

Args:
size (tuple): The width and height of the renderbuffer.

Keyword Args:
samples (int): The number of samples. Value 0 means no multisample format.

Returns:
:py:class:`Renderbuffer` object


def from_backbone_config(cls, backbone_config: PretrainedConfig, **kwargs):
    return cls(backbone_config=backbone_config, **kwargs)

Instantiate a [`TvpConfig`] (or a derived class) from a pre-trained backbone model configuration.

Args:
backbone_config ([`PretrainedConfig`]):
The backbone configuration.
Returns:
[`TvpConfig`]: An instance of a configuration object


def _get_next_date_from_partial_date(partial_date):
    relativedelta_arg = 'years'
    if partial_date.month:
        relativedelta_arg = 'months'
    if partial_date.day:
        relativedelta_arg = 'days'
    next_date = (parse(partial_date.dumps()) + relativedelta(**{relativedelta_arg: 1}))
    return PartialDate.from_parts(next_date.year, (next_date.month if partial_date.month else None), (next_date.day if partial_date.day else None))

Calculates the next date from the given partial date.

Args:
partial_date (inspire_utils.date.PartialDate): The partial date whose next date should be calculated.

Returns:
PartialDate: The next date from the given partial date.


def get(self, identity, params=None, headers=None):
    path = self._sub_url_params('/creditor_bank_accounts/:identity', {'identity': identity})
    response = self._perform_request('GET', path, params, headers, retry_failures=True)
    return self._resource_for(response)

Get a single creditor bank account.

Retrieves the details of an existing creditor bank account.

Args:
identity (string): Unique identifier, beginning with "BA".
params (dict, optional): Query string parameters.

Returns:
ListResponse of CreditorBankAccount instances


def _send_offset_fetch_request(self, partitions):
    assert (self.config['api_version'] >= (0, 8, 1)), 'Unsupported Broker API'
    assert all(map((lambda k: isinstance(k, TopicPartition)), partitions))
    if (not partitions):
        return Future().success({})
    node_id = self.coordinator()
    if (node_id is None):
        return Future().failure(Errors.GroupCoordinatorNotAvailableError)
    if (not self._client.ready(node_id)):
        log.debug('Node %s not ready -- failing offset fetch request', node_id)
        return Future().failure(Errors.NodeNotReadyError)
    log.debug('Group %s fetching committed offsets for partitions: %s', self.group_id, partitions)
    topic_partitions = collections.defaultdict(set)
    for tp in partitions:
        topic_partitions[tp.topic].add(tp.partition)
    if (self.config['api_version'] >= (0, 8, 2)):
        request = OffsetFetchRequest[1](self.group_id, list(topic_partitions.items()))
    else:
        request = OffsetFetchRequest[0](self.group_id, list(topic_partitions.items()))
    future = Future()
    _f = self._client.send(node_id, request)
    _f.add_callback(self._handle_offset_fetch_response, future)
    _f.add_errback(self._failed_request, node_id, request, future)
    return future

Fetch the committed offsets for a set of partitions.

This is a non-blocking call. The returned future can be polled to get
the actual offsets returned from the broker.

Arguments:
partitions (list of TopicPartition): the partitions to fetch

Returns:
Future: resolves to dict of offsets: {TopicPartition: int}


def get_statuses(self, batch_ids):

        with self._lock:
            return {b: self.get_status(b) for b in batch_ids}

Returns a statuses dict for the requested batches.

Args:
batch_ids (list of str): The ids of the batches to get statuses for

Returns:
dict: A dict with keys of batch ids, and values of status enums


def read_worker_creds(key="credentials"):

    for path in CREDS_FILES:
        if not os.path.exists(path):
            continue
        contents = load_json_or_yaml(path, is_path=True, exception=None)
        if contents.get(key):
            return contents[key]
    else:
        if key == "credentials" and os.environ.get("TASKCLUSTER_ACCESS_TOKEN") and \
                os.environ.get("TASKCLUSTER_CLIENT_ID"):
            credentials = {
                "accessToken": os.environ["TASKCLUSTER_ACCESS_TOKEN"],
                "clientId": os.environ["TASKCLUSTER_CLIENT_ID"],
            }
            if os.environ.get("TASKCLUSTER_CERTIFICATE"):
                credentials['certificate'] = os.environ['TASKCLUSTER_CERTIFICATE']
            return credentials

Get credentials from CREDS_FILES or the environment.

This looks at the CREDS_FILES in order, and falls back to the environment.

Args:
key (str, optional): each CREDS_FILE is a json dict.  This key's value
contains the credentials.  Defaults to 'credentials'.

Returns:
dict: the credentials found. None if no credentials found.


def update_vmss(access_token, subscription_id, resource_group, vmss_name, body):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Compute/virtualMachineScaleSets/', vmss_name, '?api-version=', COMP_API])
    return do_put(endpoint, body, access_token)

Update a VMSS with a new JSON body. E.g. do a GET, change something, call this.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vm_name (str): Name of the virtual machine.
body (dict): JSON body of the VM scale set.

Returns:
HTTP response.


def assign(self, assign_context: 'AssignContext') -> Iterable['BoundedWindow']:
    raise NotImplementedError

Associates windows to an element.

Arguments:
assign_context: Instance of AssignContext.

Returns:
An iterable of BoundedWindow.


def sample_points_using_uncertainty(self, logits: torch.Tensor, uncertainty_function, num_points: int, oversample_ratio: int, importance_sample_ratio: float) -> torch.Tensor:
    num_boxes = logits.shape[0]
    num_points_sampled = int(num_points * oversample_ratio)
    point_coordinates = torch.rand(num_boxes, num_points_sampled, 2, device=logits.device)
    point_logits = sample_point(logits, point_coordinates, align_corners=False)
    point_uncertainties = uncertainty_function(point_logits)
    num_uncertain_points = int(importance_sample_ratio * num_points)
    num_random_points = num_points - num_uncertain_points
    idx = torch.topk(point_uncertainties[:, 0, :], k=num_uncertain_points, dim=1)[1]
    shift = num_points_sampled * torch.arange(num_boxes, dtype=torch.long, device=logits.device)
    idx += shift[:, None]
    point_coordinates = point_coordinates.view(-1, 2)[idx.view(-1), :].view(num_boxes, num_uncertain_points, 2)
    if num_random_points > 0:
        point_coordinates = torch.cat([point_coordinates, torch.rand(num_boxes, num_random_points, 2, device=logits.device)], dim=1)
    return point_coordinates

This function is meant for sampling points in [0, 1] * [0, 1] coordinate space based on their uncertainty. The
uncertainty is calculated for each point using the passed `uncertainty function` that takes points logit
prediction as input.

Args:
logits (`float`):
Logit predictions for P points.
uncertainty_function:
A function that takes logit predictions for P points and returns their uncertainties.
num_points (`int`):
The number of points P to sample.
oversample_ratio (`int`):
Oversampling parameter.
importance_sample_ratio (`float`):
Ratio of points that are sampled via importance sampling.

Returns:
point_coordinates (`torch.Tensor`):
Coordinates for P sampled points.


def _call_flat(self, tensor_inputs, captured_inputs):
    ctx = context.context()
    executing_eagerly = ctx.executing_eagerly()
    default_graph = ops.get_default_graph()
    if default_graph.building_function and (not self._func_graph.saveable):
        default_graph.mark_as_unsaveable(self._func_graph.saving_errors)
    if record.could_possibly_record() or hasattr(default_graph, 'watch_variable'):
        for v in self._func_graph.variables:
            resource_variable_ops.variable_accessed(v)
    if not executing_eagerly:
        for i, tensor_input in enumerate(tensor_inputs):
            if tensor_input.dtype == dtypes.resource or tensor_input.dtype == dtypes.variant:
                continue
            graph_input_shape = tensor_shape.TensorShape(self._func_graph.inputs[i].shape)
            if not graph_input_shape.is_compatible_with(tensor_input.shape):
                raise ValueError(f'Tensor {tensor_input} is not compatible with the shape this function was traced with. Expected shape {self._func_graph.inputs[i].shape}, but got shape {tensor_input.shape}.\n\nIf you called get_concrete_function, you may need to pass a tf.TensorSpec(..., shape=...) with a less specific shape, having None on axes which can vary.')
    args = tensor_inputs + captured_inputs
    possible_gradient_type = gradients_util.PossibleTapeGradientTypes(args)
    if possible_gradient_type == gradients_util.POSSIBLE_GRADIENT_TYPES_NONE and executing_eagerly:
        return self._inference_function.call_preflattened(args)
    forward_backward = self._select_forward_and_backward_functions(args, possible_gradient_type, executing_eagerly)
    forward_function, args_with_tangents = forward_backward.forward()
    if executing_eagerly:
        flat_outputs = forward_function.call_flat(*args_with_tangents)
    else:
        with default_graph._override_gradient_function({'PartitionedCall': self._get_gradient_function(), 'StatefulPartitionedCall': self._get_gradient_function()}):
            flat_outputs = forward_function.call_flat(*args_with_tangents)
    forward_backward.record(flat_outputs)
    return self.function_type.pack_output(flat_outputs)

Executes the wrapped function.

Args:
tensor_inputs: a list of only Tensors generated from args, kwargs.
captured_inputs: the captured inputs that are also part of the input args
to the actual execution. By default, it should be self._captured_inputs.
Returns:
The result of applying the TF function to `args`.

Raises:
ValueError: If `args` contains anything other than Tensors or Variables.


def delete(self):

        config = self.get()
        if not config:
            return True
        command = 'no router ospf {}'.format(config['ospf_process_id'])
        return self.configure(command)

Removes the entire ospf process from the running configuration

Args:
None
Returns:
bool: True if the command completed succssfully


def ttr(self, kloc, acc=10**3, verbose=1):

        kloc = numpy.asarray(kloc, dtype=int)
        shape = kloc.shape
        kloc = kloc.reshape(len(self), -1)
        cache = {}
        out = [evaluation.evaluate_recurrence_coefficients(self, k)
               for k in kloc.T]
        out = numpy.array(out).T
        return out.reshape((2,)+shape)

Three terms relation's coefficient generator

Args:
k (numpy.ndarray, int):
The order of the coefficients.
acc (int):
Accuracy of discretized Stieltjes if analytical methods are
unavailable.

Returns:
(Recurrence coefficients):
Where out[0] is the first (A) and out[1] is the second
coefficient With ``out.shape==(2,)+k.shape``.


def absnormpath(self, path):

        path = self.normcase(path)
        cwd = self._matching_string(path, self.cwd)
        if not path:
            path = self.path_separator
        elif not self._starts_with_root_path(path):

            root_name = self._matching_string(path, self.root.name)
            empty = self._matching_string(path, '')
            path = self._path_separator(path).join(
                (cwd != root_name and cwd or empty, path))
        if path == self._matching_string(path, '.'):
            path = cwd
        return self.normpath(path)

Absolutize and minimalize the given path.

Forces all relative paths to be absolute, and normalizes the path to
eliminate dot and empty components.

Args:
path:  Path to normalize.

Returns:
The normalized path relative to the current working directory,
or the root directory if path is empty.


def exons(self, hgnc_id=None, transcript_id=None,  build=None):

        query = {}
        if build:
            query['build'] = build
        if hgnc_id:
            query['hgnc_id'] = hgnc_id
        if transcript_id:
            query['transcript_id'] = transcript_id

        return self.exon_collection.find(query)

Return all exons

Args:
hgnc_id(int)
transcript_id(str)
build(str)

Returns:
exons(iterable(dict))


def load_py_config(conf_file):
    if (sys.version_info >= (3, 5)):
        from importlib import util
        spec = util.spec_from_file_location('pelconf', conf_file)
        mod = util.module_from_spec(spec)
        spec.loader.exec_module(mod)
    elif (sys.version_info >= (3, 3)):
        from importlib import machinery
        loader = machinery.SourceFileLoader('pelconf', conf_file)
        _ = loader.load_module()
    elif (sys.version_info <= (3, 0)):
        import imp
        imp.load_source('pelconf', conf_file)

Import configuration from a python file.

This will just import the file into python. Sky is the limit. The file
has to deal with the configuration all by itself (i.e. call conf.init()).
You will also need to add your src directory to sys.paths if it's not the
current working directory. This is done automatically if you use yaml
config as well.

Args:
conf_file (str):
Path to the py module config. This function will not check the file
name or extension and will just crash if the given file does not
exist or is not a valid python file.


def apply_trans_fn(self, fn: Callable[[torch.Tensor], torch.Tensor]) -> Rigid:
    return Rigid(self._rots, fn(self._trans))

Applies a Tensor -> Tensor function to the stored translation.

Args:
fn:
A function of type Tensor -> Tensor to be applied to the translation
Returns:
A transformation object with a transformed translation.


def from_dict(cls, config_dict: Dict[str, Any], **kwargs) -> 'GenerationConfig':
    return_unused_kwargs = kwargs.pop('return_unused_kwargs', False)
    kwargs.pop('_from_auto', None)
    kwargs.pop('_from_pipeline', None)
    if '_commit_hash' in kwargs and '_commit_hash' in config_dict:
        kwargs['_commit_hash'] = config_dict['_commit_hash']
    config = cls(**{**config_dict, **kwargs})
    unused_kwargs = config.update(**kwargs)
    logger.info(f'Generate config {config}')
    if return_unused_kwargs:
        return (config, unused_kwargs)
    else:
        return config

Instantiates a [`GenerationConfig`] from a Python dictionary of parameters.

Args:
config_dict (`Dict[str, Any]`):
Dictionary that will be used to instantiate the configuration object.
kwargs (`Dict[str, Any]`):
Additional parameters from which to initialize the configuration object.

Returns:
[`GenerationConfig`]: The configuration object instantiated from those parameters.


def set_of_vars(lovs):

    return set(var for pvars in lovs for svars in pvars for var in svars)

Build set of variables from list.

Args:
lovs: nested lists of variables such as the one produced by
:func:`list_of_vars`.
Returns:
set of str: flattened set of all the variables present in the
nested lists.


def _calculateLrcString(inputstring):
    _checkString(inputstring, description='input LRC string')
    register = 0
    for character in inputstring:
        register += ord(character)
    lrc = (((register ^ 255) + 1) & 255)
    lrcString = _numToOneByteString(lrc)
    return lrcString

Calculate LRC for Modbus.

Args:
inputstring (str): An arbitrary-length message (without the beginning
colon and terminating CRLF). It should already be decoded from hex-string.

Returns:
A one-byte LRC bytestring (not encoded to hex-string)

Algorithm from the document 'MODBUS over serial line specification and implementation guide V1.02'.

The LRC is calculated as 8 bits (one byte).

For example a LRC 0110 0001 (bin) = 61 (hex) = 97 (dec) = 'a'. This function will
then return 'a'.

In Modbus ASCII mode, this should be transmitted using two characters. This
example should be transmitted '61', which is a string of length two. This function
does not handle that conversion for transmission.


def get_document(project_id, knowledge_base_id, document_id):

    import dialogflow_v2beta1 as dialogflow
    client = dialogflow.DocumentsClient()
    document_path = client.document_path(project_id, knowledge_base_id,
                                         document_id)

    response = client.get_document(document_path)
    print('Got Document:')
    print(' - Display Name: {}'.format(response.display_name))
    print(' - Knowledge ID: {}'.format(response.name))
    print(' - MIME Type: {}'.format(response.mime_type))
    print(' - Knowledge Types:')
    for knowledge_type in response.knowledge_types:
        print('    - {}'.format(KNOWLEDGE_TYPES[knowledge_type]))
    print(' - Source: {}\n'.format(response.content_uri))

Gets a Document.

Args:
project_id: The GCP project linked with the agent.
knowledge_base_id: Id of the Knowledge base.
document_id: Id of the Document.


def holiday_name(self, value=None):
    if (value is not None):
        try:
            value = str(value)
        except ValueError:
            raise ValueError('value {} need to be of type str for field `holiday_name`'.format(value))
        if (',' in value):
            raise ValueError('value should not contain a comma for field `holiday_name`')
    self._holiday_name = value

Corresponds to IDD Field `holiday_name`

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

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


def train_model(self,
                  train_op,
                  cost_to_log,
                  num_steps,
                  feed_vars=(),
                  feed_data=None,
                  print_every=100):

    costs = [train_op]
    if (isinstance(cost_to_log, collections.Sequence)
        and not isinstance(cost_to_log, six.string_types)):
      costs.extend(cost_to_log)
    else:
      costs.append(cost_to_log)
    return self.run_model(costs,
                          num_steps,
                          feed_vars=feed_vars,
                          feed_data=feed_data,
                          print_every=print_every)[2:]

Trains the given model.

Args:
train_op: The training operation.
cost_to_log: A cost to log.
num_steps: Number of batches to run.
feed_vars: A list or tuple of the variables that will be fed.
feed_data: A generator that produces tuples of the same length as
feed_vars.
print_every: Print and save every so many steps.
Returns:
`cost_to_log` from the final step.


def set_filetype(self, filetype, bufnr=None):

        if bufnr:
            self._vim.command(str(bufnr) + 'bufdo set filetype=' + filetype)
        else:
            self._vim.command('set filetype=' + filetype)

Set filetype for a buffer.

Note: it's a quirk of Vim's Python API that using the buffer.options
dictionary to set filetype does not trigger ``FileType`` autocommands,
hence this implementation executes as a command instead.

Args:
filetype (str): The filetype to set.
bufnr (Optional[int]): A Vim buffer number, current if ``None``.


def predict_features(self, df_features, df_target, idx=0, **kwargs):

        y = np.transpose(df_target.values)
        X = np.transpose(df_features.values)

        path, beta, A, lam = hsiclasso(X, y)

        return beta

For one variable, predict its neighbouring nodes.

Args:
df_features (pandas.DataFrame):
df_target (pandas.Series):
idx (int): (optional) for printing purposes
kwargs (dict): additional options for algorithms

Returns:
list: scores of each feature relatively to the target

.. warning::
Not implemented. Implemented by the algorithms.


def assert_shape_match(shape1, shape2):

  shape1 = tf.TensorShape(shape1)
  shape2 = tf.TensorShape(shape2)
  if shape1.ndims is None or shape2.ndims is None:
    raise ValueError('Shapes must have known rank. Got %s and %s.' %
                     (shape1.ndims, shape2.ndims))
  shape1.assert_same_rank(shape2)
  shape1.assert_is_compatible_with(shape2)

Ensure the shape1 match the pattern given by shape2.

Ex:
assert_shape_match((64, 64, 3), (None, None, 3))

Args:
shape1 (tuple): Static shape
shape2 (tuple): Dynamic shape (can contain None)


def get_pixel_coordinates(self, point, ccdnum):
    hdulist_index = self.get_hdulist_idx(ccdnum)
    if (isinstance(point[0], Quantity) and isinstance(point[1], Quantity)):
        pix_point = (point[0].value, point[1].value)
    else:
        pix_point = point
    if self.reading.inverted:
        pix_point = (((self.reading.obs.naxis1 - pix_point[0]) + 1), ((self.reading.obs.naxis2 - pix_point[1]) + 1))
    (x, y) = self.hdulist[hdulist_index].converter.convert(pix_point)
    return (x, y, hdulist_index)

Retrieves the pixel location of a point within the current HDUList given the
location in the original FITS image.  This takes into account that
the image may be a cutout of a larger original.

Args:
point: tuple(float, float)
(x, y) in original.

Returns:
(x, y) pixel in this image.
@param extno: the extno from the original Mosaic that the x/y coordinates are from.


def classify_field(value):

    if not (isinstance(value, six.string_types) and value):
        return

    schema = load_schema('elements/inspire_field')
    inspire_categories = schema['properties']['term']['enum']

    for inspire_category in inspire_categories:
        if value.upper() == inspire_category.upper():
            return inspire_category

    category = normalize_arxiv_category(value)
    return ARXIV_TO_INSPIRE_CATEGORY_MAPPING.get(category, 'Other')

Normalize ``value`` to an Inspire category.

Args:
value(str): an Inspire category to properly case, or an arXiv category
to translate to the corresponding Inspire category.

Returns:
str: ``None`` if ``value`` is not a non-empty string,
otherwise the corresponding Inspire category.


def _build_udf(name, code, return_type, params, language, imports):

    params = ','.join(['%s %s' % named_param for named_param in params])
    imports = ','.join(['library="%s"' % i for i in imports])

    if language.lower() == 'sql':
        udf = 'CREATE TEMPORARY FUNCTION {name} ({params})\n' + \
              'RETURNS {return_type}\n' + \
              'AS (\n' + \
              '{code}\n' + \
              ');'
    else:
        udf = 'CREATE TEMPORARY FUNCTION {name} ({params})\n' +\
              'RETURNS {return_type}\n' + \
              'LANGUAGE {language}\n' + \
              'AS \n' +\
              'OPTIONS (\n' +\
              '{imports}\n' +\
              ');'
    return udf.format(name=name, params=params, return_type=return_type,
                      language=language, code=code, imports=imports)

Creates the UDF part of a BigQuery query using its pieces

Args:
name: the name of the javascript function
code: function body implementing the logic.
return_type: BigQuery data type of the function return. See supported data types in
the BigQuery docs
params: dictionary of parameter names and types
language: see list of supported languages in the BigQuery docs
imports: a list of GCS paths containing further support code.


def transform(self):
    request = _worker.Request()
    result = self._transform_fn(self._model, request.content, request.content_type, request.accept)
    if isinstance(result, tuple):
        return _worker.Response(response=result[0], mimetype=result[1])
    return result

Take a request with input data, deserialize it, make a prediction, and return a
serialized response.

Returns:
sagemaker_containers.beta.framework.worker.Response: a Flask response object with
the following args:

* response: the serialized data to return
* accept: the content type that the data was serialized into


def PrintMessage(self, message):

    if (message.DESCRIPTOR.full_name == _ANY_FULL_TYPE_NAME and
        self.descriptor_pool and self._TryPrintAsAnyMessage(message)):
      return
    fields = message.ListFields()
    if self.use_index_order:
      fields.sort(key=lambda x: x[0].index)
    for field, value in fields:
      if _IsMapEntry(field):
        for key in sorted(value):

          entry_submsg = value.GetEntryClass()(key=key, value=value[key])
          self.PrintField(field, entry_submsg)
      elif field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
        for element in value:
          self.PrintField(field, element)
      else:
        self.PrintField(field, value)

Convert protobuf message to text format.

Args:
message: The protocol buffers message.


class Reduce(Metric):

    def __init__(self, reduction, name, dtype=None):
        super(Reduce, self).__init__(name=name, dtype=dtype)
        self.reduction = reduction
        self.total = self.add_weight('total', initializer=init_ops.zeros_initializer)
        if reduction in [metrics_utils.Reduction.SUM_OVER_BATCH_SIZE, metrics_utils.Reduction.WEIGHTED_MEAN]:
            self.count = self.add_weight('count', initializer=init_ops.zeros_initializer)

    def update_state(self, values, sample_weight=None):

        [values], sample_weight = metrics_utils.ragged_assert_compatible_and_get_flat_values([values], sample_weight)
        try:
            values = math_ops.cast(values, self._dtype)
        except (ValueError, TypeError):
            msg = 'The output of a metric function can only be a single Tensor. Got: %s' % (values,)
            if isinstance(values, dict):
                msg += '. To return a dict of values, implement a custom Metric subclass.'
            raise RuntimeError(msg)
        if sample_weight is not None:
            sample_weight = math_ops.cast(sample_weight, self._dtype)
            values, _, sample_weight = losses_utils.squeeze_or_expand_dimensions(values, sample_weight=sample_weight)
            try:
                sample_weight = weights_broadcast_ops.broadcast_weights(sample_weight, values)
            except ValueError:
                ndim = backend.ndim(values)
                weight_ndim = backend.ndim(sample_weight)
                if self.reduction == metrics_utils.Reduction.SUM:
                    values = math_ops.reduce_sum(values, axis=list(range(weight_ndim, ndim)))
                else:
                    values = math_ops.reduce_mean(values, axis=list(range(weight_ndim, ndim)))
            values = math_ops.multiply(values, sample_weight)
        value_sum = math_ops.reduce_sum(values)
        with ops.control_dependencies([value_sum]):
            update_total_op = self.total.assign_add(value_sum)
        if self.reduction == metrics_utils.Reduction.SUM:
            return update_total_op
        if self.reduction == metrics_utils.Reduction.SUM_OVER_BATCH_SIZE:
            num_values = math_ops.cast(array_ops.size(values), self._dtype)
        elif self.reduction == metrics_utils.Reduction.WEIGHTED_MEAN:
            if sample_weight is None:
                num_values = math_ops.cast(array_ops.size(values), self._dtype)
            else:
                num_values = math_ops.reduce_sum(sample_weight)
        else:
            raise NotImplementedError('reduction [%s] not implemented' % self.reduction)
        with ops.control_dependencies([update_total_op]):
            return self.count.assign_add(num_values)

    def result(self):
        if self.reduction == metrics_utils.Reduction.SUM:
            return array_ops.identity(self.total)
        elif self.reduction in [metrics_utils.Reduction.WEIGHTED_MEAN, metrics_utils.Reduction.SUM_OVER_BATCH_SIZE]:
            return math_ops.div_no_nan(self.total, self.count)
        else:
            raise NotImplementedError('reduction [%s] not implemented' % self.reduction)

Encapsulates metrics that perform a reduce operation on the values.

Args:
reduction: a `tf.keras.metrics.Reduction` enum value.
name: string name of the metric instance.
dtype: (Optional) data type of the metric result.


def before_run(self, run_context):
    return None

Called before each call to run().

You can return from this call a `SessionRunArgs` object indicating ops or
tensors to add to the upcoming `run()` call.  These ops/tensors will be run
together with the ops/tensors originally passed to the original run() call.
The run args you return can also contain feeds to be added to the run()
call.

The `run_context` argument is a `SessionRunContext` that provides
information about the upcoming `run()` call: the originally requested
op/tensors, the TensorFlow Session.

At this point graph is finalized and you can not add ops.

Args:
run_context: A `SessionRunContext` object.

Returns:
None or a `SessionRunArgs` object.


def __init__(self, state):

    super(TurbiniaProcessor, self).__init__(state)
    self.client = None
    self.disk_name = None
    self.instance = None
    self.project = None
    self.turbinia_region = None
    self.turbinia_zone = None
    self._output_path = None

Initialize the Turbinia artifact processor object.

Args:
state: The dfTimewolf state object


def draw_line(self, x1, y1, x2, y2):

        check_int_err(lib.SDL_RenderDrawLine(self._ptr, x1, y1, x2, y2))

Draw a line on the current rendering target.

Args:
x1 (int): The x coordinate of the start point.
y1 (int): The y coordinate of the start point.
x2 (int): The x coordinate of the end point.
y2 (int): The y coordinate of the end point.

Raises:
SDLError: If an error is encountered.


def mark_bl(self) -> int:
    counter = 0
    stringy_lines = find_stringy_lines(self.node, self.first_line_no)
    for (relative_line_number, line) in enumerate(self.lines):
        if ((relative_line_number not in stringy_lines) and (line.strip() == '')):
            counter += 1
            self.line_markers[relative_line_number] = LineType.blank_line
    return counter

Mark unprocessed lines that have no content and no string nodes
covering them as blank line BL.

Returns:
Number of blank lines found with no stringy parent node.


def unsqueeze(self, dim: int) -> Rotation:
    if dim >= len(self.shape):
        raise ValueError('Invalid dimension')
    if self._rot_mats is not None:
        rot_mats = self._rot_mats.unsqueeze(dim if dim >= 0 else dim - 2)
        return Rotation(rot_mats=rot_mats, quats=None)
    elif self._quats is not None:
        quats = self._quats.unsqueeze(dim if dim >= 0 else dim - 1)
        return Rotation(rot_mats=None, quats=quats, normalize_quats=False)
    else:
        raise ValueError('Both rotations are None')

Analogous to torch.unsqueeze. The dimension is relative to the shape of the Rotation object.

Args:
dim: A positive or negative dimension index.
Returns:
The unsqueezed Rotation.


def counts(self,*args,**kwargs):

        n = Counts.read_cellframe(self,prune_neighbors=False)
        if 'measured_regions' in kwargs: n.measured_regions = kwargs['measured_regions']
        else: n.measured_regions = self.get_measured_regions()
        if 'measured_phenotypes' in kwargs: n.measured_phenotypes = kwargs['measured_phenotypes']
        else: n.measured_phenotypes = self.phenotypes
        n.microns_per_pixel = self.microns_per_pixel
        if 'minimum_region_size_pixels' in kwargs: n.minimum_region_size_pixels = kwargs['minimum_region_size_pixels']
        else: n.minimum_region_size_pixels = 1
        return n

Return a class that can be used to access count densities

Args:
measured_regions (pandas.DataFrame): Dataframe of regions that are being measured (defaults to all the regions)
measured_phenotypes (list): List of phenotypes present (defaults to all the phenotypes)
minimum_region_size_pixels (int): Minimum region size to calculate counts on in pixels (Default: 1)

Returns:
Counts: returns a class that holds the counts.


def get_op_traceback(self, op_name):
    if (not self._graph_traceback):
        raise ValueError('No graph traceback has been received yet.')
    for op_log_entry in self._graph_traceback.log_entries:
        if (op_log_entry.name == op_name):
            return self._code_def_to_traceback_list(op_log_entry.code_def)
    raise ValueError(('No op named "%s" can be found in the graph of the latest version  (%d).' % (op_name, self._graph_version)))

Get the traceback of an op in the latest version of the TF graph.

Args:
op_name: Name of the op.

Returns:
Creation traceback of the op, in the form of a list of 2-tuples:
(file_path, lineno)

Raises:
ValueError: If the op with the given name cannot be found in the latest
version of the graph that this SourceManager instance has received, or
if this SourceManager instance has not received any graph traceback yet.


def write_configuration_file(filepath=_give_default_file_path(), overwrite=False):
    config = configparser.ConfigParser()
    config.read_dict(settings)
    if (os.path.isfile(filepath) and (not overwrite)):
        try:
            raise FileExistsError
        except NameError:
            warn('File exists already and overwrite is False (default).')
    else:
        with open(filepath, 'w') as configfile:
            config.write(configfile)

Create a configuration file.

Writes the current state of settings into a configuration file.

.. note:: Since a file is permamently written, this function
is strictly speaking not sideeffect free.

Args:
filepath (str): Where to write the file.
The default is under both UNIX and Windows ``~/.chemcoordrc``.
overwrite (bool):

Returns:
None:


def NewFromJSON(data):

        return SharedFile(
            sharekey=data.get('sharekey', None),
            name=data.get('name', None),
            user=User.NewFromJSON(data.get('user', None)),
            title=data.get('title', None),
            description=data.get('description', None),
            posted_at=data.get('posted_at', None),
            permalink=data.get('permalink', None),
            width=data.get('width', None),
            height=data.get('height', None),
            views=data.get('views', 0),
            likes=data.get('likes', 0),
            saves=data.get('saves', 0),
            comments=data.get('comments', None),
            nsfw=data.get('nsfw', False),
            image_url=data.get('image_url', None),
            source_url=data.get('source_url', None),
            saved=data.get('saved', False),
            liked=data.get('liked', False),
        )

Create a new SharedFile instance from a JSON dict.

Args:
data (dict): JSON dictionary representing a SharedFile.

Returns:
A SharedFile instance.


def update_script(self, information, timeout=-1):

        uri = "{}/script".format(self.data["uri"])
        return self._helper.update(information, uri=uri, timeout=timeout)

Updates the configuration script of the logical enclosure and on all enclosures in the logical enclosure with
the specified ID.

Args:
information: Updated script.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Return:
Configuration script.


def FromReplica(self, replica):

        return AccountState(replica.ScriptHash, replica.IsFrozen, replica.Votes, replica.Balances)

Get AccountState object from a replica.
Args:
replica (obj): must have ScriptHash, IsFrozen, Votes and Balances members.

Returns:
AccountState:


def get_sentence(self, offset: int) -> (BioCSentence or None):
    for sentence in self.sentences:
        if (sentence.offset == offset):
            return sentence
    return None

Gets sentence with specified offset

Args:
offset: sentence offset

Return:
the sentence with specified offset


def _add_function(self, function) -> None:
    self._check_not_finalized()
    name = function.name
    if getattr(function, 'grad_func_name', None) and getattr(function, 'python_grad_func', None):
        raise ValueError('Gradient defined twice for function %s' % name)
    with self._c_graph.get() as c_graph:
        with function._c_func.get() as func:
            if getattr(function, '_grad_func', None):
                with function._grad_func._c_func.get() as gradient:
                    pywrap_tf_session.TF_GraphCopyFunction(c_graph, func, gradient)
            else:
                pywrap_tf_session.TF_GraphCopyFunction(c_graph, func, None)
    self._functions[compat.as_str(name)] = function
    if self._graph_def_versions.min_consumer < 12:
        self._graph_def_versions.min_consumer = 12

Adds a function to the graph.

After the function has been added, you can call to the function by
passing the function name in place of an op name to
`Graph.create_op()`.

Args:
function: A `_DefinedFunction` object.

Raises:
ValueError: if another function is defined with the same name.


def relation_completions(completion_text: str, bel_spec: BELSpec, bel_fmt: str, size: int) -> list:
    if (bel_fmt == 'short'):
        relation_list = bel_spec['relations']['list_short']
    else:
        relation_list = bel_spec['relations']['list_long']
    matches = []
    for r in relation_list:
        if re.match(completion_text, r):
            matches.append(r)
    replace_list = []
    for match in matches:
        highlight = match.replace(completion_text, f'<em>{completion_text}</em>')
        replace_list.append({'replacement': match, 'label': match, 'highlight': highlight, 'type': 'Relation'})
    return replace_list[:size]

Filter BEL relations by prefix

Args:
prefix: completion string
bel_fmt: short, medium, long BEL formats
spec: BEL specification

Returns:
list: list of BEL relations that match prefix


def validate_log_output(self, passed, db_data, user_data, oper):

        truncate = self.args.truncate
        if db_data is not None and passed:
            if isinstance(db_data, (string_types)) and len(db_data) > truncate:
                db_data = db_data[:truncate]
            elif isinstance(db_data, (list)):
                db_data_truncated = []
                for d in db_data:
                    if d is not None and isinstance(d, string_types) and len(d) > truncate:
                        db_data_truncated.append('{} ...'.format(d[: self.args.truncate]))
                    else:
                        db_data_truncated.append(d)
                db_data = db_data_truncated

        if user_data is not None and passed:
            if isinstance(user_data, (string_types)) and len(user_data) > truncate:
                user_data = user_data[: self.args.truncate]
            elif isinstance(user_data, (list)):
                user_data_truncated = []
                for u in user_data:
                    if isinstance(db_data, (string_types)) and len(u) > truncate:
                        user_data_truncated.append('{} ...'.format(u[: self.args.truncate]))
                    else:
                        user_data_truncated.append(u)
                user_data = user_data_truncated

        self.log.info('[validate] DB Data   : ({}), Type: [{}]'.format(db_data, type(db_data)))
        self.log.info('[validate] Operator  : ({})'.format(oper))
        self.log.info('[validate] User Data : ({}), Type: [{}]'.format(user_data, type(user_data)))

        if passed:
            self.log.info('[validate] Results   : Passed')
        else:
            self.log.error('[validate] Results  : Failed')
            if db_data is not None and user_data is not None and oper in ['eq', 'ne']:
                try:
                    diff_count = 0
                    for i, diff in enumerate(difflib.ndiff(db_data, user_data)):
                        if diff[0] == ' ':
                            continue
                        elif diff[0] == '-':
                            self.log.info(
                                '[validate] Diff      : Missing data at index {}'.format(i)
                            )
                        elif diff[0] == '+':
                            self.log.info('[validate] Diff      : Extra data at index {}'.format(i))
                        if diff_count > self.max_diff:

                            self.log.info('Max number of differences reached.')
                            break
                        diff_count += 1
                except TypeError:
                    pass
                except KeyError:
                    pass

            if self.args.halt_on_fail:
                raise RuntimeError('Failed validating data.')

Format the validation log output to be easier to read.

Args:
passed (bool): The results of the validation test.
db_data (str): The data store in Redis.
user_data (str): The user provided data.
oper (str): The comparison operator.

Raises:
RuntimeError: Raise error on validation failure if halt_on_fail is True.


def set_bool(self, location, value):
    element = self._handle_location(location)
    if isinstance(value, basestring):
        value = (True if (value.upper() == 'TRUE') else False)
    elif (not isinstance(value, bool)):
        raise ValueError
    if (value is True):
        element.text = 'true'
    else:
        element.text = 'false'

Set a boolean value.

Casper booleans in XML are string literals of "true" or "false".
This method sets the text value of "location" to the correct
string representation of a boolean.

Args:
location: Element or a string path argument to find()
value: Boolean or string value to set. (Accepts
"true"/"True"/"TRUE"; all other strings are False).


def from_poscar_string(poscar_string, transformations=None):
    p = Poscar.from_string(poscar_string)
    if (not p.true_names):
        raise ValueError('Transformation can be craeted only from POSCAR strings with proper VASP5 element symbols.')
    raw_string = re.sub("'", '"', poscar_string)
    s = p.structure
    source_info = {'source': 'POSCAR', 'datetime': str(datetime.datetime.now()), 'original_file': raw_string}
    return TransformedStructure(s, transformations, history=[source_info])

Generates TransformedStructure from a poscar string.

Args:
poscar_string (str): Input POSCAR string.
transformations ([Transformations]): Sequence of transformations
to be applied to the input structure.


def authors_titles_validator(record, result):
    record_authors = get_value(record, 'authors', [])
    result_authors = get_value(result, '_source.authors', [])
    author_score = compute_author_match_score(record_authors, result_authors)
    title_max_score = 0.0
    record_titles = get_value(record, 'titles.title', [])
    result_titles = get_value(result, '_source.titles.title', [])
    for cartesian_pair in product(record_titles, result_titles):
        record_title_tokens = get_tokenized_title(cartesian_pair[0])
        result_title_tokens = get_tokenized_title(cartesian_pair[1])
        current_title_jaccard = compute_jaccard_index(record_title_tokens, result_title_tokens)
        if ((current_title_jaccard > title_max_score) and (current_title_jaccard >= 0.5)):
            title_max_score = current_title_jaccard
    return (((author_score + title_max_score) / 2) > 0.5)

Compute a validation score for the possible match.

The score is based on a similarity score of the authors sets and the maximum Jaccard index found between 2 titles:
one from the record and one from the result title sets.

If the computed score is higher than 0.5, then the match is valid, otherwise it is not.

Args:
record (dict): the given record we are trying to match with similar ones in INSPIRE.
result (dict): possible match returned by the ES query that needs to be validated.

Returns:
bool: validation decision.


def _prepare_skip_target_masks(self):
    return [l is None for l in self.loss_functions]

Boolean mask for whether the target in the output list should be skipped.

If the loss function corresponding to a model output is None, then this
output will be skipped during total loss calculation and feed targets
preparation.

Returns:
A boolean list for whether the corresponding target in the output list
should be skipped during loss calculation.


def verify_tensor_all_finite_v2(x, message, name=None):
    with ops.name_scope(name, 'VerifyFinite', [x]) as name:
        x = ops.convert_to_tensor(x, name='x')
        with ops.colocate_with(x):
            verify_input = array_ops.check_numerics(x, message=message)
            out = control_flow_ops.with_dependencies([verify_input], x)
    return out

Assert that the tensor does not contain any NaN's or Inf's.

>>> @tf.function
... def f(x):
...   x = tf.debugging.assert_all_finite(x, 'Input x must be all finite')
...   return x + 1

>>> f(tf.constant([np.inf, 1, 2]))
Traceback (most recent call last):
...
InvalidArgumentError: ...

Args:
x: Tensor to check.
message: Message to log on failure.
name: A name for this operation (optional).

Returns:
Same tensor as `x`.


def analyse(self, path_and_filename, pattern):
    with open(path_and_filename) as handle:
        content = handle.read()
        loc = (content.count('\n') + 1)
        com = 0
        for match in re.findall(pattern, content, re.DOTALL):
            com += (match.count('\n') + 1)
        return (max(0, (loc - com)), com)

Find out lines of code and lines of comments.

Args:
path_and_filename (str): path and filename to parse  for loc and com.
pattern (str): regex to search for line commens and block comments

Returns:
int, int: loc and com for given file.


def _ScanEncryptedVolumeNode(self, scan_context, scan_node):

    if scan_node.type_indicator == definitions.TYPE_INDICATOR_APFS_CONTAINER:

      container_file_entry = resolver.Resolver.OpenFileEntry(
          scan_node.path_spec, resolver_context=self._resolver_context)
      fsapfs_volume = container_file_entry.GetAPFSVolume()

      try:
        is_locked = not apfs_helper.APFSUnlockVolume(
            fsapfs_volume, scan_node.path_spec, resolver.Resolver.key_chain)
      except IOError as exception:
        raise errors.BackEndError(
            'Unable to unlock APFS volume with error: {0!s}'.format(exception))

    else:
      file_object = resolver.Resolver.OpenFileObject(
          scan_node.path_spec, resolver_context=self._resolver_context)
      is_locked = not file_object or file_object.is_locked
      file_object.close()

    if is_locked:
      scan_context.LockScanNode(scan_node.path_spec)

      if scan_node.type_indicator == definitions.TYPE_INDICATOR_BDE:
        path_spec = self.ScanForFileSystem(scan_node.path_spec.parent)
        if path_spec:
          scan_context.AddScanNode(path_spec, scan_node.parent_node)

Scans an encrypted volume node for supported formats.

Args:
scan_context (SourceScannerContext): source scanner context.
scan_node (SourceScanNode): source scan node.

Raises:
BackEndError: if the scan node cannot be unlocked.
ValueError: if the scan context or scan node is invalid.


def incident(self, name, **kwargs):
    group_obj = Incident(name, **kwargs)
    return self._group(group_obj)

Add Incident data to Batch object.

Args:
name (str): The name for this Group.
date_added (str, kwargs): The date timestamp the Indicator was created.
event_date (str, kwargs): The event datetime expression for this Group.
status (str, kwargs): The status for this Group.
xid (str, kwargs): The external id for this Group.

Returns:
obj: An instance of Incident.


def dd2dms(dd):
    (m, s) = divmod((dd * 3600), 60)
    (d, m) = divmod(m, 60)
    return (int(d), int(m), s)

Decimal degrees to DMS.

Args:
dd (float). Decimal degrees.

Return:
tuple. Degrees, minutes, and seconds.


def parse(source, segmenter='nlapi', language=None, max_length=None, classname=None, attributes=None, **kwargs):
    parser = get_parser(segmenter, **kwargs)
    return parser.parse(source, language=language, max_length=max_length, classname=classname, attributes=attributes)

Parses input source.

Args:
source (str): Input source to process.
segmenter (:obj:`str`, optional): Segmenter to use [default: nlapi].
language (:obj:`str`, optional): Language code.
max_length (:obj:`int`, optional): Maximum length of a chunk.
classname (:obj:`str`, optional): Class name of output SPAN tags.
attributes (:obj:`dict`, optional): Attributes for output SPAN tags.

Returns:
Results in a dict. :code:`chunks` holds a list of chunks
(:obj:`budou.chunk.ChunkList`) and :code:`html_code` holds the output HTML
code.


def get_absolute_name(prefix, relative_name):
    path = prefix.split('.') if prefix else []
    name = relative_name.lstrip('.')
    ndots = len(relative_name) - len(name)
    if ndots > len(path):
        return None
    prefix = ''.join([p + '.' for p in path[:len(path) + 1 - ndots]])
    return prefix + name

Joins a dotted-name prefix and a relative name.

Args:
prefix: A dotted name, e.g. foo.bar.baz
relative_name: A dotted name with possibly some leading dots, e.g. ..x.y

Returns:
The relative name appended to the prefix, after going up one level for each
leading dot.
e.g. foo.bar.baz + ..hello.world -> foo.bar.hello.world
None if the relative name has too many leading dots.


def parse_charset(header_string):
    match = re.search('charset[ ]?=[ ]?["\']?([a-z0-9_-]+)', header_string, re.IGNORECASE)
    if match:
        return match.group(1)

Parse a "Content-Type" string for the document encoding.

Returns:
str, None


def load(self, context):

    try:

      import tensorflow
    except ImportError:
      return

    from tensorboard.plugins.interactive_inference.interactive_inference_plugin import InteractiveInferencePlugin
    return InteractiveInferencePlugin(context)

Returns the plugin, if possible.

Args:
context: The TBContext flags.

Returns:
A InteractiveInferencePlugin instance or None if it couldn't be loaded.


def list_as_sub(access_token, subscription_id):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/providers/Microsoft.Compute/availabilitySets',
                        '?api-version=', COMP_API])
    return do_get_next(endpoint, access_token)

List availability sets in a subscription.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.

Returns:
HTTP response. JSON body of the list of availability set properties.


def _read_protocol_line(self):
    while True:
        line = self._proc.stdout.readline().decode('utf-8')
        if not line:
            raise jsonrpc_client_base.AppStartError(self._ad, 'Unexpected EOF waiting for app to start')
        line = line.strip()
        if line.startswith('INSTRUMENTATION_RESULT:') or line.startswith('SNIPPET '):
            self.log.debug('Accepted line from instrumentation output: "%s"', line)
            return line
        self.log.debug('Discarded line from instrumentation output: "%s"', line)

Reads the next line of instrumentation output relevant to snippets.

This method will skip over lines that don't start with 'SNIPPET' or
'INSTRUMENTATION_RESULT'.

Returns:
(str) Next line of snippet-related instrumentation output, stripped.

Raises:
jsonrpc_client_base.AppStartError: If EOF is reached without any
protocol lines being read.


def _to_int(operand: List[WorkSpaceMessage]) -> Optional[int]:
    if not operand:
        return None
    if len(operand) > 1:
        raise ValueError('Expected single int result but got multiple items.')
    if not fhir_types.is_integer(operand[0].message):
        raise ValueError('Expected single int but got a non-int value.')
    return proto_utils.get_value_at_field(operand[0].message, 'value')

Converts an evaluation result to an int value or None.

Args:
operand: an expression operand result to convert to int.

Returns:
the int value, or None if the operand was empty.

Raises:
ValueError if it is not an empty result or a single, int value.


def processor_groups(mesh_shape, group_dims):

  group_numbers = [
      pnum_to_group(mesh_shape, group_dims, pnum)
      for pnum in xrange(mesh_shape.size)]
  ret = []
  for pnum, g in enumerate(group_numbers):
    while len(ret) <= g:
      ret.append([])
    ret[g].append(pnum)
  return ret

Groups of processors which differ only in the given dimensions.

Args:
mesh_shape: a Shape
group_dims: a list of integers

Returns:
a list of lists of integers (processor numbers)


def security(self, domains):

        api_name = 'opendns-security'
        fmt_url_path = u'security/name/{0}.json'
        return self._multi_get(api_name, fmt_url_path, domains)

Calls security end point and adds an 'is_suspicious' key to each response.

Args:
domains: An enumerable of strings
Returns:
A dict of {domain: security_result}


def add_hgnc_id(self, genes):

        genes_by_alias = self.genes_by_alias()

        for gene in genes:
            id_info = genes_by_alias.get(gene['hgnc_symbol'])
            if not id_info:
                LOG.warning("Gene %s does not exist in scout", gene['hgnc_symbol'])
                continue
            gene['hgnc_id'] = id_info['true']
            if not id_info['true']:
                if len(id_info['ids']) > 1:
                    LOG.warning("Gene %s has ambiguous value, please choose one hgnc id in result", gene['hgnc_symbol'])
                gene['hgnc_id'] = ','.join([str(hgnc_id) for hgnc_id in id_info['ids']])

Add the correct hgnc id to a set of genes with hgnc symbols

Args:
genes(list(dict)): A set of genes with hgnc symbols only


def export_outputs_for_mode(mode, serving_export_outputs=None, predictions=None, loss=None, metrics=None):
    if mode not in SIGNATURE_KEY_MAP:
        raise ValueError('Export output type not found for mode: {}. Expected one of: {}.\n'.format(mode, SIGNATURE_KEY_MAP.keys()))
    signature_key = SIGNATURE_KEY_MAP[mode]
    if mode_keys.is_predict(mode):
        return get_export_outputs(serving_export_outputs, predictions)
    elif mode_keys.is_train(mode):
        return {signature_key: export_output_lib.TrainOutput(loss=loss, predictions=predictions, metrics=metrics)}
    else:
        return {signature_key: export_output_lib.EvalOutput(loss=loss, predictions=predictions, metrics=metrics)}

Util function for constructing a `ExportOutput` dict given a mode.

The returned dict can be directly passed to `build_all_signature_defs` helper
function as the `export_outputs` argument, used for generating a SignatureDef
map.

Args:
mode: A `ModeKeys` specifying the mode.
serving_export_outputs: Describes the output signatures to be exported to
`SavedModel` and used during serving. Should be a dict or None.
predictions: A dict of Tensors or single Tensor representing model
predictions. This argument is only used if serving_export_outputs is not
set.
loss: A dict of Tensors or single Tensor representing calculated loss.
metrics: A dict of (metric_value, update_op) tuples, or a single tuple.
metric_value must be a Tensor, and update_op must be a Tensor or Op

Returns:
Dictionary mapping the key to an `ExportOutput` object.
The key is the expected SignatureDef key for the mode.

Raises:
ValueError: if an appropriate ExportOutput cannot be found for the mode.


def _make_headers(self, method, path, query={}, headers={}):
    date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
    nonce = self._make_nonce()
    ctype = (headers.get('Content-Type') if headers.get('Content-Type') else 'application/json')
    auth = self._make_auth(method, date, nonce, path, query=query, ctype=ctype)
    req_headers = {'Content-Type': 'application/json', 'Date': date, 'On-Nonce': nonce, 'Authorization': auth, 'User-Agent': 'Onshape Python Sample App', 'Accept': 'application/json'}
    for h in headers:
        req_headers[h] = headers[h]
    return req_headers

Creates a headers object to sign the request

Args:
- method (str): HTTP method
- path (str): Request path, e.g. /api/documents. No query string
- query (dict, default={}): Query string in key-value format
- headers (dict, default={}): Other headers to pass in

Returns:
- dict: Dictionary containing all headers


def create_dynamic_module(name: Union[str, os.PathLike]) -> None:
    init_hf_modules()
    dynamic_module_path = (Path(HF_MODULES_CACHE) / name).resolve()
    if not dynamic_module_path.parent.exists():
        create_dynamic_module(dynamic_module_path.parent)
    os.makedirs(dynamic_module_path, exist_ok=True)
    init_path = dynamic_module_path / '__init__.py'
    if not init_path.exists():
        init_path.touch()
        importlib.invalidate_caches()

Creates a dynamic module in the cache directory for modules.

Args:
name (`str` or `os.PathLike`):
The name of the dynamic module to create.


def conv_block_internal(conv_fn, inputs, filters, dilation_rates_and_kernel_sizes, first_relu=True, use_elu=False, separabilities=None, **kwargs):
    name = (kwargs.pop('name') if ('name' in kwargs) else None)
    mask = (kwargs.pop('mask') if ('mask' in kwargs) else None)
    use_layer_norm = ('normalizer_fn' not in kwargs)
    norm = kwargs.pop('normalizer_fn', None)
    use_normalizer_fn = (use_layer_norm or norm)
    if use_layer_norm:
        norm = (lambda x, name: layer_norm(x, filters, name=name))
    with tf.variable_scope(name, 'conv_block', [inputs]):
        (cur, counter) = (inputs, (- 1))
        for (dilation_rate, kernel_size) in dilation_rates_and_kernel_sizes:
            counter += 1
            if (first_relu or (counter > 0)):
                cur = (tf.nn.elu(cur) if use_elu else tf.nn.relu(cur))
            if (mask is not None):
                cur *= mask
            if separabilities:
                cur = conv_fn(cur, filters, kernel_size, dilation_rate=dilation_rate, name=('conv_block_%d' % counter), use_bias=(norm is None), separability=separabilities[counter], **kwargs)
            else:
                cur = conv_fn(cur, filters, kernel_size, dilation_rate=dilation_rate, name=('conv_block_%d' % counter), use_bias=(norm is None), **kwargs)
            if use_normalizer_fn:
                cur = norm(cur, name=('conv_block_norm_%d' % counter))
        return cur

A block of convolutions.

Args:
conv_fn: convolution function, e.g. conv or separable_conv.
inputs: a Tensor
filters: an Integer
dilation_rates_and_kernel_sizes: a list of tuples (dilation, (k_w, k_h))
first_relu: whether to do a relu at start (defaults to True)
use_elu: whether to use ELUs instead of ReLUs (defaults to False)
separabilities: list of separability factors (per-layer).
**kwargs: additional arguments (e.g., pooling)

Returns:
a Tensor.


def _ParseStorageMediaImageOptions(self, options):

    self._partitions = getattr(options, 'partitions', None)
    if self._partitions:
      try:
        self._ParseVolumeIdentifiersString(self._partitions, prefix='p')
      except ValueError:
        raise errors.BadConfigOption('Unsupported partitions')

    self._volumes = getattr(options, 'volumes', None)
    if self._volumes:
      try:
        self._ParseVolumeIdentifiersString(self._volumes, prefix='apfs')
      except ValueError:
        raise errors.BadConfigOption('Unsupported volumes')

Parses the storage media image options.

Args:
options (argparse.Namespace): command line arguments.

Raises:
BadConfigOption: if the options are invalid.


def _coefficient_handler_factory(trans_table, parse_func, assertion=(lambda c, ctx: True), ion_type=None, append_first_if_not=None):

    def transition(prev, c, ctx, trans):
        if (prev == _UNDERSCORE):
            _illegal_character(c, ctx, ('Underscore before %s.' % (_chr(c),)))
        return ctx.immediate_transition(trans_table[c](c, ctx))
    return _numeric_handler_factory(_DIGITS, transition, assertion, (_DOT,), parse_func, ion_type=ion_type, append_first_if_not=append_first_if_not)

Generates a handler co-routine which tokenizes a numeric coefficient.

Args:
trans_table (dict): lookup table for the handler for the next component of this numeric token, given the
ordinal of the first character in that component.
parse_func (callable): Called upon ending the numeric value. Accepts the current token value and returns a
thunk that lazily parses the token.
assertion (callable): Accepts the first character's ordinal and the current context. Returns True if this is
a legal start to the component.
ion_type (Optional[IonType]): The type of the value if it were to end on this coefficient.
append_first_if_not (Optional[int]): The ordinal of a character that should not be appended to the token if
it occurs first in this component (e.g. an underscore in many cases).


def SetSourceInformation(self, source_path, source_type, artifact_filters=None, filter_file=None):
    self._artifact_filters = artifact_filters
    self._filter_file = filter_file
    self._source_path = source_path
    self._source_type = self._SOURCE_TYPES.get(source_type, 'UNKNOWN')

Sets the source information.

Args:
source_path (str): path of the source.
source_type (str): source type.
artifact_filters (Optional[list[str]]): names of artifact definitions to
use as filters.
filter_file (Optional[str]): filter file.


def disable_inheritance(path, objectType, copy=True):

    dc = daclConstants()
    objectType = dc.getObjectTypeBit(objectType)
    path = dc.processPath(path, objectType)

    return _set_dacl_inheritance(path, objectType, False, copy, None)

Disable inheritance on an object

Args:
path: The path to the object
objectType: The type of object (FILE, DIRECTORY, REGISTRY)
copy: True will copy the Inherited ACEs to the DACL before disabling inheritance

Returns (dict): A dictionary containing the results

CLI Example:

.. code-block:: bash

salt 'minion-id' win_dacl.disable_inheritance c:\temp directory


def load_chkpt_vars(model_path):
    model_path = get_checkpoint_path(model_path)
    reader = tfv1.train.NewCheckpointReader(model_path)
    var_names = reader.get_variable_to_shape_map().keys()
    result = {}
    for n in var_names:
        result[n] = reader.get_tensor(n)
    return result

Load all variables from a checkpoint to a dict.

Args:
model_path(str): path to a checkpoint.

Returns:
dict: a name:value dict


def adapt(self, all_ouputs: AllOutputs) -> DataPacket:
    adapted = {}
    for (name, recipe) in self.adapting_recipes.items():
        adapted[name] = self._construct(all_ouputs, recipe)
    return adapted

Adapt inputs for the transformer included in the step.

Args:
all_ouputs: Dict of outputs from parent steps. The keys should
match the names of these steps and the values should be their
respective outputs.

Returns:
Dictionary with the same keys as `adapting_recipes` and values
constructed according to the respective recipes.


def connect(cls, usb_handle, **kwargs):

    adb_connection = adb_protocol.AdbConnection.connect(usb_handle, **kwargs)
    return cls(adb_connection)

Connect to the device.

Args:
usb_handle: UsbHandle instance to use.
**kwargs: See AdbConnection.connect for kwargs. Includes rsa_keys, and
auth_timeout_ms.

Returns:
An instance of this class if the device connected successfully.


def adversary_phone_asset(
        self, main_type, sub_type, unique_id, asset_id, action='GET', params=None
    ):

        params = params or {}

        url = '/v2/{}/{}/{}/adversaryAssets/phoneNumbers/{}'.format(
            main_type, sub_type, unique_id, asset_id
        )

        if action == 'GET':
            return self.tcex.session.get(url, params=params)
        if action == 'DELETE':
            return self.tcex.session.delete(url)
        return None

Args:
main_type:
sub_type:
unique_id:
asset_id:
action:
params:

Return:


def _get_json(endpoint, params, referer='scores'):

    h = dict(HEADERS)
    h['referer'] = 'http:
    _get = get(BASE_URL.format(endpoint=endpoint), params=params,
               headers=h)

    _get.raise_for_status()
    return _get.json()

Internal method to streamline our requests / json getting

Args:
endpoint (str): endpoint to be called from the API
params (dict): parameters to be passed to the API

Raises:
HTTPError: if requests hits a status code != 200

Returns:
json (json): json object for selected API call


def add_item_to_sonos_playlist(self, queueable_item, sonos_playlist):

        response, _ = self.music_library._music_lib_search(
            sonos_playlist.item_id, 0, 1)
        update_id = response['UpdateID']

        metadata = to_didl_string(queueable_item)

        self.avTransport.AddURIToSavedQueue([
            ('InstanceID', 0),
            ('UpdateID', update_id),
            ('ObjectID', sonos_playlist.item_id),
            ('EnqueuedURI', queueable_item.resources[0].uri),
            ('EnqueuedURIMetaData', metadata),

            ('AddAtIndex', 4294967295)
        ])

Adds a queueable item to a Sonos' playlist.

Args:
queueable_item (DidlObject): the item to add to the Sonos' playlist
sonos_playlist (DidlPlaylistContainer): the Sonos' playlist to
which the item should be added


def FileEntryExistsByPathSpec(self, path_spec):

    volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec)

    if volume_index is None:
      location = getattr(path_spec, 'location', None)
      return location is not None and location == self.LOCATION_ROOT

    return (
        0 <= volume_index < self._vslvm_volume_group.number_of_logical_volumes)

Determines if a file entry for a path specification exists.

Args:
path_spec (PathSpec): path specification.

Returns:
bool: True if the file entry exists.


def _firestore_api(self):
    if (self._firestore_api_internal is None):
        self._firestore_api_internal = firestore_client.FirestoreClient(credentials=self._credentials)
    return self._firestore_api_internal

Lazy-loading getter GAPIC Firestore API.

Returns:
~.gapic.firestore.v1beta1.firestore_client.FirestoreClient: The
GAPIC client with the credentials of the current client.


def get(self, key, default=None):
    if (key in self.__cli):
        return self.__cli[key]
    if (key in self.__config):
        return self.__config.get(key)
    if (key in self.__defaults):
        return self.__defaults.get(key)
    return default

Get the value for `key`.

Gives priority to command-line overrides.

Args:
key: str, the key to get the value for.

Returns:
object: The value for `key`


async def inspect(self, *, node_id: str) -> Mapping[str, Any]:

        response = await self.docker._query_json(
            "nodes/{node_id}".format(node_id=node_id), method="GET"
        )
        return response

Inspect a node

Args:
node_id: The ID or name of the node


def data_it(db_data, user_type):
    data_type = {'array': list, 'dict': dict, 'entity': dict, 'list': list, 'str': string_types, 'string': string_types}
    if (user_type is None):
        if (db_data is None):
            return True
    elif (user_type.lower() in ['null', 'none']):
        if (db_data is None):
            return True
    elif (user_type.lower() in 'binary'):
        try:
            base64.b64decode(db_data)
            return True
        except Exception:
            return False
    elif (data_type.get(user_type.lower()) is not None):
        if isinstance(db_data, data_type.get(user_type.lower())):
            return True
    return False

Validate data is type.

Args:
db_data (dict|str|list): The data store in Redis.
user_data (str): The user provided data.

Returns:
bool: True if the data passed validation.


def get_asset_url(self, path):
    url = ((self.root_url + '/assets/') + path)
    if (path in self.asset_hash):
        url += ('?' + self.asset_hash[path])
    return url

Get the URL of an asset. If asset hashes are added and one exists for
the path, it will be appended as a query string.

Args:
path (str): Path to the file, relative to your "assets" directory.


def _expand_terms(self, terms):
    ret = {'keywords': list(), 'doc': list(), 'from': None, 'to': None}
    if (not isinstance(terms, dict)):
        stp = SearchTermParser()
        terms = stp.parse(terms, term_join=self.backend._and_join)
    if ('about' in terms):
        ret['doc'].append(terms['about'])
    if ('with' in terms):
        ret['doc'].append(terms['with'])
    if ('in' in terms):
        place_vids = self._expand_place_ids(terms['in'])
        ret['keywords'].append(place_vids)
    if ('by' in terms):
        ret['keywords'].append(terms['by'])
    ret['from'] = terms.get('from', None)
    ret['to'] = terms.get('to', None)
    return ret

Expands partition terms to the appropriate fields.

Args:
terms (dict or str):

Returns:
dict: keys are field names, values are query strings


def check_end_blocks(frame):
    try:
        try:
            module_name = frame.f_globals['__name__']
        except KeyError:
            warnings.warn('Can not get the source of an uknown module. End-of-block syntax check is skipped.', EndSyntaxWarning)
            return
        end
        filename = frame.f_globals.get('__file__', '<unknown>')
        try:
            source = inspect.getsource(sys.modules[module_name])
        except Exception:
            warnings.warn(('Can not get the source of module "%s". End-of-block syntax check is skipped.' % (module_name,)), EndSyntaxWarning)
            return
        end
    finally:
        del frame
    end
    root = ast.parse(source)
    for node in ast.walk(root):
        bodies = get_compound_bodies(node)
        if (not bodies):
            continue
        end
        if (isinstance(node, ast.If) and (len(node.orelse) == 1) and isinstance(node.orelse[0], ast.If)):
            continue
        end
        if (PY2 and isinstance(node, ast.TryFinally) and (len(node.body) == 1) and isinstance(node.body[0], ast.TryExcept)):
            continue
        end
        for body in bodies:
            skip_next = False
            for (i, child) in enumerate(body):
                if skip_next:
                    skip_next = False
                elif is_end_node(child):
                    raise SyntaxError('"end" does not close a block.', [filename, child.lineno, child.col_offset, (source.splitlines()[(child.lineno - 1)] + '\n')])
                elif get_compound_bodies(child):
                    try:
                        ok = is_end_node(body[(i + 1)])
                    except IndexError:
                        ok = False
                    end
                    if (not ok):
                        raise SyntaxError('This block is not closed with "end".', [filename, child.lineno, child.col_offset, (source.splitlines()[(child.lineno - 1)] + '\n')])
                    end
                    skip_next = True
                end
            end
        end
    end

Performs end-block check.

Args:
frame: A frame object of the module to be checked.

Raises:
SyntaxError: If check failed.


def write_info_file(resource, path, dataset_name, original_fname):

  info_path = _get_info_path(path)
  info = _read_info(info_path) or {}
  urls = set(info.get('urls', []) + [resource.url])
  dataset_names = info.get('dataset_names', [])
  if dataset_name:
    dataset_names.append(dataset_name)
  if 'original_fname' in info and info['original_fname'] != original_fname:
    raise AssertionError(
        '`original_fname` "%s" stored in %s does NOT match "%s".' % (
            info['original_fname'], info_path, original_fname))
  info = dict(urls=list(urls), dataset_names=list(set(dataset_names)),
              original_fname=original_fname)
  with py_utils.atomic_write(info_path, 'w') as info_f:
    json.dump(info, info_f, sort_keys=True)

Write the INFO file next to local file.

Although the method is synchronized, there is still a risk two processes
running at the same time overlap here. Risk accepted, since potentially lost
data (`dataset_name`) is only for human consumption.

Args:
resource: resource for which to write the INFO file.
path: path of downloaded file.
dataset_name: data used to dl the file.
original_fname: name of file as downloaded.


def coroutine(func):

    def wrapper(*args, **kwargs):
        gen = func(*args, **kwargs)
        val = next(gen)
        if val != None:
            raise TypeError('Unexpected value from start of coroutine')
        return gen
    wrapper.__name__ = func.__name__
    wrapper.__doc__ = func.__doc__
    return wrapper

Wraps a PEP-342 enhanced generator in a way that avoids boilerplate of the "priming" call to ``next``.

Args:
func (Callable): The function constructing a generator to decorate.

Returns:
Callable: The decorated generator.


def decode_der(cert_der):
    return cryptography.x509.load_der_x509_certificate(data=cert_der, backend=cryptography.hazmat.backends.default_backend())

Decode cert DER string to Certificate object.

Args:
cert_der : Certificate as a DER encoded string

Returns:
cryptography.Certificate()


def register_defs(self, def_list, **kwargs):
    for item in def_list:
        if isinstance(item, tuple):
            self.register_rml_def(*item, **kwargs)
        elif isinstance(item, dict):
            cp_kwargs = kwargs.copy()
            item.update(kwargs)
            self.register_rml_def(**item)

Registers a list of Rml defintions objects

Args:
-----
def_list: list of objects defining the rml definitons


def make_pixel_mask(image: np.ndarray, output_size: Tuple[int, int], input_data_format: Optional[Union[str, ChannelDimension]]=None) -> np.ndarray:
    input_height, input_width = get_image_size(image, channel_dim=input_data_format)
    mask = np.zeros(output_size, dtype=np.int64)
    mask[:input_height, :input_width] = 1
    return mask

Make a pixel mask for the image, where 1 indicates a valid pixel and 0 indicates padding.

Args:
image (`np.ndarray`):
Image to make the pixel mask for.
output_size (`Tuple[int, int]`):
Output size of the mask.


def _handle_unsupported(self, request: dict) -> dict:
    response = {'response': {'shouldEndSession': False, 'outputSpeech': {'type': 'PlainText', 'text': self.config['unsupported_message']}, 'card': {'type': 'Simple', 'content': self.config['unsupported_message']}}}
    response = self._generate_response(response, request)
    return response

Handles all unsupported types of Alexa requests. Returns standard message.

Args:
request: Alexa request.
Returns:
response: "response" part of response dict conforming Alexa specification.


def remove_training_nodes(input_graph, protected_nodes=None):
    if not protected_nodes:
        protected_nodes = []
    types_to_remove = {'CheckNumerics': True}
    input_nodes = input_graph.node
    names_to_remove = {}
    for node in input_nodes:
        if node.op in types_to_remove and node.name not in protected_nodes:
            names_to_remove[node.name] = True
    nodes_after_removal = []
    for node in input_nodes:
        if node.name in names_to_remove:
            continue
        new_node = node_def_pb2.NodeDef()
        new_node.CopyFrom(node)
        input_before_removal = node.input
        del new_node.input[:]
        for full_input_name in input_before_removal:
            input_name = re.sub('^\\^', '', full_input_name)
            if input_name in names_to_remove:
                continue
            new_node.input.append(full_input_name)
        nodes_after_removal.append(new_node)
    types_to_splice = {'Identity': True, 'StopGradient': True}
    control_input_names = set()
    node_names_with_control_input = set()
    node_in_colocated = set()
    for node in nodes_after_removal:
        for node_input in node.input:
            if '^' in node_input:
                control_input_names.add(node_input.replace('^', ''))
                node_names_with_control_input.add(node.name)
        if '_class' in node.attr:
            for colocated_node_name in node.attr['_class'].list.s:
                node_in_colocated.add(_get_colocated_node_name(colocated_node_name))
    names_to_splice = {}
    for node in nodes_after_removal:
        if node.op in types_to_splice and node.name not in protected_nodes:
            if node.name in node_in_colocated:
                continue
            if node.name not in node_names_with_control_input:
                names_to_splice[node.name] = node.input[0]
    names_to_splice = {name: value for name, value in names_to_splice.items() if name not in control_input_names}
    nodes_after_splicing = []
    for node in nodes_after_removal:
        if node.name in names_to_splice:
            continue
        new_node = node_def_pb2.NodeDef()
        new_node.CopyFrom(node)
        input_before_removal = node.input
        del new_node.input[:]
        for full_input_name in input_before_removal:
            input_name = re.sub('^\\^', '', full_input_name)
            while input_name in names_to_splice:
                full_input_name = names_to_splice[input_name]
                input_name = re.sub('^\\^', '', full_input_name)
            new_node.input.append(full_input_name)
        nodes_after_splicing.append(new_node)
    output_graph = graph_pb2.GraphDef()
    output_graph.node.extend(nodes_after_splicing)
    return output_graph

Prunes out nodes that aren't needed for inference.

There are nodes like Identity and CheckNumerics that are only useful
during training, and can be removed in graphs that will be used for
nothing but inference. Here we identify and remove them, returning an
equivalent graph. To be specific, CheckNumerics nodes are always removed, and
Identity nodes that aren't involved in control edges are spliced out so that
their input and outputs are directly connected.

Args:
input_graph: Model to analyze and prune.
protected_nodes: An optional list of names of nodes to be kept
unconditionally. This is for example useful to preserve Identity output
nodes.

Returns:
A list of nodes with the unnecessary ones removed.


def __init__(
      self, hash_queue, hash_analysis_queue, hashes_per_batch=1,
      lookup_hash='sha256', wait_after_analysis=0):

    super(HashAnalyzer, self).__init__()
    self._abort = False
    self._hash_queue = hash_queue
    self._hash_analysis_queue = hash_analysis_queue
    self.analyses_performed = 0
    self.hashes_per_batch = hashes_per_batch
    self.lookup_hash = lookup_hash
    self.seconds_spent_analyzing = 0
    self.wait_after_analysis = wait_after_analysis

Initializes a hash analyzer.

Args:
hash_queue (Queue.queue): contains hashes to be analyzed.
hash_analysis_queue (Queue.queue): queue that the analyzer will append
HashAnalysis objects to.
hashes_per_batch (Optional[int]): number of hashes to analyze at once.
lookup_hash (Optional[str]): name of the hash attribute to look up.
wait_after_analysis (Optional[int]): number of seconds to wait after each
batch is analyzed.


def store(self, df, attribute_columns):
    entity_id_start = (models.Entity.get_max_id(self.session) + 1)
    attribute_id_start = (models.Attribute.get_max_id(self.session) + 1)
    df['id'] = range(entity_id_start, (entity_id_start + len(df)))
    df['type'] = self.type
    df[['id', 'type']].to_sql(name=models.Entity.__tablename__, con=self.client.engine, if_exists='append', index=False)
    for col in attribute_columns:
        attr_df = df[[col, 'id']].rename(columns={'id': 'entity_id', col: 'value'})
        attr_df['name'] = col
        attr_df['id'] = range(attribute_id_start, (attribute_id_start + len(df)))
        attribute_id_start += len(df)
        attr_df.to_sql(name=models.Attribute.__tablename__, con=self.client.engine, if_exists='append', index=False)

Store entities and their attributes

Args:
df (pandas.DataFrame): data to store (storing appends 'id' and 'type' columns!)
attribute_columns (list(str)): list of column labels that define attributes


def compose_q_update_vec(self, q_update_vec: torch.Tensor) -> Rigid:
    q_vec, t_vec = (q_update_vec[..., :3], q_update_vec[..., 3:])
    new_rots = self._rots.compose_q_update_vec(q_vec)
    trans_update = self._rots.apply(t_vec)
    new_translation = self._trans + trans_update
    return Rigid(new_rots, new_translation)

Composes the transformation with a quaternion update vector of shape [*, 6], where the final 6 columns
represent the x, y, and z values of a quaternion of form (1, x, y, z) followed by a 3D translation.

Args:
q_vec: The quaternion update vector.
Returns:
The composed transformation.


def is_par(chromosome, position, build='37'):

    chrom_match = CHR_PATTERN.match(chromosome)
    chrom = chrom_match.group(2)

    if not chrom in ['X','Y']:
        return False

    if PAR_COORDINATES[build][chrom].search(position):
        return True

    return False

Check if a variant is in the Pseudo Autosomal Region or not

Args:
chromosome(str)
position(int)
build(str): The genome build

Returns:
bool


def u(data, bits=None, endian=None, target=None):
    return globals()[('u%d' % _get_bits(bits, target))](data, endian=endian, target=target)

Unpack a signed pointer for a given target.

Args:
data(bytes): The data to unpack.
bits(:class:`pwnypack.target.Target.Bits`): Override the default
word size. If ``None`` it will look at the word size of
``target``.
endian(:class:`~pwnypack.target.Target.Endian`): Override the default
byte order. If ``None``, it will look at the byte order of
the ``target`` argument.
target(:class:`~pwnypack.target.Target`): Override the default byte
order. If ``None``, it will look at the byte order of
the global :data:`~pwnypack.target.target`.

Returns:
int: The pointer value.


def mpr(truth, recommend):

    if len(recommend) == 0 and len(truth) == 0:
        return 0.
    elif len(truth) == 0 or len(truth) == 0:
        return 100.

    accum = 0.
    n_recommend = recommend.size
    for t in truth:
        r = np.where(recommend == t)[0][0] / float(n_recommend)
        accum += r
    return accum * 100. / truth.size

Mean Percentile Rank (MPR).

Args:
truth (numpy 1d array): Set of truth samples.
recommend (numpy 1d array): Ordered set of recommended samples.

Returns:
float: MPR.


def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):

        tstream = BytearrayStream()

        if self.unique_identifier is not None:
            self.unique_identifier.write(tstream, kmip_version=kmip_version)

        self.revocation_reason.write(tstream, kmip_version=kmip_version)

        if self.compromise_occurrence_date is not None:
            self.compromise_occurrence_date.write(
                tstream,
                kmip_version=kmip_version
            )

        self.length = tstream.length()
        super(RevokeRequestPayload, self).write(
            ostream,
            kmip_version=kmip_version
        )
        ostream.write(tstream.buffer)

Write the data encoding the RevokeRequestPayload object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.


def convert(isbn, code='978'):

    isbn = _isbn_cleanse(isbn)
    if len(isbn) == 10:
        isbn = code + isbn[:-1]
        return isbn + calculate_checksum(isbn)
    else:
        if isbn.startswith('978'):
            return isbn[3:-1] + calculate_checksum(isbn[3:-1])
        else:
            raise IsbnError('Only ISBN-13s with 978 Bookland code can be '
                            'converted to ISBN-10.')

Convert ISBNs between ISBN-10 and ISBN-13.

Note:
No attempt to hyphenate converted ISBNs is made, because the
specification requires that *any* hyphenation must be correct but
allows ISBNs without hyphenation.

Args:
isbn (str): SBN, ISBN-10 or ISBN-13
code (str): EAN Bookland code

Returns:
``str``: Converted ISBN-10 or ISBN-13

Raise:
IsbnError: When ISBN-13 isn't convertible to an ISBN-10


def jpeg_compression(x, severity=1):
    c = [25, 18, 15, 10, 7][(severity - 1)]
    x = tfds.core.lazy_imports.PIL_Image.fromarray(x.astype(np.uint8))
    output = io.BytesIO()
    x.save(output, 'JPEG', quality=c)
    output.seek(0)
    x = tfds.core.lazy_imports.PIL_Image.open(output)
    return np.asarray(x)

Conduct jpeg compression to images.

Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.

Returns:
numpy array, image with uint8 pixels in [0,255]. Applied jpeg compression.


def get_snapshots(self, domains=None):

        snapshots = {}
        for vm_name, vm in self.get_vms().items():
            if domains and vm_name not in domains:
                continue

            snapshots[vm_name] = vm._spec['snapshots']

        return snapshots

Get the list of snapshots for each domain
Args:
domanins(list of str): list of the domains to get the snapshots
for, all will be returned if none or empty list passed
Returns:
dict of str -> list(str): with the domain names and the list of
snapshots for each


def create_normal_matrix(self, modelview):

        normal_m = Matrix33.from_matrix44(modelview)
        normal_m = normal_m.inverse
        normal_m = normal_m.transpose()
        return normal_m

Creates a normal matrix from modelview matrix

Args:
modelview: The modelview matrix

Returns:
A 3x3 Normal matrix as a :py:class:`numpy.array`


def abort(code, error=None, message=None):

    if error is None:
        flask_abort(code)
    elif isinstance(error, Response):
        error.status_code = code
        flask_abort(code, response=error)
    else:
        body = {
            "status": code,
            "error": error,
            "message": message
        }
        flask_abort(code, response=export(body, code))

Abort with suitable error response

Args:
code (int): status code
error (str): error symbol or flask.Response
message (str): error message


def forward_ports(remote_host, local_host, local_listen_ports, remote_listen_ports):
    if ((':' in local_host) and (not local_host.startswith('['))):
        local_host = ('[%s]' % local_host)
    ssh = (whichcraft.which('ssh') or whichcraft.which('plink'))
    if (not ssh):
        raise ValueError("Couldn't find an ssh client.")
    args = [ssh, remote_host]
    for local_port in local_listen_ports:
        args += ['-L', ('%s:%s:%s:%s' % (local_host, local_port, local_host, local_port))]
    for remote_port in remote_listen_ports:
        args += ['-R', ('%s:%s:%s:%s' % (local_host, remote_port, local_host, remote_port))]
    logging.info('SSH port forwarding: %s', ' '.join(args))
    return subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, close_fds=(os.name == 'posix'))

Forwards ports such that multiplayer works between machines.

Args:
remote_host: Where to ssh to.
local_host: "127.0.0.1" or "::1".
local_listen_ports: Which ports to listen on locally to forward remotely.
remote_listen_ports: Which ports to listen on remotely to forward locally.

Returns:
The ssh process.

Raises:
ValueError: if it can't find ssh.


def _decode_byte(byte):

    bits = []
    for _ in range(8):
        bits.append(byte & 1)
        byte >>= 1
    return bits

Helper for decode_qp, turns a single byte into a list of bits.

Args:
byte: byte to be decoded

Returns:
list of bits corresponding to byte


def _FormatDataToken(self, token_data):
    format_string = bsmtoken.BSM_TOKEN_DATA_PRINT.get(token_data.data_format, 'UNKNOWN')
    if (token_data.data_format == 4):
        data = bytes(bytearray(token_data.data)).split(b'\x00')[0]
        data = data.decode('utf-8')
    else:
        data = ''.join(['{0:02x}'.format(byte) for byte in token_data.data])
    return {'format': format_string, 'data': data}

Formats a data token as a dictionary of values.

Args:
token_data (bsm_token_data_data): AUT_DATA token data.

Returns:
dict[str, str]: token values.


def Expand(self, macro_ref_str):

    match = _MACRO_RE.match(macro_ref_str)
    if match is None or match.group(0) != macro_ref_str:
      raise PDDMError('Failed to parse macro reference: "%s"' % macro_ref_str)
    if match.group('name') not in self._macros:
      raise PDDMError('No macro named "%s".' % match.group('name'))
    return self._Expand(match, [], macro_ref_str)

Expands the macro reference.

Args:
macro_ref_str: String of a macro reference (i.e. foo(a, b)).

Returns:
The text from the expansion.

Raises:
PDDMError if there are any issues.


def project(self, term, **kwargs):

        params = kwargs
        baseuri = self._BASE_URI + 'projects/' + term
        res = self.session.get(baseuri, params=params)
        self.handle_http_error(res)
        return res

Search for a project by id.

Args:
term (str): Term to search for.
kwargs (dict): additional keywords passed into
requests.session.get params keyword.


def upgrade(self, dependencies=False, prerelease=False, force=False):

        pip_args = ['install', self.pkg]

        found = self._get_current() != (-1)
        if found:
            pip_args.append("--upgrade")

        if force:
            pip_args.append(
                "--force-reinstall" if found else "--ignore-installed")

        if not dependencies:
            pip_args.append("--no-deps")

        if prerelease:
            pip_args.append("--pre")

        proxy = os.environ.get('http_proxy')
        if proxy:
            pip_args.extend(['--proxy', proxy])

        if self.__index:
            pip_args.extend(['-i', self.index])

        try:
            ecode = pip.main(args=pip_args)
        except TypeError:

            ecode = pip.main(initial_args=pip_args)

        if ecode != 0:
            raise PIPError(ecode)

Upgrade the package unconditionaly
Args:
dependencies: update package dependencies if True (see pip --no-deps)
prerelease: update to pre-release and development versions
force: reinstall all packages even if they are already up-to-date
Returns True if pip was sucessful