def __getitem__(self, key):
    if key in self._policy_map:
        return self._policy_map[key]
    matching_keys = []
    for k in self._policy_map:
        if re.search(k, key):
            matching_keys.append(k)
    if len(matching_keys) > 1:
        raise ValueError(f"Path '{key}' matches multiple dtype policy specification keys: {matching_keys}. Please make sure each path only matches at most one dtype policy specification key in the DTypePolicyMap.")
    elif len(matching_keys) == 1:
        return self._policy_map[matching_keys[0]]
    return self.default_policy

Retrieves the corresponding `DTypePolicy` by the string key.

When there isn't an exact match, all the existing keys in the map
will be treated as a regex and map against the input key again. When
there are multiple matches for the regex, an `ValueError` will be
raised. Returns `self.default_policy` if there isn't any match found.

Args:
key: String key to query a `DTypePolicy`.

Returns:
Corresponding `DTypePolicy` based on the query.


def frequency_to_probability(frequency_map, decorator=lambda f: f):

    total = sum(frequency_map.values())
    return {k: decorator(v / total) for k, v in frequency_map.items()}

Transform a ``frequency_map`` into a map of probability using the sum of all frequencies as the total.

Example:
>>> frequency_to_probability({'a': 2, 'b': 2})
{'a': 0.5, 'b': 0.5}

Args:
frequency_map (dict): The dictionary to transform
decorator (function): A function to manipulate the probability

Returns:
Dictionary of ngrams to probability


def start_new_feature(**cc_kwargs):
    project = Project.from_path(pathlib.Path.cwd().resolve())
    contrib_dir = project.get('contrib', 'module_path')
    with tempfile.TemporaryDirectory() as tempdir:
        output_dir = tempdir
        cc_kwargs['output_dir'] = output_dir
        rendered_dir = render_feature_template(**cc_kwargs)
        src = rendered_dir
        dst = contrib_dir
        synctree(src, dst, onexist=_fail_if_feature_exists)
    logger.info('Start new feature successful.')

Start a new feature within a ballet project

Renders the feature template into a temporary directory, then copies the
feature files into the proper path within the contrib directory.

Args:
**cc_kwargs: options for the cookiecutter template

Raises:
ballet.exc.BalletError: the new feature has the same name as an
existing one


def set_cc_opt_flags(environ_cp):
    if is_ppc64le():
        default_cc_opt_flags = '-mcpu=native'
    elif is_windows():
        default_cc_opt_flags = '/arch:AVX'
    else:
        default_cc_opt_flags = '-Wno-sign-compare'
    question = 'Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is %s]: ' % default_cc_opt_flags
    cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS', question, default_cc_opt_flags)
    for opt in cc_opt_flags.split():
        write_to_bazelrc('build:opt --copt=%s' % opt)
        write_to_bazelrc('build:opt --host_copt=%s' % opt)

Set up architecture-dependent optimization flags.

Also append CC optimization flags to bazel.rc..

Args:
environ_cp: copy of the os.environ.


def get_actual_replica(self, service_id: str) -> str:

        if not self._manager:
            raise RuntimeError('Only the Swarm manager node can retrieve '
                               'replication level of the service')

        service_details = self.get_service_details(service_id)
        actual_replica = service_details["Spec"]["Mode"][
            "Replicated"]["Replicas"]
        return actual_replica

Get the actual replica level of a service.

Args:
service_id (str): docker swarm service id

Returns:
str, replicated level of the service


def get_model_class_for_feature(feature: str, framework: str='pt') -> Type:
    task = FeaturesManager.feature_to_task(feature)
    FeaturesManager._validate_framework_choice(framework)
    if framework == 'pt':
        task_to_automodel = FeaturesManager._TASKS_TO_AUTOMODELS
    else:
        task_to_automodel = FeaturesManager._TASKS_TO_TF_AUTOMODELS
    if task not in task_to_automodel:
        raise KeyError(f'Unknown task: {feature}. Possible values are {list(FeaturesManager._TASKS_TO_AUTOMODELS.values())}')
    return task_to_automodel[task]

Attempts to retrieve an AutoModel class from a feature name.

Args:
feature (`str`):
The feature required.
framework (`str`, *optional*, defaults to `"pt"`):
The framework to use for the export.

Returns:
The AutoModel class corresponding to the feature.


def GetOutputDir(self, base_dir, config_filename):
    return os.path.join(base_dir, os.path.basename(config_filename.replace('.yaml', '')))

Add the repack config filename onto the base output directory.

This allows us to repack lots of different configs to the same installer
name and still be able to distinguish them.

Args:
base_dir: output directory string
config_filename: the secondary config filename string

Returns:
String to be used as output directory for this repack.


def SignBuffer(self, in_buffer):

    precondition.AssertType(in_buffer, bytes)
    with tempfile.NamedTemporaryFile() as temp_in:
      temp_in.write(in_buffer)
      temp_in.seek(0)
      outfile = self.SignFile(temp_in.name)
      with io.open(outfile, "rb") as filedesc:
        return filedesc.read()

Sign a buffer via temp files.

Our signing tool can't sign a buffer, so we work around it using temporary
files.

Args:
in_buffer: data to sign

Returns:
signed data


def FlagCxx11Features(filename, clean_lines, linenum, error):

  line = clean_lines.elided[linenum]

  include = Match(r'\s*
  if include and include.group(1) in ('cfenv',
                                      'condition_variable',
                                      'fenv.h',
                                      'future',
                                      'mutex',
                                      'thread',
                                      'chrono',
                                      'ratio',
                                      'regex',
                                      'system_error',
                                     ):
    error(filename, linenum, 'build/c++11', 5,
          ('<%s> is an unapproved C++11 header.') % include.group(1))

  if Match(r'\s*

  for top_name in (

      'alignment_of',
      'aligned_union',
      ):
    if Search(r'\bstd::%s\b' % top_name, line):
      error(filename, linenum, 'build/c++11', 5,
            ('std::%s is an unapproved C++11 class or function.  Send c-style '
             'an example of where it would make your code more readable, and '
             'they may let you use it.') % top_name)

Flag those c++11 features that we only allow in certain places.

Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found.


def _parse_name(self, config):
    value = NAME_RE.search(config).group('value')
    return dict(name=value)

_parse_name scans the provided configuration block and extracts
the vlan name.  The config block is expected to always return the
vlan name.  The return dict is intended to be merged into the response
dict.

Args:
config (str): The vlan configuration block from the nodes running
configuration

Returns:
dict: resource dict attribute


def read_probes(self, key):

        assert key in list(self._PROBES.keys())

        import random
        if key == 'value1':
            value = random.random()
        elif key == 'value2':
            value = self.settings['output probe2']
        elif key == 'internal':
            value = self._internal_state
        elif key == 'deep_internal':
            value = self._internal_state_deep

        return value

requestes value from the instrument and returns it
Args:
key: name of requested value

Returns: reads values from instrument


def handle_api_explorer_request(self, request, start_response):

    redirect_url = self._get_explorer_redirect_url(
        request.server, request.port, request.base_path)
    return util.send_wsgi_redirect_response(redirect_url, start_response)

Handler for requests to {base_path}/explorer.

This calls start_response and returns the response body.

Args:
request: An ApiRequest, the request from the user.
start_response: A function with semantics defined in PEP-333.

Returns:
A string containing the response body (which is empty, in this case).


def list_live_services(self):
    aliases = []
    self.for_each(lambda service: aliases.append(service.alias) if service.is_alive else None)
    return aliases

Lists the aliases of all the services that are alive.

Order of this list is determined by the order the services are
registered in.

Returns:
list of strings, the aliases of the services that are running.


def resize_bilinear_nd(t, target_shape):

  shape = t.get_shape().as_list()
  target_shape = list(target_shape)
  assert len(shape) == len(target_shape)

  d = 0
  while d < len(shape):

    if shape[d] == target_shape[d]:
      d += 1
      continue

    new_shape = shape[:]
    new_shape[d : d+2] = target_shape[d : d+2]

    shape_ = collapse_shape(shape, d, d+2)
    new_shape_ = collapse_shape(new_shape, d, d+2)

    t_ = tf.reshape(t, shape_)
    t_ = tf.image.resize_bilinear(t_, new_shape_[1:3])

    t = tf.reshape(t_, new_shape)
    shape = new_shape
    d += 2

  return t

Bilinear resizes a tensor t to have shape target_shape.

This function bilinearly resizes a n-dimensional tensor by iteratively
applying tf.image.resize_bilinear (which can only resize 2 dimensions).
For bilinear interpolation, the order in which it is applied does not matter.

Args:
t: tensor to be resized
target_shape: the desired shape of the new tensor.

Returns:
The resized tensor


def from_backbone_configs(cls, backbone_config: PretrainedConfig, **kwargs):
    return cls(backbone_config=backbone_config, **kwargs)

Instantiate a [`RTDetrV2Config`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.

Args:
backbone_config ([`PretrainedConfig`]):
The backbone configuration.

Returns:
[`RTDetrV2Config`]: An instance of a configuration object


def add_session_log(self, session_log, global_step=None):
    event = event_pb2.Event(session_log=session_log)
    self._add_event(event, global_step)

Adds a `SessionLog` protocol buffer to the event file.

This method wraps the provided session in an `Event` protocol buffer
and adds it to the event file.

Args:
session_log: A `SessionLog` protocol buffer.
global_step: Number. Optional global step value to record with the
summary.


def post_warning(self, name, message):

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

Asynchronously post a user facing warning message about a service.

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


def _readline(sock, buf):
    chunks = []
    last_char = b''
    while True:
        if ((last_char == b'\r') and (buf[0:1] == b'\n')):
            chunks[(- 1)] = chunks[(- 1)][:(- 1)]
            return (buf[1:], b''.join(chunks))
        elif (buf.find(b'\r\n') != (- 1)):
            (before, sep, after) = buf.partition(b'\r\n')
            chunks.append(before)
            return (after, b''.join(chunks))
        if buf:
            chunks.append(buf)
            last_char = buf[(- 1):]
        buf = _recv(sock, RECV_SIZE)
        if (not buf):
            raise MemcacheUnexpectedCloseError()

Read line of text from the socket.

Read a line of text (delimited by "\r\n") from the socket, and
return that line along with any trailing characters read from the
socket.

Args:
sock: Socket object, should be connected.
buf: String, zero or more characters, returned from an earlier
call to _readline or _readvalue (pass an empty string on the
first call).

Returns:
A tuple of (buf, line) where line is the full line read from the
socket (minus the "\r\n" characters) and buf is any trailing
characters read after the "\r\n" was found (which may be an empty
string).


def update_sub(x, decrement):
    return state_ops.assign_sub(x, decrement)

Update the value of `x` by subtracting `decrement`.

Args:
x: A Variable.
decrement: A tensor of same shape as `x`.

Returns:
The variable `x` updated.


class HungarianMatcher(nn.Module):

    def __init__(self, class_cost: float=1, bbox_cost: float=1, giou_cost: float=1):
        super().__init__()
        requires_backends(self, ['scipy'])
        self.class_cost = class_cost
        self.bbox_cost = bbox_cost
        self.giou_cost = giou_cost
        if class_cost == 0 and bbox_cost == 0 and (giou_cost == 0):
            raise ValueError("All costs of the Matcher can't be 0")

    @torch.no_grad()
    def forward(self, outputs, targets):

        batch_size, num_queries = outputs['logits'].shape[:2]
        out_prob = outputs['logits'].flatten(0, 1).softmax(-1)
        out_bbox = outputs['pred_boxes'].flatten(0, 1)
        target_ids = torch.cat([v['class_labels'] for v in targets])
        target_bbox = torch.cat([v['boxes'] for v in targets])
        class_cost = -out_prob[:, target_ids]
        bbox_cost = torch.cdist(out_bbox, target_bbox, p=1)
        giou_cost = -generalized_box_iou(center_to_corners_format(out_bbox), center_to_corners_format(target_bbox))
        cost_matrix = self.bbox_cost * bbox_cost + self.class_cost * class_cost + self.giou_cost * giou_cost
        cost_matrix = cost_matrix.view(batch_size, num_queries, -1).cpu()
        sizes = [len(v['boxes']) for v in targets]
        indices = [linear_sum_assignment(c[i]) for i, c in enumerate(cost_matrix.split(sizes, -1))]
        return [(torch.as_tensor(i, dtype=torch.int64), torch.as_tensor(j, dtype=torch.int64)) for i, j in indices]

This class computes an assignment between the targets and the predictions of the network.

For efficiency reasons, the targets don't include the no_object. Because of this, in general, there are more
predictions than targets. In this case, we do a 1-to-1 matching of the best predictions, while the others are
un-matched (and thus treated as non-objects).

Args:
class_cost:
The relative weight of the classification error in the matching cost.
bbox_cost:
The relative weight of the L1 error of the bounding box coordinates in the matching cost.
giou_cost:
The relative weight of the giou loss of the bounding box in the matching cost.


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

    query_hash = hash(query)
    was_http_non_get = self._GetRowValue(query_hash, row, 'http_non_get')

    event_data = SafariHistoryPageVisitedEventData()
    event_data.offset = self._GetRowValue(query_hash, row, 'id')
    event_data.query = query
    event_data.title = self._GetRowValue(query_hash, row, 'title')
    event_data.url = self._GetRowValue(query_hash, row, 'url')
    event_data.visit_count = self._GetRowValue(query_hash, row, 'visit_count')
    event_data.was_http_non_get = bool(was_http_non_get)

    timestamp = self._GetRowValue(query_hash, row, 'visit_time')
    date_time = dfdatetime_cocoa_time.CocoaTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_LAST_VISITED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a visited 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 get_shape(self) -> tensor_shape.TensorShape:
    return self.shape

The statically known shape of this ragged tensor.

Returns:
A `TensorShape` containing the statically known shape of this ragged
tensor.  Ragged dimensions have a size of `None`.

Alias for `shape` property.

Examples:

>>> tf.ragged.constant([[0], [1, 2]]).get_shape()
TensorShape([2, None])

>>> tf.ragged.constant(
...    [[[0, 1]], [[1, 2], [3, 4]]], ragged_rank=1).get_shape()
TensorShape([2, None, 2])


def get_file_path(self, digest):

        relPath = Fsdb.generate_tree_path(digest, self._conf['depth'])
        return os.path.join(self.fsdbRoot, relPath)

Retrieve the absolute path to the file with the given digest

Args:
digest -- digest of the file
Returns:
String rapresenting the absolute path of the file


def __init__(self, thunk):
    self._thunk = thunk
    self._master_tensor = thunk()

Initializes a _LazyEvalTensor object.

Args:
thunk: A callable. A thunk which computes the value of the tensor.


def take_while(predicate):

    def _apply_fn(dataset):
        return dataset.take_while(predicate=predicate)
    return _apply_fn

A transformation that stops dataset iteration based on a `predicate`.

Args:
predicate: A function that maps a nested structure of tensors (having shapes
and types defined by `self.output_shapes` and `self.output_types`) to a
scalar `tf.bool` tensor.

Returns:
A `Dataset` transformation function, which can be passed to
`tf.data.Dataset.apply`.


def bandit(self, choice_rewards):
    return max(choice_rewards, key=(lambda a: np.mean(choice_rewards[a])))

Return the choice to take next using multi-armed bandit

Multi-armed bandit method. Accepts a mapping of choices to rewards which indicate their
historical performance, and returns the choice that we should make next in order to
maximize expected reward in the long term.

The default implementation is to return the arm with the highest average score.

Args:
choice_rewards (Dict[object, List[float]]): maps choice IDs to lists of rewards.

Returns:
str: the name of the choice to take next.


def color_val(color):
    if is_str(color):
        return Color[color].value
    elif isinstance(color, Color):
        return color.value
    elif isinstance(color, tuple):
        assert (len(color) == 3)
        for channel in color:
            assert ((channel >= 0) and (channel <= 255))
        return color
    elif isinstance(color, int):
        assert ((color >= 0) and (color <= 255))
        return (color, color, color)
    elif isinstance(color, np.ndarray):
        assert ((color.ndim == 1) and (color.size == 3))
        assert np.all(((color >= 0) & (color <= 255)))
        color = color.astype(np.uint8)
        return tuple(color)
    else:
        raise TypeError('Invalid type for color: {}'.format(type(color)))

Convert various input to color tuples.

Args:
color (:obj:`Color`/str/tuple/int/ndarray): Color inputs

Returns:
tuple[int]: A tuple of 3 integers indicating BGR channels.


def time_travel(self, datetime=None, timedelta=None, seconds=0, minutes=0, hours=0, days=0):
    if (datetime is not None):
        self.timedelta = (datetime - python_datetime.now())
    if (timedelta is not None):
        self.timedelta = (self.timedelta + timedelta)
    self.timedelta = (self.timedelta + python_timedelta(seconds=seconds))
    self.timedelta = (self.timedelta + python_timedelta(minutes=minutes))
    self.timedelta = (self.timedelta + python_timedelta(hours=hours))
    self.timedelta = (self.timedelta + python_timedelta(days=days))
    log('Time traveling to {}\n'.format(humanize.naturaltime(self.now())))
    faketime.change_time(self.hitch_dir.faketime(), self.now())

Mock moving forward or backward in time by shifting the system clock fed to the services tested.

Note that all of these arguments can be used together, individually or not at all. The time
traveled to will be the sum of all specified time deltas from datetime. If no datetime is specified,
the deltas will be added to the current time.

Args:
datetime (Optional[datetime]): Time travel to specific datetime.
timedelta (Optional[timedelta]): Time travel to 'timedelta' from now.
seconds (Optional[number]): Time travel 'seconds' seconds from now.
minutes (Optional[number]): Time travel 'minutes' minutes from now.
hours (Optional[number]): Time travel 'hours' hours from now.
days (Optional[number]): Time travel 'days' days from now.


def __init__(self, pid_filename):

        self.stdin_path = '/dev/null'
        self.stdout_path = '/dev/null'
        self.stderr_path = '/dev/null'
        self.pidfile_path = '/tmp/' + pid_filename + '.pid'
        self.pidfile_timeout = 5
        self.daemon_runner = runner.DaemonRunner(self)

        if self.isRunning() and "stop" not in sys.argv and \
           "restart" not in sys.argv:
            self.onIsRunning()

Generic daemon class, which allows you to daemonize your script and
react to events in simple callbacks.

Args:
pid_filename (str): name of daemon's PID file, which is stored in
``/tmp``. Class automatically adds ``.pid``
suffix.


def __init__(self, file_pattern, action_function):

        super(GeneratorAction, self).__init__()
        self.__file_pattern = file_pattern
        self.__action_function = action_function

Container to store an "action".

Every file(s) generation is considered as an action.

Args:
file_pattern: fnmatch pattern.
action_function: Callback without argument. See documentation.


def validate_resource(resource: message.Message, primitive_handler_: primitive_handler.PrimitiveHandler) -> None:
    _validate_fhir_constraints(resource, resource.DESCRIPTOR.name, primitive_handler_)

Performs basic FHIR constraint validation on the provided resource.

This API works for all supported versions of FHIR, but requires a primitive
handler to be passed as an argument.
If the FHIR version being used is known ahead of time, version-specific APIs
such as `google.fhir.r4 resource_validation` should be used instead.

Args:
resource: the resource proto to validate
primitive_handler_: Version-specific logic


def load_hgnc_genes(adapter, genes=None, ensembl_lines=None, hgnc_lines=None, exac_lines=None, mim2gene_lines=None, genemap_lines=None, hpo_lines=None, build='37', omim_api_key=''):
    gene_objects = list()
    if (not genes):
        if (ensembl_lines is None):
            ensembl_lines = fetch_ensembl_genes(build=build)
        hgnc_lines = (hgnc_lines or fetch_hgnc())
        exac_lines = (exac_lines or fetch_exac_constraint())
        if (not (mim2gene_lines and genemap_lines)):
            if (not omim_api_key):
                raise SyntaxError('Need to provide omim api key')
            mim_files = fetch_mim_files(omim_api_key, mim2genes=True, genemap2=True)
            mim2gene_lines = mim_files['mim2genes']
            genemap_lines = mim_files['genemap2']
        if (not hpo_lines):
            hpo_files = fetch_hpo_files(hpogenes=True)
            hpo_lines = hpo_files['hpogenes']
        genes = link_genes(ensembl_lines=ensembl_lines, hgnc_lines=hgnc_lines, exac_lines=exac_lines, mim2gene_lines=mim2gene_lines, genemap_lines=genemap_lines, hpo_lines=hpo_lines)
    non_existing = 0
    nr_genes = len(genes)
    with progressbar(genes.values(), label='Building genes', length=nr_genes) as bar:
        for gene_data in bar:
            if (not gene_data.get('chromosome')):
                LOG.debug('skipping gene: %s. No coordinates found', gene_data.get('hgnc_symbol', '?'))
                non_existing += 1
                continue
            gene_obj = build_hgnc_gene(gene_data, build=build)
            gene_objects.append(gene_obj)
    LOG.info('Loading genes build %s', build)
    adapter.load_hgnc_bulk(gene_objects)
    LOG.info('Loading done. %s genes loaded', len(gene_objects))
    LOG.info('Nr of genes without coordinates in build %s: %s', build, non_existing)
    return gene_objects

Load genes into the database

link_genes will collect information from all the different sources and
merge it into a dictionary with hgnc_id as key and gene information as values.

Args:
adapter(scout.adapter.MongoAdapter)
genes(dict): If genes are already parsed
ensembl_lines(iterable(str)): Lines formated with ensembl gene information
hgnc_lines(iterable(str)): Lines with gene information from genenames.org
exac_lines(iterable(str)): Lines with information pLi-scores from ExAC
mim2gene(iterable(str)): Lines with map from omim id to gene symbol
genemap_lines(iterable(str)): Lines with information of omim entries
hpo_lines(iterable(str)): Lines information about map from hpo terms to genes
build(str): What build to use. Defaults to '37'

Returns:
gene_objects(list): A list with all gene_objects that was loaded into database


def login_with_password_no_sync(self, username, password):

        warn("login_with_password_no_sync is deprecated. Use login with sync=False.",
             DeprecationWarning)
        return self.login(username, password, sync=False)

Deprecated. Use ``login`` with ``sync=False``.

Login to the homeserver.

Args:
username (str): Account username
password (str): Account password

Returns:
str: Access token

Raises:
MatrixRequestError


def render_diagram(out_base):
    import codecs
    import subprocess
    import sadisplay
    desc = sadisplay.describe(list(model_registry.values()), show_methods=False, show_properties=True, show_indexes=True)
    with codecs.open((out_base + '.dot'), 'w', encoding='utf-8') as f:
        f.write(sadisplay.dot(desc))
    if (not hasattr(config, 'DOT_EXECUTABLE')):
        raise RuntimeError("Please configure the 'DOT_EXECUTABLE' variable in your 'project_config.py'")
    if (not os.path.exists(config.DOT_EXECUTABLE)):
        raise IOError(("Could not find file pointed to by 'DOT_EXECUTABLE': " + str(config.DOT_EXECUTABLE)))
    subprocess.check_call([config.DOT_EXECUTABLE, '-T', 'png', '-o', (out_base + '.png'), (out_base + '.dot')])

Render a data model diagram

Included in the diagram are all classes from the model registry.
For your project, write a small script that imports all models that you would like to
have included and then calls this function.

.. note:: This function requires the 'dot' executable from the GraphViz package to be installed
and its location configured in your `project_config.py` variable :attr:`DOT_EXECUTABLE`.

Args:
out_base (str): output base path (file endings will be appended)


def uses_keras_history(tensors):
    checked_tensors = set()
    tensors_to_check = nest.flatten(tensors)
    while tensors_to_check:
        new_tensors_to_check = []
        for tensor in tensors_to_check:
            if id(tensor) in checked_tensors:
                continue
            checked_tensors.add(id(tensor))
            if getattr(tensor, '_keras_history_checked', None) is not None:
                continue
            if getattr(tensor, '_keras_history', None) is not None:
                return True
            try:
                new_tensors_to_check.extend(tensor.op.inputs)
            except AttributeError:
                pass
        tensors_to_check = new_tensors_to_check
    mark_checked(tensors)
    return False

Check if at least one Tensor originates from a `keras.Input`.

This is `True` if at least one Tensor has its origin in a `keras.Input`.
Any Tensor that originates from a `keras.Input` will have a dependency
Tensor with a `_keras_history` attribute attached. Tensors that have
already been checked to not originate from a `keras.Input`
are marked as `_keras_history_checked`.

Args:
tensors: An arbitrary nested structure of Tensors.

Returns:
Bool, whether at least one Tensor originates from a `keras.Input`.


def get_version(tool_name, tool_command):

        result = {}
        for line in Bash(ShellConfig(script=tool_command, internal=True)).process():
            if line.find("command not found") >= 0:
                VersionsCheck.LOGGER.error("Required tool '%s' not found (stopping pipeline)!", tool_name)
                sys.exit(1)
            else:
                version = list(re.findall(r'(\d+(\.\d+)+)+', line))[0][0]
                result = {tool_name: Version(str(version))}
            break
        return result

Get name and version of a tool defined by given command.

Args:
tool_name (str): name of the tool.
tool_command (str): Bash one line command to get the version of the tool.

Returns:
dict: tool name and version or empty when no line has been found


def get(self, request):
    code = request.GET.get('code')
    if (not code):
        return render(request, 'django_auth_adfs/login_failed.html', {'error_message': 'No authorization code was provided.'}, status=400)
    redirect_to = request.GET.get('state')
    user = authenticate(request=request, authorization_code=code)
    if (user is not None):
        if user.is_active:
            login(request, user)
            if redirect_to:
                redirect_to = base64.urlsafe_b64decode(redirect_to.encode()).decode()
            else:
                redirect_to = django_settings.LOGIN_REDIRECT_URL
            url_is_safe = is_safe_url(url=redirect_to, allowed_hosts=[request.get_host()], require_https=request.is_secure())
            redirect_to = (redirect_to if url_is_safe else '/')
            return redirect(redirect_to)
        else:
            return render(request, 'django_auth_adfs/login_failed.html', {'error_message': 'Your account is disabled.'}, status=403)
    else:
        return render(request, 'django_auth_adfs/login_failed.html', {'error_message': 'Login failed.'}, status=401)

Handles the redirect from ADFS to our site.
We try to process the passed authorization code and login the user.

Args:
request (django.http.request.HttpRequest): A Django Request object


def get_transaction_id(transaction, read_operation=True):
    if (transaction is None):
        return None
    else:
        if (not transaction.in_progress):
            raise ValueError(INACTIVE_TXN)
        if (read_operation and (len(transaction._write_pbs) > 0)):
            raise ReadAfterWriteError(READ_AFTER_WRITE_ERROR)
        return transaction.id

Get the transaction ID from a ``Transaction`` object.

Args:
transaction (Optional[~.firestore_v1beta1.transaction.\
Transaction]): An existing transaction that this query will
run in.
read_operation (Optional[bool]): Indicates if the transaction ID
will be used in a read operation. Defaults to :data:`True`.

Returns:
Optional[bytes]: The ID of the transaction, or :data:`None` if the
``transaction`` is :data:`None`.

Raises:
ValueError: If the ``transaction`` is not in progress (only if
``transaction`` is not :data:`None`).
ReadAfterWriteError: If the ``transaction`` has writes stored on
it and ``read_operation`` is :data:`True`.


def run(argv=None, save_main_session=True, test_pipeline=None) -> PipelineResult:
    known_args, pipeline_args = parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
    model_loader = KeyedModelHandler(TFModelHandlerNumpy(model_uri=known_args.model_path, model_type=ModelType.SAVED_MODEL, large_model=known_args.large_model))
    pipeline = test_pipeline
    if not test_pipeline:
        pipeline = beam.Pipeline(options=pipeline_options)
    label_pixel_tuple = pipeline | 'ReadFromInput' >> beam.io.ReadFromText(known_args.input) | 'PreProcessInputs' >> beam.Map(process_input)
    predictions = label_pixel_tuple | 'RunInference' >> RunInference(model_loader) | 'PostProcessOutputs' >> beam.ParDo(PostProcessor())
    _ = predictions | 'WriteOutput' >> beam.io.WriteToText(known_args.output, shard_name_template='', append_trailing_newlines=True)
    result = pipeline.run()
    result.wait_until_finish()
    return result

Args:
argv: Command line arguments defined for this example.
save_main_session: Used for internal testing.
test_pipeline: Used for internal testing.


def get_ip_reports(self, ips):

        api_name = 'virustotal-ip-address-reports'

        (all_responses, ips) = self._bulk_cache_lookup(api_name, ips)
        responses = self._request_reports("ip", ips, 'ip-address/report')

        for ip, response in zip(ips, responses):
            if self._cache:
                self._cache.cache_value(api_name, ip, response)
            all_responses[ip] = response

        return all_responses

Retrieves the most recent VT info for a set of ips.

Args:
ips: list of IPs.
Returns:
A dict with the IP as key and the VT report as value.


def bridge_list():
    cmd = 'ovs-vsctl list-br'
    result = __salt__['cmd.run_all'](cmd)
    retcode = result['retcode']
    stdout = result['stdout']
    return _stdout_list_split(retcode, stdout)

Lists all existing real and fake bridges.

Returns:
List of bridges (or empty list), False on failure.

.. versionadded:: 2016.3.0

CLI Example:
.. code-block:: bash

salt '*' openvswitch.bridge_list


def request(self, send_terminator = False):

        self.m_a_crc = False
        start_context = self.getContext()
        self.setContext("request[v3A]")
        try:
            self.m_serial_port.write("2f3f".decode("hex") +
                                     self.m_meter_address +
                                     "210d0a".decode("hex"))
            self.m_raw_read_a = self.m_serial_port.getResponse(self.getContext())
            unpacked_read_a = self.unpackStruct(self.m_raw_read_a, self.m_blk_a)
            self.convertData(unpacked_read_a, self.m_blk_a, 1)
            self.m_a_crc = self.crcMeterRead(self.m_raw_read_a, self.m_blk_a)
            if send_terminator:
                self.serialPostEnd()
            self.calculateFields()
            self.makeReturnFormat()
        except:
            ekm_log(traceback.format_exc(sys.exc_info()))

        self.setContext(start_context)
        return self.m_a_crc

Required request() override for v3 and standard method to read meter.

Args:
send_terminator (bool): Send termination string at end of read.

Returns:
bool: CRC request flag result from most recent read


def download_structure_file(self, outdir, file_type=None, load_header_metadata=True, force_rerun=False):
    ssbio.utils.double_check_attribute(object=self, setter=file_type, backup_attribute='file_type', custom_error_text='Please set file type to be downloaded from the PDB: pdb, mmCif, xml, or mmtf')
    p = PDBList()
    with ssbio.utils.suppress_stdout():
        structure_file = p.retrieve_pdb_file(pdb_code=self.id, pdir=outdir, file_format=file_type, overwrite=force_rerun)
    if (not op.exists(structure_file)):
        log.debug('{}: {} file not available'.format(self.id, file_type))
        raise URLError('{}.{}: file not available to download'.format(self.id, file_type))
    else:
        log.debug('{}: {} file saved'.format(self.id, file_type))
        if (file_type == 'pdb'):
            new_name = structure_file.replace('pdb', '').replace('ent', 'pdb')
            os.rename(structure_file, new_name)
            structure_file = new_name
        self.load_structure_path(structure_file, file_type)
        if (load_header_metadata and (file_type == 'mmtf')):
            self.update(parse_mmtf_header(structure_file))
        if (load_header_metadata and (file_type != 'mmtf')):
            self.update(parse_mmcif_header(download_mmcif_header(pdb_id=self.id, outdir=outdir, force_rerun=force_rerun)))

Download a structure file from the PDB, specifying an output directory and a file type. Optionally download
the mmCIF header file and parse data from it to store within this object.

Args:
outdir (str): Path to output directory
file_type (str): ``pdb``, ``mmCif``, ``xml``, ``mmtf`` - file type for files downloaded from the PDB
load_header_metadata (bool): If header metadata should be loaded into this object, fastest with mmtf files
force_rerun (bool): If structure file should be downloaded even if it already exists


class UperNetPyramidPoolingModule(nn.Module):

    def __init__(self, pool_scales: Tuple[int, ...], in_channels: int, channels: int, align_corners: bool) -> None:
        super().__init__()
        self.pool_scales = pool_scales
        self.align_corners = align_corners
        self.in_channels = in_channels
        self.channels = channels
        self.blocks = []
        for i, pool_scale in enumerate(pool_scales):
            block = UperNetPyramidPoolingBlock(pool_scale=pool_scale, in_channels=in_channels, channels=channels)
            self.blocks.append(block)
            self.add_module(str(i), block)

    def forward(self, x: torch.Tensor) -> List[torch.Tensor]:
        ppm_outs = []
        for ppm in self.blocks:
            ppm_out = ppm(x)
            upsampled_ppm_out = nn.functional.interpolate(ppm_out, size=x.size()[2:], mode='bilinear', align_corners=self.align_corners)
            ppm_outs.append(upsampled_ppm_out)
        return ppm_outs

Pyramid Pooling Module (PPM) used in PSPNet.

Args:
pool_scales (`Tuple[int]`):
Pooling scales used in Pooling Pyramid Module.
in_channels (`int`):
Input channels.
channels (`int`):
Channels after modules, before conv_seg.
align_corners (`bool`):
align_corners argument of F.interpolate.


def execute_phase(self, phase):

    repeat_count = 1
    repeat_limit = phase.options.repeat_limit or sys.maxsize
    while not self._stopping.is_set():
      is_last_repeat = repeat_count >= repeat_limit
      phase_execution_outcome = self._execute_phase_once(phase, is_last_repeat)

      if phase_execution_outcome.is_repeat and not is_last_repeat:
        repeat_count += 1
        continue

      return phase_execution_outcome

    return PhaseExecutionOutcome(None)

Executes a phase or skips it, yielding PhaseExecutionOutcome instances.

Args:
phase: Phase to execute.

Returns:
The final PhaseExecutionOutcome that wraps the phase return value
(or exception) of the final phase run. All intermediary results, if any,
are REPEAT and handled internally. Returning REPEAT here means the phase
hit its limit for repetitions.


def _git_fetch_for_comparison(remote: str, actual_branch: str, compare_branch: str, verbose: bool) -> prepared_env.PreparedEnv:
    actual_id = ''
    base_id = ''
    for depth in [10, 100, 1000, None]:
        depth_str = ('' if (depth is None) else '--depth={}'.format(depth))
        shell_tools.run_cmd('git', 'fetch', (None if verbose else '--quiet'), remote, actual_branch, depth_str, log_run_to_stderr=verbose)
        actual_id = shell_tools.output_of('git', 'rev-parse', 'FETCH_HEAD')
        shell_tools.run_cmd('git', 'fetch', (None if verbose else '--quiet'), remote, compare_branch, depth_str, log_run_to_stderr=verbose)
        base_id = shell_tools.output_of('git', 'rev-parse', 'FETCH_HEAD')
        try:
            base_id = shell_tools.output_of('git', 'merge-base', actual_id, base_id)
            break
        except subprocess.CalledProcessError:
            pass
    return prepared_env.PreparedEnv(None, actual_id, base_id, None, None)

Fetches two branches including their common ancestor.

Limits the depth of the fetch to avoid unnecessary work. Scales up the
depth exponentially and tries again when the initial guess is not deep
enough.

Args:
remote: The location of the remote repository, in a format that the
git command will understand.
actual_branch: A remote branch or ref to fetch,
compare_branch: Another remote branch or ref to fetch,
verbose: When set, more progress output is produced.

Returns:
A ComparableCommits containing the commit id of the actual branch and
a the id of a commit to compare against (e.g. for when doing incremental
checks).


def get(self, webfont_name, webfont_settings):

        try:
            webfont_settings = extend_webfont_settings(webfont_settings)
        except IcomoonSettingsError as e:
            msg = "Invalid webfont settings for '{}': {}"
            self.errors[webfont_name] = msg.format(webfont_name, e.value)
            return

        filepath = os.path.join(webfont_settings['fontdir_path'],
                                self.manifest_filename)

        if os.path.exists(filepath):
            self.manifests[webfont_name] = self.parse_manifest(filepath)
        else:
            msg = (
                   )
            self.errors[webfont_name] = msg.format(name=webfont_name,
                                                   filepath=filepath)

Get a manifest file, parse and store it.

Args:
webfont_name (string): Webfont key name. Used to store manifest
and potentially its parser error.
webfont_settings (dict): Webfont settings (an item value from
``settings.ICOMOON_WEBFONTS``).


def __init__(self, features, location_id=None, metadata=None, timeout=120):
    super().__init__(features=features, location_id=location_id, metadata=metadata, timeout=timeout)

Args:
features: (List[``videointelligence_v1.Feature``]) Required.
the Video Intelligence API features to detect
location_id: (str) Optional.
Cloud region where annotation should take place.
If no region is specified, a region will be determined
based on video file location.
metadata: (Sequence[Tuple[str, str]]) Optional.
Additional metadata that is provided to the method.
timeout: (int) Optional.
The time in seconds to wait for the response from the
Video Intelligence API


def set_colors(self, fg=None, bg=None):

        if fg is not None:
            self._fg = _format_color(fg, self._fg)
        if bg is not None:
            self._bg = _format_color(bg, self._bg)

Sets the colors to be used with the L{print_str} and draw_* methods.

Values of None will only leave the current values unchanged.

Args:
fg (Optional[Union[Tuple[int, int, int], int, Ellipsis]])
bg (Optional[Union[Tuple[int, int, int], int, Ellipsis]])
.. seealso:: :any:`move`, :any:`print_str`


def __init__(self, filename, temporary_directory=None):

    self._database = None
    self._filename = filename
    self._is_open = False
    self._temp_db_file_path = ''
    self._temporary_directory = temporary_directory
    self._temp_wal_file_path = ''

    self.schema = {}

Initializes the database object.

Args:
filename (str): name of the file entry.
temporary_directory (Optional[str]): path of the directory for temporary
files.


def and_terms(*args):

    args = [arg if not isinstance(arg, list) else ' '.join(arg) for arg in args]
    return '({0})'.format(' '.join(args))

Connect given term strings or list(s) of term strings with an AND operator for querying.

Args:
An arbitrary number of either strings or lists of strings representing query terms.

Returns
A query string consisting of argument terms and'ed together.


def Proxy(self, status, headers, exc_info=None):
    self.call_context['status'] = status
    self.call_context['headers'] = headers
    self.call_context['exc_info'] = exc_info
    return self.body_buffer.write

Save args, defer start_response until response body is parsed.

Create output buffer for body to be written into.
Note: this is not quite WSGI compliant: The body should come back as an
iterator returned from calling service_app() but instead, StartResponse
returns a writer that will be later called to output the body.
See google/appengine/ext/webapp/__init__.py::Response.wsgi_write()
write = start_response('%d %s' % self.__status, self.__wsgi_headers)
write(body)

Args:
status: Http status to be sent with this response
headers: Http headers to be sent with this response
exc_info: Exception info to be displayed for this response
Returns:
callable that takes as an argument the body content


def readlink(self, path):

        if path is None:
            raise TypeError
        try:
            link_obj = self.lresolve(path)
        except IOError as exc:
            self.raise_os_error(exc.errno, path)
        if S_IFMT(link_obj.st_mode) != S_IFLNK:
            self.raise_os_error(errno.EINVAL, path)

        if self.ends_with_path_separator(path):
            if not self.is_windows_fs and self.exists(path):
                self.raise_os_error(errno.EINVAL, path)
            if not self.exists(link_obj.path):
                if self.is_windows_fs:
                    error = errno.EINVAL
                elif self._is_circular_link(link_obj):
                    if self.is_macos:
                        return link_obj.path
                    error = errno.ELOOP
                else:
                    error = errno.ENOENT
                self.raise_os_error(error, link_obj.path)

        return link_obj.contents

Read the target of a symlink.

Args:
path:  symlink to read the target of.

Returns:
the string representing the path to which the symbolic link points.

Raises:
TypeError: if path is None
OSError: (with errno=ENOENT) if path is not a valid path, or
(with errno=EINVAL) if path is valid, but is not a symlink,
or if the path ends with a path separator (Posix only)


def write_dftbp(filename, atoms):
    scale_pos = dftbpToBohr
    lines = ''
    natoms = atoms.get_number_of_atoms()
    lines += str(natoms)
    lines += ' S \n'
    expaned_symbols = atoms.get_chemical_symbols()
    symbols = get_reduced_symbols(expaned_symbols)
    lines += (' '.join(symbols) + '\n')
    atom_numbers = []
    for ss in expaned_symbols:
        atom_numbers.append((symbols.index(ss) + 1))
    positions = (atoms.get_positions() / scale_pos)
    for ii in range(natoms):
        pos = positions[ii]
        pos_str = '{:3d} {:3d} {:20.15f} {:20.15f} {:20.15f}\n'.format((ii + 1), atom_numbers[ii], pos[0], pos[1], pos[2])
        lines += pos_str
    lines += '0.0 0.0 0.0\n'
    cell = (atoms.get_cell() / scale_pos)
    for ii in range(3):
        cell_str = '{:20.15f} {:20.15f} {:20.15f}\n'.format(cell[ii][0], cell[ii][1], cell[ii][2])
        lines += cell_str
    outfile = open(filename, 'w')
    outfile.write(lines)

Writes DFTB+ readable, gen-formatted structure files

Args:
filename: name of the gen-file to be written
atoms: object containing information about structure


def get_max_position(self, chrom):

        res = self.db.variant.find({'chrom':chrom}, {'_id':0, 'end':1}).sort([('end', DESCENDING)]).limit(1)
        end = 0
        for variant in res:
            end = variant['end']
        return end

Get the last position observed on a chromosome in the database

Args:
chrom(str)

Returns:
end(int): The largest end position found


def banner(text, border='=', width=80):

    text_padding = '{0:^%d}' % (width)
    LOG.info(border * width)
    LOG.info(text_padding.format(text))
    LOG.info(border * width)

Center _text_ in a banner _width_ wide with _border_ characters.

Args:
text (str): What to write in the banner
border (str): Border character
width (int): How long the border should be


def load_hpo_terms(adapter, hpo_lines=None, hpo_gene_lines=None, alias_genes=None):

    hpo_terms = {}

    if not hpo_lines:
        hpo_lines = fetch_hpo_terms()

    if not hpo_gene_lines:
        hpo_gene_lines = fetch_hpo_to_genes()

    LOG.info("Parsing hpo terms")
    for term in parse_hpo_obo(hpo_lines):
        hpo_terms[term['hpo_id']] = term

    if not alias_genes:
        alias_genes = adapter.genes_by_alias()

    LOG.info("Adding gene information to hpo terms ...")
    for hpo_to_symbol in parse_hpo_to_genes(hpo_gene_lines):
        hgnc_symbol = hpo_to_symbol['hgnc_symbol']
        hpo_id = hpo_to_symbol['hpo_id']

        gene_info = alias_genes.get(hgnc_symbol)
        if not gene_info:
            continue

        hgnc_id = gene_info['true']

        if hpo_id not in hpo_terms:
            continue

        hpo_term = hpo_terms[hpo_id]

        if not 'genes' in hpo_term:
            hpo_term['genes'] = set()

        hpo_term['genes'].add(hgnc_id)

    start_time = datetime.now()

    LOG.info("Loading the hpo terms...")
    nr_terms = len(hpo_terms)
    hpo_bulk = []
    with progressbar(hpo_terms.values(), label="Loading hpo terms", length=nr_terms) as bar:

        for hpo_info in bar:
            hpo_bulk.append(build_hpo_term(hpo_info))

        if len(hpo_bulk) > 10000:
            adapter.load_hpo_bulk(hpo_bulk)
            hpo_bulk = []

    if hpo_bulk:
        adapter.load_hpo_bulk(hpo_bulk)

    LOG.info("Loading done. Nr of terms loaded {0}".format(nr_terms))
    LOG.info("Time to load terms: {0}".format(datetime.now() - start_time))

Load the hpo terms into the database

Parse the hpo lines, build the objects and add them to the database

Args:
adapter(MongoAdapter)
hpo_lines(iterable(str))
hpo_gene_lines(iterable(str))


def form_out(self, _form=None):

        _form = _form or self.object_form
        self.output['forms'] = _form.serialize()
        self._add_meta_props(_form)
        self.output['forms']['grouping'] = _form.Meta.grouping
        self.output['forms']['constraints'] = _form.Meta.constraints
        self._patch_form(self.output['forms'])
        self.set_client_cmd('form')

Renders form. Applies form modifiers, then writes
result to response payload. If supplied, given form
object instance will be used instead of view's
default ObjectForm.

Args:
_form (:py:attr:`~zengine.forms.json_form.JsonForm`):
Form object to override `self.object_form`


def call(self, inputs):

    image_shape = tf.shape(input=inputs)[-3:]
    collapsed_shape = tf.concat(([-1], image_shape), axis=0)
    out = tf.reshape(inputs, collapsed_shape)
    out = self.conv1(out)
    out = self.conv2(out)
    out = self.conv3(out)
    out = self.conv4(out)
    expanded_shape = tf.concat((tf.shape(input=inputs)[:-3], [-1]), axis=0)
    return tf.reshape(out, expanded_shape)

Runs the model to generate an intermediate representation of x_t.

Args:
inputs: A batch of image sequences `x_{1:T}` of shape
`[sample_shape, batch_size, timesteps, height, width,
channels]`.

Returns:
A batch of intermediate representations of shape [sample_shape,
batch_size, timesteps, hidden_size].


def minutes(start, end=None):

    return iterate.between(start, datetime.timedelta(minutes=1), end)

Iterate over the minutes between the given datetime_tzs.

Args:
start: datetime_tz to start from.
end: (Optional) Date to end at, if not given the iterator will never
terminate.

Returns:
An iterator which generates datetime_tz objects a minute apart.


def copy_and_move_messages(from_channel, to_channel):

        with BlockSave(Message, query_dict={'channel_id': to_channel.key}):
            for message in Message.objects.filter(channel=from_channel, typ=15):
                message.key = ''
                message.channel = to_channel
                message.save()

While splitting channel and moving chosen subscribers to new channel,
old channel's messages are copied and moved to new channel.

Args:
from_channel (Channel object): move messages from channel
to_channel (Channel object): move messages to channel


def forward(self, hidden_states: Optional[torch.FloatTensor], attention_mask: Optional[torch.FloatTensor]=None, position_ids: Optional[torch.LongTensor]=None, past_key_value: Optional[Cache]=None, use_cache: Optional[bool]=False, output_attentions: Optional[bool]=False, cache_position: Optional[torch.LongTensor]=None) -> Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Optional[Tuple[torch.Tensor, Tuple[torch.Tensor], Tuple[torch.Tensor, ...]]]]:
    output_attentions = False
    bsz, q_len, hidden_size = hidden_states.size()
    query_states, router_logits, topo_info = self.experts.map(hidden_states)
    key_states, value_states = self.kv_proj(hidden_states).chunk(2, dim=-1)
    query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
    key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
    value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
    cos, sin = self.rotary_emb(value_states, position_ids)
    query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
    if past_key_value is not None:
        cache_kwargs = {'sin': sin, 'cos': cos, 'cache_position': cache_position}
        key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
    key_states = key_states.repeat(1, self.top_k, 1, 1)
    value_states = value_states.repeat(1, self.top_k, 1, 1)
    query_states = query_states.transpose(1, 2)
    key_states = key_states.transpose(1, 2)
    value_states = value_states.transpose(1, 2)
    dropout_rate = self.attention_dropout if self.training else 0.0
    input_dtype = query_states.dtype
    if input_dtype == torch.float32:
        if torch.is_autocast_enabled():
            target_dtype = torch.get_autocast_gpu_dtype()
        elif hasattr(self.config, '_pre_quantization_dtype'):
            target_dtype = self.config._pre_quantization_dtype
        else:
            target_dtype = self.kv_proj.weight.dtype
        logger.warning_once(f'The input hidden states seems to be silently casted in float32, this might be related to the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in {target_dtype}.')
        query_states = query_states.to(target_dtype)
        key_states = key_states.to(target_dtype)
        value_states = value_states.to(target_dtype)
    attn_output = _flash_attention_forward(query_states, key_states, value_states, attention_mask, q_len, dropout=dropout_rate, use_top_left_mask=self._flash_attn_uses_top_left_mask, is_causal=self.is_causal).to(input_dtype)
    attn_output = attn_output.reshape(bsz, q_len, self.top_k, self.kv_projection_size)
    attn_output = self.experts.reduce(attn_output, topo_info)
    attn_output = attn_output.view(bsz, q_len, hidden_size)
    if not output_attentions:
        attn_weights = None
    return (attn_output, attn_weights, past_key_value, router_logits)

Forward pass of the JetMoeAttention module.

Args:
hidden_states (Optional[torch.FloatTensor]): Input hidden states.
attention_mask (Optional[torch.FloatTensor]): Attention mask.
layer_past (Optional[Tuple[torch.Tensor]]): Past layer state.
use_cache (Optional[bool]): Whether to use cached states.
output_attentions (Optional[bool]): Whether to output attention weights.
cache_position (Optional[torch.LongTensor]): Position of the cache.

Returns:
Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Optional[Tuple[...]]]: Tuple containing outputs.


def Read(f):
    try:
        yaml_data = yaml.load(f)
    except yaml.YAMLError as e:
        raise ParseError(('%s' % e))
    except IOError as e:
        raise YAMLLoadError(('%s' % e))
    _CheckData(yaml_data)
    try:
        return Config(yaml_data.get('blacklist', ()), yaml_data.get('whitelist', '*'))
    except UnicodeDecodeError as e:
        raise YAMLLoadError(('%s' % e))

Reads and returns Config data from a yaml file.

Args:
f: Yaml file to parse.

Returns:
Config object as defined in this file.

Raises:
Error (some subclass): If there is a problem loading or parsing the file.


def verify(self, obj):

        if obj is not None:
            raise ValidationError("Object is not None",
                                  reason='%s is not None' % str(obj), object=obj)

        return obj

Verify that the object conforms to this verifier's schema

Args:
obj (object): A python object to verify

Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating
the reason for the lack of validation.


def collect_per_output_metric_info(metrics, output_names, output_shapes, loss_fns, from_serialized=False, is_weighted=False):
    if not metrics:
        return [{} for _ in output_names]
    if isinstance(metrics, list):
        any_sub_list = any((isinstance(m, list) for m in metrics))
        if any_sub_list:
            if len(metrics) != len(output_names):
                raise ValueError('When passing a list of lists as `metrics`, it should have one entry per model output. The model has ' + str(len(output_names)) + ' outputs, but you passed metrics=' + str(metrics))
            nested_metrics = [generic_utils.to_list(m) for m in metrics]
        elif len(output_names) > 1:
            nested_metrics = []
            for _ in output_names:
                nested_metrics.append([metrics_module.clone_metric(m) for m in metrics])
        else:
            nested_metrics = [metrics]
    elif isinstance(metrics, collections.abc.Mapping):
        generic_utils.check_for_unexpected_keys('metrics', metrics, output_names)
        nested_metrics = []
        for name in output_names:
            output_metrics = generic_utils.to_list(metrics.get(name, []))
            nested_metrics.append(output_metrics)
    else:
        raise TypeError('Type of `metrics` argument not understood. Expected a list or dictionary, found: ' + str(metrics))
    per_output_metrics = []
    for i, metrics in enumerate(nested_metrics):
        metrics_dict = collections.OrderedDict()
        for metric in metrics:
            metric_name = get_metric_name(metric, is_weighted)
            metric_fn = get_metric_function(metric, output_shape=output_shapes[i], loss_fn=loss_fns[i])
            metric_fn._from_serialized = from_serialized
            if not isinstance(metric_fn, metrics_module.Metric):
                metric_fn = metrics_module.MeanMetricWrapper(metric_fn, name=metric_name)
                metric_fn._from_serialized = False
            metrics_dict[metric_name] = metric_fn
        per_output_metrics.append(metrics_dict)
    return per_output_metrics

Maps metric names and functions to model outputs.

Args:
metrics: a list or a list of lists or a dict of metric functions.
output_names: a list of the names (strings) of model outputs.
output_shapes: a list of the shapes (strings) of model outputs.
loss_fns: a list of the loss functions corresponding to the model outputs.
from_serialized: whether the model the metrics are being sourced from is
being initialized from a serialized format.
is_weighted: Boolean indicating whether the given metrics are weighted.

Returns:
A list (one entry per model output) of dicts.
For instance, if the model has 2 outputs, and for the first output
we want to compute "binary_accuracy" and "binary_crossentropy",
and just "binary_accuracy" for the second output,
the list would look like: `[{
'acc': binary_accuracy(),
'ce': binary_crossentropy(),
}, {
'acc': binary_accuracy(),
}]`

Raises:
TypeError: if an incorrect type is passed for the `metrics` argument.


def experimental_design(self) -> Any:
    if (not self.samples):
        raise ValueError('No samples in sample sheet')
    markdown = tabulate([[getattr(s, h, '') for h in DESIGN_HEADER] for s in self.samples], headers=DESIGN_HEADER, tablefmt='pipe')
    return maybe_render_markdown(markdown)

Return a markdown summary of the samples on this sample sheet.

This property supports displaying rendered markdown only when running
within an IPython interpreter. If we are not running in an IPython
interpreter, then print out a nicely formatted ASCII table.

Returns:
Markdown, str: A visual table of IDs and names for all samples.


def GenerateModelReport(metagraph, assume_valid_feeds=True, debug=False):
    return tf_wrap.GenerateModelReport(metagraph.SerializeToString(), assume_valid_feeds, debug)

Report what's known statically about each node in the provided metagraph.

Args:
metagraph: A TensorFlow MetaGraphDef.
assume_valid_feeds: If True, assume that the shape of the fed nodes is valid
debug: Add some information useful for debugging.

Returns:
A string containing the report.


def Parse(self, stat, file_object, knowledge_base):
    (_, _) = (stat, knowledge_base)
    lines = [l.strip() for l in utils.ReadFileBytesAsUnicode(file_object).splitlines()]
    return self.ParseLines(lines)

Parse the netgroup file and return User objects.

Lines are of the form:
group1 (-,user1,) (-,user2,) (-,user3,)

Groups are ignored, we return users in lines that match the filter regexes,
or all users in the file if no filters are specified.

We assume usernames are in the default regex format specified in the adduser
man page.  Notably no non-ASCII characters.

Args:
stat: unused statentry
file_object: netgroup VFSFile
knowledge_base: unused

Returns:
rdf_client.User


def __delitem__(self, name: str) -> None:
    if base.treats_as_sealed(self):
        raise base.WritePermissionError('Cannot del item from a sealed Dict.')
    if not base.writtable_via_accessors(self):
        raise base.WritePermissionError(self._error_message("Cannot del Dict field by attribute or key while accessor_writable is set to False. Use 'rebind' method instead."))
    if name not in self:
        raise KeyError(self._error_message(f'Key does not exist in Dict: {name!r}.'))
    update = self._set_item_without_permission_check(name, pg_typing.MISSING_VALUE)
    if flags.is_change_notification_enabled() and update:
        self._notify_field_updates([update])

Delete a key from the Dict.

This is used to delete a key which resolves to a pg.typing.NonConstKey.

Args:
name: Key to delete.

Raises:
WritePermissionError: When Dict is sealed.
KeyError: When key is not a NonConstKey.


def make_simulated_env_fn(**env_kwargs):

    def env_fn(in_graph):
        class_ = (SimulatedBatchEnv if in_graph else SimulatedBatchGymEnv)
        return class_(**env_kwargs)
    return env_fn

Returns a function creating a simulated env, in or out of graph.

Args:
**env_kwargs: kwargs to pass to the simulated env constructor.

Returns:
Function in_graph -> env.


def segment_sum(data, segment_ids, num_segments=None, sorted=False):
    _segment_reduce_validation(data, segment_ids)
    if any_symbolic_tensors((data,)):
        return SegmentSum(num_segments, sorted).symbolic_call(data, segment_ids)
    return backend.math.segment_sum(data, segment_ids, num_segments=num_segments, sorted=sorted)

Computes the sum of segments in a tensor.

Args:
data: Input tensor.
segment_ids: A N-D tensor containing segment indices for each
element in `data`. Num dims for segment ids should be strictly
smaller or equal to number of dims in data.
num_segments: An integer representing the total number of
segments. If not specified, it is inferred from the maximum
value in `segment_ids`.
sorted: A boolean indicating whether `segment_ids` is sorted.
Defaults to `False`.

Returns:
A tensor containing the sum of segments, where each element
represents the sum of the corresponding segment in `data`.

Example:

>>> data = keras.ops.convert_to_tensor([1, 2, 10, 20, 100, 200])
>>> segment_ids = keras.ops.convert_to_tensor([0, 0, 1, 1, 2, 2])
>>> num_segments = 3
>>> keras.ops.segment_sum(data, segment_ids,num_segments)
array([3, 30, 300], dtype=int32)


def to_representation(self, instance):

        request = self.context['request']
        enterprise_customer = instance.enterprise_customer

        representation = super(EnterpriseCustomerCatalogDetailSerializer, self).to_representation(instance)

        paginated_content = instance.get_paginated_content(request.GET)
        count = paginated_content['count']
        search_results = paginated_content['results']

        for item in search_results:
            content_type = item['content_type']
            marketing_url = item.get('marketing_url')
            if marketing_url:
                item['marketing_url'] = utils.update_query_parameters(
                    marketing_url, utils.get_enterprise_utm_context(enterprise_customer)
                )

            if content_type == 'course':
                item['enrollment_url'] = instance.get_course_enrollment_url(item['key'])
            if content_type == 'courserun':
                item['enrollment_url'] = instance.get_course_run_enrollment_url(item['key'])
            if content_type == 'program':
                item['enrollment_url'] = instance.get_program_enrollment_url(item['uuid'])

        previous_url = None
        next_url = None
        page = int(request.GET.get('page', '1'))
        request_uri = request.build_absolute_uri()
        if paginated_content['previous']:
            previous_url = utils.update_query_parameters(request_uri, {'page': page - 1})
        if paginated_content['next']:
            next_url = utils.update_query_parameters(request_uri, {'page': page + 1})

        representation['count'] = count
        representation['previous'] = previous_url
        representation['next'] = next_url
        representation['results'] = search_results

        return representation

Serialize the EnterpriseCustomerCatalog object.

Arguments:
instance (EnterpriseCustomerCatalog): The EnterpriseCustomerCatalog to serialize.

Returns:
dict: The EnterpriseCustomerCatalog converted to a dict.


def pandas(self):
    (names, prior, posterior) = ([], [], [])
    for (iname, name) in enumerate(self.posterior_parameter.row_names):
        names.append(name)
        posterior.append(np.sqrt(float(self.posterior_parameter[(iname, iname)].x)))
        iprior = self.parcov.row_names.index(name)
        prior.append(np.sqrt(float(self.parcov[(iprior, iprior)].x)))
    for (pred_name, pred_var) in self.posterior_prediction.items():
        names.append(pred_name)
        posterior.append(np.sqrt(pred_var))
        prior.append(self.prior_prediction[pred_name])
    return pd.DataFrame({'posterior': posterior, 'prior': prior}, index=names)

get a pandas dataframe of prior and posterior for all predictions

Returns:
pandas.DataFrame : pandas.DataFrame
a dataframe with prior and posterior uncertainty estimates
for all forecasts (predictions)


def to_array(data):
    try:
        numpy_data = blosc.unpack_array(data)
    except Exception as e:
        raise ValueError('Could not load numpy data. {}'.format(e))
    return numpy_data

Import a blosc array into a numpy array.

Arguments:
data: A blosc packed numpy array

Returns:
A numpy array with data from a blosc compressed array


def __init__(self, x, offset, dim, wrap, name=None):

    super(ShiftOperation, self).__init__([x], name=name or "shift")
    self._dim = dim
    self._axis = x.shape.dims.index(dim)
    self._offset = offset
    self._wrap = wrap
    self._outputs = [Tensor(self, x.shape, x.dtype)]

Create a shift operation.

Shift x right by +offset in dimension dim.
If offset is negative, shift left.
If wrap is true then wrap-around.  Else, pad with zeros.

Args:
x: a Tensor
offset: an integer
dim: a Dimension of x
wrap: a boolean - whether to wrap or pad.
name: an optional string


def fastcc_is_consistent(model, epsilon, solver):

    for reaction in fastcc(model, epsilon, solver):
        return False
    return True

Quickly check whether model is consistent

Return true if the model is consistent. If it is only necessary to know
whether a model is consistent, this function is fast as it will return
the result as soon as it finds a single inconsistent reaction.

Args:
model: :class:`MetabolicModel` to solve.
epsilon: Flux threshold value.
solver: LP solver instance to use.


def _compute_router_probabilities(self, hidden_states: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
    self.input_dtype = hidden_states.dtype
    hidden_states = hidden_states.to(self.dtype)
    if self.training and self.jitter_noise > 0:
        hidden_states *= torch.empty_like(hidden_states).uniform_(1.0 - self.jitter_noise, 1.0 + self.jitter_noise)
    self._cast_classifier()
    router_logits = self.classifier(hidden_states)
    router_probabilities = nn.functional.softmax(router_logits, dim=-1, dtype=self.dtype).to(self.input_dtype)
    return (router_probabilities, router_logits)

Computes router probabilities from input hidden states.

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


def cancel_job(self, job_id=None, job_name=None):

        payload = {}
        if job_name is not None:
            payload['job_name'] = job_name
        if job_id is not None:
            payload['job_id'] = job_id

        jobs_url = self._get_url('jobs_path')
        res = self.rest_client.session.delete(jobs_url, params=payload)
        _handle_http_errors(res)
        return res.json()

Cancel a running job.

Args:
job_id (str, optional): Identifier of job to be canceled.
job_name (str, optional): Name of job to be canceled.

Returns:
dict: JSON response for the job cancel operation.


def __init__(self, primitive_handler_: primitive_handler.PrimitiveHandler, default_timezone: str) -> None:
    self.primitive_handler = primitive_handler_
    self.default_timezone = default_timezone
    self._resource_type_mapping = {field.message_type.name: field for field in primitive_handler_.contained_resource_cls.DESCRIPTOR.fields}

Initializes an instance of the FHIR JSON parser.

Note that this is for *internal-use* only. External clients should leverage
one of the available class constructors, such as:
`JsonParser.json_parser_with_default_timezone(...)`.

Args:
primitive_handler_: Responsible for returning PrimitiveWrappers.
default_timezone: The string representation of the timezone to default-to
when parsing time-like values.


def apply(self, flag_set: AbstractSet[Flag], operand: AbstractSet[Flag]) -> FrozenSet[Flag]:
    if (self == FlagOp.ADD):
        return frozenset((flag_set | operand))
    elif (self == FlagOp.DELETE):
        return frozenset((flag_set - operand))
    else:
        return frozenset(operand)

Apply the flag operation on the two sets, returning the result.

Args:
flag_set: The flag set being operated on.
operand: The flags to use as the operand.


def DumpMany(objs):
    precondition.AssertIterableType(objs, object)
    text = yaml.safe_dump_all(objs, default_flow_style=False, allow_unicode=True)
    if compatibility.PY2:
        text = text.decode('utf-8')
    return text

Stringifies a sequence of Python objects to a multi-document YAML.

Args:
objs: An iterable of Python objects to convert to YAML.

Returns:
A multi-document YAML representation of the given objects.


def fetch(self, refund_id, data={}, **kwargs):

        return super(Refund, self).fetch(refund_id, data, **kwargs)

Refund object for given paymnet Id

Args:
refund_id : Refund Id for which refund has to be retrieved

Returns:
Refund dict for given refund Id


def __init__(
        self,
        cls,
        diff,
    ):

        msg = "\n".join([
            "",
            "ctor: {}".format(cls),
            "extras: {}".format(diff)
        ])
        Exception.__init__(self, msg)
        self.type = str(
            type(self),
        )
        self.cls = str(cls)
        self.diff = str(diff)
        self.type = self.__class__.__name__

Note that type_assert can't be used because it would
create a circular dependency.

Args:
cls,  type, The type that was attempted to unmarshal into
diff: dict, The extra arguments that were passed to @cls


def imread(img_or_path, flag='color'):
    if isinstance(img_or_path, np.ndarray):
        return img_or_path
    elif is_str(img_or_path):
        flag = (imread_flags[flag] if is_str(flag) else flag)
        check_file_exist(img_or_path, 'img file does not exist: {}'.format(img_or_path))
        return cv2.imread(img_or_path, flag)
    else:
        raise TypeError('"img" must be a numpy array or a filename')

Read an image.

Args:
img_or_path (ndarray or str): Either a numpy array or image path.
If it is a numpy array (loaded image), then it will be returned
as is.
flag (str): Flags specifying the color type of a loaded image,
candidates are `color`, `grayscale` and `unchanged`.

Returns:
ndarray: Loaded image array.


def get(self, language: str=None, default: str=None) -> str:

        language = language or settings.LANGUAGE_CODE
        value = super().get(language, default)
        return value if value is not None else default

Gets the underlying value in the specified or
primary language.

Arguments:
language:
The language to get the value in.

Returns:
The value in the current language, or
the primary language in case no language
was specified.


def to_dataframe(self):
    data = []
    for (target_index, target_row) in enumerate(self._cm):
        for (predicted_index, count) in enumerate(target_row):
            data.append((self._labels[target_index], self._labels[predicted_index], count))
    return pd.DataFrame(data, columns=['target', 'predicted', 'count'])

Convert the confusion matrix to a dataframe.

Returns:
A DataFrame with "target", "predicted", "count" columns.


def smart_device_selection(preferred_device_type=None):
    cl_environments = CLEnvironmentFactory.all_devices(cl_device_type=preferred_device_type)
    platform_names = [env.platform.name for env in cl_environments]
    has_amd_pro_platform = any((('AMD Accelerated Parallel Processing' in name) for name in platform_names))
    if has_amd_pro_platform:
        return list(filter((lambda env: ('Clover' not in env.platform.name)), cl_environments))
    if ((preferred_device_type is not None) and (not len(cl_environments))):
        return CLEnvironmentFactory.all_devices()
    return cl_environments

Get a list of device environments that is suitable for use in MOT.

Basically this gets the total list of devices using all_devices() and applies a filter on it.

This filter does the following:
1) if the 'AMD Accelerated Parallel Processing' is available remove all environments using the 'Clover'
platform.

More things may be implemented in the future.

Args:
preferred_device_type (str): the preferred device type, one of 'CPU', 'GPU' or 'APU'.
If no devices of this type can be found, we will use any other device available.

Returns:
list of CLEnvironment: List with the CL device environments.


def _decrypt_asymmetric(self, decryption_algorithm, decryption_key, cipher_text, padding_method, hashing_algorithm=None):
    if (decryption_algorithm == enums.CryptographicAlgorithm.RSA):
        if (padding_method == enums.PaddingMethod.OAEP):
            hash_algorithm = self._encryption_hash_algorithms.get(hashing_algorithm)
            if (hash_algorithm is None):
                raise exceptions.InvalidField("The hashing algorithm '{0}' is not supported for asymmetric decryption.".format(hashing_algorithm))
            padding_method = asymmetric_padding.OAEP(mgf=asymmetric_padding.MGF1(algorithm=hash_algorithm()), algorithm=hash_algorithm(), label=None)
        elif (padding_method == enums.PaddingMethod.PKCS1v15):
            padding_method = asymmetric_padding.PKCS1v15()
        else:
            raise exceptions.InvalidField("The padding method '{0}' is not supported for asymmetric decryption.".format(padding_method))
        backend = default_backend()
        try:
            private_key = backend.load_der_private_key(decryption_key, None)
        except Exception:
            try:
                private_key = backend.load_pem_private_key(decryption_key, None)
            except Exception:
                raise exceptions.CryptographicFailure('The private key bytes could not be loaded.')
        plain_text = private_key.decrypt(cipher_text, padding_method)
        return plain_text
    else:
        raise exceptions.InvalidField("The cryptographic algorithm '{0}' is not supported for asymmetric decryption.".format(decryption_algorithm))

Encrypt data using asymmetric decryption.

Args:
decryption_algorithm (CryptographicAlgorithm): An enumeration
specifying the asymmetric decryption algorithm to use for
decryption. Required.
decryption_key (bytes): The bytes of the private key to use for
decryption. Required.
cipher_text (bytes): The bytes to be decrypted. Required.
padding_method (PaddingMethod): An enumeration specifying the
padding method to use with the asymmetric decryption
algorithm. Required.
hashing_algorithm (HashingAlgorithm): An enumeration specifying
the hashing algorithm to use with the decryption padding
method. Required, if the padding method is OAEP. Optional
otherwise, defaults to None.

Returns:
dict: A dictionary containing the decrypted data, with at least
the following key/value field:
* plain_text - the bytes of the decrypted data

Raises:
InvalidField: Raised when the algorithm is unsupported or the
length is incompatible with the algorithm.
CryptographicFailure: Raised when the key generation process
fails.


def save_page(self, path=None):
    path = _prepare_path(path, 'html')
    with open(path, 'wb') as f:
        f.write(encode_string(self.body))
    return path

Save a snapshot of the page.

If invoked without arguments, it will save a file to :data:`capybara.save_path` and the
file will be given a randomly generated filename. If invoked with a relative path, the path
will be relative to :data:`capybara.save_path`.

Args:
path (str, optional): The path to where it should be saved.

Returns:
str: The path to which the file was saved.


def __init__(self, conf, conn=None):
    super(HttpFilesSource, self).__init__(conf)
    self._SetDefaults(conf)
    if not conn:
        conn = pycurl.Curl()
        conn.setopt(pycurl.NOPROGRESS, 1)
        conn.setopt(pycurl.NOSIGNAL, 1)
        conn.setopt(pycurl.TIMEOUT, 60)
        conn.setopt(pycurl.USERAGENT, 'nsscache')
        if self.conf['http_proxy']:
            conn.setopt(pycurl.PROXY, self.conf['http_proxy'])
    self.conn = conn

Initialise the HTTP Data Source.

Args:
conf: config.Config instance
conn: pycurl Curl object


def _send_request(url_id, data=None, json=None, req_type=None):
    url = (settings.SEEDER_INFO_URL % url_id)
    if (not req_type):
        req_type = requests.get
    resp = req_type(url, data=data, json=json, timeout=settings.SEEDER_TIMEOUT, headers={'User-Agent': settings.USER_AGENT, 'Authorization': settings.SEEDER_TOKEN})
    resp.raise_for_status()
    data = resp.json()
    return data

Send request to Seeder's API.

Args:
url_id (str): ID used as identification in Seeder.
data (obj, default None): Optional parameter for data.
json (obj, default None): Optional parameter for JSON body.
req_type (fn, default None): Request method used to send/download the
data. If none, `requests.get` is used.

Returns:
dict: Data from Seeder.


def update_vm(access_token, subscription_id, resource_group, vm_name, body):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Compute/virtualMachines/', vm_name, '?api-version=', COMP_API])
    return do_put(endpoint, body, access_token)

Update a virtual machine with a new JSON body. E.g. do a GET, change something, call this.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vm_name (str): Name of the virtual machine.
body (dict): JSON body of the VM.

Returns:
HTTP response.


def CheckTaskReadyForMerge(self, task):

    if self._storage_type != definitions.STORAGE_TYPE_SESSION:
      raise IOError('Unsupported storage type.')

    if not self._processed_task_storage_path:
      raise IOError('Missing processed task storage path.')

    processed_storage_file_path = self._GetProcessedStorageFilePath(task)

    try:
      stat_info = os.stat(processed_storage_file_path)
    except (IOError, OSError):
      return False

    task.storage_file_size = stat_info.st_size
    return True

Checks if a task is ready for merging with this session storage.

If the task is ready to be merged, this method also sets the task's
storage file size.

Args:
task (Task): task.

Returns:
bool: True if the task is ready to be merged.

Raises:
IOError: if the storage type is not supported or
OSError: if the storage type is not supported or
if the temporary path for the task storage does not exist.


def update_connection_endpoint(self, connection_id, endpoint):

        if connection_id in self._connections:
            connection_info = self._connections[connection_id]
            self._connections[connection_id] = \
                ConnectionInfo(connection_info.connection_type,
                               connection_info.connection,
                               endpoint,
                               connection_info.status,
                               connection_info.public_key)

        else:
            LOGGER.debug("Could not update the endpoint %s for "
                         "connection_id %s. The connection does not "
                         "exist.",
                         endpoint,
                         connection_id)

Adds the endpoint to the connection definition. When the
connection is created by the send/receive thread, we do not
yet have the endpoint of the remote node. That is not known
until we process the incoming ConnectRequest.

Args:
connection_id (str): The identifier for the connection.
endpoint (str): A zmq-style uri which identifies a publically
reachable endpoint.


def usergroups_disable(self, *, usergroup: str, **kwargs) -> SlackResponse:
    self._validate_xoxp_token()
    kwargs.update({'usergroup': usergroup})
    return self.api_call('usergroups.disable', json=kwargs)

Disable an existing User Group

Args:
usergroup (str): The encoded ID of the User Group to disable.
e.g. 'S0604QSJC'


def msgBox(self, promptType, _timeout=(- 1), **options):
    if (promptType == 'confirm'):
        return self._sendConfirmPrompt(_timeout, options)
    else:
        raise ValueError('Unknown prompt type: {}'.format(promptType))

Send a user prompt request to the GUI

Arguments:
promptType (string):
The prompt type to send to the GUI. Currently
the only type supported is 'confirm'.

_timeout (int):
The optional amount of time for which the prompt
should be displayed to the user before a timeout occurs.
Defaults to -1 which indicates there is no timeout limit.

options (dict):
The keyword arguments that should be passed to the requested
prompt type. Check prompt specific sections below for information on what
arguments are expected to be present.

Raises:
ValueError:
If the prompt type received is an unexpected value

**Confirm Prompt**

Display a message to the user and prompt them for a confirm/deny
response to the message.

Arguments:
msg (string):
The message to display to the user

Returns:
True if the user picks 'Confirm', False if the user picks 'Deny'

Raises:
KeyError:
If the options passed to the prompt handler doesn't contain a
`msg` attribute.

APITimeoutError:
If the timeout value is reached without receiving a response.


def Deserialize(self, reader):

        self.Script = reader.ReadVarBytes()
        self.ParameterList = reader.ReadVarBytes()
        self.ReturnType = reader.ReadByte()

Deserialize full object.

Args:
reader (neo.IO.BinaryReader):


def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], *init_inputs, **kwargs):
    try:
        tokenizer = BertTokenizer.from_pretrained(pretrained_model_name_or_path, *init_inputs, **kwargs)
    except:
        from .tokenization_bert_fast import BertTokenizerFast
        tokenizer = BertTokenizerFast.from_pretrained(pretrained_model_name_or_path, *init_inputs, **kwargs)
    return cls.from_tokenizer(tokenizer, **kwargs)

Instantiate a `TFBertTokenizer` from a pre-trained tokenizer.

Args:
pretrained_model_name_or_path (`str` or `os.PathLike`):
The name or path to the pre-trained tokenizer.

Examples:

```python
from transformers import TFBertTokenizer

tf_tokenizer = TFBertTokenizer.from_pretrained("google-bert/bert-base-uncased")
```


def _resolve_attribute_match(self, match):
    if (match.group(1) == 'cluster'):
        return str(self.cluster_id)
    return self.get(match.group(1), match.group(0))

Replaces a reference to an attribute with the value of the attribute.

Args:
match (re.match object): A match object containing a match to a reference to an attribute.


def closest_eere(latitude, longitude):

    with open(env.SRC_PATH + '/eere_meta.csv') as eere_meta:
        stations = csv.DictReader(eere_meta)
        d = 9999
        station_code = ''
        station_name = ''
        for station in stations:
            new_dist = great_circle((latitude, longitude),
                                    (float(station['latitude']),
                                     float(station['longitude']))).miles
            if new_dist <= d:
                d = new_dist
                station_code = station['station_code']
                station_name = station['weather_station']
        return station_code, station_name
    raise KeyError('station not found')

Find closest station from the new(er) list.

Warning: There may be some errors with smaller non US stations.

Args:
latitude (float)
longitude (float)

Returns:
tuple (station_code (str), station_name (str))


def set_pipeline_definition(self):
    if (not self.pipeline_id):
        self.get_pipeline_id()
    json_def = self.datapipeline_data['json_definition']
    try:
        pipelineobjects = translator.definition_to_api_objects(json_def)
        parameterobjects = translator.definition_to_api_parameters(json_def)
        parametervalues = translator.definition_to_parameter_values(json_def)
    except translator.PipelineDefinitionError as error:
        LOG.warning(error)
        raise DataPipelineDefinitionError
    response = self.client.put_pipeline_definition(pipelineId=self.pipeline_id, pipelineObjects=pipelineobjects, parameterObjects=parameterobjects, parameterValues=parametervalues)
    LOG.debug(response)
    LOG.info('Successfully applied pipeline definition')
    return response

Translates the json definition and puts it on created pipeline

Returns:
dict: the response of the Boto3 command


def login_with_password_no_sync(self, username, password):
    warn('login_with_password_no_sync is deprecated. Use login with sync=False.', DeprecationWarning)
    return self.login(username, password, sync=False)

Deprecated. Use ``login`` with ``sync=False``.

Login to the homeserver.

Args:
username (str): Account username
password (str): Account password

Returns:
str: Access token

Raises:
MatrixRequestError


def get_attribute(self, obj, attr):
    if (attr == '*'):
        return obj
    if isinstance(obj, Mapping):
        return obj.get(attr, None)
    return getattr(obj, attr, None)

Get attribute of given object instance.

Reason for existence of this method is the fact that  'attribute' can
be also object's key from if is a dict or any other kind of mapping.

Note: it will return None if attribute key does not exist

Args:
obj (object): internal object to retrieve data from

Returns:
internal object's key value or attribute


async def remove(self, index=""):

        if not self.state == 'ready':
            logger.debug("Trying to remove from wrong state '{}'".format(self.state))
            return

        if index == "":
            self.statuslog.error("Must provide index to remove")
            return
        elif index == "all":
            self.queue = []
            self.update_queue()
            self.statuslog.info("Removed all songs")
            return

        indexes = index.split("-")
        self.logger.debug("Removing {}".format(indexes))

        try:
            if len(indexes) == 0:
                self.statuslog.error("Remove must specify an index or range")
                return
            elif len(indexes) == 1:
                num_lower = int(indexes[0]) - 1
                num_upper = num_lower + 1
            elif len(indexes) == 2:
                num_lower = int(indexes[0]) - 1
                num_upper = int(indexes[1])
            else:
                self.statuslog.error("Cannot have more than 2 indexes for remove range")
                return
        except TypeError:
            self.statuslog.error("Remove index must be a number")
            return
        except ValueError:
            self.statuslog.error("Remove index must be a number")
            return

        if num_lower < 0 or num_lower >= len(self.queue) or num_upper > len(self.queue):
            if len(self.queue) == 0:
                self.statuslog.warning("No songs in queue")
            elif len(self.queue) == 1:
                self.statuslog.error("Remove index must be 1 (only 1 song in queue)")
            else:
                self.statuslog.error("Remove index must be between 1 and {}".format(len(self.queue)))
            return

        if num_upper <= num_lower:
            self.statuslog.error("Second index in range must be greater than first")
            return

        lower_songname = self.queue[num_lower][1]
        for num in range(0, num_upper - num_lower):
            self.logger.debug("Removed {}".format(self.queue[num_lower][1]))
            self.queue.pop(num_lower)

        if len(indexes) == 1:
            self.statuslog.info("Removed {}".format(lower_songname))
        else:
            self.statuslog.info("Removed songs {}-{}".format(num_lower + 1, num_upper))

        self.update_queue()

The remove command

Args:
index (str): The index to remove, can be either a number, or a range in the for '##-##'


def display_hierarchy(root_ad_unit, all_ad_units):
    parent_id_to_children = collections.defaultdict(list)
    for ad_unit in all_ad_units:
        if ('parentId' in ad_unit):
            parent_id_to_children[ad_unit['parentId']].append(ad_unit)
    parent_id_to_children = dict(parent_id_to_children)
    display_hierarchy_helper(root_ad_unit, parent_id_to_children, 0)

Display the ad units as a tree.

Args:
root_ad_unit: The root ad unit to begin from.
all_ad_units: A list containing all ad units.


def from_paths(cls, path, bs=64, tfms=(None, None), trn_name='train', val_name='valid', test_name=None, test_with_labels=False, num_workers=8):
    assert (not ((tfms[0] is None) or (tfms[1] is None))), 'please provide transformations for your train and validation sets'
    (trn, val) = [folder_source(path, o) for o in (trn_name, val_name)]
    if test_name:
        test = (folder_source(path, test_name) if test_with_labels else read_dir(path, test_name))
    else:
        test = None
    datasets = cls.get_ds(FilesIndexArrayDataset, trn, val, tfms, path=path, test=test)
    return cls(path, datasets, bs, num_workers, classes=trn[2])

Read in images and their labels given as sub-folder names

Arguments:
path: a root path of the data (used for storing trained models, precomputed values, etc)
bs: batch size
tfms: transformations (for data augmentations). e.g. output of `tfms_from_model`
trn_name: a name of the folder that contains training images.
val_name:  a name of the folder that contains validation images.
test_name:  a name of the folder that contains test images.
num_workers: number of workers

Returns:
ImageClassifierData


def encode_schedule(schedule):
    (interpolation, steps, pmfs) = schedule
    return ((interpolation + ' ') + ' '.join((((('@' + str(s)) + ' ') + ' '.join(map(str, p))) for (s, p) in zip(steps, pmfs))))

Encodes a schedule tuple into a string.

Args:
schedule: A tuple containing (interpolation, steps, pmfs), where
interpolation is a string specifying the interpolation strategy, steps
is an int array_like of shape [N] specifying the global steps, and pmfs is
an array_like of shape [N, M] where pmf[i] is the sampling distribution
at global step steps[i]. N is the number of schedule requirements to
interpolate and M is the size of the probability space.

Returns:
The string encoding of the schedule tuple.


def as_json_range(self, name):
    return {'Name': name, 'Values': [json.dumps(v) for v in self.values]}

Represent the parameter range as a dictionary suitable for a request to
create an Amazon SageMaker hyperparameter tuning job using one of the deep learning frameworks.

