Skip to content

feat(linalg): dtype promotion and vector/matrix rules for matmul and dot - #16

Merged
CodeWithKyrian merged 1 commit into
mainfrom
feat/linalg-matmul-dot-dtype-and-shape-rules
Apr 19, 2026
Merged

CodeWithKyrian merged 1 commit into
mainfrom
feat/linalg-matmul-dot-dtype-and-shape-rules

Conversation

@CodeWithKyrian

Copy link
Copy Markdown
Contributor

Summary

This PR adds dtype promotion for matrix multiply and dot, implements explicit 1D and 2D matrix-multiply shape rules for matmul, and updates tests and the standalone eigen example so they use the API directly without extra casts or reshapes where those workarounds are no longer needed.

Motivation and context

Linear algebra calls should accept the natural combinations of real and complex operands and apply consistent promotion, similar to other binary operations. Vector–matrix products should not require turning vectors into columns or rows by hand when the operation already defines the intended layout. NumPy’s behavior was used as a reference while designing these rules.

What's changed

  • Added dtype promotion for matmul and dot so operands are evaluated in a common promoted type (e.g. real with complex).
  • matmul: supports 1D and 2D operands with defined rules (including 1D·1D producing a scalar result); rejects operands with more than two dimensions.
  • dot: dtype promotion aligned with other binary ops; existing dimension behavior preserved.
  • Unit tests updated for eigen verification and related cases without manual astype or reshape where superseded by the new behavior.

Breaking changes

None.

@CodeWithKyrian
CodeWithKyrian merged commit b99e42c into main Apr 19, 2026
14 checks passed
@CodeWithKyrian
CodeWithKyrian deleted the feat/linalg-matmul-dot-dtype-and-shape-rules branch April 19, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant