def IsNamedTuple(component):
    if not isinstance(component, tuple):
        return False
    has_fields = bool(getattr(component, '_fields', None))
    return has_fields

Return true if the component is a namedtuple.

Unfortunately, Python offers no native way to check for a namedtuple type.
Instead, we need to use a simple hack which should suffice for our case.
namedtuples are internally implemented as tuples, therefore we need to:
1. Check if the component is an instance of tuple.
2. Check if the component has a _fields attribute which regular tuples do
not have.

Args:
component: The component to analyze.
Returns:
True if the component is a namedtuple or False otherwise.


def alias_tensors(*args):

    def alias_if_tensor(a):
        return array_ops.identity(a) if isinstance(a, tensor.Tensor) else a
    if len(args) > 1:
        return (alias_if_tensor(a) for a in args)
    elif len(args) == 1:
        return alias_if_tensor(args[0])
    raise ValueError('at least one argument required')

Wraps any Tensor arguments with an identity op.

Any other argument, including Variables, is returned unchanged.

Args:
*args: Any arguments. Must contain at least one element.

Returns:
Same as *args, with Tensor instances replaced as described.

Raises:
ValueError: If args doesn't meet the requirements.


def apply_region_configs(env_config):
    new_config = env_config.copy()
    for region in env_config.get('regions', REGIONS):
        if isinstance(env_config.get('regions'), dict):
            region_specific_config = env_config['regions'][region]
            new_config[region] = dict(DeepChainMap(region_specific_config, env_config))
        else:
            new_config[region] = env_config.copy()
    LOG.debug('Region Specific Config:\n%s', new_config)
    return new_config

Override default env configs with region specific configs and nest
all values under a region

Args:
env_config (dict): The environment specific config.

Return:
dict: Newly updated dictionary with region overrides applied.


def imag(x):
    if any_symbolic_tensors((x,)):
        return Imag().symbolic_call(x)
    return backend.numpy.imag(x)

Return the imaginary part of the complex argument.

Args:
x: Input tensor.

Returns:
The imaginary component of the complex argument.


def _batch_prepare_for_model(self, batch_ids_pairs: List[Union[PreTokenizedInputPair, Tuple[List[int], None]]], batch_shape_ids_pairs: List[Union[PreTokenizedInputPair, Tuple[List[int], None]]], batch_pronunciation_ids_pairs: List[Union[PreTokenizedInputPair, Tuple[List[int], None]]], add_special_tokens: bool=True, padding_strategy: PaddingStrategy=PaddingStrategy.DO_NOT_PAD, truncation_strategy: TruncationStrategy=TruncationStrategy.DO_NOT_TRUNCATE, max_length: Optional[int]=None, stride: int=0, pad_to_multiple_of: Optional[int]=None, padding_side: Optional[str]=None, return_tensors: Optional[str]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_length: bool=False, verbose: bool=True) -> BatchEncoding:
    batch_outputs = {}
    for i, (first_ids, second_ids) in enumerate(batch_ids_pairs):
        first_shape_ids, second_shape_ids = batch_shape_ids_pairs[i]
        first_pronunciation_ids, second_pronunciation_ids = batch_pronunciation_ids_pairs[i]
        outputs = self.prepare_for_model(first_ids, first_shape_ids, first_pronunciation_ids, pair_ids=second_ids, pair_shape_ids=second_shape_ids, pair_pronunciation_ids=second_pronunciation_ids, add_special_tokens=add_special_tokens, padding=PaddingStrategy.DO_NOT_PAD.value, truncation=truncation_strategy.value, max_length=max_length, stride=stride, pad_to_multiple_of=None, padding_side=None, return_attention_mask=False, return_token_type_ids=return_token_type_ids, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_length=return_length, return_tensors=None, prepend_batch_axis=False, verbose=verbose)
        for key, value in outputs.items():
            if key not in batch_outputs:
                batch_outputs[key] = []
            batch_outputs[key].append(value)
    batch_outputs = self.pad(batch_outputs, padding=padding_strategy.value, max_length=max_length, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_attention_mask=return_attention_mask)
    batch_outputs = BatchEncoding(batch_outputs, tensor_type=return_tensors)
    return batch_outputs

Prepares a sequence of input id, or a pair of sequences of inputs ids so that it can be used by the model. It
adds special tokens, truncates sequences if overflowing while taking into account the special tokens and
manages a moving window (with user defined stride) for overflowing tokens

Args:
batch_ids_pairs: list of tokenized input ids or input ids pairs
batch_shape_ids_pairs: list of tokenized input shape ids or input shape ids pairs
batch_pronunciation_ids_pairs: list of tokenized input pronunciation ids or input pronunciation ids pairs


def chop(array, epsilon=1e-10):
    ret = np.array(array)
    if np.isrealobj(ret):
        ret[(abs(ret) < epsilon)] = 0.0
    else:
        ret.real[(abs(ret.real) < epsilon)] = 0.0
        ret.imag[(abs(ret.imag) < epsilon)] = 0.0
    return ret

Truncate small values of a complex array.

Args:
array (array_like): array to truncte small values.
epsilon (float): threshold.

Returns:
np.array: A new operator with small values set to zero.


def _read_mptcp_remove(self, bits, size):
    adid = []
    for _ in size:
        adid.append(self._read_unpack(1))
    data = dict(subtype='REMOVE_ADDR', removeaddr=dict(addrid=(adid or None)))
    return data

Read Remove Address option.

Positional arguments:
* bits - str, 4-bit data
* size - int, length of option

Returns:
* dict -- extracted Remove Address (REMOVE_ADDR) option

Structure of REMOVE_ADDR [RFC 6824]:
1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------+---------------+-------+-------+---------------+
|     Kind      |  Length = 3+n |Subtype|(resvd)|   Address ID  | ...
+---------------+---------------+-------+-------+---------------+
(followed by n-1 Address IDs, if required)

Octets      Bits        Name                            Description
0           0     tcp.opt.kind                    Kind (30)
1           8     tcp.opt.length                  Length
2          16     tcp.opt.mp.subtype              Subtype (4)
2          20     -                               Reserved (must be zero)
3          24     tcp.opt.mp.removeaddr.addrid    Address ID (optional list)


def __init__(self, output, output_name, loss_fn, loss_weight=None, training_target=None, output_loss_metric=None, sample_weight=None, sample_weight_mode=None):
    self._output = output
    self._output_name = output_name
    self._loss_fn = loss_fn
    self._loss_weight = loss_weight
    self._training_target = training_target
    self._output_loss_metric = output_loss_metric
    self._sample_weight = sample_weight
    self._sample_weight_mode = sample_weight_mode

Initialize the _TrainingEndpoint.

Note that the output and output_name should be stable as long as the model
structure doesn't change. The training_target suppose to be mutable since
the information is provided via `compile()`

Args:
output: the output tensor of the model.
output_name: the unique name of the output tensor.
loss_fn: the loss function for the output tensor.
loss_weight: float, the weights for the loss.
training_target: the _TrainingTarget for the model.
output_loss_metric: the metric object for the loss function.
sample_weight: the weights for how a sample is weighted during metric and
loss calculation. Could be None.
sample_weight_mode: string, 'temporal', 'samplewise' or None. The mode for
how the sample_weight is populated.


def begin_stream(self, command: Command) -> Reply:

        yield from self._control_stream.write_command(command)
        reply = yield from self._control_stream.read_reply()

        self.raise_if_not_match(
            'Begin stream',
            (
                ReplyCodes.file_status_okay_about_to_open_data_connection,
                ReplyCodes.data_connection_already_open_transfer_starting,
            ),
            reply
        )

        return reply

Start sending content on the data stream.

Args:
command: A command that tells the server to send data over the
data connection.

Coroutine.

Returns:
The begin reply.


def __init__(self, topology: Topology, core_assignment: np.ndarray):
    if not isinstance(topology, Topology):
        raise ValueError('topology must be a Topology object, got {}'.format(type(topology)))
    core_assignment = numpy_compat.np_asarray(core_assignment, dtype=np.int32)
    self._topology = topology
    if core_assignment.ndim != 3:
        raise ValueError(f'core_assignment must be a rank 3 numpy array, got shape {core_assignment.shape}')
    self._num_replicas = core_assignment.shape[0]
    self._num_cores_per_replica = core_assignment.shape[1]
    if core_assignment.shape[-1] != topology.mesh_rank:
        raise ValueError(f'core_assignment.shape[-1] must have size equal to topology rank ({topology.mesh_rank}), got core_assignment.shape={core_assignment.shape}')
    self._core_assignment = core_assignment
    self._task_and_cores_to_replicas = _compute_task_and_cores_to_replicas(self._core_assignment, topology)

Constructs a `DeviceAssignment` object.

Args:
topology: A `Topology` object that describes the physical TPU topology.
core_assignment: A logical to physical core mapping, represented as a
rank 3 numpy array. See the description of the `core_assignment`
property for more details.

Raises:
ValueError: If `topology` is not `Topology` object.
ValueError: If `core_assignment` is not a rank 3 numpy array.


def glob(*args):

    if len(args) is 1 and isinstance(args[0], list):
        args = args[0]
    matches = []
    for pattern in args:
        for item in glob2.glob(pattern):
            if not os.path.isdir(item):
                matches.append(item)
    return matches

Returns list of paths matching one or more wildcard patterns.

Args:
include_dirs: Include directories in the output


def merge(profile, branch, merge_into):

    data = merges.merge(profile, branch, merge_into)
    return data

Merge a branch into another branch.

Args:

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

branch
The name of the branch to merge.

merge_into
The name of the branch you want to merge into.

Returns:
A dict wtih data about the merge.


def __init__(self, xid=None, body_type=None, flags=0, body=b''):

        super().__init__(xid)
        self.body_type = body_type
        self.flags = flags
        self.body = body

Create a StatsRequest with the optional parameters below.

Args:
xid (int): xid to be used on the message header.
body_type (StatsType): One of the OFPST_* constants.
flags (int): OFPSF_REQ_* flags (none yet defined).
body (BinaryData): Body of the request.


def orthologize(ast, bo, species_id: str):

    if not species_id:
        bo.validation_messages.append(
            ("WARNING", "No species id was provided for orthologization")
        )
        return ast

    if isinstance(ast, NSArg):
        if ast.orthologs:

            if ast.orthologs.get(species_id, None):
                orthologized_nsarg_val = ast.orthologs[species_id]["decanonical"]
                ns, value = orthologized_nsarg_val.split(":")
                ast.change_nsvalue(ns, value)
                ast.canonical = ast.orthologs[species_id]["canonical"]
                ast.decanonical = ast.orthologs[species_id]["decanonical"]
                ast.orthologized = True
                bo.ast.species.add(
                    (species_id, ast.orthologs[species_id]["species_label"])
                )
            else:
                bo.ast.species.add((ast.species_id, ast.species_label))
                bo.validation_messages.append(
                    ("WARNING", f"No ortholog found for {ast.namespace}:{ast.value}")
                )
        elif ast.species_id:
            bo.ast.species.add((ast.species_id, ast.species_label))

    if hasattr(ast, "args"):
        for arg in ast.args:
            orthologize(arg, bo, species_id)

    return ast

Recursively orthologize BEL Entities in BEL AST using API endpoint

NOTE: - will take first ortholog returned in BEL.bio API result (which may return more than one ortholog)

Args:
ast (BEL): BEL AST
endpoint (str): endpoint url with a placeholder for the term_id

Returns:
BEL: BEL AST


def transpose(self, name=None):

    if name is None:
      name = self.module_name + "_transpose"

    if self._data_format == DATA_FORMAT_NWC:
      stride = self._stride[1:-1]
    else:
      stride = self._stride[2:]

    return Conv1D(output_channels=lambda: self.input_channels,
                  kernel_shape=self.kernel_shape,
                  stride=stride,
                  padding=self.padding,
                  use_bias=self._use_bias,
                  initializers=self.initializers,
                  partitioners=self.partitioners,
                  regularizers=self.regularizers,
                  data_format=self._data_format,
                  custom_getter=self._custom_getter,
                  name=name)

Returns matching `Conv1D` module.

Args:
name: Optional string assigning name of transpose module. The default name
is constructed by appending "_transpose" to `self.name`.

Returns:
`Conv1D` module.


def clean_model_doc_toc(model_doc: List[dict]) -> List[dict]:
    counts = defaultdict(int)
    for doc in model_doc:
        counts[doc['local']] += 1
    duplicates = [key for key, value in counts.items() if value > 1]
    new_doc = []
    for duplicate_key in duplicates:
        titles = list({doc['title'] for doc in model_doc if doc['local'] == duplicate_key})
        if len(titles) > 1:
            raise ValueError(f'{duplicate_key} is present several times in the documentation table of content at `docs/source/en/_toctree.yml` with different *Title* values. Choose one of those and remove the others.')
        new_doc.append({'local': duplicate_key, 'title': titles[0]})
    new_doc.extend([doc for doc in model_doc if counts[doc['local']] == 1])
    return sorted(new_doc, key=lambda s: s['title'].lower())

Cleans a section of the table of content of the model documentation (one specific modality) by removing duplicates
and sorting models alphabetically.

Args:
model_doc (`List[dict]`):
The list of dictionaries extracted from the `_toctree.yml` file for this specific modality.

Returns:
`List[dict]`: List of dictionaries like the input, but cleaned up and sorted.


def __init__(self, filepath):

    self._filepath = filepath
    self._subword_text_encoder = text_encoder.SubwordTextEncoder(filepath)

Create a T2tVocabulary.

Args:
filepath: a string


def _make_static_axis_non_negative_list(axis, ndims):

  axis = distribution_util.make_non_negative_axis(axis, ndims)

  axis_const = tf.get_static_value(axis)
  if axis_const is None:
    raise ValueError(
        'Expected argument `axis` to be statically available.  Found: %s' %
        axis)

  axis = axis_const + np.zeros([1], dtype=axis_const.dtype)

  return list(int(dim) for dim in axis)

Convert possibly negatively indexed axis to non-negative list of ints.

Args:
axis:  Integer Tensor.
ndims:  Number of dimensions into which axis indexes.

Returns:
A list of non-negative Python integers.

Raises:
ValueError: If `axis` is not statically defined.


def tokenize_sentence(input_dict):
    text, uid = (input_dict['text'], input_dict['id'])
    tokens = Tokenizer([text], padding=True, truncation=True, return_tensors='pt')
    tokens = {key: torch.squeeze(val) for key, val in tokens.items()}
    return ((text, uid), tokens)

It takes a dictionary with a text and an id, tokenizes the text, and
returns a tuple of the text and id and the tokenized text

Args:
input_dict: a dictionary with the text and id of the sentence

Returns:
A tuple of the text and id, and a dictionary of the tokens.


def dtime(sdat, tstart=None, tend=None):

    tseries = sdat.tseries_between(tstart, tend)
    time = tseries['t'].values
    return time[1:] - time[:-1], time[:-1]

Time increment dt.

Compute dt as a function of time.

Args:
sdat (:class:`~stagpy.stagyydata.StagyyData`): a StagyyData instance.
tstart (float): time at which the computation should start. Use the
beginning of the time series data if set to None.
tend (float): time at which the computation should end. Use the
end of the time series data if set to None.
Returns:
tuple of :class:`numpy.array`: dt and time arrays.


def play(self, **kwargs):

        path = '%s/%s/play' % (self.manager.path, self.get_id())
        self.manager.gitlab.http_post(path)

Trigger a job explicitly.

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

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabJobPlayError: If the job could not be triggered


def GetPredefinedFile(stubs_subdir, module, extension='.pytd', as_package=False):
    parts = module.split('.')
    if as_package:
        parts.append('__init__')
    mod_path = path_utils.join(*parts) + extension
    path = path_utils.join('stubs', stubs_subdir, mod_path)
    return (path, pytype_source_utils.load_text_file(path))

Get the contents of a predefined PyTD, typically with a file name *.pytd.

Arguments:
stubs_subdir: the directory, typically "builtins" or "stdlib"
module: module name (e.g., "sys" or "__builtins__")
extension: either ".pytd" or ".py"
as_package: try the module as a directory with an __init__ file

Returns:
The contents of the file
Raises:
IOError: if file not found


def add_whitespace_before(char, input_file, output_file):

    line_count = get_line_count(input_file)
    input_file = open(input_file, 'r')
    output_file = open(output_file, 'r+')
    for line in range(line_count):
        string = input_file.readline()

        if re.search(r'[a-zA-Z0-9]' + char, string) != None:
            string = re.sub(char, ' ' + char, string)
        output_file.write(string)
    input_file.close()

Adds a space before a character if there's isn't one already.

Args:
char: string, character that needs a space before it.

input_file: string, path to file to parse.

output_file: string, path to destination file.

Returns:
None.


def retrieve_from_web(generate_csv=False):
    url = 'https:
    source = urllib.request.urlopen(url)
    matches = []
    while True:
        line = source.readline()
        if '' in line:
            break
        else:
            gpu = re.search('([\\w\\S\\s\\d\\[\\]\\,]+[^*])(<a href=.*)?.*', line)
            capability = re.search('([\\d]+).([\\d]+)(/)?([\\d]+)?(.)?([\\d]+)?.*	.*', line)
            if gpu:
                matches.append(gpu.group(1))
            elif capability:
                if capability.group(3):
                    capability_str = capability.group(4) + '.' + capability.group(6)
                else:
                    capability_str = capability.group(1) + '.' + capability.group(2)
                matches.append(capability_str)
    return create_gpu_capa_map(matches, generate_csv)

Retrieves list of all CUDA compute capability from NVIDIA webpage.

Args:
generate_csv: Boolean for generating an output file containing
the results.

Returns:
OrderedDict that is a list of all CUDA compute capability listed on the
NVIDIA page. Order goes from top to bottom of the webpage content (.html).


def num_memory_zones(self):
    count = self._dll.JLINK_GetMemZones(0, 0)
    if (count < 0):
        raise errors.JLinkException(count)
    return count

Returns the number of memory zones supported by the target.

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

Returns:
An integer count of the number of memory zones supported by the
target.

Raises:
JLinkException: on error.


def gaussian_deriv(duration: int, amp: complex, sigma: float, name: str = None) -> SamplePulse:
    r
    center = duration/2
    return _sampled_gaussian_deriv_pulse(duration, amp, center, sigma, name=name)

r"""Generates unnormalized gaussian derivative `SamplePulse`.

Applies `left` sampling strategy to generate discrete pulse from continuous function.

Args:
duration: Duration of pulse. Must be greater than zero.
amp: Pulse amplitude at `center`.
sigma: Width (standard deviation) of pulse.
name: Name of pulse.


def install(self, package: str, option: str='-r') -> None:
    if (not os.path.isfile(package)):
        raise FileNotFoundError(f'{package!r} does not exist.')
    for i in option:
        if (i not in '-lrtsdg'):
            raise ValueError(f'There is no option named: {option!r}.')
    self._execute('-s', self.device_sn, 'install', option, package)

Push package to the device and install it.

Args:
option:
-l: forward lock application
-r: replace existing application
-t: allow test packages
-s: install application on sdcard
-d: allow version code downgrade (debuggable packages only)
-g: grant all runtime permissions


def get_slab_regions(slab, blength=3.5):

    fcoords, indices, all_indices = [], [], []
    for site in slab:

        neighbors = slab.get_neighbors(site, blength, include_index=True,
                                       include_image=True)
        for nn in neighbors:
            if nn[0].frac_coords[2] < 0:

                fcoords.append(nn[0].frac_coords[2])
                indices.append(nn[-2])
                if nn[-2] not in all_indices:
                    all_indices.append(nn[-2])

    if fcoords:

        while fcoords:
            last_fcoords = copy.copy(fcoords)
            last_indices = copy.copy(indices)
            site = slab[indices[fcoords.index(min(fcoords))]]
            neighbors = slab.get_neighbors(site, blength, include_index=True,
                                           include_image=True)
            fcoords, indices = [], []
            for nn in neighbors:
                if 1 > nn[0].frac_coords[2] > 0 and \
                                nn[0].frac_coords[2] < site.frac_coords[2]:

                    fcoords.append(nn[0].frac_coords[2])
                    indices.append(nn[-2])
                    if nn[-2] not in all_indices:
                        all_indices.append(nn[-2])

        upper_fcoords = []
        for site in slab:
            if all([nn[-1] not in all_indices for nn in
                    slab.get_neighbors(site, blength,
                                       include_index=True)]):
                upper_fcoords.append(site.frac_coords[2])
        coords = copy.copy(last_fcoords) if not fcoords else copy.copy(fcoords)
        min_top = slab[last_indices[coords.index(min(coords))]].frac_coords[2]
        ranges = [[0, max(upper_fcoords)], [min_top, 1]]
    else:

        sorted_sites = sorted(slab, key=lambda site: site.frac_coords[2])
        ranges = [[sorted_sites[0].frac_coords[2],
                   sorted_sites[-1].frac_coords[2]]]

    return ranges

Function to get the ranges of the slab regions. Useful for discerning where
the slab ends and vacuum begins if the slab is not fully within the cell
Args:
slab (Structure): Structure object modelling the surface
blength (float, Ang): The bondlength between atoms. You generally
want this value to be larger than the actual bondlengths in
order to find atoms that are part of the slab


def total_stored(self, wanted, slots=None):
    if (slots is None):
        slots = self.window.slots
    wanted = make_slot_check(wanted)
    return sum((slot.amount for slot in slots if wanted(slot)))

Calculates the total number of items of that type
in the current window or given slot range.

Args:
wanted: function(Slot) or Slot or itemID or (itemID, metadata)


class EnsembleAnomalyDetector(AnomalyDetector):

    def __init__(self, sub_detectors: Optional[list[AnomalyDetector]]=None, aggregation_strategy: Optional[AggregationFn]=None, **kwargs):
        if 'model_id' not in kwargs or kwargs['model_id'] is None:
            kwargs['model_id'] = getattr(self, 'spec_type', lambda: 'custom')()
        super().__init__(**kwargs)
        self._aggregation_strategy = aggregation_strategy
        self._sub_detectors = sub_detectors

    def learn_one(self, x: beam.Row) -> None:

        raise NotImplementedError

    def score_one(self, x: beam.Row) -> float:

        raise NotImplementedError

An abstract base class for an ensemble of anomaly (sub-)detectors.

Args:
sub_detectors: A list of `AnomalyDetector` used in this ensemble model.
aggregation_strategy: An optional `AggregationFn` to apply to the
predictions from all sub-detectors and yield an aggregated result.
model_id: Inherited from `AnomalyDetector`.
features: Inherited from `AnomalyDetector`.
target: Inherited from `AnomalyDetector`.
threshold_criterion: Inherited from `AnomalyDetector`.


def make_initializer(self, dataset, name=None):
    with ops.name_scope(name, 'make_initializer') as name:
        dataset_output_types = nest.map_structure(lambda component_spec: component_spec._to_legacy_output_types(), dataset.element_spec)
        dataset_output_shapes = nest.map_structure(lambda component_spec: component_spec._to_legacy_output_shapes(), dataset.element_spec)
        dataset_output_classes = nest.map_structure(lambda component_spec: component_spec._to_legacy_output_classes(), dataset.element_spec)
        nest.assert_same_structure(self.output_types, dataset_output_types)
        nest.assert_same_structure(self.output_shapes, dataset_output_shapes)
        for iterator_class, dataset_class in zip(nest.flatten(self.output_classes), nest.flatten(dataset_output_classes)):
            if iterator_class is not dataset_class:
                raise TypeError(f'Expected output classes {self.output_classes!r} but got dataset with output classes {dataset_output_classes!r}.')
        for iterator_dtype, dataset_dtype in zip(nest.flatten(self.output_types), nest.flatten(dataset_output_types)):
            if iterator_dtype != dataset_dtype:
                raise TypeError(f'Expected output types {self.output_types!r} but got dataset with output types {dataset_output_types!r}.')
        for iterator_shape, dataset_shape in zip(nest.flatten(self.output_shapes), nest.flatten(dataset_output_shapes)):
            if not iterator_shape.is_compatible_with(dataset_shape):
                raise TypeError(f'Expected output shapes compatible with {self.output_shapes!r} but got dataset with output shapes {dataset_output_shapes!r}.')
    with ops.colocate_with(self._iterator_resource):
        return gen_dataset_ops.make_iterator(dataset._variant_tensor, self._iterator_resource, name=name)

Returns a `tf.Operation` that initializes this iterator on `dataset`.

Args:
dataset: A `Dataset` whose `element_spec` if compatible with this
iterator.
name: (Optional.) A name for the created operation.

Returns:
A `tf.Operation` that can be run to initialize this iterator on the given
`dataset`.

Raises:
TypeError: If `dataset` and this iterator do not have a compatible
`element_spec`.


def train_auto_encoder(self, generative_model, a_logs_list):

        error_arr = generative_model.update()
        if error_arr.ndim > 1:
            error_arr = error_arr.mean()
        a_logs_list.append(error_arr)

        self.__logger.debug("The reconstruction error (mean): " + str(error_arr))

        return generative_model, a_logs_list

Train the generative model as the Auto-Encoder.

Args:
generative_model:   Generator which draws samples from the `fake` distribution.
a_logs_list:        `list` of the reconstruction errors.

Returns:
The tuple data. The shape is...
- Generator which draws samples from the `fake` distribution.
- `list` of the reconstruction errors.


def access_vlan(self, inter_type, inter, vlan_id):
    config = ET.Element('config')
    interface = ET.SubElement(config, 'interface', xmlns='urn:brocade.com:mgmt:brocade-interface')
    int_type = ET.SubElement(interface, inter_type)
    name = ET.SubElement(int_type, 'name')
    name.text = inter
    switchport = ET.SubElement(int_type, 'switchport')
    access = ET.SubElement(switchport, 'access')
    accessvlan = ET.SubElement(access, 'accessvlan')
    accessvlan.text = vlan_id
    try:
        self._callback(config)
        return True
    except Exception as error:
        logging.error(error)
        return False

Add a L2 Interface to a specific VLAN.

Args:
inter_type: The type of interface you want to configure. Ex.
tengigabitethernet, gigabitethernet, fortygigabitethernet.
inter: The ID for the interface you want to configure. Ex. 1/0/1
vlan_id: ID for the VLAN interface being modified. Value of 2-4096.

Returns:
True if command completes successfully or False if not.

Raises:
None


def get_user_display_name(self, userid):

        user_info = self.slack_client.api_call('users.info', user=userid)
        if user_info.get('ok'):
            user = user_info.get('user')
            if user.get('profile'):
                return user.get('profile').get('display_name')
            else:
                return user.get('name')
        else:
            return userid

Given a Slack userid, grabs user display_name from api.

Args:
userid (string): the user id of the user being queried
Returns:
dict: a dictionary of the api response


def _GenerateZipInfo(self, arcname=None, compress_type=None, st=None):

    if st is None:

      st = os.stat_result((0o100644, 0, 0, 0, 0, 0, 0, 0, 0, 0))

    mtime = time.localtime(st.st_mtime or time.time())
    date_time = mtime[0:6]

    if arcname is None:
      raise ValueError("An arcname must be provided.")

    zinfo = zipfile.ZipInfo(arcname, date_time)
    zinfo.external_attr = (st[0] & 0xFFFF) << 16

    if compress_type is None:
      zinfo.compress_type = self._compression
    else:
      zinfo.compress_type = compress_type

    zinfo.file_size = 0
    zinfo.compress_size = 0
    zinfo.flag_bits = 0x08
    zinfo.CRC = 0x08074b50

    zinfo.extra = struct.pack(
        "<HHIIHH",
        0x5855,
        12,
        0,
        0,
        0,
        0)
    return zinfo

Generate ZipInfo instance for the given name, compression and stat.

Args:
arcname: The name in the archive this should take.
compress_type: Compression type (zipfile.ZIP_DEFLATED, or ZIP_STORED)
st: An optional stat object to be used for setting headers.

Returns:
ZipInfo instance.

Raises:
ValueError: If arcname is not provided.


def get_conditional_uni(cls, left_parent, right_parent):
    (left, right, _) = cls._identify_eds_ing(left_parent, right_parent)
    left_u = (left_parent.U[0] if (left_parent.L == left) else left_parent.U[1])
    right_u = (right_parent.U[0] if (right_parent.L == right) else right_parent.U[1])
    return (left_u, right_u)

Identify pair univariate value from parents.

Args:
left_parent(Edge): left parent
right_parent(Edge): right parent

Returns:
tuple[np.ndarray, np.ndarray]: left and right parents univariate.


def minimum(x, y):
    return math_ops.minimum(x, y)

Element-wise minimum of two tensors.

Args:
x: Tensor or variable.
y: Tensor or variable.

Returns:
A tensor.


def delete(name, **kwargs):

    if info(name):
        comp_obj = _get_computer_object()
        try:
            comp_obj.Delete('group', name)
            log.info('Successfully removed group %s', name)
        except pywintypes.com_error as exc:
            msg = 'Failed to remove group {0}. {1}'.format(
                name, win32api.FormatMessage(exc.excepinfo[5]))
            log.error(msg)
            return False
    else:
        log.warning('The group %s does not exists.', name)
        return False

    return True

Remove the named group

Args:

name (str):
The name of the group to remove

Returns:
bool: ``True`` if successful, otherwise ``False``

CLI Example:

.. code-block:: bash

salt '*' group.delete foo


def get_recurrent_dropout_mask_for_cell(self, inputs, training, count=1):
    if self.recurrent_dropout == 0:
        return None
    init_kwargs = dict(inputs=inputs, training=training, count=count)
    return self._recurrent_dropout_mask_cache.setdefault(kwargs=init_kwargs)

Get the recurrent dropout mask for RNN cell.

It will create mask based on context if there isn't any existing cached
mask. If a new mask is generated, it will update the cache in the cell.

Args:
inputs: The input tensor whose shape will be used to generate dropout
mask.
training: Boolean tensor, whether its in training mode, dropout will be
ignored in non-training mode.
count: Int, how many dropout mask will be generated. It is useful for cell
that has internal weights fused together.
Returns:
List of mask tensor, generated or cached mask based on context.


def _find_config(self):
    for search_path in self.config_paths:
        for ext in self._fmt_to_ext.get(self.config_format):
            path = os.path.abspath(os.path.join(search_path, (self.config_name + ext)))
            if os.path.isfile(path):
                self.config_file = path
                return
    raise BisonError('No file named {} found in search paths {}'.format(self.config_name, self.config_paths))

Searches through the configured `config_paths` for the `config_name`
file.

If there are no `config_paths` defined, this will raise an error, so the
caller should take care to check the value of `config_paths` first.

Returns:
str: The fully qualified path to the configuration that was found.

Raises:
Exception: No paths are defined in `config_paths` or no file with
the `config_name` was found in any of the specified `config_paths`.


def version(self):
    version = int(self._dll.JLINKARM_GetDLLVersion())
    major = (version / 10000)
    minor = ((version / 100) % 100)
    rev = (version % 100)
    rev = ('' if (rev == 0) else chr(((rev + ord('a')) - 1)))
    return ('%d.%02d%s' % (major, minor, rev))

Returns the device's version.

The device's version is returned as a string of the format: M.mr where
``M`` is major number, ``m`` is minor number, and ``r`` is revision
character.

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

Returns:
Device version string.


def __init__(self, api_key: str, config: interfaces.Config=interfaces.Config()) -> None:
    self._config = config
    p_topic_generator = topic_generator.TopicGenerator(api_key=api_key, config=config)
    p_topic_researcher = topic_researcher.TopicResearcher(api_key=api_key, config=config)
    p_topic_verbalizer = topic_verbalizer.TopicVerbalizer(config=config)
    p_genai_model = genai_model.GenaiModel(api_key=api_key, model_name=self._config.research_synthesizer_model_name)
    p_preamble = preamble.Preamble(content=[ProcessorPart(prompts.SYNTHESIS_PREAMBLE), ProcessorPart('Research text: ')])
    p_suffix = preamble.Suffix(content=[ProcessorPart('Your synthesized research: ')])
    self._pipeline = p_topic_generator + p_topic_researcher + p_topic_verbalizer + p_preamble + p_suffix + p_genai_model

Initializes the Research Agent.

Args:
api_key: The API key to use for the GenAI API.
config: The configuration for the Research Agent.


def delete_submission(self, submission_id):

        LOG.info("Deleting clinvar submission %s", submission_id)
        submission_obj = self.clinvar_submission_collection.find_one({ '_id' : ObjectId(submission_id)})

        submission_variants = submission_obj.get('variant_data')
        submission_casedata = submission_obj.get('case_data')

        submission_objects = []

        if submission_variants and submission_casedata:
            submission_objects = submission_variants + submission_casedata
        elif submission_variants:
            submission_objects = submission_variants
        elif submission_casedata:
            submission_objects = submission_casedata

        result = self.clinvar_collection.delete_many({'_id': { "$in": submission_objects} })
        deleted_objects = result.deleted_count

        result = self.clinvar_submission_collection.delete_one({'_id': ObjectId(submission_id)})
        deleted_submissions = result.deleted_count

        return deleted_objects,deleted_submissions

Deletes a Clinvar submission object, along with all associated clinvar objects (variants and casedata)

Args:
submission_id(str): the ID of the submission to be deleted

Returns:
deleted_objects(int): the number of associated objects removed (variants and/or casedata)
deleted_submissions(int): 1 if it's deleted, 0 if something went wrong


def append_column(table, col_name, default_value=None):

    table[0].append(col_name.strip())
    for row in table[1:]:
        row.append(default_value)

Appends a column to the raw data without any integrity checks.

Args:
default_value: The value which will assigned, not copied into each row


def resolve_for(self, node):

        self.node = node
        self.actual_text = normalize_text(
            node.visible_text if self.query_type == "visible" else node.all_text)
        self.count = len(re.findall(self.search_regexp, self.actual_text))

        return self.count

Resolves this query relative to the given node.

Args:
node (node.Base): The node to be evaluated.

Returns:
int: The number of matches found.


def add_evaluation_step(result_tensor, ground_truth_tensor):

  with tf.name_scope('accuracy'):
    with tf.name_scope('correct_prediction'):
      prediction = tf.argmax(result_tensor, 1)
      correct_prediction = tf.equal(prediction, ground_truth_tensor)
    with tf.name_scope('accuracy'):
      evaluation_step = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  tf.summary.scalar('accuracy', evaluation_step)
  return evaluation_step, prediction

Inserts the operations we need to evaluate the accuracy of our results.

Args:
result_tensor: The new final node that produces results.
ground_truth_tensor: The node we feed ground truth data
into.

Returns:
Tuple of (evaluation step, prediction).


def cast_to_str(obj):
    if isinstance(obj, str):
        return obj
    if isinstance(obj, Seq):
        return str(obj)
    if isinstance(obj, SeqRecord):
        return str(obj.seq)
    else:
        raise ValueError('Must provide a string, Seq, or SeqRecord object.')

Return a string representation of a Seq or SeqRecord.

Args:
obj (str, Seq, SeqRecord): Biopython Seq or SeqRecord

Returns:
str: String representation of the sequence


async def apply(self, sender: str, recipient: str, mailbox: str,
                    append_msg: AppendMessage) \
            -> Tuple[Optional[str], AppendMessage]:

        ...

Run the filter and return the mailbox where it should be appended,
or None to discard, and the message to be appended, which is usually
the same as ``append_msg``.

Args:
sender: The envelope sender of the message.
recipient: The envelope recipient of the message.
mailbox: The intended mailbox to append the message.
append_msg: The message to be appended.

raises:
:exc:`~pymap.exceptions.AppendFailure`


def laplacian_pyramid_image(shape, n_levels=4, sd=None):

    batch_dims = shape[:-3]
    w, h, ch = shape[-3:]
    pyramid = 0
    for n in range(n_levels):
        k = 2 ** n
        pyramid += lowres_tensor(shape, batch_dims + (w
    return pyramid

Simple laplacian pyramid paramaterization of an image.

For more flexibility, use a sum of lowres_tensor()s.

Args:
shape: shape of resulting image, [batch, width, height, channels].
n_levels: number of levels of laplacian pyarmid.
sd: standard deviation of param initialization.

Returns:
tensor with shape from first argument.


def returns(desc=None, printer=None, data=True):
    if (data is False):
        raise ArgumentError('Specifying non data return type in returns is no longer supported')

    def _returns(func):
        annotated(func)
        func.custom_returnvalue(printer, desc)
        return func
    return _returns

Specify how the return value of this function should be handled.

Args:
desc (str): A deprecated description of the return value
printer (callable): A callable function that can format this return value
data (bool): A deprecated parameter for specifying that this function
returns data.


def experimental_distribute_dataset(self, dataset, options=None):
    return super(OneDeviceStrategy, self).experimental_distribute_dataset(dataset, options)

Distributes a tf.data.Dataset instance provided via dataset.

In this case, there is only one device, so this is only a thin wrapper
around the input dataset. It will, however, prefetch the input data to the
specified device. The returned distributed dataset can be iterated over
similar to how regular datasets can.

NOTE: Currently, the user cannot add any more transformations to a
distributed dataset.

Example:
```
strategy = tf.distribute.OneDeviceStrategy()
dataset = tf.data.Dataset.range(10).batch(2)
dist_dataset = strategy.experimental_distribute_dataset(dataset)
for x in dist_dataset:
print(x)  # [0, 1], [2, 3],...
```
Args:
dataset: `tf.data.Dataset` to be prefetched to device.
options: `tf.distribute.InputOptions` used to control options on how this
dataset is distributed.
Returns:
A "distributed `Dataset`" that the caller can iterate over.


def _to_df(self, result, handle_annotations=None):

        annotations = result._data
        if handle_annotations == 'first':
            annotations = [annotations[0]]

        face_results = []
        for i, annotation in enumerate(annotations):
            data_dict = {}
            for field, val in annotation.items():
                if 'Confidence' in field:
                    data_dict['face_' + field] = val
                elif 'oundingPoly' in field:
                    for j, vertex in enumerate(val['vertices']):
                        for dim in ['x', 'y']:
                            name = '%s_vertex%d_%s' % (field, j+1, dim)
                            val = vertex[dim] if dim in vertex else np.nan
                            data_dict[name] = val
                elif field == 'landmarks':
                    for lm in val:
                        name = 'landmark_' + lm['type'] + '_%s'
                        lm_pos = {name %
                                  k: v for (k, v) in lm['position'].items()}
                        data_dict.update(lm_pos)
                else:
                    data_dict[field] = val

            face_results.append(data_dict)

        return pd.DataFrame(face_results)

Converts a Google API Face JSON response into a Pandas Dataframe.

Args:
result (ExtractorResult): Result object from which to parse out a
Dataframe.
handle_annotations (str): How returned face annotations should be
handled in cases where there are multiple faces.
'first' indicates to only use the first face JSON object, all
other values will default to including every face.


def std_dev(self, value):

        if value == self._defaults['stdDev'] and 'stdDev' in self._values:
            del self._values['stdDev']
        else:
            self._values['stdDev'] = value

The std_dev property.

Args:
value (float). the property value.


def docx_process_simple_text(text: str, width: int) -> str:
    if width:
        return '\n'.join(textwrap.wrap(text, width=width))
    else:
        return text

Word-wraps text.

Args:
text: text to process
width: width to word-wrap to (or 0 to skip word wrapping)

Returns:
wrapped text


def _find_address_values_in_chain(self, base_contexts, addresses_to_find):

        contexts_in_chain = deque()
        contexts_in_chain.extend(base_contexts)
        reads = list(addresses_to_find)
        address_values = []
        context_ids_already_searched = []
        context_ids_already_searched.extend(base_contexts)

        while reads:
            try:
                current_c_id = contexts_in_chain.popleft()
            except IndexError:

                break
            current_context = self._contexts[current_c_id]

            deleted_addresses = current_context.get_if_deleted(reads)
            for address in deleted_addresses:
                if address is not None:
                    address_values.append((address, None))

            reads = list(set(reads) - set(deleted_addresses))

            values = current_context.get_if_set(reads)
            addresses_not_found = []
            for address, value in zip(reads, values):
                if value is not None:
                    address_values.append((address, value))
                else:
                    addresses_not_found.append(address)
            reads = addresses_not_found

            addresses_in_inputs = [address for address in reads
                                   if address in current_context]

            values = current_context.get_if_not_set(addresses_in_inputs)

            address_values.extend(list(zip(addresses_in_inputs, values)))

            for add in addresses_in_inputs:
                reads.remove(add)

            for c_id in current_context.base_contexts:
                if c_id not in context_ids_already_searched:
                    contexts_in_chain.append(c_id)
                    context_ids_already_searched.append(c_id)

        return address_values, reads

Breadth first search through the chain of contexts searching for
the bytes values at the addresses in addresses_to_find.

Args:
base_contexts (list of str): The context ids to start with.
addresses_to_find (list of str): Addresses to find values in the
chain of contexts.

Returns:
tuple of found address_values and still not found addresses


def scale(self, width: int, height: int) -> None:

        lib.TCOD_image_scale(self.image_c, width, height)
        self.width, self.height = width, height

Scale this Image to the new width and height.

Args:
width (int): The new width of the Image after scaling.
height (int): The new height of the Image after scaling.


def _update_context_field_binary_composition(present_locations, expression):

    if not any((isinstance(expression.left, ContextField),
                isinstance(expression.right, ContextField))):
        raise AssertionError(u'Received a BinaryComposition {} without any ContextField '
                             u'operands. This should never happen.'.format(expression))

    if isinstance(expression.left, ContextField):
        context_field = expression.left
        location_name, _ = context_field.location.get_location_name()
        if location_name not in present_locations:
            return TrueLiteral

    if isinstance(expression.right, ContextField):
        context_field = expression.right
        location_name, _ = context_field.location.get_location_name()
        if location_name not in present_locations:
            return TrueLiteral

    return expression

Lower BinaryCompositions involving non-existent ContextFields to True.

Args:
present_locations: set of all locations in the current MatchQuery that have not been pruned
expression: BinaryComposition with at least one ContextField operand

Returns:
TrueLiteral iff either ContextField operand is not in `present_locations`,
and the original expression otherwise


def _distro_release_info(self):
    if self.distro_release_file:
        distro_info = self._parse_distro_release_file(self.distro_release_file)
        basename = os.path.basename(self.distro_release_file)
        match = _DISTRO_RELEASE_BASENAME_PATTERN.match(basename)
        if match:
            distro_info['id'] = match.group(1)
        return distro_info
    else:
        try:
            basenames = os.listdir(_UNIXCONFDIR)
            basenames.sort()
        except OSError:
            basenames = ['SuSE-release', 'arch-release', 'base-release', 'centos-release', 'fedora-release', 'gentoo-release', 'mageia-release', 'mandrake-release', 'mandriva-release', 'mandrivalinux-release', 'manjaro-release', 'oracle-release', 'redhat-release', 'sl-release', 'slackware-version']
        for basename in basenames:
            if (basename in _DISTRO_RELEASE_IGNORE_BASENAMES):
                continue
            match = _DISTRO_RELEASE_BASENAME_PATTERN.match(basename)
            if match:
                filepath = os.path.join(_UNIXCONFDIR, basename)
                distro_info = self._parse_distro_release_file(filepath)
                if ('name' in distro_info):
                    self.distro_release_file = filepath
                    distro_info['id'] = match.group(1)
                    return distro_info
        return {}

Get the information items from the specified distro release file.

Returns:
A dictionary containing all information items.


def _check_property(self, rest=None, require_indexed=True):

    if require_indexed and not self._indexed:
      raise InvalidPropertyError('Property is unindexed %s' % self._name)
    if rest:
      raise InvalidPropertyError('Referencing subproperty %s.%s '
                                 'but %s is not a structured property' %
                                 (self._name, rest, self._name))

Internal helper to check this property for specific requirements.

Called by Model._check_properties().

Args:
rest: Optional subproperty to check, of the form 'name1.name2...nameN'.

Raises:
InvalidPropertyError if this property does not meet the given
requirements or if a subproperty is specified.  (StructuredProperty
overrides this method to handle subproperties.)


def get_organization(self, **kwargs):
    resp = self._get(self._u(self._ORGANIZATION_ENDPOINT_SUFFIX), **kwargs)
    resp.raise_for_status()
    return resp.json()

Get the organization to which the user belongs

Returns:
dictionary of the response


def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
    super(EncryptResponsePayload, self).read(input_stream, kmip_version=kmip_version)
    local_stream = utils.BytearrayStream(input_stream.read(self.length))
    if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
        self._unique_identifier = primitives.TextString(tag=enums.Tags.UNIQUE_IDENTIFIER)
        self._unique_identifier.read(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('invalid payload missing the unique identifier attribute')
    if self.is_tag_next(enums.Tags.DATA, local_stream):
        self._data = primitives.ByteString(tag=enums.Tags.DATA)
        self._data.read(local_stream, kmip_version=kmip_version)
    else:
        raise ValueError('invalid payload missing the data attribute')
    if self.is_tag_next(enums.Tags.IV_COUNTER_NONCE, local_stream):
        self._iv_counter_nonce = primitives.ByteString(tag=enums.Tags.IV_COUNTER_NONCE)
        self._iv_counter_nonce.read(local_stream, kmip_version=kmip_version)
    self.is_oversized(local_stream)

Read the data encoding the Encrypt response payload and decode it
into its constituent parts.

Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.

Raises:
ValueError: Raised if the unique_identifier or data attributes
are missing from the encoded payload.


def SmartSet(self, obj, attr_name, new_attr):
    _, obj = tf_decorator.unwrap(obj)
    if tf_inspect.ismodule(obj) or (not tf_inspect.isclass(obj) and attr_name in obj.__dict__):
        orig_obj = obj
        orig_attr = getattr(obj, attr_name)
    else:
        if not tf_inspect.isclass(obj):
            mro = list(tf_inspect.getmro(obj.__class__))
        else:
            mro = list(tf_inspect.getmro(obj))
        mro.reverse()
        orig_attr = None
        found_attr = False
        for cls in mro:
            try:
                orig_obj = cls
                orig_attr = getattr(obj, attr_name)
                found_attr = True
            except AttributeError:
                continue
        if not found_attr:
            raise AttributeError('Attribute not found.')
    old_attribute = obj.__dict__.get(attr_name)
    if old_attribute is not None and isinstance(old_attribute, staticmethod):
        orig_attr = staticmethod(orig_attr)
    self.stubs.append((orig_obj, attr_name, orig_attr))
    setattr(orig_obj, attr_name, new_attr)

Replace obj.attr_name with new_attr.

This method is smart and works at the module, class, and instance level
while preserving proper inheritance. It will not stub out C types however
unless that has been explicitly allowed by the type.

This method supports the case where attr_name is a staticmethod or a
classmethod of obj.

Notes:
- If obj is an instance, then it is its class that will actually be
stubbed. Note that the method Set() does not do that: if obj is
an instance, it (and not its class) will be stubbed.
- The stubbing is using the builtin getattr and setattr. So, the __get__
and __set__ will be called when stubbing (TODO: A better idea would
probably be to manipulate obj.__dict__ instead of getattr() and
setattr()).

Args:
obj: The object whose attributes we want to modify.
attr_name: The name of the attribute to modify.
new_attr: The new value for the attribute.

Raises:
AttributeError: If the attribute cannot be found.


def rvs(self, size=1):

        return np.random.multivariate_normal(self.mean, self.cov, size)

Convenience method to sample from this distribution.

Args:
size (int or tuple): Shape of return value. Each element is drawn
independently from this distribution.


def GetArtifactKnowledgeBase(client_obj, allow_uninitialized=False):
    client_schema = client_obj.Schema
    kb = client_obj.Get(client_schema.KNOWLEDGE_BASE)
    if (not allow_uninitialized):
        if (not kb):
            raise artifact_utils.KnowledgeBaseUninitializedError(('KnowledgeBase empty for %s.' % client_obj.urn))
        if (not kb.os):
            raise artifact_utils.KnowledgeBaseAttributesMissingError(('KnowledgeBase missing OS for %s. Knowledgebase content: %s' % (client_obj.urn, kb)))
    if (not kb):
        kb = client_schema.KNOWLEDGE_BASE()
        SetCoreGRRKnowledgeBaseValues(kb, client_obj)
    if (kb.os == 'Windows'):
        if ((not kb.environ_allusersappdata) and kb.environ_allusersprofile):
            if (kb.os_major_version >= 6):
                kb.environ_allusersappdata = u'c:\\programdata'
                kb.environ_allusersprofile = u'c:\\programdata'
            else:
                kb.environ_allusersappdata = u'c:\\documents and settings\\All Users\\Application Data'
                kb.environ_allusersprofile = u'c:\\documents and settings\\All Users'
    return kb

This generates an artifact knowledge base from a GRR client.

Args:
client_obj: A GRRClient object which is opened for reading.
allow_uninitialized: If True we accept an uninitialized knowledge_base.

Returns:
A KnowledgeBase semantic value.

Raises:
ArtifactProcessingError: If called when the knowledge base has not been
initialized.
KnowledgeBaseUninitializedError: If we failed to initialize the knowledge
base.

This is needed so that the artifact library has a standardized
interface to the data that is actually stored in the GRRClient object in
the GRR datastore.

We expect that the client KNOWLEDGE_BASE is already filled out through the,
KnowledgeBaseInitialization flow, but attempt to make some intelligent
guesses if things failed.


def swo_speed_info(self):

        info = structs.JLinkSWOSpeedInfo()
        res = self._dll.JLINKARM_SWO_Control(enums.JLinkSWOCommands.GET_SPEED_INFO,
                                             ctypes.byref(info))
        if res < 0:
            raise errors.JLinkException(res)

        return info

Retrieves information about the supported SWO speeds.

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

Returns:
A ``JLinkSWOSpeedInfo`` instance describing the target's supported
SWO speeds.

Raises:
JLinkException: on error


def from_spec(cls, spec):
    dtype = dtypes.as_dtype(spec.dtype)
    minimum = getattr(spec, 'minimum', dtype.min)
    maximum = getattr(spec, 'maximum', dtype.max)
    return BoundedTensorSpec(spec.shape, dtype, minimum, maximum, spec.name)

Returns a `TensorSpec` with the same shape and dtype as `spec`.

If `spec` is a `BoundedTensorSpec`, then the new spec's bounds are set to
`spec.minimum` and `spec.maximum`; otherwise, the bounds are set to
`spec.dtype.min` and `spec.dtype.max`.

>>> spec = tf.TensorSpec(shape=[8, 3], dtype=tf.int32, name="x")
>>> BoundedTensorSpec.from_spec(spec)
BoundedTensorSpec(shape=(8, 3), dtype=tf.int32, name='x',
minimum=array(-2147483648, dtype=int32),
maximum=array(2147483647, dtype=int32))

Args:
spec: The `TypeSpec` used to create the new `BoundedTensorSpec`.


def _GatherReturnElements(requested_return_elements, graph, results):
    return_outputs = c_api.TF_ImportGraphDefResultsReturnOutputs(results)
    return_opers = c_api.TF_ImportGraphDefResultsReturnOperations(results)
    combined_return_elements = []
    outputs_idx = 0
    opers_idx = 0
    for name in requested_return_elements:
        if ':' in name:
            combined_return_elements.append(graph._get_tensor_by_tf_output(return_outputs[outputs_idx]))
            outputs_idx += 1
        else:
            combined_return_elements.append(graph._get_operation_by_tf_operation(return_opers[opers_idx]))
            opers_idx += 1
    return combined_return_elements

Returns the requested return elements from results.

Args:
requested_return_elements: list of strings of operation and tensor names
graph: Graph
results: wrapped TF_ImportGraphDefResults

Returns:
list of `Operation` and/or `Tensor` objects


def merge_ids(self, token, channel, ids, delete=False):

        url = self.url() + "/merge/{}/".format(','.join([str(i) for i in ids]))
        req = self.remote_utils.get_url(url)
        if req.status_code is not 200:
            raise RemoteDataUploadError('Could not merge ids {}'.format(
                                        ','.join([str(i) for i in ids])))
        if delete:
            self.delete_ramon(token, channel, ids[1:])
        return True

Call the restful endpoint to merge two RAMON objects into one.

Arguments:
token (str): The token to inspect
channel (str): The channel to inspect
ids (int[]): the list of the IDs to merge
delete (bool : False): Whether to delete after merging.

Returns:
json: The ID as returned by ndstore


def notify_changes(self, changes):

        ret = []
        child_changes = {}
        for change in changes:

            self._add_child_change(change, child_changes)

        if self.update_requests:
            serialized = serialize_object(self.data)
            for request in self.update_requests:
                ret.append(request.update_response(serialized))

        if self.delta_requests:
            for change in changes:
                change[-1] = serialize_object(change[-1])
            for request in self.delta_requests:
                ret.append(request.delta_response(changes))

        for name, child_changes in child_changes.items():
            ret += self.children[name].notify_changes(child_changes)
        return ret

Set our data and notify anyone listening

Args:
changes (list): [[path, optional data]] where path is the path to
what has changed, and data is the unserialized object that has
changed

Returns:
list: [(callback, Response)] that need to be called


def check_version_2(dataset):
    if ((float(dataset.get('version')) >= 2.0) if dataset.get('version') else False):
        return True
    else:
        return False

Checks if json-stat version attribute exists and is equal or greater \
than 2.0 for a given dataset.

Args:
dataset (OrderedDict): data in JSON-stat format, previously \
deserialized to a python object by \
json.load() or json.loads(),

Returns:
bool: True if version exists and is equal or greater than 2.0, \
False otherwise. For datasets without the version attribute, \
always return False.


def writeline(self, line=b'', sep=b'\n', echo=None):

        self.writelines([line], sep, echo)

Write a byte sequences to the channel and terminate it with carriage
return and line feed.

Args:
line(bytes): The line to send.
sep(bytes): The separator to use after each line.
echo(bool): Whether to echo the written data to stdout.

Raises:
EOFError: If the channel was closed before all data was sent.


def get_tabular_stream(self, url, **kwargs):
    self.close_response()
    file_type = kwargs.get('file_type')
    if (file_type is not None):
        kwargs['format'] = file_type
        del kwargs['file_type']
    try:
        self.response = tabulator.Stream(url, **kwargs)
        self.response.open()
        return self.response
    except TabulatorException as e:
        raisefrom(DownloadError, ('Getting tabular stream for %s failed!' % url), e)

Get Tabulator stream.

Args:
url (str): URL to download
**kwargs:
headers (Union[int, List[int], List[str]]): Number of row(s) containing headers or list of headers
file_type (Optional[str]): Type of file. Defaults to inferring.
delimiter (Optional[str]): Delimiter used for values in each row. Defaults to inferring.

Returns:
tabulator.Stream: Tabulator Stream object


def _GetProcessedStorageFilePath(self, task):

    filename = '{0:s}.plaso'.format(task.identifier)
    return os.path.join(self._processed_task_storage_path, filename)

Retrieves the path of a task storage file in the processed directory.

Args:
task (Task): task.

Returns:
str: path of a task storage file in the processed directory.


def get_vocabulary(preprocess_output_dir, name):

  vocab_file = os.path.join(preprocess_output_dir, CATEGORICAL_ANALYSIS % name)
  if not file_io.file_exists(vocab_file):
    raise ValueError('File %s not found in %s' %
                     (CATEGORICAL_ANALYSIS % name, preprocess_output_dir))

  labels = python_portable_string(
      file_io.read_file_to_string(vocab_file)).split('\n')
  label_values = [x for x in labels if x]

  return label_values

Loads the vocabulary file as a list of strings.

Args:
preprocess_output_dir: Should contain the file CATEGORICAL_ANALYSIS % name.
name: name of the csv column.

Returns:
List of strings.

Raises:
ValueError: if file is missing.


def load_tensor_from_event_file(event_file_path):
    event = event_pb2.Event()
    with gfile.Open(event_file_path, 'rb') as f:
        event.ParseFromString(f.read())
        return load_tensor_from_event(event)

Load a tensor from an event file.

Assumes that the event file contains a `Event` protobuf and the `Event`
protobuf contains a `Tensor` value.

Args:
event_file_path: (`str`) path to the event file.

Returns:
The tensor value loaded from the event file, as a `numpy.ndarray`. For
uninitialized Tensors, returns `None`. For Tensors of data types that
cannot be converted to `numpy.ndarray` (e.g., `tf.resource`), return
`None`.


def unescape(inp, quote='"'):
    if (len(inp) < 2):
        return inp
    output = ''
    unesc = False
    for act in inp:
        if ((act == quote) and unesc):
            output = output[:(- 1)]
        output += act
        if (act == '\\'):
            unesc = (not unesc)
        else:
            unesc = False
    return output

Unescape `quote` in string `inp`.

Example usage::

>> unescape('hello \\"')
'hello "'

Args:
inp (str): String in which `quote` will be unescaped.
quote (char, default "): Specify which character will be unescaped.

Returns:
str: Unescaped string.


def __init__(self, string_table):
    self._string_table = string_table
    self._node_name_to_sample = {}

Constructor.

Args:
string_table: A `StringTable` object.


def get_dense_tensor(self, transformation_cache, state_manager):
    if isinstance(self.categorical_column, SequenceCategoricalColumn):
        raise ValueError('In indicator_column: {}. categorical_column must not be of type SequenceCategoricalColumn. Suggested fix A: If you wish to use DenseFeatures, use a non-sequence categorical_column_with_*. Suggested fix B: If you wish to create sequence input, use SequenceFeatures instead of DenseFeatures. Given (type {}): {}'.format(self.name, type(self.categorical_column), self.categorical_column))
    return transformation_cache.get(self, state_manager)

Returns dense `Tensor` representing feature.

Args:
transformation_cache: A `FeatureTransformationCache` object to access
features.
state_manager: A `StateManager` to create / access resources such as
lookup tables.

Returns:
Dense `Tensor` created within `transform_feature`.

Raises:
ValueError: If `categorical_column` is a `SequenceCategoricalColumn`.


def __init__(self, columns: list[str]) -> None:
    super().__init__(columns)
    if not columns:
        raise RuntimeError('Columns are not specified. Please specify the column for the  op %s' % self.__class__.__name__)

Base Operation class for TFT data processing transformations.
Processing logic for the transformation is defined in the
apply_transform() method. If you have a custom transformation that is not
supported by the existing transforms, you can extend this class
and implement the apply_transform() method.
Args:
columns: List of column names to apply the transformation.


A function that is executed upon a test failure.

User implementation is optional.

Args:
record: records.TestResultRecord, a copy of the test record for
this test, containing all information of the test execution
including exception objects.


def near(point, dist, points):

    for cmpt in points:
        if haversine(point, cmpt) <= dist:
            return True
    return False

Determine if the given point is within dist of any of points.

Args:
point ((float,float)): A latitude, longitude float tuple.
dist (int): A distance in mm ( base units )
points (list): A list of latitude, longitude float tuples to compare against.


def ProcessBlocks(self, block_limit=1000):
    self._lock.acquire()
    try:
        blockcount = 0
        while ((self._current_height <= Blockchain.Default().Height) and ((block_limit == 0) or (blockcount < block_limit))):
            block = Blockchain.Default().GetBlockByHeight(self._current_height)
            if (block is not None):
                self.ProcessNewBlock(block)
            else:
                self._current_height += 1
            blockcount += 1
        self.SaveStoredData('Height', self._current_height)
    except Exception as e:
        logger.warn(('Could not process ::: %s ' % e))
    finally:
        self._lock.release()

Method called on a loop to check the current height of the blockchain.  If the height of the blockchain
is more than the current stored height in the wallet, we get the next block in line and
processes it.

In the case that the wallet height is far behind the height of the blockchain, we do this 1000
blocks at a time.

Args:
block_limit (int): the number of blocks to process synchronously. defaults to 1000. set to 0 to block until the wallet is fully rebuilt.


def predict_proba(self, X):
    return collections.deque(self.iter_predict_proba(X), maxlen=1).pop()

Returns the predicted probabilities for ``X``.

Arguments:
X (array-like or sparse matrix of shape (n_samples, n_features)): The input samples.
Sparse matrices are accepted only if they are supported by the weak model.

Returns:
array of shape (n_samples, n_classes) containing the predicted probabilities.


def setup(self,
            hosts, files, use_tsk,
            reason, grr_server_url, grr_username, grr_password, approvers=None,
            verify=True):

    super(GRRFileCollector, self).setup(
        reason, grr_server_url, grr_username, grr_password,
        approvers=approvers, verify=verify)

    if files is not None:
      self.files = [item.strip() for item in files.strip().split(',')]

    self.hostnames = [item.strip() for item in hosts.strip().split(',')]
    self.use_tsk = use_tsk

Initializes a GRR file collector.

Args:
hosts: Comma-separated list of hostnames to launch the flow on.
files: list of file paths.
use_tsk: toggle for use_tsk flag on GRR flow.
reason: justification for GRR access.
grr_server_url: GRR server URL.
grr_username: GRR username.
grr_password: GRR password.
approvers: list of GRR approval recipients.
verify: boolean, whether to verify the GRR server's x509 certificate.


def __init__( self, max_r, number_of_bins ):

        self.max_r = max_r
        self.number_of_bins = number_of_bins
        self.data = np.zeros( number_of_bins )
        self.dr = max_r / number_of_bins

Initialise a Rdf object for manipulating radial distribution functions.

Args:
max_r (Float): the maximum r value stored for g(r).
number_of_bins (Int): number of bins for storing data about g(r).

Returns:
None


def __init__(self, pb_class_from: Type[FROM], pb_class_to: Type[TO], field_names_to_ignore: Optional[List[str]]=None):
    if field_names_to_ignore is None:
        field_names_to_ignore = []
    self._pb_class_from = pb_class_from
    self._pb_class_to = pb_class_to
    self._field_names_to_ignore = field_names_to_ignore
    self._function_convert_field_names = []
    self._convert_functions = []
    self._assert_all_fields_are_handled()

Constructor for the ProtoConverter.

Args:
pb_class_from: the init method for the proto to convert from.
pb_class_to: the init method for the proto to convert to.
field_names_to_ignore: the fields from the source proto that will be
ignored by the converter.

Returns:
ProtoConverter

Raise:
NotImplementedError: When creating the proto converter if there are
fields not handled or ignored.


def ParsePageVisitRow(self, parser_mediator, query, row, **unused_kwargs):
    query_hash = hash(query)
    was_http_non_get = self._GetRowValue(query_hash, row, 'http_non_get')
    event_data = SafariHistoryPageVisitedEventData()
    event_data.offset = self._GetRowValue(query_hash, row, 'id')
    event_data.query = query
    event_data.title = self._GetRowValue(query_hash, row, 'title')
    event_data.url = self._GetRowValue(query_hash, row, 'url')
    event_data.visit_count = self._GetRowValue(query_hash, row, 'visit_count')
    event_data.was_http_non_get = bool(was_http_non_get)
    timestamp = self._GetRowValue(query_hash, row, 'visit_time')
    date_time = dfdatetime_cocoa_time.CocoaTime(timestamp=timestamp)
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_LAST_VISITED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a visited 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 ScanSource(self, source_path):

    if os.path.islink(source_path):
      source_path = os.path.realpath(source_path)

    if (not source_path.startswith('\\\\.\\') and
        not os.path.exists(source_path)):
      raise errors.SourceScannerError(
          'No such device, file or directory: {0:s}.'.format(source_path))

    scan_context = source_scanner.SourceScannerContext()
    scan_context.OpenSourcePath(source_path)

    try:
      self._source_scanner.Scan(scan_context)
    except (ValueError, dfvfs_errors.BackEndError) as exception:
      raise errors.SourceScannerError(
          'Unable to scan source with error: {0!s}.'.format(exception))

    if scan_context.source_type not in (
        scan_context.SOURCE_TYPE_STORAGE_MEDIA_DEVICE,
        scan_context.SOURCE_TYPE_STORAGE_MEDIA_IMAGE):
      scan_node = scan_context.GetRootScanNode()
      self._source_path_specs.append(scan_node.path_spec)
      return scan_context

    scan_node = scan_context.GetRootScanNode()
    while len(scan_node.sub_nodes) == 1:
      scan_node = scan_node.sub_nodes[0]

    base_path_specs = []
    if scan_node.type_indicator != (
        dfvfs_definitions.TYPE_INDICATOR_TSK_PARTITION):
      self._ScanVolume(scan_context, scan_node, base_path_specs)

    else:

      partition_identifiers = self._GetTSKPartitionIdentifiers(scan_node)
      if not partition_identifiers:
        raise errors.SourceScannerError('No partitions found.')

      for partition_identifier in partition_identifiers:
        location = '/{0:s}'.format(partition_identifier)
        sub_scan_node = scan_node.GetSubNodeByLocation(location)
        self._ScanVolume(scan_context, sub_scan_node, base_path_specs)

    if not base_path_specs:
      raise errors.SourceScannerError(
          'No supported file system found in source.')

    self._source_path_specs = base_path_specs

    return scan_context

Scans the source path for volume and file systems.

This function sets the internal source path specification and source
type values.

Args:
source_path (str): path to the source.

Returns:
dfvfs.SourceScannerContext: source scanner context.

Raises:
SourceScannerError: if the format of or within the source is
not supported.


def events_from_file(filepath):
    records = list(tf_record.tf_record_iterator(filepath))
    result = []
    for r in records:
        event = event_pb2.Event()
        event.ParseFromString(r)
        result.append(event)
    return result

Returns all events in a single event file.

Args:
filepath: Path to the event file.

Returns:
A list of all tf.Event protos in the event file.


def remove_results(vcs, signature):

    results_directory = _get_results_directory(vcs, signature)
    if not os.path.exists(results_directory):
        raise ResultsNotFoundError
    shutil.rmtree(results_directory)

Removed saved results for this signature

Args:
vcs (easyci.vcs.base.Vcs)
signature (str)
Raises:
ResultsNotFoundError


def right_shift(x, y):
    if any_symbolic_tensors((x, y)):
        return RightShift().symbolic_call(x, y)
    return backend.numpy.right_shift(x, y)

Shift the bits of an integer to the right.

Bits are shifted to the right `y`. Because the internal representation of
numbers is in binary format, this operation is equivalent to dividing `x` by
`2**y`.

Args:
x: Input integer tensor.
y: Input integer tensor.

Returns:
Result tensor.


def from_bigquery(sql):
    if isinstance(sql, bq.Query):
        sql = sql._expanded_sql()
    parts = sql.split('.')
    if ((len(parts) == 1) or (len(parts) > 3) or any(((' ' in x) for x in parts))):
        sql = (('(' + sql) + ')')
    else:
        sql = (('`' + sql) + '`')
    query = bq.Query(('SELECT target, predicted, count(*) as count FROM %s group by target, predicted' % sql))
    df = query.execute().result().to_dataframe()
    labels = sorted((set(df['target']) | set(df['predicted'])))
    labels_count = len(labels)
    df['target'] = [labels.index(x) for x in df['target']]
    df['predicted'] = [labels.index(x) for x in df['predicted']]
    cm = [([0] * labels_count) for i in range(labels_count)]
    for (index, row) in df.iterrows():
        cm[row['target']][row['predicted']] = row['count']
    return ConfusionMatrix(cm, labels)

Create a ConfusionMatrix from a BigQuery table or query.

Args:
sql: Can be one of:
A SQL query string.
A Bigquery table string.
A Query object defined with '%%bq query --name [query_name]'.
The query results or table must include "target", "predicted" columns.
Returns:
A ConfusionMatrix that can be plotted.
Raises:
ValueError if query results or table does not include 'target' or 'predicted' columns.


def handle_error(self):
    if (not self.tasks):
        return
    self.mark_parent_tasks_as_failed(self.cur_task, flush_logs=True)
    for (index, task) in enumerate(self.tasks.values()):
        if self.should_show_by_depth((index + 1)):
            continue
        start_task_header = logging.LogRecord('', logging.INFO, '', 0, '', [], None)
        start_task_header.msg = ColorFormatter.colored('default', START_TASK_MSG)
        start_task_header.task = task.name
        self.pretty_emit(start_task_header, is_header=True, task_level=(index + 1))
    for old_record in self.tasks[self.cur_task]:
        self.pretty_emit(old_record)
    self.tasks[self.cur_task].clear()

Handles an error log record that should be shown

Returns:
None


def of(seconds: TimestampTypes) -> 'Timestamp':
    if isinstance(seconds, Timestamp):
        return seconds
    elif isinstance(seconds, (int, float)):
        return Timestamp(seconds)
    elif isinstance(seconds, datetime.datetime):
        return Timestamp.from_utc_datetime(seconds)
    else:
        raise TypeError('Cannot interpret %s %s as Timestamp.' % (seconds, type(seconds)))

Return the Timestamp for the given number of seconds.

If the input is already a Timestamp, the input itself will be returned.

Args:
seconds: Number of seconds as int, float, long, or Timestamp.

Returns:
Corresponding Timestamp object.


def add(self, input_tensor: core.Tensor) -> Mapping[str, core.Tensor]:
    out = math_ops.add(input_tensor, input_tensor)
    return {'output': out}

Performs an add operation.

Args:
input_tensor: Input tensor to perform add on.

Returns:
A map of: output key -> output result.


def validate(self, definition, version=None, strict=False):
    if (not HAS_KUBERNETES_VALIDATE):
        raise KubernetesValidateMissing()
    errors = list()
    warnings = list()
    try:
        if (version is None):
            try:
                version = self.version['kubernetes']['gitVersion']
            except KeyError:
                version = kubernetes_validate.latest_version()
        kubernetes_validate.validate(definition, version, strict)
    except kubernetes_validate.utils.ValidationError as e:
        errors.append(('resource definition validation error at %s: %s' % ('.'.join([str(item) for item in e.path]), e.message)))
    except VersionNotSupportedError as e:
        errors.append(('Kubernetes version %s is not supported by kubernetes-validate' % version))
    except kubernetes_validate.utils.SchemaNotFoundError as e:
        warnings.append(('Could not find schema for object kind %s with API version %s in Kubernetes version %s (possibly Custom Resource?)' % (e.kind, e.api_version, e.version)))
    return (warnings, errors)

validate checks a kubernetes resource definition

Args:
definition (dict): resource definition
version (str): version of kubernetes to validate against
strict (bool): whether unexpected additional properties should be considered errors

Returns:
warnings (list), errors (list): warnings are missing validations, errors are validation failures


def ranseed(seed=None):
    if (seed is None):
        seed = numpy.random.randint(1, int(2000000000.0), size=3)
    try:
        seed = tuple(seed)
    except TypeError:
        pass
    numpy.random.seed(seed)
    ranseed.seed = seed
    return seed

Seed random number generators with tuple ``seed``.

Argument ``seed`` is an integer or
a :class:`tuple` of integers that is used to seed
the random number generators used by :mod:`numpy` and
:mod:`random` (and therefore by :mod:`gvar`). Reusing
the same ``seed`` results in the same set of random numbers.

``ranseed`` generates its own seed when called without an argument
or with ``seed=None``. This seed is stored in ``ranseed.seed`` and
also returned by the function. The seed can be used to regenerate
the same set of random numbers at a later time.

Args:
seed (int, tuple, or None): Seed for generator. Generates a
random tuple if ``None``.
Returns:
The seed used to reseed the generator.


def contains(self, name):
    try:
        self._api.buckets_get(name)
    except google.datalab.utils.RequestException as e:
        if (e.status == 404):
            return False
        raise e
    except Exception as e:
        raise e
    return True

Checks if the specified bucket exists.

Args:
name: the name of the bucket to lookup.
Returns:
True if the bucket exists; False otherwise.
Raises:
Exception if there was an error requesting information about the bucket.


def prepare_locust_tests(path):

    tests_mapping = loader.load_tests(path)
    testcases = parser.parse_tests(tests_mapping)

    locust_tests = []

    for testcase in testcases:
        testcase_weight = testcase.get("config", {}).pop("weight", 1)
        for _ in range(testcase_weight):
            locust_tests.append(testcase)

    return locust_tests

prepare locust testcases

Args:
path (str): testcase file path.

Returns:
list: locust tests data

[
testcase1_dict,
testcase2_dict
]


class _ConfusionMatrixConditionCount(Metric):

    def __init__(self, confusion_matrix_cond, thresholds=None, name=None, dtype=None):
        super(_ConfusionMatrixConditionCount, self).__init__(name=name, dtype=dtype)
        self._confusion_matrix_cond = confusion_matrix_cond
        self.init_thresholds = thresholds
        self.thresholds = metrics_utils.parse_init_thresholds(thresholds, default_threshold=0.5)
        self._thresholds_distributed_evenly = metrics_utils.is_evenly_distributed_thresholds(self.thresholds)
        self.accumulator = self.add_weight('accumulator', shape=(len(self.thresholds),), initializer=init_ops.zeros_initializer)

    def update_state(self, y_true, y_pred, sample_weight=None):

        return metrics_utils.update_confusion_matrix_variables({self._confusion_matrix_cond: self.accumulator}, y_true, y_pred, thresholds=self.thresholds, thresholds_distributed_evenly=self._thresholds_distributed_evenly, sample_weight=sample_weight)

    def result(self):
        if len(self.thresholds) == 1:
            result = self.accumulator[0]
        else:
            result = self.accumulator
        return tensor_conversion.convert_to_tensor_v2_with_dispatch(result)

    def reset_state(self):
        num_thresholds = len(to_list(self.thresholds))
        backend.batch_set_value([(v, np.zeros((num_thresholds,))) for v in self.variables])

    def get_config(self):
        config = {'thresholds': self.init_thresholds}
        base_config = super(_ConfusionMatrixConditionCount, self).get_config()
        return dict(list(base_config.items()) + list(config.items()))

Calculates the number of the given confusion matrix condition.

Args:
confusion_matrix_cond: One of `metrics_utils.ConfusionMatrix` conditions.
thresholds: (Optional) Defaults to 0.5. A float value or a python list/tuple
of float threshold values in [0, 1]. A threshold is compared with
prediction values to determine the truth value of predictions (i.e., above
the threshold is `true`, below is `false`). One metric value is generated
for each threshold value.
name: (Optional) string name of the metric instance.
dtype: (Optional) data type of the metric result.


def set_column(self, X, column, value):
    if isinstance(X, pd.DataFrame):
        X.loc[(:, column)] = value
    else:
        X[(:, column)] = value
    return X

Sets a column on the matrix X with the given value.

Args:
X: `numpy.ndarray` or `pandas.DataFrame`.
column: `int` or `str`.
value: `np.ndarray` with shape (1,)

Returns:
`np.ndarray` or `pandas.DataFrame` with the inserted column.


def __init__(self, context):

    self.logdir = context.logdir
    self.multiplexer = context.multiplexer
    self.plugin_logdir = plugin_asset_util.PluginDirectory(
        self.logdir, PLUGIN_NAME)
    self.stub = None
    self.master_tpu_unsecure_channel = context.flags.master_tpu_unsecure_channel

    self._is_active = False

    self._is_active_lock = threading.Lock()

Constructs a profiler plugin for TensorBoard.

This plugin adds handlers for performance-related frontends.

Args:
context: A base_plugin.TBContext instance.


def get_protocol_version(protocol=None, target=None):
    target = get_py_internals(target)
    if (protocol is None):
        protocol = target['pickle_default_protocol']
    if (protocol > cPickle.HIGHEST_PROTOCOL):
        warnings.warn(('Downgrading pickle protocol, running python supports up to %d.' % cPickle.HIGHEST_PROTOCOL))
        protocol = cPickle.HIGHEST_PROTOCOL
    target_highest_protocol = target['pickle_highest_protocol']
    if (protocol > target_highest_protocol):
        warnings.warn(('Downgrading pickle protocol, target python supports up to %d.' % target_highest_protocol))
        protocol = target_highest_protocol
    return protocol

Return a suitable pickle protocol version for a given target.

Arguments:
target: The internals description of the targeted python
version. If this is ``None`` the specification of the currently
running python version will be used.
protocol(None or int): The requested protocol version (or None for the
default of the target python version).

Returns:
int: A suitable pickle protocol version.


def set_hook_data(self, key, data):

        if not isinstance(data, collections.Mapping):
            raise ValueError("Hook (key: %s) data must be an instance of "
                             "collections.Mapping (a dictionary for "
                             "example)." % key)

        if key in self.hook_data:
            raise KeyError("Hook data for key %s already exists, each hook "
                           "must have a unique data_key.", key)

        self.hook_data[key] = data

Set hook data for the given key.

Args:
key(str): The key to store the hook data in.
data(:class:`collections.Mapping`): A dictionary of data to store,
as returned from a hook.


def set_energy_upperbound(self, spins, offset=0):

        spin_energy = self.energy_upperbound(spins)
        self.assertions.add(GE(spin_energy, self.gap + offset))

Upper bound the energy of Theta with spins fixed to be greater than (gap + offset).

Args:
spins (dict): Spin values for a subset of the variables in Theta.
offset (float): A value that is added to the upper bound. Default value is 0.

Notes:
Add equality constraint to assertions.


def on_test_batch_end(self, batch, logs=None):

Called at the end of a batch in `evaluate` methods.

Also called at the end of a validation batch in the `fit`
methods, if validation data is provided.

Subclasses should override for any actions to run.

Note that if the `steps_per_execution` argument to `compile` in
`tf.keras.Model` is set to `N`, this method will only be called every `N`
batches.

Args:
batch: Integer, index of batch within the current epoch.
logs: Dict. Aggregated metric results up until this batch.


def _ParseLine(self, parser_mediator, structure):
    (month, day_of_month, year, hours, minutes, seconds, milliseconds) = structure.date_time
    year += 2000
    time_elements_tuple = (year, month, day_of_month, hours, minutes, seconds, milliseconds)
    try:
        date_time = dfdatetime_time_elements.TimeElementsInMilliseconds(time_elements_tuple=time_elements_tuple)
    except ValueError:
        parser_mediator.ProduceExtractionWarning('invalid date time value: {0!s}'.format(structure.date_time))
        return
    event_data = SkyDriveLogEventData()
    event_data.detail = structure.detail.replace('\n', ' ')
    event_data.log_level = structure.log_level
    event_data.module = structure.module
    event_data.source_code = structure.source_code
    event = time_events.DateTimeValuesEvent(date_time, definitions.TIME_DESCRIPTION_ADDED)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parses a logline and store appropriate attributes.

Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
structure (pyparsing.ParseResults): structure of tokens derived from
a line of a text file.


def list(self, pattern='*'):
    if (self._descriptors is None):
        self._descriptors = self._client.list_resource_descriptors(filter_string=self._filter_string)
    return [resource for resource in self._descriptors if fnmatch.fnmatch(resource.type, pattern)]

Returns a list of resource descriptors that match the filters.

Args:
pattern: An optional pattern to further filter the descriptors. This can
include Unix shell-style wildcards. E.g. ``"aws*"``, ``"*cluster*"``.

Returns:
A list of ResourceDescriptor objects that match the filters.


def _Dhcpcd(self, interfaces, logger):

    for interface in interfaces:
      dhcpcd = ['/sbin/dhcpcd']
      try:
        subprocess.check_call(dhcpcd + ['-x', interface])
      except subprocess.CalledProcessError:

        logger.info('Dhcpcd not yet running for interface %s.', interface)
      try:
        subprocess.check_call(dhcpcd + [interface])
      except subprocess.CalledProcessError:

        logger.warning('Could not activate interface %s.', interface)

Use dhcpcd to activate the interfaces.

Args:
interfaces: list of string, the output device names to enable.
logger: logger object, used to write to SysLog and serial port.


def unreduce_like(array, original_array, axis, keepdims):

  atype = type(array)
  unreducer = unreducers[atype]
  shape = shape_functions[atype]
  return unreducer(array, shape(original_array), axis, keepdims)

Reverse summing over a dimension.

Args:
array: The array that was reduced.
original_array: An array whose shape to unreduce to.
axis: The axis or axes that were summed.
keepdims: Whether these axes were kept as singleton axes.

Returns:
An array with axes broadcast to match the shape of the original array.


def ProcessConfigOverrides(filename):
    abs_filename = os.path.abspath(filename)
    cfg_filters = []
    keep_looking = True
    while keep_looking:
        (abs_path, base_name) = os.path.split(abs_filename)
        if (not base_name):
            break
        cfg_file = os.path.join(abs_path, 'CPPLINT.cfg')
        abs_filename = abs_path
        if (not os.path.isfile(cfg_file)):
            continue
        try:
            with open(cfg_file) as file_handle:
                for line in file_handle:
                    (line, _, _) = line.partition('
                    if (not line.strip()):
                        continue
                    (name, _, val) = line.partition('=')
                    name = name.strip()
                    val = val.strip()
                    if (name == 'set noparent'):
                        keep_looking = False
                    elif (name == 'filter'):
                        cfg_filters.append(val)
                    elif (name == 'exclude_files'):
                        if base_name:
                            pattern = re.compile(val)
                            if pattern.match(base_name):
                                sys.stderr.write(('Ignoring "%s": file excluded by "%s". File path component "%s" matches pattern "%s"\n' % (filename, cfg_file, base_name, val)))
                                return False
                    elif (name == 'linelength'):
                        global _line_length
                        try:
                            _line_length = int(val)
                        except ValueError:
                            sys.stderr.write('Line length must be numeric.')
                    else:
                        sys.stderr.write(('Invalid configuration option (%s) in file %s\n' % (name, cfg_file)))
        except IOError:
            sys.stderr.write(("Skipping config file '%s': Can't open for reading\n" % cfg_file))
            keep_looking = False
    for filter in reversed(cfg_filters):
        _AddFilters(filter)
    return True

Loads the configuration files and processes the config overrides.

Args:
filename: The name of the file being processed by the linter.

Returns:
False if the current |filename| should not be processed further.


def confirm(message: Text, default: bool=True, qmark: Text=DEFAULT_QUESTION_PREFIX, style: Optional[Style]=None, **kwargs: Any) -> Question:
    merged_style = merge_styles([DEFAULT_STYLE, style])
    status = {'answer': None}

    def get_prompt_tokens():
        tokens = []
        tokens.append(('class:qmark', qmark))
        tokens.append(('class:question', ' {} '.format(message)))
        if (status['answer'] is not None):
            answer = ' {}'.format((YES if status['answer'] else NO))
            tokens.append(('class:answer', answer))
        else:
            instruction = ' {}'.format((YES_OR_NO if default else NO_OR_YES))
            tokens.append(('class:instruction', instruction))
        return to_formatted_text(tokens)
    bindings = KeyBindings()

    @bindings.add(Keys.ControlQ, eager=True)
    @bindings.add(Keys.ControlC, eager=True)
    def _(event):
        event.app.exit(exception=KeyboardInterrupt, style='class:aborting')

    @bindings.add('n')
    @bindings.add('N')
    def key_n(event):
        status['answer'] = False
        event.app.exit(result=False)

    @bindings.add('y')
    @bindings.add('Y')
    def key_y(event):
        status['answer'] = True
        event.app.exit(result=True)

    @bindings.add(Keys.ControlM, eager=True)
    def set_answer(event):
        status['answer'] = default
        event.app.exit(result=default)

    @bindings.add(Keys.Any)
    def other(event):
        'Disallow inserting other text.'
        pass
    return Question(PromptSession(get_prompt_tokens, key_bindings=bindings, style=merged_style, **kwargs).app)

Prompt the user to confirm or reject.

This question type can be used to prompt the user for a confirmation
of a yes-or-no question. If the user just hits enter, the default
value will be returned.

Args:
message: Question text

default: Default value will be returned if the user just hits
enter.

qmark: Question prefix displayed in front of the question.
By default this is a `?`

style: A custom color and style for the question parts. You can
configure colors as well as font types for different elements.

Returns:
Question: Question instance, ready to be prompted (using `.ask()`).


def _validate_alias_file_content(alias_file_path, url=''):
    alias_table = get_config_parser()
    try:
        alias_table.read(alias_file_path)
        for (alias_name, alias_command) in reduce_alias_table(alias_table):
            _validate_alias_name(alias_name)
            _validate_alias_command(alias_command)
            _validate_alias_command_level(alias_name, alias_command)
            _validate_pos_args_syntax(alias_name, alias_command)
    except Exception as exception:
        error_msg = (CONFIG_PARSING_ERROR % AliasManager.process_exception_message(exception))
        error_msg = error_msg.replace(alias_file_path, (url or alias_file_path))
        raise CLIError(error_msg)

Make sure the alias name and alias command in the alias file is in valid format.

Args:
The alias file path to import aliases from.


class DetrEncoder(DetrPreTrainedModel):

    def __init__(self, config: DetrConfig):
        super().__init__(config)
        self.dropout = config.dropout
        self.layerdrop = config.encoder_layerdrop
        self.layers = nn.ModuleList([DetrEncoderLayer(config) for _ in range(config.encoder_layers)])
        self.post_init()

    def forward(self, inputs_embeds=None, attention_mask=None, object_queries=None, output_attentions=None, output_hidden_states=None, return_dict=None):

        output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
        output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        return_dict = return_dict if return_dict is not None else self.config.use_return_dict
        hidden_states = inputs_embeds
        hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
        if attention_mask is not None:
            attention_mask = _prepare_4d_attention_mask(attention_mask, inputs_embeds.dtype)
        encoder_states = () if output_hidden_states else None
        all_attentions = () if output_attentions else None
        for i, encoder_layer in enumerate(self.layers):
            if output_hidden_states:
                encoder_states = encoder_states + (hidden_states,)
            to_drop = False
            if self.training:
                dropout_probability = torch.rand([])
                if dropout_probability < self.layerdrop:
                    to_drop = True
            if to_drop:
                layer_outputs = (None, None)
            else:
                layer_outputs = encoder_layer(hidden_states, attention_mask, object_queries=object_queries, output_attentions=output_attentions)
                hidden_states = layer_outputs[0]
            if output_attentions:
                all_attentions = all_attentions + (layer_outputs[1],)
        if output_hidden_states:
            encoder_states = encoder_states + (hidden_states,)
        if not return_dict:
            return tuple((v for v in [hidden_states, encoder_states, all_attentions] if v is not None))
        return BaseModelOutput(last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions)

Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a
[`DetrEncoderLayer`].

The encoder updates the flattened feature map through multiple self-attention layers.

Small tweak for DETR:

- object_queries are added to the forward pass.

Args:
config: DetrConfig


def addColumn(self, header, values=[]):

        if len(values) == 0:
            self._impl.addColumn(header)
        else:
            assert len(values) == self.getNumRows()
            if any(isinstance(value, basestring) for value in values):
                values = list(map(str, values))
                self._impl.addColumnStr(header, values)
            elif all(isinstance(value, Real) for value in values):
                values = list(map(float, values))
                self._impl.addColumnDbl(header, values)
            else:
                raise NotImplementedError

Add a new column with the corresponding header and values to the
dataframe.

Args:
header: The name of the new column.

values: A list of size :func:`~amplpy.DataFrame.getNumRows` with
all the values of the new column.


def WriteSignedBinary(binary_urn, binary_content, private_key, public_key, chunk_size=1024, token=None):
    if _ShouldUseLegacyDatastore():
        collects.GRRSignedBlob.NewFromContent(binary_content, binary_urn, chunk_size=chunk_size, token=token, private_key=private_key, public_key=public_key)
    if data_store.RelationalDBEnabled():
        blob_references = rdf_objects.BlobReferences()
        for chunk_offset in range(0, len(binary_content), chunk_size):
            chunk = binary_content[chunk_offset:(chunk_offset + chunk_size)]
            blob_rdf = rdf_crypto.SignedBlob()
            blob_rdf.Sign(chunk, private_key, verify_key=public_key)
            blob_id = data_store.BLOBS.WriteBlobWithUnknownHash(blob_rdf.SerializeToString())
            blob_references.items.Append(rdf_objects.BlobReference(offset=chunk_offset, size=len(chunk), blob_id=blob_id))
        data_store.REL_DB.WriteSignedBinaryReferences(_SignedBinaryIDFromURN(binary_urn), blob_references)

Signs a binary and saves it to the datastore.

If a signed binary with the given URN already exists, its contents will get
overwritten.

Args:
binary_urn: URN that should serve as a unique identifier for the binary.
binary_content: Contents of the binary, as raw bytes.
private_key: Key that should be used for signing the binary contents.
public_key: Key that should be used to verify the signature generated using
the private key.
chunk_size: Size, in bytes, of the individual blobs that the binary contents
will be split to before saving to the datastore.
token: ACL token to use with the legacy (non-relational) datastore.