def validate_env(app):
    if (not hasattr(app.env, 'javalink_config_cache')):
        app.env.javalink_config_cache = {}
    for (conf_attr, (_, _, env_attr)) in ref.CONFIG_VALUES.iteritems():
        if (not env_attr):
            continue
        value = getattr(app.config, conf_attr)
        cached = app.env.javalink_config_cache.get(conf_attr, value)
        app.env.javalink_config_cache[conf_attr] = value
        if (value != cached):
            app.verbose('[javalink] config.%s has changed, clearing related env', conf_attr)
            delattr(app.env, env_attr)

Purge expired values from the environment.

When certain configuration values change, related values in the
environment must be cleared. While Sphinx can rebuild documents on
configuration changes, it does not notify extensions when this
happens. Instead, cache relevant values in the environment in order
to detect when they change.

Args:
app: The Sphinx application.


def broadcast_impl(self, old_slices, old_shape, new_shape):

    new_slice_shape = self.slice_shape(new_shape)
    def tf_fn(x):
      return (tf.zeros(new_slice_shape, dtype=x.dtype) +
              _expand_dims(x, old_shape, new_shape))
    return self.slicewise(tf_fn, old_slices)

Implementation of a broadcast operation.

Args:
old_slices: LaidOutTensor.
old_shape: Shape.
new_shape: Shape.

Returns:
LaidOutTensor.


def variance(self, name='variance'):
    with self._name_scope(name):
        try:
            return self._variance()
        except NotImplementedError as original_exception:
            try:
                return math_ops.square(self._stddev())
            except NotImplementedError:
                raise original_exception

Variance.

Variance is defined as,

```none
Var = E[(X - E[X])**2]
```

where `X` is the random variable associated with this distribution, `E`
denotes expectation, and `Var.shape = batch_shape + event_shape`.

Args:
name: Python `str` prepended to names of ops created by this function.

Returns:
variance: Floating-point `Tensor` with shape identical to
`batch_shape + event_shape`, i.e., the same shape as `self.mean()`.


def from_json(cls, data):
    required_keys = ('location', 'design_days')
    for key in required_keys:
        assert (key in data), 'Required key "{}" is missing!'.format(key)
    return cls(Location.from_json(data['location']), [DesignDay.from_json(des_day) for des_day in data['design_days']])

Create a DDY from a dictionary.

Args:
data = {
"location": ladybug Location schema,
"design_days": [] // list of ladybug DesignDay schemas}


def submit(self, cmd_string, blocksize, job_name="parsl.auto"):

        if not self.resources:
            job_name = "{0}-{1}".format(job_name, time.time()).split(".")[0]

            self.deployment_name = '{}-{}-deployment'.format(job_name,
                                                             str(time.time()).split('.')[0])

            formatted_cmd = template_string.format(command=cmd_string,
                                                   overrides=self.config["execution"]["block"]["options"].get("overrides", ''))

            print("Creating replicas :", self.init_blocks)
            self.deployment_obj = self._create_deployment_object(job_name,
                                                                 self.image,
                                                                 self.deployment_name,
                                                                 cmd_string=formatted_cmd,
                                                                 replicas=self.init_blocks)
            logger.debug("Deployment name :{}".format(self.deployment_name))
            self._create_deployment(self.deployment_obj)
            self.resources[self.deployment_name] = {'status': 'RUNNING',
                                                    'pods': self.init_blocks}

        return self.deployment_name

Submit a job

Args:
- cmd_string  :(String) - Name of the container to initiate
- blocksize   :(float) - Number of replicas

Kwargs:
- job_name (String): Name for job, must be unique

Returns:
- None: At capacity, cannot provision more
- job_id: (string) Identifier for the job


def _input_index(op, handle):
    for i, t in enumerate(op.inputs):
        if handle is t:
            return i
    raise ValueError(f'{handle!s} not in list of inputs for op: {op!r}')

Returns the index of `handle` in `op.inputs`.

Args:
op: Operation.
handle: Resource handle.

Returns:
Index in `op.inputs` receiving the resource `handle`.

Raises:
ValueError: If handle and its replicated input are both not found in
`op.inputs`.


def estimate_size(self, value):
    return len(self.encode(value))

Estimates the encoded size of the given value, in bytes.

Dataflow estimates the encoded size of a PCollection processed in a pipeline
step by using the estimated size of a random sample of elements in that
PCollection.

The default implementation encodes the given value and returns its byte
size.  If a coder can provide a fast estimate of the encoded size of a value
(e.g., if the encoding has a fixed size), it can provide its estimate here
to improve performance.

Arguments:
value: the value whose encoded size is to be estimated.

Returns:
The estimated encoded size of the given value.


def add_position_timing_signal(x, step, hparams):

  if not hparams.position_start_index:
    index = 0

  elif hparams.position_start_index == "random":

    index = tf.random_uniform(
        [], maxval=common_layers.shape_list(x)[1], dtype=tf.int32)

  elif hparams.position_start_index == "step":

    if hparams.recurrence_type == "act":
      num_steps = hparams.act_max_steps
    else:
      num_steps = hparams.num_rec_steps
    index = tf.cast(
        common_layers.shape_list(x)[1] * step / num_steps, dtype=tf.int32)

  assert hparams.pos is None

  length = common_layers.shape_list(x)[1]
  channels = common_layers.shape_list(x)[2]
  signal = common_attention.get_timing_signal_1d(
      length, channels, start_index=index)

  if hparams.add_or_concat_timing_signal == "add":
    x_with_timing = x + common_layers.cast_like(signal, x)

  elif hparams.add_or_concat_timing_signal == "concat":
    batch_size = common_layers.shape_list(x)[0]
    signal_tiled = tf.tile(signal, [batch_size, 1, 1])
    x_with_timing = tf.concat((x, signal_tiled), axis=-1)

  return x_with_timing

Add n-dimensional embedding as the position (horizontal) timing signal.

Args:
x: a tensor with shape [batch, length, depth]
step: step
hparams: model hyper parameters

Returns:
a Tensor with the same shape as x.


def initialize(self, emt_id, emt_pass):
    self._emt_id = emt_id
    self._emt_pass = emt_pass
    self.bus = BusApi(self)
    self.geo = GeoApi(self)
    self.parking = ParkingApi(self)

Manual initialization of the interface attributes.

This is useful when the interface must be declare but initialized later
on with parsed configuration values.

Args:
emt_id (str): ID given by the server upon registration
emt_pass (str): Token given by the server upon registration


def extract_subject_info_extension(cert_obj):

    try:
        subject_info_der = cert_obj.extensions.get_extension_for_oid(
            cryptography.x509.oid.ObjectIdentifier(DATAONE_SUBJECT_INFO_OID)
        ).value.value
        return str(pyasn1.codec.der.decoder.decode(subject_info_der)[0])
    except Exception as e:
        logging.debug('SubjectInfo not extracted. reason="{}"'.format(e))

Extract DataONE SubjectInfo XML doc from certificate.

Certificates issued by DataONE may include an embedded XML doc containing
additional information about the subject specified in the certificate DN. If
present, the doc is stored as an extension with an OID specified by DataONE and
formatted as specified in the DataONE SubjectInfo schema definition.

Args:
cert_obj: cryptography.Certificate

Returns:
str : SubjectInfo XML doc if present, else None


def create_builder_from_str(self, structdef_name: Union[str, _fhir_path_data_types.StructureDataType], fhir_path_expression: str, fhir_context: Optional[context_lib.FhirPathContext]=None) -> expressions.Builder:
    if isinstance(structdef_name, _fhir_path_data_types.StructureDataType):
        structdef_type = structdef_name
    else:
        if not fhir_context:
            fhir_context = self.context
        structdef = fhir_context.get_structure_definition(structdef_name)
        if not structdef:
            raise ValueError(f'Structdef {structdef_name} was not found in the provided context.')
        structdef_type = _fhir_path_data_types.StructureDataType.from_proto(structdef)
    return expressions.from_fhir_path_expression(fhir_path_expression, fhir_context, structdef_type, primitive_handler.PrimitiveHandler())

Creates an expression Builder from a FHIRPath string.

Args:
structdef_name: Either a structure definition for or the name of the
resource for the fhir_path_expression. If a string, the structure
definition is fetched from the fhir_context.
fhir_path_expression: A FHIR path string to parse.
fhir_context: An optional context to use. If not specified, will use
self.context by default.

Returns:
An equivalent expressions.Builder to the fhir_path_expression.


def _validate_path(path):

  if not path:
    raise ValueError('Path is empty')
  if not isinstance(path, basestring):
    raise TypeError('Path should be a string but is %s (%s).' %
                    (path.__class__, path))

Basic validation of Google Storage paths.

Args:
path: a Google Storage path. It should have form '/bucket/filename'
or '/bucket'.

Raises:
ValueError: if path is invalid.
TypeError: if path is not of type basestring.


def ScanForWindowsVolume(self, source_path):
    windows_path_specs = self.GetBasePathSpecs(source_path)
    if ((not windows_path_specs) or (self._source_type == definitions.SOURCE_TYPE_FILE)):
        return False
    file_system_path_spec = windows_path_specs[0]
    self._file_system = resolver.Resolver.OpenFileSystem(file_system_path_spec)
    if (file_system_path_spec.type_indicator == definitions.TYPE_INDICATOR_OS):
        mount_point = file_system_path_spec
    else:
        mount_point = file_system_path_spec.parent
    self._path_resolver = windows_path_resolver.WindowsPathResolver(self._file_system, mount_point)
    if (not self._windows_directory):
        self._ScanFileSystemForWindowsDirectory(self._path_resolver)
    if (not self._windows_directory):
        return False
    self._path_resolver.SetEnvironmentVariable('SystemRoot', self._windows_directory)
    self._path_resolver.SetEnvironmentVariable('WinDir', self._windows_directory)
    return True

Scans for a Windows volume.

Args:
source_path (str): source path.

Returns:
bool: True if a Windows volume was found.

Raises:
ScannerError: if the source path does not exists, or if the source path
is not a file or directory, or if the format of or within the source
file is not supported.


def is_time_included(self, time):

        if self._timestamps_data is None:
            self._calculate_timestamps()

        return time.moy in self._timestamps_data

Check if time is included in analysis period.

Return True if time is inside this analysis period,
otherwise return False

Args:
time: A DateTime to be tested

Returns:
A boolean. True if time is included in analysis period


def nunique(self, axis=0, dropna=True):

        axis = self._get_axis_number(axis) if axis is not None else 0
        return self._reduce_dimension(
            self._query_compiler.nunique(axis=axis, dropna=dropna)
        )

Return Series with number of distinct
observations over requested axis.

Args:
axis : {0 or 'index', 1 or 'columns'}, default 0
dropna : boolean, default True

Returns:
nunique : Series


def __init__(self, baseplate, token, actor_urn, reconnect=True,
                 *args, **kwargs):

        self.baseplate = baseplate
        self.token = token
        self.last_ping = 0
        self.actor_urn = actor_urn
        self.reconnect = reconnect
        self.auto_reconnect = True

        self.supported_events = {'message': self.on_message}
        self.user_map = {}
        self.slack_client = SlackClient(self.token)
        threading.Thread.__init__(self)

Initializes RtmBot

Args:
baseplate (Legobot.Lego): The parent Pykka actor.
Typically passed in fromLegobot.Connectors.Slack.Slack
token (string): Slack API token
actor_urn (string): URN of Pykka actor launching RtmBot
*args: Variable length argument list.
**kwargs: Arbitrary keyword arguments.

Returns:
Returns an instance of RtmBot which connects to Slack.


def tan(self: EventSetOrNode) -> EventSetOrNode:
    from temporian.core.operators.unary import tan
    return tan(self)

Calculates the tangent of an [`EventSet`][temporian.EventSet]'s features.

Can only be used on floating point features.

Example:
```python
>>> a = tp.event_set(
...     timestamps=[1, 2, 3, 4],
...     features={"M": [0, np.pi/4, np.pi/3, np.pi/6]},
... )
>>> a.tan()
indexes: ...
timestamps: [1. 2. 3. 4.]
'M': [0.     1.     1.7321 0.5774]
...

```

Returns:
EventSetOrNode with tangent of input features.


def cross_join(left: dict[str, Any], right: dict[str, Any]) -> beam.Row:
    for k, v in right.items():
        if k not in left:
            left[k] = v
        elif left[k] != v:
            _LOGGER.warning('%s exists in the input row as well the row fetched from API but have different values - %s and %s. Using the input value (%s) for the enriched row. You can override this behavior by passing a custom `join_fn` to Enrichment transform.' % (k, left[k], v, left[k]))
    return beam.Row(**left)

performs a cross join on two `dict` objects.

Joins the columns of the right row onto the left row.

Args:
left (dict[str, Any]): input request dictionary.
right (dict[str, Any]): response dictionary from the API.

Returns:
`beam.Row` containing the merged columns.


def minimum_image_dr( self, r1, r2, cutoff=None ):

        delta_r_vector = self.minimum_image( r1, r2 )
        return( self.dr( np.zeros( 3 ), delta_r_vector, cutoff ) )

Calculate the shortest distance between two points in the cell,
accounting for periodic boundary conditions.

Args:
r1 (np.array): fractional coordinates of point r1.
r2 (np.array): fractional coordinates of point r2.
cutoff (:obj: `float`, optional): if set, return zero if the minimum distance is greater than `cutoff`. Defaults to None.

Returns:
(float): The distance between r1 and r2.


def forward(self, latents: torch.Tensor, context: torch.Tensor, attention_mask: Optional[torch.Tensor]=None, position_ids: Optional[torch.LongTensor]=None, past_key_value: Optional[Tuple[torch.Tensor]]=None, output_attentions: bool=False, use_cache: bool=False) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
    bsz, q_len, _ = latents.size()
    kv_seq_len = q_len + context.size()[1]
    hidden_states = torch.concat([context, latents], dim=-2)
    queries = self.q_proj(latents)
    keys = self.k_proj(hidden_states)
    values = self.v_proj(hidden_states)
    queries = queries.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
    keys = keys.view(bsz, kv_seq_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
    values = values.view(bsz, kv_seq_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
    past_key_value = getattr(self, 'past_key_value', past_key_value)
    if past_key_value is not None:
        keys, values = past_key_value.update(keys, values, self.layer_idx)
    attention_interface: Callable = eager_attention_forward
    if self.config._attn_implementation != 'eager':
        if self.config._attn_implementation == 'sdpa' and output_attentions:
            logger.warning_once('`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to eager attention. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.')
        else:
            attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
    attn_output, attn_weights = attention_interface(self, queries, keys, values, attention_mask, is_causal=self.is_causal, scaling=self.scaling, dropout=0.0 if not self.training else self.attention_dropout)
    attn_output = attn_output.reshape(bsz, q_len, self.num_heads * self.head_dim)
    attn_output = self.o_proj(attn_output)
    if not output_attentions:
        attn_weights = None
    return (attn_output, attn_weights, past_key_value)

Runs Perceiver Self-Attention, with special (context, latents) appended along the `seq` dimension!

Args:
latents (`torch.Tensor`): Tensor of shape [bsz, n_latents, embed_dim] representing fixed length latents to compress to.
context (`torch.Tensor`): Tensor of shape [bsz, seq, embed_dim] representing long-form context to resample.
attention_mask (`torch.Tensor`, *optional*): Tensor of shape [bsz, 1, seq, n_latents] representing attention mask.
position_ids (`torch.LongTensor`, *optional*): Tensor of shape [bsz, seq] representing position indices of each input token.
past_key_value (`Tuple[torch.Tensor]`, *optional*): Tuple of tensors containing cached key and value states.
output_attentions (`bool`, *optional*, defaults to `False`): Whether to return attention weights.
use_cache (`bool`, *optional*, defaults to `False`): Whether to use past_key_value for caching.


def gru_feedfwd(a_t, h_prev, filters, name=None):

  with tf.variable_scope(name, default_name="GRU", values=[a_t, h_prev]):

    z_t = (
        tf.sigmoid(
            tpu_conv1d(a_t, filters, 1, padding="SAME", name="W_z") +
            tpu_conv1d(h_prev, filters, 1, padding="SAME", name="U_z")))
    r_t = (
        tf.sigmoid(
            tpu_conv1d(a_t, filters, 1, padding="SAME", name="W_r") +
            tpu_conv1d(h_prev, filters, 1, padding="SAME", name="U_r")))
    h_tilde = (
        tf.tanh(
            tpu_conv1d(a_t, filters, 1, padding="SAME", name="W") +
            tpu_conv1d(r_t * h_prev, filters, 1, padding="SAME", name="U")))
    h_t = (1. - z_t) * h_prev + z_t * h_tilde

  return h_t

position-wise Feed-fwd GRU gates following the MPNN.

Args:
a_t: Tensor of shape [batch, length, depth] of current input
h_prev: Tensor of shape [batch, length, depth] of prev input
filters: an integer specifying number of dimensions of the filters
name: A string
Returns:
h_t: [batch, length, filters] hidden state


def reduce_to_best_decode(metrics, reduce_func):
    num_videos = metrics.shape[1]
    mean_across_frames = np.mean(metrics, axis=(- 1))
    best_decode_ind = reduce_func(mean_across_frames, axis=0)
    best_metrics = metrics[(best_decode_ind, np.arange(num_videos), :)]
    return (best_metrics, best_decode_ind)

Extracts the best-decode from the metrics according to reduce_func.

Args:
metrics: 3-D numpy array, shape=(num_decodes, num_samples, num_frames)
reduce_func: callable, np.argmax or np.argmin.
Returns:
best_metrics: 2-D numpy array, shape=(num_samples, num_frames).
best_decode_ind: 1-D numpy array, shape=(num_samples,)


def serialize(dtype_policy):
    from keras.src.saving import serialization_lib
    return serialization_lib.serialize_keras_object(dtype_policy)

Serializes `DTypePolicy` instance.

Args:
dtype_policy: A Keras `DTypePolicy` instance.

Returns:
`DTypePolicy` configuration dictionary.


def call(self, inputs, training=True, intermediates_dict=None):
    x = self.conv1(inputs)
    x = self.bn_conv1(x, training=training)
    x = tf.nn.relu(x)
    if intermediates_dict is not None:
        intermediates_dict['block0'] = x
    x = self.max_pool(x)
    if intermediates_dict is not None:
        intermediates_dict['block0mp'] = x
    x = self.l2a(x, training=training)
    x = self.l2b(x, training=training)
    x = self.l2c(x, training=training)
    if intermediates_dict is not None:
        intermediates_dict['block1'] = x
    x = self.l3a(x, training=training)
    x = self.l3b(x, training=training)
    x = self.l3c(x, training=training)
    x = self.l3d(x, training=training)
    if intermediates_dict is not None:
        intermediates_dict['block2'] = x
    x = self.l4a(x, training=training)
    x = self.l4b(x, training=training)
    x = self.l4c(x, training=training)
    x = self.l4d(x, training=training)
    x = self.l4e(x, training=training)
    x = self.l4f(x, training=training)
    if self.block3_strides:
        x = self.subsampling_layer(x)
        if intermediates_dict is not None:
            intermediates_dict['block3'] = x
    elif intermediates_dict is not None:
        intermediates_dict['block3'] = x
    x = self.l5a(x, training=training)
    x = self.l5b(x, training=training)
    x = self.l5c(x, training=training)
    if self.average_pooling:
        x = self.avg_pool(x)
        if intermediates_dict is not None:
            intermediates_dict['block4'] = x
    elif intermediates_dict is not None:
        intermediates_dict['block4'] = x
    if self.include_top:
        return self.fc1000(self.flatten(x))
    elif self.global_pooling:
        return self.global_pooling(x)
    else:
        return x

Call the ResNet50 model.

Args:
inputs: Images to compute features for.
training: Whether model is in training phase.
intermediates_dict: `None` or dictionary. If not None, accumulate feature
maps from intermediate blocks into the dictionary.
""

Returns:
Tensor with featuremap.


def tfms_from_model(f_model, sz, aug_tfms=None, max_zoom=None, pad=0, crop_type=CropType.RANDOM,
                    tfm_y=None, sz_y=None, pad_mode=cv2.BORDER_REFLECT, norm_y=True, scale=None):

    stats = inception_stats if f_model in inception_models else imagenet_stats
    return tfms_from_stats(stats, sz, aug_tfms, max_zoom=max_zoom, pad=pad, crop_type=crop_type,
                           tfm_y=tfm_y, sz_y=sz_y, pad_mode=pad_mode, norm_y=norm_y, scale=scale)

Returns separate transformers of images for training and validation.
Transformers are constructed according to the image statistics given by the model. (See tfms_from_stats)

Arguments:
f_model: model, pretrained or not pretrained


def listen(self, grpc_port):

    if self._grpc_port:
      raise ValueError(
          "This DebuggerPlugin instance is already listening at gRPC port %d" %
          self._grpc_port)
    self._grpc_port = grpc_port

    sys.stderr.write('Creating DebuggerDataServer at port %d and logdir %s\n' %
                     (self._grpc_port, self._logdir))
    sys.stderr.flush()
    self._debugger_data_server = debugger_server_lib.DebuggerDataServer(
        self._grpc_port, self._logdir)

    threading.Thread(target=self._debugger_data_server.
                     start_the_debugger_data_receiving_server).start()

Start listening on the given gRPC port.

This method of an instance of DebuggerPlugin can be invoked at most once.
This method is not thread safe.

Args:
grpc_port: port number to listen at.

Raises:
ValueError: If this instance is already listening at a gRPC port.


def get_sailthru_client(site_code):
    config = get_sailthru_configuration(site_code)
    if (not config.get('SAILTHRU_ENABLE')):
        msg = 'Sailthru is not enabled for site {}'.format(site_code)
        log.debug(msg)
        raise SailthruNotEnabled(msg)
    key = config.get('SAILTHRU_KEY')
    secret = config.get('SAILTHRU_SECRET')
    if (not (key and secret)):
        msg = 'Both key and secret are required for site {}'.format(site_code)
        log.error(msg)
        raise ConfigurationError(msg)
    return SailthruClient(key, secret)

Returns a Sailthru client for the specified site.

Args:
site_code (str): Site for which the client should be configured.

Returns:
SailthruClient

Raises:
SailthruNotEnabled: If Sailthru is not enabled for the specified site.
ConfigurationError: If either the Sailthru API key or secret are not set for the site.


def fib_iter(n):

    assert n >= 0, 'n must be positive integer'

    fib_1 = 0
    fib_2 = 1
    sum = 0
    if n <= 1:
        return n
    for _ in range(n-1):
        sum = fib_1 + fib_2
        fib_1 = fib_2
        fib_2 = sum
    return sum

[summary]
Works iterative approximate O(n)

Arguments:
n {[int]} -- [description]

Returns:
[int] -- [description]


def from_sr_code(code):

    code = str(code)
    proj4 = utils.crscode_to_string("sr-org", code, "proj4")
    crs = from_proj4(proj4)
    return crs

Load crs object from sr-org code, via spatialreference.org.
Parses based on the proj4 representation.

Arguments:

- *code*: The SR-ORG code as an integer.

Returns:

- A CS instance of the indicated type.


def Run(self, args):
    allowed_temp_dirs = [GetTempDirForRoot(root) for root in config.CONFIG['Client.tempdir_roots']]
    if args.path:
        path = utils.NormalizePath(args.path)
        if (platform.system() == 'Windows'):
            path = client_utils.CanonicalPathToLocalPath(path)
        paths = [path]
    else:
        paths = allowed_temp_dirs
    deleted = []
    errors = []
    for path in paths:
        if os.path.isdir(path):
            for filename in os.listdir(path):
                abs_filename = os.path.join(path, filename)
                try:
                    DeleteGRRTempFile(abs_filename)
                    deleted.append(abs_filename)
                except Exception as e:
                    errors.append(e)
        elif os.path.isfile(path):
            DeleteGRRTempFile(path)
            deleted = [path]
        elif (path not in allowed_temp_dirs):
            if (not os.path.exists(path)):
                raise ErrorBadPath(('File %s does not exist' % path))
            else:
                raise ErrorBadPath(('Not a regular file or directory: %s' % path))
    reply = ''
    if deleted:
        reply = ('Deleted: %s.' % deleted)
    else:
        reply = 'Nothing deleted.'
    if errors:
        reply += ('\n%s' % errors)
    self.SendReply(rdf_client.LogMessage(data=reply))

Delete all the GRR temp files in path.

If path is a directory, look in the top level for filenames beginning with
Client.tempfile_prefix, and delete them.

If path is a regular file and starts with Client.tempfile_prefix delete it.

Args:
args: pathspec pointing to directory containing temp files to be
deleted, or a single file to be deleted.
Returns:
deleted: array of filename strings that were deleted
Raises:
ErrorBadPath: if path doesn't exist or is not a regular file or directory


def _FormatNotes(self, event):

    inode = event.inode
    if inode is None:
      inode = '-'

    notes = getattr(event, 'notes', '')
    if not notes:
      display_name = getattr(event, 'display_name', '')
      notes = 'File: {0:s} inode: {1!s}'.format(display_name, inode)
    return self._SanitizeField(notes)

Formats the notes.

Args:
event (EventObject): event.

Returns:
str: formatted notes field.


def parse_intrans(path_dir):

        intrans = {}
        with open(os.path.join(path_dir, "boltztrap.intrans"), 'r') as f:
            for line in f:
                if "iskip" in line:
                    intrans["scissor"] = Energy(float(line.split(" ")[3]),
                                                "Ry").to("eV")
                if "HISTO" in line or "TETRA" in line:
                    intrans["dos_type"] = line[:-1]
        return intrans

Parses boltztrap.intrans mainly to extract the value of scissor applied to the bands or some other inputs
Args:
path_dir: (str) dir containing the boltztrap.intrans file
Returns:
intrans (dict): a dictionary containing various inputs that had been used in the Boltztrap run.


def _to_client_query(self, client):
    ancestor_client_key = None
    if self.ancestor is not None:
        ancestor_client_key = self.ancestor.to_client_key()
    self.filters = self._set_runtime_filters()
    if isinstance(self.namespace, ValueProvider):
        self.namespace = self.namespace.get()
    return query.Query(client, kind=self.kind, project=self.project, namespace=self.namespace, ancestor=ancestor_client_key, filters=self.filters, projection=self.projection, order=self.order, distinct_on=self.distinct_on)

Returns a ``google.cloud.datastore.query.Query`` instance that represents
this query.

Args:
client: (``google.cloud.datastore.client.Client``) Datastore client
instance to use.


def dispatch_non_api_requests(self, request, start_response):

    for path_regex, dispatch_function in self._dispatchers:
      if path_regex.match(request.relative_url):
        return dispatch_function(request, start_response)

    if request.http_method == 'OPTIONS':
      cors_handler = self._create_cors_handler(request)
      if cors_handler.allow_cors_request:

        return util.send_wsgi_response('200', [], '', start_response,
                                       cors_handler)

    return None

Dispatch this request if this is a request to a reserved URL.

If the request matches one of our reserved URLs, this calls
start_response and returns the response body.  This also handles OPTIONS
CORS requests.

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

Returns:
None if the request doesn't match one of the reserved URLs this
handles.  Otherwise, returns the response body.


def Open(self, file_object, ascii_codepage='cp1252'):
    registry_file = dfwinreg_regf.REGFWinRegistryFile(ascii_codepage=ascii_codepage)
    registry_file.Open(file_object)
    return registry_file

Opens a Windows Registry file-like object.

Args:
file_object (dfvfs.FileIO): Windows Registry file-like object.
ascii_codepage (Optional[str]): ASCII string codepage.

Returns:
WinRegistryFile: Windows Registry file or None.


def _from_list_record(data):

    return [Schema._get_field_entry('Column%d' % (i + 1), value) for i, value in enumerate(data)]

Infer a BigQuery table schema from a list of values.

Args:
data: The list of values.
Returns:
A list of dictionaries containing field 'name' and 'type' entries, suitable for use in a
BigQuery Tables resource schema.


def anonymous_name():
    return 'cd2c89b7-88b7-44c8-ad83-06c2a9158347'

Returns the anonymous shared name.

In eager mode we create anonymous resources to avoid spurious sharing issues.
The runtime generates a unique name on our behalf when the reserved
anonymous shared name is used as a shared name.

Returns:
The anonymous shared name.


def embedding_lookup(self, x, means):
    x_means_hot = self.nearest_neighbor(x, means)
    x_means_hot_flat = tf.reshape(x_means_hot, [(- 1), self.hparams.num_blocks, self.hparams.block_v_size])
    x_means = tf.matmul(tf.transpose(x_means_hot_flat, perm=[1, 0, 2]), means)
    x_means = tf.transpose(x_means, [1, 0, 2])
    q_loss = tf.reduce_mean(tf.squared_difference(tf.stop_gradient(x), x_means))
    e_loss = tf.reduce_mean(tf.squared_difference(x, tf.stop_gradient(x_means)))
    return (x_means_hot, x_means, q_loss, e_loss)

Compute nearest neighbors and loss for training the embeddings.

Args:
x: Batch of encoder continuous latent states sliced/projected into
shape
[-1, num_blocks, block_dim].
means: Embedding means.

Returns:
The nearest neighbor in one hot form, the nearest neighbor
itself, the
commitment loss, embedding training loss.


def parse(self, requires_cfg=True):
    self._parse_default()
    self._parse_config(requires_cfg)
    self._parse_env()

Parse the configuration sources into `Bison`.

Args:
requires_cfg (bool): Specify whether or not parsing should fail
if a config file is not found. (default: True)


def entity_to_bulk(entities, resource_type_parent):
    if (not isinstance(entities, list)):
        entities = [entities]
    bulk_array = []
    for e in entities:
        bulk = {'type': e.get('type'), 'ownerName': e.get('ownerName')}
        if (resource_type_parent in ['Group', 'Task', 'Victim']):
            bulk['name'] = e.get('value')
        elif (resource_type_parent in ['Indicator']):
            bulk['confidence'] = e.get('confidence')
            bulk['rating'] = e.get('rating')
            bulk['summary'] = e.get('value')
        bulk_array.append(bulk)
    if (len(bulk_array) == 1):
        return bulk_array[0]
    return bulk_array

Convert Single TC Entity to Bulk format.

.. Attention:: This method is subject to frequent changes

Args:
entities (dictionary): TC Entity to be converted to Bulk.
resource_type_parent (string): The resource parent type of the tc_data provided.

Returns:
(dictionary): A dictionary representing TC Bulk format.


def IsDerivedFunction(clean_lines, linenum):

  for i in xrange(linenum, max(-1, linenum - 10), -1):
    match = Match(r'^([^()]*\w+)\(', clean_lines.elided[i])
    if match:

      line, _, closing_paren = CloseExpression(
          clean_lines, i, len(match.group(1)))
      return (closing_paren >= 0 and
              Search(r'\boverride\b', line[closing_paren:]))
  return False

Check if current line contains an inherited function.

Args:
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
Returns:
True if current line contains a function with "override"
virt-specifier.


def post_process(self, settings):
    for k in settings:
        if ((k in self.settings_manifesto) and (self.settings_manifesto[k].get('postprocess', None) is not None)):
            rules = self.settings_manifesto[k]['postprocess']
            for method_name in rules:
                settings[k] = getattr(self, method_name)(settings, k, settings[k])
    return settings

Perform post processing methods on settings according to their
definition in manifest.

Post process methods are implemented in their own method that have the
same signature:

* Get arguments: Current settings, item name and item value;
* Return item value possibly patched;

Args:
settings (dict): Loaded settings.

Returns:
dict: Settings object possibly modified (depending from applied
post processing).


def map_subgraph(init_tensor, sources, disallowed_placeholders, visited_ops, op_outputs, add_sources):
    ops_to_visit = [_as_operation(init_tensor)]
    extra_sources = object_identity.ObjectIdentitySet()
    while ops_to_visit:
        op = ops_to_visit.pop()
        if op in visited_ops:
            continue
        visited_ops.add(op)
        should_raise = False
        if disallowed_placeholders is not None and op in disallowed_placeholders:
            should_raise = True
        elif op.type == 'Placeholder':
            if disallowed_placeholders is None and (not add_sources):
                should_raise = True
            extra_sources.update(op.outputs)
        if should_raise:
            raise UnliftableError('Unable to lift tensor %s because it depends transitively on placeholder %s via at least one path, e.g.: %s' % (repr(init_tensor), repr(op), show_path(op, init_tensor, sources)))
        for inp in graph_inputs(op):
            op_outputs[inp].add(op)
            if inp not in visited_ops and inp not in (sources or extra_sources):
                ops_to_visit.append(inp)
    return extra_sources

Walk a Graph and capture the subgraph between init_tensor and sources.

Note: This function mutates visited_ops and op_outputs.

Args:
init_tensor:  A Tensor or Operation where the subgraph terminates.
sources:  A set of Tensors where subgraph extraction should stop.
disallowed_placeholders: An optional set of ops which may not appear in the
lifted graph. Defaults to all placeholders.
visited_ops: A set of operations which were visited in a prior pass.
op_outputs: A defaultdict containing the outputs of an op which are to be
copied into the new subgraph.
add_sources: A boolean indicating whether placeholders which are not in
sources should be allowed.

Returns:
The set of placeholders upon which init_tensor depends and are not in
sources.

Raises:
UnliftableError: if init_tensor depends on a placeholder which is not in
sources and add_sources is False.


def _matches(field, params):

    fieldattrs = six.iteritems(params)
    return all(getattr(field, attr) == val for attr, val in fieldattrs)

Return True if the input TypedField `field` contains instance attributes
that match the input parameters.

Args:
field: A TypedField instance.
params: A dictionary of TypedField instance attribute-to-value mappings.

Returns:
True if the input TypedField matches the input parameters.


def http(self):
    if (self._use_cached_http and hasattr(self._local, 'http')):
        return self._local.http
    if (self._http_replay is not None):
        http = self._http_replay
    else:
        http = _build_http()
    authorized_http = google_auth_httplib2.AuthorizedHttp(self._credentials, http=http)
    if self._use_cached_http:
        self._local.http = authorized_http
    return authorized_http

A thread local instance of httplib2.Http.

Returns:
httplib2.Http: An Http instance authorized by the credentials.


def generate(self, past_values: torch.Tensor, observed_mask: Optional[torch.Tensor]=None) -> SamplePatchTSMixerPredictionOutput:
    num_parallel_samples = self.num_parallel_samples
    outputs = self(past_values=past_values, future_values=None, observed_mask=observed_mask, output_hidden_states=False)
    distribution = self.distribution_output.distribution(outputs.prediction_outputs, loc=outputs.loc, scale=outputs.scale)
    samples = [distribution.sample() for _ in range(num_parallel_samples)]
    samples = torch.stack(samples, dim=1)
    return SamplePatchTSMixerPredictionOutput(sequences=samples)

Generate sequences of sample predictions from a model with a probability distribution head.

Args:
past_values (`torch.FloatTensor` of shape `(batch_size, sequence_length, num_input_channels)`):
Past values of the time series that serves as context in order to predict the future.

observed_mask (`torch.BoolTensor` of shape `(batch_size, sequence_length, num_input_channels)`, *optional*):
Boolean mask to indicate which `past_values` were observed and which were missing. Mask values selected
in `[0, 1]`:

- 1 for values that are **observed**,
- 0 for values that are **missing** (i.e. NaNs that were replaced by zeros).

Return:
[`SamplePatchTSMixerPredictionOutput`] where the outputs `sequences` tensor will have shape `(batch_size,
number of samples, prediction_length, num_input_channels)`.


def add_layer_timing_signal_learned_1d(x, layer, num_layers):

  channels = common_layers.shape_list(x)[-1]
  signal = get_layer_timing_signal_learned_1d(channels, layer, num_layers)
  x += signal
  return x

Add n-dimensional embedding as the layer (vertical) timing signal.

Adds embeddings to represent the position of the layer in the tower.

Args:
x: a tensor with shape [batch, length, depth]
layer: layer num
num_layers: total number of layers

Returns:
a Tensor the same shape as x.


def get_or_create_annotations_dict(members, ctx):
    annotations_dict = abstract_utils.get_annotations_dict(members)
    if annotations_dict is None:
        annotations_dict = abstract.AnnotationsDict({}, ctx)
        members['__annotations__'] = annotations_dict.to_variable(ctx.root_node)
    return annotations_dict

Get __annotations__ from members map, create and attach it if not present.

The returned dict is also referenced by members, so it is safe to mutate.

Args:
members: A dict of member name to variable.
ctx: context.Context instance.

Returns:
members['__annotations__'] unpacked as a python dict


def get_stops_line(self, **kwargs):

        params = {
            'line': util.ints_to_string(kwargs.get('lines', [])),
            'direction': util.direction_code(kwargs.get('direction', '')),
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

        result = self.make_request('geo', 'get_stops_line', **params)

        if not util.check_result(result, 'stop'):
            return False, 'UNKNOWN ERROR'

        values = util.response_list(result, 'stop')
        return True, [emtype.Stop(**a) for a in values]

Obtain information on the stops of the given lines.

Arguments:
lines (list[int] | int): Lines to query, may be empty to get
all the lines.
direction (str): Optional, either *forward* or *backward*.
lang (str): Language code (*es* or *en*).

Returns:
Status boolean and parsed response (list[Stop]), or message string
in case of error.


def __init__(self, fn, name=None, dtype=None, **kwargs):
    super(SumOverBatchSizeMetricWrapper, self).__init__(name=name, dtype=dtype)
    self._fn = fn
    self._fn_kwargs = kwargs

Creates a `SumOverBatchSizeMetricWrapper` instance.

Args:
fn: The metric function to wrap, with signature `fn(y_true, y_pred,
**kwargs)`.
name: (Optional) string name of the metric instance.
dtype: (Optional) data type of the metric result.
**kwargs: The keyword arguments that are passed on to `fn`.


def ParseTable(table):
    precondition.AssertIterableType(table, dict)
    result = rdf_osquery.OsqueryTable()
    result.header = ParseHeader(table)
    for row in table:
        result.rows.append(ParseRow(result.header, row))
    return result

Parses table of osquery output.

Args:
table: A table in a "parsed JSON" representation.

Returns:
A parsed `rdf_osquery.OsqueryTable` instance.


def orphan_instance(self, rval: RawValue) -> "ObjectMember":

        val = self.from_raw(rval)
        return ObjectMember(self.iname(), {}, val, None, self, datetime.now())

Return an isolated instance of the receiver.

Args:
rval: Raw value to be used for the returned instance.


def from_csv(pipe, file_pattern: str, schema: Schema, timestamp_key: str='timestamp') -> BeamEventSet:
    return pipe | 'Read csv' >> from_csv_raw(file_pattern) | 'Convert to Event Set' >> to_event_set(schema, timestamp_key, format='single_events')

Reads a file or set of csv files into a Beam EventSet.

Limitation: Timestamps have to be numerical values. See documentation of
`to_event_set` for more details.

Usage example:

```
input_node: tp.EventSetNode = ...
p | tpb.from_csv("/tmp/path.csv", input_node.schema) | ...
```

`from_csv` is equivalent to `from_csv_raw + to_event_set`.

Args:
pipe: Begin Beam pipe.
file_pattern: Path or path matching expression compatible with
`MatchFiles`.
schema: Schema of the data. If you have a Temporian node, the schema is
available with `node.schema`.
timestamp_key: Key containing the timestamps.

Returns:
A PCollection of event-set compatible with tpb.run.


def dtype_numpy(x):
    return dtypes_module.as_dtype(x.dtype).as_numpy_dtype

Returns the numpy dtype of a Keras tensor or variable.

Args:
x: Tensor or variable.

Returns:
numpy.dtype, dtype of `x`.


def transform_array(array, force_list=False, buffers=None):
    array = convert_datetime_array(array)
    return serialize_array(array, force_list=force_list, buffers=buffers)

Transform a NumPy arrays into serialized format

Converts un-serializable dtypes and returns JSON serializable
format

Args:
array (np.ndarray) : a NumPy array to be transformed
force_list (bool, optional) : whether to only output to standard lists
This function can encode some dtypes using a binary encoding, but
setting this argument to True will override that and cause only
standard Python lists to be emitted. (default: False)

buffers (set, optional) :
If binary buffers are desired, the buffers parameter may be
provided, and any columns that may be sent as binary buffers
will be added to the set. If None, then only base64 encoding
will be used (default: None)

If force_list is True, then this value will be ignored, and
no buffers will be generated.

**This is an "out" parameter**. The values it contains will be
modified in-place.

Returns:
JSON


def getGroupContentItems(self, groupName):

        admin = None
        userCommunity = None
        groupIds = None
        groupId = None

        groupContent = None
        result = None
        item = None
        items = []
        try:
            admin = arcrest.manageorg.Administration(securityHandler=self._securityHandler)

            userCommunity = admin.community
            groupIds = userCommunity.getGroupIDs(groupNames=groupName)

            if not groupIds is None:
                for groupId in groupIds:
                    groupContent = admin.content.groupContent(groupId=groupId)
                    if 'error' in groupContent:
                        print (groupContent)
                    else:
                        for result in groupContent['items']:
                            item = admin.content.getItem(itemId = result['id'])
                            items.append(item)
            return items
        except:
            line, filename, synerror = trace()
            raise common.ArcRestHelperError({
                        "function": "getGroupContent",
                        "line": line,
                        "filename":  filename,
                        "synerror": synerror,
                                        }
                                )
        finally:
            admin = None
            userCommunity = None
            groupIds = None
            groupId = None
            groupContent = None
            result = None
            item = None

            del admin
            del userCommunity
            del groupIds
            del groupId
            del groupContent
            del result
            del item

            gc.collect()

Gets all the items owned by a group(s).

Args:
groupName (list): The name of the group(s) from which to get items.
Returns:
list: A list of items belonging to the group(s).
Notes:
If you want to get items from a single group, ``groupName`` can be passed as a :py:obj:`str`.
See Also:
:py:func:`getGroupContent` for retrieving all content, not just items.


def real(self):

    def re(val):
        if hasattr(val, 'real'):
            return val.real
        elif hasattr(val, 'as_real_imag'):
            return val.as_real_imag()[0]
        elif hasattr(val, 'conjugate'):
            return ((val.conjugate() + val) / 2)
        else:
            raise NoConjugateMatrix(('Matrix entry %s contains has no defined conjugate' % str(val)))
    return self.element_wise(re)

Element-wise real part

Raises:
NoConjugateMatrix: if entries have no `conjugate` method and no
other way to determine the real part

Note:
A mathematically equivalent way to obtain a real matrix from a
complex matrix ``M`` is::

(M.conjugate() + M) / 2

However, the result may not be identical to ``M.real``, as the
latter tries to convert elements of the matrix to real values
directly, if possible, and only uses the conjugate as a fall-back


def execute(api):
    try:
        return api.execute()
    except Exception as exception:
        now = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
        _print_error(('%s: Exception %s: %s' % (now, type(exception).__name__, str(exception))))
        raise exception

Executes operation.

Args:
api: The base API object

Returns:
A response body object


def get_ip_address_info(ip_address, cache=None, nameservers=None,
                        timeout=2.0, parallel=False):

    ip_address = ip_address.lower()
    if cache:
        info = cache.get(ip_address, None)
        if info:
            return info
    info = OrderedDict()
    info["ip_address"] = ip_address
    reverse_dns = get_reverse_dns(ip_address,
                                  nameservers=nameservers,
                                  timeout=timeout)
    country = get_ip_address_country(ip_address, parallel=parallel)
    info["country"] = country
    info["reverse_dns"] = reverse_dns
    info["base_domain"] = None
    if reverse_dns is not None:
        base_domain = get_base_domain(reverse_dns)
        info["base_domain"] = base_domain

    return info

Returns reverse DNS and country information for the given IP address

Args:
ip_address (str): The IP address to check
cache (ExpiringDict): Cache storage
nameservers (list): A list of one or more nameservers to use
(Cloudflare's public DNS resolvers by default)
timeout (float): Sets the DNS timeout in seconds
parallel (bool): parallel processing

Returns:
OrderedDict: ``ip_address``, ``reverse_dns``


def RefreshClaims(self, ids, timeout='30m'):
    with data_store.DB.GetMutationPool() as mutation_pool:
        mutation_pool.QueueRefreshClaims(ids, timeout=timeout)

Refreshes claims on records identified by ids.

Args:
ids: A list of ids provided by ClaimRecords

timeout: The new timeout for these claims.

Raises:
LockError: If the queue is not locked.


def iter_cast(inputs, dst_type, return_type=None):
    if (not isinstance(inputs, collections_abc.Iterable)):
        raise TypeError('inputs must be an iterable object')
    if (not isinstance(dst_type, type)):
        raise TypeError('"dst_type" must be a valid type')
    out_iterable = six.moves.map(dst_type, inputs)
    if (return_type is None):
        return out_iterable
    else:
        return return_type(out_iterable)

Cast elements of an iterable object into some type.

Args:
inputs (Iterable): The input object.
dst_type (type): Destination type.
return_type (type, optional): If specified, the output object will be
converted to this type, otherwise an iterator.

Returns:
iterator or specified type: The converted object.


def get_axarray_fig_plt(ax_array, nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw):
    import matplotlib.pyplot as plt
    if (ax_array is None):
        (fig, ax_array) = plt.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey, squeeze=squeeze, subplot_kw=subplot_kw, gridspec_kw=gridspec_kw, **fig_kw)
    else:
        fig = plt.gcf()
        ax_array = np.reshape(np.array(ax_array), (nrows, ncols))
        if squeeze:
            if (ax_array.size == 1):
                ax_array = ax_array[0]
            elif any(((s == 1) for s in ax_array.shape)):
                ax_array = ax_array.ravel()
    return (ax_array, fig, plt)

Helper function used in plot functions that accept an optional array of Axes
as argument. If ax_array is None, we build the `matplotlib` figure and
create the array of Axes by calling plt.subplots else we return the
current active figure.

Returns:
ax: Array of :class:`Axes` objects
figure: matplotlib figure
plt: matplotlib pyplot module.


def process_curve_types(curve_types: List[Union[curve_types_lib.RiskFreeCurve, curve_types_lib.RateIndexCurve]], mask=None) -> Tuple[List[Union[curve_types_lib.RiskFreeCurve, curve_types_lib.RateIndexCurve]], List[int]]:

    def _get_signature(curve):

        if isinstance(curve, curve_types_lib.RiskFreeCurve):
            return curve.currency.value
        elif isinstance(curve, curve_types_lib.RateIndexCurve):
            return curve.currency.value + '_' + curve.index.type.value + '_' + '_'.join(curve.index.source) + '_' + '_'.join(curve.index.name)
        else:
            raise ValueError(f'{type(curve)} is not supported.')
    curve_list = to_list(curve_types)
    if mask is not None:
        return (curve_list, mask)
    curve_hash = [_get_signature(curve_type) for curve_type in curve_list]
    hash_discount_map = {_get_signature(curve_type): curve_type for curve_type in curve_list}
    mask, mask_map, num_unique_discounts = create_mask(curve_hash)
    discount_curve_types = [hash_discount_map[mask_map[i]] for i in range(num_unique_discounts)]
    return (discount_curve_types, mask)

Extracts unique curves and computes an integer mask.

#### Example
```python
curve_types = [RiskFreeCurve("USD"), RiskFreeCurve("AUD"),
RiskFreeCurve("USD")]
process_curve_types(curve_types)
# Returns [RiskFreeCurve("AUD"), RiskFreeCurve("USD")], [1, 0, 1]
```
Args:
curve_types: A list of either `RiskFreeCurve` or `RateIndexCurve`.
mask: An optional integer mask for the sorted curve type sequence. If
supplied, the function returns does not do anything and returns
`(curve_types, mask)`.

Returns:
A Tuple of `(curve_list, mask)` where  `curve_list` is  a list of unique
curves in `curve_types` and `mask` is a list of integers which is the
mask for `curve_types`.


async def validate(state, holdout_glob):

  if not glob.glob(holdout_glob):
    print('Glob "{}" didn\'t match any files, skipping validation'.format(
          holdout_glob))
  else:
    await run(
        'python3', 'validate.py', holdout_glob,
        '--flagfile={}'.format(os.path.join(FLAGS.flags_dir, 'validate.flags')),
        '--work_dir={}'.format(fsdb.working_dir()))

Validate the trained model against holdout games.

Args:
state: the RL loop State instance.
holdout_glob: a glob that matches holdout games.


def pause(self, container):

        url = self._url('/containers/{0}/pause', container)
        res = self._post(url)
        self._raise_for_status(res)

Pauses all processes within a container.

Args:
container (str): The container to pause

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def expand_path_cfg(path_cfg, alias_dict={ }, overriding_kargs={ }):

    if isinstance(path_cfg, str):
        return _expand_str(path_cfg, alias_dict, overriding_kargs)

    if isinstance(path_cfg, dict):
        return _expand_dict(path_cfg, alias_dict)

    return _expand_tuple(path_cfg, alias_dict, overriding_kargs)

expand a path config

Args:
path_cfg (str, tuple, dict): a config for path
alias_dict (dict): a dict for aliases
overriding_kargs (dict): to be used for recursive call


def _read_group_h5(filename, groupname):

    with h5py.File(filename, 'r') as h5f:
        data = h5f[groupname][()]
    return data

Return group content.

Args:
filename (:class:`pathlib.Path`): path of hdf5 file.
groupname (str): name of group to read.
Returns:
:class:`numpy.array`: content of group.


def PluginAssets(self, plugin_name):
    with self._accumulators_mutex:
        items = list(six.iteritems(self._accumulators))
    return {run: accum.PluginAssets(plugin_name) for (run, accum) in items}

Get index of runs and assets for a given plugin.

Args:
plugin_name: Name of the plugin we are checking for.

Returns:
A dictionary that maps from run_name to a list of plugin
assets for that run.


def write(self, auth, resource, value, options={}, defer=False):
    return self._call('write', auth, [resource, value, options], defer)

Writes a single value to the resource specified.

Args:
auth: cik for authentication.
resource: resource to write to.
value: value to write
options: options.


def _calc_block_mean_variance(image, mask, blocksize):

    I = image.copy()
    I_f = I.astype(np.float32) / 255.

    result = np.zeros(
        (image.shape[0] / blocksize, image.shape[1] / blocksize),
        dtype=np.float32)

    for i in xrange(0, image.shape[0] - blocksize, blocksize):
        for j in xrange(0, image.shape[1] - blocksize, blocksize):

            patch = I_f[i:i+blocksize+1, j:j+blocksize+1]
            mask_patch = mask[i:i+blocksize+1, j:j+blocksize+1]

            tmp1 = np.zeros((blocksize, blocksize))
            tmp2 = np.zeros((blocksize, blocksize))
            mean, std_dev = cv2.meanStdDev(patch, tmp1, tmp2, mask_patch)

            value = 0
            if std_dev[0][0] > MEAN_VARIANCE_THRESHOLD:
                value = mean[0][0]

            result[i/blocksize, j/blocksize] = value

    small_image = cv2.resize(I, (image.shape[1] / blocksize,
                                 image.shape[0] / blocksize))

    res, inpaintmask = cv2.threshold(result, 0.02, 1, cv2.THRESH_BINARY)

    inpainted = cv2.inpaint(small_image, inpaintmask.astype(np.uint8), 5,
                            cv2.INPAINT_TELEA)

    res = cv2.resize(inpainted, (image.shape[1], image.shape[0]))

    return res

Adaptively determines image background.

Args:
image: image converted 1-channel image.
mask: 1-channel mask, same size as image.
blocksize: adaptive algorithm parameter.

Returns:
image of same size as input with foreground inpainted with background.


class BaseLogger(Callback):

    def __init__(self, stateful_metrics=None):
        super(BaseLogger, self).__init__()
        self.stateful_metrics = set(stateful_metrics or [])

    def on_epoch_begin(self, epoch, logs=None):
        self.seen = 0
        self.totals = {}

    def on_batch_end(self, batch, logs=None):
        logs = logs or {}
        batch_size = logs.get('size', 0)
        num_steps = logs.get('num_steps', 1)
        self.seen += batch_size * num_steps
        for k, v in logs.items():
            if k in self.stateful_metrics:
                self.totals[k] = v
            elif k in self.totals:
                self.totals[k] += v * batch_size
            else:
                self.totals[k] = v * batch_size

    def on_epoch_end(self, epoch, logs=None):
        if logs is not None:
            for k in self.params['metrics']:
                if k in self.totals:
                    if k in self.stateful_metrics:
                        logs[k] = self.totals[k]
                    else:
                        logs[k] = self.totals[k] / self.seen

Callback that accumulates epoch averages of metrics.

This callback is automatically applied to every Keras model.

Args:
stateful_metrics: Iterable of string names of metrics that
should *not* be averaged over an epoch.
Metrics in this list will be logged as-is in `on_epoch_end`.
All others will be averaged in `on_epoch_end`.


def _GetSectionNames(self, pefile_object):
    section_names = []
    for section in pefile_object.sections:
        section_name = getattr(section, 'Name', b'')
        try:
            section_name = '{0:s}'.format(section_name.decode('unicode_escape'))
        except UnicodeDecodeError:
            section_name = '{0:s}'.format(repr(section_name))
        section_names.append(section_name)
    return section_names

Retrieves all PE section names.

Args:
pefile_object (pefile.PE): pefile object.

Returns:
list[str]: names of the sections.


def __init__(self, grr_worker=None):

    self.grr_worker = grr_worker
    self.response_id = INITIAL_RESPONSE_ID
    self.cpu_used = None
    self.nanny_controller = None
    self.status = rdf_flows.GrrStatus(
        status=rdf_flows.GrrStatus.ReturnedStatus.OK)
    self._last_gc_run = rdfvalue.RDFDatetime.Now()
    self._gc_frequency = config.CONFIG["Client.gc_frequency"]
    self.proc = psutil.Process()
    self.cpu_start = self.proc.cpu_times()
    self.cpu_limit = rdf_flows.GrrMessage().cpu_limit

Initializes the action plugin.

Args:
grr_worker:  The grr client worker object which may be used to e.g. send
new actions on.


def changes(self, target_version=None, nodes=None, labels=None):

        if nodes is None:
            nodes = []
        if labels is None:
            labels = []

        current_time = time.time()

        params = {
            'nodes': nodes,
            'clientTimestamp': _node.NodeTimestamps.int_to_str(current_time),
            'requestHeader': {
                'clientSessionId': self._session_id,
                'clientPlatform': 'ANDROID',
                'clientVersion': {
                    'major': '9',
                    'minor': '9',
                    'build': '9',
                    'revision': '9'
                },
                'capabilities': [
                    {'type': 'NC'},
                    {'type': 'PI'},
                    {'type': 'LB'},
                    {'type': 'AN'},
                    {'type': 'SH'},
                    {'type': 'DR'},
                    {'type': 'TR'},
                    {'type': 'IN'},

                    {'type': 'SNB'},
                    {'type': 'MI'},
                    {'type': 'CO'},

                ]
            },
        }
        if target_version is not None:
            params['targetVersion'] = target_version

        if labels:
            params['userInfo'] = {
                'labels': labels
            }

        logger.debug('Syncing %d labels and %d nodes', len(labels), len(nodes))

        return self.send(
            url=self._base_url + 'changes',
            method='POST',
            json=params
        )

Sync up (and down) all changes.

Args:
target_version (str): The local change version.
nodes (List[dict]): A list of nodes to sync up to the server.
labels (List[dict]): A list of labels to sync up to the server.

Return:
dict: Description of all changes.

Raises:
APIException: If the server returns an error.


def _save_to_hdx(self, action, id_field_name, file_to_upload=None):
    result = self._write_to_hdx(action, self.data, id_field_name, file_to_upload)
    self.old_data = self.data
    self.data = result

Creates or updates an HDX object in HDX, saving current data and replacing with returned HDX object data
from HDX

Args:
action (str): Action to perform: 'create' or 'update'
id_field_name (str): Name of field containing HDX object identifier
file_to_upload (Optional[str]): File to upload to HDX

Returns:
None


def optimize_hlo(input_stream: Iterator[str], optimizer_path: str, optimizer_args: ListOrTuple[str], expand_to_input: str=_DEFAULT_INPUT_FILE_EXPANSION_TOKEN) -> Iterator[str]:
    with tempfile.NamedTemporaryFile(mode='w+', suffix='.hlo') as test_case_file:
        test_case_file.writelines(input_stream)
        test_case_file.seek(0)
        command_argv = [optimizer_path, *(arg.replace(expand_to_input, test_case_file.name) for arg in optimizer_args)]
        hlo_opt_process = subprocess.run(command_argv, capture_output=True, check=False)
        if hlo_opt_process.returncode != 0:
            line_number_prefix_width = len(str(sum((1 for _ in test_case_file))))
            test_case_file.seek(0)
            error_lines = list()
            error_lines.append(f"Error in command '{' '.join(command_argv)}':\n\n")
            for line in io.StringIO(hlo_opt_process.stderr.decode()):
                error_lines.append(f'  {line}')
            error_lines.append(f"\nContents of input file '{test_case_file.name}' (expanded from '{expand_to_input}'), with line numbers:\n\n")
            line_number = 0
            for line_number, line in enumerate(test_case_file, start=1):
                error_lines.append(f'  {line_number:>{line_number_prefix_width}d} {line}')
            if line_number == 0:
                error_lines.append('  (File is empty.)\n')
            raise ChildProcessError(''.join(error_lines))
    return io.StringIO(hlo_opt_process.stdout.decode())

Passes `input_stream` through an optimizer; output is another stream.

Args:
input_stream: An iterator over the lines of HLO to run through an optimizer.
optimizer_path: The program to use for optimizing the HLO.
optimizer_args: The arguments to pass into the optimizer tool. All instances
of the substring `expand_to_input` in the argument list will expand to the
path of a temporary file containing the text of `input_stream`.
expand_to_input: All instances of this substring in `optimizer_args` will
expand to the path of a temporary file containing the text of
`input_stream`.

Returns:
An iterator over the lines of HLO produced by the optimizer.

Raises:
ChildProcessError: If the optimizer exits with error status.


def insert_many(self, component_index, keys, values, name=None):
    if name is None:
        name = '%s_BarrierInsertMany' % self._name
    return gen_data_flow_ops.barrier_insert_many(self._barrier_ref, keys, values, component_index, name=name)

For each key, assigns the respective value to the specified component.

This operation updates each element at component_index.

Args:
component_index: The component of the value that is being assigned.
keys: A vector of keys, with length n.
values: An any-dimensional tensor of values, which are associated with the
respective keys. The first dimension must have length n.
name: Optional name for the op.

Returns:
The operation that performs the insertion.
Raises:
InvalidArgumentsError: If inserting keys and values without elements.


def batch_normalize_with_arguments(x, arguments):

  x = prettytensor.wrap(x)

  if isinstance(arguments, bool):
    if arguments:
      return x.batch_normalize()
    else:
      return x

  kwargs = arguments._asdict()
  defaults = prettytensor._defaults

  for arg in ('learned_moments_update_rate', 'variance_epsilon',
              'scale_after_normalization'):
    if kwargs.get(arg, None) is None:
      if arg in defaults:
        kwargs[arg] = defaults[arg]
      else:
        del kwargs[arg]
  return x.batch_normalize(**kwargs)

Applies batch normalization to x as specified in arguments.

Args:
x: A Pretty Tensor.
arguments: Either a boolean to batch_normalize or a
BatchNormalizationArguments

Returns:
x with batch normalization applied.


def serialize_to_normalized_pretty_json(py_obj):
    return json.dumps(py_obj, sort_keys=True, indent=2, cls=ToJsonCompatibleTypes)

Serialize a native object to normalized, pretty printed JSON.

The JSON string is normalized by sorting any dictionary keys.

Args:
py_obj: object
Any object that can be represented in JSON. Some types, such as datetimes are
automatically converted to strings.

Returns:
str: normalized, pretty printed JSON string.


def remote_command(task: Task, command: str) -> Result:
    client = task.host.get_connection('paramiko', task.nornir.config)
    connection_state = task.host.get_connection_state('paramiko')
    chan = client.get_transport().open_session()
    if connection_state['ssh_forward_agent']:
        AgentRequestHandler(chan)
    chan.exec_command(command)
    with chan.makefile() as f:
        stdout = f.read().decode()
    with chan.makefile_stderr() as f:
        stderr = f.read().decode()
    exit_status_code = chan.recv_exit_status()
    if exit_status_code:
        raise CommandError(command, exit_status_code, stdout, stderr)
    result = (stderr if stderr else stdout)
    return Result(result=result, host=task.host, stderr=stderr, stdout=stdout)

Executes a command remotely on the host

Arguments:
command (``str``): command to execute

Returns:
Result object with the following attributes set:
* result (``str``): stderr or stdout
* stdout (``str``): stdout
* stderr (``str``): stderr

Raises:
:obj:`nornir.core.exceptions.CommandError`: when there is a command error


def get_file_clusters(self, date):
    api_name = 'virustotal-file-clusters'
    (all_responses, resources) = self._bulk_cache_lookup(api_name, date)
    response = self._request_reports('date', date, 'file/clusters')
    self._extract_response_chunks(all_responses, response, api_name)
    return all_responses

Retrieves file similarity clusters for a given time frame.

Args:
date: the specific date for which we want the clustering details.
Example: 'date': '2013-09-10'
Returns:
A dict with the VT report.


def transform_qubits(self: TSelf_Operation,
                         func: Callable[[Qid], Qid]) -> TSelf_Operation:

        return self.with_qubits(*(func(q) for q in self.qubits))

Returns the same operation, but with different qubits.

Args:
func: The function to use to turn each current qubit into a desired
new qubit.

Returns:
The receiving operation but with qubits transformed by the given
function.


def poweroff_vmss_vms(access_token, subscription_id, resource_group, vmss_name, instance_ids):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/virtualMachineScaleSets/', vmss_name,
                        '/powerOff?api-version=', COMP_API])
    body = '{"instanceIds" : ' + instance_ids + '}'
    return do_post(endpoint, body, access_token)

Poweroff all the VMs in a virtual machine scale set.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vmss_name (str): Name of the virtual machine scale set.
instance_ids (str): String representation of a JSON list of VM IDs. E.g. '[1,2]'.

Returns:
HTTP response.


def zero_add(previous_value, x, name=None, reuse=None):

  with tf.variable_scope(name, default_name="zero_add", reuse=reuse):
    gamma = tf.get_variable("gamma", (), initializer=tf.zeros_initializer())
    return previous_value + gamma * x

Resnet connection with zero initialization.

Another type of resnet connection which returns previous_value + gamma * x.
gamma is a trainable scalar and initialized with zero. It is useful when a
module is plugged into a trained model and we want to make sure it matches the
original model's performance.

Args:
previous_value:  A tensor.
x: A tensor.
name: name of variable scope; defaults to zero_add.
reuse: reuse scope.

Returns:
previous_value + gamma * x.


def parse_plugin_metadata(content):
    if (not isinstance(content, bytes)):
        raise TypeError('Content type must be bytes')
    result = plugin_data_pb2.PrCurvePluginData.FromString(content)
    if (result.version == 0):
        return result
    else:
        logger.warn('Unknown metadata version: %s. The latest version known to this build of TensorBoard is %s; perhaps a newer build is available?', result.version, PROTO_VERSION)
        return result

Parse summary metadata to a Python object.

Arguments:
content: The `content` field of a `SummaryMetadata` proto
corresponding to the pr_curves plugin.

Returns:
A `PrCurvesPlugin` protobuf object.


def normalize_whitespace(text):

    return re.sub(r"\s+", " ", text, flags=re.UNICODE).strip()

Returns the given text with outer whitespace removed and inner whitespace collapsed.

Args:
text (str): The text to normalize.

Returns:
str: The normalized text.


def file(self, path):
    with open(path, 'r') as f:
        self.body(str(f.read()))

Reads the body to match from a disk file.

Arguments:
path (str): relative or absolute path to file to read from.

Returns:
self: current Mock instance.


def send(self, message_type, message, connection_id, one_way=False):

        try:
            self._network.send(message_type, message, connection_id,
                               one_way=one_way)
        except ValueError:
            LOGGER.debug("Connection %s is no longer valid. "
                         "Removing from list of peers.",
                         connection_id)
            if connection_id in self._peers:
                del self._peers[connection_id]

Sends a message via the network.

Args:
message_type (str): The type of the message.
message (bytes): The message to be sent.
connection_id (str): The connection to send it to.


def feed(self, byts):
    self.unpk.feed(byts)
    retn = []
    while True:
        try:
            item = self.unpk.unpack()
            tell = self.unpk.tell()
            retn.append(((tell - self.size), item))
            self.size = tell
        except msgpack.exceptions.OutOfData:
            break
    return retn

Feed bytes to the unpacker and return completed objects.

Args:
byts (bytes): Bytes to unpack.

Notes:
It is intended that this function is called multiple times with
bytes from some sort of a stream, as it will unpack and return
objects as they are available.

Returns:
list: List of tuples containing the item size and the unpacked item.


def iplot_bloch_multivector(rho, figsize=None):
    html_template = Template('\n
\n
\n

\n
\n
\n    ')
    javascript_template = Template('\n

Create a bloch sphere representation.

Graphical representation of the input array, using as much bloch
spheres as qubit are required.

Args:
rho (array): State vector or density matrix
figsize (tuple): Figure size in pixels.


def es2et(
        es_fo,
        et_fo,
    ):

        et_fo.write("
        et_fo.write("
        et_fo.write("
        et_fo.write("
        et_fo.write("
        et_fo.write("

        last_rname = ""
        for line in es_fo:
            line = line.strip()
            if line == "" or line[0] == "
                continue
            else:
                (rname, mapped, ref, direction, left, right, category, nb_of_segments) = line.split("\t")
                nb_of_segments = int(nb_of_segments)

                if rname != last_rname:

                    if last_rname != "":
                        voc = Bam._vector_of_categories(single_reads_statistics, rname, nb_of_segments)
                        et_fo.write(Bam._et_line(readname=rname, vector_of_categories=voc))
                        et_fo.write(os.linesep)

                    single_reads_statistics = [
                        {
                            "U": 0,
                            "u": 0,
                            "M": [],
                            "m": 0,
                            "w": 0,
                            "T": 0,
                            "t": 0,
                        } for i in range(rnftools.lavender.MAXIMAL_MAPPING_QUALITY + 1)
                    ]
                    last_rname = rname

                if category == "U":
                    for q in range(len(single_reads_statistics)):
                        single_reads_statistics[q]["U"] += 1

                elif category == "u":
                    for q in range(len(single_reads_statistics)):
                        single_reads_statistics[q]["u"] += 1

                else:
                    mapping_quality = int(mapped.replace("mapped_", ""))
                    assert 0 <= mapping_quality and mapping_quality <= rnftools.lavender.MAXIMAL_MAPPING_QUALITY, mapping_quality

                    if category == "m":
                        for q in range(mapping_quality + 1):
                            single_reads_statistics[q]["m"] += 1
                        for q in range(mapping_quality + 1, rnftools.lavender.MAXIMAL_MAPPING_QUALITY + 1):
                            single_reads_statistics[q]["T"] += 1

                    elif category == "w":
                        for q in range(mapping_quality + 1):
                            single_reads_statistics[q]["w"] += 1
                        for q in range(mapping_quality + 1, rnftools.lavender.MAXIMAL_MAPPING_QUALITY + 1):
                            single_reads_statistics[q]["t"] += 1

                    else:
                        assert category[0] == "M", category
                        segment_id = int(category.replace("M_", ""))
                        for q in range(mapping_quality + 1):
                            single_reads_statistics[q]["M"].append(segment_id)
                        for q in range(mapping_quality + 1, rnftools.lavender.MAXIMAL_MAPPING_QUALITY + 1):
                            single_reads_statistics[q]["t"] += 1

        voc = Bam._vector_of_categories(single_reads_statistics, rname, nb_of_segments)
        et_fo.write(Bam._et_line(readname=rname, vector_of_categories=voc))
        et_fo.write(os.linesep)

Convert ES to ET.

Args:
es_fo (file): File object for the ES file.
et_fo (file): File object for the ET file.


def PlistValueToPlainValue(plist):
    if isinstance(plist, dict):
        ret_value = dict()
        for (key, value) in iteritems(plist):
            ret_value[key] = PlistValueToPlainValue(value)
        return ret_value
    elif isinstance(plist, list):
        return [PlistValueToPlainValue(value) for value in plist]
    elif isinstance(plist, datetime.datetime):
        return ((calendar.timegm(plist.utctimetuple()) * 1000000) + plist.microsecond)
    return plist

Takes the plist contents generated by binplist and returns a plain dict.

binplist uses rich types to express some of the plist types. We need to
convert them to types that RDFValueArray will be able to transport.

Args:
plist: A plist to convert.

Returns:
A simple python type.


def return_train_dataset(self):
    (X, y) = self.return_main_dataset()
    if (self.test_dataset['method'] == 'split_from_main'):
        (X, X_test, y, y_test) = train_test_split(X, y, test_size=self.test_dataset['split_ratio'], random_state=self.test_dataset['split_seed'], stratify=y)
    return (X, y)

Returns train data set

Returns:
X (numpy.ndarray): Features

y (numpy.ndarray): Labels


def combine(*rnf_profiles):
    for rnf_profile in rnf_profiles:
        self.prefix_width = max(self.prefix_width, rnf_profile.prefix_width)
        self.read_tuple_id_width = max(self.read_tuple_id_width, rnf_profile.read_tuple_id_width)
        self.genome_id_width = max(self.genome_id_width, rnf_profile.genome_id_width)
        self.chr_id_width = max(self.chr_id_width, rnf_profile.chr_id_width)
        self.coor_width = max(self.coor_width, rnf_profile.coor_width)

Combine more profiles and set their maximal values.

Args:
*rnf_profiles (rnftools.rnfformat.RnfProfile): RNF profile.


def _convert_json(obj):

    if isinstance(obj, dict):
        return {_convert_json(key): _convert_json(val)
                for (key, val) in six.iteritems(obj)}
    elif isinstance(obj, list) and len(obj) == 2:
        first = obj[0]
        second = obj[1]
        if first == 'set' and isinstance(second, list):
            return [_convert_json(elem) for elem in second]
        elif first == 'map' and isinstance(second, list):
            for elem in second:
                if not isinstance(elem, list) or len(elem) != 2:
                    return obj
            return {elem[0]: _convert_json(elem[1]) for elem in second}
        else:
            return obj
    elif isinstance(obj, list):
        return [_convert_json(elem) for elem in obj]
    else:
        return obj

Converts from the JSON output provided by ovs-vsctl into a usable Python
object tree. In particular, sets and maps are converted from lists to
actual sets or maps.

Args:
obj: Object that shall be recursively converted.

Returns:
Converted version of object.


def CaptureVariablesList(self, items, depth, empty_message, limits):

    v = []
    for name, value in items:
      if (self._total_size >= self.max_size) or (
          len(v) >= limits.max_list_items):
        v.append({
            'status': {
                'refersTo': 'VARIABLE_VALUE',
                'description': {
                    'format':
                        ('Only first $0 items were captured. Use in an '
                         'expression to see all items.'),
                    'parameters': [str(len(v))]}}})
        break
      v.append(self.CaptureNamedVariable(name, value, depth, limits))

    if not v:
      return [{'status': {
          'refersTo': 'VARIABLE_NAME',
          'description': {'format': empty_message}}}]

    return v

Captures list of named items.

Args:
items: iterable of (name, value) tuples.
depth: nested depth of dictionaries and vectors for items.
empty_message: info status message to set if items is empty.
limits: Per-object limits for capturing variable data.

Returns:
List of formatted variable objects.


def GetOptionBool(self, section, option):

    return (not self.config.has_option(section, option)
            or self.config.getboolean(section, option))

Get the value of an option in the config file.

Args:
section: string, the section of the config file to check.
option: string, the option to retrieve the value of.

Returns:
bool, True if the option is enabled or not set.


def GetCPIOArchiveFileEntryByPathSpec(self, path_spec):

    location = getattr(path_spec, 'location', None)
    if location is None:
      raise errors.PathSpecError('Path specification missing location.')

    if not location.startswith(self.LOCATION_ROOT):
      raise errors.PathSpecError('Invalid location in path specification.')

    if len(location) == 1:
      return None

    return self._cpio_archive_file.GetFileEntryByPath(location[1:])

Retrieves the CPIO archive file entry for a path specification.

Args:
path_spec (PathSpec): a path specification.

Returns:
CPIOArchiveFileEntry: CPIO archive file entry or None if not available.

Raises:
PathSpecError: if the path specification is incorrect.


def wait_for_tuning_job(self, job, poll=5):
    desc = _wait_until((lambda : _tuning_job_status(self.sagemaker_client, job)), poll)
    self._check_job_status(job, desc, 'HyperParameterTuningJobStatus')
    return desc

Wait for an Amazon SageMaker hyperparameter tuning job to complete.

Args:
job (str): Name of the tuning job to wait for.
poll (int): Polling interval in seconds (default: 5).

Returns:
(dict): Return value from the ``DescribeHyperParameterTuningJob`` API.

Raises:
ValueError: If the hyperparameter tuning job fails.


def sanity_check_actions(actions_spec):
    actions = copy.deepcopy(actions_spec)
    is_unique = ('type' in actions)
    if is_unique:
        actions = dict(action=actions)
    for (name, action) in actions.items():
        if ('type' not in action):
            action['type'] = 'int'
        if (action['type'] == 'int'):
            if ('num_actions' not in action):
                raise TensorForceError("Action requires value 'num_actions' set!")
        elif (action['type'] == 'float'):
            if (('min_value' in action) != ('max_value' in action)):
                raise TensorForceError("Action requires both values 'min_value' and 'max_value' set!")
        if ('shape' not in action):
            action['shape'] = ()
        if isinstance(action['shape'], int):
            action['shape'] = (action['shape'],)
    return (actions, is_unique)

Sanity checks an actions dict, used to define the action space for an MDP.
Throws an error or warns if mismatches are found.

Args:
actions_spec (Union[None,dict]): The spec-dict to check (or None).

Returns: Tuple of 1) the action space desc and 2) whether there is only one component in the action space.


def layout_asides(self, block, context, frag, view_name, aside_frag_fns):
    result = Fragment(frag.content)
    result.add_fragment_resources(frag)
    for (aside, aside_fn) in aside_frag_fns:
        aside_frag = self.wrap_aside(block, aside, view_name, aside_fn(block, context), context)
        aside.save()
        result.add_content(aside_frag.content)
        result.add_fragment_resources(aside_frag)
    return result

Execute and layout the aside_frags wrt the block's frag. Runtimes should feel free to override this
method to control execution, place, and style the asides appropriately for their application

This default method appends the aside_frags after frag. If you override this, you must
call wrap_aside around each aside as per this function.

Args:
block (XBlock): the block being rendered
frag (html): The result from rendering the block
aside_frag_fns list((aside, aside_fn)): The asides and closures for rendering to call


def setViewModel(self, model):

        if isinstance(model, DataFrameModel):
            self.enableEditing(False)
            self.uncheckButton()

            selectionModel = self.tableView.selectionModel()
            self.tableView.setModel(model)
            model.dtypeChanged.connect(self.updateDelegate)
            model.dataChanged.connect(self.updateDelegates)
            del selectionModel

Sets the model for the enclosed TableView in this widget.

Args:
model (DataFrameModel): The model to be displayed by
the Table View.


def _get_bucketing_id(self, user_id, attributes):
    attributes = (attributes or {})
    bucketing_id = attributes.get(enums.ControlAttributes.BUCKETING_ID)
    if (bucketing_id is not None):
        if isinstance(bucketing_id, string_types):
            return bucketing_id
        self.logger.warning('Bucketing ID attribute is not a string. Defaulted to user_id.')
    return user_id

Helper method to determine bucketing ID for the user.

Args:
user_id: ID for user.
attributes: Dict representing user attributes. May consist of bucketing ID to be used.

Returns:
String representing bucketing ID if it is a String type in attributes else return user ID.


def as_bytes(bytes_or_text, encoding='utf-8'):

    if isinstance(bytes_or_text, _six.text_type):
        return bytes_or_text.encode(encoding)
    elif isinstance(bytes_or_text, bytes):
        return bytes_or_text
    else:
        raise TypeError('Expected binary or unicode string, got %r' %
                        (bytes_or_text,))

Converts either bytes or unicode to `bytes`, using utf-8 encoding for text.
Args:
bytes_or_text: A `bytes`, `str`, or `unicode` object.
encoding: A string indicating the charset for encoding unicode.
Returns:
A `bytes` object.
Raises:
TypeError: If `bytes_or_text` is not a binary or unicode string.


def HandleForwardedIps(self, interface, forwarded_ips, interface_ip=None):
    desired = self.ip_forwarding_utils.ParseForwardedIps(forwarded_ips)
    configured = self.ip_forwarding_utils.GetForwardedIps(interface, interface_ip)
    to_add = sorted((set(desired) - set(configured)))
    to_remove = sorted((set(configured) - set(desired)))
    self._LogForwardedIpChanges(configured, desired, to_add, to_remove, interface)
    self._AddForwardedIps(to_add, interface)
    self._RemoveForwardedIps(to_remove, interface)

Handle changes to the forwarded IPs on a network interface.

Args:
interface: string, the output device to configure.
forwarded_ips: list, the forwarded IP address strings desired.
interface_ip: string, current interface ip address.


def train(self, docs, retrain=False):
    if (type(docs) == dict):
        docs = docs.items()
    train_sentences = [self._gen_sentence(item) for item in docs]
    if (self.is_trained and (retrain == False)):
        self.update_model(train_sentences, update_labels_bool=True)
    else:
        self.model = Doc2Vec(train_sentences, size=self.size, window=self.window, min_count=self.min_count, workers=self.workers)
        self.is_trained = True
    return 0

Train Doc2Vec on a series of docs. Train from scratch or update.

Args:
docs: list of tuples (assetid, body_text) or dictionary {assetid : body_text}
retrain: boolean, retrain from scratch or update model

saves model in class to self.model

Returns: 0 if successful


def get_global_generator():
    global global_generator
    if global_generator is None:
        if config.is_op_determinism_enabled():
            raise RuntimeError('"get_global_generator" cannot be called if determinism is enabled, unless "set_global_generator" has already been called. Please call "set_global_generator" first.')
        with ops.init_scope():
            global_generator = Generator.from_non_deterministic_state()
    return global_generator

Retrieves the global generator.

This function will create the global generator the first time it is called,
and the generator will be placed at the default device at that time, so one
needs to be careful when this function is first called. Using a generator
placed on a less-ideal device will incur performance regression.

Returns:
The global `tf.random.Generator` object.


def attach_template(self, _template, _key, **unbound_var_values):

    if _key in unbound_var_values:
      raise ValueError('%s specified twice.' % _key)
    unbound_var_values[_key] = self
    return _template.as_layer().construct(**unbound_var_values)

Attaches the template to this such that _key=this layer.

Note: names were chosen to avoid conflicts with any likely unbound_var keys.

Args:
_template: The template to construct.
_key: The key that this layer should replace.
**unbound_var_values: The values for the unbound_vars.
Returns:
A new layer with operation applied.
Raises:
ValueError: If _key is specified twice or there is a problem computing the
template.


def __init__(self, unique_identifier=None):

        super(ArchiveResponsePayload, self).__init__(
            enums.Tags.RESPONSE_PAYLOAD
        )

        self._unique_identifier = None
        self.unique_identifier = unique_identifier

Construct an Archive response payload struct.

Args:
unique_identifier (string): The ID of the managed object (e.g.,
a public key) that was archived. Optional, defaults to None.


def path_data(self, variable_data, path):

        try:
            import jmespath
        except ImportError:
            print('Could not import jmespath module (try "pip install jmespath").')
            sys.exit(1)

        if isinstance(variable_data, string_types):

            try:
                variable_data = json.loads(variable_data)
            except Exception:
                self.log.debug('String value ({}) could not JSON serialized.'.format(variable_data))
        if path is not None and isinstance(variable_data, (dict, list)):
            expression = jmespath.compile(path)
            variable_data = expression.search(
                variable_data, jmespath.Options(dict_cls=collections.OrderedDict)
            )
        return variable_data

Return JMESPath data.

Args:
variable_data (str): The JSON data to run path expression.
path (str): The JMESPath expression.

Returns:
dict: The resulting data from JMESPath.


def status_codes_by_date_stats():

    def date_counter(queryset):
        return dict(Counter(map((lambda dt: ms_since_epoch(datetime.combine(make_naive(dt), datetime.min.time()))), list(queryset.values_list('datetime', flat=True)))))
    codes = {low: date_counter(RequestLog.objects.filter(status_code__gte=low, status_code__lt=high)) for (low, high) in ((200, 300), (300, 400), (400, 500))}
    codes[500] = date_counter(RequestLog.objects.filter(status_code__gte=500))
    codes['attacks'] = date_counter(RequestLog.objects.filter(status_code__in=(400, 444, 502)))
    stats = {}
    for code in (200, 300, 400, 500, 'attacks'):
        for (date, count) in codes[code].items():
            if (stats.get(date, None) is None):
                stats[date] = {200: 0, 300: 0, 400: 0, 500: 0, 'attacks': 0}
            stats[date][code] += count
    stats = sorted([(k, v) for (k, v) in stats.items()], key=(lambda x: x[0]))
    return stats

Get stats for status codes by date.

Returns:
list: status codes + date grouped by type: 2xx, 3xx, 4xx, 5xx, attacks.


def _VerifyValues(self, image, kernel, strides, rates, padding, out, use_gpu, dtype):
    strides = [1] + strides + [1]
    rates = [1] + rates + [1]
    with self.cached_session(use_gpu=use_gpu):
        out_tensor = nn_ops.dilation2d(constant_op.constant(image, dtype=dtype), constant_op.constant(kernel, dtype=dtype), strides=strides, rates=rates, padding=padding, name='dilation2d')
        self.assertAllCloseAccordingToType(out, self.evaluate(out_tensor))

Verifies the output values of the dilation function.

Args:
image: Input tensor with shape: [batch, in_height, in_width, channels].
kernel: Filter tensor with shape: [filter_height, filter_width, channels].
strides: Output strides, specified as [stride_height, stride_width].
rates: Atrous rates, specified as [rate_height, rate_width].
padding: Padding type.
out: Expected output.
use_gpu: Whether we are running on GPU.


def backend_config_to_configparser(config):

    def get_store():
        return config.get('store')

    def get_day_start():
        day_start = config.get('day_start')
        if day_start:
            day_start = day_start.strftime('%H:%M:%S')
        return day_start

    def get_fact_min_delta():
        return text_type(config.get('fact_min_delta'))

    def get_tmpfile_path():
        return text_type(config.get('tmpfile_path'))

    def get_db_engine():
        return text_type(config.get('db_engine'))

    def get_db_path():
        return text_type(config.get('db_path'))

    def get_db_host():
        return text_type(config.get('db_host'))

    def get_db_port():
        return text_type(config.get('db_port'))

    def get_db_name():
        return text_type(config.get('db_name'))

    def get_db_user():
        return text_type(config.get('db_user'))

    def get_db_password():
        return text_type(config.get('db_password'))
    cp_instance = SafeConfigParser()
    cp_instance.add_section('Backend')
    cp_instance.set('Backend', 'store', get_store())
    cp_instance.set('Backend', 'day_start', get_day_start())
    cp_instance.set('Backend', 'fact_min_delta', get_fact_min_delta())
    cp_instance.set('Backend', 'tmpfile_path', get_tmpfile_path())
    cp_instance.set('Backend', 'db_engine', get_db_engine())
    cp_instance.set('Backend', 'db_path', get_db_path())
    cp_instance.set('Backend', 'db_host', get_db_host())
    cp_instance.set('Backend', 'db_port', get_db_port())
    cp_instance.set('Backend', 'db_name', get_db_name())
    cp_instance.set('Backend', 'db_user', get_db_user())
    cp_instance.set('Backend', 'db_password', get_db_password())
    return cp_instance

Return a ConfigParser instance representing a given backend config dictionary.

Args:
config (dict): Dictionary of config key/value pairs.

Returns:
SafeConfigParser: SafeConfigParser instance representing config.

Note:
We do not provide *any* validation about mandatory values what so ever.


def __call__(self, shape, dtype=None, **kwargs):
    self._validate_kwargs(kwargs, support_partition=self.support_partition)
    if dtype is not None:
        dtype = dtypes.as_dtype(dtype)
    return constant_op.constant(self.value, dtype=dtype, shape=shape)

Returns a tensor object initialized as specified by the initializer.

Args:
shape: Shape of the tensor.
dtype: Optional dtype of the tensor. If not provided the dtype of the
tensor created will be the type of the inital value.
**kwargs: Additional keyword arguments.

Raises:
TypeError: If the initializer cannot create a tensor of the requested
dtype.


def join(self) -> None:
    self._server.join()

Blocks until the server has shut down.

This is useful when starting a dedicated dispatch process.

```
dispatcher = tf.data.experimental.service.DispatchServer(
tf.data.experimental.service.DispatcherConfig(port=5050))
dispatcher.join()
```

Raises:
tf.errors.OpError: Or one of its subclasses if an error occurs while
joining the server.


def update_configuration(self, timeout=-1):

        uri = "{}/configuration".format(self.data["uri"])
        return self._helper.update(None, uri=uri, timeout=timeout)

Asynchronously applies or re-applies the logical interconnect configuration to all managed interconnects.

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

Returns:
dict: Logical Interconnect.


def update(self, settings):

        if 'settings' in settings:
            self._settings.update(settings['settings'])
        else:
            self._settings.update(settings)

        if 'instruments' in settings:
            for instrument_name, instrument_setting in settings['instruments'].items():
                self.instruments[instrument_name]['settings'].update(instrument_setting['settings'])

        if 'scripts' in settings:
            for script_name, script_setting in settings['scripts'].items():
                self.scripts[script_name].update(script_setting)

updates the internal dictionary
Args:
settings: parameters to be set
# mabe in the future:
# Returns: boolean that is true if update successful


def format_comment(comment_data):
    format_pieces = []
    if ('line' in comment_data):
        format_pieces.append('line {line}')
    if ('column' in comment_data):
        if format_pieces:
            format_pieces.append(', ')
        format_pieces.append('col {column}')
    if format_pieces:
        format_pieces.append(': ')
    if ('severity' in comment_data):
        format_pieces.append('{severity}: ')
    if ('message_id' in comment_data):
        format_pieces.append('[{message_id}]: ')
    if ('message' in comment_data):
        format_pieces.append('{message}')
    return ''.join(format_pieces).format(**comment_data)

Formats the data returned by the linters.

Given a dictionary with the fields: line, column, severity, message_id,
message, will generate a message like:

'line {line}, col {column}: {severity}: [{message_id}]: {message}'

Any of the fields may nbe absent.

Args:
comment_data: dictionary with the linter data.

Returns:
a string with the formatted message.


def forward_rates(self, market: pmd.ProcessedMarketData, past_fixing: Optional[types.FloatTensor]=None, name: Optional[str]=None) -> Tuple[types.DateTensor, types.FloatTensor]:
    name = name or self._name + '_forward_rates'
    with tf.name_scope(name):
        reference_curve = get_discount_curve(self._reference_curve_type, market, self._reference_mask)
        valuation_date = dateslib.convert_to_date_tensor(market.date)
        coupon_start_date_ord = self._coupon_start_dates.ordinal()
        coupon_end_date_ord = self._coupon_end_dates.ordinal()
        valuation_date_ord = valuation_date.ordinal()
        batch_shape = tf.shape(coupon_start_date_ord)[:-1]
        valuation_date_ord += tf.expand_dims(tf.zeros(batch_shape, dtype=tf.int32), axis=-1)
        ind = tf.maximum(tf.searchsorted(coupon_start_date_ord, valuation_date_ord) - 1, 0)
        fixing_dates_ord = tf.gather(coupon_start_date_ord, ind, batch_dims=len(coupon_start_date_ord.shape) - 1)
        fixing_end_dates_ord = tf.gather(coupon_end_date_ord, ind, batch_dims=len(coupon_start_date_ord.shape) - 1)
        fixing_dates = dateslib.dates_from_ordinals(fixing_dates_ord)
        fixing_end_dates = dateslib.dates_from_ordinals(fixing_end_dates_ord)
        if past_fixing is None:
            past_fixing = _get_fixings(fixing_dates, fixing_end_dates, self._reference_curve_type, self._reference_mask, market)
        else:
            past_fixing = tf.convert_to_tensor(past_fixing, dtype=self._dtype, name='past_fixing')
        forward_rates = reference_curve.forward_rate(self._accrual_start_date, self._accrual_end_date, day_count_fraction=self._daycount_fractions)
        forward_rates = tf.where(self._daycount_fractions > 0.0, forward_rates, tf.zeros_like(forward_rates))
        forward_rates = tf.where(self._coupon_end_dates < valuation_date, tf.constant(0, dtype=self._dtype), tf.where(self._coupon_start_dates >= valuation_date, forward_rates, past_fixing))
        return (self._coupon_end_dates, forward_rates)

Returns forward rates for the floating leg.

Args:
market: An instance of `ProcessedMarketData`.
past_fixing: An optional `Tensor` of shape compatible with
`batch_shape + [1]`. Represents the fixings for the cashflows as
observed at `market.date`.
name: Python str. The name to give to the ops created by this function.
Default value: `None` which maps to 'forward_rates'.

Returns:
A tuple of two `Tensor`s of shape `batch_shape + [num_cashflows]`
containing the dates and the corresponding forward rates for each stream
based on the input market data.