def expression(value):

        if isinstance(value, Expression):

            return Expression(value._type, value._value)
        if hasattr(value, 'spl_json'):
            sj = value.spl_json()
            return Expression(sj['type'], sj['value'])
        return Expression('splexpr', value)

Create an SPL expression.

Args:
value: Expression as a string or another `Expression`. If value is an instance of `Expression` then a new instance is returned containing the same type and value.

Returns:
Expression: SPL expression from `value`.


def getColorHSV(name):
    try:
        x = getColorInfoList()[getColorList().index(name.upper())]
    except:
        return ((- 1), (- 1), (- 1))
    r = (x[1] / 255.0)
    g = (x[2] / 255.0)
    b = (x[3] / 255.0)
    cmax = max(r, g, b)
    V = round((cmax * 100), 1)
    cmin = min(r, g, b)
    delta = (cmax - cmin)
    if (delta == 0):
        hue = 0
    elif (cmax == r):
        hue = (60.0 * (((g - b) / delta) % 6))
    elif (cmax == g):
        hue = (60.0 * (((b - r) / delta) + 2))
    else:
        hue = (60.0 * (((r - g) / delta) + 4))
    H = int(round(hue))
    if (cmax == 0):
        sat = 0
    else:
        sat = (delta / cmax)
    S = int(round((sat * 100)))
    return (H, S, V)

Retrieve the hue, saturation, value triple of a color name.

Returns:
a triple (degree, percent, percent). If not found (-1, -1, -1) is returned.


def to_lasio(self, keys=None, basis=None):
    l = lasio.LASFile()
    l.well.DATE = str(datetime.datetime.today())
    for (obj, dic) in LAS_FIELDS.items():
        if (obj == 'data'):
            continue
        for (attr, (sect, item)) in dic.items():
            value = getattr(getattr(self, obj), attr, None)
            try:
                getattr(l, sect)[item].value = value
            except:
                h = lasio.HeaderItem(item, '', value, '')
                getattr(l, sect)[item] = h
    l.header['Curves'] = []
    if (basis is None):
        basis = self.survey_basis(keys=keys)
    try:
        l.add_curve('DEPT', basis)
    except:
        raise Exception('Please provide a depth basis.')
    setattr(l.well, 'STRT', basis[0])
    setattr(l.well, 'STOP', basis[(- 1)])
    setattr(l.well, 'STEP', (basis[1] - basis[0]))
    other = ''
    if (keys is None):
        keys = [k for (k, v) in self.data.items() if isinstance(v, Curve)]
    else:
        keys = utils.flatten_list(keys)
    for k in keys:
        d = self.data[k]
        if (getattr(d, 'null', None) is not None):
            d[np.isnan(d)] = d.null
        try:
            new_data = np.copy(d.to_basis_like(basis))
        except:
            pass
        try:
            descr = getattr(d, 'description', '')
            l.add_curve(k.upper(), new_data, unit=d.units, descr=descr)
        except:
            try:
                other += ('{}\n'.format(k.upper()) + d.to_csv())
            except:
                pass
    if other:
        l.other = other
    return l

Makes a lasio object from the current well.

Args:
basis (ndarray): Optional. The basis to export the curves in. If
you don't specify one, it will survey all the curves with
``survey_basis()``.
keys (list): List of strings: the keys of the data items to
include, if not all of them. You can have nested lists, such
as you might use for ``tracks`` in ``well.plot()``.

Returns:
lasio. The lasio object.


def save(self, file_prefix: tensor_lib.Tensor, options: 'checkpoint_options.CheckpointOptions | None'=None) -> ops.Operation:
    options = options or checkpoint_options.CheckpointOptions()
    with ops.device('CPU'):
        sharded_suffix = array_ops.where(string_ops.regex_full_match(file_prefix, '^s3:
        tmp_checkpoint_prefix = string_ops.string_join([file_prefix, sharded_suffix])
        registered_paths = {saver_name: registered_saver_filename(file_prefix, saver_name) for saver_name in self._registered_savers}

    def save_fn() -> ops.Operation:
        saved_prefixes = []
        for saver_name, (save_fn, _) in self._registered_savers.items():
            maybe_saved_prefixes = save_fn(registered_paths[saver_name])
            if maybe_saved_prefixes is not None:
                flattened_saved_prefixes = nest.flatten(maybe_saved_prefixes)
                if not all((tensor_util.is_tf_type(x) and x.dtype == dtypes.string for x in flattened_saved_prefixes)):
                    raise ValueError(f'Registered saver must return a (maybe empty) list of string type tensors. Got {maybe_saved_prefixes}.')
                saved_prefixes.extend(flattened_saved_prefixes)
        shards_by_task = self._get_shards_by_task(options.experimental_sharding_callback)
        num_shards = sum([len(shards) for _, shards in shards_by_task])
        metrics.AddNumCheckpointShardsWritten(num_shards=num_shards)
        num_shards_tensor = constant_op.constant(num_shards, name='num_shards')
        sharded_saves = []
        shard_idx = 0
        for task, shards in shards_by_task:
            for shard in shards:
                with ops.device(task):
                    shard_prefix = sharded_filename(tmp_checkpoint_prefix, shard_idx, num_shards_tensor)
                    shard_idx += 1
                saved_prefixes.append(shard_prefix)
                sharded_saves.append(_single_shard_save(shard_prefix, shard, task, options))
        with ops.control_dependencies(sharded_saves):
            tensor_device_spec = list(self._shardable_tensors_by_task.keys())[-1]
            merge_device_spec = options.experimental_io_device or saveable_object_util.set_cpu0(tensor_device_spec.to_string())
            with ops.device(merge_device_spec):
                return gen_io_ops.merge_v2_checkpoints(saved_prefixes, file_prefix, delete_old_dirs=True)
    if context.executing_eagerly() and self._num_unique_tasks > 1:

        @def_function.function(jit_compile=False)
        def tf_function_save() -> None:
            save_fn()
        tf_function_save()
    else:
        return save_fn()

Save the saveable objects to a checkpoint with `file_prefix`.

Args:
file_prefix: A string or scalar string Tensor containing the prefix to
save under.
options: Optional `CheckpointOptions` object.
Returns:
An `Operation`, or None when executing eagerly.


def get_image_features(self, pixel_values: torch.FloatTensor, image_sizes: torch.Tensor, vision_feature_layer: Optional[Union[int, List[int]]]=None, vision_feature_select_strategy: Optional[str]=None):
    vision_feature_layer = vision_feature_layer if vision_feature_layer is not None else self.config.vision_feature_layer
    vision_feature_select_strategy = vision_feature_select_strategy if vision_feature_select_strategy is not None else self.config.vision_feature_select_strategy
    image_num_patches = [image_size_to_num_patches(image_size=imsize, grid_pinpoints=self.config.image_grid_pinpoints, patch_size=self.config.vision_config.image_size) for imsize in image_sizes]
    if pixel_values.dim() == 5:
        _pixel_values_list = [pix_val[:num_patch] for pix_val, num_patch in zip(pixel_values, image_num_patches)]
        pixel_values = torch.cat(_pixel_values_list, dim=0)
    elif pixel_values.dim() != 4:
        raise ValueError(f'pixel_values of shape {pixel_values.shape}, expect to be of 4 or 5 dimensions')
    image_features = self.vision_tower(pixel_values, output_hidden_states=True)
    if isinstance(vision_feature_layer, int):
        selected_image_feature = image_features.hidden_states[vision_feature_layer]
    else:
        hs_pool = [image_features.hidden_states[layer_idx] for layer_idx in vision_feature_layer]
        selected_image_feature = torch.cat(hs_pool, dim=-1)
    if vision_feature_select_strategy == 'default':
        selected_image_feature = selected_image_feature[:, 1:]
    elif vision_feature_select_strategy == 'full':
        selected_image_feature = selected_image_feature
    image_features = self.multi_modal_projector(selected_image_feature)
    image_features = torch.split(image_features, image_num_patches, dim=0)
    image_features, feature_lens = self.pack_image_features(image_features, image_sizes, vision_feature_select_strategy=vision_feature_select_strategy, image_newline=self.image_newline)
    return image_features

Obtains image last hidden states from the vision tower and apply multimodal projection.

Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, num_patches, channels, height, width)`)
The tensors corresponding to the input images.
image_sizes (`torch.Tensor` of shape `(num_images, 2)`)
Actual image size of each images (H, W).
vision_feature_layer (`Union[int, List[int]]`, *optional*):
The index of the layer to select the vision feature. If multiple indices are provided,
the vision feature of the corresponding indices will be concatenated to form the
vision features.
vision_feature_select_strategy (`str`, *optional*):
The feature selection strategy used to select the vision feature from the vision backbone.
Can be one of `"default"` or `"full"`
Returns:
image_features (List[`torch.Tensor`]): List of image feature tensor, each contains all the visual feature of all patches
and are of shape `(num_patches, image_length, embed_dim)`).


def decode(obj, content_type):
    try:
        decoder = _decoders_map[content_type]
        return decoder(obj)
    except KeyError:
        raise _errors.UnsupportedFormatError(content_type)

Decode an object ton a one of the default content types to a numpy array.

Args:
obj (object): to be decoded.
content_type (str): content type to be used.

Returns:
np.array: decoded object.


def profile_setting_default_args(ij):
    profile_default_args = OrderedDict()
    profile_default_args['api_default_org'] = '$env.API_DEFAULT_ORG'
    profile_default_args['api_access_id'] = '$env.API_ACCESS_ID'
    profile_default_args['api_secret_key'] = '$envs.API_SECRET_KEY'
    profile_default_args['tc_api_path'] = '$env.TC_API_PATH'
    profile_default_args['tc_docker'] = False
    profile_default_args['tc_in_path'] = 'log'
    profile_default_args['tc_log_level'] = 'debug'
    profile_default_args['tc_log_path'] = 'log'
    profile_default_args['tc_log_to_api'] = False
    profile_default_args['tc_out_path'] = 'log'
    profile_default_args['tc_proxy_external'] = False
    profile_default_args['tc_proxy_host'] = '$env.TC_PROXY_HOST'
    profile_default_args['tc_proxy_port'] = '$env.TC_PROXY_PORT'
    profile_default_args['tc_proxy_password'] = '$envs.TC_PROXY_PASSWORD'
    profile_default_args['tc_proxy_tc'] = False
    profile_default_args['tc_proxy_username'] = '$env.TC_PROXY_USERNAME'
    profile_default_args['tc_temp_path'] = 'log'
    if (ij.get('runtimeLevel') == 'Playbook'):
        profile_default_args['tc_playbook_db_type'] = 'Redis'
        profile_default_args['tc_playbook_db_context'] = str(uuid4())
        profile_default_args['tc_playbook_db_path'] = '$env.DB_PATH'
        profile_default_args['tc_playbook_db_port'] = '$env.DB_PORT'
        profile_default_args['tc_playbook_out_variables'] = ''
    return profile_default_args

Build the default args for this profile.

Args:
ij (dict): The install.json contents.

Returns:
dict: The default args for a Job or Playbook App.


def url(self):
    base_url = 'https:
    archived_at = self._get_archived_at()
    if (archived_at and archived_at.startswith('<')):
        archived_at = archived_at[1:]
    if (archived_at and archived_at.endswith('>')):
        archived_at = archived_at[:(- 1)]
    if (archived_at and archived_at.startswith('http')):
        return archived_at
    elif archived_at:
        return (base_url + archived_at)
    else:
        return None

An URL to the email in HyperKitty

Returns:
str or None: A relevant URL.


def _find_executable_or_die(executable_name: str, executable_path: Optional[str]=None) -> str:
    if executable_path:
        return str(pathlib.Path(executable_path).resolve(strict=True))
    resolved_path_to_exe = _find_executable(executable_name)
    if resolved_path_to_exe is None:
        raise RuntimeError(f'Could not find executable `{executable_name}`! Please change your $PATH or pass the path directly like`--{executable_name}_path=path/to/executable.')
    logging.info('Found path to %s at %s', executable_name, resolved_path_to_exe)
    return resolved_path_to_exe

Finds executable and resolves symlinks or raises RuntimeError.

Resolving symlinks is sometimes necessary for finding system headers.

Args:
executable_name: The name of the executable that we want to find.
executable_path: If not None, the path to the executable.

Returns:
The path to the executable we are looking for, after symlinks are resolved.
Raises:
RuntimeError: if path to the executable cannot be found.


def __init__(self, file_pattern, interval=360.0, has_deduplication=True, start_timestamp=Timestamp.now(), stop_timestamp=MAX_TIMESTAMP, match_updated_files=False, apply_windowing=False, empty_match_treatment=EmptyMatchTreatment.ALLOW):
    self.file_pattern = file_pattern
    self.interval = interval
    self.has_deduplication = has_deduplication
    self.start_ts = start_timestamp
    self.stop_ts = stop_timestamp
    self.match_upd = match_updated_files
    self.apply_windowing = apply_windowing
    self.empty_match_treatment = empty_match_treatment
    _LOGGER.warning('Matching Continuously is stateful, and can scale poorly. Consider using Pub/Sub Notifications (https:

Initializes a MatchContinuously transform.

Args:
file_pattern: The file path to read from.
interval: Interval at which to check for files in seconds.
has_deduplication: Whether files already read are discarded or not.
start_timestamp: Timestamp for start file checking.
stop_timestamp: Timestamp after which no more files will be checked.
match_updated_files: (When has_deduplication is set to True) whether match
file with timestamp changes.
apply_windowing: Whether each element should be assigned to
individual window. If false, all elements will reside in global window.


def load_weights_from_hdf5_group(f, layers):
    if 'keras_version' in f.attrs:
        original_keras_version = f.attrs['keras_version']
        if hasattr(original_keras_version, 'decode'):
            original_keras_version = original_keras_version.decode('utf8')
    else:
        original_keras_version = '1'
    if 'backend' in f.attrs:
        original_backend = f.attrs['backend']
        if hasattr(original_backend, 'decode'):
            original_backend = original_backend.decode('utf8')
    else:
        original_backend = None
    filtered_layers = []
    for layer in layers:
        weights = _legacy_weights(layer)
        if weights:
            filtered_layers.append(layer)
    layer_names = load_attributes_from_hdf5_group(f, 'layer_names')
    filtered_layer_names = []
    for name in layer_names:
        g = f[name]
        weight_names = load_attributes_from_hdf5_group(g, 'weight_names')
        if weight_names:
            filtered_layer_names.append(name)
    layer_names = filtered_layer_names
    if len(layer_names) != len(filtered_layers):
        raise ValueError('You are trying to load a weight file containing ' + str(len(layer_names)) + ' layers into a model with ' + str(len(filtered_layers)) + ' layers.')
    weight_value_tuples = []
    for k, name in enumerate(layer_names):
        g = f[name]
        weight_names = load_attributes_from_hdf5_group(g, 'weight_names')
        weight_values = [np.asarray(g[weight_name]) for weight_name in weight_names]
        layer = filtered_layers[k]
        symbolic_weights = _legacy_weights(layer)
        weight_values = preprocess_weights_for_loading(layer, weight_values, original_keras_version, original_backend)
        if len(weight_values) != len(symbolic_weights):
            raise ValueError('Layer
        weight_value_tuples += zip(symbolic_weights, weight_values)
    backend.batch_set_value(weight_value_tuples)

Implements topological (order-based) weight loading.

Args:
f: A pointer to a HDF5 group.
layers: a list of target layers.

Raises:
ValueError: in case of mismatch between provided layers
and weights file.


def remove(self, uids: Iterable[int]) -> None:
    for uid in uids:
        self._recent.discard(uid)
        self._flags.pop(uid, None)

Remove any session flags for the given message.

Args:
uids: The message UID values.


def set_value(self, text):
    if self.single_line:
        text = text.replace('\n', '')
    self.set_text(text)

Sets the text content.

Args:
text (str): The string content that have to be appended as standard child identified by the key 'text'


class CsvPipelineDataFormat(PipelineDataFormat):

    def __init__(self, output_path: Optional[str], input_path: Optional[str], column: Optional[str], overwrite=False):
        super().__init__(output_path, input_path, column, overwrite=overwrite)

    def __iter__(self):
        with open(self.input_path, 'r') as f:
            reader = csv.DictReader(f)
            for row in reader:
                if self.is_multi_columns:
                    yield {k: row[c] for k, c in self.column}
                else:
                    yield row[self.column[0]]

    def save(self, data: List[dict]):

        with open(self.output_path, 'w') as f:
            if len(data) > 0:
                writer = csv.DictWriter(f, list(data[0].keys()))
                writer.writeheader()
                writer.writerows(data)

Support for pipelines using CSV data format.

Args:
output_path (`str`): Where to save the outgoing data.
input_path (`str`): Where to look for the input data.
column (`str`): The column to read.
overwrite (`bool`, *optional*, defaults to `False`):
Whether or not to overwrite the `output_path`.


def set_bias(self, bias):
    self.x_offset += (bias - self._bias)
    self._bias = bias
    self._build_cdict()

Adjusts the image bias.

Bias determines where the color changes start.  At low bias, low
intensities (i.e., low pixel values) will have non-zero color
differences, while at high bias only high pixel values will have
non-zero differences

Args:
bias: float
A number between 0 and 1.  Note that upon initialization the
colormap has a default bias of 0.5.

Returns: void


def get_numeric_feature_names(example):

  numeric_features = ('float_list', 'int64_list')
  features = get_example_features(example)
  return sorted([
      feature_name for feature_name in features
      if features[feature_name].WhichOneof('kind') in numeric_features
  ])

Returns a list of feature names for float and int64 type features.

Args:
example: An example.

Returns:
A list of strings of the names of numeric features.


def get_atom_map(structure):
    syms = [site.specie.symbol for site in structure]
    unique_pot_atoms = []
    [unique_pot_atoms.append(i) for i in syms if (not unique_pot_atoms.count(i))]
    atom_map = {}
    for (i, atom) in enumerate(unique_pot_atoms):
        atom_map[atom] = (i + 1)
    return atom_map

Returns a dict that maps each atomic symbol to a unique integer starting
from 1.

Args:
structure (Structure)

Returns:
dict


def _convert_args(handler, args):
    args = list(args)
    params = inspect.signature(handler).parameters
    for (i, (arg, name)) in enumerate(zip(args, params)):
        default = params[name].default
        annotation = params[name].annotation
        if (annotation != inspect.Parameter.empty):
            if (isinstance(annotation, type) and (annotation != str)):
                args[i] = annotation(arg)
        elif (default != inspect.Parameter.empty):
            if ((default is not None) and (not isinstance(default, str))):
                args[i] = type(default)(arg)
    return args

Convert a list of command arguments to types specified by the handler.

Args:
handler: a command handler function.
args: the list of string arguments to pass to handler.

Returns:
A new list containing `args` that have been converted to the expected type
for `handler`. For each function parameter of `handler` that has either an
explicit type annotation or a non-None default value, the corresponding
element in `args` is converted to that type.


def cmPrecision(cm, average=True):

    cm = cm.type(torch.float64)
    precision = cm.diag() / (cm.sum(dim=0) + 1e-15)
    if average:
        return precision.mean()
    return precision

Calculates precision using :class:`~ignite.metrics.ConfusionMatrix` metric.
Args:
cm (ConfusionMatrix): instance of confusion matrix metric
average (bool, optional): if True metric value is averaged over all classes
Returns:
MetricsLambda


def retrieve_all(self, subset=None):
    get_object = self.factory.get_object
    obj_class = self.obj_class
    full_objects = [get_object(obj_class, list_obj.id, subset) for list_obj in self]
    return JSSObjectList(self.factory, obj_class, full_objects)

Return a list of all JSSListData elements as full JSSObjects.

This can take a long time given a large number of objects,
and depending on the size of each object. Subsetting to only
include the data you need can improve performance.

Args:
subset: For objects which support it, a list of sub-tags to
request, or an "&" delimited string, (e.g.
"general&purchasing").  Default to None.


def get_start_time_metric(result: PipelineResult, namespace: str, name: str) -> int:
    distributions = result.metrics().query(MetricsFilter().with_namespace(namespace).with_name(name))['distributions']
    min_list = list(map(lambda m: m.result.min, distributions))
    return min(min_list) if len(min_list) > 0 else -1

get the start time out of all times recorded by the specified distribution
metric

Args:
result: the PipelineResult which metrics are read from
namespace: a string representing the namespace of wanted metric
name: a string representing the  name of the wanted metric

Returns:
the smallest time in the metric or -1 if it doesn't exist


def run(self, row, **kwargs):
    self.source = row
    kwargs['output'] = self.__graph__()
    super(CSVRowProcessor, self).run(**kwargs)
    return kwargs['output']

Methods takes a row and depending if a dict or list,
runs RML rules.

Args:
-----
row(Dict, List): Row from CSV Reader


def _construct_w(self, inputs):
    weight_shape = (self._kernel_shape + (1, 1))
    if ('w' not in self._initializers):
        self._initializers['w'] = create_weight_initializer(weight_shape[:2], dtype=inputs.dtype)
    w = tf.get_variable('w', shape=weight_shape, dtype=inputs.dtype, initializer=self._initializers['w'], partitioner=self._partitioners.get('w', None), regularizer=self._regularizers.get('w', None))
    return w

Construct the convolution weight matrix.

Figures out the shape of the weight matrix, initialize it, and return it.

Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.

Returns:
w: A weight matrix of the same type as `inputs` and of shape
[kernel_shape, 1, 1].


def load_snippet(self, name, package):
    if hasattr(self, name):
        raise SnippetError(self, ('Attribute "%s" already exists, please use a different name.' % name))
    self.services.snippets.add_snippet_client(name, package)

Starts the snippet apk with the given package name and connects.

Examples:

.. code-block:: python

ad.load_snippet(
name='maps', package='com.google.maps.snippets')
ad.maps.activateZoom('3')

Args:
name: string, the attribute name to which to attach the snippet
client. E.g. `name='maps'` attaches the snippet client to
`ad.maps`.
package: string, the package name of the snippet apk to connect to.

Raises:
SnippetError: Illegal load operations are attempted.


def _make_pred_succ_maps(self, node):
    pred_map = {e[2]['wire']: e[0] for e in self._multi_graph.in_edges(nbunch=node, data=True)}
    succ_map = {e[2]['wire']: e[1] for e in self._multi_graph.out_edges(nbunch=node, data=True)}
    return (pred_map, succ_map)

Return predecessor and successor dictionaries.

Args:
node (DAGNode): reference to multi_graph node

Returns:
tuple(dict): tuple(predecessor_map, successor_map)
These map from wire (Register, int) to predecessor (successor)
nodes of n.


def write_file(self, filepath, filename=None, directory=None):

        arcname = None
        if filename or directory:
            directory = directory.rstrip("/") + "/" if directory else ""
            filename = filename or os.path.basename(filepath)
            arcname = "{}{}".format(directory, filename)
        self._copy_to_zipfile(filepath, arcname=arcname)
        return arcname or filepath

write_file: Write local file to zip
Args:
filepath: (str) location to local file
directory: (str) directory in zipfile to write file to (optional)
Returns: path to file in zip

Note: filepath must be a relative path


def load_config(self, config):

        for k, v in config.items():
            if hasattr(self, k):
                raise DeviceError(
                    self,
                    ('Attribute %s already exists with value %s, cannot set '
                     'again.') % (k, getattr(self, k)))
            setattr(self, k, v)

Add attributes to the AndroidDevice object based on config.

Args:
config: A dictionary representing the configs.

Raises:
Error: The config is trying to overwrite an existing attribute.


def Log(self, format_str, *args):

    log_entry = rdf_flow_objects.FlowLogEntry(
        client_id=self.rdf_flow.client_id,
        flow_id=self.rdf_flow.flow_id,
        hunt_id=self.rdf_flow.parent_hunt_id,
        message=format_str % args)
    data_store.REL_DB.WriteFlowLogEntries([log_entry])
    if self.rdf_flow.parent_hunt_id:
      db_compat.ProcessHuntFlowLog(self.rdf_flow, format_str % args)

Logs the message using the flow's standard logging.

Args:
format_str: Format string
*args: arguments to the format string


def threw(self, error_type=None):

        if not error_type:
            return True if len(self.exceptions) > 0 else False
        else:
            return uch.obj_in_list(self.exceptions, error_type)

Determining whether the exception is thrown
Args:
error_type:
None: checking without specified exception
Specified Exception
Return: Boolean


def get_creation_date_tags(url, domain, as_dicts=False):
    creation_date_tags = [mementoweb_api_tags(url), get_whois_tags(domain)]
    creation_date_tags = sorted(sum(creation_date_tags, []), key=(lambda x: x.date))
    if (not as_dicts):
        return creation_date_tags
    return [item._as_dict() for item in creation_date_tags]

Put together all data sources in this module and return it's output.

Args:
url (str): URL of the web. With relative paths and so on.
domain (str): Just the domain of the web.
as_dicts (bool, default False): Convert output to dictionaries
compatible with :class:`.SourceString`?

Returns:
list: Sorted list of :class:`TimeResource` objects or dicts.


def remove_collisions(self, min_dist=0.5):

        vfcoords = [v.frac_coords for v in self.vnodes]
        sfcoords = self.structure.frac_coords
        dist_matrix = self.structure.lattice.get_all_distances(vfcoords,
                                                               sfcoords)
        all_dist = np.min(dist_matrix, axis=1)
        new_vnodes = []
        for i, v in enumerate(self.vnodes):
            if all_dist[i] > min_dist:
                new_vnodes.append(v)
        self.vnodes = new_vnodes

Remove vnodes that are too close to existing atoms in the structure

Args:
min_dist(float): The minimum distance that a vertex needs to be
from existing atoms.


def _cast_to_frameset(cls, other):
    if isinstance(other, FrameSet):
        return other
    try:
        return FrameSet(other)
    except Exception:
        return NotImplemented

Private method to simplify comparison operations.

Args:
other (:class:`FrameSet` or set or frozenset or or iterable): item to be compared

Returns:
:class:`FrameSet`

Raises:
:class:`NotImplemented`: if a comparison is impossible


def load(fh, model):

    graphs = penman.load(fh, cls=XMRSCodec)
    xs = [model.from_triples(g.triples()) for g in graphs]
    return xs

Deserialize PENMAN graphs from a file (handle or filename)

Args:
fh: filename or file object
model: Xmrs subclass instantiated from decoded triples
Returns:
a list of objects (of class *model*)


def xresnet18(pretrained=False, **kwargs):
    model = XResNet(BasicBlock, [2, 2, 2, 2], **kwargs)
    if pretrained:
        model.load_state_dict(model_zoo.load_url(model_urls['xresnet18']))
    return model

Constructs a XResNet-18 model.

Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet


def __init__(self, dims):
    if not isinstance(dims, tuple):
        raise TypeError('The dimensions passed to DummyMultiDimensionalLSTM should be a tuple of ints.')
    self._dims = dims
    self._output_size = tensor_shape.TensorShape(self._dims)
    self._state_size = (tensor_shape.TensorShape(self._dims), tensor_shape.TensorShape(self._dims))

Initialize the Multi-dimensional LSTM cell.

Args:
dims: tuple that contains the dimensions of the output of the cell,
without including 'Time' or 'Batch' dimensions.


def get_device_details(self, device):
    if not isinstance(device, PhysicalDevice):
        raise ValueError('device must be a tf.config.PhysicalDevice, but got: %s' % (device,))
    if self._physical_device_to_index is None or device not in self._physical_device_to_index:
        raise ValueError('The PhysicalDevice must be one obtained from calling `tf.config.list_physical_devices`, but got: %s' % (device,))
    index = self._physical_device_to_index[device]
    details = pywrap_tfe.TF_GetDeviceDetails(index)
    if 'compute_capability' in details:
        try:
            major, minor = details['compute_capability'].split('.')
            details['compute_capability'] = (int(major), int(minor))
        except ValueError as exc:
            raise RuntimeError('Device returned compute capability an in invalid format: %s' % details['compute_capability']) from exc
    return details

Returns details about a physical devices.

Args:
device: A `tf.config.PhysicalDevice` returned by
`tf.config.list_physical_devices` or `tf.config.get_visible_devices`.

Returns:
A dict with string keys.


def _define_step(self, done, score, summary):
    if (done.shape.ndims == 0):
        done = done[None]
    if (score.shape.ndims == 0):
        score = score[None]
    score_mean = streaming_mean.StreamingMean((), tf.float32)
    with tf.control_dependencies([done, score, summary]):
        done_score = tf.gather(score, tf.where(done)[(:, 0)])
        submit_score = tf.cond(tf.reduce_any(done), (lambda : score_mean.submit(done_score)), tf.no_op)
    with tf.control_dependencies([submit_score]):
        mean_score = tf.cond(self._report, score_mean.clear, float)
        steps_made = tf.shape(score)[0]
        next_step = self._step.assign_add(steps_made)
    with tf.control_dependencies([mean_score, next_step]):
        return (tf.identity(summary), mean_score, next_step, steps_made)

Combine operations of a phase.

Keeps track of the mean score and when to report it.

Args:
done: Tensor indicating whether current score can be used.
score: Tensor holding the current, possibly intermediate, score.
summary: Tensor holding summary string to write if not an empty string.

Returns:
Tuple of summary tensor, mean score, and new global step. The mean score
is zero for non reporting steps.


def UninstallDriver(bundle_name):

  km = objc.KextManager()

  cf_bundle_name = km.PyStringToCFString(bundle_name)
  status = km.iokit.KextManagerUnloadKextWithIdentifier(cf_bundle_name)
  km.dll.CFRelease(cf_bundle_name)
  return status

Calls into the IOKit to unload a kext by its name.

Args:
bundle_name: The bundle identifier of the kernel extension as defined in
Info.plist field CFBundleIdentifier.
Returns:
The error code from the library call. objc.OS_SUCCESS if successfull.


def sg_summary_param(tensor, prefix=None, name=None):
    r

    prefix = '' if prefix is None else prefix + '/'

    name = prefix + _pretty_name(tensor) if name is None else prefix + name

    _scalar(name + '/abs', tf.reduce_mean(tf.abs(tensor)))
    _histogram(name + '/abs-h', tf.abs(tensor))

r"""Register `tensor` to summary report as `parameters`

Args:
tensor: A `Tensor` to log as parameters
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.

Returns:
None


def setScales(self,scales=None,term_num=None):

        if scales==None:
            for term_i in range(self.n_terms):
                n_scales = self.vd.getTerm(term_i).getNumberScales()
                self.vd.getTerm(term_i).setScales(SP.array(SP.randn(n_scales)))
        elif term_num==None:
            assert scales.shape[0]==self.vd.getNumberScales(), 'incompatible shape'
            index = 0
            for term_i in range(self.n_terms):
                index1 = index+self.vd.getTerm(term_i).getNumberScales()
                self.vd.getTerm(term_i).setScales(scales[index:index1])
                index = index1
        else:
            assert scales.shape[0]==self.vd.getTerm(term_num).getNumberScales(), 'incompatible shape'
            self.vd.getTerm(term_num).setScales(scales)

get random initialization of variances based on the empirical trait variance

Args:
scales:     if scales==None: set them randomly,
else: set scales to term_num (if term_num==None: set to all terms)
term_num:   set scales to term_num


def embedding_lookup(self, x, means):

    x_means_hot = self.nearest_neighbor(x, means)
    x_means_hot_flat = tf.reshape(
        x_means_hot, [-1, self.hparams.num_blocks, self.hparams.block_v_size])
    x_means = tf.matmul(tf.transpose(x_means_hot_flat, perm=[1, 0, 2]), means)
    x_means = tf.transpose(x_means, [1, 0, 2])
    q_loss = tf.reduce_mean(
        tf.squared_difference(tf.stop_gradient(x), x_means))
    e_loss = tf.reduce_mean(
        tf.squared_difference(x, tf.stop_gradient(x_means)))
    return x_means_hot, x_means, q_loss, e_loss

Compute nearest neighbors and loss for training the embeddings.

Args:
x: Batch of encoder continuous latent states sliced/projected into
shape
[-1, num_blocks, block_dim].
means: Embedding means.

Returns:
The nearest neighbor in one hot form, the nearest neighbor
itself, the
commitment loss, embedding training loss.


def get_dataframe(self, md5, compress='lz4'):

        sample = self.data_store.get_sample(md5)
        if not sample:
            raise WorkBench.DataNotFound("Could not find %s in the data store", md5)
        if not compress:
            return sample['raw_bytes']
        else:
            compress_df = lz4.dumps(sample['raw_bytes'])
            print 'Info: DataFrame compression %.0f%%' % (len(compress_df)*100.0/float(len(sample['raw_bytes'])))
            return compress_df

Return a dataframe from the DataStore. This is just a convenience method
that uses get_sample internally.
Args:
md5: the md5 of the dataframe
compress: compression to use: (defaults to 'lz4' but can be set to None)
Returns:
A msgpack'd Pandas DataFrame
Raises:
Workbench.DataNotFound if the dataframe is not found.


def peek_native(make):

    def peek(service, container, _stack=None):
        return make(service.peekNative(container))
    return peek

Deserializer factory for types which state can be natively serialized.

Arguments:

make (callable): type constructor.

Returns:

callable: deserializer (`peek` routine)


def _get_params(self, validator_parameter, name_prefix):
    params_validator = self.request.get(validator_parameter)
    user_params = {}
    for key in self.request.arguments():
        if key.startswith(name_prefix):
            values = self.request.get_all(key)
            adjusted_key = key[len(name_prefix):]
            if (len(values) == 1):
                user_params[adjusted_key] = values[0]
            else:
                user_params[adjusted_key] = values
    if params_validator:
        resolved_validator = util.for_name(params_validator)
        resolved_validator(user_params)
    return user_params

Retrieves additional user-supplied params for the job and validates them.

Args:
validator_parameter: name of the request parameter which supplies
validator for this parameter set.
name_prefix: common prefix for all parameter names in the request.

Raises:
Any exception raised by the 'params_validator' request parameter if
the params fail to validate.

Returns:
The user parameters.


def _GetXY(fd):
    try:
        rc = struct.unpack(b'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, 'junk'))
        return (rc[1], rc[0]) if rc else None
    except:
        return None

Returns the terminal (x,y) size for fd.

Args:
fd: The terminal file descriptor.

Returns:
The terminal (x,y) size for fd or None on error.


def parallel_concat(processor_list: Sequence[Processor]) -> Processor:
    if not processor_list:
        raise ValueError('processor_list is empty')
    return _ParallelProcessor(processor_list)

Create a sequence of processors to be run in parallel.

The output is the concatenation of all processors, i.e.:

parallel_concat([p1, p2])(stream) -> [p1(stream), p2(stream)]

Args:
processor_list: list of processors.

Returns:
A processor consisting of the parallel run of all the processors in the
list. The execution is sequential from the first processor to the last and
the result of each processor is concatenated


def _update_step(self, sequence):
    (observ, action, old_policy_params, reward, advantage) = sequence['sequence']
    length = sequence['length']
    old_policy = self._policy_type(**old_policy_params)
    (value_loss, value_summary) = self._value_loss(observ, reward, length)
    network = self._network(observ, length)
    (policy_loss, policy_summary) = self._policy_loss(old_policy, network.policy, action, advantage, length)
    network_loss = network.get('loss', 0.0)
    loss = ((policy_loss + value_loss) + tf.reduce_mean(network_loss))
    (gradients, variables) = zip(*self._optimizer.compute_gradients(loss))
    optimize = self._optimizer.apply_gradients(zip(gradients, variables))
    summary = tf.summary.merge([value_summary, policy_summary, tf.summary.histogram('network_loss', network_loss), tf.summary.scalar('avg_network_loss', tf.reduce_mean(network_loss)), tf.summary.scalar('gradient_norm', tf.global_norm(gradients)), utility.gradient_summaries(zip(gradients, variables))])
    with tf.control_dependencies([optimize]):
        return [tf.identity(x) for x in (value_loss, policy_loss, summary)]

Compute the current combined loss and perform a gradient update step.

The sequences must be a dict containing the keys `length` and `sequence`,
where the latter is a tuple containing observations, actions, parameters of
the behavioral policy, rewards, and advantages.

Args:
sequence: Sequences of episodes or chunks of episodes.

Returns:
Tuple of value loss, policy loss, and summary tensor.


def approximate_gradient(f, variables, delta=0.1):

    def var_gradient(var):

        def mapper_func(i):

            stencil = _five_point_stencil(f, var, i, delta)
            inner_sum = tf.nest.map_structure(tf.math.reduce_sum, tf.nest.flatten(stencil))
            outer_sum = tf.math.reduce_sum(tf.stack(inner_sum))
            entry_derivative = tf.reduce_sum(outer_sum)
            return entry_derivative
        derivatives = tf.map_fn(mapper_func, tf.range(tf.size(var)), fn_output_signature=tf.float32)
        return tf.reshape(derivatives, tf.shape(var))
    return tf.nest.map_structure(var_gradient, variables)

Approximates the gradient of f using five point stencil.

Suppose the input function returns a possibly nested structure `r` under
gradient tape `t`.  Then this function returns an approximation to
`t.gradient(r, variables, unconnected_gradients=tf.UnconnectedGradients.ZERO)`

Args:
f: Callable taking no arguments and returning a possibly nested structure
whose atomic elements are `tf.Tensor`.
variables: Possibly nested structure of `tf.Variable` in which to
differentiate `f`.
delta: Size of the fundamental perturbation in the stencil.

Returns:
The approximate gradient.  Has the same structure as the return from a
corresponding call to `tf.GradientTape().gradient`.


def decode_field(self, field, value):
    for decoder in _GetFieldCodecs(field, 'decoder'):
        result = decoder(field, value)
        value = result.value
        if result.complete:
            return value
    if isinstance(field, messages.MessageField):
        field_value = self.decode_message(field.message_type, json.dumps(value))
    elif isinstance(field, messages.EnumField):
        value = (GetCustomJsonEnumMapping(field.type, json_name=value) or value)
        try:
            field_value = super(_ProtoJsonApiTools, self).decode_field(field, value)
        except messages.DecodeError:
            if (not isinstance(value, six.string_types)):
                raise
            field_value = None
    else:
        field_value = super(_ProtoJsonApiTools, self).decode_field(field, value)
    return field_value

Decode the given JSON value.

Args:
field: a messages.Field for the field we're decoding.
value: a python value we'd like to decode.

Returns:
A value suitable for assignment to field.


def sigmoid(x):
    if any_symbolic_tensors((x,)):
        return Sigmoid().symbolic_call(x)
    return backend.nn.sigmoid(x)

Sigmoid activation function.

It is defined as `f(x) = 1 / (1 + exp(-x))`.

Args:
x: Input tensor.

Returns:
A tensor with the same shape as `x`.

Example:

>>> x = keras.ops.convert_to_tensor([-6.0, 1.0, 0.0, 1.0, 6.0])
>>> keras.ops.sigmoid(x)
array([0.00247262, 0.7310586, 0.5, 0.7310586, 0.9975274], dtype=float32)


def __init__(self, entry_list, weights=None):

        if weights is None:
            self.weights = [1.0] * len(entry_list)
        else:
            self.weights = weights
        self.entry_list = entry_list

Initializes a MultiEntry.

Args:
entry_list ([PourbaixEntry]): List of component PourbaixEntries
weights ([float]): Weights associated with each entry. Default is None


def create_upload_url(success_path, max_bytes_per_blob=None, max_bytes_total=None, **options):
    fut = create_upload_url_async(success_path, max_bytes_per_blob=max_bytes_per_blob, max_bytes_total=max_bytes_total, **options)
    return fut.get_result()

Create upload URL for POST form.

Args:
success_path: Path within application to call when POST is successful
and upload is complete.
max_bytes_per_blob: The maximum size in bytes that any one blob in the
upload can be or None for no maximum size.
max_bytes_total: The maximum size in bytes that the aggregate sizes of all
of the blobs in the upload can be or None for no maximum size.
**options: Options for create_rpc().

Returns:
The upload URL.

Raises:
TypeError: If max_bytes_per_blob or max_bytes_total are not integral types.
ValueError: If max_bytes_per_blob or max_bytes_total are not
positive values.


def cluster_spec(self):
    if self._override_client:
        client = self._override_client
    else:
        from kubernetes import config as k8sconfig
        from kubernetes import client as k8sclient
        k8sconfig.load_kube_config()
        client = k8sclient.CoreV1Api()
    cluster_map = {}
    for tf_job in self._job_to_label_mapping:
        all_pods = []
        for selector in self._job_to_label_mapping[tf_job]:
            ret = client.list_pod_for_all_namespaces(label_selector=selector)
            selected_pods = []
            for pod in sorted(ret.items, key=lambda x: x.metadata.name):
                if pod.status.phase == 'Running':
                    selected_pods.append('%s:%s' % (pod.status.host_ip, self._tf_server_port))
                else:
                    raise RuntimeError('Pod "%s" is not running; phase: "%s"' % (pod.metadata.name, pod.status.phase))
            all_pods.extend(selected_pods)
        cluster_map[tf_job] = all_pods
    return server_lib.ClusterSpec(cluster_map)

Returns a ClusterSpec object based on the latest info from Kubernetes.

We retrieve the information from the Kubernetes master every time this
method is called.

Returns:
A ClusterSpec containing host information returned from Kubernetes.

Raises:
RuntimeError: If any of the pods returned by the master is not in the
`Running` phase.


def check_configuration(ctx, base_key, needed_keys):
    if (base_key not in ctx.keys()):
        exit("[{}ERROR{}] missing configuration for '{}'".format(ERROR_COLOR, RESET_COLOR, base_key))
    if (ctx.releaser is None):
        exit("[{}ERROR{}] empty configuration for '{}' found".format(ERROR_COLOR, RESET_COLOR, base_key))
    for my_key in needed_keys:
        if (my_key not in ctx[base_key].keys()):
            exit("[{}ERROR{}] missing configuration key '{}.{}'".format(ERROR_COLOR, RESET_COLOR, base_key, my_key))

Confrim a valid configuration.

Args:
ctx (invoke.context):
base_key (str): the base configuration key everything is under.
needed_keys (list): sub-keys of the base key that are checked to make
sure they exist.


def execute_before(self, sensor_graph, scope_stack):

        parent = scope_stack[-1]
        new_scope = Scope("Configuration Scope", sensor_graph, parent.allocator, parent)
        new_scope.add_identifier('current_slot', self.slot)
        scope_stack.append(new_scope)

Execute statement before children are executed.

Args:
sensor_graph (SensorGraph): The sensor graph that we are building or
modifying
scope_stack (list(Scope)): A stack of nested scopes that may influence
how this statement allocates clocks or other stream resources.


def format_counts(counts, header=None):
    counts_dict = {}
    for (key, val) in counts.items():
        key = format_counts_memory(key, header)
        counts_dict[key] = val
    return counts_dict

Format a single experiment result coming from backend to present
to the Qiskit user.

Args:
counts (dict): counts histogram of multiple shots
header (dict): the experiment header dictionary containing
useful information for postprocessing.

Returns:
dict: a formatted counts


def to_frame(self, *args):
    if (sys.version_info < (3, 6, 0)):
        from collections import OrderedDict
        impls = OrderedDict()
        for (name, obj) in self.items():
            impls[name] = obj._impl
    else:
        impls = get_impls(self)
    return _to_frame_inner(impls, args)

Convert the cells in the view into a DataFrame object.

If ``args`` is not given, this method returns a DataFrame that
has an Index or a MultiIndex depending of the number of
cells parameters and columns each of which corresponds to each
cells included in the view.

``args`` can be given to calculate cells values and limit the
DataFrame indexes to the given arguments.

The cells in this view may have different number of parameters,
but parameters shared among multiple cells
must appear in the same position in all the parameter lists.
For example,
Having ``foo()``, ``bar(x)`` and ``baz(x, y=1)`` is okay
because the shared parameter ``x`` is always the first parameter,
but this method does not work if the view has ``quz(x, z=2, y=1)``
cells in addition to the first three cells, because ``y`` appears
in different positions.

Args:
args(optional): multiple arguments,
or an iterator of arguments to the cells.


def __init__(self, header, values):

        assert isinstance(header, Header), \
            'header must be a Ladybug Header object. Got {}'.format(type(header))
        assert isinstance(header.analysis_period, AnalysisPeriod), \
            'header of {} must have an analysis_period.'.format(self.__class__.__name__)
        assert header.analysis_period.st_hour == 0, \
            'analysis_period start hour of {} must be 0. Got {}'.format(
                self.__class__.__name__, header.analysis_period.st_hour)
        assert header.analysis_period.end_hour == 23, \
            'analysis_period end hour of {} must be 23. Got {}'.format(
                self.__class__.__name__, header.analysis_period.end_hour)

        self._header = header
        self.values = values
        self._datetimes = None
        self._validated_a_period = True

Initialize hourly discontinuous collection.

Args:
header: A Ladybug Header object.  Note that this header
must have an AnalysisPeriod on it that aligns with the
list of values.
values: A list of values.  Note that the length of this list
must align with the AnalysisPeriod on the header.


def prepare_soap_body(self, method, parameters, namespace):

        tags = []
        for name, value in parameters:
            tag = "<{name}>{value}</{name}>".format(
                name=name, value=escape("%s" % value, {'"': """}))

            tags.append(tag)

        wrapped_params = "".join(tags)

        if namespace is not None:
            soap_body = (
                '<{method} xmlns="{namespace}">'
                '{params}'
                '</{method}>'.format(
                    method=method, params=wrapped_params,
                    namespace=namespace
                ))
        else:
            soap_body = (
                '<{method}>'
                '{params}'
                '</{method}>'.format(
                    method=method, params=wrapped_params
                ))

        return soap_body

Prepare the SOAP message body for sending.

Args:
method (str): The name of the method to call.
parameters (list): A list of (name, value) tuples containing
the parameters to pass to the method.
namespace (str): tThe XML namespace to use for the method.

Returns:
str: A properly formatted SOAP Body.


def __init__(self, group_type, name, **kwargs):

        self._utils = TcExUtils()
        self._name = name
        self._type = group_type
        self._group_data = {'name': name, 'type': group_type}

        for arg, value in kwargs.items():
            self.add_key_value(arg, value)

        if kwargs.get('xid') is None:
            self._group_data['xid'] = str(uuid.uuid4())
        self._attributes = []
        self._labels = []
        self._file_content = None
        self._tags = []
        self._processed = False

Initialize Class Properties.

Args:
group_type (str): The ThreatConnect define Group type.
name (str): The name for this Group.
xid (str, kwargs): The external id for this Group.


def _skip_parameter_matching(self) -> bool:
    if self.signature.type_params:
        return False
    if self.ctx.options.analyze_annotated:
        return False
    return self.signature.has_return_annotation or self.full_name == '__init__'

Check whether we should skip parameter matching.

This is use to skip parameter matching for function calls in the context of
inference (pyi generation). This is to optimize the case where we don't
need to match parameters in cases which the function has explicit type
annotations, meaning that we don't need to infer the type.

Returns:
True if we should skip parameter matching.


def load_config(logdir):

  config_path = logdir and os.path.join(logdir, 'config.yaml')
  if not config_path or not tf.gfile.Exists(config_path):
    message = (
        'Cannot resume an existing run since the logging directory does not '
        'contain a configuration file.')
    raise IOError(message)
  with tf.gfile.FastGFile(config_path, 'r') as file_:
    config = yaml.load(file_, Loader=yaml.Loader)
  message = 'Resume run and write summaries and checkpoints to {}.'
  tf.logging.info(message.format(config.logdir))
  return config

Load a configuration from the log directory.

Args:
logdir: The logging directory containing the configuration file.

Raises:
IOError: The logging directory does not contain a configuration file.

Returns:
Configuration object.


def obtain_capture_by_value_ops(dataset):

    def capture_by_value(op):
        return op.outputs[0].dtype in TENSOR_TYPES_ALLOWLIST or op.type in OP_TYPES_ALLOWLIST
    return _traverse(dataset, capture_by_value)

Given an input dataset, finds all allowlisted ops used for construction.

Allowlisted ops are stateful ops which are known to be safe to capture by
value.

Args:
dataset: Dataset to find allowlisted stateful ops for.

Returns:
A list of variant_tensor producing dataset ops used to construct this
dataset.


def get_custom_objects():
    return GLOBAL_CUSTOM_OBJECTS

Retrieves a live reference to the global dictionary of custom objects.

Custom objects set using `custom_object_scope()` are not added to the
global dictionary of custom objects, and will not appear in the returned
dictionary.

Example:

```python
get_custom_objects().clear()
get_custom_objects()['MyObject'] = MyObject
```

Returns:
Global dictionary mapping registered class names to classes.


def _assign_method(self, resource_class, method_type):

        method_name = resource_class.get_method_name(
            resource_class, method_type)
        valid_status_codes = getattr(
            resource_class.Meta,
            'valid_status_codes',
            DEFAULT_VALID_STATUS_CODES
        )

        def get(self, method_type=method_type, method_name=method_name,
                valid_status_codes=valid_status_codes,
                resource=resource_class, data=None, uid=None, **kwargs):
            return self.call_api(
                method_type, method_name,
                valid_status_codes, resource,
                data, uid=uid, **kwargs)

        def put(self, method_type=method_type, method_name=method_name,
                valid_status_codes=valid_status_codes,
                resource=resource_class, data=None, uid=None, **kwargs):
            return self.call_api(
                method_type, method_name,
                valid_status_codes, resource,
                data, uid=uid, **kwargs)

        def post(self, method_type=method_type, method_name=method_name,
                 valid_status_codes=valid_status_codes,
                 resource=resource_class, data=None, uid=None, **kwargs):
            return self.call_api(
                method_type, method_name,
                valid_status_codes, resource,
                data, uid=uid, **kwargs)

        def patch(self, method_type=method_type, method_name=method_name,
                  valid_status_codes=valid_status_codes,
                  resource=resource_class, data=None, uid=None, **kwargs):
            return self.call_api(
                method_type, method_name,
                valid_status_codes, resource,
                data, uid=uid, **kwargs)

        def delete(self, method_type=method_type, method_name=method_name,
                   valid_status_codes=valid_status_codes,
                   resource=resource_class, data=None, uid=None, **kwargs):
            return self.call_api(
                method_type, method_name,
                valid_status_codes, resource,
                data, uid=uid, **kwargs)

        method_map = {
            'GET': get,
            'PUT': put,
            'POST': post,
            'PATCH': patch,
            'DELETE': delete
        }

        setattr(
            self, method_name,
            types.MethodType(method_map[method_type], self)
        )

Using reflection, assigns a new method to this class.

Args:
resource_class: A resource class
method_type: The HTTP method type


def sendline(self, text):
    logger.debug("Sending input '{0}' to '{1}'".format(text, self.name))
    try:
        return self._spawn.sendline(text)
    except pexpect.exceptions.EOF as e:
        logger.debug('Raising termination exception.')
        raise TerminationException(instance=self, real_exception=e, output=self.get_output())
    except pexpect.exceptions.TIMEOUT as e:
        logger.debug('Raising timeout exception.')
        raise TimeoutException(instance=self, real_exception=e, output=self.get_output())
    except Exception as e:
        logger.debug(('Sending input failed: ' + str(e)))
        raise NestedException(instance=self, real_exception=e, output=self.get_output())

Sends an input line to the running program, including os.linesep.

Args:
text (str): The input text to be send.

Raises:
TerminationException: The program terminated before / while / after sending the input.
NestedException: An internal problem occured while waiting for the output.


def ModulePath(module_name):
    module = importlib.import_module(module_name)
    path = inspect.getfile(module)
    if compatibility.PY2:
        path = path.decode('utf-8')
    if os.path.basename(path).startswith('__init__.'):
        path = os.path.dirname(path)
    if path.endswith('.pyc'):
        path = (path[:(- 4)] + '.py')
    return path

Computes a path to the specified module.

Args:
module_name: A name of the module to get the path for.

Returns:
A path to the specified module.

Raises:
ImportError: If specified module cannot be imported.


def next(self):
    options = {}
    if self._buffer_size:
        options['read_buffer_size'] = self._buffer_size
    if self._account_id:
        options['_account_id'] = self._account_id
    while True:
        filename = self._next_file()
        if (filename is None):
            raise StopIteration()
        if (self._path_filter and (not self._path_filter.accept(self._slice_ctx, filename))):
            continue
        try:
            start_time = time.time()
            handle = cloudstorage.open(filename, **options)
            self._slice_ctx.incr(self.COUNTER_IO_READ_MSEC, (int((time.time() - start_time)) * 1000))
            self._slice_ctx.incr(self.COUNTER_FILE_READ)
            return handle
        except cloudstorage.NotFoundError:
            logging.warning('File %s may have been removed. Skipping file.', filename)
            self._slice_ctx.incr(self.COUNTER_FILE_MISSING)

Returns a handler to the next file.

Non existent files will be logged and skipped. The file might have been
removed after input splitting.

Returns:
The next input from this input reader in the form of a cloudstorage
ReadBuffer that supports a File-like interface (read, readline, seek,
tell, and close). An error may be raised if the file can not be opened.

Raises:
StopIteration: The list of files has been exhausted.


def float_value_convert(dictin, dropfailedvalues=False):

    return key_value_convert(dictin, valuefn=float, dropfailedvalues=dropfailedvalues)

Convert values of dictionary to floats

Args:
dictin (DictUpperBound): Input dictionary
dropfailedvalues (bool): Whether to drop dictionary entries where key conversion fails. Defaults to False.

Returns:
Dict: Dictionary with values converted to floats


def git_ls_remote(self, uri, ref):

        logger.debug("Invoking git to retrieve commit id for repo %s...", uri)
        lsremote_output = subprocess.check_output(['git',
                                                   'ls-remote',
                                                   uri,
                                                   ref])
        if b"\t" in lsremote_output:
            commit_id = lsremote_output.split(b"\t")[0]
            logger.debug("Matching commit id found: %s", commit_id)
            return commit_id
        else:
            raise ValueError("Ref \"%s\" not found for repo %s." % (ref, uri))

Determine the latest commit id for a given ref.

Args:
uri (string): git URI
ref (string): git ref

Returns:
str: A commit id


def tell(self):
    self._check_open()
    return self.position

Tell the file's current offset.

Returns:
current offset in reading this file.

Raises:
``ValueError``: When this stream is closed.


def read_stream(self, start_offset=0, byte_count=None):

    try:
      return self._api.object_download(self._bucket, self._key,
                                       start_offset=start_offset, byte_count=byte_count)
    except Exception as e:
      raise e

Reads the content of this object as text.

Args:
start_offset: the start offset of bytes to read.
byte_count: the number of bytes to read. If None, it reads to the end.
Returns:
The text content within the object.
Raises:
Exception if there was an error requesting the object's content.


muparser cross product function

Compute the cross product of two 3x1 vectors

Args:
u (list or tuple of 3 strings): first vector
v (list or tuple of 3 strings): second vector
Returns:
A list containing a muparser string of the cross product


def get_tensor_size(self, tensor_name, partial_layout=None,
                      mesh_dimension_to_size=None):

    return (self.get_tensor_dtype(tensor_name).size *
            self.get_tensor_num_entries(tensor_name, partial_layout,
                                        mesh_dimension_to_size))

The size of a tensor in bytes.

If partial_layout is specified, then mesh_dimension_to_size must also be. In
this case, the size on a single device is returned.

Args:
tensor_name: a string, name of a tensor in the graph.
partial_layout: an optional {string: string}, from MTF dimension name to
mesh dimension name.
mesh_dimension_to_size: an optional {string: int}, from mesh dimension
name to size.

Returns:
an integer


def calculate_cidr(start_address, end_address):

    tmp_addrs = []

    try:

        tmp_addrs.extend(summarize_address_range(
            ip_address(start_address),
            ip_address(end_address)))

    except (KeyError, ValueError, TypeError):

        try:

            tmp_addrs.extend(summarize_address_range(
                ip_network(start_address).network_address,
                ip_network(end_address).network_address))

        except AttributeError:

            tmp_addrs.extend(summarize_address_range(
                ip_network(start_address).ip,
                ip_network(end_address).ip))

    return [i.__str__() for i in collapse_addresses(tmp_addrs)]

The function to calculate a CIDR range(s) from a start and end IP address.

Args:
start_address (:obj:`str`): The starting IP address.
end_address (:obj:`str`): The ending IP address.

Returns:
list of str: The calculated CIDR ranges.


def _deserialize_audience(audience_map):
    for audience in audience_map.values():
        (condition_structure, condition_list) = condition_helper.loads(audience.conditions)
        audience.__dict__.update({'conditionStructure': condition_structure, 'conditionList': condition_list})
    return audience_map

Helper method to de-serialize and populate audience map with the condition list and structure.

Args:
audience_map: Dict mapping audience ID to audience object.

Returns:
Dict additionally consisting of condition list and structure on every audience object.


def get_default_backend_config(appdirs):
    return {'store': 'sqlalchemy', 'day_start': datetime.time(5, 30, 0), 'fact_min_delta': 1, 'tmpfile_path': os.path.join(appdirs.user_data_dir, '{}.tmp'.format(appdirs.appname)), 'db_engine': 'sqlite', 'db_path': os.path.join(appdirs.user_data_dir, '{}.sqlite'.format(appdirs.appname))}

Return a default config dictionary.

Args:
appdirs (HamsterAppDirs): ``HamsterAppDirs`` instance encapsulating the apps details.

Returns:
dict: Dictionary with a default configuration.

Note:
Those defaults are independent of the particular config-store.


def __init__(self, curriculum_obj, batch_size, max_len, ops, token_by_char):

    self._vocab_dict = collections.defaultdict(lambda: 0)
    self._vocab_dict[self.UNK] = 0
    self._inv_vocab_dict = collections.defaultdict(lambda: self.UNK)

    self.curriculum_obj = curriculum_obj
    self._max_seq_length = max_len
    self._ops = ops
    self._token_by_char = token_by_char
    self._batch_size = batch_size

    num_token_digits = 1 if token_by_char else curriculum_obj.max_length
    token_list = get_tokens(10 ** num_token_digits)
    self.vocab_size = 1
    for token in self.DEFAULT_START_TOKENS + token_list:
      if token not in self._vocab_dict:
        self._vocab_dict[token] = self.vocab_size
        self._inv_vocab_dict[self.vocab_size] = token
        self.vocab_size += 1

Creates a TokenDataSource instance.

Args:
curriculum_obj: (LTECurriculum) determines sample complexity.
batch_size: (int) Batch size to generate.
max_len: (int) This is the maximum size of any given sample sequence.
ops: (list(CodeOp)). Task operations that inherit from CodeOp().
token_by_char: (bool) Whether to tokenize by char ("detokenized") or by
keyword, literals and numbers.


def get_note(self, noteid, version=None):

        params_version = ""
        if version is not None:
            params_version = '/v/' + str(version)

        params = '/i/%s%s' % (str(noteid), params_version)
        request = Request(DATA_URL+params)
        request.add_header(self.header, self.get_token())
        try:
            response = urllib2.urlopen(request)
        except HTTPError as e:
            if e.code == 401:
                raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
            else:
                return e, -1
        except IOError as e:
            return e, -1
        note = json.loads(response.read().decode('utf-8'))
        note = self.__add_simplenote_api_fields(note, noteid, int(response.info().get("X-Simperium-Version")))

        if "tags" in note:
            note["tags"] = sorted(note["tags"])

        return note, 0

Method to get a specific note

Arguments:
- noteid (string): ID of the note to get
- version (int): optional version of the note to get

Returns:
A tuple `(note, status)`

- note (dict): note object
- status (int): 0 on success and -1 otherwise


def update(self):
    (data_format, data) = RuuviTagSensor.get_data(self._mac, self._bt_device)
    if (data == self._data):
        return self._state
    self._data = data
    if (self._data is None):
        self._state = {}
    else:
        self._state = get_decoder(data_format).decode_data(self._data)
    return self._state

Get lates data from the sensor and update own state.

Returns:
dict: Latest state


def run(self, dag):

        cx_runs = dag.collect_runs(["cx"])
        for cx_run in cx_runs:

            partition = []
            chunk = []
            for i in range(len(cx_run) - 1):
                chunk.append(cx_run[i])

                qargs0 = cx_run[i].qargs
                qargs1 = cx_run[i + 1].qargs

                if qargs0 != qargs1:
                    partition.append(chunk)
                    chunk = []
            chunk.append(cx_run[-1])
            partition.append(chunk)

            for chunk in partition:
                if len(chunk) % 2 == 0:
                    for n in chunk:
                        dag.remove_op_node(n)
                else:
                    for n in chunk[1:]:
                        dag.remove_op_node(n)
        return dag

Run one pass of cx cancellation on the circuit

Args:
dag (DAGCircuit): the directed acyclic graph to run on.
Returns:
DAGCircuit: Transformed DAG.


def all(x, axis=None, keepdims=False):
    x = math_ops.cast(x, dtypes_module.bool)
    return math_ops.reduce_all(x, axis, keepdims)

Bitwise reduction (logical AND).

Args:
x: Tensor or variable.
axis: axis along which to perform the reduction.
keepdims: whether the drop or broadcast the reduction axes.

Returns:
A uint8 tensor (0s and 1s).


def _get_or_create_arg_by_name(state, name, is_kwarg=False):
    for arg in state.args + state.kwargs:
        if arg.name == name:
            return arg
    arg = Namespace()
    arg.name = name
    arg.type.lines = []
    arg.description.lines = []
    if is_kwarg:
        state.kwargs.append(arg)
    else:
        state.args.append(arg)
    return arg

Gets or creates a new Arg.

These Arg objects (Namespaces) are turned into the ArgInfo namedtuples
returned by parse. Each Arg object is used to collect the name, type, and
description of a single argument to the docstring's function.

Args:
state: The state of the parser.
name: The name of the arg to create.
is_kwarg: A boolean representing whether the argument is a keyword arg.
Returns:
The new Arg.


def _contiguous_groups(
        length: int,
        comparator: Callable[[int, int], bool]
) -> List[Tuple[int, int]]:

    result = []
    start = 0
    while start < length:
        past = start + 1
        while past < length and comparator(start, past):
            past += 1
        result.append((start, past))
        start = past
    return result

Splits range(length) into approximate equivalence classes.

Args:
length: The length of the range to split.
comparator: Determines if two indices have approximately equal items.

Returns:
A list of (inclusive_start, exclusive_end) range endpoints. Each
corresponds to a run of approximately-equivalent items.


def delete_public_ip(access_token, subscription_id, resource_group, public_ip_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Network/publicIPAddresses/', public_ip_name,
                        '?api-version=', NETWORK_API])
    return do_delete(endpoint, access_token)

Delete a public ip addresses associated with a resource group.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
public_ip_name (str): Name of the public ip address resource.

Returns:
HTTP response.


def _CheckParserCanProcessFileEntry(self, parser, file_entry):
    for filter_object in parser.FILTERS:
        if filter_object.Match(file_entry):
            return True
    return False

Determines if a parser can process a file entry.

Args:
file_entry (dfvfs.FileEntry): file entry.
parser (BaseParser): parser.

Returns:
bool: True if the file entry can be processed by the parser object.


def _pretty_print(key_val, sep=': ', min_col_width=39, text_width=None):

    if text_width is None:
        text_width = get_terminal_size().columns
    if text_width < min_col_width:
        min_col_width = text_width
    ncols = (text_width + 1)
    colw = (text_width + 1)
    ncols = min(ncols, len(key_val))

    wrapper = TextWrapper(width=colw)
    lines = []
    for key, val in key_val:
        if len(key) + len(sep) >= colw
            wrapper.subsequent_indent = ' '
        else:
            wrapper.subsequent_indent = ' ' * (len(key) + len(sep))
        lines.extend(wrapper.wrap('{}{}{}'.format(key, sep, val)))

    chunks = []
    for rem_col in range(ncols, 1, -1):
        isep = ceil(len(lines) / rem_col)
        while isep < len(lines) and lines[isep][0] == ' ':
            isep += 1
        chunks.append(lines[:isep])
        lines = lines[isep:]
    chunks.append(lines)
    lines = zip_longest(*chunks, fillvalue='')

    fmt = '|'.join(['{{:{}}}'.format(colw)] * (ncols - 1))
    fmt += '|{}' if ncols > 1 else '{}'
    print(*(fmt.format(*line) for line in lines), sep='\n')

Print a iterable of key/values

Args:
key_val (list of (str, str)): the pairs of section names and text.
sep (str): separator between section names and text.
min_col_width (int): minimal acceptable column width
text_width (int): text width to use. If set to None, will try to infer
the size of the terminal.


def _ExpectedKeysForEntry(self, entry):
    return [entry.name]

Generate a list of expected cache keys for this type of map.

Args:
entry: A GroupMapEntry

Returns:
A list of strings


def forward(self, seq_length=None, position=None):
    if position is None and seq_length is None:
        raise ValueError('Either position or seq_length must be provided')
    if position is None:
        position = torch.arange(seq_length, dtype=torch.float32, device=self.inv_timescales.device).unsqueeze(0)
    elif position.ndim != 2:
        raise ValueError(f'position must be 2-dimensional, got shape {position.shape}')
    scaled_time = position.view(*position.shape, 1) * self.inv_timescales.view(1, 1, -1)
    signal = torch.cat([torch.sin(scaled_time), torch.cos(scaled_time)], dim=2)
    signal = F.pad(signal, (0, 0, 0, self.embedding_dims % 2))
    return signal

Generates a Tensor of sinusoids with different frequencies.

Args:
seq_length: an optional Python int defining the output sequence length.
if the `position` argument is specified.
position: [B, seq_length], optional position for each token in the
sequence, only required when the sequence is packed.

Returns:
[B, seqlen, D] if `position` is specified, else [1, seqlen, D]


def _HasTable(self, table_name):

    query = self._HAS_TABLE_QUERY.format(table_name)

    self._cursor.execute(query)
    return bool(self._cursor.fetchone())

Determines if a specific table exists.

Args:
table_name (str): name of the table.

Returns:
bool: True if the table exists, false otherwise.


def handle_simple_responses(
      self, timeout_ms=None, info_cb=DEFAULT_MESSAGE_CALLBACK):

    return self._accept_responses('OKAY', info_cb, timeout_ms=timeout_ms)

Accepts normal responses from the device.

Args:
timeout_ms: Timeout in milliseconds to wait for each response.
info_cb: Optional callback for text sent from the bootloader.

Returns:
OKAY packet's message.


def get_spd_dos(self):
    spd_dos = {}
    for atom_dos in self.pdos.values():
        for (orb, pdos) in atom_dos.items():
            orbital_type = _get_orb_type(orb)
            if (orbital_type not in spd_dos):
                spd_dos[orbital_type] = pdos
            else:
                spd_dos[orbital_type] = add_densities(spd_dos[orbital_type], pdos)
    return {orb: Dos(self.efermi, self.energies, densities) for (orb, densities) in spd_dos.items()}

Get orbital projected Dos.

Returns:
dict of {orbital: Dos}, e.g. {"s": Dos object, ...}


def bbox_transpose(bbox, axis, rows, cols):

    x_min, y_min, x_max, y_max = bbox
    if axis != 0 and axis != 1:
        raise ValueError('Axis must be either 0 or 1.')
    if axis == 0:
        bbox = [y_min, x_min, y_max, x_max]
    if axis == 1:
        bbox = [1 - y_max, 1 - x_max, 1 - y_min, 1 - x_min]
    return bbox

Transposes a bounding box along given axis.

Args:
bbox (tuple): A tuple (x_min, y_min, x_max, y_max).
axis (int): 0 - main axis, 1 - secondary axis.
rows (int): Image rows.
cols (int): Image cols.


def cudnn_compatible_gru(units, n_hidden, n_layers=1, trainable_initial_states=False, seq_lengths=None, input_initial_h=None, name='cudnn_gru', reuse=False):
    with tf.variable_scope(name, reuse=reuse):
        if trainable_initial_states:
            init_h = tf.get_variable('init_h', [n_layers, 1, n_hidden])
            init_h = tf.tile(init_h, (1, tf.shape(units)[0], 1))
        else:
            init_h = tf.zeros([n_layers, tf.shape(units)[0], n_hidden])
        initial_h = (input_initial_h or init_h)
        with tf.variable_scope('cudnn_gru', reuse=reuse):

            def single_cell():
                return tf.contrib.cudnn_rnn.CudnnCompatibleGRUCell(n_hidden)
            cell = tf.nn.rnn_cell.MultiRNNCell([single_cell() for _ in range(n_layers)])
            units = tf.transpose(units, (1, 0, 2))
            (h, h_last) = tf.nn.dynamic_rnn(cell=cell, inputs=units, time_major=True, initial_state=tuple(tf.unstack(initial_h, axis=0)))
            h = tf.transpose(h, (1, 0, 2))
            h_last = h_last[(- 1)]
            if (seq_lengths is not None):
                indices = tf.stack([tf.range(tf.shape(h)[0]), (seq_lengths - 1)], axis=1)
                h_last = tf.gather_nd(h, indices)
            return (h, h_last)

