def init_cache(self, batch_size, max_length, encoder_outputs):
    decoder_input_ids = jnp.ones((batch_size, max_length), dtype='i4')
    decoder_attention_mask = jnp.ones_like(decoder_input_ids)
    decoder_position_ids = jnp.broadcast_to(jnp.arange(jnp.atleast_2d(decoder_input_ids).shape[-1]), decoder_input_ids.shape)

    def _decoder_forward(module, decoder_input_ids, decoder_attention_mask, decoder_position_ids, **kwargs):
        decoder_module = module._get_decoder_module()
        return decoder_module(input_ids=decoder_input_ids, attention_mask=decoder_attention_mask, position_ids=decoder_position_ids, **kwargs)
    init_variables = self.module.init(jax.random.PRNGKey(0), decoder_input_ids=decoder_input_ids, decoder_attention_mask=decoder_attention_mask, decoder_position_ids=decoder_position_ids, encoder_hidden_states=encoder_outputs[0], init_cache=True, method=_decoder_forward)
    return unfreeze(init_variables['cache'])

Args:
batch_size (`int`):
batch_size used for fast auto-regressive decoding. Defines the batch size of the initialized cache.
max_length (`int`):
maximum possible length for auto-regressive decoding. Defines the sequence length of the initialized
cache.
encoder_outputs (`Union[FlaxBaseModelOutput, tuple(tuple(jnp.ndarray)]`):
`encoder_outputs` consists of (`last_hidden_state`, *optional*: `hidden_states`, *optional*:
`attentions`). `last_hidden_state` of shape `(batch_size, sequence_length, hidden_size)`, *optional*)
is a sequence of hidden-states at the output of the last layer of the encoder. Used in the
cross-attention of the decoder.


def all_events_filter(
            self,
            from_block: BlockSpecification = GENESIS_BLOCK_NUMBER,
            to_block: BlockSpecification = 'latest',
    ) -> StatelessFilter:

        return self.events_filter(None, from_block, to_block)

Install a new filter for all the events emitted by the current token network contract

Args:
from_block: Create filter starting from this block number (default: 0).
to_block: Create filter stopping at this block number (default: 'latest').

Return:
The filter instance.


def _get_operation_input_field_values(self, metadata, file_input):

    input_args = metadata['request']['ephemeralPipeline']['inputParameters']
    vals_dict = metadata['request']['pipelineArgs']['inputs']

    names = [
        arg['name'] for arg in input_args if ('localCopy' in arg) == file_input
    ]

    return {name: vals_dict[name] for name in names if name in vals_dict}

Returns a dictionary of envs or file inputs for an operation.

Args:
metadata: operation metadata field
file_input: True to return a dict of file inputs, False to return envs.

Returns:
A dictionary of input field name value pairs


def _PrintAnalysisStatusHeader(self, processing_status):
    self._output_writer.Write('Storage file\t\t: {0:s}\n'.format(self._storage_file_path))
    self._PrintProcessingTime(processing_status)
    if (processing_status and processing_status.events_status):
        self._PrintEventsStatus(processing_status.events_status)
    self._output_writer.Write('\n')

Prints the analysis status header.

Args:
processing_status (ProcessingStatus): processing status.


def accuracy(y_true: [list, np.ndarray], y_predicted: [list, np.ndarray]) -> float:

    examples_len = len(y_true)
    correct = sum([y1 == y2 for y1, y2 in zip(y_true, y_predicted)])
    return correct / examples_len if examples_len else 0

Calculate accuracy in terms of absolute coincidence

Args:
y_true: array of true values
y_predicted: array of predicted values

Returns:
portion of absolutely coincidental samples


def diff(self) -> List[str]:
    return set(self.to_track.keys()) - self._seen

This method returns a set difference between the keys in the tracked state dict and the one we have access so far.
This is an effective method to check if we have update all the keys

Returns:
List[str]: List of keys not yet updated


def draw_point(self, x, y):
    check_int_err(lib.SDL_RenderDrawPoint(self._ptr, x, y))

Draw a point on the current rendering target.

Args:
x (int): The x coordinate of the point.
y (int): The y coordinate of the point.

Raises:
SDLError: If an error is encountered.


def calculate_subscription_lifecycle(subscription_id):

    subscription = Subscription.objects.select_related("messageset", "schedule").get(
        id=subscription_id
    )
    behind = subscription.messages_behind()
    if behind == 0:
        return

    current_messageset = subscription.messageset
    current_sequence_number = subscription.next_sequence_number
    end_subscription = Subscription.fast_forward_lifecycle(subscription, save=False)[-1]
    BehindSubscription.objects.create(
        subscription=subscription,
        messages_behind=behind,
        current_messageset=current_messageset,
        current_sequence_number=current_sequence_number,
        expected_messageset=end_subscription.messageset,
        expected_sequence_number=end_subscription.next_sequence_number,
    )

Calculates the expected lifecycle position the subscription in
subscription_ids, and creates a BehindSubscription entry for them.

Args:
subscription_id (str): ID of subscription to calculate lifecycle for


async def leave_conversation(self, conv_id):

        logger.info('Leaving conversation: {}'.format(conv_id))
        await self._conv_dict[conv_id].leave()
        del self._conv_dict[conv_id]

Leave a conversation.

Args:
conv_id (str): ID of conversation to leave.


def _MeanAggregator(inputs, segments):
    result = []
    for inputs_i, segments_i in zip(array_ops.split(inputs, inputs.shape[0]), array_ops.split(segments, segments.shape[0])):
        means_i = math_ops.unsorted_segment_mean(inputs_i, segments_i, num_segments=math_ops.reduce_max(segments_i) + 1)
        result.append(array_ops.reshape(array_ops.gather(means_i, segments_i), [-1]))
    return array_ops_stack.stack(result, axis=0)

Replaces each segment with its mean along the last axis.

Specifically, each value in the `inputs` tensor gets replaced by the mean
value computed from the values that belong to the same segment.

Args:
inputs: A 2-tensor. Aggregation is done over dimension 1.
segments: A 2-tensor, same shape as `input`.

Returns:
The result, same shape and type as `inputs`.


