def convert_response(allocate_quota_response, project_id):

    if not allocate_quota_response or not allocate_quota_response.allocateErrors:
        return _IS_OK

    theError = allocate_quota_response.allocateErrors[0]
    error_tuple = _QUOTA_ERROR_CONVERSION.get(theError.code, _IS_UNKNOWN)
    if error_tuple[1].find(u'{') == -1:
        return error_tuple

    updated_msg = error_tuple[1].format(project_id=project_id, detail=theError.description or u'')
    return error_tuple[0], updated_msg

Computes a http status code and message `AllocateQuotaResponse`

The return value a tuple (code, message) where

code: is the http status code
message: is the message to return

Args:
allocate_quota_response (:class:`endpoints_management.gen.servicecontrol_v1_messages.AllocateQuotaResponse`):
the response from calling an api

Returns:
tuple(code, message)


def insert_system(cur, system_name, encoded_data=None):

    if encoded_data is None:
        encoded_data = {}

    if 'system_name' not in encoded_data:
        encoded_data['system_name'] = system_name

    insert = "INSERT OR IGNORE INTO system(system_name) VALUES (:system_name);"
    cur.execute(insert, encoded_data)

Insert a system name into the cache.

Args:
cur (:class:`sqlite3.Cursor`):
An sqlite3 cursor. This function is meant to be run within a :obj:`with` statement.

system_name (str):
The unique name of a system

encoded_data (dict, optional):
If a dictionary is provided, it will be populated with the serialized data. This is
useful for preventing encoding the same information many times.


def _preprocess_journal_query_value(third_journal_field, old_publication_info_values):

        publication_info_keys = [
            ElasticSearchVisitor.JOURNAL_TITLE,
            ElasticSearchVisitor.JOURNAL_VOLUME,
            third_journal_field,
        ]
        values_list = [
            value.strip()
            for value
            in old_publication_info_values.split(',')
            if value
        ]

        old_publication_info = [
            {
                key: value
                for key, value
                in zip(publication_info_keys, values_list)
                if value
            }
        ]

        new_publication_info = convert_old_publication_info_to_new(old_publication_info)[0]

        return new_publication_info

Transforms the given journal query value (old publication info) to the new one.

Args:
third_journal_field (six.text_type): The final field to be used for populating the old publication info.
old_publication_info_values (six.text_type): The old publication info. It must be one of {only title, title
& volume, title & volume & artid/page_start}.

Returns:
(dict) The new publication info.


def register(self, alias, service_class, configs=None, start_service=True):
    if not inspect.isclass(service_class):
        raise Error(self._device, '"%s" is not a class!' % service_class)
    if not issubclass(service_class, base_service.BaseService):
        raise Error(self._device, 'Class %s is not a subclass of BaseService!' % service_class)
    if alias in self._service_objects:
        raise Error(self._device, 'A service is already registered with alias "%s".' % alias)
    service_obj = service_class(self._device, configs)
    service_obj.alias = alias
    if start_service:
        service_obj.start()
    self._service_objects[alias] = service_obj

Registers a service.

This will create a service instance, starts the service, and adds the
instance to the mananger.

Args:
alias: string, the alias for this instance.
service_class: class, the service class to instantiate.
configs: (optional) config object to pass to the service class's
constructor.
start_service: bool, whether to start the service instance or not.
Default is True.


def start_tpot(automated_run, session, path):

    module = functions.import_string_code_as_module(automated_run.source)
    extraction = session.query(models.Extraction).first()
    X, y = extraction.return_train_dataset()

    tpot_learner =  module.tpot_learner

    tpot_learner.fit(X, y)

    temp_filename = os.path.join(path, 'tpot-temp-export-{}'.format(os.getpid()))
    tpot_learner.export(temp_filename)

    with open(temp_filename) as f:
        base_learner_source = f.read()

    base_learner_source = constants.tpot_learner_docstring + base_learner_source

    try:
        os.remove(temp_filename)
    except OSError:
        pass

    blo = models.BaseLearnerOrigin(
        source=base_learner_source,
        name='TPOT Learner',
        meta_feature_generator='predict'
    )

    session.add(blo)
    session.commit()

Starts a TPOT automated run that exports directly to base learner setup

Args:
automated_run (xcessiv.models.AutomatedRun): Automated run object

session: Valid SQLAlchemy session

path (str, unicode): Path to project folder


def _polar(abs_, angle):
    abs_ = backend.convert_to_tensor(abs_)
    angle = backend.convert_to_tensor(angle)
    real = abs_ * backend.numpy.cos(angle)
    imaginary = abs_ * backend.numpy.sin(angle)
    result = backend.math._get_complex_tensor_from_tuple((real, imaginary))
    return result

Internal implementation of the polar function.

Args:
abs_: The magnitude (absolute value) of the complex number.
angle: The angle (in radians) of the complex number.

Returns:
A complex number (or array of complex numbers) with the same shape as
`abs_` and `angle`.


def DeregisterDecrypter(cls, decrypter):
    encryption_method = decrypter.ENCRYPTION_METHOD.lower()
    if (encryption_method not in cls._decrypters):
        raise KeyError('Decrypter for encryption method: {0:s} not set.'.format(decrypter.ENCRYPTION_METHOD))
    del cls._decrypters[encryption_method]

Deregisters a decrypter for a specific encryption method.

Args:
decrypter (type): decrypter class.

Raises:
KeyError: if the corresponding decrypter is not set.


def prefix(self, imod: YangIdentifier, mid: ModuleId) -> YangIdentifier:

        try:
            did = (imod, self.implement[imod])
        except KeyError:
            raise ModuleNotImplemented(imod) from None
        try:
            pmap = self.modules[mid].prefix_map
        except KeyError:
            raise ModuleNotRegistered(*mid) from None
        for p in pmap:
            if pmap[p] == did:
                return p
        raise ModuleNotImported(imod, mid)

Return the prefix corresponding to an implemented module.

Args:
imod: Name of an implemented module.
mid: Identifier of the context module.

Raises:
ModuleNotImplemented: If `imod` is not implemented.
ModuleNotRegistered: If `mid` is not registered in YANG library.
ModuleNotImported: If `imod` is not imported in `mid`.


def read(self, vals):

        i = 0
        count = int(vals[i])
        i += 1
        for _ in range(count):
            obj = DesignCondition()
            obj.read(vals[i:i + obj.field_count])
            self.add_design_condition(obj)
            i += obj.field_count

Read values.

Args:
vals (list): list of strings representing values


def residual_block_layer(inputs, hparams):

  kernel = (hparams.res_kernel_size, hparams.res_kernel_size)
  x = inputs
  for i in range(hparams.num_res_layers):
    with tf.variable_scope("res_conv_%d" % i):

      y = common_layers.conv_block(
          common_layers.layer_norm(x, hparams.hidden_size, name="lnorm"),
          hparams.hidden_size, [((1, 1), kernel)],
          strides=(1, 1),
          padding="SAME",
          name="residual_conv")

      y = common_layers.conv_block(
          y,
          hparams.hidden_size, [((1, 1), (1, 1))],
          strides=(1, 1),
          padding="SAME",
          name="residual_dense")
      x = common_layers.layer_postprocess(x, y, hparams)
  return x

Residual block over inputs.

Runs a residual block consisting of
conv: kernel_size x kernel_size
conv: 1x1
dropout, add and normalize according to hparams.layer_postprocess_sequence.

Args:
inputs: Tensor of shape [batch, height, width, hparams.hidden_size].
hparams: HParams.

Returns:
Tensor of shape [batch, height, width, hparams.hidden_size].


def push_image(registry, image):
    values = {'registry': registry, 'image': image['name']}
    log.info('Pushing <33>{registry}<35>/{image}'.format(**values))
    shell.run('docker push {registry}/{image}'.format(**values))

Push the given image to selected repository.

Args:
registry (str):
The name of the registry we're pushing to. This is the address of
the repository without the protocol specification (no http(s)://)
image (dict[str, Any]):
The dict containing the information about the image. This is the
same dictionary as defined in DOCKER_IMAGES variable.


def compute_video_metrics_from_predictions(predictions, decode_hparams):

  all_results = {}

  ssim_all_decodes, psnr_all_decodes = [], []
  for single_decode in predictions:
    args = get_zipped_dataset_from_predictions(single_decode)
    psnr_single, ssim_single = compute_one_decoding_video_metrics(*args)
    psnr_all_decodes.append(psnr_single)
    ssim_all_decodes.append(ssim_single)
  psnr_all_decodes = np.array(psnr_all_decodes)
  ssim_all_decodes = np.array(ssim_all_decodes)
  all_results.update({"PSNR": psnr_all_decodes, "SSIM": ssim_all_decodes})
  return compute_all_metrics_statistics(all_results)

Computes metrics from predictions.

Args:
predictions: list of list of dicts.
outer length: num_decodes, inner_length: num_samples
decode_hparams: Decode hparams. instance of HParams.
Returns:
statistics: dict of Tensors, key being the metric with each Tensor
having the shape (num_samples, num_frames).


def _name_to_tensor(self, tensor_name):
    (id1, id2) = self._tensor_name_to_ids[tensor_name]
    return self._operations[id1].outputs[id2]

The tensor with the given name.

Args:
tensor_name: a string, name of a tensor in the graph.

Returns:
a tf.Tensor or mtf.Tensor


def load(filename):

    fileObj = open(filename, 'rb')
    variable = pickle.load(fileObj)
    fileObj.close()
    return variable

Load variable from Pickle file

Args:
path (str): path of the file to load

Returns:
variable read from path


def market_info(ticker: str) -> dict:
    t_info = ticker.split()
    assets = param.load_info('assets')
    if ((t_info[(- 1)] == 'Equity') and ('=' not in t_info[0])):
        exch = t_info[(- 2)]
        for info in assets.get('Equity', [dict()]):
            if ('exch_codes' not in info):
                continue
            if (exch in info['exch_codes']):
                return info
        return dict()
    if (t_info[(- 1)] == 'Curncy'):
        for info in assets.get('Curncy', [dict()]):
            if ('tickers' not in info):
                continue
            if ((t_info[0].split('+')[0] in info['tickers']) or (t_info[0][(- 1)].isdigit() and (t_info[0][:(- 1)] in info['tickers']))):
                return info
        return dict()
    if (t_info[(- 1)] == 'Comdty'):
        for info in assets.get('Comdty', [dict()]):
            if ('tickers' not in info):
                continue
            if (t_info[0][:(- 1)] in info['tickers']):
                return info
        return dict()
    if ((t_info[(- 1)] == 'Index') or ((t_info[(- 1)] == 'Equity') and ('=' in t_info[0]))):
        if (t_info[(- 1)] == 'Equity'):
            tck = t_info[0].split('=')[0]
        else:
            tck = ' '.join(t_info[:(- 1)])
        for info in assets.get('Index', [dict()]):
            if ('tickers' not in info):
                continue
            if ((tck[:2] == 'UX') and ('UX' in info['tickers'])):
                return info
            if (tck in info['tickers']):
                if (t_info[(- 1)] == 'Equity'):
                    return info
                if (not info.get('is_fut', False)):
                    return info
            if (tck[:(- 1)].rstrip() in info['tickers']):
                if info.get('is_fut', False):
                    return info
        return dict()
    if (t_info[(- 1)] == 'Corp'):
        for info in assets.get('Corp', [dict()]):
            if ('ticker' not in info):
                continue
    return dict()

Get info for given market

Args:
ticker: Bloomberg full ticker

Returns:
dict

Examples:
>>> info = market_info('SHCOMP Index')
>>> info['exch']
'EquityChina'
>>> info = market_info('ICICIC=1 IS Equity')
>>> info['freq'], info['is_fut']
('M', True)
>>> info = market_info('INT1 Curncy')
>>> info['freq'], info['is_fut']
('M', True)
>>> info = market_info('CL1 Comdty')
>>> info['freq'], info['is_fut']
('M', True)
>>> # Wrong tickers
>>> market_info('C XX Equity')
{}
>>> market_info('XXX Comdty')
{}
>>> market_info('Bond_ISIN Corp')
{}
>>> market_info('XYZ Index')
{}
>>> market_info('XYZ Curncy')
{}


def build_tfexample_transfored_training_input_fn(schema, features, analysis_output_dir, raw_data_file_pattern, training_batch_size, num_epochs=None, randomize_input=False, min_after_dequeue=1, reader_num_threads=1, allow_smaller_final_batch=True):

    def transformed_training_input_fn():
        'Training input function that reads transformed data.'
        if isinstance(raw_data_file_pattern, six.string_types):
            filepath_list = [raw_data_file_pattern]
        else:
            filepath_list = raw_data_file_pattern
        files = []
        for path in filepath_list:
            files.extend(file_io.get_matching_files(path))
        filename_queue = tf.train.string_input_producer(files, num_epochs=num_epochs, shuffle=randomize_input)
        options = tf.python_io.TFRecordOptions(compression_type=tf.python_io.TFRecordCompressionType.GZIP)
        (ex_id, ex_str) = tf.TFRecordReader(options=options).read_up_to(filename_queue, training_batch_size)
        queue_capacity = (((reader_num_threads + 3) * training_batch_size) + min_after_dequeue)
        if randomize_input:
            (_, batch_ex_str) = tf.train.shuffle_batch(tensors=[ex_id, ex_str], batch_size=training_batch_size, capacity=queue_capacity, min_after_dequeue=min_after_dequeue, enqueue_many=True, num_threads=reader_num_threads, allow_smaller_final_batch=allow_smaller_final_batch)
        else:
            (_, batch_ex_str) = tf.train.batch(tensors=[ex_id, ex_str], batch_size=training_batch_size, capacity=queue_capacity, enqueue_many=True, num_threads=reader_num_threads, allow_smaller_final_batch=allow_smaller_final_batch)
        feature_spec = {}
        feature_info = get_transformed_feature_info(features, schema)
        for (name, info) in six.iteritems(feature_info):
            if (info['size'] is None):
                feature_spec[name] = tf.VarLenFeature(dtype=info['dtype'])
            else:
                feature_spec[name] = tf.FixedLenFeature(shape=[info['size']], dtype=info['dtype'])
        parsed_tensors = tf.parse_example(batch_ex_str, feature_spec)
        transformed_features = {}
        for (k, v) in six.iteritems(parsed_tensors):
            if (isinstance(v, tf.Tensor) and (v.get_shape().ndims == 1)):
                transformed_features[k] = tf.expand_dims(v, (- 1))
            else:
                transformed_features[k] = v
        transformed_features = image_feature_engineering(features=features, feature_tensors_dict=transformed_features)
        target_name = get_target_name(features)
        if ((not target_name) or (target_name not in transformed_features)):
            raise ValueError('Cannot find target transform in features')
        transformed_target = transformed_features.pop(target_name)
        return (transformed_features, transformed_target)
    return transformed_training_input_fn

Creates training input_fn that reads transformed tf.example files.

Args:
schema: schema list
features: features dict
analysis_output_dir: output folder from analysis
raw_data_file_pattern: file path, or list of files
training_batch_size: An int specifying the batch size to use.
num_epochs: numer of epochs to read from the files. Use None to read forever.
randomize_input: If true, the input rows are read out of order. This
randomness is limited by the min_after_dequeue value.
min_after_dequeue: Minimum number elements in the reading queue after a
dequeue, used to ensure a level of mixing of elements. Only used if
randomize_input is True.
reader_num_threads: The number of threads enqueuing data.
allow_smaller_final_batch: If false, fractional batches at the end of
training or evaluation are not used.

Returns:
An input_fn suitable for training that reads transformed data in tf record
files of tf.example.


def register_repeating_metric(self, metric_name, frequency, getter):
    l = task.LoopingCall(self._publish_repeating_metric, metric_name, getter)
    repeating_metric_handle = RepeatingMetricHandle(l, frequency)
    self._repeating_metric_handles.append(repeating_metric_handle)
    if self.running:
        repeating_metric_handle.start()
    return repeating_metric_handle

Record hits to a metric at a specified interval.

Args:
metric_name: The name of the metric to record with Carbon.
frequency: The frequency with which to poll the getter and record the value with Carbon.
getter: A function which takes no arguments and returns the value to record with Carbon.

Returns:
RepeatingMetricHandle instance. Call .stop() on it to stop recording the metric.


def _is_molecule_linear(self, mol):
    if (mol.NumAtoms() < 3):
        return True
    a1 = mol.GetAtom(1)
    a2 = mol.GetAtom(2)
    for i in range(3, (mol.NumAtoms() + 1)):
        angle = float(mol.GetAtom(i).GetAngle(a2, a1))
        if (angle < 0.0):
            angle = (- angle)
        if (angle > 90.0):
            angle = (180.0 - angle)
        if (angle > self._angle_tolerance):
            return False
    return True

Is the molecule a linear one

Args:
mol: The molecule. OpenBabel OBMol object.

Returns:
Boolean value.


def seek(self, offset=None, whence=0, position=None):
    self._preread_check()
    if offset is None and position is None:
        raise TypeError('seek(): offset argument required')
    if offset is not None and position is not None:
        raise TypeError('seek(): offset and position may not be set simultaneously.')
    if position is not None:
        offset = position
    if whence == 0:
        pass
    elif whence == 1:
        offset += self.tell()
    elif whence == 2:
        offset += self.size()
    else:
        raise errors.InvalidArgumentError(None, None, 'Invalid whence argument: {}. Valid values are 0, 1, or 2.'.format(whence))
    self._read_buf.seek(offset)

Seeks to the offset in the file.

Args:
offset: The byte count relative to the whence argument.
whence: Valid values for whence are:
0: start of the file (default)
1: relative to the current position of the file
2: relative to the end of file. `offset` is usually negative.


def Unzip(iterable):

  lefts = []
  rights = []

  for left, right in iterable:
    lefts.append(left)
    rights.append(right)

  return lefts, rights

Unzips specified iterable of pairs to pair of two iterables.

This function is an inversion of the standard `zip` function and the following
hold:

* ∀ l, r. l, r == unzip(zip(l, r))
* ∀ p. p == zip(unzip(p))

Examples:
>>> Unzip([("foo", 1), ("bar", 2), ("baz", 3)])
(["foo", "bar", "baz"], [1, 2, 3])

Args:
iterable: An iterable of pairs to unzip.

Returns:
A pair of iterables after unzipping.


def create_bmi_config_file(self, filename: str='bmi_config.txt') -> None:
    s0 = self.construct_default_initial_state()
    s0.to_csv(filename, index_label='variable')

Create a BMI config file to initialize the model.

Args:
filename: The filename with which the config file should be saved.


def set_notify_dispatch_request(self, notify_dispatch_request, *args):
    self._notify_dispatch_request = notify_dispatch_request
    self._notify_args = args

Set function to call just before requests are dispatched

Args:
notify_dispatch_request (callable): function will be called
with request as single arg just before request is dispatched


def get_queue_name(queue_name):
    if queue_name:
        return queue_name
    queue_name = os.environ.get('HTTP_X_APPENGINE_QUEUENAME', parameters.config.QUEUE_NAME)
    if ((len(queue_name) > 1) and (queue_name[0:2] == '__')):
        return parameters.config.QUEUE_NAME
    else:
        return queue_name

Determine which queue MR should run on.

How to choose the queue:
1. If user provided one, use that.
2. If we are starting a mr from taskqueue, inherit that queue.
If it's a special queue, fall back to the default queue.
3. Default queue.

If user is using any MR pipeline interface, pipeline.start takes a
"queue_name" argument. The pipeline will run on that queue and MR will
simply inherit the queue_name.

Args:
queue_name: queue_name from user. Maybe None.

Returns:
The queue name to run on.


def generate_host_passthrough(self, vcpu_num):
    cpu = ET.Element('cpu', mode='host-passthrough')
    cpu.append(self.generate_topology(vcpu_num))
    if (vcpu_num > 1):
        cpu.append(self.generate_numa(vcpu_num))
    return cpu

Generate host-passthrough XML cpu node

Args:
vcpu_num(str): number of virtual CPUs

Returns:
lxml.etree.Element: CPU XML node


def compute(self, x_arr, y_arr):

        x_arr = x_arr / np.linalg.norm(x_arr, ord=1)
        y_arr = y_arr / np.linalg.norm(y_arr, ord=1)
        mixture_arr = 0.5 * (x_arr + y_arr)
        return 0.5 * (super().compute(x_arr, mixture_arr) + super().compute(y_arr, mixture_arr))

Compute distance.

Args:
x_arr:      `np.ndarray` of vectors.
y_arr:      `np.ndarray` of vectors.

Retruns:
`np.ndarray` of distances.


def download_tile(map_layer, zoom, x, y):

    try:
        tile_url = map_layer.get_tile_url(zoom, x, y)
        tmp_file, headers = urllib.request.urlretrieve(tile_url)
        return (x, y), tmp_file
    except URLError as e:
        app.logger.info("Error downloading tile x={}, y={}, z={} for layer {}: {}".format(
            x, y, zoom, map_layer, e.reason))
        return (x, y), pkg_resources.resource_filename("geos", "static/empty_tile.png")

Download a given tile from the tile server.

Args:
map_layer (MapLayer): MapLayer object which provides the tile-url.
zoom (int): zoom level
x (int): Tile-x-coordinate
y (int): Tile-y-coordinate

Returns:
file: temporary file containing the downloaded image.


def check_coordinates(chromosome, pos, coordinates):
    chrom_match = CHR_PATTERN.match(chromosome)
    chrom = chrom_match.group(2)
    if (chrom != coordinates['chrom']):
        return False
    if ((pos >= coordinates['start']) and (pos <= coordinates['end'])):
        return True
    return False

Check if the variant is in the interval given by the coordinates

Args:
chromosome(str): Variant chromosome
pos(int): Variant position
coordinates(dict): Dictionary with the region of interest


def split_if_relative_reference(reference: message.Message) -> None:
    _validate_reference(reference)
    uri_field = reference.DESCRIPTOR.fields_by_name.get('uri')
    if not proto_utils.field_is_set(reference, uri_field):
        return
    uri = proto_utils.get_value_at_field(reference, uri_field)
    internal_match = re.fullmatch(_INTERNAL_REFERENCE_PATTERN, uri.value)
    if internal_match is not None:
        reference_id_field = get_reference_id_field_for_resource(reference, internal_match.group('resource_type'))
        reference_id = proto_utils.create_message_from_descriptor(reference_id_field.message_type)
        populate_typed_reference_id(reference_id, internal_match.group('resource_id'), internal_match.group('version'))
        proto_utils.copy_common_field(uri, reference_id, 'id')
        proto_utils.copy_common_field(uri, reference_id, 'extension')
        proto_utils.set_value_at_field(reference, reference_id_field, reference_id)
        return
    fragment_match = re.fullmatch(_FRAGMENT_REFERENCE_PATTERN, uri.value)
    if fragment_match is not None:
        fragment_field = reference.DESCRIPTOR.fields_by_name['fragment']
        fragment = proto_utils.create_message_from_descriptor(fragment_field.message_type)
        value_field = fragment.DESCRIPTOR.fields_by_name['value']
        proto_utils.set_value_at_field(fragment, value_field, uri.value[1:])
        proto_utils.copy_common_field(uri, fragment, 'id')
        proto_utils.copy_common_field(uri, fragment, 'extension')
        proto_utils.set_value_at_field(reference, fragment_field, fragment)
        return

If possible, parses a `Reference` `uri` into more structured fields.

This is only possible for two forms of reference uris:
* Relative references of the form $TYPE/$ID, e.g., "Patient/1234"
In this case, this will be parsed to a proto of the form:
{patient_id: {value: "1234"}}
* Fragments of the form "#$FRAGMENT", e.g., "#vs1".  In this case, this would
be parsed into a proto of the form:
{fragment: {value: "vs1"} }

If the reference URI matches one of these schemas, the `uri` field will be
cleared, and the appropriate structured fields set. Otherwise, the reference
will be unchanged.

Args:
reference: The FHIR reference to potentially split.

Raises:
ValueError: If the message is not a valid FHIR Reference proto.


def make_hex_texture(grid_size = 2, resolution=1):

    grid_x, grid_y = np.meshgrid(
        np.arange(grid_size),
        np.arange(grid_size)
    )
    ROOT_3_OVER_2 = np.sqrt(3) / 2
    ONE_HALF = 0.5

    grid_x = (grid_x * np.sqrt(3) + (grid_y % 2) * ROOT_3_OVER_2).flatten()
    grid_y = grid_y.flatten() * 1.5

    grid_points = grid_x.shape[0]

    x_offsets = np.interp(np.arange(4 * resolution),
        np.arange(4) * resolution, [
            ROOT_3_OVER_2,
            0.,
            -ROOT_3_OVER_2,
            -ROOT_3_OVER_2,
        ])
    y_offsets = np.interp(np.arange(4 * resolution),
        np.arange(4) * resolution, [
            -ONE_HALF,
            -1.,
            -ONE_HALF,
            ONE_HALF
        ])

    tmx = 4 * resolution
    x_t = np.tile(grid_x, (tmx, 1)) + x_offsets.reshape((tmx, 1))
    y_t = np.tile(grid_y, (tmx, 1)) + y_offsets.reshape((tmx, 1))

    x_t = np.vstack([x_t, np.tile(np.nan, (1, grid_x.size))])
    y_t = np.vstack([y_t, np.tile(np.nan, (1, grid_y.size))])

    return fit_texture((x_t.flatten('F'), y_t.flatten('F')))

Makes a texture consisting on a grid of hexagons.

Args:
grid_size (int): the number of hexagons along each dimension of the grid
resolution (int): the number of midpoints along the line of each hexagon

Returns:
A texture.


def opt(parser: Union[Parser, Sequence[Input]]) -> OptionalParser:

    if isinstance(parser, str):
        parser = lit(parser)
    return OptionalParser(parser)

Optionally match a parser.

An ``OptionalParser`` attempts to match ``parser``. If it succeeds, it
returns a list of length one with the value returned by the parser as the
only element. If it fails, it returns an empty list.

Args:
parser: Parser or literal


def add_license(self, contents):
    buf_size = len(contents)
    buf = (ctypes.c_char * (buf_size + 1))(*contents.encode())
    res = self._dll.JLINK_EMU_AddLicense(buf)
    if (res == (- 1)):
        raise errors.JLinkException('Unspecified error.')
    elif (res == (- 2)):
        raise errors.JLinkException('Failed to read/write license area.')
    elif (res == (- 3)):
        raise errors.JLinkException('J-Link out of space.')
    return (res == 0)

Adds the given ``contents`` as a new custom license to the J-Link.

Args:
self (JLink): the ``JLink`` instance
contents: the string contents of the new custom license

Returns:
``True`` if license was added, ``False`` if license already existed.

Raises:
JLinkException: if the write fails.

Note:
J-Link V9 and J-Link ULTRA/PRO V4 have 336 Bytes of memory for
licenses, while older versions of 80 bytes.


def connect_raise_node(self, node, except_guards):
    for guard in except_guards:
        if guard in self.raises:
            self.raises[guard].append(node)
        else:
            self.raises[guard] = [node]

Adds extra connection between a raise node and containing except guards.

The node is a graph node, not an ast node.

Args:
node: Node
except_guards: Tuple[ast.AST, ...], the except sections that guard node


def update(self, b):
    hv = self.hashfunc(b)
    reg_index = (hv & (self.m - 1))
    bits = (hv >> self.p)
    self.reg[reg_index] = max(self.reg[reg_index], self._get_rank(bits))

Update the HyperLogLog with a new data value in bytes.
The value will be hashed using the hash function specified by
the `hashfunc` argument in the constructor.

Args:
b: The value to be hashed using the hash function specified.

Example:
To update with a new string value (using the default SHA1 hash
function, which requires bytes as input):

.. code-block:: python

hll = HyperLogLog()
hll.update("new value".encode('utf-8'))

We can also use a different hash function, for example, `pyfarmhash`:

.. code-block:: python

import farmhash
def _hash_32(b):
return farmhash.hash32(b)
hll = HyperLogLog(hashfunc=_hash_32)
hll.update("new value")


def _check_module_is_text_embedding(module_spec):

  issues = []

  input_info_dict = module_spec.get_input_info_dict()
  if len(input_info_dict) != 1:
    issues.append("Module default signature must require only one input")
  else:
    input_info, = input_info_dict.values()
    input_shape = input_info.get_shape()
    if not (input_info.dtype == tf.string and input_shape.ndims == 1 and
            input_shape.as_list() == [None]):
      issues.append(
          "Module default signature must have only one input "
          "tf.Tensor(shape=(?,), dtype=string)"
      )

  output_info_dict = module_spec.get_output_info_dict()
  if "default" not in output_info_dict:
    issues.append("Module default signature must have a 'default' output.")
  else:
    output_info = output_info_dict["default"]
    output_shape = output_info.get_shape()
    if not (output_info.dtype == tf.float32 and output_shape.ndims == 2 and
            not output_shape.as_list()[0] and output_shape.as_list()[1]):
      issues.append(
          "Module default signature must have a 'default' output of "
          "tf.Tensor(shape=(?,K), dtype=float32)."
      )

  if issues:
    raise ValueError("Module is not a text-embedding: %r" % issues)

Raises ValueError if `module_spec` is not a text-embedding module.

Args:
module_spec: A `ModuleSpec` to test.

Raises:
ValueError: if `module_spec` default signature is not compatible with
Tensor(string, shape=(?,)) -> Tensor(float32, shape=(?,K)).


def get_block(self, parent, config='running_config'):
    try:
        parent = ('^%s$' % parent)
        return self.node.section(parent, config=config)
    except TypeError:
        return None

Scans the config and returns a block of code

Args:
parent (str): The parent string to search the config for and
return the block
config (str): A text config string to be searched. Default
is to search the running-config of the Node.

Returns:
A string object that represents the block from the config.  If
the parent string is not found, then this method will
return None.


def GetMap(self, cache_info):
    return self.GetParser().GetMap(cache_info, self.CreateMap())

Creates a Map from the cache_info data.

Args:
cache_info: file-like object containing the data to parse

Returns:
A child of Map containing the cache data.


def remove_dimensions(self, dimension_names):

        with self._lock:
            for dimension in dimension_names:
                if dimension in self._extra_dimensions:
                    del self._extra_dimensions[dimension]

Removes extra dimensions added by the add_dimensions() function.
Ignores dimension names that don't exist.

Args:
dimension_names (list): List of dimension names to remove.


def if_sqlserver_disable_constraints_triggers(session: SqlASession,
                                              tablename: str) -> None:

    with if_sqlserver_disable_constraints(session, tablename):
        with if_sqlserver_disable_triggers(session, tablename):
            yield

If we're running under SQL Server, disable triggers AND constraints for the
specified table while the resource is held.

Args:
session: SQLAlchemy :class:`Session`
tablename: table name


def record(ekey, entry, diff=False):

    taskdb = active_db()
    taskdb.record(ekey, entry, diff)

    taskdb.save()

Records the specified entry to the key-value store under the specified
entity key.

Args:
ekey (str): fqdn/uuid of the method/object to store the entry for.
entry (dict): attributes and values gleaned from the execution.
diff (bool): when True, the "c" element of `entry` will be diffed
against previous entries under the same `ekey` if their method
(attribute "m") matches.


def funds(self, term, field=None, **kwargs):

        params = kwargs
        params['q'] = term
        if field:
            params['f'] = field
        else:
            params['f'] = 'fu.org.n'
        baseuri = self._BASE_URI + 'funds'
        res = self.session.get(baseuri, params=params)
        self.handle_http_error(res)
        return res

Search for funds matching a search term.

Args:
term (str): Fund id to search on
field (str): The field to search on.
Options are title, amount, org_name and type.
kwargs (dict): additional keywords passed into
requests.session.get params keyword.


def __init__(self, Outer, Inner, *l):

        super().__init__()
        self.value = [Outer()]
        self.l = self.value[0].value
        self.Outer = Outer
        self.Inner = Inner
        self.add(l)

init

Args:
Outer (class): One of the possible outer classes.
Inner (class): One of the possible inner classes.
*l: To be processed and set to value


def set_number_of_shards(self, number_of_shards):
    for policy in self._sharding_policies:
        policy.set_number_of_shards(number_of_shards)
        policy.set_number_of_partitions(self._number_of_partitions)
    self._validate()

Sets the number of shards to use for the InfeedQueue.

Args:
number_of_shards: number of ways to shard the InfeedQueue.

Raises:
ValueError: if number_of_shards is not > 0; or the policies have
been frozen and number_of_shards was already set to something
else.


def has_shell_command(self, command):
    try:
        output = self.shell(['command', '-v', command]).decode('utf-8').strip()
        return (command in output)
    except AdbError:
        return False

Checks to see if a given check command exists on the device.

Args:
command: A string that is the name of the command to check.

Returns:
A boolean that is True if the command exists and False otherwise.


def execute(self, correlation_id, args):

        return self._intercepter.execute(_next, correlation_id, args)

Executes the command given specific arguments as an input.

Args:
correlation_id: a unique correlation/transaction id
args: command arguments

Returns: an execution result.

Raises:
MicroserviceError: when execution fails for whatever reason.


def ParseFileObject(self, parser_mediator, file_object):
    data = file_object.read(self._HEADER_READ_SIZE)
    if (not data.startswith(b'<?xml')):
        raise errors.UnableToParseFile('Not an Opera typed history file [not a XML]')
    (_, _, data) = data.partition(b'\n')
    if (not data.startswith(b'<typed_history')):
        raise errors.UnableToParseFile('Not an Opera typed history file [wrong XML root key]')
    file_object.seek(0, os.SEEK_SET)
    xml = ElementTree.parse(file_object)
    for history_item in xml.iterfind('typed_history_item'):
        event_data = OperaTypedHistoryEventData()
        event_data.entry_type = history_item.get('type', None)
        event_data.url = history_item.get('content', None)
        if (event_data.entry_type == 'selected'):
            event_data.entry_selection = 'Filled from autocomplete.'
        elif (event_data.entry_type == 'text'):
            event_data.entry_selection = 'Manually typed.'
        last_typed_time = history_item.get('last_typed', None)
        if (last_typed_time is None):
            parser_mediator.ProduceExtractionWarning('missing last typed time.')
            continue
        date_time = dfdatetime_time_elements.TimeElements()
        try:
            date_time.CopyFromStringISO8601(last_typed_time)
        except ValueError as exception:
            parser_mediator.ProduceExtractionWarning('unsupported last typed time: {0:s} with error: {1!s}.'.format(last_typed_time, exception))
            continue
        event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_LAST_VISITED)
        parser_mediator.ProduceEventWithEventData(event, event_data)

