def __get_merged_api_info(self, services):

    merged_api_info = services[0].api_info

    for service in services[1:]:
      if not merged_api_info.is_same_api(service.api_info):
        raise api_exceptions.ApiConfigurationError(
            _MULTICLASS_MISMATCH_ERROR_TEMPLATE % (service.api_info.name,
                                                   service.api_info.api_version))

    return merged_api_info

Builds a description of an API.

Args:
services: List of protorpc.remote.Service instances implementing an
api/version.

Returns:
The _ApiInfo object to use for the API that the given services implement.

Raises:
ApiConfigurationError: If there's something wrong with the API
configuration, such as a multiclass API decorated with different API
descriptors (see the docstring for api()).


def assert_not_almost_equal(first, second, places=None, msg=None, delta=None, extras=None):
    _call_unittest_assertion(_pyunit_proxy.assertNotAlmostEqual, first, second, places=places, msg=msg, delta=delta, extras=extras)

Asserts that first is not almost equal to second.

Args:
first: The first value to compare.
second: The second value to compare.
places: How many decimal places to take into account for comparison.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most significant digit).
msg: A string that adds additional info about the failure.
delta: Delta to use for comparison instead of decimal places.
extras: An optional field for extra information to be included in
test result.


def read(path):

        if fs.exists(path):
            with open(path) as infile:
                components = infile.read().split()
                pid = int(components[0])
                date = datetime.date.fromtimestamp(float(components[1]))
            return pid, date
        else:
            return None, None

Read the contents of a LockFile.

Arguments:
path (str): Path to lockfile.

Returns:
Tuple(int, datetime): The integer PID of the lock owner, and the
date the lock was required. If the lock is not claimed, both
values are None.


def parent_callback(self, parent_fu):

        if parent_fu.done() is True:
            e = parent_fu._exception
            if e:
                super().set_exception(e)
            else:
                super().set_result(self.file_obj)
        return

Callback from executor future to update the parent.

Args:
- parent_fu (Future): Future returned by the executor along with callback

Returns:
- None

Updates the super() with the result() or exception()


def foo(x: int, *args, y: str, **kwargs) -> float:
    del x, y, args, kwargs

A function.

Args:
x: Input 1.
*args: Variable positional args.
y: Input 2.
**kwargs: Variable keyword args.

Returns:
The result.


def _lower_if_str(item):

    try:
        string_type = basestring
    except NameError:
        string_type = str

    if isinstance(item, string_type):
        return item.lower()

    return item

Try to convert item to lowercase, if it is string.

Args:
item (obj): Str, unicode or any other object.

Returns:
obj: ``item.lower()`` if `item` is ``str`` or ``unicode``, else just \
`item` itself.


def backup_value(self, value, up_to):
    self.N += 1
    self.W += value
    if ((self.parent is None) or (self is up_to)):
        return
    self.parent.backup_value(value, up_to)

Propagates a value estimation up to the root node.

Args:
value: the value to be propagated (1 = black wins, -1 = white wins)
up_to: the node to propagate until.


def __init__(self, key, value, timeout):

        self.key = key
        self.value = value
        self.expiration = time.clock() * 1000 + timeout

Creates instance of the cache entry.

Args:
key: the unique key used to identify and locate the value.
value: the cached value.
timeout: time to live for the object in milliseconds


def delete(self, context_id, address_list):
    if (context_id not in self._contexts):
        return False
    context = self._contexts[context_id]
    for add in address_list:
        if (not self.address_is_valid(address=add)):
            raise AuthorizationException(address=add)
    context.delete_direct(address_list)
    return True

Delete the values associated with list of addresses, for a specific
context referenced by context_id.

Args:
context_id (str): the return value of create_context, referencing
a particular context.
address_list (list): a list of address strs

Returns:
(bool): True if the operation is successful, False if
the context_id doesn't reference a known context.

Raises:
AuthorizationException: Raised when an address in address_list is
not authorized either by not being in the inputs for the
txn associated with this context, or it is under a namespace
but the characters that are under the namespace are not valid
address characters.


def arg_types(parsed: Parsed, errors: Errors) -> Tuple[(Parsed, Errors)]:
    func_pattern = re.compile('\\s*[a-zA-Z]+\\(')
    nsarg_pattern = re.compile('^\\s*([A-Z]+):(.*?)\\s*$')
    for span in parsed:
        if ((parsed[span]['type'] != 'Function') or ('parens_span' not in parsed[span])):
            continue
        for (i, arg) in enumerate(parsed[span]['args']):
            nsarg_matches = nsarg_pattern.match(arg['arg'])
            if func_pattern.match(arg['arg']):
                parsed[span]['args'][i].update({'type': 'Function'})
            elif nsarg_matches:
                (start, end) = arg['span']
                ns = nsarg_matches.group(1)
                ns_val = nsarg_matches.group(2)
                ns_span = nsarg_matches.span(1)
                ns_span = ((ns_span[0] + start), ((ns_span[1] + start) - 1))
                ns_val_span = nsarg_matches.span(2)
                ns_val_span = ((ns_val_span[0] + start), ((ns_val_span[1] + start) - 1))
                parsed[span]['args'][i].update({'type': 'NSArg', 'ns': ns, 'ns_span': ns_span, 'ns_val': ns_val, 'ns_val_span': ns_val_span})
            else:
                parsed[span]['args'][i].update({'type': 'StrArg'})
    return (parsed, errors)

Add argument types to parsed function data structure

Args:
parsed: function and arg locations in BEL string
errors: error messages

Returns:
(parsed, errors): parsed, arguments with arg types plus error messages


def forward(self, inputs_embeds, attention_mask: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None) -> Union[Tuple, BaseModelOutput]:
    output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
    output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    return_dict = return_dict if return_dict is not None else self.config.use_return_dict
    encoder_states = () if output_hidden_states else None
    all_attentions = () if output_attentions else None
    hidden_states = inputs_embeds
    for idx, encoder_layer in enumerate(self.layers):
        if output_hidden_states:
            encoder_states = encoder_states + (hidden_states,)
        layer_outputs = encoder_layer(hidden_states, attention_mask, output_attentions=output_attentions)
        hidden_states = layer_outputs[0]
        if output_attentions:
            all_attentions = all_attentions + (layer_outputs[1],)
    if output_hidden_states:
        encoder_states = encoder_states + (hidden_states,)
    if not return_dict:
        return tuple((v for v in [hidden_states, encoder_states, all_attentions] if v is not None))
    return BaseModelOutput(last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions)

Args:
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
Embedded representation of the inputs. Should be float, not int tokens.
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

- 1 for tokens that are **not masked**,
- 0 for tokens that are **masked**.

