本文整理汇总了Python中operator.__or__方法的典型用法代码示例。如果您正苦于以下问题:Python operator.__or__方法的具体用法?Python operator.__or__怎么用?Python operator.__or__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.__or__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __or__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def __or__(self, other):
'''
Take a bitwise 'OR' of the bit vector on which the method is invoked with the
argument bit vector. Return the result as a new bit vector. If the two bit
vectors are not of the same size, pad the shorter one with zero's from the
left.
'''
if self.size < other.size:
bv1 = self._resize_pad_from_left(other.size - self.size)
bv2 = other
elif self.size > other.size:
bv1 = self
bv2 = other._resize_pad_from_left(self.size - other.size)
else:
bv1 = self
bv2 = other
res = BitVector( size = bv1.size )
lpb = map(operator.__or__, bv1.vector, bv2.vector)
res.vector = array.array( 'H', lpb )
return res
示例2: shift_right_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def shift_right_by_one(self):
'''
For a one-bit in-place right non-circular shift. Note that bitvector size
does not change. The rightmost bit that moves past the last element of the
bitvector is discarded and leftmost bit of the returned vector is set to
zero.
'''
size = len(self.vector)
right_most_bits = list(map( operator.__and__, self.vector, [0x8000]*size ))
self.vector = list(map( operator.__and__, self.vector, [~0x8000]*size ))
right_most_bits.insert(0, 0)
right_most_bits.pop()
self.vector = list(map(operator.__lshift__, self.vector, [1]*size))
self.vector = list(map( operator.__or__, self.vector, \
list(map(operator.__rshift__,right_most_bits, [15]*size))))
self._setbit(0, 0)
示例3: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def __init__(self):
Backend.__init__(self)
# self._make_raw_ops(set(expression_operations) - set(expression_set_operations), op_module=BackendVSA)
self._make_expr_ops(set(expression_set_operations), op_class=self)
self._make_raw_ops(set(backend_operations_vsa_compliant), op_module=BackendVSA)
self._op_raw['StridedInterval'] = BackendVSA.CreateStridedInterval
self._op_raw['ValueSet'] = ValueSet.__init__
self._op_raw['AbstractLocation'] = AbstractLocation.__init__
self._op_raw['Reverse'] = BackendVSA.Reverse
self._op_raw['If'] = self.If
self._op_expr['BVV'] = self.BVV
self._op_expr['BoolV'] = self.BoolV
self._op_expr['BVS'] = self.BVS
# reduceable
self._op_raw['__add__'] = self._op_add
self._op_raw['__sub__'] = self._op_sub
self._op_raw['__mul__'] = self._op_mul
self._op_raw['__or__'] = self._op_or
self._op_raw['__xor__'] = self._op_xor
self._op_raw['__and__'] = self._op_and
self._op_raw['__mod__'] = self._op_mod
示例4: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def __init__(self, sep_chars="=:", comment_chars="#;"):
eol_chars = set("\n\r")
sep_chars = set(sep_chars)
comment_chars = set(comment_chars)
key_chars = set(string.printable) - (sep_chars | eol_chars | comment_chars)
value_chars = set(string.printable) - (eol_chars | comment_chars)
OLC = reduce(operator.__or__, [OneLineComment(c) for c in comment_chars])
Comment = (WS >> OLC).map(lambda x: None)
Num = Number & (WSChar | LineEnd)
Key = WS >> PosMarker(String(key_chars).map(lambda x: x.strip())) << WS
Sep = InSet(sep_chars)
Value = WS >> (Num | String(value_chars).map(lambda x: x.strip()))
KVPair = (Key + Opt(Sep + Value, default=[None, None])).map(lambda a: (a[0], a[1][1]))
Line = Comment | KVPair | EOL.map(lambda x: None)
Doc = Many(Line).map(skip_none).map(to_entry)
self.Top = Doc + EOF
示例5: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def __init__(self, sep_chars="=:", comment_chars="#;"):
eol_chars = set("\n\r")
sep_chars = set(sep_chars)
comment_chars = set(comment_chars)
key_chars = set(string.printable) - (sep_chars | eol_chars | comment_chars)
value_chars = set(string.printable) - (eol_chars | comment_chars)
OLC = reduce(operator.__or__, [OneLineComment(c) for c in comment_chars])
Comment = (WS >> OLC).map(lambda x: None)
Num = Number & (WSChar | LineEnd)
Key = WS >> PosMarker(String(key_chars).map(str.strip)) << WS
Sep = InSet(sep_chars)
Value = WS >> (Num | String(value_chars).map(str.strip))
KVPair = (Key + Opt(Sep + Value, default=[None, None])).map(
lambda a: (a[0], a[1][1])
)
Line = Comment | KVPair | EOL.map(lambda x: None)
Doc = Many(Line).map(skip_none).map(to_entry)
self.Top = Doc + EOF
示例6: circular_rotate_left_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def circular_rotate_left_by_one(self):
'For a one-bit in-place left circular shift'
size = len(self.vector)
bitstring_leftmost_bit = self.vector[0] & 1
left_most_bits = list(map(operator.__and__, self.vector, [1]*size))
left_most_bits.append(left_most_bits[0])
del(left_most_bits[0])
self.vector = list(map(operator.__rshift__, self.vector, [1]*size))
self.vector = list(map( operator.__or__, self.vector, \
list( map(operator.__lshift__, left_most_bits, [15]*size) )))
self._setbit(self.size -1, bitstring_leftmost_bit)
示例7: circular_rotate_right_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def circular_rotate_right_by_one(self):
'For a one-bit in-place right circular shift'
size = len(self.vector)
bitstring_rightmost_bit = self[self.size - 1]
right_most_bits = list(map( operator.__and__,
self.vector, [0x8000]*size ))
self.vector = list(map( operator.__and__, self.vector, [~0x8000]*size ))
right_most_bits.insert(0, bitstring_rightmost_bit)
right_most_bits.pop()
self.vector = list(map(operator.__lshift__, self.vector, [1]*size))
self.vector = list(map( operator.__or__, self.vector, \
list(map(operator.__rshift__, right_most_bits, [15]*size))))
self._setbit(0, bitstring_rightmost_bit)
示例8: shift_left_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def shift_left_by_one(self):
'''
For a one-bit in-place left non-circular shift. Note that bitvector size
does not change. The leftmost bit that moves past the first element of the
bitvector is discarded and rightmost bit of the returned vector is set to
zero.
'''
size = len(self.vector)
left_most_bits = list(map(operator.__and__, self.vector, [1]*size))
left_most_bits.append(left_most_bits[0])
del(left_most_bits[0])
self.vector = list(map(operator.__rshift__, self.vector, [1]*size))
self.vector = list(map( operator.__or__, self.vector, \
list(map(operator.__lshift__, left_most_bits, [15]*size))))
self._setbit(self.size -1, 0)
示例9: _op_or
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def _op_or(*args):
return reduce(operator.__or__, args)
示例10: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def __init__(self):
Backend.__init__(self)
self._make_raw_ops(set(backend_operations) - { 'If' }, op_module=bv)
self._make_raw_ops(backend_strings_operations, op_module=strings)
self._make_raw_ops(backend_fp_operations, op_module=fp)
self._op_raw['If'] = self._If
self._op_raw['BVV'] = self.BVV
self._op_raw['StringV'] = self.StringV
self._op_raw['FPV'] = self.FPV
# reduceable
self._op_raw['__add__'] = self._op_add
self._op_raw['__sub__'] = self._op_sub
self._op_raw['__mul__'] = self._op_mul
self._op_raw['__or__'] = self._op_or
self._op_raw['__xor__'] = self._op_xor
self._op_raw['__and__'] = self._op_and
# unary
self._op_raw['__invert__'] = self._op_not
self._op_raw['__neg__'] = self._op_neg
# boolean ops
self._op_raw['And'] = self._op_and
self._op_raw['Or'] = self._op_or
self._op_raw['Xor'] = self._op_xor
self._op_raw['Not'] = self._op_boolnot
self._cache_objects = False
示例11: fromParams
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def fromParams(method, num_regs):
isstatic = method.access & flags.ACC_STATIC
full_ptypes = method.id.getSpacedParamTypes(isstatic)
offset = num_regs - len(full_ptypes)
prims = TreeList(scalars.INVALID, operator.__and__)
arrs = TreeList(arrays.INVALID, arrays.merge)
tainted = TreeList(False, operator.__or__)
for i, desc in enumerate(full_ptypes):
if desc is not None:
prims[offset + i] = scalars.fromDesc(desc)
arrs[offset + i] = arrays.fromDesc(desc)
return TypeInfo(prims, arrs, tainted)
示例12: _combine_requests
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def _combine_requests(self):
"""Create single request that combines keys and filters of all subscribers"""
if not self.has_subscribers:
# Don't request anything
log.debug('No subscribers - setting request to None')
self.set_request(None)
else:
kwargs = {}
all_filters = tuple(self._tfilters.values())
if not all_filters or None in all_filters:
# No subscribers or at least one subscriber wants all torrents
kwargs['torrents'] = None
else:
kwargs['torrents'] = reduce(operator.__or__, all_filters)
# Combine keys of all requests
kwargs['keys'] = reduce(lambda a,b: {*a,*b}, self._keys.values())
# Filters also need certain keys
for f in all_filters:
if f is not None:
kwargs['keys'].update(f.needed_keys)
log.debug('Combined filters: %s', kwargs['torrents'])
log.debug('Combined keys: %s', kwargs['keys'])
self.set_request(self._api.torrents, **kwargs)
示例13: propagateOr
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def propagateOr(x, y):
return propagateBitwise(x, y, operator.__or__, True, False)
示例14: intersection
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def intersection(self, geometry):
try:
geoms = geometry.geoms
except AttributeError:
return set(self._index.intersection(geometry.bounds))
else:
return reduce(operator.__or__, (self.intersection(geom) for geom in geoms), set())
示例15: get_mnist
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __or__ [as 别名]
def get_mnist(location="./", batch_size=64, labels_per_class=100):
from functools import reduce
from operator import __or__
from torch.utils.data.sampler import SubsetRandomSampler
from torchvision.datasets import MNIST
import torchvision.transforms as transforms
from utils import onehot
flatten_bernoulli = lambda x: transforms.ToTensor()(x).view(-1).bernoulli()
mnist_train = MNIST(location, train=True, download=True,
transform=flatten_bernoulli, target_transform=onehot(n_labels))
mnist_valid = MNIST(location, train=False, download=True,
transform=flatten_bernoulli, target_transform=onehot(n_labels))
def get_sampler(labels, n=None):
# Only choose digits in n_labels
(indices,) = np.where(reduce(__or__, [labels == i for i in np.arange(n_labels)]))
# Ensure uniform distribution of labels
np.random.shuffle(indices)
indices = np.hstack([list(filter(lambda idx: labels[idx] == i, indices))[:n] for i in range(n_labels)])
indices = torch.from_numpy(indices)
sampler = SubsetRandomSampler(indices)
return sampler
# Dataloaders for MNIST
labelled = torch.utils.data.DataLoader(mnist_train, batch_size=batch_size, num_workers=2, pin_memory=cuda,
sampler=get_sampler(mnist_train.train_labels.numpy(), labels_per_class))
unlabelled = torch.utils.data.DataLoader(mnist_train, batch_size=batch_size, num_workers=2, pin_memory=cuda,
sampler=get_sampler(mnist_train.train_labels.numpy()))
validation = torch.utils.data.DataLoader(mnist_valid, batch_size=batch_size, num_workers=2, pin_memory=cuda,
sampler=get_sampler(mnist_valid.test_labels.numpy()))
return labelled, unlabelled, validation