Python operator.__or__() Examples
The following are 30
code examples of operator.__or__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
operator
, or try the search function
.
Example #1
Source File: BitVector.py From ClusType with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: BitVector.py From knob with MIT License | 6 votes |
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)
Example #3
Source File: BitVector.py From knob with MIT License | 6 votes |
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
Example #4
Source File: backend_vsa.py From claripy with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #5
Source File: BitVector.py From ClusType with GNU General Public License v3.0 | 6 votes |
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
Example #6
Source File: test_pos_marker.py From insights-core with Apache License 2.0 | 6 votes |
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
Example #7
Source File: kvpairs.py From insights-core with Apache License 2.0 | 6 votes |
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
Example #8
Source File: index.py From c3nav with Apache License 2.0 | 5 votes |
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())
Example #9
Source File: bitwise_util.py From MARA_Framework with GNU Lesser General Public License v3.0 | 5 votes |
def propagateOr(x, y): return propagateBitwise(x, y, operator.__or__, True, False)
Example #10
Source File: typeinference.py From Adhrit with GNU General Public License v3.0 | 5 votes |
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)
Example #11
Source File: typeinference.py From apkutils with MIT License | 5 votes |
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)
Example #12
Source File: mnist_sslvae.py From semi-supervised-pytorch with MIT License | 5 votes |
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
Example #13
Source File: datautils.py From semi-supervised-pytorch with MIT License | 5 votes |
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
Example #14
Source File: typeinference.py From enjarify with Apache License 2.0 | 5 votes |
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)
Example #15
Source File: xorg.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 5 votes |
def _event_mask(self): """The event mask. """ return functools.reduce(operator.__or__, self._EVENTS, 0)
Example #16
Source File: test_arithmetic.py From py-flags with MIT License | 5 votes |
def test_or(self): self._test_incompatible_types_fail(operator.__or__) self.assertEqual(no_flags | no_flags, no_flags) self.assertEqual(no_flags | all_flags, all_flags) self.assertEqual(no_flags | f0, f0) self.assertEqual(no_flags | f1, f1) self.assertEqual(no_flags | f2, f2) self.assertEqual(no_flags | f01, f01) self.assertEqual(no_flags | f02, f02) self.assertEqual(no_flags | f12, f12) self.assertEqual(f0 | no_flags, f0) self.assertEqual(f0 | all_flags, all_flags) self.assertEqual(f0 | f0, f0) self.assertEqual(f0 | f1, f01) self.assertEqual(f0 | f2, f02) self.assertEqual(f0 | f01, f01) self.assertEqual(f0 | f02, f02) self.assertEqual(f0 | f12, all_flags) self.assertEqual(f01 | no_flags, f01) self.assertEqual(f01 | all_flags, all_flags) self.assertEqual(f01 | f0, f01) self.assertEqual(f01 | f1, f01) self.assertEqual(f01 | f2, all_flags) self.assertEqual(f01 | f01, f01) self.assertEqual(f01 | f02, all_flags) self.assertEqual(f01 | f12, all_flags) self.assertEqual(all_flags | no_flags, all_flags) self.assertEqual(all_flags | all_flags, all_flags) self.assertEqual(all_flags | f0, all_flags) self.assertEqual(all_flags | f1, all_flags) self.assertEqual(all_flags | f2, all_flags) self.assertEqual(all_flags | f01, all_flags) self.assertEqual(all_flags | f02, all_flags) self.assertEqual(all_flags | f12, all_flags)
Example #17
Source File: typeinference.py From TTDeDroid with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: BitVector.py From ClusType with GNU General Public License v3.0 | 5 votes |
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)
Example #19
Source File: BitVector.py From ClusType with GNU General Public License v3.0 | 5 votes |
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)
Example #20
Source File: BitVector.py From ClusType with GNU General Public License v3.0 | 5 votes |
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)
Example #21
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def __or__(self, other): if isinstance(other, TruthValue): conf = self.conf if self.conf < other.conf: conf = other.conf norm = np.sqrt(self.norm * other.norm) return TruthValue(norm, conf=conf) elif other is False: return self else: raise Exception()
Example #22
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def __ror__(self, other): return self.__or__(other)
Example #23
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def Tangent(line, twod): name = twod.__class__.__name__ if name == "circle": d = perpendicular_distance_between_line_and_point(line, twod.center) return Equals(d, twod.radius) elif issubtype(name, 'polygon'): out = reduce(operator.__or__, (PointLiesOnLine(point, line) for point in twod), False) return out raise Exception()
Example #24
Source File: typeinference.py From MARA_Framework with GNU Lesser General Public License v3.0 | 5 votes |
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)
Example #25
Source File: trequestpool.py From stig with GNU General Public License v3.0 | 5 votes |
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)
Example #26
Source File: typeinference.py From MobileSF with GNU General Public License v3.0 | 5 votes |
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)
Example #27
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def Isosceles(triangle): sides = [distance_between_points(triangle[index-1], point) for index, point in enumerate(triangle)] combs = itertools.combinations(sides, 2) out = reduce(operator.__or__, (Equals(a, b) for a, b in combs), False) return out
Example #28
Source File: backend_concrete.py From claripy with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #29
Source File: backend_z3.py From claripy with BSD 2-Clause "Simplified" License | 5 votes |
def _op_or(*args): return reduce(operator.__or__, args)
Example #30
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def IsRightTriangle(triangle): angles = _polygon_to_angles(triangle) tv = reduce(operator.__or__, (IsRightAngle(angle) for angle in angles), False) return tv