def _create_route(self, env, item):

        if item.name in env:
            if isinstance(env[item.name], ApiRoutesByVersion):
                if item.version in env[item.name].at_version:
                    existing_dt = env[item.name].at_version[item.version]
                    raise InvalidSpec(
                        'Route %s at version %d already defined (%s:%d).' % (
                            quote(item.name), item.version, existing_dt._ast_node.path,
                            existing_dt._ast_node.lineno),
                        item.lineno, item.path)
            else:
                existing_dt = env[item.name]
                raise InvalidSpec(
                    'Symbol %s already defined (%s:%d).' % (
                        quote(item.name), existing_dt._ast_node.path,
                        existing_dt._ast_node.lineno),
                    item.lineno, item.path)
        else:
            env[item.name] = ApiRoutesByVersion()

        route = ApiRoute(
            name=item.name,
            version=item.version,
            ast_node=item,
        )
        env[route.name].at_version[route.version] = route
        return route

Constructs a route and adds it to the environment.

Args:
env (dict): The environment of defined symbols. A new key is added
corresponding to the name of this new route.
item (AstRouteDef): Raw route definition from the parser.

Returns:
stone.api.ApiRoutesByVersion: A group of fully-defined routes indexed by versions.


def __init__(self, unique_identifier=None, attribute_names=None):

        super(GetAttributesRequestPayload, self).__init__(
            enums.Tags.REQUEST_PAYLOAD)

        self._unique_identifier = None
        self._attribute_names = list()

        self.unique_identifier = unique_identifier
        self.attribute_names = attribute_names

Construct a GetAttributes request payload.

Args:
unique_identifier (string): The ID of the managed object with
which the retrieved attributes should be associated. Optional,
defaults to None.
attribute_names: A list of strings identifying the names of the
attributes associated with the managed object. Optional,
defaults to None.


def shadow_calc(data):

    up_shadow = abs(data.high - (max(data.open, data.close)))
    down_shadow = abs(data.low - (min(data.open, data.close)))
    entity = abs(data.open - data.close)
    towards = True if data.open < data.close else False
    print('=' * 15)
    print('up_shadow : {}'.format(up_shadow))
    print('down_shadow : {}'.format(down_shadow))
    print('entity: {}'.format(entity))
    print('towards : {}'.format(towards))
    return up_shadow, down_shadow, entity, data.date, data.code

计算上下影线

Arguments:
data {DataStruct.slice} -- 输入的是一个行情切片

Returns:
up_shadow {float} -- 上影线
down_shdow {float} -- 下影线
entity {float} -- 实体部分
date {str} -- 时间
code {str} -- 代码


def _runOneBenchmark(self, default_device, num_iters=10, static_unroll=False, steps=10):

    def loop_body(i, x):
        with ops.device('/gpu:0'):
            nx = nn_ops.conv2d(input=x, filter=kernel, strides=[1, 1, 1, 1], padding='SAME', data_format='NHWC', name='conv2d')
            ni = math_ops.add(i, 1)
            return (ni, nx)
    ops.reset_default_graph()
    with session.Session() as sess, ops.device(default_device):
        i, x, kernel = self._getInitVariables()
        self.evaluate(variables.global_variables_initializer())
        if static_unroll:
            for _ in range(steps):
                i, x = loop_body(i, x)
        else:
            i, x = while_loop_tf.while_loop(lambda i, _: i < steps, loop_body, [i, x], parallel_iterations=steps, swap_memory=True)
        r = math_ops.reduce_sum(x)
        dx, dk = gradients_impl.gradients(r, [x, kernel])
        r = control_flow_ops.group(dx, dk)
        for _ in range(3):
            self.evaluate(r)
        start_time = time.time()
        for _ in range(num_iters):
            self.evaluate(r)
        return (time.time() - start_time) / num_iters

Evaluate the while loop performance.

Args:
default_device: The default device to run all ops except the loop_body.
loop_body is always run on GPU.
num_iters: Number of iterations to run.
static_unroll: If true, run unrolled version; otherwise, run while_loop.
steps: Total number of repeated steps to run the loop.

Returns:
The duration of the run in seconds.


def _get_rest_doc(self, request, start_response):

    api = request.body_json['api']
    version = request.body_json['version']

    generator = discovery_generator.DiscoveryGenerator(request=request)
    services = [s for s in self._backend.api_services if
                s.api_info.name == api and s.api_info.api_version == version]
    doc = generator.pretty_print_config_to_json(services)
    if not doc:
      error_msg = ('Failed to convert .api to discovery doc for '
                   'version %s of api %s') % (version, api)
      _logger.error('%s', error_msg)
      return util.send_wsgi_error_response(error_msg, start_response)
    return self._send_success_response(doc, start_response)

Sends back HTTP response with API directory.

This calls start_response and returns the response body.  It will return
the discovery doc for the requested api/version.

Args:
request: An ApiRequest, the transformed request sent to the Discovery API.
start_response: A function with semantics defined in PEP-333.

Returns:
A string, the response body.


def attention_mask_autoregressive(query_pos, dtype=tf.float32):
    memory_pos = rename_length_to_memory_length(query_pos)
    return (mtf.cast(mtf.less(query_pos, memory_pos), dtype) * (- 1000000000.0))

Bias for self-attention where attention to the right is disallowed.

Args:
query_pos: a mtf.Tensor with shape [..., length_dim]
dtype: a tf.dtype

Returns:
a mtf.Tensor with shape [..., length_dim, memory_length_dim]


def unwrap_or_else(self, callback: Callable[([], U)]) -> Union[(T, U)]:
    return (self._val if self._is_some else callback())

Returns the contained value or computes it from ``callback``.

Args:
callback: The the default callback.

Returns:
The contained value if the :py:class:`Option` is ``Some``,
otherwise ``callback()``.

Examples:
>>> Some(0).unwrap_or_else(lambda: 111)
0
>>> NONE.unwrap_or_else(lambda: 'ha')
'ha'


def to_barrier_key(cls, barrier_index_key):

    barrier_index_path = barrier_index_key.to_path()

    (pipeline_kind, dependent_pipeline_id,
     unused_kind, purpose) = barrier_index_path[-4:]

    barrier_record_path = (
        pipeline_kind, dependent_pipeline_id,
        _BarrierRecord.kind(), purpose)

    return db.Key.from_path(*barrier_record_path)

Converts a _BarrierIndex key to a _BarrierRecord key.

Args:
barrier_index_key: db.Key for a _BarrierIndex entity.

Returns:
db.Key for the corresponding _BarrierRecord entity.


def clear_tc(self, owner, data, clear_type):
    batch = self.tcex.batch(owner, action='Delete')
    tc_type = data.get('type')
    path = data.get('path')
    if (tc_type in self.tcex.group_types):
        name = self.tcex.playbook.read(data.get('name'))
        name = self.path_data(name, path)
        if (name is not None):
            print('Deleting ThreatConnect Group: {}{}{}'.format(c.Style.BRIGHT, c.Fore.MAGENTA, name))
            self.log.info('[{}] Deleting ThreatConnect {} with name: {}.'.format(clear_type, tc_type, name))
            batch.group(tc_type, name)
    elif (tc_type in self.tcex.indicator_types):
        if (data.get('summary') is not None):
            summary = self.tcex.playbook.read(data.get('summary'))
        else:
            resource = self.tcex.resource(tc_type)
            summary = resource.summary(data)
        summary = self.path_data(summary, path)
        if (summary is not None):
            print('Deleting ThreatConnect Indicator: {}{}{}'.format(c.Style.BRIGHT, c.Fore.MAGENTA, summary))
            self.log.info('[{}] Deleting ThreatConnect {} with value: {}.'.format(clear_type, tc_type, summary))
            batch.indicator(tc_type, summary)
    batch_results = batch.submit()
    self.log.debug('[{}] Batch Results: {}'.format(clear_type, batch_results))
    for error in (batch_results.get('errors') or []):
        self.log.error('[{}] Batch Error: {}'.format(clear_type, error))

Delete threat intel from ThreatConnect platform.

Args:
owner (str): The ThreatConnect owner.
data (dict): The data for the threat intel to clear.
clear_type (str): The type of clear action.


def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):

        local_stream = BytearrayStream()

        if self._unique_identifier:
            self._unique_identifier.write(
                local_stream,
                kmip_version=kmip_version
            )
        else:
            raise ValueError(
                "Invalid struct missing the unique identifier attribute."
            )

        if self._cryptographic_parameters:
            self._cryptographic_parameters.write(
                local_stream,
                kmip_version=kmip_version
            )

        self.length = local_stream.length()
        super(MACSignatureKeyInformation, self).write(
            output_stream,
            kmip_version=kmip_version
        )
        output_stream.write(local_stream.buffer)

Write the data encoding the MACSignatureKeyInformation struct to a
stream.

Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.


def _get_element_by_names(source, names):

    if source is None:
        return source

    else:
        if names:
            head, *rest = names
            if isinstance(source, dict) and head in source:
                return _get_element_by_names(source[head], rest)
            elif isinstance(source, list) and head.isdigit():
                return _get_element_by_names(source[int(head)], rest)
            elif not names[0]:
                pass
            else:
                source = None
        return source

Given a dict and path '/' or '.' separated. Digs into de dict to retrieve
the specified element.

Args:
source (dict): set of nested objects in which the data will be searched
path (list): list of attribute names


def from_unknown_text(text, strict=False):
    if text.startswith('+'):
        crs = from_proj4(text, strict)
    elif text.startswith(('PROJCS[', 'GEOGCS[')):
        crs = from_unknown_wkt(text, strict)
    elif text.startswith('EPSG:'):
        crs = from_epsg_code(text.split(':')[1])
    elif text.startswith('ESRI:'):
        crs = from_esri_code(text.split(':')[1])
    elif text.startswith('SR-ORG:'):
        crs = from_sr_code(text.split(':')[1])
    else:
        raise FormatError('Could not auto-detect the type of crs format, make sure it is one of the supported formats')
    return crs

Detect crs string format and parse into crs object with appropriate function.

Arguments:

- *text*: The crs text representation of unknown type.
- *strict* (optional): When True, the parser is strict about names having to match
exactly with upper and lowercases. Default is not strict (False).

Returns:

- CRS object.


def from_structures(cls, structures, constant_lattice=True, **kwargs):

        frac_coords = [structure.frac_coords for structure in structures]
        if constant_lattice:
            lattice = structures[0].lattice.matrix
        else:
            lattice = [structure.lattice.matrix for structure in structures]
        site_properties = [structure.site_properties for structure in structures]
        return cls(lattice, structures[0].species, frac_coords, site_properties=site_properties,
                   constant_lattice=constant_lattice, **kwargs)

Convenience constructor to obtain trajectory from a list of structures.
Note: Assumes no atoms removed during simulation

Args:
structures (list): list of pymatgen Structure objects.
constant_lattice (bool): Whether the lattice changes during the simulation, such as in an NPT MD
simulation. True results in

Returns:
(Trajectory)


def get(cls, ns, key):
    return getattr(db, cls.__name__).find_one((ConfigItem.namespace_prefix == ns), (ConfigItem.key == key))

Fetch an item by namespace and key

Args:
ns (str): Namespace prefix
key (str): Item key

Returns:
:obj:`Configitem`: Returns config item object if found, else `None`


def search(self, trace_func: Callable[([List[LineSequence], float, float, float, bool], None)]=None) -> List[LineSequence]:

    def search_trace(state: _STATE, temp: float, cost: float, probability: float, accepted: bool):
        if trace_func:
            (trace_seqs, _) = state
            trace_func(trace_seqs, temp, cost, probability, accepted)
    (seqs, _) = optimization.anneal_minimize(self._create_initial_solution(), self._quadratic_sum_cost, self._force_edges_active_move, self._rand.random_sample, trace_func=search_trace)
    return seqs

Issues new linear sequence search.

Each call to this method starts new search.

Args:
trace_func: Optional callable which will be called for each simulated
annealing step with arguments: solution candidate (list of linear
sequences on the chip), current temperature (float), candidate cost
(float), probability of accepting candidate (float), and acceptance
decision (boolean).

Returns:
List of linear sequences on the chip found by this method.


def CheckCompletedBlocks(self, filename, error):
    for obj in self.stack:
        if isinstance(obj, _ClassInfo):
            error(filename, obj.starting_linenum, 'build/class', 5, ('Failed to find complete declaration of class %s' % obj.name))
        elif isinstance(obj, _NamespaceInfo):
            error(filename, obj.starting_linenum, 'build/namespaces', 5, ('Failed to find complete declaration of namespace %s' % obj.name))

Checks that all classes and namespaces have been completely parsed.

Call this when all lines in a file have been processed.
Args:
filename: The name of the current file.
error: The function to call with any errors found.


def add_subassistants_to(cls, parser, assistant_tuple, level, alias=None):

        name = alias or assistant_tuple[0].name
        p = parser.add_parser(name,
                              description=assistant_tuple[0].description,
                              argument_default=argparse.SUPPRESS)
        for arg in assistant_tuple[0].args:
            arg.add_argument_to(p)

        if len(assistant_tuple[1]) > 0:
            subparsers = cls._add_subparsers_required(p,
                dest=settings.SUBASSISTANT_N_STRING.format(level),
                title=cls.subparsers_str,
                description=cls.subparsers_desc)
            for subas_tuple in sorted(assistant_tuple[1], key=lambda x: x[0].name):
                cls.add_subassistants_to(subparsers, subas_tuple, level + 1)
        elif level == 1:
            subparsers = cls._add_subparsers_required(p,
                dest=settings.SUBASSISTANT_N_STRING.format(level),
                title=cls.subparsers_str,
                description=devassistant_argparse.ArgumentParser.no_assistants_msg)

Adds assistant from given part of assistant tree and all its subassistants to
a given argument parser.

Args:
parser: instance of devassistant_argparse.ArgumentParser
assistant_tuple: part of assistant tree (see generate_argument_parser doc)
level: level of subassistants that given assistant is at


def nac_v(msg):
    tc = typecode(msg)
    if (tc != 19):
        raise RuntimeError(('%s: Not an airborne velocity message, expecting TC = 19' % msg))
    msgbin = common.hex2bin(msg)
    NACv = common.bin2int(msgbin[42:45])
    try:
        HFOMr = uncertainty.NACv[NACv]['HFOMr']
        VFOMr = uncertainty.NACv[NACv]['VFOMr']
    except KeyError:
        (HFOMr, VFOMr) = (uncertainty.NA, uncertainty.NA)
    return (HFOMr, VFOMr)

Calculate NACv, Navigation Accuracy Category - Velocity

Args:
msg (string): 28 bytes hexadecimal message string, TC = 19

Returns:
int or string: 95% horizontal accuracy bounds for velocity, Horizontal Figure of Merit
int or string: 95% vertical accuracy bounds for velocity, Vertical Figure of Merit


def metta_config(quarter, num_dimensions):
    (first_day, last_day) = quarter_boundaries(quarter)
    return {'start_time': first_day, 'end_time': last_day, 'prediction_window': 3, 'label_name': 'onet_soc_code', 'label_type': 'categorical', 'matrix_id': 'job_postings_{}'.format(quarter), 'feature_names': ['doc2vec_{}'.format(i) for i in range(num_dimensions)]}

Returns metta metadata for a quarter's SOC code classifier matrix

Args:
quarter (str) quarter, in format '2015Q1'
num_dimensions (int) Number of features in matrix

Returns: (dict) metadata suitable for metta.archive_train_test


def find_library_windows(cls):
    dll = (cls.get_appropriate_windows_sdk_name() + '.dll')
    root = 'C:\\'
    for d in os.listdir(root):
        dir_path = os.path.join(root, d)
        if (d.startswith('Program Files') and os.path.isdir(dir_path)):
            dir_path = os.path.join(dir_path, 'SEGGER')
            if (not os.path.isdir(dir_path)):
                continue
            ds = filter((lambda x: x.startswith('JLink')), os.listdir(dir_path))
            for jlink_dir in ds:
                lib_path = os.path.join(dir_path, jlink_dir, dll)
                if os.path.isfile(lib_path):
                    (yield lib_path)

Loads the SEGGER DLL from the windows installation directory.

On Windows, these are found either under:
- ``C:\\Program Files\\SEGGER\\JLink``
- ``C:\\Program Files (x86)\\SEGGER\\JLink``.

Args:
cls (Library): the ``Library`` class

Returns:
The paths to the J-Link library files in the order that they are
found.


def values(self, column_major=False):
    if column_major:
        return list(map(list, zip(*self._values)))
    return [row[:] for row in self._values]

Return a nested list with the worksheet values.

Args:
column_major (bool): as list of columns (default list of rows)
Returns:
list: list of lists with values


def _notify_mutated(self, obj, old, hint=None):
    value = self.__get__(obj, obj.__class__)
    value = self.property.prepare_value(obj, self.name, value)
    self._real_set(obj, old, value, hint=hint)

A method to call when a container is mutated "behind our back"
and we detect it with our |PropertyContainer| wrappers.

Args:
obj (HasProps) :
The object who's container value was mutated

old (object) :
The "old" value of the container

In this case, somewhat weirdly, ``old`` is a copy and the
new value should already be set unless we change it due to
validation.

hint (event hint or None, optional)
An optional update event hint, e.g. ``ColumnStreamedEvent``
(default: None)

Update event hints are usually used at times when better
update performance can be obtained by special-casing in
some way (e.g. streaming or patching column data sources)

Returns:
None


def _sym_missing(self) -> Dict[str, Any]:
    missing = dict()
    for k, v in self._sym_attributes.items():
        if pg_typing.MISSING_VALUE != v and isinstance(v, base.Symbolic):
            missing_child = v.sym_missing(flatten=False)
            if missing_child:
                missing[k] = missing_child
    return missing

Returns missing values for Functor.

Semantically unbound arguments are not missing, thus we only return partial
bound arguments in `sym_missing`. As a result, a functor is partial only
when any of its bound arguments is partial.

Returns:
A dict of missing key (or path) to missing value.


def code_string_to_enum_value_descriptor(code_string: str, enum_descriptor: descriptor.EnumDescriptor) -> descriptor.EnumValueDescriptor:
    value_descriptor = _get_enum_value_descriptor_memo(enum_descriptor, code_string)
    if value_descriptor is not None:
        return value_descriptor
    fhir_case_code_string = code_string.upper().replace('-', '_')
    value_descriptor = enum_descriptor.values_by_name.get(fhir_case_code_string)
    if value_descriptor is not None:
        _set_enum_value_descriptor_memo(enum_descriptor, code_string, value_descriptor)
        return value_descriptor
    for value_descriptor in enum_descriptor.values:
        if value_descriptor.GetOptions().HasExtension(annotations_pb2.fhir_original_code) and value_descriptor.GetOptions().Extensions[annotations_pb2.fhir_original_code] == code_string:
            _set_enum_value_descriptor_memo(enum_descriptor, code_string, value_descriptor)
            return value_descriptor
    raise fhir_errors.InvalidFhirError(f'Failed to convert {code_string!r} to {enum_descriptor.full_name}. No matching enum found.')

Returns an EnumValueDescriptor for a provided EnumDescriptor and raw code.

Args:
code_string: A raw string representation of the code to retrieve.
enum_descriptor: The EnumDescriptor the desired EnumValueDescriptor belongs
to.

Returns:
An instance of EnumValueDescriptor that the code_string represents.

Raises:
fhir_errors.InvalidFhirError: In the event that a conversion from
code_string was unsuccessful.


def _prep_noise_interpolants(self):
    noise_lists = {}
    self.noise_interpolants = {}
    if isinstance(self.sensitivity_curves, str):
        self.sensitivity_curves = [self.sensitivity_curves]
    if isinstance(self.noise_type_in, list):
        if (len(self.noise_type_in) != len(self.sensitivity_curves)):
            raise ValueError((('noise_type_in must have same shape as sensitivity_curves if it is' + 'provided as a list.') + 'If all curves are of the same type, provide a string.'))
    else:
        assert isinstance(self.noise_type_in, str)
        self.noise_type_in = [self.noise_type_in for _ in self.sensitivity_curves]
    if isinstance(self.signal_type, str):
        self.signal_type = [self.signal_type]
    for (num, sc) in enumerate(self.sensitivity_curves):
        if isinstance(sc, str):
            (f, h_n) = read_noise_curve(sc, noise_type_in=self.noise_type_in[num], noise_type_out='char_strain')
            if (sc[(- 4):] == '.txt'):
                key = sc.split('.')[0].split('/')[(- 1)]
            else:
                key = sc
        elif isinstance(sc, list):
            (f, h_n) = sc
            key = str(num)
        else:
            raise ValueError(('Sensitivity curves must either be string' + 'or list containing f_n and asd_n.'))
        noise_lists[key] = [f, h_n]
    if (str(self.add_wd_noise).lower() in ['true', 'both', 'yes']):
        if isinstance(self.wd_noise, str):
            (f_n_wd, h_n_wd) = read_noise_curve(self.wd_noise, noise_type_in=self.wd_noise_type_in, noise_type_out='char_strain')
        elif isinstance(self, wd_noise, list):
            (f_n_wd, h_n_wd) = self.wd_noise
        trans_dict = {}
        for sc in noise_lists.keys():
            (f_n, h_n) = noise_lists[sc]
            if (self.add_wd_noise.lower() == 'both'):
                trans_dict[sc] = [f_n, h_n]
            (f_n, h_n) = combine_with_wd_noise(f_n, h_n, f_n_wd, h_n_wd)
            trans_dict[(sc + '_wd')] = [f_n, h_n]
        noise_lists = trans_dict
    for sc in noise_lists:
        (f_n, h_n) = noise_lists[sc]
        self.noise_interpolants[sc] = interpolate.interp1d(f_n, h_n, bounds_error=False, fill_value=1e+30)
    return

Construct interpolated sensitivity curves

This will construct the interpolated sensitivity curves
using scipy.interpolate.interp1d. It will add wd noise
if that is requested.

Raises:
ValueError: ``len(noise_type_in) != len(sensitivity_curves)``
ValueError: Issue with sensitivity curve type provided.


def print_source(self, args, screen_info=None):
    del screen_info
    parsed = self._arg_parsers['print_source'].parse_args(args)
    device_name_regex = re.compile(parsed.device_name_filter) if parsed.device_name_filter else None
    profile_data = []
    data_generator = self._get_profile_data_generator()
    device_count = len(self._run_metadata.step_stats.dev_stats)
    for index in range(device_count):
        device_stats = self._run_metadata.step_stats.dev_stats[index]
        if device_name_regex and (not device_name_regex.match(device_stats.device)):
            continue
        profile_data.extend(data_generator(device_stats))
    source_annotation = source_utils.annotate_source_against_profile(profile_data, os.path.expanduser(parsed.source_file_path), node_name_filter=parsed.node_name_filter, op_type_filter=parsed.op_type_filter)
    if not source_annotation:
        return debugger_cli_common.RichTextLines(['The source file %s does not contain any profile information for the previous Session run under the following filters:' % parsed.source_file_path, '  --%s: %s' % (_DEVICE_NAME_FILTER_FLAG, parsed.device_name_filter), '  --%s: %s' % (_NODE_NAME_FILTER_FLAG, parsed.node_name_filter), '  --%s: %s' % (_OP_TYPE_FILTER_FLAG, parsed.op_type_filter)])
    max_total_cost = 0
    for line_index in source_annotation:
        total_cost = self._get_total_cost(source_annotation[line_index], parsed.cost_type)
        max_total_cost = max(max_total_cost, total_cost)
    source_lines, line_num_width = source_utils.load_source(parsed.source_file_path)
    cost_bar_max_length = 10
    total_cost_head = parsed.cost_type
    column_widths = {'cost_bar': cost_bar_max_length + 3, 'total_cost': len(total_cost_head) + 3, 'num_nodes_execs': len(self._NUM_EXECS_SUB_HEAD) + 1, 'line_number': line_num_width}
    head = RL(' ' * column_widths['cost_bar'] + total_cost_head + ' ' * (column_widths['total_cost'] - len(total_cost_head)) + self._NUM_NODES_HEAD + ' ' * (column_widths['num_nodes_execs'] - len(self._NUM_NODES_HEAD)), font_attr=self._LINE_COST_ATTR)
    head += RL(self._LINENO_HEAD, font_attr=self._LINE_NUM_ATTR)
    sub_head = RL(' ' * (column_widths['cost_bar'] + column_widths['total_cost']) + self._NUM_EXECS_SUB_HEAD + ' ' * (column_widths['num_nodes_execs'] - len(self._NUM_EXECS_SUB_HEAD)) + ' ' * column_widths['line_number'], font_attr=self._LINE_COST_ATTR)
    sub_head += RL(self._SOURCE_HEAD, font_attr='bold')
    lines = [head, sub_head]
    output_annotations = {}
    for i, line in enumerate(source_lines):
        lineno = i + 1
        if lineno in source_annotation:
            annotation = source_annotation[lineno]
            cost_bar = self._render_normalized_cost_bar(self._get_total_cost(annotation, parsed.cost_type), max_total_cost, cost_bar_max_length)
            annotated_line = cost_bar
            annotated_line += ' ' * (column_widths['cost_bar'] - len(cost_bar))
            total_cost = RL(cli_shared.time_to_readable_str(self._get_total_cost(annotation, parsed.cost_type), force_time_unit=parsed.time_unit), font_attr=self._LINE_COST_ATTR)
            total_cost += ' ' * (column_widths['total_cost'] - len(total_cost))
            annotated_line += total_cost
            file_path_filter = re.escape(parsed.source_file_path) + '$'
            command = 'lp --file_path_filter %s --min_lineno %d --max_lineno %d' % (file_path_filter, lineno, lineno + 1)
            if parsed.device_name_filter:
                command += ' --%s %s' % (_DEVICE_NAME_FILTER_FLAG, parsed.device_name_filter)
            if parsed.node_name_filter:
                command += ' --%s %s' % (_NODE_NAME_FILTER_FLAG, parsed.node_name_filter)
            if parsed.op_type_filter:
                command += ' --%s %s' % (_OP_TYPE_FILTER_FLAG, parsed.op_type_filter)
            menu_item = debugger_cli_common.MenuItem(None, command)
            num_nodes_execs = RL('%d(%d)' % (annotation.node_count, annotation.node_exec_count), font_attr=[self._LINE_COST_ATTR, menu_item])
            num_nodes_execs += ' ' * (column_widths['num_nodes_execs'] - len(num_nodes_execs))
            annotated_line += num_nodes_execs
        else:
            annotated_line = RL(' ' * sum((column_widths[col_name] for col_name in column_widths if col_name != 'line_number')))
        line_num_column = RL(' L%d' % lineno, self._LINE_NUM_ATTR)
        line_num_column += ' ' * (column_widths['line_number'] - len(line_num_column))
        annotated_line += line_num_column
        annotated_line += line
        lines.append(annotated_line)
        if parsed.init_line == lineno:
            output_annotations[debugger_cli_common.INIT_SCROLL_POS_KEY] = len(lines) - 1
    return debugger_cli_common.rich_text_lines_from_rich_line_list(lines, annotations=output_annotations)

Print a Python source file with line-level profile information.

Args:
args: Command-line arguments, excluding the command prefix, as a list of
str.
screen_info: Optional dict input containing screen information such as
cols.

Returns:
Output text lines as a RichTextLines object.


def is_active(self, node):

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

Checks whether a statement is active.

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

Args:
node: an instance of gast.Assign

Returns:
Whether the statement is active.


def __init__(self, channel):

    self.ListContexts = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.Contexts/ListContexts',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.ListContextsRequest.SerializeToString,
        response_deserializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.ListContextsResponse.FromString,
        )
    self.GetContext = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.Contexts/GetContext',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.GetContextRequest.SerializeToString,
        response_deserializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.Context.FromString,
        )
    self.CreateContext = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.Contexts/CreateContext',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.CreateContextRequest.SerializeToString,
        response_deserializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.Context.FromString,
        )
    self.UpdateContext = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.Contexts/UpdateContext',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.UpdateContextRequest.SerializeToString,
        response_deserializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.Context.FromString,
        )
    self.DeleteContext = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.Contexts/DeleteContext',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.DeleteContextRequest.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
    self.DeleteAllContexts = channel.unary_unary(
        '/google.cloud.dialogflow.v2beta1.Contexts/DeleteAllContexts',
        request_serializer=google_dot_cloud_dot_dialogflow__v2beta1_dot_proto_dot_context__pb2.DeleteAllContextsRequest.SerializeToString,
        response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def ReadSerializableArray(self, class_name, max=sys.maxsize):

        module = '.'.join(class_name.split('.')[:-1])
        klassname = class_name.split('.')[-1]
        klass = getattr(importlib.import_module(module), klassname)
        length = self.ReadVarInt(max=max)
        items = []

        try:
            for i in range(0, length):
                item = klass()
                item.Deserialize(self)

                items.append(item)
        except Exception as e:
            logger.error("Couldn't deserialize %s " % e)

        return items

Deserialize a stream into the object specific by `class_name`.

Args:
class_name (str): a full path to the class to be deserialized into. e.g. 'neo.Core.Block.Block'
max (int): (Optional) maximum number of bytes to read.

Returns:
list: list of `class_name` objects deserialized from the stream.


def DetermineType(value):

  object_type = type(value)
  if not hasattr(object_type, '__name__'):
    return None

  type_string = getattr(object_type, '__module__', '')
  if type_string:
    type_string += '.'

  type_string += object_type.__name__
  return type_string

Determines the type of val, returning a "full path" string.

For example:
DetermineType(5) -> __builtin__.int
DetermineType(Foo()) -> com.google.bar.Foo

Args:
value: Any value, the value is irrelevant as only the type metadata
is checked

Returns:
Type path string.  None if type cannot be determined.


def SetServerInformation(self, server, port):

    self._host = server
    self._port = port
    logger.debug('Elasticsearch server: {0!s} port: {1:d}'.format(
        server, port))

Set the server information.

Args:
server (str): IP address or hostname of the server.
port (int): Port number of the server.


def google_maps_geoloc_link(data):

    if isinstance(data, str):
        lat_lon = ip_geoloc(data)
        if lat_lon is None:
            return ''
        lat, lon = lat_lon
    else:
        lat, lon = data
    loc = '%s,%s' % (lat, lon)
    return 'https:
           'data=!3m1!4b1!4m5!3m4!1s0x0:0x0!8m2!3d%s!4d%s' % (
            loc, lat, lon)

Get a link to google maps pointing on this IP's geolocation.

Args:
data (str/tuple): IP address or (latitude, longitude).

Returns:
str: a link to google maps pointing on this IP's geolocation.


def limit(self, count):
    query = query_mod.Query(self)
    return query.limit(count)

Create a limited query with this collection as parent.

See
:meth:`~.firestore_v1beta1.query.Query.limit` for
more information on this method.

Args:
count (int): Maximum number of documents to return that match
the query.

Returns:
~.firestore_v1beta1.query.Query: A limited query.


def upload(self, resource_id, data):
    self.body = data
    self.content_type = 'application/octet-stream'
    self.resource_id(str(resource_id))
    self._request_uri = '{}/upload'.format(self._request_uri)

Update the request URI to upload the a document to this resource.

Args:
resource_id (integer): The group id.
data (any): The raw data to upload.


def get_dataset(self, dsid, dsinfo):
    data = self[dsinfo.get('file_key', dsid.name)]
    data.attrs.update(dsinfo)
    data.attrs['platform_name'] = self['/attr/satellite_name']
    data.attrs['sensor'] = self['/attr/instrument_name']
    return data

Get dataset function

Args:
dsid: Dataset ID
param2: Dataset Information

Returns:
Dask DataArray: Data


def from_base_10_int(decimal, output_base=10):

    if decimal <= 0:
        return (0,)
    if output_base == 1:
        return (1,) * decimal
    length = digits(decimal, output_base)
    converted = tuple(digit(decimal, i, output_base) for i in range(length))
    return converted[::-1]

Converts a decimal integer to a specific base.

Args:
decimal(int) A base 10 number.
output_base(int) base to convert to.

Returns:
A tuple of digits in the specified base.

Examples:
>>> from_base_10_int(255)
(2, 5, 5)
>>> from_base_10_int(255, 16)
(15, 15)
>>> from_base_10_int(9988664439, 8)
(1, 1, 2, 3, 2, 7, 5, 6, 6, 1, 6, 7)
>>> from_base_10_int(0, 17)
(0,)


def get_ogr_driver(filepath):
    (filename, file_extension) = os.path.splitext(filepath)
    EXTENSION = file_extension[1:]
    ogr_driver_count = ogr.GetDriverCount()
    for idx in range(ogr_driver_count):
        driver = ogr.GetDriver(idx)
        driver_extension = (driver.GetMetadataItem(str('DMD_EXTENSION')) or '')
        driver_extensions = (driver.GetMetadataItem(str('DMD_EXTENSIONS')) or '')
        if ((EXTENSION == driver_extension) or (EXTENSION in driver_extensions)):
            return driver
    else:
        msg = 'No driver found for the following file extension: {}'.format(EXTENSION)
        raise ValueError(msg)

Get the OGR driver from the provided file extension.

Args:
file_extension (str): file extension

Returns:
osgeo.ogr.Driver

Raises:
ValueError: no driver is found


def generate_exact(self, model, vcpu_num, host_cpu):
    nested = {'Intel': 'vmx', 'AMD': 'svm'}
    cpu = ET.Element('cpu', match='exact')
    ET.SubElement(cpu, 'model').text = model
    cpu.append(self.generate_topology(vcpu_num))
    vendor = host_cpu.findtext('vendor')
    if (not nested.get(vendor)):
        LOGGER.debug('Unknown vendor: {0}, did not configure nested virtualization cpu flag on guest.'.format(vendor))
        return cpu
    model_vendor = LibvirtCPU.get_cpu_vendor(family=model)
    if (vendor != model_vendor):
        LOGGER.debug('Not enabling nested virtualization feature, host vendor is: {0}, guest vendor: {1}'.format(vendor, model_vendor))
        return cpu
    flag = nested[vendor]
    if (host_cpu.find('feature/[@name="{0}"]'.format(flag)) is not None):
        cpu.append(self.generate_feature(name=flag))
    else:
        LOGGER.debug('missing {0} cpu flag on host, nested virtualization will probably not work.'.format(flag))
    return cpu

Generate exact CPU model with nested virtualization CPU feature.

Args:
model(str): libvirt supported CPU model
vcpu_num(int): number of virtual cpus
host_cpu(lxml.etree.Element): the host CPU model

Returns:
lxml.etree.Element: CPU XML node


def guess_task_type(name, task_defn):
    parts = name.split(':')
    task_type = parts[(- 1)]
    if (task_type == 'parent'):
        if is_action(task_defn):
            task_type = 'action'
        else:
            task_type = 'decision'
    if (task_type not in get_valid_task_types()):
        raise CoTError('Invalid task type for {}!'.format(name))
    return task_type

Guess the task type of the task.

Args:
name (str): the name of the task.

Returns:
str: the task_type.

Raises:
CoTError: on invalid task_type.


def internal_convert_n_to_tensor_or_indexed_slices(values, dtype=None, name=None, as_ref=False):
    if not isinstance(values, collections_abc.Iterable):
        raise TypeError('Argument `values` must be iterable.')
    ret = []
    for i, value in enumerate(values):
        if value is None:
            ret.append(value)
        else:
            n = None if name is None else '%s_%d' % (name, i)
            ret.append(internal_convert_to_tensor_or_indexed_slices(value, dtype=dtype, name=n, as_ref=as_ref))
    return ret

Converts `values` to a list of `Tensor` or `IndexedSlices` objects.

Any `IndexedSlices` or `SparseTensor` objects in `values` are returned
unmodified.

Args:
values: An iterable of `None`, `IndexedSlices`, `SparseTensor`, or objects
that can be consumed by `convert_to_tensor()`.
dtype: (Optional.) The required `DType` of the returned `Tensor` or
`IndexedSlices`.
name: (Optional.) A name prefix to used when a new `Tensor` is created, in
which case element `i` will be given the name `name + '_' + i`.
as_ref: True if the caller wants the results as ref tensors.

Returns:
A list of `Tensor`, `IndexedSlices`, `SparseTensor` and/or `None` objects.

Raises:
TypeError: If no conversion function is registered for an element in
`values`.
RuntimeError: If a registered conversion function returns an invalid
value.


def _decorate_block(self, start, end):

        color = self._get_scope_highlight_color()
        draw_order = DRAW_ORDERS.get('codefolding')
        d = TextDecoration(self.editor.document(), start_line=start,
                           end_line=end+1, draw_order=draw_order)
        d.set_background(color)
        d.set_full_width(True, clear=False)
        self.editor.decorations.add(d)
        self._scope_decos.append(d)

Create a decoration and add it to the editor.

Args:
start (int) start line of the decoration
end (int) end line of the decoration


def prepare_for_send(self, full_url=False):
    assert self.url
    assert self.method
    assert self.version
    url_info = self.url_info
    if ('Host' not in self.fields):
        self.fields['Host'] = url_info.hostname_with_port
    if (not full_url):
        if url_info.query:
            self.resource_path = '{0}?{1}'.format(url_info.path, url_info.query)
        else:
            self.resource_path = url_info.path
    else:
        self.resource_path = url_info.url

Modify the request to be suitable for HTTP server.

Args:
full_url (bool): Use full URL as the URI. By default, only
the path of the URL is given to the server.


def add_arguments(cls, parser):

        parser.add_argument(
            '-t', '--title',
            action='store',
            nargs='?',
            const='',
            dest='title',
            help="[issue] task/issue title.",
            )

        parser.add_argument(
            '-b', '--body',
            action='store',
            nargs='?',
            const='',
            dest='body',
            help="[issue] task/issue body.",
            )

        pass

Add arguments to the parser for collection in app.args.

Args:
parser:
`argparse.ArgumentParser`. Parser.
Arguments added here are server on
self.args.


def populate_ast_nsarg_orthologs(ast, species):
    ortholog_namespace = 'EG'
    if isinstance(ast, NSArg):
        if re.match(ortholog_namespace, ast.canonical):
            orthologs = bel.terms.orthologs.get_orthologs(ast.canonical, list(species.keys()))
            for species_id in species:
                if (species_id in orthologs):
                    orthologs[species_id]['species_label'] = species[species_id]
            ast.orthologs = copy.deepcopy(orthologs)
    if hasattr(ast, 'args'):
        for arg in ast.args:
            populate_ast_nsarg_orthologs(arg, species)
    return ast

Recursively collect NSArg orthologs for BEL AST

This requires bo.collect_nsarg_norms() to be run first so NSArg.canonical is available

Args:
ast: AST at recursive point in belobj
species: dictionary of species ids vs labels for or


def draw_sunpath(self, hoys=None, origin=None, scale=1, sun_scale=1, annual=True, rem_night=True):
    assert ladybug.isplus, '"draw_sunpath" method can only be used in the [+] libraries.'
    hoys = (hoys or ())
    origin = (origin or (0, 0, 0))
    try:
        origin = tuple(origin)
    except TypeError as e:
        try:
            origin = (origin.X, origin.Y, origin.Z)
        except AttributeError:
            raise TypeError(str(e))
    scale = (scale or 1)
    sun_scale = (sun_scale or 1)
    assert (annual or hoys), 'For daily sunpath you need to provide at least one hour.'
    radius = (200 * scale)
    base_curves = plus.base_curves(origin, radius, self.north_angle)
    if annual:
        asuns = self._analemma_suns()
        analemma_curves = plus.analemma_curves(asuns, origin, radius)
    else:
        analemma_curves = ()
    if hoys:
        suns = tuple((self.calculate_sun_from_hoy(hour) for hour in hoys))
    else:
        suns = ()
    if rem_night:
        suns = tuple((sun for sun in suns if sun.is_during_day))
    sun_geos = plus.sun_geometry(suns, origin, radius)
    if annual:
        dts = (DateTime(m, 21) for m in xrange(1, 13))
    else:
        dts = (sun.datetime for sun in suns)
    dsuns = self._daily_suns(dts)
    daily_curves = plus.daily_curves(dsuns, origin, radius)
    SPGeo = namedtuple('SunpathGeo', ('compass_curves', 'analemma_curves', 'daily_curves', 'suns', 'sun_geos'))
    return SPGeo(base_curves, analemma_curves, daily_curves, suns, sun_geos)

Create sunpath geometry. \
This method should only be used from the + libraries.

Args:
hoys: An optional list of hours of the year(default: None).
origin: Sunpath origin(default: (0, 0, 0)).
scale: Sunpath scale(default: 1).
sun_scale: Scale for the sun spheres(default: 1).
annual: Set to True to draw an annual sunpath.
Otherwise a daily sunpath is drawn.
rem_night: Remove suns which are under the horizon(night!).
Returns:
base_curves: A collection of curves for base plot.
analemma_curves: A collection of analemma_curves.
daily_curves: A collection of daily_curves.
suns: A list of suns.


def offTagAdd(self, name, func):

        if '*' in name:
            self.ontagaddglobs.rem(name, func)
            return

        cblist = self.ontagadds.get(name)
        if cblist is None:
            return
        try:
            cblist.remove(func)
        except ValueError:
            pass

Unregister a callback for tag addition.

Args:
name (str): The name of the tag or tag glob.
func (function): The callback func(node, tagname, tagval).


def orthorhombic(a: float, b: float, c: float):

        return Lattice.from_parameters(a, b, c, 90, 90, 90)

Convenience constructor for an orthorhombic lattice.

Args:
a (float): *a* lattice parameter of the orthorhombic cell.
b (float): *b* lattice parameter of the orthorhombic cell.
c (float): *c* lattice parameter of the orthorhombic cell.

Returns:
Orthorhombic lattice of dimensions a x b x c.


def apply_filter(self, structure_filter):

    def test_transformed_structure(ts):
        return structure_filter.test(ts.final_structure)
    self.transformed_structures = list(filter(test_transformed_structure, self.transformed_structures))
    for ts in self.transformed_structures:
        ts.append_filter(structure_filter)

Applies a structure_filter to the list of TransformedStructures
in the transmuter.

Args:
structure_filter: StructureFilter to apply.


def UnwrapPyTree(tree):
    unwrapper = PyTreeUnwrapper()
    unwrapper.Visit(tree)
    llines = unwrapper.GetLogicalLines()
    llines.sort(key=lambda x: x.lineno)
    return llines

Create and return a list of logical lines from the given pytree.

Arguments:
tree: the top-level pytree node to unwrap..

Returns:
A list of LogicalLine objects.


def as_operation(self, timer=datetime.utcnow):
    now = timer()
    op = sc_messages.Operation(endTime=timestamp.to_rfc3339(now), startTime=timestamp.to_rfc3339(now), importance=sc_messages.Operation.ImportanceValueValuesEnum.LOW)
    if self.operation_id:
        op.operationId = self.operation_id
    if self.operation_name:
        op.operationName = self.operation_name
    if (self.api_key and self.api_key_valid):
        op.consumerId = (u'api_key:' + self.api_key)
    elif self.consumer_project_id:
        op.consumerId = (u'project:' + self.consumer_project_id)
    return op

Makes an ``Operation`` from this instance.

Returns:
an ``Operation``


def generate_rpn_proposals(boxes, scores, img_shape,
                           pre_nms_topk, post_nms_topk=None):

    assert boxes.shape.ndims == 2, boxes.shape
    if post_nms_topk is None:
        post_nms_topk = pre_nms_topk

    topk = tf.minimum(pre_nms_topk, tf.size(scores))
    topk_scores, topk_indices = tf.nn.top_k(scores, k=topk, sorted=False)
    topk_boxes = tf.gather(boxes, topk_indices)
    topk_boxes = clip_boxes(topk_boxes, img_shape)

    topk_boxes_x1y1x2y2 = tf.reshape(topk_boxes, (-1, 2, 2))
    topk_boxes_x1y1, topk_boxes_x2y2 = tf.split(topk_boxes_x1y1x2y2, 2, axis=1)

    wbhb = tf.squeeze(topk_boxes_x2y2 - topk_boxes_x1y1, axis=1)
    valid = tf.reduce_all(wbhb > cfg.RPN.MIN_SIZE, axis=1)
    topk_valid_boxes_x1y1x2y2 = tf.boolean_mask(topk_boxes_x1y1x2y2, valid)
    topk_valid_scores = tf.boolean_mask(topk_scores, valid)

    topk_valid_boxes_y1x1y2x2 = tf.reshape(
        tf.reverse(topk_valid_boxes_x1y1x2y2, axis=[2]),
        (-1, 4), name='nms_input_boxes')
    nms_indices = tf.image.non_max_suppression(
        topk_valid_boxes_y1x1y2x2,
        topk_valid_scores,
        max_output_size=post_nms_topk,
        iou_threshold=cfg.RPN.PROPOSAL_NMS_THRESH)

    topk_valid_boxes = tf.reshape(topk_valid_boxes_x1y1x2y2, (-1, 4))
    proposal_boxes = tf.gather(topk_valid_boxes, nms_indices)
    proposal_scores = tf.gather(topk_valid_scores, nms_indices)
    tf.sigmoid(proposal_scores, name='probs')
    return tf.stop_gradient(proposal_boxes, name='boxes'), tf.stop_gradient(proposal_scores, name='scores')

Sample RPN proposals by the following steps:
1. Pick top k1 by scores
2. NMS them
3. Pick top k2 by scores. Default k2 == k1, i.e. does not filter the NMS output.

Args:
boxes: nx4 float dtype, the proposal boxes. Decoded to floatbox already
scores: n float, the logits
img_shape: [h, w]
pre_nms_topk, post_nms_topk (int): See above.

Returns:
boxes: kx4 float
scores: k logits


def masked_within_block_local_attention_1d(q, k, v, block_length=64, name=None):
    with tf.variable_scope(name, default_name='within_local_attention_1d', values=[q, k, v]):
        (batch, heads, length, depth_k) = common_layers.shape_list(q)
        depth_v = common_layers.shape_list(v)[(- 1)]
        if isinstance(block_length, tf.Tensor):
            const = tf.contrib.util.constant_value(block_length)
            if (const is not None):
                block_length = int(const)
        original_length = length
        padding_size = tf.mod((- length), block_length)
        length += padding_size
        padding = [[0, 0], [0, 0], [0, padding_size], [0, 0]]
        q = tf.pad(q, padding)
        k = tf.pad(k, padding)
        v = tf.pad(v, padding)
        num_blocks = tf.div(length, block_length)
        q = tf.reshape(q, [batch, heads, num_blocks, block_length, depth_k])
        k = tf.reshape(k, [batch, heads, num_blocks, block_length, depth_k])
        v = tf.reshape(v, [batch, heads, num_blocks, block_length, depth_v])
        attention = tf.matmul(q, k, transpose_b=True)
        attention += tf.reshape(attention_bias_lower_triangle(block_length), [1, 1, 1, block_length, block_length])
        attention = tf.nn.softmax(attention)
        output = tf.matmul(attention, v)
        output = tf.reshape(output, [batch, heads, (- 1), depth_v])
        output = tf.slice(output, [0, 0, 0, 0], [(- 1), (- 1), original_length, (- 1)])
        output.set_shape([(None if isinstance(dim, tf.Tensor) else dim) for dim in (batch, heads, length, depth_v)])
        return output

Attention to the source and a neighborhood to the left within a block.

The sequence is divided into blocks of length block_length. Attention for a
given query position can only see memory positions less than or equal to the
query position in the corresponding block.

Args:
q: a Tensor with shape [batch, heads, length, depth_k]
k: a Tensor with shape [batch, heads, length, depth_k]
v: a Tensor with shape [batch, heads, length, depth_v]
block_length: an integer
name: an optional string

Returns:
a Tensor of shape [batch, heads, length, depth_v]


def bdp_bds_cache(func, tickers, flds, **kwargs) -> ToQuery:

    cache_data = []
    log_level = kwargs.get('log', logs.LOG_LEVEL)
    logger = logs.get_logger(bdp_bds_cache, level=log_level)
    kwargs['has_date'] = kwargs.pop('has_date', func == 'bds')
    kwargs['cache'] = kwargs.get('cache', True)

    tickers = utils.flatten(tickers)
    flds = utils.flatten(flds)
    loaded = pd.DataFrame(data=0, index=tickers, columns=flds)

    for ticker, fld in product(tickers, flds):
        data_file = storage.ref_file(
            ticker=ticker, fld=fld, ext='pkl', **{
                k: v for k, v in kwargs.items() if k not in EXC_COLS
            }
        )
        if not files.exists(data_file): continue
        logger.debug(f'reading from {data_file} ...')
        cache_data.append(pd.read_pickle(data_file))
        loaded.loc[ticker, fld] = 1

    to_qry = loaded.where(loaded == 0)\
        .dropna(how='all', axis=1).dropna(how='all', axis=0)

    return ToQuery(
        tickers=to_qry.index.tolist(), flds=to_qry.columns.tolist(),
        cached_data=cache_data
    )

Find cached `BDP` / `BDS` queries

Args:
func: function name - bdp or bds
tickers: tickers
flds: fields
**kwargs: other kwargs

Returns:
ToQuery(ticker, flds, kwargs)


def convert(self, value):
    if (self._type is str):
        return str(value)
    elif (self._type is int):
        try:
            return int(value)
        except (UnicodeError, ValueError):
            raise WorkflowArgumentError('Cannot convert {} to int'.format(value))
    elif (self._type is float):
        try:
            return float(value)
        except (UnicodeError, ValueError):
            raise WorkflowArgumentError('Cannot convert {} to float'.format(value))
    elif (self._type is bool):
        if isinstance(value, bool):
            return bool(value)
        value = value.lower()
        if (value in ('true', '1', 'yes', 'y')):
            return True
        elif (value in ('false', '0', 'no', 'n')):
            return False
        raise WorkflowArgumentError('Cannot convert {} to bool'.format(value))
    else:
        return value

Convert the specified value to the type of the option.

Args:
value: The value that should be converted.

Returns:
The value with the type given by the option.


def to_FIB(self, other):
    if (not isinstance(other, GroundedFunctionNetwork)):
        raise TypeError(f'Expected GroundedFunctionNetwork, but got {type(other)}')

    def shortname(var):
        return var[(var.find('::') + 2):var.rfind('_')]

    def shortname_vars(graph, shortname):
        return [v for v in graph.nodes() if (shortname in v)]
    this_var_nodes = [shortname(n) for (n, d) in self.nodes(data=True) if (d['type'] == 'variable')]
    other_var_nodes = [shortname(n) for (n, d) in other.nodes(data=True) if (d['type'] == 'variable')]
    shared_vars = set(this_var_nodes).intersection(set(other_var_nodes))
    full_shared_vars = {full_var for shared_var in shared_vars for full_var in shortname_vars(self, shared_var)}
    return ForwardInfluenceBlanket(self, full_shared_vars)

Creates a ForwardInfluenceBlanket object representing the
intersection of this model with the other input model.

Args:
other: The GroundedFunctionNetwork object to compare this model to.

Returns:
A ForwardInfluenceBlanket object to use for model comparison.


def update_config(config):

    update(bigchaindb.config, update_types(config, bigchaindb.config))
    bigchaindb.config['CONFIGURED'] = True

Update bigchaindb.config with whatever is in the provided config dict,
and then set bigchaindb.config['CONFIGURED'] = True

Args:
config (dict): the config dict to read for changes
to the default config


def parse(self, argument):

    if isinstance(argument, self.enum_class):
      return argument
    if argument not in self.enum_class.__members__:
      raise ValueError('value should be one of <%s>' %
                       '|'.join(self.enum_class.__members__.keys()))
    else:
      return self.enum_class[argument]

Determines validity of argument and returns the correct element of enum.

Args:
argument: str or Enum class member, the supplied flag value.

Returns:
The first matching Enum class member in Enum class.

Raises:
ValueError: Raised when argument didn't match anything in enum.


def _update_field(self, uri, field):

		payload = None
		if  type(field) is not StreakField:
			return requests.codes.bad_request, None

		payload = field.to_dict(rw = True)

		try:
			uri = '/'.join([
							uri,
							field.attributes['key']
							])
		except KeyError:
			return requests.codes.bad_request, None

		code, data = self._req('post', uri , json.dumps(payload))

		return code, data

Updates a field with the provided attributes.
Args:
key	reqiured identifier for the pipeline or box
field			StreakField object
kwargs			{name, type} see StreakField for details
return			(status code, field dict)


def expected_rs(n):

  front = (n - 0.5) / n
  i = np.arange(1,n)
  back = np.sum(np.sqrt((n - i) / i))
  if n <= 340:
    middle = math.gamma((n-1) * 0.5) / math.sqrt(math.pi) / math.gamma(n * 0.5)
  else:
    middle = 1.0 / math.sqrt(n * math.pi * 0.5)
  return front * middle * back

Calculates the expected (R/S)_n for white noise for a given n.

This is used as a correction factor in the function hurst_rs. It uses the
formula of Anis-Lloyd-Peters (see [h_3]_).

Args:
n (int):
the value of n for which the expected (R/S)_n should be calculated

Returns:
float:
expected (R/S)_n for white noise


def sample_variants(self, variants, sample_name, category='snv'):
    LOG.info('Retrieving variants for subject : {0}'.format(sample_name))
    has_allele = re.compile('1|2')
    query = {'$and': [{'_id': {'$in': variants}}, {'category': category}, {'samples': {'$elemMatch': {'display_name': sample_name, 'genotype_call': {'$regex': has_allele}}}}]}
    result = self.variant_collection.find(query)
    return result

Given a list of variants get variant objects found in a specific patient

Args:
variants(list): a list of variant ids
sample_name(str): a sample display name
category(str): 'snv', 'sv' ..

Returns:
result(iterable(Variant))


def AddrStrToScriptHash(address):
    data = b58decode(address)
    if (len(data) != 25):
        raise ValueError('Not correct Address, wrong length.')
    if (data[0] != settings.ADDRESS_VERSION):
        raise ValueError('Not correct Coin Version')
    checksum = Crypto.Default().Hash256(data[:21])[:4]
    if (checksum != data[21:]):
        raise Exception('Address format error')
    return UInt160(data=data[1:21])

Convert a public address to a script hash.

Args:
address (str): base 58 check encoded public address.

Raises:
ValueError: if the address length of address version is incorrect.
Exception: if the address checksum fails.

Returns:
UInt160:


def query(self, s):
    s1 = np.sort([self.order[token] for token in s if (token in self.order)])
    logging.debug('{} original tokens and {} tokens after applying frequency order.'.format(len(s), len(s1)))
    prefix = self._get_prefix(s1)
    candidates = set([i for (p1, token) in enumerate(prefix) for (i, p2) in self.index[token] if self.position_filter_func(s1, self.sets[i], p1, p2, self.similarity_threshold)])
    logging.debug('{} candidates found.'.format(len(candidates)))
    results = deque([])
    for i in candidates:
        s2 = self.sets[i]
        sim = self.similarity_func(s1, s2)
        if (sim < self.similarity_threshold):
            continue
        results.append((i, sim))
    logging.debug('{} verified sets found.'.format(len(results)))
    return list(results)

Query the search index for sets similar to the query set.

Args:
s (Iterable): the query set.

Returns (list): a list of tuples `(index, similarity)` where the index
is the index of the matching sets in the original list of sets.


def inv(a):
    amean = gvar.mean(a)
    if ((amean.ndim != 2) or (amean.shape[0] != amean.shape[1])):
        raise ValueError(('bad matrix shape: ' + str(a.shape)))
    da = (a - amean)
    ainv = numpy.linalg.inv(amean)
    return (ainv - ainv.dot(da.dot(ainv)))

Inverse of matrix ``a``.

Args:
a: Two-dimensional, square matrix/array of numbers
and/or :class:`gvar.GVar`\s.

Returns:
The inverse of matrix ``a``.

Raises:
ValueError: If matrix is not square and two-dimensional.


def mimic_adam_with_adafactor(hparams):

  assert "adam" in hparams.optimizer
  hparams.optimizer = "adafactor"
  hparams.optimizer_adafactor_beta1 = hparams.optimizer_adam_beta1
  hparams.optimizer_adafactor_beta2 = hparams.optimizer_adam_beta2
  hparams.optimizer_adafactor_multiply_by_parameter_scale = False
  hparams.optimizer_adafactor_factored = False
  hparams.optimizer_adafactor_clipping_threshold = None
  hparams.optimizer_adafactor_decay_type = "adam"

Switch from Adam to Adafactor, approximating the behavior of Adam.

Some minor things may be different, like epsilon and beta1 correction.

Args:
hparams: model hyperparameters where "adam" in hparams.optimizer


def __init__(self, artifacts_registry, knowledge_base):

    super(ArtifactDefinitionsFilterHelper, self).__init__()
    self._artifacts_registry = artifacts_registry
    self._knowledge_base = knowledge_base

    self.file_system_artifact_names = set()
    self.file_system_find_specs = []
    self.registry_artifact_names = set()
    self.registry_find_specs = []

Initializes an artifact definitions filter helper.

Args:
artifacts_registry (artifacts.ArtifactDefinitionsRegistry): artifact
definitions registry.
knowledge_base (KnowledgeBase): contains information from the source
data needed for filtering.


def __init__(self, select2attrs=None, *args, **kwargs):

        self.select2attrs = select2attrs or {}
        assert_msg = "select2attrs attribute must be dict, not {}"
        assert isinstance(self.select2attrs, dict), assert_msg.format(
                self.select2attrs.__class__.__name__
        )
        if 'width' not in self.select2attrs:
            self.select2attrs.update({'width': '250px'})
        super(Select2Mixin, self).__init__(*args, **kwargs)

Initialize default select2 attributes.

If width is not provided, sets Select2 width to 250px.

Args:
select2attrs: a dictionary, which then passed to
Select2 constructor function as options.


def __init__(self, columns: list[str], name: Optional[str]=None):
    self.name = name
    super().__init__(columns)

Deduplicates each row (0th dimension) of the provided tensor.

Args:
columns: A list of the columns to apply the transformation on.
name: optional. A name for this operation.


def add_resource(self, feature_column, resource_name, resource):
    self._cols_to_resources_map[feature_column][resource_name] = resource
    if self._layer is not None and isinstance(resource, trackable.Trackable):
        if feature_column.name not in self._layer._resources:
            self._layer._resources[feature_column.name] = data_structures.Mapping()
        if resource_name not in self._layer._resources[feature_column.name]:
            self._layer._resources[feature_column.name][resource_name] = resource

Creates a new resource.

Resources can be things such as tables, variables, trackables, etc.

Args:
feature_column: A `FeatureColumn` object this resource corresponds to.
resource_name: Name of the resource.
resource: The resource.

Returns:
The created resource.


def ExtractEvents(self, parser_mediator, registry_key, **kwargs):

    version_value = registry_key.GetValueByName('Version')
    count_subkey = registry_key.GetSubkeyByName('Count')

    if not version_value:
      parser_mediator.ProduceExtractionWarning('missing version value')
      return

    if not version_value.DataIsInteger():
      parser_mediator.ProduceExtractionWarning(
          'unsupported version value data type')
      return

    format_version = version_value.GetDataAsObject()
    if format_version not in (3, 5):
      parser_mediator.ProduceExtractionWarning(
          'unsupported format version: {0:d}'.format(format_version))
      return

    if not count_subkey:
      parser_mediator.ProduceExtractionWarning('missing count subkey')
      return

    userassist_entry_index = 0

    for registry_value in count_subkey.GetValues():
      try:

        value_name = codecs.decode(registry_value.name, 'rot-13')
      except UnicodeEncodeError as exception:
        logger.debug((
            'Unable to decode UserAssist string: {0:s} with error: {1!s}.\n'
            'Attempting piecewise decoding.').format(
                registry_value.name, exception))

        characters = []
        for char in registry_value.name:
          if ord(char) < 128:
            try:
              characters.append(char.decode('rot-13'))
            except UnicodeEncodeError:
              characters.append(char)
          else:
            characters.append(char)

        value_name = ''.join(characters)

      if format_version == 5:
        path_segments = value_name.split('\\')

        for segment_index, path_segment in enumerate(path_segments):

          guid = path_segments[segment_index][1:-1]
          path_segments[segment_index] = known_folder_ids.PATHS.get(
              guid, path_segment)

        value_name = '\\'.join(path_segments)

        if '%' in value_name:

          environment_variables = self._knowledge_base.GetEnvironmentVariables()
          value_name = path_helper.PathHelper.ExpandWindowsPath(
              value_name, environment_variables)

      if value_name == 'UEME_CTLSESSION':
        continue

      if format_version == 3:
        entry_map = self._GetDataTypeMap('user_assist_entry_v3')
      elif format_version == 5:
        entry_map = self._GetDataTypeMap('user_assist_entry_v5')
      else:
        parser_mediator.ProduceExtractionWarning(
            'unsupported format version: {0:d}'.format(format_version))
        continue

      if not registry_value.DataIsBinaryData():
        parser_mediator.ProduceExtractionWarning(
            'unsupported value data type: {0:s}'.format(
                registry_value.data_type_string))
        continue

      entry_data_size = entry_map.GetByteSize()
      value_data_size = len(registry_value.data)
      if entry_data_size != value_data_size:
        parser_mediator.ProduceExtractionWarning(
            'unsupported value data size: {0:d}'.format(value_data_size))
        continue

      try:
        user_assist_entry = self._ReadStructureFromByteStream(
            registry_value.data, 0, entry_map)
      except (ValueError, errors.ParseError) as exception:
        parser_mediator.ProduceExtractionWarning(
            'unable to parse UserAssist entry value with error: {0!s}'.format(
                exception))
        continue

      event_data = UserAssistWindowsRegistryEventData()
      event_data.key_path = count_subkey.path
      event_data.number_of_executions = user_assist_entry.number_of_executions
      event_data.value_name = value_name

      if format_version == 3:
        if event_data.number_of_executions > 5:
          event_data.number_of_executions -= 5

      elif format_version == 5:
        userassist_entry_index += 1

        event_data.application_focus_count = (
            user_assist_entry.application_focus_count)
        event_data.application_focus_duration = (
            user_assist_entry.application_focus_duration)
        event_data.entry_index = userassist_entry_index

      timestamp = user_assist_entry.last_execution_time
      if not timestamp:
        date_time = dfdatetime_semantic_time.SemanticTime('Not set')
      else:
        date_time = dfdatetime_filetime.Filetime(timestamp=timestamp)

      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_LAST_RUN)
      parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts events from a Windows Registry key.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.


def add_state(self, name: str, state: State, initial: bool=False):
    if (not issubclass(state.__class__, State)):
        raise AttributeError('state must be subclass of spade.behaviour.State')
    self._states[name] = state
    if initial:
        self.current_state = name

Adds a new state to the FSM.

Args:
name (str): the name of the state, which is used as its identifier.
state (spade.behaviour.State): The state class
initial (bool, optional): wether the state is the initial state or not. (Only one initial state is allowed) (Default value = False)


def plot_internal_energy(self, tmin, tmax, ntemp, ylim=None, **kwargs):

        temperatures = np.linspace(tmin, tmax, ntemp)

        if self.structure:
            ylabel = r"$\Delta E$ (kJ/mol)"
        else:
            ylabel = r"$\Delta E$ (kJ/mol-c)"

        fig = self._plot_thermo(self.dos.internal_energy, temperatures, ylabel=ylabel, ylim=ylim,
                                factor=1e-3, **kwargs)

        return fig

Plots the vibrational internal energy in a temperature range.

Args:
tmin: minimum temperature
tmax: maximum temperature
ntemp: number of steps
ylim: tuple specifying the y-axis limits.
kwargs: kwargs passed to the matplotlib function 'plot'.
Returns:
matplotlib figure


def _checkResponseRegisterAddress(payload, registeraddress):

    _checkString(payload, minlength=2, description='payload')
    _checkRegisteraddress(registeraddress)

    BYTERANGE_FOR_STARTADDRESS = slice(0, 2)

    bytesForStartAddress = payload[BYTERANGE_FOR_STARTADDRESS]
    receivedStartAddress = _twoByteStringToNum(bytesForStartAddress)

    if receivedStartAddress != registeraddress:
        raise ValueError('Wrong given write start adress: {0}, but commanded is {1}. The data payload is: {2!r}'.format( \
            receivedStartAddress, registeraddress, payload))

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

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

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

Raises:
TypeError, ValueError


def create_graph_from_data(self, data):
    self.arguments['{SCORE}'] = self.scores[self.score]
    self.arguments['{VERBOSE}'] = str(self.verbose).upper()
    results = self._run_gies(data, verbose=self.verbose)
    return nx.relabel_nodes(nx.DiGraph(results), {idx: i for (idx, i) in enumerate(data.columns)})

Run the GIES algorithm.

Args:
data (pandas.DataFrame): DataFrame containing the data

Returns:
networkx.DiGraph: Solution given by the GIES algorithm.


def add_perm(self, subj_str, perm_str):

        self._assert_valid_permission(perm_str)
        self._perm_dict.setdefault(perm_str, set()).add(subj_str)

Add a permission for a subject.

Args:
subj_str : str
Subject for which to add permission(s)

perm_str : str
Permission to add. Implicitly adds all lower permissions. E.g., ``write``
will also add ``read``.


def scan(self, folder, sub=None, next_=None):
    if (not sub):
        sub = ''
    assert isinstance(sub, string_types)
    assert (isinstance(next_, int) or (next_ is None))
    return self.post('scan', params={'folder': folder, 'sub': sub, 'next': next_})

Request immediate rescan of a folder, or a specific path within a
folder.

Args:
folder (str): Folder ID.
sub (str): Path relative to the folder root. If sub is omitted
the entire folder is scanned for changes, otherwise only
the given path children are scanned.
next_ (int): Delays Syncthing's automated rescan interval for
a given amount of seconds.

Returns:
str


def load_yaml(path):
    with open(path, 'rt') as f:
        yamldict = yaml.load(f.read(), Loader=yamlloader.ordereddict.CSafeLoader)
    if (not yamldict):
        raise LoadError(('YAML file: %s is empty!' % path))
    return yamldict

Load YAML file into an ordered dictionary

Args:
path (str): Path to YAML file

Returns:
OrderedDict: Ordered dictionary containing loaded YAML file


def create_slot(primary, val, name, colocate_with_primary=True, *, copy_xla_sharding=False):
    validate_shape = val.get_shape().is_fully_defined()
    if isinstance(primary, variables.Variable):
        prefix = primary._shared_name
    else:
        prefix = primary.op.name
    with variable_scope.variable_scope(None, prefix + '/' + name):
        if colocate_with_primary:
            distribution_strategy = distribute_lib.get_strategy()
            with distribution_strategy.extended.colocate_vars_with(primary):
                return _create_slot_var(primary, val, '', validate_shape, None, None, copy_xla_sharding=copy_xla_sharding)
        else:
            return _create_slot_var(primary, val, '', validate_shape, None, None, copy_xla_sharding=copy_xla_sharding)

Create a slot initialized to the given value.

The type of the slot is determined by the given value.

Args:
primary: The primary `Variable` or `Tensor`.
val: A `Tensor` specifying the initial value of the slot.
name: Name to use for the slot variable.
colocate_with_primary: Boolean.  If True the slot is located
on the same device as `primary`.
copy_xla_sharding: Boolean. If True also copies XLA sharding
from primary.

Returns:
A `Variable` object.


def annotate(label, since, current, extra_message, custom_message=None):
    warning_message = _WarningMessage(label=label, since=since, current=current, extra_message=extra_message, custom_message=custom_message)

    def _annotate(fnc):
        if inspect.isclass(fnc):
            old_new = fnc.__new__

            def wrapped_new(cls, *args, **kwargs):
                warning_message.emit_warning(fnc.__name__)
                if old_new is object.__new__:
                    return old_new(cls)
                return old_new(cls, *args, **kwargs)
            fnc.__new__ = staticmethod(wrapped_new)
            if label == 'deprecated':
                fnc.__doc__ = _add_deprecation_notice_to_docstring(fnc.__doc__, warning_message.message.replace('%name%', fnc.__name__))
            return fnc
        else:

            @wraps(fnc)
            def inner(*args, **kwargs):
                warning_message.emit_warning(fnc.__name__)
                return fnc(*args, **kwargs)
            if label == 'deprecated':
                inner.__doc__ = _add_deprecation_notice_to_docstring(fnc.__doc__, warning_message.message.replace('%name%', fnc.__name__))
            return inner
    return _annotate

Decorates an API with a deprecated or experimental annotation.

Args:
label: the kind of annotation ('deprecated' or 'experimental').
since: the version that causes the annotation.
current: the suggested replacement function.
extra_message: an optional additional message.
custom_message: if the default message does not suffice, the message
can be changed using this argument. A string
whit replacement tokens.
A replecement string is were the previus args will
be located on the custom message.
The following replacement strings can be used:
%name% -> API.__name__
%since% -> since (Mandatory for the decapreted annotation)
%current% -> current
%extra% -> extra_message

Returns:
The decorator for the API.


def resources(self, absolute_url=None):

        if absolute_url:
            return Resources(mode="server", root_url=absolute_url + self._prefix, path_versioner=StaticHandler.append_version)
        return Resources(mode="server", root_url=self._prefix, path_versioner=StaticHandler.append_version)

Provide a :class:`~bokeh.resources.Resources` that specifies where
Bokeh application sessions should load BokehJS resources from.

Args:
absolute_url (bool):
An absolute URL prefix to use for locating resources. If None,
relative URLs are used (default: None)


def __is_function_action(self, action_function):

        is_function_action = True

        if not hasattr(action_function, '__call__'):
            return False

        try:
            for end_string, context in action_function():
                if not isinstance(end_string, basestring):
                    self.log_error("Action function must return end of filename as a string as first argument")
                if not isinstance(context, dict):
                    self.log_error("Action function must return context as a dict as second argument")
                break
        except Exception:
            is_function_action = False

        return is_function_action

Detect if given function is really an action function.

Args:
action_function: Function to test.

Note:
We don't care if the variable refer to a function but rather if it is callable or not.


def _get_status_code(self, http_status):
    try:
        return int(http_status.split(' ', 1)[0])
    except TypeError:
        _logger.warning('Unable to find status code in HTTP status %r.', http_status)
    return 500

Get the HTTP status code from an HTTP status string.

Args:
http_status: A string containing a HTTP status code and reason.

Returns:
An integer with the status code number from http_status.


def __init__(self, project, query, checksum, timeout_secs=0):
    if bigquery is None:
        raise ImportError('Bigquery dependencies are not installed.')
    if not query or not isinstance(query, str):
        raise ValueError('Invalid argument: query. Please use non-empty string')
    if not checksum or not isinstance(checksum, str):
        raise ValueError('Invalid argument: checksum. Please use non-empty string')
    self.project = project
    self.query = query
    self.expected_checksum = checksum
    self.checksum = None
    self.timeout_secs = timeout_secs

Initialize BigQueryMatcher object.
Args:
project: The name (string) of the project.
query: The query (string) to perform.
checksum: SHA-1 hash generated from a sorted list of lines
read from expected output.
timeout_secs: Duration to retry query until checksum matches. This
is useful for DF streaming pipelines or BQ streaming inserts. The
default (0) never retries.


def reshape_data(tensor, per_example_length=1):
    dims = [1, 0]
    for i in xrange(2, tensor.get_shape().ndims):
        dims.append(i)
    return pt.wrap(tf.transpose(tensor, dims)).reshape([(- 1), per_example_length])

Reshapes input so that it is appropriate for sequence_lstm..

The expected format for sequence lstms is
[timesteps * batch, per_example_length] and the data produced by the utilities
is [batch, timestep, *optional* expected_length].  The result can be cleaved
so that there is a Tensor per timestep.

Args:
tensor: The tensor to reshape.
per_example_length: The number of examples at each timestep.
Returns:
A Pretty Tensor that is compatible with cleave and then sequence_lstm.


def _Scroll(self, lines=None):

    if lines is None:
      lines = self._cli_lines

    if lines < 0:
      self._displayed -= self._cli_lines
      self._displayed += lines
      if self._displayed < 0:
        self._displayed = 0
      self._lines_to_show = self._cli_lines
    else:
      self._lines_to_show = lines

    self._lastscroll = lines

Set attributes to scroll the buffer correctly.

Args:
lines: An int, number of lines to scroll. If None, scrolls
by the terminal length.


def __init__(self, config, http_client_session=None):

        self.verify = config.get("verify", True)
        self.output = config.get("output", [])
        self.validation_results = []
        config_variables = config.get("variables", {})

        testcase_setup_hooks = config.get("setup_hooks", [])

        self.testcase_teardown_hooks = config.get("teardown_hooks", [])

        self.http_client_session = http_client_session or HttpSession()
        self.session_context = SessionContext(config_variables)

        if testcase_setup_hooks:
            self.do_hook_actions(testcase_setup_hooks, "setup")

run testcase or testsuite.

Args:
config (dict): testcase/testsuite config dict

{
"name": "ABC",
"variables": {},
"setup_hooks", [],
"teardown_hooks", []
}

http_client_session (instance): requests.Session(), or locust.client.Session() instance.


def parse_commit_message(commit_message: str) -> Dict[str, bool]:
    if commit_message is None:
        return {'skip': False, 'no_filter': False, 'test_all': False}
    command_search = re.search('\\[([^\\]]*)\\]', commit_message)
    if command_search is not None:
        command = command_search.groups()[0]
        command = command.lower().replace('-', ' ').replace('_', ' ')
        skip = command in ['ci skip', 'skip ci', 'circleci skip', 'skip circleci']
        no_filter = set(command.split(' ')) == {'no', 'filter'}
        test_all = set(command.split(' ')) == {'test', 'all'}
        return {'skip': skip, 'no_filter': no_filter, 'test_all': test_all}
    else:
        return {'skip': False, 'no_filter': False, 'test_all': False}

Parses the commit message to detect if a command is there to skip, force all or part of the CI.

Args:
commit_message (`str`): The commit message of the current commit.

Returns:
`Dict[str, bool]`: A dictionary of strings to bools with keys the following keys: `"skip"`,
`"test_all_models"` and `"test_all"`.


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 get_parent(self, tree, alt=None):

        parent = self.parent_db.get(tree.path)

        if not parent:
            return alt

        return list(parent)[0]

Get parent for given `tree` or `alt` if not found.

Args:
tree (obj): :class:`.Tree` instance, which is already stored in DB.
alt (obj, default None): Alternative value returned when `tree` is
not found.

Returns:
obj: :class:`.Tree` parent to given `tree`.


def minimum_eigen_vector(x, num_steps, learning_rate, vector_prod_fn):
    x = tf.nn.l2_normalize(x)
    for _ in range(num_steps):
        x = eig_one_step(x, learning_rate, vector_prod_fn)
    return x

Computes eigenvector which corresponds to minimum eigenvalue.

Args:
x: initial value of eigenvector.
num_steps: number of optimization steps.
learning_rate: learning rate.
vector_prod_fn: function which takes x and returns product H*x.

Returns:
approximate value of eigenvector.

This function finds approximate value of eigenvector of matrix H which
corresponds to smallest (by absolute value) eigenvalue of H.
It works by solving optimization problem x^{T}*H*x -> min.


def _parse_ospf_process_id(self, config):

        match = re.search(r'^router ospf (\d+)', config)
        return dict(ospf_process_id=int(match.group(1)))

Parses config file for the OSPF proc ID

Args:
config(str):  Running configuration
Returns:
dict: key: ospf_process_id (int)


def apply_formatting_dict(obj: Any, formatting: Dict[(str, Any)]) -> Any:
    new_obj = obj
    if isinstance(obj, str):
        if ('$' not in obj):
            new_obj = string.Formatter().vformat(obj, (), formatting_dict(**formatting))
    elif isinstance(obj, dict):
        new_obj = {}
        for (k, v) in obj.items():
            new_obj[k] = apply_formatting_dict(v, formatting)
    elif isinstance(obj, list):
        new_obj = []
        for (i, el) in enumerate(obj):
            new_obj.append(apply_formatting_dict(el, formatting))
    elif (isinstance(obj, int) or isinstance(obj, float) or (obj is None)):
        pass
    elif isinstance(obj, enum.Enum):
        pass
    else:
        logger.debug(f"Unrecognized obj '{obj}' of type '{type(obj)}'")
    return new_obj

Recursively apply a formatting dict to all strings in a configuration.

Note that it skips applying the formatting if the string appears to contain latex (specifically,
if it contains an "$"), since the formatting fails on nested brackets.

Args:
obj: Some configuration object to recursively applying the formatting to.
formatting (dict): String formatting options to apply to each configuration field.
Returns:
dict: Configuration with formatting applied to every field.


def apply_cut(self, cut):

        return Subsystem(self.network, self.state, self.node_indices,
                         cut=cut, mice_cache=self._mice_cache)

Return a cut version of this |Subsystem|.

Args:
cut (Cut): The cut to apply to this |Subsystem|.

Returns:
Subsystem: The cut subsystem.


def filter_dict(d, exclude):
    ret = {}
    for (key, value) in d.items():
        if (key not in exclude):
            ret.update({key: value})
    return ret

Return a new dict with specified keys excluded from the origional dict

Args:
d (dict): origional dict
exclude (list): The keys that are excluded


def ParseFileObject(self, parser_mediator, file_object):
    esedb_file = pyesedb.file()
    try:
        esedb_file.open_file_object(file_object)
    except IOError as exception:
        parser_mediator.ProduceExtractionWarning('unable to open file with error: {0!s}'.format(exception))
        return
    cache = ESEDBCache()
    try:
        table_names = frozenset(self._GetTableNames(esedb_file))
        for plugin in self._plugins:
            if parser_mediator.abort:
                break
            if (not plugin.required_tables.issubset(table_names)):
                continue
            try:
                plugin.UpdateChainAndProcess(parser_mediator, cache=cache, database=esedb_file)
            except Exception as exception:
                parser_mediator.ProduceExtractionWarning('plugin: {0:s} unable to parse ESE database with error: {1!s}'.format(plugin.NAME, exception))
    finally:
        esedb_file.close()

Parses an ESE database file-like object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): file-like object.


def prepare_run_debug_urls(self, fetches, feed_dict):
    self._run_counter_lock.acquire()
    run_dir = os.path.join(self._session_root, 'run_%d_%d' % (int(time.time() * 1000000.0), self._run_counter))
    self._run_counter += 1
    self._run_counter_lock.release()
    gfile.MkDir(run_dir)
    fetches_event = event_pb2.Event()
    fetches_event.log_message.message = repr(fetches)
    fetches_path = os.path.join(run_dir, debug_data.METADATA_FILE_PREFIX + debug_data.FETCHES_INFO_FILE_TAG)
    with gfile.Open(os.path.join(fetches_path), 'wb') as f:
        f.write(fetches_event.SerializeToString())
    feed_keys_event = event_pb2.Event()
    feed_keys_event.log_message.message = repr(feed_dict.keys()) if feed_dict else repr(feed_dict)
    feed_keys_path = os.path.join(run_dir, debug_data.METADATA_FILE_PREFIX + debug_data.FEED_KEYS_INFO_FILE_TAG)
    with gfile.Open(os.path.join(feed_keys_path), 'wb') as f:
        f.write(feed_keys_event.SerializeToString())
    return ['file:

Implementation of abstract method in superclass.

See doc of `NonInteractiveDebugWrapperSession.prepare_run_debug_urls()`
for details. This implementation creates a run-specific subdirectory under
self._session_root and stores information regarding run `fetches` and
`feed_dict.keys()` in the subdirectory.

Args:
fetches: Same as the `fetches` argument to `Session.run()`
feed_dict: Same as the `feed_dict` argument to `Session.run()`

Returns:
debug_urls: (`str` or `list` of `str`) file:// debug URLs to be used in
this `Session.run()` call.


def get_class_weights(y, smooth_factor=0):
    from collections import Counter
    counter = Counter(y)
    if (smooth_factor > 0):
        p = (max(counter.values()) * smooth_factor)
        for k in counter.keys():
            counter[k] += p
    majority = max(counter.values())
    return {cls: float((majority / count)) for (cls, count) in counter.items()}

Returns the weights for each class based on the frequencies of the samples.

Args:
y: A list of true labels (the labels must be hashable).
smooth_factor: A factor that smooths extremely uneven weights.

Returns:
A dictionary with the weight for each class.


def BuildFilterFindSpecs(self, artifact_definitions_path, custom_artifacts_path, knowledge_base_object, artifact_filter_names=None, filter_file_path=None):
    environment_variables = knowledge_base_object.GetEnvironmentVariables()
    find_specs = None
    if artifact_filter_names:
        logger.debug('building find specification based on artifacts: {0:s}'.format(', '.join(artifact_filter_names)))
        artifacts_registry_object = BaseEngine.BuildArtifactsRegistry(artifact_definitions_path, custom_artifacts_path)
        self._artifacts_filter_helper = artifact_filters.ArtifactDefinitionsFilterHelper(artifacts_registry_object, knowledge_base_object)
        self._artifacts_filter_helper.BuildFindSpecs(artifact_filter_names, environment_variables=environment_variables)
        if self._artifacts_filter_helper.registry_find_specs:
            self._artifacts_filter_helper.BuildFindSpecs(self._WINDOWS_REGISTRY_FILES_ARTIFACT_NAMES, environment_variables=environment_variables)
        find_specs = self._artifacts_filter_helper.file_system_find_specs
        if (not find_specs):
            raise errors.InvalidFilter('No valid file system find specifications were built from artifacts.')
    elif filter_file_path:
        logger.debug('building find specification based on filter file: {0:s}'.format(filter_file_path))
        filter_file_object = filter_file.FilterFile(filter_file_path)
        find_specs = filter_file_object.BuildFindSpecs(environment_variables=environment_variables)
        if (not find_specs):
            raise errors.InvalidFilter('No valid file system find specifications were built from filter file.')
    return find_specs

Builds find specifications from artifacts or filter file if available.

Args:
artifact_definitions_path (str): path to artifact definitions file.
custom_artifacts_path (str): path to custom artifact definitions file.
knowledge_base_object (KnowledgeBase): knowledge base.
artifact_filter_names (Optional[list[str]]): names of artifact
definitions that are used for filtering file system and Windows
Registry key paths.
filter_file_path (Optional[str]): path of filter file.

Returns:
list[dfvfs.FindSpec]: find specifications for the file source type.

Raises:
InvalidFilter: if no valid FindSpecs are built.


def convert_dt_time(duration, return_iter=False):

    try:
        days, hours, minutes, seconds = convert_timedelta(duration)
        if return_iter:
            return days, hours, minutes, seconds

        if days > 0:
            format_string = (
                '{} day{}, {} hour{}'.format(
                 days, 's' if days != 1 else '', hours, 's' if hours != 1 else ''))
        elif hours > 1:
            format_string = (
                '{} hour{}, {} minute{}'.format(
                 hours, 's' if hours != 1 else '', minutes, 's' if minutes != 1 else ''))
        else:
            format_string = (
                '{} minute{}, {} sec{}'.format(
                 minutes, 's' if minutes != 1 else '', seconds, 's' if seconds != 1 else ''))
    except AttributeError as e:
        logger.exception(
            '%s: Type mismatch when converting timedelta objects (Code: %s)' %
            (inspect.stack()[0][3], str(e)))
    except Exception as e:
        logger.exception(
            '%s: Unknown error when converting datetime objects (Code: %s)' %
            (inspect.stack()[0][3], str(e)))
    return format_string

Summary:
convert timedelta objects to human readable output
Args:
:duration (datetime.timedelta): time duration to convert
:return_iter (tuple):  tuple containing time sequence
Returns:
days, hours, minutes, seconds | TYPE: tuple (integers), OR
human readable, notated units | TYPE: string


def preds(self, nodeids=None):

        if nodeids is None: nodeids = self._nodeids
        _eps = self._eps
        return [_eps[nid][1] for nid in nodeids]

Return the Pred objects for *nodeids*, or all Preds.

Args:
nodeids: an iterable of nodeids of predications to return
Preds from; if `None`, return all Preds


def dataflow_to_dataset(df, types):
    assert isinstance(df, DataFlow), df
    assert isinstance(types, (list, tuple)), types
    df = MapData(df, (lambda dp: tuple(dp)))
    df.reset_state()
    ds = tf.data.Dataset.from_generator(df.get_data, tuple(types))
    return ds

Wrap a dataflow to tf.data.Dataset.
This function will also reset the dataflow.

If the dataflow itself is finite, the returned dataset is also finite.
Therefore, if used for training, you'll need to add `.repeat()` on the returned
dataset.

Args:
df (DataFlow): a dataflow which produces lists
types([tf.DType]): list of types

Returns:
(tf.data.Dataset)


def get_entry_type(self, tag):

        if tag.findParent().get('kind') in ['class', 'struct']:
            return u'Method'

        return super(functionTagProcessor, self).get_entry_type(tag)

Override that returns u'Method' for class/struct methods.

Override as necessary.

Args:
tag: A BeautifulSoup Tag for a function.

Returns:
If this is a class/struct method, returns u'Method', otherwise
returns the value from the inherited implementation of
get_entry_type (which should be u'Function').


def fill_memory_slot(memory, value, index):
    mask = tf.to_float(tf.one_hot(index, tf.shape(memory)[0])[(:, None, None, None)])
    fill_memory = (((1 - mask) * memory) + (mask * value[(None, ...)]))
    return fill_memory

Fills the memory slot at a particular index with the given value.

Args:
memory: a 4-d tensor [memory_size, batch, length, channel] containing
the state of all steps
value: a 3-d tensor [batch, length, channel] as the sate
index: integer in [0, memory_size)

Returns:
filled memory


def evalAsync(self, amplstatements, callback, **kwargs):

        if self._langext is not None:
            amplstatements = self._langext.translate(amplstatements, **kwargs)

        def async_call():
            self._lock.acquire()
            try:
                self._impl.eval(amplstatements)
                self._errorhandler_wrapper.check()
            except Exception:
                self._lock.release()
                raise
            else:
                self._lock.release()
                callback.run()
        Thread(target=async_call).start()

Interpret the given AMPL statement asynchronously.

Args:
amplstatements: A collection of AMPL statements and declarations to
be passed to the interpreter.

callback: Callback to be executed when the statement has been
interpreted.

Raises:
RuntimeError: if the input is not a complete AMPL statement (e.g.
if it does not end with semicolon) or if the underlying
interpreter is not running.


def set(self, key, value):

        data = self._load_file()
        data[key] = value
        self._save_file(data)

Set the value of a key

Args:
key (string): The key used to store this value
value (string): The value to store


def RegisterPlugin(cls, plugin_class):
    plugin_name = plugin_class.NAME.lower()
    if (plugin_name in cls._plugin_classes):
        raise KeyError('Plugin class already set for name: {0:s}.'.format(plugin_class.NAME))
    cls._plugin_classes[plugin_name] = plugin_class

Registers a plugin class.

The plugin classes are identified based on their lower case name.

Args:
plugin_class (type): class of the plugin.

Raises:
KeyError: if plugin class is already set for the corresponding name.


def precipitable_water(self, value=999.0):

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

        self._precipitable_water = value

Corresponds to IDD Field `precipitable_water`

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

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


def case(self, case_id=None):

        cases = self.cases()
        if case_id:
            for case in cases:
                if case.case_id == case_id:
                    return case
        else:
            if cases:
                return cases[0]

        return None

Return a Case object

If no case_id is given return one case

Args:
case_id (str): A case id

Returns:
case(Case): A Case object


def class_logit(layer, label):

    def inner(T):
        if isinstance(label, int):
            class_n = label
        else:
            class_n = T('labels').index(label)
        logits = T(layer)
        logit = tf.reduce_sum(logits[(:, class_n)])
        return logit
    return inner

Like channel, but for softmax layers.

Args:
layer: A layer name string.
label: Either a string (refering to a label in model.labels) or an int
label position.

Returns:
Objective maximizing a logit.


def configure_attributes(self, json_data):

        env = boto3.session.Session(profile_name=self.env, region_name=self.region)
        elbclient = env.client('elb')

        elb_settings = self.properties['elb']
        LOG.debug('Block ELB Settings Pre Configure Load Balancer Attributes:\n%s', pformat(elb_settings))

        for job in json.loads(json_data)['job']:
            load_balancer_attributes = {
                'CrossZoneLoadBalancing': {
                    'Enabled': True
                },
                'AccessLog': {
                    'Enabled': False,
                },
                'ConnectionDraining': {
                    'Enabled': False,
                },
                'ConnectionSettings': {
                    'IdleTimeout': 60
                }
            }
            if elb_settings.get('connection_draining_timeout'):
                connection_draining_timeout = int(elb_settings['connection_draining_timeout'])
                LOG.info('Applying Custom Load Balancer Connection Draining Timeout: %d', connection_draining_timeout)
                load_balancer_attributes['ConnectionDraining'] = {
                    'Enabled': True,
                    'Timeout': connection_draining_timeout
                }
            if elb_settings.get('idle_timeout'):
                idle_timeout = int(elb_settings['idle_timeout'])
                LOG.info('Applying Custom Load Balancer Idle Timeout: %d', idle_timeout)
                load_balancer_attributes['ConnectionSettings'] = {'IdleTimeout': idle_timeout}
            if elb_settings.get('access_log'):
                access_log_bucket_name = elb_settings['access_log']['bucket_name']
                access_log_bucket_prefix = elb_settings['access_log']['bucket_prefix']
                access_log_emit_interval = int(elb_settings['access_log']['emit_interval'])
                LOG.info('Applying Custom Load Balancer Access Log: %s/%s every %d minutes', access_log_bucket_name,
                         access_log_bucket_prefix, access_log_emit_interval)
                load_balancer_attributes['AccessLog'] = {
                    'Enabled': True,
                    'S3BucketName': access_log_bucket_name,
                    'EmitInterval': access_log_emit_interval,
                    'S3BucketPrefix': access_log_bucket_prefix
                }

            LOG.info('Applying Load Balancer Attributes')
            LOG.debug('Load Balancer Attributes:\n%s', pformat(load_balancer_attributes))
            elbclient.modify_load_balancer_attributes(
                LoadBalancerName=self.app, LoadBalancerAttributes=load_balancer_attributes)

Configure load balancer attributes such as idle timeout, connection draining, etc

Args:
json_data (json): return data from ELB upsert