def get_version_details(self, version_name):

    name = ('%s/versions/%s' % (self._full_model_name, version_name))
    return self._api.projects().models().versions().get(name=name).execute()

Get details of a version.

Args:
version: the name of the version in short form, such as "v1".
Returns: a dictionary containing the version details.


def create_temp(node, namer):

  if isinstance(node, gast.Name):
    name = node.id
  elif isinstance(node, (gast.Attribute, gast.Subscript)):
    name = node.value.id
  else:
    raise TypeError
  temp_node = gast.Name(id=namer.temp(name), annotation=None, ctx=None)
  anno.setanno(temp_node, 'temp_var', node)
  return temp_node

Create a temporary variable.

Args:
node: Create a temporary variable to store this variable in.
namer: A naming object that guarantees the names are unique.

Returns:
node: See `create_grad`. Returns a temporary variable, which is always a
simple variable annotated with `temp_var`.


def render_wrapper(self, region='us-east-1'):

        base = self.settings['pipeline']['base']

        if self.base:
            base = self.base

        email = self.settings['pipeline']['notifications']['email']
        slack = self.settings['pipeline']['notifications']['slack']
        deploy_type = self.settings['pipeline']['type']
        pipeline_id = self.compare_with_existing(region=region)

        data = {
            'app': {
                'appname': self.app_name,
                'group_name': self.group_name,
                'repo_name': self.repo_name,
                'base': base,
                'deploy_type': deploy_type,
                'environment': 'packaging',
                'region': region,
                'triggerjob': self.trigger_job,
                'run_as_user': DEFAULT_RUN_AS_USER,
                'email': email,
                'slack': slack,
                'pipeline': self.settings['pipeline']
            },
            'id': pipeline_id
        }

        self.log.debug('Wrapper app data:\n%s', pformat(data))

        wrapper = get_template(template_file='pipeline/pipeline_wrapper.json.j2', data=data, formats=self.generated)

        return json.loads(wrapper)

Generate the base Pipeline wrapper.

This renders the non-repeatable stages in a pipeline, like jenkins, baking, tagging and notifications.

Args:
region (str): AWS Region.

Returns:
dict: Rendered Pipeline wrapper.


def __init__(self, inputs, num_clusters, initial_clusters, distance_metric, random_seed, kmeans_plus_plus_num_retries, kmc2_chain_length, cluster_centers, cluster_centers_updated, cluster_centers_initialized):
    self._inputs = inputs
    self._num_clusters = num_clusters
    self._initial_clusters = initial_clusters
    self._distance_metric = distance_metric
    self._seed = random_seed
    self._kmeans_plus_plus_num_retries = kmeans_plus_plus_num_retries
    self._kmc2_chain_length = kmc2_chain_length
    self._cluster_centers = cluster_centers
    self._cluster_centers_updated = cluster_centers_updated
    self._cluster_centers_initialized = cluster_centers_initialized
    self._num_selected = array_ops.shape(self._cluster_centers)[0]
    self._num_remaining = self._num_clusters - self._num_selected
    self._num_data = math_ops.add_n([array_ops.shape(i)[0] for i in self._inputs])

Creates an op factory.

Args:
inputs: See KMeans constructor.
num_clusters: An integer Tensor providing the number of clusters.
initial_clusters: See KMeans constructor.
distance_metric: See KMeans constructor.
random_seed: See KMeans constructor.
kmeans_plus_plus_num_retries: See KMeans constructor.
kmc2_chain_length: See KMeans constructor.
cluster_centers: The TF variable holding the initial centers. It may
already contain some centers when the op is executed.
cluster_centers_updated: A second TF variable to hold a copy of the
initial centers, used for full-batch mode. In mini-batch mode,
cluster_centers_updated is the same variable as cluster_centers.
cluster_centers_initialized: A boolean TF variable that will be set to
true when all the initial centers have been chosen.


def formula_balance(model):
    compound_formula = {}
    for compound in model.compounds:
        if (compound.formula is not None):
            try:
                f = Formula.parse(compound.formula).flattened()
                compound_formula[compound.id] = f
            except ParseError as e:
                msg = 'Error parsing formula for compound {}:\n{}\n{}'.format(compound.id, e, compound.formula)
                if (e.indicator is not None):
                    msg += '\n{}'.format(e.indicator)
                logger.warning(msg)
    for reaction in model.reactions:
        (yield (reaction, reaction_formula(reaction.equation, compound_formula)))

Calculate formula compositions for each reaction.

Call :func:`reaction_formula` for each reaction.
Yield (reaction, result) pairs, where result has two formula compositions
or `None`.

Args:
model: :class:`psamm.datasource.native.NativeModel`.


def sample_forecast_max_hail(self, dist_model_name, condition_model_name, num_samples, condition_threshold=0.5, query=None):
    if (query is not None):
        dist_forecasts = self.matched_forecasts['dist'][dist_model_name].query(query)
        dist_forecasts = dist_forecasts.reset_index(drop=True)
        condition_forecasts = self.matched_forecasts['condition'][condition_model_name].query(query)
        condition_forecasts = condition_forecasts.reset_index(drop=True)
    else:
        dist_forecasts = self.matched_forecasts['dist'][dist_model_name]
        condition_forecasts = self.matched_forecasts['condition'][condition_model_name]
    max_hail_samples = np.zeros((dist_forecasts.shape[0], num_samples))
    areas = dist_forecasts['Area'].values
    for f in np.arange(dist_forecasts.shape[0]):
        condition_prob = condition_forecasts.loc[(f, self.forecast_bins['condition'][0])]
        if (condition_prob >= condition_threshold):
            max_hail_samples[f] = np.sort(gamma.rvs(*dist_forecasts.loc[(f, self.forecast_bins['dist'])].values, size=(num_samples, areas[f])).max(axis=1))
    return max_hail_samples

Samples every forecast hail object and returns an empirical distribution of possible maximum hail sizes.

Hail sizes are sampled from each predicted gamma distribution. The total number of samples equals
num_samples * area of the hail object. To get the maximum hail size for each realization, the maximum
value within each area sample is used.

Args:
dist_model_name: Name of the distribution machine learning model being evaluated
condition_model_name: Name of the hail/no-hail model being evaluated
num_samples: Number of maximum hail samples to draw
condition_threshold: Threshold for drawing hail samples
query: A str that selects a subset of the data for evaluation

Returns:
A numpy array containing maximum hail samples for each forecast object.


def __init__(self, http_error):

    error_details = None
    error_response = None
    if http_error.fp:
      try:
        error_response = http_error.fp.read()
        error_body = json.loads(error_response)
        error_details = ['%s: %s' % (detail['message'], detail['debug_info'])
                         for detail in error_body['error']['errors']]
      except (ValueError, TypeError, KeyError):
        pass
    if error_details:
      error_details_str = ', '.join(error_details)
      error_message = ('HTTP %s (%s) error when communicating with URL: %s.  '
                       'Details: %s' % (http_error.code, http_error.reason,
                                        http_error.filename, error_details_str))
    else:
      error_message = ('HTTP %s (%s) error when communicating with URL: %s. '
                       'Response: %s' % (http_error.code, http_error.reason,
                                         http_error.filename,
                                         error_response))
    super(ServerRequestException, self).__init__(error_message)

Create a ServerRequestException from a given urllib2.HTTPError.

Args:
http_error: The HTTPError that the ServerRequestException will be
based on.


def generate_block_graph(block_graph: blocks.BlockGraph, loader: jinja2.BaseLoader) -> str:
    return _generate_visualization(template_file=_BLOCKGRAPH_TEMPLATE_NAME, loader=loader, graph_data=block_serializer.encode_merged_graph(block_graph))

Generate the visualization webpage.

Args:
block_graph: blocks.BlockGraph. The block graph of the code.
loader: A jinja22 loader

Returns:
str. The rendered visualization page.


def setPadding(self, padding):

        self._pad = padding
        self._zfill = self.__class__.getPaddingNum(self._pad)

Set new padding characters for the sequence.
i.e. "#" or "@@@" or '%04d', or an empty string to disable range formatting.

Args:
padding (str): sequence padding to set


def squad_v1_exact_match(y_true: List[List[str]], y_predicted: List[str]) -> float:

    EM_total = 0
    count = 0
    for ground_truth, prediction in zip(y_true, y_predicted):
        if len(ground_truth[0]) == 0:

            continue
        count += 1
        EMs = [int(normalize_answer(gt) == normalize_answer(prediction)) for gt in ground_truth]
        EM_total += max(EMs)
    return 100 * EM_total / count if count > 0 else 0

Calculates Exact Match score between y_true and y_predicted
EM score uses the best matching y_true answer:
if y_pred equal at least to one answer in y_true then EM = 1, else EM = 0
Skips examples without an answer.
Args:
y_true: list of correct answers (correct answers are represented by list of strings)
y_predicted: list of predicted answers
Returns:
exact match score : float


def _RemoveAuthorizedKeys(self, user):

    pw_entry = self._GetUser(user)
    if not pw_entry:
      return

    home_dir = pw_entry.pw_dir
    authorized_keys_file = os.path.join(home_dir, '.ssh', 'authorized_keys')
    if os.path.exists(authorized_keys_file):
      try:
        os.remove(authorized_keys_file)
      except OSError as e:
        message = 'Could not remove authorized keys for user %s. %s.'
        self.logger.warning(message, user, str(e))

Remove a Linux user account's authorized keys file to prevent login.

Args:
user: string, the Linux user account to remove access.


async def disconnect(self, conn_id):

        self._ensure_connection(conn_id, True)

        dev = self._get_property(conn_id, 'device')
        dev.connected = False

        self._teardown_connection(conn_id)

Asynchronously disconnect from a connected device

Args:
conn_id (int): A unique identifier that will refer to this connection
callback (callback): A callback that will be called as
callback(conn_id, adapter_id, success, failure_reason)


def __init__(self, vlan_id=None):

        super().__init__(action_type=ActionType.OFPAT_SET_VLAN_VID, length=8)
        self.vlan_id = vlan_id

Create an ActionVlanVid with the optional parameters below.

Args:
vlan_id (int): VLAN priority.


def transform_feature(self, transformation_cache, state_manager):
    input_tensor = transformation_cache.get(self.key, state_manager)
    if self.normalizer_fn is not None:
        input_tensor = self.normalizer_fn(input_tensor)
    return input_tensor

See `FeatureColumn` base class.

In this case, we apply the `normalizer_fn` to the input tensor.

Args:
transformation_cache: A `FeatureTransformationCache` object to access
features.
state_manager: A `StateManager` to create / access resources such as
lookup tables.

Returns:
Normalized input tensor.


def create_authors(project_dir=os.curdir):
    pkg_info_file = os.path.join(project_dir, 'PKG-INFO')
    authors_file = os.path.join(project_dir, 'AUTHORS')
    if os.path.exists(pkg_info_file):
        return
    authors = get_authors(project_dir=project_dir)
    with open(authors_file, 'wb') as authors_fd:
        authors_fd.write((b'\n'.join((a.encode('utf-8') for a in authors)) + b'\n'))

Creates the authors file, if not in a package.

Returns:
None

Raises:
RuntimeError: If the authors could not be retrieved


async def get_records_for_zone(self, dns_zone, params=None):

        managed_zone = self.get_managed_zone(dns_zone)
        url = f'{self._base_url}/managedZones/{managed_zone}/rrsets'

        if not params:
            params = {}

        if 'fields' not in params:

            params['fields'] = ('rrsets/name,rrsets/kind,rrsets/rrdatas,'
                                'rrsets/type,rrsets/ttl,nextPageToken')
        next_page_token = None

        records = []
        while True:
            if next_page_token:
                params['pageToken'] = next_page_token
            response = await self.get_json(url, params=params)
            records.extend(response['rrsets'])
            next_page_token = response.get('nextPageToken')
            if not next_page_token:
                break

        logging.info(f'Found {len(records)} rrsets for zone "{dns_zone}".')
        return records

