def call(self, node: 'cfg.CFGNode', func: 'cfg.Binding', args: 'function.Args', alias_map: 'datatypes.UnionFind | None'=None):
    raise NotImplementedError(self.__class__.__name__)

Call this abstract value with the given arguments.

The posargs and namedargs arguments may be modified by this function.

Args:
node: The CFGNode calling this function
func: The cfg.Binding containing this function.
args: Arguments for the call.
alias_map: A datatypes.UnionFind, which stores all the type renaming
information, mapping of type parameter name to its representative.

Returns:
A tuple (cfg.Node, cfg.Variable). The CFGNode corresponds
to the function's "return" statement(s).
Raises:
function.FailedFunctionCall

Make the call as required by this specific kind of atomic value, and make
sure to annotate the results correctly with the origins (val and also other
values appearing in the arguments).


def process_tokens(self, tokens):

        for tok_type, token, (start_row, start_col), _, _ in tokens:
            if tok_type == tokenize.STRING:

                self._process_string_token(token, start_row, start_col)

Process the token stream.

This is required to override the parent class' implementation.

Args:
tokens: the tokens from the token stream to process.


def SendReply(self, rdf_value=None, request_id=None, response_id=None, session_id='W:0', message_type=None, name=None, require_fastpoll=None, ttl=None, blocking=True, task_id=None):
    if (not isinstance(rdf_value, rdfvalue.RDFValue)):
        raise RuntimeError('Sending objects other than RDFValues not supported.')
    message = rdf_flows.GrrMessage(session_id=session_id, task_id=task_id, name=name, response_id=response_id, request_id=request_id, require_fastpoll=require_fastpoll, ttl=ttl, type=message_type)
    if (rdf_value is not None):
        message.payload = rdf_value
    serialized_message = message.SerializeToString()
    self.ChargeBytesToSession(session_id, len(serialized_message))
    if (message.type == rdf_flows.GrrMessage.Type.STATUS):
        rdf_value.network_bytes_sent = self.sent_bytes_per_flow[session_id]
        del self.sent_bytes_per_flow[session_id]
        message.payload = rdf_value
    try:
        self.QueueResponse(message, blocking=blocking)
    except queue.Full:
        if (not blocking):
            raise
        logging.info('Queue is full, dropping messages.')

Send the protobuf to the server.

Args:
rdf_value: The RDFvalue to return.
request_id: The id of the request this is a response to.
response_id: The id of this response.
session_id: The session id of the flow.
message_type: The contents of this message, MESSAGE, STATUS or
RDF_VALUE.
name: The name of the client action that sends this response.
require_fastpoll: If set, this will set the client to fastpoll mode after
sending this message.
ttl: The time to live of this message.
blocking: If the output queue is full, block until there is space.
task_id: The task ID that the request was queued at. We send this back to
the server so it can de-queue the request.

Raises:
RuntimeError: An object other than an RDFValue was passed for sending.


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

    if not path_spec:
      raise ValueError('Missing path specification.')

    file_system = resolver.Resolver.OpenFileSystem(
        path_spec, resolver_context=self._resolver_context)

    file_entry = file_system.GetFileEntryByPathSpec(path_spec)
    if not file_entry:
      file_system.Close()
      raise IOError('Unable to retrieve file entry.')

    if not file_entry.IsFile():
      file_system.Close()
      raise IOError('Not a regular file.')

    self._file_system = file_system
    tar_file = self._file_system.GetTARFile()
    tar_info = file_entry.GetTARInfo()

    self._tar_ext_file = tar_file.extractfile(tar_info)

    self._current_offset = 0
    self._size = tar_info.size

Opens the file-like object defined by path specification.

Args:
path_spec (Optional[PathSpec]): path specification.
mode (Optional[str]): file access mode.

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


def _ParseExtensionsString(self, extensions_string):

    if not extensions_string:
      return

    extensions_string = extensions_string.lower()
    extensions = [
        extension.strip() for extension in extensions_string.split(',')]
    file_entry_filter = file_entry_filters.ExtensionsFileEntryFilter(extensions)
    self._filter_collection.AddFilter(file_entry_filter)

Parses the extensions string.

Args:
extensions_string (str): comma separated extensions to filter.


def delete(self, filename):
    if is_package(filename):
        self.connection['jss'].Package(filename).delete()
    else:
        self.connection['jss'].Script(filename).delete()

Delete a package or script from the distribution server.

This method simply finds the Package or Script object from the
database with the API GET call and then deletes it. This will
remove the file from the database blob.

For setups which have file share distribution points, you will
need to delete the files on the shares also.

Args:
filename: Filename (no path) to delete.


def from_json_str(cls, json_str):

    return cls.from_json(json.loads(json_str, cls=JsonDecoder))

Convert json string representation into class instance.

Args:
json_str: json representation as string.

Returns:
New instance of the class with data loaded from json string.


def forward(self, input, tokens_per_expert):
    return sequential_experts_gemm(input, self.weight, tokens_per_expert.cpu())

Perform grouped matrix multiplication.

Args:
input (`torch.Tensor`):
Input tensor of shape (num_tokens, in_features).
tokens_per_expert (`torch.Tensor`):
Number of tokens assigned to each expert.

Returns:
torch.Tensor: Output tensor of shape (num_tokens, out_features).


def rating(self, **kwargs):
    path = self._get_id_path('rating')
    payload = {'value': kwargs.pop('value', None)}
    response = self._POST(path, kwargs, payload)
    self._set_attrs_to_values(response)
    return response

This method lets users rate a movie. A valid session id or guest
session id is required.

Args:
session_id: see Authentication.
guest_session_id: see Authentication.
value: Rating value.

Returns:
A dict representation of the JSON returned from the API.


def ring_source(self):
    if (self.type != EventType.TABLET_PAD_RING):
        raise AttributeError(_wrong_prop.format(self.type))
    return self._libinput.libinput_event_tablet_pad_get_ring_source(self._handle)

The source of the interaction with the ring.

If the source is
:attr:`~libinput.constant.TabletPadRingAxisSource.FINGER`,
libinput sends a ring position value of -1 to terminate
the current interaction.

For events not of type
:attr:`~libinput.constant.EventType.TABLET_PAD_RING`, this property
raises :exc:`AttributeError`.

Returns:
~libinput.constant.TabletPadRingAxisSource: The source of the ring
interaction.
Raises:
AttributeError


def delete_operation(self, name, options=None):
    request = operations_pb2.DeleteOperationRequest(name=name)
    self._delete_operation(request, options)

Deletes a long-running operation. This method indicates that the client is
no longer interested in the operation result. It does not cancel the
operation. If the server doesn't support this method, it returns
``google.rpc.Code.UNIMPLEMENTED``.

Example:
>>> from google.gapic.longrunning import operations_client
>>> api = operations_client.OperationsClient()
>>> name = ''
>>> api.delete_operation(name)

Args:
name (string): The name of the operation resource to be deleted.
options (:class:`google.gax.CallOptions`): Overrides the default
settings for this call, e.g, timeout, retries etc.

Raises:
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
:exc:`ValueError` if the parameters are invalid.


def UpdateVFSFileAndWait(client_id, vfs_file_urn, token=None, timeout=DEFAULT_TIMEOUT):
    update_flow_urn = StartFlowAndWait(client_id, token=token, timeout=timeout, flow_name=aff4_grr.UpdateVFSFile.__name__, vfs_file_urn=vfs_file_urn)
    update_flow_obj = aff4.FACTORY.Open(update_flow_urn, token=token, aff4_type=flow.GRRFlow)
    sub_flow_urn = update_flow_obj.state.get_file_flow_urn
    if (not sub_flow_urn):
        return
    WaitForFlow(sub_flow_urn, token=token, timeout=timeout)

Waits for a file to be updated on the client.

Calls the UpdateVFSFile flow on a urn and waits for both it and the
ListDirectory flow it calls to finish.

Note that this is needed because any flows UpdateVFSFile calls via
VFS Update methods will not become child flows of UpdateVFSFile,
and therefore waiting for UpdateVFSFile to complete is not enough.

Args:
client_id: Which client to run the flow on.
vfs_file_urn: Path to VFSFile to update.
token: The datastore access token.
timeout: How long to wait for a flow to finish, maximum.


def value_rowids(self):
    if self._value_rowids is not None:
        return self._value_rowids
    return segment_id_ops.row_splits_to_segment_ids(self._row_splits)

Returns the row indices for this row partition.

`value_rowids` specifies the row index fo reach value.  In particular,
`value_rowids[i]` is the row index for `values[i]`.

Returns:
A 1-D integer `Tensor` with shape `[self.nvals()]`.
The returned tensor is nonnegative, and is sorted in ascending order.


def start(self, auto_register=True):
    return self.container.start_agent(agent=self, auto_register=auto_register)

Tells the container to start this agent.
It returns a coroutine or a future depending on whether it is called from a coroutine or a synchronous method.

Args:
auto_register (bool): register the agent in the server (Default value = True)


def _create_table_init_from_file_qat_model_tf1(self, sess: session.Session) -> Tuple[core.Tensor, core.Tensor, core.Tensor]:
    asset_dir = self.create_tempdir('assets').full_path
    asset_file = os.path.join(asset_dir, 'vocab_file.txt')
    content = '\n'.join(['static', 'range', 'quantization'])
    file_io.write_string_to_file(filename=asset_file, file_content=content)
    init = lookup_ops.TextFileInitializer(filename=asset_file, key_dtype=dtypes.string, key_index=lookup_ops.TextFileIndex.WHOLE_LINE, value_dtype=dtypes.int64, value_index=lookup_ops.TextFileIndex.LINE_NUMBER)
    table = lookup_ops.StaticHashTable(init, default_value=-1)
    input_vocabs_placeholder = array_ops.placeholder(dtypes.string, shape=(None,), name='input_vocabs')
    lookup_vals = math_ops.cast(table.lookup(input_vocabs_placeholder), dtypes.float32)
    matmul_input = array_ops_stack.stack([lookup_vals, lookup_vals])
    matmul_input = array_ops.fake_quant_with_min_max_args(matmul_input, min=-0.3, max=0.3, num_bits=8, narrow_range=False)
    weight_row = array_ops.ones(shape=array_ops.shape(input_vocabs_placeholder), dtype=dtypes.float32)
    weight = array_ops.transpose_v2(array_ops_stack.stack([weight_row, weight_row]))
    weight = array_ops.fake_quant_with_min_max_args(weight, min=-0.1, max=0.2, num_bits=8, narrow_range=False)
    output_tensor = math_ops.matmul(matmul_input, weight)
    output_tensor = array_ops.fake_quant_with_min_max_args(output_tensor, min=-0.2, max=0.2, num_bits=8, narrow_range=False)
    return (input_vocabs_placeholder, lookup_vals, output_tensor)

Creates a simple QAT model that initializes a table from an asset file.

This model creates an asset file at "vocab_file.txt" containing
comma-separated vocabularies and uses it to initialize a
`StaticVocabularyTable`. For inference, the model performs a lookup with a
1D string tensor input vocabs.

Args:
sess: Tensorflow Session to create the model in.

Returns:
(input_vocabs_placeholder, lookup_vals, output_tensor), where
* input_vocabs_placeholder is a placeholder tensor of 1D strings
* lookup_vals is an output tensor that is a direct result of table lookup
* output_tensor is a float 2x2 matrix


def setContext(self, context_str):
    if ((len(self.m_context) == 0) and (len(context_str) >= 7)):
        if (context_str[0:7] != 'request'):
            ekm_log(('Context: ' + context_str))
    self.m_context = context_str

Set context string for serial command.  Private setter.

Args:
context_str (str): Command specific string.


def ParseOptions(cls, options, configuration_object):

    if not isinstance(configuration_object, tools.CLITool):
      raise errors.BadConfigObject(
          'Configuration object is not an instance of CLITool')

    filter_file = cls._ParseStringOption(options, 'file_filter')

    if filter_file and not os.path.isfile(filter_file):
      data_location = getattr(configuration_object, '_data_location', None)
      if data_location:
        filter_file_basename = os.path.basename(filter_file)
        filter_file_path = os.path.join(data_location, filter_file_basename)
        if os.path.isfile(filter_file_path):
          filter_file = filter_file_path

    if filter_file and not os.path.isfile(filter_file):
      raise errors.BadConfigOption(
          'No such collection filter file: {0:s}.'.format(filter_file))

    setattr(configuration_object, '_filter_file', filter_file)

Parses and validates options.

Args:
options (argparse.Namespace): parser options.
configuration_object (CLITool): object to be configured by the argument
helper.

Raises:
BadConfigObject: when the configuration object is of the wrong type.
BadConfigOption: if the collection file does not exist.


def call(self, hidden_states: tf.Tensor, attention_mask: tf.Tensor, layer_head_mask: tf.Tensor, training: Optional[bool]=False):
    residual = hidden_states
    hidden_states = self.self_attn_layer_norm(hidden_states)
    hidden_states, self_attn_weights, _ = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, layer_head_mask=layer_head_mask)
    tf.debugging.assert_equal(shape_list(hidden_states), shape_list(residual), message=f'Self attn modified the shape of query {shape_list(residual)} to {shape_list(hidden_states)}')
    hidden_states = self.dropout(hidden_states, training=training)
    hidden_states = residual + hidden_states
    residual = hidden_states
    hidden_states = self.final_layer_norm(hidden_states)
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = self.activation_dropout(hidden_states, training=training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = self.dropout(hidden_states, training=training)
    hidden_states = residual + hidden_states
    return (hidden_states, self_attn_weights)

Args:
hidden_states (`tf.Tensor`): input to the layer of shape *(batch, seq_len, embed_dim)*
attention_mask (`tf.Tensor`): attention mask of size
*(batch, 1, tgt_len, src_len)* where padding elements are indicated by very large negative values.
layer_head_mask (`tf.Tensor`): mask for attention heads in a given layer of size
*(encoder_attention_heads,)*


def set(self, id, newObj):

        newObj = self.validation(newObj)
        for index in xrange(0, len(self.model.db)):
            if self.model.db[index]["id"] != id:
                continue

            newObj["id"] = id
            self.model.db[index] = self._cast_model(newObj)
            if not self._batch.enable.is_set():
                self.model.save_db()
            return self.model.db[index]

        return None

Set a object
Args:
id (int): Target Object ID
newObj (object): New object will be set
Returns:
Object: New object
None: If specified object id is not found
MultipleInvalid: If input object is invaild


def __init__(self, namespace, extractor=None):
    self.namespace = namespace
    self.counter = Metrics.counter(self.namespace, self.LABEL)
    self.extractor = extractor if extractor else lambda x: (yield x)

Initializes :class:`MeasureBytes`.

Args:
namespace(str): metric namespace
extractor: function to extract elements to be count


def softmax(x, axis=-1):
    return nn.softmax(x, axis=axis)

Softmax of a tensor.

Args:
x: A tensor or variable.
axis: The dimension softmax would be performed on.
The default is -1 which indicates the last dimension.

Returns:
A tensor.


def build_info_dict(vcf_info):

    logger = logging.getLogger(__name__)
    logger.debug("Building info dict")
    info_dict = OrderedDict()

    for info in vcf_info.split(';'):
        info = info.split('=')
        if len(info) > 1:

            info[1] = '='.join(info[1:])
            info_dict[info[0]] = info[1].split(',')
        else:
            info_dict[info[0]] = []

    return info_dict

Build a dictionary from the info of a vcf line

The dictionary will have the info keys as keys and info values as values.
Values will allways be lists that are splitted on ','

Arguments:
vcf_info (str): A string with vcf info

Returns:
info_dict (OrderedDict): A ordered dictionary with the vcf info keys as
keys and lists of values as values


def wait_until_element_not_visible(webdriver, locator_lambda_expression,
                                       timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5):

        try:
            stoptime = datetime.now() + timedelta(seconds=timeout)
            while datetime.now() < stoptime:
                element = WebDriverWait(webdriver, WTF_TIMEOUT_MANAGER.BRIEF).until(
                    locator_lambda_expression)
                if element.is_displayed():
                    time.sleep(sleep)
                else:
                    break
        except TimeoutException:
            pass

Wait for a WebElement to disappear.

Args:
webdriver (Webdriver) - Selenium Webdriver
locator (lambda) - Locator lambda expression.

Kwargs:
timeout (number) - timeout period
sleep (number) - sleep period between intervals.


def _ParseEntryObject(self, file_object, file_offset):

    entry_object_map = self._GetDataTypeMap('systemd_journal_entry_object')

    try:
      entry_object, _ = self._ReadStructureFromFileObject(
          file_object, file_offset, entry_object_map)
    except (ValueError, errors.ParseError) as exception:
      raise errors.ParseError((
          'Unable to parse entry object at offset: 0x{0:08x} with error: '
          '{1!s}').format(file_offset, exception))

    if entry_object.object_type != self._OBJECT_TYPE_ENTRY:
      raise errors.ParseError('Unsupported object type: {0:d}.'.format(
          entry_object.object_type))

    if entry_object.object_flags != 0:
      raise errors.ParseError('Unsupported object flags: 0x{0:02x}.'.format(
          entry_object.object_flags))

    return entry_object

Parses an entry object.

Args:
file_object (dfvfs.FileIO): a file-like object.
file_offset (int): offset of the entry object relative to the start
of the file-like object.

Returns:
systemd_journal_entry_object: entry object.

Raises:
ParseError: if the entry object cannot be parsed.


def save_mat(ts, filename):

    import scipy.io as sio
    tspan = ts.tspan
    fs = (1.0*len(tspan) - 1) / (tspan[-1] - tspan[0])
    mat_dict = {'data': np.asarray(ts),
                'fs': fs,
                'labels': ts.labels[1]}
    sio.savemat(filename, mat_dict, do_compression=True)
    return

save a Timeseries to a MATLAB .mat file
Args:
ts (Timeseries): the timeseries to save
filename (str): .mat filename to save to


def get_profile_ports(self, **kwargs):
    uri = self._helper.build_uri_with_query_string(kwargs, '/profile-ports')
    return self._helper.do_get(uri)

Retrieves the port model associated with a server or server hardware type and enclosure group.

Args:
enclosureGroupUri (str):
The URI of the enclosure group associated with the resource.
serverHardwareTypeUri (str):
The URI of the server hardware type associated with the resource.
serverHardwareUri (str):
The URI of the server hardware associated with the resource.

Returns:
dict: Profile port.


def replace_gradient_components(self, value, component_grads):
    return component_grads

Replaces the gradient components in `value` with `component_grads`.

The gradient of a ResourceVariable is either None or a Tensor. So we don't
need `value`'s TypeSpec or non-gradient components in this method.

Args:
value: A `ResourceVariable` with its gradient components compatible with
`component_grads`.
component_grads: A `Tensor` or None as the gradient result.

Returns:
The `component_grads`, which is either a `Tensor` or None.


def _load_schema(file_path, name=None):
    if (name is None):
        name = os.path.splitext(os.path.basename(file_path))[0]
    if (name not in _SCHEMAS):
        with open(file_path, 'r') as schema_file:
            _SCHEMAS[name] = json.load(schema_file)
    return _SCHEMAS[name]

Loads the QObj schema for use in future validations.

Caches schema in _SCHEMAS module attribute.

Args:
file_path(str): Path to schema.
name(str): Given name for schema. Defaults to file_path filename
without schema.
Return:
schema(dict): Loaded schema.


def check_onnxruntime_requirements(minimum_version: Version):
    try:
        import onnxruntime
        ort_version = parse(onnxruntime.__version__)
        if ort_version < ORT_QUANTIZE_MINIMUM_VERSION:
            raise ImportError(f'We found an older version of onnxruntime ({onnxruntime.__version__}) but we require onnxruntime to be >= {minimum_version} to enable all the conversions options.\nPlease update onnxruntime by running `pip install --upgrade onnxruntime`')
    except ImportError:
        raise ImportError("onnxruntime doesn't seem to be currently installed. Please install the onnxruntime by running `pip install onnxruntime` and relaunch the conversion.")

Check onnxruntime is installed and if the installed version match is recent enough

Raises:
ImportError: If onnxruntime is not installed or too old version is found


def _PrintWarningsDetails(self, storage):

    if not storage.HasWarnings():
      self._output_writer.Write('No warnings stored.\n\n')
      return

    for index, warning in enumerate(storage.GetWarnings()):
      title = 'Warning: {0:d}'.format(index)
      table_view = views.ViewsFactory.GetTableView(
          self._views_format_type, title=title)

      table_view.AddRow(['Message', warning.message])
      table_view.AddRow(['Parser chain', warning.parser_chain])

      path_specification = warning.path_spec.comparable
      for path_index, line in enumerate(path_specification.split('\n')):
        if not line:
          continue

        if path_index == 0:
          table_view.AddRow(['Path specification', line])
        else:
          table_view.AddRow(['', line])

      table_view.Write(self._output_writer)

Prints the details of the warnings.

Args:
storage (BaseStore): storage.


def _run_task_in_thread(self, task_fn, cluster_spec, task_type, task_id, *args, **kwargs):
    tf_config = kwargs.pop('tf_config', None)
    if tf_config is None:
        if task_type:
            tf_config = {'cluster': cluster_spec, 'task': {'type': task_type, 'index': task_id}}
        else:
            tf_config = {'cluster': cluster_spec}
    t = threading.Thread(target=self._task_thread, args=(task_fn, tf_config, context.executing_eagerly()) + args, kwargs=kwargs)
    t.start()
    return t

Run tasks in a thread.

If `tf_config` is provided, use it for the new thread; if not, construct one
from `cluster_spec`, `task_type`, and `task_id`, and provide it to the new
thread to be set as `TF_CONFIG` environment.

Args:
task_fn: The function to run in the new thread.
cluster_spec: The cluster spec.
task_type: The task type.
task_id: The task id.
*args: Additional positional arguments to provide to the thread's task_fn.
**kwargs: Additional keyword arguments to provide to the thread's task_fn.
If `tf_config` is provided, that dict will be used for the TF_CONFIG for
the new thread.

Returns:
The thread that has started.


def backslashcase(string):

    str1 = re.sub(r"_", r"\\", snakecase(string))

    return str1

Convert string into spinal case.
Join punctuation with backslash.

Args:
string: String to convert.

Returns:
string: Spinal cased string.


def SetPreferredLanguageIdentifier(self, language_identifier):
    if (not isinstance(language_identifier, py2to3.STRING_TYPES)):
        raise ValueError('Language identifier is not a string.')
    values = language_ids.LANGUAGE_IDENTIFIERS.get(language_identifier.lower(), None)
    if (not values):
        raise KeyError('Language identifier: {0:s} is not defined.'.format(language_identifier))
    self._language_identifier = language_identifier
    self._lcid = values[0]

Sets the preferred language identifier.

Args:
language_identifier (str): language identifier string such as "en-US"
for US English or "is-IS" for Icelandic.

Raises:
KeyError: if the language identifier is not defined.
ValueError: if the language identifier is not a string type.


def _pool_runner_worker(task_type, task_id, initializer, conn):
    if initializer:
        initializer = dill.loads(initializer)
        initializer()
    while True:
        try:
            fn, args, kwargs = conn.recv()
        except EOFError:
            break
        fn = dill.loads(fn)
        info = _run_contained(task_type, task_id, fn, args, kwargs)
        sys.stdout.flush()
        sys.stderr.flush()
        conn.send(info)

Function that runs on the workers in a pool.

It listens for callables to run and returns the result until `conn` is closed.
It captures the exceptions during executing the callable and return it through
`conn`.

Args:
task_type: the task type.
task_id: the task index.
initializer: a callable to execute during startup.
conn: a multiprocessing.Connection object to listen for tasks and send
results.


def Shell(device, *command):

    if command:
        return device.StreamingShell(' '.join(command))
    else:

        terminal_prompt = device.InteractiveShell()
        print(terminal_prompt.decode('utf-8'))

        while True:
            cmd = input('> ')
            if not cmd:
                continue
            elif cmd == 'exit':
                break
            else:
                stdout = device.InteractiveShell(cmd, strip_cmd=True, delim=terminal_prompt, strip_delim=True)
                if stdout:
                    if isinstance(stdout, bytes):
                        stdout = stdout.decode('utf-8')
                        print(stdout)

        device.Close()

Runs a command on the device and prints the stdout.

Args:
command: Command to run on the target.


def __init__(self, testcase: 'TensorFlowTestCase', target: Callable[..., Any], args: Optional[tuple[Any, ...]]=None, kwargs: Optional[dict[str, Any]]=None):
    self._testcase = testcase
    self._target = target
    self._args: tuple[Any, ...] = () if args is None else args
    self._kwargs: dict[str, Any] = {} if kwargs is None else kwargs
    self._thread = threading.Thread(target=self._protected_run)
    self._exception = None
    self._is_thread_joined = False

Constructs a new instance of _CheckedThread.

Args:
testcase: The TensorFlowTestCase for which this thread is being created.
target: A callable object representing the code to be executed in the
thread.
args: A tuple of positional arguments that will be passed to target.
kwargs: A dictionary of keyword arguments that will be passed to target.


def report_hit_filename(zipfilename: str, contentsfilename: str,
                        show_inner_file: bool) -> None:

    if show_inner_file:
        print("{} [{}]".format(zipfilename, contentsfilename))
    else:
        print(zipfilename)

For "hits": prints either the ``.zip`` filename, or the ``.zip`` filename
and the inner filename.

Args:
zipfilename: filename of the ``.zip`` file
contentsfilename: filename of the inner file
show_inner_file: if ``True``, show both; if ``False``, show just the
``.zip`` filename

Returns:


def ConsumeInt32(self):
    try:
        result = ParseInteger(self.token, is_signed=True, is_long=False)
    except ValueError as e:
        raise self._ParseError(str(e))
    self.NextToken()
    return result

Consumes a signed 32bit integer number.

Returns:
The integer parsed.

Raises:
ParseError: If a signed 32bit integer couldn't be consumed.


def track_trace(self, name, properties=None, severity=None):
    data = channel.contracts.MessageData()
    data.message = (name or NULL_CONSTANT_STRING)
    if properties:
        data.properties = properties
    if (severity is not None):
        data.severity_level = channel.contracts.MessageData.PYTHON_LOGGING_LEVELS.get(severity)
    self.track(data, self._context)

Sends a single trace statement.

Args:
name (str). the trace statement.\n
properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)\n
severity (str). the severity level of this trace, one of DEBUG, INFO, WARNING, ERROR, CRITICAL


def plot_title(ax, pretitle='', title='Figure', posttitle='', title_fontsize=14, title_arg=None):

    current_title = ax.get_title()

    if not current_title:
        current_title = pretitle + title + posttitle

    title_arg = dict_if_none(title_arg)

    ax.set_title(current_title, fontsize=title_fontsize, **title_arg)

Set title options of a matplotlib plot

Args:
ax: matplotlib axes
pretitle(str): String to include before the general title of the figure
posttitle (str): String to include after the general title of the figure
title (str): Set the title for the figure
title_fontsize (int): Defines the size of the title's font
title_arg (dict): Addition arguments for matplotlib.title() call


def record_value(self, value, count=1):
    if (value < 0):
        return False
    counts_index = self._counts_index_for(value)
    if ((counts_index < 0) or (self.counts_len <= counts_index)):
        return False
    self.counts[counts_index] += count
    self.total_count += count
    self.min_value = min(self.min_value, value)
    self.max_value = max(self.max_value, value)
    return True

Record a new value into the histogram

Args:
value: the value to record (must be in the valid range)
count: incremental count (defaults to 1)


def send_wsgi_response(status, headers, content, start_response, cors_handler=None):
    if cors_handler:
        cors_handler.update_headers(headers)
    content_len = (len(content) if content else 0)
    headers = [(header, value) for (header, value) in headers if (header.lower() != 'content-length')]
    headers.append(('Content-Length', ('%s' % content_len)))
    start_response(status, headers)
    return content

Dump reformatted response to CGI start_response.

This calls start_response and returns the response body.

Args:
status: A string containing the HTTP status code to send.
headers: A list of (header, value) tuples, the headers to send in the
response.
content: A string containing the body content to write.
start_response: A function with semantics defined in PEP-333.
cors_handler: A handler to process CORS request headers and update the
headers in the response.  Or this can be None, to bypass CORS checks.

Returns:
A string containing the response body.


def learn_sfa(self, mma=None):

        logging.info('Initializing learning procedure.')
        if mma:
            self._init_table_from_dfa(mma)
        else:
            self._init_table()

        logging.info('Generating a closed and consistent observation table.')
        while True:

            closed = False

            while not closed:
                logging.debug('Checking if table is closed.')
                closed, s = self.observation_table.is_closed()
                if not closed:
                    logging.debug('Closing table.')
                    self._ot_make_closed(s)
                else:
                    logging.debug('Table closed.')

            sfa = self.get_sfa_conjecture()

            logging.info('Generated conjecture machine with %d states.',
                         len(list(sfa.states)))

            logging.debug('Running equivalence query.')
            found, counter_example = self._equivalence_query(sfa)

            if found:
                logging.info('No counterexample found. Hypothesis is correct!')
                break

            logging.info(
                'Processing counterexample %s with length %d.',
                counter_example,
                len(counter_example))
            self._process_counter_example(sfa, counter_example)

        logging.info('Learning complete.')
        return '', sfa

Implements the high level loop of the algorithm for learning a
Mealy machine.
Args:
mma:
Returns:
MealyMachine: A model for the Mealy machine to be learned.


def add_node(self, node_descriptor):
    if ((self._max_nodes is not None) and (len(self.nodes) >= self._max_nodes)):
        raise ResourceUsageError('Maximum number of nodes exceeded', max_nodes=self._max_nodes)
    (node, inputs, processor) = parse_node_descriptor(node_descriptor, self.model)
    in_root = False
    for (i, input_data) in enumerate(inputs):
        (selector, trigger) = input_data
        walker = self.sensor_log.create_walker(selector)
        if walker.selector.inexhaustible:
            walker.reading = IOTileReading(4294967295, walker.selector.as_stream(), 0)
        node.connect_input(i, walker, trigger)
        if (selector.input and (not in_root)):
            self.roots.append(node)
            in_root = True
        else:
            found = False
            for other in self.nodes:
                if selector.matches(other.stream):
                    other.connect_output(node)
                    found = True
            if ((not found) and selector.buffered):
                raise NodeConnectionError('Node has input that refers to another node that has not been created yet', node_descriptor=node_descriptor, input_selector=str(selector), input_index=i)
    for other_node in self.nodes:
        for (selector, trigger) in other_node.inputs:
            if selector.matches(node.stream):
                node.connect_output(other_node)
    func = self.find_processing_function(processor)
    if (func is None):
        raise ProcessingFunctionError('Could not find processing function in installed packages', func_name=processor)
    node.set_func(processor, func)
    self.nodes.append(node)

Add a node to the sensor graph based on the description given.

The node_descriptor must follow the sensor graph DSL and describe
a node whose input nodes already exist.

Args:
node_descriptor (str): A description of the node to be added
including its inputs, triggering conditions, processing function
and output stream.


def get_model(self, opt_fn, emb_sz, n_hid, n_layers, **kwargs):

        m = get_language_model(self.nt, emb_sz, n_hid, n_layers, self.pad_idx, **kwargs)
        model = SingleModel(to_gpu(m))
        return RNN_Learner(self, model, opt_fn=opt_fn)

Method returns a RNN_Learner object, that wraps an instance of the RNN_Encoder module.

Args:
opt_fn (Optimizer): the torch optimizer function to use
emb_sz (int): embedding size
n_hid (int): number of hidden inputs
n_layers (int): number of hidden layers
kwargs: other arguments

Returns:
An instance of the RNN_Learner class.


def mkdir_interactive(dirpath):
    from benchbuild.utils.cmd import mkdir
    if os.path.exists(dirpath):
        return
    response = ui.ask('The directory {dirname} does not exist yet. Should I create it?'.format(dirname=dirpath), default_answer=True, default_answer_str='yes')
    if response:
        mkdir('-p', dirpath)
        print('Created directory {0}.'.format(dirpath))

Create a directory if required.

This will query the user for a confirmation.

Args:
dirname: The path to create.


def with_dependencies(dependencies, output_tensor, name=None):
    if context.executing_eagerly():
        return output_tensor
    with ops.name_scope(name, 'control_dependency', list(dependencies) + [output_tensor]) as name:
        with ops.colocate_with(output_tensor):
            with ops.control_dependencies(dependencies):
                output_tensor = ops.convert_to_tensor_or_composite(output_tensor)
                if isinstance(output_tensor, indexed_slices.IndexedSlices):
                    return indexed_slices.IndexedSlices(_Identity(output_tensor.values, name=name), output_tensor.indices, output_tensor.dense_shape)
                else:
                    return _Identity(output_tensor, name=name)

Produces the content of `output_tensor` only after `dependencies`.

In some cases, a user may want the output of an operation to be
consumed externally only after some other dependencies have run
first. This function ensures returns `output_tensor`, but only after all
operations in `dependencies` have run. Note that this means that there is
no guarantee that `output_tensor` will be evaluated after any `dependencies`
have run.

See also `tf.tuple` and `tf.group`.

Args:
dependencies: Iterable of operations to run before this op finishes.
output_tensor: A `Tensor` or `IndexedSlices` that will be returned.
name: (Optional) A name for this operation.

Returns:
Same as `output_tensor`.

Raises:
TypeError: if `output_tensor` is not a `Tensor` or `IndexedSlices`.


def vectorize(pyfunc, *, excluded=None, signature=None):
    if not callable(pyfunc):
        raise ValueError(f'Expected argument `pyfunc` to be a callable. Received: pyfunc={pyfunc}')
    return backend.numpy.vectorize(pyfunc, excluded=excluded, signature=signature)

Turn a function into a vectorized function.

Example:

```python
def myfunc(a, b):
return a + b

vfunc = keras.ops.vectorize(myfunc)
y = vfunc([1, 2, 3, 4], 2)  # Returns Tensor([3, 4, 5, 6])
```

Args:
pyfunc: Callable of a single tensor argument.
excluded: Optional set of integers representing
positional arguments for which the function
will not be vectorized.
These will be passed directly to `pyfunc` unmodified.
signature: Optional generalized universal function signature,
e.g., `"(m,n),(n)->(m)"` for vectorized
matrix-vector multiplication. If provided,
`pyfunc` will be called with (and expected to return)
arrays with shapes given by the size of corresponding
core dimensions. By default, `pyfunc` is assumed
to take scalars tensors as input and output.

Returns:
A new function that applies `pyfunc` to every element
of its input along axis 0 (the batch axis).


def _get_archive_filelist(filename):
    names = []
    if tarfile.is_tarfile(filename):
        with tarfile.open(filename) as tar_file:
            names = sorted(tar_file.getnames())
    elif zipfile.is_zipfile(filename):
        with zipfile.ZipFile(filename) as zip_file:
            names = sorted(zip_file.namelist())
    else:
        raise ValueError("Can not get filenames from '{!s}'. Not a tar or zip file".format(filename))
    if ('./' in names):
        names.remove('./')
    return names

Extract the list of files from a tar or zip archive.

Args:
filename: name of the archive

Returns:
Sorted list of files in the archive, excluding './'

Raises:
ValueError: when the file is neither a zip nor a tar archive
FileNotFoundError: when the provided file does not exist (for Python 3)
IOError: when the provided file does not exist (for Python 2)


def dump_seek(self, reading_id):
    if (self.dump_walker is None):
        return (pack_error(ControllerSubsystem.SENSOR_LOG, SensorLogError.STREAM_WALKER_NOT_INITIALIZED), Error.NO_ERROR, 0)
    try:
        exact = self.dump_walker.seek(reading_id, target='id')
    except UnresolvedIdentifierError:
        return (pack_error(ControllerSubsystem.SENSOR_LOG, SensorLogError.NO_MORE_READINGS), Error.NO_ERROR, 0)
    error = Error.NO_ERROR
    if (not exact):
        error = pack_error(ControllerSubsystem.SENSOR_LOG, SensorLogError.ID_FOUND_FOR_ANOTHER_STREAM)
    return (error, error.NO_ERROR, self.dump_walker.count())

Seek the dump streamer to a given ID.

Returns:
(int, int, int): Two error codes and the count of remaining readings.

The first error code covers the seeking process.
The second error code covers the stream counting process (cannot fail)
The third item in the tuple is the number of readings left in the stream.


def __init__(self, dict_obj: Union[None, Iterable[Tuple[Union[str, int], Any]], typing.Dict[Union[str, int], Any]]=None, *, value_spec: Optional[pg_typing.Dict]=None, onchange_callback: Optional[Callable[[typing.Dict[utils.KeyPath, base.FieldUpdate]], None]]=None, **kwargs):
    if value_spec and (not isinstance(value_spec, pg_typing.Dict)):
        raise TypeError(f"Argument 'value_spec' must be a `pg.typing.Dict` object. Encountered {value_spec}")
    allow_partial = kwargs.pop('allow_partial', False)
    accessor_writable = kwargs.pop('accessor_writable', True)
    sealed = kwargs.pop('sealed', False)
    root_path = kwargs.pop('root_path', None)
    pass_through = kwargs.pop('pass_through', False)
    self._set_raw_attr('_as_object_attributes_container', kwargs.pop('as_object_attributes_container', False))
    if isinstance(dict_obj, Dict):
        dict_obj = {k: v for k, v in dict_obj.sym_items()}
    elif dict_obj is not None:
        dict_obj = dict(dict_obj)
    base.Symbolic.__init__(self, allow_partial=allow_partial, accessor_writable=True, sealed=False, root_path=root_path)
    dict.__init__(self)
    self._value_spec = None
    self._onchange_callback = None
    dict_obj = dict_obj or {}
    for k, v in kwargs.items():
        dict_obj[k] = v
    if value_spec:
        if pass_through:
            for k, v in dict_obj.items():
                super().__setitem__(k, self._relocate_if_symbolic(k, v))
            self._value_spec = value_spec
        else:
            for k, v in dict_obj.items():
                super().__setitem__(k, self._formalized_value(k, None, v))
            self.use_value_spec(value_spec, allow_partial)
    else:
        for k, v in dict_obj.items():
            self._set_item_without_permission_check(k, v)
    self._onchange_callback = onchange_callback
    self.set_accessor_writable(accessor_writable)
    self.seal(sealed)

Constructor.

Args:
dict_obj: A dict as initial value for this Dict.
value_spec: Value spec that applies to this Dict.
onchange_callback: Callback when sub-tree has been modified.
**kwargs: Key value pairs that will be inserted into the dict as initial
value, which provides a syntax sugar for usage as below: d =
pg.Dict(a=1, b=2)


def transform_case(self, description, case_type):

        if case_type == CasingTypeEnum.Sentence:
            description = "{}{}".format(
                description[0].upper(),
                description[1:])
        elif case_type == CasingTypeEnum.Title:
            description = description.title()
        else:
            description = description.lower()
        return description

Transforms the case of the expression description, based on options
Args:
description: The description to transform
case_type: The casing type that controls the output casing
second_expression: Seconds part
Returns:
The transformed description with proper casing


def _error_and_gradient(self, x):
    coords = x.reshape((self.m, self.n))
    d = squareform(pdist(coords))
    diff = (self.D - d)
    error = self._error(diff)
    gradient = self._gradient(diff, d, coords)
    return (error, gradient.ravel())

Compute the error and the gradient.

This is the function optimized by :obj:`scipy.optimize.minimize`.

Args:
x (`array-like`): [`m` * `n`, ] matrix.

Returns:
`tuple`: containing:

- Error (`float`)
- Gradient (`np.array`) [`m`, `n`]


def ParseOptions(cls, options, analysis_plugin):

    if not isinstance(analysis_plugin, virustotal.VirusTotalAnalysisPlugin):
      raise errors.BadConfigObject(
          'Analysis plugin is not an instance of VirusTotalAnalysisPlugin')

    api_key = cls._ParseStringOption(options, 'virustotal_api_key')
    if not api_key:
      raise errors.BadConfigOption(
          'VirusTotal API key not specified. Try again with '
          '--virustotal-api-key.')

    analysis_plugin.SetAPIKey(api_key)

    enable_rate_limit = getattr(
        options, 'virustotal_free_rate_limit', cls._DEFAULT_RATE_LIMIT)
    if enable_rate_limit:
      analysis_plugin.EnableFreeAPIKeyRateLimit()

    lookup_hash = cls._ParseStringOption(
        options, 'virustotal_hash', default_value=cls._DEFAULT_HASH)
    analysis_plugin.SetLookupHash(lookup_hash)

    if not analysis_plugin.TestConnection():
      raise errors.BadConfigOption('Unable to connect to VirusTotal')

Parses and validates options.

Args:
options (argparse.Namespace): parser options.
analysis_plugin (VirusTotalAnalysisPlugin): analysis plugin to configure.

Raises:
BadConfigObject: when the output module object is of the wrong type.
BadConfigOption: when a configuration parameter fails validation or
when unable to connect to VirusTotal.


def read_string_array(self, key, embedded=True):
    data = None
    if (key is not None):
        key_type = self.variable_type(key)
        data = self.db.read(key.strip())
        if embedded:
            data = self.read_embedded(data, key_type)
        if (data is not None):
            try:
                data = json.loads(data, object_pairs_hook=OrderedDict)
            except ValueError as e:
                err = u'Failed loading JSON data ({}). Error: ({})'.format(data, e)
                self.tcex.log.error(err)
                self.tcex.message_tc(err)
                self.tcex.exit(1)
    else:
        self.tcex.log.warning(u'The key field was None.')
    return data

Read method of CRUD operation for string array data.

Args:
key (string): The variable to read from the DB.
embedded (boolean): Resolve embedded variables.

Returns:
(list): Results retrieved from DB.


def start(args_string):

  context = _get_context()
  try:
    import IPython
    import IPython.display
  except ImportError:
    IPython = None

  if context == _CONTEXT_NONE:
    handle = None
    print("Launching TensorBoard...")
  else:
    handle = IPython.display.display(
        IPython.display.Pretty("Launching TensorBoard..."),
        display_id=True,
    )

  def print_or_update(message):
    if handle is None:
      print(message)
    else:
      handle.update(IPython.display.Pretty(message))

  parsed_args = shlex.split(args_string, comments=True, posix=True)
  start_result = manager.start(parsed_args)

  if isinstance(start_result, manager.StartLaunched):
    _display(
        port=start_result.info.port,
        print_message=False,
        display_handle=handle,
    )

  elif isinstance(start_result, manager.StartReused):
    template = (
        "Reusing TensorBoard on port {port} (pid {pid}), started {delta} ago. "
        "(Use '!kill {pid}' to kill it.)"
    )
    message = template.format(
        port=start_result.info.port,
        pid=start_result.info.pid,
        delta=_time_delta_from_info(start_result.info),
    )
    print_or_update(message)
    _display(
        port=start_result.info.port,
        print_message=False,
        display_handle=None,
    )

  elif isinstance(start_result, manager.StartFailed):
    def format_stream(name, value):
      if value == "":
        return ""
      elif value is None:
        return "\n<could not read %s>" % name
      else:
        return "\nContents of %s:\n%s" % (name, value.strip())
    message = (
        "ERROR: Failed to launch TensorBoard (exited with %d).%s%s" %
        (
            start_result.exit_code,
            format_stream("stderr", start_result.stderr),
            format_stream("stdout", start_result.stdout),
        )
    )
    print_or_update(message)

  elif isinstance(start_result, manager.StartTimedOut):
    message = (
        "ERROR: Timed out waiting for TensorBoard to start. "
        "It may still be running as pid %d."
        % start_result.pid
    )
    print_or_update(message)

  else:
    raise TypeError(
        "Unexpected result from `manager.start`: %r.\n"
        "This is a TensorBoard bug; please report it."
        % start_result
    )

Launch and display a TensorBoard instance as if at the command line.

Args:
args_string: Command-line arguments to TensorBoard, to be
interpreted by `shlex.split`: e.g., "--logdir ./logs --port 0".
Shell metacharacters are not supported: e.g., "--logdir 2>&1" will
point the logdir at the literal directory named "2>&1".


def from_unknown_text(text, strict=False):

    if text.startswith("+"):
        crs = from_proj4(text, strict)

    elif text.startswith(("PROJCS[","GEOGCS[")):
        crs = from_unknown_wkt(text, strict)

    elif text.startswith("EPSG:"):
        crs = from_epsg_code(text.split(":")[1])

    elif text.startswith("ESRI:"):
        crs = from_esri_code(text.split(":")[1])

    elif text.startswith("SR-ORG:"):
        crs = from_sr_code(text.split(":")[1])

    else: raise FormatError("Could not auto-detect the type of crs format, make sure it is one of the supported formats")

    return crs

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

Arguments:

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

Returns:

- CRS object.


def toregex(text, exact=False):

    if isregex(text):
        return text

    escaped = re.escape(normalize_text(text))
    if exact:
        escaped = r"\A{}\Z".format(escaped)

    return re.compile(escaped)

Returns a compiled regular expression for the given text.

Args:
text (str | RegexObject): The text to match.
exact (bool, optional): Whether the generated regular expression should match exact
strings. Defaults to False.

Returns:
RegexObject: A compiled regular expression that will match the text.


def size(self, st_size):
    self._check_positive_int(st_size)
    current_size = (self.st_size or 0)
    self.filesystem.change_disk_usage((st_size - current_size), self.name, self.st_dev)
    if self._byte_contents:
        if (st_size < current_size):
            self._byte_contents = self._byte_contents[:st_size]
        elif IS_PY2:
            self._byte_contents = ('%s%s' % (self._byte_contents, ('\x00' * (st_size - current_size))))
        else:
            self._byte_contents += (b'\x00' * (st_size - current_size))
    self.st_size = st_size
    self.epoch += 1

Resizes file content, padding with nulls if new size exceeds the
old size.

Args:
st_size: The desired size for the file.

Raises:
IOError: if the st_size arg is not a non-negative integer
or if st_size exceeds the available file system space


def sg_any(tensor, opt):
    return tf.reduce_any(tensor, axis=opt.axis, keep_dims=opt.keep_dims, name=opt.name)

r"""Computes the "logical or" of elements across axis of a tensor.

See `tf.reduce_any()` in tensorflow.

Args:
tensor: A `Tensor` (automatically given by chain).
opt:
axis : A tuple/list of integers or an integer. The axis to reduce.
keep_dims: If true, retains reduced dimensions with length 1.
name: If provided, replace current tensor's name.

Returns:
A `Tensor`.


def serializable_list(olist, attrs_to_serialize=None, rels_to_expand=None, group_listrels_by=None, rels_to_serialize=None, key_modifications=None, groupby=None, keyvals_to_merge=None, preserve_order=False, dict_struct=None, dict_post_processors=None):
    if groupby:
        if preserve_order:
            result = json_encoder(deep_group(olist, keys=groupby, serializer='todict', preserve_order=preserve_order, serializer_kwargs={'rels_to_serialize': rels_to_serialize, 'rels_to_expand': rels_to_expand, 'attrs_to_serialize': attrs_to_serialize, 'group_listrels_by': group_listrels_by, 'key_modifications': key_modifications, 'dict_struct': dict_struct, 'dict_post_processors': dict_post_processors}))
        else:
            result = deep_group(olist, keys=groupby, serializer='todict', preserve_order=preserve_order, serializer_kwargs={'rels_to_serialize': rels_to_serialize, 'rels_to_expand': rels_to_expand, 'attrs_to_serialize': attrs_to_serialize, 'group_listrels_by': group_listrels_by, 'key_modifications': key_modifications, 'dict_struct': dict_struct, 'dict_post_processors': dict_post_processors})
        return result
    else:
        result_list = map((lambda o: serialized_obj(o, attrs_to_serialize=attrs_to_serialize, rels_to_expand=rels_to_expand, group_listrels_by=group_listrels_by, rels_to_serialize=rels_to_serialize, key_modifications=key_modifications, dict_struct=dict_struct, dict_post_processors=dict_post_processors)), olist)
        if keyvals_to_merge:
            result_list = [merge(obj_dict, kvdict) for (obj_dict, kvdict) in zip(result_list, keyvals_to_merge)]
        return result_list

Converts a list of model instances to a list of dictionaries
using their `todict` method.

Args:
olist (list): The list of instances to convert
attrs_to_serialize (list, optional): To be passed as an argument
to the `todict` method
rels_to_expand (list, optional): To be passed as an argument
to the `todict` method
group_listrels_by (dict, optional): To be passed as an argument
to the `todict` method
rels_to_serialize (list, optional): To be passed as an argument
to the `todict` method
key_modifications (dict, optional): To be passed as an argument
to the `todict` method

groupby (list, optional): An optional list of keys based on which
the result list will be hierarchially grouped ( and converted
into a dict)

keyvals_to_merge (list of dicts, optional): A list of parameters
to be merged with each dict of the output list


def __init__(self, group_id=Group.OFPG_ALL):

        super().__init__()
        self.group_id = group_id

Create a GroupStatsRequest with the optional parameters below.

Args:
group_id(int): ID of group to read. OFPG_ALL to request informatio
for all groups.


def add_updates(self, messages: Iterable[CachedMessage], expunged: Iterable[int]) -> None:
    self._messages._update(messages)
    self._messages._remove(expunged, self._hide_expunged)
    if (not self._hide_expunged):
        self._session_flags.remove(expunged)

Update the messages in the selected mailboxes. The ``messages``
should include non-expunged messages in the mailbox that should be
checked for updates. The ``expunged`` argument is the set of UIDs that
have been expunged from the mailbox.

In an optimized implementation, ``messages`` only includes new messages
or messages with metadata updates.  This minimizes the comparison
needed to determine what untagged responses are necessary. The
:attr:`.mod_sequence` attribute may be used to support this
optimization.

If a backend implementation lacks the ability to determine the subset
of messages that have been updated, it should instead use
:meth:`.set_messages`.

Args:
messages: The cached message objects to add.
expunged: The set of message UIDs that have been expunged.


def get_ocv(self, cycles=None, direction='up', remove_first=False, interpolated=False, dx=None, number_of_points=None):
    if (cycles is None):
        cycles = self.get_cycle_numbers()
    elif (not isinstance(cycles, (list, tuple))):
        cycles = [cycles]
    else:
        remove_first = False
    ocv_rlx_id = 'ocvrlx'
    if (direction == 'up'):
        ocv_rlx_id += '_up'
    elif (direction == 'down'):
        ocv_rlx_id += '_down'
    step_table = self.dataset.step_table
    dfdata = self.dataset.dfdata
    ocv_steps = step_table.loc[(step_table['cycle'].isin(cycles), :)]
    ocv_steps = ocv_steps.loc[(ocv_steps.type.str.startswith(ocv_rlx_id), :)]
    if remove_first:
        ocv_steps = ocv_steps.iloc[(1:, :)]
    step_time_label = self.headers_normal.step_time_txt
    voltage_label = self.headers_normal.voltage_txt
    cycle_label = self.headers_normal.cycle_index_txt
    step_label = self.headers_normal.step_index_txt
    selected_df = dfdata.where((dfdata[cycle_label].isin(ocv_steps.cycle) & dfdata[step_label].isin(ocv_steps.step))).dropna()
    selected_df = selected_df.loc[(:, [cycle_label, step_label, step_time_label, voltage_label])]
    if interpolated:
        if ((dx is None) and (number_of_points is None)):
            dx = prms.Reader.time_interpolation_step
        new_dfs = list()
        groupby_list = [cycle_label, step_label]
        for (name, group) in selected_df.groupby(groupby_list):
            new_group = _interpolate_df_col(group, x=step_time_label, y=voltage_label, dx=dx, number_of_points=number_of_points)
            for (i, j) in zip(groupby_list, name):
                new_group[i] = j
            new_dfs.append(new_group)
        selected_df = pd.concat(new_dfs)
    return selected_df

get the open curcuit voltage relaxation curves.

Args:
cycles (list of ints or None): the cycles to extract from
(selects all if not given).
direction ("up", "down", or "both"): extract only relaxations that
is performed during discharge for "up" (because then the
voltage relaxes upwards) etc.
remove_first: remove the first relaxation curve (typically,
the first curve is from the initial rest period between
assembling the cell to the actual testing/cycling starts)
interpolated (bool): set to True if you want the data to be
interpolated (e.g. for creating smaller files)
dx (float): the step used when interpolating.
number_of_points (int): number of points to use (over-rides dx)
for interpolation (i.e. the length of the interpolated data).

Returns:
A pandas.DataFrame with cycle-number, step-number, step-time, and
voltage columns.


def _FloatingPointEncoder(wire_type, format):

  value_size = struct.calcsize(format)
  if value_size == 4:
    def EncodeNonFiniteOrRaise(write, value):

      if value == _POS_INF:
        write(b'\x00\x00\x80\x7F')
      elif value == _NEG_INF:
        write(b'\x00\x00\x80\xFF')
      elif value != value:
        write(b'\x00\x00\xC0\x7F')
      else:
        raise
  elif value_size == 8:
    def EncodeNonFiniteOrRaise(write, value):
      if value == _POS_INF:
        write(b'\x00\x00\x00\x00\x00\x00\xF0\x7F')
      elif value == _NEG_INF:
        write(b'\x00\x00\x00\x00\x00\x00\xF0\xFF')
      elif value != value:
        write(b'\x00\x00\x00\x00\x00\x00\xF8\x7F')
      else:
        raise
  else:
    raise ValueError('Can\'t encode floating-point values that are '
                     '%d bytes long (only 4 or 8)' % value_size)

  def SpecificEncoder(field_number, is_repeated, is_packed):
    local_struct_pack = struct.pack
    if is_packed:
      tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
      local_EncodeVarint = _EncodeVarint
      def EncodePackedField(write, value):
        write(tag_bytes)
        local_EncodeVarint(write, len(value) * value_size)
        for element in value:

          try:
            write(local_struct_pack(format, element))
          except SystemError:
            EncodeNonFiniteOrRaise(write, element)
      return EncodePackedField
    elif is_repeated:
      tag_bytes = TagBytes(field_number, wire_type)
      def EncodeRepeatedField(write, value):
        for element in value:
          write(tag_bytes)
          try:
            write(local_struct_pack(format, element))
          except SystemError:
            EncodeNonFiniteOrRaise(write, element)
      return EncodeRepeatedField
    else:
      tag_bytes = TagBytes(field_number, wire_type)
      def EncodeField(write, value):
        write(tag_bytes)
        try:
          write(local_struct_pack(format, value))
        except SystemError:
          EncodeNonFiniteOrRaise(write, value)
      return EncodeField

  return SpecificEncoder

Return a constructor for an encoder for float fields.

This is like StructPackEncoder, but catches errors that may be due to
passing non-finite floating-point values to struct.pack, and makes a
second attempt to encode those values.

Args:
wire_type:  The field's wire type, for encoding tags.
format:  The format string to pass to struct.pack().


def _from_nested_row_partitions(cls, flat_values, nested_row_partitions, name=None, validate=True):
    if not isinstance(validate, bool):
        raise TypeError(f'Argument `validate` must have type bool. Received {validate}.')
    if isinstance(nested_row_partitions, RowPartition):
        raise TypeError(f'Argument `nested_row_partitions` must be a list of RowPartitions. Received {nested_row_partitions}.')
    if isinstance(nested_row_partitions, tensor_lib.Tensor):
        raise TypeError(f'Argument `nested_row_partitions` must be a list of RowPartitions. Received {nested_row_partitions}.')
    with ops.name_scope(name, 'RaggedFromNestedRowPartitions', [flat_values] + list(nested_row_partitions)):
        result = flat_values
        for partition in reversed(nested_row_partitions):
            result = cls._from_row_partition(result, partition, validate=validate)
        return result

Creates a `RaggedTensor` from a nested list of row partitions.

Equivalent to:

```python
result = flat_values
for row_partition in reversed(nested_row_partitions):
result = _from_row_partition(result, row_partition)
```

Args:
flat_values: A potentially ragged tensor.
nested_row_partitions: A list of row partitions.  The `i`th element is
used as the row partition for the `i`th ragged dimension.
name: A name prefix for the RaggedTensor (optional).
validate: If true, then use assertions to check that the arguments form
a valid `RaggedTensor`.  Note: these assertions incur a runtime cost,
since they must be checked for each tensor value.

Returns:
A `RaggedTensor` (or `flat_values` if `nested_row_lengths` is empty).


def put(self, type: Type[T], item: T) -> None:
    LOGGER.info('Getting SinkHandlers for "{type}"'.format(type=type.__name__))
    try:
        handlers = self._put_types[type]
    except KeyError:
        try:
            LOGGER.info('Building new SinkHandlers for "{type}"'.format(type=type.__name__))
            handlers = self._put_handlers(type)
        except NoConversionError:
            handlers = None
        self._get_types[type] = handlers
    LOGGER.info('Creating new PipelineContext')
    context = self._new_context()
    LOGGER.info('Sending item "{item}" to SourceHandlers'.format(item=item))
    if (handlers is not None):
        for handler in handlers:
            handler.put(item, context)

Puts an objects into the data pipeline. The object may be transformed into a new type for insertion if necessary.

Args:
item: The object to be inserted into the data pipeline.


def write_dot(g):

    lines = ["digraph g {"]

    def attrs_txt(items):
        if items:
            txt = ", ".join(('%s="%s"' % (k, str(v).strip('"')))
                            for k, v in items)
            return '[' + txt + ']'
        else:
            return ''

    for node in g.nodes():
        atxt = attrs_txt(g.node_attributes(node))
        txt = "%s %s;" % (node, atxt)
        lines.append(txt)

    for e in g.edges():
        edge_from, edge_to = e
        attrs = g.edge_attributes(e)

        label = str(g.edge_label(e))
        if label:
            attrs.append(("label", label))

        atxt = attrs_txt(attrs)
        txt = "%s -> %s %s;" % (edge_from, edge_to, atxt)
        lines.append(txt)

    lines.append("}")
    return '\n'.join(lines)

Replacement for pygraph.readwrite.dot.write, which is dog slow.

Note:
This isn't a general replacement. It will work for the graphs that
Rez generates, but there are no guarantees beyond that.

Args:
g (`pygraph.digraph`): Input graph.

Returns:
str: Graph in dot format.


def master(self, task_type=None, task_id=None, rpc_layer=None):
    raise NotImplementedError()

Retrieves the name or URL of the session master.

Note: this is only useful for TensorFlow 1.x.

Args:
task_type: (Optional) The type of the TensorFlow task of the master.
task_id: (Optional) The index of the TensorFlow task of the master.
rpc_layer: (Optional) The RPC protocol for the given cluster.

Returns:
The name or URL of the session master.

Implementors of this function must take care in ensuring that the master
returned is up-to-date at the time to calling this function. This usually
means retrieving the master every time this function is invoked.


def open(self, path, mime_type='application/octet-stream', compression_type=CompressionTypes.AUTO) -> BinaryIO:
    raise NotImplementedError

Returns a read channel for the given file path.

Args:
path: string path of the file object to be read
mime_type: MIME type to specify the type of content in the file object
compression_type: Type of compression to be used for this object

Returns: file handle with a close function for the user to use


def kvlist_str(kvlist: List[Tuple[str, Any, Any]], compact: bool=True, verbose: bool=False, root_indent: int=0, *, label: Optional[str]=None, bracket_type: BracketType=BracketType.ROUND, custom_format: Optional[CustomFormatFn]=None, memo: Optional[Set[int]]=None, **kwargs) -> str:
    s = io.StringIO()
    is_first = True
    bracket_start, bracket_end = bracket_chars(bracket_type)
    child_indent = root_indent + 1 if label else root_indent
    body = io.StringIO()
    for k, v, d in kvlist:
        if isinstance(d, tuple):
            include_pair = True
            for sd in d:
                if sd == v:
                    include_pair = False
                    break
        else:
            include_pair = v != d
        if include_pair:
            if not is_first:
                body.write(',')
                body.write(' ' if compact else '\n')
            v = format(v, compact=compact, verbose=verbose, root_indent=child_indent, custom_format=custom_format, memo=memo, **kwargs)
            if not compact:
                body.write(_indent('', child_indent))
            if k:
                body.write(f'{k}={str_ext(v, custom_format, child_indent)}')
            else:
                body.write(str_ext(v, custom_format, child_indent))
            is_first = False
    if label and (not is_first) and (not compact):
        body.write('\n')
    body = body.getvalue()
    if label is None:
        return body
    else:
        s.write(label)
        s.write(bracket_start)
        if body:
            if not compact:
                s.write('\n')
            s.write(body)
            if not compact:
                s.write(_indent('', root_indent))
        s.write(bracket_end)
        return s.getvalue()

Formats a list key/value pairs into a comma delimited string.

Args:
kvlist: List of tuples in format of
(key, value, default_value or a tuple of default values)
compact: If True, format value in kvlist in compact form.
verbose: If True, format value in kvlist in verbose.
root_indent: The indent should be applied for values in kvlist if they are
multi-line.
label: (Optional) If not None, add label to brace all kv pairs.
bracket_type: Bracket type used for embracing the kv pairs. Applicable only
when `name` is not None.
custom_format: An optional custom format function, which will be applied to
each value (and child values) in kvlist. If the function returns None, it
will fall back to the default `pg.format`.
memo: A set of object ids that have been formatted. Used to avoid
infinite recursion in the formatting process.
**kwargs: Keyword arguments that will be passed through unto child
``Formattable`` objects.
Returns:
A formatted string from a list of key/value pairs delimited by comma.


async def listen(self, url, **opts):

        info = s_urlhelp.chopurl(url, **opts)
        info.update(opts)

        scheme = info.get('scheme')

        if scheme == 'unix':
            path = info.get('path')
            try:
                server = await s_link.unixlisten(path, self._onLinkInit)
            except Exception as e:
                if 'path too long' in str(e):
                    logger.error(f'unix:
                raise

        else:

            host = info.get('host')
            port = info.get('port')

            sslctx = None
            if scheme == 'ssl':
                sslctx = self.certdir.getServerSSLContext(hostname=host)

            server = await s_link.listen(host, port, self._onLinkInit, ssl=sslctx)

        self.listenservers.append(server)
        ret = server.sockets[0].getsockname()

        if self.addr is None:
            self.addr = ret

        return ret

Bind and listen on the given host/port with possible SSL.

Args:
host (str): A hostname or IP address.
port (int): The TCP port to bind.


def __init__(self, name=None, settings=None,
                 log_function = None, data_path = None):

        Script.__init__(self, name, settings, log_function= log_function, data_path = data_path)

Example of a script
Args:
name (optional): name of script, if empty same as class name
settings (optional): settings for this script, if empty same as default settings


def _PrintEventsStatus(self, events_status):

    if events_status:
      table_view = views.CLITabularTableView(
          column_names=['Events:', 'Filtered', 'In time slice', 'Duplicates',
                        'MACB grouped', 'Total'],
          column_sizes=[15, 15, 15, 15, 15, 0])

      table_view.AddRow([
          '', events_status.number_of_filtered_events,
          events_status.number_of_events_from_time_slice,
          events_status.number_of_duplicate_events,
          events_status.number_of_macb_grouped_events,
          events_status.total_number_of_events])

      self._output_writer.Write('\n')
      table_view.Write(self._output_writer)

Prints the status of the events.

Args:
events_status (EventsStatus): events status.


def create_sonos_playlist(self, title):
    response = self.avTransport.CreateSavedQueue([('InstanceID', 0), ('Title', title), ('EnqueuedURI', ''), ('EnqueuedURIMetaData', '')])
    item_id = response['AssignedObjectID']
    obj_id = item_id.split(':', 2)[1]
    uri = 'file:
    res = [DidlResource(uri=uri, protocol_info='x-rincon-playlist:*:*:*')]
    return DidlPlaylistContainer(resources=res, title=title, parent_id='SQ:', item_id=item_id)

Create a new empty Sonos playlist.

Args:
title: Name of the playlist

:rtype: :py:class:`~.soco.data_structures.DidlPlaylistContainer`


def get_entities(seq, suffix=False):

    if any(isinstance(s, list) for s in seq):
        seq = [item for sublist in seq for item in sublist + ['O']]

    prev_tag = 'O'
    prev_type = ''
    begin_offset = 0
    chunks = []
    for i, chunk in enumerate(seq + ['O']):
        if suffix:
            tag = chunk[-1]
            type_ = chunk.split('-')[0]
        else:
            tag = chunk[0]
            type_ = chunk.split('-')[-1]

        if end_of_chunk(prev_tag, tag, prev_type, type_):
            chunks.append((prev_type, begin_offset, i-1))
        if start_of_chunk(prev_tag, tag, prev_type, type_):
            begin_offset = i
        prev_tag = tag
        prev_type = type_

    return chunks

Gets entities from sequence.

Args:
seq (list): sequence of labels.

Returns:
list: list of (chunk_type, chunk_start, chunk_end).

Example:
>>> from seqeval.metrics.sequence_labeling import get_entities
>>> seq = ['B-PER', 'I-PER', 'O', 'B-LOC']
>>> get_entities(seq)
[('PER', 0, 1), ('LOC', 3, 3)]


def _on_report(self, sequence, topic, message):
    try:
        conn_key = self._find_connection(topic)
        conn_id = self.conns.get_connection_id(conn_key)
    except ArgumentError:
        self._logger.warn('Dropping report message that does not correspond with a known connection, topic=%s', topic)
        return
    try:
        rep_msg = messages.ReportNotification.verify(message)
        serialized_report = {}
        serialized_report['report_format'] = rep_msg['report_format']
        serialized_report['encoded_report'] = rep_msg['report']
        serialized_report['received_time'] = datetime.datetime.strptime(rep_msg['received_time'].encode().decode(), '%Y%m%dT%H:%M:%S.%fZ')
        report = self.report_parser.deserialize_report(serialized_report)
        self._trigger_callback('on_report', conn_id, report)
    except Exception:
        self._logger.exception('Error processing report conn_id=%d', conn_id)

Process a report received from a device.

Args:
sequence (int): The sequence number of the packet received
topic (string): The topic this message was received on
message (dict): The message itself


def with_random_weights(cls, options):

        return cls([(value, random.randint(1, len(options)))
                    for value in options])

Initialize from a list of options with random weights.

The weights assigned to each object are uniformally random
integers between ``1`` and ``len(options)``

Args:
options (list): The list of options of any type this object
can return with the ``get()`` method.

Returns:
SoftOptions: A newly constructed instance


def start_prompt(self, message, text_input=False, cli_color=''):
    with self._cond:
        if self._prompt:
            raise MultiplePromptsError
        prompt_id = uuid.uuid4().hex
        _LOG.debug('Displaying prompt (%s): "%s"%s', prompt_id, message, (', Expects text input.' if text_input else ''))
        self._response = None
        self._prompt = Prompt(id=prompt_id, message=message, text_input=text_input)
        if sys.stdin.isatty():
            self._console_prompt = ConsolePrompt(message, functools.partial(self.respond, prompt_id), cli_color)
            self._console_prompt.start()
        self.notify_update()
        return prompt_id

Display a prompt.

Args:
message: A string to be presented to the user.
text_input: A boolean indicating whether the user must respond with text.
cli_color: An ANSI color code, or the empty string.

Raises:
MultiplePromptsError: There was already an existing prompt.

Returns:
A string uniquely identifying the prompt.


def _GetSerializedAttributeContainerList(self, container_type):
    container_list = self._serialized_attribute_containers.get(container_type, None)
    if (not container_list):
        container_list = SerializedAttributeContainerList()
        self._serialized_attribute_containers[container_type] = container_list
    return container_list

Retrieves a serialized attribute container list.

Args:
container_type (str): attribute container type.

Returns:
SerializedAttributeContainerList: serialized attribute container list.


def set_block_entity_data(self, pos_or_x, y=None, z=None, data=None):
    if (None not in (y, z)):
        pos_or_x = (pos_or_x, y, z)
    coord_tuple = tuple((int(floor(c)) for c in pos_or_x))
    old_data = self.block_entities.get(coord_tuple, None)
    self.block_entities[coord_tuple] = data
    return old_data

Update block entity data.

Returns:
Old data if block entity data was already stored for that location,
None otherwise.


def touch(self, edited=False):
    self._dirty = True
    dt = datetime.datetime.utcnow()
    self.timestamps.updated = dt
    if edited:
        self.timestamps.edited = dt

Mark the node as dirty.

Args:
edited (bool): Whether to set the edited time.


def is_truthy(value, default=False):
    if (value is None):
        return False
    if isinstance(value, bool):
        return value
    if isinstance(value, int):
        return (value > 0)
    trues = ('1', 'true', 'y', 'yes', 'ok')
    falses = ('', '0', 'false', 'n', 'none', 'no')
    if (value.lower().strip() in falses):
        return False
    elif (value.lower().strip() in trues):
        return True
    elif default:
        return default
    else:
        raise ValueError('Invalid argument given to truthy: {0}'.format(value))

Evaluate a value for truthiness

>>> is_truthy('Yes')
True
>>> is_truthy('False')
False
>>> is_truthy(1)
True

Args:
value (Any): Value to evaluate
default (bool): Optional default value, if the input does not match the true or false values

Returns:
True if a truthy value is passed, else False


def __init__(self, resolver_context):

    super(CompressedStreamFileSystem, self).__init__(resolver_context)
    self._compression_method = None

Initializes a compressed stream file system.

Args:
resolver_context (Context): a resolver context.


def __init__(self, connection, request_key):

        self._connection = connection
        self._request_key = '{}:{}'.format(SIGNAL_REDIS_PREFIX, request_key)

Initialises the signal server.

Args:
connection: Reference to a signal connection object.
request_key (str): The key under which the list of requests is stored.


def take_snapshot(self, snapshot_name, return_dict=True, power_off=False):

        if power_off is True and self.status != "off":
            action = self.power_off(return_dict=False)
            action.wait()
            self.load()

        return self._perform_action(
            {"type": "snapshot", "name": snapshot_name},
            return_dict
        )

Take a snapshot!

Args:
snapshot_name (str): name of snapshot

Optional Args:
return_dict (bool): Return a dict when True (default),
otherwise return an Action.
power_off (bool): Before taking the snapshot the droplet will be
turned off with another API call. It will wait until the
droplet will be powered off.

Returns dict or Action


def __init__(self, elements: Sequence[Union[DataSource, DataSink]], transformers: Iterable[DataTransformer] = None) -> None:

        if not elements:
            raise ValueError("Elements must be a non-empty sequence of DataSources and DataSinks")

        if transformers is None:
            transformers = set()

        sources = set()
        sinks = set()
        targets = []
        for element in elements:
            if isinstance(element, DataSource):
                sources.add(element)
                targets.append((element, set(sinks)))

            if isinstance(element, DataSink):
                sinks.add(element)

        LOGGER.info("Beginning construction of type graph")

        self._type_graph = _build_type_graph(sources, sinks, transformers)
        LOGGER.info("Completed construction of type graph")
        self._sources = targets
        self._sinks = sinks
        self._get_types = {}
        self._put_types = {}

Initializes a data pipeline.

Args:
elements: The data stores and data sinks for this pipeline.
transformers: The data transformers for this pipeline.


def save(self, projects):
    base_path = os.path.expanduser(self.path)
    if (not os.path.isdir(base_path)):
        return
    logger.debug('Save projects config to %s', base_path)
    for (name, data) in list(projects.items()):
        project_file_path = self.get_project_config_path(name)
        with open(project_file_path, 'w') as f:
            yaml.dump(data, stream=f, default_flow_style=False)
            logger.debug("Project '%s' config has been writed to '%s'", name, project_file_path)

Save the projects configs to local path

Args:
projects (dict): project_name -> project_data


def send_email_message(self, recipient, subject, html_message, text_message, sender_email, sender_name):

        if not current_app.testing:
            try:

                from sendgrid.helpers.mail import Email, Content, Substitution, Mail
                from_email = Email(sender_email, sender_name)
                to_email = Email(recipient)
                text_content = Content('text/plain', text_message)
                html_content = Content('text/html', html_message)

                mail = Mail(from_email, subject, to_email, text_content)
                mail.add_content(html_content)

                response = self.sg.client.mail.send.post(request_body=mail.get())
                print(response.status_code)
                print(response.body)
                print(response.headers)
            except ImportError:
                raise ConfigError(SENDGRID_IMPORT_ERROR_MESSAGE)
            except Exception as e:
                print(e)
                print(e.body)
                raise

Send email message via sendgrid-python.

Args:
recipient: Email address or tuple of (Name, Email-address).
subject: Subject line.
html_message: The message body in HTML.
text_message: The message body in plain text.


def yiq_to_rgb(images):
    images = ops.convert_to_tensor(images, name='images')
    kernel = ops.convert_to_tensor(_yiq_to_rgb_kernel, dtype=images.dtype, name='kernel')
    ndims = images.get_shape().ndims
    return math_ops.tensordot(images, kernel, axes=[[ndims - 1], [0]])

Converts one or more images from YIQ to RGB.

Outputs a tensor of the same shape as the `images` tensor, containing the RGB
value of the pixels.
The output is only well defined if the Y value in images are in [0,1],
I value are in [-0.5957,0.5957] and Q value are in [-0.5226,0.5226].

Args:
images: 2-D or higher rank. Image data to convert. Last dimension must be
size 3.

Returns:
images: tensor with the same shape as `images`.


def master_job(master, cluster_def):
    if master in _LOCAL_MASTERS:
        return None
    if not cluster_def or not cluster_def.job:
        return _DEFAULT_JOB_NAME
    job_names = set((job.name for job in cluster_def.job))
    if _DEFAULT_JOB_NAME in job_names:
        raise ValueError('Currently, tpu_worker is not an allowed job name.')
    if len(job_names) == 1:
        return cluster_def.job[0].name
    if len(job_names) == 2:
        if _DEFAULT_COORDINATOR_JOB_NAME in job_names:
            job_names.remove(_DEFAULT_COORDINATOR_JOB_NAME)
            return job_names.pop()
    raise ValueError('Could not infer TPU job name.')

Returns the canonical job name to use to place TPU computations on.

Args:
master: A `string` representing the TensorFlow master to use.
cluster_def: A ClusterDef object describing the TPU cluster.

Returns:
A string containing the job name, or None if no job should be specified.

Raises:
ValueError: If the user needs to specify a tpu_job_name, because we are
unable to infer the job name automatically, or if the user-specified job
names are inappropriate.


def save(filename, numpy_data):
    png_filename = os.path.expanduser(filename)
    if (type(numpy_data) is str):
        fp = open(png_filename, 'wb')
        fp.write(numpy_data)
        fp.close()
        return png_filename
    try:
        if (numpy_data.dtype.name != 'uint8'):
            m = 'I'
            img = Image.fromarray(numpy_data, mode=m)
        else:
            img = Image.fromarray(numpy_data)
        img.save(png_filename)
    except Exception as e:
        raise ValueError('Could not save png file {0}.'.format(png_filename))
    return png_filename

Export a numpy array to a png file.

Arguments:
filename (str): A filename to which to save the png data
numpy_data (numpy.ndarray OR str): The numpy array to save to png.
OR a string: If a string is provded, it should be a binary png str

Returns:
str. The expanded filename that now holds the png data

Raises:
ValueError: If the save fails; for instance if the binary string data
cannot be coerced into a png, or perhaps your numpy.ndarray is
ill-formed?


def plot_tcoords(array, coords, scantypes=None, ax=None, **kwargs):
    if (ax is None):
        ax = plt.gca()
    if (scantypes is None):
        ax.plot(array[coords[0]], array[coords[1]], label='ALL', **kwargs)
    else:
        for scantype in scantypes:
            ax.plot(array[coords[0]][(array.scantype == scantype)], array[coords[1]][(array.scantype == scantype)], label=scantype, **kwargs)
    ax.set_xlabel(coords[0])
    ax.set_ylabel(coords[1])
    ax.set_title('{} vs {}'.format(coords[1], coords[0]))
    ax.legend()
    logger.info('{} vs {} has been plotted.'.format(coords[1], coords[0]))

Plot coordinates related to the time axis.

Args:
array (xarray.DataArray): Array which the coodinate information is included.
coords (list): Name of x axis and y axis.
scantypes (list): Scantypes. If None, all scantypes are used.
ax (matplotlib.axes): Axis you want to plot on.
kwargs (optional): Plot options passed to ax.plot().


def _get_graph(while_op, func_attr_name, attr_graph_name):
    func_graph = getattr(while_op, attr_graph_name, None)
    if func_graph is None:
        input_shapes = [tensor_shape.TensorShape(s) for s in while_op.get_attr('output_shapes')]
        func_name = while_op.get_attr(func_attr_name).name
        func_graph = util.get_func_graph(while_op, input_shapes, func_name)
    func_graph._while = while_op
    return func_graph

Returns `FuncGraph` for the given function attribute.

Args:
while_op: The While Operation.
func_attr_name: string
attr_graph_name: cached forward graph name

Returns:
`FuncGraph`


def fts_intersection(self, segs):
    fts_vecs = [self.fts(s) for s in self.filter_segs(segs)]
    return reduce((lambda a, b: (a & b)), fts_vecs)

Return the features shared by `segs`

Args:
segs (list): list of Unicode IPA segments

Returns:
set: set of (value, feature) tuples shared by the valid segments in
`segs`


def replace(self, key, value, expire=0, noreply=None):
    if (noreply is None):
        noreply = self.default_noreply
    return self._store_cmd(b'replace', {key: value}, expire, noreply)[key]

The memcached "replace" command.

Args:
key: str, see class docs for details.
value: str, see class docs for details.
expire: optional int, number of seconds until the item is expired
from the cache, or zero for no expiry (the default).
noreply: optional bool, True to not wait for the reply (defaults to
self.default_noreply).

Returns:
If noreply is True, always returns True. Otherwise returns True if
the value was stored and False if it wasn't (because the key didn't
already exist).


def parse_response(fields, records):
    data = [i['values']['data'] for i in records]
    return [{fields[idx]: row for (idx, row) in enumerate(d)} for d in data]

Parse an API response into usable objects.

Args:
fields (list[str]): List of strings indicating the fields that
are represented in the records, in the order presented in
the records.::

[
'number1',
'number2',
'number3',
'first_name',
'last_name',
'company',
'street',
'city',
'state',
'zip',
]

records (list[dict]): A really crappy data structure representing
records as returned by Five9::

[
{
'values': {
'data': [
'8881234567',
None,
None,
'Dave',
'Lasley',
'LasLabs Inc',
None,
'Las Vegas',
'NV',
'89123',
]
}
}
]

Returns:
list[dict]: List of parsed records.


def DrainTaskSchedulerQueueForClient(self, client, max_count=None):
    if (max_count is None):
        max_count = self.max_queue_size
    if (max_count <= 0):
        return []
    client = rdf_client.ClientURN(client)
    start_time = time.time()
    if data_store.RelationalDBEnabled():
        action_requests = data_store.REL_DB.LeaseClientActionRequests(client.Basename(), lease_time=rdfvalue.Duration.FromSeconds(self.message_expiry_time), limit=max_count)
        result = [rdf_flow_objects.GRRMessageFromClientActionRequest(r) for r in action_requests]
    else:
        new_tasks = queue_manager.QueueManager(token=self.token).QueryAndOwn(queue=client.Queue(), limit=max_count, lease_seconds=self.message_expiry_time)
        initial_ttl = rdf_flows.GrrMessage().task_ttl
        check_before_sending = []
        result = []
        for task in new_tasks:
            if (task.task_ttl < (initial_ttl - 1)):
                check_before_sending.append(task)
            else:
                result.append(task)
        if check_before_sending:
            with queue_manager.QueueManager(token=self.token) as manager:
                status_found = manager.MultiCheckStatus(check_before_sending)
                for task in check_before_sending:
                    if (task not in status_found):
                        result.append(task)
                    else:
                        manager.DeQueueClientRequest(task)
    stats_collector_instance.Get().IncrementCounter('grr_messages_sent', len(result))
    if result:
        logging.debug('Drained %d messages for %s in %s seconds.', len(result), client, (time.time() - start_time))
    return result

Drains the client's Task Scheduler queue.

1) Get all messages in the client queue.
2) Sort these into a set of session_ids.
3) Use data_store.DB.ResolvePrefix() to query all requests.
4) Delete all responses for retransmitted messages (if needed).

Args:
client: The ClientURN object specifying this client.
max_count: The maximum number of messages we will issue for the client.
If not given, uses self.max_queue_size .

Returns:
The tasks respresenting the messages returned. If we can not send them,
we can reschedule them for later.


def get(cls, resource_id):
    res = Resource.get(resource_id)
    return (cls(res) if res else None)

Returns the class object identified by `resource_id`

Args:
resource_id (str): Unique EC2 Instance ID to load from database

Returns:
EC2 Instance object if found, else None


def insert(self, index, item):

        if issubclass(item.__class__, self._pyof_class):
            list.insert(self, index, item)
        else:
            raise exceptions.WrongListItemType(item.__class__.__name__,
                                               self._pyof_class.__name__)

Insert an item at the specified index.

Args:
index (int): Position to insert the item.
item: Item to be inserted. It must have the type specified in the
constructor.

Raises:
:exc:`~.exceptions.WrongListItemType`: If the item has a different
type than the one specified in the constructor.


def delete(self, query_id=None, **kwargs):
    path = '/logging-service/v1/queries/{}'.format(query_id)
    r = self._httpclient.request(method='DELETE', url=self.url, path=path, **kwargs)
    return r

Delete a query job.

Uses the DELETE HTTP method to delete a query job. After calling
this endpoint, it is an error to poll for query results using
the queryId specified here.

Args:
query_id (str): Specifies the ID of the query job.
**kwargs: Supported :meth:`~pancloud.httpclient.HTTPClient.request` parameters.

Returns:
requests.Response: Requests Response() object.

Examples:
Refer to ``logging_query.py`` example.


def list_and_add(a, b):
    if (not isinstance(b, list)):
        b = [b]
    if (not isinstance(a, list)):
        a = [a]
    return (a + b)

Concatenate anything into a list.

Args:
a: the first thing
b: the second thing

Returns:
list. All the things in a list.


def __eq__(self, other):

        if type(self) is type(other) and \
                self._duration == other._duration and \
                self._name == other._name:
            return True
        return False

Two Commands are the same if they are of the same type
and have the same duration and name.

Args:
other (Command): other Command.

Returns:
bool: are self and other equal.


def add_implem(self, transition, attribute, function, **kwargs):

        implem = ImplementationProperty(
            field_name=self.state_field,
            transition=transition,
            workflow=self.workflow,
            implementation=function,
            **kwargs)
        self.implementations[transition.name] = implem
        self.transitions_at[transition.name] = attribute
        return implem

Add an implementation.

Args:
transition (Transition): the transition for which the implementation
is added
attribute (str): the name of the attribute where the implementation
will be available
function (callable): the actual implementation function
**kwargs: extra arguments for the related ImplementationProperty.


def RemoveFromQueue(self, addr):

        if addr in self.connection_queue:
            self.connection_queue.remove(addr)

Remove an address from the connection queue
Args:
addr:

Returns:


def text_wrap(text, length=None, indent='', firstline_indent=None):
    if (length is None):
        length = get_help_width()
    if (indent is None):
        indent = ''
    if (firstline_indent is None):
        firstline_indent = indent
    if (len(indent) >= length):
        raise ValueError('Length of indent exceeds length')
    if (len(firstline_indent) >= length):
        raise ValueError('Length of first line indent exceeds length')
    text = text.expandtabs(4)
    result = []
    wrapper = textwrap.TextWrapper(width=length, initial_indent=firstline_indent, subsequent_indent=indent)
    subsequent_wrapper = textwrap.TextWrapper(width=length, initial_indent=indent, subsequent_indent=indent)
    for paragraph in (p.strip() for p in text.splitlines()):
        if paragraph:
            result.extend(wrapper.wrap(paragraph))
        else:
            result.append('')
        wrapper = subsequent_wrapper
    return '\n'.join(result)

Wraps a given text to a maximum line length and returns it.

It turns lines that only contain whitespace into empty lines, keeps new lines,
and expands tabs using 4 spaces.

Args:
text: str, text to wrap.
length: int, maximum length of a line, includes indentation.
If this is None then use get_help_width()
indent: str, indent for all but first line.
firstline_indent: str, indent for first line; if None, fall back to indent.

Returns:
str, the wrapped text.

Raises:
ValueError: Raised if indent or firstline_indent not shorter than length.


def SplitIntoComponents(str_in):
    if str_in.startswith(('"', "'")):
        return shlex.split(str_in)
    else:
        components = str_in.split(' ', 1)
        if (len(components) > 1):
            return ([components[0]] + SplitIntoComponents(components[1]))
        else:
            return components

Splits strings into space-separated components.

The difference between SplitIntoComponents and .split(" ") is that
the former tries to respect single and double quotes and strip them
using lexical rules typically used in command line interpreters.

Args:
str_in: Source string to be split into components.

Returns:
str_in represented as a list of components. Components is effectively a
space-separated representation of a source string. " ".join(components)
should produce the original string (with pairs of single/double quotes
stripped).


def _parse_state_value(state, user):
    (uri, token) = state.rsplit(':', 1)
    if xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(), action_id=uri):
        return uri
    else:
        return None

Parse the value of the 'state' parameter.

Parses the value and validates the XSRF token in the state parameter.

Args:
state: string, The value of the state parameter.
user: google.appengine.api.users.User, The current user.

Returns:
The redirect URI, or None if XSRF token is not valid.


def graph_key_from_tag(tag, entity_index):
    start_token = tag.get('start_token')
    entity = tag.get('entities', [])[entity_index]
    return ((((str(start_token) + '-') + entity.get('key')) + '-') + str(entity.get('confidence')))

Returns a key from a tag entity

Args:
tag (tag) : this is the tag selected to get the key from
entity_index (int) : this is the index of the tagged entity

Returns:
str : String representing the key for the given tagged entity.


def recover(self, history: Iterable[Tuple[DNA, Union[None, float, Tuple[float]]]]) -> None:
    for i, (dna, reward) in enumerate(history):
        self._replay(i, dna, reward)
        self._num_proposals += 1
        if reward is not None:
            self._num_feedbacks += 1

Recover states by replaying the proposal history.

NOTE: `recover` will always be called before first `propose` and could be
called multiple times if there are multiple source of history, e.g: trials
from a previous study and existing trials from current study.

Args:
history: An iterable object that consists of historically proposed DNA
with its reward. The reward will be None if it is not yet provided
(via feedback).


def make_raw_assign_fn(raw_assign_fn, use_handle=True):

    def assign_fn(var, value, use_locking=False, name=None, read_value=True):
        del use_locking
        handle = var.handle if use_handle else var
        with _maybe_enter_graph(handle), _maybe_on_device(var):
            op = raw_assign_fn(handle, ops.convert_to_tensor(value, dtype=var.dtype), name=name)
            with ops.control_dependencies([op]):
                if read_value:
                    return var._read_variable_op() if use_handle else var.read_value()
                else:
                    return op
    return assign_fn

Wrap `raw_assign_fn` with the proper graph context and device scope.

Args:
raw_assign_fn: the function to be wrapped.
use_handle: if True, the `raw_assign_fn` will be applied to the handle of a
variable; otherwise it will be applied to the variable itself.

Returns:
The wrapped function.


def compute_centroid(points):

    lats = [p[1] for p in points]
    lons = [p[0] for p in points]
    return Point(np.mean(lats), np.mean(lons), None)

Computes the centroid of set of points

Args:
points (:obj:`list` of :obj:`Point`)
Returns:
:obj:`Point`


def __copyfile(source, destination):

    logger.info("copyfile: %s -> %s" % (source, destination))
    try:
        __create_destdir(destination)
        shutil.copy(source, destination)
        return True
    except Exception as e:
        logger.error(
            "copyfile: %s -> %s failed! Error: %s", source, destination, e
        )
        return False

Copy data and mode bits ("cp source destination").

The destination may be a directory.

Args:
source (str): Source file (file to copy).
destination (str): Destination file or directory (where to copy).

Returns:
bool: True if the operation is successful, False otherwise.


def valid_file(value):
    if (not value):
        raise argparse.ArgumentTypeError("'' is not a valid file path")
    elif (not os.path.exists(value)):
        raise argparse.ArgumentTypeError(('%s is not a valid file path' % value))
    elif os.path.isdir(value):
        raise argparse.ArgumentTypeError(('%s is a directory, not a regular file' % value))
    return value

Check if given file exists and is a regular file.

Args:
value (str): path to the file.

Raises:
argparse.ArgumentTypeError: if not valid.

Returns:
str: original value argument.


def _parse_mode(self, config):
    value = re.search('switchport mode (\\w+)', config, re.M)
    return dict(mode=value.group(1))

Scans the specified config and parses the switchport mode value

Args:
config (str): The interface configuration block to scan

Returns:
dict: A Python dict object with the value of switchport mode.
The dict returned is intended to be merged into the resource
dict


def signatures(self, transaction):

        if not self.multi_wallet:
            raise DecryptionError("This wallet must be unlocked with "
                                  "wallet.unlock(passphrase)")

        return self.multi_wallet.signatures(transaction)

Sign a transaction.

Args:
transaction (coinop.Transaction)

Returns:
A list of signature dicts of the form
[ {'primary': 'base58signaturestring'},
... ]


def probe_async(self, callback):

        topics = MQTTTopicValidator(self.prefix)
        self.client.publish(topics.probe, {'type': 'command', 'operation': 'probe', 'client': self.name})
        callback(self.id, True, None)

Probe for visible devices connected to this DeviceAdapter.

Args:
callback (callable): A callback for when the probe operation has completed.
callback should have signature callback(adapter_id, success, failure_reason) where:
success: bool
failure_reason: None if success is True, otherwise a reason for why we could not probe