def GetFileEntryByPathSpec(self, path_spec):

    row_index = getattr(path_spec, 'row_index', None)
    row_condition = getattr(path_spec, 'row_condition', None)

    if row_index is None and row_condition is None:
      return sqlite_blob_file_entry.SQLiteBlobFileEntry(
          self._resolver_context, self, path_spec, is_root=True,
          is_virtual=True)

    return sqlite_blob_file_entry.SQLiteBlobFileEntry(
        self._resolver_context, self, path_spec)

Retrieves a file entry for a path specification.

Args:
path_spec (PathSpec): path specification.

Returns:
FileEntry: a file entry or None.


def update(self, current, values=None, finalize=None):
    if finalize is None:
        if self.target is None:
            finalize = False
        else:
            finalize = current >= self.target
    values = values or []
    for k, v in values:
        if k not in self._values_order:
            self._values_order.append(k)
        if k not in self.stateful_metrics:
            value_base = max(current - self._seen_so_far, 1)
            if k not in self._values:
                self._values[k] = [v * value_base, value_base]
            else:
                self._values[k][0] += v * value_base
                self._values[k][1] += value_base
        else:
            self._values[k] = [v, 1]
    self._seen_so_far = current
    now = time.time()
    info = ' - %.0fs' % (now - self._start)
    if self.verbose == 1:
        if now - self._last_update < self.interval and (not finalize):
            return
        prev_total_width = self._total_width
        if self._dynamic_display:
            sys.stdout.write('\x08' * prev_total_width)
            sys.stdout.write('\r')
        else:
            sys.stdout.write('\n')
        if self.target is not None:
            numdigits = int(np.log10(self.target)) + 1
            bar = ('%' + str(numdigits) + 'd/%d [') % (current, self.target)
            prog = float(current) / self.target
            prog_width = int(self.width * prog)
            if prog_width > 0:
                bar += '=' * (prog_width - 1)
                if current < self.target:
                    bar += '>'
                else:
                    bar += '='
            bar += '.' * (self.width - prog_width)
            bar += ']'
        else:
            bar = '%7d/Unknown' % current
        self._total_width = len(bar)
        sys.stdout.write(bar)
        time_per_unit = self._estimate_step_duration(current, now)
        if self.target is None or finalize:
            if time_per_unit >= 1 or time_per_unit == 0:
                info += ' %.0fs/%s' % (time_per_unit, self.unit_name)
            elif time_per_unit >= 0.001:
                info += ' %.0fms/%s' % (time_per_unit * 1000.0, self.unit_name)
            else:
                info += ' %.0fus/%s' % (time_per_unit * 1000000.0, self.unit_name)
        else:
            eta = time_per_unit * (self.target - current)
            if eta > 3600:
                eta_format = '%d:%02d:%02d' % (eta
            elif eta > 60:
                eta_format = '%d:%02d' % (eta
            else:
                eta_format = '%ds' % eta
            info = ' - ETA: %s' % eta_format
        for k in self._values_order:
            info += ' - %s:' % k
            if isinstance(self._values[k], list):
                avg = np.mean(self._values[k][0] / max(1, self._values[k][1]))
                if abs(avg) > 0.001:
                    info += ' %.4f' % avg
                else:
                    info += ' %.4e' % avg
            else:
                info += ' %s' % self._values[k]
        self._total_width += len(info)
        if prev_total_width > self._total_width:
            info += ' ' * (prev_total_width - self._total_width)
        if finalize:
            info += '\n'
        sys.stdout.write(info)
        sys.stdout.flush()
    elif self.verbose == 2:
        if finalize:
            numdigits = int(np.log10(self.target)) + 1
            count = ('%' + str(numdigits) + 'd/%d') % (current, self.target)
            info = count + info
            for k in self._values_order:
                info += ' - %s:' % k
                avg = np.mean(self._values[k][0] / max(1, self._values[k][1]))
                if avg > 0.001:
                    info += ' %.4f' % avg
                else:
                    info += ' %.4e' % avg
            info += '\n'
            sys.stdout.write(info)
            sys.stdout.flush()
    self._last_update = now

Updates the progress bar.

Args:
current: Index of current step.
values: List of tuples: `(name, value_for_last_step)`. If `name` is in
`stateful_metrics`, `value_for_last_step` will be displayed as-is.
Else, an average of the metric over time will be displayed.
finalize: Whether this is the last update for the progress bar. If
`None`, defaults to `current >= self.target`.


def get_forecast_errors(y_hat,
                        y_true,
                        window_size=5,
                        batch_size=30,
                        smoothing_percent=0.05,
                        smoothed=True):

    errors = [abs(y_h - y_t) for y_h, y_t in zip(y_hat, y_true)]

    if not smoothed:
        return errors

    historical_error_window = int(window_size * batch_size * smoothing_percent)
    moving_avg = []
    for i in range(len(errors)):
        left_window = i - historical_error_window
        right_window = i + historical_error_window + 1
        if left_window < 0:
            left_window = 0

        if right_window > len(errors):
            right_window = len(errors)

        moving_avg.append(np.mean(errors[left_window:right_window]))

    return moving_avg

Calculates the forecasting error for two arrays of data. If smoothed errors desired,
runs EWMA.
Args:
y_hat (list): forecasted values. len(y_hat)==len(y_true).
y_true (list): true values. len(y_hat)==len(y_true).
window_size (int):
batch_size (int):
smoothing_percent (float):
smoothed (bool): whether the returned errors should be smoothed with EWMA.
Returns:
(list): error residuals. Smoothed if specified by user.


def rep1sep(parser: Union[Parser, Sequence[Input]], separator: Union[Parser, Sequence[Input]]) \
        -> RepeatedOnceSeparatedParser:

    if isinstance(parser, str):
        parser = lit(parser)
    if isinstance(separator, str):
        separator = lit(separator)
    return RepeatedOnceSeparatedParser(parser, separator)

Match a parser one or more times separated by another parser.

This matches repeated sequences of ``parser`` separated by ``separator``.
If there is at least one match, a list containing the values of the
``parser`` matches is returned. The values from ``separator`` are discarded.
If it does not match ``parser`` at all, it fails.

Args:
parser: Parser or literal
separator: Parser or literal


def _checkResponseRegisterAddress(payload, registeraddress):
    _checkString(payload, minlength=2, description='payload')
    _checkRegisteraddress(registeraddress)
    BYTERANGE_FOR_STARTADDRESS = slice(0, 2)
    bytesForStartAddress = payload[BYTERANGE_FOR_STARTADDRESS]
    receivedStartAddress = _twoByteStringToNum(bytesForStartAddress)
    if (receivedStartAddress != registeraddress):
        raise ValueError('Wrong given write start adress: {0}, but commanded is {1}. The data payload is: {2!r}'.format(receivedStartAddress, registeraddress, payload))

Check that the start adress as given in the response is correct.

The first two bytes in the payload holds the address value.

Args:
* payload (string): The payload
* registeraddress (int): The register address (use decimal numbers, not hex).

Raises:
TypeError, ValueError


def migration_exchange(self, *, users: List[str], **kwargs) -> SlackResponse:

        kwargs.update({"users": users})
        return self.api_call("migration.exchange", http_verb="GET", params=kwargs)

For Enterprise Grid workspaces, map local user IDs to global user IDs

Args:
users (list): A list of user ids, up to 400 per request.
e.g. ['W1234567890', 'U2345678901', 'U3456789012']


def kill_log_monitor(self, check_alive=True):

        self._kill_process_type(
            ray_constants.PROCESS_TYPE_LOG_MONITOR, check_alive=check_alive)

Kill the log monitor.

Args:
check_alive (bool): Raise an exception if the process was already
dead.


def data(self, namespace):

        assert namespace

        if namespace in self._data:
            return self._data[namespace]

        new_data = {}
        self._data[namespace] = new_data
        return new_data

Gets the thread.local data (dict) for a given namespace.

Args:
namespace (string): The namespace, or key, of the data dict.

Returns:
(dict)


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

Returns the dataset specified by datasetID.

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


def copy_coding(source: message.Message, target: message.Message) -> None:
    if not fhir_types.is_type_or_profile_of_coding(source.DESCRIPTOR):
        raise fhir_errors.InvalidFhirError(f'Source: {source.DESCRIPTOR.full_name} is not a type or profile of Coding.')
    if not fhir_types.is_type_or_profile_of_coding(target.DESCRIPTOR):
        raise fhir_errors.InvalidFhirError(f'Target: {target.DESCRIPTOR.full_name} is not a type or profile of Coding.')
    if proto_utils.are_same_message_type(source.DESCRIPTOR, target.DESCRIPTOR):
        target.CopyFrom(source)
        return
    proto_utils.copy_common_field(source, target, 'id')
    proto_utils.copy_common_field(source, target, 'extension')
    proto_utils.copy_common_field(source, target, 'version')
    proto_utils.copy_common_field(source, target, 'display')
    proto_utils.copy_common_field(source, target, 'user_selected')
    source_code = proto_utils.get_value_at_field(source, 'code')
    copy_code(source_code, proto_utils.set_in_parent_or_add(target, 'code'))
    target_system_field = target.DESCRIPTOR.fields_by_name.get('system')
    if target_system_field is not None:
        source_system_str = get_system_for_code(source_code)
        target_system_uri = proto_utils.set_in_parent_or_add(target, target_system_field)
        proto_utils.set_value_at_field(target_system_uri, 'value', source_system_str)

Copies all fields from source to target "Coding" messages.

Args:
source: The FHIR coding instance to copy from.
target: The FHIR coding instance to copy to.

Raises:
InvalidFhirError: In the event that source or target is not a type/profile
of Coding.


def valid_as_v2_0(voevent):

    _return_to_standard_xml(voevent)
    valid_bool = voevent_v2_0_schema.validate(voevent)
    _remove_root_tag_prefix(voevent)
    return valid_bool

Tests if a voevent conforms to the schema.

Args:
voevent(:class:`Voevent`): Root node of a VOEvent etree.
Returns:
bool: Whether VOEvent is valid


def fix_pbc(structure, matrix=None):

    spec = []
    coords = []
    if matrix is None:
        latte = Lattice(structure.lattice.matrix)
    else:
        latte = Lattice(matrix)

    for site in structure:
        spec.append(site.specie)
        coord = np.array(site.frac_coords)
        for i in range(3):
            coord[i] -= floor(coord[i])
            if np.allclose(coord[i], 1):
                coord[i] = 0
            elif np.allclose(coord[i], 0):
                coord[i] = 0
            else:
                coord[i] = round(coord[i], 7)
        coords.append(coord)

    return Structure(latte, spec, coords, site_properties=structure.site_properties)

Set all frac_coords of the input structure within [0,1].

Args:
structure (pymatgen structure object):
input structure
matrix (lattice matrix, 3 by 3 array/matrix)
new structure's lattice matrix, if none, use
input structure's matrix

Return:
new structure with fixed frac_coords and lattice matrix


def _component_specs(self):
    raise NotImplementedError('%s._component_specs()' % type(self).__name__)

A nested structure of TypeSpecs for this type's components.

Returns:
A nested structure describing the component encodings that are returned
by this TypeSpec's `_to_components` method.  In particular, for a
TypeSpec `spec` and a compatible value `value`:

```
nest.map_structure(lambda t, c: assert t.is_compatible_with(c),
spec._component_specs, spec._to_components(value))
```


def unique_name(self, name, mark_as_used=True):

    scope_name = tf.get_variable_scope().name
    if scope_name:
      name = scope_name + "/" + name

    name_key = name.lower()
    i = self._names_in_use.get(name_key, 0)
    if mark_as_used:
      self._names_in_use[name_key] = i + 1
    if i > 0:
      base_name_key = name_key
      while name_key in self._names_in_use:
        name_key = "%s_%d" % (base_name_key, i)
        i += 1
      if mark_as_used:
        self._names_in_use[name_key] = 1
      name = "%s_%d" % (name, i-1)

    return name

Like tf.Graph.unique_name, returns a unique operation name for `name`.

Args:
name: The name for an operation.
mark_as_used: whether to mark this name as being used.

Returns:
A string to use as the name for the operation.


def wrap_and_format(self, width=None, include_params=False, include_return=False, excluded_params=None):
    if (excluded_params is None):
        excluded_params = []
    out = StringIO()
    if (width is None):
        (width, _height) = get_terminal_size()
    for line in self.maindoc:
        if isinstance(line, Line):
            out.write(fill(line.contents, width=width))
            out.write('\n')
        elif isinstance(line, BlankLine):
            out.write('\n')
        elif isinstance(line, ListItem):
            out.write(fill(line.contents, initial_indent=(' %s ' % line.marker[0]), subsequent_indent='   ', width=width))
            out.write('\n')
    if include_params:
        included_params = (set(self.param_info) - set(excluded_params))
        if (len(included_params) > 0):
            out.write('\nParameters:\n')
            for param in included_params:
                info = self.param_info[param]
                out.write((' - %s (%s):\n' % (param, info.type_name)))
                out.write(fill(info.desc, initial_indent='   ', subsequent_indent='   ', width=width))
                out.write('\n')
    if include_return:
        print('Returns:')
        print(('    ' + self.return_info.type_name))
    return out.getvalue()

Wrap, format and print this docstring for a specific width.

Args:
width (int): The number of characters per line.  If set to None
this will be inferred from the terminal width and default
to 80 if not passed or if passed as None and the terminal
width cannot be determined.
include_return (bool): Include the return information section
in the output.
include_params (bool): Include a parameter information section
in the output.
excluded_params (list): An optional list of parameter names to exclude.
Options for excluding things are, for example, 'self' or 'cls'.


def locate(self, maximum_items=None, storage_status_mask=None, object_group_member=None, attributes=None):
    if (maximum_items is not None):
        if (not isinstance(maximum_items, six.integer_types)):
            raise TypeError('maximum_items must be an integer')
    if (storage_status_mask is not None):
        if (not isinstance(storage_status_mask, six.integer_types)):
            raise TypeError('storage_status_mask must be an integer')
    if (object_group_member is not None):
        if (not isinstance(object_group_member, enums.ObjectGroupMember)):
            raise TypeError('object_group_member must be a ObjectGroupMemberenumeration')
    if (attributes is not None):
        if ((not isinstance(attributes, list)) or (all((isinstance(item, cobjects.Attribute) for item in attributes)) is False)):
            raise TypeError('attributes must be a list of attributes')
    result = self.proxy.locate(maximum_items, storage_status_mask, object_group_member, attributes)
    status = result.result_status.value
    if (status == enums.ResultStatus.SUCCESS):
        return result.uuids
    else:
        reason = result.result_reason.value
        message = result.result_message.value
        raise exceptions.KmipOperationFailure(status, reason, message)

Search for managed objects, depending on the attributes specified in
the request.

Args:
maximum_items (integer): Maximum number of object identifiers the
server MAY return.
storage_status_mask (integer): A bit mask that indicates whether
on-line or archived objects are to be searched.
object_group_member (ObjectGroupMember): An enumeration that
indicates the object group member type.
attributes (list): Attributes the are REQUIRED to match those in a
candidate object.

Returns:
list: The Unique Identifiers of the located objects

Raises:
ClientConnectionNotOpen: if the client connection is unusable
KmipOperationFailure: if the operation result is a failure
TypeError: if the input arguments are invalid


def _create_simple_tf1_gather_model(self, input_type: dtypes.DType, use_variable_for_filter=False) -> Tuple[core.Tensor, core.Tensor]:
    in_placeholder = array_ops.placeholder(input_type, shape=6)
    filters = np.random.randn(128, 32).astype(np.float32)
    if use_variable_for_filter:
        filters = variables.Variable(filters)
    output_tensor = array_ops.gather_v2(filters, in_placeholder)
    return (in_placeholder, output_tensor)

Creates a basic gather model.

This is intended to be used for TF1 (graph mode) tests.

Args:
input_type: type of the input index tensor for gather operation.
use_variable_for_filter: Setting this to `True` makes the filter for the
gather operation a `tf.Variable`.

Returns:
in_placeholder: Input tensor placeholder.
output_tensor: The resulting tensor of the gather operation.


def do_ams_sto_put(endpoint, body, content_length):

    headers = {"Accept": json_acceptformat,
               "Accept-Charset" : charset,
               "x-ms-blob-type" : "BlockBlob",
               "x-ms-meta-m1": "v1",
               "x-ms-meta-m2": "v2",
               "x-ms-version" : "2015-02-21",
               "Content-Length" : str(content_length)}
    return requests.put(endpoint, data=body, headers=headers)

Do a PUT request to the Azure Storage API and return JSON.
Args:
endpoint (str): Azure Media Services Initial Endpoint.
body  (str): Azure Media Services Content Body.
content_length (str): Content_length.

Returns:
HTTP response. JSON body.


def is_active(self, node):
    if (isinstance(node.value, gast.Call) and (anno.getanno(node.value, 'func', False) == utils.pop)):
        return True
    for succ in gast.walk(node.value):
        if (isinstance(succ, gast.Name) and isinstance(succ.ctx, gast.Load) and (succ.id in self.active_variables)):
            return True
    return False

Checks whether a statement is active.

An assignment is active when its right hand side contains active
variables.

Args:
node: an instance of gast.Assign

Returns:
Whether the statement is active.


def randwindow(self, window_shape):

        row = random.randrange(window_shape[0], self.shape[1])
        col = random.randrange(window_shape[1], self.shape[2])
        return self[:, row-window_shape[0]:row, col-window_shape[1]:col]

Get a random window of a given shape from within an image

Args:
window_shape (tuple): The desired shape of the returned image as (height, width) in pixels.

Returns:
image: a new image object of the specified shape and same type


def construct_optional_traversal_tree(complex_optional_roots, location_to_optional_roots):
    tree = OptionalTraversalTree(complex_optional_roots)
    for optional_root_locations_stack in six.itervalues(location_to_optional_roots):
        tree.insert(list(optional_root_locations_stack))
    return tree

Return a tree of complex optional root locations.

Args:
complex_optional_roots: list of @optional locations (location immmediately preceding
an @optional Traverse) that expand vertex fields
location_to_optional_roots: dict mapping from location -> optional_roots where location is
within some number of @optionals and optional_roots is a list
of optional root locations preceding the successive @optional
scopes within which the location resides

Returns:
OptionalTraversalTree object representing the tree of complex optional roots


def _PrintAnalysisReportsDetails(self, storage_reader):

    if not storage_reader.HasAnalysisReports():
      self._output_writer.Write('No analysis reports stored.\n\n')
      return

    for index, analysis_report in enumerate(
        storage_reader.GetAnalysisReports()):
      title = 'Analysis report: {0:d}'.format(index)
      table_view = views.ViewsFactory.GetTableView(
          self._views_format_type, title=title)

      table_view.AddRow(['String', analysis_report.GetString()])

      table_view.Write(self._output_writer)

Prints the details of the analysis reports.

Args:
storage_reader (StorageReader): storage reader.


def listen(self, grpc_port):

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

    sys.stderr.write('Creating InteractiveDebuggerPlugin at port %d\n' %
                     self._grpc_port)
    sys.stderr.flush()
    self._debugger_data_server = (
        interactive_debugger_server_lib.InteractiveDebuggerDataServer(
            self._grpc_port))

    self._server_thread = threading.Thread(
        target=self._debugger_data_server.run_server)
    self._server_thread.start()

    signal.signal(signal.SIGINT, self.signal_handler)

Start listening on the given gRPC port.

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

Args:
grpc_port: port number to listen at.

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


def __init__(self, conf=None, conf_file=".onshapepy"):

        default_conf = {
            'stack': 'https:
            'logging': False,
            'creds': None
        }

        try:
            user_conf = yaml.load(Path.home().joinpath(conf_file))
            default_conf.update(user_conf)
        except:
            pass

        if conf:
            default_conf.update(conf)

        self.conf = default_conf

        self._stack = default_conf['stack']
        self._api = Onshape(default_conf['stack'], default_conf['creds'], default_conf['logging'])

Instantiates a new Onshape client.

Attributes:
- conf: the configuration that generated this client. This is read-only and for testing purposes.

Args:
- configuration (dict, optional): a dictionary of configuration options. Default behavior is to load this from a YAML file that
is located in user's home directory and name '.onshapepy'. For options that can be set, look
at the documentation section on 'configuration'.


def date_to_datetime(self, time_input, tz=None):
    dt = None
    try:
        dt = parser.parse(time_input)
        if ((tz is not None) and (tz != dt.tzname())):
            if (dt.tzinfo is None):
                dt = self._replace_timezone(dt)
            dt = dt.astimezone(timezone(tz))
    except IndexError:
        pass
    except TypeError:
        pass
    except ValueError:
        pass
    return dt

Convert ISO 8601 and other date strings to datetime.datetime type.

Args:
time_input (string): The time input string (see formats above).
tz (string): The time zone for the returned data.

Returns:
(datetime.datetime): Python datetime.datetime object.


def _readable_flags(transport):

        if 'flags' not in transport:
            return None
        _flag_list = []
        flags = transport['flags']
        if flags & dpkt.tcp.TH_SYN:
            if flags & dpkt.tcp.TH_ACK:
                _flag_list.append('syn_ack')
            else:
                _flag_list.append('syn')
        elif flags & dpkt.tcp.TH_FIN:
            if flags & dpkt.tcp.TH_ACK:
                _flag_list.append('fin_ack')
            else:
                _flag_list.append('fin')
        elif flags & dpkt.tcp.TH_RST:
            _flag_list.append('rst')
        elif flags & dpkt.tcp.TH_PUSH:
            _flag_list.append('psh')
        return _flag_list

Method that turns bit flags into a human readable list

Args:
transport (dict): transport info, specifically needs a 'flags' key with bit_flags
Returns:
list: a list of human readable flags (e.g. ['syn_ack', 'fin', 'rst', ...]


def setExtention(self, ext):

        import warnings
        msg = "the setExtention method is deprecated, please use setExtension"
        warnings.warn(msg)
        self.setExtension(ext)

Deprecated: use :meth:`setExtension`.

Args:
ext (str):


def build_from_generator(cls, generator, target_size, max_subtoken_length=None, reserved_tokens=None):
    token_counts = collections.defaultdict(int)
    for item in generator:
        for tok in tokenizer.encode(native_to_unicode(item)):
            token_counts[tok] += 1
    encoder = cls.build_to_target_size(target_size, token_counts, 1, 1000.0, max_subtoken_length=max_subtoken_length, reserved_tokens=reserved_tokens)
    return encoder

Builds a SubwordTextEncoder from the generated text.

Args:
generator: yields text.
target_size: int, approximate vocabulary size to create.
max_subtoken_length: Maximum length of a subtoken. If this is not set,
then the runtime and memory use of creating the vocab is quadratic in
the length of the longest token. If this is set, then it is instead
O(max_subtoken_length * length of longest token).
reserved_tokens: List of reserved tokens. The global variable
`RESERVED_TOKENS` must be a prefix of `reserved_tokens`. If this
argument is `None`, it will use `RESERVED_TOKENS`.

Returns:
SubwordTextEncoder with `vocab_size` approximately `target_size`.


def _MatmulExtractingThreeDiagonals(x, y_tr):
    diag = math_ops.reduce_sum(x * y_tr, axis=-1)
    if y_tr.shape.is_fully_defined():
        zeros = array_ops.zeros(list(x.shape[:-2]) + [1, x.shape[-1]], dtype=x.dtype)
        superdiag = math_ops.reduce_sum(x * array_ops.concat((y_tr[..., 1:, :], zeros), axis=-2), axis=-1)
        subdiag = math_ops.reduce_sum(x * array_ops.concat((zeros, y_tr[..., :-1, :]), axis=-2), axis=-1)
    else:
        rank = array_ops.rank(y_tr)
        zeros = array_ops.zeros((rank - 2, 2), dtype=dtypes.int32)
        superdiag_pad = array_ops.concat((zeros, array_ops.constant([[0, 1], [0, 0]])), axis=0)
        superdiag = math_ops.reduce_sum(x * array_ops.pad(y_tr[..., 1:, :], superdiag_pad), axis=-1)
        subdiag_pad = array_ops.concat((zeros, array_ops.constant([[1, 0], [0, 0]])), axis=0)
        subdiag = math_ops.reduce_sum(x * array_ops.pad(y_tr[..., :-1, :], subdiag_pad), axis=-1)
    return array_ops_stack.stack([superdiag, diag, subdiag], axis=-2)

Multiplies matrices and extracts three diagonals from the product.

With sizes M x K and K x M, this function takes O(MK) time and O(M) space,
while using math_ops.matmul, and then extracting the diagonals would take
O(M^2 K) time and O(M^2) space.

Args:
x: first matrix
y_tr: second matrix transposed

Returns:
Diagonals of the product in compact format (see
linalg_ops.tridiagonal_solve)


def _SerializeAttributeContainer(self, attribute_container):

    if self._serializers_profiler:
      self._serializers_profiler.StartTiming(
          attribute_container.CONTAINER_TYPE)

    try:
      attribute_container_data = self._serializer.WriteSerialized(
          attribute_container)
      if not attribute_container_data:
        raise IOError(
            'Unable to serialize attribute container: {0:s}.'.format(
                attribute_container.CONTAINER_TYPE))

      attribute_container_data = attribute_container_data.encode('utf-8')

    finally:
      if self._serializers_profiler:
        self._serializers_profiler.StopTiming(
            attribute_container.CONTAINER_TYPE)

    return attribute_container_data

Serializes an attribute container.

Args:
attribute_container (AttributeContainer): attribute container.

Returns:
bytes: serialized attribute container.

Raises:
IOError: if the attribute container cannot be serialized.
OSError: if the attribute container cannot be serialized.


def get_bucket(self, key, rate=None, capacity=None, **kwargs):

        return buckets.Bucket(
            key=key,
            rate=rate or self.rate,
            capacity=capacity or self.capacity,
            storate=self.storate,
            **kwargs)

Fetch a Bucket for the given key.

rate and capacity might be overridden from the Throttler defaults.

Args:
rate (float): Units regenerated by second, or None to keep
Throttler defaults
capacity (int): Maximum units available, or None to keep Throttler
defaults


def liquid_precipitation_quantity(self, value=99.0):

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

        self._liquid_precipitation_quantity = value

Corresponds to IDD Field `liquid_precipitation_quantity`

Args:
value (float): value for IDD Field `liquid_precipitation_quantity`
Unit: hr
Missing value: 99.0
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 pageNames(matching=False,workbooks=True,graphs=True):

    pages=[]
    if workbooks:
        pages.extend(PyOrigin.WorksheetPages())
    if graphs:
        pages.extend(PyOrigin.GraphPages())

    pages = [x.GetName() for x in pages]

    if matching:
        pages=[x for x in pages if matching in x]
    return pages

Returns the names of everything (books, notes, graphs, etc.) in the project.

Args:
matching (str, optional): if given, only return names with this string in it
workbooks (bool): if True, return workbooks
graphs (bool): if True, return workbooks

Returns:
A list of the names of what you requested


class ClapProcessor(ProcessorMixin):
    feature_extractor_class = 'ClapFeatureExtractor'
    tokenizer_class = ('RobertaTokenizer', 'RobertaTokenizerFast')

    def __init__(self, feature_extractor, tokenizer):
        super().__init__(feature_extractor, tokenizer)

    def __call__(self, text=None, audios=None, return_tensors=None, **kwargs):

        sampling_rate = kwargs.pop('sampling_rate', None)
        if text is None and audios is None:
            raise ValueError('You have to specify either text or audios. Both cannot be none.')
        if text is not None:
            encoding = self.tokenizer(text, return_tensors=return_tensors, **kwargs)
        if audios is not None:
            audio_features = self.feature_extractor(audios, sampling_rate=sampling_rate, return_tensors=return_tensors, **kwargs)
        if text is not None and audios is not None:
            encoding.update(audio_features)
            return encoding
        elif text is not None:
            return encoding
        else:
            return BatchEncoding(data=dict(**audio_features), tensor_type=return_tensors)

    def batch_decode(self, *args, **kwargs):

        return self.tokenizer.batch_decode(*args, **kwargs)

    def decode(self, *args, **kwargs):

        return self.tokenizer.decode(*args, **kwargs)

    @property
    def model_input_names(self):
        tokenizer_input_names = self.tokenizer.model_input_names
        feature_extractor_input_names = self.feature_extractor.model_input_names
        return list(dict.fromkeys(tokenizer_input_names + feature_extractor_input_names))

Constructs a CLAP processor which wraps a CLAP feature extractor and a RoBerta tokenizer into a single processor.

[`ClapProcessor`] offers all the functionalities of [`ClapFeatureExtractor`] and [`RobertaTokenizerFast`]. See the
[`~ClapProcessor.__call__`] and [`~ClapProcessor.decode`] for more information.

Args:
feature_extractor ([`ClapFeatureExtractor`]):
The audio processor is a required input.
tokenizer ([`RobertaTokenizerFast`]):
The tokenizer is a required input.


def add_block_parser(subparsers, parent_parser):

    parser = subparsers.add_parser(
        'block',
        description='Provides subcommands to display information about the '
        'blocks in the current blockchain.',
        help='Displays information on blocks in the current blockchain')

    grand_parsers = parser.add_subparsers(
        title='subcommands',
        dest='subcommand')

    grand_parsers.required = True

    description = (
        'Displays information for all blocks on the current '
        'blockchain, including the block id and number, public keys all '
        'of allsigners, and number of transactions and batches.')

    list_parser = grand_parsers.add_parser(
        'list',
        help='Displays information for all blocks on the current blockchain',
        description=description,
        parents=[base_http_parser(), base_list_parser()],
        formatter_class=argparse.RawDescriptionHelpFormatter)

    list_parser.add_argument(
        '-n',
        '--count',
        default=100,
        type=int,
        help='the number of blocks to list',
    )

    description = (
        'Displays information about the specified block on '
        'the current blockchain')

    show_parser = grand_parsers.add_parser(
        'show',
        help=description,
        description=description + '.',
        parents=[base_http_parser(), base_show_parser()],
        formatter_class=argparse.RawDescriptionHelpFormatter)
    show_parser.add_argument(
        'block_id',
        type=str,
        help='id (header_signature) of the block')

Adds arguments parsers for the block list and block show commands

Args:
subparsers: Add parsers to this subparser object
parent_parser: The parent argparse.ArgumentParser object


def add_device(self, path):

		hdevice = self._libinput.libinput_path_add_device(
			self._li, path.encode())
		if hdevice:
			return Device(hdevice, self._libinput)
		return None

Add a device to a libinput context.

If successful, the device will be added to the internal list and
re-opened on :meth:`~libinput.LibInput.resume`. The device can be
removed with :meth:`remove_device`.
If the device was successfully initialized, it is returned.

Args:
path (str): Path to an input device.
Returns:
~libinput.define.Device: A device object or :obj:`None`.


def process_obj(self, obj: Union[(URIRef, Literal, str)]) -> Union[(URIRef, Literal)]:
    if (isinstance(obj, dict) or isinstance(obj, list)):
        exit((str(obj) + ': should be str or intended to be a URIRef or Literal.'))
    if (isinstance(obj, Literal) or isinstance(obj, URIRef)):
        prefix = self.find_prefix(obj)
        if prefix:
            self.process_prefix(prefix)
        return obj
    if (len(obj) > 8):
        if (('http' == obj[:4]) and (':
            prefix = self.find_prefix(obj)
            if prefix:
                self.process_prefix(prefix)
            return URIRef(obj)
    if (':' in str(obj)):
        (presumed_prefix, info) = obj.split(':', 1)
        namespace: Union[(Namespace, None)] = self.process_prefix(presumed_prefix)
        if namespace:
            return namespace[info]
    return Literal(obj)

Gives component the proper node type

Args:
obj: Entity object to be converted to its appropriate node type

Returns:
URIRef or Literal type of the object provided.

Raises:
SystemExit: If object is a dict or list it becomes str with broken data. Needs to
come in one object at a time.


def FoldByteStream(self, mapped_value, **unused_kwargs):

    try:
      value = self.FoldValue(mapped_value)
      return self._operation.WriteTo(tuple([value]))

    except Exception as exception:
      error_string = (
          'Unable to write: {0:s} to byte stream with error: {1!s}').format(
              self._data_type_definition.name, exception)
      raise errors.FoldingError(error_string)

Folds the data type into a byte stream.

Args:
mapped_value (object): mapped value.

Returns:
bytes: byte stream.

Raises:
FoldingError: if the data type definition cannot be folded into
the byte stream.


def get_storage_usage(access_token, subscription_id, location):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Storage/locations/', location, '/usages', '?api-version=', STORAGE_API])
    return do_get(endpoint, access_token)

Returns storage usage and quota information for the specified subscription.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.

Returns:
HTTP response. JSON body of storage account usage.


def Load(cls, file_input, client=None):
    if (client is None):
        client = AdWordsClient.LoadFromStorage()
    try:
        data = yaml.safe_load(file_input)
    except yaml.YAMLError as e:
        raise googleads.errors.GoogleAdsError(('Error loading IncrementalUploadHelper from file: %s' % str(e)))
    try:
        request_builder = BatchJobHelper.GetRequestBuilder(client, version=data['version'], server=data['server'])
        return cls(request_builder, data['upload_url'], current_content_length=data['current_content_length'], is_last=data['is_last'])
    except KeyError as e:
        raise googleads.errors.GoogleAdsValueError(('Can\'t parse IncrementalUploadHelper from file. Required field "%s" is missing.' % e.message))

Loads an IncrementalUploadHelper from the given file-like object.

Args:
file_input: a file-like object containing a serialized
IncrementalUploadHelper.
client: an AdWordsClient instance. If not specified, an AdWordsClient will
be instantiated using the default configuration file.

Returns:
An IncrementalUploadHelper instance initialized using the contents of the
serialized input file.

Raises:
GoogleAdsError: If there is an error reading the input file containing the
serialized IncrementalUploadHelper.
GoogleAdsValueError: If the contents of the input file can't be parsed to
produce an IncrementalUploadHelper.


def QueueQueryAndOwn(self, queue, lease_seconds, limit, timestamp):

    try:
      lock = DB.LockRetryWrapper(queue, lease_time=lease_seconds)
      return self._QueueQueryAndOwn(
          lock.subject,
          lease_seconds=lease_seconds,
          limit=limit,
          timestamp=timestamp)
    except DBSubjectLockError:

      return []
    except Error as e:
      logging.warning("Datastore exception: %s", e)
      return []

Returns a list of Tasks leased for a certain time.

Args:
queue: The queue to query from.
lease_seconds: The tasks will be leased for this long.
limit: Number of values to fetch.
timestamp: Range of times for consideration.

Returns:
A list of GrrMessage() objects leased.


def _apply_dense(self, grad, var):
    raise NotImplementedError()

Add ops to apply dense gradients to `var`.

Args:
grad: A `Tensor`.
var: A `Variable` object.

Returns:
An `Operation`.


def update_server_def(self, server_def, keep_alive_secs=_KEEP_ALIVE_SECS):
    if not server_def:
        raise ValueError('server_def is None.')
    self._server_def = server_def
    if self._context_handle:
        server_def_str = server_def.SerializeToString()
        pywrap_tfe.TFE_ContextUpdateServerDef(self._context_handle, keep_alive_secs, server_def_str)
        self._initialize_logical_devices()
    self._clear_caches()

Update a server_def on the context.

Args:
server_def: A tensorflow::ServerDef proto. Enables execution on remote
devices.
keep_alive_secs: Num. seconds after which the remote end will hang up. As
long as the client is still alive, the server state for the context will
be kept alive. If the client is killed (or there is some failure), the
server will clean up its context keep_alive_secs after the final RPC it
receives.

Raises:
ValueError: if server_def is None.


def _set_batch_size(self, batch_size):
    if not self._has_valid_tensors():
        raise ValueError('The batch size cannot be set for this model. Please use input_shapes parameter.')
    for tensor in self._input_tensors:
        shape = tensor.shape.as_list()
        if shape[0] is None:
            shape[0] = batch_size
            tensor.set_shape(shape)

Sets the first dimension of the input tensor to `batch_size`.

Args:
batch_size: Batch size for the model. Replaces the first dimension of an
input size array if undefined. (default 1)

Raises:
ValueError: input_tensor is not defined.


def easeInOutQuint(n):

    _checkRange(n)
    n = 2 * n
    if n < 1:
        return 0.5 * n**5
    else:
        n = n - 2
        return 0.5 * (n**5 + 2)

A quintic tween function that accelerates, reaches the midpoint, and then decelerates.

Args:
n (float): The time progress, starting at 0.0 and ending at 1.0.

Returns:
(float) The line progress, starting at 0.0 and ending at 1.0. Suitable for passing to getPointOnLine().


def get_new_python_files(diff_with_last_commit=False) -> List[str]:
    repo = Repo(PATH_TO_REPO)
    try:
        main = repo.refs.main
    except AttributeError:
        main = repo.remotes.origin.refs.main
    if not diff_with_last_commit:
        print(f'main is at {main.commit}')
        print(f'Current head is at {repo.head.commit}')
        commits = repo.merge_base(main, repo.head)
        for commit in commits:
            print(f'Branching commit: {commit}')
    else:
        print(f'main is at {main.commit}')
        commits = main.commit.parents
        for commit in commits:
            print(f'Parent commit: {commit}')
    return get_new_python_files_between_commits(repo.head.commit, commits)

Return a list of python files that have been added between the current head and the main branch.

Returns:
`List[str]`: The list of python files added.


def invoke_process(self, windowed_value, restriction=None, watermark_estimator_state=None, additional_args=None, additional_kwargs=None):
    raise NotImplementedError

Invokes the DoFn.process() function.

Args:
windowed_value: a WindowedValue object that gives the element for which
process() method should be invoked along with the window
the element belongs to.
restriction: The restriction to use when executing this splittable DoFn.
Should only be specified for splittable DoFns.
watermark_estimator_state: The watermark estimator state to use when
executing this splittable DoFn. Should only
be specified for splittable DoFns.
additional_args: additional arguments to be passed to the current
`DoFn.process()` invocation, usually as side inputs.
additional_kwargs: additional keyword arguments to be passed to the
current `DoFn.process()` invocation.


def _get_namedrange(book, rangename, sheetname=None):

    def cond(namedef):
        if (namedef.type.upper() == 'RANGE'):
            if (namedef.name.upper() == rangename.upper()):
                if (sheetname is None):
                    if (not namedef.localSheetId):
                        return True
                else:
                    sheet_id = [sht.upper() for sht in book.sheetnames].index(sheetname.upper())
                    if (namedef.localSheetId == sheet_id):
                        return True
        return False

    def get_destinations(name_def):
        'Workaround for the bug in DefinedName.destinations'
        from openpyxl.formula import Tokenizer
        from openpyxl.utils.cell import SHEETRANGE_RE
        if (name_def.type == 'RANGE'):
            tok = Tokenizer(('=' + name_def.value))
            for part in tok.items:
                if (part.subtype == 'RANGE'):
                    m = SHEETRANGE_RE.match(part.value)
                    if m.group('quoted'):
                        sheet_name = m.group('quoted')
                    else:
                        sheet_name = m.group('notquoted')
                    (yield (sheet_name, m.group('cells')))
    namedef = next((item for item in book.defined_names.definedName if cond(item)), None)
    if (namedef is None):
        return None
    dests = get_destinations(namedef)
    xlranges = []
    sheetnames_upper = [name.upper() for name in book.sheetnames]
    for (sht, addr) in dests:
        if sheetname:
            sht = sheetname
        index = sheetnames_upper.index(sht.upper())
        xlranges.append(book.worksheets[index][addr])
    if (len(xlranges) == 1):
        return xlranges[0]
    else:
        return xlranges

Get range from a workbook.

A workbook can contain multiple definitions for a single name,
as a name can be defined for the entire book or for
a particular sheet.

If sheet is None, the book-wide def is searched,
otherwise sheet-local def is looked up.

Args:
book: An openpyxl workbook object.
rangename (str): Range expression, such as "A1", "$G4:$K10",
named range "NamedRange1".
sheetname (str, optional): None for book-wide name def,
sheet name for sheet-local named range.

Returns:
Range object specified by the name.


def add(self, files):

    if files.__class__.__name__ == 'str':
      self._files.append(files)
    else:
      self._files.extend(files)

Adds files to check.

Args:
files: List of files to check.


def search(self, q):
    results = self._api.search(q=q)
    return results

Search tweets by keyword.

Args:
q: keyword

Returns:
list: tweet list


def usufyToPngExport(d, fPath):
    newGraph = _generateGraphData(d)
    import matplotlib.pyplot as plt
    nx.draw(newGraph)
    plt.savefig(fPath)

Workaround to export to a png file.

Args:
-----
d: Data to export.
fPath: File path for the output file.


def __init__(self, downloader, read_buffer_size=io.DEFAULT_BUFFER_SIZE, mode='rb'):
    self._downloader = downloader
    self.mode = mode
    self._position = 0
    self._reader_buffer_size = read_buffer_size

Initializes the stream.

Args:
downloader: (Downloader) Filesystem dependent implementation.
read_buffer_size: (int) Buffer size to use during read operations.
mode: (string) Python mode attribute for this stream.


def _aspect_preserving_resize(image, resize_min):

  mlperf_log.resnet_print(key=mlperf_log.INPUT_RESIZE_ASPECT_PRESERVING,
                          value={"min": resize_min})

  shape = tf.shape(image)
  height, width = shape[0], shape[1]

  new_height, new_width = _smallest_size_at_least(height, width, resize_min)

  return _resize_image(image, new_height, new_width)

Resize images preserving the original aspect ratio.

Args:
image: A 3-D image `Tensor`.
resize_min: A python integer or scalar `Tensor` indicating the size of
the smallest side after resize.

Returns:
resized_image: A 3-D tensor containing the resized image.


def state_estimation_ensemble(data, k, n_runs=10, M_list=[], **se_params):

    if len(M_list)==0:
        M_list = []
        for i in range(n_runs):
            M, W, ll = poisson_estimate_state(data, k, **se_params)
            M_list.append(M)
    M_stacked = np.hstack(M_list)
    M_new, W_new, ll = poisson_estimate_state(M_stacked, k, **se_params)
    W_new = np.dot(data.T, M_new)
    W_new = W_new/W_new.sum(0)
    return M_new, W_new, ll

Runs an ensemble method on the list of M results...

Args:
data: genes x cells array
k: number of classes
n_runs (optional): number of random initializations of state estimation
M_list (optional): list of M arrays from state estimation
se_params (optional): optional poisson_estimate_state params

Returns:
M_new
W_new
ll


def _inf_or_operator_handler_factory(c_start, is_delegate=True):

    @coroutine
    def inf_or_operator_handler(c, ctx):
        next_ctx = None
        if (not is_delegate):
            ctx.value.append(c_start)
            (c, self) = (yield)
        else:
            assert (ctx.value[0] == c_start)
            assert (c not in _DIGITS)
            ctx.queue.unread(c)
            next_ctx = ctx
            (_, self) = (yield)
            assert (c == _)
        maybe_inf = True
        ctx.set_ion_type(IonType.FLOAT)
        match_index = 0
        trans = ctx.immediate_transition(self)
        while True:
            if maybe_inf:
                if (match_index < len(_INF_SUFFIX)):
                    maybe_inf = (c == _INF_SUFFIX[match_index])
                elif (_ends_value(c) or ((ctx.container.ion_type is IonType.SEXP) and (c in _OPERATORS))):
                    (yield ctx.event_transition(IonEvent, IonEventType.SCALAR, IonType.FLOAT, (((c_start == _MINUS) and _NEG_INF) or _POS_INF)))
                else:
                    maybe_inf = False
            if maybe_inf:
                match_index += 1
            else:
                ctx.set_unicode()
                if (match_index > 0):
                    next_ctx = ctx.derive_child_context(ctx.whence)
                    for ch in _INF_SUFFIX[0:match_index]:
                        next_ctx.value.append(ch)
                break
            (c, self) = (yield trans)
        if (ctx.container is not _C_SEXP):
            _illegal_character(c, (((next_ctx is None) and ctx) or next_ctx), ('Illegal character following %s.' % (_chr(c_start),)))
        if (match_index == 0):
            if (c in _OPERATORS):
                (yield ctx.immediate_transition(_operator_symbol_handler(c, ctx)))
            (yield ctx.event_transition(IonEvent, IonEventType.SCALAR, IonType.SYMBOL, ctx.value.as_symbol()))
        (yield _CompositeTransition(ctx.event_transition(IonEvent, IonEventType.SCALAR, IonType.SYMBOL, ctx.value.as_symbol()), ctx, partial(_unquoted_symbol_handler, c), next_ctx))
    return inf_or_operator_handler

Generates handler co-routines for values that may be `+inf` or `-inf`.

Args:
c_start (int): The ordinal of the character that starts this token (either `+` or `-`).
is_delegate (bool): True if a different handler began processing this token; otherwise, False. This will only
be true for `-inf`, because it is not the only value that can start with `-`; `+inf` is the only value
(outside of a s-expression) that can start with `+`.


def _read_tcp_options(self, size):
    counter = 0
    optkind = list()
    options = dict()
    while (counter < size):
        kind = self._read_unpack(1)
        opts = TCP_OPT.get(kind)
        enum = OPT_TYPE.get(kind)
        if (opts is None):
            len_ = (size - counter)
            counter = size
            optkind.append(enum)
            options[enum.name] = self._read_fileng(len_)
            break
        dscp = opts[1]
        if opts[0]:
            len_ = self._read_unpack(1)
            byte = opts[2](len_)
            if byte:
                data = process_opt[opts[3]](self, byte, kind)
            else:
                data = dict(kind=kind, length=2, flag=True)
        else:
            len_ = 1
            data = dict(kind=kind, length=1)
        counter += len_
        if (enum in optkind):
            if isinstance(options[dscp], tuple):
                options[dscp] += (Info(data),)
            else:
                options[dscp] = (Info(options[dscp]), Info(data))
        else:
            optkind.append(enum)
            options[dscp] = data
        if (not kind):
            break
    if (counter < size):
        len_ = (size - counter)
        options['padding'] = self._read_fileng(len_)
    return (tuple(optkind), options)

Read TCP option list.

Positional arguments:
* size -- int, length of option list

Returns:
* tuple -- TCP option list
* dict -- extracted TCP option


def write(self, x, access_logits):

    gamma = tf.layers.dense(x, 1, activation=tf.sigmoid, name="gamma")
    write_logits = access_logits - gamma * tf.expand_dims(self.mean_logits, 1)
    candidate_value = tf.layers.dense(x, self.val_depth,
                                      activation=tf.nn.relu,
                                      name="candidate_value")
    erase_gates = tf.layers.dense(x, self.memory_size,
                                  activation=tf.nn.sigmoid,
                                  name="erase")
    write_weights = tf.nn.softmax(write_logits)
    erase_weights = tf.expand_dims(1 - erase_gates * write_weights, 3)
    erase = tf.multiply(erase_weights,
                        tf.expand_dims(self.mem_vals, 1))
    addition = tf.multiply(
        tf.expand_dims(write_weights, 3),
        tf.expand_dims(candidate_value, 2))
    update_value_op = self.mem_vals.assign(
        tf.reduce_mean(erase + addition, axis=1))
    with tf.control_dependencies([update_value_op]):
      write_op = self.mean_logits.assign(
          self.mean_logits * 0.1 + tf.reduce_mean(write_logits * 0.9, axis=1))
      return write_op

Write to the memory based on a combination of similarity and least used.

Based on arXiv:1607.00036v2 [cs.LG].

Args:
x: a tensor in the shape of [batch_size, length, depth].
access_logits: the logits for accessing the memory.
Returns:
the update op.


def np2str(value):

    if hasattr(value, 'dtype') and \
            issubclass(value.dtype.type, (np.string_, np.object_)) and value.size == 1:
        value = np.asscalar(value)
        if not isinstance(value, str):

            value = value.decode()
        return value
    else:
        raise ValueError("Array is not a string type or is larger than 1")

Convert an `numpy.string_` to str.

Args:
value (ndarray): scalar or 1-element numpy array to convert

Raises:
ValueError: if value is array larger than 1-element or it is not of
type `numpy.string_` or it is not a numpy array


def compute_covariance(L_aug, Y, k, p):
    (n, d) = L_aug.shape
    assert (Y.shape[0] == n)
    mu = compute_mu(L_aug, Y, k, p)
    return (((L_aug.T @ L_aug) / n) - ((mu @ np.diag(p)) @ mu.T))

Given label matrix L_aug and labels Y, compute the covariance.

Args:
L: (np.array {0,1}) [n, d] The augmented (indicator) label matrix
Y: (np.array int) [n] The true labels in {1,...,k}
k: (int) Cardinality
p: (np.array float) [k] The class balance


def divide(x1, x2):
    if any_symbolic_tensors((x1, x2)):
        return Divide().symbolic_call(x1, x2)
    return backend.numpy.divide(x1, x2)

Divide arguments element-wise.

`keras.ops.true_divide` is an alias for this function.

Args:
x1: First input tensor.
x2: Second input tensor.

Returns:
Output tensor, the quotient `x1/x2`, element-wise.


def user_id(self):
    if self._user_id is None:
        self._user_id = self._adb.current_user_id
    return self._user_id

The user id to use for this snippet client.

All the operations of the snippet client should be used for a particular
user. For more details, see the Android documentation of testing
multiple users.

Thus this value is cached and, once set, does not change through the
lifecycles of this snippet client object. This caching also reduces the
number of adb calls needed.

Although for now self._user_id won't be modified once set, we use
`property` to avoid issuing adb commands in the constructor.

Returns:
An integer of the user id.


def create_table(bq_legacy_client: BigQueryLegacyClient, table_metadata: TableMetadata, schema: List[SchemaField]) -> Table:
    table_def = Table(table_metadata.full_table_id, schema=schema)
    table = bq_legacy_client.create_table(table_def)
    return table

Create a table in BigQuery given the ID and schema.

Note: Does NOT support nested columns.

Args:
* bq_legacy_client: BigQuery Legacy API client
* table_metadata: TableMetadata object
* schema: valid BigQuery table schema

Returns:
* Created Table object


def fileLoad(self, filePath=None, updatePath=True):
    if (not filePath):
        filePath = self.filePath
    if (not os.path.isfile(filePath)):
        raise FileNotFoundError(("Data file '%s' does not exist." % filePath))
    else:
        print(("Importing existing data file '%s' ... " % filePath), end='', flush=True)
        with open(filePath, 'r') as q:
            data_raw = q.read()
        print('Imported!')
        self.data = json.loads(data_raw)
        if updatePath:
            self.filePath = filePath

Load a JSON data file into the internal JSON data dictionary.

Current internal data will be overwritten.
If no file path is provided, the stored data file path will be used.

Args:
filePath (Optional[str]): A relative or absolute path to a
'.json' file. Defaults to None.
updatePath (Optional[bool]): Specifies whether or not to update
the stored data file path. Defaults to True.


def _get_sorted_inputs(filename):

  with tf.gfile.Open(filename) as f:
    records = f.read().split("\n")
    inputs = [record.strip() for record in records]
    if not inputs[-1]:
      inputs.pop()

  input_lens = [(i, len(line.split())) for i, line in enumerate(inputs)]
  sorted_input_lens = sorted(input_lens, key=lambda x: x[1], reverse=True)

  sorted_inputs = []
  sorted_keys = {}
  for i, (index, _) in enumerate(sorted_input_lens):
    sorted_inputs.append(inputs[index])
    sorted_keys[index] = i
  return sorted_inputs, sorted_keys

Read and sort lines from the file sorted by decreasing length.

Args:
filename: String name of file to read inputs from.
Returns:
Sorted list of inputs, and dictionary mapping original index->sorted index
of each element.


def retrieve(self, txid, headers=None):

        path = self.path + txid
        return self.transport.forward_request(
            method='GET', path=path, headers=None)

Retrieves the transaction with the given id.

Args:
txid (str): Id of the transaction to retrieve.
headers (dict): Optional headers to pass to the request.

Returns:
dict: The transaction with the given id.


def run():
    if not _SMCLI_INPUTS.value and (not _SMCLI_INPUT_EXPRS.value) and (not _SMCLI_INPUT_EXAMPLES.value):
        raise AttributeError('At least one of --inputs, --input_exprs or --input_examples must be required')
    tensor_key_feed_dict = load_inputs_from_input_arg_string(_SMCLI_INPUTS.value, _SMCLI_INPUT_EXPRS.value, _SMCLI_INPUT_EXAMPLES.value)
    run_saved_model_with_feed_dict(_SMCLI_DIR.value, _SMCLI_TAG_SET.value, _SMCLI_SIGNATURE_DEF.value, tensor_key_feed_dict, _SMCLI_OUTDIR.value, _SMCLI_OVERWRITE.value, worker=_SMCLI_WORKER.value, init_tpu=_SMCLI_INIT_TPU.value, use_tfrt=_SMCLI_USE_TFRT.value, tf_debug=_SMCLI_TF_DEBUG.value)

Function triggered by run command.

Raises:
AttributeError: An error when neither --inputs nor --input_exprs is passed
to run command.


def __call__(self, table: Union['pd.DataFrame', List['pd.DataFrame']]=None, query: Optional[Union[TextInput, List[TextInput]]]=None, answer: Optional[Union[str, List[str]]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, stride: int=0, pad_to_multiple_of: Optional[int]=None, return_tensors: Optional[Union[str, TensorType]]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_offsets_mapping: bool=False, return_length: bool=False, verbose: bool=True, **kwargs) -> BatchEncoding:
    if table is not None:
        return self.source_call_func(table=table, query=query, answer=answer, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, stride=stride, pad_to_multiple_of=pad_to_multiple_of, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)
    elif answer is not None:
        return self.target_call_func(answer=answer, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, stride=stride, pad_to_multiple_of=pad_to_multiple_of, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)
    else:
        raise ValueError('You need to provide either a `table` or an `answer`.')

Main method to tokenize and prepare for the model one or several table-sequence pair(s).

Args:
table (`pd.DataFrame`, `List[pd.DataFrame]`):
Table(s) containing tabular data.
query (`str` or `List[str]`, *optional*):
Sentence or batch of sentences related to one or more table(s) to be encoded. Note that the number of
sentences must match the number of tables.
answer (`str` or `List[str]`, *optional*):
Optionally, the corresponding answer to the questions as supervision.


def _get_output_columns(nodes, context):

    columns = []
    for node in nodes:
        for sql_output in sql_context_helpers.get_outputs(node, context):
            field_name = sql_output.field_name
            column = sql_context_helpers.get_column(field_name, node, context)
            column = column.label(sql_output.output_name)
            columns.append(column)
    return columns

Get the output columns for a list of SqlNodes.

Args:
nodes: List[SqlNode], the nodes to get output columns from.
context: CompilationContext, global compilation state and metadata.

Returns:
List[Column], list of SqlAlchemy Columns to output for this query.


def recode(self, table: pd.DataFrame, validate=False) -> pd.DataFrame:
    series = table[self.name]
    self._check_series_name(series)
    col = self.name
    data = series.copy()
    for recoder in self.recoders.values():
        try:
            data = recoder(data)
        except BaseException as err:
            raise RecodingError(col, recoder, err)
    if validate:
        failed_rows = find_failed_rows(self.validate(data.to_frame()))
        if (failed_rows.shape[0] > 0):
            raise ValidationError(f)
    return data.to_frame()

Pass the provided series obj through each recoder function sequentially and return the final result.

Args:
table (pd.DataFrame): A dataframe on which to apply recoding logic.
validate (bool): If ``True``, recoded table must pass validation tests.


def _FormatOpaqueToken(self, token_data):
    data = ''.join(['{0:02x}'.format(byte) for byte in token_data.data])
    return {'data': data}

Formats an opaque token as a dictionary of values.

Args:
token_data (bsm_token_data_opaque): AUT_OPAQUE token data.

Returns:
dict[str, str]: token values.


def mapped_repr_stripping_underscores(
        obj: Any, attrnames: List[str],
        with_addr: bool = False, joiner: str = COMMA_SPACE) -> str:

    attributes = []
    for attr_name in attrnames:
        if attr_name.startswith('_'):
            init_param_name = attr_name[1:]
        else:
            init_param_name = attr_name
        attributes.append((attr_name, init_param_name))
    return mapped_repr(obj, attributes, with_addr=with_addr, joiner=joiner)

Convenience function for :func:`__repr__`.
Here, you pass a list of internal attributes, and it assumes that the
:func:`__init__` parameter names have the leading underscore dropped.

Args:
obj: object to display
attrnames: list of attribute names
with_addr: include the memory address of ``obj``
joiner: string with which to join the elements

Returns:
string: :func:`repr`-style representation


def stop_condition(self, condition):
    for cond_format in self._known_conditions:
        try:
            cond = cond_format.FromString(condition)
            self.stop_conditions.append(cond)
            return
        except ArgumentError:
            continue
    raise ArgumentError('Stop condition could not be processed by any known StopCondition type', condition=condition, suggestion='It may be mistyped or otherwise invalid.')

Add a stop condition to this simulation.

Stop conditions are specified as strings and parsed into
the appropriate internal structures.

Args:
condition (str): a string description of the stop condition


def update_vm(access_token, subscription_id, resource_group, vm_name, body):

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

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

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

Returns:
HTTP response.


def save(self, path_info, checksum):

        assert path_info["scheme"] == "local"
        assert checksum is not None

        path = path_info["path"]
        assert os.path.exists(path)

        actual_mtime, actual_size = get_mtime_and_size(path)
        actual_inode = get_inode(path)

        existing_record = self.get_state_record_for_inode(actual_inode)
        if not existing_record:
            self._insert_new_state_record(
                path, actual_inode, actual_mtime, actual_size, checksum
            )
            return

        self._update_state_for_path_changed(
            path, actual_inode, actual_mtime, actual_size, checksum
        )

Save checksum for the specified path info.

Args:
path_info (dict): path_info to save checksum for.
checksum (str): checksum to save.


def cdna_transformation(prev_image, cdna_input, num_masks, color_channels,
                        dna_kernel_size, relu_shift):

  batch_size = tf.shape(cdna_input)[0]
  height = int(prev_image.get_shape()[1])
  width = int(prev_image.get_shape()[2])

  cdna_kerns = tfl.dense(
      cdna_input, dna_kernel_size * dna_kernel_size * num_masks,
      name="cdna_params",
      activation=None)

  cdna_kerns = tf.reshape(
      cdna_kerns, [batch_size, dna_kernel_size, dna_kernel_size, 1, num_masks])
  cdna_kerns = (tf.nn.relu(cdna_kerns - relu_shift) + relu_shift)
  norm_factor = tf.reduce_sum(cdna_kerns, [1, 2, 3], keep_dims=True)
  cdna_kerns /= norm_factor

  cdna_kerns = tf.transpose(cdna_kerns, [1, 2, 0, 4, 3])
  cdna_kerns = tf.reshape(
      cdna_kerns, [dna_kernel_size, dna_kernel_size, batch_size, num_masks])

  prev_image = tf.transpose(prev_image, [3, 1, 2, 0])

  transformed = tf.nn.depthwise_conv2d(
      prev_image, cdna_kerns, [1, 1, 1, 1], "SAME")

  transformed = tf.reshape(
      transformed, [color_channels, height, width, batch_size, num_masks])
  transformed = tf.transpose(transformed, [3, 1, 2, 0, 4])
  transformed = tf.unstack(transformed, axis=-1)
  return transformed

Apply convolutional dynamic neural advection to previous image.

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


def _on_fail(self, record):
    self.on_fail(record)

Proxy function to guarantee the base implementation of on_fail is
called.

Args:
record: records.TestResultRecord, a copy of the test record for
this test, containing all information of the test execution
including exception objects.


def register_handler(self, callable_obj, entrypoint, methods=('GET',)):

        router_obj = Route.wrap_callable(
            uri=entrypoint,
            methods=methods,
            callable_obj=callable_obj
        )

        if router_obj.is_valid:
            self._routes.add(router_obj)
            return self

        raise RouteError(
            "Missing params: methods: {} - entrypoint: {}".format(
                methods, entrypoint
            )
        )

Register a handler callable to a specific route.

Args:
entrypoint (str): The uri relative path.
methods (tuple): A tuple of valid method strings.
callable_obj (callable): The callable object.

Returns:
The Router instance (for chaining purposes).

Raises:
RouteError, for missing routing params or invalid callable
object type.


def render(self, mode=None, vertices=-1, *, first=0, instances=1) -> None:

        if mode is None:
            mode = TRIANGLES

        self.mglo.render(mode, vertices, first, instances)

The render primitive (mode) must be the same as
the input primitive of the GeometryShader.

Args:
mode (int): By default :py:data:`TRIANGLES` will be used.
vertices (int): The number of vertices to transform.

Keyword Args:
first (int): The index of the first vertex to start with.
instances (int): The number of instances.


def run(self, resources):

        hwman = resources['connection']

        updater = hwman.hwman.app(name='device_updater')
        updater.run_script(self._script, no_reboot=self._no_reboot)

Actually send the trub script.

Args:
resources (dict): A dictionary containing the required resources that
we needed access to in order to perform this step.


class AriaProjector(nn.Module):

    def __init__(self, config: AriaConfig):
        super().__init__()
        self.patch_to_query_dict = config.projector_patch_to_query_dict
        self.in_features = config.vision_config.hidden_size
        self.num_heads = config.vision_config.num_attention_heads
        self.kv_dim = config.vision_config.hidden_size
        self.hidden_features = config.text_config.hidden_size
        self.output_dim = config.text_config.hidden_size
        self.query = nn.Parameter(torch.zeros(config.max_value_projector_patch_to_query_dict, self.in_features))
        self.cross_attn = AriaCrossAttention(config)
        self.layer_norm = nn.LayerNorm(self.in_features)
        self.feed_forward = AriaProjectorMLP(self.in_features, self.hidden_features, self.output_dim)

    def forward(self, key_value_states: torch.Tensor, attn_mask: Optional[torch.Tensor]=None):

        batch_size, num_patches = (key_value_states.shape[0], key_value_states.shape[1])
        if num_patches not in self.patch_to_query_dict.keys():
            raise KeyError(f'Number of patches {num_patches} not found in patch_to_query_dict amongst possible values {self.patch_to_query_dict.keys()}.')
        query_num = self.patch_to_query_dict[num_patches]
        queries = self.query[:query_num].unsqueeze(0).repeat(batch_size, 1, 1)
        if attn_mask is not None:
            attn_mask = attn_mask.repeat_interleave(self.num_heads, 0)
            attn_mask = attn_mask.unsqueeze(1).expand(-1, queries.size(1), -1)
        attention_out = self.cross_attn(key_value_states, queries, attn_mask=attn_mask)
        out = self.feed_forward(self.layer_norm(attention_out))
        return out

Aria Projector module.

This module projects vision features into the language model's embedding space, enabling interaction between vision and language components.

Args:
config (`AriaConfig`):
Configuration object for the model.


def ParseNetworkDataUsage(self, parser_mediator, cache=None, database=None, table=None, **unused_kwargs):
    self._ParseGUIDTable(parser_mediator, cache, database, table, self._NETWORK_DATA_USAGE_VALUES_MAP, SRUMNetworkDataUsageEventData)

Parses the network data usage monitor table.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
cache (Optional[ESEDBCache]): cache, which contains information about
the identifiers stored in the SruDbIdMapTable table.
database (Optional[pyesedb.file]): ESE database.
table (Optional[pyesedb.table]): table.


def corpus_token_counts(
    text_filepattern, corpus_max_lines, split_on_newlines=True):

  counts = collections.Counter()
  for doc in _read_filepattern(
      text_filepattern,
      max_lines=corpus_max_lines,
      split_on_newlines=split_on_newlines):
    counts.update(encode(_native_to_unicode(doc)))

  mlperf_log.transformer_print(
      key=mlperf_log.PREPROC_VOCAB_SIZE, value=len(counts))
  return counts

Read the corpus and compute a dictionary of token counts.

Args:
text_filepattern: A pattern matching one or more files.
corpus_max_lines: An integer; maximum total lines to read.
split_on_newlines: A boolean. If true, then split files by lines and strip
leading and trailing whitespace from each line. Otherwise, treat each
file as a single string.

Returns:
a dictionary mapping token to count.


def set_image_data_format(data_format):
    global _IMAGE_DATA_FORMAT
    if data_format not in {'channels_last', 'channels_first'}:
        raise ValueError('Unknown data_format: ' + str(data_format))
    _IMAGE_DATA_FORMAT = str(data_format)

Sets the value of the image data format convention.

Args:
data_format: string. `'channels_first'` or `'channels_last'`.

Example:
>>> tf.keras.backend.image_data_format()
'channels_last'
>>> tf.keras.backend.set_image_data_format('channels_first')
>>> tf.keras.backend.image_data_format()
'channels_first'
>>> tf.keras.backend.set_image_data_format('channels_last')

Raises:
ValueError: In case of invalid `data_format` value.


def _get_target(self, target):

        depth = target.count('.') + 1
        parts = target.split('.', 1)
        for m in self.modules:
            if parts[0] == m.name:
                if depth < 3:
                    return m
        for p in self.packages:
            if parts[0] == p.name:
                if depth == 1:
                    return p

                target = p._get_target(parts[1])
                if target:
                    return target

                if depth < 3:
                    return p
        return None

Get the Package or Module related to given target.

Args:
target (str): target to find.

Returns:
Package/Module: package containing target or corresponding module.


def enable_extana_streaming(self, include_imu=False, enabled_sensors=SENSOR_ALL):
    if (not self.dongle._enable_extana_streaming(self, include_imu, enabled_sensors)):
        logger.warn('Failed to enable SK8-ExtAna streaming!')
        return False
    if include_imu:
        self.enabled_imus = [0]
    return True

Configures and enables sensor data streaming from the SK8-ExtAna device.

By default this will cause the SK8 to only stream data from the analog
sensors on the SK8-ExtAna, but if `include_imu` is set to True, it will
also send data from the internal IMU in the SK8.

NOTE: only one streaming mode can be active at any time, so e.g. if you
want to stream IMU data normally, you must disable SK8-ExtAna streaming first.

Args:
include_imu (bool): If False, only SK8-ExtAna packets will be streamed.
If True, the device will also stream data from the SK8's internal IMU.
enabled_sensors (int): If `include_imu` is True, this can be used to
select which IMU sensors will be active.

Returns:
bool. True if successful, False if an error occurred.


def from_json(cls, data):

        user = cls()

        user.user_id = data['userId']
        user.username = data['username']
        user.auth_system = data['authSystem']
        user.roles = data['roles']

        return user

Return object based on JSON / dict input

Args:
data (dict): Dictionary containing a serialized User object

Returns:
:obj:`User`: User object representing the data


def requires_submit(func):

    @functools.wraps(func)
    def _wrapper(self, *args, **kwargs):
        if (self._future is None):
            raise JobError('Job not submitted yet!. You have to .submit() first!')
        return func(self, *args, **kwargs)
    return _wrapper

Decorator to ensure that a submit has been performed before
calling the method.

Args:
func (callable): test function to be decorated.

Returns:
callable: the decorated function.


def __init__(self, app, sender_email=None, sender_name=None):

        super(SendmailEmailAdapter, self).__init__(app)

        try:
            from flask_sendmail import Mail
        except ImportError:
            raise ConfigError(
                "The Flask-Sendmail package is missing. Install Flask-Sendmail with 'pip install Flask-Sendmail'.")
        self.mail = Mail(app)

Check config settings and setup Flask-Sendemail.

Args:
app(Flask): The Flask application instance.


def listen(self, orb, listeners):

        if isinstance(listeners, Listener):
            listeners = [listeners]

        orb.event = None
        results = []
        for listener in listeners:
            if listener.check(orb):
                results.append(self._bisect(listener.prev, orb, listener))

            listener.prev = orb
        return sorted(results, key=lambda x: x.date)

This method allows to loop over the listeners and trigger the :py:meth:`_bisect` method
in case a watched parameter has its state changed.

Args:
orb (Orbit): The current state of the orbit
listeners (iterable): List of Listener objects
Return:
list of Orbit: Orbits corresponding to events, sorted by dates


def predict(self, data, graph=None, nruns=6, njobs=None, gpus=0, verbose=None, plot=False, plot_generated_pair=False, return_list_results=False):
    (verbose, njobs) = SETTINGS.get_default(('verbose', verbose), ('nb_jobs', njobs))
    if (njobs != 1):
        list_out = Parallel(n_jobs=njobs)((delayed(run_SAM)(data, skeleton=graph, lr_gen=self.lr, lr_disc=self.dlr, regul_param=self.l1, nh=self.nh, dnh=self.dnh, gpu=bool(gpus), train_epochs=self.train, test_epochs=self.test, batch_size=self.batchsize, plot=plot, verbose=verbose, gpu_no=(idx % max(gpus, 1))) for idx in range(nruns)))
    else:
        list_out = [run_SAM(data, skeleton=graph, lr_gen=self.lr, lr_disc=self.dlr, regul_param=self.l1, nh=self.nh, dnh=self.dnh, gpu=bool(gpus), train_epochs=self.train, test_epochs=self.test, batch_size=self.batchsize, plot=plot, verbose=verbose, gpu_no=0) for idx in range(nruns)]
    if return_list_results:
        return list_out
    else:
        W = list_out[0]
        for w in list_out[1:]:
            W += w
        W /= nruns
    return nx.relabel_nodes(nx.DiGraph(W), {idx: i for (idx, i) in enumerate(data.columns)})

Execute SAM on a dataset given a skeleton or not.

Args:
data (pandas.DataFrame): Observational data for estimation of causal relationships by SAM
skeleton (numpy.ndarray): A priori knowledge about the causal relationships as an adjacency matrix.
Can be fed either directed or undirected links.
nruns (int): Number of runs to be made for causal estimation.
Recommended: >=12 for optimal performance.
njobs (int): Numbers of jobs to be run in Parallel.
Recommended: 1 if no GPU available, 2*number of GPUs else.
gpus (int): Number of available GPUs for the algorithm.
verbose (bool): verbose mode
plot (bool): Plot losses interactively. Not recommended if nruns>1
plot_generated_pair (bool): plots a generated pair interactively.  Not recommended if nruns>1
Returns:
networkx.DiGraph: Graph estimated by SAM, where A[i,j] is the term
of the ith variable for the jth generator.


class _StatelessThresholdDoFn(_BaseThresholdDoFn):

    def __init__(self, threshold_fn_spec: Spec):
        assert isinstance(threshold_fn_spec.config, dict)
        threshold_fn_spec.config['_run_init'] = True
        self._threshold_fn = Specifiable.from_spec(threshold_fn_spec)
        assert isinstance(self._threshold_fn, ThresholdFn)
        assert not self._threshold_fn.is_stateful, 'This DoFn can only take stateless function as threshold_fn'

    def process(self, element: NestedKeyedOutputT, **kwargs) -> Iterable[NestedKeyedOutputT]:

        k1, (k2, result) = element
        yield (k1, (k2, self._apply_threshold_to_predictions(result)))

Applies a stateless ThresholdFn to anomaly detection results.

This DoFn is designed for stateless `ThresholdFn` implementations. It
initializes the `ThresholdFn` once during setup and applies it to each
incoming element without maintaining any state across elements.

Args:
threshold_fn_spec (Spec): Specification defining the `ThresholdFn` to be
used.

Raises:
AssertionError: If the provided `threshold_fn_spec` leads to the
creation of a stateful `ThresholdFn`.


def residual_block_v2(x, filters, kernel_size=3, stride=1, conv_shortcut=False, name=None):
    if backend.image_data_format() == 'channels_last':
        bn_axis = 3
    else:
        bn_axis = 1
    preact = layers.BatchNormalization(axis=bn_axis, epsilon=1.001e-05, name=name + '_preact_bn')(x)
    preact = layers.Activation('relu', name=name + '_preact_relu')(preact)
    if conv_shortcut:
        shortcut = layers.Conv2D(4 * filters, 1, strides=stride, name=name + '_0_conv')(preact)
    else:
        shortcut = layers.MaxPooling2D(1, strides=stride)(x) if stride > 1 else x
    x = layers.Conv2D(filters, 1, strides=1, use_bias=False, name=name + '_1_conv')(preact)
    x = layers.BatchNormalization(axis=bn_axis, epsilon=1.001e-05, name=name + '_1_bn')(x)
    x = layers.Activation('relu', name=name + '_1_relu')(x)
    x = layers.ZeroPadding2D(padding=((1, 1), (1, 1)), name=name + '_2_pad')(x)
    x = layers.Conv2D(filters, kernel_size, strides=stride, use_bias=False, name=name + '_2_conv')(x)
    x = layers.BatchNormalization(axis=bn_axis, epsilon=1.001e-05, name=name + '_2_bn')(x)
    x = layers.Activation('relu', name=name + '_2_relu')(x)
    x = layers.Conv2D(4 * filters, 1, name=name + '_3_conv')(x)
    x = layers.Add(name=name + '_out')([shortcut, x])
    return x

A residual block for ResNet*_v2.

Args:
x: Input tensor.
filters: No of filters in the bottleneck layer.
kernel_size: Kernel size of the bottleneck layer. Defaults to `3`.
stride: Stride of the first layer. Defaults to `1`.
conv_shortcut: Use convolution shortcut if `True`, otherwise
use identity shortcut. Defaults to `True`
name(optional): Name of the block

Returns:
Output tensor for the residual block.


def ip_address(address):

    try:
        return IPv4Address(address)
    except (AddressValueError, NetmaskValueError):
        pass

    try:
        return IPv6Address(address)
    except (AddressValueError, NetmaskValueError):
        pass

    raise ValueError('%r does not appear to be an IPv4 or IPv6 address' %
                     address)

Take an IP string/int and return an object of the correct type.

Args:
address: A string or integer, the IP address.  Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.

Returns:
An IPv4Address or IPv6Address object.

Raises:
ValueError: if the *address* passed isn't either a v4 or a v6
address


def get_encoding(path):

    def check_ascii(_data):

        try:
            _data.decode('ASCII')
            log.debug('Found ASCII')
        except UnicodeDecodeError:
            return False
        else:
            return True

    def check_bom(_data):

        boms = [
            ('UTF-32-BE', salt.utils.stringutils.to_bytes(codecs.BOM_UTF32_BE)),
            ('UTF-32-LE', salt.utils.stringutils.to_bytes(codecs.BOM_UTF32_LE)),
            ('UTF-16-BE', salt.utils.stringutils.to_bytes(codecs.BOM_UTF16_BE)),
            ('UTF-16-LE', salt.utils.stringutils.to_bytes(codecs.BOM_UTF16_LE)),
            ('UTF-8', salt.utils.stringutils.to_bytes(codecs.BOM_UTF8)),
            ('UTF-7', salt.utils.stringutils.to_bytes('\x2b\x2f\x76\x38\x2D')),
            ('UTF-7', salt.utils.stringutils.to_bytes('\x2b\x2f\x76\x38')),
            ('UTF-7', salt.utils.stringutils.to_bytes('\x2b\x2f\x76\x39')),
            ('UTF-7', salt.utils.stringutils.to_bytes('\x2b\x2f\x76\x2b')),
            ('UTF-7', salt.utils.stringutils.to_bytes('\x2b\x2f\x76\x2f')),
        ]
        for _encoding, bom in boms:
            if _data.startswith(bom):
                log.debug('Found BOM for %s', _encoding)
                return _encoding
        return False

    def check_utf8_markers(_data):
        try:
            decoded = _data.decode('UTF-8')
        except UnicodeDecodeError:
            return False
        else:

            if six.PY2:
                for char in decoded:
                    if 0xD800 <= ord(char) <= 0xDFFF:
                        return False
            return True

    def check_system_encoding(_data):
        try:
            _data.decode(__salt_system_encoding__)
        except UnicodeDecodeError:
            return False
        else:
            return True

    if not os.path.isfile(path):
        raise CommandExecutionError('Not a file')
    try:
        with fopen(path, 'rb') as fp_:
            data = fp_.read(2048)
    except os.error:
        raise CommandExecutionError('Failed to open file')

    encoding = check_bom(data)
    if encoding:
        return encoding

    if check_utf8_markers(data):
        return 'UTF-8'

    if check_system_encoding(data):
        return __salt_system_encoding__

    if check_ascii(data):
        return 'ASCII'

    raise CommandExecutionError('Could not detect file encoding')

Detect a file's encoding using the following:
- Check for Byte Order Marks (BOM)
- Check for UTF-8 Markers
- Check System Encoding
- Check for ascii

Args:

path (str): The path to the file to check

Returns:
str: The encoding of the file

Raises:
CommandExecutionError: If the encoding cannot be detected


def _paginate_expand_value_set_request(request_func: Callable[[int], requests.Response], value_set_url: str, value_set_version: Optional[str]) -> value_set_pb2.ValueSet:
    offset = 0
    codes: List[value_set_pb2.ValueSet.Expansion.Contains] = []
    while True:
        resp = request_func(offset)
        if resp.status_code >= 400:
            logging.error('Error from terminology service: %s', resp.text)
        resp.raise_for_status()
        resp_json = resp.json()
        response_value_set = json_format.json_fhir_object_to_proto(resp_json, value_set_pb2.ValueSet, validate=False)
        codes.extend(response_value_set.expansion.contains)
        offset += len(resp_json['expansion'].get('contains', ()))
        if 'total' not in resp_json['expansion'] or offset >= resp_json['expansion']['total']:
            del response_value_set.expansion.contains[:]
            response_value_set.expansion.contains.extend(codes)
            response_value_set.url.value = value_set_url
            if value_set_version is not None:
                response_value_set.version.value = value_set_version
            return response_value_set

Performs a request to the terminology service, including pagination.

Given a function which performs a request against a terminology service, use
the function to make requests until the full response has been paginated
through.

Args:
request_func: The function to call to perform a request to the terminology
service. The function must accept an integer representing the pagination
offset value to include in the request and return a requests Response
object.
value_set_url: The URL of the value set being expanded.
value_set_version: The version of the value set being expanded.

Returns:
The current definition of the value set from the server with its expanded
codes present.


def _find_image_files(data_dir, labels_file):
    print(('Determining list of input files and labels from %s.' % data_dir))
    unique_labels = [l.strip() for l in tf.gfile.FastGFile(labels_file, 'r').readlines()]
    labels = []
    filenames = []
    texts = []
    label_index = 1
    for text in unique_labels:
        jpeg_file_path = ('%s/%s/*' % (data_dir, text))
        matching_files = tf.gfile.Glob(jpeg_file_path)
        labels.extend(([label_index] * len(matching_files)))
        texts.extend(([text] * len(matching_files)))
        filenames.extend(matching_files)
        if (not (label_index % 100)):
            print(('Finished finding files in %d of %d classes.' % (label_index, len(labels))))
        label_index += 1
    shuffled_index = list(range(len(filenames)))
    random.seed(12345)
    random.shuffle(shuffled_index)
    filenames = [filenames[i] for i in shuffled_index]
    texts = [texts[i] for i in shuffled_index]
    labels = [labels[i] for i in shuffled_index]
    print(('Found %d JPEG files across %d labels inside %s.' % (len(filenames), len(unique_labels), data_dir)))
    return (filenames, texts, labels)

Build a list of all images files and labels in the data set.

Args:
data_dir: string, path to the root directory of images.

Assumes that the image data set resides in JPEG files located in
the following directory structure.

data_dir/dog/another-image.JPEG
data_dir/dog/my-image.jpg

where 'dog' is the label associated with these images.

labels_file: string, path to the labels file.

The list of valid labels are held in this file. Assumes that the file
contains entries as such:
dog
cat
flower
where each line corresponds to a label. We map each label contained in
the file to an integer starting with the integer 0 corresponding to the
label contained in the first line.

Returns:
filenames: list of strings; each string is a path to an image file.
texts: list of strings; each string is the class, e.g. 'dog'
labels: list of integer; each integer identifies the ground truth.


def __init__(self, channel):

        self.CreateClientEvent = channel.unary_unary(
            "/google.cloud.talent.v4beta1.EventService/CreateClientEvent",
            request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_event__service__pb2.CreateClientEventRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_event__pb2.ClientEvent.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def write_file(self, filename, *, overwrite=False):
    if (exists(filename) and (not overwrite)):
        raise OSError((filename + ' already present. Specify "overwrite=True" to overwrite, or rename.'))
    with open(filename, 'w') as yaml_file:
        yaml.dump(self._properties, yaml_file)

Write new ChemKED YAML file based on object.

Arguments:
filename (`str`): Filename for target YAML file
overwrite (`bool`, optional): Whether to overwrite file with given name if present.
Must be supplied as a keyword-argument.

Raises:
`NameError`: If ``filename`` is already present, and ``overwrite`` is not ``True``.

Example:
>>> dataset = ChemKED(yaml_file)
>>> dataset.write_file(new_yaml_file)


def delete(self, url=None, post_data={}, parse_data=False, key=None, parameters=None):
    return self._fetch('DELETE', url, post_data=post_data, parse_data=parse_data, key=key, parameters=parameters, full_return=True)

Issue a PUT request.

Kwargs:
url (str): Destination URL
post_data (dict): Dictionary of parameter and values
parse_data (bool): If true, parse response data
key (string): If parse_data==True, look for this key when parsing data
parameters (dict): Additional GET parameters to append to the URL

Returns:
dict. Response (a dict with keys: success, data, info, body)

Raises:
AuthenticationError, ConnectionError, urllib2.HTTPError, ValueError, Exception


def get_log_level(args):

    index = -1
    log_level = None
    if '<command>' in args and args['<command>']:
        index = sys.argv.index(args['<command>'])
    if args.get('--debug'):
        log_level = 'DEBUG'
        if '--debug' in sys.argv and sys.argv.index('--debug') < index:
            sys.argv.remove('--debug')
        elif '-d' in sys.argv and sys.argv.index('-d') < index:
            sys.argv.remove('-d')
    elif args.get('--verbose'):
        log_level = 'INFO'
        if '--verbose' in sys.argv and sys.argv.index('--verbose') < index:
            sys.argv.remove('--verbose')
        elif '-v' in sys.argv and sys.argv.index('-v') < index:
            sys.argv.remove('-v')
    elif args.get('--log-level'):
        log_level = args['--log-level']
        sys.argv.remove('--log-level')
        sys.argv.remove(log_level)
    if log_level not in (None, 'DEBUG', 'INFO', 'WARN', 'ERROR'):
        raise exceptions.InvalidLogLevelError(log_level)
    return getattr(logging, log_level) if log_level else None

Get the log level from the CLI arguments.

Removes logging arguments from sys.argv.

Args:
args: The parsed docopt arguments to be used to determine the logging
level.

Returns:
The correct log level based on the three CLI arguments given.

Raises:
ValueError: Raised if the given log level is not in the acceptable
list of values.


def VerifyRow(self, parser_mediator, row):

    if len(row) < self.MIN_COLUMNS:
      return False

    try:
      timestamp = self._ConvertToTimestamp(row['date'], row['time'])
    except ValueError:
      return False

    if timestamp is None:
      return False

    try:
      block_mode = int(row['block_mode'], 10)
    except (ValueError, TypeError):
      return False

    if block_mode not in formatter.BLOCK_MODES:
      return False
    return True

Verifies if a line of the file is in the expected format.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
row (dict[str, str]): fields of a single row, as specified in COLUMNS.

Returns:
bool: True if this is the correct parser, False otherwise.


def play_match(black_model, white_model, games, sgf_dir):

    with utils.logged_timer("Loading weights"):
        black_net = dual_net.DualNetwork(black_model)
        white_net = dual_net.DualNetwork(white_model)

    readouts = FLAGS.num_readouts

    black = MCTSPlayer(black_net, two_player_mode=True)
    white = MCTSPlayer(white_net, two_player_mode=True)

    black_name = os.path.basename(black_net.save_file)
    white_name = os.path.basename(white_net.save_file)

    for i in range(games):
        num_move = 0

        for player in [black, white]:
            player.initialize_game()
            first_node = player.root.select_leaf()
            prob, val = player.network.run(first_node.position)
            first_node.incorporate_results(prob, val, first_node)

        while True:
            start = time.time()
            active = white if num_move % 2 else black
            inactive = black if num_move % 2 else white

            current_readouts = active.root.N
            while active.root.N < current_readouts + readouts:
                active.tree_search()

            if FLAGS.verbose >= 3:
                print(active.root.position)

            if active.should_resign():
                active.set_result(-1 *
                                  active.root.position.to_play, was_resign=True)
                inactive.set_result(
                    active.root.position.to_play, was_resign=True)

            if active.is_done():
                fname = "{:d}-{:s}-vs-{:s}-{:d}.sgf".format(int(time.time()),
                                                            white_name, black_name, i)
                active.set_result(active.root.position.result(), was_resign=False)
                with gfile.GFile(os.path.join(sgf_dir, fname), 'w') as _file:
                    sgfstr = sgf_wrapper.make_sgf(active.position.recent,
                                                  active.result_string, black_name=black_name,
                                                  white_name=white_name)
                    _file.write(sgfstr)
                print("Finished game", i, active.result_string)
                break

            move = active.pick_move()
            active.play_move(move)
            inactive.play_move(move)

            dur = time.time() - start
            num_move += 1

            if (FLAGS.verbose > 1) or (FLAGS.verbose == 1 and num_move % 10 == 9):
                timeper = (dur / readouts) * 100.0
                print(active.root.position)
                print("%d: %d readouts, %.3f s/100. (%.2f sec)" % (num_move,
                                                                   readouts,
                                                                   timeper,
                                                                   dur))

Plays matches between two neural nets.

Args:
black_model: Path to the model for black player
white_model: Path to the model for white player


def read_counts(node):

  cfg.forward(node, cfg.ReachingDefinitions())

  rc = ReadCounts()
  rc.visit(node)
  return rc.n_read

Check how many times a variable definition was used.

Args:
node: An AST to analyze.

Returns:
A dictionary from assignment nodes to the number of times the assigned to
variable was used.


def get_build_output(self, process):
    while True:
        output = process.stdout.readline()
        if ((output == b'') and (process.poll() is not None)):
            if (process.returncode > 0):
                raise Exception(('Compilation ended with an error.\nSTDERR\n%s\nSTDOUT\n%s' % (process.stderr.read(), process.stdout.read())))
            return
        if output:
            matches = re.search('\\[\\s*(\\d+?)/(\\d+)\\].*', output.strip().decode('utf-8'))
            if (matches is not None):
                (yield [int(matches.group(1)), int(matches.group(2))])

Parse the output of the ns-3 build process to extract the information
that is needed to draw the progress bar.

Args:
process: the subprocess instance to listen to.


def setup(self, timezone=None):
    self._timezone = timezone
    self._output_path = tempfile.mkdtemp()

Sets up the _timezone attribute.

Args:
timezone: Timezone name (optional)


def expand_docstring(**kwargs):

    def _fn_wrapped(fn):
        'Original function with modified `__doc__` attribute.'
        doc = inspect.cleandoc(fn.__doc__)
        for (k, v) in six.iteritems(kwargs):
            pattern = (('\\$\\{' + str(k)) + '\\}')
            doc = re.sub(pattern, (lambda match: v), doc)
        fn.__doc__ = doc
        return fn
    return _fn_wrapped

Decorator to programmatically expand the docstring.

Args:
**kwargs: Keyword arguments to set. For each key-value pair `k` and `v`,
the key is found as `${k}` in the docstring and replaced with `v`.

Returns:
Decorated function.


def _get_weighted_mean_squared_error(self, quant_min, quant_max) -> tuple[float, float, float]:
    dequantized_hist_mids = self._get_dequantized_hist_mids_after_quantize(quant_min, quant_max)
    squared_error = (self._hist_mids - dequantized_hist_mids) ** 2
    weighted_error = np.sum(squared_error * self._hist_freq)
    return (weighted_error, quant_min, quant_max)

Gets mean squared error between hist_mids and dequantized hist_mids.

Quantization converts the range of numbers from [quant_min, quant_max] to
[0, 2^num_bits - 1]. Values less than quant_min are converted to 0, and
values greater than quant_max are converted to 2^num_bits - 1.

Args:
quant_min: The minimum real value that can be represented by a quantized
value.
quant_max: The maximum real value that can be represented by a quantized
value.

Returns:
(error, quant_min, quant_max): Tuple of weighted mean squared error.
error = (hist_mids - dequantized_hist_mids)**2 * hist_freq


def __init__(self, shape, mean=0.0, log_stddev=0.0, scope='gaussian', summary_labels=()):

        self.shape = shape
        action_size = util.prod(self.shape)

        self.mean = Linear(size=action_size, bias=mean, scope='mean', summary_labels=summary_labels)
        self.log_stddev = Linear(size=action_size, bias=log_stddev, scope='log-stddev', summary_labels=summary_labels)

        super(Gaussian, self).__init__(shape=shape, scope=scope, summary_labels=summary_labels)

Categorical distribution.

Args:
shape: Action shape.
mean: Optional distribution bias for the mean.
log_stddev: Optional distribution bias for the standard deviation.