def compute_cost_graph(self, devices=None):
    cost_graph_def = cost_graph_pb2.CostGraphDef()
    for (i, operation_name) in enumerate(self.get_all_operation_names()):
        node = cost_graph_def.node.add(name=operation_name, device=self.get_operation_device(operation_name), id=i)
        for input_name in self.get_operation_input_names(operation_name):
            (id1, id2) = self._tensor_name_to_ids[input_name]
            node.input_info.add(preceding_node=id1, preceding_port=id2)
        for output_name in self.get_operation_output_names(operation_name):
            tensor_device = self.get_tensor_device(output_name)
            if ((devices is None) or (tensor_device is None) or (tensor_device in devices)):
                node.output_info.add(size=self.get_tensor_num_entries(output_name), alias_input_port=(- 1), dtype=self.get_tensor_dtype(output_name).as_datatype_enum, shape=self.get_tensor_shape(output_name).as_proto())
            else:
                node.output_info.add(size=0, alias_input_port=(- 1), dtype=self.get_tensor_dtype(output_name).as_datatype_enum)
            if self.is_tensor_final(output_name):
                node.is_final = True
    return cost_graph_def

Computes a CostGraphDef protobuf based on this graph.

Defined in tensorflow/core/framework/cost_graph.proto.

Args:
devices: optional [string], the names of devices to consider. If
specified, any tensor on a device not listed is given a size of zero.
Any device-less tensor (e.g. Mesh TensorFlow tensor) is not affected.

Returns:
a CostGraphDef protobuf with a Node for every operation in the graph, each
of which is populated with size/dtype information for its inputs and
outputs (which match the input/output order of the operation).


def prepare(path, name):

    setup_path = os.path.join(path, 'setup.py')
    if not os.path.exists(setup_path):
        data = textwrap.dedent( % name)

        logger.info('Module %s does not provide a setup.py. \nGenerating setup.py' % name)

        _files.write_file(setup_path, data)

        data = textwrap.dedent()

        logger.info('Generating setup.cfg')

        _files.write_file(os.path.join(path, 'setup.cfg'), data)

        data = textwrap.dedent()

        logger.info('Generating MANIFEST.in')

        _files.write_file(os.path.join(path, 'MANIFEST.in'), data)

Prepare a Python script (or module) to be imported as a module.
If the script does not contain a setup.py file, it creates a minimal setup.
Args:
path (str): path to directory with the script or module.
name (str): name of the script or module.


def insertImage(page, rect, filename=None, pixmap=None, stream=None, rotate=0,
                keep_proportion = True,
                overlay=True):

    def calc_matrix(fw, fh, tr, rotate=0):

        tmp = Point((tr.x1 + tr.x0) / 2., (tr.y1 + tr.y0) / 2.)

        rot = Matrix(rotate)

        m = Matrix(1, 0, 0, 1, -0.5, -0.5) * rot

        small = min(fw, fh)

        if rotate not in (0, 180):
            fw, fh = fh, fw

        if fw < 1:
            if (float(tr.width) / fw) > (float(tr.height) / fh):
                w = tr.height * small
                h = tr.height
            else:
                w = tr.width
                h = tr.width / small

        elif fw != fh:
            if (float(tr.width) / fw) > (float(tr.height) / fh):
                w = tr.height / small
                h = tr.height
            else:
                w = tr.width
                h = tr.width * small

        else:
            w = tr.width
            h = tr.height

        m *= Matrix(w, h)

        m *= Matrix(1, 0, 0, 1, tmp.x, tmp.y)

        return m

    CheckParent(page)
    doc = page.parent
    if not doc.isPDF:
        raise ValueError("not a PDF")
    if bool(filename) + bool(stream) + bool(pixmap) != 1:
        raise ValueError("need exactly one of filename, pixmap, stream")

    if filename and not os.path.exists(filename):
        raise FileNotFoundError("No such file: '%s'" % filename)
    elif stream and type(stream) not in (bytes, bytearray, io.BytesIO):
        raise ValueError("stream must be bytes-like or BytesIO")
    elif pixmap and type(pixmap) is not Pixmap:
        raise ValueError("pixmap must be a Pixmap")

    while rotate < 0:
        rotate += 360
    while rotate > 360:
        rotate -= 360
    if rotate not in (0, 90, 180, 270):
        raise ValueError("bad rotate value")

    r = page.rect & rect
    if r.isEmpty or r.isInfinite:
        raise ValueError("rect must be finite and not empty")
    _imgpointer = None

    if keep_proportion is True:
        if pixmap:
            w = pixmap.width
            h = pixmap.height
        elif stream:

            img_size = TOOLS.image_size(stream, keep_image=True)
            w, h = img_size[:2]
            stream = None
            _imgpointer = img_size[-1]
        else:
            img = open(filename, "rb")
            stream = img.read()
            img_size = TOOLS.image_size(stream, keep_image=True)
            w, h = img_size[:2]
            _imgpointer = img_size[-1]
            stream = None
            filename = None
            img.close()

        maxf = max(w, h).__float__()
        fw = w / maxf
        fh = h / maxf
    else:
        fw = fh = 1.0

    clip = r * ~page._getTransformation()

    matrix = calc_matrix(fw, fh, clip, rotate=rotate)

    ilst = [i[7] for i in doc.getPageImageList(page.number)]
    n = "fzImg"
    i = 0
    _imgname = n + "0"
    while _imgname in ilst:
        i += 1
        _imgname = n + str(i)

    page._insertImage(
            filename=filename,
            pixmap=pixmap,
            stream=stream,
            matrix=matrix,
            overlay=overlay,
            _imgname=_imgname,
            _imgpointer=_imgpointer,
        )

Insert an image in a rectangle on the current page.

Notes:
Exactly one of filename, pixmap or stream must be provided.
Args:
rect: (rect-like) where to place the source image
filename: (str) name of an image file
pixmap: (obj) a Pixmap object
stream: (bytes) an image in memory
rotate: (int) degrees (multiple of 90)
keep_proportion: (bool) whether to maintain aspect ratio
overlay: (bool) put in foreground


def set_ocha_url(cls, url=None):
    if (url is None):
        url = cls._ochaurl_int
    cls._ochaurl = url

Set World Bank url from which to retrieve countries data

Args:
url (str): World Bank url from which to retrieve countries data. Defaults to internal value.

Returns:
None


def _determine_timeout(default_timeout, specified_timeout, retry):
    if (specified_timeout is DEFAULT):
        specified_timeout = default_timeout
    if (specified_timeout is default_timeout):
        if (retry and (retry is not DEFAULT) and isinstance(default_timeout, timeout.ExponentialTimeout)):
            return default_timeout.with_deadline(retry._deadline)
        else:
            return default_timeout
    if isinstance(specified_timeout, (int, float)):
        return timeout.ConstantTimeout(specified_timeout)
    else:
        return specified_timeout

Determines how timeout should be applied to a wrapped method.

Args:
default_timeout (Optional[Timeout]): The default timeout specified
at method creation time.
specified_timeout (Optional[Timeout]): The timeout specified at
invocation time. If :attr:`DEFAULT`, this will be set to
the ``default_timeout``.
retry (Optional[Retry]): The retry specified at invocation time.

Returns:
Optional[Timeout]: The timeout to apply to the method or ``None``.


def testConcreteFunctionStructuredSignatureError(self, conc_args=(), conc_kwargs=None, call_args=(), call_kwargs=None, error='.*', exception=TypeError):
    conc_args = conc_args() if callable(conc_args) else conc_args
    conc_kwargs = conc_kwargs() if callable(conc_kwargs) else conc_kwargs or {}
    call_args = call_args() if callable(call_args) else call_args
    call_kwargs = call_kwargs() if callable(call_kwargs) else call_kwargs or {}
    self.assertIsInstance(conc_args, tuple)
    self.assertIsInstance(call_args, tuple)
    self.assertIsInstance(conc_kwargs, dict)
    self.assertIsInstance(call_kwargs, dict)

    @polymorphic_function.function
    def func(x, y=5, *varargs, **kwargs):
        del y, varargs, kwargs
        return x
    conc = func.get_concrete_function(*conc_args, **conc_kwargs)
    with self.assertRaisesRegex(exception, error):
        self.evaluate(conc(*call_args, **call_kwargs))

Tests for errors in the structured signature.

Args:
conc_args: Positional arguments used for get_concrete_function.
conc_kwargs: Keyword arguments used for get_concrete_function.
call_args: Positional arguments used to call the function.
call_kwargs: Keyword arguments used to call the function.
error: Expected exception message.
exception: Expected exception type.


def load_img(path, grayscale=False, target_size=None):
    img = io.imread(path, grayscale)
    if target_size:
        img = transform.resize(img, target_size, preserve_range=True).astype('uint8')
    return img

Utility function to load an image from disk.

Args:
path: The image file path.
grayscale: True to convert to grayscale image (Default value = False)
target_size: (w, h) to resize. (Default value = None)

Returns:
The loaded numpy image.


def get_index(self, prefix=''):

        if prefix:
            prefixed = '%s_index' % prefix
        else:
            prefixed = 'index'

        if prefixed in self.__cli and self.__cli[prefixed]:
            index = self.__cli.get(prefixed)
            from_conf = False
        else:
            index = self.__config.get(prefixed)
            from_conf = True

        return self.__abspath(index, from_conf)

Retrieve the absolute path to an index, according to
`prefix`.

Args:
prefix: str, the desired prefix or `None`.

Returns:
str: An absolute path, or `None`


def build_error_response(self, version, reason, message):
    batch_item = messages.ResponseBatchItem(result_status=contents.ResultStatus(enums.ResultStatus.OPERATION_FAILED), result_reason=contents.ResultReason(reason), result_message=contents.ResultMessage(message))
    return self._build_response(version, [batch_item])

Build a simple ResponseMessage with a single error result.

Args:
version (ProtocolVersion): The protocol version the response
should be addressed with.
reason (ResultReason): An enumeration classifying the type of
error occurred.
message (str): A string providing additional information about
the error.

Returns:
ResponseMessage: The simple ResponseMessage containing a
single error result.


def autobuild_release(family=None):

    if family is None:
        family = utilities.get_family('module_settings.json')

    env = Environment(tools=[])
    env['TILE'] = family.tile

    target = env.Command(['
                         action=env.Action(create_release_settings_action, "Creating release manifest"))
    env.AlwaysBuild(target)

    if os.path.exists('RELEASE.md'):
        env.Command(['build/output/RELEASE.md'], ['RELEASE.md'], Copy("$TARGET", "$SOURCE"))

    copy_include_dirs(family.tile)
    copy_tilebus_definitions(family.tile)
    copy_dependency_docs(family.tile)
    copy_linker_scripts(family.tile)

    if not family.tile.settings.get('hide_dependency_images', False):
        copy_dependency_images(family.tile)

    copy_extra_files(family.tile)
    build_python_distribution(family.tile)

Copy necessary files into build/output so that this component can be used by others

Args:
family (ArchitectureGroup): The architecture group that we are targeting.  If not
provided, it is assumed that we are building in the current directory and the
module_settings.json file is read to create an ArchitectureGroup


def _dereference_args(pipeline_name, args, kwargs):
    lookup_slots = set()
    for arg in itertools.chain(args, kwargs.itervalues()):
        if (arg['type'] == 'slot'):
            lookup_slots.add(db.Key(arg['slot_key']))
    slot_dict = {}
    for (key, slot_record) in zip(lookup_slots, db.get(lookup_slots)):
        if ((slot_record is None) or (slot_record.status != _SlotRecord.FILLED)):
            raise SlotNotFilledError(('Slot "%s" missing its value. From %s(*args=%s, **kwargs=%s)' % (key, pipeline_name, _short_repr(args), _short_repr(kwargs))))
        slot_dict[key] = slot_record.value
    arg_list = []
    for current_arg in args:
        if (current_arg['type'] == 'slot'):
            arg_list.append(slot_dict[db.Key(current_arg['slot_key'])])
        elif (current_arg['type'] == 'value'):
            arg_list.append(current_arg['value'])
        else:
            raise UnexpectedPipelineError(('Unknown parameter type: %r' % current_arg))
    kwarg_dict = {}
    for (key, current_arg) in kwargs.iteritems():
        if (current_arg['type'] == 'slot'):
            kwarg_dict[key] = slot_dict[db.Key(current_arg['slot_key'])]
        elif (current_arg['type'] == 'value'):
            kwarg_dict[key] = current_arg['value']
        else:
            raise UnexpectedPipelineError(('Unknown parameter type: %r' % current_arg))
    return (arg_list, kwarg_dict)

Dereference a Pipeline's arguments that are slots, validating them.

Each argument value passed in is assumed to be a dictionary with the format:
{'type': 'value', 'value': 'serializable'}  # A resolved value.
{'type': 'slot', 'slot_key': 'str() on a db.Key'}  # A pending Slot.

Args:
pipeline_name: The name of the pipeline class; used for debugging.
args: Iterable of positional arguments.
kwargs: Dictionary of keyword arguments.

Returns:
Tuple (args, kwargs) where:
Args: A list of positional arguments values that are all dereferenced.
Kwargs: A list of keyword arguments values that are all dereferenced.

Raises:
SlotNotFilledError if any of the supplied 'slot_key' records are not
present in the Datastore or have not yet been filled.
UnexpectedPipelineError if an unknown parameter type was passed.


def flash_from_file(self, partition, source_file, source_len=0,
                      info_cb=DEFAULT_MESSAGE_CALLBACK, progress_callback=None,
                      timeout_ms=None):

    if source_len == 0:

      source_len = os.stat(source_file).st_size
    download_response = self.download(
        source_file, source_len=source_len, info_cb=info_cb,
        progress_callback=progress_callback)
    flash_response = self.flash(partition, info_cb=info_cb,
                                timeout_ms=timeout_ms)
    return download_response + flash_response

Flashes a partition from the file on disk.

Args:
partition: Partition name to flash to.
source_file: Filename to download to the device.
source_len: Optional length of source_file, uses os.stat if not provided.
info_cb: See Download.
progress_callback: See Download.
timeout_ms: The amount of time to wait on okay after flashing.

Returns:
Download and flash responses, normally nothing.


def __init__(self, vendor_id=9583, product_id=50735):

        print("Opening SpaceMouse device")
        self.device = hid.device()
        self.device.open(vendor_id, product_id)

        print("Manufacturer: %s" % self.device.get_manufacturer_string())
        print("Product: %s" % self.device.get_product_string())

        self._display_controls()

        self.single_click_and_hold = False

        self._control = [0., 0., 0., 0., 0., 0.]
        self._reset_state = 0
        self.rotation = np.array([[-1., 0., 0.], [0., 1., 0.], [0., 0., -1.]])
        self._enabled = False

        self.thread = threading.Thread(target=self.run)
        self.thread.daemon = True
        self.thread.start()

Initialize a SpaceMouse handler.

Args:
vendor_id: HID device vendor id
product_id: HID device product id

Note:
Use hid.enumerate() to view all USB human interface devices (HID).
Make sure SpaceMouse is detected before running the script.
You can look up its vendor/product id from this method.


def constant_time_string_compare(a, b):
    try:
        return hmac.compare_digest(a, b)
    except AttributeError:
        if (len(a) != len(b)):
            return False
        result = 0
        for (x, y) in zip(a, b):
            result |= (ord(x) ^ ord(y))
        return (result == 0)

Helper for comparing string in constant time, independent
of the python version being used.

Args:
a (str): A string to compare
b (str): A string to compare


def contains_saved_model(export_dir):
    if isinstance(export_dir, os.PathLike):
        export_dir = os.fspath(export_dir)
    return maybe_saved_model_directory(export_dir)

Checks whether the provided export directory could contain a SavedModel.

Note that the method does not load any data by itself. If the method returns
`false`, the export directory definitely does not contain a SavedModel. If the
method returns `true`, the export directory may contain a SavedModel but
provides no guarantee that it can be loaded.

Args:
export_dir: Absolute path to possible export location. For example,
'/my/foo/model'.

Returns:
True if the export directory contains SavedModel files, False otherwise.


def write(self, data):
    if (not isinstance(data, (bytes, bytearray, list))):
        raise TypeError('Invalid data type, should be bytes, bytearray, or list.')
    if isinstance(data, list):
        data = bytearray(data)
    try:
        return os.write(self._fd, data)
    except OSError as e:
        raise SerialError(e.errno, ('Writing serial port: ' + e.strerror))

Write `data` to the serial port and return the number of bytes
written.

Args:
data (bytes, bytearray, list): a byte array or list of 8-bit integers to write.

Returns:
int: number of bytes written.

Raises:
SerialError: if an I/O or OS error occurs.
TypeError: if `data` type is invalid.
ValueError: if data is not valid bytes.


def Progress(self):
    now = time.time()
    if ((now - self.last_progress_time) <= 2):
        return
    self.last_progress_time = now
    client_utils.KeepAlive()
    self.grr_worker.Heartbeat()
    user_start = self.cpu_start.user
    system_start = self.cpu_start.system
    cpu_times = self.proc.cpu_times()
    user_end = cpu_times.user
    system_end = cpu_times.system
    used_cpu = (((user_end - user_start) + system_end) - system_start)
    if (used_cpu > self.cpu_limit):
        self.grr_worker.SendClientAlert('Cpu limit exceeded.')
        raise CPUExceededError('Action exceeded cpu limit.')

Indicate progress of the client action.

This function should be called periodically during client actions that do
not finish instantly. It will notify the nanny that the action is not stuck
and avoid the timeout and it will also check if the action has reached its
cpu limit.

Raises:
CPUExceededError: CPU limit exceeded.


def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, syntax=None):
    if ((api_implementation.Type() == 'cpp') and build_file_if_cpp):
        from typy.google.protobuf import descriptor_pb2
        file_descriptor_proto = descriptor_pb2.FileDescriptorProto()
        file_descriptor_proto.message_type.add().MergeFrom(desc_proto)
        proto_name = str(uuid.uuid4())
        if package:
            file_descriptor_proto.name = os.path.join(package.replace('.', '/'), (proto_name + '.proto'))
            file_descriptor_proto.package = package
        else:
            file_descriptor_proto.name = (proto_name + '.proto')
        _message.default_pool.Add(file_descriptor_proto)
        result = _message.default_pool.FindFileByName(file_descriptor_proto.name)
        if _USE_C_DESCRIPTORS:
            return result.message_types_by_name[desc_proto.name]
    full_message_name = [desc_proto.name]
    if package:
        full_message_name.insert(0, package)
    enum_types = {}
    for enum_proto in desc_proto.enum_type:
        full_name = '.'.join((full_message_name + [enum_proto.name]))
        enum_desc = EnumDescriptor(enum_proto.name, full_name, None, [EnumValueDescriptor(enum_val.name, ii, enum_val.number) for (ii, enum_val) in enumerate(enum_proto.value)])
        enum_types[full_name] = enum_desc
    nested_types = {}
    for nested_proto in desc_proto.nested_type:
        full_name = '.'.join((full_message_name + [nested_proto.name]))
        nested_desc = MakeDescriptor(nested_proto, package='.'.join(full_message_name), build_file_if_cpp=False, syntax=syntax)
        nested_types[full_name] = nested_desc
    fields = []
    for field_proto in desc_proto.field:
        full_name = '.'.join((full_message_name + [field_proto.name]))
        enum_desc = None
        nested_desc = None
        if field_proto.HasField('type_name'):
            type_name = field_proto.type_name
            full_type_name = '.'.join((full_message_name + [type_name[(type_name.rfind('.') + 1):]]))
            if (full_type_name in nested_types):
                nested_desc = nested_types[full_type_name]
            elif (full_type_name in enum_types):
                enum_desc = enum_types[full_type_name]
        field = FieldDescriptor(field_proto.name, full_name, (field_proto.number - 1), field_proto.number, field_proto.type, FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), field_proto.label, None, nested_desc, enum_desc, None, False, None, options=field_proto.options, has_default_value=False)
        fields.append(field)
    desc_name = '.'.join(full_message_name)
    return Descriptor(desc_proto.name, desc_name, None, None, fields, list(nested_types.values()), list(enum_types.values()), [], options=desc_proto.options)

Make a protobuf Descriptor given a DescriptorProto protobuf.

Handles nested descriptors. Note that this is limited to the scope of defining
a message inside of another message. Composite fields can currently only be
resolved if the message is defined in the same scope as the field.

Args:
desc_proto: The descriptor_pb2.DescriptorProto protobuf message.
package: Optional package name for the new message Descriptor (string).
build_file_if_cpp: Update the C++ descriptor pool if api matches.
Set to False on recursion, so no duplicates are created.
syntax: The syntax/semantics that should be used.  Set to "proto3" to get
proto3 field presence semantics.
Returns:
A Descriptor for protobuf messages.


def assign_methods(self, resource_class):

        assert all([
            x.upper() in VALID_METHODS for x in resource_class.Meta.methods])
        for method in resource_class.Meta.methods:

            self._assign_method(
                resource_class,
                method.upper()
            )

Given a resource_class and it's Meta.methods tuple,
assign methods for communicating with that resource.

Args:
resource_class: A single resource class


def update_box(self, box):

		payload = None
		if  type(box) is not StreakBox:
			return requests.codes.bad_request, None

		payload = box.to_dict(rw = True)

		try:
			uri = self.box_root_uri + '/' + box.attributes['boxKey']
		except KeyError:
			return requests.codes.bad_request, None

		code, data = self._req('post', uri , json.dumps(payload))

		return code, data

Updates a box with the provided attributes.
Args:
box 	StreakBox object with updated info
return	(status code, box in dict form)


def _setBitOn(x, bitNum):

    _checkInt(x, minvalue=0, description='input value')
    _checkInt(bitNum, minvalue=0, description='bitnumber')

    return x | (1 << bitNum)

Set bit 'bitNum' to True.

Args:
* x (int): The value before.
* bitNum (int): The bit number that should be set to True.

Returns:
The value after setting the bit. This is an integer.

For example:
For x = 4 (dec) = 0100 (bin), setting bit number 0 results in 0101 (bin) = 5 (dec).


async def process_response(self, request, response):
    (await super().process_response(request, response))
    if (COOKIE_AUTH_KEY in request):
        if response.started:
            raise RuntimeError('Cannot save cookie into started response')
        cookie = request[COOKIE_AUTH_KEY]
        if (cookie == ''):
            response.del_cookie(self.cookie_name)
        else:
            response.set_cookie(self.cookie_name, cookie)

Called to perform any processing of the response required.

This function stores any cookie data in the COOKIE_AUTH_KEY as a
cookie in the response object. If the value is a empty string, the
associated cookie is deleted instead.

This function requires the response to be a aiohttp Response object,
and assumes that the response has not started if the remember or
forget functions are called during the request.

Args:
request: aiohttp Request object.
response: response object returned from the handled view

Raises:
RuntimeError: Raised if response has already started.


def _CalculateNTFSTimeHash(self, file_entry):

    date_time_values = []

    access_time = getattr(file_entry, 'access_time', None)
    if access_time:
      date_time_string = access_time.CopyToDateTimeString()
      date_time_values.append('atime:{0:s}'.format(date_time_string))

    creation_time = getattr(file_entry, 'creation_time', None)
    if creation_time:
      date_time_string = creation_time.CopyToDateTimeString()
      date_time_values.append('crtime:{0:s}'.format(date_time_string))

    modification_time = getattr(file_entry, 'modification_time', None)
    if modification_time:
      date_time_string = modification_time.CopyToDateTimeString()
      date_time_values.append('mtime:{0:s}'.format(date_time_string))

    change_time = getattr(file_entry, 'change_time', None)
    if change_time:
      date_time_string = change_time.CopyToDateTimeString()
      date_time_values.append('ctime:{0:s}'.format(date_time_string))

    date_time_values = ''.join(date_time_values)
    date_time_values = date_time_values.encode('ascii')

    hash_value = hashlib.md5()
    hash_value.update(date_time_values)
    return hash_value.hexdigest()

Calculates an MD5 from the date and time value of a NTFS file entry.

Args:
file_entry (dfvfs.FileEntry): file entry.

Returns:
str: hexadecimal representation of the MD5 hash value of the date and
time values of the file entry.


def locator(self, value):
    self._locator = value
    (self._latitude, self._longitude) = utils.from_grid_locator(value)

Update the locator, and trigger a latitude and longitude update.

Args:
value (str): New Maidenhead locator string


def _process_dataset(name, directory, num_shards, synset_to_human,
                     image_to_bboxes):

  filenames, synsets, labels = _find_image_files(directory, FLAGS.labels_file)
  humans = _find_human_readable_labels(synsets, synset_to_human)
  bboxes = _find_image_bounding_boxes(filenames, image_to_bboxes)
  _process_image_files(name, filenames, synsets, labels,
                       humans, bboxes, num_shards)

Process a complete data set and save it as a TFRecord.

Args:
name: string, unique identifier specifying the data set.
directory: string, root path to the data set.
num_shards: integer number of shards for this data set.
synset_to_human: dict of synset to human labels, e.g.,
'n02119022' --> 'red fox, Vulpes vulpes'
image_to_bboxes: dictionary mapping image file names to a list of
bounding boxes. This list contains 0+ bounding boxes.


def create_detector(model_uri: str, **kwargs) -> OfflineDetector:
    model_handler = KeyedModelHandler(PyODModelHandler(model_uri=model_uri)).with_postprocess_fn(OfflineDetector.score_prediction_adapter)
    m = model_handler.load_model()
    assert isinstance(m, PyODBaseDetector)
    threshold = float(m.threshold_)
    detector = OfflineDetector(model_handler, threshold_criterion=FixedThreshold(threshold), **kwargs)
    return detector

A utility function to create OfflineDetector for a PyOD model.

**NOTE:** This API and its implementation are currently under active
development and may not be backward compatible.

Args:
model_uri: The URI specifying the location of the pickled PyOD model.
**kwargs: Additional keyword arguments.


def restore(self, save_path, options=None):
    self._checkpoint_options = copy.copy(options) if options else self._checkpoint_options
    if self._checkpoint_options:
        self._checkpoint_options.experimental_enable_async_checkpoint = False
    self._queue.join()
    status = self.checkpointer().restore(save_path, self._checkpoint_options)
    return status

Restore the checkpointed variables.

Args:
save_path: The full name of the checkpoint file to be restored.
options: CheckpointOption instance.

Returns:
A load status object, which can be used to make assertions about the
status of a checkpoint restoration. See tf.train.Checkpoint.restore()
for more details.


def add_response(self, req, resp):

        if self._cache is None:
            return
        signature = sign(req.allocateQuotaRequest)
        with self._cache as c:
            now = self._timer()
            item = c.get(signature)
            if item is None:
                c[signature] = CachedItem(
                    req, resp, self.service_name, now)
            else:

                item.last_check_time = now
                item.response = resp
                item.is_in_flight = False
                c[signature] = item

Adds the response from sending to `req` to this instance's cache.

Args:
req (`ServicecontrolServicesAllocateQuotaRequest`): the request
resp (AllocateQuotaResponse): the response from sending the request


def get_all(self, include_archived=False):
    return [conv for conv in self._conv_dict.values() if ((not conv.is_archived) or include_archived)]

Get all the conversations.

Args:
include_archived (bool): (optional) Whether to include archived
conversations. Defaults to ``False``.

Returns:
List of all :class:`.Conversation` objects.


def to_dict(self, remove_nones=False):
    content = {'uri': self.uri, 'protocol_info': self.protocol_info, 'import_uri': self.import_uri, 'size': self.size, 'duration': self.duration, 'bitrate': self.bitrate, 'sample_frequency': self.sample_frequency, 'bits_per_sample': self.bits_per_sample, 'nr_audio_channels': self.nr_audio_channels, 'resolution': self.resolution, 'color_depth': self.color_depth, 'protection': self.protection}
    if remove_nones:
        nones = [k for k in content if (content[k] is None)]
        for k in nones:
            del content[k]
    return content

Return a dict representation of the `DidlResource`.

Args:
remove_nones (bool, optional): Optionally remove dictionary
elements when their value is `None`.

Returns:
dict: a dict representing the `DidlResource`


