Last active
April 22, 2016 12:03
-
-
Save jgillis/f7bf47d7686deef361465c5bf43f95ae to your computer and use it in GitHub Desktop.
Matrix mul infix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
class Infix(object): | |
def __init__(self, func): | |
self.func = func | |
def __or__(self, other): | |
return self.func(other) | |
def __ror__(self, other): | |
return Infix(partial(self.func, other)) | |
def __call__(self, v1, v2): | |
return self.func(v1, v2) | |
@Infix | |
def mul(a,b): | |
return mtimes(a,b) | |
from casadi import * | |
A = MX.sym("A",2,2) | |
b = MX.sym("b",2) | |
print A |mul| b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Isn't there a Python syntax for matrix multiplication already: