def cat_adb_log(self, tag, begin_time):

        if not self.adb_logcat_file_path:
            raise Error(
                self._ad,
                'Attempting to cat adb log when none has been collected.')
        end_time = mobly_logger.get_log_line_timestamp()
        self._ad.log.debug('Extracting adb log from logcat.')
        adb_excerpt_path = os.path.join(self._ad.log_path, 'AdbLogExcerpts')
        utils.create_dir(adb_excerpt_path)
        f_name = os.path.basename(self.adb_logcat_file_path)
        out_name = f_name.replace('adblog,', '').replace('.txt', '')
        out_name = ',%s,%s.txt' % (begin_time, out_name)
        out_name = out_name.replace(':', '-')
        tag_len = utils.MAX_FILENAME_LEN - len(out_name)
        tag = tag[:tag_len]
        out_name = tag + out_name
        full_adblog_path = os.path.join(adb_excerpt_path, out_name)
        with io.open(full_adblog_path, 'w', encoding='utf-8') as out:
            in_file = self.adb_logcat_file_path
            with io.open(
                    in_file, 'r', encoding='utf-8', errors='replace') as f:
                in_range = False
                while True:
                    line = None
                    try:
                        line = f.readline()
                        if not line:
                            break
                    except:
                        continue
                    line_time = line[:mobly_logger.log_line_timestamp_len]
                    if not mobly_logger.is_valid_logline_timestamp(line_time):
                        continue
                    if self._is_timestamp_in_range(line_time, begin_time,
                                                   end_time):
                        in_range = True
                        if not line.endswith('\n'):
                            line += '\n'
                        out.write(line)
                    else:
                        if in_range:
                            break

Takes an excerpt of the adb logcat log from a certain time point to
current time.

Args:
tag: An identifier of the time period, usualy the name of a test.
begin_time: Logline format timestamp of the beginning of the time
period.


def write_pattern(lines_per_file, no_data=False):
    temp_dir = tempfile.mkdtemp()
    all_data = []
    file_name = None
    start_index = 0
    for i in range(len(lines_per_file)):
        file_name, data = write_data(lines_per_file[i], no_data=no_data, directory=temp_dir, prefix='mytemp')
        all_data.extend(data)
        start_index += lines_per_file[i]
    assert file_name
    return (file_name[:file_name.rfind(os.path.sep)] + os.path.sep + 'mytemp*', all_data)

Writes a pattern of temporary files.

Args:
lines_per_file (List[int]): The number of lines to write per file.
no_data (bool): If :data:`True`, empty lines will be written, otherwise
each line will contain a concatenation of b'line' and the line number.

Returns:
Tuple[str, List[bytes]]: A tuple of the filename pattern and a list of the
written data.


def _save_and_log_checkpoint(self, actor):
    actor_id = self._worker.actor_id
    checkpoint_info = self._worker.actor_checkpoint_info[actor_id]
    checkpoint_info.num_tasks_since_last_checkpoint += 1
    now = int((1000 * time.time()))
    checkpoint_context = ray.actor.CheckpointContext(actor_id, checkpoint_info.num_tasks_since_last_checkpoint, (now - checkpoint_info.last_checkpoint_timestamp))
    if actor.should_checkpoint(checkpoint_context):
        try:
            now = int((1000 * time.time()))
            checkpoint_id = self._worker.raylet_client.prepare_actor_checkpoint(actor_id)
            checkpoint_info.checkpoint_ids.append(checkpoint_id)
            actor.save_checkpoint(actor_id, checkpoint_id)
            if (len(checkpoint_info.checkpoint_ids) > ray._config.num_actor_checkpoints_to_keep()):
                actor.checkpoint_expired(actor_id, checkpoint_info.checkpoint_ids.pop(0))
            checkpoint_info.num_tasks_since_last_checkpoint = 0
            checkpoint_info.last_checkpoint_timestamp = now
        except Exception:
            traceback_str = ray.utils.format_error_message(traceback.format_exc())
            ray.utils.push_error_to_driver(self._worker, ray_constants.CHECKPOINT_PUSH_ERROR, traceback_str, driver_id=self._worker.task_driver_id)

Save an actor checkpoint if necessary and log any errors.

Args:
actor: The actor to checkpoint.

Returns:
The result of the actor's user-defined `save_checkpoint` method.


def wait_for_task(self, task, timeout=-1):

        self.__wait_task_completion(task, timeout)

        task = self.get(task)

        logger.debug("Waiting for task. Percentage complete: " + str(task.get('computedPercentComplete')))
        logger.debug("Waiting for task. Task state: " + str(task.get('taskState')))

        task_response = self.__get_task_response(task)
        logger.debug('Task completed')
        return task_response

Wait for task execution and return associated resource.

Args:
task: task dict
timeout: timeout in seconds

Returns:
Associated resource when creating or updating; True when deleting.


def add_chain_ids(self, chains):

        chains = ssbio.utils.force_list(chains)

        for c in chains:
            if self.chains.has_id(c):
                log.debug('{}: chain already present'.format(c))
            else:
                chain_prop = ChainProp(ident=c, pdb_parent=self.id)
                self.chains.append(chain_prop)
                log.debug('{}: added to chains list'.format(c))

Add chains by ID into the chains attribute

Args:
chains (str, list): Chain ID or list of IDs


def FilterItems(self, filterFn, key=None):
    with self._mutex:
        if key:
            if (key in self._buckets):
                return self._buckets[key].FilterItems(filterFn)
            else:
                return 0
        else:
            return sum((bucket.FilterItems(filterFn) for bucket in self._buckets.values()))

Filter items within a Reservoir, using a filtering function.

Args:
filterFn: A function that returns True for the items to be kept.
key: An optional bucket key to filter. If not specified, will filter all
all buckets.

Returns:
The number of items removed.


def parse_header_format(description):

    description = description.strip('"')
    keyword = 'Format:'
    before_keyword, keyword, after_keyword = description.partition(keyword)
    return after_keyword.strip()

Get the format from a vcf header line description

If format begins with white space it will be stripped

Args:
description(str): Description from a vcf header line

Return:
format(str): The format information from description


def lcm(*numbers):
    n = 1
    for i in numbers:
        n = ((i * n)
    return n

Return lowest common multiple of a sequence of numbers.

Args:
\*numbers: Sequence of numbers.

Returns:
(int) Lowest common multiple of numbers.


def _execute(self, connection, query, fetch=True):

        with connection.cursor() as cursor:
            cursor.execute(query)
            if fetch:
                return cursor.fetchall()
            else:
                cursor.execute('COMMIT;')

Executes given query and returns result.

Args:
connection: connection to postgres database who stores mpr data.
query (str): sql query
fetch (boolean, optional): if True, fetch query result and return it. If False, do not fetch.

Returns:
iterable with query result or None if fetch is False.


def _create_tensor_summary(name, true_positive_counts, false_positive_counts, true_negative_counts, false_negative_counts, precision, recall, num_thresholds=None, display_name=None, description=None, collections=None):
    import tensorflow.compat.v1 as tf
    summary_metadata = metadata.create_summary_metadata(display_name=(display_name if (display_name is not None) else name), description=(description or ''), num_thresholds=num_thresholds)
    combined_data = tf.stack([tf.cast(true_positive_counts, tf.float32), tf.cast(false_positive_counts, tf.float32), tf.cast(true_negative_counts, tf.float32), tf.cast(false_negative_counts, tf.float32), tf.cast(precision, tf.float32), tf.cast(recall, tf.float32)])
    return tf.summary.tensor_summary(name='pr_curves', tensor=combined_data, collections=collections, summary_metadata=summary_metadata)

A private helper method for generating a tensor summary.

We use a helper method instead of having `op` directly call `raw_data_op`
to prevent the scope of `raw_data_op` from being embedded within `op`.

Arguments are the same as for raw_data_op.

Returns:
A tensor summary that collects data for PR curves.


def AddCustomJsonEnumMapping(enum_type, python_name, json_name,
                             package=None):

    if not issubclass(enum_type, messages.Enum):
        raise exceptions.TypecheckError(
            'Cannot set JSON enum mapping for non-enum "%s"' % enum_type)
    if python_name not in enum_type.names():
        raise exceptions.InvalidDataError(
            'Enum value %s not a value for type %s' % (python_name, enum_type))
    field_mappings = _JSON_ENUM_MAPPINGS.setdefault(enum_type, {})
    _CheckForExistingMappings('enum', enum_type, python_name, json_name)
    field_mappings[python_name] = json_name

Add a custom wire encoding for a given enum value.

This is primarily used in generated code, to handle enum values
which happen to be Python keywords.

Args:
enum_type: (messages.Enum) An enum type
python_name: (basestring) Python name for this value.
json_name: (basestring) JSON name to be used on the wire.
package: (NoneType, optional) No effect, exists for legacy compatibility.


def __init__(self, ea):

        self._ea = ea

        results = self._calc_cases()

        self._map = self._build_map(results)

        self._reverse_map = self._build_reverse(self._map)

Initialize a switch parser.

Args:
ea: An address of a switch jump instruction.


def rich_text_lines_from_rich_line_list(rich_text_list, annotations=None):
    lines = []
    font_attr_segs = {}
    for i, rl in enumerate(rich_text_list):
        if isinstance(rl, RichLine):
            lines.append(rl.text)
            if rl.font_attr_segs:
                font_attr_segs[i] = rl.font_attr_segs
        else:
            lines.append(rl)
    return RichTextLines(lines, font_attr_segs, annotations=annotations)

Convert a list of RichLine objects or strings to a RichTextLines object.

Args:
rich_text_list: a list of RichLine objects or strings
annotations: annotations for the resultant RichTextLines object.

Returns:
A corresponding RichTextLines object.


def startstop(inst_id, cmdtodo):
    tar_inst = EC2R.Instance(inst_id)
    thecmd = getattr(tar_inst, cmdtodo)
    response = thecmd()
    return response

Start or Stop the Specified Instance.

Args:
inst_id (str): instance-id to perform command against
cmdtodo (str): command to perform (start or stop)
Returns:
response (dict): reponse returned from AWS after
performing specified action.


def _close(self, close_type):
    txn_response = self.api.http_request('POST', ('%sfcr:tx/fcr:%s' % (self.root, close_type)), data=None, headers=None)
    if (txn_response.status_code == 204):
        logger.debug(('%s for transaction: %s, successful' % (close_type, self.root)))
        self.active = False
        return True
    elif (txn_response.status_code in [404, 410]):
        logger.debug(('transaction does not exist: %s' % self.root))
        self.active = False
        return False
    else:
        raise Exception(('HTTP %s, could not commit transaction' % txn_response.status_code))

Ends transaction by committing, or rolling back, all changes during transaction.

Args:
close_type (str): expects "commit" or "rollback"

Return:
(bool)


def fetch(clobber=False):

    table_dir = os.path.join(data_dir(), 'marshall')

    if not clobber:
        h5_fname = os.path.join(table_dir, 'marshall.h5')
        h5_size = 5033290
        h5_dsets = {
            'l': (801, 81),
            'b': (801, 81),
            'chi2_all': (801, 81),
            'chi2_giants': (801, 81),
            'A': (801, 81, 33),
            'sigma_A': (801, 81, 33),
            'dist': (801, 81, 33),
            'sigma_dist': (801, 81, 33)
        }
        if fetch_utils.h5_file_exists(h5_fname, h5_size, dsets=h5_dsets):
            print('File appears to exist already. Call ``fetch(clobber=True)`` '
                  'to force overwriting of existing file.')
            return

    url = 'ftp:
    md5 = '637b95b025517a8b9757b6465b632285'
    table_fname = os.path.join(table_dir, 'table1.dat.gz')
    fetch_utils.download_and_verify(url, md5, fname=table_fname)

    url = 'ftp:
    md5 = '3b7c1296b181b3d77106ab50193dc7ee'
    readme_fname = os.path.join(table_dir, 'ReadMe')
    fetch_utils.download_and_verify(url, md5, fname=readme_fname)

    dat2hdf5(table_dir)

    print('Cleaning up ...')
    os.remove(table_fname)
    os.remove(readme_fname)

Downloads the Marshall et al. (2006) dust map, which is based on 2MASS
stellar photometry.

Args:
clobber (Optional[:obj:`bool`]): If ``True``, any existing file will be
overwritten, even if it appears to match. If ``False`` (the
default), :obj:`fetch()` will attempt to determine if the dataset
already exists. This determination is not 100\% robust against data
corruption.


def update_all(cls, *criterion, **kwargs):

        try:
            r = cls.query.filter(*criterion).update(kwargs, 'fetch')
            cls.session.commit()
            return r
        except:
            cls.session.rollback()
            raise

Batch method for updating all instances obeying the criterion

Args:
*criterion: SQLAlchemy query criterion for filtering what
instances to update
**kwargs: The parameters to be updated

Examples:

>>> User.update_all(active=True)

>>> Customer.update_all(Customer.country=='India', active=True)

The second example sets active=True for all customers with
country India.


def _crossover(candidate):
    sample_index1 = np.random.choice(len(candidate))
    sample_index2 = np.random.choice(len(candidate))
    sample_1 = candidate[sample_index1]
    sample_2 = candidate[sample_index2]
    cross_index = int((len(sample_1) * np.random.uniform(low=0.3, high=0.7)))
    logger.info((LOGGING_PREFIX + 'Perform crossover between %sth and %sth at index=%s'), sample_index1, sample_index2, cross_index)
    next_gen = []
    for i in range(len(sample_1)):
        if (i > cross_index):
            next_gen.append(sample_2[i])
        else:
            next_gen.append(sample_1[i])
    return next_gen

Perform crossover action to candidates.

For example, new gene = 60% sample_1 + 40% sample_2.

Args:
candidate: List of candidate genes (encodings).

Examples:
>>> # Genes that represent 3 parameters
>>> gene1 = np.array([[0, 0, 1], [0, 1], [1, 0]])
>>> gene2 = np.array([[0, 1, 0], [1, 0], [0, 1]])
>>> new_gene = _crossover([gene1, gene2])
>>> # new_gene could be the first [n=1] parameters of
>>> # gene1 + the rest of gene2
>>> # in which case:
>>> #   new_gene[0] = gene1[0]
>>> #   new_gene[1] = gene2[1]
>>> #   new_gene[2] = gene1[1]

Returns:
New gene (encoding)


def rms(x):
    try:
        return ((np.array(x) ** 2).mean() ** 0.5)
    except:
        x = np.array(dropna(x))
        invN = (1.0 / len(x))
        return (sum(((invN * (x_i ** 2)) for x_i in x)) ** 0.5)

Root Mean Square"

Arguments:
x (seq of float): A sequence of numerical values

Returns:
The square root of the average of the squares of the values

math.sqrt(sum(x_i**2 for x_i in x) / len(x))

or

return (np.array(x) ** 2).mean() ** 0.5

>>> rms([0, 2, 4, 4])
3.0


def add_resource(self, feature_column, name, resource):
    del feature_column, name, resource
    raise NotImplementedError('StateManager.add_resource')

Creates a new resource.

Resources can be things such as tables, variables, trackables, etc.

Args:
feature_column: A `FeatureColumn` object this resource corresponds to.
name: Name of the resource.
resource: The resource.

Returns:
The created resource.


def get_urls_from_onetab(onetab):

    html = requests.get(onetab).text
    soup = BeautifulSoup(html, 'lxml')

    divs = soup.findAll('div', {'style': 'padding-left: 24px; '
                                         'padding-top: 8px; '
                                         'position: relative; '
                                         'font-size: 13px;'})

    return [div.find('a').attrs['href'] for div in divs]

Get video urls from a link to the onetab shared page.

Args:
onetab (str): Link to a onetab shared page.

Returns:
list: List of links to the videos.


def _tuple_of_big_endian_int(bit_groups: Tuple[np.ndarray, ...]
                             ) -> Tuple[int, ...]:

    return tuple(_big_endian_int(bits) for bits in bit_groups)

Returns the big-endian integers specified by groups of bits.

Args:
bit_groups: Groups of descending bits, each specifying a big endian
integer with the 1s bit at the end.

Returns:
A tuple containing the integer for each group.


def epoch_to_log_line_timestamp(epoch_time, time_zone=None):
    (s, ms) = divmod(epoch_time, 1000)
    d = datetime.datetime.fromtimestamp(s, tz=time_zone)
    return (d.strftime('%m-%d %H:%M:%S.') + str(ms))

Converts an epoch timestamp in ms to log line timestamp format, which
is readible for humans.

Args:
epoch_time: integer, an epoch timestamp in ms.
time_zone: instance of tzinfo, time zone information.
Using pytz rather than python 3.2 time_zone implementation for
python 2 compatibility reasons.

Returns:
A string that is the corresponding timestamp in log line timestamp
format.


def remove_subj(self, subj_str):
    for subj_set in list(self._perm_dict.values()):
        subj_set -= {subj_str}

Remove all permissions for subject.

Args:
subj_str : str
Subject for which to remove all permissions. Since subjects can only be present
in the AccessPolicy when they have one or more permissions, this removes the
subject itself as well.

The subject may still have access to the obj. E.g.:

* The obj has public access.
* The subj has indirect access by being in a group which has access.
* The subj has an equivalent subj that has access.
* The subj is set as the rightsHolder for the object.


def addFixedEffect(self, F=None, A=None, Ftest=None):
    if (A is None):
        A = sp.eye(self.P)
    if (F is None):
        F = sp.ones((self.N, 1))
        if (self.Ntest is not None):
            Ftest = sp.ones((self.Ntest, 1))
    assert (A.shape[1] == self.P), 'VarianceDecomposition:: A has incompatible shape'
    assert (F.shape[0] == self.N), 'VarianceDecimposition:: F has incompatible shape'
    if (Ftest is not None):
        assert (self.Ntest is not None), 'VarianceDecomposition:: specify Ntest for predictions (method VarianceDecomposition::setTestSampleSize)'
        assert (Ftest.shape[0] == self.Ntest), 'VarianceDecimposition:: Ftest has incompatible shape'
        assert (Ftest.shape[1] == F.shape[1]), 'VarianceDecimposition:: Ftest has incompatible shape'
    self.sample_designs.append(F)
    self.sample_test_designs.append(Ftest)
    self.trait_designs.append(A)
    self._desync()

add fixed effect term to the model

Args:
F:     sample design matrix for the fixed effect [N,K]
A:     trait design matrix for the fixed effect (e.g. sp.ones((1,P)) common effect; sp.eye(P) any effect) [L,P]
Ftest: sample design matrix for test samples [Ntest,K]


def stop_artifact_creation(self, id_or_uri, task_uri):

        data = {
            "taskUri": task_uri
        }

        uri = self.URI + '/' + extract_id_from_uri(id_or_uri) + self.STOP_CREATION_PATH

        return self._client.update(data, uri=uri)

Stops creation of the selected Artifact Bundle.

Args:
id_or_uri: ID or URI of the Artifact Bundle.
task_uri: Task URI associated with the Artifact Bundle.

Returns:
string:


def read_into(self, buffer, size=(- 1), *, offset=0, write_offset=0) -> None:
    return self.mglo.read_into(buffer, size, offset, write_offset)

Read the content into a buffer.

Args:
buffer (bytarray): The buffer that will receive the content.
size (int): The size. Value ``-1`` means all.

Keyword Args:
offset (int): The read offset.
write_offset (int): The write offset.


def time(func, *args, **kwargs):

    start_time = time_module.time()
    func(*args, **kwargs)
    end_time = time_module.time()
    return end_time - start_time

Call the supplied function with the supplied arguments,
and return the total execution time as a float in seconds.

The precision of the returned value depends on the precision of
`time.time()` on your platform.

Arguments:
func: the function to run.
*args: positional arguments to pass into the function.
**kwargs: keyword arguments to pass into the function.
Returns:
Execution time of the function as a float in seconds.


def substatements(self) -> List[Statement]:
    res = []
    self.opt_separator()
    while (self.peek() != '}'):
        res.append(self.statement())
        self.opt_separator()
    self.offset += 1
    return res

Parse substatements.

Raises:
EndOfInput: If past the end of input.


def compute_actor_handle_id(actor_handle_id, num_forks):
    assert isinstance(actor_handle_id, ActorHandleID)
    handle_id_hash = hashlib.sha1()
    handle_id_hash.update(actor_handle_id.binary())
    handle_id_hash.update(str(num_forks).encode('ascii'))
    handle_id = handle_id_hash.digest()
    return ActorHandleID(handle_id)

Deterministically compute an actor handle ID.

A new actor handle ID is generated when it is forked from another actor
handle. The new handle ID is computed as hash(old_handle_id || num_forks).

Args:
actor_handle_id (common.ObjectID): The original actor handle ID.
num_forks: The number of times the original actor handle has been
forked so far.

Returns:
An ID for the new actor handle.


def Rsync(url, tgt_name, tgt_root=None):

    if tgt_root is None:
        tgt_root = str(CFG["tmp_dir"])

    from benchbuild.utils.cmd import rsync

    tgt_dir = local.path(tgt_root) / tgt_name
    if not source_required(tgt_dir):
        Copy(tgt_dir, ".")
        return

    rsync("-a", url, tgt_dir)
    update_hash(tgt_dir)
    Copy(tgt_dir, ".")

RSync a folder.

Args:
url (str): The url of the SOURCE location.
fname (str): The name of the TARGET.
to (str): Path of the target location.
Defaults to ``CFG["tmpdir"]``.


def execute_feed(feed, dao, print_field, msg='Processing'):
    global clean_run
    try:
        dao.pre_fetch(feed.feed)
        for feed_item in feed.feed:
            try:
                value = feed_item[print_field]
                print('%s %s' % (msg, value))
                logger.log('%s %s' % (msg, value))
                dao.process(feed_item)
            except Exception as error:
                clean_run = False
                stack = traceback.format_exc()
                print(stack)
                logger.log(str(error))
    finally:
        feed.update()

Executes a specific feed.

Args:
feed: Feed object representing the Bulkdozer feed to process.
dao: The data access object to be used to interact with the CM API and
update, must match the entity being updated in CM, in the sense that the
required fields to fetch, create, and update the entity in CM must be
included in the feed.
print_field: Field that identifies the item, used to print status messages
to the Log tab of the Bulkdozer feed.
msg: Prefix message to use when writing to the Log tab of the Bulkdozer
feed, for instance we display Processing Campaign for campaign, and
Uploading Asset for assets.


def is_visible(self, selector):
    self.debug_log(('Is visible (%s)' % selector))
    element = self.find(selector, raise_exception=False, wait_until_present=False, wait_until_visible=False)
    if element:
        if element.is_displayed(raise_exception=False):
            element.highlight(style=BROME_CONFIG['highlight']['element_is_visible'])
            self.debug_log(('is visible (%s): True' % selector))
            return True
    self.debug_log(('is visible (%s): False' % selector))
    return False

Check if an element is visible in the dom or not

This method will check if the element is displayed or not

This method might (according
to the config highlight:element_is_visible)
highlight the element if it is visible

This method won't wait until the element is visible or present
This method won't raise any exception if the element is not visible

Returns:
bool: True if the element is visible; False otherwise


def load_config(logdir):
    config_path = (logdir and os.path.join(logdir, 'config.yaml'))
    if ((not config_path) or (not tf.gfile.Exists(config_path))):
        message = 'Cannot resume an existing run since the logging directory does not contain a configuration file.'
        raise IOError(message)
    with tf.gfile.FastGFile(config_path, 'r') as file_:
        config = yaml.load(file_, Loader=yaml.Loader)
    message = 'Resume run and write summaries and checkpoints to {}.'
    tf.logging.info(message.format(config.logdir))
    return config

Load a configuration from the log directory.

Args:
logdir: The logging directory containing the configuration file.

Raises:
IOError: The logging directory does not contain a configuration file.

Returns:
Configuration object.


def bdp(tickers, flds, **kwargs):
    logger = logs.get_logger(bdp, level=kwargs.pop('log', logs.LOG_LEVEL))
    (con, _) = create_connection()
    ovrds = assist.proc_ovrds(**kwargs)
    logger.info(f)
    data = con.ref(tickers=tickers, flds=flds, ovrds=ovrds)
    if (not kwargs.get('cache', False)):
        return [data]
    qry_data = []
    for (r, snap) in data.iterrows():
        subset = [r]
        data_file = storage.ref_file(ticker=snap.ticker, fld=snap.field, ext='pkl', **kwargs)
        if data_file:
            if (not files.exists(data_file)):
                qry_data.append(data.iloc[subset])
            files.create_folder(data_file, is_file=True)
            data.iloc[subset].to_pickle(data_file)
    return qry_data

Bloomberg reference data

Args:
tickers: tickers
flds: fields to query
**kwargs: bbg overrides

Returns:
pd.DataFrame

Examples:
>>> bdp('IQ US Equity', 'Crncy', raw=True)
ticker  field value
0  IQ US Equity  Crncy   USD
>>> bdp('IQ US Equity', 'Crncy').reset_index()
ticker crncy
0  IQ US Equity   USD


def _EvaluateNumberOfElements(self, context):
    number_of_elements = None
    if self._data_type_definition.number_of_elements:
        number_of_elements = self._data_type_definition.number_of_elements
    elif self._data_type_definition.number_of_elements_expression:
        expression = self._data_type_definition.number_of_elements_expression
        namespace = {}
        if (context and context.values):
            namespace.update(context.values)
        namespace['__builtins__'] = {}
        try:
            number_of_elements = eval(expression, namespace)
        except Exception as exception:
            raise errors.MappingError('Unable to determine number of elements with error: {0!s}'.format(exception))
    if ((number_of_elements is None) or (number_of_elements < 0)):
        raise errors.MappingError('Invalid number of elements: {0!s}'.format(number_of_elements))
    return number_of_elements

Evaluates number of elements.

Args:
context (DataTypeMapContext): data type map context.

Returns:
int: number of elements.

Raises:
MappingError: if the number of elements cannot be determined.


def list(self, params=None, headers=None):
    path = '/creditor_bank_accounts'
    response = self._perform_request('GET', path, params, headers, retry_failures=True)
    return self._resource_for(response)

List creditor bank accounts.

Returns a [cursor-paginated](#api-usage-cursor-pagination) list of your
creditor bank accounts.

Args:
params (dict, optional): Query string parameters.

Returns:
CreditorBankAccount


def lease(self, items):

        self._manager.leaser.add(items)
        self._manager.maybe_pause_consumer()

Add the given messages to lease management.

Args:
items(Sequence[LeaseRequest]): The items to lease.


def _original_vocab(tmp_dir):
    vocab_url = 'http:
    vocab_filename = os.path.basename((vocab_url + '.en'))
    vocab_filepath = os.path.join(tmp_dir, vocab_filename)
    if (not os.path.exists(vocab_filepath)):
        generator_utils.maybe_download(tmp_dir, vocab_filename, vocab_url)
    return set([text_encoder.native_to_unicode(l.strip()) for l in tf.gfile.Open(vocab_filepath)])

Returns a set containing the original vocabulary.

This is important for comparing with published results.

Args:
tmp_dir: directory containing dataset.

Returns:
a set of strings


def _log(self, utterance: Any, direction: str, dialog_id: Optional[Hashable]=None):
    if isinstance(utterance, str):
        pass
    elif isinstance(utterance, RichMessage):
        utterance = utterance.json()
    elif isinstance(utterance, (list, dict)):
        utterance = jsonify_data(utterance)
    else:
        utterance = str(utterance)
    dialog_id = (str(dialog_id) if (not isinstance(dialog_id, str)) else dialog_id)
    if (self.log_file.tell() >= (self.log_max_size * 1024)):
        self.log_file.close()
        self.log_file = self._get_log_file()
    else:
        try:
            log_msg = {}
            log_msg['timestamp'] = self._get_timestamp_utc_str()
            log_msg['dialog_id'] = dialog_id
            log_msg['direction'] = direction
            log_msg['message'] = utterance
            log_str = json.dumps(log_msg, ensure_ascii=self.config['ensure_ascii'])
            self.log_file.write(f)
        except IOError:
            log.error('Failed to write dialog log.')

Logs single dialog utterance to current dialog log file.

Args:
utterance: Dialog utterance.
direction: 'in' or 'out' utterance direction.
dialog_id: Dialog ID.


def enrich_json_objects_by_object_type(request, value):
    time_start_globally = time()
    if isinstance(value, list):
        json = [(x.to_json() if hasattr(x, 'to_json') else x) for x in value]
    elif isinstance(value, dict):
        json = value
    else:
        json = value.to_json()
    (objects, nested) = _collect_json_objects(json, by='object_type')
    for enricher_info in _get_OBJECT_TYPE_ENRICHER_ORDER():
        if (len(enricher_info['object_types']) > 0):
            enricher_objects = flatten([objects.get(object_type, []) for object_type in enricher_info['object_types']])
            enricher_nested = any([nested.get(object_type, False) for object_type in enricher_info['object_types']])
        else:
            enricher_objects = flatten(objects.values())
            enricher_nested = any(nested.values())
        if (len(enricher_objects) > 0):
            time_start = time()
            enricher_info['enricher'](request, enricher_objects, enricher_nested)
            LOGGER.debug('enrichment "{}" took {} seconds'.format(enricher_info['enricher_name'], (time() - time_start)))
            if (not enricher_info['pure']):
                (objects, nested) = _collect_json_objects(json, by='object_type')
    LOGGER.debug('The whole enrichment of json objects by their object_type took {} seconds.'.format((time() - time_start_globally)))
    return json

Take the given value and start enrichment by object_type. The va

Args:
request (django.http.request.HttpRequest): request which is currently processed
value (dict|list|django.db.models.Model):
in case of django.db.models.Model object (or list of these
objects), to_json method is invoked

Returns:
dict|list


def _get_backend(filename):

    filename = os.path.abspath(filename)

    with _backends_lock:
        if filename not in _backends:
            _backends[filename] = _MultiprocessStorageBackend(filename)
        return _backends[filename]

A helper method to get or create a backend with thread locking.

This ensures that only one backend is used per-file per-process, so that
thread and process locks are appropriately shared.

Args:
filename: The full path to the credential storage file.

Returns:
An instance of :class:`_MultiprocessStorageBackend`.


def GenerateBand(self, band, meta_only=False, cast=False):

        if not meta_only:
            fname = band.get('file_name')
            data = self.ReadTif('%s/%s' % (os.path.dirname(self.filename), fname))

        def FixBitmap(d):
            p = d.get('bitmap_description')
            if p:
                lis = p.get('bit')
                bm = dict()

                for i in lis:
                    key = i['num']
                    value = i['text']
                    bm[key] = value
                del d['bitmap_description']
                d['bitmap_description'] = bm
            return d

        band = SetProperties(Band, FixBitmap(self.CleanDict(band)))
        if not meta_only:
            if cast:

                data = data.astype(np.float32)
                data[data==band.fill_value] = -9999
                if band.valid_range is not None:
                    data[data<band.valid_range.min] = -9999
                    data[data>band.valid_range.max] = -9999
                data[data==-9999] = np.nan
            else:
                data = np.ma.masked_where(data==band.fill_value, data)
                if band.valid_range is not None:
                    data = np.ma.masked_where(data<band.valid_range.min, data)
                    data = np.ma.masked_where(data>band.valid_range.max, data)

            if self.yflip:
                data = np.flip(data, 0)
            band.data = data

        if not meta_only:
            band.validate()

        return band

Genreate a Band object given band metadata

Args:
band (dict): dictionary containing metadata for a given band

Return:
Band : the loaded Band onject


def bcs_parameters(n_site, n_fermi, u, t) :

    wave_num = np.linspace(0, 1, n_site, endpoint=False)

    hop_erg = -2 * t * np.cos(2 * np.pi * wave_num)

    fermi_erg = hop_erg[n_fermi

    hop_erg = hop_erg - fermi_erg

    def _bcs_gap(x):

        s = 0.
        for i in range(n_site):
            s += 1. / np.sqrt(hop_erg[i] ** 2 + x ** 2)
        return 1 + s * u / (2 * n_site)

    delta = scipy.optimize.bisect(_bcs_gap, 0.01, 10000. * abs(u))

    bcs_v = np.sqrt(0.5 * (1 - hop_erg / np.sqrt(hop_erg ** 2 + delta ** 2)))

    bog_theta = np.arcsin(bcs_v)

    return delta, bog_theta

Generate the parameters for the BCS ground state, i.e., the
superconducting gap and the rotational angles in the Bogoliubov
transformation.

Args:
n_site: the number of sites in the Hubbard model
n_fermi: the number of fermions
u: the interaction strength
t: the tunneling strength

Returns:
float delta, List[float] bog_theta


def __init__(self, graph_def, input_tensors, output_tensors, input_arrays_with_shape=None, output_arrays=None, experimental_debug_info_func=None):
    super(TFLiteFrozenGraphConverter, self).__init__(experimental_debug_info_func)
    self._graph_def = graph_def
    self._input_tensors = input_tensors
    self._output_tensors = output_tensors
    self._control_output_arrays = None
    if not self._has_valid_tensors():
        self._input_arrays_with_shape = input_arrays_with_shape
        self._output_arrays = output_arrays
    if input_tensors is not None and input_arrays_with_shape is not None:
        logging.warning('input_arrays_with_shape will be ignored when both the given input_tensors and input_arrays_with_shape are not None.')
    if output_tensors is not None and output_arrays is not None:
        logging.warning('output_arrays will be ignored when both the given output_tensors and output_arrays are not None.')

Constructor for TFLiteConverter.

Args:
graph_def: Frozen TensorFlow GraphDef.
input_tensors: List of input tensors. Type and shape are computed using
`foo.shape` and `foo.dtype`.
output_tensors: List of output tensors (only .name is used from this).
input_arrays_with_shape: Tuple of strings representing input tensor names
and list of integers representing input shapes (e.g., [("foo", [1, 16,
16, 3])]). Use only when graph cannot be loaded into TensorFlow and when
`input_tensors` and `output_tensors` are None. (default None)
output_arrays: List of output tensors to freeze graph with. Use only when
graph cannot be loaded into TensorFlow and when `input_tensors` and
`output_tensors` are None. (default None)
experimental_debug_info_func: An experimental function to retrieve the
graph debug info for a set of nodes from the `graph_def`.

Raises:
ValueError: Invalid arguments.


def _verify_compatible_image_shapes(img1, img2):
    shape1 = img1.get_shape().with_rank_at_least(3)
    shape2 = img2.get_shape().with_rank_at_least(3)
    shape1[-3:].assert_is_compatible_with(shape2[-3:])
    if shape1.ndims is not None and shape2.ndims is not None:
        for dim1, dim2 in zip(reversed(shape1.dims[:-3]), reversed(shape2.dims[:-3])):
            if not (dim1 == 1 or dim2 == 1 or dim1.is_compatible_with(dim2)):
                raise ValueError('Two images are not compatible: %s and %s' % (shape1, shape2))
    shape1, shape2 = array_ops.shape_n([img1, img2])
    checks = []
    checks.append(control_flow_assert.Assert(math_ops.greater_equal(array_ops.size(shape1), 3), [shape1, shape2], summarize=10))
    checks.append(control_flow_assert.Assert(math_ops.reduce_all(math_ops.equal(shape1[-3:], shape2[-3:])), [shape1, shape2], summarize=10))
    return (shape1, shape2, checks)

Checks if two image tensors are compatible for applying SSIM or PSNR.

This function checks if two sets of images have ranks at least 3, and if the
last three dimensions match.

Args:
img1: Tensor containing the first image batch.
img2: Tensor containing the second image batch.

Returns:
A tuple containing: the first tensor shape, the second tensor shape, and a
list of control_flow_ops.Assert() ops implementing the checks.

Raises:
ValueError: When static shape check fails.


def execute_processing_block(pb_id: str, log_level='DEBUG'):

    init_logger('sip', show_log_origin=True, propagate=False,
                log_level=log_level)
    LOG.info('+' * 40)
    LOG.info('+ Executing Processing block: %s!', pb_id)
    LOG.info('+' * 40)
    LOG.info('Processing Block Controller version: %s', __version__)
    LOG.info('Docker Swarm API version: %s', sip_swarm_api_version)
    LOG.info('Configuration database API version: %s', config_db_version)

    pb = ProcessingBlock(pb_id)

    LOG.info('Starting workflow %s %s', pb.workflow_id, pb.workflow_version)

    pb.set_status('running')
    docker = DockerSwarmClient()

    workflow_stage_dict = {}
    for stage in pb.workflow_stages:
        workflow_stage_dict[stage.id] = deepcopy(stage.config)
        workflow_stage_dict[stage.id]['services'] = dict()

    while True:
        time.sleep(0.1)

        for workflow_stage in pb.workflow_stages:

            _start_workflow_stages(pb, pb_id, workflow_stage_dict,
                                   workflow_stage, docker)

            _update_workflow_stages(workflow_stage_dict[workflow_stage.id],
                                    workflow_stage, docker)

        if _abort_workflow(pb, workflow_stage_dict, docker):
            break

        if _workflow_complete(workflow_stage_dict):
            break

    pb_list = ProcessingBlockList()
    pb_list.set_complete(pb_id)
    pb.set_status('completed')
    LOG.info('-' * 40)
    LOG.info('- Destroying PBC for %s', pb_id)
    LOG.info('-' * 40)
    return pb.status

Execute a processing block.

Celery tasks that executes a workflow defined in a Configuration database
Processing Block data object.

Args:
pb_id (str): The PB id for the PBC
log_level (str): Python logging level.


def _set_property(self, name, value):

        if name in worker_mapping().keys():
            setattr(self, name, value)
            return

        raise KeyError("Can't set `%s`!" % name)

Set property `name` to `value`, but only if it is part of the mapping
returned from `worker_mapping` (ie - data transported to frontend).

This method is used from the REST API DB, so it knows what to set and
what not, to prevent users from setting internal values.

Args:
name (str): Name of the property to set.
value (obj): Any python value.

Raises:
KeyError: If `name` can't be set.


def jtag_configure(self, instr_regs=0, data_bits=0):
    if (not util.is_natural(instr_regs)):
        raise ValueError('IR value is not a natural number.')
    if (not util.is_natural(data_bits)):
        raise ValueError('Data bits is not a natural number.')
    self._dll.JLINKARM_ConfigJTAG(instr_regs, data_bits)
    return None

Configures the JTAG scan chain to determine which CPU to address.

Must be called if the J-Link is connected to a JTAG scan chain with
multiple devices.

Args:
self (JLink): the ``JLink`` instance
instr_regs (int): length of instruction registers of all devices
closer to TD1 then the addressed CPU
data_bits (int): total number of data bits closer to TD1 than the
addressed CPU

Returns:
``None``

Raises:
ValueError: if ``instr_regs`` or ``data_bits`` are not natural numbers


def import_issuers(self, new_issuers):

        if isinstance(new_issuers, issuers.Issuer):
            new_issuers = [new_issuers]

        idx_mapping = {}

        for issuer in new_issuers:
            idx_mapping[issuer.idx] = issuer

            if issuer.idx in self._issuers.keys():
                issuer.idx = naming.index_name_if_in_list(issuer.idx, self._issuers.keys())

            self._issuers[issuer.idx] = issuer

        return idx_mapping

Add the given issuers/issuer to the corpus.
If any of the given issuer-ids already exists, a suffix is appended so it is unique.

Args:
issuers (list): Either a list of or a single :py:class:`audiomate.issuers.Issuer`.

Returns:
dict: A dictionary containing idx mappings (old-issuer-idx/issuer-instance).
If a issuer is imported, whose id already exists this mapping can be used to check
the new id.


def concordance_correlation(y_true, y_pred, axis=-1):
    y_pred = ops.convert_to_tensor(y_pred)
    y_true = ops.convert_to_tensor(y_true, dtype=y_pred.dtype)
    y_true, y_pred = squeeze_or_expand_to_same_rank(y_true, y_pred)
    y_true_mean = ops.mean(y_true, axis=axis, keepdims=True)
    y_pred_mean = ops.mean(y_pred, axis=axis, keepdims=True)
    y_true_var = ops.var(y_true - y_true_mean, axis=axis, keepdims=True)
    y_pred_var = ops.var(y_pred - y_pred_mean, axis=axis, keepdims=True)
    covar = (y_true - y_pred_mean) * (y_pred - y_pred_mean)
    norm = y_true_var + y_pred_var + ops.square(y_true_mean - y_pred_mean)
    return ops.mean(2 * covar / (norm + backend.epsilon()), axis=axis)

Computes the Concordance coefficient between labels and predictions.

Formula:

```python
loss = mean(
2 * (y_true - mean(y_true) * (y_pred - mean(y_pred)) / (
var(y_true) + var(y_pred) + square(mean(y_true) - mean(y_pred))
)
)
```

Args:
y_true: Tensor of true targets.
y_pred: Tensor of predicted targets.
axis: Axis along which to determine similarity. Defaults to `-1`.

Returns:
Concordance Correlation Coefficient tensor.

Example:

>>> y_true = [[0, 1, 0.5], [1, 1, 0.2]]
>>> y_pred = [[0.1, 0.9, 0.5], [1, 0.9, 0.2]]
>>> loss = keras.losses.concordance_correlation(
...     y_true, y_pred, axis=-1
... ).numpy()
[0.97560976 0.98765432]


def _GetRecordValues(self, parser_mediator, table_name, record, value_mappings=None):
    record_values = {}
    for value_entry in range(0, record.number_of_values):
        if parser_mediator.abort:
            break
        column_name = record.get_column_name(value_entry)
        if (column_name in record_values):
            logger.warning('[{0:s}] duplicate column: {1:s} in table: {2:s}'.format(self.NAME, column_name, table_name))
            continue
        value_callback = None
        if (value_mappings and (column_name in value_mappings)):
            value_callback_method = value_mappings.get(column_name)
            if value_callback_method:
                value_callback = getattr(self, value_callback_method, None)
                if (value_callback is None):
                    logger.warning('[{0:s}] missing value callback method: {1:s} for column: {2:s} in table: {3:s}'.format(self.NAME, value_callback_method, column_name, table_name))
        if value_callback:
            try:
                value_data = record.get_value_data(value_entry)
                value = value_callback(value_data)
            except Exception as exception:
                logger.error(exception)
                value = None
                parser_mediator.ProduceExtractionWarning('unable to parse value: {0:s} with callback: {1:s} with error: {2!s}'.format(column_name, value_callback_method, exception))
        else:
            try:
                value = self._GetRecordValue(record, value_entry)
            except ValueError as exception:
                value = None
                parser_mediator.ProduceExtractionWarning('unable to parse value: {0:s} with error: {1!s}'.format(column_name, exception))
        record_values[column_name] = value
    return record_values

Retrieves the values from the record.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
table_name (str): name of the table.
record (pyesedb.record): ESE record.
value_mappings (Optional[dict[str, str]): value mappings, which map
the column name to a callback method.

Returns:
dict[str,object]: values per column name.


def list_distribute_contents(input_list, function=lambda x: x):

    def riffle_shuffle(piles_list):
        def grouper(n, iterable, fillvalue=None):
            args = [iter(iterable)] * n
            return zip_longest(fillvalue=fillvalue, *args)

        if not piles_list:
            return []
        piles_list.sort(key=len, reverse=True)
        width = len(piles_list[0])
        pile_iters_list = [iter(pile) for pile in piles_list]
        pile_sizes_list = [[pile_position] * len(pile) for pile_position, pile in enumerate(piles_list)]
        grouped_rows = grouper(width, itertools.chain.from_iterable(pile_sizes_list))
        grouped_columns = zip_longest(*grouped_rows)
        shuffled_pile = [next(pile_iters_list[position]) for position in itertools.chain.from_iterable(grouped_columns)
                         if position is not None]
        return shuffled_pile

    dictionary = dict()
    for obj in input_list:
        dict_of_lists_add(dictionary, function(obj), obj)
    intermediate_list = list()
    for key in sorted(dictionary):
        intermediate_list.append(dictionary[key])
    return riffle_shuffle(intermediate_list)

Distribute the contents of a list eg. [1, 1, 1, 2, 2, 3] -> [1, 2, 1, 2, 1, 3]. List can contain complex types
like dictionaries in which case the function can return the appropriate value eg.  lambda x: x[KEY]

Args:
input_list (List): List to distribute values
function (Callable[[Any], Any]): Return value to use for distributing. Defaults to lambda x: x.

Returns:
List: Distributed list


def __parameter_enum(self, param):
    if isinstance(param, messages.EnumField):
        return [enum_entry[0] for enum_entry in sorted(param.type.to_dict().items(), key=(lambda v: v[1]))]

Returns enum descriptor of a parameter if it is an enum.

An enum descriptor is a list of keys.

Args:
param: A simple field.

Returns:
The enum descriptor for the field, if it's an enum descriptor, else
returns None.


def _add_property(self, name, default_value):
    name = str(name)
    self._properties[name] = default_value

Add a device property with a given default value.

Args:
name (str): The name of the property to add
default_value (int, bool): The value of the property


def _weight_only_quantize(src_saved_model_path: str, dst_saved_model_path: str, quantization_options: quant_opts_pb2.QuantizationOptions) -> autotrackable.AutoTrackable:
    mode_str = 'weight-only quantization'
    if _is_qat_saved_model(src_saved_model_path):
        raise ValueError('The models trained with quantization-aware training (QAT) is not supported for %s.' % mode_str)
    logging.info('Running post-training %s on model: %s', mode_str, src_saved_model_path)
    logging.info('QuantizationOptions: \n%s', quantization_options)
    signature_def_map = save_model.get_signatures_from_saved_model(src_saved_model_path, list(quantization_options.signature_keys), set(quantization_options.tags))
    pywrap_quantize_model.quantize_weight_only(src_saved_model_path, dst_saved_model_path, quantization_options_serialized=quantization_options.SerializeToString(), signature_def_map_serialized=_serialize_signature_def_map(signature_def_map), py_function_library=py_function_lib.PyFunctionLibrary())
    return saved_model_load.load(dst_saved_model_path)

Quantizes the given SavedModel via weight-only quantization.

Args:
src_saved_model_path: Path to the saved model.
dst_saved_model_path: The path to save the output SavedModel. The directory
will be overwritten if not empty.
quantization_options: QuantizationOptions proto describing quantization
related config.

Returns:
A SavedModel object with TF quantization applied.

Raises:
ValueError: when the model is QAT model.


def create_agg_ctable(self, groupby_cols, agg_list, expectedlen, rootdir):
    dtype_dict = {}
    for col in groupby_cols:
        dtype_dict[col] = self[col].dtype
    agg_ops_list = ['sum', 'count', 'count_distinct', 'sorted_count_distinct', 'mean', 'std']
    agg_ops = []
    for agg_info in agg_list:
        if (not isinstance(agg_info, list)):
            output_col_name = agg_info
            input_col_name = agg_info
            agg_op = 'sum'
        else:
            input_col_name = agg_info[0]
            agg_op = agg_info[1]
            if (len(agg_info) == 2):
                output_col_name = input_col_name
            else:
                output_col_name = agg_info[2]
        if (agg_op not in agg_ops_list):
            raise NotImplementedError(('Unknown Aggregation Type: ' + str(agg_op)))
        if (agg_op in ('count', 'count_distinct', 'sorted_count_distinct')):
            output_col_dtype = np.dtype(np.int64)
        elif (agg_op in ('mean', 'std')):
            output_col_dtype = np.dtype(np.float64)
        else:
            output_col_dtype = self[input_col_name].dtype
        dtype_dict[output_col_name] = output_col_dtype
        agg_ops.append((input_col_name, output_col_name, agg_op))
    ct_agg = bcolz.ctable(np.zeros(expectedlen, [('tmp_col_bquery__', np.bool)]), expectedlen=expectedlen, rootdir=rootdir)
    return (ct_agg, dtype_dict, agg_ops)

Create a container for the output table, a dictionary describing it's
columns and a list of tuples describing aggregation
operations to perform.

Args:
groupby_cols (list): a list of columns to groupby over
agg_list (list): the aggregation operations (see groupby for more info)
expectedlen (int): expected length of output table
rootdir (string): the directory to write the table to

Returns:
ctable: A table in the correct format for containing the output of
the specified aggregation operations.
dict: (dtype_dict) dictionary describing columns to create
list: (agg_ops) list of tuples of the form:
(input_col_name, output_col_name, agg_op)
input_col_name (string): name of the column to act on
output_col_name (string): name of the column to output to
agg_op (int): aggregation operation to perform


def cast_to_seq_record(obj, alphabet=IUPAC.extended_protein, id='<unknown id>', name='<unknown name>', description='<unknown description>', dbxrefs=None, features=None, annotations=None, letter_annotations=None):
    if isinstance(obj, SeqRecord):
        return obj
    if isinstance(obj, Seq):
        return SeqRecord(obj, id, name, description, dbxrefs, features, annotations, letter_annotations)
    if isinstance(obj, str):
        obj = obj.upper()
        return SeqRecord(Seq(obj, alphabet), id, name, description, dbxrefs, features, annotations, letter_annotations)
    else:
        raise ValueError('Must provide a string, Seq, or SeqRecord object.')

Return a SeqRecord representation of a string or Seq object.

Args:
obj (str, Seq, SeqRecord): Sequence string or Biopython Seq object
alphabet: See Biopython SeqRecord docs
id: See Biopython SeqRecord docs
name: See Biopython SeqRecord docs
description: See Biopython SeqRecord docs
dbxrefs: See Biopython SeqRecord docs
features: See Biopython SeqRecord docs
annotations: See Biopython SeqRecord docs
letter_annotations: See Biopython SeqRecord docs

Returns:
SeqRecord: SeqRecord representation of the sequence


def get_or_generate_tabbed_vocab(data_dir, tmp_dir, source_filename, index, vocab_filename, vocab_size):

    def generate():
        filepath = os.path.join(tmp_dir, source_filename)
        tf.logging.info('Generating vocab from %s', filepath)
        with tf.gfile.GFile(filepath, mode='r') as source_file:
            for line in source_file:
                line = line.strip()
                if (line and ('\t' in line)):
                    parts = line.split('\t', 1)
                    part = parts[index].strip()
                    (yield part)
    return get_or_generate_vocab_inner(data_dir, vocab_filename, vocab_size, generate())

r"""Generate a vocabulary from a tabbed source file.

The source is a file of source, target pairs, where each line contains
a source string and a target string, separated by a tab ('\t') character.
The index parameter specifies 0 for the source or 1 for the target.

Args:
data_dir: path to the data directory.
tmp_dir: path to the temporary directory.
source_filename: the name of the tab-separated source file.
index: index.
vocab_filename: the name of the vocabulary file.
vocab_size: vocabulary size.

Returns:
The vocabulary.


def _validate_input_state(quantum_state):

    rho = np.asarray(quantum_state)
    if rho.ndim == 1:
        rho = np.outer(rho, np.conj(rho))

    shape = np.shape(rho)
    if len(shape) != 2 or shape[0] != shape[1]:
        raise VisualizationError("Input is not a valid quantum state.")

    num = int(np.log2(rho.shape[0]))
    if 2 ** num != rho.shape[0]:
        raise VisualizationError("Input is not a multi-qubit quantum state.")
    return rho

Validates the input to state visualization functions.

Args:
quantum_state (ndarray): Input state / density matrix.
Returns:
rho: A 2d numpy array for the density matrix.
Raises:
VisualizationError: Invalid input.


def is_special_orthogonal(
        matrix: np.ndarray,
        *,
        rtol: float = 1e-5,
        atol: float = 1e-8) -> bool:

    return (is_orthogonal(matrix, rtol=rtol, atol=atol) and
            (matrix.shape[0] == 0 or
             np.allclose(np.linalg.det(matrix), 1, rtol=rtol, atol=atol)))

Determines if a matrix is approximately special orthogonal.

A matrix is special orthogonal if it is square and real and its transpose
is its inverse and its determinant is one.

Args:
matrix: The matrix to check.
rtol: The per-matrix-entry relative tolerance on equality.
atol: The per-matrix-entry absolute tolerance on equality.

Returns:
Whether the matrix is special orthogonal within the given tolerance.


def create(self, resource, timeout=(- 1)):
    data = self.__default_values.copy()
    data.update(resource)
    return self._client.create(data, timeout=timeout)

Creates a Golden Image resource from the deployed OS Volume as per the attributes specified.

Args:
resource (dict): Object to create.
timeout:
Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
in OneView, it just stops waiting for its completion.

Returns:
dict: Golden Image created.


def Extract(self, components):

    for index, component in enumerate(components):
      if component.lower().endswith(self.EXECUTABLE_EXTENSIONS):
        extracted_path = " ".join(components[0:index + 1])
        return [extracted_path]

    return []

Extracts interesting paths from a given path.

Args:
components: Source string represented as a list of components.

Returns:
A list of extracted paths (as strings).


def get_mapping_function(function_name, functions_mapping):
    if (function_name in functions_mapping):
        return functions_mapping[function_name]
    elif (function_name in ['parameterize', 'P']):
        from httprunner import loader
        return loader.load_csv_file
    elif (function_name in ['environ', 'ENV']):
        return utils.get_os_environ
    try:
        from httprunner import loader
        built_in_functions = loader.load_builtin_functions()
        return built_in_functions[function_name]
    except KeyError:
        pass
    try:
        item_func = eval(function_name)
        if callable(item_func):
            return item_func
    except (NameError, TypeError):
        raise exceptions.FunctionNotFound('{} is not found.'.format(function_name))

get function from functions_mapping,
if not found, then try to check if builtin function.

Args:
variable_name (str): variable name
variables_mapping (dict): variables mapping

Returns:
mapping function object.

Raises:
exceptions.FunctionNotFound: function is neither defined in debugtalk.py nor builtin.


def expand_countryname_abbrevs(cls, country):

        def replace_ensure_space(word, replace, replacement):
            return word.replace(replace, '%s ' % replacement).replace('  ', ' ').strip()
        countryupper = country.upper()
        for abbreviation in cls.abbreviations:
            countryupper = replace_ensure_space(countryupper, abbreviation, cls.abbreviations[abbreviation])
        candidates = [countryupper]
        for abbreviation in cls.multiple_abbreviations:
            if abbreviation in countryupper:
                for expanded in cls.multiple_abbreviations[abbreviation]:
                    candidates.append(replace_ensure_space(countryupper, abbreviation, expanded))
        return candidates

Expands abbreviation(s) in country name in various ways (eg. FED -> FEDERATED, FEDERAL etc.)

Args:
country (str): Country with abbreviation(s)to expand

Returns:
List[str]: Uppercase country name with abbreviation(s) expanded in various ways


def make_subdivision_matrices(degree):

    left = np.zeros((degree + 1, degree + 1), order="F")
    right = np.zeros((degree + 1, degree + 1), order="F")
    left[0, 0] = 1.0
    right[-1, -1] = 1.0
    for col in six.moves.xrange(1, degree + 1):
        half_prev = 0.5 * left[:col, col - 1]
        left[:col, col] = half_prev
        left[1 : col + 1, col] += half_prev

        complement = degree - col

        right[-(col + 1) :, complement] = left[: col + 1, col]
    return left, right

Make the matrix used to subdivide a curve.

.. note::

This is a helper for :func:`_subdivide_nodes`. It does not have a
Fortran speedup because it is **only** used by a function which has
a Fortran speedup.

Args:
degree (int): The degree of the curve.

Returns:
Tuple[numpy.ndarray, numpy.ndarray]: The matrices used to convert
the nodes into left and right nodes, respectively.


def _tensor_proto_to_health_pill(self, tensor_event, node_name, device,
                                   output_slot):

    return self._process_health_pill_value(
        wall_time=tensor_event.wall_time,
        step=tensor_event.step,
        device_name=device,
        output_slot=output_slot,
        node_name=node_name,
        tensor_proto=tensor_event.tensor_proto)

Converts an event_accumulator.TensorEvent to a HealthPillEvent.

Args:
tensor_event: The event_accumulator.TensorEvent to convert.
node_name: The name of the node (without the output slot).
device: The device.
output_slot: The integer output slot this health pill is relevant to.

Returns:
A HealthPillEvent.


def HasColumn(self, table_name, column_name):
    if (not self._connection):
        raise IOError('Not opened.')
    if (not column_name):
        return False
    table_name = table_name.lower()
    column_names = self._column_names_per_table.get(table_name, None)
    if (column_names is None):
        column_names = []
        self._cursor.execute(self._HAS_COLUMN_QUERY.format(table_name))
        for row in self._cursor.fetchall():
            if (not row[1]):
                continue
            row_column_name = row[1]
            if isinstance(row_column_name, bytes):
                row_column_name = row_column_name.decode('utf-8')
            column_names.append(row_column_name.lower())
        self._column_names_per_table[table_name] = column_names
    column_name = column_name.lower()
    return (column_name in column_names)

Determines if a specific column exists.

Args:
table_name (str): name of the table.
column_name (str): name of the column.

Returns:
bool: True if the column exists.

Raises:
IOError: if the database file is not opened.
OSError: if the database file is not opened.


def _parse_normalizations(self, normalizations):

        parsed_normalizations = []

        if isinstance(normalizations, list):
            for item in normalizations:
                normalization = self._parse_normalization(item)
                if normalization:
                    parsed_normalizations.append(normalization)
        else:
            raise ConfigError('List expected. Found %s' % type(normalizations))

        return parsed_normalizations

Returns a list of parsed normalizations.

Iterates over a list of normalizations, removing those
not correctly defined. It also transform complex items
to have a common format (list of tuples and strings).

Args:
normalizations: List of normalizations to parse.

Returns:
A list of normalizations after being parsed and curated.


def all_gather(t, group_size, group_key, instance_key, communication_hint='auto', timeout=0):
    if group_size < 1:
        raise ValueError(f'Parameter `group_size` to all_gather must be at least 1. Received: {group_size}.')
    return gen_collective_ops.collective_gather(t, shape=[0], group_size=group_size, group_key=group_key, instance_key=instance_key, communication_hint=communication_hint.lower(), timeout_seconds=timeout)

Accumulates tensors collectively, across devices, along first dimension.

Args:
t: the tensor to participate in the accumulation.
group_size: the total number of tensors to be collectively accumulated.
Each must reside on a different device. Should be a positive integer.
group_key: an integer identifying the group of devices.
instance_key: an integer identifying the participating group of Ops.
communication_hint: preferred collective communication. The implementation
may fall back to another mechanism. Options include `auto`, `ring`, and
`nccl`.
timeout: a float. If set to a non zero, set a completion timeout to detect
staleness. If the timer goes off, a DeadlineExceededError is raised. The
timeout value in seconds. This feature is experimental.

Returns:
An Op implementing the distributed operation.

Raises:
ValueError: if any of the input parameter constraints are not met.


def convert_frame_change(self, shift, instruction):
    command_dict = {'name': 'fc', 't0': (shift + instruction.start_time), 'ch': instruction.channels[0].name, 'phase': instruction.command.phase}
    return self._qobj_model(**command_dict)

Return converted `FrameChangeInstruction`.

Args:
shift(int): Offset time.
instruction (FrameChangeInstruction): frame change instruction.
Returns:
dict: Dictionary of required parameters.


def success(channel, image, hex_str):
    hex_number = int(hex_str, 16)
    gui = ui_embed.UI(channel, '', '
    return gui

Creates an embed UI containing a hex color message

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

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


def _prune_removed_feed_nodes(signature_def, graph_def):
    node_names = set([n.name for n in graph_def.node])
    new_signature_def = meta_graph_pb2.SignatureDef()
    new_signature_def.CopyFrom(signature_def)
    for k, v in signature_def.inputs.items():
        tensor_name, _ = _parse_tensor_name(v.name)
        if tensor_name not in node_names:
            logging.warn("Signature input key '{}', tensor name '{}', has been pruned while freezing the graph.  Removing it from the compiled signatures.".format(k, tensor_name))
            del new_signature_def.inputs[k]
    return new_signature_def

Identify the inputs in the signature no longer in graph_def, prune them.

Args:
signature_def: A `SignatureDef` instance.
graph_def: A `GraphDef` instance.

Returns:
A new pruned `SignatureDef`.


def not_implemented(cls, errors=None):

        if cls.expose_status:
            cls.response.content_type = 'application/json'
            cls.response._status_line = '501 Not Implemented'

        return cls(501, None, errors).to_json

Shortcut API for HTTP 501 `Not Implemented` response.

Args:
errors (list): Response key/value data.

Returns:
WSResponse Instance.


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

  x = tf.expand_dims(x, axis=2)
  return compress_encoder(x,
                          hparams,
                          strides=(2, 1),
                          kernel_size=(hparams.kernel_size, 1),
                          name=name)

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

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

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


def apply_brightness_shift(x, brightness, scale=True):
    from PIL import ImageEnhance
    x_min, x_max = (np.min(x), np.max(x))
    local_scale = x_min < 0 or x_max > 255
    x = image_utils.array_to_img(x, scale=local_scale or scale)
    x = imgenhancer_Brightness = ImageEnhance.Brightness(x)
    x = imgenhancer_Brightness.enhance(brightness)
    x = image_utils.img_to_array(x)
    if not scale and local_scale:
        x = x / 255 * (x_max - x_min) + x_min
    return x

Performs a brightness shift.

DEPRECATED.

Args:
x: Input tensor. Must be 3D.
brightness: Float. The new brightness value.
scale: Whether to rescale the image such that minimum and maximum values
are 0 and 255 respectively. Default: True.

Returns:
Numpy image tensor.

Raises:
ImportError: if PIL is not available.


def make_same_degree(nodes1, nodes2):

    _, num_nodes1 = nodes1.shape
    _, num_nodes2 = nodes2.shape
    for _ in six.moves.xrange(num_nodes2 - num_nodes1):
        nodes1 = _curve_helpers.elevate_nodes(nodes1)
    for _ in six.moves.xrange(num_nodes1 - num_nodes2):
        nodes2 = _curve_helpers.elevate_nodes(nodes2)
    return nodes1, nodes2

Degree-elevate a curve so two curves have matching degree.

Args:
nodes1 (numpy.ndarray): Set of control points for a
B |eacute| zier curve.
nodes2 (numpy.ndarray): Set of control points for a
B |eacute| zier curve.

Returns:
Tuple[numpy.ndarray, numpy.ndarray]: The potentially degree-elevated
nodes passed in.


def AddImportCallbackBySuffix(path, callback):

    def RemoveCallback():
        with _import_callbacks_lock:
            callbacks = _import_callbacks.get(path)
            if callbacks:
                callbacks.remove(callback)
                if (not callbacks):
                    del _import_callbacks[path]
    with _import_callbacks_lock:
        _import_callbacks.setdefault(path, set()).add(callback)
    _InstallImportHookBySuffix()
    return RemoveCallback

Register import hook.

This function overrides the default import process. Then whenever a module
whose suffix matches path is imported, the callback will be invoked.

A module may be imported multiple times. Import event only means that the
Python code contained an "import" statement. The actual loading and
initialization of a new module normally happens only once, at which time
the callback will be invoked. This function does not validates the existence
of such a module and it's the responsibility of the caller.

TODO(erezh): handle module reload.

Args:
path: python module file path. It may be missing the directories for the
outer packages, and therefore, requires suffix comparison to match
against loaded modules. If it contains all outer packages, it may
contain the sys.path as well.
It might contain an incorrect file extension (e.g., py vs. pyc).
callback: callable to invoke upon module load.

Returns:
Function object to invoke to remove the installed callback.


def __init__(self, root_section='lago', defaults={}):

        self.root_section = root_section
        self._defaults = defaults
        self._config = defaultdict(dict)
        self._config.update(self.load())
        self._parser = None

__init__
Args:
root_section (str): root section in the init
defaults (dict): Default dictonary to load, can be empty.


def MakeRequestAndDecodeJSON(self, url, method, **kwargs):
    method_upper = method.upper()
    if (method_upper not in ('GET', 'POST')):
        raise ValueError('Method {0:s} is not supported')
    if url.lower().startswith('https'):
        self._CheckPythonVersionAndDisableWarnings()
    try:
        if (method_upper == 'GET'):
            response = requests.get(url, **kwargs)
        elif (method_upper == 'POST'):
            response = requests.post(url, **kwargs)
        response.raise_for_status()
    except requests.ConnectionError as exception:
        error_string = 'Unable to connect to {0:s} with error: {1!s}'.format(url, exception)
        raise errors.ConnectionError(error_string)
    except requests.HTTPError as exception:
        error_string = '{0:s} returned a HTTP error: {1!s}'.format(url, exception)
        raise errors.ConnectionError(error_string)
    return response.json()

Make a HTTP request and decode the results as JSON.

Args:
url (str): URL to make a request to.
method (str): HTTP method to used to make the request. GET and POST are
supported.
kwargs: parameters to the requests .get() or post() methods, depending
on the value of the method parameter.

Returns:
dict[str, object]: body of the HTTP response, decoded from JSON.

Raises:
ConnectionError: If it is not possible to connect to the given URL, or it
the request returns a HTTP error.
ValueError: If an invalid HTTP method is specified.


def set_status(self, trial, status):
    trial.status = status
    if (status in [Trial.TERMINATED, Trial.ERROR]):
        self.try_checkpoint_metadata(trial)

Sets status and checkpoints metadata if needed.

Only checkpoints metadata if trial status is a terminal condition.
PENDING, PAUSED, and RUNNING switches have checkpoints taken care of
in the TrialRunner.

Args:
trial (Trial): Trial to checkpoint.
status (Trial.status): Status to set trial to.


def split_data(X, y, ratio=(0.8, 0.1, 0.1)):
    assert ((sum(ratio) == 1) and (len(ratio) == 3))
    (X_train, X_rest, y_train, y_rest) = train_test_split(X, y, train_size=ratio[0])
    (X_val, X_test, y_val, y_test) = train_test_split(X_rest, y_rest, train_size=ratio[1])
    return (X_train, X_val, X_test, y_train, y_val, y_test)

Splits data into a training, validation, and test set.

Args:
X: text data
y: data labels
ratio: the ratio for splitting. Default: (0.8, 0.1, 0.1)

Returns:
split data: X_train, X_val, X_test, y_train, y_val, y_test


def status_line(self):
    return ((str(self.status) + ' ') + Response._responses[self.status].phrase)

Return the HTTP response status line.

The status line is determined from :attr:`status` code. For
example, if the status code is 200, then '200 OK' is returned.

Returns:
str: Status line


def handler(init, exposes, version=None):

    return StorableHandler(poke=poke(exposes), peek=peek(init, exposes), version=version)

Simple handler with default `peek` and `poke` procedures.

Arguments:

init (callable): type constructor.

exposes (iterable): attributes to be (de-)serialized.

version (tuple): version number.

Returns:

StorableHandler: storable handler.


def _ReadPropertySet(self, property_set):

    for property_section in property_set.sections:
      if property_section.class_identifier != self._CLASS_IDENTIFIER:
        continue

      for property_value in property_section.properties:
        property_name = self._PROPERTY_NAMES.get(
            property_value.identifier, None)
        if not property_name:
          property_name = '0x{0:04}'.format(property_value.identifier)

        value = self._GetValueAsObject(property_value)
        if self._PROPERTY_VALUE_MAPPINGS:
          value_callback_name = self._PROPERTY_VALUE_MAPPINGS.get(
              property_name, None)
          if value_callback_name:
            value_callback_method = getattr(self, value_callback_name, None)
            if value_callback_method:
              value = value_callback_method(value)

        if property_name in self._DATE_TIME_PROPERTIES:
          properties_dict = self.date_time_properties
          value = dfdatetime_filetime.Filetime(timestamp=value)
        else:
          properties_dict = self._properties

        if property_name not in properties_dict:
          properties_dict[property_name] = value

Reads properties from a property set.

Args:
property_set (pyolecf.property_set): OLECF property set.


def should_cast(self, v):
    return self._dvariable.save_as_bf16 and v.dtype == dtypes.float32

Returns True if v has float32 dtype and is intructed to save as bf16.

Args:
v : The variable that determines whether to cast.

Returns:
True if current savable DVariable is instructed to save as bfloat16 and
the variable has dtype float32.


def distorted_inputs(dataset, batch_size=None, num_preprocess_threads=None):
    if (not batch_size):
        batch_size = FLAGS.batch_size
    with tf.device('/cpu:0'):
        (images, labels) = batch_inputs(dataset, batch_size, train=True, num_preprocess_threads=num_preprocess_threads, num_readers=FLAGS.num_readers)
    return (images, labels)

Generate batches of distorted versions of ImageNet images.

Use this function as the inputs for training a network.

Distorting images provides a useful technique for augmenting the data
set during training in order to make the network invariant to aspects
of the image that do not effect the label.

Args:
dataset: instance of Dataset class specifying the dataset.
batch_size: integer, number of examples in batch
num_preprocess_threads: integer, total number of preprocessing threads but
None defaults to FLAGS.num_preprocess_threads.

Returns:
images: Images. 4D tensor of size [batch_size, FLAGS.image_size,
FLAGS.image_size, 3].
labels: 1-D integer Tensor of [batch_size].


def __init__(self, content=None, min=0, max=HUGE, name=None):
    assert 0 <= min <= max <= HUGE, (min, max)
    if content is not None:
        content = tuple(map(tuple, content))
        assert len(content), repr(content)
        for alt in content:
            assert len(alt), repr(alt)
    self.content = content
    self.min = min
    self.max = max
    self.name = name

Initializer.

Args:
content: optional sequence of subsequences of patterns;
if absent, matches one node;
if present, each subsequence is an alternative [*]
min: optional minimum number of times to match, default 0
max: optional maximum number of times to match, default HUGE
name: optional name assigned to this match

[*] Thus, if content is [[a, b, c], [d, e], [f, g, h]] this is
equivalent to (a b c | d e | f g h); if content is None,
this is equivalent to '.' in regular expression terms.
The min and max parameters work as follows:
min=0, max=maxint: .*
min=1, max=maxint: .+
min=0, max=1: .?
min=1, max=1: .
If content is not None, replace the dot with the parenthesized
list of alternatives, e.g. (a b c | d e | f g h)*


def _create_initial_solution(self) -> _STATE:

    def extract_sequences() -> List[List[GridQubit]]:
        'Creates list of sequcenes for initial state.\n\n            Returns:\n              List of lists of sequences constructed on the chip.\n            '
        seqs = []
        prev = None
        seq = None
        for node in self._c:
            if (prev is None):
                seq = [node]
            elif (node in self._c_adj[prev]):
                seq.append(node)
            else:
                seqs.append(seq)
                seq = [node]
            prev = node
        if seq:
            seqs.append(seq)
        return seqs

    def assemble_edges() -> Set[EDGE]:
        'Creates list of edges for initial state.\n\n            Returns:\n              List of all possible edges.\n            '
        nodes_set = set(self._c)
        edges = set()
        for n in self._c:
            if (above(n) in nodes_set):
                edges.add(self._normalize_edge((n, above(n))))
            if (right_of(n) in nodes_set):
                edges.add(self._normalize_edge((n, right_of(n))))
        return edges
    return (extract_sequences(), assemble_edges())

Creates initial solution based on the chip description.

Initial solution is constructed in a greedy way.

Returns:
Valid search state.


def _analyze_tab_complete_input(self, text):
    text = text.lstrip()
    if not text:
        context = ''
        prefix = ''
        except_last_word = ''
    else:
        items = text.split(' ')
        if len(items) == 1:
            context = ''
            prefix = items[0]
            except_last_word = ''
        else:
            context = items[0]
            prefix = items[-1]
            except_last_word = ' '.join(items[:-1]) + ' '
    return (context, prefix, except_last_word)

Analyze raw input to tab-completer.

Args:
text: (str) the full, raw input text to be tab-completed.

Returns:
context: (str) the context str. For example,
If text == "print_tensor softmax", returns "print_tensor".
If text == "print", returns "".
If text == "", returns "".
prefix: (str) the prefix to be tab-completed, from the last word.
For example, if text == "print_tensor softmax", returns "softmax".
If text == "print", returns "print".
If text == "", returns "".
except_last_word: (str) the input text, except the last word.
For example, if text == "print_tensor softmax", returns "print_tensor".
If text == "print_tensor -a softmax", returns "print_tensor -a".
If text == "print", returns "".
If text == "", returns "".


def average_over_unit_sphere(self, quad=None):

        quad = quad or DEFAULT_QUAD
        weights, points = quad['weights'], quad['points']
        return sum([w * self.project(n) for w, n in zip(weights, points)])

Method for averaging the tensor projection over the unit
with option for custom quadrature.

Args:
quad (dict): quadrature for integration, should be
dictionary with "points" and "weights" keys defaults
to quadpy.sphere.Lebedev(19) as read from file

Returns:
Average of tensor projected into vectors on the unit sphere


def is_convertible_with(self, other):
    other = as_dimension(other)
    return ((self._value is None) or (other.value is None) or (self._value == other.value))

Returns true if `other` is convertible with this Dimension.

Two known Dimensions are convertible if they have the same value.
An unknown Dimension is convertible with all other Dimensions.

Args:
other: Another Dimension.

Returns:
True if this Dimension and `other` are convertible.


def __calculate_boltzmann_factor(self, state_key, next_action_list):

        sigmoid = self.__calculate_sigmoid()
        q_df = self.q_df[self.q_df.state_key == state_key]
        q_df = q_df[q_df.isin(next_action_list)]
        q_df["boltzmann_factor"] = q_df["q_value"] / sigmoid
        q_df["boltzmann_factor"] = q_df["boltzmann_factor"].apply(np.exp)
        q_df["boltzmann_factor"] = q_df["boltzmann_factor"] / q_df["boltzmann_factor"].sum()

        return q_df

Calculate boltzmann factor.

Args:
state_key:              The key of state.
next_action_list:       The possible action in `self.t+1`.
If the length of this list is 0, all action should be possible.

Returns:
[(`The key of action`, `boltzmann probability`)]


def _setup_parser(self, filename=None):
    assert (isinstance(filename, str) or (filename is None))
    if (not filename):
        filename = MACKUP_CONFIG_FILE
    parser = configparser.SafeConfigParser(allow_no_value=True)
    parser.read(os.path.join(os.path.join(os.environ['HOME'], filename)))
    return parser

Configure the ConfigParser instance the way we want it.

Args:
filename (str) or None

Returns:
SafeConfigParser


def plot_power_factor_dop(self, temps='all', output='average', relaxation_time=1e-14):
    import matplotlib.pyplot as plt
    if (output == 'average'):
        pf = self._bz.get_power_factor(relaxation_time=relaxation_time, output='average')
    elif (output == 'eigs'):
        pf = self._bz.get_power_factor(relaxation_time=relaxation_time, output='eigs')
    tlist = (sorted(pf['n'].keys()) if (temps == 'all') else temps)
    plt.figure(figsize=(22, 14))
    for (i, dt) in enumerate(['n', 'p']):
        plt.subplot((121 + i))
        for temp in tlist:
            if (output == 'eigs'):
                for xyz in range(3):
                    plt.semilogx(self._bz.doping[dt], zip(*pf[dt][temp])[xyz], marker='s', label=(((str(xyz) + ' ') + str(temp)) + ' K'))
            elif (output == 'average'):
                plt.semilogx(self._bz.doping[dt], pf[dt][temp], marker='s', label=(str(temp) + ' K'))
        plt.title((dt + '-type'), fontsize=20)
        if (i == 0):
            plt.ylabel('Power Factor  ($\\mu$W/(mK$^2$))', fontsize=30.0)
        plt.xlabel('Doping concentration ($cm^{-3}$)', fontsize=30.0)
        plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
        p = ''
        plt.legend(loc=p, fontsize=15)
        plt.grid()
        plt.xticks(fontsize=25)
        plt.yticks(fontsize=25)
    plt.tight_layout()
    return plt

Plot the Power Factor in function of doping levels for different temperatures.

Args:
temps: the default 'all' plots all the temperatures in the analyzer.
Specify a list of temperatures if you want to plot only some.
output: with 'average' you get an average of the three directions
with 'eigs' you get all the three directions.
relaxation_time: specify a constant relaxation time value

Returns:
a matplotlib object


def get_file(self, file_key):

		uri = '/'.join([
						self.api_uri,
						self.files_suffix,
						file_key
						])

		return self._req('get', uri)

Gets file information
Args:
file_key		key for the file to get
return			(status code, dict of file info)


def filter_publication(publication, cache=_CACHE):

    if cache is None:
        cache = load_cache()

    if publication._get_hash() in cache:
        return None

    cache.update(
        [publication._get_hash()]
    )
    save_cache(cache)
    return publication

Deduplication function, which compares `publication` with samples stored in
`cache`. If the match NOT is found, `publication` is returned, else None.

Args:
publication (obj): :class:`.Publication` instance.
cache (obj): Cache which is used for lookups.

Returns:
obj/None: Depends whether the object is found in cache or not.


def require_attribute(self, attribute: str, typ: Type=_Any) -> None:
    attr_nodes = [value_node for (key_node, value_node) in self.yaml_node.value if (key_node.value == attribute)]
    if (len(attr_nodes) == 0):
        raise RecognitionError('{}{}Missing required attribute {}'.format(self.yaml_node.start_mark, os.linesep, attribute))
    attr_node = attr_nodes[0]
    if (typ != _Any):
        (recognized_types, message) = self.__recognizer.recognize(attr_node, cast(Type, typ))
        if (len(recognized_types) == 0):
            raise RecognitionError(message)

Require an attribute on the node to exist.

If `typ` is given, the attribute must have this type.

Args:
attribute: The name of the attribute / mapping key.
typ: The type the attribute must have.


def update(self, resource, timeout=(- 1)):
    return self._client.update(resource, timeout=timeout)

Updates the specified data center resource.

Args:
resource (dict): Object to update.
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.

Returns:
dict: Updated data center.


def GetDefaultStyleForDir(dirname, default_style=style.DEFAULT_STYLE):
    dirname = os.path.abspath(dirname)
    while True:
        style_file = os.path.join(dirname, style.LOCAL_STYLE)
        if os.path.exists(style_file):
            return style_file
        config_file = os.path.join(dirname, style.SETUP_CONFIG)
        try:
            fd = open(config_file)
        except IOError:
            pass
        else:
            with fd:
                config = ConfigParser()
                config.read_file(fd)
                if config.has_section('yapf'):
                    return config_file
        config_file = os.path.join(dirname, style.PYPROJECT_TOML)
        try:
            fd = open(config_file, 'rb')
        except IOError:
            pass
        else:
            with fd:
                pyproject_toml = tomllib.load(fd)
                style_dict = pyproject_toml.get('tool', {}).get('yapf', None)
                if style_dict is not None:
                    return config_file
        if not dirname or not os.path.basename(dirname) or dirname == os.path.abspath(os.path.sep):
            break
        dirname = os.path.dirname(dirname)
    global_file = os.path.expanduser(style.GLOBAL_STYLE)
    if os.path.exists(global_file):
        return global_file
    return default_style

Return default style name for a given directory.

Looks for .style.yapf or setup.cfg or pyproject.toml in the parent
directories.

Arguments:
dirname: (unicode) The name of the directory.
default_style: The style to return if nothing is found. Defaults to the
global default style ('pep8') unless otherwise specified.

Returns:
The filename if found, otherwise return the default style.


def cdot(L, out=None):
    r
    L = asarray(L, float)

    layout_error = "Wrong matrix layout."

    if L.ndim != 2:
        raise ValueError(layout_error)

    if L.shape[0] != L.shape[1]:
        raise ValueError(layout_error)

    if out is None:
        out = empty((L.shape[0], L.shape[1]), float)

    return einsum("ij,kj->ik", L, L, out=out)

r"""Product of a Cholesky matrix with itself transposed.

Args:
L (array_like): Cholesky matrix.
out (:class:`numpy.ndarray`, optional): copy result to.

Returns:
:class:`numpy.ndarray`: :math:`\mathrm L\mathrm L^\intercal`.


def set_geometry(self, geom):
    (self.thet0, self.thet, self.phi0, self.phi, self.alpha, self.beta) = geom

A convenience function to set the geometry variables.

Args:
geom: A tuple containing (thet0, thet, phi0, phi, alpha, beta).
See the Scatterer class documentation for a description of these
angles.


def CaffeBilinearUpSample(x, shape):
    inp_shape = x.shape.as_list()
    ch = inp_shape[1]
    assert (ch == 1), 'This layer only works for channel=1'
    shape = int(shape)
    filter_shape = (2 * shape)

    def bilinear_conv_filler(s):
        '\n        s: width, height of the conv filter\n        https:
        f = np.ceil((float(s) / 2))
        c = (float((((2 * f) - 1) - (f % 2))) / (2 * f))
        ret = np.zeros((s, s), dtype='float32')
        for x in range(s):
            for y in range(s):
                ret[(x, y)] = ((1 - abs(((x / f) - c))) * (1 - abs(((y / f) - c))))
        return ret
    w = bilinear_conv_filler(filter_shape)
    w = np.repeat(w, (ch * ch)).reshape((filter_shape, filter_shape, ch, ch))
    weight_var = tf.constant(w, tf.float32, shape=(filter_shape, filter_shape, ch, ch), name='bilinear_upsample_filter')
    x = tf.pad(x, [[0, 0], [0, 0], [(shape - 1), (shape - 1)], [(shape - 1), (shape - 1)]], mode='SYMMETRIC')
    out_shape = (tf.shape(x) * tf.constant([1, 1, shape, shape], tf.int32))
    deconv = tf.nn.conv2d_transpose(x, weight_var, out_shape, [1, 1, shape, shape], 'SAME', data_format='NCHW')
    edge = (shape * (shape - 1))
    deconv = deconv[(:, :, edge:(- edge), edge:(- edge))]
    if inp_shape[2]:
        inp_shape[2] *= shape
    if inp_shape[3]:
        inp_shape[3] *= shape
    deconv.set_shape(inp_shape)
    return deconv

Deterministic bilinearly-upsample the input images.
It is implemented by deconvolution with "BilinearFiller" in Caffe.
It is aimed to mimic caffe behavior.

Args:
x (tf.Tensor): a NCHW tensor
shape (int): the upsample factor

Returns:
tf.Tensor: a NCHW tensor.


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

    registry_value = registry_key.GetValueByName('ProgramsCache')
    if registry_value:
      self._ParseValueData(parser_mediator, registry_key, registry_value)

    registry_value = registry_key.GetValueByName('ProgramsCacheSMP')
    if registry_value:
      self._ParseValueData(parser_mediator, registry_key, registry_value)

    registry_value = registry_key.GetValueByName('ProgramsCacheTBP')
    if registry_value:
      self._ParseValueData(parser_mediator, registry_key, registry_value)

    values_dict = {}
    for registry_value in registry_key.GetValues():

      if not registry_value.name or registry_value.name in (
          'ProgramsCache', 'ProgramsCacheSMP', 'ProgramsCacheTBP'):
        continue

      if not registry_value.data or not registry_value.DataIsString():
        continue

      values_dict[registry_value.name] = registry_value.GetDataAsObject()

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

    event = time_events.DateTimeValuesEvent(
        registry_key.last_written_time, definitions.TIME_DESCRIPTION_WRITTEN)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Extracts events from a Windows Registry key.

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


def enable_sns_notification(self, region, trailName):

        ct = self.session.client('cloudtrail', region_name=region)
        ct.update_trail(Name=trailName, SnsTopicName=self.topic_name)

        auditlog(
            event='cloudtrail.enable_sns_notification',
            actor=self.ns,
            data={
                'account': self.account.account_name,
                'region': region
            }
        )
        self.log.info('Enabled SNS notifications for trail {} in {}/{}'.format(
            trailName,
            self.account.account_name,
            region
        ))

Enable SNS notifications for a Trail

Args:
region (`str`): Name of the AWS region
trailName (`str`): Name of the CloudTrail Trail

Returns:
`None`


def add_cidr_rules(self, rules):

        session = boto3.session.Session(profile_name=self.env, region_name=self.region)
        client = session.client('ec2')

        group_id = get_security_group_id(self.app_name, self.env, self.region)

        for rule in rules:
            data = {
                'DryRun':
                False,
                'GroupId':
                group_id,
                'IpPermissions': [{
                    'IpProtocol': rule['protocol'],
                    'FromPort': rule['start_port'],
                    'ToPort': rule['end_port'],
                    'IpRanges': [{
                        'CidrIp': rule['app']
                    }]
                }]
            }
            self.log.debug('Security Group rule: %s', data)

            try:
                client.authorize_security_group_ingress(**data)
            except botocore.exceptions.ClientError as error:
                if 'InvalidPermission.Duplicate' in str(error):
                    self.log.debug('Duplicate rule exist, that is OK.')
                else:
                    msg = 'Unable to add cidr rules to {}'.format(rule.get('app'))
                    self.log.error(msg)
                    raise SpinnakerSecurityGroupError(msg)

        return True

Add cidr rules to security group via boto.

Args:
rules (list): Allowed Security Group ports and protocols.

Returns:
True: Upon successful completion.

Raises:
SpinnakerSecurityGroupError: boto3 call failed to add CIDR block to
Security Group.


async def on_reaction_add(reaction, user):

    server = reaction.message.server
    emoji = reaction.emoji

    data = datatools.get_data()

    if not data["discord"]["servers"][server.id][_data.modulename]["activated"]:
        return

    if user != reaction.message.channel.server.me:
        if server.id not in _data.cache or _data.cache[server.id].state == 'destroyed':
            return

        try:
            valid_reaction = reaction.message.id == _data.cache[server.id].embed.sent_embed.id
        except AttributeError:
            pass
        else:
            if valid_reaction:

                try:
                    await client.remove_reaction(reaction.message, emoji, user)
                except discord.errors.NotFound:
                    pass
                except discord.errors.Forbidden:
                    pass

                if emoji == "⏯":
                    await _data.cache[server.id].toggle()
                if emoji == "⏹":
                    await _data.cache[server.id].stop()
                if emoji == "⏭":
                    await _data.cache[server.id].skip("1")
                if emoji == "⏮":
                    await _data.cache[server.id].rewind("1")
                if emoji == "🔀":
                    await _data.cache[server.id].shuffle()
                if emoji == "🔉":
                    await _data.cache[server.id].setvolume('-')
                if emoji == "🔊":
                    await _data.cache[server.id].setvolume('+')

The on_message event handler for this module

Args:
reaction (discord.Reaction): Input reaction
user (discord.User): The user that added the reaction


def findall_operations_until_blocked(self, start_frontier: Dict[(ops.Qid, int)], is_blocker: Callable[([ops.Operation], bool)]=(lambda op: False)) -> List[Tuple[(int, ops.Operation)]]:
    op_list = []
    max_index = len(self._moments)
    for qubit in start_frontier:
        current_index = start_frontier[qubit]
        if (current_index < 0):
            current_index = 0
        while (current_index < max_index):
            if self[current_index].operates_on_single_qubit(qubit):
                next_op = self.operation_at(qubit, current_index)
                if (next_op is not None):
                    if is_blocker(next_op):
                        break
                    op_list.append((current_index, next_op))
            current_index += 1
    return op_list

Finds all operations until a blocking operation is hit.  This returns
a list of all operations from the starting frontier until a blocking
operation is encountered.  An operation is part of the list if
it is involves a qubit in the start_frontier dictionary, comes after
the moment listed in that dictionary, and before any blocking
operationi that involve that qubit.  Operations are only considered
to blocking the qubits that they operate on, so a blocking operation
that does not operate on any qubit in the starting frontier is not
actually considered blocking.  See `reachable_frontier_from` for a more
in depth example of reachable states.

Args:
start_frontier: A starting set of reachable locations.
is_blocker: A predicate that determines if operations block
reachability. Any location covered by an operation that causes
`is_blocker` to return True is considered to be an unreachable
location.

Returns:
A list of tuples. Each tuple describes an operation found between
the start frontier and a blocking operation. The first item of
each tuple is the index of the moment containing the operation,
and the second item is the operation itself.


def from_rotation_and_translation(rotation_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), translation_vec=(0, 0, 0), tol=0.1):
    rotation_matrix = np.array(rotation_matrix)
    translation_vec = np.array(translation_vec)
    if (rotation_matrix.shape != (3, 3)):
        raise ValueError('Rotation Matrix must be a 3x3 numpy array.')
    if (translation_vec.shape != (3,)):
        raise ValueError('Translation vector must be a rank 1 numpy array with 3 elements.')
    affine_matrix = np.eye(4)
    affine_matrix[0:3][(:, 0:3)] = rotation_matrix
    affine_matrix[0:3][(:, 3)] = translation_vec
    return SymmOp(affine_matrix, tol)

Creates a symmetry operation from a rotation matrix and a translation
vector.

Args:
rotation_matrix (3x3 array): Rotation matrix.
translation_vec (3x1 array): Translation vector.
tol (float): Tolerance to determine if rotation matrix is valid.

Returns:
SymmOp object


def confirmMapIdentity(self, subject, vendorSpecific=None):

        response = self.confirmMapIdentityResponse(subject, vendorSpecific)
        return self._read_boolean_response(response)

See Also: confirmMapIdentityResponse()

Args:
subject:
vendorSpecific:

Returns:


def serialize_to_transport(self, encoding='utf-8', xslt_url=None):

        assert encoding in ('utf-8', 'UTF-8')
        dataone_exception_pyxb = self.get_pyxb()
        return d1_common.xml.serialize_for_transport(
            dataone_exception_pyxb, xslt_url=xslt_url
        )

Serialize to XML ``bytes`` with prolog.

Args:
encoding: str
Encoding to use for XML doc bytes
xslt_url: str
If specified, add a processing instruction to the XML doc that specifies the
download location for an XSLT stylesheet.

Returns:
bytes: XML holding a DataONEError based type.


def find(cls, session, resource_id, include=None):
    url = session._build_url(cls._resource_path(), resource_id)
    params = build_request_include(include, None)
    process = cls._mk_one(session, include=include)
    return session.get(url, CB.json(200, process), params=params)

Retrieve a single resource.

This should only be called from sub-classes.

Args:

session(Session): The session to find the resource in

resource_id: The ``id`` for the resource to look up

Keyword Args:

include: Resource classes to include

Returns:

Resource: An instance of a resource, or throws a
:class:`NotFoundError` if the resource can not be found.


def join(self, *, collapse: bool=False) -> str:
    lines = []
    for line in self._lines:
        content = line.content
        if not collapse:
            indentation = ' ' * line.indent_lvl * line.indent_size
            content = textwrap.indent(content, indentation)
        lines.append(content)
    if collapse:
        token = ''
    else:
        token = '\n'
    return token.join(lines)

Returns the lines.

Args:
collapse: If `True`, all lines are merged together in a single line.

Returns:
text: All lines merged together


def zbar_function(fname, restype, *args):

    prototype = CFUNCTYPE(restype, *args)
    return prototype((fname, load_libzbar()))

Returns a foreign function exported by `zbar`.

Args:
fname (:obj:`str`): Name of the exported function as string.
restype (:obj:): Return type - one of the `ctypes` primitive C data
types.
*args: Arguments - a sequence of `ctypes` primitive C data types.

Returns:
cddl.CFunctionType: A wrapper around the function.