def run_defense_work(self, work_id):

    class_batch_id = (
        self.defense_work.work[work_id]['output_classification_batch_id'])
    class_batch = self.class_batches.read_batch_from_datastore(class_batch_id)
    adversarial_batch_id = class_batch['adversarial_batch_id']
    submission_id = class_batch['submission_id']
    cloud_result_path = class_batch['result_path']
    logging.info('Defense work piece: '
                 'adversarial_batch_id="%s" submission_id="%s"',
                 adversarial_batch_id, submission_id)
    if submission_id in self.blacklisted_submissions:
      raise WorkerError('Blacklisted submission')

    defense = DefenseSubmission(submission_id, self.submissions,
                                self.storage_bucket)
    defense.download()

    input_dir = os.path.join(LOCAL_INPUT_DIR, adversarial_batch_id)
    if os.path.exists(input_dir):
      sudo_remove_dirtree(input_dir)
    os.makedirs(input_dir)
    try:
      shell_call([
          'gsutil', '-m', 'cp',

          os.path.join('gs:
                       'adversarial_images', adversarial_batch_id, '*'),
          input_dir
      ])
      adv_images_files = os.listdir(input_dir)
      if (len(adv_images_files) == 1) and adv_images_files[0].endswith('.zip'):
        logging.info('Adversarial batch is in zip archive %s',
                     adv_images_files[0])
        shell_call([
            'unzip', os.path.join(input_dir, adv_images_files[0]),
            '-d', input_dir
        ])
        os.remove(os.path.join(input_dir, adv_images_files[0]))
        adv_images_files = os.listdir(input_dir)
      logging.info('%d adversarial images copied', len(adv_images_files))
    except (subprocess.CalledProcessError, IOError) as e:
      raise WorkerError('Can''t copy adversarial batch locally', e)

    if os.path.exists(LOCAL_OUTPUT_DIR):
      sudo_remove_dirtree(LOCAL_OUTPUT_DIR)
    os.mkdir(LOCAL_OUTPUT_DIR)
    output_filname = os.path.join(LOCAL_OUTPUT_DIR, 'result.csv')

    elapsed_time_sec = defense.run(input_dir, output_filname)

    batch_result = eval_lib.analyze_one_classification_result(
        storage_client=None,
        file_path=output_filname,
        adv_batch=self.adv_batches.data[adversarial_batch_id],
        dataset_batches=self.dataset_batches,
        dataset_meta=self.dataset_meta)

    try:
      shell_call([
          'gsutil', 'cp', output_filname,
          os.path.join('gs:
      ])
    except subprocess.CalledProcessError as e:
      raise WorkerError('Can''t result to Cloud Storage', e)
    return elapsed_time_sec, submission_id, batch_result

Runs one defense work.

Args:
work_id: ID of the piece of work to run

Returns:
elapsed_time_sec, submission_id - elapsed time and id of the submission

Raises:
WorkerError: if error occurred during execution.


def from_dict(cls, tx, skip_schema_validation=True):

        operation = tx.get('operation', Transaction.CREATE) if isinstance(tx, dict) else Transaction.CREATE
        cls = Transaction.resolve_class(operation)

        if not skip_schema_validation:
            cls.validate_id(tx)
            cls.validate_schema(tx)

        inputs = [Input.from_dict(input_) for input_ in tx['inputs']]
        outputs = [Output.from_dict(output) for output in tx['outputs']]
        return cls(tx['operation'], tx['asset'], inputs, outputs,
                   tx['metadata'], tx['version'], hash_id=tx['id'], tx_dict=tx)

Transforms a Python dictionary to a Transaction object.

Args:
tx_body (dict): The Transaction to be transformed.

Returns:
:class:`~bigchaindb.common.transaction.Transaction`


def sign(self, byts):

        chosen_hash = c_hashes.SHA256()
        hasher = c_hashes.Hash(chosen_hash, default_backend())
        hasher.update(byts)
        digest = hasher.finalize()
        return self.priv.sign(digest,
                              c_ec.ECDSA(c_utils.Prehashed(chosen_hash))
                              )

Compute the ECC signature for the given bytestream.

Args:
byts (bytes): The bytes to sign.

Returns:
bytes: The RSA Signature bytes.


def show_stories(self, raw=False, limit=None):
    show_stories = self._get_stories('showstories', limit)
    if raw:
        show_stories = [story.raw for story in show_stories]
    return show_stories

Returns list of item ids of latest Show HN stories

Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.

Returns:
`list` object containing ids of Show HN stories.


def get_path_list(self, type_str=None):
    return list(reversed([v.label_str for v in self.parent_gen if (type_str in (None, v.type_str))]))

Get list of the labels of the nodes leading up to this node from the root.

Args:
type_str:
SUBJECT_NODE_TAG, TYPE_NODE_TAG or None. If set, only include
information from nodes of that type.

Returns:
list of str: The labels of the nodes leading up to this node from the root.


def check(self, dsm, **kwargs):

        med_matrix = CompleteMediation.generate_mediation_matrix(dsm)
        return CompleteMediation.matrices_compliance(dsm, med_matrix)

Check if matrix and its mediation matrix are compliant.

It means that number of dependencies for each (line, column) is either
0 if the mediation matrix (line, column) is 0, or >0 if the mediation
matrix (line, column) is 1.

Args:
dsm (:class:`DesignStructureMatrix`): the DSM to check.

Returns:
bool: True if compliant, else False


def find_element_by_name(self, name, update=False) -> Elements:

        return self.find_element(by=By.NAME, value=name, update=update)

Finds an element by name.

Args:
name: The name of the element to be found.
update: If the interface has changed, this option should be True.

Returns:
The element if it was found.

Raises:
NoSuchElementException - If the element wasn't found.

Usage:
element = driver.find_element_by_name('foo')


def _linear_interp(curve, test_x, round_result=False):
    index = 0
    for index in range((len(curve) - 1)):
        if (curve[index][0] == curve[(index + 1)][0]):
            continue
        if (curve[index][0] <= test_x <= curve[(index + 1)][0]):
            slope = ((curve[(index + 1)][1] - curve[index][1]) / (curve[(index + 1)][0] - curve[index][0]))
            y_intercept = (curve[index][1] - (slope * curve[index][0]))
            result = ((slope * test_x) + y_intercept)
            if round_result:
                return int(round(result))
            elif result.is_integer():
                return int(result)
            else:
                return result
    else:
        raise ProbabilityUndefinedError

Take a series of points and interpolate between them at ``test_x``.

Args:
curve (list[tuple]): A list of ``(x, y)`` points sorted in
nondecreasing ``x`` value. If multiple points have the same
``x`` value, all but the last will be ignored.
test_x (float): The ``x`` value to find the ``y`` value of

Returns:
float: The ``y`` value of the curve at ``test_x``
if ``round_result is False``

int: if ``round_result is True`` or the result is a whole number,
the ``y`` value of the curve at ``test_x`` rounded to the
nearest whole number.

Raises:
ProbabilityUndefinedError: if ``test_x`` is out of the
domain of ``curve``

Example:
>>> curve = [(0, 0), (2, 1)]
>>> _linear_interp(curve, 0.5)
0.25
>>> _linear_interp(curve, 0.5, round_result=True)
0


def prep_parallel(self, binary_args, other_args):
    if (self.length < 100):
        raise Exception('Run this across 1 processor by setting num_processors kwarg to None.')
    if (self.num_processors == (- 1)):
        self.num_processors = mp.cpu_count()
    split_val = int(np.ceil((self.length / self.num_splits)))
    split_inds = [(self.num_splits * i) for i in np.arange(1, split_val)]
    inds_split_all = np.split(np.arange(self.length), split_inds)
    self.args = []
    for (i, ind_split) in enumerate(inds_split_all):
        trans_args = []
        for arg in binary_args:
            try:
                trans_args.append(arg[ind_split])
            except TypeError:
                trans_args.append(arg)
        self.args.append(((i, tuple(trans_args)) + other_args))
    return

Prepare the parallel calculations

Prepares the arguments to be run in parallel.
It will divide up arrays according to num_splits.

Args:
binary_args (list): List of binary arguments for input into the SNR function.
other_args (tuple of obj): tuple of other args for input into parallel snr function.


def write_sample(binary, payload, path, filename):

    if not os.path.exists(path):
        os.makedirs(path)

    sample = os.path.join(path, filename)

    if binary:
        with open(sample, "wb") as f:
            f.write(base64.b64decode(payload))
    else:
        with open(sample, "w") as f:
            f.write(payload)

This function writes a sample on file system.

Args:
binary (bool): True if it's a binary file
payload: payload of sample, in base64 if it's a binary
path (string): path of file
filename (string): name of file
hash_ (string): file hash


Pre-fetches all required items to be update into the cache.

This increases performance for update operations.

Args:
feed: List of feed items to retrieve


def bottom(self, features):

    if not self._problem_hparams:
      log_warn("Without a Problem, T2TModel.bottom is a passthrough.")
      return features

    transformed_features = collections.OrderedDict()
    all_previous_modalities = []
    target_modality = _create_target_modality(self._problem_hparams.modality)

    for feature_name, modality in sorted(
        six.iteritems(self._problem_hparams.modality)):
      if feature_name not in features:
        tf.logging.warning("Missing feature %s - ignoring." % feature_name)
        continue
      vocab_size = self._problem_hparams.vocab_size[feature_name]
      if vocab_size is not None and hasattr(self._hparams, "vocab_divisor"):
        vocab_size += (-vocab_size) % self._hparams.vocab_divisor
      modality_name = self._hparams.name.get(
          feature_name,
          modalities.get_name(modality))(self._hparams, vocab_size)

      if feature_name in target_modality:
        if len(target_modality) > 1:
          variable_scope_name = "%s/%s" % (modality_name, feature_name)
        else:
          variable_scope_name = modality_name
        bottom = self._hparams.bottom.get(
            feature_name,
            modalities.get_targets_bottom(modality))

        with tf.variable_scope(variable_scope_name) as vs:
          self._add_variable_scope(variable_scope_name, vs)
          log_info("Transforming feature '%s' with %s.targets_bottom",
                   feature_name,
                   modality_name)
          transformed_features[feature_name] = bottom(features[feature_name],
                                                      self._hparams,
                                                      vocab_size)
      else:
        bottom = self._hparams.bottom.get(feature_name,
                                          modalities.get_bottom(modality))
        do_reuse = modality_name in all_previous_modalities
        with tf.variable_scope(modality_name, reuse=do_reuse) as vs:
          self._add_variable_scope(modality_name, vs)
          log_info("Transforming feature '%s' with %s.bottom",
                   feature_name,
                   modality_name)
          transformed_features[feature_name] = bottom(features[feature_name],
                                                      self._hparams,
                                                      vocab_size)
        all_previous_modalities.append(modality_name)

    for key in features:
      if key not in transformed_features:

        transformed_features[key] = features[key]
      else:

        transformed_features[key + "_raw"] = features[key]

    return transformed_features

Transforms features to feed into body.

Args:
features: dict of str to Tensor. Typically it is the preprocessed data
batch after Problem's preprocess_example().

Returns:
transformed_features: dict of same key-value pairs as features. The value
Tensors are newly transformed.


def enter_diff_mode(self, context_model=None):
    assert (not self.diff_mode)
    self.diff_mode = True
    if (context_model is None):
        self.diff_from_source = True
        self.diff_context_model = self.context_model.copy()
    else:
        self.diff_from_source = False
        self.diff_context_model = context_model
    self.clear()
    self.setColumnCount(5)
    self.refresh()

Enter diff mode.

Args:
context_model (`ContextModel`): Context to diff against. If None, a
copy of the current context is used.


def JobDueToRun(self, job):

    if not job.enabled:
      return False

    if job.forced_run_requested:
      return True

    now = rdfvalue.RDFDatetime.Now()

    if (job.last_run_time is not None and
        job.last_run_time + job.frequency > now):
      return False

    if not job.current_run_id:
      return True

    if job.allow_overruns:
      return True

    return False

Determines if the given job is due for another run.

Args:
job: The cron job rdfvalue object.

Returns:
True if it is time to run based on the specified frequency.


def __copyfile2(source, destination):

    logger.info("copyfile2: %s -> %s" % (source, destination))
    try:
        __create_destdir(destination)
        shutil.copy2(source, destination)
        return True
    except Exception as e:
        logger.error(
            "copyfile2: %s -> %s failed! Error: %s", source, destination, e
        )
        return False

Copy data and all stat info ("cp -p source destination").

The destination may be a directory.

Args:
source (str): Source file (file to copy).
destination (str): Destination file or directory (where to copy).

Returns:
bool: True if the operation is successful, False otherwise.


def flow2rgb(flow, color_wheel=None, unknown_thr=1000000.0):
    assert ((flow.ndim == 3) and (flow.shape[(- 1)] == 2))
    if (color_wheel is None):
        color_wheel = make_color_wheel()
    assert ((color_wheel.ndim == 2) and (color_wheel.shape[1] == 3))
    num_bins = color_wheel.shape[0]
    dx = flow[(:, :, 0)].copy()
    dy = flow[(:, :, 1)].copy()
    ignore_inds = (((np.isnan(dx) | np.isnan(dy)) | (np.abs(dx) > unknown_thr)) | (np.abs(dy) > unknown_thr))
    dx[ignore_inds] = 0
    dy[ignore_inds] = 0
    rad = np.sqrt(((dx ** 2) + (dy ** 2)))
    if np.any((rad > np.finfo(float).eps)):
        max_rad = np.max(rad)
        dx /= max_rad
        dy /= max_rad
    [h, w] = dx.shape
    rad = np.sqrt(((dx ** 2) + (dy ** 2)))
    angle = (np.arctan2((- dy), (- dx)) / np.pi)
    bin_real = (((angle + 1) / 2) * (num_bins - 1))
    bin_left = np.floor(bin_real).astype(int)
    bin_right = ((bin_left + 1) % num_bins)
    w = (bin_real - bin_left.astype(np.float32))[(..., None)]
    flow_img = (((1 - w) * color_wheel[(bin_left, :)]) + (w * color_wheel[(bin_right, :)]))
    small_ind = (rad <= 1)
    flow_img[small_ind] = (1 - (rad[(small_ind, None)] * (1 - flow_img[small_ind])))
    flow_img[np.logical_not(small_ind)] *= 0.75
    flow_img[(ignore_inds, :)] = 0
    return flow_img

Convert flow map to RGB image.

Args:
flow (ndarray): Array of optical flow.
color_wheel (ndarray or None): Color wheel used to map flow field to
RGB colorspace. Default color wheel will be used if not specified.
unknown_thr (str): Values above this threshold will be marked as
unknown and thus ignored.

Returns:
ndarray: RGB image that can be visualized.


def find(self, selector, **kwargs):
    self.debug_log(('Finding element with selector: %s' % selector))
    elements = self.find_all(selector, **kwargs)
    if len(elements):
        self.debug_log(('find (%s): Element found' % selector))
        return elements[0]
    else:
        self.debug_log(('find (%s): No element found' % selector))
        return None

Find an element with a selector

Args:
selector (str): the selector used to find the element

Kwargs:
wait_until_present (bool)
wait_until_visible (bool)
raise_exception (bool)

Returns:
None if no element was found
proxy_element is an element was found

Raises:
this function might raise an exception
depending on the raise_exception kwargs
or
the config proxy_driver:raise_exception


def multiply(x1, x2):
    if any_symbolic_tensors((x1, x2)):
        return Multiply().symbolic_call(x1, x2)
    return backend.numpy.multiply(x1, x2)

Multiply arguments element-wise.

Args:
x1: First input tensor.
x2: Second input tensor.

Returns:
Output tensor, element-wise product of `x1` and `x2`.


def add_inner_graph_id(self, inner_graph_id):
    assert isinstance(inner_graph_id, str)
    self._inner_graph_ids.append(inner_graph_id)

Add the debugger-generated ID of a graph nested within this graph.

Args:
inner_graph_id: The debugger-generated ID of the nested inner graph.


def get_service(self, uuid):

        if uuid in self.services:
            return self.services[uuid]

        if pp_hex(uuid) in self.services:
            return self.services[pp_hex(uuid)]

        return None

Lookup information about a given GATT service.

Args:
uuid (str): a string containing the hex-encoded service UUID

Returns:
None if an error occurs, otherwise a :class:`Service` object.


def _call_post_with_user_override(self, sap_user_id, url, payload):
    SAPSuccessFactorsEnterpriseCustomerConfiguration = apps.get_model('sap_success_factors', 'SAPSuccessFactorsEnterpriseCustomerConfiguration')
    (oauth_access_token, _) = SAPSuccessFactorsAPIClient.get_oauth_access_token(self.enterprise_configuration.sapsf_base_url, self.enterprise_configuration.key, self.enterprise_configuration.secret, self.enterprise_configuration.sapsf_company_id, sap_user_id, SAPSuccessFactorsEnterpriseCustomerConfiguration.USER_TYPE_USER)
    response = requests.post(url, data=payload, headers={'Authorization': 'Bearer {}'.format(oauth_access_token), 'content-type': 'application/json'})
    return (response.status_code, response.text)

Make a post request with an auth token acquired for a specific user to a SuccessFactors endpoint.

Args:
sap_user_id (str): The user to use to retrieve an auth token.
url (str): The url to post to.
payload (str): The json encoded payload to post.


def pipe(self, format=None, renderer=None, formatter=None):
    if (format is None):
        format = self._format
    data = text_type(self.source).encode(self._encoding)
    out = backend.pipe(self._engine, format, data, renderer, formatter)
    return out

Return the source piped through the Graphviz layout command.

Args:
format: The output format used for rendering (``'pdf'``, ``'png'``, etc.).
renderer: The output renderer used for rendering (``'cairo'``, ``'gd'``, ...).
formatter: The output formatter used for rendering (``'cairo'``, ``'gd'``, ...).
Returns:
Binary (encoded) stdout of the layout command.
Raises:
ValueError: If ``format``, ``renderer``, or ``formatter`` are not known.
graphviz.RequiredArgumentError: If ``formatter`` is given but ``renderer`` is None.
graphviz.ExecutableNotFound: If the Graphviz executable is not found.
subprocess.CalledProcessError: If the exit status is non-zero.


def zipf_distribution(nbr_symbols, alpha):

  tmp = np.power(np.arange(1, nbr_symbols + 1), -alpha)
  zeta = np.r_[0.0, np.cumsum(tmp)]
  return [x / zeta[-1] for x in zeta]

Helper function: Create a Zipf distribution.

Args:
nbr_symbols: number of symbols to use in the distribution.
alpha: float, Zipf's Law Distribution parameter. Default = 1.5.
Usually for modelling natural text distribution is in
the range [1.1-1.6].

Returns:
distr_map: list of float, Zipf's distribution over nbr_symbols.


def _ScanVolume(self, scan_context, scan_node, base_path_specs):

    if not scan_node or not scan_node.path_spec:
      raise errors.ScannerError('Invalid or missing scan node.')

    if scan_context.IsLockedScanNode(scan_node.path_spec):

      self._ScanEncryptedVolume(scan_context, scan_node)

      if scan_context.IsLockedScanNode(scan_node.path_spec):
        return

    if scan_node.IsVolumeSystemRoot():
      self._ScanVolumeSystemRoot(scan_context, scan_node, base_path_specs)

    elif scan_node.IsFileSystem():
      self._ScanFileSystem(scan_node, base_path_specs)

    elif scan_node.type_indicator == definitions.TYPE_INDICATOR_VSHADOW:

      path_spec = path_spec_factory.Factory.NewPathSpec(
          definitions.TYPE_INDICATOR_TSK, location='/',
          parent=scan_node.path_spec)

      base_path_specs.append(path_spec)

    else:
      for sub_scan_node in scan_node.sub_nodes:
        self._ScanVolume(scan_context, sub_scan_node, base_path_specs)

Scans a volume scan node for volume and file systems.

Args:
scan_context (SourceScannerContext): source scanner context.
scan_node (SourceScanNode): volume scan node.
base_path_specs (list[PathSpec]): file system base path specifications.

Raises:
ScannerError: if the format of or within the source
is not supported or the scan node is invalid.


def ParsePathItem(item, opts=None):
    if (item == os.path.curdir):
        return CurrentComponent()
    if (item == os.path.pardir):
        return ParentComponent()
    recursion = PATH_RECURSION_REGEX.search(item)
    if (recursion is None):
        return GlobComponent(item, opts)
    (start, end) = recursion.span()
    if (not ((start == 0) and (end == len(item)))):
        raise ValueError('malformed recursive component')
    if recursion.group('max_depth'):
        max_depth = int(recursion.group('max_depth'))
    else:
        max_depth = None
    return RecursiveComponent(max_depth=max_depth, opts=opts)

Parses string path component to an `PathComponent` instance.

Args:
item: A path component string to be parsed.
opts: A `PathOpts` object.

Returns:
`PathComponent` instance corresponding to given path fragment.

Raises:
ValueError: If the path item contains a recursive component fragment but
cannot be parsed as such.


def _CreateFolder(self, parent, name, visible=True, description=None):

    folder = ET.SubElement(parent, 'Folder')
    name_tag = ET.SubElement(folder, 'name')
    name_tag.text = name
    if description is not None:
      desc_tag = ET.SubElement(folder, 'description')
      desc_tag.text = description
    if not visible:
      visibility = ET.SubElement(folder, 'visibility')
      visibility.text = '0'
    return folder

Create a KML Folder element.

Args:
parent: The parent ElementTree.Element instance.
name: The folder name as a string.
visible: Whether the folder is initially visible or not.
description: A description string or None.

Returns:
The folder ElementTree.Element instance.


def _load_data(self, resource, default=DEFAULT_VALUE_SAFEGUARD, **kwargs):

        default_val = default if default != self.DEFAULT_VALUE_SAFEGUARD else {}
        try:
            return get_edx_api_data(
                api_config=CatalogIntegration.current(),
                resource=resource,
                api=self.client,
                **kwargs
            ) or default_val
        except (SlumberBaseException, ConnectionError, Timeout) as exc:
            LOGGER.exception(
                'Failed to load data from resource [%s] with kwargs [%s] due to: [%s]',
                resource, kwargs, str(exc)
            )
            return default_val

Load data from API client.

Arguments:
resource(string): type of resource to load
default(any): value to return if API query returned empty result. Sensible values: [], {}, None etc.

Returns:
dict: Deserialized response from Course Catalog API


def extend_webfont_settings(webfont_settings):

    if not webfont_settings.get('fontdir_path', False):
        raise IcomoonSettingsError(("Webfont settings miss the required key "
                                    "item 'fontdir_path'"))

    if not webfont_settings.get('csspart_path', False):
        webfont_settings['csspart_path'] = None

    return webfont_settings

Validate a webfont settings and optionally fill missing ``csspart_path``
option.

Args:
webfont_settings (dict): Webfont settings (an item value from
``settings.ICOMOON_WEBFONTS``).

Returns:
dict: Webfont settings


def d_hkl(self, miller_index: Vector3Like) -> float:
    gstar = self.reciprocal_lattice_crystallographic.metric_tensor
    hkl = np.array(miller_index)
    return (1 / (dot(dot(hkl, gstar), hkl.T) ** (1 / 2)))

Returns the distance between the hkl plane and the origin

Args:
miller_index ([h,k,l]): Miller index of plane

Returns:
d_hkl (float)


def list_users():
    res = 0
    user_list = []
    dowhile = True
    try:
        while (res or dowhile):
            dowhile = False
            (users, _, res) = win32net.NetUserEnum(None, 0, win32netcon.FILTER_NORMAL_ACCOUNT, res, win32netcon.MAX_PREFERRED_LENGTH)
            for user in users:
                user_list.append(user['name'])
        return user_list
    except win32net.error:
        pass

Return a list of all users on Windows

Returns:
list: A list of all users on the system

CLI Example:

.. code-block:: bash

salt '*' user.list_users


def register_controller(self, module, required=True, min_number=1):
    verify_controller_module(module)
    module_ref_name = module.__name__.split('.')[-1]
    if module_ref_name in self._controller_objects:
        raise signals.ControllerError('Controller module %s has already been registered. It cannot be registered again.' % module_ref_name)
    module_config_name = module.MOBLY_CONTROLLER_CONFIG_NAME
    if module_config_name not in self.controller_configs:
        if required:
            raise signals.ControllerError('No corresponding config found for %s' % module_config_name)
        logging.warning('No corresponding config found for optional controller %s', module_config_name)
        return None
    try:
        original_config = self.controller_configs[module_config_name]
        controller_config = copy.deepcopy(original_config)
        objects = module.create(controller_config)
    except Exception:
        logging.exception('Failed to initialize objects for controller %s, abort!', module_config_name)
        raise
    if not isinstance(objects, list):
        raise signals.ControllerError('Controller module %s did not return a list of objects, abort.' % module_ref_name)
    actual_number = len(objects)
    if actual_number < min_number:
        module.destroy(objects)
        raise signals.ControllerError('Expected to get at least %d controller objects, got %d.' % (min_number, actual_number))
    self._controller_objects[module_ref_name] = copy.copy(objects)
    logging.debug('Found %d objects for controller %s', len(objects), module_config_name)
    self._controller_modules[module_ref_name] = module
    return objects

Loads a controller module and returns its loaded devices.

This is to be used in a mobly test class.

Args:
module: A module that follows the controller module interface.
required: A bool. If True, failing to register the specified
controller module raises exceptions. If False, the objects
failed to instantiate will be skipped.
min_number: An integer that is the minimum number of controller
objects to be created. Default is one, since you should not
register a controller module without expecting at least one
object.

Returns:
A list of controller objects instantiated from controller_module, or
None if no config existed for this controller and it was not a
required controller.

Raises:
ControllerError:
* The controller module has already been registered.
* The actual number of objects instantiated is less than the
* `min_number`.
* `required` is True and no corresponding config can be found.
* Any other error occurred in the registration process.


def find_all_build_files(dir: str) -> List[Tuple[str, str]]:
    build_file_dirs = []
    for root, _, files in os.walk(dir):
        for file in files:
            if file in BUILD_FILENAMES:
                root = root.strip('./')
                build_file_dirs.append((root, file))
    return build_file_dirs

List all the BUILD files.

Returns:
The list of (directory, filename) of all BUILD files.


def __init__(self, config: PretrainedConfig, generation_config: GenerationConfig, device: torch.device, dtype: torch.dtype=torch.float16, layer_device_map: Optional[Dict[int, Union[str, torch.device, int]]]=None, initial_prompt_shapes: Optional[List[List[int]]]=None) -> None:
    self.num_key_value_heads = config.num_attention_heads if getattr(config, 'num_key_value_heads', None) is None else config.num_key_value_heads
    self.head_dim = config.head_dim if hasattr(config, 'head_dim') else config.hidden_size
    self.num_hidden_layers = config.num_hidden_layers
    num_blocks = getattr(generation_config, 'num_blocks', None)
    block_size = getattr(generation_config, 'block_size', None)
    if num_blocks is None or block_size is None:
        logger.info('Calculating optimal block size and number...')
        num_blocks, block_size = compute_optimal_blocks(device, config, generation_config, initial_prompt_shapes or [], dtype, median_prefill_length=200)
        logger.info(f'Using calculated num_blocks={num_blocks}, block_size={block_size}')
    self.block_size = block_size
    self.num_blocks = num_blocks
    self.cache_shape = (self.num_key_value_heads, num_blocks, self.block_size, self.head_dim)
    self.dtype = dtype
    self.device = device
    self.key_cache: List[torch.Tensor] = []
    self.value_cache: List[torch.Tensor] = []
    for idx in range(config.num_hidden_layers):
        layer_device = layer_device_map[idx] if layer_device_map is not None else device
        new_layer_key_cache = torch.zeros(self.cache_shape, dtype=self.dtype, device=layer_device)
        new_layer_value_cache = torch.zeros(self.cache_shape, dtype=self.dtype, device=layer_device)
        torch._dynamo.mark_static_address(new_layer_key_cache)
        torch._dynamo.mark_static_address(new_layer_value_cache)
        self.key_cache.append(new_layer_key_cache)
        self.value_cache.append(new_layer_value_cache)
    self._free_blocks = deque(range(num_blocks))
    self._block_tables: Dict[str, List[int]] = {}

Initialize a paged attention cache for efficient memory usage.

Args:
config: Model configuration
generation_config: Generation configuration containing cache parameters
device: Device for the cache tensors
dtype: Data type for the cache tensors
layer_device_map: Optional mapping of layer indices to devices
initial_prompt_shapes: Optional sample prompts to help calculate optimal cache size


def percent_point(self, y, V):

        self.check_fit()

        if self.theta < 0:
            return V

        else:
            a = np.power(y, self.theta / (-1 - self.theta))
            b = np.power(V, self.theta)
            u = np.power((a + b - 1) / b, -1 / self.theta)
            return u

Compute the inverse of conditional cumulative distribution :math:`C(u|v)^-1`

Args:
y: `np.ndarray` value of :math:`C(u|v)`.
v: `np.ndarray` given value of v.


def potentially_ragged_concat(tensors):
    if len(tensors) == 1:
        return tensors[0]
    elif isinstance(tensors[0], tf.SparseTensor):
        return tf.sparse.concat(axis=0, sp_inputs=tensors)
    elif isinstance(tensors[0], tf.RaggedTensor):
        return tf.concat(tensors, axis=0)
    non_batch_shapes = tf.stack([tf.shape(tensor)[1:] for tensor in tensors])
    constant_dims = tf.math.reduce_all(non_batch_shapes == non_batch_shapes[:1], axis=0)
    if tf.math.reduce_all(constant_dims).numpy().item():
        if _is_scalar(tensors[0]):
            return tf.stack(tensors, axis=0)
        else:
            return tf.concat(tensors, axis=0)
    constant_inner_dimensions = constant_dims.numpy().tolist()[::-1].index(False)
    if constant_inner_dimensions == 0:
        constant_inner_shape = None
    else:
        constant_inner_shape = tensors[0].shape[-constant_inner_dimensions:]
    return tf.ragged.constant([tensor.numpy() for tensor in tensors], inner_shape=constant_inner_shape).merge_dims(0, 1)

Concats `Tensor`s along their first dimension.

Args:
tensors: List of `Tensor`s.

Returns:
Concatenation of the inputs along the first dimension -- of type
`np.ndarray` if all input shapes are compatible, or `tf.RaggedTensor`
if not.


def ScanForWindowsVolume(self, source_path):

    windows_path_specs = self.GetBasePathSpecs(source_path)
    if (not windows_path_specs or
        self._source_type == definitions.SOURCE_TYPE_FILE):
      return False

    file_system_path_spec = windows_path_specs[0]
    self._file_system = resolver.Resolver.OpenFileSystem(file_system_path_spec)

    if file_system_path_spec.type_indicator == definitions.TYPE_INDICATOR_OS:
      mount_point = file_system_path_spec
    else:
      mount_point = file_system_path_spec.parent

    self._path_resolver = windows_path_resolver.WindowsPathResolver(
        self._file_system, mount_point)

    if not self._windows_directory:
      self._ScanFileSystemForWindowsDirectory(self._path_resolver)

    if not self._windows_directory:
      return False

    self._path_resolver.SetEnvironmentVariable(
        'SystemRoot', self._windows_directory)
    self._path_resolver.SetEnvironmentVariable(
        'WinDir', self._windows_directory)

    return True

Scans for a Windows volume.

Args:
source_path (str): source path.

Returns:
bool: True if a Windows volume was found.

Raises:
ScannerError: if the source path does not exists, or if the source path
is not a file or directory, or if the format of or within the source
file is not supported.


def match(self, path):
    this = self.segments
    that = path.split('/')
    current_var = None
    bindings = {}
    segment_count = self.segment_count
    j = 0
    for i in range(0, len(this)):
        if (j >= len(that)):
            break
        if (this[i].kind == _TERMINAL):
            if (this[i].literal == '*'):
                bindings[current_var] = that[j]
                j += 1
            elif (this[i].literal == '**'):
                until = (((j + len(that)) - segment_count) + 1)
                segment_count += (len(that) - segment_count)
                bindings[current_var] = '/'.join(that[j:until])
                j = until
            elif (this[i].literal != that[j]):
                raise ValidationException(("mismatched literal: '%s' != '%s'" % (this[i].literal, that[j])))
            else:
                j += 1
        elif (this[i].kind == _BINDING):
            current_var = this[i].literal
    if ((j != len(that)) or (j != segment_count)):
        raise ValidationException('match error: could not render from the path template: {}'.format(path))
    return bindings

Matches a fully qualified path template string.

Args:
path (str): A fully qualified path template string.

Returns:
dict: Var names to matched binding values.

Raises:
ValidationException: If path can't be matched to the template.


async def receive(self, timeout: float=None) -> Union[(Message, None)]:
    if timeout:
        coro = self.queue.get()
        try:
            msg = (await asyncio.wait_for(coro, timeout=timeout))
        except asyncio.TimeoutError:
            msg = None
    else:
        try:
            msg = self.queue.get_nowait()
        except asyncio.QueueEmpty:
            msg = None
    return msg

Receives a message for this behaviour.
If timeout is not None it returns the message or "None"
after timeout is done.

Args:
timeout (float): number of seconds until return

Returns:
spade.message.Message: a Message or None


def _create_regexp_filter(regex):
    compiled_regex = re.compile(regex)

    def filter_fn(value):
        if (not isinstance(value, six.string_types)):
            raise error.HParamsError(('Cannot use a regexp filter for a value of type %s. Value: %s' % (type(value), value)))
        return (re.search(compiled_regex, value) is not None)
    return filter_fn

Returns a boolean function that filters strings based on a regular exp.

Args:
regex: A string describing the regexp to use.
Returns:
A function taking a string and returns True if any of its substrings
matches regex.


def _delete_record(self, identifier=None, rtype=None, name=None, content=None):
    success_url = self.URLS['dns'].format(self.domain_id)
    record_ids = self._get_matching_dns_entry_ids(identifier, rtype, name, content)
    LOGGER.debug('Record IDs to delete: %s', record_ids)
    success = True
    for rec_id in record_ids:
        delete_response = self.session.get(self.URLS['dns_delete_entry'].format(self.domain_id, rec_id))
        self._invalidate_records_cache()
        self._log('Delete DNS entry {}'.format(rec_id), delete_response)
        success = (success and (delete_response.url == success_url))
    return success

Delete one or more DNS entries in the domain zone that match the given
criteria.

Args:
[identifier] (str): An ID to match against DNS entry easyname IDs.
[rtype] (str): A DNS rtype (e.g. A, TXT, MX, etc) to match against DNS
entry types.
[name] (str): A name to match against DNS entry names.
[content] (str): A content to match against a DNS entry contents.

Returns:
bool: True if the record(s) were deleted successfully, False
otherwise.


def DeserializeExclusiveData(self, reader):

        self.Type = TransactionType.ClaimTransaction
        if self.Version != 0:
            raise Exception('Format Exception')

        numrefs = reader.ReadVarInt()

        claims = []
        for i in range(0, numrefs):
            c = CoinReference()
            c.Deserialize(reader)
            claims.append(c)

        self.Claims = claims
        if len(self.Claims) == 0:
            raise Exception('Format Exception')

Deserialize full object.

Args:
reader (neo.IO.BinaryReader):

Raises:
Exception: If the transaction type is incorrect or if there are no claims.


def items_sort(cls, items):

        class t(tuple):

            def __cmp__(self, other):
                for a, b in six.moves.zip_longest(self, other):
                    if a != b:
                        if a is None:
                            return 1
                        if b is None:
                            return -1
                        return a - b
                return 0

            def __lt__(self, other):
                return self.__cmp__(other) < 0
            def __gt_(self, other):
                return self.__cmp__(other) > 0
            def __le__(self, other):
                return self.__cmp__(other) <= 0
            def __ge_(self, other):
                return self.__cmp__(other) >= 0
            def __eq__(self, other):
                return self.__cmp__(other) == 0
            def __ne__(self, other):
                return self.__cmp__(other) != 0

        def key_func(x):
            if x.indented:
                return t((int(x.parent_item.sort), int(x.sort)))
            return t((int(x.sort), ))

        return sorted(items, key=key_func, reverse=True)

Sort list items, taking into account parent items.

Args:
items (list[gkeepapi.node.ListItem]): Items to sort.
Returns:
list[gkeepapi.node.ListItem]: Sorted items.


async def sync_services(self):
    services = {}
    servs = (await self.list_services())
    for (i, serv) in enumerate(servs):
        info = (await self.service_info(serv))
        status = (await self.service_status(serv))
        messages = (await self.get_messages(serv))
        headline = (await self.get_headline(serv))
        services[serv] = states.ServiceState(info['short_name'], info['long_name'], info['preregistered'], i)
        services[serv].state = status['numeric_status']
        for message in messages:
            services[serv].post_message(message.level, message.message, message.count, message.created)
        if (headline is not None):
            services[serv].set_headline(headline.level, headline.message, headline.created)
    return services

Poll the current state of all services.

Returns:
dict: A dictionary mapping service name to service status


def _build_projection_expression(clean_table_keys):
    projection_expression = ''
    for key in clean_table_keys[:(- 1)]:
        projection_expression += '{},'.format(key)
    projection_expression += clean_table_keys[(- 1)]
    return projection_expression

Given cleaned up keys, this will return a projection expression for
the dynamodb lookup.

Args:
clean_table_keys (dict): keys without the data types attached

Returns:
str: A projection expression for the dynamodb lookup.


def blit(self, console: tcod.console.Console, x: float, y: float, bg_blend: int, scale_x: float, scale_y: float, angle: float) -> None:
    lib.TCOD_image_blit(self.image_c, _console(console), x, y, bg_blend, scale_x, scale_y, angle)

Blit onto a Console using scaling and rotation.

Args:
console (Console): Blit destination Console.
x (float): Console X position for the center of the Image blit.
y (float): Console Y position for the center of the Image blit.
The Image blit is centered on this position.
bg_blend (int): Background blending mode to use.
scale_x (float): Scaling along Image x axis.
Set to 1 for no scaling.  Must be over 0.
scale_y (float): Scaling along Image y axis.
Set to 1 for no scaling.  Must be over 0.
angle (float): Rotation angle in radians. (Clockwise?)


def _collect_classes(m):

    from f311 import filetypes as ft
    from f311 import explorer as ex

    def _extend(classes, newclasses):

        classes.extend([class_ for class_ in newclasses if class_ not in classes])

    file_classes = [class_ for class_ in a99.get_classes_in_module(m, ft.DataFile) if class_.flag_collect]

    _extend(_classes_txt, [class_ for class_ in file_classes if class_.flag_txt])

    _extend(_classes_bin, [class_ for class_ in file_classes if not class_.flag_txt])

    _extend(_classes_sp, [class_ for class_ in file_classes if issubclass(class_, ft.FileSpectrum)])

    _extend(_classes_file, file_classes)

    _extend(_classes_vis, a99.get_classes_in_module(m, ex.Vis))

    global _classes_file_superclass
    _classes_file_superclass = [cls.__bases__[0] for cls in _classes_file]

Adds entries to _classes_*

Args:
m: module object that must contain the following sub-modules: datatypes, vis


def as_list_data(self):
    element = ElementTree.Element(self.list_type)
    id_ = ElementTree.SubElement(element, 'id')
    id_.text = self.id
    name = ElementTree.SubElement(element, 'name')
    name.text = self.name
    return element

Return an Element to be used in a list.

Most lists want an element with tag of list_type, and
subelements of id and name.

Returns:
Element: list representation of object.


def to_dict(self, rw = False):

		return {k:v for (k,v) in self.attributes.items()
				if (v is not None and (not rw or (k in self.rw_attr_keys)))}

Returns relevant attributes as a dict.
Args:
rw 			if True only returns the read/write enabled object attributes


def ChangePassword(self, password_old, password_new):
    if (not self.ValidatePassword(password_old)):
        return False
    if isinstance(password_new, str):
        password_new = password_new.encode('utf-8')
    password_key = hashlib.sha256(password_new)
    self.SaveStoredData('PasswordHash', password_key)
    self.SaveStoredData('MasterKey', AES.new(self._master_key, AES.MODE_CBC, self._iv))
    return True

Change the password used to protect the private key.

Args:
password_old (str): the current password used to encrypt the private key.
password_new (str): the new to be used password to encrypt the private key.

Returns:
bool: whether the password has been changed


def __init__(self, endpoint_name, sagemaker_session=None):

        super(MXNetPredictor, self).__init__(endpoint_name, sagemaker_session, json_serializer, json_deserializer)

Initialize an ``MXNetPredictor``.

Args:
endpoint_name (str): The name of the endpoint to perform inference on.
sagemaker_session (sagemaker.session.Session): Session object which manages interactions with
Amazon SageMaker APIs and any other AWS services needed. If not specified, the estimator creates one
using the default AWS configuration chain.


def bbox_clip(bboxes, img_shape):
    assert ((bboxes.shape[(- 1)] % 4) == 0)
    clipped_bboxes = np.empty_like(bboxes, dtype=bboxes.dtype)
    clipped_bboxes[(..., 0::2)] = np.maximum(np.minimum(bboxes[(..., 0::2)], (img_shape[1] - 1)), 0)
    clipped_bboxes[(..., 1::2)] = np.maximum(np.minimum(bboxes[(..., 1::2)], (img_shape[0] - 1)), 0)
    return clipped_bboxes

Clip bboxes to fit the image shape.

Args:
bboxes (ndarray): Shape (..., 4*k)
img_shape (tuple): (height, width) of the image.

Returns:
ndarray: Clipped bboxes.


def get_pb_ids(self) -> List[str]:
    values = DB.get_hash_value(self._key, 'processing_block_ids')
    return ast.literal_eval(values)

Return the list of PB ids associated with the SBI.

Returns:
list, Processing block ids


def get_gruneisen_parameter(self, temperature=None, structure=None, quad=None):
    return (np.trace(self.get_tgt(temperature, structure, quad)) / 3.0)

Gets the single average gruneisen parameter from the TGT.

Args:
temperature (float): Temperature in kelvin, if not specified
will return non-cv-normalized value
structure (float): Structure to be used in directional heat
capacity determination, only necessary if temperature
is specified
quad (dict): quadrature for integration, should be
dictionary with "points" and "weights" keys defaults
to quadpy.sphere.Lebedev(19) as read from file


def items_sort(cls, items):

    class t(tuple):
        'Tuple with element-based sorting'

        def __cmp__(self, other):
            for (a, b) in six.moves.zip_longest(self, other):
                if (a != b):
                    if (a is None):
                        return 1
                    if (b is None):
                        return (- 1)
                    return (a - b)
            return 0

        def __lt__(self, other):
            return (self.__cmp__(other) < 0)

        def __gt_(self, other):
            return (self.__cmp__(other) > 0)

        def __le__(self, other):
            return (self.__cmp__(other) <= 0)

        def __ge_(self, other):
            return (self.__cmp__(other) >= 0)

        def __eq__(self, other):
            return (self.__cmp__(other) == 0)

        def __ne__(self, other):
            return (self.__cmp__(other) != 0)

    def key_func(x):
        if x.indented:
            return t((int(x.parent_item.sort), int(x.sort)))
        return t((int(x.sort),))
    return sorted(items, key=key_func, reverse=True)


def get_dependency_graph(self):
    from rez.vendor.pygraph.classes.digraph import digraph
    nodes = {}
    edges = set()
    for variant in self._resolved_packages:
        nodes[variant.name] = variant.qualified_package_name
        for request in variant.get_requires():
            if (not request.conflict):
                edges.add((variant.name, request.name))
    g = digraph()
    node_color = '
    node_fontsize = 10
    attrs = [('fontsize', node_fontsize), ('fillcolor', node_color), ('style', 'filled')]
    for (name, qname) in nodes.iteritems():
        g.add_node(name, attrs=(attrs + [('label', qname)]))
    for edge in edges:
        g.add_edge(edge)
    return g

Generate the dependency graph.

The dependency graph is a simpler subset of the resolve graph. It
contains package name nodes connected directly to their dependencies.
Weak references and conflict requests are not included in the graph.
The dependency graph does not show conflicts.

Returns:
`pygraph.digraph` object.


def list_container_services(access_token, subscription_id, resource_group):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', resource_group, '/providers/Microsoft.ContainerService/ContainerServices', '?api-version=', ACS_API])
    return do_get(endpoint, access_token)

List the container services in a resource group.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.

Returns:
HTTP response. JSON model.


def _update_workflow_definition(pb_config: dict):
    known_workflows = get_workflows()
    workflow_id = pb_config['workflow']['id']
    workflow_version = pb_config['workflow']['version']
    if ((workflow_id not in known_workflows) or (workflow_version not in known_workflows[workflow_id])):
        raise RuntimeError('Unknown workflow definition: {}:{}'.format(workflow_id, workflow_version))
    workflow = get_workflow(workflow_id, workflow_version)
    for stage in workflow['stages']:
        stage['status'] = 'none'
    pb_config['workflow_parameters'] = pb_config['workflow']['parameters']
    pb_config['workflow_id'] = pb_config['workflow']['id']
    pb_config['workflow_version'] = pb_config['workflow']['version']
    pb_config['workflow_stages'] = workflow['stages']
    pb_config.pop('workflow', None)

Update the PB configuration workflow definition.

Args:
pb_config (dict): PB configuration dictionary

Raises:
RunTimeError, if the workflow definition (id, version)
specified in the sbi_config is not known.


def add_connection(self, name, **kwargs):
    name = 'connection:{}'.format(name)
    self.add_section(name)
    for (key, value) in list(kwargs.items()):
        self.set(name, key, value)
    self.generate_tags()

Adds a connection to the configuration

This method will add a connection to the configuration.  The connection
added is only available for the lifetime of the object and is not
persisted.

Note:
If a call is made to load() or reload(), any connections added
with this method must be re-added to the config instance

Args:
name (str): The name of the connection to add to the config.  The
name provided will automatically be prepended with the string
connection:
**kwargs (dict); The set of properties used to provide the node
configuration


def _getargspec(target):
    fullargspecs = getfullargspec(target)
    defaults = fullargspecs.defaults or ()
    if fullargspecs.kwonlydefaults:
        defaults += tuple(fullargspecs.kwonlydefaults.values())
    if not defaults:
        defaults = None
    argspecs = ArgSpec(args=fullargspecs.args + fullargspecs.kwonlyargs, varargs=fullargspecs.varargs, keywords=fullargspecs.varkw, defaults=defaults)
    return argspecs

A python3 version of getargspec.

Calls `getfullargspec` and assigns args, varargs,
varkw, and defaults to a python 2/3 compatible `ArgSpec`.

The parameter name 'varkw' is changed to 'keywords' to fit the
`ArgSpec` struct.

Args:
target: the target object to inspect.

Returns:
An ArgSpec with args, varargs, keywords, and defaults parameters
from FullArgSpec.


def from_preset(preset):

        if preset == 'vesta_2019':
            cut_offs = loadfn(os.path.join(_directory, 'vesta_cutoffs.yaml'))
            return CutOffDictNN(cut_off_dict=cut_offs)
        else:
            raise ValueError("Unrecognised preset: {}".format(preset))

Initialise a CutOffDictNN according to a preset set of cut-offs.

Args:
preset (str): A preset name. The list of supported presets are:

- "vesta_2019": The distance cut-offs used by the VESTA
visualisation program.

Returns:
A CutOffDictNN using the preset cut-off dictionary.


def gradients(ys, xs, grad_ys=None):

  graph = ys[0].graph
  if not grad_ys:
    grad_ys = [Constant(y.mesh, 1.0, y.shape, y.dtype).outputs[0] for y in ys]

  downstream = set(xs)
  for op in graph.operations:
    if op.has_gradient:
      if set(op.inputs) & downstream:
        downstream |= set(op.outputs)
  tensor_to_gradient = dict(zip(ys, grad_ys))
  for op in graph.operations[::-1]:
    grad_outputs = [tensor_to_gradient.get(out) for out in op.outputs]
    if op.has_gradient and any(grad_outputs) and (set(op.inputs) & downstream):
      with tf.variable_scope(op.name + "/gradients"):
        input_grads = op.gradient(grad_outputs)
        for inp, grad in zip(op.inputs, input_grads):
          if inp in downstream and grad is not None:
            if inp in tensor_to_gradient:
              tensor_to_gradient[inp] += grad
            else:
              tensor_to_gradient[inp] = grad
  return [tensor_to_gradient.get(x, None) for x in xs]

Compute gradients in dtf.

Args:
ys: a list of Tensors
xs: a list of Tensors
grad_ys: an optional list of Tensors

Returns:
grad_xs: a list of Tensors


def _build_vocab(filename, vocab_dir, vocab_name):
    vocab_path = os.path.join(vocab_dir, vocab_name)
    if (not tf.gfile.Exists(vocab_path)):
        with tf.gfile.GFile(filename, 'r') as f:
            data = f.read().split()
        counter = collections.Counter(data)
        count_pairs = sorted(counter.items(), key=(lambda x: ((- x[1]), x[0])))
        (words, _) = list(zip(*count_pairs))
        encoder = text_encoder.TokenTextEncoder(None, vocab_list=words)
        encoder.store_to_file(vocab_path)
    else:
        encoder = text_encoder.TokenTextEncoder(vocab_path)
    return encoder

Reads a file to build a vocabulary.

Args:
filename: file to read list of words from.
vocab_dir: directory where to save the vocabulary.
vocab_name: vocab file name.

Returns:
text encoder.


def dump(self, content, filepath, indent=4):

        with open(filepath, 'w') as fp:
            pyaml.dump(content, dst=fp, indent=indent)

Dump settings content to filepath.

Args:
content (str): Settings content.
filepath (str): Settings file location.


def __init__(self, ctx):
    if ctx.options.use_fiddle_overlay:
        member_map = {'Config': overlay.add_name('Config', BuildableBuilder), 'Partial': overlay.add_name('Partial', BuildableBuilder)}
    else:
        member_map = {}
    ast = ctx.loader.import_name('fiddle')
    super().__init__(ctx, 'fiddle', member_map, ast)

Initializes the FiddleOverlay.

This function loads the AST for the fiddle module, which is used to
access type information for any members that are not explicitly provided by
the overlay. See get_attribute in attribute.py for how it's used.

Args:
ctx: An instance of context.Context.


def _FormatInode(self, event):
    inode = event.inode
    if (inode is None):
        if (hasattr(event, 'pathspec') and hasattr(event.pathspec, 'image_inode')):
            inode = event.pathspec.image_inode
    if (inode is None):
        inode = '-'
    return inode

Formats the inode.

Args:
event (EventObject): event.

Returns:
str: inode field.


def torque_on(self):

        data = []
        data.append(0x0A)
        data.append(self.servoid)
        data.append(RAM_WRITE_REQ)
        data.append(TORQUE_CONTROL_RAM)
        data.append(0x01)
        data.append(0x60)
        send_data(data)

Enable the torques of Herkulex

In this mode, position control and velocity control
will work.

Args:
none


def _std(self):
    variance = tf.cond((self._count > 1), (lambda : (self._var_sum / tf.cast((self._count - 1), tf.float32))), (lambda : (tf.ones_like(self._var_sum) * float('nan'))))
    return tf.sqrt((variance + 0.0001))

Computes the current estimate of the standard deviation.

Note that the standard deviation is not defined until at least two samples
were seen.

Returns:
Tensor of current variance.


def split_by_proportionally_distribute_labels(self, proportions={}, use_lengths=True):
    identifiers = {}
    for utterance in self.corpus.utterances.values():
        if use_lengths:
            identifiers[utterance.idx] = {l: int((d * 100)) for (l, d) in utterance.label_total_duration().items()}
        else:
            identifiers[utterance.idx] = utterance.label_count()
    splits = utils.get_identifiers_splitted_by_weights(identifiers, proportions)
    return self._subviews_from_utterance_splits(splits)

Split the corpus into subsets, so the occurrence of the labels is distributed amongst the
subsets according to the given proportions.

Args:
proportions (dict): A dictionary containing the relative size of the target subsets.
The key is an identifier for the subset.
use_lengths (bool): If True the lengths of the labels are considered for splitting proportionally,
otherwise only the number of occurrences is taken into account.

Returns:
(dict): A dictionary containing the subsets with the identifier from the input as key.


def getprop(self, prop_name):

        return self.shell(
            ['getprop', prop_name],
            timeout=DEFAULT_GETPROP_TIMEOUT_SEC).decode('utf-8').strip()

Get a property of the device.

This is a convenience wrapper for "adb shell getprop xxx".

Args:
prop_name: A string that is the name of the property to get.

Returns:
A string that is the value of the property, or None if the property
doesn't exist.


def _save_states(self, state, serialized_readers_entity):
    mr_id = state.key().id_or_name()
    fresh_state = model.MapreduceState.get_by_job_id(mr_id)
    if (not self._check_mr_state(fresh_state, mr_id)):
        return False
    if (fresh_state.active_shards != 0):
        logging.warning('Mapreduce %s already has active shards. Looks like spurious task execution.', mr_id)
        return None
    config = util.create_datastore_write_config(state.mapreduce_spec)
    db.put([state, serialized_readers_entity], config=config)
    return True

Run transaction to save state.

Args:
state: a model.MapreduceState entity.
serialized_readers_entity: a model._HugeTaskPayload entity containing
json serialized input readers.

Returns:
False if a fatal error is encountered and this task should be dropped
immediately. True if transaction is successful. None if a previous
attempt of this same transaction has already succeeded.


def as_graph(self, depth=0):
    if (depth in self._graph_cache):
        return self._graph_cache[depth]
    self._graph_cache[depth] = graph = Graph(self, depth=depth)
    return graph

Create a graph with self as node, cache it, return it.

Args:
depth (int): depth of the graph.

Returns:
Graph: an instance of Graph.


def get_special_tokens_mask(self, token_ids_0, token_ids_1=None, already_has_special_tokens=False):
    if already_has_special_tokens:
        if token_ids_1 is not None:
            raise ValueError('You should not supply a second sequence if the provided sequence of ids is already formatted with special tokens for the model.')
        return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_0]
    if token_ids_1 is not None:
        return [1] + [0] * len(token_ids_0) + [1, 1] + [0] * len(token_ids_1) + [1]
    return [1] + [0] * len(token_ids_0) + [1]

Retrieves sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `encode` method.

Args:
token_ids_0 (`List[int]`):
List of ids of the first sequence.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
already_has_special_tokens (`str`, *optional*, defaults to `False`):
Whether or not the token list is already formatted with special tokens for the model.
Returns:
`List[int]`:
The list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.


def update_video_status(edx_video_id, status):
    try:
        video = _get_video(edx_video_id)
    except Video.DoesNotExist:
        error_message = u'Video not found when trying to update video status with edx_video_id: {0}'.format(edx_video_id)
        raise ValVideoNotFoundError(error_message)
    video.status = status
    video.save()

Update status for an existing video.

Args:
edx_video_id: ID of the video
status: video status

Raises:
Raises ValVideoNotFoundError if the video cannot be retrieved.


def VisitNamedType(self, node):
    return pytd.ClassType(node.name)

Converts a named type to a class type, to be filled in later.

Args:
node: The NamedType. This type only has a name.

Returns:
A ClassType. This ClassType will (temporarily) only have a name.


def quadratic_jacobian_polynomial(nodes):
    jac_parts = _helpers.matrix_product(nodes, _QUADRATIC_JACOBIAN_HELPER)
    jac_at_nodes = np.empty((1, 6), order='F')
    jac_at_nodes[(0, 0)] = two_by_two_det(jac_parts[(:, :2)])
    jac_at_nodes[(0, 1)] = two_by_two_det(jac_parts[(:, 2:4)])
    jac_at_nodes[(0, 2)] = two_by_two_det(jac_parts[(:, 4:6)])
    jac_at_nodes[(0, 3)] = two_by_two_det(jac_parts[(:, 6:8)])
    jac_at_nodes[(0, 4)] = two_by_two_det(jac_parts[(:, 8:10)])
    jac_at_nodes[(0, 5)] = two_by_two_det(jac_parts[(:, 10:)])
    bernstein = _helpers.matrix_product(jac_at_nodes, _QUADRATIC_TO_BERNSTEIN)
    return bernstein

