Add matrix power operation to linalg API and backend implementations#23227
Add matrix power operation to linalg API and backend implementations#23227buildwithsuhana wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the matrix_power operation to Keras linear algebra operations (keras.ops.linalg), implementing it across all supported backends (JAX, NumPy, OpenVINO, TensorFlow, and PyTorch) along with corresponding unit tests. The review feedback highlights two important issues: first, the OpenVINO backend implementation passes raw Python integers to opset functions instead of Node or Output objects, which can cause compilation or runtime failures; second, the non-symbolic execution path in _matrix_power lacks validation to ensure n is an integer, which could lead to infinite loops or incorrect behavior in backends like TensorFlow and OpenVINO if a float is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
05fc9b7 to
8549bfe
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #23227 +/- ##
==========================================
- Coverage 84.80% 84.01% -0.80%
==========================================
Files 465 465
Lines 69201 69288 +87
Branches 11379 11398 +19
==========================================
- Hits 58687 58212 -475
- Misses 7577 8147 +570
+ Partials 2937 2929 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
26fe0b1 to
295e14a
Compare
295e14a to
cce3ec7
Compare
Description
This PR introduces the matrix_power operation to the keras.ops.linalg module, providing a unified API to raise square matrices to an integer power n across all supported backends.
matrix_poweris a fundamental operation in linear algebra with several critical applications in machine learning, physics, and computer science.The keras.ops.linalg.matrix_power(x, n) operation raises a square matrix (or a batch of square matrices) to the integer power n.
Contributor Agreement
Please review our AI-Assisted Contribution Policy and check all boxes below before submitting your PR for review:
Note: Failing to adhere to this agreement may result in your future PRs no longer being reviewed.