def get_payments(self):
    query = '\n          query {\n            user {\n              payments {\n                nmrAmount\n                round {\n                  number\n                  openTime\n                  resolveTime\n                  resolvedGeneral\n                  resolvedStaking\n                }\n                tournament\n                usdAmount\n              }\n            }\n          }\n        '
    data = self.raw_query(query, authorization=True)['data']
    payments = data['user']['payments']
    for p in payments:
        utils.replace(p['round'], 'openTime', utils.parse_datetime_string)
        utils.replace(p['round'], 'resolveTime', utils.parse_datetime_string)
        utils.replace(p, 'usdAmount', utils.parse_float_string)
        utils.replace(p, 'nmrAmount', utils.parse_float_string)
    return payments

Get all your payments.

Returns:
list of dicts: payments

For each payout in the list, a dict contains the following items:

* nmrAmount (`decimal.Decimal`)
* usdAmount (`decimal.Decimal`)
* tournament (`str`)
* round (`dict`)
* number (`int`)
* openTime (`datetime`)
* resolveTime (`datetime`)
* resolvedGeneral (`bool`)
* resolvedStaking (`bool`)

Example:
>>> api = NumerAPI(secret_key="..", public_id="..")
>>> api.get_payments()
[{'nmrAmount': Decimal('0.00'),
'round': {'number': 84,
'openTime': datetime.datetime(2017, 12, 2, 18, 0, tzinfo=tzutc()),
'resolveTime': datetime.datetime(2018, 1, 1, 18, 0, tzinfo=tzutc()),
'resolvedGeneral': True,
'resolvedStaking': True},
'tournament': 'staking',
'usdAmount': Decimal('17.44')},
...
]


def split_heads(self, x):
    with tf.name_scope('split_heads'):
        batch_size = tf.shape(x)[0]
        length = tf.shape(x)[1]
        depth = (self.hidden_size
        x = tf.reshape(x, [batch_size, length, self.num_heads, depth])
        return tf.transpose(x, [0, 2, 1, 3])

Split x into different heads, and transpose the resulting value.

The tensor is transposed to insure the inner dimensions hold the correct
values during the matrix multiplication.

Args:
x: A tensor with shape [batch_size, length, hidden_size]

Returns:
A tensor with shape [batch_size, num_heads, length, hidden_size/num_heads]


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

Retrieves table data from a specified set of rows. Requires the READER dataset role.

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


def render(self, bindings):

        out = []
        binding = False
        for segment in self.segments:
            if segment.kind == _BINDING:
                if segment.literal not in bindings:
                    raise ValidationException(
                        ('rendering error: value for key \'{}\' '
                         'not provided').format(segment.literal))
                out.extend(PathTemplate(bindings[segment.literal]).segments)
                binding = True
            elif segment.kind == _END_BINDING:
                binding = False
            else:
                if binding:
                    continue
                out.append(segment)
        path = _format(out)
        self.match(path)
        return path

Renders a string from a path template using the provided bindings.

Args:
bindings (dict): A dictionary of var names to binding strings.

Returns:
str: The rendered instantiation of this path template.

Raises:
ValidationError: If a key isn't provided or if a sub-template can't
be parsed.


def assert_lessthan(arr_test, arr_max, msg=''):
    r
    if util_arg.NO_ASSERTS:
        return
    arr1 = np.array(arr_test)
    arr2 = np.array(arr_max)
    error = arr_max - arr_test
    passed = error >= 0
    if not np.all(passed):
        failed_xs = np.where(np.logical_not(passed))
        failed_error = error.take(failed_xs)
        failed_arr_test = arr1.take(failed_xs)
        failed_arr_target = arr2.take(failed_xs)

        msg_list = [
            'FAILED ASSERT LESSTHAN',
            msg,
            '  * failed_xs = %r' % (failed_xs,),
            '  * failed_error = %r' % (failed_error,),
            '  * failed_arr_test   = %r' % (failed_arr_test,),
            '  * failed_arr_target = %r' % (failed_arr_target,),
        ]
        msg = '\n'.join(msg_list)
        raise AssertionError(msg)
    return error

r"""
Args:
arr_test (ndarray or list):
arr_target (ndarray or list):
thresh (scalar or ndarray or list):


def _init_net_specs(conf):

        for net_name, net_spec in conf.get('nets', {}).items():
            net_spec['name'] = net_name
            net_spec['mapping'] = {}
            net_spec.setdefault('type', 'nat')

        return conf

Given a configuration specification, initializes all the net
definitions in it so they can be used comfortably

Args:
conf (dict): Configuration specification

Returns:
dict: the adapted new conf


def ResourcePath(package_name, filepath):
    if (not getattr(sys, 'frozen', None)):
        target = _GetPkgResources(package_name, filepath)
        if (target and os.access(target, os.R_OK)):
            return target
    target = os.path.join(sys.prefix, filepath)
    if (target and os.access(target, os.R_OK)):
        return target
    return None

Computes a path to the specified package resource.

Args:
package_name: A name of the package where the resource is located.
filepath: A path to the resource relative to the package location.

Returns:
A path to the resource or `None` if the resource cannot be found.


def resolution(self, indicator=None):

        self._request_entity = 'dnsResolution'
        self._request_uri = '{}/dnsResolutions'.format(self._request_uri)
        if indicator is not None:
            self._request_uri = '{}/{}/dnsResolutions'.format(self._api_uri, indicator)

Update the URI to retrieve host resolutions for the provided indicator.

Args:
indicator (string): The indicator to retrieve resolutions.


def repay_funding(self, amount, currency):
    params = {'amount': amount, 'currency': currency}
    return self._send_message('post', '/funding/repay', data=json.dumps(params))

Repay funding. Repays the older funding records first.

Args:
amount (int): Amount of currency to repay
currency (str): The currency, example USD

Returns:
Not specified by cbpro.


def get_usedby_and_readonly(self, id):

        uri = self.URI + "/" + id + "/usedby/readonly"
        return self._client.get(uri)

Gets the build plans details os teh selected plan script as per the selected attributes.

Args:
id: ID of the Plan Script.

Returns:
array of build plans


def __init__(self, value, method=Method.PREFIX):

        self.value = value
        self.method = method

Init method.

Args:
value (str): value to match.
method (const): Method constant, matching method.


def getTokensForText(self, body, POStags=None):

        return self._text.getTokensForText(self._retina, body, POStags)

Get tokenized input text
Args:
body, str: The text to be tokenized (required)
POStags, str: Specify desired POS types (optional)
Returns:
list of str
Raises:
CorticalioException: if the request was not successful


def macro_tpm(self, micro_tpm, check_independence=True):
    if (not is_state_by_state(micro_tpm)):
        micro_tpm = convert.state_by_node2state_by_state(micro_tpm)
    macro_tpm = self.macro_tpm_sbs(micro_tpm)
    if check_independence:
        validate.conditionally_independent(macro_tpm)
    return convert.state_by_state2state_by_node(macro_tpm)

Create a coarse-grained macro TPM.

Args:
micro_tpm (nd.array): The TPM of the micro-system.
check_independence (bool): Whether to check that the macro TPM is
conditionally independent.

Raises:
ConditionallyDependentError: If ``check_independence`` is ``True``
and the macro TPM is not conditionally independent.

Returns:
np.ndarray: The state-by-node TPM of the macro-system.


def quarter_boundaries(quarter):

    year, quarter = quarter.split('Q')
    year = int(year)
    quarter = int(quarter)
    first_month_of_quarter = 3 * quarter - 2
    last_month_of_quarter = 3 * quarter
    first_day = date(year, first_month_of_quarter, 1)
    last_day = date(year, last_month_of_quarter, monthrange(year, last_month_of_quarter)[1])
    return first_day, last_day

Returns first and last day of a quarter

Args:
quarter (str) quarter, in format '2015Q1'

Returns: (tuple) datetime.dates for the first and last days of the quarter


def handle_error(self, item_session: ItemSession, error: BaseException) -> Actions:
    if ((not self._ssl_verification) and isinstance(error, SSLVerificationError)):
        self._statistics.increment_error(ProtocolError())
    else:
        self._statistics.increment_error(error)
    self._waiter.increment()
    action = self.consult_error_hook(item_session, error)
    if (action == Actions.RETRY):
        item_session.set_status(Status.error)
    elif (action == Actions.FINISH):
        item_session.set_status(Status.done)
    elif (action == Actions.STOP):
        raise HookStop('Script requested immediate stop.')
    elif (self._ssl_verification and isinstance(error, SSLVerificationError)):
        raise
    elif (isinstance(error, ConnectionRefused) and (not self.retry_connrefused)):
        item_session.set_status(Status.skipped)
    elif (isinstance(error, DNSNotFound) and (not self.retry_dns_error)):
        item_session.set_status(Status.skipped)
    else:
        item_session.set_status(Status.error)
    return action

Process an error.

Returns:
A value from :class:`.hook.Actions`.


def _ParseInfo2Record(self, parser_mediator, file_object, record_offset, record_size):
    record_data = self._ReadData(file_object, record_offset, record_size)
    record_map = self._GetDataTypeMap('recycler_info2_file_entry')
    try:
        record = self._ReadStructureFromByteStream(record_data, record_offset, record_map)
    except (ValueError, errors.ParseError) as exception:
        raise errors.ParseError('Unable to map record data at offset: 0x{0:08x} with error: {1!s}'.format(record_offset, exception))
    codepage = (parser_mediator.codepage or 'ascii')
    ascii_filename = record.original_filename.split(b'\x00')[0]
    try:
        ascii_filename = ascii_filename.decode(codepage)
    except UnicodeDecodeError:
        ascii_filename = ascii_filename.decode(codepage, errors='replace')
        parser_mediator.ProduceExtractionWarning('unable to decode original filename.')
    unicode_filename = None
    if (record_size > 280):
        record_offset += 280
        utf16_string_map = self._GetDataTypeMap('recycler_info2_file_entry_utf16le_string')
        try:
            unicode_filename = self._ReadStructureFromByteStream(record_data[280:], record_offset, utf16_string_map)
        except (ValueError, errors.ParseError) as exception:
            raise errors.ParseError('Unable to map record data at offset: 0x{0:08x} with error: {1!s}'.format(record_offset, exception))
        unicode_filename = unicode_filename.rstrip('\x00')
    if (record.deletion_time == 0):
        date_time = dfdatetime_semantic_time.SemanticTime('Not set')
    else:
        date_time = dfdatetime_filetime.Filetime(timestamp=record.deletion_time)
    event_data = WinRecycleBinEventData()
    event_data.drive_number = record.drive_number
    event_data.original_filename = (unicode_filename or ascii_filename)
    event_data.file_size = record.original_file_size
    event_data.offset = record_offset
    event_data.record_index = record.index
    if (ascii_filename != unicode_filename):
        event_data.short_filename = ascii_filename
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_DELETED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses an INFO-2 record.

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

Raises:
ParseError: if the record cannot be read.


def reply(self, status=200, new_response=False, **kw):
    res = (Response(**kw) if new_response else self._response)
    res.status((status or res._status))
    res.mock = self
    self._response = res
    return res

Defines the mock response.

Arguments:
status (int, optional): response status code. Defaults to ``200``.
**kw (dict): optional keyword arguments passed to ``pook.Response``
constructor.

Returns:
pook.Response: mock response definition instance.


def terminate(self, task_type, task_id):
    with self._process_lock:
        p = self._processes.get((task_type, task_id), None)
        if p is None:
            raise ValueError('{}-{} does not exist'.format(task_type, task_id))
        self._terminated.add((task_type, task_id))
        self._parent_to_sub_queue.put('terminate {} {}'.format(task_type, task_id))
        p.join()

Terminates the process with `task_type` and `task_id`.

If auto_retart=True, the terminated task will be restarted unless the chief
has already exited with zero exit code.

Args:
task_type: the task type.
task_id: the task id.


def print_serial_number_info(self, serial_number, print_to_screen=True):
    r = self.select_serial_number_row(serial_number)
    if r.empty:
        warnings.warn('missing serial number')
        return
    txt1 = (80 * '=')
    txt1 += '\n'
    txt1 += f
    txt1 = (80 * '-')
    txt1 += '\n'
    txt2 = ''
    for (label, value) in zip(r.columns, r.values[0]):
        if (label in self.headers):
            txt1 += f
        else:
            txt2 += f
    if print_to_screen:
        print(txt1)
        print((80 * '-'))
        print(txt2)
        print((80 * '='))
        return
    else:
        return txt1

Print information about the run.

Args:
serial_number: serial number.
print_to_screen: runs the print statement if True,
returns txt if not.

Returns:
txt if print_to_screen is False, else None.


def configure_app(app, config=None, config_obj=None):

    app.config.from_object(config_obj or BaseConfig)
    if config is not None:
        app.config.from_pyfile(config)

Configure application instance.

Args:
app (Flask): initialized Flask app instance
config (Optional[path]): path to a Python module config file
config_obj (Optional[class]): Python config object


def GetStream(data=None):

        if len(__mstreams_available__) == 0:
            if data:
                mstream = MemoryStream(data)
                mstream.seek(0)
            else:
                mstream = MemoryStream()
            __mstreams__.append(mstream)
            return mstream

        mstream = __mstreams_available__.pop()

        if data is not None and len(data):
            mstream.Cleanup()
            mstream.write(data)

        mstream.seek(0)

        return mstream

Get a MemoryStream instance.

Args:
data (bytes, bytearray, BytesIO): (Optional) data to create the stream from.

Returns:
MemoryStream: instance.


def _create_or_validate_filenames_dataset(filenames, name=None):
    if isinstance(filenames, data_types.DatasetV2):
        element_type = dataset_ops.get_legacy_output_types(filenames)
        if element_type != dtypes.string:
            raise TypeError(f'The `filenames` argument must contain `tf.string` elements. Got a dataset of `{element_type!r}` elements.')
        element_shape = dataset_ops.get_legacy_output_shapes(filenames)
        if not element_shape.is_compatible_with(tensor_shape.TensorShape([])):
            raise TypeError(f'The `filenames` argument must contain `tf.string` elements of shape [] (i.e. scalars). Got a dataset of element shape {element_shape!r}.')
    else:
        filenames = nest.map_structure(_normalise_fspath, filenames)
        filenames = ops.convert_to_tensor(filenames, dtype_hint=dtypes.string)
        if filenames.dtype != dtypes.string:
            raise TypeError(f'The `filenames` argument must contain `tf.string` elements. Got `{filenames.dtype!r}` elements.')
        filenames = array_ops.reshape(filenames, [-1], name='flat_filenames')
        filenames = from_tensor_slices_op._TensorSliceDataset(filenames, is_files=True, name=name)
    return filenames

Creates (or validates) a dataset of filenames.

Args:
filenames: Either a list or dataset of filenames. If it is a list, it is
convert to a dataset. If it is a dataset, its type and shape is validated.
name: (Optional.) A name for the tf.data operation.

Returns:
A dataset of filenames.


def onehot_encode(dataset, char_indices, maxlen):
    X = np.zeros((len(dataset), maxlen, len(char_indices.keys())))
    for (i, sentence) in enumerate(dataset):
        for (t, char) in enumerate(sentence):
            X[(i, t, char_indices[char])] = 1
    return X

One hot encode the tokens

Args:
dataset  list of lists of tokens
char_indices  dictionary of {key=character, value=index to use encoding vector}
maxlen  int  Length of each sample
Return:
np array of shape (samples, tokens, encoding length)


def _ConditionalFormatMessages(self, event_values):

    string_pieces = []
    for map_index, attribute_name in enumerate(self._format_string_pieces_map):
      if not attribute_name or attribute_name in event_values:
        if attribute_name:
          attribute = event_values.get(attribute_name, None)

          if (not isinstance(attribute, (bool, float)) and
              not isinstance(attribute, py2to3.INTEGER_TYPES) and
              not attribute):
            continue

        string_pieces.append(self.FORMAT_STRING_PIECES[map_index])

    format_string = self.FORMAT_STRING_SEPARATOR.join(string_pieces)

    string_pieces = []
    for map_index, attribute_name in enumerate(
        self._format_string_short_pieces_map):
      if not attribute_name or event_values.get(attribute_name, None):
        string_pieces.append(self.FORMAT_STRING_SHORT_PIECES[map_index])
    short_format_string = self.FORMAT_STRING_SEPARATOR.join(string_pieces)

    return self._FormatMessages(
        format_string, short_format_string, event_values)

Determines the conditional formatted message strings.

Args:
event_values (dict[str, object]): event values.

Returns:
tuple(str, str): formatted message string and short message string.


def add_property_orders(query_proto, *orders):
    for order in orders:
        proto = query_proto.order.add()
        if (order[0] == '-'):
            order = order[1:]
            proto.direction = query_pb2.PropertyOrder.DESCENDING
        else:
            proto.direction = query_pb2.PropertyOrder.ASCENDING
        proto.property.name = order

Add ordering constraint for the given datastore.Query proto message.

Args:
query_proto: datastore.Query proto message.
orders: list of propertype name string, default to ascending
order and set descending if prefixed by '-'.

Usage:
>>> add_property_orders(query_proto, 'foo')  # sort by foo asc
>>> add_property_orders(query_proto, '-bar')  # sort by bar desc


def convert_coco_poly_to_mask(segmentations, height: int, width: int) -> np.ndarray:
    try:
        from pycocotools import mask as coco_mask
    except ImportError:
        raise ImportError('Pycocotools is not installed in your environment.')
    masks = []
    for polygons in segmentations:
        rles = coco_mask.frPyObjects(polygons, height, width)
        mask = coco_mask.decode(rles)
        if len(mask.shape) < 3:
            mask = mask[..., None]
        mask = np.asarray(mask, dtype=np.uint8)
        mask = np.any(mask, axis=2)
        masks.append(mask)
    if masks:
        masks = np.stack(masks, axis=0)
    else:
        masks = np.zeros((0, height, width), dtype=np.uint8)
    return masks

Convert a COCO polygon annotation to a mask.

Args:
segmentations (`List[List[float]]`):
List of polygons, each polygon represented by a list of x-y coordinates.
height (`int`):
Height of the mask.
width (`int`):
Width of the mask.


def _get_backend_instance(self, backend_cls):

        try:
            backend_instance = backend_cls(provider=self)
        except Exception as err:
            raise QiskitError('Backend %s could not be instantiated: %s' %
                              (backend_cls, err))

        return backend_instance

Return an instance of a backend from its class.

Args:
backend_cls (class): Backend class.
Returns:
BaseBackend: a backend instance.
Raises:
QiskitError: if the backend could not be instantiated.


def model_fn(hparams, seed):

  rng = random.Random(seed)

  model = tf.keras.models.Sequential()
  model.add(tf.keras.layers.Input(INPUT_SHAPE))
  model.add(tf.keras.layers.Reshape(INPUT_SHAPE + (1,)))

  conv_filters = 8
  for _ in xrange(hparams[HP_CONV_LAYERS]):
    model.add(tf.keras.layers.Conv2D(
        filters=conv_filters,
        kernel_size=hparams[HP_CONV_KERNEL_SIZE],
        padding="same",
        activation="relu",
    ))
    model.add(tf.keras.layers.MaxPool2D(pool_size=2, padding="same"))
    conv_filters *= 2

  model.add(tf.keras.layers.Flatten())
  model.add(tf.keras.layers.Dropout(hparams[HP_DROPOUT], seed=rng.random()))

  dense_neurons = 32
  for _ in xrange(hparams[HP_DENSE_LAYERS]):
    model.add(tf.keras.layers.Dense(dense_neurons, activation="relu"))
    dense_neurons *= 2

  model.add(tf.keras.layers.Dense(OUTPUT_CLASSES, activation="softmax"))

  model.compile(
      loss="sparse_categorical_crossentropy",
      optimizer=hparams[HP_OPTIMIZER],
      metrics=["accuracy"],
  )
  return model

Create a Keras model with the given hyperparameters.

Args:
hparams: A dict mapping hyperparameters in `HPARAMS` to values.
seed: A hashable object to be used as a random seed (e.g., to
construct dropout layers in the model).

Returns:
A compiled Keras model.


def guess_strategy_type(file_name_or_ext):
    if ('.' not in file_name_or_ext):
        ext = file_name_or_ext
    else:
        (name, ext) = os.path.splitext(file_name_or_ext)
    ext = ext.lstrip('.')
    file_type_map = get_file_type_map()
    return file_type_map.get(ext, None)

Guess strategy type to use for file by extension.

Args:
file_name_or_ext: Either a file name with an extension or just
an extension

Returns:
Strategy: Type corresponding to extension or None if there's no
corresponding strategy type


def start_listener_thread(self, timeout_ms: int = 30000, exception_handler: Callable = None):

        assert not self.should_listen and self.sync_thread is None, 'Already running'
        self.should_listen = True
        self.sync_thread = gevent.spawn(self.listen_forever, timeout_ms, exception_handler)
        self.sync_thread.name = f'GMatrixClient.listen_forever user_id:{self.user_id}'

Start a listener greenlet to listen for events in the background.
Args:
timeout_ms: How long to poll the Home Server for before retrying.
exception_handler: Optional exception handler function which can
be used to handle exceptions in the caller thread.


def normalized_energy_at_conditions(self, pH, V):

        return self.energy_at_conditions(pH, V) * self.normalization_factor

Energy at an electrochemical condition, compatible with
numpy arrays for pH/V input

Args:
pH (float): pH at condition
V (float): applied potential at condition

Returns:
energy normalized by number of non-O/H atoms at condition


def _verifyStackFrames(self, stack_frames):
    self.assertTrue([frame for frame in stack_frames if frame[0] == _current_file_full_path])

Verify the correctness of the stack frames.

Currently, it simply asserts that the current file is found in the stack
frames.
TODO(cais): Perhaps implement a stricter check later.

Args:
stack_frames: The stack frames to verify.


def parse_file(path, format=None, encoding='utf-8', force_types=True):
    try:
        with open(path, 'rb') as f:
            return parse(f, format, encoding, force_types)
    except EnvironmentError as e:
        raise AnyMarkupError(e, traceback.format_exc())

A convenience wrapper of parse, which accepts path of file to parse.

Args:
path: path to file to parse
format: explicitly override the guessed `inp` markup format
encoding: file encoding, defaults to utf-8
force_types:
if `True`, integers, floats, booleans and none/null
are recognized and returned as proper types instead of strings;
if `False`, everything is converted to strings
if `None`, backend return value is used
Returns:
parsed `inp` (dict or list) containing unicode values
Raises:
AnyMarkupError if a problem occurs while parsing


def create_new(cls, mapreduce_id, shard_number):

    shard_id = cls.shard_id_from_number(mapreduce_id, shard_number)
    state = cls(key_name=shard_id,
                mapreduce_id=mapreduce_id)
    return state

Create new shard state.

Args:
mapreduce_id: unique mapreduce id as string.
shard_number: shard number for which to create shard state.

Returns:
new instance of ShardState ready to put into datastore.


def _redistribute_builder(self, afi='ipv4', source=None):
    if (source == 'connected'):
        return getattr(self._rbridge, 'rbridge_id_router_router_bgp_address_family_{0}_{0}_unicast_default_vrf_af_{0}_uc_and_vrf_cmds_call_point_holder_redistribute_connected_redistribute_connected'.format(afi))
    else:
        raise AttributeError('Invalid source.')

Build BGP redistribute method.

Do not use this method directly.  You probably want ``redistribute``.

Args:
source (str): Source for redistributing. (connected)
afi (str): Address family to configure. (ipv4, ipv6)

Returns:
Method to redistribute desired source.

Raises:
KeyError: if `source` is not specified.

Examples:
>>> import pynos.device
>>> conn = ('10.24.39.203', '22')
>>> auth = ('admin', 'password')
>>> with pynos.device.Device(conn=conn, auth=auth) as dev:
...     output = dev.bgp._redistribute_builder(source='connected',
...     afi='ipv4')
...     dev.bgp._redistribute_builder(source='hodor',
...     afi='ipv4') # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
AttributeError


def encode_plus(self, text: Union[TextInput, PreTokenizedInput], text_pair: Optional[PreTokenizedInput]=None, xpaths: Optional[List[List[int]]]=None, node_labels: Optional[List[int]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, stride: int=0, pad_to_multiple_of: Optional[int]=None, padding_side: Optional[str]=None, return_tensors: Optional[Union[str, TensorType]]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_offsets_mapping: bool=False, return_length: bool=False, verbose: bool=True, **kwargs) -> BatchEncoding:
    padding_strategy, truncation_strategy, max_length, kwargs = self._get_padding_truncation_strategies(padding=padding, truncation=truncation, max_length=max_length, pad_to_multiple_of=pad_to_multiple_of, verbose=verbose, **kwargs)
    return self._encode_plus(text=text, xpaths=xpaths, text_pair=text_pair, node_labels=node_labels, add_special_tokens=add_special_tokens, padding_strategy=padding_strategy, truncation_strategy=truncation_strategy, max_length=max_length, stride=stride, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)

Tokenize and prepare for the model a sequence or a pair of sequences. .. warning:: This method is deprecated,
`__call__` should be used instead.

Args:
text (`str`, `List[str]`, `List[List[str]]`):
The first sequence to be encoded. This can be a string, a list of strings or a list of list of strings.
text_pair (`List[str]` or `List[int]`, *optional*):
Optional second sequence to be encoded. This can be a list of strings (nodes of a single example) or a
list of list of strings (nodes of a batch of examples).


def get_rows_fieldnames_from_query(
        session: Union[Session, Engine, Connection],
        query: Query) -> Tuple[Sequence[Sequence[Any]], Sequence[str]]:

    result = session.execute(query)
    fieldnames = result.keys()

    rows = result.fetchall()
    return rows, fieldnames

Returns results and column names from a query.

Args:
session: SQLAlchemy :class:`Session`, :class:`Engine`, or
:class:`Connection` object
query: SQLAlchemy :class:`Query`

Returns:
``(rows, fieldnames)`` where ``rows`` is the usual set of results and
``fieldnames`` are the name of the result columns/fields.


def ConvertToWireFormat(self, value):

    output = _SerializeEntries(
        (python_format, wire_format, value.type_descriptor)
        for (python_format, wire_format) in value.wrapped_list)
    return b"", b"", output

Convert to the wire format.

Args:
value: is of type RepeatedFieldHelper.

Returns:
A wire format representation of the value.


def _scalar_field_to_json(field, row_value):

    converter = _SCALAR_VALUE_TO_JSON_ROW.get(field.field_type)
    if converter is None:
        return row_value
    return converter(row_value)

Maps a field and value to a JSON-safe value.

Args:
field ( \
:class:`~google.cloud.bigquery.schema.SchemaField`, \
):
The SchemaField to use for type conversion and field name.
row_value (any):
Value to be converted, based on the field's type.

Returns:
any:
A JSON-serializable object.


class AriaProjectorMLP(nn.Module):

    def __init__(self, in_features, hidden_features, output_dim):
        super().__init__()
        self.linear_in = nn.Linear(in_features, hidden_features, bias=False)
        self.linear_out = nn.Linear(hidden_features, output_dim, bias=False)
        self.act = ACT2FN['gelu_new']

    def forward(self, hidden_states):
        hidden_states = self.act(self.linear_in(hidden_states))
        hidden_states = self.linear_out(hidden_states)
        return hidden_states

Feed-Forward Network module for the Aria Projector.

Args:
in_features (`int`):
Input embedding dimension.
hidden_features (`int`):
Hidden dimension of the feed-forward network.
output_dim (`int`):
Output dimension.


def Var(self, mu=None):
    if (mu is None):
        mu = self.Mean()
    var = 0.0
    for (x, p) in self.d.iteritems():
        var += (p * ((x - mu) ** 2))
    return var

Computes the variance of a PMF.

Args:
mu: the point around which the variance is computed;
if omitted, computes the mean

Returns:
float variance


def __init__(self, all_batch_items=None, commit_count=None):
    self._all_batch_items = all_batch_items
    self._commit_count = commit_count
    self.mutations = []

Fake ``google.cloud.datastore.batch.Batch`` object.

Args:
all_batch_items: (list) If set, will append all entities/keys added to
this batch.
commit_count: (list of int) If set, will increment commit_count[0] on
each ``commit``.


def get_execution_host_info():
    host = os.environ.get('HOSTNAME', None)
    cluster = os.environ.get('SGE_O_HOST', None)
    if (host is None):
        try:
            import socket
            host = (host or socket.gethostname())
        except:
            pass
    return ((host or 'unknown'), (cluster or 'unknown'))

Tries to return a tuple describing the execution host.
Doesn't work for all queueing systems

Returns:
(HOSTNAME, CLUSTER_NAME)


def app(environ, start_response):
    from wsgi import container
    'Add Environ To Service Container\n    Add the environ to the service container. The environ is generated by the\n    the WSGI server above and used by a service provider to manipulate the\n    incoming requests\n    '
    container.bind('Environ', environ)
    'Execute All Service Providers That Require The WSGI Server\n    Run all service provider boot methods if the wsgi attribute is true.\n    '
    try:
        for provider in container.make('WSGIProviders'):
            container.resolve(provider.boot)
    except Exception as e:
        container.make('ExceptionHandler').load_exception(e)
    "We Are Ready For Launch\n    If we have a solid response and not redirecting then we need to return\n    a 200 status code along with the data. If we don't, then we'll have\n    to return a 302 redirection to where ever the user would like go\n    to next.\n    "
    start_response(container.make('Request').get_status_code(), container.make('Request').get_and_reset_headers())
    'Final Step\n    This will take the data variable from the Service Container and return\n    it to the WSGI server.\n    '
    return iter([bytes(container.make('Response'), 'utf-8')])

The WSGI Application Server.

Arguments:
environ {dict} -- The WSGI environ dictionary
start_response {WSGI callable}

Returns:
WSGI Response


def __init__(self, forecast_io):

        if forecast_io.has_currently():
            self.currently = forecast_io.get_currently()
            for item in self.currently.keys():
                setattr(self, item, self.currently[item])

Construct a new 'FIOCurrently' object.
Recieves an ForecastIO object and gets the currently weather conditions
if they are available in the object.

Args:
forecast_io (ForecastIO): The ForecastIO object


def _handle_create(self, response, ignore_tombstone, auto_refresh):

		if response.status_code == 201:

			self.uri = self.repo.parse_uri(response.text)

			if auto_refresh:
				self.refresh()
			elif auto_refresh == None:
				if self.repo.default_auto_refresh:
					self.refresh()

			if hasattr(self,'_post_create'):
				self._post_create(auto_refresh=auto_refresh)

		elif response.status_code == 404:
			raise Exception('HTTP 404, for this POST request target location does not exist')

		elif response.status_code == 409:
			raise Exception('HTTP 409, resource already exists')

		elif response.status_code == 410:
			if ignore_tombstone:
				response = self.repo.api.http_request('DELETE', '%s/fcr:tombstone' % self.uri)
				if response.status_code == 204:
					logger.debug('tombstone removed, retrying create')
					self.create()
				else:
					raise Exception('HTTP %s, Could not remove tombstone for %s' % (response.status_code, self.uri))
			else:
				raise Exception('tombstone for %s detected, aborting' % self.uri)

		elif response.status_code == 415:
			raise Exception('HTTP 415, unsupported media type')

		else:
			raise Exception('HTTP %s, unknown error creating resource' % response.status_code)

		return self

Handles response from self.create()

Args:
response (requests.models.Response): response object from self.create()
ignore_tombstone (bool): If True, will attempt creation, if tombstone exists (409), will delete tombstone and retry


def text_pb(tag, data, description=None):

  try:
    tensor = tensor_util.make_tensor_proto(data, dtype=np.object)
  except TypeError as e:
    raise TypeError('tensor must be of type string', e)
  summary_metadata = metadata.create_summary_metadata(
      display_name=None, description=description)
  summary = summary_pb2.Summary()
  summary.value.add(tag=tag,
                    metadata=summary_metadata,
                    tensor=tensor)
  return summary

Create a text tf.Summary protobuf.

Arguments:
tag: String tag for the summary.
data: A Python bytestring (of type bytes), a Unicode string, or a numpy data
array of those types.
description: Optional long-form description for this summary, as a `str`.
Markdown is supported. Defaults to empty.

Raises:
TypeError: If the type of the data is unsupported.

Returns:
A `tf.Summary` protobuf object.


def ProtoFromDataFrames(self, dataframes):

    datasets = []
    for dataframe in dataframes:
      table = dataframe['table']
      table_entries = {}
      for col in table:
        table_entries[col] = self.NdarrayToEntry(table[col])
      datasets.append({
          'entries': table_entries,
          'size': len(table),
          'name': dataframe['name']
      })
    return self.GetDatasetsProto(datasets)

Creates a feature statistics proto from a set of pandas dataframes.
Args:
dataframes: A list of dicts describing tables for each dataset for the
proto. Each entry contains a 'table' field of the dataframe of the
data
and a 'name' field to identify the dataset in the proto.
Returns:
The feature statistics proto for the provided tables.


def list_container_instance_groups_sub(access_token, subscription_id):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.ContainerInstance/ContainerGroups', '?api-version=', CONTAINER_API])
    return do_get(endpoint, access_token)

List the container groups in a subscription.

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

Returns:
HTTP response. JSON list of container groups and their properties.


def set_soft_device_placement(enabled):
    context.context().soft_device_placement = enabled

Enable or disable soft device placement.

If enabled, ops can be placed on different devices than the device explicitly
assigned by the user. This potentially has a large performance cost due to an
increase in data communication between devices.

Some cases where soft_device_placement would modify device assignment are:
1. no GPU/TPU implementation for the OP
2. no GPU devices are known or registered
3. need to co-locate with reftype input(s) which are from CPU
4. an OP can not be compiled by XLA.  Common for TPU which always requires
the XLA compiler.

For TPUs, if this option is true, a feature called automatic outside
compilation is enabled. Automatic outside compilation will move uncompilable
ops within a TPU program to instead run on the host. This can be used when
encountering compilation failures due to unsupported ops.

Note: by default soft device placement is enabled when running in eager mode
(for convenience) and disabled in graph mode (for performance).

Args:
enabled: A boolean indicating whether to enable soft placement.


def get_all_dependencies(metadata: MetaData,
                         extra_dependencies: List[TableDependency] = None,
                         sort: bool = True) \
        -> List[TableDependency]:

    extra_dependencies = extra_dependencies or []
    for td in extra_dependencies:
        td.set_metadata_if_none(metadata)
    dependencies = set([td.sqla_tuple() for td in extra_dependencies])

    tables = list(metadata.tables.values())

    for table in tables:
        for fkc in table.foreign_key_constraints:
            if fkc.use_alter is True:

                continue

            dependent_on = fkc.referred_table
            if dependent_on is not table:
                dependencies.add((dependent_on, table))

        if hasattr(table, "_extra_dependencies"):

            dependencies.update(
                (parent, table) for parent in table._extra_dependencies
            )

    dependencies = [
        TableDependency(parent_table=parent, child_table=child)
        for parent, child in dependencies
    ]
    if sort:
        dependencies.sort(key=lambda td_: (td_.parent_tablename,
                                           td_.child_tablename))
    return dependencies

Describes how the tables found in the metadata depend on each other.
(If table B contains a foreign key to table A, for example, then B depends
on A.)

Args:
metadata: the metadata to inspect
extra_dependencies: additional table dependencies to specify manually
sort: sort into alphabetical order of (parent, child) table names?

Returns:
a list of :class:`TableDependency` objects

See :func:`sort_tables_and_constraints` for method.


def __check_no_missing_attributes(self, node: yaml.Node, mapping: CommentedMap) -> None:
    logger.debug('Checking presence of required attributes')
    for (name, type_, required) in class_subobjects(self.class_):
        if (required and (name not in mapping)):
            raise RecognitionError('{}{}Missing attribute {} needed for constructing a {}'.format(node.start_mark, os.linesep, name, self.class_.__name__))
        if ((name in mapping) and (not self.__type_matches(mapping[name], type_))):
            raise RecognitionError('{}{}Attribute {} has incorrect type {}, expecting a {}'.format(node.start_mark, os.linesep, name, type(mapping[name]), type_))

Checks that all required attributes are present.

Also checks that they're of the correct type.

Args:
mapping: The mapping with subobjects of this object.

Raises:
RecognitionError: if an attribute is missing or the type \
is incorrect.


def get_partstudio_tessellatededges(self, did, wid, eid):

        return self._api.request('get', '/api/partstudios/d/' + did + '/w/' + wid + '/e/' + eid + '/tessellatededges')

Gets the tessellation of the edges of all parts in a part studio.

Args:
- did (str): Document ID
- wid (str): Workspace ID
- eid (str): Element ID

Returns:
- requests.Response: Onshape response data


def checksum(path):
    filesystem = FileSystems.get_filesystem(path)
    return filesystem.checksum(path)

Fetch checksum metadata of a file on the
:class:`~apache_beam.io.filesystem.FileSystem`.

This operation returns checksum metadata as stored in the underlying
FileSystem. It should not read any file data. Checksum type and format are
FileSystem dependent and are not compatible between FileSystems.

Args:
path: string path of a file.

Returns: string containing checksum

Raises:
``BeamIOError``: if path isn't a file or doesn't exist.


def run(argv=None, save_main_session=True):
    known_args, pipeline_args = parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
    engine_handler = KeyedModelHandler(TensorRTEngineHandlerNumPy(min_batch_size=1, max_batch_size=1, engine_path=known_args.engine_path))
    with beam.Pipeline(options=pipeline_options) as p:
        filename_value_pair = p | 'ReadImageNames' >> beam.io.ReadFromText(known_args.input) | 'ReadImageData' >> beam.Map(lambda image_name: read_image(image_file_name=image_name, path_to_dir=known_args.images_dir)) | 'AttachImageSizeToKey' >> beam.Map(attach_im_size_to_key) | 'PreprocessImages' >> beam.MapTuple(lambda file_name, data: (file_name, preprocess_image(data)))
        predictions = filename_value_pair | 'TensorRTRunInference' >> RunInference(engine_handler) | 'ProcessOutput' >> beam.ParDo(PostProcessor())
        _ = predictions | 'WriteOutputToGCS' >> beam.io.WriteToText(known_args.output, shard_name_template='', append_trailing_newlines=True)

Args:
argv: Command line arguments defined for this example.


def ToRequest(self):
    param = {}
    if self.email:
        param['email'] = self.email
    if self.user_id:
        param['localId'] = self.user_id
    if self.name:
        param['displayName'] = self.name
    if self.photo_url:
        param['photoUrl'] = self.photo_url
    if (self.email_verified is not None):
        param['emailVerified'] = self.email_verified
    if self.password_hash:
        param['passwordHash'] = base64.urlsafe_b64encode(self.password_hash)
    if self.salt:
        param['salt'] = base64.urlsafe_b64encode(self.salt)
    if self.provider_info:
        param['providerUserInfo'] = self.provider_info
    return param

Converts to gitkit api request parameter dict.

Returns:
Dict, containing non-empty user attributes.


def validlocations(configuration=None):
    if (Locations._validlocations is None):
        if (configuration is None):
            configuration = Configuration.read()
        Locations._validlocations = configuration.call_remoteckan('group_list', {'all_fields': True})
    return Locations._validlocations

Read valid locations from HDX

Args:
configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration.

Returns:
List[Dict]: A list of valid locations


def multiple(layer: int, limit: int) -> Set[str]:

	return {str(x).zfill(2) for x in [2**x for x in range(limit)] if x % 2**(layer - 1) == 0}

Returns a set of strings to be used as Slots with Pabianas default Clock.

Args:
layer: The layer in the hierarchy this Area is placed in.
Technically, the number specifies how many of the Clocks signals are relevant to the Area.
Between 1 and limit.
limit: The number of layers of the hierarchy.


def _apply_same_padding(inputs, kernel_size, strides, data_format, operation_type, dilation_rate=1):
    spatial_shape = inputs.shape[2:]
    num_spatial_dims = len(spatial_shape)
    padding = []
    if operation_type != 'pooling':
        dilation_rate = standardize_tuple(dilation_rate, num_spatial_dims, 'dilation_rate')
    for i in range(num_spatial_dims):
        dil = 1 if operation_type == 'pooling' else dilation_rate[i]
        pad = _compute_padding_length(spatial_shape[i], kernel_size[i], strides[i], dil)
        padding.append(pad)
    if all((left == right for left, right in padding)):
        return (inputs, [left for left, _ in padding])
    flattened_padding = []
    for pad in reversed(padding):
        flattened_padding.extend(pad)
    mode = 'replicate' if operation_type == 'pooling' else 'constant'
    return (tnn.pad(inputs, pad=tuple(flattened_padding), mode=mode), 0)

Apply same padding to the input tensor.

This function will evaluate if the padding value is compatible with torch
functions. To avoid calling `pad()` as much as possible, which may cause
performance or memory issues, when compatible, it does not apply the padding
to the tensor, but returns the input tensor and the padding value to pass to
the torch functions. If not compatible, it returns the padded tensor and 0
as the padding value.

Returns:
tensor: A padded tensor or the inputs.
padding: The padding value, ready to pass to the torch functions.


def validate_language_key(obj, key):
    backend = bigchaindb.config['database']['backend']
    if (backend == 'localmongodb'):
        data = obj.get(key, {})
        if isinstance(data, dict):
            validate_all_values_for_key_in_obj(data, 'language', validate_language)
        elif isinstance(data, list):
            validate_all_values_for_key_in_list(data, 'language', validate_language)

Validate all nested "language" key in `obj`.

Args:
obj (dict): dictionary whose "language" key is to be validated.

Returns:
None: validation successful

Raises:
ValidationError: will raise exception in case language is not valid.


def variables_initializer(var_list, name='init'):
    if var_list and (not context.executing_eagerly()):
        return control_flow_ops.group(*[v.initializer for v in var_list], name=name)
    return control_flow_ops.no_op(name=name)

Returns an Op that initializes a list of variables.

After you launch the graph in a session, you can run the returned Op to
initialize all the variables in `var_list`. This Op runs all the
initializers of the variables in `var_list` in parallel.

Calling `initialize_variables()` is equivalent to passing the list of
initializers to `Group()`.

If `var_list` is empty, however, the function still returns an Op that can
be run. That Op just has no effect.

@compatibility(TF2)
In TF2, variables are initialized immediately when they are created. There is
no longer a need to run variable initializers before using them.
@end_compatibility

Args:
var_list: List of `Variable` objects to initialize.
name: Optional name for the returned operation.

Returns:
An Op that run the initializers of all the specified variables.


def pyxb_to_dict(rp_pyxb):
    return {'allowed': bool(_get_attr_or_list(rp_pyxb, 'allowed')), 'num': _get_as_int(rp_pyxb), 'block': _get_as_set(rp_pyxb, 'block'), 'pref': _get_as_set(rp_pyxb, 'pref')}

Convert ReplicationPolicy PyXB object to a normalized dict.

Args:
rp_pyxb: ReplicationPolicy to convert.

Returns:
dict : Replication Policy as normalized dict.

Example::

{
'allowed': True,
'num': 3,
'blockedMemberNode': {'urn:node:NODE1', 'urn:node:NODE2', 'urn:node:NODE3'},
'preferredMemberNode': {'urn:node:NODE4', 'urn:node:NODE5'},
}


def sd(line, cell=None):
    parser = google.datalab.utils.commands.CommandParser(prog='%sd', description='Execute various Stackdriver related operations. Use "%sd <stackdriver_product> -h" for help on a specific Stackdriver product.')
    _create_monitoring_subparser(parser)
    return google.datalab.utils.commands.handle_magic_line(line, cell, parser)

Implements the stackdriver cell magic for ipython notebooks.

Args:
line: the contents of the storage line.
Returns:
The results of executing the cell.


def greater_equal(x1, x2):
    if any_symbolic_tensors((x1, x2)):
        return GreaterEqual().symbolic_call(x1, x2)
    return backend.numpy.greater_equal(x1, x2)

Return the truth value of `x1 >= x2` element-wise.

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

Returns:
Output tensor, element-wise comparison of `x1` and `x2`.


def is_abstract(x: Any) -> bool:
    return utils.is_partial(x) or is_pure_symbolic(x)

Returns if the input value is abstract.

Example::

@pg.symbolize
class Foo:
def __init__(self, x):
pass

class Bar(pg.PureSymbolic):
pass

assert not pg.is_abstract(1)
assert not pg.is_abstract(Foo(1))
assert pg.is_abstract(Foo.partial())
assert pg.is_abstract(Bar())
assert pg.is_abstract(Foo(Bar()))
assert pg.is_abstract(Foo(pg.oneof([1, 2])))

Args:
x: Value to query against.

Returns:
True if value itself is partial/PureSymbolic or its child and nested
child fields contain partial/PureSymbolic values.


def calculate_row_format(columns, keys=None):

    row_format = ''
    if keys is None:
        keys = columns.keys()
    else:
        keys = [key for key in keys if key in columns]

    for key in keys:
        if len(row_format) > 0:
            row_format += "|"
        row_format += "%%(%s)-%ds" % (key, columns[key])

    return '|' + row_format + '|'

Calculate row format.

Args:
columns (dict): the keys are the column name and the value the max length.
keys (list): optional list of keys to order columns as well as to filter for them.

Returns:
str: format for table row


def search_stack_for_localvar(varname):

    curr_frame = inspect.currentframe()
    print(' * Searching parent frames for: ' + six.text_type(varname))
    frame_no = 0
    while curr_frame.f_back is not None:
        if varname in curr_frame.f_locals.keys():
            print(' * Found in frame: ' + six.text_type(frame_no))
            return curr_frame.f_locals[varname]
        frame_no += 1
        curr_frame = curr_frame.f_back
    print('... Found nothing in all ' + six.text_type(frame_no) + ' frames.')
    return None

Finds a local varable somewhere in the stack and returns the value

Args:
varname (str): variable name

Returns:
None if varname is not found else its value


def get_flag_value(self, wanted_flag_name):
    tensor_tracer_flags = self._env.get(FLAGS_ENV_VAR)
    if not tensor_tracer_flags:
        return (False, None)
    pos = 0
    while True:
        match, has_value = TTParameters.match_next_flag(tensor_tracer_flags, pos)
        if not match:
            return (False, None)
        flag_name = match.group(1)
        if has_value:
            flag_value = match.group(2)
        else:
            flag_value = None
        if flag_name == wanted_flag_name:
            return (True, flag_value)
        pos = match.end()
    raise RuntimeError('Invalid tensor tracer flag. Could not recognize %s.' % flag_name)

Returns the value of a TensorTracer flags.

Args:
wanted_flag_name: the name of the flag we are looking for.

Returns:
A pair where the first element indicates if the flag is
found and the second element is the value of the flag.

Raises:
RuntimeError: If supposedly deadcode is reached.


def underline(self, action):

        if action == 'off':
            action = '0'
            self.send(chr(27)+chr(45)+action)
        else:
            self.send(chr(27)+chr(45)+action)

Enable/cancel underline printing

Args:
action -- Enable or disable underline printing. Options are '1' - '4' and 'cancel'
Returns:
None
Raises:
None


def is_union(declaration):
    if (not is_class(declaration)):
        return False
    decl = class_traits.get_declaration(declaration)
    return (decl.class_type == class_declaration.CLASS_TYPES.UNION)

Returns True if declaration represents a C++ union

Args:
declaration (declaration_t): the declaration to be checked.

Returns:
bool: True if declaration represents a C++ union


def text(self, tag, textdata, step=None):

    if step is None:
      step = self._step
    else:
      self._step = step
    smd = SummaryMetadata(
        plugin_data=SummaryMetadata.PluginData(plugin_name='text'))
    if isinstance(textdata, (str, bytes)):
      tensor = tf.make_tensor_proto(
          values=[textdata.encode(encoding='utf_8')], shape=(1,))
    else:
      textdata = onp.array(textdata)
      datashape = onp.shape(textdata)
      if len(datashape) == 1:
        tensor = tf.make_tensor_proto(
            values=[td.encode(encoding='utf_8') for td in textdata],
            shape=(datashape[0],))
      elif len(datashape) == 2:
        tensor = tf.make_tensor_proto(
            values=[
                td.encode(encoding='utf_8') for td in onp.reshape(textdata, -1)
            ],
            shape=(datashape[0], datashape[1]))
    summary = Summary(
        value=[Summary.Value(tag=tag, metadata=smd, tensor=tensor)])
    self.add_summary(summary, step)

Saves a text summary.

Args:
tag: str: label for this data
textdata: string, or 1D/2D list/numpy array of strings
step: int: training step
Note: markdown formatting is rendered by tensorboard.


def get(cls, sha1=''):
    with conf.within_proj_dir():
        cmd = 'git show -s --format="%H||%an||%ae||%s||%b||%P" {}'.format(sha1)
        result = shell.run(cmd, capture=True, never_pretend=True).stdout
    (sha1, name, email, title, desc, parents) = result.split('||')
    return CommitDetails(sha1=sha1, author=Author(name, email), title=title, desc=desc, parents_sha1=parents.split())

Return details about a given commit.

Args:
sha1 (str):
The sha1 of the commit to query. If not given, it will return
the details for the latest commit.

Returns:
CommitDetails: Commit details. You can use the instance of the
class to query git tree further.


def resolve_identifier(self, name, expected_type=None):
    name = str(name)
    if (name in self._known_identifiers):
        obj = self._known_identifiers[name]
        if ((expected_type is not None) and (not isinstance(obj, expected_type))):
            raise UnresolvedIdentifierError(u'Identifier resolved to an object of an unexpected type', name=name, expected_type=expected_type.__name__, resolved_type=obj.__class__.__name__)
        return obj
    if (self.parent is not None):
        try:
            return self.parent.resolve_identifier(name)
        except UnresolvedIdentifierError:
            pass
    raise UnresolvedIdentifierError(u'Could not resolve identifier', name=name, scope=self.name)

Resolve an identifier to an object.

There is a single namespace for identifiers so the user also should
pass an expected type that will be checked against what the identifier
actually resolves to so that there are no surprises.

Args:
name (str): The name that we want to resolve
expected_type (type): The type of object that we expect to receive.
This is an optional parameter.  If None is passed, no type checking
is performed.

Returns:
object: The resolved object


def export_verified_variants(aggregate_variants, unique_callers):
    document_lines = []
    for variant in aggregate_variants:
        samples = []
        for sample in variant['samples']:
            line = []
            line.append(variant['institute'])
            line.append(variant['_id'])
            line.append(variant['category'])
            line.append(variant['variant_type'])
            line.append(variant['display_name'][:30])
            case_name = variant['case_obj']['display_name']
            local_link = '/'.join(['', variant['institute'], case_name, variant['_id']])
            line.append(local_link)
            line.append(variant.get('validation'))
            line.append(case_name)
            case_individual = next((ind for ind in variant['case_obj']['individuals'] if (ind['individual_id'] == sample['sample_id'])))
            if (case_individual['phenotype'] == 2):
                line.append(' '.join([sample.get('display_name'), '(A)']))
            else:
                line.append(sample.get('display_name'))
            line.append(''.join(['chr', variant['chromosome'], ':', str(variant['position'])]))
            line.append('>'.join([variant.get('reference')[:10], variant.get('alternative')[:10]]))
            genes = []
            prot_effect = []
            funct_anno = []
            for gene in variant.get('genes'):
                genes.append(gene.get('hgnc_symbol', ''))
                funct_anno.append(gene.get('functional_annotation'))
                for transcript in gene.get('transcripts'):
                    if (transcript.get('is_canonical') and transcript.get('protein_sequence_name')):
                        prot_effect.append(urllib.parse.unquote(transcript.get('protein_sequence_name')))
            line.append(','.join(prot_effect))
            line.append(','.join(funct_anno))
            line.append(','.join(genes))
            line.append(variant.get('rank_score'))
            line.append(variant.get('cadd_score'))
            line.append(sample.get('genotype_call'))
            line.append(sample['allele_depths'][0])
            line.append(sample['allele_depths'][1])
            line.append(sample['genotype_quality'])
            for caller in unique_callers:
                if variant.get(caller):
                    line.append(variant.get(caller))
                else:
                    line.append('-')
            document_lines.append(line)
    return document_lines

Create the lines for an excel file with verified variants for
an institute

Args:
aggregate_variants(list): a list of variants with aggregates case data
unique_callers(set): a unique list of available callers

Returns:
document_lines(list): list of lines to include in the document


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

Creates a new `BitbucketServerConfig`. This API is experimental.

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


def __init__(self, binary_id, cause=None):

    super(UnknownSignedBinaryError, self).__init__(binary_id, cause=cause)

    self.binary_id = binary_id
    self.message = ("Signed binary of type %s and path %s was not found" %
                    (self.binary_id.binary_type, self.binary_id.path))

Initializes UnknownSignedBinaryError.

Args:
binary_id: rdf_objects.SignedBinaryID for the signed binary.
cause: A lower-level Exception raised by the database driver, which might
have more details about the error.


def __init__(self, name=None, eid=None):

        if None not in (name, eid):
            raise TypeError("Provide only a `name` or an `eid`.")

        self._eid = eid or _get_enum(name)
        self._comments = EnumComments(self._eid)

Get an existing enum.

Only provide one of `name` and `eid`.

Args:
name: Name of the enum
eid: Enum ID


def tables_insert(self, table_name, schema=None, query=None, friendly_name=None, description=None):
    url = (Api._ENDPOINT + (Api._TABLES_PATH % (table_name.project_id, table_name.dataset_id, '', '')))
    data = {'kind': 'bigquery
    if schema:
        data['schema'] = {'fields': schema}
    if query:
        data['view'] = {'query': query}
    if friendly_name:
        data['friendlyName'] = friendly_name
    if description:
        data['description'] = description
    return datalab.utils.Http.request(url, data=data, credentials=self._credentials)

Issues a request to create a table or view in the specified dataset with the specified id.
A schema must be provided to create a Table, or a query must be provided to create a View.

Args:
table_name: the name of the table as a tuple of components.
schema: the schema, if this is a Table creation.
query: the query, if this is a View creation.
friendly_name: an optional friendly name.
description: an optional description.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.


def offTagDel(self, name, func):
    if ('*' in name):
        self.ontagdelglobs.rem(name, func)
        return
    cblist = self.ontagdels.get(name)
    if (cblist is None):
        return
    try:
        cblist.remove(func)
    except ValueError:
        pass

Unregister a callback for tag deletion.

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


def __init__(self, line: Optional[Text] = None):

        self.line = line or self.default_separator
        super(Separator, self).__init__(self.line, None, "-")

Create a separator in a list.

Args:
line: Text to be displayed in the list, by default uses `---`.


def netmiko_file_transfer(task: Task, source_file: str, dest_file: str, **kwargs: Any) -> Result:
    net_connect = task.host.get_connection('netmiko', task.nornir.config)
    kwargs.setdefault('direction', 'put')
    scp_result = file_transfer(net_connect, source_file=source_file, dest_file=dest_file, **kwargs)
    if (kwargs.get('disable_md5') is True):
        file_valid = scp_result['file_exists']
    else:
        file_valid = (scp_result['file_exists'] and scp_result['file_verified'])
    return Result(host=task.host, result=file_valid, changed=scp_result['file_transferred'])

Execute Netmiko file_transfer method

Arguments:
source_file: Source file.
dest_file: Destination file.
kwargs: Additional arguments to pass to file_transfer

Returns:
Result object with the following attributes set:
* result (``bool``): file exists and MD5 is valid
* changed (``bool``): the destination file was changed


def _ExtractJQuery(self, jquery_raw):

    data_part = ''
    if not jquery_raw:
      return {}

    if '[' in jquery_raw:
      _, _, first_part = jquery_raw.partition('[')
      data_part, _, _ = first_part.partition(']')
    elif jquery_raw.startswith('
      _, _, first_part = jquery_raw.partition('{')
      data_part = '{{{0:s}'.format(first_part)
    elif '({' in jquery_raw:
      _, _, first_part = jquery_raw.partition('(')
      data_part, _, _ = first_part.rpartition(')')

    if not data_part:
      return {}

    try:
      data_dict = json.loads(data_part)
    except ValueError:
      return {}

    return data_dict

Extracts values from a JQuery string.

Args:
jquery_raw (str): JQuery string.

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


def build_tab_completion_table(alias_table):

    alias_commands = [t[1] for t in filter_aliases(alias_table)]
    tab_completion_table = defaultdict(list)
    for alias_command in alias_commands:
        for reserved_command in azext_alias.cached_reserved_commands:

            if reserved_command == alias_command or reserved_command.startswith(alias_command + ' ') \
                    and '' not in tab_completion_table[alias_command]:
                tab_completion_table[alias_command].append('')
            elif ' {} '.format(alias_command) in reserved_command or reserved_command.endswith(' ' + alias_command):

                index = reserved_command.index(alias_command)
                parent_command = reserved_command[:index - 1]
                if parent_command not in tab_completion_table[alias_command]:
                    tab_completion_table[alias_command].append(parent_command)

    with open(GLOBAL_ALIAS_TAB_COMP_TABLE_PATH, 'w') as f:
        f.write(json.dumps(tab_completion_table))

    return tab_completion_table

Build a dictionary where the keys are all the alias commands (without positional argument placeholders)
and the values are all the parent commands of the keys. After that, write the table into a file.
The purpose of the dictionary is to validate the alias tab completion state.

For example:
{
"group": ["", "ad"],
"dns": ["network"]
}

Args:
alias_table: The alias table.

Returns:
The tab completion table.


def iter(self, max_value: int) -> Iterator[int]:

        return chain.from_iterable(
            (self._get_range(elem, max_value) for elem in self.sequences))

Iterates through the sequence numbers contained in the set, bounded
by the given maximum value (in place of any ``*``).

Args:
max_value: The maximum value of the set.


def isClientCert(self, name):

        crtpath = self._getPathJoin('users', '%s.p12' % name)
        return os.path.isfile(crtpath)

Checks if a user client certificate (PKCS12) exists.

Args:
name (str): The name of the user keypair.

Examples:
Check if the client certificate "myuser" exists:

exists = cdir.isClientCert('myuser')

Returns:
bool: True if the certificate is present, False otherwise.


def Send(self, command_id, data=b'', size=0):

        if data:
            if not isinstance(data, bytes):
                data = data.encode('utf8')
            size = len(data)

        if not self._CanAddToSendBuffer(len(data)):
            self._Flush()
        buf = struct.pack(b'<2I', self.id_to_wire[command_id], size) + data
        self.send_buffer[self.send_idx:self.send_idx + len(buf)] = buf
        self.send_idx += len(buf)

Send/buffer FileSync packets.

Packets are buffered and only flushed when this connection is read from. All
messages have a response from the device, so this will always get flushed.

Args:
command_id: Command to send.
data: Optional data to send, must set data or size.
size: Optionally override size from len(data).


def filename(self, fname, timestep=None, suffix='', force_legacy=False):

        if timestep is not None:
            fname += '{:05d}'.format(timestep)
        fname += suffix
        if not force_legacy and self.hdf5:
            fpath = self.hdf5 / fname
        else:
            fpath = self.par['ioin']['output_file_stem'] + '_' + fname
            fpath = self.path / fpath
        return fpath

Return name of StagYY output file.

Args:
fname (str): name stem.
timestep (int): snapshot number, set to None if this is not
relevant.
suffix (str): optional suffix of file name.
force_legacy (bool): force returning the legacy output path.
Returns:
:class:`pathlib.Path`: the path of the output file constructed
with the provided segments.


def resolves_for(self, node):

        self.node = node
        self.actual_styles = node.style(*self.expected_styles.keys())

        return all(
            toregex(value).search(self.actual_styles[style])
            for style, value in iter(self.expected_styles.items()))

Resolves this query relative to the given node.

Args:
node (node.Base): The node to be evaluated.

Returns:
int: The number of matches found.


def DeletePendingNotification(self, timestamp):

    shown_notifications = self.Get(self.Schema.SHOWN_NOTIFICATIONS)
    if not shown_notifications:
      shown_notifications = self.Schema.SHOWN_NOTIFICATIONS()

    pending = self.Get(self.Schema.PENDING_NOTIFICATIONS)
    if not pending:
      return

    delete_count = 0
    for idx in reversed(range(0, len(pending))):
      if pending[idx].timestamp == timestamp:
        shown_notifications.Append(pending[idx])
        pending.Pop(idx)
        delete_count += 1

    if delete_count > 1:
      raise UniqueKeyError("Multiple notifications at %s" % timestamp)

    self.Set(self.Schema.PENDING_NOTIFICATIONS, pending)
    self.Set(self.Schema.SHOWN_NOTIFICATIONS, shown_notifications)

Deletes the pending notification with the given timestamp.

Args:
timestamp: The timestamp of the notification. Assumed to be unique.

Raises:
UniqueKeyError: Raised if multiple notifications have the timestamp.


def remove_volume(self, name, force=False):
    params = {}
    if force:
        if utils.version_lt(self._version, '1.25'):
            raise errors.InvalidVersion('force removal was introduced in API 1.25')
        params = {'force': force}
    url = self._url('/volumes/{0}', name, params=params)
    resp = self._delete(url)
    self._raise_for_status(resp)

Remove a volume. Similar to the ``docker volume rm`` command.

Args:
name (str): The volume's name
force (bool): Force removal of volumes that were already removed
out of band by the volume driver plugin.

Raises:
:py:class:`docker.errors.APIError`
If volume failed to remove.


def avg_grads(tower_grads):

  average_grads = []
  for grad_and_vars in zip(*tower_grads):

    grads = []
    for g, _ in grad_and_vars:

      expanded_g = tf.expand_dims(g, 0)

      grads.append(expanded_g)

    grad = tf.concat(0, grads)
    grad = tf.reduce_mean(grad, 0)

    v = grad_and_vars[0][1]
    grad_and_var = (grad, v)
    average_grads.append(grad_and_var)
  return average_grads

Calculate the average gradient for each shared variable across all towers.

Note that this function provides a synchronization point across all towers.

Args:
tower_grads: List of lists of (gradient, variable) tuples. The outer list
is over individual gradients. The inner list is over the gradient
calculation for each tower.
Returns:
List of pairs of (gradient, variable) where the gradient has been averaged
across all towers.


def broadcast_dynamic_shape(shape_x, shape_y):
    if not isinstance(shape_x, RaggedTensorDynamicShape):
        raise TypeError('shape_x must be a RaggedTensorDynamicShape')
    if not isinstance(shape_y, RaggedTensorDynamicShape):
        raise TypeError('shape_y must be a RaggedTensorDynamicShape')
    if shape_x.rank is None or shape_y.rank is None:
        raise ValueError('Unable to broadcast: unknown rank')
    broadcast_rank = max(shape_x.rank, shape_y.rank)
    shape_x = shape_x.broadcast_to_rank(broadcast_rank)
    shape_y = shape_y.broadcast_to_rank(broadcast_rank)
    for axis in range(broadcast_rank):
        shape_x = shape_x.broadcast_dimension(axis, shape_y.dimension_size(axis))
        shape_y = shape_y.broadcast_dimension(axis, shape_x.dimension_size(axis))
    return shape_x

Returns the shape formed by broadcasting two shapes to be compatible.

Args:
shape_x: A `RaggedTensorDynamicShape`
shape_y: A `RaggedTensorDynamicShape`

Returns:
A `RaggedTensorDynamicShape`.
Raises:
ValueError: If `shape_x` and `shape_y` are not broadcast-compatible.


def remove_chain(self, name):

        if name in self.chains:
            delattr(self.chains, name)
        else:
            raise ValueError("Chain with this name not found")

Remove chain from current shelve file

Args:
name: chain name


def add_completions(
    replace_list: list, belstr: str, replace_span: Span, completion_text: str
) -> List[Mapping[str, Any]]:

    completions = []

    for r in replace_list:

        if len(belstr) > 0:
            belstr_end = len(belstr) - 1
        else:
            belstr_end = 0

        log.debug(
            f'Replace list {r}  Replace_span {replace_span}  BELstr: {belstr} Len: {belstr_end} Test1 {r["type"] == "Function"}  Test2 {replace_span[1] + 1 == len(belstr)}'
        )

        if (
            r["type"] == "Function"
            and replace_span[0] > 0
            and belstr[replace_span[0] - 1] == ","
        ):
            log.debug("prior char is a comma")
            replacement = (
                belstr[0 : replace_span[0]]
                + " "
                + f"{r['replacement']}()"
                + belstr[replace_span[1] + 1 :]
            )
            cursor_loc = len(
                belstr[0 : replace_span[0]] + " " + f"{r['replacement']}()"
            )

        elif replace_span[0] > 0 and belstr[replace_span[0] - 1] == ",":
            log.debug("prior char is a comma")
            replacement = (
                belstr[0 : replace_span[0]]
                + " "
                + r["replacement"]
                + belstr[replace_span[1] + 1 :]
            )
            cursor_loc = len(belstr[0 : replace_span[0]] + " " + r["replacement"])

        elif r["type"] == "Function" and replace_span[1] >= belstr_end:
            replacement = belstr[0 : replace_span[0]] + f"{r['replacement']}()"
            cursor_loc = len(replacement) - 1
            log.debug(f"Replacement: {replacement}")

        else:
            replacement = (
                belstr[0 : replace_span[0]]
                + r["replacement"]
                + belstr[replace_span[1] + 1 :]
            )
            cursor_loc = len(
                belstr[0 : replace_span[0]] + r["replacement"]
            )

        completions.append(
            {
                "replacement": replacement,
                "cursor_loc": cursor_loc,
                "highlight": r["highlight"],
                "label": r["label"],
            }
        )

    return completions

Create completions to return given replacement list

Args:
replace_list: list of completion replacement values
belstr: BEL String
replace_span: start, stop of belstr to replace
completion_text: text to use for completion - used for creating highlight
Returns:
[{
"replacement": replacement,
"cursor_loc": cursor_loc,
"highlight": highlight,
"label": label,
}]


def to_b58check(self, testnet=False):
    version = (self.TESTNET_VERSION if testnet else self.MAINNET_VERSION)
    return base58.b58encode_check((bytes([version]) + bytes(self)))

Generates a Base58Check encoding of this private key.

Returns:
str: A Base58Check encoded string representing the key.


def get_package_hashes(filename):

    log.debug('Getting package hashes')
    filename = os.path.abspath(filename)
    with open(filename, 'rb') as f:
        data = f.read()

    _hash = hashlib.sha256(data).hexdigest()
    log.debug('Hash for file %s: %s', filename, _hash)
    return _hash

Provides hash of given filename.

Args:

filename (str): Name of file to hash

Returns:

(str): sha256 hash


def core_name(self):

        buf_size = self.MAX_BUF_SIZE
        buf = (ctypes.c_char * buf_size)()
        self._dll.JLINKARM_Core2CoreName(self.core_cpu(), buf, buf_size)
        return ctypes.string_at(buf).decode()

Returns the name of the target ARM core.

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

Returns:
The target core's name.


def bind_sockets(address, port):
    ss = netutil.bind_sockets(port=(port or 0), address=address)
    assert len(ss)
    ports = {s.getsockname()[1] for s in ss}
    assert (len(ports) == 1), 'Multiple ports assigned??'
    actual_port = ports.pop()
    if port:
        assert (actual_port == port)
    return (ss, actual_port)

Bind a socket to a port on an address.

Args:
address (str) :
An address to bind a port on, e.g. ``"localhost"``

port (int) :
A port number to bind.

Pass 0 to have the OS automatically choose a free port.

This function returns a 2-tuple with the new socket as the first element,
and the port that was bound as the second. (Useful when passing 0 as a port
number to bind any free port.)

Returns:
(socket, port)


def add_key_value(self, key, value):
    key = self._metadata_map.get(key, key)
    if (key in ['dateAdded', 'eventDate', 'firstSeen', 'publishDate']):
        self._group_data[key] = self._utils.format_datetime(value, date_format='%Y-%m-%dT%H:%M:%SZ')
    elif (key == 'file_content'):
        pass
    else:
        self._group_data[key] = value

Add custom field to Group object.

.. note:: The key must be the exact name required by the batch schema.

Example::

document = tcex.batch.group('Document', 'My Document')
document.add_key_value('fileName', 'something.pdf')

Args:
key (str): The field key to add to the JSON batch data.
value (str): The field value to add to the JSON batch data.


def copy_docstring(source_class):

    def decorator(method):
        'Decorator implementation.\n\n        Args:\n            method (Callable): The method to copy the docstring to.\n\n        Returns:\n            Callable: the same method passed in with an updated docstring.\n\n        Raises:\n            ValueError: if the method already has a docstring.\n        '
        if method.__doc__:
            raise ValueError('Method already has a docstring.')
        source_method = getattr(source_class, method.__name__)
        method.__doc__ = source_method.__doc__
        return method
    return decorator

Decorator that copies a method's docstring from another class.

Args:
source_class (type): The class that has the documented method.

Returns:
Callable: A decorator that will copy the docstring of the same
named method in the source class to the decorated method.


def permut2expr(self, P):
    if (len(P) > (1 << self.nbits)):
        raise ValueError(('P must not contain more than %d elements' % (1 << self.nbits)))
    X = self.var('X')
    ret = super(MBA, self).permut2expr(P, X.vec)
    return (self.from_vec(ret), X)

Convert a substitution table into an arybo application

Args:
P: list of integers. The list must not contain more than 2**nbits elements.

Returns:
A tuple containing an :class:`MBAVariable` object with the result
and the symbolic input variable used in this object. A typical use
case is to feed these into vectorial_decomp.

Example:
>>> mba = MBA(4)
>>> P = [i^7 for i in range(16)]
>>> E,X = mba.permut2expr(P)
>>> E.vectorial_decomp([X])
App NL = Vec([
0,
0,
0,
0
])
AffApp matrix = Mat([
[1, 0, 0, 0]
[0, 1, 0, 0]
[0, 0, 1, 0]
[0, 0, 0, 1]
])
AffApp cst = Vec([
1,
1,
1,
0
])


def object_table(self, object_id=None):

        self._check_connected()
        if object_id is not None:

            return self._object_table(object_id)
        else:

            object_keys = self._keys(ray.gcs_utils.TablePrefix_OBJECT_string +
                                     "*")
            object_ids_binary = {
                key[len(ray.gcs_utils.TablePrefix_OBJECT_string):]
                for key in object_keys
            }

            results = {}
            for object_id_binary in object_ids_binary:
                results[binary_to_object_id(object_id_binary)] = (
                    self._object_table(binary_to_object_id(object_id_binary)))
            return results

Fetch and parse the object table info for one or more object IDs.

Args:
object_id: An object ID to fetch information about. If this is
None, then the entire object table is fetched.

Returns:
Information from the object table.


def depth_october_average_ground_temperature(self, value=None):

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

        self._depth_october_average_ground_temperature = value

Corresponds to IDD Field `depth_october_average_ground_temperature`

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

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


def addFileHandler(self,filename='', dr='',lvl=1):

        fname = self.name
        if filename != '':
            fname = filename
        if '.' not in fname:
            fname+='.log'
        fh = logging.FileHandler(os.path.join(dr,fname))
        fh.setLevel(lvl)
        frmtString = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
        fFrmt = logging.Formatter(frmtString)
        fh.setFormatter(fFrmt)
        self.addHandler(fh)

This function will add a file handler to a log with the provided level.

Args:
lvl (int): The severity level of messages printed to the file with
the file handler, default = 1.


def model_spec(ops, matrix):
    return api.ModelSpec(matrix=np.array(matrix), ops=[INPUT] + ops + [OUTPUT])

NASBench model spec that is parameterized by ops and their connections.

Args:
ops: a list of allowed ops except the INPUT and OUTPUT layer.
matrix: the adjacency matrix for the connectivity of each layers, which
should be an upper triangle matrix.

Returns:
A NASBench spec.


def normalize(self, image, mean, std, rescale=False):
    self._ensure_format_supported(image)
    if isinstance(image, PIL.Image.Image):
        image = self.to_numpy_array(image, rescale=True)
    elif rescale:
        if isinstance(image, np.ndarray):
            image = self.rescale(image.astype(np.float32), 1 / 255.0)
        elif is_torch_tensor(image):
            image = self.rescale(image.float(), 1 / 255.0)
    if isinstance(image, np.ndarray):
        if not isinstance(mean, np.ndarray):
            mean = np.array(mean).astype(image.dtype)
        if not isinstance(std, np.ndarray):
            std = np.array(std).astype(image.dtype)
    elif is_torch_tensor(image):
        import torch
        if not isinstance(mean, torch.Tensor):
            if isinstance(mean, np.ndarray):
                mean = torch.from_numpy(mean)
            else:
                mean = torch.tensor(mean)
        if not isinstance(std, torch.Tensor):
            if isinstance(std, np.ndarray):
                std = torch.from_numpy(std)
            else:
                std = torch.tensor(std)
    if image.ndim == 3 and image.shape[0] in [1, 3]:
        return (image - mean[:, None, None]) / std[:, None, None]
    else:
        return (image - mean) / std

Normalizes `image` with `mean` and `std`. Note that this will trigger a conversion of `image` to a NumPy array
if it's a PIL Image.

Args:
image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
The image to normalize.
mean (`List[float]` or `np.ndarray` or `torch.Tensor`):
The mean (per channel) to use for normalization.
std (`List[float]` or `np.ndarray` or `torch.Tensor`):
The standard deviation (per channel) to use for normalization.
rescale (`bool`, *optional*, defaults to `False`):
Whether or not to rescale the image to be between 0 and 1. If a PIL image is provided, scaling will
happen automatically.


def cancelPnL(self, account, modelCode: str = ''):

        key = (account, modelCode)
        reqId = self.wrapper.pnlKey2ReqId.pop(key, None)
        if reqId:
            self.client.cancelPnL(reqId)
            self.wrapper.pnls.pop(reqId, None)
        else:
            self._logger.error(
                'cancelPnL: No subscription for '
                f'account {account}, modelCode {modelCode}')

Cancel PnL subscription.

Args:
account: Cancel for this account.
modelCode: If specified, cancel for this account model.


def ParseOptions(cls, options, output_module):

    if not isinstance(output_module, timesketch_out.TimesketchOutputModule):
      raise errors.BadConfigObject(
          'Output module is not an instance of TimesketchOutputModule')

    document_type = cls._ParseStringOption(
        options, 'document_type', default_value=cls._DEFAULT_DOCUMENT_TYPE)
    output_module.SetDocumentType(document_type)

    flush_interval = cls._ParseNumericOption(
        options, 'flush_interval', default_value=cls._DEFAULT_FLUSH_INTERVAL)
    output_module.SetFlushInterval(flush_interval)

    index = cls._ParseStringOption(
        options, 'index', default_value=cls._DEFAULT_UUID)
    output_module.SetIndexName(index)

    name = cls._ParseStringOption(
        options, 'timeline_name', default_value=cls._DEFAULT_NAME)
    output_module.SetTimelineName(name)

    username = cls._ParseStringOption(
        options, 'username', default_value=cls._DEFAULT_USERNAME)
    output_module.SetTimelineOwner(username)

Parses and validates options.

Args:
options (argparse.Namespace): parser options.
output_module (TimesketchOutputModule): output module to configure.

Raises:
BadConfigObject: when the output module object is of the wrong type.
BadConfigOption: when a configuration parameter fails validation.


def load_wav_file(filename):
    with tf.compat.v1.Session(graph=tf.Graph()) as sess:
        wav_filename_placeholder = tf.compat.v1.placeholder(tf.string, [])
        wav_loader = io_ops.read_file(wav_filename_placeholder)
        wav_decoder = tf.audio.decode_wav(wav_loader, desired_channels=1)
        return sess.run(wav_decoder, feed_dict={wav_filename_placeholder: filename}).audio.flatten()

Loads an audio file and returns a float PCM-encoded array of samples.

Args:
filename: Path to the .wav file to load.

Returns:
Numpy array holding the sample data as floats between -1.0 and 1.0.


def loss(logits, labels, batch_size=None):
    if (not batch_size):
        batch_size = FLAGS.batch_size
    sparse_labels = tf.reshape(labels, [batch_size, 1])
    indices = tf.reshape(tf.range(batch_size), [batch_size, 1])
    concated = tf.concat(axis=1, values=[indices, sparse_labels])
    num_classes = logits[0].get_shape()[(- 1)].value
    dense_labels = tf.sparse_to_dense(concated, [batch_size, num_classes], 1.0, 0.0)
    slim.losses.cross_entropy_loss(logits[0], dense_labels, label_smoothing=0.1, weight=1.0)
    slim.losses.cross_entropy_loss(logits[1], dense_labels, label_smoothing=0.1, weight=0.4, scope='aux_loss')

Adds all losses for the model.

Note the final loss is not returned. Instead, the list of losses are collected
by slim.losses. The losses are accumulated in tower_loss() and summed to
calculate the total loss.

Args:
logits: List of logits from inference(). Each entry is a 2-D float Tensor.
labels: Labels from distorted_inputs or inputs(). 1-D tensor
of shape [batch_size]
batch_size: integer


def get_query_info(sql, con, partition_column):

    engine = create_engine(con)
    if is_table(engine, sql):
        table_metadata = get_table_metadata(engine, sql)
        query = build_query_from_table(sql)
        cols = get_table_columns(table_metadata)
    else:
        check_query(sql)
        query = sql.replace(";", "")
        cols = get_query_columns(engine, query)

    cols_names = list(cols.keys())
    return cols_names, query

Return a columns name list and the query string

Args:
sql: SQL query or table name
con: database connection or url string
partition_column: column used to share the data between the workers

Returns:
Columns name list and query string


def every_match(self, callback, **kwargs):
    if (len(kwargs) == 0):
        raise ArgumentError('You must specify at least one message field to wait on')
    spec = MessageSpec(**kwargs)
    responder = self._add_waiter(spec, callback)
    return (spec, responder)

Invoke callback every time a matching message is received.

The callback will be invoked directly inside process_message so that
you can guarantee that it has been called by the time process_message
has returned.

The callback can be removed by a call to remove_waiter(), passing the
handle object returned by this call to identify it.

Args:
callback (callable): A callable function that will be called as
callback(message) whenever a matching message is received.

Returns:
object: An opaque handle that can be passed to remove_waiter().

This handle is the only way to remove this callback if you no
longer want it to be called.


def forward(self, hidden_states: torch.Tensor, position_embeddings: Optional[torch.Tensor]=None, reference_points=None, spatial_shapes=None, spatial_shapes_list=None, level_start_index=None, encoder_hidden_states: Optional[torch.Tensor]=None, encoder_attention_mask: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=False):
    residual = hidden_states
    hidden_states, self_attn_weights = self.self_attn(hidden_states=hidden_states, position_embeddings=position_embeddings, output_attentions=output_attentions)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    second_residual = hidden_states
    cross_attn_weights = None
    hidden_states, cross_attn_weights = self.encoder_attn(hidden_states=hidden_states, attention_mask=encoder_attention_mask, encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=encoder_attention_mask, position_embeddings=position_embeddings, reference_points=reference_points, spatial_shapes=spatial_shapes, spatial_shapes_list=spatial_shapes_list, level_start_index=level_start_index, output_attentions=output_attentions)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = second_residual + hidden_states
    hidden_states = self.encoder_attn_layer_norm(hidden_states)
    residual = hidden_states
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = nn.functional.dropout(hidden_states, p=self.activation_dropout, training=self.training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (self_attn_weights, cross_attn_weights)
    return outputs

Args:
hidden_states (`torch.FloatTensor`):
Input to the layer of shape `(seq_len, batch, embed_dim)`.
position_embeddings (`torch.FloatTensor`, *optional*):
Position embeddings that are added to the queries and keys in the self-attention layer.
reference_points (`torch.FloatTensor`, *optional*):
Reference points.
spatial_shapes (`torch.LongTensor`, *optional*):
Spatial shapes.
level_start_index (`torch.LongTensor`, *optional*):
Level start index.
encoder_hidden_states (`torch.FloatTensor`):
cross attention input to the layer of shape `(seq_len, batch, embed_dim)`
encoder_attention_mask (`torch.FloatTensor`): encoder attention mask of size
`(batch, 1, target_len, source_len)` where padding elements are indicated by very large negative
values.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.


def attach(self, engine, start=Events.STARTED, pause=Events.COMPLETED, resume=None, step=None):
    engine.add_event_handler(start, self.reset)
    engine.add_event_handler(pause, self.pause)
    if (resume is not None):
        engine.add_event_handler(resume, self.resume)
    if (step is not None):
        engine.add_event_handler(step, self.step)
    return self

Register callbacks to control the timer.

Args:
engine (Engine):
Engine that this timer will be attached to.
start (Events):
Event which should start (reset) the timer.
pause (Events):
Event which should pause the timer.
resume (Events, optional):
Event which should resume the timer.
step (Events, optional):
Event which should call the `step` method of the counter.

Returns:
self (Timer)


def parse_iso8601_str(string):
    datetime_obj = datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ')
    return int(calendar.timegm(datetime_obj.utctimetuple()))

Parse a fixed ISO8601 datetime string.

.. Note:: This function only parses dates in the format
``%Y-%m-%dT%H:%M:%SZ``. You must use a library like ``dateutils``
to properly parse dates and times.

Returns:
float: A UNIX timestamp.


def _any_overlap_or_contiguous(self, test_overlap: bool) -> bool:
    for i in range(len(self.intervals)):
        for j in range((i + 1), len(self.intervals)):
            first = self.intervals[i]
            second = self.intervals[j]
            if test_overlap:
                test = first.overlaps(second)
            else:
                test = first.contiguous(second)
            if test:
                return True
    return False

Do any of the intervals overlap?

Args:
test_overlap: if ``True``, test for overlapping intervals; if
``False``, test for contiguous intervals.


def _bigbird_block_rand_mask(self, from_seq_length, to_seq_length, from_block_size, to_block_size, num_rand_blocks, last_idx=-1):
    if from_seq_length
        raise ValueError('Error the number of blocks needs to be same!')
    rand_attn = np.zeros((from_seq_length
    if not self.training:
        return rand_attn
    middle_seq = np.arange(1, to_seq_length
    last = to_seq_length
    if last_idx > 2 * to_block_size:
        last = last_idx
    r = num_rand_blocks
    for i in range(1, from_seq_length
        start = i - 2
        end = i
        if i == 1:
            rand_attn[i - 1, :] = np.random.permutation(middle_seq[2:last])[:r]
        elif i == 2:
            rand_attn[i - 1, :] = np.random.permutation(middle_seq[3:last])[:r]
        elif i == from_seq_length
            rand_attn[i - 1, :] = np.random.permutation(middle_seq[:last])[:r]
        elif i == from_seq_length
            rand_attn[i - 1, :] = np.random.permutation(middle_seq[:last])[:r]
        elif start > last:
            start = last
            rand_attn[i - 1, :] = np.random.permutation(middle_seq[:start])[:r]
        elif end + 1 == last:
            rand_attn[i - 1, :] = np.random.permutation(middle_seq[:start])[:r]
        else:
            rand_attn[i - 1, :] = np.random.permutation(np.concatenate((middle_seq[:start], middle_seq[end + 1:last])))[:r]
    return rand_attn

Create adjacency list of random attention.

Args:
from_seq_length: int. length of from sequence.
to_seq_length: int. length of to sequence.
from_block_size: int. size of block in from sequence.
to_block_size: int. size of block in to sequence.
num_rand_blocks: int. Number of random chunks per row.
last_idx: if -1 then num_rand_blocks blocks chosen anywhere in to sequence,
if positive then num_rand_blocks blocks chosen only up to last_idx.

Returns:
adjacency list of size from_seq_length//from_block_size-2 by num_rand_blocks


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 make_layer_stack(layers=gin.REQUIRED, num_layers=6):

  return LayerStack([cls() for cls in layers] * num_layers)

Configurable layer stack.

Args:
layers: a list of subclasses of TransformerLayer
num_layers: an integer
Returns:
a LayerStack


def GetPresetsInformation(cls):
    parser_presets_information = []
    for preset_definition in ParsersManager.GetPresets():
        preset_information_tuple = (preset_definition.name, ', '.join(preset_definition.parsers))
        parser_presets_information.append(preset_information_tuple)
    return parser_presets_information

Retrieves the presets information.

Returns:
list[tuple]: containing:

str: preset name
str: comma separated parser names that are defined by the preset


class UnivNetModelOutput(ModelOutput):
    waveforms: Optional[torch.FloatTensor] = None
    waveform_lengths: Optional[torch.FloatTensor] = None

Output class for the [`UnivNetModel`], which includes the generated audio waveforms and the original unpadded
lengths of those waveforms (so that the padding can be removed by [`UnivNetModel.batch_decode`]).

Args:
waveforms (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
Batched 1D (mono-channel) output audio waveforms.
waveform_lengths (`torch.FloatTensor` of shape `(batch_size,)`):
The batched length in samples of each unpadded waveform in `waveforms`.


def EnsureGdbPosition(self, pid, tid, frame_depth):

    position = [pid, tid, frame_depth]
    if not pid:
      return
    if not self.IsAttached():
      try:
        self.Attach(position)
      except gdb.error as exc:
        raise PositionUnavailableException(exc.message)
    if gdb.selected_inferior().pid != pid:
      self.Detach()
      try:
        self.Attach(position)
      except gdb.error as exc:
        raise PositionUnavailableException(exc.message)

    if tid:
      tstate_head = GdbCache.INTERP_HEAD['tstate_head']
      for tstate in self._IterateChainedList(tstate_head, 'next'):
        if tid == tstate['thread_id']:
          self.selected_tstate = tstate
          break
      else:
        raise PositionUnavailableException('Thread %s does not exist.' %
                                           str(tid))
      stack_head = self.selected_tstate['frame']
      if frame_depth is not None:
        frames = list(self._IterateChainedList(stack_head, 'f_back'))
        frames.reverse()
        try:
          self.selected_frame = frames[frame_depth]
        except IndexError:
          raise PositionUnavailableException('Stack is not %s frames deep' %
                                             str(frame_depth + 1))

Make sure our position matches the request.

Args:
pid: The process ID of the target process
tid: The python thread ident of the target thread
frame_depth: The 'depth' of the requested frame in the frame stack
Raises:
PositionUnavailableException: If the requested process, thread or frame
can't be found or accessed.


def _kernel(kernel_spec):
    if isinstance(kernel_spec, tf.compat.integral_types):
        return [kernel_spec, kernel_spec]
    elif (len(kernel_spec) == 1):
        return [kernel_spec[0], kernel_spec[0]]
    else:
        assert (len(kernel_spec) == 2)
        return kernel_spec

Expands the kernel spec into a length 2 list.

Args:
kernel_spec: An integer or a length 1 or 2 sequence that is expanded to a
list.
Returns:
A length 2 list.


def connect_to(self, vertex, weight=1):

        for edge in self.edges_out:
            if vertex == edge.vertex_in:
                return edge
        return Edge(self, vertex, weight)

Connect this vertex to another one.

Args:
vertex (Vertex): vertex to connect to.
weight (int): weight of the edge.

Returns:
Edge: the newly created edge.