r"""Compute the Jacobian determinant of a quadratic surface.

.. note::

This is used **only** by :meth:`Surface._compute_valid` (which is
in turn used to compute / cache the :attr:`Surface.is_valid`
property).

Converts :math:`\det(J(s, t))` to a polynomial on the reference
triangle and represents it as a surface object.

.. note::

This assumes that ``nodes`` is ``2 x 6`` but doesn't verify this.
(However, the right multiplication by ``_QUADRATIC_JACOBIAN_HELPER``
would fail if ``nodes`` wasn't ``R x 6`` and then the ensuing
determinants would fail if there weren't 2 rows.)

Args:
nodes (numpy.ndarray): A 2 x 6 array of nodes in a surface.

Returns:
numpy.ndarray: 1 x 6 array, coefficients in Bernstein basis.


def Match(self, event):

    if not self._matcher:
      return True

    self._decision = self._matcher.Matches(event)
    return self._decision

Determines if an event matches the filter.

Args:
event (EventObject): an event.

Returns:
bool: True if the event matches the filter.


def day_of_year(self):
    if self._day_of_year is None:
        cumul_days_in_month_nonleap = tf.math.cumsum(_DAYS_IN_MONTHS_NON_LEAP, exclusive=True)
        cumul_days_in_month_leap = tf.math.cumsum(_DAYS_IN_MONTHS_LEAP, exclusive=True)
        days_before_month_non_leap = tf.gather(cumul_days_in_month_nonleap, self.month() - 1)
        days_before_month_leap = tf.gather(cumul_days_in_month_leap, self.month() - 1)
        days_before_month = tf.where(date_utils.is_leap_year(self.year()), days_before_month_leap, days_before_month_non_leap)
        self._day_of_year = days_before_month + self.day()
    return self._day_of_year

Calculates the number of days since the beginning of the year.

Returns:
Tensor of int32 type with elements in range [1, 366]. January 1st yields
"1".

#### Example

```python
dt = tff.datetime.dates_from_tuples([(2019, 1, 25), (2020, 3, 2)])
dt.day_of_year()  # [25, 62]
```


def next(self) -> 'ArrayEntry':
    try:
        (newval, naft) = self.after.pop()
    except IndexError:
        raise NonexistentInstance(self.json_pointer(), 'next of last') from None
    return ArrayEntry((self.index + 1), self.before.cons(self.value), naft, newval, self.parinst, self.schema_node, self.timestamp)

Return an instance node corresponding to the next entry.

Raises:
NonexistentInstance: If the receiver is the last entry of the parent array.


def gene_filter(self, query, mongo_query):
    LOG.debug('Adding panel and genes-related parameters to the query')
    gene_query = []
    if (query.get('hgnc_symbols') and query.get('gene_panels')):
        gene_query.append({'hgnc_symbols': {'$in': query['hgnc_symbols']}})
        gene_query.append({'panels': {'$in': query['gene_panels']}})
        mongo_query['$or'] = gene_query
    else:
        if query.get('hgnc_symbols'):
            hgnc_symbols = query['hgnc_symbols']
            mongo_query['hgnc_symbols'] = {'$in': hgnc_symbols}
            LOG.debug(('Adding hgnc_symbols: %s to query' % ', '.join(hgnc_symbols)))
        if query.get('gene_panels'):
            gene_panels = query['gene_panels']
            mongo_query['panels'] = {'$in': gene_panels}
    return gene_query

Adds gene-related filters to the query object

Args:
query(dict): a dictionary of query filters specified by the users
mongo_query(dict): the query that is going to be submitted to the database

Returns:
mongo_query(dict): returned object contains gene and panel-related filters


def Named(self, name):
    self._name = name
    return self

Adds a prefix to the subject, when it is displayed in error messages.

This is especially useful in the context of types that have no helpful
string representation (e.g., boolean). Writing
AssertThat(foo).Named('foo').IsTrue()
then results in a more reasonable error.

Args:
name: string, the name to display along with the actual value.

Returns:
self


def add_cookie_header(self, request, referrer_host=None):

        new_request = convert_http_request(request, referrer_host)
        self._cookie_jar.add_cookie_header(new_request)

        request.fields.clear()

        for name, value in new_request.header_items():
            request.fields.add(name, value)

Wrapped ``add_cookie_header``.

Args:
request: An instance of :class:`.http.request.Request`.
referrer_host (str): An hostname or IP address of the referrer
URL.


def persist_as_png(structure_dict, filepath):

    graph = _create_graph(structure_dict)
    graph.write(filepath, format='png')

Saves pipeline diagram to disk as png file.

Args:
structure_dict (dict): dict returned by
:func:`~steppy.base.Step.upstream_structure`
filepath (str): filepath to which the png with pipeline visualization should be persisted


def download(self, url_or_urls):

    with self._downloader.tqdm():
      return _map_promise(self._download, url_or_urls)

Download given url(s).

Args:
url_or_urls: url or `list`/`dict` of urls to download and extract. Each
url can be a `str` or `tfds.download.Resource`.

Returns:
downloaded_path(s): `str`, The downloaded paths matching the given input
url_or_urls.


def forward(self, hidden_state):
    num_channels = hidden_state.shape[-1]
    x = self.projection_in(hidden_state).permute(0, 3, 1, 2).contiguous()
    q, ctx, gates = torch.split(x, (num_channels, num_channels, self.focal_level + 1), 1)
    ctx_all = 0
    for level in range(self.focal_level):
        ctx = self.focal_layers[level](ctx)
        ctx_all = ctx_all + ctx * gates[:, level:level + 1]
    ctx_global = self.activation(ctx.mean(2, keepdim=True).mean(3, keepdim=True))
    ctx_all = ctx_all + ctx_global * gates[:, self.focal_level:]
    if self.normalize_modulator:
        ctx_all = ctx_all / (self.focal_level + 1)
    modulator = self.projection_context(ctx_all)
    x_out = q * modulator
    x_out = x_out.permute(0, 2, 3, 1).contiguous()
    if self.use_post_layernorm_in_modulation:
        x_out = self.layernorm(x_out)
    x_out = self.projection_out(x_out)
    x_out = self.projection_dropout(x_out)
    return x_out

Args:
hidden_state:
Input features with shape of (batch_size, height, width, num_channels)


class BayesianDetectorConfig(PretrainedConfig):

    def __init__(self, watermarking_depth: Optional[int]=None, base_rate: float=0.5, **kwargs):
        self.watermarking_depth = watermarking_depth
        self.base_rate = base_rate
        self.model_name = None
        self.watermarking_config = None
        super().__init__(**kwargs)

    def set_detector_information(self, model_name, watermarking_config):
        self.model_name = model_name
        self.watermarking_config = watermarking_config

This is the configuration class to store the configuration of a [`BayesianDetectorModel`]. It is used to
instantiate a Bayesian Detector model according to the specified arguments.

Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PretrainedConfig`] for more information.

Args:
watermarking_depth (`int`, *optional*):
The number of tournament layers.
base_rate (`float1`, *optional*, defaults to 0.5):
Prior probability P(w) that a text is watermarked.


def predict_proba(self, a, b, **kwargs):

        return self.cds_score(b, a) - self.cds_score(a, b)

Infer causal relationships between 2 variables using the CDS statistic

Args:
a (numpy.ndarray): Variable 1
b (numpy.ndarray): Variable 2

Returns:
float: Causation score (Value : 1 if a->b and -1 if b->a)


def get_parameters(params=None, path='', grad_only=True):

    global current_scope
    if params is None:
        params = OrderedDict()
    for k, v in iteritems(current_scope):
        if isinstance(v, dict):
            with parameter_scope(k):
                params = get_parameters(
                    params, '/'.join([path, k]) if path else k, grad_only=grad_only)
        else:
            assert isinstance(v, nn.Variable)
            if not grad_only or v.need_grad:
                params['/'.join([path, k]) if path else k] = v
    return params

Get parameter Variables under the current parameter scope.

Args:
params (dict): Internal use. User doesn't set it manually.
path (str): Internal use.  User doesn't set it manually.
grad_only (bool): Retrieve all parameters under the current scope if
False, while only parameters with need_grad=True are retrieved
if True.

Returns:
dict: {:obj:`str` : :obj:`~nnabla.Variable`}


def move(self, x, y):

        self._cursor = self._normalizePoint(x, y)

Move the virtual cursor.

Args:
x (int): x-coordinate to place the cursor.
y (int): y-coordinate to place the cursor.

.. seealso:: :any:`get_cursor`, :any:`print_str`, :any:`write`