Add linear system solver (Ax = b) using LAPACK dgesv#51
Merged
Conversation
Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add Ax = b solver using LAPACK on JVM
Add linear system solver (Ax = b) using LAPACK dgesv
Nov 24, 2025
Quafadas
reviewed
Nov 24, 2025
Owner
|
@copilot seems like CI is failing. Can you check? |
- Move dimension check (A.rows == b.rows) to use inline bounds check pattern similar to other matrix checks - Remove redundant require statement inside if bc block - Keep NaN checks in if bc block following eig.scala pattern - Update test to expect MatrixDimensionMismatch exception type - All 25 tests still pass Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
Contributor
Author
Quafadas
requested changes
Nov 24, 2025
Per code review feedback, the manual element-by-element copy into a new array is unnecessary since the solve(Matrix) method already makes a copy via deepCopy. Now directly returns xMatrix.raw which contains the solution. This improves performance by avoiding an extra O(n) copy operation. All 25 tests continue to pass. Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements a linear system solver for solving Ax = b using LAPACK's dgesv routine on the JVM, with placeholder implementations for JS and Native platforms. The implementation follows established patterns from existing LAPACK-based operations (eigenvalues, SVD, Cholesky) in the repository.
Key Changes
- Adds JVM-specific solve implementation using LAPACK dgesv with LU decomposition
- Provides two API variants: one for matrix right-hand sides and one for vector (Array) right-hand sides
- Includes comprehensive validation (bounds checking, NaN detection, dimension compatibility)
- Adds 25 comprehensive tests covering various matrix types and edge cases
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| vecxt/src-jvm/solve.scala | JVM implementation using LAPACK dgesv for solving linear systems with proper error handling and validation |
| vecxt/src-js-native/solve.scala | Placeholder implementation for JS and Native platforms (not yet implemented) |
| vecxt/src/all.scala | Exports Solve module to make it available in the public API |
| vecxt/test/src-jvm/solve.test.scala | Comprehensive test suite with 25 tests covering identity matrices, diagonal matrices, triangular matrices, singular matrices, edge cases, and error conditions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation Plan for Linear System Solver (Ax = b)
This PR implements a linear system solver using LAPACK's dgesv routine, following the pattern established in the repository for other LAPACK-based operations (eigenvalues, SVD, Cholesky).
Tasks:
Recent Changes (per code review):
Implementation Summary:
Solver Features:
solve(A, b: Array[Double])andsolve(A, b: Matrix[Double])Test Coverage: 10/10 (25 comprehensive tests) - all passing
Security Summary:
No security vulnerabilities detected. The implementation:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.