Parses an Opera typed history file-like object.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): file-like object.

Raises:
UnableToParseFile: when the file cannot be parsed.


def add(self, datum, location_ids):
    node_name = datum.node_exec_stats.node_name
    if node_name in self._node_name_to_sample:
        sample = self._node_name_to_sample[node_name]
        sample.location_id.extend(location_ids)
    else:
        sample = profile_pb2.Sample()
        sample.value.extend([0, 0, 0])
        label = sample.label.add()
        label.key = self._string_table.index_of('node_name')
        label.str = self._string_table.index_of(node_name)
        label = sample.label.add()
        label.key = self._string_table.index_of('op_type')
        label.str = self._string_table.index_of(datum.op_type)
        self._node_name_to_sample[node_name] = sample
    sample.value[0] += 1
    sample.value[1] += datum.node_exec_stats.all_end_rel_micros
    sample.value[2] += datum.node_exec_stats.op_end_rel_micros - datum.node_exec_stats.op_start_rel_micros

Adds a sample data point.

Args:
datum: `ProfileDatum` to add a sample for.
location_ids: List of numberic location ids for this
sample.


def header_string_from_file(filename='feff.inp'):

        with zopen(filename, "r") as fobject:
            f = fobject.readlines()
            feff_header_str = []
            ln = 0

            try:
                feffpmg = f[0].find("pymatgen")
            except IndexError:
                feffpmg = False

            if feffpmg:
                nsites = int(f[8].split()[2])
                for line in f:
                    ln += 1
                    if ln <= nsites + 9:
                        feff_header_str.append(line)
            else:

                end = 0
                for line in f:
                    if (line[0] == "*" or line[0] == "T") and end == 0:
                        feff_header_str.append(line.replace("\r", ""))
                    else:
                        end = 1

        return ''.join(feff_header_str)

Reads Header string from either a HEADER file or feff.inp file
Will also read a header from a non-pymatgen generated feff.inp file

Args:
filename: File name containing the Header data.

Returns:
Reads header string.


def _craft_s3_keys(self):
    now = time.gmtime()
    stub = 'templates/{stack_name}/{version}'.format(stack_name=self._config.get('environment', {}).get('stack_name', None), version=self._config.get('codeVersion'))
    stub = ((stub + '/') + str(now.tm_year))
    stub = ((stub + '/') + str(('%02d' % now.tm_mon)))
    stub = ((stub + '/') + str(('%02d' % now.tm_mday)))
    stub = ((stub + '/') + str(('%02d' % now.tm_hour)))
    stub = ((stub + ':') + str(('%02d' % now.tm_min)))
    stub = ((stub + ':') + str(('%02d' % now.tm_sec)))
    if self._yaml:
        template_key = (stub + '/stack.yaml')
    else:
        template_key = (stub + '/stack.json')
    property_key = (stub + '/stack.properties')
    return (template_key, property_key)

We are putting stuff into S3, were supplied the bucket. Here we
craft the key of the elements we are putting up there in the
internet clouds.

Args:
None

Returns:
a tuple of teplate file key and property file key


def __init__(self, cache_file_name=None, update_cache=True, req_timeout=90.0):

        self._requests = MultiRequest(max_requests=2, req_timeout=req_timeout)

        self._cache = ApiCache(cache_file_name, update_cache) if cache_file_name else None

Establishes basic HTTP params and loads a cache.

Args:
cache_file_name: String file name of cache.
update_cache: Determines whether cache should be written out back to the disk when closing it.
Default is `True`.
req_timeout: Maximum number of seconds to wait without reading a response byte before deciding an error has occurred.
Default is 90.0 seconds.


def Process(self, parser_mediator, plist_name, top_level, **kwargs):
    logger.debug('Plist {0:s} plugin used for: {1:s}'.format(self.NAME, plist_name))
    self.GetEntries(parser_mediator, top_level=top_level, **kwargs)

Overwrite the default Process function so it always triggers.

Process() checks if the current plist being processed is a match for a
plugin by comparing the PATH and KEY requirements defined by a plugin.  If
both match processing continues; else raise WrongPlistPlugin.

The purpose of the default plugin is to always trigger on any given plist
file, thus it needs to overwrite the default behavior of comparing PATH
and KEY.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
plist_name (str): name of the plist.
top_level (dict[str, object]): plist top-level key.


def get_command_from_result(script, result, debug=False):

    if not debug:
        command = "python waf --run \"" + script + " " + " ".join(
            ['--%s=%s' % (param, value) for param, value in
             result['params'].items()]) + "\""
    else:
        command = "python waf --run " + script + " --command-template=\"" +\
            "gdb --args %s " + " ".join(['--%s=%s' % (param, value) for
                                         param, value in
                                         result['params'].items()]) + "\""
    return command

Return the command that is needed to obtain a certain result.

Args:
params (dict): Dictionary containing parameter: value pairs.
debug (bool): Whether the command should include the debugging
template.


def begin_statement(self, stmt):
    self.active_stmts.add(stmt)

Marks the beginning of a statement.

Args:
stmt: Hashable, a key by which the statement can be identified in the
CFG's stmt_prev and stmt_next attributes


def _build(self, inputs, memory, treat_input_as_matrix=False):
    if treat_input_as_matrix:
        inputs = basic.BatchFlatten(preserve_dims=2)(inputs)
        inputs_reshape = basic.BatchApply(basic.Linear(self._mem_size), n_dims=2)(inputs)
    else:
        inputs = basic.BatchFlatten()(inputs)
        inputs = basic.Linear(self._mem_size)(inputs)
        inputs_reshape = tf.expand_dims(inputs, 1)
    memory_plus_input = tf.concat([memory, inputs_reshape], axis=1)
    next_memory = self._attend_over_memory(memory_plus_input)
    n = inputs_reshape.get_shape().as_list()[1]
    next_memory = next_memory[(:, :(- n), :)]
    if ((self._gate_style == 'unit') or (self._gate_style == 'memory')):
        (self._input_gate, self._forget_gate) = self._create_gates(inputs_reshape, memory)
        next_memory = (self._input_gate * tf.tanh(next_memory))
        next_memory += (self._forget_gate * memory)
    output = basic.BatchFlatten()(next_memory)
    return (output, next_memory)

Adds relational memory to the TensorFlow graph.

Args:
inputs: Tensor input.
memory: Memory output from the previous time step.
treat_input_as_matrix: Optional, whether to treat `input` as a sequence
of matrices. Defaulta to False, in which case the input is flattened
into a vector.

Returns:
output: This time step's output.
next_memory: The next version of memory to use.


def _FindLargestIdPostfixNumber(self, schedule):

    postfix_number_re = re.compile('(\d+)$')

    def ExtractPostfixNumber(entity_id):

      if entity_id is None:
        return 0
      match = postfix_number_re.search(entity_id)
      if match is not None:
        return int(match.group(1))
      else:
        return 0

    id_data_sets = {'agency_id': schedule.GetAgencyList(),
                    'stop_id': schedule.GetStopList(),
                    'route_id': schedule.GetRouteList(),
                    'trip_id': schedule.GetTripList(),
                    'service_id': schedule.GetServicePeriodList(),
                    'fare_id': schedule.GetFareAttributeList(),
                    'shape_id': schedule.GetShapeList()}

    max_postfix_number = 0
    for id_name, entity_list in id_data_sets.items():
      for entity in entity_list:
        entity_id = getattr(entity, id_name)
        postfix_number = ExtractPostfixNumber(entity_id)
        max_postfix_number = max(max_postfix_number, postfix_number)
    return max_postfix_number

Finds the largest integer used as the ending of an id in the schedule.

Args:
schedule: The schedule to check.

Returns:
The maximum integer used as an ending for an id.


def statement(self) -> Statement:
    (pref, kw) = self.keyword()
    pres = self.opt_separator()
    next = self.peek()
    if (next == ';'):
        arg = None
        sub = False
    elif (next == '{'):
        arg = None
        sub = True
    elif (not pres):
        raise UnexpectedInput(self, 'separator')
    else:
        self._arg = ''
        sub = self.argument()
        arg = self._arg
    self.offset += 1
    res = Statement(kw, arg, pref=pref)
    if sub:
        res.substatements = self.substatements()
        for sub in res.substatements:
            sub.superstmt = res
    return res

Parse YANG statement.

Raises:
EndOfInput: If past the end of input.
UnexpectedInput: If no syntactically correct statement is found.


def insert(self, point, data=None):
    assert (len(point) == self.k)
    if (self.size == 0):
        if (self.region is None):
            self.region = ([[(- math.inf), math.inf]] * self.k)
        axis = 0
        return self.new_node(point, self.region, axis, data)
    current_id = 0
    while True:
        parent_node = self.node_list[current_id]
        axis = parent_node.axis
        if (point[axis] < parent_node.point[axis]):
            (next_id, left) = (parent_node.left, True)
        else:
            (next_id, left) = (parent_node.right, False)
        if (next_id is None):
            break
        current_id = next_id
    region = parent_node.region[:]
    region[axis] = parent_node.region[axis][:]
    limit = parent_node.point[axis]
    if left:
        self.node_list[current_id] = parent_node._replace(left=self.size)
        region[axis][1] = limit
    else:
        self.node_list[current_id] = parent_node._replace(right=self.size)
        region[axis][0] = limit
    return self.new_node(point, region, ((axis + 1) % self.k), data)

Insert a new node in the tree.

Args:
point (:obj:`tuple` of float or int): Stores the position of the
node.
data (:obj, optional): The information stored by the node.

Returns:
int: The identifier of the new node.

Example:
>>> tree = Tree(4, 800)
>>> point = (3, 7)
>>> data = {'name': Fresnel, 'label': blue, 'speed': 98.2}
>>> node_id = tree.insert(point, data)


def to_json(self):
    mapper_spec = self.mapper.to_json()
    return {'name': self.name, 'mapreduce_id': self.mapreduce_id, 'mapper_spec': mapper_spec, 'params': self.params, 'hooks_class_name': self.hooks_class_name}

Serializes all data in this mapreduce spec into json form.

Returns:
data in json format.


def cast(self, value):
    if (self.type is None):
        return value
    if (self.type in (str, int, float)):
        try:
            return self.type(value)
        except Exception as e:
            raise errors.BisonError('Failed to cast {} to {}'.format(value, self.type)) from e
    elif (self.type == bool):
        return (value.lower() == 'true')
    else:
        raise errors.BisonError('Unsupported type for casting: {}'.format(self.type))

Cast a value to the type required by the option, if one is set.

This is used to cast the string values gathered from environment
variable into their required type.

Args:
value: The value to cast.

Returns:
The value casted to the expected type for the option.


def parse_op_and_node(line):
    op_type = line.strip().split(' ')[0].replace('[', '').replace(']', '')
    node_name = line.strip().split(' ')[1]
    return (op_type, node_name)

Parse a line containing an op node followed by a node name.

For example, if the line is
"  [Variable] hidden/weights",
this function will return ("Variable", "hidden/weights")

Args:
line: The line to be parsed, as a str.

Returns:
Name of the parsed op type.
Name of the parsed node.


def _ProduceSingleContent(self, mod, showprivate=False, showinh=False):

        try:
            all = mod[1].__all__
        except AttributeError:
            raise RuntimeError('Module (%s) MUST have `__all__` defined.' % mod[1].__name__)
        try:
            name = mod[1].__displayname__
        except AttributeError:
            name = mod[0]
        try:
            category = mod[1].__category__
            self.__categories.setdefault(category, 0)
            self.__categories[category] += 1
        except AttributeError:
            pass
        feats = inspect.getmembers(mod[1])
        fname = 'content/' + mod[1].__name__.replace('.', '/').replace(' ', '-')+'.rst'
        feats = [f for f in feats if f[0] in all and (showprivate or not f[0][0:1] == '_')]
        with open(fname, 'w') as fid:
            fid.write(Classifier.GetModuleText(name, mod[1].__name__, showprivate=showprivate))

            for f in feats:

                if inspect.isclass(f[1]) or inspect.isfunction(f[1]):
                    try:
                        featname = f[1].__displayname__
                    except AttributeError:
                        featname = f[1].__name__
                    try:
                        category = f[1].__category__
                        self.__categories.setdefault(category, 0)
                        self.__categories[category] += 1
                    except AttributeError:
                        pass

                    if inspect.isclass(f[1]):
                        fid.write(Classifier.GetClassText(featname, '%s.%s' % (mod[1].__name__, f[1].__name__), showprivate=showprivate, showinh=showinh))
                    elif inspect.isfunction(f[1]):
                         fid.write(Classifier.GetFunctionText(featname, '%s.%s' %  (mod[1].__name__, f[1].__name__)))

            fid.close()
        return '\n   %s' % (fname.split('/')[-1])

An internal helper to create a page for a single module. This will
automatically generate the needed RSF to document the module
and save the module to its own page in its appropriate location.

Args:
mod (module): The single module to document as its own page
showprivate (bool): A flag for whether or not to display private members

Returns:
str: The file name ready to be appended to a toctree


def _exponent_handler_factory(ion_type, exp_chars, parse_func, first_char=None):

    def transition(prev, c, ctx, trans):
        if ((c in _SIGN) and (prev in exp_chars)):
            ctx.value.append(c)
        else:
            _illegal_character(c, ctx)
        return trans
    illegal = (exp_chars + _SIGN)
    return _numeric_handler_factory(_DIGITS, transition, (lambda c, ctx: (c in exp_chars)), illegal, parse_func, illegal_at_end=illegal, ion_type=ion_type, first_char=first_char)

Generates a handler co-routine which tokenizes an numeric exponent.

