def _get_and_write_archive(self, hunt, output_file_path):

    hunt_archive = hunt.GetFilesArchive()
    hunt_archive.WriteToFile(output_file_path)

Gets and writes a hunt archive.

Function is necessary for the _check_approval_wrapper to work.

Args:
hunt: The GRR hunt object.
output_file_path: The output path where to write the Hunt Archive.


def derive_identity_arf(name, arf):
    from sherpa.astro.data import DataARF
    from sherpa.astro.instrument import ARF1D
    darf = DataARF(name, arf.energ_lo, arf.energ_hi, np.ones(arf.specresp.shape), arf.bin_lo, arf.bin_hi, arf.exposure, header=None)
    return ARF1D(darf, pha=arf._pha)

Create an "identity" ARF that has uniform sensitivity.

*name*
The name of the ARF object to be created; passed to Sherpa.
*arf*
An existing ARF object on which to base this one.
Returns:
A new ARF1D object that has a uniform spectral response vector.

In many X-ray observations, the relevant background signal does not behave
like an astrophysical source that is filtered through the telescope's
response functions. However, I have been unable to get current Sherpa
(version 4.9) to behave how I want when working with backround models that
are *not* filtered through these response functions. This function
constructs an "identity" ARF response function that has uniform sensitivity
as a function of detector channel.


def clinvar_submission_header(submission_objs, csv_type):
    complete_header = {}
    custom_header = {}
    if (csv_type == 'variant_data'):
        complete_header = CLINVAR_HEADER
    else:
        complete_header = CASEDATA_HEADER
    for (header_key, header_value) in complete_header.items():
        for clinvar_obj in submission_objs:
            for (key, value) in clinvar_obj.items():
                if ((not (header_key in custom_header)) and (header_key == key)):
                    custom_header[header_key] = header_value
    return custom_header

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

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

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


def get_available_storage_systems(self, start=0, count=(- 1), filter='', sort='', **kwargs):
    uri = self._helper.build_uri_with_query_string(kwargs, '/available-storage-systems')
    return self._helper.get_all(start=start, count=count, filter=filter, sort=sort, uri=uri)

Retrieves the list of the storage systems and their associated volumes available to the server profile
based on the given server hardware type and enclosure group.

Args:
count:
The number of resources to return. A count of -1 requests all items. The actual number of items in
the response may differ from the requested count if the sum of start and count exceed the total
number of items.
start:
The first item to return, using 0-based indexing. If not specified, the default is 0 - start with the
first available item.
filter (list or str):
A general filter/query string to narrow the list of items returned. The default is no filter; all
resources are returned.
sort:
The sort order of the returned data set. By default, the sort order is based on create time, with the
oldest entry first.
enclosureGroupUri (str):
The URI of the enclosure group associated with the resource.
serverHardwareTypeUri (str):
The URI of the server hardware type associated with the resource.

Returns:
list: Available storage systems.


def construct_field(model_name, field_name, field_type, all_models, **kwargs):
    field_type_parts = field_type.split('->')
    _field_type = field_type_parts[0].strip().split('[]')[0].strip()
    back_populates = (field_type_parts[1].strip() if (len(field_type_parts) > 1) else None)
    error_context = kwargs.pop('error_context', StatikErrorContext())
    _kwargs = copy(kwargs)
    _kwargs['back_populates'] = back_populates
    if ((_field_type not in FIELD_TYPES) and (_field_type not in all_models)):
        raise InvalidFieldTypeError(model_name, field_name, context=error_context)
    if (_field_type in FIELD_TYPES):
        return FIELD_TYPES[_field_type](field_name, **_kwargs)
    if field_type_parts[0].strip().endswith('[]'):
        return StatikManyToManyField(field_name, _field_type, **_kwargs)
    return StatikForeignKeyField(field_name, _field_type, **_kwargs)

Helper function to build a field from the given field name and
type.

Args:
model_name: The name of the model for which we're building this field.
field_name: The name of the field to build.
field_type: A string indicator as to which field type must be built.
all_models: A list containing the names of all of the models, which
will help us when building foreign key lookups.


def read_config_string_options(obj: Any, parser: ConfigParser, section: str, options: Iterable[str], default: str=None) -> None:
    for o in options:
        setattr(obj, o, get_config_string_option(parser, section, o, default=default))

Reads config options and writes them as attributes of ``obj``, with
attribute names as per ``options``.

Args:
obj: the object to modify
parser: instance of :class:`ConfigParser`
section: section name within config file
options: option (variable) names within that section
default: value to use for any missing options

Returns:


