def get_dopants_from_substitution_probabilities(structure, num_dopants=5, threshold=0.001, match_oxi_sign=False):
    els_have_oxi_states = [hasattr(s, 'oxi_state') for s in structure.species]
    if (not all(els_have_oxi_states)):
        raise ValueError('All sites in structure must have oxidation states to predict dopants.')
    sp = SubstitutionPredictor(threshold=threshold)
    subs = [sp.list_prediction([s]) for s in set(structure.species)]
    subs = [{'probability': pred['probability'], 'dopant_species': list(pred['substitutions'].keys())[0], 'original_species': list(pred['substitutions'].values())[0]} for species_preds in subs for pred in species_preds]
    subs.sort(key=(lambda x: x['probability']), reverse=True)
    return _get_dopants(subs, num_dopants, match_oxi_sign)

Get dopant suggestions based on substitution probabilities.

Args:
structure (Structure): A pymatgen structure decorated with
oxidation states.
num_dopants (int): The number of suggestions to return for
n- and p-type dopants.
threshold (float): Probability threshold for substitutions.
match_oxi_sign (bool): Whether to force the dopant and original species
to have the same sign of oxidation state. E.g. If the original site
is in a negative charge state, then only negative dopants will be
returned.

Returns:
(dict): Dopant suggestions, given as a dictionary with keys "n_type" and
"p_type". The suggestions for each doping type are given as a list of
dictionaries, each with they keys:

- "probability": The probability of substitution.
- "dopant_species": The dopant species.
- "original_species": The substituted species.


def view(self, viewer=None, use_curr_dir=False):
    if (viewer is None):
        viewer = settings['defaults']['viewer']
    if use_curr_dir:
        TEMP_DIR = os.path.curdir
    else:
        TEMP_DIR = tempfile.gettempdir()

    def give_filename(i):
        filename = (('ChemCoord_' + str(i)) + '.xyz')
        return os.path.join(TEMP_DIR, filename)
    i = 1
    while os.path.exists(give_filename(i)):
        i = (i + 1)
    self.to_xyz(give_filename(i))

    def open_file(i):
        'Open file and close after being finished.'
        try:
            subprocess.check_call([viewer, give_filename(i)])
        except (subprocess.CalledProcessError, FileNotFoundError):
            raise
        finally:
            if use_curr_dir:
                pass
            else:
                os.remove(give_filename(i))
    Thread(target=open_file, args=(i,)).start()

View your molecule.

.. note:: This function writes a temporary file and opens it with
an external viewer.
If you modify your molecule afterwards you have to recall view
in order to see the changes.

Args:
viewer (str): The external viewer to use. If it is None,
the default as specified in cc.settings['defaults']['viewer']
is used.
use_curr_dir (bool): If True, the temporary file is written to
the current diretory. Otherwise it gets written to the
OS dependendent temporary directory.

Returns:
None:


def update(self, rec=None, drop=None, tables=None, install=None, materialize=None, indexes=None, joins=0, views=0):
    if (not drop):
        drop = []
    if (not tables):
        tables = set()
    if (not install):
        install = set()
    if (not materialize):
        materialize = set()
    if (not indexes):
        indexes = set()
    if rec:
        self.update(drop=rec.drop, tables=rec.tables, install=rec.install, materialize=rec.materialize, indexes=rec.indexes, joins=rec.joins)
    self.drop += drop
    self.tables |= set(tables)
    self.install |= set(install)
    self.materialize |= set(materialize)
    self.indexes |= set(indexes)
    self.joins += joins
    self.views += views
    if ((self.joins > 0) or (self.views > 0)):
        self.materialize |= self.install
        self.install = set()

Updates current record.

Args:
rec (FIMRecord):


def __cloudflare_list_zones(self, *, account, **kwargs):

        done = False
        zones = []
        page = 1

        while not done:
            kwargs['page'] = page
            response = self.__cloudflare_request(account=account, path='/zones', args=kwargs)
            info = response['result_info']

            if 'total_pages' not in info or page == info['total_pages']:
                done = True
            else:
                page += 1

            zones += response['result']

        return zones

Helper function to list all zones registered in the CloudFlare system. Returns a `list` of the zones

Args:
account (:obj:`CloudFlareAccount`): A CloudFlare Account object
**kwargs (`dict`): Extra arguments to pass to the API endpoint

Returns:
`list` of `dict`


def get_or_search(self) -> List[GridQubit]:
    if (not self._sequence):
        self._sequence = self._find_sequence()
    return self._sequence

Starts the search or gives previously calculated sequence.

Returns:
The linear qubit sequence found.


async def _catch_response(self, h11_connection):
    response = (await self._recv_event(h11_connection))
    resp_data = {'encoding': self.encoding, 'method': self.method, 'status_code': response.status_code, 'reason_phrase': str(response.reason, 'utf-8'), 'http_version': str(response.http_version, 'utf-8'), 'headers': c_i_dict([(str(name, 'utf-8'), str(value, 'utf-8')) for (name, value) in response.headers]), 'body': b'', 'url': self.req_url}
    for header in response.headers:
        if (header[0] == b'set-cookie'):
            try:
                resp_data['headers']['set-cookie'].append(str(header[1], 'utf-8'))
            except (KeyError, AttributeError):
                resp_data['headers']['set-cookie'] = [str(header[1], 'utf-8')]
    get_body = False
    try:
        if (int(resp_data['headers']['content-length']) > 0):
            get_body = True
    except KeyError:
        try:
            if ('chunked' in resp_data['headers']['transfer-encoding'].lower()):
                get_body = True
        except KeyError:
            if (resp_data['headers'].get('connection', '').lower() == 'close'):
                get_body = True
    if get_body:
        if (self.callback is not None):
            endof = (await self._body_callback(h11_connection))
        elif self.stream:
            if (not (((self.scheme == self.initial_scheme) and (self.host == self.initial_netloc)) or (resp_data['headers']['connection'].lower() == 'close'))):
                self.sock._active = False
            resp_data['body'] = StreamBody(h11_connection, self.sock, resp_data['headers'].get('content-encoding', None), resp_data['encoding'])
            self.streaming = True
        else:
            while True:
                data = (await self._recv_event(h11_connection))
                if isinstance(data, h11.Data):
                    resp_data['body'] += data.data
                elif isinstance(data, h11.EndOfMessage):
                    break
    else:
        endof = (await self._recv_event(h11_connection))
        assert isinstance(endof, h11.EndOfMessage)
    if self.streaming:
        return StreamResponse(**resp_data)
    return Response(**resp_data)

Instantiates the parser which manages incoming data, first getting
the headers, storing cookies, and then parsing the response's body,
if any.

This function also instances the Response class in which the response
status line, headers, cookies, and body is stored.

It should be noted that in order to remain preformant, if the user
wishes to do any file IO it should use async files or risk long wait
times and risk connection issues server-side when using callbacks.

If a callback is used, the response's body will be None.

Returns:
The most recent response object.


def sort_objects(objects: List[Any], key: Optional[Callable[[Any], str]]=None) -> List[Any]:

    def noop(x):
        return x
    if key is None:
        key = noop
    constants = [obj for obj in objects if key(obj).isupper()]
    classes = [obj for obj in objects if key(obj)[0].isupper() and (not key(obj).isupper())]
    functions = [obj for obj in objects if not key(obj)[0].isupper()]
    key1 = ignore_underscore_and_lowercase(key)
    return sorted(constants, key=key1) + sorted(classes, key=key1) + sorted(functions, key=key1)

Sort a list of objects following the rules of isort (all uppercased first, camel-cased second and lower-cased
last).

Args:
objects (`List[Any]`):
The list of objects to sort.
key (`Callable[[Any], str]`, *optional*):
A function taking an object as input and returning a string, used to sort them by alphabetical order.
If not provided, will default to noop (so a `key` must be provided if the `objects` are not of type string).

Returns:
`List[Any]`: The sorted list with the same elements as in the inputs


def ConvertDateTimeToOffset(date_time_value):

  date_time_obj = datetime(int(date_time_value['date']['year']),
                           int(date_time_value['date']['month']),
                           int(date_time_value['date']['day']),
                           int(date_time_value['hour']),
                           int(date_time_value['minute']),
                           int(date_time_value['second']))
  date_time_str = pytz.timezone(
      date_time_value['timeZoneId']).localize(date_time_obj).isoformat()

  if date_time_str[-5:] == '00:00':
    return date_time_str[:-6] + 'Z'
  else:
    return date_time_str

Converts the PQL formatted response for a dateTime object.

Output conforms to ISO 8061 format, e.g. 'YYYY-MM-DDTHH:MM:SSz.'

Args:
date_time_value: dict The date time value from the PQL response.

Returns:
str: A string representation of the date time value uniform to
ReportService.


def read_double(self, little_endian=True):

        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.unpack("%sd" % endian, 8)

Read 8 bytes as a double value from the stream.

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

Returns:
float:


def create_summary_metadata(display_name, description, num_thresholds):
    pr_curve_plugin_data = plugin_data_pb2.PrCurvePluginData(version=PROTO_VERSION, num_thresholds=num_thresholds)
    content = pr_curve_plugin_data.SerializeToString()
    return summary_pb2.SummaryMetadata(display_name=display_name, summary_description=description, plugin_data=summary_pb2.SummaryMetadata.PluginData(plugin_name=PLUGIN_NAME, content=content))

Create a `summary_pb2.SummaryMetadata` proto for pr_curves plugin data.

Arguments:
display_name: The display name used in TensorBoard.
description: The description to show in TensorBoard.
num_thresholds: The number of thresholds to use for PR curves.

Returns:
A `summary_pb2.SummaryMetadata` protobuf object.


def process_tag(self, tag_proc_name, tag):

        tag_processor = self.tag_procs[tag_proc_name]

        db_entry = (tag_processor.get_name(tag),
                    tag_processor.get_entry_type(tag),
                    tag_processor.get_filename(tag))

        self.zeal_db.insert(*db_entry)

        self.entry_count += 1

Process a tag with a tag processor and insert a DB entry.

Args:
tag_proc_name: A string key that maps to the TagProcessor to use.
tag: A BeautifulSoup Tag to process.


def _InverseDistanceWeighted(self, latitude, longitude, radius=1):
    if (radius == 1):
        offsetmatrix = (None, (0, 1), None, ((- 1), 0), (0, 0), (1, 0), None, (0, (- 1)), None)
    elif (radius == 2):
        offsetmatrix = (None, None, (0, 2), None, None, None, ((- 1), 1), (0, 1), (1, 1), None, ((- 2), 0), ((- 1), 0), (0, 0), (1, 0), (2, 0), None, ((- 1), (- 1)), (0, (- 1)), (1, (- 1)), None, None, None, (0, (- 2)), None, None)
    else:
        raise ValueError('Radius {} invalid, expected 1 or 2'.format(radius))
    (row, column) = self.get_row_and_column(latitude, longitude)
    (center_lat, center_long) = self.get_lat_and_long(row, column)
    if ((latitude == center_lat) and (longitude == center_long)):
        return self.get_elevation_from_row_and_column(int(row), int(column))
    weights = 0
    elevation = 0
    for offset in offsetmatrix:
        if ((offset is not None) and (0 <= (row + offset[0]) < self.square_side) and (0 <= (column + offset[1]) < self.square_side)):
            cell = self.get_elevation_from_row_and_column(int((row + offset[0])), int((column + offset[1])))
            if (cell is not None):
                distance = mod_utils.distance(latitude, longitude, (center_lat + (float(offset[0]) / (self.square_side - 1))), (center_long + (float(offset[1]) / (self.square_side - 1))))
                weights += (1 / distance)
                elevation += (cell / distance)
    return (elevation / weights)

Return the Inverse Distance Weighted Elevation.

Interpolate the elevation of the given point using the inverse
distance weigthing algorithm (exp of 1) in the form:
sum((1/distance) * elevation)/sum(1/distance)
for each point in the matrix.
The matrix size is determined by the radius. A radius of 1 uses
5 points and a radius of 2 uses 13 points. The matrices are set
up to use cells adjacent to and including the one that contains
the given point. Any cells referenced by the matrix that are on
neighboring tiles are ignored.

Args:
latitude: float of the latitude in decimal degrees
longitude: float of the longitude in decimal degrees
radius: int of 1 or 2 indicating the size of the matrix

Returns:
a float of the interpolated elevation in the same units as
the underlying .hgt file (meters)

Exceptions:
raises a ValueError if an invalid radius is supplied


class RunOfflineDetector(beam.PTransform[beam.PCollection[NestedKeyedInputT], beam.PCollection[NestedKeyedOutputT]]):

    def __init__(self, offline_detector: OfflineDetector):
        self._offline_detector = offline_detector

    def _restore_and_convert(self, elem: tuple[tuple[Any, Any, beam.Row], Any]) -> NestedKeyedOutputT:

        (orig_key, temp_key, row), prediction = elem
        assert isinstance(prediction, AnomalyPrediction), 'Wrong model handler output type.' + f"Expected: 'AnomalyPrediction', but got '{type(prediction).__name__}'. " + 'Consider adding a post-processing function via `with_postprocess_fn` ' + f"to convert from '{type(prediction).__name__}' to 'AnomalyPrediction', " + 'or use `score_prediction_adapter` or `label_prediction_adapter` to ' + 'perform the conversion.'
        result = AnomalyResult(example=row, predictions=[dataclasses.replace(prediction, model_id=self._offline_detector._model_id)])
        return (orig_key, (temp_key, result))

    def _select_features(self, elem: tuple[Any, beam.Row]) -> tuple[Any, beam.Row]:
        assert self._offline_detector._features is not None
        k, v = elem
        row_dict = v._asdict()
        return (k, beam.Row(**{k: row_dict[k] for k in self._offline_detector._features}))

    def expand(self, input: beam.PCollection[NestedKeyedInputT]) -> beam.PCollection[NestedKeyedOutputT]:
        model_uuid = f'{self._offline_detector._model_id}:{uuid.uuid4().hex[:6]}'
        run_inference = RunInference(self._offline_detector._keyed_model_handler, **self._offline_detector._run_inference_args)
        rekeyed_model_input = input | 'Rekey' >> beam.Map(lambda x: ((x[0], x[1][0], x[1][1]), x[1][1]))
        if self._offline_detector._features is not None:
            rekeyed_model_input = rekeyed_model_input | 'Select Features' >> beam.Map(self._select_features)
        rekeyed_model_output = rekeyed_model_input | f'Call RunInference ({model_uuid})' >> run_inference
        ret = rekeyed_model_output | 'Restore keys and convert model output' >> beam.Map(self._restore_and_convert)
        if self._offline_detector._threshold_criterion:
            ret = ret | f'Run Threshold Criterion ({model_uuid})' >> RunThresholdCriterion(self._offline_detector._threshold_criterion)
        return ret

Runs a offline anomaly detector on a PCollection of data.

This PTransform applies a `OfflineDetector` to the input data, handling
custom input/output conversion and inference.

Args:
offline_detector: The `OfflineDetector` to run.


async def get_matches(self, force_update=False) -> list:

        if force_update or self.matches is None:
            res = await self.connection('GET',
                                        'tournaments/{}/matches'.format(self._id),
                                        include_attachments=1)
            self._refresh_matches_from_json(res)
        return self.matches or []

get all matches (once the tournament is started)

|methcoro|

Args:
force_update (default=False): True to force an update to the Challonge API

Returns:
list[Match]:

Raises:
APIException


def __init__(self, package, ad, config=None):
    super().__init__(package=package, device=ad)
    self.host_port = None
    self.device_port = None
    self.uid = UNKNOWN_UID
    self._adb = ad.adb
    self._user_id = None if config is None else config.user_id
    self._proc = None
    self._client = None
    self._conn = None
    self._event_client = None
    self._config = config or Config()
    self._server_start_stdout = []

Initializes the instance of Snippet Client V2.

Args:
package: str, see base class.
ad: AndroidDevice, the android device object associated with this client.
config: Config, the configuration object. See the docstring of the
`Config` class for supported configurations.


def predict(self, text):
    pred = self.predict_proba(text)
    tags = self._get_tags(pred)
    return tags

Predict using the model.

Args:
text: string, the input text.

Returns:
tags: list, shape = (num_words,)
Returns predicted values.


def write_to_filterbank(self, filename_out):
    print('[Filterbank] Warning: Non-standard function to write in filterbank (.fil) format. Please use Waterfall.')
    n_bytes = int((self.header[b'nbits'] / 8))
    with open(filename_out, 'wb') as fileh:
        fileh.write(generate_sigproc_header(self))
        j = self.data
        if (n_bytes == 4):
            np.float32(j.ravel()).tofile(fileh)
        elif (n_bytes == 2):
            np.int16(j.ravel()).tofile(fileh)
        elif (n_bytes == 1):
            np.int8(j.ravel()).tofile(fileh)

Write data to blimpy file.

Args:
filename_out (str): Name of output file


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

    query_hash = hash(query)

    event_data = WindowsTimelineUserEngagedEventData()
    event_data.package_identifier = self._GetRowValue(
        query_hash, row, 'PackageName')

    payload_json_bytes = bytes(self._GetRowValue(query_hash, row, 'Payload'))
    payload_json_string = payload_json_bytes.decode('utf-8')
    payload = json.loads(payload_json_string)

    if 'reportingApp' in payload:
      event_data.reporting_app = payload['reportingApp']
    if 'activeDurationSeconds' in payload:
      event_data.active_duration_seconds = int(payload['activeDurationSeconds'])

    timestamp = self._GetRowValue(query_hash, row, 'StartTime')
    date_time = dfdatetime_posix_time.PosixTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_START)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a timeline row that describes a user interacting with an app.

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.


