Commit 05db9ddb by Julius NehringWirxel

### Further WIP. Requires testing.

parent 80dfb46e
 ... ... @@ -2,12 +2,12 @@ #include // std::hypot #include // This file includes an adapted version of the Eigendecomposition class from Jama (https://math.nist.gov/javanumerics/jama/) // which is in public domain. namespace tg { namespace detail namespace { template class eigenvalue_decomposition_impl ... ... @@ -30,23 +30,23 @@ private: /** Arrays for internal storage of eigenvalues. @serial internal storage of eigenvalues. */ array d; array e; tg::array d; tg::array e; /** Array for internal storage of eigenvectors. @serial internal storage of eigenvectors. */ array, D> V; tg::array, D> V; /** Array for internal storage of nonsymmetric Hessenberg form. @serial internal storage of nonsymmetric Hessenberg form. */ array, D> H; tg::array, D> H; /** Working storage for nonsymmetric algorithm. @serial working storage for nonsymmetric algorithm. */ array ort; tg::array ort; /* ------------------------ Private Methods ... ... @@ -992,10 +992,10 @@ private: @param Arg Square matrix */ public: eigenvalue_decomposition_impl(mat const& m) eigenvalue_decomposition_impl(tg::mat const& m) { // internal matrices are row-major, tg::mat is column major mat A = transpose(m); tg::mat A = transpose(m); issymmetric = true; for (int j = 0; (j < D) & issymmetric; j++) ... ... @@ -1048,30 +1048,30 @@ public: @return V */ mat getV() tg::mat getV() { // column vs row-major return transpose(mat(V)); return transpose(tg::mat(V)); } /** Return the real parts of the eigenvalues @return real(diag(D)) */ array getRealEigenvalues() { return d; } tg::array getRealEigenvalues() { return d; } /** Return the imaginary parts of the eigenvalues @return imag(diag(D)) */ array getImagEigenvalues() { return e; } tg::array getImagEigenvalues() { return e; } /** Return the block diagonal eigenvalue matrix @return D */ mat getD() tg::mat getD() { mat X; tg::mat X; for (int i = 0; i < D; i++) { for (int j = 0; j < D; j++) ... ... @@ -1094,10 +1094,10 @@ public: }; template [[nodiscard]] constexpr array, D> eigen_decomposition_impl(mat const& m) tg::array, D> eigen_decomp_wrapper(tg::mat const& m) { eigenvalue_decomposition_impl decomp(m); array, D> res; tg::array, D> res; auto const eigenvalues = decomp.getRealEigenvalues(); auto const eigenvectors = decomp.getV(); ... ... @@ -1107,31 +1107,53 @@ template return res; } } template <> [[nodiscard]] inline constexpr array, 3> eigen_decomposition(mat<3, 3, float> const& m) template tg::array eigenvalues_wrapper(tg::mat const& m) { return detail::eigen_decomposition_impl(m); } eigenvalue_decomposition_impl decomp(m); tg::array res; template <> [[nodiscard]] inline constexpr array, 4> eigen_decomposition(mat<4, 4, float> const& m) { return detail::eigen_decomposition_impl(m); } auto const eigenvalues = decomp.getRealEigenvalues(); template <> [[nodiscard]] inline constexpr array, 3> eigen_decomposition(mat<3, 3, double> const& m) { return detail::eigen_decomposition_impl(m); for (auto i = 0; i < D; ++i) res[i] = {eigenvalues[i]}; return res; } template <> [[nodiscard]] inline constexpr array, 4> eigen_decomposition(mat<4, 4, double> const& m) template tg::array, D> eigenvectors_wrapper(tg::mat const& m) { return detail::eigen_decomposition_impl(m); } eigenvalue_decomposition_impl decomp(m); tg::array, D> res; auto const eigenvectors = decomp.getV(); for (auto i = 0; i < D; ++i) res[i] = {eigenvectors[i]}; return res; } } namespace tg::detail { array, 2> eigen_decomposition_impl(mat<2, 2, float> const& m) { return eigen_decomp_wrapper(m); } array, 2> eigen_decomposition_impl(mat<2, 2, double> const& m) { return eigen_decomp_wrapper(m); } array, 3> eigen_decomposition_impl(mat<3, 3, float> const& m) { return eigen_decomp_wrapper(m); } array, 3> eigen_decomposition_impl(mat<3, 3, double> const& m) { return eigen_decomp_wrapper(m); } array, 4> eigen_decomposition_impl(mat<4, 4, float> const& m) { return eigen_decomp_wrapper(m); } array, 4> eigen_decomposition_impl(mat<4, 4, double> const& m) { return eigen_decomp_wrapper(m); } array eigenvalues_impl(mat<2, 2, float> const& m) { return eigenvalues_wrapper(m); } array eigenvalues_impl(mat<2, 2, double> const& m) { return eigenvalues_wrapper(m); } array eigenvalues_impl(mat<3, 3, float> const& m) { return eigenvalues_wrapper(m); } array eigenvalues_impl(mat<3, 3, double> const& m) { return eigenvalues_wrapper(m); } array eigenvalues_impl(mat<4, 4, float> const& m) { return eigenvalues_wrapper(m); } array eigenvalues_impl(mat<4, 4, double> const& m) { return eigenvalues_wrapper(m); } array, 2> eigenvectors_impl(mat<2, 2, float> const& m) { return eigenvectors_wrapper(m); } array, 2> eigenvectors_impl(mat<2, 2, double> const& m) { return eigenvectors_wrapper(m); } array, 3> eigenvectors_impl(mat<3, 3, float> const& m) { return eigenvectors_wrapper(m); } array, 3> eigenvectors_impl(mat<3, 3, double> const& m) { return eigenvectors_wrapper(m); } array, 4> eigenvectors_impl(mat<4, 4, float> const& m) { return eigenvectors_wrapper(m); } array, 4> eigenvectors_impl(mat<4, 4, double> const& m) { return eigenvectors_wrapper(m); } }