Get all resource record sets for a managed zone, using the DNS zone.

Args:
dns_zone (str): Desired DNS zone to query.
params (dict): (optional) Additional query parameters for HTTP
requests to the GDNS API.
Returns:
list of dicts representing rrsets.


class TFDebertaXSoftmax(keras.layers.Layer):

    def __init__(self, axis=-1, **kwargs):
        super().__init__(**kwargs)
        self.axis = axis

    def call(self, inputs: tf.Tensor, mask: tf.Tensor):
        rmask = tf.logical_not(tf.cast(mask, tf.bool))
        output = tf.where(rmask, tf.cast(float('-inf'), dtype=self.compute_dtype), inputs)
        output = stable_softmax(tf.cast(output, dtype=tf.float32), self.axis)
        output = tf.where(rmask, 0.0, output)
        return output

Masked Softmax which is optimized for saving memory

Args:
input (`tf.Tensor`): The input tensor that will apply softmax.
mask (`tf.Tensor`): The mask matrix where 0 indicate that element will be ignored in the softmax calculation.
dim (int): The dimension that will apply softmax


def AddValue(self, registry_value):
    name = registry_value.name.upper()
    if (name in self._values):
        raise KeyError('Value: {0:s} already exists.'.format(registry_value.name))
    self._values[name] = registry_value

Adds a value.

Args:
registry_value (WinRegistryValue): Windows Registry value.

Raises:
KeyError: if the value already exists.


def add_profile_variants(self, profile_variants):
    results = self.db.profile_variant.insert_many(profile_variants)
    return results

Add several variants to the profile_variant collection in the
database

Args:

profile_variants(list(models.ProfileVariant))


def valueReadPreprocessor(valueString, replaceParamsFile=None):
    if (type(valueString) is bool):
        log.warning('Only numerical variable types can be handled by the valueReadPreprocessor function.')
        return valueString
    processedValue = valueString
    if ((replaceParamsFile is not None) and (valueString is not None)):
        if (('[' in valueString) or (']' in valueString)):
            processedValue = '{0}'.format(REPLACE_NO_VALUE)
            for targetParam in replaceParamsFile.targetParameters:
                if (targetParam.targetVariable == valueString):
                    processedValue = '{0}'.format(((- 1) * targetParam.id))
                    break
    return processedValue

Apply global pre-processing to values during reading throughout the project.

Args:
valueString (str): String representing the value to be preprocessed.
replaceParamsFile (gsshapy.orm.ReplaceParamFile, optional): Instance of the replace param file. Required if
replacement variables are included in the project.

Returns:
str: Processed value as a string


def index_min(x, idx, y):
    return _index_update_helper(tf_np.ndarray._with_index_min, x, idx, y)

Pure equivalent of `x[idx] = minimum(x[idx], y)`.

Returns the value of x that would result from the NumPy-style indexed
assignment `x[idx] = minimum(x[idx], y)`. Because it's a pure function, `x`
itself won't be changed.

Args:
x: an array with the values to be updated.
idx: a Numpy-style index, consisting of `None`, integers, slice objects,
ellipses, ndarrays with integer dtypes, or a tuple of the above.
y: the array of updates. `y` must be broadcastable to the shape of the array
that would be returned by `x[idx]`.

Returns:
The updated version of `x`.


def queuify_logger(logger, queue_handler, queue_listener):
    if isinstance(logger, str):
        logger = logging.getLogger(logger)
    handlers = [handler for handler in logger.handlers if (handler not in queue_listener.handlers)]
    if handlers:
        queue_listener.handlers = tuple((list(queue_listener.handlers) + handlers))
    del logger.handlers[:]
    logger.addHandler(queue_handler)

Replace logger's handlers with a queue handler while adding existing
handlers to a queue listener.

This is useful when you want to use a default logging config but then
optionally add a logger's handlers to a queue during runtime.

Args:
logger (mixed): Logger instance or string name of logger to queue-ify
handlers.
queue_handler (QueueHandler): Instance of a ``QueueHandler``.
queue_listener (QueueListener): Instance of a ``QueueListener``.


def process_user_info_response(self, response):
    mapping = (('username', 'preferred_username'), ('email', 'email'), ('last_name', 'family_name'), ('first_name', 'given_name'))
    return {dest: response[source] for (dest, source) in mapping}

Process the user info response data.

By default, this simply maps the edX user info key-values (example below) to Django-friendly names. If your
provider returns different fields, you should sub-class this class and override this method.

.. code-block:: python

{
"username": "jdoe",
"email": "jdoe@example.com",
"first_name": "Jane",
"last_name": "Doe"
}

Arguments:
response (dict): User info data

Returns:
dict


def yaml(modules_to_register: Iterable[Any] = None, classes_to_register: Iterable[Any] = None) -> ruamel.yaml.YAML:

    yaml = ruamel.yaml.YAML(typ = "rt")

    yaml.representer.add_representer(np.ndarray, numpy_to_yaml)
    yaml.constructor.add_constructor("!numpy_array", numpy_from_yaml)

    yaml = register_module_classes(yaml = yaml, modules = modules_to_register)
    yaml = register_classes(yaml = yaml, classes = classes_to_register)

    return yaml

Create a YAML object for loading a YAML configuration.

Args:
modules_to_register: Modules containing classes to be registered with the YAML object. Default: None.
classes_to_register: Classes to be registered with the YAML object. Default: None.
Returns:
A newly creating YAML object, configured as apporpirate.


def _compute_transitions(self, corpus, order=1):

        self.transitions = defaultdict(lambda: defaultdict(int))

        for corpus_entry in corpus:
            tokens = self.tokenize(corpus_entry)

            last_tokens = utils.prefilled_buffer(
                self._start_symbol, length=self.order)

            for token_value in chain(tokens, self._end_symbol):
                for suffix in utils.get_suffixes(last_tokens):
                    self.transitions[suffix][token_value] += 1

                last_tokens.append(token_value)

        self._compute_relative_probs(self.transitions)

Computes the transition probabilities of a corpus
Args:
corpus: the given corpus (a corpus_entry needs to be iterable)
order: the maximal Markov chain order


def eval_image(image, height, width, scope=None):
    with tf.name_scope(values=[image, height, width], name=scope, default_name='eval_image'):
        image = tf.image.central_crop(image, central_fraction=0.875)
        image = tf.expand_dims(image, 0)
        image = tf.image.resize_bilinear(image, [height, width], align_corners=False)
        image = tf.squeeze(image, [0])
        return image

Prepare one image for evaluation.

Args:
image: 3-D float Tensor
height: integer
width: integer
scope: Optional scope for name_scope.
Returns:
3-D float Tensor of prepared image.


def check_upload_status(self, video_id):
    if (not self.authenticated):
        raise ApiError(_('Authentication is required'))
    entry = self.fetch_video(video_id)
    upload_status = Api.yt_service.CheckUploadStatus(entry)
    if (upload_status is not None):
        video_upload_state = upload_status[0]
        detailed_message = upload_status[1]
        return {'upload_state': video_upload_state, 'detailed_message': detailed_message}
    else:
        return True

Checks the video upload status
Newly uploaded videos may be in the processing state

Authentication is required

Returns:
True if video is available
otherwise a dict containes upload_state and detailed message
i.e. {"upload_state": "processing", "detailed_message": ""}


def check_par(chrom, pos):

    par = False

    for interval in PAR.get(chrom,[]):
        if (pos >= interval[0] and pos <= interval[1]):
            par = True

    return par

Check if a coordinate is in the PAR region

Args:
chrom(str)
pos(int)

Returns:
par(bool)


async def _on_event(self, event_):

        conv_id = event_.conversation_id.id
        try:
            conv = await self._get_or_fetch_conversation(conv_id)
        except exceptions.NetworkError:
            logger.warning(
                'Failed to fetch conversation for event notification: %s',
                conv_id
            )
        else:
            self._sync_timestamp = parsers.from_timestamp(event_.timestamp)
            conv_event = conv.add_event(event_)

            if conv_event is not None:
                await self.on_event.fire(conv_event)
                await conv.on_event.fire(conv_event)

Receive a hangouts_pb2.Event and fan out to Conversations.

Args:
event_: hangouts_pb2.Event instance


def _multiple_field(cls):
    klassdict = cls.__dict__
    try:
        return klassdict['_entitylist_multifield'][0]
    except (KeyError, IndexError, TypeError):
        from . import fields
        multifield_tuple = tuple(fields.find(cls, multiple=True))
        assert (len(multifield_tuple) == 1)
        multifield = multifield_tuple[0]
        assert issubclass(multifield.type_, Entity)
        cls._entitylist_multifield = multifield_tuple
        return multifield_tuple[0]

Return the "multiple" TypedField associated with this EntityList.

This also lazily sets the ``_entitylist_multiplefield`` value if it
hasn't been set yet. This is set to a tuple containing one item because
if we set the class attribute to the TypedField, we would effectively
add a TypedField descriptor to the class, which we don't want.

Raises:
AssertionError: If there is more than one multiple TypedField
or the the TypedField type_ is not a subclass of Entity.


def invert_attention_mask(self, encoder_attention_mask: Tensor) -> Tensor:
    if encoder_attention_mask.dim() == 3:
        encoder_extended_attention_mask = encoder_attention_mask[:, None, :, :]
    if encoder_attention_mask.dim() == 2:
        encoder_extended_attention_mask = encoder_attention_mask[:, None, None, :]
    encoder_extended_attention_mask = encoder_extended_attention_mask.to(dtype=self.dtype)
    encoder_extended_attention_mask = (1.0 - encoder_extended_attention_mask) * torch.finfo(self.dtype).min
    return encoder_extended_attention_mask

Invert an attention mask (e.g., switches 0. and 1.).

Args:
encoder_attention_mask (`torch.Tensor`): An attention mask.

Returns:
`torch.Tensor`: The inverted attention mask.


def _getScalesDiag(self, termx=0):
    assert (self.P > 1), 'VarianceDecomposition:: diagonal init_method allowed only for multi trait models'
    assert (self.noisPos is not None), 'VarianceDecomposition:: noise term has to be set'
    assert (termx < (self.n_randEffs - 1)), 'VarianceDecomposition:: termx>=n_randEffs-1'
    assert (self.trait_covar_type[self.noisPos] not in ['lowrank', 'block', 'fixed']), 'VarianceDecomposition:: diagonal initializaiton not posible for such a parametrization'
    assert (self.trait_covar_type[termx] not in ['lowrank', 'block', 'fixed']), 'VarianceDecimposition:: diagonal initializaiton not posible for such a parametrization'
    scales = []
    res = self._getH2singleTrait(self.vd.getTerm(termx).getK())
    scaleg = sp.sqrt(res['varg'].mean())
    scalen = sp.sqrt(res['varn'].mean())
    for term_i in range(self.n_randEffs):
        if (term_i == termx):
            _scales = (scaleg * self.diag[term_i])
        elif (term_i == self.noisPos):
            _scales = (scalen * self.diag[term_i])
        else:
            _scales = (0.0 * self.diag[term_i])
        if (self.jitter[term_i] > 0):
            _scales = sp.concatenate((_scales, sp.array([sp.sqrt(self.jitter[term_i])])))
        scales.append(_scales)
    return sp.concatenate(scales)

Internal function for parameter initialization
Uses 2 term single trait model to get covar params for initialization

