def export(self, filename, offset=0, length=None):
    self.__validate_offset(filename=filename, offset=offset, length=length)
    with open(filename, 'w') as f:
        if (length is None):
            length = (len(self.data) - offset)
        if (offset > 0):
            output = self.data[offset:length]
        else:
            output = self.data[:length]
        f.write(output)

Exports byte array to specified destination

Args:
filename (str): destination to output file
offset (int): byte offset (default: 0)


def autosave(self, index):

        finfo = self.stack.data[index]
        document = finfo.editor.document()
        if not document.changed_since_autosave or finfo.newly_created:
            return
        autosave_filename = self.get_autosave_filename(finfo.filename)
        logger.debug('Autosaving %s to %s', finfo.filename, autosave_filename)
        try:
            self.stack._write_to_file(finfo, autosave_filename)
            document.changed_since_autosave = False
        except EnvironmentError as error:
            action = (_('Error while autosaving {} to {}')
                      .format(finfo.filename, autosave_filename))
            msgbox = AutosaveErrorDialog(action, error)
            msgbox.exec_if_enabled()

Autosave a file.

Do nothing if the `changed_since_autosave` flag is not set or the file
is newly created (and thus not named by the user). Otherwise, save a
copy of the file with the name given by `self.get_autosave_filename()`
and clear the `changed_since_autosave` flag. Errors raised when saving
are silently ignored.

Args:
index (int): index into self.stack.data


def get_error(self, block=False, timeout=None):

        try:
            error = self._errors.get(block=block, timeout=timeout)
            return error
        except Exception:
            return None

Removes and returns an error from self._errors

Args:
block(bool): if True block until a RTMMessage is available,
else it will return None when self._inbox is empty
timeout(int): it blocks at most timeout seconds

Returns:
error if inbox is not empty, else None


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

Delete a named container.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
service_name (str): Name of container service.

Returns:
HTTP response.


def _RunScripts(self, run_dir=None):

    with _CreateTempDir(self.script_type, run_dir=run_dir) as dest_dir:
      try:
        self.logger.info('Starting %s scripts.', self.script_type)
        script_dict = self.retriever.GetScripts(dest_dir)
        self.executor.RunScripts(script_dict)
      finally:
        self.logger.info('Finished running %s scripts.', self.script_type)

Retrieve metadata scripts and execute them.

Args:
run_dir: string, the base directory location of the temporary directory.


def _VerifyOneTest(self, pool_func, input_sizes, ksize, strides, padding, data_format, expected):
    total_size = np.prod(input_sizes)
    x = np.array([f * 1.0 for f in range(1, total_size + 1)], dtype=np.float32)
    x = x.reshape(input_sizes)
    with self.session() as sess:
        with self.test_scope():
            inputs = array_ops.placeholder(dtypes.float32)
            t = inputs
            if data_format == 'NCHW':
                t = NHWCToNCHW(t)
                ksize = NHWCToNCHW(ksize)
                strides = NHWCToNCHW(strides)
            t = pool_func(t, ksize=ksize, strides=strides, padding=padding, data_format=data_format)
            if data_format == 'NCHW':
                t = NCHWToNHWC(t)
        actual = sess.run(t, {inputs: x})
        self.assertAllClose(expected, actual.flatten(), rtol=1e-05, atol=1e-06)

Verifies the output values of the pooling function.

Args:
pool_func: Function to be called, currently only co.MaxPool.
input_sizes: Input tensor dimensions.
ksize: The kernel size dimensions
strides: The stride dimensions
padding: Padding type.
data_format: The data format we use to run the pooling operation.
expected: An array containing the expected operation outputs.


def apply(self, window_length, samples=True, func1d=None):

        window_length /= 1 if samples else self.step
        if func1d is None:
            func1d = np.mean
        params = self.__dict__.copy()
        out = self._rolling_window(int(window_length), func1d)
        return Curve(out, params=params)

Runs any kind of function over a window.

Args:
window_length (int): the window length. Required.
samples (bool): window length is in samples. Use False for a window
length given in metres.
func1d (function): a function that takes a 1D array and returns a
scalar. Default: ``np.mean()``.

Returns:
Curve.