CuDNN Compatible GRU implementation.
It should be used to load models saved with CudnnGRUCell to run on CPU.

Args:
units: tf.Tensor with dimensions [B x T x F], where
B - batch size
T - number of tokens
F - features

n_hidden: dimensionality of hidden state
trainable_initial_states: whether to create a special trainable variable
to initialize the hidden states of the network or use just zeros
seq_lengths: tensor of sequence lengths with dimension [B]
n_layers: number of layers
input_initial_h: initial hidden state, tensor
name: name of the variable scope to use
reuse:whether to reuse already initialized variable

Returns:
h - all hidden states along T dimension,
tf.Tensor with dimensionality [B x T x F]
h_last - last hidden state, tf.Tensor with dimensionality [B x H]


def _get(self, feed_item):
    return self._api().get(profileId=self.profile_id, id=str(feed_item[self._id_field])).execute()

Fetches an item from CM.

Args:
feed_item: Feed item from Bulkdozer feed representing the item to fetch
from CM.


def _build_mask_ds(mask, mask_offset):

  mask_ds = tf.data.Dataset.from_tensor_slices(mask)
  mask_ds = mask_ds.repeat()
  mask_ds = mask_ds.skip(mask_offset)
  return mask_ds

Build the mask dataset to indicate which element to skip.

Args:
mask: `tf.Tensor`, binary mask to apply to all following elements. This
mask should have a length 100.
mask_offset: `tf.Tensor`, Integer specifying from how much the mask
should be shifted for the first element.

Returns:
mask_ds: `tf.data.Dataset`, a dataset returning False for examples to skip
and True for examples to keep.


def decode_message(self, message_type, encoded_message):
    encoded_message = six.ensure_str(encoded_message)
    if (not encoded_message.strip()):
        return message_type()
    dictionary = json.loads(encoded_message)
    message = self.__decode_dictionary(message_type, dictionary)
    message.check_initialized()
    return message

Merge JSON structure to Message instance.

Args:
message_type: Message to decode data to.
encoded_message: JSON encoded version of message.

Returns:
Decoded instance of message_type.

Raises:
ValueError: If encoded_message is not valid JSON.
messages.ValidationError if merged message is not initialized.


def get_version():
    if (not INSTALLED):
        try:
            with open('version.txt', 'r') as v_fh:
                return v_fh.read()
        except Exception:
            warnings.warn('Unable to resolve package version until installed', UserWarning)
            return '0.0.0'
    return p_version.get_version(HERE)

find current version information

Returns:
(str): version information


def _assert_obj_type(pub, name='pub', obj_type=DBPublication):
    if (not isinstance(pub, obj_type)):
        raise InvalidType(('`%s` have to be instance of %s, not %s!' % (name, obj_type.__name__, pub.__class__.__name__)))

Make sure, that `pub` is instance of the `obj_type`.

Args:
pub (obj): Instance which will be checked.
name (str): Name of the instance. Used in exception. Default `pub`.
obj_type (class): Class of which the `pub` should be instance. Default
:class:`.DBPublication`.

Raises:
InvalidType: When the `pub` is not instance of `obj_type`.


def GetUserinfo(credentials, http=None):

    http = http or httplib2.Http()
    url = _GetUserinfoUrl(credentials)

    response, content = http.request(url)
    if response.status == http_client.BAD_REQUEST:
        credentials.refresh(http)
        url = _GetUserinfoUrl(credentials)
        response, content = http.request(url)
    return json.loads(content or '{}')

Get the userinfo associated with the given credentials.

This is dependent on the token having either the userinfo.email or
userinfo.profile scope for the given token.

Args:
credentials: (oauth2client.client.Credentials) incoming credentials
http: (httplib2.Http, optional) http instance to use

Returns:
The email address for this token, or None if the required scopes
aren't available.


def AddRoute(self, short_name, long_name, route_type, route_id=None):
    if (route_id is None):
        route_id = util.FindUniqueId(self.routes)
    route = self._gtfs_factory.Route(short_name=short_name, long_name=long_name, route_type=route_type, route_id=route_id)
    route.agency_id = self.GetDefaultAgency().agency_id
    self.AddRouteObject(route)
    return route

Add a route to this schedule.

Args:
short_name: Short name of the route, such as "71L"
long_name: Full name of the route, such as "NW 21st Ave/St Helens Rd"
route_type: A type such as "Tram", "Subway" or "Bus"
route_id: id of the route or None, in which case a unique id is picked
Returns:
A new Route object


def read_nanopubs(fn: str) -> Iterable[Mapping[str, Any]]:

    jsonl_flag, json_flag, yaml_flag = False, False, False
    if fn == "-" or "jsonl" in fn:
        jsonl_flag = True
    elif "json" in fn:
        json_flag = True
    elif re.search("ya?ml", fn):
        yaml_flag = True
    else:
        log.error("Do not recognize nanopub file format - neither json nor jsonl format.")
        return {}

    try:
        if re.search("gz$", fn):
            f = gzip.open(fn, "rt")
        else:
            try:
                f = click.open_file(fn, mode="rt")
            except Exception as e:
                log.info(f"Can not open file {fn}  Error: {e}")
                quit()

        if jsonl_flag:
            for line in f:
                yield json.loads(line)
        elif json_flag:
            nanopubs = json.load(f)
            for nanopub in nanopubs:
                yield nanopub
        elif yaml_flag:
            nanopubs = yaml.load(f, Loader=yaml.SafeLoader)
            for nanopub in nanopubs:
                yield nanopub

    except Exception as e:
        log.error(f"Could not open file: {fn}")

Read file and generate nanopubs

If filename has *.gz, will read as a gzip file
If filename has *.jsonl*, will parsed as a JSONLines file
IF filename has *.json*, will be parsed as a JSON file
If filename has *.yaml* or *.yml*,  will be parsed as a YAML file

Args:
filename (str): filename to read nanopubs from

Returns:
Generator[Mapping[str, Any]]: generator of nanopubs in nanopub_bel JSON Schema format


def training_loop_hparams_from_scoped_overrides(scoped_overrides, trial_id):
    trial_hp_overrides = scoped_overrides.values()
    loop_hp = create_loop_hparams()
    model_hp_name = trial_hp_overrides.get('loop.generative_model_params', loop_hp.generative_model_params)
    model_hp = registry.hparams(model_hp_name).parse(FLAGS.hparams)
    base_algo_params_name = trial_hp_overrides.get('loop.base_algo_params', loop_hp.base_algo_params)
    algo_hp = registry.hparams(base_algo_params_name)
    combined_hp = merge_unscoped_hparams(zip(HP_SCOPES, [loop_hp, model_hp, algo_hp]))
    combined_hp.override_from_dict(trial_hp_overrides)
    (loop_hp, model_hp, algo_hp) = split_scoped_hparams(HP_SCOPES, combined_hp)
    model_hp_name = ('model_hp_%s' % str(trial_id))
    dynamic_register_hparams(model_hp_name, model_hp)
    loop_hp.generative_model_params = model_hp_name
    algo_hp_name = ('algo_hp_%s' % str(trial_id))
    dynamic_register_hparams(algo_hp_name, algo_hp)
    loop_hp.base_algo_params = algo_hp_name
    return loop_hp

Create HParams suitable for training loop from scoped HParams.

Args:
scoped_overrides: HParams, with keys all scoped by one of HP_SCOPES. These
parameters are overrides for the base HParams created by
create_loop_hparams.
trial_id: str, trial identifier. This is used to register unique HParams
names for the underlying model and ppo HParams.

Returns:
HParams suitable for passing to training_loop.


def __deepcopy__(self, memo):
    with distribute_lib.enter_or_assert_strategy(self._distribute_strategy):
        new_values = []
        for value in self._values:
            with ops.device(value.device):
                new_values.append(copy.deepcopy(value, memo))
    copied_variable = type(self)(strategy=self._distribute_strategy, values=new_values, aggregation=self._aggregation, var_policy=copy.deepcopy(self._policy, memo))
    memo[id(self)] = copied_variable
    return copied_variable

Perform a deepcopy of the `DistributedVariable`.

Unlike the deepcopy of a regular tf.Variable, this keeps the original
strategy and devices of the `DistributedVariable`.  To avoid confusion
with the behavior of deepcopy on a regular `Variable` (which does
copy into new devices), we only allow a deepcopy of a `DistributedVariable`
within its originating strategy scope.

Args:
memo: The memoization object for `deepcopy`.

Returns:
A deep copy of the current `DistributedVariable`.

Raises:
RuntimeError: If trying to deepcopy into a different strategy.


def create_room(self, alias=None, is_public=False, invitees=None):

        response = self.api.create_room(alias=alias,
                                        is_public=is_public,
                                        invitees=invitees)
        return self._mkroom(response["room_id"])

Create a new room on the homeserver.

Args:
alias (str): The canonical_alias of the room.
is_public (bool):  The public/private visibility of the room.
invitees (str[]): A set of user ids to invite into the room.

Returns:
Room

Raises:
MatrixRequestError


def load_feature_lists(self, feature_lists):

        column_names = []
        feature_ranges = []
        running_feature_count = 0

        for list_id in feature_lists:
            feature_list_names = load_lines(self.features_dir + 'X_train_{}.names'.format(list_id))
            column_names.extend(feature_list_names)
            start_index = running_feature_count
            end_index = running_feature_count + len(feature_list_names) - 1
            running_feature_count += len(feature_list_names)
            feature_ranges.append([list_id, start_index, end_index])

        X_train = np.hstack([
            load(self.features_dir + 'X_train_{}.pickle'.format(list_id))
            for list_id in feature_lists
        ])
        X_test = np.hstack([
            load(self.features_dir + 'X_test_{}.pickle'.format(list_id))
            for list_id in feature_lists
        ])

        df_train = pd.DataFrame(X_train, columns=column_names)
        df_test = pd.DataFrame(X_test, columns=column_names)

        return df_train, df_test, feature_ranges

Load pickled features for train and test sets, assuming they are saved
in the `features` folder along with their column names.

Args:
feature_lists: A list containing the names of the feature lists to load.

Returns:
A tuple containing 3 items: train dataframe, test dataframe,
and a list describing the index ranges for the feature lists.


def foreach_loop(self, context):

        logger.debug("starting")

        foreach = context.get_formatted_iterable(self.foreach_items)

        foreach_length = len(foreach)

        logger.info(f"foreach decorator will loop {foreach_length} times.")

        for i in foreach:
            logger.info(f"foreach: running step {i}")

            context['i'] = i

            self.run_conditional_decorators(context)
            logger.debug(f"foreach: done step {i}")

        logger.debug(f"foreach decorator looped {foreach_length} times.")
        logger.debug("done")

Run step once for each item in foreach_items.

On each iteration, the invoked step can use context['i'] to get the
current iterator value.

Args:
context: (pypyr.context.Context) The pypyr context. This arg will
mutate.


def tryload(self, cfgstr=None, on_error='raise'):

        cfgstr = self._rectify_cfgstr(cfgstr)
        if self.enabled:
            try:
                if self.verbose > 1:
                    self.log('[cacher] tryload fname={}'.format(self.fname))
                return self.load(cfgstr)
            except IOError:
                if self.verbose > 0:
                    self.log('[cacher] ... {} cache miss'.format(self.fname))
            except Exception:
                if self.verbose > 0:
                    self.log('[cacher] ... failed to load')
                if on_error == 'raise':
                    raise
                elif on_error == 'clear':
                    self.clear(cfgstr)
                    return None
                else:
                    raise KeyError('Unknown method on_error={}'.format(on_error))
        else:
            if self.verbose > 1:
                self.log('[cacher] ... cache disabled: fname={}'.format(self.fname))
        return None

Like load, but returns None if the load fails due to a cache miss.

Args:
on_error (str): How to handle non-io errors errors. Either raise,
which re-raises the exception, or clear which deletes the cache
and returns None.


def GetPasswdMap(self, since=None):
    return PasswdUpdateGetter(self.conf).GetUpdates(source=self, search_base=self.conf['base'], search_filter=self.conf['filter'], search_scope=self.conf['scope'], since=since)

Return the passwd map from this source.

Args:
since: Get data only changed since this timestamp (inclusive) or None
for all data.

Returns:
instance of maps.PasswdMap


def get_kpoint_degeneracy(self, kpoint, cartesian=False, tol=1e-2):

        all_kpts = self.get_sym_eq_kpoints(kpoint, cartesian, tol=tol)
        if all_kpts is not None:
            return len(all_kpts)

Returns degeneracy of a given k-point based on structure symmetry
Args:
kpoint (1x3 array): coordinate of the k-point
cartesian (bool): kpoint is in cartesian or fractional coordinates
tol (float): tolerance below which coordinates are considered equal

Returns:
(int or None): degeneracy or None if structure is not available


def weights(self):
    return self._dedup_weights(self._undeduplicated_weights)

Returns the list of all layer variables/weights.

Note: This will not track the weights of nested `tf.Modules` that are not
themselves Keras layers.

Returns:
A list of variables.


def get_features_for_wav(self, wav_filename, model_settings, sess):
    desired_samples = model_settings['desired_samples']
    input_dict = {self.wav_filename_placeholder_: wav_filename, self.time_shift_padding_placeholder_: [[0, 0], [0, 0]], self.time_shift_offset_placeholder_: [0, 0], self.background_data_placeholder_: np.zeros([desired_samples, 1]), self.background_volume_placeholder_: 0, self.foreground_volume_placeholder_: 1}
    data_tensor = sess.run([self.output_], feed_dict=input_dict)
    return data_tensor

Applies the feature transformation process to the input_wav.

Runs the feature generation process (generally producing a spectrogram from
the input samples) on the WAV file. This can be useful for testing and
verifying implementations being run on other platforms.

Args:
wav_filename: The path to the input audio file.
model_settings: Information about the current model being trained.
sess: TensorFlow session that was active when processor was created.

Returns:
Numpy data array containing the generated features.


def price(self, market: pmd.ProcessedMarketData, name: Optional[str]=None) -> types.FloatTensor:
    name = name or self._name + '_price'
    with tf.name_scope(name):
        discount_curve = cashflow_streams.get_discount_curve(self._discount_curve_type, market, self._mask)
        reference_curve = cashflow_streams.get_discount_curve(self._reference_curve_type, market, self._reference_mask)
        daycount_fractions = tf.expand_dims(self._daycount_fractions, axis=-1)
        fwd_rate = reference_curve.forward_rate(self._accrual_start_date.expand_dims(axis=-1), self._accrual_end_date.expand_dims(axis=-1), day_count_fraction=daycount_fractions)
        discount_at_settlement = discount_curve.discount_factor(self._accrual_start_date.expand_dims(axis=-1))
        discount_at_settlement = tf.where(daycount_fractions > 0.0, discount_at_settlement, tf.zeros_like(discount_at_settlement))
        discount_at_settlement = tf.squeeze(discount_at_settlement, axis=-1)
        fwd_rate = tf.squeeze(fwd_rate, axis=-1)
        return self._short_position * discount_at_settlement * self._notional_amount * (fwd_rate - self._fixed_rate) * self._daycount_fractions / (1.0 + self._daycount_fractions * fwd_rate)

Returns the present value of the stream on the valuation date.

Args:
market: An instance of `ProcessedMarketData`.
name: Python str. The name to give to the ops created by this function.
Default value: `None` which maps to 'price'.

Returns:
A `Tensor` of shape `batch_shape`  containing the modeled price of each
FRA contract based on the input market data.


def _calc_dir_size(path):
    dir_size = 0
    for (root, dirs, files) in os.walk(path):
        for fn in files:
            full_fn = os.path.join(root, fn)
            dir_size += os.path.getsize(full_fn)
    return dir_size

Calculate size of all files in `path`.

Args:
path (str): Path to the directory.

Returns:
int: Size of the directory in bytes.


def delete_s3_bucket(client, resource):
    if dbconfig.get('enable_delete_s3_buckets', NS_AUDITOR_REQUIRED_TAGS, False):
        client.delete_bucket(Bucket=resource.id)
    return (ActionStatus.SUCCEED, resource.metrics())

Delete an S3 bucket

This function will try to delete an S3 bucket

Args:
client (:obj:`boto3.session.Session.client`): A boto3 client object
resource (:obj:`Resource`): The resource object to terminate

Returns:
`ActionStatus`


def _load_stdlib_versions(self):
    lines = self._store.load_stdlib_versions()
    versions = {}
    for line in lines:
        line2 = line.split('
        if not line2:
            continue
        match = re.fullmatch('(.+): (\\d)\\.(\\d+)(?:-(?:(\\d)\\.(\\d+))?)?', line2)
        assert match
        module, min_major, min_minor, max_major, max_minor = match.groups()
        minimum = (int(min_major), int(min_minor))
        maximum = (int(max_major), int(max_minor)) if max_major is not None and max_minor is not None else None
        versions[module] = (minimum, maximum)
    return versions

Loads the contents of typeshed/stdlib/VERSIONS.

VERSIONS lists the stdlib modules with the Python version in which they were
first added, in the format `{module}: {min_major}.{min_minor}-` or
`{module}: {min_major}.{min_minor}-{max_major}.{max_minor}`.

Returns:
A mapping from module name to version range in the format
{name: ((min_major, min_minor), (max_major, max_minor))}
The max tuple can be `None`.


def fetch_task_to_run(self):
    if all((task.is_completed for task in self)):
        raise StopIteration('All tasks completed.')
    for task in self:
        if task.can_run:
            return task
    logger.warning('Possible deadlock in fetch_task_to_run!')
    return None

Returns the first task that is ready to run or
None if no task can be submitted at present"

Raises:
`StopIteration` if all tasks are done.


def user_is_sponsor(self, user):
    sponsors = self.get_true_sponsors()
    for sponsor in sponsors:
        sp_user = sponsor.user
        if (sp_user == user):
            return True
    return False

Return whether the given user is a sponsor of the activity.

Returns:
Boolean


def _readable_flags(transport):
    if ('flags' not in transport):
        return None
    _flag_list = []
    flags = transport['flags']
    if (flags & dpkt.tcp.TH_SYN):
        if (flags & dpkt.tcp.TH_ACK):
            _flag_list.append('syn_ack')
        else:
            _flag_list.append('syn')
    elif (flags & dpkt.tcp.TH_FIN):
        if (flags & dpkt.tcp.TH_ACK):
            _flag_list.append('fin_ack')
        else:
            _flag_list.append('fin')
    elif (flags & dpkt.tcp.TH_RST):
        _flag_list.append('rst')
    elif (flags & dpkt.tcp.TH_PUSH):
        _flag_list.append('psh')
    return _flag_list

Method that turns bit flags into a human readable list

Args:
transport (dict): transport info, specifically needs a 'flags' key with bit_flags
Returns:
list: a list of human readable flags (e.g. ['syn_ack', 'fin', 'rst', ...]


def write(self, data, echo=None):

        if echo or (echo is None and self.echo):
            sys.stdout.write(data.decode('latin1'))
            sys.stdout.flush()
        self.channel.write(data)

Write data to channel.

Args:
data(bytes): The data to write to the channel.
echo(bool): Whether to echo the written data to stdout.

Raises:
EOFError: If the channel was closed before all data was sent.


def _refresh(self, http):

        if not self.store:
            self._do_refresh_request(http)
        else:
            self.store.acquire_lock()
            try:
                new_cred = self.store.locked_get()

                if (new_cred and not new_cred.invalid and
                        new_cred.access_token != self.access_token and
                        not new_cred.access_token_expired):
                    logger.info('Updated access_token read from Storage')
                    self._updateFromCredential(new_cred)
                else:
                    self._do_refresh_request(http)
            finally:
                self.store.release_lock()

Refreshes the access_token.

This method first checks by reading the Storage object if available.
If a refresh is still needed, it holds the Storage lock until the
refresh is completed.

Args:
http: an object to be used to make HTTP requests.

Raises:
HttpAccessTokenRefreshError: When the refresh fails.


def _request(self, method, resource_uri, **kwargs):

        data = kwargs.get('data')
        response = method(self.API_BASE_URL + resource_uri,
                          json=data, headers=self.headers)
        response.raise_for_status()
        return response.json()

Perform a method on a resource.

Args:
method: requests.`method`
resource_uri: resource endpoint
Raises:
HTTPError
Returns:
JSON Response


def yaml_to_ordered_dict(stream, loader=yaml.SafeLoader):

    class OrderedUniqueLoader(loader):
        '\n        Subclasses the given pyYAML `loader` class.\n\n        Validates all sibling keys to insure no duplicates.\n\n        Returns an OrderedDict instead of a Dict.\n        '
        NO_DUPE_SIBLINGS = ['stacks', 'class_path']
        NO_DUPE_CHILDREN = ['stacks']

        def _error_mapping_on_dupe(self, node, node_name):
            'check mapping node for dupe children keys.'
            if isinstance(node, MappingNode):
                mapping = {}
                for n in node.value:
                    a = n[0]
                    b = mapping.get(a.value, None)
                    if b:
                        msg = '{} mapping cannot have duplicate keys {} {}'
                        raise ConstructorError(msg.format(node_name, b.start_mark, a.start_mark))
                    mapping[a.value] = a

        def _validate_mapping(self, node, deep=False):
            if (not isinstance(node, MappingNode)):
                raise ConstructorError(None, None, ('expected a mapping node, but found %s' % node.id), node.start_mark)
            mapping = OrderedDict()
            for (key_node, value_node) in node.value:
                key = self.construct_object(key_node, deep=deep)
                try:
                    hash(key)
                except TypeError as exc:
                    raise ConstructorError('while constructing a mapping', node.start_mark, ('found unhashable key (%s)' % exc), key_node.start_mark)
                if ((key in mapping) and (key in self.NO_DUPE_SIBLINGS)):
                    msg = '{} key cannot have duplicate siblings {} {}'
                    raise ConstructorError(msg.format(key, node.start_mark, key_node.start_mark))
                if (key in self.NO_DUPE_CHILDREN):
                    self._error_mapping_on_dupe(value_node, key_node.value)
                value = self.construct_object(value_node, deep=deep)
                mapping[key] = value
            return mapping

        def construct_mapping(self, node, deep=False):
            'Override parent method to use OrderedDict.'
            if isinstance(node, MappingNode):
                self.flatten_mapping(node)
            return self._validate_mapping(node, deep=deep)

        def construct_yaml_map(self, node):
            data = OrderedDict()
            (yield data)
            value = self.construct_mapping(node)
            data.update(value)
    OrderedUniqueLoader.add_constructor(u'tag:yaml.org,2002:map', OrderedUniqueLoader.construct_yaml_map)
    return yaml.load(stream, OrderedUniqueLoader)

Provides yaml.load alternative with preserved dictionary order.

Args:
stream (string): YAML string to load.
loader (:class:`yaml.loader`): PyYAML loader class. Defaults to safe
load.

Returns:
OrderedDict: Parsed YAML.