class Speech2TextProcessor(ProcessorMixin):
    feature_extractor_class = 'Speech2TextFeatureExtractor'
    tokenizer_class = 'Speech2TextTokenizer'

    def __init__(self, feature_extractor, tokenizer):
        super().__init__(feature_extractor, tokenizer)
        self.current_processor = self.feature_extractor
        self._in_target_context_manager = False

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

        if self._in_target_context_manager:
            return self.current_processor(*args, **kwargs)
        if 'raw_speech' in kwargs:
            warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.')
            audio = kwargs.pop('raw_speech')
        else:
            audio = kwargs.pop('audio', None)
        sampling_rate = kwargs.pop('sampling_rate', None)
        text = kwargs.pop('text', None)
        if len(args) > 0:
            audio = args[0]
            args = args[1:]
        if audio is None and text is None:
            raise ValueError('You need to specify either an `audio` or `text` input to process.')
        if audio is not None:
            inputs = self.feature_extractor(audio, *args, sampling_rate=sampling_rate, **kwargs)
        if text is not None:
            encodings = self.tokenizer(text, **kwargs)
        if text is None:
            return inputs
        elif audio is None:
            return encodings
        else:
            inputs['labels'] = encodings['input_ids']
            return inputs

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

        return self.tokenizer.batch_decode(*args, **kwargs)

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

        return self.tokenizer.decode(*args, **kwargs)

    @contextmanager
    def as_target_processor(self):

        warnings.warn('`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your labels by using the argument `text` of the regular `__call__` method (either in the same call as your audio inputs, or in a separate call.')
        self._in_target_context_manager = True
        self.current_processor = self.tokenizer
        yield
        self.current_processor = self.feature_extractor
        self._in_target_context_manager = False

Constructs a Speech2Text processor which wraps a Speech2Text feature extractor and a Speech2Text tokenizer into a
single processor.

[`Speech2TextProcessor`] offers all the functionalities of [`Speech2TextFeatureExtractor`] and
[`Speech2TextTokenizer`]. See the [`~Speech2TextProcessor.__call__`] and [`~Speech2TextProcessor.decode`] for more
information.

Args:
feature_extractor (`Speech2TextFeatureExtractor`):
An instance of [`Speech2TextFeatureExtractor`]. The feature extractor is a required input.
tokenizer (`Speech2TextTokenizer`):
An instance of [`Speech2TextTokenizer`]. The tokenizer is a required input.


def _ProcessDirectory(self, mediator, file_entry):

    self.processing_status = definitions.STATUS_INDICATOR_COLLECTING

    if self._processing_profiler:
      self._processing_profiler.StartTiming('collecting')

    for sub_file_entry in file_entry.sub_file_entries:
      if self._abort:
        break

      try:
        if not sub_file_entry.IsAllocated():
          continue

      except dfvfs_errors.BackEndError as exception:
        warning_message = (
            'unable to process directory entry: {0:s} with error: '
            '{1!s}').format(sub_file_entry.name, exception)
        mediator.ProduceExtractionWarning(
            warning_message, path_spec=file_entry.path_spec)
        continue

      if sub_file_entry.type_indicator == dfvfs_definitions.TYPE_INDICATOR_TSK:
        if file_entry.IsRoot() and sub_file_entry.name == '$OrphanFiles':
          continue

      event_source = event_sources.FileEntryEventSource(
          path_spec=sub_file_entry.path_spec)

      stat_object = sub_file_entry.GetStat()
      if stat_object:
        event_source.file_entry_type = stat_object.type

      mediator.ProduceEventSource(event_source)

      self.last_activity_timestamp = time.time()

    if self._processing_profiler:
      self._processing_profiler.StopTiming('collecting')

    self.processing_status = definitions.STATUS_INDICATOR_RUNNING

Processes a directory file entry.

Args:
mediator (ParserMediator): mediates the interactions between
parsers and other components, such as storage and abort signals.
file_entry (dfvfs.FileEntry): file entry of the directory.


def _base_expansion_size(num, bases):
    return (tf.floor((tf.math.log(num) / tf.math.log(bases))) + 1)

Computes the number of terms in the place value expansion.

Let num = a0 + a1 b + a2 b^2 + ... ak b^k be the place value expansion of
`num` in base b (ak <> 0). This function computes and returns `k+1` for each
base `b` specified in `bases`.

This can be inferred from the base `b` logarithm of `num` as follows:
$$k = Floor(log_b (num)) + 1  = Floor( log(num) / log(b)) + 1$$

Args:
num: Scalar `Tensor` of dtype either `float32` or `float64`. The number to
compute the base expansion size of.
bases: `Tensor` of the same dtype as num. The bases to compute the size
against.

Returns:
Tensor of same dtype and shape as `bases` containing the size of num when
written in that base.


def __init__(self, replacements):
    self.replacements = replacements
    self.in_replacements = False
    self.preserved_annos = {anno.Basic.DIRECTIVES, anno.Basic.EXTRA_LOOP_TEST, anno.Basic.ORIGIN, anno.Basic.SKIP_PROCESSING, anno.Static.ORIG_DEFINITIONS, 'function_context_name'}

Create a new ReplaceTransformer.

Args:
replacements: A mapping from placeholder names to (lists of) AST nodes
that these placeholders will be replaced by.


def _list_valid_filenames_in_directory(directory, white_list_formats, split, class_indices, follow_links):
    dirname = os.path.basename(directory)
    if split:
        all_files = list(_iter_valid_files(directory, white_list_formats, follow_links))
        num_files = len(all_files)
        start, stop = (int(split[0] * num_files), int(split[1] * num_files))
        valid_files = all_files[start:stop]
    else:
        valid_files = _iter_valid_files(directory, white_list_formats, follow_links)
    classes = []
    filenames = []
    for root, fname in valid_files:
        classes.append(class_indices[dirname])
        absolute_path = os.path.join(root, fname)
        relative_path = os.path.join(dirname, os.path.relpath(absolute_path, directory))
        filenames.append(relative_path)
    return (classes, filenames)

Lists paths of files in `subdir` with extensions in `white_list_formats`.

Args:
directory: absolute path to a directory containing the files to list.
The directory name is used as class label
and must be a key of `class_indices`.
white_list_formats: set of strings containing allowed extensions for
the files to be counted.
split: tuple of floats (e.g. `(0.2, 0.6)`) to only take into
account a certain fraction of files in each directory.
E.g.: `segment=(0.6, 1.0)` would only account for last 40 percent
of images in each directory.
class_indices: dictionary mapping a class name to its index.
follow_links: boolean, follow symbolic links to subdirectories.

Returns:
classes: a list of class indices
filenames: the path of valid files in `directory`, relative from
`directory`'s parent (e.g., if `directory` is "dataset/class1",
the filenames will be
`["class1/file1.jpg", "class1/file2.jpg", ...]`).


def lengths(self):
    return np.array([math.sqrt(sum((row ** 2))) for row in self.matrix])

The cell lengths.

Args:
None

Returns:
(np.array(a,b,c)): The cell lengths.


def schema(self):
    if (not self._schema):
        try:
            self._load_info()
            self._schema = _schema.Schema(self._info['schema']['fields'])
        except KeyError:
            raise Exception('Unexpected table response: missing schema')
    return self._schema

Retrieves the schema of the table.

Returns:
A Schema object containing a list of schema fields and associated metadata.
Raises
Exception if the request could not be executed or the response was malformed.


def _generate_enqueue_op(self, flat_inputs: List[internal_types.NativeObject], flat_weights: List[Optional[internal_types.NativeObject]], flat_features: List[tpu_embedding_v2_utils.FeatureConfig], device_ordinal: int, mode_override: Text) -> ops.Operation:
    combiners = [table.combiner for table in self._table_config]
    indices_or_row_splits = []
    values = []
    weights = []
    int_zeros = array_ops.zeros((0,), dtype=dtypes.int32)
    float_zeros = array_ops.zeros((0,), dtype=dtypes.float32)
    for inp, weight, (path, feature) in zip(flat_inputs, flat_weights, flat_features):
        if isinstance(inp, tensor_lib.Tensor):
            self._add_data_for_tensor(inp, weight, indices_or_row_splits, values, weights, int_zeros, float_zeros, path)
        elif isinstance(inp, sparse_tensor.SparseTensor):
            self._add_data_for_sparse_tensor(inp, weight, indices_or_row_splits, values, weights, int_zeros, float_zeros, path, feature)
        elif isinstance(inp, ragged_tensor.RaggedTensor):
            self._add_data_for_ragged_tensor(inp, weight, indices_or_row_splits, values, weights, int_zeros, float_zeros, path, feature)
        else:
            raise ValueError('Input {} is of unknown type {}. Please only pass Tensor, SparseTensor or RaggedTensor as input to enqueue.'.format(path, type(inp)))
    return tpu_ops.enqueue_tpu_embedding_arbitrary_tensor_batch(sample_indices_or_row_splits=indices_or_row_splits, embedding_indices=values, aggregation_weights=weights, mode_override=mode_override, device_ordinal=device_ordinal, combiners=combiners)

Outputs a the enqueue op given the inputs and weights.

Args:
flat_inputs: A list of input tensors.
flat_weights: A list of input weights (or None) of the same length as
flat_inputs.
flat_features: A list of FeatureConfigs of the same length as flat_inputs.
device_ordinal: The device to create the enqueue op for.
mode_override: A tensor containing the string "train" or "inference".

Returns:
The enqueue op.


def import_object_from_string_code(code, object):

    sha256 = hashlib.sha256(code.encode('UTF-8')).hexdigest()
    module = imp.new_module(sha256)
    try:
        exec_(code, module.__dict__)
    except Exception as e:
        raise exceptions.UserError('User code exception', exception_message=str(e))
    sys.modules[sha256] = module
    try:
        return getattr(module, object)
    except AttributeError:
        raise exceptions.UserError("{} not found in code".format(object))

Used to import an object from arbitrary passed code.

Passed in code is treated as a module and is imported and added
to `sys.modules` with its SHA256 hash as key.

Args:
code (string): Python code to import as module

object (string): Name of object to extract from imported module


def _setup_parser(self, filename=None):

        assert isinstance(filename, str) or filename is None

        if not filename:
            filename = MACKUP_CONFIG_FILE

        parser = configparser.SafeConfigParser(allow_no_value=True)
        parser.read(os.path.join(os.path.join(os.environ['HOME'], filename)))

        return parser

Configure the ConfigParser instance the way we want it.

Args:
filename (str) or None

Returns:
SafeConfigParser


def save(self, **fields):
    for field in fields:
        if (field in self.writable_fields):
            setattr(self, field, fields[field])
        else:
            self._handle_wrong_field(field, ATTR_TYPE_WRITE)
    if self._populated_fields:
        self._update(**self._modified_fields)
    else:
        self._create(**self._modified_fields)

Save the instance to the remote Transifex server.

If it was pre-populated, it updates the instance on the server,
otherwise it creates a new object.

Any values given in `fields` will be attempted to be saved
on the object. The same goes for any other values already set
to the object by `model_instance.attr = value`.

Raises:
AttributeError: if a given field is not included in
`self.writable_fields`,


def new_from_list(cls, content, fill_title=True, **kwargs):

        obj = cls(**kwargs)
        obj.append_from_list(content, fill_title)
        return obj

Populates the Table with a list of tuples of strings.

Args:
content (list): list of tuples of strings. Each tuple is a row.
fill_title (bool): if true, the first tuple in the list will
be set as title


