def parse(file_contents, file_name):
    env = Environment()
    result = ''
    try:
        env.parse(file_contents)
    except Exception:
        (_, exc_value, _) = sys.exc_info()
        result += 'ERROR: Jinja2 Template File: {0}'.format(file_name)
        result += (repr(exc_value) + '\n')
    return result

Takes a list of files which are assumed to be jinja2 templates and tries to
parse the contents of the files

Args:
file_contents (str): File contents of a jinja file

Raises:
Exception: An exception is raised if the contents of the file cannot be
parsed.


def _get_mpr_view(self, connection, table):
    logger.debug('Looking for view of the table.\n    table: {}'.format(table.vid))
    view = self.get_view_name(table)
    view_exists = self._relation_exists(connection, view)
    if view_exists:
        logger.debug('View of the table exists.\n    table: {}, view: {}'.format(table.vid, view))
        return view
    raise MissingViewError('sqlite database does not have view for {} table.'.format(table.vid))

Finds and returns view name in the sqlite db represented by given connection.

Args:
connection: connection to sqlite db where to look for partition table.
table (orm.Table):

Raises:
MissingViewError: if database does not have partition table.

Returns:
str: database table storing partition data.


def bitwise_not(x):
    if any_symbolic_tensors((x,)):
        return BitwiseNot().symbolic_call(x)
    return backend.numpy.bitwise_not(x)

Compute bit-wise inversion, or bit-wise NOT, element-wise.

Computes the bit-wise NOT of the underlying binary representation of the
integers in the input arrays. This ufunc implements the C/Python operator
`~`.

Args:
x: Input integer tensor.

Returns:
Result tensor.


def branch(self):
    cmd = ['git', 'symbolic-ref', '--short', 'HEAD']
    try:
        output = self.sh(cmd, shell=False, ignore_error=True).rstrip()
    except subprocess.CalledProcessError as e:
        log.exception(e)
        return ('
    if output.startswith('fatal: ref HEAD is not a symbolic ref'):
        output = ('
    return output

Determine the branch name of the working directory of this Repository

Returns:
str: branch name (``git symbolic-ref --short HEAD``)


def get_submissions_for_student_item(request, course_id, student_id, item_id):
    student_item_dict = dict(course_id=course_id, student_id=student_id, item_id=item_id)
    context = dict(**student_item_dict)
    try:
        submissions = get_submissions(student_item_dict)
        context['submissions'] = submissions
    except SubmissionRequestError:
        context['error'] = 'The specified student item was not found.'
    return render_to_response('submissions.html', context)

Retrieve all submissions associated with the given student item.

Developer utility for accessing all the submissions associated with a
student item. The student item is specified by the unique combination of
course, student, and item.

Args:
request (dict): The request.
course_id (str): The course id for this student item.
student_id (str): The student id for this student item.
item_id (str): The item id for this student item.

Returns:
HttpResponse: The response object for this request. Renders a simple
development page with all the submissions related to the specified
student item.


def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):

        init_params = dict()

        init_params['role'] = job_details['RoleArn']
        init_params['train_instance_count'] = job_details['ResourceConfig']['InstanceCount']
        init_params['train_instance_type'] = job_details['ResourceConfig']['InstanceType']
        init_params['train_volume_size'] = job_details['ResourceConfig']['VolumeSizeInGB']
        init_params['train_max_run'] = job_details['StoppingCondition']['MaxRuntimeInSeconds']
        init_params['input_mode'] = job_details['AlgorithmSpecification']['TrainingInputMode']
        init_params['base_job_name'] = job_details['TrainingJobName']
        init_params['output_path'] = job_details['OutputDataConfig']['S3OutputPath']
        init_params['output_kms_key'] = job_details['OutputDataConfig']['KmsKeyId']

        has_hps = 'HyperParameters' in job_details
        init_params['hyperparameters'] = job_details['HyperParameters'] if has_hps else {}

        if 'TrainingImage' in job_details['AlgorithmSpecification']:
            init_params['image'] = job_details['AlgorithmSpecification']['TrainingImage']
        elif 'AlgorithmName' in job_details['AlgorithmSpecification']:
            init_params['algorithm_arn'] = job_details['AlgorithmSpecification']['AlgorithmName']
        else:
            raise RuntimeError('Invalid AlgorithmSpecification. Either TrainingImage or '
                               'AlgorithmName is expected. None was found.')

        if 'MetricDefinitons' in job_details['AlgorithmSpecification']:
            init_params['metric_definitions'] = job_details['AlgorithmSpecification']['MetricsDefinition']

        if 'EnableInterContainerTrafficEncryption' in job_details:
            init_params['encrypt_inter_container_traffic'] = \
                job_details['EnableInterContainerTrafficEncryption']

        subnets, security_group_ids = vpc_utils.from_dict(job_details.get(vpc_utils.VPC_CONFIG_KEY))
        if subnets:
            init_params['subnets'] = subnets
        if security_group_ids:
            init_params['security_group_ids'] = security_group_ids

        if 'InputDataConfig' in job_details and model_channel_name:
            for channel in job_details['InputDataConfig']:
                if channel['ChannelName'] == model_channel_name:
                    init_params['model_channel_name'] = model_channel_name
                    init_params['model_uri'] = channel['DataSource']['S3DataSource']['S3Uri']
                    break

        return init_params

Convert the job description to init params that can be handled by the class constructor

Args:
job_details: the returned job details from a describe_training_job API call.
model_channel_name (str): Name of the channel where pre-trained model data will be downloaded.

Returns:
dictionary: The transformed init_params


def sync_l(self, option: str = 'all') -> None:

        if option in ['system', 'vendor', 'oem', 'data', 'all']:
            self._execute('-s', self.device_sn, 'sync', '-l', option)
        else:
            raise ValueError('There is no option named: {!r}.'.format(option))

List but don't copy.

Args:
option: 'system', 'vendor', 'oem', 'data', 'all'


def parse_geometry(ml_log, log=None, ml_version='2016.12', print_output=False):

    aabb = {}
    geometry = {'aabb':aabb}
    with open(ml_log) as fread:
        for line in fread:
            if 'Mesh Bounding Box min' in line:
                geometry['aabb']['min'] = (line.split()[4:7])
                geometry['aabb']['min'] = [util.to_float(val) for val in geometry['aabb']['min']]
            if 'Mesh Bounding Box max' in line:
                geometry['aabb']['max'] = (line.split()[4:7])
                geometry['aabb']['max'] = [util.to_float(val) for val in geometry['aabb']['max']]
            if 'Mesh Bounding Box Size' in line:
                geometry['aabb']['size'] = (line.split()[4:7])
                geometry['aabb']['size'] = [util.to_float(val) for val in geometry['aabb']['size']]
            if 'Mesh Bounding Box Diag' in line:
                geometry['aabb']['diagonal'] = util.to_float(line.split()[4])
            if 'Mesh Volume' in line:
                geometry['volume_mm3'] = util.to_float(line.split()[3])
                geometry['volume_cm3'] = geometry['volume_mm3'] * 0.001
            if 'Mesh Surface' in line:
                if ml_version == '1.3.4BETA':
                    geometry['area_mm2'] = util.to_float(line.split()[3])
                else:
                    geometry['area_mm2'] = util.to_float(line.split()[4])
                geometry['area_cm2'] = geometry['area_mm2'] * 0.01
            if 'Mesh Total Len of' in line:
                if 'including faux edges' in line:
                    geometry['total_edge_length_incl_faux'] = util.to_float(
                        line.split()[7])
                else:
                    geometry['total_edge_length'] = util.to_float(
                        line.split()[7])
            if 'Thin shell barycenter' in line:
                geometry['barycenter'] = (line.split()[3:6])
                geometry['barycenter'] = [util.to_float(val) for val in geometry['barycenter']]
            if 'Thin shell (faces) barycenter' in line:
                geometry['barycenter'] = (line.split()[4:7])
                geometry['barycenter'] = [util.to_float(val) for val in geometry['barycenter']]
            if 'Vertices barycenter' in line:
                geometry['vert_barycenter'] = (line.split()[2:5])
                geometry['vert_barycenter'] = [util.to_float(val) for val in geometry['vert_barycenter']]
            if 'Center of Mass' in line:
                geometry['center_of_mass'] = (line.split()[4:7])
                geometry['center_of_mass'] = [util.to_float(val) for val in geometry['center_of_mass']]
            if 'Inertia Tensor' in line:
                geometry['inertia_tensor'] = []
                for val in range(3):
                    row = (next(fread, val).split()[1:4])
                    row = [util.to_float(b) for b in row]
                    geometry['inertia_tensor'].append(row)
            if 'Principal axes' in line:
                geometry['principal_axes'] = []
                for val in range(3):
                    row = (next(fread, val).split()[1:4])
                    row = [util.to_float(b) for b in row]
                    geometry['principal_axes'].append(row)
            if 'axis momenta' in line:
                geometry['axis_momenta'] = (next(fread).split()[1:4])
                geometry['axis_momenta'] = [util.to_float(val) for val in geometry['axis_momenta']]
                break
    for key, value in geometry.items():
        if log is not None:
            log_file = open(log, 'a')
            log_file.write('{:27} = {}\n'.format(key, value))
            log_file.close()
        elif print_output:
            print('{:27} = {}'.format(key, value))
    return geometry

Parse the ml_log file generated by the measure_geometry function.

Warnings: Not all keys may exist if mesh is not watertight or manifold

Args:
ml_log (str): MeshLab log file to parse
log (str): filename to log output


def DeregisterAttributeContainer(cls, attribute_container_class):

    container_type = attribute_container_class.CONTAINER_TYPE.lower()
    if container_type not in cls._attribute_container_classes:
      raise KeyError(
          'Attribute container class not set for container type: '
          '{0:s}.'.format(attribute_container_class.CONTAINER_TYPE))

    del cls._attribute_container_classes[container_type]

Deregisters an attribute container class.

The attribute container classes are identified based on their lower case
container type.

Args:
attribute_container_class (type): attribute container class.

Raises:
KeyError: if attribute container class is not set for
the corresponding container type.


def convert_tokens_to_ids(self, tokens: Union[str, list[str]]) -> Union[int, list[int]]:
    if tokens is None:
        return None
    if isinstance(tokens, str):
        return self._convert_token_to_id_with_added_voc(tokens)
    ids = []
    for token in tokens:
        ids.append(self._convert_token_to_id_with_added_voc(token))
    return ids

Converts a token string (or a sequence of tokens) in a single integer id (or a sequence of ids), using the
vocabulary.

Args:
tokens (`str` or `List[str]`): One or several token(s) to convert to token id(s).

Returns:
`int` or `List[int]`: The token id or list of token ids.


def _prefix_from_prefix_string(cls, prefixlen_str):

        if not _BaseV4._DECIMAL_DIGITS.issuperset(prefixlen_str):
            cls._report_invalid_netmask(prefixlen_str)
        try:
            prefixlen = int(prefixlen_str)
        except ValueError:
            cls._report_invalid_netmask(prefixlen_str)
        if not (0 <= prefixlen <= cls._max_prefixlen):
            cls._report_invalid_netmask(prefixlen_str)
        return prefixlen

Return prefix length from a numeric string

Args:
prefixlen_str: The string to be converted

Returns:
An integer, the prefix length.

Raises:
NetmaskValueError: If the input is not a valid netmask


def pretty_str(something, indent=0):
    if isinstance(something, CodeEntity):
        return something.pretty_str(indent=indent)
    else:
        return ((' ' * indent) + repr(something))

Return a human-readable string representation of an object.

Uses `pretty_str` if the given value is an instance of
`CodeEntity` and `repr` otherwise.

Args:
something: Some value to convert.

Kwargs:
indent (int): The amount of spaces to use as indentation.


def match_validator(expression):

    if isinstance(expression, str):
        compiled = re.compile(expression)
    elif hasattr(expression, 'match'):

        compiled = expression
    else:
        raise TypeError(
            'Provided match is nor a string nor has a match method '
            '(like re expressions)'
        )

    def validator(value):
        if not compiled.match(value):

            raise ValidationError(
                "{} does not match pattern: {}".format(
                    value,
                    compiled.pattern
                    if hasattr(compiled, 'pattern')
                    else compiled
                )
            )

    return validator

Return validator function that will check if matches given expression.

Args:
match: if string then this will be converted to regular expression
using ``re.compile``. Can be also any object that has ``match()``
method like already compiled regular regular expression or custom
matching object/class.


def scored_to_phenotype(self, phenotypes):

    def _apply_score(scored_calls, phenotypes):
        present = sorted(list((set(phenotypes) & set(scored_calls.keys()))))
        total = sum([scored_calls[x] for x in present])
        if (total > 1):
            raise ValueError('You cant extract phenotypes from scores if they are not mutually exclusive')
        if (total == 0):
            return np.nan
        for label in present:
            if (scored_calls[label] == 1):
                return label
        raise ValueError('Should have hit an exit criteria already')
    output = self.copy()
    output['phenotype_label'] = output.apply((lambda x: _apply_score(x['scored_calls'], phenotypes)), 1)
    output['phenotype_calls'] = output.apply((lambda x: dict([(y, (1 if (x['phenotype_label'] == y) else 0)) for y in phenotypes])), 1)
    return output

Convert binary pehnotypes to mutually exclusive phenotypes.
If none of the phenotypes are set, then phenotype_label becomes nan
If any of the phenotypes are multiply set then it throws a fatal error.

Args:
phenotypes (list): a list of scored_names to convert to phenotypes

Returns:
CellDataFrame


def resolve_mode(self, name):
    if (name not in settings.CODEMIRROR_MODES):
        msg = "Given config name '{}' does not exists in 'settings.CODEMIRROR_MODES'."
        raise UnknowModeError(msg.format(name))
    return settings.CODEMIRROR_MODES.get(name)

From given mode name, return mode file path from
``settings.CODEMIRROR_MODES`` map.

Arguments:
name (string): Mode name.

Raises:
KeyError: When given name does not exist in
``settings.CODEMIRROR_MODES``.

Returns:
string: Mode file path.


def aggregate(self, index):
    if isinstance(index, string_types):
        col_df_grouped = self.col_df.groupby(self.df[index])
    else:
        self.col_df.index = pd.MultiIndex.from_arrays([self.df[i] for i in index])
        col_df_grouped = self.col_df.groupby(level=index)
        self.col_df.index = self.df.index
    self.reduced_df = pd.DataFrame({colred: col_df_grouped[colred.column].agg(colred.agg_func) for colred in self.column_reductions})
    reduced_dfs = []
    for cf in self.column_functions:
        reduced_dfs.append(cf.apply_and_name(self))
    return pd.concat(reduced_dfs, axis=1)

Performs a groupby of the unique Columns by index, as constructed from self.df.

Args:
index (str, or pd.Index): Index or column name of self.df.

Returns:
pd.DataFrame: A dataframe, aggregated by index, that contains the result
of the various ColumnFunctions, and named accordingly.


def set_uid(self, uid, schema=None):

        try:
            uid, schema = author_id_normalize_and_schema(uid, schema)
        except UnknownUIDSchema:

            pass

        self._ensure_field('ids', [])
        self.obj['ids'] = [id_ for id_ in self.obj['ids'] if id_.get('schema') != schema]
        self._add_uid(uid, schema)

Set a unique ID.

If a UID of a given schema already exists in a record it will
be overwritten, otherwise it will be appended to the record.

Args:
uid (string): unique identifier.
schema (Optional[string]): schema of the unique identifier. If
``None``, the schema will be guessed based on the shape of
``uid``.

Raises:
SchemaUIDConflict: it UID and schema are not matching


def text_filepaths_for_task(self, tmp_dir, task_id):
    assert (task_id >= 0)
    assert (task_id < (self.num_train_shards + self.num_dev_shards))
    if (task_id < self.num_train_shards):
        return [f for (i, f) in enumerate(self.train_text_filepaths(tmp_dir)) if ((i % self.num_train_shards) == task_id)]
    else:
        return [f for (i, f) in enumerate(self.dev_text_filepaths(tmp_dir)) if ((i % self.num_dev_shards) == (task_id - self.num_train_shards))]

List of input filepaths for a particular training or dev shard.

Args:
tmp_dir: a string
task_id: an integer less than self.num_shards
Returns:
a list of tuples (filepath, start_pos, num_bytes)


def __response_message_descriptor(self, message_type, method_id):
    descriptor = {'200': {'description': 'A successful response'}}
    if (message_type != message_types.VoidMessage()):
        self.__parser.add_message(message_type.__class__)
        self.__response_schema[method_id] = self.__parser.ref_for_message_type(message_type.__class__)
        descriptor['200']['schema'] = {'$ref': '
    return dict(descriptor)

Describes the response.

Args:
message_type: messages.Message class, The message to describe.
method_id: string, Unique method identifier (e.g. 'myapi.items.method')

Returns:
Dictionary describing the response.


def __init__(self, feature_dict, length=None, **kwargs):

    self._length = length
    super(SequenceDict, self).__init__(feature_dict, **kwargs)

Construct a sequence dict.

Args:
feature_dict: `dict`, the features to wrap
length: `int`, length of the sequence if static and known in advance
**kwargs: `dict`, constructor kwargs of `tfds.features.FeaturesDict`


def to_json_string(self, use_diff: bool=True) -> str:
    if use_diff is True:
        config_dict = self.to_diff_dict()
    else:
        config_dict = self.to_dict()
    return json.dumps(config_dict, indent=2, sort_keys=True) + '\n'

Serializes this instance to a JSON string.

Args:
use_diff (`bool`, *optional*, defaults to `True`):
If set to `True`, only the difference between the config instance and the default `PretrainedConfig()`
is serialized to JSON string.

Returns:
`str`: String containing all the attributes that make up this configuration instance in JSON format.


def save_pickle(obj, outfile, protocol=2):

    with open(outfile, 'wb') as f:
        pickle.dump(obj, f, protocol=protocol)

    return outfile

Save the object as a pickle file

Args:
outfile (str): Filename
protocol (int): Pickle protocol to use. Default is 2 to remain compatible with Python 2

Returns:
str: Path to pickle file


def create_s3_event(app_name, env, region, bucket, triggers):
    session = boto3.Session(profile_name=env, region_name=region)
    s3_client = session.client('s3')
    lambda_alias_arn = get_lambda_alias_arn(app_name, env, region)
    LOG.debug('Lambda ARN for lambda function %s is %s.', app_name, lambda_alias_arn)
    LOG.debug('Creating S3 events for bucket %s', bucket)
    principal = 's3.amazonaws.com'
    statement_id = '{}_s3_{}'.format(app_name, bucket).replace('.', '')
    source_arn = 'arn:aws:s3:::{}'.format(bucket)
    add_lambda_permissions(function=lambda_alias_arn, env=env, region=region, principal=principal, statement_id=statement_id, source_arn=source_arn)
    template_kwargs = {'lambda_arn': lambda_alias_arn, 'triggers': triggers}
    config = get_template(template_file='infrastructure/lambda/s3_event.json.j2', **template_kwargs)
    s3_client.put_bucket_notification_configuration(Bucket=bucket, NotificationConfiguration=json.loads(config))
    LOG.info('Created lambda %s S3 event on bucket %s', app_name, bucket)

Create S3 lambda events from triggers

Args:
app_name (str): name of the lambda function
env (str): Environment/Account for lambda function
region (str): AWS region of the lambda function
triggers (list): List of triggers from the settings


def wait(self, duration=None, count=0):

        start = time.time()
        total = 0
        while True:
            type, result = self._recv(MSG, PING, OK)
            if type is MSG:
                total += 1
                if self._handle_msg(result) is False:
                    break

                if count and total >= count:
                    break

            elif type is PING:
                self._handle_ping()

            if duration and time.time() - start > duration:
                break

Publish publishes the data argument to the given subject.

Args:
duration (float): will wait for the given number of seconds
count (count): stop of wait after n messages from any subject


def operate_multi(self, points):

        points = np.array(points)
        affine_points = np.concatenate(
            [points, np.ones(points.shape[:-1] + (1,))], axis=-1)
        return np.inner(affine_points, self.affine_matrix)[..., :-1]

Apply the operation on a list of points.

Args:
points: List of Cartesian coordinates

Returns:
Numpy array of coordinates after operation


def ip(self, value):

        if value == self._defaults['ai.location.ip'] and 'ai.location.ip' in self._values:
            del self._values['ai.location.ip']
        else:
            self._values['ai.location.ip'] = value

The ip property.

Args:
value (string). the property value.


def _make_parser_func(sep):

    def parser_func(
        filepath_or_buffer,
        sep=sep,
        delimiter=None,
        header="infer",
        names=None,
        index_col=None,
        usecols=None,
        squeeze=False,
        prefix=None,
        mangle_dupe_cols=True,
        dtype=None,
        engine=None,
        converters=None,
        true_values=None,
        false_values=None,
        skipinitialspace=False,
        skiprows=None,
        nrows=None,
        na_values=None,
        keep_default_na=True,
        na_filter=True,
        verbose=False,
        skip_blank_lines=True,
        parse_dates=False,
        infer_datetime_format=False,
        keep_date_col=False,
        date_parser=None,
        dayfirst=False,
        iterator=False,
        chunksize=None,
        compression="infer",
        thousands=None,
        decimal=b".",
        lineterminator=None,
        quotechar='"',
        quoting=0,
        escapechar=None,
        comment=None,
        encoding=None,
        dialect=None,
        tupleize_cols=None,
        error_bad_lines=True,
        warn_bad_lines=True,
        skipfooter=0,
        doublequote=True,
        delim_whitespace=False,
        low_memory=True,
        memory_map=False,
        float_precision=None,
    ):
        _, _, _, kwargs = inspect.getargvalues(inspect.currentframe())
        if not kwargs.get("sep", sep):
            kwargs["sep"] = "\t"
        return _read(**kwargs)

    return parser_func

Creates a parser function from the given sep.

Args:
sep: The separator default to use for the parser.

Returns:
A function object.


def from_raw(self, robj: RawObject) -> RootNode:
    cooked = self.schema.from_raw(robj)
    return RootNode(cooked, self.schema, cooked.timestamp)

Create an instance node from a raw data tree.

Args:
robj: Dictionary representing a raw data tree.

Returns:
Root instance node.


def _generate(cls, strategy, params):
    if cls._meta.abstract:
        raise errors.FactoryError(('Cannot generate instances of abstract factory %(f)s; Ensure %(f)s.Meta.model is set and %(f)s.Meta.abstract is either not set or False.' % dict(f=cls.__name__)))
    step = builder.StepBuilder(cls._meta, params, strategy)
    return step.build()

generate the object.

Args:
params (dict): attributes to use for generating the object
strategy: the strategy to use


def device_ids(self):
    if self._device_ids is None:
        with ops.init_scope():
            device_ids_list = []
            for index, device in enumerate(self.components):
                with ops.device(device):
                    device_ids_list.append(array_ops.identity(constant_op.constant(index)))
            self._device_ids = self.pack(device_ids_list)
    return self._device_ids

A parallel tensor with scalar integers numbering component devices.

Each device ID is placed on its corresponding device, in the same order as
the `components` constructor argument.

Returns:
A parallel tensor containing 0 on the first device, 1 on the second, etc.


def dft_task(cls, mol, xc="b3lyp", **kwargs):

        t = NwTask.from_molecule(mol, theory="dft", **kwargs)
        t.theory_directives.update({"xc": xc,
                                    "mult": t.spin_multiplicity})
        return t

A class method for quickly creating DFT tasks with optional
cosmo parameter .

Args:
mol: Input molecule
xc: Exchange correlation to use.
\\*\\*kwargs: Any of the other kwargs supported by NwTask. Note the
theory is always "dft" for a dft task.


def from_class(cls, target_class):

        module_name = target_class.__module__
        class_name = target_class.__name__
        return cls(module_name, "__init__", class_name)

Create a FunctionDescriptor from a class.

Args:
cls: Current class which is required argument for classmethod.
target_class: the python class used to create the function
descriptor.

Returns:
The FunctionDescriptor instance created according to the class.


def __init__(self, app, env, region, prop_path, artifact_path, artifact_version, primary_region='us-east-1'):

        self.app_name = app
        self.env = env
        self.region = region
        self.artifact_path = artifact_path
        self.version = artifact_version
        self.properties = get_properties(prop_path, env=self.env, region=self.region)
        self.s3props = self.properties['s3']
        generated = get_details(app=app, env=env, region=region)

        include_region = True
        if self.region == primary_region:
            include_region = False
        if self.s3props.get('shared_bucket_master'):
            self.bucket = generated.shared_s3_app_bucket(include_region=include_region)
            self.s3path = app
        elif self.s3props.get('shared_bucket_target'):
            shared_app = self.s3props['shared_bucket_target']
            newgenerated = get_details(app=shared_app, env=env, region=region)
            self.bucket = newgenerated.shared_s3_app_bucket(include_region=include_region)
            self.s3path = app
        else:
            self.bucket = generated.s3_app_bucket(include_region=include_region)
            self.s3path = self.s3props['path'].lstrip('/')

        self.s3_version_uri = ''
        self.s3_latest_uri = ''
        self.setup_pathing()

S3 deployment object.

Args:
app (str): Application name
env (str): Environment/Account
region (str): AWS Region
prop_path (str): Path of environment property file
artifact_path (str): Path to tar.gz artifact
primary_region (str): The primary region for the application.


def _get_css_files(cls, extra_files):
    packager = Packager()
    css_packages = getattr(cls, 'css_packages', {})
    return dict(((media_target, cls._get_media_files(packager=packager, media_packages=media_packages, media_type='css', extra_files=extra_files.get(media_target, []))) for (media_target, media_packages) in six.iteritems(css_packages)))

Return all CSS files from the Media class.

Args:
extra_files (dict):
The contents of the Media class's original :py:attr:`css`
attribute, if one was provided.

Returns:
dict:
The CSS media types and files to return for the :py:attr:`css`
attribute.


def populate_development(version):
    with open(DEVELOPMENT_TEMPLATE, 'r') as file_obj:
        template = file_obj.read()
    contents = template.format(revision=version, rtd_version=version)
    with open(DEVELOPMENT_FILE, 'w') as file_obj:
        file_obj.write(contents)

Populates ``DEVELOPMENT.rst`` with release-specific data.

This is because ``DEVELOPMENT.rst`` is used in the Sphinx documentation.

Args:
version (str): The current version.


def parse_cartouche_text(lines):
    indent_lines = unindent(lines)
    indent_lines = pad_blank_lines(indent_lines)
    indent_lines = first_paragraph_indent(indent_lines)
    indent_paragraphs = gather_lines(indent_lines)
    parse_tree = group_paragraphs(indent_paragraphs)
    syntax_tree = extract_structure(parse_tree)
    result = syntax_tree.render_rst()
    ensure_terminal_blank(result)
    return result

Parse text in cartouche format and return a reStructuredText equivalent

Args:
lines: A sequence of strings representing the lines of a single
docstring as read from the source by Sphinx. This string should be
in a format that can be parsed by cartouche.

Returns:
A list of lines containing the transformed docstring as
reStructuredText as produced by cartouche.

Raises:
RuntimeError: If the docstring cannot be parsed.


def sampler(sample_function: Callable) -> Callable:

    def generate_sampler(continuous_pulse: Callable) -> Callable:
        'Return a decorated sampler function.'

        @functools.wraps(continuous_pulse)
        def call_sampler(duration: int, *args, **kwargs) -> commands.SamplePulse:
            'Replace the call to the continuous function with a call to the sampler applied\n            to the anlytic pulse function.'
            sampled_pulse = sample_function(continuous_pulse, duration, *args, **kwargs)
            return np.asarray(sampled_pulse, dtype=np.complex_)
        call_sampler = _update_annotations(call_sampler)
        call_sampler = _update_docstring(call_sampler, sample_function)
        call_sampler.__dict__.pop('__wrapped__')
        return commands.functional_pulse(call_sampler)
    return generate_sampler

Sampler decorator base method.

Samplers are used for converting an continuous function to a discretized pulse.

They operate on a function with the signature:
`def f(times: np.ndarray, *args, **kwargs) -> np.ndarray`
Where `times` is a numpy array of floats with length n_times and the output array
is a complex numpy array with length n_times. The output of the decorator is an
instance of `FunctionalPulse` with signature:
`def g(duration: int, *args, **kwargs) -> SamplePulse`

Note if your continuous pulse function outputs a `complex` scalar rather than a
`np.ndarray`, you should first vectorize it before applying a sampler.

This class implements the sampler boilerplate for the sampler.

Args:
sample_function: A sampler function to be decorated.


def get_object(self, file_path):

        file_path = make_string_path(file_path)
        file_path = self.absnormpath(self._original_path(file_path))
        return self.get_object_from_normpath(file_path)

Search for the specified filesystem object within the fake
filesystem.

Args:
file_path: Specifies the target FakeFile object to retrieve.

Returns:
The FakeFile object corresponding to `file_path`.

Raises:
IOError: if the object is not found.


def concat(self, array_like):
    arr = list(array_like)
    if (len(set([x.microns_per_pixel for x in arr])) != 1):
        raise ValueError('Multiple microns per pixel set')
    cdf = CellDataFrame(pd.concat([pd.DataFrame(x) for x in arr]))
    cdf.microns_per_pixel = arr[0].microns_per_pixel
    return cdf

Concatonate multiple CellDataFrames

throws an error if the microns_per_pixel is not uniform across the frames

Args:
array_like (list): a list of CellDataFrames with 1 or more CellDataFrames

Returns:
CellDataFrame


def s_url(self, path, method=None, type_cast=None):
    if (not type_cast):
        type_cast = {}

    def decorator(function):
        self.s_add(path, function, method, type_cast)
        return function
    return decorator

Decorator for registering a simple path.

Args:
path (str): Path to be matched.
method (str, optional): Usually used to define one of GET, POST,
PUT, DELETE. You may use whatever fits your situation though.
Defaults to None.
type_cast (dict, optional): Mapping between the param name and
one of `int`, `float` or `bool`. The value reflected by the
provided param name will than be casted to the given type.
Defaults to None.


def mode_group(self):
    hmodegroup = self._libinput.libinput_event_tablet_pad_get_mode_group(self._handle)
    return TabletPadModeGroup(hmodegroup, self._libinput)

The mode group that the button, ring, or strip that
triggered this event is considered in.

The mode is a virtual grouping of functionality, usually based on some
visual feedback like LEDs on the pad. See `Tablet pad modes`_
for details.

Returns:
~libinput.define.TabletPadModeGroup: The mode group of the button,
ring or strip that caused this event.


def trees_by_subpath(self, sub_path):

        matches = (
            self.path_db[tree_path].keys()
            for tree_path in self.path_db.iterkeys()
            if tree_path.startswith(sub_path)
        )

        return set(sum(matches, []))

Search trees by `sub_path` using ``Tree.path.startswith(sub_path)``
comparison.

Args:
sub_path (str): Part of the :attr:`.Tree.path` property of
:class:`.Tree`.

Returns:
set: Set of matching :class:`Tree` instances.


def random_get_instance() -> tcod.random.Random:
    return tcod.random.Random._new_from_cdata(ffi.cast('mersenne_data_t*', lib.TCOD_random_get_instance()))

Return the default Random instance.

Returns:
Random: A Random instance using the default random number generator.


def crop(self, extent, copy=False):

        try:
            if extent[0] is None:
                extent = (self.start.z, extent[1])
            if extent[1] is None:
                extent = (extent[0], self.stop.z)
        except:
            m = "You must provide a 2-tuple for the new extents. Use None for"
            m += " the existing start or stop."
            raise StriplogError(m)

        first_ix = self.read_at(extent[0], index=True)
        last_ix = self.read_at(extent[1], index=True)

        first = self[first_ix].split_at(extent[0])[1]
        last = self[last_ix].split_at(extent[1])[0]

        new_list = self.__list[first_ix:last_ix+1].copy()
        new_list[0] = first
        new_list[-1] = last

        if copy:
            return Striplog(new_list)
        else:
            self.__list = new_list
            return

Crop to a new depth range.

Args:
extent (tuple): The new start and stop depth. Must be 'inside'
existing striplog.
copy (bool): Whether to operate in place or make a copy.

Returns:
Operates in place by deault; if copy is True, returns a striplog.


def delete(self, remove_tombstone=True):

		response = self.repo.api.http_request('DELETE', self.uri)

		if response.status_code == 204:

			self._empty_resource_attributes()

		if remove_tombstone:
			self.repo.api.http_request('DELETE', '%s/fcr:tombstone' % self.uri)

		return True

Method to delete resources.

Args:
remove_tombstone (bool): If True, will remove tombstone at uri/fcr:tombstone when removing resource.

Returns:
(bool)


def _convert_single_op_hint_to_stub(call, graph_def, function_def_nodes=None, is_last_run=True):
    if function_def_nodes is None:
        function_def_nodes = set()
    name_to_input_name, name_to_node, name_to_seq_num = _extract_graph_summary(graph_def)
    input_names, output_names = call.flattened_inputs_and_outputs()
    reachable_by_input = _bfs_for_reachable_nodes(input_names, name_to_input_name)
    reachable_by_output = _bfs_for_reachable_nodes(output_names, name_to_input_name)
    output_nodes_set = set(output_names)
    nodes_after_fuse = []
    nodes_deleted_by_fuse = set()
    for node in graph_def.node:
        n = _tensor_name_base(node.name)
        if n in reachable_by_output:
            if n not in reachable_by_input and n not in output_nodes_set:
                nodes_deleted_by_fuse.add(n)
        elif n not in reachable_by_input and n not in function_def_nodes:
            nodes_after_fuse.append(n)
        elif not is_last_run:
            nodes_after_fuse.append(n)
    out = _graph_pb2.GraphDef()
    reachable_by_input_sorted = sorted(list(reachable_by_input), key=lambda n: name_to_seq_num[n])
    for node in reachable_by_input_sorted:
        out.node.extend([_copy.deepcopy(name_to_node[node])])
    sorted_input_indices = list(call.inputs.keys())
    sorted_input_indices.sort()
    sorted_output_indices = list(call.outputs.keys())
    sorted_output_indices.sort()
    new_node = _node_def_pb2.NodeDef()
    optional_input_node = _node_def_pb2.NodeDef()
    optional_input_node.name = 'Const' + str(_uuid.uuid1().hex)
    optional_input_node.op = 'Const'
    optional_input_node.attr['dtype'].CopyFrom(_attr_value_pb2.AttrValue(type=_dtypes.float32.as_datatype_enum))
    optional_input_node.attr['value'].CopyFrom(_attr_value_pb2.AttrValue(tensor=_tensor_util.make_tensor_proto([-1], _dtypes.float32, [1])))
    out.node.extend([optional_input_node])
    max_index = max(sorted_input_indices) + 1
    for cur_index in range(max_index):
        if cur_index in sorted_input_indices:
            inputs = call.inputs[cur_index]
            input_name = inputs.aggregate_and_return_name_for_input(out)
            new_node.input.append(input_name)
        else:
            new_node.input.append(optional_input_node.name)
    new_node.attr[OpHint.TFLITE_INPUT_INDICES].list.i.extend(sorted_input_indices)
    new_node.op = call.function_name
    new_node.name = call.uuid
    out.node.extend([new_node])
    output_dtypes = []
    max_output_index = max(sorted_output_indices) + 1
    for cur_index in range(max_output_index):
        if cur_index in sorted_output_indices:
            output = call.outputs[cur_index]
            output_dtype = output.aggregate_and_return_name_for_output(new_node.name, cur_index, out)
        else:
            output_dtype = optional_input_node.attr['type'].i
        output_dtypes.append(output_dtype)
    new_node.attr['_output_types'].list.type[:] = output_dtypes
    new_node.attr['_output_quantized'].b = False
    for n in nodes_after_fuse:
        should_keep = True
        for input_name in name_to_input_name[n]:
            if input_name in nodes_deleted_by_fuse:
                should_keep = False
        if should_keep:
            out.node.extend([_copy.deepcopy(name_to_node[n])])
    out.library.CopyFrom(graph_def.library)
    out.versions.CopyFrom(graph_def.versions)
    return out

Given a graph_def, converts `call` into a stub and returns a new graph_def.

Args:
call: A single function call to be converted.
graph_def: A graph_def to use as input (that has call obviously).
function_def_nodes: Nodes inside the function def those are not connected to
the graph.
is_last_run: Whether it is the last run for a given pass (for OpHint has
children).

Returns:
A new transformed graph-def that has call as a stub (single op).

Note: after this process, the graph_def can no longer be loaded into
the tensorflow runtime, so all future manipulations are done in graph_def
level.


def _usage_id_from_node(self, node, parent_id, id_generator=None):

        if id_generator is not None:
            warnings.warn(
                "Passing an id_generator directly is deprecated "
                "in favor of constructing the Runtime with the id_generator",
                DeprecationWarning,
                stacklevel=3,
            )

        id_generator = id_generator or self.id_generator

        block_type = node.tag

        node.attrib.pop('xblock-family', None)

        def_id = id_generator.create_definition(block_type)
        usage_id = id_generator.create_usage(def_id)
        keys = ScopeIds(None, block_type, def_id, usage_id)
        block_class = self.mixologist.mix(self.load_block_type(block_type))

        aside_children = []
        for child in node.iterchildren():

            xblock_family = child.attrib.pop('xblock-family', None)
            if xblock_family:
                xblock_family = self._family_id_to_superclass(xblock_family)
                if issubclass(xblock_family, XBlockAside):
                    aside_children.append(child)

        for child in aside_children:
            self._aside_from_xml(child, def_id, usage_id, id_generator)
            node.remove(child)
        block = block_class.parse_xml(node, self, keys, id_generator)
        block.parent = parent_id
        block.save()
        return usage_id

Create a new usage id from an XML dom node.

Args:
node (lxml.etree.Element): The DOM node to interpret.
parent_id: The usage ID of the parent block
id_generator (IdGenerator): The :class:`.IdGenerator` to use
for creating ids


def _clone_helper(op_to_clone, variant_tensor_ops):
    remap_dict = {}
    for input_tensor in op_to_clone.inputs:
        input_tensor_op = input_tensor.op
        if input_tensor_op in variant_tensor_ops:
            recursive_map = _clone_helper(input_tensor_op, variant_tensor_ops)
            remap_dict.update(recursive_map)
    inputs_list = []
    for input_tensor in op_to_clone.inputs:
        input_tensor_op = input_tensor.op
        if input_tensor_op in remap_dict:
            remapped_input = remap_dict[input_tensor_op].outputs[0]
            inputs_list.append(remapped_input)
        else:
            inputs_list.append(input_tensor_op.outputs[input_tensor.value_index])
    g = ops.get_default_graph()
    new_op = g.create_op(op_to_clone.type, inputs_list, [o.dtype for o in op_to_clone.outputs], name=op_to_clone.name, attrs=op_to_clone.node_def.attr, op_def=_get_op_def(op_to_clone))
    remap_dict[op_to_clone] = new_op
    return remap_dict

Helper method that recursively clones `op_to_clone`.

Args:
op_to_clone: The op we want to clone.
variant_tensor_ops: A list of ops that we have to clone along the way.

Returns:
A dictionary mapping old_ops to new_ops created. Includes op_to_clone
as a key.


def create_snapshot(self, volume_id_or_uri, snapshot, timeout=-1):

        uri = self.__build_volume_snapshot_uri(volume_id_or_uri)

        return self._client.create(snapshot, uri=uri, timeout=timeout, default_values=self.DEFAULT_VALUES_SNAPSHOT)

Creates a snapshot for the specified volume.

Args:
volume_id_or_uri:
Can be either the volume ID or the volume URI.
snapshot (dict):
Object to create.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation in
OneView, just stops waiting for its completion.

Returns:
dict: Storage volume.


def get_all_profiles(store='local'):

    return {
        'Domain Profile': get_all_settings(profile='domain', store=store),
        'Private Profile': get_all_settings(profile='private', store=store),
        'Public Profile': get_all_settings(profile='public', store=store)
    }

Gets all properties for all profiles in the specified store

Args:

store (str):
The store to use. This is either the local firewall policy or the
policy defined by local group policy. Valid options are:

- lgpo
- local

Default is ``local``

Returns:
dict: A dictionary containing the specified settings for each profile


def _plot(self, axes_list):

        axes = axes_list[0]

        if self.plot_settings:
            axes.imshow(self.data['image_data'], cmap=self.plot_settings['cmap'], interpolation=self.plot_settings['interpol'], extent=self.data['extent'])
            axes.set_xlabel(self.plot_settings['xlabel'])
            axes.set_ylabel(self.plot_settings['ylabel'])
            axes.set_title(self.plot_settings['title'])

        self._update(axes_list)

Plots a dot on top of each selected NV, with a corresponding number denoting the order in which the NVs are
listed.
Precondition: must have an existing image in figure_list[0] to plot over
Args:
figure_list:


def is_enrolled(self, username, course_run_id):
    enrollment = self.get_course_enrollment(username, course_run_id)
    return ((enrollment is not None) and enrollment.get('is_active', False))

Query the enrollment API and determine if a learner is enrolled in a course run.

Args:
username (str): The username by which the user goes on the OpenEdX platform
course_run_id (str): The string value of the course's unique identifier

Returns:
bool: Indicating whether the user is enrolled in the course run. Returns False under any errors.


def run(self, data):
    result_type = namedtuple('Result', 'code messages')
    if (self.passes is True):
        result = result_type(Checker.Code.PASSED, '')
    elif (self.passes is False):
        if self.allow_failure:
            result = result_type(Checker.Code.IGNORED, '')
        else:
            result = result_type(Checker.Code.FAILED, '')
    else:
        try:
            result = self.check(data, **self.arguments)
            messages = ''
            if isinstance(result, tuple):
                (result, messages) = result
            if (result not in Checker.Code):
                result = (Checker.Code.PASSED if bool(result) else Checker.Code.FAILED)
            if ((result == Checker.Code.FAILED) and self.allow_failure):
                result = Checker.Code.IGNORED
            result = result_type(result, messages)
        except NotImplementedError:
            result = result_type(Checker.Code.NOT_IMPLEMENTED, '')
    self.result = result

Run the check method and format the result for analysis.

Args:
data (DSM/DMM/MDM): DSM/DMM/MDM instance to check.

Returns:
tuple (int, str): status constant from Checker class and messages.


def from_celery(cls, worker_name, job_dict, celery_app):

        if not isinstance(job_dict, dict) or 'id' not in job_dict:
            raise JobStatInvalid('The job description is missing important fields.')

        async_result = AsyncResult(id=job_dict['id'], app=celery_app)
        a_info = async_result.info if isinstance(async_result.info, dict) else None

        return JobStats(
            name=a_info.get('name', '') if a_info is not None else '',
            job_id=job_dict['id'],
            job_type=a_info.get('type', '') if a_info is not None else '',
            workflow_id=a_info.get('workflow_id', '') if a_info is not None else '',
            queue=a_info.get('queue', '') if a_info is not None else '',
            start_time=a_info.get('start_time', None) if a_info is not None else None,
            arguments=a_info.get('arguments', {}) if a_info is not None else {},
            acknowledged=job_dict['acknowledged'],
            func_name=job_dict['type'],
            hostname=job_dict['hostname'],
            worker_name=worker_name,
            worker_pid=job_dict['worker_pid'],
            routing_key=job_dict['delivery_info']['routing_key']
        )

Create a JobStats object from the dictionary returned by celery.

Args:
worker_name (str): The name of the worker this jobs runs on.
job_dict (dict): The dictionary as returned by celery.
celery_app: Reference to a celery application object.

Returns:
JobStats: A fully initialized JobStats object.


def _input_valid(input_, operation, message, output_condition_uri=None):
    ccffill = input_.fulfillment
    try:
        parsed_ffill = Fulfillment.from_uri(ccffill.serialize_uri())
    except (TypeError, ValueError, ParsingError, ASN1DecodeError, ASN1EncodeError):
        return False
    if (operation == Transaction.CREATE):
        output_valid = True
    else:
        output_valid = (output_condition_uri == ccffill.condition_uri)
    message = sha3_256(message.encode())
    if input_.fulfills:
        message.update('{}{}'.format(input_.fulfills.txid, input_.fulfills.output).encode())
    ffill_valid = parsed_ffill.validate(message=message.digest())
    return (output_valid and ffill_valid)

Validates a single Input against a single Output.

Note:
In case of a `CREATE` Transaction, this method
does not validate against `output_condition_uri`.

Args:
input_ (:class:`~bigchaindb.common.transaction.
Input`) The Input to be signed.
operation (str): The type of Transaction.
message (str): The fulfillment message.
output_condition_uri (str, optional): An Output to check the
Input against.

Returns:
bool: If the Input is valid.


def submit(self, cmd_string, blocksize, tasks_per_node, job_name="parsl"):

        if not self.resources:
            cur_timestamp = str(time.time() * 1000).split(".")[0]
            job_name = "{0}-{1}".format(job_name, cur_timestamp)

            if not self.deployment_name:
                deployment_name = '{}-deployment'.format(job_name)
            else:
                deployment_name = '{}-{}-deployment'.format(self.deployment_name,
                                                            cur_timestamp)

            formatted_cmd = template_string.format(command=cmd_string,
                                                   worker_init=self.worker_init)

            self.deployment_obj = self._create_deployment_object(job_name,
                                                                 self.image,
                                                                 deployment_name,
                                                                 cmd_string=formatted_cmd,
                                                                 replicas=self.init_blocks,
                                                                 volumes=self.persistent_volumes)
            logger.debug("Deployment name :{}".format(deployment_name))
            self._create_deployment(self.deployment_obj)
            self.resources[deployment_name] = {'status': 'RUNNING',
                                               'pods': self.init_blocks}

        return deployment_name

Submit a job
Args:
- cmd_string  :(String) - Name of the container to initiate
- blocksize   :(float) - Number of replicas
- tasks_per_node (int) : command invocations to be launched per node

Kwargs:
- job_name (String): Name for job, must be unique
Returns:
- None: At capacity, cannot provision more
- job_id: (string) Identifier for the job


def memory_usage(self, string=False):

        if string:
            n = getsizeof(self)
            return ' '.join((str(s) for s in convert_bytes(n)))
        return self.info()['size']

Get the memory usage estimate of the container.

Args:
string (bool): Human readable string (default false)

See Also:
:func:`~exa.core.container.Container.info`


def get_body(name):
    try:
        (body, propag) = _bodies[name.lower()]
        body.propagate = propag.propagate
    except KeyError as e:
        raise UnknownBodyError(e.args[0])
    return body

Retrieve a given body orbits and parameters

Args:
name (str): Object name
Return:
Body:


def truncate(text, max_len=350, end='...'):
    if (len(text) <= max_len):
        return text
    return (text[:max_len].rsplit(' ', maxsplit=1)[0] + end)

Truncate the supplied text for display.

Arguments:
text (:py:class:`str`): The text to truncate.
max_len (:py:class:`int`, optional): The maximum length of the
text before truncation (defaults to 350 characters).
end (:py:class:`str`, optional): The ending to use to show that
the text was truncated (defaults to ``'...'``).

Returns:
:py:class:`str`: The truncated text.


def validate_labels(known_classes, passed_labels, argument_name):
    known_classes = np.array(known_classes)
    passed_labels = np.array(passed_labels)
    (unique_labels, unique_indexes) = np.unique(passed_labels, return_index=True)
    if (len(passed_labels) != len(unique_labels)):
        indexes = np.arange(0, len(passed_labels))
        duplicate_indexes = indexes[(~ np.in1d(indexes, unique_indexes))]
        duplicate_labels = [str(x) for x in passed_labels[duplicate_indexes]]
        msg = 'The following duplicate labels were passed into {0}: {1}'.format(argument_name, ', '.join(duplicate_labels))
        raise ValueError(msg)
    passed_labels_absent = (~ np.in1d(passed_labels, known_classes))
    if np.any(passed_labels_absent):
        absent_labels = [str(x) for x in passed_labels[passed_labels_absent]]
        msg = 'The following labels were passed into {0}, but were not found in labels: {1}'.format(argument_name, ', '.join(absent_labels))
        raise ValueError(msg)
    return

Validates the labels passed into the true_labels or pred_labels
arguments in the plot_confusion_matrix function.

Raises a ValueError exception if any of the passed labels are not in the
set of known classes or if there are duplicate labels. Otherwise returns
None.

Args:
known_classes (array-like):
The classes that are known to appear in the data.
passed_labels (array-like):
The labels that were passed in through the argument.
argument_name (str):
The name of the argument being validated.

Example:
>>> known_classes = ["A", "B", "C"]
>>> passed_labels = ["A", "B"]
>>> validate_labels(known_classes, passed_labels, "true_labels")


def WriteOutput(title, locations, limit, f):

  output_prefix =  % locals()

  output_suffix =  % locals()

  f.write(transitfeed.EncodeUnicode(output_prefix))
  for source, destination in zip(locations[0:limit], locations[1:limit + 1]):
    f.write(transitfeed.EncodeUnicode("<li>%s\n" %
                                      LatLngsToGoogleLink(source, destination)))
  f.write(transitfeed.EncodeUnicode(output_suffix))

Write html to f for up to limit trips between locations.

Args:
title: String used in html title
locations: list of (lat, lng) tuples
limit: maximum number of queries in the html
f: a file object


def _create_candidates(self, n=1000):
    if self.grid:
        return self._candidates_from_grid(n)
    else:
        return self._random_candidates(n)

Generate random hyperparameter vectors

Args:
n (int, optional): number of candidates to generate. Defaults to 1000.

Returns:
candidates (np.array): Array of candidate hyperparameter vectors with shape
(n_samples, len(tunables))


def _SkipFieldValue(tokenizer):
    if tokenizer.TryConsumeByteString():
        while tokenizer.TryConsumeByteString():
            pass
        return
    if ((not tokenizer.TryConsumeIdentifier()) and (not _TryConsumeInt64(tokenizer)) and (not _TryConsumeUint64(tokenizer)) and (not tokenizer.TryConsumeFloat())):
        raise ParseError(('Invalid field value: ' + tokenizer.token))

Skips over a field value.

Args:
tokenizer: A tokenizer to parse the field name and values.

Raises:
ParseError: In case an invalid field value is found.


def get_contingency_tables(self):
    return np.array([ContingencyTable(*ct) for ct in self.contingency_tables.values])

Create an Array of ContingencyTable objects for each probability threshold.

Returns:
Array of ContingencyTable objects


def vec_to_surface(vec):

        miller = [None] * 3
        index = []
        for i, value in enumerate(vec):
            if abs(value) < 1.e-8:
                miller[i] = 0
            else:
                index.append(i)
        if len(index) == 1:
            miller[index[0]] = 1
        else:
            min_index = np.argmin([i for i in vec if i != 0])
            true_index = index[min_index]
            index.pop(min_index)
            frac = []
            for i, value in enumerate(index):
                frac.append(Fraction(vec[value] / vec[true_index]).limit_denominator(100))
            if len(index) == 1:
                miller[true_index] = frac[0].denominator
                miller[index[0]] = frac[0].numerator
            else:
                com_lcm = lcm(frac[0].denominator, frac[1].denominator)
                miller[true_index] = com_lcm
                miller[index[0]] = frac[0].numerator * int(round((com_lcm / frac[0].denominator)))
                miller[index[1]] = frac[1].numerator * int(round((com_lcm / frac[1].denominator)))
        return miller

Transform a float vector to a surface miller index with integers.

Args:
vec (1 by 3 array float vector): input float vector
Return:
the surface miller index of the input vector.


def _extract_image_batch(images, num_images, batch_size):
    if len(ops.shape(images)) != 4:
        raise ValueError('`plot_images_gallery()` requires you to batch your `np.array` samples together.')
    num_samples = min(num_images, batch_size)
    sample = images[:num_samples, ...]
    return sample

Extracts a batch of images for plotting.

Args:
images: The 4D tensor or NumPy array of images.
num_images: The number of images to extract.
batch_size: The original batch size of the images.

Returns:
A 4D tensor or NumPy array containing the extracted images.

Raises:
ValueError: If `images` is not a 4D tensor/array.


def uid(uid):

    if uid is None:
        raise ValueError('UID cannot be None.')

    def decorate(test_func):
        @functools.wraps(test_func)
        def wrapper(*args, **kwargs):
            return test_func(*args, **kwargs)

        setattr(wrapper, 'uid', uid)
        return wrapper

    return decorate

Decorator specifying the unique identifier (UID) of a test case.

The UID will be recorded in the test's record when executed by Mobly.

If you use any other decorator for the test method, you may want to use
this as the outer-most one.

Note a common UID system is the Universal Unitque Identifier (UUID), but
we are not limiting people to use UUID, hence the more generic name `UID`.

Args:
uid: string, the uid for the decorated test function.


def aggregate(self, reducer, seed=default, result_selector=identity):
    if self.closed():
        raise ValueError('Attempt to call aggregate() on a closed Queryable.')
    if (not is_callable(reducer)):
        raise TypeError('aggregate() parameter reducer={0} is not callable'.format(repr(reducer)))
    if (not is_callable(result_selector)):
        raise TypeError('aggregate() parameter result_selector={0} is not callable'.format(repr(result_selector)))
    if (seed is default):
        try:
            return result_selector(fold(reducer, self))
        except TypeError as e:
            if ('empty sequence' in str(e)):
                raise ValueError('Cannot aggregate() empty sequence with no seed value')
    return result_selector(fold(reducer, self, seed))

Apply a function over a sequence to produce a single result.

Apply a binary function cumulatively to the elements of the source
sequence so as to reduce the iterable to a single value.

Note: This method uses immediate execution.

Args:
reducer: A binary function the first positional argument of which
is an accumulated value and the second is the update value from
the source sequence. The return value should be the new
accumulated value after the update value has been incorporated.

seed: An optional value used to initialise the accumulator before
iteration over the source sequence. If seed is omitted the
and the source sequence contains only one item, then that item
is returned.

result_selector: An optional unary function applied to the final
accumulator value to produce the result. If omitted, defaults
to the identity function.

Raises:
ValueError: If called on an empty sequence with no seed value.
TypeError: If reducer is not callable.
TypeError: If result_selector is not callable.


def get_video_formats(self):
    if not self._video_formats:
        self._video_formats = list(self._api(iterate=True).list(profileId=self.profile_id).execute())
    return self._video_formats

Fetches video formats from CM.

Returns:
The lists of video formats from CM.


def send_rpc_response(self, rpc_tag, result, response):

        if rpc_tag not in self.in_flight_rpcs:
            raise ArgumentError("In flight RPC could not be found, it may have timed out", rpc_tag=rpc_tag)

        del self.in_flight_rpcs[rpc_tag]

        response_message = {
            'response': response,
            'result': result
        }

        try:
            self.rpc_results.set(rpc_tag, response_message)
        except KeyError:
            self._logger.warning("RPC response came but no one was waiting: response=%s", response)

Send a response to an RPC.

Args:
rpc_tag (str): The exact string given in a previous call to send_rpc_command
result (str): The result of the operation.  The possible values of response are:
service_not_found, rpc_not_found, timeout, success, invalid_response,
invalid_arguments, execution_exception
response (bytes): The raw bytes that we should send back as a response.


def set_aws_clients(self, clients):

    if type(clients) is not dict:
      raise TypeError("clients must be a dict")
    self._aws_clients = clients

Stash a dictionary of AWS clients in the context object
Args:
clients: dictionary of clients


def CopyNoFail(src, root=None):

    if root is None:
        root = str(CFG["tmp_dir"])
    src_path = local.path(root) / src

    if src_path.exists():
        Copy(src_path, '.')
        return True
    return False

Just copy fName into the current working directory, if it exists.

No action is executed, if fName does not exist. No Hash is checked.

Args:
src: The filename we want to copy to '.'.
root: The optional source dir we should pull fName from. Defaults
to benchbuild.settings.CFG["tmpdir"].

Returns:
True, if we copied something.


def get_knowledge_base(project_id, knowledge_base_id):
    import dialogflow_v2beta1 as dialogflow
    client = dialogflow.KnowledgeBasesClient()
    knowledge_base_path = client.knowledge_base_path(project_id, knowledge_base_id)
    response = client.get_knowledge_base(knowledge_base_path)
    print('Got Knowledge Base:')
    print(' - Display Name: {}'.format(response.display_name))
    print(' - Knowledge ID: {}'.format(response.name))

Gets a specific Knowledge base.

Args:
project_id: The GCP project linked with the agent.
knowledge_base_id: Id of the Knowledge base.


def get_pipeline_options(project: str, job_name: str, mode: str, num_workers: int=cfg.NUM_WORKERS, streaming: bool=True) -> PipelineOptions:
    job_name = f'{job_name}-{datetime.now().strftime('%Y%m%d%H%M%S')}'
    staging_bucket = f'gs:
    dataflow_options = {'runner': 'DirectRunner' if mode == 'local' else 'DataflowRunner', 'job_name': job_name, 'project': project, 'region': cfg.REGION, 'staging_location': f'{staging_bucket}/dflow-staging', 'temp_location': f'{staging_bucket}/dflow-temp', 'setup_file': './setup.py', 'streaming': streaming}
    if num_workers:
        dataflow_options.update({'num_workers': num_workers})
    return PipelineOptions(flags=[], **dataflow_options)

Function to retrieve the pipeline options.
Args:
project: GCP project to run on
mode: Indicator to run local, cloud or template
num_workers: Number of Workers for running the job parallely
max_num_workers: Maximum number of workers running the job parallely
Returns:
Dataflow pipeline options


def delete_group_member(self, grp_name, user):

        self.project_service.set_auth(self._token_project)
        self.project_service.delete_group_member(grp_name, user)

Delete the given user to the named group.

Both group and user must already exist for this to succeed.

Args:
name (string): Name of group.
user_name (string): User to delete from the group.

Raises:
requests.HTTPError on failure.


def save_saved_model(file_name, sess, input_tensor, output_tensor):
    builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(file_name)
    tensor_info_inputs = {'input': tf.compat.v1.saved_model.utils.build_tensor_info(input_tensor)}
    tensor_info_outputs = {'output': tf.compat.v1.saved_model.utils.build_tensor_info(output_tensor)}
    signature = tf.compat.v1.saved_model.signature_def_utils.build_signature_def(inputs=tensor_info_inputs, outputs=tensor_info_outputs, method_name=tf.compat.v1.saved_model.signature_constants.PREDICT_METHOD_NAME)
    builder.add_meta_graph_and_variables(sess, [tf.compat.v1.saved_model.tag_constants.SERVING], signature_def_map={tf.compat.v1.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature})
    builder.save()

Writes a SavedModel out to disk.

Args:
file_name: Where to save the file.
sess: TensorFlow session containing the graph.
input_tensor: Tensor object defining the input's properties.
output_tensor: Tensor object defining the output's properties.


def _CheckKeyPath(self, registry_key, search_depth):

    if self._key_path_segments is None:
      return False

    if search_depth < 0 or search_depth > self._number_of_key_path_segments:
      return False

    if search_depth == 0:
      segment_name = ''
    else:
      segment_name = self._key_path_segments[search_depth - 1]

      if self._is_regex:
        if isinstance(segment_name, py2to3.STRING_TYPES):

          flags = re.DOTALL | re.IGNORECASE | re.UNICODE

          try:
            segment_name = r'^{0:s}$'.format(segment_name)
            segment_name = re.compile(segment_name, flags=flags)
          except sre_constants.error:

            return False

          self._key_path_segments[search_depth - 1] = segment_name

      else:
        segment_name = segment_name.lower()
        self._key_path_segments[search_depth - 1] = segment_name

    if search_depth > 0:
      if self._is_regex:

        if not segment_name.match(registry_key.name):
          return False

      elif segment_name != registry_key.name.lower():
        return False

    return True

Checks the key path find specification.

Args:
registry_key (WinRegistryKey): Windows Registry key.
search_depth (int): number of key path segments to compare.

Returns:
bool: True if the Windows Registry key matches the find specification,
False if not.


def get_unit(self, name):
    return Unit(client=self, data=self._single_request('Units.Get', unitName=name))

Retreive a specifi unit from the fleet cluster by name

Args:
name (str): If specified, only this unit name is returned

Returns:
Unit: The unit identified by ``name`` in the fleet cluster

Raises:
fleet.v1.errors.APIError: Fleet returned a response code >= 400


def get_pending_component_servicing():
    key = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending'
    if __utils__['reg.key_exists']('HKLM', key):
        log.debug('Key exists: %s', key)
        return True
    else:
        log.debug('Key does not exist: %s', key)
    return False

Determine whether there are pending Component Based Servicing tasks that
require a reboot.

.. versionadded:: 2016.11.0

Returns:
bool: ``True`` if there are pending Component Based Servicing tasks,
otherwise ``False``

CLI Example:

.. code-block:: bash

salt '*' system.get_pending_component_servicing


def get_video_features(self, pixel_values_videos: torch.FloatTensor, video_grid_thw: Optional[torch.LongTensor]=None):
    pixel_values_videos = pixel_values_videos.type(self.visual.dtype)
    video_embeds = self.visual(pixel_values_videos, grid_thw=video_grid_thw)
    split_sizes = (video_grid_thw.prod(-1)
    video_embeds = torch.split(video_embeds, split_sizes)
    return video_embeds

Encodes videos into continuous embeddings that can be forwarded to the language model.

Args:
pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
The tensors corresponding to the input videos.
video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
The temporal, height and width of feature shape of each video in LLM.


def _batch_transpose(mat):
    n = distribution_util.prefer_static_rank(mat)
    perm = tf.range(n)
    perm = tf.concat([perm[:(- 2)], [perm[(- 1)], perm[(- 2)]]], axis=0)
    return tf.transpose(a=mat, perm=perm)

Transpose a possibly batched matrix.

Args:
mat: A `tf.Tensor` of shape `[..., n, m]`.

Returns:
A tensor of shape `[..., m, n]` with matching batch dimensions.


class BaseModelOutputWithIntermediateActivations(ModelOutput):
    last_hidden_states: Optional[torch.FloatTensor] = None
    intermediate_activations: Optional[Tuple[torch.FloatTensor, ...]] = None

Base class for model's outputs that also contains intermediate activations that can be used at later stages. Useful
in the context of Vision models.:

Args:
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
Sequence of hidden-states at the output of the last layer of the model.
intermediate_activations (`tuple(torch.FloatTensor)`, *optional*):
Intermediate activations that can be used to compute hidden states of the model at various layers.


def image_feature_engineering(features, feature_tensors_dict):

  engineered_features = {}
  for name, feature_tensor in six.iteritems(feature_tensors_dict):
    if name in features and features[name]['transform'] == IMAGE_TRANSFORM:
      with tf.name_scope(name, 'Wx_plus_b'):
        hidden = tf.contrib.layers.fully_connected(
            feature_tensor,
            IMAGE_HIDDEN_TENSOR_SIZE)
        engineered_features[name] = hidden
    else:
      engineered_features[name] = feature_tensor
  return engineered_features

Add a hidden layer on image features.

Args:
features: features dict
feature_tensors_dict: dict of feature-name: tensor


def AddArguments(cls, argument_group):

    argument_group.add_argument(
        '--analysis', metavar='PLUGIN_LIST', dest='analysis_plugins',
        default='', action='store', type=str, help=(
            'A comma separated list of analysis plugin names to be loaded '
            'or "--analysis list" to see a list of available plugins.'))

    arguments = sys.argv[1:]
    argument_index = 0

    if '--analysis' in arguments:
      argument_index = arguments.index('--analysis') + 1

    if 0 < argument_index < len(arguments):
      names = [name.strip() for name in arguments[argument_index].split(',')]
    else:
      names = None

    if names and names != ['list']:
      manager.ArgumentHelperManager.AddCommandLineArguments(
          argument_group, category='analysis', names=names)

Adds command line arguments to an argument group.

This function takes an argument parser or an argument group object and adds
to it all the command line arguments this helper supports.

Args:
argument_group (argparse._ArgumentGroup|argparse.ArgumentParser):
argparse group.


def from_concrete_functions(cls, funcs, trackable_obj=None):
    TFLiteConverterBase._set_original_model_type(conversion_metadata_fb.ModelType.TF_CONCRETE_FUNCTIONS)
    if trackable_obj is None:
        logging.warning('Please consider providing the trackable_obj argument in the from_concrete_functions. Providing without the trackable_obj argument is deprecated and it will use the deprecated conversion path.')
    for func in funcs:
        if not isinstance(func, _function.ConcreteFunction):
            message = 'This function takes in a list of ConcreteFunction.'
            if isinstance(func, _def_function.Function):
                message += ' To get the ConcreteFunction from a Function, call get_concrete_function.'
            raise ValueError(message)
    return cls(funcs, trackable_obj)

Creates a TFLiteConverter object from ConcreteFunctions.

Args:
funcs: List of TensorFlow ConcreteFunctions. The list should not contain
duplicate elements. Currently converter can only convert a single
ConcreteFunction. Converting multiple functions is under development.
trackable_obj:   An `AutoTrackable` object (typically `tf.module`)
associated with `funcs`. A reference to this object needs to be
maintained so that Variables do not get garbage collected since
functions have a weak reference to Variables.

Returns:
TFLiteConverter object.

Raises:
Invalid input type.


def bot(self, id):
    json = self.skype.conn('GET', '{0}/agents'.format(SkypeConnection.API_BOT), params={'agentId': id}, auth=SkypeConnection.Auth.SkypeToken).json().get('agentDescriptions', [])
    return (self.merge(SkypeBotUser.fromRaw(self.skype, json[0])) if json else None)

Retrieve a single bot.

Args:
id (str): UUID or username of the bot

Returns:
SkypeBotUser: resulting bot user object


def disable_inheritance(path, objectType, copy=True):
    dc = daclConstants()
    objectType = dc.getObjectTypeBit(objectType)
    path = dc.processPath(path, objectType)
    return _set_dacl_inheritance(path, objectType, False, copy, None)

Disable inheritance on an object

Args:
path: The path to the object
objectType: The type of object (FILE, DIRECTORY, REGISTRY)
copy: True will copy the Inherited ACEs to the DACL before disabling inheritance

Returns (dict): A dictionary containing the results

CLI Example:

.. code-block:: bash

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


def update_clinvar_submission_status(self, user_id, submission_id, status):
    LOG.info('closing clinvar submission "%s"', submission_id)
    if (status == 'open'):
        self.clinvar_submission_collection.update_many({'user_id': user_id}, {'$set': {'status': 'closed', 'updated_at': datetime.now()}})
    updated_submission = self.clinvar_submission_collection.find_one_and_update({'_id': ObjectId(submission_id)}, {'$set': {'status': status, 'updated_at': datetime.now()}}, return_document=pymongo.ReturnDocument.AFTER)
    return updated_submission

Set a clinvar submission ID to 'closed'

Args:
submission_id(str): the ID of the clinvar submission to close

Return
updated_submission(obj): the submission object with a 'closed' status


def list_permissions(self, group_name=None, resource=None):

        return self.service.list_permissions(group_name, resource,
                                             self.url_prefix, self.auth, self.session, self.session_send_opts)

List permission sets associated filtering by group and/or resource.

Args:
group_name (string): Name of group.
resource (intern.resource.boss.Resource): Identifies which data model object to operate on.

Returns:
(list): List of permissions.

Raises:
requests.HTTPError on failure.


def StartTiming(self, profile_name):
    if (profile_name not in self._profile_measurements):
        self._profile_measurements[profile_name] = CPUTimeMeasurement()
    self._profile_measurements[profile_name].SampleStart()

Starts timing CPU time.

Args:
profile_name (str): name of the profile to sample.


def get_completed_task(self, task, timeout=(- 1)):
    self.__wait_task_completion(task, timeout)
    return self.get(task)

Waits until the task is completed and returns the task resource.

Args:
task: TaskResource
timeout: Timeout in seconds

Returns:
dict: TaskResource


def set_max_epochs(max_epochs):
    global _MAX_EPOCHS
    _MAX_EPOCHS = max_epochs

Limit the maximum number of epochs for any call to fit.

This will cap the number of epochs for any training run using `model.fit()`.
This is purely for debugging, and can also be set via the `KERAS_MAX_EPOCHS`
environment variable to quickly run a script without modifying its source.

Args:
max_epochs: The integer limit on the number of epochs or `None`. If
`None`, no limit is applied.


def get_tld(url):
    if (url not in URLHelper.__cache):
        URLHelper.__cache[url] = urlparse(url)
    parts = URLHelper.__cache[url].netloc.split('.')
    if (len(parts) == 1):
        return ''
    else:
        return parts[(- 1)]

Get the tld of the given URL.

Args:
url (str): The URL to get the tld from.

Returns:
str: The tld


def smart_cond(pred, true_fn=None, false_fn=None, name=None):
    if isinstance(pred, variables.Variable):
        return cond.cond(pred, true_fn=true_fn, false_fn=false_fn, name=name)
    return smart_module.smart_cond(pred, true_fn=true_fn, false_fn=false_fn, name=name)

Return either `true_fn()` if predicate `pred` is true else `false_fn()`.

If `pred` is a bool or has a constant value, we return either `true_fn()`
or `false_fn()`, otherwise we use `tf.cond` to dynamically route to both.

Args:
pred: A scalar determining whether to return the result of `true_fn` or
`false_fn`.
true_fn: The callable to be performed if pred is true.
false_fn: The callable to be performed if pred is false.
name: Optional name prefix when using `tf.cond`.

Returns:
Tensors returned by the call to either `true_fn` or `false_fn`.

Raises:
TypeError: If `true_fn` or `false_fn` is not callable.


def post(self, path, params=None, timeout=None, event_timeout=None):
    future = self.post_async(path, params)
    self.wait_all_futures(future, timeout=timeout, event_timeout=event_timeout)
    return future.result()

Synchronously calls a method

Args:
path (list): The path to post to
params (dict): parameters for the call
timeout (float): time in seconds to wait for responses, wait
forever if None
event_timeout: maximum time in seconds to wait between each response
event, wait forever if None

Returns:
the result from 'method'


def parse_log(file_path):

    if not os.path.isfile(file_path):
        return elements.error("Output Log", "Could not open file: " + file_path.split(os.sep)[-1])

    headers = ["Converged Iterations",
               "Avg. Iterations to Converge",
               "Processor Count",
               "Dycore Type"]

    with open(file_path, 'r') as f:
        dycore_types = {"0": "Glide",
                        "1": "Glam",
                        "2": "Glissade",
                        "3": "Albany_felix",
                        "4": "BISICLES"}
        curr_step = 0
        proc_count = 0
        iter_number = 0
        converged_iters = []
        iters_to_converge = []
        for line in f:
            split = line.split()
            if ('CISM dycore type' in line):
                if line.split()[-1] == '=':
                    dycore_type = dycore_types[next(f).strip()]
                else:
                    dycore_type = dycore_types[line.split()[-1]]
            elif ('total procs' in line):
                proc_count += int(line.split()[-1])
            elif ('Nonlinear Solver Step' in line):
                curr_step = int(line.split()[4])
            elif ('Compute ice velocities, time = ' in line):
                converged_iters.append(curr_step)
                curr_step = float(line.split()[-1])
            elif ('"SOLVE_STATUS_CONVERGED"' in line):
                split = line.split()
                iters_to_converge.append(int(split[split.index('"SOLVE_STATUS_CONVERGED"') + 2]))
            elif ("Compute dH/dt" in line):
                iters_to_converge.append(int(iter_number))
            elif len(split) > 0 and split[0].isdigit():
                iter_number = split[0]
        if iters_to_converge == []:
            iters_to_converge.append(int(iter_number))
    data = {
        "Dycore Type": dycore_type,
        "Processor Count": proc_count,
        "Converged Iterations": len(converged_iters),
        "Avg. Iterations to Converge": np.mean(iters_to_converge)
    }
    return elements.table("Output Log", headers, data)

Parse a CISM output log and extract some information.

Args:
file_path: absolute path to the log file

Return:
A dictionary created by the elements object corresponding to
the results of the bit for bit testing


def __init__(self, url, urlSchemes=None):

        self._urlApi = url
        self._urlSchemes = {}
        self._initRequestHeaders()
        self._urllib = urllib2

        if urlSchemes is not None:
            for urlScheme in urlSchemes:
                self.addUrlScheme(urlScheme)

        self._implicitFormat = self._urlApi.find('{format}') != -1

Create a new OEmbedEndpoint object.

Args:
url: The url of a provider API (API endpoint).
urlSchemes: A list of URL schemes for this endpoint.


def find_write(driver, elem_path, write_str, clear_first=True, send_enter=False, by=CSS, timeout=TIMEOUT, poll_frequency=0.5):
    elem = find_element(driver, elem_path=elem_path, by=by, timeout=timeout, poll_frequency=poll_frequency)
    if clear_first:
        elem.clear()
    elem.send_keys(write_str)
    if send_enter:
        elem.send_keys(Keys.ENTER)
    return elem

Find a writable element and write to it

find_write locates a writable element on the page, waiting
for up to timeout seconds. Once found, it writes the string
to it.

Args:
driver (selenium webdriver or element): A driver or element
elem_path (str): String used to located the element
write_str (str): String to write
clear_first (bool): Clear the contents before writing (default True)
send_enter (bool): Send a keyboard ENTER after writing string
by (selenium By): Selenium By reference
timeout (int): Selenium Wait timeout, in seconds
poll_frequency (float): Selenium Wait polling frequency, in seconds

Returns:
element: Selenium element

Raises:
TimeoutException: Raised when target element isn't located


def raster_statistics(raster_file):

        ds = gdal_Open(raster_file)
        band = ds.GetRasterBand(1)
        minv, maxv, meanv, std = band.ComputeStatistics(False)
        return minv, maxv, meanv, std

Get basic statistics of raster data.

Args:
raster_file: raster file path.

Returns:
min, max, mean, std.


def _expand_variables(input_str, cmake_vars):

    def replace(match):
        if match.group(1) in cmake_vars:
            return cmake_vars[match.group(1)]
        return ''
    return _CMAKE_ATVAR_REGEX.sub(replace, _CMAKE_VAR_REGEX.sub(replace, input_str))

Expands ${VARIABLE}s and @VARIABLE@s in 'input_str', using dictionary 'cmake_vars'.

Args:
input_str: the string containing ${VARIABLE} or @VARIABLE@ expressions to expand.
cmake_vars: a dictionary mapping variable names to their values.

Returns:
The expanded string.


def assemble_data(data_dfs, concat_direction):
    if (concat_direction == 'horiz'):
        all_data_df = pd.concat(data_dfs, axis=1)
        n_cols = all_data_df.shape[1]
        logger.debug('all_data_df.shape[1]: {}'.format(n_cols))
        n_cols_cumulative = sum([df.shape[1] for df in data_dfs])
        assert (n_cols == n_cols_cumulative)
    elif (concat_direction == 'vert'):
        all_data_df = pd.concat(data_dfs, axis=0)
        n_rows = all_data_df.shape[0]
        logger.debug('all_data_df.shape[0]: {}'.format(n_rows))
        n_rows_cumulative = sum([df.shape[0] for df in data_dfs])
        assert (n_rows == n_rows_cumulative)
    all_data_df_sorted = all_data_df.sort_index(axis=0).sort_index(axis=1)
    return all_data_df_sorted

Assemble the data dfs together. Both indices are sorted.

Args:
data_dfs (list of pandas dfs)
concat_direction (string): 'horiz' or 'vert'

Returns:
all_data_df_sorted (pandas df)


def MakeCACert(private_key, common_name=u'grr', issuer_cn=u'grr_test', issuer_c=u'US'):
    public_key = private_key.GetPublicKey()
    builder = x509.CertificateBuilder()
    issuer = x509.Name([x509.NameAttribute(oid.NameOID.COMMON_NAME, issuer_cn), x509.NameAttribute(oid.NameOID.COUNTRY_NAME, issuer_c)])
    subject = x509.Name([x509.NameAttribute(oid.NameOID.COMMON_NAME, common_name)])
    builder = builder.subject_name(subject)
    builder = builder.issuer_name(issuer)
    valid_from = (rdfvalue.RDFDatetime.Now() - rdfvalue.Duration('1d'))
    valid_until = (rdfvalue.RDFDatetime.Now() + rdfvalue.Duration('3650d'))
    builder = builder.not_valid_before(valid_from.AsDatetime())
    builder = builder.not_valid_after(valid_until.AsDatetime())
    builder = builder.serial_number(1)
    builder = builder.public_key(public_key.GetRawPublicKey())
    builder = builder.add_extension(x509.BasicConstraints(ca=True, path_length=None), critical=True)
    builder = builder.add_extension(x509.SubjectKeyIdentifier.from_public_key(public_key.GetRawPublicKey()), critical=False)
    certificate = builder.sign(private_key=private_key.GetRawPrivateKey(), algorithm=hashes.SHA256(), backend=openssl.backend)
    return rdf_crypto.RDFX509Cert(certificate)

Generate a CA certificate.

Args:
private_key: The private key to use.
common_name: Name for cert.
issuer_cn: Name for issuer.
issuer_c: Country for issuer.

Returns:
The certificate.


def load_repo_addons(_globals):

    repos_dir = os.path.expanduser('~/.fabsetup-addon-repos')
    if os.path.isdir(repos_dir):
        basedir, repos, _ = next(os.walk(repos_dir))
        for repo_dir in [os.path.join(basedir, repo)
                         for repo in repos

                         if '.' not in repo]:
            sys.path.append(repo_dir)
            package_name, username = package_username(repo_dir.split('/')[-1])
            load_addon(username, package_name, _globals)

Load all fabsetup addons which are stored under ~/.fabsetup-addon-repos
as git repositories.

Args:
_globals(dict): the globals() namespace of the fabric script.

Return: None


def inner(*args):
    haspoly = sum([isinstance(arg, Poly) for arg in args])
    if (not haspoly):
        return numpy.sum(numpy.prod(args, 0), 0)
    out = args[0]
    for arg in args[1:]:
        out = (out * arg)
    return sum(out)

Inner product of a polynomial set.

Args:
args (chaospy.poly.base.Poly):
The polynomials to perform inner product on.

Returns:
(chaospy.poly.base.Poly):
Resulting polynomial.

Examples:
>>> x,y = cp.variable(2)
>>> P = cp.Poly([x-1, y])
>>> Q = cp.Poly([x+1, x*y])
>>> print(cp.inner(P, Q))
q0^2+q0q1^2-1
>>> x = numpy.arange(4)
>>> print(cp.inner(x, x))
14


def create_cloudtrail(self, region):

        ct = self.session.client('cloudtrail', region_name=region)

        self.create_sns_topic(region)

        ct.create_trail(
            Name=self.trail_name,
            S3BucketName=self.bucket_name,
            S3KeyPrefix=self.account.account_name,
            IsMultiRegionTrail=True,
            IncludeGlobalServiceEvents=True,
            SnsTopicName=self.topic_name
        )
        self.subscribe_sns_topic_to_sqs(region)

        auditlog(
            event='cloudtrail.create_cloudtrail',
            actor=self.ns,
            data={
                'account': self.account.account_name,
                'region': region
            }
        )
        self.log.info('Created CloudTrail for {} in {} ({})'.format(self.account, region, self.bucket_name))

Creates a new CloudTrail Trail

Args:
region (str): Name of the AWS region

Returns:
`None`


def expect_equal(first, second, msg=None, extras=None):
    try:
        asserts.assert_equal(first, second, msg, extras)
    except signals.TestSignal as e:
        logging.exception('Expected %s equals to %s, but they are not.', first, second)
        recorder.add_error(e)

Expects the equality of objects, otherwise fail the test.

If the expectation is not met, the test is marked as fail after its
execution finishes.

Error message is "first != second" by default. Additional explanation can
be supplied in the message.

Args:
first: The first object to compare.
second: The second object to compare.
msg: A string that adds additional info about the failure.
extras: An optional field for extra information to be included in test
result.


def __init__(self, start, end, source_bundles):
    super().__init__()
    self._start = start
    self._end = end
    self._source_bundles = source_bundles
    self._lock = threading.RLock()
    self._range_trackers = [None] * len(source_bundles)
    self._claimed_source_ix = self._start[0]
    last = end[0] if end[1] is None else end[0] + 1
    self._cumulative_weights = [0] * start[0] + self._compute_cumulative_weights(source_bundles[start[0]:last]) + [1] * (len(source_bundles) - last - start[0])

Initializes ``ConcatRangeTracker``

Args:
start: start position, a tuple of (source_index, source_position)
end: end position, a tuple of (source_index, source_position)
source_bundles: the list of source bundles in the ConcatSource


def write_supercells_with_displacements(supercell, cells_with_disps, filename="geo.gen"):

    write_dftbp(filename + "S", supercell)

    for ii in range(len(cells_with_disps)):
        write_dftbp(filename + "S-{:03d}".format(ii+1), cells_with_disps[ii])

Writes perfect supercell and supercells with displacements

Args:
supercell: perfect supercell
cells_with_disps: supercells with displaced atoms
filename: root-filename


def __init__(self, log_dir):

    if not gfile.isdir(log_dir):
      gfile.makedirs(log_dir)

    self._event_writer = EventFileWriter(log_dir, 10, 120, None)
    self._step = 0
    self._closed = False

Create a new SummaryWriter.

Args:
log_dir: path to record tfevents files in.


def __init__(self, input_energy: energy.BitstringEnergy, num_expectation_samples: int, initial_seed: Union[None, tf.Tensor]=None, name: Union[None, str]=None):
    super().__init__(input_energy, num_expectation_samples, initial_seed, name)
    self._all_bitstrings = tf.constant(list(itertools.product([0, 1], repeat=input_energy.num_bits)), dtype=tf.int8)
    self._logits_variable = tf.Variable(-input_energy(self.all_bitstrings), trainable=False)
    self._distribution = tfd.Categorical(logits=self._logits_variable)

Initializes an AnalyticEnergyInference.

Internally, this class saves all possible bitstrings as a tensor, whose
energies are calculated relative to an input energy function for sampling
and other inference tasks.

Args:
input_energy: The parameterized energy function which defines this
distribution via the equations of an energy based model.  This class
assumes that all parameters of `energy` are `tf.Variable`s and that
they are all returned by `energy.variables`.
num_expectation_samples: Number of samples to draw and use for estimating
the expectation value.
initial_seed: PRNG seed; see tfp.random.sanitize_seed for details. This
seed will be used in the `sample` method.  If None, the seed is updated
after every inference call.  Otherwise, the seed is fixed.
name: Optional name for the model.


def _build_toy_dataset(n: int, data_prefix='', data2_is_categorical_integer=False, num_indexes: int=10) -> tp.EventSet:
    np.random.seed(0)
    index_values = list(range(int(num_indexes)))
    timestamps = np.sort(np.random.randn(n) * n)
    index_1 = np.random.choice(index_values, n)
    index_2 = np.random.choice(index_values, n)
    data_1 = np.random.randn(n)
    if data2_is_categorical_integer:
        data_2 = np.random.choice(list(range(int(10))), n)
    else:
        data_2 = np.random.randn(n)
    return tp.from_pandas(pd.DataFrame({'timestamp': timestamps, 'index_1': index_1, 'index_2': index_2, data_prefix + 'data_1': data_1, data_prefix + 'data_2': data_2}), indexes=['index_1', 'index_2'])

Builds a toy dataset with two features.

Args:
n: Number of timestamps.
data_prefix: Optional prefix in the feature names.
data2_is_categorical_integer: If true, the second feature is
categorical. If false (default), the second feature is numerical.

Returns:
An EventSet containing the toy dataset.


def _refine_candidate(self, width, height):
    packer = newPacker(PackingMode.Offline, PackingBin.BFF, pack_algo=self._pack_algo, sort_algo=SORT_LSIDE, rotation=self._rotation)
    packer.add_bin(width, height)
    for r in self._rectangles:
        packer.add_rect(*r)
    packer.pack()
    if (len(packer[0]) != len(self._rectangles)):
        return None
    new_height = max(packer[0], key=(lambda x: x.top)).top
    return (width, new_height, packer)

Use bottom-left packing algorithm to find a lower height for the
container.

Arguments:
width
height

Returns:
tuple (width, height, PackingAlgorithm):


def variables(self):
    return self.weights

Returns the list of all layer variables/weights.

Alias of `self.weights`.

Note: This will not track the weights of nested `tf.Modules` that are not
themselves Keras layers.

Returns:
A list of variables.


def market_close(self, session, mins) -> Session:

        if session not in self.exch: return SessNA
        end_time = self.exch[session][-1]
        return Session(shift_time(end_time, -int(mins) + 1), end_time)

Time intervals for market close

Args:
session: [allday, day, am, pm, night]
mins: mintues before close

Returns:
Session of start_time and end_time


def Verify(self, completely=False):

        res = super(Block, self).Verify()
        if not res:
            return False

        from neo.Blockchain import GetBlockchain, GetConsensusAddress

        if self.Transactions[0].Type != TransactionType.MinerTransaction:
            return False
        for tx in self.Transactions[1:]:
            if tx.Type == TransactionType.MinerTransaction:
                return False

        if completely:
            bc = GetBlockchain()

            if self.NextConsensus != GetConsensusAddress(bc.GetValidators(self.Transactions).ToArray()):
                return False

            for tx in self.Transactions:
                if not tx.Verify():
                    pass
            logger.error("Blocks cannot be fully validated at this moment.  please pass completely=False")
            raise NotImplementedError()

        return True

Verify the integrity of the block.

Args:
completely: (Not functional at this time).

Returns:
bool: True if valid. False otherwise.


def DecodeMessages(self, response_comms):

    cipher_verified = False
    try:
      cipher = self.encrypted_cipher_cache.Get(response_comms.encrypted_cipher)
      stats_collector_instance.Get().IncrementCounter(
          "grr_encrypted_cipher_cache", fields=["hits"])

      cipher.VerifyReceivedHMAC(response_comms)
      cipher_verified = True

      source = cipher.GetSource()
      remote_public_key = self._GetRemotePublicKey(source)
    except KeyError:
      stats_collector_instance.Get().IncrementCounter(
          "grr_encrypted_cipher_cache", fields=["misses"])
      cipher = ReceivedCipher(response_comms, self.private_key)

      source = cipher.GetSource()
      try:
        remote_public_key = self._GetRemotePublicKey(source)
        if cipher.VerifyCipherSignature(remote_public_key):

          self.encrypted_cipher_cache.Put(response_comms.encrypted_cipher,
                                          cipher)
          cipher_verified = True

      except UnknownClientCertError:

        remote_public_key = None

    plain = cipher.Decrypt(response_comms.encrypted, response_comms.packet_iv)
    try:
      packed_message_list = rdf_flows.PackedMessageList.FromSerializedString(
          plain)
    except rdfvalue.DecodeError as e:
      raise DecryptionError(e)

    message_list = self.DecompressMessageList(packed_message_list)

    auth_state = self.VerifyMessageSignature(
        response_comms,
        packed_message_list,
        cipher,
        cipher_verified,
        response_comms.api_version,
        remote_public_key)

    for msg in message_list.job:
      msg.auth_state = auth_state
      msg.source = cipher.cipher_metadata.source

    return (message_list.job, cipher.cipher_metadata.source,
            packed_message_list.timestamp)

Extract and verify server message.

Args:
response_comms: A ClientCommunication rdfvalue

Returns:
list of messages and the CN where they came from.

Raises:
DecryptionError: If the message failed to decrypt properly.


def check_origin(self, origin):
    from ..util import check_whitelist
    parsed_origin = urlparse(origin)
    origin_host = parsed_origin.netloc.lower()
    allowed_hosts = self.application.websocket_origins
    if settings.allowed_ws_origin():
        allowed_hosts = set(settings.allowed_ws_origin())
    allowed = check_whitelist(origin_host, allowed_hosts)
    if allowed:
        return True
    else:
        log.error("Refusing websocket connection from Origin '%s';                       use --allow-websocket-origin=%s or set BOKEH_ALLOW_WS_ORIGIN=%s to permit this; currently we allow origins %r", origin, origin_host, origin_host, allowed_hosts)
        return False

Implement a check_origin policy for Tornado to call.

The supplied origin will be compared to the Bokeh server whitelist. If the
origin is not allow, an error will be logged and ``False`` will be returned.

Args:
origin (str) :
The URL of the connection origin

Returns:
bool, True if the connection is allowed, False otherwise


def replace_first(pcoll, regex, replacement):
    regex = Regex._regex_compile(regex)
    return pcoll | Map(lambda elem: regex.sub(replacement, elem, 1))

Returns the matches if a portion of the line matches the regex and replaces
the first match with the replacement string.

Args:
regex: the regular expression string or (re.compile) pattern.
replacement: the string to be substituted for each match.


def begin_run_group(project):
    from benchbuild.utils.db import create_run_group
    from datetime import datetime
    (group, session) = create_run_group(project)
    group.begin = datetime.now()
    group.status = 'running'
    session.commit()
    return (group, session)

Begin a run_group in the database.

A run_group groups a set of runs for a given project. This models a series
of runs that form a complete binary runtime test.

Args:
project: The project we begin a new run_group for.

Returns:
``(group, session)`` where group is the created group in the
database and session is the database session this group lives in.


def send(self, stream=False):

        try:
            response = self.session.request(
                self._http_method,
                self._url,
                auth=self._basic_auth,
                data=self._body,
                files=self._files,
                headers=self._headers,
                params=self._payload,
                stream=stream,
                timeout=self._timeout,
            )
        except Exception as e:
            err = 'Failed making HTTP request ({}).'.format(e)
            raise RuntimeError(err)

        self.tcex.log.info(u'Status Code: {}'.format(response.status_code))
        return response

Send the HTTP request via Python Requests modules.

This method will send the request to the remote endpoint.  It will try to handle
temporary communications issues by retrying the request automatically.

Args:
stream (bool): Boolean to enable stream download.

Returns:
Requests.Response: The Request response


def on_predict_end(self, logs=None):
    logs = self._process_logs(logs)
    for callback in self.callbacks:
        callback.on_predict_end(logs)

Calls the `on_predict_end` methods of its callbacks.

Args:
logs: Dict. Currently no data is passed to this argument for this method
but that may change in the future.