def sheets_id(config, auth, url_or_name):
    if url_or_name.startswith('https:
        m = re.search('^(?:https:\\/\\/docs.google.com\\/spreadsheets\\/d\\/)?([a-zA-Z0-9-_]+)(?:\\/.*)?$', url_or_name)
        if m:
            return m.group(1)
    else:
        sheet = file_find(config, auth, url_or_name)
        if sheet:
            return sheet['id']
        else:
            m = re.search('^([a-zA-Z0-9-_]+)$', url_or_name)
            if m:
                return m.group(1)
    if config.verbose:
        print('SHEET DOES NOT EXIST', url_or_name)
    return None

Pull sheet id from URL, name, or id itself

Args:
config - see starthinker/util/configuration.py
auth - user or service
url_or_name - one of: URL, document title, or id

Returns:
String containing document id used by API calls.


def kill_raylet(self, check_alive=True):

        self._kill_process_type(
            ray_constants.PROCESS_TYPE_RAYLET, check_alive=check_alive)

Kill the raylet.

Args:
check_alive (bool): Raise an exception if the process was already
dead.


def get_vol_surface(currencies: List[str], equity_types: List[str], market: pmd.ProcessedMarketData, mask: List[int]) -> volatility_surface.VolatilitySurface:
    vols = market.volatility_surface(currencies, equity_types)
    expiries = vols.node_expiries().ordinal()
    strikes = vols.node_strikes()
    volatilities = vols.node_volatilities()
    prepare_strikes = tf.gather(strikes, mask)
    prepare_vols = tf.gather(volatilities, mask)
    prepare_expiries = dateslib.dates_from_ordinals(tf.gather(expiries, mask))
    vol_surface = volatility_surface.VolatilitySurface(valuation_date=market.date, expiries=prepare_expiries, strikes=prepare_strikes, volatilities=prepare_vols, daycount_convention=vols.daycount_convention)
    return vol_surface

Builds a batched volatility surface.

Given a list of discount curve an integer mask, creates a discount curve
object to compute discount factors against the list of discount curves.

#### Example
```none
currencies = ["USD", "GBP"]
equity_types = ["GOOG", "EZJ"]
# A mask to price a batch of 7 instruments with the corresponding discount
# curves ["GOOG", "EZJ", "EZJ", "EZJ" "GOOG", "GOOG"].
mask = [0, 1, 1, 1, 0, 0]
market = MarketDataDict(...)
get_vol_surface(currencies, equity_types, market, mask)
# Returns a VolatilitySurface object that can compute a volatilities for a
# batch of 6 expiry dates and strikes.
```

Args:
currencies: A list of underlying currencies.
equity_types: A corresponding list of equity types.
market: An instance of the processed market data.
mask: An integer mask.

Returns:
An instance of `VolatilitySurface`.


def set_page_artid(self, page_start=None, page_end=None, artid=None):

        if page_end and not page_start:
            raise ValueError('End_page provided without start_page')

        self._ensure_reference_field('publication_info', {})
        publication_info = self.obj['reference']['publication_info']
        if page_start:
            publication_info['page_start'] = page_start
        if page_end:
            publication_info['page_end'] = page_end
        if artid:
            publication_info['artid'] = artid

Add artid, start, end pages to publication info of a reference.

Args:
page_start(Optional[string]): value for the field page_start
page_end(Optional[string]): value for the field page_end
artid(Optional[string]): value for the field artid

Raises:
ValueError: when no start_page given for an end_page


def destroy_cloudwatch_log_event(app='', env='dev', region=''):
    session = boto3.Session(profile_name=env, region_name=region)
    cloudwatch_client = session.client('logs')
    cloudwatch_client.delete_subscription_filter(logGroupName='/aws/lambda/awslimitchecker', filterName=app)
    return True

Destroy Cloudwatch log event.

Args:
app (str): Spinnaker Application name.
env (str): Deployment environment.
region (str): AWS region.
Returns:
bool: True upon successful completion.


def _get_file_name_for_handle(handle):

    assert is_win
    assert handle != winapi.INVALID_HANDLE_VALUE

    size = winapi.FILE_NAME_INFO.FileName.offset + \
        winapi.MAX_PATH * ctypes.sizeof(winapi.WCHAR)
    buf = ctypes.create_string_buffer(size)

    if winapi.GetFileInformationByHandleEx is None:

        return None

    status = winapi.GetFileInformationByHandleEx(
        handle, winapi.FileNameInfo, buf, size)
    if status == 0:
        return None

    name_info = ctypes.cast(
        buf, ctypes.POINTER(winapi.FILE_NAME_INFO)).contents
    offset = winapi.FILE_NAME_INFO.FileName.offset
    data = buf[offset:offset + name_info.FileNameLength]
    return bytes2fsn(data, "utf-16-le")

(Windows only) Returns a file name for a file handle.

Args:
handle (winapi.HANDLE)
Returns:
`text` or `None` if no file name could be retrieved.


def filter_db_names(paths: List[str]) -> List[str]:

    return [
        db_path
        for db_path in paths
        if VERSION_RE.match(os.path.basename(db_path))
    ]

Returns a filtered list of `paths`, where every name matches our format.

Args:
paths: A list of file names.


def tokenize(self, char_input, max_len, by_char=False):

    if by_char:
      tokenized_list = [self._vocab_dict[token] for token in char_input]
    else:
      tokenized_list = []
      compound_token = ""
      for token in char_input:

        add_number = compound_token.isdigit() and not token.isdigit()
        add_word = compound_token.isalpha() and not token.isalpha()
        if add_number or add_word:
          tokenized_list.append(self._vocab_dict[compound_token])
          compound_token = ""

        if token.isdigit():
          compound_token += token
        elif token.isalpha():
          compound_token += token
        else:
          tokenized_list.append(self._vocab_dict[token])
      if compound_token:
        tokenized_list.append(self._vocab_dict[compound_token])

    seq_size = len(tokenized_list)
    if seq_size < max_len:
      padding = [self._vocab_dict[get_padding()]] * (max_len - seq_size)
      tokenized_list.extend(padding)
    elif seq_size > max_len:
      raise ValueError("Token sequence is too large: {}".format(
          len(tokenized_list)))

    return tokenized_list, seq_size

Produces the list of integer indices corresponding to a token list.

Args:
char_input: The character string to be tokenized.
max_len: Truncation length.
by_char: If true each character is a token - otherwise alpha-numeric
groupings are tokens.

Returns:
A padded list of string tokens and the true sequence length.

Raises:
ValueError: the token sequence is too long.


def _get_main_op_tensor(meta_graph_def_to_load, init_op_key=constants.MAIN_OP_KEY):
    collection_def = meta_graph_def_to_load.collection_def
    init_op = None
    if init_op_key in collection_def:
        init_op_list = collection_def[init_op_key].node_list.value
        if len(init_op_list) != 1:
            raise RuntimeError(f'Expected exactly one SavedModel init op. Found {len(init_op_list)}: {init_op_list}.')
        init_op = ops.get_collection(init_op_key)[0]
    return init_op

Gets the main op tensor, if one exists.

Args:
meta_graph_def_to_load: The meta graph def from the SavedModel to be loaded.
init_op_key: name of the collection to check; should be one of MAIN_OP_KEY
or the deprecated LEGACY_INIT_OP_KEY

Returns:
The main op tensor, if it exists and `None` otherwise.

Raises:
RuntimeError: If the collection def corresponding to the main op key has
other than exactly one tensor.


def get_feature_variable_string(self, feature_key, variable_key, user_id, attributes=None):

    variable_type = entities.Variable.Type.STRING
    return self._get_feature_variable_for_type(feature_key, variable_key, variable_type, user_id, attributes)

Returns value for a certain string variable attached to a feature.

Args:
feature_key: Key of the feature whose variable's value is being accessed.
variable_key: Key of the variable whose value is to be accessed.
user_id: ID for user.
attributes: Dict representing user attributes.

Returns:
String value of the variable. None if:
- Feature key is invalid.
- Variable key is invalid.
- Mismatch with type of variable.


def _to_camel_case(string):
    components = string.split('_')
    return ('%s%s' % (components[0], ''.join((c.title() for c in components[1:]))))

Return a camel cased version of the input string.

Args:
string (str): A snake cased string.

Returns:
str: A camel cased string.


def __init__(self, channel):

        self.ListSinks = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/ListSinks",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.ListSinksRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.ListSinksResponse.FromString,
        )
        self.GetSink = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/GetSink",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.GetSinkRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogSink.FromString,
        )
        self.CreateSink = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/CreateSink",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.CreateSinkRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogSink.FromString,
        )
        self.UpdateSink = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/UpdateSink",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.UpdateSinkRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogSink.FromString,
        )
        self.DeleteSink = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/DeleteSink",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.DeleteSinkRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
        self.ListExclusions = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/ListExclusions",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.ListExclusionsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.ListExclusionsResponse.FromString,
        )
        self.GetExclusion = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/GetExclusion",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.GetExclusionRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogExclusion.FromString,
        )
        self.CreateExclusion = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/CreateExclusion",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.CreateExclusionRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogExclusion.FromString,
        )
        self.UpdateExclusion = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/UpdateExclusion",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.UpdateExclusionRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.LogExclusion.FromString,
        )
        self.DeleteExclusion = channel.unary_unary(
            "/google.logging.v2.ConfigServiceV2/DeleteExclusion",
            request_serializer=google_dot_cloud_dot_logging__v2_dot_proto_dot_logging__config__pb2.DeleteExclusionRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def add_sample_tag_value(self, tag_name, new_sample_values):
    if (tag_name in self.format_tags):
        msg = 'New format value [{}] already exists.'.format(tag_name)
        raise KeyError(msg)
    if (not self._samples_match(new_sample_values)):
        raise KeyError('Sample name values must match existing sample names')
    for sample in self.sample_tag_values.keys():
        value = str(new_sample_values[sample])
        self.sample_tag_values[sample][tag_name] = value

Appends a new format tag-value for all samples.

Args:
tag_name: string tag name; must not already exist
new_sample

Raises:
KeyError: if tag_name to be added already exists


def connect(self, slot):
    self._ensure_slot_args(slot)
    if (not self.is_connected(slot)):
        self.slots.append(slot)

Connect ``slot`` to this singal.

Args:
slot (callable): Callable object wich accepts keyword arguments.

Raises:
InvalidSlot: If ``slot`` doesn't accept keyword arguments.


def _GetVSSStoreIdentifiers(self, scan_node):

    if not scan_node or not scan_node.path_spec:
      raise errors.ScannerError('Invalid scan node.')

    volume_system = vshadow_volume_system.VShadowVolumeSystem()
    volume_system.Open(scan_node.path_spec)

    volume_identifiers = self._source_scanner.GetVolumeIdentifiers(
        volume_system)
    if not volume_identifiers:
      return []

    if not self._mediator:
      raise errors.ScannerError(
          'Unable to proceed. VSS stores found but no mediator to determine '
          'how they should be used.')

    try:
      volume_identifiers = self._mediator.GetVSSStoreIdentifiers(
          volume_system, volume_identifiers)

    except KeyboardInterrupt:
      raise errors.UserAbort('File system scan aborted.')

    return self._NormalizedVolumeIdentifiers(
        volume_system, volume_identifiers, prefix='vss')

Determines the VSS store identifiers.

Args:
scan_node (SourceScanNode): scan node.

Returns:
list[str]: VSS store identifiers.

Raises:
ScannerError: if the format the scan node is invalid or no mediator
is provided and VSS store identifiers are found.
UserAbort: if the user requested to abort.


def calculate_bv_sum(site, nn_list, scale_factor=1.0):

    el1 = Element(site.specie.symbol)
    bvsum = 0
    for (nn, dist) in nn_list:
        el2 = Element(nn.specie.symbol)
        if (el1 in ELECTRONEG or el2 in ELECTRONEG) and el1 != el2:
            r1 = BV_PARAMS[el1]["r"]
            r2 = BV_PARAMS[el2]["r"]
            c1 = BV_PARAMS[el1]["c"]
            c2 = BV_PARAMS[el2]["c"]
            R = r1 + r2 - r1 * r2 * (sqrt(c1) - sqrt(c2)) ** 2 / \
                (c1 * r1 + c2 * r2)
            vij = exp((R - dist * scale_factor) / 0.31)
            bvsum += vij * (1 if el1.X < el2.X else -1)
    return bvsum

Calculates the BV sum of a site.

Args:
site:
The site
nn_list:
List of nearest neighbors in the format [(nn_site, dist), ...].
scale_factor:
A scale factor to be applied. This is useful for scaling distance,
esp in the case of calculation-relaxed structures which may tend
to under (GGA) or over bind (LDA).


def _process_datum(self, data, input_reader, ctx, transient_shard_state):

    if data is not input_readers.ALLOW_CHECKPOINT:
      self.slice_context.incr(context.COUNTER_MAPPER_CALLS)

      handler = transient_shard_state.handler

      if isinstance(handler, map_job.Mapper):
        handler(self.slice_context, data)
      else:
        if input_reader.expand_parameters:
          result = handler(*data)
        else:
          result = handler(data)

        if util.is_generator(result):
          for output in result:
            if isinstance(output, operation.Operation):
              output(ctx)
            else:
              output_writer = transient_shard_state.output_writer
              if not output_writer:
                logging.warning(
                    "Handler yielded %s, but no output writer is set.", output)
              else:
                output_writer.write(output)

    if self._time() - self._start_time >= parameters.config._SLICE_DURATION_SEC:
      return False
    return True

Process a single data piece.

Call mapper handler on the data.

Args:
data: a datum to process.
input_reader: input reader.
ctx: mapreduce context
transient_shard_state: transient shard state.

Returns:
True if scan should be continued, False if scan should be stopped.


def __init__(self, hyperparameter_tuning_job_name, sagemaker_session=None):

        sagemaker_session = sagemaker_session or Session()
        self._sage_client = sagemaker_session.sagemaker_client
        self._tuning_job_name = hyperparameter_tuning_job_name
        self.clear_cache()

Initialize a ``HyperparameterTuningJobAnalytics`` instance.

Args:
hyperparameter_tuning_job_name (str): name of the HyperparameterTuningJob to analyze.
sagemaker_session (sagemaker.session.Session): Session object which manages interactions with
Amazon SageMaker APIs and any other AWS services needed. If not specified, one is created
using the default AWS configuration chain.


def get_book_metadata(self, asin):

    kbm = self._get_api_call('get_book_metadata', '"%s"' % asin)
    return KindleCloudReaderAPI._kbm_to_book(kbm)

Returns a book's metadata.

Args:
asin: The ASIN of the book to be queried.

Returns:
A `KindleBook` instance corresponding to the book associated with
`asin`.


def _useRPCConfig(self):
    return config_pb2.ConfigProto(rpc_options=rpc_options_pb2.RPCOptions(use_rpc_for_inprocess_master=True))

Return a `tf.compat.v1.ConfigProto` that ensures we use the RPC stack for tests.

This configuration ensures that we continue to exercise the gRPC
stack when testing, rather than using the in-process optimization,
which avoids using gRPC as the transport between a client and
master in the same process.

Returns:
A `tf.compat.v1.ConfigProto`.


def download(url: str, filename: str, skip_cert_verify: bool=True) -> None:
    log.info('Downloading from {} to {}', url, filename)
    ctx = ssl.create_default_context()
    if skip_cert_verify:
        log.debug(('Skipping SSL certificate check for ' + url))
        ctx.check_hostname = False
        ctx.verify_mode = ssl.CERT_NONE
    with urllib.request.urlopen(url, context=ctx) as u, open(filename, 'wb') as f:
        f.write(u.read())

Downloads a URL to a file.

Args:
url: URL to download from
filename: file to save to
skip_cert_verify: skip SSL certificate check?


def Deserialize(self, reader):

        super(UnspentCoinState, self).Deserialize(reader)

        blen = reader.ReadVarInt()
        self.Items = [0] * blen
        for i in range(0, blen):
            self.Items[i] = int.from_bytes(reader.ReadByte(do_ord=False), 'little')

Deserialize full object.

Args:
reader (neocore.IO.BinaryReader):


def sia(transition, direction=Direction.BIDIRECTIONAL):

    validate.direction(direction, allow_bi=True)
    log.info("Calculating big-alpha for %s...", transition)

    if not transition:
        log.info('Transition %s is empty; returning null SIA '
                 'immediately.', transition)
        return _null_ac_sia(transition, direction)

    if not connectivity.is_weak(transition.network.cm,
                                transition.node_indices):
        log.info('%s is not strongly/weakly connected; returning null SIA '
                 'immediately.', transition)
        return _null_ac_sia(transition, direction)

    log.debug("Finding unpartitioned account...")
    unpartitioned_account = account(transition, direction)
    log.debug("Found unpartitioned account.")

    if not unpartitioned_account:
        log.info('Empty unpartitioned account; returning null AC SIA '
                 'immediately.')
        return _null_ac_sia(transition, direction)

    cuts = _get_cuts(transition, direction)
    engine = ComputeACSystemIrreducibility(
        cuts, transition, direction, unpartitioned_account)
    result = engine.run_sequential()
    log.info("Finished calculating big-ac-phi data for %s.", transition)
    log.debug("RESULT: \n%s", result)
    return result

Return the minimal information partition of a transition in a specific
direction.

Args:
transition (Transition): The candidate system.

Returns:
AcSystemIrreducibilityAnalysis: A nested structure containing all the
data from the intermediate calculations. The top level contains the
basic irreducibility information for the given subsystem.


def add_common_arguments(self, parser, has_device=False):
    if has_device:
        parser.add_argument('-t', '--tif', required=True, type=str.lower, choices=['jtag', 'swd'], help='target interface (JTAG | SWD)')
        parser.add_argument('-d', '--device', required=True, help='specify the target device name')
    group = parser.add_mutually_exclusive_group(required=False)
    group.add_argument('-s', '--serial', dest='serial_no', help='specify the J-Link serial number')
    group.add_argument('-i', '--ip_addr', dest='ip_addr', help='J-Link IP address')
    return None

Adds common arguments to the given parser.

Common arguments for a J-Link command are the target interface, and
J-Link serial number or IP address.

Args:
self (Command): the ``Command`` instance
parser (argparse.ArgumentParser): the parser to add the arguments to
has_device (bool): boolean indicating if it has the device argument

Returns:
``None``


def enable_broadcasting(self):
    if (self._broadcast_reports is not None):
        _clear_queue(self._broadcast_reports)
        return self._broadcast_reports
    self._broadcast_reports = queue.Queue()
    return self._broadcast_reports

Begin accumulating broadcast reports received from all devices.

This method will allocate a queue to receive broadcast reports that
will be filled asynchronously as broadcast reports are received.

Returns:
queue.Queue: A queue that will be filled with braodcast reports.


def _add_trackable_child(self, name, value):
    self._track_trackable(value, name, overwrite=True)

Restores a connection between trackables when loading from SavedModel.

SavedModel stores both the object metadata and its list of children. When
loading, this function is used along with `_deserialize_from_proto` to load
objects from the SavedModel: First, all saved objects are created with
`_deserialize_from_proto`. After that is complete, the children are
connected using `_add_trackable_child`.

**Example**

`tf.Module`, `tf.keras.Model` and Keras layers use `__setattr__` to track
children. This is why users can call `model.v = tf.Variable(...)`, and the
variable will be automatically saved to the checkpoint. The implementation
of this method for the listed objects is:

```
def _add_trackable_child(self, name, value):
self.__setattr__(name, value)
```

Args:
name: The name of the connection between the parent and child `Trackable`.
value: The child `Trackable` object.


def segments(seg_type=None):
    for index in xrange(idaapi.get_segm_qty()):
        seg = Segment(index=index)
        if ((seg_type is None) or (seg.type == seg_type)):
            (yield Segment(index=index))

Iterate segments based on type

Args:
seg_type: type of segment e.g. SEG_CODE

Returns:
iterator of `Segment` objects. if seg_type is None , returns all segments
otherwise returns only the relevant ones


def valid_content_type(self, content_type, accept):
    accept_tokens = accept.replace(' ', '').split(';')
    content_type_tokens = content_type.replace(' ', '').split(';')
    return (all(((elem in content_type_tokens) for elem in accept_tokens)) and ((content_type_tokens[0] == 'application/vnd.oasis.taxii+json') or (content_type_tokens[0] == 'application/vnd.oasis.stix+json')))

Check that the server is returning a valid Content-Type

Args:
content_type (str): ``Content-Type:`` header value
accept (str): media type to include in the ``Accept:`` header.


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

        url = self.base_url
        return self.post_url(url, data, **kwargs)

Create Virtual Account from given dict

Args:
Param for Creating Virtual Account

Returns:
Virtual Account dict


def parse(desktop_file_or_string):

	if os.path.isfile(desktop_file_or_string):
		with open(desktop_file_or_string) as f:
			desktop_file = f.read()

	else:
		desktop_file = desktop_file_or_string

	result = {}

	for line in desktop_file.split('\n'):
		if '=' in line:
			result[line.split('=')[0]] = line.split('=')[1]

	for key, value in result.items():
		if value == 'false':
			result[key] = False
		elif value == 'true':
			result[key] = True

	if not 'Terminal' in result:
		result['Terminal'] = False

	if not 'Hidden' in result:
		result['Hidden'] = False

	return result

Parse a .desktop file.
Parse a .desktop file or a string with its contents into an easy-to-use dict, with standard values present even if not defined in file.
Args:
desktop_file_or_string (str): Either the path to a .desktop file or a string with a .desktop file as its contents.
Returns:
dict: A dictionary of the parsed file.


def top_k(x, reduced_dim, new_dim, dtype=tf.int32, name=None):
    reduced_dim = convert_to_dimension(reduced_dim)
    new_dim = convert_to_dimension(new_dim)
    indices = []
    values = []
    k = new_dim.size
    with tf.name_scope(name, default_name='top_k'):
        for i in xrange(k):
            (max_index, max_val) = top_1(x, reduced_dim, dtype)
            indices.append(max_index)
            values.append(max_val)
            if ((i + 1) < k):
                x += one_hot(max_index, reduced_dim, on_value=(- 1000000000.0), dtype=x.dtype)
    axis = x.shape.dims.index(reduced_dim)
    return (stack(indices, new_dim.name, axis), stack(values, new_dim.name, axis))

Like tf.top_k.

This operation returns two tensors with the same shape.  The output shape
is identical to the shape of x, except that reduced_dim is replaced by
new_dim.

Args:
x: a Tensor
reduced_dim: a Dimension in x.shape.dims.
new_dim: a Dimension.  The size determines k.
dtype: optional dtype for indices.
name: optional string.
Returns:
indices: a Tensor with given dtype.
values: a Tensor with same type as x.


def import_gssapi_extension(name):

    try:
        path = 'gssapi.raw.ext_{0}'.format(name)
        __import__(path)
        return sys.modules[path]
    except ImportError:
        return None

Import a GSSAPI extension module

This method imports a GSSAPI extension module based
on the name of the extension (not including the
'ext_' prefix).  If the extension is not available,
the method retuns None.

Args:
name (str): the name of the extension

Returns:
module: Either the extension module or None


def encode(self, s):

    return [int(w) + self._num_reserved_ids for w in s.split()]

Transform a human-readable string into a sequence of int ids.

The ids should be in the range [num_reserved_ids, vocab_size). Ids [0,
num_reserved_ids) are reserved.

EOS is not appended.

Args:
s: human-readable string to be converted.

Returns:
ids: list of integers


def columns_exist(inspect_dataset):
    if (not hasattr(inspect_dataset, 'columns')):
        warnings.warn('No columns list found in dataset; no autoinspection performed.')
        return
    elif isinstance(inspect_dataset.columns[0], string_types):
        columns = inspect_dataset.columns
    elif (isinstance(inspect_dataset.columns[0], dict) and ('name' in inspect_dataset.columns[0])):
        columns = [col['name'] for col in inspect_dataset.columns]
    else:
        raise AutoInspectError('Unable to determine column names for this dataset.')
    create_multiple_expectations(inspect_dataset, columns, 'expect_column_to_exist')

This function will take a dataset and add expectations that each column present exists.

Args:
inspect_dataset (great_expectations.dataset): The dataset to inspect and to which to add expectations.


def from_backbone_configs(cls, backbone_config: PretrainedConfig, **kwargs):
    return cls(backbone_config=backbone_config, **kwargs)

Instantiate a [`RTDetrV2Config`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.

Args:
backbone_config ([`PretrainedConfig`]):
The backbone configuration.

Returns:
[`RTDetrV2Config`]: An instance of a configuration object


def __call__(self, obj, **cfg):

        depth = self.config.depth or 0
        seen_on_path = self.config.seen_on_path or frozenset()
        cfg.setdefault('depth', depth + 1)
        cfg['seen_on_path'] = seen_on_path | {id(obj)}
        h = self.with_config(cfg)
        max_depth = h.config.max_depth

        if h.config.preprocess:
            obj = h.config.preprocess(obj, hrepr)

        if id(obj) in seen_on_path:

            result = self.H.span['hrepr-circular']('⥁')
        elif max_depth is not None and depth >= max_depth:
            result = h._hrepr(obj, self.type_handlers_short,
                              ['__hrepr_short__'], self.stdrepr_short)
        else:
            result = h._hrepr(obj, self.type_handlers,
                              ['__hrepr__', '__hrepr_short__'],
                              self.stdrepr)

        if h.config.postprocess:
            return h.config.postprocess(obj, result, h.H, h) or result
        else:
            return result

Return the HTML representation of an object.

Args:
obj: The object to represent
cfg: Configuration to add to the current
configuration for this operation.

Returns:
The representation of the object.


def sd(series):
    if np.issubdtype(series.dtype, np.number):
        return series.std()
    else:
        return np.nan

Returns the standard deviation of values in a series.

Args:
series (pandas.Series): column to summarize.


def get_tensor_device(self, tensor_name):

    tensor = self._name_to_tensor(tensor_name)
    if isinstance(tensor, tf.Tensor):
      return tensor.device
    else:
      return None

The device of a tensor.

Note that only tf tensors have device assignments.

Args:
tensor_name: a string, name of a tensor in the graph.

Returns:
a string or None, representing the device name.


def _print_test_names(test_class):
    cls = test_class(config_parser.TestRunConfig())
    test_names = []
    try:
        cls._pre_run()
        if cls.tests:
            test_names = list(cls.tests)
        else:
            test_names = cls.get_existing_test_names()
    except Exception:
        logging.exception('Failed to retrieve generated tests.')
    finally:
        cls._clean_up()
    print('==========> %s <==========' % cls.TAG)
    for name in test_names:
        print(name)

Prints the names of all the tests in a test module.

If the module has generated tests defined based on controller info, this
may not be able to print the generated tests.

Args:
test_class: module, the test module to print names from.


def MakeCdfFromPmf(pmf, name=None):

    if name == None:
        name = pmf.name
    return MakeCdfFromItems(pmf.Items(), name)

Makes a CDF from a Pmf object.

Args:
pmf: Pmf.Pmf object
name: string name for the data.

Returns:
Cdf object


def cached_name_scope(name, top_level=True):
    if (not top_level):
        current_ns = tf.get_default_graph().get_name_scope()
        if current_ns:
            name = ((current_ns + '/') + name)
    ns = _get_cached_ns(name)
    with tf.name_scope(ns):
        (yield ns)

Return a context which either opens and caches a new name scope,
or reenter an existing one.

Args:
top_level(bool): if True, the name scope will always be top-level.
It will not be nested under any existing name scope of the caller.


def get_contract_from_name(self, contract_name):

        return next((c for c in self.contracts if c.name == contract_name), None)

Return a contract from a name
Args:
contract_name (str): name of the contract
Returns:
Contract


def make_keyed_tensor_model_fn(model_fn: str) -> KeyedTensorInferenceFn:

    def attr_fn(batch: Sequence[dict[str, torch.Tensor]], model: torch.nn.Module, device: str, inference_args: Optional[dict[str, Any]]=None, model_id: Optional[str]=None) -> Iterable[PredictionResult]:
        key_to_tensor_list = defaultdict(list)
        with torch.no_grad():
            for example in batch:
                for key, tensor in example.items():
                    key_to_tensor_list[key].append(tensor)
            key_to_batched_tensors = {}
            for key in key_to_tensor_list:
                batched_tensors = torch.stack(key_to_tensor_list[key])
                batched_tensors = _convert_to_device(batched_tensors, device)
                key_to_batched_tensors[key] = batched_tensors
            pred_fn = getattr(model, model_fn)
            predictions = pred_fn(**key_to_batched_tensors, **inference_args)
        return utils._convert_to_result(batch, predictions, model_id)
    return attr_fn

Produces a KeyedTensorInferenceFn that uses a method of the model other that
the forward() method.

Args:
model_fn: A string name of the method to be used. This is accessed through
getattr(model, model_fn)


async def get_run_output(self, pipeline_uuid: str, example_filepath: str) -> str:
    self._verify_pipeline_uuid(pipeline_uuid)
    request = api_pb2.GetRunOutputRequest(pipeline_uuid=pipeline_uuid)
    response = await self._stub.GetRunOutput(request, **self._kwargs)
    if response.output == '':
        logging.info('Run output for %s is empty', example_filepath)
    return response.output

Get the result of pipeline execution.

Args:
pipeline_uuid: uuid of the pipeline
example_filepath: path to the file of the example

Returns:
output: contain the result of pipeline execution


def _generate_key_map(entity_list, key, entity_class):
    key_map = {}
    for obj in entity_list:
        key_map[obj[key]] = entity_class(**obj)
    return key_map

Helper method to generate map from key to entity object for given list of dicts.

Args:
entity_list: List consisting of dict.
key: Key in each dict which will be key in the map.
entity_class: Class representing the entity.

Returns:
Map mapping key to entity object.


def make_color_wheel(bins=None):
    if (bins is None):
        bins = [15, 6, 4, 11, 13, 6]
    assert (len(bins) == 6)
    (RY, YG, GC, CB, BM, MR) = tuple(bins)
    ry = [1, (np.arange(RY) / RY), 0]
    yg = [(1 - (np.arange(YG) / YG)), 1, 0]
    gc = [0, 1, (np.arange(GC) / GC)]
    cb = [0, (1 - (np.arange(CB) / CB)), 1]
    bm = [(np.arange(BM) / BM), 0, 1]
    mr = [1, 0, (1 - (np.arange(MR) / MR))]
    num_bins = (((((RY + YG) + GC) + CB) + BM) + MR)
    color_wheel = np.zeros((3, num_bins), dtype=np.float32)
    col = 0
    for (i, color) in enumerate([ry, yg, gc, cb, bm, mr]):
        for j in range(3):
            color_wheel[(j, col:(col + bins[i]))] = color[j]
        col += bins[i]
    return color_wheel.T

Build a color wheel.

Args:
bins(list or tuple, optional): Specify the number of bins for each
color range, corresponding to six ranges: red -> yellow,
yellow -> green, green -> cyan, cyan -> blue, blue -> magenta,
magenta -> red. [15, 6, 4, 11, 13, 6] is used for default
(see Middlebury).

Returns:
ndarray: Color wheel of shape (total_bins, 3).


def add_symbol(self, symbol_name, namespace_stack, node, module):

        if namespace_stack:

            last_namespace = self.namespaces
            for namespace in namespace_stack:
                last_namespace = last_namespace.setdefault(namespace, {})
        else:
            last_namespace = self.namespaces[None]
        return self._add(symbol_name, last_namespace, node, module)

Adds symbol_name defined in namespace_stack to the symbol table.

Args:
symbol_name: 'name of the symbol to lookup'
namespace_stack: None or ['namespaces', 'symbol', 'defined', 'in']
node: ast.Node that defines this symbol
module: module (any object) this symbol is defined in

Returns:
bool(if symbol was *not* already present)


def random_normal(shape, mean=0.0, stddev=1.0, dtype=dtypes.float32, seed=None):
    dtype = dtypes.as_dtype(dtype)
    with ops.name_scope('random_normal'):
        samples = random_ops.random_normal(shape, mean=mean, stddev=stddev, dtype=dtype.real_dtype, seed=seed)
        if dtype.is_complex:
            if seed is not None:
                seed += 1234
            more_samples = random_ops.random_normal(shape, mean=mean, stddev=stddev, dtype=dtype.real_dtype, seed=seed)
            samples = math_ops.complex(samples, more_samples)
        return samples

Tensor with (possibly complex) Gaussian entries.

Samples are distributed like

```
N(mean, stddev^2), if dtype is real,
X + iY,  where X, Y ~ N(mean, stddev^2) if dtype is complex.
```

Args:
shape:  `TensorShape` or Python list.  Shape of the returned tensor.
mean:  `Tensor` giving mean of normal to sample from.
stddev:  `Tensor` giving stdev of normal to sample from.
dtype:  `TensorFlow` `dtype` or numpy dtype
seed:  Python integer seed for the RNG.

Returns:
`Tensor` with desired shape and dtype.


def _set_request_cache_if_django_cache_hit(key, django_cached_response):

        if django_cached_response.is_found:
            DEFAULT_REQUEST_CACHE.set(key, django_cached_response.value)

Sets the value in the request cache if the django cached response was a hit.

Args:
key (string)
django_cached_response (CachedResponse)


def parse_mip_analysis(mip_config_raw: dict, qcmetrics_raw: dict, sampleinfo_raw: dict) -> dict:
    outdata = _define_output_dict()
    _config(mip_config_raw, outdata)
    _qc_metrics(outdata, qcmetrics_raw)
    _qc_sample_info(outdata, sampleinfo_raw)
    return outdata

Parse the output analysis files from MIP for adding info
to trend database

Args:
mip_config_raw (dict): raw YAML input from MIP analysis config file
qcmetrics_raw (dict): raw YAML input from MIP analysis qc metric file
sampleinfo_raw (dict): raw YAML input from MIP analysis qc sample info file
Returns:
dict: parsed data


def _determine_case(was_upper, words, string):
    case_type = 'unknown'
    if was_upper:
        case_type = 'upper'
    elif string.islower():
        case_type = 'lower'
    elif (len(words) > 0):
        camel_case = words[0].islower()
        pascal_case = (words[0].istitle() or words[0].isupper())
        if (camel_case or pascal_case):
            for word in words[1:]:
                c = (word.istitle() or word.isupper())
                camel_case &= c
                pascal_case &= c
                if (not c):
                    break
        if camel_case:
            case_type = 'camel'
        elif pascal_case:
            case_type = 'pascal'
        else:
            case_type = 'mixed'
    return case_type

Determine case type of string.

Arguments:
was_upper {[type]} -- [description]
words {[type]} -- [description]
string {[type]} -- [description]

Returns:
- upper: All words are upper-case.
- lower: All words are lower-case.
- pascal: All words are title-case or upper-case. Note that the
stringiable may still have separators.
- camel: First word is lower-case, the rest are title-case or
upper-case. stringiable may still have separators.
- mixed: Any other mixing of word casing. Never occurs if there are
no separators.
- unknown: stringiable contains no words.


def _ReduceParserFilters(cls, includes, excludes):

    if not includes or not excludes:
      return

    for parser_name in set(includes).intersection(excludes):

      if includes[parser_name] == excludes[parser_name]:
        logger.warning(
            'Parser {0:s} was in both the inclusion and exclusion lists. '
            'Ignoring included parser.'.format(parser_name))
        includes.pop(parser_name)
        continue

      plugin_includes = includes[parser_name]
      plugin_excludes = excludes[parser_name]
      intersection = set(plugin_includes).intersection(plugin_excludes)
      if not intersection:
        continue

      logger.warning(
          'Parser {0:s} plugins: {1:s} in both the inclusion and exclusion '
          'lists. Ignoring included plugins.'.format(
              parser_name, ', '.join(intersection)))
      plugins_list = list(set(plugin_includes).difference(intersection))
      includes[parser_name] = plugins_list

    parsers_to_pop = []
    for parser_name in excludes:
      if parser_name in includes:
        continue

      logger.warning(
          'The excluded parser: {0:s} is not associated with the included '
          'parsers: {1:s}. Ignoring excluded parser.'.format(
              parser_name, ', '.join(includes.keys())))
      parsers_to_pop.append(parser_name)

    for parser_name in parsers_to_pop:
      excludes.pop(parser_name)

Reduces the parsers and plugins to include and exclude.

If an intersection is found, the parser or plugin is removed from
the inclusion set. If a parser is not in inclusion set there is no need
to have it in the exclusion set.

Args:
includes (dict[str, BaseParser]): included parsers and plugins by name.
excludes (dict[str, BaseParser]): excluded parsers and plugins by name.


def forward(self, spectrogram: torch.FloatTensor, global_conditioning: Optional[torch.FloatTensor]=None) -> torch.FloatTensor:
    hidden_states = self.conv_pre(spectrogram)
    if global_conditioning is not None:
        hidden_states = hidden_states + self.cond(global_conditioning)
    for i in range(self.num_upsamples):
        hidden_states = nn.functional.leaky_relu(hidden_states, self.config.leaky_relu_slope)
        hidden_states = self.upsampler[i](hidden_states)
        res_state = self.resblocks[i * self.num_kernels](hidden_states)
        for j in range(1, self.num_kernels):
            res_state += self.resblocks[i * self.num_kernels + j](hidden_states)
        hidden_states = res_state / self.num_kernels
    hidden_states = nn.functional.leaky_relu(hidden_states)
    hidden_states = self.conv_post(hidden_states)
    waveform = torch.tanh(hidden_states)
    return waveform

Converts a spectrogram into a speech waveform.

Args:
spectrogram (`torch.FloatTensor` of shape `(batch_size, config.spectrogram_bins, sequence_length)`):
Tensor containing the spectrograms.
global_conditioning (`torch.FloatTensor` of shape `(batch_size, config.speaker_embedding_size, 1)`, *optional*):
Tensor containing speaker embeddings, for multispeaker models.

Returns:
`torch.FloatTensor`: Tensor of shape shape `(batch_size, 1, num_frames)` containing the speech waveform.


def _args_to_val(func, args):

  from .google_imports import gql
  vals = []
  for arg in args:
    if isinstance(arg, (int, long, basestring)):
      val = Parameter(arg)
    elif isinstance(arg, gql.Literal):
      val = arg.Get()
    else:
      raise TypeError('Unexpected arg (%r)' % arg)
    vals.append(val)
  if func == 'nop':
    if len(vals) != 1:
      raise TypeError('"nop" requires exactly one value')
    return vals[0]
  pfunc = ParameterizedFunction(func, vals)
  if pfunc.is_parameterized():
    return pfunc
  else:
    return pfunc.resolve({}, {})

Helper for GQL parsing to extract values from GQL expressions.

This can extract the value from a GQL literal, return a Parameter
for a GQL bound parameter (:1 or :foo), and interprets casts like
KEY(...) and plain lists of values like (1, 2, 3).

Args:
func: A string indicating what kind of thing this is.
args: One or more GQL values, each integer, string, or GQL literal.


def SendCommand(self, command, arg=None):

        if arg is not None:
            if not isinstance(arg, bytes):
                arg = arg.encode('utf8')
            command = b'%s:%s' % (command, arg)

        self._Write(io.BytesIO(command), len(command))

Sends a command to the device.

Args:
command: The command to send.
arg: Optional argument to the command.


def _add_sync_queues_and_barrier(self, name, dependencies):
    self._sync_queue_counter += 1
    with tf.device(self.sync_queue_devices[(self._sync_queue_counter % len(self.sync_queue_devices))]):
        sync_queues = [tf.FIFOQueue(self.num_worker, [tf.bool], shapes=[[]], shared_name=('%s%s' % (name, i))) for i in range(self.num_worker)]
        queue_ops = []
        token = tf.constant(False)
        with tf.control_dependencies(dependencies):
            for (i, q) in enumerate(sync_queues):
                if (i != self.task_index):
                    queue_ops.append(q.enqueue(token))
        queue_ops.append(sync_queues[self.task_index].dequeue_many((len(sync_queues) - 1)))
        return tf.group(*queue_ops, name=name)

Adds ops to enqueue on all worker queues.

Args:
name: prefixed for the shared_name of ops.
dependencies: control dependency from ops.

Returns:
an op that should be used as control dependency before starting next step.


async def Append(self, stream) -> None:
    from .grpc.admin_pb2 import AppendRequest, AppendResponse, ERROR_RESPONSE
    request: AppendRequest = (await stream.recv_message())
    mailbox = (request.mailbox or 'INBOX')
    flag_set = frozenset((Flag(flag) for flag in request.flags))
    when = datetime.fromtimestamp(request.when, timezone.utc)
    append_msg = AppendMessage(request.data, flag_set, when, ExtensionOptions.empty())
    try:
        session = (await self._login_as(request.user))
        if (self._with_filter and (session.filter_set is not None)):
            filter_value = (await session.filter_set.get_active())
            if (filter_value is not None):
                filter_ = (await session.filter_set.compile(filter_value))
                (new_mailbox, append_msg) = (await filter_.apply(request.sender, request.recipient, mailbox, append_msg))
                if (new_mailbox is None):
                    (await stream.send_message(AppendResponse()))
                    return
                else:
                    mailbox = new_mailbox
        (append_uid, _) = (await session.append_messages(mailbox, [append_msg]))
    except ResponseError as exc:
        resp = AppendResponse(result=ERROR_RESPONSE, error_type=type(exc).__name__, error_response=bytes(exc.get_response(b'.')), mailbox=mailbox)
        (await stream.send_message(resp))
    else:
        validity = append_uid.validity
        uid = next(iter(append_uid.uids))
        resp = AppendResponse(mailbox=mailbox, validity=validity, uid=uid)
        (await stream.send_message(resp))

Append a message directly to a user's mailbox.

If the backend session defines a
:attr:`~pymap.interfaces.session.SessionInterface.filter_set`, the
active filter implementation will be applied to the appended message,
such that the message may be discarded, modified, or placed into a
specific mailbox.

For example, using the CLI client::

$ cat message.txt | pymap-admin append user@example.com

See ``pymap-admin append --help`` for more options.

Args:
stream (:class:`~grpclib.server.Stream`): The stream for the
request and response.


def zero(duration: int, name: str=None) -> SamplePulse:
    return _sampled_zero_pulse(duration, name=name)

Generates zero-sampled `SamplePulse`.

Args:
duration: Duration of pulse. Must be greater than zero.
name: Name of pulse.


def django_cache_function(timeout: int=(5 * 60), cache_key: str='', debug_cache: bool=False):
    cache_key = (cache_key or None)

    def decorator(fn):

        def wrapper(*args, **kwargs):
            if cache_key:
                call_sig = ''
                _cache_key = cache_key
                check_stored_call_sig = False
            else:
                call_sig = get_call_signature(fn, args, kwargs)
                _cache_key = make_cache_key(call_sig)
                check_stored_call_sig = True
            if debug_cache:
                log.critical(('Checking cache for key: ' + _cache_key))
            cache_result_tuple = cache.get(_cache_key)
            if (cache_result_tuple is None):
                if debug_cache:
                    log.debug('Cache miss')
            else:
                if debug_cache:
                    log.debug('Cache hit')
                (cached_call_sig, func_result) = cache_result_tuple
                if ((not check_stored_call_sig) or (cached_call_sig == call_sig)):
                    return func_result
                log.warning('... Cache hit was due to hash collision; cached_call_sig {} != call_sig {}'.format(repr(cached_call_sig), repr(call_sig)))
            func_result = fn(*args, **kwargs)
            cache_result_tuple = (call_sig, func_result)
            cache.set(key=_cache_key, value=cache_result_tuple, timeout=timeout)
            return func_result
        return wrapper
    return decorator

Decorator to add caching to a function in Django.
Uses the Django default cache.

Args:

timeout: timeout in seconds; use None for "never expire", as 0 means
"do not cache".

cache_key: optional cache key to use (if falsy, we'll invent one)
debug_cache: show hits/misses?


def _qInstallMessageHandler(handler):

    def messageOutputHandler(*args):

        if len(args) == 3:
            msgType, logContext, msg = args
        elif len(args) == 2:
            msgType, msg = args
            logContext = None
        else:
            raise TypeError(
                "handler expected 2 or 3 arguments, got {0}".format(len(args)))

        if isinstance(msg, bytes):

            msg = msg.decode()

        handler(msgType, logContext, msg)

    passObject = messageOutputHandler if handler else handler
    if Qt.IsPySide or Qt.IsPyQt4:
        return Qt._QtCore.qInstallMsgHandler(passObject)
    elif Qt.IsPySide2 or Qt.IsPyQt5:
        return Qt._QtCore.qInstallMessageHandler(passObject)

Install a message handler that works in all bindings

Args:
handler: A function that takes 3 arguments, or None


def number_of_records_per_hour(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 `number_of_records_per_hour`'.format(value))

        self._number_of_records_per_hour = value

Corresponds to IDD Field `number_of_records_per_hour`

Args:
value (int): value for IDD Field `number_of_records_per_hour`
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 parse_args(self, arglist=None):

        args = self._parser.parse_args(args=arglist)
        sub_cmd = args.loam_sub_name
        if sub_cmd is None:
            for opt, sct in self._opt_bare.items():
                self._conf[sct][opt] = getattr(args, opt, None)
        else:
            for opt, sct in self._opt_cmds[sub_cmd].items():
                self._conf[sct][opt] = getattr(args, opt, None)
        return args

Parse arguments and update options accordingly.

Args:
arglist (list of str): list of arguments to parse. If set to None,
``sys.argv[1:]`` is used.

Returns:
:class:`Namespace`: the argument namespace returned by the
:class:`argparse.ArgumentParser`.


def __recognize_user_class(self, node: yaml.Node,
                               expected_type: Type) -> RecResult:

        logger.debug('Recognizing as a user-defined class')
        loc_str = '{}{}'.format(node.start_mark, os.linesep)
        if hasattr(expected_type, 'yatiml_recognize'):
            try:
                unode = UnknownNode(self, node)
                expected_type.yatiml_recognize(unode)
                return [expected_type], ''
            except RecognitionError as e:
                if len(e.args) > 0:
                    message = ('Error recognizing a {}\n{}because of the'
                               ' following error(s): {}').format(
                                   expected_type.__class__, loc_str,
                                   indent(e.args[0], '    '))
                else:
                    message = 'Error recognizing a {}\n{}'.format(
                        expected_type.__class__, loc_str)
                return [], message
        else:
            if issubclass(expected_type, enum.Enum):
                if (not isinstance(node, yaml.ScalarNode)
                        or node.tag != 'tag:yaml.org,2002:str'):
                    message = 'Expected an enum value from {}\n{}'.format(
                        expected_type.__class__, loc_str)
                    return [], message
            elif (issubclass(expected_type, UserString)
                  or issubclass(expected_type, str)):
                if (not isinstance(node, yaml.ScalarNode)
                        or node.tag != 'tag:yaml.org,2002:str'):
                    message = 'Expected a string matching {}\n{}'.format(
                        expected_type.__class__, loc_str)
                    return [], message
            else:

                if not isinstance(node, yaml.MappingNode):
                    message = 'Expected a dict/mapping here\n{}'.format(
                        loc_str)
                    return [], message

                for attr_name, type_, required in class_subobjects(
                        expected_type):
                    cnode = Node(node)

                    for name in [attr_name, attr_name.replace('_', '-')]:
                        if cnode.has_attribute(name):
                            subnode = cnode.get_attribute(name)
                            recognized_types, message = self.recognize(
                                subnode.yaml_node, type_)
                            if len(recognized_types) == 0:
                                message = ('Failed when checking attribute'
                                           ' {}:\n{}').format(
                                               name, indent(message, '    '))
                                return [], message
                            break
                    else:
                        if required:
                            message = (
                                'Error recognizing a {}\n{}because it'
                                ' is missing an attribute named {}').format(
                                    expected_type.__name__, loc_str, attr_name)
                            if '_' in attr_name:
                                message += ' or maybe {}.\n'.format(
                                    attr_name.replace('_', '-'))
                            else:
                                message += '.\n'
                            return [], message

            return [expected_type], ''

Recognize a user-defined class in the node.

This tries to recognize only exactly the specified class. It \
recurses down into the class's attributes, but not to its \
subclasses. See also __recognize_user_classes().

Args:
node: The node to recognize.
expected_type: A user-defined class.

Returns:
A list containing the user-defined class, or an empty list.


def subset(self, ns_uris):
    sub_ns = NamespaceSet()
    for ns_uri in ns_uris:
        ni = self.__lookup_uri(ns_uri)
        new_ni = copy.deepcopy(ni)
        sub_ns._NamespaceSet__add_namespaceinfo(new_ni)
    return sub_ns

Return a subset of this NamespaceSet containing only data for the
given namespaces.

Args:
ns_uris (iterable): An iterable of namespace URIs which select the
namespaces for the subset.

Returns:
The subset

Raises:
NamespaceNotFoundError: If any namespace URIs in `ns_uris` don't
match any namespaces in this set.


def compress_mean(x, dim, compression_factor):
    dims = x.shape.dims
    pos = dims.index(dim)
    compressed_dim = mtf.Dimension(dim.name, (dim.size
    compression_factor_dim = mtf.Dimension('compression_factor', compression_factor)
    new_shape = ((dims[:pos] + [compressed_dim, compression_factor_dim]) + dims[(pos + 1):])
    x = mtf.reshape(x, new_shape)
    x = mtf.reduce_mean(x, reduced_dim=compression_factor_dim)
    return x

Compress by taking group means.

Args:
x: a Tensor
dim: a dimension in x.shape
compression_factor: an integer

Returns:
a Tensor


def cidr(self, block, **kwargs):
    indicator_obj = CIDR(block, **kwargs)
    return self._indicator(indicator_obj)

Add CIDR data to Batch object.

Args:
block (str): The value for this Indicator.
confidence (str, kwargs): The threat confidence for this Indicator.
date_added (str, kwargs): The date timestamp the Indicator was created.
last_modified (str, kwargs): The date timestamp the Indicator was last modified.
rating (str, kwargs): The threat rating for this Indicator.
xid (str, kwargs): The external id for this Indicator.

Returns:
obj: An instance of CIDR.


def _check_module_is_text_embedding(module_spec):
    issues = []
    input_info_dict = module_spec.get_input_info_dict()
    if (len(input_info_dict) != 1):
        issues.append('Module default signature must require only one input')
    else:
        (input_info,) = input_info_dict.values()
        input_shape = input_info.get_shape()
        if (not ((input_info.dtype == tf.string) and (input_shape.ndims == 1) and (input_shape.as_list() == [None]))):
            issues.append('Module default signature must have only one input tf.Tensor(shape=(?,), dtype=string)')
    output_info_dict = module_spec.get_output_info_dict()
    if ('default' not in output_info_dict):
        issues.append("Module default signature must have a 'default' output.")
    else:
        output_info = output_info_dict['default']
        output_shape = output_info.get_shape()
        if (not ((output_info.dtype == tf.float32) and (output_shape.ndims == 2) and (not output_shape.as_list()[0]) and output_shape.as_list()[1])):
            issues.append("Module default signature must have a 'default' output of tf.Tensor(shape=(?,K), dtype=float32).")
    if issues:
        raise ValueError(('Module is not a text-embedding: %r' % issues))

Raises ValueError if `module_spec` is not a text-embedding module.

Args:
module_spec: A `ModuleSpec` to test.

Raises:
ValueError: if `module_spec` default signature is not compatible with
Tensor(string, shape=(?,)) -> Tensor(float32, shape=(?,K)).


def instantiate(config):
    for (handle, cfg) in list(config['apps'].items()):
        if (not cfg.get('enabled', True)):
            continue
        app = get_application(handle)
        instances[app.handle] = app(cfg)

instantiate all registered vodka applications

Args:
config (dict or MungeConfig): configuration object


def extract(self, text: str) -> List[Extraction]:

        content = BeautifulSoup(text, 'html5lib')
        subject = content.find('h1').text.strip()
        recip = self.mailing_list_name

        navbar = content.find(id='navbar')
        if navbar == None:
            info = self.old_format(content)
        else:
            info = self.new_format(navbar, content)
        for i in info[0:3]:
            if i == 'None':
                print('missed something important')
        sender = info[0]
        date   = info[1]
        body   = info[2]
        nxt    = info[3]
        rep_to = info[4]
        pub = 'SeeSat_Obs'
        dRec = datetime.datetime.now().isoformat()

        msg_obj = {
            'url' : self.email_url,
            '@context' : {
                '@vocab' : 'schema.org'
            },
            'subject' : subject,
            'recip' : recip,
            'sender' : sender
        }
        if date != 'None':
            msg_obj['dateReceived'] = date
        if body != 'None':
            msg_obj['body'] = body
        if nxt != 'None':
            msg_obj['nxt'] = nxt
        if rep_to != 'None':
            msg_obj['replyToMessage'] = rep_to
        return Extraction(value=msg_obj, extractor_name=self.name)

Extracts and structures email message from UTF8-encoded text
Args:
text: str

Returns: Extraction


def select_all(self, serial_numbers):
    sheet = self.table
    col = self.db_sheet_cols.id
    rows = sheet.loc[(:, col)].isin(serial_numbers)
    return sheet.loc[(rows, :)]

Select rows for identification for a list of serial_number.

Args:
serial_numbers: list (or ndarray) of serial numbers

Returns:
pandas.DataFrame


def cwt(ts, freqs=np.logspace(0, 2), wavelet=cwtmorlet, plot=True):
    orig_ndim = ts.ndim
    if (ts.ndim is 1):
        ts = ts[(:, np.newaxis)]
    channels = ts.shape[1]
    fs = ((len(ts) - 1.0) / ((1.0 * ts.tspan[(- 1)]) - ts.tspan[0]))
    x = signal.detrend(ts, axis=0)
    dtype = wavelet((fs / freqs[0]), (fs / freqs[0])).dtype
    coefs = np.zeros((len(ts), len(freqs), channels), dtype)
    for i in range(channels):
        coefs[(:, :, i)] = roughcwt(x[(:, i)], cwtmorlet, (fs / freqs)).T
    if plot:
        _plot_cwt(ts, coefs, freqs)
    if (orig_ndim is 1):
        coefs = coefs[(:, :, 0)]
    return coefs

Continuous wavelet transform
Note the full results can use a huge amount of memory at 64-bit precision

Args:
ts: Timeseries of m variables, shape (n, m). Assumed constant timestep.
freqs: list of frequencies (in Hz) to use for the tranform.
(default is 50 frequency bins logarithmic from 1Hz to 100Hz)
wavelet: the wavelet to use. may be complex. see scipy.signal.wavelets
plot: whether to plot time-resolved power spectrum

Returns:
coefs: Continuous wavelet transform output array, shape (n,len(freqs),m)


def build_query_string(self, data):

        query_params = []
        keys_to_be_removed = []
        for key, value in data.items():
            if key not in ['version', 'restApi', 'resourcePath']:
                if key == 'addressLine':
                    query_params.append('{0}={1}'.format(key,
                                                         quote(value)))
                    keys_to_be_removed.append(key)
                else:
                    query_params.append('{0}={1}'.format(key,
                                                         value))
                    keys_to_be_removed.append(key)
        data['query'] = "&".join(query_params)
        for k in keys_to_be_removed:
            del data[k]
        return data

This method occurs after dumping the data into the class.

Args:
data (dict): dictionary of all the query values

Returns:
data (dict): ordered dict of all the values


def next(self):
    options = {}
    if self._buffer_size:
        options['read_buffer_size'] = self._buffer_size
    if self._account_id:
        options['_account_id'] = self._account_id
    while True:
        filename = self._next_file()
        if (filename is None):
            raise StopIteration()
        try:
            start_time = time.time()
            handle = cloudstorage.open(filename, **options)
            ctx = context.get()
            if ctx:
                operation.counters.Increment(COUNTER_IO_READ_MSEC, int(((time.time() - start_time) * 1000)))(ctx)
            return handle
        except cloudstorage.NotFoundError:
            if getattr(self, '_fail_on_missing_input', False):
                raise errors.FailJobError(('File missing in GCS, aborting: %s' % filename))
            logging.warning('File %s may have been removed. Skipping file.', filename)

Returns the next input from this input reader, a block of bytes.

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

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

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


def _format_message(self, channel, text):

        payload = {'type': 'message', 'id': next(self._msg_ids)}
        payload.update(channel=channel, text=text)
        return json.dumps(payload)

Format an outgoing message for transmission.

Note:
Adds the message type (``'message'``) and incremental ID.

Arguments:
channel (:py:class:`str`): The channel to send to.
text (:py:class:`str`): The message text to send.

Returns:
:py:class:`str`: The JSON string of the message.


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

		if axis == 0:
			self.values = self.values[ordering, :]
		elif axis == 1:
			self.values = self.values[:, ordering]
		else:
			raise ValueError("axis must be 0 or 1")

Permute the layer along an axis

Args:
axis: The axis to permute (0, permute the rows; 1, permute the columns)
ordering: The permutation vector


def get_choices(field):
    empty_label = getattr(field.field, 'empty_label', False)
    needs_empty_value = False
    choices = []
    if hasattr(field.field, '_choices'):
        choices = field.field._choices
    elif hasattr(field.field, '_queryset'):
        queryset = field.field._queryset
        field_name = (getattr(field.field, 'to_field_name') or 'pk')
        choices += ((getattr(obj, field_name), str(obj)) for obj in queryset)
    if (choices and ((choices[0][1] == BLANK_CHOICE_DASH[0][1]) or choices[0][0])):
        needs_empty_value = True
        if (not choices[0][0]):
            del choices[0]
    if (empty_label == BLANK_CHOICE_DASH[0][1]):
        empty_label = None
    if (empty_label or (not field.field.required)):
        if needs_empty_value:
            choices.insert(0, ('', (empty_label or BLANK_CHOICE_DASH[0][1])))
    return choices

Find choices of a field, whether it has choices or has a queryset.

Args:
field (BoundField): Django form boundfield

Returns:
list: List of choices


def __init__(self, input_dataset, num_replicas):

    def recalculate_batch_size(type_spec):

        output_shape = type_spec._to_legacy_output_shapes()
        if not isinstance(output_shape, tensor_shape.TensorShape):
            return None
        if output_shape.rank is None:
            return None
        if len(output_shape) < 1:
            raise ValueError('Invalid `input_dataset`. Expected a dataset whose elements have rank >= 1 but found a dataset whose elements are scalars. Fix the issue by adding the `batch` transformation to the dataset.')
        output_dims = [d.value for d in output_shape.dims]
        if output_dims[0] is not None and output_dims[0] % num_replicas == 0:
            return output_dims[0]
        return None

    def rebatch(type_spec):
        batch_size = recalculate_batch_size(type_spec)
        return type_spec._unbatch()._batch(batch_size)
    self._element_spec = nest.map_structure(rebatch, dataset_ops.get_structure(input_dataset))
    input_dataset = dataset_ops.normalize_to_dense(input_dataset)
    variant_tensor = ged_ops.rebatch_dataset(input_dataset._variant_tensor, num_replicas=num_replicas, **self._flat_structure)
    super(_LegacyRebatchDataset, self).__init__(input_dataset, variant_tensor)

Creates a _LegacyRebatchDataset.

Args:
input_dataset: `Dataset` to rebatch.
num_replicas: A `tf.int64` scalar, representing the number of sub-batches
to split each batch from `input_dataset` into.


def body(time, elements_finished, current_input, emit_ta, state, loop_state):
    next_output, cell_state = cell(current_input, state)
    nest.assert_same_structure(state, cell_state)
    nest.assert_same_structure(cell.output_size, next_output)
    next_time = time + 1
    next_finished, next_input, next_state, emit_output, next_loop_state = loop_fn(next_time, next_output, cell_state, loop_state)
    nest.assert_same_structure(state, next_state)
    nest.assert_same_structure(current_input, next_input)
    nest.assert_same_structure(emit_ta, emit_output)
    loop_state = loop_state if next_loop_state is None else next_loop_state

    def _copy_some_through(current, candidate):

        def copy_fn(cur_i, cand_i):
            if isinstance(cur_i, tensor_array_ops.TensorArray):
                return cand_i
            if cur_i.shape.rank == 0:
                return cand_i
            with ops.colocate_with(cand_i):
                return array_ops.where(elements_finished, cur_i, cand_i)
        return nest.map_structure(copy_fn, current, candidate)
    emit_output = _copy_some_through(zero_emit, emit_output)
    next_state = _copy_some_through(state, next_state)
    emit_ta = nest.map_structure(lambda ta, emit: ta.write(time, emit), emit_ta, emit_output)
    elements_finished = math_ops.logical_or(elements_finished, next_finished)
    return (next_time, elements_finished, next_input, emit_ta, next_state, loop_state)

Internal while loop body for raw_rnn.

Args:
time: time scalar.
elements_finished: batch-size vector.
current_input: possibly nested tuple of input tensors.
emit_ta: possibly nested tuple of output TensorArrays.
state: possibly nested tuple of state tensors.
loop_state: possibly nested tuple of loop state tensors.

Returns:
Tuple having the same size as Args but with updated values.


def _init_func():
    ds_variant = gen_dataset_ops.unwrap_dataset_variant(wrap_ds_variant)
    resource = gen_dataset_ops.anonymous_iterator(**self._input_dataset._flat_structure)
    with ops.control_dependencies([gen_dataset_ops.make_iterator(ds_variant, resource)]):
        return gen_dataset_ops.iterator_to_string_handle(resource)

Creates an iterator for the input dataset.

Returns:
A `string` tensor that encapsulates the iterator created.


def traverse_preorder(self, leaves=True, internal=True):

        s = deque(); s.append(self)
        while len(s) != 0:
            n = s.pop()
            if (leaves and n.is_leaf()) or (internal and not n.is_leaf()):
                yield n
            s.extend(n.children)

Perform a preorder traversal starting at this ``Node`` object

Args:
``leaves`` (``bool``): ``True`` to include leaves, otherwise ``False``

``internal`` (``bool``): ``True`` to include internal nodes, otherwise ``False``


def write_representative_sequences_file(self, outname, outdir=None, set_ids_from_model=True):

        if not outdir:
            outdir = self.data_dir
            if not outdir:
                raise ValueError('Output directory must be specified')

        outfile = op.join(outdir, outname + '.faa')

        tmp = []
        for x in self.genes_with_a_representative_sequence:
            repseq = x.protein.representative_sequence
            copied_seq_record = copy(repseq)
            if set_ids_from_model:
                copied_seq_record.id = x.id
            tmp.append(copied_seq_record)

        SeqIO.write(tmp, outfile, "fasta")

        log.info('{}: wrote all representative sequences to file'.format(outfile))
        self.genome_path = outfile
        return self.genome_path

Write all the model's sequences as a single FASTA file. By default, sets IDs to model gene IDs.

Args:
outname (str): Name of the output FASTA file without the extension
outdir (str): Path to output directory of downloaded files, must be set if GEM-PRO directories
were not created initially
set_ids_from_model (bool): If the gene ID source should be the model gene IDs, not the original sequence ID


def LockRetryWrapper(self, subject, retrywrap_timeout=1, retrywrap_max_timeout=10, blocking=True, lease_time=None):
    timeout = 0
    while (timeout < retrywrap_max_timeout):
        try:
            return self.DBSubjectLock(subject, lease_time=lease_time)
        except DBSubjectLockError:
            if (not blocking):
                raise
            stats_collector_instance.Get().IncrementCounter('datastore_retries')
            time.sleep(retrywrap_timeout)
            timeout += retrywrap_timeout
    raise DBSubjectLockError('Retry number exceeded.')

Retry a DBSubjectLock until it succeeds.

Args:
subject: The subject which the lock applies to.
retrywrap_timeout: How long to wait before retrying the lock.
retrywrap_max_timeout: The maximum time to wait for a retry until we
raise.
blocking: If False, raise on first lock failure.
lease_time: lock lease time in seconds.

Returns:
The DBSubjectLock object

Raises:
DBSubjectLockError: If the maximum retry count has been reached.


def lower(self, lowering):

    old_shape = self.inputs[0].shape
    new_shape = self.outputs[0].shape
    mesh_impl = lowering.mesh_impl(self)
    slices = lowering.tensors[self.inputs[0]]
    mesh_axis_to_cumprod_old = mesh_impl.mesh_axis_to_cumprod(old_shape)
    mesh_axis_to_cumprod_new = mesh_impl.mesh_axis_to_cumprod(new_shape)

    mesh_axes_allsplit = []
    mesh_axes_allconcat = []
    mesh_axes_alltoall = []
    for mesh_axis, (old_cumprod, new_cumprod) in enumerate(
        zip(mesh_axis_to_cumprod_old, mesh_axis_to_cumprod_new)):
      if new_cumprod != old_cumprod:
        if old_cumprod is None:

          mesh_axes_allsplit.append(mesh_axis)
        elif new_cumprod is None:

          mesh_axes_allconcat.append(mesh_axis)
        else:

          mesh_axes_alltoall.append(mesh_axis)

    laid_out_size = mesh_impl.laid_out_size(old_shape)

    for mesh_axis in mesh_axes_allsplit:
      tensor_axis = old_shape.cumprod_to_tensor_axis(
          mesh_axis_to_cumprod_new[mesh_axis])
      if tensor_axis is None:

        raise NotImplementedError(
            "Try first reshaping to insert a new tf dimension,"
            " then changing layout. input_shape=%s output_shape=%s"
            % (self.inputs[0].shape, self.outputs[0].shape))
      slices = mesh_impl.allsplit(slices, mesh_axis, tensor_axis)
      laid_out_size
    for mesh_axis in mesh_axes_alltoall:
      split_tensor_axis = old_shape.cumprod_to_tensor_axis(
          mesh_axis_to_cumprod_new[mesh_axis])
      if split_tensor_axis is None:

        raise NotImplementedError(
            "Try first reshaping to insert a new tf dimension,"
            " then changing layout. input_shape=%s output_shape=%s"
            % (self.inputs[0].shape, self.outputs[0].shape))
      concat_tensor_axis = old_shape.cumprod_to_tensor_axis(
          mesh_axis_to_cumprod_old[mesh_axis])
      assert concat_tensor_axis is not None
      slices = mesh_impl.alltoall(
          slices, mesh_axis, split_tensor_axis, concat_tensor_axis)
      lowering.add_counter(
          "alltoall/%s/reshape_op" % mesh_axis, laid_out_size)

    for mesh_axis in mesh_axes_allconcat:
      tensor_axis = old_shape.cumprod_to_tensor_axis(
          mesh_axis_to_cumprod_old[mesh_axis])
      assert tensor_axis is not None
      slices = mesh_impl.allconcat(slices, mesh_axis, tensor_axis)
      laid_out_size *= mesh_impl.shape[mesh_axis].size
      lowering.add_counter(
          "allconcat/%s/reshape_op" % mesh_axis, laid_out_size)

    old_slice_shape = mesh_impl.slice_shape(old_shape)
    new_slice_shape = mesh_impl.slice_shape(new_shape)
    if new_slice_shape != old_slice_shape:
      def reshape_fn(x):
        return tf.reshape(x, new_slice_shape)
      slices = mesh_impl.slicewise(reshape_fn, slices)
    lowering.set_tensor_lowering(self.outputs[0], slices)

Lower the ReshapeOperation.

Reshaping can require collective communication between processors.
We haven't yet implemented all possible reshapes.  We try to handle the
common cases here - otherwise we raise a NotImplementedError.

Args:
lowering: a Lowering
Raises:
NotImplementedError: if we haven't covered this case


def new_body(name=None, pos=None, **kwargs):

    if name is not None:
        kwargs["name"] = name
    if pos is not None:
        kwargs["pos"] = array_to_string(pos)
    element = ET.Element("body", attrib=kwargs)
    return element

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

Args:
name (str): body name.
pos: 3d position of the body frame.


def update(self, rotate_worker_token=False, rotate_manager_token=False, **kwargs):
    if (kwargs.get('node_cert_expiry') is None):
        kwargs['node_cert_expiry'] = 7776000000000000
    return self.client.api.update_swarm(version=self.version, swarm_spec=self.client.api.create_swarm_spec(**kwargs), rotate_worker_token=rotate_worker_token, rotate_manager_token=rotate_manager_token)

Update the swarm's configuration.

It takes the same arguments as :py:meth:`init`, except
``advertise_addr``, ``listen_addr``, and ``force_new_cluster``. In
addition, it takes these arguments:

Args:
rotate_worker_token (bool): Rotate the worker join token. Default:
``False``.
rotate_manager_token (bool): Rotate the manager join token.
Default: ``False``.

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


def detached_sites( self, site_labels=None ):

        clusters = self.connected_sites( site_labels=site_labels )
        island_clusters = [ c for c in clusters if not any( c.is_periodically_contiguous() ) ]
        return list( itertools.chain.from_iterable( ( c.sites for c in island_clusters ) ) )

Returns all sites in the lattice (optionally from the set of sites with specific labels)
that are not part of a percolating network.
This is determined from clusters of connected sites that do not wrap round to
themselves through a periodic boundary.

Args:
site_labels (String or List(String)): Lables of sites to be considered.

Returns:
(List(Site)): List of sites not in a periodic percolating network.


def _open_tracing_interface(self, connection_id, callback):
    try:
        context = self.connections.get_context(connection_id)
    except ArgumentError:
        callback(connection_id, self.id, False, 'Could not find connection information')
        return
    self._logger.info('Attempting to enable tracing')
    self.connections.begin_operation(connection_id, 'open_interface', callback, self.get_config('default_timeout'))
    try:
        characteristic = context['services'][TileBusService][TracingChar]
    except KeyError:
        self.connections.finish_operation(connection_id, False, "Can't find characteristic to open tracing interface")
        return
    self._register_notification_callback(context['connection_handle'], characteristic.value_handle, (lambda trace_chunk: self._trigger_callback('on_trace', connection_id, bytearray(trace_chunk))))
    self.bable.set_notification(enabled=True, connection_handle=context['connection_handle'], characteristic=characteristic, on_notification_set=[self._on_interface_opened, context], on_notification_received=self._on_notification_received, timeout=1.0, sync=False)

Enable the tracing interface for this IOTile device

Args:
connection_id (int): The unique identifier for the connection
callback (callback): Callback to be called when this command finishes
callback(conn_id, adapter_id, success, failure_reason)


def update(self, settings):

        settings = self.clean(settings)

        self._settings.update(settings)

        self.set_settings(settings)

        return self._settings

Update object attributes from given settings

Args:
settings (dict): Dictionnary of elements to update settings.

Returns:
dict: Dictionnary of all current saved settings.


def rargmax(x, eps=1e-08):
    idxs = np.where((abs((x - np.max(x, axis=0))) < eps))[0]
    return np.random.choice(idxs)

Argmax with random tie-breaking

Args:
x: a 1-dim numpy array
Returns:
the argmax index


def stop(self):
    if (not self.is_started):
        raise ConnectionError('Client is already stopped')
    if self.takeout_id:
        self.send(functions.account.FinishTakeoutSession())
        log.warning('Takeout session {} finished'.format(self.takeout_id))
    Syncer.remove(self)
    self.dispatcher.stop()
    for _ in range(self.DOWNLOAD_WORKERS):
        self.download_queue.put(None)
    for i in self.download_workers_list:
        i.join()
    self.download_workers_list.clear()
    for _ in range(self.UPDATES_WORKERS):
        self.updates_queue.put(None)
    for i in self.updates_workers_list:
        i.join()
    self.updates_workers_list.clear()
    for i in self.media_sessions.values():
        i.stop()
    self.media_sessions.clear()
    self.is_started = False
    self.session.stop()
    return self

Use this method to manually stop the Client.
Requires no parameters.

Raises:
``ConnectionError`` in case you try to stop an already stopped Client.


def __send_ses_email(self, recipients, subject, body_html, body_text):

        source_arn = dbconfig.get('source_arn', NS_EMAIL)
        return_arn = dbconfig.get('return_path_arn', NS_EMAIL)

        session = get_local_aws_session()
        ses = session.client('ses', region_name=dbconfig.get('ses_region', NS_EMAIL, 'us-west-2'))

        body = {}
        if body_html:
            body['Html'] = {
                'Data': body_html
            }
        if body_text:
            body['Text'] = {
                'Data': body_text
            }

        ses_options = {
            'Source': self.sender,
            'Destination': {
                'ToAddresses': recipients
            },
            'Message': {
                'Subject': {
                    'Data': subject
                },
                'Body': body
            }
        }

        if source_arn and return_arn:
            ses_options.update({
                'SourceArn': source_arn,
                'ReturnPathArn': return_arn
            })

        ses.send_email(**ses_options)

Send an email using SES

Args:
recipients (`1ist` of `str`): List of recipient email addresses
subject (str): Subject of the email
body_html (str): HTML body of the email
body_text (str): Text body of the email

Returns:
`None`


def _calculate_aggregation_loss_unknown(logits_aggregation, aggregate_mask):
    dist_aggregation = torch.distributions.categorical.Categorical(logits=logits_aggregation)
    aggregation_ops_total_mass = torch.sum(dist_aggregation.probs[:, 1:], dim=1)
    return -torch.log(aggregation_ops_total_mass) * aggregate_mask

Calculates aggregation loss in the case of answer supervision.

Args:
logits_aggregation (`torch.FloatTensor` of shape `(batch_size, num_aggregation_labels)`):
Logits per aggregation operation.
aggregate_mask (`torch.FloatTensor` of shape `(batch_size, )`):
A mask set to 1 for examples that should use aggregation functions

Returns:
aggregation_loss_unknown (`torch.FloatTensor` of shape `(batch_size,)`): Aggregation loss (in case of answer
supervision) per example.


def Render(self, stream, justify=None):
    stream.write(self._con.Colorize(self._string, self._color, justify or self._justify))

Renders the string as self._color on the console.

Args:
stream: The stream to render the string to. The stream given here *must*
have the same encoding as sys.stdout for this to work properly.
justify: The justification function, self._justify if None.


def loads(self, config_str, as_defaults=False):
    self._rw.load_config_from_string(self._config, config_str, as_defaults=as_defaults)

Load configuration values from the specified source string.

Args:
config_str:
as_defaults (bool): if ``True``, contents of ``source`` will be treated as schema of configuration items.


def forward(self, inputs: torch.Tensor):
    residual = inputs
    inputs = self.norm(inputs)
    inputs = inputs.permute(0, 3, 2, 1)
    if self.gated_attn:
        inputs = self.gating_block(inputs)
    inputs = self.mlp(inputs)
    inputs = inputs.permute(0, 3, 2, 1)
    out = inputs + residual
    return out

Args:
inputs (`torch.Tensor` of shape `((batch_size, num_channels, num_patches, d_model))`):
input to the MLP layer
Returns:
`torch.Tensor` of the same shape as `inputs`


def run(self, funcs):
    funcs = [(f if callable(f) else functools.partial(*f)) for f in funcs]
    if (len(funcs) == 1):
        return [funcs[0]()]
    if (len(funcs) > self._workers):
        self.shutdown()
        self._workers = len(funcs)
        self._executor = futures.ThreadPoolExecutor(self._workers)
    futs = [self._executor.submit(f) for f in funcs]
    (done, not_done) = futures.wait(futs, self._timeout, futures.FIRST_EXCEPTION)
    for f in done:
        if ((not f.cancelled()) and (f.exception() is not None)):
            if not_done:
                for nd in not_done:
                    nd.cancel()
                self.shutdown(False)
            raise f.exception()
    return [f.result(timeout=0) for f in futs]

Run a set of functions in parallel, returning their results.

Make sure any function you pass exits with a reasonable timeout. If it
doesn't return within the timeout or the result is ignored due an exception
in a separate thread it will continue to stick around until it finishes,
including blocking process exit.

Args:
funcs: An iterable of functions or iterable of args to functools.partial.

Returns:
A list of return values with the values matching the order in funcs.

Raises:
Propagates the first exception encountered in one of the functions.


def experimental_tpu_predict_loop(model, dataset, verbose=0, steps=None, callbacks=None):
    mode = ModeKeys.PREDICT
    dataset_fully_shaped = dist_utils.is_dataset_shape_fully_defined(dataset)
    padding_handler = None
    if not dataset_fully_shaped:
        padding_handler = padding_util.PartialBatchPaddingHandler(model._feed_output_shapes)
        batch_size, _, prefetch_buffer = input_lib._get_dataset_attributes(dataset)
        padding_handler.padded_batch_size = batch_size
        padding_handler.padding_mask = dataset.reduce(padding_handler.padding_mask, padding_handler.update_mask)
        dataset = dataset.map(padding_handler.pad_batch)
        dataset = dataset.unbatch()
        dataset = dataset.batch(batch_size, drop_remainder=True)
        if prefetch_buffer is not None:
            dataset = dataset.prefetch(prefetch_buffer)
    current_strategy = model._distribution_strategy
    iterator = dist_utils.get_iterator(dataset, current_strategy)
    scope = dist_utils.distributed_scope(strategy=current_strategy, learning_phase=0)
    scope.__enter__()

    def _predict_step_fn(inputs):

        distribute_lib.get_replica_context().merge_call(_build_model, args=(model, mode, inputs))
        _, outputs, updates, _ = _per_replica_execution_function(dist_utils.get_distributed_model(model, mode), mode)
        with ops.control_dependencies([updates]):
            return [array_ops.identity(out) for out in outputs]
    predict_input_data = iterator.get_next()
    per_replica_outputs = current_strategy.run(_predict_step_fn, args=(predict_input_data,))
    output_tensors = dist_utils.flatten_per_replica_values(current_strategy, per_replica_outputs)
    if verbose >= 1:
        progbar = Progbar(target=steps)
    if model._compile_distribution:
        dist_utils._copy_weights_to_distributed_model(model, mode)
    dist_utils._reset_metrics(model)
    callbacks = cbks.configure_callbacks(callbacks, model, do_validation=False, epochs=1, steps_per_epoch=steps, verbose=verbose, count_mode='steps', mode=mode)
    callbacks._call_begin_hook(mode)
    num_model_outputs = len(model.output_names)
    unconcatenated_outs = [[] for _ in range(num_model_outputs)]
    if steps is not None:
        target_steps = steps
    else:
        raise ValueError('Number of steps could not be inferred from the data, please pass the steps argument.')
    current_step = 0
    while current_step < target_steps:
        batch_logs = {'batch': current_step, 'size': 1}
        callbacks._call_batch_hook(mode, 'begin', current_step, batch_logs)
        try:
            predict_ops = control_flow_ops.group(output_tensors)
            _, batch_outs = backend.batch_get_value([predict_ops, output_tensors])
        except errors.OutOfRangeError:
            warning_msg = 'Make sure that your dataset can generate at least `steps` batches (in this case, {} batches).'.format(steps)
            logging.warning('Your dataset iterator ran out of data; interrupting evaluation. ' + warning_msg)
            break
        for i in range(num_model_outputs):
            output_start_index = i * current_strategy.num_replicas_in_sync
            output_end_index = output_start_index + current_strategy.num_replicas_in_sync
            single_model_output = batch_outs[output_start_index:output_end_index]
            unconcatenated_outs[i].extend(single_model_output)
        batch_logs = cbks.make_logs(model, batch_logs, batch_outs, mode)
        callbacks._call_batch_hook(mode, 'end', current_step, batch_logs)
        if verbose == 1:
            progbar.update(current_step + 1)
        current_step += 1
    if verbose >= 1:
        progbar.update(current_step)
    callbacks._call_end_hook(mode)
    scope.__exit__(None, None, None)
    if len(unconcatenated_outs) == 1:
        prediction_result = np.concatenate(unconcatenated_outs[0], axis=0)
    else:
        prediction_result = [np.concatenate(out, axis=0) for out in unconcatenated_outs]
    if padding_handler:
        prediction_result = padding_handler.apply_mask(prediction_result)
    return prediction_result

Predict loop for predicting with TPU tf.distribute.Strategy.

Args:
model: Keras Model instance.
dataset: Dataset for input data.
verbose: Integer, Verbosity mode 0 or 1.
steps: Total number of steps (batches of samples)
before declaring `_predict_loop` finished.
Ignored with the default value of `None`.
callbacks: List of callbacks to be called during training

Returns:
Array of predictions (if the model has a single output)
or list of arrays of predictions
(if the model has multiple outputs).


def BindVar(self, var_id, value):
    if (var_id not in self._vars):
        raise KeyError(var_id)
    self._var_bindings[var_id].append(value)

Associates a value with given variable.

This can be called multiple times to associate multiple values.

Args:
var_id: A variable id to bind the values to.
value: A value to bind to the specified variable.

Raises:
KeyError: If given variable is not specified in the pattern.


def get_storage_account_keys(access_token, subscription_id, rgname, account_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourcegroups/', rgname,
                        '/providers/Microsoft.Storage/storageAccounts/', account_name,
                        '/listKeys',
                        '?api-version=', STORAGE_API])
    return do_post(endpoint, '', access_token)

Get the access keys for the specified storage account.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
rgname (str): Azure resource group name.
account_name (str): Name of the new storage account.

Returns:
HTTP response. JSON body of storage account keys.


def add_sample(a_float, dist):

    dist_type, _ = _detect_bucket_option(dist)
    if dist_type == u'exponentialBuckets':
        _update_general_statistics(a_float, dist)
        _update_exponential_bucket_count(a_float, dist)
    elif dist_type == u'linearBuckets':
        _update_general_statistics(a_float, dist)
        _update_linear_bucket_count(a_float, dist)
    elif dist_type == u'explicitBuckets':
        _update_general_statistics(a_float, dist)
        _update_explicit_bucket_count(a_float, dist)
    else:
        _logger.error(u'Could not determine bucket option type for %s', dist)
        raise ValueError(u'Unknown bucket option type')

Adds `a_float` to `dist`, updating its existing buckets.

Args:
a_float (float): a new value
dist (:class:`endpoints_management.gen.servicecontrol_v1_messages.Distribution`):
the Distribution being updated

Raises:
ValueError: if `dist` does not have known bucket options defined
ValueError: if there are not enough bucket count fields in `dist`


def require_fresh_games(self, number_fresh):
    latest = self.latest_game_number
    table_state = self.bt_table.row(TABLE_STATE)
    table_state.set_cell(METADATA, WAIT_CELL, int((latest + number_fresh)))
    table_state.commit()
    print('== Setting wait cell to ', int((latest + number_fresh)), flush=True)

Require a given number of fresh games to be played.

Args:
number_fresh:  integer, number of new fresh games needed

Increments the cell `table_state=metadata:wait_for_game_number`
by the given number of games.  This will cause
`self.wait_for_fresh_games()` to block until the game
counter has reached this number.


def accepts(regex, negate, *values):
    return (any(((v and regex.search(v)) for v in values)) != negate)

Given a compiled regex and a negate, find if any of the values match.

Args:
regex (Pattern):
negate (bool):
*values (str):

Returns:


def to_input_req(self):
    return {WARM_START_TYPE: self.type.value, PARENT_HYPERPARAMETER_TUNING_JOBS: [{HYPERPARAMETER_TUNING_JOB_NAME: parent} for parent in self.parents]}

Converts the ``self`` instance to the desired input request format.

Returns:
dict: Containing the "WarmStartType" and "ParentHyperParameterTuningJobs" as the first class fields.

Examples:
>>> warm_start_config = WarmStartConfig(warm_start_type=WarmStartTypes.TransferLearning,parents=["p1,p2"])
>>> warm_start_config.to_input_req()
{
"WarmStartType":"TransferLearning",
"ParentHyperParameterTuningJobs": [
{'HyperParameterTuningJobName': "p1"},
{'HyperParameterTuningJobName': "p2"},
]
}


def insert_ising_model(cur, nodelist, edgelist, linear, quadratic, offset, encoded_data=None):
    if (encoded_data is None):
        encoded_data = {}
    insert_graph(cur, nodelist, edgelist, encoded_data=encoded_data)
    if ('linear_biases' not in encoded_data):
        encoded_data['linear_biases'] = _serialize_linear_biases(linear, nodelist)
    if ('quadratic_biases' not in encoded_data):
        encoded_data['quadratic_biases'] = _serialize_quadratic_biases(quadratic, edgelist)
    if ('offset' not in encoded_data):
        encoded_data['offset'] = offset
    if ('max_quadratic_bias' not in encoded_data):
        encoded_data['max_quadratic_bias'] = max(itervalues(quadratic))
    if ('min_quadratic_bias' not in encoded_data):
        encoded_data['min_quadratic_bias'] = min(itervalues(quadratic))
    if ('max_linear_bias' not in encoded_data):
        encoded_data['max_linear_bias'] = max(itervalues(linear))
    if ('min_linear_bias' not in encoded_data):
        encoded_data['min_linear_bias'] = min(itervalues(linear))
    insert = '\n        INSERT OR IGNORE INTO ising_model(\n            linear_biases,\n            quadratic_biases,\n            offset,\n            max_quadratic_bias,\n            min_quadratic_bias,\n            max_linear_bias,\n            min_linear_bias,\n            graph_id)\n        SELECT\n            :linear_biases,\n            :quadratic_biases,\n            :offset,\n            :max_quadratic_bias,\n            :min_quadratic_bias,\n            :max_linear_bias,\n            :min_linear_bias,\n            graph.id\n        FROM graph WHERE\n            num_nodes = :num_nodes AND\n            num_edges = :num_edges AND\n            edges = :edges;\n        '
    cur.execute(insert, encoded_data)

Insert an Ising model into the cache.

Args:
cur (:class:`sqlite3.Cursor`): An sqlite3 cursor. This function
is meant to be run within a :obj:`with` statement.
nodelist (list): The nodes in the graph.
edgelist (list): The edges in the graph.
linear (dict): The linear bias associated with each node in nodelist.
quadratic (dict): The quadratic bias associated with teach edge in edgelist.
offset (float): The constant offset applied to the ising problem.
encoded_data (dict, optional): If a dictionary is provided, it
will be populated with the serialized data. This is useful for
preventing encoding the same information many times.


def logspace(start, stop, num=50, endpoint=True, base=10, dtype=None, axis=0):
    if any_symbolic_tensors((start, stop)):
        return Logspace(num, endpoint, base, dtype, axis)(start, stop)
    return backend.numpy.logspace(start, stop, num=num, endpoint=endpoint, base=base, dtype=dtype, axis=axis)

Returns numbers spaced evenly on a log scale.

In linear space, the sequence starts at `base ** start` and ends with
`base ** stop` (see `endpoint` below).

Args:
start: The starting value of the sequence.
stop: The final value of the sequence, unless `endpoint` is `False`.
In that case, `num + 1` values are spaced over the interval in
log-space, of which all but the last (a sequence of length `num`)
are returned.
num: Number of samples to generate. Defaults to `50`.
endpoint: If `True`, `stop` is the last sample. Otherwise, it is not
included. Defaults to `True`.
base: The base of the log space. Defaults to `10`.
dtype: The type of the output tensor.
axis: The axis in the result to store the samples. Relevant only
if start or stop are array-like.

Note:
Torch backend does not support `axis` argument.

Returns:
A tensor of evenly spaced samples on a log scale.


def load_folder_content(folder_path):

    items_mapping = {}

    for file_path in load_folder_files(folder_path):
        items_mapping[file_path] = load_file(file_path)

    return items_mapping

load api/testcases/testsuites definitions from folder.

Args:
folder_path (str): api/testcases/testsuites files folder.

Returns:
dict: api definition mapping.

{
"tests/api/basic.yml": [
{"api": {"def": "api_login", "request": {}, "validate": []}},
{"api": {"def": "api_logout", "request": {}, "validate": []}}
]
}


def update(cls, customer_id, **kwargs):
    return cls().requests.put('customer/{customer_id}'.format(**locals()), data=kwargs)

Static method defined to update paystack customer data by id.

Args:
customer_id: paystack customer id.
first_name: customer's first name(optional).
last_name: customer's last name(optional).
email: customer's email address(optional).
phone:customer's phone number(optional).

Returns:
Json data from paystack API.


def check_compiled(module):
    check_module = importlib.import_module(module)
    ext = os.path.splitext(check_module.__file__)[-1]
    if ext in ('.py', '.pyc'):
        raise RuntimeError("Profiling uncompiled code.\nTo compile beam, run 'pip install Cython; python setup.py build_ext --inplace'")

Check whether given module has been compiled.
Args:
module: string, module name


def sample_paths(self, times: types.RealTensor, num_samples: Optional[int]=1, initial_state: Optional[types.RealTensor]=None, random_type: Optional[random.RandomType]=None, seed: Optional[types.IntTensor]=None, swap_memory: Optional[bool]=True, time_step: Optional[types.RealTensor]=None, num_time_steps: Optional[types.IntTensor]=None, skip: Optional[types.IntTensor]=0, precompute_normal_draws: Optional[bool]=True, times_grid: Optional[types.RealTensor]=None, normal_draws: Optional[types.RealTensor]=None, watch_params: Optional[List[types.RealTensor]]=None, validate_args: Optional[bool]=False, name: Optional[str]=None) -> types.RealTensor:
    name = name or self._name + '_log_sample_path'
    with tf.name_scope(name):
        if initial_state is not None:
            initial_state = tf.math.log(tf.convert_to_tensor(initial_state, dtype_hint=tf.float64))
        if self.precompute_iv():
            if time_step is not None or num_time_steps is not None or times_grid is not None:
                raise ValueError('`time_step`, `num_time_steps`, or `times_grid` cannot be usedwith the interpolated LVM')
            times_grid = self._times_grid
        return tf.math.exp(super(LocalVolatilityModel, self).sample_paths(times=times, num_samples=num_samples, initial_state=initial_state, random_type=random_type, seed=seed, swap_memory=swap_memory, name=name, time_step=time_step, num_time_steps=num_time_steps, skip=skip, precompute_normal_draws=precompute_normal_draws, times_grid=times_grid, normal_draws=normal_draws, watch_params=watch_params, validate_args=validate_args))

Returns samples from the LV process.

See GenericItoProcess.sample_paths. If `times_grid` is supplied to
`__init__`, then `times_grid` cannot be supplied here.

Raises:
ValueError: If `precompute_iv` is True, but `time_step`, `num_time_steps`
or `times_grid` are given.


Validate a value.

Args:
value: The value to validate
*args: External arguments necessary for validation.

Returns:
True if the value is valid, False otherwise.