def __init__(self, variant_tensor, resource_creator):
    super(_VariantTracker, self).__init__(device='CPU')
    self._resource_handle = variant_tensor
    if not isinstance(resource_creator, def_function.Function):
        raise TypeError('Resource creator should already be a tf.function.')
    self._create_resource = resource_creator

Record that `variant_tensor` is associated with `resource_creator`.

Args:
variant_tensor: The variant-dtype Tensor associated with the Dataset. This
Tensor will be a captured input to functions which use the Dataset, and
is used by saving code to identify the corresponding _VariantTracker.
resource_creator: A zero-argument function which creates a new
variant-dtype Tensor. This function will be included in SavedModels and
run to re-create the Dataset's variant Tensor on restore.


def send_to_default_exchange(self, sess_id, message=None):

        msg = json.dumps(message, cls=ZEngineJSONEncoder)
        log.debug("Sending following message to %s queue through default exchange:\n%s" % (
            sess_id, msg))
        self.get_channel().publish(exchange='', routing_key=sess_id, body=msg)

Send messages through RabbitMQ's default exchange,
which will be delivered through routing_key (sess_id).

This method only used for un-authenticated users, i.e. login process.

Args:
sess_id string: Session id
message dict: Message object.


def serialize_example(transformed_json_data, features, feature_indices, target_name):

  import six
  import tensorflow as tf
  from trainer import feature_transforms

  line = str(transformed_json_data[target_name][0])
  for name, info in feature_indices:
    if features[name]['transform'] in [feature_transforms.IDENTITY_TRANSFORM,
                                       feature_transforms.SCALE_TRANSFORM]:
      line += ' %d:%s' % (info['index_start'], str(transformed_json_data[name][0]))
    elif features[name]['transform'] in [feature_transforms.ONE_HOT_TRANSFORM,
                                         feature_transforms.MULTI_HOT_TRANSFORM]:
      for i in range(info['size']):
        if i in transformed_json_data[name]:
          line += ' %d:1' % (info['index_start'] + i)
    elif features[name]['transform'] in [feature_transforms.IMAGE_TRANSFORM]:
      for i in range(info['size']):
        line += ' %d:%s' % (info['index_start'] + i, str(transformed_json_data[name][i]))

  return line

Makes an instance of data in libsvm format.

Args:
transformed_json_data: dict of transformed data.
features: features config.
feature_indices: output of feature_transforms.get_transformed_feature_indices()

Returns:
The text line representation of an instance in libsvm format.


def get_language(self, text):
    files = {'text': text}
    (res, status_code) = self.post(self.language_service, files=files)
    if (status_code != 200):
        logger.debug('Language recognition failed.')
    return (self.decode(res), status_code)

Recognise the language of the text in input

Args:
id (str): The text whose the language needs to be recognised

Returns:
dict, int: A dict containing the recognised language and the
confidence score.


def _add_source(model):

    ignored_keys = {"author_tags", "original_xml", "additional_info"}

    source = "Aleph"
    for key, val in model.get_mapping().iteritems():
        if key in ignored_keys:
            continue

        if type(val) in [list, tuple]:
            ss_val = [
                SourceString(item, source).to_dict()
                for item in val
            ]
        else:
            ss_val = [SourceString(val, source).to_dict()]

        setattr(model, key, ss_val)

    return model

Go over all attributes in `model` and add :class:`SourceString` to them.

Args:
model (obj): :class:`Model` instance.

Returns:
obj: :class:`Model` instance with :class:`SourceString` descriptors.


async def send_script(self, client_id, conn_string, script):
    conn_id = self._client_connection(client_id, conn_string)
    (await self.adapter.send_script(conn_id, script))

Send a script to a device on behalf of a client.

See :meth:`AbstractDeviceAdapter.send_script`.

Args:
client_id (str): The client we are working for.
conn_string (str): A connection string that will be
passed to the underlying device adapter.
script (bytes): The script that we wish to send.

Raises:
DeviceServerError: There is an issue with your client_id such
as not being connected to the device.
DeviceAdapterError: The adapter had a protocol issue sending the script.


def bit_for_bit(model_path, bench_path, config):

    fname = model_path.split(os.path.sep)[-1]

    if not (os.path.isfile(bench_path) and os.path.isfile(model_path)):
        return elements.error("Bit for Bit",
                              "File named " + fname + " has no suitable match!")
    try:
        model_data = Dataset(model_path)
        bench_data = Dataset(bench_path)
    except (FileNotFoundError, PermissionError):
        return elements.error("Bit for Bit",
                              "File named " + fname + " could not be read!")
    if not (netcdf.has_time(model_data) and netcdf.has_time(bench_data)):
        return elements.error("Bit for Bit",
                              "File named " + fname + " could not be read!")

    headers = ["Max Error", "Index of Max Error", "RMS Error", "Plot"]
    stats = LIVVDict()
    for i, var in enumerate(config["bit_for_bit_vars"]):
        if var in model_data.variables and var in bench_data.variables:
            m_vardata = model_data.variables[var][:]
            b_vardata = bench_data.variables[var][:]
            diff_data = m_vardata - b_vardata
            if diff_data.any():
                stats[var]["Max Error"] = np.amax(np.absolute(diff_data))
                stats[var]["Index of Max Error"] = str(
                        np.unravel_index(np.absolute(diff_data).argmax(), diff_data.shape))
                stats[var]["RMS Error"] = np.sqrt(np.sum(np.square(diff_data).flatten()) /
                                                  diff_data.size)
                pf = plot_bit_for_bit(fname, var, m_vardata, b_vardata, diff_data)
            else:
                stats[var]["Max Error"] = stats[var]["RMS Error"] = 0
                pf = stats[var]["Index of Max Error"] = "N/A"
            stats[var]["Plot"] = pf
        else:
            stats[var] = {"Max Error": "No Match", "RMS Error": "N/A", "Plot": "N/A"}
    model_data.close()
    bench_data.close()
    return elements.bit_for_bit("Bit for Bit", headers, stats)

Checks whether the given files have bit for bit solution matches
on the given variable list.

Args:
model_path: absolute path to the model dataset
bench_path: absolute path to the benchmark dataset
config: the configuration of the set of analyses

Returns:
A dictionary created by the elements object corresponding to
the results of the bit for bit testing


def extract_all_content(self, path=None, payload=None, objectInput=None, pretty_print=False, convert_to_obj=False):
    f = file_path(path, payload, objectInput)
    switches = ['-J', '-t', '-r', f]
    if (not pretty_print):
        switches.remove('-r')
    result = self._command_template(switches)
    if (result and convert_to_obj):
        result = json.loads(result, encoding='utf-8')
    return (result, path, f)

This function returns a JSON of all contents and
metadata of passed file

Args:
path (string): Path of file to analyze
payload (string): Payload base64 to analyze
objectInput (object): file object/standard input to analyze
pretty_print (boolean): If True adds newlines and whitespace,
for better readability
convert_to_obj (boolean): If True convert JSON in object


def convert_to_tensor_with_default(value, default, dtype=None, name=None):
    rtn_val = default if value is None else value
    return tf.convert_to_tensor(rtn_val, dtype=dtype, name=name)

Converts the given `value` to a `Tensor` or returns the `default` value.

Converts the input `value` to a `Tensor` or returns `default` converted to a
`Tensor` if `value == None`.

Args:
value: An object whose type has a registered Tensor conversion function.
default: The value to return if `value == None`.
dtype: Optional element type for the returned tensor. If missing, the type
is inferred from the type of value.
name: Optional name to use if a new Tensor is created.

Returns:
A Tensor based on value.


def _consumers(self):
    consumers = nest.flatten([component.consumers() for component in nest.flatten(self, expand_composites=True) if getattr(component, 'graph', None) is not None])
    return list(set(consumers))

Returns a list of `Operation`s that consume this `CompositeTensor`.

Returns:
A list of `Operation`s.

Raises:
RuntimeError: If this method is called while executing eagerly.


def delete(filepath):

    remove_acl(filepath)

    remove_immutable_attribute(filepath)

    if os.path.isfile(filepath) or os.path.islink(filepath):
        os.remove(filepath)
    elif os.path.isdir(filepath):
        shutil.rmtree(filepath)

Delete the given file, directory or link.

It Should support undelete later on.

Args:
filepath (str): Absolute full path to a file. e.g. /path/to/file


def addRow(self, triggered):

        if triggered:
            model = self.tableView.model()
            model.addDataFrameRows()
            self.sender().setChecked(False)

Adds a row to the model.

This method is also a slot.

Args:
triggered (bool): If the corresponding button was
activated, the row will be appended to the end.


class Wav2Vec2PhonemeCTCTokenizerOutput(ModelOutput):
    text: Union[List[str], str]
    char_offsets: Union[List[ListOfDict], ListOfDict] = None

Output type of [` Wav2Vec2PhonemeCTCTokenizer`], with transcription.

Args:
text (list of `str` or `str`):
Decoded logits in text from. Usually the speech transcription.
char_offsets (list of `List[Dict[str, Union[int, str]]]` or `List[Dict[str, Union[int, str]]]`):
Offsets of the decoded characters. In combination with sampling rate and model downsampling rate char
offsets can be used to compute time stamps for each character. Total logit score of the beam associated with
produced text.


def save_to_file(self, filename, remap_dim0=None, remap_dim1=None):

    with open(filename, 'w') as fobj:
      columns = list(sorted(self._dim1))
      for col in columns:
        fobj.write(',')
        fobj.write(str(remap_dim1[col] if remap_dim1 else col))
      fobj.write('\n')
      for row in sorted(self._dim0):
        fobj.write(str(remap_dim0[row] if remap_dim0 else row))
        for col in columns:
          fobj.write(',')
          fobj.write(str(self[row, col]))
        fobj.write('\n')

Saves matrix to the file.

Args:
filename: name of the file where to save matrix
remap_dim0: dictionary with mapping row indices to row names which should
be saved to file. If none then indices will be used as names.
remap_dim1: dictionary with mapping column indices to column names which
should be saved to file. If none then indices will be used as names.


def SetFlushInterval(self, flush_interval):

    self._flush_interval = flush_interval
    logger.debug('Elasticsearch flush interval: {0:d}'.format(flush_interval))

Set the flush interval.

Args:
flush_interval (int): number of events to buffer before doing a bulk
insert.


def set_attributes(self, **kwargs):

        for field, value in kwargs.items():
            if field in self.Meta.attributes:
                setattr(self, field, value)

Set the resource attributes from the kwargs.
Only sets items in the `self.Meta.attributes` white list.

Args:
kwargs: Keyword arguements passed into the init of this class


def __init__(self, dct_type=2, validate_args=False, name='dct'):

    if dct_type not in (2, 3):
      raise NotImplementedError('`type` must be one of 2 or 3')
    self._dct_type = dct_type
    super(DiscreteCosineTransform, self).__init__(
        forward_min_event_ndims=1,
        inverse_min_event_ndims=1,
        is_constant_jacobian=True,
        validate_args=validate_args,
        name=name)

Instantiates the `DiscreteCosineTransform` bijector.

Args:
dct_type: Python `int`, the DCT type performed by the forward
transformation. Currently, only 2 and 3 are supported.
validate_args: Python `bool` indicating whether arguments should be
checked for correctness.
name: Python `str` name given to ops managed by this object.


def modify_ack_deadline(self, seconds):
    self._request_queue.put(requests.ModAckRequest(ack_id=self._ack_id, seconds=seconds))

Resets the deadline for acknowledgement.

New deadline will be the given value of seconds from now.

The default implementation handles this for you; you should not need
to manually deal with setting ack deadlines. The exception case is
if you are implementing your own custom subclass of
:class:`~.pubsub_v1.subcriber._consumer.Consumer`.

Args:
seconds (int): The number of seconds to set the lease deadline
to. This should be between 0 and 600. Due to network latency,
values below 10 are advised against.


def get_enterprise_customer_or_404(enterprise_uuid):

    EnterpriseCustomer = apps.get_model('enterprise', 'EnterpriseCustomer')
    try:
        enterprise_uuid = UUID(enterprise_uuid)
        return EnterpriseCustomer.objects.get(uuid=enterprise_uuid)
    except (TypeError, ValueError, EnterpriseCustomer.DoesNotExist):
        LOGGER.error('Unable to find enterprise customer for UUID: [%s]', enterprise_uuid)
        raise Http404

Given an EnterpriseCustomer UUID, return the corresponding EnterpriseCustomer or raise a 404.

Arguments:
enterprise_uuid (str): The UUID (in string form) of the EnterpriseCustomer to fetch.

Returns:
(EnterpriseCustomer): The EnterpriseCustomer given the UUID.


def in_coord_list(coord_list, coord, atol=1e-8):

    return len(find_in_coord_list(coord_list, coord, atol=atol)) > 0

Tests if a particular coord is within a coord_list.

Args:
coord_list: List of coords to test
coord: Specific coordinates
atol: Absolute tolerance. Defaults to 1e-8. Accepts both scalar and
array.

Returns:
True if coord is in the coord list.


def create_token_type_ids_from_sequences(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
    sep = [self.sep_token_id]
    cls = [self.cls_token_id]
    if token_ids_1 is None:
        return len(cls + token_ids_0 + sep) * [0]
    return len(cls + token_ids_0 + sep + sep + token_ids_1 + sep) * [0]

Create a mask from the two sequences passed to be used in a sequence-pair classification task. PLBart does not
make use of token type ids, therefore a list of zeros is returned.

Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of zeros.


def target_call_func(self, answer: Union[str, List[str]], 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, pad_to_multiple_of: Optional[int]=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:
    is_batched = isinstance(answer, (list, tuple))
    if is_batched:
        return self.target_batch_encode_plus(answer=answer, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, pad_to_multiple_of=pad_to_multiple_of, 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)
    else:
        return self.target_encode_plus(answer=answer, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, pad_to_multiple_of=pad_to_multiple_of, 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)

The method tokenizes and prepares the answer label for the model.

Args:
answer (`str` or `List[str]`):
Corresponding answer supervision to the queries for training the model.


def allconcat(self, x, mesh_axis, concat_axis):

    return self._collective_with_groups(
        x, [mesh_axis],
        functools.partial(allconcat_ring, concat_axis=concat_axis))

Grouped allconcat (like MPI allgather followed by concat).

Args:
x: a LaidOutTensor
mesh_axis: an integer - the mesh axis along which to group
concat_axis: an integer (the Tensor axis along which to concatenate)
Returns:
a LaidOutTensor


def _validate_signature_def_map(self, signature_def_map):
    for signature_def_key in signature_def_map:
        signature_def = signature_def_map[signature_def_key]
        inputs = signature_def.inputs
        outputs = signature_def.outputs
        for inputs_key in inputs:
            self._validate_tensor_info(inputs[inputs_key])
        for outputs_key in outputs:
            self._validate_tensor_info(outputs[outputs_key])
    if constants.INIT_OP_SIGNATURE_KEY in signature_def_map:
        raise KeyError(f'SignatureDef map key "{constants.INIT_OP_SIGNATURE_KEY}" is reserved for initialization. Please use a different key.')
    if constants.TRAIN_OP_SIGNATURE_KEY in signature_def_map:
        raise KeyError(f'SignatureDef map key "{constants.TRAIN_OP_SIGNATURE_KEY}" is reserved for the train op. Please use a different key.')

Validates the `SignatureDef` entries in the signature def map.

Validation of entries in the signature def map includes ensuring that the
`name` and `dtype` fields of the TensorInfo protos of the `inputs` and
`outputs` of each `SignatureDef` are populated. Also ensures that reserved
SignatureDef keys for the initialization and train ops are not used.

Args:
signature_def_map: The map of signature defs to be validated.

Raises:
AssertionError: If a TensorInfo is not valid.
KeyError: If a reserved signature key is used in the map.


def decode(tokens):

  token_is_alnum = [t[0] in _ALPHANUMERIC_CHAR_SET for t in tokens]
  ret = []
  for i, token in enumerate(tokens):
    if i > 0 and token_is_alnum[i - 1] and token_is_alnum[i]:
      ret.append(u" ")
    ret.append(token)
  return "".join(ret)

Decode a list of tokens to a unicode string.

Args:
tokens: a list of Unicode strings
Returns:
a unicode string


def _is_variable(node_def: node_def_pb2.NodeDef) -> bool:
    return node_def.op == 'VarHandleOp'

Determines whether `node_def` is a variable node.

Args:
node_def: `NodeDef` to test whether it is a variable or not.

Returns:
Returns True if it is a variable.


def clear(self, back_r: int=0, back_g: int=0, back_b: int=0, fore_r: int=0, fore_g: int=0, fore_b: int=0, char: str=' ') -> None:
    n = (self.width * self.height)
    self.back_r = ([back_r] * n)
    self.back_g = ([back_g] * n)
    self.back_b = ([back_b] * n)
    self.fore_r = ([fore_r] * n)
    self.fore_g = ([fore_g] * n)
    self.fore_b = ([fore_b] * n)
    self.char = ([ord(char)] * n)

Clears the console.  Values to fill it with are optional, defaults
to black with no characters.

Args:
back_r (int): Red background color, from 0 to 255.
back_g (int): Green background color, from 0 to 255.
back_b (int): Blue background color, from 0 to 255.
fore_r (int): Red foreground color, from 0 to 255.
fore_g (int): Green foreground color, from 0 to 255.
fore_b (int): Blue foreground color, from 0 to 255.
char (AnyStr): A single character str or bytes object.


def normalize(self, text, normalizations=None):
    for (normalization, kwargs) in self._parse_normalizations((normalizations or self._config.normalizations)):
        try:
            text = getattr(self, normalization)(text, **kwargs)
        except AttributeError as e:
            self._logger.debug('Invalid normalization: %s', e)
    return text

Normalize a given text applying all normalizations.

Normalizations to apply can be specified through a list of
parameters and will be executed in that order.

Args:
text: The text to be processed.
normalizations: List of normalizations to apply.

Returns:
The text normalized.


def helper_add(access_token, ck_id, path, body):
    full_path = ''.join([path, "('", ck_id, "')"])
    full_path_encoded = urllib.parse.quote(full_path, safe='')
    endpoint = ''.join([ams_rest_endpoint, full_path_encoded])
    return do_ams_put(endpoint, full_path_encoded, body, access_token, 'json_only', '1.0;NetFx')

Helper Function to add strings to a URL path.

Args:
access_token (str): A valid Azure authentication token.
ck_id (str): A CK ID.
path (str): A URL Path.
body (str): A Body.

Returns:
HTTP response. JSON body.


def get_variation_for_feature(self, feature, user_id, attributes=None):

    experiment = None
    variation = None
    bucketing_id = self._get_bucketing_id(user_id, attributes)

    if feature.groupId:
      group = self.config.get_group(feature.groupId)
      if group:
        experiment = self.get_experiment_in_group(group, bucketing_id)
        if experiment and experiment.id in feature.experimentIds:
          variation = self.get_variation(experiment, user_id, attributes)

          if variation:
            self.logger.debug('User "%s" is in variation %s of experiment %s.' % (
              user_id,
              variation.key,
              experiment.key
            ))
            return Decision(experiment, variation, enums.DecisionSources.FEATURE_TEST)
      else:
        self.logger.error(enums.Errors.INVALID_GROUP_ID_ERROR.format('_get_variation_for_feature'))

    elif feature.experimentIds:

      experiment = self.config.get_experiment_from_id(feature.experimentIds[0])
      if experiment:
        variation = self.get_variation(experiment, user_id, attributes)

        if variation:
          self.logger.debug('User "%s" is in variation %s of experiment %s.' % (
            user_id,
            variation.key,
            experiment.key
          ))
          return Decision(experiment, variation, enums.DecisionSources.FEATURE_TEST)

    if feature.rolloutId:
      rollout = self.config.get_rollout_from_id(feature.rolloutId)
      return self.get_variation_for_rollout(rollout, user_id, attributes)
    else:
      return Decision(None, None, enums.DecisionSources.ROLLOUT)

Returns the experiment/variation the user is bucketed in for the given feature.

Args:
feature: Feature for which we are determining if it is enabled or not for the given user.
user_id: ID for user.
attributes: Dict representing user attributes.

Returns:
Decision namedtuple consisting of experiment and variation for the user.


def remove_send_message(self, connection):

        if connection in self._send_message:
            del self._send_message[connection]
            LOGGER.debug("Removed send_message function "
                         "for connection %s", connection)
        else:
            LOGGER.warning("Attempted to remove send_message "
                           "function for connection %s, but no "
                           "send_message function was registered",
                           connection)

Removes a send_message function previously registered
with the Dispatcher.

Args:
connection (str): A locally unique identifier provided
by the receiver of messages.


def __get_scope(cls,
            expr: Union['Expression', Tuple]) -> Set[str]:

        scope = set()
        for i, atom in enumerate(expr):
            if isinstance(atom, Expression):
                scope.update(cls.__get_scope(atom._expr))
            elif type(atom) in [tuple, list]:
                scope.update(cls.__get_scope(atom))
            elif atom == 'pvar_expr':
                functor, params = expr[i+1]
                arity = len(params) if params is not None else 0
                name = '{}/{}'.format(functor, arity)
                scope.add(name)
                break
        return scope

Returns the set of fluents in the expression's scope.

Args:
expr: Expression object or nested tuple of Expressions.

Returns:
The set of fluents in the expression's scope.


def _is_valid_netmask(self, prefixlen):

        try:
            prefixlen = int(prefixlen)
        except ValueError:
            return False
        return 0 <= prefixlen <= self._max_prefixlen

Verify that the netmask/prefixlen is valid.

Args:
prefixlen: A string, the netmask in prefix length format.

Returns:
A boolean, True if the prefix represents a valid IPv6
netmask.


def do_ams_auth(endpoint, body):

    headers = {"content-type": "application/x-www-form-urlencoded",
               "Accept": json_acceptformat}
    return requests.post(endpoint, data=body, headers=headers)

Acquire Media Services Authentication Token.
Args:
endpoint (str): Azure Media Services Initial Endpoint.
body (str): A Content Body.

Returns:
HTTP response. JSON body.


def insert_into_range(self, operations: ops.OP_TREE, start: int, end: int) -> int:
    if (not (0 <= start <= end <= len(self))):
        raise IndexError('Bad insert indices: [{}, {})'.format(start, end))
    operations = list(ops.flatten_op_tree(operations))
    for op in operations:
        self._device.validate_operation(op)
    i = start
    op_index = 0
    while (op_index < len(operations)):
        op = operations[op_index]
        while ((i < end) and (not self._device.can_add_operation_into_moment(op, self._moments[i]))):
            i += 1
        if (i >= end):
            break
        self._moments[i] = self._moments[i].with_operation(op)
        op_index += 1
    if (op_index >= len(operations)):
        return end
    return self.insert(end, operations[op_index:])

Writes operations inline into an area of the circuit.

Args:
start: The start of the range (inclusive) to write the
given operations into.
end: The end of the range (exclusive) to write the given
operations into. If there are still operations remaining,
new moments are created to fit them.
operations: An operation or tree of operations to insert.

Returns:
An insertion index that will place operations after the operations
that were inserted by this method.

Raises:
IndexError: Bad inline_start and/or inline_end.


def plug(update_kwargs=True, **plugs_map):
    for a_plug in plugs_map.values():
        if (not (isinstance(a_plug, PlugPlaceholder) or issubclass(a_plug, BasePlug))):
            raise InvalidPlugError(('Plug %s is not a subclass of plugs.BasePlug nor a placeholder for one' % a_plug))

    def result(func):
        'Wrap the given function and return the wrapper.\n\n    Args:\n      func: The function to wrap.\n\n    Returns:\n      A PhaseDescriptor that, when called will invoke the wrapped function,\n        passing plugs as keyword args.\n\n    Raises:\n      DuplicatePlugError:  If a plug name is declared twice for the\n          same function.\n    '
        phase = openhtf.core.phase_descriptor.PhaseDescriptor.wrap_or_copy(func)
        duplicates = (frozenset((p.name for p in phase.plugs)) & frozenset(plugs_map))
        if duplicates:
            raise DuplicatePlugError(('Plugs %s required multiple times on phase %s' % (duplicates, func)))
        phase.plugs.extend([PhasePlug(name, a_plug, update_kwargs=update_kwargs) for (name, a_plug) in six.iteritems(plugs_map)])
        return phase
    return result

Creates a decorator that passes in plugs when invoked.

This function returns a decorator for a function that will replace positional
arguments to that function with the plugs specified.  See the module
docstring for details and examples.

Note this decorator does not work with class or bound methods, but does work
with @staticmethod.

Args:
update_kwargs: If true, makes the decorated phase take this plug as a kwarg.
**plugs_map: Dict mapping name to Plug type.

Returns:
A PhaseDescriptor that will pass plug instances in as kwargs when invoked.

Raises:
InvalidPlugError: If a type is provided that is not a subclass of BasePlug.


def create_and_fill_np_array(start_or_end_logits, dataset, max_len):
    step = 0
    logits_concat = np.full((len(dataset), max_len), -100, dtype=np.float32)
    for i, output_logit in enumerate(start_or_end_logits):
        batch_size = output_logit.shape[0]
        cols = output_logit.shape[1]
        if step + batch_size < len(dataset):
            logits_concat[step:step + batch_size, :cols] = output_logit
        else:
            logits_concat[step:, :cols] = output_logit[:len(dataset) - step]
        step += batch_size
    return logits_concat

Create and fill numpy array of size len_of_validation_data * max_length_of_output_tensor

Args:
start_or_end_logits(:obj:`tensor`):
This is the output predictions of the model. We can only enter either start or end logits.
eval_dataset: Evaluation dataset
max_len(:obj:`int`):
The maximum length of the output tensor. ( See the model.eval() part for more details )


def changes(self):
    output = []
    if (self.status() is self.UNMODIFIED):
        output = [(self.formatter % (' ', self.key, self.old_value))]
    elif (self.status() is self.ADDED):
        output.append((self.formatter % ('+', self.key, self.new_value)))
    elif (self.status() is self.REMOVED):
        output.append((self.formatter % ('-', self.key, self.old_value)))
    elif (self.status() is self.MODIFIED):
        output.append((self.formatter % ('-', self.key, self.old_value)))
        output.append((self.formatter % ('+', self.key, self.new_value)))
    return output

Returns a list of changes to represent the diff between
old and new value.

Returns:
list: [string] representation of the change (if any)
between old and new value


def run_instruction(self, op: opcodes.Opcode, state: frame_state.FrameState) -> frame_state.FrameState:
    _opcode_counter.inc(op.name)
    self.frame.current_opcode = op
    self._importing = 'IMPORT' in op.__class__.__name__
    if log.isEnabledFor(logging.INFO):
        vm_utils.log_opcode(op, state, self.frame, len(self.frames))
    if op.line in self._branch_tracker.matches.match_cases:
        state = self._handle_match_case(state, op)
    bytecode_fn = getattr(self, f'byte_{op.name}', None)
    if bytecode_fn is None:
        raise VirtualMachineError(f'Unknown opcode: {op.name}')
    state = bytecode_fn(state, op)
    if state.why in ('reraise', 'Never'):
        state = state.set_why('exception')
    implicit_return = op.name in ('RETURN_VALUE', 'RETURN_CONST') and op.line not in self._director.return_lines
    if len(self.frames) <= 2:
        for err in self._branch_tracker.check_ending(op, implicit_return):
            self.ctx.errorlog.incomplete_match(self.frames, err.line, err.cases)
    self.frame.current_opcode = None
    return state

Run a single bytecode instruction.

Args:
op: An opcode.
state: The state just before running this instruction.

Returns:
The state right after this instruction that should roll over to the
subsequent instruction. If this opcode aborts this function (e.g. through
a 'raise'), then the state's "why" attribute is set to the abort reason.
Raises:
VirtualMachineError: if a fatal error occurs.


def find_dependency_wheels(tile):
    return [os.path.join(x.folder, 'python', x.support_wheel) for x in _iter_dependencies(tile) if x.has_wheel]

Return a list of all python wheel objects created by dependencies of this tile

Args:
tile (IOTile): Tile that we should scan for dependencies

Returns:
list: A list of paths to dependency wheels


async def _async_wait_for_process(future_process: Any, out: Optional[Union[(TeeCapture, IO[str])]]=sys.stdout, err: Optional[Union[(TeeCapture, IO[str])]]=sys.stderr) -> CommandOutput:
    process = (await future_process)
    future_output = _async_forward(process.stdout, out)
    future_err_output = _async_forward(process.stderr, err)
    (output, err_output) = (await asyncio.gather(future_output, future_err_output))
    (await process.wait())
    return CommandOutput(output, err_output, process.returncode)

Awaits the creation and completion of an asynchronous process.

Args:
future_process: The eventually created process.
out: Where to write stuff emitted by the process' stdout.
err: Where to write stuff emitted by the process' stderr.

Returns:
A (captured output, captured error output, return code) triplet.


def _get_samples_shared_with(self, other, index=None):
    if isinstance(other, (pd.DataFrame, Projection)):
        df_other = (other.coords if isinstance(other, Projection) else other)
        if (len(set(df_other.index)) != len(df_other.index)):
            raise ValueError('other index has duplicates')
        if (len(set(self.coords.index)) != len(self.coords.index)):
            raise ValueError('This projection index has duplicates')
        if index:
            uniq_idx = set(index)
            if (len(uniq_idx) != len(index)):
                raise ValueError('index has has duplicates')
            if (uniq_idx - set(df_other.index)):
                raise ValueError('index has samples not in other')
            if (uniq_idx - set(self.coords.index)):
                raise ValueError('index has samples not in this projection')
        else:
            uniq_idx = (set(df_other.index) & set(self.coords.index))
            if (not len(uniq_idx)):
                raise ValueError('No samples shared between other and this projection')
        idx = list(uniq_idx)
        return (self.coords.loc[(idx, :)].values, df_other.loc[(idx, :)].values)
    else:
        other = np.array(other)
        if (other.shape != self.coords.shape):
            raise ValueError('array-like must have the same shape as self.coords')
        return (self.coords.values, other)

Find samples shared with another dataset.

Args:
other
(:py:class:`pymds.Projection` or :py:class:`pandas.DataFrame`
or `array-like`):
The other dataset. If `other` is an instance of
:py:class:`pymds.Projection` or :py:class:`pandas.DataFrame`,
then `other` must have indexes in common with this projection.
If `array-like`, then other must have same dimensions as
`self.coords`.
index (`list-like` or `None`): If `other` is an instance of
:py:class:`pymds.Projection` or :py:class:`pandas.DataFrame`
then only return samples in index.

Returns:
`tuple`: containing:

- this (`numpy.array`) Shape [`x`, `n`].
- other (`numpy.array`) Shape [`x`, `n`].


def zip_fit_params(data):
    (genes, cells) = data.shape
    m = data.mean(1)
    v = data.var(1)
    M = ((v - m) / (((m ** 2) + v) - m))
    M = np.array([min(1.0, max(0.0, x)) for x in M])
    L = ((m + (v / m)) - 1.0)
    L[np.isnan(L)] = 0.0
    L = np.array([max(0.0, x) for x in L])
    return (L, M)

Returns the ZIP parameters that best fit a given data set.

Args:
data (array): 2d array of genes x cells belonging to a given cluster

Returns:
L (array): 1d array of means
M (array): 1d array of zero-inflation parameter


def probability_density(self, X):

        self.check_fit()
        return norm.pdf(X, loc=self.mean, scale=self.std)

Compute probability density.

Arguments:
X: `np.ndarray` of shape (n, 1).

Returns:
np.ndarray


def StartsWith(this, that):

  this_iter = iter(this)
  that_iter = iter(that)

  while True:
    try:
      this_value = next(that_iter)
    except StopIteration:
      return True

    try:
      that_value = next(this_iter)
    except StopIteration:
      return False

    if this_value != that_value:
      return False

Checks whether an items of one iterable are a prefix of another.

Args:
this: An iterable that needs to be checked.
that: An iterable of which items must match the prefix of `this`.

Returns:
`True` if `that` is a prefix of `this`, `False` otherwise.


def _hertz_to_mel(frequencies_hertz, name=None):
    with ops.name_scope(name, 'hertz_to_mel', [frequencies_hertz]):
        frequencies_hertz = ops.convert_to_tensor(frequencies_hertz)
        return _MEL_HIGH_FREQUENCY_Q * math_ops.log(1.0 + frequencies_hertz / _MEL_BREAK_FREQUENCY_HERTZ)

Converts frequencies in `frequencies_hertz` in Hertz to the mel scale.

Args:
frequencies_hertz: A `Tensor` of frequencies in Hertz.
name: An optional name for the operation.

Returns:
A `Tensor` of the same shape and type of `frequencies_hertz` containing
frequencies in the mel scale.


def ub_to_str(string):

    if not isinstance(string, str):
        if six.PY2:
            return str(string)
        else:
            return string.decode()
    return string

converts py2 unicode / py3 bytestring into str
Args:
string (unicode, byte_string): string to be converted

Returns:
(str)


def add_argument(self, parser, bootstrap=False):
    tmp_default = self.default
    exclusive_grp = parser.add_mutually_exclusive_group()
    self.default = True
    args = self._get_argparse_names(parser.prefix_chars)
    kwargs = self._get_argparse_kwargs(bootstrap)
    exclusive_grp.add_argument(*args, **kwargs)
    self.default = False
    args = self._get_argparse_names(parser.prefix_chars)
    kwargs = self._get_argparse_kwargs(bootstrap)
    exclusive_grp.add_argument(*args, **kwargs)
    self.default = tmp_default

Add boolean item as an argument to the given parser.

An exclusive group is created on the parser, which will add
a boolean-style command line argument to the parser.

Examples:
A non-nested boolean value with the name 'debug' will result
in a command-line argument like the following:

'--debug/--no-debug'

Args:
parser (argparse.ArgumentParser): The parser to add this item to.
bootstrap (bool): Flag to indicate whether you only want to mark
this item as required or not.


def run_metadata(name, data, step=None):
    summary_metadata = summary_pb2.SummaryMetadata()
    summary_metadata.plugin_data.plugin_name = 'graph_run_metadata'
    summary_metadata.plugin_data.content = b'1'
    with summary_scope(name, 'graph_run_metadata_summary', [data, step]) as (tag, _):
        with ops.device('cpu:0'):
            tensor = constant_op.constant(data.SerializeToString(), dtype=dtypes.string)
        return write(tag=tag, tensor=tensor, step=step, metadata=summary_metadata)

Writes entire RunMetadata summary.

A RunMetadata can contain DeviceStats, partition graphs, and function graphs.
Please refer to the proto for definition of each field.

Args:
name: A name for this summary. The summary tag used for TensorBoard will be
this name prefixed by any active name scopes.
data: A RunMetadata proto to write.
step: Explicit `int64`-castable monotonic step value for this summary. If
omitted, this defaults to `tf.summary.experimental.get_step()`, which must
not be None.

Returns:
True on success, or false if no summary was written because no default
summary writer was available.

Raises:
ValueError: if a default writer exists, but no step was provided and
`tf.summary.experimental.get_step()` is None.


def publish(self, topic, dct):
    get_logger().info('Publishing message {} on routing key {}...'.format(dct, topic))
    self._channel.basic_publish(exchange=self.exchange, routing_key=topic, body=json.dumps(dct))

Send a dict with internal routing key to the exchange.

Args:
topic: topic to publish the message to
dct: dict object to send


def from_dict(cls, d, fmt=None):

        if fmt == "abivars":
            from pymatgen.io.abinit.abiobjects import structure_from_abivars
            return structure_from_abivars(cls=cls, **d)

        lattice = Lattice.from_dict(d["lattice"])
        sites = [PeriodicSite.from_dict(sd, lattice) for sd in d["sites"]]
        charge = d.get("charge", None)
        return cls.from_sites(sites, charge=charge)

Reconstitute a Structure object from a dict representation of Structure
created using as_dict().

Args:
d (dict): Dict representation of structure.

Returns:
Structure object


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

    class OrderedUniqueLoader(loader):

        NO_DUPE_SIBLINGS = ["stacks", "class_path"]

        NO_DUPE_CHILDREN = ["stacks"]

        def _error_mapping_on_dupe(self, node, node_name):

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

        def _validate_mapping(self, node, deep=False):
            if not isinstance(node, MappingNode):
                raise ConstructorError(
                    None, None,
                    "expected a mapping node, but found %s" % node.id,
                    node.start_mark)
            mapping = OrderedDict()
            for key_node, value_node in node.value:
                key = self.construct_object(key_node, deep=deep)
                try:
                    hash(key)
                except TypeError as exc:
                    raise ConstructorError(
                        "while constructing a mapping", node.start_mark,
                        "found unhashable key (%s)" % exc, key_node.start_mark
                    )

                if key in mapping and key in self.NO_DUPE_SIBLINGS:
                    msg = "{} key cannot have duplicate siblings {} {}"
                    raise ConstructorError(
                        msg.format(key, node.start_mark, key_node.start_mark)
                    )
                if key in self.NO_DUPE_CHILDREN:

                    self._error_mapping_on_dupe(value_node, key_node.value)
                value = self.construct_object(value_node, deep=deep)
                mapping[key] = value
            return mapping

        def construct_mapping(self, node, deep=False):

            if isinstance(node, MappingNode):
                self.flatten_mapping(node)
            return self._validate_mapping(node, deep=deep)

        def construct_yaml_map(self, node):
            data = OrderedDict()
            yield data
            value = self.construct_mapping(node)
            data.update(value)

    OrderedUniqueLoader.add_constructor(
        u'tag:yaml.org,2002:map', OrderedUniqueLoader.construct_yaml_map,
    )
    return yaml.load(stream, OrderedUniqueLoader)

Provides yaml.load alternative with preserved dictionary order.

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

Returns:
OrderedDict: Parsed YAML.


def user_exists(self, username):

        response = self._get(self.rest_url + "/user",
                             params={"username": username})

        if not response.ok:
            return None

        return True

Determines if the user exists.

Args:
username: The user name.

Returns:
bool:
True if the user exists in the Crowd application.


def ParseFileObject(self, parser_mediator, file_object):

    if file_object.read(1) != b'{':
      raise errors.UnableToParseFile((
          '[{0:s}] {1:s} is not a valid Preference file, '
          'missing opening brace.').format(
              self.NAME, parser_mediator.GetDisplayName()))

    file_object.seek(0, os.SEEK_SET)
    file_content = file_object.read()
    file_content = codecs.decode(file_content, self._ENCODING)

    try:
      json_dict = json.loads(file_content)
    except ValueError as exception:
      raise errors.UnableToParseFile((
          '[{0:s}] Unable to parse file {1:s} as JSON: {2!s}').format(
              self.NAME, parser_mediator.GetDisplayName(), exception))
    except IOError as exception:
      raise errors.UnableToParseFile((
          '[{0:s}] Unable to open file {1:s} for parsing as'
          'JSON: {2!s}').format(
              self.NAME, parser_mediator.GetDisplayName(), exception))

    if not set(self.REQUIRED_KEYS).issubset(set(json_dict.keys())):
      raise errors.UnableToParseFile('File does not contain Preference data.')

    extensions_setting_dict = json_dict.get('extensions')
    if not extensions_setting_dict:
      raise errors.UnableToParseFile(
          '[{0:s}] {1:s} is not a valid Preference file, '
          'does not contain extensions value.'.format(
              self.NAME, parser_mediator.GetDisplayName()))

    extensions_dict = extensions_setting_dict.get('settings')
    if not extensions_dict:
      raise errors.UnableToParseFile(
          '[{0:s}] {1:s} is not a valid Preference file, '
          'does not contain extensions settings value.'.format(
              self.NAME, parser_mediator.GetDisplayName()))

    extensions_autoupdate_dict = extensions_setting_dict.get('autoupdate')
    if extensions_autoupdate_dict:
      autoupdate_lastcheck_timestamp = extensions_autoupdate_dict.get(
          'last_check', None)

      if autoupdate_lastcheck_timestamp:
        autoupdate_lastcheck = int(autoupdate_lastcheck_timestamp, 10)

        event_data = ChromeExtensionsAutoupdaterEventData()
        event_data.message = 'Chrome extensions autoupdater last run'

        date_time = dfdatetime_webkit_time.WebKitTime(
            timestamp=autoupdate_lastcheck)
        event = time_events.DateTimeValuesEvent(
            date_time, definitions.TIME_DESCRIPTION_ADDED)
        parser_mediator.ProduceEventWithEventData(event, event_data)

      autoupdate_nextcheck_timestamp = extensions_autoupdate_dict.get(
          'next_check', None)
      if autoupdate_nextcheck_timestamp:
        autoupdate_nextcheck = int(autoupdate_nextcheck_timestamp, 10)

        event_data = ChromeExtensionsAutoupdaterEventData()
        event_data.message = 'Chrome extensions autoupdater next run'

        date_time = dfdatetime_webkit_time.WebKitTime(
            timestamp=autoupdate_nextcheck)
        event = time_events.DateTimeValuesEvent(
            date_time, definitions.TIME_DESCRIPTION_ADDED)
        parser_mediator.ProduceEventWithEventData(event, event_data)

    browser_dict = json_dict.get('browser', None)
    if browser_dict and 'last_clear_browsing_data_time' in browser_dict:
      last_clear_history_timestamp = browser_dict.get(
          'last_clear_browsing_data_time', None)

      if last_clear_history_timestamp:
        last_clear_history = int(last_clear_history_timestamp, 10)

        event_data = ChromeExtensionsAutoupdaterEventData()
        event_data.message = 'Chrome history was cleared by user'

        date_time = dfdatetime_webkit_time.WebKitTime(
            timestamp=last_clear_history)
        event = time_events.DateTimeValuesEvent(
            date_time, definitions.TIME_DESCRIPTION_DELETED)
        parser_mediator.ProduceEventWithEventData(event, event_data)

    self._ExtractExtensionInstallEvents(extensions_dict, parser_mediator)

    profile_dict = json_dict.get('profile', None)
    if profile_dict:
      content_settings_dict = profile_dict.get('content_settings', None)
      if content_settings_dict:
        exceptions_dict = content_settings_dict.get('exceptions', None)
        if exceptions_dict:
          self._ExtractContentSettingsExceptions(
              exceptions_dict, parser_mediator)

Parses a Chrome preferences file-like object.

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

Raises:
UnableToParseFile: when the file cannot be parsed.


def __init__(self, scope, parent, explicit=True):

        CodeStatement.__init__(self, scope, parent)
        self.body = []
        self.explicit = explicit

Constructor for code blocks.

Args:
scope (CodeEntity): The program scope where this object belongs.
parent (CodeEntity): This object's parent in the program tree.

Kwargs:
explicit (bool): Whether the block is explicit in the code.


def clone(self, name=None):

    if name is None:
      name = self.module_name + "_clone"

    return type(self)(output_channels=self.output_channels,
                      kernel_shape=self._kernel_shape,
                      stride=self._stride,
                      rate=self._rate,
                      padding=self._padding,
                      use_bias=self._use_bias,
                      initializers=self._initializers,
                      partitioners=self._partitioners,
                      regularizers=self._regularizers,
                      mask=self._mask,
                      data_format=self._data_format,
                      custom_getter=self._custom_getter,
                      name=name)

Returns a cloned `_ConvND` module.

Args:
name: Optional string assigning name of cloned module. The default name
is constructed by appending "_clone" to `self.module_name`.

Returns:
A copy of the current class.


def tokenize(self, s, pattern=None, active=None):

        if pattern is None:
            if self.tokenize_pattern is None:
                pattern = r'[ \t]+'
            else:
                pattern = self.tokenize_pattern
        if active is None:
            active = self.active
        return self.group.tokenize(s, pattern=pattern, active=active)

Rewrite and tokenize the input string *s*.

Args:
s (str): the input string to process
pattern (str, optional): the regular expression pattern on
which to split tokens; defaults to `[ \t]+`
active (optional): a collection of external module names
that may be applied if called
Returns:
a :class:`~delphin.tokens.YyTokenLattice` containing the
tokens and their characterization information


def _process_parameters_section(func_documentation, sig, func, class_name, model_name_lowercase, parent_class, indent_level):
    docstring = set_min_indent('Args:\n', indent_level + 4)
    undocumented_parameters = []
    documented_params = {}
    documented_kwargs = {}
    if func_documentation is not None:
        documented_params, func_documentation = parse_docstring(func_documentation)
        if model_name_lowercase is not None:
            documented_params = format_args_docstring(documented_params, model_name_lowercase)
    param_docstring, missing_args = _process_regular_parameters(sig, func, class_name, documented_params, indent_level, undocumented_parameters)
    docstring += param_docstring
    kwargs_docstring = _process_kwargs_parameters(sig, func, parent_class, model_name_lowercase, documented_kwargs, indent_level, undocumented_parameters)
    docstring += kwargs_docstring
    if len(undocumented_parameters) > 0:
        print('\n'.join(undocumented_parameters))
    return docstring

Process the parameters section of the docstring.

Args:
func_documentation (`str`): Existing function documentation (manually specified in the docstring)
sig (`inspect.Signature`): Function signature
func (`function`): Function the parameters belong to
class_name (`str`): Name of the class the function belongs to
model_name_lowercase (`str`): Lowercase model name
parent_class (`class`): Parent class of the function (if any)
indent_level (`int`): Indentation level


def retrieve_token(self, token):

        headers = self.client._get_private_headers()
        endpoint = '/tokens/{}'.format(token)
        return self.client._get(self.client.URL_BASE + endpoint, headers=headers)

Retrieve Token details for a specific Token.

Args:
token: The identifier of the token.

Returns:


def get_link_flags():
    is_mac = _platform.system() == 'Darwin'
    ver = _VERSION.split('.')[0]
    flags = []
    if not _MONOLITHIC_BUILD:
        flags.append('-L%s' % get_lib())
        if is_mac:
            flags.append('-ltensorflow_framework.%s' % ver)
        else:
            flags.append('-l:libtensorflow_framework.so.%s' % ver)
    return flags

Returns the linker flags for linking with TensorFlow.

The returned list of arguments can be passed to the linker for linking against
TensorFlow. The result is platform dependent.

For example, on a typical Linux system with Python 3.7 the following command
prints `['-L/usr/local/lib/python3.7/dist-packages/tensorflow',
'-l:libtensorflow_framework.so.2']`

>>> print(tf.sysconfig.get_link_flags())

Returns:
A list of strings for the linker flags.


def __parse_cmd_args(args, sudo, shell):
    if (isinstance(args, tuple) and (len(args) == 1) and isinstance(args[0], tuple)):
        args = args[0]
    if shell:
        if isinstance(args, six.string_types):
            pass
        elif (isinstance(args, (list, tuple)) and (len(args) > 1)):
            args = ' '.join(args)
        elif (isinstance(args, (list, tuple)) and (len(args) == 1)):
            if isinstance(args[0], (tuple, list)):
                args = ' '.join(args)
            elif isinstance(args[0], six.string_types):
                args = args[0]
    elif isinstance(args, six.string_types):
        args = shlex.split(args, posix=(not WIN32))
    elif isinstance(args, (list, tuple)):
        if (len(args) > 1):
            args = tuple(args)
        elif (len(args) == 1):
            if isinstance(args[0], (tuple, list)):
                args = tuple(args[0])
            elif isinstance(args[0], six.string_types):
                args = shlex.split(args[0], posix=(not WIN32))
    if (sudo is True):
        if (not WIN32):
            if shell:
                args = ('sudo ' + args)
            else:
                args = (tuple(['sudo']) + tuple(args))
        else:
            pass
    if WIN32:
        if ((len(args) == 1) and isinstance(args[0], six.string_types)):
            args = shlex.split(args[0], posix=(not WIN32))
    return args

When shell is True, Popen will only accept strings. No tuples
Shell really should not be true.

Returns:
args suitable for subprocess.Popen

I'm not quite sure what those are yet. Plain old string seem to work
well? But I remember needing shlex at some point.

CommandLine:
python -m utool.util_cplat --test-__parse_cmd_args

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_cplat import *  # NOQA
>>> # build test data
>>> args = 'echo "hello world"'
>>> sudo = False
>>> shell = False
>>> # execute function
>>> args = __parse_cmd_args(args, sudo, shell)
>>> # verify results
>>> result = str(args)
>>> print(result)


def is_valid_assignment(self, mtf_dimension_name, mesh_dimension_name):
    return ((mtf_dimension_name in self._splittable_mtf_dimension_names) and ((self._mtf_dimension_name_to_size_gcd[mtf_dimension_name] % self._mesh_dimension_name_to_size[mesh_dimension_name]) == 0))

Whether this MTF dimension may be assigned to this mesh dimension.

Args:
mtf_dimension_name: string, the name of a Mesh TensorFlow dimension.
mesh_dimension_name: string, the name of a mesh dimension.

Returns:
A boolean indicating whether the assignment is valid.


def parse(file_contents, file_name):

    env = Environment()
    result = ""
    try:
        env.parse(file_contents)
    except Exception:
        _, exc_value, _ = sys.exc_info()
        result += "ERROR: Jinja2 Template File: {0}".format(file_name)
        result += repr(exc_value) + '\n'

    return result

Takes a list of files which are assumed to be jinja2 templates and tries to
parse the contents of the files

Args:
file_contents (str): File contents of a jinja file

Raises:
Exception: An exception is raised if the contents of the file cannot be
parsed.


def with_values(self, new_values):
    new_values = _convert_to_ragged_tensor_values(new_values)
    new_values.shape.with_rank_at_least(1)
    self.values.shape[:1].assert_is_compatible_with(new_values.shape[:1])
    if isinstance(new_values, RaggedTensor) and self._row_partition.dtype != new_values.row_splits.dtype:
        if not ragged_config.auto_cast_partition_dtype():
            raise ValueError('self and new_values have mismatched row_splits dtypes; use RaggedTensor.with_row_splits_dtype() to convert them to compatible dtypes.')
        new_values = new_values.with_row_splits_dtype(dtypes.int64)
        return self.with_row_splits_dtype(dtypes.int64).with_values(new_values)
    return RaggedTensor(values=new_values, row_partition=self._row_partition, internal=True)

Returns a copy of `self` with `values` replaced by `new_value`.

Preserves cached row-partitioning tensors such as `self.cached_nrows` and
`self.cached_value_rowids` if they have values.

Args:
new_values: Potentially ragged tensor to use as the `values` for the
returned `RaggedTensor`.  Must have `rank > 0`, and must have the same
number of rows as `self.values`.

Returns:
A `RaggedTensor`.  `result.rank = 1 + new_values.rank`.
`result.ragged_rank = 1 + new_values.ragged_rank`


def MakePmfFromItems(t, name=''):

    pmf = Pmf(dict(t), name)
    pmf.Normalize()
    return pmf

Makes a PMF from a sequence of value-probability pairs

Args:
t: sequence of value-probability pairs
name: string name for this PMF

Returns:
Pmf object


def locked_put(self, credentials):

        keyring.set_password(self._service_name, self._user_name,
                             credentials.to_json())

Write Credentials to file.

Args:
credentials: Credentials, the credentials to store.


def write(gctoo, out_fname, data_null='NaN', metadata_null='-666', filler_null='-666', data_float_format='%.4f'):
    if (not out_fname.endswith('.gct')):
        out_fname += '.gct'
    f = open(out_fname, 'w')
    dims = [str(gctoo.data_df.shape[0]), str(gctoo.data_df.shape[1]), str(gctoo.row_metadata_df.shape[1]), str(gctoo.col_metadata_df.shape[1])]
    write_version_and_dims(VERSION, dims, f)
    write_top_half(f, gctoo.row_metadata_df, gctoo.col_metadata_df, metadata_null, filler_null)
    write_bottom_half(f, gctoo.row_metadata_df, gctoo.data_df, data_null, data_float_format, metadata_null)
    f.close()
    logger.info('GCT has been written to {}'.format(out_fname))

Write a gctoo object to a gct file.

Args:
gctoo (gctoo object)
out_fname (string): filename for output gct file
data_null (string): how to represent missing values in the data (default = "NaN")
metadata_null (string): how to represent missing values in the metadata (default = "-666")
filler_null (string): what value to fill the top-left filler block with (default = "-666")
data_float_format (string): how many decimal points to keep in representing data
(default = 4 digits; None will keep all digits)

Returns:
None


def get_app_hostname():
    if ((not is_running_on_app_engine()) or is_running_on_localhost()):
        return None
    app_id = app_identity.get_application_id()
    prefix = get_hostname_prefix()
    suffix = 'appspot.com'
    if (':' in app_id):
        tokens = app_id.split(':')
        api_name = tokens[1]
        if (tokens[0] == 'google.com'):
            suffix = 'googleplex.com'
    else:
        api_name = app_id
    return '{0}{1}.{2}'.format(prefix, api_name, suffix)

Return hostname of a running Endpoints service.

Returns hostname of an running Endpoints API. It can be 1) "localhost:PORT"
if running on development server, or 2) "app_id.appspot.com" if running on
external app engine prod, or "app_id.googleplex.com" if running as Google
first-party Endpoints API, or 4) None if not running on App Engine
(e.g. Tornado Endpoints API).

Returns:
A string representing the hostname of the service.


def info(name):
    try:
        handle_scm = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_CONNECT)
    except pywintypes.error as exc:
        raise CommandExecutionError('Failed to connect to the SCM: {0}'.format(exc.strerror))
    try:
        handle_svc = win32service.OpenService(handle_scm, name, (((win32service.SERVICE_ENUMERATE_DEPENDENTS | win32service.SERVICE_INTERROGATE) | win32service.SERVICE_QUERY_CONFIG) | win32service.SERVICE_QUERY_STATUS))
    except pywintypes.error as exc:
        raise CommandExecutionError('Failed To Open {0}: {1}'.format(name, exc.strerror))
    try:
        config_info = win32service.QueryServiceConfig(handle_svc)
        status_info = win32service.QueryServiceStatusEx(handle_svc)
        try:
            description = win32service.QueryServiceConfig2(handle_svc, win32service.SERVICE_CONFIG_DESCRIPTION)
        except pywintypes.error:
            description = 'Failed to get description'
        delayed_start = win32service.QueryServiceConfig2(handle_svc, win32service.SERVICE_CONFIG_DELAYED_AUTO_START_INFO)
    finally:
        win32service.CloseServiceHandle(handle_scm)
        win32service.CloseServiceHandle(handle_svc)
    ret = dict()
    try:
        sid = win32security.LookupAccountName('', 'NT Service\\{0}'.format(name))[0]
        ret['sid'] = win32security.ConvertSidToStringSid(sid)
    except pywintypes.error:
        ret['sid'] = 'Failed to get SID'
    ret['BinaryPath'] = config_info[3]
    ret['LoadOrderGroup'] = config_info[4]
    ret['TagID'] = config_info[5]
    ret['Dependencies'] = config_info[6]
    ret['ServiceAccount'] = config_info[7]
    ret['DisplayName'] = config_info[8]
    ret['Description'] = description
    ret['Status_ServiceCode'] = status_info['ServiceSpecificExitCode']
    ret['Status_CheckPoint'] = status_info['CheckPoint']
    ret['Status_WaitHint'] = status_info['WaitHint']
    ret['StartTypeDelayed'] = delayed_start
    flags = list()
    for bit in SERVICE_TYPE:
        if isinstance(bit, int):
            if (config_info[0] & bit):
                flags.append(SERVICE_TYPE[bit])
    ret['ServiceType'] = (flags if flags else config_info[0])
    flags = list()
    for bit in SERVICE_CONTROLS:
        if (status_info['ControlsAccepted'] & bit):
            flags.append(SERVICE_CONTROLS[bit])
    ret['ControlsAccepted'] = (flags if flags else status_info['ControlsAccepted'])
    try:
        ret['Status_ExitCode'] = SERVICE_ERRORS[status_info['Win32ExitCode']]
    except KeyError:
        ret['Status_ExitCode'] = status_info['Win32ExitCode']
    try:
        ret['StartType'] = SERVICE_START_TYPE[config_info[1]]
    except KeyError:
        ret['StartType'] = config_info[1]
    try:
        ret['ErrorControl'] = SERVICE_ERROR_CONTROL[config_info[2]]
    except KeyError:
        ret['ErrorControl'] = config_info[2]
    try:
        ret['Status'] = SERVICE_STATE[status_info['CurrentState']]
    except KeyError:
        ret['Status'] = status_info['CurrentState']
    return ret

