def speech_recognition_bottom(x, model_hparams, vocab_size):
    del vocab_size
    inputs = x
    p = model_hparams
    num_mel_bins = p.audio_num_mel_bins
    num_channels = (3 if p.audio_add_delta_deltas else 1)
    with tf.variable_scope('speech_recognition_modality'):
        if p.audio_preproc_in_bottom:
            with tf.variable_scope('fbanks'):
                waveforms = tf.squeeze(inputs, [2, 3])
                mel_fbanks = common_audio.compute_mel_filterbank_features(waveforms, sample_rate=p.audio_sample_rate, dither=p.audio_dither, preemphasis=p.audio_preemphasis, frame_length=p.audio_frame_length, frame_step=p.audio_frame_step, lower_edge_hertz=p.audio_lower_edge_hertz, upper_edge_hertz=p.audio_upper_edge_hertz, num_mel_bins=p.audio_num_mel_bins, apply_mask=True)
                if p.audio_add_delta_deltas:
                    mel_fbanks = common_audio.add_delta_deltas(mel_fbanks)
                x = tf.reshape(mel_fbanks, (common_layers.shape_list(mel_fbanks)[:2] + [num_mel_bins, num_channels]))
                nonpadding_mask = (1.0 - common_attention.embedding_to_padding(x))
                num_of_nonpadding_elements = ((tf.reduce_sum(nonpadding_mask) * num_mel_bins) * num_channels)
                var_epsilon = 1e-09
                mean = (tf.reduce_sum(x, axis=[1], keepdims=True) / num_of_nonpadding_elements)
                variance = ((((num_of_nonpadding_elements * (mean ** 2.0)) - ((2.0 * mean) * tf.reduce_sum(x, axis=[1], keepdims=True))) + tf.reduce_sum((x ** 2), axis=[1], keepdims=True)) / num_of_nonpadding_elements)
                x = (((x - mean) * tf.rsqrt((variance + var_epsilon))) * tf.expand_dims(nonpadding_mask, (- 1)))
        else:
            x = inputs
        x.set_shape([None, None, num_mel_bins, num_channels])
        x = tf.pad(x, [[0, 0], [0, 8], [0, 0], [0, 0]])
        for _ in range(2):
            x = tf.layers.conv2d(x, 128, (3, 3), (2, 2), use_bias=False)
            x = common_layers.layer_norm(x)
            x = tf.nn.relu(x)
        xshape = common_layers.shape_list(x)
        x = tf.pad(x, [[0, 0], [0, 2], [0, 0], [0, 0]])
        x = tf.layers.conv2d(x, p.hidden_size, (3, xshape[2]), use_bias=False)
        assert (common_layers.shape_list(x)[2] == 1)
        x = common_layers.layer_norm(x)
        x = tf.nn.relu(x)
    return x

Use batchnorm instead of CMVN and shorten the stft with strided convs.

Args:
x: float32 tensor with shape [batch_size, len, 1, freqs * channels]
model_hparams: HParams, model hyperparmeters.
vocab_size: int, vocabulary size.

Returns:
float32 tensor with shape [batch_size, shorter_len, 1, hidden_size]


def parse_query(self, query, index, stop_current, shuffle):
    if ((index is not None) and (len(self.queue) > 0)):
        if ((index < 0) or (index >= len(self.queue))):
            if (len(self.queue) == 1):
                self.statuslog.error('Play index must be 1 (1 song in queue)')
                return
            else:
                self.statuslog.error('Play index must be between 1 and {}'.format(len(self.queue)))
                return
    try:
        yt_videos = api_music.parse_query(query, self.statuslog)
        if shuffle:
            random.shuffle(yt_videos)
        if (len(yt_videos) == 0):
            self.statuslog.error('No results for: {}'.format(query))
            return
        if (index is None):
            self.queue = (self.queue + yt_videos)
        elif (len(self.queue) > 0):
            self.queue = ((self.queue[:index] + yt_videos) + self.queue[index:])
        else:
            self.queue = yt_videos
        self.update_queue()
        if stop_current:
            if self.streamer:
                self.streamer.stop()
    except Exception as e:
        logger.exception(e)

Parses a query and adds it to the queue

Args:
query (str): Either a search term or a link
index (int): The index to enqueue at (None for end)
stop_current (bool): Whether to stop the current song after the songs are queued
shuffle (bool): Whether to shuffle the added songs


def roulette(weights, n):
    if (n > len(weights)):
        raise Exception("Can't choose {} samples from {} items".format(n, len(weights)))
    if any(map((lambda w: (w <= 0)), weights.values())):
        raise Exception("The weight can't be a non-positive number.")
    items = weights.items()
    chosen = set()
    for i in range(n):
        total = sum(list(zip(*items))[1])
        dice = (random.random() * total)
        running_weight = 0
        chosen_item = None
        for (item, weight) in items:
            if (dice < (running_weight + weight)):
                chosen_item = item
                break
            running_weight += weight
        chosen.add(chosen_item)
        items = [(i, w) for (i, w) in items if (i != chosen_item)]
    return list(chosen)

Choose randomly the given number of items. The probability the item is
chosen is proportionate to its weight.

.. testsetup::

import random
from proso.rand import roulette

random.seed(1)

.. testcode::

print(roulette({'cat': 2, 'dog': 1000}, 1))

.. testoutput::

['dog']

Args:
weights (dict): item -> weight mapping, non-positive weights are forbidden
n (int): number of chosen items

Returns:
list: randomly chosen items


def saml_metadata(self, client_id):

        return self.get(url='https:
                                                                  client_id))

Get SAML2.0 Metadata.

Args:
client_id (str): Client Id of the application to get the SAML metadata for.


def receiveds_parsing(receiveds):
    parsed = []
    receiveds = [re.sub(JUNK_PATTERN, ' ', i).strip() for i in receiveds]
    n = len(receiveds)
    log.debug('Nr. of receiveds. {}'.format(n))
    for (idx, received) in enumerate(receiveds):
        log.debug('Parsing received {}/{}'.format((idx + 1), n))
        log.debug('Try to parse {!r}'.format(received))
        try:
            values_by_clause = parse_received(received)
        except MailParserReceivedParsingError:
            parsed.append({'raw': received})
        else:
            parsed.append(values_by_clause)
    log.debug(('len(receiveds) %s, len(parsed) %s' % (len(receiveds), len(parsed))))
    if (len(receiveds) != len(parsed)):
        log.error(('len(receiveds): %s, len(parsed): %s, receiveds: %s,             parsed: %s' % (len(receiveds), len(parsed), receiveds, parsed)))
        return receiveds_not_parsed(receiveds)
    else:
        return receiveds_format(parsed)

This function parses the receiveds headers.

Args:
receiveds (list): list of raw receiveds headers

Returns:
a list of parsed receiveds headers with first hop in first position


def _testReduceJoin(self, input_array, truth, truth_shape, axis, keep_dims=False, separator=''):
    with self.cached_session():
        output = string_ops.reduce_join(inputs=input_array, axis=axis, keep_dims=keep_dims, separator=separator)
        output_array = self.evaluate(output)
    self.assertAllEqualUnicode(truth, output_array)
    self.assertAllEqual(truth_shape, output.get_shape())

Compares the output of reduce_join to an expected result.

Args:
input_array: The string input to be joined.
truth: An array or np.array of the expected result.
truth_shape: An array or np.array of the expected shape.
axis: The indices to reduce over.
keep_dims: Whether or not to retain reduced dimensions.
separator: The separator to use for joining.


def plotpsd(data, dt, ndivide=1, window=hanning, overlap_half=False, ax=None, **kwargs):

    if ax is None:
        ax = plt.gca()
    vk, psddata = psd(data, dt, ndivide, window, overlap_half)
    ax.loglog(vk, psddata, **kwargs)
    ax.set_xlabel('Frequency [Hz]')
    ax.set_ylabel('PSD')
    ax.legend()

Plot PSD (Power Spectral Density).

Args:
data (np.ndarray): Input data.
dt (float): Time between each data.
ndivide (int): Do averaging (split data into ndivide, get psd of each, and average them).
overlap_half (bool): Split data to half-overlapped regions.
ax (matplotlib.axes): Axis the figure is plotted on.
kwargs (optional): Plot options passed to ax.plot().


def convert_formula_to_atomic_fractions(formula):

    mole_fractions = {}
    total_mole_fraction = 0.0

    for match in CHEMICAL_FORMULA_PATTERN.finditer(formula):
        symbol, mole_fraction = match.groups()

        z = pyxray.element_atomic_number(symbol.strip())

        if mole_fraction == '':
            mole_fraction = 1.0
        mole_fraction = float(mole_fraction)

        mole_fraction = float(mole_fraction)
        mole_fractions[z] = mole_fraction
        total_mole_fraction += mole_fraction

    atomic_fractions = {}
    for z, mole_fraction in mole_fractions.items():
        atomic_fractions[z] = mole_fraction / total_mole_fraction

    return atomic_fractions

Converts a chemical formula to an atomic fraction :class:`dict`.

Args:
formula (str): chemical formula, like Al2O3. No wildcard are accepted.


def _instantiate_data_type(self, data_type_class, data_type_args, loc):
    assert issubclass(data_type_class, DataType), ('Expected stone.data_type.DataType, got %r' % data_type_class)
    argspec = inspect.getargspec(data_type_class.__init__)
    argspec.args.remove('self')
    num_args = len(argspec.args)
    num_defaults = len((argspec.defaults or ()))
    (pos_args, kw_args) = data_type_args
    if ((num_args - num_defaults) > len(pos_args)):
        raise InvalidSpec(('Missing positional argument %s for %s type' % (quote(argspec.args[len(pos_args)]), quote(data_type_class.__name__))), *loc)
    elif ((num_args - num_defaults) < len(pos_args)):
        raise InvalidSpec(('Too many positional arguments for %s type' % quote(data_type_class.__name__)), *loc)
    args = {}
    for (i, key) in enumerate(argspec.args):
        args[key] = (i >= (num_args - num_defaults))
    for key in kw_args:
        if (key not in args):
            raise InvalidSpec(('Unknown argument %s to %s type.' % (quote(key), quote(data_type_class.__name__))), *loc)
        if (not args[key]):
            raise InvalidSpec(('Positional argument %s cannot be specified as a keyword argument.' % quote(key)), *loc)
        del args[key]
    try:
        return data_type_class(*pos_args, **kw_args)
    except ParameterError as e:
        raise InvalidSpec(('Bad argument to %s type: %s' % (quote(data_type_class.__name__), e.args[0])), *loc)

Responsible for instantiating a data type with additional attributes.
This method ensures that the specified attributes are valid.

Args:
data_type_class (DataType): The class to instantiate.
data_type_attrs (dict): A map from str -> values of attributes.
These will be passed into the constructor of data_type_class
as keyword arguments.

Returns:
stone.data_type.DataType: A parameterized instance.


def _ensure_node_in_anf(self, parent, field, node):
    if node is None:
        return node
    if _is_trivial(node):
        return node
    if isinstance(node, list):
        return [self._ensure_node_in_anf(parent, field, n) for n in node]
    if isinstance(node, gast.keyword):
        node.value = self._ensure_node_in_anf(parent, field, node.value)
        return node
    if isinstance(node, (gast.Starred, gast.withitem, gast.slice)):
        return self._ensure_fields_in_anf(node, parent, field)
    if self._should_transform(parent, field, node):
        return self._do_transform_node(node)
    else:
        return node

Puts `node` in A-normal form, by replacing it with a variable if needed.

The exact definition of A-normal form is given by the configuration.  The
parent and the incoming field name are only needed because the configuration
may be context-dependent.

Args:
parent: An AST node, the parent of `node`.
field: The field name under which `node` is the child of `parent`.
node: An AST node, potentially to be replaced with a variable reference.

Returns:
node: An AST node; the argument if transformation was not necessary,
or the new variable reference if it was.


