def wait(self, timeout=None):

    if self._future:
      try:

        self._future.exception(timeout)
      except concurrent.futures.TimeoutError:
        self._timeout()
      self._refresh_state()
    else:

      while not self.is_complete:
        if timeout is not None:
          if timeout <= 0:
            self._timeout()
          timeout -= Job._POLL_INTERVAL_SECONDS
        time.sleep(Job._POLL_INTERVAL_SECONDS)
    return self

Wait for the job to complete, or a timeout to happen.

Args:
timeout: how long to wait before giving up (in seconds); default None which means no timeout.

Returns:
The Job


def profile(self, num):
    baseuri = (self._BASE_URI + 'company/{}'.format(num))
    res = self.session.get(baseuri)
    self.handle_http_error(res)
    return res

Search for company profile by company number.

Args:
num (str): Company number to search on.


def heightmap_get_normal(
    hm: np.ndarray, x: float, y: float, waterLevel: float
) -> Tuple[float, float, float]:

    cn = ffi.new("float[3]")
    lib.TCOD_heightmap_get_normal(_heightmap_cdata(hm), x, y, cn, waterLevel)
    return tuple(cn)

Return the map normal at given coordinates.

Args:
hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
x (float): The x coordinate.
y (float): The y coordinate.
waterLevel (float): The heightmap is considered flat below this value.

Returns:
Tuple[float, float, float]: An (x, y, z) vector normal.


def CreateSmartShoppingAdGroup(client, campaign_id):
    ad_group_service = client.GetService('AdGroupService', version='v201809')
    ad_group = {'campaignId': campaign_id, 'name': ('Smart Shopping ad group
    adgroup_operations = {'operator': 'ADD', 'operand': ad_group}
    ad_group = ad_group_service.mutate(adgroup_operations)['value'][0]
    ad_group_id = ad_group['id']
    print(('AdGroup with name "%s" and ID "%s" was added.' % (ad_group['name'], ad_group_id)))
    return ad_group_id

Adds a new Smart Shopping ad group.

Args:
client: an AdWordsClient instance.
campaign_id: the str ID of a Smart Shopping campaign.
Returns:
An ad group ID.


def push_doc(self, document):

        msg = self._protocol.create('PUSH-DOC', document)
        reply = self._send_message_wait_for_reply(msg)
        if reply is None:
            raise RuntimeError("Connection to server was lost")
        elif reply.header['msgtype'] == 'ERROR':
            raise RuntimeError("Failed to push document: " + reply.content['text'])
        else:
            return reply

Push a document to the server, overwriting any existing server-side doc.

Args:
document : (Document)
A Document to push to the server

Returns:
The server reply


def set_cache_policy(self, func):
    if (func is None):
        func = self.default_cache_policy
    elif isinstance(func, bool):
        func = (lambda unused_key, flag=func: flag)
    self._cache_policy = func

Set the context cache policy function.

Args:
func: A function that accepts a Key instance as argument and returns
a bool indicating if it should be cached.  May be None.


def cumulative_probabilities( self ):

        partition_function = np.sum( self.p )
        return np.cumsum( self.p ) / partition_function

Cumulative sum of the relative probabilities for all possible jumps.

Args:
None

Returns:
(np.array): Cumulative sum of relative jump probabilities.


def check_prerequisites(
        prerequisites,
        checker,
        msg_tmpl='Prerequisites "{}" are required in method "{}" but not '
        'found, please install them first.'):

    def wrap(func):

        @functools.wraps(func)
        def wrapped_func(*args, **kwargs):
            requirements = [prerequisites] if isinstance(
                prerequisites, str) else prerequisites
            missing = []
            for item in requirements:
                if not checker(item):
                    missing.append(item)
            if missing:
                print(msg_tmpl.format(', '.join(missing), func.__name__))
                raise RuntimeError('Prerequisites not meet.')
            else:
                return func(*args, **kwargs)

        return wrapped_func

    return wrap

A decorator factory to check if prerequisites are satisfied.

Args:
prerequisites (str of list[str]): Prerequisites to be checked.
checker (callable): The checker method that returns True if a
prerequisite is meet, False otherwise.
msg_tmpl (str): The message template with two variables.

Returns:
decorator: A specific decorator.


def combine(args, part=None):
    args = [cleanup(arg) for arg in args]
    if (part is not None):
        (parts, orders) = part
        if (numpy.array(orders).size == 1):
            orders = ([int(numpy.array(orders).item())] * len(args))
        parts = numpy.array(parts).flatten()
        for (i, arg) in enumerate(args):
            (m, n) = (float(parts[i]), float(orders[i]))
            l = len(arg)
            args[i] = arg[int(((m / n) * l)):int((((m + 1) / n) * l))]
    shapes = [arg.shape for arg in args]
    size = (numpy.prod(shapes, 0)[0] * numpy.sum(shapes, 0)[1])
    if (size > (10 ** 9)):
        raise MemoryError('Too large sets')
    if (len(args) == 1):
        out = args[0]
    elif (len(args) == 2):
        out = combine_two(*args)
    else:
        arg1 = combine_two(*args[:2])
        out = combine(([arg1] + args[2:]))
    return out

All linear combination of a list of list.

Args:
args (numpy.ndarray) : List of input arrays.  Components to take linear
combination of with `args[i].shape=(N[i], M[i])` where N is to be
taken linear combination of and M is static.  M[i] is set to 1 if
missing.

Returns:
(numpy.array) : matrix of combinations with shape (numpy.prod(N),
numpy.sum(M)).

Examples:
>>> A, B = [1,2], [[4,4],[5,6]]
>>> print(chaospy.quad.combine([A, B]))
[[1. 4. 4.]
[1. 5. 6.]
[2. 4. 4.]
[2. 5. 6.]]


def _ParseCString(self, page_data, string_offset):
    cstring_map = self._GetDataTypeMap('cstring')
    try:
        value_string = self._ReadStructureFromByteStream(page_data[string_offset:], string_offset, cstring_map)
    except (ValueError, errors.ParseError) as exception:
        raise errors.ParseError('Unable to map string data at offset: 0x{0:08x} with error: {1!s}'.format(string_offset, exception))
    return value_string.rstrip('\x00')

Parses a C string from the page data.

Args:
page_data (bytes): page data.
string_offset (int): offset of the string relative to the start
of the page.

Returns:
str: string.

Raises:
ParseError: when the string cannot be parsed.


def label_search(self, label:str) -> List[dict]:

        ilx_rows = self.label2rows(self.local_degrade(label))
        if not ilx_rows:
            return None
        else:
            return ilx_rows

Returns the rows in InterLex associated with that label

Note:
Pressumed to have duplicated labels in InterLex
Args:
label: label of the entity you want to find
Returns:
None or List[dict]


def _overload_operator(cls, tensor_class, operator):
    tensor_oper = getattr(tensor_class, operator)
    tensor_oper = getattr(tensor_oper, '__func__', tensor_oper)
    setattr(cls, operator, tensor_oper)

Overload an operator with the same implementation as a base Tensor class.

We pull the operator out of the class dynamically to avoid ordering issues.

Args:
tensor_class: The (Composite)Tensor to get the method from.
operator: string. The operator name.


def read(self, size=None):

    if not self._is_open:
      raise IOError('Not opened.')

    if self._current_offset < 0:
      raise IOError('Invalid current offset value less than zero.')

    if self._current_offset >= self._size:
      return b''

    if size is None or self._current_offset + size > self._size:
      size = self._size - self._current_offset

    if self._tsk_attribute:
      data = self._tsk_file.read_random(
          self._current_offset, size, self._tsk_attribute.info.type,
          self._tsk_attribute.info.id)
    else:
      data = self._tsk_file.read_random(self._current_offset, size)

    self._current_offset += len(data)

    return data

Reads a byte string from the file-like object at the current offset.

The function will read a byte string of the specified size or
all of the remaining data if no size was specified.

Args:
size (Optional[int]): number of bytes to read, where None is all
remaining data.

Returns:
bytes: data read.

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


def insert(self, optional_root_locations_path):

        encountered_simple_optional = False
        parent_location = self._root_location
        for optional_root_location in optional_root_locations_path:
            if encountered_simple_optional:
                raise AssertionError(u'Encountered simple optional root location {} in path, but'
                                     u'further locations are present. This should not happen: {}'
                                     .format(optional_root_location, optional_root_locations_path))

            if optional_root_location not in self._location_to_children:

                encountered_simple_optional = True
            else:
                self._location_to_children[parent_location].add(optional_root_location)
                parent_location = optional_root_location

Insert a path of optional Locations into the tree.

Each OptionalTraversalTree object contains child Location objects as keys mapping to
other OptionalTraversalTree objects.

Args:
optional_root_locations_path: list of optional root Locations all except the last
of which must be present in complex_optional_roots


def promote_artifacts(self, promote_stage='latest'):
    if (promote_stage.lower() == 'alpha'):
        self._sync_to_uri(self.s3_canary_uri)
    elif (promote_stage.lower() == 'canary'):
        self._sync_to_uri(self.s3_latest_uri)
    else:
        self._sync_to_uri(self.s3_latest_uri)

Promote artifact version to dest.

Args:
promote_stage (string): Stage that is being promoted


def read_int8(self, little_endian=True):

        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.unpack('%sb' % endian)

Read 1 byte as a signed integer value from the stream.

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

Returns:
int:


def _merge_tensor_signatures(self, signatures):
    sorted_update = []
    if self._num_signature_dimensions() > 1:
        signature_indices = self._signature_types()
        for _, val in sorted(signatures.items(), key=lambda item: signature_indices[item[0]]):
            sorted_update.append(val)
        updates = array_ops_stack.stack(sorted_update, axis=0, name='merge_single_op_signatures')
    elif self._num_signature_dimensions() == 1:
        (_, val), = signatures.items()
        updates = val
    else:
        raise ValueError('Cannot merge 0 signatures. Check the value passed for flag --signatures.')
    return updates

Returns a tensor that merges the given signatures.

Args:
signatures: A dictionary of the signature updates from signature name to
a tensor of dimension [1].
Returns:
A tensor that concats the signature values in a predefined order.
Raises:
ValueError: Unable to merge signatures.


def _ReadEncryptedData(self, read_size):

    encrypted_data = self._file_object.read(read_size)

    read_count = len(encrypted_data)

    self._encrypted_data = b''.join([self._encrypted_data, encrypted_data])

    self._decrypted_data, self._encrypted_data = (
        self._decrypter.Decrypt(self._encrypted_data))

    self._decrypted_data_size = len(self._decrypted_data)

    return read_count

Reads encrypted data from the file-like object.

Args:
read_size (int): number of bytes of encrypted data to read.

Returns:
int: number of bytes of encrypted data read.


def on_predict_batch_end(self, batch, logs=None):

Called at the end of a batch in `predict` 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 merge_two_dictionaries(a, b, merge_lists=False):
    key = None
    try:
        if ((a is None) or isinstance(a, (six.string_types, six.text_type, six.integer_types, float))):
            a = b
        elif isinstance(a, list):
            if isinstance(b, list):
                if merge_lists:
                    a.extend(b)
                else:
                    a = b
            else:
                a.append(b)
        elif isinstance(a, (dict, UserDict)):
            if isinstance(b, (dict, UserDict)):
                for key in b:
                    if (key in a):
                        a[key] = merge_two_dictionaries(a[key], b[key], merge_lists=merge_lists)
                    else:
                        a[key] = b[key]
            else:
                raise ValueError(('Cannot merge non-dict "%s" into dict "%s"' % (b, a)))
        else:
            raise ValueError(('NOT IMPLEMENTED "%s" into "%s"' % (b, a)))
    except TypeError as e:
        raise ValueError(('TypeError "%s" in key "%s" when merging "%s" into "%s"' % (e, key, b, a)))
    return a

Merges b into a and returns merged result

NOTE: tuples and arbitrary objects are not handled as it is totally ambiguous what should happen

Args:
a (DictUpperBound): dictionary to merge into
b (DictUpperBound): dictionary to merge from
merge_lists (bool): Whether to merge lists (True) or replace lists (False). Default is False.

Returns:
DictUpperBound: Merged dictionary


def nb_ll_row(params, data_row):

    p = params[0]
    r = params[1]
    n = len(data_row)
    ll = np.sum(gammaln(data_row + r)) - np.sum(gammaln(data_row + 1))
    ll -= n*gammaln(r)
    ll += np.sum(data_row)*np.log(p)
    ll += n*r*np.log(1-p)
    return -ll

returns the negative LL of a single row.

Args:
params (array) - [p, r]
data_row (array) - 1d array of data

Returns:
LL of row


def __init__(self, submission_id, submissions, storage_bucket):

    super(DefenseSubmission, self).__init__(submission_id, submissions,
                                            storage_bucket)
    if self.type != TYPE_DEFENSE:
      raise WorkerError('Incorrect defense type for submission "{0}"'.format(
          submission_id))

Initializes DefenseSubmission.

Args:
submission_id: ID of the submission
submissions: instance of CompetitionSubmissions with all submissions
storage_bucket: storage bucket where all submissions are stored

Raises:
WorkerError: if submission has incorrect type


def __init__(self, feed_fn):
    self.feed_fn = feed_fn

Initializes a `FeedFnHook`.

Args:
feed_fn: function that takes no arguments and returns `dict` of `Tensor`
to feed.


def check_denotation(target_values, predicted_values):
    if (len(target_values) != len(predicted_values)):
        return False
    for target in target_values:
        if (not any((target.match(pred) for pred in predicted_values))):
            return False
    return True

Return True if the predicted denotation is correct.

Args:
target_values (list[Value])
predicted_values (list[Value])
Returns:
bool


def ParseContactRow(self, parser_mediator, query, row, **unused_kwargs):

    query_hash = hash(query)

    event_data = TwitterIOSContactEventData()
    event_data.description = self._GetRowValue(query_hash, row, 'description')
    event_data.followers_count = self._GetRowValue(
        query_hash, row, 'followersCount')
    event_data.following = self._GetRowValue(query_hash, row, 'following')
    event_data.following_count = self._GetRowValue(
        query_hash, row, 'followingCount')
    event_data.location = self._GetRowValue(query_hash, row, 'location')
    event_data.name = self._GetRowValue(query_hash, row, 'name')
    event_data.profile_url = self._GetRowValue(
        query_hash, row, 'profileImageUrl')
    event_data.query = query
    event_data.screen_name = self._GetRowValue(query_hash, row, 'screenName')
    event_data.url = self._GetRowValue(query_hash, row, 'url')

    timestamp = self._GetRowValue(query_hash, row, 'createdDate')
    if timestamp:

      timestamp = int(timestamp)
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_CREATION)
      parser_mediator.ProduceEventWithEventData(event, event_data)

    timestamp = self._GetRowValue(query_hash, row, 'updatedAt')
    if timestamp:

      timestamp = int(timestamp)
      date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
      event = time_events.DateTimeValuesEvent(
          date_time, definitions.TIME_DESCRIPTION_UPDATE)
      parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a contact row from the database.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row resulting from query.


def _send_json(self, method, path, data):

        headers = {'Content-type': 'application/json'}
        return self._make_request(method, path, data=data, headers=headers)

Make a application/json request.

Args:
`method`: The method of the request (POST or PUT).
`path`: The path to the resource.
`data`: The JSON-encoded data.
Returns:
The content of the response.
Raises:
An exception depending on the HTTP status code of the response.


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

        self._name = name
        self.client = client
        self._state = None

Create a Thing.

Args:
name (str): name of the Thing. This corresponds to the
AWS IoT Thing name.
client (str): MQTT client connection to use. This can be set
anytime before publishing Thing messages to the server.


def _apply(self, ctx: ExtensionContext) -> AugmentedDict:

        node_key, node_value = ctx.node

        def process(pattern: Pattern[str], _str: str) -> str:
            _match = pattern.match(_str)
            if _match is None:
                return _str

            placeholder, envvar = _match.group(1), _match.group(2)
            envvalue = os.environ.get(envvar, None)
            if envvalue is None and self.fail_on_unset:
                raise ExtensionError("Environment variable '{}' is unset.".format(envvar))

            return _str.replace(placeholder, envvalue or self.default)

        _pattern = re.compile(self.__pattern__)
        node_key = process(_pattern, node_key)
        node_value = process(_pattern, node_value)

        return {node_key: node_value}

Replaces any {{env::*}} directives with it's actual environment variable value or a default.

Args:
ctx: The processing context.

Returns:
Returns the altered node key and value.


def FetchAllGraphSeries(label, report_type, period=None, token=None):
    if _ShouldUseLegacyDatastore():
        return _FetchAllGraphSeriesFromTheLegacyDB(label, report_type, period=period, token=token)
    if (period is None):
        time_range = None
    else:
        range_end = rdfvalue.RDFDatetime.Now()
        time_range = time_utils.TimeRange((range_end - period), range_end)
    return data_store.REL_DB.ReadAllClientGraphSeries(label, report_type, time_range=time_range)

Fetches graph series for the given label and report-type from the DB.

Args:
label: Client label to fetch data for.
report_type: rdf_stats.ClientGraphSeries.ReportType to fetch data for.
period: rdfvalue.Duration specifying how far back in time to fetch data. If
not provided, all data for the given label and report-type will be
returned.
token: ACL token to use for reading from the legacy (non-relational)
datastore.

Raises:
AFF4AttributeTypeError: If, when reading to the legacy DB, an unexpected
report-data type is encountered.

Returns:
A dict mapping timestamps to graph-series. The timestamps
represent when the graph-series were written to the datastore.


def get(self, name, *default):
    curr = self.values
    for part in name.split('.'):
        if (part in curr):
            curr = curr[part]
        elif default:
            return default[0]
        else:
            fmt = "Context value '{}' does not exist:\n{}"
            raise AttributeError(fmt.format(name, util.yaml_dump(self.values)))
    return curr

Get context value with the given name and optional default.

Args:
name (str):
The name of the context value.
*default (Any):
If given and the key doesn't not exist, this will be returned
instead. If it's not given and the context value does not exist,
`AttributeError` will be raised

Returns:
The requested context value.  If the value does not exist it will
return `default` if give or raise `AttributeError`.

Raises:
AttributeError: If the value does not exist and `default` was not
given.


def is_text(self):
    return (self.type in [self._TYPE_PASTE, self._TYPE_TEXT, self._TYPE_TWEET])

Tells if this message is a text message.

Returns:
bool. Success


def parse_step(step_name):
    prefix = 'step'
    step_name = step_name.lower().replace(' ', '_')
    step_name = step_name[len(prefix):] if prefix and step_name.startswith(prefix) else step_name
    return step_name.strip(':_')

Replaces white spaces and removes 'Step:' label

Args:
step_name(str): step name passed in metric ParDo

Returns:
lower case step name without namespace and step label


def publish(cls, message, client_filter=None):
    with cls._lock:
        for client in cls.subscribers:
            if ((not client_filter) or client_filter(client)):
                client.send(message)

Publish messages to subscribers.

Args:
message: The message to publish.
client_filter: A filter function to call passing in each client. Only
clients for whom the function returns True will have the
message sent to them.


def teardown(self, *args, **kwargs):
    pass

Called to clean up an instance before it is discarded.

If you are using Dataflow, you need to enable Dataflow Runner V2
before using this feature.

Args:
*args: Additional arguments and side inputs.
**kwargs: Additional arguments and side inputs.


def index_add(x, idx, y):
    return _index_update_helper(tf_np.ndarray._with_index_add, x, idx, y)

Pure equivalent of `x[idx] += y`.

Returns the value of x that would result from the NumPy-style indexed
assignment `x[idx] += y`. Because it's a pure function, `x` itself won't be
changed.

Args:
x: an array with the values to be updated.
idx: a Numpy-style index, consisting of `None`, integers, slice objects,
ellipses, ndarrays with integer dtypes, or a tuple of the above.
y: the array of updates. `y` must be broadcastable to the shape of the array
that would be returned by `x[idx]`.

Returns:
The updated version of `x`.


def guess_depth(packages):

    if len(packages) == 1:
        return packages[0].count('.') + 2
    return min(p.count('.') for p in packages) + 1

Guess the optimal depth to use for the given list of arguments.

Args:
packages (list of str): list of packages.

Returns:
int: guessed depth to use.


def _separate_string(string: str, stride: int, separator: str) -> str:
    result = ''
    for i, c in enumerate(string):
        if i > 0 and i % stride == 0:
            result += separator
        result += c
    return result

Returns a separated string by separator at multiples of stride.

For example, the input:
* string: 'thequickbrownfoxjumpedoverthelazydog'
* stride: 3
* separator: '-'

Would produce a return value of:
'the-qui-ckb-row-nfo-xju-mpe-dov-ert-hel-azy-dog'

Args:
string: The string to split.
stride: The interval to insert the separator at.
separator: The string to insert at every stride interval.

Returns:
The original string with the separator present at every stride interval.


def generate_string(self, initial_logits, initial_state, sequence_length):
    current_logits = initial_logits
    current_state = initial_state
    generated_letters = []
    for _ in range(sequence_length):
        char_index = tf.squeeze(tf.multinomial(current_logits, 1))
        char_one_hot = tf.one_hot(char_index, self._output_size, 1.0, 0.0)
        generated_letters.append(char_one_hot)
        (gen_out_seq, current_state) = self._core(tf.nn.relu(self._embed_module(char_one_hot)), current_state)
        current_logits = self._output_module(gen_out_seq)
    generated_string = tf.stack(generated_letters)
    return generated_string

Builds sub-graph to generate a string, sampled from the model.

Args:
initial_logits: Starting logits to sample from.
initial_state: Starting state for the RNN core.
sequence_length: Number of characters to sample.

Returns:
A Tensor of characters, with dimensions `[sequence_length, batch_size,
output_size]`.


def from_file(cls, path):

        with open(path, 'r', errors='replace') as f:
            return cls(f.read())

Create a text from a file.

Args:
path (str): The file path.


def _AddPropertiesForNonRepeatedScalarField(field, cls):
    proto_field_name = field.name
    property_name = _PropertyName(proto_field_name)
    type_checker = type_checkers.GetTypeChecker(field)
    default_value = field.default_value
    valid_values = set()
    is_proto3 = (field.containing_type.syntax == 'proto3')

    def getter(self):
        return self._fields.get(field, default_value)
    getter.__module__ = None
    getter.__doc__ = ('Getter for %s.' % proto_field_name)
    clear_when_set_to_default = (is_proto3 and (not field.containing_oneof))

    def field_setter(self, new_value):
        new_value = type_checker.CheckValue(new_value)
        if (clear_when_set_to_default and (not new_value)):
            self._fields.pop(field, None)
        else:
            self._fields[field] = new_value
        if (not self._cached_byte_size_dirty):
            self._Modified()
    if field.containing_oneof:

        def setter(self, new_value):
            field_setter(self, new_value)
            self._UpdateOneofState(field)
    else:
        setter = field_setter
    setter.__module__ = None
    setter.__doc__ = ('Setter for %s.' % proto_field_name)
    doc = ('Magic attribute generated for "%s" proto field.' % proto_field_name)
    setattr(cls, property_name, property(getter, setter, doc=doc))

Adds a public property for a nonrepeated, scalar protocol message field.
Clients can use this property to get and directly set the value of the field.
Note that when the client sets the value of a field by using this property,
all necessary "has" bits are set as a side-effect, and we also perform
type-checking.

Args:
field: A FieldDescriptor for this field.
cls: The class we're constructing.


def __init__(self, function_name, level=1, children_inputs_mappings=None, **kwargs):
    self._function_name = function_name
    self._level = level
    if self._level == 1:
        assert children_inputs_mappings is None
    else:
        assert isinstance(children_inputs_mappings, dict)
    self._children_inputs_mappings = children_inputs_mappings
    if self._children_inputs_mappings is not None:
        self._validate_children_inputs_mappings(self._children_inputs_mappings)
    self._unique_function_id = _uuid.uuid1().hex
    self._attrs_to_store_later = kwargs
    self._stored_attrs = False
    self._inputs = OpHint.OpHintArgumentTracker(self._function_name, self._unique_function_id, 'InputHint', OpHint.FUNCTION_INPUT_INDEX_ATTR, level, self._children_inputs_mappings)
    self._outputs = OpHint.OpHintArgumentTracker(self._function_name, self._unique_function_id, 'OutputHint', OpHint.FUNCTION_OUTPUT_INDEX_ATTR, level, self._children_inputs_mappings)

Create a OpHint.

Args:
function_name: Name of the function (the custom op name in tflite)
level: OpHint level.
children_inputs_mappings: Children OpHint inputs/outputs mapping.
children_inputs_mappings should like below:
"parent_first_child_input":
[{"parent_input_index": num, "child_input_index": num}, ...]
"parent_last_child_output":
[{"parent_output_index": num, "child_output_index": num}, ...]
"internal_children_input_output":
[{"child_input_index": num, "child_output_index": num}, ...]
**kwargs: Keyword arguments of any constant attributes for the function.


def exit_hook(callable, once=True):
    if (once and (callable in ExitHooks)):
        return
    ExitHooks.append(callable)

r"""A decorator that makes the decorated function to run while ec exits.

Args:
callable (callable): The target callable.
once (bool): Avoids adding a func to the hooks, if it has been added already. Defaults to True.

Note:
Hooks are processedd in a LIFO order.


def play_alert(zones, alert_uri, alert_volume=20, alert_duration=0, fade_back=False):

    for zone in zones:
        zone.snap = Snapshot(zone)
        zone.snap.snapshot()
        print('snapshot of zone: {}'.format(zone.player_name))

    for zone in zones:

        if zone.is_coordinator:
            if not zone.is_playing_tv:

                trans_state = zone.get_current_transport_info()
                if trans_state['current_transport_state'] == 'PLAYING':
                    zone.pause()

        zone.volume = alert_volume
        zone.mute = False

    print('will play: {} on all coordinators'.format(alert_uri))
    for zone in zones:
        if zone.is_coordinator:
            zone.play_uri(uri=alert_uri, title='Sonos Alert')

    time.sleep(alert_duration)

    for zone in zones:
        print('restoring {}'.format(zone.player_name))
        zone.snap.restore(fade=fade_back)

Demo function using soco.snapshot across multiple Sonos players.

Args:
zones (set): a set of SoCo objects
alert_uri (str): uri that Sonos can play as an alert
alert_volume (int): volume level for playing alert (0 tp 100)
alert_duration (int): length of alert (if zero then length of track)
fade_back (bool): on reinstating the zones fade up the sound?


def add_ast_fn(d, spec, parent_function=None):
    if (d['type'] == 'Function'):
        ast_fn = Function(d['function']['name'], spec, parent_function=parent_function)
        for arg in d['args']:
            if (arg['type'] == 'Function'):
                ast_fn.add_argument(add_ast_fn(arg, spec, parent_function=ast_fn))
            elif (arg['type'] == 'NSArg'):
                ast_fn.add_argument(NSArg(arg['nsarg']['ns'], arg['nsarg']['ns_val'], ast_fn))
            elif (arg['type'] == 'StrArg'):
                ast_fn.add_argument(StrArg(arg['arg'], ast_fn))
    return ast_fn

Convert dict AST to object AST Function

Args:
ast_fn: AST object Function
d: AST as dictionary
spec: BEL Specification

Return:
ast_fn


def post_process(self, outputs, target_sizes):
    logging.warning_once('`post_process` is deprecated and will be removed in v5 of Transformers, please use `post_process_object_detection` instead, with `threshold=0.` for equivalent results.')
    out_logits, out_bbox = (outputs.logits, outputs.pred_boxes)
    if len(out_logits) != len(target_sizes):
        raise ValueError('Make sure that you pass in as many target sizes as the batch dimension of the logits')
    if target_sizes.shape[1] != 2:
        raise ValueError('Each element of target_sizes must contain the size (h, w) of each image of the batch')
    prob = out_logits.sigmoid()
    topk_values, topk_indexes = torch.topk(prob.view(out_logits.shape[0], -1), 300, dim=1)
    scores = topk_values
    topk_boxes = torch.div(topk_indexes, out_logits.shape[2], rounding_mode='floor')
    labels = topk_indexes % out_logits.shape[2]
    boxes = center_to_corners_format(out_bbox)
    boxes = torch.gather(boxes, 1, topk_boxes.unsqueeze(-1).repeat(1, 1, 4))
    img_h, img_w = target_sizes.unbind(1)
    scale_fct = torch.stack([img_w, img_h, img_w, img_h], dim=1)
    boxes = boxes * scale_fct[:, None, :]
    results = [{'scores': s, 'labels': l, 'boxes': b} for s, l, b in zip(scores, labels, boxes)]
    return results

Converts the output of [`ConditionalDetrForObjectDetection`] into the format expected by the Pascal VOC format (xmin, ymin, xmax, ymax).
Only supports PyTorch.

Args:
outputs ([`ConditionalDetrObjectDetectionOutput`]):
Raw outputs of the model.
target_sizes (`torch.Tensor` of shape `(batch_size, 2)`):
Tensor containing the size (h, w) of each image of the batch. For evaluation, this must be the original
image size (before any data augmentation). For visualization, this should be the image size after data
augment, but before padding.
Returns:
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
in the batch as predicted by the model.


def validate(self, scope: ValidationScope = ValidationScope.all,
                 ctype: ContentType = ContentType.config) -> None:

        self.schema_node._validate(self, scope, ctype)

Validate the receiver's value.

Args:
scope: Scope of the validation (syntax, semantics or all).
ctype: Receiver's content type.

Raises:
SchemaError: If the value doesn't conform to the schema.
SemanticError: If the value violates a semantic constraint.
YangTypeError: If the value is a scalar of incorrect type.


def get_block(self, block_id):

        block = backend.query.get_block(self.connection, block_id)
        latest_block = self.get_latest_block()
        latest_block_height = latest_block['height'] if latest_block else 0

        if not block and block_id > latest_block_height:
            return

        result = {'height': block_id,
                  'transactions': []}

        if block:
            transactions = backend.query.get_transactions(self.connection, block['transactions'])
            result['transactions'] = [t.to_dict() for t in Transaction.from_db(self, transactions)]

        return result

Get the block with the specified `block_id`.

Returns the block corresponding to `block_id` or None if no match is
found.

Args:
block_id (int): block id of the block to get.


def predict_proba(self, x, batch_size=32, verbose=0):
    warnings.warn('`model.predict_proba()` is deprecated and will be removed after 2021-01-01. Please use `model.predict()` instead.')
    preds = self.predict(x, batch_size, verbose)
    if preds.min() < 0.0 or preds.max() > 1.0:
        logging.warning('Network returning invalid probability values. The last layer might not normalize predictions into probabilities (like softmax or sigmoid would).')
    return preds

Generates class probability predictions for the input samples.

The input samples are processed batch by batch.

Args:
x: input data, as a Numpy array or list of Numpy arrays
(if the model has multiple inputs).
batch_size: integer.
verbose: verbosity mode, 0 or 1.

Returns:
A Numpy array of probability predictions.


def get(self, key, default=None):
    if (key.count('.') == 0):
        return super(DotDict, self).get(key, default)
    value = default
    (first, remainder) = key.split('.', 1)
    if (first in self):
        value = super(DotDict, self).get(first, default)
        if isinstance(value, (dict, DotDict)):
            return DotDict(value).get(remainder, default)
    return value

Get a value from the `DotDict`.

The `key` parameter can either be a regular string key,
e.g. "foo", or it can be a string key with dot notation,
e.g. "foo.bar.baz", to signify a nested lookup.

The default value is returned if any level of the key's
components are not found.

Args:
key (str): The key to get the value for.
default: The return value should the given key
not exist in the `DotDict`.


def create_interconnect(self, location_entries, timeout=(- 1)):
    return self._helper.create(location_entries, uri=self.locations_uri, timeout=timeout)

Creates an interconnect at the given location.

Warning:
It does not create the LOGICAL INTERCONNECT itself.
It will fail if no interconnect is already present on the specified position.

Args:
location_entries (dict): Dictionary with location entries.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: Created interconnect.


def identify(self, token):

        payload = {
            'op': 2,
            'd': {
                'token': self.token,
                'properties': {
                    '$os': sys.platform,
                    '$browser': 'legobot',
                    '$device': 'legobot'
                },
                'compress': False,
                'large_threshold': 250
            }
        }
        payload['d']['synced_guilds'] = []
        logger.info("Identifying with the following message: \
                    {}".format(payload))
        self.ws.send(json.dumps(payload))
        return

Identifies to the websocket endpoint

Args:
token (string): Discord bot token


def assert_split_at_fraction_exhaustive(source, start_position=None, stop_position=None, perform_multi_threaded_test=True):
    expected_items = read_from_source(source, start_position, stop_position)
    if not expected_items:
        raise ValueError('Source %r is empty.' % source)
    if len(expected_items) == 1:
        raise ValueError('Source %r only reads a single item.' % source)
    all_non_trivial_fractions = []
    any_successful_fractions = False
    any_non_trivial_fractions = False
    for i in range(len(expected_items)):
        stats = SplitFractionStatistics([], [])
        assert_split_at_fraction_binary(source, expected_items, i, 0.0, None, 1.0, None, stats)
        if stats.successful_fractions:
            any_successful_fractions = True
        if stats.non_trivial_fractions:
            any_non_trivial_fractions = True
        all_non_trivial_fractions.append(stats.non_trivial_fractions)
    if not any_successful_fractions:
        raise ValueError('SplitAtFraction test completed vacuously: no successful split fractions found')
    if not any_non_trivial_fractions:
        raise ValueError('SplitAtFraction test completed vacuously: no non-trivial split fractions found')
    if not perform_multi_threaded_test:
        return
    num_total_trials = 0
    for i in range(len(expected_items)):
        non_trivial_fractions = [2.0]
        non_trivial_fractions.extend(all_non_trivial_fractions[i])
        min_non_trivial_fraction = min(non_trivial_fractions)
        if min_non_trivial_fraction == 2.0:
            continue
        num_trials = 0
        have_success = False
        have_failure = False
        thread_pool = _ThreadPool(2)
        try:
            while True:
                num_trials += 1
                if num_trials > MAX_CONCURRENT_SPLITTING_TRIALS_PER_ITEM:
                    _LOGGER.warning('After %d concurrent splitting trials at item
                    break
                if _assert_split_at_fraction_concurrent(source, expected_items, i, min_non_trivial_fraction, thread_pool):
                    have_success = True
                else:
                    have_failure = True
                if have_success and have_failure:
                    _LOGGER.info('%d trials to observe both success and failure of concurrent splitting at item
                    break
        finally:
            thread_pool.close()
        num_total_trials += num_trials
        if num_total_trials > MAX_CONCURRENT_SPLITTING_TRIALS_TOTAL:
            _LOGGER.warning('After %d total concurrent splitting trials, considered only %d items, giving up.', num_total_trials, i)
            break
    _LOGGER.info('%d total concurrent splitting trials for %d items', num_total_trials, len(expected_items))

Performs and tests dynamic work rebalancing exhaustively.

Asserts that for each possible start position, a source can be split at
every interesting fraction (halfway between two fractions that differ by at
least one item) and the results are consistent if a split succeeds.
Verifies multi threaded splitting as well.

Args:
source (~apache_beam.io.iobase.BoundedSource): the source to perform
dynamic splitting on.
perform_multi_threaded_test (bool): if :data:`True` performs a
multi-threaded test, otherwise this test is skipped.

Raises:
ValueError: if the exhaustive splitting test fails.


def search(cls, session, queries, out_type):
    cls._check_implements('search')
    domain = cls.get_search_domain(queries)
    return cls(('/search/%s.json' % cls.__endpoint__), data={'query': str(domain)}, session=session, out_type=out_type)

Search for a record given a domain.

Args:
session (requests.sessions.Session): Authenticated session.
queries (helpscout.models.Domain or iter): The queries for the
domain. If a ``Domain`` object is provided, it will simply be
returned. Otherwise, a ``Domain`` object will be generated
from the complex queries. In this case, the queries should
conform to the interface in
:func:`helpscout.domain.Domain.from_tuple`.
out_type (helpscout.BaseModel): The type of record to output. This
should be provided by child classes, by calling super.

Returns:
RequestPaginator(output_type=helpscout.BaseModel): Results
iterator of the ``out_type`` that is defined.


def _pack_images(images, rows, cols):
    shape = onp.shape(images)
    (width, height, depth) = shape[(- 3):]
    images = onp.reshape(images, ((- 1), width, height, depth))
    batch = onp.shape(images)[0]
    rows = onp.minimum(rows, batch)
    cols = onp.minimum((batch
    images = images[:(rows * cols)]
    images = onp.reshape(images, (rows, cols, width, height, depth))
    images = onp.transpose(images, [0, 2, 1, 3, 4])
    images = onp.reshape(images, [(rows * width), (cols * height), depth])
    return images

Helper utility to make a tiled field of images from numpy arrays.

Args:
images: Image tensor in shape [N, W, H, C].
rows: Number of images per row in tiled image.
cols: Number of images per column in tiled image.

Returns:
A tiled image of shape [W * rows, H * cols, C].
Truncates incomplete rows.


def remove_pos_arg_placeholders(alias_command):
    split_command = shlex.split(alias_command)
    boundary_index = len(split_command)
    for (i, subcommand) in enumerate(split_command):
        if ((not re.match('^[a-z]', subcommand.lower())) or (i > COLLISION_CHECK_LEVEL_DEPTH)):
            boundary_index = i
            break
    return ' '.join(split_command[:boundary_index]).lower()

Remove positional argument placeholders from alias_command.

Args:
alias_command: The alias command to remove from.

Returns:
The alias command string without positional argument placeholder.


def get_special_tokens_mask(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None, already_has_special_tokens: bool=False) -> List[int]:
    if already_has_special_tokens:
        return super().get_special_tokens_mask(token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True)
    if token_ids_1 is None:
        return [1] + [0] * len(token_ids_0) + [1]
    return [1] + [0] * len(token_ids_0) + [1] + [0] * len(token_ids_1) + [1]

Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `prepare_for_model` method.

Args:
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
already_has_special_tokens (`bool`, *optional*, defaults to `False`):
Whether or not the token list is already formatted with special tokens for the model.

Returns:
`List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.


def get_key(self, match_key, num_results=1, best=True, **dfilter):
    return get_key(match_key, self.keys(), num_results=num_results, best=best, **dfilter)

Get multiple fully-specified keys that match the provided query.

Args:
key (DatasetID): DatasetID of query parameters to use for
searching. Any parameter that is `None`
is considered a wild card and any match is
accepted. Can also be a string representing the
dataset name or a number representing the dataset
wavelength.
num_results (int): Number of results to return. If `0` return all,
if `1` return only that element, otherwise
return a list of matching keys.
**dfilter (dict): See `get_key` function for more information.


def CheckPath(self, path, path_segment_separator=None):
    if (not self._case_sensitive):
        path = path.lower()
    if (path_segment_separator is None):
        path_segment_separator = self._path_segment_separator
    path_segments = path.split(path_segment_separator)
    number_of_path_segments = len(path_segments)
    scan_object = self._root_node
    while scan_object:
        if isinstance(scan_object, py2to3.STRING_TYPES):
            break
        if (scan_object.path_segment_index >= number_of_path_segments):
            scan_object = scan_object.default_value
            continue
        path_segment = path_segments[scan_object.path_segment_index]
        scan_object = scan_object.GetScanObject(path_segment)
    if (not isinstance(scan_object, py2to3.STRING_TYPES)):
        return False
    filter_path_segments = scan_object.split(self._path_segment_separator)
    return (filter_path_segments == path_segments)

Checks if a path matches the scan tree-based path filter.

Args:
path: a string containing the path.
path_segment_separator: optional string containing the path segment
separator. None defaults to the path segment
separator that was set when the path filter
scan tree was initialized.

Returns:
A boolean indicating if the path matches the filter.


def post(self, service, data):
    url = self._url_format(service)
    data = Base._data_to_json(data)
    headers = {'content-type': 'application/json'}
    return self.rest_action(self._session.post, url, data=data, headers=headers)

Generic POST operation for sending data to Learning Modules API.

Data should be a JSON string or a dict.  If it is not a string,
it is turned into a JSON string for the POST body.

Args:
service (str): The endpoint service to use, i.e. gradebook
data (json or dict): the data payload

Raises:
requests.RequestException: Exception connection error
ValueError: Unable to decode response content

Returns:
list: the json-encoded content of the response


def save_state_regularly(self, fname, frequency=600):

        self.save_state(fname)
        loop = asyncio.get_event_loop()
        self.save_state_loop = loop.call_later(frequency,
                                               self.save_state_regularly,
                                               fname,
                                               frequency)

Save the state of node with a given regularity to the given
filename.

Args:
fname: File name to save retularly to
frequency: Frequency in seconds that the state should be saved.
By default, 10 minutes.


def latch_config_variables(self):
    return {desc.name: desc.latch() for desc in self._config_variables.values()}

Latch the current value of all config variables as python objects.

This function will capture the current value of all config variables
at the time that this method is called.  It must be called after
start() has been called so that any default values in the config
variables have been properly set otherwise DataError will be thrown.

Conceptually this method performs the operation that happens just
before a tile executive hands control to the tile application
firmware. It latches in the value of all config variables at that
point in time.

For convenience, this method does all necessary binary -> python
native object conversion so that you just get python objects back.

Returns:
dict: A dict of str -> object with the config variable values.

The keys in the dict will be the name passed to
`declare_config_variable`.

The values will be the python objects that result from calling
latch() on each config variable.  Consult ConfigDescriptor.latch()
for documentation on how that method works.


def is_end_node(node):

    return (isinstance(node, ast.Expr) and
            isinstance(node.value, ast.Name) and
            node.value.id == 'end')

Checks if a node is the "end" keyword.

Args:
node: AST node.

Returns:
True if the node is the "end" keyword, otherwise False.


def _next_layer_gather_index(bc, original_rp, broadcast_rp):
    old_value_rowids = array_ops.gather(bc.gather_index, broadcast_rp.value_rowids())

    def gi_no_broadcast():
        old_row_starts = array_ops.gather(original_rp.row_splits(), old_value_rowids)
        expected_row_lengths = array_ops.gather(params=original_rp.row_lengths(), indices=bc.gather_index)
        actual_row_lengths = broadcast_rp.row_lengths()
        check_valid = check_ops.assert_equal(expected_row_lengths, actual_row_lengths, message='Cannot broadcast')
        gather_index = old_row_starts + broadcast_rp.offsets_in_rows()
        return control_flow_ops.with_dependencies([check_valid], gather_index)

    def gi_broadcast():
        return old_value_rowids
    if not original_rp.is_uniform():
        return gi_no_broadcast()
    do_broadcast = math_ops.equal(original_rp.uniform_row_length(), constant_op.constant(1, original_rp.dtype))
    gather_index = cond.cond(do_broadcast, true_fn=gi_broadcast, false_fn=gi_no_broadcast)
    return gather_index

Create the next layer gather_index whether or not a broadcast happens.

*----------bc-------->*
|                     |
original_rp           broadcast_rp
|                     |
\|/                   \|/
*--next_broadcaster-->*

Args:
bc: the old broadcaster.
original_rp: the original row partition.
broadcast_rp: the target row partition.

Returns:
the gather_index for next_broadcaster.
Raises:
InvalidArgumentError if the shapes are incompatible.


def set(self, *args):
    assert (len(args) in (1, 2))
    if (len(args) == 1):
        value = args[0]
        self._impl.set(value)
    else:
        (index, value) = args
        if isinstance(value, Real):
            self._impl.setTplDbl(Tuple(index)._impl, value)
        elif isinstance(value, basestring):
            self._impl.setTplStr(Tuple(index)._impl, value)
        else:
            raise TypeError

Set the value of a single instance of this parameter.

Args:
args: value if the parameter is scalar, index and value
otherwise.

Raises:
RuntimeError: If the entity has been deleted in the underlying
AMPL.

TypeError: If the parameter is not scalar and the index is not
provided.


def has_title(self, title, **kwargs):

        try:
            self.assert_title(title, **kwargs)
            return True
        except ExpectationNotMet:
            return False

Checks if the page has the given title.

Args:
title (str | RegexObject): The string or regex that the title should match.
**kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.

Returns:
bool: Whether it matches.


def draw_text(img, pos, text, color, font_scale=0.4):
    img = img.astype(np.uint8)
    (x0, y0) = (int(pos[0]), int(pos[1]))
    font = cv2.FONT_HERSHEY_SIMPLEX
    ((text_w, text_h), _) = cv2.getTextSize(text, font, font_scale, 1)
    if ((x0 + text_w) > img.shape[1]):
        x0 = (img.shape[1] - text_w)
    if ((y0 - int((1.15 * text_h))) < 0):
        y0 = int((1.15 * text_h))
    back_topleft = (x0, (y0 - int((1.3 * text_h))))
    back_bottomright = ((x0 + text_w), y0)
    cv2.rectangle(img, back_topleft, back_bottomright, color, (- 1))
    text_bottomleft = (x0, (y0 - int((0.25 * text_h))))
    cv2.putText(img, text, text_bottomleft, font, font_scale, (222, 222, 222), lineType=cv2.LINE_AA)
    return img

Draw text on an image.

Args:
pos (tuple): x, y; the position of the text
text (str):
font_scale (float):
color (tuple): a 3-tuple BGR color in [0, 255]


def run(self, gin):

        with ScratchDir("."):
            p = subprocess.Popen(
                self._gulp_cmd, stdout=subprocess.PIPE,
                stdin=subprocess.PIPE, stderr=subprocess.PIPE
            )

            out, err = p.communicate(bytearray(gin, "utf-8"))
            out = out.decode("utf-8")
            err = err.decode("utf-8")

            if "Error" in err or "error" in err:
                print(gin)
                print("----output_0---------")
                print(out)
                print("----End of output_0------\n\n\n")
                print("----output_1--------")
                print(out)
                print("----End of output_1------")
                raise GulpError(err)

            if "ERROR" in out:
                raise GulpError(out)

            conv_err_string = "Conditions for a minimum have not been satisfied"
            if conv_err_string in out:
                raise GulpConvergenceError()

            gout = ""
            for line in out.split("\n"):
                gout = gout + line + "\n"
            return gout

Run GULP using the gin as input

Args:
gin: GULP input string

Returns:
gout: GULP output string


async def init(self, name, conf=None):
    tank = self.tanks.get(name)
    if (tank is not None):
        return tank
    iden = s_common.guid()
    logger.info('Creating new tank: %s', name)
    path = s_common.genpath(self.dirn, 'tanks', iden)
    tank = (await CryoTank.anit(path, conf))
    node = (await self.names.open((name,)))
    (await node.set((iden, conf)))
    self.tanks.put(name, tank)
    return tank

Generate a new CryoTank with a given name or get an reference to an existing CryoTank.

Args:
name (str): Name of the CryoTank.

Returns:
CryoTank: A CryoTank instance.


def load_disease_terms(adapter, genemap_lines, genes=None, hpo_disease_lines=None):
    if (not genes):
        genes = adapter.genes_by_alias()
    disease_terms = get_mim_phenotypes(genemap_lines=genemap_lines)
    if (not hpo_disease_lines):
        hpo_disease_lines = fetch_hpo_phenotype_to_terms()
    hpo_diseases = parse_hpo_diseases(hpo_disease_lines)
    start_time = datetime.now()
    nr_diseases = None
    LOG.info('Loading the hpo disease...')
    for (nr_diseases, disease_number) in enumerate(disease_terms):
        disease_info = disease_terms[disease_number]
        disease_id = 'OMIM:{0}'.format(disease_number)
        if (disease_id in hpo_diseases):
            hpo_terms = hpo_diseases[disease_id]['hpo_terms']
            if hpo_terms:
                disease_info['hpo_terms'] = hpo_terms
        disease_obj = build_disease_term(disease_info, genes)
        adapter.load_disease_term(disease_obj)
    LOG.info('Loading done. Nr of diseases loaded {0}'.format(nr_diseases))
    LOG.info('Time to load diseases: {0}'.format((datetime.now() - start_time)))

Load the omim phenotypes into the database

Parse the phenotypes from genemap2.txt and find the associated hpo terms
from ALL_SOURCES_ALL_FREQUENCIES_diseases_to_genes_to_phenotypes.txt.

Args:
adapter(MongoAdapter)
genemap_lines(iterable(str))
genes(dict): Dictionary with all genes found in database
hpo_disease_lines(iterable(str))


def contains(self, key):
    try:
        self._api.objects_get(self._bucket, key)
    except datalab.utils.RequestException as e:
        if (e.status == 404):
            return False
        raise e
    except Exception as e:
        raise e
    return True

Checks if the specified item exists.

Args:
key: the key of the item to lookup.
Returns:
True if the item exists; False otherwise.
Raises:
Exception if there was an error requesting information about the item.


def is_compatible(self, other: 'ValueSpec') -> bool:

Returns True if values acceptable to `other` is acceptable to this spec.

Args:
other: Other value spec.

Returns:
True if values that is applicable to the other value spec can be applied
to current spec. Otherwise False.


def list_(return_yaml=True, include_pillar=True, include_opts=True, **kwargs):
    beacons = None
    try:
        eventer = salt.utils.event.get_event('minion', opts=__opts__)
        res = __salt__['event.fire']({'func': 'list', 'include_pillar': include_pillar, 'include_opts': include_opts}, 'manage_beacons')
        if res:
            event_ret = eventer.get_event(tag='/salt/minion/minion_beacons_list_complete', wait=kwargs.get('timeout', 30))
            log.debug('event_ret %s', event_ret)
            if (event_ret and event_ret['complete']):
                beacons = event_ret['beacons']
    except KeyError:
        ret = {'comment': 'Event module not available. Beacon list failed.', 'result': False}
        return ret
    if beacons:
        if return_yaml:
            tmp = {'beacons': beacons}
            return salt.utils.yaml.safe_dump(tmp, default_flow_style=False)
        else:
            return beacons
    else:
        return {'beacons': {}}

List the beacons currently configured on the minion.

Args:

return_yaml (bool):
Whether to return YAML formatted output, default ``True``.

include_pillar (bool):
Whether to include beacons that are configured in pillar, default
is ``True``.

include_opts (bool):
Whether to include beacons that are configured in opts, default is
``True``.

Returns:
list: List of currently configured Beacons.

CLI Example:

.. code-block:: bash

salt '*' beacons.list


class AutoformerFeatureEmbedder(nn.Module):

    def __init__(self, cardinalities: List[int], embedding_dims: List[int]) -> None:
        super().__init__()
        self.num_features = len(cardinalities)
        self.embedders = nn.ModuleList([nn.Embedding(c, d) for c, d in zip(cardinalities, embedding_dims)])

    def forward(self, features: torch.Tensor) -> torch.Tensor:
        if self.num_features > 1:
            cat_feature_slices = torch.chunk(features, self.num_features, dim=-1)
        else:
            cat_feature_slices = [features]
        return torch.cat([embed(cat_feature_slice.squeeze(-1)) for embed, cat_feature_slice in zip(self.embedders, cat_feature_slices)], dim=-1)

Embed a sequence of categorical features.

Args:
cardinalities (`list[int]`):
List of cardinalities of the categorical features.
embedding_dims (`list[int]`):
List of embedding dimensions of the categorical features.


def _ContainsNone(self, fail_verb, excluded):
    present = []
    if len(excluded) == 1:
        if excluded[0] in self._actual:
            present.extend(excluded)
    elif excluded:
        try:
            actual_set = set(self._actual)
        except TypeError:
            actual_set = self._actual
        for i in excluded:
            if i in actual_set:
                present.append(i)
    if present:
        self._FailWithBadResults(fail_verb, excluded, 'contains', present)

Determines if the subject contains none of the excluded elements.

Helper function for ContainsNoneIn() and ContainsNoneOf().

Args:
fail_verb: string describing how the excluded elements should be excluded.
excluded: iterable of objects that should not be contained in the subject.

Returns:
None if the subject contains none of the expected elements.

Raises:
TruthAssertionError: the subject contains any of the excluded elements.


def read(in_path):
    assert os.path.exists(in_path), "The following GRP file can't be found. in_path: {}".format(in_path)
    with open(in_path, 'r') as f:
        lines = f.readlines()
        grp = [line.strip() for line in lines if (line and (not re.match('^
    return grp

Read a grp file at the path specified by in_path.

Args:
in_path (string): path to GRP file

Returns:
grp (list)


def validate(self, proxy_scanner, expected_num=20, queue_timeout=3, val_timeout=5):
    while (self.proxy_num() < expected_num):
        try:
            candidate_proxy = proxy_scanner.proxy_queue.get(timeout=queue_timeout)
        except queue.Empty:
            if proxy_scanner.is_scanning():
                continue
            else:
                break
        addr = candidate_proxy['addr']
        protocol = candidate_proxy['protocol']
        ret = self.is_valid(addr, protocol, val_timeout)
        if (self.proxy_num() >= expected_num):
            self.logger.info('Enough valid proxies, thread {} exit.'.format(threading.current_thread().name))
            break
        if ret['valid']:
            self.add_proxy(Proxy(addr, protocol))
            self.logger.info('{} ok, {:.2f}s'.format(addr, ret['response_time']))
        else:
            self.logger.info('{} invalid, {}'.format(addr, ret['msg']))

Target function of validation threads

Args:
proxy_scanner: A ProxyScanner object.
expected_num: Max number of valid proxies to be scanned.
queue_timeout: Timeout for getting a proxy from the queue.
val_timeout: An integer passed to `is_valid` as argument `timeout`.


def __init__(self, task_queue, verbose=True):

        multiprocessing.Process.__init__(self)
        self._task_queue = task_queue
        self.total_task = self._task_queue.qsize()
        self.current_state = None
        self.verbose = verbose

Construct an instance of TaskTracker

Args:
task_queue (multiprocessing.JoinableQueue): A queue of the
input data.
verbose (bool, optional): Set to False to disable verbose output.


def _update_task(self, task):
    self.task = task
    self.task.data.update(self.task_data)
    self.task_type = task.task_spec.__class__.__name__
    self.spec = task.task_spec
    self.task_name = task.get_name()
    self.activity = getattr(self.spec, 'service_class', '')
    self._set_lane_data()

Assigns current task step to self.task
then updates the task's data with self.task_data

Args:
task: Task object.


def check_partitioners(partitioners, keys):
    if (partitioners is None):
        return {}
    _assert_is_dictlike(partitioners, valid_keys=keys)
    keys = set(keys)
    if (not (set(partitioners) <= keys)):
        extra_keys = (set(partitioners) - keys)
        raise KeyError('Invalid partitioner keys {}, partitioners can only be provided for {}'.format(', '.join(("'{}'".format(key) for key in extra_keys)), ', '.join(("'{}'".format(key) for key in keys))))
    _check_nested_callables(partitioners, 'Partitioner')
    return partitioners

Checks the given partitioners.

This checks that `partitioners` is a dictionary that only contains keys in
`keys`, and furthermore the entries in `partitioners` are functions or
further dictionaries (the latter used, for example, in passing partitioners
to modules inside modules) that must satisfy the same constraints.

Args:
partitioners: Dictionary of partitioners (allowing nested dictionaries) or
None.
keys: Iterable of valid keys for `partitioners`.

Returns:
Checked dictionary of partitioners. If `partitioners=None`, an empty
dictionary will be returned.

Raises:
KeyError: If an partitioner is provided for a key not in `keys`.
TypeError: If a provided partitioner is not a callable function, or
`partitioners` is not a Mapping.


def most_recent(path, startswith=None, endswith=None):

    candidate_files = []
    for filename in all_files_in_directory(path):
        if startswith and not os.path.basename(filename).startswith(startswith):
            continue
        if endswith and not filename.endswith(endswith):
            continue
        candidate_files.append({'name': filename, 'modtime': os.path.getmtime(filename)})

    most_recent = sorted(candidate_files, key=lambda k: k['modtime'], reverse=True)
    return most_recent[0]['name'] if most_recent else None

Recursively inspect all files under a directory and return the most recent

Args:
path (str): the path of the directory to traverse
startswith (str): the file name start with (optional)
endswith (str): the file name ends with (optional)
Returns:
the most recent file within the subdirectory


def remove(self, keys, name=None):
    if keys.dtype != self._key_dtype:
        raise TypeError(f'Dtype of argument `keys` must be {self._key_dtype}, received: {keys.dtype}')
    with ops.name_scope(name, '%s_lookup_table_remove' % self.name, (self.resource_handle, keys, self._default_value)):
        op = gen_lookup_ops.lookup_table_remove_v2(self.resource_handle, keys)
    return op

Removes `keys` and its associated values from the table.

If a key is not present in the table, it is silently ignored.

Args:
keys: Keys to remove. Can be a tensor of any shape. Must match the table's
key type.
name: A name for the operation (optional).

Returns:
The created Operation.

Raises:
TypeError: when `keys` do not match the table data types.


def copy_results(self, copy_to_dir, rename_model_to=None, force_rerun=False):
    if (not rename_model_to):
        rename_model_to = self.model_to_use
    new_model_path = op.join(copy_to_dir, '{}.pdb'.format(rename_model_to))
    if self.structure_path:
        if ssbio.utils.force_rerun(flag=force_rerun, outfile=new_model_path):
            custom_clean = CleanPDB()
            my_pdb = StructureIO(self.structure_path)
            new_model_path = my_pdb.write_pdb(custom_selection=custom_clean, custom_name=rename_model_to, out_dir=copy_to_dir, force_rerun=force_rerun)
        self.load_structure_path(structure_path=new_model_path, file_type='pdb')
        dest_itasser_dir = op.join(copy_to_dir, '{}_itasser'.format(rename_model_to))
        if (not op.exists(dest_itasser_dir)):
            os.mkdir(dest_itasser_dir)
        for attr in self._attrs_to_copy:
            old_file_path = getattr(self, attr)
            new_file_path = op.join(dest_itasser_dir, op.basename(old_file_path))
            if ssbio.utils.force_rerun(flag=force_rerun, outfile=new_file_path):
                shutil.copy2(old_file_path, new_file_path)
                log.debug('{}: copied from {}'.format(new_file_path, old_file_path))
            else:
                log.debug('{}: file already exists'.format(new_file_path))
            setattr(self, attr, new_file_path)

Copy the raw information from I-TASSER modeling to a new folder.

Copies all files in the list _attrs_to_copy.

Args:
copy_to_dir (str): Directory to copy the minimal set of results per sequence.
rename_model_to (str): New file name (without extension)
force_rerun (bool): If existing models and results should be overwritten.


def __init__(self):
    self._last_step_outputs = {}
    self._last_step_outputs_reduce_ops = {}
    self._non_tensor_outputs = {}

Initialize an output context.

Returns:
A context object.


async def is_try_or_pull_request(context, task):

    if is_github_task(task):
        return await is_pull_request(context, task)
    else:
        return is_try(task, context.config['source_env_prefix'])

Determine if a task is a try or a pull-request-like task (restricted privs).

Checks are the ones done in ``is_try`` and ``is_pull_request``

Args:
context (scriptworker.context.Context): the scriptworker context.
task (dict): the task definition to check.

Returns:
bool: True if it's a pull-request or a try task


def _MergeIdenticalCaseInsensitive(self, a, b):
    if (a.lower() != b.lower()):
        raise MergeError(("values must be the same (case insensitive) ('%s' vs '%s')" % (transitfeed.EncodeUnicode(a), transitfeed.EncodeUnicode(b))))
    return b

Tries to merge two strings.

The string are required to be the same ignoring case. The second string is
always used as the merged value.

Args:
a: The first string.
b: The second string.

Returns:
The merged string. This is equal to the second string.

Raises:
MergeError: The strings were not the same ignoring case.


def reset_logger(name, level=None, handler=None):

  if level is None:
    level = logging.INFO
  logger = logging.getLogger(name)
  logger.setLevel(level)

  handler = handler or logging.StreamHandler()
  handler.setFormatter(logging.Formatter(_DEFAULT_LOG_FORMAT))

  logger.handlers = [handler]
  return logger

Make a standard python logger object with default formatter, handler, etc.

Defaults are:
- level == logging.INFO
- handler == logging.StreamHandler()

Args:
name: a logger name.
level: an optional initial log level for this logger.
handler: an optional initial handler for this logger.

Returns: a standard python logger with a single handler.


def genes_by_alias(hgnc_genes):
    alias_genes = {}
    for hgnc_id in hgnc_genes:
        gene = hgnc_genes[hgnc_id]
        hgnc_symbol = gene['hgnc_symbol']
        for alias in gene['previous_symbols']:
            true_id = None
            if (alias == hgnc_symbol):
                true_id = hgnc_id
            if (alias in alias_genes):
                alias_genes[alias.upper()]['ids'].add(hgnc_id)
                if true_id:
                    alias_genes[alias.upper()]['true_id'] = hgnc_id
            else:
                alias_genes[alias.upper()] = {'true': true_id, 'ids': set([hgnc_id])}
    return alias_genes

Return a dictionary with hgnc symbols as keys

Value of the dictionaries are information about the hgnc ids for a symbol.
If the symbol is primary for a gene then 'true_id' will exist.
A list of hgnc ids that the symbol points to is in ids.

Args:
hgnc_genes(dict): a dictionary with hgnc_id as key and gene info as value

Returns:
alias_genes(dict):
{
'hgnc_symbol':{
'true_id': int,
'ids': list(int)
}
}


def is_stopped(self):
    resp = self._client.send(Request(action='is_dag_stopped', payload={'dag_name': self._dag_name}))
    return resp.payload['is_stopped']

Check whether the task received a stop signal from the workflow.

Tasks can use the stop flag to gracefully terminate their work. This is
particularly important for long running tasks and tasks that employ an
infinite loop, such as trigger tasks.

Returns:
bool: True if the task should be stopped.


def dispatch(self, message):

        for validator, callback in self.validators:
            if not validator.matches(message):
                continue

            callback(message)
            return

        raise ArgumentError("No handler was registered for message", message=message)

Dispatch a message to a callback based on its schema.

Args:
message (dict): The message to dispatch


def register(self, cmd: Type[Command]) -> None:
    self.commands[cmd.command] = cmd

Register a new IMAP command.

Args:
cmd: The new command type.


def editline_with_regex(self, regex_tgtline, to_replace):
    for (idx, line) in enumerate(self._swp_lines):
        mobj = re.match(regex_tgtline, line)
        if mobj:
            self._swp_lines[idx] = to_replace
            return

find the first matched line, then replace

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


def exists(self, path):

        self.__validate_storage_path(path)
        try:
            metadata = self.api_client.get_entity_by_query(path=path)
        except StorageNotFoundException:
            return False

        return metadata and 'uuid' in metadata

Check if a certain path exists in the storage service.

Args:
path (str): The path to be checked

Returns:
True if the path exists, False otherwise

Raises:
StorageArgumentException: Invalid arguments
StorageForbiddenException: Server response code 403
StorageNotFoundException: Server response code 404
StorageException: other 400-600 error codes


def get_lock_state_transaction(self, transaction_id):

        response = None
        try:
            response = requests.get(
                urls.get_lockstate_transaction(self._giid, transaction_id),
                headers={
                    'Accept': 'application/json, text/javascript, */*; q=0.01',
                    'Cookie': 'vid={}'.format(self._vid)})
        except requests.exceptions.RequestException as ex:
            raise RequestError(ex)
        _validate_response(response)
        return json.loads(response.text)

Get lock state transaction status

Args:
transaction_id: Transaction ID received from set_lock_state


def ping(hostname: str, timeout_s: int = 5) -> bool:

    if sys.platform == "win32":
        timeout_ms = timeout_s * 1000
        args = [
            "ping",
            hostname,
            "-n", "1",
            "-w", str(timeout_ms),
        ]
    elif sys.platform.startswith('linux'):
        args = [
            "ping",
            hostname,
            "-c", "1",
            "-w", str(timeout_s),
        ]
    else:
        raise AssertionError("Don't know how to ping on this operating system")
    proc = subprocess.Popen(args,
                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    proc.communicate()
    retcode = proc.returncode
    return retcode == 0

Pings a host, using OS tools.

Args:
hostname: host name or IP address
timeout_s: timeout in seconds

Returns:
was the ping successful?


def setup_config(cfg, config_filenames=None, env_var_name=None):
    if (env_var_name is None):
        env_var_name = 'BB_CONFIG_FILE'
    config_path = os.getenv(env_var_name, None)
    if (not config_path):
        config_path = find_config(defaults=config_filenames)
    if config_path:
        cfg.load(config_path)
        cfg['config_file'] = os.path.abspath(config_path)
    cfg.init_from_env()

This will initialize the given configuration object.

The following resources are available in the same order:
1) Default settings.
2) Config file.
3) Environment variables.

WARNING: Environment variables do _not_ take precedence over the config
file right now. (init_from_env will refuse to update the
value, if there is already one.)

Args:
config_filenames: list of possible config filenames
env_var_name: name of the environment variable holding the config path


def get_diff(repo: Repo, base_commit: str, commits: List[str]) -> List[str]:
    print('\n
    code_diff = []
    for commit in commits:
        for diff_obj in commit.diff(base_commit):
            if diff_obj.change_type == 'A' and diff_obj.b_path.endswith('.py'):
                code_diff.append(diff_obj.b_path)
            elif diff_obj.change_type == 'D' and diff_obj.a_path.endswith('.py'):
                code_diff.append(diff_obj.a_path)
            elif diff_obj.change_type in ['M', 'R'] and diff_obj.b_path.endswith('.py'):
                if diff_obj.a_path != diff_obj.b_path:
                    code_diff.extend([diff_obj.a_path, diff_obj.b_path])
                elif diff_is_docstring_only(repo, commit, diff_obj.b_path):
                    print(f'Ignoring diff in {diff_obj.b_path} as it only concerns docstrings or comments.')
                else:
                    code_diff.append(diff_obj.a_path)
    return code_diff

Get the diff between a base commit and one or several commits.

Args:
repo (`git.Repo`):
A git repository (for instance the Transformers repo).
base_commit (`str`):
The commit reference of where to compare for the diff. This is the current commit, not the branching point!
commits (`List[str]`):
The list of commits with which to compare the repo at `base_commit` (so the branching point).

Returns:
`List[str]`: The list of Python files with a diff (files added, renamed or deleted are always returned, files
modified are returned if the diff in the file is not only in docstrings or comments, see
`diff_is_docstring_only`).


def wait_until_final(self, poll_interval=1, timeout=60):
    start_time = time.time()
    elapsed = 0
    while ((self.status != 'complete') and ((timeout <= 0) or (elapsed < timeout))):
        time.sleep(poll_interval)
        self.refresh()
        elapsed = (time.time() - start_time)

It will poll the URL to grab the latest status resource in a given
timeout and time interval.

Args:
poll_interval (int): how often to poll the status service.
timeout (int): how long to poll the URL until giving up. Use <= 0
to wait forever


def create_feed_dict_from_input_data(input_data: RepresentativeSample, signature_def: meta_graph_pb2.SignatureDef) -> Mapping[str, np.ndarray]:
    feed_dict = {}
    for input_key, input_value in input_data.items():
        input_tensor_name = signature_def.inputs[input_key].name
        value = input_value
        if isinstance(input_value, core.Tensor):
            value = input_value.eval()
        feed_dict[input_tensor_name] = value
    return feed_dict

Constructs a feed_dict from input data.

Note: This function should only be used in graph mode.

This is a helper function that converts an 'input key -> input value' mapping
to a feed dict. A feed dict is an 'input tensor name -> input value' mapping
and can be directly passed to the `feed_dict` argument of `sess.run()`.

Args:
input_data: Input key -> input value mapping. The input keys should match
the input keys of `signature_def`.
signature_def: A SignatureDef representing the function that `input_data` is
an input to.

Returns:
Feed dict, which is intended to be used as input for `sess.run`. It is
essentially a mapping: input tensor name -> input value. Note that the input
value in the feed dict is not a `Tensor`.


def get_extra_args():
    g = ops.get_default_graph()
    if isinstance(g, _FuncGraph):
        return g.extra_args
    else:
        return []

Returns the corresponding function arguments for the captured inputs.

Returns:
If the default graph is being used to define a function, the
returned list of place holders are those used inside the function
body corresponding those returned by get_extra_inputs(). Otherwise,
returns an empty list.


def get(self, item, alt=None):

        try:
            val = self[item]
        except ValueError:
            return alt

        return val if val is not None else alt

Standard dict-like .get() method.

Args:
item (str): See :meth:`.__getitem__` for details.
alt (default None): Alternative value, if item is not found.

Returns:
obj: `item` or `alt`, if item is not found.


def get_train_examples(self, data_dir, filename=None):
    if data_dir is None:
        data_dir = ''
    if self.train_file is None:
        raise ValueError('SquadProcessor should be instantiated via SquadV1Processor or SquadV2Processor')
    with open(os.path.join(data_dir, self.train_file if filename is None else filename), 'r', encoding='utf-8') as reader:
        input_data = json.load(reader)['data']
    return self._create_examples(input_data, 'train')

Returns the training examples from the data directory.

Args:
data_dir: Directory containing the data files used for training and evaluating.
filename: None by default, specify this if the training file has a different name than the original one
which is `train-v1.1.json` and `train-v2.0.json` for squad versions 1.1 and 2.0 respectively.


def ExtractEvents(
      self, parser_mediator, registry_key, codepage='cp1252', **kwargs):

    self._ParseSubKey(parser_mediator, registry_key, [], codepage=codepage)

Extracts events from a Windows Registry key.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
codepage (Optional[str]): extended ASCII string codepage.


def moments_v2(x, axes, shift=None, keepdims=False, name=None):
    return moments(x=x, axes=axes, shift=shift, name=name, keep_dims=keepdims)

Calculates the mean and variance of `x`.

The mean and variance are calculated by aggregating the contents of `x`
across `axes`.  If `x` is 1-D and `axes = [0]` this is just the mean
and variance of a vector.

Note: shift is currently not used; the true mean is computed and used.

When using these moments for batch normalization (see
`tf.nn.batch_normalization`):

* for so-called "global normalization", used with convolutional filters with
shape `[batch, height, width, depth]`, pass `axes=[0, 1, 2]`.
* for simple batch normalization pass `axes=[0]` (batch only).

Args:
x: A `Tensor`.
axes: Array of ints.  Axes along which to compute mean and
variance.
shift: Not used in the current implementation.
keepdims: produce moments with the same dimensionality as the input.
name: Name used to scope the operations that compute the moments.

Returns:
Two `Tensor` objects: `mean` and `variance`.


def init_log(log_file):

    log = None
    try:
        log = open(log_file, 'a')

        sys.stdout = Tee(sys.stdout, log)
    except:
        pass
    return log

Creates log file on disk and "Tees" :py:class:`sys.stdout` to console and disk

Args:
log_file (str): The path on disk to append or create the log file.

Returns:
file: The opened log file.


def intersect(self, second_iterable, selector=identity):
    if self.closed():
        raise ValueError('Attempt to call intersect() on a closed Queryable.')
    if (not is_iterable(second_iterable)):
        raise TypeError('Cannot compute intersect() with second_iterable of non-iterable {0}'.format(str(type(second_iterable))[7:(- 1)]))
    if (not is_callable(selector)):
        raise TypeError('intersect() parameter selector={0} is not callable'.format(repr(selector)))
    return self._create(self._generate_intersect_result(second_iterable, selector))

Returns those elements which are both in the source sequence and in
the second_iterable.

Note: This method uses deferred execution.

Args:
second_iterable: Elements are returned if they are also in the
sequence.

selector: An optional single argument function which is used to
project the elements in the source and second_iterables prior
to comparing them. If omitted the identity function will be
used.

Returns:
A sequence containing all elements in the source sequence  which
are also members of the second sequence.

Raises:
ValueError: If the Queryable has been closed.
TypeError: If the second_iterable is not in fact iterable.
TypeError: If the selector is not callable.


def success(channel, image, hex_str):

    hex_number = int(hex_str, 16)

    gui = ui_embed.UI(
        channel,
        "",
        "
        modulename=modulename,
        colour=hex_number,
        thumbnail=image,
    )

    return gui

Creates an embed UI containing a hex color message

Args:
channel (discord.Channel): The Discord channel to bind the embed to
image (str): The url of the image to add
hex_str (str): The hex value

Returns:
ui (ui_embed.UI): The embed UI object that was created


def is_back_tracking(neurite):

    def pair(segs):
        ' Pairs the input list into triplets'
        return zip(segs, segs[1:])

    def coords(node):
        ' Returns the first three values of the tree that correspond to the x, y, z coordinates'
        return node[COLS.XYZ]

    def max_radius(seg):
        ' Returns maximum radius from the two segment endpoints'
        return max(seg[0][COLS.R], seg[1][COLS.R])

    def is_not_zero_seg(seg):
        ' Returns True if segment has zero length'
        return (not np.allclose(coords(seg[0]), coords(seg[1])))

    def is_in_the_same_verse(seg1, seg2):
        ' Checks if the vectors face the same direction. This\n        is true if their dot product is greater than zero.\n        '
        v1 = (coords(seg2[1]) - coords(seg2[0]))
        v2 = (coords(seg1[1]) - coords(seg1[0]))
        return (np.dot(v1, v2) >= 0)

    def is_seg2_within_seg1_radius(dist, seg1, seg2):
        ' Checks whether the orthogonal distance from the point at the end of\n        seg1 to seg2 segment body is smaller than the sum of their radii\n        '
        return (dist <= (max_radius(seg1) + max_radius(seg2)))

    def is_seg1_overlapping_with_seg2(seg1, seg2):
        'Checks if a segment is in proximity of another one upstream'
        s1 = coords(seg2[0])
        s2 = coords(seg2[1])
        C = (0.5 * (s1 + s2))
        P = coords(seg1[1])
        CP = (P - C)
        S1S2 = (s2 - s1)
        prj = mm.vector_projection(CP, S1S2)
        if (not is_seg2_within_seg1_radius(np.linalg.norm((CP - prj)), seg1, seg2)):
            return False
        return (np.linalg.norm(prj) < (0.55 * np.linalg.norm(S1S2)))

    def is_inside_cylinder(seg1, seg2):
        ' Checks if seg2 approximately lies within a cylindrical volume of seg1.\n        Two conditions must be satisfied:\n            1. The two segments are not facing the same direction  (seg2 comes back to seg1)\n            2. seg2 is overlaping with seg1\n        '
        return ((not is_in_the_same_verse(seg1, seg2)) and is_seg1_overlapping_with_seg2(seg1, seg2))
    section_itr = (snode for snode in neurite.iter_sections() if (snode.points.shape[0] > 2))
    for snode in section_itr:
        segment_pairs = list(filter(is_not_zero_seg, pair(snode.points)))
        for (i, seg1) in enumerate(segment_pairs[1:]):
            for seg2 in segment_pairs[0:(i + 1)]:
                if is_inside_cylinder(seg1, seg2):
                    return True
    return False

Check if a neurite process backtracks to a previous node. Back-tracking takes place
when a daughter of a branching process goes back and either overlaps with a previous point, or
lies inside the cylindrical volume of the latter.

Args:
neurite(Neurite): neurite to operate on

Returns:
True Under the following scenaria:
1. A segment endpoint falls back and overlaps with a previous segment's point
2. The geometry of a segment overlaps with a previous one in the section


def sheets_values_batch_update(config, auth, sheet_url_or_name, data):
    sheet_id = sheets_id(config, auth, sheet_url_or_name)
    API_Sheets(config, auth).spreadsheets().values().batchUpdate(spreadsheetId=sheet_id, body=data).execute()

Helper for performing batch value operations.

Args:
config - see starthinker/util/configuration.py
auth - user or service
sheet_url_or_name - one of: URL, document title, or id
data - JSON data for sending to batch request

No Return


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

    model = XResNet(BasicBlock, [2, 2, 2, 2], **kwargs)
    if pretrained: model.load_state_dict(model_zoo.load_url(model_urls['xresnet18']))
    return model

Constructs a XResNet-18 model.

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


def create_tree_from_string(line):

    depth         = 0
    current_word  = ""
    root          = None
    current_node  = root

    for char in line:
        if char == '(':
            if current_node is not None and len(current_word) > 0:
                attribute_text_label(current_node, current_word)
                current_word = ""
            depth += 1
            if depth > 1:

                child = LabeledTree(depth=depth)
                current_node.add_child(child)
                current_node = child
                root.add_general_child(child)
            else:
                root = LabeledTree(depth=depth)
                root.add_general_child(root)
                current_node = root

        elif char == ')':

            if len(current_word) > 0:
                attribute_text_label(current_node, current_word)
                current_word = ""

            depth -= 1
            if current_node.parent != None:
                current_node.parent.udepth = max(current_node.udepth+1, current_node.parent.udepth)
            current_node = current_node.parent
        else:

            current_word += char
    if depth != 0:
        raise ParseError("Not an equal amount of closing and opening parentheses")

    return root

Parse and convert a string representation
of an example into a LabeledTree datastructure.

Arguments:
----------
line : str, string version of the tree.

Returns:
--------
LabeledTree : parsed tree.


def sample_from_discretized_mix_logistic(pred, seed=None):
    (logits, locs, log_scales, coeffs) = split_to_discretized_mix_logistic_params(pred)
    num_mixtures = shape_list(logits)[(- 1)]
    gumbel_noise = (- tf.log((- tf.log(tf.random_uniform(tf.shape(logits), minval=1e-05, maxval=(1.0 - 1e-05), seed=seed)))))
    sel = tf.one_hot(tf.argmax((logits + gumbel_noise), (- 1)), depth=num_mixtures, dtype=tf.float32)
    sel = tf.expand_dims(sel, (- 1))
    locs = tf.reduce_sum((locs * sel), 3)
    log_scales = tf.reduce_sum((log_scales * sel), 3)
    coeffs = tf.reduce_sum((coeffs * sel), 3)
    uniform_noise = tf.random_uniform(tf.shape(locs), minval=1e-05, maxval=(1.0 - 1e-05), seed=seed)
    logistic_noise = (tf.log(uniform_noise) - tf.log1p((- uniform_noise)))
    x = (locs + (tf.exp(log_scales) * logistic_noise))
    x0 = x[(..., 0)]
    x1 = (x[(..., 1)] + (coeffs[(..., 0)] * x0))
    x2 = ((x[(..., 2)] + (coeffs[(..., 1)] * x0)) + (coeffs[(..., 2)] * x1))
    x = tf.stack([x0, x1, x2], axis=(- 1))
    x = tf.clip_by_value(x, (- 1.0), 1.0)
    return x

Sampling from a discretized mixture of logistics.

Args:
pred: A [batch, height, width, num_mixtures*10] tensor of floats
comprising one unconstrained mixture probability, three means
(one per channel), three standard deviations (one per channel),
and three coefficients which linearly parameterize dependence across
channels.
seed: Random seed.

Returns:
A tensor of shape [batch, height, width, 3] with real intensities scaled
between -1 and 1.


def match(self, message) -> bool:
    if (self.to and (message.to != self.to)):
        return False
    if (self.sender and (message.sender != self.sender)):
        return False
    if (self.body and (message.body != self.body)):
        return False
    if (self.thread and (message.thread != self.thread)):
        return False
    for (key, value) in self.metadata.items():
        if (message.get_metadata(key) != value):
            return False
    logger.debug(f'message matched {self} == {message}')
    return True

Returns wether a message matches with this message or not.
The message can be a Message object or a Template object.

Args:
message (spade.message.Message): the message to match to

Returns:
bool: wether the message matches or not


def sample_g_values(self, ngram_keys: torch.LongTensor) -> torch.LongTensor:
    sampling_table_size, = self.sampling_table.shape
    sampling_table = self.sampling_table.reshape((1, 1, sampling_table_size))
    ngram_keys = ngram_keys % sampling_table_size
    return torch.take_along_dim(sampling_table, indices=ngram_keys, dim=2)

Samples g values from Bernoulli distribution.

It is not possible to pass random keys in a vectorized way in torch. Instead
we pre-compute a random sampling table, and use apply modulo table size to
map from ngram keys (int64) to g values.

Args:
ngram_keys (`torch.LongTensor`):
Random keys (batch_size, num_ngrams, depth).

Returns:
G values (batch_size, num_ngrams, depth).


def city(self, value=None):
    if (value is not None):
        try:
            value = str(value)
        except ValueError:
            raise ValueError('value {} need to be of type str for field `city`'.format(value))
        if (',' in value):
            raise ValueError('value should not contain a comma for field `city`')
    self._city = value

Corresponds to IDD Field `city`

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

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


def build_image(registry, image):

    if ':' in image['name']:
        _, tag = image['name'].split(':', 1)
    else:
        _, tag = image['name'], None

    values = {
        'registry': '' if registry is None else registry + '/',
        'image': image['name'],
        'tag': tag,
    }

    if tag is None:
        args = [
            '-t {registry}{image}'.format(**values),
            '-t {registry}{image}:{version}'.format(
                version=versioning.current(),
                **values
            ),
        ]
    else:
        args = ['-t {registry}{image}'.format(**values)]

    if 'file' in image:
        args.append('-f {}'.format(conf.proj_path(image['file'])))

    with conf.within_proj_dir(image.get('path', '.')):
        log.info("Building <33>{registry}<35>/{image}", **values)
        shell.run('docker build {args} .'.format(args=' '.join(args)))

Build docker image.

Args:
registry (str):
The name of the registry this image belongs to. If not given, the
resulting image will have a name without the registry.
image (dict[str, Any]):
The dict containing the information about the built image. This is
the same dictionary as defined in DOCKER_IMAGES variable.


def save_as_json(total: list,
                 name='data.json',
                 sort_by: str = None,
                 no_duplicate=False,
                 order='asc'):

    if sort_by:
        reverse = order == 'desc'
        total = sorted(total, key=itemgetter(sort_by), reverse=reverse)
    if no_duplicate:
        total = [key for key, _ in groupby(total)]
    data = json.dumps(total, ensure_ascii=False)
    Path(name).write_text(data, encoding='utf-8')

Save what you crawled as a json file.

Args:
total (list): Total of data you crawled.
name (str, optional): Defaults to 'data.json'. The name of the file.
sort_by (str, optional): Defaults to None. Sort items by a specific key.
no_duplicate (bool, optional): Defaults to False. If True, it will remove duplicated data.
order (str, optional): Defaults to 'asc'. The opposite option is 'desc'.


def VerifyStructure(self, parser_mediator, line):

    self._last_month = 0
    self._year_use = parser_mediator.GetEstimatedYear()

    key = 'header'

    try:
      structure = self._MAC_WIFI_HEADER.parseString(line)
    except pyparsing.ParseException:
      structure = None

    if not structure:
      key = 'turned_over_header'

      try:
        structure = self._MAC_WIFI_TURNED_OVER_HEADER.parseString(line)
      except pyparsing.ParseException:
        structure = None

    if not structure:
      logger.debug('Not a Mac Wifi log file')
      return False

    time_elements_tuple = self._GetTimeElementsTuple(key, structure)

    try:
      dfdatetime_time_elements.TimeElementsInMilliseconds(
          time_elements_tuple=time_elements_tuple)
    except ValueError:
      logger.debug(
          'Not a Mac Wifi log file, invalid date and time: {0!s}'.format(
              structure.date_time))
      return False

    self._last_month = time_elements_tuple[1]

    return True

Verify that this file is a Mac Wifi log file.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
line (str): line from a text file.

Returns:
bool: True if the line is in the expected format, False if not.


def parse(source):
    if isinstance(source, str):
        return parse_stream(six.StringIO(source))
    else:
        return parse_stream(source)

Parses source code returns an array of instructions suitable for
optimization and execution by a Machine.

Args:
source: A string or stream containing source code.


def _logspace_mean(log_values):

  center = tf.stop_gradient(_sample_max(log_values))

  centered_values = tf.math.exp(log_values - center)

  log_mean_of_values = tf.math.log(_sample_mean(centered_values)) + center

  return log_mean_of_values

Evaluate `Log[E[values]]` in a stable manner.

Args:
log_values:  `Tensor` holding `Log[values]`.

Returns:
`Tensor` of same `dtype` as `log_values`, reduced across dim 0.
`Log[Mean[values]]`.


def resolve(self, keys: Iterable[str]) -> Tuple[Dict[KeySpec, List[str]], List[str]]:
    keys = list(keys)
    input_keyset = set(keys)
    nonconst_key_specs = [k for k in self._fields.keys() if not k.is_const]
    nonconst_keys = {k: [] for k in nonconst_key_specs}
    unmatched_keys = []
    keys_by_key_spec = dict()
    for key in keys:
        if key not in self._fields:
            matched_nonconst_keys = False
            for key_spec in nonconst_key_specs:
                if key_spec.match(key):
                    nonconst_keys[key_spec].append(key)
                    matched_nonconst_keys = True
                    break
            if not matched_nonconst_keys:
                unmatched_keys.append(key)
    for key_spec in self._fields.keys():
        keys = []
        if not key_spec.is_const:
            keys = nonconst_keys.get(key_spec, [])
        elif key_spec in input_keyset:
            keys.append(str(key_spec))
        keys_by_key_spec[key_spec] = keys
    return (keys_by_key_spec, unmatched_keys)

Resolve keys by grouping them by their matched fields.

Args:
keys: A list of string keys.

Returns:
A tuple of matched key results and unmatched keys.
Matched key results are an ordered dict of KeySpec to matched keys,
in field declaration order.
Unmatched keys are strings from input.


def extend(self, *iterables):

        for value in iterables:
            list.extend(self, value)
        return self

Add all values of all iterables at the end of the list

Args:
iterables: iterable which content to add at the end

Example:

>>> from ww import l
>>> lst = l([])
>>> lst.extend([1, 2])
[1, 2]
>>> lst
[1, 2]
>>> lst.extend([3, 4]).extend([5, 6])
[1, 2, 3, 4, 5, 6]
>>> lst
[1, 2, 3, 4, 5, 6]


def filter_values(cls, part_info):
    filtered = []
    for info_list in cls.filter_parts(part_info).values():
        filtered += info_list
    return filtered

Filter the part_info dict list looking for instances of our class

Args:
part_info (dict): {part_name: [Info] or None} as returned from
Controller.run_hook()

Returns:
list: [info] where info is a subclass of cls


def register_read_multiple(self, register_indices):
    num_regs = len(register_indices)
    buf = (ctypes.c_uint32 * num_regs)(*register_indices)
    data = (ctypes.c_uint32 * num_regs)(0)
    statuses = (ctypes.c_uint8 * num_regs)(0)
    res = self._dll.JLINKARM_ReadRegs(buf, data, statuses, num_regs)
    if (res < 0):
        raise errors.JLinkException(res)
    return list(data)

Retrieves the values from the registers specified.

Args:
self (JLink): the ``JLink`` instance
register_indices (list): list of registers to read

Returns:
A list of values corresponding one-to-one for each of the given
register indices.  The returned list of values are the values in
order of which the indices were specified.

Raises:
JLinkException: if a given register is invalid or an error occurs.


def _follow_link(self, link_path_components, link):
    link_path = link.contents
    sep = self._path_separator(link_path)
    if (not self._starts_with_root_path(link_path)):
        components = link_path_components[:(- 1)]
        components.append(link_path)
        link_path = sep.join(components)
    return self.normpath(link_path)

Follow a link w.r.t. a path resolved so far.

The component is either a real file, which is a no-op, or a
symlink. In the case of a symlink, we have to modify the path
as built up so far
/a/b => ../c  should yield /a/../c (which will normalize to /a/c)
/a/b => x     should yield /a/x
/a/b => /x/y/z should yield /x/y/z
The modified path may land us in a new spot which is itself a
link, so we may repeat the process.

Args:
link_path_components: The resolved path built up to the link
so far.
link: The link object itself.

Returns:
(string) The updated path resolved after following the link.

Raises:
IOError: if there are too many levels of symbolic link


def headers(self, headers=None, **kw):

        headers = kw if kw else headers
        self._request.headers = headers
        self.add_matcher(matcher('HeadersMatcher', headers))

Defines a dictionary of arguments.

Header keys are case insensitive.

Arguments:
headers (dict): headers to match.
**headers (dict): headers to match as variadic keyword arguments.

Returns:
self: current Mock instance.


def _ReadStructure(self, file_object, file_offset, data_size, data_type_map, description):
    data = self._ReadData(file_object, file_offset, data_size, description)
    return self._ReadStructureFromByteStream(data, file_offset, data_type_map, description)

Reads a structure.

Args:
file_object (FileIO): file-like object.
file_offset (int): offset of the data relative from the start of
the file-like object.
data_size (int): data size of the structure.
data_type_map (dtfabric.DataTypeMap): data type map of the structure.
description (str): description of the structure.

Returns:
object: structure values object.

Raises:
FileFormatError: if the structure cannot be read.
ValueError: if file-like object or date type map are invalid.