Skip to content

Prototype class EigenSystem for solving eigenvalue problems#768

Open
yungyuc wants to merge 1 commit into
solvcon:masterfrom
yungyuc:feature/veclib-eigen
Open

Prototype class EigenSystem for solving eigenvalue problems#768
yungyuc wants to merge 1 commit into
solvcon:masterfrom
yungyuc:feature/veclib-eigen

Conversation

@yungyuc
Copy link
Copy Markdown
Member

@yungyuc yungyuc commented May 10, 2026

Use Apple Accelerate/veclib DGEEV (LAPACK interface) to prototype an eigenvalue solver for a general linear system. The prototype uses double-precision floating point (float64) only.

Provide Python binding using pybind11 and create basic tests in Python. In the Python wrapper, set EigenSystem to None when it is not built.

All platforms has LAPACK, but properly set up the build system for all platforms will use some efforts. I start with Apple because it is the most popular platform among the contributors, and Apple Silicon is the most accessible platform for GPU and other interesting accelerating instructions.

Future work:

  1. Detail API control like selection of left and/or right eigenvectors.
  2. More test cases.
  3. Add all data types: float32, complex64, complex128.
  4. Add Linux support.
  5. Add Windows support.
  6. Intel MKL (oneAPI MKL) support on Linux and Windows.

Use Apple Accelerate/veclib DGEEV (LAPACK interface) to prototype an eigenvalue
solver for a general system.

Provide Python binding using pybind11 and create basic tests in Python.  In the
Python wrapper, set `EigenSystem` to `None` when it is not built.
namespace python
{

#ifdef __APPLE__
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a prototype. Fence for code that only builds with macOS/Apple.

#ifdef __APPLE__
WrapEigenSystem::commit(mod, "EigenSystem", "Eigen problem solver");
#else // __APPLE__
mod.attr("EigenSystem") = pybind11::none();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than macOS/Apple, assign None to the symbol EigenSystem.

* This header is only available on Apple platforms.
*/

#ifndef __APPLE__
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only builds on macOS/Apple.


public:

using value_type = double;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this prototype, EigenSystem hard-codes to use float64 (double). It will be extended to be a template and support float32, complex64, and complex128 in the future.


static std::string format_shape(array_type const & arr);

SimpleArray<value_type> const & m_matrix;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lifecycle may not be correct with the const &. I am still considering to fix it with this or the next PR.

Comment thread tests/test_linalg.py
np.testing.assert_allclose(A_np @ vr[:, j], wr[j] * vr[:, j],
rtol=1e-10, atol=1e-12)

def test_2x2_rotation_complex_conjugate_pair(self):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test the rotation matrix that only has imaginary eigenvalues.

Comment thread tests/test_linalg.py
np.testing.assert_allclose(A_np @ v_conj, lam_conj * v_conj,
rtol=1e-12, atol=1e-14)

def test_left_eigenvectors_satisfy_left_equation(self):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test left eigenvectors.

Comment thread tests/test_linalg.py
wr[j] * vl[:, j],
rtol=1e-10, atol=1e-12)

def test_rejects_non_square_and_non_2d_inputs(self):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test for square shape.

Comment thread tests/test_linalg.py
ValueError, r"must be a square 2D SimpleArray"):
mm.EigenSystem(A_3d)

def test_accessors_before_run_are_inert(self):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test done flag.

Comment thread tests/test_linalg.py
wr = solver.wr.ndarray
self.assertTrue(np.all(np.isfinite(wr)))

def test_matrix_property_survives_input_gc(self):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matrix property lifecycle.

@yungyuc yungyuc marked this pull request as ready for review May 10, 2026 14:32
@yungyuc yungyuc self-assigned this May 10, 2026
@yungyuc yungyuc added the array Multi-dimensional array implementation label May 10, 2026
@yungyuc yungyuc added the performance Profiling, runtime, and memory consumption label May 10, 2026
@yungyuc
Copy link
Copy Markdown
Member Author

yungyuc commented May 11, 2026

@KHLee529 @tigercosmos Please help take a look at the prototype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

array Multi-dimensional array implementation performance Profiling, runtime, and memory consumption

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant