def find_node_by_value(self, value):
    try:
        return next((n for n in self.node_list if (n.value == value)))
    except StopIteration:
        return None

Find and return a node in self.node_list with the value ``value``.

If multiple nodes exist with the value ``value``,
return the first one found.

If no such node exists, this returns ``None``.

Args:
value (Any): The value of the node to find

Returns:
Node: A node with value ``value`` if it was found

None: If no node exists with value ``value``

Example:
>>> from blur.markov.node import Node
>>> node_1 = Node('One')
>>> graph = Graph([node_1])
>>> found_node = graph.find_node_by_value('One')
>>> found_node == node_1
True


def update_torch_dtype(self, torch_dtype: 'torch.dtype') -> 'torch.dtype':
    return torch_dtype

Some quantization methods require to explicitly set the dtype of the model to a
target dtype. You need to override this method in case you want to make sure that behavior is
preserved

Args:
torch_dtype (`torch.dtype`):
The input dtype that is passed in `from_pretrained`


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

Base class for model's outputs, with potential hidden states.

Args:
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
Sequence of hidden-states at the output of the last layer of the model.
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`):
Tuple of `torch.FloatTensor` (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape `(batch_size, num_channels, height, width)`.

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


def get_pipeline_path(pipeline_name, working_directory):
    logger.debug('starting')
    logger.debug(f'current directory is {working_directory}')
    pipeline_path = os.path.abspath(os.path.join(working_directory, 'pipelines', (pipeline_name + '.yaml')))
    if os.path.isfile(pipeline_path):
        logger.debug(f'Found {pipeline_path}')
    else:
        logger.debug(f'{pipeline_name} not found in current directory/pipelines folder. Looking in pypyr install directory instead.')
        pypyr_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        logger.debug(f'pypyr installation directory is: {pypyr_dir}')
        pipeline_path = os.path.abspath(os.path.join(pypyr_dir, 'pipelines', (pipeline_name + '.yaml')))
        if os.path.isfile(pipeline_path):
            logger.debug(f'Found {pipeline_path}')
        else:
            raise PipelineNotFoundError(f'{pipeline_name}.yaml not found in either {working_directory}/pipelines or {pypyr_dir}/pipelines')
    logger.debug('done')
    return pipeline_path

Look for the pipeline in the various places it could be.

First checks the cwd. Then checks pypyr/pipelines dir.

Args:
pipeline_name: string. Name of pipeline to find
working_directory: string. Path in which to look for pipeline_name.yaml

Returns:
Absolute path to the pipeline_name.yaml file

Raises:
PipelineNotFoundError: if pipeline_name.yaml not found in working_dir
or in {pypyr install dir}/pipelines.


def save(self, recipe):
    if (('id' in recipe) and (recipe['id'] is not None)):
        self.logger.debug(('Updating existing recipe: ' + json.dumps(recipe)))
        url = ('%(base_url)s/recipe/json/%(recipe_id)s' % {'base_url': self.base_url, 'recipe_id': recipe['id']})
        r = self.gbdx_connection.put(url, json=recipe)
        try:
            r.raise_for_status()
        except:
            print(r.text)
            raise
        return recipe['id']
    else:
        self.logger.debug(('Creating new recipe: ' + json.dumps(recipe)))
        url = ('%(base_url)s/recipe/json' % {'base_url': self.base_url})
        r = self.gbdx_connection.post(url, json=recipe)
        try:
            r.raise_for_status()
        except:
            print(r.text)
            raise
        recipe_json = r.json()
        return recipe_json['id']

Saves an AnswerFactory Recipe

Args:
recipe (dict): Dictionary specifying a recipe

Returns:
AnswerFactory Recipe id


def market_open(self, session, mins) -> Session:
    if (session not in self.exch):
        return SessNA
    start_time = self.exch[session][0]
    return Session(start_time, shift_time(start_time, int(mins)))

Time intervals for market open

Args:
session: [allday, day, am, pm, night]
mins: mintues after open

Returns:
Session of start_time and end_time


def dummyctrl(self,r,ctrl):

        dv = DummyVertex(r)
        dv.view.w,dv.view.h=self.dw,self.dh
        self.grx[dv] = dv
        dv.ctrl = ctrl
        ctrl[r] = dv
        self.layers[r].append(dv)
        return dv

creates a DummyVertex at rank r inserted in the ctrl dict
of the associated edge and layer.

Arguments:
r (int): rank value
ctrl (dict): the edge's control vertices

Returns:
DummyVertex : the created DummyVertex.


def split(self, desired_bundle_size: int, start_position: Union[int, str, bytes, ObjectId]=None, stop_position: Union[int, str, bytes, ObjectId]=None):
    desired_bundle_size_in_mb = desired_bundle_size
    desired_bundle_size_in_mb = max(desired_bundle_size_in_mb, 1)
    is_initial_split = start_position is None and stop_position is None
    start_position, stop_position = self._replace_none_positions(start_position, stop_position)
    if self.bucket_auto:
        split_keys = []
        weights = []
        for bucket in self._get_auto_buckets(desired_bundle_size_in_mb, start_position, stop_position, is_initial_split):
            split_keys.append({'_id': bucket['_id']['max']})
            weights.append(bucket['count'])
    else:
        split_keys = self._get_split_keys(desired_bundle_size_in_mb, start_position, stop_position)
        weights = itertools.cycle((desired_bundle_size_in_mb,))
    bundle_start = start_position
    for split_key_id, weight in zip(split_keys, weights):
        if bundle_start >= stop_position:
            break
        bundle_end = min(stop_position, split_key_id['_id'])
        yield iobase.SourceBundle(weight=weight, source=self, start_position=bundle_start, stop_position=bundle_end)
        bundle_start = bundle_end
    if bundle_start < stop_position:
        weight = 1 if self.bucket_auto else desired_bundle_size_in_mb
        yield iobase.SourceBundle(weight=weight, source=self, start_position=bundle_start, stop_position=stop_position)

Splits the source into a set of bundles.

Bundles should be approximately of size ``desired_bundle_size`` bytes.

Args:
desired_bundle_size: the desired size (in bytes) of the bundles returned.
start_position: if specified the given position must be used as the
starting position of the first bundle.
stop_position: if specified the given position must be used as the ending
position of the last bundle.
Returns:
an iterator of objects of type 'SourceBundle' that gives information about
the generated bundles.


def get(self, url):
    self._driver.get(url)
    if self.bot_diary:
        self.bot_diary.add_auto_entry('I went on', target=url, take_screenshot=True)
    if BROME_CONFIG['proxy_driver']['intercept_javascript_error']:
        self.init_javascript_error_interception()
    return True

Navigate to a specific url

This specific implementation inject a javascript
script to intercept the javascript error

Configurable with the "proxy_driver:intercept_javascript_error" config

Args:
url (str): the url to navigate to

Returns:
bool


def describe_field(field_definition):

    field_descriptor = FieldDescriptor()
    field_descriptor.name = field_definition.name
    field_descriptor.number = field_definition.number
    field_descriptor.variant = field_definition.variant

    if isinstance(field_definition, messages.EnumField):
        field_descriptor.type_name = field_definition.type.definition_name()

    if isinstance(field_definition, messages.MessageField):
        field_descriptor.type_name = (
            field_definition.message_type.definition_name())

    if field_definition.default is not None:
        field_descriptor.default_value = _DEFAULT_TO_STRING_MAP[
            type(field_definition)](field_definition.default)

    if field_definition.repeated:
        field_descriptor.label = FieldDescriptor.Label.REPEATED
    elif field_definition.required:
        field_descriptor.label = FieldDescriptor.Label.REQUIRED
    else:
        field_descriptor.label = FieldDescriptor.Label.OPTIONAL

    return field_descriptor

Build descriptor for Field instance.

Args:
field_definition: Field instance to provide descriptor for.

Returns:
Initialized FieldDescriptor instance describing the Field instance.


def _IsWindowsDrivePathSegment(cls, path_segment):
    if ((len(path_segment) == 2) and (path_segment[1] == ':') and path_segment[0].isalpha()):
        return True
    path_segment = path_segment.upper()
    return (path_segment in ('%%ENVIRON_SYSTEMDRIVE%%', '%SYSTEMDRIVE%'))

Determines if the path segment contains a Windows Drive indicator.

A drive indicator can be a drive letter or %SystemDrive%.

Args:
path_segment (str): path segment.

Returns:
bool: True if the path segment contains a Windows Drive indicator.


def _CreateOutputModule(self, options):
    formatter_mediator = formatters_mediator.FormatterMediator(data_location=self._data_location)
    try:
        formatter_mediator.SetPreferredLanguageIdentifier(self._preferred_language)
    except (KeyError, TypeError) as exception:
        raise RuntimeError(exception)
    mediator = output_mediator.OutputMediator(self._knowledge_base, formatter_mediator, preferred_encoding=self.preferred_encoding)
    mediator.SetTimezone(self._preferred_time_zone)
    try:
        output_module = output_manager.OutputManager.NewOutputModule(self._output_format, mediator)
    except (KeyError, ValueError) as exception:
        raise RuntimeError('Unable to create output module with error: {0!s}'.format(exception))
    if output_manager.OutputManager.IsLinearOutputModule(self._output_format):
        output_file_object = open(self._output_filename, 'wb')
        output_writer = tools.FileObjectOutputWriter(output_file_object)
        output_module.SetOutputWriter(output_writer)
    helpers_manager.ArgumentHelperManager.ParseOptions(options, output_module)
    missing_parameters = output_module.GetMissingArguments()
    while missing_parameters:
        for parameter in missing_parameters:
            value = self._PromptUserForInput('Missing parameter {0:s} for output module'.format(parameter))
            if (value is None):
                logger.warning('Unable to set the missing parameter for: {0:s}'.format(parameter))
                continue
            setattr(options, parameter, value)
        helpers_manager.ArgumentHelperManager.ParseOptions(options, output_module)
        missing_parameters = output_module.GetMissingArguments()
    return output_module

Creates the output module.

Args:
options (argparse.Namespace): command line arguments.

Returns:
OutputModule: output module.

Raises:
RuntimeError: if the output module cannot be created.


def apply(self, read_tuple_name, read_tuple_id=None, synchronize_widths=True):

        parts = read_tuple_name.split("__")
        parts[0] = self._fill_right(parts[0], "-", self.prefix_width)
        if read_tuple_id is not None:
            parts[1] = "{:x}".format(read_tuple_id)
        parts[1] = self._fill_left(parts[1], "0", self.read_tuple_id_width)

        if synchronize_widths:
            new_segments = []
            segments = parts[2][1:-1].split("),(")
            for segment in segments:
                values = segment.split(",")
                values[0] = values[0].zfill(self.genome_id_width)
                values[1] = values[1].zfill(self.chr_id_width)
                values[3] = values[3].zfill(self.coor_width)
                values[4] = values[4].zfill(self.coor_width)
                new_segments.append("(" + ",".join(values) + ")")
            parts[2] = ",".join(new_segments)

        return "__".join(parts)

Apply profile on a read tuple name and update read tuple ID.

Args:
read_tuple_name (str): Read tuple name to be updated.
read_tuple_id (id): New read tuple ID.
synchronize_widths (bool): Update widths (in accordance to this profile).


def _make_sent_vector(self, sent: List, bucket_length: int =None) -> np.ndarray:

        bucket_length = bucket_length or len(sent)
        answer = np.zeros(shape=(bucket_length, MAX_WORD_LENGTH+2), dtype=np.int32)
        for i, word in enumerate(sent):
            answer[i, 0] = self.tags.tok2idx("BEGIN")
            m = min(len(word), MAX_WORD_LENGTH)
            for j, x in enumerate(word[-m:]):
                answer[i, j+1] = self.symbols.tok2idx(x)
            answer[i, m+1] = self.tags.tok2idx("END")
            answer[i, m+2:] = self.tags.tok2idx("PAD")
        return answer

Transforms a sentence to Numpy array, which will be the network input.

Args:
sent: input sentence
bucket_length: the width of the bucket

Returns:
A 3d array, answer[i][j][k] contains the index of k-th letter
in j-th word of i-th input sentence.


def nCr(n, r):
    f = math.factorial
    return int(((f(n) / f(r)) / f((n - r))))

Calculates nCr.

Args:
n (int): total number of items.
r (int): items to choose

Returns:
nCr.


def get_site_energy(self, site_index):

        if self._charged:
            warn('Per atom energies for charged structures not supported in EwaldSummation')
        return np.sum(self._recip[:,site_index]) + np.sum(self._real[:,site_index]) \
            + self._point[site_index]

Compute the energy for a single site in the structure

Args:
site_index (int): Index of site
ReturnS:
(float) - Energy of that site


def get_airports(self, country):
    url = AIRPORT_BASE.format(country.replace(' ', '-'))
    return self._fr24.get_airports_data(url)

Returns a list of all the airports
For a given country this returns a list of dicts, one for each airport, with information like the iata code of the airport etc

Args:
country (str): The country for which the airports will be fetched

Example::

from pyflightdata import FlightData
f=FlightData()
f.get_airports('India')


def alias_inplace_add(x, i, v):
    return _inplace_helper(x, i, v, gen_array_ops.inplace_add)

Applies an inplace add on input x at index i with value v. Aliases x.

If i is None, x and v must be the same shape. Computes
x += v;
If i is a scalar, x has a rank 1 higher than v's. Computes
x[i, :] += v;
Otherwise, x and v must have the same rank. Computes
x[i, :] += v;

Args:
x: A Tensor.
i: None, a scalar or a vector.
v: A Tensor.

Returns:
Returns x.


def log_variables(variables=None):

  if variables is None:
    variables = tf.global_variables() + tf.local_variables()
  for row in format_variables(variables, join_lines=False):
    tf.logging.info(row)

Logs variable information.

This function logs the name, shape, type, collections, and device for either
all variables or a given iterable of variables. In the "Device" columns,
the nature of the variable (legacy or resource (for ResourceVariables)) is
also specified in parenthesis.

Args:
variables: iterable of variables; if not provided, then all variables
(in the default graph) are logged.


def to_tensorflow_dataset(evset: EventSet, timestamps: str='timestamp') -> 'tensorflow.data.Dataset':
    tf = import_tf()
    if len(evset.schema.indexes) != 0:
        evset = drop_index(evset)
    data = evset.get_arbitrary_index_data()
    dict_data = {timestamps: data.timestamps}
    for feature_idx, feature in enumerate(evset.schema.features):
        dict_data[feature.name] = data.features[feature_idx]
    return tf.data.Dataset.from_tensor_slices(dict_data)

Converts an [`EventSet`][temporian.EventSet] to a tensorflow Dataset.

Usage example:
```python
evset = event_set(
timestamps=[1, 2, 3, 4],
features={
"f1": [10, 11, 12, 13],
"f2": [b"a", b"b", b"c", b"d"],
"label": [0, 1, 0, 1],
},
)

tf_dataset = tp.to_tensorflow_dataset(evset)

def extract_label(example):
label = example.pop("label")
return example, label
tf_dataset = tf_dataset.map(extract_label).batch(100)

model = ... # A Keras model
model.fit(tf_dataset)
```

Args:
evset: Input event set.
timestamps: Output key containing the timestamps.

Returns:
TensorFlow dataset created from EventSet.


def min_sequence_length(self, dataset_split):

    return {
        problem.DatasetSplit.TRAIN: 8,
        problem.DatasetSplit.EVAL: 65,
        problem.DatasetSplit.TEST: 65
    }[dataset_split]

Determine the minimum sequence length given a dataset_split.

Args:
dataset_split: A problem.DatasetSplit.

Returns:
The minimum length that a sequence can be for this dataset_split.


def __init__(self, data_location=None):

    super(FormatterMediator, self).__init__()
    self._data_location = data_location
    self._language_identifier = self.DEFAULT_LANGUAGE_IDENTIFIER
    self._lcid = self.DEFAULT_LCID
    self._winevt_database_reader = None

Initializes a formatter mediator object.

Args:
data_location (str): path of the formatter data files.


def detail_poi(self, **kwargs):

        params = {
            'language': util.language_code(kwargs.get('lang')),
            'family': kwargs.get('family')
        }

        if kwargs.get('id'):
            params['id'] = kwargs['id']

        result = self.make_request('detail_poi', {}, **params)

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

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

Obtain detailed info of a given POI.

Args:
family (str): Family code of the POI (3 chars).
lang (str): Language code (*es* or *en*).
id (int): Optional, ID of the POI to query. Passing value -1 will
result in information from all POIs.

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


def serialize(self):
    segment = hangouts_pb2.Segment(type=self.type_, text=self.text, formatting=hangouts_pb2.Formatting(bold=self.is_bold, italic=self.is_italic, strikethrough=self.is_strikethrough, underline=self.is_underline))
    if (self.link_target is not None):
        segment.link_data.link_target = self.link_target
    return segment

Serialize this segment to a ``Segment`` message.

Returns:
``Segment`` message.


def unpack_grad_tuple(gv, gpt):
    elt_widths = [x.num_elements() for x in gpt.shapes]
    with tf.device(gv[0][0].device):
        with tf.name_scope('unpack'):
            splits = tf.split(gv[0], elt_widths)
            unpacked_gv = []
            for (idx, s) in enumerate(splits):
                unpacked_gv.append((tf.reshape(s, gpt.shapes[idx]), gpt.vars[idx]))
    return unpacked_gv

Unpack a previously packed collection of gradient tensors.

Args:
gv: A (grad, var) pair to be unpacked.
gpt: A GradPackTuple describing the packing operation that produced gv.

Returns:
A list of (grad, var) pairs corresponding to the values that were
originally packed into gv, maybe following subsequent operations like
reduction.


def days(value: Union[int, float]) -> Duration:
    return float(value * 60 * 60 * 24)

Converts input value from number of days to a `Duration` in seconds.

Example:
```python
>>> a = tp.event_set(
...    # Dates are converted to unix timestamps
...    timestamps=["2020-01-01", "2020-01-02", "2020-01-31"],
...    features={"f1": [1, 5, -5]}
... )

>>> a.moving_sum(window_length=tp.duration.days(2))
indexes: ...
timestamps: ['2020-01-01T00:00:00' '2020-01-02T00:00:00'
'2020-01-31T00:00:00']
'f1': [ 1 6 -5]
...

```

Args:
value: number of days.

Returns:
Equivalent number of seconds.


def addSearchers(self, *searchers):
    self._searchers.extend(searchers)
    ((debug.logger & debug.flagCompiler) and debug.logger(('current compiled MIBs location(s): %s' % ', '.join([str(x) for x in self._searchers]))))
    return self

Add more transformed MIBs repositories.

MibCompiler.compile will invoke each of configured searcher objects
in order of their addition asking each if already transformed MIB
module already exists and is more recent than specified.

Args:
searchers: searcher object(s)

Returns:
reference to itself (can be used for call chaining)


def create_module_graph(module_spec):

  height, width = hub.get_expected_image_size(module_spec)
  with tf.Graph().as_default() as graph:
    resized_input_tensor = tf.placeholder(tf.float32, [None, height, width, 3])
    m = hub.Module(module_spec)
    bottleneck_tensor = m(resized_input_tensor)
    wants_quantization = any(node.op in FAKE_QUANT_OPS
                             for node in graph.as_graph_def().node)
  return graph, bottleneck_tensor, resized_input_tensor, wants_quantization

Creates a graph and loads Hub Module into it.

Args:
module_spec: the hub.ModuleSpec for the image module being used.

Returns:
graph: the tf.Graph that was created.
bottleneck_tensor: the bottleneck values output by the module.
resized_input_tensor: the input images, resized as expected by the module.
wants_quantization: a boolean, whether the module has been instrumented
with fake quantization ops.


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

    installation_value = None
    string_values = {}
    for registry_value in registry_key.GetValues():

      if not registry_value.name:
        continue

      if (registry_value.name == 'InstallDate' and
          registry_value.DataIsInteger()):
        installation_value = registry_value
        continue

      if not registry_value.data or not registry_value.DataIsString():
        continue

      string_value_name = self._STRING_VALUE_NAME_STRINGS.get(
          registry_value.name, None)
      if not string_value_name:
        continue

      string_values[string_value_name] = registry_value.GetDataAsObject()

    values_dict = {}
    values_dict['Owner'] = string_values.get('owner', '')
    values_dict['Product name'] = string_values.get('product_name', '')
    values_dict['Service pack'] = string_values.get('service_pack', '')
    values_dict['Windows Version Information'] = string_values.get(
        'version', '')

    event_data = windows_events.WindowsRegistryEventData()
    event_data.key_path = registry_key.path
    event_data.offset = registry_key.offset
    event_data.regvalue = values_dict

    event = time_events.DateTimeValuesEvent(
        registry_key.last_written_time, definitions.TIME_DESCRIPTION_WRITTEN)
    parser_mediator.ProduceEventWithEventData(event, event_data)

    if installation_value:
      event_data = windows_events.WindowsRegistryInstallationEventData()
      event_data.key_path = registry_key.path
      event_data.offset = registry_key.offset
      event_data.owner = string_values.get('owner', None)
      event_data.product_name = string_values.get('product_name', None)
      event_data.service_pack = string_values.get('service_pack', None)
      event_data.version = string_values.get('version', None)

      installation_time = installation_value.GetDataAsObject()
      date_time = dfdatetime_posix_time.PosixTime(timestamp=installation_time)
      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_INSTALLATION)
      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 packtext(text, width=80):
    r
    import utool as ut
    import textwrap
    new_text = '\n'.join(textwrap.wrap(text, width))
    new_text = ut.remove_doublspaces(new_text).strip()
    return new_text

r"""
Args:
text (str):

CommandLine:
python -m utool.util_str --exec-pack_paragraph --show

Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import *  # NOQA
>>> import utool as ut
>>> width = 80
>>> text = lorium_ipsum()
>>> result = packtext(text)
>>> print(result)


def merge_and_fit(self, track, pairings):

        for (self_seg_index, track_seg_index, _) in pairings:
            self_s = self.segments[self_seg_index]
            ss_start = self_s.points[0]
            track_s = track.segments[track_seg_index]
            tt_start = track_s.points[0]
            tt_end = track_s.points[-1]

            d_start = ss_start.distance(tt_start)
            d_end = ss_start.distance(tt_end)

            if d_start > d_end:
                track_s = track_s.copy()
                track_s.points = list(reversed(track_s.points))

            self_s.merge_and_fit(track_s)
        return self

Merges another track with this one, ordering the points based on a
distance heuristic

Args:
track (:obj:`Track`): Track to merge with
pairings
Returns:
:obj:`Segment`: self


def get_metar(
            metar: typing.Union[str, 'CustomMetar']
    ) -> typing.Tuple[typing.Union[str, None], typing.Union['CustomMetar', None]]:

        error: typing.Optional[str] = None
        if isinstance(metar, CustomMetar):
            return None, metar

        if isinstance(metar, str):
            LOGGER.debug('building CustomMetar from: %s', metar)
            if len(metar) == 4:
                LOGGER.debug('retrieving METAR from ICAO')

                metar = AWC.query_icao(metar).raw_metar
        else:
            error = f'expected a string or or a CustomMetar object, got: {type(metar)}'

        if error:
            return error, None

        try:
            return None, CustomMetar(metar_code=metar)
        except ParserError:
            return f'Unable to parse METAR: {metar}', None

Builds a CustomMetar object from a CustomMetar object (returns it), an ICAO code or a METAR string

Args:
metar: CustomMetar object, ICAO string or METAR string

Returns: CustomMetar object


def _anonymize_table(cls, table_data, pii_fields):
    for pii_field in pii_fields:
        field_name = pii_field['name']
        transformer = cls.get_class(TRANSFORMERS['categorical'])(pii_field)
        table_data[field_name] = transformer.anonymize_column(table_data)
    return table_data

Anonymize in `table_data` the fields in `pii_fields`.

Args:
table_data (pandas.DataFrame): Original dataframe/table.
pii_fields (list[dict]): Metadata for the fields to transform.

Result:
pandas.DataFrame: Anonymized table.


def _embedding_lookup_for_ragged_tensor(self, inp: ragged_tensor.RaggedTensor, weight: Optional[ragged_tensor.RaggedTensor], table: tf_variables.Variable, feature: tpu_embedding_v2_utils.FeatureConfig) -> tensor.Tensor:
    if inp.shape.rank != 2:
        raise ValueError('Only rank 2 ragged tensor is supported, but got rank {}'.format(inp.shape.rank))
    batch_size = inp.shape[0]

    def ragged_to_dense_outside_compilation(inp, weight, batch_size, feature):
        if weight is None:
            weight = ragged_tensor.RaggedTensor.from_row_splits(array_ops.ones_like(inp.values, dtype=dtypes.float32), inp.row_splits)
        if not feature.output_shape and feature.max_sequence_length > 0:
            inp = inp.to_tensor(shape=(batch_size, feature.max_sequence_length))
            weight = array_ops.ones_like(inp, dtype=dtypes.float32)
        elif feature.output_shape:
            with ops.init_scope():
                output_batch_size = math_ops.reduce_prod(feature.output_shape).numpy()
            if output_batch_size == batch_size:
                inp, weight = (inp.to_tensor(), weight.to_tensor())
            elif output_batch_size > batch_size and output_batch_size % batch_size == 0:
                seq_length = output_batch_size
                inp = inp.to_tensor(shape=(batch_size, seq_length))
                weight = array_ops.ones_like(inp, dtype=dtypes.float32)
            else:
                raise ValueError('Output shape set in the FeatureConfig should be the factor of the input data batch size. But instead got output shape {}, input data batch size {}'.format(feature.output_shape, batch_size))
        else:
            inp, weight = (inp.to_tensor(), weight.to_tensor())
        return (inp, weight)
    inp, weight = tpu_replication.outside_compilation(ragged_to_dense_outside_compilation, inp=inp, weight=weight, batch_size=batch_size, feature=feature)
    embeddings = embedding_ops.embedding_lookup_v2(table, inp)
    weight = array_ops.expand_dims(weight, -1)
    embeddings *= weight
    if feature.output_shape:
        with ops.init_scope():
            output_batch_size = math_ops.reduce_prod(feature.output_shape).numpy()
        if output_batch_size == batch_size:
            embeddings = self._apply_combiner_to_embeddings(embeddings, weight, feature.table.combiner)
        embeddings = array_ops.reshape(embeddings, shape=feature.output_shape + [feature.table.dim])
    elif feature.max_sequence_length == 0:
        embeddings = self._apply_combiner_to_embeddings(embeddings, weight, feature.table.combiner)
    return embeddings

Embedding lookup for ragged tensor based on its feature config.

Args:
inp: a single rank 2 RaggedTensor input.
weight: None or RaggedTensor which has the same shape of the input.
table: a table variable.
feature: a feature config.

Returns:
Embedding lookup result.

Raises:
ValueError: if input ragged tensor is not rank 2 or output shape set in
the feature config doesn't match with the first dim size of the input.


def settings(package, reload_=False):

    global packages
    if package not in packages or reload_:
        from os import path
        result = CaseConfigParser()
        if package != "acorn":
            confpath = _package_path(package)
            _read_single(result, confpath)
        _read_single(result, _package_path("acorn"))
        packages[package] = result

    return packages[package]

Returns the config settings for the specified package.

Args:
package (str): name of the python package to get settings for.


def ReadSerializedDict(cls, json_dict):
    if json_dict:
        json_object = cls._ConvertDictToObject(json_dict)
        if (not isinstance(json_object, containers_interface.AttributeContainer)):
            raise TypeError('{0:s} is not an attribute container type.'.format(type(json_object)))
        return json_object
    return None

Reads an attribute container from serialized dictionary form.

Args:
json_dict (dict[str, object]): JSON serialized objects.

Returns:
AttributeContainer: attribute container or None.

Raises:
TypeError: if the serialized dictionary does not contain an
AttributeContainer.


def _to_live_trigger_log(self, **kwargs):

        field_names = (field.name for field in TriggerLogAbstract._meta.get_fields())
        attributes = {name: getattr(self, name) for name in field_names}
        del attributes['id']
        attributes.update(kwargs)
        return TriggerLog(**attributes)

Make a new, non-archived :class:`.TriggerLog` instance with duplicate data.

Args:
**kwargs: Set as attributes of the new instance, overriding what would otherwise be
copied from ``self``.

Returns:
The new (unpersisted) :class:`TriggerLog` instance.


def __init__(self, step_name, transform_id=None):
    self.step_name = step_name
    self.transform_id = transform_id

Creates a new step NameContext.

Args:
step_name: The name of the step.


def datasets_list(self, project_id=None, max_results=0, page_token=None):
    if (project_id is None):
        project_id = self._project_id
    url = (Api._ENDPOINT + (Api._DATASETS_PATH % (project_id, '')))
    args = {}
    if (max_results != 0):
        args['maxResults'] = max_results
    if (page_token is not None):
        args['pageToken'] = page_token
    return datalab.utils.Http.request(url, args=args, credentials=self._credentials)

Issues a request to list the datasets in the project.

Args:
project_id: the project id to use to fetch the results; use None for the default project.
max_results: an optional maximum number of tables to retrieve.
page_token: an optional token to continue the retrieval.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.


def _get_descending_key(gettime=time.time):

  now_descending = int((_FUTURE_TIME - gettime()) * 100)
  request_id_hash = os.environ.get("REQUEST_ID_HASH")
  if not request_id_hash:
    request_id_hash = str(random.getrandbits(32))
  return "%d%s" % (now_descending, request_id_hash)

Returns a key name lexically ordered by time descending.

This lets us have a key name for use with Datastore entities which returns
rows in time descending order when it is scanned in lexically ascending order,
allowing us to bypass index building for descending indexes.

Args:
gettime: Used for testing.

Returns:
A string with a time descending key.


def editline_with_regex(self, regex_tgtline, to_replace):

        for idx, line in enumerate(self._swp_lines):
            mobj = re.match(regex_tgtline, line)

            if mobj:
                self._swp_lines[idx] = to_replace

                return

find the first matched line, then replace

Args:
regex_tgtline (str): regular expression used to match the target line
to_replace    (str): line you wanna use to replace


def emit_pid(self, name: str, pid: int) -> None:
    event = {}
    event['name'] = 'process_name'
    event['ph'] = 'M'
    event['pid'] = pid
    event['args'] = {'name': name}
    self._metadata.append(event)

Adds a process metadata event to the trace.

Args:
name:  The process name as a string.
pid:  Identifier of the process as an integer.


def convert_reshape(params, w_name, scope_name, inputs, layers, weights, names):
    print('Converting reshape ...')
    if (names == 'short'):
        tf_name = ('RESH' + random_string(4))
    elif (names == 'keep'):
        tf_name = w_name
    else:
        tf_name = (w_name + str(random.random()))
    if (len(inputs) > 1):
        if (layers[inputs[1]][0] == (- 1)):
            print('Cannot deduct batch size! It will be omitted, but result may be wrong.')
        reshape = keras.layers.Reshape(layers[(inputs[1] + '_np')], name=tf_name)
        layers[scope_name] = reshape(layers[inputs[0]])
    elif (inputs[0] in layers):
        reshape = keras.layers.Reshape(params['shape'][1:], name=tf_name)
        layers[scope_name] = reshape(layers[inputs[0]])
    else:
        print('Skip weight matrix transpose, but result may be wrong.')

Convert reshape layer.

Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers


def visit(self, visitor, visitor_arg):
    visitor(self, visitor_arg)
    for t in self._inner_types():
        if isinstance(t, TypeConstraint):
            t.visit(visitor, visitor_arg)
        else:
            visitor(t, visitor_arg)

Visitor method to visit all inner types of a composite type.

Args:
visitor: A callable invoked for all nodes in the type tree comprising
a composite type. The visitor will be called with the node visited
and the visitor argument specified here.
visitor_arg: Visitor callback second argument.


def _align_monomer(self, monomer, mon_vector, move_direction):
    axis = np.cross(mon_vector, move_direction)
    origin = monomer[self.start].coords
    angle = get_angle(mon_vector, move_direction)
    op = SymmOp.from_origin_axis_angle(origin, axis, angle)
    monomer.apply_operation(op)

rotate the monomer so that it is aligned along the move direction

Args:
monomer (Molecule)
mon_vector (numpy.array): molecule vector that starts from the
start atom index to the end atom index
move_direction (numpy.array): the direction of the polymer chain
extension


def copy_submission_to_destination(self, src_filename, dst_subdir, submission_id):
    extension = [e for e in ALLOWED_EXTENSIONS if src_filename.endswith(e)]
    if (len(extension) != 1):
        logging.error('Invalid submission extension: %s', src_filename)
        return
    dst_filename = os.path.join(self.target_dir, dst_subdir, (submission_id + extension[0]))
    cmd = ['gsutil', 'cp', src_filename, dst_filename]
    if (subprocess.call(cmd) != 0):
        logging.error("Can't copy submission to destination")
    else:
        logging.info('Submission copied to: %s', dst_filename)

Copies submission to target directory.

Args:
src_filename: source filename of the submission
dst_subdir: subdirectory of the target directory where submission should
be copied to
submission_id: ID of the submission, will be used as a new
submission filename (before extension)


def make_ndarray(tensor):

    shape = [d.size for d in tensor.tensor_shape.dim]
    num_elements = np.prod(shape, dtype=np.int64)
    tensor_dtype = dtypes.as_dtype(tensor.dtype)
    dtype = tensor_dtype.as_numpy_dtype

    if tensor.tensor_content:
        return np.frombuffer(tensor.tensor_content, dtype=dtype).copy().reshape(shape)
    elif tensor_dtype == dtypes.float16 or tensor_dtype == dtypes.bfloat16:

        if len(tensor.half_val) == 1:
            tmp = np.array(tensor.half_val[0], dtype=np.uint16)
            tmp.dtype = tensor_dtype.as_numpy_dtype
            return np.repeat(tmp, num_elements).reshape(shape)
        else:
            tmp = np.fromiter(tensor.half_val, dtype=np.uint16)
            tmp.dtype = tensor_dtype.as_numpy_dtype
            return tmp.reshape(shape)
    elif tensor_dtype == dtypes.float32:
        if len(tensor.float_val) == 1:
            return np.repeat(
                np.array(tensor.float_val[0], dtype=dtype), num_elements
            ).reshape(shape)
        else:
            return np.fromiter(tensor.float_val, dtype=dtype).reshape(shape)
    elif tensor_dtype == dtypes.float64:
        if len(tensor.double_val) == 1:
            return np.repeat(
                np.array(tensor.double_val[0], dtype=dtype), num_elements
            ).reshape(shape)
        else:
            return np.fromiter(tensor.double_val, dtype=dtype).reshape(shape)
    elif tensor_dtype in [
        dtypes.int32,
        dtypes.uint8,
        dtypes.uint16,
        dtypes.int16,
        dtypes.int8,
        dtypes.qint32,
        dtypes.quint8,
        dtypes.qint8,
        dtypes.qint16,
        dtypes.quint16,
    ]:
        if len(tensor.int_val) == 1:
            return np.repeat(
                np.array(tensor.int_val[0], dtype=dtype), num_elements
            ).reshape(shape)
        else:
            return np.fromiter(tensor.int_val, dtype=dtype).reshape(shape)
    elif tensor_dtype == dtypes.int64:
        if len(tensor.int64_val) == 1:
            return np.repeat(
                np.array(tensor.int64_val[0], dtype=dtype), num_elements
            ).reshape(shape)
        else:
            return np.fromiter(tensor.int64_val, dtype=dtype).reshape(shape)
    elif tensor_dtype == dtypes.string:
        if len(tensor.string_val) == 1:
            return np.repeat(
                np.array(tensor.string_val[0], dtype=dtype), num_elements
            ).reshape(shape)
        else:
            return np.array([x for x in tensor.string_val], dtype=dtype).reshape(shape)
    elif tensor_dtype == dtypes.complex64:
        it = iter(tensor.scomplex_val)
        if len(tensor.scomplex_val) == 2:
            return np.repeat(
                np.array(
                    complex(tensor.scomplex_val[0], tensor.scomplex_val[1]), dtype=dtype
                ),
                num_elements,
            ).reshape(shape)
        else:
            return np.array(
                [complex(x[0], x[1]) for x in zip(it, it)], dtype=dtype
            ).reshape(shape)
    elif tensor_dtype == dtypes.complex128:
        it = iter(tensor.dcomplex_val)
        if len(tensor.dcomplex_val) == 2:
            return np.repeat(
                np.array(
                    complex(tensor.dcomplex_val[0], tensor.dcomplex_val[1]), dtype=dtype
                ),
                num_elements,
            ).reshape(shape)
        else:
            return np.array(
                [complex(x[0], x[1]) for x in zip(it, it)], dtype=dtype
            ).reshape(shape)
    elif tensor_dtype == dtypes.bool:
        if len(tensor.bool_val) == 1:
            return np.repeat(
                np.array(tensor.bool_val[0], dtype=dtype), num_elements
            ).reshape(shape)
        else:
            return np.fromiter(tensor.bool_val, dtype=dtype).reshape(shape)
    else:
        raise TypeError("Unsupported tensor type: %s" % tensor.dtype)

Create a numpy ndarray from a tensor.

Create a numpy ndarray with the same shape and data as the tensor.

Args:
tensor: A TensorProto.

Returns:
A numpy array with the tensor contents.

Raises:
TypeError: if tensor has unsupported type.


def _get_next_task_from_raylet(self):
    with profiling.profile('worker_idle'):
        task = self.raylet_client.get_task()
    ray.utils.set_cuda_visible_devices(ray.get_gpu_ids())
    return task

Get the next task from the raylet.

Returns:
A task from the raylet.


def build_case(case, vcf_individuals=None, case_id=None, vcf_path=None, sv_individuals=None, vcf_sv_path=None, nr_variants=None, nr_sv_variants=None, profiles=None, matches=None, profile_path=None):
    individual_positions = get_individual_positions(vcf_individuals)
    sv_individual_positions = get_individual_positions(sv_individuals)
    family_id = None
    if case:
        if (not case.affected_individuals):
            LOG.warning('No affected individuals could be found in ped file')
        family_id = case.family_id
    case_id = (case_id or family_id)
    if (case_id is None):
        raise CaseError
    case_obj = Case(case_id=case_id)
    if vcf_path:
        case_obj['vcf_path'] = vcf_path
        case_obj['nr_variants'] = nr_variants
    if vcf_sv_path:
        case_obj['vcf_sv_path'] = vcf_sv_path
        case_obj['nr_sv_variants'] = nr_sv_variants
    if profile_path:
        case_obj['profile_path'] = profile_path
    ind_objs = []
    if case:
        if individual_positions:
            _ind_pos = individual_positions
        else:
            _ind_pos = sv_individual_positions
        for ind_id in case.individuals:
            individual = case.individuals[ind_id]
            try:
                profile = (profiles[ind_id] if profiles else None)
                similar_samples = (matches[ind_id] if matches else None)
                ind_obj = Individual(ind_id=ind_id, case_id=case_id, ind_index=_ind_pos[ind_id], sex=individual.sex, profile=profile, similar_samples=similar_samples)
                ind_objs.append(dict(ind_obj))
            except KeyError:
                raise CaseError('Ind %s in ped file does not exist in VCF', ind_id)
    else:
        for ind_id in individual_positions:
            profile = (profiles[ind_id] if profiles else None)
            similar_samples = (matches[ind_id] if matches else None)
            ind_obj = Individual(ind_id=ind_id, case_id=case_id, ind_index=individual_positions[ind_id], profile=profile, similar_samples=similar_samples)
            ind_objs.append(dict(ind_obj))
    for ind_obj in ind_objs:
        if vcf_sv_path:
            case_obj['sv_individuals'].append(dict(ind_obj))
            case_obj['_sv_inds'][ind_obj['ind_id']] = dict(ind_obj)
        if vcf_path:
            case_obj['individuals'].append(dict(ind_obj))
            case_obj['_inds'][ind_obj['ind_id']] = dict(ind_obj)
    return case_obj

Build a Case from the given information

Args:
case(ped_parser.Family): A family object
vcf_individuals(list): Show the order of inds in vcf file
case_id(str): If another name than the one in family file should be used
vcf_path(str)
sv_individuals(list): Show the order of inds in vcf file
vcf_sv_path(str)
nr_variants(int)
nr_sv_variants(int)
profiles(dict): The profiles for each sample in vcf
matches(dict(list)): list of similar samples for each sample in vcf.

Returns:
case_obj(models.Case)


def any_sparse(classes):
    return any((c is sparse_tensor.SparseTensor for c in nest.flatten(classes)))

Checks for sparse tensor.

Args:
classes: a structure of objects that identify the dataset item classes

Returns:
`True` if `classes` contains a sparse tensor type and `False` otherwise.


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

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

        self._unique_identifier = None
        self._usage_limits_count = None

        self.unique_identifier = unique_identifier
        self.usage_limits_count = usage_limits_count

Construct a GetUsageAllocation request payload struct.

Args:
unique_identifier (string): The ID of the managed object (e.g.,
a public key) to obtain a usage allocation for. Optional,
defaults to None.
usage_limits_count (int): The number of usage limits units that
should be reserved for the object. Optional, defaults to None.


def from_string(cls, cl_function, dependencies=()):

        return_type, function_name, parameter_list, body = split_cl_function(cl_function)
        return SimpleCLFunction(return_type, function_name, parameter_list, body, dependencies=dependencies)

Parse the given CL function into a SimpleCLFunction object.

Args:
cl_function (str): the function we wish to turn into an object
dependencies (list or tuple of CLLibrary): The list of CL libraries this function depends on

Returns:
SimpleCLFunction: the CL data type for this parameter declaration


def write_int16(self, value, little_endian=True):
    if little_endian:
        endian = '<'
    else:
        endian = '>'
    return self.pack(('%sh' % endian), value)

Pack the value as a signed integer and write 2 bytes to the stream.

Args:
value:
little_endian (bool): specify the endianness. (Default) Little endian.

Returns:
int: the number of bytes written.


def _load_audio_list(self, path):

        result = {}

        for entry in textfile.read_separated_lines_generator(path, separator='\t', max_columns=4):
            for i in range(len(entry)):
                if entry[i] == '\\N':
                    entry[i] = None

            if len(entry) < 4:
                entry.extend([None] * (4 - len(entry)))

            if not self.include_empty_licence and entry[2] is None:
                continue

            if self.include_licenses is not None and entry[2] not in self.include_licenses:
                continue

            result[entry[0]] = entry[1:]

        return result

Load and filter the audio list.

Args:
path (str): Path to the audio list file.

Returns:
dict: Dictionary of filtered sentences (id : username, license, attribution-url)


def commit_signature(vcs, user_config, signature):

    if signature not in get_staged_signatures(vcs):
        raise NotStagedError
    evidence_path = _get_committed_history_path(vcs)
    committed_signatures = get_committed_signatures(vcs)
    if signature in committed_signatures:
        raise AlreadyCommittedError
    committed_signatures.append(signature)
    string = '\n'.join(committed_signatures[-user_config['history_limit']:])
    with open(evidence_path, 'w') as f:
        f.write(string)
    unstage_signature(vcs, signature)

Add `signature` to the list of committed signatures

The signature must already be staged

Args:
vcs (easyci.vcs.base.Vcs)
user_config (dict)
signature (basestring)

Raises:
NotStagedError
AlreadyCommittedError


def get(self, entity, key):
    if entity in self._store:
        return self._store[entity].get(str(key))
    return None

Gets and item from the cache.

Args:
entity: The entity cache to use.
key: The key to use to lookup the cached item.


def ParseRecord(self, parser_mediator, key, structure):

    if key not in ('logline', 'no_header_single_line'):
      raise errors.ParseError(
          'Unable to parse record, unknown structure: {0:s}'.format(key))

    if key == 'logline':
      self._ParseLogline(parser_mediator, structure)

    elif key == 'no_header_single_line':
      self._ParseNoHeaderSingleLine(parser_mediator, structure)

Parse each record structure and return an EventObject if applicable.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
key (str): identifier of the structure of tokens.
structure (pyparsing.ParseResults): structure of tokens derived from
a line of a text file.

Raises:
ParseError: when the structure type is unknown.


def _verify_docker_image_size(self, image_name):
    shell_call(['docker', 'pull', image_name])
    try:
        image_size = subprocess.check_output(['docker', 'inspect', '--format={{.Size}}', image_name]).strip()
        image_size = int(image_size)
    except (ValueError, subprocess.CalledProcessError) as e:
        logging.error('Failed to determine docker image size: %s', e)
        return False
    logging.info('Size of docker image %s is %d', image_name, image_size)
    if (image_size > MAX_DOCKER_IMAGE_SIZE):
        logging.error('Image size exceeds limit %d', MAX_DOCKER_IMAGE_SIZE)
    return (image_size <= MAX_DOCKER_IMAGE_SIZE)

Verifies size of Docker image.

Args:
image_name: name of the Docker image.

Returns:
True if image size is within the limits, False otherwise.


def createURL(self, word, mode="phonefy"):

        try:
            return self.modes[mode]["url"].format(placeholder=urllib.pathname2url(word))
        except:
            if mode == "base":
                if word[0] == "/":
                    return self.baseURL+word[1:], word
                else:
                    return self.baseURL+word
            else:
                try:
                    return self.url[mode].replace("<"+mode+">", urllib.pathname2url(word))
                except:
                    pass
        return None

Method to create the URL replacing the word in the appropriate URL.

Args:
-----
word: Word to be searched.
mode: Mode to be executed.

Return:
-------
The URL to be queried.


def encode(self, sequence):

        sequence = super().encode(sequence)
        sequence = self.tokenize(sequence)
        vector = [self.stoi.get(token, self.unknown_index) for token in sequence]
        if self.append_eos:
            vector.append(self.eos_index)
        return torch.tensor(vector)

Encodes a ``sequence``.

Args:
sequence (str): String ``sequence`` to encode.

Returns:
torch.Tensor: Encoding of the ``sequence``.


def delete(self, vid):

        command = 'no vlan %s' % vid
        return self.configure(command) if isvlan(vid) else False

Deletes a VLAN from the running configuration

Args:
vid (str): The VLAN ID to delete

Returns:
True if the operation was successful otherwise False


def get_device(ads, **kwargs):
    filtered = get_devices(ads, **kwargs)
    if len(filtered) == 1:
        return filtered[0]
    else:
        serials = [ad.serial for ad in filtered]
        raise Error('More than one device matched: %s' % serials)

Finds a unique AndroidDevice instance from a list that has specific
attributes of certain values.

Example:
get_device(android_devices, label='foo', phone_number='1234567890')
get_device(android_devices, model='angler')

Args:
ads: A list of AndroidDevice instances.
kwargs: keyword arguments used to filter AndroidDevice instances.

Returns:
The target AndroidDevice instance.

Raises:
Error: None or more than one device is matched.


def __init__(self, in_features: int, lateral_widths: List[int], feature_size: int=256):
    super().__init__()
    self.stem = MaskFormerFPNConvLayer(in_features, feature_size)
    self.layers = nn.Sequential(*[MaskFormerFPNLayer(feature_size, lateral_width) for lateral_width in lateral_widths[::-1]])

Feature Pyramid Network, given an input tensor and a set of feature map of different feature/spatial size, it
creates a list of feature maps with the same feature size.

Args:
in_features (`int`):
The number of input features (channels).
lateral_widths (`List[int]`):
A list with the features (channels) size of each lateral connection.
feature_size (int, *optional*, defaults to 256):
The features (channels) of the resulting feature maps.


def ParseFileObject(self, parser_mediator, file_object):
    self._last_charset_attribute = 'ascii'
    self._ParseHeader(parser_mediator, file_object)
    data_dict = {}
    time_dict = {}
    try:
        for (name, value) in self._ParseAttributesGroup(file_object):
            name = self._ATTRIBUTE_NAME_TRANSLATION.get(name, name)
            if (name in self._DATE_TIME_VALUE_NAMES):
                time_dict.setdefault(name, []).append(value)
            else:
                data_dict.setdefault(name, []).append(value)
    except (ValueError, errors.ParseError) as exception:
        parser_mediator.ProduceExtractionWarning('unable to parse attributes with error: {0!s}'.format(exception))
        return
    event_data = CupsIppEventData()
    event_data.application = self._GetStringValue(data_dict, 'application')
    event_data.computer_name = self._GetStringValue(data_dict, 'computer_name')
    event_data.copies = data_dict.get('copies', [0])[0]
    event_data.data_dict = data_dict
    event_data.doc_type = self._GetStringValue(data_dict, 'doc_type')
    event_data.job_id = self._GetStringValue(data_dict, 'job_id')
    event_data.job_name = self._GetStringValue(data_dict, 'job_name')
    event_data.user = self._GetStringValue(data_dict, 'user')
    event_data.owner = self._GetStringValue(data_dict, 'owner')
    event_data.printer_id = self._GetStringValue(data_dict, 'printer_id')
    event_data.uri = self._GetStringValue(data_dict, 'uri')
    for (name, usage) in iter(self._DATE_TIME_VALUES.items()):
        for date_time in time_dict.get(name, []):
            event = time_events.DateTimeValuesEvent(date_time, usage)
            parser_mediator.ProduceEventWithEventData(event, event_data)
    for (name, usage) in iter(self._POSIX_TIME_VALUES.items()):
        for time_value in time_dict.get(name, []):
            date_time = dfdatetime_posix_time.PosixTime(timestamp=time_value)
            event = time_events.DateTimeValuesEvent(date_time, usage)
            parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a CUPS IPP 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.

Raises:
UnableToParseFile: when the file cannot be parsed.


def create_token_type_ids_from_sequences(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
    sep = [self.sep_token_id]
    cls = [self.cls_token_id]
    if token_ids_1 is None:
        return len(cls + token_ids_0 + sep) * [0]
    return len(cls + token_ids_0 + sep + sep + token_ids_1 + sep) * [0]

Args:
Create a mask from the two sequences passed to be used in a sequence-pair classification task. RoBERTa does not:
make use of token type ids, therefore a list of zeros is returned.
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
Returns:
`List[int]`: List of zeros.


def _build_map(inputs, outputs):
    finished_nodes = set()
    nodes_in_progress = set()
    nodes_in_decreasing_depth = []
    operation_indices = {}
    for output in tree.flatten(outputs):
        _build_map_helper(inputs, output, finished_nodes, nodes_in_progress, nodes_in_decreasing_depth, operation_indices)
    return (nodes_in_decreasing_depth, operation_indices)

Topologically sort nodes in order from inputs to outputs.

It uses a depth-first search to topologically sort nodes that appear in the
_keras_history connectivity metadata of `outputs`.

Args:
outputs: the output tensors whose _keras_history metadata should be
walked. This may be an arbitrary nested structure.

Returns:
A tuple like (ordered_nodes, operation_to_first_traversal_index)
ordered_nodes: list of nodes appearing in the keras history,
topologically sorted from original inputs to the `outputs`.
(If outputs have different sets of ancestors, the inputs to one
output may appear after a different output).
operation_to_first_traversal_index:
A dict mapping operation to the traversal index in the DFS where it
is seen. Note: if a operation is shared by several nodes, the dict
will onlystore the index corresponding to the *first* time the
operation seen.


def is_spontaneous(gene, custom_id=None):

    spont = re.compile("[Ss](_|)0001")
    if spont.match(gene.id):
        return True
    elif gene.id == custom_id:
        return True
    else:
        return False

Input a COBRApy Gene object and check if the ID matches a spontaneous ID regex.

Args:
gene (Gene): COBRApy Gene
custom_id (str): Optional custom spontaneous ID if it does not match the regular expression ``[Ss](_|)0001``

Returns:
bool: If gene ID matches spontaneous ID


def backups(self):
    if (not self.__backups):
        self.__backups = Backups(self.__connection)
    return self.__backups

Gets the Backup API client.

Returns:
Backups:


def Pack(cls, obj, version):
    if isinstance(obj, (datetime.datetime, datetime.date)):
        return cls.AdManagerDateTimePacker(obj, version)
    return obj

Pack the given object using Ad Manager-specific logic.

Args:
obj: an object to be packed for SOAP using Ad Manager-specific logic, if
applicable.
version: the version of the current API, e.g. 'v201811'

Returns:
The given object packed with Ad Manager-specific logic for SOAP,
if applicable. Otherwise, returns the given object unmodified.


def write_config_files(self, host, hyperparameters, input_data_config):

        config_path = os.path.join(self.container_root, host, 'input', 'config')

        resource_config = {
            'current_host': host,
            'hosts': self.hosts
        }

        json_input_data_config = {}
        for c in input_data_config:
            channel_name = c['ChannelName']
            json_input_data_config[channel_name] = {
                'TrainingInputMode': 'File'
            }
            if 'ContentType' in c:
                json_input_data_config[channel_name]['ContentType'] = c['ContentType']

        _write_json_file(os.path.join(config_path, 'hyperparameters.json'), hyperparameters)
        _write_json_file(os.path.join(config_path, 'resourceconfig.json'), resource_config)
        _write_json_file(os.path.join(config_path, 'inputdataconfig.json'), json_input_data_config)

Write the config files for the training containers.

This method writes the hyperparameters, resources and input data configuration files.

Args:
host (str): Host to write the configuration for
hyperparameters (dict): Hyperparameters for training.
input_data_config (dict): Training input channels to be used for training.

Returns: None


def get_pluggable_module_information(self, id_or_uri):
    uri = (self._client.build_uri(id_or_uri) + '/pluggableModuleInformation')
    return self._client.get(uri)

Gets all the pluggable module information.

Args:
id_or_uri: Can be either the interconnect id or uri.

Returns:
array: dicts of the pluggable module information.


def _get_manager(cluster_info, host, executor_id):
    for node in cluster_info:
        if ((node['host'] == host) and (node['executor_id'] == executor_id)):
            addr = node['addr']
            authkey = node['authkey']
            TFSparkNode.mgr = TFManager.connect(addr, authkey)
            break
    if (TFSparkNode.mgr is None):
        msg = ((('No TFManager found on this node, please ensure that:\n' + '1. Spark num_executors matches TensorFlow cluster_size\n') + '2. Spark cores/tasks per executor is 1.\n') + '3. Spark dynamic allocation is disabled.')
        raise Exception(msg)
    logging.info('Connected to TFSparkNode.mgr on {0}, executor={1}, state={2}'.format(host, executor_id, str(TFSparkNode.mgr.get('state'))))
    return TFSparkNode.mgr

Returns this executor's "singleton" instance of the multiprocessing.Manager, reconnecting per python-worker if needed.

Args:
:cluster_info: cluster node reservations
:host: host IP address
:executor_id: unique id per executor (created during initial call to run())

Returns:
TFManager instance for this executor/python-worker


def get_prep_value(self, value: LocalizedValue) -> dict:
    if isinstance(value, dict):
        value = LocalizedValue(value)
    if ((not isinstance(value, LocalizedValue)) and value):
        value = None
    if value:
        cleaned_value = self.clean(value)
        self.validate(cleaned_value)
    else:
        cleaned_value = value
    return super(LocalizedField, self).get_prep_value((cleaned_value.__dict__ if cleaned_value else None))

Turns the specified value into something the database
can store.

If an illegal value (non-LocalizedValue instance) is
specified, we'll treat it as an empty :see:LocalizedValue
instance, on which the validation will fail.

Dictonaries are converted into :see:LocalizedValue instances.

Arguments:
value:
The :see:LocalizedValue instance to serialize
into a data type that the database can understand.

Returns:
A dictionary containing a key for every language,
extracted from the specified value.


def __init__(self, input_fn, input_workers, input_contexts, strategy):
    assert isinstance(input_workers, input_lib.InputWorkers)
    if input_workers.num_workers != len(input_contexts):
        raise ValueError('Number of input workers (%d) is not same as number of input_contexts (%d)' % (input_workers.num_workers, len(input_contexts)))
    iterators = []
    for i, ctx in enumerate(input_contexts):
        worker = input_workers.worker_devices[i]
        with ops.device(worker):
            result = input_fn(ctx)
            devices = input_workers.compute_devices_for_worker(i)
            if isinstance(result, data_types.DatasetV2):
                iterator = _SingleWorkerDatasetIterator(result, worker, devices)
            elif callable(result):
                iterator = _SingleWorkerCallableIterator(result, worker, devices)
            else:
                raise ValueError('input_fn must return a tf.data.Dataset or a callable.')
            iterators.append(iterator)
    super(InputFunctionIterator, self).__init__(input_workers, iterators, strategy, cardinality=cardinality_lib.UNKNOWN, enable_get_next_as_optional=False)
    self._enable_get_next_as_optional = False

Make an iterator for input provided via an input function.

Currently implements PER_WORKER mode, in which the `input_fn` is called
once on each worker.

TODO(priyag): Add other replication modes.

Args:
input_fn: Input function that returns a `tf.data.Dataset` object.
input_workers: an `InputWorkers` object.
input_contexts: A list of `InputContext` instances to be passed to call(s)
to `input_fn`. Length and order should match worker order in
`worker_device_pairs`.
strategy: a `tf.distribute.Strategy` object, used to run all-reduce to
handle last partial batch.


def _right_pad(x, final_rank):
    padded_shape = tf.concat([tf.shape(input=x), tf.ones((final_rank - tf.rank(x)), dtype=tf.int32)], axis=0)
    static_padded_shape = None
    if (x.shape.is_fully_defined() and isinstance(final_rank, int)):
        static_padded_shape = x.shape.as_list()
        extra_dims = (final_rank - len(static_padded_shape))
        static_padded_shape.extend(([1] * extra_dims))
    padded_x = tf.reshape(x, (static_padded_shape or padded_shape))
    return padded_x

Pads the shape of x to the right to be of rank final_rank.

Expands the dims of `x` to the right such that its rank is equal to
final_rank. For example, if `x` is of shape [1, 5, 7, 2] and `final_rank` is
7, we return padded_x, which is of shape [1, 5, 7, 2, 1, 1, 1].

Args:
x: The tensor whose shape is to be padded.
final_rank: Scalar int32 `Tensor` or Python `int`. The desired rank of x.

Returns:
padded_x: A tensor of rank final_rank.


def from_bytes(value):
    result = (value.decode('utf-8') if isinstance(value, six.binary_type) else value)
    if isinstance(result, six.text_type):
        return result
    else:
        raise ValueError('{0!r} could not be converted to unicode'.format(value))

Converts bytes to a string value, if necessary.

Args:
value (Union[str, bytes]): The value to be converted.

Returns:
str: The original value converted to unicode (if bytes) or as passed in
if it started out as unicode.

Raises:
ValueError: If the value could not be converted to unicode.


def set_servo_speed(self, goalspeed, led):

        if goalspeed>0 :
            goalspeed_msb = (int(goalspeed)& 0xFF00) >> 8
            goalspeed_lsb = int(goalspeed) & 0xff
        elif goalspeed<0 :
            goalspeed_msb = 64+(255- ((int(goalspeed)& 0xFF00) >> 8))
            goalspeed_lsb = (abs(goalspeed) & 0xff)

        data = []
        data.append(0x0C)
        data.append(self.servoid)
        data.append(I_JOG_REQ)
        data.append(goalspeed_lsb)
        data.append(goalspeed_msb)
        data.append(0x02|led)
        data.append(self.servoid)
        data.append(0x00)
        send_data(data)

Set the Herkulex in continuous rotation mode

Args:

goalspeed (int): the speed , range -1023 to 1023
led (int): the LED color
0x00 LED off
0x04 GREEN
0x08 BLUE
0x10 RED


def GetEntries(self, parser_mediator, match=None, **unused_kwargs):
    device_cache = match.get('DeviceCache', {})
    for (device, value) in iter(device_cache.items()):
        name = value.get('Name', '')
        if name:
            name = ''.join(('Name:', name))
        event_data = plist_event.PlistTimeEventData()
        event_data.root = '/DeviceCache'
        datetime_value = value.get('LastInquiryUpdate', None)
        if datetime_value:
            event_data.desc = ' '.join(filter(None, ('Bluetooth Discovery', name)))
            event_data.key = '{0:s}/LastInquiryUpdate'.format(device)
            event = time_events.PythonDatetimeEvent(datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
            parser_mediator.ProduceEventWithEventData(event, event_data)
            if (device in match.get('PairedDevices', [])):
                event_data.desc = 'Paired:True {0:s}'.format(name)
                event_data.key = device
                event = time_events.PythonDatetimeEvent(datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
                parser_mediator.ProduceEventWithEventData(event, event_data)
        datetime_value = value.get('LastNameUpdate', None)
        if datetime_value:
            event_data.desc = ' '.join(filter(None, ('Device Name Set', name)))
            event_data.key = '{0:s}/LastNameUpdate'.format(device)
            event = time_events.PythonDatetimeEvent(datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
            parser_mediator.ProduceEventWithEventData(event, event_data)
        datetime_value = value.get('LastServicesUpdate', None)
        if datetime_value:
            event_data.desc = ' '.join(filter(None, ('Services Updated', name)))
            event_data.key = '{0:s}/LastServicesUpdate'.format(device)
            event = time_events.PythonDatetimeEvent(datetime_value, definitions.TIME_DESCRIPTION_WRITTEN)
            parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts relevant BT entries.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS.


def reactions_add(self, *, name: str, **kwargs) -> SlackResponse:
    kwargs.update({'name': name})
    return self.api_call('reactions.add', json=kwargs)

Adds a reaction to an item.

Args:
name (str): Reaction (emoji) name. e.g. 'thumbsup'
channel (str): Channel where the message to add reaction to was posted.
e.g. 'C1234567890'
timestamp (str): Timestamp of the message to add reaction to. e.g. '1234567890.123456'


def unsplat(f: Callable[([Iterable], A)]) -> Callable[(..., A)]:

    def unsplatted(*args):
        return f(args)
    return unsplatted

Convert a function taking a single iterable argument into a function taking multiple arguments.

Args:
f: Any function taking a single iterable argument

Returns:
A function that accepts multiple arguments. Each argument of this function is passed as an element of an
iterable to ``f``.

Example:
$ def f(a):
$     return a[0] + a[1] + a[2]
$
$ f([1, 2, 3])  # 6
$ g = unsplat(f)
$ g(1, 2, 3)  # 6


def get_full_filename_by_suffixes(dir_src, suffixes):

        file_names = FileClass.get_filename_by_suffixes(dir_src, suffixes)
        if file_names is None:
            return None
        return list(dir_src + os.sep + name for name in file_names)

get full file names with the given suffixes in the given directory

Args:
dir_src: directory path
suffixes: wanted suffixes

Returns:
full file names with the given suffixes as list


def sign(check_request):
    if (not isinstance(check_request, sc_messages.CheckRequest)):
        raise ValueError(u'Invalid request')
    op = check_request.operation
    if ((op is None) or (op.operationName is None) or (op.consumerId is None)):
        logging.error(u'Bad %s: not initialized => not signed', check_request)
        raise ValueError(u'check request must be initialized with an operation')
    md5 = hashlib.md5()
    md5.update(op.operationName.encode('utf-8'))
    md5.update(b'\x00')
    md5.update(op.consumerId.encode('utf-8'))
    if op.labels:
        signing.add_dict_to_hash(md5, encoding.MessageToPyValue(op.labels))
    for value_set in op.metricValueSets:
        md5.update(b'\x00')
        md5.update(value_set.metricName.encode('utf-8'))
        for mv in value_set.metricValues:
            metric_value.update_hash(md5, mv)
    md5.update(b'\x00')
    if op.quotaProperties:
        md5.update(repr(op.quotaProperties).encode('utf-8'))
    md5.update(b'\x00')
    return md5.digest()

Obtains a signature for an operation in a `CheckRequest`

Args:
op (:class:`endpoints_management.gen.servicecontrol_v1_messages.Operation`): an
operation used in a `CheckRequest`

Returns:
string: a secure hash generated from the operation


def LineWrap(text, omit_sgr=False):

  def _SplitWithSgr(text_line):

    token_list = sgr_re.split(text_line)
    text_line_list = []
    line_length = 0
    for (index, token) in enumerate(token_list):

      if token is '':
        continue

      if sgr_re.match(token):

        text_line_list.append(token)
        text_line = ''.join(token_list[index +1:])
      else:
        if line_length + len(token) <= width:

          text_line_list.append(token)
          line_length += len(token)
          text_line = ''.join(token_list[index +1:])
        else:

          text_line_list.append(token[:width - line_length])
          text_line = token[width - line_length:]
          text_line += ''.join(token_list[index +1:])
          break

    return (''.join(text_line_list), text_line)

  (_, width) = TerminalSize()
  text = str(text)
  text_multiline = []
  for text_line in text.splitlines():

    while ((omit_sgr and (len(StripAnsiText(text_line)) > width)) or
           (len(text_line) > width)):

      if not omit_sgr:
        text_multiline.append(text_line[:width])
        text_line = text_line[width:]
      else:
        (multiline_line, text_line) = _SplitWithSgr(text_line)
        text_multiline.append(multiline_line)
    if text_line:
      text_multiline.append(text_line)
  return '\n'.join(text_multiline)

Break line to fit screen width, factoring in ANSI/SGR escape sequences.

Args:
text: String to line wrap.
omit_sgr: Bool, to omit counting ANSI/SGR sequences in the length.

Returns:
Text with additional line wraps inserted for lines grater than the width.


async def _on_state_update(self, state_update):

        notification_type = state_update.WhichOneof('state_update')

        if state_update.HasField('conversation'):
            try:
                await self._handle_conversation_delta(
                    state_update.conversation
                )
            except exceptions.NetworkError:
                logger.warning(
                    'Discarding %s for %s: Failed to fetch conversation',
                    notification_type.replace('_', ' '),
                    state_update.conversation.conversation_id.id
                )
                return

        if notification_type == 'typing_notification':
            await self._handle_set_typing_notification(
                state_update.typing_notification
            )
        elif notification_type == 'watermark_notification':
            await self._handle_watermark_notification(
                state_update.watermark_notification
            )
        elif notification_type == 'event_notification':
            await self._on_event(
                state_update.event_notification.event
            )

Receive a StateUpdate and fan out to Conversations.

Args:
state_update: hangouts_pb2.StateUpdate instance


def cmd_ssh_user(tar_aminame, inst_name):

    if tar_aminame == "Unknown":
        tar_aminame = inst_name

    userlu = {"ubunt": "ubuntu", "debia": "admin", "fedor": "root",
              "cento": "centos", "openb": "root"}
    usertemp = ['name'] + [value for key, value in list(userlu.items())
                           if key in tar_aminame.lower()]
    usertemp = dict(zip(usertemp[::2], usertemp[1::2]))
    username = usertemp.get('name', 'ec2-user')
    debg.dprint("loginuser Calculated: ", username)
    return username

Calculate instance login-username based on image-name.

Args:
tar_aminame (str): name of the image instance created with.
inst_name (str): name of the instance.
Returns:
username (str): name for ssh based on AMI-name.


def get_users(self, capacity=None):
    users = list()
    usersdicts = self.data.get('users')
    if (usersdicts is not None):
        for userdata in usersdicts:
            if ((capacity is not None) and (userdata['capacity'] != capacity)):
                continue
            id = userdata.get('id')
            if (id is None):
                id = userdata['name']
            user = hdx.data.user.User.read_from_hdx(id, configuration=self.configuration)
            user['capacity'] = userdata['capacity']
            users.append(user)
    return users

Returns the organization's users.

Args:
capacity (Optional[str]): Filter by capacity eg. member, admin. Defaults to None.
Returns:
List[User]: Organization's users.


def to_text_diagram(
            self,
            *,
            use_unicode_characters: bool = True,
            transpose: bool = False,
            precision: Optional[int] = 3,
            qubit_order: ops.QubitOrderOrList = ops.QubitOrder.DEFAULT) -> str:

        diagram = self.to_text_diagram_drawer(
            use_unicode_characters=use_unicode_characters,
            precision=precision,
            qubit_order=qubit_order,
            transpose=transpose)

        return diagram.render(
            crossing_char=(None
                           if use_unicode_characters
                           else ('-' if transpose else '|')),
            horizontal_spacing=1 if transpose else 3,
            use_unicode_characters=use_unicode_characters)

Returns text containing a diagram describing the circuit.

Args:
use_unicode_characters: Determines if unicode characters are
allowed (as opposed to ascii-only diagrams).
transpose: Arranges qubit wires vertically instead of horizontally.
precision: Number of digits to display in text diagram
qubit_order: Determines how qubits are ordered in the diagram.

Returns:
The text diagram.


def _PrintStorageInformationAsText(self, storage_reader):
    table_view = views.ViewsFactory.GetTableView(self._views_format_type, title='Plaso Storage Information')
    table_view.AddRow(['Filename', os.path.basename(self._storage_file_path)])
    table_view.AddRow(['Format version', storage_reader.format_version])
    table_view.AddRow(['Serialization format', storage_reader.serialization_format])
    table_view.Write(self._output_writer)
    if (storage_reader.storage_type == definitions.STORAGE_TYPE_SESSION):
        self._PrintSessionsOverview(storage_reader)
        self._PrintSessionsDetails(storage_reader)
        storage_counters = self._CalculateStorageCounters(storage_reader)
        if ('parsers' not in storage_counters):
            self._output_writer.Write('Unable to determine number of events generated per parser.\n')
        else:
            self._PrintParsersCounter(storage_counters['parsers'])
        if ('analysis_reports' not in storage_counters):
            self._output_writer.Write('Unable to determine number of reports generated per plugin.\n')
        else:
            self._PrintAnalysisReportCounter(storage_counters['analysis_reports'])
        if ('event_labels' not in storage_counters):
            self._output_writer.Write('Unable to determine number of event tags generated per label.\n')
        else:
            self._PrintEventLabelsCounter(storage_counters['event_labels'])
        self._PrintWarningCounters(storage_counters)
        if self._verbose:
            self._PrintWarningsDetails(storage_reader)
        self._PrintAnalysisReportsDetails(storage_reader)
    elif (storage_reader.storage_type == definitions.STORAGE_TYPE_TASK):
        self._PrintTasksInformation(storage_reader)

Prints information about the store as human-readable text.

Args:
storage_reader (StorageReader): storage reader.


def PyParseIntCast(string, location, tokens):
    for (index, token) in enumerate(tokens):
        try:
            tokens[index] = int(token)
        except ValueError:
            logger.error('Unable to cast [{0:s}] to an int, setting to 0'.format(token))
            tokens[index] = 0
    for key in tokens.keys():
        try:
            tokens[key] = int(tokens[key], 10)
        except ValueError:
            logger.error('Unable to cast [{0:s} = {1:d}] to an int, setting to 0'.format(key, tokens[key]))
            tokens[key] = 0

Return an integer from a string.

This is a pyparsing callback method that converts the matched
string into an integer.

The method modifies the content of the tokens list and converts
them all to an integer value.

Args:
string (str): original string.
location (int): location in the string where the match was made.
tokens (list[str]): extracted tokens, where the string to be converted
is stored.


def create_header(cls, request_id=None):
    header = {'msgid': bkserial.make_id(), 'msgtype': cls.msgtype}
    if (request_id is not None):
        header['reqid'] = request_id
    return header

Return a message header fragment dict.

Args:
request_id (str or None) :
Message ID of the message this message replies to

Returns:
dict : a message header


def recipe_bigquery_storage(config, auth_read, bucket, auth_write, path, dataset, table, schema):
    bigquery(config, {'auth': auth_read, 'from': {'bucket': bucket, 'path': path}, 'to': {'auth': auth_write, 'dataset': dataset, 'table': table}, 'schema': schema})

Move using bucket and path prefix.

Args:
auth_read (authentication) - Credentials used for reading data.
bucket (string) - Google cloud bucket.
auth_write (authentication) - Credentials used for writing data.
path (string) - Path prefix to read from, no * required.
dataset (string) - Existing BigQuery dataset.
table (string) - Table to create from this query.
schema (json) - Schema provided in JSON list format or empty list.


def MeshViewers(
        shape=(1, 1), titlebar="Mesh Viewers", keepalive=False,
        window_width=1280, window_height=960
):

    if not test_for_opengl():
        return Dummy()
    mv = MeshViewerLocal(
        shape=shape, titlebar=titlebar, uid=None, keepalive=keepalive,
        window_width=window_width, window_height=window_height
    )
    return mv.get_subwindows()

Allows subplot-style inspection of primitives in multiple subwindows.

Args:
shape: a tuple indicating the number of vertical and horizontal windows requested

Returns: a list of lists of MeshViewer objects: one per window requested.


def standard_to_absl(level):
    if (not isinstance(level, int)):
        raise TypeError('Expect an int level, found {}'.format(type(level)))
    if (level < 0):
        level = 0
    if (level < STANDARD_DEBUG):
        return ((STANDARD_DEBUG - level) + 1)
    elif (level < STANDARD_INFO):
        return ABSL_DEBUG
    elif (level < STANDARD_WARNING):
        return ABSL_INFO
    elif (level < STANDARD_ERROR):
        return ABSL_WARNING
    elif (level < STANDARD_CRITICAL):
        return ABSL_ERROR
    else:
        return ABSL_FATAL

Converts an integer level from the standard value to the absl value.

Args:
level: int, a Python standard logging level.

Raises:
TypeError: Raised when level is not an integer.

Returns:
The corresponding integer level for use in absl logging.


def get_help_datapacks(module_name, server_prefix):
    _dir = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
    module_dir = '{}/../{}'.format(_dir, module_name, '_help.json')
    if os.path.isdir(module_dir):
        module_help_path = '{}/{}'.format(module_dir, '_help.json')
        if os.path.isfile(module_help_path):
            return helptools.get_help_datapacks(module_help_path, server_prefix)
        else:
            return [('Help', '{} does not have a help.json file'.format(module_name), False)]
    else:
        return [('Help', 'No module found called {}'.format(module_name), False)]

Get the help datapacks for a module

Args:
module_name (str): The module to get help data for
server_prefix (str): The command prefix for this server

Returns:
datapacks (list): The help datapacks for the module


def export(self, filename, offset=0, length=None):

        self.__validate_offset(filename=filename, offset=offset, length=length)

        with open(filename, 'w') as f:
            if length is None:
                length = len(self.data) - offset

            if offset > 0:
                output = self.data[offset:length]
            else:
                output = self.data[:length]

            f.write(output)

Exports byte array to specified destination

Args:
filename (str): destination to output file
offset (int): byte offset (default: 0)


def _compute_diff(left: pg.DNA, right: pg.DNA) -> Tuple[int, int, int]:
    if left.value == right.value:
        assert len(left.children) == len(right.children)
        n = 0 if left.value is None else 1
        w = 0
        d = 0
        for c1, c2 in zip(left.children, right.children):
            cn, cw, cd = _compute_diff(c1, c2)
            n += cn
            w += cw
            d += cd
        return (n, w, d)
    else:
        nl = len(left.to_numbers())
        nr = len(right.to_numbers())
        n = max(nl, nr)
        return (n, 1, n - 1)

Compute different positions in two DNAs.

Args:
left: the first DNA to compare.
right: the right DNA to compare.

Returns:
A tuple of (N, W, D). 'N' is the total number of components in the larger
DNA, 'W' is the number of matching genes with different values, and 'D' is
the number of disjoint
genes. PyGlove DNAs have no notion of 'E' (i.e. excess genes from the
original paper), so we exclude them.


def vgg11_bn(pretrained=False, **kwargs):

    if pretrained:
        kwargs['init_weights'] = False
    model = VGG(make_layers(cfg['A'], batch_norm=True), **kwargs)
    if pretrained:
        model.load_state_dict(model_zoo.load_url(model_urls['vgg11_bn']))
    return model

VGG 11-layer model (configuration "A") with batch normalization

Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet


def refresh(self, refresh_binary=True):

		updated_self = self.repo.get_resource(self.uri)

		if not isinstance(self, type(updated_self)):
			raise Exception('Instantiated %s, but repository reports this resource is %s' % (type(updated_self), type(self)) )

		if updated_self:

			self.status_code = updated_self.status_code
			self.rdf.data = updated_self.rdf.data
			self.headers = updated_self.headers
			self.exists = updated_self.exists

			if type(self) != NonRDFSource:
				self._parse_graph()

			self.versions = SimpleNamespace()

			if type(updated_self) == NonRDFSource and refresh_binary:
				self.binary.refresh(updated_self)

			if hasattr(self,'_post_refresh'):
				self._post_refresh()

			del(updated_self)

		else:
			logger.debug('resource %s not found, dumping values')
			self._empty_resource_attributes()

Performs GET request and refreshes RDF information for resource.

Args:
None

Returns:
None


def get_data_node(self, path: DataPath) -> Optional[DataNode]:
    addr = self.schema_data.path2route(path)
    node = self.schema
    for p in addr:
        node = node.get_data_child(*p)
        if (node is None):
            return None
    return node

Return the data node addressed by a data path.

Args:
path: Data path.

Returns:
Data node if found in the schema, or ``None``.

Raises:
InvalidSchemaPath: If the schema path is invalid.


def convert_to_numpy(x):
    if any_symbolic_tensors((x,)):
        return np.array(x)
    return backend.convert_to_numpy(x)

Convert a tensor to a NumPy array.

Args:
x: A tensor.

Returns:
A NumPy array.


def _process_arguments(arguments):
    if (arguments is None):
        return ''
    result = ''
    for (key, value) in arguments.items():
        if (not key.startswith('bokeh-')):
            result += '&{}={}'.format(quote_plus(str(key)), quote_plus(str(value)))
    return result

Return user-supplied HTML arguments to add to a Bokeh server URL.

Args:
arguments (dict[str, object]) :
Key/value pairs to add to the URL

Returns:
str


def serialize_many_sparse_v2(sp_input, out_type=dtypes.string, name=None):
    sp_input = _convert_to_sparse_tensor(sp_input)
    return gen_sparse_ops.serialize_many_sparse(sp_input.indices, sp_input.values, sp_input.dense_shape, name=name, out_type=out_type)

Serialize `N`-minibatch `SparseTensor` into an `[N, 3]` `Tensor`.

The `SparseTensor` must have rank `R` greater than 1, and the first dimension
is treated as the minibatch dimension.  Elements of the `SparseTensor`
must be sorted in increasing order of this first dimension.  The serialized
`SparseTensor` objects going into each row of the output `Tensor` will have
rank `R-1`.

The minibatch size `N` is extracted from `sparse_shape[0]`.

Args:
sp_input: The input rank `R` `SparseTensor`.
out_type: The `dtype` to use for serialization.
name: A name prefix for the returned tensors (optional).

Returns:
A matrix (2-D `Tensor`) with `N` rows and `3` columns. Each column
represents serialized `SparseTensor`'s indices, values, and shape
(respectively).

Raises:
TypeError: If `sp_input` is not a `SparseTensor`.


def __frontend_limit_rules_descriptor(self, api_info):
    if (not api_info.frontend_limits.rules):
        return None
    rules = []
    for rule in api_info.frontend_limits.rules:
        descriptor = {}
        for (propname, descname) in (('match', 'match'), ('qps', 'qps'), ('user_qps', 'userQps'), ('daily', 'daily'), ('analytics_id', 'analyticsId')):
            if (getattr(rule, propname) is not None):
                descriptor[descname] = getattr(rule, propname)
        if descriptor:
            rules.append(descriptor)
    return rules

Builds a frontend limit rules descriptor from API info.

Args:
api_info: An _ApiInfo object.

Returns:
A list of dictionaries with frontend limit rules information.


def __init__(self, loc, scale, validate_args=False, allow_nan_stats=True, name='Laplace'):
    parameters = dict(locals())
    with ops.name_scope(name, values=[loc, scale]) as name:
        with ops.control_dependencies([check_ops.assert_positive(scale)] if validate_args else []):
            self._loc = array_ops.identity(loc, name='loc')
            self._scale = array_ops.identity(scale, name='scale')
            check_ops.assert_same_float_dtype([self._loc, self._scale])
        super(Laplace, self).__init__(dtype=self._loc.dtype, reparameterization_type=distribution.FULLY_REPARAMETERIZED, validate_args=validate_args, allow_nan_stats=allow_nan_stats, parameters=parameters, graph_parents=[self._loc, self._scale], name=name)

Construct Laplace distribution with parameters `loc` and `scale`.

The parameters `loc` and `scale` must be shaped in a way that supports
broadcasting (e.g., `loc / scale` is a valid operation).

Args:
loc: Floating point tensor which characterizes the location (center)
of the distribution.
scale: Positive floating point tensor which characterizes the spread of
the distribution.
validate_args: Python `bool`, default `False`. When `True` distribution
parameters are checked for validity despite possibly degrading runtime
performance. When `False` invalid inputs may silently render incorrect
outputs.
allow_nan_stats: Python `bool`, default `True`. When `True`,
statistics (e.g., mean, mode, variance) use the value "`NaN`" to
indicate the result is undefined. When `False`, an exception is raised
if one or more of the statistic's batch members are undefined.
name: Python `str` name prefixed to Ops created by this class.

Raises:
TypeError: if `loc` and `scale` are of different dtype.


def get_filetypes_info(editor_quote='`', flag_leaf=True):
    NONE_REPL = ''
    import f311
    data = []
    for attr in f311.classes_file(flag_leaf):
        description = a99.get_obj_doc0(attr)
        def_ = (NONE_REPL if (attr.default_filename is None) else attr.default_filename)
        ee = attr.editors
        if (ee is None):
            ee = NONE_REPL
        else:
            ee = ', '.join(['{0}{1}{0}'.format(editor_quote, x, editor_quote) for x in ee])
        data.append({'description': description, 'default_filename': def_, 'classname': attr.__name__, 'editors': ee, 'class': attr, 'txtbin': ('text' if attr.flag_txt else 'binary')})
    data.sort(key=(lambda x: x['description']))
    return data

Reports available data types

Args:
editor_quote: character to enclose the name of the editor script between.
flag_leaf: see tabulate_filetypes_rest()

Returns:
list: list of FileTypeInfo


def cancel_id(cls, id):

        conn = Qubole.agent()
        data = {"status": "kill"}
        return conn.put(cls.element_path(id), data)

Cancels command denoted by this id

Args:
`id`: command id


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

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

    file_object = resolver.Resolver.OpenFileObject(
        path_spec.parent, resolver_context=self._resolver_context)

    cpio_archive_file = cpio.CPIOArchiveFile()
    try:
      cpio_archive_file.Open(file_object)
    except:
      file_object.close()
      raise

    self._file_object = file_object
    self._cpio_archive_file = cpio_archive_file

Opens the file system defined by path specification.

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

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


def find_resistance(record):

    for feature in record.features:
        labels = set(feature.qualifiers.get("label", []))
        cassettes = labels.intersection(_ANTIBIOTICS)
        if len(cassettes) > 1:
            raise RuntimeError("multiple resistance cassettes detected")
        elif len(cassettes) == 1:
            return _ANTIBIOTICS.get(cassettes.pop())
    raise RuntimeError("could not find the resistance of '{}'".format(record.id))

Infer the antibiotics resistance of the given record.

Arguments:
record (`~Bio.SeqRecord.SeqRecord`): an annotated sequence.

Raises:
RuntimeError: when there's not exactly one resistance cassette.


def read_from_bigquery(*, table: Optional[str]=None, query: Optional[str]=None, row_restriction: Optional[str]=None, fields: Optional[Iterable[str]]=None):
    if query is None:
        assert table is not None
    else:
        assert table is None and row_restriction is None and (fields is None)
    return ReadFromBigQuery(query=query, table=table, row_restriction=row_restriction, selected_fields=fields, method='DIRECT_READ', output_type='BEAM_ROW')

Reads data from BigQuery.

Exactly one of table or query must be set.
If query is set, neither row_restriction nor fields should be set.

Args:
table (str): The table to read from, specified as `DATASET.TABLE`
or `PROJECT:DATASET.TABLE`.
query (str): A query to be used instead of the table argument.
row_restriction (str): Optional SQL text filtering statement, similar to a
WHERE clause in a query. Aggregates are not supported. Restricted to a
maximum length for 1 MB.
selected_fields (list[str]): Optional List of names of the fields in the
table that should be read. If empty, all fields will be read. If the
specified field is a nested field, all the sub-fields in the field will be
selected. The output field order is unrelated to the order of fields
given here.


def ParseFileObject(self, parser_mediator, file_object):

    display_name = parser_mediator.GetDisplayName()
    self.ParseFileLNKFile(parser_mediator, file_object, display_name)

Parses a Windows Shortcut (LNK) 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 add(self, *value):
    flattenedValueList = list(flatten(value))
    return self._add(flattenedValueList, self.value)

convert value and add to self.value

Subclass must overwrite this method.
Subclass are responsible of creating whatever single instance it need from its ``add(*value)`` and call ``_add()`` to add them to ``self.value``

Args:
*value: the value to be added


def _UploadChunk(self, chunk):

    blob = _CompressedDataBlob(chunk)

    self._action.ChargeBytesToSession(len(chunk.data))
    self._action.SendReply(blob, session_id=self._TRANSFER_STORE_SESSION_ID)

    return rdf_client_fs.BlobImageChunkDescriptor(
        digest=hashlib.sha256(chunk.data).digest(),
        offset=chunk.offset,
        length=len(chunk.data))

Uploads a single chunk to the transfer store flow.

Args:
chunk: A chunk to upload.

Returns:
A `BlobImageChunkDescriptor` object.


def set_syslog_server(server=None, type="primary"):

    if not server:
        raise salt.exceptions.CommandExecutionError("The SYSLOG server must be specified.")

    if type == "primary":
        dn = "sys/svc-ext/syslog/client-primary"
        inconfig = .format(server)
    elif type == "secondary":
        dn = "sys/svc-ext/syslog/client-secondary"
        inconfig = .format(server)
    else:
        raise salt.exceptions.CommandExecutionError("The SYSLOG type must be either primary or secondary.")

    ret = __proxy__['cimc.set_config_modify'](dn, inconfig, False)

    return ret

Set the SYSLOG server on the host.

Args:
server(str): The hostname or IP address of the SYSLOG server.

type(str): Specifies the type of SYSLOG server. This can either be primary (default) or secondary.

CLI Example:

.. code-block:: bash

salt '*' cimc.set_syslog_server foo.bar.com

salt '*' cimc.set_syslog_server foo.bar.com primary

salt '*' cimc.set_syslog_server foo.bar.com secondary


def _build_http_client(cls, session: AppSession):
    stream_factory = functools.partial(HTTPStream, ignore_length=session.args.ignore_length, keep_alive=session.args.http_keep_alive)
    return session.factory.new('HTTPClient', connection_pool=session.factory['ConnectionPool'], stream_factory=stream_factory)

Create the HTTP client.

Returns:
Client: An instance of :class:`.http.Client`.


def counter(urn: str, labels: Optional[Dict[str, str]]=None, process_wide: bool=False) -> UserMetrics.DelegatingCounter:
    return UserMetrics.DelegatingCounter(MetricName(namespace=None, name=None, urn=urn, labels=labels), process_wide=process_wide)

Obtains or creates a Counter metric.

Args:
namespace: A class or string that gives the namespace to a metric
name: A string that gives a unique name to a metric
urn: URN to populate on a MonitoringInfo, when sending to RunnerHarness.
labels: Labels to populate on a MonitoringInfo
process_wide: Whether or not the metric is specific to the current bundle
or should be calculated for the entire process.

Returns:
A Counter object.


def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
    hidden_states = hidden_states.view(self.num_experts, -1, self.hidden_size)
    gate_up = torch.bmm(hidden_states, self.gate_up_proj)
    gate, up = gate_up.chunk(2, dim=-1)
    next_states = torch.bmm(up * self.act_fn(gate), self.down_proj)
    next_states = next_states.view(-1, self.hidden_size)
    return next_states

This should really not be run on a single machine, as we are reaching compute bound:
- the inputs are expected to be "sorted" per expert already.
- the weights are viewed with another dim, to match num_expert, 1, shape * num_tokens, shape

Args:
hidden_states (torch.Tensor): (batch_size * token_num, hidden_size)
selected_experts (torch.Tensor): (batch_size * token_num, top_k)
routing_weights (torch.Tensor): (batch_size * token_num, top_k)
Returns:
torch.Tensor


def _sym_inferred(self, key: str, **kwargs):
    if key not in self._sym_attributes:
        raise AttributeError(key)
    v = pg_utils.contextual.get_scoped_value(self._contextual_overrides, key)
    if v is not None:
        return v.value
    override = pg_utils.contextual.get_contextual_override(key)
    if override and override.override_attrs:
        return override.value
    return super()._sym_inferred(key, context_override=override, **kwargs)

Override to allow attribute to access scoped value.

Args:
key: attribute name.
**kwargs: Optional keyword arguments for value inference.

Returns:
The value of the symbolic attribute. If not available, returns the
default value.

Raises:
AttributeError: If the attribute does not exist or contextual attribute
is not ready.


def list_container_services(access_token, subscription_id, resource_group):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourcegroups/', resource_group,
                        '/providers/Microsoft.ContainerService/ContainerServices',
                        '?api-version=', ACS_API])
    return do_get(endpoint, access_token)

List the container services in a resource group.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.

Returns:
HTTP response. JSON model.