def _create_4d_causal_attention_mask(input_shape: Union[torch.Size, tuple, list], dtype: torch.dtype, device: torch.device, past_key_values_length: int=0, sliding_window: Optional[int]=None) -> Optional[torch.Tensor]:
    attn_mask_converter = AttentionMaskConverter(is_causal=True, sliding_window=sliding_window)
    key_value_length = past_key_values_length + input_shape[-1]
    attention_mask = attn_mask_converter.to_causal_4d(input_shape[0], input_shape[-1], key_value_length, dtype=dtype, device=device)
    return attention_mask

Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)`

Args:
input_shape (`tuple(int)` or `list(int)` or `torch.Size`):
The input shape should be a tuple that defines `(batch_size, query_length)`.
dtype (`torch.dtype`):
The torch dtype the created mask shall have.
device (`int`):
The torch device the created mask shall have.
sliding_window (`int`, *optional*):
If the model uses windowed attention, a sliding window should be passed.


def CopyToDateTimeString(self):
    if (self._timestamp is None):
        return None
    (number_of_days, hours, minutes, seconds) = self._GetTimeValues(self._timestamp)
    (year, month, day_of_month) = self._GetDateValues(number_of_days, 1970, 1, 1)
    if (self.fraction_of_second is None):
        return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'.format(year, month, day_of_month, hours, minutes, seconds)
    if (pytsk3.TSK_VERSION_NUM >= 67240191):
        return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:09d}'.format(year, month, day_of_month, hours, minutes, seconds, self.fraction_of_second)
    return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:07d}'.format(year, month, day_of_month, hours, minutes, seconds, self.fraction_of_second)

Copies the date time value to a date and time string.

Returns:
str: date and time value formatted as:
YYYY-MM-DD hh:mm:ss or
YYYY-MM-DD hh:mm:ss.####### or
YYYY-MM-DD hh:mm:ss.#########


def get_field(self, field_type):
    for field in self.oxm_match_fields:
        if (field.oxm_field == field_type):
            return field.oxm_value
    return None

Return the value for the 'field_type' field in oxm_match_fields.

Args:
field_type (~pyof.v0x04.common.flow_match.OxmOfbMatchField,
~pyof.v0x04.common.flow_match.OxmMatchFields):
The type of the OXM field you want the value.

Returns:
The integer number of the 'field_type' if it exists. Otherwise
return None.


def _ParseLogLine(self, parser_mediator, structure):

    try:
      date_time = dfdatetime_time_elements.TimeElements(
          time_elements_tuple=structure.date_time)
      date_time.is_local_time = True
    except ValueError:
      parser_mediator.ProduceExtractionWarning(
          'invalid date time value: {0!s}'.format(structure.date_time))
      return

    event_data = WinFirewallEventData()
    event_data.action = self._GetStructureValue(structure, 'action')
    event_data.dest_ip = self._GetStructureValue(structure, 'dest_ip')
    event_data.dest_port = self._GetStructureValue(structure, 'dest_port')
    event_data.flags = self._GetStructureValue(structure, 'flags')
    event_data.icmp_code = self._GetStructureValue(structure, 'icmp_code')
    event_data.icmp_type = self._GetStructureValue(structure, 'icmp_type')
    event_data.info = self._GetStructureValue(structure, 'info')
    event_data.path = self._GetStructureValue(structure, 'path')
    event_data.protocol = self._GetStructureValue(structure, 'protocol')
    event_data.size = self._GetStructureValue(structure, 'size')
    event_data.source_ip = self._GetStructureValue(structure, 'source_ip')
    event_data.source_port = self._GetStructureValue(structure, 'source_port')
    event_data.tcp_ack = self._GetStructureValue(structure, 'tcp_ack')
    event_data.tcp_seq = self._GetStructureValue(structure, 'tcp_seq')
    event_data.tcp_win = self._GetStructureValue(structure, 'tcp_win')

    if self._use_local_timezone:
      time_zone = parser_mediator.timezone
    else:
      time_zone = pytz.UTC

    event = time_events.DateTimeValuesEvent(
        date_time, definitions.TIME_DESCRIPTION_WRITTEN, time_zone=time_zone)
    parser_mediator.ProduceEventWithEventData(event, event_data)

Parse a single log line and and produce an event object.

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 _MergeMessageField(self, tokenizer, message, field):

    is_map_entry = _IsMapEntry(field)

    if tokenizer.TryConsume('<'):
      end_token = '>'
    else:
      tokenizer.Consume('{')
      end_token = '}'

    if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
      if field.is_extension:
        sub_message = message.Extensions[field].add()
      elif is_map_entry:

        sub_message = field.message_type._concrete_class()
      else:
        sub_message = getattr(message, field.name).add()
    else:
      if field.is_extension:
        sub_message = message.Extensions[field]
      else:
        sub_message = getattr(message, field.name)
      sub_message.SetInParent()

    while not tokenizer.TryConsume(end_token):
      if tokenizer.AtEnd():
        raise tokenizer.ParseErrorPreviousToken('Expected "%s".' % (end_token,))
      self._MergeField(tokenizer, sub_message)

    if is_map_entry:
      value_cpptype = field.message_type.fields_by_name['value'].cpp_type
      if value_cpptype == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
        value = getattr(message, field.name)[sub_message.key]
        value.MergeFrom(sub_message.value)
      else:
        getattr(message, field.name)[sub_message.key] = sub_message.value

Merges a single scalar field into a message.

Args:
tokenizer: A tokenizer to parse the field value.
message: The message of which field is a member.
field: The descriptor of the field to be merged.

Raises:
ParseError: In case of text parsing problems.


def register_event(self, *names):
    for name in names:
        if (name in self.__events):
            continue
        self.__events[name] = Event(name)

Registers new events after instance creation

Args:
*names (str): Name or names of the events to register


def __Build(leaves):
    if (len(leaves) < 1):
        raise Exception('Leaves must have length')
    if (len(leaves) == 1):
        return leaves[0]
    num_parents = int(((len(leaves) + 1) / 2))
    parents = [MerkleTreeNode() for i in range(0, num_parents)]
    for i in range(0, num_parents):
        node = parents[i]
        node.LeftChild = leaves[(i * 2)]
        leaves[(i * 2)].Parent = node
        if (((i * 2) + 1) == len(leaves)):
            node.RightChild = node.LeftChild
        else:
            node.RightChild = leaves[((i * 2) + 1)]
            leaves[((i * 2) + 1)].Parent = node
        hasharray = bytearray((node.LeftChild.Hash.ToArray() + node.RightChild.Hash.ToArray()))
        node.Hash = UInt256(data=Crypto.Hash256(hasharray))
    return MerkleTree.__Build(parents)

Build the merkle tree.

Args:
leaves (list): items are of type MerkleTreeNode.

Returns:
MerkleTreeNode: the root node.


def _op_writes_to_resource(handle, op):
    if op.type in RESOURCE_READ_OPS:
        return False
    input_index = _input_index(op, handle)
    try:
        read_only_input_indices = op.get_attr(READ_ONLY_RESOURCE_INPUTS_ATTR)
    except ValueError:
        return True
    return input_index not in read_only_input_indices

Returns whether op writes to resource handle.

Args:
handle: Resource handle. Must be an input of `op`.
op: Operation.

Returns:
Returns False if op is a read-only op registered using
`register_read_only_resource_op` or if `handle` is an input at one of
the indices in the `READ_ONLY_RESOURCE_INPUTS_ATTR` attr of the op, True
otherwise.

Raises:
ValueError: if `handle` is not an input of `op`.


def _init_zeo_root(self, attempts=3):
    try:
        db_root = self._connection.root()
    except ConnectionStateError:
        if (attempts <= 0):
            raise
        self._open_connection()
        return self._init_zeo_root(attempts=(attempts - 1))
    if (self.project_key and (self.project_key not in db_root)):
        with transaction.manager:
            db_root[self.project_key] = self.default_type()
    self._root = (db_root[self.project_key] if self.project_key else db_root)

Get and initialize the ZEO root object.

Args:
attempts (int, default 3): How many times to try, if the connection
was lost.


def case(self, case):
    LOG.debug('Getting case {0} from database'.format(case.get('case_id')))
    case_id = case['case_id']
    return self.db.case.find_one({'case_id': case_id})

Get a case from the database

Search the cases with the case id

Args:
case (dict): A case dictionary

Returns:
mongo_case (dict): A mongo case dictionary


def _CalculateParameterListState(self, newline):
    current = self.next_token
    previous = current.previous_token
    penalty = 0
    if _IsFunctionDefinition(previous):
        first_param_column = previous.total_length + self.stack[-2].indent
        if not newline:
            param_list = self.param_list_stack[-1]
            if param_list.parameters and param_list.has_typed_return:
                last_param = param_list.parameters[-1].first_token
                last_token = _LastTokenInLine(previous.matching_bracket)
                total_length = last_token.total_length
                total_length -= last_param.total_length - len(last_param.value)
                if total_length + self.column > self.column_limit:
                    penalty += split_penalty.VERY_STRONGLY_CONNECTED
            return penalty
        if first_param_column <= self.column:
            penalty += split_penalty.VERY_STRONGLY_CONNECTED
        return penalty
    if not self.param_list_stack:
        return penalty
    param_list = self.param_list_stack[-1]
    if current == self.param_list_stack[-1].closing_bracket:
        self.param_list_stack.pop()
        if newline and param_list.has_typed_return:
            if param_list.split_before_closing_bracket:
                penalty -= split_penalty.STRONGLY_CONNECTED
            elif param_list.LastParamFitsOnLine(self.column):
                penalty += split_penalty.STRONGLY_CONNECTED
        if not newline and param_list.has_typed_return and param_list.has_split_before_first_param:
            penalty += split_penalty.STRONGLY_CONNECTED
        return penalty
    if not param_list.parameters:
        return penalty
    if newline:
        if self._FitsOnLine(param_list.parameters[0].first_token, _LastTokenInLine(param_list.closing_bracket)):
            penalty += split_penalty.STRONGLY_CONNECTED
    if not newline and style.Get('SPLIT_BEFORE_NAMED_ASSIGNS') and param_list.has_default_values and (current != param_list.parameters[0].first_token) and (current != param_list.closing_bracket) and (subtypes.PARAMETER_START in current.subtypes):
        penalty += split_penalty.STRONGLY_CONNECTED
    return penalty

Makes required changes to parameter list state.

Args:
newline: Whether the current token is to be added on a newline.

Returns:
The penalty for the token-newline combination given the current
parameter state.


def addDataDocuments(self, scidata_pid_list, scimeta_pid=None):

        mpids = self.getAggregatedScienceMetadataPids()
        if scimeta_pid is None:
            if len(mpids) > 1:
                raise ValueError(
                    "No metadata PID specified and more than one choice available."
                )
            scimeta_pid = mpids[0]
        else:
            if scimeta_pid not in mpids:
                self.addMetadataDocument(scimeta_pid)

        for dpid in scidata_pid_list:
            self.addResource(dpid)
            self.setDocumentedBy(dpid, scimeta_pid)
            self.setDocuments(scimeta_pid, dpid)

Add Science Data object(s)

Args:
scidata_pid_list : list of str
List of one or more PIDs of Science Data objects

scimeta_pid: str
PID of a Science Metadata object that documents the Science Data objects.


def should_load_checkpoint():
    return dc_context.get_current_worker_context().experimental_should_init

Returns whether the current worker should load checkpoints.

In multi-worker training, if loading checkpoint is requested by user, or
needed for fault-tolerance, the cluster should load checkpoint but not
necessarily every worker in the cluster should.

Returns:
Whether this particular worker in the cluster should load checkpoints.


def parse_changes(json):
    changes = []
    dates = len(json)
    for date in range(1, dates):
        last_close = json[(date - 1)]['close']
        now_close = json[date]['close']
        changes.append((now_close - last_close))
    logger.debug('Market Changes (from JSON):\n{0}'.format(changes))
    return changes

Gets price changes from JSON

Args:
json: JSON data as a list of dict dates, where the keys are
the raw market statistics.

Returns:
List of floats of price changes between entries in JSON.


def batch_remove(self, removals: Iterable[Tuple[(int, ops.Operation)]]) -> None:
    copy = self.copy()
    for (i, op) in removals:
        if (op not in copy._moments[i].operations):
            raise ValueError("Can't remove {} @ {} because it doesn't exist.".format(op, i))
        copy._moments[i] = ops.Moment((old_op for old_op in copy._moments[i].operations if (op != old_op)))
    self._device.validate_circuit(copy)
    self._moments = copy._moments

Removes several operations from a circuit.

Args:
removals: A sequence of (moment_index, operation) tuples indicating
operations to delete from the moments that are present. All
listed operations must actually be present or the edit will
fail (without making any changes to the circuit).

ValueError:
One of the operations to delete wasn't present to start with.

IndexError:
Deleted from a moment that doesn't exist.


def _get_concrete_function_garbage_collected(self, *args, **kwargs):
    with self._lock:
        if self._variable_creation_config is None:
            initializers = []
            self._initialize(args, kwargs, add_initializers_to=initializers)
            self._initialize_uninitialized_variables(initializers)
    if self._created_variables:
        return tracing_compilation.trace_function(args, kwargs, dataclasses.replace(self._no_variable_creation_config, bind_graph_to_function=True))
    elif self._variable_creation_config is not None:
        concrete = tracing_compilation.trace_function(args, kwargs, dataclasses.replace(self._variable_creation_config, bind_graph_to_function=True))
        if self._created_variables:
            raise ValueError('Creating variables on a non-first call to a function decorated with tf.function.')
        return concrete

Returns a `ConcreteFunction` specialized to inputs and execution context.

Unlike `get_concrete_function(...)`, the graph will be deleted when the
returned function is deleted.  It's useful to avoid creating a reference
cycle when you know for sure that the graph will be no longer used without
the returned function.

Args:
*args: inputs to specialize on.
**kwargs: inputs to specialize on.

Returns:
A TensorFlow function which takes exactly one `tf.Tensor` per argument.

Raises:
ValueError: if this object has not yet been called on concrete values.


def sed(regexpr, repl, force=False, recursive=False, dpath_list=None,
        fpath_list=None, verbose=None, include_patterns=None,
        exclude_patterns=[]):

    if include_patterns is None:
        include_patterns = ['*.py', '*.pyx', '*.pxi', '*.cxx', '*.cpp', '*.hxx', '*.hpp', '*.c', '*.h', '*.html', '*.tex']
    if dpath_list is None:
        dpath_list = [os.getcwd()]
    if verbose is None:
        verbose = ut.NOT_QUIET
    if fpath_list is None:
        greater_exclude_dirs = get_standard_exclude_dnames()
        exclude_dirs = []
        fpath_generator = matching_fpaths(
            dpath_list, include_patterns, exclude_dirs,
            greater_exclude_dirs=greater_exclude_dirs,
            recursive=recursive, exclude_patterns=exclude_patterns)
    else:
        fpath_generator = fpath_list
    if verbose:
        print('sed-ing %r' % (dpath_list,))
        print(' * regular expression : %r' % (regexpr,))
        print(' * replacement        : %r' % (repl,))
        print(' * include_patterns   : %r' % (include_patterns,))
        print(' * recursive: %r' % (recursive,))
        print(' * force: %r' % (force,))
        from utool import util_str
        print(' * fpath_list: %s' % (util_str.repr3(fpath_list),))
    regexpr = extend_regex(regexpr)

    num_changed = 0
    num_files_checked = 0
    fpaths_changed = []
    for fpath in fpath_generator:
        num_files_checked += 1
        changed_lines = sedfile(fpath, regexpr, repl, force, verbose=verbose)
        if changed_lines is not None:
            fpaths_changed.append(fpath)
            num_changed += len(changed_lines)
    import utool as ut
    print('num_files_checked = %r' % (num_files_checked,))
    print('fpaths_changed = %s' % (ut.repr3(sorted(fpaths_changed)),))
    print('total lines changed = %r' % (num_changed,))

Python implementation of sed. NOT FINISHED

searches and replaces text in files

Args:
regexpr (str): regx patterns to find
repl (str): text to replace
force (bool):
recursive (bool):
dpath_list (list): directories to search (defaults to cwd)


def advance_for_next_slice(self, recovery_slice=False):
    if recovery_slice:
        self.slice_id += 2
        self.input_reader = self.input_reader.from_json(self._input_reader_json)
    else:
        self.slice_id += 1

Advance relavent states for next slice.

Args:
recovery_slice: True if this slice is running recovery logic.
See handlers.MapperWorkerCallbackHandler._attempt_slice_recovery
for more info.


def convert_to_dimension(d):
    if (d is None):
        return None
    if isinstance(d, Dimension):
        if ((not isinstance(d.name, str)) or (not isinstance(d.size, int))):
            raise ValueError(('Bad dimension %s' % (d,)))
        return d
    (name, size) = d
    if (isinstance(name, str) and isinstance(size, int)):
        return Dimension(name, size)
    else:
        raise ValueError(('could not convert %s to Dimension' % (d,)))

Converts input to a Dimension.

Args:
d: Dimension, tuple (string, int), or None.

Returns:
Dimension or None.

Raises:
ValueError: If d cannot be converted to a Dimension.


def preprocess_GIF(self, image, **kwargs):
    if ('transparency' in image.info):
        save_kwargs = {'transparency': image.info['transparency']}
    else:
        save_kwargs = {}
    return (image, save_kwargs)

Receive a PIL Image instance of a GIF and return 2-tuple.

Args:
* [0]: Original Image instance (passed to `image`)
* [1]: Dict with a transparency key (to GIF transparency layer)


def dense_to_sparse(x, ignore_value=None, name=None):

  with tf.compat.v1.name_scope(name, 'dense_to_sparse', [x, ignore_value]):
    x = tf.convert_to_tensor(value=x, name='x')
    if ignore_value is None:
      if x.dtype.base_dtype == tf.string:

        ignore_value = ''
      else:
        ignore_value = x.dtype.as_numpy_dtype(0)
      ignore_value = tf.cast(ignore_value, x.dtype, name='ignore_value')
    indices = tf.where(tf.not_equal(x, ignore_value), name='indices')
    return tf.SparseTensor(
        indices=indices,
        values=tf.gather_nd(x, indices, name='values'),
        dense_shape=tf.shape(input=x, out_type=tf.int64, name='dense_shape'))

Converts dense `Tensor` to `SparseTensor`, dropping `ignore_value` cells.

Args:
x: A `Tensor`.
ignore_value: Entries in `x` equal to this value will be
absent from the return `SparseTensor`. If `None`, default value of
`x` dtype will be used (e.g. '' for `str`, 0 for `int`).
name: Python `str` prefix for ops created by this function.

Returns:
sparse_x: A `tf.SparseTensor` with the same shape as `x`.

Raises:
ValueError: when `x`'s rank is `None`.


def get_templates(load_all=True, **kwargs):

    if load_all is False:
        templates = db.DBSession.query(Template).all()
    else:
        templates = db.DBSession.query(Template).options(joinedload_all('templatetypes.typeattrs')).all()

    return templates

Get all templates.
Args:
load_all Boolean: Returns just the template entry or the full template structure (template types and type attrs)
Returns:
List of Template objects


def add(self, aspect, ifpresent="error"):

        if isinstance(aspect, contextualize):
            self.contextualize.update(aspect)
            return True

        classification = [(network, self.networks), (system, self.systems), (ansible, self.ansible_hosts),
                          (deploy, self.deploys), (configure, self.configures)]
        aspect_list = [l for t, l in classification if isinstance(aspect, t)]
        assert len(aspect_list) == 1, "Unexpected aspect for RADL."
        aspect_list = aspect_list[0]

        old_aspect = [a for a in aspect_list if a.getId() == aspect.getId()]
        if old_aspect:

            if ifpresent == "error":
                raise Exception("Aspect with the same id was found.")
            elif ifpresent == "replace":
                for i, elem in enumerate(aspect_list):
                    if elem.getId() == old_aspect[0].getId():
                        del aspect_list[i]
                        break
                aspect_list.append(aspect)
                return True
            elif ifpresent == "ignore":
                return False
            else:
                raise ValueError
        else:

            aspect_list.append(aspect)
            return True

Add a network, ansible_host, system, deploy, configure or contextualize.

Args:
- aspect(network, system, deploy, configure or contextualize): thing to add.
- ifpresent(str): if it has been defined, do:

- ``"ignore"``: not add the aspect.
- ``"replace"``: replace by the old defined.
- ``"error"``: raise an error.

Return(bool): True if aspect was added.


def processor_coordinates_to_pnum(mesh_shape, coord):

  ret = 0
  multiplier = 1
  for c, d in zip(coord[::-1], mesh_shape.to_integer_list[::-1]):
    ret += multiplier * c
    multiplier *= d
  return ret

Inverse of pnum_to_processor_coordinates.

Args:
mesh_shape: a Shape
coord: a list of integers with length len(mesh_shape)

Returns:
an integer less than len(mesh_shape)


def get_train_hooks(name_list, **kwargs):
    if (not name_list):
        return []
    train_hooks = []
    for name in name_list:
        hook_name = HOOKS.get(name.strip().lower())
        if (hook_name is None):
            raise ValueError('Unrecognized training hook requested: {}'.format(name))
        else:
            train_hooks.append(hook_name(**kwargs))
    return train_hooks

Factory for getting a list of TensorFlow hooks for training by name.

Args:
name_list: a list of strings to name desired hook classes. Allowed:
LoggingTensorHook, ProfilerHook, ExamplesPerSecondHook, which are defined
as keys in HOOKS
**kwargs: a dictionary of arguments to the hooks.

Returns:
list of instantiated hooks, ready to be used in a classifier.train call.

Raises:
ValueError: if an unrecognized name is passed.


def download_file(self, remote_filename, local_filename=None):
    status = 'Failed'
    if (local_filename is None):
        local_filename = remote_filename
    if ((not self.args.force) and os.access(local_filename, os.F_OK)):
        if (not self._confirm_overwrite(local_filename)):
            self._print_results(local_filename, 'Skipped')
            return
    url = '{}{}'.format(self.base_url, remote_filename)
    r = requests.get(url, allow_redirects=True)
    if r.ok:
        open(local_filename, 'wb').write(r.content)
        status = 'Success'
    else:
        self.handle_error('Error requesting: {}'.format(url), False)
    self._print_results(local_filename, status)

Download file from github.

Args:
remote_filename (str): The name of the file as defined in git repository.
local_filename (str, optional): Defaults to None. The name of the file as it should be
be written to local filesystem.


def generate_policy_statements(self):
    statements = self._policy_statements
    statements.extend(lambda_basic_execution_statements(self.function.Ref()))
    extended_statements = self.extended_policy_statements()
    if extended_statements:
        statements.extend(extended_statements)
    return statements

Generates the policy statements for the role used by the function.

To add additional statements you can either override the
`extended_policy_statements` method to return a list of Statements
to be added to the policy, or override this method itself if you
need more control.

Returns:
list: A list of :class:`awacs.aws.Statement` objects.


def __init__(self, features):
    self._features = features.copy()
    self._feature_tensors = {}

Creates a `FeatureTransformationCache`.

Args:
features: A mapping from feature column to objects that are `Tensor` or
`SparseTensor`, or can be converted to same via
`sparse_tensor.convert_to_tensor_or_sparse_tensor`. A `string` key
signifies a base feature (not-transformed). A `FeatureColumn` key means
that this `Tensor` is the output of an existing `FeatureColumn` which
can be reused.


def point_line_distance(point, start, end):

    if start == end:
        return distance(point, start)
    else:
        un_dist = abs(
            (end.lat-start.lat)*(start.lon-point.lon) - (start.lat-point.lat)*(end.lon-start.lon)
        )
        n_dist = sqrt(
            (end.lat-start.lat)**2 + (end.lon-start.lon)**2
        )
        if n_dist == 0:
            return 0
        else:
            return un_dist / n_dist

Distance from a point to a line, formed by two points

Args:
point (:obj:`Point`)
start (:obj:`Point`): line point
end (:obj:`Point`): line point
Returns:
float: distance to line, in degrees


def _BreakpointEvent(self, event, frame):

    error_status = None

    if event != native.BREAKPOINT_EVENT_HIT:
      error_status = _BREAKPOINT_EVENT_STATUS[event]
    elif self.definition.get('action') == 'LOG':
      error_status = self._collector.Log(frame)
      if not error_status:
        return

    if not self._SetCompleted():
      return

    self.Clear()

    if error_status:
      self._CompleteBreakpoint({'status': error_status})
      return

    collector = capture_collector.CaptureCollector(
        self.definition, self.data_visibility_policy)

    try:
      collector.Collect(frame)
    except BaseException as e:
      native.LogInfo('Internal error during data capture: %s' % repr(e))
      error_status = {'isError': True,
                      'description': {
                          'format': ('Internal error while capturing data: %s' %
                                     repr(e))}}
      self._CompleteBreakpoint({'status': error_status})
      return
    except:
      native.LogInfo('Unknown exception raised')
      error_status = {'isError': True,
                      'description': {
                          'format': 'Unknown internal error'}}
      self._CompleteBreakpoint({'status': error_status})
      return

    self._CompleteBreakpoint(collector.breakpoint, is_incremental=False)

Callback invoked by cdbg_native when breakpoint hits.

Args:
event: breakpoint event (see kIntegerConstants in native_module.cc).
frame: Python stack frame of breakpoint hit or None for other events.


def CheckRedundantVirtual(filename, clean_lines, linenum, error):

  line = clean_lines.elided[linenum]
  virtual = Match(r'^(.*)(\bvirtual\b)(.*)$', line)
  if not virtual: return

  if (Search(r'\b(public|protected|private)\s+$', virtual.group(1)) or
      Match(r'^\s+(public|protected|private)\b', virtual.group(3))):
    return

  if Match(r'^.*[^:]:[^:].*$', line): return

  end_col = -1
  end_line = -1
  start_col = len(virtual.group(2))
  for start_line in xrange(linenum, min(linenum + 3, clean_lines.NumLines())):
    line = clean_lines.elided[start_line][start_col:]
    parameter_list = Match(r'^([^(]*)\(', line)
    if parameter_list:

      (_, end_line, end_col) = CloseExpression(
          clean_lines, start_line, start_col + len(parameter_list.group(1)))
      break
    start_col = 0

  if end_col < 0:
    return

  for i in xrange(end_line, min(end_line + 3, clean_lines.NumLines())):
    line = clean_lines.elided[i][end_col:]
    match = Search(r'\b(override|final)\b', line)
    if match:
      error(filename, linenum, 'readability/inheritance', 4,
            ('"virtual" is redundant since function is '
             'already declared as "%s"' % match.group(1)))

    end_col = 0
    if Search(r'[^\w]\s*$', line):
      break

Check if line contains a redundant "virtual" function-specifier.

Args:
filename: The name of the current file.
clean_lines: A CleansedLines instance containing the file.
linenum: The number of the line to check.
error: The function to call with any errors found.


def poweroff_vmss(access_token, subscription_id, resource_group, vmss_name):
    endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Compute/virtualMachineScaleSets/', vmss_name, '/powerOff?api-version=', COMP_API])
    body = '{"instanceIds" : ["*"]}'
    return do_post(endpoint, body, access_token)

Power off all the VMs in a virtual machine scale set.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vmss_name (str): Name of the virtual machine scale set.

Returns:
HTTP response.


def ProduceEventSource(self, event_source):

    if not self._storage_writer:
      raise RuntimeError('Storage writer not set.')

    self._storage_writer.AddEventSource(event_source)
    self._number_of_event_sources += 1

    self.last_activity_timestamp = time.time()

Produces an event source.

Args:
event_source (EventSource): an event source.

Raises:
RuntimeError: when storage writer is not set.


def _pad_all_input(inputs: Iterable[core_types.Tensor], padded_shapes: List[Optional[tensor_shape.TensorShape]], padding_spec: PaddingSpec) -> Tuple[List[List[Any]], List[dynamic_padding.PaddingMap]]:
    maximum_static_shapes = []
    need_padding = []
    input_shape_tensors = []
    for core_idx, inputs_per_core in enumerate(inputs):
        for idx, input_tensor in enumerate(inputs_per_core):
            input_shape = input_tensor.get_shape().as_list()
            if core_idx == 0:
                input_shape_tensors.append([])
                maximum_static_shapes.append(input_shape)
                need_padding.append(np.full_like(input_shape, False, dtype=bool))
            else:
                for i, s in enumerate(input_shape):
                    if s is None or s != maximum_static_shapes[idx][i]:
                        need_padding[idx][i] = True
                maximum_static_shapes[idx] = max(input_shape, maximum_static_shapes[idx])
            real_input_shape = array_ops.shape(input_tensor)
            real_input_shape.op._set_attr(_POST_DEVICE_REWRITE_ATTR, attr_value_pb2.AttrValue(b=True))
            input_shape_tensors[idx].append(real_input_shape)
    maximum_shapes = []
    for shapes_per_input in input_shape_tensors:
        maximum_shapes.append(math_ops.reduce_max(array_ops_stack.stack(shapes_per_input), axis=0))
    padded_inputs = []
    real_shapes = []
    padding_maps = []
    for core_idx, inputs_per_core in enumerate(inputs):
        padded_inputs.append([])
        real_shapes.append([])
        real_shape_idx = len(inputs_per_core) - 1
        for idx, input_tensor in enumerate(inputs_per_core):
            input_shape_tensor = input_shape_tensors[idx][core_idx]
            input_shape = input_tensor.get_shape().as_list()
            padded_shape = padded_shapes[idx]
            if any(need_padding[idx]) and padded_shape is not None:
                for i, s in enumerate(input_shape):
                    if need_padding[idx][i]:
                        if core_idx == 0:
                            real_shape_idx += 1
                            padding_map = dynamic_padding.PaddingMap()
                            padding_map.arg_index = idx
                            padding_map.shape_index = i
                            padding_map.padding_arg_index = real_shape_idx
                            padding_maps.append(padding_map)
                        real_shapes[core_idx].append(math_ops.cast(input_shape_tensor[i], dtypes.int32))
                paddings = []
                for i, s in enumerate(padded_shape.dims):
                    if need_padding[idx][i]:
                        minimum_dynamic_dim_size = 2
                        if s.value is not None:
                            max_dim_size = max(s.value, minimum_dynamic_dim_size)
                        else:
                            max_dim_size = math_ops.maximum(maximum_shapes[idx][i], minimum_dynamic_dim_size)
                            if padding_spec == PaddingSpec.POWER_OF_TWO:
                                max_dim_size = _ceil_to_pow_of_n(max_dim_size, 2)
                        padding = [0, max_dim_size - input_shape_tensor[i]]
                    else:
                        padding = [0, 0]
                    paddings.append(padding)
                if input_tensor.get_shape().is_fully_defined():
                    padded_input = cond.cond(array_ops.constant(True), lambda: array_ops.pad(input_tensor, paddings), lambda: input_tensor)
                else:
                    padded_input = array_ops.pad(input_tensor, paddings)
                padded_input.op._set_attr(_POST_DEVICE_REWRITE_ATTR, attr_value_pb2.AttrValue(b=True))
                padded_inputs[core_idx].append(padded_input)
            else:
                padded_inputs[core_idx].append(input_tensor)
    num_replicas = len(padded_inputs)
    for i in range(num_replicas):
        padded_inputs[i].extend(real_shapes[i])
    return (padded_inputs, padding_maps)

Pad all input tensors given padded_shapes.

The real shape tensors will be concatenated with the padded original inputs.

Args:
inputs: The original inputs.
padded_shapes: A list of padded shapes for each input. If an entry is None,
no padding is performed.
padding_spec: An enum specified by `tpu.PaddingSpec`. This describes the
padding policy when the `inputs` to `tf.tpu.replicate` is dynamic.
One usage is to enable automatic bucketizing on the inputs by setting the
value to `tpu.PaddingSpec.POWER_OF_TWO`, which can help to reduce the
recompilation in the XLA side.

Returns:
The padded inputs and a PaddingMap list which maps the padded input
dimension to the real shape argument index.


def __init__(self,
            device: Device,
            scheduled_operations: Iterable[ScheduledOperation] = ()
            ) -> None:

        self.device = device
        self.scheduled_operations = SortedListWithKey(scheduled_operations,
                                                      key=lambda e: e.time)
        self._max_duration = max(
            [e.duration for e in self.scheduled_operations] or [Duration()])

Initializes a new schedule.

Args:
device: The hardware this schedule will run on.
scheduled_operations: Initial list of operations to apply. These
will be moved into a sorted list, with a key equal to each
operation's start time.


def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
    output = [self.cls_token_id] + token_ids_0 + [self.sep_token_id]
    if token_ids_1 is not None:
        output += token_ids_1 + [self.sep_token_id]
    return output

Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A ConvBERT sequence has the following format:

- single sequence: `[CLS] X [SEP]`
- pair of sequences: `[CLS] A [SEP] B [SEP]`

Args:
token_ids_0 (`List[int]`):
List of IDs to which the special tokens will be added.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.

Returns:
`List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.


def retrieve_differences(self, id_or_uri, content, timeout=(- 1)):
    uri = ((self.URI + '/differences/') + extract_id_from_uri(id_or_uri))
    return self._client.create(content, uri=uri, timeout=timeout)

Retrieves the modified contents of the selected Plan Script according to the provided content object, as per
the selected attributes.

Args:
id_or_uri: ID or URI of the Plan Script.
content (str): Plan Script content.
timeout:
Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
in OneView, it just stops waiting for its completion.

Returns:
dict: Script differences.


def show(self, progress, msg=None):

        if self.whole_tag.style.display == "none":
            self.whole_tag.style.display = "block"

        if isinstance(progress, int) or isinstance(progress, float):
            percentage = progress
        else:
            percentage = self.__class__._compute_percentage(progress)

        self.tag.class_name = "progress-bar"
        if percentage < 100:
            self.tag.class_name += " progress-bar-striped active"
        else:
            msg = "Hotovo"

        self.tag.aria_valuemin = percentage
        self.tag.style.width = "{}%".format(percentage)

        if msg:
            self.tag.text = msg

Show the progress bar and set it to `progress` tuple or value.

Args:
progress (tuple / int / float): Tuple ``(done / len(all))`` or
the direct percentage value as int / float.
msg (str, default None): Alternative background description.


def db_en004(self, value=None):
    if (value is not None):
        try:
            value = float(value)
        except ValueError:
            raise ValueError('value {} need to be of type float for field `db_en004`'.format(value))
    self._db_en004 = value

Corresponds to IDD Field `db_en004`
mean coincident dry-bulb temperature to
Enthalpy corresponding to 0.4% annual cumulative frequency of occurrence

Args:
value (float): value for IDD Field `db_en004`
Unit: C
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

Raises:
ValueError: if `value` is not a valid value


def GetMetadataLegacy(client, token=None):
    if isinstance(client, rdfvalue.RDFURN):
        client_fd = aff4.FACTORY.Open(client, mode='r', token=token)
    else:
        client_fd = client
    metadata = ExportedMetadata()
    metadata.client_urn = client_fd.urn
    metadata.client_age = client_fd.urn.age
    metadata.hostname = utils.SmartUnicode(client_fd.Get(client_fd.Schema.HOSTNAME, ''))
    metadata.os = utils.SmartUnicode(client_fd.Get(client_fd.Schema.SYSTEM, ''))
    metadata.uname = utils.SmartUnicode(client_fd.Get(client_fd.Schema.UNAME, ''))
    metadata.os_release = utils.SmartUnicode(client_fd.Get(client_fd.Schema.OS_RELEASE, ''))
    metadata.os_version = utils.SmartUnicode(client_fd.Get(client_fd.Schema.OS_VERSION, ''))
    kb = client_fd.Get(client_fd.Schema.KNOWLEDGE_BASE)
    usernames = ''
    if kb:
        usernames = ([user.username for user in kb.users] or '')
    metadata.usernames = utils.SmartUnicode(usernames)
    metadata.mac_address = utils.SmartUnicode(client_fd.Get(client_fd.Schema.MAC_ADDRESS, ''))
    system_labels = set()
    user_labels = set()
    for l in client_fd.GetLabels():
        if (l.owner == 'GRR'):
            system_labels.add(l.name)
        else:
            user_labels.add(l.name)
    metadata.labels = ','.join(sorted((system_labels | user_labels)))
    metadata.system_labels = ','.join(sorted(system_labels))
    metadata.user_labels = ','.join(sorted(user_labels))
    metadata.hardware_info = client_fd.Get(client_fd.Schema.HARDWARE_INFO)
    metadata.kernel_version = client_fd.Get(client_fd.Schema.KERNEL)
    return metadata

Builds ExportedMetadata object for a given client id.

Note: This is a legacy aff4-only implementation.
TODO(user): deprecate as soon as REL_DB migration is done.

Args:
client: RDFURN of a client or VFSGRRClient object itself.
token: Security token.

Returns:
ExportedMetadata object with metadata of the client.


def UploadImageAsset(client, url):
    asset_service = client.GetService('AssetService', version='v201809')
    image_request = requests.get(url)
    image_asset = {'xsi_type': 'ImageAsset', 'imageData': image_request.content}
    operation = {'operator': 'ADD', 'operand': image_asset}
    result = asset_service.mutate([operation])
    return result['value'][0]['assetId']

Uploads the image from the specified url.

Args:
client: An AdWordsClient instance.
url: The image URL.

Returns:
The ID of the uploaded image.


def fix(self, value=None):
    if (value is None):
        self._impl.fix()
    else:
        self._impl.fix(value)

Fix all instances of this variable to a value if provided or to
their current value otherwise.

Args:
value: value to be set.


def _move_bee(self, bee, new_values):

        score = np.nan_to_num(new_values[0])
        if bee.score > score:
            bee.failed_trials += 1
        else:
            bee.values = new_values[1]
            bee.score = score
            bee.error = new_values[2]
            bee.failed_trials = 0
            self._logger.log('debug', 'Bee assigned to new merged position')

Moves a bee to a new position if new fitness score is better than
the bee's current fitness score

Args:
bee (EmployerBee): bee to move
new_values (tuple): (new score, new values, new fitness function
return value)


def getFluvialLinks(self):
    fluvialTypeKeywords = ('TRAPEZOID', 'TRAP', 'BREAKPOINT', 'ERODE', 'SUBSURFACE')
    fluvialLinks = []
    for link in self.streamLinks:
        for fluvialTypeKeyword in fluvialTypeKeywords:
            if (fluvialTypeKeyword in link.type):
                fluvialLinks.append(link)
                break
    return fluvialLinks

Retrieve only the links that represent fluvial portions of the stream. Returns a list of StreamLink instances.

Returns:
list: A list of fluvial :class:`.StreamLink` objects.


class StructureModuleConfig:
    sequence_dim: int = 384
    pairwise_dim: int = 128
    ipa_dim: int = 16
    resnet_dim: int = 128
    num_heads_ipa: int = 12
    num_qk_points: int = 4
    num_v_points: int = 8
    dropout_rate: float = 0.1
    num_blocks: int = 8
    num_transition_layers: int = 1
    num_resnet_blocks: int = 2
    num_angles: int = 7
    trans_scale_factor: int = 10
    epsilon: float = 1e-08
    inf: float = 100000.0

    def to_dict(self):
        return asdict(self)

Args:
sequence_dim:
Single representation channel dimension
pairwise_dim:
Pair representation channel dimension
ipa_dim:
IPA hidden channel dimension
resnet_dim:
Angle resnet (Alg. 23 lines 11-14) hidden channel dimension
num_heads_ipa:
Number of IPA heads
num_qk_points:
Number of query/key points to generate during IPA
num_v_points:
Number of value points to generate during IPA
dropout_rate:
Dropout rate used throughout the layer
num_blocks:
Number of structure module blocks
num_transition_layers:
Number of layers in the single representation transition (Alg. 23 lines 8-9)
num_resnet_blocks:
Number of blocks in the angle resnet
num_angles:
Number of angles to generate in the angle resnet
trans_scale_factor:
Scale of single representation transition hidden dimension
epsilon:
Small number used in angle resnet normalization
inf:
Large number used for attention masking


def validate_wrapped(self) -> None:
    if self.has_value():
        validate_primitive_json_representation(self.wrapped.DESCRIPTOR, self.string_value())
    else:
        validate_primitive_without_value(self.wrapped)

Validates the underlying wrapped value.

Raises:
fhir_errors.InvalidFhirError: In the event that the wrapped value doesn't
conform to the FHIR standard.


def origin(self):
    with self.selenium.context(self.selenium.CONTEXT_CHROME):
        return self.root.get_attribute('origin')

Provide access to the notification origin.

Returns:
str: The notification origin.


def typed_returnvalue(self, type_name, formatter=None):
    self.return_info = ReturnInfo(type_name, formatter, True, None)

Add type information to the return value of this function.

Args:
type_name (str): The name of the type of the return value.
formatter (str): An optional name of a formatting function specified
for the type given in type_name.


def diff_fromDelta(self, text1, delta):

    diffs = []
    pointer = 0
    tokens = delta.split("\t")
    for token in tokens:
      if token == "":

        continue

      param = token[1:]
      if token[0] == "+":
        param = urllib.parse.unquote(param)
        diffs.append((self.DIFF_INSERT, param))
      elif token[0] == "-" or token[0] == "=":
        try:
          n = int(param)
        except ValueError:
          raise ValueError("Invalid number in diff_fromDelta: " + param)
        if n < 0:
          raise ValueError("Negative number in diff_fromDelta: " + param)
        text = text1[pointer : pointer + n]
        pointer += n
        if token[0] == "=":
          diffs.append((self.DIFF_EQUAL, text))
        else:
          diffs.append((self.DIFF_DELETE, text))
      else:

        raise ValueError("Invalid diff operation in diff_fromDelta: " +
            token[0])
    if pointer != len(text1):
      raise ValueError(
          "Delta length (%d) does not equal source text length (%d)." %
         (pointer, len(text1)))
    return diffs

Given the original text1, and an encoded string which describes the
operations required to transform text1 into text2, compute the full diff.

Args:
text1: Source string for the diff.
delta: Delta text.

Returns:
Array of diff tuples.

Raises:
ValueError: If invalid input.


def get_stage(self, matrix_name, stage_name):
    found_stage = None
    if (matrix_name in self.data):
        result = Select(self.data[matrix_name]).where((lambda entry: (entry.stage == stage_name))).build()
        found_stage = (result[0] if (len(result) > 0) else None)
    return found_stage

Get Stage of a concrete matrix.

Attributes:
matrix_name (str): name of the matrix
stage_name (str): name of the stage.

Returns:
CollectorStage: when stage has been found or None.


def __init__(self, key):

    if not isinstance(key, (int, long, basestring)):
      raise TypeError('Parameter key must be an integer or string, not %s' %
                      (key,))
    self.__key = key

Constructor.

Args:
key: The Parameter key, must be either an integer or a string.


def save_index(self, filename):
    data = {}
    for f in self.files.values():
        entities = {v.entity.id: v.value for (k, v) in f.tags.items()}
        data[f.path] = {'domains': f.domains, 'entities': entities}
    with open(filename, 'w') as outfile:
        json.dump(data, outfile)

Save the current Layout's index to a .json file.

Args:
filename (str): Filename to write to.

Note: At the moment, this won't serialize directory-specific config
files. This means reconstructed indexes will only work properly in
cases where there aren't multiple layout specs within a project.


def register_gate(name, gateclass, allow_overwrite=False):

        if hasattr(Circuit, name):
            if allow_overwrite:
                warnings.warn(f"Circuit has attribute `{name}`.")
            else:
                raise ValueError(f"Circuit has attribute `{name}`.")
        if name.startswith("run_with_"):
            if allow_overwrite:
                warnings.warn(f"Gate name `{name}` may conflict with run of backend.")
            else:
                raise ValueError(f"Gate name `{name}` shall not start with 'run_with_'.")
        if not allow_overwrite:
            if name in GATE_SET:
                raise ValueError(f"Gate '{name}' is already exists in gate set.")
            if name in GLOBAL_MACROS:
                raise ValueError(f"Macro '{name}' is already exists.")
        GATE_SET[name] = gateclass

Register new gate to gate set.

Args:
name (str): The name of gate.
gateclass (type): The type object of gate.
allow_overwrite (bool, optional): If True, allow to overwrite the existing gate.
Otherwise, raise the ValueError.

Raises:
ValueError: The name is duplicated with existing gate.
When `allow_overwrite=True`, this error is not raised.


def run_step(self, is_shell):

        assert is_shell is not None, ("is_shell param must exist for CmdStep.")

        if is_shell:
            args = self.cmd_text
        else:
            args = shlex.split(self.cmd_text)

        if self.is_save:
            completed_process = subprocess.run(args,
                                               cwd=self.cwd,
                                               shell=is_shell,

                                               stdout=subprocess.PIPE,
                                               stderr=subprocess.PIPE,

                                               universal_newlines=True)
            self.context['cmdOut'] = {
                'returncode': completed_process.returncode,
                'stdout': completed_process.stdout,
                'stderr': completed_process.stderr
            }

            self.logger.info(f"stdout: {completed_process.stdout}")
            if completed_process.stderr:
                self.logger.error(f"stderr: {completed_process.stderr}")

            completed_process.check_returncode()
        else:

            subprocess.run(args, shell=is_shell, check=True, cwd=self.cwd)

Run a command.

Runs a program or executable. If is_shell is True, executes the command
through the shell.

Args:
is_shell: bool. defaults False. Set to true to execute cmd through
the default shell.


def get_edge(self, source: Node, target: Node) -> Optional[Edge]:

        return self.get_edge_by_index(source.index, target.index)

Returns the edge connection the given nodes if such an edge exists.

Arguments:
source (Node): One of the endpoints of the queried edge.
target (Node): The other endpoint of the queried edge.

Returns:
Returns the edge connection the given nodes
or `None` if no such node exists.


def get_slot(self, var, name):
    named_slots = self._slots.get(name, None)
    if not named_slots:
        return None
    slot = named_slots.get(_var_key(var), None)
    if distribute_utils.is_distributed_variable(slot) and (not distribute_utils.is_distributed_variable(var)):
        slot = slot._get_on_device_or_primary()
    return slot

Return a slot named `name` created for `var` by the Optimizer.

Some `Optimizer` subclasses use additional variables.  For example
`Momentum` and `Adagrad` use variables to accumulate updates.  This method
gives access to these `Variable` objects if for some reason you need them.

Use `get_slot_names()` to get the list of slot names created by the
`Optimizer`.

Args:
var: A variable passed to `minimize()` or `apply_gradients()`.
name: A string.

Returns:
The `Variable` for the slot if it was created, `None` otherwise.


def delete(self, membershipId):
    check_type(membershipId, basestring, may_be_none=False)
    self._session.delete(((API_ENDPOINT + '/') + membershipId))

Delete a team membership, by ID.

Args:
membershipId(basestring): The team membership ID.

Raises:
TypeError: If the parameter types are incorrect.
ApiError: If the Webex Teams cloud returns an error.


def in_template_path(fn):
    return os.path.join(os.path.abspath(os.path.dirname(__file__)), '../templates', fn)

Return `fn` in template context, or in other words add `fn` to template
path, so you don't need to write absolute path of `fn` in template
directory manually.

Args:
fn (str): Name of the file in template dir.

Return:
str: Absolute path to the file.


def _ConvertScalarFieldValue(value, field, require_str=False):
    if (field.cpp_type in _INT_TYPES):
        return _ConvertInteger(value)
    elif (field.cpp_type in _FLOAT_TYPES):
        return _ConvertFloat(value)
    elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_BOOL):
        return _ConvertBool(value, require_str)
    elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING):
        if (field.type == descriptor.FieldDescriptor.TYPE_BYTES):
            return base64.b64decode(value)
        else:
            if _UNPAIRED_SURROGATE_PATTERN.search(value):
                raise ParseError('Unpaired surrogate')
            return value
    elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM):
        enum_value = field.enum_type.values_by_name.get(value, None)
        if (enum_value is None):
            try:
                number = int(value)
                enum_value = field.enum_type.values_by_number.get(number, None)
            except ValueError:
                raise ParseError('Invalid enum value {0} for enum type {1}.'.format(value, field.enum_type.full_name))
            if (enum_value is None):
                raise ParseError('Invalid enum value {0} for enum type {1}.'.format(value, field.enum_type.full_name))
        return enum_value.number

Convert a single scalar field value.

Args:
value: A scalar value to convert the scalar field value.
field: The descriptor of the field to convert.
require_str: If True, the field value must be a str.

Returns:
The converted scalar field value

Raises:
ParseError: In case of convert problems.


def __init__(self, config={}):

        self._config = config

        self._headers = {}
        self._base_url = ""

        if config.get('session'):
            self._session = requests.Session()
        else:
            self._session = requests

Base class for interacting with RESTful APIs
Child class MUST have a ._base_url property!

Args:
config (dict): Arbitrary options that child classes can access


def company(self, **kwargs):
    path = self._get_path('company')
    response = self._GET(path, kwargs)
    self._set_attrs_to_values(response)
    return response

Search for companies by name.

Args:
query: CGI escpaed string.
page: (optional) Minimum value of 1. Expected value is an integer.

Returns:
A dict respresentation of the JSON returned from the API.


def trees_by_path(self, path):
    return set(self.path_db.get(path, OOSet()).keys())

Search trees by `path`.

Args:
path (str): :attr:`.Tree.path` property of :class:`.Tree`.

Returns:
set: Set of matching :class:`Tree` instances.


def LR_train(w, b, X, Y, num_iterations, learning_rate, print_cost=True):
    costs = []
    for i in range(num_iterations):
        (grads, cost) = propagate(w, b, X, Y)
        dw = grads['dw']
        db = grads['db']
        w = (w - (learning_rate * dw))
        b = (b - (learning_rate * db))
        if ((i % 100) == 0):
            costs.append(cost)
        if (print_cost and ((i % 100) == 0)):
            print(('Cost after iteration %i: %f' % (i, cost)))
    params = {'w': w, 'b': b}
    grads = {'dw': dw, 'db': db}
    return (params, grads, costs)

This function optimizes w and b by running a gradient descent algorithm

Arguments:
w       weights, a numpy array of size (dim, 1)
b       bias, a scalar
X       data of shape (dim, number of examples)
Y       true "label" vector, of shape (1, number of examples)
num_iterations      number of iterations of the optimization loop
learning_rate       learning rate of the gradient descent update rule
print_cost          True to print the loss every 100 steps

Returns:
params      dictionary containing the weights w and bias b
grads       dictionary containing the gradients of the weights and bias with respect to the cost function
costs       list of all the costs computed during the optimization, this will be used to plot the learning curve.


def args(self, args):
    self._args = args
    self._logger.log('debug', 'Args set to {}'.format(args))

Set additional arguments to be passed to the fitness function

Args:
args (dict): additional arguments


def Parse(self, filename, feed):
    dom = minidom.parse(filename)
    self.ParseDom(dom, feed)

Reads the kml file, parses it and updated the Google transit feed
object with the extracted information.

Args:
filename - kml file name
feed - an instance of Schedule class to be updated


def top(self, **kwargs):

        return self.client.api.top(self.id, **kwargs)

Display the running processes of the container.

Args:
ps_args (str): An optional arguments passed to ps (e.g. ``aux``)

Returns:
(str): The output of the top

Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.


def _calc_map_expectation_success(self, success_count, nonnull_count, mostly):
    if (nonnull_count > 0):
        percent_success = (success_count / nonnull_count)
        if (mostly != None):
            success = bool((percent_success >= mostly))
        else:
            success = bool(((nonnull_count - success_count) == 0))
    else:
        success = True
        percent_success = None
    return (success, percent_success)

Calculate success and percent_success for column_map_expectations

Args:
success_count (int): \
The number of successful values in the column
nonnull_count (int): \
The number of nonnull values in the column
mostly (float or None): \
A value between 0 and 1 (or None), indicating the percentage of successes required to pass the expectation as a whole\
If mostly=None, then all values must succeed in order for the expectation as a whole to succeed.

Returns:
success (boolean), percent_success (float)


def list_metric_defs_for_resource(access_token, subscription_id, resource_group,
                                  resource_provider, resource_type, resource_name):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/', resource_provider,
                        '/', resource_type,
                        '/', resource_name,
                        '/providers/microsoft.insights',
                        '/metricdefinitions?api-version=', INSIGHTS_METRICS_API])
    return do_get(endpoint, access_token)

List the monitoring metric definitions for a resource.

Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
resource_provider (str): Type of resource provider.
resource_type (str): Type of resource.
resource_name (str): Name of resource.

Returns:
HTTP response. JSON body of metric definitions.


def day(self, value=None):

        if value is not None:
            try:
                value = int(value)
            except ValueError:
                raise ValueError('value {} need to be of type int '
                                 'for field `day`'.format(value))
            if value < 1:
                raise ValueError('value need to be greater or equal 1 '
                                 'for field `day`')
            if value > 31:
                raise ValueError('value need to be smaller 31 '
                                 'for field `day`')

        self._day = value

Corresponds to IDD Field `day`

Args:
value (int): value for IDD Field `day`
value >= 1
value <= 31
if `value` is None it will not be checked against the
specification and is assumed to be a missing value

Raises:
ValueError: if `value` is not a valid value


def run_validation(options):

    if options.files == sys.stdin:
        results = validate(options.files, options)
        return [FileValidationResults(is_valid=results.is_valid,
                                      filepath='stdin',
                                      object_results=results)]

    files = get_json_files(options.files, options.recursive)

    results = [validate_file(fn, options) for fn in files]

    return results

Validate files based on command line options.

Args:
options: An instance of ``ValidationOptions`` containing options for
this validation run.


def add_auto_profiling(self, cmd, options, profile_steps):
    if not self._enabled:
        return
    self._auto_profiles.append((cmd, options, profile_steps[:]))
    self._slow_path_steps |= set(profile_steps)
    self._trace_steps |= set(profile_steps)

Traces and profiles at some session run steps.

Args:
cmd: The profiling commands. (i.e. scope, op, python, graph)
options: The profiling options.
profile_steps: A list/set of integers. The profiling command and options
will be run automatically at these integer steps. Each step is
a session.run.


def _get_args(cls, args):

        if isinstance(args, tuple):
            if not len(args) == 2:
                raise TypeError(
                    "{}[...] takes one or two argument.".format(cls.__name__)
                )
            return super(_ValidationBoundedMeta, cls)._get_args(
                (args[0], None, args[1])
            )
        return super(_ValidationBoundedMeta, cls)._get_args((Any, None, args))

Return the parameters necessary to check type boundaries.

Args:
args: A tuple with one or two parameters: A type to cast the
value passed, and a predicate function to use for bounds
checking.

Returns:
A tuple with three parameters: a type, a slice, and the predicate
function. If no type was passed in args, the type defaults to Any.


def get_learning_rate(self, iter):

        return self.init_lr * (self.gamma ** (iter

Get learning rate with exponential decay based on current iteration.

Args:
iter (int): Current iteration (starting with 0).

Returns:
float: Learning rate


def _get_num_multimodal_tokens(self, image_sizes=None, **kwargs):
    vision_data = {}
    if image_sizes is not None:
        images_kwargs = LlavaNextProcessorKwargs._defaults.get('images_kwargs', {})
        images_kwargs.update(kwargs)
        size = images_kwargs.get('size', None) or self.image_processor.size
        size = (size['shortest_edge'], size['shortest_edge']) if 'shortest_edge' in size else (min(size['height'], size['width']), min(size['height'], size['width']))
        processed_height, processed_width = size
        batch_num_image_tokens = []
        num_image_patches = [1] * len(image_sizes)
        for image_size in image_sizes:
            orig_height, orig_width = image_size
            num_image_tokens = self._get_number_of_features(orig_height, orig_width, processed_height, processed_width)
            if self.vision_feature_select_strategy == 'default':
                num_image_tokens -= 1
            batch_num_image_tokens.append(num_image_tokens)
        vision_data.update({'num_image_tokens': batch_num_image_tokens, 'num_image_patches': num_image_patches})
    return MultiModalData(**vision_data)

Computes the number of placeholder tokens needed for multimodal inputs with the given sizes.
Args:
image_sizes (List[List[str]], *optional*):
The input sizes formatted as (height, width) per each image.
video_sizes (List[List[str]], *optional*):
The input sizes formatted as (num_frames, height, width) per each video.
audio_lengths (List[int], *optional*):
The input length formatted as per each audio.
Returns:
Dict[str, List[int]]: A dictionary mapping each modality ("image", "video", "audio")
to a list containing the number of placeholder tokens required. If the model doesn't accept
a certain modality or no input sizes are provided, the dict value is set to an empty list.


def add_alias_or_constant(self, alias_or_constant):
    if isinstance(alias_or_constant, pytd.Constant):
        self.constants.append(alias_or_constant)
    elif isinstance(alias_or_constant, pytd.Alias):
        name, value = (alias_or_constant.name, alias_or_constant.type)
        self.type_map[name] = value
        self.aliases[name] = alias_or_constant
    else:
        assert False, 'Unknown type of assignment'

Add an alias or constant.

Args:
alias_or_constant: the top-level definition to add.


def resolve_provider(self, path):
    share = None
    lower_path = path.lower()
    for r in self.sorted_share_list:
        if (r == '/'):
            share = r
            break
        elif ((lower_path == r) or lower_path.startswith((r + '/'))):
            share = r
            break
    if (share is None):
        return (None, None)
    return (share, self.provider_map.get(share))

Get the registered DAVProvider for a given path.

Returns:
tuple: (share, provider)


def WriteTo(self, values):
    try:
        return self._struct.pack(*values)
    except (TypeError, struct.error) as exception:
        raise IOError('Unable to write stream with error: {0!s}'.format(exception))

Writes values to a byte stream.

Args:
values (tuple[object, ...]): values to copy to the byte stream.

Returns:
bytes: byte stream.

Raises:
IOError: if byte stream cannot be written.
OSError: if byte stream cannot be read.


def translate_gt(gt: torch.Tensor, max_num_bins: int, reg_scale: int, up: torch.Tensor):
    gt = gt.reshape(-1)
    function_values = weighting_function(max_num_bins, up, reg_scale)
    diffs = function_values.unsqueeze(0) - gt.unsqueeze(1)
    mask = diffs <= 0
    closest_left_indices = torch.sum(mask, dim=1) - 1
    indices = closest_left_indices.float()
    weight_right = torch.zeros_like(indices)
    weight_left = torch.zeros_like(indices)
    valid_idx_mask = (indices >= 0) & (indices < max_num_bins)
    valid_indices = indices[valid_idx_mask].long()
    left_values = function_values[valid_indices]
    right_values = function_values[valid_indices + 1]
    left_diffs = torch.abs(gt[valid_idx_mask] - left_values)
    right_diffs = torch.abs(right_values - gt[valid_idx_mask])
    weight_right[valid_idx_mask] = left_diffs / (left_diffs + right_diffs)
    weight_left[valid_idx_mask] = 1.0 - weight_right[valid_idx_mask]
    invalid_idx_mask_neg = indices < 0
    weight_right[invalid_idx_mask_neg] = 0.0
    weight_left[invalid_idx_mask_neg] = 1.0
    indices[invalid_idx_mask_neg] = 0.0
    invalid_idx_mask_pos = indices >= max_num_bins
    weight_right[invalid_idx_mask_pos] = 1.0
    weight_left[invalid_idx_mask_pos] = 0.0
    indices[invalid_idx_mask_pos] = max_num_bins - 0.1
    return (indices, weight_right, weight_left)

Decodes bounding box ground truth (GT) values into distribution-based GT representations.

This function maps continuous GT values into discrete distribution bins, which can be used
for regression tasks in object detection models. It calculates the indices of the closest
bins to each GT value and assigns interpolation weights to these bins based on their proximity
to the GT value.

Args:
gt (Tensor): Ground truth bounding box values, shape (N, ).
max_num_bins (int): Maximum number of discrete bins for the distribution.
reg_scale (float): Controls the curvature of the Weighting Function.
up (Tensor): Controls the upper bounds of the Weighting Function.

Returns:
Tuple[Tensor, Tensor, Tensor]:
- indices (Tensor): Index of the left bin closest to each GT value, shape (N, ).
- weight_right (Tensor): Weight assigned to the right bin, shape (N, ).
- weight_left (Tensor): Weight assigned to the left bin, shape (N, ).


def dot_solve(self, y):
        r
        return np.dot(y.T, cho_solve(self._factor, y))

r"""
Compute the inner product of a vector with the inverse of the
covariance matrix applied to itself:

.. math::

y\,K^{-1}\,y

Args:
y (ndarray[nsamples]): The vector :math:`y`.


def __init__(self, features):
    self._features = features.copy()
    self._feature_tensors = {}

Creates a `_LazyBuilder`.

Args:
features: A mapping from feature column to objects that are `Tensor` or
`SparseTensor`, or can be converted to same via
`sparse_tensor.convert_to_tensor_or_sparse_tensor`. A `string` key
signifies a base feature (not-transformed). A `_FeatureColumn` key means
that this `Tensor` is the output of an existing `_FeatureColumn` which
can be reused.


def validate(data, schema=None):
    schema = _load_schema_for_record(data, schema)
    return jsonschema_validate(instance=data, schema=schema, resolver=LocalRefResolver.from_schema(schema), format_checker=inspire_format_checker)

Validate the given dictionary against the given schema.

Args:
data (dict): record to validate.
schema (Union[dict, str]): schema to validate against. If it is a
string, it is intepreted as the name of the schema to load (e.g.
``authors`` or ``jobs``). If it is ``None``, the schema is taken
from ``data['$schema']``. If it is a dictionary, it is used
directly.

Raises:
SchemaNotFound: if the given schema was not found.
SchemaKeyNotFound: if ``schema`` is ``None`` and no ``$schema`` key was
found in ``data``.
jsonschema.SchemaError: if the schema is invalid.
jsonschema.ValidationError: if the data is invalid.


def load(self, name, *, arguments=None, validate_arguments=True, strict_dag=False):
    arguments = ({} if (arguments is None) else arguments)
    try:
        workflow_module = importlib.import_module(name)
        dag_present = False
        for (key, obj) in workflow_module.__dict__.items():
            if isinstance(obj, Dag):
                self._dags_blueprint[obj.name] = obj
                dag_present = True
            elif isinstance(obj, Parameters):
                self._parameters.extend(obj)
        self._name = name
        self._docstring = inspect.getdoc(workflow_module)
        del sys.modules[name]
        if (strict_dag and (not dag_present)):
            raise WorkflowImportError('Workflow does not include a dag {}'.format(name))
        if validate_arguments:
            missing_parameters = self._parameters.check_missing(arguments)
            if (len(missing_parameters) > 0):
                raise WorkflowArgumentError(('The following parameters are required ' + 'by the workflow, but are missing: {}'.format(', '.join(missing_parameters))))
        self._provided_arguments = arguments
    except (TypeError, ImportError):
        logger.error('Cannot import workflow {}'.format(name))
        raise WorkflowImportError('Cannot import workflow {}'.format(name))

Import the workflow script and load all known objects.

The workflow script is treated like a module and imported
into the Python namespace. After the import, the method looks
for instances of known classes and stores a reference for further
use in the workflow object.

Args:
name (str): The name of the workflow script.
arguments (dict): Dictionary of additional arguments that are ingested
into the data store prior to the execution of the workflow.
validate_arguments (bool): Whether to check that all required arguments have
been supplied.
strict_dag (bool): If true then the loaded workflow module must contain an
instance of Dag.

Raises:
WorkflowArgumentError: If the workflow requires arguments to be set that
were not supplied to the workflow.
WorkflowImportError: If the import of the workflow fails.


def Lookup(self, name):
    if (name == '@'):
        return self.stack[(- 1)].context
    parts = name.split('.')
    value = self._LookUpStack(parts[0])
    for part in parts[1:]:
        try:
            value = value[part]
        except (KeyError, TypeError):
            return self._Undefined(part)
    return value

Get the value associated with a name in the current context.

The current context could be an dictionary in a list, or a dictionary
outside a list.

Args:
name: name to lookup, e.g. 'foo' or 'foo.bar.baz'

Returns:
The value, or self.undefined_str

Raises:
UndefinedVariable if self.undefined_str is not set


def setDataFrame(self, dataFrame):

        if not isinstance(dataFrame, pandas.core.frame.DataFrame):
            raise TypeError('Argument is not of type pandas.core.frame.DataFrame')

        self.layoutAboutToBeChanged.emit()
        self._dataFrame = dataFrame
        self.layoutChanged.emit()

setter function to _dataFrame. Holds all data.

Note:
It's not implemented with python properties to keep Qt conventions.

Raises:
TypeError: if dataFrame is not of type pandas.core.frame.DataFrame.

Args:
dataFrame (pandas.core.frame.DataFrame): assign dataFrame to _dataFrame. Holds all the data displayed.


def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, position_embeddings: Optional[torch.Tensor]=None, output_attentions: bool=False, **kwargs):
    residual = hidden_states
    if self.normalize_before:
        hidden_states = self.self_attn_layer_norm(hidden_states)
    hidden_states, attn_weights = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, position_embeddings=position_embeddings, output_attentions=output_attentions)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    if not self.normalize_before:
        hidden_states = self.self_attn_layer_norm(hidden_states)
    if self.normalize_before:
        hidden_states = self.final_layer_norm(hidden_states)
    residual = hidden_states
    hidden_states = self.activation_fn(self.fc1(hidden_states))
    hidden_states = nn.functional.dropout(hidden_states, p=self.activation_dropout, training=self.training)
    hidden_states = self.fc2(hidden_states)
    hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
    hidden_states = residual + hidden_states
    if not self.normalize_before:
        hidden_states = self.final_layer_norm(hidden_states)
    if self.training:
        if torch.isinf(hidden_states).any() or torch.isnan(hidden_states).any():
            clamp_value = torch.finfo(hidden_states.dtype).max - 1000
            hidden_states = torch.clamp(hidden_states, min=-clamp_value, max=clamp_value)
    outputs = (hidden_states,)
    if output_attentions:
        outputs += (attn_weights,)
    return outputs

Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, target_len, source_len)` where padding elements are indicated by very large negative
values.
position_embeddings (`torch.FloatTensor`, *optional*):
Object queries (also called content embeddings), to be added to the hidden states.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.


def save(self, **kwargs):

        updated_data = self._get_updated_data()

        if not updated_data:
            return

        obj_id = self.get_id()
        server_data = self.manager.update(obj_id, updated_data, **kwargs)
        if server_data is not None:
            self._update_attrs(server_data)

Save the changes made to the object to the server.

The object is updated to match what the server returns.

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

Raise:
GitlabAuthenticationError: If authentication is not correct
GitlabUpdateError: If the server cannot perform the request


def partial_shape_to_tensor(shape_like):
    try:
        shape_like = tensor_shape.as_shape(shape_like)
        return ops.convert_to_tensor([dim if dim is not None else -1 for dim in shape_like.as_list()], dtype=dtypes.int64)
    except (TypeError, ValueError):
        ret = ops.convert_to_tensor(shape_like, preferred_dtype=dtypes.int64)
        if ret.shape.dims is not None and len(ret.shape.dims) != 1:
            raise ValueError('The given shape {} must be a 1-D tensor of `tf.int64` values, but the shape was {}.'.format(shape_like, ret.shape))
        if ret.dtype != dtypes.int64:
            raise TypeError('The given shape {} must be a 1-D tensor of `tf.int64` values, but the element type was {}.'.format(shape_like, ret.dtype.name))
        return ret

Returns a `tf.Tensor` that represents the given shape.

Args:
shape_like: A value that can be converted to a `tf.TensorShape` or a
`tf.Tensor`.

Returns:
A 1-D `tf.Tensor` of `tf.int64` elements representing the given shape, where
`-1` is substituted for any unknown dimensions.


def call(self, input_ids: TFModelInputType | None=None, attention_mask: np.ndarray | tf.Tensor | None=None, token_type_ids: np.ndarray | tf.Tensor | None=None, position_ids: np.ndarray | tf.Tensor | None=None, head_mask: np.ndarray | tf.Tensor | None=None, inputs_embeds: np.ndarray | tf.Tensor | None=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, training: Optional[bool]=False) -> Union[TFElectraForPreTrainingOutput, Tuple[tf.Tensor]]:
    discriminator_hidden_states = self.electra(input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids, position_ids=position_ids, head_mask=head_mask, inputs_embeds=inputs_embeds, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, training=training)
    discriminator_sequence_output = discriminator_hidden_states[0]
    logits = self.discriminator_predictions(discriminator_sequence_output)
    if not return_dict:
        return (logits,) + discriminator_hidden_states[1:]
    return TFElectraForPreTrainingOutput(logits=logits, hidden_states=discriminator_hidden_states.hidden_states, attentions=discriminator_hidden_states.attentions)

Returns:

Examples:

```python
>>> import tensorflow as tf
>>> from transformers import AutoTokenizer, TFElectraForPreTraining

>>> tokenizer = AutoTokenizer.from_pretrained("google/electra-small-discriminator")
>>> model = TFElectraForPreTraining.from_pretrained("google/electra-small-discriminator")
>>> input_ids = tf.constant(tokenizer.encode("Hello, my dog is cute"))[None, :]  # Batch size 1
>>> outputs = model(input_ids)
>>> scores = outputs[0]
```


def make_decoder(base_depth, activation, input_size, output_shape):

  deconv = functools.partial(
      tf.keras.layers.Conv2DTranspose, padding="SAME", activation=activation)
  conv = functools.partial(
      tf.keras.layers.Conv2D, padding="SAME", activation=activation)
  decoder_net = tf.keras.Sequential([
      tf.keras.layers.Reshape((1, 1, input_size)),
      deconv(2 * base_depth, 7, padding="VALID"),
      deconv(2 * base_depth, 5),
      deconv(2 * base_depth, 5, 2),
      deconv(base_depth, 5),
      deconv(base_depth, 5, 2),
      deconv(base_depth, 5),
      conv(output_shape[-1], 5, activation=None),
      tf.keras.layers.Reshape(output_shape),
  ])

  def decoder(codes):

    logits = decoder_net(codes)
    return tfd.Independent(tfd.Bernoulli(logits=logits),
                           reinterpreted_batch_ndims=len(output_shape),
                           name="decoder_distribution")

  return decoder

Creates the decoder function.

Args:
base_depth: Layer base depth in decoder net.
activation: Activation function in hidden layers.
input_size: The flattened latent input shape as an int.
output_shape: The output image shape as a list.

Returns:
decoder: A `callable` mapping a `Tensor` of encodings to a
`tfd.Distribution` instance over images.


def CheckHashes(hash_ids):
    return {k: bool(v) for (k, v) in data_store.REL_DB.ReadHashBlobReferences(hash_ids).items()}

Checks if files with given hashes are present in the file store.

Args:
hash_ids: A list of SHA256HashID objects.

Returns:
A dict where SHA256HashID objects are keys. Corresponding values
may be False (if hash id is not present) or True if it is not present.


def _get_required_param(self, param_name):

    value = self.request.get(param_name)
    if not value:
      raise errors.NotEnoughArgumentsError(param_name + " not specified")
    return value

Get a required request parameter.

Args:
param_name: name of request parameter to fetch.

Returns:
parameter value

Raises:
errors.NotEnoughArgumentsError: if parameter is not specified.


def get_servo_status_detail(self):

        data = []
        data.append(0x09)
        data.append(self.servoid)
        data.append(RAM_READ_REQ)
        data.append(STATUS_DETAIL_RAM)
        data.append(BYTE1)
        send_data(data)
        rxdata = []
        try:
            rxdata = SERPORT.read(12)
            return ord(rxdata[9])&0xFF
        except HerkulexError:
            raise HerkulexError("could not communicate with motors")

Get the  detailed error status of servo

This function gets the  detailed error status (if any) of the servo

Args:
none

Returns:
int:  an integer corresponding to the servo status
* refer datasheet


def feed_amount(self, amount):

        n = None
        if amount=='1/8':
            amount = '0'
        elif amount=='1/6':
            amount = '2'
        elif re.search('/180', amount):
            n = re.search(r"(\d+)/180", amount)
            n = n.group(1)
            amount = '3'
        elif re.search('/60', amount):
            n = re.search(r"(\d+)/60", amount)
            n = n.group(1)
            amount = 'A'
        if n:
            self.send(chr(27)+amount+n)
        else:
            self.send(chr(27)+amount)

Calling this function sets the form feed amount to the specified setting.

Args:
amount: the form feed setting you desire. Options are '1/8', '1/6', 'x/180', and 'x/60',
with x being your own desired amount. X must be a minimum of 24 for 'x/180' and 8 for 'x/60'
Returns:
None
Raises:
None


def save_component(self, component_name, save_path):

        component = self.get_component(component_name=component_name)
        self._validate_savable(component=component, component_name=component_name)
        return component.save(sess=self.session, save_path=save_path)

Saves a component of this model to the designated location.

Args:
component_name: The component to save.
save_path: The location to save to.
Returns:
Checkpoint path where the component was saved.


def _get_compatible_spec(value_or_spec1, value_or_spec2):
    spec1 = _get_spec_for(value_or_spec1)
    spec2 = _get_spec_for(value_or_spec2)
    common = spec1._without_tensor_names().most_specific_common_supertype([spec2._without_tensor_names()])
    if common is None:
        raise TypeError(f'No common supertype of {spec1} and {spec2}.')
    return common

Returns the most specific compatible spec.

Args:
value_or_spec1: A TypeSpecs or a value that has a defined TypeSpec.
value_or_spec2: A TypeSpecs or a value that has a defined TypeSpec.

Returns:
The most specific compatible TypeSpecs of the input.

Raises:
ValueError: If value_or_spec1 is not compatible with value_or_spec2.


def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None,
                             containing_type=None, scope=None):

    if package:
      enum_name = '.'.join((package, enum_proto.name))
    else:
      enum_name = enum_proto.name

    if file_desc is None:
      file_name = None
    else:
      file_name = file_desc.name

    values = [self._MakeEnumValueDescriptor(value, index)
              for index, value in enumerate(enum_proto.value)]
    desc = descriptor.EnumDescriptor(name=enum_proto.name,
                                     full_name=enum_name,
                                     filename=file_name,
                                     file=file_desc,
                                     values=values,
                                     containing_type=containing_type,
                                     options=enum_proto.options)
    scope['.%s' % enum_name] = desc
    self._enum_descriptors[enum_name] = desc
    return desc

Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.

Args:
enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message.
package: Optional package name for the new message EnumDescriptor.
file_desc: The file containing the enum descriptor.
containing_type: The type containing this enum.
scope: Scope containing available types.

Returns:
The added descriptor


def __init__(
        self,
        name,
        named_tensors=None,
        scope='output',
        summary_labels=()
    ):

        self.name = name
        super(Output, self).__init__(named_tensors=named_tensors, scope=scope, summary_labels=summary_labels)

Output layer.

Args:
output: A string that names the tensor, will be added to available inputs


def _to_key_ranges_by_shard(cls, app, namespaces, shard_count, query_spec):

    key_ranges_by_ns = []

    for namespace in namespaces:
      ranges = cls._split_ns_by_scatter(
          shard_count,
          namespace,
          query_spec.entity_kind,
          app)

      random.shuffle(ranges)
      key_ranges_by_ns.append(ranges)

    ranges_by_shard = [[] for _ in range(shard_count)]
    for ranges in key_ranges_by_ns:
      for i, k_range in enumerate(ranges):
        if k_range:
          ranges_by_shard[i].append(k_range)

    key_ranges_by_shard = []
    for ranges in ranges_by_shard:
      if ranges:
        key_ranges_by_shard.append(key_ranges.KeyRangesFactory.create_from_list(
            ranges))
    return key_ranges_by_shard

Get a list of key_ranges.KeyRanges objects, one for each shard.

This method uses scatter index to split each namespace into pieces
and assign those pieces to shards.

Args:
app: app_id in str.
namespaces: a list of namespaces in str.
shard_count: number of shards to split.
query_spec: model.QuerySpec.

Returns:
a list of key_ranges.KeyRanges objects.


def add_ssa_ir(function, all_state_variables_instances):

    if not function.is_implemented:
        return

    init_definition = dict()
    for v in function.parameters:
        if v.name:
            init_definition[v.name] = (v, function.entry_point)
            function.entry_point.add_ssa_ir(Phi(LocalIRVariable(v), set()))

    for v in function.returns:
        if v.name:
            init_definition[v.name] = (v, function.entry_point)

    for (_, variable_instance) in all_state_variables_instances.items():
        if is_used_later(function.entry_point, variable_instance):

            function.entry_point.add_ssa_ir(Phi(StateIRVariable(variable_instance), set()))

    add_phi_origins(function.entry_point, init_definition, dict())

    for node in function.nodes:
        for (variable, nodes) in node.phi_origins_local_variables.values():
            if len(nodes)<2:
                continue
            if not is_used_later(node, variable):
                continue
            node.add_ssa_ir(Phi(LocalIRVariable(variable), nodes))
        for (variable, nodes) in node.phi_origins_state_variables.values():
            if len(nodes)<2:
                continue

            node.add_ssa_ir(Phi(StateIRVariable(variable), nodes))

    init_local_variables_instances = dict()
    for v in function.parameters:
        if v.name:
            new_var = LocalIRVariable(v)
            function.add_parameter_ssa(new_var)
            if new_var.is_storage:
                fake_variable = LocalIRVariable(v)
                fake_variable.name = 'STORAGE_'+fake_variable.name
                fake_variable.set_location('reference_to_storage')
                new_var.refers_to = {fake_variable}
                init_local_variables_instances[fake_variable.name] = fake_variable
            init_local_variables_instances[v.name] = new_var

    for v in function.returns:
        if v.name:
            new_var = LocalIRVariable(v)
            function.add_return_ssa(new_var)
            if new_var.is_storage:
                fake_variable = LocalIRVariable(v)
                fake_variable.name = 'STORAGE_'+fake_variable.name
                fake_variable.set_location('reference_to_storage')
                new_var.refers_to = {fake_variable}
                init_local_variables_instances[fake_variable.name] = fake_variable
            init_local_variables_instances[v.name] = new_var

    all_init_local_variables_instances = dict(init_local_variables_instances)

    init_state_variables_instances = dict(all_state_variables_instances)

    initiate_all_local_variables_instances(function.nodes, init_local_variables_instances, all_init_local_variables_instances)

    generate_ssa_irs(function.entry_point,
                     dict(init_local_variables_instances),
                     all_init_local_variables_instances,
                     dict(init_state_variables_instances),
                     all_state_variables_instances,
                     init_local_variables_instances,
                     [])

    fix_phi_rvalues_and_storage_ref(function.entry_point,
                                    dict(init_local_variables_instances),
                                    all_init_local_variables_instances,
                                    dict(init_state_variables_instances),
                                    all_state_variables_instances,
                                    init_local_variables_instances)

Add SSA version of the IR
Args:
function
all_state_variables_instances


def __init__(self, text: str):
    if '.' in text:
        raise KeyError(f"'.' cannot be used in key. Encountered: {text!r}.")
    super().__init__()
    self._text = text

Constructor.

Args:
text: string value of this key.

Raises:
KeyError: If key contains dots ('.'), which is not allowed.


def _rank(self) -> NoReturn:
    raise NotImplementedError()

Integer rank of this Tensor.

Unlike regular Tensors, the rank is always known for EagerTensors.

This is more performant than len(self._shape_tuple())

Returns:
Integer rank


def assert_compatible_matrix_dimensions(operator, x):
    assert_same_dd = check_ops.assert_equal(array_ops.shape(x)[-2], operator.domain_dimension_tensor(), message='Dimensions are not compatible.  shape[-2] of argument to be the same as this operator')
    return assert_same_dd

Assert that an argument to solve/matmul has proper domain dimension.

If `operator.shape[-2:] = [M, N]`, and `x.shape[-2:] = [Q, R]`, then
`operator.matmul(x)` is defined only if `N = Q`.  This `Op` returns an
`Assert` that "fires" if this is not the case.  Static checks are already
done by the base class `LinearOperator`.

Args:
operator:  `LinearOperator`.
x:  `Tensor`.

Returns:
`Assert` `Op`.


def SetTimelineName(self, timeline_name):

    self._timeline_name = timeline_name
    logger.info('Timeline name: {0:s}'.format(self._timeline_name))

Sets the timeline name.

Args:
timeline_name (str): timeline name.


def trace_tpu(self, graph, tensor_fetches, op_fetches=None, num_replicas=None, num_replicas_per_host=None, num_hosts=None):
    if isinstance(graph, func_graph.FuncGraph) or isinstance(graph, function._FuncGraph):
        logging.warning('Tensor Tracer is not supported for tracing FuncGraphs. Ignoring tracing.')
        return tensor_fetches
    if graph in TensorTracer._traced_graphs:
        logging.warning('Graph is already rewritten with tensor tracer, ignoring multiple calls.')
        return tensor_fetches
    else:
        TensorTracer._traced_graphs.add(graph)
    self._parameters = tensor_tracer_flags.TTParameters()
    self._tt_config.device_type = _DEVICE_TYPE_TPU
    self._tt_config.num_replicas = num_replicas
    self._tt_config.num_replicas_per_host = num_replicas_per_host
    self._tt_config.num_hosts = num_hosts
    if self._tt_config.num_replicas is not None:
        if self._tt_config.num_replicas_per_host is None:
            self._tt_config.num_replicas_per_host = 8
        if self._tt_config.num_hosts is None:
            self._tt_config.num_hosts = num_replicas
    if self._parameters.graph_dump_path:
        graph_io.write_graph(graph, self._parameters.graph_dump_path, 'graph_before_tt.pbtxt')
    with graph.as_default():
        self._add_replica_id_to_graph()
        tensor_fetches = self._trace_execution(graph, tensor_fetches, op_fetches, on_tpu=True)
    if self._parameters.graph_dump_path:
        graph_io.write_graph(graph, self._parameters.graph_dump_path, 'graph_after_tt.pbtxt')
    return tensor_fetches

Traces the tensors generated by TPU Ops in a TF graph.

Args:
graph: the graph of Ops executed on the TPU.
tensor_fetches: a (list,tuple,or a single object) of tensor fetches
returned by model_fn given to session.run. Function must be provided
with as least one tensor to fetch.
op_fetches: A list of op fetches returned by model_fn given to
session.run. op_fetches and tensor_fetches are used to determine the
nodes that will be executed. Can be None.
num_replicas: number of replicas used on the TPU.
num_replicas_per_host: number of replicas per TPU host.
num_hosts: total number of TPU hosts.

Returns:
tensor_fetches: an exact copy of tensor_fetches that has additional
dependencies.


class DistributedSamplerWithLoop(DistributedSampler):

    def __init__(self, dataset, batch_size, **kwargs):
        super().__init__(dataset, **kwargs)
        self.batch_size = batch_size

    def __iter__(self):
        indices = list(super().__iter__())
        remainder = 0 if len(indices) % self.batch_size == 0 else self.batch_size - len(indices) % self.batch_size
        start_remainder = 1 if self.rank < len(self.dataset) % self.num_replicas else 0
        indices += indices[start_remainder:start_remainder + remainder]
        return iter(indices)

Like a torch.utils.data.distributed.DistributedSampler` but loops at the end back to the beginning of the shuffled
samples to make each process have a round multiple of batch_size samples.

Args:
dataset (`torch.utils.data.Dataset`):
Dataset used for sampling.
batch_size (`int`):
The batch size used with this sampler
kwargs (`Dict[str, Any]`, *optional*):
All other keyword arguments passed to `DistributedSampler`.


def ask_yes_no(question, default='no', answer=None):
    u
    default = default.lower()
    yes = [u'yes', u'ye', u'y']
    no = [u'no', u'n']
    if default in no:
        help_ = u'[N/y]?'
        default = False
    else:
        default = True
        help_ = u'[Y/n]?'
    while 1:
        display = question + '\n' + help_
        if answer is None:
            log.debug(u'Under None')
            answer = six.moves.input(display)
            answer = answer.lower()
        if answer == u'':
            log.debug(u'Under blank')
            return default
        if answer in yes:
            log.debug(u'Must be true')
            return True
        elif answer in no:
            log.debug(u'Must be false')
            return False
        else:
            sys.stdout.write(u'Please answer yes or no only!\n\n')
            sys.stdout.flush()
            answer = None
            six.moves.input(u'Press enter to continue')
            sys.stdout.write('\n\n\n\n\n')
            sys.stdout.flush()

u"""Will ask a question and keeps prompting until
answered.

Args:

question (str): Question to ask end user

default (str): Default answer if user just press enter at prompt

answer (str): Used for testing

Returns:

(bool) Meaning:

True - Answer is  yes

False - Answer is no