def get_sns_topic_arn(topic_name, account, region):

    if topic_name.count(':') == 5 and topic_name.startswith('arn:aws:sns:'):
        return topic_name
    session = boto3.Session(profile_name=account, region_name=region)
    sns_client = session.client('sns')

    topics = sns_client.list_topics()['Topics']

    matched_topic = None
    for topic in topics:
        topic_arn = topic['TopicArn']
        if topic_name == topic_arn.split(':')[-1]:
            matched_topic = topic_arn
            break
    else:
        LOG.critical("No topic with name %s found.", topic_name)
        raise SNSTopicNotFound('No topic with name {0} found'.format(topic_name))
    return matched_topic

Get SNS topic ARN.

Args:
topic_name (str): Name of the topic to lookup.
account (str): Environment, e.g. dev
region (str): Region name, e.g. us-east-1

Returns:
str: ARN for requested topic name


def start_listing(self, request: Request) -> ListingResponse:

        if self._session_state != SessionState.ready:
            raise RuntimeError('Session not ready')

        response = ListingResponse()

        yield from self._prepare_fetch(request, response)
        yield from self._open_data_stream()

        mlsd_command = Command('MLSD', self._request.file_path)
        list_command = Command('LIST', self._request.file_path)

        try:
            yield from self._begin_stream(mlsd_command)
            self._listing_type = 'mlsd'
        except FTPServerError as error:
            if error.reply_code in (ReplyCodes.syntax_error_command_unrecognized,
                                    ReplyCodes.command_not_implemented):
                self._listing_type = None
            else:
                raise

        if not self._listing_type:

            yield from self._begin_stream(list_command)
            self._listing_type = 'list'

        _logger.debug('Listing type is %s', self._listing_type)

        self._session_state = SessionState.directory_request_sent

        return response

Fetch a file listing.

Args:
request: Request.

Returns:
A listing response populated with the initial data connection
reply.

Once the response is received, call :meth:`download_listing`.

Coroutine.


def __init__(
      self, script_type, default_shell=None, run_dir=None, debug=False):

    self.script_type = script_type
    self.default_shell = default_shell
    name = '%s-script' % self.script_type
    facility = logging.handlers.SysLogHandler.LOG_DAEMON
    self.logger = logger.Logger(name=name, debug=debug, facility=facility)
    self.retriever = script_retriever.ScriptRetriever(self.logger, script_type)
    self.executor = script_executor.ScriptExecutor(
        self.logger, script_type, default_shell=default_shell)
    self._RunScripts(run_dir=run_dir)

Constructor.

Args:
script_type: string, the metadata script type to run.
default_shell: string, the default shell to execute the script.
run_dir: string, the base directory location of the temporary directory.
debug: bool, True if debug output should write to the console.


def preprocess_frame(frame):

  frame = common_layers.convert_rgb_to_real(frame)
  frame = frame - 0.5
  frame, _ = glow_ops.uniform_binning_correction(frame)
  return frame

Preprocess frame.

1. Converts [0, 255] to [-0.5, 0.5]
2. Adds uniform noise.

Args:
frame: 3-D Tensor representing pixels.
Returns:
frame: 3-D Tensor with values in between [-0.5, 0.5]


def match_date(date):
    date_pattern = re.compile('^(19|20)\\d\\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])')
    if re.match(date_pattern, date):
        return True
    return False

Check if a string is a valid date

Args:
date(str)

Returns:
bool


def get_tri_area(pts):
    (a, b, c) = (pts[0], pts[1], pts[2])
    v1 = (np.array(b) - np.array(a))
    v2 = (np.array(c) - np.array(a))
    area_tri = abs((sp.linalg.norm(sp.cross(v1, v2)) / 2))
    return area_tri

Given a list of coords for 3 points,
Compute the area of this triangle.

Args:
pts: [a, b, c] three points


def element_spec(self):
    raise NotImplementedError('Optional.element_spec')

The type specification of an element of this optional.

>>> optional = tf.experimental.Optional.from_value(42)
>>> print(optional.element_spec)
tf.TensorSpec(shape=(), dtype=tf.int32, name=None)

Returns:
A (nested) structure of `tf.TypeSpec` objects matching the structure of an
element of this optional, specifying the type of individual components.


def to_json(self, **kwargs) -> JSONValueType:

Returns a plain Python value as a representation for this object.

A plain Python value are basic python types that can be serialized into
JSON, e.g: ``bool``, ``int``, ``float``, ``str``, ``dict`` (with string
keys), ``list``, ``tuple`` where the container types should have plain
Python values as their values.

Args:
**kwargs: Keyword arguments as flags to control JSON conversion.

Returns:
A plain Python value.


def create_lease_object_from_subnet(self, subnet):

        if '/' not in subnet:
            subnet = '{}/{}'.format(subnet, self._cidr)

        try:
            if not self.is_leasable_subnet(subnet):
                raise LagoSubnetLeaseOutOfRangeException(
                    subnet, self.get_allowed_range()
                )
        except AddrFormatError:
            raise LagoSubnetLeaseMalformedAddrException(subnet)

        return Lease(store_path=self.path, subnet=subnet)

Create a lease from ip in a dotted decimal format,
(for example `192.168.200.0/24`). the _cidr will be added if not exist
in `subnet`.

Args:
subnet (str): The value of the third octet

Returns:
Lease: Lease object which represents the requested subnet.

Raises:
LagoSubnetLeaseOutOfRangeException: If the resultant subnet is
malformed or out of the range of the store.


def absl_to_standard(level):

  if not isinstance(level, int):
    raise TypeError('Expect an int level, found {}'.format(type(level)))
  if level < ABSL_FATAL:
    level = ABSL_FATAL
  if level <= ABSL_DEBUG:
    return ABSL_TO_STANDARD[level]

  return STANDARD_DEBUG - level + 1

Converts an integer level from the absl value to the standard value.

Args:
level: int, an absl.logging level.

Raises:
TypeError: Raised when level is not an integer.

Returns:
The corresponding integer level for use in standard logging.


def round_model(model: typing.Dict[str, typing.Dict[str, float]], scale: int) -> typing.Dict[str, typing.Dict[str, int]]:
    model_rounded: typing.Dict[str, typing.Dict[str, int]] = dict()
    for feature_group, features in model.items():
        for feature_content, score in features.items():
            scaled_score = int(score * scale)
            if abs(scaled_score) > 0:
                model_rounded.setdefault(feature_group, {})
                model_rounded[feature_group][feature_content] = scaled_score
    return model_rounded

Rounds the scores in the model to integer after scaling.

Args:
model (Dict[str, Dict[str, float]]): The model to round scores.
scale (int, optional): A scale factor to multiply scores.

Returns:
model_rounded (Dict[str, Dict[str, int]]) The rounded model.


def ed25519_public_key_to_string(key):

    return base64.b64encode(key.public_bytes(
        encoding=serialization.Encoding.Raw,
        format=serialization.PublicFormat.Raw,
    ), None).decode('utf-8')

Convert an ed25519 public key to a base64-encoded string.

Args:
key (Ed25519PublicKey): the key to write to the file.

Returns:
str: the key representation as a str


def variables_accessed(variables):
    accessed = []
    for variable in variables:
        if variable.trainable:
            accessed.extend(_variables_override(variable))
    for var in accessed:
        pywrap_tfe.TFE_Py_TapeVariableAccessed(var)
        pywrap_tfe.TFE_Py_VariableWatcherVariableAccessed(var)

Notifies all tapes in the stack that variables have been accessed.

Only trainable variables are marked as accessed.

Args:
variables: iterable of variables to mark as accessed.


def get_speaker_info(self, refresh=False, timeout=None):

        if self.speaker_info and refresh is False:
            return self.speaker_info
        else:
            response = requests.get('http:
                                    ':1400/xml/device_description.xml',
                                    timeout=timeout)
            dom = XML.fromstring(response.content)

        device = dom.find('{urn:schemas-upnp-org:device-1-0}device')
        if device is not None:
            self.speaker_info['zone_name'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}roomName')

            self.speaker_info['player_icon'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}iconList/'
                '{urn:schemas-upnp-org:device-1-0}icon/'
                '{urn:schemas-upnp-org:device-1-0}url'
            )

            self.speaker_info['uid'] = self.uid
            self.speaker_info['serial_number'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}serialNum')
            self.speaker_info['software_version'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}softwareVersion')
            self.speaker_info['hardware_version'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}hardwareVersion')
            self.speaker_info['model_number'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}modelNumber')
            self.speaker_info['model_name'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}modelName')
            self.speaker_info['display_version'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}displayVersion')

            mac = self.speaker_info['serial_number'].split(':')[0]
            self.speaker_info['mac_address'] = mac

            return self.speaker_info
        return None

Get information about the Sonos speaker.

Arguments:
refresh(bool): Refresh the speaker info cache.
timeout: How long to wait for the server to send
data before giving up, as a float, or a
`(connect timeout, read timeout)` tuple
e.g. (3, 5). Default is no timeout.

Returns:
dict: Information about the Sonos speaker, such as the UID,
MAC Address, and Zone Name.


def _construct_key(self, rule_id: str, spacy_rule_id:int) -> int:

        hash_key = (rule_id, spacy_rule_id)
        hash_v = hash(hash_key) + sys.maxsize + 1
        self._hash_map[hash_v] = hash_key
        return hash_v

Use a mapping to store the information about rule_id for each matches, create the mapping key here
Args:
rule_id: str
spacy_rule_id:int

Returns: int


def update_in_hdx(self):
    capacity = self.data.get('capacity')
    if (capacity is not None):
        del self.data['capacity']
    self._update_in_hdx('user', 'id')
    if (capacity is not None):
        self.data['capacity'] = capacity

Check if user exists in HDX and if so, update user

Returns:
None


def Scan(self, scan_context, auto_recurse=True, scan_path_spec=None):
    if (not scan_context):
        raise ValueError('Invalid scan context.')
    scan_context.updated = False
    if scan_path_spec:
        scan_node = scan_context.GetScanNode(scan_path_spec)
    else:
        scan_node = scan_context.GetUnscannedScanNode()
    if scan_node:
        self._ScanNode(scan_context, scan_node, auto_recurse=auto_recurse)

Scans for supported formats.

Args:
scan_context (SourceScannerContext): source scanner context.
auto_recurse (Optional[bool]): True if the scan should automatically
recurse as far as possible.
scan_path_spec (Optional[PathSpec]): path specification to indicate
where the source scanner should continue scanning, where None
indicates the scanner will start with the sources.

Raises:
ValueError: if the scan context is invalid.


def _get_backend(filename):
    filename = os.path.abspath(filename)
    with _backends_lock:
        if (filename not in _backends):
            _backends[filename] = _MultiprocessStorageBackend(filename)
        return _backends[filename]

A helper method to get or create a backend with thread locking.

This ensures that only one backend is used per-file per-process, so that
thread and process locks are appropriately shared.

Args:
filename: The full path to the credential storage file.

Returns:
An instance of :class:`_MultiprocessStorageBackend`.


def all_near_zero(a: Union[(float, complex, Iterable[float], np.ndarray)], *, atol: float=1e-08) -> bool:
    return np.all(np.less_equal(np.abs(a), atol))

Checks if the tensor's elements are all near zero.

Args:
a: Tensor of elements that could all be near zero.
atol: Absolute tolerance.


def GetSources(self, event):

    if self.DATA_TYPE != event.data_type:
      raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
          event.data_type))

    source_long = getattr(event, 'source_long', 'UNKNOWN')
    source_append = getattr(event, 'source_append', None)
    if source_append:
      source_long = '{0:s} {1:s}'.format(source_long, source_append)

    return self.SOURCE_SHORT, source_long

Determines the the short and long source for an event object.

Args:
event (EventObject): event.

Returns:
tuple(str, str): short and long source string.

Raises:
WrongFormatter: if the event object cannot be formatted by the formatter.


def index(cls):
    res = requests.get(cls.URL, headers=HEADERS, verify=False)
    res.raise_for_status()
    return res.json()

Fetches all records.

Returns:
`dict`. The JSON formatted response.

Raises:
`requests.exceptions.HTTPError`: The status code is not ok.


def fast_cond_v2(pred, true_fn, false_fn, name=None):
    if isinstance(pred, bool):
        raise TypeError('pred must not be a Python bool', pred)
    if not name:
        name = 'fast_cond'
    with ops.name_scope(name) as scope:
        true_name = util.unique_fn_name(scope, 'true')
        false_name = util.unique_fn_name(scope, 'false')
        pred = _normalize_pred(pred)
        true_graph = func_graph_module.func_graph_from_py_func(true_name, true_fn, [], {}, func_graph=util.CondBranchFuncGraph(true_name, collections=ops.get_default_graph()._collections), add_control_dependencies=False, op_return_value=pred)
        false_graph = func_graph_module.func_graph_from_py_func(false_name, false_fn, [], {}, func_graph=util.CondBranchFuncGraph(false_name, collections=ops.get_default_graph()._collections), add_control_dependencies=False, op_return_value=pred)
        verify_captures(_COND, [true_graph, false_graph])
        return _build_cond(pred, true_graph, false_graph, true_graph.external_captures, false_graph.external_captures, building_gradient=False, add_identities=False, prevent_lowering=True, name=scope)

Like cond_v2, except emits an If op and applies various optimizations.

This function is intended to be used for cases where the cond is used to
implement a simple conditional control flow operator. It makes the following
assumptions:

1. The conditional is never differentiated.
2. The caller does not rely on V1 control flow semantics, i.e. for cross
device execution, pruning subgraphs of the true or false branches, or
non-strict evaluation order.
3. The caller manually configures any control dependencies within the graphs.

In this case, the cond will be lowered to a single If (or StatelessIf) op and
the true and false graphs will be executed as TF functions.

Args:
pred: boolean Tensor
true_fn: function to execute if pred is true
false_fn: function to execute if pred is false
name: the name for the If op.

Returns:
A list of Tensors which are the outputs of the If op. Does not include
intermediate outputs.


def _list_node_attributes(self, node_name):
    lines = []
    lines.append('')
    lines.append('Node attributes:')
    attrs = self._debug_dump.node_attributes(node_name)
    for attr_key in attrs:
        lines.append('  %s:' % attr_key)
        attr_val_str = repr(attrs[attr_key]).strip().replace('\n', ' ')
        lines.append('    %s' % attr_val_str)
        lines.append('')
    return debugger_cli_common.RichTextLines(lines)

List neighbors (inputs or recipients) of a node.

Args:
node_name: Name of the node of which the attributes are to be listed.

Returns:
A RichTextLines object.


def all_reduce_indexed_slices(self, input_slices: indexed_slices.IndexedSlices, options: Optional[collective_util.Options]=None) -> indexed_slices.IndexedSlices:
    options = self._options.merge(options)
    with ops.device(self._device):

        def all_gather_indexed_slices(all_gather_fn: Callable[[core.TensorLike, Optional[collective_util.Options]], core.Tensor]) -> indexed_slices.IndexedSlices:

            all_values = all_gather_fn(input_slices.values, options)
            if options.implementation == collective_util.CommunicationImplementation.NCCL:
                control = [all_values]
            else:
                control = []
            with ops.control_dependencies(control):
                all_indices = all_gather_fn(input_slices.indices, options)
            return indexed_slices.IndexedSlices(values=all_values, indices=all_indices, dense_shape=input_slices.dense_shape)
        length = array_ops.shape(input_slices.indices)
        all_lengths = self._all_gather(length, options)

        def all_gather_with_padding(input_tensor: core.TensorLike, options: Optional[collective_util.Options]) -> core.Tensor:

            max_length = math_ops.reduce_max(all_lengths)
            padded_tensor = _pad_util(input_tensor, max_length)
            all_padded_tensors = self._all_gather(padded_tensor, options)
            split_tensors = []
            for i in range(self._group_size):
                start_pos = i * max_length
                split_tensors.append(all_padded_tensors[start_pos:start_pos + all_lengths[i]])
            return array_ops.concat(split_tensors, 0)
        return cond.cond(math_ops.equal(math_ops.reduce_max(all_lengths), math_ops.reduce_min(all_lengths)), lambda: all_gather_indexed_slices(self._all_gather), lambda: all_gather_indexed_slices(all_gather_with_padding))

All-reduce an IndexedSlices.

This method can be called outside  tf.function.

Args:
input_slices: an IndexedSlices.
options: an optional tf.distribute.experimental.CommunicationOptions. If
provided, it overrides the default options.

Returns:
The reduced IndexedSlices.


def create_heroku_connect_schema(using=DEFAULT_DB_ALIAS):

    connection = connections[using]

    with connection.cursor() as cursor:
        cursor.execute(_SCHEMA_EXISTS_QUERY, [settings.HEROKU_CONNECT_SCHEMA])
        schema_exists = cursor.fetchone()[0]
        if schema_exists:
            return False

        cursor.execute("CREATE SCHEMA %s;", [AsIs(settings.HEROKU_CONNECT_SCHEMA)])

    with connection.schema_editor() as editor:
        for model in get_heroku_connect_models():
            editor.create_model(model)

        editor.execute('CREATE EXTENSION IF NOT EXISTS "hstore";')

        from heroku_connect.models import (TriggerLog, TriggerLogArchive)
        for cls in [TriggerLog, TriggerLogArchive]:
            editor.create_model(cls)
    return True

Create Heroku Connect schema.

Note:
This function is only meant to be used for local development.
In a production environment the schema will be created by
Heroku Connect.

Args:
using (str): Alias for database connection.

Returns:
bool: ``True`` if the schema was created, ``False`` if the
schema already exists.


def set_pattern_step_setpoint(self, patternnumber, stepnumber, setpointvalue):
    _checkPatternNumber(patternnumber)
    _checkStepNumber(stepnumber)
    _checkSetpointValue(setpointvalue, self.setpoint_max)
    address = _calculateRegisterAddress('setpoint', patternnumber, stepnumber)
    self.write_register(address, setpointvalue, 1)

Set the setpoint value for a step.

Args:
* patternnumber (integer): 0-7
* stepnumber (integer): 0-7
* setpointvalue (float): Setpoint value


def _use_memcache(self, key, options=None):
    flag = ContextOptions.use_memcache(options)
    if (flag is None):
        flag = self._memcache_policy(key)
    if (flag is None):
        flag = ContextOptions.use_memcache(self._conn.config)
    if (flag is None):
        flag = True
    return flag

Return whether to use memcache for this key.

Args:
key: Key instance.
options: ContextOptions instance, or None.

Returns:
True if the key should be cached in memcache, False otherwise.


def writeline(self, line=b'', sep=b'\n', echo=None):
    self.writelines([line], sep, echo)

Write a byte sequences to the channel and terminate it with carriage
return and line feed.

Args:
line(bytes): The line to send.
sep(bytes): The separator to use after each line.
echo(bool): Whether to echo the written data to stdout.

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


def transformers_to_megatron_fix_query_key_value_ordering(param, checkpoint_version, num_splits, num_heads, hidden_size):
    input_shape = param.size()
    if checkpoint_version == 1.0:
        current_shape = (num_splits, num_heads, hidden_size) + input_shape[1:]
        param = param.view(*current_shape)
        param = param.transpose(0, 2)
        param = param.transpose(1, 2).contiguous()
    elif checkpoint_version >= 2.0:
        current_shape = (num_splits, num_heads, hidden_size) + input_shape[1:]
        param = param.view(*current_shape)
        param = param.transpose(0, 1).contiguous()
    param = param.view(*input_shape)
    return param

Permutes layout of param tensor to the one compatible with respective NVIDIA Megatron-LM checkpoint versions. Input
is [num_splits * num_heads * hidden_size, :] and output is [num_heads * hidden_size * num_splits, :] for version
1.0 and [num_heads * num_splits * hidden_size, :] for version 2.0 and later. If param is the weight tensor of the
self-attention block, the param needs to be already transposed before calling this function.

Args:
param (torch.Tensor): the tensor to permute
checkpoint_version (int): the version of the checkpoint.
num_splits (int): the number of projections, usually 3 for (Query, Key, Value)
num_heads (int): the number of attention heads
hidden_size (int): the hidden size per head


def post_async(self, path, params=None):

        request = Post(self._get_next_id(), path, params)
        request.set_callback(self._q.put)
        future = self._dispatch_request(request)
        return future

Asynchronously calls a function on a child block

Args:
path (list): The path to post to
params (dict): parameters for the call

Returns:
Future: as single Future that will resolve to the result


def ParseFromUnicode(self, value):

    precondition.AssertType(value, Text)
    value = value.strip()

    super(ClientURN, self).ParseFromUnicode(value)

    match = self.CLIENT_ID_RE.match(self._string_urn)
    if not match:
      raise type_info.TypeValueError("Client urn malformed: %s" % value)

    clientid = match.group("clientid")
    clientid_correctcase = "".join((clientid[0].upper(), clientid[1:].lower()))

    self._string_urn = self._string_urn.replace(clientid, clientid_correctcase,
                                                1)

Parse a string into a client URN.

Convert case so that all URNs are of the form C.[0-9a-f].

Args:
value: string value to parse


def _parse_string(self, xml):

        if not isinstance(xml, HTMLElement):
            xml = dhtmlparser.parseString(str(xml))

        record = xml.find("record")
        if not record:
            raise ValueError("There is no <record> in your MARC XML document!")
        record = record[0]

        self.oai_marc = len(record.find("oai_marc")) > 0

        if not self.oai_marc:
            leader = record.find("leader")
            if len(leader) >= 1:
                self.leader = leader[0].getContent()

        if self.oai_marc:
            self._parse_control_fields(record.find("fixfield"), "id")
            self._parse_data_fields(record.find("varfield"), "id", "label")
        else:
            self._parse_control_fields(record.find("controlfield"), "tag")
            self._parse_data_fields(record.find("datafield"), "tag", "code")

        if self.oai_marc and "LDR" in self.controlfields:
            self.leader = self.controlfields["LDR"]

Parse MARC XML document to dicts, which are contained in
self.controlfields and self.datafields.

Args:
xml (str or HTMLElement): input data

Also detect if this is oai marc format or not (see elf.oai_marc).


def GetDecoder(cls, encoding_method):
    encoding_method = encoding_method.lower()
    decoder = cls._decoders.get(encoding_method, None)
    if (not decoder):
        return None
    return decoder()

Retrieves the decoder object for a specific encoding method.

Args:
encoding_method (str): encoding method identifier.

Returns:
Decoder: decoder or None if the encoding method does not exists.


def __init__(self, timeseries, loop=None):

        self.timeseries = timeseries
        self.queue = deque()
        self.continuation_url = timeseries._base_url

Construct an iterator.

Args:
timeseries: the timeseries to iterate over

loop: The asyncio loop to use for iterating


def singleOrPair(obj):
    if (len(list(obj.__class__.__mro__)) <= 2):
        return 'Neither'
    elif (ancestorJr(obj) is Pair):
        return 'Pair'
    elif (ancestor(obj) is Single):
        return 'Single'
    else:
        return 'Neither'

Chech an object is single or pair or neither.

Of course,, all pairs are single, so what the function is really detecting is whether an object is only single or at the same time a pair.

Args:
obj (object): Literally anything.

Returns:
str: 'Single', or 'Pair', or 'Neither'


def _GetAccessToken(self):
    d = {'assertion': self._GenerateAssertion(), 'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer'}
    try:
        body = parse.urlencode(d)
    except AttributeError:
        body = urllib.urlencode(d)
    req = urllib_request.Request(RpcHelper.TOKEN_ENDPOINT)
    req.add_header('Content-type', 'application/x-www-form-urlencoded')
    binary_body = body.encode('utf-8')
    raw_response = urllib_request.urlopen(req, binary_body)
    return simplejson.loads(raw_response.read())['access_token']

Gets oauth2 access token for Gitkit API using service account.

Returns:
string, oauth2 access token.


def __convertChannelMask(self, channelsArray):
    maskSet = 0
    for eachChannel in channelsArray:
        mask = (1 << eachChannel)
        maskSet = (maskSet | mask)
    return maskSet

convert channelsArray to bitmask format

Args:
channelsArray: channel array (i.e. [21, 22])

Returns:
bitmask format corresponding to a given channel array


async def register_service(self, short_name, long_name, allow_duplicate=True):

        try:
            await self.send_command(OPERATIONS.CMD_REGISTER_SERVICE, dict(name=short_name, long_name=long_name),
                                    MESSAGES.RegisterServiceResponse)
        except ArgumentError:
            if not allow_duplicate:
                raise

Register a new service with the service manager.

Args:
short_name (string): A unique short name for this service that functions
as an id
long_name (string): A user facing name for this service
allow_duplicate (boolean): Don't throw an error if this service is already
registered.  This is important if the service is preregistered for example.
Raises:
ArgumentError: if the short_name is already taken


def _postprocess_for_mg(rle_masks, iou_scores, mask_boxes, amg_crops_nms_thresh=0.7):
    keep_by_nms = batched_nms(boxes=mask_boxes.float(), scores=iou_scores, idxs=torch.zeros(mask_boxes.shape[0]), iou_threshold=amg_crops_nms_thresh)
    iou_scores = iou_scores[keep_by_nms]
    rle_masks = [rle_masks[i] for i in keep_by_nms]
    mask_boxes = mask_boxes[keep_by_nms]
    masks = [_rle_to_mask(rle) for rle in rle_masks]
    return (masks, iou_scores, rle_masks, mask_boxes)

Perform NMS (Non Maximum Suppression) on the outputs.

Args:
rle_masks (`torch.Tensor`):
binary masks in the RLE format
iou_scores (`torch.Tensor` of shape (nb_masks, 1)):
iou_scores predicted by the model
mask_boxes (`torch.Tensor`):
The bounding boxes corresponding to segmentation masks
amg_crops_nms_thresh (`float`, *optional*, defaults to 0.7):
NMS threshold.


def check(self, instance, format):

        if format not in self.checkers:
            return

        func, raises = self.checkers[format]
        result, cause = None, None
        try:
            result = func(instance)
        except raises as e:
            cause = e
        if not result:
            raise FormatError(
                "%r is not a %r" % (instance, format), cause=cause,
            )

Check whether the instance conforms to the given format.

Arguments:

instance (*any primitive type*, i.e. str, number, bool):

The instance to check

format (str):

The format that instance should conform to

Raises:

FormatError: if the instance does not conform to ``format``


def starting_wall_time(self):
    return self._reader.starting_wall_time()

Wall timestamp for when the debugged TensorFlow program started.

Returns:
Stating wall time as seconds since the epoch, as a `float`.


def ParseBookmarkRow(self, parser_mediator, query, row, **unused_kwargs):
    query_hash = hash(query)
    rev_host = self._GetRowValue(query_hash, row, 'rev_host')
    bookmark_type = self._GetRowValue(query_hash, row, 'type')
    event_data = FirefoxPlacesBookmarkEventData()
    event_data.host = (rev_host or 'N/A')
    event_data.offset = self._GetRowValue(query_hash, row, 'id')
    event_data.places_title = self._GetRowValue(query_hash, row, 'places_title')
    event_data.query = query
    event_data.title = self._GetRowValue(query_hash, row, 'bookmark_title')
    event_data.type = self._BOOKMARK_TYPES.get(bookmark_type, 'N/A')
    event_data.url = self._GetRowValue(query_hash, row, 'url')
    event_data.visit_count = self._GetRowValue(query_hash, row, 'visit_count')
    timestamp = self._GetRowValue(query_hash, row, 'dateAdded')
    if timestamp:
        date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(timestamp=timestamp)
        event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_ADDED)
        parser_mediator.ProduceEventWithEventData(event, event_data)
    timestamp = self._GetRowValue(query_hash, row, 'lastModified')
    if timestamp:
        date_time = dfdatetime_posix_time.PosixTimeInMicroseconds(timestamp=timestamp)
        event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_MODIFICATION)
        parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a bookmark row.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row.


def section(self, section):

        if not isinstance(self._container, ConfigUpdater):
            raise ValueError("Sections can only be added at section level!")
        if isinstance(section, str):

            section = Section(section, container=self._container)
        elif not isinstance(section, Section):
            raise ValueError("Parameter must be a string or Section type!")
        if section.name in [block.name for block in self._container
                            if isinstance(block, Section)]:
            raise DuplicateSectionError(section.name)
        self._container.structure.insert(self._idx, section)
        self._idx += 1
        return self

Creates a section block

Args:
section (str or :class:`Section`): name of section or object

Returns:
self for chaining


def do_block(args):
    rest_client = RestClient(args.url, args.user)
    if (args.subcommand == 'list'):
        block_generator = rest_client.list_blocks()
        blocks = []
        left = args.count
        for block in block_generator:
            blocks.append(block)
            left -= 1
            if (left <= 0):
                break
        keys = ('num', 'block_id', 'batches', 'txns', 'signer')
        headers = tuple(((k.upper() if (k != 'batches') else 'BATS') for k in keys))

        def parse_block_row(block):
            batches = block.get('batches', [])
            txns = [t for b in batches for t in b['transactions']]
            return (block['header'].get('block_num', 0), block['header_signature'], len(batches), len(txns), block['header']['signer_public_key'])
        if (args.format == 'default'):
            fmt.print_terminal_table(headers, blocks, parse_block_row)
        elif (args.format == 'csv'):
            fmt.print_csv(headers, blocks, parse_block_row)
        elif ((args.format == 'json') or (args.format == 'yaml')):
            data = [{k: d for (k, d) in zip(keys, parse_block_row(b))} for b in blocks]
            if (args.format == 'yaml'):
                fmt.print_yaml(data)
            elif (args.format == 'json'):
                fmt.print_json(data)
            else:
                raise AssertionError('Missing handler: {}'.format(args.format))
        else:
            raise AssertionError('Missing handler: {}'.format(args.format))
    if (args.subcommand == 'show'):
        output = rest_client.get_block(args.block_id)
        if args.key:
            if (args.key in output):
                output = output[args.key]
            elif (args.key in output['header']):
                output = output['header'][args.key]
            else:
                raise CliException('key "{}" not found in block or header'.format(args.key))
        if (args.format == 'yaml'):
            fmt.print_yaml(output)
        elif (args.format == 'json'):
            fmt.print_json(output)
        else:
            raise AssertionError('Missing handler: {}'.format(args.format))

Runs the block list or block show command, printing output to the
console

Args:
args: The parsed arguments sent to the command at runtime


def construct(cls, name, version=None):

        other = VersionedObject(None)
        other.name_ = name
        other.version_ = Version() if version is None else version
        return other

Create a VersionedObject directly from an object name and version.

Args:
name: Object name string.
version: Version object.


def authenticate(self, connection_certificate=None, connection_info=None, request_credentials=None):
    if ((self.users_url is None) or (self.groups_url is None)):
        raise exceptions.ConfigurationError('The SLUGS URL must be specified.')
    user_id = utils.get_client_identity_from_certificate(connection_certificate)
    try:
        response = requests.get(self.users_url.format(user_id))
    except Exception:
        raise exceptions.ConfigurationError('A connection could not be established using the SLUGS URL.')
    if (response.status_code == 404):
        raise exceptions.PermissionDenied('Unrecognized user ID: {}'.format(user_id))
    response = requests.get(self.groups_url.format(user_id))
    if (response.status_code == 404):
        raise exceptions.PermissionDenied('Group information could not be retrieved for user ID: {}'.format(user_id))
    return (user_id, response.json().get('groups'))

Query the configured SLUGS service with the provided credentials.

Args:
connection_certificate (cryptography.x509.Certificate): An X.509
certificate object obtained from the connection being
authenticated. Required for SLUGS authentication.
connection_info (tuple): A tuple of information pertaining to the
connection being authenticated, including the source IP address
and a timestamp (e.g., ('127.0.0.1', 1519759267.467451)).
Optional, defaults to None. Ignored for SLUGS authentication.
request_credentials (list): A list of KMIP Credential structures
containing credential information to use for authentication.
Optional, defaults to None. Ignored for SLUGS authentication.


def he_init(n_inputs, n_outputs, activation_fn, uniform=True):

    def in_relu_family(activation_fn):
        if isinstance(activation_fn, collections.Sequence):
            activation_fn = activation_fn[0]
        return (activation_fn in (tf.nn.relu, tf.nn.relu6))
    if in_relu_family(activation_fn):
        stddev = math.sqrt((2.0 / n_inputs))
        return tf.random_normal_initializer(stddev=stddev)
    else:
        return xavier_init(n_inputs, n_outputs, uniform)

Sets the parameter initialization using the method described.

This method is designed to keep the scale of the gradients roughly the same
in all layers with ReLU activations.

He et al. (2015):
Delving deep into rectifiers: surpassing human-level performance on
imageNet classification. International Conference on Computer Vision.

For activations other than ReLU and ReLU6, this method uses Xavier
initialization as in xavier_init().

Args:
n_inputs: The number of input nodes into each output.
n_outputs: The number of output nodes for each input.
activation_fn: Activation function used in this layer.
uniform: If uniform distribution will be used for Xavier initialization.
Normal distribution will be used if False.
Returns:
An initializer.


def Open(self, filename, read_only=False):

    if self._connection:
      raise RuntimeError('Cannot open database already opened.')

    self.filename = filename
    self.read_only = read_only

    try:
      self._connection = sqlite3.connect(filename)
    except sqlite3.OperationalError:
      return False

    if not self._connection:
      return False

    self._cursor = self._connection.cursor()
    if not self._cursor:
      return False

    return True

Opens the database file.

Args:
filename (str): filename of the database.
read_only (Optional[bool]): True if the database should be opened in
read-only mode. Since sqlite3 does not support a real read-only
mode we fake it by only permitting SELECT queries.

Returns:
bool: True if successful.

Raises:
RuntimeError: if the database is already opened.


def inner(*args):

    haspoly = sum([isinstance(arg, Poly) for arg in args])

    if not haspoly:
        return numpy.sum(numpy.prod(args, 0), 0)

    out = args[0]
    for arg in args[1:]:
        out = out * arg
    return sum(out)