The deep learning framework images require that hyperparameters be serialized as JSON.

Args:
name (str): The name of the hyperparameter.

Returns:
dict[str, list[str]]: A dictionary that contains the name and values of the hyperparameter,
where the values are serialized as JSON.


def _Open(self, path_spec, mode='rb'):

    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    file_object = resolver.Resolver.OpenFileObject(
        path_spec.parent, resolver_context=self._resolver_context)

    try:
      vshadow_volume = pyvshadow.volume()
      vshadow_volume.open_file_object(file_object)
    except:
      file_object.close()
      raise

    self._file_object = file_object
    self._vshadow_volume = vshadow_volume

Opens the file system object defined by path specification.

Args:
path_spec (PathSpec): path specification.
mode (Optional[str]): file access mode. The default is 'rb' which
represents read-only binary.

Raises:
AccessError: if the access to open the file was denied.
IOError: if the file system object could not be opened.
PathSpecError: if the path specification is incorrect.
ValueError: if the path specification is invalid.


def less(x, y):
    return math_ops.less(x, y)

Element-wise truth value of (x < y).

Args:
x: Tensor or variable.
y: Tensor or variable.

Returns:
A bool tensor.


def apply(self, func, num_splits=None, other_axis_partition=None, maintain_partitioning=True, **kwargs):
    import dask
    if (num_splits is None):
        num_splits = len(self.list_of_blocks)
    if (other_axis_partition is not None):
        return [DaskFramePartition(dask.delayed(obj)) for obj in deploy_func_between_two_axis_partitions(self.axis, func, num_splits, len(self.list_of_blocks), kwargs, *dask.compute(*tuple((self.list_of_blocks + other_axis_partition.list_of_blocks))))]
    args = [self.axis, func, num_splits, kwargs, maintain_partitioning]
    args.extend(dask.compute(*self.list_of_blocks))
    return [DaskFramePartition(dask.delayed(obj)) for obj in deploy_axis_func(*args)]

Applies func to the object.

See notes in Parent class about this method.

Args:
func: The function to apply.
num_splits: The number of times to split the result object.
other_axis_partition: Another `DaskFrameAxisPartition` object to apply to
func with this one.

Returns:
A list of `DaskFramePartition` objects.


def make_adapt_function(self):
    if self._adapt_function is not None:
        return self._adapt_function

    def adapt_step(iterator):
        data = next(iterator)
        self._adapt_maybe_build(data)
        self.update_state(data)
    if self._steps_per_execution.numpy().item() == 1:
        adapt_fn = adapt_step
    else:

        def adapt_fn(iterator):
            for _ in math_ops.range(self._steps_per_execution):
                adapt_step(iterator)
    if not self._run_eagerly:
        adapt_fn = def_function.function(adapt_fn)
    self._adapt_function = adapt_fn
    return self._adapt_function

Creates a function to execute one step of `adapt`.

This method can be overridden to support custom adapt logic.
This method is called by `PreprocessingLayer.adapt`.

Typically, this method directly controls `tf.function` settings,
and delegates the actual state update logic to
`PreprocessingLayer.update_state`.

This function is cached the first time `PreprocessingLayer.adapt`
is called. The cache is cleared whenever `PreprocessingLayer.compile`
is called.

Returns:
Function. The function created by this method should accept a
`tf.data.Iterator`, retrieve a batch, and update the state of the
layer.


def energy_upperbound(self, spins):
    subtheta = self.theta.copy()
    subtheta.fix_variables(spins)
    trees = self._trees
    if (not trees):
        assert ((not subtheta.linear) and (not subtheta.quadratic))
        return subtheta.offset
    energy = Plus(self.message_upperbound(trees, {}, subtheta), subtheta.offset)
    return energy

A formula for an upper bound on the energy of Theta with spins fixed.

Args:
spins (dict): Spin values for a subset of the variables in Theta.

Returns:
Formula that upper bounds the energy with spins fixed.


def sync_proxy(self, mri, block):

        subscribe = Subscribe(path=[mri], delta=True)
        done_queue = Queue()

        def handle_response(response):

            if not isinstance(response, Delta):

                self.log.debug("Proxy got response %r", response)
                done_queue.put(None)
            else:
                cothread.Callback(
                    self._handle_response, response, block, done_queue)

        subscribe.set_callback(handle_response)
        IOLoopHelper.call(self._send_request, subscribe)
        done_queue.get(timeout=DEFAULT_TIMEOUT)

Abstract method telling the ClientComms to sync this proxy Block
with its remote counterpart. Should wait until it is connected

Args:
mri (str): The mri for the remote block
block (BlockModel): The local proxy Block to keep in sync


def restore(self, fade=False):

        try:
            if self.is_coordinator:
                self._restore_coordinator()
        finally:
            self._restore_volume(fade)

        if self.is_coordinator:
            if self.transport_state == 'PLAYING':
                self.device.play()
            elif self.transport_state == 'STOPPED':
                self.device.stop()

Restore the state of a device to that which was previously saved.

For coordinator devices restore everything. For slave devices
only restore volume etc., not transport info (transport info
comes from the slave's coordinator).

Args:
fade (bool): Whether volume should be faded up on restore.


def comments_1(self, value=None):
    if (value is not None):
        try:
            value = str(value)
        except ValueError:
            raise ValueError('value {} need to be of type str for field `comments_1`'.format(value))
        if (',' in value):
            raise ValueError('value should not contain a comma for field `comments_1`')
    self._comments_1 = value

Corresponds to IDD Field `comments_1`

Args:
value (str): value for IDD Field `comments_1`
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

Raises:
ValueError: if `value` is not a valid value


def get_aggregate(self):
    return dict([(aggregate.find('query').text, [ET.tostring(data).lstrip('<data xmlns:cps="www.clusterpoint.com" xmlns:cpse="www.clusterpoint.com">').strip().rstrip('</data>') for data in aggregate.findall('data')]) for aggregate in self._content.findall('aggregate')])

Get aggregate data.

Returns:
A dict in with queries as keys and results as values.


def Add(self, rdf_value, timestamp=None, suffix=None, mutation_pool=None):
    return self.StaticAdd(self.collection_id, rdf_value, timestamp=timestamp, suffix=suffix, mutation_pool=mutation_pool)

Adds an rdf value to the collection.

Adds an rdf value to the collection. Does not require that the collection
be locked.

Args:
rdf_value: The rdf value to add to the collection.
timestamp: The timestamp (in microseconds) to store the rdf value at.
Defaults to the current time.
suffix: A 'fractional timestamp' suffix to reduce the chance of
collisions. Defaults to a random number.
mutation_pool: A MutationPool object to write to.

Returns:
The pair (timestamp, suffix) which identifies the value within the
collection.

Raises:
ValueError: rdf_value has unexpected type.