def rotate_view(self, axis_ind=0, angle=0):
    camera = self.ren.GetActiveCamera()
    if (axis_ind == 0):
        camera.Roll(angle)
    elif (axis_ind == 1):
        camera.Azimuth(angle)
    else:
        camera.Pitch(angle)
    self.ren_win.Render()

Rotate the camera view.

Args:
axis_ind: Index of axis to rotate. Defaults to 0, i.e., a-axis.
angle: Angle to rotate by. Defaults to 0.


async def get_random_popular_person(self, limit=500):

        index = random.randrange(limit)
        data = await self._get_popular_people_page()
        if data is None:
            return
        if index >= len(data['results']):

            page, index = self._calculate_page_index(index, data)
            data = await self._get_popular_people_page(page)
        if data is None:
            return
        json_data = data['results'][index]
        details = await self._get_person_json(json_data['id'])
        details.update(**json_data)
        return Person.from_json(details, self.config['data'].get('images'))

Randomly select a popular person.

Notes:
Requires at least two API calls. May require three API calls
if the randomly-selected index isn't within the first page of
required data.

Arguments:
limit (:py:class:`int`, optional): How many of the most
popular people to make random choice from (defaults to top
``500``).

Returns:
:py:class:`~.Person`: A randomly-selected popular person.


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

    if not self._file_object_set_in_init and not path_spec:
      raise ValueError('Missing path specification.')

    if self._file_object_set_in_init:
      return

    self._file_object = self._OpenFileObject(path_spec)
    if not self._file_object:
      raise IOError('Unable to open missing file-like object.')

Opens the file-like object defined by path specification.

Args:
path_spec (Optional[PathSpec]): path specification.
mode (Optional[str]): file access mode.

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


def Artifacts(self, os_name=None, cpe=None, label=None):

    return [
        c.artifact for c in self.conditions if c.Artifacts(os_name, cpe, label)
    ]

Find the artifacts that correspond with other trigger conditions.

Args:
os_name: An OS string.
cpe: A CPE string.
label: A label string.

Returns:
A list of artifacts to be processed.


def normal(self, shape, mean=0.0, stddev=1.0, dtype=dtypes.float32, name=None):
    with ops.name_scope(name, 'stateful_normal', [shape, mean, stddev]) as name:
        shape = _shape_tensor(shape)
        mean = ops.convert_to_tensor(mean, dtype=dtype, name='mean')
        stddev = ops.convert_to_tensor(stddev, dtype=dtype, name='stddev')
        rnd = self._standard_normal(shape, dtype=dtype)
        return math_ops.add(rnd * stddev, mean, name=name)

Outputs random values from a normal distribution.

Args:
shape: A 1-D integer Tensor or Python array. The shape of the output
tensor.
mean: A 0-D Tensor or Python value of type `dtype`. The mean of the normal
distribution.
stddev: A 0-D Tensor or Python value of type `dtype`. The standard
deviation of the normal distribution.
dtype: The type of the output.
name: A name for the operation (optional).

Returns:
A tensor of the specified shape filled with random normal values.


def add_string_parameters(self, string):

        if isinstance(string, list):
            for x in string:
                self.add_string_parameters(x)
            return
        self._parameters.append("{ \"value\": \"" + string + "\" }")

Add given string parameters to the internal list.

Args:
string (list of str or str): A string or list of strings to add to the parameters.


def __call__(self, y_true, y_pred, sample_weight=None, regularization_losses=None):
    y_true = self._conform_to_outputs(y_pred, y_true)
    sample_weight = self._conform_to_outputs(y_pred, sample_weight)
    if not self._built:
        self.build(y_pred)
    y_pred = nest.flatten(y_pred)
    y_true = nest.flatten(y_true)
    sample_weight = nest.flatten(sample_weight)
    loss_values = []
    loss_metric_values = []
    batch_dim = None
    zip_args = (y_true, y_pred, sample_weight, self._losses, self._loss_weights, self._per_output_metrics)
    for y_t, y_p, sw, loss_obj, loss_weight, metric_obj in zip(*zip_args):
        if y_t is None or loss_obj is None:
            continue
        y_t, y_p, sw = match_dtype_and_rank(y_t, y_p, sw)
        sw = apply_mask(y_p, sw, get_mask(y_p))
        loss_value = loss_obj(y_t, y_p, sample_weight=sw)
        loss_metric_value = loss_value
        if loss_obj.reduction == losses_utils.ReductionV2.SUM:
            loss_metric_value *= distribute_lib.get_strategy().num_replicas_in_sync
        if batch_dim is None:
            if tf_utils.is_ragged(y_t):
                batch_dim = y_t.nrows()
            else:
                batch_dim = array_ops.shape(y_t)[0]
        if metric_obj is not None:
            metric_obj.update_state(loss_metric_value, sample_weight=batch_dim)
        if loss_weight is not None:
            loss_value *= loss_weight
            loss_metric_value *= loss_weight
        if loss_obj.reduction == losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE or loss_obj.reduction == losses_utils.ReductionV2.AUTO:
            loss_value = losses_utils.scale_loss_for_distribution(loss_value)
        loss_values.append(loss_value)
        loss_metric_values.append(loss_metric_value)
    if regularization_losses:
        regularization_losses = losses_utils.cast_losses_to_common_dtype(regularization_losses)
        reg_loss = math_ops.add_n(regularization_losses)
        loss_metric_values.append(reg_loss)
        loss_values.append(losses_utils.scale_loss_for_distribution(reg_loss))
    if loss_values:
        loss_metric_values = losses_utils.cast_losses_to_common_dtype(loss_metric_values)
        total_loss_metric_value = math_ops.add_n(loss_metric_values)
        self._loss_metric.update_state(total_loss_metric_value, sample_weight=batch_dim)
        loss_values = losses_utils.cast_losses_to_common_dtype(loss_values)
        total_loss = math_ops.add_n(loss_values)
        return total_loss
    else:
        return array_ops.zeros(shape=())

Computes the overall loss.

Args:
y_true: An arbitrary structure of Tensors representing the ground truth.
y_pred: An arbitrary structure of Tensors representing a Model's outputs.
sample_weight: An arbitrary structure of Tensors representing the
per-sample loss weights. If one Tensor is passed, it is used for all
losses. If multiple Tensors are passed, the structure should match
`y_pred`.
regularization_losses: Additional losses to be added to the total loss.

Returns:
Tuple of `(total_loss, per_output_loss_list)`


def ch_start_time(self, *channels: List[Channel]) -> int:

        return self.timeslots.ch_start_time(*channels)

Return minimum start time for supplied channels.

Args:
*channels: Supplied channels


def _create_datadict(cls, internal_name):
    if (internal_name == 'LOCATION'):
        return Location()
    if (internal_name == 'DESIGN CONDITIONS'):
        return DesignConditions()
    if (internal_name == 'TYPICAL/EXTREME PERIODS'):
        return TypicalOrExtremePeriods()
    if (internal_name == 'GROUND TEMPERATURES'):
        return GroundTemperatures()
    if (internal_name == 'HOLIDAYS/DAYLIGHT SAVINGS'):
        return HolidaysOrDaylightSavings()
    if (internal_name == 'COMMENTS 1'):
        return Comments1()
    if (internal_name == 'COMMENTS 2'):
        return Comments2()
    if (internal_name == 'DATA PERIODS'):
        return DataPeriods()
    raise ValueError('No DataDictionary known for {}'.format(internal_name))

Creates an object depending on `internal_name`

Args:
internal_name (str): IDD name

Raises:
ValueError: if `internal_name` cannot be matched to a data dictionary object


def SetHasherNames(self, hasher_names_string):

    hasher_names = hashers_manager.HashersManager.GetHasherNamesFromString(
        hasher_names_string)

    debug_hasher_names = ', '.join(hasher_names)
    logger.debug('Got hasher names: {0:s}'.format(debug_hasher_names))

    self._hashers = hashers_manager.HashersManager.GetHashers(hasher_names)
    self._hasher_names_string = hasher_names_string

Sets the hashers that should be enabled.

Args:
hasher_names_string (str): comma separated names of hashers to enable.


def valUserCert(self, byts, cacerts=None):

        cert = crypto.load_certificate(crypto.FILETYPE_PEM, byts)

        if cacerts is None:
            cacerts = self.getCaCerts()

        store = crypto.X509Store()
        [store.add_cert(cacert) for cacert in cacerts]

        ctx = crypto.X509StoreContext(store, cert)
        ctx.verify_certificate()
        return cert

Validate the PEM encoded x509 user certificate bytes and return it.

Args:
byts (bytes): The bytes for the User Certificate.
cacerts (tuple): A tuple of OpenSSL.crypto.X509 CA Certificates.

Raises:
OpenSSL.crypto.X509StoreContextError: If the certificate is not valid.

Returns:
OpenSSL.crypto.X509: The certificate, if it is valid.


def get(self, client_id, client_secret, code, redirect_uri):
    check_type(client_id, basestring, may_be_none=False)
    check_type(client_secret, basestring, may_be_none=False)
    check_type(code, basestring, may_be_none=False)
    check_type(redirect_uri, basestring, may_be_none=False)
    post_data = dict_from_items_with_values(grant_type='authorization_code', client_id=client_id, client_secret=client_secret, code=code, redirect_uri=redirect_uri)
    response = requests.post(self._endpoint_url, data=post_data, **self._request_kwargs)
    check_response_code(response, EXPECTED_RESPONSE_CODE['POST'])
    json_data = extract_and_parse_json(response)
    return self._object_factory(OBJECT_TYPE, json_data)

Exchange an Authorization Code for an Access Token.

Exchange an Authorization Code for an Access Token that can be used to
invoke the APIs.

Args:
client_id(basestring): Provided when you created your integration.
client_secret(basestring): Provided when you created your
integration.
code(basestring): The Authorization Code provided by the user
OAuth process.
redirect_uri(basestring): The redirect URI used in the user OAuth
process.

Returns:
AccessToken: An AccessToken object with the access token provided
by the Webex Teams cloud.

Raises:
TypeError: If the parameter types are incorrect.
ApiError: If the Webex Teams cloud returns an error.


def GetVSSStoreIdentifiers(self, volume_system, volume_identifiers):
    print_header = True
    while True:
        if print_header:
            self._PrintVSSStoreIdentifiersOverview(volume_system, volume_identifiers)
            print_header = False
        self._output_writer.Write('\n')
        lines = self._textwrapper.wrap(self._USER_PROMPT_VSS)
        self._output_writer.Write('\n'.join(lines))
        self._output_writer.Write('\n\nVSS identifier(s): ')
        try:
            selected_volumes = self._ReadSelectedVolumes(volume_system, prefix='vss')
            if ((not selected_volumes) or (not set(selected_volumes).difference(volume_identifiers))):
                break
        except ValueError:
            pass
        self._output_writer.Write('\n')
        lines = self._textwrapper.wrap('Unsupported VSS identifier(s), please try again or abort with Ctrl^C.')
        self._output_writer.Write('\n'.join(lines))
        self._output_writer.Write('\n\n')
    return selected_volumes

Retrieves VSS store identifiers.

This method can be used to prompt the user to provide VSS store identifiers.

Args:
volume_system (VShadowVolumeSystem): volume system.
volume_identifiers (list[str]): volume identifiers including prefix.

Returns:
list[str]: selected volume identifiers including prefix or None.


def get_display_name(self, room=None):

        if room:
            try:
                return room.members_displaynames[self.user_id]
            except KeyError:
                return self.user_id
        if not self.displayname:
            self.displayname = self.api.get_display_name(self.user_id)
        return self.displayname or self.user_id

Get this user's display name.

Args:
room (Room): Optional. When specified, return the display name of the user
in this room.

