Skip to content

Commit

Permalink
Add graph canonization
Browse files Browse the repository at this point in the history
- Add overloading of @ for Python matrix multiplication
  • Loading branch information
benruijl committed Aug 23, 2024
1 parent bd0536c commit b62d669
Show file tree
Hide file tree
Showing 4 changed files with 551 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/api/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9022,7 +9022,7 @@ impl PythonMatrix {
self.__add__(rhs.__neg__())
}

/// Add this matrix to `rhs`, returning the result.
/// Matrix multiply `self` and `rhs`, returning the result.
pub fn __mul__(&self, rhs: ScalarOrMatrix) -> PyResult<PythonMatrix> {
match rhs {
ScalarOrMatrix::Scalar(s) => {
Expand All @@ -9041,11 +9041,21 @@ impl PythonMatrix {
}
}

/// Add this matrix to `rhs`, returning the result.
/// Matrix multiply `rhs` and `self` returning the result.
pub fn __rmul__(&self, rhs: ConvertibleToRationalPolynomial) -> PyResult<PythonMatrix> {
self.__mul__(ScalarOrMatrix::Scalar(rhs))
}

/// Matrix multiply this matrix and `self`, returning the result.
pub fn __matmul__(&self, rhs: ScalarOrMatrix) -> PyResult<PythonMatrix> {
self.__mul__(rhs)
}

/// Matrix multiply `rhs` and `self`, returning the result.
pub fn __rmatmul__(&self, rhs: ConvertibleToRationalPolynomial) -> PyResult<PythonMatrix> {
self.__mul__(ScalarOrMatrix::Scalar(rhs))
}

/// Divide the matrix by the scalar, returning the result.
pub fn __truediv__(&self, rhs: ConvertibleToRationalPolynomial) -> PyResult<PythonMatrix> {
Ok(PythonMatrix {
Expand Down
Loading

0 comments on commit b62d669

Please sign in to comment.