def parse_fatcat(fatcat_xml):

    fatcat_results = {}

    with open(fatcat_xml, 'r') as f:
        soup = BeautifulSoup(f, 'lxml')

    if soup.find('block'):
        fatcat_results['tm_score'] = float(soup.find('afpchain')['tmscore'])

    return fatcat_results

Parse a FATCAT XML result file.

Args:
fatcat_xml (str): Path to FATCAT XML result file

Returns:
dict: Parsed information from the output

Todo:
- Only returning TM-score at the moment


def _log_progress(self, bytes_downloaded):
    self._total_bytes_downloaded += bytes_downloaded
    now = time.time()
    if (self._interactive_mode() or ((now - self._last_progress_msg_print_time) > 15)):
        self._print_download_progress_msg(('Downloading %s: %s' % (self._url, tf_utils.bytes_to_readable_str(self._total_bytes_downloaded, True))))
        self._last_progress_msg_print_time = now

Logs progress information about ongoing module download.

Args:
bytes_downloaded: Number of bytes downloaded.


def InsertData(self, table_id, fd, schema, job_id):

    configuration = {
        "schema": {
            "fields": schema
        },
        "destinationTable": {
            "projectId": self.project_id,
            "tableId": table_id,
            "datasetId": self.dataset_id
        },
        "sourceFormat": "NEWLINE_DELIMITED_JSON",
    }

    body = {
        "configuration": {
            "load": configuration
        },
        "jobReference": {
            "projectId": self.project_id,
            "jobId": job_id
        }
    }

    mediafile = http.MediaFileUpload(
        fd.name, mimetype="application/octet-stream")
    job = self.service.jobs().insert(
        projectId=self.project_id, body=body, media_body=mediafile)
    try:
      response = job.execute()
      return response
    except errors.HttpError as e:
      if self.GetDataset(self.dataset_id):
        logging.exception("Error with job: %s", job_id)
      else:

        logging.info("Attempting to create dataset: %s", self.dataset_id)
        self.CreateDataset()
      return self.RetryUpload(job, job_id, e)

Insert data into a bigquery table.

If the table specified doesn't exist, it will be created with the specified
schema.

Args:
table_id: string table id
fd: open file descriptor containing the newline separated JSON
schema: BigQuery schema dict
job_id: string job id

Returns:
API response object on success, None on failure


def _obtain_sampled_health_pills(self, run, node_names):

    runs_to_tags_to_content = self._event_multiplexer.PluginRunToTagToContent(
        constants.DEBUGGER_PLUGIN_NAME)

    if run not in runs_to_tags_to_content:

      return {}

    tags_to_content = runs_to_tags_to_content[run]

    mapping = {}
    for node_name in node_names:
      if node_name not in tags_to_content:

        continue

      health_pills = []
      for tensor_event in self._event_multiplexer.Tensors(run, node_name):
        json_string = tags_to_content[node_name]
        try:
          content_object = json.loads(tf.compat.as_text(json_string))
          device_name = content_object['device']
          output_slot = content_object['outputSlot']
          health_pills.append(
              self._tensor_proto_to_health_pill(tensor_event, node_name,
                                                device_name, output_slot))
        except (KeyError, ValueError) as e:
          logger.error('Could not determine device from JSON string '
                           '%r: %r', json_string, e)

      mapping[node_name] = health_pills

    return mapping

Obtains the health pills for a run sampled by the event multiplexer.

This is much faster than the alternative path of reading health pills from
disk.

Args:
run: The run to fetch health pills for.
node_names: A list of node names for which to retrieve health pills.

Returns:
A dictionary mapping from node name to a list of
event_accumulator.HealthPillEvents.


def buid(valu=None):
    if (valu is None):
        return os.urandom(32)
    byts = s_msgpack.en(valu)
    return hashlib.sha256(byts).digest()

A binary GUID like sequence of 32 bytes.

Args:
valu (object): Optional, if provided, the hash of the msgpack
encoded form of the object is returned. This can be used to
create stable buids.

Notes:
By default, this returns a random 32 byte value.

Returns:
bytes: A 32 byte value.


def __setstate__(self, state):

    self._api = state['api']
    self._path = state['path']
    self.name = api_utils._unquote_filename(self._path)
    self._buffer_size = state['buffer_size']
    self._max_request_size = state['request_size']
    self._etag = state['etag']
    self._file_size = state['size']
    self._offset = state['offset']
    self._buffer = _Buffer()
    self.closed = state['closed']
    self._buffer_future = None
    if self._remaining() and not self.closed:
      self._request_next_buffer()

Restore state as part of deserialization/unpickling.

Args:
state: the dictionary from a __getstate__ call

Along with restoring the state, pre-fetch the next read buffer.


def upload(cls, file_obj, store=None):
    if (store is None):
        store = 'auto'
    elif store:
        store = '1'
    else:
        store = '0'
    data = {'UPLOADCARE_STORE': store}
    files = uploading_request('POST', 'base/', data=data, files={'file': file_obj})
    file_ = cls(files['file'])
    return file_

Uploads a file and returns ``File`` instance.

Args:
- file_obj: file object to upload to
- store (Optional[bool]): Should the file be automatically stored
upon upload. Defaults to None.
- False - do not store file
- True - store file (can result in error if autostore
is disabled for project)
- None - use project settings

Returns:
``File`` instance


def add(self, pattern_txt):

        self.patterns[len(pattern_txt)] = pattern_txt

        low = 0
        high = len(pattern_txt) - 1

        while not pattern_txt[low]:
            low += 1

        while not pattern_txt[high]:
            high -= 1

        min_pattern = pattern_txt[low:high + 1]
        self.min_patterns[len(min_pattern)] = min_pattern

Add a pattern to the list.

Args:
pattern_txt (str list): the pattern, as a list of lines.


def config_get(config, *path, default=None):
    o = object()
    result = get_in(config, path, default=o)
    if (result is not o):
        return result
    else:
        return default

Get a configuration option following a path through the config

Example usage:

>>> config_get(config,
'problem', 'problem_type_details', 'scorer',
default='accuracy')

Args:
config (dict): config dict
*path (list[str]): List of config sections and options to follow.
default (default=None): A default value to return in the case that
the option does not exist.


def list_locations(access_token, subscription_id):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/locations?api-version=', BASE_API])
    return do_get(endpoint, access_token)

List available locations for a subscription.

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

Returns:
HTTP response. JSON list of locations.


def _handle_response(self, response, valid_status_codes, resource):

        if response.status_code not in valid_status_codes:
            raise InvalidStatusCodeError(
                status_code=response.status_code,
                expected_status_codes=valid_status_codes
                )
        if response.content:
            data = response.json()
            if isinstance(data, list):

                return [resource(**x) for x in data]
            else:

                key = getattr(resource.Meta, 'pagination_key', None)
                if isinstance(data.get(key), list):

                    return [resource(**x) for x in data.get(key)]
                else:

                    return [resource(**data)]
        return []

Handles Response objects

Args:
response: An HTTP reponse object
valid_status_codes: A tuple list of valid status codes
resource: The resource class to build from this response

returns:
resources: A list of Resource instances


def dismiss_prompt(self, text=None, wait=None):
    with self.driver.dismiss_modal('prompt', text=text, wait=wait):
        (yield)

Execute the wrapped code, dismissing a prompt.

Args:
text (str | RegexObject, optional): Text to match against the text in the modal.
wait (int | float, optional): Maximum time to wait for the modal to appear after
executing the wrapped code.

Raises:
ModalNotFound: If a modal dialog hasn't been found.


def set_forced_variation(self, experiment_key, user_id, variation_key):
    experiment = self.get_experiment_from_key(experiment_key)
    if (not experiment):
        return False
    experiment_id = experiment.id
    if (variation_key is None):
        if (user_id in self.forced_variation_map):
            experiment_to_variation_map = self.forced_variation_map.get(user_id)
            if (experiment_id in experiment_to_variation_map):
                del self.forced_variation_map[user_id][experiment_id]
                self.logger.debug(('Variation mapped to experiment "%s" has been removed for user "%s".' % (experiment_key, user_id)))
            else:
                self.logger.debug(('Nothing to remove. Variation mapped to experiment "%s" for user "%s" does not exist.' % (experiment_key, user_id)))
        else:
            self.logger.debug(('Nothing to remove. User "%s" does not exist in the forced variation map.' % user_id))
        return True
    if (not validator.is_non_empty_string(variation_key)):
        self.logger.debug('Variation key is invalid.')
        return False
    forced_variation = self.get_variation_from_key(experiment_key, variation_key)
    if (not forced_variation):
        return False
    variation_id = forced_variation.id
    if (user_id not in self.forced_variation_map):
        self.forced_variation_map[user_id] = {experiment_id: variation_id}
    else:
        self.forced_variation_map[user_id][experiment_id] = variation_id
    self.logger.debug(('Set variation "%s" for experiment "%s" and user "%s" in the forced variation map.' % (variation_id, experiment_id, user_id)))
    return True

Sets users to a map of experiments to forced variations.

Args:
experiment_key: Key for experiment.
user_id: The user ID.
variation_key: Key for variation. If None, then clear the existing experiment-to-variation mapping.

Returns:
A boolean value that indicates if the set completed successfully.


def table_delete(self, table_name):

    url = Api._ENDPOINT + (Api._TABLES_PATH % table_name)
    return datalab.utils.Http.request(url, method='DELETE', credentials=self._credentials,
                                      raw_response=True)

Issues a request to delete a table.

Args:
table_name: the name of the table as a tuple of components.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.


def GetEventFormatter(self, event):

    data_type = getattr(event, 'data_type', None)
    if not data_type:
      return None

    return formatters_manager.FormattersManager.GetFormatterObject(
        event.data_type)

Retrieves the event formatter for a specific event type.

Args:
event (EventObject): event.

Returns:
EventFormatter: event formatter or None.


def debug(msg: str, *args, **kwargs) -> None:
    _DEFAULT_LOGGER.debug(msg, *args, **kwargs)

Logs debug message.

Args:
msg: Message with possible format string.
*args: Values for variables in the format string.
**kwargs: Keyword arguments for the logger.


def _fire_event(self, event_name, *event_args, **event_kwargs):
    if (event_name in self._allowed_events):
        self._logger.debug('firing handlers for event %s ', event_name)
        for (func, args, kwargs) in self._event_handlers[event_name]:
            kwargs.update(event_kwargs)
            func(self, *(event_args + args), **kwargs)

Execute all the handlers associated with given event.

This method executes all handlers associated with the event
`event_name`. Optional positional and keyword arguments can be used to
pass arguments to **all** handlers added with this event. These
aguments updates arguments passed using :meth:`~ignite.engine.Engine.add_event_handler`.

Args:
event_name: event for which the handlers should be executed. Valid
events are from :class:`~ignite.engine.Events` or any `event_name` added by
:meth:`~ignite.engine.Engine.register_events`.
*event_args: optional args to be passed to all handlers.
**event_kwargs: optional keyword args to be passed to all handlers.


def from_object(cls, obj):

        return cls(
            obj.get('sessionId', None),
            obj.get('status', 0),
            obj.get('value', None)
        )

The factory method to create WebDriverResult from JSON Object.

Args:
obj(dict): The JSON Object returned by server.


class Owlv2Encoder(nn.Module):

    def __init__(self, config: Owlv2Config):
        super().__init__()
        self.layers = nn.ModuleList([Owlv2EncoderLayer(config) for _ in range(config.num_hidden_layers)])
        self.gradient_checkpointing = False

    def forward(self, inputs_embeds, attention_mask: Optional[torch.Tensor]=None, causal_attention_mask: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None) -> Union[Tuple, BaseModelOutput]:

        output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
        output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        return_dict = return_dict if return_dict is not None else self.config.use_return_dict
        encoder_states = () if output_hidden_states else None
        all_attentions = () if output_attentions else None
        hidden_states = inputs_embeds
        for encoder_layer in self.layers:
            if output_hidden_states:
                encoder_states = encoder_states + (hidden_states,)
            if self.gradient_checkpointing and self.training:
                layer_outputs = self._gradient_checkpointing_func(encoder_layer.__call__, hidden_states, attention_mask, causal_attention_mask, output_attentions)
            else:
                layer_outputs = encoder_layer(hidden_states, attention_mask, causal_attention_mask, output_attentions=output_attentions)
            hidden_states = layer_outputs[0]
            if output_attentions:
                all_attentions = all_attentions + (layer_outputs[1],)
        if output_hidden_states:
            encoder_states = encoder_states + (hidden_states,)
        if not return_dict:
            return tuple((v for v in [hidden_states, encoder_states, all_attentions] if v is not None))
        return BaseModelOutput(last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions)

Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`Owlv2EncoderLayer`].

Args:
config: Owlv2Config


def _checkResponseByteCount(payload):
    POSITION_FOR_GIVEN_NUMBER = 0
    NUMBER_OF_BYTES_TO_SKIP = 1
    _checkString(payload, minlength=1, description='payload')
    givenNumberOfDatabytes = ord(payload[POSITION_FOR_GIVEN_NUMBER])
    countedNumberOfDatabytes = (len(payload) - NUMBER_OF_BYTES_TO_SKIP)
    if (givenNumberOfDatabytes != countedNumberOfDatabytes):
        errortemplate = ('Wrong given number of bytes in the response: {0}, but counted is {1} as data payload length is {2}.' + ' The data payload is: {3!r}')
        errortext = errortemplate.format(givenNumberOfDatabytes, countedNumberOfDatabytes, len(payload), payload)
        raise ValueError(errortext)

Check that the number of bytes as given in the response is correct.

The first byte in the payload indicates the length of the payload (first byte not counted).

Args:
payload (string): The payload

Raises:
TypeError, ValueError


def _apply_shadow_vars(avg_grads):
    ps_var_grads = []
    for (grad, var) in avg_grads:
        assert var.name.startswith('tower'), var.name
        my_name = '/'.join(var.name.split('/')[1:])
        my_name = get_op_tensor_name(my_name)[0]
        new_v = tf.get_variable(my_name, dtype=var.dtype.base_dtype, initializer=var.initial_value, trainable=True)
        ps_var_grads.append((grad, new_v))
    return ps_var_grads

Create shadow variables on PS, and replace variables in avg_grads
by these shadow variables.

Args:
avg_grads: list of (grad, var) tuples


def run_cuda_only(func: _F) -> _F:
    if tf_inspect.isclass(func):
        raise ValueError('`run_cuda_only` only supports test methods.')

    def decorated(self: 'TensorFlowTestCase', *args, **kwargs):
        if not is_gpu_available(cuda_only=True):
            self.skipTest('Test requires CUDA GPU')
        return func(self, *args, **kwargs)
    return decorated

Execute the decorated test only if a GPU is available.

This function is intended to be applied to tests that require the presence
of a CUDA GPU. If a CUDA GPU is absent, it will simply be skipped.

Args:
func: function to be annotated.

Returns:
Returns a function that will conditionally skip the decorated test method.


def _head(self, client_kwargs):

        with _handle_client_error():

            if 'Key' in client_kwargs:
                header = self.client.head_object(**client_kwargs)

            else:
                header = self.client.head_bucket(**client_kwargs)

        for key in ('AcceptRanges', 'ResponseMetadata'):
            header.pop(key, None)
        return header

Returns object or bucket HTTP header.

Args:
client_kwargs (dict): Client arguments.

Returns:
dict: HTTP header.


def constant(cls,
            value: Value,
            dtype: tf.DType = tf.float32) -> 'TensorFluent':

        t = tf.constant(value, dtype=dtype)
        scope = []
        batch = False
        return TensorFluent(t, scope, batch=batch)

Returns a constant `value` TensorFluent with given `dtype`.

Args:
value: The constant value.
dtype: The output's data type.

Returns:
A constant TensorFluent.


def __init__(self,
               flush_size_chars=_FILE_POOL_FLUSH_SIZE,
               ctx=None,
               exclusive=False):

    self._flush_size = flush_size_chars
    self._buffer = []
    self._size = 0
    self._ctx = ctx
    self._exclusive = exclusive

Constructor.

Any classes that subclass this will need to implement the _write() function.

Args:
flush_size_chars: buffer flush threshold as int.
ctx: mapreduce context as context.Context.
exclusive: a boolean flag indicating if the pool has an exclusive
access to the file. If it is True, then it's possible to write
bigger chunks of data.


def global_pool_1d(inputs, pooling_type='MAX', mask=None):
    with tf.name_scope('global_pool', values=[inputs]):
        if (mask is not None):
            mask = tf.expand_dims(mask, axis=2)
            inputs = tf.multiply(inputs, mask)
        if (pooling_type == 'MAX'):
            output = tf.reduce_max(inputs, axis=1)
        elif (pooling_type == 'AVR'):
            if (mask is not None):
                output = tf.reduce_sum(inputs, axis=1)
                num_elems = tf.reduce_sum(mask, axis=1, keepdims=True)
                output = tf.div(output, tf.maximum(num_elems, 1))
            else:
                output = tf.reduce_mean(inputs, axis=1)
    return output

Pool elements across the last dimension.

Useful to convert a list of vectors into a single vector so as
to get a representation of a set.

Args:
inputs: A tensor of shape [batch_size, sequence_length, input_dims]
containing the sequences of input vectors.
pooling_type: the pooling type to use, MAX or AVR
mask: A tensor of shape [batch_size, sequence_length] containing a
mask for the inputs with 1's for existing elements, and 0's elsewhere.

Returns:
A tensor of shape [batch_size, input_dims] containing the sequences of
transformed vectors.


def __init__(self, while_definition):

        logger.debug("starting")

        if isinstance(while_definition, dict):

            self.error_on_max = while_definition.get('errorOnMax', False)

            self.max = while_definition.get('max', None)

            self.sleep = while_definition.get('sleep', 0)

            self.stop = while_definition.get('stop', None)

            if self.stop is None and self.max is None:
                logger.error(f"while decorator missing both max and stop.")
                raise PipelineDefinitionError("the while decorator must have "
                                              "either max or stop, or both. "
                                              "But not neither. Note that "
                                              "setting stop: False with no "
                                              "max is an infinite loop. If "
                                              "an infinite loop is really "
                                              "what you want, set stop: False")
        else:

            logger.error(f"while decorator definition incorrect.")
            raise PipelineDefinitionError("while decorator must be a dict "
                                          "(i.e a map) type.")

        logger.debug("done")

Initialize the class. No duh, huh.

You can happily expect the initializer to initialize all
member attributes.

Args:
while_definition: dict. This is the actual while definition as it
exists in the pipeline yaml.


def sub(x1, x2, output_shape=None, name=None):
    output_shape = convert_to_shape(output_shape)
    if (not isinstance(x2, Tensor)):
        return ScalarAddOperation(x1, (- x2)).outputs[0]
    with tf.name_scope(name, default_name='sub'):
        (x1, x2) = binary_arguments_to_tensors(x1, x2)
        return add(x1, negative(x2), output_shape=output_shape)

Binary subtraction with broadcsting.

Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor


def node_recipients(self, node_name, is_control=False, device_name=None):
    if not self._debug_graphs:
        raise LookupError('Node recipients are not loaded from partition graphs yet.')
    device_name = self._infer_device_name(device_name, node_name)
    debug_graph = self._debug_graphs[device_name]
    if is_control:
        return debug_graph.node_ctrl_recipients[node_name]
    else:
        return debug_graph.node_recipients[node_name]

Get recipient of the given node's output according to partition graphs.

Args:
node_name: (`str`) name of the node.
is_control: (`bool`) whether control outputs, rather than non-control
outputs, are to be returned.
device_name: (`str`) name of the device. If there is only one device or if
node_name exists on only one device, this argument is optional.

Returns:
(`list` of `str`) all inputs to the node, as a list of node names.

Raises:
LookupError: If node inputs and control inputs have not been loaded
from partition graphs yet.


def region(self, start=0, end=None):
    if (end is None):
        end = len(self.sequence)
    return '>{}\n{}'.format(self.id, self.sequence[start:end])

Returns a region of ``Sequence.sequence``, in FASTA format.

If called without kwargs, the entire sequence will be returned.

Args:

start (int): Start position of the region to be returned. Default
is 0.

end (int): End position of the region to be returned. Negative values
will function as they do when slicing strings.

Returns:

str: A region of ``Sequence.sequence``, in FASTA format


def is_symmetric(self, symprec=0.1):
    sg = SpacegroupAnalyzer(self, symprec=symprec)
    return sg.is_laue()

Checks if slab is symmetric, i.e., contains inversion symmetry.

Args:
symprec (float): Symmetry precision used for SpaceGroup analyzer.

Returns:
(bool) Whether slab contains inversion symmetry.


def get_pyxb_binding_by_api_version(api_major, api_minor=0):
    try:
        return VERSION_TO_BINDING_DICT[(api_major, api_minor)]
    except KeyError:
        raise ValueError('Unknown DataONE API version: {}.{}'.format(api_major, api_minor))

Map DataONE API version tag to PyXB binding.

Given a DataONE API major version number, return PyXB binding that can
serialize and deserialize DataONE XML docs of that version.

Args:
api_major, api_minor: str or int
DataONE API major and minor version numbers.

- If ``api_major`` is an integer, it is combined with ``api_minor`` to form an
exact version.

- If ``api_major`` is a string of ``v1`` or ``v2``, ``api_minor`` is ignored
and the latest PyXB bindingavailable for the ``api_major`` version is
returned.

Returns:
PyXB binding: E.g., ``d1_common.types.dataoneTypes_v1_1``.


def attrname_to_colname_dict(cls) -> Dict[(str, str)]:
    attr_col = {}
    for (attrname, column) in gen_columns(cls):
        attr_col[attrname] = column.name
    return attr_col

Asks an SQLAlchemy class how its attribute names correspond to database
column names.

Args:
cls: SQLAlchemy ORM class

Returns:
a dictionary mapping attribute names to database column names


def _BuildFindSpecsFromArtifact(self, definition, environment_variables):
    find_specs = []
    for source in definition.sources:
        if (source.type_indicator == artifact_types.TYPE_INDICATOR_FILE):
            for path_entry in set(source.paths):
                specifications = self._BuildFindSpecsFromFileSourcePath(path_entry, source.separator, environment_variables, self._knowledge_base.user_accounts)
                find_specs.extend(specifications)
                self.file_system_artifact_names.add(definition.name)
        elif (source.type_indicator == artifact_types.TYPE_INDICATOR_WINDOWS_REGISTRY_KEY):
            for key_path in set(source.keys):
                if ArtifactDefinitionsFilterHelper.CheckKeyCompatibility(key_path):
                    specifications = self._BuildFindSpecsFromRegistrySourceKey(key_path)
                    find_specs.extend(specifications)
                    self.registry_artifact_names.add(definition.name)
        elif (source.type_indicator == artifact_types.TYPE_INDICATOR_WINDOWS_REGISTRY_VALUE):
            key_paths = {key_value['key'] for key_value in source.key_value_pairs}
            key_paths_string = ', '.join(key_paths)
            logger.warning('Windows Registry values are not supported, extracting keys: "{0!s}"'.format(key_paths_string))
            for key_path in key_paths:
                if ArtifactDefinitionsFilterHelper.CheckKeyCompatibility(key_path):
                    specifications = self._BuildFindSpecsFromRegistrySourceKey(key_path)
                    find_specs.extend(specifications)
                    self.registry_artifact_names.add(definition.name)
        elif (source.type_indicator == artifact_types.TYPE_INDICATOR_ARTIFACT_GROUP):
            for name in source.names:
                specifications = self._BuildFindSpecsFromGroupName(name, environment_variables)
                find_specs.extend(specifications)
        else:
            logger.warning('Unsupported artifact definition source type: "{0:s}"'.format(source.type_indicator))
    return find_specs

Builds find specifications from an artifact definition.

Args:
definition (artifacts.ArtifactDefinition): artifact definition.
environment_variables (list[EnvironmentVariableArtifact]):
environment variables.

Returns:
list[dfvfs.FindSpec|dfwinreg.FindSpec]: dfVFS or dfWinReg find
specifications.


def __init__(self, column_names=None, column_sizes=None, title=None):

    super(CLITabularTableView, self).__init__(
        column_names=column_names, title=title)
    self._column_sizes = column_sizes or []

Initializes a command line table view.

Args:
column_names (Optional[list[str]]): column names.
column_sizes (Optional[list[int]]): minimum column sizes, in number of
characters. If a column name or row value is larger than the
minimum column size the column will be enlarged. Note that the
minimum columns size will be rounded up to the number of spaces
of the next tab.
title (Optional[str]): title.


def _decorate_block(self, start, end):
    color = self._get_scope_highlight_color()
    draw_order = DRAW_ORDERS.get('codefolding')
    d = TextDecoration(self.editor.document(), start_line=start, end_line=(end + 1), draw_order=draw_order)
    d.set_background(color)
    d.set_full_width(True, clear=False)
    self.editor.decorations.add(d)
    self._scope_decos.append(d)

Create a decoration and add it to the editor.

Args:
start (int) start line of the decoration
end (int) end line of the decoration


def match1(text, *patterns):

    if len(patterns) == 1:
        pattern = patterns[0]
        match = re.search(pattern, text)
        if match:
            return match.group(1)
        else:
            return None
    else:
        ret = []
        for pattern in patterns:
            match = re.search(pattern, text)
            if match:
                ret.append(match.group(1))
        return ret

Scans through a string for substrings matched some patterns (first-subgroups only).

Args:
text: A string to be scanned.
patterns: Arbitrary number of regex patterns.

Returns:
When only one pattern is given, returns a string (None if no match found).
When more than one pattern are given, returns a list of strings ([] if no match found).


def post(self, request):

        serializer = self.get_serializer(data=request.data)

        if serializer.is_valid():
            serializer.save()

            return Response(serializer.data)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Save the provided data using the class' serializer.

Args:
request:
The request being made.

Returns:
An ``APIResponse`` instance. If the request was successful
the response will have a 200 status code and contain the
serializer's data. Otherwise a 400 status code and the
request's errors will be returned.


def _parse_grad_debug_op_name(op_name):
    name_items = op_name.split('/')
    assert len(name_items) > 1
    assert name_items[-1].startswith(_GRADIENT_DEBUG_TAG)
    grad_debugger_uuid = name_items[-1][len(_GRADIENT_DEBUG_TAG):]
    if '_' in grad_debugger_uuid:
        grad_debugger_uuid = grad_debugger_uuid[:grad_debugger_uuid.index('_')]
    orig_tensor_slot = int(name_items[-2][name_items[-2].rfind('_') + 1:])
    orig_base_op_name = name_items[-2][:name_items[-2].rfind('_')]
    orig_tensor_name = '/'.join(name_items[:-2] + [orig_base_op_name]) + ':%d' % orig_tensor_slot
    return (grad_debugger_uuid, orig_tensor_name)

Parse the name of a debug gradient op.

Args:
op_name: the name of the debug gradient op.

Returns:
1) The UUID of the GradientsDebugger that created the debug gradient op.
2) Name of the original tensor whose gradient is debugged by the debug
gradient op.


def output_key_name(self, input_key: str, output_hist: Hist, projection_name: str, **kwargs) -> str:
    return projection_name

Returns the key under which the output object should be stored.

Note:
This function is just a basic placeholder which returns the projection name
and likely should be overridden.

Args:
input_key: Key of the input hist in the input dict
output_hist: The output histogram
projection_name: Projection name for the output histogram
kwargs: Projection information dict combined with additional arguments passed to
the projection function.
Returns:
Key under which the output object should be stored. By default, it returns the
projection name.


def train_validation_split(arrays, validation_split):
    flat_arrays = tree.flatten(arrays)
    unsplitable = [type(t) for t in flat_arrays if not can_slice_array(t)]
    if unsplitable:
        raise ValueError(f'Argument `validation_split` is only supported for tensors or NumPy arrays.Found incompatible type in the input: {unsplitable}')
    if all((t is None for t in flat_arrays)):
        return (arrays, arrays)
    first_non_none = None
    for t in flat_arrays:
        if t is not None:
            first_non_none = t
            break
    batch_dim = int(first_non_none.shape[0])
    split_at = int(math.floor(batch_dim * (1.0 - validation_split)))
    if split_at == 0 or split_at == batch_dim:
        raise ValueError(f'Training data contains {batch_dim} samples, which is not sufficient to split it into a validation and training set as specified by `validation_split={validation_split}`. Either provide more data, or a different value for the `validation_split` argument.')

    def _split(t, start, end):
        if t is None:
            return t
        return t[start:end]
    sliceables = convert_to_sliceable(arrays)
    train_arrays = tree.map_structure(lambda x: _split(x, start=0, end=split_at), sliceables)
    val_arrays = tree.map_structure(lambda x: _split(x, start=split_at, end=batch_dim), sliceables)
    return (train_arrays, val_arrays)

Split arrays into train and validation subsets in deterministic order.

The last part of data will become validation data.

Args:
arrays: Tensors to split. Allowed inputs are arbitrarily nested
structures of Tensors and NumPy arrays.
validation_split: Float between 0 and 1. The proportion of the dataset
to include in the validation split. The rest of the dataset will be
included in the training split.

Returns:
`(train_arrays, validation_arrays)`


def from_value(cls, ion_type, value, annotations=()):
    if (value is None):
        value = IonPyNull()
    else:
        (args, kwargs) = cls._to_constructor_args(value)
        value = cls(*args, **kwargs)
    value.ion_event = None
    value.ion_type = ion_type
    value.ion_annotations = annotations
    return value

Constructs a value as a copy with an associated Ion type and annotations.

Args:
ion_type (IonType): The associated Ion type.
value (Any): The value to construct from, generally of type ``cls``.
annotations (Sequence[unicode]):  The sequence Unicode strings decorating this value.


def generate_csr(private_key_bytes, subject_name, fqdn_list):

    return (
        cryptography.x509.CertificateSigningRequestBuilder()
        .subject_name(subject_name)
        .add_extension(
            extension=cryptography.x509.SubjectAlternativeName(
                [cryptography.x509.DNSName(v) for v in fqdn_list]
            ),
            critical=False,
        )
        .sign(
            private_key=private_key_bytes,
            algorithm=cryptography.hazmat.primitives.hashes.SHA256(),
            backend=cryptography.hazmat.backends.default_backend(),
        )
    )

Generate a Certificate Signing Request (CSR).

Args:
private_key_bytes: bytes
Private key with which the CSR will be signed.

subject_name: str
Certificate Subject Name

fqdn_list:
List of Fully Qualified Domain Names (FQDN) and/or IP addresses for which
this certificate will provide authentication.

E.g.: ['my.membernode.org', '1.2.3.4']


def parents(self, sourcepath, recursive=True):

        return self._get_recursive_dependancies(
            self._PARENTS_MAP,
            sourcepath,
            recursive=True
        )

Recursively find all parents that import the given source path.

Args:
sourcepath (str): Source file path to search for.

Keyword Arguments:
recursive (bool): Switch to enabled recursive finding (if True).
Default to True.

Returns:
set: List of finded parents path.


def __parameter_default(self, final_subfield):
    if final_subfield.default:
        if isinstance(final_subfield, messages.EnumField):
            return final_subfield.default.name
        else:
            return final_subfield.default

Returns default value of final subfield if it has one.

If this subfield comes from a field list returned from __field_to_subfields,
none of the fields in the subfield list can have a default except the final
one since they all must be message fields.

Args:
final_subfield: A simple field from the end of a subfield list.

Returns:
The default value of the subfield, if any exists, with the exception of an
enum field, which will have its value cast to a string.


def tagged(pode, tag):

    if tag.startswith('
        tag = tag[1:]
    return pode[1]['tags'].get(tag) is not None

Check if a packed node has a given tag.

Args:
pode (tuple): A packed node.
tag (str): The tag to check.

Examples:
Check if a node is tagged with "woot" and dostuff if it is.

if s_node.tagged(node,'woot'):
dostuff()

Notes:
If the tag starts with `#`, this is removed prior to checking.

Returns:
bool: True if the tag is present. False otherwise.


def destroy_sg(app='', env='', region='', **_):
    vpc = get_vpc_id(account=env, region=region)
    url = '{api}/securityGroups/{env}/{region}/{app}'.format(api=API_URL, env=env, region=region, app=app)
    payload = {'vpcId': vpc}
    security_group = requests.get(url, params=payload, verify=GATE_CA_BUNDLE, cert=GATE_CLIENT_CERT)
    if (not security_group):
        LOG.info('Nothing to delete.')
    else:
        LOG.info('Found Security Group in %(region)s: %(name)s', security_group)
        destroy_request = get_template('destroy/destroy_sg.json.j2', app=app, env=env, region=region, vpc=vpc)
        wait_for_task(destroy_request)
    return True

Destroy Security Group.

Args:
app (str): Spinnaker Application name.
env (str): Deployment environment.
region (str): Region name, e.g. us-east-1.

Returns:
True upon successful completion.


def parse_requirements(file_):

    modules = []
    delim = ["<", ">", "=", "!", "~"]

    try:
        f = open_func(file_, "r")
    except OSError:
        logging.error("Failed on file: {}".format(file_))
        raise
    else:
        data = [x.strip() for x in f.readlines() if x != "\n"]
    finally:
        f.close()

    data = [x for x in data if x[0].isalpha()]

    for x in data:
        if not any([y in x for y in delim]):
            modules.append({"name": x, "version": None})
        for y in x:
            if y in delim:
                module = x.split(y)
                module_name = module[0]
                module_version = module[-1].replace("=", "")
                module = {"name": module_name, "version": module_version}

                if module not in modules:
                    modules.append(module)

                break

    return modules

Parse a requirements formatted file.

Traverse a string until a delimiter is detected, then split at said
delimiter, get module name by element index, create a dict consisting of
module:version, and add dict to list of parsed modules.

Args:
file_: File to parse.

Raises:
OSerror: If there's any issues accessing the file.

Returns:
tuple: The contents of the file, excluding comments.


def encode_mezzanine_asset(access_token, processor_id, asset_id, output_assetname, json_profile):
    path = '/Jobs'
    endpoint = ''.join([ams_rest_endpoint, path])
    assets_path = ''.join(['/Assets', "('", asset_id, "')"])
    assets_path_encoded = urllib.parse.quote(assets_path, safe='')
    endpoint_assets = ''.join([ams_rest_endpoint, assets_path_encoded])
    body = (((((((((('{     \t\t"Name":"' + output_assetname) + '",    \t\t"InputMediaAssets":[{        \t  \t\t"__metadata":{        \t     \t\t\t"uri":"') + endpoint_assets) + '"        \t  \t\t}      \t \t}],    \t\t"Tasks":[{        \t  \t\t"Configuration":\'') + json_profile) + '\',        \t  \t\t"MediaProcessorId":"') + processor_id) + '",        \t  \t\t"TaskBody":"<?xml version=\\"1.0\\" encoding=\\"utf-16\\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset assetCreationOptions=\\"0\\" assetName=\\"') + output_assetname) + '\\">JobOutputAsset(0)</outputAsset></taskBody>"       \t\t}] \t}')
    return do_ams_post(endpoint, path, body, access_token)

Get Media Service Encode Mezanine Asset.

Args:
access_token (str): A valid Azure authentication token.
processor_id (str): A Media Service Processor ID.
asset_id (str): A Media Service Asset ID.
output_assetname (str): A Media Service Asset Name.
json_profile (str): A Media Service JSON Profile.

Returns:
HTTP response. JSON body.


def to_env_var(env_var: str, value) -> str:
    val = to_yaml(value)
    ret_val = ('%s=%s' % (env_var, escape_yaml(val)))
    return ret_val

Create an environment variable from a name and a value.

This generates a shell-compatible representation of an
environment variable that is assigned a YAML representation of
a value.

Args:
env_var (str): Name of the environment variable.
value (Any): A value we convert from.


def collapse_repeated(labels, seq_length, name=None):
    with ops.name_scope(name, 'collapse_repeated_labels', [labels, seq_length]):
        labels = ops.convert_to_tensor(labels, name='labels')
        seq_length = ops.convert_to_tensor(seq_length, name='seq_length')
        label_mask = array_ops.concat([array_ops.ones_like(labels[:, :1], dtypes.bool), math_ops.not_equal(labels[:, 1:], labels[:, :-1])], axis=1)
        maxlen = _get_dim(labels, 1)
        seq_mask = array_ops.sequence_mask(seq_length, maxlen=maxlen)
        label_mask = math_ops.logical_and(label_mask, seq_mask)
        new_seq_len = math_ops.reduce_sum(math_ops.cast(label_mask, dtypes.int32), axis=1)
        new_maxlen = math_ops.reduce_max(new_seq_len)
        idx_mask = array_ops.sequence_mask(new_seq_len, maxlen=new_maxlen)
        flat_labels = array_ops.reshape(labels, [-1])
        flat_label_mask = array_ops.reshape(label_mask, [-1])
        flat_idx_mask = array_ops.reshape(idx_mask, [-1])
        idx = math_ops.range(_get_dim(flat_idx_mask, 0))
        flat = array_ops.scatter_nd(indices=array_ops.expand_dims(array_ops.boolean_mask(idx, flat_idx_mask), axis=1), updates=array_ops.boolean_mask(flat_labels, flat_label_mask), shape=array_ops.shape(flat_idx_mask))
        batch_size = _get_dim(labels, 0)
        new_shape = [batch_size, new_maxlen]
        return (array_ops.reshape(flat, new_shape), math_ops.cast(new_seq_len, seq_length.dtype))

Merge repeated labels into single labels.

Args:
labels: Tensor of shape [batch, max value in seq_length]
seq_length: Tensor of shape [batch], sequence length of each batch element.
name: A name for this `Op`. Defaults to "collapse_repeated_labels".

Returns:
A tuple `(collapsed_labels, new_seq_length)` where

collapsed_labels: Tensor of shape [batch, max_seq_length] with repeated
labels collapsed and padded to max_seq_length, eg:
`[[A, A, B, B, A], [A, B, C, D, E]] => [[A, B, A, 0, 0], [A, B, C, D, E]]`

new_seq_length: int tensor of shape [batch] with new sequence lengths.


def all_distances(coords1, coords2):
    c1 = np.array(coords1)
    c2 = np.array(coords2)
    z = ((c1[(:, None, :)] - c2[(None, :, :)]) ** 2)
    return (np.sum(z, axis=(- 1)) ** 0.5)

Returns the distances between two lists of coordinates

Args:
coords1: First set of cartesian coordinates.
coords2: Second set of cartesian coordinates.

Returns:
2d array of cartesian distances. E.g the distance between
coords1[i] and coords2[j] is distances[i,j]


def execute(command, cwd=os.path.curdir, **options):
    process = subprocess.Popen(shlex.split(command), cwd=cwd, **options)
    (stdout, stderr) = process.communicate()
    return (process, stdout, stderr)

Run the system command with optional options.

Args:
* command: system command.
* cwd: current working directory.
* verbose: direct options for :func:`subprocess.Popen`.

Returns:
Opened process, standard output & error.


def inference(self, observed_arr):

        _ = self.__lstm_model.inference(observed_arr)
        return self.__lstm_model.get_feature_points()

Draws samples from the `fake` distribution.

Args:
observed_arr:     `np.ndarray` of observed data points.

Returns:
`np.ndarray` of inferenced.


def jaccard_sims(feature_list):
    sim_info_list = []
    for feature_info in feature_list:
        md5_source = feature_info['md5']
        features_source = feature_info['features']
        for feature_info in feature_list:
            md5_target = feature_info['md5']
            features_target = feature_info['features']
            if (md5_source == md5_target):
                continue
            sim = jaccard_sim(features_source, features_target)
            if (sim > 0.5):
                sim_info_list.append({'source': md5_source, 'target': md5_target, 'sim': sim})
    return sim_info_list

Compute Jaccard similarities between all the observations in the feature list.

Args:
feature_list: a list of dictionaries, each having structure as
{ 'md5' : String, 'features': list of Strings }

Returns:
list of dictionaries with structure as
{'source': md5 String, 'target': md5 String, 'sim': Jaccard similarity Number}


def genCaCert(self, name, signas=None, outp=None, save=True):
    (pkey, cert) = self._genBasePkeyCert(name)
    ext0 = crypto.X509Extension(b'basicConstraints', False, b'CA:TRUE')
    cert.add_extensions([ext0])
    if (signas is not None):
        self.signCertAs(cert, signas)
    else:
        self.selfSignCert(cert, pkey)
    if save:
        keypath = self._savePkeyTo(pkey, 'cas', ('%s.key' % name))
        if (outp is not None):
            outp.printf(('key saved: %s' % (keypath,)))
        crtpath = self._saveCertTo(cert, 'cas', ('%s.crt' % name))
        if (outp is not None):
            outp.printf(('cert saved: %s' % (crtpath,)))
    return (pkey, cert)

Generates a CA keypair.

Args:
name (str): The name of the CA keypair.
signas (str): The CA keypair to sign the new CA with.
outp (synapse.lib.output.Output): The output buffer.

Examples:
Make a CA named "myca":

mycakey, mycacert = cdir.genCaCert('myca')

Returns:
((OpenSSL.crypto.PKey, OpenSSL.crypto.X509)): Tuple containing the private key and certificate objects.


def get_output_at(self, node_index):
    return self._get_node_attribute_at_index(node_index, 'output_tensors', 'output')

Retrieves the output tensor(s) of a layer at a given node.

Args:
node_index: Integer, index of the node
from which to retrieve the attribute.
E.g. `node_index=0` will correspond to the
first output node of the layer.

Returns:
A tensor (or list of tensors if the layer has multiple outputs).

Raises:
RuntimeError: If called in Eager mode.


def assert_same_rank(self, other):
    other = as_shape(other)
    if ((self.ndims is not None) and (other.ndims is not None)):
        if (self.ndims != other.ndims):
            raise ValueError(('Shapes %s and %s must have the same rank' % (self, other)))

Raises an exception if `self` and `other` do not have convertible ranks.

Args:
other: Another `TensorShape`.

Raises:
ValueError: If `self` and `other` do not represent shapes with the
same rank.


def get_xml_request(self):

    def wrap_xml_content(xml_content):
        ' Wrap XML content string in the correct CPS request envelope.'
        fields = ['<?xml version="1.0" encoding="utf-8"?>\n', '<cps:request xmlns:cps="www.clusterpoint.com">\n', '<cps:storage>', self.connection._storage, '</cps:storage>\n']
        if self.timestamp:
            fields += []
        if self.request_id:
            fields += ['<cps:request_id>', str(self.request_id), '</cps:request_id>\n']
        if self.connection.reply_charset:
            fields += []
        if self.connection.application:
            fields += ['<cps:application>', self.connection.application, '</cps:application>\n']
        fields += ['<cps:command>', self._command, '</cps:command>\n', '<cps:user>', self.connection._user, '</cps:user>\n', '<cps:password>', self.connection._password, '</cps:password>\n', '<cps:account>', self.connection._account, '</cps:account>\n']
        if self.timeout:
            fields += ['<cps:timeout>', str(self.timeout), '</cps:timeout>\n']
        if self.type:
            fields += ['<cps:type>', self.type, '</cps:type>\n']
        if xml_content:
            fields += ['<cps:content>\n', xml_content, '\n</cps:content>\n']
        else:
            fields += '<cps:content/>\n'
        fields += '</cps:request>\n'
        xml_request = ''.join(fields)
        return xml_request
    xml_content = []
    if self._documents:
        xml_content += self._documents
    for (key, value) in self._nested_content.items():
        if value:
            xml_content += ((['<{0}>'.format(key)] + ['<{0}>{1}</{0}>'.format(sub_key, sub_value) for (sub_key, sub_value) in value if sub_value]) + ['</{0}>'.format(key)])
    for (key, value) in self._content.items():
        if (not isinstance(value, list)):
            value = [value]
        xml_content += ['<{0}>{1}</{0}>'.format(key, item) for item in value if item]
    xml_content = '\n'.join(xml_content)
    return wrap_xml_content(xml_content)

Make xml request string from stored request information.

Returns:
A properly formated XMl request string containing all set request fields and
wraped in connections envelope.


def ParseApplicationUsageRow(self, parser_mediator, query, row, **unused_kwargs):
    query_hash = hash(query)
    application_name = self._GetRowValue(query_hash, row, 'event')
    usage = 'Application {0:s}'.format(application_name)
    event_data = MacOSApplicationUsageEventData()
    event_data.application = self._GetRowValue(query_hash, row, 'app_path')
    event_data.app_version = self._GetRowValue(query_hash, row, 'app_version')
    event_data.bundle_id = self._GetRowValue(query_hash, row, 'bundle_id')
    event_data.count = self._GetRowValue(query_hash, row, 'number_times')
    event_data.query = query
    timestamp = self._GetRowValue(query_hash, row, 'last_time')
    date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(date_time, usage)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses an application usage row.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row.


def _build_ds_from_instruction(instruction, ds_from_file_fn):
    examples_ds = ds_from_file_fn(instruction['filepath'])
    mask_ds = _build_mask_ds(mask_offset=instruction['mask_offset'], mask=instruction['mask'])
    ds = tf.data.Dataset.zip((examples_ds, mask_ds))
    ds = ds.filter((lambda example, mask: mask))
    ds = ds.map((lambda example, mask: example))
    return ds

Map an instruction to a real datasets for one particular shard.

Args:
instruction: A `dict` of `tf.Tensor` containing the instruction to load
the particular shard (filename, mask,...)
ds_from_file_fn: `fct`, function which returns the dataset associated to
the filename

Returns:
dataset: `tf.data.Dataset`, The shard loaded from the instruction


def from_dict(cls, config_dict, return_unused_kwargs=False, **kwargs):
    config = cls(**config_dict)
    to_remove = []
    for key, value in kwargs.items():
        if hasattr(config, key):
            setattr(config, key, value)
            to_remove.append(key)
    for key in to_remove:
        kwargs.pop(key, None)
    if return_unused_kwargs:
        return (config, kwargs)
    else:
        return config

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

Args:
config_dict (`Dict[str, Any]`):
Dictionary that will be used to instantiate the configuration object.
return_unused_kwargs (`bool`,*optional*, defaults to `False`):
Whether or not to return a list of unused keyword arguments. Used for `from_pretrained` method in
`PreTrainedModel`.
kwargs (`Dict[str, Any]`):
Additional parameters from which to initialize the configuration object.

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


def device_id_to_slug(did):

    try:
        device_slug = IOTileDeviceSlug(did, allow_64bits=False)
    except ValueError:
        raise ArgumentError("Unable to recognize {} as a device id".format(did))

    return str(device_slug)

Converts a device id into a correct device slug.

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


def connection_made(self, transport):

        self.transport = transport
        self.responders = [self.make_responder(self)]

        try:
            good_func = callable(self.responders[0].on_data)
        except AttributeError:
            good_func = False

        if not good_func:
            err_str = "Provided responder MUST implement an 'on_data' method"
            raise TypeError(err_str)

        log_info = (id(self), self.remote_hostname, self.remote_port)
        log.info("{:d} connection from {}:{}", *log_info)

(asyncio.Protocol member)

Called upon when there is a new socket connection.
This creates a new responder (as determined by the member
'responder_type') and stores in a list.
Incoming data from this connection will always call on_data
to the last element of this list.

Args:
transport (asyncio.Transport): The Transport handling the
socket communication


def storage(line, cell=None):

  parser = datalab.utils.commands.CommandParser(prog='storage', description=)

  copy_parser = parser.subcommand('copy',
                                  'Copy one or more GCS objects to a different location.')
  copy_parser.add_argument('-s', '--source', help='The name of the object(s) to copy', nargs='+')
  copy_parser.add_argument('-d', '--destination', required=True,
                           help='The copy destination. For multiple source items this must be a '
                                'bucket.')
  copy_parser.set_defaults(func=_storage_copy)

  create_parser = parser.subcommand('create', 'Create one or more GCS buckets.')
  create_parser.add_argument('-p', '--project', help='The project associated with the objects')
  create_parser.add_argument('-b', '--bucket', help='The name of the bucket(s) to create',
                             nargs='+')
  create_parser.set_defaults(func=_storage_create)

  delete_parser = parser.subcommand('delete', 'Delete one or more GCS buckets or objects.')
  delete_parser.add_argument('-b', '--bucket', nargs='*',
                             help='The name of the bucket(s) to remove')
  delete_parser.add_argument('-o', '--object', nargs='*',
                             help='The name of the object(s) to remove')
  delete_parser.set_defaults(func=_storage_delete)

  list_parser = parser.subcommand('list', 'List buckets in a project, or contents of a bucket.')
  list_parser.add_argument('-p', '--project', help='The project associated with the objects')
  group = list_parser.add_mutually_exclusive_group()
  group.add_argument('-o', '--object',
                     help='The name of the objects(s) to list; can include wildchars',
                     nargs='?')
  group.add_argument('-b', '--bucket',
                     help='The name of the buckets(s) to list; can include wildchars',
                     nargs='?')
  list_parser.set_defaults(func=_storage_list)

  read_parser = parser.subcommand('read',
                                  'Read the contents of a storage object into a Python variable.')
  read_parser.add_argument('-o', '--object', help='The name of the object to read',
                           required=True)
  read_parser.add_argument('-v', '--variable', required=True,
                           help='The name of the Python variable to set')
  read_parser.set_defaults(func=_storage_read)

  view_parser = parser.subcommand('view', 'View the contents of a storage object.')
  view_parser.add_argument('-n', '--head', type=int, default=20,
                           help='The number of initial lines to view')
  view_parser.add_argument('-t', '--tail', type=int, default=20,
                           help='The number of lines from end to view')
  view_parser.add_argument('-o', '--object', help='The name of the object to view',
                           required=True)
  view_parser.set_defaults(func=_storage_view)

  write_parser = parser.subcommand('write',
                                   'Write the value of a Python variable to a storage object.')
  write_parser.add_argument('-v', '--variable', help='The name of the source Python variable',
                            required=True)
  write_parser.add_argument('-o', '--object', required=True,
                            help='The name of the destination GCS object to write')
  write_parser.add_argument('-c', '--content_type', help='MIME type', default='text/plain')
  write_parser.set_defaults(func=_storage_write)

  return datalab.utils.commands.handle_magic_line(line, cell, parser)

Implements the storage cell magic for ipython notebooks.

Args:
line: the contents of the storage line.
Returns:
The results of executing the cell.


def _parse_logline_timestamp(t):

    date, time = t.split(' ')
    month, day = date.split('-')
    h, m, s = time.split(':')
    s, ms = s.split('.')
    return (month, day, h, m, s, ms)

Parses a logline timestamp into a tuple.

Args:
t: Timestamp in logline format.

Returns:
An iterable of date and time elements in the order of month, day, hour,
minute, second, microsecond.


def _ParseHTTPHeaders(self, header_data, offset, display_name):

    header_string = header_data.decode('ascii', errors='replace')

    try:
      http_header_start = header_string.index('request-method')
    except ValueError:
      logger.debug('No request method in header: "{0:s}"'.format(header_string))
      return None, None

    http_headers = header_string[http_header_start::]

    header_parts = http_headers.split('\x00')

    request_method = header_parts[1]

    if request_method not in self._REQUEST_METHODS:
      logger.debug((
          '[{0:s}] {1:s}:{2:d}: Unknown HTTP method \'{3:s}\'. Response '
          'headers: \'{4:s}\'').format(
              self.NAME, display_name, offset, request_method, header_string))

    try:
      response_head_start = http_headers.index('response-head')
    except ValueError:
      logger.debug('No response head in header: "{0:s}"'.format(header_string))
      return request_method, None

    response_head = http_headers[response_head_start::]

    response_head_parts = response_head.split('\x00')

    response_head_text = response_head_parts[1]
    response_head_text_parts = response_head_text.split('\r\n')

    response_code = response_head_text_parts[0]

    if not response_code.startswith('HTTP'):
      logger.debug((
          '[{0:s}] {1:s}:{2:d}: Could not determine HTTP response code. '
          'Response headers: \'{3:s}\'.').format(
              self.NAME, display_name, offset, header_string))

    return request_method, response_code

Extract relevant information from HTTP header.

Args:
header_data (bytes): HTTP header data.
offset (int): offset of the cache record, relative to the start of
the Firefox cache file.
display_name (str): display name of the Firefox cache file.

Returns:
tuple: containing:

str: HTTP request method or None if the value cannot be extracted.
str: HTTP response code or None if the value cannot be extracted.


def before_request(self, request, method, url, headers):
    parts = urllib.parse.urlsplit(url)
    audience = urllib.parse.urlunsplit((parts.scheme, parts.netloc, parts.path, '', ''))
    token = self._get_jwt_for_audience(audience)
    self.apply(headers, token=token)

Performs credential-specific before request logic.

Args:
request (Any): Unused. JWT credentials do not need to make an
HTTP request to refresh.
method (str): The request's HTTP method.
url (str): The request's URI. This is used as the audience claim
when generating the JWT.
headers (Mapping): The request's headers.


def list_workflow_outputs(self):

        workflow_outputs = []
        for task in self.tasks:
            for output_port_name in task.outputs._portnames:
                if task.outputs.__getattribute__(output_port_name).persist:
                    workflow_outputs.append(task.name + ':' + output_port_name)

        return workflow_outputs

Get a list of outputs from the workflow that are saved to S3. To get resolved locations call workflow status.
Args:
None

Returns:
list


def __content_type_matches(self, content_type, available_content_types):

        if content_type is None:
            return False

        if content_type in available_content_types:
            return True

        for available_content_type in available_content_types:
            if available_content_type in content_type:
                return True

        return False

Check if the given content type matches one of the available content types.

Args:
content_type (str): The given content type.
available_content_types list(str): All the available content types.

Returns:
bool: True if a match was found, False otherwise.


def set_synchronous_execution(enable):
    if enable is None:
        context.context().execution_mode = None
    elif enable:
        context.context().execution_mode = context.SYNC
    else:
        context.context().execution_mode = context.ASYNC

Specifies whether operations are executed synchronously or asynchronously.

TensorFlow can execute operations synchronously or asynchronously. If
asynchronous execution is enabled, operations may return "non-ready" handles.

When `enable` is set to None, an appropriate value will be picked
automatically. The value picked may change between TensorFlow releases.

Args:
enable: Whether operations should be dispatched synchronously.
Valid values:
- None: sets the system default.
- True: executes each operation synchronously.
- False: executes each operation asynchronously.


def contract_low_support(self, threshold):

        if not isinstance(threshold, float) and not isinstance(threshold, int):
            raise TypeError("threshold must be float or int")
        to_contract = list()
        for node in self.traverse_preorder():
            try:
                if float(str(node)) < threshold:
                    to_contract.append(node)
            except:
                pass
        for node in to_contract:
            node.contract()

Contract internal nodes labeled by a number (e.g. branch support) below ``threshold``

Args:
``threshold`` (``float``): The support threshold to use when contracting nodes


def coinbase_withdraw(self, amount, currency, coinbase_account_id):
    params = {'amount': amount, 'currency': currency, 'coinbase_account_id': coinbase_account_id}
    return self._send_message('post', '/withdrawals/coinbase-account', data=json.dumps(params))

Withdraw funds to a coinbase account.

You can move funds between your Coinbase accounts and your cbpro
trading accounts within your daily limits. Moving funds between
Coinbase and cbpro is instant and free.

See AuthenticatedClient.get_coinbase_accounts() to receive
information regarding your coinbase_accounts.

Args:
amount (Decimal): The amount to withdraw.
currency (str): The type of currency (eg. 'BTC')
coinbase_account_id (str): ID of the coinbase account.

Returns:
dict: Information about the deposit. Example::
{
"id":"593533d2-ff31-46e0-b22e-ca754147a96a",
"amount":"10.00",
"currency": "BTC",
}


def _srvmgr(cmd, return_json=False):

    if isinstance(cmd, list):
        cmd = ' '.join(cmd)

    if return_json:
        cmd = 'ConvertTo-Json -Compress -Depth 4 -InputObject @({0})' \
              ''.format(cmd)

    cmd = 'Import-Module WebAdministration; {0}'.format(cmd)

    ret = __salt__['cmd.run_all'](cmd, shell='powershell', python_shell=True)

    if ret['retcode'] != 0:
        msg = 'Unable to execute command: {0}\nError: {1}' \
              ''.format(cmd, ret['stderr'])
        log.error(msg)

    return ret

Execute a powershell command from the WebAdministration PS module.

Args:
cmd (list): The command to execute in a list
return_json (bool): True formats the return in JSON, False just returns
the output of the command.

Returns:
str: The output from the command


def to_json_string(self):
    return json.dumps(self.__dict__, indent=2) + '\n'

Serializes this instance to a JSON formatted string.
Returns:
str: JSON formatted string representing the configuration instance.


def are_equivalent_xml(a_xml, b_xml):

    return are_equivalent_pyxb(
        d1_common.xml.deserialize(a_xml), d1_common.xml.deserialize(b_xml)
    )

Check if two ReplicationPolicy XML docs are semantically equivalent.

The ReplicationPolicy XML docs are normalized before comparison.

Args:
a_xml, b_xml: ReplicationPolicy XML docs to compare

Returns:
bool: ``True`` if the resulting policies for the two objects are semantically
equivalent.


def array2bytes(arr, bytes_type=bytes):
    bio = io.BytesIO()
    np.save(bio, arr, allow_pickle=False)
    return bytes_type(bio.getvalue())

Wraps NumPy's save function to return bytes.

We use :func:`numpy.save` rather than :meth:`numpy.ndarray.tobytes` because
it encodes endianness and order.

Args:
arr (:obj:`numpy.ndarray`):
Array to be saved.

bytes_type (class, optional, default=bytes):
This class will be used to wrap the bytes objects in the
serialization if `use_bytes` is true. Useful for when using
Python 2 and using BSON encoding, which will not accept the raw
`bytes` type, so `bson.Binary` can be used instead.

Returns:
bytes_type


def from_encoder_decoder_configs(cls, encoder_config: PretrainedConfig, decoder_config: PretrainedConfig, **kwargs) -> PretrainedConfig:
    logger.info('Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config')
    decoder_config.is_decoder = True
    decoder_config.add_cross_attention = True
    return cls(encoder=encoder_config.to_dict(), decoder=decoder_config.to_dict(), **kwargs)

Instantiate a [`SpeechEncoderDecoderConfig`] (or a derived class) from a pre-trained encoder model
configuration and decoder model configuration.

Returns:
[`SpeechEncoderDecoderConfig`]: An instance of a configuration object


def _find_max_under_constraint(self, constrained, dependent, predicate):
    feasible = array_ops.where_v2(predicate(constrained, self.value))
    feasible_exists = math_ops.greater(array_ops.size(feasible), 0)
    max_dependent = math_ops.reduce_max(array_ops.gather(dependent, feasible))
    return array_ops.where_v2(feasible_exists, max_dependent, 0.0)

Returns the maximum of dependent_statistic that satisfies the constraint.

Args:
constrained: Over these values the constraint
is specified. A rank-1 tensor.
dependent: From these values the maximum that satiesfies the
constraint is selected. Values in this tensor and in
`constrained` are linked by having the same threshold at each
position, hence this tensor must have the same shape.
predicate: A binary boolean functor to be applied to arguments
`constrained` and `self.value`, e.g. `tf.greater`.

Returns maximal dependent value, if no value satiesfies the constraint 0.0.


def get_environmental_configuration(self, id_or_uri):

        uri = self._client.build_uri(id_or_uri) + "/environmentalConfiguration"
        return self._client.get(uri)

Returns a description of the environmental configuration (supported feature set, calibrated minimum & maximum
power, location & dimensions, ...) of the resource.

Args:
id_or_uri:
Can be either the Unmanaged Device id or the uri

Returns:
dict:
EnvironmentalConfiguration


def intern(self, text):
    if self.table_type.is_shared:
        raise TypeError('Cannot intern on shared symbol table')
    if (not isinstance(text, six.text_type)):
        raise TypeError(('Cannot intern non-Unicode sequence into symbol table: %r' % text))
    token = self.get(text)
    if (token is None):
        token = self.__add_text(text)
    return token

Interns the given Unicode sequence into the symbol table.

Note:
This operation is only valid on local symbol tables.

Args:
text (unicode): The target to intern.

Returns:
SymbolToken: The mapped symbol token which may already exist in the table.


def import_event(tensor, name=None):
    return gen_summary_ops.import_event(_summary_state.writer._resource, tensor, name=name)

Writes a `tf.compat.v1.Event` binary proto.

This can be used to import existing event logs into a new summary writer sink.
Please note that this is lower level than the other summary functions and
will ignore the `tf.summary.should_record_summaries` setting.

Args:
tensor: A `tf.Tensor` of type `string` containing a serialized
`tf.compat.v1.Event` proto.
name: A name for the operation (optional).

Returns:
The created `tf.Operation`.


def FindHeader(self, header):
    for section_list in self.include_list:
        for f in section_list:
            if (f[0] == header):
                return f[1]
    return (- 1)

Check if a header has already been included.

Args:
header: header to check.
Returns:
Line number of previous occurrence, or -1 if the header has not
been seen before.


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

Corresponds to IDD Field `hr_dp020`
humidity ratio corresponding to
Dew-point temperature corresponding to 2.0% annual cumulative frequency of occurrence
calculated at the standard atmospheric pressure at elevation of station

Args:
value (float): value for IDD Field `hr_dp020`
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 _all_sum_grad(op, grad):
    if op.get_attr('reduction') != b'sum':
        raise LookupError('No gradient defined for NcclAllReduce except for reduction="sum".')
    _check_device(grad, expected=op.device)
    num_devices = op.get_attr('num_devices')
    shared_name = op.get_attr('shared_name') + b'_grad'
    with ops.device(op.device):
        return gen_nccl_ops.nccl_all_reduce(input=grad, reduction='sum', num_devices=num_devices, shared_name=shared_name)

The gradients for `all_sum`.

Args:
op: The `all_sum` `Operation` that we are differentiating.
grad: Gradient with respect to the output of the `all_sum` op.

Returns:
The gradient with respect to the output of `all_sum`.

Raises:
LookupError: If `reduction` is not `sum`.


def entanglement_of_formation(state, d0, d1=None):

    state = np.array(state)

    if d1 is None:
        d1 = int(len(state) / d0)

    if state.ndim == 2 and len(state) == 4 and d0 == 2 and d1 == 2:
        return __eof_qubit(state)
    elif state.ndim == 1:

        if d0 < d1:
            tr = [1]
        else:
            tr = [0]
        state = partial_trace(state, tr, dimensions=[d0, d1])
        return entropy(state)
    else:
        print('Input must be a state-vector or 2-qubit density matrix.')
    return None

Compute the entanglement of formation of quantum state.

The input quantum state must be either a bipartite state vector, or a
2-qubit density matrix.

Args:
state (array_like): (N) array_like or (4,4) array_like, a
bipartite quantum state.
d0 (int): the dimension of the first subsystem.
d1 (int or None): the dimension of the second subsystem.

Returns:
float: The entanglement of formation.


def camelcase(text, acronyms=None):
    (words, _case, _sep) = case_parse.parse_case(text, acronyms)
    if words:
        words[0] = words[0].lower()
    return ''.join(words)

Return text in camelCase style.

Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect

>>> camelcase("hello world")
'helloWorld'
>>> camelcase("HELLO_HTML_WORLD", True, ["HTML"])
'helloHTMLWorld'


def _validate_or_infer_batch_size(self, batch_size, steps, x):
    if isinstance(x, (data_types.DatasetV1, data_types.DatasetV2, data_utils.Sequence)) or tf_inspect.isgenerator(x):
        if batch_size is not None:
            raise ValueError('The `batch_size` argument must not be specified for the given input type. Received input: {}, batch_size: {}'.format(x, batch_size))
        return
    layers = self._flatten_layers(include_self=False, recursive=False)
    first_layer = next(layers, None)
    if first_layer:
        static_batch_size = training_utils.get_static_batch_size(first_layer)
        if static_batch_size is not None:
            if self._distribution_strategy and distributed_training_utils.global_batch_size_supported(self._distribution_strategy):
                num_splits_for_ds = self._distribution_strategy.num_replicas_in_sync
            else:
                num_splits_for_ds = 1
            if batch_size is not None:
                if batch_size % num_splits_for_ds != 0:
                    raise ValueError('The `batch_size` argument ({}) must be divisible the by number of replicas ({})'.format(batch_size, num_splits_for_ds))
                per_replica_batch_size = batch_size
                if per_replica_batch_size != static_batch_size:
                    raise ValueError('The `batch_size` argument value {} is incompatible with the specified batch size of your Input Layer: {}'.format(per_replica_batch_size, static_batch_size))
            if isinstance(x, (data_types.DatasetV2, iterator_ops.Iterator, iterator_ops.IteratorBase)):
                ds_batch_size = tensor_shape.Dimension(nest.flatten(dataset_ops.get_legacy_output_shapes(x))[0][0]).value
                if ds_batch_size is not None:
                    if ds_batch_size % num_splits_for_ds != 0:
                        raise ValueError('The batch output shape of your `Dataset` {} cannot be divisible by number of replicas {}'.format(ds_batch_size, num_splits_for_ds))
                    ds_per_replica_batch_size = ds_batch_size
                    if ds_per_replica_batch_size != static_batch_size:
                        raise ValueError('The batch output shape of your `Dataset` is {}, which is incompatible with the specified batch size of your Input Layer: {}'.format(ds_per_replica_batch_size, static_batch_size))
            if steps is None:
                batch_size = static_batch_size * num_splits_for_ds
    if batch_size is None and steps is None:
        batch_size = 32
    return batch_size

Validates that the `batch_size` provided is consistent with InputLayer.

It's possible that the user specified a static batch size in their
InputLayer. If so, this method checks the provided `batch_size` and `x`
arguments are consistent with this static batch size. Also, if
`batch_size` is `None`, this method will attempt to infer the batch size
from the static batch size of the InputLayer. Lastly, ValueError will be
raised if `x` is a tf.data.Dataset and `batch_size` is specified as we
expect users to provide batched datasets.

Args:
batch_size: The batch_size provided as an argument to
fit/evaluate/predict.
steps: The steps provided as an argument to fit/evaluate/predict.
x: The data passed as `x` to fit/evaluate/predict.

Returns:
The validated batch_size, auto-inferred from the first layer if not
provided.


def send_fetches(self):
    futures = []
    for (node_id, request) in six.iteritems(self._create_fetch_requests()):
        if self._client.ready(node_id):
            log.debug('Sending FetchRequest to node %s', node_id)
            future = self._client.send(node_id, request)
            future.add_callback(self._handle_fetch_response, request, time.time())
            future.add_errback(log.error, 'Fetch to node %s failed: %s', node_id)
            futures.append(future)
    self._fetch_futures.extend(futures)
    self._clean_done_fetch_futures()
    return futures

Send FetchRequests for all assigned partitions that do not already have
an in-flight fetch or pending fetch data.

Returns:
List of Futures: each future resolves to a FetchResponse


def moma(self, wt_fluxes):
    reactions = set(self._adjustment_reactions())
    v = self._v
    obj_expr = 0
    for (f_reaction, f_value) in iteritems(wt_fluxes):
        if (f_reaction in reactions):
            obj_expr += ((f_value - v[f_reaction]) ** 2)
    self._prob.set_objective(obj_expr)
    self._solve(lp.ObjectiveSense.Minimize)

Minimize the redistribution of fluxes using Euclidean distance.

Minimizing the redistribution of fluxes using a quadratic objective
function. The distance is minimized by minimizing the sum of
(wild type - knockout)^2.

Args:
wt_fluxes: Dictionary of all the wild type fluxes that will be
used to find a close MOMA solution. Fluxes can be expiremental
or calculated using :meth: get_fba_flux(objective).


def keypath(self, key):

        return fs.path(self.path, self.escape_key(key))

Get the filesystem path for a key.

Arguments:
key: Key.

Returns:
str: Absolute path.


def _MergeEntities(self, a, b):

    distance = transitfeed.ApproximateDistanceBetweenStops(a, b)
    if distance > self.largest_stop_distance:
      raise MergeError("Stops are too far apart: %.1fm "
                       "(largest_stop_distance is %.1fm)." %
                       (distance, self.largest_stop_distance))
    scheme = {'stop_id': self._MergeIdentical,
              'stop_name': self._MergeIdenticalCaseInsensitive,
              'zone_id': self._MergeIdentical,
              'location_type': self._MergeIdentical}
    return self._SchemedMerge(scheme, a, b)

Merges two stops.

For the stops to be merged, they must have:
- the same stop_id
- the same stop_name (case insensitive)
- the same zone_id
- locations less than largest_stop_distance apart
The other attributes can have arbitary changes. The merged attributes are
taken from the new stop.

Args:
a: The first stop.
b: The second stop.

Returns:
The merged stop.

Raises:
MergeError: The stops could not be merged.


def GetCacheValueByObject(self, vfs_object):
    for (identifier, cache_value) in iter(self._values.items()):
        if (not cache_value):
            raise RuntimeError('Missing cache value.')
        if (cache_value.vfs_object == vfs_object):
            return (identifier, cache_value)
    return (None, None)

Retrieves the cache value for the cached object.

Args:
vfs_object (object): VFS object that was cached.

Returns:
tuple[str, ObjectsCacheValue]: identifier and cache value object or
(None, None) if not cached.

Raises:
RuntimeError: if the cache value is missing.


def get_box(self, box_key = None, sort_by = None):

		uri = '/'.join([
						self.api_uri,
						self.boxes_suffix
						])
		if box_key:
			uri = '/'.join([
							uri,
							box_key
							])
		if sort_by:
				if sort_by in ['creationTimestamp', 'lastUpdatedTimestamp']:
					uri += self.sort_by_postfix + sort_by
				else:
					return requests.codes.bad_request, {'success' : 'False',
												'error': 'sortBy needs to be \'creationTimestamp\', or \'lastUpdatedTimestamp\''}
		return self._req('get', uri)

Gets a list of one/all box objects. Performs a single GET.
To go deeper individual boxes need to be polled for their contents.
This is a directory for what we could ask for.
Args:
box_key		key for the target box (default: None i.e. ALL)
sort_by		in desc order by 'creationTimestamp' or 'lastUpdatedTimestamp'
returns 	(status code for the GET request, dict of box or a list thereof)


def create_tasks(self, wfk_file, scr_input):

        assert len(self) == 0
        wfk_file = self.wfk_file = os.path.abspath(wfk_file)

        shell_manager = self.manager.to_shell_manager(mpi_procs=1)

        w = Work(workdir=self.tmpdir.path_join("_qptdm_run"), manager=shell_manager)

        fake_input = scr_input.deepcopy()
        fake_task = w.register(fake_input)
        w.allocate()
        w.build()

        fake_task.inlink_file(wfk_file)
        fake_task.set_vars({"nqptdm": -1})
        fake_task.start_and_wait()

        with NetcdfReader(fake_task.outdir.has_abiext("qptdms.nc")) as reader:
            qpoints = reader.read_value("reduced_coordinates_of_kpoints")

        for qpoint in qpoints:
            qptdm_input = scr_input.deepcopy()
            qptdm_input.set_vars(nqptdm=1, qptdm=qpoint)
            new_task = self.register_scr_task(qptdm_input, manager=self.manager)

            if self.flow.gc is not None:
                new_task.set_gc(self.flow.gc)

        self.allocate()

Create the SCR tasks and register them in self.

Args:
wfk_file: Path to the ABINIT WFK file to use for the computation of the screening.
scr_input: Input for the screening calculation.


def _ScanNode(self, scan_context, scan_node, auto_recurse=True):
    if (not scan_context):
        raise ValueError('Invalid scan context.')
    if (not scan_node):
        raise ValueError('Invalid scan node.')
    scan_path_spec = scan_node.path_spec
    system_level_file_entry = None
    if scan_node.IsSystemLevel():
        system_level_file_entry = resolver.Resolver.OpenFileEntry(scan_node.path_spec, resolver_context=self._resolver_context)
        if (system_level_file_entry is None):
            raise errors.BackEndError('Unable to open file entry.')
        if system_level_file_entry.IsDirectory():
            scan_context.SetSourceType(definitions.SOURCE_TYPE_DIRECTORY)
            return
        source_path_spec = self.ScanForStorageMediaImage(scan_node.path_spec)
        if source_path_spec:
            scan_node.scanned = True
            scan_node = scan_context.AddScanNode(source_path_spec, scan_node)
            if system_level_file_entry.IsDevice():
                source_type = definitions.SOURCE_TYPE_STORAGE_MEDIA_DEVICE
            else:
                source_type = definitions.SOURCE_TYPE_STORAGE_MEDIA_IMAGE
            scan_context.SetSourceType(source_type)
            if (not auto_recurse):
                return
    source_path_spec = None
    while True:
        if scan_node.IsFileSystem():
            break
        if scan_node.SupportsEncryption():
            self._ScanEncryptedVolumeNode(scan_context, scan_node)
        if scan_context.IsLockedScanNode(scan_node.path_spec):
            break
        source_path_spec = self.ScanForVolumeSystem(scan_node.path_spec)
        if (not source_path_spec):
            break
        if (not scan_context.HasScanNode(source_path_spec)):
            scan_node.scanned = True
            scan_node = scan_context.AddScanNode(source_path_spec, scan_node)
            if (system_level_file_entry and system_level_file_entry.IsDevice()):
                source_type = definitions.SOURCE_TYPE_STORAGE_MEDIA_DEVICE
            else:
                source_type = definitions.SOURCE_TYPE_STORAGE_MEDIA_IMAGE
            scan_context.SetSourceType(source_type)
        if scan_node.IsVolumeSystemRoot():
            self._ScanVolumeSystemRootNode(scan_context, scan_node, auto_recurse=auto_recurse)
            return
        if ((not auto_recurse) and scan_context.updated):
            return
        if (not scan_context.updated):
            break
    if scan_node.IsVolumeSystemRoot():
        pass
    elif scan_context.IsLockedScanNode(scan_node.path_spec):
        pass
    elif ((scan_node.type_indicator == definitions.TYPE_INDICATOR_VSHADOW) and auto_recurse and (scan_node.path_spec != scan_path_spec)):
        pass
    elif (not scan_node.IsFileSystem()):
        source_path_spec = self.ScanForFileSystem(scan_node.path_spec)
        if (not source_path_spec):
            if (scan_node.path_spec.type_indicator == definitions.TYPE_INDICATOR_RAW):
                scan_node = scan_context.RemoveScanNode(scan_node.path_spec)
                scan_context.source_type = definitions.SOURCE_TYPE_FILE
            else:
                scan_context.SetSourceType(definitions.SOURCE_TYPE_FILE)
        elif (not scan_context.HasScanNode(source_path_spec)):
            scan_node.scanned = True
            scan_node = scan_context.AddScanNode(source_path_spec, scan_node)
            if (system_level_file_entry and system_level_file_entry.IsDevice()):
                source_type = definitions.SOURCE_TYPE_STORAGE_MEDIA_DEVICE
            else:
                source_type = definitions.SOURCE_TYPE_STORAGE_MEDIA_IMAGE
            scan_context.SetSourceType(source_type)
    if (not scan_node.scanned):
        scan_node.scanned = True

Scans a node for supported formats.

Args:
scan_context (SourceScannerContext): source scanner context.
scan_node (SourceScanNode): source scan node.
auto_recurse (Optional[bool]): True if the scan should automatically
recurse as far as possible.

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


def get(self, request):

        code = request.GET.get("code")

        if not code:

            return render(request, 'django_auth_adfs/login_failed.html', {
                'error_message': "No authorization code was provided.",
            }, status=400)

        redirect_to = request.GET.get("state")

        user = authenticate(request=request, authorization_code=code)

        if user is not None:
            if user.is_active:
                login(request, user)

                if redirect_to:
                    redirect_to = base64.urlsafe_b64decode(redirect_to.encode()).decode()
                else:
                    redirect_to = django_settings.LOGIN_REDIRECT_URL
                url_is_safe = is_safe_url(
                    url=redirect_to,
                    allowed_hosts=[request.get_host()],
                    require_https=request.is_secure(),
                )
                redirect_to = redirect_to if url_is_safe else '/'
                return redirect(redirect_to)
            else:

                return render(request, 'django_auth_adfs/login_failed.html', {
                    'error_message': "Your account is disabled.",
                }, status=403)
        else:

            return render(request, 'django_auth_adfs/login_failed.html', {
                'error_message': "Login failed.",
            }, status=401)

Handles the redirect from ADFS to our site.
We try to process the passed authorization code and login the user.

Args:
request (django.http.request.HttpRequest): A Django Request object


def get_reserved_vlan_range(self, id_or_uri):

        uri = self._client.build_uri(id_or_uri) + "/reserved-vlan-range"
        return self._client.get(uri)

Gets the reserved vlan ID range for the fabric.

Note:
This method is only available on HPE Synergy.

Args:
id_or_uri: ID or URI of fabric.

Returns:
dict: vlan-pool


def performance_curve(self):
    pod = (self.contingency_tables['TP'] / (self.contingency_tables['TP'] + self.contingency_tables['FN']))
    far = (self.contingency_tables['FP'] / (self.contingency_tables['FP'] + self.contingency_tables['TP']))
    far[((self.contingency_tables['FP'] + self.contingency_tables['TP']) == 0)] = np.nan
    return pd.DataFrame({'POD': pod, 'FAR': far, 'Thresholds': self.thresholds}, columns=['POD', 'FAR', 'Thresholds'])

Calculate the Probability of Detection and False Alarm Ratio in order to output a performance diagram.

Returns:
pandas.DataFrame containing POD, FAR, and probability thresholds.


def __init__(self,pos=None,chrom=None,separate_chroms=False):

        assert pos is not None, 'Slider:: set pos'
        assert chrom is not None, 'Slider:: set chrom'

        self.pos   = pos
        self.chrom = chrom

        self.separate_chroms = separate_chroms

        self.windows = None

        self.info   = {}
        pass

Constructor
Args:
pos:        position
chrom:      chromosome


async def addNodes(self, nodedefs):

        for (formname, formvalu), forminfo in nodedefs:

            props = forminfo.get('props')

            if props is not None:
                props.pop('.created', None)

            node = await self.addNode(formname, formvalu, props=props)
            if node is not None:
                tags = forminfo.get('tags')
                if tags is not None:
                    for tag, asof in tags.items():
                        await node.addTag(tag, valu=asof)

            yield node

Add/merge nodes in bulk.

The addNodes API is designed for bulk adds which will
also set properties and add tags to existing nodes.
Nodes are specified as a list of the following tuples:

( (form, valu), {'props':{}, 'tags':{}})

Args:
nodedefs (list): A list of nodedef tuples.

Returns:
(list): A list of xact messages.


def chartspan(cls, start, end):

        return cls(Lnk.CHARTSPAN, (int(start), int(end)))

Create a Lnk object for a chart span.

Args:
start: the initial chart vertex
end: the final chart vertex


def get_enum_from_canonical_name(self, enum_name):

        return next((e for e in self.enums if e.canonical_name == enum_name), None)

Return an enum from a canonical name
Args:
enum_name (str): canonical name of the enum
Returns:
Enum


def get_cartesian(self):

        coords = ['x', 'y', 'z']
        eq_sets = self._metadata['eq']['eq_sets']
        sym_ops = self._metadata['eq']['sym_ops']
        frame = pd.DataFrame(index=[i for v in eq_sets.values() for i in v],
                             columns=['atom', 'x', 'y', 'z'], dtype='f8')
        frame['atom'] = pd.Series(
            {i: self.loc[k, 'atom'] for k, v in eq_sets.items() for i in v})
        frame.loc[self.index, coords] = self.loc[:, coords]
        for i in eq_sets:
            for j in eq_sets[i]:
                frame.loc[j, coords] = np.dot(sym_ops[i][j],
                                              frame.loc[i, coords])
        return Cartesian(frame)

Return a :class:`~Cartesian` where all
members of a symmetry equivalence class are inserted back in.

Args:
None

Returns:
Cartesian: A new cartesian instance.


def inc(self, key, count=1):
    if count < 0:
        raise ValueError('Counter must be monotonically increasing.')
    if not _enabled:
        return
    self._counts[key] = self._counts.get(key, 0) + count
    self._total += count

Increment the metric by the specified amount.

Args:
key: A string to be used as the key.
count: The amount to increment by (non-negative integer).

Raises:
ValueError: if the count is less than 0.


def maybe_append_oov_vectors(embeddings, num_oov_buckets):

  num_embeddings = np.shape(embeddings)[0]
  embedding_dim = np.shape(embeddings)[1]
  embeddings.resize(
      [num_embeddings + num_oov_buckets, embedding_dim], refcheck=False)

Adds zero vectors for oov buckets if num_oov_buckets > 0.

Since we are assigning zero vectors, adding more that one oov bucket is only
meaningful if we perform fine-tuning.

Args:
embeddings: Embeddings to extend.
num_oov_buckets: Number of OOV buckets in the extended embedding.


def make_action(self, fn, schema_parser, meta):
    validate_input = validate_output = None
    if ('$input' in meta):
        with MarkKey('$input'):
            validate_input = schema_parser.parse(meta['$input'])
    if ('$output' in meta):
        with MarkKey('$output'):
            validate_output = schema_parser.parse(meta['$output'])

    def action(data):
        if validate_input:
            try:
                data = validate_input(data)
            except Invalid as ex:
                return abort(400, 'InvalidData', str(ex))
            if isinstance(data, dict):
                rv = fn(**data)
            else:
                rv = fn(data)
        else:
            rv = fn()
        (rv, status, headers) = unpack(rv)
        if validate_output:
            try:
                rv = validate_output(rv)
            except Invalid as ex:
                return abort(500, 'ServerError', str(ex))
        return (rv, status, headers)
    return action

Make resource's method an action

Validate input, output by schema in meta.
If no input schema, call fn without params.
If no output schema, will not validate return value.

Args:
fn: resource's method
schema_parser: for parsing schema in meta
meta: meta data of the action


async def evaluate_model(eval_model_path, target_model_path, sgf_dir, seed):

  lines = await run(
      'bazel-bin/cc/eval',
      '--flagfile={}'.format(os.path.join(FLAGS.flags_dir, 'eval.flags')),
      '--model={}'.format(eval_model_path),
      '--model_two={}'.format(target_model_path),
      '--sgf_dir={}'.format(sgf_dir),
      '--seed={}'.format(seed))
  result = '\n'.join(lines[-7:])
  logging.info(result)
  eval_stats, target_stats = parse_win_stats_table(result, 2)
  num_games = eval_stats.total_wins + target_stats.total_wins
  win_rate = eval_stats.total_wins / num_games
  logging.info('Win rate %s vs %s: %.3f', eval_stats.model_name,
               target_stats.model_name, win_rate)
  return win_rate

Evaluate one model against a target.

Args:
eval_model_path: the path to the model to evaluate.
target_model_path: the path to the model to compare to.
sgf_dif: directory path to write SGF output to.
seed: random seed to use when running eval.

Returns:
The win-rate of eval_model against target_model in the range [0, 1].


def list_groups(name):
    if six.PY2:
        name = _to_unicode(name)
    ugrp = set()
    try:
        user = info(name)['groups']
    except KeyError:
        return False
    for group in user:
        ugrp.add(group.strip(' *'))
    return sorted(list(ugrp))

Return a list of groups the named user belongs to

Args:
name (str): The user name for which to list groups

Returns:
list: A list of groups to which the user belongs

CLI Example:

.. code-block:: bash

salt '*' user.list_groups foo


def getConfigPath(configFileName = None):

    paths = {}
    applicationPath = "./"

    if sys.platform == 'win32':
        applicationPath = os.path.expanduser(os.path.join('~\\', 'OSRFramework'))
    else:
        applicationPath = os.path.expanduser(os.path.join('~/', '.config', 'OSRFramework'))

    paths = {
        "appPath": applicationPath,
        "appPathData": os.path.join(applicationPath, "data"),
        "appPathDefaults": os.path.join(applicationPath, "default"),
        "appPathPlugins": os.path.join(applicationPath, "plugins"),
        "appPathWrappers": os.path.join(applicationPath, "plugins", "wrappers"),
        "appPathPatterns": os.path.join(applicationPath, "plugins", "patterns"),
    }

    for path in paths.keys():
        if not os.path.exists(paths[path]):
            os.makedirs(paths[path])

    return paths

Auxiliar function to get the configuration paths depending on the system

Args:
-----
configFileName: TODO.

Returns:
--------
A dictionary with the following keys: appPath, appPathDefaults,
appPathTransforms, appPathPlugins, appPathPatterns, appPathPatterns.


def macro_state(self, micro_state):
    assert (len(micro_state) == len(self.micro_indices))
    reindexed = self.reindex()
    return utils.state_of(reindexed.output_indices, micro_state)

Compute the macro-state of this blackbox.

This is just the state of the blackbox's output indices.

Args:
micro_state (tuple[int]): The state of the micro-elements in the
blackbox.

Returns:
tuple[int]: The state of the output indices.


def get_historical_data(nmr_problems):

    observations = np.tile(np.array([[10, 256, 202, 97]]), (nmr_problems, 1))
    nmr_tanks_ground_truth = np.ones((nmr_problems,)) * 276
    return observations, nmr_tanks_ground_truth

Get the historical tank data.

Args:
nmr_problems (int): the number of problems

Returns:
tuple: (observations, nmr_tanks_ground_truth)


def delete(self, name, action, seqno):
    return self.configure(('no route-map %s %s %s' % (name, action, seqno)))

Deletes the routemap from the node

Note:
This method will attempt to delete the routemap from the nodes
operational config.  If the routemap does not exist then this
method will not perform any changes but still return True

Args:
name (string): The full name of the routemap.
action (string): The action to take for this routemap clause.
seqno (integer): The sequence number for the routemap clause.

Returns:
True if the routemap could be deleted otherwise False (see Node)


def validate_activation(classifier_activation, weights):
    if weights is None:
        return
    classifier_activation = activations.get(classifier_activation)
    if classifier_activation not in {activations.get('softmax'), activations.get(None)}:
        raise ValueError(f'Only `None` and `softmax` activations are allowed for the `classifier_activation` argument when using pretrained weights, with `include_top=True`; Received: classifier_activation={classifier_activation}')

validates that the classifer_activation is compatible with the weights.

Args:
classifier_activation: str or callable activation function
weights: The pretrained weights to load.

Raises:
ValueError: if an activation other than `None` or `softmax` are used with
pretrained weights.


def generate_hyperband_schedule(self, R, eta):

        schedule = []
        s_max = int(math.floor(math.log(R, eta)))

        for s in range(0, s_max + 1):
            n = math.ceil(int((s_max + 1) / (s + 1)) * eta ** s)
            r = R * eta ** (-s)
            bracket = []
            for i in range(0, s + 1):
                n_i = int(math.floor(n * eta ** (-i)))
                r_i = int(r * eta ** i)
                bracket.append((n_i, r_i))
            schedule = [bracket] + schedule
        return schedule

Generate hyperband schedule according to the paper.

Args:
R: maximum resources per config.
eta: proportion of configruations to discard per
iteration of successive halving.

Returns: hyperband schedule, which is represented
as a list of brackets, where each bracket
contains a list of (num configurations,
num resources to use per configuration).
See the paper for more details.


def _infer_output_coder(self, input_type=None, input_coder=None):
    return None

Returns the output coder to use for output of this transform.

The Coder returned here should not be wrapped in a WindowedValueCoder
wrapper.

Args:
input_type: An instance of an allowed built-in type, a custom class, or a
typehints.TypeConstraint for the input type, or None if not available.
input_coder: Coder object for encoding input to this PTransform, or None
if not available.

Returns:
Coder object for encoding output of this PTransform or None if unknown.


def _ConvertInteger(value):
    if (isinstance(value, float) and (not value.is_integer())):
        raise ParseError("Couldn't parse integer: {0}.".format(value))
    if (isinstance(value, six.text_type) and (value.find(' ') != (- 1))):
        raise ParseError('Couldn\'t parse integer: "{0}".'.format(value))
    return int(value)

Convert an integer.

Args:
value: A scalar value to convert.

Returns:
The integer value.

Raises:
ParseError: If an integer couldn't be consumed.


def is_on_curve(self, point):
    (X, Y) = (point.X, point.Y)
    return (((((pow(Y, 2, self.P) - pow(X, 3, self.P)) - (self.a * X)) - self.b) % self.P) == 0)

Checks whether a point is on the curve.

Args:
point (AffinePoint): Point to be checked.

Returns:
bool: True if point is on the curve, False otherwise.


def _DownloadScript(self, url, dest_dir):
    if url.startswith('gs:
        url = re.sub('^gs:
        return self._DownloadAuthUrl(url, dest_dir)
    header = 'http[s]?:
    domain = 'storage\\.googleapis\\.com'
    bucket = '(?P<bucket>[a-z0-9][-_.a-z0-9]*[a-z0-9])'
    obj = '(?P<obj>[^\\*\\?]+)'
    gs_regex = re.compile(('\\A%s%s\\.%s/%s\\Z' % (header, bucket, domain, obj)))
    match = gs_regex.match(url)
    if match:
        return self._DownloadAuthUrl(url, dest_dir)
    gs_regex = re.compile(('\\A%s(commondata)?%s/%s/%s\\Z' % (header, domain, bucket, obj)))
    match = gs_regex.match(url)
    if match:
        return self._DownloadAuthUrl(url, dest_dir)
    return self._DownloadUrl(url, dest_dir)

Download the contents of the URL to the destination.

Args:
url: string, the URL to download.
dest_dir: string, the path to a directory for storing metadata scripts.

Returns:
string, the path to the file storing the metadata script.