def __init__(self, channel):

        self.AnnotateVideo = channel.unary_unary(
            "/google.cloud.videointelligence.v1beta1.VideoIntelligenceService/AnnotateVideo",
            request_serializer=google_dot_cloud_dot_videointelligence__v1beta1_dot_proto_dot_video__intelligence__pb2.AnnotateVideoRequest.SerializeToString,
            response_deserializer=google_dot_longrunning_dot_operations__pb2.Operation.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def send_email_message(self, recipient, subject, html_message, text_message, sender_email, sender_name):

        sender = '"%s" <%s>' % (sender_name, sender_email) if sender_name else sender_email

        if not current_app.testing:
            try:

                from flask_mail import Message
                message = Message(
                    subject,
                    sender=sender,
                    recipients=[recipient],
                    html=html_message,
                    body=text_message)

                self.mail.send(message)

            except (socket.gaierror, socket.error) as e:
                raise EmailError('SMTP Connection error: Check your MAIL_SERVER and MAIL_PORT settings.')
            except smtplib.SMTPAuthenticationError:
                raise EmailError('SMTP Authentication error: Check your MAIL_USERNAME and MAIL_PASSWORD settings.')

Send email message via Flask-Mail.

Args:
recipient: Email address or tuple of (Name, Email-address).
subject: Subject line.
html_message: The message body in HTML.
text_message: The message body in plain text.


def get_filename(self, task, default_ext):

        url_path = urlparse(task['file_url'])[2]
        extension = url_path.split('.')[-1] if '.' in url_path else default_ext
        file_idx = self.fetched_num + self.file_idx_offset
        return '{:06d}.{}'.format(file_idx, extension)

Set the path where the image will be saved.

The default strategy is to use an increasing 6-digit number as
the filename. You can override this method if you want to set custom
naming rules. The file extension is kept if it can be obtained from
the url, otherwise ``default_ext`` is used as extension.

Args:
task (dict): The task dict got from ``task_queue``.

Output:
Filename with extension.


def get_voigt_dict(rank):

        vdict = {}
        for ind in itertools.product(*[range(3)] * rank):
            v_ind = ind[:rank % 2]
            for j in range(rank
                pos = rank % 2 + 2 * j
                v_ind += (reverse_voigt_map[ind[pos:pos + 2]],)
            vdict[ind] = v_ind
        return vdict

Returns a dictionary that maps indices in the tensor to those
in a voigt representation based on input rank

Args:
rank (int): Tensor rank to generate the voigt map


def visualize_instance_html(self,
                                exp,
                                label,
                                div_name,
                                exp_object_name,
                                show_table=True,
                                show_all=False):

        if not show_table:
            return ''
        weights = [0] * len(self.feature_names)
        for x in exp:
            weights[x[0]] = x[1]
        out_list = list(zip(self.exp_feature_names,
                            self.feature_values,
                            weights))
        if not show_all:
            out_list = [out_list[x[0]] for x in exp]
        ret = u % (exp_object_name, json.dumps(out_list, ensure_ascii=False), label, div_name)
        return ret

Shows the current example in a table format.

Args:
exp: list of tuples [(id, weight), (id,weight)]
label: label id (integer)
div_name: name of div object to be used for rendering(in js)
exp_object_name: name of js explanation object
show_table: if False, don't show table visualization.
show_all: if True, show zero-weighted features in the table.


def sg_symbol_from_int_number(int_number, hexagonal=True):

    syms = []
    for n, v in get_symm_data("space_group_encoding").items():
        if v["int_number"] == int_number:
            syms.append(n)
    if len(syms) == 0:
        raise ValueError("Invalid international number!")
    if len(syms) == 2:
        if hexagonal:
            syms = list(filter(lambda s: s.endswith("H"), syms))
        else:
            syms = list(filter(lambda s: not s.endswith("H"), syms))
    return syms.pop()

Obtains a SpaceGroup name from its international number.

Args:
int_number (int): International number.
hexagonal (bool): For rhombohedral groups, whether to return the
hexagonal setting (default) or rhombohedral setting.

Returns:
(str) Spacegroup symbol


def get_monochrome_handler(extranames: List[str]=None, with_process_id: bool=False, with_thread_id: bool=False, stream: TextIO=None) -> logging.StreamHandler:
    fmt = '%(asctime)s.%(msecs)03d'
    if (with_process_id or with_thread_id):
        procinfo = []
        if with_process_id:
            procinfo.append('p%(process)d')
        if with_thread_id:
            procinfo.append('t%(thread)d')
        fmt += ' [{}]'.format('.'.join(procinfo))
    extras = ((':' + ':'.join(extranames)) if extranames else '')
    fmt += ' %(name)s{extras}:%(levelname)s: '.format(extras=extras)
    fmt += '%(message)s'
    f = logging.Formatter(fmt, datefmt=LOG_DATEFMT, style='%')
    h = logging.StreamHandler(stream)
    h.setFormatter(f)
    return h

Gets a monochrome log handler using a standard format.

Args:
extranames: additional names to append to the logger's name
with_process_id: include the process ID in the logger's name?
with_thread_id: include the thread ID in the logger's name?
stream: ``TextIO`` stream to send log output to

Returns:
the :class:`logging.StreamHandler`


def _use_composite_impl(fast, tensor_shape):
    if fast is False:
        return False
    batch_shape = tensor_shape[:-2]
    matrix_shape = tensor_shape[-2:]
    if not tensor_shape.is_fully_defined():
        return True
    tensor_size = tensor_shape.num_elements() * matrix.dtype.size
    is_io_bound = batch_shape.num_elements() > np.min(matrix_shape)
    L2_CACHE_SIZE_GUESSTIMATE = 256000
    if tensor_size > L2_CACHE_SIZE_GUESSTIMATE and is_io_bound:
        return False
    else:
        return True

Determines whether to use the composite or specialized CPU kernel.

When the total size of the tensor is larger than the cache size and the
batch size is large compared to the smallest matrix dimension, then the
composite implementation is inefficient since it has to read the entire
tensor from memory multiple times. In this case we fall back to the
original CPU kernel, which does all the computational steps on each
matrix separately.

Only fast mode is supported by the composite impl, so `False` is returned
if `fast` is `False`.

Args:
fast: bool indicating if fast mode in the solver was requested.
tensor_shape: The shape of the tensor.

Returns:
True if the composite impl should be used. False otherwise.


def received_char_count(self, count):

        n1 = count/100
        n2 = (count-(n1*100))/10
        n3 = (count-((n1*100)+(n2*10)))
        self.send('^PC'+chr(n1)+chr(n2)+chr(n3))

Set recieved char count limit

Args:
count: the amount of received characters you want to stop at.
Returns:
None
Raises:
None


def SendSerializedMessage(self, message):
    try:
        ba = Helper.ToArray(message)
        ba2 = binascii.unhexlify(ba)
        self.bytes_out += len(ba2)
        self.transport.write(ba2)
    except Exception as e:
        logger.debug(f'Could not send serialized message {e}')

Send the `message` to the remote client.

Args:
message (neo.Network.Message):


def get(self, object_id):
    if object_id is None:
        return
    return self._obj_ids_to_obj.get(object_id)

Given a shared object ID, returns a previously instantiated object.

Args:
object_id: shared object ID to use when attempting to find already-loaded
object.

Returns:
The object, if we've seen this ID before. Else, `None`.


def descriptors(package):
    from os import path
    dpath = _descriptor_path(package)
    if path.isfile(dpath):
        import json
        with open(dpath) as f:
            jdb = json.load(f)
        return jdb
    else:
        return None

Returns a dictionary of descriptors deserialized from JSON for the
specified package.

Args:
package (str): name of the python package to get settings for.


def compressed_char(self, action):

        if action == 'on':
            action = 15
        elif action == 'off':
            action = 18
        else:
            raise RuntimeError('Invalid action for function compressedChar. Options are on and off')
        self.send(chr(action))

Enable/cancel compressed character printing

Args:
action: Enable or disable compressed character printing. Options are 'on' and 'off'
Returns:
None
Raises:
RuntimeError: Invalid action.


def _get_apis(self, apis):

        ret = []

        for data in apis:
            ret.append(SpecificationAPI(specification=self, data=data))

        return sorted(ret, key=lambda x: x.rest_name[1:])

Process apis for the given model

Args:
model: the model processed
apis: the list of apis availble for the current model
relations: dict containing all relations between resources


def timestamp_any(value):

    return int(calendar.timegm(dateutil.parser.parse(value).utctimetuple()))

Convert timestamp string to time in seconds since epoch.

Most timestamps strings are supported in fact this wraps the
dateutil.parser.parse() method. This is SLOW use the other timestamp_*()
functions if possible.

Args:
value: A timestamp string.

Returns:
The time in seconds since epoch as an integer.


def is_user_enrolled(cls, user, course_id, course_mode):
    enrollment_client = EnrollmentApiClient()
    try:
        enrollments = enrollment_client.get_course_enrollment(user.username, course_id)
        if (enrollments and (course_mode == enrollments.get('mode'))):
            return True
    except HttpClientError as exc:
        logging.error('Error while checking enrollment status of user %(user)s: %(message)s', dict(user=user.username, message=str(exc)))
    except KeyError as exc:
        logging.warning('Error while parsing enrollment data of user %(user)s: %(message)s', dict(user=user.username, message=str(exc)))
    return False

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

Args:
user: The user whose enrollment needs to be checked
course_mode: The mode with which the enrollment should be checked
course_id: course id of the course where enrollment should be checked.

Returns:
Boolean: Whether or not enrollment exists


def emulate(self, context=None, start=None, end=None, arch_mode=None, hooks=None, max_instrs=None, print_asm=False):

        if arch_mode is not None:

            self._load(arch_mode=arch_mode)

        context = context if context else {}

        start_addr = start if start else self.binary.ea_start
        end_addr = end if end else self.binary.ea_end

        hooks = hooks if hooks else {}

        for reg, val in context.get('registers', {}).items():
            self.ir_emulator.registers[reg] = val

        for addr, val in context.get('memory', {}).items():
            self.ir_emulator.memory.write(addr, 4, val)

        self.emulator.emulate(start_addr, end_addr, hooks, max_instrs, print_asm)

        context_out = {
            'registers': {},
            'memory': {}
        }

        for reg, val in self.ir_emulator.registers.items():
            context_out['registers'][reg] = val

        return context_out

Emulate native code.

Args:
context (dict): Processor context (register and/or memory).
start (int): Start address.
end (int): End address.
arch_mode (int): Architecture mode.
hooks (dict): Hooks by address.
max_instrs (int): Maximum number of instructions to execute.
print_asm (bool): Print asm.

Returns:
dict: Processor context.


def _check_nested_callables(dictionary, object_name):
    for (key, entry) in six.iteritems(dictionary):
        if hasattr(entry, 'items'):
            _check_nested_callables(entry, object_name)
        elif (not callable(entry)):
            raise TypeError("{} for '{}' is not a callable function or dictionary".format(object_name, key))

Checks if all items in the dictionary and in subdictionaries are callables.

Args:
dictionary: Dictionary of callables or other dictionaries with callables.
object_name: The name of the object that is expected in the dictionary.
E.g. 'Initializer', 'Partitioner' or 'Regularizer'. The first letter
should be capitalised as this will be the first word in the error message.

Raises:
TypeError: If the dictionary contains something that is not either a
dictionary or a callable.


async def connect(self, client_id, conn_string):

        conn_id = self.adapter.unique_conn_id()

        self._client_info(client_id)

        await self.adapter.connect(conn_id, conn_string)
        self._hook_connect(conn_string, conn_id, client_id)

Connect to a device on behalf of a client.

See :meth:`AbstractDeviceAdapter.connect`.

Args:
client_id (str): The client we are working for.
conn_string (str): A connection string that will be
passed to the underlying device adapter to connect.

Raises:
DeviceServerError: There is an issue with your client_id.
DeviceAdapterError: The adapter had an issue connecting.


def parse(self, string, strict=True):
    if isinstance(string, bytes):
        errors = ('strict' if strict else 'replace')
        string = string.decode(self.encoding, errors=errors)
    if (not self.raw):
        self.raw = string
    else:
        self.raw += string
    lines = unfold_lines(string).splitlines()
    for line in lines:
        if line:
            if (':' not in line):
                if strict:
                    raise ValueError('Field missing colon.')
                else:
                    continue
            (name, value) = line.split(':', 1)
            name = name.strip()
            value = value.strip()
            self.add(name, value)

Parse the string or bytes.

Args:
strict (bool): If True, errors will not be ignored

Raises:
:class:`ValueError` if the record is malformed.


def institute(self, institute_id):
    LOG.debug('Fetch institute {}'.format(institute_id))
    institute_obj = self.institute_collection.find_one({'_id': institute_id})
    if (institute_obj is None):
        LOG.debug('Could not find institute {0}'.format(institute_id))
    return institute_obj

Featch a single institute from the backend

Args:
institute_id(str)

Returns:
Institute object


def _sections_to_variance_sections(self, sections_over_time):
    variance_sections = []
    for i in range(len(sections_over_time[0])):
        time_sections = [sections[i] for sections in sections_over_time]
        variance = np.var(time_sections, axis=0)
        variance_sections.append(variance)
    return variance_sections

Computes the variance of corresponding sections over time.

Returns:
a list of np arrays.


def to_processor(self) -> Processor:
    return _ProcessorWrapper(map_processor.map_part_function(_chain_part_processors([self], task_name=self.key_prefix)))

Converts this PartProcessor to a Processor.

Adds status and debug stream to the output streams.

Returns:
a processor that will run the part processor for each part concurrently
in the input stream.


def distort_image(image, height, width, bbox, thread_id=0, scope=None):
    with tf.name_scope(values=[image, height, width, bbox], name=scope, default_name='distort_image'):
        if (not thread_id):
            image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0), bbox)
            tf.summary.image('image_with_bounding_boxes', image_with_box)
        sample_distorted_bounding_box = tf.image.sample_distorted_bounding_box(tf.shape(image), bounding_boxes=bbox, min_object_covered=0.1, aspect_ratio_range=[0.75, 1.33], area_range=[0.05, 1.0], max_attempts=100, use_image_if_no_bounding_boxes=True)
        (bbox_begin, bbox_size, distort_bbox) = sample_distorted_bounding_box
        if (not thread_id):
            image_with_distorted_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0), distort_bbox)
            tf.summary.image('images_with_distorted_bounding_box', image_with_distorted_box)
        distorted_image = tf.slice(image, bbox_begin, bbox_size)
        resize_method = (thread_id % 4)
        distorted_image = tf.image.resize_images(distorted_image, [height, width], method=resize_method)
        distorted_image.set_shape([height, width, 3])
        if (not thread_id):
            tf.summary.image('cropped_resized_image', tf.expand_dims(distorted_image, 0))
        distorted_image = tf.image.random_flip_left_right(distorted_image)
        distorted_image = distort_color(distorted_image, thread_id)
        if (not thread_id):
            tf.summary.image('final_distorted_image', tf.expand_dims(distorted_image, 0))
        return distorted_image

Distort one image for training a network.

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

Args:
image: 3-D float Tensor of image
height: integer
width: integer
bbox: 3-D float Tensor of bounding boxes arranged [1, num_boxes, coords]
where each coordinate is [0, 1) and the coordinates are arranged
as [ymin, xmin, ymax, xmax].
thread_id: integer indicating the preprocessing thread.
scope: Optional scope for name_scope.
Returns:
3-D float Tensor of distorted image used for training.


def coord_list_mapping(subset, superset, atol=1e-8):

    c1 = np.array(subset)
    c2 = np.array(superset)
    inds = np.where(np.all(np.isclose(c1[:, None, :], c2[None, :, :], atol=atol),
                           axis=2))[1]
    result = c2[inds]
    if not np.allclose(c1, result, atol=atol):
        if not is_coord_subset(subset, superset):
            raise ValueError("subset is not a subset of superset")
    if not result.shape == c1.shape:
        raise ValueError("Something wrong with the inputs, likely duplicates "
                         "in superset")
    return inds

Gives the index mapping from a subset to a superset.
Subset and superset cannot contain duplicate rows

Args:
subset, superset: List of coords

Returns:
list of indices such that superset[indices] = subset


def convert_coco_poly_to_mask(segmentations, height: int, width: int) -> np.ndarray:
    try:
        from pycocotools import mask as coco_mask
    except ImportError:
        raise ImportError('Pycocotools is not installed in your environment.')
    masks = []
    for polygons in segmentations:
        rles = coco_mask.frPyObjects(polygons, height, width)
        mask = coco_mask.decode(rles)
        if len(mask.shape) < 3:
            mask = mask[..., None]
        mask = np.asarray(mask, dtype=np.uint8)
        mask = np.any(mask, axis=2)
        masks.append(mask)
    if masks:
        masks = np.stack(masks, axis=0)
    else:
        masks = np.zeros((0, height, width), dtype=np.uint8)
    return masks

Convert a COCO polygon annotation to a mask.

Args:
segmentations (`List[List[float]]`):
List of polygons, each polygon represented by a list of x-y coordinates.
height (`int`):
Height of the mask.
width (`int`):
Width of the mask.


def circuit_to_pdf_using_qcircuit_via_tex(circuit: circuits.Circuit, filepath: str, pdf_kwargs=None, qcircuit_kwargs=None, clean_ext=('dvi', 'ps'), documentclass='article'):
    pdf_kwargs = {'compiler': 'latexmk', 'compiler_args': ['-pdfps'], **({} if (pdf_kwargs is None) else pdf_kwargs)}
    qcircuit_kwargs = ({} if (qcircuit_kwargs is None) else qcircuit_kwargs)
    tex = circuit_to_latex_using_qcircuit(circuit, **qcircuit_kwargs)
    doc = Document(documentclass=documentclass, document_options='dvips')
    doc.packages.append(Package('amsmath'))
    doc.packages.append(Package('qcircuit'))
    doc.append(NoEscape(tex))
    doc.generate_pdf(filepath, **pdf_kwargs)
    for ext in clean_ext:
        try:
            os.remove(((filepath + '.') + ext))
        except (OSError, IOError) as e:
            if (e.errno != errno.ENOENT):
                raise

Compiles the QCircuit-based latex diagram of the given circuit.

Args:
circuit: The circuit to produce a pdf of.
filepath: Where to output the pdf.
pdf_kwargs: The arguments to pass to generate_pdf.
qcircuit_kwargs: The arguments to pass to
circuit_to_latex_using_qcircuit.
clean_ext: The file extensions to clean up after compilation. By
default, latexmk is used with the '-pdfps' flag, which produces
intermediary dvi and ps files.
documentclass: The documentclass of the latex file.


def predict(self, data, initial_args=None):
    request_args = self._create_request_args(data, initial_args)
    response = self.sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args)
    return self._handle_response(response)

Return the inference from the specified endpoint.

Args:
data (object): Input data for which you want the model to provide inference.
If a serializer was specified when creating the RealTimePredictor, the result of the
serializer is sent as input data. Otherwise the data must be sequence of bytes, and
the predict method then sends the bytes in the request body as is.
initial_args (dict[str,str]): Optional. Default arguments for boto3
``invoke_endpoint`` call. Default is None (no default arguments).

Returns:
object: Inference for the given input. If a deserializer was specified when creating
the RealTimePredictor, the result of the deserializer is returned. Otherwise the response
returns the sequence of bytes as is.


def destroy_dns(app='', env='dev', **_):

    client = boto3.Session(profile_name=env).client('route53')

    generated = get_details(app=app, env=env)
    record = generated.dns_elb()

    zone_ids = get_dns_zone_ids(env=env, facing='external')

    for zone_id in zone_ids:
        record_sets = client.list_resource_record_sets(
            HostedZoneId=zone_id, StartRecordName=record, StartRecordType='CNAME', MaxItems='1')

        for found_record in record_sets['ResourceRecordSets']:
            assert destroy_record(client=client, found_record=found_record, record=record, zone_id=zone_id)

    return True

Destroy DNS records.

Args:
app (str): Spinnaker Application name.
env (str): Deployment environment.
regions (str): AWS region.

Returns:
bool: True upon successful completion.


def drain(self, cluster, nodes, max_size):
    if (not nodes):
        return {}
    now = time.time()
    batches = {}
    for node_id in nodes:
        size = 0
        partitions = list(cluster.partitions_for_broker(node_id))
        ready = []
        self._drain_index %= len(partitions)
        start = self._drain_index
        while True:
            tp = partitions[self._drain_index]
            if ((tp in self._batches) and (tp not in self.muted)):
                with self._tp_locks[tp]:
                    dq = self._batches[tp]
                    if dq:
                        first = dq[0]
                        backoff = (bool((first.attempts > 0)) and bool(((first.last_attempt + (self.config['retry_backoff_ms'] / 1000.0)) > now)))
                        if (not backoff):
                            if (((size + first.records.size_in_bytes()) > max_size) and (len(ready) > 0)):
                                break
                            else:
                                batch = dq.popleft()
                                batch.records.close()
                                size += batch.records.size_in_bytes()
                                ready.append(batch)
                                batch.drained = now
            self._drain_index += 1
            self._drain_index %= len(partitions)
            if (start == self._drain_index):
                break
        batches[node_id] = ready
    return batches

Drain all the data for the given nodes and collate them into a list of
batches that will fit within the specified size on a per-node basis.
This method attempts to avoid choosing the same topic-node repeatedly.

Arguments:
cluster (ClusterMetadata): The current cluster metadata
nodes (list): list of node_ids to drain
max_size (int): maximum number of bytes to drain

Returns:
dict: {node_id: list of ProducerBatch} with total size less than the
requested max_size.


def self_adjoint_eig(tensor, name=None):
    e, v = gen_linalg_ops.self_adjoint_eig_v2(tensor, compute_v=True, name=name)
    return (e, v)

Computes the eigen decomposition of a batch of self-adjoint matrices.

Computes the eigenvalues and eigenvectors of the innermost N-by-N matrices
in `tensor` such that
`tensor[...,:,:] * v[..., :,i] = e[..., i] * v[...,:,i]`, for i=0...N-1.

Args:
tensor: `Tensor` of shape `[..., N, N]`. Only the lower triangular part of
each inner inner matrix is referenced.
name: string, optional name of the operation.

Returns:
e: Eigenvalues. Shape is `[..., N]`. Sorted in non-decreasing order.
v: Eigenvectors. Shape is `[..., N, N]`. The columns of the inner most
matrices contain eigenvectors of the corresponding matrices in `tensor`


def add_keywords_from_list(self, keyword_list):
    if (not isinstance(keyword_list, list)):
        raise AttributeError('keyword_list should be a list')
    for keyword in keyword_list:
        self.add_keyword(keyword)

To add keywords from a list

Args:
keyword_list (list(str)): List of keywords to add

Examples:
>>> keyword_processor.add_keywords_from_list(["java", "python"]})
Raises:
AttributeError: If `keyword_list` is not a list.


def elementwise_division(func):
    sparse_func = jax_sparse.sparsify(func)

    @functools.wraps(func)
    def sparse_wrapper(x1, x2):
        if isinstance(x1, jax_sparse.JAXSparse):
            if isinstance(x2, jax_sparse.JAXSparse):
                x1 = x1.todense()
                x2 = x2.todense()
            elif isinstance(x1, jax_sparse.BCOO):
                if not hasattr(x2, 'shape') or len(x2.shape) == 0:
                    return jax_sparse.BCOO((func(x1.data, x2), x1.indices), shape=x1.shape, indices_sorted=x1.indices_sorted, unique_indices=x1.unique_indices)
                else:
                    if not jax_utils.is_in_jax_tracing_scope(x2):
                        x2_zeros_and_nans = jnp.equal(x2, 0)
                        if not jnp.issubdtype(x2.dtype, jnp.integer):
                            x2_zeros_and_nans = jnp.logical_or(x2_zeros_and_nans, jnp.isnan(x2))
                        x2_zeros_and_nans = jax_sparse.bcoo_fromdense(x2_zeros_and_nans, n_batch=x1.n_batch, n_dense=x1.n_dense, index_dtype=x1.indices.dtype)
                        x1 = bcoo_add_indices(x1, x2_zeros_and_nans, sum_duplicates=True)
                    return sparse_func(x1, x2)
            else:
                raise ValueError(f'Unsupported sparse format: {x1.__class__}')
        elif isinstance(x2, jax_sparse.JAXSparse):
            x2 = x2.todense()
        return func(x1, x2)
    return sparse_wrapper

Decorator to add support for `BCOO` sparse tensors to element-wise binary
division and related operators.

This decorator is designed for operations related to the division of two
two operands (e.g. `divide`). It accepts `BCOO` tensors for both the
dividend and the divisor, but handles them differently based on whether they
are the dividend or the divisor.

- If the divisor is sparse, it is densified and the result is dense because
the result contains Inf or Nan outside of the indices of the dividend.
- If the dividend is sparse and the divisor is dense, it finds occurrences
of zeros and NaNs in the divisor. The result may therefore have more
indices than there were in the dividend to return correct values where the
divisor was zero or NaN.
- If the dividend is sparse and the divisor is a scalar, it does the
division element-wise. Note that the result is incorrectly sparse if the
scalar divisor is zero.

Args:
func: The function to wrap.
Returns:
Wrapped function that supports `BCOO` sparse tensors.


def get_workunit(self, ignore_list=None):
    if (ignore_list is None):
        ignore_list = []
    potential_files = self.get_potential_files(ignore_list)
    while (len(potential_files) > 0):
        potential_file = self.select_potential_file(potential_files)
        potential_files.remove(potential_file)
        if self._filter(potential_file):
            continue
        if (self.directory_context.get_file_size(potential_file) == 0):
            continue
        if self.progress_manager.is_done(potential_file):
            self._done.append(potential_file)
            continue
        else:
            try:
                self.progress_manager.lock(potential_file)
            except FileLockedException:
                continue
            self._already_fetched.append(potential_file)
            return self.builder.build_workunit(self.directory_context.get_full_path(potential_file))
    logger.info('No eligible workunits remain to be fetched.')
    raise NoAvailableWorkException()

Gets a new unit of work.

Args:
ignore_list: list(str)
A list of filenames which should be ignored.  Defaults to None.

Returns:
new_workunit: WorkUnit
A new unit of work that has not yet been processed.  A lock on
it has been acquired.

Raises:
NoAvailableWorkException
There is no more work available.


class SimpleSlidingMeanTracker(WindowedTracker, MeanTracker):

    def __init__(self, window_size):
        super().__init__(window_mode=WindowMode.SLIDING, window_size=window_size)

    def get(self):

        if len(self._queue) == 0:
            return float('nan')
        with warnings.catch_warnings(record=False):
            warnings.simplefilter('ignore')
            return np.nanmean(self._queue)

Sliding window mean tracker that calculates mean using NumPy.

This tracker uses NumPy's `nanmean` function to calculate the mean of the
values currently in the sliding window. It's a simple, non-incremental
approach.

Args:
window_size: The size of the sliding window.


def rebuild_tree(cls, session, tree_id):

        session.query(cls).filter_by(tree_id=tree_id)\
            .update({cls.left: 0, cls.right: 0, cls.level: 0})
        top = session.query(cls).filter_by(parent_id=None)\
            .filter_by(tree_id=tree_id).one()
        top.left = left = 1
        top.right = right = 2
        top.level = level = cls.get_default_level()

        def recursive(children, left, right, level):
            level = level + 1
            for i, node in enumerate(children):
                same_level_right = children[i - 1].right
                left = left + 1

                if i > 0:
                    left = left + 1
                if same_level_right:
                    left = same_level_right + 1

                right = left + 1
                node.left = left
                node.right = right
                parent = node.parent

                j = 0
                while parent:
                    parent.right = right + 1 + j
                    parent = parent.parent
                    j += 1

                node.level = level
                recursive(node.children, left, right, level)

        recursive(top.children, left, right, level)

This method rebuid tree.

Args:
session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session
tree_id (int or str): id of tree

Example:

* :mod:`sqlalchemy_mptt.tests.cases.get_tree.test_rebuild`


def __init__(self, xid=None, elements=None):

        super().__init__(xid)
        self.elements = elements

Create a Hello with the optional parameters below.

Args:
xid (int): xid to be used on the message header.
elements: List of elements - 0 or more


def __init__(self, project: str, location: str, api_endpoint: str, feature_store_id: str, entity_type_id: str, feature_ids: list[str], row_key: str, *, exception_level: ExceptionLevel=ExceptionLevel.WARN, **kwargs):
    self.project = project
    self.location = location
    self.api_endpoint = api_endpoint
    self.feature_store_id = feature_store_id
    self.entity_type_id = entity_type_id
    self.feature_ids = feature_ids
    self.row_key = row_key
    self.exception_level = exception_level
    self.kwargs = kwargs if kwargs else {}
    if 'client_options' in self.kwargs:
        if not self.kwargs['client_options']['api_endpoint']:
            self.kwargs['client_options']['api_endpoint'] = self.api_endpoint
        elif self.kwargs['client_options']['api_endpoint'] != self.api_endpoint:
            raise ValueError('Multiple values received for api_endpoint in api_endpoint and client_options parameters.')
    else:
        self.kwargs['client_options'] = {'api_endpoint': self.api_endpoint}
    try:
        _ = aiplatform.Featurestore(featurestore_name=self.feature_store_id, project=self.project, location=self.location, credentials=self.kwargs.get('credentials'))
    except NotFound:
        raise NotFound('Vertex AI Feature Store (Legacy) %s does not exist' % self.feature_store_id)

Initializes an instance of `VertexAIFeatureStoreLegacyEnrichmentHandler`.

Args:
project (str): The GCP project for the Vertex AI Feature Store (Legacy).
location (str): The region for the Vertex AI Feature Store (Legacy).
api_endpoint (str): The API endpoint for the
Vertex AI Feature Store (Legacy).
feature_store_id (str): The id of the Vertex AI Feature Store (Legacy).
entity_type_id (str): The entity type of the feature store.
feature_ids (list[str]): A list of feature-ids to fetch
from the Feature Store.
row_key (str): The row key field name containing the entity id
for the feature values.
exception_level: a `enum.Enum` value from
`apache_beam.transforms.enrichment_handlers.utils.ExceptionLevel`
to set the level when an empty row is returned from the BigTable query.
Defaults to `ExceptionLevel.WARN`.
kwargs: Optional keyword arguments to configure the
`aiplatform.gapic.FeaturestoreOnlineServingServiceClient`.


def _group_centroid(mol, ilabels, group_atoms):

        c1x, c1y, c1z = 0.0, 0.0, 0.0
        for i in group_atoms:
            orig_idx = ilabels[i-1]
            oa1 = mol.GetAtom(orig_idx)
            c1x += float(oa1.x())
            c1y += float(oa1.y())
            c1z += float(oa1.z())
        num_atoms = len(group_atoms)
        c1x /= num_atoms
        c1y /= num_atoms
        c1z /= num_atoms
        return c1x, c1y, c1z

Calculate the centroids of a group atoms indexed by the labels of inchi

Args:
mol: The molecule. OpenBabel OBMol object
ilabel: inchi label map

Returns:
Centroid. Tuple (x, y, z)


def from_deformation(cls, deformation):

        dfm = Deformation(deformation)
        return cls(0.5 * (np.dot(dfm.trans, dfm) - np.eye(3)))

Factory method that returns a Strain object from a deformation
gradient

Args:
deformation (3x3 array-like):


def CopyToDatetime(cls, timestamp, timezone, raise_error=False):
    datetime_object = datetime.datetime(1970, 1, 1, 0, 0, 0, 0, tzinfo=pytz.UTC)
    if (not timestamp):
        if raise_error:
            raise ValueError('Missing timestamp value')
        return datetime_object
    try:
        datetime_object += datetime.timedelta(microseconds=timestamp)
        return datetime_object.astimezone(timezone)
    except OverflowError as exception:
        if raise_error:
            raise
        logging.error('Unable to copy {0:d} to a datetime object with error: {1!s}'.format(timestamp, exception))
    return datetime_object

Copies the timestamp to a datetime object.

Args:
timestamp: The timestamp which is an integer containing the number
of micro seconds since January 1, 1970, 00:00:00 UTC.
timezone: The timezone (pytz.timezone) object.
raise_error: Boolean that if set to True will not absorb an OverflowError
if the timestamp is out of bounds. By default there will be
no error raised.

Returns:
A datetime object (instance of datetime.datetime). A datetime object of
January 1, 1970 00:00:00 UTC is returned on error if raises_error is
not set.

Raises:
OverflowError: If raises_error is set to True and an overflow error
occurs.
ValueError: If raises_error is set to True and no timestamp value is
provided.


def run(argv=None, save_main_session=True, test_pipeline=None) -> PipelineResult:
    known_args, pipeline_args = parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
    pipeline = test_pipeline
    if not test_pipeline:
        pipeline = beam.Pipeline(options=pipeline_options)
    tokenizer = AutoTokenizer.from_pretrained(known_args.model_name)
    model_handler = HuggingFaceModelHandlerKeyedTensor(model_uri=known_args.model_name, model_class=known_args.model_class, framework='pt', max_batch_size=1, large_model=known_args.large_model)
    if not known_args.input:
        text = pipeline | 'CreateSentences' >> beam.Create(['The capital of France is Paris .', 'It is raining cats and dogs .', 'Today is Monday and tomorrow is Tuesday .', 'There are 5 coconuts on this palm tree .', 'The strongest person in the world is not famous .', 'The secret ingredient to his wonderful life was gratitude .', 'The biggest animal in the world is the whale .'])
    else:
        text = pipeline | 'ReadSentences' >> beam.io.ReadFromText(known_args.input)
    text_and_tokenized_text_tuple = text | 'FilterEmptyLines' >> beam.ParDo(filter_empty_lines) | 'AddMask' >> beam.Map(add_mask_to_last_word) | 'TokenizeSentence' >> beam.Map(lambda x: tokenize_sentence(x, tokenizer))
    output = text_and_tokenized_text_tuple | 'RunInference' >> RunInference(KeyedModelHandler(model_handler)) | 'ProcessOutput' >> beam.ParDo(PostProcessor(tokenizer=tokenizer))
    _ = output | 'WriteOutput' >> beam.io.WriteToText(known_args.output, shard_name_template='', append_trailing_newlines=True)
    result = pipeline.run()
    result.wait_until_finish()
    return result

Args:
argv: Command line arguments defined for this example.
save_main_session: Used for internal testing.
test_pipeline: Used for internal testing.


