本文整理汇总了Python中operator.__mul__方法的典型用法代码示例。如果您正苦于以下问题:Python operator.__mul__方法的具体用法?Python operator.__mul__怎么用?Python operator.__mul__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.__mul__方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [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
示例2: testMath
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [as 别名]
def testMath(self):
self.failUnlessEqual(str(-vector(2, "a")), "unnamed_vector{=(unnamed_scalar{=-1.0} * a[0], unnamed_scalar{=-1.0} * a[1])}")
self.failUnlessEqual(str(vector(2, "a") + vector(2, "b")), "unnamed_vector{=(a[0] + b[0], a[1] + b[1])}")
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, 1, vector(2))
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, vector(2), 1)
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, scalar(), vector(2))
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, vector(2), scalar())
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, scalar() + scalar(), vector(2))
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, vector(2), scalar() + scalar())
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__add__, vector(2), vector(3))
self.failUnlessEqual(str(vector(2, "a") - vector(2, "b")), "unnamed_vector{=(unnamed_scalar{=-1.0} * b[0] + a[0], unnamed_scalar{=-1.0} * b[1] + a[1])}")
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, 1, vector(2))
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, vector(2), 1)
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, scalar(), vector(2))
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, vector(2), scalar())
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, scalar() + scalar(), vector(2))
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, vector(2), scalar() + scalar())
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__sub__, vector(2), vector(3))
self.failUnlessEqual(str(2 * vector(2, "a")), "unnamed_vector{=(a[0] * unnamed_scalar{=2.0}, a[1] * unnamed_scalar{=2.0})}")
self.failUnlessEqual(str(vector(2, "a") * 2), "unnamed_vector{=(a[0] * unnamed_scalar{=2.0}, a[1] * unnamed_scalar{=2.0})}")
self.failUnlessEqual(str(scalar(name="s") * vector(2, "a")), "unnamed_vector{=(a[0] * s, a[1] * s)}")
self.failUnlessEqual(str(scalar(name="s") * (vector(2, "a") + vector(2, "b"))), "unnamed_vector{=(a[0] * s + b[0] * s, a[1] * s + b[1] * s)}")
self.failUnlessEqual(str((scalar(name="s") + scalar(name="t")) * vector(2, "a")), "unnamed_vector{=(a[0] * s + a[0] * t, a[1] * s + a[1] * t)}")
self.failUnlessEqual(str((scalar(name="s") + scalar(name="t")) * (vector(2, "a") + vector(2, "b"))), "unnamed_vector{=(a[0] * s + b[0] * s + a[0] * t + b[0] * t, a[1] * s + b[1] * s + a[1] * t + b[1] * t)}")
self.failUnlessEqual(str(vector(2, "a") * scalar(name="s")), "unnamed_vector{=(a[0] * s, a[1] * s)}")
self.failUnlessEqual(str(vector(2, "a") * vector(2, "b")), "a[0] * b[0] + a[1] * b[1]")
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__mul__, vector(2, "a"), vector(3))
self.failUnlessEqual(str(vector(2, "a") / 2.0), "unnamed_vector{=(unnamed_scalar{=0.5} * a[0], unnamed_scalar{=0.5} * a[1])}")
self.failUnlessEqual(str(vector(2, "a") / 2), "unnamed_vector{=(unnamed_scalar{=0.0} * a[0], unnamed_scalar{=0.0} * a[1])}") # integer logic!
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, scalar(), vector(1))
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, scalar() + scalar(), vector(1))
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, vector(1), scalar())
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, vector(1), scalar() + scalar())
self.failUnlessRaises((RuntimeError, AttributeError, TypeError), operator.__div__, vector(1), vector(1))
示例3: _op_mul
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [as 别名]
def _op_mul(*args):
return reduce(operator.__mul__, args)
示例4: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [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
示例5: __mul__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [as 别名]
def __mul__(self, other):
return self._operation(other, operator.__mul__)
示例6: __rmul__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [as 别名]
def __rmul__(self, other):
return self._roperation(other, operator.__mul__)
示例7: _string_to_operator
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [as 别名]
def _string_to_operator(self):
operators = {
"+": operator.__add__,
"-": operator.__sub__,
"*": operator.__mul__,
"**": operator.__pow__,
"/": operator.__truediv__,
"//": operator.__floordiv__,
}
return operators[self.operator]
### PUBLIC PROPERTIES ###
示例8: __mul__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [as 别名]
def __mul__(self,other):
if (self.cols != other.rows):
raise ValueError("dimension mismatch")
result = self.MakeSimilarMatrix((self.rows,other.cols),'z')
for i in range(self.rows):
for j in range(other.cols):
result.data[i][j] = reduce(self.add, map(
self.mul,self.data[i], other.GetColumn(j)))
return result
示例9: get_tree_score
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [as 别名]
def get_tree_score(self, semantic_tree):
assert isinstance(semantic_tree, SemanticTreeNode)
unary_rules = semantic_tree.get_unary_rules()
binary_rules = semantic_tree.get_binary_rules()
scores = [self.get_score(rule) for rule in itertools.chain(unary_rules, binary_rules)]
return reduce(__mul__, scores, 1)
示例10: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __mul__ [as 别名]
def __init__(self, reuse_z3_solver=None, ast_cache_size=10000):
Backend.__init__(self, solver_required=True)
self._enable_simplification_cache = False
self._hash_to_constraint = weakref.WeakValueDictionary()
# Per-thread Z3 solver
# This setting is treated as a global setting and is not supposed to be changed during runtime, unless you know
# what you are doing.
if reuse_z3_solver is None:
reuse_z3_solver = True if os.environ.get('REUSE_Z3_SOLVER', "False").lower() in {"1", "true", "yes", "y"} \
else False
self.reuse_z3_solver = reuse_z3_solver
self._ast_cache_size = ast_cache_size
# and the operations
all_ops = backend_fp_operations | backend_operations if supports_fp else backend_operations
all_ops |= backend_strings_operations - {'StrIsDigit'}
for o in all_ops - {'BVV', 'BoolV', 'FPV', 'FPS', 'BitVec', 'StringV'}:
self._op_raw[o] = getattr(self, '_op_raw_' + o)
self._op_raw['Xor'] = self._op_raw_Xor
self._op_raw['__ge__'] = self._op_raw_UGE
self._op_raw['__gt__'] = self._op_raw_UGT
self._op_raw['__le__'] = self._op_raw_ULE
self._op_raw['__lt__'] = self._op_raw_ULT
self._op_raw['Reverse'] = self._op_raw_Reverse
self._op_raw['Identical'] = self._identical
self._op_raw['fpToSBV'] = self._op_raw_fpToSBV
self._op_raw['fpToUBV'] = self._op_raw_fpToUBV
self._op_expr['BVS'] = self.BVS
self._op_expr['BVV'] = self.BVV
self._op_expr['FPV'] = self.FPV
self._op_expr['FPS'] = self.FPS
self._op_expr['BoolV'] = self.BoolV
self._op_expr['BoolS'] = self.BoolS
self._op_expr['StringV'] = self.StringV
self._op_expr['StringS'] = self.StringS
self._op_raw['__floordiv__'] = self._op_div
self._op_raw['__mod__'] = self._op_mod
# 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
# XXX this is a HUGE HACK that should be removed whenever uninitialized gets moved to the
# "proposed annotation backend" or wherever will prevent it from being part of the object
# identity. also whenever the VSA attributes get the fuck out of BVS as well