def run_step(self, rewriter):

        assert rewriter, ("FileRewriter instance required to run "
                          "FileInRewriterStep.")
        rewriter.files_in_to_out(in_path=self.path_in, out_path=self.path_out)

Do the file in to out rewrite.

Doesn't do anything more crazy than call files_in_to_out on the
rewriter.

Args:
rewriter: pypyr.filesystem.FileRewriter instance.


def unify(t1, t2):

    a = prune(t1)
    b = prune(t2)
    if isinstance(a, TypeVariable):
        if a != b:
            if occurs_in_type(a, b):
                raise InferenceError("recursive unification")
            a.instance = b
    elif isinstance(b, TypeVariable):
        unify(b, a)
    elif isinstance(a, TypeOperator) and a.name == 'any':
            return
    elif isinstance(b, TypeOperator) and b.name == 'any':
            return
    elif isinstance(a, TypeOperator) and isinstance(b, TypeOperator):
        if len(a.types) != len(b.types):
            raise InferenceError("Type length differ")
        else:
            if a.name != b.name:
                raise InferenceError("Type name differ")
        try:
            for p, q in zip(a.types, b.types):
                unify(p, q)
        except InferenceError:
            raise
    elif isinstance(a, MultiType) and isinstance(b, MultiType):
        if len(a.types) != len(b.types):
            raise InferenceError("Type lenght differ")
        for p, q in zip(a.types, b.types):
            unify(p, q)
    elif isinstance(b, MultiType):
        return unify(b, a)
    elif isinstance(a, MultiType):
        types = []
        for t in a.types:
            try:
                t_clone = fresh(t, {})
                b_clone = fresh(b, {})
                unify(t_clone, b_clone)
                types.append(t)
            except InferenceError:
                pass
        if types:
            if len(types) == 1:
                unify(clone(types[0]), b)
            else:

                def try_unify(t, ts):
                    if isinstance(t, TypeVariable):
                        return
                    if any(isinstance(tp, TypeVariable) for tp in ts):
                        return
                    if any(len(tp.types) != len(t.types) for tp in ts):
                        return
                    for i, tt in enumerate(t.types):
                        its = [prune(tp.types[i]) for tp in ts]
                        if any(isinstance(it, TypeVariable) for it in its):
                            continue
                        it0 = its[0]
                        it0ntypes = len(it0.types)
                        if all(((it.name == it0.name) and
                                (len(it.types) == it0ntypes))
                               for it in its):
                            ntypes = [TypeVariable() for _ in range(it0ntypes)]
                            new_tt = TypeOperator(it0.name, ntypes)
                            new_tt.__class__ = it0.__class__
                            unify(tt, new_tt)
                            try_unify(prune(tt), [prune(it) for it in its])
                try_unify(b, types)
        else:
            raise InferenceError("No overload")
    else:
        raise RuntimeError("Not unified {} and {}".format(type(a), type(b)))

Unify the two types t1 and t2.

Makes the types t1 and t2 the same.

Args:
t1: The first type to be made equivalent
t2: The second type to be be equivalent

Returns:
None

Raises:
InferenceError: Raised if the types cannot be unified.


def parse_sampleinfo(data: dict) -> dict:
    genome_build = data['human_genome_build']
    genome_build_str = f"{genome_build['source']}{genome_build['version']}"
    if ('svdb' in data['program']):
        svdb_outpath = f"{data['program']['svdb']['path']}"
    else:
        svdb_outpath = ''
    outdata = {'date': data['analysis_date'], 'family': data['family'], 'genome_build': genome_build_str, 'rank_model_version': data['program']['genmod']['rank_model']['version'], 'is_finished': (True if (data['analysisrunstatus'] == 'finished') else False), 'pedigree_path': data['pedigree_minimal'], 'peddy': {'ped': (data['program']['peddy']['peddy']['path'] if ('peddy' in data['program']) else None), 'ped_check': (data['program']['peddy']['ped_check']['path'] if ('peddy' in data['program']) else None), 'sex_check': (data['program']['peddy']['sex_check']['path'] if ('peddy' in data['program']) else None)}, 'qcmetrics_path': data['program']['qccollect']['path'], 'samples': [], 'snv': {'bcf': data['most_complete_bcf']['path'], 'clinical_vcf': data['vcf_binary_file']['clinical']['path'], 'gbcf': data['gbcf_file']['path'], 'research_vcf': data['vcf_binary_file']['research']['path']}, 'svdb_outpath': svdb_outpath, 'sv': {'bcf': data.get('sv_bcf_file', {}).get('path'), 'clinical_vcf': (data['sv_vcf_binary_file']['clinical']['path'] if ('sv_vcf_binary_file' in data) else None), 'merged': svdb_outpath, 'research_vcf': (data['sv_vcf_binary_file']['research']['path'] if ('sv_vcf_binary_file' in data) else None)}, 'version': data['mip_version']}
    for (sample_id, sample_data) in data['sample'].items():
        sample = {'id': sample_id, 'bam': sample_data['most_complete_bam']['path'], 'sambamba': list(sample_data['program']['sambamba_depth'].values())[0]['path'], 'sex': sample_data['sex'], 'subsample_mt': (list(sample_data['program']['samtools_subsample_mt'].values())[0]['path'] if ('samtools_subsample_mt' in sample_data['program']) else None), 'vcf2cytosure': list(sample_data['program']['vcf2cytosure'].values())[0]['path']}
        chanjo_sexcheck = list(sample_data['program']['chanjo_sexcheck'].values())[0]
        sample['chanjo_sexcheck'] = chanjo_sexcheck['path']
        outdata['samples'].append(sample)
    return outdata

Parse MIP sample info file.

Args:
data (dict): raw YAML input from MIP qc sample info file

Returns:
dict: parsed data


def add_individual(self, genotype):

        logger.debug("Adding genotype {0} to variant {1}".format(
            genotype, self['variant_id']))
        self['individuals'].append(genotype)

Add the information for a individual

This adds a genotype dict to variant['individuals']

Args:
genotype (dict): A genotype dictionary


def db_ws010c(self, value=None):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError('value {} need to be of type float '
                                 'for field `db_ws010c`'.format(value))

        self._db_ws010c = value

Corresponds to IDD Field `db_ws010c`
Mean coincident dry-bulb temperature to wind speed corresponding to 1.0% cumulative frequency for coldest month

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

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


def apply_with_summary(input_layer, operation, *op_args, **op_kwargs):

  return layers.apply_activation(input_layer.bookkeeper,
                                 input_layer.tensor,
                                 operation,
                                 activation_args=op_args,
                                 activation_kwargs=op_kwargs)

Applies the given operation to `input_layer` and create a summary.

Args:
input_layer: The input layer for this op.
operation: An operation that takes a tensor and the supplied args.
*op_args: Extra arguments for operation.
**op_kwargs: Keyword arguments for the operation.
Returns:
A new layer with operation applied.


def get_metric_group_definitions(self):
    group_names = self.properties.get('metric-groups', None)
    if (not group_names):
        group_names = self.manager.get_metric_group_definition_names()
    mg_defs = []
    for group_name in group_names:
        try:
            mg_def = self.manager.get_metric_group_definition(group_name)
            mg_defs.append(mg_def)
        except ValueError:
            pass
    return mg_defs

Get the faked metric group definitions for this context object
that are to be returned from its create operation.

If a 'metric-groups' property had been specified for this context,
only those faked metric group definitions of its manager object that
are in that list, are included in the result. Otherwise, all metric
group definitions of its manager are included in the result.

Returns:

iterable of :class:~zhmcclient.FakedMetricGroupDefinition`: The faked
metric group definitions, in the order they had been added.


def compress(string, mode=MODE_GENERIC, quality=11, lgwin=22, lgblock=0):
    compressor = Compressor(mode=mode, quality=quality, lgwin=lgwin, lgblock=lgblock)
    return (compressor.process(string) + compressor.finish())

Compress a byte string.

Args:
string (bytes): The input data.
mode (int, optional): The compression mode can be MODE_GENERIC (default),
MODE_TEXT (for UTF-8 format text input) or MODE_FONT (for WOFF 2.0).
quality (int, optional): Controls the compression-speed vs compression-
density tradeoff. The higher the quality, the slower the compression.
Range is 0 to 11. Defaults to 11.
lgwin (int, optional): Base 2 logarithm of the sliding window size. Range
is 10 to 24. Defaults to 22.
lgblock (int, optional): Base 2 logarithm of the maximum input block size.
Range is 16 to 24. If set to 0, the value will be set based on the
quality. Defaults to 0.

Returns:
The compressed byte string.

Raises:
brotli.error: If arguments are invalid, or compressor fails.


async def build(self, *, remote: str=None, fileobj: BinaryIO=None, path_dockerfile: str=None, tag: str=None, quiet: bool=False, nocache: bool=False, buildargs: Mapping=None, pull: bool=False, rm: bool=True, forcerm: bool=False, labels: Mapping=None, stream: bool=False, encoding: str=None) -> Mapping:
    local_context = None
    headers = {}
    params = {'t': tag, 'rm': rm, 'q': quiet, 'pull': pull, 'remote': remote, 'nocache': nocache, 'forcerm': forcerm, 'dockerfile': path_dockerfile}
    if ((remote is None) and (fileobj is None)):
        raise ValueError('You need to specify either remote or fileobj')
    if (fileobj and remote):
        raise ValueError('You cannot specify both fileobj and remote')
    if (fileobj and (not encoding)):
        raise ValueError('You need to specify an encoding')
    if ((remote is None) and (fileobj is None)):
        raise ValueError('Either remote or fileobj needs to be provided.')
    if fileobj:
        local_context = fileobj.read()
        headers['content-type'] = 'application/x-tar'
    if (fileobj and encoding):
        headers['Content-Encoding'] = encoding
    if buildargs:
        params.update({'buildargs': json.dumps(buildargs)})
    if labels:
        params.update({'labels': json.dumps(labels)})
    response = (await self.docker._query('build', 'POST', params=clean_map(params), headers=headers, data=local_context))
    return (await json_stream_result(response, stream=stream))

Build an image given a remote Dockerfile
or a file object with a Dockerfile inside

Args:
path_dockerfile: path within the build context to the Dockerfile
remote: a Git repository URI or HTTP/HTTPS context URI
quiet: suppress verbose build output
nocache: do not use the cache when building the image
rm: remove intermediate containers after a successful build
pull: downloads any updates to the FROM image in Dockerfiles
encoding: set `Content-Encoding` for the file object your send
forcerm: always remove intermediate containers, even upon failure
labels: arbitrary key/value labels to set on the image
fileobj: a tar archive compressed or not


def wait_for_endpoint(self, endpoint, poll=5):

        desc = _wait_until(lambda: _deploy_done(self.sagemaker_client, endpoint), poll)
        status = desc['EndpointStatus']

        if status != 'InService':
            reason = desc.get('FailureReason', None)
            raise ValueError('Error hosting endpoint {}: {} Reason: {}'.format(endpoint, status, reason))
        return desc

Wait for an Amazon SageMaker endpoint deployment to complete.

Args:
endpoint (str): Name of the ``Endpoint`` to wait for.
poll (int): Polling interval in seconds (default: 5).

Returns:
dict: Return value from the ``DescribeEndpoint`` API.


def search_address(self, address, filters=None, startDate=None, endDate=None, types=None):
    (lat, lng) = self.get_address_coords(address)
    return self.search_point(lat, lng, filters=filters, startDate=startDate, endDate=endDate, types=types)

Perform a catalog search over an address string

Args:
address: any address string
filters: Array of filters.  Optional.  Example:
[
"(sensorPlatformName = 'WORLDVIEW01' OR sensorPlatformName ='QUICKBIRD02')",
"cloudCover < 10",
"offNadirAngle < 10"
]
startDate: string.  Optional.  Example: "2004-01-01T00:00:00.000Z"
endDate: string.  Optional.  Example: "2004-01-01T00:00:00.000Z"
types: Array of types to search for.  Optional.  Example (and default):  ["Acquisition"]

Returns:
catalog search resultset


def process_remote_sources(raw_config, environment=None):

    config = yaml.safe_load(raw_config)
    if config and config.get('package_sources'):
        processor = SourceProcessor(
            sources=config['package_sources'],
            stacker_cache_dir=config.get('stacker_cache_dir')
        )
        processor.get_package_sources()
        if processor.configs_to_merge:
            for i in processor.configs_to_merge:
                logger.debug("Merging in remote config \"%s\"", i)
                remote_config = yaml.safe_load(open(i))
                config = merge_map(remote_config, config)

            if not environment:
                environment = {}
            return render(str(config), environment)

    return raw_config

Stage remote package sources and merge in remote configs.

Args:
raw_config (str): the raw stacker configuration string.
environment (dict, optional): any environment values that should be
passed to the config

Returns:
str: the raw stacker configuration string


def get_rms_dist(self, struct1, struct2):
    (struct1, struct2) = self._process_species([struct1, struct2])
    (struct1, struct2, fu, s1_supercell) = self._preprocess(struct1, struct2)
    match = self._match(struct1, struct2, fu, s1_supercell, use_rms=True, break_on_match=False)
    if (match is None):
        return None
    else:
        return (match[0], max(match[1]))

Calculate RMS displacement between two structures

Args:
struct1 (Structure): 1st structure
struct2 (Structure): 2nd structure

Returns:
rms displacement normalized by (Vol / nsites) ** (1/3)
and maximum distance between paired sites. If no matching
lattice is found None is returned.


def from_dict(cls, content):

        if 'resources' in content:
            content['resources'] = [DidlResource.from_dict(x)
                                    for x in content['resources']]
        return cls(**content)

Create an instance from a dict.

An alternative constructor. Equivalent to ``DidlObject(**content)``.

Args:
content (dict): a dict containing metadata information. Required.
Valid keys are the same as the parameters for `DidlObject`.


def _timeout_from_retry_config(retry_params):
    return timeout.ExponentialTimeout(initial=(retry_params['initial_rpc_timeout_millis'] / _MILLIS_PER_SECOND), maximum=(retry_params['max_rpc_timeout_millis'] / _MILLIS_PER_SECOND), multiplier=retry_params['rpc_timeout_multiplier'], deadline=(retry_params['total_timeout_millis'] / _MILLIS_PER_SECOND))

Creates a ExponentialTimeout object given a gapic retry configuration.

Args:
retry_params (dict): The retry parameter values, for example::

{
"initial_retry_delay_millis": 1000,
"retry_delay_multiplier": 2.5,
"max_retry_delay_millis": 120000,
"initial_rpc_timeout_millis": 120000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 120000,
"total_timeout_millis": 600000
}

Returns:
google.api_core.retry.ExponentialTimeout: The default time object for
the method.


def _parse_line(line):
    (line, timestamp) = line.rsplit(',', 1)
    (line, command) = line.rsplit(',', 1)
    (path, username) = line.rsplit(',', 1)
    return {'timestamp': timestamp.strip(), 'command': command.strip(), 'username': username.strip(), 'path': path}

Convert one line from the extended log to dict.

Args:
line (str): Line which will be converted.

Returns:
dict: dict with ``timestamp``, ``command``, ``username`` and ``path`` \
keys.

Note:
Typical line looks like this::

/home/ftp/xex/asd bsd.dat, xex, STOR, 1398351777

Filename may contain ``,`` character, so I am ``rsplitting`` the line
from the end to the beginning.


def from_json(cls, data):

        role = cls()

        role.role_id = data['roleId']
        role.name = data['name']
        role.color = data['color']

        return role

Return object based on JSON / dict input

Args:
data (dict): Dictionary containing a serialized Role object

Returns:
:obj:`Role`: Role object representing the data


def __init__(self, function, kind='exception'):

        self._function = function
        self._kind = kind
        if kind != 'exception' and kind != 'value':
            raise ValueError(kind)

Returns a retry condition which will run the supplied function
in either on_value or on_exception depending if kind == 'exception'
or 'value'

Args:
function: The function to run.
kind: the type of condition exception or value based.


def chebyshev(coefs, time, domain):

    return Chebyshev(coefs, domain=domain)(time) - 0.5 * coefs[0]

Evaluate a Chebyshev Polynomial

Args:
coefs (list, np.array): Coefficients defining the polynomial
time (int, float): Time where to evaluate the polynomial
domain (list, tuple): Domain (or time interval) for which the polynomial is defined: [left, right]

Reference: Appendix A in the MSG Level 1.5 Image Data Format Description.


def set_domain_id(self, value=None, default=False, disable=False):

        return self._configure_mlag('domain-id', value, default, disable)

Configures the mlag domain-id value

Args:
value (str): The value to configure the domain-id
default (bool): Configures the domain-id using the default keyword
disable (bool): Negates the domain-id using the no keyword

Returns:
bool: Returns True if the commands complete successfully


def _BiasAddGradV1(unused_bias_op: ops.Operation, received_grad):
    reduction_dim_tensor = math_ops.range(array_ops.rank(received_grad) - 1)
    return (received_grad, math_ops.reduce_sum(received_grad, reduction_dim_tensor))

Return the gradients for the 2 inputs of bias_op.

The first input of unused_bias_op is the tensor t, and its gradient is
just the gradient the unused_bias_op received.

The second input of unused_bias_op is the bias vector which has one fewer
dimension than "received_grad" (the batch dimension.)  Its gradient is the
received gradient Summed on the batch dimension, which is the first dimension.

Args:
unused_bias_op: The BiasOp for which we need to generate gradients.
received_grad: Tensor.  The gradients passed to the BiasOp.

Returns:
Two tensors, the first one for the "tensor" input of the BiasOp,
the second one for the "bias" input of the BiasOp.


def _process_update(self, item, feed_item):
    item['name'] = feed_item.get(FieldMap.EVENT_TAG_NAME, None)
    item['status'] = feed_item.get(FieldMap.EVENT_TAG_STATUS, None)
    item['type'] = feed_item.get(FieldMap.EVENT_TAG_TYPE, None)
    item['url'] = feed_item.get(FieldMap.EVENT_TAG_URL, None)

Processes the update of an Event Tag

Args:
item: Object representing the event tag to be updated, this object is
updated directly.
feed_item: Feed item representing event tag values from the Bulkdozer
feed.


def transfer(self, data):
    settings = self.transfer_settings
    settings.spi_tx_size = len(data)
    self.transfer_settings = settings
    response = ''
    for i in range(0, len(data), 60):
        response += self.sendCommand(commands.SPITransferCommand(data[i:(i + 60)])).data
        time.sleep(0.01)
    while (len(response) < len(data)):
        response += self.sendCommand(commands.SPITransferCommand('')).data
    return ''.join(response)

Transfers data over SPI.

Arguments:
data: The data to transfer.

Returns:
The data returned by the SPI device.


def start_data_fetch(self):
    self.stop_data_fetch()
    self._data_fetcher = _ViewDataFetcher(self, self._tuple_fn)
    t = threading.Thread(target=self._data_fetcher)
    t.start()
    return self._data_fetcher.items

Starts a thread that fetches data from the Streams view server.

Each item in the returned `Queue` represents a single tuple
on the stream the view is attached to.

Returns:
queue.Queue: Queue containing view data.

.. note:: This is a queue of the tuples coverted to Python
objects, it is not a queue of :py:class:`ViewItem` objects.


def and_evaluator(conditions, leaf_evaluator):

  saw_null_result = False

  for condition in conditions:
    result = evaluate(condition, leaf_evaluator)
    if result is False:
      return False
    if result is None:
      saw_null_result = True

  return None if saw_null_result else True

Evaluates a list of conditions as if the evaluator had been applied
to each entry and the results AND-ed together.

Args:
conditions: List of conditions ex: [operand_1, operand_2].
leaf_evaluator: Function which will be called to evaluate leaf condition values.

Returns:
Boolean:
- True if all operands evaluate to True.
- False if a single operand evaluates to False.
None: if conditions couldn't be evaluated.


def add_cohp(self, label, cohp):

        energies = cohp.energies - cohp.efermi if self.zero_at_efermi \
            else cohp.energies
        populations = cohp.get_cohp()
        int_populations = cohp.get_icohp()
        self._cohps[label] = {"energies": energies, "COHP": populations,
                              "ICOHP": int_populations, "efermi": cohp.efermi}

Adds a COHP for plotting.

Args:
label: Label for the COHP. Must be unique.

cohp: COHP object.


def getFormat(self, formatId, vendorSpecific=None):

        response = self.getFormatResponse(formatId, vendorSpecific)
        return self._read_dataone_type_response(response, 'ObjectFormat')

See Also: getFormatResponse()

Args:
formatId:
vendorSpecific:

Returns:


def mean(series):

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

Returns the mean of a series.

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


def set(self, value):
    pywrap_tfe.TFE_MonitoringStringGaugeCellSet(self._cell, value)

Atomically set the value.

Args:
value: string value.


def DoesNotContainIgnoreCase(self, value):

    self._awql = self._CreateSingleValueCondition(
        value, 'DOES_NOT_CONTAIN_IGNORE_CASE')
    return self._query_builder

Sets the type of the WHERE clause as "doesn not contain ignore case".

Args:
value: The value to be used in the WHERE condition.

Returns:
The query builder that this WHERE builder links to.


def transformation_matrix(self):
    t = np.array([[0.0], [0.0], [0.0]])
    Rt = np.hstack([self.rotation_matrix, t])
    return np.vstack([Rt, np.array([0.0, 0.0, 0.0, 1.0])])

Get the 4x4 homogeneous transformation matrix equivalent of the quaternion rotation.

Returns:
A 4x4 homogeneous transformation matrix as a 4x4 Numpy array

Note:
This feature only makes sense when referring to a unit quaternion. Calling this method will implicitly normalise the Quaternion object to a unit quaternion if it is not already one.


def MapByteStream(self, byte_stream, **unused_kwargs):

    raise errors.MappingError(
        'Unable to map {0:s} data type to byte stream'.format(
            self._data_type_definition.TYPE_INDICATOR))

Maps the data type on a byte stream.

Args:
byte_stream (bytes): byte stream.

Returns:
object: mapped value.

Raises:
MappingError: if the data type definition cannot be mapped on
the byte stream.


async def send_rpc(self, conn_id, address, rpc_id, payload, timeout):

        try:
            return await super(EmulatedDeviceAdapter, self).send_rpc(conn_id, address, rpc_id, payload, timeout)
        finally:
            for dev in self.devices.values():
                dev.wait_idle()

Asynchronously send an RPC to this IOTile device

Args:
conn_id (int): A unique identifier that will refer to this connection
address (int): the address of the tile that we wish to send the RPC to
rpc_id (int): the 16-bit id of the RPC we want to call
payload (bytearray): the payload of the command
timeout (float): the number of seconds to wait for the RPC to execute


def set_cpu0(device_string):
    if context.is_custom_device(device_string):
        return device_string
    parsed_device = pydev.DeviceSpec.from_string(device_string)
    parsed_device = parsed_device.replace(device_type='CPU', device_index=0)
    return parsed_device.to_string()

Creates a new device string based on `device_string` but using /CPU:0.

If the device is already on /CPU:0 or it is a custom device, this is a no-op.

Args:
device_string: A device string.

Returns:
A device string.


def _contains_op(self, graphdef: graph_pb2.GraphDef, op_name: str, attr_name: str='', attr_val: _AttrValType=None, node_name: str='') -> bool:
    if self._contains_op_with_name_and_attribute(nodes=graphdef.node, op_name=op_name, attr_name=attr_name, attr_val=attr_val, node_name=node_name):
        return True
    for func in graphdef.library.function:
        if self._contains_op_with_name_and_attribute(nodes=func.node_def, op_name=op_name, attr_name=attr_name, attr_val=attr_val, node_name=node_name):
            return True
    return False

Determines if the graph def contains the given op.

Args:
graphdef: A GraphDef object.
op_name: Name of the operation to find within the graph.
attr_name: Name of the attribute of the op to match.
attr_val: Value of the attr_name to check.
node_name: Name of the node to match. Accepts regex2 format.

Returns:
True if and only if the graph def contains an op named `op_name`. If
`attr_name` is given, check if the `attr_val` matches with the attribute
value of the op.


def unpatchify(self, patchified_pixel_values, original_image_size: Optional[Tuple[int, int]]=None):
    patch_size, num_channels = (self.config.patch_size, self.config.num_channels)
    original_image_size = original_image_size if original_image_size is not None else (self.config.image_size, self.config.image_size)
    original_height, original_width = original_image_size
    num_patches_h = original_height
    num_patches_w = original_width
    if num_patches_h * num_patches_w != patchified_pixel_values.shape[1]:
        raise ValueError(f'The number of patches in the patchified pixel values {patchified_pixel_values.shape[1]}, does not match the number of patches on original image {num_patches_h}*{num_patches_w}')
    batch_size = patchified_pixel_values.shape[0]
    patchified_pixel_values = patchified_pixel_values.reshape(batch_size, num_patches_h, num_patches_w, patch_size, patch_size, num_channels)
    patchified_pixel_values = torch.einsum('nhwpqc->nchpwq', patchified_pixel_values)
    pixel_values = patchified_pixel_values.reshape(batch_size, num_channels, num_patches_h * patch_size, num_patches_w * patch_size)
    return pixel_values

Args:
patchified_pixel_values (`torch.FloatTensor` of shape `(batch_size, num_patches, patch_size**2 * num_channels)`:
Patchified pixel values.
original_image_size (`Tuple[int, int]`, *optional*):
Original image size.

Returns:
`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`:
Pixel values.


def kde(self, term, bandwidth=2000, samples=1000, kernel='gaussian'):
    terms = np.array(self.terms[term])[(:, np.newaxis)]
    kde = KernelDensity(kernel=kernel, bandwidth=bandwidth).fit(terms)
    x_axis = np.linspace(0, len(self.tokens), samples)[(:, np.newaxis)]
    scores = kde.score_samples(x_axis)
    return (np.exp(scores) * (len(self.tokens) / samples))

Estimate the kernel density of the instances of term in the text.

Args:
term (str): A stemmed term.
bandwidth (int): The kernel bandwidth.
samples (int): The number of evenly-spaced sample points.
kernel (str): The kernel function.

Returns:
np.array: The density estimate.


def update_context(self, context, app=None):

        if (app is None and self._context is _CONTEXT_MISSING
                and not in_app_context()):
            raise RuntimeError("Attempted to update component context without"
                               " a bound app context or eager app set! Please"
                               " pass the related app you want to update the"
                               " context for!")

        if self._context is not _CONTEXT_MISSING:
            self._context = ImmutableDict(context)
        else:
            key = self._get_context_name(app=app)
            setattr(_CONTEXT_LOCALS, key, ImmutableDict(context))

Replace the component's context with a new one.

Args:
context (dict): The new context to set this component's context to.

Keyword Args:
app (flask.Flask, optional): The app to update this context for. If
not provided, the result of ``Component.app`` will be used.


def custom_getter(self, activation_dtype=tf.bfloat16):

    def getter_fn(getter, *args, **kwargs):
        requested_dtype = kwargs['dtype']
        if (requested_dtype in (tf.bfloat16, tf.float32)):
            kwargs['dtype'] = tf.bfloat16
            kwargs['initializer'] = _EncodingInitializer(kwargs['initializer'], self)
            ret = self._decode_with_identity_gradient(getter(*args, **kwargs))
            return tf.cast(ret, activation_dtype)
        return getter(*args, **kwargs)
    return getter_fn

A custom getter that uses the encoding for bfloat16 and float32 vars.

When a bfloat16 or float32 variable is requsted, an encoded float16
varaible is created, which is then decoded and cast to a bfloat16
activation.

Args:
activation_dtype: a dtype to which to convert the decoded value.

Returns:
a function.


def __init__(self, data_points, timestamps, hz, voltage, offset=0):

        self._data_points = data_points
        self._timestamps = timestamps
        self.offset = offset
        num_of_data_pt = len(self._data_points)
        if self.offset >= num_of_data_pt:
            raise MonsoonError(
                ("Offset number (%d) must be smaller than the "
                 "number of data points (%d).") % (offset, num_of_data_pt))
        self.data_points = self._data_points[self.offset:]
        self.timestamps = self._timestamps[self.offset:]
        self.hz = hz
        self.voltage = voltage
        self.tag = None
        self._validate_data()

Instantiates a MonsoonData object.

Args:
data_points: A list of current values in Amp (float).
timestamps: A list of epoch timestamps (int).
hz: The hertz at which the data points are measured.
voltage: The voltage at which the data points are measured.
offset: The number of initial data points to discard
in calculations.


def _processing_limit(self, spec):
    processing_rate = float(spec.mapper.params.get('processing_rate', 0))
    slice_processing_limit = (- 1)
    if (processing_rate > 0):
        slice_processing_limit = int(math.ceil(((parameters.config._SLICE_DURATION_SEC * processing_rate) / int(spec.mapper.shard_count))))
    return slice_processing_limit

Get the limit on the number of map calls allowed by this slice.

Args:
spec: a Mapreduce spec.

Returns:
The limit as a positive int if specified by user. -1 otherwise.


def editTemplate(id, data):

        conn = Qubole.agent()
        return conn.put(Template.element_path(id), data)

Edit an existing template.

Args:
`id`:   ID of the template to edit
`data`: json data to be updated
Returns:
Dictionary containing the updated details of the template.


def include(self, scheduled_operation: ScheduledOperation):
    collisions = self.query(time=scheduled_operation.time, duration=scheduled_operation.duration, qubits=scheduled_operation.operation.qubits)
    if collisions:
        raise ValueError('Operation {} has collisions: {}'.format(scheduled_operation.operation, collisions))
    self.scheduled_operations.add(scheduled_operation)
    self._max_duration = max(self._max_duration, scheduled_operation.duration)

Adds a scheduled operation to the schedule.

Args:
scheduled_operation: The operation to add.

Raises:
ValueError:
The operation collided with something already in the schedule.


def __init__(self, element_type=None, length=None, content=b''):

        super().__init__()
        self.element_type = element_type
        self.length = length
        self.content = content

Create a HelloElemHeader with the optional parameters below.

Args:
element_type: One of OFPHET_*.
length: Length in bytes of the element, including this header,
excluding padding.


def store(self, extractions: List[Extraction], attribute: str, group_by_tags: bool=True) -> None:
    if (not isinstance(self._value, dict)):
        raise StoreExtractionError(('segment is type: ' + str(type(self._value))))
    if (not len(extractions)):
        return
    if group_by_tags:
        try:
            next((x for x in extractions if x.tag))
            if (attribute not in self._extractions):
                self._extractions[attribute] = set([])
                self._value[attribute] = {}
            extraction_provenances = {}
            for e in extractions:
                tag = (e.tag if e.tag else 'NO_TAGS')
                if (tag not in self.value[attribute]):
                    self.value[attribute][tag] = [e.value]
                elif (e.value not in self.value[attribute][tag]):
                    self.value[attribute][tag].append(e.value)
                if (isinstance(e.value, Number) or isinstance(e.value, str)):
                    extraction_provenances[e.value] = e.prov_id
            self._extractions[attribute] = self._extractions[attribute].union(extractions)
            new_id = self._document.provenance_id_index
            storage_provenance_record: StorageProvenanceRecord = StorageProvenanceRecord(new_id, self.json_path, attribute, extraction_provenances, self.document)
            self._document.provenance_id_index_incrementer()
            self._document.provenances[new_id] = storage_provenance_record
            self.create_storage_provenance(storage_provenance_record)
            return
        except StopIteration:
            pass
    if (attribute not in self._extractions):
        self._extractions[attribute] = set([])
        self._value[attribute] = list()
    self._extractions[attribute] = self._extractions[attribute].union(extractions)
    extraction_provenances = dict()
    for a_extraction in extractions:
        if (isinstance(a_extraction.value, Number) or isinstance(a_extraction.value, str)):
            extraction_provenances[a_extraction.value] = a_extraction.prov_id
        if (a_extraction.value not in self._value[attribute]):
            self._value[attribute].append(a_extraction.value)
    new_id = self._document.provenance_id_index
    storage_provenance_record: StorageProvenanceRecord = StorageProvenanceRecord(new_id, self.json_path, attribute, extraction_provenances, self.document)
    self._document.provenance_id_index_incrementer()
    self._document.provenances[new_id] = storage_provenance_record
    self.create_storage_provenance(storage_provenance_record)

Records extractions in the container, and for each individual extraction inserts a
ProvenanceRecord to record where the extraction is stored.
Records the "output_segment" in the provenance.

Extractions are always recorded in a list.

Errors out if the segment is primitive, such as a string.

Args:
extractions (List[Extraction]):
attribute (str): where to store the extractions.
group_by_tags (bool): Set to True to use tags as sub-keys, and values of Extractions
with the same tag will be stored in a list as the value of the corresponding key.
(if none of the Extractions has 'tag', do not group by tags)

Returns:


def filter_list(lst, takeout, case_sensitive=True):

    takeout = force_list(takeout)

    if not case_sensitive:
        lst = [x.lower() for x in lst]
        takeout = [y.lower() for y in takeout]

    return [x for x in lst if x not in takeout]

Return a modified list removing items specified.

Args:
lst: Original list of values
takeout: Object or objects to remove from lst
case_sensitive: if the search should be case sensitive

Returns:
list: Filtered list of values


def _zsh_comp_command(self, zcf, cmd, grouping, add_help=True):

        if add_help:
            if grouping:
                print("+ '(help)'", end=BLK, file=zcf)
            print("'--help[show help message]'", end=BLK, file=zcf)
            print("'-h[show help message]'", end=BLK, file=zcf)

        no_comp = ('store_true', 'store_false')
        cmd_dict = self._opt_cmds[cmd] if cmd else self._opt_bare
        for opt, sct in cmd_dict.items():
            meta = self._conf[sct].def_[opt]
            if meta.cmd_kwargs.get('action') == 'append':
                grpfmt, optfmt = "+ '{}'", "'*{}[{}]{}'"
                if meta.comprule is None:
                    meta.comprule = ''
            else:
                grpfmt, optfmt = "+ '({})'", "'{}[{}]{}'"
            if meta.cmd_kwargs.get('action') in no_comp \
               or meta.cmd_kwargs.get('nargs') == 0:
                meta.comprule = None
            if meta.comprule is None:
                compstr = ''
            elif meta.comprule == '':
                optfmt = optfmt.split('[')
                optfmt = optfmt[0] + '=[' + optfmt[1]
                compstr = ': :( )'
            else:
                optfmt = optfmt.split('[')
                optfmt = optfmt[0] + '=[' + optfmt[1]
                compstr = ': :{}'.format(meta.comprule)
            if grouping:
                print(grpfmt.format(opt), end=BLK, file=zcf)
            for name in _names(self._conf[sct], opt):
                print(optfmt.format(name, meta.help.replace("'", "'\"'\"'"),
                                    compstr), end=BLK, file=zcf)

Write zsh _arguments compdef for a given command.

Args:
zcf (file): zsh compdef file.
cmd (str): command name, set to None or '' for bare command.
grouping (bool): group options (zsh>=5.4).
add_help (bool): add an help option.


def get(self, ID, index='vector-web-s'):
    url = (self.get_url % index)
    r = self.gbdx_connection.get((url + ID))
    r.raise_for_status()
    return r.json()

Retrieves a vector.  Not usually necessary because searching is the best way to find & get stuff.

Args:
ID (str): ID of the vector object
index (str): Optional.  Index the object lives in.  defaults to 'vector-web-s'

Returns:
record (dict): A dict object identical to the json representation of the catalog record


def merge_default_values(resource_list, default_values):

    def merge_item(resource):
        return merge_resources(default_values, resource)
    return lmap(merge_item, resource_list)

Generate a new list where each item of original resource_list will be merged with the default_values.

Args:
resource_list: list with items to be merged
default_values: properties to be merged with each item list. If the item already contains some property
the original value will be maintained.

Returns:
list: list containing each item merged with default_values


def __init__(self, function=None, data=None):

        super(LocationsError, self).__init__()
        self.function = function
        self.data = data

Initialise a new ``LocationsError`` object.

Args:
function (str): Function where error is raised
data (tuple): Location number and data


def create_module_to_test_map(reverse_map: Optional[Dict[str, List[str]]]=None, filter_models: bool=False) -> Dict[str, List[str]]:
    if reverse_map is None:
        reverse_map = create_reverse_dependency_map()

    def is_test(fname):
        if fname.startswith('tests'):
            return True
        if fname.startswith('examples') and fname.split(os.path.sep)[-1].startswith('test'):
            return True
        return False
    test_map = {module: [f for f in deps if is_test(f)] for module, deps in reverse_map.items()}
    if not filter_models:
        return test_map
    num_model_tests = len(list(PATH_TO_TESTS.glob('models/*')))

    def has_many_models(tests):
        model_tests = {Path(t).parts[2] for t in tests if t.startswith('tests/models/')}
        return len(model_tests) > num_model_tests

    def filter_tests(tests, module=''):
        filtered_tests = []
        for t in tests:
            if not t.startswith('tests/models/') or Path(t).parts[2] in IMPORTANT_MODELS or '/'.join(Path(t).parts[1:3]) in module:
                filtered_tests += [t]
        return filtered_tests
    return {module: filter_tests(tests, module=module) if has_many_models(tests) else tests for module, tests in test_map.items()}

Extract the tests from the reverse_dependency_map and potentially filters the model tests.

Args:
reverse_map (`Dict[str, List[str]]`, *optional*):
The reverse dependency map as created by `create_reverse_dependency_map`. Will default to the result of
that function if not provided.
filter_models (`bool`, *optional*, defaults to `False`):
Whether or not to filter model tests to only include core models if a file impacts a lot of models.

Returns:
`Dict[str, List[str]]`: A dictionary that maps each file to the tests to execute if that file was modified.


def update_m(data, old_M, old_W, selected_genes, disp=False, inner_max_iters=100, parallel=True, threads=4, write_progress_file=None, tol=0.0, regularization=0.0, **kwargs):
    (genes, cells) = data.shape
    k = old_M.shape[1]
    non_selected_genes = [x for x in range(genes) if (x not in set(selected_genes))]
    new_M = np.zeros((genes, k))
    new_M[(selected_genes, :)] = old_M
    if disp:
        print('computing initial guess for M by data*W.T')
    new_M_non_selected = (data[(non_selected_genes, :)] * sparse.csc_matrix(old_W.T))
    new_M[(non_selected_genes, :)] = new_M_non_selected.toarray()
    X = data.astype(float)
    XT = X.T
    is_sparse = False
    if sparse.issparse(X):
        is_sparse = True
        update_fn = sparse_nolips_update_w
        X = sparse.csc_matrix(X)
        XT = sparse.csc_matrix(XT)
        if parallel:
            update_fn = parallel_sparse_nolips_update_w
        Xsum = np.asarray(X.sum(0)).flatten()
        Xsum_m = np.asarray(X.sum(1)).flatten()
        method = 'NoLips'
        objective_fn = _call_sparse_obj
    else:
        objective_fn = objective
        update_fn = nolips_update_w
        Xsum = X.sum(0)
        Xsum_m = X.sum(1)
        if (method == 'NoLips'):
            is_sparse = True
            X = sparse.csc_matrix(X)
            XT = sparse.csc_matrix(XT)
            update_fn = sparse_nolips_update_w
            if parallel:
                update_fn = parallel_sparse_nolips_update_w
            objective_fn = _call_sparse_obj
    if disp:
        print('starting estimating M')
    new_M = _estimate_w(XT, new_M.T, old_W.T, Xsum_m, update_fn, objective_fn, is_sparse, parallel, threads, method, tol, disp, inner_max_iters, 'M', regularization)
    if (write_progress_file is not None):
        progress = open(write_progress_file, 'w')
        progress.write('0')
        progress.close()
    return new_M.T

This returns a new M matrix that contains all genes, given an M that was
created from running state estimation with a subset of genes.

Args:
data (sparse matrix or dense array): data matrix of shape (genes, cells), containing all genes
old_M (array): shape is (selected_genes, k)
old_W (array): shape is (k, cells)
selected_genes (list): list of selected gene indices
Rest of the args are as in poisson_estimate_state

Returns:
new_M: array of shape (all_genes, k)


def __init__(self, serial_no):

        self.name = self.SERIAL_NAME_FMT.format(serial_no)
        self.acquired = False
        self.fd = None
        self.path = None
        self.path = os.path.join(tempfile.tempdir, self.name)

Creates an instance of a ``JLock`` and populates the name.

Note:
This method may fail if there is no temporary directory in which to
have the lockfile placed.

Args:
self (JLock): the ``JLock`` instance
serial_no (int): the serial number of the J-Link

Returns:
``None``


def export(rv, code=None, headers=None):
    if isinstance(rv, ResponseBase):
        return make_response(rv, code, headers)
    else:
        if (code is None):
            code = 200
        mediatype = request.accept_mimetypes.best_match(exporters.keys(), default='application/json')
        return exporters[mediatype](rv, code, headers)

Create a suitable response

Args:
rv: return value of action
code: status code
headers: response headers
Returns:
flask.Response


def info(self, **kwargs):
    path = self._get_credit_id_path('info')
    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response

Get the detailed information about a particular credit record. This is
currently only supported with the new credit model found in TV. These
ids can be found from any TV credit response as well as the tv_credits
and combined_credits methods for people.

The episodes object returns a list of episodes and are generally going
to be guest stars. The season array will return a list of season
numbers.  Season credits are credits that were marked with the
"add to every season" option in the editing interface and are
assumed to be "season regulars".

Args:
language: (optional) ISO 639-1 code.

Returns:
A dict respresentation of the JSON returned from the API.


def load_certificates(ca_location, crl_location=None, invalidate_cache=False):
    if (crl_location is None):
        crl_location = ''
    try:
        if invalidate_cache:
            del _cached_certificates[(ca_location + crl_location)]
        else:
            return _cached_certificates[(ca_location + crl_location)]
    except KeyError:
        pass
    (ca, crl) = (None, None)
    if ca_location:
        ca = _load_certificate(ca_location)
    if crl_location:
        crl = _load_certificate(crl_location)
    _cached_certificates[(ca_location + crl_location)] = (ca, crl)
    return (ca, crl)

Load the CA certificate and CRL, caching it for future use.

.. note::
Providing the location of the CA and CRL as an HTTPS URL is deprecated
and will be removed in a future release.

Args:
ca_location (str): The location of the Certificate Authority certificate. This should
be the absolute path to a PEM-encoded file. It can also be an HTTPS url, but this
is deprecated and will be removed in a future release.
crl_location (str): The location of the Certificate Revocation List. This should
be the absolute path to a PEM-encoded file. It can also be an HTTPS url, but
this is deprecated and will be removed in a future release.
invalidate_cache (bool): Whether or not to invalidate the certificate cache.

Returns:
tuple: A tuple of the (CA certificate, CRL) as unicode strings.

Raises:
requests.exception.RequestException: Any exception requests could raise.
IOError: If the location provided could not be opened and read.


def read(self, size=None):

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

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

    if self._decrypted_stream_size is None:
      self._decrypted_stream_size = self._GetDecryptedStreamSize()

    if self._decrypted_stream_size < 0:
      raise IOError('Invalid decrypted stream size.')

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

    if self._realign_offset:
      self._AlignDecryptedDataOffset(self._current_offset)
      self._realign_offset = False

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

    decrypted_data = b''

    if size == 0:
      return decrypted_data

    while size > self._decrypted_data_size:
      decrypted_data = b''.join([
          decrypted_data,
          self._decrypted_data[self._decrypted_data_offset:]])

      remaining_decrypted_data_size = (
          self._decrypted_data_size - self._decrypted_data_offset)

      self._current_offset += remaining_decrypted_data_size
      size -= remaining_decrypted_data_size

      if self._current_offset >= self._decrypted_stream_size:
        break

      read_count = self._ReadEncryptedData(self._ENCRYPTED_DATA_BUFFER_SIZE)
      self._decrypted_data_offset = 0
      if read_count == 0:
        break

    if size > 0:
      slice_start_offset = self._decrypted_data_offset
      slice_end_offset = slice_start_offset + size

      decrypted_data = b''.join([
          decrypted_data,
          self._decrypted_data[slice_start_offset:slice_end_offset]])

      self._decrypted_data_offset += size
      self._current_offset += size

    return decrypted_data

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

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

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

Returns:
bytes: data read.

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


def copy(self, resource_view):

        if isinstance(resource_view, str):
            if is_valid_uuid(resource_view) is False:
                raise HDXError('%s is not a valid resource view id!' % resource_view)
            resource_view = ResourceView.read_from_hdx(resource_view)
        if not isinstance(resource_view, dict) and not isinstance(resource_view, ResourceView):
            raise HDXError('%s is not a valid resource view!' % resource_view)
        for key in resource_view:
            if key not in ('id', 'resource_id', 'package_id'):
                self.data[key] = resource_view[key]

Copies all fields except id, resource_id and package_id from another resource view.

Args:
resource_view (Union[ResourceView,Dict,str]): Either a resource view id or resource view metadata either from a ResourceView object or a dictionary

Returns:
None


def post_process_object_detection(self, outputs, threshold: float=0.5, target_sizes: Union[TensorType, List[Tuple]]=None):
    out_logits, out_bbox = (outputs.logits, outputs.pred_boxes)
    if target_sizes is not None:
        if len(out_logits) != len(target_sizes):
            raise ValueError('Make sure that you pass in as many target sizes as the batch dimension of the logits')
    prob = nn.functional.softmax(out_logits, -1)
    scores, labels = prob[..., :-1].max(-1)
    boxes = center_to_corners_format(out_bbox)
    if target_sizes is not None:
        if isinstance(target_sizes, List):
            img_h = torch.Tensor([i[0] for i in target_sizes])
            img_w = torch.Tensor([i[1] for i in target_sizes])
        else:
            img_h, img_w = target_sizes.unbind(1)
        scale_fct = torch.stack([img_w, img_h, img_w, img_h], dim=1).to(boxes.device)
        boxes = boxes * scale_fct[:, None, :]
    results = []
    for s, l, b in zip(scores, labels, boxes):
        score = s[s > threshold]
        label = l[s > threshold]
        box = b[s > threshold]
        results.append({'scores': score, 'labels': label, 'boxes': box})
    return results

Converts the raw output of [`YolosForObjectDetection`] into final bounding boxes in (top_left_x, top_left_y,
bottom_right_x, bottom_right_y) format. Only supports PyTorch.

Args:
outputs ([`YolosObjectDetectionOutput`]):
Raw outputs of the model.
threshold (`float`, *optional*):
Score threshold to keep object detection predictions.
target_sizes (`torch.Tensor` or `List[Tuple[int, int]]`, *optional*):
Tensor of shape `(batch_size, 2)` or list of tuples (`Tuple[int, int]`) containing the target size
`(height, width)` of each image in the batch. If unset, predictions will not be resized.
Returns:
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels and boxes for an image
in the batch as predicted by the model.


def row_starts(self):
    return self._row_splits[:-1]

Returns the start indices for rows in this row partition.

These indices specify where the values for each row begin.
`partition.row_starts()` is equal to `partition.row_splits()[:-1]`.

Returns:
A 1-D integer Tensor with shape `[self.nrows()]`.
The returned tensor is nonnegative, and is sorted in ascending order.
`self.row_starts()[0] == 0`.
`self.row_starts()[-1] <= self.nvals()`.


def gripper_factory(name):
    if (name == 'TwoFingerGripper'):
        return TwoFingerGripper()
    if (name == 'LeftTwoFingerGripper'):
        return LeftTwoFingerGripper()
    if (name == 'PR2Gripper'):
        return PR2Gripper()
    if (name == 'RobotiqGripper'):
        return RobotiqGripper()
    if (name == 'PushingGripper'):
        return PushingGripper()
    if (name == 'RobotiqThreeFingerGripper'):
        return RobotiqThreeFingerGripper()
    raise ValueError('Unkown gripper name {}'.format(name))

Genreator for grippers

Creates a Gripper instance with the provided name.

Args:
name: the name of the gripper class

Returns:
gripper: Gripper instance

Raises:
XMLError: [description]


def rewards_to_go(rewards, mask, gamma=0.99):
    (B, T) = rewards.shape
    masked_rewards = (rewards * mask)
    r2gs = [masked_rewards[(:, (- 1))]]
    for t in reversed(range((T - 1))):
        r2gs.append((masked_rewards[(:, t)] + (gamma * r2gs[(- 1)])))
    assert (T == len(r2gs))
    return np.flip(np.stack(r2gs, axis=1), axis=1)

r"""Computes rewards to go.

Reward to go is defined as follows, the discounted reward that we have to
yet collect, going forward from this point, i.e.:

r2g_t = \sum_{l=0}^{\infty} (\gamma^{l} * reward_{t+l})

Args:
rewards: np.ndarray of shape (B, T) of rewards.
mask: np.ndarray of shape (B, T) of mask for the rewards.
gamma: float, discount factor.

Returns:
rewards to go, np.ndarray of shape (B, T).


def get_shared_file(self, sharekey=None):
    if (not sharekey):
        raise Exception('You must specify a sharekey.')
    endpoint = '/api/sharedfile/{0}'.format(sharekey)
    data = self._make_request('GET', endpoint)
    return SharedFile.NewFromJSON(data)

Returns a SharedFile object given by the sharekey.

Args:
sharekey (str): Sharekey of the SharedFile you want to retrieve.

Returns:
SharedFile


def infer(self, ob):

    self._add_to_stack(ob)
    logits, vf = self.infer_from_frame_stack(self._frame_stack)
    return logits, vf

Add new observation to frame stack and infer policy.

Args:
ob: array of shape (height, width, channels)

Returns:
logits and vf.


def _preprocess_op_time(self, op_time: str) -> None:
    if op_time == 'schedule':
        self._step_stats = self._origin_step_stats
        return
    self._step_stats = copy.deepcopy(self._origin_step_stats)
    stream_all_stats = []
    job_stats = []
    for stats in self._step_stats.dev_stats:
        if '/stream:all' in stats.device:
            stream_all_stats.append(stats)
        elif '/job' in stats.device:
            job_stats.append(stats)
    op_gpu_start = {}
    op_gpu_end = {}
    for stats in stream_all_stats:
        for kernel in stats.node_stats:
            name, _ = self._parse_kernel_label(kernel.timeline_label, kernel.node_name)
            start = kernel.all_start_micros
            end = kernel.all_start_micros + kernel.all_end_rel_micros
            if name in op_gpu_start:
                op_gpu_start[name] = min(op_gpu_start[name], start)
                op_gpu_end[name] = max(op_gpu_end[name], end)
            else:
                op_gpu_start[name] = start
                op_gpu_end[name] = end
    for stats in job_stats:
        for op in stats.node_stats:
            if op.node_name in op_gpu_start:
                end = max(op_gpu_end[op.node_name], op.all_start_micros + op.all_end_rel_micros)
                if op_time == 'gpu':
                    op.all_start_micros = op_gpu_start[op.node_name]
                op.all_end_rel_micros = end - op.all_start_micros

Update the start and end time of ops in step stats.

Args:
op_time: How the execution time of op is shown in timeline. Possible
values are "schedule", "gpu" and "all".  "schedule" will show op from
the time it is scheduled to the end of the scheduling. Notice by the end
of its scheduling its async kernels may not start yet. It is shown using
the default value from step_stats. "gpu" will show op with the execution
time of its kernels on GPU. "all" will show op from the start of its
scheduling to the end of its last kernel.


def process_messages(self, max_messages=10000):
    subscribe_clients = [self.primary_subscribe_client]
    for subscribe_client in subscribe_clients:
        for _ in range(max_messages):
            message = subscribe_client.get_message()
            if (message is None):
                break
            channel = message['channel']
            data = message['data']
            if (channel == ray.gcs_utils.XRAY_HEARTBEAT_BATCH_CHANNEL):
                message_handler = self.xray_heartbeat_batch_handler
            elif (channel == ray.gcs_utils.XRAY_DRIVER_CHANNEL):
                message_handler = self.xray_driver_removed_handler
            else:
                raise Exception('This code should be unreachable.')
            message_handler(channel, data)

Process all messages ready in the subscription channels.

This reads messages from the subscription channels and calls the
appropriate handlers until there are no messages left.

Args:
max_messages: The maximum number of messages to process before
returning.


def get_reference(self, datas, name):
    rule_name = '-'.join((RULE_REFERENCE, name))
    structure_mode = 'nested'
    if (rule_name not in datas):
        msg = "Unable to find enabled reference '{}'"
        raise SerializerError(msg.format(name))
    properties = datas.get(rule_name)
    if ('structure' in properties):
        if (properties['structure'] == 'flat'):
            structure_mode = 'flat'
        elif (properties['structure'] == 'list'):
            structure_mode = 'list'
        elif (properties['structure'] == 'string'):
            structure_mode = 'string'
        elif (properties['structure'] == 'json'):
            structure_mode = 'json'
        elif (properties['structure'] == 'nested'):
            pass
        else:
            msg = "Invalid structure mode name '{}' for reference '{}'"
            raise SerializerError(msg.format(structure_mode, name))
        del properties['structure']
    for item in properties.keys():
        self.validate_variable_name(item)
    if (structure_mode == 'flat'):
        context = self.serialize_to_flat(name, properties)
    elif (structure_mode == 'list'):
        context = self.serialize_to_list(name, properties)
    elif (structure_mode == 'string'):
        context = self.serialize_to_string(name, properties)
    elif (structure_mode == 'nested'):
        context = self.serialize_to_nested(name, properties)
    elif (structure_mode == 'json'):
        context = self.serialize_to_json(name, properties)
    return context

Get serialized reference datas

Because every reference is turned to a dict (that stands on ``keys``
variable that is a list of key names), every variables must have the
same exact length of word than the key name list.

A reference name starts with 'styleguide-reference-' followed by
name for reference.

A reference can contains variable ``--structure`` setted to ``"flat"``,
``"list"`` or ``"string"`` to define serialization structure.

Arguments:
datas (dict): Data where to search for reference declaration. This
is commonly the fully parsed manifest.
name (string): Reference name to get and serialize.

Returns:
collections.OrderedDict: Serialized reference datas.


def get_definition(self, name: YangIdentifier,
                       kw: YangIdentifier) -> Optional["Statement"]:

        stmt = self.superstmt
        while stmt:
            res = stmt.find1(kw, name)
            if res:
                return res
            stmt = stmt.superstmt
        return None

Search ancestor statements for a definition.

Args:
name: Name of a grouping or datatype (with no prefix).
kw: ``grouping`` or ``typedef``.

Raises:
DefinitionNotFound: If the definition is not found.


def get_url(self, url):
    try:
        req = requests.get(url, headers={'Authorization': 'Token {}'.format(self._user_token)}, verify=False)
        if (req.status_code is 403):
            raise ValueError('Access Denied')
        else:
            return req
    except requests.exceptions.ConnectionError as e:
        if (str(e) == '403 Client Error: Forbidden'):
            raise ValueError('Access Denied')
        else:
            raise e

Get a response object for a given url.

Arguments:
url (str): The url make a get to
token (str): The authentication token

Returns:
obj: The response object


def smart_constant_value(pred):
    if isinstance(pred, tensor.Tensor):
        pred_value = tensor_util.constant_value(pred)
        if pred_value is None:
            pred_value = tensor_util.try_evaluate_constant(pred)
    elif pred in {0, 1}:
        pred_value = bool(pred)
    elif isinstance(pred, bool):
        pred_value = pred
    else:
        raise TypeError(f'Argument `pred` must be a Tensor, or a Python bool, or 1 or 0. Received: pred={pred} of type {type(pred).__name__}')
    return pred_value

Return the bool value for `pred`, or None if `pred` had a dynamic value.

Args:
pred: A scalar, either a Python bool or tensor.

Returns:
True or False if `pred` has a constant boolean value, None otherwise.

Raises:
TypeError: If `pred` is not a Tensor or bool.


def _count_tokens(files, file_byte_limit=1e6):

  token_counts = collections.defaultdict(int)

  for filepath in files:
    with tf.gfile.Open(filepath, mode="r") as reader:
      file_byte_budget = file_byte_limit
      counter = 0
      lines_to_skip = int(reader.size() / (file_byte_budget * 2))
      for line in reader:
        if counter < lines_to_skip:
          counter += 1
        else:
          if file_byte_budget < 0:
            break
          line = line.strip()
          file_byte_budget -= len(line)
          counter = 0

          for token in _split_string_to_tokens(_native_to_unicode(line)):
            token_counts[token] += 1
  return token_counts

Return token counts of words in the files.

Samples file_byte_limit bytes from each file, and counts the words that appear
in the samples. The samples are semi-evenly distributed across the file.

Args:
files: List of filepaths
file_byte_limit: Max number of bytes that will be read from each file.

Returns:
Dictionary mapping tokens to the number of times they appear in the sampled
lines from the files.


def event_shape_tensor(self, name='event_shape_tensor'):
    with self._name_scope(name):
        if self.event_shape.is_fully_defined():
            return ops.convert_to_tensor(self.event_shape.as_list(), dtype=dtypes.int32, name='event_shape')
        return self._event_shape_tensor()

Shape of a single sample from a single batch as a 1-D int32 `Tensor`.

Args:
name: name to give to the op

Returns:
event_shape: `Tensor`.


def calculate_sun_from_date_time(self, datetime, is_solar_time=False):
    if ((datetime.year != 2016) and self.is_leap_year):
        datetime = DateTime(datetime.month, datetime.day, datetime.hour, datetime.minute, True)
    (sol_dec, eq_of_time) = self._calculate_solar_geometry(datetime)
    hour = datetime.float_hour
    is_daylight_saving = self.is_daylight_saving_hour(datetime.hoy)
    hour = ((hour + 1) if self.is_daylight_saving_hour(datetime.hoy) else hour)
    sol_time = (self._calculate_solar_time(hour, eq_of_time, is_solar_time) * 60)
    if ((sol_time / 4) < 0):
        hour_angle = ((sol_time / 4) + 180)
    else:
        hour_angle = ((sol_time / 4) - 180)
    zenith = math.degrees(math.acos(((math.sin(self._latitude) * math.sin(math.radians(sol_dec))) + ((math.cos(self._latitude) * math.cos(math.radians(sol_dec))) * math.cos(math.radians(hour_angle))))))
    altitude = (90 - zenith)
    if (altitude > 85):
        atmos_refraction = 0
    elif (altitude > 5):
        atmos_refraction = (58.1 / math.tan(math.radians(altitude)))
        ((- 0.07) / (math.tan(math.radians(altitude)) ** 3))
        ((+ 8.6e-05) / (math.tan(math.radians(altitude)) ** 5))
    elif (altitude > (- 0.575)):
        atmos_refraction = 1735
        ((+ altitude) * ((- 518.2) + (altitude * (103.4 + (altitude * ((- 12.79) + (altitude * 0.711)))))))
    else:
        atmos_refraction = ((- 20.772) / math.tan(math.radians(altitude)))
    atmos_refraction /= 3600
    altitude += atmos_refraction
    if (hour_angle > 0):
        azimuth = ((math.degrees(math.acos((((math.sin(self._latitude) * math.cos(math.radians(zenith))) - math.sin(math.radians(sol_dec))) / (math.cos(self._latitude) * math.sin(math.radians(zenith)))))) + 180) % 360)
    else:
        azimuth = ((540 - math.degrees(math.acos((((math.sin(self._latitude) * math.cos(math.radians(zenith))) - math.sin(math.radians(sol_dec))) / (math.cos(self._latitude) * math.sin(math.radians(zenith))))))) % 360)
    altitude = math.radians(altitude)
    azimuth = math.radians(azimuth)
    return Sun(datetime, altitude, azimuth, is_solar_time, is_daylight_saving, self.north_angle)

Get Sun for an hour of the year.

This code is originally written by Trygve Wastvedt \
(Trygve.Wastvedt@gmail.com)
based on (NOAA) and modified by Chris Mackey and Mostapha Roudsari

Args:
datetime: Ladybug datetime
is_solar_time: A boolean to indicate if the input hour is solar time.
(Default: False)

Returns:
A sun object for this particular time


def run_command(self, command, arg=None, is_eval=False, member_id=None):

        logger.debug("run_command({command}, {arg}, {is_eval}, {member_id})".format(**locals()))
        mode = is_eval and 'eval' or 'command'
        hostname = None
        if isinstance(member_id, int):
            hostname = self.member_id_to_host(member_id)
        result = getattr(self.connection(hostname=hostname).admin, mode)(command, arg)
        logger.debug("command result: {result}".format(result=result))
        return result

run command on replica set
if member_id is specified command will be execute on this server
if member_id is not specified command will be execute on the primary

Args:
command - command string
arg - command argument
is_eval - if True execute command as eval
member_id - member id

return command's result


def bind_extensions(app):
    app.db = app.config['PUZZLE_BACKEND']
    app.db.init_app(app)
    bootstrap.init_app(app)
    markdown(app)

    @app.template_filter('islist')
    def islist(object):
        return isinstance(object, (tuple, list))

Configure extensions.

Args:
app (Flask): initialized Flask app instance


def output_all_intermediates():
    if _EXPERIMENTAL_OUTPUT_ALL_INTERMEDIATES_OVERRIDE is not None:
        return _EXPERIMENTAL_OUTPUT_ALL_INTERMEDIATES_OVERRIDE
    if in_defun():
        return False
    if control_flow_util.GraphOrParentsInXlaContext(ops.get_default_graph()):
        return False
    if context.context().function_call_options.executor_type == 'SINGLE_THREADED_EXECUTOR':
        return False
    return _is_building_keras_layer()

Whether to output all intermediates of a functional control flow op.

The default behavior is to output intermediates only when building a Keras
Layer in graph mode and that too when certain other conditions are met:
1. We do not output intermediates if the functional control flow op
is being built inside a FuncGraph which is not a If/While graph. This
guards against outputting intermediates in eager mode since keras adds
tensors to a FuncGraph named "keras_graph" in that case. Also because we
do not output intermediates of tf.function (since this feature is only for
backwards compatibility) outputting intermediates of functional control
flow ops built inside tf.function is of no value.
2. We do not output intermediates when the compilation is using XLA or for a
TPU.
3. We do not output intermediates when a single threaded executor is used
since that does not perform inlining and pruning.

Returns:
A bool telling whether to output all intermediates.


def save_local_scope(self, line_number, saved_function_call_index):
    saved_variables = list()
    saved_variables_so_far = set()
    first_node = None
    for assignment in [node for node in self.nodes if ((type(node) == AssignmentNode) or (type(node) == AssignmentCallNode) or (type(Node) == BBorBInode))]:
        if (assignment.left_hand_side in saved_variables_so_far):
            continue
        saved_variables_so_far.add(assignment.left_hand_side)
        save_name = 'save_{}_{}'.format(saved_function_call_index, assignment.left_hand_side)
        previous_node = self.nodes[(- 1)]
        saved_scope_node = RestoreNode(((save_name + ' = ') + assignment.left_hand_side), save_name, [assignment.left_hand_side], line_number=line_number, path=self.filenames[(- 1)])
        if (not first_node):
            first_node = saved_scope_node
        self.nodes.append(saved_scope_node)
        saved_variables.append(SavedVariable(LHS=save_name, RHS=assignment.left_hand_side))
        self.connect_if_allowed(previous_node, saved_scope_node)
    return (saved_variables, first_node)

Save the local scope before entering a function call by saving all the LHS's of assignments so far.

Args:
line_number(int): Of the def of the function call about to be entered into.
saved_function_call_index(int): Unique number for each call.

Returns:
saved_variables(list[SavedVariable])
first_node(EntryOrExitNode or None or RestoreNode): Used to connect previous statements to this function.


def __init__(self, dic):

        super().__init__()
        self.value = [DictSingle()]
        self.d = self.value[0].value
        self.add(dic)


def CreateAd(client, opener, ad_group_id):

  ad_group_ad_service = client.GetService('AdGroupAdService', 'v201809')
  media_service = client.GetService('MediaService', 'v201809')

  marketing_image_id = _CreateImage(
      media_service, opener, 'https:
  logo_image_id = _CreateImage(media_service, opener, 'https:

  ad = {
      'xsi_type': 'ResponsiveDisplayAd',

      'marketingImage': {
          'xsi_type': 'Image',
          'mediaId': marketing_image_id
      },
      'shortHeadline': 'Travel',
      'longHeadline': 'Travel the World',
      'description': 'Take to the air!',
      'businessName': 'Interplanetary Cruises',
      'finalUrls': ['http:

      'callToActionText': 'Apply Now',

      'dynamicDisplayAdSettings': CreateDynamicDisplayAdSettings(
          client, opener),

      'logoImage': {
          'xsi_type': 'Image',
          'mediaId': logo_image_id
      },

      'squareMarketingImage': {
          'xsi_type': 'Image',
          'mediaId': logo_image_id
      },

  }

  ad_group_ad = {
      'ad': ad,
      'adGroupId': ad_group_id
  }

  operations = [{
      'operation': 'ADD',
      'operand': ad_group_ad
  }]

  return ad_group_ad_service.mutate(operations)['value'][0]

Creates a ResponsiveDisplayAd.

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

Returns:
The ad group ad that was successfully created.


def __init__(self, splittable: bool, compression_type, desired_bundle_size: int, min_bundle_size: int, source_from_file: Callable[[str], iobase.BoundedSource], with_filename: bool=False):
    self._splittable = splittable
    self._compression_type = compression_type
    self._desired_bundle_size = desired_bundle_size
    self._min_bundle_size = min_bundle_size
    self._source_from_file = source_from_file
    self._with_filename = with_filename
    self._is_reshuffle = True

Args:
splittable: If False, files won't be split into sub-ranges. If True,
files may or may not be split into data ranges.
compression_type: A ``CompressionType`` object that specifies the
compression type of the files that will be processed. If
``CompressionType.AUTO``, system will try to automatically
determine the compression type based on the extension of
files.
desired_bundle_size: the desired size of data ranges that should be
generated when splitting a file into data ranges.
min_bundle_size: minimum size of data ranges that should be generated when
splitting a file into data ranges.
source_from_file: a function that produces a ``BoundedSource`` given a
file name. System will use this function to generate
``BoundedSource`` objects for file paths. Note that file
paths passed to this will be for individual files, not
for file patterns even if the ``PCollection`` of files
processed by the transform consist of file patterns.
with_filename: If True, returns a Key Value with the key being the file
name and the value being the actual data. If False, it only returns
the data.


def sas_interconnect_types(self):
    if (not self.__sas_interconnect_types):
        self.__sas_interconnect_types = SasInterconnectTypes(self.__connection)
    return self.__sas_interconnect_types

Gets the SasInterconnectTypes API client.

Returns:
SasInterconnectTypes:


def if_false(self, predicate: Callable[..., bool]):
    return Conditional(predicate, None, self)

Conditionally applies current operation when predicate returns False.

Args:
predicate: The predicate that takes the outputs from the previous
operation as input, with optional keyword arguments `global_state` and
`step`. Returns False if current operation needs to be enabled.
Otherwise no operation will be performed.

Returns:
A conditional operation.


def load_scenario(self, scenario_name, **kwargs):
    scenario = self._known_scenarios.get(scenario_name)
    if (scenario is None):
        raise ArgumentError(('Unknown scenario %s' % scenario_name), known_scenarios=list(self._known_scenarios))
    scenario(**kwargs)

Load a scenario into the emulated object.

Scenarios are specific states of an an object that can be customized
with keyword parameters.  Typical examples are:

- data logger with full storage
- device with low battery indication on

Args:
scenario_name (str): The name of the scenario that we wish to
load.
**kwargs: Any arguments that should be passed to configure
the scenario.  These arguments will be passed directly
to the scenario handler.


def absent(name, bridge=None):

    ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
    bridge_exists = False
    if bridge:
        bridge_exists = __salt__['openvswitch.bridge_exists'](bridge)
        if bridge_exists:
            port_list = __salt__['openvswitch.port_list'](bridge)
        else:
            port_list = ()
    else:
        port_list = [name]

    comments = {}
    comments['comment_bridge_notexists'] = 'Bridge {0} does not exist.'.format(bridge)
    comments['comment_port_notexists'] = 'Port {0} does not exist on bridge {1}.'.format(name, bridge)
    comments['comment_port_deleted'] = 'Port {0} deleted.'.format(name)
    comments['comment_port_notdeleted'] = 'Unable to delete port {0}.'.format(name)
    comments['changes_port_deleted'] = {name: {'old': 'Port named {0} may exist.'.format(name),
                                   'new': 'Deleted port {0}.'.format(name),
                                   }
                            }

    if __opts__['test']:
        if bridge and not bridge_exists:
            ret['result'] = None
            ret['comment'] = comments['comment_bridge_notexists']
        elif name not in port_list:
            ret['result'] = True
            ret['comment'] = comments['comment_port_notexists']
        else:
            ret['result'] = None
            ret['comment'] = comments['comment_port_deleted']
        return ret

    if bridge and not bridge_exists:
        ret['result'] = False
        ret['comment'] = comments['comment_bridge_notexists']
    elif name not in port_list:
        ret['result'] = True
        ret['comment'] = comments['comment_port_notexists']
    else:
        if bridge:
            port_remove = __salt__['openvswitch.port_remove'](br=bridge, port=name)
        else:
            port_remove = __salt__['openvswitch.port_remove'](br=None, port=name)

        if port_remove:
            ret['result'] = True
            ret['comment'] = comments['comment_port_deleted']
            ret['changes'] = comments['changes_port_deleted']
        else:
            ret['result'] = False
            ret['comment'] = comments['comment_port_notdeleted']

    return ret

Ensures that the named port exists on bridge, eventually deletes it.
If bridge is not set, port is removed from  whatever bridge contains it.

Args:
name: The name of the port.
bridge: The name of the bridge.


def __update(self, score, values, error):
    if self._minimize:
        if ((self._best_score is None) or (score > self._best_score)):
            self._best_score = score
            self._best_values = values.copy()
            self._best_error = error
            self._logger.log('debug', 'New best food source memorized: {}'.format(self._best_error))
            return True
    elif (not self._minimize):
        if ((self._best_score is None) or (score < self._best_score)):
            self._best_score = score
            self._best_values = values.copy()
            self._best_error = error
            self._logger.log('debug', 'New best food source memorized: {}'.format(self._best_error))
            return True
    return False

Update the best score and values if the given score is better than
the current best score

Args:
score (float): new score to evaluate
values (list): new value ranges to evaluate
error (float): new fitness function return value to evaluate

Returns:
bool: True if new score is better, False otherwise


def defocus_blur(x, severity=1):

  c = [(3, 0.1), (4, 0.5), (6, 0.5), (8, 0.5), (10, 0.5)][severity - 1]
  x = np.array(x) / 255.
  kernel = disk(radius=c[0], alias_blur=c[1])
  channels = []
  for d in range(3):
    channels.append(tfds.core.lazy_imports.cv2.filter2D(x[:, :, d], -1, kernel))
  channels = np.array(channels).transpose((1, 2, 0))
  x_clip = np.clip(channels, 0, 1) * 255
  return around_and_astype(x_clip)

Defocus blurring to images.

Apply defocus blurring to images using Gaussian kernel.

Args:
x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255].
severity: integer, severity of corruption.

Returns:
numpy array, image with uint8 pixels in [0,255]. Applied defocus blur.


def _get_test_names_from_class(self, test):
    try:
        test._pre_run()
        if test.tests:
            return list(test.tests)
        else:
            return test.get_existing_test_names()
    finally:
        test._clean_up()

Returns the names of all the tests in a test class.

Args:
test: module, the test module to print names from.


def measure_each(*qubits: raw_types.Qid,
                 key_func: Callable[[raw_types.Qid], str] = str
                 ) -> List[gate_operation.GateOperation]:

    return [MeasurementGate(1, key_func(q)).on(q) for q in qubits]

Returns a list of operations individually measuring the given qubits.

The qubits are measured in the computational basis.

Args:
*qubits: The qubits to measure.
key_func: Determines the key of the measurements of each qubit. Takes
the qubit and returns the key for that qubit. Defaults to str.

Returns:
A list of operations individually measuring the given qubits.


def apply(self, parent_environ=None):
    interpreter = Python(target_environ=os.environ)
    executor = self._create_executor(interpreter, parent_environ)
    self._execute(executor)
    interpreter.apply_environ()

Apply the context to the current python session.

Note that this updates os.environ and possibly sys.path, if
`parent_environ` is not provided.

Args:
parent_environ: Environment to interpret the context within,
defaults to os.environ if None.


def subSample(self,Irow=None,Icol_geno=None,Icol_pheno=None):

        C = copy.copy(self)
        if Irow is not None:
            C.genoM = C.genoM[Irow]
            C.phenoM = C.phenoM[Irow]
            C.sample_ID = C.sample_ID[Irow]
        if Icol_geno is not None:
            C.genoM = C.genoM[:,Icol_geno]
            C.genoPos = C.genoPos[Icol_geno]
            C.genoChrom = C.genoChrom[Icol_geno]
            C.genoPos_cum = C.genoPos_cum[Icol_geno]
        if Icol_pheno is not None:
            C.phenoM = C.phenoM[:,Icol_pheno]
            C.phenotype_ID = C.phenotype_ID[Icol_pheno]
            if C.eqtl:
                C.geneID   = C.geneID[Icol_pheno]
                C.gene_pos = C.gene_pos[Icol_pheno,:]
                C.geneIDs  = list(set(C.geneID))
            if C.E != None:
                C.E  = C.E[Icol_pheno]
                C.Es = list(set(C.E))

        C.N = C.genoM.shape[0]
        C.S = C.genoM.shape[1]
        C.P = C.phenoM.shape[1]
        return C

sample a particular set of individuals (Irow) or phenotypes (Icol_pheno) or genotypes (Icol_geno)

Args:
Irow:           indices for a set of individuals
Icol_pheno:     indices for a set of phenotypes
Icol_geno:      indices for a set of SNPs

Returns:
QTLdata opject holding the specified subset of the data


def sort_servers_closest(servers: Sequence[str]) -> Sequence[Tuple[str, float]]:

    if not {urlparse(url).scheme for url in servers}.issubset({'http', 'https'}):
        raise TransportError('Invalid server urls')

    get_rtt_jobs = set(
        gevent.spawn(lambda url: (url, get_http_rtt(url)), server_url)
        for server_url
        in servers
    )

    gevent.joinall(get_rtt_jobs, raise_error=False)
    sorted_servers: List[Tuple[str, float]] = sorted(
        (job.value for job in get_rtt_jobs if job.value[1] is not None),
        key=itemgetter(1),
    )
    log.debug('Matrix homeserver RTT times', rtt_times=sorted_servers)
    return sorted_servers

Sorts a list of servers by http round-trip time

Params:
servers: sequence of http server urls
Returns:
sequence of pairs of url,rtt in seconds, sorted by rtt, excluding failed servers
(possibly empty)


def to_string(cls, error_code):

        if error_code == cls.RTT_ERROR_CONTROL_BLOCK_NOT_FOUND:
            return 'The RTT Control Block has not yet been found (wait?)'
        return super(JLinkRTTErrors, cls).to_string(error_code)

Returns the string message for the given error code.

Args:
cls (JLinkRTTErrors): the ``JLinkRTTErrors`` class
error_code (int): error code to convert

Returns:
An error string corresponding to the error code.

Raises:
ValueError: if the error code is invalid.


def set_exception(self, exception):

        if self.done():
            raise RuntimeError("set_exception can only be called once.")

        self._exception = exception
        self._trigger()

Set the result of the future to the given exception.

Args:
exception (:exc:`Exception`): The exception raised.


def main(args):

    args = parse_args(args)
    setup_logging(args.loglevel)
    _logger.debug("Starting crazy calculations...")
    print("The {}-th Fibonacci number is {}".format(args.n, fib(args.n)))
    _logger.info("Script ends here")

Main entry point allowing external calls

Args:
args ([str]): command line parameter list


def GetArtifact(self, name):
    self._CheckDirty()
    result = self._artifacts.get(name)
    if (not result):
        raise rdf_artifacts.ArtifactNotRegisteredError(('Artifact %s missing from registry. You may need to sync the artifact repo by running make in the artifact directory.' % name))
    return result

Get artifact by name.

Args:
name: artifact name string.

Returns:
artifact object.
Raises:
ArtifactNotRegisteredError: if artifact doesn't exist in the registy.


def fetch_service_config(service_name=None, service_version=None):
    if (not service_name):
        service_name = _get_env_var_or_raise(_SERVICE_NAME_ENV_KEY)
    if (not service_version):
        service_version = _get_service_version(_SERVICE_VERSION_ENV_KEY, service_name)
    _logger.debug(u'Contacting Service Management API for service %s version %s', service_name, service_version)
    response = _make_service_config_request(service_name, service_version)
    _logger.debug(u'obtained service json from the management api:\n%s', response.data)
    service = encoding.JsonToMessage(messages.Service, response.data)
    _validate_service_config(service, service_name, service_version)
    return service

Fetches the service config from Google Service Management API.

Args:
service_name: the service name. When this argument is unspecified, this
method uses the value of the "SERVICE_NAME" environment variable as the
service name, and raises ValueError if the environment variable is unset.
service_version: the service version. When this argument is unspecified,
this method uses the value of the "SERVICE_VERSION" environment variable
as the service version, and raises ValueError if the environment variable
is unset.

Returns: the fetched service config JSON object.

Raises:
ValueError: when the service name/version is neither provided as an
argument or set as an environment variable; or when the fetched service
config fails validation.
Exception: when the Google Service Management API returns non-200 response.


def get_by_name(self, name):
    san_managers = self._client.get_all()
    result = [x for x in san_managers if (x['name'] == name)]
    return (result[0] if result else None)

Gets a SAN Manager by name.

Args:
name: Name of the SAN Manager

Returns:
dict: SAN Manager.


def getbalance(self, user_id='', as_decimal=True):
    balance = unicode(self.rpc.call('getbalance', user_id))
    self.logger.debug((('"' + user_id) + '"'), self.coin, 'balance:', balance)
    if as_decimal:
        return Decimal(balance)
    else:
        return balance

Calculate the total balance in all addresses belonging to this user.

Args:
user_id (str): this user's unique identifier
as_decimal (bool): balance is returned as a Decimal if True (default)
or a string if False

Returns:
str or Decimal: this account's total coin balance


def add_config(self, slot, config_id, config_type, value):

        if slot not in self.config_database:
            self.config_database[slot] = {}

        self.config_database[slot][config_id] = (config_type, value)

Add a config variable assignment to this sensor graph.

Args:
slot (SlotIdentifier): The slot identifier that this config
variable is assigned to.
config_id (int): The 16-bit id of this config_id
config_type (str): The type of the config variable, currently
supported are fixed width integer types, strings and binary
blobs.
value (str|int|bytes): The value to assign to the config variable.


def serialize(optimizer):
    return serialization_lib.serialize_keras_object(optimizer)

Returns the optimizer configuration as a Python dict.

Args:
optimizer: An `Optimizer` instance to serialize.

Returns:
Python dict which contains the configuration of the optimizer.


def _validate_isvalid_t_range(self, isvalid_t_range, field, values):

        if all([isinstance(v, (float, int)) for v in values]):

            T_low = Q_(values[0], 'K')
            T_mid = Q_(values[1], 'K')
            T_hi = Q_(values[2], 'K')
        elif all([isinstance(v, str) for v in values]):
            T_low = Q_(values[0])
            T_mid = Q_(values[1])
            T_hi = Q_(values[2])
        else:
            self._error(field, 'The temperatures in the range must all be either with units or '
                               'without units, they cannot be mixed')
            return False

        if min([T_low, T_mid, T_hi]) != T_low:
            self._error(field, 'The first element of the T_range must be the lower limit')
        if max([T_low, T_mid, T_hi]) != T_hi:
            self._error(field, 'The last element of the T_range must be the upper limit')

Checks that the temperature ranges given for thermo data are valid
Args:
isvalid_t_range (`bool`): flag from schema indicating T range is to be checked
field (`str`): T_range
values (`list`): List of temperature values indicating low, middle, and high ranges

The rule's arguments are validated against this schema:
{'isvalid_t_range': {'type': 'bool'}, 'field': {'type': 'str'},
'value': {'type': 'list'}}


def select(self, children: List['ColumnExpressionBuilder']) -> 'ColumnExpressionBuilder':
    if self._column_name:
        raise AttributeError(f'select() must not be called on a builder with name set already. Got select called on {str(self)}.')
    if self._builder.return_type.returns_collection() and (not self._needs_unnest):
        raise AttributeError(f'select() must not be called on a builder which returns collection. Got select called on {str(self)}.')
    if not isinstance(self._builder.return_type, _fhir_path_data_types.StructureDataType):
        raise AttributeError(f'select() can only be called on a FHIR path which returns a StructureDataType. Got type of {self._builder.return_type} from {str(self)}.')
    for child_builder in children:
        if not child_builder.column_name and (not child_builder.children):
            raise AttributeError(f'select() child builders must either have name names or children. Got {str(child_builder)}')
        if not child_builder.fhir_path.startswith(self._builder.fhir_path):
            raise AttributeError(f'select() child builders must be built by starting with their parent FHIR path. Got {str(child_builder)} in {self._builder.fhir_path}.')
        path_to_replace = self._builder.fhir_path
        reference_node = self._builder.node
        child_builder.node.replace_operand(path_to_replace, _evaluation.ReferenceNode(self._builder.node.context, reference_node, unnested=True))
    return ColumnExpressionBuilder(self._builder, self._column_name, children, self._needs_unnest, True)

The select() function.

Selects the child fields from a FHIR path which returns a StructureDataType.
Once this function is called, the FHIR path is sealed to be immutable.

Args:
children: A list of selected FHIR Path.

Returns:
A new ColumnExpressionBuilder with the given children.


def inverse(self):
    ss = self._sum_of_squares()
    if (ss > 0):
        return self.__class__(array=(self._vector_conjugate() / ss))
    else:
        raise ZeroDivisionError('a zero quaternion (0 + 0i + 0j + 0k) cannot be inverted')

Inverse of the quaternion object, encapsulated in a new instance.

For a unit quaternion, this is the inverse rotation, i.e. when combined with the original rotation, will result in the null rotation.

Returns:
A new Quaternion object representing the inverse of this object


def _is_executing(self) -> bool:
    executors = self._executor.transform_executor_services.executors
    if not executors:
        return False
    for transform_executor in executors:
        if not transform_executor.blocked:
            return True
    return False

Checks whether the job is still executing.

Returns:
True if there is at least one non-blocked TransformExecutor active.


def update_script(self, script_body):
    uri = '{}/script'.format(self.data['uri'])
    return self._helper.update(script_body, uri=uri)

Updates the configuration script of the enclosure-group with the specified URI.

Args:
id_or_uri: Resource id or resource uri.
script_body:  Configuration script.

Returns:
dict: Updated enclosure group.


def console_map_ascii_codes_to_font(firstAsciiCode: int, nbCodes: int, fontCharX: int, fontCharY: int) -> None:
    lib.TCOD_console_map_ascii_codes_to_font(_int(firstAsciiCode), nbCodes, fontCharX, fontCharY)

Remap a contiguous set of codes to a contiguous set of tiles.

Both the tile-set and character codes must be contiguous to use this
function.  If this is not the case you may want to use
:any:`console_map_ascii_code_to_font`.

Args:
firstAsciiCode (int): The starting character code.
nbCodes (int): The length of the contiguous set.
fontCharX (int): The starting X tile coordinate on the loaded tileset.
0 is the leftmost tile.
fontCharY (int): The starting Y tile coordinate on the loaded tileset.
0 is the topmost tile.


def get_if_set(self, addresses):

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

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

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

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


def __init__(self, campfire, id, current=False):

        super(User, self).__init__(campfire)
        self.set_data(self._connection.get("users/%s" % id, key="user"))
        self.current = current

Initialize.

Args:
campfire (:class:`Campfire`): Campfire instance
id (str): User ID

Kwargs:
current (bool): Wether user is current user, or not


def tensorflow_version(self):
    return self._reader.tensorflow_version()

TensorFlow version used in the debugged TensorFlow program.

Note: this is not necessarily the same as the version of TensorFlow used to
load the DebugEvent file set.

Returns:
TensorFlow version used by the debugged program, as a `str`.


def get_candidates(self, input_ids: torch.LongTensor) -> Tuple[torch.LongTensor, Optional[torch.FloatTensor]]:
    raise NotImplementedError(f'{self.__class__} is an abstract class. Only classes inheriting this class can call `get_candidates`.')

Fetches the candidates to be tried for the current input.

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

Return:
`torch.LongTensor` of shape `(batch_size, candidate_length)` containing the candidate sequences to be
assessed by the model and, optionally, a `torch.FloatTensor` of shape `(batch_size, candidate_length,
vocabulary_size)` containing the logits associated to each candidate.


def get_tokens(self, *, payer_id, credit_card_token_id, start_date, end_date):

        payload = {
            "language": self.client.language.value,
            "command": PaymentCommand.GET_TOKENS.value,
            "merchant": {
                "apiLogin": self.client.api_login,
                "apiKey": self.client.api_key
            },
            "creditCardTokenInformation": {
                "payerId": payer_id,
                "creditCardTokenId": credit_card_token_id,
                "startDate": start_date.strftime('%Y-%m-%dT%H:%M:%S'),
                "endDate": end_date.strftime('%Y-%m-%dT%H:%M:%S')
            },
            "test": self.client.is_test
        }
        return self.client._post(self.url, json=payload)

With this functionality you can query previously the Credit Cards Token.

Args:
payer_id:
credit_card_token_id:
start_date:
end_date:

Returns:


def get_public_ip(access_token, subscription_id, resource_group, ip_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Network/',
                        'publicIPAddresses/', ip_name,
                        '?api-version=', NETWORK_API])
    return do_get(endpoint, access_token)

Get details about the named public ip address.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
public_ip_name (str): Name of the public ip address resource.

Returns:
HTTP response. Public IP address JSON body.


def __truediv__(self, other: 'TensorFluent') -> 'TensorFluent':

        return self._binary_op(self, other, tf.divide, tf.float32)

Returns a TensorFluent for the division arithmetic operator.

Args:
self: The first operand.
other: The second operand.

Returns:
A TensorFluent wrapping the operator's output.


def are_equal(self, sp1, sp2):

        set1 = set(sp1.elements)
        set2 = set(sp2.elements)
        return set1.issubset(set2) or set2.issubset(set1)

True if there is some overlap in composition between the species

Args:
sp1: First species. A dict of {specie/element: amt} as per the
definition in Site and PeriodicSite.
sp2: Second species. A dict of {specie/element: amt} as per the
definition in Site and PeriodicSite.

Returns:
True always


def destroy_sg(app='', env='', region='', **_):

    vpc = get_vpc_id(account=env, region=region)

    url = '{api}/securityGroups/{env}/{region}/{app}'.format(api=API_URL, env=env, region=region, app=app)
    payload = {'vpcId': vpc}
    security_group = requests.get(url, params=payload, verify=GATE_CA_BUNDLE, cert=GATE_CLIENT_CERT)

    if not security_group:
        LOG.info('Nothing to delete.')
    else:
        LOG.info('Found Security Group in %(region)s: %(name)s', security_group)

        destroy_request = get_template('destroy/destroy_sg.json.j2', app=app, env=env, region=region, vpc=vpc)
        wait_for_task(destroy_request)

    return True

Destroy Security Group.

Args:
app (str): Spinnaker Application name.
env (str): Deployment environment.
region (str): Region name, e.g. us-east-1.

Returns:
True upon successful completion.


def coord(self):
    if (not self.require_3D):
        self.fail(AttributeError('use 3D coordinate in 2D descriptor'))
    return self._context.get_coord(self)

Get 3D coordinate.

Returns:
numpy.array[3, N]: coordinate matrix


def _flatten_summand_list(kernels):
    flattened = []
    for k in kernels:
        if isinstance(k, _SumKernel):
            flattened += k.kernels
        else:
            flattened.append(k)
    return flattened

Flatten a list of kernels which may contain _SumKernel instances.

Args:
kernels: Python list of `PositiveSemidefiniteKernel` instances

Returns:
Python list containing the elements of kernels, with any _SumKernel
instances replaced by their `kernels` property contents.


def bcs_parameters(n_site, n_fermi, u, t):
    wave_num = np.linspace(0, 1, n_site, endpoint=False)
    hop_erg = (((- 2) * t) * np.cos(((2 * np.pi) * wave_num)))
    fermi_erg = hop_erg[(n_fermi
    hop_erg = (hop_erg - fermi_erg)

    def _bcs_gap(x):
        'Defines the self-consistent equation for the BCS wavefunction.\n\n        Args:\n            x: the superconducting gap\n        '
        s = 0.0
        for i in range(n_site):
            s += (1.0 / np.sqrt(((hop_erg[i] ** 2) + (x ** 2))))
        return (1 + ((s * u) / (2 * n_site)))
    delta = scipy.optimize.bisect(_bcs_gap, 0.01, (10000.0 * abs(u)))
    bcs_v = np.sqrt((0.5 * (1 - (hop_erg / np.sqrt(((hop_erg ** 2) + (delta ** 2)))))))
    bog_theta = np.arcsin(bcs_v)
    return (delta, bog_theta)

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

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

Returns:
float delta, List[float] bog_theta