def poll(self, batch_id, retry_seconds=None, back_off=None, timeout=None, halt_on_error=True):
    if (self.halt_on_poll_error is not None):
        halt_on_error = self.halt_on_poll_error
    if ((self._poll_interval is None) and (self._batch_data_count is not None)):
        self._poll_interval = max(math.ceil((self._batch_data_count / 300)), 5)
    elif (self._poll_interval is None):
        self._poll_interval = 15
    if (back_off is None):
        poll_interval_back_off = 2.5
    else:
        poll_interval_back_off = float(back_off)
    if (retry_seconds is None):
        poll_retry_seconds = 5
    else:
        poll_retry_seconds = int(retry_seconds)
    if (timeout is None):
        timeout = self.poll_timeout
    else:
        timeout = int(timeout)
    params = {'includeAdditional': 'true'}
    poll_count = 0
    poll_time_total = 0
    data = {}
    while True:
        poll_count += 1
        poll_time_total += self._poll_interval
        time.sleep(self._poll_interval)
        self.tcex.log.info('Batch poll time: {} seconds'.format(poll_time_total))
        try:
            r = self.tcex.session.get('/v2/batch/{}'.format(batch_id), params=params)
            if ((not r.ok) or ('application/json' not in r.headers.get('content-type', ''))):
                self.tcex.handle_error(545, [r.status_code, r.text], halt_on_error)
                return data
            data = r.json()
            if (data.get('status') != 'Success'):
                self.tcex.handle_error(545, [r.status_code, r.text], halt_on_error)
        except Exception as e:
            self.tcex.handle_error(540, [e], halt_on_error)
        if (data.get('data', {}).get('batchStatus', {}).get('status') == 'Completed'):
            modifier = (poll_time_total * 0.7)
            self._poll_interval_times = (self._poll_interval_times[(- 4):] + [modifier])
            weights = [1]
            poll_interval_time_weighted_sum = 0
            for poll_interval_time in self._poll_interval_times:
                poll_interval_time_weighted_sum += (poll_interval_time * weights[(- 1)])
                weights.append((weights[(- 1)] * 1.5))
            weights.pop()
            self._poll_interval = math.floor((poll_interval_time_weighted_sum / sum(weights)))
            if (poll_count == 1):
                self._poll_interval = (self._poll_interval * 0.85)
            self.tcex.log.debug('Batch Status: {}'.format(data))
            return data
        self._poll_interval = min((poll_retry_seconds + int((poll_count * poll_interval_back_off))), 20)
        if (poll_time_total >= timeout):
            self.tcex.handle_error(550, [timeout], True)

Poll Batch status to ThreatConnect API.

.. code-block:: javascript

{
"status": "Success",
"data": {
"batchStatus": {
"id":3505,
"status":"Completed",
"errorCount":0,
"successCount":0,
"unprocessCount":0
}
}
}

Args:
batch_id (str): The ID returned from the ThreatConnect API for the current batch job.
retry_seconds (int): The base number of seconds used for retries when job is not
completed.
back_off (float): A multiplier to use for backing off on each poll attempt when job has
not completed.
timeout (int, optional): The number of seconds before the poll should timeout.
halt_on_error (bool, default:True): If True any exception will raise an error.

Returns:
dict: The batch status returned from the ThreatConnect API.


def isprocess(pid, error=False):

    try:

        os.kill(pid, 0)
        return True
    except OSError:
        return False

Check that a process is running.

Arguments:

pid (int): Process ID to check.

Returns:

True if the process is running, else false.


def from_location(cls, location):

        if not location:
            return cls()
        try:
            if hasattr(location, 'isLocation'):

                return location

            elif hasattr(location, 'Latitude'):

                return cls(city=str(location.Name.replace(",", " ")),
                           latitude=location.Latitude,
                           longitude=location.Longitude)

            elif location.startswith('Site:'):
                loc, city, latitude, longitude, time_zone, elevation = \
                    [x.strip() for x in re.findall(r'\r*\n*([^\r\n]*)[,|;]',
                                                   location, re.DOTALL)]
            else:
                try:
                    city, latitude, longitude, time_zone, elevation = \
                        [key.split(":")[-1].strip()
                         for key in location.split(",")]
                except ValueError:

                    return cls(city=location)

            return cls(city=city, country=None, latitude=latitude,
                       longitude=longitude, time_zone=time_zone,
                       elevation=elevation)

        except Exception as e:
            raise ValueError(
                "Failed to create a Location from %s!\n%s" % (location, e))

Try to create a Ladybug location from a location string.

Args:
locationString: Location string

Usage:

l = Location.from_location(locationString)


def variable_accessed(variable):
    variables = _variables_override(variable)
    for var in variables:
        pywrap_tfe.TFE_Py_TapeVariableAccessed(var)
        pywrap_tfe.TFE_Py_VariableWatcherVariableAccessed(var)

Notifies all tapes in the stack that a variable has been accessed.

Args:
variable: variable to be watched.


def tick(self):
    self._handle_command_buffer()
    self._client.release()
    self._client.acquire()
    return self._get_full_state()

Ticks the environment once. Normally used for multi-agent environments.

Returns:
dict: A dictionary from agent name to its full state. The full state is another dictionary
from :obj:`holodeck.sensors.Sensors` enum to np.ndarray, containing the sensors information
for each sensor. The sensors always include the reward and terminal sensors.


def init_from_class_batches(self, class_batches, num_shards=None):
    shards_for_submissions = {}
    shard_idx = 0
    for (idx, (batch_id, batch_val)) in enumerate(iteritems(class_batches)):
        work_id = DEFENSE_WORK_ID_PATTERN.format(idx)
        submission_id = batch_val['submission_id']
        shard_id = None
        if num_shards:
            shard_id = shards_for_submissions.get(submission_id)
            if (shard_id is None):
                shard_id = (shard_idx % num_shards)
                shards_for_submissions[submission_id] = shard_id
                shard_idx += 1
        self.work[work_id] = {'claimed_worker_id': None, 'claimed_worker_start_time': None, 'is_completed': False, 'error': None, 'elapsed_time': None, 'submission_id': submission_id, 'shard_id': shard_id, 'output_classification_batch_id': batch_id}

Initializes work pieces from classification batches.

Args:
class_batches: dict with classification batches, could be obtained
as ClassificationBatches.data
num_shards: number of shards to split data into,
if None then no sharding is done.