Get information about a service on the system

Args:
name (str): The name of the service. This is not the display name. Use
``get_service_name`` to find the service name.

Returns:
dict: A dictionary containing information about the service.

CLI Example:

.. code-block:: bash

salt '*' service.info spooler


def stop_instance(self):
    stop_url = self._get_url('stop_path')
    res = self.rest_client.session.put(stop_url, json={})
    _handle_http_errors(res)
    return res.json()

Stop the instance for this Streaming Analytics service.

Returns:
dict: JSON response for the instance stop operation.


def sync_executors(self):
    if self._context_handle:
        pywrap_tfe.TFE_ContextSyncExecutors(self._context_handle)
    else:
        raise ValueError('Context is not initialized.')

Sync both local executors and the ones on remote workers.

In async execution mode, local function calls can return before the
corresponding remote op/function execution requests are completed. Calling
this method creates a synchronization barrier for remote executors. It only
returns when all remote pending nodes are finished, potentially with errors
if any remote executors are in error state.

Raises:
ValueError: if context is not initialized.


def back_propagation(self, delta_arr):

        re_encoder_delta_arr, delta_hidden_arr, re_encoder_grads_list = self.__retrospective_encoder.hidden_back_propagate(
            delta_arr[:, -1]
        )
        re_encoder_grads_list.insert(0, None)
        re_encoder_grads_list.insert(0, None)

        observed_arr, encoded_arr, decoded_arr, re_encoded_arr = self.__inferenced_tuple
        delta_arr = self.__encoder_decoder_controller.computable_loss.compute_delta(
            decoded_arr,
            observed_arr
        )
        delta_arr[:, -1] += re_encoder_delta_arr[:, -1]

        decoder_grads_list, encoder_delta_arr, encoder_grads_list = self.__encoder_decoder_controller.back_propagation(
            delta_arr
        )
        return re_encoder_grads_list, decoder_grads_list, encoder_delta_arr, encoder_grads_list

Back propagation.

Args:
delta_output_arr:    Delta.

Returns:
Tuple data.
- decoder's `list` of gradations,
- encoder's `np.ndarray` of Delta,
- encoder's `list` of gradations.


def recombine(self, parents: List[pg.DNA], global_state: pg.geno.AttributeDict, step: int) -> List[pg.DNA]:

Generate a list of child DNA based on the list of parents given.

User should override this method with optional keyword arguments
'global_state' and 'step'.

The parents DNA contains a metadata field 'generation', which is the
generation of the parent DNA. If the Recombinator does not assign this
field for the new child DNA, the child DNA will have the maximum generation
from the parents plus 1.

Args:
parents: Parent trials.
global_state: An `AttributeDict` object as the global state container,
which is readable/writable during the operation.
step: Number of examples historically proposed, which can be used for
determining a cross over schedule.

Returns:
A list of generated child DNA.


def console_get_width(con: tcod.console.Console) -> int:
    return int(lib.TCOD_console_get_width(_console(con)))

Return the width of a console.

Args:
con (Console): Any Console instance.

Returns:
int: The width of a Console.

.. deprecated:: 2.0
Use `Console.width` instead.


def get(account_id, account_type_id=None):

        if type(account_id) == str:
            args = {'account_name': account_id}
        else:
            args = {'account_id': account_id}

        if account_type_id:
            args['account_type_id'] = account_type_id

        return db.Account.find_one(**args)

Return account by ID and type

Args:
account_id (`int`, `str`): Unique Account identifier
account_type_id (str): Type of account to get

Returns:
:obj:`Account`: Returns an Account object if found, else None


def __init__(self, scaffold=None, master='', config=None, checkpoint_dir=None, checkpoint_filename_with_path=None):
    self._checkpoint_dir = checkpoint_dir
    self._checkpoint_filename_with_path = checkpoint_filename_with_path
    self._scaffold = scaffold or Scaffold()
    self._session_manager = None
    self._master = master
    self._config = config

Initializes a chief session creator.

Args:
scaffold: A `Scaffold` used for gathering or building supportive ops. If
not specified a default one is created. It's used to finalize the graph.
master: `String` representation of the TensorFlow master to use.
config: `ConfigProto` proto used to configure the session.
checkpoint_dir: A string.  Optional path to a directory where to restore
variables.
checkpoint_filename_with_path: Full file name path to the checkpoint file.


def can_user_access_build(param_name):
    build_id = (request.args.get(param_name, type=int) or request.form.get(param_name, type=int) or request.json[param_name])
    if (not build_id):
        logging.debug('Build ID in param_name=%r was missing', param_name)
        abort(400)
    ops = operations.UserOps(current_user.get_id())
    (build, user_is_owner) = ops.owns_build(build_id)
    if (not build):
        logging.debug('Could not find build_id=%r', build_id)
        abort(404)
    if (current_user.is_authenticated() and (not user_is_owner)):
        ops.evict()
        claim_invitations(current_user)
        (build, user_is_owner) = ops.owns_build(build_id)
    if (not user_is_owner):
        if (current_user.is_authenticated() and current_user.superuser):
            pass
        elif (request.method != 'GET'):
            logging.debug('No way to log in user via modifying request')
            abort(403)
        elif build.public:
            pass
        elif current_user.is_authenticated():
            logging.debug('User does not have access to this build')
            abort(flask.Response('You cannot access this build', 403))
        else:
            logging.debug('Redirecting user to login to get build access')
            abort(login.unauthorized())
    elif (not login_fresh()):
        logging.debug('User login is old; forcing refresh')
        abort(login.needs_refresh())
    return build

Determines if the current user can access the build ID in the request.

Args:
param_name: Parameter name to use for getting the build ID from the
request. Will fetch from GET or POST requests.

Returns:
The build the user has access to.


def __init__(self, filenames, index=0, buffer_size=None, _account_id=None,
               delimiter=None):

    self._filenames = filenames
    self._index = index
    self._buffer_size = buffer_size
    self._account_id = _account_id
    self._delimiter = delimiter
    self._bucket = None
    self._bucket_iter = None

    self._fail_on_missing_input = None

Initialize a GoogleCloudStorageInputReader instance.

Args:
filenames: A list of Google Cloud Storage filenames of the form
'/bucket/objectname'.
index: Index of the next filename to read.
buffer_size: The size of the read buffer, None to use default.
_account_id: Internal use only. See cloudstorage documentation.
delimiter: Delimiter used as path separator. See class doc for details.


def _StopStyleSelectionMethod(self, doc):
    if (not self.show_stop_hierarchy):
        return (lambda stop: (None, None))
    self._CreateStyle(doc, 'stop_entrance', {'IconStyle': {'color': 'ff0000ff'}})
    self._CreateStyle(doc, 'entrance_connection', {'LineStyle': {'color': 'ff0000ff', 'width': '2'}})
    self._CreateStyle(doc, 'stop_platform', {'IconStyle': {'color': 'ffff0000'}})
    self._CreateStyle(doc, 'platform_connection', {'LineStyle': {'color': 'ffff0000', 'width': '2'}})
    self._CreateStyle(doc, 'stop_standalone', {'IconStyle': {'color': 'ff00ff00'}})

    def StyleSelectionMethod(stop):
        if (stop.location_type == transitfeed.Stop.LOCATION_TYPE_STATION):
            return ('stop_station', None)
        elif (stop.location_type == googletransit.Stop.LOCATION_TYPE_ENTRANCE):
            return ('stop_entrance', 'entrance_connection')
        elif stop.parent_station:
            return ('stop_platform', 'platform_connection')
        return ('stop_standalone', None)
    return StyleSelectionMethod

Create a method to determine which style to apply to a stop placemark.

Args:
doc: the KML document.

Returns:
A function that should accept a Stop argument and return a tuple of
(stop placemark style id, pathway placemark style id).  Either style id
can be None, indicating no style should be set.

Given a Stop, we need to determine what KML style to apply to the stops'
placemark.  In the most basic case, no styling is applied.  However, if
show_stop_hierarchy is enabled, we style each type of stop differently
depending on if the stop is a station, platform, entrance, etc.  This method
returns a function that is used to pick which style id should be associated
with a stop placemark, or None if no style should be applied.  It also
optionally returns a style id to associate with any line-string connections
associated with a stop (eg. to show the pathway between an entrance and a
station).


def _ReadCompressedData(self, read_size):

    self._uncompressed_data = self._zip_ext_file.read(read_size)
    self._uncompressed_data_size = len(self._uncompressed_data)

Reads compressed data from the file-like object.

Args:
read_size (int): number of bytes of compressed data to read.


def to_json(value: Any, **kwargs) -> Any:
    if isinstance(value, (type(None), bool, int, float, str)):
        v = value
    elif isinstance(value, JSONConvertible):
        v = value.to_json(**kwargs)
    elif isinstance(value, tuple):
        v = [JSONConvertible.TUPLE_MARKER] + to_json(list(value), **kwargs)
    elif isinstance(value, list):
        v = [to_json(item, **kwargs) for item in value]
    elif isinstance(value, dict):
        v = {k: to_json(v, **kwargs) for k, v in value.items()}
    elif isinstance(value, (type, typing.GenericAlias)):
        v = _type_to_json(value)
    elif inspect.isbuiltin(value):
        v = _builtin_function_to_json(value)
    elif inspect.isfunction(value):
        v = _function_to_json(value)
    elif inspect.ismethod(value):
        v = _method_to_json(value)
    elif isinstance(value, typing._Final):
        v = _annotation_to_json(value)
    elif value is ...:
        v = {JSONConvertible.TYPE_NAME_KEY: 'type', 'name': 'builtins.Ellipsis'}
    else:
        v, converted = (None, False)
        if JSONConvertible.TYPE_CONVERTER is not None:
            converter = JSONConvertible.TYPE_CONVERTER(type(value))
            if converter:
                v = to_json(converter(value))
                converted = True
        if not converted:
            v = _OpaqueObject(value).to_json(**kwargs)
    return v

Serializes a (maybe) JSONConvertible value into a plain Python object.

Args:
value: value to serialize. Applicable value types are:

* Builtin python types: None, bool, int, float, string;
* JSONConvertible types;
* List types;
* Tuple types;
* Dict types.

**kwargs: Keyword arguments to pass to value.to_json if value is
JSONConvertible.

Returns:
JSON value.


def to_python(self):
    return (self.selector, COMPARISON_MAP.get(self.comparison, self.comparison), self.argument)

Deconstruct the ``Constraint`` instance to a tuple.

Returns:
tuple: The deconstructed ``Constraint``.


def _parse_username(self, config):

        (username, priv, role, nopass, fmt, secret, sshkey) = config
        resource = dict()
        resource['privilege'] = priv
        resource['role'] = role
        resource['nopassword'] = nopass == 'nopassword'
        resource['format'] = fmt
        resource['secret'] = secret
        resource['sshkey'] = sshkey
        return {username: resource}

Scans the config block and returns the username as a dict

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

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


def AddBackpropAccumulatedValue(self, history_value, value, dead_branch=False):
    history_ctxt = history_value.op._get_control_flow_context()
    cond_ctxt = None
    value_ctxt = value.op._get_control_flow_context()
    while value_ctxt and value_ctxt != history_ctxt:
        if isinstance(value_ctxt, control_flow_ops.CondContext):
            cond_ctxt = value_ctxt
            break
        value_ctxt = value_ctxt.outer_context
    with ops.control_dependencies(None):
        self.grad_context.Enter()
        if cond_ctxt:
            grad_state = self
            pred = None
            while pred is None and grad_state:
                pred = grad_state.history_map.get(cond_ctxt.pred.name)
                grad_state = grad_state.outer_grad_state
            if pred is None:
                pred = cond_ctxt.pred
            branch = 1 - cond_ctxt.branch if dead_branch else cond_ctxt.branch
            history_value = control_flow_ops._SwitchRefOrTensor(history_value, pred)[branch]
        pop = gen_data_flow_ops.stack_pop_v2(history_value, value.dtype.base_dtype)
        pop.set_shape(value.get_shape())
        self.grad_context.Exit()
    parallel_iterations = self.grad_context.parallel_iterations
    if parallel_iterations > 1:
        self.grad_sync._add_control_input(pop.op)
    return pop

Add the getter for an accumulated value in the grad context.

This is added to the backprop loop. Called in the grad context to
get the value of an accumulated value. The stack pop op must be guarded
by the pred of the controlling cond.

Args:
history_value: The history (a stack) of a value.
value: The value that is pushed onto the stack.
dead_branch: True iff the tensor is on a dead branch of a cond.

Returns:
The current value (the top of the stack).


def create(self, resource):
    return self.service.create(resource, self.url_prefix, self.auth, self.session, self.session_send_opts)

Create the given resource.

Args:
resource (intern.resource.boss.BossResource): Create a data model object with attributes matching those of the resource.

Returns:
(intern.resource.boss.BossResource): Returns resource of type requested on success.

Raises:
requests.HTTPError on failure.


def cancel(self, subscription_id, data={}, **kwargs):
    url = '{}/{}/cancel'.format(self.base_url, subscription_id)
    return self.post_url(url, data, **kwargs)

Cancel subscription given by subscription_id

Args:
subscription_id : Id for which subscription has to be cancelled

Returns:
Subscription Dict for given subscription id


def VerifyServerControlResponse(self, http_object):
    if (http_object.code != 200):
        return False
    try:
        (http_object.messages, http_object.source, http_object.nonce) = self.communicator.DecryptMessage(http_object.data)
        return True
    except communicator.DecodingError as e:
        logging.info('Protobuf decode error: %s.', e)
        return False

Verify the server response to a 'control' endpoint POST message.

We consider the message correct if and only if we can decrypt it
properly. Note that in practice we can not use the HTTP status to figure out
if the request worked because captive proxies have a habit of lying and
returning a HTTP success code even when there is no connectivity.

Args:
http_object: The HTTPObject returned from the HTTP transaction.

Returns:
True if the http_object is correct. False if it is not valid.

Side Effect:
Fill in the decoded_data attribute in the http_object.


def greedy_decode(logits_fn, initial_ids, temperature=0.0, initial_states=None, eos_id=EOS_ID, forced_ids=None, use_tpu=True):
    length_dim = initial_ids.shape.dims[(- 1)]
    mesh = initial_ids.mesh
    num_steps = mtf.constant(mesh, length_dim.size, dtype=tf.int32)

    def cond_fn(step_num, prev_ids, *unused_states):
        'Should we run another loop iteration.'
        overflow = mtf.equal(step_num, num_steps)
        has_eos = mtf.reduce_any(mtf.equal(prev_ids, eos_id), reduced_dim=length_dim)
        all_has_eos = mtf.reduce_all(has_eos)
        return mtf.logical_not(mtf.logical_or(overflow, all_has_eos))

    def body_fn(step_num, ids, *states):
        'Body function for greedy decoding.\n\n    Args:\n      step_num: a mtf.Tensor\n      ids: a mtf.Tensor\n      *states: additional mtf.Tensors\n    Returns:\n      new_step_num, new_ids, *new_states\n    '
        (logits, new_states) = logits_fn(step_num, ids, states)
        vocab_dim = logits.shape.dims[(- 1)]
        new_ids = mtf.sample_with_temperature(logits, vocab_dim, temperature)
        if (forced_ids is not None):
            forced = mtf.gather(forced_ids, step_num, length_dim)
            new_ids = (forced + (new_ids * mtf.to_int32(mtf.equal(forced, 0))))
        ids += (new_ids * mtf.one_hot(step_num, length_dim, dtype=tf.int32))
        new_step_num = (step_num + 1)
        return ([new_step_num, ids] + new_states)
    initial_step_num = mtf.constant(mesh, 0, dtype=tf.int32)
    while_loop_inputs = ([initial_step_num, initial_ids] + initial_states)
    (final_step_num, mtf_samples) = mtf.while_loop(cond_fn, body_fn, while_loop_inputs, num_loop_vars=(None if use_tpu else 2))[:2]
    mtf_samples = mtf.Print(mtf_samples, [final_step_num], 'output_length')
    return mtf_samples

Greedy decoding.

Args:
logits_fn: Interface to the model, to provide logits.
Shoud take:
step_num - mtf Scalar
ids - mtf Tensor with shape [..., length]
states - list of mtf.Tensor
Should return:
logits - [batch, vocab_size]
new_states - list of mtf.Tensor
initial_ids: mtf.Tensor with shape [..., length], containing zeros.
temperature: a float between 0.0 (argmax) and 1.0 (random)
initial_states: list of mtf.Tensor
eos_id: ID for end of sentence.
forced_ids: optional mtf.Tensor with shape [..., length]
use_tpu: a boolean
Returns:
Tensor with shape [..., length]


def createEmails(nicks=None, nicksFile=None):

    candidate_emails = set()
    if nicks != None:
        for n in nicks:
            for e in email_providers.domains:
                candidate_emails.add("{}@{}".format(n, e))
    elif nicksFile != None:
        with open(nicksFile, "r") as iF:
            nicks = iF.read().splitlines()
            for n in nicks:
                for e in email_providers.domains:
                    candidate_emails.add("{}@{}".format(n, e))
    return candidate_emails

Method that globally permits to generate the emails to be checked.

Args:
-----
nicks: List of aliases.
nicksFile: The filepath to the aliases file.

Returns:
--------
list: list of emails to be checked.


def share(self, name, item):

        try:

            if isinstance(item, s_telepath.Aware):
                item.onTeleShare(self, name)

            self.shared[name] = item

        except Exception:
            logger.exception(f'onTeleShare() error for: {name}')

Share an object via the telepath protocol.

Args:
name (str): Name of the shared object
item (object): The object to share over telepath.


def encoder(self, inputs, n_layers=3):

    latent_dims = self.hparams.z_dim

    shape_as_list = inputs.shape.as_list()
    if len(shape_as_list) != 5:
      raise ValueError("Expected inputs to be a 5-D, got %d" %
                       len(shape_as_list))
    if inputs.dtype != tf.float32:
      raise ValueError("Expected dtype tf.float32, got %s" % inputs.dtype)

    batch_size, _ = shape_as_list[:2]
    inputs = tf.reshape(inputs, [-1] + list(inputs.shape)[2:])
    n_filters = 64
    rectified = None

    padding = [[0, 0], [1, 1], [1, 1], [0, 0]]
    for i in range(n_layers):
      with tf.variable_scope("layer_%d" % (i + 1)):
        n_filters *= 2**i
        if i:
          padded = tf.pad(rectified, padding)
        else:
          padded = tf.pad(inputs, padding)
        convolved = tf.layers.conv2d(padded, filters=n_filters, kernel_size=4,
                                     strides=2, padding="VALID")
        normalized = tf.contrib.layers.instance_norm(convolved)
        rectified = tf.nn.leaky_relu(normalized, alpha=0.2)

    pooled = tf.nn.avg_pool(
        rectified, [1] + rectified.shape[1:3].as_list() + [1],
        strides=[1, 1, 1, 1], padding="VALID")
    squeezed = tf.squeeze(pooled, [1, 2])

    with tf.variable_scope("z_mu"):
      z_mu = tf.layers.dense(squeezed, latent_dims)
    with tf.variable_scope("z_log_sigma_sq"):
      z_log_var = tf.layers.dense(squeezed, latent_dims)
      z_log_var = tf.clip_by_value(z_log_var, -10, 10)

    z_mu = tf.reshape(z_mu, (batch_size, -1, latent_dims))
    z_log_var = tf.reshape(
        z_log_var, (batch_size, -1, latent_dims))
    return z_mu, z_log_var

Convnet that encodes inputs into mean and std of a gaussian.

Args:
inputs: 5-D Tensor, shape (batch_size, num_frames, width, height, channels)
n_layers: Number of layers.

Returns:
z_mu: Mean of the latent gaussians.
z_log_var: log(var) of the latent gaussians.

Raises:
ValueError: If inputs is not a 5-D tensor or not float32.


def pdb_downloader_and_metadata(self, outdir=None, pdb_file_type=None, force_rerun=False):

        if not pdb_file_type:
            pdb_file_type = self.pdb_file_type

        counter = 0
        for g in tqdm(self.genes):
            pdbs = g.protein.pdb_downloader_and_metadata(outdir=outdir, pdb_file_type=pdb_file_type, force_rerun=force_rerun)

            if pdbs:
                counter += len(pdbs)

        log.info('Updated PDB metadata dataframe. See the "df_pdb_metadata" attribute for a summary dataframe.')
        log.info('Saved {} structures total'.format(counter))

Download ALL mapped experimental structures to each protein's structures directory.

Args:
outdir (str): Path to output directory, if GEM-PRO directories were not set or other output directory is
desired
pdb_file_type (str): Type of PDB file to download, if not already set or other format is desired
force_rerun (bool): If files should be re-downloaded if they already exist


def StartsWith(self, value):

    self._awql = self._CreateSingleValueCondition(value, 'STARTS_WITH')
    return self._query_builder

Sets the type of the WHERE clause as "starts with".

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

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


def write_float(self, value, little_endian=True):

        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.pack('%sf' % endian, value)

Pack the value as a float and write 4 bytes to the stream.

Args:
value (number): the value to write to the stream.
little_endian (bool): specify the endianness. (Default) Little endian.

Returns:
int: the number of bytes written.


def get_params(img, output_size):

        w, h, *_ = img.shape

        th, tw = output_size
        if w == tw and h == th:
            return 0, 0, h, w

        i = random.randint(0, h - th)
        j = random.randint(0, w - tw)
        return i, j, th, tw

Get parameters for ``crop`` for a random crop.

Args:
img (PIL Image): Image to be cropped.
output_size (tuple): Expected output size of the crop.

Returns:
tuple: params (i, j, h, w) to be passed to ``crop`` for random crop.


def _GetInstanceConfig(self):
    try:
        instance_data = self.metadata_dict['instance']['attributes']
    except KeyError:
        instance_data = {}
        self.logger.warning('Instance attributes were not found.')
    try:
        project_data = self.metadata_dict['project']['attributes']
    except KeyError:
        project_data = {}
        self.logger.warning('Project attributes were not found.')
    return (instance_data.get('google-instance-configs') or project_data.get('google-instance-configs'))

Get the instance configuration specified in metadata.

Returns:
string, the instance configuration data.


def compute_output_shape(self, input_shape):
    if context.executing_eagerly():
        self._maybe_build(input_shape)
        with func_graph.FuncGraph(str(self.name) + '_scratch_graph').as_default():
            input_shape = tf_utils.convert_shapes(input_shape, to_tuples=False)

            def _make_placeholder_like(shape):
                ph = backend.placeholder(shape=shape, dtype=self.dtype)
                ph._keras_mask = None
                return ph
            inputs = nest.map_structure(_make_placeholder_like, input_shape)
            try:
                outputs = self(inputs, training=False)
            except TypeError as e:
                raise NotImplementedError("We could not automatically infer the static shape of the layer's output. Please implement the `compute_output_shape` method on your layer (%s)." % self.__class__.__name__) from e
        return nest.map_structure(lambda t: t.shape, outputs)
    raise NotImplementedError('Please run in eager mode or implement the `compute_output_shape` method on your layer (%s).' % self.__class__.__name__)

Computes the output shape of the layer.

If the layer has not been built, this method will call `build` on the
layer. This assumes that the layer will later be used with inputs that
match the input shape provided here.

Args:
input_shape: Shape tuple (tuple of integers)
or list of shape tuples (one per output tensor of the layer).
Shape tuples can include None for free dimensions,
instead of an integer.

Returns:
An input shape tuple.


def check_managed_pipeline(name='', app_name=''):

    *pipeline_name_prefix, bracket_region = name.split()
    region = bracket_region.strip('[]')

    not_managed_message = '"{0}" is not managed.'.format(name)

    if 'onetime' in region:
        LOG.info('"%s" is a onetime, marked for cleaning.', name)
        return region

    if not all([bracket_region.startswith('['), bracket_region.endswith(']')]):
        LOG.debug('"%s" does not end with "[region]".', name)
        raise ValueError(not_managed_message)

    if len(pipeline_name_prefix) is not 1:
        LOG.debug('"%s" does not only have one word before [region].', name)
        raise ValueError(not_managed_message)

    if app_name not in pipeline_name_prefix:
        LOG.debug('"%s" does not use "%s" before [region].', name, app_name)
        raise ValueError(not_managed_message)

    return region

Check a Pipeline name is a managed format **app_name [region]**.

Args:
name (str): Name of Pipeline to check.
app_name (str): Name of Application to find in Pipeline name.

Returns:
str: Region name from managed Pipeline name.

Raises:
ValueError: Pipeline is not managed.


def _create_inbound_stream(self, config=None):

        if config is None:
            raise ValueError('No stream config to create stream from.')

        name = self._get_stream_name(config)
        stream_handlers = self._get_stream_handlers(config, name)
        stream_input = config.get('input', None)
        if stream_input is None:
            raise(cfg.AitConfigMissing('inbound stream {}\'s input'.format(name)))

        if type(stream_input[0]) is int:
            return PortInputStream(name,
                                   stream_input,
                                   stream_handlers,
                                   zmq_args={'zmq_context': self.broker.context,
                                             'zmq_proxy_xsub_url': self.broker.XSUB_URL,
                                             'zmq_proxy_xpub_url': self.broker.XPUB_URL})
        else:
            return ZMQStream(name,
                             stream_input,
                             stream_handlers,
                             zmq_args={'zmq_context': self.broker.context,
                                       'zmq_proxy_xsub_url': self.broker.XSUB_URL,
                                       'zmq_proxy_xpub_url': self.broker.XPUB_URL})

Creates an inbound stream from its config.

Params:
config:       stream configuration as read by ait.config
Returns:
stream:       a Stream
Raises:
ValueError:   if any of the required config values are missing


def list_media_services_rg(access_token, subscription_id, rgname):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', rgname, '/providers/microsoft.media/mediaservices?api-version=', MEDIA_API])
    return do_get(endpoint, access_token)

List the media services 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.

Returns:
HTTP response. JSON body.


def create_media_assetfile(access_token, parent_asset_id, name, is_primary='false', is_encrypted='false', encryption_scheme='None', encryptionkey_id='None'):
    path = '/Files'
    endpoint = ''.join([ams_rest_endpoint, path])
    if (encryption_scheme == 'StorageEncryption'):
        body = (((((((((((((('{ \t\t\t"IsEncrypted": "' + is_encrypted) + '", \t\t\t"EncryptionScheme": "') + encryption_scheme) + '", \t\t\t"EncryptionVersion": "') + '1.0') + '", \t\t\t"EncryptionKeyId": "') + encryptionkey_id) + '", \t\t\t"IsPrimary": "') + is_primary) + '", \t\t\t"MimeType": "video/mp4", \t\t\t"Name": "') + name) + '", \t\t\t"ParentAssetId": "') + parent_asset_id) + '" \t\t}')
    else:
        body = (((((('{ \t\t\t"IsPrimary": "' + is_primary) + '", \t\t\t"MimeType": "video/mp4", \t\t\t"Name": "') + name) + '", \t\t\t"ParentAssetId": "') + parent_asset_id) + '" \t\t}')
    return do_ams_post(endpoint, path, body, access_token)

Create Media Service Asset File.

Args:
access_token (str): A valid Azure authentication token.
parent_asset_id (str): Media Service Parent Asset ID.
name (str): Media Service Asset Name.
is_primary (str): Media Service Primary Flag.
is_encrypted (str): Media Service Encryption Flag.
encryption_scheme (str): Media Service Encryption Scheme.
encryptionkey_id (str): Media Service Encryption Key ID.

Returns:
HTTP response. JSON body.


def update_dict_recursive(editable_dict: dict, editing_dict: dict) -> None:

    for k, v in editing_dict.items():
        if isinstance(v, collections.Mapping):
            update_dict_recursive(editable_dict.get(k, {}), v)
        else:
            editable_dict[k] = v

Updates dict recursively

You need to use this function to update dictionary if depth of editing_dict is more then 1

Args:
editable_dict: dictionary, that will be edited
editing_dict: dictionary, that contains edits
Returns:
None


def panel(self, panel_id):
    if (not isinstance(panel_id, ObjectId)):
        panel_id = ObjectId(panel_id)
    panel_obj = self.panel_collection.find_one({'_id': panel_id})
    return panel_obj

Fetch a gene panel by '_id'.

Args:
panel_id (str, ObjectId): str or ObjectId of document ObjectId

Returns:
dict: panel object or `None` if panel not found


def BuildFindSpecs(self, artifact_filter_names, environment_variables=None):

    find_specs = []
    for name in artifact_filter_names:
      definition = self._artifacts_registry.GetDefinitionByName(name)
      if not definition:
        logger.debug('undefined artifact definition: {0:s}'.format(name))
        continue

      logger.debug('building find spec from artifact definition: {0:s}'.format(
          name))
      artifact_find_specs = self._BuildFindSpecsFromArtifact(
          definition, environment_variables)
      find_specs.extend(artifact_find_specs)

    for find_spec in find_specs:
      if isinstance(find_spec, file_system_searcher.FindSpec):
        self.file_system_find_specs.append(find_spec)

      elif isinstance(find_spec, registry_searcher.FindSpec):
        self.registry_find_specs.append(find_spec)

      else:
        logger.warning('Unsupported find specification type: {0:s}'.format(
            type(find_spec)))

Builds find specifications from artifact definitions.

Args:
artifact_filter_names (list[str]): names of artifact definitions that are
used for filtering file system and Windows Registry key paths.
environment_variables (Optional[list[EnvironmentVariableArtifact]]):
environment variables.


def phase_uniquizer(all_phases):
    measurement_name_maker = UniqueNameMaker(itertools.chain.from_iterable((phase.measurements.keys() for phase in all_phases if phase.measurements)))
    attachment_names = list(itertools.chain.from_iterable((phase.attachments.keys() for phase in all_phases)))
    attachment_names.extend(itertools.chain.from_iterable(([('multidim_' + name) for (name, meas) in phase.measurements.items() if (meas.dimensions is not None)] for phase in all_phases if phase.measurements)))
    attachment_name_maker = UniqueNameMaker(attachment_names)
    for phase in all_phases:
        for (name, _) in sorted(phase.measurements.items()):
            old_name = name
            name = measurement_name_maker.make_unique(name)
            phase.measurements[old_name].name = name
            phase.measurements[name] = phase.measurements.pop(old_name)
        for (name, _) in sorted(phase.attachments.items()):
            old_name = name
            name = attachment_name_maker.make_unique(name)
            phase.attachments[old_name].name = name
            phase.attachments[name] = phase.attachments.pop(old_name)
    return all_phases

Makes the names of phase measurement and attachments unique.

This function will make the names of measurements and attachments unique.
It modifies the input all_phases.

Args:
all_phases: the phases to make unique

Returns:
the phases now modified.


def install_js():
    target_jsdir = join(SERVER, 'static', 'js')
    target_cssdir = join(SERVER, 'static', 'css')
    target_tslibdir = join(SERVER, 'static', 'lib')
    STATIC_ASSETS = [join(JS, 'bokeh.js'), join(JS, 'bokeh.min.js'), join(CSS, 'bokeh.css'), join(CSS, 'bokeh.min.css')]
    if (not all((exists(a) for a in STATIC_ASSETS))):
        print(BOKEHJS_INSTALL_FAIL)
        sys.exit(1)
    if exists(target_jsdir):
        shutil.rmtree(target_jsdir)
    shutil.copytree(JS, target_jsdir)
    if exists(target_cssdir):
        shutil.rmtree(target_cssdir)
    shutil.copytree(CSS, target_cssdir)
    if exists(target_tslibdir):
        shutil.rmtree(target_tslibdir)
    if exists(TSLIB):
        lib = {'lib.es5.d.ts', 'lib.dom.d.ts', 'lib.es2015.core.d.ts', 'lib.es2015.promise.d.ts', 'lib.es2015.symbol.d.ts', 'lib.es2015.iterable.d.ts'}
        shutil.copytree(TSLIB, target_tslibdir, ignore=(lambda _, files: [f for f in files if (f not in lib)]))

Copy built BokehJS files into the Python source tree.

Returns:
None


def __init__(self, **kwargs):

        self.unitname = kwargs.get('unitname', self.unitname)
        self.unitmultiplier = kwargs.get('unitmultiplier', self.unitmultiplier)

Distance unit parameter.

Args:

- **unitname**: A pycrs.elements.units.UnitName instance with the name given by each supported format.
- **unitmultiplier**: A pycrs.elements.units.UnitMultiplier instance.


def set_lock_state(self, code, device_label, state):

        response = None
        try:
            response = requests.put(
                urls.set_lockstate(self._giid, device_label, state),
                headers={
                    'Accept': 'application/json, text/javascript, */*; q=0.01',
                    'Content-Type': 'application/json',
                    'Cookie': 'vid={}'.format(self._vid)},
                data=json.dumps({"code": str(code)}))
        except requests.exceptions.RequestException as ex:
            raise RequestError(ex)
        _validate_response(response)
        return json.loads(response.text)

Lock or unlock

Args:
code (str): Lock code
device_label (str): device label of lock
state (str): 'lock' or 'unlock'


def print_layer_summary(layer):
    try:
        output_shape = layer.output_shape
    except AttributeError:
        output_shape = 'multiple'
    except RuntimeError:
        output_shape = '?'
    name = layer.name
    cls_name = layer.__class__.__name__
    if not layer.built and (not getattr(layer, '_is_graph_network', False)):
        params = '0 (unused)'
    else:
        params = layer.count_params()
    fields = [name + ' (' + cls_name + ')', output_shape, params]
    print_row(fields, positions)

Prints a summary for a single layer.

Args:
layer: target layer.