Python ast.MatMult() Examples
The following are 5
code examples of ast.MatMult().
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
ast
, or try the search function
.
Example #1
Source File: helper.py From YAPyPy with MIT License | 6 votes |
def term_rewrite(head, tail): if tail: for op, each in tail: head = ast.BinOp( head, { '*': ast.Mult, '@': ast.MatMult, '%': ast.Mod, '//': ast.FloorDiv, '/': ast.Div }[op.value](), each, **loc @ op, ) return head
Example #2
Source File: helper.py From YAPyPy with MIT License | 6 votes |
def augassign_rewrite(it: Tokenizer): return { '+=': ast.Add, '-=': ast.Sub, '*=': ast.Mult, '/=': ast.Div, '//=': ast.FloorDiv, '@=': ast.MatMult, '%=': ast.Mod, '&=': ast.BitAnd, '|=': ast.BitOr, '^=': ast.BitXor, '<<=': ast.LShift, '>>=': ast.RShift, '**=': ast.Pow, }[it.value]
Example #3
Source File: BehavioralRTLIRGenL1Pass.py From pymtl3 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def visit_AugAssign( s, node ): """Return the behavioral RTLIR of a non-blocking assignment If the given AugAssign is not @= or <<=, throw PyMTLSyntaxError """ if isinstance( node.op, (ast.LShift, ast.MatMult) ): value = s.visit( node.value ) targets = [ s.visit( node.target ) ] blocking = False if isinstance(node.op, ast.LShift) else True ret = bir.Assign( targets, value, blocking ) ret.ast = node return ret raise PyMTLSyntaxError( s.blk, node, 'invalid operation: augmented assignment is not @= or <<= assignment!' )
Example #4
Source File: _recompute.py From icontract with MIT License | 5 votes |
def visit_BinOp(self, node: ast.BinOp) -> Any: """Recursively visit the left and right operand, respectively, and apply the operation on the results.""" # pylint: disable=too-many-branches left = self.visit(node=node.left) right = self.visit(node=node.right) if isinstance(node.op, ast.Add): result = left + right elif isinstance(node.op, ast.Sub): result = left - right elif isinstance(node.op, ast.Mult): result = left * right elif isinstance(node.op, ast.Div): result = left / right elif isinstance(node.op, ast.FloorDiv): result = left // right elif isinstance(node.op, ast.Mod): result = left % right elif isinstance(node.op, ast.Pow): result = left**right elif isinstance(node.op, ast.LShift): result = left << right elif isinstance(node.op, ast.RShift): result = left >> right elif isinstance(node.op, ast.BitOr): result = left | right elif isinstance(node.op, ast.BitXor): result = left ^ right elif isinstance(node.op, ast.BitAnd): result = left & right elif isinstance(node.op, ast.MatMult): result = left @ right else: raise NotImplementedError("Unhandled op of {}: {}".format(node, node.op)) self.recomputed_values[node] = result return result
Example #5
Source File: compiler.py From Transcrypt with Apache License 2.0 | 4 votes |
def visit_BinOp (self, node): if type (node.op) == ast.FloorDiv: if self.allowOperatorOverloading: self.emit ('__floordiv__ (') self.visitSubExpr (node, node.left) self.emit (', ') self.visitSubExpr (node, node.right) self.emit (')') else: self.emit ('Math.floor (') self.visitSubExpr (node, node.left) self.emit (' / ') self.visitSubExpr (node, node.right) self.emit (')') elif ( type (node.op) in (ast.Pow, ast.MatMult) or (type (node.op) == ast.Mod and (self.allowOperatorOverloading or not self.allowJavaScriptMod)) or (type (node.op) in ( ast.Mult, ast.Div, ast.Add, ast.Sub, ast.LShift, ast.RShift, ast.BitOr, ast.BitXor, ast.BitAnd ) and self.allowOperatorOverloading) ): self.emit ('{} ('.format (self.filterId ( # Non-overloaded ('__floordiv__' if self.allowOperatorOverloading else 'Math.floor') if type (node.op) == ast.FloorDiv else ('__pow__' if self.allowOperatorOverloading else 'Math.pow') if type (node.op) == ast.Pow else '__matmul__' if type (node.op) == ast.MatMult else ('__jsmod__' if self.allowJavaScriptMod else '__mod__') if type (node.op) == ast.Mod else # Overloaded arithmetic '__mul__' if type (node.op) == ast.Mult else '__truediv__' if type (node.op) == ast.Div else '__add__' if type (node.op) == ast.Add else '__sub__' if type (node.op) == ast.Sub else # Overloaded bitwise '__lshift__' if type (node.op) == ast.LShift else '__rshift__' if type (node.op) == ast.RShift else '__or__' if type (node.op) == ast.BitOr else '__xor__' if type (node.op) == ast.BitXor else '__and__' if type (node.op) == ast.BitAnd else 'Never here' ))) self.visit (node.left) self.emit (', ') self.visit (node.right) self.emit (')') else: self.visitSubExpr (node, node.left) self.emit (' {} '.format (self.operators [type (node.op)][0])) self.visitSubExpr (node, node.right)