def _process_single_batch(model, inputs, targets, output_loss_metrics=None, sample_weights=None, training=False):
    with backend.eager_learning_phase_scope(1 if training else 0), training_utils.RespectCompiledTrainableState(model):
        with GradientTape() as tape:
            outs, total_loss, output_losses, masks = _model_loss(model, inputs, targets, output_loss_metrics=output_loss_metrics, sample_weights=sample_weights, training=training)
            if isinstance(model.optimizer, loss_scale_optimizer.LossScaleOptimizer):
                scaled_total_loss = model.optimizer.get_scaled_loss(total_loss)
            else:
                scaled_total_loss = total_loss
        if training:
            trainable_weights = model.trainable_weights
            if trainable_weights:
                if hasattr(model, '_backwards'):
                    model._backwards(tape, scaled_total_loss)
                else:
                    grads = tape.gradient(scaled_total_loss, trainable_weights)
                    if isinstance(model.optimizer, loss_scale_optimizer.LossScaleOptimizer):
                        grads = model.optimizer.get_unscaled_gradients(grads)
                    model.optimizer.apply_gradients(zip(grads, trainable_weights))
            else:
                logging.warning('The list of trainable weights is empty. Make sure that you are not setting model.trainable to False before compiling the model.')
        return (outs, total_loss, output_losses, masks)

Calculate the loss and gradient for one input batch.

The model weights are updated if training is set to True.

Args:
model: Model whose loss has to be calculated.
inputs: List of input arrays.
targets: List of target arrays.
output_loss_metrics: List of metrics that are used to aggregated output
loss values.
sample_weights: Optional list of sample weight arrays.
training: The boolean represents if the weights of the model are updated.
'fit' methods will set this to True while 'evaluate' methods will
set this to False.

Returns:
output of the model, total loss, the loss and the mask
associated with each output.

Raises:
ValueError: If the model has no loss to optimize.


def __init__(self, value=None, tag=enums.Tags.DEFAULT):

        if value is None:
            value = int(time.time())
        super(DateTime, self).__init__(value, tag)
        self.type = enums.Types.DATE_TIME

Create a DateTime.

Args:
value (int): The value of the DateTime in number of seconds since
the Epoch. See the time package for additional information.
Optional, defaults to the current time.
tag (Tags): An enumeration defining the tag of the LongInteger.
Optional, defaults to Tags.DEFAULT.


def UploadFile(self, fd, offset=0, amount=None):

    return self._UploadChunkStream(
        self._streamer.StreamFile(fd, offset=offset, amount=amount))

Uploads chunks of a given file descriptor to the transfer store flow.

Args:
fd: A file descriptor to upload.
offset: An integer offset at which the file upload should start on.
amount: An upper bound on number of bytes to stream. If it is `None` then
the whole file is uploaded.

Returns:
A `BlobImageDescriptor` object.


def __one_equals_true(value):
    if (isinstance(value, six.integer_types) and (value == 1)):
        return True
    elif (isinstance(value, six.string_types) and (re.match('\\d+', value, flags=(re.IGNORECASE + re.UNICODE)) is not None) and (six.text_type(value) == '1')):
        return True
    return False

Test for ``1`` as a number or a string and return ``True`` if it is.

Args:
value: string or number or None.

Returns:
bool: ``True`` if 1 otherwise ``False``.


def get_module(dir_path: str, relative_to_dir: str) -> str:
    dir_path = dir_path[len(relative_to_dir):]
    dir_path = dir_path.replace(os.sep, '/')
    return dir_path.replace('/', '.').strip('.')

Get module that corresponds to path relative to relative_to_dir.

Args:
dir_path: Path to directory.
relative_to_dir: Get module relative to this directory.

Returns:
Name of module that corresponds to the given directory.


def export_model(model, model_type, export_dir, model_column_fn):
    (wide_columns, deep_columns) = model_column_fn()
    if (model_type == 'wide'):
        columns = wide_columns
    elif (model_type == 'deep'):
        columns = deep_columns
    else:
        columns = (wide_columns + deep_columns)
    feature_spec = tf.feature_column.make_parse_example_spec(columns)
    example_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
    model.export_savedmodel(export_dir, example_input_fn, strip_default_attrs=True)

Export to SavedModel format.

Args:
model: Estimator object
model_type: string indicating model type. "wide", "deep" or "wide_deep"
export_dir: directory to export the model.
model_column_fn: Function to generate model feature columns.


def latents_to_observations(self, latent_means, latent_covs):
    with tf.name_scope('latents_to_observations'):
        pushforward_latents_step = build_pushforward_latents_step(self.get_observation_matrix_for_timestep, self.get_observation_noise_for_timestep)
        latent_means = distribution_util.move_dimension(latent_means, source_idx=(- 2), dest_idx=0)
        latent_means = latent_means[(..., tf.newaxis)]
        latent_covs = distribution_util.move_dimension(latent_covs, source_idx=(- 3), dest_idx=0)
        (initial_observation_mean, initial_observation_cov) = pushforward_latents_step(_=None, latent_t_mean_cov=(self.initial_step, latent_means[self.initial_step], latent_covs[self.initial_step]))
        timesteps = tf.range(self.initial_step, (self.initial_step + self.num_timesteps))
        (observation_means, observation_covs) = tf.scan(pushforward_latents_step, elems=(timesteps, latent_means, latent_covs), initializer=(initial_observation_mean, initial_observation_cov), parallel_iterations=10000)
        observation_means = distribution_util.move_dimension(observation_means[(..., 0)], source_idx=0, dest_idx=(- 2))
        observation_covs = distribution_util.move_dimension(observation_covs, source_idx=0, dest_idx=(- 3))
        return (observation_means, observation_covs)

Push latent means and covariances forward through the observation model.

Args:
latent_means: float `Tensor` of shape `[..., num_timesteps, latent_size]`
latent_covs: float `Tensor` of shape
`[..., num_timesteps, latent_size, latent_size]`.

Returns:
observation_means: float `Tensor` of shape
`[..., num_timesteps, observation_size]`
observation_covs: float `Tensor` of shape
`[..., num_timesteps, observation_size, observation_size]`


def _CreateWindowsPathResolver(self, file_system, mount_point, environment_variables):
    if (environment_variables is None):
        environment_variables = []
    path_resolver = windows_path_resolver.WindowsPathResolver(file_system, mount_point)
    for environment_variable in environment_variables:
        name = environment_variable.name.lower()
        if (name not in ('systemroot', 'userprofile')):
            continue
        path_resolver.SetEnvironmentVariable(environment_variable.name, environment_variable.value)
    return path_resolver

Create a Windows path resolver and sets the environment variables.

Args:
file_system (dfvfs.FileSystem): file system.
mount_point (dfvfs.PathSpec): mount point path specification.
environment_variables (list[EnvironmentVariableArtifact]): environment
variables.

Returns:
dfvfs.WindowsPathResolver: Windows path resolver.


def flatten(vari):

    if isinstance(vari, Poly):
        shape = int(numpy.prod(vari.shape))
        return reshape(vari, (shape,))

    return numpy.array(vari).flatten()

Flatten a shapeable quantity.

Args:
vari (chaospy.poly.base.Poly, numpy.ndarray):
Shapeable input quantity.

Returns:
(chaospy.poly.base.Poly, numpy.ndarray):
Same type as ``vari`` with `len(Q.shape)==1`.

Examples:
>>> P = chaospy.reshape(chaospy.prange(4), (2,2))
>>> print(P)
[[1, q0], [q0^2, q0^3]]
>>> print(chaospy.flatten(P))
[1, q0, q0^2, q0^3]


def subnet_range(ip_net, cidr):

    subnets_dict = dict()
    subnet = whole_subnet_maker(ip_net, cidr)
    subnets_dict['IP'] = ip_net
    subnets_dict['NET'] = subnet
    subnets_dict['CIDR'] = '%s/%s' % (whole_subnet_maker(ip_net, cidr), cidr)
    if int(cidr) >= 24:
        subnet_split = subnet.split('.')
        first_ip = int(subnet_split[3]) + 1
        last_ip = (int(subnet_split[3]) + 1) + (253 - int(__mask_conversion[int(cidr)]['OCT4']))
        bcast_ip = (int(subnet_split[3]) + 1) + (254 - int(__mask_conversion[int(cidr)]['OCT4']))
        temp = '%s.%s.%s.' % (subnet_split[0], subnet_split[1], subnet_split[2])
        subnets_dict['RANGE'] = '%s%i to %s%i' % (temp, first_ip, temp, last_ip)
        subnets_dict['BCAST'] = '%s%i' % (temp, bcast_ip)
        subnets_dict['MASK'] = __mask_conversion[int(cidr)]['MASK']
        subnets_dict['INVMASK'] = __mask_conversion[int(cidr)]['INVMASK']
        subnets_dict['CIDRVAL'] = __mask_conversion[int(cidr)]['CIDR']
    elif int(cidr) >= 16:
        subnet_split = subnet.split('.')
        first_ip = int(subnet_split[2])
        last_ip = (int(subnet_split[2]) + 1) + (254 - int(__mask_conversion[int(cidr)]['OCT3']))
        bcast_ip = (int(subnet_split[2]) + 1) + (254 - int(__mask_conversion[int(cidr)]['OCT3']))
        temp = '%s.%s.' % (subnet_split[0], subnet_split[1])
        subnets_dict['RANGE'] = '%s%i.1 to %s%i.254' % (temp, first_ip, temp, last_ip)
        subnets_dict['BCAST'] = '%s%i.255' % (temp, bcast_ip)
        subnets_dict['MASK'] = __mask_conversion[int(cidr)]['MASK']
        subnets_dict['INVMASK'] = __mask_conversion[int(cidr)]['INVMASK']
        subnets_dict['CIDRVAL'] = __mask_conversion[int(cidr)]['CIDR']
    elif int(cidr) >= 8:
        subnet_split = subnet.split('.')
        first_ip = int(subnet_split[1])
        last_ip = (int(subnet_split[1]) + 1) + (254 - int(__mask_conversion[int(cidr)]['OCT2']))
        bcast_ip = (int(subnet_split[1]) + 1) + (254 - int(__mask_conversion[int(cidr)]['OCT2']))
        temp = '%s.' % (subnet_split[0],)
        subnets_dict['RANGE'] = '%s%i.0.1 to %s%i.255.254' % (temp, first_ip, temp, last_ip)
        subnets_dict['BCAST'] = '%s%i.255.255' % (temp, bcast_ip)
        subnets_dict['MASK'] = __mask_conversion[int(cidr)]['MASK']
        subnets_dict['INVMASK'] = __mask_conversion[int(cidr)]['INVMASK']
        subnets_dict['CIDRVAL'] = __mask_conversion[int(cidr)]['CIDR']
    elif int(cidr) >= 1:
        subnet_split = subnet.split('.')
        first_ip = int(subnet_split[0])
        last_ip = (int(subnet_split[0]) + 1) + (254 - int(__mask_conversion[int(cidr)]['OCT1']))
        bcast_ip = (int(subnet_split[0]) + 1) + (254 - int(__mask_conversion[int(cidr)]['OCT1']))
        subnets_dict['RANGE'] = '%i.0.0.1 to %i.255.255.254' % (first_ip, last_ip)
        subnets_dict['BCAST'] = '%i.255.255.255' % (bcast_ip,)
        subnets_dict['MASK'] = __mask_conversion[int(cidr)]['MASK']
        subnets_dict['INVMASK'] = __mask_conversion[int(cidr)]['INVMASK']
        subnets_dict['CIDRVAL'] = __mask_conversion[int(cidr)]['CIDR']
    return subnets_dict

