def ShapeEquals(tensor_proto, shape):
    if not isinstance(tensor_proto, tensor_pb2.TensorProto):
        raise TypeError(f'`tensor_proto` must be a tensor_pb2.TensorProto object, but got type {type(tensor_proto)}.')
    if isinstance(shape, tensor_shape_pb2.TensorShapeProto):
        shape = [d.size for d in shape.dim]
    elif not isinstance(shape, (list, tuple)):
        raise TypeError(f'`shape` must be a list or tuple, but got type {type(shape)}.')
    tensor_shape_list = [d.size for d in tensor_proto.tensor_shape.dim]
    return all((x == y for x, y in zip(tensor_shape_list, shape)))

Returns True if "tensor_proto" has the given "shape".

Args:
tensor_proto: A TensorProto.
shape: A tensor shape, expressed as a TensorShape, list, or tuple.

Returns:
True if "tensor_proto" has the given "shape", otherwise False.

Raises:
TypeError: If "tensor_proto" is not a TensorProto, or shape is not a
TensorShape, list, or tuple.


def compute_batch_indices(batch_size, beam_size):

  batch_pos = tf.range(batch_size * beam_size)
  batch_pos = tf.reshape(batch_pos, [batch_size, beam_size])
  return batch_pos

Computes the i'th coordinate that contains the batch index for gathers.

Batch pos is a tensor like [[0,0,0,0,],[1,1,1,1],..]. It says which
batch the beam item is in. This will create the i of the i,j coordinate
needed for the gather.

Args:
batch_size: Batch size
beam_size: Size of the beam.
Returns:
batch_pos: [batch_size, beam_size] tensor of ids


def check(self):
    for info in self.get_info():
        if (info.free < info.limit):
            return info

Check resource levels.

Returns:
None, ResourceInfo: If None is provided, no levels are exceeded.
Otherwise, the first ResourceInfo exceeding limits is returned.


def get_bel_versions() -> List[str]:
    spec_dir = config['bel']['lang']['specifications']
    fn = f'{spec_dir}/versions.json'
    with open(fn, 'r') as f:
        versions = json.load(f)
    return versions

Get BEL Language versions supported

Get the list of all BEL Language versions supported.  The file this depends
on is generated by belspec_yaml2json and is kept up to date using
`make update_ebnf` or `make update_parsers`.  You can also run `belspec_yaml2json`
directly as it's added as a command by pip install.

Returns:
List[str]: list of versions


def parse_tensor_name_with_slicing(in_str):
    if in_str.count('[') == 1 and in_str.endswith(']'):
        tensor_name = in_str[:in_str.index('[')]
        tensor_slicing = in_str[in_str.index('['):]
    else:
        tensor_name = in_str
        tensor_slicing = ''
    return (tensor_name, tensor_slicing)

Parse tensor name, potentially suffixed by slicing string.

Args:
in_str: (str) Input name of the tensor, potentially followed by a slicing
string. E.g.: Without slicing string: "hidden/weights/Variable:0", with
slicing string: "hidden/weights/Variable:0[1, :]"

Returns:
(str) name of the tensor
(str) slicing string, if any. If no slicing string is present, return "".


def prepare_framework(estimator, s3_operations):

    if estimator.code_location is not None:
        bucket, key = fw_utils.parse_s3_url(estimator.code_location)
        key = os.path.join(key, estimator._current_job_name, 'source', 'sourcedir.tar.gz')
    else:
        bucket = estimator.sagemaker_session._default_bucket
        key = os.path.join(estimator._current_job_name, 'source', 'sourcedir.tar.gz')
    script = os.path.basename(estimator.entry_point)
    if estimator.source_dir and estimator.source_dir.lower().startswith('s3:
        code_dir = estimator.source_dir
        estimator.uploaded_code = fw_utils.UploadedCode(s3_prefix=code_dir, script_name=script)
    else:
        code_dir = 's3:
        estimator.uploaded_code = fw_utils.UploadedCode(s3_prefix=code_dir, script_name=script)
        s3_operations['S3Upload'] = [{
            'Path': estimator.source_dir or script,
            'Bucket': bucket,
            'Key': key,
            'Tar': True
        }]
    estimator._hyperparameters[sagemaker.model.DIR_PARAM_NAME] = code_dir
    estimator._hyperparameters[sagemaker.model.SCRIPT_PARAM_NAME] = script
    estimator._hyperparameters[sagemaker.model.CLOUDWATCH_METRICS_PARAM_NAME] = \
        estimator.enable_cloudwatch_metrics
    estimator._hyperparameters[sagemaker.model.CONTAINER_LOG_LEVEL_PARAM_NAME] = estimator.container_log_level
    estimator._hyperparameters[sagemaker.model.JOB_NAME_PARAM_NAME] = estimator._current_job_name
    estimator._hyperparameters[sagemaker.model.SAGEMAKER_REGION_PARAM_NAME] = \
        estimator.sagemaker_session.boto_region_name

Prepare S3 operations (specify where to upload `source_dir`) and environment variables
related to framework.

Args:
estimator (sagemaker.estimator.Estimator): The framework estimator to get information from and update.
s3_operations (dict): The dict to specify s3 operations (upload `source_dir`).


def get_connection_count(self, id=None, endpoint=None):

        return self._call_endpoint(GET_CONNECTION_COUNT, id=id, endpoint=endpoint)

Gets the number of nodes connected to the endpoint
Args:
id: (int, optional) id to use for response tracking
endpoint: (RPCEndpoint, optional) endpoint to specify to use
Returns:
json object of the result or the error encountered in the RPC call


def ge(self, other, axis="columns", level=None):

        return self._binary_op("ge", other, axis=axis, level=level)

Checks element-wise that this is greater than or equal to other.

Args:
other: A DataFrame or Series or scalar to compare to.
axis: The axis to perform the gt over.
level: The Multilevel index level to apply gt over.

Returns:
A new DataFrame filled with Booleans.


def get_country_info_from_iso3(cls, iso3, use_live=True, exception=None):
    countriesdata = cls.countriesdata(use_live=use_live)
    country = countriesdata['countries'].get(iso3.upper())
    if (country is not None):
        return country
    if (exception is not None):
        raise exception
    return None

Get country information from ISO3 code

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

Returns:
Optional[Dict[str]]: country information


def tag_versions(repo_path):
    repo = dulwich.repo.Repo(repo_path)
    tags = get_tags(repo)
    maj_version = 0
    feat_version = 0
    fix_version = 0
    last_maj_version = 0
    last_feat_version = 0
    result = []
    for (commit_sha, children) in reversed(get_children_per_first_parent(repo_path).items()):
        commit = get_repo_object(repo, commit_sha)
        (maj_version, feat_version, fix_version) = get_version(commit=commit, tags=tags, maj_version=maj_version, feat_version=feat_version, fix_version=fix_version, children=children)
        if ((last_maj_version != maj_version) or (last_feat_version != feat_version)):
            last_maj_version = maj_version
            last_feat_version = feat_version
            tag_name = ('refs/tags/v%d.%d' % (maj_version, feat_version))
            if ON_PYTHON3:
                repo[str.encode(tag_name)] = commit
            else:
                repo[tag_name] = commit
            result.append(('v%d.%d -> %s' % (maj_version, feat_version, commit_sha)))
    return '\n'.join(result)

Given a repo will add a tag for each major version.

Args:
repo_path(str): path to the git repository to tag.


def get_tool_context(self, tool_alias):

        tools_dict = self.get_tools()
        data = tools_dict.get(tool_alias)
        if data:
            return data["context_name"]
        return None

Given a visible tool alias, return the name of the context it
belongs to.

Args:
tool_alias (str): Tool alias to search for.

Returns:
(str): Name of the context that exposes a visible instance of this
tool alias, or None if the alias is not available.


def stop(self, timeout_s=None):

    self._stopping.set()
    with self._current_phase_thread_lock:
      phase_thread = self._current_phase_thread
      if not phase_thread:
        return

    if phase_thread.is_alive():
      phase_thread.kill()

      _LOG.debug('Waiting for cancelled phase to exit: %s', phase_thread)
      timeout = timeouts.PolledTimeout.from_seconds(timeout_s)
      while phase_thread.is_alive() and not timeout.has_expired():
        time.sleep(0.1)
      _LOG.debug('Cancelled phase %s exit',
                 "didn't" if phase_thread.is_alive() else 'did')

    self.test_state.stop_running_phase()

Stops execution of the current phase, if any.

It will raise a ThreadTerminationError, which will cause the test to stop
executing and terminate with an ERROR state.

Args:
timeout_s: int or None, timeout in seconds to wait for the phase to stop.


def do_conneg(accept, supported):

    for result in parse_accept_header(accept):
        mime_type = result[0]
        if (mime_type in supported):
            return mime_type
    return None

Parse accept header and look for preferred type in supported list.

Arguments:
accept - HTTP Accept header
supported - list of MIME type supported by the server

Returns:
supported MIME type with highest q value in request, else None.

FIXME - Should replace this with negotiator2


def merge(self, dataset):

        def merge_data(source, dest):
            for key, value in source.items():
                if isinstance(value, dict):
                    merge_data(value, dest.setdefault(key, {}))
                else:
                    dest[key] = value
            return dest

        merge_data(dataset.data, self._data)

        for h in dataset.task_history:
            if h not in self._task_history:
                self._task_history.append(h)

Merge the specified dataset on top of the existing data.

This replaces all values in the existing dataset with the values from the
given dataset.

Args:
dataset (TaskData): A reference to the TaskData object that should be merged
on top of the existing object.


def write_wav(path, samples, sr=16000):
    max_value = np.abs(np.iinfo(np.int16).min)
    data = (samples * max_value).astype(np.int16)
    scipy.io.wavfile.write(path, sr, data)

Write to given samples to a wav file.
The samples are expected to be floating point numbers
in the range of -1.0 to 1.0.

Args:
path (str): The path to write the wav to.
samples (np.array): A float array .
sr (int): The sampling rate.


def pose_inv(pose):

    pose_inv = np.zeros((4, 4))
    pose_inv[:3, :3] = pose[:3, :3].T
    pose_inv[:3, 3] = -pose_inv[:3, :3].dot(pose[:3, 3])
    pose_inv[3, 3] = 1.0
    return pose_inv

Computes the inverse of a homogenous matrix corresponding to the pose of some
frame B in frame A. The inverse is the pose of frame A in frame B.

Args:
pose: numpy array of shape (4,4) for the pose to inverse

Returns:
numpy array of shape (4,4) for the inverse pose


def pad(x, paddings, dim_name, name=None):

  return PadOperation(
      x, paddings, dim_name, name=name).outputs[0]

Slice operation.

Args:
x: a list of Tensors
paddings: list of integers of size 2, padding size before and after for dim.
dim_name: string, name for the padding dim
name: an optional string
Returns:
a Tensor with shape extended by output_shape for the last axis.


def ParsePathItem(item, opts=None):

  if item == os.path.curdir:
    return CurrentComponent()

  if item == os.path.pardir:
    return ParentComponent()

  recursion = PATH_RECURSION_REGEX.search(item)
  if recursion is None:
    return GlobComponent(item, opts)

  start, end = recursion.span()
  if not (start == 0 and end == len(item)):
    raise ValueError("malformed recursive component")

  if recursion.group("max_depth"):
    max_depth = int(recursion.group("max_depth"))
  else:
    max_depth = None

  return RecursiveComponent(max_depth=max_depth, opts=opts)

Parses string path component to an `PathComponent` instance.

Args:
item: A path component string to be parsed.
opts: A `PathOpts` object.

Returns:
`PathComponent` instance corresponding to given path fragment.

Raises:
ValueError: If the path item contains a recursive component fragment but
cannot be parsed as such.


def _CountClientStatisticByLabel(self, day_buckets, extract_statistic_fn):
    counts = collections.defaultdict(int)
    now = rdfvalue.RDFDatetime.Now()
    for info in self.IterateAllClientsFullInfo(batch_size=db.MAX_COUNT):
        if (not info.metadata.ping):
            continue
        statistic_value = extract_statistic_fn(info)
        for client_label in info.GetLabelsNames(owner='GRR'):
            for day_bucket in day_buckets:
                time_boundary = (now - rdfvalue.Duration.FromDays(day_bucket))
                if (info.metadata.ping > time_boundary):
                    counts[(statistic_value, client_label, day_bucket)] += 1
    return dict(counts)

Returns client-activity metrics for a particular statistic.

Args:
day_buckets: A set of n-day-active buckets.
extract_statistic_fn: A function that extracts the statistic's value from
a ClientFullInfo object.


def translate(self, start=None, end=None, arch_mode=None):

        start_addr = start if start else self.binary.ea_start
        end_addr = end if end else self.binary.ea_end

        self.ir_translator.reset()

        for addr, asm, _ in self.disassemble(start=start_addr, end=end_addr, arch_mode=arch_mode):
            yield addr, asm, self.ir_translator.translate(asm)

Translate to REIL instructions.

Args:
start (int): Start address.
end (int): End address.
arch_mode (int): Architecture mode.

Returns:
(int, Instruction, list): A tuple of the form (address, assembler instruction, REIL instructions).


def _handle_missing_parameters(parameter_values, all_params, required_params, existing_stack=None):
    missing_params = list((set(all_params) - set(parameter_values.keys())))
    if (existing_stack and ('Parameters' in existing_stack)):
        stack_parameters = [p['ParameterKey'] for p in existing_stack['Parameters']]
        for p in missing_params:
            if (p in stack_parameters):
                logger.debug('Using previous value for parameter %s from existing stack', p)
                parameter_values[p] = UsePreviousParameterValue
    final_missing = list((set(required_params) - set(parameter_values.keys())))
    if final_missing:
        raise MissingParameterException(final_missing)
    return list(parameter_values.items())

Handles any missing parameters.

If an existing_stack is provided, look up missing parameters there.

Args:
parameter_values (dict): key/value dictionary of stack definition
parameters
all_params (list): A list of all the parameters used by the
template/blueprint.
required_params (list): A list of all the parameters required by the
template/blueprint.
existing_stack (dict): A dict representation of the stack. If
provided, will be searched for any missing parameters.

Returns:
list of tuples: The final list of key/value pairs returned as a
list of tuples.

Raises:
MissingParameterException: Raised if a required parameter is
still missing.


def diff_prettyHtml(self, diffs):
    html = []
    for (op, data) in diffs:
        text = data.replace('&', '&').replace('<', '<').replace('>', '>').replace('\n', '¶
')
        if (op == self.DIFF_INSERT):
            html.append(('<ins style="background:
        elif (op == self.DIFF_DELETE):
            html.append(('<del style="background:
        elif (op == self.DIFF_EQUAL):
            html.append(('%s' % text))
    return ''.join(html)

Convert a diff array into a pretty HTML report.

Args:
diffs: Array of diff tuples.

Returns:
HTML representation.


def restrict_condition(node, var, condition):
    dnf = []
    restricted = False
    for b in var.bindings:
        match_result = _match_condition(b.data, condition)
        if match_result:
            dnf.append([b])
        else:
            restricted = True
    if not dnf:
        _restrict_counter.inc('unsatisfiable')
        return UNSATISFIABLE
    elif restricted:
        _restrict_counter.inc('restricted')
        return Condition(node, dnf)
    else:
        _restrict_counter.inc('unrestricted')
        return None

Return a restricted condition based on filtered bindings.

Args:
node: The CFGNode.
var: A variable.
condition: A value that we will check each binding for compatibility with.

Returns:
A Condition or None. Each binding of the variable is checked for
compatibility with the condition. If either no bindings match, or all
bindings match, then None is returned.  Otherwise a new Condition is built
from the specified, compatible, bindings.


def get_fba_flux(self, objective):

        flux_result = self.solve_fba(objective)
        fba_fluxes = {}

        for key in self._model.reactions:
            fba_fluxes[key] = flux_result.get_value(self._v_wt[key])
        return fba_fluxes

Return a dictionary of all the fluxes solved by FBA.

Dictionary of fluxes is used in :meth:`.lin_moma` and :meth:`.moma`
to minimize changes in the flux distributions following model
perturbation.

Args:
objective: The objective reaction that is maximized.

Returns:
Dictionary of fluxes for each reaction in the model.


def get_variable_scope_name(value):

  value = getattr(value, "variable_scope", value)
  if isinstance(value, tf.VariableScope):
    return value.name
  elif isinstance(value, six.string_types):
    return value
  else:
    raise ValueError("Not a variable scope: {}".format(value))

Returns the name of the variable scope indicated by the given value.

Args:
value: String, variable scope, or object with `variable_scope` attribute
(e.g., Sonnet module).

Returns:
The name (a string) of the corresponding variable scope.

Raises:
ValueError: If `value` does not identify a variable scope.


def _constrain_L2_grad(op, grad):

  inp = op.inputs[0]
  inp_norm = tf.norm(inp)
  unit_inp = inp / inp_norm

  grad_projection = dot(unit_inp, grad)
  parallel_grad = unit_inp * grad_projection

  is_in_ball = tf.less_equal(inp_norm, 1)
  is_pointed_inward = tf.less(grad_projection, 0)
  allow_grad = tf.logical_or(is_in_ball, is_pointed_inward)
  clip_grad = tf.logical_not(allow_grad)

  clipped_grad = tf.cond(clip_grad, lambda: grad - parallel_grad, lambda: grad)

  return clipped_grad

Gradient for constrained optimization on an L2 unit ball.

This function projects the gradient onto the ball if you are on the boundary
(or outside!), but leaves it untouched if you are inside the ball.

Args:
op: the tensorflow op we're computing the gradient for.
grad: gradient we need to backprop

Returns:
(projected if necessary) gradient.


def GetFileSystem(self, path_spec):

    identifier = self._GetFileSystemCacheIdentifier(path_spec)
    return self._file_system_cache.GetObject(identifier)

Retrieves a file system object defined by path specification.

Args:
path_spec (PathSpec): path specification.

Returns:
FileSystem: a file system object or None if not cached.


def __call__(self, inputs: Union[str, List[str]], **kwargs: Any) -> Union[List[Dict[str, Any]], List[List[Dict[str, Any]]]]:
    outputs = super().__call__(inputs, **kwargs)
    if isinstance(inputs, list) and len(inputs) == 1:
        return outputs[0]
    return outputs

Fill the masked token in the text(s) given as inputs.

Args:
inputs (`str` or `List[str]`):
One or several texts (or one list of prompts) with masked tokens.
targets (`str` or `List[str]`, *optional*):
When passed, the model will limit the scores to the passed targets instead of looking up in the whole
vocab. If the provided targets are not in the model vocab, they will be tokenized and the first
resulting token will be used (with a warning, and that might be slower).
top_k (`int`, *optional*):
When passed, overrides the number of predictions to return.

Return:
A list or a list of list of `dict`: Each result comes as list of dictionaries with the following keys:

- **sequence** (`str`) -- The corresponding input with the mask token prediction.
- **score** (`float`) -- The corresponding probability.
- **token** (`int`) -- The predicted token id (to replace the masked one).
- **token_str** (`str`) -- The predicted token (to replace the masked one).


def fts(self, segment):

        match = self.seg_regex.match(segment)
        if match:
            pre, base, post = match.group('pre'), match.group('base'), match.group('post')
            seg = copy.deepcopy(self.bases[base])
            for m in reversed(pre):
                seg = update_ft_set(seg, self.prefix_dias[m])
            for m in post:
                seg = update_ft_set(seg, self.postfix_dias[m])
            return set(seg)
        else:
            return None

Return features corresponding to segment as list of (value,
feature) tuples

Args:
segment (unicode): segment for which features are to be returned as
Unicode string

Returns:
list: None if `segment` cannot be parsed; otherwise, a list of the
features of `segment` as (value, feature) pairs


def add_metric(self, labels, count_value, sum_value, timestamp=None):

        self.samples.append(Sample(self.name + '_count', dict(zip(self._labelnames, labels)), count_value, timestamp))
        self.samples.append(Sample(self.name + '_sum', dict(zip(self._labelnames, labels)), sum_value, timestamp))

Add a metric to the metric family.

Args:
labels: A list of label values
count_value: The count value of the metric.
sum_value: The sum value of the metric.


def _padding_to_conv_op_padding(padding):
    if (not isinstance(padding, tuple)):
        raise ValueError('padding should be a tuple.')
    if all(((p == SAME) for p in padding)):
        return SAME
    else:
        return VALID

Whether to use SAME or VALID for the underlying convolution op.

Args:
padding: A tuple of members of ALLOWED_PADDINGS, e.g. as returned from
`_fill_and_verify_padding`.

Returns:
One of CONV_OP_ALLOWED_PADDINGS, the padding method to use for the
underlying convolution op.

Raises:
ValueError: If padding is not a tuple.


def _get_entity(self):
    if self._is_ndb():
        return self._model.get_by_id(self._key_name)
    else:
        return self._model.get_by_key_name(self._key_name)

Retrieve entity from datastore.

Uses a different model method for db or ndb models.

Returns:
Instance of the model corresponding to the current storage object
and stored using the key name of the storage object.


async def ban_user(channel, user):
    data = datatools.get_data()
    server_id = channel.server.id
    try:
        (await client.ban(user))
    except discord.errors.Forbidden:
        (await client.send_typing(channel))
        embed = ui_embed.error(channel, 'Ban Error', 'I do not have the permissions to ban that person.')
        (await embed.send())
        return
    if ('warnings' in data['discord']['servers'][server_id][_data.modulename]):
        if (user.id in data['discord']['servers'][server_id][_data.modulename]['warnings']):
            data['discord']['servers'][server_id][_data.modulename]['warnings'][user.id] = 0
            datatools.write_data(data)
    (await client.send_typing(channel))
    embed = ui_embed.user_ban(channel, user)
    (await embed.send())
    try:
        response = "You have been banned from the server '{}' contact the owners to resolve this issue.".format(channel.server.name)
        (await client.send_message(user, response))
    except Exception as e:
        logger.exception(e)

Bans a user from a server

Args:
channel: The channel to send the warning message in
user: The user to give the warning to


def vasp_version_from_outcar(filename='OUTCAR'):
    with open(filename) as f:
        line = f.readline().strip()
    return line

Returns the first line from a VASP OUTCAR file, to get the VASP source version string.

Args:
filename (Str, optional): OUTCAR filename. Defaults to 'OUTCAR'.

Returns:
(Str): The first line read from the OUTCAR file.


def update_mp_firware_version(self, timeout=(- 1)):
    uri = '{}/mpFirmwareVersion'.format(self.data['uri'])
    return self._helper.do_put(uri, None, timeout, None)

Updates the iLO firmware on a physical server to a minimum ILO firmware version required by OneView to
manage the server.

Args:
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
Resource


def configfile_from_path(path, strict=True):
    extension = path.split('.')[(- 1)]
    conf_type = FILE_TYPES.get(extension)
    if (not conf_type):
        raise exc.UnrecognizedFileExtension('Cannot parse file of type {0}. Choices are {1}.'.format(extension, FILE_TYPES.keys()))
    return conf_type(path=path, strict=strict)

Get a ConfigFile object based on a file path.

This method will inspect the file extension and return the appropriate
ConfigFile subclass initialized with the given path.

Args:
path (str): The file path which represents the configuration file.
strict (bool): Whether or not to parse the file in strict mode.

Returns:
confpy.loaders.base.ConfigurationFile: The subclass which is
specialized for the given file path.

Raises:
UnrecognizedFileExtension: If there is no loader for the path.


def create_magic_packet(macaddress):
    if (len(macaddress) == 12):
        pass
    elif (len(macaddress) == 17):
        sep = macaddress[2]
        macaddress = macaddress.replace(sep, '')
    else:
        raise ValueError('Incorrect MAC address format')
    data = (b'FFFFFFFFFFFF' + (macaddress * 16).encode())
    send_data = b''
    for i in range(0, len(data), 2):
        send_data += struct.pack(b'B', int(data[i:(i + 2)], 16))
    return send_data

Create a magic packet.

A magic packet is a packet that can be used with the for wake on lan
protocol to wake up a computer. The packet is constructed from the
mac address given as a parameter.

Args:
macaddress (str): the mac address that should be parsed into a
magic packet.


def get_reference_points(spatial_shapes_list, valid_ratios, device):
    reference_points_list = []
    for lvl, (height, width) in enumerate(spatial_shapes_list):
        ref_y, ref_x = torch.meshgrid(torch.linspace(0.5, height - 0.5, height, dtype=valid_ratios.dtype, device=device), torch.linspace(0.5, width - 0.5, width, dtype=valid_ratios.dtype, device=device), indexing='ij')
        ref_y = ref_y.reshape(-1)[None] / (valid_ratios[:, None, lvl, 1] * height)
        ref_x = ref_x.reshape(-1)[None] / (valid_ratios[:, None, lvl, 0] * width)
        ref = torch.stack((ref_x, ref_y), -1)
        reference_points_list.append(ref)
    reference_points = torch.cat(reference_points_list, 1)
    reference_points = reference_points[:, :, None] * valid_ratios[:, None]
    return reference_points

Get reference points for each feature map. Used in decoder.

Args:
spatial_shapes_list (`list` of `tuple`):
Spatial shapes of the backbone feature maps as a list of tuples.
valid_ratios (`torch.FloatTensor`):
Valid ratios of each feature map, has shape of `(batch_size, num_feature_levels, 2)`.
device (`torch.device`):
Device on which to create the tensors.
Returns:
`torch.FloatTensor` of shape `(batch_size, num_queries, num_feature_levels, 2)`


def check_missing_atoms(self, template=None, ha_only=True):

        missing_atoms = {}

        if not template:
            import protein_residues
            template = protein_residues.normal

        for residue in self.get_residues():

            if not template.has_key(residue.resname):

                raise ValueError('Residue name (%s) not in the template' %residue.resname )

            if ha_only:
                heavy_atoms = [ atom for atom in template[residue.resname]['atoms'].keys()
                                if atom[0] != 'H' and not (atom[0].isdigit() and atom[1] == 'H')]
                reference_set = set(heavy_atoms)
            else:
                reference_set = set(template[residue.resname]['atoms'].keys())

            structure_set = set(residue.child_dict.keys())

            diff = reference_set.difference(structure_set)

            if diff:
                residue_uniq_id = (residue.parent.id, residue.resname, residue.get_id()[1])
                missing_atoms[residue_uniq_id] = list(diff)

        return missing_atoms

Checks for missing atoms based on a template.
Default: Searches for missing heavy atoms (not Hydrogen) based on Bio.Struct.protein_residues

Arguments:
- template, dictionary, keys are residue names, values list of atom names.
- ha_only, boolean, default True, restrict check to heavy atoms.

Returns a dictionary of tuples with the missing atoms per residue.


def _infer_type(str_val, na_value, prev_type):
    if str_val in ('', na_value):
        return prev_type
    type_list = [dtypes.int32, dtypes.int64, dtypes.float32, dtypes.float64, dtypes.string]
    type_functions = [_is_valid_int32, _is_valid_int64, lambda str_val: _is_valid_float(str_val, dtypes.float32), lambda str_val: _is_valid_float(str_val, dtypes.float64), lambda str_val: True]
    for i in range(len(type_list)):
        validation_fn = type_functions[i]
        if validation_fn(str_val) and (prev_type is None or prev_type in type_list[:i + 1]):
            return type_list[i]

Given a string, infers its tensor type.

Infers the type of a value by picking the least 'permissive' type possible,
while still allowing the previous type inference for this column to be valid.

Args:
str_val: String value to infer the type of.
na_value: Additional string to recognize as a NA/NaN CSV value.
prev_type: Type previously inferred based on values of this column that
we've seen up till now.
Returns:
Inferred dtype.


def bash_complete(self, path, cmd, *cmds):
    path = pathlib.Path(path)
    subcmds = list(self.subcmds.keys())
    with path.open('w') as bcf:
        print('_{}() {{'.format(cmd), file=bcf)
        print('COMPREPLY=()', file=bcf)
        print('local cur=${COMP_WORDS[COMP_CWORD]}', end='\n\n', file=bcf)
        optstr = ' '.join(self._bash_comp_command(None))
        print('local options="{}"'.format(optstr), end='\n\n', file=bcf)
        if subcmds:
            print('local commands="{}"'.format(' '.join(subcmds)), file=bcf)
            print('declare -A suboptions', file=bcf)
        for sub in subcmds:
            optstr = ' '.join(self._bash_comp_command(sub))
            print('suboptions[{}]="{}"'.format(sub, optstr), file=bcf)
        condstr = 'if'
        for sub in subcmds:
            print(condstr, '[[ "${COMP_LINE}" == *"', sub, '"* ]] ; then', file=bcf)
            print('COMPREPLY=( `compgen -W "${suboptions[', sub, ']}" -- ${cur}` )', sep='', file=bcf)
            condstr = 'elif'
        print(condstr, '[[ ${cur} == -* ]] ; then', file=bcf)
        print('COMPREPLY=( `compgen -W "${options}" -- ${cur}`)', file=bcf)
        if subcmds:
            print('else', file=bcf)
            print('COMPREPLY=( `compgen -W "${commands}" -- ${cur}`)', file=bcf)
        print('fi', file=bcf)
        print('}', end='\n\n', file=bcf)
        print('complete -F _{0} {0}'.format(cmd), *cmds, file=bcf)

Write bash complete script.

Args:
path (path-like): desired path of the complete script.
cmd (str): command name that should be completed.
cmds (str): extra command names that should be completed.


def has_attribute(self, attribute: str) -> bool:
    return any([(key_node.value == attribute) for (key_node, _) in self.yaml_node.value])

Whether the node has an attribute with the given name.

Use only if is_mapping() returns True.

Args:
attribute: The name of the attribute to check for.

Returns:
True iff the attribute is present.


def setup_logger(config):
    logger = logging.getLogger(PROGRAM_NAME)
    num_level = getattr(logging, config.get('daemon', 'loglevel').upper(), None)
    logger.setLevel(num_level)
    lengths = []
    for section in config:
        lengths.append(len(section))
    width = (sorted(lengths)[(- 1)] + 1)

    def log_format():
        'Produce a log format line.'
        supported_keys = ['asctime', 'levelname', 'process', 'threadName', 'message']
        return ' '.join(['%({0:s})'.format(i) for i in supported_keys])
    custom_format = log_format()
    json_formatter = CustomJsonFormatter(custom_format, prefix=(PROGRAM_NAME + ': '))
    formatter = logging.Formatter('%(asctime)s {program}[%(process)d] %(levelname)-8s %(threadName)-{width}s %(message)s'.format(program=PROGRAM_NAME, width=width))
    if config.has_option('daemon', 'log_file'):
        file_handler = logging.handlers.RotatingFileHandler(config.get('daemon', 'log_file'), maxBytes=config.getint('daemon', 'log_maxbytes'), backupCount=config.getint('daemon', 'log_backups'))
        if config.getboolean('daemon', 'json_log_file'):
            file_handler.setFormatter(json_formatter)
        else:
            file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)
    if config.has_option('daemon', 'log_server'):
        udp_handler = logging.handlers.SysLogHandler((config.get('daemon', 'log_server'), config.getint('daemon', 'log_server_port')))
        if config.getboolean('daemon', 'json_log_server'):
            udp_handler.setFormatter(json_formatter)
        else:
            udp_handler.setFormatter(formatter)
        logger.addHandler(udp_handler)
    if ((not config.has_option('daemon', 'log_file')) and (not config.has_option('daemon', 'log_server'))):
        stream_handler = logging.StreamHandler()
        if config.getboolean('daemon', 'json_stdout'):
            stream_handler.setFormatter(json_formatter)
        else:
            stream_handler.setFormatter(formatter)
        logger.addHandler(stream_handler)
    if config.has_option('daemon', 'stderr_file'):
        sys.stderr = CustomRotatingFileLogger(filepath=config.get('daemon', 'stderr_file'), maxbytes=config.getint('daemon', 'log_maxbytes'), backupcount=config.getint('daemon', 'log_backups'))
    elif (config.has_option('daemon', 'stderr_log_server') and (not config.has_option('daemon', 'stderr_file'))):
        sys.stderr = CustomUdpLogger(server=config.get('daemon', 'log_server'), port=config.getint('daemon', 'log_server_port'))
    else:
        print('messages for unhandled exceptions will go to STDERR')
    return logger

Configure the logging environment.

Notice:
By default logging will go to STDOUT and messages for unhandled
exceptions or crashes will go to STDERR. If log_file and/or log_server
is set then we don't log to STDOUT. Messages for unhandled exceptions
or crashes can only go to either STDERR or to stderr_file or to
stderr_log_server.

Arguments:
config (obj): A configparser object which holds our configuration.

Returns:
A logger with all possible handlers configured.


def apply_orderby(e: exp.Order, df: pd.DataFrame) -> pd.DataFrame:
    orderby_columns = []
    orderby_columns_order = []
    for el in e.expressions:
        orderby_column = el.find(exp.Column).find(exp.Identifier).this
        order = not bool(el.args['desc'])
        orderby_columns.append(orderby_column)
        orderby_columns_order.append(order)
    df = df.sort_values(orderby_columns, ascending=orderby_columns_order)
    return df

Apply ORDER BY clause to the DataFrame.

Args:
- e (exp.Order): Parsed ORDER BY expression.
- df (pd.DataFrame): DataFrame to be sorted.

Returns:
- pd.DataFrame: Sorted DataFrame based on the ORDER BY clause.


def get_export_outputs(export_outputs, predictions):
    if export_outputs is None:
        default_output = export_output_lib.PredictOutput(predictions)
        export_outputs = {signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: default_output}
    if not isinstance(export_outputs, dict):
        raise TypeError(f'`export_outputs` must be dict, received: {export_outputs}.')
    for v in export_outputs.values():
        if not isinstance(v, export_output_lib.ExportOutput):
            raise TypeError(f'Values in `export_outputs` must be ExportOutput objects, received: {export_outputs}.')
    _maybe_add_default_serving_output(export_outputs)
    return export_outputs

Validate export_outputs or create default export_outputs.

Args:
export_outputs: Describes the output signatures to be exported to
`SavedModel` and used during serving. Should be a dict or None.
predictions:  Predictions `Tensor` or dict of `Tensor`.

Returns:
Valid export_outputs dict

Raises:
TypeError: if export_outputs is not a dict or its values are not
ExportOutput instances.


def _ReportSameIdButNotMerged(self, entity_id, reason):
    self.feed_merger.problem_reporter.SameIdButNotMerged(self, entity_id, reason)

Report that two entities have the same id but could not be merged.

Args:
entity_id: The id of the entities.
reason: A string giving a reason why they could not be merged.


def __init__(self, name, description=None, color=None):

        self._label_data = {'name': name}

        if description is not None:
            self._label_data['description'] = description
        if color is not None:
            self._label_data['color'] = color

Initialize Class Properties.

Args:
name (str): The value for this security label.
description (str): A description for this security label.
color (str): A color (hex value) for this security label.


def seed(s):
    try:
        s = int(s)
    except TypeError:
        raise ValueError(f'Argument `s` got an invalid value {s}. Only integers are supported.')
    random_seed.set_seed(s)

Sets the seed for the random number generator.

Uses `tf.set_random_seed`.

Args:
s: an integer.


def showbox(self, force_rerun=False):
    log.debug('{}: running box maker...'.format(self.id))
    if (not self.sphsel_path):
        return ValueError('Please run sphere_selector_using_residues')
    boxfile = op.join(self.dock_dir, '{}_box.pdb'.format(self.id))
    boxscript = op.join(self.dock_dir, '{}_box.in'.format(self.id))
    if ssbio.utils.force_rerun(flag=force_rerun, outfile=boxfile):
        with open(boxscript, 'w') as f:
            f.write('Y\n')
            f.write('0\n')
            f.write('{}\n'.format(op.basename(self.sphsel_path)))
            f.write('1\n')
            f.write('{}'.format(op.basename(boxfile)))
        cmd = 'showbox < {}'.format(boxscript)
        os.chdir(self.dock_dir)
        os.system(cmd)
    if ssbio.utils.is_non_zero_file(boxfile):
        self.box_path = boxfile
        log.debug('{}: successful box creation'.format(self.box_path))
    else:
        log.critical('{}: showbox failed to run on selected spheres file'.format(self.sphsel_path))

Create the dummy PDB box around the selected spheres.

Args:
force_rerun (bool): If method should be rerun even if output file exists


def filter_parts(cls, part_info):
    filtered = OrderedDict()
    for (part_name, info_list) in part_info.items():
        if ((info_list is None) or isinstance(info_list, Exception)):
            continue
        info_list = [i for i in info_list if isinstance(i, cls)]
        if info_list:
            filtered[part_name] = info_list
    return filtered

Filter the part_info dict looking for instances of our class

Args:
part_info (dict): {part_name: [Info] or None} as returned from
Controller.run_hook()

Returns:
dict: {part_name: [info]} where info is a subclass of cls


def FindUnspentCoinsByAssetAndTotal(self, asset_id, amount, from_addr=None, use_standard=False, watch_only_val=0, reverse=False):
    coins = self.FindUnspentCoinsByAsset(asset_id, from_addr=from_addr, use_standard=use_standard, watch_only_val=watch_only_val)
    sum = Fixed8(0)
    for coin in coins:
        sum = (sum + coin.Output.Value)
    if (sum < amount):
        return None
    coins = sorted(coins, key=(lambda coin: coin.Output.Value.value))
    if reverse:
        coins.reverse()
    total = Fixed8(0)
    for coin in coins:
        if (coin.Output.Value == amount):
            return [coin]
    to_ret = []
    for coin in coins:
        total = (total + coin.Output.Value)
        to_ret.append(coin)
        if (total >= amount):
            break
    return to_ret

Finds unspent coin objects totalling a requested value in the wallet limited to those of a certain asset type.

Args:
asset_id (UInt256): a bytearray (len 32) representing an asset on the blockchain.
amount (int): the amount of unspent coins that are being requested.
from_addr (UInt160): a bytearray (len 20) representing an address.
use_standard (bool): whether or not to only include standard contracts ( i.e not a smart contract addr ).
watch_only_val (int): a flag ( 0 or 64 ) indicating whether or not to find coins that are in 'watch only' addresses.

Returns:
list: a list of ``neo.Wallet.Coin`` in the wallet that are not spent. this list is empty if there are not enough coins to satisfy the request.


def _maybe_load_initial_epoch_from_ckpt(self, initial_epoch):
    if self._training_state is not None:
        return self._training_state.maybe_load_initial_epoch_from_ckpt(initial_epoch, mode=ModeKeys.TRAIN)
    return initial_epoch

Maybe load initial epoch from ckpt considering possible worker recovery.

Refer to tensorflow/python/keras/distribute/worker_training_state.py
for more information.

Args:
initial_epoch: The original initial_epoch user passes in in `fit()`.

Returns:
If the training is recovering from previous failure under multi-worker
training setting, return the epoch the training is supposed to continue
at. Otherwise, return the `initial_epoch` the user passes in.


def _serve_audio_metadata(self, request):
    tag = request.args.get('tag')
    run = request.args.get('run')
    sample = int(request.args.get('sample', 0))
    events = self._multiplexer.Tensors(run, tag)
    response = self._audio_response_for_run(events, run, tag, sample)
    return http_util.Respond(request, response, 'application/json')

Given a tag and list of runs, serve a list of metadata for audio.

Note that the actual audio data are not sent; instead, we respond
with URLs to the audio. The frontend should treat these URLs as
opaque and should not try to parse information about them or
generate them itself, as the format may change.

Args:
request: A werkzeug.wrappers.Request object.

Returns:
A werkzeug.Response application.


def from_bytes(value):

    result = (value.decode('utf-8')
              if isinstance(value, six.binary_type) else value)
    if isinstance(result, six.text_type):
        return result
    else:
        raise ValueError(
            '{0!r} could not be converted to unicode'.format(value))

Converts bytes to a string value, if necessary.

Args:
value (Union[str, bytes]): The value to be converted.

Returns:
str: The original value converted to unicode (if bytes) or as passed in
if it started out as unicode.

Raises:
ValueError: If the value could not be converted to unicode.


def codify(combination):

	if (isinstance(combination, int) and
		(combination < 0 or combination >= LIMIT)):
		raise errors.FlagError("Out-of-range flag-combination!")

	codes = []

	for enum in (Style, Color, Fill):
		for flag in enum:
			if combination & flag:
				codes.append(str(flag))

	return ";".join(codes)

Gets escape-codes for flag combinations.

Arguments:
combination (int): Either a single integer-convertible flag
or an OR'd flag-combination.
Returns:
A semi-colon-delimited string of appropriate escape sequences.

Raises:
errors.FlagError if the combination is out-of-range.


def validate_context(context):

  if not context.service_registry.service_record(context.service_name):
    fail("service: {} not found in service registry: {}".format(
         context.service_name, context.service_registry.filespec))
  service_type = context.service_registry.service_record(context.service_name)["type"]

  if context.key not in EFConfig.VERSION_KEYS:
    fail("invalid key: {}; see VERSION_KEYS in ef_config for supported keys".format(context.key))

  if "allowed_types" in EFConfig.VERSION_KEYS[context.key] and \
          service_type not in EFConfig.VERSION_KEYS[context.key]["allowed_types"]:
    fail("service_type: {} is not allowed for key {}; see VERSION_KEYS[KEY]['allowed_types']"
         "in ef_config and validate service registry entry".format(service_type, context.key))

  return True

Set the key for the current context.
Args:
context: a populated EFVersionContext object


def generate(organization, package, destination):
    gen = ResourceGenerator(organization, package)
    tmp = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
    try:
        tmp.write(gen.conf())
    finally:
        tmp.close()
    shutil.copy(tmp.name, os.path.join(destination, 'conf.py'))
    tmp = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
    try:
        tmp.write(gen.makefile())
    finally:
        tmp.close()
    shutil.copy(tmp.name, os.path.join(destination, 'Makefile'))

Generates the Sphinx configuration and Makefile.

Args:
organization (str): the organization name.
package (str): the package to be documented.
destination (str): the destination directory.


def clear_events(self, event_name):
    self.lock.acquire()
    try:
        q = self.get_event_q(event_name)
        q.queue.clear()
    except queue.Empty:
        return
    finally:
        self.lock.release()

Clear all events of a particular name.

Args:
event_name: Name of the events to be popped.


def to_bazelrc_lines(self, dpav: DiscoverablePathsAndVersions) -> list[str]:
    dpav.get_relevant_paths_and_versions(self)
    rc = []
    build_and_test_tag_filters = list(_DEFAULT_BUILD_AND_TEST_TAG_FILTERS)
    if self.os == OS.DARWIN:
        build_and_test_tag_filters.append('-no_mac')
    if self.host_compiler == HostCompiler.GCC:
        rc.append(f'build --action_env GCC_HOST_COMPILER_PATH={dpav.gcc_path}')
    elif self.host_compiler == HostCompiler.CLANG:
        rc.append(f'build --action_env CLANG_COMPILER_PATH={dpav.clang_path}')
        rc.append(f'build --repo_env CC={dpav.clang_path}')
        rc.append(f'build --repo_env BAZEL_COMPILER={dpav.clang_path}')
        self.compiler_options.append('-Wno-error=unused-command-line-argument')
        if dpav.lld_path:
            rc.append(f'build --linkopt --ld-path={dpav.lld_path}')
    if self.backend == Backend.CPU:
        build_and_test_tag_filters.append('-gpu')
    elif self.backend == Backend.CUDA:
        build_and_test_tag_filters.append('-rocm-only')
        build_and_test_tag_filters.append('-sycl-only')
        compiler_pair = (self.cuda_compiler, self.host_compiler)
        if compiler_pair == (CudaCompiler.CLANG, HostCompiler.CLANG):
            rc.append('build --config cuda_clang')
            rc.append(f'build --action_env CLANG_CUDA_COMPILER_PATH={dpav.clang_path}')
        elif compiler_pair == (CudaCompiler.NVCC, HostCompiler.CLANG):
            rc.append('build --config cuda_nvcc')
            rc.append(f'build --action_env CLANG_CUDA_COMPILER_PATH={dpav.clang_path}')
        elif compiler_pair == (CudaCompiler.NVCC, HostCompiler.GCC):
            rc.append('build --config cuda')
        else:
            raise NotImplementedError('CUDA clang with host compiler gcc not supported')
        if dpav.cuda_version:
            rc.append(f'build:cuda --repo_env HERMETIC_CUDA_VERSION={dpav.cuda_version}')
        rc.append(f'build:cuda --repo_env HERMETIC_CUDA_COMPUTE_CAPABILITIES={','.join(dpav.cuda_compute_capabilities)}')
        if dpav.cudnn_version:
            rc.append(f'build:cuda --repo_env HERMETIC_CUDNN_VERSION={dpav.cudnn_version}')
        if dpav.local_cuda_path:
            rc.append(f'build:cuda --repo_env LOCAL_CUDA_PATH={dpav.local_cuda_path}')
        if dpav.local_cudnn_path:
            rc.append(f'build:cuda --repo_env LOCAL_CUDNN_PATH={dpav.local_cudnn_path}')
        if dpav.local_nccl_path:
            rc.append(f'build:cuda --repo_env LOCAL_NCCL_PATH={dpav.local_nccl_path}')
        if not self.using_nccl:
            rc.append('build --config nonccl')
    elif self.backend == Backend.ROCM:
        build_and_test_tag_filters.append('-cuda-only')
        build_and_test_tag_filters.append('-sycl-only')
        compiler_pair = (self.rocm_compiler, self.host_compiler)
        if compiler_pair == (RocmCompiler.HIPCC, HostCompiler.CLANG):
            rc.append('build --config rocm')
            rc.append(f'build --action_env CLANG_COMPILER_PATH={dpav.clang_path}')
        elif compiler_pair == (RocmCompiler.HIPCC, HostCompiler.GCC):
            rc.append('build --config rocm')
        else:
            raise NotImplementedError('ROCm clang with host compiler not supported')
    elif self.backend == Backend.SYCL:
        build_and_test_tag_filters.append('-cuda-only')
        build_and_test_tag_filters.append('-rocm-only')
        build_and_test_tag_filters.append('-no-sycl')
        rc.append('build --config sycl')
    if dpav.ld_library_path:
        rc.append(f'build --action_env LD_LIBRARY_PATH={dpav.ld_library_path}')
    if dpav.clang_major_version in (16, 17, 18):
        self.compiler_options.append('-Wno-gnu-offsetof-extensions')
    if dpav.clang_major_version and dpav.clang_major_version >= 19:
        self.compiler_options.append('-Wno-c23-extensions')
    if dpav.clang_major_version is not None and dpav.clang_major_version < 16 or (dpav.gcc_major_version is not None and dpav.gcc_major_version < 13):
        rc.append('build --define=xnn_enable_avxvnniint8=false')
    if dpav.clang_major_version is not None and dpav.clang_major_version < 14 or (dpav.gcc_major_version is not None and dpav.gcc_major_version < 12):
        rc.append('build --define=xnn_enable_avx512fp16=false')
    rc.append(f'build --action_env PYTHON_BIN_PATH={self.python_bin_path}')
    rc.append(f'build --python_path {self.python_bin_path}')
    rc.append('test --test_env LD_LIBRARY_PATH')
    rc.append('test --test_size_filters small,medium')
    rc.extend([f'build --copt {compiler_option}' for compiler_option in self.compiler_options])
    build_and_test_tag_filters = ','.join(build_and_test_tag_filters)
    rc.append(f'build --build_tag_filters {build_and_test_tag_filters}')
    rc.append(f'build --test_tag_filters {build_and_test_tag_filters}')
    rc.append(f'test --build_tag_filters {build_and_test_tag_filters}')
    rc.append(f'test --test_tag_filters {build_and_test_tag_filters}')
    return rc

Creates a bazelrc given an XLAConfigOptions.

Necessary paths are provided by the user, or retrieved via
`self._get_relevant_paths`.

Args:
dpav: DiscoverablePathsAndVersions that may hold user-specified paths and
versions. The dpav will then read from `self` to determine what to try
to auto-configure.

Returns:
The lines of a bazelrc.


def num_gpus():
    try:
        cmd = shlex.split('nvidia-smi --list-gpus')
        output = subprocess.check_output(cmd).decode('utf-8')
        return sum([1 for x in output.split('\n') if x.startswith('GPU ')])
    except (OSError, subprocess.CalledProcessError):
        logger.info('No GPUs detected (normal if no gpus installed)')
        return 0

The number of gpus available in the current container.

Returns:
int: number of gpus available in the current container.


def register_event(self, direction, verb, child_fn, priority=10):

        if verb not in self._event_handlers:
            self._event_handlers[verb] = []

        self._event_handlers[verb].append({
            'handler': child_fn,
            'direction': direction,
            'priority': priority,
        })

        for name, server in self.servers.items():
            server.register_event(direction, verb, child_fn, priority=priority)

Register an event with all servers.

Args:
direction (str): `in`, `out`, `both`, `raw`.
verb (str): Event name.
child_fn (function): Handler function.
priority (int): Handler priority (lower priority executes first).


def absolute_coords(self):
    if (self.type != EventType.POINTER_MOTION_ABSOLUTE):
        raise AttributeError(_wrong_prop.format(self.type))
    abs_x = self._libinput.libinput_event_pointer_get_absolute_x(self._handle)
    abs_y = self._libinput.libinput_event_pointer_get_absolute_y(self._handle)
    return (abs_x, abs_y)

The current absolute coordinates of the pointer event,
in mm from the top left corner of the device.

To get the corresponding output screen coordinate, use
:meth:`transform_absolute_coords`.

For pointer events that are not of type
:attr:`~libinput.constant.EventType.POINTER_MOTION_ABSOLUTE`,
this property raises :exc:`AttributeError`.

Returns:
(float, float): The current absolute coordinates.
Raises:
AttributeError


def recover_last_checkpoints(self, checkpoint_paths):
    checkpoints_with_mtimes = []
    for checkpoint_path in checkpoint_paths:
        try:
            mtime = checkpoint_management.get_checkpoint_mtimes([checkpoint_path])
        except errors.NotFoundError:
            continue
        if mtime:
            checkpoints_with_mtimes.append((checkpoint_path, mtime[0]))
    self.set_last_checkpoints_with_time(checkpoints_with_mtimes)

Recovers the internal saver state after a crash.

This method is useful for recovering the "self._last_checkpoints" state.

Globs for the checkpoints pointed to by `checkpoint_paths`.  If the files
exist, use their mtime as the checkpoint timestamp.

Args:
checkpoint_paths: a list of checkpoint paths.


def on_epoch_end(self, epoch, logs=None):

Called at the end of an epoch.

Subclasses should override for any actions to run. This function should only
be called during TRAIN mode.

Args:
epoch: Integer, index of epoch.
logs: Dict, metric results for this training epoch, and for the
validation epoch if validation is performed. Validation result keys
are prefixed with `val_`. For training epoch, the values of the
`Model`'s metrics are returned. Example : `{'loss': 0.2, 'accuracy':
0.7}`.


def convert_attribute_tag_to_name(value):
    if (not isinstance(value, Tags)):
        raise ValueError('The attribute tag must be a Tags enumeration.')
    for entry in attribute_name_tag_table:
        if (value == entry[1]):
            return entry[0]
    raise ValueError('Unrecognized attribute tag: {}'.format(value))

A utility function that converts an attribute tag into the corresponding
attribute name string.

For example: enums.Tags.STATE -> 'State'

Args:
value (enum): The Tags enumeration value of the attribute.

Returns:
string: The attribute name string that corresponds to the attribute
tag.

Raises:
ValueError: if the attribute tag is not a Tags enumeration or if it
is unrecognized attribute tag


def html_for_env_var(key):
    value = os.getenv(key)
    return KEY_VALUE_TEMPLATE.format(key, value)

Returns an HTML snippet for an environment variable.

Args:
key: A string representing an environment variable name.

Returns:
String HTML representing the value and variable.


def create_vnet(access_token, subscription_id, resource_group, name, location, address_prefix='10.0.0.0/16', subnet_prefix='10.0.0.0/16', nsg_id=None):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Network/virtualNetworks/', name, '?api-version=', NETWORK_API])
    vnet_body = {'location': location}
    properties = {'addressSpace': {'addressPrefixes': [address_prefix]}}
    subnet = {'name': 'subnet'}
    subnet['properties'] = {'addressPrefix': subnet_prefix}
    if (nsg_id is not None):
        subnet['properties']['networkSecurityGroup'] = {'id': nsg_id}
    properties['subnets'] = [subnet]
    vnet_body['properties'] = properties
    body = json.dumps(vnet_body)
    return do_put(endpoint, body, access_token)

Create a VNet with specified name and location. Optional subnet address prefix..

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
name (str): Name of the new VNet.
location (str): Azure data center location. E.g. westus.
address_prefix (str): Optional VNet address prefix. Default '10.0.0.0/16'.
subnet_prefix (str): Optional subnet address prefix. Default '10.0.0.0/16'.
nsg_id (str): Optional Netwrok Security Group resource Id. Default None.

Returns:
HTTP response. VNet JSON body.


def pages(self):
    (avro_schema, column_names) = _avro_schema(self._read_session)
    for block in self._reader:
        self._status = block.status
        (yield ReadRowsPage(avro_schema, column_names, block))

A generator of all pages in the stream.

Returns:
types.GeneratorType[google.cloud.bigquery_storage_v1beta1.ReadRowsPage]:
A generator of pages.


def consume(self, expect_class=None):
    if (expect_class and (not isinstance(self.current_token, expect_class))):
        raise InvalidTokenError(('Unexpected token at %d: got %r, expected %s' % (self.current_pos, self.current_token, expect_class.__name__)))
    current_token = self.current_token
    self._forward()
    return current_token

Retrieve the current token, then advance the parser.

If an expected class is provided, it will assert that the current token
matches that class (is an instance).

Note that when calling a token's nud() or led() functions, the "current"
token is the token following the token whose method has been called.

Returns:
Token: the previous current token.

Raises:
InvalidTokenError: If an expect_class is provided and the current
token doesn't match that class.


class DepthAnythingPreActResidualLayer(nn.Module):

    def __init__(self, config):
        super().__init__()
        self.activation1 = nn.ReLU()
        self.convolution1 = nn.Conv2d(config.fusion_hidden_size, config.fusion_hidden_size, kernel_size=3, stride=1, padding=1, bias=True)
        self.activation2 = nn.ReLU()
        self.convolution2 = nn.Conv2d(config.fusion_hidden_size, config.fusion_hidden_size, kernel_size=3, stride=1, padding=1, bias=True)

    def forward(self, hidden_state: torch.Tensor) -> torch.Tensor:
        residual = hidden_state
        hidden_state = self.activation1(hidden_state)
        hidden_state = self.convolution1(hidden_state)
        hidden_state = self.activation2(hidden_state)
        hidden_state = self.convolution2(hidden_state)
        return hidden_state + residual

ResidualConvUnit, pre-activate residual unit.

Args:
config (`[DepthAnythingConfig]`):
Model configuration class defining the model architecture.


def __init__(self, daemon=False, *args, **kwargs):

        super(ThreadReturn, self).__init__(*args, **kwargs)
        self.daemon = daemon
        self._return = None

Initializes the thread.

Args:
self (ThreadReturn): the ``ThreadReturn`` instance
daemon (bool): if the thread should be spawned as a daemon
args: optional list of arguments
kwargs: optional key-word arguments

Returns:
``None``


def normalise(self, to_currency):
    out = Money(currency=to_currency)
    for money in self._money_obs:
        out += converter.convert(money, to_currency)
    return Balance([out])

Normalise this balance into a single currency

Args:
to_currency (str): Destination currency

Returns:
(Balance): A new balance object containing a single Money value in the specified currency


def _make_assets_key_collection(saved_model_proto, export_path):
    asset_filenames = {}
    used_asset_filenames = set()

    def _make_asset_filename(original_filename):
        'Returns the asset filename to use for the file.'
        if (original_filename in asset_filenames):
            return asset_filenames[original_filename]
        basename = os.path.basename(original_filename)
        suggestion = basename
        index = 0
        while (suggestion in used_asset_filenames):
            suggestion = ('%s%d' % (basename, index))
            index += 1
        asset_filenames[original_filename] = suggestion
        used_asset_filenames.add(suggestion)
        return suggestion
    for meta_graph in saved_model_proto.meta_graphs:
        collection_def = meta_graph.collection_def.get(tf_v1.GraphKeys.ASSET_FILEPATHS)
        if (collection_def is None):
            continue
        if (collection_def.WhichOneof('kind') != 'node_list'):
            raise ValueError('MetaGraph collection ASSET_FILEPATHS is not a list of tensors.')
        for tensor in collection_def.node_list.value:
            if (not tensor.endswith(':0')):
                raise ValueError('Unexpected tensor in ASSET_FILEPATHS collection.')
        asset_nodes = set([_get_node_name_from_tensor(tensor) for tensor in collection_def.node_list.value])
        tensor_filename_map = {}
        for node in meta_graph.graph_def.node:
            if (node.name in asset_nodes):
                _check_asset_node_def(node)
                filename = node.attr['value'].tensor.string_val[0]
                tensor_filename_map[(node.name + ':0')] = filename
                node.attr['value'].tensor.string_val[0] = tf.compat.as_bytes('SAVEDMODEL-ASSET')
        if tensor_filename_map:
            assets_key_collection = meta_graph.collection_def[tf_v1.saved_model.constants.ASSETS_KEY]
            for (tensor, filename) in sorted(tensor_filename_map.items()):
                asset_proto = meta_graph_pb2.AssetFileDef()
                asset_proto.filename = _make_asset_filename(filename)
                asset_proto.tensor_info.name = tensor
                assets_key_collection.any_list.value.add().Pack(asset_proto)
    return {original_filename: _get_asset_filename(export_path, asset_filename) for (original_filename, asset_filename) in asset_filenames.items()}

Creates an ASSETS_KEY collection in the GraphDefs in saved_model_proto.

Adds an ASSETS_KEY collection to the GraphDefs in the SavedModel and returns
a map from original asset filename to filename when exporting the SavedModel
to `export_path`.

This is roughly the inverse operation of `_merge_assets_key_collection`.

Args:
saved_model_proto: SavedModel proto to be modified.
export_path: string with path where the saved_model_proto will be exported.

Returns:
A map from original asset filename to asset filename when exporting the
SavedModel to path.

Raises:
ValueError: on unsuported/unexpected SavedModel.


def goto(directory, create=False):
    current = os.getcwd()
    directory = os.path.abspath(directory)
    if (os.path.isdir(directory) or (create and mkdir(directory))):
        logger.info('goto -> %s', directory)
        os.chdir(directory)
        try:
            (yield True)
        finally:
            logger.info('goto <- %s', directory)
            os.chdir(current)
    else:
        logger.info('goto(%s) - directory does not exist, or cannot be created.', directory)
        (yield False)

Context object for changing directory.

Args:
directory (str): Directory to go to.
create (bool): Create directory if it doesn't exists.

Usage::

>>> with goto(directory) as ok:
...     if not ok:
...         print 'Error'
...     else:
...         print 'All OK'


def BuildChecks(self, request):
    result = []
    if (request.HasField('start_time') or request.HasField('end_time')):

        def FilterTimestamp(file_stat, request=request):
            return (file_stat.HasField('st_mtime') and ((file_stat.st_mtime < request.start_time) or (file_stat.st_mtime > request.end_time)))
        result.append(FilterTimestamp)
    if (request.HasField('min_file_size') or request.HasField('max_file_size')):

        def FilterSize(file_stat, request=request):
            return (file_stat.HasField('st_size') and ((file_stat.st_size < request.min_file_size) or (file_stat.st_size > request.max_file_size)))
        result.append(FilterSize)
    if request.HasField('perm_mode'):

        def FilterPerms(file_stat, request=request):
            return ((file_stat.st_mode & request.perm_mask) != request.perm_mode)
        result.append(FilterPerms)
    if request.HasField('uid'):

        def FilterUID(file_stat, request=request):
            return (file_stat.st_uid != request.uid)
        result.append(FilterUID)
    if request.HasField('gid'):

        def FilterGID(file_stat, request=request):
            return (file_stat.st_gid != request.gid)
        result.append(FilterGID)
    if request.HasField('path_regex'):
        regex = request.path_regex

        def FilterPath(file_stat, regex=regex):
            'Suppress any filename not matching the regular expression.'
            return (not regex.Search(file_stat.pathspec.Basename()))
        result.append(FilterPath)
    if request.HasField('data_regex'):

        def FilterData(file_stat, **_):
            'Suppress files that do not match the content.'
            return (not self.TestFileContent(file_stat))
        result.append(FilterData)
    return result

Parses request and returns a list of filter callables.

Each callable will be called with the StatEntry and returns True if the
entry should be suppressed.

Args:
request: A FindSpec that describes the search.

Returns:
a list of callables which return True if the file is to be suppressed.


def BSearchRound(a, x, lo=0, hi=None):

    if len(a) == 0: return -1
    hi = hi if hi is not None else len(a)
    pos = bisect_left(a, x, lo, hi)

    if pos >= hi:
        return hi - 1
    elif a[pos] == x or pos == lo:
        return pos
    else:
        return pos - 1 if x - a[pos - 1] <= a[pos] - x else pos

Returns index of a that is closest to x.

Arguments:
a -- ordered numeric sequence
x -- element to search within a
lo -- lowest index to consider in search*
hi -- highest index to consider in search*

*bisect.bisect_left capability that we don't need to loose.


def list_runs(self, project, entity=None):
    query = gql('\n        query Buckets($model: String!, $entity: String!) {\n            model(name: $model, entityName: $entity) {\n                buckets(first: 10) {\n                    edges {\n                        node {\n                            id\n                            name\n                            description\n                        }\n                    }\n                }\n            }\n        }\n        ')
    return self._flatten_edges(self.gql(query, variable_values={'entity': (entity or self.settings('entity')), 'model': (project or self.settings('project'))})['model']['buckets'])

Lists runs in W&B scoped by project.

Args:
project (str): The project to scope the runs to
entity (str, optional): The entity to scope this project to.  Defaults to public models

Returns:
[{"id",name","description"}]


def get_config_value(name, path_to_file='config.txt'):

    if not os.path.isfile(path_to_file):
        path_to_file = os.path.join('../instruments/', path_to_file)

    path_to_file = os.path.abspath(path_to_file)

    if not os.path.isfile(path_to_file):
        print(('path_to_file', path_to_file))

        return None

    f = open(path_to_file, 'r')
    string_of_file_contents = f.read()

    if name[-1] is not ':':
        name += ':'

    if name not in string_of_file_contents:
        return None
    else:
        config_value = [line.split(name)[1] for line in string_of_file_contents.split('\n')
                        if len(line.split(name)) > 1][0].strip()
        return config_value

gets the value for "name" from "path_to_file" config file
Args:
name: name of varibale in config file
path_to_file: path to config file

Returns: path to dll if name exists in the file; otherwise, returns None


def to_html(self):

        text = self.text
        if text is None:
            text = self.uri
        return '%s' % (
            self.uri, self.html_attributes(), text)

Render as html

Args:
None

Returns:
Str the html representation

Raises:
Errors are propagated


def verify_no_new_dims(input_shapes, output_shape):

  all_input_dims = set(sum([s.dims for s in input_shapes], []))
  all_output_dims = set(output_shape.dims)
  if not all_output_dims.issubset(all_input_dims):
    raise ValueError(
        "No new dimensions allowed in output"
        " input_shapes = %s output_shape= %s"
        % ([s.dims for s in input_shapes], output_shape.dims))

Verifies that all dimensions in the output are in at least one input.

Args:
input_shapes: a list of Shapes
output_shape: a Shape
Raises:
ValueError: if there are new dimensions in the output.


def update_caseid(self, case_obj, family_id):
    new_case = deepcopy(case_obj)
    new_case['_id'] = family_id
    for case_variants in ['suspects', 'causatives']:
        new_variantids = []
        for variant_id in case_obj.get(case_variants, []):
            case_variant = self.variant(variant_id)
            if (not case_variant):
                continue
            new_variantid = get_variantid(case_variant, family_id)
            new_variantids.append(new_variantid)
        new_case[case_variants] = new_variantids
    for acmg_obj in self.acmg_collection.find({'case_id': case_obj['_id']}):
        LOG.info('update ACMG classification: %s', acmg_obj['classification'])
        acmg_variant = self.variant(acmg_obj['variant_specific'])
        new_specific_id = get_variantid(acmg_variant, family_id)
        self.acmg_collection.find_one_and_update({'_id': acmg_obj['_id']}, {'$set': {'case_id': family_id, 'variant_specific': new_specific_id}})
    institute_obj = self.institute(case_obj['owner'])
    for event_obj in self.events(institute_obj, case=case_obj):
        LOG.info('update event: %s', event_obj['verb'])
        self.event_collection.find_one_and_update({'_id': event_obj['_id']}, {'$set': {'case': family_id}})
    self.case_collection.insert_one(new_case)
    self.case_collection.find_one_and_delete({'_id': case_obj['_id']})
    return new_case

Update case id for a case across the database.

This function is used when a case is a rerun or updated for another reason.

Args:
case_obj(dict)
family_id(str): The new family id

Returns:
new_case(dict): The updated case object


def diff_fromDelta(self, text1, delta):
    diffs = []
    pointer = 0
    tokens = delta.split('\t')
    for token in tokens:
        if (token == ''):
            continue
        param = token[1:]
        if (token[0] == '+'):
            param = urllib.parse.unquote(param)
            diffs.append((self.DIFF_INSERT, param))
        elif ((token[0] == '-') or (token[0] == '=')):
            try:
                n = int(param)
            except ValueError:
                raise ValueError(('Invalid number in diff_fromDelta: ' + param))
            if (n < 0):
                raise ValueError(('Negative number in diff_fromDelta: ' + param))
            text = text1[pointer:(pointer + n)]
            pointer += n
            if (token[0] == '='):
                diffs.append((self.DIFF_EQUAL, text))
            else:
                diffs.append((self.DIFF_DELETE, text))
        else:
            raise ValueError(('Invalid diff operation in diff_fromDelta: ' + token[0]))
    if (pointer != len(text1)):
        raise ValueError(('Delta length (%d) does not equal source text length (%d).' % (pointer, len(text1))))
    return diffs

Given the original text1, and an encoded string which describes the
operations required to transform text1 into text2, compute the full diff.

Args:
text1: Source string for the diff.
delta: Delta text.

Returns:
Array of diff tuples.

Raises:
ValueError: If invalid input.


def CleanseComments(line):

  commentpos = line.find('
  if commentpos != -1 and not IsCppString(line[:commentpos]):
    line = line[:commentpos].rstrip()

  return _RE_PATTERN_CLEANSE_LINE_C_COMMENTS.sub('', line)

Removes //-comments and single-line C-style /* */ comments.

Args:
line: A line of C++ source.

Returns:
The line with single-line comments removed.


def _hexvalue_to_rgb(hexvalue):

        r = int(hexvalue[0:2], 16)
        g = int(hexvalue[2:4], 16)
        b = int(hexvalue[4:6], 16)

        return (r, g, b)

Converts the hexvalue used by tuya for colour representation into
an RGB value.

Args:
hexvalue(string): The hex representation generated by BulbDevice._rgb_to_hexvalue()


def create_box_reminder(self, box_key, message, remind_date, remind_follwers, **kwargs):

		uri = '/'.join([
						self.api_uri,
						self.boxes_suffix,
						box_key,
						self.reminders_suffix
						])
		kwargs.update({	'message':message,
						'remindDate':remind_date,
						'remindFollowers': remind_follwers})

		new_rem = StreakReminder(**kwargs)

		code, data = self._req('put', uri, new_rem.to_dict(rw = True))

		return code, data

Creates a reminder with the provided attributes.
Args:
box_key 			specifying the box to add the field to
message				message for the reminder
remind_date			date to remind on in ticks.
remind_followers	true/false
kwargs				{..} see StreakReminder object for details
return				(status code, reminder dict)


def get_list(self, name, default=None):
    if (name not in self):
        if (default is not None):
            return default
        raise EnvironmentError.not_found(self._prefix, name)
    return list(self[name])

Retrieves an environment variable as a list.

Note that while implicit access of environment variables
containing tuples will return tuples, using this method will
coerce tuples to lists.

Args:
name (str): The case-insensitive, unprefixed variable name.
default: If provided, a default value will be returned
instead of throwing ``EnvironmentError``.

Returns:
list: The environment variable's value as a list.

Raises:
EnvironmentError: If the environment variable does not
exist, and ``default`` was not provided.
ValueError: If the environment variable value is not an
integer with base 10.


def reduce(cls, requirements: Iterable['FetchRequirement']) \
            -> 'FetchRequirement':

        return reduce(lambda x, y: x | y, requirements, cls.NONE)

Reduce a set of fetch requirements into a single requirement.

Args:
requirements: The set of fetch requirements.


class UpsampleOneStep(nn.Module):

    def __init__(self, scale, in_channels, out_channels):
        super().__init__()
        self.conv = nn.Conv2d(in_channels, scale ** 2 * out_channels, 3, 1, 1)
        self.pixel_shuffle = nn.PixelShuffle(scale)

    def forward(self, x):
        x = self.conv(x)
        x = self.pixel_shuffle(x)
        return x

UpsampleOneStep module (the difference with Upsample is that it always only has 1conv + 1pixelshuffle)

Used in lightweight SR to save parameters.

Args:
scale (int):
Scale factor. Supported scales: 2^n and 3.
in_channels (int):
Channel number of intermediate features.
out_channels (int):
Channel number of output features.


def connect(self, db_uri, debug=False):

        kwargs = {'echo': debug, 'convert_unicode': True}

        if 'mysql' in db_uri:
            kwargs['pool_recycle'] = 3600
        elif ':
            logger.debug("detected sqlite path URI: {}".format(db_uri))
            db_path = os.path.abspath(os.path.expanduser(db_uri))
            db_uri = "sqlite:

        self.engine = create_engine(db_uri, **kwargs)
        logger.debug('connection established successfully')

        BASE.metadata.bind = self.engine

        self.session = scoped_session(sessionmaker(bind=self.engine))

        self.query = self.session.query
        return self

Configure connection to a SQL database.

Args:
db_uri (str): path/URI to the database to connect to
debug (Optional[bool]): whether to output logging information


def _reduced_stack(istart=3, iend=5, ipython=True):

    import inspect
    return [i[istart:iend] for i in inspect.stack() if _decorated_path(i[1])]

Returns the reduced function call stack that includes only relevant
function calls (i.e., ignores any that are not part of the specified package
or acorn.

Args:
package (str): name of the package that the logged method belongs to.


def lines(start=None, end=None, reverse=False, selection=False):

    if selection:
        start, end = get_selection()

    else:
        start, end = fix_addresses(start, end)

    if not reverse:
        item = idaapi.get_item_head(start)
        while item < end:
            yield Line(item)
            item += idaapi.get_item_size(item)

    else:
        item = idaapi.get_item_head(end - 1)
        while item >= start:
            yield Line(item)
            item = idaapi.get_item_head(item - 1)

Iterate lines in range.

Args:
start: Starting address, start of IDB if `None`.
end: End address, end of IDB if `None`.
reverse: Set to true to iterate in reverse order.
selection: If set to True, replaces start and end with current selection.

Returns:
iterator of `Line` objects.


def CreateShapeFromDtypeAndTuple(dtype, shape_tuple):
    element_type = types_.MAP_DTYPE_TO_RECORD[str(dtype)].primitive_type
    return Shape(element_type, shape_tuple)

Create a shape from a Numpy dtype and a sequence of nonnegative integers.

Args:
dtype: a numpy dtype, e.g. np.dtype('int32').
shape_tuple: a sequence of nonnegative integers.

Returns:
A Shape object.


def get_alexa_rankings(self, domains):

        api_name = 'alexa_rankings'

        (all_responses, domains) = self._bulk_cache_lookup(api_name, domains)
        responses = self._request_reports(domains)

        for domain, response in zip(domains, responses):
            xml_response = self._extract_response_xml(domain, response)
            if self._cache:
                self._cache.cache_value(api_name, domain, response)
            all_responses[domain] = xml_response

        return all_responses

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

Args:
domains: list of string domains.
Returns:
A dict with the domain as key and the VT report as value.


def parse_client_table(redis_client):

    NIL_CLIENT_ID = ray.ObjectID.nil().binary()
    message = redis_client.execute_command("RAY.TABLE_LOOKUP",
                                           ray.gcs_utils.TablePrefix.CLIENT,
                                           "", NIL_CLIENT_ID)

    if message is None:
        return []

    node_info = {}
    gcs_entry = ray.gcs_utils.GcsTableEntry.GetRootAsGcsTableEntry(message, 0)

    ordered_client_ids = []

    for i in range(gcs_entry.EntriesLength()):
        client = (ray.gcs_utils.ClientTableData.GetRootAsClientTableData(
            gcs_entry.Entries(i), 0))

        resources = {
            decode(client.ResourcesTotalLabel(i)):
            client.ResourcesTotalCapacity(i)
            for i in range(client.ResourcesTotalLabelLength())
        }
        client_id = ray.utils.binary_to_hex(client.ClientId())

        if not client.IsInsertion():
            assert client_id in node_info, "Client removed not found!"
            assert node_info[client_id]["IsInsertion"], (
                "Unexpected duplicate removal of client.")
        else:
            ordered_client_ids.append(client_id)

        node_info[client_id] = {
            "ClientID": client_id,
            "IsInsertion": client.IsInsertion(),
            "NodeManagerAddress": decode(
                client.NodeManagerAddress(), allow_none=True),
            "NodeManagerPort": client.NodeManagerPort(),
            "ObjectManagerPort": client.ObjectManagerPort(),
            "ObjectStoreSocketName": decode(
                client.ObjectStoreSocketName(), allow_none=True),
            "RayletSocketName": decode(
                client.RayletSocketName(), allow_none=True),
            "Resources": resources
        }

    return [node_info[client_id] for client_id in ordered_client_ids]

Read the client table.

Args:
redis_client: A client to the primary Redis shard.

Returns:
A list of information about the nodes in the cluster.


def _render_batch(self, non_fluents: NonFluents, states: Fluents, actions: Fluents, interms: Fluents, rewards: np.array, horizon: Optional[int]=None) -> None:
    if (horizon is None):
        horizon = len(states[0][1])
        self._render_round_init(horizon, non_fluents)
        for t in range(horizon):
            s = [(s[0], s[1][t]) for s in states]
            f = [(f[0], f[1][t]) for f in interms]
            a = [(a[0], a[1][t]) for a in actions]
            r = rewards[t]
            self._render_timestep(t, s, a, f, r)
        self._render_round_end(rewards)

Prints `non_fluents`, `states`, `actions`, `interms` and `rewards`
for given `horizon`.

Args:
states (Sequence[Tuple[str, np.array]]): A state trajectory.
actions (Sequence[Tuple[str, np.array]]): An action trajectory.
interms (Sequence[Tuple[str, np.array]]): An interm state trajectory.
rewards (np.array): Sequence of rewards (1-dimensional array).
horizon (Optional[int]): Number of timesteps.


def validate(cls, mapper_spec):

    reader_spec = cls.get_params(mapper_spec, allow_old=False)

    if cls.BUCKET_NAME_PARAM not in reader_spec:
      raise errors.BadReaderParamsError(
          "%s is required for Google Cloud Storage" %
          cls.BUCKET_NAME_PARAM)
    try:
      cloudstorage.validate_bucket_name(
          reader_spec[cls.BUCKET_NAME_PARAM])
    except ValueError, error:
      raise errors.BadReaderParamsError("Bad bucket name, %s" % (error))

    if cls.OBJECT_NAMES_PARAM not in reader_spec:
      raise errors.BadReaderParamsError(
          "%s is required for Google Cloud Storage" %
          cls.OBJECT_NAMES_PARAM)
    filenames = reader_spec[cls.OBJECT_NAMES_PARAM]
    if not isinstance(filenames, list):
      raise errors.BadReaderParamsError(
          "Object name list is not a list but a %s" %
          filenames.__class__.__name__)
    for filename in filenames:
      if not isinstance(filename, basestring):
        raise errors.BadReaderParamsError(
            "Object name is not a string but a %s" %
            filename.__class__.__name__)
    if cls.DELIMITER_PARAM in reader_spec:
      delimiter = reader_spec[cls.DELIMITER_PARAM]
      if not isinstance(delimiter, basestring):
        raise errors.BadReaderParamsError(
            "%s is not a string but a %s" %
            (cls.DELIMITER_PARAM, type(delimiter)))

Validate mapper specification.

Args:
mapper_spec: an instance of model.MapperSpec

Raises:
BadReaderParamsError: if the specification is invalid for any reason such
as missing the bucket name or providing an invalid bucket name.


def cache_memlimit(self, memlimit):
    self._fetch_cmd(b'cache_memlimit', [str(int(memlimit))], False)
    return True

The memcached "cache_memlimit" command.

Args:
memlimit: int, the number of megabytes to set as the new cache memory
limit.

Returns:
If no exception is raised, always returns True.


def load_nips2011_papers(path):
    path = os.path.expanduser(path)
    filename = 'NIPS_1987-2015.csv'
    filepath = os.path.join(path, filename)
    if (not os.path.exists(filepath)):
        url = 'https:
        if (not tf.io.gfile.exists(path)):
            tf.io.gfile.makedirs(path)
        print(('Downloading %s to %s' % (url, filepath)))
        urllib.request.urlretrieve(url, filepath)
    with open(filepath) as f:
        iterator = csv.reader(f)
        documents = next(iterator)[1:]
        words = []
        x_train = []
        for row in iterator:
            words.append(row[0])
            x_train.append(row[1:])
    x_train = np.array(x_train, dtype=np.int)
    doc_idx = [i for (i, document) in enumerate(documents) if document.startswith('2011')]
    documents = [documents[doc] for doc in doc_idx]
    x_train = x_train[(:, doc_idx)]
    word_idx = np.logical_and((np.sum((x_train != 0), 1) >= 2), (np.sum(x_train, 1) >= 10))
    words = [word for (word, idx) in zip(words, word_idx) if idx]
    bag_of_words = x_train[(word_idx, :)].T
    return (bag_of_words, words)

Loads NIPS 2011 conference papers.

The NIPS 1987-2015 data set is in the form of a 11,463 x 5,812 matrix of
per-paper word counts, containing 11,463 words and 5,811 NIPS conference
papers (Perrone et al., 2016). We subset to papers in 2011 and words appearing
in at least two documents and having a total word count of at least 10.

Built from the Observations Python package.

Args:
path: str.
Path to directory which either stores file or otherwise file will
be downloaded and extracted there. Filename is `NIPS_1987-2015.csv`.

Returns:
bag_of_words: np.ndarray of shape [num_documents, num_words]. Each element
denotes the number of occurrences of a specific word in a specific
document.
words: List of strings, denoting the words for `bag_of_words`'s columns.


def pretty_dnf(dnf):
    if not dnf:
        return 'false'
    else:
        return ' | '.join((pretty_conjunction(c) for c in dnf))

Pretty-print a disjunctive normal form (disjunction of conjunctions).

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

Args:
dnf: A list of list of strings. (Disjunction of conjunctions of strings)

Returns:
A pretty-printed string.


def parse_config_output(self, output):

        regexp = re.compile('^(config |edit |set |end$|next$)(.*)')
        current_block = self

        if isinstance(output, py23_compat.string_types):
            output = output.splitlines()

        for line in output:
            if 'uuid' in line:
                continue
            if 'snmp-index' in line:
                continue
            line = line.strip()
            result = regexp.match(line)

            if result is not None:
                action = result.group(1).strip()
                data = result.group(2).strip()

                if action == 'config' or action == 'edit':
                    data = data.replace('"', '')
                    if data not in current_block.get_block_names():
                        config_block = FortiConfig(data, action, current_block)
                        current_block[data] = config_block
                    else:
                        config_block = current_block[data]
                    current_block = config_block
                elif action == 'end' or action == 'next':
                    current_block = current_block.get_parent()
                elif action == 'set':
                    split_data = data.split(' ')
                    parameter = split_data[0]
                    data = split_data[1:]
                    current_block.set_param(parameter, ' '.join(data))

This method will parse a string containing FortiOS config and will load it into the current
:class:`~pyFG.forticonfig.FortiConfig` object.

Args:
- **output** (string) - A string containing a supported version of FortiOS config


def __init__(self, name=None, description=None, providers=None,
                 checkers=None):

        self.name = name
        self.description = description
        self.providers = providers or []
        self.checkers = checkers or []
        self.results = []

Initialization method.

Args:
name (str): the group name.
description (str): the group description.
providers (list): the list of providers.
checkers (list): the list of checkers.


def CheckRedundantVirtual(filename, clean_lines, linenum, error):
    line = clean_lines.elided[linenum]
    virtual = Match('^(.*)(\\bvirtual\\b)(.*)$', line)
    if (not virtual):
        return
    if (Search('\\b(public|protected|private)\\s+$', virtual.group(1)) or Match('^\\s+(public|protected|private)\\b', virtual.group(3))):
        return
    if Match('^.*[^:]:[^:].*$', line):
        return
    end_col = (- 1)
    end_line = (- 1)
    start_col = len(virtual.group(2))
    for start_line in xrange(linenum, min((linenum + 3), clean_lines.NumLines())):
        line = clean_lines.elided[start_line][start_col:]
        parameter_list = Match('^([^(]*)\\(', line)
        if parameter_list:
            (_, end_line, end_col) = CloseExpression(clean_lines, start_line, (start_col + len(parameter_list.group(1))))
            break
        start_col = 0
    if (end_col < 0):
        return
    for i in xrange(end_line, min((end_line + 3), clean_lines.NumLines())):
        line = clean_lines.elided[i][end_col:]
        match = Search('\\b(override|final)\\b', line)
        if match:
            error(filename, linenum, 'readability/inheritance', 4, ('"virtual" is redundant since function is already declared as "%s"' % match.group(1)))
        end_col = 0
        if Search('[^\\w]\\s*$', line):
            break

Check if line contains a redundant "virtual" function-specifier.

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 sheets_batch_update(config, auth, sheet_url_or_name, data):
    sheet_id = sheets_id(config, auth, sheet_url_or_name)
    API_Sheets(config, auth).spreadsheets().batchUpdate(spreadsheetId=sheet_id, body=data).execute()

Helper for performing batch operations.

Args:
config - see starthinker/util/configuration.py
auth - user or service
sheet_url_or_name - one of: URL, document title, or id
data - JSON data for sending to batch request

No Return


def get_extrema(self, normalize_rxn_coordinate=True):

        x = np.arange(0, np.max(self.r), 0.01)
        y = self.spline(x) * 1000

        scale = 1 if not normalize_rxn_coordinate else 1 / self.r[-1]
        min_extrema = []
        max_extrema = []
        for i in range(1, len(x) - 1):
            if y[i] < y[i-1] and y[i] < y[i+1]:
                min_extrema.append((x[i] * scale, y[i]))
            elif y[i] > y[i-1] and y[i] > y[i+1]:
                max_extrema.append((x[i] * scale, y[i]))
        return min_extrema, max_extrema

Returns the positions of the extrema along the MEP. Both local
minimums and maximums are returned.

Args:
normalize_rxn_coordinate (bool): Whether to normalize the
reaction coordinate to between 0 and 1. Defaults to True.

Returns:
(min_extrema, max_extrema), where the extrema are given as
[(x1, y1), (x2, y2), ...].


def guess_strategy_type(file_name_or_ext):

    if '.' not in file_name_or_ext:
        ext = file_name_or_ext
    else:
        name, ext = os.path.splitext(file_name_or_ext)
    ext = ext.lstrip('.')
    file_type_map = get_file_type_map()
    return file_type_map.get(ext, None)

Guess strategy type to use for file by extension.

Args:
file_name_or_ext: Either a file name with an extension or just
an extension

Returns:
Strategy: Type corresponding to extension or None if there's no
corresponding strategy type


def interact_GxE_1dof(snps, pheno, env, K=None, covs=None, test='lrt'):
    N = snps.shape[0]
    if (K is None):
        K = SP.eye(N)
    if (covs is None):
        covs = SP.ones((N, 1))
    assert ((env.shape[0] == N) and (pheno.shape[0] == N) and (K.shape[0] == N) and (K.shape[1] == N) and (covs.shape[0] == N)), 'shapes missmatch'
    Inter0 = SP.ones((N, 1))
    pv = SP.zeros((env.shape[1], snps.shape[1]))
    print(('starting %i interaction scans for %i SNPs each.' % (env.shape[1], snps.shape[1])))
    t0 = time.time()
    for i in range(env.shape[1]):
        t0_i = time.time()
        cov_i = SP.concatenate((covs, env[(:, i:(i + 1))]), 1)
        lm_i = simple_interaction(snps=snps, pheno=pheno, covs=cov_i, Inter=env[(:, i:(i + 1))], Inter0=Inter0, test=test)
        pv[(i, :)] = lm_i.getPv()[(0, :)]
        t1_i = time.time()
        print(('Finished %i out of %i interaction scans in %.2f seconds.' % ((i + 1), env.shape[1], (t1_i - t0_i))))
    t1 = time.time()
    print(('-----------------------------------------------------------\nFinished all %i interaction scans in %.2f seconds.' % (env.shape[1], (t1 - t0))))
    return pv

Univariate GxE fixed effects interaction linear mixed model test for all
pairs of SNPs and environmental variables.

Args:
snps:   [N x S] SP.array of S SNPs for N individuals
pheno:  [N x 1] SP.array of 1 phenotype for N individuals
env:    [N x E] SP.array of E environmental variables for N individuals
K:      [N x N] SP.array of LMM-covariance/kinship koefficients (optional)
If not provided, then linear regression analysis is performed
covs:   [N x D] SP.array of D covariates for N individuals
test:    'lrt' for likelihood ratio test (default) or 'f' for F-test

Returns:
pv:     [E x S] SP.array of P values for interaction tests between all
E environmental variables and all S SNPs


def parse_cluster_spec(cluster_spec, cluster, verbose=False):
    job_strings = cluster_spec.split(',')
    if not cluster_spec:
        raise ValueError('Empty cluster_spec string')
    for job_string in job_strings:
        job_def = cluster.job.add()
        if job_string.count('|') != 1:
            raise ValueError("Not exactly one instance of '|' in cluster_spec")
        job_name = job_string.split('|')[0]
        if not job_name:
            raise ValueError('Empty job_name in cluster_spec')
        job_def.name = job_name
        if verbose:
            logging.info('Added job named "%s"', job_name)
        job_tasks = job_string.split('|')[1].split(';')
        for i in range(len(job_tasks)):
            if not job_tasks[i]:
                raise ValueError('Empty task string at position %d' % i)
            job_def.tasks[i] = job_tasks[i]
            if verbose:
                logging.info('  Added task "%s" to job "%s"', job_tasks[i], job_name)

Parse content of cluster_spec string and inject info into cluster protobuf.

Args:
cluster_spec: cluster specification string, e.g.,
"local|localhost:2222;localhost:2223"
cluster: cluster protobuf.
verbose: If verbose logging is requested.

Raises:
ValueError: if the cluster_spec string is invalid.


def match_unknown_against_protocol(self, matcher, solver, unknown, complete):
    assert is_unknown(unknown)
    assert is_complete(complete)
    type_params = {p.type_param: matcher.type_parameter(unknown, complete, p) for p in complete.template}
    subst = type_params.copy()
    implication = matcher.match_Protocol_against_Unknown(complete, unknown, subst)
    if implication is not booleq.FALSE and type_params:
        for param in type_params.values():
            solver.register_variable(param.name)
    solver.implies(booleq.Eq(unknown.name, complete.name), implication)

Given an ~unknown, match it against a class.

Args:
matcher: An instance of pytd.type_match.TypeMatch.
solver: An instance of pytd.booleq.Solver.
unknown: The unknown class to match
complete: A complete class to match against. (E.g. a built-in or a user
defined class)

Returns:
An instance of pytd.booleq.BooleanTerm.


def compress_pdf(filepath, output_path, ghostscript_binary):

    if not filepath.endswith(PDF_EXTENSION):
        raise ValueError("Filename must end with .pdf!\n%s does not." % filepath)
    try:
        file_size = os.stat(filepath).st_size
        if file_size < FILE_SIZE_LOWER_LIMIT:
            LOGGER.info(NOT_COMPRESSING.format(filepath, file_size, FILE_SIZE_LOWER_LIMIT))
            process = subprocess.Popen(['cp', filepath, output_path])
        else:
            LOGGER.info(COMPRESSING.format(filepath))
            process = subprocess.Popen(
                [ghostscript_binary, "-sDEVICE=pdfwrite",
                 "-dCompatabilityLevel=1.4", "-dPDFSETTINGS=/ebook",
                 "-dNOPAUSE", "-dQUIET", "-dBATCH",
                 "-sOutputFile=%s" % output_path, filepath]
                )
    except FileNotFoundError:
        msg = GS_NOT_INSTALLED.format(ghostscript_binary)
        raise FileNotFoundError(msg)
    process.communicate()
    LOGGER.info(FILE_DONE.format(output_path))

Compress a single PDF file.

Args:
filepath (str): Path to the PDF file.
output_path (str): Output path.
ghostscript_binary (str): Name/alias of the Ghostscript binary.

Raises:
ValueError
FileNotFoundError


def constant(cls, value: Value, dtype: tf.DType=tf.float32) -> 'TensorFluent':
    t = tf.constant(value, dtype=dtype)
    scope = []
    batch = False
    return TensorFluent(t, scope, batch=batch)

Returns a constant `value` TensorFluent with given `dtype`.

Args:
value: The constant value.
dtype: The output's data type.

Returns:
A constant TensorFluent.


def add_enum(name=None, index=None, flags=idaapi.hexflag(), bitfield=False):

    if name is not None:
        with ignored(exceptions.EnumNotFound):
            _get_enum(name)
            raise exceptions.EnumAlreadyExists()

    if index is None or index < 0:
        index = idaapi.get_enum_qty()

    eid = idaapi.add_enum(index, name, flags)

    if eid == idaapi.BADADDR:
        raise exceptions.EnumCreationFailed('Failed creating enum "{}"'.format(name))

    if bitfield:
        idaapi.set_enum_bf(eid, bitfield)

    return Enum(eid=eid)

Create a new enum.

Args:
name: Name of the enum to create.
index: The index of the enum. Leave at default to append the enum as the last enum.
flags: Enum type flags.
bitfield: Is the enum a bitfield.

Returns:
An `Enum` object.


def is53(msg):

    if allzeros(msg):
        return False

    d = hex2bin(data(msg))

    if wrongstatus(d, 1, 3, 12):
        return False

    if wrongstatus(d, 13, 14, 23):
        return False

    if wrongstatus(d, 24, 25, 33):
        return False

    if wrongstatus(d, 34, 35, 46):
        return False

    if wrongstatus(d, 47, 49, 56):
        return False

    ias = ias53(msg)
    if ias is not None and ias > 500:
        return False

    mach = mach53(msg)
    if mach is not None and mach > 1:
        return False

    tas = tas53(msg)
    if tas is not None and tas > 500:
        return False

    vr = vr53(msg)
    if vr is not None and abs(vr) > 8000:
        return False

    return True

Check if a message is likely to be BDS code 5,3
(Air-referenced state vector)

Args:
msg (String): 28 bytes hexadecimal message string

Returns:
bool: True or False


def mols_to_file(mols, path):

    with open(path, 'w') as f:
        f.write(mols_to_text(mols))

Save molecules to the SDFile format file

Args:
mols: list of molecule objects
path: file path to save


def delete(filename, retry_params=None, _account_id=None):
    api = storage_api._get_storage_api(retry_params=retry_params, account_id=_account_id)
    common.validate_file_path(filename)
    filename = api_utils._quote_filename(filename)
    (status, resp_headers, content) = api.delete_object(filename)
    errors.check_status(status, [204], filename, resp_headers=resp_headers, body=content)

Delete a Google Cloud Storage file.

Args:
filename: A Google Cloud Storage filename of form '/bucket/filename'.
retry_params: An api_utils.RetryParams for this call to GCS. If None,
the default one is used.
_account_id: Internal-use only.

Raises:
errors.NotFoundError: if the file doesn't exist prior to deletion.


def sync(coro, timeout=None):

    loop = initloop()
    return asyncio.run_coroutine_threadsafe(coro, loop).result(timeout)

Schedule a coroutine to run on the global loop and return it's result.

Args:
coro (coroutine): The coroutine instance.

Notes:
This API is thread safe and should only be called by non-loop threads.


def feed(self, data_len, feed_time=None):
    self._bytes_transferred += data_len
    self._collected_bytes_transferred += data_len
    time_now = (feed_time or time.time())
    time_diff = (time_now - self._last_feed_time)
    if (time_diff < self._sample_min_time):
        return
    self._last_feed_time = time.time()
    if ((data_len == 0) and (time_diff >= self._stall_time)):
        self._stalled = True
        return
    self._samples.append((time_diff, self._collected_bytes_transferred))
    self._collected_bytes_transferred = 0

Update the bandwidth meter.

Args:
data_len (int): The number of bytes transfered since the last
call to :func:`feed`.
feed_time (float): Current time.