def __process_instr(self, instr, avoid, next_addr, initial_state, execution_state, trace_current):

        if instr.mnemonic == ReilMnemonic.JCC:
            not_taken_addr = next_addr
            address, index = split_address(instr.address)

            logger.debug("[+] Processing branch: {:

            if isinstance(instr.operands[0], ReilRegisterOperand):
                next_ip = self.__process_branch_cond(instr, avoid, initial_state, execution_state, trace_current, not_taken_addr)

            else:
                next_ip = self.__process_branch_uncond(instr, trace_current, not_taken_addr)

        else:
            trace_current += [(instr, None)]

            self.__cpu.execute(instr)

            next_ip = next_addr

        return next_ip

Process a REIL instruction.

Args:
instr (ReilInstruction): Instruction to process.
avoid (list): List of addresses to avoid while executing the code.
next_addr (int): Address of the following instruction.
initial_state (State): Initial execution state.
execution_state (Queue): Queue of execution states.
trace_current (list): Current trace.

Returns:
int: Returns the next address to execute.


def _op_in_graph_mode(tensor):
    if context.executing_eagerly():
        return tensor
    return tensor.op

Returns the tensor's op in graph mode, or the tensor in eager mode.

This is useful because sometimes an op is needed in graph mode instead of a
tensor. In eager mode, there are no ops.

Args:
tensor: A tensor.

Returns:
The tensor's op in graph mode. The tensor in eager mode.


def download(url, output_file=None, open_file=True, allow_overwrite=False):

    filename = url.split('/')[-1]
    if output_file is None:
        cache = os.path.join(get_data_home(), filename)
    else:
        cache = output_file
    if os.path.exists(cache) and not allow_overwrite:
        logger.info("> {} already exists.".format(cache))
        logger.info("> If you have any issue when using this file, ")
        logger.info("> manually remove the file and try download again.")
    else:
        r = request.urlopen(url)
        try:
            if six.PY2:
                content_length = int(r.info().dict['content-length'])
            elif six.PY3:
                content_length = int(r.info()['Content-Length'])
        except:
            content_length = 0
        unit = 1000000
        content = b''
        with tqdm(total=content_length, desc=filename, unit='B', unit_scale=True, unit_divisor=1024) as t:
            while True:
                data = r.read(unit)
                l = len(data)
                t.update(l)
                if l == 0:
                    break
                content += data
        with open(cache, 'wb') as f:
            f.write(content)
    if not open_file:
        return
    return open(cache, 'rb')

Download a file from URL.

Args:
url (str): URL.
output_file (str, optional): If given, the downloaded file is written to the given path.
open_file (bool): If True, it returns an opened file stream of the downloaded file.
allow_overwrite (bool): If True, it overwrites an existing file.

Returns:
Returns file object if open_file is True, otherwise None.


def on_click(self, handler):
    self.on_event(ButtonClick, handler)
    self.on_event(MenuItemClick, handler)

Set up a handler for button or menu item clicks.

Args:
handler (func) : handler function to call when button is activated.

Returns:
None


def delete_metadata(self, resource, keys):

        self.metadata_service.set_auth(self._token_metadata)
        self.metadata_service.delete(resource, keys)

Deletes the given key-value pairs associated with the given resource.

Will attempt to delete all key-value pairs even if some fail.

Args:
resource (intern.resource.boss.BossResource)
keys (list)

Raises:
HTTPErrorList on failure.


def resample(self, size, interpolation=gdalconst.GRA_NearestNeighbour):

        factors = (size[0] / float(self.RasterXSize),
                   size[1] / float(self.RasterYSize))
        affine = AffineTransform(*tuple(self.affine))
        affine.scale = (affine.scale[0] / factors[0],
                        affine.scale[1] / factors[1])
        dest = self.new(size, affine)

        gdal.ReprojectImage(self.ds, dest.ds, None, None, interpolation)
        return dest

Returns a new instance resampled to provided size.

Arguments:
size -- tuple of x,y image dimensions


def subset_gctoo(gctoo, row_bool=None, col_bool=None, rid=None, cid=None, ridx=None, cidx=None, exclude_rid=None, exclude_cid=None):
    assert (sum([(rid is not None), (row_bool is not None), (ridx is not None)]) <= 1), 'Only one of rid, row_bool, and ridx can be provided.'
    assert (sum([(cid is not None), (col_bool is not None), (cidx is not None)]) <= 1), 'Only one of cid, col_bool, and cidx can be provided.'
    rows_to_keep = get_rows_to_keep(gctoo, rid, row_bool, ridx, exclude_rid)
    cols_to_keep = get_cols_to_keep(gctoo, cid, col_bool, cidx, exclude_cid)
    rows_to_keep_bools = gctoo.data_df.index.isin(rows_to_keep)
    cols_to_keep_bools = gctoo.data_df.columns.isin(cols_to_keep)
    out_gctoo = GCToo.GCToo(src=gctoo.src, version=gctoo.version, data_df=gctoo.data_df.loc[(rows_to_keep_bools, cols_to_keep_bools)], row_metadata_df=gctoo.row_metadata_df.loc[(rows_to_keep_bools, :)], col_metadata_df=gctoo.col_metadata_df.loc[(cols_to_keep_bools, :)])
    assert (out_gctoo.data_df.size > 0), 'Subsetting yielded an empty gct!'
    logger.info(('Initial GCToo with {} rows and {} columns subsetted down to ' + '{} rows and {} columns.').format(gctoo.data_df.shape[0], gctoo.data_df.shape[1], out_gctoo.data_df.shape[0], out_gctoo.data_df.shape[1]))
    return out_gctoo

Extract a subset of data from a GCToo object in a variety of ways.
The order of rows and columns will be preserved.

Args:
gctoo (GCToo object)
row_bool (list of bools): length must equal gctoo.data_df.shape[0]
col_bool (list of bools): length must equal gctoo.data_df.shape[1]
rid (list of strings): rids to include
cid (list of strings): cids to include
ridx (list of integers): row integer ids to include
cidx (list of integers): col integer ids to include
exclude_rid (list of strings): rids to exclude
exclude_cid (list of strings): cids to exclude

Returns:
out_gctoo (GCToo object): gctoo after subsetting


def reset_port_protection(self, id_or_uri, timeout=(- 1)):
    uri = (self._client.build_uri(id_or_uri) + '/resetportprotection')
    return self._client.update_with_zero_body(uri, timeout)

Triggers a reset of port protection.

Cause port protection to be reset on all the interconnects of the logical interconnect that matches ID.

Args:
id_or_uri: Can be either the interconnect id or the interconnect uri.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: The interconnect.


def add_gene_info(self, variant_obj, gene_panels=None):
    gene_panels = (gene_panels or [])
    variant_obj['has_refseq'] = False
    extra_info = {}
    for panel_obj in gene_panels:
        for gene_info in panel_obj['genes']:
            hgnc_id = gene_info['hgnc_id']
            if (hgnc_id not in extra_info):
                extra_info[hgnc_id] = []
            extra_info[hgnc_id].append(gene_info)
    for variant_gene in variant_obj.get('genes', []):
        hgnc_id = variant_gene['hgnc_id']
        hgnc_gene = self.hgnc_gene(hgnc_id)
        if (not hgnc_gene):
            continue
        transcripts_dict = {}
        for transcript in hgnc_gene.get('transcripts', []):
            tx_id = transcript['ensembl_transcript_id']
            transcripts_dict[tx_id] = transcript
        hgnc_gene['transcripts_dict'] = transcripts_dict
        if hgnc_gene.get('incomplete_penetrance'):
            variant_gene['omim_penetrance'] = True
        panel_info = extra_info.get(hgnc_id, [])
        disease_associated = set()
        disease_associated_no_version = set()
        manual_penetrance = False
        mosaicism = False
        manual_inheritance = set()
        for gene_info in panel_info:
            for tx in gene_info.get('disease_associated_transcripts', []):
                stripped = re.sub('\\.[0-9]', '', tx)
                disease_associated_no_version.add(stripped)
                disease_associated.add(tx)
            if gene_info.get('reduced_penetrance'):
                manual_penetrance = True
            if gene_info.get('mosaicism'):
                mosaicism = True
            manual_inheritance.update(gene_info.get('inheritance_models', []))
        variant_gene['disease_associated_transcripts'] = list(disease_associated)
        variant_gene['manual_penetrance'] = manual_penetrance
        variant_gene['mosaicism'] = mosaicism
        variant_gene['manual_inheritance'] = list(manual_inheritance)
        for transcript in variant_gene.get('transcripts', []):
            tx_id = transcript['transcript_id']
            if (not (tx_id in transcripts_dict)):
                continue
            hgnc_transcript = transcripts_dict[tx_id]
            if hgnc_transcript.get('is_primary'):
                transcript['is_primary'] = True
            if (not hgnc_transcript.get('refseq_id')):
                continue
            refseq_id = hgnc_transcript['refseq_id']
            transcript['refseq_id'] = refseq_id
            variant_obj['has_refseq'] = True
            if (refseq_id in disease_associated_no_version):
                transcript['is_disease_associated'] = True
            transcript['refseq_identifiers'] = hgnc_transcript.get('refseq_identifiers', [])
        variant_gene['common'] = hgnc_gene
        variant_gene['disease_terms'] = self.disease_terms(hgnc_id)
    return variant_obj

Add extra information about genes from gene panels

Args:
variant_obj(dict): A variant from the database
gene_panels(list(dict)): List of panels from database


def calculate_3D_elastic_energy(self, film, match, elasticity_tensor=None, include_strain=False):
    if (elasticity_tensor is None):
        return 9999
    struc = SlabGenerator(self.film, match['film_miller'], 20, 15, primitive=False).get_slab().oriented_unit_cell
    film_matrix = list(match['film_sl_vecs'])
    film_matrix.append(np.cross(film_matrix[0], film_matrix[1]))
    substrate_matrix = list(match['sub_sl_vecs'])
    temp_sub = np.cross(substrate_matrix[0], substrate_matrix[1])
    temp_sub = ((temp_sub * fast_norm(film_matrix[2])) / fast_norm(temp_sub))
    substrate_matrix.append(temp_sub)
    transform_matrix = np.transpose(np.linalg.solve(film_matrix, substrate_matrix))
    dfm = Deformation(transform_matrix)
    strain = dfm.green_lagrange_strain.convert_to_ieee(struc, initial_fit=False)
    energy_density = elasticity_tensor.energy_density(strain)
    if include_strain:
        return (((film.volume * energy_density) / len(film.sites)), strain.von_mises_strain)
    else:
        return ((film.volume * energy_density) / len(film.sites))

Calculates the multi-plane elastic energy. Returns 999 if no elastic
tensor was given on init

Args:
film(Structure): conventional standard structure for the film
match(dictionary) : match dictionary from substrate analyzer
elasticity_tensor(ElasticTensor): elasticity tensor for the film
include_strain(bool): include strain in the output or not; changes
return from just the energy to a tuple with the energy and strain
in voigt notation


def _fetch_certs(request, certs_url):
    response = request(certs_url, method='GET')
    if (response.status != http_client.OK):
        raise exceptions.TransportError('Could not fetch certificates at {}'.format(certs_url))
    return json.loads(response.data.decode('utf-8'))

Fetches certificates.

Google-style cerificate endpoints return JSON in the format of
``{'key id': 'x509 certificate'}``.

Args:
request (google.auth.transport.Request): The object used to make
HTTP requests.
certs_url (str): The certificate endpoint URL.

Returns:
Mapping[str, str]: A mapping of public key ID to x.509 certificate
data.


def get_collectors(self, limit=1000, offset=0):
    options = {'limit': limit, 'offset': offset}
    request = requests.get(self.url, params=options, auth=self.auth)
    try:
        results = request.json()['collectors']
    except KeyError:
        results = request.json()
    except json.decoder.JSONDecodeError:
        results = []
    return results

Returns a dict of collectors.

Args:
limit (int): number of collectors to return
offset (int): the offset of where the list of collectors should begin from


def draw_layer(ax, layer):
    ax.set_aspect('equal', 'datalim')
    ax.plot(*layer)
    ax.axis('off')

Draws a layer on the given matplotlib axis.

Args:
ax (axis): the matplotlib axis to draw on
layer (layer): the layers to plot


def _print_results(file, status):
    file_color = c.Fore.GREEN
    status_color = c.Fore.RED
    if (status == 'Success'):
        status_color = c.Fore.GREEN
    elif (status == 'Skipped'):
        status_color = c.Fore.YELLOW
    print('{}{!s:<13}{}{!s:<35}{}{!s:<8}{}{}'.format(c.Fore.CYAN, 'Downloading:', file_color, file, c.Fore.CYAN, 'Status:', status_color, status))

Print the download results.

Args:
file (str): The filename.
status (str): The file download status.


def __init__(self, additional_note='', kwargs_dict=None):
    self._additional_note = additional_note
    if kwargs_dict:
        bullets = []
        for key in sorted(kwargs_dict.keys()):
            value = kwargs_dict[key]
            if any((x.isspace() for x in key)):
                raise ValueError('Parameter name "%s" contains whitespace.' % key)
            value = value.lstrip()
            if '\n' in value:
                raise ValueError('Parameter description for "%s" contains newlines.' % key)
            bullets.append('*  `%s`: %s' % (key, value))
        self._additional_note += '\n\n

Initializes the AppendDocstring object.

Args:
additional_note: Python string added as additional docstring to public
version of function.
kwargs_dict: Python string/string dictionary representing specific kwargs
expanded from the **kwargs input.

Raises:
ValueError: if kwargs_dict.key contains whitespace.
ValueError: if kwargs_dict.value contains newlines.


def bidiagonalize_real_matrix_pair_with_symmetric_products(mat1: np.ndarray, mat2: np.ndarray, *, rtol: float=1e-05, atol: float=1e-08, check_preconditions: bool=True) -> Tuple[(np.ndarray, np.ndarray)]:
    if check_preconditions:
        if np.any((np.imag(mat1) != 0)):
            raise ValueError('mat1 must be real.')
        if np.any((np.imag(mat2) != 0)):
            raise ValueError('mat2 must be real.')
        if (not predicates.is_hermitian(mat1.dot(mat2.T), rtol=rtol, atol=atol)):
            raise ValueError('mat1 @ mat2.T must be symmetric.')
        if (not predicates.is_hermitian(mat1.T.dot(mat2), rtol=rtol, atol=atol)):
            raise ValueError('mat1.T @ mat2 must be symmetric.')
    (base_left, base_diag, base_right) = _svd_handling_empty(np.real(mat1))
    base_diag = np.diag(base_diag)
    dim = base_diag.shape[0]
    rank = dim
    while ((rank > 0) and tolerance.all_near_zero(base_diag[((rank - 1), (rank - 1))], atol=atol)):
        rank -= 1
    base_diag = base_diag[(:rank, :rank)]
    semi_corrected = base_left.T.dot(np.real(mat2)).dot(base_right.T)
    overlap = semi_corrected[(:rank, :rank)]
    overlap_adjust = diagonalize_real_symmetric_and_sorted_diagonal_matrices(overlap, base_diag, rtol=rtol, atol=atol, check_preconditions=check_preconditions)
    extra = semi_corrected[(rank:, rank:)]
    (extra_left_adjust, _, extra_right_adjust) = _svd_handling_empty(extra)
    left_adjust = combinators.block_diag(overlap_adjust, extra_left_adjust)
    right_adjust = combinators.block_diag(overlap_adjust.T, extra_right_adjust)
    left = left_adjust.T.dot(base_left.T)
    right = base_right.T.dot(right_adjust.T)
    return (left, right)

Finds orthogonal matrices that diagonalize both mat1 and mat2.

Requires mat1 and mat2 to be real.
Requires mat1.T @ mat2 to be symmetric.
Requires mat1 @ mat2.T to be symmetric.

Args:
mat1: One of the real matrices.
mat2: The other real matrix.
rtol: Relative numeric error threshold.
atol: Absolute numeric error threshold.
check_preconditions: If set, verifies that the inputs are real, and that
mat1.T @ mat2 and mat1 @ mat2.T are both symmetric. Defaults to set.

Returns:
A tuple (L, R) of two orthogonal matrices, such that both L @ mat1 @ R
and L @ mat2 @ R are diagonal matrices.

Raises:
ValueError: Matrices don't meet preconditions (e.g. not real).


def get_config():
    profiles = {}
    curr = None
    cmd = ['netsh', 'advfirewall', 'show', 'allprofiles']
    ret = __salt__['cmd.run_all'](cmd, python_shell=False, ignore_retcode=True)
    if (ret['retcode'] != 0):
        raise CommandExecutionError(ret['stdout'])
    for line in ret['stdout'].splitlines():
        if (not curr):
            tmp = re.search('(.*) Profile Settings:', line)
            if tmp:
                curr = tmp.group(1)
        elif line.startswith('State'):
            profiles[curr] = (line.split()[1] == 'ON')
            curr = None
    return profiles

Get the status of all the firewall profiles

Returns:
dict: A dictionary of all profiles on the system

Raises:
CommandExecutionError: If the command fails

CLI Example:

.. code-block:: bash

salt '*' firewall.get_config


def _GetBetweenQEqualsAndAmpersand(self, url):
    (_, _, url) = url.partition('?')
    (_, _, url) = url.partition('q=')
    if (not url):
        return ''
    (url, _, _) = url.partition('&')
    return url

Retrieves the substring between the substrings 'q=' and '&'.

Args:
url (str): URL.

Returns:
str: search query, the value between 'q=' and '&'  or None if no query
was found.


def recursive_copy(src_dir, dest_dir):

  file_io.recursive_create_dir(dest_dir)
  for file_name in file_io.list_directory(src_dir):
    old_path = os.path.join(src_dir, file_name)
    new_path = os.path.join(dest_dir, file_name)

    if file_io.is_directory(old_path):
      recursive_copy(old_path, new_path)
    else:
      file_io.copy(old_path, new_path, overwrite=True)

Copy the contents of src_dir into the folder dest_dir.
Args:
src_dir: gsc or local path.
dest_dir: gcs or local path.


def polyFitIgnoringOutliers(
        x, y, deg=2, niter=3, nstd=2, return_outliers=False):

    if return_outliers:
        a = all_outliers = np.zeros_like(y, dtype=bool)
    for i in range(niter):
        poly = np.polyfit(x, y, deg)
        p = np.poly1d(poly)
        if i == niter - 1:
            break
        y_fit = p(x)
        dy = y - y_fit
        std = (dy**2).mean()**0.5
        inliers = abs(dy) < nstd * std
        if return_outliers:
            a[~inliers] = True

        if inliers.sum() > deg + 1:
            x = x[inliers]
            y = y[inliers]
            if return_outliers:
                a = a[inliers]
        else:
            break
    if return_outliers:
        return p, all_outliers
    return p

Returns:
(np.poly1d): callable function of polynomial fit excluding all outliers
Args:
deg (int): degree of polynomial fit
n_iter (int): do linear regression n times
successive removing
nstd (float): exclude outliers, if their deviation
is > [nstd] * standard deviation
return_outliers (bool): also return outlier positions as 2. arg


def registerAccount(self, person, vendorSpecific=None):

        response = self.registerAccountResponse(person, vendorSpecific)
        return self._read_boolean_response(response)

See Also: registerAccountResponse()

Args:
person:
vendorSpecific:

Returns:


def get_or_create(session, model, **kwargs):

    instance = session.query(model).filter_by(**kwargs).first()
    if instance:
        return instance, False
    else:
        instance = model(**kwargs)
        if 'dataset' in kwargs:
            instance.update_sequence_id(session, kwargs['dataset'])
        session.add(instance)
        session.commit()
        return instance, True

Get or create sqlalchemy instance.

Args:
session (Sqlalchemy session):
model (sqlalchemy model):
kwargs (dict): kwargs to lookup or create instance.

Returns:
Tuple: first element is found or created instance, second is boolean - True if instance created,
False if instance found.


def absl_to_cpp(level):

  if not isinstance(level, int):
    raise TypeError('Expect an int level, found {}'.format(type(level)))
  if level >= 0:

    return 0
  else:
    return -level

Converts an absl log level to a cpp log level.

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

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

Returns:
The corresponding integer level for use in Abseil C++.


def report_server_init_errors(address=None, port=None, **kwargs):
    try:
        (yield)
    except EnvironmentError as e:
        if (e.errno == errno.EADDRINUSE):
            log.critical('Cannot start Bokeh server, port %s is already in use', port)
        elif (e.errno == errno.EADDRNOTAVAIL):
            log.critical("Cannot start Bokeh server, address '%s' not available", address)
        else:
            codename = errno.errorcode[e.errno]
            log.critical('Cannot start Bokeh server [%s]: %r', codename, e)
        sys.exit(1)

A context manager to help print more informative error messages when a
``Server`` cannot be started due to a network problem.

Args:
address (str) : network address that the server will be listening on

port (int) : network address that the server will be listening on

Example:

.. code-block:: python

with report_server_init_errors(**server_kwargs):
server = Server(applications, **server_kwargs)

If there are any errors (e.g. port or address in already in use) then a
critical error will be logged and the process will terminate with a
call to ``sys.exit(1)``


def get(self, url, params=None, **kwargs):

        return self.call_api(
            "GET",
            url,
            params=params,
            **kwargs
        )

Call the API with a GET request.

Args:
url (str): Resource location relative to the base URL.
params (dict or None): Query-string parameters.

Returns:
ResultParser or ErrorParser.


def optimize_boolean_expression_comparisons(ir_blocks):
    operator_inverses = {u'=': u'!=', u'!=': u'='}

    def visitor_fn(expression):
        'Expression visitor function that performs the above rewriting.'
        if (not isinstance(expression, BinaryComposition)):
            return expression
        left_is_binary_composition = isinstance(expression.left, BinaryComposition)
        right_is_binary_composition = isinstance(expression.right, BinaryComposition)
        if ((not left_is_binary_composition) and (not right_is_binary_composition)):
            return expression
        identity_literal = None
        inverse_literal = None
        if (expression.operator == u'='):
            identity_literal = TrueLiteral
            inverse_literal = FalseLiteral
        elif (expression.operator == u'!='):
            identity_literal = FalseLiteral
            inverse_literal = TrueLiteral
        else:
            return expression
        expression_to_rewrite = None
        if ((expression.left == identity_literal) and right_is_binary_composition):
            return expression.right
        elif ((expression.right == identity_literal) and left_is_binary_composition):
            return expression.left
        elif ((expression.left == inverse_literal) and right_is_binary_composition):
            expression_to_rewrite = expression.right
        elif ((expression.right == inverse_literal) and left_is_binary_composition):
            expression_to_rewrite = expression.left
        if (expression_to_rewrite is None):
            return expression
        elif (expression_to_rewrite.operator not in operator_inverses):
            return expression
        else:
            return BinaryComposition(operator_inverses[expression_to_rewrite.operator], expression_to_rewrite.left, expression_to_rewrite.right)
    new_ir_blocks = []
    for block in ir_blocks:
        new_block = block.visit_and_update_expressions(visitor_fn)
        new_ir_blocks.append(new_block)
    return new_ir_blocks

Optimize comparisons of a boolean binary comparison expression against a boolean literal.

Rewriting example:
BinaryComposition(
'=',
BinaryComposition('!=', something, NullLiteral)
False)

The above is rewritten into:
BinaryComposition('=', something, NullLiteral)

Args:
ir_blocks: list of basic block objects

Returns:
a new list of basic block objects, with the optimization applied


def cudnn_stacked_bi_gru(units, n_hidden, seq_lengths=None, n_stacks=2, keep_prob=1.0, concat_stacked_outputs=False, trainable_initial_states=False, name='cudnn_stacked_bi_gru', reuse=False):
    if (seq_lengths is None):
        seq_lengths = (tf.ones([tf.shape(units)[0]], dtype=tf.int32) * tf.shape(units)[1])
    outputs = [units]
    with tf.variable_scope(name, reuse=reuse):
        for n in range(n_stacks):
            if (n == 0):
                inputs = outputs[(- 1)]
            else:
                inputs = variational_dropout(outputs[(- 1)], keep_prob=keep_prob)
            ((h_fw, h_bw), _) = cudnn_bi_gru(inputs, n_hidden, seq_lengths, n_layers=1, trainable_initial_states=trainable_initial_states, name='{}_cudnn_bi_gru'.format(n), reuse=reuse)
            outputs.append(tf.concat([h_fw, h_bw], axis=2))
    if concat_stacked_outputs:
        return tf.concat(outputs[1:], axis=2)
    return outputs[(- 1)]

Fast CuDNN Stacked Bi-GRU implementation

Args:
units: tf.Tensor with dimensions [B x T x F], where
B - batch size
T - number of tokens
F - features
n_hidden: dimensionality of hidden state
seq_lengths: number of tokens in each sample in the batch
n_stacks: number of stacked Bi-GRU
keep_prob: dropout keep_prob between Bi-GRUs (intra-layer dropout)
concat_stacked_outputs: return last Bi-GRU output or concat outputs from every Bi-GRU,
trainable_initial_states: whether to create a special trainable variable
to initialize the hidden states of the network or use just zeros
name: name of the variable scope to use
reuse: whether to reuse already initialized variable

Returns:
h - all hidden states along T dimension,
tf.Tensor with dimensionality [B x T x ((n_hidden * 2) * n_stacks)]


def easeInOutExpo(n):

    _checkRange(n)
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        n = n * 2
        if n < 1:
            return 0.5 * 2**(10 * (n - 1))
        else:
            n -= 1

            return 0.5 * (-1 * (2 ** (-10 * n)) + 2)

An exponential tween function that accelerates, reaches the midpoint, and then decelerates.

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

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


def _prepare_4d_causal_attention_mask_with_cache_position(attention_mask: torch.Tensor, sequence_length: int, target_length: int, dtype: torch.dtype, cache_position: torch.Tensor, batch_size: int, **kwargs):
    if attention_mask is not None and attention_mask.dim() == 4:
        causal_mask = attention_mask
    else:
        min_dtype = torch.finfo(dtype).min
        causal_mask = torch.full((sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=cache_position.device)
        if sequence_length != 1:
            causal_mask = torch.triu(causal_mask, diagonal=1)
        causal_mask *= torch.arange(target_length, device=cache_position.device) > cache_position.reshape(-1, 1)
        causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
        if attention_mask is not None:
            causal_mask = causal_mask.clone()
            mask_length = attention_mask.shape[-1]
            padding_attention_mask = (attention_mask[:, None, None, :] == attention_mask[:, None, :, None])[:, :, -sequence_length:, :].to(dtype)
            padding_mask = causal_mask[:, :, :, :mask_length] + padding_attention_mask
            padding_mask = padding_mask == 0
            causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(padding_mask, min_dtype)
    return causal_mask

Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
`(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.

Args:
attention_mask (`torch.Tensor`):
A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape
`(batch_size, 1, query_length, key_value_length)`.
sequence_length (`int`):
The sequence length being processed.
target_length (`int`):
The target length: when generating with static cache, the mask should be as long as the static cache,
to account for the 0 padding, the part of the cache that is not filled yet.
dtype (`torch.dtype`):
The dtype to use for the 4D attention mask.
cache_position (`torch.Tensor`):
Indices depicting the position of the input sequence tokens in the sequence.
batch_size (`torch.Tensor`):
Batch size.


def golden_images(self):
    if (not self.__golden_images):
        self.__golden_images = GoldenImages(self.__connection)
    return self.__golden_images

Gets the Golden Images API client.

Returns:
GoldenImages:


def next_generation(self, mut_rate=0, max_mut_amt=0, log_base=10):
    if (self.__num_processes > 1):
        process_pool = Pool(processes=self.__num_processes)
        members = [m.get() for m in self.__members]
    else:
        members = self.__members
    if (len(members) == 0):
        raise Exception('Generation 0 not found: use generate_population() first')
    selected_members = self.__select_fn(members)
    reproduction_probs = list(reversed(logspace(0.0, 1.0, num=len(selected_members), base=log_base)))
    reproduction_probs = (reproduction_probs / sum(reproduction_probs))
    self.__members = []
    for _ in range(self.__pop_size):
        parent_1 = nrandom.choice(selected_members, p=reproduction_probs)
        parent_2 = nrandom.choice(selected_members, p=reproduction_probs)
        feed_dict = {}
        for param in self.__parameters:
            which_parent = uniform(0, 1)
            if (which_parent < 0.5):
                feed_dict[param.name] = parent_1.parameters[param.name]
            else:
                feed_dict[param.name] = parent_2.parameters[param.name]
            feed_dict[param.name] = self.__mutate_parameter(feed_dict[param.name], param, mut_rate, max_mut_amt)
        if (self.__num_processes > 1):
            self.__members.append(process_pool.apply_async(self._start_process, [self.__cost_fn, feed_dict, self.__cost_fn_args]))
        else:
            self.__members.append(Member(feed_dict, self.__cost_fn(feed_dict, self.__cost_fn_args)))
    if (self.__num_processes > 1):
        process_pool.close()
        process_pool.join()
    self.__determine_best_member()

Generates the next population from a previously evaluated generation

Args:
mut_rate (float): mutation rate for new members (0.0 - 1.0)
max_mut_amt (float): how much the member is allowed to mutate
(0.0 - 1.0, proportion change of mutated parameter)
log_base (int): the higher this number, the more likely the first
Members (chosen with supplied selection function) are chosen
as parents for the next generation


def closing(input_rasterfilename, times):
    input_raster = RasterUtilClass.read_raster(input_rasterfilename)
    closing_raster = input_raster
    for i in range(times):
        closing_raster = RasterUtilClass.raster_dilation(closing_raster)
    for i in range(times):
        closing_raster = RasterUtilClass.raster_erosion(closing_raster)
    return closing_raster

Do closing.

Closing: Dilate firstly, then Erode.

Args:
input_rasterfilename: input original raster image filename.
times: Erode and Dilate times.

Returns:
closing_raster: raster image after close.


def transpose(self, name=None):

    if any(x > 1 for x in self._rate):
      raise base.NotSupportedError(
          "Cannot transpose a dilated convolution module.")

    if any(p != self._conv_op_padding for p in self._padding):
      raise base.NotSupportedError(
          "Cannot tranpose a convolution using mixed paddings or paddings "
          "other than SAME or VALID.")

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

    def output_shape():
      if self._data_format == DATA_FORMAT_NCHW:
        return self.input_shape[2:4]
      else:
        return self.input_shape[1:3]

    return Conv2DTranspose(output_channels=lambda: self._input_channels,
                           output_shape=output_shape,
                           kernel_shape=self._kernel_shape,
                           stride=self._stride,
                           padding=self._conv_op_padding,
                           use_bias=self._use_bias,
                           initializers=self._initializers,
                           partitioners=self._partitioners,
                           regularizers=self._regularizers,
                           data_format=self._data_format,
                           custom_getter=self._custom_getter,
                           name=name)

Returns matching `Conv2DTranspose` module.

Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.

Returns:
`Conv2DTranspose` module.

Raises:
base.NotSupportedError: If `rate` in any dimension > 1.


def copy(self, destination):

		destination_uri = self.repo.parse_uri(destination)

		response = self.repo.api.http_request('COPY', self.uri, data=None, headers={'Destination':destination_uri.toPython()})

		if response.status_code == 201:
			return destination_uri
		else:
			raise Exception('HTTP %s, could not move resource %s to %s' % (response.status_code, self.uri, destination_uri))

Method to copy resource to another location

Args:
destination (rdflib.term.URIRef, str): URI location to move resource

Returns:
(Resource) new, moved instance of resource


def micros_to_timestamp(micros, timestamp):

  seconds = long(micros / _MICROS_PER_SECOND)
  micro_remainder = micros % _MICROS_PER_SECOND
  timestamp.seconds = seconds
  timestamp.nanos = micro_remainder * _NANOS_PER_MICRO

Convert microseconds from utc epoch to google.protobuf.timestamp.

Args:
micros: a long, number of microseconds since utc epoch.
timestamp: a google.protobuf.timestamp.Timestamp to populate.


def warp(self, to_sref, dest=None, interpolation=gdalconst.GRA_NearestNeighbour):

        if not hasattr(to_sref, 'ExportToWkt'):
            to_sref = SpatialReference(to_sref)
        dest_wkt = to_sref.ExportToWkt()
        dtype = self[0].DataType
        err_thresh = 0.125

        vrt = gdal.AutoCreateWarpedVRT(self.ds, None, dest_wkt,
                                       interpolation, err_thresh)
        if vrt is None:
            raise ValueError('Could not warp %s to %s' % (self, dest_wkt))
        warpsize = (vrt.RasterXSize, vrt.RasterYSize, len(self))
        warptrans = vrt.GetGeoTransform()
        vrt = None
        if dest is None:
            imgio = MemFileIO()
            rwarp = self.driver.raster(imgio, warpsize, dtype)
            imgio.close()
        else:
            rwarp = self.driver.raster(dest, warpsize, dtype)
        rwarp.SetGeoTransform(warptrans)
        rwarp.SetProjection(to_sref)
        if self.nodata is not None:
            for band in rwarp:
                band.SetNoDataValue(self.nodata)
                band = None

        gdal.ReprojectImage(self.ds, rwarp.ds, None, None, interpolation)
        return rwarp

Returns a new reprojected instance.

Arguments:
to_sref -- spatial reference as a proj4 or wkt string, or a
SpatialReference
Keyword args:
dest -- filepath as str
interpolation -- GDAL interpolation type


def register(self, table):

        if table.table_type.is_system:
            raise ValueError('Cannot add system table to catalog')
        if not table.table_type.is_shared:
            raise ValueError('Cannot add local table to catalog')
        if table.is_substitute:
            raise ValueError('Cannot add substitute table to catalog')

        versions = self.__tables.get(table.name)
        if versions is None:
            versions = {}
            self.__tables[table.name] = versions
        versions[table.version] = table

Adds a shared table to the catalog.

Args:
table (SymbolTable): A non-system, shared symbol table.


def compose_q_update_vec(self, q_update_vec: torch.Tensor, normalize_quats: bool=True) -> Rotation:
    quats = self.get_quats()
    new_quats = quats + quat_multiply_by_vec(quats, q_update_vec)
    return Rotation(rot_mats=None, quats=new_quats, normalize_quats=normalize_quats)

Returns a new quaternion Rotation after updating the current object's underlying rotation with a quaternion
update, formatted as a [*, 3] tensor whose final three columns represent x, y, z such that (1, x, y, z) is the
desired (not necessarily unit) quaternion update.

Args:
q_update_vec:
A [*, 3] quaternion update tensor
normalize_quats:
Whether to normalize the output quaternion
Returns:
An updated Rotation


def getToC(doc, simple=True):

    def recurse(olItem, liste, lvl):
        'Recursively follow the outline item chain and record item information in a list.'
        while olItem:
            if olItem.title:
                title = olItem.title
            else:
                title = ' '
            if (not olItem.isExternal):
                if olItem.uri:
                    page = (olItem.page + 1)
                else:
                    page = (- 1)
            else:
                page = (- 1)
            if (not simple):
                link = getLinkDict(olItem)
                liste.append([lvl, title, page, link])
            else:
                liste.append([lvl, title, page])
            if olItem.down:
                liste = recurse(olItem.down, liste, (lvl + 1))
            olItem = olItem.next
        return liste
    if doc.isClosed:
        raise ValueError('illegal operation on closed document')
    olItem = doc.outline
    if (not olItem):
        return []
    lvl = 1
    liste = []
    return recurse(olItem, liste, lvl)

Create a table of contents.

Args:
simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation.


def __init__(self, name, data=None, package_cls=None):

        super(PackageMaker, self).__init__(data)
        self.name = name
        self.package_cls = package_cls or Package

        self.installed_variants = []
        self.skipped_variants = []

Create a package maker.

Args:
name (str): Package name.


def copy_sharding(from_tensor, to_tensor, use_sharding_op=False):
    sharding = get_tensor_sharding(from_tensor)
    if sharding is None:
        return to_tensor
    if isinstance(to_tensor, resource_variable_ops.BaseResourceVariable) and context.xla_sharding_for_resource_variables_enabled():
        proto = xla_data_pb2.OpSharding()
        proto.ParseFromString(sharding)
        to_tensor._set_xla_sharding(proto)
        return to_tensor
    if use_sharding_op:
        to_tensor = tf2xla.sharding(to_tensor, sharding=sharding)
    attr_value = attr_value_pb2.AttrValue(s=sharding)
    to_tensor.op._set_attr('_XlaSharding', attr_value)
    return to_tensor

Copies the a tensor's sharding to another.

Args:
from_tensor: Source tensor. Must be the sole output of an op.
to_tensor: the tensor the annotate with the copy.
use_sharding_op: whether to create a sharding op on `to_tensor`.

Returns:
A tensor with sharding annotation copied from `from_tensor`.


def __init__(self, items: Optional[Iterable[Any]]=None, *, value_spec: Optional[pg_typing.List]=None, onchange_callback: Optional[Callable[[Dict[utils.KeyPath, base.FieldUpdate]], None]]=None, allow_partial: bool=False, accessor_writable: bool=True, sealed: bool=False, root_path: Optional[utils.KeyPath]=None):
    if value_spec and (not isinstance(value_spec, pg_typing.List)):
        raise TypeError(f"Argument 'value_spec' must be a `pg.typing.List` object. Encountered {value_spec}.")
    base.Symbolic.__init__(self, allow_partial=allow_partial, accessor_writable=accessor_writable, sealed=False, root_path=root_path)
    self._value_spec = None
    self._onchange_callback = None
    list.__init__(self)
    if items:
        if isinstance(items, List):
            items = items.sym_values()
        for item in items:
            self._set_item_without_permission_check(len(self), item)
    if value_spec:
        self.use_value_spec(value_spec, allow_partial)
    self._onchange_callback = onchange_callback
    self.seal(sealed)

Constructor.

Args:
items: A optional iterable object as initial value for this list.
value_spec: Value spec that applies to this List.
onchange_callback: Callback when sub-tree has been modified.
allow_partial: Whether to allow unbound or partial fields. This takes
effect only when value_spec is not None.
accessor_writable: Whether to allow modification of this List using
accessors (operator[]).
sealed: Whether to seal this List after creation.
root_path: KeyPath of this List in its object tree.


def sym_distance(cls, q0, q1):
    q = Quaternion.sym_log_map(q0, q1)
    return q.norm

Quaternion symmetrized distance.

Find the intrinsic symmetrized geodesic distance between q0 and q1.

Params:
q0: the first quaternion
q1: the second quaternion

Returns:
A positive amount corresponding to the length of the symmetrized
geodesic curve connecting q0 to q1.

Note:
This formulation is more numerically stable when performing
iterative gradient descent on the Riemannian quaternion manifold.
However, the distance between q and -q is equal to pi, rendering this
formulation not useful for measuring rotation similarities when the
samples are spread over a "solid" angle of more than pi/2 radians
(the spread refers to quaternions as point samples on the unit hypersphere).


def __init__(self, batch_size, key_depth, val_depth, memory_size,
               sharpen_factor=1., name="neural_memory"):

    self.name = name
    self.batch_size = batch_size
    self.key_depth = key_depth
    self.val_depth = val_depth
    self.memory_size = memory_size
    self.sharpen_factor = sharpen_factor
    with tf.variable_scope(name):
      self.segment_number = tf.get_variable(
          "segment_number", [self.batch_size],
          dtype=tf.int32, trainable=False,
          initializer=tf.constant_initializer(100000))
      self.mem_vals = tf.get_variable(
          "memvals", [self.batch_size, self.memory_size, self.val_depth],
          dtype=tf.float32, trainable=False,
          initializer=tf.constant_initializer(.0))
      self.mean_logits = tf.get_variable(
          "meanlogits", [self.batch_size, self.memory_size],
          dtype=tf.float32, trainable=False,
          initializer=tf.constant_initializer(.0))

Initialize the memory object.

Args:
batch_size: the batch size.
key_depth: the depth of the memory keys.
val_depth: the depth of the memory values.
memory_size: the number of items in the memory.
sharpen_factor: the sharpen_factor for addressing the memory.
name: the optional variable scope.


def _get_token(request=None, allowed_auth_schemes=('OAuth', 'Bearer'), allowed_query_keys=('bearer_token', 'access_token')):
    allowed_auth_schemes = _listlike_guard(allowed_auth_schemes, 'allowed_auth_schemes', iterable_only=True)
    auth_header = os.environ.get('HTTP_AUTHORIZATION')
    if auth_header:
        for auth_scheme in allowed_auth_schemes:
            if auth_header.startswith(auth_scheme):
                return auth_header[(len(auth_scheme) + 1):]
        return None
    if request:
        allowed_query_keys = _listlike_guard(allowed_query_keys, 'allowed_query_keys', iterable_only=True)
        for key in allowed_query_keys:
            (token, _) = request.get_unrecognized_field_info(key)
            if token:
                return token

Get the auth token for this request.

Auth token may be specified in either the Authorization header or
as a query param (either access_token or bearer_token).  We'll check in
this order:
1. Authorization header.
2. bearer_token query param.
3. access_token query param.

Args:
request: The current request, or None.

Returns:
The token in the request or None.


def parse_cscore(infile):
    cscore_dict = {}
    with open(infile, 'r') as f:
        for ll in f.readlines():
            if ll.lower().startswith('model1'):
                l = ll.split()
                cscore = l[1]
                tmscore_full = l[2].split('+-')
                tmscore = tmscore_full[0]
                tmscore_err = tmscore_full[1]
                rmsd_full = l[3].split('+-')
                rmsd = rmsd_full[0]
                rmsd_err = rmsd_full[1]
                cscore_dict['c_score'] = float(cscore)
                cscore_dict['tm_score'] = float(tmscore)
                cscore_dict['tm_score_err'] = float(tmscore_err)
                cscore_dict['rmsd'] = float(rmsd)
                cscore_dict['rmsd_err'] = float(rmsd_err)
    return cscore_dict

Parse the cscore file to return a dictionary of scores.

Args:
infile (str): Path to cscore

Returns:
dict: Dictionary of scores


def end_of(self, event_id, import_options=True):
    event_id = str(event_id)
    if (event_id in DatePickerDictionary.items):
        linked_picker = DatePickerDictionary.items[event_id]
        self.config['linked_to'] = linked_picker.config['id']
        if import_options:
            backup_moment_format = self.config['options']['format']
            self.config['options'].update(linked_picker.config['options'])
            self.config['options'].update(self.options_param)
            if (self.format_param or ('format' in self.options_param)):
                self.config['options']['format'] = backup_moment_format
            else:
                self.format = linked_picker.format
        self.config['options']['useCurrent'] = False
        self._link_to(linked_picker)
    else:
        raise KeyError(('start-date not specified for event_id "%s"' % event_id))
    return self

Set Date-Picker as the end-date of a date-range.

Args:
- event_id (string): User-defined unique id for linking two fields
- import_options (bool): inherit options from start-date input,
default: TRUE


def compile_action_preconditions(self, state: Sequence[tf.Tensor], action: Sequence[tf.Tensor]) -> List[TensorFluent]:
    scope = self.action_precondition_scope(state, action)
    preconds = []
    with self.graph.as_default():
        with tf.name_scope('action_preconditions'):
            for p in self.rddl.domain.preconds:
                fluent = self._compile_expression(p, scope)
                preconds.append(fluent)
            return preconds

Compiles the action preconditions given current `state` and `action` fluents.

Args:
state (Sequence[tf.Tensor]): The current state fluents.
action (Sequence[tf.Tensor]): The action fluents.

Returns:
A list of :obj:`rddl2tf.fluent.TensorFluent`.


def create_event_model(event):

    if event['type'].startswith('task'):
        factory = {
            JobEventName.Started: JobStartedEvent,
            JobEventName.Succeeded: JobSucceededEvent,
            JobEventName.Stopped: JobStoppedEvent,
            JobEventName.Aborted: JobAbortedEvent
        }
        if event['type'] in factory:
            return factory[event['type']].from_event(event)
        else:
            raise JobEventTypeUnsupported(
                'Unsupported event type {}'.format(event['type']))
    elif event['type'].startswith('worker'):
        raise WorkerEventTypeUnsupported(
            'Unsupported event type {}'.format(event['type']))
    else:
        raise EventTypeUnknown('Unknown event type {}'.format(event['type']))

Factory function that turns a celery event into an event object.

Args:
event (dict): A dictionary that represents a celery event.

Returns:
object: An event object representing the received event.

Raises:
JobEventTypeUnsupported: If an unsupported celery job event was received.
WorkerEventTypeUnsupported: If an unsupported celery worker event was received.
EventTypeUnknown: If an unknown event type (neither job nor worker) was received.


Get the equivalent yaw-pitch-roll angles aka. intrinsic Tait-Bryan angles following the z-y'-x'' convention

Returns:
yaw:    rotation angle around the z-axis in radians, in the range `[-pi, pi]`
pitch:  rotation angle around the y'-axis in radians, in the range `[-pi/2, -pi/2]`
roll:   rotation angle around the x''-axis in radians, in the range `[-pi, pi]`

The resulting rotation_matrix would be R = R_x(roll) R_y(pitch) R_z(yaw)

Note:
This feature only makes sense when referring to a unit quaternion. Calling this method will implicitly normalise the Quaternion object to a unit quaternion if it is not already one.


def initial_state(self, batch_size, trainable=False):
    init_state = tf.eye(self._mem_slots, batch_shape=[batch_size])
    if (self._mem_size > self._mem_slots):
        difference = (self._mem_size - self._mem_slots)
        pad = tf.zeros((batch_size, self._mem_slots, difference))
        init_state = tf.concat([init_state, pad], (- 1))
    elif (self._mem_size < self._mem_slots):
        init_state = init_state[(:, :, :self._mem_size)]
    return init_state

Creates the initial memory.

We should ensure each row of the memory is initialized to be unique,
so initialize the matrix to be the identity. We then pad or truncate
as necessary so that init_state is of size
(batch_size, self._mem_slots, self._mem_size).

Args:
batch_size: The size of the batch.
trainable: Whether the initial state is trainable. This is always True.

Returns:
init_state: A truncated or padded matrix of size
(batch_size, self._mem_slots, self._mem_size).


def Collect(self, top_frame):

    frame = top_frame
    top_line = self.breakpoint['location']['line']
    breakpoint_frames = self.breakpoint['stackFrames']
    try:

      if 'expressions' in self.breakpoint:
        self.breakpoint['evaluatedExpressions'] = [
            self._CaptureExpression(top_frame, expression) for expression
            in self.breakpoint['expressions']]

      while frame and (len(breakpoint_frames) < self.max_frames):
        line = top_line if frame == top_frame else frame.f_lineno
        code = frame.f_code
        if len(breakpoint_frames) < self.max_expand_frames:
          frame_arguments, frame_locals = self.CaptureFrameLocals(frame)
        else:
          frame_arguments = []
          frame_locals = []

        breakpoint_frames.append({
            'function': _GetFrameCodeObjectName(frame),
            'location': {
                'path': NormalizePath(code.co_filename),
                'line': line
            },
            'arguments': frame_arguments,
            'locals': frame_locals
        })
        frame = frame.f_back

    except BaseException as e:

      self.breakpoint['status'] = {
          'isError': True,
          'description': {
              'format': ('INTERNAL ERROR: Failed while capturing locals '
                         'of frame $0: $1'),
              'parameters': [str(len(breakpoint_frames)), str(e)]}}

    num_vars = 1

    while (num_vars < len(self._var_table)) and (
        self._total_size < self.max_size):
      self._var_table[num_vars] = self.CaptureVariable(
          self._var_table[num_vars], 0, self.default_capture_limits,
          can_enqueue=False)

      num_vars += 1

    self.TrimVariableTable(num_vars)

    self._CaptureEnvironmentLabels()
    self._CaptureRequestLogId()
    self._CaptureUserId()

Collects call stack, local variables and objects.

Starts collection from the specified frame. We don't start from the top
frame to exclude the frames due to debugger. Updates the content of
self.breakpoint.

Args:
top_frame: top frame to start data collection.


def make_call_types(f, globals_d):

    arg_spec = getargspec(f)
    args = [k for k in arg_spec.args if k != "self"]

    defaults = {}
    if arg_spec.defaults:
        default_args = args[-len(arg_spec.defaults):]
        for a, default in zip(default_args, arg_spec.defaults):
            defaults[a] = default

    if not getattr(f, "__annotations__", None):

        annotations = make_annotations(f, globals_d)
    else:
        annotations = f.__annotations__

    call_types = OrderedDict()
    for a in args:
        anno = anno_with_default(annotations[a], defaults.get(a, NO_DEFAULT))
        assert isinstance(anno, Anno), \
            "Argument %r has type %r which is not an Anno" % (a, anno)
        call_types[a] = anno

    return_type = anno_with_default(annotations.get("return", None))
    if return_type is Any:
        return_type = Anno("Any return value", Any, "return")
    assert return_type is None or isinstance(return_type, Anno), \
        "Return has type %r which is not an Anno" % (return_type,)

    return call_types, return_type

Make a call_types dictionary that describes what arguments to pass to f

Args:
f: The function to inspect for argument names (without self)
globals_d: A dictionary of globals to lookup annotation definitions in


def start_listener_thread(self, timeout_ms=30000, exception_handler=None):

        try:
            thread = Thread(target=self.listen_forever,
                            args=(timeout_ms, exception_handler))
            thread.daemon = True
            self.sync_thread = thread
            self.should_listen = True
            thread.start()
        except RuntimeError:
            e = sys.exc_info()[0]
            logger.error("Error: unable to start thread. %s", str(e))

Start a listener thread to listen for events in the background.

Args:
timeout (int): How long to poll the Home Server for before
retrying.
exception_handler (func(exception)): Optional exception handler
function which can be used to handle exceptions in the caller
thread.


def __write_to_fil_light(self, filename_out, *args, **kwargs):

        n_bytes  = self.header[b'nbits'] / 8
        with open(filename_out, "wb") as fileh:
            fileh.write(generate_sigproc_header(self))
            j = self.data
            if n_bytes == 4:
                np.float32(j.ravel()).tofile(fileh)
            elif n_bytes == 2:
                np.int16(j.ravel()).tofile(fileh)
            elif n_bytes == 1:
                np.int8(j.ravel()).tofile(fileh)

Write data to .fil file.

Args:
filename_out (str): Name of output file


def _get_snippet_ctime(self, snip_name):

        if snip_name not in self.snip_ctimes:
            snippet = yaml_snippet_loader.YamlSnippetLoader.get_snippet_by_name(snip_name)
            self.snip_ctimes[snip_name] = os.path.getctime(snippet.path)
        return self.snip_ctimes[snip_name]

Returns and remembers (during this DevAssistant invocation) last ctime of given
snippet.

Calling ctime costs lost of time and some snippets, like common_args, are used widely,
so we don't want to call ctime bazillion times on them during one invocation.

Args:
snip_name: name of snippet to get ctime for
Returns:
ctime of the snippet


def _GetWinevtRcDatabaseReader(self):
    if ((not self._winevt_database_reader) and self._data_location):
        database_path = os.path.join(self._data_location, self._WINEVT_RC_DATABASE)
        if (not os.path.isfile(database_path)):
            return None
        self._winevt_database_reader = winevt_rc.WinevtResourcesSqlite3DatabaseReader()
        if (not self._winevt_database_reader.Open(database_path)):
            self._winevt_database_reader = None
    return self._winevt_database_reader

Opens the Windows Event Log resource database reader.

Returns:
WinevtResourcesSqlite3DatabaseReader: Windows Event Log resource
database reader or None.


class PoolerAnswerClass(nn.Module):

    def __init__(self, config):
        super().__init__()
        self.dense_0 = nn.Linear(config.hidden_size * 2, config.hidden_size)
        self.activation = nn.Tanh()
        self.dense_1 = nn.Linear(config.hidden_size, 1, bias=False)
        logger.warning_once('[DEPRECATION WARNING] `PoolerAnswerClass` is deprecated and will be removed in v4.53. Please use model-specific class, e.g. `XLMPoolerAnswerClass`.')

    def forward(self, hidden_states: torch.FloatTensor, start_states: Optional[torch.FloatTensor]=None, start_positions: Optional[torch.LongTensor]=None, cls_index: Optional[torch.LongTensor]=None) -> torch.FloatTensor:

        hsz = hidden_states.shape[-1]
        assert start_states is not None or start_positions is not None, 'One of start_states, start_positions should be not None'
        if start_positions is not None:
            start_positions = start_positions[:, None, None].expand(-1, -1, hsz)
            start_states = hidden_states.gather(-2, start_positions).squeeze(-2)
        if cls_index is not None:
            cls_index = cls_index[:, None, None].expand(-1, -1, hsz)
            cls_token_state = hidden_states.gather(-2, cls_index).squeeze(-2)
        else:
            cls_token_state = hidden_states[:, -1, :]
        x = self.dense_0(torch.cat([start_states, cls_token_state], dim=-1))
        x = self.activation(x)
        x = self.dense_1(x).squeeze(-1)
        return x

Compute SQuAD 2.0 answer class from classification and start tokens hidden states.

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


def __call__(self, func: T) -> T:
    api_names_attr = API_ATTRS[self._api_name].names
    api_names_attr_v1 = API_ATTRS_V1[self._api_name].names
    _, undecorated_func = tf_decorator.unwrap(func)
    self.set_attr(undecorated_func, api_names_attr, self._names)
    self.set_attr(undecorated_func, api_names_attr_v1, self._names_v1)
    for name in self._names:
        _NAME_TO_SYMBOL_MAPPING[name] = func
    for name_v1 in self._names_v1:
        _NAME_TO_SYMBOL_MAPPING['compat.v1.%s' % name_v1] = func
    return func

Calls this decorator.

Args:
func: decorated symbol (function or class).

Returns:
The input function with _tf_api_names attribute set.


def create_pull_response(responses):
    from google.cloud import pubsub
    from google.protobuf import timestamp_pb2
    res = pubsub.types.PullResponse()
    for response in responses:
        received_message = pubsub.types.ReceivedMessage()
        message = received_message.message
        message.data = response.data
        if response.attributes is not None:
            for k, v in response.attributes.items():
                message.attributes[k] = v
        publish_time = timestamp_pb2.Timestamp()
        if response.publish_time_secs is not None:
            publish_time.seconds = response.publish_time_secs
        if response.publish_time_nanos is not None:
            publish_time.nanos = response.publish_time_nanos
        message.publish_time = publish_time
        if response.ack_id is not None:
            received_message.ack_id = response.ack_id
        res.received_messages.append(received_message)
    return res

Create an instance of ``google.cloud.pubsub.types.ReceivedMessage``.

Used to simulate the response from pubsub.SubscriberClient().pull().

Args:
responses: list of ``PullResponseMessage``

Returns:
An instance of ``google.cloud.pubsub.types.PullResponse`` populated with
responses.


def get_reference(root):
    reference = {}
    elem = root.find('bibliographyLink')
    if (elem is None):
        raise MissingElementError('bibliographyLink')
    ref_doi = elem.get('doi', None)
    ref_key = elem.get('preferredKey', None)
    if (ref_doi is not None):
        try:
            ref = crossref_api.works(ids=ref_doi)['message']
        except (HTTPError, habanero.RequestError, ConnectionError):
            if (ref_key is None):
                raise KeywordError('DOI not found and preferredKey attribute not set')
            else:
                warn('Missing doi attribute in bibliographyLink or lookup failed. Setting "detail" key as a fallback; please update to the appropriate fields.')
                reference['detail'] = ref_key
                if (reference['detail'][(- 1)] != '.'):
                    reference['detail'] += '.'
        else:
            if (ref_key is not None):
                warn('Using DOI to obtain reference information, rather than preferredKey.')
            reference['doi'] = elem.attrib['doi']
            reference['journal'] = ref.get('container-title')[0]
            ref_year = (ref.get('published-print') or ref.get('published-online'))
            reference['year'] = int(ref_year['date-parts'][0][0])
            reference['volume'] = int(ref.get('volume'))
            reference['pages'] = ref.get('page')
            reference['authors'] = []
            for author in ref['author']:
                auth = {}
                auth['name'] = ' '.join([author['given'], author['family']])
                orcid = author.get('ORCID')
                if orcid:
                    auth['ORCID'] = orcid.lstrip('http:
                reference['authors'].append(auth)
    elif (ref_key is not None):
        warn('Missing doi attribute in bibliographyLink. Setting "detail" key as a fallback; please update to the appropriate fields.')
        reference['detail'] = ref_key
        if (reference['detail'][(- 1)] != '.'):
            reference['detail'] += '.'
    else:
        raise MissingAttributeError('preferredKey', 'bibliographyLink')
    return reference

Read reference info from root of ReSpecTh XML file.

Args:
root (`~xml.etree.ElementTree.Element`): Root of ReSpecTh XML file

Returns:
properties (`dict`): Dictionary with reference information


def path_fraction_point(points, fraction):

    seg_id, offset = path_fraction_id_offset(points, fraction, relative_offset=True)
    return linear_interpolate(points[seg_id], points[seg_id + 1], offset)

Computes the point which corresponds to the fraction
of the path length along the piecewise linear curve which
is constructed from the set of points.

Args:
points: an iterable of indexable objects with indices
0, 1, 2 correspoding to 3D cartesian coordinates
fraction: path length fraction (0 <= fraction <= 1)

Returns:
The 3D coordinates of the aforementioned point


def tail(self, n):

        if n < 0:
            n = max(0, len(self.index) + n)
        if self._is_transposed:
            result = self.__constructor__(
                self.data.transpose().take(1, -n).transpose(),
                self.index[-n:],
                self.columns,
                self._dtype_cache,
            )
            result._is_transposed = True
        else:
            result = self.__constructor__(
                self.data.take(0, -n), self.index[-n:], self.columns, self._dtype_cache
            )
        return result

Returns the last n rows.

Args:
n: Integer containing the number of rows to return.

Returns:
DataManager containing the last n rows of the original DataManager.


def _GetNumberOfDaysInCentury(self, year):
    if (year < 0):
        raise ValueError('Year value out of bounds.')
    (year, _) = divmod(year, 100)
    if self._IsLeapYear(year):
        return 36525
    return 36524

Retrieves the number of days in a century.

Args:
year (int): year in the century e.g. 1970.

Returns:
int: number of (remaining) days in the century.

Raises:
ValueError: if the year value is out of bounds.


def GetDataDownloader(self, version=sorted(_SERVICE_MAP.keys())[(- 1)], server=None):
    if (not server):
        server = DEFAULT_ENDPOINT
    return DataDownloader(self, version, server)

Creates a downloader for Ad Manager reports and PQL result sets.

This is a convenience method. It is functionally identical to calling
DataDownloader(ad_manager_client, version, server)

Args:
[optional]
version: A string identifying the Ad Manager version to connect to.
This defaults to what is currently the latest version. This will be
updated in future releases to point to what is then the
latest version.
server: A string identifying the webserver hosting the Ad Manager API.

Returns:
A DataDownloader tied to this AdManagerClient, ready to download reports.


def getmtime(self, path):
    try:
        file_obj = self.filesystem.resolve(path)
        return file_obj.st_mtime
    except IOError:
        self.filesystem.raise_os_error(errno.ENOENT, winerror=3)

Returns the modification time of the fake file.

Args:
path: the path to fake file.

Returns:
(int, float) the modification time of the fake file
in number of seconds since the epoch.

Raises:
OSError: if the file does not exist.


def parse_peddy_ped_check(lines):

    ped_check = []
    header = []
    for i,line in enumerate(lines):
        line = line.rstrip()
        if i == 0:

            header = line.lstrip('
        else:
            pair_info = dict(zip(header, line.split(',')))

            pair_info['hets_a'] = convert_number(pair_info['hets_a'])

            pair_info['hets_b'] = convert_number(pair_info['hets_b'])

            pair_info['ibs0'] = convert_number(pair_info['ibs0'])

            pair_info['ibs2'] = convert_number(pair_info['ibs2'])

            pair_info['n'] = convert_number(pair_info['n'])

            pair_info['rel'] = convert_number(pair_info['rel'])

            pair_info['pedigree_relatedness'] = convert_number(pair_info['pedigree_relatedness'])

            pair_info['rel_difference'] = convert_number(pair_info['rel_difference'])

            pair_info['shared_hets'] = convert_number(pair_info['shared_hets'])

            pair_info['pedigree_parents'] = make_bool(pair_info.get('pedigree_parents'))

            pair_info['predicted_parents'] = make_bool(pair_info.get('predicted_parents'))

            pair_info['parent_error'] = make_bool(pair_info.get('parent_error'))

            pair_info['sample_duplication_error'] = make_bool(pair_info.get('sample_duplication_error'))

            ped_check.append(pair_info)

    return ped_check

Parse a .ped_check.csv file

Args:
lines(iterable(str))

Returns:
ped_check(list(dict))


def _decorate_run_options_for_profile(self, run_options):
    run_options.trace_level = config_pb2.RunOptions.FULL_TRACE

Modify a RunOptions object for profiling TensorFlow graph execution.

Args:
run_options: (RunOptions) the modified RunOptions object.


def page(self, title=None, pageid=None, auto_suggest=True, redirect=True, preload=False):
    if (((title is None) or (title.strip() == '')) and (pageid is None)):
        raise ValueError('Either a title or a pageid must be specified')
    elif title:
        if auto_suggest:
            temp_title = self.suggest(title)
            if (temp_title is None):
                raise PageError(title=title)
            else:
                title = temp_title
        return MediaWikiPage(self, title, redirect=redirect, preload=preload)
    else:
        return MediaWikiPage(self, pageid=pageid, preload=preload)

Get MediaWiki page based on the provided title or pageid

Args:
title (str): Page title
pageid (int): MediaWiki page identifier
auto-suggest (bool): **True:** Allow page title auto-suggest
redirect (bool): **True:** Follow page redirects
preload (bool): **True:** Load most page properties
Raises:
ValueError: when title is blank or None and no pageid is \
provided
Raises:
:py:func:`mediawiki.exceptions.PageError`: if page does \
not exist
Note:
Title takes precedence over pageid if both are provided


def _calculate_page_index(index, data):
    if (index > data['total_results']):
        raise ValueError('index not in paged data')
    page_length = len(data['results'])
    return (((index

Determine the location of a given index in paged data.

Arguments:
index (:py:class:`int`): The overall index.
data: (:py:class:`dict`) The first page of data.

Returns:
:py:class:`tuple`: The location of that index, in the format
``(page, index_in_page)``.


def MemberVisible(component, name, member, class_attrs=None, verbose=False):
    if isinstance(name, str) and name.startswith('__'):
        return False
    if verbose:
        return True
    if member is absolute_import or member is division or member is print_function:
        return False
    if isinstance(member, type(absolute_import)):
        return False
    modules_to_hide = []
    if inspect.ismodule(member) and member in modules_to_hide:
        return False
    if inspect.isclass(component):
        if class_attrs is None:
            class_attrs = inspectutils.GetClassAttrsDict(component) or {}
        class_attr = class_attrs.get(name)
        if class_attr:
            if class_attr.kind in ('method', 'property'):
                return False
            tuplegetter = getattr(collections, '_tuplegetter', type(None))
            if isinstance(class_attr.object, tuplegetter):
                return False
    if isinstance(name, str):
        return not name.startswith('_')
    return True

Returns whether a member should be included in auto-completion or help.

Determines whether a member of an object with the specified name should be
included in auto-completion or help text(both usage and detailed help).

If the member name starts with '__', it will always be excluded. If it
starts with only one '_', it will be included for all non-string types. If
verbose is True, the members, including the private members, are included.

When not in verbose mode, some modules and functions are excluded as well.

Args:
component: The component containing the member.
name: The name of the member.
member: The member itself.
class_attrs: (optional) If component is a class, provide this as:
inspectutils.GetClassAttrsDict(component). If not provided, it will be
computed.
verbose: Whether to include private members.
Returns
A boolean value indicating whether the member should be included.


def get_formal_type_parameter(self, t: str) -> 'BaseValue':
    del t
    return self.ctx.convert.unsolvable

Get the class's type for the type parameter.

Treating self as a class_mixin.Class, gets its formal type for the given
type parameter. For the real implementation, see
ParameterizedClass.get_formal_type_parameter.

Args:
t: The name of the type parameter.

Returns:
A formal type.


def _is_txn_to_replay(self, txn_id, possible_successor, already_seen):

        is_successor = self._is_predecessor_of_possible_successor(
            txn_id,
            possible_successor)
        in_different_batch = not self._is_in_same_batch(txn_id,
                                                        possible_successor)
        has_not_been_seen = possible_successor not in already_seen

        return is_successor and in_different_batch and has_not_been_seen

Decide if possible_successor should be replayed.

Args:
txn_id (str): Id of txn in failed batch.
possible_successor (str): Id of txn to possibly replay.
already_seen (list): A list of possible_successors that have
been replayed.

Returns:
(bool): If the possible_successor should be replayed.


def _runExperimentImpl(options, model=None):

  json_helpers.validate(options.privateOptions,
                        schemaDict=g_parsedPrivateCommandLineOptionsSchema)

  experimentDir = options.experimentDir
  descriptionPyModule = helpers.loadExperimentDescriptionScriptFromDir(
      experimentDir)
  expIface = helpers.getExperimentDescriptionInterfaceFromModule(
      descriptionPyModule)

  if options.privateOptions['listAvailableCheckpoints']:
    _printAvailableCheckpoints(experimentDir)
    return None

  experimentTasks = expIface.getModelControl().get('tasks', [])

  if (len(experimentTasks) == 0 and
      expIface.getModelControl()['environment'] == OpfEnvironment.Nupic):
    expIface.convertNupicEnvToOPF()
    experimentTasks = expIface.getModelControl().get('tasks', [])

  expIface.normalizeStreamSources()

  newSerialization = options.privateOptions['newSerialization']

  if options.privateOptions['listTasks']:
    print "Available tasks:"

    for label in [t['taskLabel'] for t in experimentTasks]:
      print "\t", label

    return None

  if options.privateOptions['runCheckpointName']:

    assert model is None

    checkpointName = options.privateOptions['runCheckpointName']

    model = ModelFactory.loadFromCheckpoint(
          savedModelDir=_getModelCheckpointDir(experimentDir, checkpointName),
          newSerialization=newSerialization)

  elif model is not None:
    print "Skipping creation of OPFExperiment instance: caller provided his own"
  else:
    modelDescription = expIface.getModelDescription()
    model = ModelFactory.create(modelDescription)

  if options.privateOptions['createCheckpointName']:
    checkpointName = options.privateOptions['createCheckpointName']
    _saveModel(model=model,
               experimentDir=experimentDir,
               checkpointLabel=checkpointName,
               newSerialization=newSerialization)

    return model

  taskIndexList = range(len(experimentTasks))

  customTaskExecutionLabelsList = options.privateOptions['taskLabels']
  if customTaskExecutionLabelsList:
    taskLabelsList = [t['taskLabel'] for t in experimentTasks]
    taskLabelsSet = set(taskLabelsList)

    customTaskExecutionLabelsSet = set(customTaskExecutionLabelsList)

    assert customTaskExecutionLabelsSet.issubset(taskLabelsSet), \
           ("Some custom-provided task execution labels don't correspond "
            "to actual task labels: mismatched labels: %r; actual task "
            "labels: %r.") % (customTaskExecutionLabelsSet - taskLabelsSet,
                              customTaskExecutionLabelsList)

    taskIndexList = [taskLabelsList.index(label) for label in
                     customTaskExecutionLabelsList]

    print "
                                                   i in taskIndexList]

  for taskIndex in taskIndexList:

    task = experimentTasks[taskIndex]

    taskRunner = _TaskRunner(model=model,
                             task=task,
                             cmdOptions=options)
    taskRunner.run()
    del taskRunner

    if options.privateOptions['checkpointModel']:
      _saveModel(model=model,
                 experimentDir=experimentDir,
                 checkpointLabel=task['taskLabel'],
                 newSerialization=newSerialization)

  return model

Creates and runs the experiment

Args:
options: namedtuple ParseCommandLineOptionsResult
model: For testing: may pass in an existing OPF Model instance
to use instead of creating a new one.

Returns: reference to OPFExperiment instance that was constructed (this
is provided to aid with debugging) or None, if none was
created.


def exhaustive_curie_check(self, ontology: pd.DataFrame, curie_predicate: str, curie_prefix: str, diff: bool=True) -> Tuple[list]:
    (inside, outside) = ([], [])
    curie_prefix = curie_prefix.replace(':', '')
    header = (['Index'] + list(ontology.columns))
    for row in ontology.itertuples():
        row = {header[i]: val for (i, val) in enumerate(row)}
        entity_curie = row[curie_predicate]
        if isinstance(entity_curie, list):
            if (len(entity_curie) != 0):
                exit('Need to have only 1 iri in the cell from the onotology.')
            else:
                entity_curie = entity_curie[0]
        entity_curie = ((curie_prefix + ':') + self.extract_fragment(entity_curie))
        ilx_row = self.curie2row.get(entity_curie)
        if ilx_row:
            inside.append({'external_ontology_row': row, 'ilx_rows': [ilx_row]})
        else:
            outside.append(row)
    if diff:
        diff = self.__exhaustive_diff(inside)
        return (inside, outside, diff)
    return (inside, outside)

All entities with conflicting curies gets a full diff to see if they belong

Args:
ontology: pandas DataFrame created from an ontology where the colnames are predicates
and if classes exist it is also thrown into a the colnames.
curie_predicate: usually in qname form and is the colname of the DataFrame
curie_prefix: Not all cells in the DataFrame will have complete curies so we extract
the fragement from the cell and use the prefix to complete it.
diff: complete exhaustive diff if between curie matches... will take FOREVER if there are a lot -> n^2
Returns:
inside: entities that are inside of InterLex
outside: entities NOT in InterLex
diff (optional): List[List[dict]]... so complicated but usefull diff between matches only


def _controller_buffer(self, port):

        address = _LIB.Controller(self._env, port)

        buffer_ = ctypes.cast(address, ctypes.POINTER(CONTROLLER_VECTOR)).contents

        return np.frombuffer(buffer_, dtype='uint8')

Find the pointer to a controller and setup a NumPy buffer.

Args:
port: the port of the controller to setup

Returns:
a NumPy buffer with the controller's binary data


def _compile_arithmetic_expression(self, expr: Expression, scope: Dict[(str, TensorFluent)], batch_size: Optional[int]=None, noise: Optional[List[tf.Tensor]]=None) -> TensorFluent:
    etype = expr.etype
    args = expr.args
    if (len(args) == 1):
        etype2op = {'+': (lambda x: x), '-': (lambda x: (- x))}
        if (etype[1] not in etype2op):
            raise ValueError('Invalid binary arithmetic expression:\n{}'.format(expr))
        op = etype2op[etype[1]]
        x = self._compile_expression(args[0], scope, batch_size, noise)
        fluent = op(x)
    else:
        etype2op = {'+': (lambda x, y: (x + y)), '-': (lambda x, y: (x - y)), '*': (lambda x, y: (x * y)), '/': (lambda x, y: (x / y))}
        if (etype[1] not in etype2op):
            raise ValueError('Invalid binary arithmetic expression:\n{}'.format(expr))
        op = etype2op[etype[1]]
        x = self._compile_expression(args[0], scope, batch_size, noise)
        y = self._compile_expression(args[1], scope, batch_size, noise)
        fluent = op(x, y)
    return fluent

Compile an arithmetic expression `expr` into a TensorFluent
in the given `scope` with optional batch size.

Args:
expr (:obj:`rddl2tf.expr.Expression`): A RDDL arithmetic expression.
scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope.
batch_size (Optional[size]): The batch size.

Returns:
:obj:`rddl2tf.fluent.TensorFluent`: The compiled expression as a TensorFluent.


def slice_hidden(self, x):
    x_sliced = tf.reshape(x, shape=[(- 1), self.hparams.num_blocks, self.hparams.block_dim])
    return x_sliced

Slice encoder hidden state into block_dim.

Args:
x: Encoder hidden state of shape [-1, hidden_size].

Returns:
Sliced states of shape [-1, num_blocks, block_dim].


def floor(x):
    if any_symbolic_tensors((x,)):
        return Floor().symbolic_call(x)
    return backend.numpy.floor(x)

Return the floor of the input, element-wise.

The floor of the scalar `x` is the largest integer `i`, such that `i <= x`.

Args:
x: Input tensor.

Returns:
Output tensor, element-wise floor of `x`.


def get(cls, issue_id):
    res = Issue.get(issue_id, IssueType.get(cls.issue_type).issue_type_id)
    return (cls(res) if res else None)

Returns the class object identified by `issue_id`

Args:
issue_id (str): Unique EC2 Instance ID to load from database

Returns:
EC2 Instance object if found, else None


def _ParseCachedEntryVista(self, value_data, cached_entry_offset):

    try:
      cached_entry = self._ReadStructureFromByteStream(
          value_data[cached_entry_offset:], cached_entry_offset,
          self._cached_entry_data_type_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.ParseError(
          'Unable to parse cached entry value with error: {0!s}'.format(
              exception))

    path_size = cached_entry.path_size
    maximum_path_size = cached_entry.maximum_path_size
    path_offset = cached_entry.path_offset

    if path_offset > 0 and path_size > 0:
      path_size += path_offset
      maximum_path_size += path_offset

      try:
        path = value_data[path_offset:path_size].decode('utf-16-le')
      except UnicodeDecodeError:
        raise errors.ParseError('Unable to decode cached entry path to string')

    cached_entry_object = AppCompatCacheCachedEntry()
    cached_entry_object.cached_entry_size = (
        self._cached_entry_data_type_map.GetByteSize())
    cached_entry_object.insertion_flags = cached_entry.insertion_flags
    cached_entry_object.last_modification_time = (
        cached_entry.last_modification_time)
    cached_entry_object.path = path
    cached_entry_object.shim_flags = cached_entry.shim_flags

    return cached_entry_object

Parses a Windows Vista cached entry.

Args:
value_data (bytes): value data.
cached_entry_offset (int): offset of the first cached entry data
relative to the start of the value data.

Returns:
AppCompatCacheCachedEntry: cached entry.

Raises:
ParseError: if the value data could not be parsed.


def get(cls, session, team_id):

        return cls(
            '/teams/%d.json' % team_id,
            singleton=True,
            session=session,
        )

Return a specific team.

Args:
session (requests.sessions.Session): Authenticated session.
team_id (int): The ID of the team to get.

Returns:
helpscout.models.Person: A person singleton representing the team,
if existing. Otherwise ``None``.


def List(self, request, global_params=None):
    config = self.GetMethodConfig('List')
    return self._RunMethod(config, request, global_params=global_params)

Lists all jobs that you started in the specified project. Job information is available for a six month period after creation. The job list is sorted in reverse chronological order, by job creation time. Requires the Can View project role, or the Is Owner project role if you set the allUsers property.

Args:
request: (BigqueryJobsListRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(JobList) The response message.


def preprocess(source):
    doc = html5lib.parseFragment(source)
    source = ET.tostring(doc, encoding='utf-8', method='text').decode('utf-8')
    source = source.replace(u'\n', u'').strip()
    source = re.sub('\\s\\s+', u' ', source)
    return source

Removes unnecessary break lines and white spaces.

Args:
source (str): Input sentence.

Returns:
Preprocessed sentence. (str)


def _parse_flowcontrol_send(self, config):

        value = 'off'
        match = re.search(r'flowcontrol send (\w+)$', config, re.M)
        if match:
            value = match.group(1)
        return dict(flowcontrol_send=value)

Scans the config block and returns the flowcontrol send value

Args:
config (str): The interface config block to scan

Returns:
dict: Returns a dict object with the flowcontrol send value
retrieved from the config block.  The returned dict object
is intended to be merged into the interface resource dict


def time_zones_for_number(numobj):

    ntype = number_type(numobj)
    if ntype == PhoneNumberType.UNKNOWN:
        return _UNKNOWN_TIME_ZONE_LIST
    elif not is_number_type_geographical(ntype, numobj.country_code):
        return _country_level_time_zones_for_number(numobj)
    return time_zones_for_geographical_number(numobj)

As time_zones_for_geographical_number() but explicitly checks the
validity of the number passed in.

Arguments:
numobj -- a valid phone number for which we want to get the time zones to which it belongs
Returns a list of the corresponding time zones or a single element list with the default
unknown time zone if no other time zone was found or if the number was invalid


def build_chain(self, source, chain):
    for group in WalkByGroup(source, (chain.order + 1)):
        pre = group[:(- 1)]
        res = group[(- 1)]
        if (pre not in chain.content):
            chain.content[pre] = {res: 1}
        elif (res not in chain.content[pre]):
            chain.content[pre][res] = 1
        else:
            chain.content[pre][res] += 1
    chain.decache()

Build markov chain from source on top of existin chain

Args:
source: iterable which will be used to build chain
chain: MarkovChain in currently loaded shelve file that
will be extended by source


def _GetEntries(self, paths, max_entries, iterator_from_file, is_sequence=False):
    entries = {}
    index = 0
    for filepath in paths:
        reader = iterator_from_file(filepath)
        for record in reader:
            if is_sequence:
                sequence_example = tf.train.SequenceExample.FromString(record)
                self._ParseExample(sequence_example.context.feature, sequence_example.feature_lists.feature_list, entries, index)
            else:
                self._ParseExample(tf.train.Example.FromString(record).features.feature, [], entries, index)
            index += 1
            if (index == max_entries):
                return (entries, index)
    return (entries, index)

Extracts examples into a dictionary of feature values.

Args:
paths: A list of the paths to the files to parse.
max_entries: The maximum number of examples to load.
iterator_from_file: A method that takes a file path string and returns an
iterator to the examples in that file.
is_sequence: True if the input data from 'iterator_from_file' are
tf.SequenceExamples, False if tf.Examples. Defaults to false.

Returns:
A tuple with two elements:
- A dictionary of all features parsed thus far and arrays of their
values.
- The number of examples parsed.


def SetDecodedStreamSize(self, decoded_stream_size):
    if self._is_open:
        raise IOError('Already open.')
    if (decoded_stream_size < 0):
        raise ValueError('Invalid decoded stream size: {0:d} value out of bounds.'.format(decoded_stream_size))
    self._decoded_stream_size = decoded_stream_size

Sets the decoded stream size.

This function is used to set the decoded stream size if it can be
determined separately.

Args:
decoded_stream_size (int): size of the decoded stream in bytes.

Raises:
IOError: if the file-like object is already open.
OSError: if the file-like object is already open.
ValueError: if the decoded stream size is invalid.


def _might_have_parameter(fn_or_cls, arg_name):

  if inspect.isclass(fn_or_cls):
    fn = _find_class_construction_fn(fn_or_cls)
  else:
    fn = fn_or_cls

  while hasattr(fn, '__wrapped__'):
    fn = fn.__wrapped__
  arg_spec = _get_cached_arg_spec(fn)
  if six.PY3:
    if arg_spec.varkw:
      return True
    return arg_name in arg_spec.args or arg_name in arg_spec.kwonlyargs
  else:
    if arg_spec.keywords:
      return True
    return arg_name in arg_spec.args

Returns True if `arg_name` might be a valid parameter for `fn_or_cls`.

Specifically, this means that `fn_or_cls` either has a parameter named
`arg_name`, or has a `**kwargs` parameter.

Args:
fn_or_cls: The function or class to check.
arg_name: The name fo the parameter.

Returns:
Whether `arg_name` might be a valid argument of `fn`.


def get_sv_variants(self, chromosome=None, end_chromosome=None, sv_type=None,
                        pos=None, end=None):

        query = {}

        if chromosome:
            query['chrom'] = chromosome
        if end_chromosome:
            query['end_chrom'] = end_chromosome
        if sv_type:
            query['sv_type'] = sv_type
        if pos:
            if not '$and' in query:
                query['$and'] = []
            query['$and'].append({'pos_left': {'$lte': pos}})
            query['$and'].append({'pos_right': {'$gte': pos}})

        if end:
            if not '$and' in query:
                query['$and'] = []
            query['$and'].append({'end_left': {'$lte': end}})
            query['$and'].append({'end_right': {'$gte': end}})

        LOG.info("Find all sv variants {}".format(query))

        return self.db.structural_variant.find(query).sort([('chrom', ASCENDING), ('pos_left', ASCENDING)])

Return all structural variants in the database

Args:
chromosome (str)
end_chromosome (str)
sv_type (str)
pos (int): Left position of SV
end (int): Right position of SV

Returns:
variants (Iterable(Variant))


class IntLayerNorm(nn.Module):

    def __init__(self, normalized_shape, eps, output_bit=8, quant_mode=False, force_dequant='none'):
        super().__init__()
        self.normalized_shape = normalized_shape
        self.eps = eps
        self.weight = nn.Parameter(torch.zeros(normalized_shape))
        self.bias = nn.Parameter(torch.zeros(normalized_shape))
        self.quant_mode = quant_mode
        if force_dequant in ['nonlinear', 'layernorm']:
            logger.info('Force dequantize layernorm')
            self.quant_mode = False
        self.register_buffer('shift', torch.zeros(1))
        self.output_bit = output_bit
        self.max_bit = 32
        self.dim_sqrt = None
        self.activation = QuantAct(self.output_bit, quant_mode=self.quant_mode)

    def set_shift(self, y_int):
        with torch.no_grad():
            y_sq_int = y_int ** 2
            var_int = torch.sum(y_sq_int, axis=2, keepdim=True)
            shift = torch.log2(torch.sqrt(var_int / 2 ** self.max_bit)).ceil().max()
            shift_old = self.shift
            self.shift = torch.max(self.shift, shift)
            logger.info(f'Dynamic shift adjustment: {int(shift_old)} -> {int(self.shift)}')

    def overflow_fallback(self, y_int):

        self.set_shift(y_int)
        y_int_shifted = floor_ste.apply(y_int / 2 ** self.shift)
        y_sq_int = y_int_shifted ** 2
        var_int = torch.sum(y_sq_int, axis=2, keepdim=True)
        return var_int

    def forward(self, x, scaling_factor=None):
        if not self.quant_mode:
            mean = x.mean(axis=2, keepdim=True)
            y = x - mean
            var = torch.mean(y ** 2, axis=2, keepdim=True)
            x = y / torch.sqrt(self.eps + var)
            x = x * self.weight + self.bias
            return (x, None)
        if self.dim_sqrt is None:
            n = torch.tensor(x.shape[2], dtype=torch.float)
            self.dim_sqrt = torch.sqrt(n).to(x.device)
        x_int = x / scaling_factor
        mean_int = round_ste.apply(x_int.mean(axis=2, keepdim=True))
        y_int = x_int - mean_int
        y_int_shifted = floor_ste.apply(y_int / 2 ** self.shift)
        y_sq_int = y_int_shifted ** 2
        var_int = torch.sum(y_sq_int, axis=2, keepdim=True)
        if self.training:
            if var_int.max() >= 2 ** self.max_bit:
                var_int = self.overflow_fallback(y_int)
                assert var_int.max() < 2 ** self.max_bit + 0.1, 'Error detected in overflow handling: `var_int` exceeds `self.max_bit` (the maximum possible bit width)'
        std_int = floor_ste.apply(torch.sqrt(var_int)) * 2 ** self.shift
        factor = floor_ste.apply(2 ** 31 / std_int)
        y_int = floor_ste.apply(y_int * factor / 2)
        scaling_factor = self.dim_sqrt / 2 ** 30
        bias = self.bias.data.detach() / self.weight.data.detach()
        bias_int = floor_ste.apply(bias / scaling_factor)
        y_int = y_int + bias_int
        scaling_factor = scaling_factor * self.weight
        x = y_int * scaling_factor
        return (x, scaling_factor)

Quantized version of `torch.nn.LayerNorm`. Adds quantization-specific arguments on top of `torch.nn.LayerNorm`.

Args:
output_bit (`int`, *optional*, defaults to `8`):
Bitwidth for the layer output activation.
quant_mode (`bool`, *optional*, defaults to `False`):
Whether or not the layer is quantized.
force_dequant (`str`, *optional*, defaults to `"none"`):
Force dequantize the layer if either "layernorm" or "nonlinear" is given.


def add_graph(self, run_key, device_name, graph_def, debug=False):
    graph_dict = (self._run_key_to_debug_graphs if debug else self._run_key_to_original_graphs)
    if (not (run_key in graph_dict)):
        graph_dict[run_key] = dict()
    graph_dict[run_key][tf.compat.as_str(device_name)] = debug_graphs_helper.DebugGraphWrapper(graph_def)

Add a GraphDef.

Args:
run_key: A key for the run, containing information about the feeds,
fetches, and targets.
device_name: The name of the device that the `GraphDef` is for.
graph_def: An instance of the `GraphDef` proto.
debug: Whether `graph_def` consists of the debug ops.


def _determine_best_metric(self, metrics, trial):
    is_new_best_metric = False
    if self.args.metric_for_best_model is not None:
        metric_to_check = self.args.metric_for_best_model
        if not metric_to_check.startswith('eval_'):
            metric_to_check = f'eval_{metric_to_check}'
        try:
            metric_value = metrics[metric_to_check]
        except KeyError as exc:
            raise KeyError(f"The `metric_for_best_model` training argument is set to '{metric_to_check}', which is not found in the evaluation metrics. The available evaluation metrics are: {list(metrics.keys())}. Consider changing the `metric_for_best_model` via the TrainingArguments.") from exc
        operator = np.greater if self.args.greater_is_better else np.less
        if self.state.best_metric is None:
            self.state.best_metric = float('-inf') if self.args.greater_is_better else float('inf')
        if operator(metric_value, self.state.best_metric):
            self.state.best_metric = metric_value
            if self.args.save_strategy in [SaveStrategy.STEPS, SaveStrategy.EPOCH]:
                self.state.best_global_step = self.state.global_step
            is_new_best_metric = True
    return is_new_best_metric

Determine if the model should be saved based on the evaluation metrics.

Returns:
bool: True if a new best metric was found, else False