def _call_rpc(self, header):

        length, _, cmd, feature, address = struct.unpack("<BBBBB", bytes(header))
        rpc_id = (feature << 8) | cmd

        payload = self.rpc_payload[:length]

        status = (1 << 6)
        try:
            response = self.device.call_rpc(address, rpc_id, bytes(payload))
            if len(response) > 0:
                status |= (1 << 7)
        except (RPCInvalidIDError, RPCNotFoundError):
            status = 2
            response = b''
        except TileNotFoundError:
            status = 0xFF
            response = b''
        except Exception:
            status = 3
            response = b''
            self._logger.exception("Exception raise while calling rpc, header=%s, payload=%s", header, payload)

        self._audit(
            "RPCReceived",
            rpc_id=rpc_id,
            address=address,
            payload=binascii.hexlify(payload),
            status=status,
            response=binascii.hexlify(response)
        )

        resp_header = struct.pack("<BBBB", status, 0, 0, len(response))

        if len(response) > 0:
            self._send_rpc_response(
                (ReceiveHeaderChar.value_handle, resp_header),
                (ReceivePayloadChar.value_handle, response)
            )
        else:
            self._send_rpc_response((ReceiveHeaderChar.value_handle, resp_header))

Call an RPC given a header and possibly a previously sent payload
It is executed in the baBLE working thread: should not be blocking.

Args:
header (bytearray): The RPC header we should call


def repeat(coro, times=1, step=1, limit=1, loop=None):
    assert_corofunction(coro=coro)
    times = max(int(times), 1)
    iterable = range(1, (times + 1), step)
    return (yield from map(coro, iterable, limit=limit, loop=loop))

Executes the coroutine function ``x`` number of  times,
and accumulates results in order as you would use with ``map``.

Execution concurrency is configurable using ``limit`` param.

This function is a coroutine.

Arguments:
coro (coroutinefunction): coroutine function to schedule.
times (int): number of times to execute the coroutine.
step (int): increment iteration step, as with ``range()``.
limit (int): concurrency execution limit. Defaults to 10.
loop (asyncio.BaseEventLoop): optional event loop to use.

Raises:
TypeError: if coro is not a coroutine function.

Returns:
list: accumulated yielded values returned by coroutine.

Usage::

async def mul_2(num):
return num * 2

await paco.repeat(mul_2, times=5)
# => [2, 4, 6, 8, 10]


def handle_response(self, item_session: ItemSession) -> Actions:
    action = self.consult_response_hook(item_session)
    if (action == Actions.RETRY):
        item_session.set_status(Status.error)
    elif (action == Actions.FINISH):
        item_session.set_status(Status.done)
    elif (action == Actions.STOP):
        raise HookStop('Script requested immediate stop.')
    return action

Generic handler for a response.

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


def on_train_batch_end(self, batch, logs=None):
    self.on_batch_end(batch, logs=logs)

Called at the end of a training batch in `fit` methods.

Subclasses should override for any actions to run.

Note that if the `steps_per_execution` argument to `compile` in
`tf.keras.Model` is set to `N`, this method will only be called every `N`
batches.

Args:
batch: Integer, index of batch within the current epoch.
logs: Dict. Aggregated metric results up until this batch.


def setOption(self, name, value):
    if isinstance(value, bool):
        lock_and_call((lambda : self._impl.setBoolOption(name, value)), self._lock)
    elif isinstance(value, int):
        lock_and_call((lambda : self._impl.setIntOption(name, value)), self._lock)
    elif isinstance(value, float):
        lock_and_call((lambda : self._impl.setDblOption(name, value)), self._lock)
    elif isinstance(value, basestring):
        lock_and_call((lambda : self._impl.setOption(name, value)), self._lock)
    else:
        raise TypeError

Set an AMPL option to a specified value.

Args:
name: Name of the option to be set (alphanumeric without spaces).

value: The value the option must be set to.

Raises:
InvalidArgumet: if the option name is not valid.

TypeError: if the value has an invalid type.


def run_test_in_subprocess(test_case, target_func, inputs=None, timeout=None):
    if timeout is None:
        timeout = int(os.environ.get('PYTEST_TIMEOUT', 600))
    start_methohd = 'spawn'
    ctx = multiprocessing.get_context(start_methohd)
    input_queue = ctx.Queue(1)
    output_queue = ctx.JoinableQueue(1)
    input_queue.put(inputs, timeout=timeout)
    process = ctx.Process(target=target_func, args=(input_queue, output_queue, timeout))
    process.start()
    try:
        results = output_queue.get(timeout=timeout)
        output_queue.task_done()
    except Exception as e:
        process.terminate()
        test_case.fail(e)
    process.join(timeout=timeout)
    if results['error'] is not None:
        test_case.fail(f'{results['error']}')

To run a test in a subprocess. In particular, this can avoid (GPU) memory issue.

Args:
test_case (`unittest.TestCase`):
The test that will run `target_func`.
target_func (`Callable`):
The function implementing the actual testing logic.
inputs (`dict`, *optional*, defaults to `None`):
The inputs that will be passed to `target_func` through an (input) queue.
timeout (`int`, *optional*, defaults to `None`):
The timeout (in seconds) that will be passed to the input and output queues. If not specified, the env.
variable `PYTEST_TIMEOUT` will be checked. If still `None`, its value will be set to `600`.


def trace_format(self):
    cmd = enums.JLinkTraceCommand.GET_FORMAT
    data = ctypes.c_uint32(0)
    res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(data))
    if (res == 1):
        raise errors.JLinkException('Failed to get trace format.')
    return data.value

Retrieves the current format the trace buffer is using.

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

Returns:
The current format the trace buffer is using.  This is one of the
attributes of ``JLinkTraceFormat``.


def dumps(xs, model=None, properties=False, indent=True, **kwargs):

    xs = list(xs)

    if not xs:
        return ''

    given_class = xs[0].__class__
    if model is None:
        model = xs[0].__class__

    if not hasattr(model, 'to_triples'):
        raise TypeError(
            '{} class does not implement to_triples()'.format(model.__name__)
        )

    if given_class.__name__ in ('Mrs', 'Xmrs'):
        xs = [model.from_xmrs(x, **kwargs) for x in xs]
    elif given_class.__name__ == 'Eds' and model.__name__ != 'Eds':
        raise ValueError('Cannot convert EDS to non-EDS')

    codec = XMRSCodec()
    graphs = [
        codec.triples_to_graph(model.to_triples(x, properties=properties))
        for x in xs
    ]

    if 'pretty_print' in kwargs:
        indent = kwargs['pretty_print']

    return penman.dumps(graphs, cls=XMRSCodec, indent=indent)

Serialize Xmrs (or subclass) objects to PENMAN notation

Args:
xs: iterator of :class:`~delphin.mrs.xmrs.Xmrs` objects to
serialize
model: Xmrs subclass used to get triples
properties: if `True`, encode variable properties
indent: if `True`, adaptively indent; if `False` or `None`,
don't indent; if a non-negative integer N, indent N spaces
per level
Returns:
the PENMAN serialization of *xs*


def dispatch_callback(self, items):
    if (not self._manager.is_active):
        return
    batched_commands = collections.defaultdict(list)
    for item in items:
        batched_commands[item.__class__].append(item)
    _LOGGER.debug('Handling %d batched requests', len(items))
    if batched_commands[requests.LeaseRequest]:
        self.lease(batched_commands.pop(requests.LeaseRequest))
    if batched_commands[requests.ModAckRequest]:
        self.modify_ack_deadline(batched_commands.pop(requests.ModAckRequest))
    if batched_commands[requests.AckRequest]:
        self.ack(batched_commands.pop(requests.AckRequest))
    if batched_commands[requests.NackRequest]:
        self.nack(batched_commands.pop(requests.NackRequest))
    if batched_commands[requests.DropRequest]:
        self.drop(batched_commands.pop(requests.DropRequest))

Map the callback request to the appropriate gRPC request.

Args:
action (str): The method to be invoked.
kwargs (Dict[str, Any]): The keyword arguments for the method
specified by ``action``.

Raises:
ValueError: If ``action`` isn't one of the expected actions
"ack", "drop", "lease", "modify_ack_deadline" or "nack".


def from_hoy(cls, hoy, leap_year=False):

        return cls.from_moy(round(hoy * 60), leap_year)

Create Ladybug Datetime from an hour of the year.

Args:
hoy: A float value 0 <= and < 8760


def log(self, level, msg, *args, **kwargs):
    if (level >= logging.FATAL):
        extra = kwargs.setdefault('extra', {})
        extra[_ABSL_LOG_FATAL] = True
    super(ABSLLogger, self).log(level, msg, *args, **kwargs)

Logs a message at a cetain level substituting in the supplied arguments.

This method behaves differently in python and c++ modes.

Args:
level: int, the standard logging level at which to log the message.
msg: str, the text of the message to log.
*args: The arguments to substitute in the message.
**kwargs: The keyword arguments to substitute in the message.


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

Base class for `PatchTSMixerEncoderOutput`, with potential hidden states.

Args:
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, num_patches, d_model)`):
Hidden-state at the output of the last layer of the model.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
Hidden-states of the model at the output of each layer.


def _from_compatible_tensor_list(self, tensor_list: List['core_types.Symbol']) -> Any:
    return self._from_components(nest.pack_sequence_as(self._component_specs, tensor_list, expand_composites=True))

Reconstructs a value from a compatible flat list of `tf.Tensor`.

Args:
tensor_list: A flat list of `tf.Tensor`, compatible with
`self._flat_tensor_specs`.  (Caller is responsible for ensuring
compatibility.)

Returns:
A value that is compatible with this `TypeSpec`.


def median(series):

    if np.issubdtype(series.dtype, np.number):
        return series.median()
    else:
        return np.nan

Returns the median value of a series.

Args:
series (pandas.Series): column to summarize.


def _AddAttribute(self, attribute):

    if attribute.identifier in self._attributes:
      raise KeyError((
          'Volume attribute object already set for volume attribute '
          'identifier: {0:s}.').format(attribute.identifier))

    self._attributes[attribute.identifier] = attribute

Adds an attribute.

Args:
attribute (VolumeAttribute): a volume attribute.

Raises:
KeyError: if volume attribute is already set for the corresponding volume
attribute identifier.


def Close(self):
    if self._connection:
        self._cursor = None
        self._connection.close()
        self._connection = None
    try:
        os.remove(self._temp_file_path)
    except (IOError, OSError):
        pass
    self._temp_file_path = ''

Closes the database file object.

Raises:
IOError: if the close failed.
OSError: if the close failed.


def __init__(self,
                 lang='en',
                 lower=True,
                 charset=None):

        super(CharTokenizer, self).__init__(lang, lower)
        self.charset = charset

Encodes text into `(samples, characters)`

Args:
lang: The spacy language to use. (Default value: 'en')
lower: Lower cases the tokens if True. (Default value: True)
charset: The character set to use. For example `charset = 'abc123'`. If None, all characters will be used.
(Default value: None)


def libravatar_url(email=None, openid=None, size=64, default='retro'):
    params = collections.OrderedDict([('s', size), ('d', default)])
    query = parse.urlencode(params)
    if email:
        value = email
    elif openid:
        value = openid
    else:
        raise ValueError('You must provide either the email or the openid.')
    idhash = sha256(value.encode('utf-8')).hexdigest()
    return ('https:

Get the URL to an avatar from libravatar.

Either the user's email or openid must be provided.

If you want to use Libravatar federation (through DNS), you should install
and use the ``libravatar`` library instead. Check out the
``libravatar.libravatar_url()`` function.

Args:
email (str): The user's email
openid (str): The user's OpenID
size (int): Size of the avatar in pixels (it's a square).
default (str): Default avatar to return if not found.
Returns:
str: The URL to the avatar image.
Raises:
ValueError: If neither email nor openid are provided.


def os_deployment_servers(self):
    if (not self.__os_deployment_servers):
        self.__os_deployment_servers = OsDeploymentServers(self.__connection)
    return self.__os_deployment_servers

Gets the Os Deployment Servers API client.

Returns:
OsDeploymentServers:


class StandardInputStep(Step):

    def __init__(self, dataset_fn, distribution):
        super(StandardInputStep, self).__init__(distribution)
        self._iterator = distribution.make_input_fn_iterator(lambda _: dataset_fn())

    def initialize(self):
        return self._iterator.initializer

Step with a standard implementation of input handling.

Args:
dataset_fn: a function that returns a tf.data Dataset that produces the
input for the model.


def create_webdriver(self, testname=None):
    try:
        driver_type = self._config_reader.get(self.DRIVER_TYPE_CONFIG)
    except:
        driver_type = self.DRIVER_TYPE_LOCAL
        _wtflog.warn('%s setting is missing from config. Using default setting, %s', self.DRIVER_TYPE_CONFIG, driver_type)
    if (driver_type == self.DRIVER_TYPE_REMOTE):
        self.webdriver = self.__create_remote_webdriver_from_config(testname=testname)
    else:
        self.webdriver = self.__create_driver_from_browser_config()
    try:
        self.webdriver.maximize_window()
    except:
        time.sleep(self._timeout_mgr.BRIEF)
        try:
            self.webdriver.maximize_window()
        except Exception as e:
            if (isinstance(e, WebDriverException) and ('implemented' in e.msg.lower())):
                pass
            else:
                _wtflog.warn(('Unable to maxmize browser window. ' + 'It may be possible the browser did not instantiate correctly. % s'), e)
    return self.webdriver

Creates an instance of Selenium webdriver based on config settings.
This should only be called by a shutdown hook.  Do not call directly within
a test.

Kwargs:
testname: Optional test name to pass, this gets appended to the test name
sent to selenium grid.

Returns:
WebDriver - Selenium Webdriver instance.


def remove_empty_text(utterances: List[Utterance]) -> List[Utterance]:

    return [utter for utter in utterances if utter.text.strip() != ""]

Remove empty utterances from a list of utterances
Args:
utterances: The list of utterance we are processing


def enable_inheritance(path, objectType, clear=False):

    dc = daclConstants()
    objectType = dc.getObjectTypeBit(objectType)
    path = dc.processPath(path, objectType)

    return _set_dacl_inheritance(path, objectType, True, None, clear)

enable/disable inheritance on an object

Args:
path: The path to the object
objectType: The type of object (FILE, DIRECTORY, REGISTRY)
clear: True will remove non-Inherited ACEs from the ACL

Returns (dict): A dictionary containing the results

CLI Example:

.. code-block:: bash

salt 'minion-id' win_dacl.enable_inheritance c:\temp directory


def add_signature(name=None, inputs=None, outputs=None):
    if (not name):
        name = 'default'
    if (inputs is None):
        inputs = {}
    if (outputs is None):
        outputs = {}
    if (not isinstance(inputs, dict)):
        inputs = {'default': inputs}
    if (not isinstance(outputs, dict)):
        outputs = {'default': outputs}
    message = find_signature_inputs_from_multivalued_ops(inputs)
    if message:
        logging.error(message)
    message = find_signature_input_colocation_error(name, inputs)
    if message:
        raise ValueError(message)
    saved_model_lib.add_signature(name, inputs, outputs)

Adds a signature to the module definition.

NOTE: This must be called within a `module_fn` that is defining a Module.

Args:
name: Signature name as a string. If omitted, it is interpreted as 'default'
and is the signature used when `Module.__call__` `signature` is not
specified.
inputs: A dict from input name to Tensor or SparseTensor to feed when
applying the signature. If a single tensor is passed, it is interpreted
as a dict with a single 'default' entry.
outputs: A dict from output name to Tensor or SparseTensor to return from
applying the signature. If a single tensor is passed, it is interpreted
as a dict with a single 'default' entry.

Raises:
ValueError: if the arguments are invalid.


class FlaxSuppressTokensAtBeginLogitsProcessor(FlaxLogitsProcessor):

    def __init__(self, begin_suppress_tokens, begin_index):
        self.begin_suppress_tokens = list(begin_suppress_tokens)
        self.begin_index = begin_index

    def __call__(self, input_ids, scores, cur_len: int):
        apply_penalty = 1 - jnp.bool_(cur_len - self.begin_index)
        scores = jnp.where(apply_penalty, scores.at[:, self.begin_suppress_tokens].set(-float('inf')), scores)
        return scores

[`FlaxLogitsProcessor`] suppressing a list of tokens as soon as the `generate` function starts generating using
`begin_index` tokens. This should ensure that the tokens defined by `begin_suppress_tokens` are not sampled at the
beginning of the generation.

Args:
begin_suppress_tokens (`List[int]`):
Tokens to not sample.
begin_index (`int`):
Index where the tokens are suppressed.


def Scripts(unicode_dir=_UNICODE_DIR):

  scripts = {}

  def DoLine(codes, fields):

    (_, name) = fields
    scripts.setdefault(name, []).extend(codes)

  ReadUnicodeTable(unicode_dir+"/Scripts.txt", 2, DoLine)
  return scripts

Returns dict mapping script names to code lists.

Args:
unicode_dir: Unicode data directory

Returns:
dict mapping script names to code lists


def with_accounted_types(self, account_type_regexes):
    self._options['account_type_regexes'] = copy.copy(account_type_regexes)
    return self

Selectively counting statistics based on node types.

Here, 'types' means the profiler nodes' properties. Profiler by default
consider device name (e.g. /job:xx/.../device:GPU:0) and operation type
(e.g. MatMul) as profiler nodes' properties. User can also associate
customized 'types' to profiler nodes through OpLogProto proto.

For example, user can select profiler nodes placed on gpu:0 with:
`account_type_regexes=['.*gpu:0.*']`

If none of a node's properties match the specified regexes, the node is
not displayed nor accounted.

Args:
account_type_regexes: A list of regexes specifying the types.
Returns:
self.


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

List the container groups in a resource group.

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

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


def data_vectors(self):
    return {field: self.record[field] for field in self.record.dtype.names if (field != 'sample')}

The per-sample data in a vector.

Returns:
dict: A dict where the keys are the fields in the record and the
values are the corresponding arrays.

Examples:
>>> sampleset = dimod.SampleSet.from_samples([[-1, 1], [1, 1]], dimod.SPIN,
energy=[-1, 1])
>>> sampleset.data_vectors['energy']
array([-1,  1])

Note that this is equivalent to, and less performant than:

>>> sampleset = dimod.SampleSet.from_samples([[-1, 1], [1, 1]], dimod.SPIN,
energy=[-1, 1])
>>> sampleset.record['energy']
array([-1,  1])


def download_data_impl(self, run, tag, response_format):

    scalars_plugin_instance = self._get_scalars_plugin()
    if not scalars_plugin_instance:
      raise ValueError(('Failed to respond to request for /download_data. '
                        'The scalars plugin is oddly not registered.'))

    body, mime_type = scalars_plugin_instance.scalars_impl(
        tag, run, None, response_format)
    return body, mime_type

Provides a response for downloading scalars data for a data series.

Args:
run: The run.
tag: The specific tag.
response_format: A string. One of the values of the OutputFormat enum of
the scalar plugin.

Raises:
ValueError: If the scalars plugin is not registered.

Returns:
2 entities:
- A JSON object response body.
- A mime type (string) for the response.


def log(msg, level=0):

    red = '\033[91m'
    endc = '\033[0m'

    cfg = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'stdout': {
                'format': '[%(levelname)s]: %(asctime)s - %(message)s',
                'datefmt': '%x %X'
            },
            'stderr': {
                'format': red + '[%(levelname)s]: %(asctime)s - %(message)s' + endc,
                'datefmt': '%x %X'
            }
        },
        'handlers': {
            'stdout': {
                'class': 'logging.StreamHandler',
                'level': 'DEBUG',
                'formatter': 'stdout'
            },
            'stderr': {
                'class': 'logging.StreamHandler',
                'level': 'ERROR',
                'formatter': 'stderr'
            }
        },
        'loggers': {
            'info': {
                'handlers': ['stdout'],
                'level': 'INFO',
                'propagate': True
            },
            'error': {
                'handlers': ['stderr'],
                'level': 'ERROR',
                'propagate': False
            }
        }
    }

    dictConfig(cfg)

    lg = 'info' if level == 0 else 'error'
    lvl = 20 if level == 0 else 40

    logger = logging.getLogger(lg)
    logger.log(lvl, msg)

Logs a message to the console, with optional level paramater

Args:
- msg (str): message to send to console
- level (int): log level; 0 for info, 1 for error (default = 0)


def _get_ngrams(segment, max_order):

  ngram_counts = collections.Counter()
  for order in range(1, max_order + 1):
    for i in range(0, len(segment) - order + 1):
      ngram = tuple(segment[i:i + order])
      ngram_counts[ngram] += 1
  return ngram_counts

Extracts all n-grams up to a given maximum order from an input segment.

Args:
segment: text segment from which n-grams will be extracted.
max_order: maximum length in tokens of the n-grams returned by this
methods.

Returns:
The Counter containing all n-grams up to max_order in segment
with a count of how many times each n-gram occurred.


def append(self, species, coords, validate_proximity=True, properties=None):
    return self.insert(len(self), species, coords, validate_proximity=validate_proximity, properties=properties)

Appends a site to the molecule.

Args:
species: Species of inserted site
coords: Coordinates of inserted site
validate_proximity (bool): Whether to check if inserted site is
too close to an existing site. Defaults to True.
properties (dict): A dict of properties for the Site.

Returns:
New molecule with inserted site.


def get_candidates(self, input_ids: torch.LongTensor) -> Tuple[torch.LongTensor, Optional[torch.FloatTensor]]:
    input_length = input_ids.size(1)
    if self.max_length == input_length + 1:
        return (input_ids, None)
    chosen_ids = None
    match_found = False
    for ngram_size in range(min(self.max_matching_ngram_size, input_length - 1), 0, -1):
        windows = input_ids.unfold(dimension=1, size=ngram_size, step=1)
        ngram_tensor = input_ids[0, -ngram_size:]
        matches = (windows == ngram_tensor).all(dim=2)
        match_indices = matches.nonzero(as_tuple=True)[1]
        for idx in match_indices:
            start_idx = idx + ngram_size
            end_idx = start_idx + self.num_output_tokens
            end_idx = min(end_idx, input_length, self.max_length)
            if start_idx < end_idx:
                chosen_ids = input_ids[0, start_idx:end_idx]
                match_found = True
                mask = isin_mps_friendly(chosen_ids, self.eos_token_id)
                match_indices_eos = torch.nonzero(mask)
                if match_indices_eos.numel() > 0:
                    first_eos_index = match_indices_eos[0].item()
                    chosen_ids = chosen_ids[:first_eos_index]
                break
        if match_found:
            break
    if chosen_ids is None or len(chosen_ids) == 0:
        return (input_ids, None)
    chosen_ids = chosen_ids.unsqueeze(0)
    candidate_input_ids = torch.cat((input_ids, chosen_ids), dim=1)
    return (candidate_input_ids, None)

Fetches the candidates to be tried for the current input.

Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. [What are input IDs?](../glossary#input-ids)

Return:
`torch.LongTensor` of shape `(num_candidates, candidate_length)`: The candidate sequences to be tried.


def _BuildEventData(self, record):
    event_data = FseventsdEventData()
    event_data.path = record.path
    event_data.flags = record.event_flags
    event_data.event_identifier = record.event_identifier
    event_data.node_identifier = getattr(record, 'node_identifier', None)
    return event_data

Builds an FseventsdData object from a parsed structure.

Args:
record (dls_record_v1|dls_record_v2): parsed record structure.

Returns:
FseventsdEventData: event data attribute container.


def delete_note(self, note_id):

        note, status = self.trash_note(note_id)
        if (status == -1):
            return note, status

        params = '/i/%s' % (str(note_id))
        request = Request(url=DATA_URL+params, method='DELETE')
        request.add_header(self.header, self.get_token())
        try:
            response = urllib2.urlopen(request)
        except IOError as e:
            return e, -1
        except HTTPError as e:
            if e.code == 401:
                raise SimplenoteLoginFailed('Login to Simplenote API failed! Check Token.')
            else:
                return e, -1
        return {}, 0

Method to permanently delete a note

Arguments:
- note_id (string): key of the note to trash

Returns:
A tuple `(note, status)`

- note (dict): an empty dict or an error message
- status (int): 0 on success and -1 otherwise


def __init__(self, name):

        self.name = name
        self.edges_in = set()
        self.edges_out = set()

Initialization method.

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


def RegisterCredentials(cls, credentials):
    if (credentials.type_indicator in cls._credentials):
        raise KeyError('Credentials object already set for type indicator: {0:s}.'.format(credentials.type_indicator))
    cls._credentials[credentials.type_indicator] = credentials

Registers a path specification credentials.

Args:
credentials (Credentials): credentials.

Raises:
KeyError: if credentials object is already set for the corresponding
type indicator.


def _get_value(self, scalar_data_blob, dtype_enum):
    tensorflow_dtype = tf.DType(dtype_enum)
    buf = np.frombuffer(scalar_data_blob, dtype=tensorflow_dtype.as_numpy_dtype)
    return np.asscalar(buf)

Obtains value for scalar event given blob and dtype enum.

Args:
scalar_data_blob: The blob obtained from the database.
dtype_enum: The enum representing the dtype.

Returns:
The scalar value.


def _remove_subsequent_result_because_of_batch_failure(self, sig):
    batch = self._batches_by_txn_id[sig]
    seen = []
    for txn in batch.transactions:
        txn_id = txn.header_signature
        for poss_successor in self._scheduled.copy():
            if (not self.is_transaction_in_schedule(poss_successor)):
                continue
            if self._is_txn_to_replay(txn_id, poss_successor, seen):
                if self._txn_has_result(poss_successor):
                    del self._txn_results[poss_successor]
                    self._scheduled.remove(poss_successor)
                    self._txns_available[poss_successor] = self._transactions[poss_successor]
                else:
                    self._outstanding.add(poss_successor)
                seen.append(poss_successor)

Remove transactions from scheduled and txn_results for
successors of txns in a failed batch. These transactions will now,
or in the future be rescheduled in next_transaction; giving a
replay ability.

Args:
sig (str): Transaction header signature


def repeat(sequence):
    N = len(sequence)

    def f(i):
        return sequence[(i % N)]
    return partial(force, sequence=_advance(f))

Return a driver function that can advance a repeated of values.

.. code-block:: none

seq = [0, 1, 2, 3]

# repeat(seq) => [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ...]

Args:
sequence (seq) : a sequence of values for the driver to bounce


def unflatten(guide, falttened_input):

    return [unflatten(sub_list, falttened_input) if isinstance(sub_list, list)
            else next(falttened_input) for sub_list in guide]

Unflatten a falttened generator.

Args:
guide: A guide list to follow the structure
falttened_input: A flattened iterator object

Usage:

guide = [["a"], ["b","c","d"], [["e"]], ["f"]]
input_list = [0, 1, 2, 3, 4, 5, 6, 7]
unflatten(guide, iter(input_list))
>> [[0], [1, 2, 3], [[4]], [5]]


def _get_access_token():
    access_token = os.environ.get(ACCESS_TOKEN_ENVIRONMENT_VARIABLE)
    if access_token:
        return access_token
    else:
        for access_token_variable in LEGACY_ACCESS_TOKEN_ENVIRONMENT_VARIABLES:
            access_token = os.environ.get(access_token_variable)
            if access_token:
                env_var_deprecation_warning = PendingDeprecationWarning('Use of the `{legacy}` environment variable will be deprecated in the future.  Please update your environment(s) to use the new `{new}` environment variable.'.format(legacy=access_token, new=ACCESS_TOKEN_ENVIRONMENT_VARIABLE))
                warnings.warn(env_var_deprecation_warning)
                return access_token

Attempt to get the access token from the environment.

Try using the current and legacy environment variables. If the access token
is found in a legacy environment variable, raise a deprecation warning.

Returns:
The access token found in the environment (str), or None.


def SetModifyTimestamp(self, value):
    if value is None or isinstance(value, int):
        self._last_modification_timestamp = value
    else:
        raise TypeError('timestamp can only be int or None, not %r' % value)

Set the last modify timestamp of this map.

Args:
value: An integer containing the number of seconds since epoch, or None.

Raises:
TypeError: The argument is not an int or None.


def _dropout(x, rate, noise_shape, uniform_sampler, dummy_rng_step, name, default_name):
    with ops.name_scope(name, default_name, [x]) as name:
        is_rate_number = isinstance(rate, numbers.Real)
        if is_rate_number and (rate < 0 or rate >= 1):
            raise ValueError(f'`rate` must be a scalar tensor or a float in the range [0, 1). Received: rate={rate}')
        x = ops.convert_to_tensor(x, name='x')
        x_dtype = x.dtype
        if not x_dtype.is_floating:
            raise ValueError(f'`x.dtype` must be a floating point tensor as `x` will be scaled. Received: x_dtype={x_dtype}')
        if is_rate_number and rate == 0:
            dummy_rng_step()
            return x
        is_executing_eagerly = context.executing_eagerly()
        if not tensor_util.is_tf_type(rate):
            if is_rate_number:
                keep_prob = 1 - rate
                scale = 1 / keep_prob
                scale = ops.convert_to_tensor(scale, dtype=x_dtype)
                ret = gen_math_ops.mul(x, scale)
            else:
                raise ValueError(f'`rate` must be a scalar or scalar tensor. Received: rate={rate}')
        else:
            rate.get_shape().assert_has_rank(0)
            rate_dtype = rate.dtype
            if rate_dtype != x_dtype:
                if not rate_dtype.is_compatible_with(x_dtype):
                    raise ValueError(f'`x.dtype` must be compatible with `rate.dtype`. Received: x.dtype={x_dtype} and rate.dtype={rate_dtype}')
                rate = gen_math_ops.cast(rate, x_dtype, name='rate')
            one_tensor = constant_op.constant(1, dtype=x_dtype)
            ret = gen_math_ops.real_div(x, gen_math_ops.sub(one_tensor, rate))
        noise_shape = _get_noise_shape(x, noise_shape)
        random_tensor = uniform_sampler(shape=noise_shape, dtype=x_dtype)
        keep_mask = random_tensor >= rate
        zero_tensor = constant_op.constant(0, dtype=x_dtype)
        ret = array_ops.where_v2(keep_mask, ret, zero_tensor)
        if not is_executing_eagerly:
            ret.set_shape(x.get_shape())
        return ret

Shared implementation of the various dropout functions.

Args:
x: same as the namesake in `dropout_v2`.
rate: same as the namesake in `dropout_v2`.
noise_shape: same as the namesake in `dropout_v2`.
uniform_sampler: a callable of signature `(shape, dtype) ->
Tensor`, used to generate a tensor of uniformly-distributed
random numbers in the range `[0, 1)`, of the given shape and dtype.
dummy_rng_step: a callable of signature `() -> None`, to make a
dummy RNG call in the fast path. In the fast path where rate is
0, we don't need to generate random numbers, but some samplers
still require you to make an RNG call, to make sure that RNG
states won't depend on whether the fast path is taken.
name: same as the namesake in `dropout_v2`.
default_name: a default name in case `name` is `None`.

Returns:
A Tensor of the same shape and dtype of `x`.


def encode_boxes(self, text: Union[TextInput, PreTokenizedInput, EncodedInput], text_pair: Optional[Union[TextInput, PreTokenizedInput, EncodedInput]]=None, boxes: Optional[List[List[int]]]=None, word_labels: Optional[List[List[int]]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, stride: int=0, return_tensors: Optional[Union[str, TensorType]]=None, **kwargs) -> List[int]:
    encoded_inputs = self.encode_plus_boxes(text, text_pair=text_pair, boxes=boxes, word_labels=word_labels, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, stride=stride, return_tensors=return_tensors, **kwargs)
    return encoded_inputs['input_ids']

Args:
Converts a string to a sequence of ids (integer), using the tokenizer and vocabulary. Same as doing
`self.convert_tokens_to_ids(self.tokenize(text))`.
text (`str`, `List[str]` or `List[int]`):
The first sequence to be encoded. This can be a string, a list of strings (tokenized string using the
`tokenize` method) or a list of integers (tokenized string ids using the `convert_tokens_to_ids`
method).
text_pair (`str`, `List[str]` or `List[int]`, *optional*):
Optional second sequence to be encoded. This can be a string, a list of strings (tokenized string using
the `tokenize` method) or a list of integers (tokenized string ids using the `convert_tokens_to_ids`
method).


def noisy_moment(self, moment: 'cirq.Moment',
                     system_qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':

        if not hasattr(self.noisy_moments, '_not_overridden'):
            return self.noisy_moments([moment], system_qubits)

        if not hasattr(self.noisy_operation, '_not_overridden'):
            return [self.noisy_operation(op) for op in moment]

        assert False, 'Should be unreachable.'

Adds noise to the operations from a moment.

Args:
moment: The moment to add noise to.
system_qubits: A list of all qubits in the system.

Returns:
An OP_TREE corresponding to the noisy operations for the moment.


def __create_and_save_state(cls, job_config, mapreduce_spec):

    state = model.MapreduceState.create_new(job_config.job_id)
    state.mapreduce_spec = mapreduce_spec
    state.active = True
    state.active_shards = 0
    state.app_id = job_config._app
    config = datastore_rpc.Configuration(force_writes=job_config._force_writes)
    state.put(config=config)
    return state

Save map job state to datastore.

Save state to datastore so that UI can see it immediately.

Args:
job_config: map_job.JobConfig.
mapreduce_spec: model.MapreduceSpec.

Returns:
model.MapreduceState for this job.


def __init__(self, shape, scope='distribution', summary_labels=None):

        self.shape = shape

        self.scope = scope
        self.summary_labels = set(summary_labels or ())

        self.variables = dict()
        self.all_variables = dict()

        def custom_getter(getter, name, registered=False, **kwargs):
            variable = getter(name=name, registered=True, **kwargs)
            if registered:
                pass
            elif name in self.all_variables:
                assert variable is self.all_variables[name]
                if kwargs.get('trainable', True):
                    assert variable is self.variables[name]
                    if 'variables' in self.summary_labels:
                        tf.contrib.summary.histogram(name=name, tensor=variable)
            else:
                self.all_variables[name] = variable
                if kwargs.get('trainable', True):
                    self.variables[name] = variable
                    if 'variables' in self.summary_labels:
                        tf.contrib.summary.histogram(name=name, tensor=variable)
            return variable

        self.parameterize = tf.make_template(
            name_=(scope + '/parameterize'),
            func_=self.tf_parameterize,
            custom_getter_=custom_getter
        )
        self.sample = tf.make_template(
            name_=(scope + '/sample'),
            func_=self.tf_sample,
            custom_getter_=custom_getter
        )
        self.log_probability = tf.make_template(
            name_=(scope + '/log-probability'),
            func_=self.tf_log_probability,
            custom_getter_=custom_getter
        )
        self.entropy = tf.make_template(
            name_=(scope + '/entropy'),
            func_=self.tf_entropy,
            custom_getter_=custom_getter
        )
        self.kl_divergence = tf.make_template(
            name_=(scope + '/kl-divergence'),
            func_=self.tf_kl_divergence,
            custom_getter_=custom_getter
        )
        self.regularization_loss = tf.make_template(
            name_=(scope + '/regularization-loss'),
            func_=self.tf_regularization_loss,
            custom_getter_=custom_getter
        )

Distribution.

Args:
shape: Action shape.


def set_xml(self, diagram, force=False):

        no_of_running = WFInstance.objects.filter(wf=self, finished=False, started=True).count()
        if no_of_running and not force:
            raise RunningInstancesExist(
                "Can't update WF diagram! Running %s WF instances exists for %s" % (
                    no_of_running, self.name
                ))
        else:
            self.xml = diagram
            parser = BPMNParser(diagram.body)
            self.description = parser.get_description()
            self.title = parser.get_name() or self.name.replace('_', ' ').title()
            extensions = dict(parser.get_wf_extensions())
            self.programmable = extensions.get('programmable', False)
            self.task_type = extensions.get('task_type', None)
            self.menu_category = extensions.get('menu_category', settings.DEFAULT_WF_CATEGORY_NAME)
            self.save()

updates xml link if there aren't any running instances of this wf
Args:
diagram: XMLDiagram object


def __init__(self, sbn):

        isbn = '0' + sbn
        super(Sbn, self).__init__(isbn)

Initialise a new ``Sbn`` object.

Args:
sbn (str): SBN string


def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
    output = [self.cls_token_id] + token_ids_0 + [self.sep_token_id]
    if token_ids_1:
        output += token_ids_1 + [self.sep_token_id]
    return output

Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A BERT sequence has the following format:

- single sequence: `[CLS] X [SEP]`
- pair of sequences: `[CLS] A [SEP] B [SEP]`

Args:
token_ids_0 (`List[int]`):
List of IDs to which the special tokens will be added.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.


def plot_state_histogram(result: trial_result.TrialResult) -> np.ndarray:

    import matplotlib.pyplot as plt

    num_qubits = len(result.measurements.keys())
    states = 2**num_qubits
    values = np.zeros(states)

    measurement_by_result = np.array([
        v.transpose()[0] for k, v in result.measurements.items()]).transpose()

    for meas in measurement_by_result:

        state_ind = int(''.join([str(x) for x in [int(x) for x in meas]]), 2)
        values[state_ind] += 1

    plot_labels = [bin(x)[2:].zfill(num_qubits) for x in range(states)]
    plt.bar(np.arange(states), values, tick_label=plot_labels)
    plt.xlabel('qubit state')
    plt.ylabel('result count')
    plt.show()

    return values

Plot the state histogram from a single result with repetitions.

States is a bitstring representation of all the qubit states in a single
result.
Currently this function assumes each measurement gate applies to only
a single qubit.

Args:
result: The trial results to plot.

Returns:
The histogram. A list of values plotted on the y-axis.


def get_enterprise_customer_user(user_id, enterprise_uuid):

    EnterpriseCustomerUser = apps.get_model('enterprise', 'EnterpriseCustomerUser')
    try:
        return EnterpriseCustomerUser.objects.get(
            enterprise_customer__uuid=enterprise_uuid,
            user_id=user_id
        )
    except EnterpriseCustomerUser.DoesNotExist:
        return None

Return the object for EnterpriseCustomerUser.

Arguments:
user_id (str): user identifier
enterprise_uuid (UUID): Universally unique identifier for the enterprise customer.

Returns:
(EnterpriseCustomerUser): enterprise customer user record


def get(self):
    parser = reqparse.RequestParser()
    parser.add_argument('public_key', type=parameters.valid_ed25519, required=True)
    parser.add_argument('spent', type=parameters.valid_bool)
    args = parser.parse_args(strict=True)
    pool = current_app.config['bigchain_pool']
    with pool() as bigchain:
        outputs = bigchain.get_outputs_filtered(args['public_key'], args['spent'])
        return [{'transaction_id': output.txid, 'output_index': output.output} for output in outputs]

API endpoint to retrieve a list of links to transaction
outputs.

Returns:
A :obj:`list` of :cls:`str` of links to outputs.


def path_is_empty(p: tcod.path.AStar) -> bool:
    return bool(lib.TCOD_path_is_empty(p._path_c))

Return True if a path is empty.

Args:
p (AStar): An AStar instance.
Returns:
bool: True if a path is empty.  Otherwise False.


def ToParameter(item: StackItem):
    if (isinstance(item, Array) or isinstance(item, Struct)):
        items = item.GetArray()
        output = [ContractParameter.ToParameter(subitem) for subitem in items]
        return ContractParameter(type=ContractParameterType.Array, value=output)
    elif isinstance(item, Boolean):
        return ContractParameter(type=ContractParameterType.Boolean, value=item.GetBoolean())
    elif isinstance(item, ByteArray):
        return ContractParameter(type=ContractParameterType.ByteArray, value=item.GetByteArray())
    elif isinstance(item, Integer):
        return ContractParameter(type=ContractParameterType.Integer, value=str(item.GetBigInteger()))
    elif isinstance(item, InteropInterface):
        return ContractParameter(type=ContractParameterType.InteropInterface, value=item.GetInterface())

Convert a StackItem to a ContractParameter object

Args:
item (neo.VM.InteropService.StackItem) The item to convert to a ContractParameter object

Returns:
ContractParameter


def mixins(self, name):

        m = self._smixins(name)
        if m:
            return m
        return self._smixins(name.replace('?>?', ' '))

Search mixins for name.
Allow '>' to be ignored. '.a .b()' == '.a > .b()'
Args:
name (string): Search term
Returns:
Mixin object list OR False


def _wrap_result(self, response):
    if isinstance(response, int):
        response = self._wrap_response(response)
    return HandlerResult(status=HandlerStatus.RETURN, message_out=self._response_proto(**response), message_type=self._response_type)

Wraps child's response in a HandlerResult to be sent back to client.

Args:
response (enum or dict): Either an integer status enum, or a dict
of attributes to be added to the protobuf response.


def output_reference(self, name):

        if name not in self.output_names:
            raise ValueError('Invalid output "{}"'.format(name))
        return Reference(step_name=self.name_in_workflow, output_name=name)

Return a reference to the given output for use in an input
of a next Step.

For a Step named `echo` that has an output called `echoed`, the
reference `echo/echoed` is returned.

Args:
name (str): the name of the Step output
Raises:
ValueError: The name provided is not a valid output name for this
Step.


def register_many(self, *args):
    params = []
    for name in args:
        params.append(self.register(name))
    return params

Register many configuration names.

Arguments:
*args: Config names as strings.

Returns:
list: List of registered configs.


def call(self, inputs):
    image_shape = tf.shape(input=inputs)[(- 3):]
    collapsed_shape = tf.concat(([(- 1)], image_shape), axis=0)
    out = tf.reshape(inputs, collapsed_shape)
    out = self.conv1(out)
    out = self.conv2(out)
    out = self.conv3(out)
    out = self.conv4(out)
    expanded_shape = tf.concat((tf.shape(input=inputs)[:(- 3)], [(- 1)]), axis=0)
    return tf.reshape(out, expanded_shape)

Runs the model to generate an intermediate representation of x_t.

Args:
inputs: A batch of image sequences `x_{1:T}` of shape
`[sample_shape, batch_size, timesteps, height, width,
channels]`.

Returns:
A batch of intermediate representations of shape [sample_shape,
batch_size, timesteps, hidden_size].


def prepare_namespace(self, func):
    if self.is_imethod:
        to_run = getattr(self.obj, self.imethod_name)
    else:
        to_run = func
    for (varname, modulename) in self.global_modules.items():
        to_run.__globals__[varname] = __import__(modulename)
    if self.global_closure:
        to_run.__globals__.update(self.global_closure)
    if self.global_functions:
        to_run.__globals__.update(self.global_functions)
    return to_run

Prepares the function to be run after deserializing it.
Re-associates any previously bound variables and modules from the closure

Returns:
callable: ready-to-call function


def rot90(array, k=1, axes=(0, 1)):
    if any_symbolic_tensors((array,)):
        return Rot90(k=k, axes=axes).symbolic_call(array)
    return backend.numpy.rot90(array, k=k, axes=axes)

Rotate an array by 90 degrees in the plane specified by axes.

This function rotates an array counterclockwise
by 90 degrees `k` times in the plane specified by `axes`.
Supports arrays of two or more dimensions.

Args:
array: Input array to rotate.
k: Number of times the array is rotated by 90 degrees.
axes: A tuple of two integers specifying the
plane of rotation (defaults to `(0, 1)`).

Returns:
Rotated array.

Examples:

>>> import numpy as np
>>> from keras import ops
>>> m = np.array([[1, 2], [3, 4]])
>>> rotated = ops.rot90(m)
>>> rotated
array([[2, 4],
[1, 3]])

>>> m = np.arange(8).reshape((2, 2, 2))
>>> rotated = ops.rot90(m, k=1, axes=(1, 2))
>>> rotated
array([[[1, 3],
[0, 2]],
[[5, 7],
[4, 6]]])


def unravel_staff(staff_data):
    staff_list = []
    for (role, staff_members) in staff_data['data'].items():
        for member in staff_members:
            member['role'] = role
            staff_list.append(member)
    return staff_list

Unravels staff role dictionary into flat list of staff
members with ``role`` set as an attribute.

Args:
staff_data(dict): Data return from py:method::get_staff

Returns:
list: Flat list of staff members with ``role`` set to
role type (i.e. course_admin, instructor, TA, etc)


def forecast(self, throughputs, backlog_size, num_simulations=10000, max_periods=10000, seed=None):

        self._check_throughputs(throughputs)
        results = []

        if seed is not None:
            random.seed(seed)

        for i in range(0, num_simulations):
            simulated_backlog = backlog_size
            time_unit_count = 0
            while simulated_backlog > 0:
                simulated_backlog -= random.choice(throughputs)
                time_unit_count += 1
                if time_unit_count > max_periods:
                    raise ValueError("More than {} periods calculated".format(max_periods))
            results.append(time_unit_count)

        return Results(results)

Forecasts how long a backlog will take to complete given the historical values provided.
Arguments:
throughputs(List[int]): Number of units completed per unit of time (stories per week, story points per month, etc.)
backlog_size(int): Units in the backlog (stories, points, etc.)
Returns:
results
Exceptions:
ValueError: If there aren't any positive throughputs, or the simulation takes too long.


def _predictResponseSize(mode, functioncode, payloadToSlave):
    MIN_PAYLOAD_LENGTH = 4
    BYTERANGE_FOR_GIVEN_SIZE = slice(2, 4)
    NUMBER_OF_PAYLOAD_BYTES_IN_WRITE_CONFIRMATION = 4
    NUMBER_OF_PAYLOAD_BYTES_FOR_BYTECOUNTFIELD = 1
    RTU_TO_ASCII_PAYLOAD_FACTOR = 2
    NUMBER_OF_RTU_RESPONSE_STARTBYTES = 2
    NUMBER_OF_RTU_RESPONSE_ENDBYTES = 2
    NUMBER_OF_ASCII_RESPONSE_STARTBYTES = 5
    NUMBER_OF_ASCII_RESPONSE_ENDBYTES = 4
    _checkMode(mode)
    _checkFunctioncode(functioncode, None)
    _checkString(payloadToSlave, description='payload', minlength=MIN_PAYLOAD_LENGTH)
    if (functioncode in [5, 6, 15, 16]):
        response_payload_size = NUMBER_OF_PAYLOAD_BYTES_IN_WRITE_CONFIRMATION
    elif (functioncode in [1, 2, 3, 4]):
        given_size = _twoByteStringToNum(payloadToSlave[BYTERANGE_FOR_GIVEN_SIZE])
        if ((functioncode == 1) or (functioncode == 2)):
            number_of_inputs = given_size
            response_payload_size = ((NUMBER_OF_PAYLOAD_BYTES_FOR_BYTECOUNTFIELD + (number_of_inputs
        elif ((functioncode == 3) or (functioncode == 4)):
            number_of_registers = given_size
            response_payload_size = (NUMBER_OF_PAYLOAD_BYTES_FOR_BYTECOUNTFIELD + (number_of_registers * _NUMBER_OF_BYTES_PER_REGISTER))
    else:
        raise ValueError('Wrong functioncode: {}. The payload is: {!r}'.format(functioncode, payloadToSlave))
    if (mode == MODE_ASCII):
        return ((NUMBER_OF_ASCII_RESPONSE_STARTBYTES + (response_payload_size * RTU_TO_ASCII_PAYLOAD_FACTOR)) + NUMBER_OF_ASCII_RESPONSE_ENDBYTES)
    else:
        return ((NUMBER_OF_RTU_RESPONSE_STARTBYTES + response_payload_size) + NUMBER_OF_RTU_RESPONSE_ENDBYTES)

Calculate the number of bytes that should be received from the slave.

Args:
* mode (str): The modbus protcol mode (MODE_RTU or MODE_ASCII)
* functioncode (int): Modbus function code.
* payloadToSlave (str): The raw request that is to be sent to the slave (not hex encoded string)

Returns:
The preducted number of bytes (int) in the response.

Raises:
ValueError, TypeError.


def create_detector(self, detector):
    resp = self._post(self._u(self._DETECTOR_ENDPOINT_SUFFIX), data=detector)
    resp.raise_for_status()
    return resp.json()

Creates a new detector.

Args:
detector (object): the detector model object. Will be serialized as
JSON.
Returns:
dictionary of the response (created detector model).


def get_application_configurations(self, name=None):

        if hasattr(self, 'applicationConfigurations'):
           return self._get_elements(self.applicationConfigurations, 'applicationConfigurations', ApplicationConfiguration, None, name)

Retrieves application configurations for this instance.

Args:
name (str, optional): Only return application configurations containing property **name** that matches `name`. `name` can be a
regular expression. If `name` is not supplied, then all application configurations are returned.

Returns:
list(ApplicationConfiguration): A list of application configurations matching the given `name`.

.. versionadded 1.12


def apply_cut(self, cut):
    return MacroSubsystem(self.network, self.network_state, self.micro_node_indices, cut=cut, time_scale=self.time_scale, blackbox=self.blackbox, coarse_grain=self.coarse_grain)

Return a cut version of this |MacroSubsystem|.

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

Returns:
MacroSubsystem: The cut version of this |MacroSubsystem|.


def parse_user_data(variables, raw_user_data, blueprint_name):
    variable_values = {}
    for (key, value) in variables.items():
        if (type(value) is CFNParameter):
            variable_values[key] = value.to_parameter_value()
        else:
            variable_values[key] = value
    template = string.Template(raw_user_data)
    res = ''
    try:
        res = template.substitute(variable_values)
    except ValueError as exp:
        raise InvalidUserdataPlaceholder(blueprint_name, exp.args[0])
    except KeyError as key:
        raise MissingVariable(blueprint_name, key)
    return res

Parse the given user data and renders it as a template

It supports referencing template variables to create userdata
that's supplemented with information from the stack, as commonly
required when creating EC2 userdata files.

For example:
Given a raw_user_data string: 'open file ${file}'
And a variables dictionary with: {'file': 'test.txt'}
parse_user_data would output: open file test.txt

Args:
variables (dict): variables available to the template
raw_user_data (str): the user_data to be parsed
blueprint_name (str): the name of the blueprint

Returns:
str: The parsed user data, with all the variables values and
refs replaced with their resolved values.

Raises:
InvalidUserdataPlaceholder: Raised when a placeholder name in
raw_user_data is not valid.
E.g ${100} would raise this.
MissingVariable: Raised when a variable is in the raw_user_data that
is not given in the blueprint


def _genBgTerm_fromXX(self,vTot,vCommon,XX,a=None,c=None):

        vSpecific = vTot-vCommon

        SP.random.seed(0)
        if c==None: c = SP.randn(self.P)
        XX += 1e-3 * SP.eye(XX.shape[0])
        L = LA.cholesky(XX,lower=True)

        R = self.genWeights(self.N,self.P)
        A = self.genTraitEffect()
        if a is not None: A[0,:] = a
        Yc = SP.dot(L,SP.dot(R,A))
        Yc*= SP.sqrt(vCommon)/SP.sqrt(Yc.var(0).mean())

        R = SP.randn(self.N,self.P)
        Yi = SP.dot(L,SP.dot(R,SP.diag(c)))
        Yi*= SP.sqrt(vSpecific)/SP.sqrt(Yi.var(0).mean())

        return Yc, Yi

generate background term from SNPs

Args:
vTot: variance of Yc+Yi
vCommon: variance of Yc
XX: kinship matrix
a: common scales, it can be set for debugging purposes
c: indipendent scales, it can be set for debugging purposes


def EncodeEnv(env, encoding=None):
    encoding = encoding or _GetEncoding()
    return {Encode(k, encoding=encoding): Encode(v, encoding=encoding) for k, v in env.items()}

Encodes all the key value pairs in env in preparation for subprocess.

Args:
env: {str: str}, The environment you are going to pass to subprocess.
encoding: str, The encoding to use or None to use the default.

Returns:
{bytes: bytes}, The environment to pass to subprocess.


def _keyDown(key):

    if key not in keyboardMapping or keyboardMapping[key] is None:
        return

    if type(key) == int:
        fake_input(_display, X.KeyPress, key)
        _display.sync()
        return

    needsShift = pyautogui.isShiftCharacter(key)
    if needsShift:
        fake_input(_display, X.KeyPress, keyboardMapping['shift'])

    fake_input(_display, X.KeyPress, keyboardMapping[key])

    if needsShift:
        fake_input(_display, X.KeyRelease, keyboardMapping['shift'])
    _display.sync()

Performs a keyboard key press without the release. This will put that
key in a held down state.

NOTE: For some reason, this does not seem to cause key repeats like would
happen if a keyboard key was held down on a text field.

Args:
key (str): The key to be pressed down. The valid names are listed in
pyautogui.KEY_NAMES.

Returns:
None


def __init__(self, learning_rate, initial_accumulator_value=0.1, use_locking=False, name='Adagrad'):
    if initial_accumulator_value <= 0.0:
        raise ValueError('initial_accumulator_value must be positive: %s' % initial_accumulator_value)
    super(AdagradOptimizer, self).__init__(use_locking, name)
    self._learning_rate = learning_rate
    self._initial_accumulator_value = initial_accumulator_value
    self._learning_rate_tensor = None

Construct a new Adagrad optimizer.

Args:
learning_rate: A `Tensor` or a floating point value.  The learning rate.
initial_accumulator_value: A floating point value.
Starting value for the accumulators, must be positive.
use_locking: If `True` use locks for update operations.
name: Optional name prefix for the operations created when applying
gradients.  Defaults to "Adagrad".

Raises:
ValueError: If the `initial_accumulator_value` is invalid.


def symbol_top(body_output, targets, model_hparams, vocab_size):
    del targets
    if model_hparams.shared_embedding_and_softmax_weights:
        scope_name = 'shared'
        reuse = tf.AUTO_REUSE
    else:
        scope_name = 'softmax'
        reuse = False
    with tf.variable_scope(scope_name, reuse=reuse):
        body_output_shape = common_layers.shape_list(body_output)
        var = get_weights(model_hparams, vocab_size, body_output_shape[(- 1)])
        if (model_hparams.factored_logits and (model_hparams.mode == tf.estimator.ModeKeys.TRAIN)):
            body_output = tf.expand_dims(body_output, 3)
            return common_layers.FactoredTensor(body_output, var)
        else:
            body_output = tf.reshape(body_output, [(- 1), body_output_shape[(- 1)]])
            logits = tf.matmul(body_output, var, transpose_b=True)
            return tf.reshape(logits, (body_output_shape[:(- 1)] + [1, vocab_size]))

Generate logits.

Args:
body_output: A Tensor with shape
[batch, p0, p1, model_hparams.hidden_size].
targets: Unused.
model_hparams: HParams, model hyperparmeters.
vocab_size: int, vocabulary size.

Returns:
logits: A Tensor with shape  [batch, p0, p1, ?, vocab_size].


def concurrence(state):
    rho = np.array(state)
    if (rho.ndim == 1):
        rho = outer(state)
    if (len(state) != 4):
        raise Exception('Concurrence is only defined for more than two qubits')
    YY = np.fliplr(np.diag([(- 1), 1, 1, (- 1)]))
    A = rho.dot(YY).dot(rho.conj()).dot(YY)
    w = la.eigh(A, eigvals_only=True)
    w = np.sqrt(np.maximum(w, 0))
    return max(0.0, (w[(- 1)] - np.sum(w[0:(- 1)])))

Calculate the concurrence.

Args:
state (np.array): a quantum state (1x4 array) or a density matrix (4x4
array)
Returns:
float: concurrence.
Raises:
Exception: if attempted on more than two qubits.


def create_course_completion(self, user_id, payload):
    return self._post(urljoin(self.enterprise_configuration.degreed_base_url, self.global_degreed_config.completion_status_api_path), payload, self.COMPLETION_PROVIDER_SCOPE)

Send a completion status payload to the Degreed Completion Status endpoint

Args:
user_id: Unused.
payload: JSON encoded object (serialized from DegreedLearnerDataTransmissionAudit)
containing completion status fields per Degreed documentation.

Returns:
A tuple containing the status code and the body of the response.
Raises:
HTTPError: if we received a failure response code from Degreed


def add_nodes(self, nodes):
    if (not isinstance(nodes, list)):
        add_list = [nodes]
    else:
        add_list = nodes
    self.node_list.extend(add_list)

Add a given node or list of nodes to self.node_list.

Args:
node (Node or list[Node]): the node or list of nodes to add
to the graph

Returns: None

Examples:

Adding one node: ::

>>> from blur.markov.node import Node
>>> graph = Graph()
>>> node_1 = Node('One')
>>> graph.add_nodes(node_1)
>>> print([node.value for node in graph.node_list])
['One']

Adding multiple nodes at a time in a list: ::

>>> from blur.markov.node import Node
>>> graph = Graph()
>>> node_1 = Node('One')
>>> node_2 = Node('Two')
>>> graph.add_nodes([node_1, node_2])
>>> print([node.value for node in graph.node_list])
['One', 'Two']


def initialize(self, map_arr, start_point_label="S", end_point_label="G", wall_label="

        np.set_printoptions(threshold=np.inf)

        self.__agent_label = agent_label
        self.__map_arr = map_arr
        self.__start_point_label = start_point_label
        start_arr_tuple = np.where(self.__map_arr == self.__start_point_label)
        x_arr, y_arr = start_arr_tuple
        self.__start_point_tuple = (x_arr[0], y_arr[0])
        end_arr_tuple = np.where(self.__map_arr == self.__end_point_label)
        x_arr, y_arr = end_arr_tuple
        self.__end_point_tuple = (x_arr[0], y_arr[0])
        self.__wall_label = wall_label

        for x in range(self.__map_arr.shape[1]):
            for y in range(self.__map_arr.shape[0]):
                if (x, y) == self.__start_point_tuple or (x, y) == self.__end_point_tuple:
                    continue
                arr_value = self.__map_arr[y][x]
                if arr_value == self.__wall_label:
                    continue

                self.save_r_df((x, y), float(arr_value))

Initialize map of maze and setup reward value.

Args:
map_arr:              Map. the 2d- `np.ndarray`.
start_point_label:    Label of start point.
end_point_label:      Label of end point.
wall_label:           Label of wall.
agent_label:          Label of agent.


def expand_value_set_url_using_service(self, value_set_url: str, terminology_service_url: str) -> value_set_pb2.ValueSet:
    value_set_url, value_set_version = url_utils.parse_url_version(value_set_url)
    auth = self.auth_per_terminology_server.get(terminology_service_url)
    return self._expand_value_set_url_using_service(value_set_url=value_set_url, value_set_version=value_set_version, terminology_service_url=terminology_service_url, auth=auth)

Expands the value set using the requested terminology service.

Requests an expansion of the value set from the terminology
server at `terminology_service_url` for the given URL and version if present
on the URL.

If the terminology service requires credentials to access,
`terminology_service_url` must have an entry in the
`auth_per_terminology_server` given to this class' constructor.

Retrieves the current definition of the value set from the terminology
service as well as its expansion.

Args:
value_set_url: The url of the value set to expand.
terminology_service_url: The url of the terminology service to use when
expanding `value_set_url`.

Returns:
The current definition of the value set from the server with its expanded
codes present.


async def teardown_client(self, client_id):
    client_info = self._client_info(client_id)
    self.adapter.remove_monitor(client_info['monitor'])
    conns = client_info['connections']
    for (conn_string, conn_id) in conns.items():
        try:
            self._logger.debug('Disconnecting client %s from conn %s at teardown', client_id, conn_string)
            (await self.adapter.disconnect(conn_id))
        except:
            self._logger.exception('Error disconnecting device during teardown_client: conn_string=%s', conn_string)
    del self._clients[client_id]

Release all resources held by a client.

This method must be called and awaited whenever a client is
disconnected.  It ensures that all of the client's resources are
properly released and any devices they have connected to are
disconnected cleanly.

Args:
client_id (str): The client that we should tear down.

Raises:
ArgumentError: The client_id is unknown.


def CreateAd(client, opener, ad_group_id):
    ad_group_ad_service = client.GetService('AdGroupAdService', 'v201809')
    media_service = client.GetService('MediaService', 'v201809')
    marketing_image_id = _CreateImage(media_service, opener, 'https:
    logo_image_id = _CreateImage(media_service, opener, 'https:
    ad = {'xsi_type': 'ResponsiveDisplayAd', 'marketingImage': {'xsi_type': 'Image', 'mediaId': marketing_image_id}, 'shortHeadline': 'Travel', 'longHeadline': 'Travel the World', 'description': 'Take to the air!', 'businessName': 'Interplanetary Cruises', 'finalUrls': ['http:
    ad_group_ad = {'ad': ad, 'adGroupId': ad_group_id}
    operations = [{'operation': 'ADD', 'operand': ad_group_ad}]
    return ad_group_ad_service.mutate(operations)['value'][0]

Creates a ResponsiveDisplayAd.

Args:
client: an AdWordsClient instance.
opener: an OpenerDirector instance.
ad_group_id: an int ad group ID.

Returns:
The ad group ad that was successfully created.


def build_aspect_ratio_mask(aspect_ratios: List[List[Tuple[int, int]]], max_image_tiles: int) -> np.ndarray:
    batch_size = len(aspect_ratios)
    max_num_images = max([len(row) for row in aspect_ratios])
    aspect_ratio_mask = np.zeros((batch_size, max_num_images, max_image_tiles), dtype=np.int64)
    aspect_ratio_mask[:, :, 0] = 1
    for i, sample_aspect_ratios in enumerate(aspect_ratios):
        for j, (num_tiles_w, num_tiles_h) in enumerate(sample_aspect_ratios):
            aspect_ratio_mask[i, j, :num_tiles_w * num_tiles_h] = 1
    return aspect_ratio_mask

Builds a mask for the aspect ratios of the images.

Args:
aspect_ratios (`List[List[Tuple[int, int]]]`):
A list of lists containing aspect ratios for each image in the batch.
Each aspect ratio is represented as a tuple of (width, height) in terms of number of tiles.
max_image_tiles (`int`):
The maximum number of tiles any image can be split into.

Returns:
`np.ndarray`: A 3D numpy array of shape (batch_size, max_num_images, max_image_tiles).
The mask contains 1s for valid tiles and 0s for padding.


def simplify_countryname(cls, country):
    countryupper = country.upper()
    words = get_words_in_sentence(countryupper)
    index = countryupper.find(',')
    if (index != (- 1)):
        countryupper = countryupper[:index]
    index = countryupper.find(':')
    if (index != (- 1)):
        countryupper = countryupper[:index]
    regex = re.compile('\\(.+?\\)')
    countryupper = regex.sub('', countryupper)
    remove = copy.deepcopy(cls.simplifications)
    for (simplification1, simplification2) in cls.abbreviations.items():
        countryupper = countryupper.replace(simplification1, '')
        remove.append(simplification2)
    for (simplification1, simplifications) in cls.multiple_abbreviations.items():
        countryupper = countryupper.replace(simplification1, '')
        for simplification2 in simplifications:
            remove.append(simplification2)
    remove = '|'.join(remove)
    regex = re.compile((('\\b(' + remove) + ')\\b'), flags=re.IGNORECASE)
    countryupper = regex.sub('', countryupper)
    countryupper = countryupper.strip()
    countryupper_words = get_words_in_sentence(countryupper)
    if (len(countryupper_words) > 1):
        countryupper = countryupper_words[0]
    if countryupper:
        words.remove(countryupper)
    return (countryupper, words)

Simplifies country name by removing descriptive text eg. DEMOCRATIC, REPUBLIC OF etc.

Args:
country (str): Country name to simplify

Returns:
Tuple[str, List[str]]: Uppercase simplified country name and list of removed words


def parse_verilog_file(fname):

  with open(fname, 'rt') as fh:
    text = fh.read()
  return parse_verilog(text)

Parse a named Verilog file

Args:
fname (str): File to parse.
Returns:
List of parsed objects.


def load_readers(filenames=None, reader=None, reader_kwargs=None, ppp_config_dir=None):
    reader_instances = {}
    reader_kwargs = (reader_kwargs or {})
    reader_kwargs_without_filter = reader_kwargs.copy()
    reader_kwargs_without_filter.pop('filter_parameters', None)
    if (ppp_config_dir is None):
        ppp_config_dir = get_environ_config_dir()
    if ((not filenames) and (not reader)):
        return {}
    elif (reader and (filenames is not None) and (not filenames)):
        raise ValueError("'filenames' was provided but is empty.")
    elif (not filenames):
        LOG.warning("'filenames' required to create readers and load data")
        return {}
    elif ((reader is None) and isinstance(filenames, dict)):
        reader = list(filenames.keys())
        remaining_filenames = set((f for fl in filenames.values() for f in fl))
    elif (reader and isinstance(filenames, dict)):
        filenames = filenames[reader]
        remaining_filenames = set((filenames or []))
    else:
        remaining_filenames = set((filenames or []))
    for (idx, reader_configs) in enumerate(configs_for_reader(reader, ppp_config_dir)):
        if isinstance(filenames, dict):
            readers_files = set(filenames[reader[idx]])
        else:
            readers_files = remaining_filenames
        try:
            reader_instance = load_reader(reader_configs, **reader_kwargs)
        except (KeyError, IOError, yaml.YAMLError) as err:
            LOG.info('Cannot use %s', str(reader_configs))
            LOG.debug(str(err))
            continue
        if readers_files:
            loadables = reader_instance.select_files_from_pathnames(readers_files)
        if loadables:
            reader_instance.create_filehandlers(loadables, fh_kwargs=reader_kwargs_without_filter)
            reader_instances[reader_instance.name] = reader_instance
            remaining_filenames -= set(loadables)
        if (not remaining_filenames):
            break
    if remaining_filenames:
        LOG.warning("Don't know how to open the following files: {}".format(str(remaining_filenames)))
    if (not reader_instances):
        raise ValueError('No supported files found')
    elif (not any((list(r.available_dataset_ids) for r in reader_instances.values()))):
        raise ValueError('No dataset could be loaded. Either missing requirements (such as Epilog, Prolog) or none of the provided files match the filter parameters.')
    return reader_instances

Create specified readers and assign files to them.

Args:
filenames (iterable or dict): A sequence of files that will be used to load data from. A ``dict`` object
should map reader names to a list of filenames for that reader.
reader (str or list): The name of the reader to use for loading the data or a list of names.
reader_kwargs (dict): Keyword arguments to pass to specific reader instances.
ppp_config_dir (str): The directory containing the configuration files for satpy.

Returns: Dictionary mapping reader name to reader instance


def _find_root_dir(path, spor_dir):
    start_path = pathlib.Path((os.getcwd() if (path is None) else path))
    paths = ([start_path] + list(start_path.parents))
    for path in paths:
        data_dir = (path / spor_dir)
        if (data_dir.exists() and data_dir.is_dir()):
            return path
    raise ValueError('No spor repository found')

Search for a spor repo containing `path`.

This searches for `spor_dir` in directories dominating `path`. If a
directory containing `spor_dir` is found, then that directory is returned
as a `pathlib.Path`.

Returns: The dominating directory containing `spor_dir` as a
`pathlib.Path`.

Raises:
ValueError: No repository is found.


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

Get UNIX Epoch time in seconds on the FileSystem.

Args:
path: string path of file.

Returns: float UNIX Epoch time

Raises:
``BeamIOError``: if path doesn't exist.


def log_histogram(self, name, value, step=None):
    if isinstance(value, six.string_types):
        raise TypeError('"value" should be a number, got {}'.format(type(value)))
    self._check_step(step)
    tf_name = self._ensure_tf_name(name)
    summary = self._histogram_summary(tf_name, value, step=step)
    self._log_summary(tf_name, summary, value, step=step)

Log a histogram for given name on given step.

Args:
name (str): name of the variable (it will be converted to a valid
tensorflow summary name).
value (tuple or list): either list of numbers
to be summarized as a histogram, or a tuple of bin_edges and
bincounts that directly define a histogram.
step (int): non-negative integer used for visualization


def map_to_pdf(map_source, zoom, x, y, width, height):

    map_source = app.config["mapsources"][map_source]
    pdf_file = print_map(map_source, x=float(x), y=float(y),
                         zoom=int(zoom), width=float(width), height=float(height), format='pdf')
    return send_file(pdf_file,
                     attachment_filename="map.pdf",
                     as_attachment=True)

Generate a PDF at the given position.

Args:
map_source (str): id of the map source to print.
zoom (int): zoom-level to print
x (float): Center of the Map in mercator projection (EPSG:4326), x-coordinate
y (float): Center of the Map in mercator projection (EPSG:4326), y-coordinate
width (float): width of the pdf in mm
height (float): height of the pdf in mm

Returns:


def maybe(cls, val: Optional[T]) -> 'Option[T]':

        return cast('Option[T]', NONE) if val is None else cls.Some(val)

Shortcut method to return ``Some`` or :py:data:`NONE` based on ``val``.

Args:
val: Some value.

Returns:
``Some(val)`` if the ``val`` is not None, otherwise :py:data:`NONE`.

Examples:
>>> Option.maybe(0)
Some(0)
>>> Option.maybe(None)
NONE


def compress_encoder_2d(x, hparams, name=None):

  return compress_encoder(
      x,
      hparams,
      strides=(2, 2),
      kernel_size=(hparams.kernel_size, hparams.kernel_size),
      name=name)

Encoder that compresses 2-D inputs by 2**num_compress_steps.

Args:
x: Tensor of shape [batch, height, width, channels].
hparams: HParams.
name: string, variable scope.

Returns:
Tensor of shape [batch, latent_length, hparams.hidden_size], where
latent_length is
hparams.num_latents * (height*width) / 2**(hparams.num_compress_steps).


def write_to_hdf5(self, filename_out, *args, **kwargs):

        t0 = time.time()

        self.__update_header()

        if self.container.isheavy():
            self.__write_to_hdf5_heavy(filename_out)
        else:
            self.__write_to_hdf5_light(filename_out)

        t1 = time.time()
        logger.info('Conversion time: %2.2fsec' % (t1- t0))

Write data to HDF5 file.
It check the file size then decides how to write the file.

Args:
filename_out (str): Name of output file


def keep_doc_examples_only(content: str) -> str:
    splits = content.split('```')
    content = '```' + '```'.join(splits[1::2]) + '```'
    lines_to_keep = []
    for line in content.split('\n'):
        line = re.sub('
        if len(line) != 0 and (not line.isspace()):
            lines_to_keep.append(line)
    return '\n'.join(lines_to_keep)

Remove everything from the code content except the doc examples (used to determined if a diff should trigger doc
tests or not).

Args:
content (`str`): The code to clean

Returns:
`str`: The cleaned code.


def subscriber(address,topics,callback,message_type):

    return Subscriber(address,topics,callback,message_type)

Creates a subscriber binding to the given address and
subscribe the given topics.
The callback is invoked for every message received.

Args:
- address: the address to bind the PUB socket to.
- topics: the topics to subscribe
- callback: the callback to invoke for every message. Must accept 2 variables - topic and message
- message_type: the type of message to receive


def set_dataset_year_range(self, dataset_year, dataset_end_year=None):

        if isinstance(dataset_year, int):
            dataset_date = '01/01/%d' % dataset_year
        elif isinstance(dataset_year, str):
            dataset_date = '01/01/%s' % dataset_year
        else:
            raise hdx.data.hdxobject.HDXError('dataset_year has type %s which is not supported!' % type(dataset_year).__name__)
        if dataset_end_year is None:
            dataset_end_year = dataset_year
        if isinstance(dataset_end_year, int):
            dataset_end_date = '31/12/%d' % dataset_end_year
        elif isinstance(dataset_end_year, str):
            dataset_end_date = '31/12/%s' % dataset_end_year
        else:
            raise hdx.data.hdxobject.HDXError('dataset_end_year has type %s which is not supported!' % type(dataset_end_year).__name__)
        self.set_dataset_date(dataset_date, dataset_end_date)

Set dataset date as a range from year or start and end year.

Args:
dataset_year (Union[str, int]): Dataset year given as string or int
dataset_end_year (Optional[Union[str, int]]): Dataset end year given as string or int

Returns:
None


def dot(matrix, vector):

    matrix_weld_type = None
    vector_weld_type = None

    if isinstance(matrix, LazyOpResult):
        matrix_weld_type = matrix.weld_type
        matrix = matrix.expr
    elif isinstance(matrix, np.ndarray):
        matrix_weld_type = numpy_weld_impl.numpy_to_weld_type_mapping[
            str(matrix.dtype)]

    if isinstance(vector, LazyOpResult):
        vector_weld_type = vector.weld_type
        vector = vector.expr
    elif isinstance(vector, np.ndarray):
        vector_weld_type = numpy_weld_impl.numpy_to_weld_type_mapping[
            str(vector.dtype)]

    return NumpyArrayWeld(
        numpy_weld_impl.dot(
            matrix,
            vector,
            matrix_weld_type,
            vector_weld_type),
        WeldDouble())

Computes the dot product between a matrix and a vector.
TODO: Make this more generic

Args:
matrix (TYPE): Description
vector (TYPE): Description


def trailing_stop_loss(self, accountID, **kwargs):

        return self.create(
            accountID,
            order=TrailingStopLossOrderRequest(**kwargs)
        )

Shortcut to create a Trailing Stop Loss Order in an Account

Args:
accountID : The ID of the Account
kwargs : The arguments to create a TrailingStopLossOrderRequest

Returns:
v20.response.Response containing the results from submitting
the request


def CrowdsaleRegister(self, wallet, register_addresses, from_addr=None):
    invoke_args = [self.ScriptHash.ToString(), 'crowdsale_register', [PromptUtils.parse_param(p, wallet) for p in register_addresses]]
    (tx, fee, results, num_ops, engine_success) = TestInvokeContract(wallet, invoke_args, None, True, from_addr)
    return (tx, fee, results)

Register for a crowd sale.

Args:
wallet (neo.Wallets.Wallet): a wallet instance.
register_addresses (list): list of public addresses to register for the sale.

Returns:
tuple:
InvocationTransaction: the transaction.
int: the transaction fee.
list: the neo VM evaluation stack results.


def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
    if token_ids_1 is None:
        return self.prefix_tokens + token_ids_0 + self.suffix_tokens
    return self.prefix_tokens + token_ids_0 + token_ids_1 + self.suffix_tokens

Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. An NLLB sequence has the following format, where `X` represents the sequence:

- `input_ids` (for encoder) `X [eos, src_lang_code]`
- `decoder_input_ids`: (for decoder) `X [eos, tgt_lang_code]`

BOS is never used. Pairs of sequences are not the expected use case, but they will be handled without a
separator.

Args:
token_ids_0 (`List[int]`):
List of IDs to which the special tokens will be added.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.


def decode(self, ids, strip_extraneous=False):
    if strip_extraneous:
        ids = strip_ids(ids, list(range((self._num_reserved_ids or 0))))
    return ' '.join(self.decode_list(ids))

Transform a sequence of int ids into a human-readable string.

EOS is not expected in ids.

Args:
ids: list of integers to be converted.
strip_extraneous: bool, whether to strip off extraneous tokens
(EOS and PAD).

Returns:
s: human-readable string.


def from_dict(event_dict):
    return CallbackEvent(callback_id=event_dict['callbackId'], name=event_dict['name'], creation_time=event_dict['time'], data=event_dict['data'])

Creates a CallbackEvent object from a dictionary.

Args:
event_dict: dict, a dictionary representing an event.

Returns:
A CallbackEvent object.


def entry_dict_from_list(all_slab_entries):
    entry_dict = {}
    for entry in all_slab_entries:
        hkl = tuple(entry.miller_index)
        if (hkl not in entry_dict.keys()):
            entry_dict[hkl] = {}
        if entry.clean_entry:
            clean = entry.clean_entry
        else:
            clean = entry
        if (clean not in entry_dict[hkl].keys()):
            entry_dict[hkl][clean] = []
        if entry.adsorbates:
            entry_dict[hkl][clean].append(entry)
    return entry_dict

Converts a list of SlabEntry to an appropriate dictionary. It is
assumed that if there is no adsorbate, then it is a clean SlabEntry
and that adsorbed SlabEntry has the clean_entry parameter set.

Args:
all_slab_entries (list): List of SlabEntry objects

Returns:
(dict): Dictionary of SlabEntry with the Miller index as the main
key to a dictionary with a clean SlabEntry as the key to a
list of adsorbed SlabEntry.


def _build_key_wrapping_specification(self, value):

        if value is None:
            return None
        if not isinstance(value, dict):
            raise TypeError("Key wrapping specification must be a dictionary.")

        encryption_key_info = self._build_encryption_key_information(
            value.get('encryption_key_information')
        )
        mac_signature_key_info = self._build_mac_signature_key_information(
            value.get('mac_signature_key_information')
        )

        key_wrapping_specification = cobjects.KeyWrappingSpecification(
            wrapping_method=value.get('wrapping_method'),
            encryption_key_information=encryption_key_info,
            mac_signature_key_information=mac_signature_key_info,
            attribute_names=value.get('attribute_names'),
            encoding_option=value.get('encoding_option')
        )
        return key_wrapping_specification

Build a KeyWrappingSpecification struct from a dictionary.

Args:
value (dict): A dictionary containing the key/value pairs for a
KeyWrappingSpecification struct.

Returns:
KeyWrappingSpecification: a KeyWrappingSpecification struct

Raises:
TypeError: if the input argument is invalid


def _DiscoverElementTypeFromLocalname(self, type_localname):
    elem_type = None
    last_exception = None
    for ns_prefix in self.zeep_client.wsdl.types.prefix_map.values():
        try:
            elem_type = self.zeep_client.get_type(('{%s}%s' % (ns_prefix, type_localname)))
        except zeep.exceptions.LookupError as e:
            last_exception = e
            continue
        break
    if (not elem_type):
        raise last_exception
    return elem_type

Searches all namespaces for a type by name.

Args:
type_localname: The name of the type.

Returns:
A fully qualified SOAP type with the specified name.

Raises:
A zeep.exceptions.LookupError if the type cannot be found in any
namespace.


def decorate(self, record):

        color = 'gray'
        if record.levelno == logging.WARNING:
            color = 'yellow'
        if record.levelno == logging.INFO:
            color = 'green'
        if record.levelno == logging.DEBUG:
            color = 'gray'
        if record.levelno >= logging.ERROR:
            color = 'red'

        notify = False
        if record.levelno >= logging.ERROR:
            nofiy = True

        payload = {
            'color': color,
            'notify': notify,
            'message_format': 'text'
        }

        return payload

Build up HipChat specific values for log record

Args:
record (:obj:`logging.record`): log message object

Returns:
dict: params for POST request


def call(self, inputs, states):
    raise NotImplementedError('Abstract method')

The function that contains the logic for one RNN step calculation.

Args:
inputs: the input tensor, which is a slide from the overall RNN input by
the time dimension (usually the second dimension).
states: the state tensor from previous step, which has the same shape
as `(batch, state_size)`. In the case of timestep 0, it will be the
initial state user specified, or zero filled tensor otherwise.

Returns:
A tuple of two tensors:
1. output tensor for the current timestep, with size `output_size`.
2. state tensor for next step, which has the shape of `state_size`.


def factor_hatch(field_name, patterns, factors, start=0, end=None):
    return field(field_name, CategoricalPatternMapper(patterns=patterns, factors=factors, start=start, end=end))

Create a ``DataSpec`` dict that applies a client-side
``CategoricalPatternMapper`` transformation to a ``ColumnDataSource``
column.

Args:
field_name (str) : a field name to configure ``DataSpec`` with

patterns (seq[string]) : a list of hatch patterns to use to map to

factors (seq) : a sequences of categorical factors corresponding to
the palette

start (int, optional) : a start slice index to apply when the column
data has factors with multiple levels. (default: 0)

end (int, optional) : an end slice index to apply when the column
data has factors with multiple levels. (default: None)

Returns:
dict

Added in version 1.1.1


def check_schema_transforms_match(schema, inverted_features):

  num_target_transforms = 0

  for col_schema in schema:
    col_name = col_schema['name']
    col_type = col_schema['type'].lower()

    if col_name in inverted_features:
      for transform in inverted_features[col_name]:
        transform_name = transform['transform']
        if transform_name == constant.TARGET_TRANSFORM:
          num_target_transforms += 1
          continue

        elif col_type in constant.NUMERIC_SCHEMA:
          if transform_name not in constant.NUMERIC_TRANSFORMS:
            raise ValueError(
                'Transform %s not supported by schema %s' % (transform_name, col_type))
        elif col_type == constant.STRING_SCHEMA:
          if (transform_name not in constant.CATEGORICAL_TRANSFORMS + constant.TEXT_TRANSFORMS and
             transform_name != constant.IMAGE_TRANSFORM):
            raise ValueError(
                'Transform %s not supported by schema %s' % (transform_name, col_type))
        else:
          raise ValueError('Unsupported schema type %s' % col_type)

    if col_name in inverted_features:
      transform_set = {x['transform'] for x in inverted_features[col_name]}
      if 1 != sum([transform_set.issubset(set(constant.NUMERIC_TRANSFORMS)),
                   transform_set.issubset(set(constant.CATEGORICAL_TRANSFORMS)),
                   transform_set.issubset(set(constant.TEXT_TRANSFORMS)),
                   transform_set.issubset(set([constant.IMAGE_TRANSFORM])),
                   transform_set.issubset(set([constant.TARGET_TRANSFORM]))]):
        message =  % (str(constant.TEXT_TRANSFORMS),
                 str(constant.CATEGORICAL_TRANSFORMS),
                 str(constant.NUMERIC_TRANSFORMS),
                 constant.IMAGE_TRANSFORM,
                 constant.TARGET_TRANSFORM,
                 col_name,
                 str(transform_set))
        raise ValueError(message)

  if num_target_transforms != 1:
    raise ValueError('Must have exactly one target transform')

Checks that the transform and schema do not conflict.

Args:
schema: schema list
inverted_features: inverted_features dict

Raises:
ValueError if transform cannot be applied given schema type.


def get_appliance_by_name(self, appliance_name):
    appliances = self.get_appliances()
    if appliances:
        for appliance in appliances:
            if (appliance['name'] == appliance_name):
                return appliance
    return None

Gets the particular Image Streamer resource based on its name.

Args:
appliance_name:
The Image Streamer resource name.

Returns:
dict: Image Streamer resource.


def register_frame_to_skip(method: Union[Callable[..., Any], List[Callable[..., Any]]]) -> bool:
    register_fn = getattr(_DEFAULT_LOGGER.__class__, 'register_frame_to_skip', None)
    if register_fn is None:
        return False
    methods = [method] if not isinstance(method, list) else method
    for m in methods:
        register_fn(inspect.getsourcefile(m), m.__name__)
    return True

Skips the source of the given method when logging.

Args:
method: The method to skip. Can be a single method or a list of methods.

Returns:
True if the method is registered to skip.

Raises:
TypeError: The source file of the method cannot be inspected.


def CmdRegister(self, challenge_param, app_param):
    self.logger.debug('CmdRegister')
    if ((len(challenge_param) != 32) or (len(app_param) != 32)):
        raise errors.InvalidRequestError()
    body = bytearray((challenge_param + app_param))
    response = self.InternalSendApdu(apdu.CommandApdu(0, apdu.CMD_REGISTER, 3, 0, body))
    response.CheckSuccessOrRaise()
    return response.body

Register security key.

Ask the security key to register with a particular origin & client.

Args:
challenge_param: Arbitrary 32 byte challenge string.
app_param: Arbitrary 32 byte applciation parameter.

Returns:
A binary structure containing the key handle, attestation, and a
signature over that by the attestation key.  The precise format
is dictated by the FIDO U2F specs.

Raises:
TUPRequiredError: A Test of User Precense is required to proceed.
ApduError: Something went wrong on the device.


def __init__(self, location, field_type):

        super(GlobalContextField, self).__init__(location, field_type)
        self.location = location
        self.field_type = field_type
        self.validate()

Construct a new GlobalContextField object that references a field at a given location.

Args:
location: Location, specifying where the field was declared.

Returns:
new GlobalContextField object


def _Check3DImage(image, require_static=True):
    try:
        image_shape = image.get_shape().with_rank(3)
    except ValueError:
        raise ValueError("'image' (shape %s) must be three-dimensional." % image.shape)
    if require_static and (not image_shape.is_fully_defined()):
        raise ValueError("'image' (shape %s) must be fully defined." % image_shape)
    if any((x == 0 for x in image_shape)):
        raise ValueError("all dims of 'image.shape' must be > 0: %s" % image_shape)
    if not image_shape.is_fully_defined():
        return [check_ops.assert_positive(array_ops.shape(image), ["all dims of 'image.shape' must be > 0."])]
    else:
        return []

Assert that we are working with a properly shaped image.

Args:
image: 3-D Tensor of shape [height, width, channels]
require_static: If `True`, requires that all dimensions of `image` are known
and non-zero.

Raises:
ValueError: if `image.shape` is not a 3-vector.

Returns:
An empty list, if `image` has fully defined dimensions. Otherwise, a list
containing an assert op is returned.


def on_moved(self, event):
    if (not self._event_error):
        pathtools_options = {'included_patterns': self.patterns, 'excluded_patterns': self.ignore_patterns, 'case_sensitive': self.case_sensitive}
        if match_path(event.dest_path, **pathtools_options):
            self.logger.info(u'Change detected from a move on: %s', event.dest_path)
            self.compile_dependencies(event.dest_path)

Called when a file or a directory is moved or renamed.

Many editors don't directly change a file, instead they make a
transitional file like ``*.part`` then move it to the final filename.

Args:
event: Watchdog event, either ``watchdog.events.DirMovedEvent`` or
``watchdog.events.FileModifiedEvent``.


def add_tensor_filter(self, filter_name, tensor_filter):
    self._tensor_filters[filter_name] = tensor_filter

Add a tensor filter.

Args:
filter_name: (`str`) name of the filter.
tensor_filter: (`callable`) the filter callable. See the doc string of
`DebugDumpDir.find()` for more details about its signature.


def generate_key(action, path_or_id, settings=None, default=" (default)"):

    settings = " {}".format(str(sorted(settings.items()))) if settings else default
    return "{}: {}{}".format(action.upper(), path_or_id, settings)

generate_key: generate key used for caching
Args:
action (str): how video is being processed (e.g. COMPRESSED or DOWNLOADED)
path_or_id (str): path to video or youtube_id
settings (dict): settings for compression or downloading passed in by user
default (str): if settings are None, default to this extension (avoid overwriting keys)
Returns: filename


def predict_proba(self, a, b, nb_runs=6, nb_jobs=None, gpu=None, idx=0, verbose=None, ttest_threshold=0.01, nb_max_runs=16, train_epochs=1000, test_epochs=1000):
    (Nb_jobs, verbose, gpu) = SETTINGS.get_default(('nb_jobs', nb_jobs), ('verbose', verbose), ('gpu', gpu))
    x = np.stack([a.ravel(), b.ravel()], 1)
    ttest_criterion = TTestCriterion(max_iter=nb_max_runs, runs_per_iter=nb_runs, threshold=ttest_threshold)
    AB = []
    BA = []
    while ttest_criterion.loop(AB, BA):
        if (nb_jobs != 1):
            result_pair = Parallel(n_jobs=nb_jobs)((delayed(GNN_instance)(x, idx=idx, device=('cuda:{}'.format((run % gpu)) if gpu else 'cpu'), verbose=verbose, train_epochs=train_epochs, test_epochs=test_epochs) for run in range(ttest_criterion.iter, (ttest_criterion.iter + nb_runs))))
        else:
            result_pair = [GNN_instance(x, idx=idx, device=('cuda:0' if gpu else 'cpu'), verbose=verbose, train_epochs=train_epochs, test_epochs=test_epochs) for run in range(ttest_criterion.iter, (ttest_criterion.iter + nb_runs))]
        AB.extend([runpair[0] for runpair in result_pair])
        BA.extend([runpair[1] for runpair in result_pair])
    if verbose:
        print('P-value after {} runs : {}'.format(ttest_criterion.iter, ttest_criterion.p_value))
    score_AB = np.mean(AB)
    score_BA = np.mean(BA)
    return ((score_BA - score_AB) / (score_BA + score_AB))

Run multiple times GNN to estimate the causal direction.

Args:
a (np.ndarray): Variable 1
b (np.ndarray): Variable 2
nb_runs (int): number of runs to execute per batch (before testing for significance with t-test).
nb_jobs (int): number of runs to execute in parallel. (Initialized with ``cdt.SETTINGS.NB_JOBS``)
gpu (bool): use gpu (Initialized with ``cdt.SETTINGS.GPU``)
idx (int): (optional) index of the pair, for printing purposes
verbose (bool): verbosity (Initialized with ``cdt.SETTINGS.verbose``)
ttest_threshold (float): threshold to stop the boostraps before ``nb_max_runs`` if the difference is significant
nb_max_runs (int): Max number of bootstraps
train_epochs (int): Number of epochs during which the model is going to be trained
test_epochs (int): Number of epochs during which the model is going to be tested

Returns:
float: Causal score of the pair (Value : 1 if a->b and -1 if b->a)


def compute_sub_structure(self, sub_structure, tol=0.001):
    total_energy_matrix = self.total_energy_matrix.copy()

    def find_match(site):
        for test_site in sub_structure:
            frac_diff = (abs((np.array(site.frac_coords) - np.array(test_site.frac_coords))) % 1)
            frac_diff = [((abs(a) < tol) or (abs(a) > (1 - tol))) for a in frac_diff]
            if all(frac_diff):
                return test_site
        return None
    matches = []
    for (i, site) in enumerate(self._s):
        matching_site = find_match(site)
        if matching_site:
            new_charge = compute_average_oxidation_state(matching_site)
            old_charge = self._oxi_states[i]
            scaling_factor = (new_charge / old_charge)
            matches.append(matching_site)
        else:
            scaling_factor = 0
        total_energy_matrix[(i, :)] *= scaling_factor
        total_energy_matrix[(:, i)] *= scaling_factor
    if (len(matches) != len(sub_structure)):
        output = ['Missing sites.']
        for site in sub_structure:
            if (site not in matches):
                output.append('unmatched = {}'.format(site))
        raise ValueError('\n'.join(output))
    return sum(sum(total_energy_matrix))

Gives total ewald energy for an sub structure in the same
lattice. The sub_structure must be a subset of the original
structure, with possible different charges.

Args:
substructure (Structure): Substructure to compute Ewald sum for.
tol (float): Tolerance for site matching in fractional coordinates.

Returns:
Ewald sum of substructure.


def from_conv_part_data(conv_part_data, self_user_id):

        user_id = UserID(chat_id=conv_part_data.id.chat_id,
                         gaia_id=conv_part_data.id.gaia_id)
        return User(user_id, conv_part_data.fallback_name, None, None, [],
                    (self_user_id == user_id) or (self_user_id is None))

Construct user from ``ConversationParticipantData`` message.

Args:
conv_part_id: ``ConversationParticipantData`` message.
self_user_id (~hangups.user.UserID or None): The ID of the current
user. If ``None``, assume ``conv_part_id`` is the current user.

Returns:
:class:`~hangups.user.User` object.


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 serialize_dtype(o):

    if len(o) == 0:
        return dict(
            _type='np.dtype',
            descr=str(o))
    return dict(
        _type='np.dtype',
        descr=o.descr)

Serializes a :obj:`numpy.dtype`.

Args:
o (:obj:`numpy.dtype`): :obj:`dtype` to be serialized.

Returns:
A dictionary that can be passed to :obj:`json.dumps`.


def post(self, path, body, headers=None):
    response = requests.post(self._url_for(path), data=json.dumps(body), headers=self._headers(headers))
    self._handle_errors(response)
    return response

Perform a POST request, providing a body, which will be JSON-encoded.

Args:
path (str): A path that gets appended to ``base_url``.
body (dict): Dictionary that will be JSON-encoded and sent as the body.

Example:
api_client.post('/users', body={'name': 'Billy Jean'})

Returns:
A requests ``Response`` object.