[What are attention masks?](../glossary#attention-mask)
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.
output_hidden_states (`bool`, *optional*):
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
for more detail.
return_dict (`bool`, *optional*):
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.


def _kl_categorical_categorical(a, b, name=None):
    with ops.name_scope(name, 'kl_categorical_categorical', values=[a.logits, b.logits]):
        delta_log_probs1 = nn_ops.log_softmax(a.logits) - nn_ops.log_softmax(b.logits)
        return math_ops.reduce_sum(nn_ops.softmax(a.logits) * delta_log_probs1, axis=-1)

Calculate the batched KL divergence KL(a || b) with a and b Categorical.

Args:
a: instance of a Categorical distribution object.
b: instance of a Categorical distribution object.
name: (optional) Name to use for created operations.
default is "kl_categorical_categorical".

Returns:
Batchwise KL(a || b)


def format_config(sensor_graph):

    cmdfile = CommandFile("Config Variables", "1.0")

    for slot in sorted(sensor_graph.config_database, key=lambda x: x.encode()):
        for conf_var, conf_def in sorted(sensor_graph.config_database[slot].items()):
            conf_type, conf_val = conf_def

            if conf_type == 'binary':
                conf_val = 'hex:' + hexlify(conf_val)

            cmdfile.add("set_variable", slot, conf_var, conf_type, conf_val)

    return cmdfile.dump()

Extract the config variables from this sensor graph in ASCII format.

Args:
sensor_graph (SensorGraph): the sensor graph that we want to format

Returns:
str: The ascii output lines concatenated as a single string


def easeInOutElastic(n, amplitude=1, period=0.5):

    _checkRange(n)
    n *= 2
    if n < 1:
        return easeInElastic(n, amplitude=amplitude, period=period) / 2
    else:
        return easeOutElastic(n-1, amplitude=amplitude, period=period) / 2 + 0.5

An elastic tween function wobbles towards the midpoint.

Args:
n (float): The time progress, starting at 0.0 and ending at 1.0.

Returns:
(float) The line progress, starting at 0.0 and ending at 1.0. Suitable for passing to getPointOnLine().


def gamma_automatic(kpts=(1, 1, 1), shift=(0, 0, 0)):

        return Kpoints("Automatic kpoint scheme", 0,
                       Kpoints.supported_modes.Gamma, kpts=[kpts],
                       kpts_shift=shift)

Convenient static constructor for an automatic Gamma centered Kpoint
grid.

Args:
kpts: Subdivisions N_1, N_2 and N_3 along reciprocal lattice
vectors. Defaults to (1,1,1)
shift: Shift to be applied to the kpoints. Defaults to (0,0,0).

Returns:
Kpoints object


def _pad_images(self, images: 'torch.Tensor'):
    height, width = get_image_size(images, channel_dim=ChannelDimension.FIRST)
    pad_height = int(np.sqrt(height / 2) * 3)
    pad_width = int(np.sqrt(width / 2) * 3)
    return F.pad(images, padding=(pad_width, pad_height), padding_mode='reflect')

Args:
image (`torch.Tensor`):
Image to pad.


def bottleneck_block_v1(cnn, depth, depth_bottleneck, stride):
    input_layer = cnn.top_layer
    in_size = cnn.top_size
    name_key = 'resnet_v1'
    name = (name_key + str(cnn.counts[name_key]))
    cnn.counts[name_key] += 1
    with tf.variable_scope(name):
        if (depth == in_size):
            if (stride == 1):
                shortcut = input_layer
            else:
                shortcut = cnn.apool(1, 1, stride, stride, input_layer=input_layer, num_channels_in=in_size)
        else:
            shortcut = cnn.conv(depth, 1, 1, stride, stride, activation=None, use_batch_norm=True, input_layer=input_layer, num_channels_in=in_size, bias=None)
        cnn.conv(depth_bottleneck, 1, 1, stride, stride, input_layer=input_layer, num_channels_in=in_size, use_batch_norm=True, bias=None)
        cnn.conv(depth_bottleneck, 3, 3, 1, 1, mode='SAME_RESNET', use_batch_norm=True, bias=None)
        res = cnn.conv(depth, 1, 1, 1, 1, activation=None, use_batch_norm=True, bias=None)
        output = tf.nn.relu((shortcut + res))
        cnn.top_layer = output
        cnn.top_size = depth

Bottleneck block with identity short-cut for ResNet v1.

Args:
cnn: the network to append bottleneck blocks.
depth: the number of output filters for this bottleneck block.
depth_bottleneck: the number of bottleneck filters for this block.
stride: Stride used in the first layer of the bottleneck block.


def patch_on_value(src: symbolic.Symbolic, old_value: Any, value: Any=None, value_fn: Optional[Callable[[Any], Any]]=None, skip_notification: Optional[bool]=None) -> Any:
    return _conditional_patch(src, lambda k, v, p: v == old_value, value, value_fn, skip_notification)

Recursively patch values on matched values.

Example::

d = pg.Dict(a={'x': 1}, b=1)
print(pg.patching.patch_on_value(d, 1, value=3))
# {a={x=3}, b=3}

Args:
src: symbolic value to patch.
old_value: Old value to match.
value: New value for field that satisfy `condition`.
value_fn: Callable object that produces new value based on old value.
If not None, `value` must be None.
skip_notification: If True, `on_change` event will not be triggered for this
operation. If None, the behavior is decided by `pg.notify_on_rebind`.
Please see `symbolic.Symbolic.rebind` for details.

Returns:
`src` after being patched.


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

Create a mask from the two sequences passed to be used in a sequence-pair classification task. RoBERTa does not
make use of token type ids, therefore a list of zeros is returned.
Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
Returns:
`List[int]`: List of zeros.


def _CanSkipDataStream(self, file_entry, data_stream):

    if file_entry.IsFile():
      return False

    if data_stream.IsDefault():
      return True

    return False

Determines if analysis and extraction of a data stream can be skipped.

This is used to prevent Plaso trying to run analyzers or extract content
from a pipe or socket it encounters while processing a mounted filesystem.

Args:
file_entry (dfvfs.FileEntry): file entry to consider for skipping.
data_stream (dfvfs.DataStream): data stream to consider for skipping.

Returns:
bool: True if the data stream can be skipped.


def grep(self, regex):
    matches = []
    logger.debug("Searching student files for '{0}'".format(regex))
    for fname in self.student_files:
        if os.path.isfile((self.working_dir + fname)):
            for line in open((self.working_dir + fname), 'br'):
                if re.search(regex.encode(), line):
                    logger.debug("{0} contains '{1}'".format(fname, regex))
                    matches.append(fname)
    return matches

Scans the student files for text patterns.

Args:
regex (str):       Regular expression used for scanning inside the files.

Returns:
tuple:     Names of the matching files in the working directory.


def register_entity(self, entity_value, entity_type, alias_of=None, domain=0):
    if (domain not in self.domains):
        self.register_domain(domain=domain)
    self.domains[domain].register_entity(entity_value=entity_value, entity_type=entity_type, alias_of=alias_of)

Register an entity to be tagged in potential parse results.

Args:
entity_value(str): the value/proper name of an entity instance
(Ex: "The Big Bang Theory")
entity_type(str): the type/tag of an entity instance (Ex: "Television Show")
domain(str): a string representing the domain you wish to add the entity to


def _mask(self, tensor, length, padding_value=0):

    with tf.name_scope('mask'):
      range_ = tf.range(tensor.shape[1].value)
      mask = range_[None, :] < length[:, None]
      if tensor.shape.ndims > 2:
        for _ in range(tensor.shape.ndims - 2):
          mask = mask[..., None]
        mask = tf.tile(mask, [1, 1] + tensor.shape[2:].as_list())
      masked = tf.where(mask, tensor, padding_value * tf.ones_like(tensor))
      return tf.check_numerics(masked, 'masked')

Set padding elements of a batch of sequences to a constant.

Useful for setting padding elements to zero before summing along the time
dimension, or for preventing infinite results in padding elements.

Args:
tensor: Tensor of sequences.
length: Batch of sequence lengths.
padding_value: Value to write into padding elements.

Returns:
Masked sequences.


def value(self, row, col, device_name_filter=None, node_name_filter=None, op_type_filter=None):
    menu_item = None
    if col == 0:
        text = self._profile_datum_list[row].node_exec_stats.node_name
    elif col == 1:
        text = self._profile_datum_list[row].op_type
    elif col == 2:
        text = str(self.formatted_start_time[row])
    elif col == 3:
        text = str(self.formatted_op_time[row])
    elif col == 4:
        text = str(self.formatted_exec_time[row])
    elif col == 5:
        command = 'ps'
        if device_name_filter:
            command += ' --%s %s' % (_DEVICE_NAME_FILTER_FLAG, device_name_filter)
        if node_name_filter:
            command += ' --%s %s' % (_NODE_NAME_FILTER_FLAG, node_name_filter)
        if op_type_filter:
            command += ' --%s %s' % (_OP_TYPE_FILTER_FLAG, op_type_filter)
        command += ' %s --init_line %d' % (self._profile_datum_list[row].file_path, self._profile_datum_list[row].line_number)
        menu_item = debugger_cli_common.MenuItem(None, command)
        text = self._profile_datum_list[row].file_line_func
    else:
        raise IndexError('Invalid column index %d.' % col)
    return RL(text, font_attr=menu_item)

Get the content of a cell of the table.

Args:
row: (int) row index.
col: (int) column index.
device_name_filter: Regular expression to filter by device name.
node_name_filter: Regular expression to filter by node name.
op_type_filter: Regular expression to filter by op type.

Returns:
A debuggre_cli_common.RichLine object representing the content of the
cell, potentially with a clickable MenuItem.

Raises:
IndexError: if row index is out of range.


def make_es_id(uri):
    try:
        uri = uri.clean_uri
    except AttributeError:
        pass
    return sha1(uri.encode()).hexdigest()

Creates the id based off of the uri value

Args:
-----
uri: the uri to conver to an elasticsearch id


def box_to_center_and_scale(box: Union[Tuple, List, np.ndarray], image_width: int, image_height: int, normalize_factor: float=200.0, padding_factor: float=1.25):
    top_left_x, top_left_y, width, height = box[:4]
    aspect_ratio = image_width / image_height
    center = np.array([top_left_x + width * 0.5, top_left_y + height * 0.5], dtype=np.float32)
    if width > aspect_ratio * height:
        height = width * 1.0 / aspect_ratio
    elif width < aspect_ratio * height:
        width = height * aspect_ratio
    scale = np.array([width / normalize_factor, height / normalize_factor], dtype=np.float32)
    scale = scale * padding_factor
    return (center, scale)

Encodes a bounding box in COCO format into (center, scale).

Args:
box (`Tuple`, `List`, or `np.ndarray`):
Bounding box in COCO format (top_left_x, top_left_y, width, height).
image_width (`int`):
Image width.
image_height (`int`):
Image height.
normalize_factor (`float`):
Width and height scale factor.
padding_factor (`float`):
Bounding box padding factor.

Returns:
tuple: A tuple containing center and scale.

- `np.ndarray` [float32](2,): Center of the bbox (x, y).
- `np.ndarray` [float32](2,): Scale of the bbox width & height.


def _print_results(filename, data):

    if filename:
        with open(filename, 'wb') as f:
            f.write(data)
    else:
        print data

Print data to a file or STDOUT.

Args:
filename (str or None): If None, print to STDOUT; otherwise, print
to the file with this name.
data (str): Data to print.


def get_ip_address_country(ip_address, parallel=False):

    def download_country_database(location='GeoLite2-Country.mmdb'):
        'Downloads the MaxMind Geolite2 Country database\n\n        Args:\n            location (str): Local location for the database file\n        '
        if parallel:
            logging.warning('Cannot download GeoIP database in parallel mode')
            return
        url = 'https:
        headers = {'User-Agent': USER_AGENT}
        original_filename = 'GeoLite2-Country.mmdb'
        try:
            response = requests.get(url, headers=headers)
            response.raise_for_status()
            tar_bytes = response.content
            tar_file = tarfile.open(fileobj=BytesIO(tar_bytes), mode='r:gz')
            tar_dir = tar_file.getnames()[0]
            tar_path = '{0}/{1}'.format(tar_dir, original_filename)
            tar_file.extract(tar_path)
            shutil.move(tar_path, location)
            shutil.rmtree(tar_dir)
        except Exception as e:
            logger.warning('Error downloading {0}: {1}'.format(url, e.__str__()))
    system_paths = ['GeoLite2-Country.mmdb', '/usr/local/share/GeoIP/GeoLite2-Country.mmdb', '/usr/share/GeoIP/GeoLite2-Country.mmdb', '/var/lib/GeoIP/GeoLite2-Country.mmdb', '/var/local/lib/GeoIP/GeoLite2-Country.mmdb', 'C:\\GeoIP\\GeoLite2-Country.mmdb']
    db_path = None
    for system_path in system_paths:
        if os.path.exists(system_path):
            db_path = system_path
            break
    if (db_path is None):
        db_path = os.path.join(tempdir, 'GeoLite2-Country.mmdb')
        if (not os.path.exists(db_path)):
            download_country_database(db_path)
            if (not os.path.exists(db_path)):
                return None
        else:
            db_age = (datetime.now() - datetime.fromtimestamp(os.stat(db_path).st_mtime))
            if (db_age > timedelta(days=7)):
                download_country_database()
        db_path = db_path
    db_reader = geoip2.database.Reader(db_path)
    country = None
    try:
        country = db_reader.country(ip_address).country.iso_code
    except geoip2.errors.AddressNotFoundError:
        pass
    return country

Uses the MaxMind Geolite2 Country database to return the ISO code for the
country associated with the given IPv4 or IPv6 address

Args:
ip_address (str): The IP address to query for
parallel (bool): Parallel processing

Returns:
str: And ISO country code associated with the given IP address


def element_at(self, index):

        if self.closed():
            raise ValueError("Attempt to call element_at() on a "
                             "closed Queryable.")

        if index < 0:
            raise OutOfRangeError("Attempt to use negative index.")

        try:
            return self._iterable[index]
        except IndexError:
            raise OutOfRangeError("Index out of range.")
        except TypeError:
            pass

        for i, item in enumerate(self):
            if i == index:
                return item
        raise OutOfRangeError("element_at(index) out of range.")

Return the element at ordinal index.

Note: This method uses immediate execution.

Args:
index: The index of the element to be returned.

Returns:
The element at ordinal index in the source sequence.

Raises:
ValueError: If the Queryable is closed().
ValueError: If index is out of range.


def _parse_testcase(testcase, project_mapping, session_variables_set=None):

    testcase.setdefault("config", {})
    prepared_config = __prepare_config(
        testcase["config"],
        project_mapping,
        session_variables_set
    )
    prepared_testcase_tests = __prepare_testcase_tests(
        testcase["teststeps"],
        prepared_config,
        project_mapping,
        session_variables_set
    )
    return {
        "config": prepared_config,
        "teststeps": prepared_testcase_tests
    }

parse testcase

Args:
testcase (dict):
{
"config": {},
"teststeps": []
}


def _ws_on_open(self, ws: websocket.WebSocketApp):

        payload = {
            'op': WebSocketEvent.IDENTIFY.value,
            'd': {
                'token': self.token,
                'properties': {
                    '$os': sys.platform,
                    '$browser': 'Pycord',
                    '$device': 'Pycord',
                    '$referrer': '',
                    '$referring_domain': ''
                },
                'compress': True,
                'large_threshold': 250
            }
        }
        self.logger.debug('Sending identify payload')
        ws.send(json.dumps(payload))
        self.connected = True

Callback for sending the initial authentication data

This "payload" contains the required data to authenticate this websocket
client as a suitable bot connection to the Discord websocket.

Args:
ws: websocket connection


def change_disk_usage(self, usage_change, file_path, st_dev):

        mount_point = self._mount_point_for_device(st_dev)
        if mount_point:
            total_size = mount_point['total_size']
            if total_size is not None:
                if total_size - mount_point['used_size'] < usage_change:
                    self.raise_io_error(errno.ENOSPC, file_path)
            mount_point['used_size'] += usage_change

Change the used disk space by the given amount.

Args:
usage_change: Number of bytes added to the used space.
If negative, the used space will be decreased.

file_path: The path of the object needing the disk space.

st_dev: The device ID for the respective file system.

Raises:
IOError: if usage_change exceeds the free file system space


def create_context(self, state_hash, base_contexts, inputs, outputs):

        for address in inputs:
            if not self.namespace_is_valid(address):
                raise CreateContextException(
                    "Address or namespace {} listed in inputs is not "
                    "valid".format(address))
        for address in outputs:
            if not self.namespace_is_valid(address):
                raise CreateContextException(
                    "Address or namespace {} listed in outputs is not "
                    "valid".format(address))

        addresses_to_find = [add for add in inputs if len(add) == 70]

        address_values, reads = self._find_address_values_in_chain(
            base_contexts=base_contexts,
            addresses_to_find=addresses_to_find)

        context = ExecutionContext(
            state_hash=state_hash,
            read_list=inputs,
            write_list=outputs,
            base_context_ids=base_contexts)

        contexts_asked_not_found = [cid for cid in base_contexts
                                    if cid not in self._contexts]
        if contexts_asked_not_found:
            raise KeyError(
                "Basing a new context off of context ids {} "
                "that are not in context manager".format(
                    contexts_asked_not_found))

        context.create_initial(address_values)

        self._contexts[context.session_id] = context

        if reads:
            context.create_prefetch(reads)
            self._address_queue.put_nowait(
                (context.session_id, state_hash, reads))
        return context.session_id

Create a ExecutionContext to run a transaction against.

Args:
state_hash: (str): Merkle root to base state on.
base_contexts (list of str): Context ids of contexts that will
have their state applied to make this context.
inputs (list of str): Addresses that can be read from.
outputs (list of str): Addresses that can be written to.
Returns:
context_id (str): the unique context_id of the session


def __init__(self, adgroup_id):

    self.next_id = -1

    self.operations = []
    self.adgroup_id = adgroup_id

Initializer.

Args:
adgroup_id: The ID of the AdGroup that we wish to attach the partition
tree to.


def _subscribe_extend(tensor, side_effects):
    assert len(tensor.op.inputs) == 1, 'Op {} must only have one input'.format(tensor.op.name)
    source_tensor = tensor.op.inputs[0]
    outs = []
    name_scope = source_tensor.op.name + '/subscription/'
    with ops.name_scope(name_scope):
        for s in side_effects:
            outs += s(source_tensor)
    out_ops = [out.op if isinstance(out, tensor_lib.Tensor) else out for out in outs]
    tensor.op._add_control_inputs(out_ops)
    return tensor

Helper method to extend the list of side_effects for a subscribed tensor.

Args:
tensor: A `tf.Tensor` as returned by subscribe().
side_effects: List of side_effect functions, see subscribe for details.

Returns:
The given subscribed tensor (for API consistency).


def _CheckLocation(self, file_entry, search_depth):
    if (self._location_segments is None):
        return False
    if ((search_depth < 0) or (search_depth > self._number_of_location_segments)):
        return False
    if (search_depth == 0):
        segment_name = ''
    else:
        segment_name = self._location_segments[(search_depth - 1)]
        if self._is_regex:
            if isinstance(segment_name, py2to3.STRING_TYPES):
                flags = (re.DOTALL | re.UNICODE)
                if (not self._is_case_sensitive):
                    flags |= re.IGNORECASE
                try:
                    segment_name = '^{0:s}$'.format(segment_name)
                    segment_name = re.compile(segment_name, flags=flags)
                except sre_constants.error:
                    return False
                self._location_segments[(search_depth - 1)] = segment_name
        elif (not self._is_case_sensitive):
            segment_name = segment_name.lower()
            self._location_segments[(search_depth - 1)] = segment_name
    if (search_depth > 0):
        if self._is_regex:
            if (not segment_name.match(file_entry.name)):
                return False
        elif self._is_case_sensitive:
            if (segment_name != file_entry.name):
                return False
        elif (segment_name != file_entry.name.lower()):
            return False
    return True

Checks the location find specification.

Args:
file_entry (FileEntry): file entry.
search_depth (int): number of location path segments to compare.

Returns:
bool: True if the file entry matches the find specification, False if not.


def tinsel(to_patch, module_name, decorator=mock_decorator):

    def fn_decorator(function):

        def wrapper(*args, **kwargs):
            with patch(to_patch, decorator):
                m = importlib.import_module(module_name)
                reload(m)
                function(*args, **kwargs)
            reload(m)
        return wrapper
    return fn_decorator

Decorator for simple in-place decorator mocking for tests

Args:
to_patch: the string path of the function to patch
module_name: complete string path of the module to reload
decorator (optional): replacement decorator. By default a pass-through
will be used.

Returns:
A wrapped test function, during the context of execution the specified
path is patched.


def merge_options(*options_list):
    if len(options_list) < 1:
        raise ValueError('At least one options should be provided')
    result_type = type(options_list[0])
    for options in options_list:
        if not isinstance(options, result_type):
            raise TypeError('Could not merge incompatible options of type {} and {}.'.format(type(options), result_type))
    if not isinstance(options_list[0], OptionsBase):
        raise TypeError('All options to be merged should inherit from `OptionsBase` but found option of type {} which does not.'.format(type(options_list[0])))
    default_options = result_type()
    result = result_type()
    for options in options_list:
        for name in options._options:
            this = getattr(result, name)
            that = getattr(options, name)
            default = getattr(default_options, name)
            if that == default:
                continue
            elif this == default:
                setattr(result, name, that)
            elif isinstance(this, OptionsBase):
                setattr(result, name, merge_options(this, that))
            elif name == 'framework_type':
                setattr(result, name, this + that)
            elif this != that:
                logging.warning('Changing the value of option %s from %r to %r.', name, this, that)
                setattr(result, name, that)
    return result

Merges the given options, returning the result as a new options object.

The input arguments are expected to have a matching type that derives from
`tf.data.OptionsBase` (and thus each represent a set of options). The method
outputs an object of the same type created by merging the sets of options
represented by the input arguments.

If an option is set to different values by different options objects, the
result will match the setting of the options object that appears in the input
list last.

If an option is an instance of `tf.data.OptionsBase` itself, then this method
is applied recursively to the set of options represented by this option.

Args:
*options_list: options to merge

Raises:
TypeError: if the input arguments are incompatible or not derived from
`tf.data.OptionsBase`

Returns:
A new options object which is the result of merging the given options.


def forward(self, input_ids: torch.LongTensor) -> torch.FloatTensor:
    if self.map:
        my_input_ids = self.assistant_overlap_token_ids[input_ids[0, -1]].unsqueeze(0).unsqueeze(0)
    else:
        self.map = True
        my_input_ids = input_ids
    return self.original_embedding(my_input_ids)

Args:
input_ids (torch.LongTensor): Tensor of token IDs (batch_size, seq_len).

Returns:
torch.FloatTensor: Corresponding input embeddings.


def fori_loop(lower, upper, body_fun, init_val):
    if any_symbolic_tensors((lower, upper, init_val)):
        return ForiLoop(lower, upper, body_fun).symbolic_call(init_val)
    return backend.core.fori_loop(lower, upper, body_fun, init_val)

For loop implementation.

Args:
lower: The initial value of the loop variable.
upper: The upper bound of the loop variable.
body_fun: A callable that represents the loop body. Must take two
arguments: the loop variable and the loop state. The loop state
should be updated and returned by this function.
init_val: The initial value of the loop state.

Returns:
The final state after the loop.

Example:

>>> lower = 0
>>> upper = 10
>>> body_fun = lambda i, s: (i + 1, s + i)
>>> init_val = 0
>>> keras.ops.fori_loop(lower, upper, body_fun, init_val)
45


def get_icohp_dict_by_bondlengths(self, minbondlength=0.0, maxbondlength=8.0):

        newicohp_dict = {}
        for value in self._icohplist.values():
            if value._length >= minbondlength and value._length <= maxbondlength:
                newicohp_dict[value._label] = value
        return newicohp_dict

get a dict of IcohpValues corresponding to certaind bond lengths
Args:
minbondlength: defines the minimum of the bond lengths of the bonds
maxbondlength: defines the maximum of the bond lengths of the bonds
Returns:
dict of IcohpValues, the keys correspond to the values from the initial list_labels


def get_csv(filename):

    check_if_this_file_exist(filename)

    filename = os.path.abspath(filename)
    s = command_line(['exiftool', '-G', '-csv', '-sort', filename])
    if s:

        s = s.decode('utf-8')
        return s
    else:
        return 0

Return a csv representation of the exif

get a filename and returns a unicode string with a CSV format

Arguments:
filename {string} -- your filename

Returns:
[unicode] -- unicode string


def get_token_accuracy(targets, outputs, ignore_index=None):
    n_correct = 0.0
    n_total = 0.0
    for (target, output) in zip(targets, outputs):
        if ((not torch.is_tensor(target)) or is_scalar(target)):
            target = torch.LongTensor([target])
        if ((not torch.is_tensor(output)) or is_scalar(output)):
            output = torch.LongTensor([[output]])
        if (len(target.size()) != len(output.size())):
            prediction = output.max(dim=0)[0].view((- 1))
        else:
            prediction = output
        if (ignore_index is not None):
            mask = target.ne(ignore_index)
            n_correct += prediction.eq(target).masked_select(mask).sum().item()
            n_total += mask.sum().item()
        else:
            n_total += len(target)
            n_correct += prediction.eq(target).sum().item()
    return ((n_correct / n_total), n_correct, n_total)

Get the accuracy token accuracy between two tensors.

Args:
targets (1 - 2D :class:`torch.Tensor`): Target or true vector against which to measure
saccuracy
outputs (1 - 3D :class:`torch.Tensor`): Prediction or output vector
ignore_index (int, optional): Specifies a target index that is ignored

Returns:
:class:`tuple` consisting of accuracy (:class:`float`), number correct (:class:`int`) and
total (:class:`int`)

Example:

>>> import torch
>>> from torchnlp.metrics import get_token_accuracy
>>> targets = torch.LongTensor([[1, 1], [2, 2], [3, 3]])
>>> outputs = torch.LongTensor([[1, 1], [2, 3], [4, 4]])
>>> accuracy, n_correct, n_total = get_token_accuracy(targets, outputs, ignore_index=3)
>>> accuracy
0.75
>>> n_correct
3.0
>>> n_total
4.0


def AddArg(self, argument):

    self.args.append(argument)
    if len(self.args) > self.number_of_args:
      raise errors.ParseError('Too many arguments for this expression.')

    elif len(self.args) == self.number_of_args:
      return True

    return False

Adds a new argument to this expression.

Args:
argument (str): argument to add.

Returns:
True if the argument is the last argument, False otherwise.

Raises:
ParseError: If there are too many arguments.


def get_losses(scope=None, loss_collection=ops.GraphKeys.LOSSES):
    return ops.get_collection(loss_collection, scope)

Gets the list of losses from the loss_collection.

Args:
scope: An optional scope name for filtering the losses to return.
loss_collection: Optional losses collection.

Returns:
a list of loss tensors.


def extract_possible_actions(self, state_key):

        if state_key in self.__state_action_list_dict:
            return self.__state_action_list_dict[state_key]
        else:
            action_list = []
            state_key_list = [action_list.extend(self.__state_action_list_dict[k]) for k in self.__state_action_list_dict.keys() if len([s for s in state_key if s in k]) > 0]
            return action_list

Concreat method.

Args:
state_key       The key of state. this value is point in map.

Returns:
[(x, y)]


def create_graph_from_data(self, data, **kwargs):
    self.arguments['{CITEST}'] = self.dir_CI_test[self.CI_test]
    self.arguments['{METHOD_INDEP}'] = self.dir_method_indep[self.method_indep]
    self.arguments['{DIRECTED}'] = 'TRUE'
    self.arguments['{ALPHA}'] = str(self.alpha)
    self.arguments['{NJOBS}'] = str(self.nb_jobs)
    self.arguments['{VERBOSE}'] = str(self.verbose).upper()
    results = self._run_pc(data, verbose=self.verbose)
    return nx.relabel_nodes(nx.DiGraph(results), {idx: i for (idx, i) in enumerate(data.columns)})

Run the PC algorithm.

Args:
data (pandas.DataFrame): DataFrame containing the data

Returns:
networkx.DiGraph: Solution given by PC on the given data.


def get_gated_grpc_tensors(self, matching_debug_op=None):

    with self._grpc_gated_lock:
      matching_debug_op = matching_debug_op or 'DebugIdentity'
      if matching_debug_op not in self._grpc_gated_tensors:

        node_name_to_op_type = dict(
            (node.name, node.op) for node in self._graph_def.node)

        gated = []
        for node in self._graph_def.node:
          if node.op == matching_debug_op:
            for attr_key in node.attr:
              if attr_key == 'gated_grpc' and node.attr[attr_key].b:
                node_name, output_slot, _, debug_op = (
                    debug_graphs.parse_debug_node_name(node.name))
                gated.append(
                    (node_name, node_name_to_op_type[node_name], output_slot,
                     debug_op))
                break
        self._grpc_gated_tensors[matching_debug_op] = gated

      return self._grpc_gated_tensors[matching_debug_op]

Extract all nodes with gated-gRPC debug ops attached.

Uses cached values if available.
This method is thread-safe.

Args:
graph_def: A tf.GraphDef proto.
matching_debug_op: Return tensors and nodes with only matching the
specified debug op name (optional). If `None`, will extract only
`DebugIdentity` debug ops.

Returns:
A list of (node_name, op_type, output_slot, debug_op) tuples.


def erase(self):
    try:
        if (not self.halted()):
            self.halt()
    except errors.JLinkException:
        pass
    res = self._dll.JLINK_EraseChip()
    if (res < 0):
        raise errors.JLinkEraseException(res)
    return res

Erases the flash contents of the device.

This erases the flash memory of the target device.  If this method
fails, the device may be left in an inoperable state.

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

Returns:
Number of bytes erased.


def log_abs_determinant(self, name='log_abs_det'):
    if self.is_square is False:
        raise NotImplementedError('Determinant not implemented for an operator that is expected to not be square.')
    with self._name_scope(name):
        return self._log_abs_determinant()

Log absolute value of determinant for every batch member.

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

Returns:
`Tensor` with shape `self.batch_shape` and same `dtype` as `self`.

Raises:
NotImplementedError:  If `self.is_square` is `False`.


def install(pkg, target='LocalSystem', store=False, allow_untrusted=False):

    if '*.' not in pkg:

        pkg = _quote(pkg)

    target = _quote(target)

    cmd = 'installer -pkg {0} -target {1}'.format(pkg, target)
    if store:
        cmd += ' -store'
    if allow_untrusted:
        cmd += ' -allowUntrusted'

    python_shell = False
    if '*.' in cmd:
        python_shell = True

    return __salt__['cmd.run_all'](cmd, python_shell=python_shell)

Install a pkg file

Args:
pkg (str): The package to install
target (str): The target in which to install the package to
store (bool): Should the package be installed as if it was from the
store?
allow_untrusted (bool): Allow the installation of untrusted packages?

Returns:
dict: A dictionary containing the results of the installation

CLI Example:

.. code-block:: bash

salt '*' macpackage.install test.pkg


def _configure_from_module(self, item):
    package = None
    if (item[0] == '.'):
        package = self.import_name
    obj = importlib.import_module(item, package=package)
    self.config.from_object(obj)
    return self

Configure from a module by import path.

Effectively, you give this an absolute or relative import path, it will
import it, and then pass the resulting object to
``_configure_from_object``.

Args:
item (str):
A string pointing to a valid import path.

Returns:
fleaker.App:
Returns itself.


def __init__(
      self, maximum_number_of_tasks=_MAXIMUM_NUMBER_OF_TASKS, use_zeromq=True):

    super(TaskMultiProcessEngine, self).__init__()
    self._enable_sigsegv_handler = False
    self._filter_find_specs = None
    self._last_worker_number = 0
    self._maximum_number_of_tasks = maximum_number_of_tasks
    self._merge_task = None
    self._merge_task_on_hold = None
    self._number_of_consumed_event_tags = 0
    self._number_of_consumed_events = 0
    self._number_of_consumed_reports = 0
    self._number_of_consumed_sources = 0
    self._number_of_consumed_warnings = 0
    self._number_of_produced_event_tags = 0
    self._number_of_produced_events = 0
    self._number_of_produced_reports = 0
    self._number_of_produced_sources = 0
    self._number_of_produced_warnings = 0
    self._number_of_worker_processes = 0
    self._path_spec_extractor = extractors.PathSpecExtractor()
    self._processing_configuration = None
    self._resolver_context = context.Context()
    self._session_identifier = None
    self._status = definitions.STATUS_INDICATOR_IDLE
    self._storage_merge_reader = None
    self._storage_merge_reader_on_hold = None
    self._task_queue = None
    self._task_queue_port = None
    self._task_manager = task_manager.TaskManager()
    self._use_zeromq = use_zeromq

Initializes an engine.

Args:
maximum_number_of_tasks (Optional[int]): maximum number of concurrent
tasks, where 0 represents no limit.
use_zeromq (Optional[bool]): True if ZeroMQ should be used for queuing
instead of Python's multiprocessing queue.


def __eq__(self, other):

    if not isinstance(other, DateTimeValues):
      return False

    normalized_timestamp = self._GetNormalizedTimestamp()
    other_normalized_timestamp = other._GetNormalizedTimestamp()

    if normalized_timestamp is None and other_normalized_timestamp is not None:
      return False

    if normalized_timestamp is not None and other_normalized_timestamp is None:
      return False

    return normalized_timestamp == other_normalized_timestamp

Determines if the date time values are equal to other.

Args:
other (DateTimeValues): date time values to compare against.

Returns:
bool: True if the date time values are equal to other.


def check_cuda_lib(path, check_soname=True):
    if not os.path.isfile(path):
        raise ConfigError('No library found under: ' + path)
    objdump = shutil.which('objdump')
    if check_soname and objdump is not None and (not _is_windows()):
        output = subprocess.check_output([objdump, '-p', path]).decode('utf-8')
        output = [line for line in output.splitlines() if 'SONAME' in line]
        sonames = [line.strip().split(' ')[-1] for line in output]
        if not any((soname == os.path.basename(path) for soname in sonames)):
            raise ConfigError('None of the libraries match their SONAME: ' + path)

Tests if a library exists on disk and whether its soname matches the filename.

Args:
path: the path to the library.
check_soname: whether to check the soname as well.

Raises:
ConfigError: If the library does not exist or if its soname does not match
the filename.


def sanity_check_ir_blocks_from_frontend(ir_blocks, query_metadata_table):
    if (not ir_blocks):
        raise AssertionError(u'Received no ir_blocks: {}'.format(ir_blocks))
    _sanity_check_fold_scope_locations_are_unique(ir_blocks)
    _sanity_check_no_nested_folds(ir_blocks)
    _sanity_check_query_root_block(ir_blocks)
    _sanity_check_output_source_follower_blocks(ir_blocks)
    _sanity_check_block_pairwise_constraints(ir_blocks)
    _sanity_check_mark_location_preceding_optional_traverse(ir_blocks)
    _sanity_check_every_location_is_marked(ir_blocks)
    _sanity_check_coerce_type_outside_of_fold(ir_blocks)
    _sanity_check_all_marked_locations_are_registered(ir_blocks, query_metadata_table)
    _sanity_check_registered_locations_parent_locations(query_metadata_table)

Assert that IR blocks originating from the frontend do not have nonsensical structure.

Args:
ir_blocks: list of BasicBlocks representing the IR to sanity-check

Raises:
AssertionError, if the IR has unexpected structure. If the IR produced by the front-end
cannot be successfully and correctly used to generate MATCH or Gremlin due to a bug,
this is the method that should catch the problem.


def resplit_datasets(dataset, other_dataset, random_seed=None, split=None):
    from torchnlp.datasets import Dataset
    concat = (dataset.rows + other_dataset.rows)
    shuffle(concat, random_seed=random_seed)
    if (split is None):
        return (Dataset(concat[:len(dataset)]), Dataset(concat[len(dataset):]))
    else:
        split = max(min(round((len(concat) * split)), len(concat)), 0)
        return (Dataset(concat[:split]), Dataset(concat[split:]))

Deterministic shuffle and split algorithm.

Given the same two datasets and the same ``random_seed``, the split happens the same exact way
every call.

Args:
dataset (lib.datasets.Dataset): First dataset.
other_dataset (lib.datasets.Dataset): Another dataset.
random_seed (int, optional): Seed to control the shuffle of both datasets.
split (float, optional): If defined it is the percentage of rows that first dataset gets
after split otherwise the original proportions are kept.

Returns:
:class:`lib.datasets.Dataset`, :class:`lib.datasets.Dataset`: Resplit datasets.


def search(self, filters):
    records = self.__model__.search(self.__five9__, filters)
    return self.__class__(self.__five9__, self.__model__, records)

Search Five9 given a filter.

Args:
filters (dict): A dictionary of search strings, keyed by the name
of the field to search.

Returns:
Environment: An environment representing the recordset.


def copy_file(self, file_id, dest_folder_id):
    return self.__request('POST', (('/files/' + unicode(file_id)) + '/copy'), data={'parent': {'id': unicode(dest_folder_id)}})

Copy file to new destination

Args:
file_id (int): ID of the folder.

dest_folder_id (int): ID of parent folder you are copying to.

Returns:
dict. Response from Box.

Raises:
BoxError: An error response is returned from Box (status_code >= 400).

BoxError: 409 - Item with the same name already exists.
In this case you will need download the file and upload a new version to your destination.
(Box currently doesn't have a method to copy a new verison.)

BoxHttpResponseError: Response from Box is malformed.

requests.exceptions.*: Any connection related problem.


def AddStationDecoration(self, index, color="

    tmpstr = str()
    num_stations = len(self._stations)
    ind = int(index)
    if self._stations:
      if 0<ind<num_stations:
        y = self._stations[ind]
        tmpstr = '<polyline class="Dec" stroke="%s" points="%s,%s,%s,%s" />' \
          % (color, 20, 20+y+.5, self._gwidth+20, 20+y+.5)
    self._decorators.append(tmpstr)

Flushes existing decorations and highlights the given station-line.

Args:
# Integer, index of stop to be highlighted.
index: 4
# An optional string with a html color code
color: "#fff"


def softmax_cross_entropy_with_logits(logits, targets, vocab_dim, z_loss=0.0):
    if (logits.shape != targets.shape):
        raise ValueError(('logits shape must equal targets shapelogits=%s targets=%s' % (logits.to_string, targets.to_string)))
    if (vocab_dim not in logits.shape.dims):
        raise ValueError('vocab_dim must be in logits.shape.dims')
    log_z = mtf.reduce_logsumexp(logits, vocab_dim)
    log_softmax = (logits - log_z)
    loss = mtf.negative(mtf.reduce_sum((log_softmax * targets), reduced_dim=vocab_dim))
    if (z_loss != 0):
        loss += (z_loss * mtf.square(log_z))
    return loss

Per-example softmax loss.

if z_loss is nonzero, we add a loss equal to z_loss*log(z)^2, where z is the
partition function.  Example value: z_loss=1e-4.  Two uses of z_loss are:
- To keep the logits from drifting too far from zero, which can cause
unacceptable roundoff errors in bfloat16.
- To encourage the logits to be normalized log-probabilities.

Args:
logits: a mtf.Tensor whose shape contains vocab_dim
targets: a mtf.Tensor with the same shape as logits
vocab_dim: a mtf.Dimension
z_loss: a float

Returns:
a mtf.Tensor whose shape is equal to logits.shape - vocab_dim

Raises:
ValueError: if the shapes do not match.


def from_library(lib):
    if not lib.function and (not lib.gradient):
        return []
    funcs = {fdef.signature.name: fdef for fdef in lib.function}
    for g in lib.gradient:
        if g.function_name not in funcs:
            raise ValueError(f"FunctionDefLibrary missing '{g.function_name}' FunctionDef\n{lib}")
        if g.gradient_func not in funcs:
            raise ValueError(f"FunctionDefLibrary missing '{g.gradient_func}' FunctionDef\n{lib}")
    func_to_grad = collections.defaultdict(lambda: None)
    grad_to_funcs = collections.defaultdict(list)
    for gdef in lib.gradient:
        func_to_grad[gdef.function_name] = gdef.gradient_func
        grad_to_funcs[gdef.gradient_func].append(gdef.function_name)
    ready = [fdef for fdef in lib.function if func_to_grad[fdef.signature.name] is None]
    if not ready:
        raise ValueError(f'FunctionDefLibrary contains cyclic gradient functions!\n{lib}')
    initialized = {}
    while ready:
        fdef = ready.pop()
        name = fdef.signature.name
        grad = initialized.get(func_to_grad[name])
        if func_to_grad[name]:
            assert grad
        defined_func = _from_definition(fdef, grad_func=grad)
        initialized[name] = defined_func
        ready.extend((funcs[f] for f in grad_to_funcs[name]))
    return initialized.values()

Creates _DefinedFunctions initialized from a FunctionDefLibrary proto.

This method handles assigning the correct gradient functions to each
function.

Args:
lib: a FunctionDefLibrary

Returns:
A list of _DefinedFunctions

Raises:
ValueError: `lib` is invalid


def load_variants(adapter, vcf_obj, case_obj, skip_case_id=False, gq_treshold=None, max_window=3000, variant_type='snv'):
    if (variant_type == 'snv'):
        nr_variants = case_obj['nr_variants']
    else:
        nr_variants = case_obj['nr_sv_variants']
    nr_inserted = 0
    case_id = case_obj['case_id']
    if skip_case_id:
        case_id = None
    with click.progressbar(vcf_obj, label='Inserting variants', length=nr_variants) as bar:
        variants = (build_variant(variant, case_obj, case_id, gq_treshold) for variant in bar)
    if (variant_type == 'sv'):
        for sv_variant in variants:
            if (not sv_variant):
                continue
            adapter.add_structural_variant(variant=sv_variant, max_window=max_window)
            nr_inserted += 1
    if (variant_type == 'snv'):
        nr_inserted = adapter.add_variants(variants)
    LOG.info('Inserted %s variants of type %s', nr_inserted, variant_type)
    return nr_inserted

Load variants for a family into the database.

Args:
adapter (loqusdb.plugins.Adapter): initialized plugin
case_obj(Case): dict with case information
nr_variants(int)
skip_case_id (bool): whether to include the case id on variant level
or not
gq_treshold(int)
max_window(int): Specify the max size for sv windows
variant_type(str): 'sv' or 'snv'

Returns:
nr_inserted(int)


def inside_cell(self, r):
    centre = np.array([0.5, 0.5, 0.5])
    new_r = self.nearest_image(centre, r)
    return new_r

Given a fractional-coordinate, if this lies outside the cell return the equivalent point inside the cell.

Args:
r (np.array): Fractional coordinates of a point (this may be outside the cell boundaries).

Returns:
(np.array): Fractional coordinates of an equivalent point, inside the cell boundaries.


def __init__(self, unique_identifier=None):

        super(ObtainLeaseRequestPayload, self).__init__(
            enums.Tags.REQUEST_PAYLOAD
        )

        self._unique_identifier = None
        self.unique_identifier = unique_identifier

Construct an ObtainLease request payload struct.

Args:
unique_identifier (string): The ID of the managed object (e.g.,
a public key) to obtain a lease for. Optional, defaults to
None.


def create(self, image, command=None, **kwargs):
    if isinstance(image, Image):
        image = image.id
    kwargs['image'] = image
    kwargs['command'] = command
    kwargs['version'] = self.client.api._version
    create_kwargs = _create_container_args(kwargs)
    resp = self.client.api.create_container(**create_kwargs)
    return self.get(resp['Id'])

Create a container without starting it. Similar to ``docker create``.

Takes the same arguments as :py:meth:`run`, except for ``stdout``,
``stderr``, and ``remove``.

Returns:
A :py:class:`Container` object.

Raises:
:py:class:`docker.errors.ImageNotFound`
If the specified image does not exist.
:py:class:`docker.errors.APIError`
If the server returns an error.


def expert_to_batch_indices(self):
    return tf.split(self._batch_index, self._part_sizes_tensor, 0, num=self._num_experts)

Batch indices corresponding to the examples in the per-expert `Tensor`s.

Returns:
a list of `num_experts` one-dimensional `Tensor`s with type `tf.int64`
and shapes `[expert_batch_size_i]`


def _train_model(self, checkpoint_dir, num_steps):
    with ops.Graph().as_default():
        random_seed.set_random_seed(0)
        tf_inputs = constant_op.constant(self._inputs, dtype=dtypes.float32)
        tf_labels = constant_op.constant(self._labels, dtype=dtypes.float32)
        tf_predictions = logistic_classifier(tf_inputs)
        loss_op = losses.log_loss(labels=tf_labels, predictions=tf_predictions)
        optimizer = gradient_descent.GradientDescentOptimizer(learning_rate=1.0)
        train_op = optimizer.minimize(loss_op, training.get_or_create_global_step())
        with monitored_session.MonitoredTrainingSession(checkpoint_dir=checkpoint_dir, hooks=[basic_session_run_hooks.StopAtStepHook(num_steps)]) as session:
            loss = None
            while not session.should_stop():
                _, loss = session.run([train_op, loss_op])
            if num_steps >= 300:
                assert loss < 0.015

Trains a simple classification model.

Note that the data has been configured such that after around 300 steps,
the model has memorized the dataset (e.g. we can expect %100 accuracy).

Args:
checkpoint_dir: The directory where the checkpoint is written to.
num_steps: The number of steps to train for.


def Categories(unicode_dir=_UNICODE_DIR):

  categories = {}

  def DoLine(codes, fields):

    category = fields[2]
    categories.setdefault(category, []).extend(codes)

    if len(category) > 1:
      short = category[0]
      categories.setdefault(short, []).extend(codes)

  ReadUnicodeTable(unicode_dir+"/UnicodeData.txt", 15, DoLine)
  return categories

Returns dict mapping category names to code lists.

Args:
unicode_dir: Unicode data directory

Returns:
dict mapping category names to code lists


def lookup(self, keys, name=None):
    key_tensor = keys
    if isinstance(keys, (sparse_tensor.SparseTensor, internal.RaggedTensor)):
        key_tensor = keys.values
    if keys.dtype.base_dtype != self._key_dtype:
        raise TypeError(f'Dtype of argument `keys` must be {self._key_dtype}, received: {keys.dtype}')
    with ops.name_scope(name, '%s_Lookup' % self.name, (self.resource_handle, key_tensor, self._default_value)):
        values = gen_lookup_ops.lookup_table_find_v2(self.resource_handle, key_tensor, self._default_value)
    values.set_shape(key_tensor.get_shape())
    if isinstance(keys, sparse_tensor.SparseTensor):
        return sparse_tensor.SparseTensor(keys.indices, values, keys.dense_shape)
    elif isinstance(keys, internal.RaggedTensor):
        return keys.with_values(values)
    else:
        return values

Looks up `keys` in a table, outputs the corresponding values.

The `default_value` is used for keys not present in the table.

Args:
keys: Keys to look up. May be either a `SparseTensor` or dense `Tensor`.
name: A name for the operation (optional).

Returns:
A `SparseTensor` if keys are sparse, a `RaggedTensor` if keys are ragged,
otherwise a dense `Tensor`.

Raises:
TypeError: when `keys` or `default_value` doesn't match the table data
types.


def construct_field(model_name, field_name, field_type, all_models, **kwargs):

    field_type_parts = field_type.split('->')
    _field_type = field_type_parts[0].strip().split('[]')[0].strip()
    back_populates = field_type_parts[1].strip() if len(field_type_parts) > 1 else None
    error_context = kwargs.pop('error_context', StatikErrorContext())
    _kwargs = copy(kwargs)
    _kwargs['back_populates'] = back_populates

    if _field_type not in FIELD_TYPES and _field_type not in all_models:
        raise InvalidFieldTypeError(
            model_name,
            field_name,
            context=error_context
        )

    if _field_type in FIELD_TYPES:
        return FIELD_TYPES[_field_type](field_name, **_kwargs)

    if field_type_parts[0].strip().endswith('[]'):
        return StatikManyToManyField(field_name, _field_type, **_kwargs)

    return StatikForeignKeyField(field_name, _field_type, **_kwargs)

Helper function to build a field from the given field name and
type.

Args:
model_name: The name of the model for which we're building this field.
field_name: The name of the field to build.
field_type: A string indicator as to which field type must be built.
all_models: A list containing the names of all of the models, which
will help us when building foreign key lookups.


def _is_unannotated_contextmanager_exit(self, func: _function_base.Function, args: function.Args) -> bool:
    if not isinstance(func, _function_base.BoundInterpreterFunction):
        return False
    if not self.name.endswith('.__exit__'):
        return False
    if self.signature.has_param_annotations:
        return False
    return len(args.posargs) == 4 and (not args.has_namedargs()) and (not args.starargs) and (not args.starstarargs)

Returns whether this is an unannotated contextmanager __exit__ method.

If this is a bound method named __exit__ that has no type annotations and is
passed four positional args and nothing else, then we assume that it is a
contextmanager's __exit__ method that needs annotations added.

Args:
func: A method binding for self.
args: Passed arguments.


def __init__(self, func=None, max_threads=10, token=None):

    self.thread_pool = threadpool.ThreadPool.Factory(self.THREAD_POOL_NAME,
                                                     max_threads)
    self.thread_pool.Start()
    self.token = token
    self.func = func
    self.broken_subjects = []

    self.out_queue = queue.Queue()

Iterate over all clients in a threadpool.

Args:
func: A function to call with each client urn.
max_threads: Number of threads to use.
token: Auth token.

Raises:
ValueError: If function not specified.


def depth_june_average_ground_temperature(self, value=None):
    if (value is not None):
        try:
            value = float(value)
        except ValueError:
            raise ValueError('value {} need to be of type float for field `depth_june_average_ground_temperature`'.format(value))
    self._depth_june_average_ground_temperature = value

Corresponds to IDD Field `depth_june_average_ground_temperature`

Args:
value (float): value for IDD Field `depth_june_average_ground_temperature`
Unit: C
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 get_group(self, name, user_name=None):
    self.project_service.set_auth(self._token_project)
    return self.project_service.get_group(name, user_name)

Get information on the given group or whether or not a user is a member
of the group.

Args:
name (string): Name of group to query.
user_name (optional[string]): Supply None if not interested in
determining if user is a member of the given group.

Returns:
(mixed): Dictionary if getting group information or bool if a user
name is supplied.

Raises:
requests.HTTPError on failure.


def equals(self, rhs):
    try:
        return isinstance(rhs, self._class_name)
    except TypeError:
        return (type(rhs) == type(self._class_name))

Check to see if the RHS is an instance of class_name.

Args:
# rhs: the right hand side of the test
rhs: object

Returns:
bool


def generate_cot(context, parent_path=None):
    body = generate_cot_body(context)
    schema = load_json_or_yaml(context.config['cot_schema_path'], is_path=True, exception=ScriptWorkerException, message="Can't read schema file {}: %(exc)s".format(context.config['cot_schema_path']))
    validate_json_schema(body, schema, name='chain of trust')
    body = format_json(body)
    parent_path = (parent_path or os.path.join(context.config['artifact_dir'], 'public'))
    unsigned_path = os.path.join(parent_path, 'chain-of-trust.json')
    write_to_file(unsigned_path, body)
    if context.config['sign_chain_of_trust']:
        ed25519_signature_path = '{}.sig'.format(unsigned_path)
        ed25519_private_key = ed25519_private_key_from_file(context.config['ed25519_private_key_path'])
        ed25519_signature = ed25519_private_key.sign(body.encode('utf-8'))
        write_to_file(ed25519_signature_path, ed25519_signature, file_type='binary')
    return body

Format and sign the cot body, and write to disk.

Args:
context (scriptworker.context.Context): the scriptworker context.
parent_path (str, optional): The directory to write the chain of trust
artifacts to.  If None, this is ``artifact_dir/public/``.
Defaults to None.

Returns:
str: the contents of the chain of trust artifact.

Raises:
ScriptWorkerException: on schema error.


def get_nc_attrs(nc):
    meta = {'experiment': nc.experiment_id, 'frequency': nc.frequency, 'institute': nc.institute_id, 'model': nc.model_id, 'modeling_realm': nc.modeling_realm, 'ensemble_member': 'r{}i{}p{}'.format(nc.realization, nc.initialization_method, nc.physics_version)}
    variable_name = get_var_name(nc)
    if variable_name:
        meta.update({'variable_name': variable_name})
    return meta

Gets netCDF file metadata attributes.

Arguments:
nc (netCDF4.Dataset): an open NetCDF4 Dataset to pull attributes from.

Returns:
dict: Metadata as extracted from the netCDF file.


def _classify_segment(self, address, length):

        end_address = address + length - 1

        _, start_seg = self._find_address(address)
        _, end_seg = self._find_address(end_address)

        if start_seg is not None or end_seg is not None:
            raise ArgumentError("Overlapping segments are not yet supported", address=address, length=length)

        return DisjointSegment()

Determine how a new data segment fits into our existing world

Params:
address (int): The address we wish to classify
length (int): The length of the segment

Returns:
int: One of SparseMemoryMap.prepended


def instantiate_interface(virtual_iface, config, loop):

    if virtual_iface == 'null':
        return StandardDeviceServer(None, {}, loop=loop)

    conf = {}
    if 'interface' in config:
        conf = config['interface']

    try:
        reg = ComponentRegistry()
        if virtual_iface.endswith('.py'):
            _name, iface = reg.load_extension(virtual_iface, class_filter=AbstractDeviceServer, unique=True)
        else:
            _name, iface = reg.load_extensions('iotile.device_server', name_filter=virtual_iface,
                                               class_filter=AbstractDeviceServer, unique=True)

        return iface(None, conf, loop=loop)
    except ArgumentError as err:
        print("ERROR: Could not load device_server (%s): %s" % (virtual_iface, err.msg))
        sys.exit(1)

Find a virtual interface by name and instantiate it

Args:
virtual_iface (string): The name of the pkg_resources entry point corresponding to
the interface.  It should be in group iotile.virtual_interface
config (dict): A dictionary with a 'interface' key with the config info for configuring
this virtual interface.  This is optional.

Returns:
VirtualInterface: The instantiated subclass of VirtualInterface


def stretch_hist_equalize(self, approximate=False):

        logger.info("Perform a histogram equalized contrast stretch.")

        nwidth = 2048.
        logger.debug("Make histogram bins having equal amount of data, " +
                     "using numpy percentile function:")

        def _band_hist(band_data):
            cdf = da.arange(0., 1., 1. / nwidth, chunks=nwidth)
            if approximate:

                flat_data = band_data.ravel()

                bins = da.percentile(flat_data[da.notnull(flat_data)],
                                     cdf * 100.)
            else:
                bins = dask.delayed(np.nanpercentile)(band_data, cdf * 100.)
                bins = da.from_delayed(bins, shape=(nwidth,), dtype=cdf.dtype)
            res = dask.delayed(np.interp)(band_data, bins, cdf)
            res = da.from_delayed(res, shape=band_data.shape,
                                  dtype=band_data.dtype)
            return res

        band_results = []
        for band in self.data['bands'].values:
            if band == 'A':
                continue
            band_data = self.data.sel(bands=band)
            res = _band_hist(band_data.data)
            band_results.append(res)

        if 'A' in self.data.coords['bands'].values:
            band_results.append(self.data.sel(bands='A'))
        self.data.data = da.stack(band_results,
                                  axis=self.data.dims.index('bands'))

Stretch the current image's colors through histogram equalization.

Args:
approximate (bool): Use a faster less-accurate percentile
calculation. At the time of writing the dask
version of `percentile` is not as accurate as
the numpy version. This will likely change in
the future. Current dask version 0.17.


def add_delta_deltas(filterbanks, name=None):
    delta_filter = np.array([2, 1, 0, (- 1), (- 2)])
    delta_delta_filter = scipy.signal.convolve(delta_filter, delta_filter, 'full')
    delta_filter_stack = np.array([((([0] * 4) + [1]) + ([0] * 4)), ((([0] * 2) + list(delta_filter)) + ([0] * 2)), list(delta_delta_filter)], dtype=np.float32).T[(:, None, None, :)]
    delta_filter_stack /= np.sqrt(np.sum((delta_filter_stack ** 2), axis=0, keepdims=True))
    filterbanks = tf.nn.conv2d(filterbanks, delta_filter_stack, [1, 1, 1, 1], 'SAME', data_format='NHWC', name=name)
    return filterbanks

Compute time first and second-order derivative channels.

Args:
filterbanks: float32 tensor with shape [batch_size, len, num_bins, 1]
name: scope name

Returns:
float32 tensor with shape [batch_size, len, num_bins, 3]


def _from_any_pb(pb_type, any_pb):
    msg = pb_type()
    if (not any_pb.Unpack(msg)):
        raise TypeError('Could not convert {} to {}'.format(any_pb.__class__.__name__, pb_type.__name__))
    return msg

Converts an Any protobuf to the specified message type

Args:
pb_type (type): the type of the message that any_pb stores an instance
of.
any_pb (google.protobuf.any_pb2.Any): the object to be converted.

Returns:
pb_type: An instance of the pb_type message.

Raises:
TypeError: if the message could not be converted.


def set_hparam(self, name, value):

    param_type, is_list = self._hparam_types[name]
    if isinstance(value, list):
      if not is_list:
        raise ValueError(
            'Must not pass a list for single-valued parameter: %s' % name)
      setattr(self, name, [
          _cast_to_type_if_compatible(name, param_type, v) for v in value])
    else:
      if is_list:
        raise ValueError(
            'Must pass a list for multi-valued parameter: %s.' % name)
      setattr(self, name, _cast_to_type_if_compatible(name, param_type, value))

Set the value of an existing hyperparameter.

This function verifies that the type of the value matches the type of the
existing hyperparameter.

Args:
name: Name of the hyperparameter.
value: New value of the hyperparameter.

Raises:
KeyError: If the hyperparameter doesn't exist.
ValueError: If there is a type mismatch.


def pretty_print_counters(counters):

  totals = collections.defaultdict(int)
  for (name, val) in counters:
    prefixes = [name[:i] for i in xrange(len(name)) if name[i] == "/"] + [name]
    for p in prefixes:
      totals[p] += val
  parts = []
  for name, val in sorted(six.iteritems(totals)):
    parts.append(" " * name.count("/") + "%s: %.3g" % (name, val))
  return "\n".join(parts)

print counters hierarchically.

Each counter is a pair of a string and a number.
The string can have slashes, meaning that the number also counts towards
each prefix.  e.g.  "parameters/trainable" counts towards both "parameters"
and "parameters/trainable".

Args:
counters: a list of (string, number) pairs

Returns:
a string


def find_n_data_blocks(self):
    self.file_obj.seek(0)
    (header0, data_idx0) = self.read_header()
    self.file_obj.seek(data_idx0)
    block_size = int(header0['BLOCSIZE'])
    n_bits = int(header0['NBITS'])
    self.file_obj.seek(int(header0['BLOCSIZE']), 1)
    n_blocks = 1
    end_found = False
    while (not end_found):
        try:
            (header, data_idx) = self.read_header()
            self.file_obj.seek(data_idx)
            self.file_obj.seek(header['BLOCSIZE'], 1)
            n_blocks += 1
        except EndOfFileError:
            end_found = True
            break
    self.file_obj.seek(0)
    return n_blocks

Seek through the file to find how many data blocks there are in the file

Returns:
n_blocks (int): number of data blocks in the file


def dump(self, output, close_after_write=True):

        self.open(output)
        try:
            self.make_worksheet(self.table_name)
            self.write_table()
        finally:
            if close_after_write:
                self.close()

Write a worksheet to the current workbook.

Args:
output (str):
Path to the workbook file to write.
close_after_write (bool, optional):
Close the workbook after write.
Defaults to |True|.


def token_to_id(self, token):
    token = self.process_token(token)
    return self._token2id.get(token, (len(self._token2id) - 1))

Get the token_id of given token.

Args:
token (str): token from vocabulary.

Returns:
int: int id of token.


def _parse_dbpath(dbpath):

        if isinstance(dbpath, list):

            dbpath = '|'.join(dbpath)

        if not dbpath.endswith('$'):
            dbpath = '(%s)$' % dbpath

        return dbpath

Converts the dbpath to a regexp pattern.

Transforms dbpath from a string or an array of strings to a
regexp pattern which will be used to match database names.

Args:
dbpath: a string or an array containing the databases to be matched
from a cluster.

Returns:
A regexp pattern that will match any of the desired databases on
on a cluster.


def UploadOperations(self, operations, is_last=False):
    if self._is_last:
        raise googleads.errors.AdWordsBatchJobServiceInvalidOperationError("Can't add new operations to a completed incremental upload.")
    req = self._request_builder.BuildUploadRequest(self._upload_url, operations, current_content_length=self._current_content_length, is_last=is_last)
    try:
        _batch_job_logger.debug('Outgoing request: %s %s %s', req.get_full_url(), req.headers, req.data)
        self._url_opener.open(req)
        if _batch_job_logger.isEnabledFor(logging.INFO):
            _batch_job_logger.info('Request summary: %s', self._ExtractRequestSummaryFields(req))
    except urllib2.HTTPError as e:
        if (e.code != 308):
            if _batch_job_logger.isEnabledFor(logging.WARNING):
                _batch_job_logger.warning('Request summary: %s', self._ExtractRequestSummaryFields(req, error=e))
            raise
    self._current_content_length += len(req.data)
    self._is_last = is_last

Uploads operations to the given uploadUrl in incremental steps.

Note: Each list of operations is expected to contain operations of the
same type, similar to how one would normally send operations in an
AdWords API Service request.

Args:
operations: one or more lists of operations as would be sent to the
AdWords API for the associated service.
is_last: a boolean indicating whether this is the final increment to be
added to the batch job.


class XLMPoolerStartLogits(nn.Module):

    def __init__(self, config: XLMConfig):
        super().__init__()
        self.dense = nn.Linear(config.hidden_size, 1)

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

        x = self.dense(hidden_states).squeeze(-1)
        if p_mask is not None:
            if p_mask.dtype == torch.float16:
                x = x * (1 - p_mask) - 65500 * p_mask
            else:
                x = x * (1 - p_mask) - 1e+30 * p_mask
        return x

Compute SQuAD start logits from sequence hidden states.

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


def transform(node, ctx):
    node = qual_names.resolve(node)
    node = CallTreeTransformer(ctx).visit(node)
    return node

Transform function call to the compiled counterparts.

Args:
node: AST
ctx: EntityContext
Returns:
A tuple (node, new_names):
node: The transformed AST
new_names: set(string), containing any newly-generated names


def _ParseIdentifierMappingRecord(
      self, parser_mediator, table_name, esedb_record):

    record_values = self._GetRecordValues(
        parser_mediator, table_name, esedb_record)

    identifier = record_values.get('IdIndex', None)
    if identifier is None:
      parser_mediator.ProduceExtractionWarning(
          'IdIndex value missing from table: SruDbIdMapTable')
      return None, None

    identifier_type = record_values.get('IdType', None)
    if identifier_type not in self._SUPPORTED_IDENTIFIER_TYPES:
      parser_mediator.ProduceExtractionWarning(
          'unsupported IdType value: {0!s} in table: SruDbIdMapTable'.format(
              identifier_type))
      return None, None

    mapped_value = record_values.get('IdBlob', None)
    if mapped_value is None:
      parser_mediator.ProduceExtractionWarning(
          'IdBlob value missing from table: SruDbIdMapTable')
      return None, None

    if identifier_type == 3:
      try:
        fwnt_identifier = pyfwnt.security_identifier()
        fwnt_identifier.copy_from_byte_stream(mapped_value)
        mapped_value = fwnt_identifier.get_string()
      except IOError:
        parser_mediator.ProduceExtractionWarning(
            'unable to decode IdBlob value as Windows NT security identifier')
        return None, None

    else:
      try:
        mapped_value = mapped_value.decode('utf-16le').rstrip('\0')
      except UnicodeDecodeError:
        parser_mediator.ProduceExtractionWarning(
            'unable to decode IdBlob value as UTF-16 little-endian string')
        return None, None

    return identifier, mapped_value

Extracts an identifier mapping from a SruDbIdMapTable record.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
table_name (str): name of the table the record is stored in.
esedb_record (pyesedb.record): record.

Returns:
tuple[int, str]: numeric identifier and its string representation or
None, None if no identifier mapping can be retrieved from the record.


def from_json(cls, data):
    required_keys = ('name', 'day_type', 'location', 'dry_bulb_condition', 'humidity_condition', 'wind_condition', 'sky_condition')
    for key in required_keys:
        assert (key in data), 'Required key "{}" is missing!'.format(key)
    return cls(data['name'], data['day_type'], Location.from_json(data['location']), DryBulbCondition.from_json(data['dry_bulb_condition']), HumidityCondition.from_json(data['humidity_condition']), WindCondition.from_json(data['wind_condition']), SkyCondition.from_json(data['sky_condition']))

Create a Design Day from a dictionary.

Args:
data = {
"name": string,
"day_type": string,
"location": ladybug Location schema,
"dry_bulb_condition": ladybug DryBulbCondition schema,
"humidity_condition": ladybug HumidityCondition schema,
"wind_condition": ladybug WindCondition schema,
"sky_condition": ladybug SkyCondition schema}


def add(self, node):

        if node.parent_id != _node.Root.ID:
            raise exception.InvalidException('Not a top level node')

        self._nodes[node.id] = node
        self._nodes[node.parent_id].append(node, False)

Register a top level node (and its children) for syncing up to the server. There's no need to call this for nodes created by
:py:meth:`createNote` or :py:meth:`createList` as they are automatically added.

LoginException: If :py:meth:`login` has not been called.
Args:
node (gkeepapi.node.Node): The node to sync.

Raises:
Invalid: If the parent node is not found.


def _get_params(mcs, bases, namespace):
    params = [(name, namespace.pop(name)) for (name, attribute) in list(namespace.items()) if isinstance(attribute, BaseParam)]
    for base in reversed(bases):
        if hasattr(base, mcs._params_storage_key):
            params = (list(getattr(base, mcs._params_storage_key).items()) + params)
    return OrderedDict(params)

Create params dictionary to be used in resource class namespace.

Pop all parameter objects from attributes dict (namespace)
and store them under _params_storage_key atrribute.
Also collect all params from base classes in order that ensures
params can be overriden.

Args:
bases: all base classes of created resource class
namespace (dict): namespace as dictionary of attributes


def directed_bipartition_of_one(seq):
    bipartitions = list(bipartition_of_one(seq))
    return chain(bipartitions, reverse_elements(bipartitions))

Generate directed bipartitions where one part is of length 1.

Args:
seq (Iterable): The sequence to partition.

Returns:
list[tuple[tuple]]: A list of tuples containing each of the two
partitions.

Example:
>>> partitions = directed_bipartition_of_one((1, 2, 3))
>>> list(partitions)  # doctest: +NORMALIZE_WHITESPACE
[((1,), (2, 3)),
((2,), (1, 3)),
((3,), (1, 2)),
((2, 3), (1,)),
((1, 3), (2,)),
((1, 2), (3,))]


def print_start_trigger(self, type):

        types = {'recieved': 1,
                 'filled': 2,
                 'num_recieved': 3}

        if type in types:
            self.send('^PT'+chr(types[type]))
        else:
            raise RuntimeError('Invalid type.')

Set print start trigger.

Args:
type: The type of trigger you desire.
Returns:
None
Raises:
RuntimeError: Invalid type.


def _AddRestoreOps(self, filename_tensor, saveables, restore_sequentially, reshape, preferred_shard=-1, name='restore_all'):
    all_tensors = self.bulk_restore(filename_tensor, saveables, preferred_shard, restore_sequentially)
    assign_ops = []
    idx = 0
    for saveable in saveables:
        shapes = None
        if reshape:
            shapes = []
            for spec in saveable.specs:
                v = spec.tensor
                shape = v.get_shape()
                if not shape.is_fully_defined():
                    shape = array_ops.shape(v)
                shapes.append(shape)
        saveable_tensors = all_tensors[idx:idx + len(saveable.specs)]
        idx += len(saveable.specs)
        assign_ops.append(saveable.restore(saveable_tensors, shapes))
    return control_flow_ops.group(*assign_ops, name=name)

Add operations to restore saveables.

Args:
filename_tensor: Tensor for the path of the file to load.
saveables: A list of SaveableObject objects.
restore_sequentially: True if we want to restore variables sequentially
within a shard.
reshape: True if we want to reshape loaded tensors to the shape of the
corresponding variable.
preferred_shard: Shard to open first when loading a sharded file.
name: Name for the returned op.

Returns:
An Operation that restores the variables.


def __chunk(segment, abbr=False):

    names = ('north', 'east', 'south', 'west', 'north')
    if not abbr:
        sjoin = '-'
    else:
        names = [s[0].upper() for s in names]
        sjoin = ''
    if segment % 2 == 0:
        return (names[segment].capitalize(),
                sjoin.join((names[segment].capitalize(), names[segment],
                            names[segment + 1])),
                sjoin.join((names[segment].capitalize(), names[segment + 1])),
                sjoin.join((names[segment + 1].capitalize(), names[segment],
                            names[segment + 1])))
    else:
        return (names[segment].capitalize(),
                sjoin.join((names[segment].capitalize(), names[segment + 1],
                            names[segment])),
                sjoin.join((names[segment + 1].capitalize(), names[segment])),
                sjoin.join((names[segment + 1].capitalize(),
                            names[segment + 1], names[segment])))

Generate a ``tuple`` of compass direction names.

Args:
segment (list): Compass segment to generate names for
abbr (bool): Names should use single letter abbreviations

Returns:
bool: Direction names for compass segment


def decode_raw_v1(input_bytes=None, out_type=None, little_endian=True, name=None, bytes=None):
    input_bytes = deprecation.deprecated_argument_lookup('input_bytes', input_bytes, 'bytes', bytes)
    if out_type is None:
        raise ValueError("decode_raw_v1() missing 1 positional argument: 'out_type'")
    return gen_parsing_ops.decode_raw(input_bytes, out_type, little_endian=little_endian, name=name)

Convert raw byte strings into tensors.

Args:
input_bytes:
Each element of the input Tensor is converted to an array of bytes.
out_type:
`DType` of the output. Acceptable types are `half`, `float`, `double`,
`int32`, `uint16`, `uint8`, `int16`, `int8`, `int64`.
little_endian:
Whether the `input_bytes` data is in little-endian format. Data will be
converted into host byte order if necessary.
name: A name for the operation (optional).
bytes: Deprecated parameter. Use `input_bytes` instead.

Returns:
A `Tensor` object storing the decoded bytes.


def orth_gs(order, dist, normed=False, sort='GR', cross_truncation=1.0, **kws):
    logger = logging.getLogger(__name__)
    dim = len(dist)
    if isinstance(order, int):
        if (order == 0):
            return chaospy.poly.Poly(1, dim=dim)
        basis = chaospy.poly.basis(0, order, dim, sort, cross_truncation=cross_truncation)
    else:
        basis = order
    basis = list(basis)
    polynomials = [basis[0]]
    if normed:
        for idx in range(1, len(basis)):
            for idy in range(idx):
                orth = chaospy.descriptives.E((basis[idx] * polynomials[idy]), dist, **kws)
                basis[idx] = (basis[idx] - (polynomials[idy] * orth))
            norms = chaospy.descriptives.E((polynomials[(- 1)] ** 2), dist, **kws)
            if (norms <= 0):
                logger.warning('Warning: Polynomial cutoff at term %d', idx)
                break
            basis[idx] = (basis[idx] / numpy.sqrt(norms))
            polynomials.append(basis[idx])
    else:
        norms = [1.0]
        for idx in range(1, len(basis)):
            for idy in range(idx):
                orth = chaospy.descriptives.E((basis[idx] * polynomials[idy]), dist, **kws)
                basis[idx] = (basis[idx] - ((polynomials[idy] * orth) / norms[idy]))
            norms.append(chaospy.descriptives.E((polynomials[(- 1)] ** 2), dist, **kws))
            if (norms[(- 1)] <= 0):
                logger.warning('Warning: Polynomial cutoff at term %d', idx)
                break
            polynomials.append(basis[idx])
    return chaospy.poly.Poly(polynomials, dim=dim, shape=(len(polynomials),))

Gram-Schmidt process for generating orthogonal polynomials.

Args:
order (int, Poly):
The upper polynomial order. Alternative a custom polynomial basis
can be used.
dist (Dist):
Weighting distribution(s) defining orthogonality.
normed (bool):
If True orthonormal polynomials will be used instead of monic.
sort (str):
Ordering argument passed to poly.basis. If custom basis is used,
argument is ignored.
cross_truncation (float):
Use hyperbolic cross truncation scheme to reduce the number of
terms in expansion.

Returns:
(Poly):
The orthogonal polynomial expansion.

Examples:
>>> Z = chaospy.J(chaospy.Normal(), chaospy.Normal())
>>> print(chaospy.around(chaospy.orth_gs(2, Z), 4))
[1.0, q1, q0, q1^2-1.0, q0q1, q0^2-1.0]


def EqualTo(self, value):
    self._awql = self._CreateSingleValueCondition(value, '=')
    return self._query_builder

Sets the type of the WHERE clause as "equal to".

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

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


def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var, var_default):
    var = environ_cp.get(var_name)
    if var is None:
        var = get_input(ask_for_var)
        print('\n')
    if not var:
        var = var_default
    return var

Get var_name either from env, or user or default.

If var_name has been set as environment variable, use the preset value, else
ask for user input. If no input is provided, the default is used.

Args:
environ_cp: copy of the os.environ.
var_name: string for name of environment variable, e.g. "TF_NEED_CUDA".
ask_for_var: string for how to ask for user input.
var_default: default value string.

Returns:
string value for var_name


def ensure_mingw_drive(win32_path):
    r
    win32_drive, _path = splitdrive(win32_path)
    mingw_drive = '/' + win32_drive[:-1].lower()
    mingw_path = mingw_drive + _path
    return mingw_path

r""" replaces windows drives with mingw style drives

Args:
win32_path (str):

CommandLine:
python -m utool.util_path --test-ensure_mingw_drive

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_path import *  # NOQA
>>> win32_path = r'C:/Program Files/Foobar'
>>> result = ensure_mingw_drive(win32_path)
>>> print(result)
/c/Program Files/Foobar


def __init__(self, clean_stop_exception_types=None):
    if clean_stop_exception_types is None:
        clean_stop_exception_types = (errors.OutOfRangeError,)
    self._clean_stop_exception_types = tuple(clean_stop_exception_types)
    self._lock = threading.Lock()
    self._stop_event = threading.Event()
    self._exc_info_to_raise = None
    self._joined = False
    self._registered_threads = set()

Create a new Coordinator.

Args:
clean_stop_exception_types: Optional tuple of Exception types that should
cause a clean stop of the coordinator. If an exception of one of these
types is reported to `request_stop(ex)` the coordinator will behave as
if `request_stop(None)` was called.  Defaults to
`(tf.errors.OutOfRangeError,)` which is used by input queues to signal
the end of input. When feeding training data from a Python iterator it
is common to add `StopIteration` to this list.


def get_minutes_description(self):
    return self.get_segment_description(self._expression_parts[1], _('every minute'), (lambda s: s), (lambda s: _('every {0} minutes').format(s)), (lambda s: _('minutes {0} through {1} past the hour')), (lambda s: ('' if (s == '0') else _('at {0} minutes past the hour'))))

Generates a description for only the MINUTE portion of the expression

Returns:
The MINUTE description


def get_height(self, id=None, endpoint=None):

        return self._call_endpoint(GET_BLOCK_COUNT, id=id, endpoint=endpoint)

Get the current height of the blockchain
Args:
id: (int, optional) id to use for response tracking
endpoint: (RPCEndpoint, optional) endpoint to specify to use

Returns:
json object of the result or the error encountered in the RPC call


def remove_callback(self, callback):
    self.callback_handler.remove_callback(callback)

Remove a callback from the current list of [`~transformers.TrainerCallback`].

Args:
callback (`type` or [`~transformers.TrainerCallback]`):
A [`~transformers.TrainerCallback`] class or an instance of a [`~transformers.TrainerCallback`]. In the
first case, will remove the first member of that class found in the list of callbacks.


def run_notebook_hook(notebook_type, action, *args, **kw):
    if (notebook_type not in _HOOKS):
        raise RuntimeError(('no display hook installed for notebook type %r' % notebook_type))
    if (_HOOKS[notebook_type][action] is None):
        raise RuntimeError(('notebook hook for %r did not install %r action' % notebook_type), action)
    return _HOOKS[notebook_type][action](*args, **kw)

Run an installed notebook hook with supplied arguments.

Args:
noteboook_type (str) :
Name of an existing installed notebook hook

actions (str) :
Name of the hook action to execute, ``'doc'`` or ``'app'``

All other arguments and keyword arguments are passed to the hook action
exactly as supplied.

Returns:
Result of the hook action, as-is

Raises:
RuntimeError
If the hook or specific action is not installed


def remove_showcase(self, showcase):

        dataset_showcase = self._get_dataset_showcase_dict(showcase)
        showcase = hdx.data.showcase.Showcase({'id': dataset_showcase['showcase_id']}, configuration=self.configuration)
        showcase._write_to_hdx('disassociate', dataset_showcase, 'package_id')

Remove dataset from showcase

Args:
showcase (Union[Showcase,Dict,str]): Either a showcase id string or showcase metadata from a Showcase object or dictionary

Returns:
None


def verify(self, token, **kwargs):

        path = '/runners/verify'
        post_data = {'token': token}
        self.gitlab.http_post(path, post_data=post_data, **kwargs)

Validates authentication credentials for a registered Runner.

Args:
token (str): The runner's authentication token
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabVerifyError: If the server failed to verify the token


def make_directory_writable(dirname):

  retval = shell_call(['docker', 'run', '-v',
                       '{0}:/output_dir'.format(dirname),
                       'busybox:1.27.2',
                       'chmod', '-R', 'a+rwx', '/output_dir'])
  if not retval:
    logging.error('Failed to change permissions on directory: %s', dirname)
  return retval

Makes directory readable and writable by everybody.

Args:
dirname: name of the directory

Returns:
True if operation was successfull

If you run something inside Docker container and it writes files, then
these files will be written as root user with restricted permissions.
So to be able to read/modify these files outside of Docker you have to change
permissions to be world readable and writable.


def __init__(self, variables, name='TPUReplicatedVariable'):
    if not isinstance(variables, abc.Sequence) or not variables or any((not isinstance(v, variables_lib.Variable) for v in variables)):
        raise TypeError(f'Argument `variables` should be a non-empty list of `variables.Variable`s. Received {variables}')
    if any((v.dtype != variables[0].dtype for v in variables)):
        raise ValueError(f'All elements in argument `variables` must have the same dtype. Received dtypes: {[v.dtype for v in variables]}')
    if any((v.shape != variables[0].shape for v in variables)):
        raise ValueError(f'All elements in argument `variables` must have the same shape. Received shapes: {[v.shape for v in variables]}')
    self._vars = variables
    self._name = name
    self._common_name = self._name.split(':')[0]
    self._cached_value = None

Treats `variables` as a replicated list of `tf.Variable`s.

Example:

```
variables = [
tf.Variable(..., shape=(10, 100), dtype=tf.float32),
tf.Variable(..., shape=(10, 100), dtype=tf.float32),
tf.Variable(..., shape=(10, 100), dtype=tf.float32),
tf.Variable(..., shape=(10, 100), dtype=tf.float32),
]
replicated_variable = TPUReplicatedVariable(variables)
assert replicated_variable.shape.as_list() == [10, 100]
```

Args:
variables: A list of `ResourceVariable`s that comprise this replicated
variable. Variables should not be shared between different
`TPUReplicatedVariable` objects.
name: String. Name of this container. Defaults to "TPUReplicatedVariable".


def compute_q(self, query_antecedent):
    ret = mtf.einsum([query_antecedent, self.wq], reduced_dims=[self.query_input_dim])
    if self.combine_dims:
        ret = mtf.replace_dimensions(ret, ret.shape.dims[(- 1)], self.q_dims)
    return ret

Compute query Tensor q.

Args:
query_antecedent: a Tensor with dimensions
{query_input_dim} + other_dims
Returns:
a Tensor with dimensions
query_heads_dims + {key_dim} + other_dims


def _parse_logline_timestamp(t):
    (date, time) = t.split(' ')
    (month, day) = date.split('-')
    (h, m, s) = time.split(':')
    (s, ms) = s.split('.')
    return (month, day, h, m, s, ms)

Parses a logline timestamp into a tuple.

Args:
t: Timestamp in logline format.

Returns:
An iterable of date and time elements in the order of month, day, hour,
minute, second, microsecond.


def mutex(self, mutex, **kwargs):
    indicator_obj = Mutex(mutex, **kwargs)
    return self._indicator(indicator_obj)

Add Mutex data to Batch object.

Args:
mutex (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 Mutex.


def to_avro(file_path_or_buffer, df, schema=None, codec='null', append=False):
    if (schema is None):
        schema = __schema_infer(df)
    open_mode = ('wb' if (not append) else 'a+b')
    if isinstance(file_path_or_buffer, six.string_types):
        with open(file_path_or_buffer, open_mode) as f:
            fastavro.writer(f, schema=schema, records=df.to_dict('records'), codec=codec)
    else:
        fastavro.writer(file_path_or_buffer, schema=schema, records=df.to_dict('records'), codec=codec)

Avro file writer.

Args:
file_path_or_buffer:
Output file path or file-like object.
df: pd.DataFrame.
schema: Dict of Avro schema.
If it's set None, inferring schema.
append: Boolean to control if will append to existing file
codec: A string indicating the compression codec to use.
Default is no compression ("null"), other acceptable values are
"snappy" and "deflate". You must have python-snappy installed to use
the snappy codec.