class AlignVisionEncoder(nn.Module):

    def __init__(self, config: AlignVisionConfig):
        super().__init__()
        self.depth_coefficient = config.depth_coefficient

        def round_repeats(repeats):
            return int(math.ceil(self.depth_coefficient * repeats))
        num_base_blocks = len(config.in_channels)
        num_blocks = sum((round_repeats(n) for n in config.num_block_repeats))
        curr_block_num = 0
        blocks = []
        for i in range(num_base_blocks):
            in_dim = round_filters(config, config.in_channels[i])
            out_dim = round_filters(config, config.out_channels[i])
            stride = config.strides[i]
            kernel_size = config.kernel_sizes[i]
            expand_ratio = config.expand_ratios[i]
            for j in range(round_repeats(config.num_block_repeats[i])):
                id_skip = True if j == 0 else False
                stride = 1 if j > 0 else stride
                in_dim = out_dim if j > 0 else in_dim
                adjust_padding = False if curr_block_num in config.depthwise_padding else True
                drop_rate = config.drop_connect_rate * curr_block_num / num_blocks
                block = AlignVisionBlock(config=config, in_dim=in_dim, out_dim=out_dim, stride=stride, kernel_size=kernel_size, expand_ratio=expand_ratio, drop_rate=drop_rate, id_skip=id_skip, adjust_padding=adjust_padding)
                blocks.append(block)
                curr_block_num += 1
        self.blocks = nn.ModuleList(blocks)

    def forward(self, hidden_states: torch.FloatTensor, output_hidden_states: Optional[bool]=False, return_dict: Optional[bool]=True) -> BaseModelOutputWithPoolingAndNoAttention:
        all_hidden_states = (hidden_states,) if output_hidden_states else None
        for block in self.blocks:
            hidden_states = block(hidden_states)
            if output_hidden_states:
                all_hidden_states += (hidden_states,)
        if not return_dict:
            return tuple((v for v in [hidden_states, all_hidden_states] if v is not None))
        return BaseModelOutputWithNoAttention(last_hidden_state=hidden_states, hidden_states=all_hidden_states)

Forward propagates the embeddings through each vision encoder (EfficientNet) block.

Args:
config ([`AlignVisionConfig`]):
Model configuration class.


def continue_abort(self, root_pipeline_key, cursor=None, max_to_notify=_MAX_ABORTS_TO_BEGIN):
    if (not isinstance(root_pipeline_key, db.Key)):
        root_pipeline_key = db.Key(root_pipeline_key)
    query = _PipelineRecord.all(cursor=cursor).filter('root_pipeline =', root_pipeline_key)
    results = query.fetch(max_to_notify)
    task_list = []
    for pipeline_record in results:
        if (pipeline_record.status not in (_PipelineRecord.RUN, _PipelineRecord.WAITING)):
            continue
        pipeline_key = pipeline_record.key()
        task_list.append(taskqueue.Task(name=('%s-%s-abort' % (self.task_name, pipeline_key.name())), url=self.abort_handler_path, params=dict(pipeline_key=pipeline_key, purpose=_BarrierRecord.ABORT), headers={'X-Ae-Pipeline-Key': pipeline_key}))
    if (len(results) == max_to_notify):
        the_match = re.match('(.*)-([0-9]+)', self.task_name)
        if the_match:
            prefix = the_match.group(1)
            end = (int(the_match.group(2)) + 1)
        else:
            prefix = self.task_name
            end = 0
        task_list.append(taskqueue.Task(name=('%s-%d' % (prefix, end)), url=self.fanout_abort_handler_path, params=dict(root_pipeline_key=root_pipeline_key, cursor=query.cursor())))
    if task_list:
        try:
            taskqueue.Queue(self.queue_name).add(task_list)
        except (taskqueue.TombstonedTaskError, taskqueue.TaskAlreadyExistsError):
            pass

Sends the abort signal to all children for a root pipeline.

Args:
root_pipeline_key: db.Key of the root pipeline to abort.
cursor: The query cursor for enumerating _PipelineRecords when inserting
tasks to cause child pipelines to terminate.
max_to_notify: Used for testing.


def generate_html(store):
    spline = {'version': VERSION, 'url': 'https:
    html_template_file = os.path.join(os.path.dirname(__file__), 'templates/report.html.j2')
    with open(html_template_file) as handle:
        html_template = handle.read()
        return render(html_template, spline=spline, store=store)

Generating HTML report.

Args:
store (Store): report data.

Returns:
str: rendered HTML template.


def check_oneof(**kwargs):

    if not kwargs:
        return None

    not_nones = [val for val in kwargs.values() if val is not None]
    if len(not_nones) > 1:
        raise ValueError('Only one of {fields} should be set.'.format(
            fields=', '.join(sorted(kwargs.keys())),
        ))

Raise ValueError if more than one keyword argument is not none.

Args:
kwargs (dict): The keyword arguments sent to the function.

Returns: None

Raises:
ValueError: If more than one entry in kwargs is not none.


def get(self, identifier, default=None):

        if isinstance(identifier, int):
            values = list(self.data.values())
            if 0 <= identifier < len(values):
                return values[identifier]
            else:
                return default
        return super(Overlay, self).get(identifier, default)

Get a layer in the Overlay.

Get a particular layer in the Overlay using its path string
or an integer index.

Args:
identifier: Index or path string of the item to return
default: Value to return if no item is found

Returns:
The indexed layer of the Overlay


def publish(self,message,message_type,topic=''):

        if message_type == MULTIPART:
            raise Exception("Unsupported request type")

        super(Publisher,self).send(message,message_type,topic)

Publish the message on the PUB socket with the given topic name.

Args:
- message: the message to publish
- message_type: the type of message being sent
- topic: the topic on which to send the message. Defaults to ''.


def _get_non_string_match(self, key):

        expression = r'(?:\s*)'.join([
            '^',
            'define',
            r'\(',
            '\'{}\''.format(key),
            ',',
            r'(.*)',
            r'\)',
            ';'
        ])

        pattern = re.compile(expression, re.MULTILINE)
        return pattern.search(self._content)

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

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

Return:
MatchObject: The discovered match.


def to_dd(degrees, minutes, seconds=0):
    sign = ((- 1) if any(((i < 0) for i in (degrees, minutes, seconds))) else 1)
    return (sign * ((abs(degrees) + (abs(minutes) / 60)) + (abs(seconds) / 3600)))

Convert degrees, minutes and optionally seconds to decimal angle.

Args:
degrees (float): Number of degrees
minutes (float): Number of minutes
seconds (float): Number of seconds

Returns:
float: Angle converted to decimal degrees


def build_conflict_dict(key_list, val_list):
    key_to_vals = defaultdict(list)
    for (key, val) in zip(key_list, val_list):
        key_to_vals[key].append(val)
    return key_to_vals

Builds dict where a list of values is associated with more than one key

Args:
key_list (list):
val_list (list):

Returns:
dict: key_to_vals

CommandLine:
python -m utool.util_dict --test-build_conflict_dict

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_dict import *  # NOQA
>>> import utool as ut
>>> key_list = [  1,   2,   2,   3,   1]
>>> val_list = ['a', 'b', 'c', 'd', 'e']
>>> key_to_vals = build_conflict_dict(key_list, val_list)
>>> result = ut.repr4(key_to_vals)
>>> print(result)
{
1: ['a', 'e'],
2: ['b', 'c'],
3: ['d'],
}


def get_config(self, name):

        if name not in self.registry:
            msg = "Given config name '{}' is not registered."
            raise NotRegisteredError(msg.format(name))

        return copy.deepcopy(self.registry[name])

Return a registred configuration for given config name.

Arguments:
name (string): A registred config name.

Raises:
NotRegisteredError: If given config name does not exist in
registry.

Returns:
dict: Configuration.


def sample_measurements(self, indices: List[int], repetitions: int=1) -> List[List[bool]]:
    reversed_indices = [((self._num_qubits - 1) - index) for index in indices]
    return sim.sample_state_vector(self._current_state(), reversed_indices, repetitions)

Samples from measurements in the computational basis.

Note that this does not collapse the wave function.

Args:
indices: Which qubits are measured.

Returns:
Measurement results with True corresponding to the |1> state.
The outer list is for repetitions, and the inner corresponds to
measurements ordered by the input indices.

Raises:
ValueError if repetitions is less than one.


def codemirror_parameters(field):
    manifesto = CodemirrorAssetTagRender()
    names = manifesto.register_from_fields(field)
    config = manifesto.get_codemirror_parameters(names[0])
    return mark_safe(json.dumps(config))

Filter to include CodeMirror parameters as a JSON string for a single
field.

This must be called only on an allready rendered field, meaning you must
not use this filter on a field before a form. Else, the field widget won't
be correctly initialized.

Example:
::

{% load djangocodemirror_tags %}
{{ form.myfield|codemirror_parameters }}

Arguments:
field (djangocodemirror.fields.CodeMirrorField): A form field.

Returns:
string: JSON object for parameters, marked safe for Django templates.


def get_collection(self, key=None, name=None):

        if name is not None:
            logger.warn("TowerTensorHandle.get_collection(name=..) was renamed to (key=..) !")
            key = name
        return self._ctx.get_collection_in_tower(key)

See :meth:`BaseTowerContext.get_collection_in_tower`.

Args:
key (str): the key of the collection
name: deprecated


def value_derived_from_wavefunction(self,
                                        state: np.ndarray,
                                        qubit_map: Dict[raw_types.Qid, int]
                                        ) -> Any:

The value of the display, derived from the full wavefunction.

Args:
state: The wavefunction.
qubit_map: A dictionary from qubit to qubit index in the
ordering used to define the wavefunction.


def sg_argmin(tensor, opt):
    r
    opt += tf.sg_opt(axis=tensor.get_shape().ndims - 1)
    return tf.argmin(tensor, opt.axis, opt.name)

r"""Returns the indices of the minimum values along the specified axis.

See `tf.argin()` in tensorflow.

Args:
tensor: A `Tensor` (automatically given by chain).
opt:
axis: Target axis. Default is the last one.
name: If provided, replace current tensor's name.

Returns:
A `Tensor`.


def _get_connection(self, conn_or_int_id):

        key = conn_or_int_id
        if isinstance(key, str):
            table = self._int_connections
        elif isinstance(key, int):
            table = self._connections
        else:
            return None

        try:
            data = table[key]
        except KeyError:
            return None

        return data

Get the data for a connection by either conn_id or internal_id

Args:
conn_or_int_id (int, string): The external integer connection id or
and internal string connection id

Returns:
dict: The context data associated with that connection or None if it cannot
be found.

Raises:
ArgumentError: When the key is not found in the list of active connections
or is invalid.


def has_all_nonzero_neurite_radii(neuron, threshold=0.0):
    bad_ids = []
    seen_ids = set()
    for s in _nf.iter_sections(neuron):
        for (i, p) in enumerate(s.points):
            info = (s.id, i)
            if ((p[COLS.R] <= threshold) and (info not in seen_ids)):
                seen_ids.add(info)
                bad_ids.append(info)
    return CheckResult((len(bad_ids) == 0), bad_ids)

Check presence of neurite points with radius not above threshold

Arguments:
neuron(Neuron): The neuron object to test
threshold: value above which a radius is considered to be non-zero

Returns:
CheckResult with result including list of (section ID, point ID) pairs
of zero-radius points


def sget_steptime(self, cycle, step, dataset_number=None):

        dataset_number = self._validate_dataset_number(dataset_number)
        if dataset_number is None:
            self._report_empty_dataset()
            return
        cycle_index_header = self.headers_normal.cycle_index_txt
        step_time_header = self.headers_normal.step_time_txt
        step_index_header = self.headers_normal.step_index_txt
        test = self.datasets[dataset_number].dfdata

        if isinstance(step, (list, tuple)):
            warnings.warn(f"The varialbe step is a list."
                          f"Should be an integer."
                          f"{step}")
            step = step[0]

        c = test.loc[
            (test[cycle_index_header] == cycle) &
            (test[step_index_header] == step), :
        ]

        if not self.is_empty(c):
            t = c[step_time_header]
            return t
        else:
            return None

Returns step time for cycle, step.

Convinience function; same as issuing
dfdata[(dfdata[cycle_index_header] == cycle) &
(dfdata[step_index_header] == step)][step_time_header]

Args:
cycle: cycle number
step: step number
dataset_number: the dataset number (automatic selection if None)

Returns:
pandas.Series or None if empty


def has_no_unchecked_field(self, locator, **kwargs):

        kwargs["checked"] = False
        return self.has_no_selector("field", locator, **kwargs)

Checks if the page or current node has no radio button or checkbox with the given label,
value, or id, that is currently unchecked.

Args:
locator (str): The label, name, or id of an unchecked field.
**kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
bool: Whether it doesn't exist.


def bake(self, start_response):
    if isinstance(self._content, six.text_type):
        self._content = self._content.encode('utf8')
    if (self._content_length is None):
        self._content_length = len(self._content)
    self._headers[HttpResponseHeaders.CONTENT_LENGTH] = str(self._content_length)
    headers = list(self._headers.items())
    cookies = [(HttpResponseHeaders.SET_COOKIE, v.OutputString()) for (_, v) in self._cookies.items()]
    if len(cookies):
        headers = (list(headers) + cookies)
    start_response(self._status_code, headers)
    if isinstance(self._content, six.binary_type):
        return [self._content]
    return self._content

Bakes the response and returns the content.

Args:
start_response (:obj:`callable`): Callback method that accepts
status code and a list of tuples (pairs) containing headers'
key and value respectively.


def to_rfc3339(timestamp):
    if isinstance(timestamp, datetime.datetime):
        timestamp = (timestamp - _EPOCH_START)
    if (not isinstance(timestamp, datetime.timedelta)):
        _logger.error(u'Could not convert %s to a rfc3339 time,', timestamp)
        raise ValueError(u'Invalid timestamp type')
    return strict_rfc3339.timestamp_to_rfc3339_utcoffset(timestamp.total_seconds())

Converts ``timestamp`` to an RFC 3339 date string format.

``timestamp`` can be either a ``datetime.datetime`` or a
``datetime.timedelta``.  Instances of the later are assumed to be a delta
with the beginining of the unix epoch, 1st of January, 1970

The returned string is always Z-normalized.  Examples of the return format:
'1972-01-01T10:00:20.021Z'

Args:
timestamp (datetime|timedelta): represents the timestamp to convert

Returns:
string: timestamp converted to a rfc3339 compliant string as above

Raises:
ValueError: if timestamp is not a datetime.datetime or datetime.timedelta


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

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

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

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

    self._current_offset = 0
    self._size = len(self._file_data)

Opens the file-like object defined by path specification.

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

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


def _prepare_total_loss(self, masks):
    if self.run_eagerly:
        raise TypeError('total loss can not be computed when compiled with run_eagerly = True.')
    loss_list = []
    with backend.name_scope('loss'):
        for endpoint, mask in zip(self._training_endpoints, masks):
            if endpoint.should_skip_target():
                continue
            y_true = endpoint.training_target.target
            y_pred = endpoint.output
            loss_fn = endpoint.loss_fn
            loss_weight = endpoint.loss_weight
            loss_name = endpoint.loss_name()
            sample_weight = endpoint.sample_weight
            with backend.name_scope(loss_name):
                if mask is not None:
                    mask = math_ops.cast(mask, y_pred.dtype)
                    if sample_weight is None:
                        sample_weight = mask
                    else:
                        mask, _, sample_weight = losses_utils.squeeze_or_expand_dimensions(mask, sample_weight=sample_weight)
                        sample_weight *= mask
                if hasattr(loss_fn, 'reduction'):
                    per_sample_losses = loss_fn.call(y_true, y_pred)
                    weighted_losses = losses_utils.compute_weighted_loss(per_sample_losses, sample_weight=sample_weight, reduction=losses_utils.ReductionV2.NONE)
                    loss_reduction = loss_fn.reduction
                    if loss_reduction == losses_utils.ReductionV2.AUTO:
                        loss_reduction = losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE
                    output_loss = losses_utils.reduce_weighted_loss(weighted_losses, reduction=loss_reduction)
                else:
                    output_loss = loss_fn(y_true, y_pred, sample_weight=sample_weight)
                    loss_reduction = losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE
            if len(self.outputs) > 1:
                endpoint.output_loss_metric(output_loss)
            if loss_reduction == losses_utils.ReductionV2.SUM_OVER_BATCH_SIZE:
                output_loss = losses_utils.scale_loss_for_distribution(output_loss)
            loss_list.append(loss_weight * output_loss)
        if not loss_list and (not self.losses):
            raise ValueError('The model cannot be compiled because it has no loss to optimize.')
        custom_losses = self.get_losses_for(None) + self.get_losses_for(self.inputs)
        if custom_losses:
            total_custom_loss = math_ops.add_n(losses_utils.cast_losses_to_common_dtype(custom_losses))
            loss_list.append(losses_utils.scale_loss_for_distribution(total_custom_loss))
        loss_list = losses_utils.cast_losses_to_common_dtype(loss_list)
        if loss_list:
            total_loss = math_ops.add_n(loss_list)
        else:
            total_loss = 0.0
    return total_loss

Computes total loss from loss functions.

Args:
masks: List of mask values corresponding to each model output.

Returns:
A list of loss weights of python floats.

Raises:
TypeError: If model run_eagerly is True.


def _class_factory(base):

    class ClsPyPy(base):

        def __repr__(self):
            return repr(base(super(ClsPyPy, self).value))

        @classmethod
        def from_buffer(cls, ba):
            try:
                integer = struct.unpack_from(getattr(cls, '_type_'), ba)[0]
            except struct.error:
                len_ = len(ba)
                size = struct.calcsize(getattr(cls, '_type_'))
                if (len_ < size):
                    raise ValueError('Buffer size too small ({0} instead of at least {1} bytes)'.format(len_, size))
                raise
            return cls(integer)

    class ClsPy26(base):

        def __repr__(self):
            return repr(base(super(ClsPy26, self).value))

        def __iter__(self):
            return iter(struct.pack(getattr(super(ClsPy26, self), '_type_'), super(ClsPy26, self).value))
    try:
        base.from_buffer(bytearray(base()))
    except TypeError:
        return ClsPy26
    except AttributeError:
        return ClsPyPy
    except ValueError:
        return ClsPyPy
    return base

Create subclasses of ctypes.

Positional arguments:
base -- base class to subclass.

Returns:
New class definition.


def to_microseconds(value):
    if (not value.tzinfo):
        value = value.replace(tzinfo=pytz.utc)
    value = value.astimezone(pytz.utc)
    return (int((calendar.timegm(value.timetuple()) * 1000000.0)) + value.microsecond)

Convert a datetime to microseconds since the unix epoch.

Args:
value (datetime.datetime): The datetime to covert.

Returns:
int: Microseconds since the unix epoch.


class AlignVisionModelOutput(ModelOutput):
    image_embeds: Optional[torch.FloatTensor] = None
    last_hidden_state: Optional[torch.FloatTensor] = None
    hidden_states: Optional[Tuple[torch.FloatTensor]] = None

Base class for vision model's outputs that also contains image embeddings of the pooling of the last hidden states.

Args:
image_embeds (`torch.FloatTensor` of shape `(batch_size, output_dim)` *optional* returned when model is initialized with `with_projection=True`):
The image embeddings obtained by applying the projection layer to the pooler_output.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
Sequence of hidden-states at the output of the last layer of the model.
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape `(batch_size, sequence_length, hidden_size)`.

Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.


def make_code_readable(s):

    s = s if isinstance(s, str) else str(s)

    MAP = {",": ",\n", "{": "{\n ", "}": "\n}"}

    ll = []

    state = "open"
    flag_single = False
    flag_double = False
    flag_backslash = False
    for ch in s:
        if flag_backslash:
            flag_backslash = False
            continue

        if ch == "\\":
            flag_backslash = True
            continue

        if flag_single:
            if ch == "'":
                flag_single = False
        elif not flag_double and ch == "'":
            flag_single = True

        if flag_double:
            if ch == '"':
                flag_double = False
        elif not flag_single and ch == '"':
            flag_double = True

        if flag_single or flag_double:
            ll.append(ch)
        else:
            ll.append(MAP.get(ch, ch))

    return "".join(ll)

Add newlines at strategic places in code string for printing.

Args:
s: str, piece of code. If not str, will attempt to convert to str.

Returns:
str


def testBasic(self, count, batch_size, drop_remainder):
    dataset = dataset_ops.Dataset.from_tensor_slices(list(range(count))).batch(batch_size=batch_size, drop_remainder=drop_remainder)
    num_full_batches = count
    for i in range(num_full_batches):
        expected_batch = np.arange(i * batch_size, i * batch_size + batch_size, 1, dtype=np.int32)
        self.assertAllEqual(expected_batch, self.evaluate(random_access.at(dataset, i)))
    has_remainder = not drop_remainder and count % batch_size != 0
    if has_remainder:
        expected_batch = np.arange(batch_size * num_full_batches, count, 1)
        self.assertAllEqual(expected_batch, self.evaluate(random_access.at(dataset, num_full_batches)))
    with self.assertRaises(errors.OutOfRangeError):
        self.evaluate(random_access.at(dataset, index=num_full_batches + (1 if has_remainder else 0)))

Tests the batch dataset logic for various input configurations.

Args:
count: the number of input elements
batch_size: the batch size
drop_remainder: whether a smaller batch size should be produced if batch
size does not divide number of inputs evenly


def expand_defaults(schema, features):
    schema_names = [x['name'] for x in schema]
    for (name, transform) in six.iteritems(features):
        if ('source_column' not in transform):
            transform['source_column'] = name
    used_schema_columns = []
    for (name, transform) in six.iteritems(features):
        if (transform['source_column'] not in schema_names):
            raise ValueError(('source column %s is not in the schema for transform %s' % (transform['source_column'], name)))
        used_schema_columns.append(transform['source_column'])
    for col_schema in schema:
        schema_name = col_schema['name']
        schema_type = col_schema['type'].lower()
        if (schema_type not in (constant.NUMERIC_SCHEMA + [constant.STRING_SCHEMA])):
            raise ValueError(('Only the following schema types are supported: %s' % ' '.join((constant.NUMERIC_SCHEMA + [constant.STRING_SCHEMA]))))
        if (schema_name not in used_schema_columns):
            if (schema_type in constant.NUMERIC_SCHEMA):
                features[schema_name] = {'transform': constant.DEFAULT_NUMERIC_TRANSFORM, 'source_column': schema_name}
            elif (schema_type == constant.STRING_SCHEMA):
                features[schema_name] = {'transform': constant.DEFAULT_CATEGORICAL_TRANSFORM, 'source_column': schema_name}
            else:
                raise NotImplementedError(('Unknown type %s' % schema_type))

Add to features any default transformations.

Not every column in the schema has an explicit feature transformation listed
in the featurs file. For these columns, add a default transformation based on
the schema's type. The features dict is modified by this function call.

After this function call, every column in schema is used in a feature, and
every feature uses a column in the schema.

Args:
schema: schema list
features: features dict

Raises:
ValueError: if transform cannot be applied given schema type.


def saturate_kwargs(keys, **kwargs):

    if isinstance(keys, str): keys = [keys]
    keys = [k for k in keys if k in kwargs and hasattr(kwargs.get(k, None), '__iter__')]
    if len(keys) == 0: return []

    kw_corr = list(product(*(range(len(kwargs[k])) for k in keys)))

    kw_arr = []
    for corr in kw_corr: kw_arr.append(
        dict(zip(keys, [kwargs[keys[i]][corr[i]] for i in range(len(keys))]))
    )

    for k in keys: kwargs.pop(k, None)
    kw_arr = [{**k, **kwargs} for k in kw_arr]

    return kw_arr

Saturate all combinations of kwargs

Args:
keys: keys in kwargs that want to use process
**kwargs: kwargs for func


def _http_request(self, method, uri, headers=None, body_parts=None):

    if isinstance(uri, (str, unicode)):
      uri = Uri.parse_uri(uri)
    connection = self._get_connection(uri, headers=headers)
    if self.debug:
      connection.debuglevel = 1

    if connection.host != uri.host:
      connection.putrequest(method, str(uri))
    else:
      connection.putrequest(method, uri._get_relative_path())

    if (uri.scheme == 'https' and int(uri.port or 443) == 443 and
        hasattr(connection, '_buffer') and
        isinstance(connection._buffer, list)):
      header_line = 'Host: %s:443' % uri.host
      replacement_header_line = 'Host: %s' % uri.host
      try:
        connection._buffer[connection._buffer.index(header_line)] = (
            replacement_header_line)
      except ValueError:
        pass

    for header_name, value in headers.iteritems():
      connection.putheader(header_name, value)
    connection.endheaders()

    if body_parts:
      for part in body_parts:
        _send_data_part(part, connection)

    return connection.getresponse()

Makes an HTTP request using httplib.

Args:
method: str example: 'GET', 'POST', 'PUT', 'DELETE', etc.
uri: str or atom.http_core.Uri
headers: dict of strings mapping to strings which will be sent as HTTP
headers in the request.
body_parts: list of strings, objects with a read method, or objects
which can be converted to strings using str. Each of these
will be sent in order as the body of the HTTP request.


def file_exists(file_path, credentials=None):
    if file_path.startswith('gs:
        return _file_exists_in_gcs(file_path, credentials)
    else:
        return os.path.isfile(file_path)

Check whether the file exists, on local disk or GCS.

Args:
file_path: The target file path; should have the 'gs://' prefix if in gcs.
credentials: Optional credential to be used to load the file from gcs.

Returns:
True if the file's there.


def erase(self, keys, name=None):
    if keys.dtype != self._key_dtype:
        raise TypeError('Signature mismatch. Keys must be dtype %s, got %s.' % (self._key_dtype, keys.dtype))
    with ops.name_scope(name, '%s_lookup_table_remove' % self.name, (self.resource_handle, keys, self._default_value)):
        op = gen_lookup_ops.lookup_table_remove_v2(self.resource_handle, keys)
    return op

Removes `keys` and its associated values from the table.

If a key is not present in the table, it is silently ignored.

Args:
keys: Keys to remove. Can be a tensor of any shape. Must match the table's
key type.
name: A name for the operation (optional).

Returns:
The created Operation.

Raises:
TypeError: when `keys` do not match the table data types.


def get_curve(self, mnemonic, alias=None):
    return self.data.get(self.get_mnemonic(mnemonic, alias=alias), None)

Wraps get_mnemonic.

Instead of picking curves by name directly from the data dict, you
can pick them up with this method, which takes account of the alias
dict you pass it. If you do not pass an alias dict, then you get the
curve you asked for, if it exists, or None. NB Wells do not have alias
dicts, but Projects do.

Args:
mnemonic (str): the name of the curve you want.
alias (dict): an alias dictionary, mapping mnemonics to lists of
mnemonics.

Returns:
Curve.


def save(self, *, auto_commit=False):
    try:
        db.session.add(self.resource)
        if auto_commit:
            db.session.commit()
    except SQLAlchemyError as ex:
        self.log.exception('Failed updating resource: {}'.format(ex))
        db.session.rollback()

Save the resource to the database

Args:
auto_commit (bool): Automatically commit the transaction. Default: `False`

Returns:
`None`


def _callEventGetAll(self, callback_id, event_name):
    return self._event_client.eventGetAll(callback_id, event_name)

Calls snippet lib's eventGetAll.

Override this method to use this class with various snippet lib
implementations.

Args:
callback_id: The callback identifier.
event_name: The callback name.

Returns:
A list of event dictionaries.


def gs50(msg):

    d = hex2bin(data(msg))

    if d[23] == '0':
        return None

    spd = bin2int(d[24:34]) * 2
    return spd

Ground speed, BDS 5,0 message

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

Returns:
int: ground speed in knots


def update(self, table_name, set_query, where=None):
    self.validate_access_permission(['w', 'a'])
    self.verify_table_existence(table_name)
    query = SqlQuery.make_update(table_name, set_query, where)
    return self.execute_query(query, logging.getLogger().findCaller())

Execute an UPDATE query.

Args:
table_name (|str|):
Table name of executing the query.
set_query (|str|):
``SET`` clause for the update query.
where (|arg_where_type| , optional):
``WHERE`` clause for the update query.
Defaults to |None|.

Raises:
IOError:
|raises_write_permission|
simplesqlite.NullDatabaseConnectionError:
|raises_check_connection|
simplesqlite.TableNotFoundError:
|raises_verify_table_existence|
simplesqlite.OperationalError:
|raises_operational_error|


def current_lr(self):
    if (self.optimizer is None):
        raise RuntimeError('lr is not applicable because optimizer does not exist.')
    return [group['lr'] for group in self.optimizer.param_groups]

Get current learning rates.

Returns:
list: Current learning rate of all param groups.


def version_diff(version1, version2):
    if ((version1 is None) or (version2 is None)):
        return 'unknown'
    if (version1 == version2):
        return 'none'
    for v in ('major', 'minor', 'patch'):
        if (getattr(version1, v) != getattr(version2, v)):
            return v
    return 'other'

Return string representing the diff between package versions.

We're interested in whether this is a major, minor, patch or 'other'
update. This method will compare the two versions and return None if
they are the same, else it will return a string value indicating the
type of diff - 'major', 'minor', 'patch', 'other'.

Args:
version1: the Version object we are interested in (e.g. current)
version2: the Version object to compare against (e.g. latest)

Returns a string - 'major', 'minor', 'patch', 'other', or None if the
two are identical.


def _get_summary_op(self):
    summary_op = None
    if self._summary_op is not None:
        summary_op = self._summary_op
    elif self._scaffold.summary_op is not None:
        summary_op = self._scaffold.summary_op
    if summary_op is None:
        return None
    if not isinstance(summary_op, list):
        return [summary_op]
    return summary_op

Fetches the summary op either from self._summary_op or self._scaffold.

Returns:
Returns a list of summary `Tensor`.


def _pypi_push(dist):
    for filename in os.listdir(dist):
        full_path = os.path.join(dist, filename)
        if os.path.isfile(full_path):
            _shell(('twine register ' + shlex.quote(full_path)), check=False)
    _shell(('twine upload ' + shlex.quote((dist + '/*'))))

Push created package to PyPI.

Requires the following defined environment variables:
- TWINE_USERNAME: The PyPI username to upload this package under
- TWINE_PASSWORD: The password to the user's account

Args:
dist (str):
The distribution to push. Must be a valid directory; shell globs are
NOT allowed.


def execute_ssh_command(client, cmd):
    try:
        (stdin, stdout, stderr) = client.exec_command(cmd)
        err = stderr.read()
        out = stdout.read()
        if err:
            raise IpaSSHException((out.decode() + err.decode()))
    except:
        raise
    return out.decode()

Execute given command using paramiko.

Returns:
String output of cmd execution.
Raises:
IpaSSHException: If stderr returns a non-empty string.


def _MakeCacheInvariant(self, urn, age):
    precondition.AssertType(urn, Text)
    return ('%s:%s' % (urn, self.ParseAgeSpecification(age)))

Returns an invariant key for an AFF4 object.

The object will be cached based on this key. This function is specifically
extracted to ensure that we encapsulate all security critical aspects of the
AFF4 object so that objects do not leak across security boundaries.

Args:
urn: The urn of the object.
age: The age policy used to build this object. Should be one of
ALL_TIMES, NEWEST_TIME or a range.

Returns:
A key into the cache.


def _sym_rebind(self, path_value_pairs: Dict[utils.KeyPath, Any]) -> List[FieldUpdate]:

Subclass specific rebind implementation.

Args:
path_value_pairs: A dictionary of key path to new field value.

Returns:
A list of FieldUpdate from this rebind.

Raises:
WritePermissionError: If object is sealed.
KeyError: If update location specified by key or key path is not aligned
with the schema of the object tree.
TypeError: If updated field value type does not conform to field spec.
ValueError: If updated field value is not acceptable according to field
spec.


def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, layer_head_mask: torch.Tensor, output_attentions: bool=False) -> torch.Tensor:
    residual = hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    hidden_states, attn_weights, _ = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, layer_head_mask=layer_head_mask, output_attentions=output_attentions)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    residual = hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = nn.functional.dropout(hidden_states, p=self.activation_dropout, training=self.training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    if hidden_states.dtype == torch.float16:
        clamp_value = torch.finfo(hidden_states.dtype).max - 1000
        hidden_states = torch.clamp(hidden_states, min=-clamp_value, max=clamp_value)
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (attn_weights,)
    return outputs

Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
`(encoder_attention_heads,)`.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.


def reducing(reducer, init=UNSET):
    reducer2 = reducer

    def reducing_transducer(reducer):
        return Reducing(reducer, reducer2, init)
    return reducing_transducer

Create a reducing transducer with the given reducer.

Args:
reducer: A two-argument function which will be used to combine the
partial cumulative result in the first argument with the next
item from the input stream in the second argument.

Returns: A reducing transducer: A single argument function which,
when passed a reducing function, returns a new reducing function
which entirely reduces the input stream using 'reducer' before
passing the result to the reducing function passed to the
transducer.


def delete_qubits(self, indices):
    if (not isinstance(indices, list)):
        indices = [indices]
    self._z = np.delete(self._z, indices)
    self._x = np.delete(self._x, indices)
    return self

Delete pauli at the indices.

Args:
indices(list[int]): the indices of to-be-deleted paulis

Returns:
Pauli: self


def set_speed(self, speed=None, auto=False, adaptive=False):
    if (speed is None):
        speed = 0
    elif (not util.is_natural(speed)):
        raise TypeError(('Expected positive number for speed, given %s.' % speed))
    elif (speed > self.MAX_JTAG_SPEED):
        raise ValueError(('Given speed exceeds max speed of %d.' % self.MAX_JTAG_SPEED))
    elif (speed < self.MIN_JTAG_SPEED):
        raise ValueError(('Given speed is too slow.  Minimum is %d.' % self.MIN_JTAG_SPEED))
    if auto:
        speed = (speed | self.AUTO_JTAG_SPEED)
    if adaptive:
        speed = (speed | self.ADAPTIVE_JTAG_SPEED)
    self._dll.JLINKARM_SetSpeed(speed)
    return None

Sets the speed of the JTAG communication with the ARM core.

If no arguments are present, automatically detects speed.

If a ``speed`` is provided, the speed must be no larger than
``JLink.MAX_JTAG_SPEED`` and no smaller than ``JLink.MIN_JTAG_SPEED``.
The given ``speed`` can also not be ``JLink.INVALID_JTAG_SPEED``.

Args:
self (JLink): the ``JLink`` instance
speed (int): the speed in kHz to set the communication at
auto (bool): automatically detect correct speed
adaptive (bool): select adaptive clocking as JTAG speed

Returns:
``None``

Raises:
TypeError: if given speed is not a natural number.
ValueError: if given speed is too high, too low, or invalid.


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

Updates information in an existing dataset. The update method replaces the entire dataset resource, whereas the patch method only replaces fields that are provided in the submitted dataset resource. This method supports patch semantics.

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


def sort_topologically(dag):
    dag = copy.deepcopy(dag)
    sorted_nodes = []
    independent_nodes = deque(get_independent_nodes(dag))
    while independent_nodes:
        node = independent_nodes.popleft()
        sorted_nodes.append(node)
        downstream_nodes = dag[node]
        while downstream_nodes:
            downstream_node = downstream_nodes.pop(0)
            if (downstream_node not in dag):
                continue
            if (not has_dependencies(downstream_node, dag)):
                independent_nodes.append(downstream_node)
    if (len(sorted_nodes) != len(dag.keys())):
        raise ValueError('graph is not acyclic')
    return sorted_nodes

Sort the dag breath first topologically.

Only the nodes inside the dag are returned, i.e. the nodes that are also keys.

Returns:
a topological ordering of the DAG.
Raises:
an error if this is not possible (graph is not valid).


def triangular_coord(coord):

    unitvec = np.array([[1, 0], [0.5, math.sqrt(3) / 2]])
    result = np.dot(np.array(coord), unitvec)
    return result.transpose()

Convert a 2D coordinate into a triangle-based coordinate system for a
prettier phase diagram.

Args:
coordinate: coordinate used in the convex hull computation.

Returns:
coordinates in a triangular-based coordinate system.


def cancel_base_units(units, to_remove):

    to_remove = to_remove.copy()
    remaining_units = []
    total_factor = Fraction(1)

    for unit in units:
        factor, base_unit = get_conversion_factor(unit)
        if not to_remove.get(base_unit, 0):
            remaining_units.append(unit)
            continue

        total_factor *= factor
        to_remove[base_unit] -= 1

    return total_factor, remaining_units

Given a list of units, remove a specified number of each base unit.

Arguments:
units: an iterable of units
to_remove: a mapping of base_unit => count, such as that returned from
count_base_units

Returns a 2-tuple of (factor, remaining_units).


def _expression_to_sql(expression, node, context):
    _expression_transformers = {expressions.LocalField: _transform_local_field_to_expression, expressions.Variable: _transform_variable_to_expression, expressions.Literal: _transform_literal_to_expression, expressions.BinaryComposition: _transform_binary_composition_to_expression}
    expression_type = type(expression)
    if (expression_type not in _expression_transformers):
        raise NotImplementedError(u'Unsupported compiler expression "{}" of type "{}" cannot be converted to SQL expression.'.format(expression, type(expression)))
    return _expression_transformers[expression_type](expression, node, context)

Recursively transform a Filter block predicate to its SQLAlchemy expression representation.

Args:
expression: expression, the compiler expression to transform.
node: SqlNode, the SqlNode the expression applies to.
context: CompilationContext, global compilation state and metadata.

Returns:
Expression, SQLAlchemy Expression equivalent to the passed compiler expression.


def _sparse_block_diag(sp_a):
    sp_a_shape = tf.convert_to_tensor(value=_get_shape(sp_a, tf.int64))
    ind_mat = tf.concat([[sp_a_shape[(- 2):]], tf.eye(2, dtype=tf.int64)], axis=0)
    indices = tf.matmul(sp_a.indices, ind_mat)
    dense_shape = (sp_a_shape[0] * sp_a_shape[1:])
    return tf.SparseTensor(indices=indices, values=sp_a.values, dense_shape=dense_shape)

Returns a block diagonal rank 2 SparseTensor from a batch of SparseTensors.

Args:
sp_a: A rank 3 `SparseTensor` representing a batch of matrices.

Returns:
sp_block_diag_a: matrix-shaped, `float` `SparseTensor` with the same dtype
as `sparse_or_matrix`, of shape [B * M, B * N] where `sp_a` has shape
[B, M, N]. Each [M, N] batch of `sp_a` is lined up along the diagonal.


def _get_parsed_args(command_name, doc, argv):
    _LOGGER.debug('Parsing docstring:  with arguments %s.', doc, argv)
    args = docopt(doc, argv=argv)
    if (command_name == settings.command):
        args[command_name] = True
    return args

Parse the docstring with docopt.

Args:
command_name: The name of the subcommand to parse.
doc: A docopt-parseable string.
argv: The list of arguments to pass to docopt during parsing.

Returns:
The docopt results dictionary. If the subcommand has the same name as
the primary command, the subcommand value will be added to the
dictionary.


def print_gate(gate: Gate, ndigits: int=2, file: TextIO=None) -> None:
    N = gate.qubit_nb
    gate_tensor = gate.vec.asarray()
    lines = []
    for (index, amplitude) in np.ndenumerate(gate_tensor):
        ket = ''.join([str(n) for n in index[0:N]])
        bra = ''.join([str(index[n]) for n in range(N, (2 * N))])
        if (round((abs(amplitude) ** 2), ndigits) > 0.0):
            lines.append('{} -> {} : {}'.format(bra, ket, amplitude))
    lines.sort(key=(lambda x: int(x[0:N])))
    print('\n'.join(lines), file=file)

Pretty print a gate tensor

Args:
gate:
ndigits:
file: Stream to which to write. Defaults to stdout


def depth_july_average_ground_temperature(self, value=None):
    if (value is not None):
        try:
            value = float(value)
        except ValueError:
            raise ValueError('value {} need to be of type float for field `depth_july_average_ground_temperature`'.format(value))
    self._depth_july_average_ground_temperature = value

Corresponds to IDD Field `depth_july_average_ground_temperature`

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

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


def _exec_one_test_with_repeat(self, test_name, test_method, repeat_count, max_consecutive_error):
    consecutive_error_count = 0
    if max_consecutive_error == 0:
        max_consecutive_error = repeat_count
    previous_record = None
    for i in range(repeat_count):
        new_test_name = f'{test_name}_{i}'
        new_record = records.TestResultRecord(new_test_name, self.TAG)
        if i > 0:
            new_record.parent = (previous_record, records.TestParentType.REPEAT)
        previous_record = self.exec_one_test(new_test_name, test_method, new_record)
        if previous_record.result in [records.TestResultEnums.TEST_RESULT_FAIL, records.TestResultEnums.TEST_RESULT_ERROR]:
            consecutive_error_count += 1
        else:
            consecutive_error_count = 0
        if consecutive_error_count == max_consecutive_error:
            logging.error('Repeated test case "%s" has consecutively failed %d iterations, aborting the remaining %d iterations.', test_name, consecutive_error_count, repeat_count - 1 - i)
            return

Repeatedly execute a test case.

This method performs the action defined by the `repeat` decorator.

If the number of consecutive failures reach the threshold set by
`max_consecutive_error`, the remaining iterations will be abandoned.

Args:
test_name: string, Name of the test.
test_method: function, The test method to execute.
repeat_count: int, the number of times to repeat the test case.
max_consecutive_error: int, the maximum number of consecutive iterations
allowed to fail before abandoning the remaining iterations.


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

Retrieve a GitHubEnterpriseConfig.

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


def round_accuracy(y_true, y_predicted):
    predictions = [round(x) for x in y_predicted]
    examples_len = len(y_true)
    correct = sum([(y1 == y2) for (y1, y2) in zip(y_true, predictions)])
    return ((correct / examples_len) if examples_len else 0)

Rounds predictions and calculates accuracy in terms of absolute coincidence.

Args:
y_true: list of true values
y_predicted: list of predicted values

Returns:
portion of absolutely coincidental samples


def swo_num_bytes(self):
    res = self._dll.JLINKARM_SWO_Control(enums.JLinkSWOCommands.GET_NUM_BYTES, 0)
    if (res < 0):
        raise errors.JLinkException(res)
    return res

Retrives the number of bytes in the SWO buffer.

Args:
self (JLink): the ``JLink`` instance

Returns:
Number of bytes in the SWO buffer.

Raises:
JLinkException: on error


def allow_exception(self, exc_class):
    name = exc_class.__name__
    self._allowed_exceptions[name] = exc_class

Allow raising this class of exceptions from commands.

When a command fails on the server side due to an exception, by
default it is turned into a string and raised on the client side as an
ExternalError.  The original class name is sent but ignored.  If you
would like to instead raise an instance of the same exception on the
client side, you can pass the exception class object to this method
and instances of that exception will be reraised.

The caveat is that the exception must be creatable with a single
string parameter and it should have a ``msg`` property.

Args:
exc_class (class): A class object with the exception that
we should allow to pass from server to client.


def reduce_mean(self, x):
    return self.reduce(lambda y: math_ops.reduce_mean(y, axis=0), x)

Performs a mean reduction on `x` across pfor iterations.

Note that this currently may not work inside a control flow construct.
Args:
x: an unvectorized Tensor.

Returns:
A Tensor that has same rank as `x`. The value is the mean of the values
of `x` across the pfor iterations.


def domain_tag(self, domains):

        api_name = 'opendns-domain_tag'
        fmt_url_path = u'domains/{0}/latest_tags'
        return self._multi_get(api_name, fmt_url_path, domains)

Get the data range when a domain is part of OpenDNS block list.

Args:
domains: an enumerable of strings domain names
Returns:
An enumerable of string with period, category, and url


def data_kva_compare(db_data, user_data):

        for kv_data in db_data:
            if kv_data.get('key') == user_data.get('key'):
                if kv_data.get('value') == user_data.get('value'):
                    return True
        return False

Validate key/value data in KeyValueArray.

Args:
db_data (list): The data store in Redis.
user_data (dict): The user provided data.

Returns:
bool: True if the data passed validation.


def get_special_tokens_mask(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None, already_has_special_tokens: bool=False) -> List[int]:
    if already_has_special_tokens:
        return super().get_special_tokens_mask(token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True)
    prefix_ones = [1] * len(self.prefix_tokens)
    suffix_ones = [1] * len(self.suffix_tokens)
    if token_ids_1 is None:
        return prefix_ones + [0] * len(token_ids_0) + suffix_ones
    return prefix_ones + [0] * len(token_ids_0) + [0] * len(token_ids_1) + suffix_ones

Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `prepare_for_model` method.

Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
already_has_special_tokens (`bool`, *optional*, defaults to `False`):
Whether or not the token list is already formatted with special tokens for the model.

Returns:
`List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.


def set_position_d(self, dvalue):
    dvalue_msb = (int(dvalue) >> 8)
    dvalue_lsb = (int(dvalue) & 255)
    data = []
    data.append(11)
    data.append(self.servoid)
    data.append(RAM_WRITE_REQ)
    data.append(POSITION_KD_RAM)
    data.append(BYTE2)
    data.append(dvalue_lsb)
    data.append(dvalue_msb)
    send_data(data)

Set the D gain of the PID

Args:
dvalue (int): D value


def campaign(self, name, **kwargs):

        group_obj = Campaign(name, **kwargs)
        return self._group(group_obj)

Add Campaign data to Batch object.

Args:
name (str): The name for this Group.
date_added (str, kwargs): The date timestamp the Indicator was created.
first_seen (str, kwargs): The first seen datetime expression for this Group.
xid (str, kwargs): The external id for this Group.

Returns:
obj: An instance of Campaign.


def getatime(self, path):

        try:
            file_obj = self.filesystem.resolve(path)
        except IOError:
            self.filesystem.raise_os_error(errno.ENOENT)
        return file_obj.st_atime

Returns the last access time of the fake file.

Note: Access time is not set automatically in fake filesystem
on access.

Args:
path: the path to fake file.

Returns:
(int, float) the access time of the fake file in number of seconds
since the epoch.

Raises:
OSError: if the file does not exist.


def __init__(self, pcolls, options=None, runner=None):
    assert len(pcolls) > 0, 'Need at least 1 PCollection as the target data to build a pipeline fragment that produces it.'
    for pcoll in pcolls:
        assert isinstance(pcoll, beam.pvalue.PCollection), '{} is not an apache_beam.pvalue.PCollection.'.format(pcoll)
    self._user_pipeline = pcolls[0].pipeline
    self._pcolls = set(pcolls)
    for pcoll in self._pcolls:
        assert pcoll.pipeline is self._user_pipeline, '{} belongs to a different user pipeline than other PCollections given and cannot be used to build a pipeline fragment that produces the given PCollections.'.format(pcoll)
    self._options = options
    self._runner = runner
    self._runner_pipeline = self._build_runner_pipeline()
    _, self._context = self._runner_pipeline.to_runner_api(return_context=True)
    self._runner_pcoll_to_id = instr.pcoll_to_pcoll_id(self._runner_pipeline, self._context)
    self._id_to_target_pcoll = self._calculate_target_pcoll_ids()
    self._label_to_user_transform = self._calculate_user_transform_labels()
    self._runner_pcolls_to_user_pcolls, self._runner_transforms_to_user_transforms = self._build_correlation_between_pipelines(self._runner_pcoll_to_id, self._id_to_target_pcoll, self._label_to_user_transform)
    self._necessary_transforms, self._necessary_pcollections = self._mark_necessary_transforms_and_pcolls(self._runner_pcolls_to_user_pcolls)
    self._runner_pipeline = self._prune_runner_pipeline_to_fragment(self._runner_pipeline, self._necessary_transforms)

Constructor of PipelineFragment.

Args:
pcolls: (List[PCollection]) a list of PCollections to build pipeline
fragment for.
options: (PipelineOptions) the pipeline options for the implicit
pipeline run.
runner: (Runner) the pipeline runner for the implicit
pipeline run.


def raw_sql(cls, cur, query: str, values: tuple):

        yield from cur.execute(query, values)
        return (yield from cur.fetchall())

Run a raw sql query

Args:
query : query string to execute
values : tuple of values to be used with the query

Returns:
result of query as list of named tuple


def get_setting_list(self, key, default_value=None, delimiter=',', value_type=str):
    value = self.get_setting(key)
    if (value is not None):
        setting_list = [value_type(v) for v in value.split(delimiter)]
    else:
        setting_list = default_value
    return setting_list

Get the setting stored at the given key and split it to a list.

Args:
key (str): the setting key
default_value (list, optional): The default value, if none is
found. Defaults to None.
delimiter (list of str, optional): The delimiter to break on.
Defaults to ','.
value_type (function, optional): The type of a setting value in the
list. Defaults to `str`.

Returns:
list of str: The values of the setting if found, default_value
otherwise.

If a value is found, it is split using the given delimiter.


def to_representation(self, instance):
    updated_course_run = copy.deepcopy(instance)
    enterprise_customer_catalog = self.context['enterprise_customer_catalog']
    updated_course_run['enrollment_url'] = enterprise_customer_catalog.get_course_run_enrollment_url(updated_course_run['key'])
    return updated_course_run

Return the updated course run data dictionary.

Arguments:
instance (dict): The course run data.

Returns:
dict: The updated course run data.


def recipe_bigquery_census_normalize(config, auth, census_geography, census_year, census_span, dataset, type):
    census(config, {'auth': auth, 'normalize': {'census_geography': census_geography, 'census_year': census_year, 'census_span': census_span}, 'to': {'dataset': dataset, 'type': type}})

Convert given census table to percent of population, normalizing it.

Args:
auth (authentication) - Credentials used for writing data.
census_geography (choice) - Census table to get data from.
census_year (choice) - Census table to get data from.
census_span (choice) - Census table to get data from.
dataset (string) - Existing BigQuery dataset.
type (choice) - Write Census_Percent as table or view.


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

        intervals = list(itertools.chain(*(self._table[chan] for chan in channels
                                           if chan in self._table)))
        if intervals:
            return max((interval.end for interval in intervals))
        return 0

Return maximum time of timeslots over all channels.

Args:
*channels: Channels over which to obtain stop time.


def get(self, section, option):
    if (not self.has_section(section)):
        raise NoSectionError(section) from None
    section = self.__getitem__(section)
    option = self.optionxform(option)
    try:
        value = section[option]
    except KeyError:
        raise NoOptionError(option, section)
    return value

Gets an option value for a given section.

Args:
section (str): section name
option (str): option name

Returns:
:class:`Option`: Option object holding key/value pair


def parallel_map(self, map_fn: Callable[..., _Tout], *trees: Tree[_Tin], num_threads: Optional[int]=None, progress_bar: bool=False, is_leaf: Optional[LeafFn]=None) -> Tree[_Tout]:
    with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:
        launch_worker = functools.partial(executor.submit, map_fn)
        futures = self.backend.map(launch_worker, *trees, is_leaf=is_leaf)
        leaves, _ = self.backend.flatten(futures, is_leaf=is_leaf)
        itr = concurrent.futures.as_completed(leaves)
        if progress_bar:
            itr = etqdm.tqdm(itr, total=len(leaves))
        for f in itr:
            if f.exception():
                raise f.exception()
    return self.backend.map(lambda f: f.result(), futures)

Same as `tree.map_structure` but apply `map_fn` in parallel.

Args:
map_fn: Worker function
*trees: Nested input to pass to the `map_fn`
num_threads: Number of workers (default to CPU count * 5)
progress_bar: If True, display a progression bar.
is_leaf: Don't recurse into leaf if `is_leaf(node)` is `True`

Returns:
The nested structure after `map_fn` has been applied.


def match(self, f, *args):
    try:
        match = f(self.tokenizer, *args)
    except StopIteration:
        return
    if (match is None):
        return
    if (not isinstance(match, grammar.TokenMatch)):
        raise TypeError(('Invalid grammar function %r returned %r.' % (f, match)))
    self.matched = match
    return match

Match grammar function 'f' against next token and set 'self.matched'.

Arguments:
f: A grammar function - see efilter.parsers.common.grammar. Must
return TokenMatch or None.
args: Passed to 'f', if any.

Returns:
Instance of efilter.parsers.common.grammar.TokenMatch or None.

Comment:
If a match is returned, it will also be stored in self.matched.


def isset(name):

    def wrapped(func):

        @functools.wraps(func)
        def _decorator(*args, **kwargs):
            if core.isset(name):
                return func(*args, **kwargs)
        return _decorator
    return wrapped

Only execute the function if the variable is set.

Args:
name: The name of the environment variable

Returns:
The function return value or `None` if the function was skipped.


async def remember(request, user_id):
    auth_policy = request.get(POLICY_KEY)
    if (auth_policy is None):
        raise RuntimeError('auth_middleware not installed')
    return (await auth_policy.remember(request, user_id))

Called to store and remember the userid for a request

Args:
request: aiohttp Request object.
user_id: String representing the user_id to remember

Raises:
RuntimeError: Middleware is not installed


def isbase(path1, path2):

    _path1 = forcedir(abspath(path1))
    _path2 = forcedir(abspath(path2))
    return _path2.startswith(_path1)

Check if ``path1`` is a base of ``path2``.

Arguments:
path1 (str): A PyFilesytem path.
path2 (str): A PyFilesytem path.

Returns:
bool: `True` if ``path2`` starts with ``path1``

Example:
>>> isbase('foo/bar', 'foo/bar/baz/egg.txt')
True


def find_xml_generator(name="castxml"):

    if sys.version_info[:2] >= (3, 3):
        path = _find_xml_generator_for_python_greater_equals_33(name)
    else:
        path = _find_xml_generator_for_legacy_python(name)

    if path == "" or path is None:
        raise Exception("No c++ parser found. Please install castxml.")
    return path.rstrip(), name

Try to find a c++ parser (xml generator)

Args:
name (str): name of the c++ parser (e.g. castxml)

Returns:
path (str), name (str): path to the xml generator and it's name

If no c++ parser is found the function raises an exception.
pygccxml does currently only support castxml as c++ parser.


def __init__(self, extension_name=None, extension_tag=None,
                 extension_type=None):

        super(ExtensionInformation, self).__init__(Tags.EXTENSION_INFORMATION)

        if extension_name is None:
            self.extension_name = ExtensionName()
        else:
            self.extension_name = extension_name

        self.extension_tag = extension_tag
        self.extension_type = extension_type

        self.validate()

Construct an ExtensionInformation object.

Args:
extension_name (ExtensionName): The name of the extended Object.
extension_tag (ExtensionTag): The tag of the extended Object.
extension_type (ExtensionType): The type of the extended Object.


def __fetch_route53_zone_tags(self, zone_id):
    route53 = self.session.client('route53')
    try:
        return {tag['Key']: tag['Value'] for tag in route53.list_tags_for_resource(ResourceType='hostedzone', ResourceId=zone_id.split('/')[(- 1)])['ResourceTagSet']['Tags']}
    finally:
        del route53

Return a dict with the tags for the zone

Args:
zone_id (`str`): ID of the hosted zone

Returns:
:obj:`dict` of `str`: `str`


def noise_op(latents, hparams):

  if hparams.latent_noise == 0 or hparams.mode != tf.estimator.ModeKeys.TRAIN:
    return latents
  latent_shape = common_layers.shape_list(latents)
  return latents + tf.random_normal(latent_shape, stddev=hparams.latent_noise)

Adds isotropic gaussian-noise to each latent.

Args:
latents: 4-D or 5-D tensor, shape=(NTHWC) or (NHWC).
hparams: HParams.
Returns:
latents: latents with isotropic gaussian noise appended.


def _CalculateYLines(self, dists):
    tot_dist = sum(dists)
    if (tot_dist > 0):
        pixel_dist = [(float((d * (self._gheight - 20))) / tot_dist) for d in dists]
        pixel_grid = ([0] + [int((pd + sum(pixel_dist[0:i]))) for (i, pd) in enumerate(pixel_dist)])
    else:
        pixel_grid = []
    return pixel_grid

Builds a list with y-coordinates for the horizontal lines in the graph.

Args:
# One integer for each pair of stations
# indicating the approximate distance
dists: [0,33,140, ... ,X]

Returns:
# One integer y-coordinate for each station normalized between
# 0 and X, where X is the height of the graph in pixels
[0, 33, 140, ... , X]


def download(url, fname=None):
    if (fname is None):
        fname = url.split('/')[(- 1)]
    with contextlib.closing(requests.get(url, stream=True)) as r:
        try:
            r.raise_for_status()
        except requests.exceptions.HTTPError as error:
            print('Error connecting to URL: "{}"'.format(url))
            print(r.text)
            raise error
        with open(fname, 'wb') as f:
            shutil.copyfileobj(r.raw, f)
    return fname

Downloads a file.

Args:
url (str): The URL to download.
fname (Optional[str]): The filename to store the downloaded file in. If
`None`, take the filename from the URL. Defaults to `None`.

Returns:
The filename the URL was downloaded to.

Raises:
requests.exceptions.HTTPError: There was a problem connecting to the
URL.


def console_get_background_flag(con: tcod.console.Console) -> int:
    return int(lib.TCOD_console_get_background_flag(_console(con)))

Return this consoles current blend mode.

Args:
con (Console): Any Console instance.

.. deprecated:: 8.5
Check :any:`Console.default_bg_blend` instead.


def top_stories(self, raw=False, limit=None):

        top_stories = self._get_stories('topstories', limit)
        if raw:
            top_stories = [story.raw for story in top_stories]
        return top_stories

Returns list of item ids of current top stories

Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to represent all
objects in raw json.

Returns:
`list` object containing ids of top stories.


def _postprocess_non_flat_outputs(outputs):
    new_output_tensors = []
    for o in nest.flatten(outputs):
        if isinstance(o, ops.Operation):
            raise ValueError('xla.compile does not support Operation as return value in non-flat output structure. You can set returned Operations as control dependencies of returned Tensors so Operations are triggered when Tensors are evaluated. Operation found: "%s"' % o.name)
        try:
            o = ops.convert_to_tensor(o)
        except Exception as e:
            raise ValueError('XLA computation function return values must all either be Operations or convertible to Tensors. Got error: "%s"' % str(e))
        with ops.device(o.device if o.device else ''):
            new_output_tensors.append(array_ops.identity(o))
    return (new_output_tensors, [])

Validates non-flat outputs and adds back device assignments.

Args:
outputs: Output from `computation` inside `xla.compile`.

Returns:
Tensors extracted from outputs and an empty list because Operations are not
allowed in non-flat outputs..


def __init__(self, callback):

        super(LLDP, self).__init__(callback)
        self._lldp = brcd_lldp(callback=pynos.utilities.return_xml)

LLDP init method.

Args:
callback (function): Callback function that will be called for each
action.

Returns:
LLDP Object

Raises:
None


def gs50(msg):
    d = hex2bin(data(msg))
    if (d[23] == '0'):
        return None
    spd = (bin2int(d[24:34]) * 2)
    return spd

Ground speed, BDS 5,0 message

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

Returns:
int: ground speed in knots


def add_to_optionally_restored(self, var):
    self._optionally_restored.append(var)

Add a variable to the list of optionally restored variables.

There are situations where certain variables should be ignored in assertions
such as assert_existing_objects_matched(). One example is that of a
checkpoint saved with train.Saver(), and restored with train.Checkpoint():
it is possible for the train.Saver() checkpoint to be missing the internal
`save_counter` variable, which we want to ignore on restore.

Args:
var: The variable to treat as optionally restored.


def force_list(data):
    if (data is None):
        return []
    elif (not isinstance(data, (list, tuple, set))):
        return [data]
    elif isinstance(data, (tuple, set)):
        return list(data)
    return data

Force ``data`` to become a list.

You should use this method whenever you don't want to deal with the
fact that ``NoneType`` can't be iterated over. For example, instead
of writing::

bar = foo.get('bar')
if bar is not None:
for el in bar:
...

you can write::

for el in force_list(foo.get('bar')):
...

Args:
data: any Python object.

Returns:
list: a list representation of ``data``.

Examples:
>>> force_list(None)
[]
>>> force_list('foo')
['foo']
>>> force_list(('foo', 'bar'))
['foo', 'bar']
>>> force_list(['foo', 'bar', 'baz'])
['foo', 'bar', 'baz']


def __init__(self, file_entry):

    super(APFSVolume, self).__init__(file_entry.name)
    self._file_entry = file_entry

Initializes an APFS volume.

Args:
file_entry (APFSContainerFileEntry): an APFS container file entry.


def run_inference_on_image(image):
    if (not tf.gfile.Exists(image)):
        tf.logging.fatal('File does not exist %s', image)
    image_data = tf.gfile.FastGFile(image, 'rb').read()
    create_graph()
    with tf.Session() as sess:
        softmax_tensor = sess.graph.get_tensor_by_name('softmax:0')
        predictions = sess.run(softmax_tensor, {'DecodeJpeg/contents:0': image_data})
        predictions = np.squeeze(predictions)
        node_lookup = NodeLookup()
        top_k = predictions.argsort()[(- FLAGS.num_top_predictions):][::(- 1)]
        for node_id in top_k:
            human_string = node_lookup.id_to_string(node_id)
            score = predictions[node_id]
            print(('%s (score = %.5f)' % (human_string, score)))

Runs inference on an image.

Args:
image: Image file name.

Returns:
Nothing


def get_font(self, weight='medium', slant='upright', width='normal'):

    def find_closest_style(style, styles, alternatives):
        try:
            return (style, styles[style])
        except KeyError:
            for option in alternatives[style]:
                try:
                    return (option, styles[option])
                except KeyError:
                    continue

    def find_closest_weight(weight, weights):
        index = FontWeight.values.index(weight)
        min_distance = len(FontWeight.values)
        closest = None
        for (i, option) in enumerate(FontWeight.values):
            if ((option in weights) and (abs((index - i)) < min_distance)):
                min_distance = abs((index - i))
                closest = option
        return (closest, weights[closest])
    (available_width, slants) = find_closest_style(width, self, FontWidth.alternatives)
    (available_slant, weights) = find_closest_style(slant, slants, FontSlant.alternatives)
    (available_weight, font) = find_closest_weight(weight, weights)
    if ((available_width != width) or (available_slant != slant) or (available_weight != weight)):
        warn('{} does not include a {} {} {} font. Falling back to {} {} {}'.format(self.name, width, weight, slant, available_width, available_weight, available_slant))
    return font

Return the font matching or closest to the given style

If a font with the given weight, slant and width is available, return
it. Otherwise, return the font that is closest in style.

Args:
weight (FontWeight): weight of the font
slant (FontSlant): slant of the font
width (FontWidth): width of the font

Returns:
Font: the requested font


def set_computer_policy(name, setting, cumulative_rights_assignments=True, adml_language='en-US'):
    pol = {}
    pol[name] = setting
    ret = set_(computer_policy=pol, user_policy=None, cumulative_rights_assignments=cumulative_rights_assignments, adml_language=adml_language)
    return ret

Set a single computer policy

Args:
name (str):
The name of the policy to configure

setting (str):
The setting to configure the named policy with

cumulative_rights_assignments (bool): Determine how user rights
assignment policies are configured. If True, user right assignment
specifications are simply added to the existing policy. If False,
only the users specified will get the right (any existing will have
the right revoked)

adml_language (str): The language files to use for looking up
Administrative Template policy data (i.e. how the policy is
displayed in the GUI).  Defaults to 'en-US' (U.S. English).

Returns:
bool: True if successful, otherwise False

CLI Example:

.. code-block:: bash

salt '*' lgpo.set_computer_policy LockoutDuration 1440


def lines_from_string(string, as_interned=False):

    if as_interned:
        return [sys.intern(line) for line in string.splitlines()]
    return string.splitlines()

Create a list of file lines from a given string.

Args:
string (str): File string
as_interned (bool): List of "interned" strings (default False)

Returns:
strings (list): File line list


def create_pane(widgets, horizontal, parent_widget=None, compact=False,
                compact_spacing=2):

    pane = parent_widget or QtGui.QWidget()
    type_ = QtGui.QHBoxLayout if horizontal else QtGui.QVBoxLayout
    layout = type_()
    if compact:
        layout.setSpacing(compact_spacing)
        layout.setContentsMargins(compact_spacing, compact_spacing,
                                  compact_spacing, compact_spacing)

    for widget in widgets:
        stretch = 0
        if isinstance(widget, tuple):
            widget, stretch = widget

        if isinstance(widget, int):
            layout.addSpacing(widget)
        elif widget:
            layout.addWidget(widget, stretch)
        else:
            layout.addStretch()

    pane.setLayout(layout)
    return pane

Create a widget containing an aligned set of widgets.

Args:
widgets (list of `QWidget`).
horizontal (bool).
align (str): One of:
- 'left', 'right' (horizontal);
- 'top', 'bottom' (vertical)
parent_widget (`QWidget`): Owner widget, QWidget is created if this
is not provided.

Returns:
`QWidget`


def __non_body_parameter_descriptor(self, param):

    descriptor = {}

    descriptor['name'] = param.name

    param_type, param_format = self.__field_to_parameter_type_and_format(param)

    if param.required:
      descriptor['required'] = True

    descriptor['type'] = param_type

    if param_format:
      descriptor['format'] = param_format

    default = self.__parameter_default(param)
    if default is not None:
      descriptor['default'] = default

    if param.repeated:
      descriptor['repeated'] = True

    enum_descriptor = self.__parameter_enum(param)
    if enum_descriptor is not None:
      descriptor['enum'] = enum_descriptor

    return descriptor

Creates descriptor for a parameter.

Args:
param: The parameter to be described.

Returns:
Dictionary containing a descriptor for the parameter.


def feature_info(self):
    feature_list = self.prop('available-features-list', None)
    if (feature_list is None):
        raise ValueError(('Firmware features are not supported on CPC %s' % self.manager.cpc.name))
    return feature_list

Returns information about the features available for the CPC of this
partition.

Authorization requirements:

* Object-access permission to this partition.

Returns:

:term:`iterable`:
An iterable where each item represents one feature that is
available for the CPC of this partition.

Each item is a dictionary with the following items:

* `name` (:term:`unicode string`): Name of the feature.
* `description` (:term:`unicode string`): Short description of
the feature.
* `state` (bool): Enablement state of the feature (`True` if the
enabled, `False` if disabled).

Raises:

:exc:`ValueError`: Features are not supported on the HMC.
:exc:`~zhmcclient.HTTPError`
:exc:`~zhmcclient.ParseError`
:exc:`~zhmcclient.AuthError`
:exc:`~zhmcclient.ConnectionError`


def set_document_type(loader_cls: Type, type_: Type) -> None:

    loader_cls.document_type = type_

    if not hasattr(loader_cls, '_registered_classes'):
        loader_cls._registered_classes = dict()

Set the type corresponding to the whole document.

Args:
loader_cls: The loader class to set the document type for.
type_: The type to loader should process the document into.


def format_speech_generation_kwargs(kwargs):
    kwargs_text = {}
    kwargs_speech = {}
    for key, value in kwargs.items():
        if key.startswith('text_'):
            key = key[len('text_'):]
            kwargs_text[key] = value
        elif key.startswith('speech_'):
            key = key[len('speech_'):]
            kwargs_speech[key] = value
        elif key == 'generation_config':
            kwargs_text[key] = value
        else:
            if key not in kwargs_text:
                kwargs_text[key] = value
            if key not in kwargs_speech:
                kwargs_speech[key] = value
    return (kwargs_text, kwargs_speech)

Format kwargs for SeamlessM4T models that generate speech, attribute kwargs to either the text generation or the
speech generation models.

Args:
kwargs (`dict`)`:
Keyword arguments are of two types:

- Without a prefix, they will be entered as `**kwargs` for the `generate` method of each sub-model,
except for `decoder_input_ids` which will only be passed through the text components.
- With a *text_* or *speech_* prefix, they will be input for the `generate` method of the
text model and speech model respectively. It has the priority over the keywords without a prefix.

This means you can, for example, specify a generation strategy for one generation but not for the
other.


def refer(self, text):
    data = self.reply(text)
    data['refer_key'] = self['key']
    return data

Refers current message and replys a new message

Args:
text(str): message content

Returns:
RTMMessage


def __init__(self, outputdir, os_name, os_bits):

        if type(self) == Basedriver:
            raise Exception('Basedriver cannot be instantiated')
        self.outputdir = outputdir
        self.os_name = os_name
        self.os_bits = os_bits

Instantiate a new webdriver class
Args:
outputdir:    The path to the directory to use.
os_name:      Valid options: ['windows', 'linux', 'mac']
os_bits:      Valid options: ['32', '64']


def start(self, timeout=None, root_object=None):

        if self._is_running:
            return

        if timeout:
            self._timeout = timeout
            self._start_time = int(time())

        pushcenter_logger.debug("[NURESTPushCenter] Starting push center on url %s ..." % self.url)
        self._is_running = True
        self.__root_object = root_object

        from .nurest_session import NURESTSession
        current_session = NURESTSession.get_current_session()
        args_session = {'session': current_session}

        self._thread = StoppableThread(target=self._listen, name='push-center', kwargs=args_session)
        self._thread.daemon = True
        self._thread.start()

Starts listening to events.

Args:
timeout (int): number of seconds before timeout. Used for testing purpose only.
root_object (bambou.NURESTRootObject): NURESTRootObject object that is listening. Used for testing purpose only.


def _convert_date(self, value):
    try:
        result = parser.parse(value)
        if not result.tzinfo:
            result = ZoneInfo(self._timezone).localize(result)
        if ':' in value:
            return result.strftime('%Y-%m-%dT%H:%M:%S.000%z')
        else:
            return result.strftime('%Y-%m-%d')
    except:
        return None

Converts dates into a Bulkdozer specific format to be written back to the Feed.

Args:
value: String representation of the date.

Returns:
Bulkdozer string representation of a date. Returns null if the value
cannot be parsed into a date.


def parse_services(config, services):

    enabled = 0
    for service in services:
        check_disabled = config.getboolean(service, 'check_disabled')
        if not check_disabled:
            enabled += 1

    return enabled

Parse configuration to return number of enabled service checks.

Arguments:
config (obj): A configparser object with the configuration of
anycast-healthchecker.
services (list): A list of section names which holds configuration
for each service check

Returns:
A number (int) of enabled service checks.


def learn(self, grad_arr, fix_opt_flag=False):

        deconvolution_layer_list = self.__deconvolution_layer_list[::-1]
        for i in range(len(deconvolution_layer_list)):
            try:
                grad_arr = deconvolution_layer_list[i].back_propagate(grad_arr)
            except:
                self.__logger.debug("Error raised in Convolution layer " + str(i + 1))
                raise

        if fix_opt_flag is False:
            self.__optimize(self.__learning_rate, 1)

        return grad_arr

Update this Discriminator by ascending its stochastic gradient.

Args:
grad_arr:       `np.ndarray` of gradients.
fix_opt_flag:   If `False`, no optimization in this model will be done.

Returns:
`np.ndarray` of delta or gradients.


def _should_include_node(node_or_node_name, export_scope, exclude_nodes):
    if not isinstance(node_or_node_name, str):
        try:
            node_name = node_or_node_name.name
        except AttributeError:
            return True
    else:
        node_name = node_or_node_name
    if exclude_nodes and (node_or_node_name in exclude_nodes or node_name in exclude_nodes):
        return False
    return node_name.startswith(_UNBOUND_INPUT_PREFIX) or (not export_scope or node_name.startswith(export_scope))

Returns `True` if a node should be included.

Args:
node_or_node_name: A node or `string` node name.
export_scope: `string`. Name scope under which to extract the subgraph. The
scope name will be stripped from the node definitions for easy import
later into new name scopes.
exclude_nodes: An iterable of nodes or `string` node names to omit from the
export, or None.  Note no sanity-checking is done, so this list must be
carefully constructed to avoid producing an invalid graph.

Returns:
`True` if the node should be included.


def tomography_basis(basis, prep_fun=None, meas_fun=None):

    ret = TomographyBasis(basis)
    ret.prep_fun = prep_fun
    ret.meas_fun = meas_fun
    return ret

Generate a TomographyBasis object.

See TomographyBasis for further details.abs

Args:
prep_fun (callable) optional: the function which adds preparation
gates to a circuit.
meas_fun (callable) optional: the function which adds measurement
gates to a circuit.

Returns:
TomographyBasis: A tomography basis.


def get(self, type: Type[T], query: Mapping[str, Any], context: PipelineContext = None) -> T:

        pass

Gets a query from the data source.

Args:
query: The query being requested.
context: The context for the extraction (mutable).

Returns:
The requested object.


def set_desired_state(self, state):

        if state not in self._STATES:
            raise ValueError(
                'state must be one of: {0}'.format(
                    self._STATES
                ))

        self._data['desiredState'] = state

        if self._is_live():
            self._update('_data', self._client.set_unit_desired_state(self.name, self.desiredState))

        return self._data['desiredState']

Update the desired state of a unit.

Args:
state (str): The desired state for the unit, must be one of ``_STATES``

Returns:
str: The updated state

Raises:
fleet.v1.errors.APIError: Fleet returned a response code >= 400
ValueError: An invalid value for ``state`` was provided


def get_help(self, prefix='', include_special_flags=True):

    flags_by_module = self.flags_by_module_dict()
    if flags_by_module:
      modules = sorted(flags_by_module)

      main_module = sys.argv[0]
      if main_module in modules:
        modules.remove(main_module)
        modules = [main_module] + modules
      return self._get_help_for_modules(modules, prefix, include_special_flags)
    else:
      output_lines = []

      values = six.itervalues(self._flags())
      if include_special_flags:
        values = itertools.chain(
            values, six.itervalues(_helpers.SPECIAL_FLAGS._flags()))
      self._render_flag_list(values, output_lines, prefix)
      return '\n'.join(output_lines)

Returns a help string for all known flags.

Args:
prefix: str, per-line output prefix.
include_special_flags: bool, whether to include description of
SPECIAL_FLAGS, i.e. --flagfile and --undefok.

Returns:
str, formatted help message.


def __init__(self, max_shard_bytes, max_shards=None, bytes_per_string=16):
    if max_shard_bytes < 1:
        raise ValueError(f'Argument `max_shard_bytes` must be positive. Received {max_shard_bytes}')
    if max_shards and max_shards < 1:
        raise ValueError(f'Argument `max_shards` must be positive. Received {max_shards}')
    if bytes_per_string < 1:
        raise ValueError(f'Argument `bytes_per_string` must be positive. Received: {bytes_per_string}')
    self._max_shard_bytes = max_shard_bytes
    self._max_shards = max_shards
    self._bytes_per_string = bytes_per_string

Creates a new `MaxSizePartitioner`.

Args:
max_shard_bytes: The maximum size any given shard is allowed to be.
max_shards: The maximum number of shards in `int` created taking
precedence over `max_shard_bytes`.
bytes_per_string: If the partition value is of type string, this provides
an estimate of how large each string is.


def license_from_trove(trove):

    license = []
    for classifier in trove:
        if 'License' in classifier:
            stripped = classifier.strip()

            stripped = stripped[stripped.find('License'):]
            if stripped in settings.TROVE_LICENSES:
                license.append(settings.TROVE_LICENSES[stripped])
    return ' and '.join(license)

Finds out license from list of trove classifiers.
Args:
trove: list of trove classifiers
Returns:
Fedora name of the package license or empty string, if no licensing
information is found in trove classifiers.


def price(self, valuation_date, market, model=None, name=None):
    name = name or self._name + '_price'
    with tf.name_scope(name):
        discount_curve = market.discount_curve
        coupon_cf = self._cashflows.price(valuation_date, market, model)
        principal_cf = self._notional * discount_curve.get_discount_factor(self._maturity_date)
        return coupon_cf + principal_cf

Returns the price of the FRNs on the valuation date.

Args:
valuation_date: A scalar `DateTensor` specifying the date on which
valuation is being desired.
market: A namedtuple of type `InterestRateMarket` which contains the
necessary information for pricing the FRNs.
model: Reserved for future use.
name: Python str. The name to give to the ops created by this function.
Default value: `None` which maps to 'price'.

Returns:
A Rank 1 `Tensor` of real dtype containing the price of each FRN
based on the input market data.


def Query(cls, index_urn, target_prefix="", limit=100, token=None):

    return data_store.DB.FileHashIndexQuery(
        index_urn, target_prefix, limit=limit)

Search the index for matches starting with target_prefix.

Args:
index_urn: The index to use. Should be a urn that points to the sha256
namespace.
target_prefix: The prefix to match against the index.
limit: Either a tuple of (start, limit) or a maximum number of results to
return.
token: A DB token.

Returns:
URNs of files which have the same data as this file - as read from the
index.


def supports_card_actions(channel_id: str, button_cnt: int=100) -> bool:
    max_actions = {Channels.facebook: 3, Channels.skype: 3, Channels.ms_teams: 3, Channels.line: 99, Channels.slack: 100, Channels.emulator: 100, Channels.direct_line: 100, Channels.webchat: 100, Channels.cortana: 100}
    return ((button_cnt <= max_actions[channel_id]) if (channel_id in max_actions) else False)

Determine if a number of Card Actions are supported by a Channel.

Args:
channel_id (str): The Channel to check if the Card Actions are supported in.
button_cnt (int, optional): Defaults to 100. The number of Card Actions to check for the Channel.

Returns:
bool: True if the Channel supports the button_cnt total Card Actions, False if the Channel does not support that number of Card Actions.


def GetLineWidth(line):

  if isinstance(line, unicode):
    width = 0
    for uc in unicodedata.normalize('NFC', line):
      if unicodedata.east_asian_width(uc) in ('W', 'F'):
        width += 2
      elif not unicodedata.combining(uc):
        width += 1
    return width
  else:
    return len(line)

Determines the width of the line in column positions.

Args:
line: A string, which may be a Unicode string.

Returns:
The width of the line in column positions, accounting for Unicode
combining characters and wide characters.


def is_attribute_applicable_to_object_type(self, attribute, object_type):

        rule_set = self._attribute_rule_sets.get(attribute)
        if object_type in rule_set.applies_to_object_types:
            return True
        else:
            return False

Check if the attribute is supported by the given object type.

Args:
attribute (string): The name of the attribute (e.g., 'Name').
Required.
object_type (ObjectType): An ObjectType enumeration
(e.g., ObjectType.SYMMETRIC_KEY). Required.
Returns:
bool: True if the attribute is applicable to the object type.
False otherwise.


def rec_new(self, val):

        if val not in self.things:
            for child in val.children():
                self.rec_new(child)
            self.new(val)
        return val

Recursively add a new value and its children to me.

Args:
val (LispVal): The value to be added.

Returns:
LispVal: The added value.


def add_record(self, record):
    record.update_record()
    if record.result == TestResultEnums.TEST_RESULT_SKIP:
        self.skipped.append(record)
        return
    self.executed.append(record)
    if record.result == TestResultEnums.TEST_RESULT_FAIL:
        self.failed.append(record)
    elif record.result == TestResultEnums.TEST_RESULT_PASS:
        self.passed.append(record)
    else:
        self.error.append(record)

Adds a test record to test result.

A record is considered executed once it's added to the test result.

Adding the record finalizes the content of a record, so no change
should be made to the record afterwards.

Args:
record: A test record object to add.


def compute_ssim(image1, image2, gaussian_kernel_sigma=1.5, gaussian_kernel_width=11):
    gaussian_kernel_1d = get_gaussian_kernel(gaussian_kernel_width, gaussian_kernel_sigma)
    return SSIM(image1, gaussian_kernel_1d).ssim_value(image2)

Computes SSIM.

Args:
im1: First PIL Image object to compare.
im2: Second PIL Image object to compare.

Returns:
SSIM float value.


class XLNetPoolerStartLogits(nn.Module):

    def __init__(self, config: XLNetConfig):
        super().__init__()
        self.dense = nn.Linear(config.hidden_size, 1)

    def forward(self, hidden_states: torch.FloatTensor, p_mask: Optional[torch.FloatTensor]=None) -> torch.FloatTensor:

        x = self.dense(hidden_states).squeeze(-1)
        if p_mask is not None:
            if p_mask.dtype == torch.float16:
                x = x * (1 - p_mask) - 65500 * p_mask
            else:
                x = x * (1 - p_mask) - 1e+30 * p_mask
        return x

Compute SQuAD start logits from sequence hidden states.

Args:
config ([`XLNetConfig`]):
The config used by the model, will be used to grab the `hidden_size` of the model.


def list_leases(self, uuid=None):

        try:
            lease_files = os.listdir(self.path)
        except OSError as e:
            raise_from(
                LagoSubnetLeaseBadPermissionsException(self.path, e.strerror),
                e
            )

        leases = [
            self.create_lease_object_from_idx(lease_file.split('.')[0])
            for lease_file in lease_files if lease_file != LOCK_NAME
        ]
        if not uuid:
            return leases
        else:
            return [lease for lease in leases if lease.uuid == uuid]

List current subnet leases

Args:
uuid(str): Filter the leases by uuid

Returns:
list of :class:~Lease: current leases


def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):

        num_records = None
        if isinstance(records, list):
            for record in records:
                if record.channel == 'train':
                    num_records = record.num_records
                    break
            if num_records is None:
                raise ValueError('Must provide train channel.')
        else:
            num_records = records.num_records

        default_mini_batch_size = min(self.DEFAULT_MINI_BATCH_SIZE,
                                      max(1, int(num_records / self.train_instance_count)))
        use_mini_batch_size = mini_batch_size or default_mini_batch_size

        super(PCA, self)._prepare_for_training(records=records, mini_batch_size=use_mini_batch_size, job_name=job_name)

Set hyperparameters needed for training.

Args:
* records (:class:`~RecordSet`): The records to train this ``Estimator`` on.
* mini_batch_size (int or None): The size of each mini-batch to use when training. If ``None``, a
default value will be used.
* job_name (str): Name of the training job to be created. If not specified, one is generated,
using the base name given to the constructor if applicable.


def m_to_mile(value):
    if value is None:
        return None
    return value / 1609

Converts distance in meters to miles

Args:
value: floating point representing the distance in meters
Returns: distance in miles


def main(raw_args=None):

    multifile_choices = frozenset(['c_files'])

    if raw_args is None:
        raw_args = sys.argv[1:]

    parser = build_parser()
    args = parser.parse_args(raw_args)

    if args.output is None and args.format in multifile_choices:
        print("You must specify an output file with -o, --output when "
              "using a format that produces multiple files (-f %s)" % args.format)
        return 1

    desc = TBDescriptor(args.bus_definition)

    if args.format == 'json':
        print("JSON output is not yet supported")
        return 1

    block = desc.get_block()

    template_map = {
        'command_map_c': 'command_map_c.c.tpl',
        'command_map_h': 'command_map_c.h.tpl',
        'config_map_c': 'config_variables_c.c.tpl',
        'config_map_h': 'config_variables_c.h.tpl'
    }

    template_name = template_map.get(args.format)
    data = block.render_template(template_name)
    print(data)

    return 0

Run the iotile-tbcompile script.

Args:
raw_args (list): Optional list of command line arguments.  If not
passed these are pulled from sys.argv.


def batch(self, spec, batch_size):

    def batch_field(f):
        if isinstance(f, type_spec.BatchableTypeSpec):
            return f.__batch_encoder__.batch(f, batch_size)
        elif isinstance(f, tensor_shape.TensorShape):
            return [batch_size] + f
        else:
            return f
    fields = tuple(spec.__dict__.items())
    batched_fields = nest.map_structure(batch_field, fields)
    return _create_object_from_type_and_dict(type(spec), batched_fields)

Returns the TypeSpec representing a batch of values described by `spec`.

The default definition returns a `TypeSpec` that is equal to `spec`, except
that an outer axis with size `batch_size` is added to every nested
`TypeSpec` and `TensorShape` field.  Subclasses may override this default
definition, when necessary.

Args:
spec: The `TypeSpec` for an individual value.
batch_size: An `int` indicating the number of values that are batched
together, or `None` if the batch size is not known.

Returns:
A `TypeSpec` for a batch of values.


def Resnet50(hidden_size=64, num_output_classes=1001, mode='train'):

  del mode
  return layers.Serial(
      layers.Conv(hidden_size, (7, 7), (2, 2), 'SAME'),
      layers.BatchNorm(), layers.Relu(),
      layers.MaxPool(pool_size=(3, 3), strides=(2, 2)),
      ConvBlock(3, [hidden_size, hidden_size, 4 * hidden_size], (1, 1)),
      IdentityBlock(3, [hidden_size, hidden_size, 4 * hidden_size]),
      IdentityBlock(3, [hidden_size, hidden_size, 4 * hidden_size]),
      ConvBlock(3, [2 * hidden_size, 2 * hidden_size, 8 * hidden_size], (2, 2)),
      IdentityBlock(3, [2 * hidden_size, 2 * hidden_size, 8 * hidden_size]),
      IdentityBlock(3, [2 * hidden_size, 2 * hidden_size, 8 * hidden_size]),
      IdentityBlock(3, [2 * hidden_size, 2 * hidden_size, 8 * hidden_size]),
      ConvBlock(3, [4 * hidden_size, 4 * hidden_size, 16*hidden_size], (2, 2)),
      IdentityBlock(3, [4 * hidden_size, 4 * hidden_size, 16 * hidden_size]),
      IdentityBlock(3, [4 * hidden_size, 4 * hidden_size, 16 * hidden_size]),
      IdentityBlock(3, [4 * hidden_size, 4 * hidden_size, 16 * hidden_size]),
      IdentityBlock(3, [4 * hidden_size, 4 * hidden_size, 16 * hidden_size]),
      IdentityBlock(3, [4 * hidden_size, 4 * hidden_size, 16 * hidden_size]),
      ConvBlock(3, [8 * hidden_size, 8 * hidden_size, 32*hidden_size], (2, 2)),
      IdentityBlock(3, [8 * hidden_size, 8 * hidden_size, 32 * hidden_size]),
      IdentityBlock(3, [8 * hidden_size, 8 * hidden_size, 32 * hidden_size]),
      layers.AvgPool(pool_size=(7, 7)), layers.Flatten(),
      layers.Dense(num_output_classes), layers.LogSoftmax())

ResNet.

Args:
hidden_size: the size of the first hidden layer (multiplied later).
num_output_classes: how many classes to distinguish.
mode: whether we are training or evaluating or doing inference.

Returns:
The ResNet model with the given layer and output sizes.


def _create_variables_and_slots(self) -> Dict[Text, Dict[Text, tf_variables.Variable]]:

    def create_variables(table):

        variable_shape = (table.vocabulary_size, table.dim)

        def getter(name, shape, dtype, initializer, trainable):
            del shape
            initial_value = functools.partial(initializer, variable_shape, dtype=dtype)
            return tf_variables.Variable(name=name, initial_value=initial_value, shape=variable_shape, dtype=dtype, trainable=trainable)

        def variable_creator(name, initializer, trainable=True):
            return self._add_variable_with_custom_getter(name=name, initializer=initializer, shape=variable_shape, dtype=dtypes.float32, getter=getter, trainable=trainable)
        parameters = variable_creator(table.name, table.initializer, trainable=not self._using_tpu)

        def slot_creator(name, initializer):
            return variable_creator(table.name + '/' + name, initializer, False)
        if table.optimizer is not None:
            slot_vars = table.optimizer._create_slots(parameters, slot_creator)
        else:
            slot_vars = {}
        slot_vars['parameters'] = parameters
        return slot_vars
    variables = {}
    for table in self._table_config:
        if not self._using_tpu:
            variables[table.name] = create_variables(table)
        else:
            with variable_scope.variable_creator_scope(make_sharded_variable_creator(self._hosts)):
                variables[table.name] = create_variables(table)
    return variables

Create variables for TPU embeddings.

Note under TPUStrategy this will ensure that all creations happen within a
variable creation scope of the sharded variable creator.

Returns:
A dict of dicts. The outer dict is keyed by the table names and the inner
dicts are keyed by 'parameters' and the slot variable names.