Args:
ion_type (IonType): The type of the value with this exponent.
exp_chars (sequence): The set of ordinals of the legal exponent characters for this component.
parse_func (callable): Called upon ending the numeric value. Accepts the current token value and returns a
thunk that lazily parses the token.
first_char (Optional[int]): The ordinal of the character that should be appended instead of the character that
occurs first in this component. This is useful for preparing the token for parsing in the case where a
particular character is peculiar to the Ion format (e.g. 'd' to denote the exponent of a decimal value
should be replaced with 'e' for compatibility with python's Decimal type).


def read(self, n=-1):
    self._preread_check()
    if n == -1:
        length = self.size() - self.tell()
    else:
        length = n
    return self._prepare_value(self._read_buf.read(length))

Returns the contents of a file as a string.

Starts reading from current position in file.

Args:
n: Read `n` bytes if `n != -1`. If `n = -1`, reads to end of file.

Returns:
`n` bytes of the file (or whole file) in bytes mode or `n` bytes of the
string if in string (regular) mode.


def _value_loss(self, observ, reward, length):

    with tf.name_scope('value_loss'):
      value = self._network(observ, length).value
      return_ = utility.discounted_return(
          reward, length, self._config.discount)
      advantage = return_ - value
      value_loss = 0.5 * self._mask(advantage ** 2, length)
      summary = tf.summary.merge([
          tf.summary.histogram('value_loss', value_loss),
          tf.summary.scalar('avg_value_loss', tf.reduce_mean(value_loss))])
      value_loss = tf.reduce_mean(value_loss)
      return tf.check_numerics(value_loss, 'value_loss'), summary

Compute the loss function for the value baseline.

The value loss is the difference between empirical and approximated returns
over the collected episodes. Returns the loss tensor and a summary strin.

Args:
observ: Sequences of observations.
reward: Sequences of reward.
length: Batch of sequence lengths.

Returns:
Tuple of loss tensor and summary tensor.


def __init__(self, export_dir):
    self._export_dir = export_dir
    self._variables_path = path_helpers.get_variables_path(export_dir)
    self._saved_model = parse_saved_model(export_dir)

Creates a `SavedModelLoader`.

Args:
export_dir: Directory in which the SavedModel protocol buffer and
variables to be loaded are located.


def add_polyhedron(self, neighbors, center, color, opacity=1.0,
                       draw_edges=False, edges_color=[0.0, 0.0, 0.0],
                       edges_linewidth=2):

        points = vtk.vtkPoints()
        conv = vtk.vtkConvexPointSet()
        for i in range(len(neighbors)):
            x, y, z = neighbors[i].coords
            points.InsertPoint(i, x, y, z)
            conv.GetPointIds().InsertId(i, i)
        grid = vtk.vtkUnstructuredGrid()
        grid.Allocate(1, 1)
        grid.InsertNextCell(conv.GetCellType(), conv.GetPointIds())
        grid.SetPoints(points)

        dsm = vtk.vtkDataSetMapper()
        polysites = [center]
        polysites.extend(neighbors)
        self.mapper_map[dsm] = polysites
        if vtk.VTK_MAJOR_VERSION <= 5:
            dsm.SetInputConnection(grid.GetProducerPort())
        else:
            dsm.SetInputData(grid)
        ac = vtk.vtkActor()

        ac.SetMapper(dsm)
        ac.GetProperty().SetOpacity(opacity)
        if color == 'element':

            myoccu = 0.0
            for specie, occu in center.species.items():
                if occu > myoccu:
                    myspecie = specie
                    myoccu = occu
            color = [i / 255 for i in self.el_color_mapping[myspecie.symbol]]
            ac.GetProperty().SetColor(color)
        else:
            ac.GetProperty().SetColor(color)
        if draw_edges:
            ac.GetProperty().SetEdgeColor(edges_color)
            ac.GetProperty().SetLineWidth(edges_linewidth)
            ac.GetProperty().EdgeVisibilityOn()
        self.ren.AddActor(ac)

Adds a polyhedron.

Args:
neighbors: Neighbors of the polyhedron (the vertices).
center: The atom in the center of the polyhedron.
color: Color for text as RGB.
opacity: Opacity of the polyhedron
draw_edges: If set to True, the a line will be drawn at each edge
edges_color: Color of the line for the edges
edges_linewidth: Width of the line drawn for the edges


def CopyMicrosecondsToFractionOfSecond(cls, microseconds):

    if microseconds < 0 or microseconds >= definitions.MICROSECONDS_PER_SECOND:
      raise ValueError(
          'Number of microseconds value: {0:d} out of bounds.'.format(
              microseconds))

    milliseconds, _ = divmod(
        microseconds, definitions.MICROSECONDS_PER_MILLISECOND)
    return decimal.Decimal(milliseconds) / definitions.MILLISECONDS_PER_SECOND

Copies the number of microseconds to a fraction of second value.

Args:
microseconds (int): number of microseconds.

Returns:
decimal.Decimal: fraction of second, which must be a value between 0.0 and
1.0.

Raises:
ValueError: if the number of microseconds is out of bounds.


def json_using_iso8601(__obj: Dict) -> Dict:

    for key, value in __obj.items():
        with suppress(TypeError, ValueError):
            __obj[key] = parse_datetime(value)
        with suppress(TypeError, ValueError):
            __obj[key] = parse_delta(value)
    return __obj

Parse ISO-8601 values from JSON databases.

See :class:`json.JSONDecoder`

Args:
__obj: Object to decode


def save(self, resource):
    resource_type = None
    xid = None
    if isinstance(resource, dict):
        resource_type = resource.get('type')
        xid = resource.get('xid')
    else:
        resource_type = resource.type
        xid = resource.xid
    if ((resource_type is not None) and (xid is not None)):
        saved = True
        if (resource_type in self.tcex.group_types):
            try:
                self.groups_shelf[xid] = resource
            except Exception:
                saved = False
            if saved:
                try:
                    del self._groups[xid]
                except KeyError:
                    pass
        elif (resource_type in self.tcex.indicator_types_data.keys()):
            try:
                self.indicators_shelf[xid] = resource
            except Exception:
                saved = False
            if saved:
                try:
                    del self._indicators[xid]
                except KeyError:
                    pass

Save group|indicator dict or object to shelve.

Best effort to save group/indicator data to disk.  If for any reason the save fails
the data will still be accessible from list in memory.

Args:
resource (dict|obj): The Group or Indicator dict or object.


def IsAllocated(self):
    if (self._stat_object is None):
        self._stat_object = self._GetStat()
    return (self._stat_object and self._stat_object.is_allocated)

Determines if the file entry is allocated.

Returns:
bool: True if the file entry is allocated.


def allan_variance(data, dt, tmax=10):
    allanvar = []
    nmax = (len(data) if (len(data) < (tmax / dt)) else int((tmax / dt)))
    for i in range(1, (nmax + 1)):
        databis = data[(len(data) % i):]
        y = databis.reshape((len(data)
        allanvar.append((((y[1:] - y[:(- 1)]) ** 2).mean() / 2))
    return ((dt * np.arange(1, (nmax + 1))), np.array(allanvar))

Calculate Allan variance.

Args:
data (np.ndarray): Input data.
dt (float): Time between each data.
tmax (float): Maximum time.

Returns:
vk (np.ndarray): Frequency.
allanvar (np.ndarray): Allan variance.


def list_of_vars(arg_plot):
    lovs = [[[var for var in svars.split(',') if var] for svars in pvars.split('.') if svars] for pvars in arg_plot.split('-') if pvars]
    lovs = [[slov for slov in lov if slov] for lov in lovs if lov]
    return [lov for lov in lovs if lov]

Construct list of variables per plot.

Args:
arg_plot (str): string with variable names separated with
``_`` (figures), ``.`` (subplots) and ``,`` (same subplot).
Returns:
three nested lists of str

- variables on the same subplot;
- subplots on the same figure;
- figures.


def get_sso(self, role):

        uri = "{}/sso?role={}".format(self.data['uri'], role)
        return self._helper.do_get(uri)

Builds the SSO (Single Sign-On) URL parameters for the specified enclosure. This allows the user to
log in to the enclosure without providing credentials. This API is currently only supported by C7000 enclosures.

Args:
role: Role

Returns:
SSO (Single Sign-On) URL parameters.


def make_parts_for(self, field_name, field_data):
    typ = field_data.field_type
    subtyp = field_data.field_subtype
    if (typ in ('read', 'xadc')):
        writeable = False
    else:
        writeable = True
    if ((typ == 'time') or ((typ in ('param', 'read')) and (subtyp == 'time'))):
        self._make_time_parts(field_name, field_data, writeable)
    elif ((typ == 'write') and (subtyp == 'action')):
        self._make_action_part(field_name, field_data)
    elif (typ in ('param', 'read', 'write', 'xadc')):
        self._make_param_part(field_name, field_data, writeable)
    elif (typ == 'bit_out'):
        self._make_out(field_name, field_data, 'bit')
    elif (typ == 'pos_out'):
        self._make_out(field_name, field_data, 'pos')
        self._make_scale_offset(field_name)
        self._make_out_capture(field_name, field_data)
    elif (typ == 'ext_out'):
        self._make_out_capture(field_name, field_data)
    elif (typ == 'bit_mux'):
        self._make_mux(field_name, field_data, 'bit')
        self._make_mux_delay(field_name)
    elif (typ == 'pos_mux'):
        self._make_mux(field_name, field_data, 'pos')
    elif (typ == 'table'):
        self._make_table(field_name, field_data)
    else:
        raise ValueError(('Unknown type %r subtype %r' % (typ, subtyp)))

Create the relevant parts for this field

Args:
field_name (str): Short field name, e.g. VAL
field_data (FieldData): Field data object


class DacOutput(ModelOutput):
    loss: Optional[torch.FloatTensor] = None
    audio_values: Optional[torch.FloatTensor] = None
    quantized_representation: Optional[torch.FloatTensor] = None
    audio_codes: Optional[torch.LongTensor] = None
    projected_latents: Optional[torch.FloatTensor] = None

Args:
loss (`torch.Tensor`):
Loss from the encoder model, comprising the weighted combination of the commitment and codebook losses.
audio_values (`torch.Tensor` of shape `(batch_size, input_length)`):
Reconstructed audio data.
quantized_representation (`torch.Tensor` of shape `(batch_size, dimension, time_steps)`):
Quantized continuous representation of input.
audio_codes (`torch.LongTensor` of shape `(batch_size, num_codebooks, time_steps)`):
Codebook indices for each codebook (quantized discrete representation of input).
projected_latents (`torch.Tensor` of shape `(batch_size, num_codebooks * dimension, time_steps)`):
Projected latents (continuous representation of input before quantization).


def _create_forward(out_node):
    retval = out_node.body[0].body[(- 1)]
    if (len(retval.value.elts) == 1):
        retval.value = retval.value.elts[0]
    return out_node

Create a user-friendly forward function.

Ensures that a single value instead of a tuple is returned if the user asked
for the gradient with respect to only one input.

Args:
out_node: The function definition AST.

Returns:
The function definition with potentially changed return statement.


def read(self, *labels, **args):
    raise NotImplementedError

Return the PCollection as a list as well as the version number.

Args:
*labels: List of labels for PCollection instance.
**args: Dict of additional arguments. Currently only 'tail' as a boolean.
When tail is True, will wait and read new elements until the cache is
complete.

Returns:
A tuple containing an iterator for the items in the PCollection and the
version number.

It is possible that the version numbers from read() and_latest_version()
are different. This usually means that the cache's been evicted (thus
unavailable => read() returns version = -1), but it had reached version n
before eviction.


def query_file(self, file_sha, verbose=False):

        if len(file_sha) not in [64, 40]:
            print('File sha looks malformed: {:s}'.format(file_sha))
            return {'file_sha': file_sha, 'malformed': True}

        return self._query('file', file_sha, verbose)

Query the VirusTotal Service
Args:
file_sha (str): The file sha1 or sha256 hash
url (str): The domain/url to be queried (default=None)


def functions(start=None, end=None):
    (start, end) = fix_addresses(start, end)
    for func_t in idautils.Functions(start, end):
        (yield Function(func_t))

Get all functions in range.

Args:
start: Start address of the range. Defaults to IDB start.
end: End address of the range. Defaults to IDB end.

Returns:
This is a generator that iterates over all the functions in the IDB.


def reopen_encoded(fileobj, mode='r', fallback_encoding=None):
    encoding = determine_encoding(fileobj.name, fallback_encoding)
    fileobj.close()
    return open(fileobj.name, mode, encoding=encoding)

Makes sure that a file was opened with some valid encoding.

Arguments:
fileobj (file): The file-object.
mode (str, optional): The mode in which to re-open the file.
fallback_encoding (str, optional): The encoding in which to re-open
the file if it does not specify an encoding itself.

Returns:
file: The re-opened file.


def _tokenize(self, text, **kwargs):
    return self.sp_model.encode(text, out_type=str)

Args:
text: TextInput
Returns a tokenized string. The Gemma tokenizer never adds a prefix space.


def DeserializeExclusiveData(self, reader):

        self.Type = TransactionType.RegisterTransaction
        self.AssetType = reader.ReadByte()
        self.Name = reader.ReadVarString()
        self.Amount = reader.ReadFixed8()
        self.Precision = reader.ReadByte()
        self.Owner = ECDSA.Deserialize_Secp256r1(reader)

        self.Admin = reader.ReadUInt160()

Deserialize full object.

Args:
reader (neo.IO.BinaryReader):


def get_absolute_name(package, relative_name):
    path = (package.split('.') if package else [])
    name = relative_name.lstrip('.')
    ndots = (len(relative_name) - len(name))
    if (ndots > len(path)):
        return relative_name
    absolute_path = path[:((len(path) + 1) - ndots)]
    if name:
        absolute_path.append(name)
    return '.'.join(absolute_path)

Joins a package name and a relative name.

Args:
package: A dotted name, e.g. foo.bar.baz
relative_name: A dotted name with possibly some leading dots, e.g. ..x.y

Returns:
The relative name appended to the parent's package, after going up one
level for each leading dot.
e.g. foo.bar.baz + ..hello.world -> foo.hello.world
The unchanged relative_name if it does not start with a dot
or has too many leading dots.


def stop(self, timeout=5):
    for worker in self._threads:
        self._queue.put(_SHUTDOWNREQUEST)
    current = threading.currentThread()
    if ((timeout is not None) and (timeout >= 0)):
        endtime = (time.time() + timeout)
    while self._threads:
        worker = self._threads.pop()
        if ((worker is not current) and worker.isAlive()):
            try:
                if ((timeout is None) or (timeout < 0)):
                    worker.join()
                else:
                    remaining_time = (endtime - time.time())
                    if (remaining_time > 0):
                        worker.join(remaining_time)
                    if worker.isAlive():
                        c = worker.conn
                        if (c and (not c.rfile.closed)):
                            try:
                                c.socket.shutdown(socket.SHUT_RD)
                            except TypeError:
                                c.socket.shutdown()
                        worker.join()
            except (AssertionError, KeyboardInterrupt):
                pass

Terminate all worker threads.

Args:
timeout (int): time to wait for threads to stop gracefully


def decode(cls, command_str):

        name, _, arg = command_str.partition(" ")

        args = []

        if len(arg) > 0:
            if arg[0] != '{' or arg[-1] != '}':
                raise DataError("Invalid command, argument is not contained in { and }", arg=arg, cmd=name)

            arg = arg[1:-1]
            args = arg.split(",")

        proc = []

        for arg in args:
            if arg.startswith("hex:"):
                arg = unhexlify(arg[4:]).decode('utf-8')

            proc.append(arg)

        return Command(name, proc)

Decode a string encoded command back into a Command object.

Args:
command_str (str): The encoded command string output from a
previous call to encode.

Returns:
Command: The decoded Command object.


def cut_video(in_file,
              out_file,
              start=None,
              end=None,
              vcodec=None,
              acodec=None,
              log_level='info',
              print_cmd=False,
              **kwargs):

    options = {'log_level': log_level}
    if vcodec is None:
        options['vcodec'] = 'copy'
    if acodec is None:
        options['acodec'] = 'copy'
    if start:
        options['ss'] = start
    else:
        start = 0
    if end:
        options['t'] = end - start
    convert_video(in_file, out_file, print_cmd, **options)

Cut a clip from a video.

Args:
in_file (str): Input video filename.
out_file (str): Output video filename.
start (None or float): Start time (in seconds).
end (None or float): End time (in seconds).
vcodec (None or str): Output video codec, None for unchanged.
acodec (None or str): Output audio codec, None for unchanged.
log_level (str): Logging level of ffmpeg.
print_cmd (bool): Whether to print the final ffmpeg command.


def remove_collisions(self, min_dist=0.5):

        s_f_coords = self.structure.frac_coords
        f_coords = self.extrema_coords
        if len(f_coords) == 0:
            if self.extrema_type is None:
                logger.warning(
                    "Please run ChargeDensityAnalyzer.get_local_extrema first!")
                return
            new_f_coords = []
            self._update_extrema(new_f_coords, self.extrema_type)
            return new_f_coords

        dist_matrix = self.structure.lattice.get_all_distances(f_coords,
                                                               s_f_coords)
        all_dist = np.min(dist_matrix, axis=1)
        new_f_coords = []

        for i, f in enumerate(f_coords):
            if all_dist[i] > min_dist:
                new_f_coords.append(f)
        self._update_extrema(new_f_coords, self.extrema_type)

        return new_f_coords

Remove predicted sites that are too close to existing atoms in the
structure.

Args:
min_dist (float): The minimum distance (in Angstrom) that
a predicted site needs to be from existing atoms. A min_dist
with value <= 0 returns all sites without distance checking.


def _add_ttl_ns(self, line):

        lg = logging.getLogger("%s.%s" % (self.ln, inspect.stack()[0][3]))
        lg.setLevel(self.log_level)

        lg.debug("line:\n%s", line)
        line = str(line).strip()

        if line is None or line == 'none' or line == '' \
                or not line.lower().startswith('@prefix'):
            return

        line = line.replace("@prefix","",1).strip()
        if line.endswith("."):
            line = line[:-1]
        prefix = line[:line.find(":")].strip()
        uri = self.clean_iri(line[line.find(":")+1:].strip())

        lg.debug("\nprefix: %s  uri: %s", prefix, uri)
        self.bind(prefix, uri, override=False, calc=False)

takes one prefix line from the turtle file and binds the namespace
to the class

Args:
line: the turtle prefix line string


def extract_backup_bundle(self, resource, timeout=-1):

        return self._client.update(resource, uri=self.BACKUP_ARCHIVE_PATH, timeout=timeout)

Extracts the existing backup bundle on the appliance and creates all the artifacts.

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

Returns:
dict: A Deployment Group associated with the Artifact Bundle backup.


def dft_task(cls, mol, xc='b3lyp', **kwargs):
    t = NwTask.from_molecule(mol, theory='dft', **kwargs)
    t.theory_directives.update({'xc': xc, 'mult': t.spin_multiplicity})
    return t

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

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


def get_special_dtypes_update(self, model, torch_dtype: 'torch.dtype') -> Dict[str, 'torch.dtype']:
    return {name: torch_dtype for name, _ in model.named_parameters() if any((m in name for m in self.modules_to_not_convert))}

returns dtypes for modules that are not quantized - used for the computation of the device_map in case
one passes a str as a device_map. The method will use the `modules_to_not_convert` that is modified
in `_process_model_before_weight_loading`.

Args:
model (`~transformers.PreTrainedModel`):
The model to quantize
torch_dtype (`torch.dtype`):
The dtype passed in `from_pretrained` method.


def run(self, inputs=None, warmup_iterations: int=10, benchmark_iterations: int=100) -> TestResultCollection:
    inputs = inputs or self.generate_random_inputs()

    def run_model(model, **kwargs):
        return model.run(inputs, warmup_iterations, benchmark_iterations, **kwargs)
    try:
        cpu_base_result = run_model(self._ori_model, enable_gpu=False)
    except RuntimeError as err:
        logging.info('%s cannot run on CPU. Reason: %s.', self._ori_model.model_config, err)
        cpu_base_result = None
    gpu_base_result = run_model(self._ori_model, enable_gpu=True)
    trt_results = list(map(run_model, self._trt_models))
    return TestResultCollection(test_name=self._name, model_config=self.model_config, cpu_base_result=cpu_base_result, gpu_base_result=gpu_base_result, trt_results=trt_results)

Runs model inference with provided or randomly generated input tensors.

Args:
inputs: Mapping from names to input ndarrays in TF1. Or a sequence of
tensors in TF2. If `None`, ramdomly generated input tensors will be used
instead.
warmup_iterations: Number of inferences to warm up the runtime.
benchmark_iterations: Number of inferences to measure the latency.

Returns:
`TestResultCollection` summarizing latency and numerics information for
different TensorRT conversion settings.


def _set_least_batch_id(self, txn_signature):
    batch = self._batches_by_txn_id[txn_signature]
    least_index = self._index_of_batch(self._batches_by_id[self._least_batch_id_wo_results].batch)
    current_index = self._index_of_batch(batch)
    all_prior = False
    if (current_index <= least_index):
        return
    if all((all(((t.header_signature in self._txn_results) for t in b.transactions)) for b in self._batches[least_index:current_index])):
        all_prior = True
    if (not all_prior):
        return
    possible_least = self._batches[current_index].header_signature
    for b in self._batches[current_index:]:
        if (not all(((t.header_signature in self._txn_results) for t in b.transactions))):
            possible_least = b.header_signature
            break
    self._least_batch_id_wo_results = possible_least

Set the first batch id that doesn't have all results.

Args:
txn_signature (str): The txn identifier of the transaction with
results being set.


def __init__(self,
                 lang='en',
                 lower=True,
                 charset=None):

        super(SentenceCharTokenizer, self).__init__(lang, lower, charset)

Encodes text into `(samples, sentences, characters)`

Args:
lang: The spacy language to use. (Default value: 'en')
lower: Lower cases the tokens if True. (Default value: True)
charset: The character set to use. For example `charset = 'abc123'`. If None, all characters will be used.
(Default value: None)


def _FilterOutPathInfoDuplicates(path_infos):

  pi_dict = {}

  for pi in path_infos:
    path_key = (pi.path_type, pi.GetPathID())
    pi_dict.setdefault(path_key, []).append(pi)

  def _SortKey(pi):
    return (
        pi.stat_entry.st_ctime,
        pi.stat_entry.st_mtime,
        pi.stat_entry.st_atime,
        pi.stat_entry.st_ino,
    )

  for pi_values in pi_dict.values():
    if len(pi_values) > 1:
      pi_values.sort(key=_SortKey, reverse=True)

  return [v[0] for v in pi_dict.values()]

Filters out duplicates from passed PathInfo objects.

Args:
path_infos: An iterable with PathInfo objects.

Returns:
A list of PathInfo objects with duplicates removed. Duplicates are
removed following this logic: they're sorted by (ctime, mtime, atime,
inode number) in the descending order and then the first one is taken
and the others are dropped.


def dataverse_download_doi(doi, local_fname=None, file_requirements={}, clobber=False):
    metadata = dataverse_search_doi(doi)

    def requirements_match(metadata):
        for key in file_requirements.keys():
            if (metadata['dataFile'].get(key, None) != file_requirements[key]):
                return False
        return True
    for file_metadata in metadata['data']['latestVersion']['files']:
        if requirements_match(file_metadata):
            file_id = file_metadata['dataFile']['id']
            md5sum = file_metadata['dataFile']['md5']
            if (local_fname is None):
                local_fname = file_metadata['dataFile']['filename']
            if ((not clobber) and os.path.isfile(local_fname)):
                print('Checking existing file to see if MD5 sum matches ...')
                md5_existing = get_md5sum(local_fname)
                if (md5_existing == md5sum):
                    print('File exists. Not overwriting.')
                    return
            print("Downloading data to '{}' ...".format(local_fname))
            dataverse_download_id(file_id, md5sum, fname=local_fname, clobber=False)
            return
    raise DownloadError(('No file found under the given DOI matches the requirements.\nThe metadata found for this DOI was:\n' + json.dumps(file_metadata, indent=2, sort_keys=True)))

Downloads a file from the Dataverse, using a DOI and set of metadata
parameters to locate the file.

Args:
doi (str): Digital Object Identifier (DOI) containing the file.
local_fname (Optional[str]): Local filename to download the file to. If
`None`, then use the filename provided by the Dataverse. Defaults to
`None`.
file_requirements (Optional[dict]): Select the file containing the
given metadata entries. If multiple files meet these requirements,
only the first in downloaded. Defaults to `{}`, corresponding to no
requirements.

Raises:
DownloadError: Either no matching file was found under the given DOI, or
the MD5 sum of the file was not as expected.
requests.exceptions.HTTPError: The given DOI does not exist, or there
was a problem connecting to the Dataverse.


def ReadSerialized(cls, json_string):

    if json_string:
      json_dict = json.loads(json_string)
      return cls.ReadSerializedDict(json_dict)

    return None

Reads an attribute container from serialized form.

Args:
json_string (str): JSON serialized attribute container.

Returns:
AttributeContainer: attribute container or None.


def put(self, value, priority=100):

        task_name = '{}{:03d}_{}'.format(self.TASK_PREFIX, priority, self._counter)
        path = posixpath.join(self._queue_path, task_name)
        self._client.kv[path] = value

Put a task into the queue.

Args:
value (str): Task data.
priority (int): An optional priority as an integer with at most 3 digits.
Lower values signify higher priority.


def update_branch(profile, name, sha):

    ref = "heads/" + name
    data = refs.update_ref(profile, ref, sha)
    return data

Move a branch's HEAD to a new SHA.

Args:

profile
A profile generated from ``simplygithub.authentication.profile``.
Such profiles tell this module (i) the ``repo`` to connect to,
and (ii) the ``token`` to connect with.

name
The name of the branch to update.

sha
The commit SHA to point the branch's HEAD to.

Returns:
A dict with data about the branch.


def prepare_wheel_srcs(headers: list[str], srcs: list[str], dests: list[str], aot: list[str], srcs_dir: str, version: str) -> None:
    prepare_headers(headers, os.path.join(srcs_dir, 'tensorflow/include'))
    prepare_srcs(srcs, dests, srcs_dir)
    prepare_aot(aot, os.path.join(srcs_dir, 'tensorflow/xla_aot_runtime_src'))
    create_init_files(os.path.join(srcs_dir, 'tensorflow'))
    shutil.move(os.path.join(srcs_dir, 'tensorflow/tools/pip_package/MANIFEST.in'), os.path.join(srcs_dir, 'MANIFEST.in'))
    shutil.move(os.path.join(srcs_dir, 'tensorflow/tools/pip_package/THIRD_PARTY_NOTICES.txt'), os.path.join(srcs_dir, 'tensorflow/THIRD_PARTY_NOTICES.txt'))
    update_xla_tsl_imports(os.path.join(srcs_dir, 'tensorflow'))
    if dests:
        return
    if not is_windows():
        rename_libtensorflow(os.path.join(srcs_dir, 'tensorflow'), version)
    if not is_macos() and (not is_windows()):
        patch_so(srcs_dir)

Rearrange source and header files.

Args:
headers: a list of paths to header files.
srcs: a list of paths to the rest of files.
dests: a list of paths to files with srcs files destinations.
aot: a list of paths to files that should be in xla_aot directory.
srcs_dir: directory to copy files to.
version: tensorflow version.


def psnr_and_ssim(output, target):
    output = tf.cast(output, dtype=tf.int32)
    target = tf.cast(target, dtype=tf.int32)
    psnr = tf.image.psnr(output, target, max_val=255)
    ssim = tf.image.ssim(output, target, max_val=255)
    return (psnr, ssim)

Compute the PSNR and SSIM.

Args:
output: 4-D Tensor, shape=(num_frames, height, width, num_channels)
target: 4-D Tensor, shape=(num_frames, height, width, num_channels)
Returns:
psnr: 1-D Tensor, shape=(num_frames,)
ssim: 1-D Tensor, shape=(num_frames,)


def pad_mixture_dimensions(x, mixture_distribution, categorical_distribution, event_ndims):
    with tf.name_scope('pad_mix_dims'):

        def _get_ndims(d):
            if (tensorshape_util.rank(d.batch_shape) is not None):
                return tensorshape_util.rank(d.batch_shape)
            return tf.shape(input=d.batch_shape_tensor())[0]
        dist_batch_ndims = _get_ndims(mixture_distribution)
        cat_batch_ndims = _get_ndims(categorical_distribution)
        pad_ndims = tf.where(categorical_distribution.is_scalar_batch(), dist_batch_ndims, (dist_batch_ndims - cat_batch_ndims))
        s = tf.shape(input=x)
        x = tf.reshape(x, shape=tf.concat([s[:(- 1)], tf.ones([pad_ndims], dtype=tf.int32), s[(- 1):], tf.ones([event_ndims], dtype=tf.int32)], axis=0))
        return x

Pad dimensions of event tensors for mixture distributions.

See `Mixture._sample_n` and `MixtureSameFamily._sample_n` for usage examples.

Args:
x: event tensor to pad.
mixture_distribution: Base distribution of the mixture.
categorical_distribution: `Categorical` distribution that mixes the base
distribution.
event_ndims: Integer specifying the number of event dimensions in the event
tensor.

Returns:
A padded version of `x` that can broadcast with `categorical_distribution`.


def _checksum(cls, line):

        tr_table = str.maketrans({c: None for c in ascii_uppercase + "+ ."})
        no_letters = line[:68].translate(tr_table).replace("-", "1")
        return sum([int(l) for l in no_letters]) % 10

Compute the checksum of a full line

Args:
line (str): Line to compute the checksum from
Return:
int: Checksum (modulo 10)


def get_poi_types(self, **kwargs):
    params = {'cultureInfo': util.language_code(kwargs.get('lang'))}
    result = self.make_request('geo', 'get_poi_types', **params)
    values = result.get('types', [])
    return (True, [emtype.PoiType(**a) for a in values])

Obtain POI types.

Args:
lang (str): Language code (*es* or *en*).

Returns:
Status boolean and parsed response (list[PoiType]), or message string
in case of error.


def _has_strict_none_origins(self, binding):
    if not self._analyzing:
        return True
    has_any_none_origin = False
    walker = cfg_utils.walk_binding(binding, keep_binding=lambda b: self._data_is_none(b.data))
    origin = None
    while True:
        try:
            origin = walker.send(origin)
        except StopIteration:
            break
        for source_set in origin.source_sets:
            if not source_set:
                if self.ctx.program.is_reachable(src=self.frame.node, dst=origin.where):
                    return True
                has_any_none_origin = True
    return not has_any_none_origin

Whether the binding has any possible origins, with None filtering.

Determines whether the binding has any possibly visible origins at the
current node once we've filtered out false positives on None. The caller
still must call HasCombination() to find out whether these origins are
actually reachable.

Args:
binding: A cfg.Binding.

Returns:
True if there are possibly visible origins, else False.


def _SmallestColSize(self, text):

        if not text:
            return 0
        stripped = terminal.StripAnsiText(text)
        return max(len(word) for word in stripped.split())

Finds the largest indivisible word of a string.

...and thus the smallest possible column width that can contain that
word unsplit over rows.

Args:
text: A string of text potentially consisting of words.

Returns:
Integer size of the largest single word in the text.


def remote_file(self, branch='master', filename=''):
    LOG.info('Retrieving "%s" from "%s".', filename, self.git_short)
    file_contents = ''
    try:
        file_blob = self.project.files.get(file_path=filename, ref=branch)
    except gitlab.exceptions.GitlabGetError:
        file_blob = None
    LOG.debug('GitLab file response:\n%s', file_blob)
    if (not file_blob):
        msg = 'Project "{0}" is missing file "{1}" in "{2}" branch.'.format(self.git_short, filename, branch)
        LOG.warning(msg)
        raise FileNotFoundError(msg)
    else:
        file_contents = b64decode(file_blob.content).decode()
    LOG.debug('Remote file contents:\n%s', file_contents)
    return file_contents

Read the remote file on Git Server.

Args:
branch (str): Git Branch to find file.
filename (str): Name of file to retrieve relative to root of
repository.

Returns:
str: Contents of remote file.

Raises:
FileNotFoundError: Requested file missing.


def _ParseVSSProcessingOptions(self, options):
    vss_only = False
    vss_stores = None
    self._process_vss = (not getattr(options, 'no_vss', False))
    if self._process_vss:
        vss_only = getattr(options, 'vss_only', False)
        vss_stores = getattr(options, 'vss_stores', None)
    if vss_stores:
        try:
            self._ParseVolumeIdentifiersString(vss_stores, prefix='vss')
        except ValueError:
            raise errors.BadConfigOption('Unsupported VSS stores')
    self._vss_only = vss_only
    self._vss_stores = vss_stores

Parses the VSS processing options.

Args:
options (argparse.Namespace): command line arguments.

Raises:
BadConfigOption: if the options are invalid.


def AddTableColumns(self, table, columns):

    table_columns = self._table_columns.setdefault(table, [])
    for attr in columns:
      if attr not in table_columns:
        table_columns.append(attr)

Add columns to table if they are not already there.

Args:
table: table name as a string
columns: an iterable of column names


def get_timezone_olson_id():
    tzoffset = int(time.timezone / 3600)
    if tzoffset <= 0:
        gmt = f'GMT+{-tzoffset}'
    else:
        gmt = f'GMT-{tzoffset}'
    return GMT_to_olson[gmt]

Return the Olson ID of the local (non-DST) timezone.

Returns:
A string representing one of the Olson IDs of the local (non-DST)
timezone.


def _IsMetadataFile(self, file_entry):
    if ((file_entry.type_indicator == dfvfs_definitions.TYPE_INDICATOR_TSK) and (file_entry.path_spec.location in self._METADATA_FILE_LOCATIONS_TSK)):
        return True
    return False

Determines if the file entry is a metadata file.

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

Returns:
bool: True if the file entry is a metadata file.


def run(self, inputs: Dict[(str, Union[(float, Iterable)])], torch_size: Optional[int]=None) -> Union[(float, Iterable)]:
    for i in self.inputs:
        self.nodes[i]['value'] = inputs[i]
    for func_set in self.function_sets:
        for func_name in func_set:
            lambda_fn = self.nodes[func_name]['lambda_fn']
            output_node = list(self.successors(func_name))[0]
            signature = self.nodes[func_name]['func_inputs']
            input_values = [self.nodes[n]['value'] for n in signature]
            res = lambda_fn(*input_values)
            if ((torch_size is not None) and (len(signature) == 0)):
                self.nodes[output_node]['value'] = torch.tensor(([res] * torch_size), dtype=torch.double)
            else:
                self.nodes[output_node]['value'] = res
    return self.nodes[self.output_node]['value']

Executes the GrFN over a particular set of inputs and returns the
result.

Args:
inputs: Input set where keys are the names of input nodes in the
GrFN and each key points to a set of input values (or just one).

Returns:
A set of outputs from executing the GrFN, one for every set of
inputs.


def orient_directed_graph(self, data, dag, alg='HC'):
    alg_dic = {'HC': hill_climbing, 'HCr': hill_climbing_with_removal, 'tabu': tabu_search, 'EHC': exploratory_hill_climbing}
    return alg_dic[alg](data, dag, nh=self.nh, nb_runs=self.nb_runs, gpu=self.gpu, nb_jobs=self.nb_jobs, lr=self.lr, train_epochs=self.train_epochs, test_epochs=self.test_epochs, verbose=self.verbose)

Modify and improve a directed acyclic graph solution using CGNN.

Args:
data (pandas.DataFrame): Observational data on which causal
discovery has to be performed.
dag (nx.DiGraph): Graph that provides the initial solution,
on which the CGNN algorithm will be applied.
alg (str): Exploration heuristic to use, among ["HC", "HCr",
"tabu", "EHC"]
Returns:
networkx.DiGraph: Solution given by CGNN.


def prepare_minibatch(self, audio_paths, texts, overwrite=False,
                          is_bi_graphemes=False, seq_length=-1, save_feature_as_csvfile=False):

        assert len(audio_paths) == len(texts),\
            "Inputs and outputs to the network must be of the same number"

        features = [self.featurize(a, overwrite=overwrite, save_feature_as_csvfile=save_feature_as_csvfile) for a in audio_paths]
        input_lengths = [f.shape[0] for f in features]
        feature_dim = features[0].shape[1]
        mb_size = len(features)

        if seq_length == -1:
            x = np.zeros((mb_size, self.max_seq_length, feature_dim))
        else:
            x = np.zeros((mb_size, seq_length, feature_dim))
        y = np.zeros((mb_size, self.max_label_length))
        labelUtil = LabelUtil.getInstance()
        label_lengths = []
        for i in range(mb_size):
            feat = features[i]
            feat = self.normalize(feat)
            x[i, :feat.shape[0], :] = feat
            if is_bi_graphemes:
                label = generate_bi_graphemes_label(texts[i])
                label = labelUtil.convert_bi_graphemes_to_num(label)
                y[i, :len(label)] = label
            else:
                label = labelUtil.convert_word_to_num(texts[i])
                y[i, :len(texts[i])] = label
            label_lengths.append(len(label))
        return {
            'x': x,
            'y': y,
            'texts': texts,
            'input_lengths': input_lengths,
            'label_lengths': label_lengths,
        }

Featurize a minibatch of audio, zero pad them and return a dictionary
Params:
audio_paths (list(str)): List of paths to audio files
texts (list(str)): List of texts corresponding to the audio files
Returns:
dict: See below for contents


def caption_to_item(self, caption):
    captions = self.captions()
    if caption not in captions:
        raise LookupError('There is no menu item with the caption "%s"' % caption)
    return self._items[captions.index(caption)]

Get a MenuItem from the caption.

Args:
caption: (str) The caption to look up.

Returns:
(MenuItem) The first-match menu item with the caption, if any.

Raises:
LookupError: If a menu item with the caption does not exist.


def from_list(cls, vals: List[Value] = [], reverse: bool = False) -> "LinkedList":

        res = EmptyList()
        for v in (vals if reverse else vals[::-1]):
            res = cls(v, res)
        return res

Create an instance from a standard list.

Args:
vals: Python list of instance values.


def __init__(self, hash_queue, hash_analysis_queue, **kwargs):

    super(VirusTotalAnalyzer, self).__init__(
        hash_queue, hash_analysis_queue, **kwargs)
    self._api_key = None
    self._checked_for_old_python_version = False

Initializes a VirusTotal analyzer.

Args:
hash_queue (Queue.queue): queue that contains hashes to be analyzed.
hash_analysis_queue (Queue.queue): queue the analyzer will append
HashAnalysis objects to.


def digest_content(self, rule):

        data = OrderedDict()

        current_key = None

        for token in rule.content:

            if token.type == 'ident':

                name = token.value
                if name.startswith('-'):
                    name = name[1:]

                current_key = name
                data[current_key] = None

            if token.type == 'string':
                data[current_key] = token.value

        return data

Walk on rule content tokens to return a dict of properties.

This is pretty naive and will choke/fail on everything that is more
evolved than simple ``ident(string):value(string)``

Arguments:
rule (tinycss2.ast.QualifiedRule): Qualified rule object as
returned by  tinycss2.

Returns:
dict: Dictionnary of retrieved variables and properties.


def _get_anchor(module_to_name, fullname):
    if (not _anchor_re.match(fullname)):
        raise ValueError(("'%s' is not a valid anchor" % fullname))
    anchor = fullname
    for module_name in module_to_name.values():
        if fullname.startswith((module_name + '.')):
            rest = fullname[(len(module_name) + 1):]
            if (len(anchor) > len(rest)):
                anchor = rest
    return anchor

Turn a full member name into an anchor.

Args:
module_to_name: Dictionary mapping modules to short names.
fullname: Fully qualified name of symbol.

Returns:
HTML anchor string.  The longest module name prefix of fullname is
removed to make the anchor.

Raises:
ValueError: If fullname uses characters invalid in an anchor.


def benchmark_config():
    config = config_pb2.ConfigProto()
    config.graph_options.rewrite_options.dependency_optimization = rewriter_config_pb2.RewriterConfig.OFF
    return config

Returns a tf.compat.v1.ConfigProto for disabling the dependency optimizer.

Returns:
A TensorFlow ConfigProto object.


def __init__(self, resolver_context):

    super(FileSystem, self).__init__()
    self._is_cached = False
    self._is_open = False
    self._path_spec = None
    self._resolver_context = resolver_context

    if not getattr(self, 'TYPE_INDICATOR', None):
      raise ValueError('Missing type indicator.')

Initializes a file system.

Args:
resolver_context (Context): resolver context.

Raises:
ValueError: if a derived file system class does not define a type
indicator.


def get_course_enrollments(self, enterprise_customer, days):
    return CourseEnrollment.objects.filter(created__gt=(datetime.datetime.now() - datetime.timedelta(days=days))).filter(user_id__in=enterprise_customer.enterprise_customer_users.values_list('user_id', flat=True))

Get course enrollments for all the learners of given enterprise customer.

Arguments:
enterprise_customer (EnterpriseCustomer): Include Course enrollments for learners
of this enterprise customer.
days (int): Include course enrollment of this number of days.

Returns:
(list): A list of CourseEnrollment objects.


def __init__(self, project_id, instance_id, database_id, pool=None, credentials=None, max_batch_size_bytes=1048576, max_number_rows=50, max_number_cells=500):
    self._configuration = _BeamSpannerConfiguration(project=project_id, instance=instance_id, database=database_id, table=None, query_name=None, credentials=credentials, pool=pool, snapshot_read_timestamp=None, snapshot_exact_staleness=None)
    self._max_batch_size_bytes = max_batch_size_bytes
    self._max_number_rows = max_number_rows
    self._max_number_cells = max_number_cells
    self._database_id = database_id
    self._project_id = project_id
    self._instance_id = instance_id
    self._pool = pool

A PTransform to write onto Google Cloud Spanner.

Args:
project_id: Cloud spanner project id. Be sure to use the Project ID,
not the Project Number.
instance_id: Cloud spanner instance id.
database_id: Cloud spanner database id.
max_batch_size_bytes: (optional) Split the mutations into batches to
reduce the number of transaction sent to Spanner. By default it is
set to 1 MB (1048576 Bytes).
max_number_rows: (optional) Split the mutations into batches to
reduce the number of transaction sent to Spanner. By default it is
set to 50 rows per batch.
max_number_cells: (optional) Split the mutations into batches to
reduce the number of transaction sent to Spanner. By default it is
set to 500 cells per batch.


def pyxb_to_dict(rp_pyxb):

    return {
        'allowed': bool(_get_attr_or_list(rp_pyxb, 'allowed')),
        'num': _get_as_int(rp_pyxb),
        'block': _get_as_set(rp_pyxb, 'block'),
        'pref': _get_as_set(rp_pyxb, 'pref'),
    }

Convert ReplicationPolicy PyXB object to a normalized dict.

Args:
rp_pyxb: ReplicationPolicy to convert.

Returns:
dict : Replication Policy as normalized dict.

Example::

{
'allowed': True,
'num': 3,
'blockedMemberNode': {'urn:node:NODE1', 'urn:node:NODE2', 'urn:node:NODE3'},
'preferredMemberNode': {'urn:node:NODE4', 'urn:node:NODE5'},
}


def set_transaction_execution_result(self, txn_signature, is_valid, context_id, state_changes, events, data, error_message, error_data):
    raise NotImplementedError()

Set the status of an executed transaction.

Called by the executor after a transaction has been processed.

The scheduler must know when transactions have finished being
applied so that it can determine which transactions will become
eligible for processing.

Args:
txn_signature (str): The signature of the transaction, which
must match the header_signature field of the Transaction
object which was part of the added Batch.
is_valid (bool): True if transaction applied successfully or False
if the transaction failed and was not applied.
context_id (str): If status is True, contains the context_id
associated with the state changes made by the transaction.
If status is False, this should be set to None.

Raises:
ValueError: Thrown if transaction_signature does not match a
transaction.