Returns:
The display name. Defaults to the user ID if not set.


def graph_op_digests(self, op_type=None):
    if op_type is not None:
        return [digest for digest in self._graph_op_digests if digest.op_type == op_type]
    else:
        return self._graph_op_digests

Get the list of the digests for graph-op creation so far.

Args:
op_type: Optional op type to filter the creation events with.

Returns:
A list of `GraphOpCreationDigest` objects.


def _initialize_memory(self, policy_params):
    template = (self._batch_env.observ[0], self._batch_env.action[0], tools.nested.map((lambda x: x[(0, 0)]), policy_params), self._batch_env.reward[0])
    with tf.variable_scope('ppo_temporary'):
        self._current_episodes = parts.EpisodeMemory(template, len(self._batch_env), self._config.max_length, 'episodes')
    self._finished_episodes = parts.EpisodeMemory(template, self._config.update_every, self._config.max_length, 'memory')
    self._num_finished_episodes = tf.Variable(0, False)

Initialize temporary and permanent memory.

Args:
policy_params: Nested tuple of policy parameters with all dimensions set.

Initializes the attributes `self._current_episodes`,
`self._finished_episodes`, and `self._num_finished_episodes`. The episodes
memory serves to collect multiple episodes in parallel. Finished episodes
are copied into the next free slot of the second memory. The memory index
points to the next free slot.


def add_header(self, key, value, **params):
    key = self.escape(key)
    ci_key = key.casefold()

    def quoted_params(items):
        for p in items:
            param_name = self.escape(p[0])
            param_val = self.de_quote(self.escape(p[1]))
            (yield (param_name, param_val))
    sorted_items = sorted(params.items())
    quoted_iter = (('%s="%s"' % p) for p in quoted_params(sorted_items))
    param_str = ' '.join(quoted_iter)
    if param_str:
        value = ('%s; %s' % (value, param_str))
    self._header_data[ci_key] = (key, value)

Add a header to the collection, including potential parameters.

Args:
key (str): The name of the header
value (str): The value to store under that key
params: Option parameters to be appended to the value,
automatically formatting them in a standard way


def render_chart_data(data):

    builder = HtmlBuilder()
    builder._render_objects(data, datatype='chartdata')
    return builder._to_html()

Return a dictionary list formatted as a HTML table.

Args:
data: data in the form consumed by Google Charts.


def _create(cls, model_class, *args, **kwargs):

        manager = cls._get_manager(model_class)

        return manager.create_user(*args, **kwargs)

Create a new user instance.

Args:
model_class:
The type of model to create an instance of.
args:
Positional arguments to create the instance with.
kwargs:
Keyword arguments to create the instance with.

Returns:
A new user instance of the type specified by
``model_class``.


def open_image(fn):

    flags = cv2.IMREAD_UNCHANGED+cv2.IMREAD_ANYDEPTH+cv2.IMREAD_ANYCOLOR
    if not os.path.exists(fn) and not str(fn).startswith("http"):
        raise OSError('No such file or directory: {}'.format(fn))
    elif os.path.isdir(fn) and not str(fn).startswith("http"):
        raise OSError('Is a directory: {}'.format(fn))
    elif isdicom(fn):
        slice = pydicom.read_file(fn)
        if slice.PhotometricInterpretation.startswith('MONOCHROME'):

            im = np.stack([slice.pixel_array]*3,-1)
            return im / ((1 << slice.BitsStored)-1)
        else:

            raise OSError('Unsupported DICOM image with PhotometricInterpretation=={}'.format(slice.PhotometricInterpretation))
    else:

        try:
            if str(fn).startswith("http"):
                req = urllib.urlopen(str(fn))
                image = np.asarray(bytearray(req.read()), dtype="uint8")
                im = cv2.imdecode(image, flags).astype(np.float32)/255
            else:
                im = cv2.imread(str(fn), flags).astype(np.float32)/255
            if im is None: raise OSError(f'File not recognized by opencv: {fn}')
            return cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
        except Exception as e:
            raise OSError('Error handling image at: {}'.format(fn)) from e

Opens an image using OpenCV given the file path.

Arguments:
fn: the file path of the image

Returns:
The image in RGB format as numpy array of floats normalized to range between 0.0 - 1.0


def get_model_field(model, field_name):

    meta = model._meta
    try:
        if DJANGO19:
            field = meta.get_field(field_name)
        else:
            field = meta.get_field_by_name(field_name)[0]
        return field
    except:
        if DJANGO19:
            related_objs = (
                f for f in meta.get_fields()
                if (f.one_to_many or f.one_to_one)
                and f.auto_created and not f.concrete
            )
            related_m2m_objs = (
                f for f in meta.get_fields(include_hidden=True)
                if f.many_to_many and f.auto_created
            )
        else:
            related_objs = meta.get_all_related_objects()
            related_m2m_objs = meta.get_all_related_many_to_many_objects()

        related_objects = {
            o.get_accessor_name(): o
            for o in chain(related_objs, related_m2m_objs)
        }
        if field_name in related_objects:
            return related_objects[field_name]
        else:

            if hasattr(meta, 'virtual_fields'):
                for field in meta.virtual_fields:
                    if field.name == field_name:
                        return field

            raise AttributeError(
                '%s is not a valid field for %s' % (field_name, model)
            )

Return a field given a model and field name.

Arguments:
model: a Django model
field_name: the name of a field

Returns:
A Django field if `field_name` is a valid field for `model`,
None otherwise.


def __init__(self, parent=None):

        super(SupportedDtypesTranslator, self).__init__(parent)

        self._strs = [(np.dtype(object), self.tr('text'))]

        self._ints = [(np.dtype(np.int8), self.tr('small integer (8 bit)')),
                      (np.dtype(np.int16), self.tr('small integer (16 bit)')),
                      (np.dtype(np.int32), self.tr('integer (32 bit)')),
                      (np.dtype(np.int64), self.tr('integer (64 bit)'))]

        self._uints = [(np.dtype(np.uint8), self.tr('unsigned small integer (8 bit)')),
                       (np.dtype(np.uint16), self.tr('unsigned small integer (16 bit)')),
                       (np.dtype(np.uint32), self.tr('unsigned integer (32 bit)')),
                       (np.dtype(np.uint64), self.tr('unsigned integer (64 bit)'))]

        self._floats = [(np.dtype(np.float16), self.tr('floating point number (16 bit)')),
                      (np.dtype(np.float32), self.tr('floating point number (32 bit)')),
                      (np.dtype(np.float64), self.tr('floating point number (64 bit)'))]

        self._datetime = [(np.dtype('<M8[ns]'), self.tr('date and time'))]

        self._bools = [(np.dtype(bool), self.tr('true/false value'))]

        self._all = self._strs + self._ints + self._uints + self._floats + self._bools + self._datetime

Constructs the object with the given parent.

Args:
parent (QtCore.QObject, optional): Causes the objected to be owned
by `parent` instead of Qt. Defaults to `None`.


def __init__(self, vertex_out, vertex_in, weight=1):

        self.vertex_out = None
        self.vertex_in = None
        self.weight = weight
        self.go_from(vertex_out)
        self.go_in(vertex_in)

Initialization method.

Args:
vertex_out (Vertex): source vertex (edge going out).
vertex_in (Vertex): target vertex (edge going in).
weight (int): weight of the edge.


def rgb_to_grayscale(images, name=None):
    with ops.name_scope(name, 'rgb_to_grayscale', [images]) as name:
        images = ops.convert_to_tensor(images, name='images')
        orig_dtype = images.dtype
        flt_image = convert_image_dtype(images, dtypes.float32)
        rgb_weights = [0.2989, 0.587, 0.114]
        gray_float = math_ops.tensordot(flt_image, rgb_weights, [-1, -1])
        gray_float = array_ops.expand_dims(gray_float, -1)
        return convert_image_dtype(gray_float, orig_dtype, name=name)

Converts one or more images from RGB to Grayscale.

Outputs a tensor of the same `DType` and rank as `images`.  The size of the
last dimension of the output is 1, containing the Grayscale value of the
pixels.

>>> original = tf.constant([[[1.0, 2.0, 3.0]]])
>>> converted = tf.image.rgb_to_grayscale(original)
>>> print(converted.numpy())
[[[1.81...]]]

Args:
images: The RGB tensor to convert. The last dimension must have size 3 and
should contain RGB values.
name: A name for the operation (optional).

Returns:
The converted grayscale image(s).


def _wrap_2d_function(inputs, compute_op, dim=-1, name=None):

    def _swap_axis(input_tensor, dim_index, last_index, name=None):

        return array_ops.transpose(input_tensor, array_ops.concat([math_ops.range(dim_index), [last_index], math_ops.range(dim_index + 1, last_index), [dim_index]], 0), name=name)
    inputs = ops.convert_to_tensor(inputs)
    shape = inputs.get_shape()
    is_last_dim = dim == -1 or dim == shape.ndims - 1
    if is_last_dim:
        return compute_op(inputs, name=name)
    dim_val = dim
    if isinstance(dim, tensor_lib.Tensor):
        dim_val = tensor_util.constant_value(dim)
    if dim_val is not None and (not -shape.ndims <= dim_val < shape.ndims):
        raise errors_impl.InvalidArgumentError(None, None, f'`dim` must be in the range [{-shape.ndims}, {shape.ndims}) where {shape.ndims} is the number of dimensions in the input. Received: dim={dim_val}')
    ndims = array_ops.rank(inputs)
    if not isinstance(dim, tensor_lib.Tensor):
        if dim < 0:
            dim += ndims
    else:
        dim = array_ops.where(math_ops.less(dim, 0), dim + ndims, dim)
    input_rank = array_ops.rank(inputs)
    dim_axis = dim % shape.ndims
    inputs = _swap_axis(inputs, dim_axis, math_ops.subtract(input_rank, 1))

    def fix_output(output):
        output = _swap_axis(output, dim_axis, math_ops.subtract(input_rank, 1), name=name)
        output.set_shape(shape)
        return output
    outputs = compute_op(inputs)
    if isinstance(outputs, tuple):
        return tuple((fix_output(output) for output in outputs))
    else:
        return fix_output(outputs)

Helper function for ops that accept and return 2d inputs of same shape.

It reshapes and transposes the inputs into a 2-D Tensor and then invokes
the given function. The output would be transposed and reshaped back.
If the given function returns a tuple of tensors, each of them will be
transposed and reshaped.

Args:
inputs: A non-empty `Tensor`. Must be one of the following types: `half`,
`float32`, `float64`.
compute_op: The function to wrap. Must accept the input tensor as its first
arugment, and a second keyword argument `name`.
dim: The dimension softmax would be performed on. The default is -1 which
indicates the last dimension.
name: A name for the operation (optional).

Returns:
A `Tensor`. Has the same shape as inputs. If compute_op returns multiple
tensors, each of them have the same shape as the input.
Raises:
InvalidArgumentError: if `inputs` is empty or `dim` is beyond the last
dimension of `inputs`.


def get_invalid_txn_info(self, batch_id):
    with self._lock:
        return [info.copy() for info in self._invalid.get(batch_id, [])]

Fetches the id of the Transaction that failed within a particular
Batch, as well as any error message or other data about the failure.

Args:
batch_id (str): The id of the Batch containing an invalid txn

Returns:
list of dict: A list of dicts with three possible keys:
* 'id' - the header_signature of the invalid Transaction
* 'message' - the error message sent by the TP
* 'extended_data' - any additional data sent by the TP


def _get_overlaps_tensor(self, L):
    (n, m) = L.shape
    LY = np.array([np.where((L == y), 1, 0) for y in range(self.k_0, (self.k + 1))])
    O = (np.einsum('abc,dbe,fbg->cegadf', LY, LY, LY) / n)
    return torch.from_numpy(O).float()

Transforms the input label matrix to a three-way overlaps tensor.

Args:
L: (np.array) An n x m array of LF output labels, in {0,...,k} if
self.abstains, else in {1,...,k}, generated by m conditionally
independent LFs on n data points

Outputs:
O: (torch.Tensor) A (m, m, m, k, k, k) tensor of the label-specific
empirical overlap rates; that is,

O[i,j,k,y1,y2,y3] = P(\lf_i = y1, \lf_j = y2, \lf_k = y3)

where this quantity is computed empirically by this function, based
on the label matrix L.


def derive_annotations(self, annotations):

        cls = type(self)

        return cls(
            self[0],
            self[1],
            self[2],
            self[3],
            annotations,
            self[5]
        )

Derives a new event from this one setting the ``annotations`` attribute.

Args:
annotations: (Sequence[Union[amazon.ion.symbols.SymbolToken, unicode]]):
The annotations associated with the derived event.

Returns:
IonEvent: The newly generated event.


def register_key_flag_for_module(self, module_name, flag):

    key_flags_by_module = self.key_flags_by_module_dict()

    key_flags = key_flags_by_module.setdefault(module_name, [])

    if flag not in key_flags:
      key_flags.append(flag)

Specifies that a flag is a key flag for a module.

Args:
module_name: str, the name of a Python module.
flag: Flag, the Flag instance that is key to the module.


def filter(self, scored_list):
    top_n_key = ((- 1) * self.top_n)
    top_n_list = sorted(scored_list, key=(lambda x: x[1]))[top_n_key:]
    result_list = sorted(top_n_list, key=(lambda x: x[0]))
    return result_list

Filtering with top-n ranking.

Args:
scored_list:    The list of scoring.

Retruns:
The list of filtered result.


def peek(self, index, name=None):
    if name is None:
        name = '%s_peek' % self._name
    fn = lambda: gen_data_flow_ops.stage_peek(index, dtypes=self._dtypes, shared_name=self._name, name=name, capacity=self._capacity, memory_limit=self._memory_limit)
    return self.__internal_get(fn, name)

Peeks at an element in the staging area.

If the staging area is too small to contain the element at
the specified index, it will block until enough elements
are inserted to complete the operation.

The placement of the returned tensor will be determined by
the current device scope when this function is called.

Args:
index: The index of the tensor within the staging area
to look up.
name: A name for the operation (optional).

Returns:
The tuple of tensors that was gotten.


def get_numpy_iterator(self):
    raise NotImplementedError

Get a Python iterable for the `DataAdapter`, that yields NumPy
arrays.

Returns:
A Python iterator.


def save_model_to_hdf5(model, filepath, overwrite=True, include_optimizer=True):
    if h5py is None:
        raise ImportError('`save_model` requires h5py.')
    if len(model.weights) != len(model._undeduplicated_weights):
        logging.warning('Found duplicated `Variable`s in Model\'s `weights`. This is usually caused by `Variable`s being shared by Layers in the Model. These `Variable`s will be treated as separate `Variable`s when the Model is restored. To avoid this, please save with `save_format="tf"`.')
    if not isinstance(filepath, h5py.File):
        if not overwrite and os.path.isfile(filepath):
            proceed = ask_to_proceed_with_overwrite(filepath)
            if not proceed:
                return
        dirpath = os.path.dirname(filepath)
        if not os.path.exists(dirpath):
            gfile.MakeDirs(dirpath)
        f = h5py.File(filepath, mode='w')
        opened_new_file = True
    else:
        f = filepath
        opened_new_file = False
    try:
        model_metadata = saving_utils.model_metadata(model, include_optimizer)
        for k, v in model_metadata.items():
            if isinstance(v, (dict, list, tuple)):
                f.attrs[k] = json.dumps(v, default=json_utils.get_json_type).encode('utf8')
            else:
                f.attrs[k] = v
        model_weights_group = f.create_group('model_weights')
        model_layers = model.layers
        save_weights_to_hdf5_group(model_weights_group, model_layers)
        if include_optimizer and model.optimizer and (not isinstance(model.optimizer, optimizer_v1.TFOptimizer)):
            save_optimizer_weights_to_hdf5_group(f, model.optimizer)
        f.flush()
    finally:
        if opened_new_file:
            f.close()

Saves a model to a HDF5 file.

The saved model contains:
- the model's configuration (topology)
- the model's weights
- the model's optimizer's state (if any)

Thus the saved model can be reinstantiated in
the exact same state, without any of the code
used for model definition or training.

Args:
model: Keras model instance to be saved.
filepath: One of the following:
- String, path where to save the model
- `h5py.File` object where to save the model
overwrite: Whether we should overwrite any existing
model at the target location, or instead
ask the user with a manual prompt.
include_optimizer: If True, save optimizer's state together.

Raises:
ImportError: if h5py is not available.


def convert_ids_to_tokens(self, ids: Union[int, list[int]], skip_special_tokens: bool=False) -> Union[str, list[str]]:
    if isinstance(ids, int):
        return self._tokenizer.id_to_token(ids)
    tokens = []
    ids_to_skip = set(self.all_special_ids) if skip_special_tokens else set()
    for index in ids:
        index = int(index)
        if index in ids_to_skip:
            continue
        tokens.append(self._tokenizer.id_to_token(index))
    return tokens

Converts a single index or a sequence of indices in a token or a sequence of tokens, using the vocabulary and
added tokens.

Args:
ids (`int` or `List[int]`):
The token id (or token ids) to convert to tokens.
skip_special_tokens (`bool`, *optional*, defaults to `False`):
Whether or not to remove special tokens in the decoding.

Returns:
`str` or `List[str]`: The decoded token(s).


def record_batch_metrics(self, requests_in_batch: List) -> None:
    if not _has_opentelemetry or not requests_in_batch:
        return
    decode_tokens = 0
    prefill_tokens = 0
    for state in requests_in_batch:
        if state.status == RequestStatus.DECODING:
            decode_tokens += 1
        elif state.status in [RequestStatus.PREFILLING, RequestStatus.PREFILLING_SPLIT]:
            prefill_tokens += len(state.prompt_ids)
    total_batch_tokens = decode_tokens + prefill_tokens
    try:
        if prefill_tokens > 0:
            self.prefill_tokens_counter.add(prefill_tokens)
        if decode_tokens > 0:
            self.decode_tokens_counter.add(decode_tokens)
        if prefill_tokens > 0:
            ratio = decode_tokens / prefill_tokens
            self.decode_prefill_ratio_gauge.set(ratio)
        fill_percentage = total_batch_tokens / self.max_batch_tokens * 100.0
        self.batch_fill_percentage_histogram.record(fill_percentage)
        logger.debug(f'Batch metrics: {decode_tokens} decode tokens, {prefill_tokens} prefill tokens, batch fill: {fill_percentage:.2f}% ({total_batch_tokens}/{self.max_batch_tokens})')
    except Exception as e:
        logger.warning(f'Failed to record batch metrics: {e}')

Record metrics about the batch composition including decode/prefill ratio and batch fill percentage.

Args:
requests_in_batch: List of request states in the current batch


def remove(self, *dic):

        dicList = list(flatten(dic))
        for d in dicList:
            di = []
            for k in d:

                di.append(Pair(k, IntegerSingle(d[k])))
            dictSingle = DictSingle(di)

            self._remove([dictSingle], self.l)

remove a calendar config.

Args:
*dic (dict): dictionary with format {'Day': 12, 'Hour': 34} Avaliable keys are Month, Day, Weekday, Hour, Minute. *Note the uppercase.* You can use gen(), genMix() to generate complex config dictionary.


def get_random_numeric_tensor(self, dtype=None, min_size=_MIN_SIZE, max_size=_MAX_SIZE, min_val=_MIN_INT, max_val=_MAX_INT):
    if max_size > 8:
        raise tf.errors.InvalidArgumentError(None, None, 'Given size of {} will result in an OOM error'.format(max_size))
    seed = self.get_int()
    shape = self.get_int_list(min_length=min_size, max_length=max_size, min_int=min_size, max_int=max_size)
    if dtype is None:
        dtype = self.get_tf_dtype(allowed_set=_TF_RANDOM_DTYPES)
    elif dtype not in _TF_RANDOM_DTYPES:
        raise tf.errors.InvalidArgumentError(None, None, 'Given dtype {} is not accepted in get_random_numeric_tensor'.format(dtype))
    return tf.random.uniform(shape=shape, minval=min_val, maxval=max_val, dtype=dtype, seed=seed)

Return a tensor of random shape and values.

Generated tensors are capped at dimension sizes of 8, as 2^32 bytes of
requested memory crashes the fuzzer (see b/34190148).
Returns only type that tf.random.uniform can generate. If you need a
different type, consider using tf.cast.

Args:
dtype: Type of tensor, must of one of the following types: float16,
float32, float64, int32, or int64
min_size: Minimum size of returned tensor
max_size: Maximum size of returned tensor
min_val: Minimum value in returned tensor
max_val: Maximum value in returned tensor

Returns:
Tensor of random shape filled with uniformly random numeric values.


def export_gpx_file(self):
    gpx = create_elem('gpx', GPX_ELEM_ATTRIB)
    if (not self.metadata.bounds):
        self.metadata.bounds = [j for i in self for j in i]
    gpx.append(self.metadata.togpx())
    track = create_elem('trk')
    gpx.append(track)
    for segment in self:
        chunk = create_elem('trkseg')
        track.append(chunk)
        for place in segment:
            chunk.append(place.togpx())
    return etree.ElementTree(gpx)

Generate GPX element tree from ``Trackpoints``.

Returns:
etree.ElementTree: GPX element tree depicting ``Trackpoints``
objects


def __init__(self, visitor):
    self._visitor = visitor
    self._root_name = 'tf'
    self._private_map = {'tf': ['compiler', 'core', 'security', 'dtensor', 'python', 'tsl'], 'tf.flags': ['cpp_flags']}
    self._do_not_descend_map = {'tf': ['examples', 'flags', 'platform', 'pywrap_tensorflow', 'user_ops', 'tools', 'tensorboard'], 'tf.app': ['flags'], 'tf.test': ['mock']}

Constructor.

`visitor` should be a callable suitable as a visitor for `traverse`. It will
be called only for members of the public TensorFlow API.

Args:
visitor: A visitor to call for the public API.


def from_arrays(cls, path, trn, val, bs=64, tfms=(None, None), classes=None, num_workers=4, test=None, continuous=False):
    f = (ArraysIndexRegressionDataset if continuous else ArraysIndexDataset)
    datasets = cls.get_ds(f, trn, val, tfms, test=test)
    return cls(path, datasets, bs, num_workers, classes=classes)

Read in images and their labels given as numpy arrays

Arguments:
path: a root path of the data (used for storing trained models, precomputed values, etc)
trn: a tuple of training data matrix and target label/classification array (e.g. `trn=(x,y)` where `x` has the
shape of `(5000, 784)` and `y` has the shape of `(5000,)`)
val: a tuple of validation data matrix and target label/classification array.
bs: batch size
tfms: transformations (for data augmentations). e.g. output of `tfms_from_model`
classes: a list of all labels/classifications
num_workers: a number of workers
test: a matrix of test data (the shape should match `trn[0]`)

Returns:
ImageClassifierData


def start_dag(self, dag, *, data=None):

        return self._client.send(
            Request(
                action='start_dag',
                payload={'name': dag.name if isinstance(dag, Dag) else dag,
                         'data': data if isinstance(data, MultiTaskData) else None}
            )
        ).payload['dag_name']

Schedule the execution of a dag by sending a signal to the workflow.

Args:
dag (Dag, str): The dag object or the name of the dag that should be started.
data (MultiTaskData): The data that should be passed on to the new dag.

Returns:
str: The name of the successfully started dag.


def forward(self, device_port, local_port=None):

        port = self._adb_device.forward(device_port, local_port)
        return (self._host, port)

Forward device port to local
Args:
device_port: port inside device
local_port: port on PC, if this value is None, a port will random pick one.

Returns:
tuple, (host, local_port)


def pixel_image(shape, sd=None, init_val=None):

    if sd is not None and init_val is not None:
        warnings.warn(
            "`pixel_image` received both an initial value and a sd argument. Ignoring sd in favor of the supplied initial value."
        )

    sd = sd or 0.01
    init_val = init_val or np.random.normal(size=shape, scale=sd).astype(np.float32)
    return tf.Variable(init_val)

A naive, pixel-based image parameterization.
Defaults to a random initialization, but can take a supplied init_val argument
instead.

Args:
shape: shape of resulting image, [batch, width, height, channels].
sd: standard deviation of param initialization noise.
init_val: an initial value to use instead of a random initialization. Needs
to have the same shape as the supplied shape argument.

Returns:
tensor with shape from first argument.


def _get_bit(self, n, hash_bytes):

        if hash_bytes[n
            return True

        return False

Determines if the n-th bit of passed bytes is 1 or 0.

Arguments:

hash_bytes - List of hash byte values for which the n-th bit value
should be checked. Each element of the list should be an integer from
0 to 255.

Returns:

True if the bit is 1. False if the bit is 0.


def update_dns_zone_record(env, zone_id, **kwargs):
    client = boto3.Session(profile_name=env).client('route53')
    response = {}
    hosted_zone_info = client.get_hosted_zone(Id=zone_id)
    zone_name = hosted_zone_info['HostedZone']['Name'].rstrip('.')
    dns_name = kwargs.get('dns_name')
    if (dns_name and dns_name.endswith(zone_name)):
        dns_name_aws = kwargs.get('dns_name_aws')
        dns_json = get_template(template_file='infrastructure/dns_upsert.json.j2', **kwargs)
        LOG.info('Attempting to create DNS record %s (%s) in Hosted Zone %s (%s)', dns_name, dns_name_aws, zone_id, zone_name)
        try:
            response = client.change_resource_record_sets(HostedZoneId=zone_id, ChangeBatch=json.loads(dns_json))
            LOG.info('Upserted DNS record %s (%s) in Hosted Zone %s (%s)', dns_name, dns_name_aws, zone_id, zone_name)
        except botocore.exceptions.ClientError as error:
            LOG.info('Error creating DNS record %s (%s) in Hosted Zone %s (%s)', dns_name, dns_name_aws, zone_id, zone_name)
            LOG.debug(error)
    else:
        LOG.info('Skipping creating DNS record %s in non-matching Hosted Zone %s (%s)', dns_name, zone_id, zone_name)
    LOG.debug('Route53 JSON Response: \n%s', pformat(response))

Create a Route53 CNAME record in _env_ zone.

Args:
env (str): Deployment environment.
zone_id (str): Route53 zone id.

Keyword Args:
dns_name (str): FQDN of application's dns entry to add/update.
dns_name_aws (str): FQDN of AWS resource
dns_ttl (int): DNS time-to-live (ttl)


def __init__(self, input_queue, output_queue):

        super(WorkflowThread, self).__init__(input_queue, output_queue)
        self.pending = PendingBarriers()
        self.worker_threads = []
        self.register(WorkflowItem, input_queue)

Initializer.

Args:
input_queue: Queue this worker consumes work from. These should be
WorkflowItems to process, or any WorkItems registered with this
class using the register() method.
output_queue: Queue where this worker puts finished work items,
if any.


def __init__(self, chain):

        self.queue = []
        self._fsm = JTAGStateMachine()
        self._chain = chain

Create a new CommandQueue to manage, compile, and run Primitives.

Args:
chain: A JTAGScanChain instance that this queue will be associated with.


def _last_path_token(builder: expressions.Builder) -> str:
    if isinstance(builder.node, _evaluation.RootMessageNode):
        return ''
    return builder.node.to_path_token()

Returns `builder`'s last path token less the resource type.

For example:
* "Foo" returns "" (empty string)
* "Foo.bar" returns "bar"
* "Foo.bar.bats" returns "bats"

Args:
builder: The `builder` whose relative path to return.


def dna_transformation(prev_image, dna_input, dna_kernel_size, relu_shift):

  prev_image_pad = tf.pad(prev_image, [[0, 0], [2, 2], [2, 2], [0, 0]])
  image_height = int(prev_image.get_shape()[1])
  image_width = int(prev_image.get_shape()[2])

  inputs = []
  for xkern in range(dna_kernel_size):
    for ykern in range(dna_kernel_size):
      inputs.append(
          tf.expand_dims(
              tf.slice(prev_image_pad, [0, xkern, ykern, 0],
                       [-1, image_height, image_width, -1]), [3]))
  inputs = tf.concat(axis=3, values=inputs)

  kernel = tf.nn.relu(dna_input - relu_shift) + relu_shift
  kernel = tf.expand_dims(
      kernel / tf.reduce_sum(kernel, [3], keep_dims=True), [4])
  return tf.reduce_sum(kernel * inputs, [3], keep_dims=False)

Apply dynamic neural advection to previous image.

Args:
prev_image: previous image to be transformed.
dna_input: hidden lyaer to be used for computing DNA transformation.
dna_kernel_size: dna kernel size.
relu_shift: shift for ReLU function.
Returns:
List of images transformed by the predicted CDNA kernels.


def serialize_quantity(o):

    return dict(
        _type='astropy.units.Quantity',
        value=o.value,
        unit=o.unit.to_string())

Serializes an :obj:`astropy.units.Quantity`, for JSONification.

Args:
o (:obj:`astropy.units.Quantity`): :obj:`Quantity` to be serialized.

Returns:
A dictionary that can be passed to :obj:`json.dumps`.


def normalize_json(template):
    obj = parse_cloudformation_template(template)
    json_str = json.dumps(obj, sort_keys=True, indent=4, default=str, separators=(',', ': '))
    result = []
    lines = json_str.split('\n')
    for line in lines:
        result.append((line + '\n'))
    return result

Normalize our template for diffing.

Args:
template(str): string representing the template

Returns:
list: json representation of the parameters


def _from_yaml_v0(cls, job):
    job_metadata = {}
    for key in ['job-id', 'job-name', 'create-time']:
        job_metadata[key] = job.get(key)
    job_metadata['create-time'] = dsub_util.replace_timezone(datetime.datetime.strptime(job['create-time'], '%Y-%m-%d %H:%M:%S.%f'), tzlocal())
    job_resources = Resources()
    params = {}
    labels = job.get('labels', {})
    if ('dsub-version' in labels):
        job_metadata['dsub-version'] = labels['dsub-version']
        del labels['dsub-version']
    params['labels'] = cls._label_params_from_dict(labels)
    params['envs'] = cls._env_params_from_dict(job.get('envs', {}))
    params['inputs'] = cls._input_file_params_from_dict(job.get('inputs', {}), False)
    params['outputs'] = cls._output_file_params_from_dict(job.get('outputs', {}), False)
    if (job.get('task-id') is None):
        job_params = params
        task_metadata = {'task-id': None}
        task_params = {}
    else:
        job_params = {}
        task_metadata = {'task-id': str(job.get('task-id'))}
        task_params = params
    task_resources = Resources(logging_path=job.get('logging'))
    task_descriptors = [TaskDescriptor.get_complete_descriptor(task_metadata, task_params, task_resources)]
    return JobDescriptor.get_complete_descriptor(job_metadata, job_params, job_resources, task_descriptors)

Populate a JobDescriptor from the local provider's original meta.yaml.

The local job provider had the first incarnation of a YAML file for each
task. That idea was extended here in the JobDescriptor and the local
provider adopted the JobDescriptor.to_yaml() call to write its meta.yaml.

The JobDescriptor.from_yaml() detects if it receives a local provider's
"v0" meta.yaml and calls this function.

Args:
job: an object produced from decoding meta.yaml.

Returns:
A JobDescriptor populated as best we can from the old meta.yaml.


def _iterate_through_class(self, class_dict):
    output_dict = {}
    for key in class_dict:
        val = class_dict[key]
        try:
            val = val.__dict__
        except AttributeError:
            pass
        if (type(val) is dict):
            val = self._iterate_through_class(val)
        if (type(val) is list):
            temp_val = []
            for val_i in val:
                try:
                    val_i = val_i.__dict__
                except AttributeError:
                    pass
                if (type(val_i) is dict):
                    val_i = self._iterate_through_class(val_i)
                temp_val.append(val_i)
            val = temp_val
        output_dict[key] = val
    return output_dict

Recursive function for output dictionary creation.

Function will check each value in a dictionary to see if it is a
class, list, or dictionary object. The idea is to turn all class objects into
dictionaries. If it is a class object it will pass its ``class.__dict__``
recursively through this function again. If it is a dictionary,
it will pass the dictionary recursively through this functin again.

If the object is a list, it will iterate through entries checking for class
or dictionary objects and pass them recursively through this function.
This uses the knowledge of the list structures in the code.

Args:
class_dict (obj): Dictionary to iteratively check.

Returns:
Dictionary with all class objects turned into dictionaries.


def cdna_transformation(prev_image, cdna_input, num_masks, color_channels, dna_kernel_size, relu_shift):
    batch_size = tf.shape(cdna_input)[0]
    height = int(prev_image.get_shape()[1])
    width = int(prev_image.get_shape()[2])
    cdna_kerns = tfl.dense(cdna_input, ((dna_kernel_size * dna_kernel_size) * num_masks), name='cdna_params', activation=None)
    cdna_kerns = tf.reshape(cdna_kerns, [batch_size, dna_kernel_size, dna_kernel_size, 1, num_masks])
    cdna_kerns = (tf.nn.relu((cdna_kerns - relu_shift)) + relu_shift)
    norm_factor = tf.reduce_sum(cdna_kerns, [1, 2, 3], keep_dims=True)
    cdna_kerns /= norm_factor
    cdna_kerns = tf.transpose(cdna_kerns, [1, 2, 0, 4, 3])
    cdna_kerns = tf.reshape(cdna_kerns, [dna_kernel_size, dna_kernel_size, batch_size, num_masks])
    prev_image = tf.transpose(prev_image, [3, 1, 2, 0])
    transformed = tf.nn.depthwise_conv2d(prev_image, cdna_kerns, [1, 1, 1, 1], 'SAME')
    transformed = tf.reshape(transformed, [color_channels, height, width, batch_size, num_masks])
    transformed = tf.transpose(transformed, [3, 1, 2, 0, 4])
    transformed = tf.unstack(transformed, axis=(- 1))
    return transformed

Apply convolutional dynamic neural advection to previous image.

Args:
prev_image: previous image to be transformed.
cdna_input: hidden lyaer to be used for computing CDNA kernels.
num_masks: number of masks and hence the number of CDNA transformations.
color_channels: the number of color channels in the images.
dna_kernel_size: dna kernel size.
relu_shift: shift for ReLU function.
Returns:
List of images transformed by the predicted CDNA kernels.


class _ImageEmbeddingHandler(_EmbeddingHandler):

    def _validate_column_data(self, batch):
        if isinstance(batch[0], (int, str, float, bool)):
            raise TypeError(f'Embeddings can only be generated on dict[str, Image].Got dict[str, {type(batch[0])}] instead.')

    def get_metrics_namespace(self) -> str:
        return self._underlying.get_metrics_namespace() or 'BeamML_ImageEmbeddingHandler'

A ModelHandler intended to be work on list[dict[str, Image]] inputs.

The inputs to the model handler are expected to be a list of dicts.

For example, if the original mode is used with RunInference to take a
PCollection[E] to a PCollection[P], this ModelHandler would take a
PCollection[dict[str, E]] to a PCollection[dict[str, P]].

_ImageEmbeddingHandler will accept an EmbeddingsManager instance, which
contains the details of the model to be loaded and the inference_fn to be
used. The purpose of _ImageEmbeddingHandler is to generate embeddings for
image inputs using the EmbeddingsManager instance.

If the input is not an Image representation column, a RuntimeError will be
raised.

This is an internal class and offers no backwards compatibility guarantees.

Args:
embeddings_manager: An EmbeddingsManager instance.


def plugin_test_validation(self, handler):

        methods = {name:func for name, func in inspect.getmembers(handler, callable)}
        if 'test' not in methods.keys():
            print 'Failure for plugin: %s' % (handler.__name__)
            print 'Validation Error: The file must have a top level test() method'
            return None
        else:
            return methods['test']

Plugin validation.

Every workbench plugin must have top level test method.

Args:
handler: The loaded plugin.

Returns:
None if the test fails or the test function.


def end_entry(self):
    if (self.in_progress is None):
        return Error.NO_ERROR
    if (self.in_progress.data_space() == 2):
        return Error.INPUT_BUFFER_WRONG_SIZE
    for entry in self.entries:
        if ((entry.target == self.in_progress.target) and (entry.var_id == self.in_progress.var_id)):
            entry.valid = False
    self.entries.append(self.in_progress)
    self.data_index += (self.in_progress.data_space() - 2)
    self.in_progress = None
    return Error.NO_ERROR

Finish a previously started config database entry.

This commits the currently in progress entry.  The expected flow is
that start_entry() is called followed by 1 or more calls to add_data()
followed by a single call to end_entry().

Returns:
int: An error code


def add(self, private_key):

        if not isinstance(private_key, PaillierPrivateKey):
            raise TypeError("private_key should be of type PaillierPrivateKey, "
                            "not %s" % type(private_key))
        self.__keyring[private_key.public_key] = private_key

Add a key to the keyring.

Args:
private_key (PaillierPrivateKey): a key to add to this keyring.


def load_fasta_file_as_dict_of_seqrecords(filename):

    results = {}
    records = load_fasta_file(filename)
    for r in records:
        results[r.id] = r

    return results

Load a FASTA file and return the sequences as a dict of {ID: SeqRecord}

Args:
filename (str): Path to the FASTA file to load

Returns:
dict: Dictionary of IDs to their SeqRecords


def __method_descriptor(self, service, method_info, operation_id,
                          protorpc_method_info, security_definitions):

    descriptor = {}

    request_message_type = (resource_container.ResourceContainer.
                            get_request_message(protorpc_method_info.remote))
    request_kind = self.__get_request_kind(method_info)
    remote_method = protorpc_method_info.remote

    path = method_info.get_path(service.api_info)

    descriptor['parameters'] = self.__request_message_descriptor(
        request_kind, request_message_type,
        method_info.method_id(service.api_info),
        path)
    descriptor['responses'] = self.__response_message_descriptor(
        remote_method.response_type(), method_info.method_id(service.api_info))
    descriptor['operationId'] = operation_id

    api_key_required = method_info.is_api_key_required(service.api_info)
    if method_info.audiences is not None:
      descriptor['security'] = self.__security_descriptor(
          method_info.audiences, security_definitions,
          api_key_required=api_key_required)
    elif service.api_info.audiences is not None or api_key_required:
      descriptor['security'] = self.__security_descriptor(
          service.api_info.audiences, security_definitions,
          api_key_required=api_key_required)

    if method_info.metric_costs:
      descriptor['x-google-quota'] = self.__x_google_quota_descriptor(
          method_info.metric_costs)

    return descriptor

Describes a method.

Args:
service: endpoints.Service, Implementation of the API as a service.
method_info: _MethodInfo, Configuration for the method.
operation_id: string, Operation ID of the method
protorpc_method_info: protorpc.remote._RemoteMethodInfo, ProtoRPC
description of the method.
security_definitions: list of dicts, security definitions for the API.

Returns:
Dictionary describing the method.


def fetch_time_output(marker, format_s, ins):

    from parse import parse

    timings = [x for x in ins if marker in x]
    res = [parse(format_s, t) for t in timings]
    return [_f for _f in res if _f]

Fetch the output /usr/bin/time from a.

Args:
marker: The marker that limits the time output
format_s: The format string used to parse the timings
ins: A list of lines we look for the output.

Returns:
A list of timing tuples


def post(self, json=None):

        return self._call('post', url=self.endpoint, json=json)

Send a POST request and return the JSON decoded result.

Args:
json (dict, optional): Object to encode and send in request.

Returns:
mixed: JSON decoded response data.


def get_variants(self, chromosome=None, start=None, end=None):
    query = {}
    if chromosome:
        query['chrom'] = chromosome
    if start:
        query['start'] = {'$lte': end}
        query['end'] = {'$gte': start}
    LOG.info('Find all variants {}'.format(query))
    return self.db.variant.find(query).sort([('start', ASCENDING)])

Return all variants in the database
If no region is specified all variants will be returned.

Args:
chromosome(str)
start(int)
end(int)

Returns:
variants(Iterable(Variant))


def generate_hpo_gene_list(self, *hpo_terms):

        genes = {}
        for term in hpo_terms:
            hpo_obj = self.hpo_term(term)
            if hpo_obj:
                for hgnc_id in hpo_obj['genes']:
                    if hgnc_id in genes:
                        genes[hgnc_id] += 1
                    else:
                        genes[hgnc_id] = 1
            else:
                LOG.warning("Term %s could not be found", term)

        sorted_genes = sorted(genes.items(), key=operator.itemgetter(1), reverse=True)
        return sorted_genes

Generate a sorted list with namedtuples of hpogenes

Each namedtuple of the list looks like (hgnc_id, count)

Args:
hpo_terms(iterable(str))

Returns:
hpo_genes(list(HpoGene))


def get_username(self, userid):

        username = self.user_map.get(userid)
        if not username:
            users = self.get_users()
            if users:
                members = {
                    m['id']: m['name']
                    for m in users.get('members', [{}])
                    if m.get('id')
                    and m.get('name')
                }
                if members:
                    self.user_map.update(members)

                username = self.user_map.get(userid, userid)

        return username

Perform a lookup of users to resolve a userid to a username

Args:
userid (string): Slack userid to lookup.

Returns:
string: Human-friendly name of the user


def classifier_factory(clf):

    required_methods = ['fit', 'score', 'predict']

    for method in required_methods:
        if not hasattr(clf, method):
            raise TypeError('"{}" is not in clf. Did you pass a '
                            'classifier instance?'.format(method))

    optional_methods = ['predict_proba']

    for method in optional_methods:
        if not hasattr(clf, method):
            warnings.warn('{} not in clf. Some plots may '
                          'not be possible to generate.'.format(method))

    additional_methods = {
        'plot_learning_curve': plot_learning_curve,
        'plot_confusion_matrix': plot_confusion_matrix_with_cv,
        'plot_roc_curve': plot_roc_curve_with_cv,
        'plot_ks_statistic': plot_ks_statistic_with_cv,
        'plot_precision_recall_curve': plot_precision_recall_curve_with_cv,
        'plot_feature_importances': plot_feature_importances
    }

    for key, fn in six.iteritems(additional_methods):
        if hasattr(clf, key):
            warnings.warn('"{}" method already in clf. '
                          'Overriding anyway. This may '
                          'result in unintended behavior.'.format(key))
        setattr(clf, key, types.MethodType(fn, clf))
    return clf

Embeds scikit-plot instance methods in an sklearn classifier.

Args:
clf: Scikit-learn classifier instance

Returns:
The same scikit-learn classifier instance passed in **clf**
with embedded scikit-plot instance methods.

Raises:
ValueError: If **clf** does not contain the instance methods
necessary for scikit-plot instance methods.


def exe_cmd(*cmds):

    cmd = ' '.join(cmds)
    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
    (out, err) = proc.communicate()
    if not err:
        return out
    return err

Executes commands in a new shell. Directing stderr to PIPE.

This is fastboot's own exe_cmd because of its peculiar way of writing
non-error info to stderr.

Args:
cmds: A sequence of commands and arguments.

Returns:
The output of the command run.

Raises:
Exception: An error occurred during the command execution.


def clear(self, size=(- 1), *, offset=0, chunk=None) -> None:
    self.mglo.clear(size, offset, chunk)

Clear the content.

Args:
size (int): The size. Value ``-1`` means all.

Keyword Args:
offset (int): The offset.
chunk (bytes): The chunk to use repeatedly.


def make_encoder(base_depth, activation, latent_size, code_size):

  conv = functools.partial(
      tf.keras.layers.Conv2D, padding="SAME", activation=activation)

  encoder_net = tf.keras.Sequential([
      conv(base_depth, 5, 1),
      conv(base_depth, 5, 2),
      conv(2 * base_depth, 5, 1),
      conv(2 * base_depth, 5, 2),
      conv(4 * latent_size, 7, padding="VALID"),
      tf.keras.layers.Flatten(),
      tf.keras.layers.Dense(latent_size * code_size, activation=None),
      tf.keras.layers.Reshape([latent_size, code_size])
  ])

  def encoder(images):

    images = 2 * tf.cast(images, dtype=tf.float32) - 1
    codes = encoder_net(images)
    return codes

  return encoder

Creates the encoder function.

Args:
base_depth: Layer base depth in encoder net.
activation: Activation function in hidden layers.
latent_size: The number of latent variables in the code.
code_size: The dimensionality of each latent variable.

Returns:
encoder: A `callable` mapping a `Tensor` of images to a `Tensor` of shape
`[..., latent_size, code_size]`.


def num_embedding_devices_per_chip(self):
    return self.tpu_hardware_feature_proto.num_embedding_devices_per_chip

Number of embedding accelerator devices per chip.

Returns:
Number of embedding devices per chip.


def __init__(self, projection=None, orientation0=(0, 0, -1), **kwargs):

        kwargs['orientation0'] = orientation0
        super(Camera, self).__init__(**kwargs)
        self.projection = PerspectiveProjection() if not projection else projection
        self.reset_uniforms()

Returns a camera object

Args:
projection (obj): the projection type for the camera. It can either be an instance of OrthoProjection or PerspeectiveProjection
orientation0 (tuple):

Returns:
Camera instance


def set_sflow(self, name, value=None, default=False, disable=False):

        if value not in [True, False, None]:
            raise ValueError

        commands = ['interface %s' % name]
        commands.append(self.command_builder('sflow enable', value=value,
                                             default=default, disable=disable))
        return self.configure(commands)

Configures the sFlow state on the interface

Args:
name (string): The interface identifier.  It must be a full
interface name (ie Ethernet, not Et)

value (boolean): True if sFlow should be enabled otherwise False

default (boolean): Specifies the default value for sFlow

disable (boolean): Specifies to disable sFlow

Returns:
True if the operation succeeds otherwise False is returned


def _ParseOriginalFilename(self, file_object, format_version):
    file_offset = file_object.tell()
    if (format_version == 1):
        data_type_map = self._GetDataTypeMap('recycle_bin_metadata_utf16le_string')
    else:
        data_type_map = self._GetDataTypeMap('recycle_bin_metadata_utf16le_string_with_size')
    try:
        (original_filename, _) = self._ReadStructureFromFileObject(file_object, file_offset, data_type_map)
    except (ValueError, errors.ParseError) as exception:
        raise errors.ParseError('Unable to parse original filename with error: {0!s}'.format(exception))
    if (format_version == 1):
        return original_filename.rstrip('\x00')
    return original_filename.string.rstrip('\x00')

Parses the original filename.

Args:
file_object (FileIO): file-like object.
format_version (int): format version.

Returns:
str: filename or None on error.

Raises:
ParseError: if the original filename cannot be read.


def _assert_weights_created(self):
    if self.dynamic:
        return
    if 'build' in self.__class__.__dict__ and self.__class__ != Model and (not self.built):
        raise ValueError('Weights for model %s have not yet been created. Weights are created when the Model is first called on inputs or `build()` is called with an `input_shape`.' % self.name)

Asserts that all the weights for the model have been created.

For a non-dynamic model, the weights must already be created after the
layer has been called. For a dynamic model, the exact list of weights can
never be known for certain since it may change at any time during execution.

We run this check right before accessing weights or getting the Numpy value
for the current weights. Otherwise, if the layer has never been called,
the user would just get an empty list, which is misleading.

Raises:
ValueError: if the weights of the network has not yet been created.


def output(self, _filename):

        txt = ''
        for contract in self.slither.contracts_derived:
            txt += '\n{}:\n'.format(contract.name)
            table = PrettyTable(['Name', 'Type'])
            for variable in contract.state_variables:
                if not variable.is_constant:
                    table.add_row([variable.name, str(variable.type)])
            txt += str(table) + '\n'

        self.info(txt)

_filename is not used
Args:
_filename(string)


def find_nearest_color_hexstr(hexdigits, color_table=None, method='euclid'):
    triplet = []
    try:
        if (len(hexdigits) == 3):
            for digit in hexdigits:
                digit = int(digit, 16)
                triplet.append(((digit * 16) + digit))
        elif (len(hexdigits) == 6):
            triplet.extend((int(hexdigits[i:(i + 2)], 16) for i in (0, 2, 4)))
        else:
            raise ValueError(('wrong length: %r' % hexdigits))
    except ValueError:
        return None
    return find_nearest_color_index(*triplet, color_table=color_table, method=method)

Given a three or six-character hex digit string, return the nearest
color index.

Arguments:
hexdigits:  a three/6 digit hex string, e.g. 'b0b', '123456'

Returns:
int, None: index, or None on error.


def is_github_task(task):

    return any((

        task.get('schedulerId') == 'taskcluster-github',

        task.get('extra', {}).get('tasks_for', '').startswith('github-'),
        is_github_url(task.get('metadata', {}).get('source', '')),
    ))

Determine if a task is related to GitHub.

This function currently looks into the ``schedulerId``, ``extra.tasks_for``, and
``metadata.source``.

Args:
task (dict): the task definition to check.

Returns:
bool: True if a piece of data refers to GitHub


def inputs(self) -> Mapping[str, Mapping[int, str]]:
    raise NotImplementedError()

Mapping containing the axis definition of the input tensors to provide to the model

Returns:
For each input: its name associated to the axes symbolic name and the axis position within the tensor


def set_pattern_additional_cycles(self, patternnumber, value):

        _checkPatternNumber(patternnumber)
        minimalmodbus._checkInt(value, minvalue=0, maxvalue=99, description='number of additional cycles')

        address = _calculateRegisterAddress('cycles', patternnumber)
        self.write_register(address, value, 0)

Set the number of additional cycles for a given pattern.

Args:
* patternnumber (integer): 0-7
* value (integer): 0-99


def generate_files(generator, output_filenames, max_cases=None, cycle_every_n=1):
    if outputs_exist(output_filenames):
        tf.logging.info('Skipping generator because outputs files exists at {}'.format(output_filenames))
        return
    tmp_filenames = [(fname + '.incomplete') for fname in output_filenames]
    num_shards = len(output_filenames)
    if (num_shards > 0):
        if ('-train' in output_filenames[0]):
            tag = 'train'
        elif ('-dev' in output_filenames[0]):
            tag = 'eval'
        else:
            tag = 'other'
    writers = [tf.python_io.TFRecordWriter(fname) for fname in tmp_filenames]
    (counter, shard) = (0, 0)
    for case in generator:
        if (case is None):
            continue
        if ((counter % 100000) == 0):
            tf.logging.info(('Generating case %d.' % counter))
        counter += 1
        if (max_cases and (counter > max_cases)):
            break
        example = to_example(case)
        writers[shard].write(example.SerializeToString())
        if ((counter % cycle_every_n) == 0):
            shard = ((shard + 1) % num_shards)
    for writer in writers:
        writer.close()
    for (tmp_name, final_name) in zip(tmp_filenames, output_filenames):
        tf.gfile.Rename(tmp_name, final_name)
    if (num_shards > 0):
        if (tag == 'train'):
            mlperf_log.transformer_print(key=mlperf_log.PREPROC_NUM_TRAIN_EXAMPLES, value=counter)
        elif (tag == 'eval'):
            mlperf_log.transformer_print(key=mlperf_log.PREPROC_NUM_EVAL_EXAMPLES, value=counter)
    tf.logging.info('Generated %s Examples', counter)

Generate cases from a generator and save as TFRecord files.

Generated cases are transformed to tf.Example protos and saved as TFRecords
in sharded files named output_dir/output_name-00..N-of-00..M=num_shards.

Args:
generator: a generator yielding (string -> int/float/str list) dictionaries.
output_filenames: List of output file paths.
max_cases: maximum number of cases to get from the generator;
if None (default), we use the generator until StopIteration is raised.
cycle_every_n: how many cases from the generator to take before
switching to the next shard; by default set to 1, switch every case.


def calc_checksum(sentence):
    if sentence.startswith('$'):
        sentence = sentence[1:]
    sentence = sentence.split('*')[0]
    return reduce(xor, map(ord, sentence))

Calculate a NMEA 0183 checksum for the given sentence.

NMEA checksums are a simple XOR of all the characters in the sentence
between the leading "$" symbol, and the "*" checksum separator.

Args:
sentence (str): NMEA 0183 formatted sentence


def create_gpu_capa_map(match_list, generate_csv=False, filename='compute_capability'):
    gpu_capa = collections.OrderedDict()
    include = False
    gpu = ''
    cnt = 0
    mismatch_cnt = 0
    for match in match_list:
        if 'Products' in match:
            if not include:
                include = True
            continue
        elif 'www' in match:
            include = False
            break
        if include:
            if gpu:
                if gpu in gpu_capa:
                    gpu_capa[gpu].append(match)
                else:
                    gpu_capa[gpu] = [match]
                gpu = ''
                cnt += 1
                if len(list(gpu_capa.keys())) < cnt:
                    mismatch_cnt += 1
                    cnt = len(list(gpu_capa.keys()))
            else:
                gpu = match
    if generate_csv:
        f_name = filename + '.csv'
        write_csv_from_dict(f_name, gpu_capa)
    return gpu_capa

Generates a map between GPU types and corresponding compute capability.

This method is used for retrieving CUDA compute capability from the web only.

Args:
match_list: List of all CUDA compute capability detected from the webpage.
generate_csv: Boolean for creating csv file to store results.
filename: String that is the name of the csv file (without `.csv` ending).

Returns:
OrderedDict that lists in the incoming order of all CUDA compute capability
provided as `match_list`.


def pop(self):
    return self._queue.popleft()

Removes and returns the oldest value from the data window (FIFO).

Returns:
The oldest value from the window.


def get_qa_logit_layer(self) -> nn.Module:
    if hasattr(self, 'answer_head'):
        return self.answer_head.logit_fc[-1]

Returns the linear layer that produces question answering logits.

Returns:
`nn.Module`: A torch module mapping the question answering prediction hidden states or `None` if LXMERT
does not have a visual answering head.


def bulk_load_docs(es, docs):

    chunk_size = 200

    try:
        results = elasticsearch.helpers.bulk(es, docs, chunk_size=chunk_size)
        log.debug(f"Elasticsearch documents loaded: {results[0]}")

        if len(results[1]) > 0:
            log.error("Bulk load errors {}".format(results))
    except elasticsearch.ElasticsearchException as e:
        log.error("Indexing error: {}\n".format(e))

Bulk load docs

Args:
es: elasticsearch handle
docs: Iterator of doc objects - includes index_name


def get_parameter_bounds(self, include_frozen=False):
    if include_frozen:
        return self.parameter_bounds
    return list((p for (p, f) in zip(self.parameter_bounds, self.unfrozen_mask) if f))

Get a list of the parameter bounds

Args:
include_frozen (Optional[bool]): Should the frozen parameters be
included in the returned value? (default: ``False``)


def wait_for_plug_update(self, plug_name, remote_state, timeout_s):
    plug = self._plugs_by_name.get(plug_name)
    if (plug is None):
        raise InvalidPlugError(('Cannot wait on unknown plug "%s".' % plug_name))
    if (not isinstance(plug, FrontendAwareBasePlug)):
        raise InvalidPlugError(('Cannot wait on a plug %s that is not an subclass of FrontendAwareBasePlug.' % plug_name))
    (state, update_event) = plug.asdict_with_event()
    if (state != remote_state):
        return state
    if update_event.wait(timeout_s):
        return plug._asdict()

Wait for a change in the state of a frontend-aware plug.

Args:
plug_name: Plug name, e.g. 'openhtf.plugs.user_input.UserInput'.
remote_state: The last observed state.
timeout_s: Number of seconds to wait for an update.

Returns:
An updated state, or None if the timeout runs out.

Raises:
InvalidPlugError: The plug can't be waited on either because it's not in
use or it's not a frontend-aware plug.


def generate_index(fn, cols=None, names=None, sep=" "):

    assert cols is not None, "'cols' was not set"
    assert names is not None, "'names' was not set"
    assert len(cols) == len(names)

    bgzip, open_func = get_open_func(fn, return_fmt=True)

    data = pd.read_csv(fn, sep=sep, engine="c", usecols=cols, names=names,
                       compression="gzip" if bgzip else None)

    f = open_func(fn, "rb")
    data["seek"] = np.fromiter(_seek_generator(f), dtype=np.uint)[:-1]
    f.close()

    write_index(get_index_fn(fn), data)

    return data

Build a index for the given file.

Args:
fn (str): the name of the file.
cols (list): a list containing column to keep (as int).
names (list): the name corresponding to the column to keep (as str).
sep (str): the field separator.

Returns:
pandas.DataFrame: the index.


def get_axis_value_discrete(self, axis):
    if (self.type != EventType.POINTER_AXIS):
        raise AttributeError(_wrong_meth.format(self.type))
    return self._libinput.libinput_event_pointer_get_axis_value_discrete(self._handle, axis)

Return the axis value in discrete steps for a given axis event.

How a value translates into a discrete step depends on the source.
If the source is :attr:`~libinput.constant.PointerAxisSource.WHEEL`,
the discrete value correspond to the number of physical mouse wheel
clicks.

If the source is :attr:`~libinput.constant.PointerAxisSource.CONTINUOUS`
or :attr:`~libinput.constant.PointerAxisSource.FINGER`, the discrete
value is always 0.

Args:
axis (~libinput.constant.PointerAxis): The axis who's value to get.
Returns:
float: The discrete value for the given event.
Raises:
AttributeError


def _DeserializeResponse(self, payload):

        status_line, payload = payload.split('\n', 1)
        _, status, _ = status_line.split(' ', 2)

        parser = email_parser.Parser()
        msg = parser.parsestr(payload)

        info = dict(msg)
        info['status'] = status

        content = msg.get_payload()

        return http_wrapper.Response(info, content, self.__batch_url)

Convert string into Response and content.

Args:
payload: Header and body string to be deserialized.

Returns:
A Response object


def ReadLine(self, file_object):
    (line, _, self.lines) = self.lines.partition('\n')
    if (not line):
        self.ReadLines(file_object)
        (line, _, self.lines) = self.lines.partition('\n')
    return line

Reads a line.

Args:
file_object (dfvfs.FileIO): file-like object.

Returns:
str: line read from the lines buffer.


def is_scheduled(configuration, task={}):
    days = configuration.recipe.get('setup', {}).get('day', [])
    hours = [int(h) for h in task.get('hour', configuration.recipe.get('setup', {}).get('hour', []))]
    if days == [] or configuration.date.strftime('%a') in days:
        if hours == [] or configuration.hour in hours:
            return True
    return False

Wrapper for day_hour_scheduled that returns True if current time zone safe hour is in recipe schedule.

Used as a helper for any cron job running projects.  Keeping this logic in
project
helps avoid time zone detection issues and scheduling discrepencies between
machines.

Args:
* recipe: (Recipe JSON) The JSON of a recipe.
* task: ( dictionary / JSON ) The specific task being considered for execution.

Returns:
- True if task is scheduled to run current hour, else False.


def make_test_function(self):
    if self.test_function is not None:
        return self.test_function

    def step_function(model, iterator):

        def run_step(data):
            outputs = model.test_step(data)
            with ops.control_dependencies(_minimum_control_deps(outputs)):
                model._test_counter.assign_add(1)
            return outputs
        data = next(iterator)
        outputs = model.distribute_strategy.run(run_step, args=(data,))
        outputs = reduce_per_replica(outputs, self.distribute_strategy, reduction='first')
        return outputs
    if self._steps_per_execution.numpy().item() == 1:

        def test_function(iterator):

            return step_function(self, iterator)
    else:

        def test_function(iterator):

            for _ in math_ops.range(self._steps_per_execution):
                outputs = step_function(self, iterator)
            return outputs
    if not self.run_eagerly:
        test_function = def_function.function(test_function, experimental_relax_shapes=True)
    self.test_function = test_function
    if self._cluster_coordinator:
        self.test_function = lambda iterator: self._cluster_coordinator.schedule(test_function, args=(iterator,))
    return self.test_function

Creates a function that executes one step of evaluation.

This method can be overridden to support custom evaluation logic.
This method is called by `Model.evaluate` and `Model.test_on_batch`.

Typically, this method directly controls `tf.function` and
`tf.distribute.Strategy` settings, and delegates the actual evaluation
logic to `Model.test_step`.

This function is cached the first time `Model.evaluate` or
`Model.test_on_batch` is called. The cache is cleared whenever
`Model.compile` is called.

Returns:
Function. The function created by this method should accept a
`tf.data.Iterator`, and return a `dict` containing values that will
be passed to `tf.keras.Callbacks.on_test_batch_end`.


def __init__(self, key, items):

        self._key = key
        sequence = list(items)
        super(Grouping, self).__init__(sequence)

Create a Grouping with a given key and a collection of members.

Args:
key: The key corresponding to this Grouping

items: An iterable collection of the members of the group.


def to_dms(angle, style='dms'):
    sign = (1 if (angle >= 0) else (- 1))
    angle = (abs(angle) * 3600)
    (minutes, seconds) = divmod(angle, 60)
    (degrees, minutes) = divmod(minutes, 60)
    if (style == 'dms'):
        return tuple(((sign * abs(i)) for i in (int(degrees), int(minutes), seconds)))
    elif (style == 'dm'):
        return tuple(((sign * abs(i)) for i in (int(degrees), (minutes + (seconds / 60)))))
    else:
        raise ValueError(('Unknown style type %r' % style))

Convert decimal angle to degrees, minutes and possibly seconds.

Args:
angle (float): Angle to convert
style (str): Return fractional or whole minutes values

Returns:
tuple of int: Angle converted to degrees, minutes and possibly seconds

Raises:
ValueError: Unknown value for ``style``


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 process_result_value(self, value, dialect):
    masks = list()
    if value:
        for e in enums.CryptographicUsageMask:
            if (e.value & value):
                masks.append(e)
    return masks

Returns a new list of enums.CryptographicUsageMask Enums. This converts
the integer value into the list of enums.

Args:
value(int): The integer value stored in the database that is used
to create the list of enums.CryptographicUsageMask Enums.
dialect(string): SQL dialect


def _set_mode(self, discover_mode, connect_mode):
    payload = struct.pack('<BB', discover_mode, connect_mode)
    response = self._send_command(6, 1, payload)
    (result,) = unpack('<H', response.payload)
    if (result != 0):
        return (False, {'reason': 'Error code from BLED112 setting mode', 'code': result})
    return (True, None)

Set the mode of the BLED112, used to enable and disable advertising

To enable advertising, use 4, 2.
To disable advertising use 0, 0.

Args:
discover_mode (int): The discoverability mode, 0 for off, 4 for on (user data)
connect_mode (int): The connectability mode, 0 for of, 2 for undirected connectable


def EnqueueBreakpointUpdate(self, breakpoint):

    with self._transmission_thread_startup_lock:
      if self._transmission_thread is None:
        self._transmission_thread = threading.Thread(
            target=self._TransmissionThreadProc)
        self._transmission_thread.name = 'Cloud Debugger transmission thread'
        self._transmission_thread.daemon = True
        self._transmission_thread.start()

    self._transmission_queue.append((breakpoint, 0))
    self._new_updates.set()

Asynchronously updates the specified breakpoint on the backend.

This function returns immediately. The worker thread is actually doing
all the work. The worker thread is responsible to retry the transmission
in case of transient errors.

Args:
breakpoint: breakpoint in either final or non-final state.


def create_primes(threshold):
    if (threshold == 2):
        return [2]
    elif (threshold < 2):
        return []
    numbers = list(range(3, (threshold + 1), 2))
    root_of_threshold = (threshold ** 0.5)
    half = int((((threshold + 1) / 2) - 1))
    idx = 0
    counter = 3
    while (counter <= root_of_threshold):
        if numbers[idx]:
            idy = int((((counter * counter) - 3) / 2))
            numbers[idy] = 0
            while (idy < half):
                numbers[idy] = 0
                idy += counter
        idx += 1
        counter = ((2 * idx) + 3)
    return ([2] + [number for number in numbers if number])

Generate prime values using sieve of Eratosthenes method.

Args:
threshold (int):
The upper bound for the size of the prime values.

Returns (List[int]):
All primes from 2 and up to ``threshold``.


def convert_item_to_command_line_arg(self, action, key, value):
    args = []
    if (action is None):
        command_line_key = self.get_command_line_key_for_unknown_config_file_setting(key)
    else:
        command_line_key = action.option_strings[(- 1)]
    if ((action is not None) and isinstance(action, ACTION_TYPES_THAT_DONT_NEED_A_VALUE)):
        if (value.lower() in ('true', 'yes', '1')):
            args.append(command_line_key)
        elif (value.lower() in ('false', 'no', '0')):
            pass
        else:
            self.error(("Unexpected value for %s: '%s'. Expecting 'true', 'false', 'yes', 'no', '1' or '0'" % (key, value)))
    elif isinstance(value, list):
        if ((action is None) or isinstance(action, argparse._AppendAction)):
            for list_elem in value:
                args.append(command_line_key)
                args.append(str(list_elem))
        elif ((isinstance(action, argparse._StoreAction) and (action.nargs in ('+', '*'))) or (isinstance(action.nargs, int) and (action.nargs > 1))):
            args.append(command_line_key)
            for list_elem in value:
                args.append(str(list_elem))
        else:
            self.error(("%s can't be set to a list '%s' unless its action type is changed to 'append' or nargs is set to '*', '+', or > 1" % (key, value)))
    elif isinstance(value, str):
        args.append(command_line_key)
        args.append(value)
    else:
        raise ValueError(('Unexpected value type %s for value: %s' % (type(value), value)))
    return args

Converts a config file or env var key + value to a list of
commandline args to append to the commandline.

Args:
action: The argparse Action object for this setting, or None if this
config file setting doesn't correspond to any defined
configargparse arg.
key: string (config file key or env var name)
value: parsed value of type string or list


def build_ring_all_reduce(input_tensors, num_workers, num_subchunks, gpu_perm, red_op, un_op=None):
    if len(input_tensors) < 2:
        raise ValueError('input_tensors must be length 2 or longer')
    input_tensors, shape = _flatten_tensors(input_tensors)
    devices = [t.device for t in input_tensors]
    pred_by_s_d, rank_by_s_d = _ring_permutations(num_workers, num_subchunks, gpu_perm)
    chunks_by_dev, pad_len = _build_ring_gather(input_tensors, devices, num_subchunks, pred_by_s_d, rank_by_s_d, red_op)
    if un_op:
        chunks_by_dev = _apply_unary_to_chunks(un_op, chunks_by_dev)
    output_tensors = _build_ring_scatter(pred_by_s_d, rank_by_s_d, chunks_by_dev)
    if pad_len > 0:
        output_tensors = _strip_padding(output_tensors, pad_len)
    if len(shape) != 1:
        output_tensors = _reshape_tensors(output_tensors, shape)
    return output_tensors

Construct a subgraph performing a ring-style all-reduce of input_tensors.

Args:
input_tensors: a list of `tf.Tensor` objects, which must all
have the same shape and type.
num_workers: number of worker tasks spanned by input_tensors.
num_subchunks: number of subchunks each device should process in one tick.
gpu_perm: a list of ints giving a ring-wise rank ordering of GPUs at
each worker.  All workers must have the same number of
GPUs with the same rank ordering.  If NVLINK is available, this should
be a ring order supported by NVLINK edges.
red_op: a binary operator for elementwise reduction.
un_op: an optional unary operator to apply to fully reduced values.

Raises:
ValueError: empty input_tensors or they don't all have same
size.

Returns:
a list of `tf.Tensor` identical sum-reductions of input_tensors.


def close(self, file_des):
    file_handle = self.filesystem.get_open_file(file_des)
    file_handle.close()

Close a file descriptor.

Args:
file_des: An integer file descriptor for the file object requested.

Raises:
OSError: bad file descriptor.
TypeError: if file descriptor is not an integer.


def delete_case(self, case_id=None, institute_id=None, display_name=None):
    query = {}
    if case_id:
        query['_id'] = case_id
        LOG.info('Deleting case %s', case_id)
    else:
        if (not (institute_id and display_name)):
            raise ValueError('Have to provide both institute_id and display_name')
        LOG.info('Deleting case %s institute %s', display_name, institute_id)
        query['owner'] = institute_id
        query['display_name'] = display_name
    result = self.case_collection.delete_one(query)
    return result

Delete a single case from database

Args:
institute_id(str)
case_id(str)

Returns:
case_obj(dict): The case that was deleted


def WriteEventMACBGroup(self, event_macb_group):

    output_values = self._GetOutputValues(event_macb_group[0])

    timestamp_descriptions = [
        event.timestamp_desc for event in event_macb_group]
    output_values[3] = (
        self._output_mediator.GetMACBRepresentationFromDescriptions(
            timestamp_descriptions))

    output_values[6] = '; '.join(timestamp_descriptions)

    self._WriteOutputValues(output_values)

Writes an event MACB group to the output.

Args:
event_macb_group (list[EventObject]): event MACB group.


def set_napp(self, user, napp, version=None):
    self.user = user
    self.napp = napp
    self.version = (version or 'latest')

Set info about NApp.

Args:
user (str): NApps Server username.
napp (str): NApp name.
version (str): NApp version.


def __init__(self, filenames, record_bytes, header_bytes=None, footer_bytes=None, buffer_size=None, compression_type=None, name=None):
    self._filenames = filenames
    self._record_bytes = ops.convert_to_tensor(record_bytes, dtype=dtypes.int64, name='record_bytes')
    self._header_bytes = convert.optional_param_to_tensor('header_bytes', header_bytes)
    self._footer_bytes = convert.optional_param_to_tensor('footer_bytes', footer_bytes)
    self._buffer_size = convert.optional_param_to_tensor('buffer_size', buffer_size, _DEFAULT_READER_BUFFER_SIZE_BYTES)
    self._compression_type = convert.optional_param_to_tensor('compression_type', compression_type, argument_default='', argument_dtype=dtypes.string)
    self._name = name
    variant_tensor = gen_dataset_ops.fixed_length_record_dataset_v2(self._filenames, self._header_bytes, self._record_bytes, self._footer_bytes, self._buffer_size, self._compression_type, metadata=self._metadata.SerializeToString())
    super(_FixedLengthRecordDataset, self).__init__(variant_tensor)

Creates a `FixedLengthRecordDataset`.

Args:
filenames: A `tf.string` tensor containing one or more filenames.
record_bytes: A `tf.int64` scalar representing the number of bytes in each
record.
header_bytes: (Optional.) A `tf.int64` scalar representing the number of
bytes to skip at the start of a file.
footer_bytes: (Optional.) A `tf.int64` scalar representing the number of
bytes to ignore at the end of a file.
buffer_size: (Optional.) A `tf.int64` scalar representing the number of
bytes to buffer when reading.
compression_type: (Optional.) A `tf.string` scalar evaluating to one of
`""` (no compression), `"ZLIB"`, or `"GZIP"`.
name: (Optional.) A name for the tf.data operation.


def _assert_at_most_n_true(predicates, n, msg):
    preds_c = array_ops_stack.stack(predicates, name='preds_c')
    num_true_conditions = math_ops.reduce_sum(math_ops.cast(preds_c, dtypes.int32), name='num_true_conds')
    condition = math_ops.less_equal(num_true_conditions, constant_op.constant(n, name='n_true_conds'))
    preds_names = ', '.join((getattr(p, 'name', '?') for p in predicates))
    error_msg = ['%s: more than %d conditions (%s) evaluated as True:' % (msg, n, preds_names), preds_c]
    return control_flow_assert.Assert(condition, data=error_msg, summarize=len(predicates))

Returns an Assert op that checks that at most n predicates are True.

Args:
predicates: list of bool scalar tensors.
n: maximum number of true predicates allowed.
msg: Error message.


def GetEntries(self, parser_mediator, match=None, **unused_kwargs):

    version = match.get('LastAttemptSystemVersion', 'N/A')
    pending = match.get('LastUpdatesAvailable', None)

    event_data = plist_event.PlistTimeEventData()
    event_data.desc = 'Last MacOS {0:s} full update.'.format(version)
    event_data.key = ''
    event_data.root = '/'

    datetime_value = match.get('LastFullSuccessfulDate', None)
    if datetime_value:
      event = time_events.PythonDatetimeEvent(
          datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
      parser_mediator.ProduceEventWithEventData(event, event_data)

    datetime_value = match.get('LastSuccessfulDate', None)
    if datetime_value and pending:
      software = []
      for update in match.get('RecommendedUpdates', []):
        identifier = update.get('Identifier', '<IDENTIFIER>')
        product_key = update.get('Product Key', '<PRODUCT_KEY>')

        software.append('{0:s}({1:s})'.format(identifier, product_key))

      if not software:
        return

      software = ','.join(software)
      event_data.desc = (
          'Last Mac OS {0!s} partially update, pending {1!s}: '
          '{2:s}.').format(version, pending, software)

      event = time_events.PythonDatetimeEvent(
          datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
      parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts relevant MacOS update entries.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS.


def __init__(self, data_file, vocab_data_file):

    def reading_function(file_name):
      for root in self.ROOTS:
        file_path = os.path.join(root, file_name)
        if os.path.exists(file_path):
          break
        file_path = None
      assert file_path is not None, ("Couldn't locate %s in %r" %
                                     (file_name, self.ROOTS))
      with open(file_path, mode="rb") as fp:
        return list(fp.read().decode().replace("\n", self.CHAR_EOS))

    self._vocab_dict = {}
    self._inv_vocab_dict = {}

    token_list = reading_function(vocab_data_file)
    self.vocab_size = 0
    for token in self.DEFAULT_START_TOKENS + token_list:
      if token not in self._vocab_dict:
        self._vocab_dict[token] = self.vocab_size
        self._inv_vocab_dict[self.vocab_size] = token
        self.vocab_size += 1

    raw_data = reading_function(data_file)
    self.flat_data = np.array(self.tokenize(raw_data), dtype=np.int32)
    self.num_tokens = self.flat_data.shape[0]

Creates a TokenDataSource instance.

Args:
data_file: file object containing text data to be tokenized.
vocab_data_file: file object containing text data used to initialize
the vocabulary.


def add_edge_bias(x, filter_size):
    x_shape = common_layers.shape_list(x)
    if ((filter_size[0] == 1) and (filter_size[1] == 1)):
        return x
    a = ((filter_size[0] - 1)
    b = ((filter_size[1] - 1)
    padding = [[0, 0], [a, a], [b, b], [0, 0]]
    x_bias = tf.zeros((x_shape[:(- 1)] + [1]))
    x = tf.pad(x, padding)
    x_pad = tf.pad(x_bias, padding, constant_values=1)
    return tf.concat([x, x_pad], axis=3)

Pad x and concatenates an edge bias across the depth of x.

The edge bias can be thought of as a binary feature which is unity when
the filter is being convolved over an edge and zero otherwise.

Args:
x: Input tensor, shape (NHWC)
filter_size: filter_size to determine padding.
Returns:
x_pad: Input tensor, shape (NHW(c+1))


def Add(self, other):

    if len(self.data) != len(other.data):
      raise RuntimeError("Can only add series of identical lengths.")
    for i in range(len(self.data)):
      if self.data[i][1] != other.data[i][1]:
        raise RuntimeError("Timestamp mismatch.")
      if self.data[i][0] is None and other.data[i][0] is None:
        continue
      self.data[i][0] = (self.data[i][0] or 0) + (other.data[i][0] or 0)

Add other to self pointwise.

Requires that both self and other are of the same length, and contain
identical timestamps. Typically this means that Normalize has been called
on both with identical time parameters.

Args:
other: The sequence to add to self.

Raises:
RuntimeError: other does not contain the same timestamps as self.


def MakeCdfFromPmf(pmf, name=None):
    if (name == None):
        name = pmf.name
    return MakeCdfFromItems(pmf.Items(), name)

Makes a CDF from a Pmf object.

Args:
pmf: Pmf.Pmf object
name: string name for the data.

Returns:
Cdf object


def save(self, items):
    rows = []
    indx = self.indx
    size = 0
    tick = s_common.now()
    for item in items:
        byts = s_msgpack.en(item)
        size += len(byts)
        lkey = s_common.int64en(indx)
        indx += 1
        rows.append((lkey, byts))
    self.slab.putmulti(rows, append=True, db=self.db)
    took = (s_common.now() - tick)
    origindx = self.indx
    self.indx = indx
    return {'indx': indx, 'size': size, 'count': len(items), 'time': tick, 'took': took}
    return origindx

Save a series of items to a sequence.

Args:
items (tuple): The series of items to save into the sequence.

Returns:
The index of the first item


def emit(self, record):
    if (record.levelno < logging.getLevelName(self.min_level)):
        return
    evt = LogEvent()
    evt.level = record.levelname
    evt.levelno = record.levelno
    evt.timestamp = datetime.fromtimestamp(record.created)
    evt.message = record.message
    evt.filename = record.filename
    evt.lineno = record.lineno
    evt.module = record.module
    evt.funcname = record.funcName
    evt.pathname = record.pathname
    evt.process_id = record.process
    if (record.levelno >= 40):
        evt.stacktrace = traceback.format_exc()
    try:
        db.session.add(evt)
        db.session.commit()
    except Exception:
        db.session.rollback()

Persist a record into the database

Args:
record (`logging.Record`): The logging.Record object to store

Returns:
`None`


def get_structure_from_prev_run(vasprun, outcar=None, sym_prec=0.1, international_monoclinic=True):
    structure = vasprun.final_structure
    site_properties = {}
    if vasprun.is_spin:
        if (outcar and outcar.magnetization):
            site_properties.update({'magmom': [i['tot'] for i in outcar.magnetization]})
        else:
            site_properties.update({'magmom': vasprun.parameters['MAGMOM']})
    if vasprun.parameters.get('LDAU', False):
        for k in ('LDAUU', 'LDAUJ', 'LDAUL'):
            vals = vasprun.incar[k]
            m = {}
            l = []
            s = 0
            for site in structure:
                if (site.specie.symbol not in m):
                    m[site.specie.symbol] = vals[s]
                    s += 1
                l.append(m[site.specie.symbol])
            if (len(l) == len(structure)):
                site_properties.update({k.lower(): l})
            else:
                raise ValueError('length of list {} not the same asstructure'.format(l))
    structure = structure.copy(site_properties=site_properties)
    if sym_prec:
        sym_finder = SpacegroupAnalyzer(structure, symprec=sym_prec)
        new_structure = sym_finder.get_primitive_standard_structure(international_monoclinic=international_monoclinic)
        vpa_old = (structure.volume / structure.num_sites)
        vpa_new = (new_structure.volume / new_structure.num_sites)
        if ((abs((vpa_old - vpa_new)) / vpa_old) > 0.02):
            raise ValueError('Standardizing cell failed! VPA old: {}, VPA new: {}'.format(vpa_old, vpa_new))
        sm = StructureMatcher()
        if (not sm.fit(structure, new_structure)):
            raise ValueError("Standardizing cell failed! Old structure doesn't match new.")
        structure = new_structure
    return structure

Process structure from previous run.

Args:
vasprun (Vasprun): Vasprun that contains the final structure
from previous run.
outcar (Outcar): Outcar that contains the magnetization info from
previous run.
sym_prec (float): Tolerance for symmetry finding for standardization. If
no standardization is desired, set to 0 or a False.
international_monoclinic (bool): Whether to use international
convention (vs Curtarolo) for monoclinic. Defaults True.

Returns:
Returns the magmom-decorated structure that can be passed to get
Vasp input files, e.g. get_kpoints.


def is_in_path(program):
    if (sys.version_info.major == 2):
        path = os.getenv('PATH')
        if (os.name == 'nt'):
            path = path.split(';')
        else:
            path = path.split(':')
    else:
        path = os.get_exec_path()
    for i in path:
        if os.path.isdir(i):
            if (program in os.listdir(i)):
                return True

Check if a program is in the system ``PATH``.

Checks if a given program is in the user's ``PATH`` or not.

Args:
program (str): The program to try to find in ``PATH``.

Returns:
bool: Is the program in ``PATH``?


def _compute_edge_nodes(nodes, degree):
    (dimension, _) = np.shape(nodes)
    nodes1 = np.empty((dimension, (degree + 1)), order='F')
    nodes2 = np.empty((dimension, (degree + 1)), order='F')
    nodes3 = np.empty((dimension, (degree + 1)), order='F')
    curr2 = degree
    curr3 = (- 1)
    for i in six.moves.xrange((degree + 1)):
        nodes1[(:, i)] = nodes[(:, i)]
        nodes2[(:, i)] = nodes[(:, curr2)]
        nodes3[(:, i)] = nodes[(:, curr3)]
        curr2 += (degree - i)
        curr3 -= (i + 2)
    return (nodes1, nodes2, nodes3)

Compute the nodes of each edges of a surface.

.. note::

There is also a Fortran implementation of this function, which
will be used if it can be built.

Args:
nodes (numpy.ndarray): Control point nodes that define the surface.
degree (int): The degree of the surface define by ``nodes``.

Returns:
Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]: The nodes in
the edges of the surface.