Inner product of a polynomial set.

Args:
args (chaospy.poly.base.Poly):
The polynomials to perform inner product on.

Returns:
(chaospy.poly.base.Poly):
Resulting polynomial.

Examples:
>>> x,y = cp.variable(2)
>>> P = cp.Poly([x-1, y])
>>> Q = cp.Poly([x+1, x*y])
>>> print(cp.inner(P, Q))
q0^2+q0q1^2-1
>>> x = numpy.arange(4)
>>> print(cp.inner(x, x))
14


def __register_class(self, parsed_config):

    methods = parsed_config.get('methods')
    if not methods:
      return

    service_classes = set()
    for method in methods.itervalues():
      rosy_method = method.get('rosyMethod')
      if rosy_method and '.' in rosy_method:
        method_class = rosy_method.split('.', 1)[0]
        service_classes.add(method_class)

    for service_class in service_classes:
      if service_class in self.__registered_classes:
        raise api_exceptions.ApiConfigurationError(
            'API class %s has already been registered.' % service_class)
      self.__registered_classes.add(service_class)

Register the class implementing this config, so we only add it once.

Args:
parsed_config: The JSON object with the API configuration being added.

Raises:
ApiConfigurationError: If the class has already been registered.


def set_clang_compiler_path_win(environ_cp):
    default_clang_path = 'C:/Program Files/LLVM/bin/clang.exe'
    if not os.path.exists(default_clang_path):
        default_clang_path = shutil.which('clang') or ''
    clang_compiler_path = prompt_loop_or_load_from_env(environ_cp, var_name='CLANG_COMPILER_PATH', var_default=default_clang_path, ask_for_var='Please specify the path to clang executable.', check_success=os.path.exists, resolve_symlinks=True, error_msg='Invalid clang path. %s cannot be found. Note that Clang is nowpreferred compiler. You may use MSVC by removing --config=win_clang')
    write_action_env_to_bazelrc('CLANG_COMPILER_PATH', clang_compiler_path)
    write_to_bazelrc(f'build --repo_env=CC="{clang_compiler_path}"')
    write_to_bazelrc(f'build --repo_env=BAZEL_COMPILER="{clang_compiler_path}"')
    return clang_compiler_path

Set CLANG_COMPILER_PATH and environment variables.

Loop over user prompts for clang path until receiving a valid response.
Default is used if no input is given. Set CLANG_COMPILER_PATH and write
environment variables CC and BAZEL_COMPILER to .bazelrc.

Args:
environ_cp: (Dict) copy of the os.environ.

Returns:
string value for clang_compiler_path.


def move_to(self, destination_filename: str,
                alter_if_clash: bool = True) -> None:

        if not self.src_filename:
            return
        if alter_if_clash:
            counter = 0
            while os.path.exists(destination_filename):
                root, ext = os.path.splitext(destination_filename)
                destination_filename = "{r}_{c}{e}".format(
                    r=root, c=counter, e=ext)
                counter += 1

        else:
            if os.path.exists(destination_filename):
                src = self.rescue_filename or self.src_filename
                log.warning("Destination exists; won't move {!r} to {!r}",
                            src, destination_filename)
                return
        if self.rescue_filename:
            shutil.move(self.rescue_filename, destination_filename)
            os.remove(self.src_filename)
            log.info("Moved recovered file {!r} to {!r} and deleted corrupted "
                     "original {!r}",
                     self.rescue_filename,
                     destination_filename,
                     self.src_filename)
            self.rescue_filename = ""
        else:
            shutil.move(self.src_filename, destination_filename)
            log.info("Moved {!r} to {!r}", self.src_filename,
                     destination_filename)
        self.src_filename = ""

Move the file to which this class refers to a new location.
The function will not overwrite existing files (but offers the option
to rename files slightly to avoid a clash).

Args:
destination_filename: filename to move to
alter_if_clash: if ``True`` (the default), appends numbers to
the filename if the destination already exists, so that the
move can proceed.


def present_weather_codes(self, value=None):

        if value is not None:
            try:
                value = int(value)
            except ValueError:
                raise ValueError(
                    'value {} need to be of type int '
                    'for field `present_weather_codes`'.format(value))

        self._present_weather_codes = value

Corresponds to IDD Field `present_weather_codes`

Args:
value (int): value for IDD Field `present_weather_codes`
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

Raises:
ValueError: if `value` is not a valid value


def load(tiff_filename):
    tiff_filename = os.path.expanduser(tiff_filename)
    try:
        img = tiff.imread(tiff_filename)
    except Exception as e:
        raise ValueError('Could not load file {0} for conversion.'.format(tiff_filename))
        raise
    return numpy.array(img)

Import a TIFF file into a numpy array.

Arguments:
tiff_filename:  A string filename of a TIFF datafile

Returns:
A numpy array with data from the TIFF file


def nlargest(self, n=None):

		if n is None:
			return sorted(self.counts(), key=itemgetter(1), reverse=True)
		else:
			return heapq.nlargest(n, self.counts(), key=itemgetter(1))

List the n most common elements and their counts.

List is from the most
common to the least.  If n is None, the list all element counts.

Run time should be O(m log m) where m is len(self)
Args:
n (int): The number of elements to return


def duration_to_string(duration):
    (m, s) = divmod(duration, 60)
    (h, m) = divmod(m, 60)
    return ('%d:%02d:%02d' % (h, m, s))

Converts a duration to a string

Args:
duration (int): The duration in seconds to convert

Returns s (str): The duration as a string


def set_input(self, p_name, value):
    name = self.python_names.get(p_name)
    if ((p_name is None) or (name not in self.get_input_names())):
        raise ValueError('Invalid input "{}"'.format(p_name))
    self.step_inputs[name] = value

Set a Step's input variable to a certain value.

The value comes either from a workflow input or output of a previous
step.

Args:
name (str): the name of the Step input
value (str): the name of the output variable that provides the
value for this input.

Raises:
ValueError: The name provided is not a valid input name for this
Step.


def create_standalone_context(require=None, **settings) -> 'Context':
    backend = os.environ.get('MODERNGL_BACKEND')
    if (backend is not None):
        settings['backend'] = backend
    ctx = Context.__new__(Context)
    (ctx.mglo, ctx.version_code) = mgl.create_standalone_context(settings)
    ctx._screen = None
    ctx.fbo = None
    ctx._info = None
    ctx.extra = None
    if ((require is not None) and (ctx.version_code < require)):
        raise ValueError('Requested OpenGL version {}, got version {}'.format(require, ctx.version_code))
    return ctx

Create a standalone ModernGL context.

Example::

# Create a context with highest possible supported version
ctx = moderngl.create_context()

# Require at least OpenGL 4.3
ctx = moderngl.create_context(require=430)

Keyword Arguments:
require (int): OpenGL version code.

Returns:
:py:class:`Context` object


class PipelineException(Exception):

    def __init__(self, task: str, model: str, reason: str):
        super().__init__(reason)
        self.task = task
        self.model = model

Raised by a [`Pipeline`] when handling __call__.

Args:
task (`str`): The task of the pipeline.
model (`str`): The model used by the pipeline.
reason (`str`): The error message to display.


