Skip to content

Instantly share code, notes, and snippets.

@jgillis
Last active April 22, 2016 12:03
Show Gist options
  • Save jgillis/f7bf47d7686deef361465c5bf43f95ae to your computer and use it in GitHub Desktop.
Save jgillis/f7bf47d7686deef361465c5bf43f95ae to your computer and use it in GitHub Desktop.
Matrix mul infix
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
@jaeandersson
Copy link

Isn't there a Python syntax for matrix multiplication already:

A @ b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment