def from_json(cls, json_value: Dict[str, Any], *, allow_partial: bool=False, root_path: Optional[utils.KeyPath]=None) -> 'DNA':
    cloneable_metadata_keys = json_value.pop('_cloneable_metadata_keys', None)
    if json_value.get('format', None) == 'compact':
        with symbolic.enable_type_check(False):
            dna = DNA.parse(symbolic.from_json(json_value.get('value')))
            if 'metadata' in json_value:
                dna.rebind(metadata=symbolic.from_json(json_value.get('metadata')), raise_on_no_change=False, skip_notification=True)
    else:
        dna = super(DNA, cls).from_json(json_value, allow_partial=allow_partial, root_path=root_path)
        assert isinstance(dna, DNA)
    if cloneable_metadata_keys:
        dna._cloneable_metadata_keys = set(cloneable_metadata_keys)
    return dna

Class method that load a DNA from a JSON value.

Args:
json_value: Input JSON value, only JSON dict is acceptable.
allow_partial: Whether to allow elements of the list to be partial.
root_path: KeyPath of loaded object in its object tree.

Returns:
A DNA object.


def shape(self) -> torch.Size:
    if self._rot_mats is not None:
        return self._rot_mats.shape[:-2]
    elif self._quats is not None:
        return self._quats.shape[:-1]
    else:
        raise ValueError('Both rotations are None')

Returns the virtual shape of the rotation object. This shape is defined as the batch dimensions of the
underlying rotation matrix or quaternion. If the Rotation was initialized with a [10, 3, 3] rotation matrix
tensor, for example, the resulting shape would be [10].

Returns:
The virtual shape of the rotation object


def fill_rects(self, *rects):

        rect_array = ffi.new('SDL_Rect[]', len(rects))
        for i, r in enumerate(rects):
            rect_array[i] = r._ptr[0]
        check_int_err(lib.SDL_RenderFillRects(self._ptr, rect_array, len(rects)))

Fill some number of rectangles on the current rendering target with the drawing color.

Args:
*rects (Rect): The destination rectangles.

Raises:
SDLError: If an error is encountered.


def PushAttributeContainer(self, serialized_data):
    self._list.append(serialized_data)
    self.data_size += len(serialized_data)
    self.next_sequence_number += 1

Pushes a serialized attribute container onto the list.

Args:
serialized_data (bytes): serialized attribute container data.


def heightmap_add_hm(
    hm1: np.ndarray, hm2: np.ndarray, hm3: np.ndarray
) -> None:

    hm3[:] = hm1[:] + hm2[:]

Add two heightmaps together and stores the result in ``hm3``.

Args:
hm1 (numpy.ndarray): The first heightmap.
hm2 (numpy.ndarray): The second heightmap to add to the first.
hm3 (numpy.ndarray): A destination heightmap to store the result.

.. deprecated:: 2.0
Do ``hm3[:] = hm1[:] + hm2[:]`` instead.


def ParseFileObject(self, parser_mediator, file_object):

    file_entry = parser_mediator.GetFileEntry()
    display_name = parser_mediator.GetDisplayName()

    file_header_map = self._GetDataTypeMap('custom_file_header')

    try:
      file_header, file_offset = self._ReadStructureFromFileObject(
          file_object, 0, file_header_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.UnableToParseFile((
          'Invalid Custom Destination: {0:s} - unable to parse file header '
          'with error: {1!s}').format(display_name, exception))

    if file_header.unknown1 != 2:
      raise errors.UnableToParseFile((
          'Unsupported Custom Destination file: {0:s} - invalid unknown1: '
          '{1:d}.').format(display_name, file_header.unknown1))

    if file_header.header_values_type > 2:
      raise errors.UnableToParseFile((
          'Unsupported Custom Destination file: {0:s} - invalid header value '
          'type: {1:d}.').format(display_name, file_header.header_values_type))

    if file_header.header_values_type == 0:
      data_map_name = 'custom_file_header_value_type_0'
    else:
      data_map_name = 'custom_file_header_value_type_1_or_2'

    file_header_value_map = self._GetDataTypeMap(data_map_name)

    try:
      _, value_data_size = self._ReadStructureFromFileObject(
          file_object, file_offset, file_header_value_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.UnableToParseFile((
          'Invalid Custom Destination: {0:s} - unable to parse file header '
          'value with error: {1!s}').format(display_name, exception))

    file_offset += value_data_size
    file_size = file_object.get_size()
    remaining_file_size = file_size - file_offset

    entry_header_map = self._GetDataTypeMap('custom_entry_header')
    file_footer_map = self._GetDataTypeMap('custom_file_footer')

    first_guid_checked = False
    while remaining_file_size > 4:
      try:
        entry_header, entry_data_size = self._ReadStructureFromFileObject(
            file_object, file_offset, entry_header_map)

      except (ValueError, errors.ParseError) as exception:
        if not first_guid_checked:
          raise errors.UnableToParseFile((
              'Invalid Custom Destination file: {0:s} - unable to parse '
              'entry header with error: {1!s}').format(
                  display_name, exception))

        parser_mediator.ProduceExtractionWarning(
            'unable to parse entry header with error: {0!s}'.format(
                exception))
        break

      if entry_header.guid != self._LNK_GUID:
        if not first_guid_checked:
          raise errors.UnableToParseFile((
              'Unsupported Custom Destination file: {0:s} - invalid entry '
              'header signature offset: 0x{1:08x}.').format(
                  display_name, file_offset))

        try:

          file_footer, _ = self._ReadStructureFromFileObject(
              file_object, file_offset, file_footer_map)

          if file_footer.signature != self._FILE_FOOTER_SIGNATURE:
            parser_mediator.ProduceExtractionWarning(
                'invalid entry header signature at offset: 0x{0:08x}'.format(
                    file_offset))

        except (ValueError, errors.ParseError) as exception:
          parser_mediator.ProduceExtractionWarning((
              'unable to parse footer at offset: 0x{0:08x} with error: '
              '{1!s}').format(file_offset, exception))
          break

        break

      first_guid_checked = True
      file_offset += entry_data_size
      remaining_file_size -= entry_data_size

      lnk_file_size = self._ParseLNKFile(
          parser_mediator, file_entry, file_offset, remaining_file_size)

      file_offset += lnk_file_size
      remaining_file_size -= lnk_file_size

    try:
      file_footer, _ = self._ReadStructureFromFileObject(
          file_object, file_offset, file_footer_map)

      if file_footer.signature != self._FILE_FOOTER_SIGNATURE:
        parser_mediator.ProduceExtractionWarning(
            'invalid footer signature at offset: 0x{0:08x}'.format(file_offset))

    except (ValueError, errors.ParseError) as exception:
      parser_mediator.ProduceExtractionWarning((
          'unable to parse footer at offset: 0x{0:08x} with error: '
          '{1!s}').format(file_offset, exception))

Parses a .customDestinations-ms file-like object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): a file-like object.

Raises:
UnableToParseFile: when the file cannot be parsed.


def detect_gaps(dataframe, timestep, print_all=False, print_max=5, verbose=True):
    gcount = 0
    msg_counter = 0
    warning_printed = False
    try:
        n = len(dataframe.index)
    except:
        print('Error: Invalid dataframe.')
        return (- 1)
    for i in range(0, n):
        if (i > 0):
            time_diff = (dataframe.index[i] - dataframe.index[(i - 1)])
            if ((time_diff.delta / 1000000000.0) != timestep):
                gcount += 1
                if (print_all or (msg_counter <= (print_max - 1))):
                    if verbose:
                        print(('Warning: Gap in time series found between %s and %s' % (dataframe.index[(i - 1)], dataframe.index[i])))
                    msg_counter += 1
                if ((msg_counter == print_max) and verbose and (not warning_printed)):
                    print(('Waring: Only the first %i gaps have been listed. Try to increase print_max parameter to show more details.' % msg_counter))
                    warning_printed = True
    if verbose:
        print(('%i gaps found in total.' % gcount))
    return gcount

checks if a given dataframe contains gaps and returns the number of gaps

This funtion checks if a dataframe contains any gaps for a given temporal
resolution that needs to be specified in seconds. The number of gaps
detected in the dataframe is returned.

Args:
dataframe: A pandas dataframe object with index defined as datetime
timestep (int): The temporal resolution of the time series in seconds
(e.g., 86400 for daily values)
print_all (bool, opt): Lists every gap on the screen
print_mx (int, opt): The maximum number of gaps listed on the screen in
order to avoid a decrease in performance if numerous gaps occur
verbose (bool, opt): Enables/disables output to the screen

Returns:
The number of gaps as integer. Negative values indicate errors.


def _parse_peer_address(self, config):
    match = re.search('peer-address ([^\\s]+)', config)
    value = (match.group(1) if match else None)
    return dict(peer_address=value)

Scans the config block and parses the peer-address value

Args:
config (str): The config block to scan

Returns:
dict: A dict object that is intended to be merged into the
resource dict


def find_coord(targ_length,xyz,rcum,theta,phi):

    i = np.nonzero(rcum <= targ_length)[0][-1]
    if i == len(theta):
        return xyz[-1,:]
    else:
        r_lcl = targ_length-rcum[i]
        (dx,dy,dz) = spherical_to_cartesian(r_lcl,theta[i],phi[i])
        return xyz[i,:] + [dx,dy,dz]

Find (x,y,z) ending coordinate of segment path along section
path.

Args:
targ_length = scalar specifying length of segment path, starting
from the begining of the section path
xyz = coordinates specifying the section path
rcum = cumulative sum of section path length at each node in xyz
theta, phi = angles between each coordinate in xyz


def get_associated(self, retrieve=False):

		if self.exists and hasattr(self.rdf.triples, 'pcdm') and hasattr(self.rdf.triples.pcdm, 'hasRelatedFile'):
			files = [ self.repo.parse_uri(uri) for uri in self.rdf.triples.pcdm.hasRelatedFile ]

			return files

		else:
			return []

get pcdm:hasRelatedFile for this resource

Args:
retrieve (bool): if True, issue .refresh() on resource thereby confirming existence and retrieving payload


def should_stop(self):
    return self._stop_event.is_set()

Check if stop was requested.

Returns:
True if a stop was requested.


def get_component(self, component_name):
    mapping = self.get_components()
    return (mapping[component_name] if (component_name in mapping) else None)

Looks up a component by its name.

Args:
component_name: The name of the component to look up.
Returns:
The component for the provided name or None if there is no such component.


def save_to_text_file(monsoon_data, file_path):

        if not monsoon_data:
            raise MonsoonError("Attempting to write empty Monsoon data to "
                               "file, abort")
        utils.create_dir(os.path.dirname(file_path))
        with io.open(file_path, 'w', encoding='utf-8') as f:
            for md in monsoon_data:
                f.write(str(md))
                f.write(MonsoonData.delimiter)

Save multiple MonsoonData objects to a text file.

Args:
monsoon_data: A list of MonsoonData objects to write to a text
file.
file_path: The full path of the file to save to, including the file
name.


async def init(self, name, conf=None):

        tank = self.tanks.get(name)
        if tank is not None:
            return tank

        iden = s_common.guid()

        logger.info('Creating new tank: %s', name)

        path = s_common.genpath(self.dirn, 'tanks', iden)

        tank = await CryoTank.anit(path, conf)

        node = await self.names.open((name,))
        await node.set((iden, conf))

        self.tanks.put(name, tank)

        return tank

Generate a new CryoTank with a given name or get an reference to an existing CryoTank.

Args:
name (str): Name of the CryoTank.

Returns:
CryoTank: A CryoTank instance.


def MoveStateToNextToken(self):
    current = self.next_token
    if not current.OpensScope() and (not current.ClosesScope()):
        self.lowest_level_on_line = min(self.lowest_level_on_line, self.paren_level)
    if current.OpensScope():
        last = self.stack[-1]
        new_indent = style.Get('CONTINUATION_INDENT_WIDTH') + last.last_space
        self.stack.append(_ParenState(new_indent, self.stack[-1].last_space))
        self.paren_level += 1
    if len(self.stack) > 1 and current.ClosesScope():
        if subtypes.DICTIONARY_KEY_PART in current.subtypes:
            self.stack[-2].last_space = self.stack[-2].indent
        else:
            self.stack[-2].last_space = self.stack[-1].last_space
        self.stack.pop()
        self.paren_level -= 1
    is_multiline_string = current.is_string and '\n' in current.value
    if is_multiline_string:
        self.column += len(current.value.split('\n')[0])
    elif not current.is_pseudo:
        self.column += len(current.value)
    self.next_token = self.next_token.next_token
    penalty = 0
    if not current.is_pylint_comment and (not current.is_pytype_comment) and (not current.is_copybara_comment) and (self.column > self.column_limit):
        excess_characters = self.column - self.column_limit
        penalty += style.Get('SPLIT_PENALTY_EXCESS_CHARACTER') * excess_characters
    if is_multiline_string:
        self.column = len(current.value.split('\n')[-1])
    return penalty

Calculate format decision state information and move onto the next token.

Before moving onto the next token, we first calculate the format decision
state given the current token and its formatting decisions. Then the format
decision state is set up so that the next token can be added.

Returns:
The penalty for the number of characters over the column limit.


def _binary_product(variables):

    multiplier, multiplicand, product = variables

    return BinaryQuadraticModel({multiplier: 0.0,
                                 multiplicand: 0.0,
                                 product: 3.0},
                                {(multiplier, multiplicand): 1.0,
                                 (multiplier, product): -2.0,
                                 (multiplicand, product): -2.0},
                                0.0,
                                Vartype.BINARY)

Create a bqm with a gap of 2 that represents the product of two variables.

Args:
variables (list):
multiplier, multiplicand, product

Returns:
:obj:`.BinaryQuadraticModel`


def LessThanOrEqualTo(self, value):
    self._awql = self._CreateSingleValueCondition(value, '<=')
    return self._query_builder

Sets the type of the WHERE clause as "less than or equal to.

Args:
value: The value to be used in the WHERE condition.

Returns:
The query builder that this WHERE builder links to.


def config_file(self, filename):
    if os.path.isfile(filename):
        with open(filename, 'r') as fh:
            self._config_data = json.load(fh)
    else:
        self.tcex.log.error('Could not load configuration file "{}".'.format(filename))

Load configuration data from provided file and inject values into sys.argv.

Args:
config (str): The configuration file name.


def recipe_email_dv360_to_bigquery(config, auth_read, email, subject, dataset, table, dbm_schema, is_incremental_load):
    email(config, {'auth': auth_read, 'read': {'from': 'noreply-dv360@google.com', 'to': email, 'subject': subject, 'link': 'https:

Pulls a DV360 Report from a gMail email into BigQuery.

Args:
auth_read (authentication) - Credentials used for reading data.
email (string) - Email address report was sent to.
subject (string) - Regular expression to match subject. Double escape backslashes.
dataset (string) - Existing dataset in BigQuery.
table (string) - Name of table to be written to.
dbm_schema (json) - Schema provided in JSON list format or empty list.
is_incremental_load (boolean) - Append report data to table based on date column, de-duplicates.


def wrap_cached_variables(concrete_function):
    outer_graph = func_graph_module.FuncGraph('{}_no_cache'.format(concrete_function.graph.name))
    mapped_captures = None
    remapped_captures = {}
    with outer_graph.as_default():
        for capture, placeholder in concrete_function.graph.captures:
            cached_variable = getattr(capture, '_cached_variable', None)
            if cached_variable is None:
                continue
            cached_variable = cached_variable()
            new_cached_value = cached_variable.read_value()
            key = id(capture)
            external = concrete_function.graph.function_captures.by_val_external[key]
            internal = concrete_function.graph.function_captures.by_val_internal[key]
            remapped_captures[key] = [external, internal]
            concrete_function.graph.function_captures.add_or_replace(key=key, external=new_cached_value, internal=placeholder, is_by_ref=False)
            mapped_captures = True
    if not mapped_captures:
        return concrete_function
    inner_concrete = defun.ConcreteFunction.from_func_graph(concrete_function.graph, concrete_function.function_type, {})

    def wrap_function(*args):
        return inner_concrete._call_flat(list(args), inner_concrete.captured_inputs)
    args = nest.flatten(concrete_function.structured_input_signature, expand_composites=True)
    func_graph_module.func_graph_from_py_func(None, wrap_function, args=tuple(args), kwargs={}, func_graph=outer_graph)
    fn = defun.ConcreteFunction.from_func_graph(outer_graph, concrete_function.function_type, {})
    fn._arg_keywords = concrete_function._arg_keywords
    fn._num_positional_args = concrete_function._num_positional_args
    for key, capture in remapped_captures.items():
        external, internal = capture
        concrete_function.graph._function_captures.add_or_replace(key=key, external=external, internal=internal, is_by_ref=False)
    return fn

Wraps the concrete function if it uses cached read tensors.

This function creates a new concrete function that captures variables
instead of the cached read tensors.

Args:
concrete_function: A Concrete function that maybe captures cached read
tensors.

Returns:
A concrete function that wraps the original concrete function, which
captures variables instead. If the original function did not capture any
cached values, then the function is not wrapped and the original object is
returned.


def print_table(self, stream=sys.stdout, filter_function=None):

        print(self.to_table(filter_function=filter_function), file=stream)

A pretty ASCII printer for the periodic table, based on some filter_function.

Args:
stream: file-like object
filter_function:
A filtering function that take a Pseudo as input and returns a boolean.
For example, setting filter_function = lambda p: p.Z_val > 2 will print
a periodic table containing only pseudos with Z_val > 2.


def compile_default_action(self, batch_size: Optional[int] = None) -> Sequence[tf.Tensor]:

        with self.graph.as_default():
            with tf.name_scope('default_action'):
                self._initialize_default_action_fluents()
                if batch_size is None:
                    return self.default_action_fluents
                return self._compile_batch_fluents(self.default_action_fluents, batch_size)

Returns a tuple of tensors representing the default action fluents.

Args:
batch_size (int): The batch size.

Returns:
Sequence[tf.Tensor]: A tuple of tensors.


def num_tasks(self, job_name):
    try:
        job = self._cluster_spec[job_name]
    except KeyError:
        raise ValueError('No such job in cluster: %r' % job_name)
    return len(job)

Returns the number of tasks defined in the given job.

Args:
job_name: The string name of a job in this cluster.

Returns:
The number of tasks defined in the given job.

Raises:
ValueError: If `job_name` does not name a job in this cluster.


def from_pandas(pandas_df, dataset_class=dataset.pandas_dataset.PandasDataset, expectations_config=None, autoinspect_func=None):
    return _convert_to_dataset_class(pandas_df, dataset_class, expectations_config, autoinspect_func)

Read a Pandas data frame and return a great_expectations dataset.

Args:
pandas_df (Pandas df): Pandas data frame
dataset_class (Dataset class) = dataset.pandas_dataset.PandasDataset:
class to which to convert resulting Pandas df
expectations_config (string) = None: path to great_expectations config file
autoinspect_func (function) = None: The autoinspection function that should
be run on the dataset to establish baseline expectations.

Returns:
great_expectations dataset


def deserialize(config, custom_objects=None):
    if config['class_name'].lower() in ALL_OBJECTS_DICT:
        config['class_name'] = config['class_name'].lower()
    return serialization_lib.deserialize_keras_object(config, module_objects=ALL_OBJECTS_DICT, custom_objects=custom_objects)

Returns a Keras optimizer object via its configuration.

Args:
config: Optimizer configuration dictionary.
custom_objects: Optional dictionary mapping names (strings) to custom
objects (classes and functions) to be considered during
deserialization.

Returns:
A Keras Optimizer instance.


def get_cytoband_coordinates(chrom, pos):

    coordinate = ""

    if chrom in CYTOBANDS:
        for interval in CYTOBANDS[chrom][pos]:
            coordinate = interval.data

    return coordinate

Get the cytoband coordinate for a position

Args:
chrom(str)
pos(int)

Returns:
coordinate(str)


def _is_default_hook(default_hook, hook):

    if not hasattr(default_hook, '__call__'):
      raise TypeError('Default hooks for ndb.model.Model must be callable')
    if not hasattr(hook, '__call__'):
      raise TypeError('Hooks must be callable')
    return default_hook.im_func is hook.im_func

Checks whether a specific hook is in its default state.

Args:
cls: A ndb.model.Model class.
default_hook: Callable specified by ndb internally (do not override).
hook: The hook defined by a model class using _post_*_hook.

Raises:
TypeError if either the default hook or the tested hook are not callable.


def _getGraphOpTypes(self, graphdef, output_nodes):
    name_to_input_name, name_to_node, _ = _extract_graph_summary(graphdef)
    used_node_names = _bfs_for_reachable_nodes(output_nodes, name_to_input_name)
    return set([name_to_node[node_name].op for node_name in used_node_names])

Returns used op types in `graphdef` reachable from `output_nodes`.

This is used to check that after the stub transformation the expected
nodes are there.

NOTE: this is not a exact test that the graph is the correct output, but
it balances compact expressibility of test with sanity checking.

Args:
graphdef: TensorFlow proto graphdef.
output_nodes: A list of output node names that we need to reach.

Returns:
A set of node types reachable from `output_nodes`.


def update_metadata(token: str, commit_sha: str):
    frameworks_table = get_frameworks_table()
    frameworks_dataset = Dataset.from_pandas(frameworks_table)
    resolved_tags_file = hf_hub_download('huggingface/transformers-metadata', 'pipeline_tags.json', repo_type='dataset', token=token)
    tags_dataset = Dataset.from_json(resolved_tags_file)
    table = {tags_dataset[i]['model_class']: (tags_dataset[i]['pipeline_tag'], tags_dataset[i]['auto_class']) for i in range(len(tags_dataset))}
    table = update_pipeline_and_auto_class_table(table)
    model_classes = sorted(table.keys())
    tags_table = pd.DataFrame({'model_class': model_classes, 'pipeline_tag': [table[m][0] for m in model_classes], 'auto_class': [table[m][1] for m in model_classes]})
    tags_dataset = Dataset.from_pandas(tags_table)
    hub_frameworks_json = hf_hub_download(repo_id='huggingface/transformers-metadata', filename='frameworks.json', repo_type='dataset', token=token)
    with open(hub_frameworks_json) as f:
        hub_frameworks_json = f.read()
    hub_pipeline_tags_json = hf_hub_download(repo_id='huggingface/transformers-metadata', filename='pipeline_tags.json', repo_type='dataset', token=token)
    with open(hub_pipeline_tags_json) as f:
        hub_pipeline_tags_json = f.read()
    with tempfile.TemporaryDirectory() as tmp_dir:
        frameworks_dataset.to_json(os.path.join(tmp_dir, 'frameworks.json'))
        tags_dataset.to_json(os.path.join(tmp_dir, 'pipeline_tags.json'))
        with open(os.path.join(tmp_dir, 'frameworks.json')) as f:
            frameworks_json = f.read()
        with open(os.path.join(tmp_dir, 'pipeline_tags.json')) as f:
            pipeline_tags_json = f.read()
        frameworks_equal = hub_frameworks_json == frameworks_json
        hub_pipeline_tags_equal = hub_pipeline_tags_json == pipeline_tags_json
        if frameworks_equal and hub_pipeline_tags_equal:
            print('No updates on the Hub, not pushing the metadata files.')
            return
        if commit_sha is not None:
            commit_message = f'Update with commit {commit_sha}\n\nSee: https:
        else:
            commit_message = 'Update'
        upload_folder(repo_id='huggingface/transformers-metadata', folder_path=tmp_dir, repo_type='dataset', token=token, commit_message=commit_message)

Update the metadata for the Transformers repo in `huggingface/transformers-metadata`.

Args:
token (`str`): A valid token giving write access to `huggingface/transformers-metadata`.
commit_sha (`str`): The commit SHA on Transformers corresponding to this update.


def line_intersection(self, point1, point2, tolerance=1e-8):

        b1 = self.bary_coords(point1)
        b2 = self.bary_coords(point2)
        l = b1 - b2

        valid = np.abs(l) > 1e-10

        possible = b1 - (b1[valid] / l[valid])[:, None] * l
        barys = []
        for p in possible:

            if (p >= -tolerance).all():
                found = False

                for b in barys:
                    if np.all(np.abs(b - p) < tolerance):
                        found = True
                        break
                if not found:
                    barys.append(p)
        assert len(barys) < 3
        return [self.point_from_bary_coords(b) for b in barys]

Computes the intersection points of a line with a simplex
Args:
point1, point2 ([float]): Points that determine the line
Returns:
points where the line intersects the simplex (0, 1, or 2)


def _make_auth(self, method, date, nonce, path, query={}, ctype='application/json'):

        query = urlencode(query)

        hmac_str = (method + '\n' + nonce + '\n' + date + '\n' + ctype + '\n' + path +
                    '\n' + query + '\n').lower().encode('utf-8')

        signature = base64.b64encode(hmac.new(self._secret_key, hmac_str, digestmod=hashlib.sha256).digest())
        auth = 'On ' + self._access_key.decode('utf-8') + ':HmacSHA256:' + signature.decode('utf-8')

        if self._logging:
            utils.log({
                'query': query,
                'hmac_str': hmac_str,
                'signature': signature,
                'auth': auth
            })

        return auth

Create the request signature to authenticate

Args:
- method (str): HTTP method
- date (str): HTTP date header string
- nonce (str): Cryptographic nonce
- path (str): URL pathname
- query (dict, default={}): URL query string in key-value pairs
- ctype (str, default='application/json'): HTTP Content-Type


def __call__(self, shape, dtype=None, **kwargs):
    _validate_kwargs(self.__class__.__name__, kwargs)
    dtype = _assert_float_dtype(_get_dtype(dtype))
    if _PARTITION_SHAPE in kwargs:
        shape = kwargs[_PARTITION_SHAPE]
    return self._random_generator.random_normal(shape, self.mean, self.stddev, dtype)

Returns a tensor object initialized to random normal values.

Args:
shape: Shape of the tensor.
dtype: Optional dtype of the tensor. Only floating point types are
supported. If not specified, `tf.keras.backend.floatx()` is used, which
default to `float32` unless you configured it otherwise (via
`tf.keras.backend.set_floatx(float_dtype)`)
**kwargs: Additional keyword arguments.


def get_folders(cls, session, mailbox_or_id):

        if isinstance(mailbox_or_id, Mailbox):
            mailbox_or_id = mailbox_or_id.id
        return cls(
            '/mailboxes/%d/folders.json' % mailbox_or_id,
            session=session,
            out_type=Folder,
        )

List the folders for the mailbox.

Args:
mailbox_or_id (helpscout.models.Mailbox or int): Mailbox or the ID
of the mailbox to get the folders for.

Returns:
RequestPaginator(output_type=helpscout.models.Folder): Folders
iterator.


class _IndicatorColumn(_DenseColumn, _SequenceDenseColumn, collections.namedtuple('_IndicatorColumn', ['categorical_column'])):

    @property
    def name(self):
        return '{}_indicator'.format(self.categorical_column.name)

    def _transform_feature(self, inputs):

        id_weight_pair = self.categorical_column._get_sparse_tensors(inputs)
        id_tensor = id_weight_pair.id_tensor
        weight_tensor = id_weight_pair.weight_tensor
        if weight_tensor is not None:
            weighted_column = sparse_ops.sparse_merge(sp_ids=id_tensor, sp_values=weight_tensor, vocab_size=int(self._variable_shape[-1]))
            weighted_column = sparse_ops.sparse_slice(weighted_column, [0, 0], weighted_column.dense_shape)
            return array_ops.scatter_nd(weighted_column.indices, weighted_column.values, weighted_column.dense_shape)
        dense_id_tensor = sparse_ops.sparse_tensor_to_dense(id_tensor, default_value=-1)
        one_hot_id_tensor = array_ops.one_hot(dense_id_tensor, depth=self._variable_shape[-1], on_value=1.0, off_value=0.0)
        return math_ops.reduce_sum(one_hot_id_tensor, axis=[-2])

    @property
    def _parse_example_spec(self):
        return self.categorical_column._parse_example_spec

    @property
    def _variable_shape(self):

        return tensor_shape.TensorShape([1, self.categorical_column._num_buckets])

    def _get_dense_tensor(self, inputs, weight_collections=None, trainable=None):

        del weight_collections
        del trainable
        if isinstance(self.categorical_column, _SequenceCategoricalColumn):
            raise ValueError('In indicator_column: {}. categorical_column must not be of type _SequenceCategoricalColumn. Suggested fix A: If you wish to use input_layer, use a non-sequence categorical_column_with_*. Suggested fix B: If you wish to create sequence input, use sequence_input_layer instead of input_layer. Given (type {}): {}'.format(self.name, type(self.categorical_column), self.categorical_column))
        return inputs.get(self)

    def _get_sequence_dense_tensor(self, inputs, weight_collections=None, trainable=None):
        del weight_collections
        del trainable
        if not isinstance(self.categorical_column, _SequenceCategoricalColumn):
            raise ValueError('In indicator_column: {}. categorical_column must be of type _SequenceCategoricalColumn to use sequence_input_layer. Suggested fix: Use one of sequence_categorical_column_with_*. Given (type {}): {}'.format(self.name, type(self.categorical_column), self.categorical_column))
        dense_tensor = inputs.get(self)
        sparse_tensors = self.categorical_column._get_sparse_tensors(inputs)
        sequence_length = fc_utils.sequence_length_from_sparse_tensor(sparse_tensors.id_tensor)
        return _SequenceDenseColumn.TensorSequenceLengthPair(dense_tensor=dense_tensor, sequence_length=sequence_length)

Represents a one-hot column for use in deep networks.

Args:
categorical_column: A `_CategoricalColumn` which is created by
`categorical_column_with_*` function.


def bin(self, bins, labels=None):
    return dim(self, bin, bins, labels=labels)

Bins continuous values.

Bins continuous using the provided bins and assigns labels
either computed from each bins center point or from the
supplied labels.

Args:
bins: List or array containing the bin boundaries
labels: List of labels to assign to each bin
If the bins are length N the labels should be length N-1


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

        super(StateTransaction, self).__init__(*args, **kwargs)

        self.Type = TransactionType.StateTransaction

Create an instance.

Args:
*args:
**kwargs:


def authenticate(self, request):

        request = request._request
        user = getattr(request, 'user', None)

        if not user or user.is_anonymous:
            return None

        self.enforce_csrf(request)

        return (user, None)

Authenticate the user, requiring a logged-in account and CSRF.

This is exactly the same as the `SessionAuthentication` implementation,
with the `user.is_active` check removed.

Args:
request (HttpRequest)

Returns:
Tuple of `(user, token)`

Raises:
PermissionDenied: The CSRF token check failed.


def get(self, key, index=None):
    records = self.get_multi([key], index=index)
    try:
        return records[0][1]
    except IndexError:
        return None

Retrieves a value associated with a key from the database

Args:
key (str): The key to retrieve


def concurrence(state):

    rho = np.array(state)
    if rho.ndim == 1:
        rho = outer(state)
    if len(state) != 4:
        raise Exception("Concurrence is only defined for more than two qubits")

    YY = np.fliplr(np.diag([-1, 1, 1, -1]))
    A = rho.dot(YY).dot(rho.conj()).dot(YY)
    w = la.eigh(A, eigvals_only=True)
    w = np.sqrt(np.maximum(w, 0))
    return max(0.0, w[-1] - np.sum(w[0:-1]))

Calculate the concurrence.

Args:
state (np.array): a quantum state (1x4 array) or a density matrix (4x4
array)
Returns:
float: concurrence.
Raises:
Exception: if attempted on more than two qubits.


def __init__(self, command=None, payload=None, print_payload=False):

        self.Command = command
        self.Magic = settings.MAGIC

        if payload is None:
            payload = bytearray()
        else:
            payload = binascii.unhexlify(Helper.ToArray(payload))

        self.Checksum = Message.GetChecksum(payload)
        self.Payload = payload

        if print_payload:
            logger.info("PAYLOAD: %s " % self.Payload)

Create an instance.

Args:
command (str): payload command e.g. "inv", "getdata". See NeoNode.MessageReceived() for more commands.
payload (bytes): raw bytes of the payload.
print_payload: UNUSED


def List(self, device_path):
    connection = self.protocol_handler.Open(self._handle, destination=b'sync:')
    listing = self.filesync_handler.List(connection, device_path)
    connection.Close()
    return listing

Return a directory listing of the given path.

Args:
device_path: Directory to list.


def update_args(self, args):
    for arg in vars(args):
        if (self.get(arg) and (getattr(args, arg) is not None)):
            self._config[self.root_section][arg] = getattr(args, arg)

Update config dictionary with parsed args, as resolved by argparse.
Only root positional arguments that already exist will overridden.

Args:
args (namespace): args parsed by argparse


def make_request(url, data, on_complete):
    req = ajax.ajax()
    req.bind('complete', on_complete)
    req.open('POST', url, True)
    req.set_header('content-type', 'application/x-www-form-urlencoded')
    req.send(data)

Make AJAX request to `url` with given POST `data`. Call `on_complete`
callback when complete.

Args:
url (str): URL.
data (dict): Dictionary with POST data.
on_complete (ref): Reference to function / method which will be called
when the request is done.


def fashion_mnist_generator(tmp_dir, training, how_many, start_from=0):
    _get_fashion_mnist(tmp_dir)
    d = (_FASHION_MNIST_LOCAL_FILE_PREFIX + (_MNIST_TRAIN_DATA_FILENAME if training else _MNIST_TEST_DATA_FILENAME))
    l = (_FASHION_MNIST_LOCAL_FILE_PREFIX + (_MNIST_TRAIN_LABELS_FILENAME if training else _MNIST_TEST_LABELS_FILENAME))
    return mnist_common_generator(tmp_dir, training, how_many, d, l, start_from)

Image generator for FashionMNIST.

Args:
tmp_dir: path to temporary storage directory.
training: a Boolean; if true, we use the train set, otherwise the test set.
how_many: how many images and labels to generate.
start_from: from which image to start.

Returns:
An instance of image_generator that produces MNIST images.


def cost(self, t_node, branch_length, multiplicity=2.0):

        merger_time = t_node+branch_length
        return self.integral_merger_rate(merger_time) - self.integral_merger_rate(t_node)\
                 - np.log(self.total_merger_rate(merger_time))*(multiplicity-1.0)/multiplicity

returns the cost associated with a branch starting at t_node
t_node is time before present, the branch goes back in time

Args:
- t_node:           time of the node
- branch_length:    branch length, determines when this branch merges with sister
- multiplicity:     2 if merger is binary, higher if this is a polytomy


def _get_max_page(dom):

    div = dom.find("div", {"class": "razeniKnihListovani"})

    if not div:
        return 1

    links = div[0].find("a")
    max_page = filter(
        lambda x: "href" in x.params and "pageindex=" in x.params["href"],
        links
    )
    max_page = map(
        lambda x: x.params["href"].split("pageindex=")[-1],
        max_page
    )
    max_page = filter(lambda x: x.isdigit(), max_page)
    max_page = map(lambda x: int(x), max_page)

    if not max_page:
        return 1

    return max(max_page)

Try to guess how much pages are in book listing.

Args:
dom (obj): HTMLElement container of the page with book list.

Returns:
int: Number of pages for given category.


def get_gates(self, x):
    x = tf.stop_gradient(x)
    x = tf.matmul(x, self.t_vectors)
    x = tf.sign(x)
    x = (tf.matmul(x, self.t_group, transpose_b=True) / self.nb_hyperplanes)
    x = tf.argmax(x, axis=(- 1))
    x = tf.one_hot(x, self.nb_buckets)
    return x

Return the bucket id of the given tensor.

Args:
x (tf.Tensor): float32 of shape [length, depth]

Returns:
tf.Tensor: One-hot vector int64 of shape [heads, length, nb_buckets]
containing the id of the bucket


def check_channel(fcn):

    def wrapper(*args, **kwargs):
        if not isinstance(args[1], ChannelResource):
            raise RuntimeError('resource must be an instance of intern.resource.boss.ChannelResource.')

        if not args[1].cutout_ready:
            raise PartialChannelResourceError(
                    'ChannelResource not fully initialized.  Use intern.remote.BossRemote.get_channel({}, {}, {})'.format(
                        args[1].name, args[1].coll_name, args[1].exp_name))
        return fcn(*args, **kwargs)

    return wrapper

Decorator that ensures a valid channel passed in.

Args:
fcn (function): Function that has a ChannelResource as its second argument.

Returns:
(function): Wraps given function with one that checks for a valid channel.


def __init__(self, cell):
    self._cell = cell

Creates a new SamplerCell.

Args:
cell: A c pointer of TFE_MonitoringSamplerCell.


def nic_v1(msg, NICs):
    if ((typecode(msg) < 5) or (typecode(msg) > 22)):
        raise RuntimeError(('%s: Not a surface position message (5<TC<8),             airborne position message (8<TC<19),             or airborne position with GNSS height (20<TC<22)' % msg))
    tc = typecode(msg)
    NIC = uncertainty.TC_NICv1_lookup[tc]
    if isinstance(NIC, dict):
        NIC = NIC[NICs]
    try:
        Rc = uncertainty.NICv1[NIC][NICs]['Rc']
        VPL = uncertainty.NICv1[NIC][NICs]['VPL']
    except KeyError:
        (Rc, VPL) = (uncertainty.NA, uncertainty.NA)
    return (Rc, VPL)

Calculate NIC, navigation integrity category, for ADS-B version 1

Args:
msg (string): 28 bytes hexadecimal message string
NICs (int or string): NIC supplement

Returns:
int or string: Horizontal Radius of Containment
int or string: Vertical Protection Limit


def create_impression_event(self, experiment, variation_id, user_id, attributes):
    params = self._get_common_params(user_id, attributes)
    impression_params = self._get_required_params_for_impression(experiment, variation_id)
    params[self.EventParams.USERS][0][self.EventParams.SNAPSHOTS].append(impression_params)
    return Event(self.EVENTS_URL, params, http_verb=self.HTTP_VERB, headers=self.HTTP_HEADERS)

Create impression Event to be sent to the logging endpoint.

Args:
experiment: Experiment for which impression needs to be recorded.
variation_id: ID for variation which would be presented to user.
user_id: ID for user.
attributes: Dict representing user attributes and values which need to be recorded.

Returns:
Event object encapsulating the impression event.


def is_ordered(cat_id):
    url = 'https:
    auth = Auth()
    r = _req_with_retries(auth.gbdx_connection, url)
    if (r is not None):
        return (r.status_code == 200)
    return False

Checks to see if a CatalogID has been ordered or not.

Args:
catalogID (str): The catalog ID from the platform catalog.
Returns:
ordered (bool): Whether or not the image has been ordered


def _respond(self, channel, text):
    result = self._format_message(channel, text)
    if (result is not None):
        logger.info('Sending message: %r', truncate(result, max_len=50))
    self.socket.send_str(result)

Respond to a message on the current socket.

Args:
channel (:py:class:`str`): The channel to send to.
text (:py:class:`str`): The message text to send.


def if_callable_call_with_formatted_string(callback, formattable_string, *args):

    try:
        formatted_string = formattable_string.format(*args)
    except IndexError:
        raise ValueError("Mismatch metween amount of insertion points in the formattable string\n"
                         "and the amount of args given.")
    if callable(callback):
        callback(formatted_string)

If the callback is callable, format the string with the args and make a call.
Otherwise, do nothing.

Args:
callback (function): May or may not be callable.
formattable_string (str): A string with '{}'s inserted.
*args: A variable amount of arguments for the string formatting. Must correspond to the
amount of '{}'s in 'formattable_string'.
Raises:
ValueError


def __init__(self, resolver_context):

    super(TSKFile, self).__init__(resolver_context)
    self._current_offset = 0
    self._file_system = None
    self._size = 0
    self._tsk_attribute = None
    self._tsk_file = None

Initializes a file-like object.

Args:
resolver_context (Context): resolver context.


async def cancel(self, task: asyncio.Task, wait_for: bool=True) -> Any:
    if (task is None):
        return
    task.cancel()
    with suppress(KeyError):
        self._tasks.remove(task)
    with suppress(Exception):
        return ((await task) if wait_for else None)

Cancels and waits for an `asyncio.Task` to finish.
Removes it from the collection of managed tasks.

Args:
task (asyncio.Task):
The to be cancelled task.
It is not required that the task was was created with `TaskScheduler.create_task()`.

wait_for (bool, optional):
Whether to wait for the task to finish execution.
If falsey, this function returns immediately after cancelling the task.

Returns:
Any: The return value of `task`. None if `wait_for` is falsey.


def on(self, day, strict=False):

        day_start, day_stop = day.floor('day').span('day')
        if strict:
            return self.included(day_start, day_stop)
        else:
            return self.overlapping(day_start, day_stop)

Iterates (in chronological order) over all events that occurs on `day`

Args:
day (Arrow object)
strict (bool): if True events will be returned only if they are\
strictly *included* in `day`.


def execute_forever(method, interval_s):

  interval = Interval(method)
  interval.start(interval_s)
  return interval

Executes a method forever at the specified interval.

Args:
method: The callable to execute.
interval_s: The number of seconds to start the execution after each method
finishes.
Returns:
An Interval object.


def get_experiment_from_id(self, experiment_id):
    experiment = self.experiment_id_map.get(experiment_id)
    if experiment:
        return experiment
    self.logger.error(('Experiment ID "%s" is not in datafile.' % experiment_id))
    self.error_handler.handle_error(exceptions.InvalidExperimentException(enums.Errors.INVALID_EXPERIMENT_KEY_ERROR))
    return None

Get experiment for the provided experiment ID.

Args:
experiment_id: Experiment ID for which experiment is to be determined.

Returns:
Experiment corresponding to the provided experiment ID.


def create_elb_dns(self, regionspecific=False):

        if regionspecific:
            dns_elb = self.generated.dns()['elb_region']
        else:
            dns_elb = self.generated.dns()['elb']

        dns_elb_aws = find_elb(name=self.app_name, env=self.env, region=self.region)

        zone_ids = get_dns_zone_ids(env=self.env, facing=self.elb_subnet)

        self.log.info('Updating Application URL: %s', dns_elb)

        dns_kwargs = {
            'dns_name': dns_elb,
            'dns_name_aws': dns_elb_aws,
            'dns_ttl': self.dns_ttl,
        }

        for zone_id in zone_ids:
            self.log.debug('zone_id: %s', zone_id)
            update_dns_zone_record(self.env, zone_id, **dns_kwargs)

        return dns_elb

Create dns entries in route53.

Args:
regionspecific (bool): The DNS entry should have region on it
Returns:
str: Auto-generated DNS name for the Elastic Load Balancer.


def _download_to_local(boto_conn, s3_path, fp, num_result_dir, delim=None):

    def _callback(downloaded, total):
        '\n        Call function for upload.\n\n        `downloaded`: File size already downloaded (int)\n\n        `total`: Total file size to be downloaded (int)\n        '
        if ((total is 0) or (downloaded == total)):
            return
        progress = ((downloaded * 100) / total)
        sys.stderr.write('\r[{0}] {1}%'.format(('
        sys.stderr.flush()
    m = _URI_RE.match(s3_path)
    bucket_name = m.group(1)
    bucket = boto_conn.get_bucket(bucket_name)
    retries = 6
    if (s3_path.endswith('/') is False):
        key_name = m.group(2)
        key_instance = bucket.get_key(key_name)
        while ((key_instance is None) and (retries > 0)):
            retries = (retries - 1)
            log.info(('Results file is not available on s3. Retry: ' + str((6 - retries))))
            time.sleep(10)
            key_instance = bucket.get_key(key_name)
        if (key_instance is None):
            raise Exception('Results file not available on s3 yet. This can be because of s3 eventual consistency issues.')
        log.info(('Downloading file from %s' % s3_path))
        if (delim is None):
            try:
                key_instance.get_contents_to_file(fp)
            except boto.exception.S3ResponseError as e:
                if (e.status == 403):
                    log.warn('Access denied while fetching the s3 object. Retrying without specifying the version....')
                    key_instance.open()
                    fp.write(key_instance.read())
                    key_instance.close()
                else:
                    raise
        else:
            _read_iteratively(key_instance, fp, delim=delim)
    else:
        key_prefix = m.group(2)
        bucket_paths = bucket.list(key_prefix)
        for one_path in bucket_paths:
            name = one_path.name
            if name.endswith('$folder$'):
                continue
            log.info(('Downloading file from %s' % name))
            if (delim is None):
                one_path.get_contents_to_file(fp)
            else:
                _read_iteratively(one_path, fp, delim=delim)

Downloads the contents of all objects in s3_path into fp

Args:
`boto_conn`: S3 connection object

`s3_path`: S3 path to be downloaded

`fp`: The file object where data is to be downloaded


def CallNtpdate(logger):
    ntpd_inactive = subprocess.call(['service', 'ntpd', 'status'])
    try:
        if (not ntpd_inactive):
            subprocess.check_call(['service', 'ntpd', 'stop'])
        subprocess.check_call('ntpdate `awk \'$1=="server" {print $2}\' /etc/ntp.conf`', shell=True)
        if (not ntpd_inactive):
            subprocess.check_call(['service', 'ntpd', 'start'])
    except subprocess.CalledProcessError:
        logger.warning('Failed to sync system time with ntp server.')
    else:
        logger.info('Synced system time with ntp server.')

Sync clock using ntpdate.

Args:
logger: logger object, used to write to SysLog and serial port.


def ion_equals(a, b, timestamps_instants_only=False):
    if timestamps_instants_only:
        return _ion_equals_timestamps_instants(a, b)
    return _ion_equals_timestamps_data_model(a, b)

Tests two objects for equivalence under the Ion data model.

There are three important cases:
* When neither operand specifies its `ion_type` or `annotations`, this method will only return True when the
values of both operands are equivalent under the Ion data model.
* When only one of the operands specifies its `ion_type` and `annotations`, this method will only return True
when that operand has no annotations and has a value equivalent to the other operand under the Ion data model.
* When both operands specify `ion_type` and `annotations`, this method will only return True when the ion_type
and annotations of both are the same and their values are equivalent under the Ion data model.

Note that the order of the operands does not matter.

Args:
a (object): The first operand.
b (object): The second operand.
timestamps_instants_only (Optional[bool]): False if timestamp objects (datetime and its subclasses) should be
compared according to the Ion data model (where the instant, precision, and offset must be equal); True
if these objects should be considered equivalent if they simply represent the same instant.


def generate_full_symmops(symmops, tol):
    UNIT = np.eye(4)
    generators = [op.affine_matrix for op in symmops if (not np.allclose(op.affine_matrix, UNIT))]
    if (not generators):
        return symmops
    else:
        full = list(generators)
        for g in full:
            for s in generators:
                op = np.dot(g, s)
                d = (np.abs((full - op)) < tol)
                if (not np.any(np.all(np.all(d, axis=2), axis=1))):
                    full.append(op)
        d = (np.abs((full - UNIT)) < tol)
        if (not np.any(np.all(np.all(d, axis=2), axis=1))):
            full.append(UNIT)
        return [SymmOp(op) for op in full]

Recursive algorithm to permute through all possible combinations of the
initially supplied symmetry operations to arrive at a complete set of
operations mapping a single atom to all other equivalent atoms in the
point group.  This assumes that the initial number already uniquely
identifies all operations.

Args:
symmops ([SymmOp]): Initial set of symmetry operations.

Returns:
Full set of symmetry operations.


def get_http_json(self, url=None, retry_count=3, rate_limit_timeout=120, headers=None):
    if (headers is None):
        headers = {'Accept': 'application/rdap+json'}
    try:
        log.debug('HTTP query for {0} at {1}'.format(self.address_str, url))
        conn = Request(url, headers=headers)
        data = self.opener.open(conn, timeout=self.timeout)
        try:
            d = json.loads(data.readall().decode('utf-8', 'ignore'))
        except AttributeError:
            d = json.loads(data.read().decode('utf-8', 'ignore'))
        try:
            for tmp in d['notices']:
                if (tmp['title'] == 'Rate Limit Notice'):
                    log.debug('RDAP query rate limit exceeded.')
                    if (retry_count > 0):
                        log.debug('Waiting {0} seconds...'.format(str(rate_limit_timeout)))
                        sleep(rate_limit_timeout)
                        return self.get_http_json(url=url, retry_count=(retry_count - 1), rate_limit_timeout=rate_limit_timeout, headers=headers)
                    else:
                        raise HTTPRateLimitError('HTTP lookup failed for {0}. Rate limit exceeded, wait and try again (possibly a temporary block).'.format(url))
        except (KeyError, IndexError):
            pass
        return d
    except HTTPError as e:
        if (e.code == 429):
            log.debug('HTTP query rate limit exceeded.')
            if (retry_count > 0):
                log.debug('Waiting {0} seconds...'.format(str(rate_limit_timeout)))
                sleep(rate_limit_timeout)
                return self.get_http_json(url=url, retry_count=(retry_count - 1), rate_limit_timeout=rate_limit_timeout, headers=headers)
            else:
                raise HTTPRateLimitError('HTTP lookup failed for {0}. Rate limit exceeded, wait and try again (possibly a temporary block).'.format(url))
        else:
            raise HTTPLookupError('HTTP lookup failed for {0} with error code {1}.'.format(url, str(e.code)))
    except (URLError, socket.timeout, socket.error) as e:
        log.debug('HTTP query socket error: {0}'.format(e))
        if (retry_count > 0):
            log.debug('HTTP query retrying (count: {0})'.format(str(retry_count)))
            return self.get_http_json(url=url, retry_count=(retry_count - 1), rate_limit_timeout=rate_limit_timeout, headers=headers)
        else:
            raise HTTPLookupError('HTTP lookup failed for {0}.'.format(url))
    except (HTTPLookupError, HTTPRateLimitError) as e:
        raise e
    except:
        raise HTTPLookupError('HTTP lookup failed for {0}.'.format(url))

The function for retrieving a json result via HTTP.

Args:
url (:obj:`str`): The URL to retrieve (required).
retry_count (:obj:`int`): The number of times to retry in case
socket errors, timeouts, connection resets, etc. are
encountered. Defaults to 3.
rate_limit_timeout (:obj:`int`): The number of seconds to wait
before retrying when a rate limit notice is returned via
rdap+json or HTTP error 429. Defaults to 60.
headers (:obj:`dict`): The HTTP headers. The Accept header
defaults to 'application/rdap+json'.

Returns:
dict: The data in json format.

Raises:
HTTPLookupError: The HTTP lookup failed.
HTTPRateLimitError: The HTTP request rate limited and retries
were exhausted.


def separable_conv2d(x, depthwise_kernel, pointwise_kernel, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1)):
    if data_format is None:
        data_format = image_data_format()
    if data_format not in {'channels_first', 'channels_last'}:
        raise ValueError('Unknown data_format: ' + str(data_format))
    if len(strides) != 2:
        raise ValueError('`strides` must be a tuple of 2 integers.')
    x, tf_data_format = _preprocess_conv2d_input(x, data_format)
    padding = _preprocess_padding(padding)
    if not isinstance(strides, tuple):
        strides = tuple(strides)
    if tf_data_format == 'NHWC':
        strides = (1,) + strides + (1,)
    else:
        strides = (1, 1) + strides
    x = nn.separable_conv2d(x, depthwise_kernel, pointwise_kernel, strides=strides, padding=padding, rate=dilation_rate, data_format=tf_data_format)
    if data_format == 'channels_first' and tf_data_format == 'NHWC':
        x = array_ops.transpose(x, (0, 3, 1, 2))
    return x

2D convolution with separable filters.

Args:
x: input tensor
depthwise_kernel: convolution kernel for the depthwise convolution.
pointwise_kernel: kernel for the 1x1 convolution.
strides: strides tuple (length 2).
padding: string, `"same"` or `"valid"`.
data_format: string, `"channels_last"` or `"channels_first"`.
dilation_rate: tuple of integers,
dilation rates for the separable convolution.

Returns:
Output tensor.

Raises:
ValueError: if `data_format` is neither `channels_last` or
`channels_first`.
ValueError: if `strides` is not a tuple of 2 integers.


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

        self._files = []
        self._prefixes = defaultdict(lambda: set(['']))
        self._extract = kwargs.get('extract', False)
        self._supersede = kwargs.get('supersede', False)
        self._match_version = kwargs.get('_match_version', True)
        self._local_warned = False

        for f in compressed_files:
            if isinstance(f, zipfile.ZipFile):
                bin_package = any(n.endswith('.so') or n.endswith('.pxd') or n.endswith('.dylib')
                                  for n in f.namelist())
                need_extract = True
            elif isinstance(f, tarfile.TarFile):
                bin_package = any(m.name.endswith('.so') or m.name.endswith('.pxd') or m.name.endswith('.dylib')
                                  for m in f.getmembers())
                need_extract = True
            elif isinstance(f, dict):
                bin_package = any(name.endswith('.so') or name.endswith('.pxd') or name.endswith('.dylib')
                                  for name in iterkeys(f))
                need_extract = False
            elif isinstance(f, list):
                bin_package = any(name.endswith('.so') or name.endswith('.pxd') or name.endswith('.dylib')
                                  for name in f)
                need_extract = False
            else:
                raise TypeError('Compressed file can only be zipfile.ZipFile or tarfile.TarFile')

            if bin_package:
                if not ALLOW_BINARY:
                    raise SystemError('Cannot load binary package. It is quite possible that you are using an old '
                                      'MaxCompute service which does not support binary packages. If this is '
                                      'not true, please set `odps.isolation.session.enable` to True or ask your '
                                      'project owner to change project-level configuration.')
                if need_extract:
                    f = self._extract_archive(f)

            prefixes = set([''])
            dir_prefixes = set()
            if isinstance(f, zipfile.ZipFile):
                for name in f.namelist():
                    name = name if name.endswith('/') else (name.rsplit('/', 1)[0] + '/')
                    if name in prefixes:
                        continue
                    try:
                        f.getinfo(name + '__init__.py')
                    except KeyError:
                        prefixes.add(name)
            elif isinstance(f, tarfile.TarFile):
                for member in f.getmembers():
                    name = member.name if member.isdir() else member.name.rsplit('/', 1)[0]
                    if name in prefixes:
                        continue
                    try:
                        f.getmember(name + '/__init__.py')
                    except KeyError:
                        prefixes.add(name + '/')
            elif isinstance(f, (list, dict)):

                if ALLOW_BINARY:
                    bin_package = True

                rendered_names = set()
                for name in f:
                    name = name.replace(os.sep, '/')
                    rendered_names.add(name)

                for name in rendered_names:
                    name = name if name.endswith('/') else (name.rsplit('/', 1)[0] + '/')
                    if name in prefixes or '/tests/' in name:
                        continue
                    if name + '__init__.py' not in rendered_names:
                        prefixes.add(name)
                        dir_prefixes.add(name)
                    else:
                        if '/' in name.rstrip('/'):
                            ppath = name.rstrip('/').rsplit('/', 1)[0]
                        else:
                            ppath = ''
                        prefixes.add(ppath)
                        dir_prefixes.add(ppath)

            if bin_package:
                path_patch = []
                for p in sorted(dir_prefixes):
                    if p in sys.path:
                        continue
                    parent_exist = False
                    for pp in path_patch:
                        if p[:len(pp)] == pp:
                            parent_exist = True
                            break
                    if parent_exist:
                        continue
                    path_patch.append(p)
                if self._supersede:
                    sys.path = path_patch + sys.path
                else:
                    sys.path = sys.path + path_patch
            else:
                self._files.append(f)
                if prefixes:
                    self._prefixes[id(f)] = sorted(prefixes)

Constructor.

Args:
compressed_files zipfile.ZipFile or tarfile.TarFile


def all_function(function: _evaluation.AllFunction, operand_result: Optional[_sql_data_types.IdentifierSelect], params_result: Collection[_sql_data_types.StandardSqlExpression]) -> _sql_data_types.Select:
    sql_alias = 'all_'
    sql_data_type = _sql_data_types.Boolean
    if not operand_result or not params_result:
        return _sql_data_types.Select(select_part=_sql_data_types.RawExpression('TRUE', _sql_alias=sql_alias, _sql_data_type=_sql_data_types.Boolean), from_part=None, sql_dialect=_sql_data_types.SqlDialect.SPARK)
    else:
        criteria = list(params_result)[0]
        context_sql = None
        where_part = None
        if _fhir_path_data_types.is_collection(function.parent_node.return_type):
            context_sql = operand_result.from_part
            where_part = operand_result.where_part
        else:
            context_sql = str(operand_result.to_subquery())
        criteria_sql = _sql_data_types.RawExpression(criteria.as_operand(), _sql_alias=sql_alias, _sql_data_type=sql_data_type).to_subquery()
        internal_if_null_call = _sql_data_types.FunctionCall('IFNULL', [criteria_sql, 'FALSE'], _sql_alias=sql_alias, _sql_data_type=sql_data_type)
        logical_and_call = _sql_data_types.FunctionCall('BOOL_AND', (internal_if_null_call,), _sql_alias=sql_alias, _sql_data_type=sql_data_type)
        return _sql_data_types.Select(select_part=_sql_data_types.FunctionCall('IFNULL', [logical_and_call, 'TRUE'], _sql_alias=sql_alias, _sql_data_type=sql_data_type), from_part=context_sql, where_part=where_part, sql_dialect=_sql_data_types.SqlDialect.SPARK)

Generates Spark SQL representing the FHIRPath all() function.

Returns true if criteria evaluates to true for every item in its operand.

This function takes one param (`criteria`) in addition to its operand. If
operand is not provided, it returns True.

Args:
function: The FHIRPath AST `AllFunction` node
operand_result: The expression which is being evaluated
params_result: The parameter passed in to function

Returns:
A compiled Spark SQL expression.


def __init__(self, settings, room_id, pause=1):

        Process.__init__(self)
        self._pause = pause
        self._room_id = room_id
        self._callback = None
        self._queue = None
        self._connection = Connection.create_from_settings(settings)
        self._last_message_id = None

Initialize.

Args:
settings (dict): Settings used to create a :class:`Connection` instance
room_id (int): Room ID

Kwargs:
pause (int): Pause in seconds between requests


def WriteBytes(self, value, unhex=True):

        if unhex:
            try:
                value = binascii.unhexlify(value)
            except binascii.Error:
                pass
        return self.stream.write(value)

Write a `bytes` type to the stream.

Args:
value (bytes): array of bytes to write to the stream.
unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb'

Returns:
int: the number of bytes written.


class _Validate(beam.PTransform):

    def __init__(self, schema: dict[str, Any], error_handling: Optional[Mapping[str, Any]]=None):
        self._schema = schema
        self._exception_handling_args = exception_handling_args(error_handling)

    @maybe_with_exception_handling
    def expand(self, pcoll):
        validator = json_utils.row_validator(schema_from_element_type(pcoll.element_type), self._schema)

        def invoke_validator(x):
            validator(x)
            return x
        return pcoll | beam.Map(invoke_validator)

    def with_exception_handling(self, **kwargs):
        self._exception_handling_args = kwargs
        return self

Validates each element of a PCollection against a json schema.

Args:
schema: A json schema against which to validate each element.
error_handling: Whether and how to handle errors during iteration.
If this is not set, invalid elements will fail the pipeline, otherwise
invalid elements will be passed to the specified error output along
with information about how the schema was invalidated.


def __init__(self, indent=True, relation_sort=original_order):

        self.indent = indent
        self.relation_sort = relation_sort

Initialize a new codec.

Args:
indent: if True, adaptively indent; if False or None, don't
indent; if a non-negative integer, indent that many
spaces per nesting level
relation_sort: when encoding, sort the relations on each
node according to this function; by default, the
original order is maintained


def get_cuda_version_all():
    key = 'cuda_ver_all'
    out, err = run_shell_cmd(cmds_all[PLATFORM.lower()][key])
    ret_val = out.split(b'\n')
    filtered = []
    for item in ret_val:
        if item not in ['\n', '']:
            filtered.append(item)
    all_vers = []
    for item in filtered:
        ver_re = re.search('.*/cuda(\\-[\\d]+\\.[\\d]+)?', item.decode('utf-8'))
        if ver_re.group(1):
            all_vers.append(ver_re.group(1).strip('-'))
    if err and FLAGS.debug:
        print('Error in detecting CUDA version:\n %s' % str(err))
    return all_vers

Retrieves all additional CUDA versions available (other than default).

For retrieving default CUDA version, use `get_cuda_version` function.

stderr is silenced by default. Setting FLAGS.debug mode will not enable it.
Remove `2> /dev/null` command from `cmds_linux['cuda_ver_dflt']` to enable
stderr.

Returns:
List of all CUDA versions found (except default version).
e.g. ['10.1', '10.2']


def disambiguate_query(self, query, language=None, entities=None):
    body = {'shortText': query, 'entities': [], 'onlyNER': 'false', 'customisation': 'generic'}
    if language:
        body['language'] = {'lang': language}
    if entities:
        body['entities'] = entities
    files = {'query': str(body)}
    logger.debug('About to submit the following query {}'.format(body))
    (res, status) = self.post(self.disambiguate_service, files=files, headers={'Accept': 'application/json'})
    if (status == 200):
        return (self.decode(res), status)
    else:
        logger.debug('Disambiguation failed.')
        return (None, status)

Call the disambiguation service in order to disambiguate a search query.

Args:
text (str): Query to be disambiguated.
language (str): language of text (if known)
entities (list): list of entities or mentions to be supplied by
the user.

Returns:
dict, int: API response and API status.


def set_mlag_id(self, name, value=None, default=False, disable=False):
    cmd = self.command_builder('mlag', value=value, default=default, disable=disable)
    return self.configure_interface(name, cmd)

Configures the interface mlag value for the specified interface

Args:
name (str): The interface to configure.  Valid values for the
name arg include Port-Channel*
value (str): The mlag identifier to cofigure on the interface
default (bool): Configures the interface mlag value using the
default keyword
disable (bool): Negates the interface mlag value using the
no keyword

Returns:
bool: Returns True if the commands complete successfully


def sort_segment_points(Aps, Bps):

    mid = []
    j = 0
    mid.append(Aps[0])
    for i in range(len(Aps)-1):
        dist = distance_tt_point(Aps[i], Aps[i+1])
        for m in range(j, len(Bps)):
            distm = distance_tt_point(Aps[i], Bps[m])
            if dist > distm:
                direction = dot(normalize(line(Aps[i].gen2arr(), Aps[i+1].gen2arr())), normalize(Bps[m].gen2arr()))
                if direction > 0:
                    j = m + 1
                    mid.append(Bps[m])
                    break

        mid.append(Aps[i+1])
    for m in range(j, len(Bps)):
        mid.append(Bps[m])
    return mid

Takes two line segments and sorts all their points,
so that they form a continuous path

Args:
Aps: Array of tracktotrip.Point
Bps: Array of tracktotrip.Point
Returns:
Array with points ordered


def __getitem__(self, key):
    if key is None:
        key = self._key()
    value = self._get_recursive(key)
    if value is None:
        value = self[key] = self.default_factory()
    return value

Gets the value at key (or current context), or sets default value.

Args:
key: May be `None` or `Graph`object. When `None`, the key is set to the
current context.

Returns:
Either the cached or default value.


def delete_folder(self, folder_id, recursive=True):
    return self.__request('DELETE', ('folders/%s' % (folder_id,)), querystring={'recursive': unicode(recursive).lower()})

Delete an existing folder

Args:
folder_id (int): ID of the folder to delete.
recursive (bool): Delete all subfolder if True.

Returns:
dict. Response from Box.

Raises:
BoxError: An error response is returned from Box (status_code >= 400).

BoxHttpResponseError: Response from Box is malformed.

requests.exceptions.*: Any connection related problem.


def create(self, name, network):

        if not network in SUPPORTED_NETWORKS:
            raise ValueError('Network not valid!')
        account = self.wrap(self.resource.create(dict(name=name,
                                                      network=network)))
        self.add(account)
        return account

Create a new Account object and add it to this Accounts collection.

Args:
name (str): Account name
network (str): Type of cryptocurrency.  Can be one of, 'bitcoin', '
bitcoin_testnet', 'litecoin', 'dogecoin'.

Returns: The new round.Account


def recipe_email_to_bigquery(config, auth_read, email_from, email_to, subject, link, attachment, dataset, table, schema, header, is_incremental_load):
    email(config, {'auth': auth_read, 'read': {'from': email_from, 'to': email_to, 'subject': subject, 'link': link, 'attachment': attachment}, 'write': {'bigquery': {'dataset': dataset, 'table': table, 'schema': schema, 'header': header, 'is_incremental_load': is_incremental_load}}})

Import emailed CM report, Dv360 report, csv, or excel into a BigQuery table.

Args:
auth_read (authentication) - Credentials used for reading data.
email_from (string) - Must match from field.
email_to (string) - Must match to field.
subject (string) - Regular expression to match subject.
link (string) - Regular expression to match email.
attachment (string) - Regular expression to match atttachment.
dataset (string) - Existing dataset in BigQuery.
table (string) - Name of table to be written to.
schema (json) - Schema provided in JSON list format or empty list.
header (boolean) - Does the csv contain a header row.
is_incremental_load (boolean) - Append report data to table based on date column, de-duplicates.


def bessel_j0(x, name=None):
    with ops.name_scope(name, 'bessel_j0', [x]):
        return gen_special_math_ops.bessel_j0(x)

Computes the Bessel j0 function of `x` element-wise.

Modified Bessel function of order 0.

>>> tf.math.special.bessel_j0([0.5, 1., 2., 4.]).numpy()
array([ 0.93846981,  0.76519769,  0.22389078, -0.39714981], dtype=float32)

Args:
x: A `Tensor` or `SparseTensor`. Must be one of the following types: `half`,
`float32`, `float64`.
name: A name for the operation (optional).

Returns:
A `Tensor` or `SparseTensor`, respectively. Has the same type as `x`.

@compatibility(scipy)
Equivalent to scipy.special.j0
@end_compatibility


def __auth_descriptor(self, api_info):

    if api_info.auth is None:
      return None

    auth_descriptor = {}
    if api_info.auth.allow_cookie_auth is not None:
      auth_descriptor['allowCookieAuth'] = api_info.auth.allow_cookie_auth
    if api_info.auth.blocked_regions:
      auth_descriptor['blockedRegions'] = api_info.auth.blocked_regions

    return auth_descriptor

Builds an auth descriptor from API info.

Args:
api_info: An _ApiInfo object.

Returns:
A dictionary with 'allowCookieAuth' and/or 'blockedRegions' keys.


def parse(self, ping_message):

        try:

            if typepy.is_not_null_string(ping_message.stdout):
                ping_message = ping_message.stdout
        except AttributeError:
            pass

        logger.debug("parsing ping result: {}".format(ping_message))

        self.__parser = NullPingParser()

        if typepy.is_null_string(ping_message):
            logger.debug("ping_message is empty")
            self.__stats = PingStats()

            return self.__stats

        ping_lines = _to_unicode(ping_message).splitlines()
        parser_class_list = (
            LinuxPingParser,
            WindowsPingParser,
            MacOsPingParser,
            AlpineLinuxPingParser,
        )

        for parser_class in parser_class_list:
            self.__parser = parser_class()
            try:
                self.__stats = self.__parser.parse(ping_lines)
                return self.__stats
            except ParseError as e:
                if e.reason != ParseErrorReason.HEADER_NOT_FOUND:
                    raise e
            except pp.ParseException:
                pass

        self.__parser = NullPingParser()

        return self.__stats

Parse ping command output.

Args:
ping_message (str or :py:class:`~pingparsing.PingResult`):
``ping`` command output.

Returns:
:py:class:`~pingparsing.PingStats`: Parsed result.


def getSlicesForText(self, retina_name, body, get_fingerprint=None, start_index=0, max_results=10):

        resourcePath = '/text/slices'
        method = 'POST'

        queryParams = {}
        headerParams = {'Accept': 'Application/json', 'Content-Type': 'application/json'}
        postData = None

        queryParams['retina_name'] = retina_name
        queryParams['start_index'] = start_index
        queryParams['max_results'] = max_results
        queryParams['get_fingerprint'] = get_fingerprint
        postData = body
        response = self.apiClient._callAPI(resourcePath, method, queryParams, postData, headerParams)
        return [text.Text(**r) for r in response.json()]

Get a list of slices of the text
Args:
retina_name, str: The retina name (required)
body, str: The text to be evaluated (required)
get_fingerprint, bool: Configure if the fingerprint should be returned as part of the results (optional)
start_index, int: The start-index for pagination (optional) (optional)
max_results, int: Max results per page (optional) (optional)
Returns: Array[Text]


def get_policy(observations, hparams, action_space):

  if not isinstance(action_space, gym.spaces.Discrete):
    raise ValueError("Expecting discrete action space.")

  obs_shape = common_layers.shape_list(observations)
  (frame_height, frame_width) = obs_shape[2:4]

  if hparams.policy_problem_name == "dummy_policy_problem_ttt":
    tf.logging.info("Using DummyPolicyProblemTTT for the policy.")
    policy_problem = tic_tac_toe_env.DummyPolicyProblemTTT()
  else:
    tf.logging.info("Using DummyPolicyProblem for the policy.")
    policy_problem = DummyPolicyProblem(action_space, frame_height, frame_width)

  trainer_lib.add_problem_hparams(hparams, policy_problem)
  hparams.force_full_predict = True
  model = registry.model(hparams.policy_network)(
      hparams, tf.estimator.ModeKeys.TRAIN
  )
  try:
    num_target_frames = hparams.video_num_target_frames
  except AttributeError:
    num_target_frames = 1
  features = {
      "inputs": observations,
      "input_action": tf.zeros(obs_shape[:2] + [1], dtype=tf.int32),
      "input_reward": tf.zeros(obs_shape[:2] + [1], dtype=tf.int32),
      "targets": tf.zeros(obs_shape[:1] + [num_target_frames] + obs_shape[2:]),
      "target_action": tf.zeros(
          obs_shape[:1] + [num_target_frames, 1], dtype=tf.int32),
      "target_reward": tf.zeros(
          obs_shape[:1] + [num_target_frames, 1], dtype=tf.int32),
      "target_policy": tf.zeros(
          obs_shape[:1] + [num_target_frames] + [action_space.n]),
      "target_value": tf.zeros(
          obs_shape[:1] + [num_target_frames])
  }
  with tf.variable_scope(tf.get_variable_scope(), reuse=tf.AUTO_REUSE):
    t2t_model.create_dummy_vars()
    (targets, _) = model(features)
  return (targets["target_policy"][:, 0, :], targets["target_value"][:, 0])

Get a policy network.

Args:
observations: observations
hparams: parameters
action_space: action space

Returns:
Tuple (action logits, value).


def dumps(o, preserve=False):

    retval = ""
    addtoretval, sections = _dump_sections(o, "")
    retval += addtoretval
    while sections != {}:
        newsections = {}
        for section in sections:
            addtoretval, addtosections = _dump_sections(sections[section],
                                                        section, preserve)
            if addtoretval or (not addtoretval and not addtosections):
                if retval and retval[-2:] != "\n\n":
                    retval += "\n"
                retval += "[" + section + "]\n"
                if addtoretval:
                    retval += addtoretval
            for s in addtosections:
                newsections[section + "." + s] = addtosections[s]
        sections = newsections
    return retval

Stringifies input dict as toml

Args:
o: Object to dump into toml

preserve: Boolean parameter. If true, preserve inline tables.

Returns:
String containing the toml corresponding to dict


def run(self, data_loaders, workflow, max_epochs, **kwargs):
    assert isinstance(data_loaders, list)
    assert mmcv.is_list_of(workflow, tuple)
    assert (len(data_loaders) == len(workflow))
    self._max_epochs = max_epochs
    work_dir = (self.work_dir if (self.work_dir is not None) else 'NONE')
    self.logger.info('Start running, host: %s, work_dir: %s', get_host_info(), work_dir)
    self.logger.info('workflow: %s, max: %d epochs', workflow, max_epochs)
    self.call_hook('before_run')
    while (self.epoch < max_epochs):
        for (i, flow) in enumerate(workflow):
            (mode, epochs) = flow
            if isinstance(mode, str):
                if (not hasattr(self, mode)):
                    raise ValueError('runner has no method named "{}" to run an epoch'.format(mode))
                epoch_runner = getattr(self, mode)
            elif callable(mode):
                epoch_runner = mode
            else:
                raise TypeError('mode in workflow must be a str or callable function, not {}'.format(type(mode)))
            for _ in range(epochs):
                if ((mode == 'train') and (self.epoch >= max_epochs)):
                    return
                epoch_runner(data_loaders[i], **kwargs)
    time.sleep(1)
    self.call_hook('after_run')

Start running.

Args:
data_loaders (list[:obj:`DataLoader`]): Dataloaders for training
and validation.
workflow (list[tuple]): A list of (phase, epochs) to specify the
running order and epochs. E.g, [('train', 2), ('val', 1)] means
running 2 epochs for training and 1 epoch for validation,
iteratively.
max_epochs (int): Total training epochs.


def FromFile(cls, inpath):

        with open(inpath, "r") as infile:
            indata = infile.read()

        return cls.FromString(indata)

Load a CommandFile from a path.

Args:
inpath (str): The path to the file to load

Returns:
CommandFile: The decoded CommandFile object.


class PatchTSMixerForPretraining(PatchTSMixerPreTrainedModel):

    def __init__(self, config: PatchTSMixerConfig):
        super().__init__(config)
        self.model = PatchTSMixerModel(config, mask_input=True)
        self.head = PatchTSMixerPretrainHead(config=config)
        self.masked_loss = config.masked_loss
        self.use_return_dict = config.use_return_dict
        if config.post_init:
            self.post_init()

    @auto_docstring
    def forward(self, past_values: torch.Tensor, observed_mask: Optional[torch.Tensor]=None, output_hidden_states: Optional[bool]=False, return_loss: bool=True, return_dict: Optional[bool]=None) -> PatchTSMixerForPreTrainingOutput:

        return_dict = return_dict if return_dict is not None else self.use_return_dict
        if self.masked_loss is True:
            loss = torch.nn.MSELoss(reduction='none')
        else:
            loss = torch.nn.MSELoss(reduction='mean')
        model_output = self.model(past_values, observed_mask=observed_mask, output_hidden_states=output_hidden_states, return_dict=return_dict)
        if isinstance(model_output, tuple):
            model_output = PatchTSMixerModelOutput(*model_output)
        x_hat = self.head(model_output.last_hidden_state)
        if return_loss is True:
            loss_val = loss(x_hat, model_output.patch_input)
        else:
            loss_val = None
        if self.masked_loss is True and loss_val is not None:
            loss_val = (loss_val.mean(dim=-1) * model_output.mask).sum() / (model_output.mask.sum() + 1e-10)
        if not return_dict:
            return tuple((v for v in [loss_val, x_hat, model_output.last_hidden_state, model_output.hidden_states]))
        return PatchTSMixerForPreTrainingOutput(loss=loss_val, prediction_outputs=x_hat, last_hidden_state=model_output.last_hidden_state, hidden_states=model_output.hidden_states)

`PatchTSMixer` for mask pretraining.

Args:
config (`PatchTSMixerConfig`):
Configuration.

Returns:
`None`.


def ExportNEP2(self, passphrase):
    if (len(passphrase) < 2):
        raise ValueError('Passphrase must have a minimum of 2 characters')
    address_hash_tmp = hashlib.sha256(self.GetAddress().encode('utf-8')).digest()
    address_hash_tmp2 = hashlib.sha256(address_hash_tmp).digest()
    address_hash = address_hash_tmp2[:4]
    pwd_normalized = bytes(unicodedata.normalize('NFC', passphrase), 'utf-8')
    derived = scrypt.hash(pwd_normalized, address_hash, N=SCRYPT_ITERATIONS, r=SCRYPT_BLOCKSIZE, p=SCRYPT_PARALLEL_FACTOR, buflen=SCRYPT_KEY_LEN_BYTES)
    derived1 = derived[:32]
    derived2 = derived[32:]
    xor_ed = xor_bytes(bytes(self.PrivateKey), derived1)
    cipher = AES.new(derived2, AES.MODE_ECB)
    encrypted = cipher.encrypt(xor_ed)
    assembled = bytearray()
    assembled.extend(NEP_HEADER)
    assembled.extend(NEP_FLAG)
    assembled.extend(address_hash)
    assembled.extend(encrypted)
    encrypted_key_nep2 = base58.b58encode_check(bytes(assembled))
    return encrypted_key_nep2.decode('utf-8')

Export the encrypted private key in NEP-2 format.

Args:
passphrase (str): The password to encrypt the private key with, as unicode string

Returns:
str: The NEP-2 encrypted private key


def open(self, **params):

        logger.info('opening telnet')
        self.port = params['port']
        self.ip = params['ip']
        self.tn = None
        self._init()

Open telnet connection

Args:
params (dict), must contain two parameters "ip" - ip address or hostname and "port" - port number

Example:
params = {'port': 23, 'ip': 'localhost'}


def __init__(self, channel):

        self.StreamingAnnotateVideo = channel.stream_stream(
            "/google.cloud.videointelligence.v1p3beta1.StreamingVideoIntelligenceService/StreamingAnnotateVideo",
            request_serializer=google_dot_cloud_dot_videointelligence__v1p3beta1_dot_proto_dot_video__intelligence__pb2.StreamingAnnotateVideoRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_videointelligence__v1p3beta1_dot_proto_dot_video__intelligence__pb2.StreamingAnnotateVideoResponse.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def get_site_dos(self, site):

        site_dos = functools.reduce(add_densities, self.pdos[site].values())
        return Dos(self.efermi, self.energies, site_dos)

Get the total Dos for a site (all orbitals).

Args:
site: Site in Structure associated with CompleteDos.

Returns:
Dos containing summed orbital densities for site.


def _serialize_normalized_array(array, fmt='png', quality=70):
    dtype = array.dtype
    assert np.issubdtype(dtype, np.unsignedinteger)
    assert (np.max(array) <= np.iinfo(dtype).max)
    assert (array.shape[(- 1)] > 1)
    image = PIL.Image.fromarray(array)
    image_bytes = BytesIO()
    image.save(image_bytes, fmt, quality=quality)
    image_data = image_bytes.getvalue()
    return image_data

Given a normalized array, returns byte representation of image encoding.

Args:
array: NumPy array of dtype uint8 and range 0 to 255
fmt: string describing desired file format, defaults to 'png'
quality: specifies compression quality from 0 to 100 for lossy formats

Returns:
image data as BytesIO buffer


def _Load(dec: '_Dec[_DecT]', filename: Path, compress: bool=False, open_function=open) -> _DecT:
    try:
        with open_function(filename, 'rb') as fi:
            if compress:
                with gzip.GzipFile(fileobj=fi) as zfi:
                    data = zfi.read()
            else:
                data = fi.read()
        return dec.decode(data)
    except (OSError, gzip.BadGzipFile, msgspec.DecodeError, msgspec.ValidationError) as e:
        raise LoadPickleError(filename) from e

Loads a serialized file.

Args:
dec: The msgspec.Decoder to use.
filename: The file to read.
compress: if True, the file will be opened using gzip.
open_function: The function to open the file with.

Returns:
The decoded object.

Raises:
LoadPickleError, if there is an OSError, gzip error, or msgspec error.


def __setattr__(self, key, value):

        if key in self.__dict__ or '_' + key in self.__dict__:
            object.__setattr__(self, key, value)
        else:
            self.set(key, value)

A shortcut for the 'set' method.

Args:
key (str): The name of the attribute to set.
value (str): The value to assign to 'key'.


def mangle_scope_tree(root, toplevel):

    def mangle(scope):

        if scope.get_enclosing_scope() is None and not toplevel:
            return
        for name in scope.symbols:
            mangled_name = scope.get_next_mangled_name()
            scope.mangled[name] = mangled_name
            scope.rev_mangled[mangled_name] = name

    def visit(node):
        mangle(node)
        for child in node.children:
            visit(child)

    visit(root)

Walk over a scope tree and mangle symbol names.

Args:
toplevel: Defines if global scope should be mangled or not.


def f2format(filename):

    print('Now converting %r...' % filename)

    encoding = os.getenv('F2FORMAT_ENCODING', LOCALE_ENCODING)

    lineno = dict()
    content = list()
    with open(filename, 'r', encoding=encoding) as file:
        lineno[1] = 0
        for lnum, line in enumerate(file, start=1):
            content.append(line)
            lineno[lnum+1] = lineno[lnum] + len(line)

    string = ''.join(content)
    text = convert(string, lineno)

    with open(filename, 'w', encoding=encoding) as file:
        file.write(text)

Wrapper works for conversion.

Args:
- filename -- str, file to be converted


def matches_filters(self, node):

        visible = self.visible

        if self.options["text"]:
            if isregex(self.options["text"]):
                regex = self.options["text"]
            elif self.exact_text is True:
                regex = re.compile(r"\A{}\Z".format(re.escape(self.options["text"])))
            else:
                regex = toregex(self.options["text"])

            text = normalize_text(
                node.all_text if visible == "all" else node.visible_text)

            if not regex.search(text):
                return False

        if isinstance(self.exact_text, (bytes_, str_)):
            regex = re.compile(r"\A{}\Z".format(re.escape(self.exact_text)))

            text = normalize_text(
                node.all_text if visible == "all" else node.visible_text)

            if not regex.search(text):
                return False

        if visible == "visible":
            if not node.visible:
                return False
        elif visible == "hidden":
            if node.visible:
                return False

        for name, node_filter in iter(self._node_filters.items()):
            if name in self.filter_options:
                if not node_filter.matches(node, self.filter_options[name]):
                    return False
            elif node_filter.has_default:
                if not node_filter.matches(node, node_filter.default):
                    return False

        if self.options["filter"] and not self.options["filter"](node):
            return False

        return True

Returns whether the given node matches all filters.

Args:
node (Element): The node to evaluate.

Returns:
bool: Whether the given node matches.


def find_clusters(struct, connected_matrix):
    n_atoms = len(struct.species)
    if (n_atoms == 0):
        return [0, 0, 0]
    if (0 in np.sum(connected_matrix, axis=0)):
        return [0, 1, 0]
    cluster_sizes = []
    clusters = []
    visited = [False for item in range(n_atoms)]
    connected_matrix += np.eye(len(connected_matrix))

    def visit(atom, atom_cluster):
        visited[atom] = True
        new_cluster = set(np.where((connected_matrix[atom] != 0))[0]).union(atom_cluster)
        atom_cluster = new_cluster
        for new_atom in atom_cluster:
            if (not visited[new_atom]):
                visited[new_atom] = True
                atom_cluster = visit(new_atom, atom_cluster)
        return atom_cluster
    for i in range(n_atoms):
        if (not visited[i]):
            atom_cluster = set()
            cluster = visit(i, atom_cluster)
            clusters.append(cluster)
            cluster_sizes.append(len(cluster))
    max_cluster = max(cluster_sizes)
    min_cluster = min(cluster_sizes)
    return [max_cluster, min_cluster, clusters]

Finds bonded clusters of atoms in the structure with periodic boundary
conditions.

If there are atoms that are not bonded to anything, returns [0,1,0]. (For
faster computation time)

Author: "Gowoon Cheon"
Email: "gcheon@stanford.edu"

Args:
struct (Structure): Input structure
connected_matrix: Must be made from the same structure with
find_connected_atoms() function.

Returns:
max_cluster: the size of the largest cluster in the crystal structure
min_cluster: the size of the smallest cluster in the crystal structure
clusters: list of bonded clusters found here, clusters are formatted as
sets of indices of atoms


def parse_qcmetrics(metrics: dict) -> dict:

    data = {
        'versions': {
            'freebayes': metrics['program']['freebayes']['version'],
            'gatk': metrics['program']['gatk']['version'],
            'manta': metrics['program'].get('manta', {}).get('version'),
            'bcftools': metrics['program']['bcftools']['version'],
            'vep': metrics['program']['varianteffectpredictor']['version'],
        },
        'samples': [],
    }

    plink_samples = {}
    plink_sexcheck = metrics['program'].get('plink_sexcheck', {}).get('sample_sexcheck')
    if isinstance(plink_sexcheck, str):
        sample_id, sex_number = plink_sexcheck.strip().split(':', 1)
        plink_samples[sample_id] = PED_SEX_MAP.get(int(sex_number))
    elif isinstance(plink_sexcheck, list):
        for sample_raw in plink_sexcheck:
            sample_id, sex_number = sample_raw.split(':', 1)
            plink_samples[sample_id] = PED_SEX_MAP.get(int(sex_number))

    for sample_id, sample_metrics in metrics['sample'].items():

        bam_stats = [values['bamstats'] for key, values in sample_metrics.items()
                     if key[:-1].endswith('.lane')]
        total_reads = sum(int(bam_stat['raw_total_sequences']) for bam_stat in bam_stats)
        total_mapped = sum(int(bam_stat['reads_mapped']) for bam_stat in bam_stats)

        main_key = [key for key in sample_metrics.keys() if '_lanes_' in key][0]

        hs_metrics = sample_metrics[main_key]['collecthsmetrics']['header']['data']
        multiple_inst_metrics = sample_metrics[main_key]['collectmultiplemetricsinsertsize']['header']['data']
        multiple_metrics = sample_metrics[main_key]['collectmultiplemetrics']['header']['pair']

        sample_data = {
            'at_dropout': hs_metrics['AT_DROPOUT'],
            'completeness_target': {
                10: hs_metrics['PCT_TARGET_BASES_10X'],
                20: hs_metrics['PCT_TARGET_BASES_20X'],
                50: hs_metrics['PCT_TARGET_BASES_50X'],
                100: hs_metrics['PCT_TARGET_BASES_100X'],
            },
            'duplicates': float(sample_metrics[main_key]['markduplicates']['fraction_duplicates']),
            'gc_dropout': hs_metrics['GC_DROPOUT'],
            'id': sample_id,
            'median_insert_size':  multiple_inst_metrics['MEDIAN_INSERT_SIZE'],
            'mapped': total_mapped / total_reads,
            'plink_sex': plink_samples.get(sample_id),
            'predicted_sex': sample_metrics[main_key]['chanjo_sexcheck']['gender'],
            'reads': total_reads,
            'insert_size_standard_deviation': float(multiple_inst_metrics['STANDARD_DEVIATION']),
            'strand_balance': float(multiple_metrics['STRAND_BALANCE']),
            'target_coverage': float(hs_metrics['MEAN_TARGET_COVERAGE']),
        }
        data['samples'].append(sample_data)
    return data

Parse MIP qc metrics file.
Args:
metrics (dict): raw YAML input from MIP qc metrics file

Returns:
dict: parsed data


def _ParsePathSpecification(self, knowledge_base, searcher, file_system, path_specification, path_separator):
    try:
        file_entry = searcher.GetFileEntryByPathSpec(path_specification)
    except IOError as exception:
        relative_path = searcher.GetRelativePath(path_specification)
        if (path_separator != file_system.PATH_SEPARATOR):
            relative_path_segments = file_system.SplitPath(relative_path)
            relative_path = '{0:s}{1:s}'.format(path_separator, path_separator.join(relative_path_segments))
        raise errors.PreProcessFail('Unable to retrieve file entry: {0:s} with error: {1!s}'.format(relative_path, exception))
    if file_entry:
        self._ParseFileEntry(knowledge_base, file_entry)

Parses a file system for a preprocessing attribute.

Args:
knowledge_base (KnowledgeBase): to fill with preprocessing information.
searcher (dfvfs.FileSystemSearcher): file system searcher to preprocess
the file system.
file_system (dfvfs.FileSystem): file system to be preprocessed.
path_specification (dfvfs.PathSpec): path specification that contains
the artifact value data.
path_separator (str): path segment separator.

Raises:
PreProcessFail: if the preprocessing fails.


def remove_bucket_list_item(self, id, collection, item):

        if type(id) is not ObjectId:
            id = ObjectId(id)
        obj = getattr(self.db, collection)
        result = obj.update(
            {'_id': id},
            {'$pull': {'bucket_list': item}}
        )
        return result

Removes an item from the bucket list

Args:
id: the CRITs object id of the TLO
collection: The db collection. See main class documentation.
item: the bucket list item to remove
Returns:
The mongodb result


def _GetFileSystemCacheIdentifier(self, path_spec):
    string_parts = []
    string_parts.append(getattr(path_spec.parent, 'comparable', ''))
    string_parts.append('type: {0:s}'.format(path_spec.type_indicator))
    return ''.join(string_parts)

Determines the file system cache identifier for the path specification.

Args:
path_spec (PathSpec): path specification.

Returns:
str: identifier of the VFS object.


def regularize_cost_from_collection(name='regularize_cost'):

    ctx = get_current_tower_context()
    if not ctx.is_training:

        return tf.constant(0, dtype=tf.float32, name='empty_' + name)

    if ctx.has_own_variables:
        losses = ctx.get_collection_in_tower(tfv1.GraphKeys.REGULARIZATION_LOSSES)
    else:
        losses = tfv1.get_collection(tfv1.GraphKeys.REGULARIZATION_LOSSES)
    if len(losses) > 0:
        logger.info("regularize_cost_from_collection() found {} regularizers "
                    "in REGULARIZATION_LOSSES collection.".format(len(losses)))

        def maploss(l):
            assert l.dtype.is_floating, l
            if l.dtype != tf.float32:
                l = tf.cast(l, tf.float32)
            return l

        losses = [maploss(l) for l in losses]
        reg_loss = tf.add_n(losses, name=name)
        return reg_loss
    else:
        return tf.constant(0, dtype=tf.float32, name='empty_' + name)

Get the cost from the regularizers in ``tf.GraphKeys.REGULARIZATION_LOSSES``.
If in replicated mode, will only regularize variables created within the current tower.

Args:
name (str): the name of the returned tensor

Returns:
tf.Tensor: a scalar, the total regularization cost.


def _BuildMessageFromTypeName(type_name, descriptor_pool):
    from google.protobuf import symbol_database
    database = symbol_database.Default()
    try:
        message_descriptor = descriptor_pool.FindMessageTypeByName(type_name)
    except KeyError:
        return None
    message_type = database.GetPrototype(message_descriptor)
    return message_type()

Returns a protobuf message instance.

Args:
type_name: Fully-qualified protobuf  message type name string.
descriptor_pool: DescriptorPool instance.

Returns:
A Message instance of type matching type_name, or None if the a Descriptor
wasn't found matching type_name.


def _select_mgmt_networks(self, conf):

        nets = conf['nets']
        mgmts = sorted(
            [
                name for name, net in nets.iteritems()
                if net.get('management') is True
            ]
        )

        if len(mgmts) == 0:
            mgmt_name = sorted((nets.keys()))[0]
            LOGGER.debug(
                'No management network configured, selecting network %s',
                mgmt_name
            )
            nets[mgmt_name]['management'] = True
            mgmts.append(mgmt_name)

        for mgmt_name in mgmts:
            if nets[mgmt_name].get('dns_domain_name', None) is None:
                nets[mgmt_name]['dns_domain_name'] = 'lago.local'

        return mgmts

Select management networks. If no management network is found, it will
mark the first network found by sorted the network lists. Also adding
default DNS domain, if none is set.

Args:
conf(spec): spec