Args:
termx:      non-noise term terms that is used for initialization


def __init__(self, device_name, node_exec_stats, file_path, line_number, func_name, op_type):
    self.device_name = device_name
    self.node_exec_stats = node_exec_stats
    self.file_path = file_path
    self.line_number = line_number
    self.func_name = func_name
    if self.file_path:
        self.file_line_func = '%s:%d(%s)' % (os.path.basename(self.file_path), self.line_number, self.func_name)
    else:
        self.file_line_func = ''
    self.op_type = op_type
    self.start_time = self.node_exec_stats.all_start_micros
    self.op_time = self.node_exec_stats.op_end_rel_micros - self.node_exec_stats.op_start_rel_micros

Constructor.

Args:
device_name: (string) name of the device.
node_exec_stats: `NodeExecStats` proto.
file_path: path to the source file involved in creating the op.
line_number: line number in the file involved in creating the op.
func_name: name of the function that the line belongs to.
op_type: (string) Operation type.


def deepnn(x):

    with tf.name_scope("reshape"):
        x_image = tf.reshape(x, [-1, 28, 28, 1])

    with tf.name_scope("conv1"):
        W_conv1 = weight_variable([5, 5, 1, 32])
        b_conv1 = bias_variable([32])
        h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)

    with tf.name_scope("pool1"):
        h_pool1 = max_pool_2x2(h_conv1)

    with tf.name_scope("conv2"):
        W_conv2 = weight_variable([5, 5, 32, 64])
        b_conv2 = bias_variable([64])
        h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2)

    with tf.name_scope("pool2"):
        h_pool2 = max_pool_2x2(h_conv2)

    with tf.name_scope("fc1"):
        W_fc1 = weight_variable([7 * 7 * 64, 1024])
        b_fc1 = bias_variable([1024])

        h_pool2_flat = tf.reshape(h_pool2, [-1, 7 * 7 * 64])
        h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)

    with tf.name_scope("dropout"):
        keep_prob = tf.placeholder(tf.float32)
        h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)

    with tf.name_scope("fc2"):
        W_fc2 = weight_variable([1024, 10])
        b_fc2 = bias_variable([10])

        y_conv = tf.matmul(h_fc1_drop, W_fc2) + b_fc2
    return y_conv, keep_prob

deepnn builds the graph for a deep net for classifying digits.

Args:
x: an input tensor with the dimensions (N_examples, 784), where 784 is
the number of pixels in a standard MNIST image.

Returns:
A tuple (y, keep_prob). y is a tensor of shape (N_examples, 10), with
values equal to the logits of classifying the digit into one of 10
classes (the digits 0-9). keep_prob is a scalar placeholder for the
probability of dropout.


def set_default(self, name, value):

    fl = self._flags()
    if name not in fl:
      self._set_unknown_flag(name, value)
      return
    fl[name]._set_default(value)
    self._assert_validators(fl[name].validators)

Changes the default value of the named flag object.

The flag's current value is also updated if the flag is currently using
the default value, i.e. not specified in the command line, and not set
by FLAGS.name = value.

Args:
name: str, the name of the flag to modify.
value: The new default value.

Raises:
UnrecognizedFlagError: Raised when there is no registered flag named name.
IllegalFlagValueError: Raised when value is not valid.


def copy(self) -> 'TraceableStack[T]':
    return TraceableStack(self._stack)

Return a copy of self referencing the same objects but in a new list.

This method is implemented to support thread-local stacks.

Returns:
TraceableStack with a new list that holds existing objects.


def analyze(model_path=None, model_content=None, gpu_compatibility=False, **kwargs):
    if not model_path and (not model_content):
        raise ValueError('neither `model_path` nor `model_content` is provided')
    if model_path:
        print(f'=== {model_path} ===\n')
        tflite_model = model_path
        input_is_filepath = True
    else:
        print('=== TFLite ModelAnalyzer ===\n')
        tflite_model = model_content
        input_is_filepath = False
    if kwargs.get('experimental_use_mlir', False):
        print(wrap_converter.wrapped_flat_buffer_file_to_mlir(tflite_model, input_is_filepath))
    else:
        print(_analyzer_wrapper.ModelAnalyzer(tflite_model, input_is_filepath, gpu_compatibility))

Analyzes the given tflite_model with dumping model structure.

This tool provides a way to understand users' TFLite flatbuffer model by
dumping internal graph structure. It also provides additional features
like checking GPU delegate compatibility.

WARNING: Experimental interface, subject to change.
The output format is not guaranteed to stay stable, so don't
write scripts to this.

Args:
model_path: TFLite flatbuffer model path.
model_content: TFLite flatbuffer model object.
gpu_compatibility: Whether to check GPU delegate compatibility.
**kwargs: Experimental keyword arguments to analyze API.

Returns:
Print analyzed report via console output.


def flush_all(self, delay=0, noreply=None):
    if (noreply is None):
        noreply = self.default_noreply
    cmd = (b'flush_all ' + six.text_type(delay).encode('ascii'))
    if noreply:
        cmd += b' noreply'
    cmd += b'\r\n'
    results = self._misc_cmd([cmd], b'flush_all', noreply)
    if noreply:
        return True
    return (results[0] == b'OK')

The memcached "flush_all" command.

Args:
delay: optional int, the number of seconds to wait before flushing,
or zero to flush immediately (the default).
noreply: optional bool, True to not wait for the reply (defaults to
self.default_noreply).

Returns:
True.


def _location_infos_equal(left, right):
    if ((not isinstance(left, LocationInfo)) or (not isinstance(right, LocationInfo))):
        raise AssertionError(u'Unsupported LocationInfo comparison between types {} and {} with values {}, {}'.format(type(left), type(right), left, right))
    optional_scopes_depth_equal = (left.optional_scopes_depth == right.optional_scopes_depth)
    parent_query_paths_equal = (((left.parent_location is None) and (right.parent_location is None)) or (left.parent_location.query_path == right.parent_location.query_path))
    recursive_scopes_depths_equal = (left.recursive_scopes_depth == right.recursive_scopes_depth)
    types_equal = (left.type == right.type)
    return all([optional_scopes_depth_equal, parent_query_paths_equal, recursive_scopes_depths_equal, types_equal])

Return True if LocationInfo objects are equivalent for the SQL backend, False otherwise.

LocationInfo objects are considered equal for the SQL backend iff the optional scopes depth,
recursive scopes depth, types and parent query paths are equal.

Args:
left: LocationInfo, left location info object to compare.
right: LocationInfo, right location info object to compare.

Returns:
bool, True if LocationInfo objects equivalent, False otherwise.


def get_tag(self, tag_name, **kwargs):
    return self._get_object_by_name(self._TAG_ENDPOINT_SUFFIX, tag_name, **kwargs)

get a tag by name

Args:
tag_name (string): name of tag to get

Returns:
dictionary of the response


def get(cls, ns, key):

        return getattr(db, cls.__name__).find_one(
            ConfigItem.namespace_prefix == ns,
            ConfigItem.key == key
        )

Fetch an item by namespace and key

Args:
ns (str): Namespace prefix
key (str): Item key

Returns:
:obj:`Configitem`: Returns config item object if found, else `None`


def _check_wires_list(self, wires, node):
    if (len(set(wires)) != len(wires)):
        raise DAGCircuitError('duplicate wires')
    wire_tot = (len(node.qargs) + len(node.cargs))
    if (node.condition is not None):
        wire_tot += node.condition[0].size
    if (len(wires) != wire_tot):
        raise DAGCircuitError(('expected %d wires, got %d' % (wire_tot, len(wires))))

Check that a list of wires is compatible with a node to be replaced.

- no duplicate names
- correct length for operation
Raise an exception otherwise.

Args:
wires (list[register, index]): gives an order for (qu)bits
in the input circuit that is replacing the node.
node (DAGNode): a node in the dag

Raises:
DAGCircuitError: if check doesn't pass.


def move(self, delta):
    self.pos = ((self.pos[0] + delta[0]), (self.pos[1] + delta[1]))

Move the node.

Args:
delta (tupel): A tupel, holding the adjustment of the position.


def forward(self, hidden_states: torch.Tensor, padding_mask: Optional[torch.LongTensor]=None) -> Tuple:
    self.input_dtype = hidden_states.dtype
    batch_size, sequence_length, hidden_dim = hidden_states.shape
    hidden_states = hidden_states.reshape(batch_size * sequence_length, hidden_dim)
    hidden_states = hidden_states.to(self.dtype)
    self._cast_classifier()
    router_logits = self.classifier(hidden_states)
    top_1_mask, router_probs = self.route_tokens(router_logits, self.input_dtype, padding_mask)
    return (top_1_mask, router_probs)

The hidden states are reshaped to simplify the computation of the router probabilities (combining weights for
each experts.)

Args:
hidden_states (`torch.Tensor`):
(batch_size, sequence_length, hidden_dim) from which router probabilities are computed.
Returns:
top_1_mask (`torch.Tensor` of shape (batch_size, sequence_length)):
Index tensor of shape [batch_size, sequence_length] corresponding to the expert selected for each token
using the top1 probabilities of the router.
router_probabilities (`torch.Tensor` of shape (batch_size, sequence_length, nump_experts)):
Tensor of shape (batch_size, sequence_length, num_experts) corresponding to the probabilities for each
token and expert. Used for routing tokens to experts.
router_logits (`torch.Tensor` of shape (batch_size, sequence_length))):
Logits tensor of shape (batch_size, sequence_length, num_experts) corresponding to raw router logits.
This is used later for computing router z-loss.


def DeserializeFromBufer(buffer, offset=0):
    mstream = StreamManager.GetStream(buffer)
    reader = BinaryReader(mstream)
    tx = Transaction.DeserializeFrom(reader)
    StreamManager.ReleaseStream(mstream)
    return tx

Deserialize object instance from the specified buffer.

Args:
buffer (bytes, bytearray, BytesIO): (Optional) data to create the stream from.
offset: UNUSED

Returns:
Transaction:


def _validate_query(query):

    query = deepcopy(query)

    if query["q"] == BLANK_QUERY["q"]:
        raise ValueError("No query specified.")

    query["q"] = _clean_query_string(query["q"])

    if query["limit"] is None:
        query["limit"] = SEARCH_LIMIT if query["advanced"] else NONADVANCED_LIMIT

    elif query["limit"] > SEARCH_LIMIT:
        warnings.warn('Reduced result limit from {} to the Search maximum: {}'
                      .format(query["limit"], SEARCH_LIMIT), RuntimeWarning)
        query["limit"] = SEARCH_LIMIT

    for key, val in BLANK_QUERY.items():

        if query.get(key, float('nan')) == val:
            query.pop(key)

    to_remove = [field for field in query.keys() if field not in BLANK_QUERY.keys()]
    [query.pop(field) for field in to_remove]

    return query

Validate and clean up a query to be sent to Search.
Cleans the query string, removes unneeded parameters, and validates for correctness.
Does not modify the original argument.
Raises an Exception on invalid input.

Arguments:
query (dict): The query to validate.

Returns:
dict: The validated query.


def OpenFileEntry(cls, path_spec_object, resolver_context=None):

    file_system = cls.OpenFileSystem(
        path_spec_object, resolver_context=resolver_context)

    if resolver_context is None:
      resolver_context = cls._resolver_context

    file_entry = file_system.GetFileEntryByPathSpec(path_spec_object)

    resolver_context.ReleaseFileSystem(file_system)

    return file_entry

Opens a file entry object defined by path specification.

Args:
path_spec_object (PathSpec): path specification.
resolver_context (Optional[Context]): resolver context, where None
represents the built in context which is not multi process safe.

