Python operator.__and__() Examples
The following are 30
code examples of operator.__and__().
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 knob with MIT License | 6 votes |
def __and__(self, other): ''' Take a bitwise 'AND' 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 zeros 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.__and__, bv1.vector, bv2.vector) res.vector = array.array( 'H', lpb ) return res
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: shared_uart.py From litex-buildenv with BSD 2-Clause "Simplified" License | 6 votes |
def do_finalize(self): if self.tx_signals: for tx_sig in self.tx_signals: self.comb += [ # TX tx_sig.eq(self.tx), ] if self.rx_signals: self.comb += [ # RX self.rx.eq(reduce(operator.__and__, self.rx_signals)) ] # FIXME: Add a test for the shared UART
Example #4
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 #5
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 #6
Source File: shared_uart.py From HDMI2USB-litex-firmware with BSD 2-Clause "Simplified" License | 6 votes |
def do_finalize(self): if self.tx_signals: for tx_sig in self.tx_signals: self.comb += [ # TX tx_sig.eq(self.tx), ] if self.rx_signals: self.comb += [ # RX self.rx.eq(reduce(operator.__and__, self.rx_signals)) ] # FIXME: Add a test for the shared UART
Example #7
Source File: BitVector.py From ClusType with GNU General Public License v3.0 | 6 votes |
def __and__(self, other): ''' Take a bitwise 'AND' 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 zeros 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.__and__, bv1.vector, bv2.vector) res.vector = array.array( 'H', lpb ) return res
Example #8
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 #9
Source File: monitor.py From DeepSea with GNU General Public License v3.0 | 5 votes |
def finish(self, event): self.targets[event.minion]['finished'] = True self.targets[event.minion]['success'] = event.success and event.retcode == 0 self.targets[event.minion]['event'] = event if reduce(operator.__and__, [t['finished'] for t in self.targets.values()]): self.success = reduce( operator.__and__, [t['success'] for t in self.targets.values()]) self.finished = True
Example #10
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 #11
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 #12
Source File: test_arithmetic.py From py-flags with MIT License | 5 votes |
def test_and(self): self._test_incompatible_types_fail(operator.__and__) self.assertEqual(no_flags & no_flags, no_flags) self.assertEqual(no_flags & all_flags, no_flags) self.assertEqual(no_flags & f0, no_flags) self.assertEqual(no_flags & f1, no_flags) self.assertEqual(no_flags & f2, no_flags) self.assertEqual(no_flags & f01, no_flags) self.assertEqual(no_flags & f02, no_flags) self.assertEqual(no_flags & f12, no_flags) self.assertEqual(f0 & no_flags, no_flags) self.assertEqual(f0 & all_flags, f0) self.assertEqual(f0 & f0, f0) self.assertEqual(f0 & f1, no_flags) self.assertEqual(f0 & f2, no_flags) self.assertEqual(f0 & f01, f0) self.assertEqual(f0 & f02, f0) self.assertEqual(f0 & f12, no_flags) self.assertEqual(f01 & no_flags, no_flags) self.assertEqual(f01 & all_flags, f01) self.assertEqual(f01 & f0, f0) self.assertEqual(f01 & f1, f1) self.assertEqual(f01 & f2, no_flags) self.assertEqual(f01 & f01, f01) self.assertEqual(f01 & f02, f0) self.assertEqual(f01 & f12, f1) self.assertEqual(all_flags & no_flags, no_flags) self.assertEqual(all_flags & all_flags, all_flags) self.assertEqual(all_flags & f0, f0) self.assertEqual(all_flags & f1, f1) self.assertEqual(all_flags & f2, f2) self.assertEqual(all_flags & f01, f01) self.assertEqual(all_flags & f02, f02) self.assertEqual(all_flags & f12, f12)
Example #13
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 #14
Source File: compatibility.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def all(items): return reduce(operator.__and__, items) # --- test if interpreter supports yield keyword ---
Example #15
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 #16
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 #17
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 #18
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def __and__(self, other): if isinstance(other, TruthValue): conf = self.conf if self.conf > other.conf: conf = other.conf norm = (self.norm + other.norm)/2.0 return TruthValue(norm, conf=conf) elif other is True: return self else: raise Exception()
Example #19
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def __rand__(self, other): return self.__and__(other)
Example #20
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def IsInscribedIn(triangle, circle): out = reduce(operator.__and__, (PointLiesOnCircle(point, circle) for point in triangle), True) return out
Example #21
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def IsCenterOf(point, twod): name = twod.__class__.__name__ if name == 'circle': return Equals(point[0], twod.center[0]) & Equals(point[1], twod.center[1]) elif issubtype(name, 'polygon'): distances = [distance_between_points(point, each) for each in twod] reg = IsRegular(twod) out = reduce(operator.__and__, (Equals(distances[index-1], distance) for index, distance in enumerate(distances)), True) return reg & out else: raise Exception()
Example #22
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def IntersectAt(lines, point): assert isinstance(lines, SetNode) out = reduce(operator.__and__, (PointLiesOnLine(point, line) for line in lines.children), True) return out
Example #23
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def IsRectangle(quad): lines = _polygon_to_lines(quad) out = reduce(operator.__and__, (Perpendicular(lines[index-1], line) for index, line in enumerate(lines)), True) return out
Example #24
Source File: ontology_semantics.py From geosolver with Apache License 2.0 | 5 votes |
def evaluate(formula, assignment): if not isinstance(formula, Node): return formula if not formula.is_grounded(assignment.keys()): return None if isinstance(formula, SetNode): if issubtype(formula.head.return_type, 'boolean'): out = reduce(operator.__and__, (evaluate(child, assignment) for child in formula.children), True) return out return formula if isinstance(formula.signature, VariableSignature): return assignment[formula.signature.id] elif is_number(formula.signature.id): return float(formula.signature.id) else: evaluated_args = [] for arg in formula.children: if isinstance(arg, FormulaNode): evaluated_args.append(evaluate(arg, assignment)) elif isinstance(arg, SetNode): evaluated_args.append(SetNode([evaluate(arg_arg, assignment) for arg_arg in arg.children])) else: evaluated_args.append(arg) # FIXME : rather than try/catch, check type matching try: out = getattr(this, formula.signature.id)(*evaluated_args) return out except: return TruthValue(np.inf)
Example #25
Source File: backend_vsa.py From claripy with BSD 2-Clause "Simplified" License | 5 votes |
def And(a, *args): return reduce(operator.__and__, args, a)
Example #26
Source File: BitVector.py From knob with MIT License | 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 #27
Source File: BitVector.py From knob with MIT License | 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 #28
Source File: BitVector.py From knob with MIT License | 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 #29
Source File: fundamental_factor.py From zvt with MIT License | 5 votes |
def do_compute(self): def filter_df(df): se = pd.Series(index=df.index) for index, row in df.iterrows(): if row.report_period == 'year': mul = 4 elif row.report_period == 'season3': mul = 3 elif row.report_period == 'half_year': mul = 2 else: mul = 1 filters = [] for col in self.col_period_threshold: col_se = eval(f'row.{col}') filters.append(col_se >= mul * self.col_period_threshold[col]) se[index] = list(accumulate(filters, func=operator.__and__))[-1] return se if self.col_period_threshold: self.factor_df = self.data_df.loc[lambda df: filter_df(df), :] self.factor_df = pd.DataFrame(index=self.data_df.index, columns=['count'], data=1) self.factor_df = self.factor_df.reset_index(level=1) self.factor_df = self.factor_df.groupby(level=0).rolling(window=self.window, on=self.time_field).count() self.factor_df = self.factor_df.reset_index(level=0, drop=True) self.factor_df = self.factor_df.set_index(self.time_field, append=True) self.factor_df = self.factor_df.loc[(slice(None), slice(self.start_timestamp, self.end_timestamp)), :] self.logger.info('factor:{},factor_df:\n{}'.format(self.factor_name, self.factor_df)) self.result_df = self.factor_df.apply(lambda x: x >= self.count) self.logger.info('factor:{},result_df:\n{}'.format(self.factor_name, self.result_df))
Example #30
Source File: target_selector.py From zvt with MIT License | 5 votes |
def run(self): """ """ if self.filter_factors: musts = [] for factor in self.filter_factors: df = factor.result_df if not pd_is_not_null(df): raise Exception('no data for factor:{},{}'.format(factor.factor_name, factor)) if len(df.columns) > 1: s = df.agg("and", axis="columns") s.name = 'score' musts.append(s.to_frame(name='score')) else: df.columns = ['score'] musts.append(df) self.filter_result = list(accumulate(musts, func=operator.__and__))[-1] if self.score_factors: scores = [] for factor in self.score_factors: df = factor.result_df if not pd_is_not_null(df): raise Exception('no data for factor:{},{}'.format(factor.factor_name, factor)) if len(df.columns) > 1: s = df.agg("mean", axis="columns") s.name = 'score' scores.append(s.to_frame(name='score')) else: df.columns = ['score'] scores.append(df) self.score_result = list(accumulate(scores, func=operator.__add__))[-1] self.generate_targets()