def get_element_spd_dos(self, el):

        el = get_el_sp(el)
        el_dos = {}
        for site, atom_dos in self.pdos.items():
            if site.specie == el:
                for orb, pdos in atom_dos.items():
                    orbital_type = _get_orb_type_lobster(orb)
                    if orbital_type not in el_dos:
                        el_dos[orbital_type] = pdos
                    else:
                        el_dos[orbital_type] = \
                            add_densities(el_dos[orbital_type], pdos)

        return {orb: Dos(self.efermi, self.energies, densities)
                for orb, densities in el_dos.items()}

Get element and spd projected Dos

Args:
el: Element in Structure.composition associated with LobsterCompleteDos

Returns:
dict of {Element: {"S": densities, "P": densities, "D": densities}}


def dispatch_callback(self, items):

        if not self._manager.is_active:
            return

        batched_commands = collections.defaultdict(list)

        for item in items:
            batched_commands[item.__class__].append(item)

        _LOGGER.debug("Handling %d batched requests", len(items))

        if batched_commands[requests.LeaseRequest]:
            self.lease(batched_commands.pop(requests.LeaseRequest))
        if batched_commands[requests.ModAckRequest]:
            self.modify_ack_deadline(batched_commands.pop(requests.ModAckRequest))

        if batched_commands[requests.AckRequest]:
            self.ack(batched_commands.pop(requests.AckRequest))
        if batched_commands[requests.NackRequest]:
            self.nack(batched_commands.pop(requests.NackRequest))
        if batched_commands[requests.DropRequest]:
            self.drop(batched_commands.pop(requests.DropRequest))

Map the callback request to the appropriate gRPC request.

Args:
action (str): The method to be invoked.
kwargs (Dict[str, Any]): The keyword arguments for the method
specified by ``action``.

Raises:
ValueError: If ``action`` isn't one of the expected actions
"ack", "drop", "lease", "modify_ack_deadline" or "nack".


def _compute_nfps_uniform(cum_counts, sizes):

    nfps = np.zeros((len(sizes), len(sizes)))

    for l in range(len(sizes)):
        for u in range(l, len(sizes)):
            nfps[l, u] = _compute_nfp_uniform(l, u, cum_counts, sizes)
    return nfps

Computes the matrix of expected false positives for all possible
sub-intervals of the complete domain of set sizes, assuming uniform
distribution of set_sizes within each sub-intervals.

Args:
cum_counts: the complete cummulative distribution of set sizes.
sizes: the complete domain of set sizes.

Return (np.array): the 2-D array of expected number of false positives
for every pair of [l, u] interval, where l is axis-0 and u is
axis-1.


def loadFunction(self, root):
    for element in root.iter():
        if (element.tag == 'function'):
            self.functionList.append(element.attrib['name'])

Loads a list with all the functions in the Fortran File

Args:
root: The root of the XML ast tree.

Returns:
None

Does not return anything but populates a list (self.functionList) that
contains all the functions in the Fortran File.


def _GetApprovals(self, approval_type, offset, count, filter_func=None, token=None):
    approvals_base_urn = aff4.ROOT_URN.Add('users').Add(token.username).Add('approvals').Add(approval_type)
    all_children = aff4.FACTORY.RecursiveMultiListChildren([approvals_base_urn])
    approvals_urns = []
    for (subject, children) in all_children:
        if children:
            continue
        approvals_urns.append(subject)
    approvals_urns.sort(key=(lambda x: x.age), reverse=True)
    approvals = list(aff4.FACTORY.MultiOpen(approvals_urns, mode='r', aff4_type=aff4_security.Approval, age=aff4.ALL_TIMES, token=token))
    approvals_by_urn = {}
    for approval in approvals:
        approvals_by_urn[(approval.symlink_urn or approval.urn)] = approval
    cur_offset = 0
    sorted_approvals = []
    for approval_urn in approvals_urns:
        try:
            approval = approvals_by_urn[approval_urn]
        except KeyError:
            continue
        if ((filter_func is not None) and (not filter_func(approval))):
            continue
        cur_offset += 1
        if (cur_offset <= offset):
            continue
        if (count and (len(sorted_approvals) >= count)):
            break
        sorted_approvals.append(approval)
    subjects_urns = [a.Get(a.Schema.SUBJECT) for a in approvals]
    subjects_by_urn = {}
    for subject in aff4.FACTORY.MultiOpen(subjects_urns, mode='r', token=token):
        subjects_by_urn[subject.urn] = subject
    return (sorted_approvals, subjects_by_urn)

Gets all approvals for a given user and approval type.

Args:
approval_type: The type of approvals to get.
offset: The starting index within the collection.
count: The number of items to return.
filter_func: A predicate function, returning True if a specific approval
should be included in the result and False otherwise.
token: The token identifying the user.

Returns:
A list of approvals of the given approval type.


def create(self, name, targetUrl, resource, event, filter=None, secret=None, **request_parameters):
    check_type(name, basestring, may_be_none=False)
    check_type(targetUrl, basestring, may_be_none=False)
    check_type(resource, basestring, may_be_none=False)
    check_type(event, basestring, may_be_none=False)
    check_type(filter, basestring)
    check_type(secret, basestring)
    post_data = dict_from_items_with_values(request_parameters, name=name, targetUrl=targetUrl, resource=resource, event=event, filter=filter, secret=secret)
    json_data = self._session.post(API_ENDPOINT, json=post_data)
    return self._object_factory(OBJECT_TYPE, json_data)

Create a webhook.

Args:
name(basestring): A user-friendly name for this webhook.
targetUrl(basestring): The URL that receives POST requests for
each event.
resource(basestring): The resource type for the webhook.
event(basestring): The event type for the webhook.
filter(basestring): The filter that defines the webhook scope.
secret(basestring): The secret used to generate payload signature.
**request_parameters: Additional request parameters (provides
support for parameters that may be added in the future).

Returns:
Webhook: A Webhook object with the details of the created webhook.

Raises:
TypeError: If the parameter types are incorrect.
ApiError: If the Webex Teams cloud returns an error.


def _split_cell(cell, module):

  lines = cell.split('\n')
  code = None
  last_def = -1
  name = None
  define_wild_re = re.compile('^DEFINE\s+.*$', re.IGNORECASE)
  define_re = re.compile('^DEFINE\s+QUERY\s+([A-Z]\w*)\s*?(.*)$', re.IGNORECASE)
  select_re = re.compile('^SELECT\s*.*$', re.IGNORECASE)
  standard_sql_re = re.compile('^(CREATE|WITH|INSERT|DELETE|UPDATE)\s*.*$', re.IGNORECASE)

  for i, line in enumerate(lines):
    define_match = define_re.match(line)
    select_match = select_re.match(line)
    standard_sql_match = standard_sql_re.match(line)

    if i:
      prior_content = ''.join(lines[:i]).strip()
      if select_match:

        select_match = len(prior_content) == 0 or \
            (prior_content[-1] != '(' and not standard_sql_re.match(prior_content))
      if standard_sql_match:
        standard_sql_match = len(prior_content) == 0 or not standard_sql_re.match(prior_content)

    if define_match or select_match or standard_sql_match:

      if code is None:
        code = ('\n'.join(lines[:i])).strip()
        if len(code):
          code += '\n'
      elif last_def >= 0:

        query = '\n'.join([line for line in lines[last_def:i] if len(line)]).strip()
        if select_match and name != datalab.data._utils._SQL_MODULE_MAIN and len(query) == 0:

          continue

        statement = datalab.data.SqlStatement(query, module)
        module.__dict__[name] = statement

        module.__dict__[datalab.data._utils._SQL_MODULE_LAST] = statement

      if define_match:
        name = define_match.group(1)
        lines[i] = define_match.group(2)
      else:
        name = datalab.data._utils._SQL_MODULE_MAIN

      last_def = i
    else:
      define_wild_match = define_wild_re.match(line)
      if define_wild_match:
        raise Exception('Expected "DEFINE QUERY <name>"')

  if last_def >= 0:

    query = '\n'.join([line for line in lines[last_def:] if len(line)]).strip()
    statement = datalab.data.SqlStatement(query, module)
    module.__dict__[name] = statement
    module.__dict__[datalab.data._utils._SQL_MODULE_LAST] = statement

  if code is None:
    code = ''
  module.__dict__[datalab.data._utils._SQL_MODULE_ARGPARSE] = _arguments(code, module)
  return module.__dict__.get(datalab.data._utils._SQL_MODULE_LAST, None)

Split a hybrid %%sql cell into the Python code and the queries.

Populates a module with the queries.

Args:
cell: the contents of the %%sql cell.
module: the module that the contents will populate.

Returns:
The default (last) query for the module.


def __init__(self, directory, container, entry_point, use_gpu):

    self.name = os.path.basename(directory)
    self.directory = directory
    self.container = container
    self.entry_point = entry_point
    self.use_gpu = use_gpu

Initializes instance of Submission class.

Args:
directory: location of the submission.
container: URL of Docker container which should be used to run submission.
entry_point: entry point script, which invokes submission.
use_gpu: whether to use Docker with GPU or not.


def __init__(self, name, transition_min=258.15, transition_max=298.15,
                 transition_gamma=3.0, **kwargs):

        self.transition_min = transition_min
        self.transition_max = transition_max
        self.transition_gamma = transition_gamma
        super(CloudCompositor, self).__init__(name, **kwargs)

Collect custom configuration values.

Args:
transition_min (float): Values below or equal to this are
clouds -> opaque white
transition_max (float): Values above this are
cloud free -> transparent
transition_gamma (float): Gamma correction to apply at the end


def consolidate(self, args):

        result = dict(args)

        for opt in self:
            if opt.name in result:
                result[opt.name] = opt.convert(result[opt.name])
            else:
                if opt.default is not None:
                    result[opt.name] = opt.convert(opt.default)

        return result

Consolidate the provided arguments.

If the provided arguments have matching options, this performs a type conversion.
For any option that has a default value and is not present in the provided
arguments, the default value is added.

Args:
args (dict): A dictionary of the provided arguments.

Returns:
dict: A dictionary with the type converted and with default options enriched
arguments.


def process_api_config_response(self, config_json):
    with self._config_lock:
        self._add_discovery_config()
        for config in config_json.get('items', []):
            lookup_key = (config.get('name', ''), config.get('version', ''))
            self._configs[lookup_key] = config
        for config in self._configs.itervalues():
            name = config.get('name', '')
            api_version = config.get('api_version', '')
            path_version = config.get('path_version', '')
            sorted_methods = self._get_sorted_methods(config.get('methods', {}))
            for (method_name, method) in sorted_methods:
                self._save_rest_method(method_name, name, path_version, method)

Parses a JSON API config and registers methods for dispatch.

Side effects:
Parses method name, etc. for all methods and updates the indexing
data structures with the information.

Args:
config_json: A dict, the JSON body of the getApiConfigs response.


def create_datastore(self, schema=None, primary_key=None, delete_first=0, path=None):
    if (delete_first == 0):
        pass
    elif (delete_first == 1):
        self.delete_datastore()
    elif (delete_first == 2):
        if (primary_key is None):
            self.delete_datastore()
    else:
        raise HDXError('delete_first must be 0, 1 or 2! (0 = No, 1 = Yes, 2 = Delete if no primary key)')
    if (path is None):
        (url, path) = self.download()
        delete_after_download = True
    else:
        url = path
        delete_after_download = False

    def convert_to_text(extended_rows):
        for (number, headers, row) in extended_rows:
            for (i, val) in enumerate(row):
                row[i] = str(val)
            (yield (number, headers, row))
    with Download(full_agent=self.configuration.get_user_agent()) as downloader:
        try:
            stream = downloader.get_tabular_stream(path, headers=1, post_parse=[convert_to_text], bytes_sample_size=1000000)
            nonefieldname = False
            if (schema is None):
                schema = list()
                for fieldname in stream.headers:
                    if (fieldname is not None):
                        schema.append({'id': fieldname, 'type': 'text'})
                    else:
                        nonefieldname = True
            data = {'resource_id': self.data['id'], 'force': True, 'fields': schema, 'primary_key': primary_key}
            self._write_to_hdx('datastore_create', data, 'resource_id')
            if (primary_key is None):
                method = 'insert'
            else:
                method = 'upsert'
            logger.debug(('Uploading data from %s to datastore' % url))
            offset = 0
            chunksize = 100
            rowset = stream.read(keyed=True, limit=chunksize)
            while (len(rowset) != 0):
                if nonefieldname:
                    for row in rowset:
                        del row[None]
                data = {'resource_id': self.data['id'], 'force': True, 'method': method, 'records': rowset}
                self._write_to_hdx('datastore_upsert', data, 'resource_id')
                rowset = stream.read(keyed=True, limit=chunksize)
                logger.debug(('Uploading: %s' % offset))
                offset += chunksize
        except Exception as e:
            raisefrom(HDXError, ('Upload to datastore of %s failed!' % url), e)
        finally:
            if delete_after_download:
                remove(path)

For tabular data, create a resource in the HDX datastore which enables data preview in HDX. If no schema is provided
all fields are assumed to be text. If path is not supplied, the file is first downloaded from HDX.

Args:
schema (List[Dict]): List of fields and types of form {'id': 'FIELD', 'type': 'TYPE'}. Defaults to None.
primary_key (Optional[str]): Primary key of schema. Defaults to None.
delete_first (int): Delete datastore before creation. 0 = No, 1 = Yes, 2 = If no primary key. Defaults to 0.
path (Optional[str]): Local path to file that was uploaded. Defaults to None.

Returns:
None


def jump_if(state, op, ctx, *, jump_if_val, pop=PopBehavior.NONE):
    if pop is PopBehavior.ALWAYS:
        state, value = state.pop()
    else:
        value = state.top()
    if jump_if_val is None:
        normal_val = frame_state.NOT_NONE
    elif jump_if_val is frame_state.NOT_NONE:
        normal_val = None
    elif isinstance(jump_if_val, bool):
        normal_val = not jump_if_val
    else:
        raise NotImplementedError(f'Unsupported jump value: {jump_if_val!r}')
    jump = frame_state.restrict_condition(state.node, value, jump_if_val)
    normal = frame_state.restrict_condition(state.node, value, normal_val)
    if jump is not frame_state.UNSATISFIABLE:
        if jump:
            assert jump.binding
            else_state = state.forward_cfg_node('Jump', jump.binding).forward_cfg_node('Jump')
        else:
            else_state = state.forward_cfg_node('Jump')
        ctx.vm.store_jump(op.target, else_state)
    else:
        else_state = None
    if pop is PopBehavior.OR:
        state = state.pop_and_discard()
    if normal is frame_state.UNSATISFIABLE:
        return state.set_why('unsatisfiable')
    elif not else_state and (not normal):
        return state
    else:
        return state.forward_cfg_node('NoJump', normal.binding if normal else None)

Implementation of various _JUMP_IF bytecodes.

Args:
state: Initial FrameState.
op: An opcode.
ctx: The current context.
jump_if_val: Indicates what value leads to a jump. The non-jump state is
reached by the value's negation. Use frame_state.NOT_NONE for `not None`.
pop: Whether and how the opcode pops a value off the stack.

Returns:
The new FrameState.


def WriteEventBody(self, event):

    output_string = NativePythonFormatterHelper.GetFormattedEventObject(event)
    self._output_writer.Write(output_string)

Writes the body of an event to the output.

Args:
event (EventObject): event.


def _initialize_operations(self):
    if isinstance(self._graph, tf.Graph):
        return self._graph.get_operations()
    elif isinstance(self._graph, mtf.Graph):
        return self._graph.operations
    else:
        raise TypeError('Graph is not tf.Graph or mtf.Graph: {}'.format(type(self._graph)))

Initializer for _operations.

Raises:
TypeError: _graph is not a tf.Graph or mtf.Graph.

Returns:
a list of (tf.Operation or mtf.Operation)


def UpdateTaskAsProcessingByIdentifier(self, task_identifier):

    with self._lock:
      task_processing = self._tasks_processing.get(task_identifier, None)
      if task_processing:
        task_processing.UpdateProcessingTime()
        self._UpdateLatestProcessingTime(task_processing)
        return

      task_queued = self._tasks_queued.get(task_identifier, None)
      if task_queued:
        logger.debug('Task {0:s} was queued, now processing.'.format(
            task_identifier))
        self._tasks_processing[task_identifier] = task_queued
        del self._tasks_queued[task_identifier]

        task_queued.UpdateProcessingTime()
        self._UpdateLatestProcessingTime(task_queued)
        return

      task_abandoned = self._tasks_abandoned.get(task_identifier, None)
      if task_abandoned:
        del self._tasks_abandoned[task_identifier]
        self._tasks_processing[task_identifier] = task_abandoned
        logger.debug('Task {0:s} was abandoned, but now processing.'.format(
            task_identifier))

        task_abandoned.UpdateProcessingTime()
        self._UpdateLatestProcessingTime(task_abandoned)
        return

      if task_identifier in self._tasks_pending_merge:

        return

    raise KeyError('Status of task {0:s} is unknown.'.format(task_identifier))

Updates the task manager to reflect the task is processing.

Args:
task_identifier (str): unique identifier of the task.

Raises:
KeyError: if the task is not known to the task manager.


def get_run_key(feed_dict, fetches):
    return json.dumps(RunKey(get_flattened_names(feed_dict), get_flattened_names(fetches)))

Summarize the names of feeds and fetches as a RunKey JSON string.

Args:
feed_dict: The feed_dict given to the `Session.run()` call.
fetches: The fetches from the `Session.run()` call.

Returns:
A JSON Array consisting of two items. They first items is a flattened
Array of the names of the feeds. The second item is a flattened Array of
the names of the fetches.


def operations_happening_at_same_time_as(self, scheduled_operation: ScheduledOperation) -> List[ScheduledOperation]:
    overlaps = self.query(time=scheduled_operation.time, duration=scheduled_operation.duration)
    return [e for e in overlaps if (e != scheduled_operation)]

Finds operations happening at the same time as the given operation.

Args:
scheduled_operation: The operation specifying the time to query.

Returns:
Scheduled operations that overlap with the given operation.


def has_axon(neuron, treefun=_read_neurite_type):

    return CheckResult(NeuriteType.axon in (treefun(n) for n in neuron.neurites))

Check if a neuron has an axon

Arguments:
neuron(Neuron): The neuron object to test
treefun: Optional function to calculate the tree type of
neuron's neurites

Returns:
CheckResult with result


def get_block(self, block_id):
    block = backend.query.get_block(self.connection, block_id)
    latest_block = self.get_latest_block()
    latest_block_height = (latest_block['height'] if latest_block else 0)
    if ((not block) and (block_id > latest_block_height)):
        return
    result = {'height': block_id, 'transactions': []}
    if block:
        transactions = backend.query.get_transactions(self.connection, block['transactions'])
        result['transactions'] = [t.to_dict() for t in Transaction.from_db(self, transactions)]
    return result

Get the block with the specified `block_id`.

Returns the block corresponding to `block_id` or None if no match is
found.

Args:
block_id (int): block id of the block to get.


def pad(self, image: np.array, data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None):
    height, width = get_image_size(image)
    size = max(height, width)
    image = pad(image=image, padding=((0, size - height), (0, size - width)), constant_values=0.5, data_format=data_format, input_data_format=input_data_format)
    return image

Pad an image to a square with gray pixels on the bottom and the right, as per the original OWLv2
implementation.

Args:
image (`np.ndarray`):
Image to pad.
data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format of the image. If not provided, it will be the same as the input image.
input_data_format (`ChannelDimension` or `str`, *optional*):
The channel dimension format of the input image. If not provided, it will be inferred from the input
image.


def get_charge_transfer(self, atom_index):
    if (self.potcar is None):
        raise ValueError('POTCAR must be supplied in order to calculate charge transfer!')
    potcar_indices = []
    for (i, v) in enumerate(self.natoms):
        potcar_indices += ([i] * v)
    nelect = self.potcar[potcar_indices[atom_index]].nelectrons
    return (self.data[atom_index]['charge'] - nelect)

Returns the charge transferred for a particular atom. Requires POTCAR
to be supplied.

Args:
atom_index:
Index of atom.

Returns:
Charge transfer associated with atom from the Bader analysis.
Given by final charge on atom - nelectrons in POTCAR for
associated atom.


def visualize_reconstruction(inputs, reconstruct, num=3, name="reconstruction"):

  reconstruct = tf.clip_by_value(reconstruct, 0., 1.)
  inputs_and_reconstruct = tf.concat((inputs[:num], reconstruct[:num]), axis=0)
  image_summary(inputs_and_reconstruct, name)

Visualizes the reconstruction of inputs in TensorBoard.

Args:
inputs: A tensor of the original inputs, of shape [batch, timesteps,
h, w, c].
reconstruct: A tensor of a reconstruction of inputs, of shape
[batch, timesteps, h, w, c].
num: Integer for the number of examples to visualize.
name: String name of this summary.


def convert_per_replica_to_dtensor(per_replica_value, mesh):
    values = per_replica_value.values
    if isinstance(values[0], (float, int)):
        rank = 0
    else:
        rank = len(values[0].shape)
    if rank == 0:
        result = []
        for v in values:
            result.append(array_ops.expand_dims_v2(v, axis=0))
        rank += 1
    else:
        result = list(values)
    batch_layout = layout.Layout.batch_sharded(mesh, batch_dim=DEFAULT_BATCH_MESH_DIM_NAME, rank=rank)
    return d_api.pack(result, batch_layout)

Convert a PerReplica result to a DTensor instance.

Args:
per_replica_value: A PerReplica instance whose value will be converted
to DTensor.
mesh: The mesh used for layout creation.

Returns:
A DTensor instance that packed from per_replica_value with batch sharded
layout.


def switch_types(self):
    if (not self.__switch_types):
        self.__switch_types = SwitchTypes(self.__connection)
    return self.__switch_types

Gets the SwitchTypes API client.

Returns:
SwitchTypes:


def __init__(self, storage_writer, path):

    super(SQLiteStorageMergeReader, self).__init__(storage_writer)
    self._active_container_type = None
    self._active_cursor = None
    self._add_active_container_method = None
    self._add_container_type_methods = {}
    self._compression_format = definitions.COMPRESSION_FORMAT_NONE
    self._connection = None
    self._container_types = None
    self._cursor = None
    self._event_data_identifier_mappings = {}
    self._path = path

    for container_type, method_name in self._ADD_CONTAINER_TYPE_METHODS.items():
      method = getattr(self, method_name, None)
      if not method:
        raise RuntimeError(
            'Add method missing for container type: {0:s}'.format(
                container_type))

      self._add_container_type_methods[container_type] = method

Initializes a storage merge reader.

Args:
storage_writer (StorageWriter): storage writer.
path (str): path to the input file.

Raises:
IOError: if the input file cannot be opened.
RuntimeError: if an add container method is missing.


def parse_lxml(self, file, encoding=None, target_class=HTMLParserTarget,
                   parser_type='html'):

        if encoding:
            lxml_encoding = to_lxml_encoding(encoding) or 'latin1'
        else:
            lxml_encoding = encoding

        elements = []

        callback_func = elements.append

        target = target_class(callback_func)

        if parser_type == 'html':
            parser = lxml.html.HTMLParser(
                encoding=lxml_encoding, target=target
            )
        elif parser_type == 'xhtml':
            parser = lxml.html.XHTMLParser(
                encoding=lxml_encoding, target=target, recover=True
            )
        else:
            parser = lxml.etree.XMLParser(
                encoding=lxml_encoding, target=target, recover=True
            )

        if parser_type == 'html':

            for dummy in range(3):
                parser.feed('<html>'.encode(encoding))

        while True:
            data = file.read(self.BUFFER_SIZE)

            if not data:
                break

            parser.feed(data)

            for element in elements:
                yield element

            del elements[:]

        parser.close()

        for element in elements:
            yield element

Return an iterator of elements found in the document.

Args:
file: A file object containing the document.
encoding (str): The encoding of the document.
target_class: A class to be used for target parsing.
parser_type (str): The type of parser to use. Accepted values:
``html``, ``xhtml``, ``xml``.

Returns:
iterator: Each item is an element from
:mod:`.document.htmlparse.element`


def Run(self, conf, args):
    raise NotImplementedError('command %r not implemented' % self.__class__.__name__)

Run this command.

Commands are invoked with a global configuration object and a list
of arguments.

Args:
conf: A Config object defining global configuration of
nss_cache.
args: A list of strings of commandline arguments.
Returns:
0 if the command was successful
non-zero shell error code if not.


def _LinearMapByteStream(
      self, byte_stream, byte_offset=0, context=None, **unused_kwargs):

    elements_data_size = self._data_type_definition.GetByteSize()
    self._CheckByteStreamSize(byte_stream, byte_offset, elements_data_size)

    try:
      struct_tuple = self._operation.ReadFrom(byte_stream[byte_offset:])
      mapped_values = map(self._element_data_type_map.MapValue, struct_tuple)

    except Exception as exception:
      error_string = (
          'Unable to read: {0:s} from byte stream at offset: {1:d} '
          'with error: {2!s}').format(
              self._data_type_definition.name, byte_offset, exception)
      raise errors.MappingError(error_string)

    if context:
      context.byte_size = elements_data_size

    return tuple(mapped_values)

Maps a data type sequence on a byte stream.

Args:
byte_stream (bytes): byte stream.
byte_offset (Optional[int]): offset into the byte stream where to start.
context (Optional[DataTypeMapContext]): data type map context.

Returns:
tuple[object, ...]: mapped values.

Raises:
MappingError: if the data type definition cannot be mapped on
the byte stream.


def part_studio_stl(self, did, wid, eid):

        req_headers = {
            'Accept': 'application/vnd.onshape.v1+octet-stream'
        }
        return self._api.request('get', '/api/partstudios/d/' + did + '/w/' + wid + '/e/' + eid + '/stl', headers=req_headers)

Exports STL export from a part studio

Args:
- did (str): Document ID
- wid (str): Workspace ID
- eid (str): Element ID

Returns:
- requests.Response: Onshape response data


def MultiDestroyFlowStates(self, session_ids, request_limit=None):
    subjects = [session_id.Add('state') for session_id in session_ids]
    to_delete = []
    deleted_requests = []
    for (subject, values) in self.MultiResolvePrefix(subjects, self.FLOW_REQUEST_PREFIX, limit=request_limit):
        for (_, serialized, _) in values:
            request = rdf_flow_runner.RequestState.FromSerializedString(serialized)
            deleted_requests.append(request)
            response_subject = self.GetFlowResponseSubject(request.session_id, request.id)
            to_delete.append(response_subject)
        to_delete.append(subject)
    self.DeleteSubjects(to_delete, sync=True)
    return deleted_requests

Deletes all requests and responses for the given flows.

Args:
session_ids: A lists of flows to destroy.
request_limit: A limit on the number of requests to delete.

Returns:
A list of requests that were deleted.


def copy_graph(subject, existing_graph):

    new_graph = rdflib.Graph()
    for predicate, object_ in existing_graph.predicate_objects():
        new_graph.add((subject, predicate, object_))
    return new_graph

Function takes a subject and an existing graph, returns a new graph with
all predicate and objects of the existing graph copied to the new_graph with
subject as the new subject

Args:
subject(rdflib.URIRef): A URIRef subject
existing_graph(rdflib.Graph): A rdflib.Graph

Returns:
rdflib.Graph


def __init__(self, tensors):
    if not isinstance(tensors, (list, tuple)) or not tensors:
        raise ValueError('Unable to create a ShardedNdArray without a list of tensors.')
    self.tensors = tensors
    self.n_devices = len(tensors)

Initializes the ShardedNdArray.

Note that the tensors should be ordered in the way the pmap producing these
tensors is run.

Args:
tensors: list or tuple of eager tensors, one for each device.


def _histogram_equalization_helper(valid_data, number_of_bins, clip_limit=None, slope_limit=None):
    (temp_histogram, temp_bins) = np.histogram(valid_data, number_of_bins)
    if (clip_limit is not None):
        pixels_to_clip_at = int((clip_limit * (valid_data.size / float(number_of_bins))))
        mask_to_clip = (temp_histogram > clip_limit)
        temp_histogram[mask_to_clip] = pixels_to_clip_at
    cumulative_dist_function = temp_histogram.cumsum()
    if (slope_limit is not None):
        pixel_height_limit = int((slope_limit * (valid_data.size / float(number_of_bins))))
        cumulative_excess_height = 0
        num_clipped_pixels = 0
        weight_metric = np.zeros(cumulative_dist_function.shape, dtype=float)
        for pixel_index in range(1, cumulative_dist_function.size):
            current_pixel_count = cumulative_dist_function[pixel_index]
            diff_from_acceptable = (((current_pixel_count - cumulative_dist_function[(pixel_index - 1)]) - pixel_height_limit) - cumulative_excess_height)
            if (diff_from_acceptable < 0):
                weight_metric[pixel_index] = abs(diff_from_acceptable)
            cumulative_excess_height += max(diff_from_acceptable, 0)
            cumulative_dist_function[pixel_index] = (current_pixel_count - cumulative_excess_height)
            num_clipped_pixels = (num_clipped_pixels + cumulative_excess_height)
    cumulative_dist_function = (((number_of_bins - 1) * cumulative_dist_function) / cumulative_dist_function[(- 1)])
    return (cumulative_dist_function, temp_bins)

Calculate the simplest possible histogram equalization, using only valid data.

Returns:
cumulative distribution function and bin information


def get_resource(self, uri: str) -> Optional[message.Message]:
    for collection in (self.structure_definitions, self.search_parameters, self.code_systems, self.value_sets):
        resource = collection.get(uri)
        if resource is not None:
            return resource
    return None

Retrieves a protocol buffer representation of the given resource.

Args:
uri: The URI of the resource to retrieve.

Returns:
Protocol buffer for the resource or `None` if the `uri` can not be found.


def from_structure(cls, structure, ff_elements=None, atom_style='charge'):
    s = structure.get_sorted_structure()
    (box, symmop) = lattice_2_lmpbox(s.lattice)
    coords = symmop.operate_multi(s.cart_coords)
    site_properties = s.site_properties
    if ('velocities' in site_properties):
        velos = np.array(s.site_properties['velocities'])
        rot = SymmOp.from_rotation_and_translation(symmop.rotation_matrix)
        rot_velos = rot.operate_multi(velos)
        site_properties.update({'velocities': rot_velos})
    boxed_s = Structure(box.to_lattice(), s.species, coords, site_properties=site_properties, coords_are_cartesian=True)
    symbols = list(s.symbol_set)
    if ff_elements:
        symbols.extend(ff_elements)
    elements = sorted((Element(el) for el in set(symbols)))
    mass_info = [tuple(([i.symbol] * 2)) for i in elements]
    ff = ForceField(mass_info)
    topo = Topology(boxed_s)
    return cls.from_ff_and_topologies(box=box, ff=ff, topologies=[topo], atom_style=atom_style)

Simple constructor building LammpsData from a structure without
force field parameters and topologies.

Args:
structure (Structure): Input structure.
ff_elements ([str]): List of strings of elements that must
be present due to force field settings but not
necessarily in the structure. Default to None.
atom_style (str): Choose between "atomic" (neutral) and
"charge" (charged). Default to "charge".


def deep_del(data, fn):
    result = {}
    for (k, v) in data.iteritems():
        if (not fn(v)):
            if isinstance(v, dict):
                result[k] = deep_del(v, fn)
            else:
                result[k] = v
    return result

Create dict copy with removed items.

Recursively remove items where fn(value) is True.

Returns:
dict: New dict with matching items removed.


def get_lang(tweet):
    if is_original_format(tweet):
        lang_field = 'lang'
    else:
        lang_field = 'twitter_lang'
    if ((tweet[lang_field] is not None) and (tweet[lang_field] != 'und')):
        return tweet[lang_field]
    else:
        return None

Get the language that the Tweet is written in.

Args:
tweet (Tweet or dict): A Tweet object or dictionary

Returns:
str: 2-letter BCP 47 language code (or None if undefined)

Example:
>>> from tweet_parser.getter_methods.tweet_text import get_lang
>>> original = {"created_at": "Wed May 24 20:17:19 +0000 2017",
...             "lang": "en"}
>>> get_lang(original)
'en'

>>> activity = {"postedTime": "2017-05-24T20:17:19.000Z",
...             "twitter_lang": "en"}
>>> get_lang(activity)
'en'


def add(self, distinguished_name, object_class, attributes):
    self.conn.add(distinguished_name, object_class, attributes)

Add object to LDAP.

Args:
distinguished_name: the DN of the LDAP record to be added
object_class: The objectClass of the record to be added.
This is a list of length >= 1.
attributes: a dictionary of LDAP attributes to add
See ldap_tools.api.group.API#__ldap_attr


def f(x, depth1, depth2, dim='2d', first_batch_norm=True, stride=1, training=True, bottleneck=True, padding='SAME'):
    conv = CONFIG[dim]['conv']
    with tf.variable_scope('f', reuse=tf.AUTO_REUSE):
        if first_batch_norm:
            net = tf.layers.batch_normalization(x, training=training)
            net = tf.nn.relu(net)
        else:
            net = x
        if bottleneck:
            net = conv(net, depth1, 1, strides=stride, padding=padding, activation=None)
            net = tf.layers.batch_normalization(net, training=training)
            net = tf.nn.relu(net)
            net = conv(net, depth1, 3, strides=1, padding=padding, activation=None)
            net = tf.layers.batch_normalization(net, training=training)
            net = tf.nn.relu(net)
            net = conv(net, depth2, 1, strides=1, padding=padding, activation=None)
        else:
            net = conv(net, depth2, 3, strides=stride, padding=padding, activation=None)
            net = tf.layers.batch_normalization(x, training=training)
            net = tf.nn.relu(net)
            net = conv(net, depth2, 3, strides=stride, padding=padding, activation=None)
        return net

Applies residual function for RevNet.

Args:
x: input tensor
depth1: Number of output channels for the first and second conv layers.
depth2: Number of output channels for the third conv layer.
dim: '2d' if 2-dimensional, '3d' if 3-dimensional.
first_batch_norm: Whether to keep the first batch norm layer or not.
Typically used in the first RevNet block.
stride: Stride for the first conv filter. Note that this particular
RevNet architecture only varies the stride for the first conv
filter. The stride for the second conv filter is always set to 1.
training: True for train phase, False for eval phase.
bottleneck: If true, apply bottleneck 1x1 down/up sampling.
padding: Padding for each conv layer.

Returns:
Output tensor after applying residual function for RevNet.


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

        self.model = kwargs.pop('model', self.model)
        self.queryset = kwargs.pop('queryset', self.queryset)
        self.search_fields = kwargs.pop('search_fields', self.search_fields)
        self.max_results = kwargs.pop('max_results', self.max_results)
        defaults = {'data_view': 'django_select2:auto-json'}
        defaults.update(kwargs)
        super(ModelSelect2Mixin, self).__init__(*args, **defaults)

Overwrite class parameters if passed as keyword arguments.

Args:
model (django.db.models.Model): Model to select choices from.
queryset (django.db.models.query.QuerySet): QuerySet to select choices from.
search_fields (list): List of model lookup strings.
max_results (int): Max. JsonResponse view page size.


def get_nonconflicting_string(base_fmtstr, conflict_set, offset=0):
    conflict_set_ = set(conflict_set)
    for count in it.count(offset):
        base_str = (base_fmtstr % count)
        if (base_str not in conflict_set_):
            return base_str

gets a new string that wont conflict with something that already exists

Args:
base_fmtstr (str):
conflict_set (set):

CommandLine:
python -m utool.util_dev --test-get_nonconflicting_string

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_dev import *  # NOQA
>>> # build test data
>>> base_fmtstr = 'somestring%d'
>>> conflict_set = ['somestring0']
>>> # execute function
>>> result = get_nonconflicting_string(base_fmtstr, conflict_set)
>>> # verify results
>>> print(result)
somestring1


def _set_details(self, content):
    try:
        self.details = str(content)
    except UnicodeEncodeError:
        logging.error('Unable to decode "%s" in Py3, encoding in utf-8.', content)
        self.details = content.encode('utf-8')

Sets the `details` field.

Args:
content: the content to extract details from.


def _ParseKey(self, knowledge_base, registry_key, value_name):

    user_account = artifacts.UserAccountArtifact(
        identifier=registry_key.name, path_separator='\\')

    registry_value = registry_key.GetValueByName('ProfileImagePath')
    if registry_value:
      profile_path = registry_value.GetDataAsObject()
      username = self._GetUsernameFromProfilePath(profile_path)

      user_account.user_directory = profile_path or None
      user_account.username = username or None

    try:
      knowledge_base.AddUserAccount(user_account)
    except KeyError:

      pass

Parses a Windows Registry key for a preprocessing attribute.

Args:
knowledge_base (KnowledgeBase): to fill with preprocessing information.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
value_name (str): name of the Windows Registry value.

Raises:
errors.PreProcessFail: if the preprocessing fails.


def add_to_dumper(dumper: Type, classes: List[Type]) -> None:
    if (not isinstance(classes, list)):
        classes = [classes]
    for class_ in classes:
        if issubclass(class_, enum.Enum):
            dumper.add_representer(class_, EnumRepresenter(class_))
        elif (issubclass(class_, str) or issubclass(class_, UserString)):
            dumper.add_representer(class_, UserStringRepresenter(class_))
        else:
            dumper.add_representer(class_, Representer(class_))

Register user-defined classes with the Dumper.

This enables the Dumper to write objects of your classes to a \
YAML file. Note that all the arguments are types, not instances!

Args:
dumper: Your dumper class(!), derived from yatiml.Dumper
classes: One or more classes to add.


def update_aliases(self):
    try:
        response = self.client.api.get_room_state(self.room_id)
        for chunk in response:
            if (('content' in chunk) and ('aliases' in chunk['content'])):
                if (chunk['content']['aliases'] != self.aliases):
                    self.aliases = chunk['content']['aliases']
                    return True
                else:
                    return False
    except MatrixRequestError:
        return False

Get aliases information from room state.

Returns:
boolean: True if the aliases changed, False if not


def _dilated_conv_layer(self, output_channels, dilation_rate, apply_relu,
                          name):

    layer_components = [
        conv.Conv2D(
            output_channels, [3, 3],
            initializers=self._initializers,
            regularizers=self._regularizers,
            rate=dilation_rate,
            name="dilated_conv_" + name),
    ]
    if apply_relu:
      layer_components.append(lambda net: tf.nn.relu(net, name="relu_" + name))
    return sequential.Sequential(layer_components, name=name)

Create a dilated convolution layer.

Args:
output_channels: int. Number of output channels for each pixel.
dilation_rate: int. Represents how many pixels each stride offset will
move. A value of 1 indicates a standard convolution.
apply_relu: bool. If True, a ReLU non-linearlity is added.
name: string. Name for layer.

Returns:
a sonnet Module for a dilated convolution.


def __init__(self, core, keep_probs):

    super(RecurrentDropoutWrapper, self).__init__(
        custom_getter=None, name=core.module_name + "_recdropout")
    self._core = core
    self._keep_probs = keep_probs

    self._dropout_state_size = []

    def set_dropout_state_size(keep_prob, state_size):
      if keep_prob is not None:
        self._dropout_state_size.append(state_size)
        return len(self._dropout_state_size) - 1
      return None

    self._dropout_indexes = tf.contrib.framework.nest.map_structure(
        set_dropout_state_size, keep_probs, core.state_size)

Builds a new wrapper around a given core.

Args:
core: the RNN core to be wrapped.
keep_probs: the recurrent dropout keep probabilities to apply.
This should have the same structure has core.init_state. No dropout is
applied for leafs set to None.


def toInteger(self) -> 'Builder':
    return self._to_builder(_evaluation.ToIntegerFunction(self.node.context, self.node, []))

The FHIRPath toInteger() function.

Casts its operand to an integer.
Returns an empty collection if the operand can not be coerced to an integer.
Raises a ValueError if the operand collection contains more than one
element.

Returns:
An integer representation of its operand.


def GetMessages(self, formatter_mediator, event):

    if self.DATA_TYPE != event.data_type:
      raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
          event.data_type))

    event_values = event.CopyToDict()

    regvalue = event_values.get('regvalue', {})
    string_parts = []
    for key, value in sorted(regvalue.items()):
      string_parts.append('{0:s}: {1!s}'.format(key, value))
    event_values['text'] = ' '.join(string_parts)

    urls = event_values.get('urls', [])
    if urls:
      event_values['urls'] = ' - '.join(urls)

    if 'key_path' in event_values:
      format_string = self.FORMAT_STRING
    else:
      format_string = self.FORMAT_STRING_ALTERNATIVE

    return self._FormatMessages(
        format_string, self.FORMAT_STRING_SHORT, event_values)

Determines the formatted message strings for an event object.

Args:
formatter_mediator (FormatterMediator): mediates the interactions
between formatters and other components, such as storage and Windows
EventLog resources.
event (EventObject): event.

Returns:
tuple(str, str): formatted message string and short message string.

Raises:
WrongFormatter: if the event object cannot be formatted by the formatter.


def _refresh(self, _):

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

Refresh self.access_token.

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


def OpenSourcePath(self, source_path):

    source_path_spec = path_spec_factory.Factory.NewPathSpec(
        definitions.TYPE_INDICATOR_OS, location=source_path)

    self.AddScanNode(source_path_spec, None)

Opens the source path.

Args:
source_path (str): source path.


def check_beam_implementation(test: absltest.TestCase, input_data: Union[EventSet, List[EventSet]], output_node: EventSetNode, cast: Optional[DType]=None):
    if isinstance(input_data, EventSet):
        input_data = [input_data]
    tmp_dir = tempfile.mkdtemp()
    output_path = os.path.join(tmp_dir, 'output.csv')
    input_paths = []
    for input_idx, input_evset in enumerate(input_data):
        input_path = os.path.join(tmp_dir, f'input_{input_idx}.csv')
        input_paths.append(input_path)
        to_tensorflow_record(input_evset, path=input_path)
    with TestPipeline() as p:
        input_pcollection = {}
        for input_path, input_evset in zip(input_paths, input_data):
            input_pcollection[input_evset.node()] = p | beam_from_tensorflow_record(input_path, input_evset.node().schema)
        output_pcollection = run_multi_io(inputs=input_pcollection, outputs=[output_node])
        assert len(output_pcollection) == 1
        output = output_pcollection[output_node] | beam_to_tensorflow_record(output_path, output_node.schema, shard_name_template='')
        assert_that(output, equal_to([output_path]))
    beam_output = from_tensorflow_record(output_path, output_node.schema)
    if cast:
        beam_output = beam_output.cast(cast)
    expected_output = output_node.run(input_data)
    assertEqualEventSet(test, beam_output, expected_output)

Checks the result of the Numpy backend against the Beam backend.

Args:
test: The absl's test.
input_data: An event set to feed to a graph.
output_node: Output of the graph.
input_node: Input of the graph. If not set, uses input_data.node()
instead.
cast: DType to cast beam's output to after loading it from csv. Useful
for comparing outputs that are expected to be int32 for example,
since when written to CSV those will be loaded back up as int64.


def update_particle(position_update, velocity_update, state, nbest_topology, idx_particle):
    (idx, particle) = idx_particle
    nbest = state.swarm[nbest_topology[idx]].best_position
    velocity = velocity_update(particle, nbest, state)
    position = position_update(particle.position, velocity)
    return particle._replace(position=position, velocity=velocity)

Update function for a particle.

Calculates and updates the velocity and position of a particle for a
single iteration of the PSO algorithm. Social best particle is determined
by the state.params['topology'] function.

Args:
state: cipy.algorithms.pso.State: The state of the PSO algorithm.
nbest_topology: dict: Containing neighbourhood best index for each
particle index.
idx_particle: tuple: Tuple of the index of the particle and the
particle itself.

Returns:
cipy.algorithms.pso.Particle: A new particle with the updated position
and velocity.


def kick_user(self, user_id, reason=''):
    try:
        self.client.api.kick_user(self.room_id, user_id)
        return True
    except MatrixRequestError:
        return False

Kick a user from this room.

Args:
user_id (str): The matrix user id of a user.
reason  (str): A reason for kicking the user.

Returns:
boolean: Whether user was kicked.


def HashBuffer(self, buf):

    for hasher in itervalues(self._hashers):
      hasher.update(buf)
      if self._progress:
        self._progress()

    self._bytes_read += len(buf)

Updates underlying hashers with a given buffer.

Args:
buf: A byte buffer (string object) that is going to be fed to the hashers.


def _get_label_encoder_and_max(self, x):
    label_count = x.fillna(NAN_INT).value_counts()
    n_uniq = label_count.shape[0]
    label_count = label_count[(label_count >= self.min_obs)]
    n_uniq_new = label_count.shape[0]
    offset = (0 if (n_uniq == n_uniq_new) else 1)
    label_encoder = pd.Series((np.arange(n_uniq_new) + offset), index=label_count.index)
    max_label = label_encoder.max()
    label_encoder = label_encoder.to_dict()
    return (label_encoder, max_label)

Return a mapping from values and its maximum of a column to integer labels.

Args:
x (pandas.Series): a categorical column to encode.

Returns:
label_encoder (dict): mapping from values of features to integers
max_label (int): maximum label


def exec_start(self, exec_id, detach=False, tty=False, stream=False, socket=False, demux=False):
    data = {'Tty': tty, 'Detach': detach}
    headers = ({} if detach else {'Connection': 'Upgrade', 'Upgrade': 'tcp'})
    res = self._post_json(self._url('/exec/{0}/start', exec_id), headers=headers, data=data, stream=True)
    if detach:
        return self._result(res)
    if socket:
        return self._get_raw_response_socket(res)
    return self._read_from_socket(res, stream, tty=tty, demux=demux)

Start a previously set up exec instance.

Args:
exec_id (str): ID of the exec instance
detach (bool): If true, detach from the exec command.
Default: False
tty (bool): Allocate a pseudo-TTY. Default: False
stream (bool): Stream response data. Default: False
socket (bool): Return the connection socket to allow custom
read/write operations.
demux (bool): Return stdout and stderr separately

Returns:

(generator or str or tuple): If ``stream=True``, a generator
yielding response chunks. If ``socket=True``, a socket object for
the connection. A string containing response data otherwise. If
``demux=True``, a tuple with two elements of type byte: stdout and
stderr.

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def __init__(self, name=None, options=None):
    compression_type = python_io.TFRecordOptions.get_compression_type_string(options)
    rr = gen_io_ops.tf_record_reader_v2(name=name, compression_type=compression_type)
    super(TFRecordReader, self).__init__(rr)

Create a TFRecordReader.

Args:
name: A name for the operation (optional).
options: A TFRecordOptions object (optional).


def check_done(self):
    raise NotImplementedError

Checks whether the restriction has been fully processed.

Called by the SDK harness after iterator returned by ``DoFn.process()``
has been fully read.

This method must raise a `ValueError` if there is still any unclaimed work
remaining in the restriction when this method is invoked. Exception raised
must have an informative error message.

This API is required to be implemented in order to make sure no data loss
during SDK processing.

Returns: ``True`` if current restriction has been fully processed.
Raises:
ValueError: if there is still any unclaimed work remaining.


def _get_create_query(partition, tablename, include=None):
    TYPE_MAP = {'int': 'INTEGER', 'float': 'REAL', six.binary_type.__name__: 'TEXT', six.text_type.__name__: 'TEXT', 'date': 'DATE', 'datetime': 'TIMESTAMP WITHOUT TIME ZONE'}
    columns_types = []
    if (not include):
        include = []
    for column in sorted(partition.datafile.reader.columns, key=(lambda x: x['pos'])):
        if (include and (column['name'] not in include)):
            continue
        sqlite_type = TYPE_MAP.get(column['type'])
        if (not sqlite_type):
            raise Exception('Do not know how to convert {} to sql column.'.format(column['type']))
        columns_types.append('    "{}" {}'.format(column['name'], sqlite_type))
    columns_types_str = ',\n'.join(columns_types)
    query = 'CREATE TABLE IF NOT EXISTS {}(\n{})'.format(tablename, columns_types_str)
    return query

Creates and returns `CREATE TABLE ...` sql statement for given mprows.

Args:
partition (orm.Partition):
tablename (str): name of the table in the return create query.
include (list of str, optional): list of columns to include to query.

Returns:
str: create table query.


def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
    output = [self.cls_token_id] + token_ids_0 + [self.sep_token_id]
    if token_ids_1 is not None:
        output += token_ids_1 + [self.sep_token_id]
    return output

Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A RoFormer sequence has the following format:

- single sequence: `[CLS] X [SEP]`
- pair of sequences: `[CLS] A [SEP] B [SEP]`

Args:
token_ids_0 (`List[int]`):
List of IDs to which the special tokens will be added.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.


def _on_disconnect(self, result):
    (success, _, context) = self._parse_return(result)
    callback = context['callback']
    connection_id = context['connection_id']
    handle = context['handle']
    callback(connection_id, self.id, success, 'No reason given')
    self._remove_connection(handle)

Callback called when disconnection command finishes

Args:
result (dict): result returned from diconnection command


def AliasMethod(func, from_constant):
    new_func = func.Replace(kind=MethodKind.METHOD)
    if func.kind == MethodKind.STATICMETHOD or (func.kind == MethodKind.METHOD and (not from_constant)):
        return new_func
    return new_func.Replace(signatures=tuple((s.Replace(params=s.params[1:]) for s in new_func.signatures)))

Returns method func with its signature modified as if it has been aliased.

Args:
func: A pytd.Function.
from_constant: If True, func will be modified as if it has been aliased from
an instance of its defining class, e.g.,
class Foo:
def func(self): ...
const = ...  # type: Foo
func = const.func
Otherwise, it will be modified as if aliased from the class itself:
class Foo:
def func(self): ...
func = Foo.func

Returns:
A pytd.Function, the aliased method.


def transform_and_print_file(self, file_path: str, transformation: Optional[Callable[[Iterator[str]], Iterator[str]]]=None, output_stream: io.TextIOBase=cast(io.TextIOBase, sys.stdout)) -> None:
    if transformation is None:
        transformation = self.annotate_test_file
    if file_path == _STANDARD_IO_STREAMS:
        output_stream.writelines(transformation(sys.stdin))
    else:
        with open(file_path, 'r') as file_contents:
            output_stream.writelines(transformation(file_contents))

Reads from `file_path`, applies a transformation, and prints to `stdout`.

Args:
file_path: The path to the input file. If this is equal to the constant
`_STANDARD_IO_STREAMS` (i.e. the string "-"), the input will come from
`stdin`.
transformation: A function that takes an iterator over the lines of an HLO
file and returns an iterator over the lines of the transformed file. If
this is left as `None`, `self.annotate_test_file` will be used.
output_stream: The stream to which the transformed file should be written.
Defaults to `stdout`.


def AddBitbucketServerConnectedRepository(self, request, global_params=None):
    config = self.GetMethodConfig('AddBitbucketServerConnectedRepository')
    return self._RunMethod(config, request, global_params=global_params)

Add a Bitbucket Server repository to a given BitbucketServerConfig's connected repositories. This API is experimental.

Args:
request: (CloudbuildProjectsLocationsBitbucketServerConfigsAddBitbucketServerConnectedRepositoryRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(AddBitbucketServerConnectedRepositoryResponse) The response message.


def decompress(ctype, unc_len, data):
    if (ctype == UBIFS_COMPR_LZO):
        try:
            return lzo.decompress(b''.join((b'\xf0', struct.pack('>I', unc_len), data)))
        except Exception as e:
            error(decompress, 'Warn', ('LZO Error: %s' % e))
    elif (ctype == UBIFS_COMPR_ZLIB):
        try:
            return zlib.decompress(data, (- 11))
        except Exception as e:
            error(decompress, 'Warn', ('ZLib Error: %s' % e))
    else:
        return data

Decompress data.

Arguments:
Int:ctype    -- Compression type LZO, ZLIB (*currently unused*).
Int:unc_len  -- Uncompressed data lenth.
Str:data     -- Data to be uncompessed.

Returns:
Uncompressed Data.


def do_searchfy(self, query, **kwargs):

        try:
            results = self.wrapperAPI.search_users(query)

            for r in results:
                aux = {}
                aux["type"]="i3visio.uri"
                alias=r["value"].split(' - ')[1]
                qURL = self.createURL(word=alias, mode="usufy")
                aux["value"]= qURL
                aux["attributes"]= []
                r["attributes"].append(aux)

        except Exception, e:
            return super(Twitter, self).do_searchfy(query, **kwargs)

Verifying a usufy query in this platform.

This might be redefined in any class inheriting from Platform.

Args:
-----
query: The element to be searched.

Return:
-------
A list of elements to be appended.


def get_extra_inputs():
    g = ops.get_default_graph()
    if isinstance(g, _FuncGraph):
        return g.extra_inputs
    else:
        return []

Returns the captured input tensors by the function.

Returns:
If the default graph is being used to define a function, the
returned list of tensors are those accessed inside the function body
but defined outside the function body so far. Otherwise, returns an
empty list.


def convert_dense_weights_data_format(dense, previous_feature_map_shape, target_data_format='channels_first'):
    assert target_data_format in {'channels_last', 'channels_first'}
    kernel, bias = dense.get_weights()
    for i in range(kernel.shape[1]):
        if target_data_format == 'channels_first':
            c, h, w = previous_feature_map_shape
            original_fm_shape = (h, w, c)
            ki = kernel[:, i].reshape(original_fm_shape)
            ki = np.transpose(ki, (2, 0, 1))
        else:
            h, w, c = previous_feature_map_shape
            original_fm_shape = (c, h, w)
            ki = kernel[:, i].reshape(original_fm_shape)
            ki = np.transpose(ki, (1, 2, 0))
        kernel[:, i] = np.reshape(ki, (np.prod(previous_feature_map_shape),))
    dense.set_weights([kernel, bias])

Utility useful when changing a convnet's `data_format`.

When porting the weights of a convnet from one data format to the other,
if the convnet includes a `Flatten` layer
(applied to the last convolutional feature map)
followed by a `Dense` layer, the weights of that `Dense` layer
should be updated to reflect the new dimension ordering.

Args:
dense: The target `Dense` layer.
previous_feature_map_shape: A shape tuple of 3 integers,
e.g. `(512, 7, 7)`. The shape of the convolutional
feature map right before the `Flatten` layer that
came before the target `Dense` layer.
target_data_format: One of "channels_last", "channels_first".
Set it "channels_last"
if converting a "channels_first" model to "channels_last",
or reciprocally.


def remove_slice_from_lines(lines, clean_text, slice) -> str:
    base = clean_text[slice[0]]
    section = list(slice)
    check_start_flag = False
    for line_idx in range(max(0, slice[0] - 1), max(0, slice[0] - 5), -1):
        if not lines[line_idx]:
            continue
        if lines[line_idx] == '
            section[0] = line_idx
            break
        elif ratio(base, remove_numbers(lines[line_idx])) < 0.9:
            section[0] = line_idx + 1
            potential_ref = remove_numbers(lines[max(0, line_idx - 1)].partition('* [')[-1])
            if len(potential_ref) >= 0.75 * len(base) and ratio(base, potential_ref) < 0.9:
                section[0] = line_idx
            check_start_flag = True
            break
    for line_idx in range(min(len(lines), slice[1]), min(len(lines), slice[1] + 5)):
        if ratio(base, remove_numbers(lines[line_idx])) < 0.9:
            section[1] = line_idx
            break
    if len(lines) <= section[1]:
        section[1] = len(lines) - 1
    to_delete = '\n'.join(lines[section[0]:section[1] + 1])
    itera, iterb = (enumerate(lines[section[1] - 1]), enumerate(lines[section[1]]))
    while True:
        try:
            ia, a = next(itera)
            while a.isnumeric():
                ia, a = next(itera)
            ib, b = next(iterb)
            while b.isnumeric():
                ib, b = next(iterb)
            if a != b:
                break
        except StopIteration:
            break
    if check_start_flag and '* [' in to_delete:
        to_delete = '* [' + to_delete.partition('* [')[-1]
    try:
        delta = len(lines[section[1]]) - ib - 1
        if delta > 0:
            to_delete = to_delete[:-delta]
    except UnboundLocalError:
        pass
    return to_delete.strip()

Remove a slice of text from the lines based on specific criteria.

This function identifies a slice of text within the lines and removes it based on certain conditions.

Args:
lines (list of str): The list of lines containing the text.
clean_text (list of str): A cleaned version of the text (without numbers).
slice (tuple): A tuple representing the start and end indices of the slice to be removed.

Returns:
str: The removed slice of text as a single string.


def read_struct(fstream):
    line = fstream.readline().strip()
    fragments = line.split(',')
    fragments = [x for x in fragments if (x is not None)]
    partition = dict()
    if (not (len(fragments) >= 3)):
        return None
    partition['struct'] = fragments[0]
    partition['info'] = fragments[1]
    partition['num_lines'] = fragments[2]
    struct = None
    if ((partition is not None) and (partition['struct'] == 'STRUCT')):
        num_lines = int(partition['num_lines'].strip())
        struct = {}
        for _ in range(num_lines):
            cols = fetch_cols(fstream)
            struct.update({cols[0]: cols[1:]})
    return struct

Read a likwid struct from the text stream.

Args:
fstream: Likwid's filestream.

Returns (dict(str: str)):
A dict containing all likwid's struct info as key/value pairs.


def extract_variable_info(kwargs) -> Tuple[Text, Tuple[int, ...], dtypes.DType, Callable[[], Any]]:
    if isinstance(kwargs['initial_value'], functools.partial) and ('shape' in kwargs['initial_value'].keywords or kwargs['initial_value'].args):
        if 'shape' in kwargs['initial_value'].keywords:
            shape = kwargs['initial_value'].keywords['shape']
        else:
            shape = kwargs['initial_value'].args[0]
        return (kwargs['name'], shape, kwargs['initial_value'].keywords.get('dtype', kwargs['dtype']), kwargs['initial_value'].func)
    elif 'shape' not in kwargs or kwargs['shape'] is None or (not callable(kwargs['initial_value'])):
        raise ValueError('Unable to extract initializer function and shape from {}. Please either pass a function that expects a shape and dtype as the initial value for your variable or functools.partial object with the shape and dtype kwargs set. This is needed so that we can initialize the shards of the ShardedVariable locally.'.format(kwargs['initial_value']))
    else:
        return (kwargs['name'], kwargs['shape'], kwargs['dtype'], kwargs['initial_value'])

Extracts the variable creation attributes from the kwargs.

Args:
kwargs: a dict of keyword arguments that were passed to a variable creator
scope.

Returns:
A tuple of variable name, shape, dtype, initialization function.


def _extract_mnist_images(filename, num_images):

  with gzip.open(filename) as bytestream:
    bytestream.read(16)
    buf = bytestream.read(_MNIST_IMAGE_SIZE * _MNIST_IMAGE_SIZE * num_images)
    data = np.frombuffer(buf, dtype=np.uint8)
    data = data.reshape(num_images, _MNIST_IMAGE_SIZE, _MNIST_IMAGE_SIZE, 1)
  return data

Extract images from an MNIST file into a numpy array.

Args:
filename: The path to an MNIST images file.
num_images: The number of images in the file.

Returns:
A numpy array of shape [number_of_images, height, width, channels].


def build(self, input_shape):
    if not hasattr(self.build, '_is_default'):
        self._build_input_shape = input_shape
    self.built = True

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of `Layer` or `Model`
can override if they need a state-creation step in-between
layer instantiation and layer call.

This is typically used to create the weights of `Layer` subclasses.

Args:
input_shape: Instance of `TensorShape`, or list of instances of
`TensorShape` if the layer expects a list of inputs
(one instance per input).


def get_user_data_configuration():
    from cloud_inquisitor import get_local_aws_session, app_config
    kms_region = app_config.kms_region
    session = get_local_aws_session()
    if (session.get_credentials().method == 'iam-role'):
        kms = session.client('kms', region_name=kms_region)
    else:
        sts = session.client('sts')
        audit_role = sts.assume_role(RoleArn=app_config.aws_api.instance_role_arn, RoleSessionName='cloud_inquisitor')
        kms = boto3.session.Session(audit_role['Credentials']['AccessKeyId'], audit_role['Credentials']['SecretAccessKey'], audit_role['Credentials']['SessionToken']).client('kms', region_name=kms_region)
    user_data_url = app_config.user_data_url
    res = requests.get(user_data_url)
    if (res.status_code == 200):
        data = kms.decrypt(CiphertextBlob=b64decode(res.content))
        kms_config = json.loads(zlib.decompress(data['Plaintext']).decode('utf-8'))
        app_config.database_uri = kms_config['db_uri']
    else:
        raise RuntimeError('Failed loading user-data, cannot continue: {}: {}'.format(res.status_code, res.content))

Retrieve and update the application configuration with information from the user-data

Returns:
`None`


def dbmax50years(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 `dbmax50years`'.format(value))
    self._dbmax50years = value

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

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

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


def enable(self, timeout=0):

        self.client.api.enable_plugin(self.name, timeout)
        self.reload()

Enable the plugin.

Args:
timeout (int): Timeout in seconds. Default: 0

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def get_operator_output_port(self):
    return OperatorOutputPort(self.rest_client.make_request(self.operatorOutputPort), self.rest_client)

Get the output port of this exported stream.

Returns:
OperatorOutputPort: Output port of this exported stream.


def potcar_spec( filename ):

    p_spec = {}
    with open( filename, 'r' ) as f:
        potcars = re.split('(End of Dataset\n)', f.read() )
    potcar_md5sums = [ md5sum( ''.join( pair ) ) for pair in zip( potcars[::2], potcars[1:-1:2] ) ]
    for this_md5sum in potcar_md5sums:
        for ps in potcar_sets:
            for p, p_md5sum in potcar_md5sum_data[ ps ].items():
                if this_md5sum == p_md5sum:
                    p_spec[ p ] = ps
    if len( p_spec ) != len( potcar_md5sums ):
        raise ValueError( 'One or more POTCARs did not have matching md5 hashes' )
    return p_spec

Returns a dictionary specifying the pseudopotentials contained in a POTCAR file.

Args:
filename (Str): The name of the POTCAR file to process.

Returns:
(Dict): A dictionary of pseudopotential filename: dataset pairs, e.g.
{ 'Fe_pv': 'PBE_54', 'O', 'PBE_54' }


def __init__(self, value: Union[int, float], period: Union[int, float]):

        self.value = value % period
        self.period = period

Initializes the equivalence class.

Args:
value: numerical value to wrap.
period: periodicity of the numerical value.


def Clear(self):
    headers = {'Content-length': '0'}
    (response, _) = self._http.request(('%s/reset' % self._host), method='POST', headers=headers)
    if (response.status == 200):
        return True
    else:
        logging.warning('failed to clear emulator; response was: %s', response)

Clears all data from the emulator instance.

Returns:
True if the data was successfully cleared, False otherwise.


def bulk_create(self, *records):
    if (not records):
        raise TypeError('Must provide at least one record')
    if any(((not isinstance(r, dict)) for r in records)):
        raise TypeError('New records must be provided as dicts')
    new_records = []
    for record_data in records:
        record = record_factory(self._app, record_data)
        record.validate()
        new_records.append(record)
    self._swimlane.request('post', 'app/{}/record/batch'.format(self._app.id), json=[r._raw for r in new_records])

Create and validate multiple records in associated app

Args:
*records (dict): One or more dicts of new record field names and values

Notes:
Requires Swimlane 2.15+

Validates like :meth:`create`, but only sends a single request to create all provided fields, and does not
return the newly created records

Any validation failures on any of the records will abort the batch creation, not creating any new records

Does not return the newly created records

Examples:
Create 3 new records with single request

::

app.records.bulk_create(
{'Field 1': 'value 1', ...},
{'Field 1': 'value 2', ...},
{'Field 1': 'value 3', ...}
)

Raises:
swimlane.exceptions.UnknownField: If any field in any new record cannot be found
swimlane.exceptions.ValidationError: If any field in any new record fails validation
TypeError: If no dict of fields was provided, or any provided argument is not a dict


def config_pp(subs):
    print('(c|f): available only as CLI argument/in the config file', end='\n\n')
    for sub in subs:
        hlp_lst = []
        for (opt, meta) in conf[sub].defaults_():
            if (meta.cmd_arg ^ meta.conf_arg):
                opt += (' (c)' if meta.cmd_arg else ' (f)')
            hlp_lst.append((opt, meta.help))
        if hlp_lst:
            print('{}:'.format(sub))
            _pretty_print(hlp_lst, sep=' -- ', text_width=min(get_terminal_size().columns, 100))
            print()

Pretty print of configuration options.

Args:
subs (iterable of str): iterable with the list of conf sections to
print.


def fromkeys(cls, iterable, value=None):
    if (not callable(value)):
        return cls(dict.fromkeys(iterable, value))
    return cls(((key, value(key)) for key in iterable))

Create a new d from

Args:
iterable: Iterable containing keys
value: value to associate with each key.
If callable, will be value[key]

Returns: new DictWrapper

Example:

>>> from ww import d
>>> sorted(d.fromkeys('123', value=4).items())
[('1', 4), ('2', 4), ('3', 4)]
>>> sorted(d.fromkeys(range(3), value=lambda e:e**2).items())
[(0, 0), (1, 1), (2, 4)]


def _compile_fragment_ast(schema, current_schema_type, ast, location, context):
    query_metadata_table = context['metadata']
    coerces_to_type_name = ast.type_condition.name.value
    coerces_to_type_obj = schema.get_type(coerces_to_type_name)
    basic_blocks = []
    is_same_type_as_scope = current_schema_type.is_same_type(coerces_to_type_obj)
    equivalent_union_type = context['type_equivalence_hints'].get(coerces_to_type_obj, None)
    is_base_type_of_union = (isinstance(current_schema_type, GraphQLUnionType) and current_schema_type.is_same_type(equivalent_union_type))
    if (not (is_same_type_as_scope or is_base_type_of_union)):
        query_metadata_table.record_coercion_at_location(location, coerces_to_type_obj)
        basic_blocks.append(blocks.CoerceType({coerces_to_type_name}))
    inner_basic_blocks = _compile_ast_node_to_ir(schema, coerces_to_type_obj, ast, location, context)
    basic_blocks.extend(inner_basic_blocks)
    return basic_blocks

Return a list of basic blocks corresponding to the inline fragment at this AST node.

Args:
schema: GraphQL schema object, obtained from the graphql library
current_schema_type: GraphQLType, the schema type at the current location
ast: GraphQL AST node, obtained from the graphql library.
location: Location object representing the current location in the query
context: dict, various per-compilation data (e.g. declared tags, whether the current block
is optional, etc.). May be mutated in-place in this function!

Returns:
list of basic blocks, the compiled output of the vertex AST node


def videos(self, **kwargs):

        path = self._get_series_id_season_number_episode_number_path('videos')

        response = self._GET(path, kwargs)
        self._set_attrs_to_values(response)
        return response

Get the videos that have been added to a TV episode (teasers, clips,
etc...).

Args:
language: (optional) ISO 639 code.

Returns:
A dict respresentation of the JSON returned from the API.


def _substitute_globals(config_dict):

    constants = _get_all_constants()

    if type(config_dict) != dict:
        return

    for key, val in config_dict.iteritems():
        if key in constants and type(val) in _ALLOWED:
            globals()[key] = val

Set global variables to values defined in `config_dict`.

Args:
config_dict (dict): dict with data, which are used to set `globals`.

Note:
`config_dict` have to be dictionary, or it is ignored. Also all
variables, that are not already in globals, or are not types defined in
:attr:`_ALLOWED` (str, int, ..) or starts with ``_`` are silently
ignored.


def mark_as_unsaveable(self, error_message):
    self._saveable = False
    if isinstance(error_message, str):
        error_message = [error_message]
    self._saving_errors.update(error_message)

Marks this FuncGraph as unsaveable.

Any attempts to export this FuncGraph will raise an error with the specified
message.

Args:
error_message: List or string containing the error message to be raised
when saving this FuncGraph to SavedModel.


def parse(cls, representation, corpus=None):

        criteria_definitions = representation.split('\n')
        criteria = []

        for i in range(0, len(criteria_definitions), 2):
            filter_name = criteria_definitions[i]
            filter_repr = criteria_definitions[i + 1]

            if filter_name not in available_filter_criteria():
                raise UnknownFilterCriteriaException('Unknown filter-criterion {}'.format(filter_name))

            criterion = available_filter_criteria()[filter_name].parse(filter_repr)
            criteria.append(criterion)

        return cls(corpus, criteria)

Creates a subview from a string representation (created with ``self.serialize``).

Args:
representation (str): The representation.

Returns:
Subview: The created subview.


def _unpack(formatstring, packed):

    _checkString(formatstring, description='formatstring', minlength=1)
    _checkString(packed, description='packed string', minlength=1)

    if sys.version_info[0] > 2:
        packed = bytes(packed, encoding='latin1')

    try:
        value = struct.unpack(formatstring, packed)[0]
    except:
        errortext = 'The received bytestring is probably wrong, as the bytestring-to-num conversion failed.'
        errortext += ' Bytestring: {0!r} Struct format code is: {1}'
        raise ValueError(errortext.format(packed, formatstring))

    return value

Unpack a bytestring into a value.

Uses the built-in :mod:`struct` Python module.

Args:
* formatstring (str): String for the packing. See the :mod:`struct` module for details.
* packed (str): The bytestring to be unpacked.

Returns:
A value. The type depends on the formatstring.

Raises:
ValueError

Note that the :mod:`struct` module wants byte buffers for Python3,
but bytestrings for Python2. This is compensated for automatically.


def get_generic_distributions(generic_dists, metric_id):
    return sum((get_all_distributions_by_type(dist, metric_id) for dist in generic_dists), [])

Creates flatten list of distributions per its value type.
A generic distribution is the one which is not processed but saved in
the most raw version.

Args:
generic_dists: list of distributions to be saved
metric_id(uuid): id of the current test run

Returns:
list of dictionaries made from :class:`DistributionMetric`


def __init__(self, datastore_client, storage_client, dataset_name):

    super(DatasetBatches, self).__init__(
        datastore_client=datastore_client,
        entity_kind_batches=KIND_DATASET_BATCH,
        entity_kind_images=KIND_DATASET_IMAGE)
    self._storage_client = storage_client
    self._dataset_name = dataset_name

Initializes DatasetBatches.

Args:
datastore_client: instance of CompetitionDatastoreClient
storage_client: instance of CompetitionStorageClient
dataset_name: name of the dataset ('dev' or 'final')


def update_value(self, offset, value):
    if ((offset + len(value)) > self.total_size):
        return Error.INPUT_BUFFER_TOO_LONG
    if (len(self.current_value) < offset):
        self.current_value += bytearray((offset - len(self.current_value)))
    if (len(self.current_value) > offset):
        self.current_value = self.current_value[:offset]
    self.current_value += bytearray(value)
    return 0

Update the binary value currently stored for this config value.

Returns:
int: An opaque error code that can be returned from a set_config rpc


def __init__(self, name=None, description=None, arguments=None):

        if name:
            self.name = name
        if description:
            self.description = description

        self.arguments = arguments or {}
        self.data = None

Initialization method.

Args:
arguments (dict): arguments that will be used for get_data method.


def dict_to_schema(schema_dict, required, allow_custom_keys=True, modifier=None):
    if modifier:
        modifier = Use(modifier)

    def _to(value):
        if isinstance(value, dict):
            d = {}
            for (k, v) in value.iteritems():
                if isinstance(k, basestring):
                    k = (Required(k) if required else Optional(k))
                d[k] = _to(v)
            if allow_custom_keys:
                d[Optional(basestring)] = (modifier or object)
            schema = Schema(d)
        elif modifier:
            schema = And(value, modifier)
        else:
            schema = value
        return schema
    return _to(schema_dict)

Convert a dict of Schemas into a Schema.

Args:
required (bool): Whether to make schema keys optional or required.
allow_custom_keys (bool, optional): If True, creates a schema that
allows custom items in dicts.
modifier (callable): Functor to apply to dict values - it is applied
via `Schema.Use`.

Returns:
A `Schema` object.


def FetchSizeOfSignedBinary(binary_urn,
                            token = None
                           ):

  if _ShouldUseLegacyDatastore():
    try:
      aff4_stream = aff4.FACTORY.Open(
          binary_urn, aff4_type=collects.GRRSignedBlob, mode="r", token=token)
      return aff4_stream.size
    except aff4.InstantiationError:
      raise SignedBinaryNotFoundError(binary_urn)
  else:
    try:
      references, _ = data_store.REL_DB.ReadSignedBinaryReferences(
          _SignedBinaryIDFromURN(binary_urn))
    except db.UnknownSignedBinaryError:
      raise SignedBinaryNotFoundError(binary_urn)
    last_reference = references.items[-1]
    return last_reference.offset + last_reference.size

Returns the size of the given binary (in bytes).

Args:
binary_urn: RDFURN that uniquely identifies the binary.
token: ACL token to use with the legacy (non-relational) datastore.

Raises:
SignedBinaryNotFoundError: If no signed binary with the given URN exists.


def convert(self, inp):

        inp = self._preprocess(inp)

        n = NumberService().longestNumber(inp)
        units = self.extractUnits(inp)

        quantity = pq.Quantity(float(n), units[0])
        quantity.units = units[1]

        return quantity

Converts a string representation of some quantity of units into a
quantities object.

Args:
inp (str): A textual representation of some quantity of units,
e.g., "fifty kilograms".

Returns:
A quantities object representing the described quantity and its
units.


def Register(self, name, constructor):

    precondition.AssertType(name, Text)

    if name in self._constructors:
      message = "Duplicated constructors %r and %r for name '%s'"
      message %= (constructor, self._constructors[name], name)
      raise ValueError(message)

    self._constructors[name] = constructor

Registers a new constructor in the factory.

Args:
name: A name associated with given constructor.
constructor: A constructor function that creates instances.

Raises:
ValueError: If there already is a constructor associated with given name.


def draw_mask(im, mask, alpha=0.5, color=None):
    if (color is None):
        color = PALETTE_RGB[np.random.choice(len(PALETTE_RGB))][::(- 1)]
    im = np.where(np.repeat((mask > 0)[(:, :, None)], 3, axis=2), ((im * (1 - alpha)) + (color * alpha)), im)
    im = im.astype('uint8')
    return im

Overlay a mask on top of the image.

Args:
im: a 3-channel uint8 image in BGR
mask: a binary 1-channel image of the same size
color: if None, will choose automatically


def make_descriptors(self, base_name):
    units_name = (base_name + '_units')
    units_props = self._units_type.make_descriptors(units_name)
    return (units_props + [UnitsSpecPropertyDescriptor(base_name, self, units_props[0])])

Return a list of ``PropertyDescriptor`` instances to install on a
class, in order to delegate attribute access to this property.

Unlike simpler property types, ``UnitsSpec`` returns multiple
descriptors to install. In particular, descriptors for the base
property as well as the associated units property are returned.

Args:
name (str) : the name of the property these descriptors are for

Returns:
list[PropertyDescriptor]

The descriptors returned are collected by the ``MetaHasProps``
metaclass and added to ``HasProps`` subclasses during class creation.


def _start_reader_thread(self, stream, chunks):

    import io
    import threading
    def target():
      while True:
        chunk = stream.read(io.DEFAULT_BUFFER_SIZE)
        if not chunk:
          break
        chunks.append(chunk)
    thread = threading.Thread(target=target)
    thread.start()
    return thread

Starts a thread for reading output from FFMPEG.

The thread reads consecutive chunks from the stream and saves them in
the given list.

Args:
stream: output stream of the FFMPEG process.
chunks: list to save output chunks to.

Returns:
Thread


def find(self, title):
    files = backend.iterfiles(self._drive, name=title)
    try:
        return next((self[id] for (id, _) in files))
    except StopIteration:
        raise KeyError(title)

Fetch and return the first spreadsheet with the given title.

Args:
title(str): title/name of the spreadsheet to return
Returns:
SpreadSheet: new SpreadSheet instance
Raises:
KeyError: if no spreadsheet with the given ``title`` is found


def register_dispatchable_type(cls):
    _api_dispatcher.register_dispatchable_type(cls)
    return cls

Class decorator that registers a type for use with type-based dispatch.

Should *not* be used with subclasses of `CompositeTensor` or `ExtensionType`
(which are automatically registered).

Note: this function is intended to support internal legacy use cases (such
as RaggedTensorValue), and will probably not be exposed as a public API.

Args:
cls: The class to register.

Returns:
`cls`.


def prune(A, threshold):
    if isinstance(A, Poly):
        B = A.A.copy()
        for key in A.keys:
            values = B[key].copy()
            values[(numpy.abs(values) < threshold)] = 0.0
            B[key] = values
        return Poly(B, A.dim, A.shape, A.dtype)
    A = A.copy()
    A[(numpy.abs(A) < threshold)] = 0.0
    return A

Remove coefficients that is not larger than a given threshold.

Args:
A (Poly):
Input data.
threshold (float):
Threshold for which values to cut.

Returns:
(Poly):
Same type as A.

Examples:
>>> P = chaospy.sum(chaospy.prange(3)*2**-numpy.arange(0, 6, 2, float))
>>> print(P)
0.0625q0^2+0.25q0+1.0
>>> print(chaospy.prune(P, 0.1))
0.25q0+1.0
>>> print(chaospy.prune(P, 0.5))
1.0
>>> print(chaospy.prune(P, 1.5))
0.0


def get_callback_url(self, **kwargs):

    if not self.async:
      raise UnexpectedPipelineError(
          'May only call get_callback_url() method for asynchronous pipelines.')
    kwargs['pipeline_id'] = self._pipeline_key.name()
    params = urllib.urlencode(sorted(kwargs.items()))
    return '%s/callback?%s' % (self.base_path, params)

Returns a relative URL for invoking this Pipeline's callback method.

Args:
kwargs: Dictionary mapping keyword argument names to single values that
should be passed to the callback when it is invoked.

Raises:
UnexpectedPipelineError if this is invoked on pipeline that is not async.


def get_choices_for(self, field):

        choices = self._fields[field].choices
        if isinstance(choices, six.string_types):
            return [(d['value'], d['name']) for d in self._choices_manager.get_all(choices)]
        else:
            return choices

Get the choices for the given fields.

Args:
field (str): Name of field.

Returns:
List of tuples. [(name, value),...]


def __init__(self, queue_id=None):

        super().__init__(action_type=ActionType.OFPAT_SET_QUEUE, length=8)
        self.queue_id = queue_id

Create an ActionSetQueue with the optional parameters below.

Args:
queue_id (int): The queue_id send packets to given queue on port.