def json_compat_obj_decode(data_type, obj, caller_permissions=None, alias_validators=None, strict=True, old_style=False, for_msgpack=False):
    decoder = PythonPrimitiveToStoneDecoder(caller_permissions, alias_validators, for_msgpack, old_style, strict)
    if isinstance(data_type, bv.Primitive):
        return decoder.make_stone_friendly(data_type, obj, True)
    else:
        return decoder.json_compat_obj_decode_helper(data_type, obj)

Decodes a JSON-compatible object based on its data type into a
representative Python object.

Args:
data_type (Validator): Validator for serialized_obj.
obj: The JSON-compatible object to decode based on data_type.
caller_permissions (list): The list of raw-string caller permissions
with which to serialize.
strict (bool): If strict, then unknown struct fields will raise an
error, and unknown union variants will raise an error even if a
catch all field is specified. See json_decode() for more.

Returns:
See json_decode().


def get_revision_sha(self, dest, rev):

        output = self.run_command(['show-ref', rev], cwd=dest,
                                  show_stdout=False, on_returncode='ignore')
        refs = {}
        for line in output.strip().splitlines():
            try:
                sha, ref = line.split()
            except ValueError:

                raise ValueError('unexpected show-ref line: {!r}'.format(line))

            refs[ref] = sha

        branch_ref = 'refs/remotes/origin/{}'.format(rev)
        tag_ref = 'refs/tags/{}'.format(rev)

        sha = refs.get(branch_ref)
        if sha is not None:
            return (sha, True)

        sha = refs.get(tag_ref)

        return (sha, False)

Return (sha_or_none, is_branch), where sha_or_none is a commit hash
if the revision names a remote branch or tag, otherwise None.

Args:
dest: the repository directory.
rev: the revision name.


def FixedUnPooling(x, shape, unpool_mat=None, data_format='channels_last'):

    data_format = get_data_format(data_format, keras_mode=False)
    shape = shape2d(shape)

    output_shape = StaticDynamicShape(x)
    output_shape.apply(1 if data_format == 'NHWC' else 2, lambda x: x * shape[0])
    output_shape.apply(2 if data_format == 'NHWC' else 3, lambda x: x * shape[1])

    if shape[0] == 2 and shape[1] == 2 and unpool_mat is None and data_format == 'NHWC':
        ret = UnPooling2x2ZeroFilled(x)
    else:

        if unpool_mat is None:
            mat = np.zeros(shape, dtype='float32')
            mat[0][0] = 1
            unpool_mat = tf.constant(mat, name='unpool_mat')
        elif isinstance(unpool_mat, np.ndarray):
            unpool_mat = tf.constant(unpool_mat, name='unpool_mat')
        assert unpool_mat.shape.as_list() == list(shape)

        if data_format == 'NHWC':
            x = tf.transpose(x, [0, 3, 1, 2])

        x = tf.expand_dims(x, -1)
        mat = tf.expand_dims(unpool_mat, 0)
        ret = tf.tensordot(x, mat, axes=1)

        if data_format == 'NHWC':
            ret = tf.transpose(ret, [0, 2, 4, 3, 5, 1])
        else:
            ret = tf.transpose(ret, [0, 1, 2, 4, 3, 5])

        shape3_dyn = [output_shape.get_dynamic(k) for k in range(1, 4)]
        ret = tf.reshape(ret, tf.stack([-1] + shape3_dyn))

    ret.set_shape(tf.TensorShape(output_shape.get_static()))
    return ret

Unpool the input with a fixed matrix to perform kronecker product with.

Args:
x (tf.Tensor): a 4D image tensor
shape: int or (h, w) tuple
unpool_mat: a tf.Tensor or np.ndarray 2D matrix with size=shape.
If is None, will use a matrix with 1 at top-left corner.

Returns:
tf.Tensor: a 4D image tensor.


def is_convertible_with(self, other):

        other = as_dimension(other)
        return self._value is None or other.value is None or self._value == other.value

Returns true if `other` is convertible with this Dimension.

Two known Dimensions are convertible if they have the same value.
An unknown Dimension is convertible with all other Dimensions.

Args:
other: Another Dimension.

Returns:
True if this Dimension and `other` are convertible.


def run_numerical_categorical_analysis(args, schema_list):

  header = [column['name'] for column in schema_list]
  input_files = file_io.get_matching_files(args.input_file_pattern)

  for col_schema in schema_list:
    col_type = col_schema['type'].lower()
    if col_type != 'string' and col_type != 'integer' and col_type != 'float':
      raise ValueError('Schema contains an unsupported type %s.' % col_type)

  def _init_numerical_results():
    return {'min': float('inf'),
            'max': float('-inf'),
            'count': 0,
            'sum': 0.0}
  numerical_results = collections.defaultdict(_init_numerical_results)
  categorical_results = collections.defaultdict(set)

  for input_file in input_files:
    with file_io.FileIO(input_file, 'r') as f:
      for line in f:
        parsed_line = dict(zip(header, line.strip().split(',')))

        for col_schema in schema_list:
          col_name = col_schema['name']
          col_type = col_schema['type']
          if col_type.lower() == 'string':
            categorical_results[col_name].update([parsed_line[col_name]])
          else:

            if not parsed_line[col_name].strip():
              continue

            numerical_results[col_name]['min'] = (
              min(numerical_results[col_name]['min'],
                  float(parsed_line[col_name])))
            numerical_results[col_name]['max'] = (
              max(numerical_results[col_name]['max'],
                  float(parsed_line[col_name])))
            numerical_results[col_name]['count'] += 1
            numerical_results[col_name]['sum'] += float(parsed_line[col_name])

  for col_schema in schema_list:
    if col_schema['type'].lower() != 'string':
      col_name = col_schema['name']
      mean = numerical_results[col_name]['sum'] / numerical_results[col_name]['count']
      del numerical_results[col_name]['sum']
      del numerical_results[col_name]['count']
      numerical_results[col_name]['mean'] = mean

  file_io.write_string_to_file(
      os.path.join(args.output_dir, NUMERICAL_ANALYSIS_FILE),
      json.dumps(numerical_results, indent=2, separators=(',', ': ')))

  for name, unique_labels in six.iteritems(categorical_results):
    labels = '\n'.join(list(unique_labels))
    file_io.write_string_to_file(
        os.path.join(args.output_dir, CATEGORICAL_ANALYSIS_FILE % name),
        labels)

Makes the numerical and categorical analysis files.

Args:
args: the command line args
schema_list: python object of the schema json file.

Raises:
ValueError: if schema contains unknown column types.


def user_picklist(i_info, command):
    valid_entry = False
    awsc.get_all_aminames(i_info)
    list_instances(i_info, '', True)
    msg_txt = 'Enter {0}
    while (not valid_entry):
        entry_raw = obtain_input(msg_txt)
        try:
            entry_int = int(entry_raw)
        except ValueError:
            entry_int = 999
        (tar_idx, valid_entry) = user_entry(entry_int, len(i_info), command)
    return tar_idx

Display list of instances matching args and ask user to select target.

Instance list displayed and user asked to enter the number corresponding
to the desired target instance, or '0' to abort.

Args:
i_info (dict): information on instances and details.
command (str): command specified on the command line.
Returns:
tar_idx (int): the dictionary index number of the targeted instance.


def clone(self, opts):
    topt = self.opts.copy()
    topt.update(opts)
    return self.__class__(self.modl, self.name, self.info, topt)

Create a new instance of this type with the specified options.

Args:
opts (dict): The type specific options for the new instance.


def merge_lists(*args):

    out = {}
    for contacts in filter(None, args):
        for contact in contacts:
            out[contact.value] = contact

    return list(out.values())

Merge an arbitrary number of lists into a single list and dedupe it

Args:
*args: Two or more lists

Returns:
A deduped merged list of all the provided lists as a single list


def get_dimension(self, dimension, default=None, strict=False):

        if dimension is not None and not isinstance(dimension, (int, basestring, Dimension)):
            raise TypeError('Dimension lookup supports int, string, '
                            'and Dimension instances, cannot lookup '
                            'Dimensions using %s type.' % type(dimension).__name__)
        all_dims = self.dimensions()
        if isinstance(dimension, int):
            if 0 <= dimension < len(all_dims):
                return all_dims[dimension]
            elif strict:
                raise KeyError("Dimension %r not found" % dimension)
            else:
                return default
        dimension = dimension_name(dimension)
        name_map = {dim.name: dim for dim in all_dims}
        name_map.update({dim.label: dim for dim in all_dims})
        name_map.update({util.dimension_sanitizer(dim.name): dim for dim in all_dims})
        if strict and dimension not in name_map:
            raise KeyError("Dimension %r not found." % dimension)
        else:
            return name_map.get(dimension, default)

Get a Dimension object by name or index.

Args:
dimension: Dimension to look up by name or integer index
default (optional): Value returned if Dimension not found
strict (bool, optional): Raise a KeyError if not found

Returns:
Dimension object for the requested dimension or default


def response(self):
    if isinstance(self.body, bytes):
        out = self.body
    elif isinstance(self.body, str):
        out = self.body.encode(self.charset)
    else:
        out = b''
    self.add_header('Content-Type', self.content_type)
    self.add_header('Content-Length', str(len(out)))
    self.start(self.status_line, self._headers)
    return [out]

Return the HTTP response body.

Returns:
bytes: HTTP response body as a sequence of bytes


def read_from_hdx(identifier, configuration=None):
    user = User(configuration=configuration)
    result = user._load_from_hdx('user', identifier)
    if result:
        return user
    return None

Reads the user given by identifier from HDX and returns User object

Args:
identifier (str): Identifier of user
configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration.

Returns:
Optional[User]: User object if successful read, None if not


def chosen_angle_to_canonical_half_turns(
        half_turns: Optional[Union[sympy.Basic, float]] = None,
        rads: Optional[float] = None,
        degs: Optional[float] = None,
        default: float = 1.0,
) -> Union[sympy.Basic, float]:

    return canonicalize_half_turns(
            chosen_angle_to_half_turns(
                half_turns=half_turns,
                rads=rads,
                degs=degs,
                default=default))

Returns a canonicalized half_turns based on the given arguments.

At most one of half_turns, rads, degs must be specified. If none are
specified, the output defaults to half_turns=1.

Args:
half_turns: The number of half turns to rotate by.
rads: The number of radians to rotate by.
degs: The number of degrees to rotate by
default: The half turns angle to use if nothing else is specified.

Returns:
A number of half turns.


def _initialise(self, initial_state: str='unknown') -> dict:
    initial_state = initial_state.lower()
    if ((initial_state != 'unknown') and (initial_state not in self._allowed_states)):
        raise ValueError('Invalid initial state: {}'.format(initial_state))
    _initial_state = dict(current_state=initial_state, target_state=initial_state, current_timestamp=datetime.utcnow().isoformat(), target_timestamp=datetime.utcnow().isoformat())
    return _initial_state

Return a dictionary used to initialise a state object.

This method is used to obtain a dictionary/hash describing the initial
state of SDP or a service in SDP.

Args:
initial_state (str): Initial state.

Returns:
dict, Initial state configuration


def dense_relu_dense(x, hidden_channels, dropout=0.0, dropout_broadcast_dims=None, master_dtype=tf.float32, slice_dtype=tf.float32, name=None):
    with tf.variable_scope(name, default_name='dense_relu_dense'):
        io_channels = x.shape.dims[(- 1)]
        h = dense(x, hidden_channels, use_bias=False, activation=mtf.relu, master_dtype=master_dtype, slice_dtype=slice_dtype, name='wi')
        if (dropout != 0.0):
            h = mtf.dropout(h, (1.0 - dropout), noise_shape=(h.shape - dropout_broadcast_dims))
        return dense(h, io_channels, use_bias=False, activation=None, master_dtype=master_dtype, slice_dtype=slice_dtype, name='wo')

Hidden layer with ReLU activation followed by linear projection.

The output has the same number of channels as the input.

Args:
x: a mtf.Tensor
hidden_channels: a mtf.Dimension - channels in the hidden layer
dropout: an optional float
dropout_broadcast_dims: an optional list of mtf.Dimension
master_dtype: a tf.dtype
slice_dtype: a tf.dtype
name: an optional string

Returns:
a mtf.Tensor with the same shape as x.


def add_filter(self, package_filter):

        filters = self.filters + [package_filter]
        self.filters = sorted(filters, key=lambda x: x.cost)

Add a filter to the list.

Args:
package_filter (`PackageFilter`): Filter to add.


def _get_musts(options):

    if options.version == '2.0':
        return musts20.list_musts(options)
    else:
        return musts21.list_musts(options)

Return the list of 'MUST' validators for the correct version of STIX.

Args:
options: ValidationOptions instance with validation options for this
validation run, including the STIX spec version.


def _RegisterKeyFlagForModule(self, module_name, flag):

    key_flags_by_module = self.KeyFlagsByModuleDict()

    key_flags = key_flags_by_module.setdefault(module_name, [])

    if flag not in key_flags:
      key_flags.append(flag)

Specifies that a flag is a key flag for a module.

Args:
module_name: A string, the name of a Python module.
flag: A Flag object, a flag that is key to the module.


def run_inference(self, batch: Sequence[numpy.ndarray], model: tf.Module, inference_args: Optional[dict[str, Any]]=None) -> Iterable[PredictionResult]:
    inference_args = {} if not inference_args else inference_args
    return self._inference_fn(model, batch, inference_args, self._model_uri)

Runs inferences on a batch of numpy array and returns an Iterable of
numpy array Predictions.

This method stacks the n-dimensional numpy array in a vectorized format to
optimize the inference call.

Args:
batch: A sequence of numpy nd-array. These should be batchable, as this
method will call `numpy.stack()` and pass in batched numpy nd-array
with dimensions (batch_size, n_features, etc.) into the model's
predict() function.
model: A Tensorflow model.
inference_args: any additional arguments for an inference.

Returns:
An Iterable of type PredictionResult.


def add_update_resource(self, resource, ignore_datasetid=False):

        resource = self._get_resource_from_obj(resource)
        if 'package_id' in resource:
            if not ignore_datasetid:
                raise HDXError('Resource %s being added already has a dataset id!' % (resource['name']))
        resource.check_url_filetoupload()
        resource_updated = self._addupdate_hdxobject(self.resources, 'name', resource)
        if resource.get_file_to_upload():
            resource_updated.set_file_to_upload(resource.get_file_to_upload())

Add new or update existing resource in dataset with new metadata

Args:
resource (Union[hdx.data.resource.Resource,Dict,str]): Either resource id or resource metadata from a Resource object or a dictionary
ignore_datasetid (bool): Whether to ignore dataset id in the resource

Returns:
None


def lbest_idx(state, idx):
    swarm = state.swarm
    n_s = state.params['n_s']
    cmp = comparator(swarm[0].best_fitness)
    indices = __lbest_indices__(len(swarm), n_s, idx)
    best = None
    for i in indices:
        if ((best is None) or cmp(swarm[i].best_fitness, swarm[best].best_fitness)):
            best = i
    return best

lbest Neighbourhood topology function.

Neighbourhood size is determined by state.params['n_s'].

Args:
state: cipy.algorithms.pso.State: The state of the PSO algorithm.
idx: int: index of the particle in the swarm.

Returns:
int: The index of the lbest particle.


def sample_to(self, count, skip_header_rows, strategy, target):
    if (sys.version_info.major > 2):
        xrange = range
    if (strategy == 'BIGQUERY'):
        import datalab.bigquery as bq
        if (not self.path.startswith('gs:
            raise Exception('Cannot use BIGQUERY if data is not in GCS')
        federated_table = self._create_federated_table(skip_header_rows)
        row_count = self._get_gcs_csv_row_count(federated_table)
        query = bq.Query('SELECT * from data', data_sources={'data': federated_table})
        sampling = bq.Sampling.random(((count * 100) / float(row_count)))
        sample = query.sample(sampling=sampling)
        df = sample.to_dataframe()
    elif (strategy == 'LOCAL'):
        local_file = self.path
        if self.path.startswith('gs:
            local_file = tempfile.mktemp()
            datalab.utils.gcs_copy_file(self.path, local_file)
        with open(local_file) as f:
            row_count = sum((1 for line in f))
        start_row = (1 if (skip_header_rows is True) else 0)
        skip_count = (((row_count - count) - 1) if (skip_header_rows is True) else (row_count - count))
        skip = sorted(random.sample(xrange(start_row, row_count), skip_count))
        header_row = (0 if (skip_header_rows is True) else None)
        df = pd.read_csv(local_file, skiprows=skip, header=header_row, delimiter=self._delimiter)
        if self.path.startswith('gs:
            os.remove(local_file)
    else:
        raise Exception('strategy must be BIGQUERY or LOCAL')
    if target.startswith('gs:
        with tempfile.NamedTemporaryFile() as f:
            df.to_csv(f, header=False, index=False)
            f.flush()
            datalab.utils.gcs_copy_file(f.name, target)
    else:
        with open(target, 'w') as f:
            df.to_csv(f, header=False, index=False, sep=str(self._delimiter))

Sample rows from GCS or local file and save results to target file.

Args:
count: number of rows to sample. If strategy is "BIGQUERY", it is used as approximate number.
skip_header_rows: whether to skip first row when reading from source.
strategy: can be "LOCAL" or "BIGQUERY". If local, the sampling happens in local memory,
and number of resulting rows matches count. If BigQuery, sampling is done
with BigQuery in cloud, and the number of resulting rows will be approximated to
count.
target: The target file path, can be GCS or local path.
Raises:
Exception if strategy is "BIGQUERY" but source is not a GCS path.


def __setattr__(self, name, value):

        if name.startswith("_"):
            super(HasProps, self).__setattr__(name, value)
            return

        props = sorted(self.properties())
        descriptor = getattr(self.__class__, name, None)

        if name in props or (descriptor is not None and descriptor.fset is not None):
            super(HasProps, self).__setattr__(name, value)
        else:
            matches, text = difflib.get_close_matches(name.lower(), props), "similar"

            if not matches:
                matches, text = props, "possible"

            raise AttributeError("unexpected attribute '%s' to %s, %s attributes are %s" %
                (name, self.__class__.__name__, text, nice_join(matches)))

Intercept attribute setting on HasProps in order to special case
a few situations:

* short circuit all property machinery for ``_private`` attributes
* suggest similar attribute names on attribute errors

Args:
name (str) : the name of the attribute to set on this object
value (obj) : the value to set

Returns:
None


def remove_context(self, name):
    self._context(name)
    del self.contexts[name]
    self._flush_tools()

Remove a context from the suite.

Args:
name (str): Name of the context to remove.


def breakpoints(self):
    return self._breakpoints

Get a set of the currently-activated breakpoints.

Returns:
A `set` of 3-tuples: (node_name, output_slot, debug_op), e.g.,
{("MatMul", 0, "DebugIdentity")}.


def unique(self):
    all_rx = set([iv.primary for iv in self])
    table = {r: 0 for r in all_rx}
    for iv in self:
        table[iv.primary] += iv.thickness
    return sorted(table.items(), key=operator.itemgetter(1), reverse=True)

Property. Summarize a Striplog with some statistics.

Returns:
List. A list of (Component, total thickness thickness) tuples.


def persist_upstream_diagram(self, filepath):

        assert isinstance(filepath, str),\
            'Step {} error, filepath must be str. Got {} instead'.format(self.name, type(filepath))
        persist_as_png(self.upstream_structure, filepath)

Creates upstream steps diagram and persists it to disk as png file.

Pydot graph is created and persisted to disk as png file under the filepath directory.

Args:
filepath (str): filepath to which the png with steps visualization should
be persisted


def index(self, connection, partition, columns):

        query_tmpl = 'CREATE INDEX ON {table_name} ({column});'
        table_name = '{}_v'.format(partition.vid)
        for column in columns:
            query = query_tmpl.format(table_name=table_name, column=column)
            logger.debug('Creating postgres index.\n    column: {}, query: {}'.format(column, query))
            with connection.cursor() as cursor:
                cursor.execute(query)
                cursor.execute('COMMIT;')

Create an index on the columns.

Args:
connection:
partition (orm.Partition):
columns (list of str):


def gen_support_records(transaction_manager, min_support, **kwargs):

    max_length = kwargs.get('max_length')

    _create_next_candidates = kwargs.get(
        '_create_next_candidates', create_next_candidates)

    candidates = transaction_manager.initial_candidates()
    length = 1
    while candidates:
        relations = set()
        for relation_candidate in candidates:
            support = transaction_manager.calc_support(relation_candidate)
            if support < min_support:
                continue
            candidate_set = frozenset(relation_candidate)
            relations.add(candidate_set)
            yield SupportRecord(candidate_set, support)
        length += 1
        if max_length and length > max_length:
            break
        candidates = _create_next_candidates(relations, length)

Returns a generator of support records with given transactions.

Arguments:
transaction_manager -- Transactions as a TransactionManager instance.
min_support -- A minimum support (float).

Keyword arguments:
max_length -- The maximum length of relations (integer).


def mark_parent_tasks_as_failed(self, task_name, flush_logs=False):
    for existing_task_name in self.tasks:
        if (existing_task_name == task_name):
            break
        if flush_logs:
            self.tasks[existing_task_name].clear()
        self.tasks[existing_task_name].failed = True
    self.mark_main_tasks_as_failed()

Marks all the parent tasks as failed

Args:
task_name (str): Name of the child task
flush_logs (bool): If ``True`` will discard all the logs form
parent tasks

Returns:
None


def unpack(self, buff, offset=0):

        unpack_length = UBInt16()
        unpack_length.unpack(buff, offset)
        super().unpack(buff[:offset+unpack_length], offset)

Unpack a binary message into this object's attributes.

Pass the correct length for list unpacking.

Args:
buff (bytes): Binary data package to be unpacked.
offset (int): Where to begin unpacking.


def load_graph(self, graph, tags, import_scope=None, **saver_kwargs):
    meta_graph_def = self.get_meta_graph_def_from_tags(tags)
    if sys.byteorder == 'big':
        saved_model_utils.swap_function_tensor_content(meta_graph_def, 'little', 'big')
    with graph.as_default():
        return tf_saver._import_meta_graph_with_return_elements(meta_graph_def, import_scope=import_scope, **saver_kwargs)

Load ops and nodes from SavedModel MetaGraph into graph.

Args:
graph: tf.Graph object.
tags: a set of string tags identifying a MetaGraphDef.
import_scope: Optional `string` -- if specified, prepend this string
followed by '/' to all loaded tensor names. This scope is applied to
tensor instances loaded into the passed session, but it is *not* written
through to the static `MetaGraphDef` protocol buffer that is returned.
**saver_kwargs: keyword arguments to pass to tf.train.import_meta_graph.

Returns:
A tuple of
* Saver defined by the MetaGraph, which can be used to restore the
variable values.
* List of `Operation`/`Tensor` objects returned from
`tf.import_graph_def` (may be `None`).


def trace_save_restore_function_map(obj, factory_data_list):
    saveable_fns = {}
    for factory_data in factory_data_list:
        saveable_factory = factory_data.factory
        attribute_name = factory_data.name
        if resource_variable_ops.is_resource_variable(obj) or resource_variable_ops.is_resource_variable(saveable_factory) or (not callable(saveable_factory)):
            continue
        concrete_save, concrete_restore = _trace_save_restore_functions(saveable_factory, obj)
        if not concrete_save:
            continue
        saveable_fns[attribute_name] = (concrete_save, concrete_restore)
    return saveable_fns

Traces all save and restore functions in the provided factory list.

Args:
obj: `Trackable` object.
factory_data_list: List of `_CheckpointFactoryData`.

Returns:
Dict mapping atttribute names to tuples of concrete save/restore functions.


def get_position(fallback=CURSOR_POS_FALLBACK):
    values = fallback
    if is_a_tty():
        import tty, termios
        try:
            with TermStack() as fd:
                tty.setcbreak(fd, termios.TCSANOW)
                sys.stdout.write((CSI + '6n'))
                sys.stdout.flush()
                resp = _read_until(maxchars=10, end='R')
        except AttributeError:
            return values
        resp = resp.lstrip(CSI)
        try:
            values = tuple((int(token) for token in resp.partition(';')[::(- 2)]))
        except Exception as err:
            log.error('parse error: %s on %r', err, resp)
    return values

Return the current column number of the terminal cursor.
Used to figure out if we need to print an extra newline.

Returns:
tuple(int): (x, y), (,)  - empty, if an error occurred.

TODO: needs non-ansi mode for Windows
Note:
Checks is_a_tty() first, since function would block if i/o were
redirected through a pipe.


def constants_from_enum(cls, module=None):

  if not issubclass(cls, enum.Enum):
    raise TypeError("Class '{}' is not subclass of enum.".format(cls.__name__))

  if module is None:
    module = cls.__module__
  for value in cls:
    constant('{}.{}'.format(module, str(value)), value)
  return cls

Decorator for an enum class that generates Gin constants from values.

Generated constants have format `module.ClassName.ENUM_VALUE`. The module
name is optional when using the constant.

Args:
cls: Class type.
module: The module to associate with the constants, to help handle naming
collisions. If `None`, `cls.__module__` will be used.

Returns:
Class type (identity function).

Raises:
TypeError: When applied to a non-enum class.


def remove_keywords_from_list(self, keyword_list):

        if not isinstance(keyword_list, list):
                raise AttributeError("keyword_list should be a list")

        for keyword in keyword_list:
            self.remove_keyword(keyword)

To remove keywords present in list

Args:
keyword_list (list(str)): List of keywords to remove

Examples:
>>> keyword_processor.remove_keywords_from_list(["java", "python"]})
Raises:
AttributeError: If `keyword_list` is not a list.


def MsgUser(msg):

  msg_tested_versions = ['xp', 'vista', '2008', '2003']
  msg_args = ['/c', '%SystemRoot%\\System32\\msg.exe', '*', '/TIME:0']
  host_version = platform.platform().lower()
  if not msg:
    return ('Command not ran.', 'Empty message.', -1)
  else:
    msg_args.extend([msg])
  for version in msg_tested_versions:
    if host_version.find(version) != -1:

      res = client_utils_common.Execute(
          'cmd', msg_args, time_limit=-1, bypass_whitelist=True)
      return res
  return ('', 'Command not available for this version.', -1)

Sends a message to a user.

Args:
msg: Message to be displaied to user.

Returns:
res which is a tuple of (stdout, stderr, exit_status, time_taken).


def random_masking(self, pixel_values: torch.FloatTensor, noise: Optional[torch.FloatTensor]=None) -> Tuple[torch.BoolTensor, torch.LongTensor]:
    batch_size = pixel_values.shape[0]
    num_windows = math.prod(self.mask_spatial_shape)
    len_keep = int(num_windows * (1 - self.mask_ratio))
    if noise is None:
        noise = torch.rand(batch_size, num_windows, device=pixel_values.device)
    ids_shuffle = torch.argsort(noise, dim=1)
    ids_restore = torch.argsort(ids_shuffle, dim=1).to(pixel_values.device)
    bool_masked_pos = torch.zeros([batch_size, num_windows], device=pixel_values.device)
    bool_masked_pos[:, :len_keep] = 1
    bool_masked_pos = torch.gather(bool_masked_pos, dim=1, index=ids_restore).bool()
    return (bool_masked_pos, ids_restore)

Perform per-sample random masking by per-sample shuffling. Per-sample shuffling is done by argsort random
noise.

Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`)
noise (`torch.FloatTensor` of shape `(batch_size, num_mask_units)`, *optional*) which is
mainly used for testing purposes to control randomness and maintain the reproducibility


def is_generic_list(type_: Type) -> bool:

    if hasattr(typing, '_GenericAlias'):

        return (isinstance(type_, typing._GenericAlias) and
                type_.__origin__ is list)
    else:

        return (isinstance(type_, typing.GenericMeta) and
                type_.__origin__ is List)

Determines whether a type is a List[...].

How to do this varies for different Python versions, due to the
typing library not having a stable API. This functions smooths
over the differences.

Args:
type_: The type to check.

Returns:
True iff it's a List[...something...].


def words(self, batch_index: int=0) -> List[Optional[int]]:
    if not self._encodings:
        raise ValueError('words() is not available when using non-fast tokenizers (e.g. instance of a `XxxTokenizerFast` class).')
    warnings.warn('`BatchEncoding.words()` property is deprecated and should be replaced with the identical, but more self-explanatory `BatchEncoding.word_ids()` property.', FutureWarning)
    return self.word_ids(batch_index)

Return a list mapping the tokens to their actual word in the initial sentence for a fast tokenizer.

Args:
batch_index (`int`, *optional*, defaults to 0): The index to access in the batch.

Returns:
`List[Optional[int]]`: A list indicating the word corresponding to each token. Special tokens added by the
tokenizer are mapped to `None` and other tokens are mapped to the index of their corresponding word
(several tokens will be mapped to the same word index if they are parts of that word).


def create_ref(profile, ref, sha):

    resource = "/refs"
    payload = {"ref": "refs/" + ref, "sha": sha}
    data = api.post_request(profile, resource, payload)
    return prepare(data)

Create a ref.

Args:

profile
A profile generated from ``simplygithub.authentication.profile``.
Such profiles tell this module (i) the ``repo`` to connect to,
and (ii) the ``token`` to connect with.

ref
The ref to create, e.g., ``heads/my-feature-branch``.

sha
The SHA of the commit to point the ref to.

Returns
A dict with data about the ref.


def is_attribute_multivalued(self, attribute):

        rule_set = self._attribute_rule_sets.get(attribute)
        return rule_set.multiple_instances_permitted

Check if the attribute is allowed to have multiple instances.

Args:
attribute (string): The name of the attribute
(e.g., 'State'). Required.


def concat(lists):

    return lists[0].new(
        pd.concat([lists.data for lists in lists]).drop_duplicates()
    )

类似于pd.concat 用于合并一个list里面的多个DataStruct,会自动去重

Arguments:
lists {[type]} -- [DataStruct1,DataStruct2,....,DataStructN]

Returns:
[type] -- new DataStruct


def camel_case_split(identifier: str) -> List[str]:
    matches = re.finditer('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)', identifier)
    return [m.group(0) for m in matches]

Split a camel-cased name into words.

Args:
identifier (`str`): The camel-cased name to parse.

Returns:
`List[str]`: The list of words in the identifier (as separated by capital letters).

Example:

```py
>>> camel_case_split("CamelCasedClass")
["Camel", "Cased", "Class"]
```


def common_shape(*args: Sequence[tf.Tensor], name: Optional[str]=None) -> Union[tf.TensorShape, tf.Tensor]:
    name = 'common_shape' if name is None else name
    with tf.name_scope(name):
        is_fully_defined = True
        if args:
            for arg in args:
                arg = tf.convert_to_tensor(arg)
                is_fully_defined &= arg.shape.is_fully_defined()
            if is_fully_defined:
                output_shape = args[0].shape
                for arg in args[1:]:
                    try:
                        output_shape = tf.broadcast_static_shape(output_shape, arg.shape)
                    except ValueError:
                        raise ValueError(f'Shapes of {args} are incompatible')
                return output_shape
            output_shape = tf.shape(args[0])
            for arg in args[1:]:
                output_shape = tf.broadcast_dynamic_shape(output_shape, tf.shape(arg))
            return output_shape

Returns common shape for a sequence of Tensors.

The common shape is the smallest-rank shape to which all tensors are
broadcastable.

#### Example
```python
import tensorflow as tf
import tf_quant_finance as tff

args = [tf.ones([1, 2], dtype=tf.float64), tf.constant([[True], [False]])]
tff.utils.common_shape(*args)
# Expected: [2, 2]
```

Args:
*args: A sequence of `Tensor`s of compatible shapes and any `dtype`s.
name: Python string. The name to give to the ops created by this function.
Default value: `None` which maps to the default name
`broadcast_tensor_shapes`.

Returns:
A common shape for the input `Tensor`s, which an instance of TensorShape,
if the input shapes are fully defined, or a `Tensor` for dynamically shaped
inputs.

Raises:
ValueError: If inputs are of incompatible shapes.


def _StartProfiling(self, configuration):

    if not configuration:
      return

    if configuration.HaveProfileMemoryGuppy():
      self._guppy_memory_profiler = profilers.GuppyMemoryProfiler(
          self._name, configuration)
      self._guppy_memory_profiler.Start()

    if configuration.HaveProfileMemory():
      self._memory_profiler = profilers.MemoryProfiler(
          self._name, configuration)
      self._memory_profiler.Start()

    if configuration.HaveProfileProcessing():
      identifier = '{0:s}-processing'.format(self._name)
      self._processing_profiler = profilers.ProcessingProfiler(
          identifier, configuration)
      self._processing_profiler.Start()

    if configuration.HaveProfileSerializers():
      identifier = '{0:s}-serializers'.format(self._name)
      self._serializers_profiler = profilers.SerializersProfiler(
          identifier, configuration)
      self._serializers_profiler.Start()

    if configuration.HaveProfileStorage():
      self._storage_profiler = profilers.StorageProfiler(
          self._name, configuration)
      self._storage_profiler.Start()

    if configuration.HaveProfileTasks():
      self._tasks_profiler = profilers.TasksProfiler(self._name, configuration)
      self._tasks_profiler.Start()

Starts profiling.

Args:
configuration (ProfilingConfiguration): profiling configuration.


def has_channel(val: Any) -> bool:
    channel_getter = getattr(val, '_has_channel_', None)
    result = (NotImplemented if (channel_getter is None) else channel_getter())
    if (result is not NotImplemented):
        return result
    result = has_mixture_channel(val)
    if ((result is not NotImplemented) and result):
        return result
    return (channel(val, None) is not None)

Returns whether the value has a channel representation.

Returns:
If `val` has a `_has_channel_` method and its result is not
NotImplemented, that result is returned. Otherwise, if `val` has a
`_has_mixture_` method and its result is not NotImplemented, that
result is returned. Otherwise if `val` has a `_has_unitary_` method
and its results is not NotImplemented, that result is returned.
Otherwise, if the value has a _channel_ method return if that
has a non-default value. Returns False if none of these functions
exists.


def __init__(self, credential_type=None, credential_value=None):

        super(Credential, self).__init__(tag=Tags.CREDENTIAL)

        self._credential_type = None
        self._credential_value = None

        self.credential_type = credential_type
        self.credential_value = credential_value

Construct a Credential struct.

Args:
credential_type (CredentialType): An enumeration value that
specifies the type of the credential struct. Optional,
defaults to None. Required for encoding and decoding.
credential_value (CredentialValue): The credential value
corresponding to the credential type. Optional, defaults to
None. Required for encoding and decoding.


def stateless_random_flip_left_right(image, seed):
    random_func = functools.partial(stateless_random_ops.stateless_random_uniform, seed=seed)
    return _random_flip(image, 1, random_func, 'stateless_random_flip_left_right')

Randomly flip an image horizontally (left to right) deterministically.

Guarantees the same results given the same `seed` independent of how many
times the function is called, and independent of global seed settings (e.g.
`tf.random.set_seed`).

Example usage:

>>> image = np.array([[[1], [2]], [[3], [4]]])
>>> seed = (2, 3)
>>> tf.image.stateless_random_flip_left_right(image, seed).numpy().tolist()
[[[2], [1]], [[4], [3]]]

Args:
image: 4-D Tensor of shape `[batch, height, width, channels]` or 3-D Tensor
of shape `[height, width, channels]`.
seed: A shape [2] Tensor, the seed to the random number generator. Must have
dtype `int32` or `int64`. (When using XLA, only `int32` is allowed.)

Returns:
A tensor of the same type and shape as `image`.


def group_modes(modes):
    if (len(modes) > 0):
        previous = modes[0]
        grouped = []
        for changep in modes[1:]:
            if (changep['label'] != previous['label']):
                previous['to'] = changep['from']
                grouped.append(previous)
                previous = changep
        previous['to'] = modes[(- 1)]['to']
        grouped.append(previous)
        return grouped
    else:
        return modes

Groups consecutive transportation modes with same label, into one

Args:
modes (:obj:`list` of :obj:`dict`)
Returns:
:obj:`list` of :obj:`dict`


def watch_statuses(self, observer, batch_ids):
    with self._lock:
        statuses = self.get_statuses(batch_ids)
        if self._has_no_pendings(statuses):
            observer.notify_batches_finished(statuses)
        else:
            self._observers[observer] = statuses

Allows a component to register to be notified when a set of
batches is no longer PENDING. Expects to be able to call the
"notify_batches_finished" method on the registered component, sending
the statuses of the batches.

Args:
observer (object): Must implement "notify_batches_finished" method
batch_ids (list of str): The ids of the batches to watch


def seat_button_count(self):
    if (self.type != EventType.POINTER_BUTTON):
        raise AttributeError(_wrong_prop.format(self.type))
    return self._libinput.libinput_event_pointer_get_seat_button_count(self._handle)

The total number of buttons pressed on all devices on the
associated seat after the event was triggered.

For pointer events that are not of type
:attr:`~libinput.constant.EventType.POINTER_BUTTON`, this property
raises :exc:`AssertionError`.

Returns:
int: The seat wide pressed button count for the key of this event.
Raises:
AssertionError


def loads(s, model):
    graphs = penman.loads(s, cls=XMRSCodec)
    xs = [model.from_triples(g.triples()) for g in graphs]
    return xs

Deserialize PENMAN graphs from a string

Args:
s (str): serialized PENMAN graphs
model: Xmrs subclass instantiated from decoded triples
Returns:
a list of objects (of class *model*)


def _add_capitalization_constrain(token_lst: List[Dict], capi_lst: List, word_lst: List) -> List[Dict]:

        result = []
        for a_token in token_lst:
            if "exact" in capi_lst and word_lst != []:
                for word in word_lst:
                    token = copy.deepcopy(a_token)
                    token[attrs.ORTH] = word
                    result.append(token)
            if "lower" in capi_lst:
                token = copy.deepcopy(a_token)
                token[attrs.IS_LOWER] = True
                result.append(token)
            if "upper" in capi_lst:
                token = copy.deepcopy(a_token)
                token[attrs.IS_UPPER] = True
                result.append(token)
            if "title" in capi_lst:
                token = copy.deepcopy(a_token)
                token[attrs.IS_TITLE] = True
                result.append(token)
            if "mixed" in capi_lst:
                token = copy.deepcopy(a_token)
                token[attrs.IS_UPPER] = False
                token[attrs.IS_LOWER] = False
                token[attrs.IS_TITLE] = False
                result.append(token)
        return result

Add capitalization constrain for some token type, create cross production
Args:
token_lst: List[Dict]
capi_lst: List
word_lst: List

Returns: List[Dict]


def get_lb_nat_rule(access_token, subscription_id, resource_group, lb_name, rule_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Network/loadBalancers/', lb_name,
                        '/inboundNatRules/', rule_name,
                        '?api-version=', NETWORK_API])
    return do_get(endpoint, access_token)

Get details about a load balancer inbound NAT rule.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
lb_name (str): Name of the load balancer.
rule_name (str): Name of the NAT rule.

Returns:
HTTP response. JSON body of rule.


def _get_tensor_name(node_name, output_slot):
    return '%s:%d' % (node_name, output_slot)

Get tensor name given node name and output slot index.

Args:
node_name: Name of the node that outputs the tensor, as a string.
output_slot: Output slot index of the tensor, as an integer.

Returns:
Name of the tensor, as a string.


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

Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it returns `google.rpc.Code.UNIMPLEMENTED`. Clients can use Operations.GetOperation or other methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an Operation.error value with a google.rpc.Status.code of 1, corresponding to `Code.CANCELLED`.

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


def build_batch(cls, size, **kwargs):

        return [cls.build(**kwargs) for _ in range(size)]

Build a batch of instances of the given class, with overriden attrs.

Args:
size (int): the number of instances to build

Returns:
object list: the built instances


def sample_ogrid(self, ogrid: np.array) -> np.array:
    if (len(ogrid) != self.dimensions):
        raise ValueError(('len(ogrid) must equal self.dimensions, %r != %r' % (len(ogrid), self.dimensions)))
    ogrids = [np.ascontiguousarray(array, np.float32) for array in ogrid]
    out = np.ndarray([array.size for array in ogrids], np.float32)
    lib.NoiseSampleOpenMeshGrid(self._tdl_noise_c, len(ogrids), out.shape, [ffi.cast('float*', array.ctypes.data) for array in ogrids], ffi.cast('float*', out.ctypes.data))
    return out

Sample an open mesh-grid array and return the result.

Args
ogrid (Sequence[Sequence[float]]): An open mesh-grid.

Returns:
numpy.ndarray: An array of sampled points.

The ``shape`` is based on the lengths of the open mesh-grid
arrays.
The ``dtype`` is `numpy.float32`.


def maybe_base_expanded_node_name(self, node_name):
    with self._node_name_lock:
        if (self._maybe_base_expanded_node_names is None):
            self._maybe_base_expanded_node_names = dict()
            sorted_names = sorted((node.name for node in self._graph_def.node))
            for (i, name) in enumerate(sorted_names):
                j = (i + 1)
                while ((j < len(sorted_names)) and sorted_names[j].startswith(name)):
                    if sorted_names[j].startswith((name + '/')):
                        self._maybe_base_expanded_node_names[name] = (((name + '/(') + name.split('/')[(- 1)]) + ')')
                        break
                    j += 1
        return self._maybe_base_expanded_node_names.get(node_name, node_name)

Expand the base name if there are node names nested under the node.

For example, if there are two nodes in the graph, "a" and "a/read", then
calling this function on "a" will give "a/(a)", a form that points at
a leaf node in the nested TensorBoard graph. Calling this function on
"a/read" will just return "a/read", because there is no node nested under
it.

This method is thread-safe.

Args:
node_name: Name of the node.
graph_def: The `GraphDef` that the node is a part of.

Returns:
Possibly base-expanded node name.


def __init__(self, input: EventSetNode, check_overflow: bool, dtype: Optional[DType]=None, dtype_to_dtype: Optional[Dict[DType, DType]]=None, feature_name_to_dtype: Optional[Dict[str, DType]]=None, dtypes: Optional[List[DType]]=None):
    super().__init__()
    assert sum((x is not None for x in [dtype, dtype_to_dtype, feature_name_to_dtype, dtypes])) == 1
    if dtypes is None:
        dtypes = build_dtypes_list_from_target_dtypes(input, dtype, dtype_to_dtype, feature_name_to_dtype)
    self._dtypes = dtypes
    self._check_overflow = check_overflow
    assert len(self._dtypes) == len(input.schema.features)
    self.add_attribute('dtypes', self._dtypes)
    self.add_attribute('check_overflow', check_overflow)
    self.add_input('input', input)
    output_features = []
    output_schema = Schema(features=[], indexes=input.schema.indexes, is_unix_timestamp=input.schema.is_unix_timestamp)
    is_noop = True
    for new_dtype, feature_node, feature_schema in zip(self._dtypes, input.feature_nodes, input.schema.features):
        output_schema.features.append(FeatureSchema(feature_schema.name, new_dtype))
        if new_dtype is feature_schema.dtype:
            output_features.append(feature_node)
        else:
            is_noop = False
            output_features.append(Feature(creator=self))
    if is_noop:
        self.add_output('output', input)
    else:
        self.add_output('output', create_node_with_new_reference(schema=output_schema, features=output_features, sampling=input.sampling_node, creator=self))
    self._is_noop = is_noop
    self.check()

Constructor.

There can only be one of dtype, dtype_to_dtype, feature_name_to_dtype,
or dtypes.

Args:
input: Input node.
check_overflow: Check for casting overflow.
dtype: All the input features are casted to dtype.
dtype_to_dtype: Mapping between current dtype and new dtype.
feature_name_to_dtype: Mapping between feature name and new dtype.
dtypes: Dtype for each of the input feature (indexed by feature
idx).


def _get_channel(host, timeout):
    connection = create_blocking_connection(host)
    if (timeout >= 0):
        connection.add_timeout(timeout, (lambda : (sys.stderr.write('Timeouted!\n') or sys.exit(1))))
    return connection.channel()

Create communication channel for given `host`.

Args:
host (str): Specified --host.
timeout (int): Set `timeout` for returned `channel`.

Returns:
Object: Pika channel object.


def _check_arg_equality(node_a, node_b, attr_name):
    return (getattr(node_a, attr_name) == getattr(node_b, attr_name))

Check equality of nodes based on the comparison of their attributes named attr_name.

Args:
node_a (astroid.node): first node to compare.
node_b (astroid.node): second node to compare.
attr_name (str): name of the nodes attribute to use for comparison.

Returns:
bool: True if node_a.attr_name == node_b.attr_name, False otherwise.


def find(self, instance_id):

        instance = AtlasServiceInstance.Instance(instance_id, self.backend)
        self.backend.storage.populate(instance)
        return instance

find an instance

Create a new instance and populate it with data stored if it exists.

Args:
instance_id (str): UUID of the instance

Returns:
AtlasServiceInstance.Instance: An instance


def learn(self, grad_arr, fix_opt_flag=False):

        channel = grad_arr.shape[1]
        grad_arr = self.__deconvolution_model.learn(grad_arr[:, :channel], fix_opt_flag=fix_opt_flag)
        delta_arr = self.__cnn.back_propagation(grad_arr)
        if fix_opt_flag is False:
            self.__cnn.optimize(self.__learning_rate, 1)
        return delta_arr

Update this Discriminator by ascending its stochastic gradient.

Args:
grad_arr:       `np.ndarray` of gradients.
fix_opt_flag:   If `False`, no optimization in this model will be done.

Returns:
`np.ndarray` of delta or gradients.


def delete_devices(self, auth_body, devices):
    content = {'auth': auth_body, 'devices': devices}
    return self._send('POST', '/delete_devices', content=content)

Bulk deletion of devices.

NOTE: This endpoint uses the User-Interactive Authentication API.

Args:
auth_body (dict): Authentication params.
devices (list): List of device ID"s to delete.


def register(self, op):
    if not hasattr(op, FALLBACK_DISPATCH_ATTR):
        raise AssertionError('Dispatching not enabled for %s' % op)
    getattr(op, FALLBACK_DISPATCH_ATTR).append(self)

Register this dispatcher as a handler for `op`.

Args:
op: Python function: the TensorFlow operation that should be handled. Must
have a dispatch list (which is added automatically for generated ops,
and can be added to Python ops using the `add_dispatch_support`
decorator).


Make a set of tests to do reduce operation.

Args:
reduce_op: TensorFlow reduce operation to test, i.e. `tf.reduce_mean`.
min_value: min value for created tensor data.
max_value: max value for created tensor data.
boolean_tensor_only: If true, will only generate tensor with boolean value.
allow_fully_quantize: bool, whether fully_quantize is allowed.

Returns:
a function representing the true generator with `reduce_op_in` curried.


def bulk_write(self, metrics):
    try:
        for metric in metrics:
            self.producer.send(self.topic, metric)
        self.producer.flush()
    except (KafkaTimeoutError, NoBrokersAvailable) as exc:
        logger.warning('bulk_write metrics %r failure %r', metrics, exc)

Write multiple metrics to kafka in one request

Args:
metrics (list):


def write(self, handle: TextIO, blank_lines: int = 1) -> None:

        if not isinstance(blank_lines, int) or blank_lines <= 0:
            raise ValueError('Number of blank lines must be a positive int.')

        writer = csv.writer(handle)
        csv_width: int = max([len(self.all_sample_keys), 2])

        section_order = ['Header', 'Reads'] + self._sections + ['Settings']

        def pad_iterable(
            iterable: Iterable, size: int = csv_width, padding: str = ''
        ) -> List[str]:
            return list(islice(chain(iterable, repeat(padding)), size))

        def write_blank_lines(
            writer: Any, n: int = blank_lines, width: int = csv_width
        ) -> None:
            for i in range(n):
                writer.writerow(pad_iterable([], width))

        for title in section_order:
            writer.writerow(pad_iterable([f'[{title}]'], csv_width))
            section = getattr(self, title)
            if title == 'Reads':
                for read in self.Reads:
                    writer.writerow(pad_iterable([read], csv_width))
            else:
                for key, value in section.items():
                    writer.writerow(pad_iterable([key, value], csv_width))
            write_blank_lines(writer)

        writer.writerow(pad_iterable(['[Data]'], csv_width))
        writer.writerow(pad_iterable(self.all_sample_keys, csv_width))

        for sample in self.samples:
            line = [getattr(sample, key) for key in self.all_sample_keys]
            writer.writerow(pad_iterable(line, csv_width))

Write this :class:`SampleSheet` to a file-like object.

Args:
handle: Object to wrap by csv.writer.
blank_lines: Number of blank lines to write between sections.


def __init__(self, corruption_type, severity, **kwargs):

    super(Cifar10CorruptedConfig, self).__init__(**kwargs)
    self.corruption = corruption_type
    self.severity = severity

Constructor.

Args:
corruption_type: string, must be one of the items in _CORRUPTIONS.
severity: integer, bewteen 1 and 5.
**kwargs: keyword arguments forwarded to super.


def create_model(self, ModelName, PrimaryContainer, *args, **kwargs):

        LocalSagemakerClient._models[ModelName] = _LocalModel(ModelName, PrimaryContainer)

Create a Local Model Object

Args:
ModelName (str): the Model Name
PrimaryContainer (dict): a SageMaker primary container definition


def mset(self, values):

        for key, value in values.items():
            self.set(key, value)

Set the value of several keys at once.

Args:
values (dict): maps a key to its value.


def get_pipeline_newsfeeds(self, pipeline_key, detail_level = None):

		uri = '/'.join([
						self.api_uri,
						self.pipelines_suffix,
						pipeline_key,
						self.newsfeed_suffix
						])
		return self._get_newsfeeds(uri, detail_level)

Function to get newsfeed for a pipeline
Args:
pipeline_key	pipeline key
detail_level 	arguments for req str ['ALL', 'CONDENSED']
return 			list of feed dicts parse at your convenience


def update(self, forecasts, observations):
    if (len(observations.shape) == 1):
        obs_cdfs = np.zeros((observations.size, self.thresholds.size))
        for (o, observation) in enumerate(observations):
            obs_cdfs[(o, (self.thresholds >= observation))] = 1
    else:
        obs_cdfs = observations
    self.errors['F_2'] += np.sum((forecasts ** 2), axis=0)
    self.errors['F_O'] += np.sum((forecasts * obs_cdfs), axis=0)
    self.errors['O_2'] += np.sum((obs_cdfs ** 2), axis=0)
    self.errors['O'] += np.sum(obs_cdfs, axis=0)
    self.num_forecasts += forecasts.shape[0]

Update the statistics with forecasts and observations.

Args:
forecasts: The discrete Cumulative Distribution Functions of
observations:


def cumulative_distribution(self, X):

        self.check_fit()

        U, V = self.split_matrix(X)

        num = np.multiply(
            np.exp(np.multiply(-self.theta, U)) - 1,
            np.exp(np.multiply(-self.theta, V)) - 1
        )
        den = np.exp(-self.theta) - 1

        return -1.0 / self.theta * np.log(1 + num / den)

Computes the cumulative distribution function for the copula, :math:`C(u, v)`

Args:
X: `np.ndarray`

Returns:
np.array: cumulative distribution


def __init__(self, base, reversible_layer, name=None):

    self.base = base
    self.reversible_layer = reversible_layer
    if name is None:
      name = reversible_layer.name + base.name
    super(TransformedDistribution, self).__init__(
        base.dtype,
        base.reparameterization_type,
        base.validate_args,
        base.allow_nan_stats,
        parameters=dict(locals()),
        name=name)

Constructs a transformed distribution.

Args:
base: Base distribution.
reversible_layer: Callable with methods `reverse` and `log_det_jacobian`.
name: Name for scoping operations in the class.


def dispatch(self, msg):

        logger.debug(f"Got message: {msg}")
        futures = []
        matched = False
        for behaviour in (x for x in self.behaviours if x.match(msg)):
            futures.append(self.submit(behaviour.enqueue(msg)))
            logger.debug(f"Message enqueued to behaviour: {behaviour}")
            self.traces.append(msg, category=str(behaviour))
            matched = True
        if not matched:
            logger.warning(f"No behaviour matched for message: {msg}")
            self.traces.append(msg)
        return futures

Dispatch the message to every behaviour that is waiting for
it using their templates match.

Args:
msg (spade.message.Messagge): the message to dispatch.

Returns:
list(asyncio.Future): a list of futures of the append of the message at each matched behaviour.


def setup(self,
            host, flow_id,
            reason, grr_server_url, grr_username, grr_password, approvers=None,
            verify=True):

    super(GRRFlowCollector, self).setup(
        reason, grr_server_url, grr_username, grr_password,
        approvers=approvers, verify=verify)
    self.flow_id = flow_id
    self.host = host

Initializes a GRR flow collector.

Args:
host: hostname of machine.
flow_id: ID of GRR flow to retrieve.
reason: justification for GRR access.
grr_server_url: GRR server URL.
grr_username: GRR username.
grr_password: GRR password.
approvers: list of GRR approval recipients.
verify: boolean, whether to verify the GRR server's x509 certificate.


def remove(self, iterable, data=None, index=0):
    if (index == len(iterable)):
        if self.is_terminal:
            if data:
                self.data.remove(data)
                if (len(self.data) == 0):
                    self.is_terminal = False
            else:
                self.data.clear()
                self.is_terminal = False
            return True
        else:
            return False
    elif (iterable[index] in self.children):
        return self.children[iterable[index]].remove(iterable, index=(index + 1), data=data)
    else:
        return False

Remove an element from the trie

Args
iterable(hashable): key used to find what is to be removed
data(object): data associated with the key
index(int): index of what is to me removed

Returns:
bool:
True: if it was removed
False: if it was not removed


def path_to_zip(path):

    if not os.path.exists(path):
        raise IOError("%s doesn't exists!" % path)

    with tempfile.NamedTemporaryFile(delete=False) as ntf:
        zip_fn = ntf.name

    with zipfile.ZipFile(zip_fn, mode="w") as zip_file:
        for root, dirs, files in os.walk(path):
            for fn in files:
                zip_file.write(os.path.join(root, fn))

    return zip_fn

Compress `path` to the ZIP.

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

Returns:
str: Path to the zipped file (in /tmp).


def from_string(cls, s):
    log.debug('Parsing email from string')
    message = email.message_from_string(s)
    return cls(message)

Init a new object from a string.

Args:
s (string): raw email

Returns:
Instance of MailParser


def loss_masks(self, masks_queries_logits: Tensor, mask_labels: List[Tensor], indices: Tuple[np.array], num_masks: int) -> Dict[str, Tensor]:
    src_idx = self._get_predictions_permutation_indices(indices)
    tgt_idx = self._get_targets_permutation_indices(indices)
    pred_masks = masks_queries_logits[src_idx]
    target_masks, _ = self._pad_images_to_max_in_batch(mask_labels)
    target_masks = target_masks[tgt_idx]
    pred_masks = nn.functional.interpolate(pred_masks[:, None], size=target_masks.shape[-2:], mode='bilinear', align_corners=False)
    pred_masks = pred_masks[:, 0].flatten(1)
    target_masks = target_masks.flatten(1)
    losses = {'loss_mask': sigmoid_focal_loss(pred_masks, target_masks, num_masks), 'loss_dice': dice_loss(pred_masks, target_masks, num_masks)}
    return losses

Compute the losses related to the masks using focal and dice loss.

Args:
masks_queries_logits (`torch.Tensor`):
A tensor of shape `batch_size, num_queries, height, width`
mask_labels (`torch.Tensor`):
List of mask labels of shape `(labels, height, width)`.
indices (`Tuple[np.array])`:
The indices computed by the Hungarian matcher.
num_masks (`int)`:
The number of masks, used for normalization.

Returns:
`Dict[str, Tensor]`: A dict of `torch.Tensor` containing two keys:
- **loss_mask** -- The loss computed using sigmoid focal loss on the predicted and ground truth masks.
- **loss_dice** -- The loss computed using dice loss on the predicted on the predicted and ground truth
masks.


def MakePmfFromList(t, name=''):
    hist = MakeHistFromList(t)
    d = hist.GetDict()
    pmf = Pmf(d, name)
    pmf.Normalize()
    return pmf

Makes a PMF from an unsorted sequence of values.

Args:
t: sequence of numbers
name: string name for this PMF

Returns:
Pmf object


def dense_rank(series, ascending=True):

    ranks = series.rank(method='dense', ascending=ascending)
    return ranks

Equivalent to `series.rank(method='dense', ascending=ascending)`.

Args:
series: column to rank.

Kwargs:
ascending (bool): whether to rank in ascending order (default is `True`).


def summarize_neural_network_spec(mlmodel_spec):

    inputs = [(blob.name, _get_feature_description_summary(blob)) for blob in mlmodel_spec.description.input]
    outputs = [(blob.name, _get_feature_description_summary(blob)) for blob in mlmodel_spec.description.output]
    nn = None

    if mlmodel_spec.HasField('neuralNetwork'):
        nn = mlmodel_spec.neuralNetwork
    elif mlmodel_spec.HasField('neuralNetworkClassifier'):
        nn = mlmodel_spec.neuralNetworkClassifier
    elif mlmodel_spec.HasField('neuralNetworkRegressor'):
        nn = mlmodel_spec.neuralNetworkRegressor

    layers = [_summarize_network_layer_info(layer) for layer in nn.layers] if nn != None else None
    return (inputs, outputs, layers)

Summarize network into the following structure.
Args:
mlmodel_spec : mlmodel spec
Returns:
inputs : list[(str, str)] - a list of two tuple (name, descriptor) for each input blob.
outputs : list[(str, str)] - a list of two tuple (name, descriptor) for each output blob
layers : list[(str, list[str], list[str], list[(str, str)])] - a list of layers represented by
layer name, input blobs, output blobs, a list of (parameter name, content)


def relpath(self, path):
    for root in self.roots:
        if isinstance(root, Pattern):
            match = root.match(path)
            if (not match):
                continue
            root = match.group(0)
        try:
            relative = path.split(root, 1)[1]
            return relative.lstrip('/')
        except IndexError:
            continue
    return path

Get path relative to storage.

args:
path (str): Absolute path or URL.

Returns:
str: relative path.


def __init__(self, filepaths, overrides=None, locked=False):

        self.filepaths = filepaths
        self._sourced_filepaths = None
        self.overrides = overrides or {}
        self.locked = locked

Create a config.

Args:
filepaths (list of str): List of config files to load.
overrides (dict): A dict containing settings that override all
others. Nested settings are overridden with nested dicts.
locked: If True, settings overrides in environment variables are
ignored.


def images(self, name=None, quiet=False, all=False, filters=None):
    params = {'filter': name, 'only_ids': (1 if quiet else 0), 'all': (1 if all else 0)}
    if filters:
        params['filters'] = utils.convert_filters(filters)
    res = self._result(self._get(self._url('/images/json'), params=params), True)
    if quiet:
        return [x['Id'] for x in res]
    return res

List images. Similar to the ``docker images`` command.

Args:
name (str): Only show images belonging to the repository ``name``
quiet (bool): Only return numeric IDs as a list.
all (bool): Show intermediate image layers. By default, these are
filtered out.
filters (dict): Filters to be processed on the image list.
Available filters:
- ``dangling`` (bool)
- ``label`` (str): format either ``key`` or ``key=value``

Returns:
(dict or list): A list if ``quiet=True``, otherwise a dict.

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


def from_model_config(cls, config: 'PretrainedConfig', task: str='default') -> 'OnnxConfig':
    return cls(config, task=task)

Instantiate a OnnxConfig for a specific model

Args:
config: The model's configuration to use when exporting to ONNX

Returns:
OnnxConfig for this model


def relativefrom(base, path):

    base_parts = list(iteratepath(base))
    path_parts = list(iteratepath(path))

    common = 0
    for component_a, component_b in zip(base_parts, path_parts):
        if component_a != component_b:
            break
        common += 1

    return "/".join([".."] * (len(base_parts) - common) + path_parts[common:])

Return a path relative from a given base path.

Insert backrefs as appropriate to reach the path from the base.

Arguments:
base (str): Path to a directory.
path (str): Path to make relative.

Returns:
str: the path to ``base`` from ``path``.

>>> relativefrom("foo/bar", "baz/index.html")
'../../baz/index.html'


def Query(args):
    query = args.query.encode('utf-8')
    timeout = (args.timeout_millis / 1000)
    try:
        command = [config.CONFIG['Osquery.path'], '--S', '--json', query]
        proc = subprocess.run(command, timeout=timeout, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    except subprocess.TimeoutExpired as error:
        raise TimeoutError(cause=error)
    except subprocess.CalledProcessError as error:
        raise Error('osquery invocation error', cause=error)
    stdout = proc.stdout.decode('utf-8')
    stderr = proc.stderr.decode('utf-8').strip()
    return ProcOutput(stdout=stdout, stderr=stderr)

Calls osquery with given query and returns its output.

Args:
args: A query to call osquery with.

Returns:
A "parsed JSON" representation of the osquery output.

Raises:
QueryError: If the query is incorrect.
TimeoutError: If a call to the osquery executable times out.
Error: If anything else goes wrong with the subprocess call.


def get_prefix(self, name):
    if (name == 'current'):
        name = self.current
    try:
        return self.prefixes[name]
    except KeyError:
        raise KeyError(('Unable to find prefix "%s" in workdir %s' % (name, self.path)))

Retrieve a prefix, resolving the current one if needed

Args:
name(str): name of the prefix to retrieve, or current to get the
current one

Returns:
self.prefix_class: instance of the prefix with the given name


def peek_step(self, val: ObjectValue,
                  sn: "DataNode") -> Tuple[Value, "DataNode"]:

        cn = sn.get_data_child(self.name, self.namespace)
        try:
            return (val[cn.iname()], cn)
        except (IndexError, KeyError, TypeError):
            return (None, cn)

Return member value addressed by the receiver + its schema node.

Args:
val: Current value (object).
sn:  Current schema node.


def _decode_value(self, value):
    if isinstance(value, (int, float, str, bool, datetime)):
        return value
    elif isinstance(value, list):
        return [self._decode_value(item) for item in value]
    elif isinstance(value, dict):
        result = {}
        for (key, item) in value.items():
            result[key] = self._decode_value(item)
        return result
    elif isinstance(value, ObjectId):
        if self._gridfs.exists({'_id': value}):
            return pickle.loads(self._gridfs.get(value).read())
        else:
            raise DataStoreGridfsIdInvalid()
    else:
        raise DataStoreDecodeUnknownType()

Decodes the value by turning any binary data back into Python objects.

The method searches for ObjectId values, loads the associated binary data from
GridFS and returns the decoded Python object.

Args:
value (object): The value that should be decoded.

Raises:
DataStoreDecodingError: An ObjectId was found but the id is not a valid
GridFS id.
DataStoreDecodeUnknownType: The type of the specified value is unknown.

Returns:
object: The decoded value as a valid Python object.


def follow(self, chars):
    chars = chars.lower()
    node = self.node
    for char in chars:
        node = cgaddag.gdg_follow_edge(self.gdg, node, char.encode('ascii'))
        if (not node):
            raise KeyError(char)
    return Node(self.gdg, node)

Traverse the GADDAG to the node at the end of the given characters.

Args:
chars: An string of characters to traverse in the GADDAG.

Returns:
The Node which is found by traversing the tree.


def relocate(self, destination):
    for activate in self.bin.activates:
        activate.vpath = destination
    for binfile in self.bin.files:
        if (binfile.shebang and (('python' in binfile.shebang) or ('pypy' in binfile.shebang))):
            binfile.shebang = '

Configure the virtual environment for another path.

Args:
destination (str): The target path of the virtual environment.

Note:
This does not actually move the virtual environment. Is only
rewrites the metadata required to support a move.


def __init__( self ):

        self.lattice = None
        self.number_of_atoms = None
        self.number_of_jumps = None
        self.for_time = None
        self.number_of_equilibration_jumps = 0
        self.atoms = None
        self.has_run = False

Initialise a Simulation object.

Args:
None

Returns:
None

Notes:
Simulation parameters need to be set using their corresponding setter methods.


def copyfile(src, dst, follow_symlinks=True):

    src, src_is_storage = format_and_is_storage(src)
    dst, dst_is_storage = format_and_is_storage(dst)

    if not src_is_storage and not dst_is_storage:
        return shutil_copyfile(src, dst, follow_symlinks=follow_symlinks)

    with handle_os_exceptions():

        try:
            if not hasattr(dst, 'read') and not isdir(dirname(dst)):
                raise IOError("No such file or directory: '%s'" % dst)

        except ObjectPermissionError:

            pass

        _copy(src, dst, src_is_storage, dst_is_storage)

Copies a source file to a destination file.

Equivalent to "shutil.copyfile".

Source and destination can also be binary opened file-like objects.

Args:
src (path-like object or file-like object): Source file.
dst (path-like object or file-like object): Destination file.
follow_symlinks (bool): Follow symlinks.
Not supported on cloud storage objects.

Raises:
IOError: Destination directory not found.


def move_temp_file(src, dest):

    try:
        move_file(src, dest)
    except Exception:
        try:
            os.remove(src)
        except Exception as ex_clean:

            logger.error(f"error removing temp file {src}. "
                         f"{ex_clean}")

        raise

Move src to dest. Delete src if something goes wrong.

Overwrites dest.

Args:
src: str or path-like. source file
dest: str or path-like. destination file

Returns:
None.

Raises:
FileNotFoundError: out path parent doesn't exist.
OSError: if any IO operations go wrong. Does its best to clean up after
itself and remove temp files.


def copy(self, stateful=False):
    raise NotImplementedError(f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.')

Creates a new instance of this constraint.

Args:
stateful(`bool`): Whether to not only copy the constraint for new instance, but also its state.

Return:
constraint(`Constraint`): The same constraint as the one being called from.


def interpolate_holes(self):
    assert (self.validated_a_period is True), 'validated_a_period property must be True to use interpolate_holes(). Run validate_analysis_period().'
    mins_per_step = int((60 / self.header.analysis_period.timestep))
    new_datetimes = self.header.analysis_period.datetimes
    new_values = []
    i = 0
    if (new_datetimes[0] != self.datetimes[0]):
        n_steps = int(((self.datetimes[0].moy - new_datetimes[0].moy) / mins_per_step))
        new_values.extend(([self._values[0]] * n_steps))
        i = (n_steps - 1)
    for j in xrange(len(self._values)):
        if (new_datetimes[i] == self.datetimes[j]):
            new_values.append(self._values[j])
            i += 1
        else:
            n_steps = int(((self.datetimes[j].moy - new_datetimes[i].moy) / mins_per_step))
            intp_vals = self._xxrange(self._values[(j - 1)], self._values[j], n_steps)
            new_values.extend((list(intp_vals)[1:] + [self._values[j]]))
            i += n_steps
    if (len(new_values) != len(new_datetimes)):
        n_steps = (len(new_datetimes) - len(new_values))
        new_values.extend(([self._values[(- 1)]] * n_steps))
    return HourlyContinuousCollection(self.header.duplicate(), new_values)

Linearly interpolate over holes in this collection to make it continuous.

Returns:
continuous_collection: A HourlyContinuousCollection with the same data
as this collection but with missing data filled by means of a
linear interpolation.


def document(self, document_id, **kwargs):
    baseuri = '{}document/{}/content'.format(self._DOCUMENT_URI, document_id)
    res = self.session.get(baseuri, params=kwargs)
    self.handle_http_error(res)
    return res

Requests for a document by the document id.
Normally the response.content can be saved as a pdf file

Args:
document_id (str): The id of the document retrieved.
kwargs (dict): additional keywords passed into
requests.session.get *params* keyword.


def get_auth_token(self, user_payload):
    now = datetime.utcnow()
    payload = {'user': user_payload}
    if ('iat' in self.verify_claims):
        payload['iat'] = now
    if ('nbf' in self.verify_claims):
        payload['nbf'] = (now + self.leeway)
    if ('exp' in self.verify_claims):
        payload['exp'] = (now + self.expiration_delta)
    if (self.audience is not None):
        payload['aud'] = self.audience
    if (self.issuer is not None):
        payload['iss'] = self.issuer
    return jwt.encode(payload, self.secret_key, algorithm=self.algorithm, json_encoder=ExtendedJSONEncoder).decode('utf-8')

Create a JWT authentication token from ``user_payload``

Args:
user_payload(dict, required): A `dict` containing required information
to create authentication token


def draw_rect(self, rect):
    check_int_err(lib.SDL_RenderDrawRect(self._ptr, rect._ptr))

Draw a rectangle on the current rendering target.

Args:
rect (Rect): The destination rectangle, or None to outline the entire rendering target.

Raises:
SDLError: If an error is encountered.


def _serve_image_metadata(self, request):

    tag = request.args.get('tag')
    run = request.args.get('run')
    sample = int(request.args.get('sample', 0))
    response = self._image_response_for_run(run, tag, sample)
    return http_util.Respond(request, response, 'application/json')

Given a tag and list of runs, serve a list of metadata for images.

Note that the images themselves are not sent; instead, we respond with URLs
to the images. The frontend should treat these URLs as opaque and should not
try to parse information about them or generate them itself, as the format
may change.

Args:
request: A werkzeug.wrappers.Request object.

Returns:
A werkzeug.Response application.


def create_with_zero_body(self, uri=None, timeout=-1, custom_headers=None):

        if not uri:
            uri = self.URI

        logger.debug('Create with zero body (uri = %s)' % uri)
        resource_data = self._helper.do_post(uri, {}, timeout, custom_headers)

        return resource_data

Makes a POST request to create a resource when no request body is required.

Args:
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
custom_headers: Allows set specific HTTP headers.

Returns:
Created resource.


def range(self, x_data=None):
    if (x_data is None):
        try:
            x_data = evaluation.evaluate_inverse(self, numpy.array(([[0.5]] * len(self))))
        except StochasticallyDependentError:
            x_data = approximation.find_interior_point(self)
        shape = (len(self),)
        if hasattr(self, '_range'):
            return self._range(x_data, {})
    else:
        x_data = numpy.asfarray(x_data)
        shape = x_data.shape
        x_data = x_data.reshape(len(self), (- 1))
    q_data = evaluation.evaluate_bound(self, x_data)
    q_data = q_data.reshape(((2,) + shape))
    return q_data

Generate the upper and lower bounds of a distribution.

Args:
x_data (numpy.ndarray) :
The bounds might vary over the sample space. By providing
x_data you can specify where in the space the bound should be
taken.  If omitted, a (pseudo-)random sample is used.

Returns:
(numpy.ndarray):
The lower (out[0]) and upper (out[1]) bound where
out.shape=(2,)+x_data.shape


def _index_idiom(el_name, index, alt=None):
    el_index = ('%s[%d]' % (el_name, index))
    if (index == 0):
        cond = ('%s' % el_name)
    else:
        cond = ('len(%s) - 1 >= %d' % (el_name, index))
    output = (IND + '
    return ((output + IND) + ('%s = %s if %s else %s\n\n' % (el_name, el_index, cond, repr(alt))))

Generate string where `el_name` is indexed by `index` if there are enough
items or `alt` is returned.

Args:
el_name (str): Name of the `container` which is indexed.
index (int): Index of the item you want to obtain from container.
alt (whatever, default None): Alternative value.

Returns:
str: Python code.

Live example::
>>> import generator as g
>>> print g._index_idiom("xex", 0)
# pick element from list
xex = xex[0] if xex else None
>>> print g._index_idiom("xex", 1, "something")
# pick element from list
xex = xex[1] if len(xex) - 1 >= 1 else 'something'


def create_binary_descriptor(streamer):
    trigger = 0
    if streamer.automatic:
        trigger = 1
    elif (streamer.with_other is not None):
        trigger = ((1 << 7) | streamer.with_other)
    return struct.pack('<8sHBBBx', streamer.dest.encode(), streamer.selector.encode(), trigger, streamer.KnownFormats[streamer.format], streamer.KnownTypes[streamer.report_type])

Create a packed binary descriptor of a DataStreamer object.

Args:
streamer (DataStreamer): The streamer to create a packed descriptor for

Returns:
bytes: A packed 14-byte streamer descriptor.


def clean(self, value):

		if value is None and self._optional:
			return None

		if not isinstance(value, list):
			raise ValueError('value')

		return [self._node.clean(m) for m in value]

Clean

Goes through each of the values in the list, cleans it, stores it, and
returns a new list

Arguments:
value {list} -- The value to clean

Returns:
list


def select(self, cols, mode='list'):
    if isinstance(cols, stringtypes):
        cols = _split_cols(cols)
    if (not cols):
        cols = [f.name for f in self.fields]
    return select_rows(cols, self, mode=mode)

Select columns from each row in the table.

See :func:`select_rows` for a description of how to use the
*mode* parameter.

Args:
cols: an iterable of Field (column) names
mode: how to return the data


def or_terms(*args):

    args = [arg if not isinstance(arg, list) else ' '.join(arg) for arg in args]
    return '{{{0}}}'.format(' '.join(args))

Connect given term strings or list(s) of term strings with a OR operator for querying.

Args:
An arbitrary number of either strings or lists of strings representing query terms.

Returns
A query string consisting of argument terms or'ed together.


def __init__(self, period, start_at=None):

        super().__init__()
        self._period = None
        self.period = period

        if start_at:
            self._next_activation = start_at
        else:
            self._next_activation = now()

Creates a periodic behaviour.

Args:
period (float): interval of the behaviour in seconds
start_at (datetime.datetime): whether to start the behaviour with an offset


def find(self, search_term, index=False):
    hits = []
    for (i, iv) in enumerate(self):
        try:
            search_text = (iv.description or iv.primary.summary())
            pattern = re.compile(search_term, flags=re.IGNORECASE)
            if pattern.search(search_text):
                hits.append(i)
        except TypeError:
            if (search_term in iv.components):
                hits.append(i)
    if (hits and index):
        return hits
    elif hits:
        return self[hits]
    else:
        return

Look for a regex expression in the descriptions of the striplog.
If there's no description, it looks in the summaries.

If you pass a Component, then it will search the components, not the
descriptions or summaries.

Case insensitive.

Args:
search_term (string or Component): The thing you want to search
for. Strings are treated as regular expressions.
index (bool): Whether to return the index instead of the interval.
Returns:
Striplog: A striplog that contains only the 'hit' Intervals.
However, if ``index`` was ``True``, then that's what you get.


def deserialize(json, cls=None):

    LOGGER.debug('deserialize(%s)', json)

    out = simplejson.loads(json)

    if isinstance(out, dict) and cls is not None:
        return cls(**out)

    return out

Deserialize a JSON string into a Python object.

Args:
json (str): the JSON string.
cls (:py:class:`object`):
if the ``json`` is deserialized into a ``dict`` and
this argument is set,
the ``dict`` keys are passed as keyword arguments to the
given ``cls`` initializer.

Returns:
Python object representation of the given JSON string.


def dump_logs(json_data, project_mapping, tag_name):

    pwd_dir_path, dump_file_name = _prepare_dump_info(project_mapping, tag_name)
    dump_json_file(json_data, pwd_dir_path, dump_file_name)

dump tests data to json file.
the dumped file is located in PWD/logs folder.

Args:
json_data (list/dict): json data to dump
project_mapping (dict): project info
tag_name (str): tag name, loaded/parsed/summary


def console_put_char_ex(con: tcod.console.Console, x: int, y: int, c: Union[(int, str)], fore: Tuple[(int, int, int)], back: Tuple[(int, int, int)]) -> None:
    lib.TCOD_console_put_char_ex(_console(con), x, y, _int(c), fore, back)

Draw the character c at x,y using the colors fore and back.

Args:
con (Console): Any Console instance.
x (int): Character x position from the left.
y (int): Character y position from the top.
c (Union[int, AnyStr]): Character to draw, can be an integer or string.
fore (Union[Tuple[int, int, int], Sequence[int]]):
An (r, g, b) sequence or Color instance.
back (Union[Tuple[int, int, int], Sequence[int]]):
An (r, g, b) sequence or Color instance.


def __to_plain_containers(self,
                              container: Union[CommentedSeq, CommentedMap]
                              ) -> Union[OrderedDict, list]:

        if isinstance(container, CommentedMap):
            new_container = OrderedDict()
            for key, value_obj in container.items():
                if (isinstance(value_obj, CommentedMap)
                        or isinstance(value_obj, CommentedSeq)):
                    new_container[key] = self.__to_plain_containers(value_obj)
                else:
                    new_container[key] = value_obj

        elif isinstance(container, CommentedSeq):
            new_container = list()
            for value_obj in container:
                if (isinstance(value_obj, CommentedMap)
                        or isinstance(value_obj, CommentedSeq)):
                    new_container.append(self.__to_plain_containers(value_obj))
                else:
                    new_container.append(value_obj)
        return new_container

Converts any sequence or mapping to list or OrderedDict

Stops at anything that isn't a sequence or a mapping.

One day, we'll extract the comments and formatting and store \
them out-of-band.

Args:
mapping: The mapping of constructed subobjects to edit


def __rsub__(self, other):

        other = as_dimension(other)
        if self._value is None or other.value is None:
            return Dimension(None)
        else:
            return Dimension(other.value - self._value)

Returns the subtraction of `self` from `other`.

Args:
other: Another Dimension, or a value accepted by `as_dimension`.

Returns:
A Dimension whose value is the subtraction of `self` from `other`.


def compile_src(src, filename, python_version, python_exe, mode='exec'):
    pyc_data = compiler.compile_src_string_to_pyc_string(src, filename, python_version, python_exe, mode)
    code = parse_pyc_string(pyc_data)
    if code.python_version != python_version:
        raise utils.UsageError('python_exe version %s does not match python version %s' % (utils.format_version(code.python_version), utils.format_version(python_version)))
    visit(code, AdjustFilename(filename))
    return code

Compile a string to pyc, and then load and parse the pyc.

Args:
src: Python source code.
filename: The filename the sourcecode is from.
python_version: Python version, (major, minor).
python_exe: The path to Python interpreter.
mode: "exec", "eval" or "single".

Returns:
An instance of pycnite.types.CodeTypeBase.

Raises:
UsageError: If python_exe and python_version are mismatched.


def _next_generation(self, sorted_trials):

        candidate = []
        next_generation = []
        num_population = self._next_population_size(len(sorted_trials))
        top_num = int(max(num_population * self._keep_top_ratio, 2))

        for i in range(top_num):
            candidate.append(sorted_trials[i].extra_arg)
            next_generation.append(sorted_trials[i].extra_arg)

        for i in range(top_num, num_population):
            flip_coin = np.random.uniform()
            if flip_coin < self._selection_bound:
                next_generation.append(GeneticSearch._selection(candidate))
            else:
                if flip_coin < self._selection_bound + self._crossover_bound:
                    next_generation.append(GeneticSearch._crossover(candidate))
                else:
                    next_generation.append(GeneticSearch._mutation(candidate))
        return next_generation

Generate genes (encodings) for the next generation.

Use the top K (_keep_top_ratio) trials of the last generation
as candidates to generate the next generation. The action could
be selection, crossover and mutation according corresponding
ratio (_selection_bound, _crossover_bound).

Args:
sorted_trials: List of finished trials with top
performance ones first.

Returns:
A list of new genes (encodings)


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

The FHIRPath not() function.

Returns:
An expression that evaluates to negation of the parent.


def gym_space_spec(gym_space):
    try:
        tf_dtype = tf.as_dtype(gym_space.dtype)
    except TypeError as e:
        tf.logging.error("Cannot convert space's type [%s] to tf.dtype", gym_space.dtype)
        raise e
    if isinstance(gym_space, Box):
        return box_space_spec(gym_space, tf_dtype)
    elif isinstance(gym_space, Discrete):
        return discrete_space_spec(gym_space, tf_dtype)
    else:
        raise NotImplementedError

Returns a reading spec of a gym space.

NOTE: Only implemented currently for Box and Discrete.

Args:
gym_space: instance of gym.spaces whose spec we want.

Returns:
Reading spec for that space.

Raises:
NotImplementedError: For spaces whose reading spec we haven't implemented.


def permute(self, ordering: np.ndarray, *, axis: int) -> None:

		if axis not in (0, 1):
			raise ValueError("Axis must be 0 (rows) or 1 (columns)")
		for layer in self.layers.values():
			layer._permute(ordering, axis=axis)
		if axis == 0:
			if self.row_graphs is not None:
				for g in self.row_graphs.values():
					g._permute(ordering)
			for a in self.row_attrs.values():
				a._permute(ordering)
		elif axis == 1:
			if self.col_graphs is not None:
				for g in self.col_graphs.values():
					g._permute(ordering)
			for a in self.col_attrs.values():
				a._permute(ordering)

Permute the view, by permuting its layers, attributes and graphs

Args:
ordering (np.ndarray):	The desired ordering along the axis
axis (int):				0, permute rows; 1, permute columns


async def run_code(self, code: str, sdk: SdkEnum, pipeline_options: str, datasets: List[api_pb2.Dataset], files: List[api_pb2.SnippetFile]) -> str:
    if sdk not in api_pb2.Sdk.values():
        sdks = api_pb2.Sdk.keys()
        sdks.remove(api_pb2.Sdk.Name(0))
        raise Exception(f'Incorrect sdk: must be from this pool: {', '.join(sdks)}')
    request = api_pb2.RunCodeRequest(code=code, sdk=sdk, pipeline_options=pipeline_options, datasets=datasets, files=files)
    response = await self._stub.RunCode(request, **self._kwargs)
    return response.pipeline_uuid

Run example by his code and SDK

Args:
code: code of the example.
sdk: SDK of the example.
pipeline_options: pipeline options of the example.
datasets: datasets of the example.

Returns:
pipeline_uuid: uuid of the pipeline


def _contains_quantized_function_call(self, graphdef: graph_pb2.GraphDef) -> bool:
    return any(map(self._is_quantized_function, graphdef.library.function))

Determines if the graph def has quantized function call.

Args:
graphdef: A GraphDef object.

Returns:
True if and only if the graph def contains a quantized function call.


def mark_locations(h, section, locs, markspec='or', **kwargs):
    xyz = get_section_path(h, section)
    (r, theta, phi) = sequential_spherical(xyz)
    rcum = np.append(0, np.cumsum(r))
    if ((type(locs) is float) or (type(locs) is np.float64)):
        locs = np.array([locs])
    if (type(locs) is list):
        locs = np.array(locs)
    lengths = (locs * rcum[(- 1)])
    xyz_marks = []
    for targ_length in lengths:
        xyz_marks.append(find_coord(targ_length, xyz, rcum, theta, phi))
    xyz_marks = np.array(xyz_marks)
    (line,) = plt.plot(xyz_marks[(:, 0)], xyz_marks[(:, 1)], xyz_marks[(:, 2)], markspec, **kwargs)
    return line

Marks one or more locations on along a section. Could be used to
mark the location of a recording or electrical stimulation.

Args:
h = hocObject to interface with neuron
section = reference to section
locs = float between 0 and 1, or array of floats
optional arguments specify details of marker

Returns:
line = reference to plotted markers


def FindEndOfExpressionInLine(line, startpos, stack):

  for i in xrange(startpos, len(line)):
    char = line[i]
    if char in '([{':

      stack.append(char)
    elif char == '<':

      if i > 0 and line[i - 1] == '<':

        if stack and stack[-1] == '<':
          stack.pop()
          if not stack:
            return (-1, None)
      elif i > 0 and Search(r'\boperator\s*$', line[0:i]):

        continue
      else:

        stack.append('<')
    elif char in ')]}':

      while stack and stack[-1] == '<':
        stack.pop()
      if not stack:
        return (-1, None)
      if ((stack[-1] == '(' and char == ')') or
          (stack[-1] == '[' and char == ']') or
          (stack[-1] == '{' and char == '}')):
        stack.pop()
        if not stack:
          return (i + 1, None)
      else:

        return (-1, None)
    elif char == '>':

      if (i > 0 and
          (line[i - 1] == '-' or Search(r'\boperator\s*$', line[0:i - 1]))):
        continue

      if stack:
        if stack[-1] == '<':
          stack.pop()
          if not stack:
            return (i + 1, None)
    elif char == ';':

      while stack and stack[-1] == '<':
        stack.pop()
      if not stack:
        return (-1, None)

  return (-1, stack)

Find the position just after the end of current parenthesized expression.

Args:
line: a CleansedLines line.
startpos: start searching at this position.
stack: nesting stack at startpos.

Returns:
On finding matching end: (index just after matching end, None)
On finding an unclosed expression: (-1, None)
Otherwise: (-1, new stack at end of this line)


def profile_settings_args(self, ij, required):
    if (self.args.permutation_id is not None):
        if ('sqlite3' not in sys.modules):
            print('The sqlite3 module needs to be build-in to Python for this feature.')
            sys.exit(1)
        profile_args = self.profile_settings_args_layout_json(required)
    else:
        profile_args = self.profile_settings_args_install_json(ij, required)
    return profile_args

Return args based on install.json or layout.json params.

Args:
ij (dict): The install.json contents.
required (bool): If True only required args will be returned.

Returns:
dict: Dictionary of required or optional App args.


def ExpectedMaxBatchSizes(self, run_params):
    return self.max_batch_sizes

Checks that the expected maximum batch sizes for the generated engines.

Args:
run_params: the run parameters.

Returns:
the expected maximum batch sizes for the generated engines.

There shall be engines generated for each maximum batch size.


def fixup_building_sdist():
    if ('sdist' in sys.argv):
        if ('--install-js' in sys.argv):
            print("Removing '--install-js' incompatible with 'sdist'")
            sys.argv.remove('--install-js')
        if ('--build-js' not in sys.argv):
            print("Adding '--build-js' required for 'sdist'")
            sys.argv.append('--build-js')

Check for 'sdist' and ensure we always build BokehJS when packaging

Source distributions do not ship with BokehJS source code, but must ship
with a pre-built BokehJS library. This function modifies ``sys.argv`` as
necessary so that ``--build-js`` IS present, and ``--install-js` is NOT.

Returns:
None


def conversational_mac(self, **kwargs):
    callback = kwargs.pop('callback', self._callback)
    mac_learning = getattr(self._mac_address_table, 'mac_address_table_learning_mode')
    config = mac_learning(learning_mode='conversational')
    if kwargs.pop('get', False):
        output = callback(config, handler='get_config')
        item = output.data.find('.
        if (item is not None):
            return True
    if kwargs.pop('delete', False):
        config.find('.
    return callback(config)

Enable conversational mac learning on vdx switches

Args:
get (bool): Get config instead of editing config. (True, False)
delete (bool): True, delete the mac-learning. (True, False)
callback (function): A function executed upon completion of the
method.  The only parameter passed to `callback` will be the
``ElementTree`` `config`.

Returns:
Return value of `callback`.

Raises:
None

Examples:
>>> import pynos.device
>>> conn = ('10.24.39.211', '22')
>>> auth = ('admin', 'password')
>>> with pynos.device.Device(conn=conn, auth=auth) as dev:
...     output = dev.interface.conversational_mac()
...     output = dev.interface.conversational_mac(get=True)
...     output = dev.interface.conversational_mac(delete=True)


def EncryptPrivateKey(self, decrypted):
    aes = AES.new(self._master_key, AES.MODE_CBC, self._iv)
    return aes.encrypt(decrypted)

Encrypt the provided plaintext with the initialized private key.

Args:
decrypted (byte string): the plaintext to be encrypted.

Returns:
bytes: the ciphertext.


def prefixed_name(self, unprefixed_name, max_length=0):

        if max_length == 0:
            prefixed_name = '%s-%s' % (self.uuid[:8], unprefixed_name)
        else:
            if max_length < 6:
                raise RuntimeError(
                    "Can't prefix with less than 6 chars (%s)" %
                    unprefixed_name
                )
            if max_length < 16:
                _uuid = self.uuid[:4]
            else:
                _uuid = self.uuid[:8]

            name_max_length = max_length - len(_uuid) - 1

            if name_max_length < len(unprefixed_name):
                hashed_name = hashlib.sha1(unprefixed_name).hexdigest()
                unprefixed_name = hashed_name[:name_max_length]

            prefixed_name = '%s-%s' % (_uuid, unprefixed_name)

        return prefixed_name

Returns a uuid pefixed identifier
Args:
unprefixed_name(str): Name to add a prefix to
max_length(int): maximum length of the resultant prefixed name,
will adapt the given name and the length of the uuid ot fit it
Returns:
str: prefixed identifier for the given unprefixed name