How can I add a symbolic custom matrix function?

55 views
Skip to first unread message

Thomas Atkins

unread,
Aug 26, 2024, 8:59:01 AM8/26/24
to sympy

I'm using sympy matrix expressions for differentiation and I want to add some custom matrix functions and including spectral norm and eigenvectors. I also want to be able to differentiate expressions containing these functions.

The relevant documentation(https://docs.sympy.org/latest/guides/custom-functions.html) says "functions that accept or return other kinds of objects than complex numbers should subclass another class, such as Boolean, MatrixExpr, Expr, or Basic." but only gives examples for Function.

Later it says "Subclasses of Expr that aren’t Function subclasses will need to define _eval_derivative()"

I have three questions relating to this

  1. When I subclass MatrixExpr what does _eval_derivative need to do?
  2. Do I need to define/hook/set/etc. anything else
  3. Does anyone have an example I could read?
Reply all
Reply to author
Forward
0 new messages