def allreduce_grads_hierarchical(all_grads, devices, average=False):
    num_gpu = len(devices)
    assert (num_gpu == 8), num_gpu
    assert (len(all_grads) == num_gpu), len(all_grads)
    group_size = (num_gpu
    agg_all_grads = []
    for (varid, grads) in enumerate(zip(*all_grads)):
        g0_main_gpu = (varid % num_gpu)
        g1_main_gpu = ((g0_main_gpu + group_size) % num_gpu)
        g0_start = (0 if (g0_main_gpu < group_size) else group_size)
        g1_start = (0 if (g1_main_gpu < group_size) else group_size)
        assert (g0_start != g1_start)
        g0_grads = grads[g0_start:(g0_start + group_size)]
        g1_grads = grads[g1_start:(g1_start + group_size)]
        with tf.device(devices[g0_main_gpu]):
            g0_agg = tf.add_n(g0_grads, name='group0_agg')
        with tf.device(devices[g1_main_gpu]):
            g1_agg = tf.add_n(g1_grads, name='group1_agg')
            g1_total_agg = tf.add(g0_agg, g1_agg, name='group1_total_agg')
        with tf.device(devices[g0_main_gpu]):
            g0_total_agg = tf.identity(g1_total_agg, name='group0_total_agg')
        agg_grads = []
        for k in range(num_gpu):
            if ((k < group_size) == (g0_main_gpu < group_size)):
                main_gpu = g0_total_agg
            else:
                main_gpu = g1_total_agg
            with tf.device(devices[k]):
                if (not average):
                    device_total_agg = tf.identity(main_gpu, name='device{}_total_agg'.format(k))
                else:
                    device_total_agg = tf.multiply(main_gpu, (1.0 / num_gpu), name='device{}_total_agg'.format(k))
                agg_grads.append(device_total_agg)
        agg_all_grads.append(agg_grads)
    agg_all_grads = list(zip(*agg_all_grads))
    return agg_all_grads

Hierarchical allreduce for DGX-1 system.

Args:
all_grads (K x N): List of list of gradients. N is the number of variables.
devices ([str]): K str for the K devices.
average (bool): average gradients or not.

Returns:
(K x N): same as input, but each grad is replaced by the average over K lists.


def convert_outlook_msg(msg_bytes):

    if not is_outlook_msg(msg_bytes):
        raise ValueError("The supplied bytes are not an Outlook MSG file")
    orig_dir = os.getcwd()
    tmp_dir = tempfile.mkdtemp()
    os.chdir(tmp_dir)
    with open("sample.msg", "wb") as msg_file:
        msg_file.write(msg_bytes)
    try:
        subprocess.check_call(["msgconvert", "sample.msg"],
                              stdout=null_file, stderr=null_file)
        eml_path = "sample.eml"
        with open(eml_path, "rb") as eml_file:
            rfc822 = eml_file.read()
    except FileNotFoundError:
        raise EmailParserError(
            "Failed to convert Outlook MSG: msgconvert utility not found")
    finally:
        os.chdir(orig_dir)
        shutil.rmtree(tmp_dir)

    return rfc822

Uses the ``msgconvert`` Perl utility to convert an Outlook MS file to
standard RFC 822 format

Args:
msg_bytes (bytes): the content of the .msg file

Returns:
A RFC 822 string


def use_color(setting):
    if (setting not in COLOR_CHOICES):
        raise InvalidColorSetting(setting)
    return ((setting == 'always') or ((setting == 'auto') and sys.stdout.isatty() and terminal_supports_color))

Choose whether to use color based on the command argument.

Args:
setting - Either `auto`, `always`, or `never`


def init_pool_generator(gens, random_seed=None, id_queue=None):
    global _SHARED_SEQUENCES
    _SHARED_SEQUENCES = gens
    worker_proc = multiprocessing.current_process()
    worker_proc.name = f'Keras_worker_{worker_proc.name}'
    if random_seed is not None:
        np.random.seed(random_seed + worker_proc.ident)
    if id_queue is not None:
        id_queue.put(worker_proc.ident, block=True, timeout=0.1)

Initializer function for pool workers.

Args:
gens: State which should be made available to worker processes.
random_seed: An optional value with which to seed child processes.
id_queue: A multiprocessing Queue of worker ids.
This is used to indicate that a worker process
was created by Keras.


def get_all(self, seq_set: SequenceSet) \
            -> Sequence[Tuple[int, CachedMessage]]:

        if seq_set.uid:
            all_uids = seq_set.flatten(self.max_uid) & self._uids
            return [(seq, self._cache[uid])
                    for seq, uid in enumerate(self._sorted, 1)
                    if uid in all_uids]
        else:
            all_seqs = seq_set.flatten(self.exists)
            return [(seq, self._cache[uid])
                    for seq, uid in enumerate(self._sorted, 1)
                    if seq in all_seqs]

Return the cached messages, and their sequence numbers, for the
given sequence set.

Args:
seq_set: The message sequence set.


def angle_to_distance(angle, units='metric'):

    distance = math.radians(angle) * BODY_RADIUS

    if units in ('km', 'metric'):
        return distance
    elif units in ('sm', 'imperial', 'US customary'):
        return distance / STATUTE_MILE
    elif units in ('nm', 'nautical'):
        return distance / NAUTICAL_MILE
    else:
        raise ValueError('Unknown units type %r' % units)

Convert angle in to distance along a great circle.

Args:
angle (float): Angle in degrees to convert to distance
units (str): Unit type to be used for distances

Returns:
float: Distance in ``units``

Raises:
ValueError: Unknown value for ``units``


def update_dtype(self, attr_name, index, dtype):
    attr = self._node.attr[attr_name]
    num_types = 0
    if attr.HasField('list'):
        types = attr.list.type
        num_types = len(types)
        if num_types > index:
            types[index] = dtype
            return
    elif attr.HasField('type'):
        num_types = 1
        if index == 0:
            attr.type = dtype
            return
    raise ValueError(f'`index` {index:d} is out of range for node({self._node.name}).attr({attr_name}), which has {num_types:d} elements.')

Changes the type of a given input.

Args:
attr_name: The NodeDef attribute containing the type to change.
index: The index of the input type to change.
dtype: The type to change to.


def getPageType(name,number=False):

    if not name in pageNames():
        return None
    pageType=PyOrigin.Pages(name).GetType()
    if number:
        return str(pageType)
    if pageType==1:
        return "matrix"
    if pageType==2:
        return "book"
    if pageType==3:
        return "graph"
    if pageType==4:
        return "layout"
    if pageType==5:
        return "notes"

Returns the type of the page with that name.
If that name doesn't exist, None is returned.

Args:
name (str): name of the page to get the folder from
number (bool): if True, return numbers (i.e., a graph will be 3)
if False, return words where appropriate (i.e, "graph")

Returns:
string of the type of object the page is


def add_options(cls, parser):
    kwargs = {'action': 'store', 'default': '', 'parse_from_config': True, 'comma_separated_list': True}
    for num in range(cls.min_check, cls.max_check):
        parser.add_option(None, '--filename_check{}'.format(num), **kwargs)

Required by flake8
add the possible options, called first

Args:
parser (OptionsManager):


def giant_text_sqltype(dialect: Dialect) -> str:
    if (dialect.name == SqlaDialectName.SQLSERVER):
        return 'NVARCHAR(MAX)'
    elif (dialect.name == SqlaDialectName.MYSQL):
        return 'LONGTEXT'
    else:
        raise ValueError('Unknown dialect: {}'.format(dialect.name))

Returns the SQL column type used to make very large text columns for a
given dialect.

Args:
dialect: a SQLAlchemy :class:`Dialect`
Returns:
the SQL data type of "giant text", typically 'LONGTEXT' for MySQL
and 'NVARCHAR(MAX)' for SQL Server.


def read_molden(inputfile, start_index=0, get_bonds=True):

    from chemcoord.cartesian_coordinates.cartesian_class_main import Cartesian
    with open(inputfile, 'r') as f:
        found = False
        while not found:
            line = f.readline()
            if '[N_GEO]' in line:
                found = True
                number_of_molecules = int(f.readline().strip())

        energies = []
        found = False
        while not found:
            line = f.readline()
            if 'energy' in line:
                found = True
                for _ in range(number_of_molecules):
                    energies.append(float(f.readline().strip()))

        found = False
        while not found:
            line = f.readline()
            if '[GEOMETRIES] (XYZ)' in line:
                found = True
                current_line = f.tell()
                number_of_atoms = int(f.readline().strip())
                f.seek(current_line)

        cartesians = []
        for energy in energies:
            cartesian = Cartesian.read_xyz(
                f, start_index=start_index, get_bonds=get_bonds,
                nrows=number_of_atoms, engine='python')
            cartesian.metadata['energy'] = energy
            cartesians.append(cartesian)
    return cartesians

Read a molden file.

Args:
inputfile (str):
start_index (int):

Returns:
list: A list containing :class:`~chemcoord.Cartesian` is returned.


def most_uncertain_by_mask(self, mask, y):

        idxs = np.where(mask)[0]

        return idxs[np.argsort(np.abs(self.probs[idxs,y]-(1/self.num_classes)))[:4]]

Extracts the first 4 most uncertain indexes from the ordered list of probabilities

Arguments:
mask (numpy.ndarray): the mask of probabilities specific to the selected class; a boolean array with shape (num_of_samples,) which contains True where class==selected_class, and False everywhere else
y (int): the selected class

Returns:
idxs (ndarray): An array of indexes of length 4


def _write_to_command_buffer(self, to_write):
    np.copyto(self._command_bool_ptr, True)
    to_write += '0'
    input_bytes = str.encode(to_write)
    for (index, val) in enumerate(input_bytes):
        self._command_buffer_ptr[index] = val

Write input to the command buffer.  Reformat input string to the correct format.

Args:
to_write (str): The string to write to the command buffer.


def get_path(name, *default):
    global g_config
    value = get(name, *default)
    if (value is None):
        return None
    return proj_path(value)

Get config value as path relative to the project directory.

This allows easily defining the project configuration within the fabfile
as always relative to that fabfile.

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

Returns:
The requested config value. This is one of the global values defined
in this file. 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 get_tensors(graph):
    if not isinstance(graph, ops.Graph):
        raise TypeError('Expected a graph, got: {}'.format(type(graph)))
    ts = []
    for op in graph.get_operations():
        ts += op.outputs
    return ts

get all the tensors which are input or output of an op in the graph.

Args:
graph: a `tf.Graph`.
Returns:
A list of `tf.Tensor`.
Raises:
TypeError: if graph is not a `tf.Graph`.


def _ParseLogLine(self, parser_mediator, structure):

    try:
      date_time = dfdatetime_time_elements.TimeElements(
          time_elements_tuple=structure.date_time)

      date_time.is_local_time = True
    except ValueError:
      parser_mediator.ProduceExtractionWarning(
          'invalid date time value: {0!s}'.format(structure.date_time))
      return

    event_data = SophosAVLogEventData()
    event_data.text = structure.text

    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_ADDED,
        time_zone=parser_mediator.timezone)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a log line.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
structure (pyparsing.ParseResults): structure of tokens derived from
a line of a text file.


def with_headers(self, headers):
    copy = headers.copy()
    copy.update(self._headers)
    return self.__copy_and_set('headers', copy)

Adds headers to the request

Args:
headers (dict): The headers to add the request headers

Returns:
The request builder instance in order to chain calls


def get(self):
    raise NotImplementedError('Must be implemented in subclasses.')

Wait for the result of `RemoteValue` and return the tensor result.

This makes the value concrete by copying the remote tensor to local.

Returns:
The actual output (in the form of `tf.Tensor`s) of the `tf.function`
associated with this `RemoteValue`, previously returned by a
`tf.distribute.experimental.coordinator.ClusterCoordinator.schedule` call.
This can be a single Tensor, or a structure of Tensors, depending on the
output of the `tf.function`.

Raises:
tf.errors.CancelledError: If the function that produces this `RemoteValue`
is aborted or cancelled due to failure.


def size_str(size_in_bytes):

  if not size_in_bytes:
    return "?? GiB"

  size_in_bytes = float(size_in_bytes)
  for (name, size_bytes) in _NAME_LIST:
    value = size_in_bytes / size_bytes
    if value >= 1.0:
      return "{:.2f} {}".format(value, name)
  return "{} {}".format(int(size_in_bytes), "bytes")

Returns a human readable size string.

If size_in_bytes is None, then returns "?? GiB".

For example `size_str(1.5 * tfds.units.GiB) == "1.50 GiB"`.

Args:
size_in_bytes: `int` or `None`, the size, in bytes, that we want to
format as a human-readable size string.


def actnorm_center(name, x, reverse=False, init=False):
    shape = common_layers.shape_list(x)
    with tf.variable_scope(name, reuse=tf.AUTO_REUSE):
        assert ((len(shape) == 2) or (len(shape) == 4))
        if (len(shape) == 2):
            x_mean = tf.reduce_mean(x, [0], keepdims=True)
            b = get_variable_ddi('b', (1, shape[1]), initial_value=(- x_mean), init=init)
        elif (len(shape) == 4):
            x_mean = tf.reduce_mean(x, [0, 1, 2], keepdims=True)
            b = get_variable_ddi('b', (1, 1, 1, shape[3]), initial_value=(- x_mean), init=init)
        if (not reverse):
            x += b
        else:
            x -= b
        return x

Add a bias to x.

Initialize such that the output of the first minibatch is zero centered
per channel.

Args:
name: scope
x: 2-D or 4-D Tensor.
reverse: Forward or backward operation.
init: data-dependent initialization.

Returns:
x_center: (x + b), if reverse is True and (x - b) otherwise.


def query(self, time_indices):

    if self._disposed:
      raise ValueError(
          'Cannot query: this _WatchStore instance is already disposed')
    if not isinstance(time_indices, (tuple, list)):
      time_indices = [time_indices]
    output = []
    for time_index in time_indices:
      if isinstance(self._data[time_index], _TensorValueDiscarded):
        output.append(None)
      else:
        data_item = self._data[time_index]
        if (hasattr(data_item, 'dtype') and
            tensor_helper.translate_dtype(data_item.dtype) == 'string'):
          _, _, data_item = tensor_helper.array_view(data_item)
          data_item = np.array(
              tensor_helper.process_buffers_for_display(data_item),
              dtype=np.object)
        output.append(data_item)

    return output

Query the values at given time indices.

Args:
time_indices: 0-based time indices to query, as a `list` of `int`.

Returns:
Values as a list of `numpy.ndarray` (for time indices in memory) or
`None` (for time indices discarded).


def create_socket(self):
    socket_path = os.path.join(self.config_dir, 'pueue.sock')
    try:
        if os.path.exists(socket_path):
            os.remove(socket_path)
        self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.bind(socket_path)
        self.socket.setblocking(0)
        self.socket.listen(0)
        os.chmod(socket_path, stat.S_IRWXU)
    except Exception:
        self.logger.error("Daemon couldn't socket. Aborting")
        self.logger.exception()
        sys.exit(1)
    return self.socket

Create a socket for the daemon, depending on the directory location.

Args:
config_dir (str): The absolute path to the config directory used by the daemon.

Returns:
socket.socket: The daemon socket. Clients connect to this socket.


def _print_primitive_field(self, field_name: str, field: descriptor.FieldDescriptor, value: Any) -> None:
    if proto_utils.field_is_repeated(field):
        string_values = []
        elements = []
        extensions_found = False
        nonnull_values_found = False
        for primitive in value:
            wrapper = self.primitive_handler.primitive_wrapper_from_primitive(primitive)
            string_values.append(wrapper.json_value())
            elements.append(wrapper.get_element())
            nonnull_values_found = nonnull_values_found or wrapper.has_value()
            extensions_found = extensions_found or wrapper.has_element()
        if nonnull_values_found:
            self.generator.add_field(field_name)
            self._print_list(string_values, self.generator.push)
        if extensions_found:
            if nonnull_values_found:
                self.generator.push(',')
                self.generator.add_newline()
            self.generator.add_field(f'_{field_name}')
            self._print_list(elements, self._print)
    elif self.json_format == _FhirJsonFormat.ANALYTIC and field.message_type.name == 'ReferenceId':
        str_value = proto_utils.get_value_at_field(value, 'value')
        self.generator.add_field(field_name, f'"{str_value}"')
    else:
        wrapper = self.primitive_handler.primitive_wrapper_from_primitive(value)
        if wrapper.has_value():
            self.generator.add_field(field_name, wrapper.json_value())
        if wrapper.has_element() and self.json_format == _FhirJsonFormat.PURE:
            if wrapper.has_value():
                self.generator.push(',')
                self.generator.add_newline()
            self.generator.add_field(f'_{field_name}')
            self._print(wrapper.get_element())

Prints the primitive field.

Args:
field_name: The name of the field.
field: The FielDescriptor whose contents to print.
value: The value present at field to print.


def one_of(self, chset: str) -> str:
    res = self.peek()
    if (res in chset):
        self.offset += 1
        return res
    raise UnexpectedInput(self, ('one of ' + chset))

Parse one character form the specified set.

Args:
chset: string of characters to try as alternatives.

Returns:
The character that was actually matched.

Raises:
UnexpectedInput: If the next character is not in `chset`.


def gather_continuous_embeddings(self, word_embeddings: torch.Tensor, continuous_embeddings: List[torch.Tensor], image_patch_input_indices: torch.Tensor) -> torch.Tensor:
    if not word_embeddings.shape[0] == len(continuous_embeddings):
        raise ValueError(f'Batch sizes must match! Got len(continuous_embeddings)={len(continuous_embeddings)!r} and word_embeddings.shape[0]={word_embeddings.shape[0]!r}')
    output_embeddings = word_embeddings.clone()
    for batch_idx in range(word_embeddings.shape[0]):
        dst_indices = torch.nonzero(image_patch_input_indices[batch_idx] >= 0, as_tuple=True)[0]
        src_indices = image_patch_input_indices[batch_idx][dst_indices]
        if src_indices.shape[0] > continuous_embeddings[batch_idx].shape[0]:
            raise ValueError(f'Number of continuous embeddings continuous_embeddings[batch_idx].shape={continuous_embeddings[batch_idx].shape!r} does not match number of continuous token ids src_indices.shape={src_indices.shape!r} in batch element {batch_idx}.')
        output_embeddings[batch_idx, dst_indices] = continuous_embeddings[batch_idx][src_indices].to(output_embeddings.device)
    return output_embeddings

This function places the continuous_embeddings into the word_embeddings at the locations
indicated by image_patch_input_indices. Different batch elements can have different numbers of continuous
embeddings.

Args:
word_embeddings (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
Tensor of word embeddings.
continuous_embeddings (`torch.FloatTensor` of shape `(batch_size, num_patches, hidden_size)`):
Tensor of continuous embeddings. The length of the list is the batch size. Each entry is shape
[num_image_embeddings, hidden], and num_image_embeddings needs to match the number of non-negative
indices in image_patch_input_indices for that batch element.
image_patch_input_indices (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Tensor of indices of the image patches in the input_ids tensor.


def get_if_set(self, addresses):
    with self._lock:
        results = []
        for add in addresses:
            results.append(self._get_if_set(add))
        return results

Returns the value set in this context, or None, for each address in
addresses.

Args:
addresses (list of str): The addresses to return values for, if set
within this context.

Returns:
(list): bytes set at the address or None


def for_all_test_methods(decorator: Callable[..., Any], *args, **kwargs) -> Callable[[_TC], _TC]:

    def all_test_methods_impl(cls: _TC) -> _TC:

        for name in dir(cls):
            value = getattr(cls, name)
            if callable(value) and name.startswith('test') and (name != 'test_session'):
                setattr(cls, name, decorator(*args, **kwargs)(value))
        return cls
    return all_test_methods_impl

Generate class-level decorator from given method-level decorator.

It is expected for the given decorator to take some arguments and return
a method that is then called on the test method to produce a decorated
method.

Args:
decorator: The decorator to apply.
*args: Positional arguments
**kwargs: Keyword arguments
Returns: Function that will decorate a given classes test methods with the
decorator.


def space_to_batch_direct(input_array, block_shape, paddings):
    input_array = np.array(input_array)
    block_shape = np.array(block_shape)
    num_block_dims = len(block_shape)
    paddings = np.array(paddings).reshape((len(block_shape), 2))
    padded = np.pad(input_array, pad_width=[[0, 0]] + list(paddings) + [[0, 0]] * (input_array.ndim - 1 - num_block_dims), mode='constant')
    reshaped_padded_shape = [input_array.shape[0]]
    output_shape = [input_array.shape[0] * np.prod(block_shape)]
    for block_dim, block_shape_value in enumerate(block_shape):
        reduced_size = padded.shape[block_dim + 1]
        reshaped_padded_shape.append(reduced_size)
        output_shape.append(reduced_size)
        reshaped_padded_shape.append(block_shape_value)
    reshaped_padded_shape.extend(input_array.shape[num_block_dims + 1:])
    output_shape.extend(input_array.shape[num_block_dims + 1:])
    reshaped_padded = padded.reshape(reshaped_padded_shape)
    permuted_reshaped_padded = np.transpose(reshaped_padded, list(np.arange(num_block_dims) * 2 + 2) + [0] + list(np.arange(num_block_dims) * 2 + 1) + list(np.arange(input_array.ndim - num_block_dims - 1) + 1 + num_block_dims * 2))
    return permuted_reshaped_padded.reshape(output_shape)

Direct Python implementation of space-to-batch conversion.

This is used for tests only.

Args:
input_array: N-D array
block_shape: 1-D array of shape [num_block_dims].
paddings: 2-D array of shape [num_block_dims, 2].

Returns:
Converted tensor.


def load(self, binary: pyquil.Program) -> 'QuantumFlowQVM':
    assert (self.status in ['connected', 'done'])
    prog = quil_to_program(str(binary))
    self._prog = prog
    self.program = binary
    self.status = 'loaded'
    return self

Load a pyQuil program, and initialize QVM into a fresh state.

Args:
binary: A pyQuil program


def summary(self, v):
    if hasattr(v, '__iter__'):
        self._summary = self._summary_cls(v)
    else:
        self._summary = self._summary_cls(float(v))

Set summary.

Args:
v: A new summary. It could be a single number or lists.


def get_variable_name_from_bird(bird_conf):
    bird_variable_pattern = re.compile('\n        ^\\s*\n        define\\s+\n        (?P<name>\\S+\\b)\n        \\s+\n        =\n        ', re.VERBOSE)
    with open(bird_conf, 'r') as content:
        for line in content.readlines():
            variable_match = bird_variable_pattern.search(line)
            if variable_match:
                return variable_match.group('name')
    return None

Return the variable name set in Bird configuration.

The variable name in Bird configuration is set with the keyword 'define',
here is an example:

define ACAST_PS_ADVERTISE =

and we exract the string between the word 'define' and the equals sign.

Arguments:
bird_conf (str): The absolute file name path of Bird configuration.

Returns:
The variable name as a string or None if it isn't found.


def update_headers(self, headers):

        check_type(headers, dict, may_be_none=False)
        self._req_session.headers.update(headers)

Update the HTTP headers used for requests in this session.

Note: Updates provided by the dictionary passed as the `headers`
parameter to this method are merged into the session headers by adding
new key-value pairs and/or updating the values of existing keys. The
session headers are not replaced by the provided dictionary.

Args:
headers(dict): Updates to the current session headers.


def map_(function, *structures, **kwargs):
    flatten = kwargs.pop('flatten', False)
    assert (not kwargs), 'map() got unexpected keyword arguments.'

    def impl(function, *structures):
        if (len(structures) == 0):
            return structures
        if all((isinstance(s, (tuple, list)) for s in structures)):
            if (len(set((len(x) for x in structures))) > 1):
                raise ValueError('Cannot merge tuples or lists of different length.')
            args = tuple((impl(function, *x) for x in _builtin_zip(*structures)))
            if hasattr(structures[0], '_fields'):
                return type(structures[0])(*args)
            else:
                return type(structures[0])(args)
        if all((isinstance(s, dict) for s in structures)):
            if (len(set((frozenset(x.keys()) for x in structures))) > 1):
                raise ValueError('Cannot merge dicts with different keys.')
            merged = {k: impl(function, *(s[k] for s in structures)) for k in structures[0]}
            return type(structures[0])(merged)
        return function(*structures)
    result = impl(function, *structures)
    if flatten:
        result = flatten_(result)
    return result

Apply a function to every element in a nested structure.

If multiple structures are provided as input, their structure must match and
the function will be applied to corresponding groups of elements. The nested
structure can consist of any combination of lists, tuples, and dicts.

Args:
function: The function to apply to the elements of the structure. Receives
one argument for every structure that is provided.
*structures: One of more nested structures.
flatten: Whether to flatten the resulting structure into a tuple. Keys of
dictionaries will be discarded.

Returns:
Nested structure.


def plot_kurtosis(self, f_start=None, f_stop=None, if_id=0, **kwargs):

        ax = plt.gca()

        plot_f, plot_data = self.grab_data(f_start, f_stop, if_id)

        if self.header[b'foff'] < 0:
            plot_data = plot_data[..., ::-1]
            plot_f = plot_f[::-1]

        try:
            plot_kurtosis = scipy.stats.kurtosis(plot_data, axis=0, nan_policy='omit')
        except:
            plot_kurtosis = plot_data*0.0

        plt.plot(plot_f, plot_kurtosis, **kwargs)
        plt.ylabel("Kurtosis")
        plt.xlabel("Frequency [MHz]")

        plt.xlim(plot_f[0], plot_f[-1])

Plot kurtosis

Args:
f_start (float): start frequency, in MHz
f_stop (float): stop frequency, in MHz
kwargs: keyword args to be passed to matplotlib imshow()


def find_wells_without_curve(self, mnemonic, alias=None):

        return Project([w for w in self if w.get_curve(mnemonic, alias=alias) is None])

Returns a new Project with only the wells which DO NOT have the named curve.

Args:
menmonic (str): the name of the curve to look for.
alias (dict): a welly alias dictionary.

Returns:
project.


def parse_genes(transcripts):

    genes_to_transcripts = {}

    genes = []

    hgvs_identifier = None
    canonical_transcript = None
    exon = None

    for transcript in transcripts:

        hgnc_id = transcript['hgnc_id']
        hgnc_symbol = transcript['hgnc_symbol']

        if (transcript['is_canonical'] and transcript.get('coding_sequence_name')):
            hgvs_identifier = transcript.get('coding_sequence_name')
            canonical_transcript = transcript['transcript_id']
            exon = transcript['exon']

        if hgnc_id:
            if hgnc_id in genes_to_transcripts:
                genes_to_transcripts[hgnc_id].append(transcript)
            else:
                genes_to_transcripts[hgnc_id] = [transcript]
        else:
            if hgnc_symbol:
                if hgnc_symbol in genes_to_transcripts:
                    genes_to_transcripts[hgnc_symbol].append(transcript)
                else:
                    genes_to_transcripts[hgnc_symbol] = [transcript]

    for gene_id in genes_to_transcripts:

        gene_transcripts = genes_to_transcripts[gene_id]

        most_severe_consequence = None

        most_severe_rank = float('inf')

        most_severe_transcript = None

        most_severe_region = None

        most_severe_sift = None
        most_severe_polyphen = None

        for transcript in gene_transcripts:
            hgnc_id = transcript['hgnc_id']
            hgnc_symbol = transcript['hgnc_symbol']

            for consequence in transcript['functional_annotations']:

                new_rank = SO_TERMS[consequence]['rank']

                if new_rank < most_severe_rank:

                    most_severe_rank = new_rank
                    most_severe_consequence = consequence
                    most_severe_transcript = transcript
                    most_severe_sift = transcript['sift_prediction']
                    most_severe_polyphen = transcript['polyphen_prediction']
                    most_severe_region = SO_TERMS[consequence]['region']

        gene = {
            'transcripts': gene_transcripts,
            'most_severe_transcript': most_severe_transcript,
            'most_severe_consequence': most_severe_consequence,
            'most_severe_sift': most_severe_sift,
            'most_severe_polyphen': most_severe_polyphen,
            'hgnc_id': hgnc_id,
            'hgnc_symbol': hgnc_symbol,
            'region_annotation': most_severe_region,
            'hgvs_identifier': transcript['coding_sequence_name'],
            'canonical_transcript': transcript['transcript_id'],
            'exon': transcript['exon'],
        }
        genes.append(gene)

    return genes

Parse transcript information and get the gene information from there.

Use hgnc_id as identifier for genes and ensembl transcript id to identify transcripts

Args:
transcripts(iterable(dict))

Returns:
genes (list(dict)): A list with dictionaries that represents genes


def forall(self, vars_list: List[str]) -> 'TensorFluent':
    return self._aggregation_op(tf.reduce_all, self, vars_list)

Returns the TensorFluent for the forall aggregation function.

Args:
vars_list: The list of variables to be aggregated over.

Returns:
A TensorFluent wrapping the forall aggregation function.


def _create_hash_from_doc(doc: Mapping[str, Any]) -> str:

    doc_string = json.dumps(doc, sort_keys=True)
    return _create_hash(doc_string)

Create hash Id from edge record

Args:
edge (Mapping[str, Any]): edge record to create hash from

Returns:
str: Murmur3 128 bit hash


def add_trace(self, *args, **kwargs):
    args = list(args)
    kwargs = kwargs.copy()
    for fn in self._functions.values():
        if self._expects_training_arg:

            def trace_with_training(value, fn=fn):
                utils.set_training_arg(value, self._training_arg_index, args, kwargs)
                add_trace_to_queue(fn, args, kwargs, value)
            trace_with_training(True)
            trace_with_training(False)
        else:
            add_trace_to_queue(fn, args, kwargs)

Traces all functions with the same args and kwargs.

Args:
*args: Positional args passed to the original function.
**kwargs: Keyword args passed to the original function.


def compute_context_repetition_mask(self, input_ids: torch.LongTensor) -> torch.LongTensor:
    self._check_input_ids_shape(input_ids)
    batch_size, _ = input_ids.shape
    state = SynthIDTextWatermarkState(batch_size=batch_size, ngram_len=self.ngram_len, context_history_size=self.context_history_size, device=self.device)
    contexts = input_ids[:, :-1].unfold(dimension=1, size=self.ngram_len - 1, step=1)
    _, num_contexts, _ = contexts.shape
    are_repeated_contexts = []
    for i in range(num_contexts):
        context = contexts[:, i, :]
        hash_result = torch.ones(batch_size, device=self.device, dtype=torch.long)
        context_hash = self.accumulate_hash(hash_result, context)[:, None]
        is_repeated_context = (state.context_history == context_hash).any(dim=1, keepdim=True)
        are_repeated_contexts.append(is_repeated_context)
        state.context_history = torch.concat((context_hash, state.context_history), dim=1)[:, :-1]
    are_repeated_contexts = torch.concat(are_repeated_contexts, dim=1)
    return torch.logical_not(are_repeated_contexts)

Computes repetition mask.

0 and 1 stand for repeated and not repeated context n-1 grams respectively.

Args:
input_ids (`torch.LongTensor`):
Input token ids (batch_size, input_len).

Returns:
Repetitions mask (batch_size, input_len - (ngram_len - 1)).


def clear_db(self):

        self.data_store.clear_db()

        self.plugin_manager.load_all_plugins()

        self._store_information()

Clear the Main Database of all samples and worker output.
Args:
None
Returns:
Nothing


def change_disk_usage(self, usage_change, file_path, st_dev):
    mount_point = self._mount_point_for_device(st_dev)
    if mount_point:
        total_size = mount_point['total_size']
        if (total_size is not None):
            if ((total_size - mount_point['used_size']) < usage_change):
                self.raise_io_error(errno.ENOSPC, file_path)
        mount_point['used_size'] += usage_change

Change the used disk space by the given amount.

Args:
usage_change: Number of bytes added to the used space.
If negative, the used space will be decreased.

file_path: The path of the object needing the disk space.

st_dev: The device ID for the respective file system.

Raises:
IOError: if usage_change exceeds the free file system space


def __init__(self, max_meter=None, band_types=None, capabilities=None,
                 max_bands=None, max_color=None):

        super().__init__()
        self.max_meter = max_meter
        self.band_types = band_types
        self.capabilities = capabilities
        self.max_bands = max_bands
        self.max_color = max_color

Create a MeterFeatures with the optional parameters below.

Args:
max_meter(int): Maximum number of meters.
band_types (|MeterBandType_v0x04|):
Bitmaps of OFPMBT_* values supported.
capabilities (|MeterFlags_v0x04|): Bitmaps of "ofp_meter_flags".
max_bands(int): Maximum bands per meters
max_color(int): Maximum color value


def create_backup(name):
    r
    if name in list_backups():
        raise CommandExecutionError('Backup already present: {0}'.format(name))

    ps_cmd = ['Backup-WebConfiguration',
              '-Name', "'{0}'".format(name)]

    cmd_ret = _srvmgr(ps_cmd)

    if cmd_ret['retcode'] != 0:
        msg = 'Unable to backup web configuration: {0}\nError: {1}' \
              ''.format(name, cmd_ret['stderr'])
        raise CommandExecutionError(msg)

    return name in list_backups()

r'''
Backup an IIS Configuration on the System.

.. versionadded:: 2017.7.0

.. note::
Backups are stored in the ``$env:Windir\System32\inetsrv\backup``
folder.

Args:
name (str): The name to give the backup

Returns:
bool: True if successful, otherwise False

CLI Example:

.. code-block:: bash

salt '*' win_iis.create_backup good_config_20170209


def has_types(self, types, all_=True):
    func = (all if all_ else any)
    return func([self.get_stim(t) for t in listify(types)])

Check whether the current component list matches all Stim types
in the types argument.

Args:
types (Stim, list): a Stim class or iterable of Stim classes.
all_ (bool): if True, all input types must match; if False, at
least one input type must match.

Returns:
True if all passed types match at least one Stim in the component
list, otherwise False.


def interactive_console(self):
    if (not self.running()):
        raise RuntimeError(('VM %s is not running' % self._libvirt_.name))
    virsh_command = ['virsh', '-c', config.get('libvirt_url'), 'console', self._libvirt_name()]
    return utils.run_interactive_command(command=virsh_command)

Opens an interactive console

Returns:
lago.utils.CommandStatus: result of the virsh command execution


def measurement_key(val: Any, default: Any=RaiseTypeErrorIfNotProvided):
    getter = getattr(val, '_measurement_key_', None)
    result = (NotImplemented if (getter is None) else getter())
    if (result is not NotImplemented):
        return result
    if (default is not RaiseTypeErrorIfNotProvided):
        return default
    if (getter is None):
        raise TypeError("object of type '{}' has no _measurement_key_ method.".format(type(val)))
    raise TypeError("object of type '{}' does have a _measurement_key_ method, but it returned NotImplemented.".format(type(val)))

Get the measurement key for the given value.

Args:
val: The value which has the measurement key..
default: Determines the fallback behavior when `val` doesn't have
a measurement key. If `default` is not set, a TypeError is raised.
If default is set to a value, that value is returned if the value
does not have `_measurement_key_`.

Returns:
If `val` has a `_measurement_key_` method and its result is not
`NotImplemented`, that result is returned. Otherwise, if a default
value was specified, the default value is returned.

Raises:
TypeError: `val` doesn't have a _measurement_key_ method (or that method
returned NotImplemented) and also no default value was specified.


def columns_exist(inspect_dataset):

    if not hasattr(inspect_dataset, "columns"):
        warnings.warn(
            "No columns list found in dataset; no autoinspection performed.")
        return
    elif isinstance(inspect_dataset.columns[0], string_types):
        columns = inspect_dataset.columns
    elif isinstance(inspect_dataset.columns[0], dict) and "name" in inspect_dataset.columns[0]:
        columns = [col['name'] for col in inspect_dataset.columns]
    else:
        raise AutoInspectError(
            "Unable to determine column names for this dataset.")

    create_multiple_expectations(
        inspect_dataset, columns, "expect_column_to_exist")

This function will take a dataset and add expectations that each column present exists.

Args:
inspect_dataset (great_expectations.dataset): The dataset to inspect and to which to add expectations.


def create_db(file_pth):

    conn = sqlite3.connect(file_pth)
    c = conn.cursor()

    c.execute('DROP TABLE IF EXISTS library_spectra_source')
    c.execute(
              )

    c.execute('DROP TABLE IF EXISTS metab_compound')
    c.execute()

    c.execute('DROP TABLE IF EXISTS library_spectra_meta')
    c.execute(
              )

    c.execute('DROP TABLE IF EXISTS library_spectra')
    c.execute(
              )

    c.execute('DROP TABLE IF EXISTS library_spectra_annotation')
    c.execute(
              )

Create an empty SQLite database for library spectra.

Example:
>>> from msp2db.db import create_db
>>> db_pth = 'library.db'
>>> create_db(file_pth=db_pth)

Args:
file_pth (str): File path for SQLite database


def _get_image_nums_and_video_nums(self, input_ids: Optional[torch.LongTensor]) -> Tuple[torch.Tensor, torch.Tensor]:
    image_token_id = self.config.image_token_id
    video_token_id = self.config.video_token_id
    vision_start_token_id = self.config.vision_start_token_id
    vision_start_mask = input_ids == vision_start_token_id
    vision_first_mask = torch.roll(vision_start_mask, shifts=1, dims=1)
    image_mask = input_ids == image_token_id
    video_mask = input_ids == video_token_id
    image_nums = torch.sum(vision_first_mask & image_mask, dim=1)
    video_nums = torch.sum(vision_first_mask & video_mask, dim=1)
    return (image_nums, video_nums)

Get the number of images and videos for each sample to calculate the separation length of the sample tensor.
These parameters are not passed through the processor to avoid unpredictable impacts from interface modifications.

Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary.

Returns:
image_nums (`torch.LongTensor` of shape `(batch_size, num_images_sample)`)
video_nums (`torch.LongTensor` of shape `(batch_size, num_videos_sample)`)


def set_values(self, values, separator='\n', indent=4*' '):

        self._updated = True
        self._multiline_value_joined = True
        self._values = values
        if separator == '\n':
            values.insert(0, '')
            separator = separator + indent
        self._value = separator.join(values)

Sets the value to a given list of options, e.g. multi-line values

Args:
values (list): list of values
separator (str): separator for values, default: line separator
indent (str): indentation depth in case of line separator


def from_api_repr(cls, resource, client):
    job_ref_properties = resource.get('jobReference', {'projectId': client.project})
    job_ref = _JobReference._from_api_repr(job_ref_properties)
    job = cls(job_ref, client)
    resource['jobReference'] = job_ref_properties
    job._properties = resource
    return job

Construct an UnknownJob from the JSON representation.

Args:
resource (dict): JSON representation of a job.
client (google.cloud.bigquery.client.Client):
Client connected to BigQuery API.

Returns:
UnknownJob: Job corresponding to the resource.


def DeleteOldFeedItems(client, feed_item_ids, feed):
    if (not feed_item_ids):
        return
    feed_item_service = client.GetService('FeedItemService', 'v201809')
    operations = [{'operator': 'REMOVE', 'operand': {'feedId': feed['id'], 'feedItemId': feed_item_id}} for feed_item_id in feed_item_ids]
    feed_item_service.mutate(operations)

Deletes the old feed items for which extension settings have been created.

Args:
client: an AdWordsClient instance.
feed_item_ids: a list of Feed Item Ids.
feed: the Feed containing the given Feed Item Ids.


def _normalize_feature_columns(feature_columns):
    if isinstance(feature_columns, _FeatureColumn):
        feature_columns = [feature_columns]
    if isinstance(feature_columns, collections_abc.Iterator):
        feature_columns = list(feature_columns)
    if isinstance(feature_columns, dict):
        raise ValueError('Expected feature_columns to be iterable, found dict.')
    for column in feature_columns:
        if not isinstance(column, _FeatureColumn):
            raise ValueError('Items of feature_columns must be a _FeatureColumn. Given (type {}): {}.'.format(type(column), column))
    if not feature_columns:
        raise ValueError('feature_columns must not be empty.')
    name_to_column = {}
    for column in feature_columns:
        if column.name in name_to_column:
            raise ValueError('Duplicate feature column name found for columns: {} and {}. This usually means that these columns refer to same base feature. Either one must be discarded or a duplicated but renamed item must be inserted in features dict.'.format(column, name_to_column[column.name]))
        name_to_column[column.name] = column
    return feature_columns

Normalizes the `feature_columns` input.

This method converts the `feature_columns` to list type as best as it can. In
addition, verifies the type and other parts of feature_columns, required by
downstream library.

Args:
feature_columns: The raw feature columns, usually passed by users.

Returns:
The normalized feature column list.

Raises:
ValueError: for any invalid inputs, such as empty, duplicated names, etc.


def get_stream(data=None):

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

        mstream = __mstreams_available__.pop()

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

        mstream.seek(0)

        return mstream

Get a MemoryStream instance.

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

Returns:
MemoryStream: instance.


def map_creative_third_party_url_feeds(self, creative_feed, third_party_url_feed):
    for creative in creative_feed:
        creative['third_party_urls'] = [third_party_url for third_party_url in third_party_url_feed if self._assignment_matches(creative, third_party_url)]

Maps third party url feed to the corresponding creative.

Third party URL is a child object to the creative, and there is a 1 creative
to many third party urls relationship. In Bulkdozer they are represented by
two separate tab in the feed, and this method maps the creatives to their
respective third party URLs based on the creative ID.

Args:
creative_feed: Creative feed.
third_party_url_feed: Third party url feed.


def mark_causative(self, institute, case, user, link, variant):
    display_name = variant['display_name']
    LOG.info('Mark variant {0} as causative in the case {1}'.format(display_name, case['display_name']))
    LOG.info('Adding variant to causatives in case {0}'.format(case['display_name']))
    LOG.info('Marking case {0} as solved'.format(case['display_name']))
    updated_case = self.case_collection.find_one_and_update({'_id': case['_id']}, {'$push': {'causatives': variant['_id']}, '$set': {'status': 'solved'}}, return_document=pymongo.ReturnDocument.AFTER)
    LOG.info('Creating case event for marking {0} causative'.format(variant['display_name']))
    self.create_event(institute=institute, case=case, user=user, link=link, category='case', verb='mark_causative', variant=variant, subject=variant['display_name'])
    LOG.info('Creating variant event for marking {0} causative'.format(case['display_name']))
    self.create_event(institute=institute, case=case, user=user, link=link, category='variant', verb='mark_causative', variant=variant, subject=variant['display_name'])
    return updated_case

Create an event for marking a variant causative.

Arguments:
institute (dict): A Institute object
case (dict): Case object
user (dict): A User object
link (str): The url to be used in the event
variant (variant): A variant object

Returns:
updated_case(dict)


def _container_start_handler_factory(ion_type, before_yield=lambda c, ctx: None):

    assert ion_type.is_container

    @coroutine
    def container_start_handler(c, ctx):
        before_yield(c, ctx)
        yield
        yield ctx.event_transition(IonEvent, IonEventType.CONTAINER_START, ion_type, value=None)
    return container_start_handler

Generates handlers for tokens that begin with container start characters.

Args:
ion_type (IonType): The type of this container.
before_yield (Optional[callable]): Called at initialization. Accepts the first character's ordinal and the
current context; performs any necessary initialization actions.


def option_configure(debug=False, path=None):

    if CONFIG_SCRIPT in sys.argv[0]:
        debug = True
    if path is None:
        path = local_config['PROJECT']['CONFIG_PATH']
    if debug:
        if os.path.isfile(path):
            debug_mode('local_config file: ', local_config, debug, halt=True)
        else:
            msg =
            debug_mode(msg, {'CONFIG_PATH': path}, debug, halt=True)
    r = configuration.init(debug, path)
    return r

Summary:
Initiate configuration menu to customize metal runtime options.
Console script ```keyconfig``` invokes this option_configure directly
in debug mode to display the contents of the local config file (if exists)
Args:
:path (str): full path to default local configuration file location
:debug (bool): debug flag, when True prints out contents of local
config file
Returns:
TYPE (bool):  Configuration Success | Failure


def _create_delta(self):

        states = self._read_transitions()
        total_states = len(states)
        self._add_sink_state(states)
        nulltrans = self._read_null_transitions()

        def delta(current_state, character):

            if character != '':
                newstate = states[current_state][ord(character)]
                if newstate > 0:
                    return newstate
                else:
                    return total_states
            else:
                return nulltrans[current_state]

        return total_states + 1, delta

This function creates the delta transition
Args:
startState (int): Initial state of automaton
Results:
int, func: A number indicating the total states, and the delta function


def _HandleDuplicates(self, new_aliases):
    name_to_alias = {}
    out = []
    for a in new_aliases:
        if a.name not in name_to_alias:
            name_to_alias[a.name] = a
            out.append(a)
            continue
        existing = name_to_alias[a.name]
        if self._EquivalentAliases(existing, a):
            continue
        existing_name = existing.type.name or existing.type.__class__.__name__
        a_name = a.type.name or a.type.__class__.__name__
        raise KeyError(f'Duplicate top level items: {existing_name!r}, {a_name!r}')
    return out

Handle duplicate module-level aliases.

Aliases pointing to qualified names could be the result of importing the
same entity through multiple import paths, which should not count as an
error; instead we just deduplicate them.

Args:
new_aliases: The list of new aliases to deduplicate

Returns:
A deduplicated list of aliases.

Raises:
KeyError: If there is a name clash.


def is_supergroup(self, subgroup):
    warnings.warn('This is not fully functional. Only trivial subsets are tested right now. ')
    return set(subgroup.symmetry_ops).issubset(self.symmetry_ops)

True if this group is a supergroup of the supplied group.

Args:
subgroup (SymmetryGroup): Subgroup to test.

Returns:
True if this group is a supergroup of the supplied group.


def get_unresolved(aln_df):

    unresolved_df = aln_df[aln_df['type'] == 'unresolved']
    unresolved = []
    if not unresolved_df.empty:
        unresolved_df['id_a_pos'] = unresolved_df['id_a_pos'].astype(int)
        unresolved = unresolved_df.id_a_pos.tolist()
    return unresolved

Get a list of residue numbers (in the original sequence's numbering) that are unresolved

Args:
aln_df (DataFrame): Alignment DataFrame

Returns:
list: Residue numbers that are mutated


def _load_features_from_images(self, images, names=None):
    if ((names is not None) and (len(names) != len(images))):
        raise Exception('Lists of feature names and images must be of same length!')
    self.feature_names = (names if (names is not None) else images)
    self.feature_images = imageutils.load_imgs(images, self.masker)

Load feature image data from image files.

Args:
images: A list of image filenames.
names: An optional list of strings to use as the feature names. Must
be in the same order as the images.


def _clip_gradient_op(dtype):

    def clip_gradient_backward(op, grad):
        clip_value_min = op.inputs[1]
        clip_value_max = op.inputs[2]
        clipped_grad = tf.clip_by_value(grad, clip_value_min, clip_value_max)
        return (clipped_grad, None, None)

    def clip_gradient_forward(x, clip_value_min, clip_value_max):
        del clip_value_min
        del clip_value_max
        return x
    func_name = 'ClipGradient_{}'.format(dtype.name)
    return function.Defun(dtype, dtype, dtype, python_grad_func=clip_gradient_backward, func_name=func_name)(clip_gradient_forward)

Create an op that clips gradients using a Defun.

The tensorflow Defun decorator creates an op and tensorflow caches these op
automatically according to `func_name`. Using a Defun decorator twice with the
same `func_name` does not create a new op, instead the cached op is used.

This method produces a new op the first time it is called with a given `dtype`
argument, and then uses the cached op each time it is called after that with
the same `dtype`. The min and max clip values are given as arguments for the
forward pass method so that they can be used in the backwards pass.

Args:
dtype: the dtype of the net whose gradient is being clipped.

Returns:
The op that clips gradients.


def run_docker(self, commands):
    try:
        import docker
    except ImportError:
        print('{}{}Could not import docker module (try "pip install docker").'.format(c.Style.BRIGHT, c.Fore.RED))
        sys.exit(1)
    app_args_data = self.profile.get('profile_args').data
    install_json = self.profile.get('install_json')
    client = docker.from_env()
    app_dir = os.getcwd()
    ports = {}
    if self.args.vscd:
        ports = {'{}/tcp'.format(self.args.vscd_port): self.args.vscd_port}
    volumes = {}
    in_path = '{}/{}'.format(app_dir, app_args_data.get('tc_in_path'))
    if (app_args_data.get('tc_in_path') is not None):
        volumes[in_path] = {'bind': in_path}
    log_path = '{}/{}'.format(app_dir, app_args_data.get('tc_log_path'))
    if (app_args_data.get('tc_log_path') is not None):
        volumes[log_path] = {'bind': log_path}
    out_path = '{}/{}'.format(app_dir, app_args_data.get('tc_out_path'))
    if (app_args_data.get('tc_out_path') is not None):
        volumes[out_path] = {'bind': out_path}
    temp_path = '{}/{}'.format(app_dir, app_args_data.get('tc_temp_path'))
    if (app_args_data.get('tc_temp_path') is not None):
        volumes[temp_path] = {'bind': temp_path}
    volumes[app_dir] = {'bind': app_dir}
    if (self.args.docker_image is not None):
        docker_image = self.args.docker_image
    else:
        docker_image = self.profile.get('dockerImage', install_json.get('dockerImage', self.docker_image))
    status_code = 1
    try:
        self.container = client.containers.run(docker_image, entrypoint=commands.get('cli_command'), environment=['PYTHONPATH={}/lib_latest'.format(app_dir)], detach=True, ports=ports, remove=True, volumes=volumes, working_dir=app_dir)
        results = self.container.wait()
        status_code = results.get('StatusCode')
        error = results.get('Error')
        if error:
            print('{}{}{}'.format(c.Style.BRIGHT, c.Fore.RED, error))
    except Exception as e:
        print('{}{}{}'.format(c.Style.BRIGHT, c.Fore.RED, e))
        sys.exit()
    return self.run_exit_code(status_code)

Run App in Docker Container.

Args:
commands (dict): A dictionary of the CLI commands.

Returns:
int: The exit code of the subprocess command.


def get_all_subtypes_with_tags(self):
    assert self.has_enumerated_subtypes(), 'Enumerated subtypes not set.'
    subtypes_with_tags = []
    fifo = deque([subtype_field.data_type for subtype_field in self.get_enumerated_subtypes()])
    while fifo:
        data_type = fifo.popleft()
        subtypes_with_tags.append((data_type._get_subtype_tags(), data_type))
        if data_type.has_enumerated_subtypes():
            for subtype_field in data_type.get_enumerated_subtypes():
                fifo.append(subtype_field.data_type)
    return subtypes_with_tags

Unlike other enumerated-subtypes-related functionality, this method
returns not just direct subtypes, but all subtypes of this struct. The
tag of each subtype is the list of tags from which the type descends.

This method only applies to structs that enumerate subtypes.

Use this when you need to generate a lookup table for a root struct
that maps a generated class representing a subtype to the tag it needs
in the serialized format.

Returns:
List[Tuple[List[String], Struct]]


def get(issue_id, issue_type_id):
    return db.Issue.find_one((Issue.issue_id == issue_id), (Issue.issue_type_id == issue_type_id))

Return issue by ID

Args:
issue_id (str): Unique Issue identifier
issue_type_id (str): Type of issue to get

Returns:
:obj:`Issue`: Returns Issue object if found, else None


class ClapAudioPatchMerging(nn.Module):

    def __init__(self, input_resolution: Tuple[int], dim: int, norm_layer: nn.Module=nn.LayerNorm) -> None:
        super().__init__()
        self.input_resolution = input_resolution
        self.dim = dim
        self.reduction = nn.Linear(4 * dim, 2 * dim, bias=False)
        self.norm = norm_layer(4 * dim)

    def maybe_pad(self, input_feature, height, width):
        should_pad = height % 2 == 1 or width % 2 == 1
        if should_pad:
            pad_values = (0, 0, 0, width % 2, 0, height % 2)
            input_feature = nn.functional.pad(input_feature, pad_values)
        return input_feature

    def forward(self, input_feature: torch.Tensor, input_dimensions: Tuple[int, int]) -> torch.Tensor:
        height, width = input_dimensions
        batch_size, dim, num_channels = input_feature.shape
        input_feature = input_feature.view(batch_size, height, width, num_channels)
        input_feature = self.maybe_pad(input_feature, height, width)
        input_feature_0 = input_feature[:, 0::2, 0::2, :]
        input_feature_1 = input_feature[:, 1::2, 0::2, :]
        input_feature_2 = input_feature[:, 0::2, 1::2, :]
        input_feature_3 = input_feature[:, 1::2, 1::2, :]
        input_feature = torch.cat([input_feature_0, input_feature_1, input_feature_2, input_feature_3], -1)
        input_feature = input_feature.view(batch_size, -1, 4 * num_channels)
        input_feature = self.norm(input_feature)
        input_feature = self.reduction(input_feature)
        return input_feature

Patch Merging Layer.

Args:
input_resolution (`Tuple[int]`):
Resolution of input feature.
dim (`int`):
Number of input channels.
norm_layer (`nn.Module`, *optional*, defaults to `nn.LayerNorm`):
Normalization layer class.


def CreateCampaign(client, merchant_id, budget_id):
    campaign_service = client.GetService('CampaignService', 'v201809')
    campaign = {'name': ('Shopping campaign
    operations = [{'operator': 'ADD', 'operand': campaign}]
    return campaign_service.mutate(operations)['value'][0]

Creates a new Display Network campaign.

Args:
client: an AdWordsClient instance.
merchant_id: a int merchant center ID.
budget_id: a int budget ID.

Returns:
The campaign that was successfully created.


def GetFileObjectReferenceCount(self, path_spec):
    cache_value = self._file_object_cache.GetCacheValue(path_spec.comparable)
    if (not cache_value):
        return None
    return cache_value.reference_count

Retrieves the reference count of a cached file-like object.

Args:
path_spec (PathSpec): path specification.

Returns:
int: reference count or None if there is no file-like object for
the corresponding path specification cached.


def get_lat_long(self, callsign, timestamp=timestamp_now):
    callsign_data = self.get_all(callsign, timestamp=timestamp)
    return {const.LATITUDE: callsign_data[const.LATITUDE], const.LONGITUDE: callsign_data[const.LONGITUDE]}

Returns Latitude and Longitude for a callsign

Args:
callsign (str): Amateur Radio callsign
timestamp (datetime, optional): datetime in UTC (tzinfo=pytz.UTC)

Returns:
dict: Containing Latitude and Longitude

Raises:
KeyError: No data found for callsign

Example:
The following code returns Latitude & Longitude for "DH1TW"

>>> from pyhamtools import LookupLib, Callinfo
>>> my_lookuplib = LookupLib(lookuptype="countryfile")
>>> cic = Callinfo(my_lookuplib)
>>> cic.get_lat_long("DH1TW")
{
'latitude': 51.0,
'longitude': -10.0
}

Note:
Unfortunately, in most cases the returned Latitude and Longitude are not very precise.
Clublog and Country-files.com use the country's capital coordinates in most cases, if no
dedicated entry in the database exists. Best results will be retrieved with QRZ.com Lookup.


def _find_docstring_line(self, start, end):

        for i in range(start, end + 1):
            if i in self._tokenized_triple_quotes:
                return i
        return None

Find the row where a docstring starts in a function or class.

This will search for the first match of a triple quote token in
row sequence from the start of the class or function.

Args:
start: the row where the class / function starts.
end: the row where the class / function ends.

Returns:
int: the row number where the docstring is found.


def make_job(name: str='', run_name: str='', num_tasks: int=0, install_script: str='', **kwargs) -> backend.Job:
    return _backend.make_job(name=name, run_name=run_name, num_tasks=num_tasks, install_script=install_script, **kwargs)

Create a job using current backend. Blocks until all tasks are up and initialized.

Args:
name: name of the job
run_name: name of the run (auto-assigned if empty)
num_tasks: number of tasks
install_script: bash-runnable script
**kwargs:

Returns:
backend.Job


def import_entities(self, entities):
    edata = Entity.create_payload(entities)
    r = fapi.upload_entities(self.namespace, self.name, edata, self.api_url)
    fapi._check_response_code(r, 201)

Upload entity objects.

Args:
entities: iterable of firecloud.Entity objects.


def clinvar_submission_header(submission_objs, csv_type):

    complete_header = {}
    custom_header = {}
    if csv_type == 'variant_data' :
        complete_header = CLINVAR_HEADER
    else:
        complete_header = CASEDATA_HEADER

    for header_key, header_value in complete_header.items():
        for clinvar_obj in submission_objs:
            for key, value in clinvar_obj.items():

                if not header_key in custom_header and header_key == key:
                    custom_header[header_key] = header_value

    return custom_header

Determine which fields to include in csv header by checking a list of submission objects

Args:
submission_objs(list): a list of objects (variants or casedata) to include in a csv file
csv_type(str) : 'variant_data' or 'case_data'

Returns:
custom_header(dict): A dictionary with the fields required in the csv header. Keys and values are specified in CLINVAR_HEADER and CASEDATA_HEADER


def CalculateWaitForRetry(retry_attempt, max_wait=60):
    wait_time = (2 ** retry_attempt)
    max_jitter = (wait_time / 4.0)
    wait_time += random.uniform((- max_jitter), max_jitter)
    return max(1, min(wait_time, max_wait))

Calculates amount of time to wait before a retry attempt.

Wait time grows exponentially with the number of attempts. A
random amount of jitter is added to spread out retry attempts from
different clients.

Args:
retry_attempt: Retry attempt counter.
max_wait: Upper bound for wait time [seconds].

Returns:
Number of seconds to wait before retrying request.


def deploy(app_id, version, promote, quiet):

    gae_app = GaeApp.for_branch(git.current_branch().name)

    if gae_app is None and None in (app_id,  version):
        msg = (
            "Can't find an AppEngine app setup for branch <35>{}<32> and"
            "--project and --version were not given."
        )
        log.err(msg, git.current_branch().name)
        sys.exit(1)

    if version is not None:
        gae_app.version = version

    if app_id is not None:
        gae_app.app_id = app_id

    gae_app.deploy(promote, quiet)

Deploy the app to AppEngine.

Args:
app_id (str):
AppEngine App ID. Overrides config value app_id if given.
version (str):
AppEngine project version. Overrides config values if given.
promote (bool):
If set to **True** promote the current remote app version to the one
that's being deployed.
quiet (bool):
If set to **True** this will pass the ``--quiet`` flag to gcloud
command.


def output_shape(self):
    if not self._inbound_nodes:
        raise AttributeError('The layer has never been called and thus has no defined output shape.')
    all_output_shapes = set([str(node.output_shapes) for node in self._inbound_nodes])
    if len(all_output_shapes) == 1:
        return self._inbound_nodes[0].output_shapes
    else:
        raise AttributeError('The layer "%s" has multiple inbound nodes, with different output shapes. Hence the notion of "output shape" is ill-defined for the layer. Use `get_output_shape_at(node_index)` instead.' % self.name)

Retrieves the output shape(s) of a layer.

Only applicable if the layer has one output,
or if all outputs have the same shape.

Returns:
Output shape, as an integer shape tuple
(or list of shape tuples, one tuple per output tensor).

Raises:
AttributeError: if the layer has no defined output shape.
RuntimeError: if called in Eager mode.


def remove(self,
               entity_id,
               property_uri,
               value):

        if not entity_id.startswith("http"):
            entity_uri = urllib.parse.urljoin(self.base_url, entity_id)
        else:
            entity_uri = entity_id
        sparql_template = Template()
        sparql = sparql_template.substitute(
            prefix=build_prefixes(self.namespaces),
            entity=entity_uri,
            prop_name=property_uri,
            value_str=self.__value_format__(value))
        delete_property_request = urllib.request.Request(
            entity_uri,
            data=sparql.encode(),
            method='PATCH',
            headers={'Content-Type': 'application/sparql-update'})
        response = urllib.request.urlopen(delete_property_request)
        if response.code < 400:
            return True
        return False

Method removes a triple for the given/subject.

Args:
entity_id(string): Fedora Object ID, ideally URI of the subject
property_uri(string):
value(string):

Return:
boolean: True if triple was removed from the object


def candidate_paths(self, filepath):
    (filelead, filetail) = os.path.split(filepath)
    (name, extension) = os.path.splitext(filetail)
    if extension:
        extension = extension[1:]
    filenames = [name]
    if (not name.startswith('_')):
        filenames.append('_{}'.format(name))
    if (extension and (extension in self.CANDIDATE_EXTENSIONS)):
        filenames = ['.'.join([k, extension]) for k in filenames]
    else:
        if extension:
            filenames = ['.'.join([k, extension]) for k in filenames]
        new = []
        for ext in self.CANDIDATE_EXTENSIONS:
            new.extend(['.'.join([k, ext]) for k in filenames])
        filenames = new
    return [os.path.join(filelead, v) for v in filenames]

Return candidates path for given path

* If Filename does not starts with ``_``, will build a candidate for
both with and without ``_`` prefix;
* Will build For each available extensions if filename does not have
an explicit extension;
* Leading path directory is preserved;

Args:
filepath (str): Relative path as finded in an import rule from a
SCSS source.

Returns:
list: Builded candidate paths (as relative paths).


def forward(self, encoder_hidden_states, padding_masks=None):
    hidden_states = encoder_hidden_states.transpose(1, -1)
    for layer in self.conv_layers:
        hidden_states = layer(hidden_states)
    hidden_states = self.linear(hidden_states.transpose(1, 2))
    if padding_masks is not None:
        hidden_states = hidden_states.masked_fill(padding_masks, 0.0)
    return hidden_states

Calculate forward propagation.

Args:
encoder_hidden_states (`torch.Tensor` of shape `(batch_size, max_text_length, input_dim)`):
Batch of input sequences.
padding_masks (`torch.ByteTensor` of shape `(batch_size, max_text_length)`, *optional*):
Batch of masks indicating padded part.

Returns:
Tensor: Batch of predicted sequences `(batch_size, max_text_length, 1)`.


def toarray(vari):
    if isinstance(vari, Poly):
        shape = vari.shape
        out = numpy.asarray([{} for _ in range(numpy.prod(shape))], dtype=object)
        core = vari.A.copy()
        for key in core.keys():
            core[key] = core[key].flatten()
            for i in range(numpy.prod(shape)):
                if (not numpy.all((core[key][i] == 0))):
                    out[i][key] = core[key][i]
        for i in range(numpy.prod(shape)):
            out[i] = Poly(out[i], vari.dim, (), vari.dtype)
        out = out.reshape(shape)
        return out
    return numpy.asarray(vari)

Convert polynomial array into a numpy.asarray of polynomials.

Args:
vari (Poly, numpy.ndarray):
Input data.

Returns:
(numpy.ndarray):
A numpy array with ``Q.shape==A.shape``.

Examples:
>>> poly = cp.prange(3)
>>> print(poly)
[1, q0, q0^2]
>>> array = cp.toarray(poly)
>>> print(isinstance(array, numpy.ndarray))
True
>>> print(array[1])
q0


def list_images(self):
    r = self.get((self.registry_url + '/v2/_catalog'), auth=self.auth)
    return r.json()['repositories']

List images stored in the registry.

Returns:
list[str]: List of image names.


def get_unique_tags(field_to_obs):
    return {field: sorted(set([x.get('tag', '') for x in observations])) for (field, observations) in field_to_obs.items() if (field in TAG_FIELDS)}

Returns a dictionary of tags that a user could query over.

Args:
field_to_obs: Dict that maps string field to `Observation` list.

Returns:
A dict that maps keys in `TAG_FIELDS` to a list of string tags present in
the event files. If the dict does not have any observations of the type,
maps to an empty list so that we can render this to console.


def gae_advantages(td_deltas, mask, lambda_=0.95, gamma=0.99):
    return rewards_to_go(td_deltas, mask, (lambda_ * gamma))

r"""Computes the GAE advantages given the one step TD-residuals.

The formula for a GAE advantage estimator is as follows:

A_{bt} = \sum_{l=0}^{\infty}(\gamma * \lambda)^{l}(\delta_{b,t+l}).

Internally we just call rewards_to_go, since it is the same computation.

Args:
td_deltas: np.ndarray of shape (B, T) of one step TD-residuals.
mask: np.ndarray of shape (B, T) of mask for the residuals. It maybe the
case that the `td_deltas` are already masked correctly since they are
produced by `deltas(...)`
lambda_: float, lambda parameter for GAE estimators.
gamma: float, lambda parameter for GAE estimators.

Returns:
GAE advantage estimates.


def reset_time_estimate(self, **kwargs):

        path = '%s/%s/reset_time_estimate' % (self.manager.path, self.get_id())
        return self.manager.gitlab.http_post(path, **kwargs)

Resets estimated time for the object to 0 seconds.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabTimeTrackingError: If the time tracking update cannot be done


def smooth(self, noise, strategy=INVERSE_STRATEGY):

        if strategy is INVERSE_STRATEGY:
            self.points = with_inverse(self.points, noise)
        elif strategy is EXTRAPOLATE_STRATEGY:
            self.points = with_extrapolation(self.points, noise, 30)
        elif strategy is NO_STRATEGY:
            self.points = with_no_strategy(self.points, noise)
        return self

In-place smoothing

See smooth_segment function

Args:
noise (float): Noise expected
strategy (int): Strategy to use. Either smooth.INVERSE_STRATEGY
or smooth.EXTRAPOLATE_STRATEGY
Returns:
:obj:`Segment`


def _InitValues(self, sizes):
    total_size = 1
    for s in sizes:
        total_size *= s
    x = [f * 0.5 for f in range(1, total_size + 1)]
    return constant_op.constant(x, shape=sizes)

Initializes values for input tensors.

Args:
sizes: Tensor dimensions.

Returns:
Tensor initialized to values.


def update_headers(self, response):

        if 'expires' in response.headers and 'cache-control' in response.headers:
            self.msg = self.server_cache_headers
            return response.headers
        else:
            self.msg = self.default_cache_vars
            date = parsedate(response.headers['date'])
            expires = datetime(*date[:6]) + timedelta(0, self.expire_after)
            response.headers.update({'expires': formatdate(calendar.timegm(expires.timetuple())),
                                'cache-control': 'public'})
            return response.headers

Returns the updated caching headers.

Args:
response (HttpResponse): The response from the remote service

Returns:
response:(HttpResponse.Headers): Http caching headers


def require_version(requirement: str, hint: Optional[str]=None) -> None:
    hint = f'\n{hint}' if hint is not None else ''
    if re.match('^[\\w_\\-\\d]+$', requirement):
        pkg, op, want_ver = (requirement, None, None)
    else:
        match = re.findall('^([^!=<>\\s]+)([\\s!=<>]{1,2}.+)', requirement)
        if not match:
            raise ValueError(f'requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but got {requirement}')
        pkg, want_full = match[0]
        want_range = want_full.split(',')
        wanted = {}
        for w in want_range:
            match = re.findall('^([\\s!=<>]{1,2})(.+)', w)
            if not match:
                raise ValueError(f'requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but got {requirement}')
            op, want_ver = match[0]
            wanted[op] = want_ver
            if op not in ops:
                raise ValueError(f'{requirement}: need one of {list(ops.keys())}, but got {op}')
    if pkg == 'python':
        got_ver = '.'.join([str(x) for x in sys.version_info[:3]])
        for op, want_ver in wanted.items():
            _compare_versions(op, got_ver, want_ver, requirement, pkg, hint)
        return
    try:
        got_ver = importlib.metadata.version(pkg)
    except importlib.metadata.PackageNotFoundError:
        raise importlib.metadata.PackageNotFoundError(f"The '{requirement}' distribution was not found and is required by this application. {hint}")
    if want_ver is not None:
        for op, want_ver in wanted.items():
            _compare_versions(op, got_ver, want_ver, requirement, pkg, hint)

Perform a runtime check of the dependency versions, using the exact same syntax used by pip.

The installed module version comes from the *site-packages* dir via *importlib.metadata*.

Args:
requirement (`str`): pip style definition, e.g.,  "tokenizers==0.9.4", "tqdm>=4.27", "numpy"
hint (`str`, *optional*): what suggestion to print in case of requirements not being met

Example:

```python
require_version("pandas>1.1.2")
require_version("numpy>1.18.5", "this is important to have for whatever reason")
```


def pb(name, data, display_name=None, description=None):
    import tensorflow.compat.v1 as tf
    data = np.array(data)
    if (data.shape != ()):
        raise ValueError(('Expected scalar shape for data, saw shape: %s.' % data.shape))
    if (data.dtype.kind not in ('b', 'i', 'u', 'f')):
        raise ValueError(('Cast %s to float is not supported' % data.dtype.name))
    tensor = tf.make_tensor_proto(data.astype(np.float32))
    if (display_name is None):
        display_name = name
    summary_metadata = metadata.create_summary_metadata(display_name=display_name, description=description)
    tf_summary_metadata = tf.SummaryMetadata.FromString(summary_metadata.SerializeToString())
    summary = tf.Summary()
    summary.value.add(tag=('%s/scalar_summary' % name), metadata=tf_summary_metadata, tensor=tensor)
    return summary

Create a legacy scalar summary protobuf.

Arguments:
name: A unique name for the generated summary, including any desired
name scopes.
data: A rank-0 `np.array` or array-like form (so raw `int`s and
`float`s are fine, too).
display_name: Optional name for this summary in TensorBoard, as a
`str`. Defaults to `name`.
description: Optional long-form description for this summary, as a
`str`. Markdown is supported. Defaults to empty.

Returns:
A `tf.Summary` protobuf object.


def cube(data, xcoords=None, ycoords=None, chcoords=None, scalarcoords=None, datacoords=None, attrs=None, name=None):
    cube = xr.DataArray(data, dims=('x', 'y', 'ch'), attrs=attrs, name=name)
    cube.dcc._initcoords()
    if (xcoords is not None):
        cube.coords.update({key: ('x', xcoords[key]) for key in xcoords})
    if (ycoords is not None):
        cube.coords.update({key: ('y', ycoords[key]) for key in ycoords})
    if (chcoords is not None):
        cube.coords.update({key: ('ch', chcoords[key]) for key in chcoords})
    if (datacoords is not None):
        cube.coords.update({key: (('x', 'y', 'ch'), datacoords[key]) for key in datacoords})
    if (scalarcoords is not None):
        cube.coords.update(scalarcoords)
    return cube

Create a cube as an instance of xarray.DataArray with Decode accessor.

Args:
data (numpy.ndarray): 3D (x x y x channel) array.
xcoords (dict, optional): Dictionary of arrays that label x axis.
ycoords (dict, optional): Dictionary of arrays that label y axis.
chcoords (dict, optional): Dictionary of arrays that label channel axis.
scalarcoords (dict, optional): Dictionary of values that don't label any axes (point-like).
datacoords (dict, optional): Dictionary of arrays that label x, y, and channel axes.
attrs (dict, optional): Dictionary of attributes to add to the instance.
name (str, optional): String that names the instance.

Returns:
decode cube (decode.cube): Decode cube.


def acquire(self, constructor_fn: Callable[[], Any], tag: Any=None) -> Any:
    return _shared_map.acquire(self._key, constructor_fn, tag)

Acquire a reference to the object associated with this Shared handle.

Args:
constructor_fn: function that initialises / constructs the object if not
present in the cache. This function should take no arguments. It should
return an initialised object, or None if the object could not be
initialised / constructed.
tag: an optional indentifier to store with the cached object. If
subsequent calls to acquire use different tags, the object will be
reloaded rather than returned from cache.

Returns:
A reference to an initialised object, either from the cache, or
newly-constructed.


def validate_redis(self, db_data, user_data, oper):

        passed = True

        if isinstance(db_data, int):
            db_data = str(db_data)
        if isinstance(user_data, int):
            user_data = str(user_data)

        if isinstance(db_data, (list)):
            try:
                db_data = sorted(db_data)
            except TypeError:

                pass
        if isinstance(user_data, (list)):
            try:
                user_data = sorted(user_data)
            except TypeError:

                pass

        if oper not in self.operators:
            self.log.error('Invalid operator provided ({})'.format(oper))
            return False

        if self.operators.get(oper)(db_data, user_data):
            self.reports.profile_validation(True)
        else:
            self.reports.profile_validation(False)
            passed = False

        self.validate_log_output(passed, db_data, user_data, oper)

        return passed

Validate data in Redis.

Args:
db_data (str): The data store in Redis.
user_data (str): The user provided data.
oper (str): The comparison operator.

Returns:
bool: True if the data passed validation.