Returns:
FileEntry: file entry or None if the path specification could not be
resolved.


def pie(self, key="wall_time", minfract=0.05, ax=None, **kwargs):

        ax, fig, plt = get_ax_fig_plt(ax=ax)

        ax.axis("equal")

        labels, vals = self.names_and_values(key, minfract=minfract)
        ax.pie(vals, explode=None, labels=labels, autopct='%1.1f%%', shadow=True)
        return fig

Plot pie chart for this timer.

Args:
key: Keyword used to extract data from the timer.
minfract: Don't show sections whose relative weight is less that minfract.
ax: matplotlib :class:`Axes` or None if a new figure should be created.

Returns:
`matplotlib` figure


def read_handle(url, cache=None, mode='rb'):
    scheme = urlparse(url).scheme
    if (cache == 'purge'):
        _purge_cached(url)
        cache = None
    if (_is_remote(scheme) and (cache is None)):
        cache = True
        log.debug('Cache not specified, enabling because resource is remote.')
    if cache:
        handle = _read_and_cache(url, mode=mode)
    elif (scheme in ('http', 'https')):
        handle = _handle_web_url(url, mode=mode)
    elif (scheme in 'gs'):
        handle = _handle_gfile(url, mode=mode)
    else:
        handle = open(url, mode=mode)
    (yield handle)
    handle.close()

Read from any URL with a file handle.

Use this to get a handle to a file rather than eagerly load the data:

```
with read_handle(url) as handle:
result = something.load(handle)

result.do_something()

```

When program execution leaves this `with` block, the handle will be closed
automatically.

Args:
url: a URL including scheme or a local path
Returns:
A file handle to the specified resource if it could be reached.
The handle will be closed automatically once execution leaves this context.


def delete_interconnect(self, enclosure_uri, bay, timeout=(- 1)):
    uri = '{path}?location=Enclosure:{enclosure_uri},Bay:{bay}'.format(path=self.LOCATIONS_PATH, enclosure_uri=enclosure_uri, bay=bay)
    return self._helper.delete(uri, timeout=timeout)

Deletes an interconnect from a location.

Warning:
This won't delete the LOGICAL INTERCONNECT itself and might cause inconsistency between the enclosure
and Logical Interconnect Group.

Args:
enclosure_uri: URI of the Enclosure
bay: Bay
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:
bool: Indicating if the interconnect was successfully deleted.


def get_subgraph_for_concept_pairs(
        self, concepts: List[str], cutoff: Optional[int] = None
    ):

        path_generator = (
            nx.all_simple_paths(self, source, target, cutoff=cutoff)
            for source, target in permutations(concepts, 2)
        )
        paths = chain.from_iterable(path_generator)
        return AnalysisGraph(self.subgraph(set(chain.from_iterable(paths))))

Get subgraph comprised of simple paths between the source and the
target.

Args:
concepts
cutoff


def get_hist(self, observable: Any, **kwargs: Dict[(str, Any)]) -> Any:
    return observable

Get the histogram that may be stored in some object.

This histogram is used to project from.

Note:
The output object could just be the raw ROOT histogram.

Note:
This function is just a basic placeholder and likely should be overridden.

Args:
observable (object): The input object. It could be a histogram or something more complex
kwargs: Additional arguments passed to the projection function
Return:
ROOT.TH1 or ROOT.THnBase histogram which should be projected. By default, it returns the
observable (input object).