def decompress_decoder(inputs,
                       hparams,
                       strides=(2, 2),
                       kernel=(3, 3),
                       name=None):

  with tf.variable_scope(name, default_name="decompress"):
    x = inputs
    x = tf.layers.dense(x, hparams.hidden_size, name=name + "_dense")
    x = residual_block_layer(x, hparams)
    for i in range(hparams.num_compress_steps
      j = hparams.num_compress_steps
      with tf.variable_scope(name + "_%d" % j):
        if hparams.do_decompress_attend:
          y = compress_self_attention_layer(
              x, hparams, name="decompress_selfatt")
          x += y
        y = tf.layers.conv2d_transpose(
            x,
            hparams.hidden_size,
            kernel,
            strides=strides,
            padding="SAME",
            activation=tf.nn.relu if i > 0 else None,
            name="decompress_conv")
        x = y
    return x

Decoder that decompresses 2-D inputs by 2**num_compress_steps.

Args:
inputs: Tensor of shape [batch, compress_height, compress_width, channels].
hparams: HParams.
strides: Tuple, strides for conv block.
kernel: Tuple, kernel window size for conv block.
name: string, variable scope.

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


def __init__(self, *args, **kwargs):

        super(InvocationTransaction, self).__init__(*args, **kwargs)
        self.Gas = Fixed8(0)
        self.Type = TransactionType.InvocationTransaction

Create an instance.

Args:
*args:
**kwargs:


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

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

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


def request_openbus(self, service, endpoint, **kwargs):
    if (service == 'bus'):
        endpoints = ENDPOINTS_BUS
    elif (service == 'geo'):
        endpoints = ENDPOINTS_GEO
    else:
        return None
    if (endpoint not in endpoints):
        return None
    url = (URL_OPENBUS + endpoints[endpoint])
    kwargs['idClient'] = self._emt_id
    kwargs['passKey'] = self._emt_pass
    return requests.post(url, data=kwargs, verify=True).json()

Make a request to the given endpoint of the ``openbus`` server.

This returns the plain JSON (dict) response which can then be parsed
using one of the implemented types.

Args:
service (str): Service to fetch ('bus' or 'geo').
endpoint (str): Endpoint to send the request to.
This string corresponds to the key in the ``ENDPOINTS`` dict.
**kwargs: Request arguments.

Returns:
Obtained response (dict) or None if the endpoint was not found.


def __init__(self, options):

        capacity = options[u"capacity"] if u"capacity" in options else 200
        self._cache = pylru.lrucache(capacity)

Initializes an LruBackend.

Args:
options: a dictionary that contains configuration options.


def build_grab_exception(ex, curl):

    if ex.args[0] == 23:
        if getattr(curl, 'grab_callback_interrupted', None) is True:

            return None
        else:
            return error.GrabNetworkError(ex.args[1], ex)
    else:
        if ex.args[0] == 28:
            return error.GrabTimeoutError(ex.args[1], ex)
        elif ex.args[0] == 7:
            return error.GrabConnectionError(ex.args[1], ex)
        elif ex.args[0] == 67:
            return error.GrabAuthError(ex.args[1], ex)
        elif ex.args[0] == 47:
            return error.GrabTooManyRedirectsError(ex.args[1], ex)
        elif ex.args[0] == 6:
            return error.GrabCouldNotResolveHostError(ex.args[1], ex)
        elif ex.args[0] == 3:
            return error.GrabInvalidUrl(ex.args[1], ex)
        else:
            return error.GrabNetworkError(ex.args[1], ex)

Build Grab exception from the pycurl exception

Args:
ex - the original pycurl exception
curl - the Curl instance raised the exception


def __init__(self, config_dict=None):

        self.config_dict = deepcopy(config_dict)
        self.plugins = Config.load_installed_plugins()
        self.analysis_groups = []

        if not config_dict:
            return

        analysis = config_dict.get('analysis', {})

        if isinstance(analysis, dict):
            for group_key, group_def in analysis.items():
                try:
                    self.analysis_groups.append(
                        self.inflate_analysis_group(group_key, group_def))
                except ValueError as e:
                    logger.error(
                        'Error while inflating "%s" analysis group. '
                        'The group will not be added to the list. '
                        'Exception: %s.', group_key, e)
        else:
            raise ValueError('%s type is not supported for "analysis" key, '
                             'use dict only' % type(analysis))

Initialization method.

Args:
config_dict (dict): the configuration as a dictionary.


def update(self, session, arrays=None, frame=None):

    new_config = self._get_config()

    if self._enough_time_has_passed(self.previous_config['FPS']):
      self.visualizer.update(new_config)
      self.last_update_time = time.time()
      final_image = self._update_frame(session, arrays, frame, new_config)
      self._update_recording(final_image, new_config)

Creates a frame and writes it to disk.

Args:
arrays: a list of np arrays. Use the "custom" option in the client.
frame: a 2D np array. This way the plugin can be used for video of any
kind, not just the visualization that comes with the plugin.

frame can also be a function, which only is evaluated when the
"frame" option is selected by the client.


def is_valid(self, value):
    if (not self.is_array):
        return self._valid(value)
    if isinstance(value, (list, set, tuple)):
        return all([self._valid(item) for item in value])
    return self._valid(value)

Validate value before actual instance setting based on type.

Args:
value (object): The value object for validation.

Returns:
True if value validation succeeds else False.


def find_from(path):

        realpath = os.path.realpath(path)
        config_path = os.path.join(realpath, '.ensime')

        if os.path.isfile(config_path):
            return config_path
        elif realpath == os.path.abspath('/'):
            return None
        else:
            dirname = os.path.dirname(realpath)
            return ProjectConfig.find_from(dirname)

Find path of an .ensime config, searching recursively upward from path.

Args:
path (str): Path of a file or directory from where to start searching.

Returns:
str: Canonical path of nearest ``.ensime``, or ``None`` if not found.


def __call__(self, name, value):

        super(IntegerTypeChecker, self).__call__(name, value)
        if isinstance(self.minimum, int):
            if value < self.minimum:
                raise ValueError("%s must be greater or equal %s" % (name, self.minimum))
        if isinstance(self.maximum, int):
            if value > self.maximum:
                raise ValueError("%s must be less or equal %s" % (name, self.maximum))

Call method.

Args:
name (str): the value's name.
value (int): the value to check.

Raises:
ValueError: if value is not type int.
ValueError: if value is less than minimum.
ValueError: if value is more than maximum.


def do_put(self, uri, resource, timeout, custom_headers):
    self.validate_resource_uri(uri)
    (task, body) = self._connection.put(uri, resource, custom_headers=custom_headers)
    if (not task):
        return body
    return self._task_monitor.wait_for_task(task, timeout)

Helps to make put requests.

Args:
uri: URI of the resource
timeout: Time out for the request in seconds.
custom_headers: Allows to set custom http headers.

Retuns:
Returns Task object


def pan_and_scan(self, image: np.ndarray, pan_and_scan_min_crop_size: int, pan_and_scan_max_num_crops: int, pan_and_scan_min_ratio_to_activate: float, data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None):
    height, width = get_image_size(image)
    if width >= height:
        if width / height < pan_and_scan_min_ratio_to_activate:
            return []
        num_crops_w = int(math.floor(width / height + 0.5))
        num_crops_w = min(int(math.floor(width / pan_and_scan_min_crop_size)), num_crops_w)
        num_crops_w = max(2, num_crops_w)
        num_crops_w = min(pan_and_scan_max_num_crops, num_crops_w)
        num_crops_h = 1
    else:
        if height / width < pan_and_scan_min_ratio_to_activate:
            return []
        num_crops_h = int(math.floor(height / width + 0.5))
        num_crops_h = min(int(math.floor(height / pan_and_scan_min_crop_size)), num_crops_h)
        num_crops_h = max(2, num_crops_h)
        num_crops_h = min(pan_and_scan_max_num_crops, num_crops_h)
        num_crops_w = 1
    crop_size_w = int(math.ceil(width / num_crops_w))
    crop_size_h = int(math.ceil(height / num_crops_h))
    if min(crop_size_w, crop_size_h) < pan_and_scan_min_crop_size:
        return []
    crop_positions_w = [crop_size_w * i for i in range(num_crops_w)]
    crop_positions_h = [crop_size_h * i for i in range(num_crops_h)]
    if input_data_format == ChannelDimension.LAST:
        image_crops = [image[pos_h:pos_h + crop_size_h, pos_w:pos_w + crop_size_w] for pos_h, pos_w in itertools.product(crop_positions_h, crop_positions_w)]
    else:
        image_crops = [image[:, pos_h:pos_h + crop_size_h, pos_w:pos_w + crop_size_w] for pos_h, pos_w in itertools.product(crop_positions_h, crop_positions_w)]
    return image_crops

Pan and Scan and image, by cropping into smaller images when the aspect ratio exceeds
minimum allowed ratio.

Args:
image (`np.ndarray`):
Image to resize.
pan_and_scan_min_crop_size (`int`, *optional*):
Minimum size of each crop in pan and scan.
pan_and_scan_max_num_crops (`int`, *optional*):
Maximum number of crops per image in pan and scan.
pan_and_scan_min_ratio_to_activate (`float`, *optional*):
Minimum aspect ratio to activate pan and scan.
data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format of the image. If not provided, it will be the same as the input image.
input_data_format (`ChannelDimension` or `str`, *optional*):
The channel dimension format of the input image. If not provided, it will be inferred.


def ldap_sync(self, **kwargs):
    path = ('/groups/%s/ldap_sync' % self.get_id())
    self.manager.gitlab.http_post(path, **kwargs)

Sync LDAP groups.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabCreateError: If the server cannot perform the request


def _process_regular_parameters(sig, func, class_name, documented_params, indent_level, undocumented_parameters):
    docstring = ''
    source_args_dict = source_args_doc([ModelArgs, ImageProcessorArgs])
    missing_args = {}
    for param_name, param in sig.parameters.items():
        if param_name in ARGS_TO_IGNORE or param.kind == inspect.Parameter.VAR_POSITIONAL or param.kind == inspect.Parameter.VAR_KEYWORD:
            continue
        param_type, optional = _process_parameter_type(param, param_name, func)
        param_default = ''
        if param.default != inspect._empty and param.default is not None:
            param_default = f', defaults to `{str(param.default)}`'
        param_type, optional_string, shape_string, additional_info, description, is_documented = _get_parameter_info(param_name, documented_params, source_args_dict, param_type, optional)
        if is_documented:
            if param_name == 'config':
                if param_type == '':
                    param_type = f'[`{class_name}`]'
                else:
                    param_type = f'[`{param_type.split('.')[-1]}`]'
            elif param_type == '' and False:
                print(f'🚨 {param_name} for {func.__qualname__} in file {func.__code__.co_filename} has no type')
            param_type = param_type if '`' in param_type else f'`{param_type}`'
            if additional_info:
                param_docstring = f'{param_name} ({param_type}{additional_info}):{description}'
            else:
                param_docstring = f'{param_name} ({param_type}{shape_string}{optional_string}{param_default}):{description}'
            docstring += set_min_indent(param_docstring, indent_level + 8)
        else:
            missing_args[param_name] = {'type': param_type if param_type else '<fill_type>', 'optional': optional, 'shape': shape_string, 'description': description if description else '\n    <fill_description>', 'default': param_default}
            undocumented_parameters.append(f"🚨 `{param_name}` is part of {func.__qualname__}'s signature, but not documented. Make sure to add it to the docstring of the function in {func.__code__.co_filename}.")
    return (docstring, missing_args)

Process all regular parameters (not kwargs parameters) from the function signature.

Args:
sig (`inspect.Signature`): Function signature
func (`function`): Function the parameters belong to
class_name (`str`): Name of the class
documented_params (`dict`): Dictionary of parameters that are already documented
indent_level (`int`): Indentation level
undocumented_parameters (`list`): List to append undocumented parameters to


def _ReadDefinitionFile(self, filename):

    if not filename:
      return None

    path = os.path.join(self._DEFINITION_FILES_PATH, filename)
    with open(path, 'rb') as file_object:
      definition = file_object.read()

    return dtfabric_fabric.DataTypeFabric(yaml_definition=definition)

Reads a dtFabric definition file.

Args:
filename (str): name of the dtFabric definition file.

Returns:
dtfabric.DataTypeFabric: data type fabric which contains the data format
data type maps of the data type definition, such as a structure, that
can be mapped onto binary data or None if no filename is provided.


def add_symbol(self, symbol_name, namespace_stack, node, module):
    if namespace_stack:
        last_namespace = self.namespaces
        for namespace in namespace_stack:
            last_namespace = last_namespace.setdefault(namespace, {})
    else:
        last_namespace = self.namespaces[None]
    return self._add(symbol_name, last_namespace, node, module)

Adds symbol_name defined in namespace_stack to the symbol table.

Args:
symbol_name: 'name of the symbol to lookup'
namespace_stack: None or ['namespaces', 'symbol', 'defined', 'in']
node: ast.Node that defines this symbol
module: module (any object) this symbol is defined in

Returns:
bool(if symbol was *not* already present)


def get_compound_pd(self):
    entry1 = PDEntry(self.entry1.composition, 0)
    entry2 = PDEntry(self.entry2.composition, 0)
    cpd = CompoundPhaseDiagram((self.rxn_entries + [entry1, entry2]), [Composition(entry1.composition.reduced_formula), Composition(entry2.composition.reduced_formula)], normalize_terminal_compositions=False)
    return cpd

Get the CompoundPhaseDiagram object, which can then be used for
plotting.

Returns:
(CompoundPhaseDiagram)


def files_comments_edit(
        self, *, comment: str, file: str, id: str, **kwargs
    ) -> SlackResponse:

        kwargs.update({"comment": comment, "file": file, "id": id})
        return self.api_call("files.comments.edit", json=kwargs)

Edit an existing file comment.

Args:
comment (str): The body of the comment.
e.g. 'Everyone should take a moment to read this file.'
file (str): The file id. e.g. 'F1234467890'
id (str): The file comment id. e.g. 'Fc1234567890'


def copartition_datasets(self, axis, other, left_func, right_func):
    if (left_func is None):
        new_self = self
    else:
        new_self = self.map_across_full_axis(axis, left_func)
    if (right_func is None):
        if ((axis == 0) and (not np.array_equal(other.block_lengths, new_self.block_lengths))):
            new_other = other.manual_shuffle(axis, (lambda x: x), new_self.block_lengths)
        elif ((axis == 1) and (not np.array_equal(other.block_widths, new_self.block_widths))):
            new_other = other.manual_shuffle(axis, (lambda x: x), new_self.block_widths)
        else:
            new_other = other
    else:
        new_other = other.manual_shuffle(axis, right_func, (new_self.block_lengths if (axis == 0) else new_self.block_widths))
    return (new_self, new_other)

Copartition two BlockPartitions objects.

Args:
axis: The axis to copartition.
other: The other BlockPartitions object to copartition with.
left_func: The function to apply to left. If None, just use the dimension
of self (based on axis).
right_func: The function to apply to right. If None, check the dimensions of
other and use the identity function if splitting needs to happen.

Returns:
A tuple of BlockPartitions objects, left and right.


def get_unconditional_inputs(self, num_samples=1):
    last_hidden_state = torch.zeros((num_samples, 1, self.config.text_encoder.hidden_size), device=self.device, dtype=self.dtype)
    attention_mask = torch.zeros((num_samples, 1), device=self.device, dtype=torch.long)
    return MusicgenUnconditionalInput(encoder_outputs=(last_hidden_state,), attention_mask=attention_mask, guidance_scale=1.0)

Helper function to get null inputs for unconditional generation, enabling the model to be used without the
feature extractor or tokenizer.

Args:
num_samples (int, *optional*):
Number of audio samples to unconditionally generate.
max_new_tokens (int, *optional*):
Number of tokens to generate for each sample. More tokens means longer audio samples, at the expense of
longer inference (since more audio tokens need to be generated per sample).

Example:
```python
>>> from transformers import MusicgenForConditionalGeneration

>>> model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")

>>> # get the unconditional (or 'null') inputs for the model
>>> unconditional_inputs = model.get_unconditional_inputs(num_samples=1)
>>> audio_samples = model.generate(**unconditional_inputs, max_new_tokens=256)
```


def DeregisterFormatter(cls, formatter_class):

    formatter_data_type = formatter_class.DATA_TYPE.lower()
    if formatter_data_type not in cls._formatter_classes:
      raise KeyError(
          'Formatter class not set for data type: {0:s}.'.format(
              formatter_class.DATA_TYPE))

    del cls._formatter_classes[formatter_data_type]

Deregisters a formatter class.

The formatter classes are identified based on their lower case data type.

Args:
formatter_class (type): class of the formatter.

Raises:
KeyError: if formatter class is not set for the corresponding data type.


def w8a8_block_fp8_matmul_triton(A: torch.Tensor, B: torch.Tensor, As: torch.Tensor, Bs: torch.Tensor, block_size: List[int], output_dtype: torch.dtype=torch.float32) -> torch.Tensor:
    assert len(block_size) == 2
    block_n, block_k = (block_size[0], block_size[1])
    assert A.shape[-1] == B.shape[-1]
    assert A.shape[:-1] == As.shape[:-1] and A.is_contiguous()
    assert triton.cdiv(A.shape[-1], block_k) == As.shape[-1]
    M = A.numel()
    assert B.ndim == 2 and B.is_contiguous() and (Bs.ndim == 2)
    N, K = B.shape
    assert triton.cdiv(N, block_n) == Bs.shape[0]
    assert triton.cdiv(K, block_k) == Bs.shape[1]
    C_shape = A.shape[:-1] + (N,)
    C = A.new_empty(C_shape, dtype=output_dtype)
    BLOCK_SIZE_M = 128
    if M < BLOCK_SIZE_M:
        BLOCK_SIZE_M = triton.next_power_of_2(M)
        BLOCK_SIZE_M = max(BLOCK_SIZE_M, 16)
    BLOCK_SIZE_K = block_k
    assert block_k % BLOCK_SIZE_K == 0
    BLOCK_SIZE_N = block_n

    def grid(META):
        return (triton.cdiv(M, META['BLOCK_SIZE_M']) * triton.cdiv(N, META['BLOCK_SIZE_N']),)
    _w8a8_block_fp8_matmul[grid](A, B, C, As, Bs, M, N, K, block_n, block_k, A.stride(-2), A.stride(-1), B.stride(1), B.stride(0), C.stride(-2), C.stride(-1), As.stride(-2), As.stride(-1), Bs.stride(1), Bs.stride(0), BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=BLOCK_SIZE_N, BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE_M=8)
    return C

This function performs matrix multiplication with block-wise
quantization.
It takes two input tensors `A` and `B` with scales `As` and `Bs`.
The output is returned in the specified `output_dtype`.
Args:
A: The input tensor, e.g., activation.
B: The input tensor, e.g., weight.
As: The per-token-group quantization scale for `A`.
Bs: The per-block quantization scale for `B`.
block_size: The block size for per-block quantization. It should
be 2-dim, e.g., [128, 128].
output_dytpe: The dtype of the returned tensor.
Returns:
torch.Tensor: The result of matmul.


def render_list(self, cnt, unique=False, progress_callback=None, **kwargs):

        rendered_list = []
        i = 0
        total_attempts = 0
        while True:
            if i >= cnt:
                break
            if total_attempts > cnt * self.unique_attempts_factor:
                raise StringGenerator.UniquenessError(u"couldn't satisfy uniqueness")
            s = self.render(**kwargs)
            if unique:
                if not s in rendered_list:
                    rendered_list.append(s)
                    i += 1
            else:
                rendered_list.append(s)
                i += 1
            total_attempts += 1

            if progress_callback and callable(progress_callback):
                progress_callback(i, cnt)

        return rendered_list

Return a list of generated strings.

Args:
cnt (int): length of list
unique (bool): whether to make entries unique

Returns:
list.

We keep track of total attempts because a template may
specify something impossible to attain, like [1-9]{} with cnt==1000


def _write_to_hdx(self, action, data, id_field_name, file_to_upload=None):
    file = None
    try:
        if file_to_upload:
            file = open(file_to_upload, 'rb')
            files = [('upload', file)]
        else:
            files = None
        return self.configuration.call_remoteckan(self.actions()[action], data, files=files)
    except Exception as e:
        raisefrom(HDXError, ('Failed when trying to %s %s! (POST)' % (action, data[id_field_name])), e)
    finally:
        if (file_to_upload and file):
            file.close()

Creates or updates an HDX object in HDX and return HDX object metadata dict

Args:
action (str): Action to perform eg. 'create', 'update'
data (Dict): Data to write to HDX
id_field_name (str): Name of field containing HDX object identifier or None
file_to_upload (Optional[str]): File to upload to HDX

Returns:
Dict: HDX object metadata


def add(self, pattern: Union[(Pattern, FlatTerm)], final_label: T=None) -> int:
    index = len(self._patterns)
    self._patterns.append((pattern, final_label))
    flatterm = (FlatTerm(pattern.expression) if (not isinstance(pattern, FlatTerm)) else pattern)
    if (flatterm.is_syntactic or (len(flatterm) == 1)):
        net = self._generate_syntactic_net(flatterm, index)
    else:
        net = self._generate_net(flatterm, index)
    if self._root:
        self._root = self._product_net(self._root, net)
    else:
        self._root = net
    return index

Add a pattern to the discrimination net.

Args:
pattern:
The pattern which is added to the DiscriminationNet. If an expression is given, it will be converted to
a `FlatTerm` for internal processing. You can also pass a `FlatTerm` directly.
final_label:
A label that is returned if the pattern matches when using :meth:`match`. This will default to the
pattern itself.

Returns:
The index of the newly added pattern. This is used internally to later to get the pattern and its final
label once a match is found.


def get_csr(self, bay_number=None):

        uri = "{}/https/certificaterequest".format(self.data['uri'])

        if bay_number:
            uri += "?bayNumber=%d" % (bay_number)

        return self._helper.do_get(uri)

Get an enclosure's Certificate Signing Request (CSR) that was generated by previous POST to the same URI.

Args:
bay_number: OA to retrieve the previously generated CSR.

Returns:
dict


def send_data(data):
    datalength = len(data)
    csm1 = checksum1(data, datalength)
    csm2 = checksum2(csm1)
    data.insert(0, 255)
    data.insert(1, 255)
    data.insert(5, csm1)
    data.insert(6, csm2)
    stringtosend = ''
    for i in range(len(data)):
        byteformat = ('%02X' % data[i])
        stringtosend = ((stringtosend + '\\x') + byteformat)
    try:
        SERPORT.write(stringtosend.decode('string-escape'))
    except:
        raise HerkulexError('could not communicate with motors')

Send data to herkulex

Paketize & write the packet to serial port

Args:
data (list): the data to be sent

Raises:
SerialException: Error occured while opening serial port


def __init__(self, location=None, parent=None, **kwargs):

    if not parent:
      raise ValueError('Missing parent value.')

    super(CPIOPathSpec, self).__init__(
        location=location, parent=parent, **kwargs)

Initializes a path specification.

Note that the CPIO file path specification must have a parent.

Args:
location (Optional[str]): CPIO file internal location string prefixed
with a path separator character.
parent (Optional[PathSpec]): parent path specification.

Raises:
ValueError: when parent is not set.


def _update_docstring(discretized_pulse: Callable, sampler_inst: Callable) -> Callable:

    wrapped_docstring = pydoc.render_doc(discretized_pulse, '%s')
    header, body = wrapped_docstring.split('\n', 1)
    body = textwrap.indent(body, '                    ')
    wrapped_docstring = header+body
    updated_ds = .format(continuous_name=discretized_pulse.__name__,
                           sampler_name=sampler_inst.__name__,
                           continuous_doc=wrapped_docstring)

    discretized_pulse.__doc__ = updated_ds
    return discretized_pulse

Update annotations of discretized continuous pulse function.

Args:
discretized_pulse: Discretized decorated continuous pulse.
sampler_inst: Applied sampler.


def fit_transform(self, X, y=None, **params):
    return self.fit(X, y).transform(X, y)

Learn vocabulary and return document id matrix.

This is equivalent to fit followed by transform.

Args:
X : iterable
an iterable which yields either str, unicode or file objects.

Returns:
list : document id matrix.
list: label id matrix.


def requested_packages(self, include_implicit=False):

        if include_implicit:
            return self._package_requests + self.implicit_packages
        else:
            return self._package_requests

Get packages in the request.

Args:
include_implicit (bool): If True, implicit packages are appended
to the result.

Returns:
List of `PackageRequest` objects.


def Query(args):

  query = args.query.encode("utf-8")
  timeout = args.timeout_millis / 1000

  try:

    command = [config.CONFIG["Osquery.path"], "--S", "--json", query]
    proc = subprocess.run(
        command,
        timeout=timeout,
        check=True,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)

  except subprocess.TimeoutExpired as error:
    raise TimeoutError(cause=error)
  except subprocess.CalledProcessError as error:
    raise Error("osquery invocation error", cause=error)

  stdout = proc.stdout.decode("utf-8")
  stderr = proc.stderr.decode("utf-8").strip()
  return ProcOutput(stdout=stdout, stderr=stderr)

Calls osquery with given query and returns its output.

Args:
args: A query to call osquery with.

Returns:
A "parsed JSON" representation of the osquery output.

Raises:
QueryError: If the query is incorrect.
TimeoutError: If a call to the osquery executable times out.
Error: If anything else goes wrong with the subprocess call.


def plot_real_feature(df, feature_name, bins=50, figsize=(15, 15)):

    ix_negative_target = df[df.target == 0].index
    ix_positive_target = df[df.target == 1].index

    plt.figure(figsize=figsize)

    ax_overall_dist = plt.subplot2grid((3, 2), (0, 0), colspan=2)
    ax_target_conditional_dist = plt.subplot2grid((3, 2), (1, 0), colspan=2)

    ax_botplot = plt.subplot2grid((3, 2), (2, 0))
    ax_violin_plot = plt.subplot2grid((3, 2), (2, 1))

    ax_overall_dist.set_title('Distribution of {}'.format(feature_name), fontsize=16)
    sns.distplot(
        df[feature_name],
        bins=50,
        ax=ax_overall_dist
    )

    sns.distplot(
        df.loc[ix_positive_target][feature_name],
        bins=bins,
        ax=ax_target_conditional_dist,
        label='Positive Target'
    )
    sns.distplot(
        df.loc[ix_negative_target][feature_name],
        bins=bins,
        ax=ax_target_conditional_dist,
        label='Negative Target'
    )
    ax_target_conditional_dist.legend(loc='upper right', prop={'size': 14})

    sns.boxplot(
        y=feature_name,
        x='target',
        data=df,
        ax=ax_botplot
    )
    sns.violinplot(
        y=feature_name,
        x='target',
        data=df,
        ax=ax_violin_plot
    )

    plt.show()

Plot the distribution of a real-valued feature conditioned by the target.

Examples:
`plot_real_feature(X, 'emb_mean_euclidean')`

Args:
df: Pandas dataframe containing the target column (named 'target').
feature_name: The name of the feature to plot.
bins: The number of histogram bins for the distribution plot.
figsize: The size of the plotted figure.


def is_complex_format_str(node):

    inferred = utils.safe_infer(node)
    if inferred is None or not isinstance(inferred.value, str):
        return True
    try:
        parsed = list(string.Formatter().parse(inferred.value))
    except ValueError:

        return False
    for _, _, format_spec, _ in parsed:
        if format_spec:
            return True
    return False

Checks if node represents a string with complex formatting specs.

Args:
node (astroid.node_classes.NodeNG): AST node to check
Returns:
bool: True if inferred string uses complex formatting, False otherwise


def GetParserPluginsInformation(cls, parser_filter_expression=None):

    parser_plugins_information = []
    for _, parser_class in cls.GetParsers(
        parser_filter_expression=parser_filter_expression):
      if parser_class.SupportsPlugins():
        for plugin_name, plugin_class in parser_class.GetPlugins():
          description = getattr(plugin_class, 'DESCRIPTION', '')
          parser_plugins_information.append((plugin_name, description))

    return parser_plugins_information

Retrieves the parser plugins information.

Args:
parser_filter_expression (Optional[str]): parser filter expression,
where None represents all parsers and plugins.

Returns:
list[tuple[str, str]]: pairs of parser plugin names and descriptions.


def get_db_prep_value(self, value, connection, prepared=False):
    if prepared:
        return value
    if (value is None):
        return []
    values = (value if self.multi_valued_field else [value])
    prepared_values = [self.get_prep_value(v) for v in values]
    return list(sorted(set((v for v in prepared_values if v))))

Prepare a value for DB interaction.

Returns:
- list(bytes) if not prepared
- list(str) if prepared


def _forward_and_backward_functions(self, inference_args, input_tangents):
    outputs = []
    iteration_count = 0
    while len(outputs) < len(self._func_graph.outputs) and any((backprop_util.IsTrainable(output) for output in self._func_graph.outputs[len(outputs):])):
        iteration_count += 1
        if iteration_count >= 20 and iteration_count % 5 == 0:
            new_op_with_trainable_output = None
            num_new_trainable_outputs = 0
            for output in self._func_graph.outputs[len(outputs):]:
                if backprop_util.IsTrainable(output):
                    num_new_trainable_outputs += 1
                    new_op_with_trainable_output = output.op
            logging.warning("Determining side outputs for the function '{}' is taking longer than expected ({} iterations, typically this converges in 5 or so). This could indicate that a gradient registration is adding new ops to the forward pass every time gradients are generated. {} new trainable output(s) were added this iteration, one from the following op:\n {}\nThis may indicate a TensorFlow bug, or an issue in a tf.custom_gradient.".format(self._func_graph.name, iteration_count, num_new_trainable_outputs, new_op_with_trainable_output))
        outputs = list(self._func_graph.outputs)
        self._build_functions_for_outputs(outputs, inference_args, input_tangents)
    forward_function, forward_graph, backward_function, output_indices, num_output_tangents = self._build_functions_for_outputs(outputs, inference_args, input_tangents)
    if len(self._func_graph.outputs) > len(outputs) and any((backprop_util.IsTrainable(output) for output in self._func_graph.outputs[len(outputs):])):
        raise errors.InternalError(f'Unexpectedly added new outputs to the forward function when building the backward function: {self._func_graph.outputs[len(outputs):]}.')
    return (forward_function, forward_graph, backward_function, output_indices, num_output_tangents)

Forward and backward functions suitable for higher-order gradients.

Unlike in `_FirstOrderTapeGradientFunctions`, the backward function built by
this method accepts gradients for all of the outputs of the returned forward
function, including side outputs.

Args:
inference_args: A flat list of Tensors, arguments to the inference
function.
input_tangents: A flat list of Tensors, jvps associated with
`inference_args`.

Returns:
A tuple of (forward_function, backward_function):
forward_function: Takes the same inputs as the inference function, but
returns side outputs used by backward_function in addition to the
inference function's outputs.
backward_function: Takes side outputs from forward_function and
gradients with respect to all of its outputs, real and side. Returns
gradients with respect to the inputs.


def write_markdown_to_file(self, f):
    print('---', file=f)
    print('---', file=f)
    print('<!-- This file is machine generated: DO NOT EDIT! -->', file=f)
    print('', file=f)
    print('
    if self._prefix:
        print(self._prefix, file=f)
    print('[TOC]', file=f)
    print('', file=f)
    if (self._module is not None):
        self._write_module_markdown_to_file(f, self._module)

Prints this library to file `f`.

Args:
f: File to write to.

Returns:
Dictionary of documented members.


def open_usb_handle(self, port_num):
    serial = self.get_usb_serial(port_num)
    return local_usb.LibUsbHandle.open(serial_number=serial)

open usb port

Args:
port_num: port number on the Cambrionix unit

Return:
usb handle


def get_volumes(blocks, layout_info):

    volumes = {}

    vol_blocks_lists = sort.by_vol_id(blocks, layout_info[2])

    for vol_rec in blocks[layout_info[0]].vtbl_recs:
        vol_name = vol_rec.name.strip(b'\x00').decode('utf-8')
        if vol_rec.rec_index not in vol_blocks_lists:
            vol_blocks_lists[vol_rec.rec_index] = []
        volumes[vol_name] = description(vol_rec.rec_index, vol_rec, vol_blocks_lists[vol_rec.rec_index])

    return volumes

Get a list of UBI volume objects from list of blocks

Arguments:
List:blocks            -- List of layout block objects
List:layout_info    -- Layout info (indexes of layout blocks and
associated data blocks.)

Returns:
Dict -- Of Volume objects by volume name, including any
relevant blocks.


def _CheckStorageMetadata(cls, metadata_values, check_readable_only=False):

    format_version = metadata_values.get('format_version', None)

    if not format_version:
      raise IOError('Missing format version.')

    try:
      format_version = int(format_version, 10)
    except (TypeError, ValueError):
      raise IOError('Invalid format version: {0!s}.'.format(format_version))

    if not check_readable_only and format_version != cls._FORMAT_VERSION:
      raise IOError('Format version: {0:d} is not supported.'.format(
          format_version))

    if format_version < cls._COMPATIBLE_FORMAT_VERSION:
      raise IOError(
          'Format version: {0:d} is too old and no longer supported.'.format(
              format_version))

    if format_version > cls._FORMAT_VERSION:
      raise IOError(
          'Format version: {0:d} is too new and not yet supported.'.format(
              format_version))

    metadata_values['format_version'] = format_version

    compression_format = metadata_values.get('compression_format', None)
    if compression_format not in definitions.COMPRESSION_FORMATS:
      raise IOError('Unsupported compression format: {0:s}'.format(
          compression_format))

    serialization_format = metadata_values.get('serialization_format', None)
    if serialization_format != definitions.SERIALIZER_FORMAT_JSON:
      raise IOError('Unsupported serialization format: {0:s}'.format(
          serialization_format))

    storage_type = metadata_values.get('storage_type', None)
    if storage_type not in definitions.STORAGE_TYPES:
      raise IOError('Unsupported storage type: {0:s}'.format(
          storage_type))

Checks the storage metadata.

Args:
metadata_values (dict[str, str]): metadata values per key.
check_readable_only (Optional[bool]): whether the store should only be
checked to see if it can be read. If False, the store will be checked
to see if it can be read and written to.

Raises:
IOError: if the format version or the serializer format is not supported.
OSError: if the format version or the serializer format is not supported.


def _create_scalar_select(lhs_result: _sql_data_types.StandardSqlExpression, rhs_result: _sql_data_types.StandardSqlExpression, scalar_check_op: str, sql_data_type: _sql_data_types.StandardSqlDataType, sql_alias: str):
    return _sql_data_types.Select(select_part=_sql_data_types.RawExpression(f'({lhs_result.as_operand()} {scalar_check_op} {rhs_result.as_operand()})', _sql_data_type=sql_data_type, _sql_alias=sql_alias), from_part=None, sql_dialect=_sql_data_types.SqlDialect.SPARK)

Construct a Spark SQL select statement for scalar values.

Args:
lhs_result: The result of the left-hand side expression.
rhs_result: The result of the right-hand side expression.
scalar_check_op: The scalar operation to be applied ('=' or '!=').
sql_data_type: The SQL data type for the result.
sql_alias: The SQL alias for the result.

Returns:
A compiled Spark SQL select statement.


def get_book_metadata(self, asin):
    kbm = self._get_api_call('get_book_metadata', ('"%s"' % asin))
    return KindleCloudReaderAPI._kbm_to_book(kbm)

Returns a book's metadata.

Args:
asin: The ASIN of the book to be queried.

Returns:
A `KindleBook` instance corresponding to the book associated with
`asin`.


def model_config(instance_type, model, role=None, image=None):
    s3_operations = {}
    model.image = (image or model.image)
    if isinstance(model, sagemaker.model.FrameworkModel):
        container_def = prepare_framework_container_def(model, instance_type, s3_operations)
    else:
        container_def = model.prepare_container_def(instance_type)
        base_name = utils.base_name_from_image(container_def['Image'])
        model.name = (model.name or utils.name_from_base(base_name))
    primary_container = session._expand_container_def(container_def)
    config = {'ModelName': model.name, 'PrimaryContainer': primary_container, 'ExecutionRoleArn': (role or model.role)}
    if model.vpc_config:
        config['VpcConfig'] = model.vpc_config
    if s3_operations:
        config['S3Operations'] = s3_operations
    return config

Export Airflow model config from a SageMaker model

Args:
instance_type (str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge'
model (sagemaker.model.FrameworkModel): The SageMaker model to export Airflow config from
role (str): The ``ExecutionRoleArn`` IAM Role ARN for the model
image (str): An container image to use for deploying the model

Returns:
dict: Model config that can be directly used by SageMakerModelOperator in Airflow. It can also be part
of the config used by SageMakerEndpointOperator and SageMakerTransformOperator in Airflow.


def __init__(self, scandir_path, system, name, header, bytes_path):

        self._cache = dict()
        self._system = system
        self._name = name
        self._header = header
        self._path = ''.join((
            scandir_path if scandir_path[-1] == '/' else (scandir_path + '/'),
            name))
        self._bytes_path = bytes_path

Should only be instantiated by "scandir".

Args:
scandir_path (str): scandir path argument.
system (pycosio._core.io_system.SystemBase subclass):
Storage system.
name (str): Name of the object relative to "scandir_path".
header (dict): Object header
bytes_path (bool): True if path must be returned as bytes.


def get_metric_parsers(metric_packages=tuple(), include_defaults=True):
    metric_parsers = set()
    if include_defaults:
        import git_code_debt.metrics
        metric_parsers.update(discover(git_code_debt.metrics, is_metric_cls))
    for metric_package in metric_packages:
        metric_parsers.update(discover(metric_package, is_metric_cls))
    return metric_parsers

Gets all of the metric parsers.

Args:
metric_packages - Defaults to no extra packages. An iterable of
metric containing packages.  A metric inherits DiffParserBase
and does not have __metric__ = False
A metric package must be imported using import a.b.c
include_defaults - Whether to include the generic metric parsers


def list_sites():
    ret = dict()
    ps_cmd = ['Get-ChildItem', '-Path', "'IIS:\\Sites'", '|', 'Select-Object applicationPool, applicationDefaults, Bindings, ID, Name, PhysicalPath, State']
    keep_keys = ('certificateHash', 'certificateStoreName', 'protocol', 'sslFlags')
    cmd_ret = _srvmgr(cmd=ps_cmd, return_json=True)
    try:
        items = salt.utils.json.loads(cmd_ret['stdout'], strict=False)
    except ValueError:
        raise CommandExecutionError('Unable to parse return data as Json.')
    for item in items:
        bindings = dict()
        for binding in item['bindings']['Collection']:
            if (binding['protocol'] not in ['http', 'https']):
                continue
            filtered_binding = dict()
            for key in binding:
                if (key in keep_keys):
                    filtered_binding.update({key.lower(): binding[key]})
            binding_info = binding['bindingInformation'].split(':', 2)
            (ipaddress, port, hostheader) = [element.strip() for element in binding_info]
            filtered_binding.update({'hostheader': hostheader, 'ipaddress': ipaddress, 'port': port})
            bindings[binding['bindingInformation']] = filtered_binding
        application_defaults = dict()
        for attribute in item['applicationDefaults']['Attributes']:
            application_defaults.update({attribute['Name']: attribute['Value']})
        ret[item['name']] = {'apppool': item['applicationPool'], 'bindings': bindings, 'applicationDefaults': application_defaults, 'id': item['id'], 'state': item['state'], 'sourcepath': item['physicalPath']}
    if (not ret):
        log.warning('No sites found in output: %s', cmd_ret['stdout'])
    return ret

List all the currently deployed websites.

Returns:
dict: A dictionary of the IIS sites and their properties.

CLI Example:

.. code-block:: bash

salt '*' win_iis.list_sites


def set_name(self, name, anyway=False):
    set_name(self.startEA, name, anyway=anyway)

Set Function Name.

Default behavior throws an exception when setting to a name that already exists in
the IDB. to make IDA automatically add a counter to the name (like in the GUI,)
use `anyway=True`.

Args:
name: Desired name.
anyway: `True` to set anyway.


def walknset_vars(self, task_class=None, *args, **kwargs):

        def change_task(task):
            if task_class is not None and task.__class__ is not task_class: return False
            return True

        if self.is_work:
            for task in self:
                if not change_task(task): continue
                task.set_vars(*args, **kwargs)

        elif self.is_flow:
            for task in self.iflat_tasks():
                if not change_task(task): continue
                task.set_vars(*args, **kwargs)

        else:
            raise TypeError("Don't know how to set variables for object class %s"  % self.__class__.__name__)

Set the values of the ABINIT variables in the input files of the nodes

Args:
task_class: If not None, only the input files of the tasks belonging
to class `task_class` are modified.

Example:

flow.walknset_vars(ecut=10, kptopt=4)


def _wait_for_function(self, function_descriptor, driver_id, timeout=10):
    start_time = time.time()
    warning_sent = False
    while True:
        with self.lock:
            if (self._worker.actor_id.is_nil() and (function_descriptor.function_id in self._function_execution_info[driver_id])):
                break
            elif ((not self._worker.actor_id.is_nil()) and (self._worker.actor_id in self._worker.actors)):
                break
        if ((time.time() - start_time) > timeout):
            warning_message = 'This worker was asked to execute a function that it does not have registered. You may have to restart Ray.'
            if (not warning_sent):
                ray.utils.push_error_to_driver(self._worker, ray_constants.WAIT_FOR_FUNCTION_PUSH_ERROR, warning_message, driver_id=driver_id)
            warning_sent = True
        time.sleep(0.001)

Wait until the function to be executed is present on this worker.

This method will simply loop until the import thread has imported the
relevant function. If we spend too long in this loop, that may indicate
a problem somewhere and we will push an error message to the user.

If this worker is an actor, then this will wait until the actor has
been defined.

Args:
function_descriptor : The FunctionDescriptor of the function that
we want to execute.
driver_id (str): The ID of the driver to push the error message to
if this times out.


def _model_setup():
    context.set_log_device_placement(True)
    batch_size = 64
    steps = 2
    with collective_strategy.CollectiveAllReduceStrategy().scope():
        train_ds, _ = mnist_testing_utils.mnist_synthetic_dataset(batch_size, steps)
        model = mnist_testing_utils.get_mnist_model((28, 28, 1))
    return (batch_size, steps, train_ds, model)

Set up a MNIST Keras model for testing purposes.

Builds a MNIST Keras model and returns model information.

Returns:
A tuple of (batch_size, steps, train_dataset, mode)


def norm_zero_one(array, dim=None):
    if (not util_type.is_float(array)):
        array = array.astype(np.float32)
    array_max = array.max(dim)
    array_min = array.min(dim)
    array_exnt = np.subtract(array_max, array_min)
    array_norm = np.divide(np.subtract(array, array_min), array_exnt)
    return array_norm

normalizes a numpy array from 0 to 1 based in its extent

Args:
array (ndarray):
dim   (int):

Returns:
ndarray:

CommandLine:
python -m utool.util_alg --test-norm_zero_one

Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_alg import *  # NOQA
>>> import utool as ut
>>> array = np.array([ 22, 1, 3, 2, 10, 42, ])
>>> dim = None
>>> array_norm = norm_zero_one(array, dim)
>>> result = ut.repr2(list(array_norm), precision=3)
>>> print(result)
[0.512, 0.000, 0.049, 0.024, 0.220, 1.000]


def __init__(self, operation, shape, dtype, name=None, index=0):

    if not isinstance(shape, Shape):
      raise ValueError("shape must be a Shape got %s" % shape.to_string)
    if not isinstance(dtype, tf.DType):
      raise ValueError("dtype must be a tf.DType got %s" % dtype)
    self._mesh = operation.mesh
    self._operation = operation
    self._shape = shape
    self._dtype = dtype
    if name is None:
      name = self.operation.name + ":" + str(index)
    self._name = name

Create a Tensor.

Args:
operation: the Operation that outputs this tensor
shape: a Shape
dtype: a tf.DType
name: an optional string
index: optional integer, the index among operation's output tensors


def getSpatialReferenceId(self, session):

        statement = .format(self.geometryColumnName,
                               self.tableName,
                               self.id)

        result = session.execute(statement)

        for row in result:
            return row.srid

Retrieve the spatial reference id by which the geometry column is registered.

This method is a veneer for an SQL query that calls the ``ST_SRID()`` function on the geometry column.

Args:
session (:mod:`sqlalchemy.orm.session.Session`): SQLAlchemy session object bound to PostGIS enabled database.

Returns:
str: PostGIS spatial reference ID.


def expand(tmpl, *args, **kwargs):
    replacer = functools.partial(_expand_variable_match, list(args), kwargs)
    return _VARIABLE_RE.sub(replacer, tmpl)

Expand a path template with the given variables.

..code-block:: python

>>> expand('users/*/messages/*', 'me', '123')
users/me/messages/123
>>> expand('/v1/{name=shelves/*/books/*}', name='shelves/1/books/3')
/v1/shelves/1/books/3

Args:
tmpl (str): The path template.
args: The positional variables for the path.
kwargs: The named variables for the path.

Returns:
str: The expanded path

Raises:
ValueError: If a positional or named variable is required by the
template but not specified or if an unexpected template expression
is encountered.


def add_logger(name, level=None, format=None):

    format = format or '%(filename)-11s %(lineno)-3d: %(message)s'
    log = logging.getLogger(name)

    log.setLevel(level or logging.INFO)

    ch = logging.StreamHandler(sys.stdout)
    ch.setFormatter(logging.Formatter(format))
    log.addHandler(ch)

    return log

Set up a stdout logger.

Args:
name (str): name of the logger
level: defaults to logging.INFO
format (str): format string for logging output.
defaults to ``%(filename)-11s %(lineno)-3d: %(message)s``.

Returns:
The logger object.


async def vsetup(self, author):
    if self.vready:
        logger.warning('Attempt to init voice when already initialised')
        return
    if (self.state != 'starting'):
        logger.error("Attempt to init from wrong state ('{}'), must be 'starting'.".format(self.state))
        return
    self.logger.debug('Setting up voice')
    self.vchannel = author.voice.voice_channel
    if self.vchannel:
        self.statuslog.info('Connecting to voice')
        try:
            self.vclient = (await client.join_voice_channel(self.vchannel))
        except discord.ClientException as e:
            logger.exception(e)
            self.statuslog.warning("I'm already connected to a voice channel.")
            return
        except discord.opus.OpusNotLoaded as e:
            logger.exception(e)
            logger.error('Could not load Opus. This is an error with your FFmpeg setup.')
            self.statuslog.error('Could not load Opus.')
            return
        except discord.DiscordException as e:
            logger.exception(e)
            self.statuslog.error("I couldn't connect to the voice channel. Check my permissions.")
            return
        except Exception as e:
            self.statuslog.error('Internal error connecting to voice, disconnecting.')
            logger.error('Error connecting to voice {}'.format(e))
            return
    else:
        self.statuslog.error("You're not connected to a voice channel.")
        return
    self.vready = True

Creates the voice client

Args:
author (discord.Member): The user that the voice ui will seek


def bind_to_uniform_block(self, binding=0, *, offset=0, size=(- 1)) -> None:
    self.mglo.bind_to_uniform_block(binding, offset, size)

Bind the buffer to a uniform block.

Args:
binding (int): The uniform block binding.

Keyword Args:
offset (int): The offset.
size (int): The size. Value ``-1`` means all.


def get(
            self,
            section_name,
            key_name,
    ):

        value = None
        try:
            value = self.local_config.get(section_name, key_name)
        except Exception as error_msg:
            self.logger.warning(
                '%s.%s not found in local config', section_name, key_name
            )
            try:
                value = self.global_config.get(section_name, key_name)
            except Exception as error_msg:
                self.logger.error(
                    '%s.%s not found in global config', section_name, key_name
                )
                raise KeyError('Could not find option in local/global config')

        return value

Replicate configparser.get() functionality

Args:
section_name (str): section name in config
key_name (str): key name in config.section_name

Returns:
str: do not check defaults, only return local value

Raises:
KeyError: unable to find option in either local or global config


def _LogForwardedIpChanges(
      self, configured, desired, to_add, to_remove, interface):

    if not to_add and not to_remove:
      return
    self.logger.info(
        'Changing %s IPs from %s to %s by adding %s and removing %s.',
        interface, configured or None, desired or None, to_add or None,
        to_remove or None)

Log the planned IP address changes.

Args:
configured: list, the IP address strings already configured.
desired: list, the IP address strings that will be configured.
to_add: list, the forwarded IP address strings to configure.
to_remove: list, the forwarded IP address strings to delete.
interface: string, the output device to modify.


def ParseLSQuarantineRow(self, parser_mediator, query, row, **unused_kwargs):
    query_hash = hash(query)
    event_data = LsQuarantineEventData()
    event_data.agent = self._GetRowValue(query_hash, row, 'Agent')
    event_data.data = self._GetRowValue(query_hash, row, 'Data')
    event_data.query = query
    event_data.url = self._GetRowValue(query_hash, row, 'URL')
    timestamp = self._GetRowValue(query_hash, row, 'Time')
    date_time = dfdatetime_cocoa_time.CocoaTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_FILE_DOWNLOADED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a launch services quarantine event row.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row.


def read(self, size):
    data_list = []
    bytes_read = 0
    last_block_position = self.position
    while bytes_read < size:
        bytes_from_remaining = min(size - bytes_read, len(self.remaining))
        data_list.append(self.remaining[0:bytes_from_remaining])
        self.remaining = self.remaining[bytes_from_remaining:]
        self.position += bytes_from_remaining
        bytes_read += bytes_from_remaining
        if not self.remaining:
            try:
                self.remaining = self.conn.recv_bytes()
            except EOFError:
                break
    last_block = b''.join(data_list)
    if last_block:
        self.last_block_position = last_block_position
        self.last_block = last_block
    return last_block

Read data from the wrapped pipe connection.

Args:
size: Number of bytes to read. Actual number of bytes read is always
equal to size unless EOF is reached.

Returns:
data read as str.


def class_predictor(self, image_feats: torch.FloatTensor, query_embeds: Optional[torch.FloatTensor]=None, query_mask: Optional[torch.Tensor]=None) -> Tuple[torch.FloatTensor]:
    pred_logits, image_class_embeds = self.class_head(image_feats, query_embeds, query_mask)
    return (pred_logits, image_class_embeds)

Args:
image_feats:
Features extracted from the `image_text_embedder`.
query_embeds:
Text query embeddings.
query_mask:
Must be provided with query_embeddings. A mask indicating which query embeddings are valid.


def bessel_j1(x, name=None):
    with ops.name_scope(name, 'bessel_j1', [x]):
        return gen_special_math_ops.bessel_j1(x)

Computes the Bessel j1 function of `x` element-wise.

Modified Bessel function of order 1.

>>> tf.math.special.bessel_j1([0.5, 1., 2., 4.]).numpy()
array([ 0.24226846,  0.44005059,  0.57672481, -0.06604333], dtype=float32)

Args:
x: A `Tensor` or `SparseTensor`. Must be one of the following types: `half`,
`float32`, `float64`.
name: A name for the operation (optional).

Returns:
A `Tensor` or `SparseTensor`, respectively. Has the same type as `x`.

@compatibility(scipy)
Equivalent to scipy.special.j1
@end_compatibility


def build_data(data_path, size, dataset):

    image_size = 32
    if dataset == "cifar10":
        label_bytes = 1
        label_offset = 0
    elif dataset == "cifar100":
        label_bytes = 1
        label_offset = 1
    depth = 3
    image_bytes = image_size * image_size * depth
    record_bytes = label_bytes + label_offset + image_bytes

    def load_transform(value):

        record = tf.reshape(tf.decode_raw(value, tf.uint8), [record_bytes])
        label = tf.cast(tf.slice(record, [label_offset], [label_bytes]),
                        tf.int32)

        depth_major = tf.reshape(
            tf.slice(record, [label_bytes], [image_bytes]),
            [depth, image_size, image_size])

        image = tf.cast(tf.transpose(depth_major, [1, 2, 0]), tf.float32)
        return (image, label)

    data_files = tf.gfile.Glob(data_path)
    data = tf.contrib.data.FixedLengthRecordDataset(data_files,
                                                    record_bytes=record_bytes)
    data = data.map(load_transform)
    data = data.batch(size)
    iterator = data.make_one_shot_iterator()
    return iterator.get_next()

Creates the queue and preprocessing operations for the dataset.

Args:
data_path: Filename for cifar10 data.
size: The number of images in the dataset.
dataset: The dataset we are using.

Returns:
queue: A Tensorflow queue for extracting the images and labels.


def constant(interval=1):

    try:
        itr = iter(interval)
    except TypeError:
        itr = itertools.repeat(interval)

    for val in itr:
        yield val

Generator for constant intervals.

Args:
interval: A constant value to yield or an iterable of such values.


def cancel(self):
    raise NotImplementedError()

Cancels the pipeline execution.

Raises:
IOError: If there is a persistent problem getting job
information.
NotImplementedError: If the runner does not support this
operation.

Returns:
The final state of the pipeline.


def post_process_segmentation(self, outputs, target_sizes, threshold=0.9, mask_threshold=0.5):
    logger.warning_once('`post_process_segmentation` is deprecated and will be removed in v5 of Transformers, please use `post_process_semantic_segmentation`.')
    out_logits, raw_masks = (outputs.logits, outputs.pred_masks)
    empty_label = out_logits.shape[-1] - 1
    preds = []

    def to_tuple(tup):
        if isinstance(tup, tuple):
            return tup
        return tuple(tup.tolist())
    for cur_logits, cur_masks, size in zip(out_logits, raw_masks, target_sizes):
        cur_scores, cur_labels = cur_logits.softmax(-1).max(-1)
        keep = cur_labels.ne(empty_label) & (cur_scores > threshold)
        cur_scores = cur_scores[keep]
        cur_labels = cur_labels[keep]
        cur_masks = cur_masks[keep]
        cur_masks = nn.functional.interpolate(cur_masks[:, None], to_tuple(size), mode='bilinear').squeeze(1)
        cur_masks = (cur_masks.sigmoid() > mask_threshold) * 1
        predictions = {'scores': cur_scores, 'labels': cur_labels, 'masks': cur_masks}
        preds.append(predictions)
    return preds

Converts the output of [`DetrForSegmentation`] into image segmentation predictions. Only supports PyTorch.

Args:
outputs ([`DetrSegmentationOutput`]):
Raw outputs of the model.
target_sizes (`torch.Tensor` of shape `(batch_size, 2)` or `List[Tuple]` of length `batch_size`):
Torch Tensor (or list) corresponding to the requested final size (h, w) of each prediction.
threshold (`float`, *optional*, defaults to 0.9):
Threshold to use to filter out queries.
mask_threshold (`float`, *optional*, defaults to 0.5):
Threshold to use when turning the predicted masks into binary values.
Returns:
`List[Dict]`: A list of dictionaries, each dictionary containing the scores, labels, and masks for an image
in the batch as predicted by the model.


def normalize_collaboration(collaboration):
    if (not collaboration):
        return []
    collaboration = collaboration.strip()
    if (collaboration.startswith('(') and collaboration.endswith(')')):
        collaboration = collaboration[1:(- 1)]
    collaborations = _RE_AND.split(collaboration)
    collaborations = (_RE_COLLABORATION_LEADING.sub('', collab) for collab in collaborations)
    collaborations = (_RE_COLLABORATION_TRAILING.sub('', collab) for collab in collaborations)
    return [collab.strip() for collab in collaborations]

Normalize collaboration string.

Args:
collaboration: a string containing collaboration(s) or None

Returns:
list: List of extracted and normalized collaborations

Examples:
>>> from inspire_schemas.utils import normalize_collaboration
>>> normalize_collaboration('for the CMS and ATLAS Collaborations')
['CMS', 'ATLAS']


def get_src_folder(self):
    with open(('%s/settings.gradle' % self.path)) as f:
        for line in f.readlines():
            if line.startswith('include'):
                matches = re.findall("\\'\\:?(.+?)\\'", line)
            if (len(matches) == 0):
                continue
            for folder in matches:
                if self.is_app_folder(folder):
                    return folder
    return 'app'

Gets the app source folder from settings.gradle file.

Returns:
A string containing the project source folder name (default is "app")


def has_filename(self, filename):

        fixpath = lambda path: osp.normcase(osp.realpath(path))
        for index, finfo in enumerate(self.data):
            if fixpath(filename) == fixpath(finfo.filename):
                return index
        return None

Return the self.data index position for the filename.

Args:
filename: Name of the file to search for in self.data.

Returns:
The self.data index for the filename.  Returns None
if the filename is not found in self.data.


def run_population(population, evolution, gpus):

    population_size = len(population)
    for k in range(population_size
        procs = []
        for j in range(len(gpus)):
            i = k * len(gpus) + j
            if i < population_size:
                save_path = expand_path(
                    evolution.get_value_from_config(parse_config(population[i]),
                                                    evolution.path_to_models_save_path))

                save_path.mkdir(parents=True, exist_ok=True)
                f_name = save_path / "config.json"
                save_json(population[i], f_name)

                with save_path.joinpath('out.txt').open('w', encoding='utf8') as outlog,\
                        save_path.joinpath('err.txt').open('w', encoding='utf8') as errlog:
                    env = dict(os.environ)
                    if len(gpus) > 1 or gpus[0] != -1:
                        env['CUDA_VISIBLE_DEVICES'] = str(gpus[j])

                    procs.append(Popen("{} -m deeppavlov train {}".format(sys.executable, str(f_name)),
                                       shell=True, stdout=outlog, stderr=errlog, env=env))
        for j, proc in enumerate(procs):
            i = k * len(gpus) + j
            log.info(f'Waiting on {i}th proc')
            if proc.wait() != 0:
                save_path = expand_path(
                    evolution.get_value_from_config(parse_config(population[i]),
                                                    evolution.path_to_models_save_path))
                with save_path.joinpath('err.txt').open(encoding='utf8') as errlog:
                    log.warning(f'Population {i} returned an error code {proc.returncode} and an error log:\n' +
                                errlog.read())
    return None

Change save and load paths for obtained population, save config.json with model config,
run population via current python executor (with which evolve.py already run)
and on given devices (-1 means CPU, other integeres - visible for evolve.py GPUs)
Args:
population: list of dictionaries - configs of current population
evolution: ParamsEvolution
gpus: list of given devices (list of integers)

Returns:
None


def __init__(self, file_object, encoding='utf-8', end_of_line='\n'):

    super(TextFile, self).__init__()
    self._file_object = file_object
    self._file_object_size = file_object.get_size()
    self._encoding = encoding
    self._end_of_line = end_of_line.encode(self._encoding)
    self._end_of_line_length = len(self._end_of_line)
    self._lines = []
    self._lines_buffer = b''
    self._lines_buffer_offset = 0
    self._current_offset = 0

Initializes the text file.

Args:
file_object (FileIO): a file-like object to read from.
encoding (Optional[str]): text encoding.
end_of_line (Optional[str]): end of line indicator.


def convert_legacy_structure(output_types, output_shapes, output_classes):
    flat_types = nest.flatten(output_types)
    flat_shapes = nest.flatten(output_shapes)
    flat_classes = nest.flatten(output_classes)
    flat_ret = []
    for flat_type, flat_shape, flat_class in zip(flat_types, flat_shapes, flat_classes):
        if isinstance(flat_class, type_spec.TypeSpec):
            flat_ret.append(flat_class)
        elif issubclass(flat_class, sparse_tensor.SparseTensor):
            flat_ret.append(sparse_tensor.SparseTensorSpec(flat_shape, flat_type))
        elif issubclass(flat_class, tensor_lib.Tensor):
            flat_ret.append(tensor_lib.TensorSpec(flat_shape, flat_type))
        elif issubclass(flat_class, tensor_array_ops.TensorArray):
            flat_ret.append(tensor_array_ops.TensorArraySpec(flat_shape[2:], flat_type, dynamic_size=tensor_shape.dimension_value(flat_shape[0]), infer_shape=tensor_shape.dimension_value(flat_shape[1])))
        else:
            raise TypeError('Could not build a structure for output class {}. Make sure any component class in `output_classes` inherits from one of the following classes: `tf.TypeSpec`, `tf.sparse.SparseTensor`, `tf.Tensor`, `tf.TensorArray`.'.format(flat_class.__name__))
    return nest.pack_sequence_as(output_classes, flat_ret)

Returns a `Structure` that represents the given legacy structure.

This method provides a way to convert from the existing `Dataset` and
`Iterator` structure-related properties to a `Structure` object. A "legacy"
structure is represented by the `tf.data.Dataset.output_types`,
`tf.data.Dataset.output_shapes`, and `tf.data.Dataset.output_classes`
properties.

TODO(b/110122868): Remove this function once `Structure` is used throughout
`tf.data`.

Args:
output_types: A nested structure of `tf.DType` objects corresponding to
each component of a structured value.
output_shapes: A nested structure of `tf.TensorShape` objects
corresponding to each component a structured value.
output_classes: A nested structure of Python `type` objects corresponding
to each component of a structured value.

Returns:
A `Structure`.

Raises:
TypeError: If a structure cannot be built from the arguments, because one of
the component classes in `output_classes` is not supported.


def guess_content_kind(path=None, web_video_data=None, questions=None):

    if questions and len(questions) > 0:
        return content_kinds.EXERCISE

    if path:
        ext = os.path.splitext(path)[1][1:].lower()
        if ext in content_kinds.MAPPING:
            return content_kinds.MAPPING[ext]
        raise InvalidFormatException("Invalid file type: Allowed formats are {0}".format([key for key, value in content_kinds.MAPPING.items()]))
    elif web_video_data:
        return content_kinds.VIDEO
    else:
        return content_kinds.TOPIC

guess_content_kind: determines what kind the content is
Args:
files (str or list): files associated with content
Returns: string indicating node's kind


def load(self, label_lookup_path, uid_lookup_path):
    if (not tf.gfile.Exists(uid_lookup_path)):
        tf.logging.fatal('File does not exist %s', uid_lookup_path)
    if (not tf.gfile.Exists(label_lookup_path)):
        tf.logging.fatal('File does not exist %s', label_lookup_path)
    proto_as_ascii_lines = tf.gfile.GFile(uid_lookup_path).readlines()
    uid_to_human = {}
    p = re.compile('[n\\d]*[ \\S,]*')
    for line in proto_as_ascii_lines:
        parsed_items = p.findall(line)
        uid = parsed_items[0]
        human_string = parsed_items[2]
        uid_to_human[uid] = human_string
    node_id_to_uid = {}
    proto_as_ascii = tf.gfile.GFile(label_lookup_path).readlines()
    for line in proto_as_ascii:
        if line.startswith('  target_class:'):
            target_class = int(line.split(': ')[1])
        if line.startswith('  target_class_string:'):
            target_class_string = line.split(': ')[1]
            node_id_to_uid[target_class] = target_class_string[1:(- 2)]
    node_id_to_name = {}
    for (key, val) in node_id_to_uid.items():
        if (val not in uid_to_human):
            tf.logging.fatal('Failed to locate: %s', val)
        name = uid_to_human[val]
        node_id_to_name[key] = name
    return node_id_to_name

Loads a human readable English name for each softmax node.

Args:
label_lookup_path: string UID to integer node ID.
uid_lookup_path: string UID to human-readable string.

Returns:
dict from integer node ID to human-readable string.


def locator(self, value):

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

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

Args:
value (str): New Maidenhead locator string


def center_slab(slab):
    bdists = sorted([nn[1] for nn in slab.get_neighbors(slab[0], 10) if (nn[1] > 0)])
    r = (bdists[0] * 3)
    all_indices = [i for (i, site) in enumerate(slab)]
    for site in slab:
        if any([(nn[1] > slab.lattice.c) for nn in slab.get_neighbors(site, r)]):
            shift = ((1 - site.frac_coords[2]) + 0.05)
            slab.translate_sites(all_indices, [0, 0, shift])
    weights = [s.species.weight for s in slab]
    center_of_mass = np.average(slab.frac_coords, weights=weights, axis=0)
    shift = (0.5 - center_of_mass[2])
    slab.translate_sites(all_indices, [0, 0, shift])
    return slab

The goal here is to ensure the center of the slab region
is centered close to c=0.5. This makes it easier to
find the surface sites and apply operations like doping.

There are three cases where the slab in not centered:
1. The slab region is completely between two vacuums in the
box but not necessarily centered. We simply shift the
slab by the difference in its center of mass and 0.5
along the c direction.
2. The slab completely spills outside the box from the bottom
and into the top. This makes it incredibly difficult to
locate surface sites. We iterate through all sites that
spill over (z>c) and shift all sites such that this specific
site is now on the other side. Repeat for all sites with z>c.
3. This is a simpler case of scenario 2. Either the top or bottom
slab sites are at c=0 or c=1. Treat as scenario 2.
Args:
slab (Slab): Slab structure to center
Returns:
Returns a centered slab structure


def _check_default_values(method_signature, base_signature):
    for base_param_name, base_default_value in base_signature.defaults.items():
        if base_param_name in base_signature.kwonly_params:
            if base_param_name not in method_signature.kwonly_params and base_param_name not in method_signature.param_names:
                continue
            method_param_name = base_param_name
        else:
            base_param_index = base_signature.param_names.index(base_param_name)
            if base_param_index >= len(method_signature.param_names):
                continue
            method_param_name = method_signature.param_names[base_param_index]
        try:
            method_default_value = method_signature.defaults[method_param_name]
        except KeyError:
            return SignatureError(SignatureErrorType.DEFAULT_PARAMETER_MISMATCH, f"Parameter '{method_param_name}' must have a default value.")
        try:
            base_default = abstract_utils.get_atomic_python_constant(base_default_value)
            method_default = abstract_utils.get_atomic_python_constant(method_default_value)
        except abstract_utils.ConversionError:
            continue
        if base_default != method_default:
            return SignatureError(SignatureErrorType.DEFAULT_VALUE_MISMATCH, f"Parameter '{base_param_name}' must have the same default value.")
    return None

Checks that default parameter values of the overriding method match.

Args:
method_signature: signature of the overriding method.
base_signature: signature of the overridden method.

Returns:
SignatureError if a mismatch is detected. Otherwise returns None.


def process_tfma(schema_file, big_query_table=None, eval_model_dir=None, max_eval_rows=None, pipeline_args=None, publish_to_bq=False, project=None, metrics_table=None, metrics_dataset=None):
    if big_query_table is None:
        raise ValueError('--big_query_table should be provided.')
    slice_spec = [tfma.slicer.SingleSliceSpec(), tfma.slicer.SingleSliceSpec(columns=['trip_start_hour'])]
    metrics_namespace = metrics_table
    schema = taxi.read_schema(schema_file)
    eval_shared_model = tfma.default_eval_shared_model(eval_saved_model_path=eval_model_dir, add_metrics_callbacks=[tfma.post_export_metrics.calibration_plot_and_prediction_histogram(), tfma.post_export_metrics.auc_plots()])
    metrics_monitor = None
    if publish_to_bq:
        metrics_monitor = MetricsReader(publish_to_bq=publish_to_bq, project_name=project, bq_table=metrics_table, bq_dataset=metrics_dataset, namespace=metrics_namespace, filters=MetricsFilter().with_namespace(metrics_namespace))
    pipeline = beam.Pipeline(argv=pipeline_args)
    query = taxi.make_sql(big_query_table, max_eval_rows, for_eval=True)
    raw_feature_spec = taxi.get_raw_feature_spec(schema)
    raw_data = pipeline | 'ReadBigQuery' >> ReadFromBigQuery(query=query, project=project, use_standard_sql=True) | 'Measure time: Start' >> beam.ParDo(MeasureTime(metrics_namespace)) | 'CleanData' >> beam.Map(lambda x: taxi.clean_raw_data_dict(x, raw_feature_spec))
    coder = taxi.make_proto_coder(schema)
    extractors = tfma.default_extractors(eval_shared_model=eval_shared_model, slice_spec=slice_spec, desired_batch_size=None, materialize=False)
    evaluators = tfma.default_evaluators(eval_shared_model=eval_shared_model, desired_batch_size=None, num_bootstrap_samples=1)
    _ = raw_data | 'ToSerializedTFExample' >> beam.Map(coder.encode) | 'Extract Results' >> tfma.InputsToExtracts() | 'Extract and evaluate' >> tfma.ExtractAndEvaluate(extractors=extractors, evaluators=evaluators) | 'Map Evaluations to PCollection' >> MapEvalToPCollection() | 'Measure time: End' >> beam.ParDo(MeasureTime(metrics_namespace))
    result = pipeline.run()
    result.wait_until_finish()
    if metrics_monitor:
        metrics_monitor.publish_metrics(result)

Runs a batch job to evaluate the eval_model against the given input.

Args:
schema_file: A file containing a text-serialized Schema that describes the
eval data.
big_query_table: A BigQuery table name specified as DATASET.TABLE which
should be the input for evaluation. This can only be set if input_csv is
None.
eval_model_dir: A directory where the eval model is located.
max_eval_rows: Number of rows to query from BigQuery.
pipeline_args: additional DataflowRunner or DirectRunner args passed to
the beam pipeline.
publish_to_bq:
project:
metrics_dataset:
metrics_table:

Raises:
ValueError: if input_csv and big_query_table are not specified correctly.


def _refresh(self, http):

        try:
            self._retrieve_info(http)
            self.access_token, self.token_expiry = _metadata.get_token(
                http, service_account=self.service_account_email)
        except http_client.HTTPException as err:
            raise client.HttpAccessTokenRefreshError(str(err))

Refreshes the access token.

Skip all the storage hoops and just refresh using the API.

Args:
http: an object to be used to make HTTP requests.

Raises:
HttpAccessTokenRefreshError: When the refresh fails.


def forward(self, x: torch.Tensor, mask: Optional[torch.Tensor]=None, chunk_size: Optional[int]=None, use_memory_efficient_kernel: bool=False, use_lma: bool=False, inplace_safe: bool=False) -> torch.Tensor:
    if mask is None:
        mask = x.new_ones(x.shape[:-1])
    if not self.starting:
        x = x.transpose(-2, -3)
        mask = mask.transpose(-1, -2)
    x = self.layer_norm(x)
    mask_bias = (self.inf * (mask - 1))[..., :, None, None, :]
    triangle_bias = permute_final_dims(self.linear(x), (2, 0, 1))
    triangle_bias = triangle_bias.unsqueeze(-4)
    biases = [mask_bias, triangle_bias]
    if chunk_size is not None:
        x = self._chunk(x, biases, chunk_size, use_memory_efficient_kernel=use_memory_efficient_kernel, use_lma=use_lma, inplace_safe=inplace_safe)
    else:
        x = self.mha(q_x=x, kv_x=x, biases=biases, use_memory_efficient_kernel=use_memory_efficient_kernel, use_lma=use_lma)
    if not self.starting:
        x = x.transpose(-2, -3)
    return x

Args:
x:
[*, I, J, C_in] input tensor (e.g. the pair representation)
Returns:
[*, I, J, C_in] output tensor


def find_vasp_calculations():
    dir_list = [('./' + re.sub('vasprun\\.xml', '', path)) for path in glob.iglob('**/vasprun.xml', recursive=True)]
    gz_dir_list = [('./' + re.sub('vasprun\\.xml\\.gz', '', path)) for path in glob.iglob('**/vasprun.xml.gz', recursive=True)]
    return (dir_list + gz_dir_list)

Returns a list of all subdirectories that contain either a vasprun.xml file
or a compressed vasprun.xml.gz file.

Args:
None

Returns:
(List): list of all VASP calculation subdirectories.


def disp(obj: Any, mode: str='') -> None:
    if _Options.LINE in mode:
        raise NotImplementedError('Line mode not supported in `disp()`')
    _display_and_return(obj, options=mode)

Display the object.

This is the functional API for the `;` auto display magic.

Args:
obj: The object to display
mode: Any mode supported by `ecolab.auto_display()`


def find_all_documented_objects() -> List[str]:
    documented_obj = []
    documented_methods_map = {}
    for doc_file in Path(PATH_TO_DOC).glob('**/*.md'):
        with open(doc_file, 'r', encoding='utf-8', newline='\n') as f:
            content = f.read()
        raw_doc_objs = re.findall('\\[\\[autodoc\\]\\]\\s+(\\S+)\\s+', content)
        documented_obj += [obj.split('.')[-1] for obj in raw_doc_objs]
        for obj in raw_doc_objs:
            obj_public_methods = re.findall(f'\\[\\[autodoc\\]\\] {obj}((\\n\\s+-.*)+)', content)
            if len(obj_public_methods) == 0:
                continue
            else:
                documented_methods_map[obj] = re.findall('(?<=-\\s).*', obj_public_methods[0][0])
    return (documented_obj, documented_methods_map)

Parse the content of all doc files to detect which classes and functions it documents.

Returns:
`List[str]`: The list of all object names being documented.
`Dict[str, List[str]]`: A dictionary mapping the object name (full import path, e.g.
`integrations.PeftAdapterMixin`) to its documented methods


def get_appliance_by_name(self, appliance_name):

        appliances = self.get_appliances()

        if appliances:
            for appliance in appliances:
                if appliance['name'] == appliance_name:
                    return appliance
        return None

Gets the particular Image Streamer resource based on its name.

Args:
appliance_name:
The Image Streamer resource name.

Returns:
dict: Image Streamer resource.


def write(grp, out_path):
    with open(out_path, 'w') as f:
        for x in grp:
            f.write((str(x) + '\n'))

Write a GRP to a text file.

Args:
grp (list): GRP object to write to new-line delimited text file
out_path (string): output path

Returns:
None


def _has_valid_catchup_replies(self, seq_no: int, txns_to_process: List[Tuple[(int, Any)]]) -> Tuple[(bool, str, int)]:
    assert (seq_no == txns_to_process[0][0])
    (node_name, catchup_rep) = self._find_catchup_reply_for_seq_no(seq_no)
    txns = catchup_rep.txns
    txns = [self._provider.transform_txn_for_ledger(txn) for (s, txn) in txns_to_process[:len(txns)] if (str(s) in txns)]
    temp_tree = self._ledger.treeWithAppliedTxns(txns)
    proof = catchup_rep.consProof
    final_size = self._catchup_till.final_size
    final_hash = self._catchup_till.final_hash
    try:
        logger.info('{} verifying proof for {}, {}, {}, {}, {}'.format(self, temp_tree.tree_size, final_size, temp_tree.root_hash, final_hash, proof))
        verified = self._provider.verifier(self._ledger_id).verify_tree_consistency(temp_tree.tree_size, final_size, temp_tree.root_hash, Ledger.strToHash(final_hash), [Ledger.strToHash(p) for p in proof])
    except Exception as ex:
        logger.info('{} could not verify catchup reply {} since {}'.format(self, catchup_rep, ex))
        verified = False
    return (bool(verified), node_name, len(txns))

Transforms transactions for ledger!

Returns:
Whether catchup reply corresponding to seq_no
Name of node from which txns came
Number of transactions ready to be processed


class FlaxImageClassifierOutputWithNoAttention(ModelOutput):
    logits: Optional[jnp.ndarray] = None
    hidden_states: Optional[Tuple[jnp.ndarray]] = None

Base class for outputs of image classification models.

Args:
logits (`jnp.ndarray` of shape `(batch_size, config.num_labels)`):
Classification (or regression if config.num_labels==1) scores (before SoftMax).
hidden_states (`tuple(jnp.ndarray)`, *optional*, returned when `output_hidden_states=True` is passed or when
`config.output_hidden_states=True`):
Tuple of `jnp.ndarray` (one for the output of the embeddings, if the model has an embedding layer, + one
for the output of each stage) of shape `(batch_size, num_channels, height, width)`. Hidden-states (also
called feature maps) of the model at the output of each stage.


def save_as(self, filename: str) -> None:

        lib.TCOD_image_save(self.image_c, filename.encode("utf-8"))

Save the Image to a 32-bit .bmp or .png file.

Args:
filename (Text): File path to same this Image.


def make_all(module_name, doc_string_modules=None):
    if doc_string_modules is None:
        doc_string_modules = [_sys.modules[module_name]]
    cur_members = set((name for name, _ in _tf_inspect.getmembers(_sys.modules[module_name])))
    results = set()
    for doc_module in doc_string_modules:
        results.update([m.group(1) for m in _reference_pattern.finditer(doc_module.__doc__) if m.group(1) in cur_members])
    return list(results)

Generates `__all__` from the docstring of one or more modules.

Usage: `make_all(__name__)` or
`make_all(__name__, [sys.modules(__name__), other_module])`. The doc string
modules must each a docstring, and `__all__` will contain all symbols with
`@@` references, where that symbol currently exists in the module named
`module_name`.

Args:
module_name: The name of the module (usually `__name__`).
doc_string_modules: a list of modules from which to take docstring.
If None, then a list containing only the module named `module_name` is used.

Returns:
A list suitable for use as `__all__`.


def matches(self, spec):

        if callable(spec) and not isinstance(spec, type): return spec(self)
        elif isinstance(spec, type): return isinstance(self, spec)
        specification = (self.__class__.__name__, self.group, self.label)
        split_spec = tuple(spec.split('.')) if not isinstance(spec, tuple) else spec
        split_spec, nocompare = zip(*((None, True) if s == '*' or s is None else (s, False)
                                    for s in split_spec))
        if all(nocompare): return True
        match_fn = itemgetter(*(idx for idx, nc in enumerate(nocompare) if not nc))
        self_spec = match_fn(split_spec)
        unescaped_match = match_fn(specification[:len(split_spec)]) == self_spec
        if unescaped_match: return True
        sanitizers = [util.sanitize_identifier, util.group_sanitizer, util.label_sanitizer]
        identifier_specification = tuple(fn(ident, escape=False)
                                         for ident, fn in zip(specification, sanitizers))
        identifier_match = match_fn(identifier_specification[:len(split_spec)]) == self_spec
        return identifier_match

Whether the spec applies to this object.

Args:
spec: A function, spec or type to check for a match
* A 'type[[.group].label]' string which is compared
against the type, group and label of this object
* A function which is given the object and returns
a boolean.
* An object type matched using isinstance.

Returns:
bool: Whether the spec matched this object.


def _ParseQuery(self, parser_mediator, database, query, callback, cache):

    row_cache = cache.GetRowCache(query)

    try:
      rows = database.Query(query)

    except sqlite3.DatabaseError as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to run query: {0:s} on database with error: {1!s}'.format(
              query, exception))
      return

    for index, row in enumerate(rows):
      if parser_mediator.abort:
        break

      row_hash = self._HashRow(row)
      if row_hash in row_cache:
        continue

      try:
        callback(parser_mediator, query, row, cache=cache, database=database)

      except Exception as exception:
        parser_mediator.ProduceExtractionWarning((
            'unable to parse row: {0:d} with callback: {1:s} on database '
            'with error: {2!s}').format(
                index, callback.__name__, exception))

        return

      row_cache.add(row_hash)

Queries a database and parses the results.

Args:
parser_mediator (ParserMediator): parser mediator.
database (SQLiteDatabase): database.
query (str): query.
callback (function): function to invoke to parse an individual row.
cache (SQLiteCache): cache.


def make_noise_surface(dims=DEFAULT_DIMS, blur=10, seed=None):
    if (seed is not None):
        np.random.seed(seed)
    return gaussian_filter(np.random.normal(size=dims), blur)

Makes a surface by generating random noise and blurring it.

Args:
dims (pair): the dimensions of the surface to create
blur (float): the amount of Gaussian blur to apply
seed (int): a random seed to use (optional)

Returns:
surface: A surface.


def device_function(self, op):
    if not self._merge_devices and op.device:
        return op.device
    current_device = pydev.DeviceSpec.from_string(op.device or '')
    node_def = op if isinstance(op, node_def_pb2.NodeDef) else op.node_def
    if self._ps_tasks and self._ps_device and (node_def.op in self._ps_ops):
        ps_device = pydev.DeviceSpec.from_string(self._ps_device)
        current_job, ps_job = (current_device.job, ps_device.job)
        if ps_job and (not current_job or current_job == ps_job):
            ps_device = ps_device.replace(task=self._ps_strategy(op))
        ps_device = ps_device.make_merged_spec(current_device)
        return ps_device.to_string()
    worker_device = pydev.DeviceSpec.from_string(self._worker_device or '')
    worker_device = worker_device.make_merged_spec(current_device)
    return worker_device.to_string()

Choose a device for `op`.

Args:
op: an `Operation`.

Returns:
The device to use for the `Operation`.


def GetValueRepresentation(cls, value,
                             version=sorted(_SERVICE_MAP.keys())[-1]):

    if isinstance(value, str) or isinstance(value, unicode):
      return {'value': value, 'xsi_type': 'TextValue'}
    elif isinstance(value, bool):
      return {'value': value, 'xsi_type': 'BooleanValue'}
    elif isinstance(value, numbers.Number):
      return {'value': value, 'xsi_type': 'NumberValue'}

    elif isinstance(value, datetime.datetime):
      if value.tzinfo is None:
        raise googleads.errors.GoogleAdsValueError(
            'Datetime %s is not timezone aware.' % value
        )

      return {
          'xsi_type': 'DateTimeValue',
          'value': {
              'date': {
                  'year': value.year,
                  'month': value.month,
                  'day': value.day,
              },
              'hour': value.hour,
              'minute': value.minute,
              'second': value.second,
              'timeZoneId' if version >= 'v201811' else 'timeZoneID':
                  value.tzinfo.zone,
          }
      }
    elif isinstance(value, datetime.date):
      return {
          'xsi_type': 'DateValue',
          'value': {
              'year': value.year,
              'month': value.month,
              'day': value.day,
          }
      }
    elif isinstance(value, list):
      if value and not all(isinstance(x, type(value[0])) for x in value):
        raise googleads.errors.GoogleAdsValueError('Cannot pass more than one '
                                                   'type in a set.')

      return {
          'xsi_type': 'SetValue',
          'values': [cls.GetValueRepresentation(v, version) for v in value]
      }
    else:
      raise googleads.errors.GoogleAdsValueError(
          'Can\'t represent unknown type: %s.' % type(value))

Converts a single python value to its PQL representation.

Args:
value: A python value.
version: A string identifying the Ad Manager version the value object
is compatible with. This defaults to what is currently the latest
version. This will be updated in future releases to point to what is
then the latest version.

Returns:
The value formatted for PQL statements which are compatible with a
particular API version.


def absolute_name(self):
    if (self.is_root() or self.parent.is_root()):
        return utils.slugify(self.name)
    return ':'.join([self.parent.absolute_name, utils.slugify(self.name)])

Get the absolute name of ``self``.

Returns:
str: the absolute name.


def get_all_pattern_variables(self, patternnumber):

        _checkPatternNumber(patternnumber)

        outputstring = ''
        for stepnumber in range(8):
            outputstring += 'SP{0}: {1}  Time{0}: {2}\n'.format(stepnumber, \
                self.get_pattern_step_setpoint( patternnumber, stepnumber), \
                self.get_pattern_step_time(     patternnumber, stepnumber)   )

        outputstring += 'Actual step:        {0}\n'.format(self.get_pattern_actual_step(        patternnumber) )
        outputstring += 'Additional cycles:  {0}\n'.format(self.get_pattern_additional_cycles(  patternnumber) )
        outputstring += 'Linked pattern:     {0}\n'.format(self.get_pattern_link_topattern(     patternnumber) )

        return outputstring

Get all variables for a given pattern at one time.

Args:
patternnumber (integer): 0-7

Returns:
A descriptive multiline string.


def _step(time, output_ta_t, prev_output, *states):
    current_input = tuple((ta.read(time) for ta in input_ta))
    current_input = tree.pack_sequence_as(inputs, current_input)
    mask_t = masking_fn(time)
    output, new_states = step_function(current_input, tuple(states) + tuple(constants))
    flat_output = tree.flatten(output)
    flat_mask_output = flat_zero_output if zero_output_for_mask else tree.flatten(prev_output)
    flat_new_output = compute_masked_output(mask_t, flat_output, flat_mask_output)
    flat_state = tree.flatten(states)
    flat_new_state = tree.flatten(new_states)
    flat_final_state = compute_masked_output(mask_t, flat_new_state, flat_state)
    new_states = tree.pack_sequence_as(new_states, flat_final_state)
    ta_index_to_write = time if return_all_outputs else 0
    output_ta_t = tuple((ta.write(ta_index_to_write, out) for ta, out in zip(output_ta_t, flat_new_output)))
    return (time + 1, output_ta_t, tuple(flat_new_output)) + tuple(new_states)

RNN step function.

Args:
time: Current timestep value.
output_ta_t: TensorArray.
prev_output: tuple of outputs from time - 1.
*states: List of states.

Returns:
Tuple: `(time + 1, output_ta_t, output) + tuple(new_states)`