本文整理汇总了Python中operator.__and__方法的典型用法代码示例。如果您正苦于以下问题:Python operator.__and__方法的具体用法?Python operator.__and__怎么用?Python operator.__and__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.__and__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __and__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
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
示例2: shift_right_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [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 __and__ [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: do_finalize
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
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
示例5: circular_rotate_left_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [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)
示例6: circular_rotate_right_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [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)
示例7: shift_left_by_one
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [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)
示例8: do_compute
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
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))
示例9: run
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
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()
示例10: all
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
def all(items):
return reduce(operator.__and__, items)
# --- test if interpreter supports yield keyword ---
示例11: _op_and
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
def _op_and(*args):
return reduce(operator.__and__, args)
示例12: And
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
def And(a, *args):
return reduce(operator.__and__, args, a)
示例13: fromParams
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [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)
示例14: propagateAnd
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
def propagateAnd(x, y):
return propagateBitwise(x, y, operator.__and__, False, True)
示例15: all
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __and__ [as 别名]
def all(items):
return reduce(operator.__and__, items)