def _ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None,
                                scope=None, syntax=None):

    if package:
      desc_name = '.'.join((package, desc_proto.name))
    else:
      desc_name = desc_proto.name

    if file_desc is None:
      file_name = None
    else:
      file_name = file_desc.name

    if scope is None:
      scope = {}

    nested = [
        self._ConvertMessageDescriptor(
            nested, desc_name, file_desc, scope, syntax)
        for nested in desc_proto.nested_type]
    enums = [
        self._ConvertEnumDescriptor(enum, desc_name, file_desc, None, scope)
        for enum in desc_proto.enum_type]
    fields = [self._MakeFieldDescriptor(field, desc_name, index)
              for index, field in enumerate(desc_proto.field)]
    extensions = [
        self._MakeFieldDescriptor(extension, desc_name, index,
                                  is_extension=True)
        for index, extension in enumerate(desc_proto.extension)]
    oneofs = [
        descriptor.OneofDescriptor(desc.name, '.'.join((desc_name, desc.name)),
                                   index, None, [], desc.options)
        for index, desc in enumerate(desc_proto.oneof_decl)]
    extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range]
    if extension_ranges:
      is_extendable = True
    else:
      is_extendable = False
    desc = descriptor.Descriptor(
        name=desc_proto.name,
        full_name=desc_name,
        filename=file_name,
        containing_type=None,
        fields=fields,
        oneofs=oneofs,
        nested_types=nested,
        enum_types=enums,
        extensions=extensions,
        options=_OptionsOrNone(desc_proto),
        is_extendable=is_extendable,
        extension_ranges=extension_ranges,
        file=file_desc,
        serialized_start=None,
        serialized_end=None,
        syntax=syntax)
    for nested in desc.nested_types:
      nested.containing_type = desc
    for enum in desc.enum_types:
      enum.containing_type = desc
    for field_index, field_desc in enumerate(desc_proto.field):
      if field_desc.HasField('oneof_index'):
        oneof_index = field_desc.oneof_index
        oneofs[oneof_index].fields.append(fields[field_index])
        fields[field_index].containing_oneof = oneofs[oneof_index]

    scope[_PrefixWithDot(desc_name)] = desc
    self._descriptors[desc_name] = desc
    return desc

Adds the proto to the pool in the specified package.

Args:
desc_proto: The descriptor_pb2.DescriptorProto protobuf message.
package: The package the proto should be located in.
file_desc: The file containing this message.
scope: Dict mapping short and full symbols to message and enum types.
syntax: string indicating syntax of the file ("proto2" or "proto3")

Returns:
The added descriptor.


def build_url(self):
    url = '{protocol}/{url}/{rest}/{version}/{restapi}/{rscpath}/{query}'.format(protocol=self.schema.protocol, url=self.schema.main_url, rest=self.schema.rest, version=self.schema.version, restapi=self.schema.restApi, rscpath=self.schema.resourcePath, query=self.schema.query)
    return url.replace('/None/', '/')

Builds the URL for elevations API services based on the data given
by the user.

Returns:
url (str): URL for the elevations API services


def _check_sleep(self, op):
    delay = 0.3
    start_t = time.time()
    func = tf.function(lambda: op(delay))
    results = self.evaluate(func())
    end_t = time.time()
    delta_t = end_t - start_t
    self.assertEqual(results.shape, tuple())
    self.assertGreater(delta_t, 0.9 * delay)

Check that one sleep op works in isolation.

See sleep_bin.py for an example of how the synchronous and asynchronous
sleep ops differ in behavior.

Args:
op: The sleep op, either sleep_op.SyncSleep or sleep_op.AsyncSleep.


def setOutBoundLinkQuality(self, LinkQuality):

        print '%s call setOutBoundLinkQuality' % self.port
        print LinkQuality
        try:
            cmd = 'macfilter rss add-lqi * %s' % str(LinkQuality)
            print cmd
            return self.__sendCommand(cmd)[0] == 'Done'
        except Exception, e:
            ModuleHelper.WriteIntoDebugLogger("setOutBoundLinkQuality() Error: " + str(e))

set custom LinkQualityIn for all receiving messages from the any address

Args:
LinkQuality: a given custom link quality
link quality/link margin mapping table
3: 21 - 255 (dB)
2: 11 - 20 (dB)
1: 3 - 9 (dB)
0: 0 - 2 (dB)

Returns:
True: successful to set the link quality
False: fail to set the link quality


def get_processed_events(self) -> List[Event]:
    event_ids = DB.get_list(self._processed_key)
    events = []
    for event_id in event_ids:
        event_str = DB.get_hash_value(self._data_key, event_id)
        event_dict = ast.literal_eval(event_str)
        event_dict['id'] = event_id
        event_dict['subscriber'] = self._subscriber
        events.append(Event.from_config(event_dict))
    return events

Get all processed events.

This method is intended to be used to recover events stuck in the
processed state which could happen if an event handling processing
an processed event goes down before completing the event processing.

Returns:
list[Events], list of event objects.


def read_xyz(cls, buf, start_index=0, get_bonds=True,
                 nrows=None, engine=None):

        frame = pd.read_table(buf, skiprows=2, comment='
                              nrows=nrows,
                              delim_whitespace=True,
                              names=['atom', 'x', 'y', 'z'], engine=engine)

        remove_digits = partial(re.sub, r'[0-9]+', '')
        frame['atom'] = frame['atom'].apply(remove_digits)

        molecule = cls(frame)
        molecule.index = range(start_index, start_index + len(molecule))

        if get_bonds:
            molecule.get_bonds(use_lookup=False, set_lookup=True)
        return molecule

Read a file of coordinate information.

Reads xyz-files.

Args:
inputfile (str):
start_index (int):
get_bonds (bool):
nrows (int): Number of rows of file to read.
Note that the first two rows are implicitly excluded.
engine (str): Wrapper for argument of :func:`pandas.read_csv`.

Returns:
Cartesian:


def read_windows_environ():
    res = winapi.GetEnvironmentStringsW()
    if (not res):
        raise ctypes.WinError()
    res = ctypes.cast(res, ctypes.POINTER(ctypes.c_wchar))
    done = []
    current = u''
    i = 0
    while 1:
        c = res[i]
        i += 1
        if (c == u'\x00'):
            if (not current):
                break
            done.append(current)
            current = u''
            continue
        current += c
    dict_ = {}
    for entry in done:
        try:
            (key, value) = entry.split(u'=', 1)
        except ValueError:
            continue
        key = _norm_key(key)
        dict_[key] = value
    status = winapi.FreeEnvironmentStringsW(res)
    if (status == 0):
        raise ctypes.WinError()
    return dict_

Returns a unicode dict of the Windows environment.

Raises:
WindowsEnvironError


def convert_upsample(params, w_name, scope_name, inputs, layers, weights, names):

    print('Converting upsample...')

    if params['mode'] != 'nearest':
        raise AssertionError('Cannot convert non-nearest upsampling')

    if names == 'short':
        tf_name = 'UPSL' + random_string(4)
    elif names == 'keep':
        tf_name = w_name
    else:
        tf_name = w_name + str(random.random())

    if 'height_scale' in params:
        scale = (params['height_scale'], params['width_scale'])
    elif len(inputs) == 2:
        scale = layers[inputs[-1] + '_np'][-2:]

    upsampling = keras.layers.UpSampling2D(
        size=scale, name=tf_name
    )
    layers[scope_name] = upsampling(layers[inputs[0]])

Convert nearest upsampling layer.

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


def GetMessages(self, formatter_mediator, event):

    if self.DATA_TYPE != event.data_type:
      raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
          event.data_type))

    event_values = event.CopyToDict()

    login_type = event_values.get('type', None)
    if login_type is None:
      status = 'N/A'
    else:
      status = self._STATUS_TYPES.get(login_type, 'UNKNOWN')

    event_values['status'] = status

    return self._ConditionalFormatMessages(event_values)

Determines the formatted message strings for an event object.

Args:
formatter_mediator (FormatterMediator): mediates the interactions
between formatters and other components, such as storage and Windows
EventLog resources.
event (EventObject): event.

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

Raises:
WrongFormatter: if the event object cannot be formatted by the formatter.


def average(numbers, numtype='float'):

    if type == 'decimal':
        return Decimal(sum(numbers)) / len(numbers)
    else:
        return float(sum(numbers)) / len(numbers)

Calculates the average or mean of a list of numbers

Args:
numbers: a list of integers or floating point numbers.

numtype: string, 'decimal' or 'float'; the type of number to return.

Returns:
The average (mean) of the numbers as a floating point number
or a Decimal object.

Requires:
The math module


def _compile_pvariable_expression(self, expr: Expression, scope: Dict[(str, TensorFluent)], batch_size: Optional[int]=None, noise: Optional[List[tf.Tensor]]=None) -> TensorFluent:
    etype = expr.etype
    args = expr.args
    name = expr._pvar_to_name(args)
    if (name not in scope):
        raise ValueError('Variable {} not in scope.'.format(name))
    fluent = scope[name]
    scope = (args[1] if (args[1] is not None) else [])
    if isinstance(fluent, TensorFluent):
        fluent = TensorFluent(fluent.tensor, scope, batch=fluent.batch)
    elif isinstance(fluent, tf.Tensor):
        fluent = TensorFluent(fluent, scope, batch=self.batch_mode)
    else:
        raise ValueError('Variable in scope must be TensorFluent-like: {}'.format(fluent))
    return fluent

Compile a pvariable expression `expr` into a TensorFluent
in the given `scope` with optional batch size.

Args:
expr (:obj:`rddl2tf.expr.Expression`): A RDDL pvariable expression.
scope (Dict[str, :obj:`rddl2tf.fluent.TensorFluent`]): A fluent scope.
batch_size (Optional[size]): The batch size.

Returns:
:obj:`rddl2tf.fluent.TensorFluent`: The compiled expression as a TensorFluent.


def preview(self, n=10, k='items', kheader='displayLink', klink='link', kdescription='snippet'):

    if 'searchType' in self.cseargs:
      searchType = self.cseargs['searchType']
    else:
      searchType = None
    items = self.metadata[k]

    for i, kv in enumerate(items[:n]):
      if 'start' in self.cseargs:
        i += int(self.cseargs['start'])

      header = '\n[' + str(i) + '] ' + kv[kheader]
      print(header)
      print('=' * len(header))

      if searchType == 'image':
        link = '\n' + path.basename(kv[klink])
        print(link)

      description = '\n' + kv[kdescription]
      print(description)

Print a preview of the search results.

Args:
n (int):
Maximum number of search results to preview
k (str):
Key in :class:`api.results`.metadata to preview
kheader (str):
Key in :class:`api.results`.metadata[``k``] to use as the header
klink (str):
Key in :class:`api.results`.metadata[``k``] to use as the link if image search
kdescription (str):
Key in :class:`api.results`.metadata[``k``] to use as the description


def _full_shape_filter(t: List, shapes: List) -> bool:

        if shapes:
            for a_token in t:
                if a_token._.full_shape not in shapes:
                    return False

        return True

Shape filter
Args:
t: List, list of tokens
shapes: List

Returns: bool


def isbase(path1, path2):
    _path1 = forcedir(abspath(path1))
    _path2 = forcedir(abspath(path2))
    return _path2.startswith(_path1)

Check if ``path1`` is a base of ``path2``.

Arguments:
path1 (str): A PyFilesytem path.
path2 (str): A PyFilesytem path.

Returns:
bool: `True` if ``path2`` starts with ``path1``

Example:
>>> isbase('foo/bar', 'foo/bar/baz/egg.txt')
True


def _is_quantized_input_stats_required(conversion_flags: _conversion_flags_pb2.ConverterFlags) -> bool:
    quantized_inference_types = [_types_pb2.QUANTIZED_UINT8, _types_pb2.QUANTIZED_INT8]
    return (conversion_flags.inference_type in quantized_inference_types or conversion_flags.inference_input_type in quantized_inference_types) and (not conversion_flags.post_training_quantize)

Checks if the `quantized_input_stats` flag is required for conversion.

Args:
conversion_flags: A protocol buffer describing the conversion process.

Returns:
True, if the `inference_type` or the `inference_input_type` is a quantized
type and it is not post training quantization, else False.


def set_default(self, default: Any, use_default_apply: bool=True, root_path: Optional[utils.KeyPath]=None) -> 'ValueSpec':

Sets the default value and returns `self`.

Args:
default: Default value.
use_default_apply: If True, invoke `apply` to the value, otherwise use
default value as is.
root_path: (Optional) The path of the field.

Returns:
ValueSpec itself.

Raises:
ValueError: If default value cannot be applied when use_default_apply
is set to True.


def load_data(self, data, datatype='ttl', namespace=None, graph=None, is_file=False, **kwargs):
    log.setLevel(kwargs.get('log_level', self.log_level))
    time_start = datetime.datetime.now()
    datatype_map = {'ttl': 'text/turtle', 'xml': 'application/rdf+xml', 'rdf': 'application/rdf+xml', 'nt': 'text/plain'}
    if is_file:
        datatype = data.split(os.path.extsep)[(- 1)]
        file_name = data
        log.debug('starting data load of %s', file_name)
        data = open(data, 'rb').read()
    else:
        try:
            data = data.encode('utf-8')
        except AttributeError:
            pass
    try:
        content_type = datatype_map[datatype]
    except KeyError:
        raise NotImplementedError("'%s' is not an implemented data format", datatype)
    context_uri = pick(graph, self.graph)
    result = requests.post(url=self._make_url(namespace), headers={'Content-Type': content_type}, params={'context-uri': context_uri}, data=data)
    if (result.status_code == 200):
        if is_file:
            log.info(' loaded %s into blazegraph - %s', file_name, self.format_response(result.text))
        else:
            log.info(' loaded data - %s', self.format_response(result.text))
        log.setLevel(self.log_level)
        return result
    else:
        raise SyntaxError(result.text)

Loads data via file stream from python to triplestore

Args:
-----
data: The data or filepath to load
datatype(['ttl', 'xml', 'rdf']): the type of data to load
namespace: the namespace to use
graph: the graph to load the data to.
is_file(False): If true python will read the data argument as a
filepath, determine the datatype from the file extension,
read the file and send it to blazegraph as a datastream


def group(text, size):
    if (size <= 0):
        raise ValueError('n must be a positive integer')
    return [text[i:(i + size)] for i in range(0, len(text), size)]

Group ``text`` into blocks of ``size``.

Example:
>>> group("test", 2)
['te', 'st']

Args:
text (str): text to separate
size (int): size of groups to split the text into

Returns:
List of n-sized groups of text

Raises:
ValueError: If n is non positive


def coupling(self, source_y, target_y, weight):
    return ((np.ones_like(target_y) * np.mean(source_y)) * weight)

How to couple the output of one subsystem to the input of another.

This is a fallback default coupling function that should usually be
replaced with your own.

This example coupling function takes the mean of all variables of the
source subsystem and uses that value weighted by the connection
strength to drive all variables of the target subsystem.

Arguments:
source_y (array of shape (d,)): State of the source subsystem.
target_y (array of shape (d,)): State of target subsystem.
weight (float): the connection strength for this connection.

Returns:
input (array of shape (d,)): Values to drive each variable of the
target system.


def coalescence_waiting_times(self, backward=True):

        if not isinstance(backward, bool):
            raise TypeError("backward must be a bool")
        times = list(); lowest_leaf_dist = float('-inf')
        for n,d in self.distances_from_root():
            if len(n.children) > 1:
                times.append(d)
            elif len(n.children) == 0 and d > lowest_leaf_dist:
                lowest_leaf_dist = d
        times.append(lowest_leaf_dist)
        times.sort(reverse=backward)
        for i in range(len(times)-1):
            yield abs(times[i]-times[i+1])

Generator over the waiting times of successive coalescence events

Args:
``backward`` (``bool``): ``True`` to go backward in time (i.e., leaves to root), otherwise ``False``


def decode_payload(cls, request):
    if (request.headers.get(cls.PAYLOAD_VERSION_HEADER) != cls.PAYLOAD_VERSION):
        raise DeprecationWarning('Task is generated by an older incompatible version of mapreduce. Please kill this job manually')
    return cls._decode_payload(request.body)

Decode task payload.

HugeTask controls its own payload entirely including urlencoding.
It doesn't depend on any particular web framework.

Args:
request: a webapp Request instance.

Returns:
A dict of str to str. The same as the params argument to __init__.

Raises:
DeprecationWarning: When task payload constructed from an older
incompatible version of mapreduce.


def _transform_indices(self, key):

        ndims = self.ndims
        if all(not (isinstance(el, slice) or callable(el)) for el in key):
            dim_inds = []
            for dim in self.kdims:
                dim_type = self.get_dimension_type(dim)
                if isinstance(dim_type, type) and issubclass(dim_type, Number):
                    dim_inds.append(self.get_dimension_index(dim))
            str_keys = iter(key[i] for i in range(self.ndims)
                            if i not in dim_inds)
            num_keys = []
            if len(dim_inds):
                keys = list({tuple(k[i] if ndims > 1 else k for i in dim_inds)
                             for k in self.keys()})
                q = np.array([tuple(key[i] if ndims > 1 else key for i in dim_inds)])
                idx = np.argmin([np.inner(q - np.array(x), q - np.array(x))
                                 if len(dim_inds) == 2 else np.abs(q-x)
                                     for x in keys])
                num_keys = iter(keys[idx])
            key = tuple(next(num_keys) if i in dim_inds else next(str_keys)
                        for i in range(self.ndims))
        elif any(not (isinstance(el, slice) or callable(el)) for el in key):
            keys = self.keys()
            for i, k in enumerate(key):
                if isinstance(k, slice):
                    continue
                dim_keys = np.array([ke[i] for ke in keys])
                if dim_keys.dtype.kind in 'OSU':
                    continue
                snapped_val = dim_keys[np.argmin(np.abs(dim_keys-k))]
                key = list(key)
                key[i] = snapped_val
            key = tuple(key)
        return key

Snaps indices into the GridSpace to the closest coordinate.

Args:
key: Tuple index into the GridSpace

Returns:
Transformed key snapped to closest numeric coordinates


def serialize_to_list(self, name, datas):
    items = datas.get('items', None)
    splitter = datas.get('splitter', self._DEFAULT_SPLITTER)
    if (items is None):
        msg = "List reference '{}' lacks of required 'items' variable or is empty"
        raise SerializerError(msg.format(name))
    else:
        items = self.value_splitter(name, 'items', items, mode=splitter)
    return items

Serialize given datas to a list structure.

List structure is very simple and only require a variable ``--items``
which is a string of values separated with an empty space. Every other
properties are ignored.

Arguments:
name (string): Name only used inside possible exception message.
datas (dict): Datas to serialize.

Returns:
list: List of serialized reference datas.


def get_load_balancer(self, id):
    return LoadBalancer.get_object(api_token=self.token, id=id)

Returns a Load Balancer object by its ID.

Args:
id (str): Load Balancer ID


def from_sub_model_configs(cls, text_config: ClvpEncoderConfig, speech_config: ClvpEncoderConfig, decoder_config: ClvpDecoderConfig, **kwargs):
    return cls(text_config=text_config.to_dict(), speech_config=speech_config.to_dict(), decoder_config=decoder_config.to_dict(), **kwargs)

Instantiate a [`ClvpConfig`] (or a derived class) from CLVP text model configuration, CLVP speech model
configuration and CLVP decoder model configuration.

Args:
text_config (`ClvpEncoderConfig`):
Text model configuration of type [`ClvpEncoderConfig`].
speech_config (`ClvpEncoderConfig`):
Speech model configuration of type [`ClvpEncoderConfig`].
decoder_config (`ClvpDecoderConfig`):
Decoder model configuration of type [`ClvpDecoderConfig`].

Returns:
[`ClvpConfig`]: An instance of a configuration object


def pop(stack, op_id):

  if __debug__:
    pushed_value, pushed_op_id = stack.pop()
    assert pushed_op_id == op_id, 'Wanted %s, got %s' % (op_id, pushed_op_id)
  else:
    pushed_value = stack.pop()
  return pushed_value

Pop a value from the stack (i.e. read it from the tape).

Args:
stack: The stack to pop from.
op_id: A unique variable that is also passed into the matching push.
Allows optimization passes to track pairs of pushes and pops.

Returns:
The last value.


def __init__(self, graph, canonical_device=None):

    self._graph = graph
    self.canonical_device = canonical_device
    self._operations = self._initialize_operations()
    self._operation_name_to_id = self._initialize_operation_name_to_id()
    self._tensor_name_to_ids = self._initialize_tensor_name_to_ids()
    self._final_tensors = set()

Initializer.

Args:
graph: either a tf.Graph or mtf.Graph.
canonical_device: optional string, the name of the canonical device for
IsTensoronCanonicalDevice.


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

    for subkey in registry_key.GetSubkeys():
      values_dict = {}
      values_dict['subkey_name'] = subkey.name

      vendor_identification = None
      product_identification = None
      try:
        subkey_name_parts = subkey.name.split('&')
        if len(subkey_name_parts) >= 2:
          vendor_identification = subkey_name_parts[0]
          product_identification = subkey_name_parts[1]
      except ValueError as exception:
        logger.warning(
            'Unable to split string: {0:s} with error: {1!s}'.format(
                subkey.name, exception))

      if vendor_identification and product_identification:
        values_dict['vendor'] = vendor_identification
        values_dict['product'] = product_identification

      for devicekey in subkey.GetSubkeys():
        values_dict['serial'] = devicekey.name

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

        event = time_events.DateTimeValuesEvent(
            devicekey.last_written_time,
            definitions.TIME_DESCRIPTION_LAST_CONNECTED)
        parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts events from a Windows Registry key.

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


def remove(path, force=False):
    path = os.path.expanduser(path)
    if (not os.path.isabs(path)):
        raise SaltInvocationError('File path must be absolute: {0}'.format(path))
    if ((not os.path.exists(path)) and (not is_link(path))):
        raise CommandExecutionError('Path not found: {0}'.format(path))
    if force:
        file_attributes = win32api.GetFileAttributes(path)
        win32api.SetFileAttributes(path, win32con.FILE_ATTRIBUTE_NORMAL)
    try:
        if os.path.isfile(path):
            os.remove(path)
        elif is_link(path):
            os.rmdir(path)
        else:
            for name in os.listdir(path):
                item = '{0}\\{1}'.format(path, name)
                remove(item, force)
            os.rmdir(path)
    except (OSError, IOError) as exc:
        if force:
            win32api.SetFileAttributes(path, file_attributes)
        raise CommandExecutionError("Could not remove '{0}': {1}".format(path, exc))
    return True

Remove the named file or directory

Args:
path (str): The path to the file or directory to remove.
force (bool): Remove even if marked Read-Only. Default is False

Returns:
bool: True if successful, False if unsuccessful

CLI Example:

.. code-block:: bash

salt '*' file.remove C:\\Temp


def to_proto(self, export_scope=None):
    if export_scope is None or self.name.startswith(export_scope):
        context_def = control_flow_pb2.WhileContextDef()
        context_def.context_name = ops.strip_name_scope(self.name, export_scope)
        context_def.parallel_iterations = self._parallel_iterations
        if self._maximum_iterations is not None:
            context_def.maximum_iterations_name = ops.strip_name_scope(self._maximum_iterations.name, export_scope)
        context_def.back_prop = self._back_prop
        context_def.swap_memory = self._swap_memory
        context_def.pivot_for_pred_name = ops.strip_name_scope(self._pivot_for_pred.name, export_scope)
        context_def.pivot_for_body_name = ops.strip_name_scope(self._pivot_for_body.name, export_scope)
        context_def.pivot_name = ops.strip_name_scope(self._pivot.name, export_scope)
        context_def.loop_exit_names.extend([ops.strip_name_scope(l.name, export_scope) for l in self._loop_exits])
        context_def.loop_enter_names.extend([ops.strip_name_scope(l.name, export_scope) for l in self._loop_enters])
        context_def.values_def.MergeFrom(super(WhileContext, self)._to_values_def(export_scope=export_scope))
        for nested in self._nested_contexts:
            nested_def = context_def.nested_contexts.add()
            nested.to_control_flow_context_def(nested_def)
        return context_def
    else:
        return None

Converts a `WhileContext` to a `WhileContextDef` protocol buffer.

Args:
export_scope: Optional `string`. Name scope to remove.

Returns:
A `WhileContextDef` protocol buffer.


def __init__(self, scope, parent, id, name, result):

        CodeEntity.__init__(self, scope, parent)
        self.id = id
        self.name = name
        self.result = result
        self.value = None
        self.member_of = None
        self.references = []
        self.writes = []

Constructor for variables.

Args:
scope (CodeEntity): The program scope where this object belongs.
parent (CodeEntity): This object's parent in the program tree.
id: An unique identifier for this variable.
name (str): The name of the variable in the program.
result (str): The type of the variable in the program.


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

Streams data into BigQuery one record at a time without needing to run a load job. Requires the WRITER dataset role.

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


def refactor_tree(self, tree, name):

        for fixer in chain(self.pre_order, self.post_order):
            fixer.start_tree(tree, name)

        self.traverse_by(self.bmi_pre_order_heads, tree.pre_order())
        self.traverse_by(self.bmi_post_order_heads, tree.post_order())

        match_set = self.BM.run(tree.leaves())

        while any(match_set.values()):
            for fixer in self.BM.fixers:
                if fixer in match_set and match_set[fixer]:

                    match_set[fixer].sort(key=pytree.Base.depth, reverse=True)

                    if fixer.keep_line_order:

                        match_set[fixer].sort(key=pytree.Base.get_lineno)

                    for node in list(match_set[fixer]):
                        if node in match_set[fixer]:
                            match_set[fixer].remove(node)

                        try:
                            find_root(node)
                        except ValueError:

                            continue

                        if node.fixers_applied and fixer in node.fixers_applied:

                            continue

                        results = fixer.match(node)

                        if results:
                            new = fixer.transform(node, results)
                            if new is not None:
                                node.replace(new)

                                for node in new.post_order():

                                    if not node.fixers_applied:
                                        node.fixers_applied = []
                                    node.fixers_applied.append(fixer)

                                new_matches = self.BM.run(new.leaves())
                                for fxr in new_matches:
                                    if not fxr in match_set:
                                        match_set[fxr]=[]

                                    match_set[fxr].extend(new_matches[fxr])

        for fixer in chain(self.pre_order, self.post_order):
            fixer.finish_tree(tree, name)
        return tree.was_changed

Refactors a parse tree (modifying the tree in place).

For compatible patterns the bottom matcher module is
used. Otherwise the tree is traversed node-to-node for
matches.

Args:
tree: a pytree.Node instance representing the root of the tree
to be refactored.
name: a human-readable name for this tree.

Returns:
True if the tree was modified, False otherwise.


def Append(self, new_values):

        newrow = self.NewRow()
        newrow.values = new_values
        self._table.append(newrow)

Adds a new row (list) to the table.

Args:
new_values: Tuple, dict, or Row() of new values to append as a row.

Raises:
TableError: Supplied tuple not equal to table width.


def _signal_handler(self, signal_interupt, frame):

        if self.container is not None:
            print('{}{}Stopping docker container.'.format(c.Style.BRIGHT, c.Fore.YELLOW))
            self.container.stop()
        print('{}{}Interrupt signal received.'.format(c.Style.BRIGHT, c.Fore.RED))
        self.log.error('tcrun received an interrupt signal and will now exit.')
        sys.exit(1)

Handle singal interrupt.

Args:
signal_interupt ([type]): [Description]
frame ([type]): [Description]


def open_sequence(path: Union[str, os.PathLike[str]], mode: str='r', *, perms: Optional[int]=436, serializer: Optional[Callable[[Any], Union[bytes, str]]]=None, deserializer: Optional[Callable[[Union[bytes, str]], Any]]=None, make_dirs_if_not_exist: bool=True) -> Sequence:
    if 'w' in mode or 'a' in mode:
        parent_dir = os.path.dirname(path)
        if make_dirs_if_not_exist:
            file_system.mkdirs(parent_dir, exist_ok=True)
    return _registry.get(path).open(path, mode, perms=perms, serializer=serializer, deserializer=deserializer)

Open sequence for reading or writing.

Args:
path: The path to the sequence.
mode: The mode of the sequence.
perms: (Optional) The permissions of the sequence.
serializer: (Optional) A serializer function for converting a structured
object to a string or bytes.
deserializer: (Optional) A deserializer function for converting a string or
bytes to a structured object.
make_dirs_if_not_exist: (Optional) Whether to create the directories
if they do not exist. Applicable when opening in write or append mode.

Returns:
A sequence for reading or writing.


def build_input_pipeline(x, y, batch_size):
    training_dataset = tf.data.Dataset.from_tensor_slices((x, y))
    training_batches = training_dataset.repeat().batch(batch_size)
    training_iterator = tf.compat.v1.data.make_one_shot_iterator(training_batches)
    (batch_features, batch_labels) = training_iterator.get_next()
    return (batch_features, batch_labels)

Build a Dataset iterator for supervised classification.

Args:
x: Numpy `array` of features, indexed by the first dimension.
y: Numpy `array` of labels, with the same first dimension as `x`.
batch_size: Number of elements in each training batch.

Returns:
batch_features: `Tensor` feed  features, of shape
`[batch_size] + x.shape[1:]`.
batch_labels: `Tensor` feed of labels, of shape
`[batch_size] + y.shape[1:]`.


def gene_by_alias(self, symbol, build='37'):

        res = self.hgnc_collection.find({'hgnc_symbol': symbol, 'build':build})
        if res.count() == 0:
            res = self.hgnc_collection.find({'aliases': symbol, 'build':build})

        return res

Return a iterable with hgnc_genes.

If the gene symbol is listed as primary the iterable will only have
one result. If not the iterable will include all hgnc genes that have
the symbol as an alias.

Args:
symbol(str)
build(str)

Returns:
res(pymongo.Cursor(dict))


def read(url, encoding=None, cache=None, mode='rb'):
    with read_handle(url, cache, mode=mode) as handle:
        data = handle.read()
    if encoding:
        data = data.decode(encoding)
    return data

Read from any URL.

Internally differentiates between URLs supported by tf.gfile, such as URLs
with the Google Cloud Storage scheme ('gs://...') or local paths, and HTTP
URLs. This way users don't need to know about the underlying fetch mechanism.

Args:
url: a URL including scheme or a local path
mode: mode in which to open the file. defaults to binary ('rb')
encoding: if specified, encoding that should be used to decode read data
if mode is specified to be text ('r'), this defaults to 'utf-8'.
cache: whether to attempt caching the resource. Defaults to True only if
the given URL specifies a remote resource.
Returns:
All bytes form the specified resource, or a decoded string of those.


def unmanaged_devices(self):
    if (not self.__unmanaged_devices):
        self.__unmanaged_devices = UnmanagedDevices(self.__connection)
    return self.__unmanaged_devices

Gets the Unmanaged Devices API client.

Returns:
UnmanagedDevices:


def percentile_nearest(self, percentile):

    if self._input_csv_files:
      df = self._get_data_from_csv_files()
      if 'target' not in df or 'predicted' not in df:
        raise ValueError('Cannot find "target" or "predicted" column')

      df = df[['target', 'predicted']].apply(pd.to_numeric)
      abs_errors = np.array((df['target'] - df['predicted']).apply(abs))
      return np.percentile(abs_errors, percentile, interpolation='nearest')
    elif self._bigquery:
      query = bq.Query( % (float(percentile) / 100, self._bigquery))
      df = self._get_data_from_bigquery([query])
      if df.empty:
        return None
      return df['percentile'][0]

Get nearest percentile from regression model evaluation results.

Args:
percentile: a 0~100 float number.

Returns:
the percentile float number.

Raises:
Exception if the CSV headers do not include 'target' or 'predicted', or BigQuery
does not return 'target' or 'predicted' column, or if target or predicted is not
number.


def get_duration_h_m(start: Union[str, DateTime],
                     end: Union[str, DateTime],
                     default: str = "N/A") -> str:

    start = coerce_to_pendulum(start)
    end = coerce_to_pendulum(end)
    if start is None or end is None:
        return default
    duration = end - start
    minutes = duration.in_minutes()
    (hours, minutes) = divmod(minutes, 60)
    if hours < 0:

        hours += 1
        minutes = 60 - minutes
        return "-{}:{}".format(hours, "00" if minutes == 0 else minutes)
    else:
        return "{}:{}".format(hours, "00" if minutes == 0 else minutes)

Calculate the time between two dates/times expressed as strings.

Args:
start: start date/time
end: end date/time
default: string value to return in case either of the inputs is
``None``

Returns:
a string that is one of

.. code-block:

'hh:mm'
'-hh:mm'
default


def kmip_version(self, value):

        if isinstance(value, enums.KMIPVersion):
            self.proxy.kmip_version = value
        else:
            raise ValueError("KMIP version must be a KMIPVersion enumeration")

Set the KMIP version for the client.

Args:
value (KMIPVersion): A KMIPVersion enumeration

Return:
None

Raises:
ValueError: if value is not a KMIPVersion enumeration

Example:
>>> client.kmip_version = enums.KMIPVersion.KMIP_1_1
>>>


def createCategoryFilter(self, filterName, positiveExamples, negativeExamples=[]):

        samples = {"positiveExamples": [{"text": s} for s in positiveExamples],
                   "negativeExamples": [{"text": s} for s in negativeExamples]}
        body = json.dumps(samples)
        return self._classify.createCategoryFilter(self._retina, filterName, body)

Get a classifier filter (fingerprint) for positive and negative text samples
Args:
filterName, str: A unique name for the filter. (required)
positiveExamples, list(str): The list of positive example texts. (required)
negativeExamples, list(str): The list of negative example texts. (optional)
Returns:
CategoryFilter
Raises:
CorticalioException: if the request was not successful


def expand_abbreviations(self, text):

        if not self.abbreviations:
            raise LexiconError("No abbreviations in lexicon.")

        def chunks(data, SIZE=25):

            it = iter(data)
            for i in range(0, len(data), SIZE):
                yield {k: data[k] for k in islice(it, SIZE)}

        def cb(g):

            return self.abbreviations.get(g.group(0)) or g.group(0)

        text = re.sub(r'w/', r'wi', text)

        for subdict in chunks(self.abbreviations):
            regex = r'(\b' + r'\b)|(\b'.join(subdict.keys()) + r'\b)'
            text = re.sub(regex, cb, text)

        return text

Parse a piece of text and replace any abbreviations with their full
word equivalents. Uses the lexicon.abbreviations dictionary to find
abbreviations.

Args:
text (str): The text to parse.

Returns:
str: The text with abbreviations replaced.


def pubsub_pop_message(self, deadline=None):
    if (not self.subscribed):
        excep = ClientError('you must subscribe before using pubsub_pop_message')
        raise tornado.gen.Return(excep)
    reply = None
    try:
        reply = self._reply_list.pop(0)
        raise tornado.gen.Return(reply)
    except IndexError:
        pass
    if (deadline is not None):
        td = timedelta(seconds=deadline)
        (yield self._condition.wait(timeout=td))
    else:
        (yield self._condition.wait())
    try:
        reply = self._reply_list.pop(0)
    except IndexError:
        pass
    raise tornado.gen.Return(reply)

Pops a message for a subscribed client.

Args:
deadline (int): max number of seconds to wait (None => no timeout)

Returns:
Future with the popped message as result (or None if timeout
or ConnectionError object in case of connection errors
or ClientError object if you are not subscribed)


def get_orbital_resolved_cohp(self, label, orbitals):
    if (self.orb_res_cohp is None):
        return None
    elif (isinstance(orbitals, list) or isinstance(orbitals, tuple)):
        cohp_orbs = [d['orbitals'] for d in self.orb_res_cohp[label].values()]
        orbs = []
        for orbital in orbitals:
            if isinstance(orbital[1], int):
                orbs.append(tuple((orbital[0], Orbital(orbital[1]))))
            elif isinstance(orbital[1], Orbital):
                orbs.append(tuple((orbital[0], orbital[1])))
            elif isinstance(orbital[1], str):
                orbs.append(tuple((orbital[0], Orbital[orbital[1]])))
            else:
                raise TypeError('Orbital must be str, int, or Orbital.')
        orb_index = cohp_orbs.index(orbs)
        orb_label = list(self.orb_res_cohp[label].keys())[orb_index]
    elif isinstance(orbitals, str):
        orb_label = orbitals
    else:
        raise TypeError('Orbitals must be str, list, or tuple.')
    try:
        icohp = self.orb_res_cohp[label][orb_label]['ICOHP']
    except KeyError:
        icohp = None
    return Cohp(self.efermi, self.energies, self.orb_res_cohp[label][orb_label]['COHP'], icohp=icohp, are_coops=self.are_coops)

Get orbital-resolved COHP.

Args:
label: bond label (Lobster: labels as in ICOHPLIST/ICOOPLIST.lobster).

orbitals: The orbitals as a label, or list or tuple of the form
[(n1, orbital1), (n2, orbital2)]. Orbitals can either be str,
int, or Orbital.

Returns:
A Cohp object if CompleteCohp contains orbital-resolved cohp,
or None if it doesn't.

Note: It currently assumes that orbitals are str if they aren't the
other valid types. This is not ideal, but the easiest way to
avoid unicode issues between python 2 and python 3.


def subscribe(self, requested_timeout=None, auto_renew=False, event_queue=None):
    subscription = Subscription(self, event_queue)
    subscription.subscribe(requested_timeout=requested_timeout, auto_renew=auto_renew)
    return subscription

Subscribe to the service's events.

Args:
requested_timeout (int, optional): If requested_timeout is
provided, a subscription valid for that
number of seconds will be requested, but not guaranteed. Check
`Subscription.timeout` on return to find out what period of
validity is actually allocated.
auto_renew (bool): If auto_renew is `True`, the subscription will
automatically be renewed just before it expires, if possible.
Default is `False`.

event_queue (:class:`~queue.Queue`): a thread-safe queue object on
which received events will be put. If not specified,
a (:class:`~queue.Queue`) will be created and used.

Returns:
`Subscription`: an insance of `Subscription`, representing
the new subscription.

To unsubscribe, call the `unsubscribe` method on the returned object.


def _process_update(self, item, feed_item):
    item['name'] = feed_item.get(FieldMap.CAMPAIGN_LANDING_PAGE_NAME, None)
    item['url'] = feed_item.get(FieldMap.CAMPAIGN_LANDING_PAGE_URL, None)

Updates an landing page based on the values from the feed.

Args:
item: Object representing the landing page to be updated, this object is
updated directly.
feed_item: Feed item representing landing page values from the Bulkdozer
feed.


def list(self, resource):

        return self.service.list(
            resource, self.url_prefix, self.auth, self.session,
            self.session_send_opts)

List metadata keys associated with the given resource.

Args:
resource (intern.resource.boss.BossResource): List keys associated with this resource.

Returns:
(list): List of key names.

Raises:
requests.HTTPError on failure.


def find_first(self, *args, **kwargs):
    if capybara.wait_on_first_by_default:
        kwargs.setdefault('minimum', 1)
    try:
        result = self.find_all(*args, **kwargs)
        return (result[0] if (len(result) > 0) else None)
    except ExpectationNotMet:
        return None

Find the first element on the page matching the given selector and options, or None if no
element matches.

By default, no waiting behavior occurs. However, if ``capybara.wait_on_first_by_default``
is set to true, it will trigger Capybara's waiting behavior for a minimum of 1 matching
element to be found.

Args:
*args: Variable length argument list for :class:`SelectorQuery`.
**kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

Returns:
Element: The found element or None.


def known(self, words):
    tmp = [w.lower() for w in words]
    return set((w for w in tmp if ((w in self._word_frequency.dictionary) or (not self._check_if_should_check(w)))))

The subset of `words` that appear in the dictionary of words

Args:
words (list): List of words to determine which are in the \
corpus
Returns:
set: The set of those words from the input that are in the \
corpus


def matching_args(fn, dictionary):
    arg_spec = getargspec(fn)
    if arg_spec.keywords:
        return dictionary
    return _mapping.split_by_criteria(dictionary, arg_spec.args).included

Given a function fn and a dict dictionary, returns the function arguments that match the dict keys.

Example:

def train(channel_dirs, model_dir): pass

dictionary = {'channel_dirs': {}, 'model_dir': '/opt/ml/model', 'other_args': None}

args = functions.matching_args(train, dictionary) # {'channel_dirs': {}, 'model_dir': '/opt/ml/model'}

train(**args)
Args:
fn (function): a function
dictionary (dict): the dictionary with the keys

Returns:
(dict) a dictionary with only matching arguments.


def check_codes_match(observed_code: str, theoretical_code: str) -> Optional[int]:
    observed_code_header = observed_code.split('\n')[0]
    theoretical_code_header = theoretical_code.split('\n')[0]
    _re_class_match = re.compile('class\\s+([^\\(:]+)(?:\\(|:)')
    _re_func_match = re.compile('def\\s+([^\\(]+)\\(')
    for re_pattern in [_re_class_match, _re_func_match]:
        if re_pattern.match(observed_code_header) is not None:
            try:
                observed_obj_name = re_pattern.search(observed_code_header).groups()[0]
            except Exception:
                raise ValueError('Tried to split a class or function. It did not work. Error comes from: \n```\n' + observed_code_header + '\n```\n')
            try:
                theoretical_name = re_pattern.search(theoretical_code_header).groups()[0]
            except Exception:
                raise ValueError('Tried to split a class or function. It did not work. Error comes from: \n```\n' + theoretical_code_header + '\n```\n')
            theoretical_code_header = theoretical_code_header.replace(theoretical_name, observed_obj_name)
    diff_index = 0
    if theoretical_code_header != observed_code_header:
        return 0
    diff_index = 1
    for observed_line, theoretical_line in zip(observed_code.split('\n')[1:], theoretical_code.split('\n')[1:]):
        if observed_line != theoretical_line:
            return diff_index
        diff_index += 1

Checks if two version of a code match with the exception of the class/function name.

Args:
observed_code (`str`): The code found.
theoretical_code (`str`): The code to match.

Returns:
`Optional[int]`: The index of the first line where there is a difference (if any) and `None` if the codes
match.


def swo_enable(self, cpu_speed, swo_speed=9600, port_mask=1):
    if self.swo_enabled():
        self.swo_stop()
    res = self._dll.JLINKARM_SWO_EnableTarget(cpu_speed, swo_speed, enums.JLinkSWOInterfaces.UART, port_mask)
    if (res != 0):
        raise errors.JLinkException(res)
    self._swo_enabled = True
    return None

Enables SWO output on the target device.

Configures the output protocol, the SWO output speed, and enables any
ITM & stimulus ports.

This is equivalent to calling ``.swo_start()``.

Note:
If SWO is already enabled, it will first stop SWO before enabling it
again.

Args:
self (JLink): the ``JLink`` instance
cpu_speed (int): the target CPU frequency in Hz
swo_speed (int): the frequency in Hz used by the target to communicate
port_mask (int): port mask specifying which stimulus ports to enable

Returns:
``None``

Raises:
JLinkException: on error


def allreduce(self, x, mesh_axes, reduction_fn_string):

    return self._collective_with_groups(
        x, mesh_axes, functools.partial(
            allreduce_ring, reduction_fn_string=reduction_fn_string))

Grouped allreduce, (across the given dimensions).

Args:
x: a LaidOutTensor
mesh_axes: a list of integers - the mesh dimensions to be reduced
reduction_fn_string: "SUM" or "MAX"
Returns:
a LaidOutTensor


def replace_characters(self, text, characters, replacement=''):

        if not characters:
            return text

        characters = ''.join(sorted(characters))
        if characters in self._characters_regexes:
            characters_regex = self._characters_regexes[characters]
        else:
            characters_regex = re.compile("[%s]" % re.escape(characters))
            self._characters_regexes[characters] = characters_regex

        return characters_regex.sub(replacement, text)

Remove characters from text.

Removes custom characters from input text or replaces them
with a string if specified.

Args:
text: The text to be processed.
characters: Characters that will be replaced.
replacement: New text that will replace the custom characters.

Returns:
The text without the given characters.


def __init__(self, project: str, location: str, api_endpoint: str, feature_store_name: str, feature_view_name: str, row_key: str, *, exception_level: ExceptionLevel=ExceptionLevel.WARN, **kwargs):
    self.project = project
    self.location = location
    self.api_endpoint = api_endpoint
    self.feature_store_name = feature_store_name
    self.feature_view_name = feature_view_name
    self.row_key = row_key
    self.exception_level = exception_level
    self.kwargs = kwargs if kwargs else {}
    if 'client_options' in self.kwargs:
        if not self.kwargs['client_options']['api_endpoint']:
            self.kwargs['client_options']['api_endpoint'] = self.api_endpoint
        elif self.kwargs['client_options']['api_endpoint'] != self.api_endpoint:
            raise ValueError('Multiple values received for api_endpoint in api_endpoint and client_options parameters.')
    else:
        self.kwargs['client_options'] = {'api_endpoint': self.api_endpoint}
    try:
        admin_client = aiplatform.gapic.FeatureOnlineStoreAdminServiceClient(**self.kwargs)
    except Exception:
        _LOGGER.warning('Due to insufficient admin permission, could not verify the existence of feature store. If the `exception_level` is set to WARN then make sure the feature store exists otherwise the data enrichment will not happen without throwing an error.')
    else:
        location_path = admin_client.common_location_path(project=self.project, location=self.location)
        feature_store_path = admin_client.feature_online_store_path(project=self.project, location=self.location, feature_online_store=self.feature_store_name)
        feature_store = admin_client.get_feature_online_store(name=feature_store_path)
        if not feature_store:
            raise NotFound('Vertex AI Feature Store %s does not exists in %s' % (self.feature_store_name, location_path))

Initializes an instance of `VertexAIFeatureStoreEnrichmentHandler`.

Args:
project (str): The GCP project-id for the Vertex AI Feature Store.
location (str): The region for the Vertex AI Feature Store.
api_endpoint (str): The API endpoint for the Vertex AI Feature Store.
feature_store_name (str): The name of the Vertex AI Feature Store.
feature_view_name (str): The name of the feature view within the
Feature Store.
row_key (str): The row key field name containing the unique id
for the feature values.
exception_level: a `enum.Enum` value from
`apache_beam.transforms.enrichment_handlers.utils.ExceptionLevel`
to set the level when an empty row is returned from the BigTable query.
Defaults to `ExceptionLevel.WARN`.
kwargs: Optional keyword arguments to configure the
`aiplatform.gapic.FeatureOnlineStoreServiceClient`.


def __init__(self, details):

		if not isinstance(details, dict):
			raise ValueError('details in ' + self.__class__.__name__ + '.' + sys._getframe().f_code.co_name + ' must be a dict')

		if '__name__' not in details:
			raise KeyError('__name__')

		if not _standardField.match(details['__name__']):
			raise ValueError('__name__')

		self._name = details['__name__']
		del details['__name__']

		if '__array__' in details:
			del details['__array__']

		super(Tree, self).__init__(details)

		self._class = 'Tree'

Constructor

Initialises the instance

Arguments:
details {dict} -- Details describing the type of values allowed for
the node

Raises:
KeyError
ValueError

Returns:
Tree


def initial_value_of_masked_time_series(time_series_tensor, broadcast_mask):

  num_timesteps = tf.shape(input=time_series_tensor)[-1]

  unmasked_negindices = (
      tf.cast(~broadcast_mask, tf.int32) *
      tf.range(num_timesteps, 0, -1))
  first_unmasked_indices = num_timesteps - tf.reduce_max(
      input_tensor=unmasked_negindices, axis=-1)

  if first_unmasked_indices.shape.ndims is None:
    raise NotImplementedError(
        'Cannot compute initial values of a masked time series with'
        'dynamic rank.')

  return tf.squeeze(tf.compat.v1.batch_gather(
      params=time_series_tensor,
      indices=first_unmasked_indices[..., tf.newaxis]), axis=-1)

Get the first unmasked entry of each time series in the batch.

Args:
time_series_tensor: float `Tensor` of shape [..., num_timesteps].
broadcast_mask: bool `Tensor` of same shape as `time_series`.


Write data to file sequentially.

Args:
data: (memoryview) Data to write.


def certificate_authority(self):
    if (not self.__certificate_authority):
        self.__certificate_authority = CertificateAuthority(self.__connection)
    return self.__certificate_authority

Gets the Certificate Authority API client.

Returns:
CertificateAuthority:


def fromTFExample(iter, binary_features=[]):

    def _get_value(k, v):
        if v.int64_list.value:
            result = v.int64_list.value
        elif v.float_list.value:
            result = v.float_list.value
        elif (k in binary_features):
            return bytearray(v.bytes_list.value[0])
        else:
            return v.bytes_list.value[0].decode('utf-8')
        if (len(result) > 1):
            return list(result)
        elif (len(result) == 1):
            return result[0]
        else:
            return None
    results = []
    for record in iter:
        example = tf.train.Example()
        example.ParseFromString(bytes(record[0]))
        d = {k: _get_value(k, v) for (k, v) in sorted(example.features.feature.items())}
        row = Row(**d)
        results.append(row)
    return results

mapPartition function to convert an RDD of serialized tf.train.Example bytestring into an RDD of Row.

Note: TensorFlow represents both strings and binary types as tf.train.BytesList, and we need to
disambiguate these types for Spark DataFrames DTypes (StringType and BinaryType), so we require a "hint"
from the caller in the ``binary_features`` argument.

Args:
:iter: the RDD partition iterator
:binary_features: a list of tf.train.Example features which are expected to be binary/bytearrays.

Returns:
An array/iterator of DataFrame Row with features converted into columns.


def get_symbol_list(rank, dim=6):
    indices = list(itertools.combinations_with_replacement(range(dim), r=rank))
    c_vec = np.zeros(len(indices), dtype=object)
    c_arr = np.zeros(([dim] * rank), dtype=object)
    for (n, idx) in enumerate(indices):
        c_vec[n] = sp.Symbol(('c_' + ''.join([str(i) for i in idx])))
        for perm in itertools.permutations(idx):
            c_arr[perm] = c_vec[n]
    return (c_vec, c_arr)

Returns a symbolic representation of the voigt-notation
tensor that places identical symbols for entries related
by index transposition, i. e. C_1121 = C_1211 etc.

Args:
dim (int): dimension of matrix/tensor, e. g. 6 for
voigt notation and 3 for standard
rank (int): rank of tensor, e. g. 3 for third-order ECs

Returns:
c_vec (array): array representing distinct indices
c_arr (array): array representing tensor with equivalent
indices assigned as above


def aggregate_repo(repo, args, sem, err_queue):

    try:
        logger.debug('%s' % repo)
        dirmatch = args.dirmatch
        if not match_dir(repo.cwd, dirmatch):
            logger.info("Skip %s", repo.cwd)
            return
        if args.command == 'aggregate':
            repo.aggregate()
            if args.do_push:
                repo.push()
        elif args.command == 'show-closed-prs':
            repo.show_closed_prs()
        elif args.command == 'show-all-prs':
            repo.show_all_prs()
    except Exception:
        err_queue.put_nowait(sys.exc_info())
    finally:
        sem.release()

Aggregate one repo according to the args.

Args:
repo (Repo): The repository to aggregate.
args (argparse.Namespace): CLI arguments.


Intersects two line segments

Args:
L1 ([float, float]): x and y coordinates
L2 ([float, float]): x and y coordinates
Returns:
bool: if they intersect
(float, float): x and y of intersection, if they do


def __init__(self, filename, mode='a', encoding='utf-8'):

    if 't' not in mode and encoding and py2to3.PY_3:
      mode = '{0:s}t'.format(mode)
    super(CompressedFileHandler, self).__init__(
        filename, mode=mode, encoding=encoding, delay=True)

Initializes a compressed file logging handler.

Args:
filename (str): name of the log file.
mode (Optional[str]): file access mode.
encoding (Optional[str]): encoding of the log lines.


def get_control_outputs(self, op):
    if op.graph not in self.cache:
        control_outputs = self.calc_control_outputs(op.graph)
        self.cache[op.graph] = control_outputs
    else:
        control_outputs = self.cache[op.graph]
    return control_outputs.get(op, [])

Return the control outputs for a given op.

Args:
op: The op to fetch control outputs for.

Returns:
Iterable of control output ops.


def create_writer_of_type(type_name):
    writers = available_writers()
    if (type_name not in writers.keys()):
        raise UnknownWriterException(('Unknown writer: %s' % (type_name,)))
    return writers[type_name]()

Create an instance of the writer with the given name.

Args:
type_name: The name of a writer.

Returns:
An instance of the writer with the given type.


def get_top_coins(tsym, limit=20):

	url = build_url('volumes', tsym=tsym, limit=limit)
	data = load_data(url)

	return data['Data']

Get top coins by 24 hour trading volume value in the requested currency.

Args:
tsym: TO symbol.
limit: Number of results. Default value returns top 20 coins.

Returns:
Function returns a list containing a dictionary for each result:

[{'SUPPLY': ..., 'SYMBOL': ..., 'VOLUME24HOURTO': ...},
{...},
...]

The list is ordered based on the volume of the TO currency starting with
the highest value.


def validate(self, ticket, client_ip=None, now=None, encoding='utf-8'):
    parts = self.parse(ticket)
    new_ticket = self.new(*parts[1:], client_ip=client_ip, encoding=encoding)
    if (new_ticket[:(self._hash.digest_size * 2)] != parts.digest):
        raise TicketDigestError(ticket)
    if (now is None):
        now = time.time()
    if (parts.valid_until <= now):
        raise TicketExpired(ticket)
    return parts

Validates the passed ticket, , raises a TicketError
on failure

Args:
ticket: String value (possibly generated by new function)
client_ip: Optional IPAddress of client, should be passed if the
ip address was passed on ticket creation.
now: Optional (defaults to time.time()) time to use when
validating ticket date

Returns:
Ticket a TicketInfo tuple containing the users authentication details on
success

Raises:
TicketParseError: Invalid ticket format
TicketDigestError: Digest is incorrect (ticket data was modified)
TicketExpired: Ticket has passed expiration date


def set_authentication_profile(profile=None, deploy=False):
    if (not profile):
        raise CommandExecutionError('Profile name option must not be none.')
    ret = {}
    query = {'type': 'config', 'action': 'set', 'xpath': "/config/devices/entry[@name='localhost.localdomain']/deviceconfig/system/authentication-profile", 'element': '<authentication-profile>{0}</authentication-profile>'.format(profile)}
    ret.update(__proxy__['panos.call'](query))
    if (deploy is True):
        ret.update(commit())
    return ret

Set the authentication profile of the Palo Alto proxy minion. A commit will be required before this is processed.

CLI Example:

Args:
profile (str): The name of the authentication profile to set.

deploy (bool): If true then commit the full candidate configuration, if false only set pending change.

.. code-block:: bash

salt '*' panos.set_authentication_profile foo
salt '*' panos.set_authentication_profile foo deploy=True


def get_file(self, file_name, local_destination=None, **kwargs):
    if (not local_destination):
        local_destination = file_name
    return SubprocessTask((self._rsync_cmd() + ['-ut', ('%s:%s' % (self.hostname, file_name)), local_destination]), **kwargs)

Get a file from a remote host with rsync.

Args:
file_name (str): The relative location of the file on the remote
host.

local_destination (str): The destination for the file on the local
host. If `None`, will be assumed to be the same as
**file_name**. Default `None`.

**kwargs: Passed to ``SubprocessTask``'s init method.

Return:
``pyrem.task.SubprocessTask``: The resulting task.


def _decode_crop_and_flip(image_buffer, num_channels):
    min_object_covered = 0.1
    aspect_ratio_range = [0.75, 1.33]
    area_range = [0.05, 1.0]
    max_attempts = 100
    mlperf_log.resnet_print(key=mlperf_log.INPUT_DISTORTED_CROP_MIN_OBJ_COV, value=min_object_covered)
    mlperf_log.resnet_print(key=mlperf_log.INPUT_DISTORTED_CROP_RATIO_RANGE, value=aspect_ratio_range)
    mlperf_log.resnet_print(key=mlperf_log.INPUT_DISTORTED_CROP_AREA_RANGE, value=area_range)
    mlperf_log.resnet_print(key=mlperf_log.INPUT_DISTORTED_CROP_MAX_ATTEMPTS, value=max_attempts)
    mlperf_log.resnet_print(key=mlperf_log.INPUT_CROP_USES_BBOXES, value=False)
    bbox = tf.constant([0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4])
    sample_distorted_bounding_box = tf.image.sample_distorted_bounding_box(tf.image.extract_jpeg_shape(image_buffer), bounding_boxes=bbox, min_object_covered=min_object_covered, aspect_ratio_range=aspect_ratio_range, area_range=area_range, max_attempts=max_attempts, use_image_if_no_bounding_boxes=True)
    (bbox_begin, bbox_size, _) = sample_distorted_bounding_box
    (offset_y, offset_x, _) = tf.unstack(bbox_begin)
    (target_height, target_width, _) = tf.unstack(bbox_size)
    crop_window = tf.stack([offset_y, offset_x, target_height, target_width])
    cropped = tf.image.decode_and_crop_jpeg(image_buffer, crop_window, channels=num_channels)
    mlperf_log.resnet_print(key=mlperf_log.INPUT_RANDOM_FLIP)
    cropped = tf.image.random_flip_left_right(cropped)
    return cropped

Crops the given image to a random part of the image, and randomly flips.

We use the fused decode_and_crop op, which performs better than the two ops
used separately in series, but note that this requires that the image be
passed in as an un-decoded string Tensor.

Args:
image_buffer: scalar string Tensor representing the raw JPEG image buffer.
num_channels: Integer depth of the image buffer for decoding.

Returns:
3-D tensor with cropped image.


def create_policy(self, account, client, document, name, arn=None):
    if ((not arn) and (not name)):
        raise ValueError('create_policy must be called with either arn or name in the argument list')
    if arn:
        response = client.list_policy_versions(PolicyArn=arn)
        if (len(response['Versions']) >= 5):
            version = [x for x in sorted(response['Versions'], key=(lambda k: k['CreateDate'])) if (not x['IsDefaultVersion'])][0]
            self.log.info('Deleting oldest IAM Policy version {}/{}'.format(arn, version['VersionId']))
            client.delete_policy_version(PolicyArn=arn, VersionId=version['VersionId'])
            auditlog(event='iam.check_roles.delete_policy_version', actor=self.ns, data={'account': account.account_name, 'policyName': name, 'policyArn': arn, 'versionId': version['VersionId']})
        res = client.create_policy_version(PolicyArn=arn, PolicyDocument=document, SetAsDefault=True)
    else:
        res = client.create_policy(PolicyName=name, PolicyDocument=document)
    auditlog(event='iam.check_roles.create_policy', actor=self.ns, data={'account': account.account_name, 'policyName': name, 'policyArn': arn})
    return res

Create a new IAM policy.

If the policy already exists, a new version will be added and if needed the oldest policy version not in use
will be removed. Returns a dictionary containing the policy or version information

Args:
account (:obj:`Account`): Account to create the policy on
client (:obj:`boto3.client`): A boto3 client object
document (`str`): Policy document
name (`str`): Name of the policy to create / update
arn (`str`): Optional ARN for the policy to update

Returns:
`dict`


def model(self, inputs, mode='train'):

        training = (mode == 'train')
        with tf.variable_scope('conv1') as scope:
            conv = tf.layers.conv2d(inputs=inputs, filters=16, kernel_size=[3, 3], padding='SAME')
            bn = tf.layers.batch_normalization(inputs=conv, training=training)
            bn = tf.nn.relu(bn)
            conv = tf.layers.conv2d(inputs=bn, filters=16, kernel_size=[3, 3], padding='SAME')
            bn = tf.layers.batch_normalization(inputs=conv, training=training)
            bn = tf.nn.relu(bn)
            pool = tf.layers.max_pooling2d(bn, pool_size=[2, 2], strides=2, padding='SAME', name=scope.name)

        with tf.variable_scope('conv2') as scope:
            conv = tf.layers.conv2d(inputs=pool, filters=32, kernel_size=[3, 3], padding='SAME')
            bn = tf.layers.batch_normalization(inputs=conv, training=training)
            bn = tf.nn.relu(bn)
            conv = tf.layers.conv2d(inputs=bn, filters=32, kernel_size=[3, 3], padding='SAME')
            bn = tf.layers.batch_normalization(inputs=conv, training=training)
            bn = tf.nn.relu(bn)
            pool = tf.layers.max_pooling2d(bn, pool_size=[2, 2], strides=2, padding='SAME', name=scope.name)

        with tf.variable_scope('conv3') as scope:
            conv = tf.layers.conv2d(inputs=pool, filters=32, kernel_size=[3, 3], padding='SAME')
            bn = tf.layers.batch_normalization(inputs=conv, training=training)
            bn = tf.nn.relu(bn)
            conv = tf.layers.conv2d(inputs=bn, filters=32, kernel_size=[3, 3], padding='SAME')
            bn = tf.layers.batch_normalization(inputs=conv, training=training)
            bn = tf.nn.relu(bn)
            pool = tf.layers.max_pooling2d(bn, pool_size=[2, 2], strides=2, padding='SAME', name=scope.name)

        with tf.variable_scope('fc') as scope:
            flat = tf.layers.flatten(pool)
            fc = tf.layers.dense(inputs=flat, units=32, activation=tf.nn.relu)
            softmax = tf.layers.dense(inputs=fc, units=self.num_classes, activation=tf.nn.softmax)

        return softmax

Build a simple convnet (BN before ReLU).
Args:
inputs: a tensor of size [batch_size, height, width, channels]
mode: string in ['train', 'test']
Returns:
the last op containing the predictions
Note:
Best score
Step:  7015 - Epoch: 18/20 - best batch acc: 0.8984 - loss: 1.5656
Worst score
Step:  7523 - Epoch: 20/20 - best batch acc: 0.7734 - loss: 1.6874


def is_initialized(self, name=None):
    return gen_resource_variable_ops.var_is_initialized_op(self.handle, name)

Checks whether a resource variable has been initialized.

Outputs boolean scalar indicating whether the tensor has been initialized.

Args:
name: A name for the operation (optional).

Returns:
A `Tensor` of type `bool`.


def ascii2h5(dat_fname, h5_fname):

    table = np.loadtxt(dat_fname, skiprows=1, dtype='f4')

    filter_kwargs = dict(
        chunks=True,
        compression='gzip',
        compression_opts=3)

    idx = ~np.all(table[:,2:32] < 1.e-5, axis=1)

    with h5py.File(h5_fname, 'w') as f:
        d = np.arange(0., 4.351, 0.15).astype('f4')

        dset = f.create_dataset('dists', data=d, **filter_kwargs)
        dset.attrs['description'] = 'Distances at which extinction is measured'
        dset.attrs['units'] = 'kpc'

        dset = f.create_dataset('pix_lb', data=table[idx,0:2], **filter_kwargs)
        dset.attrs['description'] = 'Galactic (l, b) of each pixel'
        dset.attrs['units'] = 'deg'

        dset = f.create_dataset('A_r', data=table[idx,2:32], **filter_kwargs)
        dset.attrs['description'] = 'Extinction'
        dset.attrs['shape'] = '(pixel, distance)'
        dset.attrs['band'] = 'r'
        dset.attrs['units'] = 'mag'

        dset = f.create_dataset('A_r_err', data=table[idx,32:], **filter_kwargs)
        dset.attrs['description'] = 'Gaussian uncertainty in extinction'
        dset.attrs['shape'] = '(pixel, distance)'
        dset.attrs['band'] = 'r'
        dset.attrs['units'] = 'mag'

Converts from the original ASCII format of the Chen+ (2014) 3D dust map to
the HDF5 format.

Args:
dat_fname (:obj:`str`): Filename of the original ASCII .dat file.
h5_fname (:obj:`str`): Output filename to write the resulting HDF5 file to.


def create_app(*, debug=False, threads=1, bigchaindb_factory=None):

    if not bigchaindb_factory:
        bigchaindb_factory = BigchainDB

    app = Flask(__name__)
    app.wsgi_app = StripContentTypeMiddleware(app.wsgi_app)

    CORS(app)

    app.debug = debug

    app.config['bigchain_pool'] = utils.pool(bigchaindb_factory, size=threads)

    add_routes(app)

    return app

Return an instance of the Flask application.

Args:
debug (bool): a flag to activate the debug mode for the app
(default: False).
threads (int): number of threads to use
Return:
an instance of the Flask application.


def softmax_classifier(input_, num_classes, labels=None, loss_weight=None, per_example_weights=None, weights=None, bias=tf.zeros_initializer(), parameter_modifier=parameters.identity, name=PROVIDED):
    full = input_.fully_connected(num_classes, activation_fn=None, name=name, weights=weights, bias=bias, parameter_modifier=parameter_modifier)
    return full.softmax(labels=labels, loss_weight=loss_weight, per_example_weights=per_example_weights, name=name)

Creates a fully-connected linear layer followed by a softmax.

This returns `(softmax, loss)` where `loss` is the cross entropy loss.

Args:
input_: A rank 2 Tensor or a Pretty Tensor holding the activation before
the logits (penultimate layer).
num_classes: The number of classes.
labels: The target labels to learn as a float tensor.  Use None to not
include a training loss.
loss_weight: A scalar multiplier for the loss.
per_example_weights: A Tensor with a weight per example.
weights: The initializer for the weights (see `fully_connected`).
bias: The initializer for the bias (see `fully_connected`).
parameter_modifier: A modifier for the parameters that compute the logits.
name: The optional name.
Returns:
A named tuple holding:

softmax: The result of this layer with softmax normalization.
loss: The cross entropy loss.
Raises:
ValueError: If the datatype is wrong.


def initialize(self):
    if eager_context.executing_eagerly():
        self._iterator = self._dataset.make_one_shot_iterator()
        return []
    else:
        return [self._iterator.initializer]

Initialize underlying iterators.

Returns:
A list of any initializer ops that should be run.


def bespoke_md5(self, md5):

        r = requests.post('http:
        self._output(r.text)

Performs Bespoke MD5 lookup on an MD5.

Args:
md5 - A hash.


def upload(self, file_path, golden_image_info):
    uri = '{0}?name={1}&description={2}'.format(self.URI, quote(golden_image_info.get('name', '')), quote(golden_image_info.get('description', '')))
    return self._client.upload(file_path, uri)

Adds a Golden Image resource from the file that is uploaded from a local drive. Only the .zip format file can
be used for the upload.

Args:
file_path (str): File name to upload.
golden_image_info (dict): Golden Image information.

Returns:
dict: Golden Image.


def alias_inplace_sub(x, i, v):
    return _inplace_helper(x, i, v, gen_array_ops.inplace_sub)

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

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

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

Returns:
Returns x.


def __init__(
      self, credential_data=None, credential_type=None, path_spec=None):

    super(CredentialConfiguration, self).__init__()
    self.credential_data = credential_data
    self.credential_type = credential_type
    self.path_spec = path_spec

Initializes a credential configuration object.

Args:
credential_data (Optional[bytes]): credential data.
credential_type (Optional[str]): credential type.
path_spec (Optional[dfvfs.PathSpec]): path specification.


def __init__(self, key_dtype, value_dtype, default_value, name='SimpleHashTable'):
    super(SimpleHashTable, self).__init__()
    self._default_value = tf.convert_to_tensor(default_value, dtype=value_dtype)
    self._value_shape = self._default_value.get_shape()
    self._key_dtype = key_dtype
    self._value_dtype = value_dtype
    self._name = name
    self._resource_handle = self._create_resource()

Creates an empty `SimpleHashTable` object.

Creates a table, the type of its keys and values are specified by key_dtype
and value_dtype, respectively.

Args:
key_dtype: the type of the key tensors.
value_dtype: the type of the value tensors.
default_value: The value to use if a key is missing in the table.
name: A name for the operation (optional).

Returns:
A `SimpleHashTable` object.


def _make_columnar(self, x):
    if (tensorshape_util.rank(x.shape) is not None):
        if (tensorshape_util.rank(x.shape) == 1):
            x = x[(tf.newaxis, :)]
        return x
    shape = tf.shape(input=x)
    maybe_expanded_shape = tf.concat([shape[:(- 1)], distribution_util.pick_vector(tf.equal(tf.rank(x), 1), [1], np.array([], dtype=np.int32)), shape[(- 1):]], 0)
    return tf.reshape(x, maybe_expanded_shape)

Ensures non-scalar input has at least one column.

Example:
If `x = [1, 2, 3]` then the output is `[[1], [2], [3]]`.

If `x = [[1, 2, 3], [4, 5, 6]]` then the output is unchanged.

If `x = 1` then the output is unchanged.

Args:
x: `Tensor`.

Returns:
columnar_x: `Tensor` with at least two dimensions.


def rapidfire(self, max_nlaunch=-1, max_loops=1, sleep_time=5):

        num_launched, do_exit, launched = 0, False, []

        for count in range(max_loops):
            if do_exit:
                break
            if count > 0:
                time.sleep(sleep_time)

            tasks = self.fetch_tasks_to_run()

            if any(task in launched for task in tasks):
                logger.critical("numtasks %d already in launched list:\n%s" % (len(tasks), launched))

            tasks = [t for t in tasks if t not in launched]

            if not tasks:
                continue

            for task in tasks:
                fired = task.start()
                if fired:
                    launched.append(task)
                    num_launched += 1

                if num_launched >= max_nlaunch > 0:
                    logger.info('num_launched >= max_nlaunch, going back to sleep')
                    do_exit = True
                    break

        self.flow.pickle_dump()

        return num_launched

Keeps submitting `Tasks` until we are out of jobs or no job is ready to run.

Args:
max_nlaunch: Maximum number of launches. default: no limit.
max_loops: Maximum number of loops
sleep_time: seconds to sleep between rapidfire loop iterations

Returns:
The number of tasks launched.


def create_sas_locator(access_token, asset_id, accesspolicy_id):

    path = '/Locators'
    endpoint = ''.join([ams_rest_endpoint, path])
    body = '{ \
		"AccessPolicyId":"' + accesspolicy_id + '", \
		"AssetId":"' + asset_id + '", \
		"Type":1 \
	}'
    return do_ams_post(endpoint, path, body, access_token)

Create Media Service SAS Locator.

Args:
access_token (str): A valid Azure authentication token.
asset_id (str): Media Service Asset ID.
accesspolicy_id (str): Media Service Access Policy ID.

Returns:
HTTP response. JSON body.


def max_intensity(item_a, time_a, item_b, time_b, max_value):
    intensity_a = item_a.max_intensity(time_a)
    intensity_b = item_b.max_intensity(time_b)
    diff = np.sqrt(((intensity_a - intensity_b) ** 2))
    return (np.minimum(diff, max_value) / float(max_value))

RMS difference in maximum intensity

Args:
item_a: STObject from the first set in ObjectMatcher
time_a: Time integer being evaluated
item_b: STObject from the second set in ObjectMatcher
time_b: Time integer being evaluated
max_value: Maximum distance value used as scaling value and upper constraint.

Returns:
Distance value between 0 and 1.


def SignMessage(self, message, script_hash):
    keypair = self.GetKeyByScriptHash(script_hash)
    prikey = bytes(keypair.PrivateKey)
    res = Crypto.Default().Sign(message, prikey)
    return (res, keypair.PublicKey)

Sign a message with a specified script_hash.

Args:
message (str): a hex encoded message to sign
script_hash (UInt160): a bytearray (len 20).

Returns:
str: the signed message


def from_backbone_configs(cls, backbone_config: PretrainedConfig, **kwargs):
    return cls(backbone_config=backbone_config, **kwargs)

Instantiate a [`RTDetrConfig`] (or a derived class) from a pre-trained backbone model configuration and DETR model
configuration.

Args:
backbone_config ([`PretrainedConfig`]):
The backbone configuration.

Returns:
[`RTDetrConfig`]: An instance of a configuration object


async def send_rpc(self, conn_id, address, rpc_id, payload, timeout):

        self._ensure_connection(conn_id, True)
        dev = self._get_property(conn_id, 'device')

        try:
            res = dev.call_rpc(address, rpc_id, bytes(payload))
            if inspect.iscoroutine(res):
                return await res
            else:
                return res
        except (RPCInvalidIDError, RPCNotFoundError, TileNotFoundError, RPCErrorCode, BusyRPCResponse):
            raise
        except Exception:
            self._logger.exception("Exception inside rpc %d:0x%04X, payload=%s",
                                   address, rpc_id, payload)
            raise

Asynchronously send an RPC to this IOTile device

Args:
conn_id (int): A unique identifier that will refer to this connection
address (int): the address of the tile that we wish to send the RPC to
rpc_id (int): the 16-bit id of the RPC we want to call
payload (bytearray): the payload of the command
timeout (float): the number of seconds to wait for the RPC to execute


def _load_dataset_clipping(self, dataset_dir, epsilon):
    self.dataset_max_clip = {}
    self.dataset_min_clip = {}
    self._dataset_image_count = 0
    for fname in os.listdir(dataset_dir):
        if (not fname.endswith('.png')):
            continue
        image_id = fname[:(- 4)]
        image = np.array(Image.open(os.path.join(dataset_dir, fname)).convert('RGB'))
        image = image.astype('int32')
        self._dataset_image_count += 1
        self.dataset_max_clip[image_id] = np.clip((image + epsilon), 0, 255).astype('uint8')
        self.dataset_min_clip[image_id] = np.clip((image - epsilon), 0, 255).astype('uint8')

Helper method which loads dataset and determines clipping range.

Args:
dataset_dir: location of the dataset.
epsilon: maximum allowed size of adversarial perturbation.


def read(self, key, array=False, embedded=True):
    self.tcex.log.debug('read variable {}'.format(key))
    data = key
    if (key is not None):
        key = key.strip()
        key_type = self.variable_type(key)
        if re.match(self._variable_match, key):
            if (key_type in self.read_data_types):
                if (key_type in ['Binary', 'BinaryArray']):
                    data = self.read_data_types[key_type](key)
                else:
                    data = self.read_data_types[key_type](key, embedded)
            else:
                data = self.read_raw(key)
        else:
            if (key_type == 'String'):
                data = re.sub('(?<!\\\\)\\\\s', ' ', data)
                data = re.sub('\\\\\\\\s', '\\s', data)
            if embedded:
                data = self.read_embedded(data, key_type)
    if (array and (not isinstance(data, list))):
        if (data is not None):
            data = [data]
        else:
            data = []
    return data

Read method of CRUD operation for working with KeyValue DB.

This method will automatically check to see if a single variable is passed
or if "mixed" data is passed and return the results from the DB. It will also
automatically determine the variable type to read.

Args:
key (string): The variable to read from the DB.
array (boolean): Convert string/dict to Array/List before returning.
embedded (boolean): Resolve embedded variables.

Returns:
(any): Results retrieved from DB


def make_encoder(activation, latent_size, base_depth):

  conv = functools.partial(
      tf.keras.layers.Conv2D, padding="SAME", activation=activation)

  encoder_net = tf.keras.Sequential([
      conv(base_depth, 5, 1),
      conv(base_depth, 5, 2),
      conv(2 * base_depth, 5, 1),
      conv(2 * base_depth, 5, 2),
      conv(4 * latent_size, 7, padding="VALID"),
      tf.keras.layers.Flatten(),
      tf.keras.layers.Dense(2 * latent_size, activation=None),
  ])

  def encoder(images):
    images = 2 * tf.cast(images, dtype=tf.float32) - 1
    net = encoder_net(images)
    return tfd.MultivariateNormalDiag(
        loc=net[..., :latent_size],
        scale_diag=tf.nn.softplus(net[..., latent_size:] +
                                  _softplus_inverse(1.0)),
        name="code")

  return encoder

Creates the encoder function.

Args:
activation: Activation function in hidden layers.
latent_size: The dimensionality of the encoding.
base_depth: The lowest depth for a layer.

Returns:
encoder: A `callable` mapping a `Tensor` of images to a
`tfd.Distribution` instance over encodings.


def __init__(self, workdir, prefix):

        self._workdir = workdir
        self._prefix = prefix

        self._pprefix = SDKWrapper(weakref.proxy(self._prefix))

__init__

Args:
workdir(:class:`~lago.workdir.Workdir`): The enviornment
workdir.
prefix(:class:~lago.prefix.Prefix): The enviornment Prefix.

Returns:
None


def choices_validator(choices):

    def validator(value):
        if value not in choices:

            raise ValidationError(
                "{} is not in {}".format(value, list(choices))
            )

    return validator

Return validator function that will check if ``value in choices``.

Args:
max_value (list, set, tuple): allowed choices for new validator


def get_samples_live(self, sensor_id, last=None):

    url = "https:

    headers = self.__gen_headers()
    headers["Content-Type"] = "application/json"

    params = { "sensorId": sensor_id }
    if last:
      params["last"] = last
    url = self.__append_url_params(url, params)

    r = requests.get(url, headers=headers)
    return r.json()

Get recent samples, one sample per second for up to the last 2 minutes.

Args:
sensor_id (string): hexadecimal id of the sensor to query, e.g.
``0x0013A20040B65FAD``
last (string): starting range, as ISO8601 timestamp

Returns:
list: dictionary objects containing sample data


def copy(self, source_file_names, destination_file_names):
    err_msg = 'source_file_names and destination_file_names should be equal in length'
    assert len(source_file_names) == len(destination_file_names), err_msg

    def _copy_path(source, destination):

        if not destination.startswith(GCSFileSystem.GCS_PREFIX):
            raise ValueError('Destination %r must be GCS path.' % destination)
        if source.endswith('/'):
            self._gcsIO().copytree(source, destination)
        else:
            self._gcsIO().copy(source, destination)
    exceptions = {}
    for source, destination in zip(source_file_names, destination_file_names):
        try:
            _copy_path(source, destination)
        except Exception as e:
            exceptions[source, destination] = e
    if exceptions:
        raise BeamIOError('Copy operation failed', exceptions)

Recursively copy the file tree from the source to the destination

Args:
source_file_names: list of source file objects that needs to be copied
destination_file_names: list of destination of the new object

Raises:
``BeamIOError``: if any of the copy operations fail


def _list_node_dumps(self, node_name):
    lines = []
    font_attr_segs = {}
    watch_keys = self._debug_dump.debug_watch_keys(node_name)
    dump_count = 0
    for watch_key in watch_keys:
        debug_tensor_data = self._debug_dump.watch_key_to_data(watch_key)
        for datum in debug_tensor_data:
            line = '  Slot %d @ %s @ %.3f ms' % (datum.output_slot, datum.debug_op, (datum.timestamp - self._debug_dump.t0) / 1000.0)
            lines.append(line)
            command = 'pt %s:%d -n %d' % (node_name, datum.output_slot, dump_count)
            font_attr_segs[len(lines) - 1] = [(2, len(line), debugger_cli_common.MenuItem(None, command))]
            dump_count += 1
    output = debugger_cli_common.RichTextLines(lines, font_attr_segs=font_attr_segs)
    output_with_header = debugger_cli_common.RichTextLines(['%d dumped tensor(s):' % dump_count, ''])
    output_with_header.extend(output)
    return output_with_header

List dumped tensor data from a node.

Args:
node_name: Name of the node of which the attributes are to be listed.

Returns:
A RichTextLines object.


def add_string_pairs_from_text_field_element(xib_file, results, text_field, special_ui_components_prefix):
    text_field_entry_comment = extract_element_internationalized_comment(text_field)
    if (text_field_entry_comment is None):
        return
    if (text_field.hasAttribute('usesAttributedText') and (text_field.attributes['usesAttributedText'].value == 'YES')):
        add_string_pairs_from_attributed_ui_element(results, text_field, text_field_entry_comment)
    else:
        try:
            text_field_entry_key = text_field.attributes['text'].value
            results.append((text_field_entry_key, (text_field_entry_comment + ' default text value')))
        except KeyError:
            pass
    try:
        text_field_entry_key = text_field.attributes['placeholder'].value
        results.append((text_field_entry_key, (text_field_entry_comment + ' placeholder text value')))
    except KeyError:
        pass
    warn_if_element_not_of_class(text_field, 'TextField', special_ui_components_prefix)

Adds string pairs from a textfield element.

Args:
xib_file (str): Path to the xib file.
results (list): The list to add the results to.
text_field(element): The textfield element from the xib, to extract the string pairs from.
special_ui_components_prefix (str):
If not None, extraction will not warn about internationalized UI components with this class prefix.


def draw_text(img, text, position=(10, 10), font='FreeSans.ttf', font_size=14, color=(0, 0, 0)):
    _check_pil()
    font_files = _find_font_file(font)
    if (len(font_files) == 0):
        logger.warn("Failed to lookup font '{}', falling back to default".format(font))
        font = ImageFont.load_default()
    else:
        font = ImageFont.truetype(font_files[0], font_size)
    img = Image.fromarray(img)
    draw = ImageDraw.Draw(img)
    draw.text(position, text, fill=color, font=font)
    return np.asarray(img)

Draws text over the image. Requires PIL.

Args:
img: The image to use.
text: The text string to overlay.
position: The text (x, y) position. (Default value = (10, 10))
font: The ttf or open type font to use. (Default value = 'FreeSans.ttf')
font_size: The text font size. (Default value = 12)
color: The (r, g, b) values for text color. (Default value = (0, 0, 0))

Returns: Image overlayed with text.


def pymmh3_hash128(key: Union[bytes, bytearray],
                   seed: int = 0,
                   x64arch: bool = True) -> int:

    if x64arch:
        return pymmh3_hash128_x64(key, seed)
    else:
        return pymmh3_hash128_x86(key, seed)

Implements 128bit murmur3 hash, as per ``pymmh3``.

Args:
key: data to hash
seed: seed
x64arch: is a 64-bit architecture available?

Returns:
integer hash


def save(self, sess, save_path, timestep=None):

        if self._saver is None:
            raise TensorForceError("register_saver_ops should be called before save")
        return self._saver.save(
            sess=sess,
            save_path=save_path,
            global_step=timestep,
            write_meta_graph=False,
            write_state=True,
        )

Saves this component's managed variables.

Args:
sess: The session for which to save the managed variables.
save_path: The path to save data to.
timestep: Optional, the timestep to append to the file name.

Returns:
Checkpoint path where the model was saved.


async def datacenters(self):
    response = (await self._api.get('/v1/coordinate/datacenters'))
    return {data['Datacenter']: data for data in response.body}

Queries for WAN coordinates of Consul servers

Returns:
Mapping: WAN network coordinates for all Consul
servers, organized by DCs.

It returns a body like this::

{
"dc1": {
"Datacenter": "dc1",
"Coordinates": [
{
"Node": "agent-one",
"Coord": {
"Adjustment": 0,
"Error": 1.5,
"Height": 0,
"Vec": [0,0,0,0,0,0,0,0]
}
}
]
}
}

This endpoint serves data out of the server's local Serf data about
the WAN, so its results may vary as requests are handled by different
servers in the cluster.

Also, it does not support blocking queries or any consistency modes.


def try_evaluate_constant(tensor):
    with tensor.graph._c_graph.get() as c_graph:
        return c_api.TF_TryEvaluateConstant_wrapper(c_graph, tensor._as_tf_output())

Evaluates a symbolic tensor as a constant.

Args:
tensor: a symbolic Tensor.

Returns:
ndarray if the evaluation succeeds, or None if it fails.


def read(cls, data):

        if isinstance(data, pd.DataFrame):
            return cls((json.loads(
                to_json_stat(data, output='dict', version='2.0'),
                object_pairs_hook=OrderedDict)))
        elif isinstance(data, OrderedDict):
            return cls(data)
        elif (isinstance(data, basestring)
              and data.startswith(("http:
                                   "ftp:

            return cls(request(data))
        elif isinstance(data, basestring):
            try:
                json_dict = json.loads(data, object_pairs_hook=OrderedDict)
                return cls(json_dict)
            except ValueError:
                raise
        else:
            try:
                json_dict = json.load(data, object_pairs_hook=OrderedDict)
                return cls(json_dict)
            except ValueError:
                raise

Reads data from URL, Dataframe, JSON string, JSON file or
OrderedDict.
Args:
data: can be a Pandas Dataframe, a JSON file, a JSON string,
an OrderedDict or a URL pointing to a JSONstat file.

Returns:
An object of class Dataset populated with data.


def exists_evaluator(self, index):
    attr_name = self.condition_data[index][0]
    return (self.attributes.get(attr_name) is not None)

Evaluate the given exists match condition for the user attributes.

Args:
index: Index of the condition to be evaluated.

Returns:
Boolean: True if the user attributes have a non-null value for the given condition,
otherwise False.


def site_occupation_statistics( self ):

        if self.time == 0.0:
            return None
        occupation_stats = { label : 0.0 for label in self.site_labels }
        for site in self.sites:
            occupation_stats[ site.label ] += site.time_occupied
        for label in self.site_labels:
            occupation_stats[ label ] /= self.time
        return occupation_stats

Average site occupation for each site type

Args:
None

Returns:
(Dict(Str:Float)): Dictionary of occupation statistics, e.g.::

{ 'A' : 2.5, 'B' : 25.3 }


def get_flat_tensor_shapes(element_spec):
    return [spec.shape for spec in get_flat_tensor_specs(element_spec)]

Returns a list `tf.TensorShapes`s for the element tensor representation.

Args:
element_spec: A nested structure of `tf.TypeSpec` objects representing to
element type specification.

Returns:
A list `tf.TensorShapes`s for the element tensor representation.


def get_execution_info(self, driver_id, function_descriptor):
    if self._worker.load_code_from_local:
        driver_id = ray.DriverID.nil()
        if (not function_descriptor.is_actor_method()):
            self._load_function_from_local(driver_id, function_descriptor)
    else:
        with profiling.profile('wait_for_function'):
            self._wait_for_function(function_descriptor, driver_id)
    try:
        function_id = function_descriptor.function_id
        info = self._function_execution_info[driver_id][function_id]
    except KeyError as e:
        message = ('Error occurs in get_execution_info: driver_id: %s, function_descriptor: %s. Message: %s' % (driver_id, function_descriptor, e))
        raise KeyError(message)
    return info

Get the FunctionExecutionInfo of a remote function.

Args:
driver_id: ID of the driver that the function belongs to.
function_descriptor: The FunctionDescriptor of the function to get.

Returns:
A FunctionExecutionInfo object.


def l1_regression_loss(y, target, name=None):

  with tf.name_scope(name, 'l1_regression', [y, target]) as scope:
    y = tf.convert_to_tensor(y, name='y')
    target = tf.convert_to_tensor(target, name='target')
    return reduce_batch_sum(tf.abs(y - target), name=scope)

Calculates the sum of absolute errors between y and target.

Args:
y: the calculated values.
target: the desired values.
name: the name for this op, defaults to l1_regression
Returns:
A tensorflow op.


def _BuildFindSpecsFromGroupName(self, group_name, environment_variables):

    definition = self._artifacts_registry.GetDefinitionByName(group_name)
    if not definition:
      return None

    return self._BuildFindSpecsFromArtifact(definition, environment_variables)

Builds find specifications from a artifact group name.

Args:
group_name (str): artifact group name.
environment_variables (list[str]): environment variable attributes used to
dynamically populate environment variables in file and registry
artifacts.

Returns:
list[dfwinreg.FindSpec|dfvfs.FindSpec]: find specifications or None if no
artifact with the given name can be retrieved.


def __init__(self, channel):

        self.GetModel = channel.unary_unary(
            "/google.cloud.bigquery.v2.ModelService/GetModel",
            request_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.GetModelRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.Model.FromString,
        )
        self.ListModels = channel.unary_unary(
            "/google.cloud.bigquery.v2.ModelService/ListModels",
            request_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.ListModelsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.ListModelsResponse.FromString,
        )
        self.PatchModel = channel.unary_unary(
            "/google.cloud.bigquery.v2.ModelService/PatchModel",
            request_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.PatchModelRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.Model.FromString,
        )
        self.DeleteModel = channel.unary_unary(
            "/google.cloud.bigquery.v2.ModelService/DeleteModel",
            request_serializer=google_dot_cloud_dot_bigquery__v2_dot_proto_dot_model__pb2.DeleteModelRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def _extract_defaults(self, defaults_var: 'cfg.Variable') -> 'tuple[cfg.Variable, ...] | None':
    if all((isinstance(d, _instances.Tuple) for d in defaults_var.data)):
        return max((d.pyval for d in defaults_var.data), key=len)
    else:
        if not (all((isinstance(d, (_instance_base.Instance, _singletons.Unknown, _singletons.Unsolvable)) for d in defaults_var.data)) and all((d.full_name == 'builtins.tuple' for d in defaults_var.data if isinstance(d, _instance_base.Instance)))):
            self.ctx.errorlog.bad_function_defaults(self.ctx.vm.frames, self.name)
        return None

Extracts defaults from a Variable, used by set_function_defaults.

Args:
defaults_var: Variable containing potential default values.

Returns:
A tuple of default values, if one could be extracted, or None otherwise.


def convert_seeded_answers(answers):

    converted = {}
    for index, answer in enumerate(answers):
        converted.setdefault(answer['answer'], {})
        converted[answer['answer']]['seeded' + str(index)] = answer['rationale']

    return converted

Convert seeded answers into the format that can be merged into student answers.

Args:
answers (list): seeded answers

Returns:
dict: seeded answers with student answers format:
{
0: {
'seeded0': 'rationaleA'
}
1: {
'seeded1': 'rationaleB'
}
}


def parse_datetime(__string: str) -> datetime.datetime:

    if not __string:
        datetime_ = datetime.datetime.now(datetime.timezone.utc)
    else:

        datetime_ = ciso8601.parse_datetime(__string)
    if datetime_.tzinfo is None:
        datetime_ = datetime_.replace(tzinfo=datetime.timezone.utc)
    return datetime_

Parse ISO-8601 datetime string.

Args:
__string: Datetime string to parse
Returns:
Parsed datetime object