def register(self, alias, service_class, configs=None, start_service=True):

        if not inspect.isclass(service_class):
            raise Error(self._device, '"%s" is not a class!' % service_class)
        if not issubclass(service_class, base_service.BaseService):
            raise Error(
                self._device,
                'Class %s is not a subclass of BaseService!' % service_class)
        if alias in self._service_objects:
            raise Error(
                self._device,
                'A service is already registered with alias "%s".' % alias)
        service_obj = service_class(self._device, configs)
        if start_service:
            service_obj.start()
        self._service_objects[alias] = service_obj

Registers a service.

This will create a service instance, starts the service, and adds the
instance to the mananger.

Args:
alias: string, the alias for this instance.
service_class: class, the service class to instantiate.
configs: (optional) config object to pass to the service class's
constructor.
start_service: bool, whether to start the service instance or not.
Default is True.


def _dump_file_name_to_datum(self, dir_name, file_name):
    debug_dump_rel_path = os.path.join(os.path.relpath(dir_name, self._dump_root), file_name)
    return DebugTensorDatum(self._dump_root, debug_dump_rel_path)

Obtain a DebugTensorDatum from the directory and file name.

Args:
dir_name: (`str`) Name of the directory in which the dump file resides.
file_name: (`str`) Base name of the dump file.

Returns:
(`DebugTensorDatum`) The `DebugTensorDatum` loaded from the dump file.


def _ParseAnalysisPluginOptions(self, options):
    analysis_plugin_info = self._analysis_manager.GetAllPluginInformation()
    analysis_plugin_names = {name.lower() for (name, _, _) in analysis_plugin_info}
    analysis_plugins = self.ParseStringOption(options, 'analysis_plugins')
    if (not analysis_plugins):
        return
    requested_plugin_names = {name.strip().lower() for name in analysis_plugins.split(',')}
    difference = requested_plugin_names.difference(analysis_plugin_names)
    if difference:
        raise errors.BadConfigOption('Non-existent analysis plugins specified: {0:s}'.format(' '.join(difference)))
    self._analysis_plugins = self._GetAnalysisPlugins(analysis_plugins)
    for analysis_plugin in self._analysis_plugins:
        helpers_manager.ArgumentHelperManager.ParseOptions(options, analysis_plugin)

Parses the analysis plugin options.

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


def normalize(self, mode="max", value=1):

        if mode.lower() == "sum":
            factor = np.sum(self.y, axis=0)
        elif mode.lower() == "max":
            factor = np.max(self.y, axis=0)
        else:
            raise ValueError("Unsupported normalization mode %s!" % mode)

        self.y /= factor / value

Normalize the spectrum with respect to the sum of intensity

Args:
mode (str): Normalization mode. Supported modes are "max" (set the
max y value to value, e.g., in XRD patterns), "sum" (set the
sum of y to a value, i.e., like a probability density).
value (float): Value to normalize to. Defaults to 1.


def _launch_flow(self, client, name, args):
    flow = self._check_approval_wrapper(client, client.CreateFlow, name=name, args=args)
    flow_id = flow.flow_id
    print('{0:s}: Scheduled'.format(flow_id))
    if self.keepalive:
        keepalive_flow = client.CreateFlow(name='KeepAlive', args=flows_pb2.KeepAliveArgs())
        print('KeepAlive Flow:{0:s} scheduled'.format(keepalive_flow.flow_id))
    return flow_id

Create specified flow, setting KeepAlive if requested.

Args:
client: GRR Client object on which to launch the flow.
name: string containing flow name.
args: proto (*FlowArgs) for type of flow, as defined in GRR flow proto.

Returns:
string containing ID of launched flow


def line_iter(xo: int, yo: int, xd: int, yd: int) -> Iterator[Tuple[(int, int)]]:
    data = ffi.new('TCOD_bresenham_data_t *')
    lib.TCOD_line_init_mt(xo, yo, xd, yd, data)
    x = ffi.new('int *')
    y = ffi.new('int *')
    (yield (xo, yo))
    while (not lib.TCOD_line_step_mt(x, y, data)):
        (yield (x[0], y[0]))

returns an Iterable

This Iterable does not include the origin point.

Args:
xo (int): X starting point.
yo (int): Y starting point.
xd (int): X destination point.
yd (int): Y destination point.

Returns:
Iterable[Tuple[int,int]]: An Iterable of (x,y) points.


def load_map_info(self, map_file):
    if (self.ensemble_name.upper() == 'SSEF'):
        (proj_dict, grid_dict) = read_arps_map_file(map_file)
        self.dx = int(grid_dict['dx'])
        mapping_data = make_proj_grids(proj_dict, grid_dict)
        for (m, v) in mapping_data.items():
            setattr(self, m, v)
        (self.i, self.j) = np.indices(self.lon.shape)
        self.proj = get_proj_obj(proj_dict)
    elif (self.ensemble_name.upper() in ['NCAR', 'NCARSTORM', 'HRRR', 'VSE', 'HREFV2']):
        (proj_dict, grid_dict) = read_ncar_map_file(map_file)
        if (self.member_name[0:7] == '1km_pbl'):
            grid_dict['dx'] = 1000
            grid_dict['dy'] = 1000
            grid_dict['sw_lon'] = 258.697
            grid_dict['sw_lat'] = 23.999
            grid_dict['ne_lon'] = 282.868269206236
            grid_dict['ne_lat'] = 36.4822338520542
        self.dx = int(grid_dict['dx'])
        mapping_data = make_proj_grids(proj_dict, grid_dict)
        for (m, v) in mapping_data.items():
            setattr(self, m, v)
        (self.i, self.j) = np.indices(self.lon.shape)
        self.proj = get_proj_obj(proj_dict)

Load map projection information and create latitude, longitude, x, y, i, and j grids for the projection.

Args:
map_file: File specifying the projection information.


def create_position_ids_from_inputs_embeds(self, inputs_embeds):
    input_shape = shape_list(inputs_embeds)[:-1]
    sequence_length = input_shape[1]
    position_ids = tf.range(start=self.padding_idx + 1, limit=sequence_length + self.padding_idx + 1, dtype=tf.int64)
    return tf.broadcast_to(tf.expand_dims(position_ids, 0), input_shape)

We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.

Args:
inputs_embeds: tf.Tensor

Returns: tf.Tensor


