def _GetDictFromStringsTable(self, parser_mediator, table):
    if (not table):
        return {}
    record_values = {}
    for record in table.records:
        if parser_mediator.abort:
            break
        if (record.get_number_of_values() != 2):
            continue
        identification = self._GetRecordValue(record, 0)
        filename = self._GetRecordValue(record, 1)
        if (not identification):
            continue
        record_values[identification] = filename
    return record_values

Build a dictionary of the value in the strings table.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
table (pyesedb.table): strings table.

Returns:
dict[str,object]: values per column name.


def __init__(self, schema, max_files_per_bundle=_DEFAULT_MAX_WRITERS_PER_BUNDLE, max_file_size=_DEFAULT_MAX_FILE_SIZE, file_format=None):
    self.schema = schema
    self.max_files_per_bundle = max_files_per_bundle
    self.max_file_size = max_file_size
    self.file_format = file_format or bigquery_tools.FileFormat.JSON

Initialize a :class:`WriteRecordsToFile`.

Args:
max_files_per_bundle (int): The maximum number of files that can be kept
open during execution of this step in a worker. This is to avoid over-
whelming the worker memory.
max_file_size (int): The maximum size in bytes for a file to be used in
an export job.


def set_agent(self, agent):

        self.agent = agent
        self.queue = asyncio.Queue(loop=self.agent.loop)
        self.presence = agent.presence
        self.web = agent.web

Links behaviour with its owner agent

Args:
agent (spade.agent.Agent): the agent who owns the behaviour


def __init__(self, initial_learning_rate, decay_steps, initial_variance=1.0, variance_decay=0.55, num_periods=0.5, alpha=0.0, beta=0.001, name=None):
    super(NoisyLinearCosineDecay, self).__init__()
    self.initial_learning_rate = initial_learning_rate
    self.decay_steps = decay_steps
    self.initial_variance = initial_variance
    self.variance_decay = variance_decay
    self.num_periods = num_periods
    self.alpha = alpha
    self.beta = beta
    self.name = name

Applies noisy linear cosine decay to the learning rate.

Args:
initial_learning_rate: A scalar `float32` or `float64` Tensor or a Python
number. The initial learning rate.
decay_steps: A scalar `int32` or `int64` `Tensor` or a Python number.
Number of steps to decay over.
initial_variance: initial variance for the noise. See computation above.
variance_decay: decay for the noise's variance. See computation above.
num_periods: Number of periods in the cosine part of the decay.
See computation above.
alpha: See computation above.
beta: See computation above.
name: String.  Optional name of the operation.  Defaults to
'NoisyLinearCosineDecay'.


def _generate_unique_name(self, symbol_name: str) -> str:
    normalized_symbol_name = self._NON_SYMBOL_NAME_CHARS_REGEX.sub('_', symbol_name)
    normalized_name_conflict_count = self._num_symbols_with_normalized_name.get(normalized_symbol_name, 0)
    self._num_symbols_with_normalized_name[normalized_symbol_name] = normalized_name_conflict_count + 1
    optional_disambiguation_suffix = '' if normalized_name_conflict_count == 0 else f'_{normalized_name_conflict_count}'
    return f'{normalized_symbol_name}{optional_disambiguation_suffix}'

Translates a symbol name to a unique FileCheck capture name.

Replaces all characters other than letters, numbers, and underscores with
underscores. If the resulting name has already been used, appends a counter
to disambiguate it. For example, this could result in the following sequence
of replacements:
1.) "foo.bar.baz" -> "foo_bar_baz"
2.) "foo.bar_baz" -> "foo_bar_baz_1"
3.) "foo_bar.baz" -> "foo_bar_baz_2"
4.) "foo_bar_baz" -> "foo_bar_baz_3"

Args:
symbol_name: The original symbol name.

Returns:
The generated FileCheck capture name.


def load_and_print_resfile(filename, info_dict=None):
    if (info_dict is None):
        info_dict = dict()
        info_dict['mass'] = 1.23
        info_dict['nom_cap'] = 3600
        info_dict['tot_mass'] = 2.33
    d = CellpyData()
    print('filename:', filename)
    print('info_dict in:', end=' ')
    print(info_dict)
    d.from_raw(filename)
    d.set_mass(info_dict['mass'])
    d.make_step_table()
    d.make_summary()
    for test in d.datasets:
        print('newtest')
        print(test)
    return info_dict

Load a raw data file and print information.

Args:
filename (str): name of the resfile.
info_dict (dict):

Returns:
info (str): string describing something.


def compress(element):
    element_spec = structure.type_spec_from_value(element)
    tensor_list = structure.to_tensor_list(element_spec, element)
    return ged_ops.compress_element(tensor_list)

Compress a dataset element.

Args:
element: A nested structure of types supported by Tensorflow.

Returns:
A variant tensor representing the compressed element. This variant can be
passed to `uncompress` to get back the original element.


def _RemoveAllFlagAppearances(self, name):
    flag_dict = self.FlagDict()
    if (name not in flag_dict):
        raise exceptions.UnrecognizedFlagError(name)
    flag = flag_dict[name]
    names_to_remove = {name}
    names_to_remove.add(flag.name)
    if flag.short_name:
        names_to_remove.add(flag.short_name)
    for n in names_to_remove:
        self.__delattr__(n)

Removes flag with name for all appearances.

A flag can be registered with its long name and an optional short name.
This method removes both of them. This is different than __delattr__.

Args:
name: Either flag's long name or short name.

Raises:
UnrecognizedFlagError: When flag name is not found.


def test_enrichment(pcoll, enrichment_handler: str, handler_config: Dict[str, Any], timeout: Optional[float]=30):
    if enrichment_handler == 'BigTable':
        row_key = handler_config['row_key']
        bt_data = INPUT_TABLES['BigTable', handler_config['instance_id'], handler_config['table_id']]
        products = {str(data[row_key]): data for data in bt_data}

        def _fn(row):
            left = row._asdict()
            right = products[str(left[row_key])]
            left['product'] = left.get('product', None) or right
            return beam.Row(**left)
    elif enrichment_handler == 'BigQuery':
        row_key = handler_config['fields']
        dataset, table = handler_config['table_name'].split('.')[-2:]
        bq_data = INPUT_TABLES['BigQuery', str(dataset), str(table)]
        bq_data = {tuple((str(data[key]) for key in row_key)): data for data in bq_data}

        def _fn(row):
            left = row._asdict()
            right = bq_data[tuple((str(left[k]) for k in row_key))]
            row = {key: left.get(key, None) or right[key] for key in {*left.keys(), *right.keys()}}
            return beam.Row(**row)
    else:
        raise ValueError(f'{enrichment_handler} is not a valid enrichment_handler.')
    return pcoll | beam.Map(_fn)

Mocks the Enrichment transform for testing purposes.

This PTransform simulates the behavior of the Enrichment transform by
looking up data from predefined in-memory tables based on the provided
`enrichment_handler` and `handler_config`.

Note: The Github action that invokes these tests does not have gcp
dependencies installed which is a prerequisite to
apache_beam.transforms.enrichment.Enrichment as a top-level import.

Args:
pcoll: The input PCollection.
enrichment_handler: A string indicating the type of enrichment handler
to simulate (e.g., 'BigTable', 'BigQuery').
handler_config: A dictionary containing configuration details for the
simulated handler (e.g., table names, row keys, fields).
timeout: An optional timeout value (ignored in this mock).

Returns:
A PCollection containing the enriched data.


def capture_image(self, device_label):

        response = None
        try:
            response = requests.post(
                urls.imagecapture(self._giid, device_label),
                headers={
                    'Content-Type': 'application/json',
                    'Cookie': 'vid={}'.format(self._vid)})
        except requests.exceptions.RequestException as ex:
            raise RequestError(ex)
        _validate_response(response)

Capture smartcam image

Args:
device_label (str): device label of camera


def stream_sync(self, report, timeout=120.0):
    done = AwaitableResponse()
    self.stream(report, callback=done.set_result)
    return done.wait(timeout)

Send a report and wait for it to finish.

This awaitable coroutine wraps VirtualIOTileDevice.stream() and turns
the callback into an awaitable object.  The appropriate usage of this
method is by calling it inside the event loop as:

await device.stream_sync(data)

Args:
report (IOTileReport): The report that should be streamed.
timeout (float): The maximum number of seconds to wait before
timing out.

Returns:
awaitable: An awaitable object with the result.

The result will be True if the data was sent successfully
or False if the data could not be sent in its entirety.

When False is returned, there is no guarantee about how much of
the data was sent, if any, just that it was not known to be
successfully sent.


def nr_cases(self, institute_id=None):

        query = {}

        if institute_id:
            query['collaborators'] = institute_id

        LOG.debug("Fetch all cases with query {0}".format(query))
        nr_cases = self.case_collection.find(query).count()

        return nr_cases

Return the number of cases

This function will change when we migrate to 3.7.1

Args:
collaborator(str): Institute id

Returns:
nr_cases(int)


def _Inputs(op: ops.Operation, xs_set):
    if _IsFunction(op.graph):
        inputs = []
        for t in op.inputs:
            if t not in xs_set:
                t = _MaybeCaptured(t)
            inputs.append(t)
        return inputs
    else:
        return op.inputs

Returns the inputs of op, crossing closure boundaries where necessary.

Args:
op: Operation
xs_set: ObjectIdentitySet of Tensors we are differentiating w.r.t.

Returns:
A list of tensors. The tensors may be from multiple Graph/FuncGraphs if op
is in a FuncGraph and has captured inputs.


def _index_to_ansi_values(self, index):

        if self.__class__.__name__[0] == 'F':
            if index < 8:
                index += ANSI_FG_LO_BASE
            else:
                index += (ANSI_FG_HI_BASE - 8)
        else:
            if index < 8:
                index += ANSI_BG_LO_BASE
            else:
                index += (ANSI_BG_HI_BASE - 8)
        return [str(index)]

Converts an palette index to the corresponding ANSI color.

Arguments:
index   - an int (from 0-15)
Returns:
index as str in a list for compatibility with values.


def notify_batches_finished(self, statuses):

        with self._wait_condition:
            self._statuses = statuses
            self._wait_condition.notify()

Called by the BatchTracker the _BatchWaiter is observing. Should not
be called by handlers.

Args:
statuses (dict of int): A dict with keys of batch ids, and values
of status enums


def add_sample(a_float, dist):
    (dist_type, _) = _detect_bucket_option(dist)
    if (dist_type == u'exponentialBuckets'):
        _update_general_statistics(a_float, dist)
        _update_exponential_bucket_count(a_float, dist)
    elif (dist_type == u'linearBuckets'):
        _update_general_statistics(a_float, dist)
        _update_linear_bucket_count(a_float, dist)
    elif (dist_type == u'explicitBuckets'):
        _update_general_statistics(a_float, dist)
        _update_explicit_bucket_count(a_float, dist)
    else:
        _logger.error(u'Could not determine bucket option type for %s', dist)
        raise ValueError(u'Unknown bucket option type')

Adds `a_float` to `dist`, updating its existing buckets.

Args:
a_float (float): a new value
dist (:class:`endpoints_management.gen.servicecontrol_v1_messages.Distribution`):
the Distribution being updated

Raises:
ValueError: if `dist` does not have known bucket options defined
ValueError: if there are not enough bucket count fields in `dist`


def metadata(self):
    if (self._info is None):
        try:
            self._info = self._api.buckets_get(self._name)
        except Exception as e:
            raise e
    return (BucketMetadata(self._info) if self._info else None)

Retrieves metadata about the bucket.

Returns:
A BucketMetadata instance with information about this bucket.
Raises:
Exception if there was an error requesting the bucket's metadata.


def load_extra_data(cls, data):

    try:
      cls._extra_config.update(json.loads(data))
    except ValueError as exception:
      sys.stderr.write('Could convert to JSON. {0:s}'.format(exception))
      exit(-1)

Loads extra JSON configuration parameters from a data buffer.

The data buffer must represent a JSON object.

Args:
data: str, the buffer to load the JSON data from.


def potcar_eatom_list_from_outcar(filename='OUTCAR'):
    with open(filename) as f:
        outcar = f.read()
    eatom_re = re.compile('energy of atom\\s+\\d+\\s+EATOM=\\s*([-\\d\\.]+)')
    eatom = [float(e) for e in eatom_re.findall(outcar)]
    return eatom

Returns a list of EATOM values for the pseudopotentials used.

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

Returns:
(List(Float)): A list of EATOM values, in the order they appear in the OUTCAR.


def build_graph(device, n, m, k, transpose_a, transpose_b, dtype):
    with ops.device('%s' % device):
        if not transpose_a:
            x = variable_v1.VariableV1(random_ops.random_uniform([n, m], dtype=dtype), use_resource=False)
        else:
            x = variable_v1.VariableV1(random_ops.random_uniform([m, n], dtype=dtype), use_resource=False)
        if not transpose_b:
            y = variable_v1.VariableV1(random_ops.random_uniform([m, k], dtype=dtype), use_resource=False)
        else:
            y = variable_v1.VariableV1(random_ops.random_uniform([k, m], dtype=dtype), use_resource=False)
        z = math_ops.matmul(x, y, transpose_a=transpose_a, transpose_b=transpose_b)
        return control_flow_ops.group(z)

Build a graph containing a sequence of matmul operations.

Args:
device: String, the device to run on.
n: tensor A's first dimension size.
m: tensor A's second dimension size.
k: tensor B's second dimension size.
transpose_a: boolean value to show if tensor A is transposed.
transpose_b: boolean value to show if tensor B is transposed.
dtype: numpy data type of the input tensor.

Returns:
A matmul operation to run()


def __init__(self, val, unit, unit_type=None):

        if unit_type is not None and str(unit) not in ALL_UNITS[unit_type]:
            raise UnitError(
                "{} is not a supported unit for {}".format(unit, unit_type))
        self._unit = Unit(unit)
        self._unit_type = unit_type

Initializes a float with unit.

Args:
val (float): Value
unit (Unit): A unit. E.g., "C".
unit_type (str): A type of unit. E.g., "charge"


def cancel(self):
    try:
        del self._protocol._consumers[self.queue]
    except (KeyError, AttributeError):
        pass
    try:
        del self._protocol.factory._consumers[self.queue]
    except (KeyError, AttributeError):
        pass
    self._running = False
    (yield self._read_loop)
    try:
        (yield self._channel.basic_cancel(consumer_tag=self._tag))
    except pika.exceptions.AMQPChannelError:
        pass
    try:
        (yield self._channel.close())
    except pika.exceptions.AMQPChannelError:
        pass
    if (not self.result.called):
        self.result.callback(self)

Cancel the consumer and clean up resources associated with it.
Consumers that are canceled are allowed to finish processing any
messages before halting.

Returns:
defer.Deferred: A deferred that fires when the consumer has finished
processing any message it was in the middle of and has been successfully
canceled.


def _new_open_bin(self, width=None, height=None, rid=None):
    factories_to_delete = set()
    new_bin = None
    for (key, binfac) in self._empty_bins.items():
        if (not binfac.fits_inside(width, height)):
            continue
        new_bin = binfac.new_bin()
        if (new_bin is None):
            continue
        self._open_bins.append(new_bin)
        if binfac.is_empty():
            factories_to_delete.add(key)
        break
    for f in factories_to_delete:
        del self._empty_bins[f]
    return new_bin

Extract the next empty bin and append it to open bins

Returns:
PackingAlgorithm: Initialized empty packing bin.
None: No bin big enough for the rectangle was found


def __init__(self, cls):

        super(EnumType, self).__init__()
        self._cls = cls

Create a new EnumType. This new EnumType requires a class object in the
constructor. The class is used to construct new instances of the Enum
when the integer value is retrieved from the database.

Args:
cls(class): An Enum class used to create new instances from integer
values.


def with_params(self, params):
    copy = params.copy()
    copy.update(self._params)
    return self.__copy_and_set('params', copy)

Adds parameters to the request params

Args:
params (dict): The parameters to add to the request params

Returns:
The request builder instance in order to chain calls


def convert_dict_to_params(src_dict):
    return '&'.join(['{}={}'.format(key, value) for (key, value) in src_dict.items()])

convert dict to params string

Args:
src_dict (dict): source mapping data structure

Returns:
str: string params data

Examples:
>>> src_dict = {
"a": 1,
"b": 2
}
>>> convert_dict_to_params(src_dict)
>>> "a=1&b=2"


def __split_off_extra_attributes(self, mapping: CommentedMap, known_attrs: List[str]) -> CommentedMap:
    attr_names = list(mapping.keys())
    main_attrs = mapping.copy()
    extra_attrs = OrderedDict(mapping.items())
    for name in attr_names:
        if ((name not in known_attrs) or (name == 'yatiml_extra')):
            del main_attrs[name]
        else:
            del extra_attrs[name]
    main_attrs['yatiml_extra'] = extra_attrs
    return main_attrs

Separates the extra attributes in mapping into yatiml_extra.

This returns a mapping containing all key-value pairs from \
mapping whose key is in known_attrs, and an additional key \
yatiml_extra which maps to a dict containing the remaining \
key-value pairs.

Args:
mapping: The mapping to split
known_attrs: Attributes that should be kept in the main \
map, and not moved to yatiml_extra.

Returns:
A map with attributes reorganised as described above.


def fetch(self, card_id, data={}, **kwargs):
    return super(Card, self).fetch(card_id, data, **kwargs)

Fetch Card for given Id

Args:
card_id : Id for which card object has to be retrieved

Returns:
Card dict for given card Id


def _ClassifyInclude(fileinfo, include, is_system):
    is_cpp_h = (include in _CPP_HEADERS)
    if (is_system and (os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++'])):
        is_system = False
    if is_system:
        if is_cpp_h:
            return _CPP_SYS_HEADER
        else:
            return _C_SYS_HEADER
    (target_dir, target_base) = os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName()))
    (include_dir, include_base) = os.path.split(_DropCommonSuffixes(include))
    target_dir_pub = os.path.normpath((target_dir + '/../public'))
    target_dir_pub = target_dir_pub.replace('\\', '/')
    if ((target_base == include_base) and ((include_dir == target_dir) or (include_dir == target_dir_pub))):
        return _LIKELY_MY_HEADER
    target_first_component = _RE_FIRST_COMPONENT.match(target_base)
    include_first_component = _RE_FIRST_COMPONENT.match(include_base)
    if (target_first_component and include_first_component and (target_first_component.group(0) == include_first_component.group(0))):
        return _POSSIBLE_MY_HEADER
    return _OTHER_HEADER

Figures out what kind of header 'include' is.

Args:
fileinfo: The current file cpplint is running over. A FileInfo instance.
include: The path to a #included file.
is_system: True if the #include used <> rather than "".

Returns:
One of the _XXX_HEADER constants.

For example:
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True)
_C_SYS_HEADER
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
_CPP_SYS_HEADER
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
_LIKELY_MY_HEADER
>>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
...                  'bar/foo_other_ext.h', False)
_POSSIBLE_MY_HEADER
>>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False)
_OTHER_HEADER


def generate_output_entities(self, json_data=None, hr=True, show_name=False, colorize=True):
    output = ''
    short = (HR_RDAP['entities']['_short'] if hr else 'entities')
    name = (HR_RDAP['entities']['_name'] if (hr and show_name) else None)
    output += generate_output(line='0', short=short, name=name, is_parent=(False if ((json_data is None) or (json_data['entities'] is None)) else True), value=('None' if ((json_data is None) or (json_data['entities'] is None)) else None), colorize=colorize)
    if (json_data is not None):
        for ent in json_data['entities']:
            output += generate_output(line='1', value=ent, colorize=colorize)
    return output

The function for generating CLI output RDAP entity results.

Args:
json_data (:obj:`dict`): The data to process. Defaults to None.
hr (:obj:`bool`): Enable human readable key translations. Defaults
to True.
show_name (:obj:`bool`): Show human readable name (default is to
only show short). Defaults to False.
colorize (:obj:`bool`): Colorize the console output with ANSI
colors. Defaults to True.

Returns:
str: The generated output.


def response_data_to_model_instance(self, response_data):

        response_data["datetime_created"] = dateutil.parser.parse(
            response_data["datetime_created"]
        )

        if response_data["datetime_finished"]:
            response_data["datetime_finished"] = dateutil.parser.parse(
                response_data["datetime_finished"]
            )

        return super(
            BaseTaskInstanceManager, self
        ).response_data_to_model_instance(response_data)

Convert response data to a task instance model.

Args:
response_data (dict): The data from the request's response.

Returns:
:class:`saltant.models.base_task_instance.BaseTaskInstance`:
A task instance model instance representing the task
instance from the reponse data.


def send_recv(self, message, timeout=10.0):

        response_queue = self.send(message)
        response = self.recv(response_queue, timeout)
        return response

Send a message to a PandABox and wait for the response

Args:
message (str): The message to send
timeout (float): How long to wait before raising queue.Empty

Returns:
str: The response


def _check_positional_parameter_annotations(method_signature, base_signature, is_subtype):
    for param_index in range(max(len(base_signature.param_names), len(method_signature.param_names))):
        if param_index == 0:
            continue
        if param_index < len(base_signature.param_names):
            base_param_name = base_signature.param_names[param_index]
        elif base_signature.varargs_name:
            base_param_name = base_signature.varargs_name
        else:
            break
        try:
            base_param_type = base_signature.annotations[base_param_name]
        except KeyError:
            continue
        if base_param_name == base_signature.varargs_name:
            base_param_type = _get_varargs_annotation_type(base_param_type)
            if base_param_type is None:
                continue
        if param_index < method_signature.posonly_count:
            method_param_name = method_signature.param_names[param_index]
        elif param_index < len(method_signature.param_names):
            if base_param_name == '_' or method_signature.param_names[param_index] == '_':
                method_param_name = method_signature.param_names[param_index]
            else:
                method_param_name = base_param_name
        elif method_signature.varargs_name:
            method_param_name = method_signature.varargs_name
        else:
            break
        try:
            method_param_type = method_signature.annotations[method_param_name]
        except KeyError:
            continue
        if method_param_name == method_signature.varargs_name:
            method_param_type = _get_varargs_annotation_type(method_param_type)
            if method_param_type is None:
                continue
        if not is_subtype(base_param_type, method_param_type):
            return SignatureError(SignatureErrorType.POSITIONAL_PARAMETER_TYPE_MISMATCH, f"Type mismatch for parameter '{method_param_name}'.")
    return None

Checks type annotations for positional parameters of the overriding method.

Args:
method_signature: signature of the overriding method.
base_signature: signature of the overridden method.
is_subtype: a binary function to compare types.

Returns:
SignatureError if a mismatch is detected. Otherwise returns None.


def plot_ticks(ax, tick_fontsize=12, xticks=None, xticks_args=None, yticks=None, yticks_args=None, zticks=None, zticks_args=None):
    if (xticks is not None):
        ax.set_xticks(xticks)
        xticks_args = dict_if_none(xticks_args)
        ax.xaxis.set_tick_params(labelsize=tick_fontsize, **xticks_args)
    if (yticks is not None):
        ax.set_yticks(yticks)
        yticks_args = dict_if_none(yticks_args)
        ax.yaxis.set_tick_params(labelsize=tick_fontsize, **yticks_args)
    if (zticks is not None):
        ax.set_zticks(zticks)
        zticks_args = dict_if_none(zticks_args)
        ax.zaxis.set_tick_params(labelsize=tick_fontsize, **zticks_args)

Function that defines the labels options of a matplotlib plot.

Args:
ax: matplotlib axes
tick_fontsize (int): Defines the size of the ticks' font
xticks([list of ticks]): Defines the values of x ticks in the figure
xticks_arg(dict):  Passsed into matplotlib as xticks arguments
yticks([list of ticks]): Defines the values of y ticks in the figure
yticks_arg(dict):  Passsed into matplotlib as yticks arguments
zticks([list of ticks]): Defines the values of z ticks in the figure
zticks_arg(dict):  Passsed into matplotlib as zticks arguments


class CSVLogger(Callback):

    def __init__(self, filename, separator=',', append=False):
        self.sep = separator
        self.filename = path_to_string(filename)
        self.append = append
        self.writer = None
        self.keys = None
        self.append_header = True
        super(CSVLogger, self).__init__()

    def on_train_begin(self, logs=None):
        if self.append:
            if file_io.file_exists_v2(self.filename):
                with gfile.GFile(self.filename, 'r') as f:
                    self.append_header = not bool(len(f.readline()))
            mode = 'a'
        else:
            mode = 'w'
        self.csv_file = gfile.GFile(self.filename, mode)

    def on_epoch_end(self, epoch, logs=None):
        logs = logs or {}

        def handle_value(k):
            is_zero_dim_ndarray = isinstance(k, np.ndarray) and k.ndim == 0
            if isinstance(k, str):
                return k
            elif isinstance(k, collections.abc.Iterable) and (not is_zero_dim_ndarray):
                return '"[%s]"' % ', '.join(map(str, k))
            else:
                return k
        if self.keys is None:
            self.keys = sorted(logs.keys())
        if self.model.stop_training:
            logs = dict(((k, logs[k]) if k in logs else (k, 'NA') for k in self.keys))
        if not self.writer:

            class CustomDialect(csv.excel):
                delimiter = self.sep
            fieldnames = ['epoch'] + self.keys
            self.writer = csv.DictWriter(self.csv_file, fieldnames=fieldnames, dialect=CustomDialect)
            if self.append_header:
                self.writer.writeheader()
        row_dict = collections.OrderedDict({'epoch': epoch})
        row_dict.update(((key, handle_value(logs[key])) for key in self.keys))
        self.writer.writerow(row_dict)
        self.csv_file.flush()

    def on_train_end(self, logs=None):
        self.csv_file.close()
        self.writer = None

Callback that streams epoch results to a CSV file.

Supports all values that can be represented as a string,
including 1D iterables such as `np.ndarray`.

Example:

```python
csv_logger = CSVLogger('training.log')
model.fit(X_train, Y_train, callbacks=[csv_logger])
```

Args:
filename: Filename of the CSV file, e.g. `'run/log.csv'`.
separator: String used to separate elements in the CSV file.
append: Boolean. True: append if file exists (useful for continuing
training). False: overwrite existing file.


def batch_insert(self, insertions: Iterable[Tuple[(int, ops.OP_TREE)]]) -> None:
    copy = self.copy()
    shift = 0
    insertions = sorted(insertions, key=(lambda e: e[0]))
    groups = _group_until_different(insertions, key=(lambda e: e[0]), value=(lambda e: e[1]))
    for (i, group) in groups:
        insert_index = (i + shift)
        next_index = copy.insert(insert_index, reversed(group), InsertStrategy.EARLIEST)
        if (next_index > insert_index):
            shift += (next_index - insert_index)
    self._moments = copy._moments

Applies a batched insert operation to the circuit.

Transparently handles the fact that earlier insertions may shift
the index that later insertions should occur at. For example, if you
insert an operation at index 2 and at index 4, but the insert at index 2
causes a new moment to be created, then the insert at "4" will actually
occur at index 5 to account for the shift from the new moment.

All insertions are done with the strategy 'EARLIEST'.

When multiple inserts occur at the same index, the gates from the later
inserts end up before the gates from the earlier inserts (exactly as if
you'd called list.insert several times with the same index: the later
inserts shift the earliest inserts forward).

Args:
insertions: A sequence of (insert_index, operations) pairs
indicating operations to add into the circuit at specific
places.


def stack(self, value):

        if value == self._defaults['stack'] and 'stack' in self._values:
            del self._values['stack']
        else:
            self._values['stack'] = value

The stack property.

Args:
value (string). the property value.


def add_snmp_community(self, **kwargs):
    community = kwargs.pop('community')
    callback = kwargs.pop('callback', self._callback)
    config = ET.Element('config')
    snmp_server = ET.SubElement(config, 'snmp-server', xmlns='urn:brocade.com:mgmt:brocade-snmp')
    community_el = ET.SubElement(snmp_server, 'community')
    community_name = ET.SubElement(community_el, 'community')
    community_name.text = community
    return callback(config)

Add SNMP Community to NOS device.

Args:
community (str): Community string to be added to device.
callback (function): A function executed upon completion of the
method.  The only parameter passed to `callback` will be the
``ElementTree`` `config`.

Returns:
Return value of `callback`.

Raises:
KeyError: if `community` is not defined.


def scatter_mul(self, sparse_delta, use_locking=False, name=None):
    if not isinstance(sparse_delta, indexed_slices.IndexedSlices):
        raise TypeError(f'Argument `sparse_delta` must be a `tf.IndexedSlices`. Received arg: {sparse_delta}')
    return self._lazy_read(gen_resource_variable_ops.resource_scatter_mul(self.handle, sparse_delta.indices, ops.convert_to_tensor(sparse_delta.values, self.dtype), name=name))

Multiply this variable by `tf.IndexedSlices`.

Args:
sparse_delta: `tf.IndexedSlices` to multiply this variable by.
use_locking: If `True`, use locking during the operation.
name: the name of the operation.

Returns:
The updated variable.

Raises:
TypeError: if `sparse_delta` is not an `IndexedSlices`.


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

Formats the notes.

Args:
event (EventObject): event.

Returns:
str: formatted notes field.


def __set__(self, instance, value):

        if value is None and self.default:
            self._cache[instance] = self.default

        else:
            try:
                cleaned_value = self.field_value(value)

            except NodeTypeError as node_error:
                raise SchemaNodeError('{}.{}: {}'.format(
                    instance.__class__.__name__, self.alias, node_error.args[0])
                )

            try:
                self.is_valid(cleaned_value)

            except SchemaNodeValidatorError as error:
                raise SchemaNodeError(
                    '{}.{} Error for value `{}` : {}'.format(
                        instance.__class__.__name__,
                        self.alias,
                        value,
                        error.args[0]
                    )
                )

            self._cache[instance] = cleaned_value

Python descriptor protocol `__set__` magic method.

Args:
instance (object): The instance with descriptor attribute.
value (object): The value for instance attribute.


def parse(self, data):
    data = '\n'.join(self.strip(data.split('\n')))
    tag_re = re.compile('^:\\n?(?P<full_tag>(?P<tag>[0-9]{2}|NS)(?P<sub_tag>[A-Z])?):', re.MULTILINE)
    matches = list(tag_re.finditer(data))
    valid_matches = list(self.sanatize_tag_id_matches(matches))
    for (i, match) in enumerate(valid_matches):
        tag_id = self.normalize_tag_id(match.group('tag'))
        tag = (self.tags.get(match.group('full_tag')) or self.tags[tag_id])
        if valid_matches[(i + 1):]:
            tag_data = data[match.end():valid_matches[(i + 1)].start()].strip()
        else:
            tag_data = data[match.end():].strip()
        tag_dict = tag.parse(self, tag_data)
        for processor in self.processors.get(('pre_%s' % tag.slug), []):
            tag_dict = processor(self, tag, tag_dict)
        result = tag(self, tag_dict)
        for processor in self.processors.get(('post_%s' % tag.slug), []):
            result = processor(self, tag, tag_dict, result)
        if isinstance(tag, mt940.tags.Statement):
            if (not self.transactions):
                transaction = Transaction(self)
                self.transactions.append(transaction)
            if transaction.data.get('id'):
                transaction = Transaction(self, result)
                self.transactions.append(transaction)
            else:
                transaction.data.update(result)
        elif (issubclass(tag.scope, Transaction) and self.transactions):
            for (k, v) in _compat.iteritems(result):
                if ((k in transaction.data) and hasattr(v, 'strip')):
                    transaction.data[k] += ('\n%s' % v.strip())
                else:
                    transaction.data[k] = v
        elif issubclass(tag.scope, Transactions):
            self.data.update(result)
    return self.transactions

Parses mt940 data, expects a string with data

Args:
data (str): The MT940 data

Returns: :py:class:`list` of :py:class:`Transaction`


def register(model_type, config, exist_ok=False) -> None:
    if issubclass(config, PretrainedConfig) and config.model_type != model_type:
        raise ValueError(f'The config you are passing has a `model_type` attribute that is not consistent with the model type you passed (config has {config.model_type} and you passed {model_type}. Fix one of those so they match!')
    CONFIG_MAPPING.register(model_type, config, exist_ok=exist_ok)

Register a new configuration for this class.

Args:
model_type (`str`): The model type like "bert" or "gpt".
config ([`PretrainedConfig`]): The config to register.


def task(self, task_uuid):

        request = clearly_pb2.FindTaskRequest(task_uuid=task_uuid)
        task = self._stub.find_task(request)
        if task.uuid:
            ClearlyClient._display_task(task, True, True, True)
        else:
            print(EMPTY)

Finds one specific task.

Args:
task_uuid (str): the task id


def __init__(self, context):

    del context
    self._debugger_data_server = None
    self._server_thread = None
    self._grpc_port = None

Constructs a debugger plugin for TensorBoard.

This plugin adds handlers for retrieving debugger-related data. The plugin
also starts a debugger data server once the log directory is passed to the
plugin via the call to get_plugin_apps.

Args:
context: A base_plugin.TBContext instance.


def listen(self, log, noprint=True):
    try:
        result = self.decode_event(log.topics, log.data)
    except ValueError:
        return
    if (not noprint):
        print(result)
    return result

Return a dictionary representation of the Log instance.

Note:
This function won't work with anonymous events.

Args:
log (processblock.Log): The Log instance that needs to be parsed.
noprint (bool): Flag to turn off priting of the decoded log instance.


def write_file(path, content, mode='w'):

    from peltak.core import context
    from peltak.core import log

    if context.get('pretend', False):
        log.info("Would overwrite <34>{path}<32> with:\n<90>{content}",
                 path=path,
                 content=content)
    else:
        with open(path, mode) as fp:
            fp.write(content)

--pretend aware file writing.

You can always write files manually but you should always handle the
--pretend case.

Args:
path (str):
content (str):
mode (str):


def run_eagerly(self):
    if self._run_eagerly is True and (not context.executing_eagerly()):
        raise ValueError('You can only set `run_eagerly=True` if eager execution is enabled.')
    if not self.dynamic:
        if self._run_eagerly is None:
            return def_function.functions_run_eagerly()
        else:
            return self._run_eagerly
    else:
        if not context.executing_eagerly():
            raise ValueError('Your model contains layers that can only be successfully run in eager execution (layers constructed with `dynamic=True`). You must enable eager execution with `tf.enable_eager_execution()`.')
        if self._run_eagerly is False:
            raise ValueError('Your model contains layers that can only be successfully run in eager execution (layers constructed with `dynamic=True`). You cannot set `run_eagerly=False`.')
        return context.executing_eagerly()

Settable attribute indicating whether the model should run eagerly.

Running eagerly means that your model will be run step by step,
like Python code. Your model might run slower, but it should become easier
for you to debug it by stepping into individual layer calls.

By default, we will attempt to compile your model to a static graph to
deliver the best execution performance.

Returns:
Boolean, whether the model should run eagerly.


def update_state(self, y_true, y_pred, sample_weight=None):
    return metrics_utils.update_confusion_matrix_variables({metrics_utils.ConfusionMatrix.TRUE_POSITIVES: self.true_positives, metrics_utils.ConfusionMatrix.FALSE_POSITIVES: self.false_positives}, y_true, y_pred, thresholds=self.thresholds, thresholds_distributed_evenly=self._thresholds_distributed_evenly, top_k=self.top_k, class_id=self.class_id, sample_weight=sample_weight)

Accumulates true positive and false positive statistics.

Args:
y_true: The ground truth values, with the same dimensions as `y_pred`.
Will be cast to `bool`.
y_pred: The predicted values. Each element must be in the range `[0, 1]`.
sample_weight: Optional weighting of each example. Defaults to 1. Can be a
`Tensor` whose rank is either 0, or the same rank as `y_true`, and must
be broadcastable to `y_true`.

Returns:
Update op.


def GetAccounts(self):
    selector = {'fields': ['CustomerId', 'CanManageClients']}
    accounts = self.client.GetService('ManagedCustomerService').get(selector)
    return accounts['entries']

Return the client accounts associated with the user's manager account.

Returns:
list List of ManagedCustomer data objects.


def _get_bounding_box(self, box: 'torch.Tensor') -> Dict[str, int]:
    if self.framework != 'pt':
        raise ValueError('The ObjectDetectionPipeline is only available in PyTorch.')
    xmin, ymin, xmax, ymax = box.int().tolist()
    bbox = {'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax}
    return bbox

Turns list [xmin, xmax, ymin, ymax] into dict { "xmin": xmin, ... }

Args:
box (`torch.Tensor`): Tensor containing the coordinates in corners format.

Returns:
bbox (`Dict[str, int]`): Dict containing the coordinates in corners format.


def select_qadapter(self, pconfs):

        policy, max_ncpus = self.policy, self.max_cores
        pconfs = pconfs.get_ordered_with_policy(policy, max_ncpus)

        if policy.precedence == "qadapter":

            for qadpos, qad in enumerate(self.qads):
                possible_pconfs = [pc for pc in pconfs if qad.can_run_pconf(pc)]

                if qad.allocation == "nodes":

                    for pconf in possible_pconfs:
                        if pconf.num_cores % qad.hw.cores_per_node == 0:
                            return self._use_qadpos_pconf(qadpos, pconf)

                if possible_pconfs:
                    return self._use_qadpos_pconf(qadpos, possible_pconfs[0])

        elif policy.precedence == "autoparal_conf":

            for pconf in pconfs:
                for qadpos, qad in enumerate(self.qads):

                    if qad.allocation == "nodes" and not pconf.num_cores % qad.hw.cores_per_node == 0:
                        continue

                    if qad.can_run_pconf(pconf):
                        return self._use_qadpos_pconf(qadpos, pconf)

        else:
            raise ValueError("Wrong value of policy.precedence = %s" % policy.precedence)

        raise RuntimeError("Cannot find qadapter for this run!")

Given a list of parallel configurations, pconfs, this method select an `optimal` configuration
according to some criterion as well as the :class:`QueueAdapter` to use.

Args:
pconfs: :class:`ParalHints` object with the list of parallel configurations

Returns:
:class:`ParallelConf` object with the `optimal` configuration.


def code_verifier(n_bytes=64):

    verifier = base64.urlsafe_b64encode(os.urandom(n_bytes)).rstrip(b'=')

    if len(verifier) < 43:
        raise ValueError("Verifier too short. n_bytes must be > 30.")
    elif len(verifier) > 128:
        raise ValueError("Verifier too long. n_bytes must be < 97.")
    else:
        return verifier

Generates a 'code_verifier' as described in section 4.1 of RFC 7636.

This is a 'high-entropy cryptographic random string' that will be
impractical for an attacker to guess.

Args:
n_bytes: integer between 31 and 96, inclusive. default: 64
number of bytes of entropy to include in verifier.

Returns:
Bytestring, representing urlsafe base64-encoded random data.


def _lower_non_existent_context_field_filters(match_traversals, visitor_fn):
    new_match_traversals = []
    for match_traversal in match_traversals:
        new_match_traversal = []
        for step in match_traversal:
            if (step.where_block is not None):
                new_filter = step.where_block.visit_and_update_expressions(visitor_fn)
                if (new_filter.predicate == TrueLiteral):
                    new_filter = None
                new_step = step._replace(where_block=new_filter)
            else:
                new_step = step
            new_match_traversal.append(new_step)
        new_match_traversals.append(new_match_traversal)
    return new_match_traversals

Return new match traversals, lowering filters involving non-existent ContextFields.

Expressions involving non-existent ContextFields are evaluated to TrueLiteral.
BinaryCompositions, where one of the operands is lowered to a TrueLiteral,
are lowered appropriately based on the present operator (u'||' and u'&&' are affected).
TernaryConditionals, where the predicate is lowered to a TrueLiteral,
are replaced by their if_true predicate.
The `visitor_fn` implements these behaviors (see `_update_context_field_expression`).

Args:
match_traversals: list of match traversal enitities to be lowered
visitor_fn: visit_and_update function for lowering expressions in given match traversal

Returns:
new list of match_traversals, with all filter expressions lowered


def generate_output_list(self, source, key, val, line='2', hr=True, show_name=False, colorize=True):
    output = generate_output(line=line, short=(HR_RDAP[source][key]['_short'] if hr else key), name=(HR_RDAP[source][key]['_name'] if (hr and show_name) else None), is_parent=(False if ((val is None) or (len(val) == 0)) else True), value=('None' if ((val is None) or (len(val) == 0)) else None), colorize=colorize)
    if (val is not None):
        for item in val:
            output += generate_output(line=str((int(line) + 1)), value=item, colorize=colorize)
    return output

The function for generating CLI output RDAP list results.

Args:
source (:obj:`str`): The parent key 'network' or 'objects'
(required).
key (:obj:`str`): The event key 'events' or 'events_actor'
(required).
val (:obj:`dict`): The event dictionary (required).
line (:obj:`str`): The line number (0-4). Determines indentation.
Defaults to '0'.
hr (:obj:`bool`): Enable human readable key translations. Defaults
to True.
show_name (:obj:`bool`): Show human readable name (default is to
only show short). Defaults to False.
colorize (:obj:`bool`): Colorize the console output with ANSI
colors. Defaults to True.

Returns:
str: The generated output.


def async_decorator(func):

    @functools.wraps(func)
    def async_wrapper(*args, **kwargs):

        if 'callback' not in kwargs or not kwargs['callback']:
            return func(*args, **kwargs)

        callback = kwargs.pop('callback')

        if not callable(callback):
            raise TypeError('Expected \'callback\' is not callable.')

        def thread_func(*args, **kwargs):

            exception, res = None, None
            try:
                res = func(*args, **kwargs)
            except Exception as e:
                exception = e
            return callback(exception, res)

        thread = threads.ThreadReturn(target=thread_func,
                                      args=args,
                                      kwargs=kwargs)
        thread.daemon = True
        thread.start()
        return thread

    return async_wrapper

Asynchronous function decorator.  Interprets the function as being
asynchronous, so returns a function that will handle calling the
Function asynchronously.

Args:
func (function): function to be called asynchronously

Returns:
The wrapped function.

Raises:
AttributeError: if ``func`` is not callable


def mean(x, axis=None, keepdims=False):

    from .function_bases import mean as mean_base
    if axis is None:
        axis = range(x.ndim)
    elif not hasattr(axis, '__iter__'):
        axis = [axis]
    return mean_base(x, axis, keepdims)

Reduction along axes with mean operation.

Args:
x (Variable): An input variable.
axis (None, int or tuple of ints): Axis or axes along which mean is
calculated. Passing the default value `None` will reduce all dimensions.
keepdims (bool): Flag whether the reduced axes are kept as a dimension with 1 element.

Returns:
~nnabla.Variable: N-D array.


def find_word_groups(self, text, category, proximity=2):
    f = re.IGNORECASE
    words = getattr(self, category)
    regex = re.compile((('(\\b' + '\\b|\\b'.join(words)) + '\\b)'), flags=f)
    candidates = regex.finditer(text)
    (starts, ends) = ([], [])
    groups = []
    for item in candidates:
        starts.append(item.span()[0])
        ends.append(item.span()[1])
        groups.append(item.group().lower())
    new_starts = []
    new_groups = []
    skip = False
    for (i, g) in enumerate(groups):
        if skip:
            skip = False
            continue
        if ((i < (len(groups) - 1)) and ((starts[(i + 1)] - ends[i]) <= proximity)):
            if (g[(- 1)] == '-'):
                sep = ''
            else:
                sep = ' '
            new_groups.append(((g + sep) + groups[(i + 1)]))
            new_starts.append(starts[i])
            skip = True
        else:
            if (g not in new_groups):
                new_groups.append(g)
                new_starts.append(starts[i])
            skip = False
    return new_groups

Given a string and a category, finds and combines words into
groups based on their proximity.

Args:
text (str): Some text.
tokens (list): A list of regex strings.

Returns:
list. The combined strings it found.

Example:
COLOURS = [r"red(?:dish)?", r"grey(?:ish)?", r"green(?:ish)?"]
s = 'GREYISH-GREEN limestone with RED or GREY sandstone.'
find_word_groups(s, COLOURS) --> ['greyish green', 'red', 'grey']


def open(self, filepath):
    with io.open(filepath, 'r', encoding='utf-8') as fp:
        content = fp.read()
    return content

Open settings backend to return its content

Args:
filepath (str): Settings object, depends from backend

Returns:
string: File content.


def with_params(self, params):

        copy = params.copy()
        copy.update(self._params)
        return self.__copy_and_set('params', copy)

Adds parameters to the request params

Args:
params (dict): The parameters to add to the request params

Returns:
The request builder instance in order to chain calls


def docstring(documentation, prepend=False, join=''):

    def decorator(func):
        current = (func.__doc__ if func.__doc__ else '').strip()
        doc = documentation.strip()
        new = '\n'.join(([doc, join, current] if prepend else [current, join, doc]))
        lines = len(new.strip().splitlines())
        if (lines == 1):
            func.__doc__ = new.strip()
        else:
            func.__doc__ = (new.strip() + '\n')
        return func
    return decorator

r"""Prepend or append a string to the current documentation of the function.

This decorator should be robust even if ``func.__doc__`` is None
(for example, if -OO was passed to the interpreter).

Usage::

@docstring('Appended this line')
def func():
"This docstring will have a line below."
pass

>>> print(func.__doc__)
This docstring will have a line below.

Appended this line

Args:
documentation (str): Documentation string that should be added,
appended or prepended to the current documentation string.
prepend (bool): Prepend the documentation string to the current
documentation if ``True`` else append. default=``False``
join (str): String used to separate docstrings. default='\n'


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

Request detailed information about the execution status of the job. EXPERIMENTAL. This API is subject to change or removal without notice.

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


def main_loop(self, steps_per_epoch, starting_epoch, max_epoch):

        with self.sess.as_default():
            self.loop.config(steps_per_epoch, starting_epoch, max_epoch)
            self.loop.update_global_step()
            try:
                self._callbacks.before_train()

                self.loop.update_global_step()
                for self.loop._epoch_num in range(
                        self.loop.starting_epoch, self.loop.max_epoch + 1):
                    logger.info("Start Epoch {} ...".format(self.loop.epoch_num))
                    self._callbacks.before_epoch()
                    start_time = time.time()
                    for self.loop._local_step in range(self.loop.steps_per_epoch):
                        if self.hooked_sess.should_stop():
                            return
                        self.run_step()
                        self._callbacks.trigger_step()
                    self._callbacks.after_epoch()
                    logger.info("Epoch {} (global_step {}) finished, time:{}.".format(
                        self.loop.epoch_num, self.loop.global_step, humanize_time_delta(time.time() - start_time)))

                    self._callbacks.trigger_epoch()
                logger.info("Training has finished!")
            except (StopTraining, tf.errors.OutOfRangeError) as e:
                logger.info("Training was stopped by exception {}.".format(str(e)))
            except KeyboardInterrupt:
                logger.info("Detected Ctrl-C and exiting main loop.")
                raise
            finally:
                self._callbacks.after_train()
                self.hooked_sess.close()

Run the main training loop.

Args:
steps_per_epoch, starting_epoch, max_epoch (int):


def loads(cls, name):
    if (not isinstance(name, six.string_types)):
        raise TypeError(u'arguments to {classname} must be of type {string_types}'.format(classname=cls.__name__, string_types=repr(six.string_types)))
    if ((not name) or name.isspace()):
        raise ValueError('name must not be empty')
    return cls(name)

Load a parsed name from a string.

Raises:
TypeError: when name isn't a type of `six.string_types`.
ValueError: when name is empty or None.


def get_random_email(ltd='com'):
    email = [RandomInputHelper.get_random_value(6, [string.ascii_lowercase]), '@', RandomInputHelper.get_random_value(6, [string.ascii_lowercase]), '.', ltd]
    return ''.join(email)

Get a random email address with the given ltd.

Args:
ltd (str): The ltd to use (e.g. com).

Returns:
str: The random email.


def read_proto(file_name: str, proto_cls: Type[_T]) -> _T:
    raw_text = ''
    proto = proto_cls()
    with open(file_name, 'r', encoding='utf-8') as f:
        raw_text = f.read()
    return text_format.Parse(raw_text, proto)

Reads a protobuf in prototxt format from file_name.

Data is parsed into an instance of `proto_cls`.

Args:
file_name: The file to read from.
proto_cls: The type of protobuf message to parse as.

Returns:
The protobuf message in the file.


def dict2str(self, d: Dict, joiner: str) -> str:

        result = str()
        for key in d:
            result = result + str(key) + " : "
            if isinstance(d[key], list):
                result = result + self.list2str(d[key], joiner) + joiner
            elif isinstance(d[key], dict):
                result = result + self.dict2str(d[key], joiner) + joiner
            elif d[key]:
                result = result + str(d[key]) + joiner
        return result

Convert dict to str as input for tokenizer

Args:
d (dict): dict for converting
joiner (str): join the elements using this string to separate them.

Returns: the value of the dict as a string


def pauli_group(number_of_qubits, case='weight'):
    if (number_of_qubits < 5):
        temp_set = []
        if (case == 'weight'):
            tmp = pauli_group(number_of_qubits, case='tensor')
            return sorted(tmp, key=(lambda x: (- np.count_nonzero((np.array(x.to_label(), 'c') == b'I')))))
        elif (case == 'tensor'):
            for k in range((4 ** number_of_qubits)):
                z = np.zeros(number_of_qubits, dtype=np.bool)
                x = np.zeros(number_of_qubits, dtype=np.bool)
                for j in range(number_of_qubits):
                    element = ((k
                    if (element == 1):
                        x[j] = True
                    elif (element == 2):
                        z[j] = True
                        x[j] = True
                    elif (element == 3):
                        z[j] = True
                temp_set.append(Pauli(z, x))
            return temp_set
        else:
            raise QiskitError("Only support 'weight' or 'tensor' cases but you have {}.".format(case))
    raise QiskitError('Only support number of qubits is less than 5')

Return the Pauli group with 4^n elements.

The phases have been removed.
case 'weight' is ordered by Pauli weights and
case 'tensor' is ordered by I,X,Y,Z counting lowest qubit fastest.

Args:
number_of_qubits (int): number of qubits
case (str): determines ordering of group elements ('weight' or 'tensor')

Returns:
list: list of Pauli objects

Raises:
QiskitError: case is not 'weight' or 'tensor'
QiskitError: number_of_qubits is larger than 4


def unite(df, colname, *args, **kwargs):
    to_unite = list([a for a in flatten(args)])
    sep = kwargs.get('sep', '_')
    remove = kwargs.get('remove', True)
    na_action = kwargs.get('na_action', 'maintain')
    if (na_action == 'maintain'):
        df[colname] = df[to_unite].apply((lambda x: (np.nan if any(x.isnull()) else sep.join(x.map(str)))), axis=1)
    elif (na_action == 'ignore'):
        df[colname] = df[to_unite].apply((lambda x: sep.join(x[(~ x.isnull())].map(str))), axis=1)
    elif (na_action == 'as_string'):
        df[colname] = df[to_unite].astype(str).apply((lambda x: sep.join(x)), axis=1)
    if remove:
        df.drop(to_unite, axis=1, inplace=True)
    return df

Does the inverse of `separate`, joining columns together by a specified
separator.

Any columns that are not strings will be converted to strings.

Args:
df (pandas.DataFrame): DataFrame passed in through the pipe.
colname (str): the name of the new joined column.
*args: list of columns to be joined, which can be strings, symbolic, or
integer positions.

Kwargs:
sep (str): the string separator to join the columns with.
remove (bool): Boolean indicating whether or not to remove the
original columns.
na_action (str): can be one of `'maintain'` (the default),
'`ignore'`, or `'as_string'`. The default will make the new column
row a `NaN` value if any of the original column cells at that
row contained `NaN`. '`ignore'` will treat any `NaN` value as an
empty string during joining. `'as_string'` will convert any `NaN`
value to the string `'nan'` prior to joining.


def html2text(__html: str, *, width: int=80, ascii_replacements: bool=False) -> str:
    html2.BODY_WIDTH = width
    html2.UNICODE_SNOB = ascii_replacements
    return html2.html2text(__html).strip()

HTML to plain text renderer.

See also: :pypi:`html2text`

Args:
__html: Text to process
width: Paragraph width
ascii_replacements: Use pseudo-ASCII replacements for Unicode
Returns:
Rendered text


def _look_adjacent(self, vectors, num_chunks_before, num_chunks_after):
    if num_chunks_before == 0 and num_chunks_after == 0:
        return vectors
    slices = []
    for i in range(-num_chunks_before, num_chunks_after + 1):
        if i == 0:
            slices.append(vectors)
        else:
            slices.append(torch.cat([vectors[:, :, i:, ...], vectors[:, :, :i, ...]], dim=2))
    return torch.cat(slices, dim=3)

Used to implement attention between consecutive chunks.

Args:
vectors: array of shape [batch_size, num_attention_heads, n_chunks, chunk_len, ...]
num_chunks_before: chunks before current chunk to include in attention
num_chunks_after: chunks after current chunk to include in attention

Returns:
tensor of shape [num_chunks, N * chunk_length, ...], where N = (1 + num_chunks_before + num_chunks_after).


def key_to_kind(cls, key):

    if key.kind() == Kind.KIND_NAME:
      return key.id()
    else:
      return key.parent().id()

Return the kind specified by a given __property__ key.

Args:
key: key whose kind name is requested.

Returns:
The kind specified by key.


def add_string_pairs_from_button_element(xib_file, results, button, special_ui_components_prefix):

    button_entry_comment = extract_element_internationalized_comment(button)
    if button_entry_comment is None:
        return

    for state in button.getElementsByTagName('state'):
        state_name = state.attributes['key'].value
        state_entry_comment = button_entry_comment + " - " + state_name + " state of button"
        if not add_string_pairs_from_attributed_ui_element(results, state, state_entry_comment):
            try:
                button_entry_key = state.attributes['title'].value
            except KeyError:
                try:
                    button_entry_key = state.getElementsByTagName('string')[0].firstChild.nodeValue
                except Exception:
                    continue

            results.append((button_entry_key, state_entry_comment))

    warn_if_element_not_of_class(button, 'Button', special_ui_components_prefix)

Adds strings pairs from a button xib element.

Args:
xib_file (str): Path to the xib file.
results (list): The list to add the results to.
button(element): The button element from the xib, to extract the string pairs from.
special_ui_components_prefix(str): A custom prefix for internationalize component to allow (default is only JT)


def minimum_required(version):

        def _minimum_required(func):

            @functools.wraps(func)
            def wrapper(self, *args, **kwargs):

                if list(self.version) < list(version):
                    raise errors.JLinkException('Version %s required.' % version)
                return func(self, *args, **kwargs)
            return wrapper
        return _minimum_required

Decorator to specify the minimum SDK version required.

Args:
version (str): valid version string

Returns:
A decorator function.


def parse_email(data, strip_attachment_payloads=False):

    if type(data) == bytes:
        if is_outlook_msg(data):
            data = convert_outlook_msg(data)
        data = data.decode("utf-8", errors="replace")
    parsed_email = mailparser.parse_from_string(data)
    headers = json.loads(parsed_email.headers_json).copy()
    parsed_email = json.loads(parsed_email.mail_json).copy()
    parsed_email["headers"] = headers

    if "received" in parsed_email:
        for received in parsed_email["received"]:
            if "date_utc" in received:
                if received["date_utc"] is None:
                    del received["date_utc"]
                else:
                    received["date_utc"] = received["date_utc"].replace("T",
                                                                        " ")

    if "from" not in parsed_email:
        if "From" in parsed_email["headers"]:
            parsed_email["from"] = parsed_email["Headers"]["From"]
        else:
            parsed_email["from"] = None

    if parsed_email["from"] is not None:
        parsed_email["from"] = parse_email_address(parsed_email["from"][0])

    if "date" in parsed_email:
        parsed_email["date"] = parsed_email["date"].replace("T", " ")
    else:
        parsed_email["date"] = None
    if "reply_to" in parsed_email:
        parsed_email["reply_to"] = list(map(lambda x: parse_email_address(x),
                                            parsed_email["reply_to"]))
    else:
        parsed_email["reply_to"] = []

    if "to" in parsed_email:
        parsed_email["to"] = list(map(lambda x: parse_email_address(x),
                                      parsed_email["to"]))
    else:
        parsed_email["to"] = []

    if "cc" in parsed_email:
        parsed_email["cc"] = list(map(lambda x: parse_email_address(x),
                                      parsed_email["cc"]))
    else:
        parsed_email["cc"] = []

    if "bcc" in parsed_email:
        parsed_email["bcc"] = list(map(lambda x: parse_email_address(x),
                                       parsed_email["bcc"]))
    else:
        parsed_email["bcc"] = []

    if "delivered_to" in parsed_email:
        parsed_email["delivered_to"] = list(
            map(lambda x: parse_email_address(x),
                parsed_email["delivered_to"])
        )

    if "attachments" not in parsed_email:
        parsed_email["attachments"] = []
    else:
        for attachment in parsed_email["attachments"]:
            if "payload" in attachment:
                payload = attachment["payload"]
                try:
                    if "content_transfer_encoding" in attachment:
                        if attachment["content_transfer_encoding"] == "base64":
                            payload = decode_base64(payload)
                        else:
                            payload = str.encode(payload)
                    attachment["sha256"] = hashlib.sha256(payload).hexdigest()
                except Exception as e:
                    logger.debug("Unable to decode attachment: {0}".format(
                        e.__str__()
                    ))
        if strip_attachment_payloads:
            for attachment in parsed_email["attachments"]:
                if "payload" in attachment:
                    del attachment["payload"]

    if "subject" not in parsed_email:
        parsed_email["subject"] = None

    parsed_email["filename_safe_subject"] = get_filename_safe_string(
        parsed_email["subject"])

    if "body" not in parsed_email:
        parsed_email["body"] = None

    return parsed_email

A simplified email parser

Args:
data: The RFC 822 message string, or MSG binary
strip_attachment_payloads (bool): Remove attachment payloads

Returns (dict): Parsed email data


def _CheckIsSocket(self, file_entry):

    if definitions.FILE_ENTRY_TYPE_SOCKET not in self._file_entry_types:
      return False
    return file_entry.IsSocket()

Checks the is_socket find specification.

Args:
file_entry (FileEntry): file entry.

Returns:
bool: True if the file entry matches the find specification, False if not.


def normalize_datetime_to_utc(dt):
    return datetime.datetime(*dt.utctimetuple()[:6], microsecond=dt.microsecond, tzinfo=datetime.timezone.utc)

Adjust datetime to UTC.

Apply the timezone offset to the datetime and set the timezone to UTC.

This is a no-op if the datetime is already in UTC.

Args:
dt : datetime
- tz-aware: Used in the formatted string.
- tz-naive: Assumed to be in UTC.

Returns:
datetime
The returned datetime is always timezone aware and in UTC.

Notes:
This forces a new object to be returned, which fixes an issue with
serialization to XML in PyXB. PyXB uses a mixin together with
datetime to handle the XML xs:dateTime. That type keeps track of
timezone information included in the original XML doc, which conflicts if we
return it here as part of a datetime mixin.

See Also:
``cast_naive_datetime_to_tz()``


def _generate_placements(self, width, height):

        skyline = self._skyline

        points = collections.deque()

        left_index = right_index = 0
        support_height = skyline[0].top
        support_index = 0

        placements = self._placement_points_generator(skyline, width)
        for p in placements:

            if p+width > skyline[right_index].right:
                for right_index in range(right_index+1, len(skyline)):
                    if skyline[right_index].top >= support_height:
                        support_index = right_index
                        support_height = skyline[right_index].top
                    if p+width <= skyline[right_index].right:
                        break

            if p >= skyline[left_index].right:
                left_index +=1

            if support_index < left_index:
                support_index = left_index
                support_height = skyline[left_index].top
                for i in range(left_index, right_index+1):
                    if skyline[i].top >= support_height:
                        support_index = i
                        support_height = skyline[i].top

            if support_height+height <= self.height:
                points.append((Rectangle(p, support_height, width, height),\
                    left_index, right_index))

        return points

Generate a list with

Arguments:
skyline (list): SkylineHSegment list
width (number):

Returns:
tuple (Rectangle, fitness):
Rectangle: Rectangle in valid position
left_skyline: Index for the skyline under the rectangle left edge.
right_skyline: Index for the skyline under the rectangle right edte.


def dataframe(self, force_refresh=False):
    if force_refresh:
        self.clear_cache()
    if (self._dataframe is None):
        self._dataframe = self._fetch_dataframe()
    return self._dataframe

A pandas dataframe with lots of interesting results about this object.
Created by calling SageMaker List and Describe APIs and converting them into
a convenient tabular summary.

Args:
force_refresh (bool): Set to True to fetch the latest data from SageMaker API.


def parse_string_descriptor(string_desc):

    if not isinstance(string_desc, str):
        string_desc = str(string_desc)

    if not string_desc.endswith(';'):
        string_desc += ';'

    parsed = get_streamer_parser().parseString(string_desc)[0]

    realtime = 'realtime' in parsed
    broadcast = 'broadcast' in parsed
    encrypted = 'security' in parsed and parsed['security'] == 'encrypted'
    signed = 'security' in parsed and parsed['security'] == 'signed'
    auto = 'manual' not in parsed

    with_other = None
    if 'with_other' in parsed:
        with_other = parsed['with_other']
        auto = False

    dest = SlotIdentifier.FromString('controller')
    if 'explicit_tile' in parsed:
        dest = parsed['explicit_tile']

    selector = parsed['selector']

    if realtime and (encrypted or signed):
        raise SensorGraphSemanticError("Realtime streamers cannot be either signed or encrypted")

    if broadcast and (encrypted or signed):
        raise SensorGraphSemanticError("Broadcast streamers cannot be either signed or encrypted")

    report_type = 'broadcast' if broadcast else 'telegram'
    dest = dest
    selector = selector

    if realtime or broadcast:
        report_format = u'individual'
    elif signed:
        report_format = u'signedlist_userkey'
    elif encrypted:
        raise SensorGraphSemanticError("Encrypted streamers are not yet supported")
    else:
        report_format = u'hashedlist'

    return DataStreamer(selector, dest, report_format, auto, report_type=report_type, with_other=with_other)

Parse a string descriptor of a streamer into a DataStreamer object.

Args:
string_desc (str): The string descriptor that we wish to parse.

Returns:
DataStreamer: A DataStreamer object representing the streamer.


def get_staged_signatures(vcs):
    staged_path = _get_staged_history_path(vcs)
    known_signatures = []
    if os.path.exists(staged_path):
        with open(staged_path, 'r') as f:
            known_signatures = f.read().split()
    return known_signatures

Get the list of staged signatures

Args:
vcs (easyci.vcs.base.Vcs)

Returns:
list(basestring) - list of signatures


def __init__(self, configuration_file='dependencies.ini'):

    super(DependencyHelper, self).__init__()
    self._test_dependencies = {}
    self.dependencies = {}

    dependency_reader = DependencyDefinitionReader()

    with open(configuration_file, 'r') as file_object:
      for dependency in dependency_reader.Read(file_object):
        self.dependencies[dependency.name] = dependency

    dependency = DependencyDefinition('mock')
    dependency.minimum_version = '0.7.1'
    dependency.version_property = '__version__'
    self._test_dependencies['mock'] = dependency

Initializes a dependency helper.

Args:
configuration_file (Optional[str]): path to the dependencies
configuration file.


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

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

    encoding_method = getattr(path_spec, 'encoding_method', None)
    if not encoding_method:
      raise errors.PathSpecError(
          'Unsupported path specification without encoding method.')

    self._encoding_method = encoding_method

Opens the file system defined by path specification.

Args:
path_spec (PathSpec): a path specification.
mode (Optional[str]): file access mode. The default is 'rb' which
represents read-only binary.

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


def sparse_read(self, indices, name=None):
    raise AttributeError

Gather slices from params axis axis according to indices.

This function supports a subset of tf.gather, see tf.gather for details on
usage.

Args:
indices: The index `Tensor`.  Must be one of the following types: `int32`,
`int64`. Must be in range `[0, params.shape[axis])`.
name: A name for the operation (optional).

Returns:
A `Tensor`. Has the same type as `params`.


def pyc_load(fp):

    magic_1 = U16(fp.read(2), target=MARSHAL_TARGET)
    magic_2 = U16(fp.read(2), target=MARSHAL_TARGET)

    internals = MAGIC_MAP.get(magic_1)
    if internals is None:
        raise ValueError('Invalid or unknown magic (%d).' % magic_1)

    if magic_2 != 2573:
        raise ValueError('Invalid secondary magic (%d).' % magic_2)

    timestamp = datetime.datetime.fromtimestamp(U32(fp.read(4), target=MARSHAL_TARGET))

    if internals['version'] >= 33:
        file_size = U32(fp.read(4))
    else:
        file_size = None

    code_object = marshal_load(fp, internals)

    return PycFile(magic_1, internals, timestamp, file_size, code_object)

Load a .pyc file from a file-like object.

Arguments:
fp(file): The file-like object to read.

Returns:
PycFile: The parsed representation of the .pyc file.


def apply_mutation(module_path, operator, occurrence):

    module_ast = get_ast(module_path, python_version=operator.python_version)
    original_code = module_ast.get_code()
    visitor = MutationVisitor(occurrence, operator)
    mutated_ast = visitor.walk(module_ast)

    mutated_code = None
    if visitor.mutation_applied:
        mutated_code = mutated_ast.get_code()
        with module_path.open(mode='wt', encoding='utf-8') as handle:
            handle.write(mutated_code)
            handle.flush()

    return original_code, mutated_code

Apply a specific mutation to a file on disk.

Args:
module_path: The path to the module to mutate.
operator: The `operator` instance to use.
occurrence: The occurrence of the operator to apply.

Returns: A `(unmutated-code, mutated-code)` tuple to the with-block. If there was
no mutation performed, the `mutated-code` is `None`.


def _expand_ellipsis(key_list, num_remaining_dims):
    if num_remaining_dims is None:
        raise ValueError('Ellipsis not supported for unknown shape RaggedTensors')
    num_indices = sum((1 for idx in key_list if idx is not array_ops.newaxis))
    if num_indices > num_remaining_dims + 1:
        raise IndexError('Too many indices for RaggedTensor')
    elif num_indices == num_remaining_dims + 1:
        return key_list[1:]
    else:
        return [slice(None, None, None)] + key_list

Expands the ellipsis at the start of `key_list`.

Assumes that the first element of `key_list` is Ellipsis.  This will either
remove the Ellipsis (if it corresponds to zero indices) or prepend a new
`slice(None, None, None)` (if it corresponds to more than zero indices).

Args:
key_list: The arguments to `__getitem__()`.
num_remaining_dims: The number of dimensions remaining.

Returns:
A copy of `key_list` with he ellipsis expanded.
Raises:
ValueError: If ragged_rank.shape.ndims is None
IndexError: If there are too many elements in `key_list`.


def duplicate(script, layer_num=None):
    filter_xml = '  <filter name="Duplicate Current layer"/>\n'
    if isinstance(script, mlx.FilterScript):
        if ((layer_num is None) or (layer_num == script.current_layer())):
            util.write_filter(script, filter_xml)
            script.add_layer('{}_copy'.format(script.layer_stack[script.current_layer()]), True)
        else:
            change(script, layer_num)
            util.write_filter(script, filter_xml)
            script.add_layer('{}_copy'.format(script.layer_stack[layer_num]), True)
    else:
        util.write_filter(script, filter_xml)
    return None

Duplicate a layer.

New layer label is '*_copy'.

Args:
script: the mlx.FilterScript object or script filename to write
the filter to.
layer_num (int): layer number to duplicate. Default is the
current layer. Not supported on the file base API.

Layer stack:
Creates a new layer
Changes current layer to the new layer

MeshLab versions:
2016.12
1.3.4BETA


def combine(a1, a2):

    if not isinstance(a1, list):
        a1 = [a1]
    if not isinstance(a2, list):
        a2 = [a2]
    return a1 + a2

Combine to argument into a single flat list

It is used when you are not sure whether arguments are lists but want to combine them into one flat list

Args:
a1: list or other thing
a2: list or other thing

Returns:
list: a flat list contain a1 and a2


def get_spectre_plot(self, sigma=0.05, step=0.01):
    from pymatgen.util.plotting import pretty_plot
    from matplotlib.mlab import normpdf
    plt = pretty_plot(12, 8)
    transitions = self.read_excitation_energies()
    minval = (min([val[0] for val in transitions]) - (5.0 * sigma))
    maxval = (max([val[0] for val in transitions]) + (5.0 * sigma))
    npts = (int(((maxval - minval) / step)) + 1)
    eneval = np.linspace(minval, maxval, npts)
    lambdaval = [(((cst.h * cst.c) / (val * cst.e)) * 1000000000.0) for val in eneval]
    spectre = np.zeros(npts)
    for trans in transitions:
        spectre += (trans[2] * normpdf(eneval, trans[0], sigma))
    spectre /= spectre.max()
    plt.plot(lambdaval, spectre, 'r-', label='spectre')
    data = {'energies': eneval, 'lambda': lambdaval, 'xas': spectre}
    plt.vlines([val[1] for val in transitions], 0.0, [val[2] for val in transitions], color='blue', label='transitions', linewidth=2)
    plt.xlabel('$\\lambda$ (nm)')
    plt.ylabel('Arbitrary unit')
    plt.legend()
    return (data, plt)

Get a matplotlib plot of the UV-visible xas. Transition are plotted
as vertical lines and as a sum of normal functions with sigma with. The
broadening is applied in energy and the xas is plotted as a function
of the wavelength.

Args:
sigma: Full width at half maximum in eV for normal functions.
step: bin interval in eV

Returns:
A dict: {"energies": values, "lambda": values, "xas": values}
where values are lists of abscissa (energies, lamba) and
the sum of gaussian functions (xas).
A matplotlib plot.


def _illegal_character(c, ctx, message=''):

    container_type = ctx.container.ion_type is None and 'top-level' or ctx.container.ion_type.name
    value_type = ctx.ion_type is None and 'unknown' or ctx.ion_type.name
    if c is None:
        header = 'Illegal token'
    else:
        c = 'EOF' if BufferQueue.is_eof(c) else _chr(c)
        header = 'Illegal character %s' % (c,)
    raise IonException('%s at position %d in %s value contained in %s. %s Pending value: %s'
                       % (header, ctx.queue.position, value_type, container_type, message, ctx.value))

Raises an IonException upon encountering the given illegal character in the given context.

Args:
c (int|None): Ordinal of the illegal character.
ctx (_HandlerContext):  Context in which the illegal character was encountered.
message (Optional[str]): Additional information, as necessary.


def AddSubkey(self, registry_key):

    name = registry_key.name.upper()
    if name in self._subkeys:
      raise KeyError(
          'Subkey: {0:s} already exists.'.format(registry_key.name))

    self._subkeys[name] = registry_key

    key_path = key_paths.JoinKeyPath([self._key_path, registry_key.name])
    registry_key._key_path = key_path

Adds a subkey.

Args:
registry_key (WinRegistryKey): Windows Registry subkey.

Raises:
KeyError: if the subkey already exists.


def read_tensor_tracer_event_file(event_file):
    step_occurrence_count = collections.defaultdict(int)
    step_occurrence_list = []
    for trace_event in summary_iterator.summary_iterator(event_file):
        if not trace_event.HasField('summary'):
            continue
        if len(trace_event.summary.value) != 1:
            raise ValueError('Single step contains %d summary values, expected 1.' % len(trace_event.summary.value))
        step = trace_event.step
        step_occurrence_count[step] += 1
        occurrence_idx = step_occurrence_count[step] - 1
        occurrence_size = len(step_occurrence_list)
        if occurrence_idx == occurrence_size:
            new_occurrence = collections.defaultdict(dict)
            step_occurrence_list.append(new_occurrence)
        elif occurrence_idx > occurrence_size:
            raise ValueError('Unexpected: occurrence_idx (%d) > occurrence_size (%d)' % (occurrence_idx, occurrence_size))
        tensor_value = trace_event.summary.value[0]
        tensor_name = tensor_value.tag
        real_shape = [d.size for d in tensor_value.tensor.tensor_shape.dim]
        tensor_content = np.frombuffer(tensor_value.tensor.tensor_content, dtypes.DType(tensor_value.tensor.dtype).as_numpy_dtype()).reshape(real_shape)
        step_occurrence_list[occurrence_idx][step][tensor_name] = tensor_content
    return step_occurrence_list

Reads the event file written by tensor tracer.

This can be used to read the full tensors written into binary event files by
by TensorTracer with trace_mode=full_tensor_summary.

Example usage:
result_dict_list = tensor_tracer.read_tensor_tracer_event_file(
event_file_path)
for result_dict in result_dict_list:
for step, tensor_dict in result_dict.items():
for tensor_name, full_tensor_content in tensor_dict.items():
logging.info(tensor_name, full_tensor_content)

Args:
event_file: Path to the event file that contains only tensor tracer events.
Returns:
A list of event dictionaries, each of which with the form:
{step_number: {tensor_name: tensor_content}}. This is a list instead of
a single event dictionary because it is possible that an event file may
have multiple event traces, each of them covering the same step ranges.
Raises:
ValueError: If an unexpected trace is found.


def Downsampled(cls, stats, interval=None):
    interval = (interval or cls.DEFAULT_SAMPLING_INTERVAL)
    result = cls(stats)
    result.cpu_samples = cls._Downsample(kind=CpuSample, samples=stats.cpu_samples, interval=interval)
    result.io_samples = cls._Downsample(kind=IOSample, samples=stats.io_samples, interval=interval)
    return result

Constructs a copy of given stats but downsampled to given interval.

Args:
stats: A `ClientStats` instance.
interval: A downsampling interval.

Returns:
A downsampled `ClientStats` instance.


def eig(x):
    if any_symbolic_tensors((x,)):
        return Eig().symbolic_call(x)
    return _eig(x)

Computes the eigenvalues and eigenvectors of a square matrix.

Args:
x: Input tensor of shape `(..., M, M)`.

Returns:
A tuple of two tensors: a tensor of shape `(..., M)` containing
eigenvalues and a tensor of shape `(..., M, M)` containing eigenvectors.


def update_handler(Model, name=None, **kwds):

    async def action_handler(service, action_type, payload, props, notify=True, **kwds):
        if (action_type == get_crud_action('update', (name or Model))):
            try:
                message_props = {}
                if ('correlation_id' in props):
                    message_props['correlation_id'] = props['correlation_id']
                pk_field = Model.primary_key()
                if (not (pk_field.name in payload)):
                    raise ValueError('Must specify the pk of the model when updating')
                model = Model.select().where((pk_field == payload[pk_field.name])).get()
                payload.pop(pk_field.name, None)
                for (key, value) in payload.items():
                    setattr(model, key, value)
                model.save()
                if notify:
                    (await service.event_broker.send(payload=ModelSerializer().serialize(model), action_type=change_action_status(action_type, success_status()), **message_props))
            except Exception as err:
                if notify:
                    (await service.event_broker.send(payload=str(err), action_type=change_action_status(action_type, error_status()), **message_props))
                else:
                    raise err
    return action_handler

This factory returns an action handler that updates a new instance of
the specified model when a update action is recieved, assuming the
action follows nautilus convetions.

Args:
Model (nautilus.BaseModel): The model to update when the action
received.

Returns:
function(type, payload): The action handler for this model


def add(self, *l):
    for a in flatten(l):
        self._add([self.Inner(a)], self.l)

add inner to outer

Args:
*l: element that is passed into Inner init


def __init__(self, name, min_val, max_val):

        self.name = name
        self.min_val = min_val
        self.max_val = max_val
        if type(min_val) != type(max_val):
            raise ValueError('Supplied min_val is not the same type as\
                             supplied max_val: {}, {}'.format(
                                 type(min_val),
                                 type(max_val))
                             )
        self.dtype = type(min_val + max_val)
        if self.dtype not in SUPPORTED_DTYPES:
            raise ValueError('Unsupported data type: use {}'
                             .format(SUPPORTED_DTYPES))

Parameter object

Args:
name (str): name of the parameter
min_val (int or float): minimum allowed value for the parameter
max_val (int or float): maximum allowed value for the parameter


def template(self):
    instance = self.template_instance()
    offset = (self._chunk.offset() + instance.template_offset())
    node = TemplateNode(self._buf, offset, self._chunk, instance)
    return node

parse the template referenced by this root node.
note, this template structure is not guaranteed to be located within the root node's boundaries.

Returns:
TemplateNode: the template.


def get_glibc_version():
    key = 'glibc_ver'
    out, err = run_shell_cmd(cmds_all[PLATFORM.lower()][key])
    if err and FLAGS.debug:
        print('Error in detecting GCC version:\n %s' % str(err))
    return out.strip(b'\n')

Retrieves version of GLIBC detected.

Returns:
String that is the version of GLIBC.
e.g. '2.24'


def report_uninitialized_resources(resource_list=None, name='report_uninitialized_resources'):
    if resource_list is None:
        resource_list = shared_resources() + local_resources()
    with ops.name_scope(name):
        local_device = os.environ.get('TF_DEVICE_FOR_UNINITIALIZED_VARIABLE_REPORTING', '/cpu:0')
        with ops.device(local_device):
            if not resource_list:
                return array_ops.constant([], dtype=dtypes.string)
            variables_mask = math_ops.logical_not(array_ops_stack.stack([r.is_initialized for r in resource_list]))
            variable_names_tensor = array_ops.constant([s.handle.name for s in resource_list])
            return array_ops.boolean_mask(variable_names_tensor, variables_mask)

Returns the names of all uninitialized resources in resource_list.

If the returned tensor is empty then all resources have been initialized.

Args:
resource_list: resources to check. If None, will use shared_resources() +
local_resources().
name: name for the resource-checking op.

Returns:
Tensor containing names of the handles of all resources which have not
yet been initialized.


def shift(x, offset, dim, wrap, name=None):
    return ShiftOperation(x, offset, dim, wrap, name=name).outputs[0]

Shift operation.

Shift x right by +offset in dimension dim.

Args:
x: a Tensor
offset: an integer. If negative, shift left instead of right.
dim: a Dimension of x
wrap: a boolean - whether to wrap (True) or pad with zeros (False).
name: an optional string

Returns:
a Tensor with the same shape and dtype as x


def get_processes(sort_by_name=True):

    if sort_by_name:
        return sorted(
            _list_processes(),
            key=cmp_to_key(
                lambda p1, p2: (cmp(p1.name, p2.name) or cmp(p1.pid, p2.pid))
            ),
        )
    else:
        return sorted(
            _list_processes(),
            key=cmp_to_key(
                lambda p1, p2: (cmp(p1.pid, p2.pid) or cmp(p1.name, p2.name))
            ),
        )

Retrieve a list of processes sorted by name.

Args:
sort_by_name (bool): Sort the list by name or by process ID's.

Returns:
list of (int, str) or list of (int, str, str): List of process id,
process name and optional cmdline tuples.


def validate(cls, mapper_spec):

    if mapper_spec.output_writer_class() != cls:
      raise errors.BadWriterParamsError("Output writer class mismatch")
    params = output_writers._get_params(mapper_spec)

    if cls.BUCKET_NAME_PARAM not in params:
      raise errors.BadWriterParamsError(
          "%s is required for the _HashingGCSOutputWriter" %
          cls.BUCKET_NAME_PARAM)

Validates mapper specification.

Args:
mapper_spec: an instance of model.MapperSpec to validate.
Raises:
BadWriterParamsError: when Output writer class mismatch.


def separate_words(text, acronyms=None):
    (words, _case, _sep) = case_parse.parse_case(text, acronyms, preserve_case=True)
    return ' '.join(words)

Return text in "seperate words" style.

Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect

>>> separate_words("HELLO_WORLD")
'HELLO WORLD'
>>> separate_words("helloHTMLWorld", True, ["HTML"])
'hello HTML World'


def __init__(self, instrument, probe_name, name = None, info = None, buffer_length = 100):

        assert isinstance(instrument, Instrument)
        assert isinstance(probe_name, str)
        assert probe_name in instrument._PROBES

        if name is None:
            name = probe_name
        assert isinstance(name, str)

        if info is None:
            info = ''
        assert isinstance(info, str)

        self.name = name
        self.info = info
        self.instrument = instrument
        self.probe_name = probe_name

        self.buffer = deque(maxlen = buffer_length)

creates a probe...
Args:
name (optinal):  name of probe, if not provided take name of function
settings (optinal): a Parameter object that contains all the information needed in the script


async def reset(self):
    params = {'include_participants': (1 if AUTO_GET_PARTICIPANTS else 0), 'include_matches': (1 if AUTO_GET_MATCHES else 0)}
    res = (await self.connection('POST', 'tournaments/{}/reset'.format(self._id), **params))
    self._refresh_from_json(res)

reset the tournament on Challonge

|methcoro|

Note:
|from_api| Reset a tournament, clearing all of its scores and attachments. You can then add/remove/edit participants before starting the tournament again.

Raises:
APIException


Returns the number of axes in a tensor, as an integer.

Args:
x: Tensor or variable.

Returns:
Integer (scalar), number of axes.

Examples:

>>> input = tf.keras.backend.placeholder(shape=(2, 4, 5))
>>> val = np.array([[1, 2], [3, 4]])
>>> kvar = tf.keras.backend.variable(value=val)
>>> tf.keras.backend.ndim(input)
3
>>> tf.keras.backend.ndim(kvar)
2


def _checkBool(inputvalue, description='inputvalue'):

    _checkString(description, minlength=1, description='description string')
    if not isinstance(inputvalue, bool):
        raise TypeError('The {0} must be boolean. Given: {1!r}'.format(description, inputvalue))

Check that the given inputvalue is a boolean.

Args:
* inputvalue (boolean): The value to be checked.
* description (string): Used in error messages for the checked inputvalue.

Raises:
TypeError, ValueError


def query_gal(self, l, b, d=None, **kwargs):
    if (not isinstance(l, units.Quantity)):
        l = (l * units.deg)
    if (not isinstance(b, units.Quantity)):
        b = (b * units.deg)
    if (d is None):
        coords = coordinates.SkyCoord(l, b, frame='galactic')
    else:
        if (not isinstance(d, units.Quantity)):
            d = (d * units.kpc)
        coords = coordinates.SkyCoord(l, b, distance=d, frame='galactic')
    return self.query(coords, **kwargs)

Query using Galactic coordinates.

Args:
l (:obj:`float`, scalar or array-like): Galactic longitude, in degrees,
or as an :obj:`astropy.unit.Quantity`.
b (:obj:`float`, scalar or array-like): Galactic latitude, in degrees,
or as an :obj:`astropy.unit.Quantity`.
d (Optional[:obj:`float`, scalar or array-like]): Distance from the Solar
System, in kpc, or as an :obj:`astropy.unit.Quantity`. Defaults to
``None``, meaning no distance is specified.
**kwargs: Any additional keyword arguments accepted by derived
classes.

Returns:
The results of the query, which must be implemented by derived
classes.


def list_filters(self):

    def _row_gen(attributes):
        for attr in attributes.values():
            (yield (attr.name, attr.type, attr.description))
    return pd.DataFrame.from_records(_row_gen(self.filters), columns=['name', 'type', 'description'])

Lists available filters in a readable DataFrame format.

Returns:
pd.DataFrame: Frame listing available filters.


def get_groups(self, **kwargs):

        params = {
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

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

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

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

Obtain line types and details.

Args:
lang (str): Language code (*es* or *en*).

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


def apply(self, inputs, *args, **kwargs):
    warnings.warn('`layer.apply` is deprecated and will be removed in a future version. Please use `layer.__call__` method instead.')
    return self.__call__(inputs, *args, **kwargs)

Deprecated, do NOT use!

This is an alias of `self.__call__`.

Args:
inputs: Input tensor(s).
*args: additional positional arguments to be passed to `self.call`.
**kwargs: additional keyword arguments to be passed to `self.call`.

Returns:
Output tensor(s).


def datasets_get(self, dataset_name):

    url = Api._ENDPOINT + (Api._DATASETS_PATH % dataset_name)
    return datalab.utils.Http.request(url, credentials=self._credentials)

Issues a request to retrieve information about a dataset.

Args:
dataset_name: the name of the dataset
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.


def add(self, rule: 'functions.ReplacementRule') -> None:

        self.matcher.add(rule.pattern, rule.replacement)

Add a new rule to the replacer.

Args:
rule:
The rule to add.


def dr(self, atom1, atom2):
    return self.cell.dr(atom1.r, atom2.r)

Calculate the distance between two atoms.

Args:
atom1 (vasppy.Atom): Atom 1.
atom2 (vasppy.Atom): Atom 2.

Returns:
(float): The distance between Atom 1 and Atom 2.


def _ws_on_open(self, ws: websocket.WebSocketApp):
    payload = {'op': WebSocketEvent.IDENTIFY.value, 'd': {'token': self.token, 'properties': {'$os': sys.platform, '$browser': 'Pycord', '$device': 'Pycord', '$referrer': '', '$referring_domain': ''}, 'compress': True, 'large_threshold': 250}}
    self.logger.debug('Sending identify payload')
    ws.send(json.dumps(payload))
    self.connected = True

Callback for sending the initial authentication data

This "payload" contains the required data to authenticate this websocket
client as a suitable bot connection to the Discord websocket.

Args:
ws: websocket connection


def get_item(dictionary, tuple_key, default_value):

    u, v = tuple_key

    tuple1 = dictionary.get((u, v), None)
    tuple2 = dictionary.get((v, u), None)

    return tuple1 or tuple2 or default_value

Grab values from a dictionary using an unordered tuple as a key.

Dictionary should not contain None, 0, or False as dictionary values.

Args:
dictionary: Dictionary that uses two-element tuple as keys
tuple_key: Unordered tuple of two elements
default_value: Value that is returned when the tuple_key is not found in the dictionary


def get_lattice_type(number):

        f = lambda i, j: i <= number <= j
        cs = {'triclinic': (1, 2), 'monoclinic': (3, 15),
              'orthorhombic': (16, 74), 'tetragonal': (75, 142),
              'trigonal': (143, 167), 'hexagonal': (168, 194),
              'cubic': (195, 230)}

        crystal_system = None
        for k, v in cs.items():
            if f(*v):
                crystal_system = k
                break

        if number in [146, 148, 155, 160, 161, 166, 167]:
            return "rhombohedral"
        elif crystal_system == "trigonal":
            return "hexagonal"
        else:
            return crystal_system

Return the lattice crystal system.

Hexagonal cells are differentiated into rhombohedral and hexagonal
lattices.

Args:
number (int): The international space group number.

Returns:
str: The lattice crystal system.


def download_structure(pdb_id, file_type, outdir='', only_header=False, force_rerun=False):

    pdb_id = pdb_id.lower()
    file_type = file_type.lower()
    file_types = ['pdb', 'pdb.gz', 'mmcif', 'cif', 'cif.gz', 'xml.gz', 'mmtf', 'mmtf.gz']
    if file_type not in file_types:
        raise ValueError('Invalid file type, must be either: pdb, pdb.gz, cif, cif.gz, xml.gz, mmtf, mmtf.gz')

    if file_type == 'mmtf':
        file_type = 'mmtf.gz'

    if file_type.endswith('.gz'):
        gzipped = True
    else:
        gzipped = False

    if file_type == 'mmcif':
        file_type = 'cif'

    if only_header:
        folder = 'header'
        outfile = op.join(outdir, '{}.header.{}'.format(pdb_id, file_type))
    else:
        folder = 'download'
        outfile = op.join(outdir, '{}.{}'.format(pdb_id, file_type))

    if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
        if file_type == 'mmtf.gz' or file_type == 'mmtf':
            mmtf_api = '1.0'
            download_link = 'http:
        else:
            download_link = 'http:

        urlretrieve(download_link, outfile)

        if gzipped:
            outfile = ssbio.utils.gunzip_file(infile=outfile,
                                              outfile=outfile.strip('.gz'),
                                              outdir=outdir,
                                              delete_original=False,
                                              force_rerun_flag=force_rerun)

        log.debug('{}: saved structure file'.format(outfile))
    else:
        if file_type == 'mmtf.gz':
            outfile = op.join(outdir, '{}.{}'.format(pdb_id, 'mmtf'))
        log.debug('{}: structure file already saved'.format(outfile))

    return outfile

Download a structure from the RCSB PDB by ID. Specify the file type desired.

Args:
pdb_id: PDB ID
file_type: pdb, pdb.gz, mmcif, cif, cif.gz, xml.gz, mmtf, mmtf.gz
outdir: Optional output directory
only_header: If only the header file should be downloaded
force_rerun: If the file should be downloaded again even if it exists

Returns:
str: Path to outfile