Function to return a subnet range value from a IP address and CIDR pair
Args:
ip_net: Unicast or Multicast IP address or subnet in the following format 192.168.1.1, 239.1.1.1
cidr: CIDR value of 1 to 32

Returns: returns a dictionary of info


def wait_for(port_num, timeout):

    logger.debug("wait for {port_num}".format(**locals()))
    t_start = time.time()
    sleeps = 0.1
    while time.time() - t_start < timeout:
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                s.connect((_host(), port_num))
                return True
            except (IOError, socket.error):
                time.sleep(sleeps)
        finally:
            s.close()
    return False

waits while process starts.
Args:
port_num    - port number
timeout     - specify how long, in seconds, a command can take before times out.
return True if process started, return False if not


def str_to_inet(address):
    try:
        return socket.inet_pton(socket.AF_INET, address)
    except socket.error:
        return socket.inet_pton(socket.AF_INET6, address)

Convert an a string IP address to a inet struct

Args:
address (str): String representation of address
Returns:
inet: Inet network address


def add(x1, x2, output_shape=None, name=None):
    output_shape = convert_to_shape(output_shape)
    if (not isinstance(x2, Tensor)):
        return ScalarAddOperation(x1, x2).outputs[0]
    with tf.name_scope(name, default_name='add'):
        (x1, x2) = binary_arguments_to_tensors(x1, x2)
        return AddOperation(x1, x2, output_shape=_infer_binary_broadcast_shape(x1.shape, x2.shape, output_shape)).outputs[0]

Binary addition with broadcsting.

Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor


def resize(self, image: 'torch.Tensor', size: SizeDict, size_divisor: int=32, interpolation: 'F.InterpolationMode'=None, antialias: bool=True, **kwargs) -> 'torch.Tensor':
    interpolation = interpolation if interpolation is not None else F.InterpolationMode.BILINEAR
    if not size.shortest_edge:
        raise ValueError(f'The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}')
    shorter = size.shortest_edge
    longer = int(1333 / 800 * shorter)
    output_size = get_resize_output_image_size(image, shorter=shorter, longer=longer, size_divisor=size_divisor)
    return F.resize(image, output_size, interpolation=interpolation, antialias=antialias)

Resize an image.

Resizes the shorter side of the image to `size["shortest_edge"]` while preserving the aspect ratio. If the
longer side is larger than the max size `(int(`size["shortest_edge"]` * 1333 / 800))`, the longer side is then
resized to the max size while preserving the aspect ratio.

Args:
image (`torch.Tensor`):
Image to resize.
size (`SizeDict`):
Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
size_divisor (`int`, *optional*, defaults to 32):
The image is resized to a size that is a multiple of this value.
resample (`InterpolationMode`, *optional*, defaults to `InterpolationMode.BILINEAR`):
`InterpolationMode` filter to use when resizing the image e.g. `InterpolationMode.BICUBIC`.

Returns:
`torch.Tensor`: The resized image.


def construct_policy(app='coreforrest', env='dev', group='forrest', region='us-east-1', pipeline_settings=None):
    LOG.info('Create custom IAM Policy for %s.', app)
    services = pipeline_settings.get('services', {})
    LOG.debug('Found requested services: %s', services)
    services = auto_service(pipeline_settings=pipeline_settings, services=services)
    if services:
        credential = get_env_credential(env=env)
        account_number = credential['accountId']
    statements = []
    for (service, value) in services.items():
        if (value is True):
            items = []
        elif isinstance(value, str):
            items = [value]
        else:
            items = value
        rendered_statements = render_policy_template(account_number=account_number, app=app, env=env, group=group, items=items, pipeline_settings=pipeline_settings, region=region, service=service)
        statements.extend(rendered_statements)
    if statements:
        policy_json = get_template('infrastructure/iam/wrapper.json.j2', statements=json.dumps(statements))
    else:
        LOG.info('No services defined for %s.', app)
        policy_json = None
    return policy_json

Assemble IAM Policy for _app_.

Args:
app (str): Name of Spinnaker Application.
env (str): Environment/Account in AWS
group (str):A Application group/namespace
region (str): AWS region
pipeline_settings (dict): Settings from *pipeline.json*.

Returns:
json: Custom IAM Policy for _app_.
None: When no *services* have been defined in *pipeline.json*.


def is_packet_trace(path):
    path = os.path.abspath(path)
    if (not os.path.isfile(path)):
        return False
    try:
        f = open(path, 'rb')
    except:
        return False
    magic = f.read(4)
    f.close()
    return (magic in FILE_TYPE_HANDLER)

Determine if a file is a packet trace that is supported by this module.

Args:
path (str): path to the trace file.

Returns:
bool: True if the file is a valid packet trace.


def blit(self, source, x=0, y=0, width=None, height=None, srcX=0, srcY=0, fg_alpha=1.0, bg_alpha=1.0):
    assert isinstance(source, (Console, Window)), 'source muse be a Window or Console instance'
    (x, y, width, height) = self._normalizeRect(x, y, width, height)
    (srcX, srcY, width, height) = source._normalizeRect(srcX, srcY, width, height)
    (srcX, srcY) = source._translate(srcX, srcY)
    source = source.console
    (x, y) = self._translate(x, y)
    self = self.console
    if (self == source):
        tmp = Console(width, height)
        _lib.TCOD_console_blit(source.console_c, srcX, srcY, width, height, tmp.console_c, 0, 0, fg_alpha, bg_alpha)
        _lib.TCOD_console_blit(tmp.console_c, 0, 0, width, height, self.console_c, x, y, fg_alpha, bg_alpha)
    else:
        _lib.TCOD_console_blit(source.console_c, srcX, srcY, width, height, self.console_c, x, y, fg_alpha, bg_alpha)

Blit another console or Window onto the current console.

By default it blits the entire source to the topleft corner.

Args:
source (Union[tdl.Console, tdl.Window]): The blitting source.
A console can blit to itself without any problems.
x (int): x-coordinate of this console to blit on.
y (int): y-coordinate of this console to blit on.
width (Optional[int]): Width of the rectangle.

Can be None to extend as far as possible to the
bottom right corner of the blit area or can be a negative
number to be sized reltive to the total size of the
B{destination} console.
height (Optional[int]): Height of the rectangle.
srcX (int):  x-coordinate of the source region to blit.
srcY (int):  y-coordinate of the source region to blit.
fg_alpha (float): The foreground alpha.