def parse_cron_line(self, line):
    stripped = line.strip()
    if (stripped and (stripped.startswith('
        rexres = self.rex.search(stripped)
        if rexres:
            return ' '.join(rexres.group(1).split())
    return None

Parses crontab line and returns only starting time string

Args:
line: crontab line
Returns:
Time part of cron line


def _get_operation_input_field_values(self, metadata, file_input):
    input_args = metadata['request']['ephemeralPipeline']['inputParameters']
    vals_dict = metadata['request']['pipelineArgs']['inputs']
    names = [arg['name'] for arg in input_args if (('localCopy' in arg) == file_input)]
    return {name: vals_dict[name] for name in names if (name in vals_dict)}

Returns a dictionary of envs or file inputs for an operation.

Args:
metadata: operation metadata field
file_input: True to return a dict of file inputs, False to return envs.

Returns:
A dictionary of input field name value pairs


def _done_callback(self, wrapped):

        if wrapped.exception():
            self.set_exception(wrapped.exception())
        else:
            self.set_result(wrapped.result())

Internal "done callback" to set the result of the object.

The result of the object if forced by the wrapped future. So this
internal callback must be called when the wrapped future is ready.

Args:
wrapped (Future): the wrapped Future object


def scan_file(path):

    path = os.path.abspath(path)
    assert os.path.exists(path), "Unreachable file '%s'." % path

    try:
        cd = pyclamd.ClamdUnixSocket()
        cd.ping()
    except pyclamd.ConnectionError:
        cd = pyclamd.ClamdNetworkSocket()
        try:
            cd.ping()
        except pyclamd.ConnectionError:
            raise ValueError(
                "Couldn't connect to clamd server using unix/network socket."
            )

    cd = pyclamd.ClamdUnixSocket()
    assert cd.ping(), "clamd server is not reachable!"

    result = cd.scan_file(path)

    return result if result else {}

Scan `path` for viruses using ``clamd`` antivirus daemon.

Args:
path (str): Relative or absolute path of file/directory you need to
scan.

Returns:
dict: ``{filename: ("FOUND", "virus type")}`` or blank dict.

Raises:
ValueError: When the server is not running.
AssertionError: When the internal file doesn't exists.


def AddTransaction(self, tx):

        if BC.Default() is None:
            return False

        if tx.Hash.ToBytes() in self.MemPool.keys():
            return False

        if BC.Default().ContainsTransaction(tx.Hash):
            return False

        if not tx.Verify(self.MemPool.values()):
            logger.error("Verifying tx result... failed")
            return False

        self.MemPool[tx.Hash.ToBytes()] = tx

        return True

Add a transaction to the memory pool.

Args:
tx (neo.Core.TX.Transaction): instance.

Returns:
bool: True if successfully added. False otherwise.


def enable_control_flow_v2(fn: _F) -> _F:

    def wrapper(*args, **kwargs):
        enable_control_flow_v2_old = control_flow_util.ENABLE_CONTROL_FLOW_V2
        control_flow_util.ENABLE_CONTROL_FLOW_V2 = True
        try:
            return fn(*args, **kwargs)
        finally:
            control_flow_util.ENABLE_CONTROL_FLOW_V2 = enable_control_flow_v2_old
    return wrapper

Decorator for enabling CondV2 and WhileV2 on a test.

Note this enables using CondV2 and WhileV2 after running the test class's
setup/teardown methods.

In addition to this, callers must import the while_v2 module in order to set
the _while_v2 module in control_flow_ops.

Args:
fn: the function to be wrapped

Returns:
The wrapped function


def create_and_register_access97_db(filename: str,
                                    dsn: str,
                                    description: str) -> bool:

    fullfilename = os.path.abspath(filename)
    create_string = fullfilename + " General"

    return (create_user_dsn(access_driver, CREATE_DB3=create_string) and
            register_access_db(filename, dsn, description))

(Windows only.)
Creates a Microsoft Access 97 database and registers it with ODBC.

Args:
filename: filename of the database to create
dsn: ODBC data source name to create
description: description of the database

Returns:
bool: was the DSN created?


def set_garbage_collector(self, exts=None, policy='task'):
    assert (policy in ('task', 'flow'))
    exts = (list_strings(exts) if (exts is not None) else ('WFK', 'SUS', 'SCR', 'BSR', 'BSC'))
    gc = GarbageCollector(exts=set(exts), policy=policy)
    self.set_gc(gc)
    for work in self:
        for task in work:
            task.set_gc(gc)

Enable the garbage collector that will remove the big output files that are not needed.

Args:
exts: string or list with the Abinit file extensions to be removed. A default is
provided if exts is None
policy: Either `flow` or `task`. If policy is set to 'task', we remove the output
files as soon as the task reaches S_OK. If 'flow', the files are removed
only when the flow is finalized. This option should be used when we are dealing
with a dynamic flow with callbacks generating other tasks since a :class:`Task`
might not be aware of its children when it reached S_OK.


def GetUnscannedScanNode(self):
    root_scan_node = self._scan_nodes.get(self._root_path_spec, None)
    if ((not root_scan_node) or (not root_scan_node.scanned)):
        return root_scan_node
    return root_scan_node.GetUnscannedSubNode()

Retrieves the first unscanned scan node.

Returns:
SourceScanNode: scan node or None if not available.


def trailing_stop_loss_replace(self, accountID, orderID, **kwargs):
    return self.replace(accountID, orderID, order=TrailingStopLossOrderRequest(**kwargs))

Shortcut to replace a pending Trailing Stop Loss Order in an Account

Args:
accountID : The ID of the Account
orderID : The ID of the Take Profit Order to replace
kwargs : The arguments to create a TrailingStopLossOrderRequest

Returns:
v20.response.Response containing the results from submitting
the request


def download_image(self, handle, dest):

        with log_utils.LogTask('Download image %s' % handle, logger=LOGGER):
            self.open_url(url=handle, dest=dest)

        self.extract_image_xz(dest)

Downloads the image from the http server

Args:
handle (str): url from the `self.baseurl` to the remote template
dest (str): Path to store the downloaded url to, must be a file
path

Returns:
None


def get(self, section, option):

        if not self.has_section(section):
            raise NoSectionError(section) from None

        section = self.__getitem__(section)
        option = self.optionxform(option)
        try:
            value = section[option]
        except KeyError:
            raise NoOptionError(option, section)

        return value

Gets an option value for a given section.

Args:
section (str): section name
option (str): option name

Returns:
:class:`Option`: Option object holding key/value pair


def SeparateFlagArgs(args):
    if '--' in args:
        separator_index = len(args) - 1 - args[::-1].index('--')
        flag_args = args[separator_index + 1:]
        args = args[:separator_index]
        return (args, flag_args)
    return (args, [])

Splits a list of args into those for Flags and those for Fire.

If an isolated '--' arg is not present in the arg list, then all of the args
are for Fire. If there is an isolated '--', then the args after the final '--'
are flag args, and the rest of the args are fire args.

Args:
args: The list of arguments received by the Fire command.
Returns:
A tuple with the Fire args (a list), followed by the Flag args (a list).


def set_signature(self, signature_map: signature_serialization._SignatureMap, wrapped_functions: Dict[Callable[..., Any], Callable[..., Any]]):
    self.list_children(self.root)
    name = signature_serialization.SIGNATURE_ATTRIBUTE_NAME
    self._children_cache[self.root][name] = signature_map
    self._wrapped_functions.update(wrapped_functions)

Attach signature to the root object.

Args:
signature_map: An object that contains signature functions.
wrapped_functions: A dictionary mapping functions to functions that are
guaranteed to not capture cached variables (functions that capture
cached variables can't be saved).


def get_parser(segmenter, **options):

  if segmenter == 'nlapi':
    return NLAPIParser(**options)
  elif segmenter == 'mecab':
    return MecabParser()
  elif segmenter == 'tinysegmenter':
    return TinysegmenterParser()
  else:
    raise ValueError('Segmenter {} is not supported.'.format(segmenter))

Gets a parser.

Args:
segmenter (str): Segmenter to use.
options (:obj:`dict`, optional): Optional settings.

Returns:
Parser (:obj:`budou.parser.Parser`)

Raises:
ValueError: If unsupported segmenter is specified.


def deconv_elems_1d(x, factor, out_depth=None):
    out_depth = (out_depth or x.get_shape().as_list()[(- 1)])
    x = tf.expand_dims(x, 1)
    x = layers().Conv2DTranspose(filters=out_depth, kernel_size=(1, factor), strides=(1, factor), padding='valid', data_format='channels_last')(x)
    x = tf.squeeze(x, 1)
    return x

Increase the length and change the dimensionality.

Expand/project each positions of dim depth of the input into
factor*tokens of dim out_depth

Args:
x (tf.Tensor): shape [batch_size, length, depth]
factor (int): Multiplicative factor of each tokens.
out_depth (int): Output depth (if None, keep depth constant)

Returns:
tf.Tensor: shape [batch_size, length*factor, out_depth]


def __init__(self, float_value, places=7):

    self._float_value = float_value
    self._places = places

Initialize IsAlmost.

Args:
float_value: The value for making the comparison.
places: The number of decimal places to round to.


def _get_next_chunk(fp, previously_read_position, chunk_size):
    (seek_position, read_size) = _get_what_to_read_next(fp, previously_read_position, chunk_size)
    fp.seek(seek_position)
    read_content = fp.read(read_size)
    read_position = seek_position
    return (read_content, read_position)

Return next chunk of data that we would from the file pointer.

Args:
fp: file-like object
previously_read_position: file pointer position that we have read from
chunk_size: desired read chunk_size

Returns:
(bytestring, int): data that has been read in, the file pointer position where the data has been read from


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

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

Constructs a ResNet-18 model.

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


def spline_functions(lower_points, upper_points, degree=3):

    lower_xx = np.array([pp[0] for pp in lower_points])
    lower_yy = np.array([pp[1] for pp in lower_points])
    upper_xx = np.array([pp[0] for pp in upper_points])
    upper_yy = np.array([pp[1] for pp in upper_points])

    lower_spline = UnivariateSpline(lower_xx, lower_yy, k=degree, s=0)
    upper_spline = UnivariateSpline(upper_xx, upper_yy, k=degree, s=0)

    def lower(x):
        return lower_spline(x)

    def upper(x):
        return upper_spline(x)

    return {'lower': lower, 'upper': upper}

Method that creates two (upper and lower) spline functions based on points lower_points and upper_points.

Args:
lower_points:
Points defining the lower function.
upper_points:
Points defining the upper function.
degree:
Degree for the spline function

Returns:
A dictionary with the lower and upper spline functions.


def get_default_data_path(*args, module=None, class_=None, flag_raise=True):
    if (module is None):
        module = __get_filetypes_module()
    if (class_ is not None):
        pkgname = class_.__module__
        mseq = pkgname.split('.')
        if ((len(mseq) < 2) or (mseq[1] != 'filetypes')):
            raise ValueError("Invalid module name for class '{}': '{}' (must be '(...).filetypes[.(...)]')".format(class_.__name__, pkgname))
        module = sys.modules[mseq[0]]
    module_path = os.path.split(module.__file__)[0]
    p = os.path.abspath(os.path.join(module_path, 'data', 'default', *args))
    if flag_raise:
        if (not os.path.isfile(p)):
            raise RuntimeError("Path not found '{}'".format(p))
    return p

Returns path to default data directory

Arguments 'module' and 'class' give the chance to return path relative to package other than
f311.filetypes

Args:
module: Python module object. It is expected that this module has a sub-subdirectory
named 'data/default'
class_: Python class object to extract path information from. If this argument is used,
it will be expected that the class "root" package will have a sub-subdirectory
named 'data/default'. Argument 'class_' **has precedence over argument 'module'**
flag_raise: raises error if file is not found. This can be turned off for whichever purpose


def full_type_name(val: '_instance_base.SimpleValue', name: str) -> str:
    if isinstance(val, _abstract.Instance):
        return full_type_name(val.cls, name)
    for t in val.template:
        if name in (t.name, t.full_name):
            return t.full_name
    for t in val.all_template_names:
        if t.split('.')[-1] == name or t == name:
            return t
    return name

Compute complete type parameter name with scope.

Args:
val: The object with type parameters.
name: The short type parameter name (e.g., T).

Returns:
The full type parameter name (e.g., List.T).


def _ParseTriggerEndTime(self, parser_mediator, trigger):

    time_elements_tuple = (
        trigger.end_date.year, trigger.end_date.month,
        trigger.end_date.day_of_month, 0, 0, 0)

    date_time = None
    if time_elements_tuple != (0, 0, 0, 0, 0, 0):
      try:
        date_time = dfdatetime_time_elements.TimeElements(
            time_elements_tuple=time_elements_tuple)
        date_time.is_local_time = True

        date_time._precision = dfdatetime_definitions.PRECISION_1_DAY
      except ValueError:
        parser_mediator.ProduceExtractionWarning(
            'invalid trigger end time: {0!s}'.format(time_elements_tuple))

    return date_time

Parses the end time from a trigger.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
trigger (job_trigger): a trigger.

Returns:
dfdatetime.DateTimeValues: last run date and time or None if not
available.


def to_basis_like(self, basis):

        try:
            curve = basis
            basis = curve.basis
            undefined = curve.null
        except:
            undefined = None

        return self.to_basis(basis=basis,
                             undefined=undefined)

Make a new curve in a new basis, given an existing one. Wraps
``to_basis()``.

Pass in a curve or the basis of a curve.

Args:
basis (ndarray): A basis, but can also be a Curve instance.

Returns:
Curve. The current instance in the new basis.


def dump(self, output, close_after_write=True):

        try:
            output.write
            self.stream = output
        except AttributeError:
            self.stream = io.open(output, "w", encoding="utf-8")

        try:
            self.write_table()
        finally:
            if close_after_write:
                self.stream.close()
                self.stream = sys.stdout

Write data to the output with tabular format.

Args:
output (file descriptor or str):
file descriptor or path to the output file.
close_after_write (bool, optional):
Close the output after write.
Defaults to |True|.


def retrieve_all(self, subset=None):

        get_object = self.factory.get_object
        obj_class = self.obj_class

        full_objects = [get_object(obj_class, list_obj.id, subset) for list_obj
                        in self]
        return JSSObjectList(self.factory, obj_class, full_objects)

Return a list of all JSSListData elements as full JSSObjects.

This can take a long time given a large number of objects,
and depending on the size of each object. Subsetting to only
include the data you need can improve performance.

Args:
subset: For objects which support it, a list of sub-tags to
request, or an "&" delimited string, (e.g.
"general&purchasing").  Default to None.


def wait_for_new_checkpoint(checkpoint_dir, last_checkpoint=None, seconds_to_sleep=1, timeout=None):
    logging.info('Waiting for new checkpoint at %s', checkpoint_dir)
    stop_time = time.time() + timeout if timeout is not None else None
    while True:
        checkpoint_path = checkpoint_management.latest_checkpoint(checkpoint_dir)
        if checkpoint_path is None or checkpoint_path == last_checkpoint:
            if stop_time is not None and time.time() + seconds_to_sleep > stop_time:
                return None
            time.sleep(seconds_to_sleep)
        else:
            logging.info('Found new checkpoint at %s', checkpoint_path)
            return checkpoint_path

Waits until a new checkpoint file is found.

Args:
checkpoint_dir: The directory in which checkpoints are saved.
last_checkpoint: The last checkpoint path used or `None` if we're expecting
a checkpoint for the first time.
seconds_to_sleep: The number of seconds to sleep for before looking for a
new checkpoint.
timeout: The maximum number of seconds to wait. If left as `None`, then the
process will wait indefinitely.

Returns:
a new checkpoint path, or None if the timeout was reached.


def __init__(self, kind=None, ancestor=None, filters=None, orders=None,
               app=None, namespace=None, default_options=None,
               projection=None, group_by=None):

    if ancestor is not None:
      if isinstance(ancestor, ParameterizedThing):
        if isinstance(ancestor, ParameterizedFunction):
          if ancestor.func != 'key':
            raise TypeError('ancestor cannot be a GQL function other than KEY')
      else:
        if not isinstance(ancestor, model.Key):
          raise TypeError('ancestor must be a Key; received %r' % (ancestor,))
        if not ancestor.id():
          raise ValueError('ancestor cannot be an incomplete key')
        if app is not None:
          if app != ancestor.app():
            raise TypeError('app/ancestor mismatch')
        if namespace is None:
          namespace = ancestor.namespace()
        else:
          if namespace != ancestor.namespace():
            raise TypeError('namespace/ancestor mismatch')
    if filters is not None:
      if not isinstance(filters, Node):
        raise TypeError('filters must be a query Node or None; received %r' %
                        (filters,))
    if orders is not None:
      if not isinstance(orders, datastore_query.Order):
        raise TypeError('orders must be an Order instance or None; received %r'
                        % (orders,))
    if default_options is not None:
      if not isinstance(default_options, datastore_rpc.BaseConfiguration):
        raise TypeError('default_options must be a Configuration or None; '
                        'received %r' % (default_options,))
      if projection is not None:
        if default_options.projection is not None:
          raise TypeError('cannot use projection= and '
                          'default_options.projection at the same time')
        if default_options.keys_only is not None:
          raise TypeError('cannot use projection= and '
                          'default_options.keys_only at the same time')

    self.__kind = kind
    self.__ancestor = ancestor
    self.__filters = filters
    self.__orders = orders
    self.__app = app
    self.__namespace = namespace
    self.__default_options = default_options

    self.__projection = None
    if projection is not None:
      if not projection:
        raise TypeError('projection argument cannot be empty')
      if not isinstance(projection, (tuple, list)):
        raise TypeError(
            'projection must be a tuple, list or None; received %r' %
            (projection,))
      self._check_properties(self._to_property_names(projection))
      self.__projection = tuple(projection)

    self.__group_by = None
    if group_by is not None:
      if not group_by:
        raise TypeError('group_by argument cannot be empty')
      if not isinstance(group_by, (tuple, list)):
        raise TypeError(
            'group_by must be a tuple, list or None; received %r' % (group_by,))
      self._check_properties(self._to_property_names(group_by))
      self.__group_by = tuple(group_by)

Constructor.
Args:
kind: Optional kind string.
ancestor: Optional ancestor Key.
filters: Optional Node representing a filter expression tree.
orders: Optional datastore_query.Order object.
app: Optional app id.
namespace: Optional namespace.
default_options: Optional QueryOptions object.
projection: Optional list or tuple of properties to project.
group_by: Optional list or tuple of properties to group by.


def mtf_transformer_lm_baseline():
    hparams = mtf_transformer_paper_lm((- 1))
    hparams.batch_size = 128
    hparams.learning_rate_decay_steps = 27200
    hparams.mesh_shape = 'batch:8'
    return hparams

Small language model to run on 1 TPU.

Run this on 2x2 on languagemodel_lm1b32k_packed for 272000 steps (10 epochs)
Results:
params/10^9  log-ppl(per-token)
0.14         3.202

Returns:
a hparams


def unhold(self):
    if (self._hold is None):
        return
    self._hold = None
    events = list(self._held_events)
    self._held_events = []
    for event in events:
        self._trigger_on_change(event)

Turn off any active document hold and apply any collected events.

Returns:
None


def from_composition_and_pd(comp, pd, working_ion_symbol="Li"):

        working_ion = Element(working_ion_symbol)
        entry = None
        working_ion_entry = None
        for e in pd.stable_entries:
            if e.composition.reduced_formula == comp.reduced_formula:
                entry = e
            elif e.is_element and \
                    e.composition.reduced_formula == working_ion_symbol:
                working_ion_entry = e

        if not entry:
            raise ValueError("Not stable compound found at composition {}."
                             .format(comp))

        profile = pd.get_element_profile(working_ion, comp)

        profile.reverse()
        if len(profile) < 2:
            return None
        working_ion_entry = working_ion_entry
        working_ion = working_ion_entry.composition.elements[0].symbol
        normalization_els = {}
        for el, amt in comp.items():
            if el != Element(working_ion):
                normalization_els[el] = amt
        vpairs = [ConversionVoltagePair.from_steps(profile[i], profile[i + 1],
                                                   normalization_els)
                  for i in range(len(profile) - 1)]
        return ConversionElectrode(vpairs, working_ion_entry, comp)

Convenience constructor to make a ConversionElectrode from a
composition and a phase diagram.

Args:
comp:
Starting composition for ConversionElectrode, e.g.,
Composition("FeF3")
pd:
A PhaseDiagram of the relevant system (e.g., Li-Fe-F)
working_ion_symbol:
Element symbol of working ion. Defaults to Li.


def _load_edflib(filename):

    import edflib
    e = edflib.EdfReader(filename, annotations_mode='all')
    if np.ptp(e.get_samples_per_signal()) != 0:
        raise Error('channels have differing numbers of samples')
    if np.ptp(e.get_signal_freqs()) != 0:
        raise Error('channels have differing sample rates')
    n = e.samples_in_file(0)
    m = e.signals_in_file
    channelnames = e.get_signal_text_labels()
    dt = 1.0/e.samplefrequency(0)

    ar = np.zeros((n, m), dtype=np.float32)

    buf = np.zeros((n,), dtype=np.float64)
    for i in range(m):
        e.read_phys_signal(i, 0, n, buf)
        ar[:,i] = buf
    tspan = np.arange(0, (n - 1 + 0.5) * dt, dt, dtype=np.float32)
    return Timeseries(ar, tspan, labels=[None, channelnames])

load a multi-channel Timeseries from an EDF (European Data Format) file
or EDF+ file, using edflib.

Args:
filename: EDF+ file

Returns:
Timeseries


def trace_start(self):
    cmd = enums.JLinkTraceCommand.START
    res = self._dll.JLINKARM_TRACE_Control(cmd, 0)
    if (res == 1):
        raise errors.JLinkException('Failed to start trace.')
    return None

Starts collecting trace data.

Args:
self (JLink): the ``JLink`` instance.

Returns:
``None``


def extract_r_df(self, state_key, r_value, action_key=None):

        if isinstance(r_value, float) is False:
            raise TypeError("The type of r_value must be float.")

        r = 0.0
        if self.r_df is None:
            self.save_r_df(state_key, r, action_key)
            return r

        r_df = self.r_df[self.r_df.state_key == state_key]
        if action_key is not None:
            r_df = r_df[r_df.action_key == action_key]
        if r_df.shape[0]:
            r = float(r_df["r_value"])
        else:
            self.save_r_df(state_key, r, action_key)
        return r

Insert or update R-Value in `self.r_df`.

Args:
state_key:     The key of state.
r_value:       R-Value(Reward).
action_key:    The key of action if it is nesesary for the parametar of value function.

Exceptions:
TypeError:      If the type of `r_value` is not float.


def filter_backends(backends, filters=None, **kwargs):

    def _match_all(obj, criteria):
        'Return True if all items in criteria matches items in obj.'
        return all(((getattr(obj, key_, None) == value_) for (key_, value_) in criteria.items()))
    configuration_filters = {}
    status_filters = {}
    for (key, value) in kwargs.items():
        if all(((key in backend.configuration()) for backend in backends)):
            configuration_filters[key] = value
        else:
            status_filters[key] = value
    if configuration_filters:
        backends = [b for b in backends if _match_all(b.configuration(), configuration_filters)]
    if status_filters:
        backends = [b for b in backends if _match_all(b.status(), status_filters)]
    backends = list(filter(filters, backends))
    return backends

Return the backends matching the specified filtering.

Filter the `backends` list by their `configuration` or `status`
attributes, or from a boolean callable. The criteria for filtering can
be specified via `**kwargs` or as a callable via `filters`, and the
backends must fulfill all specified conditions.

Args:
backends (list[BaseBackend]): list of backends.
filters (callable): filtering conditions as a callable.
**kwargs (dict): dict of criteria.

Returns:
list[BaseBackend]: a list of backend instances matching the
conditions.


def _kernel(kernel_spec):

  if isinstance(kernel_spec, tf.compat.integral_types):
    return [kernel_spec, kernel_spec]
  elif len(kernel_spec) == 1:
    return [kernel_spec[0], kernel_spec[0]]
  else:
    assert len(kernel_spec) == 2
    return kernel_spec

Expands the kernel spec into a length 2 list.

Args:
kernel_spec: An integer or a length 1 or 2 sequence that is expanded to a
list.
Returns:
A length 2 list.


def debug_command(self, cmd, args=None, progress_callback=None):
    if (args is None):
        args = {}
    try:
        self._on_progress = progress_callback
        return self._loop.run_coroutine(self.adapter.debug(0, cmd, args))
    finally:
        self._on_progress = None

Send a debug command to the connected device.

This generic method will send a named debug command with the given
arguments to the connected device.  Debug commands are typically used
for things like forcible reflashing of firmware or other, debug-style,
operations.  Not all transport protocols support debug commands and
the supported operations vary depeneding on the transport protocol.

Args:
cmd (str): The name of the debug command to send.
args (dict): Any arguments required by the given debug command
progress_callback (callable): A function that will be called periodically to
report progress.  The signature must be callback(done_count, total_count)
where done_count and total_count will be passed as integers.

Returns:
object: The return value of the debug command, if there is one.


def GetDecrypter(cls, encryption_method, **kwargs):
    encryption_method = encryption_method.lower()
    decrypter = cls._decrypters.get(encryption_method, None)
    if (not decrypter):
        return None
    return decrypter(**kwargs)

Retrieves the decrypter object for a specific encryption method.

Args:
encryption_method (str): encryption method identifier.
kwargs (dict): keyword arguments depending on the decrypter.

Returns:
Decrypter: decrypter or None if the encryption method does not exists.

Raises:
CredentialError: if the necessary credentials are missing.


def double_strike(self, action):

        if action == 'on':
            action = 'G'
        elif action == 'off':
            action = 'H'
        else:
            raise RuntimeError('Invalid action for function doubleStrike. Options are on and off')
        self.send(chr(27)+action)

Enable/cancel doublestrike printing

Args:
action: Enable or disable doublestrike printing. Options are 'on' and 'off'
Returns:
None
Raises:
RuntimeError: Invalid action.


def ensure_proc_terminate(proc):

    if isinstance(proc, list):
        for p in proc:
            ensure_proc_terminate(p)
        return

    def stop_proc_by_weak_ref(ref):
        proc = ref()
        if proc is None:
            return
        if not proc.is_alive():
            return
        proc.terminate()
        proc.join()

    assert isinstance(proc, mp.Process)
    atexit.register(stop_proc_by_weak_ref, weakref.ref(proc))

Make sure processes terminate when main process exit.

Args:
proc (multiprocessing.Process or list)


def cashflows(self, market: pmd.ProcessedMarketData, past_fixing: Optional[types.FloatTensor]=None, name: Optional[str]=None) -> Tuple[types.DateTensor, types.FloatTensor]:
    name = name or self._name + '_cashflows'
    with tf.name_scope(name):
        _, forward_rates = self.forward_rates(market, past_fixing=past_fixing)
        coupon_rate = forward_rates + tf.expand_dims(self._spread, axis=-1)
        notional = tf.expand_dims(self._notional, axis=-1)
        cashflows = notional * (self._daycount_fractions * coupon_rate)
        return (self._coupon_end_dates, cashflows)

Returns cashflows for the floating leg.

Args:
market: An instance of `ProcessedMarketData`.
past_fixing: An optional `Tensor` of shape compatible with
`batch_shape + [1]`. Represents the fixings for the cashflows as
observed at `market.date`.
name: Python str. The name to give to the ops created by this function.
Default value: `None` which maps to 'cashflows'.

Returns:
A tuple of two `Tensor`s of shape `batch_shape + [num_cashflows]` and
containing the dates and the corresponding cashflows price for each
stream based on the input market data.


def prepare_csv_read(data, field_names, *args, **kwargs):
    if (hasattr(data, 'readlines') or isinstance(data, list)):
        pass
    elif isinstance(data, basestring):
        data = open(data)
    else:
        raise TypeError(('Unable to handle data of type %r' % type(data)))
    return csv.DictReader(data, field_names, *args, **kwargs)

Prepare various input types for CSV parsing.

Args:
data (iter): Data to read
field_names (tuple of str): Ordered names to assign to fields

Returns:
csv.DictReader: CSV reader suitable for parsing

Raises:
TypeError: Invalid value for data


def from_string(species_string: str):

        m = re.search(r"([A-Z][a-z]*)([0-9.]*)([+\-])(.*)", species_string)
        if m:
            sym = m.group(1)
            oxi = 1 if m.group(2) == "" else float(m.group(2))
            oxi = -oxi if m.group(3) == "-" else oxi
            properties = None
            if m.group(4):
                toks = m.group(4).replace(",", "").split("=")
                properties = {toks[0]: float(toks[1])}
            return Specie(sym, oxi, properties)
        else:
            raise ValueError("Invalid Species String")

Returns a Specie from a string representation.

Args:
species_string (str): A typical string representation of a
species, e.g., "Mn2+", "Fe3+", "O2-".

Returns:
A Specie object.

Raises:
ValueError if species_string cannot be intepreted.


def _split_generators(self, dl_manager):
    splits = super(Imagenet2012Corrupted, self)._split_generators(dl_manager)
    validation = splits[1]
    return [validation]

Return the validation split of ImageNet2012.

Args:
dl_manager: download manager object.

Returns:
validation split.


def exists(self, path):
    return os.path.exists(path)

Check if the provided path exists on the FileSystem.

Args:
path: string path that needs to be checked.

Returns: boolean flag indicating if path exists


def clear(cls, fn):

        if hasattr(fn, cls.CACHE_VAR):
            delattr(fn, cls.CACHE_VAR)

Clear result cache on the given function.

If the function has no cached result, this call will do nothing.

Args:
fn (FunctionType):
The function whose cache should be cleared.


def set_topics(self, topics):

        if set(topics).difference(self._topics):
            future = self.cluster.request_update()
        else:
            future = Future().success(set(topics))
        self._topics = set(topics)
        return future

Set specific topics to track for metadata.

Arguments:
topics (list of str): topics to check for metadata

Returns:
Future: resolves after metadata request/response


def titles(self, unique=False):
    if unique:
        return tools.uniqued((s.title for s in self._items))
    return [s.title for s in self._items]

Return a list of contained worksheet titles.

Args:
unique (bool): drop duplicates
Returns:
list: list of titles/name strings


def _GetDirectory(self):
    if (self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY):
        return None
    return LVMDirectory(self._file_system, self.path_spec)

Retrieves the directory.

Returns:
LVMDirectory: a directory or None if not available.


def create_security_group(self):
    ingress_rules = []
    try:
        security_id = get_security_group_id(name=self.app_name, env=self.env, region=self.region)
    except (SpinnakerSecurityGroupError, AssertionError):
        self._create_security_group(ingress_rules)
    else:
        self.log.debug('Security Group ID %s found for %s.', security_id, self.app_name)
    try:
        ingress = self.update_default_rules()
    except KeyError:
        msg = 'Possible missing configuration for "{0}".'.format(self.env)
        self.log.error(msg)
        raise ForemastConfigurationFileError(msg)
    for app in ingress:
        rules = ingress[app]
        for rule in rules:
            ingress_rule = self.create_ingress_rule(app, rule)
            ingress_rules.append(ingress_rule)
    (ingress_rules_no_cidr, ingress_rules_cidr) = self._process_rules(ingress_rules)
    self._create_security_group(ingress_rules_no_cidr)
    self.add_cidr_rules(ingress_rules_cidr)
    self.add_tags()
    self.log.info('Successfully created %s security group', self.app_name)
    return True

Send a POST to spinnaker to create or update a security group.

Returns:
boolean: True if created successfully

Raises:
ForemastConfigurationFileError: Missing environment configuration or
misconfigured Security Group definition.


def search(self, resources_request=None):
    (name_pattern, version_range) = self._parse_request(resources_request)
    family_names = set((x.name for x in iter_package_families(paths=self.package_paths) if fnmatch.fnmatch(x.name, name_pattern)))
    family_names = sorted(family_names)
    if self.resource_type:
        resource_type = self.resource_type
    elif (version_range or (len(family_names) == 1)):
        resource_type = 'package'
    else:
        resource_type = 'family'
    if (not family_names):
        return (resource_type, [])
    if (resource_type == 'family'):
        results = [ResourceSearchResult(x, 'family') for x in family_names]
        return ('family', results)
    results = []
    for name in family_names:
        it = iter_packages(name, version_range, paths=self.package_paths)
        packages = sorted(it, key=(lambda x: x.version))
        if (self.latest and packages):
            packages = [packages[(- 1)]]
        for package in packages:
            try:
                if package.timestamp:
                    if (self.after_time and (package.timestamp < self.after_time)):
                        continue
                    if (self.before_time and (package.timestamp >= self.before_time)):
                        continue
                if self.validate:
                    package.validate_data()
            except ResourceContentError as e:
                if (resource_type == 'package'):
                    result = ResourceSearchResult(package, 'package', str(e))
                    results.append(result)
                continue
            if (resource_type == 'package'):
                result = ResourceSearchResult(package, 'package')
                results.append(result)
                continue
            try:
                for variant in package.iter_variants():
                    if self.validate:
                        try:
                            variant.validate_data()
                        except ResourceContentError as e:
                            result = ResourceSearchResult(variant, 'variant', str(e))
                            results.append(result)
                            continue
                    result = ResourceSearchResult(variant, 'variant')
                    results.append(result)
            except ResourceContentError:
                continue
    return (resource_type, results)

Search for resources.

Args:
resources_request (str): Resource to search, glob-style patterns
are supported. If None, returns all matching resource types.

Returns:
2-tuple:
- str: resource type (family, package, variant);
- List of `ResourceSearchResult`: Matching resources. Will be in
alphabetical order if families, and version ascending for
packages or variants.


def on_predict_batch_begin(self, batch, logs=None):
    if self._should_call_predict_batch_hooks:
        self._call_batch_hook(ModeKeys.PREDICT, 'begin', batch, logs=logs)

Calls the `on_predict_batch_begin` methods of its callbacks.

Args:
batch: Integer, index of batch within the current epoch.
logs: Dict, contains the return value of `model.predict_step`,
it typically returns a dict with a key 'outputs' containing
the model's outputs.


def canonicalize_observed_time_series_with_mask(maybe_masked_observed_time_series):
    with tf.compat.v1.name_scope('canonicalize_observed_time_series_with_mask'):
        if hasattr(maybe_masked_observed_time_series, 'is_missing'):
            observed_time_series = maybe_masked_observed_time_series.time_series
            is_missing = maybe_masked_observed_time_series.is_missing
        else:
            observed_time_series = maybe_masked_observed_time_series
            is_missing = None
        observed_time_series = tf.convert_to_tensor(value=observed_time_series, name='observed_time_series')
        observed_time_series = _maybe_expand_trailing_dim(observed_time_series)
        if (is_missing is not None):
            is_missing = tf.convert_to_tensor(value=is_missing, name='is_missing', dtype_hint=tf.bool)
        return missing_values_util.MaskedTimeSeries(observed_time_series, is_missing=is_missing)

Extract a Tensor with canonical shape and optional mask.

Args:
maybe_masked_observed_time_series: a `Tensor`-like object with shape
`[..., num_timesteps]` or `[..., num_timesteps, 1]`, or a
`tfp.sts.MaskedTimeSeries` containing such an object.
Returns:
masked_time_series: a `tfp.sts.MaskedTimeSeries` namedtuple, in which
the `observed_time_series` is converted to `Tensor` with canonical shape
`[..., num_timesteps, 1]`, and `is_missing` is either `None` or a boolean
`Tensor`.


def get_node_age_sum(self, age=None):
    if (age is None):
        age = self.age
    return pow(self.comp, age)

Get the sum of branches grown in an specific age.

Returns:
int: The sum of all nodes grown in an age.


def Exists(self, entry):
    if entry in self:
        return True
    return False

Deep comparison of a MapEntry to the MapEntry instances in the Map.

Args:
entry: A maps.MapEntry instance.

Returns:
A boolean indicating the object is present when True.


def generate(cls, public_keys, amount):
    threshold = len(public_keys)
    if (not isinstance(amount, int)):
        raise TypeError('`amount` must be a int')
    if (amount < 1):
        raise AmountError('`amount` needs to be greater than zero')
    if (not isinstance(public_keys, list)):
        raise TypeError('`public_keys` must be an instance of list')
    if (len(public_keys) == 0):
        raise ValueError('`public_keys` needs to contain at least oneowner')
    elif ((len(public_keys) == 1) and (not isinstance(public_keys[0], list))):
        if isinstance(public_keys[0], Fulfillment):
            ffill = public_keys[0]
        else:
            ffill = Ed25519Sha256(public_key=base58.b58decode(public_keys[0]))
        return cls(ffill, public_keys, amount=amount)
    else:
        initial_cond = ThresholdSha256(threshold=threshold)
        threshold_cond = reduce(cls._gen_condition, public_keys, initial_cond)
        return cls(threshold_cond, public_keys, amount=amount)

Generates a Output from a specifically formed tuple or list.

Note:
If a ThresholdCondition has to be generated where the threshold
is always the number of subconditions it is split between, a
list of the following structure is sufficient:

[(address|condition)*, [(address|condition)*, ...], ...]

Args:
public_keys (:obj:`list` of :obj:`str`): The public key of
the users that should be able to fulfill the Condition
that is being created.
amount (:obj:`int`): The amount locked by the Output.

Returns:
An Output that can be used in a Transaction.

Raises:
TypeError: If `public_keys` is not an instance of `list`.
ValueError: If `public_keys` is an empty list.


def get_all_aminames(i_info):

    for i in i_info:
        try:

            i_info[i]['aminame'] = EC2R.Image(i_info[i]['ami']).name
        except AttributeError:
            i_info[i]['aminame'] = "Unknown"
    return i_info

Get Image_Name for each instance in i_info.

Args:
i_info (dict): information on instances and details.
Returns:
i_info (dict): i_info is returned with the aminame
added for each instance.


def before_request():
    if ((not request.path.startswith('/saml')) and (not request.path.startswith('/auth'))):
        if ('accounts' not in session):
            logger.debug("Missing 'accounts' from session object, sending user to login page")
            return BaseView.make_unauth_response()
        if (request.method in ('POST', 'PUT', 'DELETE')):
            if (session['csrf_token'] != request.headers.get('X-Csrf-Token')):
                logger.info('CSRF Token is missing or incorrect, sending user to login page')
                abort(403)

Checks to ensure that the session is valid and validates the users CSRF token is present

Returns:
`None`


def get_events(self, event_title, regex=False):

        regex_val = 0
        if regex:
            regex_val = 1
        r = requests.get('{0}/events/?api_key={1}&username={2}&c-title='
                         '{3}&regex={4}'.format(self.url, self.api_key,
                                                self.username, event_title,
                                                regex_val), verify=self.verify)
        if r.status_code == 200:
            json_obj = json.loads(r.text)
            return json_obj
        else:
            log.error('Non-200 status code from get_event: '
                      '{}'.format(r.status_code))
            return None

Search for events with the provided title

Args:
event_title: The title of the event
Returns:
An event JSON object returned from the server with the following:
{
"meta":{
"limit": 20, "next": null, "offset": 0,
"previous": null, "total_count": 3
},
"objects": [{}, {}, etc]
}
or None if an error occurred.


def prepare_backend_environ(self, host, method, relative_url, headers, body, source_ip, port):
    if isinstance(body, unicode):
        body = body.encode('ascii')
    url = urlparse.urlsplit(relative_url)
    if (port != 80):
        host = ('%s:%s' % (host, port))
    else:
        host = host
    environ = {'CONTENT_LENGTH': str(len(body)), 'PATH_INFO': url.path, 'QUERY_STRING': url.query, 'REQUEST_METHOD': method, 'REMOTE_ADDR': source_ip, 'SERVER_NAME': host, 'SERVER_PORT': str(port), 'SERVER_PROTOCOL': 'HTTP/1.1', 'wsgi.version': (1, 0), 'wsgi.url_scheme': 'http', 'wsgi.errors': cStringIO.StringIO(), 'wsgi.multithread': True, 'wsgi.multiprocess': True, 'wsgi.input': cStringIO.StringIO(body)}
    util.put_headers_in_environ(headers, environ)
    environ['HTTP_HOST'] = host
    return environ

Build an environ object for the backend to consume.

Args:
host: A string containing the host serving the request.
method: A string containing the HTTP method of the request.
relative_url: A string containing path and query string of the request.
headers: A list of (key, value) tuples where key and value are both
strings.
body: A string containing the request body.
source_ip: The source IP address for the request.
port: The port to which to direct the request.

Returns:
An environ object with all the information necessary for the backend to
process the request.


def get_key_delivery_url(access_token, ck_id, key_type):

    path = '/ContentKeys'
    full_path = ''.join([path, "('", ck_id, "')", "/GetKeyDeliveryUrl"])
    endpoint = ''.join([ams_rest_endpoint, full_path])
    body = '{"keyDeliveryType": "' + key_type + '"}'
    return do_ams_post(endpoint, full_path, body, access_token)

Get Media Services Key Delivery URL.

Args:
access_token (str): A valid Azure authentication token.
ck_id (str): A Media Service Content Key ID.
key_type (str): A Media Service key Type.

Returns:
HTTP response. JSON body.


def macro_tpm(self, micro_tpm, check_independence=True):

        if not is_state_by_state(micro_tpm):
            micro_tpm = convert.state_by_node2state_by_state(micro_tpm)

        macro_tpm = self.macro_tpm_sbs(micro_tpm)

        if check_independence:
            validate.conditionally_independent(macro_tpm)

        return convert.state_by_state2state_by_node(macro_tpm)

Create a coarse-grained macro TPM.

Args:
micro_tpm (nd.array): The TPM of the micro-system.
check_independence (bool): Whether to check that the macro TPM is
conditionally independent.

Raises:
ConditionallyDependentError: If ``check_independence`` is ``True``
and the macro TPM is not conditionally independent.

Returns:
np.ndarray: The state-by-node TPM of the macro-system.


def measure_states(states, measurement_matrix, measurement_covariance):
    measurement_matrix = np.atleast_2d(measurement_matrix)
    measurement_covariance = np.atleast_2d(measurement_covariance)
    measurement_dim = measurement_matrix.shape[0]
    if (measurement_covariance.shape != (measurement_dim, measurement_dim)):
        raise ValueError('Measurement matrix and covariance have inconsistent shapes {} and {}'.format(measurement_matrix.shape, measurement_covariance.shape))
    states = np.atleast_2d(states)
    if (states.shape[0] == 0):
        return np.zeros((0, measurement_dim))
    measurement_means = measurement_matrix.dot(states.T).T
    measurement_noises = np.random.multivariate_normal(mean=np.zeros(measurement_dim), cov=measurement_covariance, size=states.shape[0])
    return (measurement_means + measurement_noises)

Measure a list of states with a measurement matrix in the presence of
measurement noise.

Args:
states (array): states to measure. Shape is NxSTATE_DIM.
measurement_matrix (array): Each state in *states* is measured with this
matrix. Should be MEAS_DIMxSTATE_DIM in shape.
measurement_covariance (array): Measurement noise covariance. Should be
MEAS_DIMxMEAS_DIM.

Returns:
(array): NxMEAS_DIM array of measurements.


def _get_connection_state(self, conn_or_int_id):

        key = conn_or_int_id
        if isinstance(key, str):
            table = self._int_connections
        elif isinstance(key, int):
            table = self._connections
        else:
            raise ArgumentError("You must supply either an int connection id or a string internal id to _get_connection_state", id=key)

        if key not in table:
            return self.Disconnected

        data = table[key]
        return data['state']

Get a connection's state by either conn_id or internal_id

This routine must only be called from the internal worker thread.

Args:
conn_or_int_id (int, string): The external integer connection id or
and internal string connection id


def parse_this(func, types, args=None, delimiter_chars=':'):
    _LOG.debug('Creating parser for %s', func.__name__)
    (func_args, dummy_1, dummy_2, defaults) = getargspec(func)
    (types, func_args) = _check_types(func.__name__, types, func_args, defaults)
    args_and_defaults = _get_args_and_defaults(func_args, defaults)
    parser = _get_arg_parser(func, types, args_and_defaults, delimiter_chars)
    arguments = parser.parse_args(_get_args_to_parse(args, sys.argv))
    return _call(func, func_args, arguments)

Create an ArgParser for the given function converting the command line
arguments according to the list of types.

Args:
func: the function for which the command line arguments to be parsed
types: a list of types - as accepted by argparse - that will be used to
convert the command line arguments
args: a list of arguments to be parsed if None sys.argv is used
delimiter_chars: characters used to separate the parameters from their
help message in the docstring. Defaults to ':'


def _get_output_tensor(self, op_type, tensor, checked_tensor, is_v1_graph_mode):
    if is_v1_graph_mode:
        if op_type == b'Placeholder':
            self._placeholder_to_debug_tensor[tensor] = checked_tensor
            return tensor
        else:
            return checked_tensor
    else:
        return tensor

Determine what tensor to output from callback.

Args:
op_type: Type of the op that outputs the original symbolic tensor, as
`bytes`.
tensor: The original output symbolic tensor.
checked_tensor: The debugger-instrumented, numerics-checking tensor.
is_v1_graph_mode: Whether the debugged proggram is running under V1 graph
mode.

Returns:
A symbolic tensor to be returned by the dumping op_callback.


def delete_case(self, case_obj):

        for ind_obj in case_obj.individuals:
            self.delete_individual(ind_obj)
        logger.info("Deleting case {0} from database".format(case_obj.case_id))
        self.session.delete(case_obj)
        self.save()
        return case_obj

Delete a case from the database

Args:
case_obj (puzzle.models.Case): initialized case model


def set_config_files_(self, *config_files):

        self._config_files = tuple(pathlib.Path(path) for path in config_files)

Set the list of config files.

Args:
config_files (pathlike): path of config files, given in the order
of reading.


def _FormatMessage(self, event):
    (message, _) = self._output_mediator.GetFormattedMessages(event)
    if (message is None):
        data_type = getattr(event, 'data_type', 'UNKNOWN')
        raise errors.NoFormatterFound('Unable to find event formatter for: {0:s}.'.format(data_type))
    return message

Formats the message.

Args:
event (EventObject): event.

Returns:
str: message field.

Raises:
NoFormatterFound: if no event formatter can be found to match the data
type in the event.


def send(self, request, stem=None):

        if stem is not None:
            request.url = request.url + "/" + stem.lstrip("/")

        prepped = self.session.prepare_request(request)
        settings = self.session.merge_environment_settings(url=prepped.url,
                                                           proxies={},
                                                           stream=None,
                                                           verify=None,
                                                           cert=None)

        return self.session.send(prepped, **settings)

Prepare and send a request

Arguments:
request: a Request object that is not yet prepared
stem: a path to append to the root URL

Returns:
The response to the request


def upload_blob(self, did, wid, filepath='./blob.json'):
    chars = (string.ascii_letters + string.digits)
    boundary_key = ''.join((random.choice(chars) for i in range(8)))
    mimetype = mimetypes.guess_type(filepath)[0]
    encoded_filename = os.path.basename(filepath)
    file_content_length = str(os.path.getsize(filepath))
    blob = open(filepath)
    req_headers = {'Content-Type': ('multipart/form-data; boundary="%s"' % boundary_key)}
    payload = (((('--' + boundary_key) + '\r\nContent-Disposition: form-data; name="encodedFilename"\r\n\r\n') + encoded_filename) + '\r\n')
    payload += (((('--' + boundary_key) + '\r\nContent-Disposition: form-data; name="fileContentLength"\r\n\r\n') + file_content_length) + '\r\n')
    payload += (((('--' + boundary_key) + '\r\nContent-Disposition: form-data; name="file"; filename="') + encoded_filename) + '"\r\n')
    payload += (('Content-Type: ' + mimetype) + '\r\n\r\n')
    payload += blob.read()
    payload += (('\r\n--' + boundary_key) + '--')
    return self._api.request('post', ((('/api/blobelements/d/' + did) + '/w/') + wid), headers=req_headers, body=payload)

Uploads a file to a new blob element in the specified doc.

Args:
- did (str): Document ID
- wid (str): Workspace ID
- filepath (str, default='./blob.json'): Blob element location

Returns:
- requests.Response: Onshape response data


def configure_vlan(self, vid, commands):
    commands = make_iterable(commands)
    commands.insert(0, ('vlan %s' % vid))
    return self.configure(commands)

Configures the specified Vlan using commands

Args:
vid (str): The VLAN ID to configure
commands: The list of commands to configure

Returns:
True if the commands completed successfully


def put(self, path, value, timeout=None, event_timeout=None):
    future = self.put_async(path, value)
    self.wait_all_futures(future, timeout=timeout, event_timeout=event_timeout)
    return future.result()

Puts a value to a path and returns when it completes

Args:
path (list): The path to put to
value (object): The value to set
timeout (float): time in seconds to wait for responses, wait forever
if None
event_timeout: maximum time in seconds to wait between each response
event, wait forever if None

Returns:
The value after the put completes


def on_each(self, *targets: raw_types.Qid) -> op_tree.OP_TREE:

        return [self.on(target) for target in targets]

Returns a list of operations apply this gate to each of the targets.

Args:
*targets: The qubits to apply this gate to.

Returns:
Operations applying this gate to the target qubits.

Raises:
ValueError if targets are not instances of Qid.


def CopyFromDateTimeString(self, time_string):
    date_time_values = self._CopyDateTimeFromString(time_string)
    year = date_time_values.get('year', 0)
    month = date_time_values.get('month', 0)
    day_of_month = date_time_values.get('day_of_month', 0)
    hours = date_time_values.get('hours', 0)
    minutes = date_time_values.get('minutes', 0)
    seconds = date_time_values.get('seconds', 0)
    self._normalized_timestamp = None
    self._number_of_seconds = self._GetNumberOfSecondsFromElements(year, month, day_of_month, hours, minutes, seconds)
    self._microseconds = date_time_values.get('microseconds', None)
    self.is_local_time = False

Copies a fake timestamp from a date and time string.

Args:
time_string (str): date and time value formatted as:
YYYY-MM-DD hh:mm:ss.######[+-]##:##

Where # are numeric digits ranging from 0 to 9 and the seconds
fraction can be either 3 or 6 digits. The time of day, seconds
fraction and time zone offset are optional. The default time zone
is UTC.