def slice_begin(self, tensor_shape, pnum):
    tensor_layout = self.tensor_layout(tensor_shape)
    coordinates = pnum_to_processor_coordinates(self.shape, pnum)
    ret = []
    for (dim_size, mesh_axis) in zip(tensor_shape.to_integer_list, tensor_layout.tensor_axis_to_mesh_axis):
        if (mesh_axis is None):
            ret.append(0)
        else:
            ret.append(((dim_size
    return ret

Begin position for the tensor slice for the given processor.

Args:
tensor_shape: Shape.
pnum: int <= self.size.

Returns:
list of integers with length tensor_shape.ndims.


def __init__(self, channel):

    self.Converse = channel.stream_stream(
        '/google.assistant.embedded.v1alpha1.EmbeddedAssistant/Converse',
        request_serializer=google_dot_assistant_dot_embedded_dot_v1alpha1_dot_embedded__assistant__pb2.ConverseRequest.SerializeToString,
        response_deserializer=google_dot_assistant_dot_embedded_dot_v1alpha1_dot_embedded__assistant__pb2.ConverseResponse.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def isexe(*components):
    _path = path(*components)
    return (isfile(_path) and os.access(_path, os.X_OK))

Return whether a path is an executable file.

Arguments:

path (str): Path of the file to check.

Examples:

>>> fs.isexe("/bin/ls")
True

>>> fs.isexe("/home")
False

>>> fs.isexe("/not/a/real/path")
False

Returns:

bool: True if file is executable, else false.


def log_jwt_dict_info(log, msg_str, jwt_dict):
    d = ts_to_str(jwt_dict)
    log_list = ([(b, d.pop(a)) for (a, b, c) in CLAIM_LIST if (a in d)] + [(k, d[k]) for k in sorted(d)])
    list(map(log, (['{}:'.format(msg_str)] + ['  {}: {}'.format(k, v) for (k, v) in log_list])))

Dump JWT to log.

Args:
log: Logger
Logger to which to write the message.

msg_str: str
A message to write to the log before the JWT values.

jwt_dict: dict
JWT containing values to log.

Returns:
None


def format_delta(__timedelta: datetime.timedelta) -> str:
    if (__timedelta == datetime.timedelta(0)):
        return ''
    days_s = ('{}D'.format(__timedelta.days) if __timedelta.days else '')
    (hours, minutes) = divmod(__timedelta.seconds, 3600)
    (minutes, seconds) = divmod(minutes, 60)
    hours_s = ('{:02d}H'.format(hours) if hours else '')
    minutes_s = ('{:02d}M'.format(minutes) if minutes else '')
    seconds_s = ('{:02d}S'.format(seconds) if seconds else '')
    return 'P{}{}{}{}{}'.format(days_s, ('T' if (hours or minutes or seconds) else ''), hours_s, minutes_s, seconds_s)

Format ISO-8601 duration string.

Args:
__timedelta: Duration to process
Returns:
ISO-8601 representation of duration


def _Write(self, data, output_file):
    _, extension = os.path.splitext(output_file)
    with TemporaryDirectoryResource() as tempdir:
        if extension == '.json':
            json.dump(data, open(output_file, 'w'), sort_keys=True, indent=2)
        elif extension in ['.tflite', '.bin']:
            input_json = os.path.join(tempdir, 'temp.json')
            with open(input_json, 'w') as fp:
                json.dump(data, fp, sort_keys=True, indent=2)
            returncode = subprocess.call([self._flatc_path, '-b', '--defaults-json', '--strict-json', '-o', tempdir, self._new_schema, input_json])
            if returncode != 0:
                raise RuntimeError('flatc failed to convert upgraded json to binary.')
            shutil.copy(os.path.join(tempdir, 'temp.tflite'), output_file)
        else:
            raise ValueError('Invalid extension on output file %r' % output_file)

Output a json or bin version of the flatbuffer model.

Args:
data: Dict representing the TensorFlow Lite model to write.
output_file: filename to write the converted flatbuffer to. (json,
tflite, or bin extension is required).
Raises:
ValueError: When the extension is not json or bin
RuntimeError: When flatc fails to convert json data to binary.


A "back-in" tween function that overshoots both the start and destination.

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 closure(self, rules):

        closure = set()

        todo = set(rules)
        while todo:
            rule = todo.pop()
            closure.add(rule)

            if rule.at_end:
                continue

            symbol = rule.rhs[rule.pos]
            for production in self.nonterminals[symbol]:
                for first in self.first(rule.rest):
                    if EPSILON in production.rhs:

                        new_rule = DottedRule(production, 1, first)
                    else:
                        new_rule = DottedRule(production, 0, first)

                    if new_rule not in closure:
                        todo.add(new_rule)

        return frozenset(closure)

Fills out the entire closure based on some initial dotted rules.

Args:
rules - an iterable of DottedRules

Returns: frozenset of DottedRules


def aggregate(self, index):

        if isinstance(index, string_types):
            col_df_grouped = self.col_df.groupby(self.df[index])
        else:
            self.col_df.index = pd.MultiIndex.from_arrays([self.df[i] for i in index])
            col_df_grouped = self.col_df.groupby(level=index)
            self.col_df.index = self.df.index

        self.reduced_df = pd.DataFrame({
            colred: col_df_grouped[colred.column].agg(colred.agg_func)
            for colred in self.column_reductions
            })

        reduced_dfs = []
        for cf in self.column_functions:

            reduced_dfs.append(cf.apply_and_name(self))

        return pd.concat(reduced_dfs, axis=1)

Performs a groupby of the unique Columns by index, as constructed from self.df.

Args:
index (str, or pd.Index): Index or column name of self.df.

Returns:
pd.DataFrame: A dataframe, aggregated by index, that contains the result
of the various ColumnFunctions, and named accordingly.


def __tomo_linear_inv(freqs, ops, weights=None, trace=None):

    if weights is not None:
        W = np.array(weights)
        if W.ndim == 1:
            W = np.diag(W)

    S = np.array([vectorize(m).conj()
                  for m in ops]).reshape(len(ops), ops[0].size)
    if weights is not None:
        S = np.dot(W, S)

    v = np.array(freqs)
    if weights is not None:
        v = np.dot(W, freqs)
    Sdg = S.T.conj()
    inv = np.linalg.pinv(np.dot(Sdg, S))

    ret = devectorize(np.dot(inv, np.dot(Sdg, v)))

    if trace is not None:
        ret = trace * ret / np.trace(ret)
    return ret

Reconstruct a matrix through linear inversion.

Args:
freqs (list[float]): list of observed frequences.
ops (list[np.array]): list of corresponding projectors.
weights (list[float] or array_like):
weights to be used for weighted fitting.
trace (float or None): trace of returned operator.

Returns:
numpy.array: A numpy array of the reconstructed operator.


def stage(self, startimage, newimage):

        client = utils.get_client()
        cprint('  Copying file from "%s:/%s" \n                 to "%s:
               % (self.sourceimage, self.sourcepath, startimage, self.destpath),
               'blue')

        cachedir = self._setcache(client)
        cacherelpath = os.path.relpath(cachedir, TMPDIR)

        if os.path.exists(cachedir) and not os.path.exists(os.path.join(cachedir, 'content.tar')):
            shutil.rmtree(cachedir)

        if not os.path.exists(cachedir):
            print(' * Creating cache at %s' % cacherelpath)
            container = client.containers.create(self.sourceimage)
            try:
                tarfile_stream, tarfile_stats = container.get_archive(self.sourcepath)
            except docker.errors.NotFound:
                raise errors.MissingFileError(
                        'Cannot copy file "%s" from image "%s" - it does not exist!' %
                        (self.sourcepath, self.sourceimage))

            tempdir = tempfile.mkdtemp(dir=BUILD_TEMPDIR)
            with open(os.path.join(tempdir, 'content.tar'), 'wb') as localfile:
                for chunk in tarfile_stream:
                    localfile.write(chunk)
            os.mkdir(cachedir)
            os.rename(tempdir, cachedir)
        else:
            print('  Using cached files from %s' % cacherelpath)

        dockerfile = 'FROM %s\nADD content.tar %s' % (startimage, self.destpath)
        with open(os.path.join(cachedir, 'Dockerfile'), 'w') as df:
            df.write(dockerfile)

        buildargs = dict(path=cachedir,
                         tag=newimage,
                         decode=True)
        utils.set_build_cachefrom(self.cache_from, buildargs, client)

        stream = client.api.build(**buildargs)
        try:
            utils.stream_docker_logs(stream, newimage)
        except ValueError as e:
            raise errors.BuildError(dockerfile, e.args[0], build_args=buildargs)

Copies the file from source to target

Args:
startimage (str): name of the image to stage these files into
newimage (str): name of the created image


def get_all_counters(obj, instance_list=None):

    counters, instances_avail = win32pdh.EnumObjectItems(None, None, obj, -1, 0)

    if instance_list is None:
        instance_list = instances_avail

    if not isinstance(instance_list, list):
        instance_list = [instance_list]

    counter_list = []
    for counter in counters:
        for instance in instance_list:
            instance = '*' if instance.lower() == '_total' else instance
            counter_list.append((obj, instance, counter))
        else:
            counter_list.append((obj, None, counter))

    return get_counters(counter_list) if counter_list else {}

Get the values for all counters available to a Counter object

Args:

obj (str):
The name of the counter object. You can get a list of valid names
using the ``list_objects`` function

instance_list (list):
A list of instances to return. Use this to narrow down the counters
that are returned.

.. note::
``_Total`` is returned as ``*``


def __init__(self, min_score=DEFAULT_MIN_SCORE,
                 user_attributes=DEFAULT_USER_ATTRIBUTES):

        if min_score < 1:
            min_score = 1
        elif min_score > 4:
            min_score = 4
        self.min_score = min_score
        self.user_attributes = user_attributes

Init method.

Args:
min_score (int): minimum score to accept (between 0 and 4).
user_attributes (tuple): list of user attributes to check.


def notch_filter(data: FLOATS_TYPE,
                 sampling_freq_hz: float,
                 notch_freq_hz: float,
                 quality_factor: float) -> FLOATS_TYPE:

    b, a = iirnotch(
        w0=normalized_frequency(notch_freq_hz, sampling_freq_hz),
        Q=quality_factor
    )
    filtered_data = lfilter(b=b, a=a, x=data)
    return filtered_data

Design and use a notch (band reject) filter to filter the data.

Args:
data: time series of the data
sampling_freq_hz: sampling frequency :math:`f_s`, in Hz
(or other consistent units)
notch_freq_hz: notch frequency, in Hz
(or other consistent units)
quality_factor: notch filter quality factor, :math:`Q`

Returns:
filtered data


def write(self, x, access_logits):
    gamma = tf.layers.dense(x, 1, activation=tf.sigmoid, name='gamma')
    write_logits = (access_logits - (gamma * tf.expand_dims(self.mean_logits, 1)))
    candidate_value = tf.layers.dense(x, self.val_depth, activation=tf.nn.relu, name='candidate_value')
    erase_gates = tf.layers.dense(x, self.memory_size, activation=tf.nn.sigmoid, name='erase')
    write_weights = tf.nn.softmax(write_logits)
    erase_weights = tf.expand_dims((1 - (erase_gates * write_weights)), 3)
    erase = tf.multiply(erase_weights, tf.expand_dims(self.mem_vals, 1))
    addition = tf.multiply(tf.expand_dims(write_weights, 3), tf.expand_dims(candidate_value, 2))
    update_value_op = self.mem_vals.assign(tf.reduce_mean((erase + addition), axis=1))
    with tf.control_dependencies([update_value_op]):
        write_op = self.mean_logits.assign(((self.mean_logits * 0.1) + tf.reduce_mean((write_logits * 0.9), axis=1)))
        return write_op

Write to the memory based on a combination of similarity and least used.

Based on arXiv:1607.00036v2 [cs.LG].

Args:
x: a tensor in the shape of [batch_size, length, depth].
access_logits: the logits for accessing the memory.
Returns:
the update op.


def dump_in_memory_result(self, result, output_path):
    file_count = 0
    logger.debug('Dumping in-memory processing results to output folder: %s', output_path)
    for (k, v) in iteritems(result):
        cur_output_path = os.path.join(output_path, k)
        if isinstance(v, dict):
            file_count += self.dump_in_memory_result(v, cur_output_path)
        else:
            if (not os.path.isdir(output_path)):
                os.makedirs(output_path)
            filename = os.path.join(output_path, k)
            logger.debug('Writing output file: %s', filename)
            with open(filename, 'wt', encoding=self.config.encoding) as f:
                f.write(v)
            file_count += 1
    return file_count

Recursively dumps the result of our processing into files within the
given output path.

Args:
result: The in-memory result of our processing.
output_path: Full path to the folder into which to dump the files.

Returns:
The number of files generated (integer).


def ContainsNone(self, *values):

    self._awql = self._CreateMultipleValuesCondition(values, 'CONTAINS_NONE')
    return self._query_builder

Sets the type of the WHERE clause as "contains none".

Args:
*values: The values to be used in the WHERE condition.

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


def depricated_name(newmethod):

    def decorator(func):

        @wraps(func)
        def wrapper(*args, **kwargs):
            warnings.simplefilter('always', DeprecationWarning)
            warnings.warn('Function {} is depricated, please use {} instead.'.format(func.__name__, newmethod), category=DeprecationWarning, stacklevel=2)
            warnings.simplefilter('default', DeprecationWarning)
            return func(*args, **kwargs)
        return wrapper
    return decorator

Decorator for warning user of depricated functions before use.

Args:
newmethod (str): Name of method to use instead.


def distance(self, other):

        return distance(self.lat, self.lon, None, other.lat, other.lon, None)

Distance between points

Args:
other (:obj:`Point`)
Returns:
float: Distance in km


def _get_enrollments_list_page(self, params=None):
    req_url = urljoin(self.base_url, self.enrollment_list_url)
    resp = self.requester.get(req_url, params=params)
    resp.raise_for_status()
    resp_json = resp.json()
    results = resp_json['results']
    next_url_str = resp_json.get('next')
    cursor = None
    qstr_cursor = None
    if next_url_str:
        next_url = urlparse(next_url_str)
        qstr = parse_qs(next_url.query)
        qstr_cursor = qstr.get('cursor')
    if (qstr_cursor and isinstance(qstr_cursor, list)):
        cursor = qstr_cursor[0]
    return (results, cursor)

Submit request to retrieve enrollments list.

Args:
params (dict): Query parameters to use in the request. Valid parameters are:
* course_id: Filters the result to course enrollments for the course
corresponding to the given course ID. The value must be URL encoded.
Optional.
* username: username: List of comma-separated usernames. Filters the result to the
course enrollments of the given users. Optional.


def map_creative_click_tag_feeds(self, creative_feed, click_tag_feed):
    for creative in creative_feed:
        creative['click_tags'] = [click_tag for click_tag in click_tag_feed if self._assignment_matches(creative, click_tag)]

Maps click tag feed to the corresponding creative.

Click Tag is a child object to the creative, and there is a 1 creative
to many click tags relationship. In Bulkdozer they are represented by
two separate tab in the feed, and this method maps the creatives to their
respective click tags based on the creative ID.

Args:
creative_feed: Creative feed.
click_tag_feed: Click tag feed.


def _get_fbeta_score(true_positives, selected, relevant, beta=1):
    precision = 1
    if (selected > 0):
        precision = (true_positives / selected)
    if (beta == 0):
        return precision
    recall = 1
    if (relevant > 0):
        recall = (true_positives / relevant)
    if ((precision > 0) and (recall > 0)):
        beta2 = (beta * beta)
        return ((((1 + beta2) * precision) * recall) / ((beta2 * precision) + recall))
    else:
        return 0

Compute Fbeta score.

Args:
true_positives: Number of true positive ngrams.
selected: Number of selected ngrams.
relevant: Number of relevant ngrams.
beta: 0 gives precision only, 1 gives F1 score, and Inf gives recall only.

Returns:
Fbeta score.


def GetCloudPath(self, resource_id, cache, database):
    cloud_path = cache.GetResults('cloud_path')
    if (not cloud_path):
        results = database.Query(self.CLOUD_PATH_CACHE_QUERY)
        cache.CacheQueryResults(results, 'cloud_path', 'resource_id', ('filename', 'parent'))
        cloud_path = cache.GetResults('cloud_path')
    if (resource_id == 'folder:root'):
        return '/'
    paths = []
    (parent_path, parent_id) = cloud_path.get(resource_id, ['', ''])
    while parent_path:
        if (parent_path == 'folder:root'):
            break
        paths.append(parent_path)
        (parent_path, parent_id) = cloud_path.get(parent_id, ['', ''])
    if (not paths):
        return '/'
    paths.reverse()
    return '/{0:s}/'.format('/'.join(paths))

Return cloud path given a resource id.

Args:
resource_id (str): resource identifier for the file.
cache (SQLiteCache): cache.
database (SQLiteDatabase): database.

Returns:
str: full path to the resource value.


def _convert_template_option(template):
    option = {}
    extraction_method = template.get('extraction_method')
    if (extraction_method == 'guess'):
        option['guess'] = True
    elif (extraction_method == 'lattice'):
        option['lattice'] = True
    elif (extraction_method == 'stream'):
        option['stream'] = True
    option['pages'] = template.get('page')
    option['area'] = [round(template['y1'], 3), round(template['x1'], 3), round(template['y2'], 3), round(template['x2'], 3)]
    return option

Convert Tabula app template to tabula-py option

Args:
template (dict): Tabula app template

Returns:
`obj`:dict: tabula-py option


def add_sample_meta(self, source, reference, method='', filename='', md5='', sha1='', sha256='', size='', mimetype='', campaign='', confidence='', description='', bucket_list=[]):
    data = {'api_key': self.api_key, 'username': self.username, 'source': source, 'reference': reference, 'method': method, 'filename': filename, 'md5': md5, 'sha1': sha1, 'sha256': sha256, 'size': size, 'mimetype': mimetype, 'upload_type': 'meta', 'campaign': campaign, 'confidence': confidence, 'bucket_list': ','.join(bucket_list)}
    r = requests.post('{0}/samples/'.format(self.url), data=data, verify=self.verify, proxies=self.proxies)
    if (r.status_code == 200):
        result_data = json.loads(r.text)
        return result_data
    else:
        log.error('Error with status code {0} and message {1}'.format(r.status_code, r.text))
    return None

Adds a metadata sample. To add an actual file, use add_sample_file.

Args:
source: Source of the information
reference: A reference where more information can be found
method: The method for obtaining the sample.
filename: The name of the file.
md5: An MD5 hash of the file.
sha1: SHA1 hash of the file.
sha256: SHA256 hash of the file.
size: size of the file.
mimetype: The mimetype of the file.
campaign: An associated campaign
confidence: The campaign confidence
bucket_list: A list of bucket list items to add
upload_type: Either 'file' or 'meta'
Returns:
A JSON sample object or None if there was an error.


def api_class(self, resource_name=None, path=None, audiences=None, scopes=None, allowed_client_ids=None, auth_level=None, api_key_required=None):
    if (auth_level is not None):
        _logger.warn(_AUTH_LEVEL_WARNING)

    def apiserving_api_decorator(api_class):
        "Decorator for ProtoRPC class that configures Google's API server.\n\n      Args:\n        api_class: remote.Service class, ProtoRPC service class being wrapped.\n\n      Returns:\n        Same class with API attributes assigned in api_info.\n      "
        self.__classes.append(api_class)
        api_class.api_info = _ApiInfo(self.__common_info, resource_name=resource_name, path=path, audiences=audiences, scopes=scopes, allowed_client_ids=allowed_client_ids, auth_level=auth_level, api_key_required=api_key_required)
        return api_class
    return apiserving_api_decorator

Get a decorator for a class that implements an API.

This can be used for single-class or multi-class implementations.  It's
used implicitly in simple single-class APIs that only use @api directly.

Args:
resource_name: string, Resource name for the class this decorates.
(Default: None)
path: string, Base path prepended to any method paths in the class this
decorates. (Default: None)
audiences: list of strings, Acceptable audiences for authentication.
(Default: None)
scopes: list of strings, Acceptable scopes for authentication.
(Default: None)
allowed_client_ids: list of strings, Acceptable client IDs for auth.
(Default: None)
auth_level: enum from AUTH_LEVEL, Frontend authentication level.
(Default: None)
api_key_required: bool, Whether a key is required to call into this API.
(Default: None)

Returns:
A decorator function to decorate a class that implements an API.


def add_imports_for_symbol(module_code_builder, symbol, source_module_name, source_name, api_name, api_version, output_module_prefix=''):
    if api_version == 1:
        names_attr = API_ATTRS_V1[api_name].names
        constants_attr = API_ATTRS_V1[api_name].constants
    else:
        names_attr = API_ATTRS[api_name].names
        constants_attr = API_ATTRS[api_name].constants
    if source_name == constants_attr:
        for exports, name in symbol:
            for export in exports:
                dest_module, dest_name = _get_name_and_module(export)
                dest_module = _join_modules(output_module_prefix, dest_module)
                module_code_builder.add_import(None, source_module_name, name, dest_module, dest_name)
    if hasattr(symbol, '__dict__') and names_attr in symbol.__dict__:
        for export in getattr(symbol, names_attr):
            dest_module, dest_name = _get_name_and_module(export)
            dest_module = _join_modules(output_module_prefix, dest_module)
            module_code_builder.add_import(symbol, source_module_name, source_name, dest_module, dest_name)

Add imports for the given symbol to `module_code_builder`.

Args:
module_code_builder: `_ModuleInitCodeBuilder` instance.
symbol: A symbol.
source_module_name: Module that we can import the symbol from.
source_name: Name we can import the symbol with.
api_name: API name. Currently, must be `tensorflow`.
api_version: API version.
output_module_prefix: Prefix to prepend to destination module.


def value_from_message(self, message):

        if not isinstance(message, self.message_type):
            raise DecodeError('Expected type %s, got %s: %r' %
                              (self.message_type.__name__,
                               type(message).__name__,
                               message))
        return message

Convert a message to a value instance.

Used by deserializers to convert from underlying messages to
value of expected user type.

Args:
message: A message instance of type self.message_type.

Returns:
Value of self.message_type.


def __init__(cls, name, bases, dictionary):

    if GeneratedServiceType._DESCRIPTOR_KEY not in dictionary:
      return
    descriptor = dictionary[GeneratedServiceType._DESCRIPTOR_KEY]
    service_builder = _ServiceBuilder(descriptor)
    service_builder.BuildService(cls)

Creates a message service class.

Args:
name: Name of the class (ignored, but required by the metaclass
protocol).
bases: Base classes of the class being constructed.
dictionary: The class dictionary of the class being constructed.
dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object
describing this protocol service type.


def num_parameters(self, only_trainable: bool=False, exclude_embeddings: bool=False) -> int:
    if exclude_embeddings:
        embedding_param_names = [f'{name}.weight' for name, module_type in self.named_modules() if isinstance(module_type, nn.Embedding)]
        total_parameters = [parameter for name, parameter in self.named_parameters() if name not in embedding_param_names]
    else:
        total_parameters = list(self.parameters())
    total_numel = []
    is_loaded_in_4bit = getattr(self, 'is_loaded_in_4bit', False)
    if is_loaded_in_4bit:
        if is_bitsandbytes_available():
            import bitsandbytes as bnb
        else:
            raise ValueError('bitsandbytes is not installed but it seems that the model has been loaded in 4bit precision, something went wrong make sure to install bitsandbytes with `pip install bitsandbytes`. You also need a GPU. ')
    for param in total_parameters:
        if param.requires_grad or not only_trainable:
            if is_loaded_in_4bit and isinstance(param, bnb.nn.Params4bit):
                if hasattr(param, 'element_size'):
                    num_bytes = param.element_size()
                elif hasattr(param, 'quant_storage'):
                    num_bytes = param.quant_storage.itemsize
                else:
                    num_bytes = 1
                total_numel.append(param.numel() * 2 * num_bytes)
            else:
                total_numel.append(param.numel())
    return sum(total_numel)

Get number of (optionally, trainable or non-embeddings) parameters in the module.

Args:
only_trainable (`bool`, *optional*, defaults to `False`):
Whether or not to return only the number of trainable parameters

exclude_embeddings (`bool`, *optional*, defaults to `False`):
Whether or not to return only the number of non-embeddings parameters

Returns:
`int`: The number of parameters.


def WriteHashes(self, arr):

        length = len(arr)
        self.WriteVarInt(length)
        for item in arr:
            ba = bytearray(binascii.unhexlify(item))
            ba.reverse()

            self.WriteBytes(ba)

Write an array of hashes to the stream.

Args:
arr (list): a list of 32 byte hashes.


def __getattr__(self, name):

        if self.has_service_by_name(name):
            return self._service_objects[name]
        return self.__getattribute__(name)

Syntactic sugar to enable direct access of service objects by alias.

Args:
name: string, the alias a service object was registered under.


def _create_test(self, testcase, function_name, sdkobject, attribute=None):

        func = getattr(testcase, function_name)
        object_name = sdkobject.rest_name

        test_name = ""
        rep = dict()
        rep["object"] = object_name

        if attribute:
            rep["attribute"] = attribute.local_name

        rep = dict((re.escape(k), v) for k, v in rep.items())
        pattern = re.compile("|".join(list(rep.keys())))

        if function_name.startswith("_"):
            function_name = function_name[1:]

        test_name = pattern.sub(lambda m: rep[re.escape(m.group(0))], function_name)

        test_func = None

        if attribute:
            test_func = lambda self, attribute=attribute: func(self, attribute)
        else:
            test_func = lambda self: func(self)

        test_func.__name__ = str(test_name)

        return (test_name, test_func)

Create a test method for the sdkoject

Args:
testcase: the testcase to that should manage the method
function_name: the name of the method in the testcase
sdkobject: the object that should be tested
attribute: the attribute information if necessary

Returns:
It returns a tuple (name, method) that represents the test method


def consume(self, tokens):

        wait_time = 0.
        self.tokens -= tokens
        if self.tokens < 0:
            self._get_tokens()
        if self.tokens < 0:
            wait_time = -self.tokens / self.fill_rate
        return wait_time

Consume tokens.
Args:
tokens (float): number of transport tokens to consume
Returns:
wait_time (float): waiting time for the consumer


def _setup(self):

        if isinstance(self.module, torch.nn.RNNBase): self.module.flatten_parameters = noop
        for name_w in self.weights:
            w = getattr(self.module, name_w)
            del self.module._parameters[name_w]
            self.module.register_parameter(name_w + '_raw', nn.Parameter(w.data))

for each string defined in self.weights, the corresponding
attribute in the wrapped module is referenced, then deleted, and subsequently
registered as a new parameter with a slightly modified name.

Args:
None

Returns:
None


def __init__(self, name):

        super(ProgressWorker, self).__init__()
        self.name = name

Worker object that will be passed to the thread.

Args:
name (str): name shown in progress ui.


def parse_formal_type_parameters(base: '_classes.InterpreterClass | _classes.PyTDClass | _classes.ParameterizedClass', prefix: str | None, formal_type_parameters: 'datatypes.AliasingDict[str, _instance_base.SimpleValue]', container: '_instance_base.SimpleValue | DummyContainer | None'=None) -> None:

    def merge(t0: '_instance_base.SimpleValue', t1: '_instance_base.SimpleValue', name: str) -> '_instance_base.SimpleValue':
        return _merge_type(t0, t1, name, base)
    if isinstance(base, _abstract.ParameterizedClass):
        if base.full_name == 'typing.Generic':
            return
        if isinstance(base.base_cls, (_abstract.InterpreterClass, _abstract.PyTDClass)):
            formal_type_parameters.merge_from(base.base_cls.all_formal_type_parameters, merge)
        params = base.get_formal_type_parameters()
        if hasattr(container, 'cls'):
            container_template = container.cls.template
        else:
            container_template = ()
        for name, param in params.items():
            if isinstance(param, _abstract.TypeParameter):
                if prefix:
                    formal_type_parameters.add_alias(name, prefix + '.' + param.name, merge)
                elif param in container_template:
                    formal_type_parameters[name] = param
            elif name not in formal_type_parameters:
                formal_type_parameters[name] = param
            else:
                last_type = formal_type_parameters[name]
                formal_type_parameters[name] = merge(last_type, param, name)
    else:
        if isinstance(base, (_abstract.InterpreterClass, _abstract.PyTDClass)):
            formal_type_parameters.merge_from(base.all_formal_type_parameters, merge)
        if base.template:
            for item in base.template:
                if isinstance(item, _abstract.TypeParameter):
                    name = full_type_name(base, item.name)
                    if name not in formal_type_parameters:
                        formal_type_parameters[name] = None

Parse type parameters from base class.

Args:
base: base class.
prefix: the full name of subclass of base class.
formal_type_parameters: the mapping of type parameter name to its type.
container: An abstract value whose class template is used when prefix=None
to decide how to handle type parameters that are aliased to other type
parameters. Values that are in the class template are kept, while all
others are ignored.

Raises:
GenericTypeError: If the lazy types of type parameter don't match


def put(self, item: T, context: PipelineContext = None) -> None:

        LOGGER.info("Converting item \"{item}\" for sink \"{sink}\"".format(item=item, sink=self._sink))
        item = self._transform(data=item, context=context)
        LOGGER.info("Puting item \"{item}\" into sink \"{sink}\"".format(item=item, sink=self._sink))
        self._sink.put(self._store_type, item, context)

Puts an objects into the data sink. The objects may be transformed into a new type for insertion if necessary.

Args:
item: The objects to be inserted into the data sink.
context: The context of the insertion (mutable).


def from_tuple(cls, query):
    (field, query) = (query[0], query[1:])
    try:
        cls = TYPES[type(query[0])]
    except KeyError:
        pass
    return cls(field, *query)

Create a condition from a query tuple.

Args:
query (tuple or list): Tuple or list that contains a query domain
in the format of ``(field_name, field_value,
field_value_to)``. ``field_value_to`` is only applicable in
the case of a date search.

Returns:
DomainCondition: An instance of a domain condition. The specific
type will depend on the data type of the first value provided
in ``query``.


def waitAndGet(self, event_name, timeout=None):
    if timeout is None:
        timeout = self.default_timeout_sec
    if timeout:
        if timeout > self.rpc_max_timeout_sec:
            raise errors.CallbackHandlerBaseError(self._device, f'Specified timeout {timeout} is longer than max timeout {self.rpc_max_timeout_sec}.')
    raw_event = self.callEventWaitAndGetRpc(self._id, event_name, timeout)
    return callback_event.from_dict(raw_event)

Waits and gets a CallbackEvent with the specified identifier.

It will raise a timeout error if the expected event does not occur within
the time limit.

Args:
event_name: str, the name of the event to get.
timeout: float, the number of seconds to wait before giving up. If None,
it will be set to self.default_timeout_sec.

Returns:
CallbackEvent, the oldest entry of the specified event.

Raises:
errors.CallbackHandlerBaseError: If the specified timeout is longer than
the max timeout supported.
errors.CallbackHandlerTimeoutError: The expected event does not occur
within the time limit.


def transcripts_by_gene(self, build='37'):

        hgnc_transcripts = {}
        LOG.info("Fetching all transcripts")
        for transcript in self.transcript_collection.find({'build':build}):
            hgnc_id = transcript['hgnc_id']
            if not hgnc_id in hgnc_transcripts:
                hgnc_transcripts[hgnc_id] = []

            hgnc_transcripts[hgnc_id].append(transcript)

        return hgnc_transcripts

Return a dictionary with hgnc_id as keys and a list of transcripts as value

Args:
build(str)

Returns:
hgnc_transcripts(dict)


def from_config(cls, config):
    return cls(**config)

Creates a regularizer from its config.

This method is the reverse of `get_config`,
capable of instantiating the same regularizer from the config
dictionary.

This method is used by Keras `model_to_estimator`, saving and
loading models to HDF5 formats, Keras model cloning, some visualization
utilities, and exporting models to and from JSON.

Args:
config: A Python dictionary, typically the output of get_config.

Returns:
A regularizer instance.


def timeout_thread_handler(timeout, stop_event):
    stop_happened = stop_event.wait(timeout)
    if (stop_happened is False):
        print(('Killing program due to %f second timeout' % timeout))
    os._exit(2)

A background thread to kill the process if it takes too long.

Args:
timeout (float): The number of seconds to wait before killing
the process.
stop_event (Event): An optional event to cleanly stop the background
thread if required during testing.


def get_config_dir(program='', system_wide=False):

	config_homes = []

	if system_wide:
		if os.name == 'nt':
			config_homes.append(
				winreg.ExpandEnvironmentStrings('%PROGRAMDATA%'))

		else:
			config_homes.append('/etc')
			config_homes.append('/etc/xdg')

			if os.name == 'darwin':
				config_homes.append('/Library')

	else:
		if os.name == 'nt':
			import winreg
			config_homes.append(
				winreg.ExpandEnvironmentStrings('%LOCALAPPDATA%'))
			config_homes.append(
				os.path.join(
					winreg.ExpandEnvironmentStrings('%APPDATA%'),
					'Roaming'))
		else:
			if os.getenv('XDG_CONFIG_HOME'):
				config_homes.append(os.getenv('XDG_CONFIG_HOME'))
			else:
				try:
					from xdg import BaseDirectory
					config_homes.append(BaseDirectory.xdg_config_home)
				except ImportError:
					config_homes.append(os.path.expanduser('~/.config'))

				config_homes.append(os.path.expanduser('~'))

				if os.name == 'darwin':
					config_homes.append(os.path.expanduser('~/Library'))

	if program:
		def __find_homes(app, dirs):

			homes = []

			for home in dirs:
				if os.path.isdir(os.path.join(home, app)):
					homes.append(os.path.join(home, app))

				if os.path.isdir(os.path.join(home, '.' + app)):
					homes.append(os.path.join(home, '.' + app))

				if os.path.isdir(os.path.join(home, app + '.d')):
					homes.append(os.path.join(home, app + '.d'))

			return homes

		app_homes = __find_homes(program, config_homes)

		if program == 'vim':
			app_homes.extend(__find_homes('vimfiles', config_homes))

		elif program == 'chrome':
			app_homes.extend(__find_homes('google-chrome', config_homes))

		elif program in ['firefox', 'thunderbird']:
			app_homes.extend(
				__find_homes(
					program, [
						os.path.expanduser('~/.mozilla')]))

		return app_homes

	return config_homes

Get the configuration directory.

Get the configuration directories, optionally for a specific program.

Args:
program	(str) : The name of the program whose configuration directories have to be found.
system_wide (bool): Gets the system-wide configuration directories.

Returns:
list: A list of all matching configuration directories found.


def decompress(content, encoding, filename='N/A'):
    try:
        encoding = (encoding or '').lower()
        if (encoding == ''):
            return content
        elif (encoding == 'gzip'):
            return gunzip(content)
    except DecompressionError as err:
        print(('Filename: ' + str(filename)))
        raise
    raise NotImplementedError((str(encoding) + ' is not currently supported. Supported Options: None, gzip'))

Decompress file content.

Required:
content (bytes): a file to be compressed
encoding: None (no compression) or 'gzip'
Optional:
filename (str:default:'N/A'): Used for debugging messages
Raises:
NotImplementedError if an unsupported codec is specified.
compression.EncodeError if the encoder has an issue

Return: decompressed content


def compile_files(raw_dir, raw_files, tag):

  tf.logging.info("Compiling files with tag %s." % tag)
  filename = "%s-%s" % (_PREFIX, tag)
  input_compiled_file = os.path.join(raw_dir, filename + ".lang1")
  target_compiled_file = os.path.join(raw_dir, filename + ".lang2")

  with tf.gfile.Open(input_compiled_file, mode="w") as input_writer:
    with tf.gfile.Open(target_compiled_file, mode="w") as target_writer:
      for i in range(len(raw_files["inputs"])):
        input_file = raw_files["inputs"][i]
        target_file = raw_files["targets"][i]

        tf.logging.info("Reading files %s and %s." % (input_file, target_file))
        write_file(input_writer, input_file)
        write_file(target_writer, target_file)
  return input_compiled_file, target_compiled_file

Compile raw files into a single file for each language.

Args:
raw_dir: Directory containing downloaded raw files.
raw_files: Dict containing filenames of input and target data.
{"inputs": list of files containing data in input language
"targets": list of files containing corresponding data in target language
}
tag: String to append to the compiled filename.

Returns:
Full path of compiled input and target files.


def register(self, node, vendorSpecific=None):

        response = self.registerResponse(node, vendorSpecific)
        return self._read_boolean_response(response)

See Also: registerResponse()

Args:
node:
vendorSpecific:

Returns:


def check_error_response(self, body, status):

    status_code = int(status.split(' ', 1)[0])
    if status_code >= 300:
      raise errors.BackendError(body, status)

Raise an exception if the response from the backend was an error.

Args:
body: A string containing the backend response body.
status: A string containing the backend response status.

Raises:
BackendError if the response is an error.


def set_last_step_output(self, name, output, reduce_op=None):
    if distribute_lib.in_cross_replica_context():
        self._last_step_outputs_reduce_ops[name] = reduce_op
        if reduce_op is None:
            self._last_step_outputs[name] = output
        else:
            distribution = distribute_lib.get_strategy()
            self._last_step_outputs[name] = distribution.reduce(reduce_op, output, axis=None)
    else:
        assert reduce_op is not None

        def merge_fn(distribution, value):
            self._last_step_outputs[name] = distribution.reduce(reduce_op, value, axis=None)
            self._last_step_outputs_reduce_ops[name] = reduce_op
        distribute_lib.get_replica_context().merge_call(merge_fn, args=(output,))

Set `output` with `name` to be outputted from the last step.

Args:
name: String, name to identify the output. Doesn't need to match tensor
name.
output: The tensors that should be outputted with `name`. See below for
actual types supported.
reduce_op: Reduction method to use to reduce outputs from multiple
replicas. Required if `set_last_step_output` is called in a replica
context. Optional in cross_replica_context.
When present, the outputs from all the replicas are reduced using the
current distribution strategy's `reduce` method. Hence, the type of
`output` must be what's supported by the corresponding `reduce` method.
For e.g. if using MirroredStrategy and reduction is set, output
must be a `PerReplica` value.
The reduce method is also recorded in a dictionary
`_last_step_outputs_reduce_ops` for later interpreting of the
outputs as already reduced or not.


def __init__(self, quantity, period_type):
    self._quantity = tf.convert_to_tensor(quantity, dtype=tf.int32, name='pt_quantity')
    self._period_type = period_type

Initializer.

Args:
quantity: A Tensor of type tf.int32, representing the quantities
of period types (e.g. how many months). Can be both positive and
negative.
period_type: A PeriodType (a day, a month, etc). Currently only one
PeriodType per instance of PeriodTensor is supported.

Example:
```python
two_weeks = PeriodTensor(2, PeriodType.WEEK)

months = [3, 6, 9, 12]
periods = PeriodTensor(months, PeriodType.MONTH)
```


def create_conversion_event(self, event_key, user_id, attributes, event_tags):
    params = self._get_common_params(user_id, attributes)
    conversion_params = self._get_required_params_for_conversion(event_key, event_tags)
    params[self.EventParams.USERS][0][self.EventParams.SNAPSHOTS].append(conversion_params)
    return Event(self.EVENTS_URL, params, http_verb=self.HTTP_VERB, headers=self.HTTP_HEADERS)

Create conversion Event to be sent to the logging endpoint.

Args:
event_key: Key representing the event which needs to be recorded.
user_id: ID for user.
attributes: Dict representing user attributes and values.
event_tags: Dict representing metadata associated with the event.

Returns:
Event object encapsulating the conversion event.


def decompose(miz_file: Path, output_folder: Path):
    (mission_folder, assets_folder) = NewMiz._get_subfolders(output_folder)
    NewMiz._wipe_folders(mission_folder, assets_folder)
    LOGGER.info('unzipping mission file')
    with Miz(miz_file) as miz:
        version = miz.mission.d['version']
        LOGGER.debug(f'mission version: "%s"', version)
        LOGGER.info('copying assets to: "%s"', assets_folder)
        ignore = shutil.ignore_patterns('mission')
        shutil.copytree(str(miz.temp_dir), str(assets_folder), ignore=ignore)
        NewMiz._reorder_warehouses(assets_folder)
        LOGGER.info('decomposing mission table into: "%s" (this will take a while)', mission_folder)
        NewMiz._decompose_dict(miz.mission.d, 'base_info', mission_folder, version, miz)

Decompose this Miz into json

Args:
output_folder: folder to output the json structure as a Path
miz_file: MIZ file path as a Path


def tanh_shrink(x):
    return ops.tanh_shrink(x)

Tanh shrink activation function.

It is defined as:

`f(x) = x - tanh(x)`.

Args:
x: Input tensor.


def add_pagination_meta(self, params, meta):

        meta['page_size'] = params['page_size']
        meta['page'] = params['page']

        meta['prev'] = "page={0}&page_size={1}".format(
            params['page'] - 1, params['page_size']
        ) if meta['page'] > 0 else None

        meta['next'] = "page={0}&page_size={1}".format(
            params['page'] + 1, params['page_size']
        ) if meta.get('has_more', True) else None

Extend default meta dictionary value with pagination hints.

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

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


def _create_variable(self, *args, **kwargs):
    with ops.name_scope('random_generator'):
        kwargs['name'] = 'StateVar'
        v = variables.Variable(*args, **kwargs)
    if isinstance(v, sharded_variable.ShardedVariable):
        raise ValueError("tf.random.Generator state is sharded, which is not allowed. When creating a tf.distribute.experimental.ParameterServerStrategy, please make sure that the `variable_partitioner` argument won't shard a small variable of shape [2] or [3]. Ways to avoid sharding small variables include setting `variable_partitioner` to None or to tf.distribute.experimental.partitioners.MinSizePartitioner with a large enough `min_shard_bytes`.")
    return v

Creates a variable.

Args:
*args: positional arguments passed along to `variables.Variable.
**kwargs: keyword arguments passed along to `variables.Variable.

Returns:
The created variable.


def write_other_members(self, f, catch_all=False):
    if catch_all:
        names = self._members.items()
    else:
        names = inspect.getmembers(self._module)
    leftovers = []
    for (name, _) in names:
        if ((name in self._members) and (name not in self._documented)):
            leftovers.append(name)
    if leftovers:
        print(('%s: undocumented members: %d' % (self._title, len(leftovers))))
        print('\n
        for name in sorted(leftovers):
            print(('  %s' % name))
            self._documented.add(name)
            self._mentioned.add(name)
            self._write_member_markdown_to_file(f, '

Writes the leftover members to `f`.

Args:
f: File to write to.
catch_all: If true, document all missing symbols from any module.
Otherwise, document missing symbols from just this module.


def get_function_id(sig):

    s = sha3.keccak_256()
    s.update(sig.encode('utf-8'))
    return int("0x" + s.hexdigest()[:8], 16)

Return the function id of the given signature
Args:
sig (str)
Return:
(int)


def __get_merged_api_info(self, services):

    base_paths = sorted(set(s.api_info.base_path for s in services))
    if len(base_paths) != 1:
      raise api_exceptions.ApiConfigurationError(
          'Multiple base_paths found: {!r}'.format(base_paths))
    names_versions = sorted(set(
        (s.api_info.name, s.api_info.api_version) for s in services))
    if len(names_versions) != 1:
      raise api_exceptions.ApiConfigurationError(
          'Multiple apis/versions found: {!r}'.format(names_versions))
    return services[0].api_info

Builds a description of an API.

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

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


def keras_mode_combinations(mode=None, run_eagerly=None):
    if mode is None:
        mode = ['eager'] if tf2.enabled() else ['graph', 'eager']
    if run_eagerly is None:
        run_eagerly = [True, False]
    result = []
    if 'eager' in mode:
        result += combinations.combine(mode=['eager'], run_eagerly=run_eagerly)
    if 'graph' in mode:
        result += combinations.combine(mode=['graph'], run_eagerly=[False])
    return result

Returns the default test combinations for tf.keras tests.

Note that if tf2 is enabled, then v1 session test will be skipped.

Args:
mode: List of modes to run the tests. The valid options are 'graph' and
'eager'. Default to ['graph', 'eager'] if not specified. If a empty list
is provide, then the test will run under the context based on tf's
version, eg graph for v1 and eager for v2.
run_eagerly: List of `run_eagerly` value to be run with the tests.
Default to [True, False] if not specified. Note that for `graph` mode,
run_eagerly value will only be False.

Returns:
A list contains all the combinations to be used to generate test cases.


def get_session(op_input_list=()):
    session = _get_session(op_input_list)
    if not _MANUAL_VAR_INIT:
        with session.graph.as_default():
            _initialize_variables(session)
    return session

Returns the TF session to be used by the backend.

If a default TensorFlow session is available, we will return it.

Else, we will return the global Keras session assuming it matches
the current graph.

If no global Keras session exists at this point:
we will create a new global session.

Note that you can manually set the global session
via `K.set_session(sess)`.

Args:
op_input_list: An option sequence of tensors or ops, which will be used
to determine the current graph. Otherwise the default graph will be
used.

Returns:
A TensorFlow session.


def batch_decode(self, waveforms, waveform_lengths=None) -> List[np.ndarray]:
    waveforms = [waveform.detach().to(device='cpu', copy=True).numpy() for waveform in waveforms]
    if waveform_lengths is not None:
        waveforms = [waveform[:waveform_lengths[i]] for i, waveform in enumerate(waveforms)]
    return waveforms

Removes padding from generated audio after running [`UnivNetModel.forward`]. This returns a ragged list of 1D
audio waveform arrays and not a single tensor/array because in general the waveforms will have different
lengths after removing padding.

Args:
waveforms (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
The batched output waveforms from the [`UnivNetModel`].
waveform_lengths (`torch.FloatTensor` of shape `(batch_size,)`, *optional*):
The batched lengths of each waveform before padding.

Returns:
`List[np.ndarray]`: A ragged list of 1D waveform arrays with padding removed.


def kill(self, procname):
    for proc in psutil.process_iter():
        if (proc.name() == procname):
            self.info_log(('[pid:%s][name:%s] killed' % (proc.pid, proc.name())))
            proc.kill()

Kill by process name

Args:
procname (str)


def append(self, event, help=""):

        if isinstance(event, str):
            self._events[event] = HookList(is_waterfall=self.is_waterfall)
            self._help[event] = (help, getframeinfo(stack()[1][0]))

            if not help:
                logger.warning("Great, don't say anything about your hooks and \
                wait for plugin creators to figure it out.")
        elif isinstance(event, Iterable):

            for name in event:
                self.append(name)
        else:
            raise TypeError("Invalid event name!")

Creates a new event. `event` may be iterable or string

Args:
event (str): Name of event to declare

Kwrgs:
help (str): Help string for the event

Raises:
TypeError

**Please** describe the event and its calling arguments in the help
string.


def sort_resources(cls, request, resources, fail_enum, header_proto=None):
    if (not request.sorting):
        return resources
    value_handlers = cls._get_handler_set(request, fail_enum, header_proto)

    def sorter(resource_a, resource_b):
        for handler in value_handlers:
            (val_a, val_b) = handler.get_sort_values(resource_a, resource_b)
            if (val_a < val_b):
                return handler.xform_result((- 1))
            if (val_a > val_b):
                return handler.xform_result(1)
        return 0
    return sorted(resources, key=cmp_to_key(sorter))

Sorts a list of resources based on a list of sort controls

Args:
request (object): The parsed protobuf request object
resources (list of objects): The resources to be sorted
fail_enum (int, enum): The enum status to raise with invalid keys
header_proto(class): Class to decode a resources header

Returns:
list: The sorted list of resources


def set_category(self, category):
    if isinstance(category, Category):
        name = category.name
    else:
        name = category
    self.find('category').text = name

Set package category

Args:
category: String of an existing category's name, or a
Category object.


def logloss(y, p):
    p[(p < EPS)] = EPS
    p[(p > (1 - EPS))] = (1 - EPS)
    return log_loss(y, p)

Bounded log loss error.

Args:
y (numpy.array): target
p (numpy.array): prediction

Returns:
bounded log loss error


def serialize_feature_columns(feature_columns):
    return [serialize_feature_column(fc) for fc in feature_columns]

Serializes a list of FeatureColumns.

Returns a list of Keras-style config dicts that represent the input
FeatureColumns and can be used with `deserialize_feature_columns` for
reconstructing the original columns.

Args:
feature_columns: A list of FeatureColumns.

Returns:
Keras serialization for the list of FeatureColumns.

Raises:
ValueError if called with input that is not a list of FeatureColumns.


def load_validator(schema_path, schema):

    if os.name == 'nt':
        file_prefix = 'file:
    else:
        file_prefix = 'file:'

    resolver = RefResolver(file_prefix + schema_path.replace("\\", "/"), schema)
    validator = Draft4Validator(schema, resolver=resolver)

    return validator

Create a JSON schema validator for the given schema.

Args:
schema_path: The filename of the JSON schema.
schema: A Python object representation of the same schema.

Returns:
An instance of Draft4Validator.


def get_mutation_rates(transcripts, mut_dict, ensembl):

    rates = {'missense': 0, 'nonsense': 0, 'splice_lof': 0,
        'splice_region': 0, 'synonymous': 0}
    combined = None

    for tx_id in transcripts:
        try:
            tx = construct_gene_object(ensembl, tx_id)
        except ValueError:
            continue

        if len(tx.get_cds_sequence()) % 3 != 0:
            raise ValueError("anomalous_coding_sequence")

        if tx.get_chrom() == "MT":
            continue

        sites = SiteRates(tx, mut_dict, masked_sites=combined)
        combined = tx + combined

        for cq in ['missense', 'nonsense', 'splice_lof', 'splice_region', 'synonymous']:
            rates[cq] += sites[cq].get_summed_rate()

    if combined is None:
        raise ValueError('no tx found')

    length = combined.get_coding_distance(combined.get_cds_end())['pos']

    return rates, combined, length

determines mutation rates per functional category for transcripts

Args:
transcripts: list of transcript IDs for a gene
mut_dict: dictionary of local sequence context mutation rates
ensembl: EnsemblRequest object, to retrieve information from Ensembl.

Returns:
tuple of (rates, merged transcript, and transcript CDS length)


def register(self, name, asymmetric=False):

    def register_func(func):
        if asymmetric:
            self._asymmetric.append(name)
        self.store[name] = func
        return func
    return register_func

Decorator for registering a measure with PyPhi.

Args:
name (string): The name of the measure.

Keyword Args:
asymmetric (boolean): ``True`` if the measure is asymmetric.


def post_error(self, name, message):

        self.post_command(OPERATIONS.CMD_POST_MESSAGE,
                          _create_message(name, states.ERROR_LEVEL, message))

Asynchronously post a user facing error message about a service.

Args:
name (string): The name of the service
message (string): The user facing error message that will be stored
for the service and can be queried later.


def from_axis_angle_and_translation(axis, angle, angle_in_radians=False, translation_vec=(0, 0, 0)):
    if isinstance(axis, (tuple, list)):
        axis = np.array(axis)
    if isinstance(translation_vec, (tuple, list)):
        vec = np.array(translation_vec)
    else:
        vec = translation_vec
    a = (angle if angle_in_radians else ((angle * pi) / 180))
    cosa = cos(a)
    sina = sin(a)
    u = (axis / np.linalg.norm(axis))
    r = np.zeros((3, 3))
    r[(0, 0)] = (cosa + ((u[0] ** 2) * (1 - cosa)))
    r[(0, 1)] = (((u[0] * u[1]) * (1 - cosa)) - (u[2] * sina))
    r[(0, 2)] = (((u[0] * u[2]) * (1 - cosa)) + (u[1] * sina))
    r[(1, 0)] = (((u[0] * u[1]) * (1 - cosa)) + (u[2] * sina))
    r[(1, 1)] = (cosa + ((u[1] ** 2) * (1 - cosa)))
    r[(1, 2)] = (((u[1] * u[2]) * (1 - cosa)) - (u[0] * sina))
    r[(2, 0)] = (((u[0] * u[2]) * (1 - cosa)) - (u[1] * sina))
    r[(2, 1)] = (((u[1] * u[2]) * (1 - cosa)) + (u[0] * sina))
    r[(2, 2)] = (cosa + ((u[2] ** 2) * (1 - cosa)))
    return SymmOp.from_rotation_and_translation(r, vec)

Generates a SymmOp for a rotation about a given axis plus translation.

Args:
axis: The axis of rotation in cartesian space. For example,
[1, 0, 0]indicates rotation about x-axis.
angle (float): Angle of rotation.
angle_in_radians (bool): Set to True if angles are given in
radians. Or else, units of degrees are assumed.
translation_vec: A translation vector. Defaults to zero.

Returns:
SymmOp for a rotation about given axis and translation.


def viewTemplate(id):

        conn = Qubole.agent()
        return conn.get(Template.element_path(id))

View an existing Template details.

Args:
`id`: ID of the template to fetch

Returns:
Dictionary containing the details of the template.


def AddStop(self, lat, lng, name, stop_id=None):
    if (stop_id is None):
        stop_id = util.FindUniqueId(self.stops)
    stop = self._gtfs_factory.Stop(stop_id=stop_id, lat=lat, lng=lng, name=name)
    self.AddStopObject(stop)
    return stop

Add a stop to this schedule.

Args:
lat: Latitude of the stop as a float or string
lng: Longitude of the stop as a float or string
name: Name of the stop, which will appear in the feed
stop_id: stop_id of the stop or None, in which case a unique id is picked

Returns:
A new Stop object


def _apply_user_agent(headers, user_agent):

    if user_agent is not None:
        if 'user-agent' in headers:
            headers['user-agent'] = (user_agent + ' ' + headers['user-agent'])
        else:
            headers['user-agent'] = user_agent

    return headers

Adds a user-agent to the headers.

Args:
headers: dict, request headers to add / modify user
agent within.
user_agent: str, the user agent to add.

Returns:
dict, the original headers passed in, but modified if the
user agent is not None.