def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    local_stream = BytearrayStream()
    if self._credential_type:
        self._credential_type.write(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('Credential struct missing the credential type.')
    if self._credential_value:
        self._credential_value.write(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('Credential struct missing the credential value.')
    self.length = local_stream.length()
    super(Credential, self).write(output_stream, kmip_version=kmip_version)
    output_stream.write(local_stream.buffer)

Write the data encoding the Credential struct to a stream.

Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.

Raises:
ValueError: Raised if either the credential type or value are not
defined.


def _get_string_match(self, key):
    expression = '(?:\\s*)'.join(['^', 'define', '\\(', "'{}'".format(key), ',', "\\'(.*)\\'", '\\)', ';'])
    pattern = re.compile(expression, re.MULTILINE)
    return pattern.search(self._content)

Gets a MatchObject for the given key, assuming a string value.

Args:
key (str): Key of the property to look-up.

Return:
MatchObject: The discovered match.


def plan_scripts(self):
    if (not self.__plan_scripts):
        self.__plan_scripts = PlanScripts(self.__connection)
    return self.__plan_scripts

Gets the Plan Scripts API client.

Returns:
PlanScripts:


def on_test_batch_begin(self, batch, logs=None):

Called at the beginning of a batch in `evaluate` methods.

Also called at the beginning of a validation batch in the `fit`
methods, if validation data is provided.

Subclasses should override for any actions to run.

Note that if the `steps_per_execution` argument to `compile` in
`Model` is set to `N`, this method will only be called every
`N` batches.

Args:
batch: Integer, index of batch within the current epoch.
logs: Dict. Currently no data is passed to this argument for this
method but that may change in the future.


def _find(self, index):

        match = _PATTERN.search(self.text, index)
        while self._max_tries > 0 and match is not None:
            start = match.start()
            candidate = self.text[start:match.end()]

            candidate = self._trim_after_first_match(_SECOND_NUMBER_START_PATTERN,
                                                     candidate)

            match = self._extract_match(candidate, start)
            if match is not None:
                return match

            index = start + len(candidate)
            self._max_tries -= 1
            match = _PATTERN.search(self.text, index)
        return None

Attempts to find the next subsequence in the searched sequence on or after index
that represents a phone number. Returns the next match, None if none was found.

Arguments:
index -- The search index to start searching at.
Returns the phone number match found, None if none can be found.


def get_tabular_stream(self, url, **kwargs):

        self.close_response()
        file_type = kwargs.get('file_type')
        if file_type is not None:
            kwargs['format'] = file_type
            del kwargs['file_type']
        try:
            self.response = tabulator.Stream(url, **kwargs)
            self.response.open()
            return self.response
        except TabulatorException as e:
            raisefrom(DownloadError, 'Getting tabular stream for %s failed!' % url, e)

Get Tabulator stream.

Args:
url (str): URL to download
**kwargs:
headers (Union[int, List[int], List[str]]): Number of row(s) containing headers or list of headers
file_type (Optional[str]): Type of file. Defaults to inferring.
delimiter (Optional[str]): Delimiter used for values in each row. Defaults to inferring.

Returns:
tabulator.Stream: Tabulator Stream object


def _GetTitleFromChromeWebStore(self, extension_identifier):

    if extension_identifier in self._extensions:
      return self._extensions.get(extension_identifier)

    page_content = self._GetChromeWebStorePage(extension_identifier)
    if not page_content:
      logger.warning(
          '[{0:s}] no data returned for extension identifier: {1:s}'.format(
              self.NAME, extension_identifier))
      return None

    first_line, _, _ = page_content.partition('\n')
    match = self._TITLE_RE.search(first_line)
    name = None
    if match:
      title = match.group(1)
      if title.startswith('Chrome Web Store - '):
        name = title[19:]
      elif title.endswith('- Chrome Web Store'):
        name = title[:-19]

    if not name:
      self._extensions[extension_identifier] = 'UNKNOWN'
      return None

    self._extensions[extension_identifier] = name
    return name

Retrieves the name of the extension from the Chrome store website.

Args:
extension_identifier (str): Chrome extension identifier.

Returns:
str: name of the extension or None.


def post_process_image_text_to_text(self, generated_outputs, skip_special_tokens=True, **kwargs):
    return self.tokenizer.batch_decode(generated_outputs, skip_special_tokens=skip_special_tokens, **kwargs)

Post-process the output of a vlm to decode the text.

Args:
generated_outputs (`torch.Tensor` or `np.ndarray`):
The output of the model `generate` function. The output is expected to be a tensor of shape `(batch_size, sequence_length)`
or `(sequence_length,)`.
skip_special_tokens (`bool`, *optional*, defaults to `True`):
Whether or not to remove special tokens in the output. Argument passed to the tokenizer's `batch_decode` method.
**kwargs:
Additional arguments to be passed to the tokenizer's `batch_decode method`.

Returns:
`List[str]`: The decoded text.


def get_iso3_country_code_fuzzy(cls, country, use_live=True, exception=None):
    countriesdata = cls.countriesdata(use_live=use_live)
    iso3 = cls.get_iso3_country_code(country, use_live=use_live)
    if (iso3 is not None):
        return (iso3, True)

    def remove_matching_from_list(wordlist, word_or_part):
        for word in wordlist:
            if (word_or_part in word):
                wordlist.remove(word)
    expanded_country_candidates = cls.expand_countryname_abbrevs(country)
    match_strength = 0
    matches = set()
    for countryname in sorted(countriesdata['countrynames2iso3']):
        for candidate in expanded_country_candidates:
            (simplified_country, removed_words) = cls.simplify_countryname(candidate)
            if (simplified_country in countryname):
                words = get_words_in_sentence(countryname)
                new_match_strength = 0
                if simplified_country:
                    remove_matching_from_list(words, simplified_country)
                    new_match_strength += 32
                for word in removed_words:
                    if (word in countryname):
                        remove_matching_from_list(words, word)
                        new_match_strength += 4
                    elif (word in cls.major_differentiators):
                        new_match_strength -= 16
                    else:
                        new_match_strength -= 1
                for word in words:
                    if (word in cls.major_differentiators):
                        new_match_strength -= 16
                    else:
                        new_match_strength -= 1
                iso3 = countriesdata['countrynames2iso3'][countryname]
                if (new_match_strength > match_strength):
                    match_strength = new_match_strength
                    matches = set()
                if (new_match_strength == match_strength):
                    matches.add(iso3)
    if ((len(matches) == 1) and (match_strength > 16)):
        return (matches.pop(), False)
    for (iso3, regex) in countriesdata['aliases'].items():
        index = re.search(regex, country.upper())
        if (index is not None):
            return (iso3, False)
    if (exception is not None):
        raise exception
    return (None, False)

Get ISO3 code for cls. A tuple is returned with the first value being the ISO3 code and the second
showing if the match is exact or not.

Args:
country (str): Country for which to get ISO3 code
use_live (bool): Try to get use latest data from web rather than file in package. Defaults to True.
exception (Optional[ExceptionUpperBound]): An exception to raise if country not found. Defaults to None.

Returns:
Tuple[[Optional[str], bool]]: ISO3 code and if the match is exact or (None, False).


def convert_coco_poly_to_mask(segmentations, height: int, width: int, device: torch.device) -> torch.Tensor:
    try:
        from pycocotools import mask as coco_mask
    except ImportError:
        raise ImportError('Pycocotools is not installed in your environment.')
    masks = []
    for polygons in segmentations:
        rles = coco_mask.frPyObjects(polygons, height, width)
        mask = coco_mask.decode(rles)
        if len(mask.shape) < 3:
            mask = mask[..., None]
        mask = torch.as_tensor(mask, dtype=torch.uint8, device=device)
        mask = torch.any(mask, axis=2)
        masks.append(mask)
    if masks:
        masks = torch.stack(masks, axis=0)
    else:
        masks = torch.zeros((0, height, width), dtype=torch.uint8, device=device)
    return masks

Convert a COCO polygon annotation to a mask.

Args:
segmentations (`List[List[float]]`):
List of polygons, each polygon represented by a list of x-y coordinates.
height (`int`):
Height of the mask.
width (`int`):
Width of the mask.


def concat(input_layer, concat_dim, other_tensors=None):
    if input_layer.is_sequence():
        all_tensors = input_layer.sequence
        all_tensors.extend((other_tensors or []))
    else:
        all_tensors = [input_layer]
        if (other_tensors is None):
            raise ValueError('Other Tensors must be supplied.')
        all_tensors.extend(other_tensors)
    if (not all_tensors):
        return prettytensor.wrap_sequence([])
    else:
        return tf.concat(all_tensors, concat_dim)

Concatenates input PrettyTensor with other_tensors along the specified dim.

This adds the Pretty Tensor passed via input_layer to the front of the list of
tensors to concat.

Args:
input_layer: The input layer.
concat_dim: The dimension along which to concat.
other_tensors: The tensors to concatenate with as an iterable or None if
this is called on a sequence.
Returns:
A new PrettyTensor.
Raises:
ValueError: If other_tensors is None and this is not a sequence.


def add_oxidation_state_by_guess(self, **kwargs):

        oxid_guess = self.composition.oxi_state_guesses(**kwargs)
        oxid_guess = oxid_guess or \
                     [dict([(e.symbol, 0) for e in self.composition])]
        self.add_oxidation_state_by_element(oxid_guess[0])

Decorates the structure with oxidation state, guessing
using Composition.oxi_state_guesses()

Args:
**kwargs: parameters to pass into oxi_state_guesses()


def _acquire_given_subnet(self, uuid_path, subnet):
    lease = self.create_lease_object_from_subnet(subnet)
    self._take_lease(lease, uuid_path)
    return lease.to_ip_network()

Try to create a lease for subnet

Args:
uuid_path (str): Path to the uuid file of a :class:`lago.Prefix`
subnet (str): dotted ipv4 subnet
(for example ```192.168.200.0```)

Returns:
netaddr.IPNetwork: Which represents the selected subnet

Raises:
LagoSubnetLeaseException: If the requested subnet is not in the
range of this store or its already been taken


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

Lists snapshots.

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


def _convert_dict_inputs(inputs, tensor_info_map):
    dict_inputs = _prepare_dict_inputs(inputs, tensor_info_map)
    return tensor_info.convert_dict_to_compatible_tensor(dict_inputs, tensor_info_map)

Converts from inputs into dict of input tensors.

This handles:
- putting inputs into a dict, per _prepare_dict_inputs(),
- converting all input values into tensors compatible with the
expected input tensor (dtype, shape).
- check sparse/non-sparse tensor types.

Args:
inputs: inputs fed to Module.__call__().
tensor_info_map: A map from string to `tensor_info.ParsedTensorInfo`
describing the signature inputs.

Returns:
A dict of tensors to feed to the signature instantiation.

Raises:
TypeError: If it fails to convert the input values into a dict of tensors
to feed to the signature instantiation.


def __init__(self, seed, salt):

    self._seed = seed.original_seed if isinstance(seed, SeedStream) else seed
    self._salt = salt
    self._counter = 0

Initializes a `SeedStream`.

Args:
seed: Any Python object convertible to string, supplying the
initial entropy.  If `None`, operations seeded with seeds
drawn from this `SeedStream` will follow TensorFlow semantics
for not being seeded.
salt: Any Python object convertible to string, supplying
auxiliary entropy.  Must be unique across the Distributions
and TensorFlow Probability code base.  See class docstring for
rationale.


def CreateAdGroup(client, campaign_id):
    ad_group_service = client.GetService('AdGroupService', 'v201809')
    ad_group = {'name': 'Dynamic remarketing ad group', 'campaignId': campaign_id, 'status': 'ENABLED'}
    operations = [{'operator': 'ADD', 'operand': ad_group}]
    return ad_group_service.mutate(operations)['value'][0]

Creates a dynamic remarketing campaign.

Args:
client: an AdWordsClient instance.
campaign_id: an int campaign ID.

Returns:
The ad group that was successfully created.


def get_rbounds(step):
    if (step.geom is not None):
        rcmb = step.geom.rcmb
    else:
        rcmb = step.sdat.par['geometry']['r_cmb']
        if (step.sdat.par['geometry']['shape'].lower() == 'cartesian'):
            rcmb = 0
    rcmb = max(rcmb, 0)
    return (rcmb, (rcmb + 1))

Radial or vertical position of boundaries.

Args:
step (:class:`~stagpy.stagyydata._Step`): a step of a StagyyData
instance.
Returns:
tuple of floats: radial or vertical positions of boundaries of the
domain.


def create_reader_of_type(type_name):

    readers = available_readers()

    if type_name not in readers.keys():
        raise UnknownReaderException('Unknown reader: %s' % (type_name,))

    return readers[type_name]()

Create an instance of the reader with the given name.

Args:
type_name: The name of a reader.

Returns:
An instance of the reader with the given type.


def uninstalled(name):

    ret = {'name': name,
           'changes': {},
           'result': False,
           'comment': ''}

    if not __salt__['wusa.is_installed'](name):
        ret['result'] = True
        ret['comment'] = '{0} already uninstalled'.format(name)
        return ret

    if __opts__['test'] is True:
        ret['result'] = None
        ret['comment'] = '{0} would be uninstalled'.format(name)
        ret['result'] = None
        return ret

    __salt__['wusa.uninstall'](name)

    if not __salt__['wusa.is_installed'](name):
        ret['comment'] = '{0} was uninstalled'.format(name)
        ret['changes'] = {'old': True, 'new': False}
        ret['result'] = True
    else:
        ret['comment'] = '{0} failed to uninstall'.format(name)

    return ret

Ensure an update is uninstalled from the minion

Args:

name(str):
Name of the Windows KB ("KB123456")

Example:

.. code-block:: yaml

KB123456:
wusa.uninstalled


def kl_divergence(mu, log_var, mu_p=0.0, log_var_p=0.0):

  batch_size = shape_list(mu)[0]
  prior_distribution = tfp.distributions.Normal(
      mu_p, tf.exp(tf.multiply(0.5, log_var_p)))
  posterior_distribution = tfp.distributions.Normal(
      mu, tf.exp(tf.multiply(0.5, log_var)))
  kld = tfp.distributions.kl_divergence(posterior_distribution,
                                        prior_distribution)
  return tf.reduce_sum(kld) / to_float(batch_size)

KL divergence of diagonal gaussian N(mu,exp(log_var)) and N(0,1).

Args:
mu: mu parameter of the distribution.
log_var: log(var) parameter of the distribution.
mu_p: optional mu from a learned prior distribution
log_var_p: optional log(var) from a learned prior distribution
Returns:
the KL loss.


def __parameter_enum(self, param):

    if isinstance(param, messages.EnumField):
      return [enum_entry[0] for enum_entry in sorted(
          param.type.to_dict().items(), key=lambda v: v[1])]

Returns enum descriptor of a parameter if it is an enum.

An enum descriptor is a list of keys.

Args:
param: A simple field.

Returns:
The enum descriptor for the field, if it's an enum descriptor, else
returns None.


def _get_qubit_index(self, qubit):

        for i, bit in enumerate(self.qubit_list):
            if qubit == bit:
                qindex = i
                break
        else:
            raise exceptions.VisualizationError("unable to find bit for operation")
        return qindex

Get the index number for a quantum bit
Args:
qubit (tuple): The tuple of the bit of the form
(register_name, bit_number)
Returns:
int: The index in the bit list
Raises:
VisualizationError: If the bit isn't found


def getMusicAlbumList(self, tagtype = 0, startnum = 0, pagingrow = 100):

        url = nurls['setProperty']

        data = {'userid': self.user_id,
                'useridx': self.useridx,
                'tagtype': tagtype,
                'startnum': startnum,
                'pagingrow': pagingrow,
                }

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

        return resultManager(r.text)

GetMusicAlbumList

Args:
tagtype = ???
startnum
pagingrow

Returns:
???
False: Failed to get property


def edit_distance_filter(source_target_input, max_equal_to_diff_ratio=0):

  thrown_out_count = 0
  source_target_output = []

  if not max_equal_to_diff_ratio:
    return source_target_input, thrown_out_count

  for src_tgt in source_target_input:
    opcodes = fast_match_sequences(*src_tgt)
    diff_char_count = 0
    equal_char_count = 0
    for tag, i1, i2, j1, j2 in opcodes:
      if tag == "diff":

        diff_char_count += max(i2 - i1, j2 - j1)
      else:
        equal_char_count += i2 - i1
    if diff_char_count <= max_equal_to_diff_ratio * equal_char_count:
      source_target_output.append(src_tgt)
    else:
      thrown_out_count += 1
  return source_target_output, thrown_out_count

Filter out examples that exceed max_edit_ratio between source and target.

Args:
source_target_input:     a list of [source, target] pairs
max_equal_to_diff_ratio: cutoff for ratio of equal chars / diff chars
between source and target

Returns:
source_target_output:    filtered subset of [source, target] input pairs
thrown_out_count:        number of examples filtered out


def open(self, filename):
    if filename:
        self.binary = BinaryFile(filename)
        self.text_section = self.binary.text_section
        self._load(arch_mode=self.binary.architecture_mode)

Open a file for analysis.

Args:
filename (str): Name of an executable file.


def _init_vocab_from_file(self, filename):

    with tf.gfile.Open(filename) as f:
      tokens = [token.strip() for token in f.readlines()]

    def token_gen():
      for token in tokens:
        yield token

    self._init_vocab(token_gen(), add_reserved_tokens=False)

Load vocab from a file.

Args:
filename: The file to load vocabulary from.


def from_file_obj(cls, fp):

        log.debug("Parsing email from file object")
        try:
            fp.seek(0)
        except IOError:

            pass
        finally:
            s = fp.read()

        return cls.from_string(s)

Init a new object from a file-like object.
Not for Outlook msg.

Args:
fp (file-like object): file-like object of raw email

Returns:
Instance of MailParser


def check_tweet(tweet, validation_checking=False):
    if ('id' not in tweet):
        raise NotATweetError("This text has no 'id' key")
    original_format = is_original_format(tweet)
    if original_format:
        _check_original_format_tweet(tweet, validation_checking=validation_checking)
    else:
        _check_activity_streams_tweet(tweet, validation_checking=validation_checking)
    return original_format

Ensures a tweet is valid and determines the type of format for the tweet.

Args:
tweet (dict/Tweet): the tweet payload
validation_checking (bool): check for valid key structure in a tweet.


def not_modified(cls, errors=None):

        if cls.expose_status:
            cls.response.content_type = 'application/json'
            cls.response._status_line = '304 Not Modified'

        return cls(304, None, errors).to_json

Shortcut API for HTTP 304 `Not Modified` response.

Args:
errors (list): Response key/value data.

Returns:
WSResponse Instance.


def add_candidate_peer_endpoints(self, peer_endpoints):

        with self._lock:
            for endpoint in peer_endpoints:
                if endpoint not in self._candidate_peer_endpoints:
                    self._candidate_peer_endpoints.append(endpoint)

Adds candidate endpoints to the list of endpoints to
attempt to peer with.

Args:
peer_endpoints ([str]): A list of public uri's which the
validator can attempt to peer with.


def capture(self, payment_id, amount, data={}, **kwargs):

        url = "{}/{}/capture".format(self.base_url, payment_id)
        data['amount'] = amount
        return self.post_url(url, data, **kwargs)

Capture Payment for given Id

Args:
payment_id : Id for which payment object has to be retrieved
Amount : Amount for which the payment has to be retrieved

Returns:
Payment dict after getting captured


def writegroup(self, auth, entries, defer=False):
    return self._call('writegroup', auth, [entries], defer)

Writes the given values for the respective resources in the list, all writes have same
timestamp.

Args:
auth: cik for authentication.
entries: List of key, value lists. eg. [[key, value], [k,v],,,]


def mesh_element(script, sample_num=1000, element='VERT'):
    if (element.lower() == 'vert'):
        element_num = 0
    elif (element.lower() == 'edge'):
        element_num = 1
    elif (element.lower() == 'face'):
        element_num = 2
    filter_xml = ''.join(['  <filter name="Mesh Element Subsampling">\n', '    <Param name="Sampling" ', 'value="{:d}" '.format(element_num), 'description="Element to sample:" ', 'enum_val0="Vertex" ', 'enum_val1="Edge" ', 'enum_val2="Face" ', 'enum_cardinality="3" ', 'type="RichEnum" ', '/>\n', '    <Param name="SampleNum" ', 'value="{:d}" '.format(sample_num), 'description="Number of samples" ', 'type="RichInt" ', '/>\n', '  </filter>\n'])
    util.write_filter(script, filter_xml)
    if isinstance(script, FilterScript):
        script.add_layer('Sampled Mesh')
    return None

Create a new layer populated with a point sampling of the current mesh,
at most one sample for each element of the mesh is created.

Samples are taking in a uniform way, one for each element
(vertex/edge/face); all the elements have the same probabilty of being
choosen.

Args:
script: the FilterScript object or script filename to write
the filter to.
sample_num (int): The desired number of elements that must be chosen.
Being a subsampling of the original elements if this number should
not be larger than the number of elements of the original mesh.
element (enum in ['VERT', 'EDGE', 'FACE']): Choose what mesh element
will be used for the subsampling. At most one point sample will
be added for each one of the chosen elements

Layer stack:
Creates new layer 'Sampled Mesh'. Current layer is changed to the new
layer.

MeshLab versions:
2016.12
1.3.4BETA


def get_updates_for(self, inputs):
    if inputs is None:
        return [u for u in self.updates if u._unconditional_update]
    updates = [u for u in self.updates if not u._unconditional_update]
    inputs = nest.flatten(inputs)
    reachable = tf_utils.get_reachable_from_inputs(inputs, updates)
    return [u for u in updates if u in reachable]

Retrieves updates relevant to a specific set of inputs.

Args:
inputs: Input tensor or list/tuple of input tensors.

Returns:
List of update ops of the layer that depend on `inputs`.


def all_tokens(self, delimiter=' '):

        tokens = set()

        for label in self:
            tokens = tokens.union(set(label.tokenized(delimiter=delimiter)))

        return tokens

Return a list of all tokens occurring in the label-list.

Args:
delimiter (str): The delimiter used to split labels into tokens
(see :meth:`audiomate.annotations.Label.tokenized`).

Returns:
:class:`set`: A set of distinct tokens.


def remove_attribute(self, attribute: str) -> None:
    attr_index = self.__attr_index(attribute)
    if (attr_index is not None):
        self.yaml_node.value.pop(attr_index)

Remove an attribute from the node.

Use only if is_mapping() returns True.

Args:
attribute: The name of the attribute to remove.


def get_distance(self, i, j, jimage=None):
    return self[i].distance(self[j], jimage)

Get distance between site i and j assuming periodic boundary
conditions. If the index jimage of two sites atom j is not specified it
selects the jimage nearest to the i atom and returns the distance and
jimage indices in terms of lattice vector translations if the index
jimage of atom j is specified it returns the distance between the i
atom and the specified jimage atom.

Args:
i (int): Index of first site
j (int): Index of second site
jimage: Number of lattice translations in each lattice direction.
Default is None for nearest image.

Returns:
distance


def _RegisterProcess(self, process):

    if process is None:
      raise ValueError('Missing process.')

    if process.pid in self._processes_per_pid:
      raise KeyError(
          'Already managing process: {0!s} (PID: {1:d})'.format(
              process.name, process.pid))

    self._processes_per_pid[process.pid] = process

Registers a process with the engine.

Args:
process (MultiProcessBaseProcess): process.

Raises:
KeyError: if the process is already registered with the engine.
ValueError: if the process is missing.


def _initialize_tensor_name_to_ids(self):
    tensor_name_to_ids = {}
    for (i, operation) in enumerate(self._operations):
        for (j, tensor) in enumerate(operation.outputs):
            tensor_name_to_ids[tensor.name] = (i, j)
    return tensor_name_to_ids

Initializer for _tensor_name_to_ids.

Returns:
a {string: (int, int)}, mapping the name of tensor T to the index of T's
operation in _operations and T's index in T's operation's outputs.


def Verify(self):
    if (not (self.Hash.ToBytes() == GetGenesis().Hash.ToBytes())):
        return False
    bc = GetBlockchain()
    if (not bc.ContainsBlock(self.Index)):
        return False
    if (self.Index > 0):
        prev_header = GetBlockchain().GetHeader(self.PrevHash.ToBytes())
        if (prev_header is None):
            return False
        if ((prev_header.Index + 1) != self.Index):
            return False
        if (prev_header.Timestamp >= self.Timestamp):
            return False
    if (not Helper.VerifyScripts(self)):
        return False
    return True

Verify block using the verification script.

Returns:
bool: True if valid. False otherwise.


def usufyToTextExport(d, fPath=None):
    if (d == []):
        return '+------------------+\n| No data found... |\n+------------------+'
    import pyexcel as pe
    import pyexcel.ext.text as text
    if (fPath == None):
        isTerminal = True
    else:
        isTerminal = False
    try:
        oldData = get_data(fPath)
    except:
        oldData = {'OSRFramework': []}
    tabularData = _generateTabularData(d, {'OSRFramework': [[]]}, True, canUnicode=False)
    sheet = pe.Sheet(tabularData['OSRFramework'])
    sheet.name = (('Profiles recovered (' + getCurrentStrDatetime()) + ').')
    sheet.name_columns_by_row(0)
    text.TABLEFMT = 'grid'
    try:
        with open(fPath, 'w') as oF:
            oF.write(str(sheet))
    except Exception as e:
        return unicode(sheet)

Workaround to export to a .txt file or to show the information.

Args:
-----
d: Data to export.
fPath: File path for the output file. If None was provided, it will
assume that it has to print it.

Returns:
--------
unicode: It sometimes returns a unicode representation of the Sheet
received.


def _populate_from_repo(self, example: Example):
    path = Path(example.filepath)
    example_folder = path.parent
    log_file_path = example_folder / self.LOGS_FILENAME
    if log_file_path.exists():
        example.logs = log_file_path.read_text()
    graph_file_path = example_folder / self.GRAPH_FILENAME
    if graph_file_path.exists():
        example.graph = graph_file_path.read_text()
    output_file_path = example_folder / self.OUTPUT_FILENAME
    if output_file_path.exists():
        example.output = output_file_path.read_text()
    compile_output_file_path = example_folder / self.COMPILE_OUTPUT_FILENAME
    if compile_output_file_path.exists():
        example.compile_output = compile_output_file_path.read_text()

Populate fields of the example reading them from the repository.
Args:
example: beam example that should be verified


def ParseFileDownloadedRow(
      self, parser_mediator, query, row, **unused_kwargs):

    query_hash = hash(query)

    event_data = ChromeHistoryFileDownloadedEventData()
    event_data.full_path = self._GetRowValue(query_hash, row, 'target_path')
    event_data.offset = self._GetRowValue(query_hash, row, 'id')
    event_data.query = query
    event_data.received_bytes = self._GetRowValue(
        query_hash, row, 'received_bytes')
    event_data.total_bytes = self._GetRowValue(query_hash, row, 'total_bytes')
    event_data.url = self._GetRowValue(query_hash, row, 'url')

    timestamp = self._GetRowValue(query_hash, row, 'start_time')
    date_time = dfdatetime_webkit_time.WebKitTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_FILE_DOWNLOADED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a file downloaded row.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row.


def _torch_extract_fbank_features(self, waveform: 'torch.FloatTensor', audio_lengths: 'torch.Tensor', device: str='cpu') -> 'torch.FloatTensor':
    fft_window = torch.hamming_window(self.win_length, periodic=False, device=device, dtype=torch.float64)
    batch_size = waveform.shape[0]
    frames = waveform.unfold(-1, self.win_length, self.hop_length)
    if batch_size > 1:
        frames = frames.clone()
        to_mask_batch_idxs = torch.arange(batch_size)[audio_lengths != audio_lengths.max()]
        if to_mask_batch_idxs.numel() > 0:
            batch_idxs_down = (audio_lengths[to_mask_batch_idxs] - self.win_length)
            batch_idxs_up = audio_lengths[to_mask_batch_idxs]
            offset_idx = batch_idxs_down.min()
            max_idx = batch_idxs_up.max()
            mask = torch.arange(max_idx - offset_idx, device=device).expand(to_mask_batch_idxs.shape[0], -1)
            mask = ((batch_idxs_down - offset_idx).unsqueeze(1) <= mask) & (mask < (batch_idxs_up - offset_idx).unsqueeze(1))
            mask = mask.unsqueeze(-1).expand(-1, -1, self.win_length)
            masked_frames = frames[to_mask_batch_idxs, offset_idx:max_idx].masked_fill_(mask, 0)
            frames[to_mask_batch_idxs, offset_idx:max_idx] = masked_frames
    frames_prev = torch.roll(frames, 1, dims=-1)
    frames_prev[:, :, 0] = frames_prev[:, :, 1]
    frames = (frames - self.preemphasis * frames_prev) * 32768
    S = torch.fft.rfft(fft_window * frames.view(-1, self.win_length), n=self.n_fft, dim=1)
    S = S.view(frames.shape[0], -1, S.shape[-1])
    S = S.to(torch.complex64)
    spec = torch.abs(S)
    spec_power = spec ** 2
    mel_filters = torch.from_numpy(self.mel_filters).to(device, torch.float32)
    log_spec = torch.clamp(spec_power @ mel_filters, min=1.0)
    log_spec = torch.log(log_spec)
    return log_spec

Compute the log mel-scaled spectrogram of batched waveforms using PyTorch's FFT implementation.

Args:
waveform (torch.FloatTensor` of shape `(batch_size, max_audio_length)`):
The batched waveforms.
audio_lengths (`torch.Tensor` of shape `(batch_size,)`):
The lengths of the waveforms along the max_audio_length dimension.
device (`str`, *optional*, defaults to "cpu"):
The device to run the computation on. (e.g., "cpu", "cuda")

Returns:
`torch.FloatTensor` of shape `(batch_size, max_feature_length, feature_size)`:
The log mel-scaled spectrogram of the batched waveforms.


def detect_alias_config_change(self):
    if self.parse_error():
        return False
    alias_config_sha1 = hashlib.sha1(self.alias_config_str.encode('utf-8')).hexdigest()
    if (alias_config_sha1 != self.alias_config_hash):
        self.alias_config_hash = alias_config_sha1
        return True
    return False

Change if the alias configuration has changed since the last run.

Returns:
False if the alias configuration file has not been changed since the last run.
Otherwise, return True.


def while_loop(cond_fn, body_fn, inputs, num_loop_vars=None, has_accumulators=False, **kwargs):
    if (num_loop_vars is None):
        return WhileLoopOperation(cond_fn, body_fn, inputs, tf_kwargs=kwargs, has_accumulators=has_accumulators).outputs
    assert (num_loop_vars > 0)
    extra_inputs = inputs[num_loop_vars:]
    my_vars = []
    for (i, x) in enumerate(extra_inputs):
        my_vars.append(get_variable(x.mesh, ('loop_var_%d' % i), x.shape, initializer=tf.zeros_initializer(), dtype=x.dtype, collections=[tf.GraphKeys.LOCAL_VARIABLES]))
    my_vars = tuple(my_vars)
    first_input = depend(inputs[0], [assign(var, x) for (var, x) in zip(my_vars, extra_inputs)])
    inputs = ([first_input] + inputs[1:num_loop_vars])

    def my_cond_fn(*inputs):
        return cond_fn(*(inputs + my_vars))

    def my_body_fn(*inputs):
        outputs = tuple(body_fn(*(inputs + my_vars)))
        extra_outputs = outputs[num_loop_vars:]
        first_output = depend(outputs[0], [assign(var, x) for (var, x) in zip(my_vars, extra_outputs)])
        outputs = ((first_output,) + outputs[1:num_loop_vars])
        return outputs
    return WhileLoopOperation(my_cond_fn, my_body_fn, inputs, tf_kwargs=kwargs, has_accumulators=has_accumulators).outputs

While Loop.

See comments above for WhileLoopOperation

num_loop_vars is a hack for the multi-gpu setup.  In this case, loops
are generally slow, as all loop variables are placed on device.  By setting
num_loop_vars=k, then all of the loop variables except for the first k
are handled as mtf Variables instead of loop variables, using explicit
updates and control dependencies.  In this case, we only return the
first num_loop_vars outputs.  Do not use this option on TPU, since it
is unnecessary and also produces incorrect results, since xla does not
respect control dependencies.

Args:
cond_fn: a function from n Tensors to scalar boolean Tensor
body_fn: a function from n Tensors to list of n Tensors
inputs: a list of n Tensors
num_loop_vars: an optional integer.
has_accumulators: a boolean
**kwargs: additional kwargs passed to tf.while_loop

Returns:
a list of n Tensors.


def is_distributed(partition_column, lower_bound, upper_bound):

    if (
        (partition_column is not None)
        and (lower_bound is not None)
        and (upper_bound is not None)
    ):
        if upper_bound > lower_bound:
            return True
        else:
            raise InvalidArguments("upper_bound must be greater than lower_bound.")
    elif (partition_column is None) and (lower_bound is None) and (upper_bound is None):
        return False
    else:
        raise InvalidArguments(
            "Invalid combination of partition_column, lower_bound, upper_bound."
            "All these arguments should be passed (distributed) or none of them (standard pandas)."
        )

Check if is possible distribute a query given that args

Args:
partition_column: column used to share the data between the workers
lower_bound: the minimum value to be requested from the partition_column
upper_bound: the maximum value to be requested from the partition_column

Returns:
True for distributed or False if not


def experimental_write_bytecode(filename, mlir_txt):
    pywrap_mlir.experimental_write_bytecode(filename, mlir_txt)

Writes an MLIR module out as bytecode.

Args:
filename: The filename to write to.
mlir_txt: The MLIR module in textual format.


def read_gold_standard_file(data_dir, fileroot, encoding=None, cetr=False):
    fname = os.path.join(data_dir, GOLD_STANDARD_DIRNAME, (fileroot + GOLD_STANDARD_EXT))
    encodings = ((encoding,) if encoding else ('utf-8', 'utf-16', 'iso-8859-1'))
    for encoding in encodings:
        try:
            with io.open(fname, mode='rt', encoding=encoding) as f:
                gold_standard = f.read()
            break
        except (UnicodeDecodeError, UnicodeError):
            gold_standard = None
    if (not gold_standard):
        return [u'', u'']
    if (not cetr):
        content_comments = RE_COMMENTS_DELIM.split(gold_standard, maxsplit=1)
        if (len(content_comments) == 1):
            content_comments = [content_comments[0], u'']
    else:
        tree = etree.fromstring(gold_standard, parser=etree.HTMLParser())
        content_comments = [u' '.join(text_from_subtree(tree)), u'']
    content_comments = [ftfy.fix_encoding(content_comments[0]).strip(), ftfy.fix_encoding(content_comments[1]).strip()]
    return content_comments

Read the gold standard content file corresponding to identifier ``fileroot``
in the gold standard directory below the root ``data_dir``.

Args:
data_dir (str)
fileroot (str)
encoding (str)
cetr (bool): if True, assume no comments and parse the gold standard
to remove tags

Returns:
List[str, str]: contents string and comments string, respectively


def AsJsonString(self):
    return json.dumps(self.AsDict(dt=False), sort_keys=True)

A JSON string representation of this User instance.

Returns:
A JSON string representation of this User instance


def local_symbol_table(imports=None, symbols=()):

    return SymbolTable(
        table_type=LOCAL_TABLE_TYPE,
        symbols=symbols,
        imports=imports
    )

Constructs a local symbol table.

Args:
imports (Optional[SymbolTable]): Shared symbol tables to import.
symbols (Optional[Iterable[Unicode]]): Initial local symbols to add.

Returns:
SymbolTable: A mutable local symbol table with the seeded local symbols.


def print_tools(self, buf=sys.stdout, verbose=False, context_name=None):

        def _get_row(entry):
            context_name_ = entry["context_name"]
            tool_alias = entry["tool_alias"]
            tool_name = entry["tool_name"]
            properties = []
            col = None

            variant = entry["variant"]
            if isinstance(variant, set):
                properties.append("(in conflict)")
                col = critical
                if verbose:
                    package = ", ".join(x.qualified_package_name for x in variant)
                else:
                    v = iter(variant).next()
                    package = "%s (+%d more)" % (v.qualified_package_name,
                                                 len(variant) - 1)
            else:
                package = variant.qualified_package_name

            if tool_name == tool_alias:
                tool_name = "-"
            else:
                properties.append("(aliased)")
                if col is None:
                    col = alias_col

            msg = " ".join(properties)
            row = [tool_alias, tool_name, package, context_name_, msg]
            return row, col

        if context_name:
            self._context(context_name)
            context_names = [context_name]
        else:
            context_names = sorted(self.contexts.iterkeys())

        rows = [["TOOL", "ALIASING", "PACKAGE", "CONTEXT", ""],
                ["----", "--------", "-------", "-------", ""]]
        colors = [None, None]

        entries_dict = defaultdict(list)
        for d in self.get_tools().itervalues():
            entries_dict[d["context_name"]].append(d)

        if verbose:

            for d in self.hidden_tools:
                d_ = d.copy()
                d_["hidden"] = True
                entries_dict[d["context_name"]].append(d_)

            for docs in self.tool_conflicts.itervalues():
                for d in docs:
                    d_ = d.copy()
                    d_["conflicting"] = True
                    entries_dict[d["context_name"]].append(d_)

        for i, context_name in enumerate(context_names):
            entries = entries_dict.get(context_name, [])
            if entries:
                if i:
                    rows.append(('', '', '', '', ''))
                    colors.append(None)

                entries = sorted(entries, key=lambda x: x["tool_alias"].lower())
                for entry in entries:
                    row, col = _get_row(entry)
                    if "hidden" in entry:
                        row[-1] = "(hidden)"
                        rows.append(row)
                        colors.append(warning)
                    elif "conflicting" in entry:
                        row[-1] = "(not visible)"
                        rows.append(row)
                        colors.append(warning)
                    else:
                        rows.append(row)
                        colors.append(col)

        if rows:
            _pr = Printer(buf)
            for col, line in zip(colors, columnise(rows)):
                _pr(line, col)
        else:
            _pr("No tools available.")

Print table of tools available in the suite.

Args:
context_name (str): If provided, only print the tools from this
context.


def parse_section_links(self, section_title):
    soup = BeautifulSoup(self.html, 'html.parser')
    headlines = soup.find_all('span', {'class': 'mw-headline'})
    tmp_soup = BeautifulSoup(section_title, 'html.parser')
    tmp_sec_title = tmp_soup.get_text().lower()
    id_tag = None
    for headline in headlines:
        tmp_id = headline.text
        if (tmp_id.lower() == tmp_sec_title):
            id_tag = headline.get('id')
            break
    if (id_tag is not None):
        return self._parse_section_links(id_tag)
    return None

Parse all links within a section

Args:
section_title (str): Name of the section to pull
Returns:
list: List of (title, url) tuples
Note:
Returns **None** if section title is not found
Note:
Side effect is to also pull the html which can be slow
Note:
This is a parsing operation and not part of the standard API


def _filter_returned_ops(fn):
    returned_ops = {}

    def wrap_and_filter_returned_ops(*args, **kwargs):
        outputs = fn(*args, **kwargs)
        flat_outputs = nest.flatten(outputs)
        for n in range(len(flat_outputs)):
            output = flat_outputs[n]
            if isinstance(output, ops.Operation):
                returned_ops[n] = output
                flat_outputs[n] = None
        return nest.pack_sequence_as(outputs, flat_outputs)
    return (wrap_and_filter_returned_ops, returned_ops)

Filtering out any ops returned by function.

Args:
fn: a function

Returns:
A tuple of (
Wrapped function that returns `None` in place of any ops,
dict that maps the index in the flat output structure to the returned op
)


def seek(self, n):
    if (self._mode != 'r'):
        raise UnsupportedOperation("not available in 'w' mode")
    if (0 <= n < self._nb_markers):
        self._n = n
        self._bed.seek(self._get_seek_position(n))
    else:
        raise ValueError('invalid position in BED: {}'.format(n))

Gets to a certain marker position in the BED file.

Args:
n (int): The index of the marker to seek to.


def receive(self, sequence, args):

        if not self._reorder:
            self._callback(*args)
            return

        if self._next_expected is not None and sequence < self._next_expected:
            print("Dropping out of order packet, seq=%d" % sequence)
            return

        self._out_of_order.append((sequence, args))
        self._out_of_order.sort(key=lambda x: x[0])

        while len(self._out_of_order) > 0:
            seq, args = self._out_of_order[0]

            if self._next_expected is not None and seq != self._next_expected:
                return

            self._callback(*args)
            self._out_of_order.pop(0)
            self._next_expected = seq+1

Receive one packet

If the sequence number is one we've already seen before, it is dropped.

If it is not the next expected sequence number, it is put into the
_out_of_order queue to be processed once the holes in sequence number
are filled in.

Args:
sequence (int): The sequence number of the received packet
args (list): The list of packet contents that will be passed to callback
as callback(*args)


def depth(self):
    if (self._depth_cache is not None):
        return self._depth_cache
    (depth, node) = (1, self)
    while (node.package is not None):
        depth += 1
        node = node.package
    self._depth_cache = depth
    return depth

Property to tell the depth of the node in the tree.

Returns:
int: the node's depth in the tree.


def _update_exit_code_from_error(self, error):

        for error_type, exit_code in self.ERROR_CODE_MAP.items():
            if isinstance(error, error_type):
                self.update_exit_code(exit_code)
                break
        else:
            self.update_exit_code(ExitStatus.generic_error)

Set the exit code based on the error type.

Args:
error (:class:`Exception`): An exception instance.


async def send_heartbeat(self, name):

        await self.send_command(OPERATIONS.CMD_HEARTBEAT, {'name': name},
                                MESSAGES.HeartbeatResponse, timeout=5.0)

Send a heartbeat for a service.

Args:
name (string): The name of the service to send a heartbeat for


def _checkMode(mode):

    if not isinstance(mode, str):
        raise TypeError('The {0} should be a string. Given: {1!r}'.format("mode", mode))

    if mode not in [MODE_RTU, MODE_ASCII]:
        raise ValueError("Unreconized Modbus mode given. Must be 'rtu' or 'ascii' but {0!r} was given.".format(mode))

Check that the Modbus mode is valie.

Args:
mode (string): The Modbus mode (MODE_RTU or MODE_ASCII)

Raises:
TypeError, ValueError


def _get_bonds(self, mol):
    num_atoms = len(mol)
    if self.ignore_ionic_bond:
        covalent_atoms = [i for i in range(num_atoms) if (mol.species[i].symbol not in self.ionic_element_list)]
    else:
        covalent_atoms = list(range(num_atoms))
    all_pairs = list(itertools.combinations(covalent_atoms, 2))
    pair_dists = [mol.get_distance(*p) for p in all_pairs]
    elements = mol.composition.as_dict().keys()
    unavailable_elements = list((set(elements) - set(self.covalent_radius.keys())))
    if (len(unavailable_elements) > 0):
        raise ValueError('The covalent radius for element {} is not available'.format(unavailable_elements))
    bond_13 = self.get_13_bonds(self.priority_bonds)
    max_length = [(((self.covalent_radius[mol.sites[p[0]].specie.symbol] + self.covalent_radius[mol.sites[p[1]].specie.symbol]) * (1 + (self.priority_cap if (p in self.priority_bonds) else (self.bond_length_cap if (p not in bond_13) else self.bond_13_cap)))) * (0.1 if (self.ignore_halogen_self_bond and (p not in self.priority_bonds) and (mol.sites[p[0]].specie.symbol in self.halogen_list) and (mol.sites[p[1]].specie.symbol in self.halogen_list)) else 1.0)) for p in all_pairs]
    bonds = [bond for (bond, dist, cap) in zip(all_pairs, pair_dists, max_length) if (dist <= cap)]
    return bonds

Find all the bond in a molcule

Args:
mol: the molecule. pymatgen Molecule object

Returns:
List of tuple. Each tuple correspond to a bond represented by the
id of the two end atoms.


def VerifyStructure(self, parser_mediator, line):

    self._line_structures = self.LINE_STRUCTURES

    self._day_of_month = None
    self._month = None
    self._year = None

    if self._SIGNATURE in line:
      return True

    return False

Verify that this file is an IIS log file.

Args:
parser_mediator (ParserMediator): mediates interactions between
parsers and other components, such as storage and dfvfs.
line (str): line from a text file.

Returns:
bool: True if the line was successfully parsed.


def _powerset(iterable):
    s = list(iterable)
    return itertools.chain.from_iterable((itertools.combinations(s, r) for r in range(len(s) + 1)))

Helper for generating all possible reduction_axes arguments.

Example: powerset([0,1,2]): () (0,) (1,) (2,) (0,1) (0,2) (1,2) (0,1,2)

Args:
iterable: An iterable of items to generate the powerset of.

Returns:
The powerset of all items in iterable.


def get_hash(self):
    if (self._hash is None):
        self._hash = self._source.get_hash(self._handle).strip()
    return self._hash

Returns the associated hash for this template version

Returns:
str: Hash for this version


def relu_layer(x, weights, biases, name=None):
    with ops.name_scope(name, 'relu_layer', [x, weights, biases]) as name:
        x = ops.convert_to_tensor(x, name='x')
        weights = ops.convert_to_tensor(weights, name='weights')
        biases = ops.convert_to_tensor(biases, name='biases')
        xw_plus_b = nn_ops.bias_add(math_ops.matmul(x, weights), biases)
        return nn_ops.relu(xw_plus_b, name=name)

Computes Relu(x * weight + biases).

Args:
x: a 2D tensor.  Dimensions typically: batch, in_units
weights: a 2D tensor.  Dimensions typically: in_units, out_units
biases: a 1D tensor.  Dimensions: out_units
name: A name for the operation (optional).  If not specified
"nn_relu_layer" is used.

Returns:
A 2-D Tensor computing relu(matmul(x, weights) + biases).
Dimensions typically: batch, out_units.


def run_op_benchmark(self, op, iters=1, warmup=True, session_config=None):
    if context.executing_eagerly():
        return self._run_eager_benchmark(iterable=op, iters=iters, warmup=warmup)
    return self._run_graph_benchmark(iterable=op, iters=iters, warmup=warmup, session_config=session_config)

Benchmarks the op.

Runs the op `iters` times. In each iteration, the benchmark measures
the time it takes to go execute the op.

Args:
op: The tf op to benchmark.
iters: Number of times to repeat the timing.
warmup: If true, warms up the session caches by running an untimed run.
session_config: A ConfigProto protocol buffer with configuration options
for the session. Applicable only for benchmarking in graph mode.

Returns:
A float, representing the per-execution wall time of the op in seconds.
This is the median time (with respect to `iters`) it takes for the op
to be executed `iters` num of times.


def _create_variables(self, num_clusters):
    init_value = array_ops.placeholder_with_default([], shape=None)
    cluster_centers = variable_v1.VariableV1(init_value, name=CLUSTERS_VAR_NAME, validate_shape=False)
    cluster_centers_initialized = variable_v1.VariableV1(False, dtype=dtypes.bool, name='initialized')
    if self._use_mini_batch and self._mini_batch_steps_per_iteration > 1:
        cluster_centers_updated = variable_v1.VariableV1(init_value, name='clusters_updated', validate_shape=False)
        update_in_steps = variable_v1.VariableV1(self._mini_batch_steps_per_iteration, dtype=dtypes.int64, name='update_in_steps')
        cluster_counts = variable_v1.VariableV1(array_ops.zeros([num_clusters], dtype=dtypes.int64))
    else:
        cluster_centers_updated = cluster_centers
        update_in_steps = None
        cluster_counts = variable_v1.VariableV1(array_ops.ones([num_clusters], dtype=dtypes.int64)) if self._use_mini_batch else None
    return (cluster_centers, cluster_centers_initialized, cluster_counts, cluster_centers_updated, update_in_steps)

Creates variables.

Args:
num_clusters: an integer Tensor providing the number of clusters.

Returns:
Tuple with following elements:
- cluster_centers: a Tensor for storing cluster centers
- cluster_centers_initialized: bool Variable indicating whether clusters
are initialized.
- cluster_counts: a Tensor for storing counts of points assigned to this
cluster. This is used by mini-batch training.
- cluster_centers_updated: Tensor representing copy of cluster centers
that are updated every step.
- update_in_steps: numbers of steps left before we sync
cluster_centers_updated back to cluster_centers.


def _source_is_newer(src_fs, src_path, dst_fs, dst_path):
    try:
        if dst_fs.exists(dst_path):
            namespace = ('details', 'modified')
            src_modified = src_fs.getinfo(src_path, namespace).modified
            if (src_modified is not None):
                dst_modified = dst_fs.getinfo(dst_path, namespace).modified
                return ((dst_modified is None) or (src_modified > dst_modified))
        return True
    except FSError:
        return True

Determine if source file is newer than destination file.

Arguments:
src_fs (FS): Source filesystem (instance or URL).
src_path (str): Path to a file on the source filesystem.
dst_fs (FS): Destination filesystem (instance or URL).
dst_path (str): Path to a file on the destination filesystem.

Returns:
bool: `True` if the source file is newer than the destination
file or file modification time cannot be determined, `False`
otherwise.


def get_config(self):
    all_args = tf_inspect.getfullargspec(self.__init__).args
    config = {'name': self.name, 'trainable': self.trainable}
    if hasattr(self, '_batch_input_shape'):
        config['batch_input_shape'] = self._batch_input_shape
    config['dtype'] = policy.serialize(self._dtype_policy)
    if hasattr(self, 'dynamic'):
        if self.dynamic:
            config['dynamic'] = self.dynamic
        elif 'dynamic' in all_args:
            all_args.remove('dynamic')
    expected_args = config.keys()
    extra_args = [arg for arg in all_args if arg not in expected_args]
    if len(extra_args) > 1 and hasattr(self.get_config, '_is_default'):
        raise NotImplementedError('Layer %s has arguments in `__init__` and therefore must override `get_config`.' % self.__class__.__name__)
    return config

Returns the config of the layer.

A layer config is a Python dictionary (serializable)
containing the configuration of a layer.
The same layer can be reinstantiated later
(without its trained weights) from this configuration.

The config of a layer does not include connectivity
information, nor the layer class name. These are handled
by `Network` (one layer of abstraction above).

Note that `get_config()` does not guarantee to return a fresh copy of dict
every time it is called. The callers should make a copy of the returned dict
if they want to modify it.

Returns:
Python dictionary.


async def import_image(self, data, stream: bool=False):
    headers = {'Content-Type': 'application/x-tar'}
    response = (await self.docker._query_chunked_post('images/load', 'POST', data=data, headers=headers))
    return (await json_stream_result(response, stream=stream))

Import tarball of image to docker.

Args:
data: tarball data of image to be imported

Returns:
Tarball of the image


def initialize_or_restore(self, session=None):
    if context.executing_eagerly():
        return
    if session is None:
        session = get_session()
    trackable_objects = util.list_objects(self._object_graph_view)
    initializers = [c.initializer for c in trackable_objects if hasattr(c, 'initializer') and c.initializer is not None and (getattr(c, '_update_uid', self._restore_uid - 1) < self._restore_uid)]
    session.run(initializers)

Runs initialization ops for variables.

Objects which would be saved by `Saver.save` will be initialized, unless
those variables are being restored by a later call to
`tf.train.Checkpoint.restore()`.

This method does nothing when executing eagerly (initializers get run
eagerly).

Args:
session: The session to run initialization ops in. If `None`, uses the
default session.


def handle_run_exception(self, pipeline_key, pipeline_func, e):

    if isinstance(e, Retry):
      retry_message = str(e)
      logging.warning('User forced retry for pipeline ID "%s" of %r: %s',
                      pipeline_key.name(), pipeline_func, retry_message)
      self.transition_retry(pipeline_key, retry_message)
    elif isinstance(e, Abort):
      abort_message = str(e)
      logging.warning('User forced abort for pipeline ID "%s" of %r: %s',
                      pipeline_key.name(), pipeline_func, abort_message)
      pipeline_func.abort(abort_message)
    else:
      retry_message = '%s: %s' % (e.__class__.__name__, str(e))
      logging.exception('Generator %r
                        pipeline_func, pipeline_key.name(), retry_message)
      self.transition_retry(pipeline_key, retry_message)

    return pipeline_func.task_retry

Handles an exception raised by a Pipeline's user code.

Args:
pipeline_key: The pipeline that raised the error.
pipeline_func: The class path name of the Pipeline that was running.
e: The exception that was raised.

Returns:
True if the exception should be re-raised up through the calling stack
by the caller of this method.


def create_dir(path):

    full_path = abs_path(path)
    if not os.path.exists(full_path):
        try:
            os.makedirs(full_path)
        except OSError as e:

            if e.errno != os.errno.EEXIST:
                raise

Creates a directory if it does not exist already.

Args:
path: The path of the directory to create.


def process_event(self, event_name: str, data: dict) -> None:

        if event_name == "after_epoch":
            self.epochs_done = data["epochs_done"]
            self.batches_seen = data["batches_seen"]
            self.train_examples_seen = data["train_examples_seen"]
        return

Process event after epoch
Args:
event_name: whether event is send after epoch or batch.
Set of values: ``"after_epoch", "after_batch"``
data: event data (dictionary)

Returns:
None


def parse_transcripts(transcript_lines):
    LOG.info('Parsing transcripts')
    if isinstance(transcript_lines, DataFrame):
        transcripts = parse_ensembl_transcript_request(transcript_lines)
    else:
        transcripts = parse_ensembl_transcripts(transcript_lines)
    parsed_transcripts = {}
    for tx in transcripts:
        tx_id = tx['ensembl_transcript_id']
        ens_gene_id = tx['ensembl_gene_id']
        if (not (tx_id in parsed_transcripts)):
            tx_info = {'chrom': tx['chrom'], 'transcript_start': tx['transcript_start'], 'transcript_end': tx['transcript_end'], 'mrna': set(), 'mrna_predicted': set(), 'nc_rna': set(), 'ensembl_gene_id': ens_gene_id, 'ensembl_transcript_id': tx_id}
            parsed_transcripts[tx_id] = tx_info
        tx_info = parsed_transcripts[tx_id]
        if tx.get('refseq_mrna_predicted'):
            tx_info['mrna_predicted'].add(tx['refseq_mrna_predicted'])
        if tx.get('refseq_mrna'):
            tx_info['mrna'].add(tx['refseq_mrna'])
        if tx.get('refseq_ncrna'):
            tx_info['nc_rna'].add(tx['refseq_ncrna'])
    return parsed_transcripts

Parse and massage the transcript information

There could be multiple lines with information about the same transcript.
This is why it is necessary to parse the transcripts first and then return a dictionary
where all information has been merged.

Args:
transcript_lines(): This could be an iterable with strings or a pandas.DataFrame

Returns:
parsed_transcripts(dict): Map from enstid -> transcript info


def compose_path(pub, uuid_url=False):
    if uuid_url:
        return join('/', UUID_DOWNLOAD_KEY, str(pub.uuid))
    return join('/', DOWNLOAD_KEY, basename(pub.file_pointer), basename(pub.filename))

Compose absolute path for given `pub`.

Args:
pub (obj): :class:`.DBPublication` instance.
uuid_url (bool, default False): Compose URL using UUID.

Returns:
str: Absolute url-path of the publication, without server's address \
and protocol.

Raises:
PrivatePublicationError: When the `pub` is private publication.


def feedforward(inputs, num_units, scope='multihead_attention'):
    with tf.variable_scope(scope):
        params = {'inputs': inputs, 'filters': num_units[0], 'kernel_size': 1, 'activation': tf.nn.relu, 'use_bias': True}
        outputs = tf.layers.conv1d(**params)
        params = {'inputs': outputs, 'filters': num_units[1], 'kernel_size': 1, 'activation': None, 'use_bias': True}
        outputs = tf.layers.conv1d(**params)
        outputs += inputs
        outputs = normalize(outputs)
    return outputs

Point-wise feed forward net.

Args:
inputs: A 3d tensor with shape of [N, T, C].
num_units: A list of two integers.
scope: Optional scope for `variable_scope`.
reuse: Boolean, whether to reuse the weights of a previous layer
by the same name.

Returns:
A 3d tensor with the same shape and dtype as inputs


def create_local_copy(self, effects=None, store=None):
    effects = self._build_effects(effects)
    store = (store or '')
    data = {'source': self.cdn_path(effects)}
    if store:
        data['store'] = store
    return rest_request('POST', 'files/', data=data)

Creates a Local File Copy on Uploadcare Storage.

Args:
- effects:
Adds CDN image effects. If ``self.default_effects`` property
is set effects will be combined with default effects.
- store:
If ``store`` option is set to False the copy of your file will
be deleted in 24 hour period after the upload.
Works only if `autostore` is enabled in the project.


def ParseFileObject(self, parser_mediator, file_object):

    file_size = file_object.get_size()

    file_header_map = self._GetDataTypeMap('rp_log_file_header')

    try:
      file_header, _ = self._ReadStructureFromFileObject(
          file_object, 0, file_header_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.UnableToParseFile(
          'Unable to parse file header with error: {0!s}'.format(
              exception))

    file_footer_map = self._GetDataTypeMap('rp_log_file_footer')

    file_footer_offset = file_size - file_footer_map.GetByteSize()

    try:
      file_footer, _ = self._ReadStructureFromFileObject(
          file_object, file_footer_offset, file_footer_map)
    except (ValueError, errors.ParseError) as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to parse file footer with error: {0!s}'.format(exception))
      return

    description = file_header.description.rstrip('\0')

    if file_footer.creation_time == 0:
      date_time = dfdatetime_semantic_time.SemanticTime('Not set')
    else:
      date_time = dfdatetime_filetime.Filetime(
          timestamp=file_footer.creation_time)

    event_data = RestorePointEventData()
    event_data.description = description
    event_data.restore_point_event_type = file_header.event_type
    event_data.restore_point_type = file_header.restore_point_type
    event_data.sequence_number = file_header.sequence_number

    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_CREATION)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a Windows Restore Point (rp.log) log file-like object.

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

Raises:
UnableToParseFile: when the file cannot be parsed.


def _maybe_name(obj) -> str:
    if obj is None:
        return 'None'
    elif hasattr(obj, 'name'):
        return obj.name
    else:
        return '<no name for %s>' % type(obj)

Returns object name if it has one, or a message otherwise.

This is useful for names that apper in error messages.
Args:
obj: Object to get the name of.
Returns:
name, "None", or a "no name" message.


def count(self) -> 'Builder':
    return self._to_builder(_evaluation.CountFunction(self.node.context, self.node, []))

The FHIRPath count() function.

Returns:
An expression that evaluates to the count of items in the parent.


def _generate_schedule(self, cpn_frequency, roll_convention):
    if self._first_coupon_date is None and self._penultimate_coupon_date is None:
        cpn_dates = dates.PeriodicSchedule(start_date=self._start_date, end_date=self._end_date, tenor=cpn_frequency, roll_convention=roll_convention).dates()
        is_regular_cpn = tf.constant(True, dtype=bool, shape=cpn_dates[:, :-1].shape)
    elif self._first_coupon_date is not None:
        cpn_dates = dates.PeriodicSchedule(start_date=self._first_coupon_date, end_date=self._end_date, tenor=cpn_frequency, roll_convention=roll_convention).dates()
        cpn_dates = dates.DateTensor.concat([self._start_date.expand_dims(-1), cpn_dates], axis=1)
        is_irregular_cpn = tf.constant(False, dtype=bool, shape=self._start_date.shape)
        is_regular_cpn = tf.concat([tf.expand_dims(is_irregular_cpn, axis=-1), tf.constant(True, dtype=bool, shape=cpn_dates[:, :-2].shape)], axis=1)
    else:
        cpn_dates = dates.PeriodicSchedule(start_date=self._start_date, end_date=self._penultimate_coupon_date, backward=True, tenor=cpn_frequency, roll_convention=roll_convention).dates()
        cpn_dates = dates.DateTensor.concat([cpn_dates, self._end_date.expand_dims(-1)], axis=1)
        is_irregular_cpn = tf.constant(False, dtype=bool, shape=self._end_date.shape)
        is_regular_cpn = tf.concat([tf.constant(True, dtype=bool, shape=cpn_dates[:, :-2].shape), tf.expand_dims(is_irregular_cpn, axis=-1)], axis=1)
    return (cpn_dates, is_regular_cpn)

Method to generate coupon dates.

Args:
cpn_frequency: A `PeriodTensor` specifying the frequency of coupon
payments.
roll_convention: Scalar of type `BusinessDayConvention` specifying how
dates are rolled if they fall on holidays.

Returns:
A tuple containing the generated date schedule and a boolean `Tensor`
of the same shape as the schedule specifying whether the coupons are
regular coupons.


def __init__(self, resolver_context):

    super(CPIOFile, self).__init__(resolver_context)
    self._cpio_archive_file = None
    self._cpio_archive_file_entry = None
    self._current_offset = 0
    self._file_system = None
    self._size = 0

Initializes a file-like object.

Args:
resolver_context (Context): resolver context.


def verify_profile_name(msg, cfg):
    if (msg.profile not in cfg.data):
        raise UnknownProfileError(msg.profile)

Verifies the profile name exists in the config.json file.

Args:
:msg: (Message class) an instance of a message class.
:cfg: (jsonconfig.Config) config instance.


def compute_bleu_summaries(hook_args):
    decode_hparams = hook_args.decode_hparams
    if (not (decode_hparams.decode_reference and decode_hparams.decode_to_file)):
        return None
    values = []
    bleu = (100 * bleu_hook.bleu_wrapper(decode_hparams.decode_reference, decode_hparams.decode_to_file))
    values.append(tf.Summary.Value(tag='BLEU', simple_value=bleu))
    tf.logging.info(('%s: BLEU = %6.2f' % (decode_hparams.decode_to_file, bleu)))
    if hook_args.hparams.mlperf_mode:
        current_step = decode_hparams.mlperf_decode_step
        mlperf_log.transformer_print(key=mlperf_log.EVAL_TARGET, value=decode_hparams.mlperf_threshold)
        mlperf_log.transformer_print(key=mlperf_log.EVAL_ACCURACY, value={'epoch': max(((current_step
        mlperf_log.transformer_print(key=mlperf_log.EVAL_STOP)
    if (bleu >= decode_hparams.mlperf_threshold):
        decode_hparams.set_hparam('mlperf_success', True)
    return values

Compute BLEU core summaries using the decoder output.

Args:
hook_args: DecodeHookArgs namedtuple
Returns:
A list of tf.Summary values if hook_args.hparams contains the
reference file and the translated file.


def from_api_repr(cls, resource):

        ref = cls()
        ref._proto = json_format.ParseDict(resource, types.ModelReference())
        return ref

Factory:  construct a model reference given its API representation

Args:
resource (Dict[str, object]):
Model reference representation returned from the API

Returns:
google.cloud.bigquery.model.ModelReference:
Model reference parsed from ``resource``.


def single_qubit_matrix_to_phased_x_z(mat: np.ndarray, atol: float=0) -> List[ops.SingleQubitGate]:
    (xy_turn, xy_phase_turn, total_z_turn) = _deconstruct_single_qubit_matrix_into_gate_turns(mat)
    result = [ops.PhasedXPowGate(exponent=(2 * xy_turn), phase_exponent=(2 * xy_phase_turn)), (ops.Z ** (2 * total_z_turn))]
    result = [g for g in result if (protocols.trace_distance_bound(g) > atol)]
    if ((len(result) == 2) and (abs(xy_turn) >= (0.5 - atol))):
        return [ops.PhasedXPowGate(phase_exponent=((2 * xy_phase_turn) + total_z_turn))]
    return result

Implements a single-qubit operation with a PhasedX and Z gate.

If one of the gates isn't needed, it will be omitted.

Args:
mat: The 2x2 unitary matrix of the operation to implement.
atol: A limit on the amount of error introduced by the
construction.

Returns:
A list of gates that, when applied in order, perform the desired
operation.


def interface_required(interface):

    def _interface_required(func):
        'Internal decorator that wraps around the decorated function.\n\n            Args:\n              func (function): function being decorated\n\n            Returns:\n              The wrapper function.\n            '

        @functools.wraps(func)
        def wrapper(self, *args, **kwargs):
            'Wrapper function to check that the given ``JLink`` has the\n                same interface as the one specified by the decorator.\n\n                Args:\n                  self (JLink): the ``JLink`` instance\n                  args: list of arguments to pass to ``func``\n                  kwargs: key-word arguments dict to pass to ``func``\n\n                Returns:\n                  The return value of the wrapped function.\n\n                Raises:\n                  JLinkException: if the current interface is not supported by\n                      the wrapped method.\n                '
            if (self.tif != interface):
                raise errors.JLinkException('Unsupported for current interface.')
            return func(self, *args, **kwargs)
        return wrapper
    return _interface_required

Decorator to specify that a particular interface type is required
for the given method to be used.

Args:
interface (int): attribute of ``JLinkInterfaces``

Returns:
A decorator function.


def write(self):
    none_type = type(None)
    attrs = self.attribute_string()
    for attr in self.__dict__.keys():
        if (type(attr) == none_type):
            setattr(self, attr, '.')
    fstr = '{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}{9}'.format(self.seqid, self.source, self.type, str(self.start), str(self.end), self._score_str, self.strand, self.phase, attrs, os.linesep)
    return fstr

Restore GFF3 entry to original format

Returns:
str: properly formatted string containing the GFF3 entry


def find_template_filename(self, template_name):

        def next_file():
            filename = self.path / template_name
            yield filename
            try:
                exts = self.default_file_extensions
            except AttributeError:
                return

            strfilename = str(filename)
            for ext in exts:
                yield Path(strfilename + ext)

        for filename in next_file():
            if filename.is_file():
                return filename

Searches for a file matching the given template name.

If found, this method returns the pathlib.Path object of the found
template file.

Args:
template_name (str): Name of the template, with or without a file
extension.

Returns:
pathlib.Path: Path to the matching filename.


def configs_for_writer(writer=None, ppp_config_dir=None):
    search_paths = ((ppp_config_dir,) if ppp_config_dir else tuple())
    if (writer is not None):
        if (not isinstance(writer, (list, tuple))):
            writer = [writer]
        config_files = [(w if w.endswith('.yaml') else (w + '.yaml')) for w in writer]
    else:
        writer_configs = glob_config(os.path.join('writers', '*.yaml'), *search_paths)
        config_files = set(writer_configs)
    for config_file in config_files:
        config_basename = os.path.basename(config_file)
        writer_configs = config_search_paths(os.path.join('writers', config_basename), *search_paths)
        if (not writer_configs):
            LOG.warning("No writer configs found for '%s'", writer)
            continue
        (yield writer_configs)

Generator of writer configuration files for one or more writers

Args:
writer (Optional[str]): Yield configs only for this writer
ppp_config_dir (Optional[str]): Additional configuration directory
to search for writer configuration files.

Returns: Generator of lists of configuration files


def read_byte(self, do_ord=True) -> int:

        try:
            if do_ord:
                return ord(self.stream.read(1))
            else:
                return self.stream.read(1)
        except Exception as e:
            raise SDKException(ErrorCode.read_byte_error(e.args[0]))

Read a single byte.
Args:
do_ord (bool): (default True) convert the byte to an ordinal first.
Returns:
bytes: a single byte if successful. 0 (int) if an exception occurred.


def maybe_center_plot(result):

    begin = re.search('(% .* matplotlib2tikz v.*)', result)
    if begin:
        result = ('\\begin{center}\n' + result[begin.end():] +
                  '\n\\end{center}')
    return result

Embeds a possible tikz image inside a center environment.

Searches for matplotlib2tikz last commend line to detect tikz images.

Args:
result: The code execution result

Returns:
The input result if no tikzpicture was found, otherwise a centered
version.


def contains(self, x: int, y: int) -> bool:
    return ((self.x <= x < (self.x + self.width)) and (self.y <= y < (self.y + self.height)))

Returns True if this node contains these coordinates.

Args:
x (int): X position to check.
y (int): Y position to check.

Returns:
bool: True if this node contains these coordinates.
Otherwise False.


def add(self, selected: 'SelectedMailbox', *,
            replace: 'SelectedMailbox' = None) -> None:

        if replace is not None:
            self._set.discard(replace)
        self._set.add(selected)

Add a new selected mailbox object to the set, which may then be
returned by :meth:`.any_selected`.

Args:
selected: The new selected mailbox object.
replace: An existing selected mailbox object that should be removed
from the weak set.


def pkg_version_list(self, pkg_id):

        pkg_data = self.__reg_software.get(pkg_id, None)
        if not pkg_data:
            return []

        if isinstance(pkg_data, list):

            return pkg_data

        installed_versions = list(pkg_data.get('version').keys())
        return sorted(installed_versions, key=cmp_to_key(self.__oldest_to_latest_version))

Returns information on a package.

Args:
pkg_id (str): Package Id of the software/component.

Returns:
list: List of version numbers installed.


def __init__(self, dtypes, shapes, names, queue_ref):
    self._dtypes = dtypes
    if shapes is not None:
        if len(shapes) != len(dtypes):
            raise ValueError(f'Queue shapes must have the same length as dtypes, received len(shapes)={len(shapes)}, len(dtypes)={len(dtypes)}')
        self._shapes = [tensor_shape.TensorShape(s) for s in shapes]
    else:
        self._shapes = [tensor_shape.unknown_shape() for _ in self._dtypes]
    if names is not None:
        if len(names) != len(dtypes):
            raise ValueError(f'Queue names must have the same length as dtypes,received len(names)={len(names)},len {len(dtypes)}')
        self._names = names
    else:
        self._names = None
    self._queue_ref = queue_ref
    if isinstance(queue_ref, ops.EagerTensor):
        if context.context().scope_name:
            self._name = context.context().scope_name
        else:
            self._name = 'Empty'
        self._resource_deleter = resource_variable_ops.EagerResourceDeleter(queue_ref, None)
    else:
        self._name = self._queue_ref.op.name.split('/')[-1]

Constructs a queue object from a queue reference.

The two optional lists, `shapes` and `names`, must be of the same length
as `dtypes` if provided.  The values at a given index `i` indicate the
shape and name to use for the corresponding queue component in `dtypes`.

Args:
dtypes:  A list of types.  The length of dtypes must equal the number
of tensors in each element.
shapes: Constraints on the shapes of tensors in an element:
A list of shape tuples or None. This list is the same length
as dtypes.  If the shape of any tensors in the element are constrained,
all must be; shapes can be None if the shapes should not be constrained.
names: Optional list of names.  If provided, the `enqueue()` and
`dequeue()` methods will use dictionaries with these names as keys.
Must be None or a list or tuple of the same length as `dtypes`.
queue_ref: The queue reference, i.e. the output of the queue op.

Raises:
ValueError: If one of the arguments is invalid.


def waiting_config_state(self, timeout=300):

        t_start = time.time()
        while not self.check_config_state():
            if time.time() - t_start > timeout:
                return False
            time.sleep(0.1)
        return True

waiting while real state equal config state
Args:
timeout - specify how long, in seconds, a command can take before server times out.

return True if operation success otherwise False


def inputs_valid(self, outputs=None):
    if (self.operation == Transaction.CREATE):
        return self._inputs_valid(['dummyvalue' for _ in self.inputs])
    elif (self.operation == Transaction.TRANSFER):
        return self._inputs_valid([output.fulfillment.condition_uri for output in outputs])
    else:
        allowed_ops = ', '.join(self.__class__.ALLOWED_OPERATIONS)
        raise TypeError('`operation` must be one of {}'.format(allowed_ops))

Validates the Inputs in the Transaction against given
Outputs.

Note:
Given a `CREATE` Transaction is passed,
dummy values for Outputs are submitted for validation that
evaluate parts of the validation-checks to `True`.

Args:
outputs (:obj:`list` of :class:`~bigchaindb.common.
transaction.Output`): A list of Outputs to check the
Inputs against.

Returns:
bool: If all Inputs are valid.


def set_iterator_element_layouts(self, iterator_resource_dtensor, layouts: List[layout_lib.Layout]):
    _pywrap_dtensor_device.SetIteratorElementLayouts(context.context()._handle, iterator_resource_dtensor, [layout.to_string() for layout in layouts], self._device_info)

Sets the element layouts on an iterator resource tensor.

Args:
iterator_resource_dtensor: a DTensor created by packing the individiual
iterator resource tensors.
layouts: the flattened list of layouts to be applied to the elements
emitted by the iterator resource DTensor.


def encode(self, input_ids: jnp.ndarray, attention_mask: Optional[jnp.ndarray]=None, position_ids: Optional[jnp.ndarray]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, train: bool=False, params: Optional[dict]=None, dropout_rng: PRNGKey=None):
    output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
    output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    return_dict = return_dict if return_dict is not None else self.config.return_dict
    if attention_mask is None:
        attention_mask = jnp.ones_like(input_ids)
    if position_ids is None:
        batch_size, sequence_length = input_ids.shape
        position_ids = jnp.broadcast_to(jnp.arange(sequence_length)[None, :], (batch_size, sequence_length))
    rngs = {}
    if dropout_rng is not None:
        rngs['dropout'] = dropout_rng

    def _encoder_forward(module, input_ids, attention_mask, position_ids, **kwargs):
        encode_module = module._get_encoder_module()
        return encode_module(input_ids, attention_mask, position_ids, **kwargs)
    return self.module.apply({'params': params or self.params}, input_ids=jnp.array(input_ids, dtype='i4'), attention_mask=jnp.array(attention_mask, dtype='i4'), position_ids=jnp.array(position_ids, dtype='i4'), output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, deterministic=not train, rngs=rngs, method=_encoder_forward)

Returns:

Example:

```python
>>> from transformers import AutoTokenizer, FlaxMarianMTModel

>>> tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-de")
>>> model = FlaxMarianMTModel.from_pretrained("Helsinki-NLP/opus-mt-en-de")

>>> text = "My friends are cool but they eat too many carbs."
>>> inputs = tokenizer(text, max_length=64, return_tensors="jax")
>>> encoder_outputs = model.encode(**inputs)
```