def get_mask2former_resize_output_image_size(image: np.ndarray, size: Union[int, Tuple[int, int], List[int], Tuple[int]], max_size: Optional[int]=None, size_divisor: int=0, default_to_square: bool=True, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> Tuple[int, int]:
    output_size = get_resize_output_image_size(input_image=image, size=size, default_to_square=default_to_square, max_size=max_size, input_data_format=input_data_format)
    if size_divisor > 0:
        height, width = output_size
        height = int(math.ceil(height / size_divisor) * size_divisor)
        width = int(math.ceil(width / size_divisor) * size_divisor)
        output_size = (height, width)
    return output_size

Computes the output size given the desired size.

Args:
image (`np.ndarray`):
The input image.
size (`int` or `Tuple[int, int]` or `List[int]` or `Tuple[int]`):
The size of the output image.
max_size (`int`, *optional*):
The maximum size of the output image.
size_divisor (`int`, *optional*, defaults to 0):
If `size_divisor` is given, the output image size will be divisible by the number.
default_to_square (`bool`, *optional*, defaults to `True`):
Whether to default to square if no size is provided.
input_data_format (`ChannelDimension` or `str`, *optional*):
The channel dimension format of the input image. If unset, will use the inferred format from the input.

Returns:
`Tuple[int, int]`: The output size.


def keywords_special_characters(keywords):
    invalid_chars = '!"
    if any(((char in invalid_chars) for char in keywords)):
        raise ValidationError(MESSAGE_KEYWORD_SPECIAL_CHARS)

Confirms that the keywords don't contain special characters

Args:
keywords (str)

Raises:
django.forms.ValidationError


def enable_type_check(enabled: bool=True) -> ContextManager[None]:
    return thread_local.thread_local_value_scope(_TLS_ENABLE_TYPE_CHECK, enabled, True)

Returns a context manager to enable or disable runtime type check.

`enable_type_check` is thread-safe and can be nested. For example,
in the following code, runtime type check with be `a` but not on `b`::

with pg.enable_type_check(False):
with pg.enable_type_check(True):
a = pg.Dict(x=1, value_spec=pg.typing.Dict([('x', pg.typing.Int())]))
b = pg.Dict(y=1, value_spec=pg.typing.Dict([('x', pg.typing.Int())]))

Args:
enabled: If True, enable runtime type check in current scope.
Otherwise, disable runtime type check.

Returns:
A context manager for allowing/disallowing runtime type check.


def set_column_count(self, count):
    current_row_count = self.row_count()
    current_column_count = self.column_count()
    if (count > current_column_count):
        cl = (TableEditableItem if self._editable else TableItem)
        for r_key in self.children.keys():
            row = self.children[r_key]
            for i in range(current_column_count, count):
                row.append(cl(), str(i))
                if self._editable:
                    row.children[str(i)].onchange.connect(self.on_item_changed, int(r_key), int(i))
        self._update_first_row()
    elif (count < current_column_count):
        for row in self.children.values():
            for i in range(count, current_column_count):
                row.remove_child(row.children[str(i)])
    self._column_count = count

Sets the table column count.

Args:
count (int): column of rows


def cache_connect(database=None):

    if database is None:
        database = cache_file()

    if os.path.isfile(database):

        conn = sqlite3.connect(database)
    else:

        conn = sqlite3.connect(database)
        conn.executescript(schema)

    with conn as cur:

        cur.execute("PRAGMA foreign_keys = ON;")

    conn.row_factory = sqlite3.Row

    return conn

Returns a connection object to a sqlite database.

Args:
database (str, optional): The path to the database the user wishes
to connect to. If not specified, a default is chosen using
:func:`.cache_file`. If the special database name ':memory:'
is given, then a temporary database is created in memory.

Returns:
:class:`sqlite3.Connection`


def parse_rdf_payload(self, data, headers):

		if headers['Content-Type'].startswith('text/plain'):
			logger.debug('text/plain Content-Type detected, using application/n-triples for parser')
			parse_format = 'application/n-triples'
		else:
			parse_format = headers['Content-Type']

		if ';charset' in parse_format:
			parse_format = parse_format.split(';')[0]

		graph = rdflib.Graph().parse(
			data=data.decode('utf-8'),
			format=parse_format)

		return graph

small function to parse RDF payloads from various repository endpoints

Args:
data (response.data): data from requests response
headers (response.headers): headers from requests response

Returns:
(rdflib.Graph): parsed graph


def vc2tex(script, tex_name='TEMP3D_texture.png', tex_width=1024, tex_height=1024, overwrite_tex=False, assign_tex=False, fill_tex=True):
    filter_xml = ''.join(['  <filter name="Vertex Color to Texture">\n', '    <Param name="textName" ', ('value="%s" ' % tex_name), 'description="Texture file" ', 'type="RichString" ', '/>\n', '    <Param name="textW" ', ('value="%d" ' % tex_width), 'description="Texture width (px)" ', 'type="RichInt" ', '/>\n', '    <Param name="textH" ', ('value="%d" ' % tex_height), 'description="Texture height (px)" ', 'type="RichInt" ', '/>\n', '    <Param name="overwrite" ', ('value="%s" ' % str(overwrite_tex).lower()), 'description="Overwrite texture" ', 'type="RichBool" ', '/>\n', '    <Param name="assign" ', ('value="%s" ' % str(assign_tex).lower()), 'description="Assign Texture" ', 'type="RichBool" ', '/>\n', '    <Param name="pullpush" ', ('value="%s" ' % str(fill_tex).lower()), 'description="Fill texture" ', 'type="RichBool" ', '/>\n', '  </filter>\n'])
    util.write_filter(script, filter_xml)
    return None

Transfer vertex colors to texture colors

Args:
script: the FilterScript object or script filename to write
the filter to.
tex_name (str): The texture file to be created
tex_width (int): The texture width
tex_height (int): The texture height
overwrite_tex (bool): If current mesh has a texture will be overwritten (with provided texture dimension)
assign_tex (bool): Assign the newly created texture
fill_tex (bool): If enabled the unmapped texture space is colored using a pull push filling algorithm, if false is set to black


def create_and_register_access_db(filename: str,
                                  dsn: str,
                                  description: str) -> bool:

    fullfilename = os.path.abspath(filename)
    create_string = fullfilename + " General"

    return (create_user_dsn(access_driver, CREATE_DB=create_string) and
            register_access_db(filename, dsn, description))

(Windows only.)
Creates a Microsoft Access database and registers it with ODBC.

Args:
filename: filename of the database to create
dsn: ODBC data source name to create
description: description of the database

Returns:
bool: was the DSN created?


def add_alias(self, alias, index):

        if index >= len(self._datasets):
            raise DataInvalidIndex('A dataset with index {} does not exist'.format(index))
        self._aliases[alias] = index

Add an alias pointing to the specified index.

Args:
alias (str): The alias that should point to the given index.
index (int): The index of the dataset for which an alias should be added.

Raises:
DataInvalidIndex: If the index does not represent a valid dataset.


def channel_interpolate(layer1, n_channel1, layer2, n_channel2):

  def inner(T):
    batch_n = T(layer1).get_shape().as_list()[0]
    arr1 = T(layer1)[..., n_channel1]
    arr2 = T(layer2)[..., n_channel2]
    weights = (np.arange(batch_n)/float(batch_n-1))
    S = 0
    for n in range(batch_n):
      S += (1-weights[n]) * tf.reduce_mean(arr1[n])
      S += weights[n] * tf.reduce_mean(arr2[n])
    return S
  return inner

Interpolate between layer1, n_channel1 and layer2, n_channel2.

Optimize for a convex combination of layer1, n_channel1 and
layer2, n_channel2, transitioning across the batch.

Args:
layer1: layer to optimize 100% at batch=0.
n_channel1: neuron index to optimize 100% at batch=0.
layer2: layer to optimize 100% at batch=N.
n_channel2: neuron index to optimize 100% at batch=N.

Returns:
Objective


def __init__(self, config, verbose=True):

        self.best_model_found = None
        self.best_iteration = None
        self.best_score = None
        self.verbose = verbose

        self.checkpoint_best = config["checkpoint_best"]
        self.checkpoint_every = config["checkpoint_every"]
        self.checkpoint_metric = config["checkpoint_metric"]
        self.checkpoint_metric_mode = config["checkpoint_metric_mode"]
        self.checkpoint_dir = config["checkpoint_dir"]
        self.checkpoint_runway = config["checkpoint_runway"]

        if "/" not in self.checkpoint_metric:
            self.checkpoint_metric = "valid/" + self.checkpoint_metric

        if not os.path.exists(self.checkpoint_dir):
            os.makedirs(self.checkpoint_dir)

        if self.checkpoint_runway and verbose:
            print(
                f"No checkpoints will be saved in the first "
                f"checkpoint_runway={self.checkpoint_runway} iterations."
            )

Saves checkpoints as applicable based on a reported metric.

Args:
checkpoint_runway (int): don't save any checkpoints for the first
this many iterations
checkpoint_dir (str): the directory for saving checkpoints


def _ComputeUniquifier(self, debuggee):

    uniquifier = hashlib.sha1()

    if ('minorversion' not in debuggee.get('labels', []) and
        'sourceContexts' not in debuggee):
      uniquifier_computer.ComputeApplicationUniquifier(uniquifier)

    return uniquifier.hexdigest()

Computes debuggee uniquifier.

The debuggee uniquifier has to be identical on all instances. Therefore the
uniquifier should not include any random numbers and should only be based
on inputs that are guaranteed to be the same on all instances.

Args:
debuggee: complete debuggee message without the uniquifier

Returns:
Hex string of SHA1 hash of project information, debuggee labels and
debuglet version.


def _rpc(self, method, *args):
    with self._lock:
        apiid = next(self._counter)
        data = {'id': apiid, 'method': method, 'params': args}
        request = json.dumps(data)
        self._client_send(request)
        response = self._client_receive()
    if not response:
        raise ProtocolError(self._ad, ProtocolError.NO_RESPONSE_FROM_SERVER)
    result = json.loads(str(response, encoding='utf8'))
    if result['error']:
        raise ApiError(self._ad, result['error'])
    if result['id'] != apiid:
        raise ProtocolError(self._ad, ProtocolError.MISMATCHED_API_ID)
    if result.get('callback') is not None:
        if self._event_client is None:
            self._event_client = self._start_event_client()
        return callback_handler.CallbackHandler(callback_id=result['callback'], event_client=self._event_client, ret_value=result['result'], method_name=method, ad=self._ad)
    return result['result']

Sends an rpc to the app.

Args:
method: str, The name of the method to execute.
args: any, The args of the method.

Returns:
The result of the rpc.

Raises:
ProtocolError: Something went wrong with the protocol.
ApiError: The rpc went through, however executed with errors.


def cumany(series):

    anys = series.expanding().apply(np.any).astype(bool)
    return anys

Calculates cumulative any of values. Equivalent to
`series.expanding().apply(np.any).astype(bool)`.

Args:
series: column to compute cumulative any for.


def get_description(self, description_type=DescriptionTypeEnum.FULL):
    try:
        if (self._parsed is False):
            parser = ExpressionParser(self._expression, self._options)
            self._expression_parts = parser.parse()
            self._parsed = True
        choices = {DescriptionTypeEnum.FULL: self.get_full_description, DescriptionTypeEnum.TIMEOFDAY: self.get_time_of_day_description, DescriptionTypeEnum.HOURS: self.get_hours_description, DescriptionTypeEnum.MINUTES: self.get_minutes_description, DescriptionTypeEnum.SECONDS: self.get_seconds_description, DescriptionTypeEnum.DAYOFMONTH: self.get_day_of_month_description, DescriptionTypeEnum.MONTH: self.get_month_description, DescriptionTypeEnum.DAYOFWEEK: self.get_day_of_week_description, DescriptionTypeEnum.YEAR: self.get_year_description}
        description = choices.get(description_type, self.get_seconds_description)()
    except Exception as ex:
        if self._options.throw_exception_on_parse_error:
            raise
        else:
            description = str(ex)
    return description

Generates a human readable string for the Cron Expression

Args:
description_type: Which part(s) of the expression to describe
Returns:
The cron expression description
Raises:
Exception: if throw_exception_on_parse_error is True


def batch_norm(x, is_training, momentum, epsilon=1e-9,
               init_zero=False, name=None):

  with tf.variable_scope(name, default_name="batch_norm", values=[x]):
    if init_zero:
      gamma_initializer = tf.zeros_initializer()
    else:
      gamma_initializer = tf.ones_initializer()

    norm_dim = x.shape.dims[0:3]
    reduced_shape = x.shape - norm_dim

    scale = mtf.get_variable(
        x.mesh,
        "batch_norm_scale",
        reduced_shape,
        initializer=gamma_initializer,
        activation_dtype=x.dtype)
    bias = mtf.get_variable(
        x.mesh,
        "batch_norm_bias",
        reduced_shape,
        initializer=tf.zeros_initializer(),
        activation_dtype=x.dtype)

    moving_mean = mtf.get_variable(
        x.mesh, "moving_mean", reduced_shape,
        initializer=tf.random_normal_initializer(stddev=1.0),
        activation_dtype=x.dtype,
        trainable=False)
    moving_variance = mtf.get_variable(
        x.mesh, "moving_variance",
        reduced_shape, initializer=tf.ones_initializer(),
        activation_dtype=x.dtype,
        trainable=False)

    if is_training:
      mean = mtf.reduce_mean(x, output_shape=reduced_shape)
      variance = mtf.reduce_mean(
          mtf.square(x - mean), output_shape=reduced_shape)

      norm_x = (x - mean) * mtf.rsqrt(variance + epsilon)

      moving_mean = mtf.assign(
          moving_mean, momentum * moving_mean + (1-momentum) * mean)
      moving_variance = mtf.assign(
          moving_variance,
          momentum * moving_variance + (1 - momentum) * variance)
    else:

      norm_x = (x - moving_mean) * mtf.rsqrt(moving_variance + epsilon)

    return (norm_x * scale) + bias

Batch normalization.

Args:
x: a mtf.Tensor whose shape contains [batch_dim, ..., dim]
is_training: a boolean, whether mode is training.
momentum: a floating point number, specifying batch norm decay value.
epsilon: a floating point number.
init_zero: a boolean, whether to initialize scale with 0's or 1's.
name: a string. variable scope.

Returns:
a mtf.Tensor with same shape as x.


def split(self):
    if (self.package_request.conflict or (len(self.variant_slice) == 1)):
        return None
    else:
        r = self.variant_slice.split()
        if (r is None):
            return None
        else:
            (slice, next_slice) = r
            scope = self._copy(slice)
            next_scope = self._copy(next_slice)
            return (scope, next_scope)

Split the scope.

Returns:
A (_PackageScope, _PackageScope) tuple, where the first scope is
guaranteed to have a common dependency. Or None, if splitting is
not applicable to this scope.


def _compute_new_attention_mask(hidden_states: torch.Tensor, seq_lens: torch.Tensor):
    batch_size, mask_seq_len = hidden_states.shape[:2]
    indices = torch.arange(mask_seq_len, device=seq_lens.device).expand(batch_size, -1)
    bool_mask = indices >= seq_lens.unsqueeze(1).expand(-1, mask_seq_len)
    mask = hidden_states.new_ones((batch_size, mask_seq_len))
    mask = mask.masked_fill(bool_mask, 0)
    return mask

Computes an attention mask of the form `(batch, seq_len)` with an attention for each element in the batch that
stops at the corresponding element in `seq_lens`.

Args:
hidden_states (`torch.FloatTensor` of shape `(batch, seq_len, *)`):
The sequences to mask, where `*` is any number of sequence-specific dimensions including none.
seq_lens (`torch.Tensor` of shape `(batch)`:
Each element represents the length of the sequence at the same index in `hidden_states`

Returns:
`torch.FloatTensor`: The float attention mask of shape `(batch, seq_len)`


def _parse_value(self, value):
    if isinstance(value, str):
        if value.upper() == 'TRUE':
            return True
        elif value.upper() == 'FALSE':
            return False
        else:
            int_value = self._convert_int(value)
            if int_value:
                return int_value
            else:
                float_value = self._convert_float(value)
                if float_value:
                    return float_value
                else:
                    date_value = self._convert_date(value)
                    if date_value:
                        return date_value
                    else:
                        return value
    else:
        return value

Parses a string value into a type specific value infering the correct type based on the data.

Args:
value: The value to parse.

Returns:
The representation of the value in the correct data type.


def plot_lattice_vectors(lattice, ax=None, **kwargs):
    (ax, fig, plt) = get_ax3d_fig_plt(ax)
    if ('color' not in kwargs):
        kwargs['color'] = 'g'
    if ('linewidth' not in kwargs):
        kwargs['linewidth'] = 3
    vertex1 = lattice.get_cartesian_coords([0.0, 0.0, 0.0])
    vertex2 = lattice.get_cartesian_coords([1.0, 0.0, 0.0])
    ax.plot(*zip(vertex1, vertex2), **kwargs)
    vertex2 = lattice.get_cartesian_coords([0.0, 1.0, 0.0])
    ax.plot(*zip(vertex1, vertex2), **kwargs)
    vertex2 = lattice.get_cartesian_coords([0.0, 0.0, 1.0])
    ax.plot(*zip(vertex1, vertex2), **kwargs)
    return (fig, ax)

Adds the basis vectors of the lattice provided to a matplotlib Axes

Args:
lattice: Lattice object
ax: matplotlib :class:`Axes` or None if a new figure should be created.
kwargs: kwargs passed to the matplotlib function 'plot'. Color defaults to green
and linewidth to 3.

Returns:
matplotlib figure and matplotlib ax


def reload_workspace(source: g3_utils.Source | None=None, *, restrict: py_utils.StrOrStrList | None=None, verbose: bool=False, reload_mode: inplace_reload.ReloadMode | str=inplace_reload.ReloadMode.INVALIDATE) -> None:
    from etils import g3_utils
    from etils.ecolab import adhoc_imports
    citc_info = g3_utils.citc_info_from_source(source)
    if isinstance(citc_info, g3_utils.PendingCl):
        citc_info = citc_info.workspace
    restrict = py_utils.normalize_str_to_list(restrict)
    if not isinstance(citc_info, g3_utils.Workspace):
        if (prev_modules := _find_modules_imported_in_different_source(source)):
            prev_module_name = next(iter(prev_modules))
            prev_source = sys.modules[prev_module_name]._etils_workspace_reload_source
            raise ValueError(f'Source was changed from {prev_source!r} to {source!r}. `reload_workspace=True` cannot auto-infer which modules to reload. Please restart your kernel.')
        else:
            return
    modules_to_reload = _get_modules_to_reload(restrict=restrict, citc_info=citc_info)
    if not modules_to_reload:
        return
    with adhoc_imports.adhoc(source, reload=modules_to_reload, restrict=restrict, restrict_reload=False, reload_recursive=False, reload_mode=reload_mode, verbose=verbose, collapse_prefix=f'Reload workspace ({len(modules_to_reload)} modules): '):
        for module_name in modules_to_reload:
            module = importlib.import_module(module_name)
            module._etils_workspace_reload_source = source
    update_global_namespace(reload=modules_to_reload, verbose=verbose)

Reload all modified files in the current workspace.

This function look at all edited files in the given workspace which are also
imported and reload them.

This is a no-op if the source is not a user workspace.

Args:
source: Same as `ecolab.adhoc`
restrict: Same as `ecolab.adhoc`
verbose: Same as `ecolab.adhoc`
reload_mode: Same as `ecolab.adhoc`


def get_orbit(name, date):
    if (name not in [x.name for x in Bsp().top.list]):
        raise UnknownBodyError(name)
    for (a, b) in Bsp().top.steps(name):
        if (b.name not in _propagator_cache):
            propagator = type(('%sBspPropagator' % b.name), (GenericBspPropagator,), {'src': a, 'dst': b})
            center = Pck()[b.full_name.title()]
            propagator.propagate(date).as_frame(b.name, center=center)
            _propagator_cache[b.name] = propagator
    if (Bsp().top not in _propagator_cache):
        _propagator_cache[Bsp().top.name] = EarthPropagator()
    return _propagator_cache[name].propagate(date)

Retrieve the orbit of a solar system object

Args:
name (str): The name of the body desired. For exact nomenclature, see
:py:func:`available_planets`
date (Date): Date at which the state vector will be extracted
Return:
Orbit: Orbit of the desired object, in the reference frame in which it is declared in
the .bsp file


def get_structural_variant(self, variant):
    query = {'chrom': variant['chrom'], 'end_chrom': variant['end_chrom'], 'sv_type': variant['sv_type'], '$and': [{'pos_left': {'$lte': variant['pos']}}, {'pos_right': {'$gte': variant['pos']}}]}
    res = self.db.structural_variant.find(query).sort('pos_left', 1)
    match = None
    distance = None
    closest_hit = None
    for hit in res:
        if (hit['end_left'] > variant['end']):
            continue
        if (hit['end_right'] < variant['end']):
            continue
        distance = (abs((variant['pos'] - ((hit['pos_left'] + hit['pos_right']) / 2))) + abs((variant['end'] - ((hit['end_left'] + hit['end_right']) / 2))))
        if (closest_hit is None):
            match = hit
            closest_hit = distance
            continue
        if (distance < closest_hit):
            match = hit
            closest_hit = distance
    return match

Check if there are any overlapping sv clusters

Search the sv variants with chrom start end_chrom end and sv_type

Args:
variant (dict): A variant dictionary

Returns:
variant (dict): A variant dictionary


def post_path(self, path: str, path_data: Union[dict, None], post_data: Any) -> dict:

        path = self._insert_vars(path, path_data or {})
        path = self.BASE_URL + path
        self._try_refresh_access_token()
        return self.session.post(path, json=post_data).json()

Modifies the ESI by an endpoint URL.

This method is not marked "private" as it _can_ be used
by consuming code, but it's probably easier to call the
`get_op` method instead.

Args:
path: raw ESI URL path
path_data: data to format the path with (can be None)
post_data: data to send to ESI

Returns:
ESI data


def remove(self, block_id):

        with self._mutex:
            entry = self._block_map[block_id]
            self._queue.remove(entry)

Remove a Processing Block from the queue.

Args:
block_id (str):


def initialize(self):

        self.fonttype = self.font_types['bitmap']
        self.send(chr(27)+chr(64))

Calling this function initializes the printer.

Args:
None
Returns:
None
Raises:
None


def get_decomposition(self, comp):

        facet, simplex = self._get_facet_and_simplex(comp)
        decomp_amts = simplex.bary_coords(self.pd_coords(comp))
        return {self.qhull_entries[f]: amt
                for f, amt in zip(facet, decomp_amts)
                if abs(amt) > PhaseDiagram.numerical_tol}

Provides the decomposition at a particular composition.

Args:
comp: A composition

Returns:
Decomposition as a dict of {Entry: amount}


def _dqdv_combinded_frame(cell, **kwargs):
    cycles = cell.get_cap(method='forth-and-forth', categorical_column=True, label_cycle_number=True)
    ica_df = dqdv_cycles(cycles, **kwargs)
    assert isinstance(ica_df, pd.DataFrame)
    return ica_df

Returns full cycle dqdv data for all cycles as one pd.DataFrame.

Args:
cell: CellpyData-object

Returns:
pandas.DataFrame with the following columns:
cycle: cycle number
voltage: voltage
dq: the incremental capacity


def _prepare_run_watch_config(self, fetches, feed_dict):
    debug_urls = self.prepare_run_debug_urls(fetches, feed_dict)
    if self._watch_fn is None:
        watch_options = WatchOptions()
    else:
        watch_options = self._watch_fn(fetches, feed_dict)
        if isinstance(watch_options, tuple):
            watch_options = WatchOptions(*watch_options)
    return (debug_urls, watch_options)

Get the debug_urls, and node/op allowlists for the current run() call.

Args:
fetches: Same as the `fetches` argument to `Session.run()`.
feed_dict: Same as the `feed_dict argument` to `Session.run()`.

Returns:
debug_urls: (str or list of str) Debug URLs for the current run() call.
Currently, the list consists of only one URL that is a file:// URL.
watch_options: (WatchOptions) The return value of a watch_fn, containing
options including debug_ops, and allowlists.


def _map_condition(self, wire_map, condition):

        if condition is None:
            new_condition = None
        else:

            bit0 = (condition[0], 0)
            new_condition = (wire_map.get(bit0, bit0)[0], condition[1])
        return new_condition

Use the wire_map dict to change the condition tuple's creg name.

Args:
wire_map (dict): a map from wires to wires
condition (tuple): (ClassicalRegister,int)
Returns:
tuple(ClassicalRegister,int): new condition


def in_cache(self, objpath, metahash):
    try:
        self.path_in_cache(objpath, metahash)
        return True
    except CacheMiss:
        return False

Returns true if object is cached.

Args:
objpath: Filename relative to buildroot.
metahash: hash object


def stop_capture(self):
    raise NotImplementedError('Base class should not be called directly!')

This function stops a capture and guarantees that the capture is
saved to the capture file configured during the start_capture() method.
Depending on the type of the sniffer the file may previously contain
partial results (e.g. for a local sniffer) or may not exist until the
stop_capture() method is executed (e.g. for a remote sniffer).

Depending on the type/subtype and configuration of the sniffer the
capture may terminate on its own without requiring a call to this
function. In such a case it is still necessary to call either this
function or the wait_for_capture() function to make sure that the
capture file is moved to the correct location.

Raises:
NoPermissionError: No permission when trying to stop a capture
and save the capture file.


def add_space(self, line):

        if not isinstance(self.last_item, Space):
            space = Space(self._structure)
            self._structure.append(space)
        self.last_item.add_line(line)
        return self

Add a Space object to the section

Used during initial parsing mainly

Args:
line (str): one line that defines the space, maybe whitespaces


def get_or_create_table(self, project_id, dataset_id, table_id, schema, create_disposition, write_disposition, additional_create_parameters=None):
    from apache_beam.io.gcp.bigquery import BigQueryDisposition
    found_table = None
    try:
        found_table = self.get_table(project_id, dataset_id, table_id)
    except HttpError as exn:
        if exn.status_code == 404:
            if create_disposition == BigQueryDisposition.CREATE_NEVER:
                raise RuntimeError('Table %s:%s.%s not found but create disposition is CREATE_NEVER.' % (project_id, dataset_id, table_id))
        else:
            raise
    if found_table and write_disposition in (BigQueryDisposition.WRITE_EMPTY, BigQueryDisposition.WRITE_TRUNCATE):
        if write_disposition == BigQueryDisposition.WRITE_TRUNCATE:
            self._delete_table(project_id, dataset_id, table_id)
        elif write_disposition == BigQueryDisposition.WRITE_EMPTY and (not self._is_table_empty(project_id, dataset_id, table_id)):
            raise RuntimeError('Table %s:%s.%s is not empty but write disposition is WRITE_EMPTY.' % (project_id, dataset_id, table_id))
    if schema is None and found_table is None:
        raise RuntimeError('Table %s:%s.%s requires a schema. None can be inferred because the table does not exist.' % (project_id, dataset_id, table_id))
    if found_table and write_disposition != BigQueryDisposition.WRITE_TRUNCATE:
        return found_table
    else:
        created_table = None
        try:
            created_table = self._create_table(project_id=project_id, dataset_id=dataset_id, table_id=table_id, schema=schema or found_table.schema, additional_parameters=additional_create_parameters)
        except HttpError as exn:
            if exn.status_code == 409:
                _LOGGER.debug('Skipping Creation. Table %s:%s.%s already exists.' % (project_id, dataset_id, table_id))
                created_table = self.get_table(project_id, dataset_id, table_id)
            else:
                raise
        _LOGGER.info('Created table %s.%s.%s with schema %s. Result: %s.', project_id, dataset_id, table_id, schema or found_table.schema, created_table)
        if write_disposition == BigQueryDisposition.WRITE_TRUNCATE:
            _LOGGER.warning('Sleeping for 150 seconds before the write as ' + 'BigQuery inserts can be routed to deleted table ' + 'for 2 mins after the delete and create.')
            time.sleep(150)
            return created_table
        else:
            return created_table

Gets or creates a table based on create and write dispositions.

The function mimics the behavior of BigQuery import jobs when using the
same create and write dispositions.

Args:
project_id: The project id owning the table.
dataset_id: The dataset id owning the table.
table_id: The table id.
schema: A bigquery.TableSchema instance or None.
create_disposition: CREATE_NEVER or CREATE_IF_NEEDED.
write_disposition: WRITE_APPEND, WRITE_EMPTY or WRITE_TRUNCATE.

Returns:
A bigquery.Table instance if table was found or created.

Raises:
`RuntimeError`: For various mismatches between the state of the table and
the create/write dispositions passed in. For example if the table is not
empty and WRITE_EMPTY was specified then an error will be raised since
the table was expected to be empty.


def _add_doc_value(self, field_name: str, jsonpath: str) -> None:
    path = self.origin_doc.etk.parse_json_path(jsonpath)
    matches = path.find(self.origin_doc.value)
    all_valid = True
    invalid = []
    for a_match in matches:
        if a_match.value:
            valid = self._add_value(field_name, a_match.value, provenance_path=str(a_match.full_path))
            if (not valid):
                invalid.append(((field_name + ':') + str(a_match.value)))
            all_valid = (all_valid and valid)
    if (not all_valid):
        raise KgValueError(('Some kg value type invalid according to schema: ' + json.dumps(invalid)))

Add a value to knowledge graph by giving a jsonpath

Args:
field_name: str
jsonpath: str

Returns:


def HashFile(self, fd, byte_count):

    while byte_count > 0:
      buf_size = min(byte_count, constants.CLIENT_MAX_BUFFER_SIZE)
      buf = fd.read(buf_size)
      if not buf:
        break

      self.HashBuffer(buf)
      byte_count -= buf_size

Updates underlying hashers with a given file.

Args:
fd: A file object that is going to be fed to the hashers.
byte_count: A maximum number of bytes that are going to be processed.


def op_and(self, *elements):

        expression = self.add_operator(Operator(';'))
        for element in elements:
            expression.add_element(element)
        return expression

Update the ``Expression`` by joining the specified additional
``elements`` using an "AND" ``Operator``

Args:
*elements (BaseExpression): The ``Expression`` and/or
``Constraint`` elements which the "AND" ``Operator`` applies
to.

Returns:
Expression: ``self`` or related ``Expression``.


def add_dataset(self, task_name, dataset=None, *, aliases=None):
    self._datasets.append((dataset if (dataset is not None) else TaskData()))
    last_index = (len(self._datasets) - 1)
    self._aliases[task_name] = last_index
    if (aliases is not None):
        for alias in aliases:
            self._aliases[alias] = last_index
    if (len(self._datasets) == 1):
        self._default_index = 0

Add a new dataset to the MultiTaskData.

Args:
task_name (str): The name of the task from which the dataset was received.
dataset (TaskData): The dataset that should be added.
aliases (list): A list of aliases that should be registered with the dataset.


def setOutputHandler(self, outputhandler):

    class OutputHandlerInternal(amplpython.OutputHandler):

        def output(self, kind, msg):
            outputhandler.output(kind, msg)
    self._outputhandler = outputhandler
    self._outputhandler_internal = OutputHandlerInternal()
    lock_and_call((lambda : self._impl.setOutputHandler(self._outputhandler_internal)), self._lock)

Sets a new output handler.

Args:
outputhandler: The function handling the AMPL output derived from
interpreting user commands.


def handle_subscribed_event(self, event_obj, event_name):
    (handler, args) = self.handlers[event_name]
    self.executor.submit(handler, event_obj, *args)

Execute the registered handler of an event.

Retrieve the handler and its arguments, and execute the handler in a
new thread.

Args:
event_obj: Json object of the event.
event_name: Name of the event to call handler for.


def clear_tc(self, owner, data, clear_type):

        batch = self.tcex.batch(owner, action='Delete')
        tc_type = data.get('type')
        path = data.get('path')
        if tc_type in self.tcex.group_types:
            name = self.tcex.playbook.read(data.get('name'))
            name = self.path_data(name, path)
            if name is not None:
                print(
                    'Deleting ThreatConnect Group: {}{}{}'.format(
                        c.Style.BRIGHT, c.Fore.MAGENTA, name
                    )
                )
                self.log.info(
                    '[{}] Deleting ThreatConnect {} with name: {}.'.format(
                        clear_type, tc_type, name
                    )
                )
                batch.group(tc_type, name)
        elif tc_type in self.tcex.indicator_types:
            if data.get('summary') is not None:
                summary = self.tcex.playbook.read(data.get('summary'))
            else:
                resource = self.tcex.resource(tc_type)
                summary = resource.summary(data)
            summary = self.path_data(summary, path)
            if summary is not None:
                print(
                    'Deleting ThreatConnect Indicator: {}{}{}'.format(
                        c.Style.BRIGHT, c.Fore.MAGENTA, summary
                    )
                )
                self.log.info(
                    '[{}] Deleting ThreatConnect {} with value: {}.'.format(
                        clear_type, tc_type, summary
                    )
                )
                batch.indicator(tc_type, summary)
        batch_results = batch.submit()
        self.log.debug('[{}] Batch Results: {}'.format(clear_type, batch_results))
        for error in batch_results.get('errors') or []:
            self.log.error('[{}] Batch Error: {}'.format(clear_type, error))

Delete threat intel from ThreatConnect platform.

Args:
owner (str): The ThreatConnect owner.
data (dict): The data for the threat intel to clear.
clear_type (str): The type of clear action.


def AddRun(self, path, name=None):
    name = (name or path)
    accumulator = None
    with self._accumulators_mutex:
        if ((name not in self._accumulators) or (self._paths[name] != path)):
            if ((name in self._paths) and (self._paths[name] != path)):
                logger.warn('Conflict for name %s: old path %s, new path %s', name, self._paths[name], path)
            logger.info('Constructing EventAccumulator for %s', path)
            accumulator = event_accumulator.EventAccumulator(path, size_guidance=self._size_guidance, tensor_size_guidance=self._tensor_size_guidance, purge_orphaned_data=self.purge_orphaned_data)
            self._accumulators[name] = accumulator
            self._paths[name] = path
    if accumulator:
        if self._reload_called:
            accumulator.Reload()
    return self

Add a run to the multiplexer.

If the name is not specified, it is the same as the path.

If a run by that name exists, and we are already watching the right path,
do nothing. If we are watching a different path, replace the event
accumulator.

If `Reload` has been called, it will `Reload` the newly created
accumulators.

Args:
path: Path to the event files (or event directory) for given run.
name: Name of the run to add. If not provided, is set to path.

Returns:
The `EventMultiplexer`.


def parse_hgnc_line(line, header):
    hgnc_gene = {}
    line = line.rstrip().split('\t')
    raw_info = dict(zip(header, line))
    if ('Withdrawn' in raw_info['status']):
        return hgnc_gene
    hgnc_symbol = raw_info['symbol']
    hgnc_gene['hgnc_symbol'] = hgnc_symbol
    hgnc_gene['hgnc_id'] = int(raw_info['hgnc_id'].split(':')[(- 1)])
    hgnc_gene['description'] = raw_info['name']
    aliases = set([hgnc_symbol, hgnc_symbol.upper()])
    previous_names = raw_info['prev_symbol']
    if previous_names:
        for alias in previous_names.strip('"').split('|'):
            aliases.add(alias)
    alias_symbols = raw_info['alias_symbol']
    if alias_symbols:
        for alias in alias_symbols.strip('"').split('|'):
            aliases.add(alias)
    hgnc_gene['previous_symbols'] = list(aliases)
    hgnc_gene['ensembl_gene_id'] = raw_info.get('ensembl_gene_id')
    omim_id = raw_info.get('omim_id')
    if omim_id:
        hgnc_gene['omim_id'] = int(omim_id.strip('"').split('|')[0])
    else:
        hgnc_gene['omim_id'] = None
    entrez_id = hgnc_gene['entrez_id'] = raw_info.get('entrez_id')
    if entrez_id:
        hgnc_gene['entrez_id'] = int(entrez_id)
    else:
        hgnc_gene['entrez_id'] = None
    ref_seq = raw_info.get('refseq_accession')
    if ref_seq:
        hgnc_gene['ref_seq'] = ref_seq.strip('"').split('|')
    else:
        hgnc_gene['ref_seq'] = []
    uniprot_ids = raw_info.get('uniprot_ids')
    if uniprot_ids:
        hgnc_gene['uniprot_ids'] = uniprot_ids.strip('""').split('|')
    else:
        hgnc_gene['uniprot_ids'] = []
    ucsc_id = raw_info.get('ucsc_id')
    if ucsc_id:
        hgnc_gene['ucsc_id'] = ucsc_id
    else:
        hgnc_gene['ucsc_id'] = None
    vega_id = raw_info.get('vega_id')
    if vega_id:
        hgnc_gene['vega_id'] = vega_id
    else:
        hgnc_gene['vega_id'] = None
    return hgnc_gene

Parse an hgnc formated line

Args:
line(list): A list with hgnc gene info
header(list): A list with the header info

Returns:
hgnc_info(dict): A dictionary with the relevant info


def insert(self, part):

        params = {k: str(v) for k,v in part.params.items()}
        res=c.create_assembly_instance(self.uri.as_dict(), part.uri.as_dict(), params)
        return res

Insert a part into this assembly.

Args:
- part (onshapepy.part.Part) A Part instance that will be inserted.

Returns:
- requests.Response: Onshape response data


def __init__(self, structure, element):

        self.structure = structure
        self.element = element

        framework = list(self.structure.symbol_set)
        get_voronoi = TopographyAnalyzer(self.structure, framework, [], check_volume=False)
        get_voronoi.cluster_nodes()
        get_voronoi.remove_collisions()

        struct_to_trim = self.structure.copy()
        for poss_inter in get_voronoi.vnodes:
            struct_to_trim.append(self.element, poss_inter.frac_coords, coords_are_cartesian=False)

        symmetry_finder = SpacegroupAnalyzer(struct_to_trim, symprec=1e-1)
        equiv_sites_list = symmetry_finder.get_symmetrized_structure().equivalent_sites

        pdc = PointDefectComparator()
        self.unique_defect_seq = []
        for poss_site_list in equiv_sites_list:
            poss_site = poss_site_list[0]
            if poss_site not in self.structure:
                now_defect = Interstitial( self.structure, poss_site)
                append_defect = True
                for unique_defect in self.unique_defect_seq:
                    if pdc.are_equal( now_defect, unique_defect):
                        append_defect = False
                if append_defect:
                    self.unique_defect_seq.append( now_defect)

        self.count_def = 0

Initializes an Interstitial generator using Voronoi sites
Args:
structure (Structure): pymatgen structure object
element (str or Element or Specie): element for the interstitial


def ParseOptions(cls, options, configuration_object):

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

    yara_rules_string = None

    path = getattr(options, 'yara_rules_path', None)
    if path:
      try:
        with io.open(path, 'rt', encoding='utf-8') as rules_file:
          yara_rules_string = rules_file.read()

      except IOError as exception:
        raise errors.BadConfigObject(
            'Unable to read Yara rules file: {0:s} with error: {1!s}'.format(
                path, exception))

      try:

        yara.compile(source=yara_rules_string)

      except yara.Error as exception:
        raise errors.BadConfigObject(
            'Unable to parse Yara rules in: {0:s} with error: {1!s}'.format(
                path, exception))

    setattr(configuration_object, '_yara_rules_string', yara_rules_string)

Parses and validates options.

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

Raises:
BadConfigObject: when the configuration object is of the wrong type.


def cancelRealTimeBars(self, bars: RealTimeBarList):
    self.client.cancelRealTimeBars(bars.reqId)
    self.wrapper.endSubscription(bars)

Cancel the realtime bars subscription.

Args:
bars: The bar list that was obtained from ``reqRealTimeBars``.


def save(self, path):

        with open(path, 'w') as f:
            f.write(self.contents())

Save svg as file(.svg)

Args:
path (str): destination to save file


def triangulate(points):

    seen = set()
    uniqpoints = [ p for p in points if str( p[:2] ) not in seen and not seen.add( str( p[:2] ) )]
    classpoints = [_Point(*point[:2]) for point in uniqpoints]

    triangle_ids = tesselator.computeDelaunayTriangulation(classpoints)

    triangles = [[uniqpoints[i] for i in triangle] for triangle in triangle_ids]

    return triangles

Connects an input list of xy tuples with lines forming a set of
smallest possible Delauney triangles between them.

Arguments:

- **points**: A list of xy or xyz point tuples to triangulate.

Returns:

- A list of triangle polygons. If the input coordinate points contained
a third z value then the output triangles will also have these z values.


def _refresh_grpc(operations_stub, operation_name):
    request_pb = operations_pb2.GetOperationRequest(name=operation_name)
    return operations_stub.GetOperation(request_pb)

Refresh an operation using a gRPC client.

Args:
operations_stub (google.longrunning.operations_pb2.OperationsStub):
The gRPC operations stub.
operation_name (str): The name of the operation.

Returns:
google.longrunning.operations_pb2.Operation: The operation.


def get_image_features(self, pixel_values: torch.FloatTensor, pixel_attention_mask: torch.LongTensor=None):
    batch_size, num_images, num_channels, height, width = pixel_values.shape
    pixel_values = pixel_values.to(dtype=self.dtype)
    pixel_values = pixel_values.view(batch_size * num_images, *pixel_values.shape[2:])
    nb_values_per_image = pixel_values.shape[1:].numel()
    real_images_inds = (pixel_values == 0.0).sum(dim=(-1, -2, -3)) != nb_values_per_image
    pixel_values = pixel_values[real_images_inds].contiguous()
    if pixel_attention_mask is None:
        pixel_attention_mask = torch.ones(size=(pixel_values.size(0), pixel_values.size(2), pixel_values.size(3)), dtype=torch.bool, device=pixel_values.device)
    else:
        pixel_attention_mask = pixel_attention_mask.view(batch_size * num_images, *pixel_attention_mask.shape[2:])
        pixel_attention_mask = pixel_attention_mask[real_images_inds].contiguous()
    patch_size = self.config.vision_config.patch_size
    patches_subgrid = pixel_attention_mask.unfold(dimension=1, size=patch_size, step=patch_size)
    patches_subgrid = patches_subgrid.unfold(dimension=2, size=patch_size, step=patch_size)
    patch_attention_mask = (patches_subgrid.sum(dim=(-1, -2)) == patch_size * patch_size).bool()
    image_hidden_states = self.vision_model(pixel_values=pixel_values, patch_attention_mask=patch_attention_mask)
    image_hidden_states = image_hidden_states.last_hidden_state
    image_hidden_states = self.connector(image_hidden_states, attention_mask=patch_attention_mask.view(pixel_values.size(0), -1))
    image_hidden_states = image_hidden_states.view(-1, image_hidden_states.shape[-1])
    return image_hidden_states

Encodes images into continuous embeddings that can be forwarded to the language model.

Args:
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
The tensors corresponding to the input images.
pixel_attention_mask (`torch.LongTensor`, *optional*):
The attention mask indicating padded regions in the image.


def __init__(self, query, num_splits=0):
    super().__init__()
    if not query.project:
        raise ValueError('query.project cannot be empty')
    if not query:
        raise ValueError('query cannot be empty')
    if num_splits < 0:
        raise ValueError('num_splits must be greater than or equal 0')
    self._project = query.project
    self._datastore_namespace = query.namespace
    self._query = query
    self._num_splits = num_splits

Initialize the `ReadFromDatastore` transform.

This transform outputs elements of type
:class:`~apache_beam.io.gcp.datastore.v1new.types.Entity`.

Args:
query: (:class:`~apache_beam.io.gcp.datastore.v1new.types.Query`) query
used to fetch entities.
num_splits: (:class:`int`) (optional) Number of splits for the query.


def ParseFileObject(self, parser_mediator, file_object):

    volume = pyfsntfs.volume()
    try:
      volume.open_file_object(file_object)
    except IOError as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to open NTFS volume with error: {0!s}'.format(exception))

    try:
      usn_change_journal = volume.get_usn_change_journal()
      self._ParseUSNChangeJournal(parser_mediator, usn_change_journal)
    finally:
      volume.close()

Parses a NTFS $UsnJrnl metadata file-like object.

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


def conversations_setTopic(
        self, *, channel: str, topic: str, **kwargs
    ) -> SlackResponse:

        kwargs.update({"channel": channel, "topic": topic})
        return self.api_call("conversations.setTopic", json=kwargs)

Sets the topic for a conversation.

Args:
channel (str): The channel id. e.g. 'C1234567890'
topic (str): The new topic for the channel. e.g. 'My Topic'


def setProperty(self, orgresource, protect, dummy = 7046):

        url = nurls['setProperty']

        data = {'userid': self.user_id,
                'useridx': self.useridx,
                'orgresource': orgresource,
                'protect': protect,
                'dummy': dummy,
                }

        r = self.session.post(url = url, data = data)

        return resultManager(r.text)

SetProperty

Args:
orgresource: File path
protect: 'Y' or 'N', 중요 표시

Returns:
Integer number: # of version list
False: Failed to get property


def new(namespace, name, wdl, synopsis,
            documentation=None, api_url=fapi.PROD_API_ROOT):

        r = fapi.update_workflow(namespace, name, synopsis,
                                 wdl, documentation, api_url)
        fapi._check_response_code(r, 201)
        d = r.json()
        return Method(namespace, name, d["snapshotId"])

Create new FireCloud method.

If the namespace + name already exists, a new snapshot is created.

Args:
namespace (str): Method namespace for this method
name (str): Method name
wdl (file): WDL description
synopsis (str): Short description of task
documentation (file): Extra documentation for method


def _update_input(self, index, tensor) -> None:
    if not isinstance(tensor, tensor_lib.Tensor):
        raise TypeError('tensor must be a Tensor: %s' % tensor)
    _assert_same_graph(self, tensor)
    self._inputs_val = None
    with self.graph._c_graph.get() as c_graph:
        pywrap_tf_session.UpdateEdge(c_graph, tensor._as_tf_output(), self._tf_input(index))

Update the input to this operation at the given index.

NOTE: This is for TF internal use only. Please don't use it.

Args:
index: the index of the input to update.
tensor: the Tensor to be used as the input at the given index.

Raises:
TypeError: if tensor is not a Tensor,
or if input tensor type is not convertible to dtype.
ValueError: if the Tensor is from a different graph.


def get_submission_ids(self, tournament=1):
    query = '\n            query($tournament: Int!) {\n              rounds(tournament: $tournament\n                     number: 0) {\n                leaderboard {\n                  username\n                  submissionId\n                }\n            }\n        }\n        '
    arguments = {'tournament': tournament}
    data = self.raw_query(query, arguments)['data']['rounds'][0]
    if (data is None):
        return None
    mapping = {item['username']: item['submissionId'] for item in data['leaderboard']}
    return mapping

Get dict with username->submission_id mapping.

Args:
tournament (int): ID of the tournament (optional, defaults to 1)

Returns:
dict: username->submission_id mapping, string->string

Example:
>>> NumerAPI().get_submission_ids()
{'1337ai': '93c46857-fed9-4594-981e-82db2b358daf',
'1x0r': '108c7601-822c-4910-835d-241da93e2e24',
...
}


def __init__(self, meshes: List[layout_lib.Mesh], is_async=True, in_flight_nodes_limit=8):
    if any((not isinstance(mesh, layout_lib.Mesh) for mesh in meshes)):
        raise TypeError('Expected a flat list of Mesh objects, got {}'.format(meshes))
    global _next_device_number
    ctx = context.context()
    with _next_device_number_lock:
        self.name = '{}/device:CUSTOM:{}'.format(ctx.host_address_space(), _next_device_number)
        _next_device_number += 1
    device, device_info = _pywrap_dtensor_device.Allocate(self.name, is_async, in_flight_nodes_limit)
    context.register_custom_device(device, self.name, device_info)
    self._device_info = device_info
    self._current_output_layout = None
    self._current_default_mesh = None
    self._meshes = set()
    self._mesh_lock = threading.Lock()
    for mesh in meshes:
        self._register_mesh(mesh)

Create a new DTensorDevice which executes ops on `underlying_device`.

Args:
meshes: A list of `Mesh` objects indicating groups of devices to execute
on. These may also be registered lazily.
is_async: Indicates whether DTensor operations on this client will return
immediately (with "non-ready" handles) or block until executed. This is
on by default and is exposed as an option for ease of debugging.
in_flight_nodes_limit: Indicates the limit of in-flight nodes before
enqueueing of async operations to DTensorDevice is blocked. This limit
is per mesh. 0 for no limits from DTensor. Default is 8.


def sign(self, message):

        message = _helpers._to_bytes(message, encoding='utf-8')
        return PKCS1_v1_5.new(self._key).sign(SHA256.new(message))

Signs a message.

Args:
message: string, Message to be signed.

Returns:
string, The signature of the message for the given key.


def add_pagination_meta(self, params, meta):
    meta['page_size'] = params['page_size']
    meta['page'] = params['page']
    meta['prev'] = ('page={0}&page_size={1}'.format((params['page'] - 1), params['page_size']) if (meta['page'] > 0) else None)
    meta['next'] = ('page={0}&page_size={1}'.format((params['page'] + 1), params['page_size']) if meta.get('has_more', True) else None)

Extend default meta dictionary value with pagination hints.

Note:
This method handler attaches values to ``meta`` dictionary without
changing it's reference. This means that you should never replace
``meta`` dictionary with any other dict instance but simply modify
its content.

Args:
params (dict): dictionary of decoded parameter values
meta (dict): dictionary of meta values attached to response


def _get_class_frame_source(class_name):
    for frame_info in inspect.stack():
        try:
            with open(frame_info[1]) as fp:
                src = ''.join(fp.readlines()[(frame_info[2] - 1):])
        except IOError:
            continue
        if re.search('\\bclass\\b\\s+\\b{}\\b'.format(class_name), src):
            reader = six.StringIO(src).readline
            tokens = tokenize.generate_tokens(reader)
            source_tokens = []
            indent_level = 0
            base_indent_level = 0
            has_base_level = False
            for (token, value, _, _, _) in tokens:
                source_tokens.append((token, value))
                if (token == tokenize.INDENT):
                    indent_level += 1
                elif (token == tokenize.DEDENT):
                    indent_level -= 1
                    if (has_base_level and (indent_level <= base_indent_level)):
                        return (tokenize.untokenize(source_tokens), frame_info[0].f_globals, frame_info[0].f_locals)
                elif (not has_base_level):
                    has_base_level = True
                    base_indent_level = indent_level
    raise TypeError('Unable to retrieve source for class "{}"'.format(class_name))

Return the source code for a class by checking the frame stack.

This is necessary because it is not possible to get the source of a class
being created by a metaclass directly.

Args:
class_name: The class to look for on the stack.

Returns:
The source code for the requested class if the class was found and the
source was accessible.


def defaultset(self, annotationtype):
    if (inspect.isclass(annotationtype) or isinstance(annotationtype, AbstractElement)):
        annotationtype = annotationtype.ANNOTATIONTYPE
    try:
        return list(self.annotationdefaults[annotationtype].keys())[0]
    except KeyError:
        raise NoDefaultError
    except IndexError:
        raise NoDefaultError

Obtain the default set for the specified annotation type.

Arguments:
annotationtype: The type of annotation, this is conveyed by passing the corresponding annototion class (such as :class:`PosAnnotation` for example), or a member of :class:`AnnotationType`, such as ``AnnotationType.POS``.

Returns:
the set (str)

Raises:
:class:`NoDefaultError` if the annotation type does not exist or if there is ambiguity (multiple sets for the same type)


def add(self, pattern: Pattern) -> int:
    inner = pattern.expression
    if (self.operation is None):
        if ((not isinstance(inner, Operation)) or isinstance(inner, CommutativeOperation)):
            raise TypeError('Pattern must be a non-commutative operation.')
        self.operation = type(inner)
    elif (not isinstance(inner, self.operation)):
        raise TypeError('All patterns must be the same operation, expected {} but got {}'.format(self.operation, type(inner)))
    if (op_len(inner) < 3):
        raise ValueError('Pattern has not enough operands.')
    operands = list(op_iter(inner))
    first_name = self._check_wildcard_and_get_name(operands[0])
    last_name = self._check_wildcard_and_get_name(operands[(- 1)])
    index = len(self._patterns)
    self._patterns.append((pattern, first_name, last_name))
    flatterm = FlatTerm.merged(*(FlatTerm(o) for o in operands[1:(- 1)]))
    self._net.add(flatterm, index)
    return index

Add a pattern that will be recognized by the matcher.

Args:
pattern:
The pattern to add.

Returns:
An internal index for the pattern.

Raises:
ValueError:
If the pattern does not have the correct form.
TypeError:
If the pattern is not a non-commutative operation.


def assert_type(tensor, tf_type, message=None, name=None):
    tf_type = dtypes.as_dtype(tf_type)
    with ops.name_scope(name, 'assert_type', [tensor]):
        if not isinstance(tensor, sparse_tensor.SparseTensor):
            tensor = ops.convert_to_tensor(tensor, name='tensor')
        if tensor.dtype != tf_type:
            raise TypeError(f'{_message_prefix(message)}{getattr(tensor, 'name', 'tensor')} must be of type {tf_type!r}; got {tensor.dtype!r}')
        return control_flow_ops.no_op('statically_determined_correct_type')

Statically asserts that the given `Tensor` is of the specified type.

Args:
tensor: A `Tensor` or `SparseTensor`.
tf_type: A tensorflow type (`dtypes.float32`, `tf.int64`, `dtypes.bool`,
etc).
message: A string to prefix to the default message.
name:  A name to give this `Op`.  Defaults to "assert_type"

Raises:
TypeError: If the tensors data type doesn't match `tf_type`.

Returns:
A `no_op` that does nothing.  Type can be determined statically.


async def _get_or_fetch_conversation(self, conv_id):
    conv = self._conv_dict.get(conv_id, None)
    if (conv is None):
        logger.info('Fetching unknown conversation %s', conv_id)
        res = (await self._client.get_conversation(hangouts_pb2.GetConversationRequest(request_header=self._client.get_request_header(), conversation_spec=hangouts_pb2.ConversationSpec(conversation_id=hangouts_pb2.ConversationId(id=conv_id)), include_event=False)))
        conv_state = res.conversation_state
        event_cont_token = None
        if conv_state.HasField('event_continuation_token'):
            event_cont_token = conv_state.event_continuation_token
        return self._add_conversation(conv_state.conversation, event_cont_token=event_cont_token)
    else:
        return conv

Get a cached conversation or fetch a missing conversation.

Args:
conv_id: string, conversation identifier

Raises:
NetworkError: If the request to fetch the conversation fails.

Returns:
:class:`.Conversation` with matching ID.


def graph(self, node_source, edge_source, layout_provider, **kwargs):
    kw = _graph(node_source, edge_source, **kwargs)
    graph_renderer = GraphRenderer(layout_provider=layout_provider, **kw)
    self.renderers.append(graph_renderer)
    return graph_renderer

Creates a network graph using the given node, edge and layout provider.

Args:
node_source (:class:`~bokeh.models.sources.ColumnDataSource`) : a user-supplied data source
for the graph nodes. An attempt will be made to convert the object to
:class:`~bokeh.models.sources.ColumnDataSource` if needed. If none is supplied, one is created
for the user automatically.

edge_source (:class:`~bokeh.models.sources.ColumnDataSource`) : a user-supplied data source
for the graph edges. An attempt will be made to convert the object to
:class:`~bokeh.models.sources.ColumnDataSource` if needed. If none is supplied, one is created
for the user automatically.

layout_provider (:class:`~bokeh.models.graphs.LayoutProvider`) : a ``LayoutProvider`` instance to
provide the graph coordinates in Cartesian space.

**kwargs: :ref:`userguide_styling_line_properties` and :ref:`userguide_styling_fill_properties`


def CheckConversion(self, data_old, data_expected):
    converter = upgrade_schema_lib.Converter()
    with tempfile.NamedTemporaryFile(suffix='.json', mode='w+') as in_json, tempfile.NamedTemporaryFile(suffix='.json', mode='w+') as out_json, tempfile.NamedTemporaryFile(suffix='.bin', mode='w+b') as out_bin, tempfile.NamedTemporaryFile(suffix='.tflite', mode='w+b') as out_tflite:
        JsonDumpAndFlush(data_old, in_json)
        converter.Convert(in_json.name, out_json.name)
        converter.Convert(in_json.name, out_tflite.name)
        converter.Convert(out_tflite.name, out_bin.name)
        self.assertEqual(open(out_bin.name, 'rb').read(), open(out_tflite.name, 'rb').read())
        converted_schema = json.load(out_json)
        self.assertEqual(converted_schema, data_expected)

Given a data dictionary, test upgrading to current version.

Args:
data_old: TFLite model as a dictionary (arbitrary version).
data_expected: TFLite model as a dictionary (upgraded).


def estimate_univariate_ess_standard_error(chain, batch_size_generator=None, compute_method=None):
    sigma = ((monte_carlo_standard_error(chain, batch_size_generator=batch_size_generator, compute_method=compute_method) ** 2) * len(chain))
    lambda_ = np.var(chain, dtype=np.float64)
    return (len(chain) * (lambda_ / sigma))

r"""Compute the univariate ESS using the standard error method.

This computes the ESS using:

.. math::

ESS(X) = n * \frac{\lambda^{2}}{\sigma^{2}}

Where :math:`\lambda` is the standard deviation of the chain and :math:`\sigma` is estimated using the monte carlo
standard error (which in turn is, by default, estimated using a batch means estimator).

Args:
chain (ndarray): the Markov chain
batch_size_generator (UniVariateESSBatchSizeGenerator): the method that generates that batch sizes
we will use. Per default it uses the :class:`SquareRootSingleBatch` method.
compute_method (ComputeMonteCarloStandardError): the method used to compute the standard error.
By default we will use the :class:`BatchMeansMCSE` method

Returns:
float: the estimated ESS


def get_room_id(self, room_alias):
    content = self._send('GET', '/directory/room/{}'.format(quote(room_alias)))
    return content.get('room_id', None)

Get room id from its alias.

Args:
room_alias (str): The room alias name.

Returns:
Wanted room's id.


def do_batch_status(args):
    rest_client = RestClient(args.url, args.user)
    batch_ids = args.batch_ids.split(',')
    if (args.wait and (args.wait > 0)):
        statuses = rest_client.get_statuses(batch_ids, args.wait)
    else:
        statuses = rest_client.get_statuses(batch_ids)
    if (args.format == 'yaml'):
        fmt.print_yaml(statuses)
    elif (args.format == 'json'):
        fmt.print_json(statuses)
    else:
        raise AssertionError('Missing handler: {}'.format(args.format))

Runs the batch-status command, printing output to the console

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


def __init__(self, obj, methods):

        self._unproxied_object = obj
        self._methods = methods

Initialize the MongoReconnectProxy.

Args:
obj: The object for which all calls should be wrapped in the AutoReconnect
exception handling block.
methods (set): The list of method names that should be wrapped.


def pretty_conjunction(conjunction):
    if not conjunction:
        return 'true'
    elif len(conjunction) == 1:
        return conjunction[0]
    else:
        return '(' + ' & '.join(conjunction) + ')'

Pretty-print a conjunction. Use parentheses as necessary.

E.g. ["a", "b"] -> "(a & b)"

Args:
conjunction: List of strings.

Returns:
A pretty-printed string.


def AddAttribute(self, attribute, value=None, age=None):

    if "w" not in self.mode:
      raise IOError("Writing attribute %s to read only object." % attribute)

    if value is None:
      value = attribute
      attribute = value.attribute_instance

    if self.mode != "w" and attribute.lock_protected and not self.transaction:
      raise IOError("Object must be locked to write attribute %s." % attribute)

    self._CheckAttribute(attribute, value)

    if attribute.versioned:
      if attribute.creates_new_object_version:
        self._new_version = True

      if age:
        value.age = age
      else:
        value.age = rdfvalue.RDFDatetime.Now()

    else:
      self._to_delete.add(attribute)
      self.synced_attributes.pop(attribute, None)
      self.new_attributes.pop(attribute, None)
      value.age = 0

    self._AddAttributeToCache(attribute, value, self.new_attributes)
    self._dirty = True

Add an additional attribute to this object.

If value is None, attribute is expected to be already initialized with a
value. For example:

fd.AddAttribute(fd.Schema.CONTAINS("some data"))

Args:
attribute: The attribute name or an RDFValue derived from the attribute.
value: The value the attribute will be set to.
age: Age (timestamp) of the attribute. If None, current time is used.

Raises:
IOError: If this object is read only.


def register(self, identified_with, identifier, user):

        self.kv_store.set(
            self._get_storage_key(identified_with, identifier),
            self.serialization.dumps(user).encode(),
        )

Register new key for given client identifier.

This is only a helper method that allows to register new
user objects for client identities (keys, tokens, addresses etc.).

Args:
identified_with (object): authentication middleware used
to identify the user.
identifier (str): user identifier.
user (str): user object to be stored in the backend.


def apply_pending(self, panel_obj, version):

        updates = {}
        new_panel = deepcopy(panel_obj)
        new_panel['pending'] = []
        new_panel['date'] = dt.datetime.now()
        info_fields = ['disease_associated_transcripts', 'inheritance_models', 'reduced_penetrance',
            'mosaicism', 'database_entry_version', 'comment']
        new_genes = []

        for update in panel_obj.get('pending', []):
            hgnc_id = update['hgnc_id']

            if update['action'] != 'add':
                updates[hgnc_id] = update
                continue
            info = update.get('info', {})
            gene_obj = {
                'hgnc_id': hgnc_id,
                'symbol': update['symbol']
            }

            for field in info_fields:
                if field in info:
                    gene_obj[field] = info[field]
            new_genes.append(gene_obj)

        for gene in panel_obj['genes']:
            hgnc_id = gene['hgnc_id']

            if hgnc_id not in updates:
                new_genes.append(gene)
                continue

            current_update = updates[hgnc_id]
            action = current_update['action']
            info = current_update['info']

            if action == 'delete':
                continue

            elif action == 'edit':
                for field in info_fields:
                    if field in info:
                        gene[field] = info[field]
                new_genes.append(gene)

        new_panel['genes'] = new_genes
        new_panel['version'] = float(version)

        inserted_id = None

        if new_panel['version'] == panel_obj['version']:

            result = self.panel_collection.find_one_and_replace(
                {'_id':panel_obj['_id']},
                new_panel,
                return_document=pymongo.ReturnDocument.AFTER
            )
            inserted_id = result['_id']
        else:
            new_panel.pop('_id')

            panel_obj['is_archived'] = True
            self.update_panel(panel_obj=panel_obj, date_obj=panel_obj['date'])

            inserted_id = self.panel_collection.insert_one(new_panel).inserted_id

        return inserted_id

Apply the pending changes to an existing gene panel or create a new version of the same panel.

Args:
panel_obj(dict): panel in database to update
version(double): panel version to update

Returns:
inserted_id(str): id of updated panel or the new one


def add_block(self, block):

        self[-1]['__blocks__'].append(block)
        self[-1]['__names__'].append(block.raw())

Add block element to scope
Args:
block (Block): Block object


def to_tensors(self, value: Any) -> List[core.Tensor]:
    del value
    return []

Breaks down a value of this type into Tensors.

For a TraceType instance, the number of tensors generated for corresponding
value should be constant.

Args:
value: A value belonging to this TraceType

Returns:
List of Tensors.


def setdefault(msg_or_dict, key, value):
    if (not get(msg_or_dict, key, default=None)):
        set(msg_or_dict, key, value)

Set the key on a protobuf Message or dictionary to a given value if the
current value is falsy.

Because protobuf Messages do not distinguish between unset values and
falsy ones particularly well (by design), this method treats any falsy
value (e.g. 0, empty list) as a target to be overwritten, on both Messages
and dictionaries.

Args:
msg_or_dict (Union[~google.protobuf.message.Message, Mapping]): the
object.
key (str): The key on the object in question.
value (Any): The value to set.

Raises:
TypeError: If ``msg_or_dict`` is not a Message or dictionary.


def __init__(self, optimizer, scope='meta-optimizer', summary_labels=(), **kwargs):

        self.optimizer = Optimizer.from_spec(spec=optimizer, kwargs=kwargs)

        super(MetaOptimizer, self).__init__(scope=scope, summary_labels=summary_labels)

Creates a new meta optimizer instance.

Args:
optimizer: The optimizer which is modified by this meta optimizer.


def insert(table, columns, values):
    rows = len(values)
    cells = len(columns) * len(values)
    return _Mutator(mutation=Mutation(insert=batch._make_write_pb(table, columns, values)), operation=WriteMutation._OPERATION_INSERT, rows=rows, cells=cells, kwargs={'table': table, 'columns': columns, 'values': values})

Insert one or more new table rows.

Args:
table: Name of the table to be modified.
columns: Name of the table columns to be modified.
values: Values to be modified.


def fprime(self, w, *args):

        x0 = args[0]
        x1 = args[1]

        n0 = x0.shape[0]
        n1 = x1.shape[0]

        n = max(n0, n1) * 10
        idx0 = np.random.choice(range(n0), size=n)
        idx1 = np.random.choice(range(n1), size=n)

        b = np.ones((n, 1))
        i1 = self.i + 1
        h = self.h
        h1 = h + 1

        w2 = w[-h1:].reshape(h1, 1)
        w1 = w[:-h1].reshape(i1, h)

        if sparse.issparse(x0):
            x0 = x0.tocsr()[idx0]
            x1 = x1.tocsr()[idx1]
            xb0 = sparse.hstack((x0, b))
            xb1 = sparse.hstack((x1, b))
        else:
            x0 = x0[idx0]
            x1 = x1[idx1]
            xb0 = np.hstack((x0, b))
            xb1 = np.hstack((x1, b))

        z0 = np.hstack((sigm(xb0.dot(w1)), b))
        z1 = np.hstack((sigm(xb1.dot(w1)), b))
        y0 = z0.dot(w2)
        y1 = z1.dot(w2)

        e = 1 - (y1 - y0)
        dy = e / n

        dw1 = -(xb1.T.dot(dy.dot(w2[:-1].reshape(1, h)) * dsigm(xb1.dot(w1))) -
               xb0.T.dot(dy.dot(w2[:-1].reshape(1, h)) * dsigm(xb0.dot(w1)))
                       ).reshape(i1 * h) + self.l1 * w[:-h1] / (i1 * h)
        dw2 = -(z1 - z0).T.dot(dy).reshape(h1) + self.l2 * w[-h1:] / h1

        return np.append(dw1, dw2)

Return the derivatives of the cost function for predictions.

Args:
w (array of float): weight vectors such that:
w[:-h1] -- weights between the input and h layers
w[-h1:] -- weights between the h and output layers
args: features (args[0]) and target (args[1])

Returns:
gradients of the cost function for predictions


def convert_tokens_to_ids(self, tokens: Union[str, Iterable[str]]) -> Union[int, list[int]]:
    if isinstance(tokens, str):
        return self._convert_token_to_id_with_added_voc(tokens)
    return [self._convert_token_to_id_with_added_voc(token) for token in tokens]

Converts a token string (or a sequence of tokens) in a single integer id (or a Iterable of ids), using the
vocabulary.

Args:
tokens (`str` or `Iterable[str]`): One or several token(s) to convert to token id(s).

Returns:
`int` or `List[int]`: The token id or list of token ids.


def _add_wire(self, wire):
    if (wire not in self.wires):
        self.wires.append(wire)
        self._max_node_id += 1
        input_map_wire = self.input_map[wire] = self._max_node_id
        self._max_node_id += 1
        output_map_wire = self._max_node_id
        wire_name = ('%s[%s]' % (wire[0].name, wire[1]))
        inp_node = DAGNode(data_dict={'type': 'in', 'name': wire_name, 'wire': wire}, nid=input_map_wire)
        outp_node = DAGNode(data_dict={'type': 'out', 'name': wire_name, 'wire': wire}, nid=output_map_wire)
        self._id_to_node[input_map_wire] = inp_node
        self._id_to_node[output_map_wire] = outp_node
        self.input_map[wire] = inp_node
        self.output_map[wire] = outp_node
        self._multi_graph.add_node(inp_node)
        self._multi_graph.add_node(outp_node)
        self._multi_graph.add_edge(inp_node, outp_node)
        self._multi_graph.adj[inp_node][outp_node][0]['name'] = ('%s[%s]' % (wire[0].name, wire[1]))
        self._multi_graph.adj[inp_node][outp_node][0]['wire'] = wire
    else:
        raise DAGCircuitError(('duplicate wire %s' % (wire,)))

Add a qubit or bit to the circuit.

Args:
wire (tuple): (Register,int) containing a register instance and index
This adds a pair of in and out nodes connected by an edge.

Raises:
DAGCircuitError: if trying to add duplicate wire


def __init__(self,
                 exclude_module=None,
                 exclude_class=None,
                 exclude_function=None,
                 nested_class=False,
                 missing_doc=True):

        self.exclude_module = exclude_module
        self.exclude_class = exclude_class
        self.exclude_function = exclude_function
        self.nested_class = nested_class
        self.missing_doc = missing_doc

Init method.

Args:
exclude_module (list): list of Ex instances.
exclude_class (list):  list of Ex instances.
exclude_function (list):  list of Ex instances.
nested_class (bool): whether to get nested classes in classes.
missing_doc (bool): whether to get doc even when empty.


def extract_archive(archive_path, dest):

  if not os.path.isdir(dest):
    os.makedirs(dest)

  try:
    tmpfolder = None

    if (not tf.gfile.Exists(archive_path)) or tf.gfile.IsDirectory(archive_path):
      raise ValueError('archive path %s is not a file' % archive_path)

    if archive_path.startswith('gs:

      tmpfolder = tempfile.mkdtemp()
      cmd_args = ['gsutil', 'cp', archive_path, tmpfolder]
      _shell_process.run_and_monitor(cmd_args, os.getpid())
      archive_path = os.path.join(tmpfolder, os.path.name(archive_path))

    if archive_path.lower().endswith('.tar.gz'):
      flags = '-xzf'
    elif archive_path.lower().endswith('.tar'):
      flags = '-xf'
    else:
      raise ValueError('Only tar.gz or tar.Z files are supported.')

    cmd_args = ['tar', flags, archive_path, '-C', dest]
    _shell_process.run_and_monitor(cmd_args, os.getpid())
  finally:
    if tmpfolder:
      shutil.rmtree(tmpfolder)

Extract a local or GCS archive file to a folder.

Args:
archive_path: local or gcs path to a *.tar.gz or *.tar file
dest: local folder the archive will be extracted to


def _transform_feature(self, inputs):
    id_weight_pair = self.categorical_column._get_sparse_tensors(inputs)
    id_tensor = id_weight_pair.id_tensor
    weight_tensor = id_weight_pair.weight_tensor
    if weight_tensor is not None:
        weighted_column = sparse_ops.sparse_merge(sp_ids=id_tensor, sp_values=weight_tensor, vocab_size=int(self._variable_shape[-1]))
        weighted_column = sparse_ops.sparse_slice(weighted_column, [0, 0], weighted_column.dense_shape)
        return array_ops.scatter_nd(weighted_column.indices, weighted_column.values, weighted_column.dense_shape)
    dense_id_tensor = sparse_ops.sparse_tensor_to_dense(id_tensor, default_value=-1)
    one_hot_id_tensor = array_ops.one_hot(dense_id_tensor, depth=self._variable_shape[-1], on_value=1.0, off_value=0.0)
    return math_ops.reduce_sum(one_hot_id_tensor, axis=[-2])

Returns dense `Tensor` representing feature.

Args:
inputs: A `_LazyBuilder` object to access inputs.

Returns:
Transformed feature `Tensor`.

Raises:
ValueError: if input rank is not known at graph building time.


def from_string(cls, string):

        lines = string.split("\n")
        timestep = int(lines[1])
        natoms = int(lines[3])
        box_arr = np.loadtxt(StringIO("\n".join(lines[5:8])))
        bounds = box_arr[:, :2]
        tilt = None
        if "xy xz yz" in lines[4]:
            tilt = box_arr[:, 2]
            x = (0, tilt[0], tilt[1], tilt[0] + tilt[1])
            y = (0, tilt[2])
            bounds -= np.array([[min(x), max(x)], [min(y), max(y)], [0, 0]])
        box = LammpsBox(bounds, tilt)
        data_head = lines[8].replace("ITEM: ATOMS", "").split()
        data = pd.read_csv(StringIO("\n".join(lines[9:])), names=data_head,
                           delim_whitespace=True)
        return cls(timestep, natoms, box, data)

Constructor from string parsing.

Args:
string (str): Input string.


def facade(projectmainfn, **kwargs):
    site_url = Configuration._create(**kwargs)
    logger.info('--------------------------------------------------')
    logger.info(('> Using HDX Python API Library %s' % Configuration.apiversion))
    logger.info(('> HDX Site: %s' % site_url))
    UserAgent.user_agent = Configuration.read().user_agent
    projectmainfn()

Facade to simplify project setup that calls project main function

Args:
projectmainfn ((None) -> None): main function of project
**kwargs: configuration parameters to pass to HDX Configuration class

Returns:
None


def model_loader(gem_file_path, gem_file_type):

    if gem_file_type.lower() == 'xml' or gem_file_type.lower() == 'sbml':
        model = read_sbml_model(gem_file_path)
    elif gem_file_type.lower() == 'mat':
        model = load_matlab_model(gem_file_path)
    elif gem_file_type.lower() == 'json':
        model = load_json_model(gem_file_path)
    else:
        raise ValueError('File type must be "sbml", "xml", "mat", or "json".')

    return model

Consolidated function to load a GEM using COBRApy. Specify the file type being loaded.

Args:
gem_file_path (str): Path to model file
gem_file_type (str): GEM model type - ``sbml`` (or ``xml``), ``mat``, or ``json`` format

Returns:
COBRApy Model object.


def extract_objects_from_source(self, text, type_filter=None):

    objects = parse_vhdl(text)
    self._register_array_types(objects)

    if type_filter:
      objects = [o for o in objects if isinstance(o, type_filter)]

    return objects

Extract object declarations from a text buffer

Args:
text (str): Source code to parse
type_filter (class, optional): Object class to filter results
Returns:
List of parsed objects.


def deserialize_ndarray(d):

    if 'data' in d:
        x = np.fromstring(
            base64.b64decode(d['data']),
            dtype=d['dtype'])
        x.shape = d['shape']
        return x
    elif 'value' in d:
        return np.array(d['value'], dtype=d['dtype'])
    elif 'npy' in d:
        return deserialize_ndarray_npy(d)
    else:
        raise ValueError('Malformed np.ndarray encoding.')

Deserializes a JSONified :obj:`numpy.ndarray`. Can handle arrays serialized
using any of the methods in this module: :obj:`"npy"`, :obj:`"b64"`,
:obj:`"readable"`.

Args:
d (`dict`): A dictionary representation of an :obj:`ndarray` object.

Returns:
An :obj:`ndarray` object.


def _ws_on_error(self, ws: websocket.WebSocketApp, error: Exception):
    self.logger.error(f'Got error from websocket connection: {str(error)}')

Callback for receiving errors from the websocket connection

Args:
ws: websocket connection
error: exception raised


def add_site_property(self, property_name, values):
    if (len(values) != len(self.sites)):
        raise ValueError('Values must be same length as sites.')
    for (site, val) in zip(self.sites, values):
        site.properties[property_name] = val

Adds a property to a site.

Args:
property_name (str): The name of the property to add.
values (list): A sequence of values. Must be same length as
number of sites.


def _tokens_to_subtoken_ids(self, tokens):
    ret = []
    for token in tokens:
        ret.extend(self._token_to_subtoken_ids(token))
    return ret

Converts a list of tokens to a list of subtoken ids.

Args:
tokens: a list of strings.
Returns:
a list of integers in the range [0, vocab_size)


def AddDir(self, dirpath):

    if dirpath not in self._dirs:
      self._dirs.add(dirpath)
      return True
    return False

Adds a directory path as a source.

Args:
dirpath: a string representing a path to the directory.

Returns:
True if the directory is not an already existing source.


def send(self, request):

        self._connection.connection.rpush(self._request_key, pickle.dumps(request))
        resp_key = '{}:{}'.format(SIGNAL_REDIS_PREFIX, request.uid)

        while True:
            if self._connection.polling_time > 0.0:
                sleep(self._connection.polling_time)

            response_data = self._connection.connection.get(resp_key)
            if response_data is not None:
                self._connection.connection.delete(resp_key)
                break

        return pickle.loads(response_data)

Send a request to the server and wait for its response.

Args:
request (Request): Reference to a request object that is sent to the server.

Returns:
Response: The response from the server to the request.