本文整理汇总了Python中builtins.all方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.all方法的具体用法?Python builtins.all怎么用?Python builtins.all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类builtins
的用法示例。
在下文中一共展示了builtins.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def load(file):
"""
Wrapper around cPickle.load which accepts either a file-like object or
a filename.
Note that the NumPy binary format is not based on pickle/cPickle anymore.
For details on the preferred way of loading and saving files, see `load`
and `save`.
See Also
--------
load, save
"""
if isinstance(file, type("")):
file = open(file, "rb")
return pickle.load(file)
# These are all essentially abbreviations
# These might wind up in a special abbreviations module
示例2: control_dependencies
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def control_dependencies(dependencies, graph=None):
"""
Ensure that all `dependencies` are executed before any operations in this scope.
Parameters
----------
dependencies : list
Sequence of operations to be evaluted before evaluating any operations defined in this
scope.
"""
# Add dependencies to the graph
graph = Graph.get_active_graph(graph)
graph.dependencies.extend(dependencies)
yield
# Remove dependencies from the graph
del graph.dependencies[-len(dependencies):]
# pylint: disable=C0103
示例3: decorate
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def decorate(self, pos, data, is_first=True):
# We can use the tree position as table ID
self._table.register(pos)
row = self._table.get_row(pos)
# We use parent's decorate() method to give the name column a tree
# structure. But we also need the original update() method so we can
# apply new data to the widget. This is dirty but it works.
if row.exists('name'):
update_method = row.name.update
decowidget = super().decorate(pos, row.name, is_first=is_first)
decowidget.update = update_method
row.replace('name', decowidget)
# Wrap the whole row in a FileItemWidget with keymapping. This also
# applies all the other values besides the name (size, progress, etc).
file_widget = self._filewidgetcls(data, row)
self._widgets[data['id']] = file_widget
return file_widget
示例4: all_children
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def all_children(self, pos):
"""Yield (position, widget) tuples of all sub-nodes (leaves and parents)"""
ft = self._filetree
lb = self._listbox
def recurse(subpos):
widget = lb.body[subpos]
if ft.is_leaf(subpos):
yield (subpos, widget)
else:
# Yield sub-parent nodes, but not the starting node that was
# passed to us
if subpos != pos:
yield (subpos, widget)
new_subpos = ft.first_child_position(subpos)
while new_subpos is not None:
yield from recurse(new_subpos)
new_subpos = ft.next_sibling_position(new_subpos)
yield from recurse(pos)
示例5: extractall
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def extractall(patt, filename, tag=0, conv=None, encoding='utf-8'):
'''Extract all values from the capturing group ``tag`` of a matching regex
``patt`` in the file ``filename``.
:arg patt: The regex pattern to search.
Any standard Python `regular expression
<https://docs.python.org/3/library/re.html#regular-expression-syntax>`_
is accepted.
:arg filename: The name of the file to examine.
:arg encoding: The name of the encoding used to decode the file.
:arg tag: The regex capturing group to be extracted.
Group ``0`` refers always to the whole match.
Since the file is processed line by line, this means that group ``0``
returns the whole line that was matched.
:arg conv: A callable that takes a single argument and returns a new value.
If provided, it will be used to convert the extracted values before
returning them.
:returns: A list of the extracted values from the matched regex.
:raises reframe.core.exceptions.SanityError: In case of errors.
'''
return list(evaluate(x)
for x in extractiter(patt, filename, tag, conv, encoding))
示例6: avg
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def avg(iterable):
'''Return the average of all the elements of ``iterable``.'''
# We walk over the iterable manually in case this is a generator
total = 0
num_vals = None
for num_vals, val in builtins.enumerate(iterable, start=1):
total += val
if num_vals is None:
raise SanityError('attempt to get average on an empty container')
return total / num_vals
# Other utility functions
示例7: __init__
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def __init__(self):
# The tree, which should be built.
self._tree = []
# List of all open constructs
self._open_blocks = []
# Nodes to which the open blocks have to be appended when closed
self._path = []
# Nr. of open blocks when file was opened. Used for checking whether all
# blocks have been closed, when file processing finishes.
self._nr_prev_blocks = []
# Current node, to which content should be added
self._curnode = self._tree
# Current file
self._curfile = None
示例8: _partial_reduction
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def _partial_reduction(cls, tensor, axis, dtype, keepdims, combine_size, stage, kw=None):
from ..merge.concatenate import TensorConcatenate
kw = kw or {}
axes = sorted(combine_size.keys())
op_type = type(tensor.op)
combine_blocks = [cls._combine_split(i, combine_size, tensor.chunk_shape)
for i in range(tensor.ndim)]
combine_blocks_idxes = [range(len(blocks)) for blocks in combine_blocks]
chunks = []
for combine_block_idx, combine_block in zip(itertools.product(*combine_blocks_idxes),
itertools.product(*combine_blocks)):
chks = [tensor.cix[idx] for idx in itertools.product(*combine_block)]
if len(chks) > 1:
op = TensorConcatenate(axis=axes, dtype=chks[0].dtype)
chk = op.new_chunk(chks, shape=cls._concatenate_shape(tensor, combine_block),
order=tensor.order)
else:
chk = chks[0]
shape = tuple(s if i not in combine_size else 1
for i, s in enumerate(chk.shape) if keepdims or i not in combine_size)
agg_op = op_type(stage=stage, axis=axis, dtype=dtype, keepdims=keepdims, **kw)
chunk = agg_op.new_chunk([chk], shape=shape,
index=tuple(idx for i, idx in enumerate(combine_block_idx)
if keepdims or i not in combine_size),
order=tensor.order)
chunks.append(chunk)
nsplits = [
tuple(c.shape[i] for c in chunks if builtins.all(idx == 0 for j, idx in enumerate(c.index) if j != i))
for i in range(len(chunks[0].shape))]
shape = tuple(builtins.sum(nsplit) for nsplit in nsplits)
agg_op = op_type(stage=stage, axis=axis, dtype=dtype, keepdims=keepdims, combine_size=combine_size, **kw)
return agg_op.new_tensors([tensor], shape, order=tensor.order,
chunks=chunks, nsplits=nsplits)
示例9: execute_map
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def execute_map(cls, ctx, op):
arg_axis = cls.get_arg_axis(op.axis, op.inputs[0].ndim)
(in_chunk,), device_id, xp = as_same_device(
[ctx[c.key] for c in op.inputs], device=op.device, ret_extra=True)
func_name = getattr(cls, '_func_name')
agg_func_name = getattr(cls, '_agg_func_name')
arg_func = getattr(xp, func_name)
agg_func_name = getattr(xp, agg_func_name)
offset = op.offset
chunk = op.outputs[0]
with device(device_id):
vals = agg_func_name(in_chunk, axis=arg_axis).reshape(chunk.shape)
try:
arg = arg_func(in_chunk, axis=arg_axis).reshape(chunk.shape)
except ValueError:
# handle all NaN
arg = arg_func(xp.where(xp.isnan(in_chunk), np.inf, in_chunk),
axis=arg_axis).reshape(chunk.shape)
if arg_axis is None:
if xp == cp:
# we need to copy to do cpu computation, then copy back to gpu
# cuz unravel_index and ravel_multi_index are not implemented in cupy
in_chunk = in_chunk.get()
total_shape = op.total_shape
ind = np.unravel_index(arg.ravel()[0], in_chunk.shape)
total_ind = tuple(o + i for (o, i) in zip(offset, ind))
res = np.ravel_multi_index(total_ind, total_shape)
if xp == cp:
# copy back
with xp.cuda.Device(in_chunk.device.id):
arg[:] = xp.asarray(res)
else:
arg[:] = res
else:
arg += offset
ctx[op.outputs[0].key] = (vals, arg)
示例10: _validate_axis
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def _validate_axis(axis, ndim, argname):
try:
axis = [operator.index(axis)]
except TypeError:
axis = list(axis)
axis = [a + ndim if a < 0 else a for a in axis]
if not builtins.all(0 <= a < ndim for a in axis):
raise ValueError('invalid axis for this array in `%s` argument' %
argname)
if len(set(axis)) != len(axis):
raise ValueError('repeated axis in `%s` argument' % argname)
return axis
示例11: _maketup
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def _maketup(descr, val):
dt = dtype(descr)
# Place val in all scalar tuples:
fields = dt.fields
if fields is None:
return val
else:
res = [_maketup(fields[name][0], val) for name in dt.names]
return tuple(res)
示例12: identity
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def identity(n, dtype=None):
"""
Return the identity array.
The identity array is a square array with ones on
the main diagonal.
Parameters
----------
n : int
Number of rows (and columns) in `n` x `n` output.
dtype : data-type, optional
Data-type of the output. Defaults to ``float``.
Returns
-------
out : ndarray
`n` x `n` array with its main diagonal set to one,
and all other elements 0.
Examples
--------
>>> np.identity(3)
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
"""
from numpy import eye
return eye(n, dtype=dtype)
示例13: array_equal
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def array_equal(a1, a2):
"""
True if two arrays have the same shape and elements, False otherwise.
Parameters
----------
a1, a2 : array_like
Input arrays.
Returns
-------
b : bool
Returns True if the arrays are equal.
See Also
--------
allclose: Returns True if two arrays are element-wise equal within a
tolerance.
array_equiv: Returns True if input arrays are shape consistent and all
elements equal.
Examples
--------
>>> np.array_equal([1, 2], [1, 2])
True
>>> np.array_equal(np.array([1, 2]), np.array([1, 2]))
True
>>> np.array_equal([1, 2], [1, 2, 3])
False
>>> np.array_equal([1, 2], [1, 4])
False
"""
try:
a1, a2 = asarray(a1), asarray(a2)
except:
return False
if a1.shape != a2.shape:
return False
return bool(asarray(a1 == a2).all())
示例14: all
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def all(iterable):
"""
Returns True if all elements of the iterable are true.
"""
for element in iterable:
if not element:
return False
return True
示例15: all
# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import all [as 别名]
def all(a, axis=None, out=None, keepdims=False):
return (a, mark_non_coercible(out))