def mean_absolute_percentage_error(y_true, y_pred):
    y_pred = ops.convert_to_tensor(y_pred)
    y_true = ops.convert_to_tensor(y_true, dtype=y_pred.dtype)
    epsilon = ops.convert_to_tensor(backend.epsilon(), dtype=y_pred.dtype)
    y_true, y_pred = squeeze_or_expand_to_same_rank(y_true, y_pred)
    diff = ops.abs((y_true - y_pred) / ops.maximum(ops.abs(y_true), epsilon))
    return 100.0 * ops.mean(diff, axis=-1)

Computes the mean absolute percentage error between `y_true` & `y_pred`.

Formula:

```python
loss = 100 * mean(abs((y_true - y_pred) / y_true), axis=-1)
```

Division by zero is prevented by dividing by `maximum(y_true, epsilon)`
where `epsilon = keras.backend.epsilon()`
(default to `1e-7`).

Args:
y_true: Ground truth values with shape = `[batch_size, d0, .. dN]`.
y_pred: The predicted values with shape = `[batch_size, d0, .. dN]`.

Returns:
Mean absolute percentage error values with shape = `[batch_size, d0, ..
dN-1]`.

Example:

>>> y_true = np.random.random(size=(2, 3))
>>> y_pred = np.random.random(size=(2, 3))
>>> loss = keras.losses.mean_absolute_percentage_error(y_true, y_pred)


def fit(self, vecs, iter=20, seed=123):

        assert vecs.dtype == np.float32
        assert vecs.ndim == 2
        N, D = vecs.shape
        assert self.Ks < N, "the number of training vector should be more than Ks"
        assert D % self.M == 0, "input dimension must be dividable by M"
        self.Ds = int(D / self.M)

        np.random.seed(seed)
        if self.verbose:
            print("iter: {}, seed: {}".format(iter, seed))

        self.codewords = np.zeros((self.M, self.Ks, self.Ds), dtype=np.float32)
        for m in range(self.M):
            if self.verbose:
                print("Training the subspace: {} / {}".format(m, self.M))
            vecs_sub = vecs[:, m * self.Ds : (m+1) * self.Ds]
            self.codewords[m], _ = kmeans2(vecs_sub, self.Ks, iter=iter, minit='points')

        return self

Given training vectors, run k-means for each sub-space and create
codewords for each sub-space.

This function should be run once first of all.

Args:
vecs (np.ndarray): Training vectors with shape=(N, D) and dtype=np.float32.
iter (int): The number of iteration for k-means
seed (int): The seed for random process

Returns:
object: self


def add_grad(left, right):

  assert left is not None and right is not None
  left_type = type(left)
  right_type = type(right)
  if left_type is ZeroGradient:
    return right
  if right_type is ZeroGradient:
    return left
  return grad_adders[(left_type, right_type)](left, right)

Recursively add the gradient of two objects.

Args:
left: The left value to add. Can be either an array, a number, list or
dictionary.
right: The right value. Must be of the same type (recursively) as the left.

Returns:
The sum of the two gradients, which will of the same type.


def Process(self, path):

    path = re.sub(self.SYSTEMROOT_RE, r"%systemroot%", path, count=1)
    path = re.sub(self.SYSTEM32_RE, r"%systemroot%\\system32", path, count=1)

    matches_iter = self.WIN_ENVIRON_REGEX.finditer(path)
    var_names = set(m.group(1).lower() for m in matches_iter)

    results = [path]
    for var_name in var_names:
      try:
        var_regex, var_value = self.vars_map[var_name]
      except KeyError:
        continue

      if isinstance(var_value, string_types):
        replacements = [var_value]
      else:
        replacements = var_value

      processed_results = []
      for result in results:
        for repl in replacements:

          processed_results.append(var_regex.sub(lambda _: repl, result))
      results = processed_results

    return results

Processes a given path.

Args:
path: Path (as a string) to post-process.

Returns:
A list of paths with environment variables replaced with their
values. If the mapping had a list of values for a particular variable,
instead of just one value, then all possible replacements will be
returned.


def update_dependency(self, tile, depinfo, destdir=None):
    if (destdir is None):
        destdir = os.path.join(tile.folder, 'build', 'deps', depinfo['unique_id'])
    has_version = False
    had_version = False
    if os.path.exists(destdir):
        has_version = True
        had_version = True
    for (priority, rule) in self.rules:
        if (not self._check_rule(rule, depinfo)):
            continue
        resolver = self._find_resolver(rule)
        if has_version:
            deptile = IOTile(destdir)
            depstatus = self._check_dep(depinfo, deptile, resolver)
            if (depstatus is False):
                shutil.rmtree(destdir)
                has_version = False
            else:
                continue
        result = resolver.resolve(depinfo, destdir)
        if ((not result['found']) and result.get('stop', False)):
            return 'not found'
        if (not result['found']):
            continue
        settings = {'resolver': resolver.__class__.__name__, 'factory_args': rule[2]}
        if ('settings' in result):
            settings['settings'] = result['settings']
        self._save_depsettings(destdir, settings)
        if had_version:
            return 'updated'
        return 'installed'
    if has_version:
        return 'already installed'
    return 'not found'

Attempt to install or update a dependency to the latest version.

Args:
tile (IOTile): An IOTile object describing the tile that has the dependency
depinfo (dict): a dictionary from tile.dependencies specifying the dependency
destdir (string): An optional folder into which to unpack the dependency

Returns:
string: a string indicating the outcome.  Possible values are:
"already installed"
"installed"
"updated"
"not found"


def track_usage(tool_id, tags):
    del tool_id, tags

No usage tracking for external library.

Args:
tool_id: A string identifier for tool to be tracked.
tags: list of string tags that will be added to the tracking.


def calculate_oobatake_dH(seq, temp):

    seq = ssbio.protein.sequence.utils.cast_to_str(seq)

    dH = 0
    temp += 273.15
    T0 = 298.15
    for aa in seq:
        H0 = oobatake_dictionary[aa]['dH'] * 1000
        dH += H0
    return dH + _sum_of_dCp(seq) * (temp - T0)

Get dH using Oobatake method in units cal/mol.

Args:
seq (str, Seq, SeqRecord): Amino acid sequence
temp (float): Temperature in degrees C

Returns:
float: dH in units cal/mol


def foreach_loop(self, context):
    logger.debug('starting')
    foreach = context.get_formatted_iterable(self.foreach_items)
    foreach_length = len(foreach)
    logger.info(f'foreach decorator will loop {foreach_length} times.')
    for i in foreach:
        logger.info(f'foreach: running step {i}')
        context['i'] = i
        self.run_conditional_decorators(context)
        logger.debug(f'foreach: done step {i}')
    logger.debug(f'foreach decorator looped {foreach_length} times.')
    logger.debug('done')

Run step once for each item in foreach_items.

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

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


def info(self, channel_id):

        resource = 'v1/channel.info?channel_id={}'.format(channel_id)
        resp = self._rtm_client.get(resource)
        if resp.is_fail():
            raise RTMServiceError("Failed to get channel information", resp)

        return resp.data['result']

Gets channel information by channel id

Args:
channel_id(int): the id of channel

Returns:
Channel

Throws:
RTMServiceError when request failed


def codemirror_field_css_bundle(field):

    manifesto = CodemirrorAssetTagRender()
    manifesto.register_from_fields(field)

    try:
        bundle_name = manifesto.css_bundle_names()[0]
    except IndexError:
        msg = ("Given field with configuration name '{}' does not have a "
               "Javascript bundle name")
        raise CodeMirrorFieldBundleError(msg.format(field.config_name))

    return bundle_name

Filter to get CodeMirror CSS bundle name needed for a single field.

Example:
::

{% load djangocodemirror_tags %}
{{ form.myfield|codemirror_field_css_bundle }}

Arguments:
field (djangocodemirror.fields.CodeMirrorField): A form field.

Raises:
CodeMirrorFieldBundleError: Raised if Codemirror configuration from
field does not have a bundle name.

Returns:
string: Bundle name to load with webassets.


def get_tf_dataset(self):
    raise NotImplementedError

Get a `tf.data.Dataset` instance for the DataAdapter.

Note that the dataset returned does not repeat for epoch, so caller
might need to create new iterator for the same dataset at the beginning
of the epoch. This behavior might change in the future.

Returns:
A `tf.data.Dataset`. Caller might use the dataset in different
context, e.g. iter(dataset) in eager to get the value directly, or
in graph mode, provide the iterator tensor to Keras model function.


def _update(self, baseNumber, magnification):
    interval = int((baseNumber * magnification))
    self.value = [IntegerSingle(interval)]

update self.value with basenumber and time interval

Args:
baseNumber (str): self.baseNumber
magnification (str): self.magnification


def decode_from_file(estimator,
                     vocabulary,
                     model_type,
                     batch_size,
                     sequence_length,
                     checkpoint_path="",
                     input_filename=gin.REQUIRED,
                     output_filename=gin.REQUIRED,
                     eos_id=1):

  with tf.gfile.Open(input_filename) as f:
    text = f.read()
  records = text.split("\n")
  inputs = [record.strip() for record in records]

  if not inputs[-1]:
    inputs.pop()
  n = len(inputs)

  all_input_ids = []
  for line in inputs:
    ids = inputs_vocabulary(vocabulary).encode(line.strip())
    if model_type != "lm":

      ids += [eos_id]
    if len(ids) > sequence_length:
      ids = ids[:sequence_length]
    else:
      ids.extend([0] * (sequence_length - len(ids)))
      all_input_ids.append(ids)

  all_input_ids.extend([all_input_ids[0]] * (-n % batch_size))
  padded_n = len(all_input_ids)
  all_input_ids = np.array(all_input_ids, dtype=np.int32)

  def input_fn(params):
    del params
    dataset = tf.data.Dataset.from_tensor_slices({"inputs": all_input_ids})
    dataset = dataset.batch(batch_size, drop_remainder=True)
    return dataset

  result_iter = estimator.predict(input_fn, checkpoint_path=checkpoint_path)
  vocab_size = targets_vocabulary(vocabulary).vocab_size
  decodes = []
  for i, result in enumerate(result_iter):
    output_ids = clean_decodes(list(result["outputs"]), vocab_size)
    output_string = targets_vocabulary(vocabulary).decode(
        [int(x) for x in output_ids])
    decodes.append(output_string)
    if i & (i - 1) == 0:
      if i < len(inputs):

        tf.logging.info("decode %d input = %s" % (i, inputs[i]))
        tf.logging.info("          output = %s" % output_string)

  if len(decodes) == padded_n:
    tf.logging.info("number of decodes matches number of inputs")
  elif len(decodes) % padded_n == 0:
    num_cores = len(decodes)
    tf.logging.info("output is repeated num_cores times - removing extras")

    def keep(i):
      return i % (batch_size * num_cores) < batch_size

    decodes = [d for i, d in enumerate(decodes) if keep(i)]
  else:
    raise ValueError("unexpected number of outputs")
  output_file = tf.gfile.Open(output_filename, "w")
  decodes = decodes[:n]
  for d in decodes:
    output_file.write(d)
    output_file.write("\n")
  output_file.close()

Decode from a text file.

Args:
estimator: a TPUEstimator
vocabulary: a mtf.transformer.vocabulary.Vocabulary
model_type: a string
batch_size: an integer
sequence_length: an integer (maximum decode length)
checkpoint_path: an optional string
input_filename: a string
output_filename: a string
eos_id: EOS id


def get_course_modes(self, course_id):
    details = self.get_course_details(course_id)
    modes = details.get('course_modes', [])
    return self._sort_course_modes([mode for mode in modes if (mode['slug'] not in EXCLUDED_COURSE_MODES)])

Query the Enrollment API for the specific course modes that are available for the given course_id.

Arguments:
course_id (str): The string value of the course's unique identifier

Returns:
list: A list of course mode dictionaries.


def ParseDesc(self, start_line=0):
    exec_mod_start = (self.executable + ':')
    after_blank = 0
    start_line = 0
    for start_line in range(start_line, len(self.output)):
        line = self.output[start_line].rstrip()
        if (('flags:' == line) and (len(self.output) > (start_line + 1)) and ('' == self.output[(start_line + 1)].rstrip())):
            start_line += 2
            logging.debug(('Flags start (python): %s' % line))
            return (start_line, 'python')
        if (exec_mod_start == line):
            logging.debug(('Flags start (swig): %s' % line))
            return (start_line, 'python')
        if (after_blank and line.startswith('  Flags from ')):
            logging.debug(('Flags start (c): %s' % line))
            return (start_line, 'c')
        if (line == 'where flags are'):
            logging.debug(('Flags start (java): %s' % line))
            start_line += 2
            return (start_line, 'java')
        logging.debug(('Desc: %s' % line))
        self.desc.append(line)
        after_blank = (line == '')
    else:
        logging.warn(('Never found the start of the flags section for "%s"!' % self.long_name))
        return ((- 1), '')

Parse the initial description.

This could be Python or C++.

Returns:
(start_line, lang_type)
start_line  Line to start parsing flags on (int)
lang_type   Either 'python' or 'c'
(-1, '')  if the flags start could not be found


def _volatility_squared_from_volatility(self, volatility, volatility_is_constant, dtype=None, name=None):
    name = name or self._name + '_volatility_squared'
    if volatility_is_constant:
        return volatility ** 2
    else:
        return pw.PiecewiseConstantFunc(volatility.jump_locations(), volatility.values() ** 2, dtype=dtype, name=name)

Returns volatility squared as either a `PiecewiseConstantFunc` or a `Tensor`.

Args:
volatility: Either a 'Tensor' or 'PiecewiseConstantFunc'.
volatility_is_constant: `bool` which is True if volatility is of type
`Tensor`.
dtype: The default dtype to use when converting values to `Tensor`s.
Default value: `None` which means that default dtypes inferred by
TensorFlow are used.
name: Python string. The name to give to the ops created by this class.
Default value: `None` which maps to the default name
'_volatility_squared'.


def playlist_songs(self, playlist):
    playlist_type = playlist.get('type')
    playlist_song_list = []
    if (playlist_type in ('USER_GENERATED', None)):
        start_token = None
        playlist_song_list = []
        while True:
            response = self._call(mc_calls.PlaylistEntryFeed, max_results=49995, start_token=start_token)
            items = response.body.get('data', {}).get('items', [])
            if items:
                playlist_song_list.extend(items)
            start_token = response.body.get('nextPageToken')
            if (start_token is None):
                break
    elif (playlist_type == 'SHARED'):
        playlist_share_token = playlist['shareToken']
        start_token = None
        playlist_song_list = []
        while True:
            response = self._call(mc_calls.PlaylistEntriesShared, playlist_share_token, max_results=49995, start_token=start_token)
            entry = response.body['entries'][0]
            items = entry.get('playlistEntry', [])
            if items:
                playlist_song_list.extend(items)
            start_token = entry.get('nextPageToken')
            if (start_token is None):
                break
    playlist_song_list.sort(key=itemgetter('absolutePosition'))
    return playlist_song_list

Get a listing of songs from a playlist.

Paramters:
playlist (dict): A playlist dict.

Returns:
list: Playlist song dicts.


def strace_clear(self, handle):

        data = ctypes.c_int(handle)
        res = self._dll.JLINK_STRACE_Control(enums.JLinkStraceCommand.TRACE_EVENT_CLR, ctypes.byref(data))
        if res < 0:
            raise errors.JLinkException('Failed to clear STRACE event.')

        return None

Clears the trace event specified by the given handle.

Args:
self (JLink): the ``JLink`` instance.
handle (int): handle of the trace event.

Returns:
``None``

Raises:
JLinkException: on error.


def _MergeMessageField(self, tokenizer, message, field):
    is_map_entry = _IsMapEntry(field)
    if tokenizer.TryConsume('<'):
        end_token = '>'
    else:
        tokenizer.Consume('{')
        end_token = '}'
    if (field.label == descriptor.FieldDescriptor.LABEL_REPEATED):
        if field.is_extension:
            sub_message = message.Extensions[field].add()
        elif is_map_entry:
            sub_message = field.message_type._concrete_class()
        else:
            sub_message = getattr(message, field.name).add()
    else:
        if field.is_extension:
            sub_message = message.Extensions[field]
        else:
            sub_message = getattr(message, field.name)
        sub_message.SetInParent()
    while (not tokenizer.TryConsume(end_token)):
        if tokenizer.AtEnd():
            raise tokenizer.ParseErrorPreviousToken(('Expected "%s".' % (end_token,)))
        self._MergeField(tokenizer, sub_message)
    if is_map_entry:
        value_cpptype = field.message_type.fields_by_name['value'].cpp_type
        if (value_cpptype == descriptor.FieldDescriptor.CPPTYPE_MESSAGE):
            value = getattr(message, field.name)[sub_message.key]
            value.MergeFrom(sub_message.value)
        else:
            getattr(message, field.name)[sub_message.key] = sub_message.value

Merges a single scalar field into a message.

Args:
tokenizer: A tokenizer to parse the field value.
message: The message of which field is a member.
field: The descriptor of the field to be merged.

Raises:
ParseError: In case of text parsing problems.


def to_json(self, drop_null=True, camel=False, indent=None, sort_keys=False):

        return json.dumps(self.to_dict(drop_null, camel), indent=indent,
                          sort_keys=sort_keys)

Serialize self as JSON

Args:
drop_null: bool, default True. Remove 'empty' attributes. See
to_dict.
camel: bool, default True. Convert keys to camelCase.
indent: int, default None. See json built-in.
sort_keys: bool, default False. See json built-in.

Return:
str: object params.


def FormatType(self, level_name, class_problist):
    class_problist.sort()
    output = []
    for (classname, problist) in class_problist:
        output.append(('
%s

\n' % (level_name, classname, UnCamelCase(classname))))
        for e in problist.problems:
            self.FormatException(e, output)
        if problist.dropped_count:
            output.append(('
and %d more of this type.' % problist.dropped_count))
        output.append('
\n')
    return ''.join(output)

Write the HTML dumping all problems of one type.

Args:
level_name: string such as "Error" or "Warning"
class_problist: sequence of tuples (class name,
BoundedProblemList object)

Returns:
HTML in a string


def LoadData(self, data, custom_properties=None):
    self.__data = []
    self.AppendData(data, custom_properties)

Loads new rows to the data table, clearing existing rows.

May also set the custom_properties for the added rows. The given custom
properties dictionary specifies the dictionary that will be used for *all*
given rows.

Args:
data: The rows that the table will contain.
custom_properties: A dictionary of string to string to set as the custom
properties for all rows.


def get_outer_class(cls: Type[Any], base_cls: Union[Type[Any], Tuple[Type[Any], ...], None]=None, immediate: bool=False) -> Optional[Type[Any]]:
    if '<locals>' in cls.__qualname__:
        raise ValueError(f'Cannot find the outer class for locally defined class {cls.__qualname__!r}')
    names = cls.__qualname__.split('.')
    if len(names) < 2:
        return None
    parent = sys.modules[cls.__module__]
    symbols = []
    for name in names[:-1]:
        symbol = getattr(parent, name, None)
        if symbol is None:
            return None
        assert inspect.isclass(symbol), symbol
        symbols.append(symbol)
        parent = symbol
    for symbol in reversed(symbols):
        if immediate:
            return symbol if not base_cls or issubclass(symbol, base_cls) else None
        if not base_cls or issubclass(symbol, base_cls):
            return symbol
    return None

Returns the outer class.

Example::

class A:
pass

class A1:
class B:
class C:
...

pg.typing.outer_class(B) is A1
pg.typing.outer_class(C) is B
pg.typing.outer_class(C, base_cls=A) is None
pg.typing.outer_class(C, base_cls=A1) is None

Args:
cls: The class to get the outer class for.
base_cls: The base class of the outer class. If provided, an outer class
that is not a subclass of `base_cls` will be returned as None.
immediate: Whether to return the immediate outer class or a class in the
nesting hierarchy that is a subclass of `base_cls`. Applicable when
`base_cls` is not None.

Returns:
The outer class of `cls`. None if cannot find one or the outer class is
not a subclass of `base_cls`.


def FromTXOutputsConfirmed(outputs):

        uns = UnspentCoinState()
        uns.Items = [0] * len(outputs)
        for i in range(0, len(outputs)):
            uns.Items[i] = int(CoinState.Confirmed)
        return uns

Get unspent outputs from a list of transaction outputs.

Args:
outputs (list): of neo.Core.TX.Transaction.TransactionOutput items.

Returns:
UnspentCoinState:


def GetAllClientLabels(token, include_catchall=False):

  labels_index = aff4.FACTORY.Create(
      standard.LabelSet.CLIENT_LABELS_URN,
      standard.LabelSet,
      mode="r",
      token=token)
  labels = set(labels_index.ListLabels())
  if include_catchall:
    labels.add(ALL_CLIENTS_LABEL)
  return labels

Get the set of all label names applied to all clients.

Args:
token: token to use when opening the index.
include_catchall: If true, we include ALL_CLIENTS_LABEL in the results.

Returns:
set of label name strings, including the catchall "All"


def images(self, **kwargs):

        path = self._get_id_path('images')

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

Get the images (posters and backdrops) for a specific movie id.

Args:
language: (optional) ISO 639-1 code.
append_to_response: (optional) Comma separated, any movie method.
include_image_language: (optional) Comma separated, a valid
ISO 69-1.

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


def to_namedtuple(self):
    keys = filter((lambda x: (not x.startswith('_'))), self.__dict__)
    opt_nt = namedtuple(self.__class__.__name__, keys)
    filtered_dict = dict(map((lambda x: (x, self.__dict__[x])), keys))
    return opt_nt(**filtered_dict)

Convert class to namedtuple.

Note:
This method is neccessary for AMQP communication.

Returns:
namedtuple: Representation of the class as simple structure.


def _remove_ancillary_layers(model, layer_map, layers):
    ancillary_layers = []
    if not model._is_graph_network:
        return (layers, ancillary_layers)
    depths = [depth for depth in model._nodes_by_depth.keys() if depth < 0]
    depths.sort(reverse=True)
    for depth in depths:
        for node in model._nodes_by_depth[depth]:
            ancillary_layers.append(layer_map[node.outbound_layer])
    return ([l for l in layers if l not in ancillary_layers], ancillary_layers)

Removes and returns any ancillary layers from `layers` based on `model`.

Ancillary layers are part of the model topology but not used to compute the
model outputs, e.g., layers from `add_loss` and `add_metric`.

Args:
model: A Keras Model.
layer_map: A map to from layers in the `model` to those in `layers`.
layers: A list of all layers.

Returns:
Two lists of layers: (1) `layers` with the ancillary layers removed, and (2)
the ancillary layers.


def parse_xml(self, xml_file, check_version=True, check_root=True, encoding=None):
    xml_etree = get_etree(xml_file, encoding=encoding)
    entity_obj = self.parse_xml_to_obj(xml_file=xml_etree, check_version=check_version, check_root=check_root)
    xml_root_node = xml_etree.getroot()
    entity = self.get_entity_class(xml_root_node.tag).from_obj(entity_obj)
    entity.__input_namespaces__ = dict(iteritems(xml_root_node.nsmap))
    with ignored(KeyError):
        pairs = get_schemaloc_pairs(xml_root_node)
        entity.__input_schemalocations__ = dict(pairs)
    return entity

Creates a python-stix STIXPackage object from the supplied xml_file.

Args:
xml_file: A filename/path or a file-like object representing a STIX
instance document
check_version: Inspect the version before parsing.
check_root: Inspect the root element before parsing.
encoding: The character encoding of the input `xml_file`. If
``None``, an attempt will be made to determine the input
character encoding.

Raises:
.UnknownVersionError: If `check_version` is ``True`` and `xml_file`
does not contain STIX version information.
.UnsupportedVersionError: If `check_version` is ``False`` and
`xml_file` contains an unsupported STIX version.
.UnsupportedRootElement: If `check_root` is ``True`` and `xml_file`
contains an invalid root element.


def from_csv(input_csv_pattern, headers=None, schema_file=None):
    if (headers is not None):
        names = headers
    elif (schema_file is not None):
        with _util.open_local_or_gcs(schema_file, mode='r') as f:
            schema = json.load(f)
        names = [x['name'] for x in schema]
    else:
        raise ValueError('Either headers or schema_file is needed')
    metrics = Metrics(input_csv_pattern=input_csv_pattern, headers=names)
    return metrics

Create a Metrics instance from csv file pattern.

Args:
input_csv_pattern: Path to Csv file pattern (with no header). Can be local or GCS path.
headers: Csv headers.
schema_file: Path to a JSON file containing BigQuery schema. Used if "headers" is None.

Returns:
a Metrics instance.

Raises:
ValueError if both headers and schema_file are None.


def audio(self, tag, audiodata, step=None, sample_rate=44100):

    audiodata = onp.array(audiodata)
    if step is None:
      step = self._step
    else:
      self._step = step
    audiodata = onp.clip(onp.squeeze(audiodata), -1, 1)
    if audiodata.ndim != 1:
      raise ValueError('Audio data must be 1D.')
    sample_list = (32767.0 * audiodata).astype(int).tolist()
    wio = io.BytesIO()
    wav_buf = wave.open(wio, 'wb')
    wav_buf.setnchannels(1)
    wav_buf.setsampwidth(2)
    wav_buf.setframerate(sample_rate)
    enc = b''.join([struct.pack('<h', v) for v in sample_list])
    wav_buf.writeframes(enc)
    wav_buf.close()
    encoded_audio_bytes = wio.getvalue()
    wio.close()
    audio = Summary.Audio(
        sample_rate=sample_rate,
        num_channels=1,
        length_frames=len(sample_list),
        encoded_audio_string=encoded_audio_bytes,
        content_type='audio/wav')
    summary = Summary(value=[Summary.Value(tag=tag, audio=audio)])
    self.add_summary(summary, step)

Saves audio.

NB: single channel only right now.

Args:
tag: str: label for this data
audiodata: ndarray [Nsamples,]: data between (-1.0,1.0) to save as wave
step: int: training step
sample_rate: sample rate of passed in audio buffer


def __init__(
      self, maximum_buffer_size=0,
      storage_type=definitions.STORAGE_TYPE_SESSION):

    if (maximum_buffer_size < 0 or
        maximum_buffer_size > self._MAXIMUM_BUFFER_SIZE):
      raise ValueError('Maximum buffer size value out of bounds.')

    if not maximum_buffer_size:
      maximum_buffer_size = self._MAXIMUM_BUFFER_SIZE

    super(SQLiteStorageFile, self).__init__()
    self._connection = None
    self._cursor = None
    self._last_session = 0
    self._maximum_buffer_size = maximum_buffer_size
    self._serialized_event_heap = event_heaps.SerializedEventHeap()

    if storage_type == definitions.STORAGE_TYPE_SESSION:
      self.compression_format = definitions.COMPRESSION_FORMAT_ZLIB
    else:
      self.compression_format = definitions.COMPRESSION_FORMAT_NONE

    self.format_version = self._FORMAT_VERSION
    self.serialization_format = definitions.SERIALIZER_FORMAT_JSON
    self.storage_type = storage_type

Initializes a store.

Args:
maximum_buffer_size (Optional[int]):
maximum size of a single storage stream. A value of 0 indicates
the limit is _MAXIMUM_BUFFER_SIZE.
storage_type (Optional[str]): storage type.

Raises:
ValueError: if the maximum buffer size value is out of bounds.


def tile(self, bbox, z=0, format=None, clip=True):

        tile_srid = 3857
        bbox = getattr(bbox, 'geos', bbox)
        clone = filter_geometry(self, intersects=bbox)
        field = clone.geo_field
        srid = field.srid
        sql = field.name
        try:
            tilew = self.tilewidths[z]
        except IndexError:
            tilew = self.tilewidths[-1]
        if bbox.srid != srid:
            bbox = bbox.transform(srid, clone=True)

        if bbox.srs.geographic:
            p = geos.Point(tilew, tilew, srid=tile_srid)
            p.transform(srid)
            tilew = p.x
        if clip:
            bufbox = bbox.buffer(tilew)
            sql = geofn.Intersection(sql, bufbox.envelope)
        sql = SimplifyPreserveTopology(sql, tilew)
        if format == 'pbf':
            return clone.pbf(bbox, geo_col=sql)
        sql = geofn.Transform(sql, 4326)
        return clone.annotate(**{format: sql})

Returns a GeoQuerySet intersecting a tile boundary.

Arguments:
bbox -- tile extent as geometry
Keyword args:
z -- tile zoom level used as basis for geometry simplification
format -- vector tile format as str (pbf, geojson)
clip -- clip geometries to tile boundary as boolean


def is_course_in_catalog(self, catalog_id, course_id):

        try:

            course_run_id = str(CourseKey.from_string(course_id))
        except InvalidKeyError:
            course_run_id = None

        endpoint = self.client.catalogs(catalog_id).contains

        if course_run_id:
            resp = endpoint.get(course_run_id=course_run_id)
        else:
            resp = endpoint.get(course_id=course_id)

        return resp.get('courses', {}).get(course_id, False)

Determine if the given course or course run ID is contained in the catalog with the given ID.

Args:
catalog_id (int): The ID of the catalog
course_id (str): The ID of the course or course run

Returns:
bool: Whether the course or course run is contained in the given catalog


def _get_num_multimodal_tokens(self, image_sizes=None, **kwargs):
    vision_data = {}
    if image_sizes is not None:
        images_kwargs = PixtralProcessorKwargs._defaults.get('images_kwargs', {})
        images_kwargs.update(kwargs)
        size = images_kwargs.get('size', None) or self.image_processor.size
        patch_size = self.patch_size * self.spatial_merge_size
        num_image_tokens = []
        for height, width in image_sizes:
            resized_height, resized_width = get_resize_output_image_size(np.zeros((height, width, 3)), size=(size['longest_edge'], size['longest_edge']), patch_size=(patch_size, patch_size))
            num_height_tokens = resized_height
            num_width_tokens = resized_width
            num_image_tokens.append((num_width_tokens + 1) * num_height_tokens)
        num_image_patches = [1] * len(image_sizes)
        vision_data.update({'num_image_tokens': num_image_tokens, 'num_image_patches': num_image_patches})
    return MultiModalData(**vision_data)

Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.

Args:
image_sizes (`List[List[int]]`, *optional*):
The input sizes formatted as (height, width) per each image.

Returns:
`MultiModalData`: A `MultiModalData` object holding number of tokens per each of the provided
input modalities, along with other useful data.


def convert_to_categorical(df):

        might_be_categorical = df.select_dtypes(include=[object]).columns.tolist()
        for column in might_be_categorical:
            if df[column].nunique() < 20:

                print('Changing column {:s} to category...'.format(column))
                df[column] = pd.Categorical(df[column])

Run a heuristic on the columns of the dataframe to determine whether it contains categorical values
if the heuristic decides it's categorical then the type of the column is changed
Args:
df (dataframe): The dataframe to check for categorical data


def generate_argument_parser(cls, tree, actions={}):

        cur_as, cur_subas = tree
        parser = devassistant_argparse.ArgumentParser(argument_default=argparse.SUPPRESS,
                                                      usage=argparse.SUPPRESS,
                                                      add_help=False)

        cls.add_default_arguments_to(parser)

        for arg in cur_as.args:
            arg.add_argument_to(parser)

        if cur_subas or actions:

            subparsers = cls._add_subparsers_required(parser,
                dest=settings.SUBASSISTANT_N_STRING.format('0'))
            for subas in sorted(cur_subas, key=lambda x: x[0].name):
                for alias in [subas[0].name] + getattr(subas[0], 'aliases', []):
                    cls.add_subassistants_to(subparsers, subas, level=1, alias=alias)

            for action, subactions in sorted(actions.items(), key=lambda x: x[0].name):
                cls.add_action_to(subparsers, action, subactions, level=1)

        return parser

Generates argument parser for given assistant tree and actions.

Args:
tree: assistant tree as returned by
devassistant.assistant_base.AssistantBase.get_subassistant_tree
actions: dict mapping actions (devassistant.actions.Action subclasses) to their
subaction dicts
Returns:
instance of devassistant_argparse.ArgumentParser (subclass of argparse.ArgumentParser)


class PoolerEndLogits(nn.Module):

    def __init__(self, config: PretrainedConfig):
        super().__init__()
        self.dense_0 = nn.Linear(config.hidden_size * 2, config.hidden_size)
        self.activation = nn.Tanh()
        self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
        self.dense_1 = nn.Linear(config.hidden_size, 1)
        logger.warning_once('[DEPRECATION WARNING] `PoolerEndLogits` is deprecated and will be removed in v4.53. Please use model-specific class, e.g. `XLMPoolerEndLogits`.')

    def forward(self, hidden_states: torch.FloatTensor, start_states: Optional[torch.FloatTensor]=None, start_positions: Optional[torch.LongTensor]=None, p_mask: Optional[torch.FloatTensor]=None) -> torch.FloatTensor:

        assert start_states is not None or start_positions is not None, 'One of start_states, start_positions should be not None'
        if start_positions is not None:
            slen, hsz = hidden_states.shape[-2:]
            start_positions = start_positions[:, None, None].expand(-1, -1, hsz)
            start_states = hidden_states.gather(-2, start_positions)
            start_states = start_states.expand(-1, slen, -1)
        x = self.dense_0(torch.cat([hidden_states, start_states], dim=-1))
        x = self.activation(x)
        x = self.LayerNorm(x)
        x = self.dense_1(x).squeeze(-1)
        if p_mask is not None:
            if get_parameter_dtype(self) == torch.float16:
                x = x * (1 - p_mask) - 65500 * p_mask
            else:
                x = x * (1 - p_mask) - 1e+30 * p_mask
        return x

Compute SQuAD end logits from sequence hidden states.

Args:
config ([`PretrainedConfig`]):
The config used by the model, will be used to grab the `hidden_size` of the model and the `layer_norm_eps`
to use.


def GetTemplateArgs(clean_lines, linenum):

  func_line = linenum
  while func_line > 0:
    line = clean_lines.elided[func_line]
    if Match(r'^\s*$', line):
      return set()
    if line.find('(') >= 0:
      break
    func_line -= 1
  if func_line == 0:
    return set()

  argument_list = ''
  match = Match(r'^(\s*template\s*)<', clean_lines.elided[func_line])
  if match:

    start_col = len(match.group(1))
    _, end_line, end_col = CloseExpression(clean_lines, func_line, start_col)
    if end_col > -1 and end_line == func_line:
      start_col += 1
      argument_list = clean_lines.elided[func_line][start_col:end_col]

  elif func_line > 1:

    match = Match(r'^(.*)>\s*$', clean_lines.elided[func_line - 1])
    if match:
      end_col = len(match.group(1))
      _, start_line, start_col = ReverseCloseExpression(
          clean_lines, func_line - 1, end_col)
      if start_col > -1:
        start_col += 1
        while start_line < func_line - 1:
          argument_list += clean_lines.elided[start_line][start_col:]
          start_col = 0
          start_line += 1
        argument_list += clean_lines.elided[func_line - 1][start_col:end_col]

  if not argument_list:
    return set()

  typenames = set()
  while True:
    match = Match(r'^[,\s]*(?:typename|class)(?:\.\.\.)?\s+(\w+)(.*)$',
                  argument_list)
    if not match:
      break
    typenames.add(match.group(1))
    argument_list = match.group(2)
  return typenames

Find list of template arguments associated with this function declaration.

Args:
clean_lines: A CleansedLines instance containing the file.
linenum: Line number containing the start of the function declaration,
usually one line after the end of the template-argument-list.
Returns:
Set of type names, or empty set if this does not appear to have
any template parameters.


def init_app(self, app):
    app.url_rule_class = partial(NavigationRule, copilot=self)
    app.context_processor(self.inject_context)

Register the extension with the application.

Args:
app (flask.Flask): The application to register with.


def _ReadDefinitionFile(self, filename):
    if (not filename):
        return None
    path = os.path.join(self._DEFINITION_FILES_PATH, filename)
    with open(path, 'rb') as file_object:
        definition = file_object.read()
    return dtfabric_fabric.DataTypeFabric(yaml_definition=definition)

Reads a dtFabric definition file.

Args:
filename (str): name of the dtFabric definition file.

Returns:
dtfabric.DataTypeFabric: data type fabric which contains the data format
data type maps of the data type definition, such as a structure, that
can be mapped onto binary data or None if no filename is provided.


def __init__(self, file_object, end_of_line=b'\n'):

    super(BinaryLineReader, self).__init__()
    self._file_object = file_object
    self._file_object_size = file_object.get_size()
    self.end_of_line = end_of_line
    self._end_of_line_length = len(self.end_of_line)
    self._lines = []
    self._lines_buffer = b''
    self._lines_buffer_offset = 0
    self._current_offset = 0

Initializes the line reader.

Args:
file_object (FileIO): a file-like object to read from.
end_of_line (Optional[bytes]): end of line indicator.


def batch_encode_plus_boxes(self, batch_text_or_text_pairs: Union[List[TextInput], List[TextInputPair], List[PreTokenizedInput]], is_pair: Optional[bool]=None, boxes: Optional[List[List[List[int]]]]=None, word_labels: Optional[List[List[int]]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, stride: int=0, is_split_into_words: bool=False, pad_to_multiple_of: Optional[int]=None, padding_side: Optional[str]=None, return_tensors: Optional[Union[str, TensorType]]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_offsets_mapping: bool=False, return_length: bool=False, verbose: bool=True, **kwargs) -> BatchEncoding:
    padding_strategy, truncation_strategy, max_length, kwargs = self._get_padding_truncation_strategies(padding=padding, truncation=truncation, max_length=max_length, pad_to_multiple_of=pad_to_multiple_of, verbose=verbose, **kwargs)
    return self._batch_encode_plus_boxes(batch_text_or_text_pairs=batch_text_or_text_pairs, is_pair=is_pair, boxes=boxes, word_labels=word_labels, add_special_tokens=add_special_tokens, padding_strategy=padding_strategy, truncation_strategy=truncation_strategy, max_length=max_length, stride=stride, is_split_into_words=is_split_into_words, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)

Tokenize and prepare for the model a list of sequences or a list of pairs of sequences.

Args:
batch_text_or_text_pairs (`List[str]`, `List[Tuple[str, str]]`, `List[List[str]]`, `List[Tuple[List[str], List[str]]]`, and for not-fast tokenizers, also `List[List[int]]`, `List[Tuple[List[int], List[int]]]`):
Batch of sequences or pair of sequences to be encoded. This can be a list of
string/string-sequences/int-sequences or a list of pair of string/string-sequences/int-sequence (see
details in `encode_plus`).


def cos(self: EventSetOrNode) -> EventSetOrNode:
    from temporian.core.operators.unary import cos
    return cos(self)

Calculates the cosine of an [`EventSet`][temporian.EventSet]'s features.

Can only be used on floating point features.

Example:
```python
>>> a = tp.event_set(
...     timestamps=[1, 2, 3, 4, 5],
...     features={"M": [0, np.pi/3, np.pi/2, np.pi, 2*np.pi]},
... )
>>> a.cos()
indexes: ...
timestamps: [1. 2. 3. 4. 5.]
'M': [ 1.0000e+00  5.0000e-01  6.1232e-17 -1.0000e+00  1.0000e+00]
...

```

Returns:
EventSetOrNode with cosine of input features.


def CheckVersion(problems, latest_version=None):

  if not latest_version:
    timeout = 20
    socket.setdefaulttimeout(timeout)
    request = urllib2.Request(LATEST_RELEASE_VERSION_URL)

    try:
      response = urllib2.urlopen(request)
      content = response.read()
      m = re.search(r'version=(\d+\.\d+\.\d+)', content)
      if m:
        latest_version = m.group(1)

    except urllib2.HTTPError as e:
      description = ('During the new-version check, we failed to reach '
                     'transitfeed server: Reason: %s [%s].' %
                     (e.reason, e.code))
      problems.OtherProblem(
        description=description, type=errors.TYPE_NOTICE)
      return
    except urllib2.URLError as e:
      description = ('During the new-version check, we failed to reach '
                     'transitfeed server. Reason: %s.' % e.reason)
      problems.OtherProblem(
        description=description, type=errors.TYPE_NOTICE)
      return

  if not latest_version:
    description = ('During the new-version check, we had trouble parsing the '
                   'contents of %s.' % LATEST_RELEASE_VERSION_URL)
    problems.OtherProblem(
      description=description, type=errors.TYPE_NOTICE)
    return

  newest_version = _MaxVersion([latest_version, __version__])
  if __version__ != newest_version:
    problems.NewVersionAvailable(newest_version)

Check if there is a newer version of transitfeed available.

Args:
problems: if a new version is available, a NewVersionAvailable problem will
be added
latest_version: if specified, override the latest version read from the
project page


def _add_sort(self, field, ascending=True):

        field = str(field)

        if field:
            self.__query["sort"].append({
                'field_name': field,
                'order': 'asc' if ascending else 'desc'
            })
        return self

Sort the search results by a certain field.

If this method is called multiple times, the later sort fields are given lower priority,
and will only be considered when the eariler fields have the same value.

Arguments:
field (str): The field to sort by, in Elasticsearch dot syntax.
ascending (bool): Sort in ascending order? **Default**: ``True``.

Returns:
SearchHelper: Self


def ngayThangNam(nn, tt, nnnn, duongLich=True, timeZone=7):

    thangNhuan = 0

    if nn > 0 and \
       nn < 32 and tt < 13 and tt > 0:
        if duongLich is True:
            [nn, tt, nnnn, thangNhuan] = S2L(nn, tt, nnnn, timeZone=timeZone)
        return [nn, tt, nnnn, thangNhuan]
    else:
        raise Exception("Ngày, tháng, năm không chính xác.")

Summary

Args:
nn (TYPE): ngay
tt (TYPE): thang
nnnn (TYPE): nam
duongLich (bool, optional): bool
timeZone (int, optional): +7 Vietnam

Returns:
TYPE: Description

Raises:
Exception: Description


def DeserializeUnsignedWithoutType(self, reader):
    self.Version = reader.ReadByte()
    self.DeserializeExclusiveData(reader)
    self.Attributes = reader.ReadSerializableArray('neo.Core.TX.TransactionAttribute.TransactionAttribute', max=self.MAX_TX_ATTRIBUTES)
    self.inputs = reader.ReadSerializableArray('neo.Core.CoinReference.CoinReference')
    self.outputs = reader.ReadSerializableArray('neo.Core.TX.Transaction.TransactionOutput')

Deserialize object without reading transaction type data.

Args:
reader (neo.IO.BinaryReader):


def less_equal(x, y):
    return math_ops.less_equal(x, y)

Element-wise truth value of (x <= y).

Args:
x: Tensor or variable.
y: Tensor or variable.

Returns:
A bool tensor.


def copy_r(src, dst):
    abssrc = os.path.abspath(src)
    absdst = os.path.abspath(dst)
    try:
        os.makedirs(absdst)
    except OSError:
        pass
    for f in os.listdir(abssrc):
        fpath = os.path.join(abssrc, f)
        if os.path.isfile(fpath):
            shutil.copy(fpath, absdst)
        elif (not absdst.startswith(fpath)):
            copy_r(fpath, os.path.join(absdst, f))
        else:
            warnings.warn(('Cannot copy %s to itself' % fpath))

Implements a recursive copy function similar to Unix's "cp -r" command.
Surprisingly, python does not have a real equivalent. shutil.copytree
only works if the destination directory is not present.

Args:
src (str): Source folder to copy.
dst (str): Destination folder.


def model_from_config(config, custom_objects=None):
    if isinstance(config, list):
        raise TypeError(f'`model_from_config` expects a dictionary, not a list. Received: config={config}. Did you meant to use `Sequential.from_config(config)`?')
    global MODULE_OBJECTS
    if not hasattr(MODULE_OBJECTS, 'ALL_OBJECTS'):
        MODULE_OBJECTS.ALL_OBJECTS = layers.__dict__
        MODULE_OBJECTS.ALL_OBJECTS['InputLayer'] = layers.InputLayer
        MODULE_OBJECTS.ALL_OBJECTS['Functional'] = models.Functional
        MODULE_OBJECTS.ALL_OBJECTS['Model'] = models.Model
        MODULE_OBJECTS.ALL_OBJECTS['Sequential'] = models.Sequential
    batch_input_shape = config['config'].pop('batch_input_shape', None)
    if batch_input_shape is not None:
        if config['class_name'] == 'InputLayer':
            config['config']['batch_shape'] = batch_input_shape
        else:
            config['config']['input_shape'] = batch_input_shape
    axis = config['config'].pop('axis', None)
    if axis is not None:
        if isinstance(axis, list) and len(axis) == 1:
            config['config']['axis'] = int(axis[0])
        elif isinstance(axis, (int, float)):
            config['config']['axis'] = int(axis)
    if config['class_name'] == 'Lambda':
        for dep_arg in LAMBDA_DEP_ARGS:
            _ = config['config'].pop(dep_arg, None)
        function_config = config['config']['function']
        if isinstance(function_config, list):
            function_dict = {'class_name': '__lambda__', 'config': {}}
            function_dict['config']['code'] = function_config[0]
            function_dict['config']['defaults'] = function_config[1]
            function_dict['config']['closure'] = function_config[2]
            config['config']['function'] = function_dict
    config = _find_replace_nested_dict(config, 'keras.', 'keras.')
    return serialization.deserialize_keras_object(config, module_objects=MODULE_OBJECTS.ALL_OBJECTS, custom_objects=custom_objects, printable_module_name='layer')

Instantiates a Keras model from its config.

Args:
config: Configuration dictionary.
custom_objects: Optional dictionary mapping names
(strings) to custom classes or functions to be
considered during deserialization.

Returns:
A Keras model instance (uncompiled).

Raises:
TypeError: if `config` is not a dictionary.


def table_chains(self, table="filter"):

        return dict((c["name"], self.get_chain(c["name"], table)) for c in self.get_table(table))

Get a dict where the keys are all the chains for the given table
and each value is the set of rules defined for the given chain.

Args:
table (str): table name, defaults to ``filter``

Returns:
dict: chains with set of defined rules


def build_attachment(self, text, target, attachment, thread):

        attachment = {
            'as_user': True,
            'text': text,
            'channel': target,
            'attachments': [
                {
                    'fallback': text,
                    'image_url': attachment
                }
            ]
        }
        if thread:
            attachment['thread_ts'] = thread
        return attachment

Builds a slack attachment.

Args:
message (Legobot.Message): message w/ metadata to send.

Returns:
attachment (dict): attachment data.


def random(self, pages=1):
    if ((pages is None) or (pages < 1)):
        raise ValueError('Number of pages must be greater than 0')
    query_params = {'list': 'random', 'rnnamespace': 0, 'rnlimit': pages}
    request = self.wiki_request(query_params)
    titles = [page['title'] for page in request['query']['random']]
    if (len(titles) == 1):
        return titles[0]
    return titles

Request a random page title or list of random titles

Args:
pages (int): Number of random pages to return
Returns:
list or int: A list of random page titles or a random page \
title if pages = 1


def setup_callbacks(self, callbacks, monitors):
    assert isinstance(callbacks, list), callbacks
    assert isinstance(monitors, list), monitors
    describe_trainable_vars()
    self.register_callback(MaintainStepCounter())
    for cb in callbacks:
        self.register_callback(cb)
    for cb in self._callbacks:
        assert (not isinstance(cb, MonitorBase)), 'Monitor cannot be pre-registered for now!'
    registered_monitors = []
    for m in monitors:
        if self.register_callback(m):
            registered_monitors.append(m)
    self.monitors = Monitors(registered_monitors)
    self.register_callback(self.monitors)
    logger.info('Setup callbacks graph ...')
    self._callbacks = Callbacks(self._callbacks)
    self._callbacks.setup_graph(weakref.proxy(self))

Setup callbacks and monitors. Must be called after the main graph is built.

Args:
callbacks ([Callback]):
monitors ([MonitorBase]):


def load(self, file_name):
    new_rundata = self.loader(file_name)
    new_rundata = self.inspect(new_rundata)
    return new_rundata

Load a raw data-file

Args:
file_name (path)

Returns:
loaded test


def on_message(self, message):
    try:
        self.log.debug('Got message %s', message)
        d = json_decode(message)
        response = deserialize_object(d, Response)
        if isinstance(response, (Return, Error)):
            request = self._request_lookup.pop(response.id)
            if isinstance(response, Error):
                response.message = ResponseError(response.message)
        else:
            request = self._request_lookup[response.id]
        cothread.Callback(request.callback, response)
    except Exception:
        self.log.exception('on_message(%r) failed', message)

Pass response from server to process receive queue

Args:
message(str): Received message


def save(self, data: dict):
    print(data)

Print the data.

Args:
data (`dict`): The data to store.


Args:
pipeline_options: Instance of ``PipelineOptions`` or dict of options and
values (like ``RuntimeValueProvider.runtime_options``).


def new_site(name, rgba=RED, pos=(0, 0, 0), size=(0.005,), **kwargs):

    kwargs["rgba"] = array_to_string(rgba)
    kwargs["pos"] = array_to_string(pos)
    kwargs["size"] = array_to_string(size)
    kwargs["name"] = name
    element = ET.Element("site", attrib=kwargs)
    return element

Creates a site element with attributes specified by @**kwargs.

Args:
name (str): site name.
rgba: color and transparency. Defaults to solid red.
pos: 3d position of the site.
size ([float]): site size (sites are spherical by default).


def AddCustomJsonFieldMapping(message_type, python_name, json_name,
                              package=None):

    if not issubclass(message_type, messages.Message):
        raise exceptions.TypecheckError(
            'Cannot set JSON field mapping for '
            'non-message "%s"' % message_type)
    try:
        _ = message_type.field_by_name(python_name)
    except KeyError:
        raise exceptions.InvalidDataError(
            'Field %s not recognized for type %s' % (
                python_name, message_type))
    field_mappings = _JSON_FIELD_MAPPINGS.setdefault(message_type, {})
    _CheckForExistingMappings('field', message_type, python_name, json_name)
    field_mappings[python_name] = json_name

Add a custom wire encoding for a given message field.

This is primarily used in generated code, to handle enum values
which happen to be Python keywords.

Args:
message_type: (messages.Message) A message type
python_name: (basestring) Python name for this value.
json_name: (basestring) JSON name to be used on the wire.
package: (NoneType, optional) No effect, exists for legacy compatibility.


def DeserializeTX(buffer):
    mstream = MemoryStream(buffer)
    reader = BinaryReader(mstream)
    tx = Transaction.DeserializeFrom(reader)
    return tx

Deserialize the stream into a Transaction object.

Args:
buffer (BytesIO): stream to deserialize the Transaction from.

Returns:
neo.Core.TX.Transaction:


def imcrop(img, bboxes, scale=1.0, pad_fill=None):
    chn = (1 if (img.ndim == 2) else img.shape[2])
    if (pad_fill is not None):
        if isinstance(pad_fill, (int, float)):
            pad_fill = [pad_fill for _ in range(chn)]
        assert (len(pad_fill) == chn)
    _bboxes = (bboxes[(None, ...)] if (bboxes.ndim == 1) else bboxes)
    scaled_bboxes = bbox_scaling(_bboxes, scale).astype(np.int32)
    clipped_bbox = bbox_clip(scaled_bboxes, img.shape)
    patches = []
    for i in range(clipped_bbox.shape[0]):
        (x1, y1, x2, y2) = tuple(clipped_bbox[(i, :)])
        if (pad_fill is None):
            patch = img[(y1:(y2 + 1), x1:(x2 + 1), ...)]
        else:
            (_x1, _y1, _x2, _y2) = tuple(scaled_bboxes[(i, :)])
            if (chn == 2):
                patch_shape = (((_y2 - _y1) + 1), ((_x2 - _x1) + 1))
            else:
                patch_shape = (((_y2 - _y1) + 1), ((_x2 - _x1) + 1), chn)
            patch = (np.array(pad_fill, dtype=img.dtype) * np.ones(patch_shape, dtype=img.dtype))
            x_start = (0 if (_x1 >= 0) else (- _x1))
            y_start = (0 if (_y1 >= 0) else (- _y1))
            w = ((x2 - x1) + 1)
            h = ((y2 - y1) + 1)
            patch[(y_start:(y_start + h), x_start:(x_start + w), ...)] = img[(y1:(y1 + h), x1:(x1 + w), ...)]
        patches.append(patch)
    if (bboxes.ndim == 1):
        return patches[0]
    else:
        return patches

Crop image patches.

3 steps: scale the bboxes -> clip bboxes -> crop and pad.

Args:
img (ndarray): Image to be cropped.
bboxes (ndarray): Shape (k, 4) or (4, ), location of cropped bboxes.
scale (float, optional): Scale ratio of bboxes, the default value
1.0 means no padding.
pad_fill (number or list): Value to be filled for padding, None for
no padding.

Returns:
list or ndarray: The cropped image patches.


def airborne_position(msg0, msg1, t0, t1):

    mb0 = common.hex2bin(msg0)[32:]
    mb1 = common.hex2bin(msg1)[32:]

    cprlat_even = common.bin2int(mb0[22:39]) / 131072.0
    cprlon_even = common.bin2int(mb0[39:56]) / 131072.0
    cprlat_odd = common.bin2int(mb1[22:39]) / 131072.0
    cprlon_odd = common.bin2int(mb1[39:56]) / 131072.0

    air_d_lat_even = 360.0 / 60
    air_d_lat_odd = 360.0 / 59

    j = common.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5)

    lat_even = float(air_d_lat_even * (j % 60 + cprlat_even))
    lat_odd = float(air_d_lat_odd * (j % 59 + cprlat_odd))

    if lat_even >= 270:
        lat_even = lat_even - 360

    if lat_odd >= 270:
        lat_odd = lat_odd - 360

    if common.cprNL(lat_even) != common.cprNL(lat_odd):
        return None

    if (t0 > t1):
        lat = lat_even
        nl = common.cprNL(lat)
        ni = max(common.cprNL(lat)- 0, 1)
        m = common.floor(cprlon_even * (nl-1) - cprlon_odd * nl + 0.5)
        lon = (360.0 / ni) * (m % ni + cprlon_even)
    else:
        lat = lat_odd
        nl = common.cprNL(lat)
        ni = max(common.cprNL(lat) - 1, 1)
        m = common.floor(cprlon_even * (nl-1) - cprlon_odd * nl + 0.5)
        lon = (360.0 / ni) * (m % ni + cprlon_odd)

    if lon > 180:
        lon = lon - 360

    return round(lat, 5), round(lon, 5)

Decode airborn position from a pair of even and odd position message

Args:
msg0 (string): even message (28 bytes hexadecimal string)
msg1 (string): odd message (28 bytes hexadecimal string)
t0 (int): timestamps for the even message
t1 (int): timestamps for the odd message

Returns:
(float, float): (latitude, longitude) of the aircraft


def speed_heading(msg):

    spd, trk_or_hdg, rocd, tag = velocity(msg)
    return spd, trk_or_hdg

Get speed and ground track (or heading) from the velocity message
(handles both airborne or surface message)

Args:
msg (string): 28 bytes hexadecimal message string

Returns:
(int, float): speed (kt), ground track or heading (degree)


def get_extended_attention_mask(self, attention_mask: tf.Tensor, input_shape: Tuple[int], is_decoder: bool) -> tf.Tensor:
    if not isinstance(attention_mask, tf.Tensor):
        attention_mask = tf.convert_to_tensor(attention_mask)
    if attention_mask.shape.rank == 3:
        extended_attention_mask = attention_mask[:, None, :, :]
    elif attention_mask.shape.rank == 2:
        if is_decoder:
            batch_size, seq_length = input_shape
            seq_ids = tf.range(seq_length, dtype=attention_mask.dtype)
            causal_mask = tf.broadcast_to(seq_ids, (batch_size, seq_length, seq_length)) <= seq_ids[None, :, None]
            if shape_list(causal_mask)[1] < shape_list(attention_mask)[1]:
                prefix_seq_len = tf.shape(attention_mask)[1] - tf.shape(causal_mask)[1]
                causal_mask = tf.concat([tf.ones((batch_size, seq_length, prefix_seq_len), dtype=causal_mask.dtype), causal_mask], axis=-1)
            extended_attention_mask = tf.cast(causal_mask[:, None, :, :], attention_mask.dtype) * attention_mask[:, None, None, :]
        else:
            extended_attention_mask = attention_mask[:, None, None, :]
    else:
        raise ValueError('Wrong shape for input_ids (shape {}) or attention_mask (shape {})'.format(input_shape, attention_mask.shape))
    extended_attention_mask = tf.cast(extended_attention_mask, self.dtype)
    extended_attention_mask = (1.0 - extended_attention_mask) * -10000.0
    return extended_attention_mask

Makes broadcastable attention and causal masks so that future and masked tokens are ignored.

Arguments:
attention_mask (`tf.Tensor`):
Mask with ones indicating tokens to attend to, zeros for tokens to ignore.
input_shape (`Tuple[int]`):
The shape of the input to the model.
is_decoder (`bool`):
Whether the model is used as a decoder.

Returns:
`tf.Tensor` The extended attention mask, with the same dtype as `attention_mask.dtype`.


def get_band_gap(self):
    if self.is_metal():
        return {'energy': 0.0, 'direct': False, 'transition': None}
    cbm = self.get_cbm()
    vbm = self.get_vbm()
    result = dict(direct=False, energy=0.0, transition=None)
    result['energy'] = (cbm['energy'] - vbm['energy'])
    if (((cbm['kpoint'].label is not None) and (cbm['kpoint'].label == vbm['kpoint'].label)) or (np.linalg.norm((cbm['kpoint'].cart_coords - vbm['kpoint'].cart_coords)) < 0.01)):
        result['direct'] = True
    result['transition'] = '-'.join([(str(c.label) if (c.label is not None) else ((str('(') + ','.join(['{0:.3f}'.format(c.frac_coords[i]) for i in range(3)])) + str(')'))) for c in [vbm['kpoint'], cbm['kpoint']]])
    return result

Returns band gap data.

Returns:
A dict {"energy","direct","transition"}:
"energy": band gap energy
"direct": A boolean telling if the gap is direct or not
"transition": kpoint labels of the transition (e.g., "\\Gamma-X")


def get_file_search(self, query):

        api_name = 'virustotal-file-search'

        (all_responses, query) = self._bulk_cache_lookup(api_name, query)
        response_chunks = self._request_reports("query", query, 'file/search')
        self._extract_response_chunks(all_responses, response_chunks, api_name)

        return all_responses

Performs advanced search on samples, matching certain binary/
metadata/detection criteria.
Possible queries: file size, file type, first or last submission to
VT, number of positives, bynary content, etc.

Args:
query: dictionary with search arguments
Example: 'query': 'type:peexe size:90kb+ positives:5+ behaviour:"taskkill"'
Returns:
A dict with the VT report.


def list(cls, session, first_name=None, last_name=None, email=None, modified_since=None):
    return super(Customers, cls).list(session, data=cls.__object__.get_non_empty_vals({'firstName': first_name, 'lastName': last_name, 'email': email, 'modifiedSince': modified_since}))

List the customers.

Customers can be filtered on any combination of first name, last name,
email, and modifiedSince.

Args:
session (requests.sessions.Session): Authenticated session.
first_name (str, optional): First name of customer.
last_name (str, optional): Last name of customer.
email (str, optional): Email address of customer.
modified_since (datetime.datetime, optional): If modified after
this date.

Returns:
RequestPaginator(output_type=helpscout.models.Customer): Customers
iterator.


def unique_id(self):
    cmd = 'svn info | grep "^Repository UUID"'
    cmdo = self.sh(cmd, shell=True, ignore_error=True)
    if cmdo:
        return cmdo.split(': ', 1)[1].rstrip()
    return None

Determine a "unique id" for this repository

Returns:
str: Repository UUID of this repository


def __init__(self, client, user_list, conversation, events=[],
                 event_cont_token=None):

        self._client = client
        self._user_list = user_list
        self._conversation = conversation
        self._events = []
        self._events_dict = {}
        self._send_message_lock = asyncio.Lock()
        self._watermarks = {}
        self._event_cont_token = event_cont_token
        for event_ in events:

            if event_.event_type != hangouts_pb2.EVENT_TYPE_OBSERVED_EVENT:
                self.add_event(event_)

        self.on_event = event.Event('Conversation.on_event')

        self.on_typing = event.Event('Conversation.on_typing')

        self.on_watermark_notification = event.Event(
            'Conversation.on_watermark_notification'
        )

        self.on_watermark_notification.add_observer(
            self._on_watermark_notification
        )

:class:`.Event` fired when an event occurs in this conversation.

Args:
conv_event: :class:`.ConversationEvent` that occurred.


def emit(self, record):
    level = record.levelno
    if (not FLAGS.is_parsed()):
        global _warn_preinit_stderr
        if _warn_preinit_stderr:
            sys.stderr.write('WARNING: Logging before flag parsing goes to stderr.\n')
            _warn_preinit_stderr = False
        self._log_to_stderr(record)
    elif FLAGS['logtostderr'].value:
        self._log_to_stderr(record)
    else:
        super(PythonHandler, self).emit(record)
        stderr_threshold = converter.string_to_standard(FLAGS['stderrthreshold'].value)
        if ((FLAGS['alsologtostderr'].value or (level >= stderr_threshold)) and (self.stream != sys.stderr)):
            self._log_to_stderr(record)
    if _is_absl_fatal_record(record):
        self.flush()
        os.abort()

Prints a record out to some streams.

If FLAGS.logtostderr is set, it will print to sys.stderr ONLY.
If FLAGS.alsologtostderr is set, it will print to sys.stderr.
If FLAGS.logtostderr is not set, it will log to the stream
associated with the current thread.

Args:
record: logging.LogRecord, the record to emit.


def _auto(method, fields, count, percent, key_field, ascending):
    if (method == 'limit'):
        return Sampling.default(fields=fields, count=count)
    elif (method == 'random'):
        return Sampling.random(fields=fields, percent=percent, count=count)
    elif (method == 'hashed'):
        return Sampling.hashed(fields=fields, field_name=key_field, percent=percent, count=count)
    elif (method == 'sorted'):
        return Sampling.sorted(fields=fields, field_name=key_field, ascending=ascending, count=count)
    else:
        raise Exception(('Unsupported sampling method: %s' % method))

Construct a sampling function according to the provided sampling technique, provided all
its needed fields are passed as arguments

Args:
method: one of the supported sampling methods: {limit,random,hashed,sorted}
fields: an optional list of field names to retrieve.
count: maximum number of rows to limit the sampled results to.
percent: the percentage of the resulting hashes to select if using hashed sampling
key_field: the name of the field to sort the rows by or use for hashing
ascending: whether to sort in ascending direction or not.
Returns:
A sampling function using the provided arguments
Raises:
Exception if an unsupported mathod name is passed


def register(config_class, image_processor_class=None, slow_image_processor_class=None, fast_image_processor_class=None, exist_ok=False):
    if image_processor_class is not None:
        if slow_image_processor_class is not None:
            raise ValueError('Cannot specify both image_processor_class and slow_image_processor_class')
        warnings.warn('The image_processor_class argument is deprecated and will be removed in v4.42. Please use `slow_image_processor_class`, or `fast_image_processor_class` instead', FutureWarning)
        slow_image_processor_class = image_processor_class
    if slow_image_processor_class is None and fast_image_processor_class is None:
        raise ValueError('You need to specify either slow_image_processor_class or fast_image_processor_class')
    if slow_image_processor_class is not None and issubclass(slow_image_processor_class, BaseImageProcessorFast):
        raise ValueError('You passed a fast image processor in as the `slow_image_processor_class`.')
    if fast_image_processor_class is not None and (not issubclass(fast_image_processor_class, BaseImageProcessorFast)):
        raise ValueError('The `fast_image_processor_class` should inherit from `BaseImageProcessorFast`.')
    if slow_image_processor_class is not None and fast_image_processor_class is not None and issubclass(fast_image_processor_class, BaseImageProcessorFast) and (fast_image_processor_class.slow_image_processor_class != slow_image_processor_class):
        raise ValueError(f'The fast processor class you are passing has a `slow_image_processor_class` attribute that is not consistent with the slow processor class you passed (fast tokenizer has {fast_image_processor_class.slow_image_processor_class} and you passed {slow_image_processor_class}. Fix one of those so they match!')
    if config_class in IMAGE_PROCESSOR_MAPPING._extra_content:
        existing_slow, existing_fast = IMAGE_PROCESSOR_MAPPING[config_class]
        if slow_image_processor_class is None:
            slow_image_processor_class = existing_slow
        if fast_image_processor_class is None:
            fast_image_processor_class = existing_fast
    IMAGE_PROCESSOR_MAPPING.register(config_class, (slow_image_processor_class, fast_image_processor_class), exist_ok=exist_ok)

Register a new image processor for this class.

Args:
config_class ([`PretrainedConfig`]):
The configuration corresponding to the model to register.
image_processor_class ([`ImageProcessingMixin`]): The image processor to register.


def compute_metrics(self):
    for (prev, point) in pairwise(self.points):
        point.compute_metrics(prev)
    return self

Computes metrics for each point

Returns:
:obj:`Segment`: self


def get_url_param(self, index, default=None):

        params = self.get_url_params()
        return params[index] if index < len(params) else default

Return url parameter with given index.

Args:
- index: starts from zero, and come after controller and
action names in url.


def sg_transpose(tensor, opt):
    r
    assert opt.perm is not None, 'perm is mandatory'
    return tf.transpose(tensor, opt.perm, name=opt.name)

r"""Permutes the dimensions according to `opt.perm`.

See `tf.transpose()` in tensorflow.

Args:
tensor: A `Tensor` (automatically given by chain).
opt:
perm: A permutation of the dimensions of `tensor`. The target shape.
name: If provided, replace current tensor's name.

Returns:
A `Tensor`.


def __init__(self, channel):

        self.CreateTenant = channel.unary_unary(
            "/google.cloud.talent.v4beta1.TenantService/CreateTenant",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__service__pb2.CreateTenantRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__pb2.Tenant.FromString,
        )
        self.GetTenant = channel.unary_unary(
            "/google.cloud.talent.v4beta1.TenantService/GetTenant",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__service__pb2.GetTenantRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__pb2.Tenant.FromString,
        )
        self.UpdateTenant = channel.unary_unary(
            "/google.cloud.talent.v4beta1.TenantService/UpdateTenant",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__service__pb2.UpdateTenantRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__pb2.Tenant.FromString,
        )
        self.DeleteTenant = channel.unary_unary(
            "/google.cloud.talent.v4beta1.TenantService/DeleteTenant",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__service__pb2.DeleteTenantRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
        self.ListTenants = channel.unary_unary(
            "/google.cloud.talent.v4beta1.TenantService/ListTenants",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__service__pb2.ListTenantsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_tenant__service__pb2.ListTenantsResponse.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def calculate_checksum_on_stream(
    f,
    algorithm=d1_common.const.DEFAULT_CHECKSUM_ALGORITHM,
    chunk_size=DEFAULT_CHUNK_SIZE,
):

    checksum_calc = get_checksum_calculator_by_dataone_designator(algorithm)
    while True:
        chunk = f.read(chunk_size)
        if not chunk:
            break
        checksum_calc.update(chunk)
    return checksum_calc.hexdigest()

Calculate the checksum of a stream.

Args:
f: file-like object
Only requirement is a ``read()`` method that returns ``bytes``.

algorithm: str
Checksum algorithm, ``MD5`` or ``SHA1`` / ``SHA-1``.

chunk_size : int
Number of bytes to read from the file and add to the checksum at a time.

Returns:
str : Checksum as a hexadecimal string, with length decided by the algorithm.


async def setvolume(self, value):

        self.logger.debug("volume command")

        if self.state != 'ready':
            return

        logger.debug("Volume command received")

        if value == '+':
            if self.volume < 100:
                self.statuslog.debug("Volume up")
                self.volume = (10 * (self.volume
                self.volumelog.info(str(self.volume))
                try:
                    self.streamer.volume = self.volume / 100
                except AttributeError:
                    pass
            else:
                self.statuslog.warning("Already at maximum volume")

        elif value == '-':
            if self.volume > 0:
                self.statuslog.debug("Volume down")
                self.volume = (10 * ((self.volume + 9)
                self.volumelog.info(str(self.volume))
                try:
                    self.streamer.volume = self.volume / 100
                except AttributeError:
                    pass
            else:
                self.statuslog.warning("Already at minimum volume")

        else:
            try:
                value = int(value)
            except ValueError:
                self.statuslog.error("Volume argument must be +, -, or a %")
            else:
                if 0 <= value <= 200:
                    self.statuslog.debug("Setting volume")
                    self.volume = value
                    self.volumelog.info(str(self.volume))
                    try:
                        self.streamer.volume = self.volume / 100
                    except AttributeError:
                        pass
                else:
                    self.statuslog.error("Volume must be between 0 and 200")

        self.write_volume()

The volume command

Args:
value (str): The value to set the volume to


def color_val(color):

    if is_str(color):
        return Color[color].value
    elif isinstance(color, Color):
        return color.value
    elif isinstance(color, tuple):
        assert len(color) == 3
        for channel in color:
            assert channel >= 0 and channel <= 255
        return color
    elif isinstance(color, int):
        assert color >= 0 and color <= 255
        return color, color, color
    elif isinstance(color, np.ndarray):
        assert color.ndim == 1 and color.size == 3
        assert np.all((color >= 0) & (color <= 255))
        color = color.astype(np.uint8)
        return tuple(color)
    else:
        raise TypeError('Invalid type for color: {}'.format(type(color)))

Convert various input to color tuples.

Args:
color (:obj:`Color`/str/tuple/int/ndarray): Color inputs

Returns:
tuple[int]: A tuple of 3 integers indicating BGR channels.


def execute_dag(self, dag, workflow_id, data=None):
    start_time = datetime.utcnow()
    logger.info('Running DAG <{}>'.format(dag.name))
    store_doc = DataStore(**self.app.user_options['config'].data_store, auto_connect=True).get(workflow_id)
    store_loc = 'log.{}'.format(dag.name)
    store_doc.set(key='{}.start_time'.format(store_loc), value=start_time, section=DataStoreDocumentSection.Meta)
    self.send_event(JobEventName.Started, job_type=JobType.Dag, name=dag.name, queue=dag.queue, time=start_time, workflow_id=workflow_id, duration=None)
    self.update_state(meta={'name': dag.name, 'queue': dag.queue, 'type': JobType.Dag, 'workflow_id': workflow_id})
    signal = DagSignal(Client(SignalConnection(**self.app.user_options['config'].signal, auto_connect=True), request_key=workflow_id), dag.name)
    dag.run(config=self.app.user_options['config'], workflow_id=workflow_id, signal=signal, data=data)
    end_time = datetime.utcnow()
    duration = (end_time - start_time).total_seconds()
    store_doc.set(key='{}.end_time'.format(store_loc), value=end_time, section=DataStoreDocumentSection.Meta)
    store_doc.set(key='{}.duration'.format(store_loc), value=duration, section=DataStoreDocumentSection.Meta)
    event_name = (JobEventName.Succeeded if (not signal.is_stopped) else JobEventName.Aborted)
    self.send_event(event_name, job_type=JobType.Dag, name=dag.name, queue=dag.queue, time=end_time, workflow_id=workflow_id, duration=duration)
    logger.info('Finished DAG <{}>'.format(dag.name))

Celery task that runs a single dag on a worker.

This celery task starts, manages and monitors the individual tasks of a dag.

Args:
self (Task): Reference to itself, the celery task object.
dag (Dag): Reference to a Dag object that is being used to start, manage and
monitor tasks.
workflow_id (string): The unique ID of the workflow run that started this dag.
data (MultiTaskData): An optional MultiTaskData object that is being passed to
the first tasks in the dag. This allows the transfer of
data from dag to dag.


def get_locpot_along_slab_plot(self, label_energies=True,
                                   plt=None, label_fontsize=10):

        plt = pretty_plot(width=6, height=4) if not plt else plt

        plt.plot(self.along_c, self.locpot_along_c, 'b--')

        xg, yg = [], []
        for i, p in enumerate(self.locpot_along_c):

            in_slab = False
            for r in self.slab_regions:
                if r[0] <= self.along_c[i] <= r[1]:
                    in_slab = True
            if len(self.slab_regions) > 1:
                if self.along_c[i] >= self.slab_regions[1][1]:
                    in_slab = True
                if self.along_c[i] <= self.slab_regions[0][0]:
                    in_slab = True

            if in_slab:
                yg.append(self.ave_bulk_p)
                xg.append(self.along_c[i])
            elif p < self.ave_bulk_p:
                yg.append(self.ave_bulk_p)
                xg.append(self.along_c[i])
            else:
                yg.append(p)
                xg.append(self.along_c[i])
        xg, yg = zip(*sorted(zip(xg, yg)))
        plt.plot(xg, yg, 'r', linewidth=2.5, zorder=-1)

        if label_energies:
            plt = self.get_labels(plt, label_fontsize=label_fontsize)
        plt.xlim([0, 1])
        plt.ylim([min(self.locpot_along_c),
                  self.vacuum_locpot+self.ave_locpot*0.2])
        plt.xlabel(r"Fractional coordinates ($\hat{c}$)", fontsize=25)
        plt.xticks(fontsize=15, rotation=45)
        plt.ylabel(r"Potential (eV)", fontsize=25)
        plt.yticks(fontsize=15)

        return plt

Returns a plot of the local potential (eV) vs the
position along the c axis of the slab model (Ang)

Args:
label_energies (bool): Whether to label relevant energy
quantities such as the work function, Fermi energy,
vacuum locpot, bulk-like locpot
plt (plt): Matplotlib pylab object
label_fontsize (float): Fontsize of labels

Returns plt of the locpot vs c axis


def create_media_service_rg(access_token, subscription_id, rgname, location, stoname, msname):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', rgname, '/providers/microsoft.media/mediaservices/', msname, '?api-version=', MEDIA_API])
    ms_body = {'name': msname}
    ms_body['location'] = location
    sub_id_str = ((((('/subscriptions/' + subscription_id) + '/resourceGroups/') + rgname) + '/providers/Microsoft.Storage/storageAccounts/') + stoname)
    storage_account = {'id': sub_id_str}
    storage_account['isPrimary'] = True
    properties = {'storageAccounts': [storage_account]}
    ms_body['properties'] = properties
    body = json.dumps(ms_body)
    return do_put(endpoint, body, access_token)

Create a media service in a resource group.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
rgname (str): Azure resource group name.
location (str): Azure data center location. E.g. westus.
stoname (str): Azure storage account name.
msname (str): Media service name.

Returns:
HTTP response. JSON body.


def are_collections_aligned(data_collections, raise_exception=True):
    if (len(data_collections) > 1):
        first_coll = data_collections[0]
        for coll in data_collections[1:]:
            if (not first_coll.is_collection_aligned(coll)):
                if (raise_exception is True):
                    error_msg = '{} Data Collection is not aligned with {} Data Collection.'.format(first_coll.header.data_type, coll.header.data_type)
                    raise ValueError(error_msg)
                return False
    return True

Test if a series of Data Collections are aligned with one another.

Aligned Data Collections are of the same Data Collection class, have the
same number of values and have matching datetimes.

Args:
data_collections: A list of Data Collections for which you want to
test if they are al aligned with one another.

Return:
True if collections are aligned, False if not aligned


def validate_field(self, field_name: str) -> bool:

        if field_name in {"@id", "@type"}:
            return True
        result = self.schema.has_field(field_name)
        if not result:

            raise UndefinedFieldError("'{}' should be present in the knowledge graph schema.".format(field_name))
        return result

Complain if a field in not in the schema
Args:
field_name:

Returns: True if the field is present.


def out_to_in(self, out_file):
    in_file = os.path.basename(out_file).replace('out', 'in', 1)
    dest = os.path.join(self.indir.path, in_file)
    if (os.path.exists(dest) and (not os.path.islink(dest))):
        logger.warning(('Will overwrite %s with %s' % (dest, out_file)))
    os.rename(out_file, dest)
    return dest

Move an output file to the output data directory of the `Task`
and rename the file so that ABINIT will read it as an input data file.

Returns:
The absolute path of the new file in the indata directory.


def sg_arg_def(**kwargs):
    r
    for k, v in kwargs.items():
        if type(v) is tuple or type(v) is list:
            v, c = v[0], v[1]
        else:
            c = k
        if type(v) is str:
            tf.app.flags.DEFINE_string(k, v, c)
        elif type(v) is int:
            tf.app.flags.DEFINE_integer(k, v, c)
        elif type(v) is float:
            tf.app.flags.DEFINE_float(k, v, c)
        elif type(v) is bool:
            tf.app.flags.DEFINE_bool(k, v, c)

r"""Defines command line options

Args:
**kwargs:
key: A name for the option.
value : Default value or a tuple of (default value, description).

Returns:
None

For example,

```
# Either of the following two lines will define `--n_epoch` command line argument and set its default value as 1.

tf.sg_arg_def(n_epoch=1)
tf.sg_arg_def(n_epoch=(1, 'total number of epochs'))
```


def request(path):
    headers = {'Accept': 'application/json'}
    try:
        requested_object = requests.get(path, headers=headers)
        requested_object.raise_for_status()
    except requests.exceptions.HTTPError as exception:
        LOGGER.error(((((((inspect.stack()[0][3] + ': HTTPError = ') + str(exception.response.status_code)) + ' ') + str(exception.response.reason)) + ' ') + str(path)))
        raise
    except requests.exceptions.InvalidURL as exception:
        LOGGER.error(((('URLError = ' + str(exception.reason)) + ' ') + str(path)))
        raise
    except Exception:
        import traceback
        LOGGER.error(('Generic exception: ' + traceback.format_exc()))
        raise
    else:
        response = requested_object.json()
        return response

Send a request to a given URL accepting JSON format and return a \
deserialized Python object.

Args:
path (str): The URI to be requested.

Returns:
response: Deserialized JSON Python object.

Raises:
HTTPError: the HTTP error returned by the requested server.
InvalidURL: an invalid URL has been requested.
Exception: generic exception.


def _show_ops_in_metagraph(saved_model_dir, tag_set):
    meta_graph_def = saved_model_utils.get_meta_graph_def(saved_model_dir, tag_set)
    _show_ops_in_metagraph_mgd(meta_graph_def)

Prints the ops in the MetaGraph.

Prints all the ops used in the MetaGraphDef indicated by the tag_set stored in
SavedModel directory.

Args:
saved_model_dir: Directory containing the SavedModel to inspect.
tag_set: Group of tag(s) of the MetaGraphDef in string format, separated by
','. For tag-set contains multiple tags, all tags must be passed in.


def get_twitter_id(self, cache=True):
    if (not (cache and ('twitter' in self.cache))):
        response = self.get_attribute('twitter')
        self.cache['twitter'] = response['artist'].get('twitter')
    return self.cache['twitter']

Get the twitter id for this artist if it exists

Args:

Kwargs:

Returns:
A twitter ID string

Example:

>>> a = artist.Artist('big boi')
>>> a.get_twitter_id()
u'BigBoi'
>>>


def _update_libdata(self, line):
    if re.match('^Comment.*$', line, re.IGNORECASE):
        comments = re.findall('"([^"]*)"', line)
        for c in comments:
            self._parse_meta_info(c)
            self._parse_compound_info(c)
    self._parse_meta_info(line)
    self._parse_compound_info(line)
    if (self.collect_meta and (re.match('^Num Peaks(.*)$', line, re.IGNORECASE) or re.match('^PK\\$PEAK:(.*)', line, re.IGNORECASE) or re.match('^PK\\$ANNOTATION(.*)', line, re.IGNORECASE))):
        self._store_compound_info()
        self._store_meta_info()
        self.meta_info = get_blank_dict(self.meta_regex)
        self.compound_info = get_blank_dict(self.compound_regex)
        self.other_names = []
        self.collect_meta = False
    if re.match('^PK\\$PEAK: m/z int\\. rel\\.int\\.$', line, re.IGNORECASE):
        self.ignore_additional_spectra_info = True
    if (re.match('^Num Peaks(.*)$', line, re.IGNORECASE) or re.match('^PK\\$PEAK:(.*)', line, re.IGNORECASE)):
        self.start_spectra = True
        return
    elif re.match('^PK\\$ANNOTATION(.*)', line, re.IGNORECASE):
        self.start_spectra_annotation = True
        match = re.match('^PK\\$ANNOTATION:(.*)', line, re.IGNORECASE)
        columns = match.group(1)
        cl = columns.split()
        self.spectra_annotation_indexes = {i: cl.index(i) for i in cl}
        return
    if self.start_spectra_annotation:
        self._parse_spectra_annotation(line)
    if self.start_spectra:
        self._parse_spectra(line)

Update the library meta data from the current line being parsed

Args:
line (str): The current line of the of the file being parsed


def _isbn_pairing(items):

    NameWrapper = namedtuple("NameWrapper", ["name", "obj"])
    metas = map(
        lambda x: NameWrapper(_just_name(x.filename), x),
        filter(lambda x: isinstance(x, MetadataFile), items)
    )
    ebooks = map(
        lambda x: NameWrapper(_just_name(x.filename), x),
        filter(lambda x: isinstance(x, EbookFile), items)
    )

    metas = sorted(metas, key=lambda x: x.name)
    ebooks = sorted(ebooks, key=lambda x: x.name, reverse=True)
    while metas:
        meta = metas.pop()

        if not isbn_validator.is_valid_isbn(meta.name):
            continue

        if not ebooks:
            break

        ebook_index = _index(ebooks, meta.name, key=lambda x: x.name)

        if ebook_index >= 0:
            logger.debug(
                "Pairing '%s' and '%s'." % (
                    meta.obj.filename,
                    ebooks[ebook_index].obj.filename
                )
            )
            items.append(
                DataPair(
                    metadata_file=meta.obj,
                    ebook_file=ebooks[ebook_index].obj
                )
            )
            items.remove(meta.obj)
            items.remove(ebooks[ebook_index].obj)
            ebooks = ebooks[ebook_index+1:]

    return items

Pair `items` with same ISBN into `DataPair` objects.

Args:
items (list): list of items, which will be searched.

Returns:
list: list with paired items. Paired items are removed, `DataPair` is \
added instead.


def observe_reward_value(self, state_arr, action_arr):

        if self.__check_goal_flag(action_arr) is True:
            return 1.0
        else:
            x, y = np.where(action_arr[-1] == 1)
            x, y = x[0], y[0]
            goal_x, goal_y = self.__goal_pos

            if x == goal_x and y == goal_y:
                distance = 0.0
            else:
                distance = np.sqrt(((x - goal_x) ** 2) + (y - goal_y) ** 2)

            if (x, y) in self.__route_long_memory_list:
                repeating_penalty = self.__repeating_penalty
            else:
                repeating_penalty = 0.0
            return 1.0 - distance - repeating_penalty

Compute the reward value.

Args:
state_arr:              `np.ndarray` of state.
action_arr:             `np.ndarray` of action.

Returns:
Reward value.


def __unionfs_set_up(ro_dir, rw_dir, mount_dir):
    mount_dir.mkdir()
    rw_dir.mkdir()
    if (not ro_dir.exists()):
        LOG.error("Base dir does not exist: '%s'", ro_dir)
        raise ValueError('Base directory does not exist')
    from benchbuild.utils.cmd import unionfs as unionfs_cmd
    LOG.debug('Mounting UnionFS on %s with RO:%s RW:%s', mount_dir, ro_dir, rw_dir)
    return unionfs_cmd[('-f', '-o', 'auto_unmount,allow_other,cow', (((rw_dir + '=RW:') + ro_dir) + '=RO'), mount_dir)]

Setup a unionfs via unionfs-fuse.

Args:
ro_base: base_directory of the project
rw_image: virtual image of actual file system
mountpoint: location where ro_base and rw_image merge


def expandEntitiesFromEmail(e):

    email = {}
    email["type"] = "i3visio.email"
    email["value"] = e
    email["attributes"] = []

    alias = {}
    alias["type"] = "i3visio.alias"
    alias["value"] = e.split("@")[0]
    alias["attributes"] = []

    domain= {}
    domain["type"] = "i3visio.domain"
    domain["value"] = e.split("@")[1]
    domain["attributes"] = []

    return [email, alias, domain]

Method that receives an email an creates linked entities

Args:
-----
e:   Email to verify.

Returns:
--------
Three different values: email, alias and domain in a list.


def ParseOptions(self, options):

    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=['data_location'])

    self._ReadParserPresetsFromFile()

    self._ParseTimezoneOption(options)

    argument_helper_names = [
        'artifact_definitions', 'hashers', 'language', 'parsers']
    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=argument_helper_names)

    self.list_hashers = self._hasher_names_string == 'list'
    self.list_language_identifiers = self._preferred_language == 'list'
    self.list_parsers_and_plugins = self._parser_filter_expression == 'list'

    if (self.list_hashers or self.list_language_identifiers or
        self.list_parsers_and_plugins or self.list_timezones):
      return

    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=['output_modules'])

    self.list_output_modules = self._output_format == 'list'
    if self.list_output_modules:
      return

    self._ParseInformationalOptions(options)

    argument_helper_names = ['extraction', 'status_view']
    helpers_manager.ArgumentHelperManager.ParseOptions(
        options, self, names=argument_helper_names)

    self._ParseLogFileOptions(options)

    self._ParseStorageMediaOptions(options)

    self._ParsePerformanceOptions(options)
    self._ParseProcessingOptions(options)

    self._storage_file_path = getattr(options, 'storage_file', None)
    if not self._storage_file_path:
      self._storage_file_path = self._GenerateStorageFileName()

    self._output_filename = getattr(options, 'write', None)

    if not self._output_filename:
      raise errors.BadConfigOption((
          'Output format: {0:s} requires an output file '
          '(-w OUTPUT_FILE)').format(self._output_format))

    if os.path.exists(self._output_filename):
      raise errors.BadConfigOption(
          'Output file already exists: {0:s}.'.format(self._output_filename))

    self._EnforceProcessMemoryLimit(self._process_memory_limit)

    self._output_module = self._CreateOutputModule(options)

Parses tool specific options.

Args:
options (argparse.Namespace): command line arguments.

Raises:
BadConfigOption: if the options are invalid.


def _global_batch_size(self):
    return True

`make_dataset_iterator` and `make_numpy_iterator` use global batch size.

`make_input_fn_iterator` assumes per-replica batching.

Returns:
Boolean.


def _GetLinkedPath(self, event):

    if hasattr(event, 'local_path'):
      return event.local_path

    if hasattr(event, 'network_path'):
      return event.network_path

    if hasattr(event, 'relative_path'):
      paths = []
      if hasattr(event, 'working_directory'):
        paths.append(event.working_directory)
      paths.append(event.relative_path)

      return '\\'.join(paths)

    return 'Unknown'

Determines the linked path.

Args:
event (EventObject): event that contains a linked path.

Returns:
str: linked path.


def parse_args(self):
    parser = ArgumentParser(description='', formatter_class=RawTextHelpFormatter)
    parser.add_argument('--generate', action='store', dest='generate', choices=['command', 'docker-run', 'docker-compose', 'ini', 'env', 'kubernetes', 'readme', 'drone-plugin'], help='Generate a template ')
    parser.add_argument('--settings', action='store', dest='settings', help='Specify a settings file. (ie settings.dev)')
    for (key, value) in self.spec.items():
        if (value['type'] in [str, int, float]):
            parser.add_argument(f'--{key.lower()}', action='store', dest=key, type=value['type'], choices=value.get('choices'), help=self.help(value))
        elif (value['type'] == bool):
            parser.add_argument(f'--{key.lower()}', action='store', dest=key, type=(lambda x: bool(strtobool(x))), choices=value.get('choices'), help=self.help(value))
        elif (value['type'] == list):
            parser.add_argument(f'--{key.lower()}', action='store', dest=key, nargs='+', choices=value.get('choices'), help=self.help(value))
        elif (value['type'] == dict):
            parser.add_argument(f'--{key.lower()}', action='store', dest=key, type=json.loads, choices=value.get('choices'), help=self.help(value))
    (args, _unknown) = parser.parse_known_args()
    return args

Parse the cli args

Returns:
args (namespace): The args


def conjugate(self):
    try:
        return Matrix(np_conjugate(self.matrix))
    except AttributeError:
        raise NoConjugateMatrix(('Matrix %s contains entries that have no defined conjugate' % str(self)))

The element-wise conjugate matrix

This is defined only if all the entries in the matrix have a defined
conjugate (i.e., they have a `conjugate` method). This is *not* the
case for a matrix of operators. In such a case, only an
:meth:`elementwise` :func:`adjoint` would be applicable, but this is
mathematically different from a complex conjugate.

Raises:
NoConjugateMatrix: if any entries have no `conjugate` method


def optionally_with_args(phase, **kwargs):

  if isinstance(phase, PhaseGroup):
    return phase.with_args(**kwargs)
  if isinstance(phase, collections.Iterable):
    return [optionally_with_args(p, **kwargs) for p in phase]

  if not isinstance(phase, phase_descriptor.PhaseDescriptor):
    phase = phase_descriptor.PhaseDescriptor.wrap_or_copy(phase)
  return phase.with_known_args(**kwargs)

Apply only the args that the phase knows.

If the phase has a **kwargs-style argument, it counts as knowing all args.

Args:
phase: phase_descriptor.PhaseDescriptor or PhaseGroup or callable, or
iterable of those, the phase or phase group (or iterable) to apply
with_args to.
**kwargs: arguments to apply to the phase.

Returns:
phase_descriptor.PhaseDescriptor or PhaseGroup or iterable with the updated
args.


def data(item=None, show_doc=False):

    if item:
        try:
            if show_doc:
                __print_item_docs(item)
                return

            df = __read_csv(item)
            return df
        except KeyError:
            find_similar(item)
    else:
        return __datasets_desc()

loads a datasaet (from in-modules datasets) in a dataframe data structure.

Args:
item (str)      : name of the dataset to load.
show_doc (bool) : to show the dataset's documentation.

Examples:

>>> iris = data('iris')

>>> data('titanic', show_doc=True)
: returns the dataset's documentation.

>>> data()
: like help(), returns a dataframe [Item, Title]
for a list of the available datasets.


def _run_in_hypothesis(self, mma, w_string, index):

        state = mma.states[0]
        s_index = 0
        for i in range(index):
            for arc in state:
                if arc.guard.is_sat(w_string[i]):
                    state = mma.states[arc.dst_state]
                    s_index = arc.dst_state

        access_string = self.observation_table.sm_vector[s_index]
        logging.debug(
            'Access string for %d: %s - %d ',
            index,
            access_string,
            s_index)
        return access_string

Run the string in the hypothesis automaton for index steps and then
return the access string for the state reached concatanated with the
rest of the string w.
Args:
mma (DFA): The hypothesis automaton
w_string (str): The examined string to be consumed
index (int): The index value for selecting the prefix of w
Return:
str: The access string


def unreduce(array, shape, axis, keepdims):

  unreducer = unreducers[type(array)]
  return unreducer(array, shape, axis, keepdims)

Reverse summing over a dimension.

Args:
array: The array that was reduced.
shape: The original shape of the array before reduction.
axis: The axis or axes that were summed.
keepdims: Whether these axes were kept as singleton axes.

Returns:
An array with axes broadcast to match the shape of the original array.


def delete_case(self, case_id=None, institute_id=None, display_name=None):

        query = {}
        if case_id:
            query['_id'] = case_id
            LOG.info("Deleting case %s", case_id)
        else:
            if not (institute_id and display_name):
                raise ValueError("Have to provide both institute_id and display_name")
            LOG.info("Deleting case %s institute %s", display_name, institute_id)
            query['owner'] = institute_id
            query['display_name'] = display_name

        result = self.case_collection.delete_one(query)
        return result

Delete a single case from database

Args:
institute_id(str)
case_id(str)

Returns:
case_obj(dict): The case that was deleted


def _write_move_counts(self, sess, h):

        def gen():
            for k, v in h.items():

                k = str(k, 'utf-8')
                vs = str(v)
                yield (k.replace('g_', 'ct_') + '_%d' % v, vs)
                yield (k + '_m_000', vs)
        mc = tf.data.Dataset.from_generator(gen, (tf.string, tf.string))
        wr_op = self.tf_table.write(mc,
                                    column_families=[METADATA],
                                    columns=[MOVE_COUNT])
        sess.run(wr_op)

Add move counts from the given histogram to the table.

Used to update the move counts in an existing table.  Should
not be needed except for backfill or repair.

Args:
sess:  TF session to use for doing a Bigtable write.
tf_table:  TF Cloud Bigtable to use for writing.
h:  a dictionary keyed by game row prefix ("g_0023561") whose values
are the move counts for each game.