def _make_request(self, verb: str, endpoint: str, **kwargs: dict[str, Any]) -> requests.Response:
    res = self._session.request(verb, urllib.parse.urljoin('https:
    res.raise_for_status()
    return res.json()

Helper method to make a request and raise an HTTPError if one occurred.

Arguments:
verb: The HTTP verb to use
endpoint: The endpoint to make the request to
**kwargs: The json that will be sent as the body of the request.

Returns:
a requests.Response object containing the response from the API.

Raises:
requests.exceptions.HTTPError


def split_code_in_indented_blocks(code: str, indent_level: str='', start_prompt: Optional[str]=None, end_prompt: Optional[str]=None) -> List[str]:
    index = 0
    lines = code.split('\n')
    if start_prompt is not None:
        while not lines[index].startswith(start_prompt):
            index += 1
        blocks = ['\n'.join(lines[:index])]
    else:
        blocks = []
    current_block = [lines[index]]
    index += 1
    while index < len(lines) and (end_prompt is None or not lines[index].startswith(end_prompt)):
        if len(lines[index]) > 0 and get_indent(lines[index]) == indent_level:
            if len(current_block) > 0 and get_indent(current_block[-1]).startswith(indent_level + ' '):
                current_block.append(lines[index])
                blocks.append('\n'.join(current_block))
                if index < len(lines) - 1:
                    current_block = [lines[index + 1]]
                    index += 1
                else:
                    current_block = []
            else:
                blocks.append('\n'.join(current_block))
                current_block = [lines[index]]
        else:
            current_block.append(lines[index])
        index += 1
    if len(current_block) > 0:
        blocks.append('\n'.join(current_block))
    if end_prompt is not None and index < len(lines):
        blocks.append('\n'.join(lines[index:]))
    return blocks

Split some code into its indented blocks, starting at a given level.

Args:
code (`str`): The code to split.
indent_level (`str`): The indent level (as string) to use for identifying the blocks to split.
start_prompt (`str`, *optional*): If provided, only starts splitting at the line where this text is.
end_prompt (`str`, *optional*): If provided, stops splitting at a line where this text is.

Warning:
The text before `start_prompt` or after `end_prompt` (if provided) is not ignored, just not split. The input `code`
can thus be retrieved by joining the result.

Returns:
`List[str]`: The list of blocks.


def make_view(controller, context, data):

    if isinstance(data, BlockModel):

        view = _make_view_subclass(Block, controller, context, data)
    elif isinstance(data, AttributeModel):

        view = Attribute(controller, context, data)
    elif isinstance(data, MethodModel):

        view = Method(controller, context, data)
    elif isinstance(data, Model):

        view = _make_view_subclass(View, controller, context, data)
    elif isinstance(data, dict):

        d = OrderedDict()
        for k, v in data.items():
            d[k] = make_view(controller, context, v)
        view = d
    elif isinstance(data, list):

        view = [make_view(controller, context, x) for x in data]
    else:

        view = data
    return view

Make a View subclass containing properties specific for given data

Args:
controller (Controller): The child controller that hosts the data
context (Context): The context the parent has made that the View should
use for manipulating the data
data (Model): The actual data that context will be manipulating

Returns:
View: A View subclass instance that provides a user-focused API to
the given data


def fft(x, axis=-1, padding_samples=0):

    if padding_samples > 0:
        padded = np.concatenate(
            [x, np.zeros((len(x), padding_samples), dtype=x.dtype)],
            axis=axis)
    else:
        padded = x

    transformed = np.fft.rfft(padded, axis=axis, norm='ortho')

    sr = audio_sample_rate(int(Seconds(1) / x.dimensions[axis].frequency))
    scale = LinearScale.from_sample_rate(sr, transformed.shape[-1])
    new_dimensions = list(x.dimensions)
    new_dimensions[axis] = FrequencyDimension(scale)
    return ArrayWithUnits(transformed, new_dimensions)

Apply an FFT along the given dimension, and with the specified amount of
zero-padding

Args:
x (ArrayWithUnits): an :class:`~zounds.core.ArrayWithUnits` instance
which has one or more :class:`~zounds.timeseries.TimeDimension`
axes
axis (int): The axis along which the fft should be applied
padding_samples (int): The number of padding zeros to apply along
axis before performing the FFT


def _unique_constraint_name(table: str, field, keys):
    postfix = '_'.join(keys)
    return '{table}_{field}_unique_{postfix}'.format(table=table, field=field.column, postfix=postfix)

Gets the name for a UNIQUE INDEX that applies
to one or more keys in a hstore field.

Arguments:
table:
The name of the table the field is
a part of.

field:
The hstore field to create a
UNIQUE INDEX for.

key:
The name of the hstore key
to create the name for.

This can also be a tuple
of multiple names.

Returns:
The name for the UNIQUE index.


def _ReadEntry(self, parser_mediator, file_object, file_offset):
    entry_map = self._GetDataTypeMap('linux_libc6_utmp_entry')
    try:
        (entry, _) = self._ReadStructureFromFileObject(file_object, file_offset, entry_map)
    except (ValueError, errors.ParseError) as exception:
        raise errors.ParseError('Unable to parse utmp entry at offset: 0x{0:08x} with error: {1!s}.'.format(file_offset, exception))
    if (entry.type not in self._SUPPORTED_TYPES):
        raise errors.UnableToParseFile('Unsupported type: {0:d}'.format(entry.type))
    encoding = (parser_mediator.codepage or 'utf-8')
    try:
        username = entry.username.split(b'\x00')[0]
        username = username.decode(encoding)
    except UnicodeDecodeError:
        parser_mediator.ProduceExtractionWarning('unable to decode username string')
        username = None
    try:
        terminal = entry.terminal.split(b'\x00')[0]
        terminal = terminal.decode(encoding)
    except UnicodeDecodeError:
        parser_mediator.ProduceExtractionWarning('unable to decode terminal string')
        terminal = None
    if (terminal == '~'):
        terminal = 'system boot'
    try:
        hostname = entry.hostname.split(b'\x00')[0]
        hostname = hostname.decode(encoding)
    except UnicodeDecodeError:
        parser_mediator.ProduceExtractionWarning('unable to decode hostname string')
        hostname = None
    if ((not hostname) or (hostname == ':0')):
        hostname = 'localhost'
    if (entry.ip_address[4:] == self._EMPTY_IP_ADDRESS[4:]):
        ip_address = self._FormatPackedIPv4Address(entry.ip_address[:4])
    else:
        ip_address = self._FormatPackedIPv6Address(entry.ip_address)
    event_data = UtmpEventData()
    event_data.hostname = hostname
    event_data.exit_status = entry.exit_status
    event_data.ip_address = ip_address
    event_data.offset = file_offset
    event_data.pid = entry.pid
    event_data.terminal = terminal
    event_data.terminal_identifier = entry.terminal_identifier
    event_data.type = entry.type
    event_data.username = username
    timestamp = (entry.microseconds + (entry.timestamp * definitions.MICROSECONDS_PER_SECOND))
    return (timestamp, event_data)

Reads an utmp entry.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): a file-like object.
file_offset (int): offset of the data relative to the start of
the file-like object.

Returns:
tuple: containing:

int: timestamp, which contains the number of microseconds
since January 1, 1970, 00:00:00 UTC.
UtmpEventData: event data of the utmp entry read.

Raises:
ParseError: if the entry cannot be parsed.


def log_cdf_laplace(x, name='log_cdf_laplace'):
    with ops.name_scope(name, values=[x]):
        x = ops.convert_to_tensor(x, name='x')
        lower_solution = -np.log(2.0) + x
        safe_exp_neg_x = math_ops.exp(-math_ops.abs(x))
        upper_solution = math_ops.log1p(-0.5 * safe_exp_neg_x)
        return array_ops.where_v2(x < 0.0, lower_solution, upper_solution)

Log Laplace distribution function.

This function calculates `Log[L(x)]`, where `L(x)` is the cumulative
distribution function of the Laplace distribution, i.e.

```L(x) := 0.5 * int_{-infty}^x e^{-|t|} dt```

For numerical accuracy, `L(x)` is computed in different ways depending on `x`,

```
x <= 0:
Log[L(x)] = Log[0.5] + x, which is exact

0 < x:
Log[L(x)] = Log[1 - 0.5 * e^{-x}], which is exact
```

Args:
x: `Tensor` of type `float32`, `float64`.
name: Python string. A name for the operation (default="log_ndtr").

Returns:
`Tensor` with `dtype=x.dtype`.

Raises:
TypeError: if `x.dtype` is not handled.


def set_vector_catch(self, flags):

        res = self._dll.JLINKARM_WriteVectorCatch(flags)
        if res < 0:
            raise errors.JLinkException(res)
        return None

Sets vector catch bits of the processor.

The CPU will jump to a vector if the given vector catch is active, and
will enter a debug state.  This has the effect of halting the CPU as
well, meaning the CPU must be explicitly restarted.

Args:
self (JLink): the ``JLink`` instance

Returns:
``None``

Raises:
JLinkException: on error.


def cancel_merge_when_pipeline_succeeds(self, **kwargs):

        path = ('%s/%s/cancel_merge_when_pipeline_succeeds' %
                (self.manager.path, self.get_id()))
        server_data = self.manager.gitlab.http_put(path, **kwargs)
        self._update_attrs(server_data)

Cancel merge when the pipeline succeeds.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabMROnBuildSuccessError: If the server could not handle the
request


def recv(self, socket_, encoding=None):
    unpacker = msgpack.Unpacker(encoding=encoding)
    response = socket_.recv(8)
    if (response == b''):
        raise TensorForceError(('No data received by socket.recv in call to method `recv` ' + '(listener possibly closed)!'))
    orig_len = int(response)
    received_len = 0
    while True:
        data = socket_.recv(min((orig_len - received_len), self.max_msg_len))
        if (not data):
            raise TensorForceError('No data of len {} received by socket.recv in call to method `recv`!'.format((orig_len - received_len)))
        data_len = len(data)
        received_len += data_len
        unpacker.feed(data)
        if (received_len == orig_len):
            break
    for message in unpacker:
        sts = message.get('status', message.get(b'status'))
        if sts:
            if ((sts == 'ok') or (sts == b'ok')):
                return message
            else:
                raise TensorForceError('RemoteEnvironment server error: {}'.format(message.get('message', 'not specified')))
        else:
            raise TensorForceError("Message without field 'status' received!")
    raise TensorForceError('No message encoded in data stream (data stream had len={})'.format(orig_len))

Receives a message as msgpack-numpy encoded byte-string from the given socket object.
Blocks until something was received.

Args:
socket_: The python socket object to use.
encoding (str): The encoding to use for unpacking messages from the socket.
Returns: The decoded (as dict) message received.


def _ConvertDictToCollectionsCounter(cls, json_dict):
    collections_counter = collections.Counter()
    for (key, value) in iter(json_dict.items()):
        if (key == '__type__'):
            continue
        collections_counter[key] = value
    return collections_counter

Converts a JSON dict into a collections.Counter.

The dictionary of the JSON serialized objects consists of:
{
'__type__': 'collections.Counter'
...
}

Here '__type__' indicates the object base type. In this case this should
be 'collections.Counter'. The rest of the elements of the dictionary make up
the preprocessing object properties.

Args:
json_dict (dict[str, object]): JSON serialized objects.

Returns:
collections.Counter: counter.


def get_config_dict(self, services, hostname=None):
    if (not isinstance(services, (tuple, list))):
        services = [services]
    endpoints_util.check_list_type(services, remote._ServiceClass, 'services', allow_none=False)
    return self.__api_descriptor(services, hostname=hostname)

JSON dict description of a protorpc.remote.Service in API format.

Args:
services: Either a single protorpc.remote.Service or a list of them
that implements an api/version.
hostname: string, Hostname of the API, to override the value set on the
current service. Defaults to None.

Returns:
dict, The API descriptor document as a JSON dict.


def from_sites(cls, sites, charge=None, validate_proximity=False, to_unit_cell=False):
    if (len(sites) < 1):
        raise ValueError(('You need at least one site to construct a %s' % cls))
    prop_keys = []
    props = {}
    lattice = None
    for (i, site) in enumerate(sites):
        if (not lattice):
            lattice = site.lattice
        elif (site.lattice != lattice):
            raise ValueError('Sites must belong to the same lattice')
        for (k, v) in site.properties.items():
            if (k not in prop_keys):
                prop_keys.append(k)
                props[k] = ([None] * len(sites))
            props[k][i] = v
    for (k, v) in props.items():
        if any(((vv is None) for vv in v)):
            warnings.warn(('Not all sites have property %s. Missing values are set to None.' % k))
    return cls(lattice, [site.species for site in sites], [site.frac_coords for site in sites], charge=charge, site_properties=props, validate_proximity=validate_proximity, to_unit_cell=to_unit_cell)

Convenience constructor to make a Structure from a list of sites.

Args:
sites: Sequence of PeriodicSites. Sites must have the same
lattice.
validate_proximity (bool): Whether to check if there are sites
that are less than 0.01 Ang apart. Defaults to False.
to_unit_cell (bool): Whether to translate sites into the unit
cell.

Returns:
(Structure) Note that missing properties are set as None.


def matching_selectors(self, partial_selector):
    if (partial_selector in self._selector_map):
        return [partial_selector]
    selector_components = partial_selector.split('.')
    node = self._selector_tree
    for component in reversed(selector_components):
        if (component not in node):
            return []
        node = node[component]
    selectors = []
    dfs_stack = [node]
    while dfs_stack:
        node = dfs_stack.pop().copy()
        selector = node.pop(_TERMINAL_KEY, None)
        dfs_stack.extend(node.values())
        if selector:
            selectors.append(selector)
    return selectors

Retrieves all selectors matching `partial_selector`.

For instance, if "one.a.b" and "two.a.b" are stored in a `SelectorMap`, both
`matching_selectors('b')` and `matching_selectors('a.b')` will return them.

In the event that `partial_selector` exactly matches an existing complete
selector, only that complete selector is returned. For instance, if
"a.b.c.d" and "c.d" are stored, `matching_selectors('c.d')` will return only
`['c.d']`, while `matching_selectors('d')` will return both.

Args:
partial_selector: The partial selector to find matches for.

Returns:
A list of selectors matching `partial_selector`.


def diag_part(self, name='diag_part'):
    with self._name_scope(name):
        return self._diag_part()

Efficiently get the [batch] diagonal part of this operator.

If this operator has shape `[B1,...,Bb, M, N]`, this returns a
`Tensor` `diagonal`, of shape `[B1,...,Bb, min(M, N)]`, where
`diagonal[b1,...,bb, i] = self.to_dense()[b1,...,bb, i, i]`.

```
my_operator = LinearOperatorDiag([1., 2.])

# Efficiently get the diagonal
my_operator.diag_part()
==> [1., 2.]

# Equivalent, but inefficient method
tf.linalg.diag_part(my_operator.to_dense())
==> [1., 2.]
```

Args:
name:  A name for this `Op`.

Returns:
diag_part:  A `Tensor` of same `dtype` as self.


def end(self):
    return (self.last.lineno, self.last.column + len(self.last.value))

The end of the logical line.

Returns:
A tuple of the ending line number and column.


def __init__(self, sink):
    super().__init__()
    self.sink = sink

Initializes a Write transform.

Args:
sink: Data sink to write to.


def sync(coro, timeout=None):
    loop = initloop()
    return asyncio.run_coroutine_threadsafe(coro, loop).result(timeout)

Schedule a coroutine to run on the global loop and return it's result.

Args:
coro (coroutine): The coroutine instance.

Notes:
This API is thread safe and should only be called by non-loop threads.


def _pywrap_tensorflow():
    try:
        from tensorboard.compat import notf
    except ImportError:
        try:
            from tensorflow.python import pywrap_tensorflow
            return pywrap_tensorflow
        except ImportError:
            pass
    from tensorboard.compat.tensorflow_stub import pywrap_tensorflow
    return pywrap_tensorflow

Provide pywrap_tensorflow access in TensorBoard.

pywrap_tensorflow cannot be accessed from tf.python.pywrap_tensorflow
and needs to be imported using
`from tensorflow.python import pywrap_tensorflow`. Therefore, we provide
a separate accessor function for it here.

NOTE: pywrap_tensorflow is not part of TensorFlow API and this
dependency will go away soon.

Returns:
pywrap_tensorflow import, if available.

Raises:
ImportError: if we couldn't import pywrap_tensorflow.


def parse(self, words):

    def exact(words):
        'If already represented as float or int, convert.'
        try:
            return float(words)
        except:
            return None
    guess = exact(words)
    if (guess is not None):
        return guess
    split = words.split(' ')
    if (split[(- 1)] in self.__fractions__):
        split[(- 1)] = self.__fractions__[split[(- 1)]]
    elif (split[(- 1)] in self.__ordinals__):
        split[(- 1)] = self.__ordinals__[split[(- 1)]]
    parsed_ordinals = ' '.join(split)
    return self.parseFloat(parsed_ordinals)

A general method for parsing word-representations of numbers.
Supports floats and integers.

Args:
words (str): Description of an arbitrary number.

Returns:
A double representation of the words.


def _generate_splits(self, m, r):
    new_rects = []
    if (r.left > m.left):
        new_rects.append(Rectangle(m.left, m.bottom, (r.left - m.left), m.height))
    if (r.right < m.right):
        new_rects.append(Rectangle(r.right, m.bottom, (m.right - r.right), m.height))
    if (r.top < m.top):
        new_rects.append(Rectangle(m.left, r.top, m.width, (m.top - r.top)))
    if (r.bottom > m.bottom):
        new_rects.append(Rectangle(m.left, m.bottom, m.width, (r.bottom - m.bottom)))
    return new_rects

When a rectangle is placed inside a maximal rectangle, it stops being one
and up to 4 new maximal rectangles may appear depending on the placement.
_generate_splits calculates them.

Arguments:
m (Rectangle): max_rect rectangle
r (Rectangle): rectangle placed

Returns:
list : list containing new maximal rectangles or an empty list


def _dump_worker_context(self, strategy):
    context = distribute_coordinator_context.get_current_worker_context()
    self.assertTrue(context is not None)
    task_type = str(context.task_type)
    task_id = context.task_id or 0
    with self._lock:
        if task_type not in self._worker_context:
            self._worker_context[task_type] = []
        while len(self._worker_context[task_type]) <= task_id:
            self._worker_context[task_type].append(None)
        self._worker_context[task_type][task_id] = (context.master_target, context.num_workers, context.is_chief, context.distributed_mode)

Dumps the properties of each worker context.

It dumps the context properties to a dict mapping from task_type to a list
of tuples of master_target, num_workers, is_chief and distribute_mode, where
the list is indexed by the task_id.

Args:
strategy: a `DistributionStrategy` object.


def slicewise(tf_fn, xs, output_shape=None, output_dtype=None, splittable_dims=None, grad_function=None, name=None):
    multiple_outputs = isinstance(output_dtype, list)
    output_shapes = (output_shape if multiple_outputs else [output_shape])
    output_dtypes = (output_dtype if multiple_outputs else [output_dtype])
    op = SlicewiseOperation(tf_fn, xs, [(convert_to_shape(shape) or xs[0].shape) for shape in output_shapes], [(dtype or xs[0].dtype) for dtype in output_dtypes], splittable_dims, grad_function, name=name)
    return (tuple(op.outputs) if multiple_outputs else op.outputs[0])

Slice-wise call to any tensorflow function.

The output shape and dtype default to those of the first input.
splittable_dims is a list of Dimensions which can be split while keeping the
computation valid.

Args:
tf_fn: a function taking n tf.Tensors and returning a tf.Tensor
xs: a list of n Tensors
output_shape: a Shape (or list of shapes)
output_dtype: a dtype (or list of dtypes)
splittable_dims: a list of Dimensions which are ok to split
grad_function: an optional gradients function.  If None, use tf gradient.
name: an optional string

Returns:
a Tensor (or a tuple of Tensors)


def get_pipeline_boxes(self, pipeline_key, sort_by = None):

		if not pipeline_key:
			return requests.codes.bad_request, None

		uri = '/'.join([
						self.api_uri,
						self.pipelines_suffix,
						pipeline_key
						])

		if sort_by:
				if sort_by in ['creationTimestamp', 'lastUpdatedTimestamp']:
					uri += self.sort_by_postfix + sort_by
				else:
					return requests.codes.bad_request, {'success' : 'False',
												'error': 'sortBy needs to be \'creationTimestamp\', or \'lastUpdatedTimestamp\''}

		return self._req('get', uri)

Gets a list of all box objects in a pipeline. Performs a single GET.
Args:
pipeline_key	key for pipeline
sort_by			in desc order by 'creationTimestamp' or 'lastUpdatedTimestamp'
Not sure if it is supported
returns 		(status code for the GET request, dict of boxes)


def ParseOptions(cls, options, configuration_object):

    if not isinstance(configuration_object, tools.CLITool):
      raise errors.BadConfigObject(
          'Configuration object is not an instance of CLITool')

    hashers = cls._ParseStringOption(
        options, 'hashers', default_value=cls._DEFAULT_HASHER_STRING)

    hasher_file_size_limit = cls._ParseNumericOption(
        options, 'hasher_file_size_limit', default_value=0)

    if hasher_file_size_limit < 0:
      raise errors.BadConfigOption(
          'Invalid hasher file size limit value cannot be negative.')

    setattr(configuration_object, '_hasher_names_string', hashers)
    setattr(
        configuration_object, '_hasher_file_size_limit', hasher_file_size_limit)

Parses and validates options.

Args:
options (argparse.Namespace): parser options.
configuration_object (CLITool): object to be configured by the argument
helper.

Raises:
BadConfigObject: when the configuration object is of the wrong type.
BadConfigOption: when a configuration parameter fails validation.


def _check_if_fenced(self, name):
    if (name in object.__getattribute__(self, '_attributes_to_fence')):
        raise TranspilerAccessError(('The fenced %s has the property %s protected' % (type(object.__getattribute__(self, '_wrapped')), name)))

Checks if the attribute name is in the list of attributes to protect. If so, raises
TranspilerAccessError.

Args:
name (string): the attribute name to check

Raises:
TranspilerAccessError: when name is the list of attributes to protect.


def GetFileObjectByPathSpec(self, path_spec):

    file_entry = self.GetFileEntryByPathSpec(path_spec)
    if not file_entry:
      return None

    return file_entry.GetFileObject()

Retrieves a file-like object for a path specification.

Args:
path_spec (PathSpec): a path specification.

Returns:
FileIO: a file-like object or None if not available.


def with_max_depth(self, max_depth):
    self._options['max_depth'] = max_depth
    return self

Set the maximum depth of display.

The depth depends on profiling view. For 'scope' view, it's the
depth of name scope hierarchy (tree), for 'op' view, it's the number
of operation types (list), etc.

Args:
max_depth: Maximum depth of the data structure to display.
Returns:
self


class TFForcedBOSTokenLogitsProcessor(TFLogitsProcessor):

    def __init__(self, bos_token_id: int):
        if bos_token_id < 0:
            raise ValueError(f'The forced bos token id  must be a non-negative integer, got {bos_token_id}')
        self.bos_token_id = bos_token_id

    def __call__(self, input_ids: tf.Tensor, scores: tf.Tensor, cur_len: int) -> tf.Tensor:
        if cur_len == 1:
            batch_size, num_tokens = scores.shape
            scores = tf.zeros((batch_size, 1))
            if self.bos_token_id > 0:
                scores = tf.concat((tf.broadcast_to(-float('inf'), (batch_size, self.bos_token_id)), scores), axis=-1)
            if self.bos_token_id < num_tokens - 1:
                scores = tf.concat((scores, tf.broadcast_to(-float('inf'), (batch_size, num_tokens - 1 - self.bos_token_id))), axis=-1)
        return scores

[`TFLogitsProcessor`] that enforces the specified token as the first generated token.

Args:
bos_token_id (`int`):
The id of the token to force as the first generated token.


def _varslist2axis(cls, fluent: 'TensorFluent', vars_list: List[str]) -> List[int]:

        axis = []
        for var in vars_list:
            if var in fluent.scope.as_list():
                ax = fluent.scope.index(var)
                if fluent.batch:
                    ax += 1
                axis.append(ax)
        return axis

Maps the `vars_list` into a list of axis indices
corresponding to the `fluent` scope.

Args:
x: The fluent.
vars_list: The list of variables to be aggregated over.

Returns:
List[int]: a list of axis.


def _wrap_call_and_conditional_losses(layer):
    layer_call = _get_layer_call_method(layer)

    def call_and_return_conditional_losses(*args, **kwargs):

        call_output = layer_call(*args, **kwargs)
        if version_utils.is_v1_layer_or_model(layer):
            conditional_losses = layer.get_losses_for(_filtered_inputs([args, kwargs]))
        else:
            conditional_losses = [l for l in layer.losses if not hasattr(l, '_unconditional_loss')]
        return (call_output, conditional_losses)
    return _create_call_fn_decorator(layer, call_and_return_conditional_losses)

Wraps call function that returns a tuple of (outputs, losses).

The losses returned are conditional on the inputs passed to the call function.
Unconditional losses (e.g. weight regularizeration) are wrapped separately.

Args:
layer: a Keras layer object

Returns:
python call function that returns outputs and conditional losses -- excludes
activity regularizer


def uniprot_reviewed_checker(uniprot_id):
    query_string = ('id:' + uniprot_id)
    uni_rev_raw = StringIO(bsup.search(query_string, columns='id,reviewed', frmt='tab'))
    uni_rev_df = pd.read_table(uni_rev_raw, sep='\t', index_col=0)
    uni_rev_df = uni_rev_df.fillna(False)
    uni_rev_df = uni_rev_df[pd.notnull(uni_rev_df.Status)]
    uni_rev_df = uni_rev_df.replace(to_replace='reviewed', value=True)
    uni_rev_df = uni_rev_df.replace(to_replace='unreviewed', value=False)
    uni_rev_dict_adder = uni_rev_df.to_dict()['Status']
    return uni_rev_dict_adder[uniprot_id]

Check if a single UniProt ID is reviewed or not.

Args:
uniprot_id:

Returns:
bool: If the entry is reviewed


def get_aws_unique_id(timeout=DEFAULT_AWS_TIMEOUT):

    try:
        resp = requests.get(AWS_ID_URL, timeout=timeout).json()
    except requests.exceptions.ConnectTimeout:
        _logger.warning('Connection timeout when determining AWS unique '
                        'ID. Not using AWS unique ID.')
        return None
    else:
        aws_id = "{0}_{1}_{2}".format(resp['instanceId'], resp['region'],
                                      resp['accountId'])
        _logger.debug('Using AWS unique ID %s.', aws_id)
        return aws_id

Determine the current AWS unique ID

Args:
timeout (int): How long to wait for a response from AWS metadata IP


def SetRange(self, range_offset, range_size):

    if self._is_open:
      raise IOError('Already open.')

    if range_offset < 0:
      raise ValueError(
          'Invalid range offset: {0:d} value out of bounds.'.format(
              range_offset))

    if range_size < 0:
      raise ValueError(
          'Invalid range size: {0:d} value out of bounds.'.format(
              range_size))

    self._range_offset = range_offset
    self._range_size = range_size
    self._current_offset = 0

Sets the data range (offset and size).

The data range is used to map a range of data within one file
(e.g. a single partition within a full disk image) as a file-like object.

Args:
range_offset (int): start offset of the data range.
range_size (int): size of the data range.

Raises:
IOError: if the file-like object is already open.
OSError: if the file-like object is already open.
ValueError: if the range offset or range size is invalid.


def derive_temporary_python2_environment(destination_directory: str, python3_environment: PreparedEnv, verbose: bool, env_name: str='.test_virtualenv_py2', python_path: str='/usr/bin/python2.7') -> PreparedEnv:
    shutil.rmtree(destination_directory)
    input_directory = cast(str, python3_environment.destination_directory)
    os.chdir(input_directory)
    conversion_script_path = os.path.join(input_directory, 'dev_tools', 'python2.7-generate.sh')
    shell_tools.run_cmd('bash', conversion_script_path, destination_directory, input_directory, python3_environment.virtual_env_path, out=sys.stderr)
    os.chdir(destination_directory)
    env_path = os.path.join(destination_directory, env_name)
    req_path = os.path.join(destination_directory, 'requirements.txt')
    dev_req_path = os.path.join(destination_directory, 'pip-list-test-tools.txt')
    contrib_req_path = os.path.join(destination_directory, 'cirq', 'contrib', 'contrib-requirements.txt')
    req_paths = [req_path, dev_req_path, contrib_req_path]
    create_virtual_env(venv_path=env_path, python_path=python_path, requirements_paths=req_paths, verbose=verbose)
    return PreparedEnv(github_repo=python3_environment.repository, actual_commit_id=python3_environment.actual_commit_id, compare_commit_id=python3_environment.compare_commit_id, destination_directory=destination_directory, virtual_env_path=env_path)

Creates a python 2.7 environment starting from a prepared python 3 one.

Args:
destination_directory: Where to put the python 2 environment.
python3_environment: The prepared environment to start from.
verbose: When set, more progress output is produced.
env_name: The name to use for the virtualenv directory.
python_path: The python binary to use.

Returns:
A description of the environment that was prepared.


def hours(start, end=None):

    return iterate.between(start, datetime.timedelta(hours=1), end)

Iterate over the hours between the given datetime_tzs.

Args:
start: datetime_tz to start from.
end: (Optional) Date to end at, if not given the iterator will never
terminate.

Returns:
An iterator which generates datetime_tz objects a hour apart.


def add_spin_by_element(self, spins):
    for site in self.sites:
        new_sp = {}
        for (sp, occu) in site.species.items():
            sym = sp.symbol
            oxi_state = getattr(sp, 'oxi_state', None)
            new_sp[Specie(sym, oxidation_state=oxi_state, properties={'spin': spins.get(str(sp), spins.get(sym, None))})] = occu
        site.species = new_sp

Add spin states to a structure.

Args:
spisn (dict): Dict of spins associated with
elements or species, e.g. {"Ni":+5} or {"Ni2+":5}


def __init__(self, f, name, problems):

    self._f = f
    self._name = name
    self._crlf = 0
    self._crlf_examples = []
    self._lf = 0
    self._lf_examples = []
    self._line_number = 0
    self._problems = problems

Create new object.

Args:
f: file-like object to wrap
name: name to use for f. StringIO objects don't have a name attribute.
problems: a ProblemReporterBase object


def fetch(self, virtual_account_id, data={}, **kwargs):

        return super(VirtualAccount, self).fetch(
            virtual_account_id,
            data,
            **kwargs)

Fetch Virtual Account for given Id

Args:
virtual_account_id :
Id for which Virtual Account object has to be retrieved

Returns:
Virtual Account dict for given Virtual Account Id


def _define_loop(graph, eval_steps):
    loop = tools.Loop(None, graph.step, graph.should_log, graph.do_report, graph.force_reset)
    loop.add_phase('eval', graph.done, graph.score, graph.summary, eval_steps, report_every=eval_steps, log_every=None, checkpoint_every=None, feed={graph.is_training: False})
    return loop

Create and configure an evaluation loop.

Args:
graph: Object providing graph elements via attributes.
eval_steps: Number of evaluation steps per epoch.

Returns:
Loop object.


def load_py(stream, filepath=None):
    with add_sys_paths(config.package_definition_build_python_paths):
        return _load_py(stream, filepath=filepath)

Load python-formatted data from a stream.

Args:
stream (file-like object).

Returns:
dict.


def _aggregate(self, tests_results):

        summary = {
            "success": True,
            "stat": {
                "testcases": {
                    "total": len(tests_results),
                    "success": 0,
                    "fail": 0
                },
                "teststeps": {}
            },
            "time": {},
            "platform": report.get_platform(),
            "details": []
        }

        for tests_result in tests_results:
            testcase, result = tests_result
            testcase_summary = report.get_summary(result)

            if testcase_summary["success"]:
                summary["stat"]["testcases"]["success"] += 1
            else:
                summary["stat"]["testcases"]["fail"] += 1

            summary["success"] &= testcase_summary["success"]
            testcase_summary["name"] = testcase.config.get("name")
            testcase_summary["in_out"] = utils.get_testcase_io(testcase)

            report.aggregate_stat(summary["stat"]["teststeps"], testcase_summary["stat"])
            report.aggregate_stat(summary["time"], testcase_summary["time"])

            summary["details"].append(testcase_summary)

        return summary

aggregate results

Args:
tests_results (list): list of (testcase, result)


def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    local_stream = utils.BytearrayStream()
    if self._asynchronous_correlation_value:
        self._asynchronous_correlation_value.write(local_stream, kmip_version=kmip_version)
    self.length = local_stream.length()
    super(CancelRequestPayload, self).write(output_stream, kmip_version=kmip_version)
    output_stream.write(local_stream.buffer)

Write the data encoding the Cancel request payload to a stream.

Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.

Raises:
ValueError: Raised if the data attribute is not defined.


def get_file(self, file_name, local_destination=None, **kwargs):

        if not local_destination:
            local_destination = file_name

        return SubprocessTask(
            self._rsync_cmd() +
            ['-ut', '%s:%s' % (self.hostname, file_name), local_destination],
            **kwargs)

Get a file from a remote host with rsync.

Args:
file_name (str): The relative location of the file on the remote
host.

local_destination (str): The destination for the file on the local
host. If `None`, will be assumed to be the same as
**file_name**. Default `None`.

**kwargs: Passed to ``SubprocessTask``'s init method.

Return:
``pyrem.task.SubprocessTask``: The resulting task.


def identity(shape, dtype: Optional[torch.dtype]=None, device: Optional[torch.device]=None, requires_grad: bool=True, fmt: str='quat') -> Rotation:
    if fmt == 'rot_mat':
        rot_mats = identity_rot_mats(shape, dtype, device, requires_grad)
        return Rotation(rot_mats=rot_mats, quats=None)
    elif fmt == 'quat':
        quats = identity_quats(shape, dtype, device, requires_grad)
        return Rotation(rot_mats=None, quats=quats, normalize_quats=False)
    else:
        raise ValueError(f'Invalid format: f{fmt}')

Returns an identity Rotation.

Args:
shape:
The "shape" of the resulting Rotation object. See documentation for the shape property
dtype:
The torch dtype for the rotation
device:
The torch device for the new rotation
requires_grad:
Whether the underlying tensors in the new rotation object should require gradient computation
fmt:
One of "quat" or "rot_mat". Determines the underlying format of the new object's rotation
Returns:
A new identity rotation


def _tidy_names(names, nnames, extra_names=None):

    if len(names) < nnames and extra_names is not None:
        names.extend(extra_names)
    names.extend(range(nnames - len(names)))
    del names[nnames:]

Truncate or extend names so that its len is nnames.

The list is modified, this function returns nothing.

Args:
names (list): list of names.
nnames (int): desired number of names.
extra_names (list of str): list of names to be used to extend the list
if needed. If this list isn't provided, a range is used instead.


def action_fluent_variables(self) -> FluentParamsList:
    fluents = self.domain.action_fluents
    ordering = self.domain.action_fluent_ordering
    return self._fluent_params(fluents, ordering)

Returns the instantiated action fluents in canonical order.

Returns:
Sequence[Tuple[str, List[str]]]: A tuple of pairs of fluent name
and a list of instantiated fluents represented as strings.


def _validate_isvalid_quantity(self, isvalid_quantity, field, value):
    quantity = Q_(value[0])
    low_lim = (0.0 * units(property_units[field]))
    try:
        if (quantity <= low_lim):
            self._error(field, 'value must be greater than 0.0 {}'.format(property_units[field]))
    except pint.DimensionalityError:
        self._error(field, ('incompatible units; should be consistent with ' + property_units[field]))

Checks for valid given value and appropriate units.

Args:
isvalid_quantity (`bool`): flag from schema indicating quantity to be checked.
field (`str`): property associated with quantity in question.
value (`list`): list whose first element is a string representing a value with units

The rule's arguments are validated against this schema:
{'isvalid_quantity': {'type': 'bool'}, 'field': {'type': 'str'},
'value': {'type': 'list'}}


def save(self, wf_state):
    self.wf_state = wf_state
    self.wf_state['role_id'] = self.current.role_id
    self.set(self.wf_state)
    if (self.wf_state['name'] not in settings.EPHEMERAL_WORKFLOWS):
        self.publish(job='_zops_sync_wf_cache', token=self.db_key)

write wf state to DB through MQ >> Worker >> _zops_sync_wf_cache

Args:
wf_state dict: wf state


def get_percentile(self, percentile):
    assert (0 <= percentile <= 100), 'percentile must be between 0 and 100. Got {}'.format(percentile)
    return self._percentile(self._values, percentile)

Get a value representing a the input percentile of the Data Collection.

Args:
percentile: A float value from 0 to 100 representing the
requested percentile.

Return:
The Data Collection value at the input percentile


def get(identifier):
    if isinstance(identifier, (Optimizer, optimizer_v2.OptimizerV2)):
        return identifier
    elif isinstance(identifier, tf_optimizer_module.Optimizer):
        opt = TFOptimizer(identifier)
        backend.track_tf_optimizer(opt)
        return opt
    elif isinstance(identifier, dict):
        return deserialize(identifier)
    elif isinstance(identifier, str):
        config = {'class_name': str(identifier), 'config': {}}
        return deserialize(config)
    else:
        raise ValueError('Could not interpret optimizer identifier: {}'.format(identifier))

Retrieves a Keras Optimizer instance.

Args:
identifier: Optimizer identifier, one of
- String: name of an optimizer
- Dictionary: configuration dictionary. - Keras Optimizer instance (it
will be returned unchanged). - TensorFlow Optimizer instance (it
will be wrapped as a Keras Optimizer).

Returns:
A Keras Optimizer instance.

Raises:
ValueError: If `identifier` cannot be interpreted.


def from_private_key(account_name, private_key=None, private_key_path=None, storage=None, storage_path=None, api_version='v3', readonly=False, http_client=None, ga_hook=None):
    if (not private_key):
        if (not private_key_path):
            raise GapyError('Must provide either a private_key or a private_key_file')
        if isinstance(private_key_path, basestring):
            private_key_path = open(private_key_path)
        private_key = private_key_path.read()
    storage = _get_storage(storage, storage_path)
    scope = (GOOGLE_API_SCOPE_READONLY if readonly else GOOGLE_API_SCOPE)
    credentials = SignedJwtAssertionCredentials(account_name, private_key, scope)
    credentials.set_store(storage)
    return Client(_build(credentials, api_version, http_client), ga_hook)

Create a client for a service account.

Create a client with an account name and a private key.

Args:
account_name: str, the account identifier (probably the account email).
private_key: str, the private key as a string.
private_key_path: str, path to a file with the private key in.
storage: oauth2client.client.Storage, a Storage implementation to store
credentials.
storage_path: str, path to a file storage.
readonly: bool, default False, if True only readonly access is requested
from GA.
http_client: httplib2.Http, Override the default http client used.
ga_hook: function, a hook that is called every time a query is made
against GA.


def _create_L_ind(self, L):

        if issparse(L):
            L = L.todense()

        L_ind = np.zeros((self.n, self.m * self.k))
        for y in range(1, self.k + 1):

            L_ind[:, (y - 1) :: self.k] = np.where(L == y, 1, 0)
        return L_ind

Convert a label matrix with labels in 0...k to a one-hot format

Args:
L: An [n,m] scipy.sparse label matrix with values in {0,1,...,k}

Returns:
L_ind: An [n,m*k] dense np.ndarray with values in {0,1}

Note that no column is required for 0 (abstain) labels.


def mangle(tree, toplevel=False):

    sym_table = SymbolTable()
    visitor = ScopeTreeVisitor(sym_table)
    visitor.visit(tree)

    fill_scope_references(tree)
    mangle_scope_tree(sym_table.globals, toplevel)

    mangler = NameManglerVisitor()
    mangler.visit(tree)

Mangle names.

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


def collect_members(module_to_name):

  members = {}
  for module, module_name in module_to_name.items():
    all_names = getattr(module, "__all__", None)
    for name, member in inspect.getmembers(module):
      if ((inspect.isfunction(member) or inspect.isclass(member)) and
          not _always_drop_symbol_re.match(name) and
          (all_names is None or name in all_names)):
        fullname = '%s.%s' % (module_name, name)
        if name in members:
          other_fullname, other_member = members[name]
          if member is not other_member:
            raise RuntimeError("Short name collision between %s and %s" %
                               (fullname, other_fullname))
          if len(fullname) == len(other_fullname):
            raise RuntimeError("Can't decide whether to use %s or %s for %s: "
                               "both full names have length %d" %
                               (fullname, other_fullname, name, len(fullname)))
          if len(fullname) > len(other_fullname):
            continue
        members[name] = fullname, member
  return members

Collect all symbols from a list of modules.

Args:
module_to_name: Dictionary mapping modules to short names.

Returns:
Dictionary mapping name to (fullname, member) pairs.


def get_and_check_tasks_for(context, task, msg_prefix=''):
    tasks_for = task['extra']['tasks_for']
    if (tasks_for not in context.config['valid_tasks_for']):
        raise ValueError('{}Unknown tasks_for: {}'.format(msg_prefix, tasks_for))
    return tasks_for

Given a parent task, return the reason the parent task was spawned.

``.taskcluster.yml`` uses this to know whether to spawn an action,
cron, or decision task definition.  ``tasks_for`` must be a valid one defined in the context.

Args:
task (dict): the task definition.
msg_prefix (str): the string prefix to use for an exception.

Raises:
(KeyError, ValueError): on failure to find a valid ``tasks_for``.

Returns:
str: the ``tasks_for``


def sparse_union_indices_and_values(x1, x2_indices, x2_values=None):
    zeros2 = tf.SparseTensor(x2_indices, tf.zeros((tf.shape(x2_indices)[0],), x1.values.dtype), x1.dense_shape)
    x1_for_union = tf.sparse.add(x1, zeros2)
    if x2_values is not None:
        x2 = tf.SparseTensor(x2_indices, x2_values, x1.dense_shape)
        zeros1 = tf.sparse.map_values(tf.zeros_like, x1)
        x2_for_union = tf.sparse.add(x2, zeros1)
        return (x1_for_union.indices, x1_for_union.values, x2_for_union.values)
    else:
        return (x1_for_union.indices, x1_for_union.values, None)

Compute the indices for the union of the indices of the provided
`tf.SparseTensor`s and another set of indices and return the modified values
for these indices.

Args:
x: a `tf.SparseTensor`.
indices: another set of indices in the `tf.SparseTensor` format.
Returns: A tuple containing:
- the indices for the union
- `x1` values for the union indices (some zeros were added)
- `x2` values for the union indices (some zeros were added) or `None` if
`x2_values` was `None`.


def put_content(self, url, content):
    cache_path = self._url_to_path(url)
    try:
        dir = os.path.dirname(cache_path)
        os.makedirs(dir)
    except OSError as e:
        if (e.errno != errno.EEXIST):
            raise Error(('Failed to create cache directories for ' % cache_path))
    try:
        with open(cache_path, 'wb') as f:
            f.write(content)
    except IOError:
        raise Error(('Failed to cache content as %s for %s' % (cache_path, url)))

Stores the content of a resource into the disk cache.

Args:
url: The url of the resource
content: The content of the resource

Raises:
CacheError: If the content cannot be put in cache


def get_day_of_month_description(self):
    expression = self._expression_parts[3]
    expression = expression.replace('?', '*')
    if (expression == 'L'):
        description = _(', on the last day of the month')
    elif ((expression == 'LW') or (expression == 'WL')):
        description = _(', on the last weekday of the month')
    else:
        regex = re.compile('(\\d{1,2}W)|(W\\d{1,2})')
        if regex.match(expression):
            m = regex.match(expression)
            day_number = int(m.group().replace('W', ''))
            day_string = (_('first weekday') if (day_number == 1) else _('weekday nearest day {0}').format(day_number))
            description = _(', on the {0} of the month').format(day_string)
        else:
            description = self.get_segment_description(expression, _(', every day'), (lambda s: s), (lambda s: (_(', every day') if (s == '1') else _(', every {0} days'))), (lambda s: _(', between day {0} and {1} of the month')), (lambda s: _(', on day {0} of the month')))
    return description

Generates a description for only the DAYOFMONTH portion of the expression

Returns:
The DAYOFMONTH description


def _viz_prototype(self, vis_fn):

    def _viz_logger(*args, **kwargs):
        self.win = vis_fn(*args, win=self.win, env=self.env, opts=self.opts, **kwargs)
    return _viz_logger

Outputs a function which will log the arguments to Visdom in an appropriate way.

Args:
vis_fn: A function, such as self.vis.image


def set_data(self, data={}, datetime_fields=[]):
    if datetime_fields:
        for field in datetime_fields:
            if (field in data):
                data[field] = self._parse_datetime(data[field])
    super(CampfireEntity, self).set_data(data)

Set entity data

Args:
data (dict): Entity data
datetime_fields (array): Fields that should be parsed as datetimes


def __init__(self, channel):

    self.PutObject = channel.stream_unary(
        '/pfs.ObjectAPI/PutObject',
        request_serializer=client_dot_pfs_dot_pfs__pb2.PutObjectRequest.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.Object.FromString,
        )
    self.PutObjectSplit = channel.stream_unary(
        '/pfs.ObjectAPI/PutObjectSplit',
        request_serializer=client_dot_pfs_dot_pfs__pb2.PutObjectRequest.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.Objects.FromString,
        )
    self.PutObjects = channel.stream_unary(
        '/pfs.ObjectAPI/PutObjects',
        request_serializer=client_dot_pfs_dot_pfs__pb2.PutObjectRequest.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
    self.GetObject = channel.unary_stream(
        '/pfs.ObjectAPI/GetObject',
        request_serializer=client_dot_pfs_dot_pfs__pb2.Object.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_wrappers__pb2.BytesValue.FromString,
        )
    self.GetObjects = channel.unary_stream(
        '/pfs.ObjectAPI/GetObjects',
        request_serializer=client_dot_pfs_dot_pfs__pb2.GetObjectsRequest.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_wrappers__pb2.BytesValue.FromString,
        )
    self.GetBlocks = channel.unary_stream(
        '/pfs.ObjectAPI/GetBlocks',
        request_serializer=client_dot_pfs_dot_pfs__pb2.GetBlocksRequest.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_wrappers__pb2.BytesValue.FromString,
        )
    self.TagObject = channel.unary_unary(
        '/pfs.ObjectAPI/TagObject',
        request_serializer=client_dot_pfs_dot_pfs__pb2.TagObjectRequest.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
    self.InspectObject = channel.unary_unary(
        '/pfs.ObjectAPI/InspectObject',
        request_serializer=client_dot_pfs_dot_pfs__pb2.Object.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.ObjectInfo.FromString,
        )
    self.CheckObject = channel.unary_unary(
        '/pfs.ObjectAPI/CheckObject',
        request_serializer=client_dot_pfs_dot_pfs__pb2.CheckObjectRequest.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.CheckObjectResponse.FromString,
        )
    self.ListObjects = channel.unary_stream(
        '/pfs.ObjectAPI/ListObjects',
        request_serializer=client_dot_pfs_dot_pfs__pb2.ListObjectsRequest.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.Object.FromString,
        )
    self.DeleteObjects = channel.unary_unary(
        '/pfs.ObjectAPI/DeleteObjects',
        request_serializer=client_dot_pfs_dot_pfs__pb2.DeleteObjectsRequest.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.DeleteObjectsResponse.FromString,
        )
    self.GetTag = channel.unary_stream(
        '/pfs.ObjectAPI/GetTag',
        request_serializer=client_dot_pfs_dot_pfs__pb2.Tag.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_wrappers__pb2.BytesValue.FromString,
        )
    self.InspectTag = channel.unary_unary(
        '/pfs.ObjectAPI/InspectTag',
        request_serializer=client_dot_pfs_dot_pfs__pb2.Tag.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.ObjectInfo.FromString,
        )
    self.ListTags = channel.unary_stream(
        '/pfs.ObjectAPI/ListTags',
        request_serializer=client_dot_pfs_dot_pfs__pb2.ListTagsRequest.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.ListTagsResponse.FromString,
        )
    self.DeleteTags = channel.unary_unary(
        '/pfs.ObjectAPI/DeleteTags',
        request_serializer=client_dot_pfs_dot_pfs__pb2.DeleteTagsRequest.SerializeToString,
        response_deserializer=client_dot_pfs_dot_pfs__pb2.DeleteTagsResponse.FromString,
        )
    self.Compact = channel.unary_unary(
        '/pfs.ObjectAPI/Compact',
        request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def delete_weight(self, object_name, weight_name):

    def delete_weight_fn(weights_dict, source_name, target_name=None):
        if weight_name not in weights_dict[source_name]:
            raise ValueError(f'Weight {weight_name} not found in object {object_name}. Weights found: {list(weights_dict[source_name].keys())}')
        weights_dict[source_name].pop(weight_name)
    self._edit_object(delete_weight_fn, object_name)

Removes a weight from an existing object.

Args:
object_name: String, name or path of the
object from which to remove the weight
(e.g. `"dense_2"` or `"layers/dense_2"`).
weight_name: String, name of the weight to
delete (e.g. `"0"`).


def get_ext(url):

    parsed = urllib.parse.urlparse(url)
    root, ext = os.path.splitext(parsed.path)
    return ext.lstrip('.')

Extract an extension from the url.

Args:
url (str): String representation of a url.

Returns:
str: Filename extension from a url (without a dot), '' if extension is not present.