diff --git a/.github/workflows/R-CMD-check-macOS.yml b/.github/workflows/R-CMD-check-macOS.yml index 4ab68f87..4a013944 100644 --- a/.github/workflows/R-CMD-check-macOS.yml +++ b/.github/workflows/R-CMD-check-macOS.yml @@ -39,6 +39,9 @@ jobs: - name: Fetch and update submodule run: git submodule update --init --recursive + cd src/volesti + git sparse-checkout set include external + git checkout - name: Install dependencies run: Rscript -e "install.packages(c('devtools', dependencies=TRUE))" -e "install.packages(c('rcmdcheck', 'devtools', 'Rcpp', 'RcppEigen', 'BH', 'testthat', 'downloader', 'xfun'))"; diff --git a/.github/workflows/R-CMD-check-ubuntu.yml b/.github/workflows/R-CMD-check-ubuntu.yml index 445c5446..8055dcd1 100644 --- a/.github/workflows/R-CMD-check-ubuntu.yml +++ b/.github/workflows/R-CMD-check-ubuntu.yml @@ -41,6 +41,9 @@ jobs: - name: Fetch and update submodule run: git submodule update --init --recursive + cd src/volesti + git sparse-checkout set include external + git checkout - name: Install dependencies run: Rscript -e "install.packages(c('testthat', 'pkgload', 'rcmdcheck', 'devtools', 'Rcpp', 'RcppEigen', 'BH', 'downloader', 'xfun', dependencies=TRUE))"; diff --git a/.github/workflows/R-CMD-check-windows.yml b/.github/workflows/R-CMD-check-windows.yml index 099f7458..a6d8167d 100644 --- a/.github/workflows/R-CMD-check-windows.yml +++ b/.github/workflows/R-CMD-check-windows.yml @@ -38,6 +38,9 @@ jobs: - name: Fetch and update submodule run: git submodule update --init --recursive + cd src/volesti + git sparse-checkout set include external + git checkout - name: Install dependencies run: Rscript -e "install.packages(c('devtools', dependencies=TRUE))" -e "install.packages(c('rcmdcheck', 'devtools', 'Rcpp', 'RcppEigen', 'BH', 'testthat', 'downloader', 'xfun'))" diff --git a/.gitmodules b/.gitmodules index 05748818..42627744 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,3 @@ -[submodule "volesti_cran_include"] - path = src/include +[submodule "src/volesti"] + path = src/volesti url = https://github.com/GeomScale/volesti.git - branch = cran_include diff --git a/R/RcppExports.R b/R/RcppExports.R index d77ee54f..f16e5f11 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -202,7 +202,9 @@ load_sdpa_format_file <- function(input_file = NULL) { #' @return A list which contains elements "x_1", ..., "x_n" representing each derivative results. Each "x_i" corresponds to a d x n matrix where each column represents a certain timestep of the solver. #' #' @examples -#' # Please visit the examples directory on examples demonstrating usage of the ODE solvers. +#' F <- function (x) (-x) +#' initial_conditions <- list("x_1" = c(0), "x_2" = c(1)) +#' states <- ode_solve(dimension=1, n=1000, F=F, initial_time=0, step_size=0.01, order=2, method="leapfrog", initial_conditions=initial_conditions, domains = list()) #' #' @export ode_solve <- function(n, step_size, order, dimension, initial_time, F, method, domains = NULL, initial_conditions = NULL) { diff --git a/man/ode_solve.Rd b/man/ode_solve.Rd index b4e8e4b9..2836f342 100644 --- a/man/ode_solve.Rd +++ b/man/ode_solve.Rd @@ -42,6 +42,8 @@ A list which contains elements "x_1", ..., "x_n" representing each derivative re Solve an ODE of the form dx^n / dt^n = F(x, t) } \examples{ -# Please visit the examples directory on examples demonstrating usage of the ODE solvers. +F <- function (x) (-x) +initial_conditions <- list("x_1" = c(0), "x_2" = c(1)) +states <- ode_solve(dimension=1, n=1000, F=F, initial_time=0, step_size=0.01, order=2, method="leapfrog", initial_conditions=initial_conditions, domains = list()) } diff --git a/src/Makevars b/src/Makevars index 4d2b7288..9fd194e7 100644 --- a/src/Makevars +++ b/src/Makevars @@ -1,16 +1,16 @@ -PKG_CPPFLAGS=-Iexternal -Iexternal/lpsolve/headers/run_headers -Iexternal/minimum_ellipsoid -Iinclude -Iinclude/convex_bodies/spectrahedra +PKG_CPPFLAGS=-Ivolesti/external -Ilpsolve/headers/run_headers -Ivolesti/external/minimum_ellipsoid -Ivolesti/include -Ivolesti/include/convex_bodies/spectrahedra PKG_CXXFLAGS= -DBOOST_NO_AUTO_PTR -DDISABLE_NLP_ORACLES -PKG_LIBS=-Lexternal/lpsolve/build/lp_solve -llp_solve -Lexternal/PackedCSparse/qd -lqd $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) +PKG_LIBS=-Llpsolve/build/lp_solve -llp_solve -Lvolesti/external/PackedCSparse/qd -lqd $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -$(SHLIB): external/lpsolve/build/lp_solve/liblp_solve.a external/PackedCSparse/qd/libqd.a +$(SHLIB): lpsolve/build/lp_solve/liblp_solve.a volesti/external/PackedCSparse/qd/libqd.a -external/lpsolve/build/lp_solve/liblp_solve.a: - @(cd external/lpsolve/build/lp_solve && $(MAKE) liblp_solve.a \ +lpsolve/build/lp_solve/liblp_solve.a: + @(cd lpsolve/build/lp_solve && $(MAKE) liblp_solve.a \ CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \ CPICFLAGS="$(CPICFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)") -external/PackedCSparse/qd/libqd.a: - @(cd external/PackedCSparse/qd && $(MAKE) libqd.a \ +volesti/external/PackedCSparse/qd/libqd.a: + @(cd volesti/external/PackedCSparse/qd && $(MAKE) libqd.a \ CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \ CPICFLAGS="$(CPICFLAGS)" AR="$(AR)") diff --git a/src/Makevars.win b/src/Makevars.win index dbd3bac5..093db7e9 100644 --- a/src/Makevars.win +++ b/src/Makevars.win @@ -1,17 +1,17 @@ -PKG_CPPFLAGS=-Iexternal -Iexternal/lpsolve/headers/run_headers -Iexternal/minimum_ellipsoid -Iinclude -Iinclude/convex_bodies/spectrahedra +PKG_CPPFLAGS=-Ivolesti/external -Ilpsolve/headers/run_headers -Ivolesti/external/minimum_ellipsoid -Ivolesti/include -Ivolesti/include/convex_bodies/spectrahedra PKG_CXXFLAGS= -lm -ldl -DBOOST_NO_AUTO_PTR -DDISABLE_NLP_ORACLES -PKG_LIBS=-Lexternal/lpsolve/build/lp_solve -llp_solve -Lexternal/PackedCSparse/qd -lqd $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) +PKG_LIBS=-Llpsolve/build/lp_solve -llp_solve -Lvolesti/external/PackedCSparse/qd -lqd $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -$(SHLIB): external/lpsolve/build/lp_solve/liblp_solve.a external/PackedCSparse/qd/libqd.a +$(SHLIB): lpsolve/build/lp_solve/liblp_solve.a volesti/external/PackedCSparse/qd/libqd.a -external/lpsolve/build/lp_solve/liblp_solve.a: - @(cd external/lpsolve/build/lp_solve && $(MAKE) liblp_solve.a \ +lpsolve/build/lp_solve/liblp_solve.a: + @(cd lpsolve/build/lp_solve && $(MAKE) liblp_solve.a \ CC="$(CC)" CPPFLAGS="$(CPPFLAGS) -DUSRDLL -DINLINE=static" \ CFLAGS="$(CFLAGS)" CPICFLAGS="$(CPICFLAGS)" AR="$(AR)" \ RANLIB="$(RANLIB)") -external/PackedCSparse/qd/libqd.a: - @(cd external/PackedCSparse/qd && $(MAKE) libqd.a \ +volesti/external/PackedCSparse/qd/libqd.a: + @(cd volesti/external/PackedCSparse/qd && $(MAKE) libqd.a \ CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \ CPICFLAGS="$(CPICFLAGS)" AR="$(AR)") \ No newline at end of file diff --git a/src/external/ChebTools/ChebTools.cpp b/src/external/ChebTools/ChebTools.cpp deleted file mode 100644 index 2813822f..00000000 --- a/src/external/ChebTools/ChebTools.cpp +++ /dev/null @@ -1,892 +0,0 @@ -//Copyright 2018* United States Secretary of Commerce, NIST. -// -//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Credit to https://github.com/usnistgov/ChebTools - -#include "ChebTools/ChebTools.h" -#include "Eigen/Dense" -#include <unsupported/Eigen/FFT> - -#include <algorithm> -#include <functional> - -#include <chrono> -#include <iostream> -#include <map> -#include <limits> - -#ifndef DBL_EPSILON -#define DBL_EPSILON std::numeric_limits<double>::epsilon() -#endif - -#ifndef DBL_MAX -#define DBL_MAX std::numeric_limits<double>::max() -#endif - -template <class T> T POW2(T x){ return x*x; } -template <class T> bool inbetween(T bound1, T bound2, T val){ return val > std::min(bound1,bound2) && val < std::max(bound1,bound2); } - -/// See python code in https://en.wikipedia.org/wiki/Binomial_coefficient#Binomial_coefficient_in_programming_languages -/// This is a direct translation of that code to C++ -double binomialCoefficient(const double n, const double k) { - if (k < 0 || k > n) { - return 0; - } - if (k == 0 || k == n) { - return 1; - } - double _k = std::min(k, n - k); //# take advantage of symmetry - double c = 1; - for (double i = 0; i < _k; ++i) { - c *= (n - i) / (i + 1); - } - return c; -} - -namespace ChebTools { - - inline bool ValidNumber(double x){ - // Idea from http://www.johndcook.com/IEEE_exceptions_in_cpp.html - return (x <= DBL_MAX && x >= -DBL_MAX); - }; - - void balance_matrix(const Eigen::MatrixXd &A, Eigen::MatrixXd &Aprime, Eigen::MatrixXd &D) { - // https://arxiv.org/pdf/1401.5766.pdf (Algorithm #3) - const int p = 2; - double beta = 2; // Radix base (2?) - int iter = 0; - Aprime = A; - D = Eigen::MatrixXd::Identity(A.rows(), A.cols()); - bool converged = false; - do { - converged = true; - for (Eigen::Index i = 0; i < A.rows(); ++i) { - double c = Aprime.col(i).lpNorm<p>(); - double r = Aprime.row(i).lpNorm<p>(); - double s = pow(c, p) + pow(r, p); - double f = 1; - //if (!ValidNumber(c)){ - // std::cout << A << std::endl; - // throw std::range_error("c is not a valid number in balance_matrix"); } - //if (!ValidNumber(r)) { throw std::range_error("r is not a valid number in balance_matrix"); } - while (c < r/beta) { - c *= beta; - r /= beta; - f *= beta; - } - while (c >= r*beta) { - c /= beta; - r *= beta; - f /= beta; - } - if (pow(c, p) + pow(r, p) < 0.95*s) { - converged = false; - D(i, i) *= f; - Aprime.col(i) *= f; - Aprime.row(i) /= f; - } - } - iter++; - if (iter > 50) { - break; - } - } while (!converged); - } - - /** - * @brief A library that stores the Chebyshev-Lobatto nodes in the domain [-1,1] - * @note The Chebyshev-Lobatto nodes are a function of degree, but not of the coefficients - */ - class ChebyshevLobattoNodesLibrary { - private: - std::map<std::size_t, Eigen::VectorXd> vectors; - void build(std::size_t N) { - double NN = static_cast<double>(N); // just a cast - vectors[N] = (Eigen::VectorXd::LinSpaced(N + 1, 0, NN).array()*EIGEN_PI / N).cos(); - } - public: - /// Get the Chebyshev-Lobatto nodes for expansion of degree \f$N\f$ - const Eigen::VectorXd & get(std::size_t N) { - auto it = vectors.find(N); - if (it != vectors.end()) { - return it->second; - } - else { - build(N); - return vectors.find(N)->second; - } - } - }; - static ChebyshevLobattoNodesLibrary CLnodes_library; - const Eigen::VectorXd &get_CLnodes(std::size_t N){ - return CLnodes_library.get(N); - } - - // DEPRECATED: but held around for future reference - //class ChebyshevRootsLibrary { - //private: - // std::map<std::size_t, Eigen::VectorXd> vectors; - // void build(std::size_t N) { - // double NN = static_cast<double>(N); // just a cast - // vectors[N] = ((Eigen::VectorXd::LinSpaced(N, 0, NN - 1).array() + 0.5)*EIGEN_PI / NN).cos(); - // } - //public: - // const Eigen::VectorXd & get(std::size_t N) { - // auto it = vectors.find(N); - // if (it != vectors.end()) { - // return it->second; - // } - // else { - // build(N); - // return vectors.find(N)->second; - // } - // } - //}; - //static ChebyshevRootsLibrary roots_library; - - // From CoolProp - template<class T> bool is_in_closed_range(T x1, T x2, T x) { return (x >= std::min(x1, x2) && x <= std::max(x1, x2)); }; - - ChebyshevExpansion ChebyshevExpansion::operator+(const ChebyshevExpansion &ce2) const { - if (m_c.size() == ce2.coef().size()) { - // Both are the same size, nothing creative to do, just add the coefficients - return ChebyshevExpansion(std::move(ce2.coef() + m_c), m_xmin, m_xmax); - } - else{ - if (m_c.size() > ce2.coef().size()) { - Eigen::VectorXd c(m_c.size()); c.setZero(); c.head(ce2.coef().size()) = ce2.coef(); - return ChebyshevExpansion(c+m_c, m_xmin, m_xmax); - } - else { - std::size_t n = ce2.coef().size(); - Eigen::VectorXd c(n); c.setZero(); c.head(m_c.size()) = m_c; - return ChebyshevExpansion(c + ce2.coef(), m_xmin, m_xmax); - } - } - }; - ChebyshevExpansion& ChebyshevExpansion::operator+=(const ChebyshevExpansion &donor) { - std::size_t Ndonor = donor.coef().size(), N1 = m_c.size(); - std::size_t Nmin = std::min(N1, Ndonor), Nmax = std::max(N1, Ndonor); - // The first Nmin terms overlap between the two vectors - m_c.head(Nmin) += donor.coef().head(Nmin); - // If the donor vector is longer than the current vector, resizing is needed - if (Ndonor > N1) { - // Resize but leave values as they were - m_c.conservativeResize(Ndonor); - // Copy the last Nmax-Nmin values from the donor - m_c.tail(Nmax - Nmin) = donor.coef().tail(Nmax - Nmin); - } - return *this; - } - ChebyshevExpansion& ChebyshevExpansion::operator-=(const ChebyshevExpansion& donor) { - std::size_t Ndonor = donor.coef().size(), N1 = m_c.size(); - std::size_t Nmin = std::min(N1, Ndonor), Nmax = std::max(N1, Ndonor); - // The first Nmin terms overlap between the two vectors - m_c.head(Nmin) -= donor.coef().head(Nmin); - // If the donor vector is longer than the current vector, resizing is needed - if (Ndonor > N1) { - // Resize but leave values as they were - m_c.conservativeResize(Ndonor); - // Copy the last Nmax-Nmin values from the donor - m_c.tail(Nmax - Nmin) = -donor.coef().tail(Nmax - Nmin); - } - return *this; - } - ChebyshevExpansion ChebyshevExpansion::operator-(const ChebyshevExpansion& ce2) const { - if (m_c.size() == ce2.coef().size()) { - // Both are the same size, nothing creative to do, just subtract the coefficients - return ChebyshevExpansion(std::move(ce2.coef() - m_c), m_xmin, m_xmax); - } - else { - if (m_c.size() > ce2.coef().size()) { - Eigen::VectorXd c(m_c.size()); c.setZero(); c.head(ce2.coef().size()) = ce2.coef(); - return ChebyshevExpansion(m_c - c, m_xmin, m_xmax); - } - else { - std::size_t n = ce2.coef().size(); - Eigen::VectorXd c(n); c.setZero(); c.head(m_c.size()) = m_c; - return ChebyshevExpansion(c - ce2.coef(), m_xmin, m_xmax); - } - } - }; - ChebyshevExpansion ChebyshevExpansion::operator*(double value) const { - return ChebyshevExpansion(m_c*value, m_xmin, m_xmax); - } - ChebyshevExpansion ChebyshevExpansion::operator+(double value) const { - Eigen::VectorXd c = m_c; - c(0) += value; - return ChebyshevExpansion(c, m_xmin, m_xmax); - } - ChebyshevExpansion ChebyshevExpansion::operator-(double value) const { - Eigen::VectorXd c = m_c; - c(0) -= value; - return ChebyshevExpansion(c, m_xmin, m_xmax); - } - ChebyshevExpansion ChebyshevExpansion::operator-() const{ - Eigen::VectorXd c = m_c; - return ChebyshevExpansion(-c, m_xmin, m_xmax); - } - ChebyshevExpansion& ChebyshevExpansion::operator*=(double value) { - m_c *= value; - return *this; - } - ChebyshevExpansion& ChebyshevExpansion::operator+=(double value) { - m_c(0) += value; - return *this; - } - ChebyshevExpansion& ChebyshevExpansion::operator-=(double value) { - m_c(0) -= value; - return *this; - } - ChebyshevExpansion ChebyshevExpansion::operator*(const ChebyshevExpansion &ce2) const { - - std::size_t order1 = this->m_c.size()-1, - order2 = ce2.coef().size()-1; - // The order of the product is the sum of the orders of the two expansions - std::size_t Norder_product = order1 + order2; - - // Create padded vectors, and copy into them the coefficients from this instance - // and that of the donor - Eigen::VectorXd a = Eigen::VectorXd::Zero(Norder_product+1), - b = Eigen::VectorXd::Zero(Norder_product+1); - a.head(order1+1) = this->m_c; b.head(order2+1) = ce2.coef(); - - // Get the matrices U and V from the libraries - const Eigen::MatrixXd &U = u_matrix_library.get(Norder_product); - const Eigen::MatrixXd &V = l_matrix_library.get(Norder_product); - - // Carry out the calculation of the final coefficients - // U*a is the functional values at the Chebyshev-Lobatto nodes for the first expansion - // U*b is the functional values at the Chebyshev-Lobatto nodes for the second expansion - // The functional values are multiplied together in an element-wise sense - this is why both products are turned into arrays - // The pre-multiplication by V takes us back to coefficients - return ChebyshevExpansion(V*((U*a).array() * (U*b).array()).matrix(), m_xmin, m_xmax); - }; - ChebyshevExpansion ChebyshevExpansion::times_x() const { - // First we treat the of chi*A multiplication in the domain [-1,1] - Eigen::Index N = m_c.size()-1; // N is the order of A - Eigen::VectorXd cc(N+2); // Order of x*A is one higher than that of A - if (N > 1) { - cc(0) = m_c(1)/2.0; - } - if (N > 2) { - cc(1) = m_c(0) + m_c(2)/2.0; - } - for (Eigen::Index i = 2; i < cc.size(); ++i) { - cc(i) = (i+1 <= N) ? 0.5*(m_c(i-1) + m_c(i+1)) : 0.5*(m_c(i - 1)); - } - // Scale the values into the real world, which is given by - // C_scaled = (b-a)/2*(chi*A) + ((b+a)/2)*A - // where the coefficients in the second term need to be padded with a zero to have - // the same order as the product of x*A - Eigen::VectorXd c_padded(N+2); c_padded << m_c, 0; - Eigen::VectorXd coefs = (((m_xmax - m_xmin)/2.0)*cc).array() + (m_xmax + m_xmin)/2.0*c_padded.array(); - return ChebyshevExpansion(coefs, m_xmin, m_xmax); - }; - ChebyshevExpansion& ChebyshevExpansion::times_x_inplace() { - Eigen::Index N = m_c.size() - 1; // N is the order of A - double diff = ((m_xmax - m_xmin) / 2.0), plus = (m_xmax + m_xmin) / 2.0; - double cim1old = 0, ciold = 0; - m_c.conservativeResize(N+2); - m_c(N+1) = 0.0; // Fill the last entry with a zero - if (N > 1) { - // 0-th element - cim1old = m_c(0); // store the current 0-th element in temporary variable - m_c(0) = diff*(0.5*m_c(1)) + plus*m_c(0); - } - if (N > 2) { - // 1-th element - ciold = m_c(1); // store the current 1-th element in temporary variable - m_c(1) = diff*(cim1old + 0.5*m_c(2)) + plus*m_c(1); - cim1old = ciold; - } - for (Eigen::Index i = 2; i <= N-1; ++i) { - ciold = m_c(i); // store the current i-th element in temporary variable - m_c(i) = diff*(0.5*(cim1old + m_c(i + 1)))+plus*m_c(i); - cim1old = ciold; - } - for (Eigen::Index i = N; i <= N + 1; ++i) { - ciold = m_c(i); // store the current i-th element in temporary variable - m_c(i) = diff*(0.5*cim1old) + plus*m_c(i); - cim1old = ciold; - } - return *this; - }; - ChebyshevExpansion ChebyshevExpansion::reciprocal() const{ - // 1. Transform Chebyshev-Lobatto node function values by the function f(y) -> 1/y - // 2. Go backwards to coefficients from node values c2 = V/y - const auto Ndegree = m_c.size() - 1; - const Eigen::MatrixXd& V = l_matrix_library.get(Ndegree); - // Values at the nodes in the x range of [-1, 1] - Eigen::VectorXd c = V*(1.0/get_node_function_values().array()).matrix(); - - return ChebyshevExpansion(c, xmin(), xmax()); - } - ChebyshevExpansion ChebyshevExpansion::apply(std::function<Eigen::ArrayXd(const Eigen::ArrayXd &)> &f) const{ - // 1. Transform Chebyshev-Lobatto node function values by the function f(y) -> y2 - // 2. Go backwards to coefficients from node values c2 = V*y2 - const auto Ndegree = m_c.size()-1; - const Eigen::MatrixXd &V = l_matrix_library.get(Ndegree); - return ChebyshevExpansion(V*f(get_node_function_values()).matrix(), xmin(), xmax()); - } - bool ChebyshevExpansion::is_monotonic() const { - auto yvals = get_node_function_values(); - auto N = yvals.size(); - Eigen::ArrayXd diff = yvals.tail(N - 1) - yvals.head(N - 1); - return (diff < 0.0).all() || (diff > 0.0).all(); - } - - const vectype &ChebyshevExpansion::coef() const { - return m_c; - }; - /** - * @brief Do a single input/single output evaluation of the Chebyshev expansion with the inputs scaled in [xmin, xmax] - * @param x A value scaled in the domain [xmin,xmax] - */ - double ChebyshevExpansion::y_recurrence(const double x) { - // Use the recurrence relationships to evaluate the Chebyshev expansion - std::size_t Norder = m_c.size() - 1; - // Scale x linearly into the domain [-1, 1] - double xscaled = (2 * x - (m_xmax + m_xmin)) / (m_xmax - m_xmin); - // Short circuit if not using recursive solution - if (Norder == 0){ return m_c[0]; } - if (Norder == 1) { return m_c[0] + m_c[1]*xscaled; } - - vectype &o = m_recurrence_buffer; - o(0) = 1; - o(1) = xscaled; - for (int n = 1; n < Norder; ++n) { - o(n + 1) = 2 * xscaled*o(n) - o(n - 1); - } - return m_c.dot(o); - } - double ChebyshevExpansion::y_Clenshaw_xscaled(const double xscaled) const { - // See https://en.wikipedia.org/wiki/Clenshaw_algorithm#Special_case_for_Chebyshev_series - std::size_t Norder = m_c.size() - 1; - double u_k = 0, u_kp1 = m_c[Norder], u_kp2 = 0; - int k = 0; - for (k = static_cast<int>(Norder) - 1; k >= 1; --k) { - // Do the recurrent calculation - u_k = 2.0 * xscaled * u_kp1 - u_kp2 + m_c(k); - // Update the values - u_kp2 = u_kp1; u_kp1 = u_k; - } - return m_c(0) + xscaled * u_kp1 - u_kp2; - } - /** - * @brief Do a vectorized evaluation of the Chebyshev expansion with the inputs scaled in [xmin, xmax] - * @param x A vectype of values in the domain [xmin,xmax] - */ - vectype ChebyshevExpansion::y(const vectype &x) const { - // Scale x linearly into the domain [-1, 1] - const vectype xscaled = (2 * x.array() - (m_xmax + m_xmin)) / (m_xmax - m_xmin); - // Then call the function that takes the scaled x values - return y_recurrence_xscaled(xscaled); - } - /** - * @brief Do a vectorized evaluation of the Chebyshev expansion with the input scaled in the domain [-1,1] - * @param xscaled A vectype of values scaled to the domain [-1,1] (the domain of the Chebyshev basis functions) - * @returns y A vectype of values evaluated from the expansion - * - * By using vectorizable types like Eigen::MatrixXd, without - * any additional work, "magical" vectorization is happening - * under the hood, giving a significant speed improvement. From naive - * testing, the increase was a factor of about 10x. - */ - vectype ChebyshevExpansion::y_recurrence_xscaled(const vectype &xscaled) const { - const std::size_t Norder = m_c.size() - 1; - - Eigen::MatrixXd A(xscaled.size(), Norder + 1); - - if (Norder == 0) { return m_c[0]*Eigen::MatrixXd::Ones(A.rows(), A.cols()); } - if (Norder == 1) { return m_c[0] + m_c[1]*xscaled.array(); } - - // Use the recurrence relationships to evaluate the Chebyshev expansion - // In this case we do column-wise evaluations of the recurrence rule - A.col(0).fill(1); - A.col(1) = xscaled; - for (int n = 1; n < Norder; ++n) { - A.col(n + 1).array() = 2 * xscaled.array()*A.col(n).array() - A.col(n - 1).array(); - } - // In this form, the matrix-vector product will yield the y values - return A*m_c; - } - vectype ChebyshevExpansion::y_Clenshaw_xscaled(const vectype &xscaled) const { - const std::size_t Norder = m_c.size() - 1; - vectype u_k, u_kp1(xscaled.size()), u_kp2(xscaled.size()); - u_kp1.fill(m_c[Norder]); u_kp2.fill(0); - for (int k = static_cast<int>(Norder) - 1; k >= 1; --k) { - u_k = 2 * xscaled.array()*u_kp1.array() - u_kp2.array() + m_c(k); - // Update summation values for all but the last step - if (k > 1) { - u_kp2 = u_kp1; u_kp1 = u_k; - } - } - return xscaled.array()*u_k.array() - u_kp1.array() + m_c(0); - } - - Eigen::MatrixXd ChebyshevExpansion::companion_matrix(const Eigen::VectorXd &coeffs) const { - Eigen::VectorXd new_mc = reduce_zeros(coeffs); - std::size_t Norder = new_mc.size() - 1; - Eigen::MatrixXd A = Eigen::MatrixXd::Zero(Norder, Norder); - // c_wrap wraps the first 0...Norder elements of the coefficient vector - Eigen::Map<const Eigen::VectorXd> c_wrap(&(new_mc[0]), Norder); - // First row - A(0, 1) = 1; - // Last row - A.row(Norder - 1) = -c_wrap / (2.0*new_mc(Norder)); - A(Norder - 1, Norder - 2) += 0.5; - // All the other rows - for (int j = 1; j < Norder - 1; ++j) { - A(j, j - 1) = 0.5; - A(j, j + 1) = 0.5; - } - return A; - } - std::vector<double> ChebyshevExpansion::real_roots2(bool only_in_domain) const { - //vector of roots to be returned - std::vector<double> roots; - - auto N = m_c.size()-1; - auto Ndegree_scaled = N*2; - Eigen::VectorXd xscaled = get_CLnodes(Ndegree_scaled), yy = y_Clenshaw_xscaled(xscaled); - - // a,b,c can also be obtained by solving the matrix system: - // [x_k^2, x_k, 1] = [b_k] for k in 1,2,3 - for (auto i = 0; i+2 < Ndegree_scaled+1; i += 2){ - const double &x_1 = xscaled[i + 0], &y_1 = yy[i + 0], - &x_2 = xscaled[i + 1], &y_2 = yy[i + 1], - &x_3 = xscaled[i + 2], &y_3 = yy[i + 2]; - double d = (x_3 - x_2)*(x_2 - x_1)*(x_3 - x_1); - double a = ((x_3 - x_2)*y_1 - (x_3 - x_1)*y_2 + (x_2 - x_1)*y_3) / d; - double b = (-(POW2(x_3) - POW2(x_2))*y_1 + (POW2(x_3) - POW2(x_1))*y_2 - (POW2(x_2) - POW2(x_1))*y_3) / d; - double c = ((x_3 - x_2)*x_2*x_3*y_1 - (x_3 - x_1)*x_1*x_3*y_2 + (x_2 - x_1)*x_2*x_1*y_3) / d; - - // Discriminant of quadratic - double D = b*b - 4*a*c; - if (D >= 0) { - double root1, root2; - if (a == 0){ - // Linear - root1 = -c/b; - root2 = -1000; // Something outside the domain; we are in scaled coordinates so this will definitely get rejected - } - else if (D == 0) { // Unlikely due to numerical precision - // Two equal real roots - root1 = -b/(2*a); - root2 = -1000; // Something outside the domain; we are in scaled coordinates so this will definitely get rejected - } - else { - // Numerically stable method for solving quadratic - // From https://people.csail.mit.edu/bkph/articles/Quadratics.pdf - double sqrtD = sqrt(D); - if (b >= 0){ - root1 = (-b - sqrtD)/(2*a); - root2 = 2*c/(-b-sqrtD); - } - else { - root1 = 2*c/(-b+sqrtD); - root2 = (-b+sqrtD)/(2*a); - } - } - bool in1 = inbetween(x_1, x_3, root1), in2 = inbetween(x_1, x_3, root2); - const ChebyshevExpansion &e = *this; - auto secant = [e](double a, double ya, double b, double yb, double yeps = 1e-14, double xeps = 1e-14) { - auto c = b - yb*(b - a) / (yb - ya); - auto yc = e.y_Clenshaw_xscaled(c); - for (auto i = 0; i < 50; ++i){ - if (yc*ya > 0) { - a=c; ya=yc; - } - else { - b=c; yb=yc; - } - if (std::abs(b - a) < xeps) { break; } - if (std::abs(yc) < yeps){ break; } - c = b - yb*(b - a) / (yb - ya); - yc = e.y_Clenshaw_xscaled(c); - } - return c; - }; - int Nroots_inside = static_cast<int>(in1) + static_cast<int>(in2); - if (Nroots_inside == 2) { - // Split the domain at the midline of the quadratic, polish each root against the underlying expansion - double x_m = -b/(2*a), y_m = e.y_Clenshaw_xscaled(x_m); - root1 = secant(x_1, y_1, x_m, y_m); - root2 = secant(x_m, y_m, x_3, y_3); - // Rescale back into real-world values in [xmin,xmax] from [-1,1] - roots.push_back(((m_xmax - m_xmin)*root1 + (m_xmax + m_xmin)) / 2.0); - roots.push_back(((m_xmax - m_xmin)*root2 + (m_xmax + m_xmin)) / 2.0); - } - else if(Nroots_inside == 1) { - root1 = secant(x_1, y_1, x_3, y_3); - roots.push_back(((m_xmax - m_xmin)*root1 + (m_xmax + m_xmin)) / 2.0); - } - else {} - } - } - return roots; - } - std::vector<double> ChebyshevExpansion::real_roots(bool only_in_domain) const { - //vector of roots to be returned - std::vector<double> roots; - Eigen::VectorXd new_mc = reduce_zeros(m_c); - //if the Chebyshev polynomial is just a constant, then there are no roots - //if a_0=0 then there are infinite roots, but for our purposes, infinite roots doesnt make sense - if (new_mc.size()<=1){ //we choose <=1 to account for the case of no coefficients - return roots; //roots is empty - } - - //if the Chebyshev polynomial is linear, then the only possible root is -a_0/a_1 - //we have this else if block because eigen is not a fan of 1x1 matrices - else if (new_mc.size()==2){ - double val_n11 = -new_mc(0)/new_mc(1); - const bool is_in_domain = (val_n11 >= -1.0 && val_n11 <= 1.0); - // Keep it if it is in domain, or if you just want all real roots - if (!only_in_domain || is_in_domain) { - // Rescale back into real-world values in [xmin,xmax] from [-1,1] - double x = ((m_xmax - m_xmin)*val_n11 + (m_xmax + m_xmin)) / 2.0; - roots.push_back(x); - } - } - - //this for all cases of higher order polynomials - else{ - // The companion matrix is definitely lower Hessenberg, so we can skip the Hessenberg - // decomposition, and get the real eigenvalues directly. These eigenvalues are defined - // in the domain [-1, 1], but it might also include values outside [-1, 1] - Eigen::VectorXcd eigs = eigenvalues(companion_matrix(new_mc), /* balance = */ true); - - - for (Eigen::Index i = 0; i < eigs.size(); ++i) { - if (std::abs(eigs(i).imag() / eigs(i).real()) < 1e-15) { - double val_n11 = eigs(i).real(); - const bool is_in_domain = (val_n11 >= -1.0 && val_n11 <= 1.0); - // Keep it if it is in domain, or if you just want all real roots - if (!only_in_domain || is_in_domain) { - // Rescale back into real-world values in [xmin,xmax] from [-1,1] - double x = ((m_xmax - m_xmin)*val_n11 + (m_xmax + m_xmin)) / 2.0; - roots.push_back(x); - } - } - } - } - return roots; - - //// The companion matrix is definitely lower Hessenberg, so we can skip the Hessenberg - //// decomposition, and get the real eigenvalues directly. These eigenvalues are defined - //// in the domain [-1, 1], but it might also include values outside [-1, 1] - //Eigen::VectorXd real_eigs = eigenvalues_upperHessenberg(companion_matrix().transpose(), /* balance = */ true); - // - //std::vector<double> roots; - //for (Eigen::Index i = 0; i < real_eigs.size(); ++i){ - // double val_n11 = real_eigs(i); - // const bool is_in_domain = (val_n11 >= -1.0 && val_n11 <= 1.0); - // // Keep it if it is in domain, or if you just want all real roots - // if (!only_in_domain || is_in_domain){ - // // Rescale back into real-world values in [xmin,xmax] from [-1,1] - // double x = ((m_xmax - m_xmin)*val_n11 + (m_xmax + m_xmin)) / 2.0; - // roots.push_back(x); - // } - //} - //return roots; - } - double ChebyshevExpansion::monotonic_solvex(double y) { - /* - Function is known to be monotonic, so we can shortcut some of the solving steps used - We don't use the eigenvalue method because it is too slow - */ - auto& e = *this; - auto secant = [e,y](double a, double ya, double b, double yb, double yeps = 1e-14, double xeps = 1e-14) { - double c, yc; - for (auto i = 0; i < 50; ++i) { - c = b - yb * (b - a) / (yb - ya); - yc = e.y_Clenshaw_xscaled(c)-y; - if (yc * ya > 0) { - a = c; ya = yc; - } - else { - b = c; yb = yc; - } - if (std::abs(b - a) < xeps) { break; } - if (std::abs(yc) < yeps) { break; } - } - return c; - }; - // Determine if the function is monotonically increasing or decreasing - auto ynodes = get_node_function_values(); - auto nodes = get_nodes_n11(); - bool increasing = ynodes[ynodes.size() - 1] > ynodes[0]; // Nodes go from 1 to -1 (stuck with this), but increasing says whether the value at the last *index* (x=-1) is greater than that of the first index (x=1). - if (increasing) { - if (y > ynodes[ynodes.size() - 1]) { - throw std::invalid_argument("Argument is outside the range of the expansion"); - } - if (y < ynodes[0]) { - throw std::invalid_argument("Argument is outside the range of the expansion"); - } - } - else { - if (y < ynodes[ynodes.size() - 1]) { - throw std::invalid_argument("Argument is outside the range of the expansion"); - } - if (y > ynodes[0]) { - throw std::invalid_argument("Argument is outside the range of the expansion"); - } - } - - // Interval bisection to find the Chebyshev-Lobatto nodes that bound the solution by bisection - int N = static_cast<int>(ynodes.size()); - Eigen::Index i = (increasing) ? get_increasingleftofval(ynodes, y, N) : get_decreasingleftofval(ynodes, y, N); - auto xscaled = secant(nodes(i), ynodes(i)-y, nodes(i + 1), ynodes(i + 1)-y); - return unscale_x(xscaled); - } - - std::vector<ChebyshevExpansion> ChebyshevExpansion::subdivide(std::size_t Nintervals, const std::size_t Norder) const { - - if (Nintervals == 1) { - return std::vector<ChebyshevExpansion>(1, *this); - } - - std::vector<ChebyshevExpansion> segments; - double deltax = (m_xmax - m_xmin) / (Nintervals - 1); - - // Vector of values in the range [-1,1] as roots of a high-order Chebyshev - double NN = static_cast<double>(Norder); - Eigen::VectorXd xpts_n11 = (Eigen::VectorXd::LinSpaced(Norder + 1, 0, NN)*EIGEN_PI/NN).array().cos(); - - for (std::size_t i = 0; i < Nintervals - 1; ++i) { - double xmin = m_xmin + i*deltax, xmax = m_xmin + (i + 1)*deltax; - Eigen::VectorXd xrealworld = ((xmax - xmin)*xpts_n11.array() + (xmax + xmin)) / 2.0; - segments.push_back(factoryf(Norder, y(xrealworld), xmin, xmax)); - } - return segments; - } - std::vector<double> ChebyshevExpansion::real_roots_intervals(const std::vector<ChebyshevExpansion> &segments, bool only_in_domain) { - std::vector<double> roots; - for (auto &seg : segments) { - const auto segroots = seg.real_roots(only_in_domain); - roots.insert(roots.end(), segroots.cbegin(), segroots.cend()); - } - return roots; - } - std::vector<double> ChebyshevExpansion::real_roots_approx(long Npoints) - { - std::vector<double> roots; - // Vector of values in the range [-1,1] as roots of a high-order Chebyshev - Eigen::VectorXd xpts_n11 = (Eigen::VectorXd::LinSpaced(Npoints + 1, 0, Npoints)*EIGEN_PI / Npoints).array().cos(); - // Scale values into real-world values - Eigen::VectorXd ypts = y_recurrence_xscaled(xpts_n11); - // Eigen::MatrixXd buf(Npoints+1, 2); buf.col(0) = xpts; buf.col(1) = ypts; std::cout << buf << std::endl; - for (size_t i = 0; i < Npoints - 1; ++i) { - // The change of sign guarantees at least one root between indices i and i+1 - double y1 = ypts(i), y2 = ypts(i + 1); - bool signchange = (std::signbit(y1) != std::signbit(y2)); - if (signchange) { - double xscaled = xpts_n11(i); - - // Fit a quadratic given three points; i and i+1 bracket the root, so need one more constraint - // i0 is the leftmost of the three indices that will be used; when i == 0, use - // indices i,i+1,i+2, otherwise i-1,i,i+1 - size_t i0 = (i >= 1) ? i - 1 : i; - Eigen::Vector3d r; - r << ypts(i0), ypts(i0 + 1), ypts(i0 + 2); - Eigen::Matrix3d A; - for (std::size_t irow = 0; irow < 3; ++irow) { - double _x = xpts_n11(i0 + irow); - A.row(irow) << _x*_x, _x, 1; - } - // abc holds the coefficients a,b,c for y = a*x^2 + b*x + c - Eigen::VectorXd abc = A.colPivHouseholderQr().solve(r); - double a = abc[0], b = abc[1], c = abc[2]; - - // Solve the quadratic and find the root you want - double x1 = (-b + sqrt(b*b - 4 * a*c)) / (2 * a); - double x2 = (-b - sqrt(b*b - 4 * a*c)) / (2 * a); - bool x1_in_range = is_in_closed_range(xpts_n11(i), xpts_n11(i + 1), x1); - bool x2_in_range = is_in_closed_range(xpts_n11(i), xpts_n11(i + 1), x2); - - // Double check that only one root is within the range - if (x1_in_range && !x2_in_range) { - xscaled = x1; - } - else if (x2_in_range && !x1_in_range) { - xscaled = x2; - } - else { - xscaled = 1e99; - } - - // Rescale back into real-world values - double x = ((m_xmax - m_xmin)*xscaled + (m_xmax + m_xmin)) / 2.0; - roots.push_back(x); - } - else { - // TODO: locate other roots based on derivative considerations - } - } - return roots; - } - - /// Chebyshev-Lobatto nodes \f$ \cos(\pi j/N), j = 0,..., N \f$ in the range [-1,1] - Eigen::VectorXd ChebyshevExpansion::get_nodes_n11() { - std::size_t N = m_c.size()-1; - return CLnodes_library.get(N); - } - /// Chebyshev-Lobatto nodes \f$\cos(\pi j/N), j = 0,..., N \f$ mapped to the range [xmin, xmax] - Eigen::VectorXd ChebyshevExpansion::get_nodes_realworld() { - return ((m_xmax - m_xmin)*get_nodes_n11().array() + (m_xmax + m_xmin))*0.5; - } - /// Values of the function at the Chebyshev-Lobatto nodes - Eigen::VectorXd ChebyshevExpansion::get_node_function_values() const{ - if (m_nodal_value_cache.size() > 0) { - return m_nodal_value_cache; - } - else { - std::size_t N = m_c.size() - 1; - return u_matrix_library.get(N) * m_c; - } - } - ChebyshevExpansion ChebyshevExpansion::factoryf(const std::size_t N, const Eigen::VectorXd &f, const double xmin, const double xmax) { - // Step 3: Get coefficients for the L matrix from the library of coefficients - const Eigen::MatrixXd &L = l_matrix_library.get(N); - // Step 4: Obtain coefficients from vector - matrix product - return ChebyshevExpansion(L*f, xmin, xmax); - } - ChebyshevExpansion ChebyshevExpansion::factoryfFFT(const std::size_t N, const Eigen::VectorXd& f, const double xmin, const double xmax) { - - Eigen::VectorXd valsUnitDisc(2 * f.size() - 2); - // Starting at x = 1, going to -1, then the same nodes, not including x=-1 and x=1, in the opposite order - valsUnitDisc.head(f.size()) = f; - valsUnitDisc.tail(f.size() - 2) = f.reverse().segment(1, f.size() - 2); - - Eigen::FFT<double> fft; - Eigen::VectorXcd FourierCoeffs(2 * f.size() - 2); - fft.fwd(FourierCoeffs, valsUnitDisc); - auto n = f.size() - 1; - Eigen::ArrayXd ChebCoeffs = FourierCoeffs.real().head(n+1)/n; - ChebCoeffs[0] /= 2; - ChebCoeffs[ChebCoeffs.size()-1] /= 2; - - return ChebyshevExpansion(ChebCoeffs, xmin, xmax); - } - ChebyshevExpansion ChebyshevExpansion::from_powxn(const std::size_t n, const double xmin, const double xmax) { - if (xmin != -1) { - throw std::invalid_argument("xmin must be -1"); - } - if (xmax != 1) { - throw std::invalid_argument("xmax must be 1"); - } - Eigen::VectorXd c = Eigen::VectorXd::Zero(n + 1); - for (std::size_t k = 0; k <= n / 2; ++k) { - std::size_t index = n - 2 * k; - double coeff = binomialCoefficient(static_cast<double>(n), static_cast<double>(k)); - if (index == 0) { - coeff /= 2.0; - } - c(index) = coeff; - } - return pow(2, 1-static_cast<int>(n))*ChebyshevExpansion(c, xmin, xmax); - } - ChebyshevExpansion ChebyshevExpansion::deriv(std::size_t Nderiv) const { - // See Mason and Handscomb, p. 34, Eq. 2.52 - // and example in https ://github.com/numpy/numpy/blob/master/numpy/polynomial/chebyshev.py#L868-L964 - vectype c = m_c; - for (std::size_t deriv_counter = 0; deriv_counter < Nderiv; ++deriv_counter) { - std::size_t N = c.size() - 1, ///< Order of the expansion - Nd = N - 1; ///< Order of the derivative expansion - vectype cd(N); - for (std::size_t r = 0; r <= Nd; ++r) { - cd(r) = 0; - for (std::size_t k = r + 1; k <= N; ++k) { - // Terms where k-r is odd have values, otherwise, they are zero - if ((k - r) % 2 == 1) { - cd(r) += 2*k*c(k); - } - } - // The first term with r = 0 is divided by 2 (the single prime in Mason and Handscomb, p. 34, Eq. 2.52) - if (r == 0) { - cd(r) /= 2; - } - // Rescale the values if the range is not [-1,1]. Arrives from the derivative of d(xreal)/d(x_{-1,1}) - cd(r) /= (m_xmax-m_xmin)/2.0; - } - if (Nderiv == 1) { - return ChebyshevExpansion(std::move(cd), m_xmin, m_xmax); - } - else{ - c = cd; - } - } - return ChebyshevExpansion(std::move(c), m_xmin, m_xmax); - }; - ChebyshevExpansion ChebyshevExpansion::integrate(std::size_t Nintegral) const { - // See Mason and Handscomb, p. 33, Eq. 2.44 & 2.45 - // and example in https ://github.com/numpy/numpy/blob/master/numpy/polynomial/chebyshev.py#L868-L964 - if (Nintegral != 1) { throw std::invalid_argument("Only support one integral for now"); } - vectype c(m_c.size() + 1); - double width = m_xmax - m_xmin; - for (auto i = 1; i < m_c.size()+1; ++i) { - if (i == 1) { - // This special case is needed because the prime on the summation in Mason indicates the first coefficient - // is to be divided by two - c[i] = (2*m_c[i - 1] - m_c[i + 1]) / (2 * i); - } - else if (i + 1 > m_c.size()-1) { - c[i] = (m_c[i - 1]) / (2 * i); - } - else { - c[i] = (m_c[i - 1] - m_c[i + 1]) / (2 * i); - } - } - c(0) = 0; // This is the arbitrary constant; - c *= width / 2; - return ChebyshevExpansion(std::move(c), m_xmin, m_xmax); - } - - Eigen::VectorXd eigenvalues_upperHessenberg(const Eigen::MatrixXd &A, bool balance){ - Eigen::VectorXd roots(A.cols()); - Eigen::RealSchur<Eigen::MatrixXd> schur; - - if (balance) { - Eigen::MatrixXd Abalanced, D; - balance_matrix(A, Abalanced, D); - schur.computeFromHessenberg(Abalanced, Eigen::MatrixXd::Zero(Abalanced.rows(), Abalanced.cols()), false); - } - else { - schur.computeFromHessenberg(A, Eigen::MatrixXd::Zero(A.rows(), A.cols()), false); - } - - const Eigen::MatrixXd &T = schur.matrixT(); - Eigen::Index j = 0; - for (int i = 0; i < T.cols(); ++i) { - if (i+1 < T.cols()-1 && std::abs(T(i+1,i)) > DBL_EPSILON){ - // Nope, this is a 2x2 block, keep moving - i += 1; - } - else{ - // This is a 1x1 block, keep this (real) eigenvalue - roots(j) = T(i, i); - j++; - } - } - roots.conservativeResize(j-1); - return roots; - } - - Eigen::VectorXcd eigenvalues(const Eigen::MatrixXd &A, bool balance) { - if (balance) { - Eigen::MatrixXd Abalanced, D; - balance_matrix(A, Abalanced, D); - return Abalanced.eigenvalues(); - } - else { - return A.eigenvalues(); - } - } - -}; /* namespace ChebTools */ diff --git a/src/external/ChebTools/ChebTools.h b/src/external/ChebTools/ChebTools.h deleted file mode 100644 index 816e273f..00000000 --- a/src/external/ChebTools/ChebTools.h +++ /dev/null @@ -1,565 +0,0 @@ -//Copyright 2018* United States Secretary of Commerce, NIST. -// -//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -// Credit to https://github.com/usnistgov/ChebTools - -#ifndef CHEBTOOLS_H -#define CHEBTOOLS_H - -#include "Eigen/Dense" -#include <vector> -#include <queue> - -#include <map> - - -namespace ChebTools{ - - // https://proquest.safaribooksonline.com/9780321637413 - // https://web.stanford.edu/class/archive/cs/cs107/cs107.1202/lab1/ - static int midpoint_Knuth(int x, int y) { - return (x & y) + ((x ^ y) >> 1); - }; - - - /** - * @brief This class stores sets of L matrices (because they are a function only of the degree of the expansion) - * - * The L matrix is used to convert from functional values to coefficients, as in \f[ \vec{c} = \mathbf{L}\vec{f} \f] - */ - class LMatrixLibrary { - private: - std::map<std::size_t, Eigen::MatrixXd> matrices; - void build(std::size_t N) { - Eigen::MatrixXd L(N + 1, N + 1); ///< Matrix of coefficients - for (int j = 0; j <= N; ++j) { - for (int k = j; k <= N; ++k) { - double p_j = (j == 0 || j == N) ? 2 : 1; - double p_k = (k == 0 || k == N) ? 2 : 1; - L(j, k) = 2.0 / (p_j*p_k*N)*cos((j*EIGEN_PI*k) / N); - // Exploit symmetry to fill in the symmetric elements in the matrix - L(k, j) = L(j, k); - } - } - matrices[N] = L; - } - public: - /// Get the \f$\mathbf{L}\f$ matrix of degree N - const Eigen::MatrixXd & get(std::size_t N) { - auto it = matrices.find(N); - if (it != matrices.end()) { - return it->second; - } - else { - build(N); - return matrices.find(N)->second; - } - } - }; - static LMatrixLibrary l_matrix_library; - - /** - * @brief This class stores sets of U matrices (because they are a function only of the degree of the expansion) - * - * The U matrix is used to convert from coefficients to functional values, as in \f[ \vec{f} = \mathbf{U}\vec{c} \f] - */ - class UMatrixLibrary { - private: - std::map<std::size_t, Eigen::MatrixXd> matrices; - void build(std::size_t N) { - Eigen::MatrixXd U(N + 1, N + 1); ///< Matrix of coefficients - for (int j = 0; j <= N; ++j) { - for (int k = j; k <= N; ++k) { - U(j, k) = cos((j*EIGEN_PI*k) / N); - // Exploit symmetry to fill in the symmetric elements in the matrix - U(k, j) = U(j, k); - } - } - matrices[N] = U; - } - public: - /// Get the \f$\mathbf{U}\f$ matrix of degree N - const Eigen::MatrixXd & get(std::size_t N) { - auto it = matrices.find(N); - if (it != matrices.end()) { - return it->second; - } - else { - build(N); - return matrices.find(N)->second; - } - } - }; - static UMatrixLibrary u_matrix_library; - - /** - For a monotonically increasing vector, find the left index of the interval bracketing the given value - */ - template<typename VecType> - int get_increasingleftofval(const VecType& breakpoints, double x, int N) { - int iL = 0, iR = N - 1, iM; - while (iR - iL > 1) { - iM = midpoint_Knuth(iL, iR); - if (x >= breakpoints[iM]) { - iL = iM; - } - else { - iR = iM; - } - } - return iL; - }; - - /** - For a monotonically decreasing vector, find the left index of the interval bracketing the given value - */ - template<typename VecType> - int get_decreasingleftofval(const VecType& breakpoints, double x, int N) { - int iL = 0, iR = N - 1, iM; - while (iR - iL > 1) { - iM = midpoint_Knuth(iL, iR); - if (x <= breakpoints[iM]) { - iL = iM; - } - else { - iR = iM; - } - } - return iL; - }; - - typedef Eigen::VectorXd vectype; - - /// Get the Chebyshev-Lobatto nodes for an expansion of degree \f$N\f$ - const Eigen::VectorXd &get_CLnodes(std::size_t N); - - Eigen::VectorXcd eigenvalues(const Eigen::MatrixXd &A, bool balance); - Eigen::VectorXd eigenvalues_upperHessenberg(const Eigen::MatrixXd &A, bool balance); - - /** - * @brief This is the main underlying object that makes all of the code of ChebTools work. - * - * This class has accessor methods for getting things from the object, and static factory - * functions for generating new expansions. It also has methods for calculating derivatives, - * roots, etc. - */ - class ChebyshevExpansion { - private: - vectype m_c; - double m_xmin, m_xmax; - - vectype m_recurrence_buffer; - vectype m_nodal_value_cache; - void resize() { - m_recurrence_buffer.resize(m_c.size()); - } - - //reduce_zeros changes the m_c field so that our companion matrix doesnt have nan values in it - //all this does is truncate m_c such that there are no trailing zero values - static Eigen::VectorXd reduce_zeros(const Eigen:: VectorXd &chebCoeffs){ - //these give us a threshold for what coefficients are large enough - double largeTerm = 1e-15; - if (chebCoeffs.size()>=1 && std::abs(chebCoeffs(0))>largeTerm){ - largeTerm = chebCoeffs(0); - } - //if the second coefficient is larger than the first, then make our tolerance - //based on the second coefficient, this is useful for functions whose mean value - //is zero on the interval - if (chebCoeffs.size()>=2 && std::abs(chebCoeffs(1))>largeTerm){ - largeTerm = chebCoeffs(1); - } - double tol = largeTerm*(1e-15); - int neededSize = static_cast<int>(chebCoeffs.size()); - //loop over m_c backwards, if we run into large enough coefficient, then record the size and break - for (int i=static_cast<int>(chebCoeffs.size())-1; i>=0; i--){ - if (std::abs(chebCoeffs(i))>tol){ - neededSize = i+1; - break; - } - neededSize--; - } - //neededSize gives us the number of coefficients that are nonzero - //we will resize m_c such that there are essentially no trailing zeros - return chebCoeffs.head(neededSize); - } - - public: - /// Initializer with coefficients, and optionally a range provided - ChebyshevExpansion(const vectype &c, double xmin = -1, double xmax = 1) : m_c(c), m_xmin(xmin), m_xmax(xmax) { resize(); }; - /// Initializer with coefficients, and optionally a range provided - ChebyshevExpansion(const std::vector<double> &c, double xmin = -1, double xmax = 1) : m_xmin(xmin), m_xmax(xmax) { - m_c = Eigen::Map<const Eigen::VectorXd>(&(c[0]), c.size()); - resize(); - }; - /// Move constructor (C++11 only) - ChebyshevExpansion(const vectype &&c, double xmin = -1, double xmax = 1) : m_c(c), m_xmin(xmin), m_xmax(xmax) { resize(); }; - - /// Cache nodal function values - void cache_nodal_function_values(vectype values) { - m_nodal_value_cache = values; - } - /// Get the minimum value of \f$x\f$ for the expansion - double xmin() const{ return m_xmin; } - /// Get the maximum value of \f$x\f$ for the expansion - double xmax() const{ return m_xmax; } - /// Go from a value in [xmin,xmax] to a value in [-1,1] - double scale_x(const double x) const { - return (2 * x - (m_xmax + m_xmin)) / (m_xmax - m_xmin); - } - /// Map from a value in [-1,1] to a value in [xmin,xmax] - double unscale_x(const double xscaled) const { - return ((m_xmax - m_xmin)*xscaled + (m_xmax + m_xmin))/2; - } - - /// Get the vector of coefficients in increasing order - const vectype &coef() const; - - /// Return the N-th derivative of this expansion, where N must be >= 1 - ChebyshevExpansion deriv(std::size_t Nderiv) const; - /// Return the indefinite integral of this function - ChebyshevExpansion integrate(std::size_t Nintegral = 1) const; - /// Get the Chebyshev-Lobatto nodes in the domain [-1,1] - Eigen::VectorXd get_nodes_n11(); - /// Get the Chebyshev-Lobatto nodes in the domain [-1,1]; thread-safe const variant - Eigen::VectorXd get_nodes_n11() const { - Eigen::Index N = m_c.size() - 1; - double NN = static_cast<double>(N); - return (Eigen::VectorXd::LinSpaced(N + 1, 0, NN).array() * EIGEN_PI / N).cos(); - } - /// Get the Chebyshev-Lobatto nodes in the domain [xmin, xmax] - Eigen::VectorXd get_nodes_realworld(); - /// Get the Chebyshev-Lobatto nodes in the domain [xmin, xmax]; thread-safe const variant - Eigen::VectorXd get_nodes_realworld() const { - return ((m_xmax - m_xmin) * get_nodes_n11().array() + (m_xmax + m_xmin)) * 0.5; - } - - /// Values of the function at the Chebyshev-Lobatto nodes - Eigen::VectorXd get_node_function_values() const; - /// Return true if the function values at the Chebyshev-Lobatto nodes are monotonic with the independent variable - bool is_monotonic() const; - - // ****************************************************************** - // *********************** OPERATORS *********************** - // ****************************************************************** - - /// A ChebyshevExpansion plus another ChebyshevExpansion yields a new ChebyheveExpansion - ChebyshevExpansion operator+(const ChebyshevExpansion &ce2) const ; - /** - * @brief An inplace addition of two expansions - * @note The lower degree one is right-padded with zeros to have the same degree as the higher degree one - * @param donor The other expansion in the summation - */ - ChebyshevExpansion& operator+=(const ChebyshevExpansion &donor); - /// Multiplication of an expansion by a constant - ChebyshevExpansion operator*(double value) const; - /// Addition of a constant to an expansion - ChebyshevExpansion operator+(double value) const; - /// Subtraction of a constant from an expansion - ChebyshevExpansion operator-(double value) const; - /// An inplace multiplication of an expansion by a constant - ChebyshevExpansion& operator*=(double value); - /// An inplace addition of a constant to an expansion - ChebyshevExpansion& operator+=(double value); - /// An inplace subtraction of a constant from an expansion - ChebyshevExpansion& operator-=(double value); - /// Unary negation operator - ChebyshevExpansion operator-() const; - /// An inplace subtraction of an expansion by another expansion - ChebyshevExpansion& operator-=(const ChebyshevExpansion &ce2); - /// An inplace subtraction of an expansion by another expansion - ChebyshevExpansion operator-(const ChebyshevExpansion& ce2) const; - /** - * @brief Multiply two Chebyshev expansions together; thanks to Julia code from Bradley Alpert, NIST - * - * Converts padded expansions to nodal functional values, functional values are multiplied together, - * and then inverse transformation is used to return to coefficients of the product - * @param ce2 The other expansion - */ - ChebyshevExpansion operator*(const ChebyshevExpansion &ce2) const; - - /** - * @brief Divide two expansions by each other. Right's reciprocal is taken, multiplied by this expansion - * - * @param ce2 The other expansion - */ - ChebyshevExpansion operator/(const ChebyshevExpansion& ce2) const { - return (*this) * ce2.reciprocal(); - } - /** - * @brief Multiply a Chebyshev expansion by its independent variable \f$x\f$ - */ - ChebyshevExpansion times_x() const; - - /** - * @brief Multiply a Chebyshev expansion by its independent variable \f$x\f$ in-place - * - * This operation is carried out in-place to minimize the amount of memory re-allocation - * which proved during profiling to be a major source of inefficiency - */ - ChebyshevExpansion& times_x_inplace(); - - ChebyshevExpansion reciprocal() const; - - /// Friend function that allows for pre-multiplication by a constant value - friend ChebyshevExpansion operator*(double value, const ChebyshevExpansion &ce){ - return ChebyshevExpansion(std::move(ce.coef()*value),ce.m_xmin, ce.m_xmax); - }; - /// Friend function that allows expansion to be the denominator in division with double - friend ChebyshevExpansion operator/(double value, const ChebyshevExpansion& ce) { - return value * ce.reciprocal(); - }; - /// Friend function that allows pre-subtraction of expansion (value-expansion) - friend ChebyshevExpansion operator-(double value, const ChebyshevExpansion& ce) { - return -ce+value; - }; - /// Friend function that allows pre-addition of expansion (value+expansion) - friend ChebyshevExpansion operator+(double value, const ChebyshevExpansion& ce) { - return ce + value; - }; - - /** - * @brief Apply a function to the expansion - * - * This function first converts the expansion to functional values at the - * Chebyshev-Lobatto nodes, applies the function to the nodal values, and then - * does the inverse transformation to arrive at the coefficients of the expansion - * after applying the transformation - */ - ChebyshevExpansion apply(std::function<Eigen::ArrayXd(const Eigen::ArrayXd &)> &f) const; - - // ****************************************************************** - // ********************** EVALUATORS *********************** - // ****************************************************************** - - /** - * @brief Do a single input/single output evaluation of the Chebyshev expansion with the inputs scaled in [xmin, xmax] - * @param x A value scaled in the domain [xmin,xmax] - */ - double y_recurrence(const double x); - /** - * @brief Do a single input/single output evaluation of the Chebyshev expansion with the inputs scaled in [xmin, xmax] - * @param x A value scaled in the domain [xmin,xmax] - */ - double y_Clenshaw(const double x) const { return y_Clenshaw_xscaled(scale_x(x)); } - /** - * @brief Do a single input/single output evaluation of the Chebyshev expansion with the inputs scaled in [-1,1] - * @param x A value scaled in the domain [-1,1] - */ - double y_Clenshaw_xscaled(const double x) const; - /** - * @brief Do a vectorized evaluation of the Chebyshev expansion with the inputs scaled in [xmin, xmax] - * @param x A vectype of values in the domain [xmin,xmax] - */ - vectype y(const vectype &x) const; - /** - * @brief Do a vectorized evaluation of the Chebyshev expansion with the inputs scaled in [xmin, xmax] - * @param x A value scaled in the domain [xmin,xmax] - */ - double y(const double x) const{ return y_Clenshaw(x); } - /** - * @brief Do a vectorized evaluation of the Chebyshev expansion with the input scaled in the domain [-1,1] - * @param xscaled A vectype of values scaled to the domain [-1,1] (the domain of the Chebyshev basis functions) - * @returns y A vectype of values evaluated from the expansion - * - * By using vectorizable types like Eigen::MatrixXd, without - * any additional work, "magical" vectorization is happening - * under the hood, giving a significant speed improvement. From naive - * testing, the increase was a factor of about 10x. - */ - vectype y_recurrence_xscaled(const vectype &xscaled) const ; - /** - * @brief Do a vectorized evaluation of the Chebyshev expansion with the input scaled in the domain [-1,1] with Clenshaw's method - * @param xscaled A vectype of values scaled to the domain [-1,1] (the domain of the Chebyshev basis functions) - * @returns y A vectype of values evaluated from the expansion - */ - vectype y_Clenshaw_xscaled(const vectype &xscaled) const ; - - /** - * @brief Construct and return the companion matrix of the Chebyshev expansion - * @returns A The companion matrix of the expansion - * - * See Boyd, SIAM review, 2013, http://dx.doi.org/10.1137/110838297, Appendix A.2 - */ - Eigen::MatrixXd companion_matrix(const Eigen::VectorXd &coeffs) const ; - /** - * @brief Return the real roots of the Chebyshev expansion - * @param only_in_domain If true, only real roots that are within the domain - * of the expansion will be returned, otherwise all real roots - * - * The roots are obtained based on the fact that the eigenvalues of the - * companion matrix are the roots of the Chebyshev expansion. Thus - * this function is relatively slow, because an eigenvalue solve is required, - * which takes O(n^3) FLOPs. But it is numerically rather reliable. - * - * As the order of the expansion increases, the eigenvalue solver in Eigen becomes - * progressively less and less able to obtain the roots properly. The eigenvalue - * solver in numpy tends to be more reliable. - */ - std::vector<double> real_roots(bool only_in_domain = true) const ; - /** - * @brief The second-generation rootfinder of ChebyshevExpansions - * @param only_in_domain True: only keep roots that are in the domain of the expansion. False: all real roots - */ - std::vector<double> real_roots2(bool only_in_domain = true) const; - - /** - * @brief Calculate the value (only one) of x in [xmin, xmax] for which the expansion value is equal to given value - * - * Functionally the use is similar to real_roots except that: - * 1) nodal values are cached - * 2) only one solution is possible - * - Warning: the monotonicity of the expansion is assumed, but not checked - * - * @param yval Given value for which value of x is to be obtained - */ - double monotonic_solvex(double yval); - - /** - * @brief Subdivide the original interval into a set of subintervals that are linearly spaced - * @note A vector of ChebyshevExpansions are returned - * @param Nintervals The number of intervals - * @param Ndegree The degree of the Chebyshev expansion in each interval - */ - std::vector<ChebyshevExpansion> subdivide(std::size_t Nintervals, std::size_t Ndegree) const ; - - /** - * @brief For a vector of ChebyshevExpansions, find all roots in each interval - * @param segments The vector of ChebyshevExpansions - * @param only_in_domain True: only keep roots that are in the domain of the expansion. False: all real roots - */ - static std::vector<double> real_roots_intervals(const std::vector<ChebyshevExpansion> &segments, bool only_in_domain = true); - - /** - * @brief Time how long (in seconds) it takes to evaluate the roots - * @param N How many repeats to do (maybe a million? It's pretty fast for small degrees) - */ - double real_roots_time(long N); - - /// A DEPRECATED function for approximating the roots (do not use) - std::vector<double> real_roots_approx(long Npoints); - - // ****************************************************************** - // *********************** BUILDERS *********************** - // ****************************************************************** - - /** - * @brief Given a set of values at the Chebyshev-Lobatto nodes, perhaps obtained from the ChebyshevExpansion::factory function, - * get the expansion, using the discrete cosine transform (DCT) approach - * - * @param N The degree of the expansion - * @param f The set of values at the Chebyshev-Lobatto nodes - * @param xmin The minimum value of x for the expansion - * @param xmax The maximum value of x for the expansion - */ - static ChebyshevExpansion factoryf(const std::size_t N, const Eigen::VectorXd &f, const double xmin, const double xmax) ; - - /** - * @brief Given a set of values at the Chebyshev-Lobatto nodes, build the expansion, using the FFT approach - * - * See this clear example: https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/23972/versions/22/previews/chebfun/examples/approx/html/ChebfunFFT.html - * - * @param N The degree of the expansion - * @param f The set of values at the Chebyshev-Lobatto nodes - * @param xmin The minimum value of x for the expansion - * @param xmax The maximum value of x for the expansion - */ - static ChebyshevExpansion factoryfFFT(const std::size_t N, const Eigen::VectorXd& f, const double xmin, const double xmax); - - /** - * @brief Given a callable function, construct the N-th order Chebyshev expansion in [xmin, xmax] - * @param N The order of the expansion; there will be N+1 coefficients - * @param func A callable object, taking the x value (in [xmin,xmax]) and returning the y value - * @param xmin The minimum x value for the fit - * @param xmax The maximum x value for the fit - * - * See Boyd, SIAM review, 2013, http://dx.doi.org/10.1137/110838297, Appendix A. - */ - template<class double_function> - static ChebyshevExpansion factory(const std::size_t N, double_function func, const double xmin, const double xmax) - { - // Get the precalculated Chebyshev-Lobatto nodes - const Eigen::VectorXd & x_nodes_n11 = get_CLnodes(N); - - // Step 1&2: Grid points functional values (function evaluated at the - // extrema of the Chebyshev polynomial of order N - there are N+1 of them) - Eigen::VectorXd f(N + 1); - for (int k = 0; k <= N; ++k) { - // The extrema in [-1,1] scaled to real-world coordinates - double x_k = ((xmax - xmin)*x_nodes_n11(k) + (xmax + xmin)) / 2.0; - f(k) = func(x_k); - } - return factoryf(N, f, xmin, xmax); - }; - - /// Convert a monomial term in the form \f$x^n\f$ to a Chebyshev expansion - static ChebyshevExpansion from_powxn(const std::size_t n, const double xmin, const double xmax); - - /** - * @brief Convert a polynomial expansion in monomial form to a Chebyshev expansion - * - * The monomial expansion is of the form \f$ y = \displaystyle\sum_{i=0}^N c_ix_i\f$ - * - * This transformation can be carried out analytically. For convenience we repetitively use - * calls to ChebyshevExpansion::from_powxn to build up the expansion. This is probably not - * the most efficient option, but it works. - * - * @param c The vector of coefficients of the monomial expansion in *increasing* degree: - * @param xmin The minimum value of \f$x\f$ for the expansion - * @param xmax The maximum value of \f$x\f$ for the expansion - */ - template<class vector_type> - static ChebyshevExpansion from_polynomial(vector_type c, const double xmin, const double xmax) { - vectype c0(1); c0 << 0; - ChebyshevExpansion s(c0, xmin, xmax); - for (std::size_t i = 0; i < static_cast<std::size_t>(c.size()); ++i) { - s += c(i)*from_powxn(i, xmin, xmax); - } - return s; - } - - static auto dyadic_splitting(const std::size_t N, const std::function<double(double)>& func, const double xmin, const double xmax, - const int M, const double tol, const int max_refine_passes = 8, - const std::function<void(int, const std::deque<ChebyshevExpansion>&)>&callback = {}) - { - - // Convenience function to get the M-element norm - auto get_err = [M](const ChebyshevExpansion& ce) { return ce.coef().tail(M).norm() / ce.coef().head(M).norm(); }; - - // Start off with the full domain from xmin to xmax - std::deque<ChebyshevExpansion> expansions; - expansions.emplace_back(ChebyshevExpansion::factory(N, func, xmin, xmax)); - - // Now enter into refinement passes - for (int refine_pass = 0; refine_pass < max_refine_passes; ++refine_pass) { - bool all_converged = true; - // Start at the right and move left because insertions will make the length increase - for (int iexpansion = static_cast<int>(expansions.size())-1; iexpansion >= 0; --iexpansion) { - auto& expan = expansions[iexpansion]; - auto err = get_err(expan); - if (err > tol) { - // Splitting is required, do a dyadic split - auto xmid = (expan.xmin() + expan.xmax()) / 2; - auto newleft = ChebyshevExpansion::factory(N, func, expan.xmin(), xmid); - auto newright = ChebyshevExpansion::factory(N, func, xmid, expan.xmax()); - std::swap(expan, newleft); - expansions.insert(expansions.begin() + iexpansion+1, newright); - all_converged = false; - } - } - if (all_converged) { break; } - if (callback != nullptr) { - callback(refine_pass, expansions); - } - } - return expansions; - } - }; - -}; /* namespace ChebTools */ -#endif diff --git a/src/external/ChebTools/speed_tests.h b/src/external/ChebTools/speed_tests.h deleted file mode 100644 index cc5944d5..00000000 --- a/src/external/ChebTools/speed_tests.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef SPEED_TESTS_H -#define SPEED_TESTS_H - -#include "ChebTools/ChebTools.h" -#include <map> - -double real_roots_time(ChebTools::ChebyshevExpansion &ce, long N); -double plus_by_inplace(ChebTools::ChebyshevExpansion &ce, const ChebTools::ChebyshevExpansion &ce2, int N); -double mult_by_inplace(ChebTools::ChebyshevExpansion &ce, double val, int N); -void mult_by(ChebTools::ChebyshevExpansion &ce, double val, int N); -std::map<std::string, double> evaluation_speed_test(ChebTools::ChebyshevExpansion &cee, const Eigen::VectorXd &xpts, long N) ; -Eigen::MatrixXd eigs_speed_test(std::vector<std::size_t> &Nvec, std::size_t Nrepeats); - -#endif \ No newline at end of file diff --git a/src/external/PackedCSparse/FloatArray.h b/src/external/PackedCSparse/FloatArray.h deleted file mode 100644 index 28d1c5da..00000000 --- a/src/external/PackedCSparse/FloatArray.h +++ /dev/null @@ -1,307 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -#pragma once -#include <immintrin.h> -#include <random> -#include <type_traits> -namespace PackedCSparse { - template <typename T, size_t k> - struct BaseImpl - { - T x[k]; - - BaseImpl() {}; - - BaseImpl(const T& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] = rhs; - } - - BaseImpl operator+(const BaseImpl& rhs) const - { - BaseImpl lhs; - for (size_t i = 0; i < k; i++) - lhs.x[i] = x[i] + rhs.x[i]; - return lhs; - } - - BaseImpl operator-(const BaseImpl& rhs) const - { - BaseImpl lhs; - for (size_t i = 0; i < k; i++) - lhs.x[i] = x[i] - rhs.x[i]; - return lhs; - } - - BaseImpl operator*(const BaseImpl& rhs) const - { - BaseImpl lhs; - for (size_t i = 0; i < k; i++) - lhs.x[i] = x[i] * rhs.x[i]; - return lhs; - } - - BaseImpl operator/(const BaseImpl& rhs) const - { - BaseImpl lhs; - for (size_t i = 0; i < k; i++) - lhs.x[i] = x[i] / rhs.x[i]; - return lhs; - } - - BaseImpl& operator+=(const BaseImpl& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] += rhs.x[i]; - return *this; - } - - BaseImpl& operator-=(const BaseImpl& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] -= rhs.x[i]; - return *this; - } - - BaseImpl& operator*=(const BaseImpl& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] *= rhs.x[i]; - return *this; - } - - BaseImpl& operator/=(const BaseImpl& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] /= rhs.x[i]; - return *this; - } - - explicit operator bool() const - { - bool ret = false; - for (size_t i = 0; i < k; i++) - ret = ret || bool(x[i]); - return ret; - } - - static T get(const BaseImpl& a, size_t index) - { - return a.x[index]; - } - - static void set(BaseImpl& a, size_t index, const T& value) - { - a.x[index] = value; - } - - static BaseImpl abs(const BaseImpl& a) - { - BaseImpl out; - for (size_t i = 0; i < k; i++) - out.x[i] = std::abs(a.x[i]); - return out; - } - - static BaseImpl log(const BaseImpl& a) - { - BaseImpl out; - for (size_t i = 0; i < k; i++) - out.x[i] = std::log(a.x[i]); - return out; - } - - static void fmadd(BaseImpl& a, const BaseImpl& b, const BaseImpl& c) - { - for (size_t i = 0; i < k; i++) - a.x[i] += b.x[i] * c.x[i]; - } - - static void fnmadd(BaseImpl& a, const BaseImpl& b, const BaseImpl& c) - { - for (size_t i = 0; i < k; i++) - a.x[i] -= b.x[i] * c.x[i]; - } - - static void fmadd(BaseImpl& a, const BaseImpl& b, const T& c) - { - for (size_t i = 0; i < k; i++) - a.x[i] += b.x[i] * c; - } - - static void fnmadd(BaseImpl& a, const BaseImpl& b, const T& c) - { - for (size_t i = 0; i < k; i++) - a.x[i] -= b.x[i] * c; - } - - static BaseImpl clipped_sqrt(const BaseImpl& a, const T nonpos_output) - { - BaseImpl out; - for (size_t i = 0; i < k; i++) - { - T r = a.x[i]; - if (r > 0) - out.x[i] = sqrt(r); - else - out.x[i] = nonpos_output; - } - return out; - } - - static BaseImpl sign(std::mt19937_64& gen) - { - BaseImpl out; - unsigned long long seed = gen(); - for (size_t i = 0; i < k; i++) - { - out.x[i] = T((2 * ((seed >> i) & 1)) - 1.0); - if ((i & 63) == 63) seed = gen(); - } - return out; - } - - }; - - template <typename T> - struct BaseScalarImpl - { - static T get(const T& x, size_t index) - { - return x; - } - - static void set(T& x, size_t index, T& value) - { - x = value; - } - - static T abs(const T &x) - { - return ::abs(x); - } - - static T log(const T &x) - { - return ::log(x); - } - - static void fmadd(T& a, const T& b, const T& c) - { - a += b * c; - } - - static void fnmadd(T& a, const T& b, const T& c) - { - a -= b * c; - } - - static T clipped_sqrt(const T& x, const T& nonpos_output) - { - if (x > 0.0) - return sqrt(x); - else - return nonpos_output; - } - - static T sign(std::mt19937_64& gen) - { - unsigned long long seed = gen(); - return T((2 * (seed & 1)) - 1.0); - } - }; - - template <typename T, size_t k> - struct FloatTypeSelector - { - using type = typename std::conditional<k == 1, T, BaseImpl<T, k>>::type; - using funcImpl = typename std::conditional<k == 1, BaseScalarImpl<T>, BaseImpl<T, k>>::type; - }; - - #ifdef __AVX2__ - #include "FloatArrayAVX2.h" - #else - template <size_t k> - struct FloatTypeSelector<double, k> - { - using type = typename std::conditional< k == 1, double, BaseImpl<double, k>>::type; - using funcImpl = typename std::conditional< k == 1, BaseScalarImpl<double>, BaseImpl<double, k>>::type; - }; - - template <size_t k, size_t l> - struct FloatTypeSelector<BaseImpl<double, k>, l> - { - using type = BaseImpl<double, k*l>; - using funcImpl = BaseImpl<double, k*l>; - }; - #endif - - template <typename T, size_t k, size_t l> - struct FloatTypeSelector<BaseImpl<T, k>, l> - { - using type = BaseImpl<T, k* l>; - using funcImpl = BaseImpl<T, k* l>; - }; - - template<typename T, size_t k = 1> - using FloatArray = typename FloatTypeSelector<T, k>::type; - - template<typename T, size_t k = 1> - using FloatArrayFunc = typename FloatTypeSelector<T, k>::funcImpl; - - template<typename T> - auto get(const T& a, size_t index) -> decltype(FloatArrayFunc<T>::get(a, index)) - { - return FloatArrayFunc<T>::get(a, index); - } - - template<typename T1, typename T2> - void set(T1& a, size_t index, T2 value) - { - FloatArrayFunc<T1>::set(a, index, value); - } - - template<typename T1, typename T2, typename T3> - void fmadd(T1& a, const T2& b, const T3& c) - { - FloatArrayFunc<T1>::fmadd(a, b, c); - } - - template<typename T1, typename T2, typename T3> - void fnmadd(T1& a, const T2& b, const T3& c) - { - FloatArrayFunc<T1>::fnmadd(a, b, c); - } - - template<typename T1, typename T2> - T1 clipped_sqrt(const T1& a, const T2 b) - { - return FloatArrayFunc<T1>::clipped_sqrt(a, b); - } - - template<typename T> - T abs(const T& a) - { - return FloatArrayFunc<T>::abs(a); - } - - template<typename T> - T log(const T& a) - { - return FloatArrayFunc<T>::log(a); - } - - template<typename T> - T sign(std::mt19937_64& gen) - { - return FloatArrayFunc<T>::sign(gen); - } -} diff --git a/src/external/PackedCSparse/FloatArrayAVX2.h b/src/external/PackedCSparse/FloatArrayAVX2.h deleted file mode 100644 index 3ae7592a..00000000 --- a/src/external/PackedCSparse/FloatArrayAVX2.h +++ /dev/null @@ -1,222 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -template<size_t k> - struct m256dArray -{ - __m256d x[k]; - - m256dArray() {}; - - m256dArray(const double rhs) - { - for (size_t i = 0; i < k; i++) - x[i] = _mm256_set1_pd(rhs); - } - - template<size_t k2> - m256dArray(const m256dArray<k2>& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] = rhs.x[i % k2]; - } - - m256dArray operator+(const m256dArray& rhs) const - { - m256dArray out; - for (size_t i = 0; i < k; i++) - out.x[i] = _mm256_add_pd(x[i], rhs.x[i]); - return out; - } - - m256dArray operator-(const m256dArray& rhs) const - { - m256dArray out; - for (size_t i = 0; i < k; i++) - out.x[i] = _mm256_sub_pd(x[i], rhs.x[i]); - return out; - } - - m256dArray operator*(const m256dArray& rhs) const - { - m256dArray out; - for (size_t i = 0; i < k; i++) - out.x[i] = _mm256_mul_pd(x[i], rhs.x[i]); - return out; - } - - m256dArray operator/(const m256dArray& rhs) const - { - m256dArray out; - for (size_t i = 0; i < k; i++) - out.x[i] = _mm256_div_pd(x[i], rhs.x[i]); - return out; - } - - m256dArray& operator+=(const m256dArray& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] = _mm256_add_pd(x[i], rhs.x[i]); - return *this; - } - - m256dArray& operator-=(const m256dArray& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] = _mm256_sub_pd(x[i], rhs.x[i]); - return *this; - } - - m256dArray& operator*=(const m256dArray& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] = _mm256_mul_pd(x[i], rhs.x[i]); - return *this; - } - - m256dArray& operator/=(const m256dArray& rhs) - { - for (size_t i = 0; i < k; i++) - x[i] = _mm256_div_pd(x[i], rhs.x[i]); - return *this; - } - - explicit operator bool() const - { - bool ret = false; - __m256d z = _mm256_set1_pd(0.0); - for (size_t i = 0; i < k; i++) - { - __m256d c = _mm256_cmp_pd(x[i], z, _CMP_EQ_OQ); - ret = ret || (_mm256_movemask_pd(c) != 0xf); - } - return ret; - } - - static double get(const m256dArray& x, size_t index) - { - double y[4]; - _mm256_store_pd(y, x.x[index / 4]); - return y[index & 3]; - } - - static void set(m256dArray& x, size_t index, double value) - { - __m256d v = _mm256_broadcast_sd(&value); - switch (index & 3) - { - case 0: x.x[index / 4] = _mm256_blend_pd(x.x[index / 4], v, 1); break; - case 1: x.x[index / 4] = _mm256_blend_pd(x.x[index / 4], v, 2); break; - case 2: x.x[index / 4] = _mm256_blend_pd(x.x[index / 4], v, 4); break; - default: x.x[index / 4] = _mm256_blend_pd(x.x[index / 4], v, 8); break; - } - } - - static m256dArray abs(const m256dArray& x) - { - const __m256d mask = _mm256_castsi256_pd(_mm256_set1_epi64x(0x7FFFFFFFFFFFFFFF)); - - m256dArray out; - for (size_t i = 0; i < k; i++) - out.x[i] = _mm256_and_pd(x.x[i], mask); - return out; - } - - static m256dArray log(const m256dArray& x) - { - // gcc does not support _mm256_log_pd - // Do it sequentially instead - - //m256dArray out; - //for (size_t i = 0; i < k; i++) - // out.x[i] = _mm256_log_pd(x.x[i]); - - m256dArray out; - for (size_t i = 0; i < 4*k; i++) - set(out, i, std::log(get(x,i))); - return out; - } - - static void fmadd(m256dArray& a, const m256dArray& b, const double& c) - { - auto cx = _mm256_set1_pd(c); - for (size_t i = 0; i < k; i++) - a.x[i] = _mm256_fmadd_pd(b.x[i], cx, a.x[i]); - } - - static void fnmadd(m256dArray& a, const m256dArray& b, const double& c) - { - auto cx = _mm256_set1_pd(c); - for (size_t i = 0; i < k; i++) - a.x[i] = _mm256_fnmadd_pd(b.x[i], cx, a.x[i]); - } - - static void fmadd(m256dArray& a, const m256dArray& b, const m256dArray& c) - { - for (size_t i = 0; i < k; i++) - a.x[i] = _mm256_fmadd_pd(b.x[i], c.x[i], a.x[i]); - } - - static void fnmadd(m256dArray& a, const m256dArray& b, const m256dArray& c) - { - for (size_t i = 0; i < k; i++) - a.x[i] = _mm256_fnmadd_pd(b.x[i], c.x[i], a.x[i]); - } - - static m256dArray clipped_sqrt(const m256dArray& x, const double nonpos_output) - { - m256dArray out; - - const __m256d large = { nonpos_output, nonpos_output, nonpos_output, nonpos_output }; - const __m256d zero = _mm256_setzero_pd(); - for (size_t i = 0; i < k; i++) - { - __m256d xi = x.x[i]; - __m256d mask = _mm256_cmp_pd(xi, zero, _CMP_LE_OS); // mask = (rhs.x[i]<= 0) ? -1 : 0 - out.x[i] = _mm256_blendv_pd(_mm256_sqrt_pd(xi), large, mask); - } - return out; - } - - static m256dArray sign(std::mt19937_64& gen) - { - m256dArray out; - const __m256i bits = _mm256_set_epi64x(1, 2, 4, 8); - const __m256d zero = _mm256_setzero_pd(); - const __m256d pos = _mm256_set_pd(1.0, 1.0, 1.0, 1.0); - const __m256d neg = _mm256_set_pd(-1.0, -1.0, -1.0, -1.0); - - unsigned long long seed = gen(); - for (size_t i = 0; i < k; i++) - { - __m256i s = _mm256_set1_epi64x((seed >> (4 * i)) & 15); - __m256i xi = _mm256_and_si256(s, bits); - __m256d x = _mm256_castsi256_pd(xi); - __m256d mask = _mm256_cmp_pd(x, zero, _CMP_EQ_OQ); // mask = (rhs.x[i] == 0) ? -1 : 0 - out.x[i] = _mm256_blendv_pd(pos, neg, mask); - if ((i & 63) == 63) seed = gen(); - } - return out; - } -}; - -template <size_t k> - struct FloatTypeSelector<double, k> -{ - static_assert(k == 1 || k % 4 == 0, "Array<double,k> assumes k = 1 or a multiple of 4"); - using type = typename std::conditional< k == 1, double, m256dArray<k / 4>>::type; - using funcImpl = typename std::conditional< k == 1, BaseScalarImpl<double>, m256dArray<k / 4>>::type; -}; - -template <size_t k, size_t l> - struct FloatTypeSelector<m256dArray<k>, l> -{ - using type = m256dArray<k* l>; - using funcImpl = m256dArray<k* l>; -}; diff --git a/src/external/PackedCSparse/PackedChol.h b/src/external/PackedCSparse/PackedChol.h deleted file mode 100644 index 97d10220..00000000 --- a/src/external/PackedCSparse/PackedChol.h +++ /dev/null @@ -1,308 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -#pragma once -#include "Eigen/Eigen" -#include "SparseMatrix.h" -#include "chol.h" -#include "leverage.h" -#include "leverageJL.h" -#include "multiply.h" -#include "qd/dd_real.h" -#include <random> -#include <vector> -using namespace PackedCSparse; - -template <typename Tin, typename Tout> -void get_slice(Tout *out, Tin *in, size_t n, size_t idx) { - for (size_t j = 0; j < n; j++) - out[j] = to_double(get(in[j], idx)); -} - -template <typename Tin, typename Tout> -void set_slice(Tout *out, Tin *in, size_t n, size_t idx) { - for (size_t j = 0; j < n; j++) - set(out[j], idx, to_double(in[j])); -} - -template <int k, typename Ti> struct PackedChol { - using Tx = double; - using Tx2 = FloatArray<double, k>; - using Te = dd_real; - - // parameters - SparseMatrix<Tx, Ti> A; - SparseMatrix<Tx, Ti> At; - UniqueAlignedPtr<Tx2> w; - Tx accuracyThreshold = 1e-6; - std::vector<size_t> - exactIdx; // k size array. Indices we perform high precision calculation - std::vector<size_t> - numExact; // number of times we perform high precision decompose (length - // k+1, the last one records how many times we do decompose) - bool decomposed = false; - - // preprocess info for different CSparse operations (PackedDouble) - MultiplyOutput<Tx2, Ti> H; // cache for H = A W A' - CholOutput<Tx2, Ti> L; // cache for L = chol(H) - LeverageOutput<Tx2, Ti> diagP; // cache for L = chol(H) - LeverageJLOutput<Tx2, Ti> diagPJL; // cache for L = chol(H) - - // preprocess info for different CSparse operations (dd_real) - MultiplyOutput<Te, Ti> H_exact; // cache for H = A W A' - CholOutput<Te, Ti> L_exact; // cache for L = chol(H) - LeverageOutput<Te, Ti> diagP_exact; // cache for L = chol(H) - LeverageJLOutput<Te, Ti> diagPJL_exact; // cache for L = chol(H) - SparseMatrix<Te, Ti> Le[k]; // store output of L_exact - - PackedChol(const SparseMatrix<Tx, Ti> &A_) { - A = std::move(A_.clone()); - At = transpose(A); - w.reset(pcs_aligned_new<Tx2>(A.n)); - numExact.resize(k + 1); - } - - void setSeed(unsigned long long seed) { - diagPJL.gen.seed(seed); - diagPJL_exact.gen.seed(seed); - } - - bool allExact() { return exactIdx.size() == k; } - - bool hasExact() { return exactIdx.size() > 0; } - - template <typename Tv2_> Tx2 decompose(const Tv2_ *w_in) { - - Tx2 acc = Tx2(0.0); - - // record w - Ti n = A.n; - - for (Ti j = 0; j < n; j++) { - w[j] = w_in[j]; - } - // compute chol - ++numExact[k]; - if (accuracyThreshold > 0.0 || - !decomposed) // the first time we call, always run the double chol. - { - multiply(H, A, w.get(), At); - chol(L, H); - decomposed = true; - - exactIdx.clear(); - acc = estimateAccuracy(); - for (size_t i = 0; i < k; i++) { - if (get(acc, i) >= - accuracyThreshold) // >= is important for the case accuracyThreshold - // = 0.0, we need to compute everything exactly - exactIdx.push_back(i); - } - } else if (!allExact()) { - exactIdx.clear(); - for (size_t i = 0; i < k; i++) - exactIdx.push_back(i); - } - - if (hasExact()) { - Te *w_exact = new Te[n]; - - for (size_t i : exactIdx) { - ++numExact[i]; - get_slice(w_exact, w.get(), n, i); - multiply(H_exact, A, w_exact, At); - chol(L_exact, H_exact); - - // copy result to Le[i] - if (!Le[i].initialized()) - Le[i] = std::move(L_exact.template clone<Te, Ti>()); - else { - Ti nz = L_exact.nnz(); - for (Ti s = 0; s < nz; ++s) - Le[i].x[s] = (L_exact.x[s]); - } - } - - delete[] w_exact; - } - return acc; - } - - Tx2 logdet() { - pcs_assert(decomposed, "logdet: Need to call decompose first."); - - Ti m = A.m; - Tx2 ret = Tx2(0); - - if (!allExact()) { - Ti *Lp = L.p.get(); - Tx2 *Lx = L.x.get(); - for (Ti j = 0; j < m; j++) - ret += log(Lx[Lp[j]]); - } - - if (hasExact()) { - for (size_t i : exactIdx) { - Te ret_e = 0.0; - Ti *Lp = Le[i].p.get(); - Te *Lx = Le[i].x.get(); - - for (Ti j = 0; j < m; j++) - ret_e += log(Lx[Lp[j]]); - - set(ret, i, to_double(ret_e)); - } - } - - return ret * Tx2(2.0); - } - - void diagL(Tx2 *out) { - pcs_assert(decomposed, "diagL: Need to call decompose first."); - - Ti m = A.m; - - if (!allExact()) { - Ti *Li = L.i.get(), *Lp = L.p.get(); - Tx2 *Lx = L.x.get(); - for (Ti j = 0; j < m; j++) - out[j] = Lx[Lp[j]]; - } - - if (hasExact()) { - for (size_t i : exactIdx) { - Ti *Lp = Le[i].p.get(); - Te *Lx = Le[i].x.get(); - - for (Ti j = 0; j < m; j++) - set(out[j], i, to_double(Lx[Lp[j]])); - } - } - } - - SparseMatrix<double, Ti> getL(Ti i) { - pcs_assert(decomposed, "getL: Need to call decompose first."); - - Ti m = L.m, n = L.n, nz = L.nnz(); - SparseMatrix<double, Ti> out(m, n, nz); - - Ti *outp = out.p.get(), *Lp = L.p.get(); - Ti *outi = out.i.get(), *Li = L.i.get(); - - for (Ti s = 0; s <= n; s++) - outp[s] = Lp[s]; - - for (Ti s = 0; s < nz; s++) - outi[s] = Li[s]; - - bool isExact = false; - for (size_t i_ : exactIdx) { - if (i_ == i) - isExact = true; - } - - double *outx = out.x.get(); - if (isExact) { - Te *Lx = Le[i].x.get(); - for (Ti s = 0; s < nz; s++) - outx[s] = to_double(Lx[s]); - } else { - Tx2 *Lx = L.x.get(); - for (Ti s = 0; s < nz; s++) - outx[s] = get(Lx[s], i); - } - - return std::move(out); - } - - void solve(Tx2 *b, Tx2 *out) { - pcs_assert(decomposed, "solve: Need to call decompose first."); - - if (!allExact()) { - lsolve(L, b, out); - ltsolve(L, out, out); - } - - if (hasExact()) { - Ti m = A.m; - Te *b_exact = new Te[m]; - Te *out_exact = new Te[m]; - - for (size_t i : exactIdx) { - get_slice(b_exact, b, m, i); - lsolve(Le[i], b_exact, out_exact); - ltsolve(Le[i], out_exact, out_exact); - set_slice(out, out_exact, m, i); - } - - delete[] b_exact; - delete[] out_exact; - } - }; - - void leverageScoreComplement(Tx2 *out) { - pcs_assert(decomposed, - "leverageScoreComplement: Need to call decompose first."); - - Ti n = A.n, m = A.m; - - if (!allExact()) { - Tx2 T1 = Tx2(1.0), T2 = Tx2(2.0); - leverage(diagP, L, A, At); - - Tx2 *tau = diagP.x.get(); - for (Ti j = 0; j < n; j++) - out[j] = T1 - tau[j] * w[j]; - } - - if (hasExact()) { - Te T1 = Te(1.0), T2 = Te(2.0); - for (size_t i : exactIdx) { - leverage(diagP_exact, Le[i], A, At); - - Te *tau = diagP_exact.x.get(); - for (Ti j = 0; j < n; j++) - set(out[j], i, to_double(T1 - tau[j] * get(w[j], i))); - } - } - } - - void leverageScoreComplementJL(Tx2 *out, size_t JL_k) { - pcs_assert(decomposed, - "leverageScoreComplementJL: Need to call decompose first."); - - Ti m = A.m, n = A.n; - - if (!allExact()) { - Tx2 T1 = Tx2(1.0), T2 = Tx2(2.0); - leverageJL(diagPJL, L, A, At, JL_k); - - Tx2 *tau = diagPJL.x.get(); - for (Ti j = 0; j < n; j++) - out[j] = T1 - tau[j] * w[j]; - } - - if (hasExact()) { - Te T1 = Te(1.0), T2 = Te(2.0); - for (size_t i : exactIdx) { - leverageJL(diagPJL_exact, Le[i], A, At, JL_k); - - Te *tau = diagPJL_exact.x.get(); - for (Ti j = 0; j < n; j++) - set(out[j], i, to_double(T1 - tau[j] * get(w[j], i))); - } - } - } - - Tx2 estimateAccuracy() { - pcs_assert(decomposed, "estimateAccuracy: Need to call decompose first."); - - return cholAccuracy(diagPJL, L, A, At, w.get()); - } -}; diff --git a/src/external/PackedCSparse/SparseMatrix.h b/src/external/PackedCSparse/SparseMatrix.h deleted file mode 100644 index 5dca4286..00000000 --- a/src/external/PackedCSparse/SparseMatrix.h +++ /dev/null @@ -1,230 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis -#pragma once -#include <memory> -#include <stdexcept> -#include "FloatArray.h" - -namespace PackedCSparse { - static void pcs_assert(bool value, const char* message) - { - if (value == false) - throw std::logic_error(message); - } - - template <typename T> - T* pcs_aligned_new(size_t size) - { - int alignment = 64; // size of memory cache line - int offset = alignment - 1 + sizeof(void*); - void* p1 = (void*)new char[size * sizeof(T) + offset]; - void** p2 = (void**)(((size_t)(p1)+offset) & ~(alignment - 1)); - p2[-1] = p1; - return (T*)p2; - } - - template <typename T> - struct AlignedDeleter - { - void operator()(T* p) const - { - delete[](char*)(((void**)p)[-1]); - } - }; - - template<typename T> - using UniqueAlignedPtr = std::unique_ptr<T[], AlignedDeleter<T>>; - - template<typename T> - using UniquePtr = std::unique_ptr<T[]>; - - // Tx = Type for entries, Ti = Type for indices. - // if Tx == bool, the matrix stores only sparsity information - template <typename Tx, typename Ti> - struct SparseMatrix - { - Ti m = 0; /* number of rows */ - Ti n = 0; /* number of columns */ - UniquePtr<Ti> p; /* column pointers (size n+1) */ - UniquePtr<Ti> i; /* row indices, size nnz */ - UniqueAlignedPtr<Tx> x; /* numerical values, size nnz */ - - SparseMatrix() = default; - - SparseMatrix(Ti m_, Ti n_, Ti nzmax_) - { - initialize(m_, n_, nzmax_); - } - - bool initialized() const - { - return p && i; - } - - void initialize(Ti m_, Ti n_, Ti nzmax) - { - if (nzmax < 1) nzmax = 1; - m = m_; n = n_; - p.reset(new Ti[n + 1]); - i.reset(new Ti[nzmax]); - if (!std::is_same<Tx, bool>::value) - x.reset(pcs_aligned_new<Tx>(nzmax)); - } - - Ti nnz() const - { - return p[n]; - } - - template <typename Tx2 = Tx, typename Ti2 = Ti> - SparseMatrix<Tx2, Ti2> clone() const - { - SparseMatrix<Tx2, Ti2> C(m, n, nnz()); - Ti* Ap = p.get(), * Ai = i.get(); Tx* Ax = x.get(); - Ti2* Cp = C.p.get(), * Ci = C.i.get(); Tx2* Cx = C.x.get(); - - for (Ti s = 0; s <= n; s++) - Cp[s] = Ti2(Ap[s]); - - Ti nz = nnz(); - for (Ti s = 0; s < nz; s++) - Ci[s] = Ti2(Ai[s]); - - if (Cx) - { - for (Ti s = 0; s < nz; s++) - Cx[s] = Ax? Tx2(Ax[s]): Tx2(1.0); - } - - return C; - } - }; - - template <typename Tx, typename Ti> - struct DenseVector - { - Ti n = 0; /* number of columns */ - UniqueAlignedPtr<Tx> x; /* numerical values, size nnz */ - - DenseVector() = default; - - DenseVector(Ti n_) - { - initialize(n_); - } - - bool initialized() const - { - return bool(x); - } - - void initialize(Ti n_) - { - n = n_; - x.reset(pcs_aligned_new<Tx>(n_)); - } - }; - - - // basic functions - template <typename Tx, typename Ti> - SparseMatrix<Tx, Ti> speye(Ti n, Tx* d = nullptr) - { - SparseMatrix<Tx, Ti> D(n, n, n); - - for (Ti k = 0; k < n; k++) - { - D.i[k] = k; - D.p[k] = k; - } - D.p[n] = n; - - Tx Tx1 = Tx(1.0); - for (Ti k = 0; k < n; k++) - D.x[k] = (d ? d[k] : Tx1); - return D; - } - - // Solve L out = x - // Input: L in Tx^{n by n}, x in Tx2^{n} - // Output: out in Tx2^{n}. - // If out is provided, we will output to out. Else, output to x. - template <typename Tx, typename Ti, typename Tx2> - void lsolve(const SparseMatrix<Tx, Ti>& L, Tx2* x, Tx2* out = nullptr) - { - pcs_assert(L.initialized(), "lsolve: bad inputs."); - pcs_assert(L.n == L.m, "lsolve: dimensions mismatch."); - - Ti n = L.n, * Lp = L.p.get(), * Li = L.i.get(); Tx* Lx = L.x.get(); - - if (!out) out = x; - if (x != out) std::copy(x, x + n, out); - - for (Ti j = 0; j < n; j++) - { - Tx2 out_j = out[j] / Lx[Lp[j]]; - out[j] = out_j; - - Ti p_start = Lp[j] + 1, p_end = Lp[j + 1]; - for (Ti p = p_start; p < p_end; p++) - { //out[Li[p]] -= Lx[p] * out[j]; - fnmadd(out[Li[p]], out_j, Lx[p]); - } - } - } - - // Solve L' out = x - // Input: L in Tx^{n by n}, x in Tx2^{n} - // Output: out in Tx2^{n}. - // If out is provided, we will output to out. Else, output to x. - template <typename Tx, typename Ti, typename Tx2> - void ltsolve(const SparseMatrix<Tx, Ti>& L, Tx2* x, Tx2* out = nullptr) - { - pcs_assert(L.initialized(), "ltsolve: bad inputs."); - pcs_assert(L.n == L.m, "ltsolve: dimensions mismatch."); - - Ti n = L.n, * Lp = L.p.get(), * Li = L.i.get(); Tx* Lx = L.x.get(); - - if (!out) out = x; - if (x != out) std::copy(x, x + n, out); - - for (Ti j = n - 1; j != -1; j--) - { - Tx2 out_j = out[j]; - - Ti p_start = Lp[j] + 1, p_end = Lp[j + 1]; - for (Ti p = p_start; p < p_end; p++) - { //out[j] -= Lx[p] * out[Li[p]]; - fnmadd(out_j, out[Li[p]], Lx[p]); - } - - out[j] = out_j / Tx2(Lx[Lp[j]]); - } - } - - // Update y <-- y + A x - // Input: A in Tx^{n by n}, x, y in Tx2^{n} - template <typename Tx, typename Ti, typename Tx2> - void gaxpy(const SparseMatrix<Tx, Ti>& A, const Tx2* x, Tx2* y) - { - pcs_assert(A.initialized(), "gaxpy: bad inputs."); - Ti m = A.m, n = A.n, * Ap = A.p.get(), * Ai = A.i.get(); Tx* Ax = A.x.get(); - - for (Ti j = 0; j < n; j++) - { - Tx2 x_j = x[j]; - - Ti p_start = Ap[j], p_end = Ap[j + 1]; - for (Ti p = p_start; p < p_end; p++) - { //y[Ai[p]] += Ax[p] * x[j]; - fmadd(y[Ai[p]], x_j, Ax[p]); - } - } - } -}; diff --git a/src/external/PackedCSparse/add.h b/src/external/PackedCSparse/add.h deleted file mode 100644 index 16195722..00000000 --- a/src/external/PackedCSparse/add.h +++ /dev/null @@ -1,102 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -#pragma once -#include <vector> -#include "SparseMatrix.h" - -// Problem: -// Compute M = A + B - -// Algorithm: -// M = 0 -// M(A != 0) += A(A != 0) -// M(B != 0) += B(A != 0) - -namespace PackedCSparse { - template <typename Tx, typename Ti> - struct AddOutput : SparseMatrix<Tx, Ti> - { - UniquePtr<Ti> forwardA; - UniquePtr<Ti> forwardB; - - template<typename Tx2> - void initialize(const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& B) - { - pcs_assert(A.initialized() && B.initialized(), "add: bad inputs."); - pcs_assert(A.n == B.n && A.m == B.m, "add: dimensions mismatch."); - - Ti m = A.m, n = A.n; - Ti Anz = A.nnz(); Ti* Ap = A.p.get(), * Ai = A.i.get(); - Ti Bnz = B.nnz(); Ti* Bp = B.p.get(), * Bi = B.i.get(); - this->m = A.m; this->n = A.n; - - std::vector<Ti> Ci; - Ti* Cp = new Ti[n + 1]; - forwardA.reset(new Ti[Anz]); - forwardB.reset(new Ti[Bnz]); - - Cp[0] = 0; - for (Ti i = 0; i < n; i++) - { - Ti s1 = Ap[i], s2 = Bp[i], end1 = Ap[i + 1], end2 = Bp[i + 1]; - while ((s1 < end1) || (s2 < end2)) - { - Ti q = Ti(Ci.size()); - Ti i1 = (s1 < end1) ? Ai[s1] : m; - Ti i2 = (s2 < end2) ? Bi[s2] : m; - Ti min_i = std::min(i1, i2); - Ci.push_back(min_i); - - if (i1 == min_i) - forwardA[s1++] = q; - - if (i2 == min_i) - forwardB[s2++] = q; - } - Cp[i + 1] = Ti(Ci.size()); - } - - this->p.reset(Cp); - this->i.reset(new Ti[Ci.size()]); - this->x.reset(pcs_aligned_new<Tx>(Ci.size())); - std::copy(Ci.begin(), Ci.end(), this->i.get()); - } - }; - - template <typename Tx, typename Ti, typename Tx2 = Tx> - void add(AddOutput<Tx2, Ti>& o, const SparseMatrix<Tx, Ti>& A, const SparseMatrix<Tx, Ti>& B) - { - if (!o.initialized()) - o.initialize(A, B); - - Ti m = o.m, n = o.n; - Ti Anz = A.nnz(); Ti* Ap = A.p.get(), * Ai = A.i.get(); Tx* Ax = A.x.get(); - Ti Bnz = B.nnz(); Ti* Bp = B.p.get(), * Bi = B.i.get(); Tx* Bx = B.x.get(); - Ti Cnz = o.nnz(); Ti* Cp = o.p.get(), * Ci = o.i.get(); Tx2* Cx = o.x.get(); - Ti* forwardA = o.forwardA.get(), *forwardB = o.forwardB.get(); - - for (Ti s = 0; s < Cnz; s++) - Cx[s] = 0; - - for (Ti s = 0; s < Anz; s++) - Cx[forwardA[s]] = Ax[s]; - - for (Ti s = 0; s < Bnz; s++) - Cx[forwardB[s]] += Bx[s]; - } - - template <typename Tx, typename Ti, typename Tx2 = Tx> - AddOutput<Tx2, Ti> add(const SparseMatrix<Tx, Ti>& A, const SparseMatrix<Tx, Ti>& B) - { - AddOutput<Tx2, Ti> o; - add(o, A, B); - return o; - } -} diff --git a/src/external/PackedCSparse/chol.h b/src/external/PackedCSparse/chol.h deleted file mode 100644 index d6001ae2..00000000 --- a/src/external/PackedCSparse/chol.h +++ /dev/null @@ -1,247 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -#pragma once -#include <vector> -#include <queue> -#include "SparseMatrix.h" -#include "transpose.h" - -// Problem: -// Compute chol(A) - -// Algorithm: -// We need to study this later as this is the bottleneck. -// Document it as a lyx. -// chol_up_looking: -// Compute L row by row -// This is faster when it is compute bound. -// -// chol_left_looking: -// Compute L col by col -// This is faster when it is memory bound. - - -namespace PackedCSparse { - template <typename Tx, typename Ti> - struct CholOutput : SparseMatrix<Tx, Ti> - { - TransposeOutput<bool, Ti> Lt; // sparsity pattern of the Lt - UniquePtr<Ti> diag; // the index for diagonal element. Ax[diag[k]] is A_kk - UniquePtr<Ti> c; // c[i] = index the last nonzero on column i in the current L - UniqueAlignedPtr<Tx> w; // the row of L we are computing - - // The cost of this is roughly 3 times larger than chol - // One can optimize it by using other data structure - void initialize(const SparseMatrix<Tx, Ti>& A) - { - pcs_assert(A.initialized(), "chol: bad inputs."); - pcs_assert(A.n == A.m, "chol: dimensions mismatch."); - - Ti n = A.n, * Ap = A.p.get(), * Ai = A.i.get(); - - // initialize - this->diag.reset(new Ti[n]); - this->c.reset(new Ti[n]); - this->w.reset(pcs_aligned_new<Tx>(n)); - - // compute the sparsity pattern of L and diag - using queue = std::priority_queue<Ti, std::vector<Ti>, std::greater<Ti>>; - queue q; // sol'n of the current row of L - Ti* mark = new Ti[n]; // used to prevent same indices push to q twice - std::vector<Ti>* cols = new std::vector<Ti>[n]; // stores the non-zeros of each col of L - Ti nz = 0, Anz = Ap[n]; - - for (Ti i = 0; i < n; i++) - mark[i] = -1; - - // for each row of A - for (Ti i = 0; i < n; i++) - { // push i-th row of A, called a_12, into mark - Ti s; - for (s = Ap[i]; s < Ap[i + 1]; s++) - { - Ti j = Ai[s]; - if (j >= i) break; - - q.push(j); - mark[j] = i; - } - if (s >= Anz) // this case happens only if the diagonal is 0. No cholesky in this case. - this->diag[i] = 0; - else - this->diag[i] = s; - - // Solve L_11 l_12 = a_12 - while (!q.empty()) - { - Ti j = q.top(); - - for (Ti k : cols[j]) - { - if (mark[k] != i) - { - q.push(k); - mark[k] = i; - } - } - q.pop(); - - // update j col - cols[j].push_back(i); - ++nz; - } - - // diag - cols[i].push_back(i); - ++nz; - } - delete[] mark; - - // write it as the compress form - SparseMatrix<Tx, Ti>::initialize(n, n, nz); - - Ti s_start = 0; Ti s = 0; - for (Ti i = 0; i < n; i++) - { - this->p[i] = s_start; - for (Ti k : cols[i]) - this->i[s++] = k; - s_start += Ti(cols[i].size()); - } - this->p[n] = s_start; - delete[] cols; - - this->Lt = transpose<Tx, Ti, bool>(*this); - - // initialize w to 0 - Tx Tv0 = Tx(0); - for (Ti k = 0; k < n; k++) - w[k] = Tv0; - } - }; - - template <typename Tx, typename Ti> - void chol(CholOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& A) - { - if (!o.initialized()) - o.initialize(A); - - //chol_up_looking(o, A); - chol_left_looking(o, A); - } - - template <typename Tx, typename Ti> - void chol_up_looking(CholOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& A) - { - Ti *Ap = A.p.get(), * Ai = A.i.get(); Tx* Ax = A.x.get(); - Ti nzmax = o.nzmax; Ti n = A.n; - Ti *Lp = o.p.get(); Ti* Li = o.i.get(); - Ti *Ltp = o.Lt.p.get(); Ti* Lti = o.Lt.i.get(); - - Tx T0 = Tx(0); - Tx* Lx = o.x.get(); Tx* w = o.w.get(); Ti* c = o.c.get(); - Ti* diag = o.diag.get(); - - Ti* Lti_ptr = Lti; - for (Ti k = 0; k < n; ++k) - { - c[k] = Lp[k]; - - Ti s_end = diag[k]; - for (Ti s = Ap[k]; s < s_end; ++s) - w[Ai[s]] = Ax[s]; - - // Solve L_11 l_12 = a_12 - Tx d = Ax[s_end]; Ti i; - for (; (i = *(Lti_ptr++)) < k;) - { - Ti dLi = Lp[i], ci = c[i]++; - Tx Lki = w[i] / Lx[dLi]; - w[i] = T0; // maintain x = 0 for the (k+1) iteration - - for (Ti q = dLi + 1; q < ci; ++q) - fnmadd(w[Li[q]], Lx[q], Lki); - - d -= Lki * Lki; - Lx[ci] = Lki; - } - - // l_22 = sqrt(a22 - <l12,l12>) - Lx[c[k]++] = clipped_sqrt(d); - } - } - - template <typename Tx, typename Ti> - void chol_left_looking(CholOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& A) - { - Ti* Ap = A.p.get(), * Ai = A.i.get(); Tx* Ax = A.x.get(); - Ti nzmax = o.nnz(); Ti n = A.n; - Ti* Lp = o.p.get(); Ti* Li = o.i.get(); - Ti* Ltp = o.Lt.p.get(); Ti* Lti = o.Lt.i.get(); - - Tx T0 = Tx(0), T1 = Tx(1); - Tx* Lx = o.x.get(); - Tx* w = o.w.get(); Ti* c = o.c.get(); - Ti* diag = o.diag.get(); - - for (Ti j = 0; j < n; ++j) - { - c[j] = Lp[j]; - - // x = A_{j:n, j} - { - Ti is_start = diag[j], is_end = Ap[j + 1]; - for (Ti is = is_start; is < is_end; ++is) - w[Ai[is]] = Ax[is]; - } - - // for each p in L_{j, 1:j-1} - Ti ps_start = Ltp[j], ps_end = Ltp[j + 1] - 1; - for (Ti ps = ps_start; ps < ps_end; ++ps) - { - Ti p = Lti[ps]; - Ti cp = c[p]++; - Tx Ljp = Lx[cp]; - - // for each i in L_{j:n,p} - Ti is_start = cp, is_end = Lp[p + 1]; - for (Ti is = is_start; is < is_end; ++is) - { - Ti i = Li[is]; - fnmadd(w[i], Lx[is], Ljp); - } - } - - Tx Ljj = clipped_sqrt(w[j], 1e128); - Lx[c[j]++] = Ljj; - Tx inv_Ljj = T1 / Ljj; - w[j] = T0; - - // for each i in L_{:,j} - { - Ti is_start = Lp[j] + 1, is_end = Lp[j + 1]; - for (Ti is = is_start; is < is_end; ++is) - { - Ti i = Li[is]; - Lx[is] = w[i] * inv_Ljj; - w[i] = T0; - } - } - } - } - - template <typename Tx, typename Ti> - CholOutput<Tx, Ti> chol(const SparseMatrix<Tx, Ti>& A) - { - CholOutput<Tx, Ti> o; - chol(o, A); - return o; - } -} diff --git a/src/external/PackedCSparse/leverage.h b/src/external/PackedCSparse/leverage.h deleted file mode 100644 index 69549308..00000000 --- a/src/external/PackedCSparse/leverage.h +++ /dev/null @@ -1,65 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -#pragma once -#include "SparseMatrix.h" -#include "projinv.h" -#include "outerprod.h" - -// Problem: -// Compute M = diag(A' inv(LL') A) - -namespace PackedCSparse { - template<typename Tx, typename Ti> - struct LeverageOutput : DenseVector<Tx, Ti> - { - ProjinvOutput<Tx, Ti> Hinv; // Hinv = inv(H)|_L - OuterprodOutput<Tx, Ti> tau; // tau = diag(A' Hinv A) - - template<typename Tx2> - void initialize(const SparseMatrix<Tx, Ti>& L, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& At) - { - pcs_assert(L.initialized() && A.initialized() && At.initialized(), "leverage: bad inputs."); - pcs_assert(L.m == L.n && L.n == A.m && L.n == At.n && A.n == At.m, "leverage: dimensions mismatch."); - DenseVector<Tx, Ti>::initialize(A.n); - Hinv.initialize(L); - tau.initialize(A, Hinv, At); - } - }; - - template<typename Tx, typename Ti, typename Tx2> - void leverage(LeverageOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& L, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& At) - { - if (!o.initialized()) - o.initialize(L, A, At); - - Tx T1 = Tx(1.0), T2 = Tx(2.0); - projinv(o.Hinv, L); - - Ti m = A.m, n = A.n; - Ti* Sp = o.Hinv.p.get(); Tx* Sv = o.Hinv.x.get(); - for (Ti k = 0; k < m; ++k) - Sv[Sp[k]] /= T2; - - outerprod(o.tau, A, o.Hinv, At); - - Tx* x = o.x.get(), * tau = o.tau.x.get(); - for (Ti j = 0; j < n; j++) - x[j] = T2 * tau[j]; - } - - - template<typename Tx, typename Ti, typename Tx2> - LeverageOutput<Tx, Ti> leverage(const SparseMatrix<Tx, Ti>& L, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& At) - { - LeverageOutput<Tx, Ti> o; - leverage(o, L, A, At); - return o; - } -} diff --git a/src/external/PackedCSparse/leverageJL.h b/src/external/PackedCSparse/leverageJL.h deleted file mode 100644 index a5001bcd..00000000 --- a/src/external/PackedCSparse/leverageJL.h +++ /dev/null @@ -1,148 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -#pragma once -#include <random> -#include "SparseMatrix.h" - -// Problem: -// Approximate M = diag(A' inv(LL') A) -namespace PackedCSparse { - const size_t JLPackedSize = 4; - - template<typename Tx, typename Ti> - struct LeverageJLOutput : DenseVector<Tx, Ti> - { - UniqueAlignedPtr<Tx> d; // random direction d - UniqueAlignedPtr<Tx> L_d; // random direction d - UniqueAlignedPtr<Tx> AtL_d; // A' L^{-1} d - Ti m = 0; - std::mt19937_64 gen; - - template<typename Tx2> - void initialize(const SparseMatrix<Tx, Ti>& L, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& At) - { - pcs_assert(L.initialized() && A.initialized() && At.initialized(), "leverageJL: bad inputs."); - pcs_assert(L.m == L.n && L.n == A.m && L.n == At.n && A.n == At.m, "leverageJL: dimensions mismatch."); - this->n = A.n; this->m = A.m; - this->x.reset(pcs_aligned_new<Tx>(this->n)); - this->d.reset(pcs_aligned_new<Tx>(this->m * 2 * JLPackedSize)); - this->L_d.reset(pcs_aligned_new<Tx>(this->m * 2 * JLPackedSize)); - this->AtL_d.reset(pcs_aligned_new<Tx>(this->n * 2 * JLPackedSize)); - } - }; - - // compute sum_{j=1}^{k} (A' L^{-T} u_j) .* (A' L^{-T} u_j) - template<size_t k, typename Tx, typename Ti, typename Tx2> - void projectionJL(LeverageJLOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& L, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& At) - { - Ti m = A.m, n = A.n; - Tx T0 = Tx(0.0), T1 = Tx(1.0); - Tx* d = o.d.get(), * L_d = o.L_d.get(), * AtL_d = o.AtL_d.get(), * x = o.x.get(); - - for (Ti i = 0; i < m * k; i++) - d[i] = sign<Tx>(o.gen); - - for (Ti i = 0; i < n * k; i++) - AtL_d[i] = T0; - - ltsolve(L, (BaseImpl<Tx, k>*)d, (BaseImpl<Tx, k>*)L_d); - gaxpy(At, (BaseImpl<Tx, k>*)L_d, (BaseImpl<Tx, k>*)AtL_d); - - for (Ti i = 0; i < n; i++) - { - Tx ret_i = T0; - for (Ti j = 0; j < k; j++) - ret_i += AtL_d[i * k + j] * AtL_d[i * k + j]; - - x[i] += ret_i; - } - } - - template<typename Tx, typename Ti, typename Tx2> - void leverageJL(LeverageJLOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& L, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& At, size_t k) - { - if (!o.initialized()) - o.initialize(L, A, At); - - Ti n = A.n; Tx* x = o.x.get(); - for (Ti i = 0; i < n; i++) - x[i] = Tx(0.0); - - constexpr size_t k_step = JLPackedSize; - for(size_t i = 1; i <= k / k_step; i++) - projectionJL<k_step>(o, L, A, At); - - for (size_t i = 1; i <= k % k_step; i++) - projectionJL<1>(o, L, A, At); - - Tx ratio = Tx(1 / double(k)); - for (Ti i = 0; i < n; i++) - x[i] *= ratio; - } - - template<typename Tx, typename Ti, typename Tx2> - LeverageJLOutput<Tx, Ti> leverageJL(const SparseMatrix<Tx, Ti>& L, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& At, size_t k) - { - LeverageJLOutput<Tx, Ti> o; - leverageJL(o, L, A, At, k); - return o; - } - - - // compute (A' L^{-T} u_j) .* (A' L^{-T} v_j) for j = 1, 2, ... k - template<typename Tx, typename Ti, typename Tx2> - Tx cholAccuracy(LeverageJLOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& L, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& At, const Tx* w) - { - if (!o.initialized()) - o.initialize(L, A, At); - - constexpr Ti k = JLPackedSize; - constexpr Ti k_ = 2 * k; - - - Ti m = A.m, n = A.n; - Tx T0 = Tx(0.0), T1 = Tx(1.0); - Tx* d = o.d.get(), * L_d = o.L_d.get(), * AtL_d = o.AtL_d.get(), * x = o.x.get(); - - std::uniform_real_distribution<double> distribution(-sqrt(3.0),sqrt(3.0)); - for (Ti i = 0; i < m * k_; i++) - d[i] = Tx(distribution(o.gen)); // roughly uniform distribution with variance 1 - - for (Ti i = 0; i < n * k_; i++) - AtL_d[i] = T0; - - ltsolve(L, (BaseImpl<Tx, k_>*)d, (BaseImpl<Tx, k_>*)L_d); - gaxpy(At, (BaseImpl<Tx, k_>*)L_d, (BaseImpl<Tx, k_>*)AtL_d); - - Tx result[k]; - for (Ti j = 0; j < k; j++) - result[j] = Tx(0.0); - - for (Ti i = 0; i < m; i++) - { - Tx* d = o.d.get() + i * (2 * k); - for (Ti j = 0; j < k; j++) - result[j] -= d[j] * d[j + k]; - } - - for (Ti i = 0; i < n; i++) - { - Tx w_i = w[i]; - for (Ti j = 0; j < k; j++) - result[j] += AtL_d[i * k_ + j] * AtL_d[i * k_ + j + k] * w_i; - } - - Tx est = Tx(0.0); - for (Ti j = 0; j < k; j++) - est += result[j] * result[j]; - - return clipped_sqrt(est/Tx(double(k)), 0.0); - } -} diff --git a/src/external/PackedCSparse/multiply.h b/src/external/PackedCSparse/multiply.h deleted file mode 100644 index cfd53375..00000000 --- a/src/external/PackedCSparse/multiply.h +++ /dev/null @@ -1,142 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -#pragma once -#include <vector> -#include <algorithm> -#include "SparseMatrix.h" - -// Problem: -// Compute M = A diag(w) B - -// Algorithm: -// Compute M col by col - -namespace PackedCSparse { - template <typename Tx, typename Ti> - struct MultiplyOutput : SparseMatrix<Tx, Ti> - { - UniqueAlignedPtr<Tx> c; - - template<typename Tx2> - void initialize(const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx2, Ti>& B) - { - pcs_assert(A.initialized() && B.initialized(), "multiply: bad inputs."); - pcs_assert(A.n == B.m, "multiply: dimensions mismatch."); - - Ti m = A.m, n = B.n; - Ti* Ap = A.p.get(), * Ai = A.i.get(); - Ti* Bp = B.p.get(), * Bi = B.i.get(); - - this->c.reset(pcs_aligned_new<Tx>(m)); - - Ti* last_j = new Ti[m]; - for (Ti i = 0; i < m; i++) - { - last_j[i] = -1; - this->c[i] = Tx(0.0); - } - - Ti* Cp = new Ti[size_t(n)+1]; - std::vector<Ti> Ci; - - Cp[0] = 0; - for (Ti j1 = 0; j1 < n; j1++) - { - for (Ti p1 = Bp[j1]; p1 < Bp[j1 + 1]; p1++) - { - Ti j2 = Bi[p1]; - for (Ti p2 = Ap[j2]; p2 < Ap[j2 + 1]; p2++) - { - Ti i = Ai[p2]; - if (last_j[i] != j1) - { - last_j[i] = j1; - Ci.push_back(i); - } - } - } - Cp[j1 + 1] = Ti(Ci.size()); - } - delete[] last_j; - - for (Ti j = 0; j < n; j++) - std::sort(Ci.begin() + Cp[j], Ci.begin() + Cp[j + 1]); - - this->m = m; this->n = n; - this->x.reset(pcs_aligned_new<Tx>(Ci.size())); - this->p.reset(Cp); - this->i.reset(new Ti[Ci.size()]); - std::copy(Ci.begin(), Ci.end(), this->i.get()); - } - }; - - template <typename Tx, typename Ti, typename Tx2, bool has_weight> - void multiply_general(MultiplyOutput<Tx2, Ti>& o, const SparseMatrix<Tx, Ti>& A, const Tx2* w, const SparseMatrix<Tx, Ti>& B) - { - if (!o.initialized()) - o.initialize(A, B); - - Ti m = o.m, n = o.n; - Ti* Ap = A.p.get(), * Ai = A.i.get(); Tx* Ax = A.x.get(); - Ti* Bp = B.p.get(), * Bi = B.i.get(); Tx* Bx = B.x.get(); - Ti* Cp = o.p.get(), * Ci = o.i.get(); Tx2* Cx = o.x.get(); - Tx2* c = o.c.get(); // initialized to 0 - - const Tx2 T0 = Tx2(0); - for (Ti j1 = 0; j1 < n; j1++) - { - for (Ti p1 = Bp[j1]; p1 < Bp[j1 + 1]; p1++) - { - Ti j2 = Bi[p1]; - Tx2 beta = has_weight? (Tx2(Bx[p1]) * w[j2]) : Tx2(Bx[p1]); - - for (Ti p2 = Ap[j2]; p2 < Ap[j2 + 1]; p2++) - { - //x[Ai[p2]] += beta * Ax[p2]; - fmadd(c[Ai[p2]], beta, Ax[p2]); - } - } - - for (Ti p1 = Cp[j1]; p1 < Cp[j1 + 1]; p1++) - { - Cx[p1] = c[Ci[p1]]; - c[Ci[p1]] = T0; // ensure c is 0 after the call - } - } - } - - template <typename Tx, typename Ti> - void multiply(MultiplyOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& A, const SparseMatrix<Tx, Ti>& B) - { - multiply_general<Tx, Ti, Tx, false>(o, A, nullptr, B); - } - - template <typename Tx, typename Ti, typename Tx2> - void multiply(MultiplyOutput<Tx2, Ti>& o, const SparseMatrix<Tx, Ti>& A, const Tx2* w, const SparseMatrix<Tx, Ti>& B) - { - multiply_general<Tx, Ti, Tx2, true>(o, A, w, B); - } - - template <typename Tx, typename Ti, typename Tx2> - MultiplyOutput<Tx2, Ti> multiply(const SparseMatrix<Tx, Ti>& A, const Tx2* w, const SparseMatrix<Tx, Ti>& B) - { - MultiplyOutput<Tx2, Ti> o; - multiply(o, A, w, B); - return o; - } - - template <typename Tx, typename Ti> - MultiplyOutput<Tx, Ti> multiply(const SparseMatrix<Tx, Ti>& A, const SparseMatrix<Tx, Ti>& B) - { - MultiplyOutput<Tx, Ti> o; - multiply(o, A, B); - return o; - } -} diff --git a/src/external/PackedCSparse/outerprod.h b/src/external/PackedCSparse/outerprod.h deleted file mode 100644 index 6f0e98e3..00000000 --- a/src/external/PackedCSparse/outerprod.h +++ /dev/null @@ -1,86 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis -#pragma once -#include "SparseMatrix.h" - -// Problem: -// Compute x = diag(At S Bt) - -// Algorithm: -// Note that x = diag(B St A) = grad_H Tr(St A H B) -// We run autodiff on the function Tr(St A H B). -// Hence, the algorithm is essentially same as multiply(A, B) with the same runtime. - -namespace PackedCSparse { - template <typename Tx, typename Ti> - struct OuterprodOutput : DenseVector<Tx, Ti> - { - UniqueAlignedPtr<Tx> s_col; - UniquePtr<Ti> s_mark; - - template<typename Tx2> - void initialize(const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx, Ti>& S, const SparseMatrix<Tx2, Ti>& B) - { - pcs_assert(A.initialized() && B.initialized() && S.initialized(), "outerprod: bad inputs."); - pcs_assert(A.m == S.m && S.n == B.n, "outerprod: dimensions mismatch."); - - DenseVector<Tx, Ti>::initialize(A.n); - s_col.reset(pcs_aligned_new<Tx>(S.m)); - s_mark.reset(new Ti[S.m]); - } - }; - - template<typename Tx, typename Ti, typename Tx2> - void outerprod(OuterprodOutput<Tx, Ti>& o, const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx, Ti>& S, const SparseMatrix<Tx2, Ti>& B) - { - if (!o.initialized()) - o.initialize(A, S, B); - - Ti Sn = S.n, Sm = S.m, An = A.n; - Ti* Ap = A.p.get(), * Ai = A.i.get(); Tx2* Ax = A.x.get(); - Ti* Bp = B.p.get(), * Bi = B.i.get(); Tx2* Bx = B.x.get(); - Ti* Sp = S.p.get(), * Si = S.i.get(); Tx* Sx = S.x.get(); - Tx* s_col = o.s_col.get(); - Ti* s_mark = o.s_mark.get(); - Tx* x = o.x.get(); - - std::fill(s_mark, s_mark + Sm, Ti(-1)); - std::fill(x, x + An, Tx(0.0)); - - for (Ti j = 0; j < Sn; j++) - { - for (Ti p = Sp[j]; p < Sp[j + 1]; p++) - { - s_col[Si[p]] = Sx[p]; - s_mark[Si[p]] = j; - } - - for (Ti p = Bp[j]; p < Bp[j + 1]; p++) - { - Ti i = Bi[p]; Tx b = Bx[p]; - for (Ti q = Ap[i]; q < Ap[i + 1]; q++) - { - Tx a = Ax[q]; Ti a_i = Ai[q]; - if (s_mark[a_i] == j) - { //x[i] += s_col[a_i] * a * b; - fmadd(x[i], s_col[a_i], a * b); - } - } - } - } - } - - template <typename Tx, typename Ti, typename Tx2> - OuterprodOutput<Tx2, Ti> outerprod(const SparseMatrix<Tx2, Ti>& A, const SparseMatrix<Tx, Ti>& S, const SparseMatrix<Tx2, Ti>& B) - { - OuterprodOutput<Tx2, Ti> o; - outerprod(o, A, S, B); - return o; - } -} diff --git a/src/external/PackedCSparse/projinv.h b/src/external/PackedCSparse/projinv.h deleted file mode 100644 index a319a47e..00000000 --- a/src/external/PackedCSparse/projinv.h +++ /dev/null @@ -1,90 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis - -#pragma once -#include "SparseMatrix.h" - -// Problem: -// Compute inv(L L') restricted on L - -// Algorithm: -// We need to study this later as this is the bottleneck. -// Document it as a lyx. - -namespace PackedCSparse { - template <typename Tx, typename Ti> - struct ProjinvOutput : SparseMatrix<Tx, Ti> - { - TransposeOutput<bool, Ti> Lt; // sparsity pattern of the Lt - UniqueAlignedPtr<Tx> w; // the row of L we are computing - UniquePtr<Ti> c; // c[i] = index the last nonzero on column i in the current L - - void initialize(const SparseMatrix<Tx, Ti>& L) - { - pcs_assert(L.initialized(), "chol: bad inputs."); - pcs_assert(L.n == L.m, "chol: dimensions mismatch."); - - // Copy the sparsity of L - SparseMatrix<Tx, Ti>::operator=(std::move(L.clone())); - - // allocate workspaces - Ti n = L.n; - w.reset(pcs_aligned_new<Tx>(n)); - c.reset(new Ti[n]); - Lt = transpose<Tx, Ti, bool>(L); - } - }; - - template <typename Tx, typename Ti> - void projinv(ProjinvOutput<Tx, Ti>& o, const SparseMatrix<Tx, Ti>& L) - { - if (!o.initialized()) - o.initialize(L); - - Tx* Sx = o.x.get(); Ti n = o.n; - Ti* Li = L.i.get(), * Lp = L.p.get(); Tx* Lv = L.x.get(); - Ti* Lti = o.Lt.i.get(), * Ltp = o.Lt.p.get(); - Tx* w = o.w.get(); - Ti* c = o.c.get(); - Tx T0 = Tx(0), T1 = Tx(1); - - for (Ti k = 0; k < n; k++) - c[k] = Lp[k + 1] - 1; - - for (Ti k = n - 1; k != -1; k--) - { - for (Ti p = Lp[k] + 1; p < Lp[k + 1]; p++) - w[Li[p]] = Sx[p]; - - Tx sum = T1 / Lv[Lp[k]]; - for (Ti p = Ltp[k + 1] - 1; p != Ltp[k] - 1; p--) - { - Ti i = Lti[p], Lpi = Lp[i]; - - for (Ti q = Lp[i + 1] - 1; q != Lpi; q--) - fnmadd(sum, Lv[q], w[Li[q]]); - //sum -= Lv[q] * w[Li[q]]; - - sum = sum / Lv[Lpi]; - w[i] = sum; - Sx[c[i]] = sum; - c[i]--; - sum = T0; - } - } - } - - template <typename Tx, typename Ti> - ProjinvOutput<Tx, Ti> projinv(const SparseMatrix<Tx, Ti>& L) - { - ProjinvOutput<Tx, Ti> o; - projinv(o, L); - return o; - } -} diff --git a/src/external/PackedCSparse/qd/COPYING b/src/external/PackedCSparse/qd/COPYING deleted file mode 100644 index a20ad70e..00000000 --- a/src/external/PackedCSparse/qd/COPYING +++ /dev/null @@ -1,16 +0,0 @@ -This work was supported by the Director, Office of Science, Division -of Mathematical, Information, and Computational Sciences of the -U.S. Department of Energy under contract numbers DE-AC03-76SF00098 and -DE-AC02-05CH11231. - -Copyright (c) 2003-2009, The Regents of the University of California, -through Lawrence Berkeley National Laboratory (subject to receipt of -any required approvals from U.S. Dept. of Energy) All rights reserved. - -By downloading or using this software you are agreeing to the modified -BSD license that is in file "BSD-LBNL-License.doc" in the main ARPREC -directory. If you wish to use the software for commercial purposes -please contact the Technology Transfer Department at TTD@lbl.gov or -call 510-286-6457." - - diff --git a/src/external/PackedCSparse/qd/Makefile b/src/external/PackedCSparse/qd/Makefile deleted file mode 100644 index 791e92b9..00000000 --- a/src/external/PackedCSparse/qd/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -QD_CPPFLAGS=$(CPPFLAGS) -I$(R_INCLUDE_DIR) -march=native - -QD_SOURCES= bits.cc c_dd.cc c_qd.cc dd_const.cc dd_real.cc fpu.cc \ - qd_const.cc qd_real.cc util.cc - -QD_OBJECTS=$(QD_SOURCES:.cc=.o) - -libqd.a: $(QD_OBJECTS) - $(AR) rc libqd.a $(QD_OBJECTS) - -.cc.o: - $(CC) $(CFLAGS) $(CPICFLAGS) $(QD_CPPFLAGS) -c $< -o $@ - -clean: - rm -rf $(QD_OBJECTS) libqd.a diff --git a/src/external/PackedCSparse/qd/NEWS b/src/external/PackedCSparse/qd/NEWS deleted file mode 100644 index f32a7575..00000000 --- a/src/external/PackedCSparse/qd/NEWS +++ /dev/null @@ -1,181 +0,0 @@ -Changes for 2.3.22 - Made changes suggested by Vasiliy Sotnikov - -Changes for 2.3.21 - Changed renorm in include/qd/qd_inline.h - -Changes for 2.3.20 - added #include <string.h> to quadt_test.cpp - changed references to 2.3.20 from 2.3.18 - -Changes for 2.3.19 - - Updated qd_real.cpp and dd_real.cpp to fix a buffer overflow problem. - -Changes for 2.3.18 - - Updated qd_real.cpp and dd_real.cpp to fix a problem in output. - -Changes for 2.3.17 - - updated qd_real.cpp, to fix a problem with improper treatment of - negative arguments in nroot. - -Changes for 2.3.16 - - Updated dd_real.cpp, to fix a problem with inaccurate values of - tanh for small arguments. - -Changes for 2.3.15 - - Updated qd_real.cpp, to fix a problem with static definitions. - -Changes for 2.3.14 - - Updated autoconfig (replaced config.sub and config.guess) - -Changes for 2.3.7 - - Fixed bug in to_digits where digits larger than 10 - where output occasionally. - -Changes for 2.3.6 - - Added fmod (C++) and mod (Fortran) functions. - -Changes for 2.3.5 - - Fixed bug in division of qd_real by dd_real. - - Fixed bug in ddoutc (Fortran ddmod.f). - - Now compiles with g++ 4.3. - - Distribute tests/coeff.dat. - -Changes for 2.3.4 - - Fixed bug in Makefile for cygwin / mingw systems. - -Changes for 2.3.3 - - Fixed bug in atan2. - -Changes for 2.3.2 - - Fixed bug in sin / cos / sincos where too much accuracy was - lost for (moderately) large angles. - - Use fused-multiply add intrinsics on IA-64 platforms if - compiled by Intel compiler. - - Fixed bug in c_dd_write and c_qd_write. - - Fixed bug were qdext.mod was not being installed. - -Changes for 2.3.1 - - Fixed bug in sincos and cos_taylor. This affected the result - of trigonometric functions in some cases. - -Changes for 2.3.0 - This is a fairly significant change, breaking API compatibility. - - Moved C++ main entry in libqdmod.a to libqd_f_main.a. - This allows to link Fortran code using QD with custom - C++ main function. Pure Fortran code will need to be linked - with qd_f_main library in addition to qdmod and qd library. - - Constructors accepting pointers made explicit. - - Fortran routines labeled as elemental or pure, where appropriate. - - Write() is now to_string(), and now takes a single fmtflag. - - dd_real addition and multiplication made commutative. - - dd_real now represented as array of two doubles, instead of - two discrete scalars. - - New Fortran generic routines to read / write, operations with - complex and integers. - - Improved exp, sin, and cos functions. - - Removed unused constants and obscure constants only used internally - from public interface. - -Changes for 2.2.6 - - Fixed bug in mixed precision multiplication: qd_real * dd_real. - -Changes for 2.2.5 - - Bug fix in qd_real addition when --enable-ieee-add is specified. - - Debugging routines dump and dump_bits updated; - dump_components removed (just use dump). - - Fortran support for Fortran strings. Use character arrays instead. - - Return NaN under error conditions. - - Added _inf constant; exp now returns Inf when argument is too large. - - Output formatting fixes for Inf and NaNs. - - Added more real-complex mixed arithmetic routines in Fortran - interface. - -Changes for 2.2.4 - - Added random_number interface for Fortran modules. - - Use slightly more conservative values for eps. - - Avoid unnecessary overflow near overflow threshold. - - Added radix, digits, min/maxexponent, range, and precision - intrinsics to Fortran interface. - - Added safe_max (C++) and safe_huge (Fortran). - -Changes for 2.2.3 - - Fix sign function bug in Fortran modules. - -Changes for 2.2.2 - - Do not bother setting uninitialized dd_real and qd_reals to zero. - - Use clock_gettime if available for timing. - - Fortran I/O should be more consistent with C++ version. - - fpu.h is now included with dd_real.h. - -Changes for 2.2.1 - - Minor fixes when printing in scientific format. - - Change search order of C++ compilers in Apple systems to avoid - case insensitive filesystems. - -Changes for 2.2.0 - - Added F95 interface for complex types. - - Renamed dd.h and qd.h to dd_real.h and qd_real.h, respectively. - This will break older C++ code using 2.1.x library, but it was - conflicting with QuickDraw libraries on Macs. (Hence the version - bump to 2.2). - - Removed overloaded typecast operators for int and double. These - permitted *automatic* conversion of dd_real/qd_real to double or - int, which is somewhat dangerous. Instead to_int and to_double - routines are added. - -Changes for 2.1.214 - - Updated pslq_test. - - Implmented numeric_limits<>. - - Better polyroot. - - Added isnan, isfinite, isinf functions. - - Fix / improve input output functions. - - Drop Microsoft Visual C++ 6.0 support. - - More efficient dd_real::sin. - -Changes for 2.1.213 - - Support for x86_64 platforms. - - Drop libtool support for now. - -Changes for 2.1.212 - - Support for pathCC compiler. - - Added accurate and sloppy versions of add / sub / mul / div avaialble. - - Added autodetection of fma functions. - -Changes for 2.1 (2003-12-30) - - added automake scripts. - - use libtool to compile / link and build libraries. - - supports standard installation targets (make install). - - support for Intel C++ compilers (icc / ecc). - - Fortran programs are now linked by C++ compiler. - - support for building shared library. - - minor bug fixes. - -Changes for 2.0 (2003-12-08) - - all header files are in "include/qd" directory. - - added autoconf scripts. - - added config.h and qd_config.h to store configuration information. - - renamed x86_* routines to fpu_* routines. - - added separate Fortran interface (f_* routines). - - options for sloppy multiply and sloppy divison separated. - - fixed C interface to be actually in C syntax. - - updated / added README, AUTHORS, NEWS, and LICENSE files. - - minor bug fixes. - -Changes for 1.2 (2003-12-04) - - added "dist-clean" target in Makefile - - initialize dd and qd variables to zero - - increases tolerance for qd / dd tests - - changed .cc extension to .cpp - - updated README, COPYING, and NEWS files - - added ChangeLog file - - fixed bug in '-all' flag in qd_test - - minor bug fixes - -Changes for 1.1 (2002-10-22) - - added "Changes" file (this file) - - fixed <strings.h> to <string.h> - - fixed constant (3/4) * pi - - fixed exp(x) to return zero if x is a large negative number - - removed "docs" target in Makefile - diff --git a/src/external/PackedCSparse/qd/README b/src/external/PackedCSparse/qd/README deleted file mode 100644 index 8a085d72..00000000 --- a/src/external/PackedCSparse/qd/README +++ /dev/null @@ -1,437 +0,0 @@ -Quad Double computation package -Copyright (C) 2003-2019 -================================================ - -Revision date: 26 February 2019 - -Authors: -Yozo Hida U.C. Berkeley yozo@cs.berkeley.edu -Xiaoye S. Li Lawrence Berkeley Natl Lab xiaoye@nersc.gov -David H. Bailey Lawrence Berkeley Natl Lab dhbailey@lbl.gov - -C++ usage guide: -Alex Kaiser Lawrence Berkeley Natl Lab adkaiser@lbl.gov - -This work was supported by the Director, Office of Science, Division of Mathematical, -Information, and Computational Sciences of the U.S. Department of Energy under contract -number DE-AC02-05CH11231. - -This work was supported by the Director, Office of Science, Division of Mathematical, -Information, and Computational Sciences of the U.S. Department of Energy under contract -numbers DE-AC03-76SF00098 and DE-AC02-05CH11231. - -*** IMPORTANT NOTES: - -See the file COPYING for modified BSD license information. -See the file INSTALL for installation instructions. -See the file NEWS for recent revisions. -See the file docs/qd.pdf for additional information. - -Outline: - -I. Introduction -II. Installation of package, and linking and executing user files -III. C++ Usage -IV. Fortran Usage -V. Note on x86-Based Processors (MOST systems in use today) - - -I. Introduction - -This package provides numeric types of twice the precision of IEEE double (106 mantissa -bits, or approximately 32 decimal digits) and four times the precision of IEEE double (212 -mantissa bits, or approximately 64 decimal digits). Due to features such as operator and -function overloading, these facilities can be utilized with only minor modifications to -conventional C++ and Fortran-90 programs. - -In addition to the basic arithmetic operations (add, subtract, multiply, divide, square root), -common transcendental functions such as the exponential, logarithm, trigonometric and -hyperbolic functions are also included. A detailed description of the algorithms used is -available in the docs subdirectory (see docs/qd.pdf). An abridged version of this paper, -which was presented at the ARITH-15 conference, is also available at: - -Yozo Hida, Xiaoye S. Li and David H. Bailey, "Algorithms for quad-double precision - floating point arithmetic," 15th IEEE Symposium on Computer Arithmetic, IEEE Computer - Society, 2001, pg. 155-162, available at - https://www.davidhbailey.com/dhbpapers/arith15.pdf. - - -II. Installation of package, and linking and executing user files - -A. Directories - -There are six directories and several files in the main directory of this distribution, -described below - -src This contains the source code of the quad-double and double-double - library. This source code does not include inline functions, - which are found in the header files in the include directory. - -include This directory contains the header files. - -fortran This directory contains Fortran-90 files. - -tests This directory contains some simple (not comprehensive) tests. - -docs This directory contains a technical paper describing the algorithms. - -config This directory contains various scripts used by the configure - script and the Makefile. - -Please note that all commands refer to a Unix-type environment such as Mac OSX or Ubuntu -Linux using the bash shell. - -B. Installing and building - -To build the library, first run the included configure script by typing - - ./configure - -This script automatically generates makefiles for building the library and selects compilers -and necessary flags and libraries to include. If the user wishes to specify compilers or flags -they may use the following options. - - CXX C++ compiler to use - CXXFLAGS C++ compiler flags to use - CC C compiler to use (for C demo program) - CFLAGS C compiler flags to use (for C demo program) - FC Fortran 90 compiler - FCFLAGS Fortran 90 compiler flags to use - FCLIBS Fortran 90 libraries needed to link with C++ code. - -For example, if one is using GNU compilers, configure with: - - ./configure CXX=g++ FC=gfortran - -The Fortran and C++ compilers must produce compatible binaries. On some systems -additional flags must be included to ensure that portions of the -library are not built with 32 and 64 bit object files. For example, on -64-Bit Mac OSX 10.6 (Snow Leopard) and 10.7 (Lion) the correct -configure line using GNU compilers is: - - ./configure CXX=g++ FC=gfortran FCFLAGS=-m64 - -To build the library, simply type - - make - -and the automatically generated makefiles will build the library including archive files. - -To allow for easy linking to the library, the user may also wish to -install the archive files to a standard place. To do this type: - - make install - -This will also build the library if it has not already been built. Many systems, including Mac -and Ubuntu Linux systems, require administrator privileges to install the library at such -standard places. On such systems, one may type: - - sudo make install - -instead if one has sufficient access. - -The directory "tests" contains programs for high precision quadrature and integer-relation -detection. To build such programs, type: - - make demo - -in the "tests" directory. - -C. Linking and executing user programs - -C++ source files: - -The simplest way to link to the library is to install it to a standard place as described above, and use the -l option. For example - - g++ compileExample.cpp -o compileExample -l qd - -One can also use this method to build with make. A file called "compileExample.cpp" and the -associated makefile "makeCompileExample" illustrate the process. - -A third alternative is to use a link script. If one types "make demo" in the test -directory, the output produced gives guidance as to how to build the files. By -following the structure of the compiling commands one may copy the appropriate portions, -perhaps replacing the filename with an argument that the user can include at link time. -An example of such a script is as follows: - -g++ -DHAVE_CONFIG_H -I.. -I../include -I../include -O2 -MT $1.o -MD -MP -MF -.deps/qd_test.Tpo -c -o $1.o $1.cpp -mv -f .deps/$1.Tpo .deps/$1.Po -g++ -O2 -o $1 $1.o ../src/libqd.a -lm - -To use the link script, make it executable (by typing "chmod +x link.scr) and then type: - -./link.scr compileExample - -Note that the file extension is not included because the script handles all extensions, -expecting the source file to have the extension ".cpp". - -Fortran-90 source files: - -Similarly, a script for compiling fortran programs may be constructed as follows. -In the fortran directory, type "make quadtsq". This compiles the Fortran program -tquadts.f, links with all necessary library files, and produces the executable -"quadts". As this is being done, all flags and linked libraries are displayed. -For instance, on a 2019-era Apple Macintosh system, where the library was installed -as above with g++ for C++ and gfortran for Fortran-90, the following is output: - -gfortran -m64 -ffree-form -c -o tquadtsq.o tquadtsq.f -/bin/sh ../libtool --tag=CXX --mode=link g++ -O2 -o quadtsq tquadtsq.o second.o -libqdmod.la libqd_f_main.la ../src/libqd.la --L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0 --L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../.. --lgfortran -lquadmath -lm -lm - -Thus a general compile-link script is the following: - -gfortran -m64 -ffree-form -c -o $1.o $1.f90 -/bin/sh ../libtool --tag=CXX --mode=link g++ -O2 -o $1 $1.o second.o \ - libqdmod.la libqd_f_main.la ../src/libqd.la \ - -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0 \ - -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../.. \ - -lgfortran -lquadmath -lm -lm - -Note that if the .f90 suffix is used for Fortran-90 source files, the --ffree-form flag may be omitted, but the first line above should end with -"$1.f90" (as shown above). After forming the script, name file, "complink.scr", -and then type "chmod +x complink.scr". To use this script compile and link a -program named "prog.f90", type "./complink.scr prog". - - -III. C++ usage - -As much as possible, operator overloading is included to make basic programming as much -like using standard typed floating-point arithmetic. Changing many codes should be as -simple as changing type statements and a few other lines. - -i. Constructors - -To create dd_real and qd_real variables calculated to the proper precision, one must use -care to use the included constructors properly. Many computations in which variables are -not explicitly typed to multiple-precision may be evaluated with double-precision -arithmetic. The user must take care to ensure that this does not cause errors. In particular, -an expression such as 1.0/3.0 will be evaluated to double precision before assignment or -further arithmetic. Upon assignment to a multi-precision variable, the value will be zero -padded. This problem is serious and potentially difficult to debug. To avoid this, use the -included constructors to force arithmetic to be performed in the full precision requested. - -For a table with descriptions, please see the documentation file qd.pdf in the docs directory. - -ii. Included functions and Constants - -Supported functions include assignment operators, comparisons, arithmetic and -assignment operators, and increments for integer types. Standard C math functions such as -exponentiation, trigonometric, logarithmic, hyperbolic, exponential and rounding functions -are included. As in assignment statements, one must be careful with implied typing of -constants when using these functions. Many codes need particular conversion for the power -function, which is frequently used with constants that must be explicitly typed for multi- -precision codes. - -Many constants are included, which are global and calculated upon initialization. The -following list of constants is calculated for both the dd_real and qd_real classes separately. -Use care to select the correct value. - -For a table with descriptions, please see the included file README.pdf - -ii. Conversion of types - -Static casts may be used to convert constants between types. One may also use constructors -to return temporary multi-precision types within expressions, but should be careful, as this -will waste memory if done repeatedly. For example: - - qd_real y ; - y = sin( qd_real(4.0) / 3.0 ) ; - -C-style casts may be used, but are not recommended. Dynamic and reinterpret casts are -not supported and should be considered unreliable. Casting between multi-precision and -standard precision types can be dangerous, and care must be taken to ensure that programs -are working properly and accuracy has not degraded by use of a misplaced type-conversion. - -D. Available precision, Control of Precision Levels, - -The library provides greatly extended accuracy when compared to standard double -precision. The type dd_real provides for 106 mantissa bits, or about 32 decimal digits. The -type qd_real provides for 212 mantissa bits, or about 64 decimal digits. - -Both the dd_real and qd_real values use the exponent from the highest double-precision -word for arithmetic, and as such do not extend the total range of values available. That -means that the maximum absolute value for either data type is the same as that of double- -precision, or approximately 10^308. The precision near this range, however, is greatly -increased. - -E. I/O - -The standard I/O stream routines have been overloaded to be fully compatible with all -included data types. One may need to manually reset the precision of the stream to obtain -full output. For example, if 60 digits are desired, use: - -cout.precision(60) ; - -When reading values using cin, each input numerical value must start on a separate -line. Two formats are acceptable: - - 1. Write the full constant - 3. Mantissa e exponent - -Here are three valid examples: - - 1.1 - 3.14159 26535 89793 - 123.123123e50 - -When read using cin, these constants will be converted using full multi-precision accuracy. - - -IV. Fortran-90 Usage - -NEW (2007-01-10): The Fortran translation modules now support the complex datatypes -"dd_complex" and "qd_complex". - -Since the quad-double library is written in C++, it must be linked in with a C++ compiler (so -that C++ specific things such as static initializations are correctly handled). Thus the main -program must be written in C/C++ and call the Fortran 90 subroutine. The Fortran 90 -subroutine should be called f_main. - -Here is a sample Fortran-90 program, equivalent to the above C++ program: - - subroutine f_main - use qdmodule - implicit none - type (qd_real) a, b - a = 1.d0 - b = cos(a)**2 + sin(a)**2 - 1.d0 - call qdwrite(6, b) - stop - end subroutine - -This verifies that cos^2(1) + sin^2(1) = 1 to 64 digit accuracy. - -Most operators and generic function references, including many mixed-mode type -combinations with double-precision (ie real*8), have been overloaded (extended) to work -with double-double and quad-double data. It is important, however, that users keep in -mind the fact that expressions are evaluated strictly according to conventional Fortran -operator precedence rules. Thus some subexpressions may be evaluated only to 15-digit -accuracy. For example, with the code - - real*8 d1 - type (dd_real) t1, t2 - ... - t1 = cos (t2) + d1/3.d0 - -the expression d1/3.d0 is computed to real*8 accuracy only (about 15 digits), since both d1 -and 3.d0 have type real*8. This result is then converted to dd_real by zero extension before -being added to cos(t2). So, for example, if d1 held the value 1.d0, then the quotient d1/3.d0 -would only be accurate to 15 digits. If a fully accurate double-double quotient is required, -this should be written: - - real*8 d1 - type (dd_real) t1, t2 - ... - t1 = cos (t2) + ddreal (d1) / 3.d0 - -which forces all operations to be performed with double-double arithmetic. - -Along this line, a constant such as 1.1 appearing in an expression is evaluated only to real*4 -accuracy, and a constant such as 1.1d0 is evaluated only to real*8 accuracy (this is -according to standard Fortran conventions). If full quad-double accuracy is required, for -instance, one should write - - type (qd_real) t1 - ... - t1 = '1.1' - -The quotes enclosing 1.1 specify to the compiler that the constant is to be converted to -binary using quad-double arithmetic, before assignment to t1. Quoted constants may only -appear in assignment statements such as this. - -To link a Fortran-90 program with the C++ qd library, it is recommended to link with the -C++ compiler used to generate the library. The Fortran 90 interface (along with a C-style -main function calling f_main) is found in qdmod library. The qd-config script installed -during "make install" can be used to determine which flags to pass to compile and link your -programs: - - "qd-config --fcflags" displays compiler flags needed to compile your Fortran files. - "qd-config --fclibs" displays linker flags needed by the C++ linker to link in all the -necessary libraries. - -A sample Makefile that can be used as a template for compiling Fortran programs using -quad-double library is found in fortran/Makefile.sample. - -F90 functions defined with dd_real arguments: - Arithmetic: + - * / ** - Comparison tests: == < > <= >= /= - Others: abs, acos, aint, anint, asin, atan, atan2, cos, cosh, dble, erf, - erfc, exp, int, log, log10, max, min, mod, ddcsshf (cosh and sinh), - ddcssnf (cos and sin), ddranf (random number generator in (0,1)), - ddnrtf (n-th root), sign, sin, sinh, sqr, sqrt, tan, tanh - -Similar functions are provided for qd_real arguments with function names qdcsshf, -qdcssnf, qdranf and qdnrtf instead of the names in the list above. - -Input and output of double-double and quad-double data is done using the special -subroutines ddread, ddwrite, qdread and qdwrite. The first argument of these subroutines -is the Fortran I/O unit number, while additional arguments (as many as needed, up to 9 -arguments) are scalar variables or array elements of the appropriate type. Example: - - integer n - type (qd_real) qda, qdb, qdc(n) - ... - call qdwrite (6, qda, qdb) - do j = 1, n - call qdwrite (6, qdc(j)) - enddo - -Each input values must be on a separate line, and may include D or E exponents. Double- -double and quad-double constants may also be specified in assignment statements by -enclosing them in quotes, as in - - ... - type (qd_real) pi - ... - pi = -"3.14159265358979323846264338327950288419716939937510582097494459230" - ... - -Sample Fortran-90 programs illustrating some of these features are provided in the f90 -subdirectory. - - -V. Note on x86-Based Processors (MOST systems in use today) - -The algorithms in this library assume IEEE double precision floating point arithmetic. Since -Intel x86 processors have extended (80-bit) floating point registers, some compilers, -albeit a declining number, may generate commands for the 80-bit instructions. The QD -library does NOT work correctly with 80-bit instructions, so if one's code does not operate -correctly, this may be the reason. To avoid such problems, the round-to-double flag must be -enabled in the control word of the FPU for this library to function properly. The following -functions contains appropriate code to facilitate manipulation of this flag. For non-x86 -systems these functions do nothing (but still exist). - -fpu_fix_start This turns on the round-to-double bit in the control word. -fpu_fix_end This restores the control flag. - -These functions must be called by the main program, as follows: - - int main() { - unsigned int old_cw; - fpu_fix_start(&old_cw); - - ... user code using quad-double library ... - - fpu_fix_end(&old_cw); - } - -A Fortran-90 example is the following: - - subroutine f_main - use qdmodule - implicit none - integer*4 old_cw - - call f_fpu_fix_start(old_cw) - - ... user code using quad-double library ... - - call f_fpu_fix_end(old_cw) - end subroutine - diff --git a/src/external/PackedCSparse/qd/bits.cc b/src/external/PackedCSparse/qd/bits.cc deleted file mode 100644 index 4eaf9a26..00000000 --- a/src/external/PackedCSparse/qd/bits.cc +++ /dev/null @@ -1,85 +0,0 @@ -/* - * src/bits.cc - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Defines various routines to get / set bits of a IEEE floating point - * number. This used by the library for debugging purposes. - */ - -#include <iostream> -#include <iomanip> -#include <cmath> -#include <climits> - -#include "qd_config.h" -#include "inline.h" -#include "bits.h" - -#ifdef HAVE_IEEEFP_H -#include <ieeefp.h> -#endif - -using std::setw; - -int get_double_expn(double x) { - if (x == 0.0) - return INT_MIN; - if (QD_ISINF(x) || QD_ISNAN(x)) - return INT_MAX; - - double y = std::abs(x); - int i = 0; - if (y < 1.0) { - while (y < 1.0) { - y *= 2.0; - i++; - } - return -i; - } else if (y >= 2.0) { - while (y >= 2.0) { - y *= 0.5; - i++; - } - return i; - } - return 0; -} - -void print_double_info(std::ostream &os, double x) { - std::streamsize old_prec = os.precision(19); - std::ios_base::fmtflags old_flags = os.flags(); - os << std::scientific; - - os << setw(27) << x << ' '; - if (QD_ISNAN(x) || QD_ISINF(x) || (x == 0.0)) { - os << " "; - } else { - - x = std::abs(x); - int expn = get_double_expn(x); - double d = std::ldexp(1.0, expn); - os << setw(5) << expn << " "; - for (int i = 0; i < 53; i++) { - if (x >= d) { - x -= d; - os << '1'; - } else - os << '0'; - d *= 0.5; - } - - if (x != 0.0) { - // should not happen - os << " +trailing stuff"; - } - } - - os.precision(old_prec); - os.flags(old_flags); -} - diff --git a/src/external/PackedCSparse/qd/bits.h b/src/external/PackedCSparse/qd/bits.h deleted file mode 100644 index 58570aac..00000000 --- a/src/external/PackedCSparse/qd/bits.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * include/bits.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * This file defines various routines to get / set bits of a IEEE floating - * point number. This is used by the library for debugging purposes. - */ - -#ifndef _QD_BITS_H -#define _QD_BITS_H - -#include <iostream> -#include "qd_config.h" - -/* Returns the exponent of the double precision number. - Returns INT_MIN is x is zero, and INT_MAX if x is INF or NaN. */ -int get_double_expn(double x); - -/* Prints - SIGN EXPN MANTISSA - of the given double. If x is NaN, INF, or Zero, this - prints out the strings NaN, +/- INF, and 0. */ -void print_double_info(std::ostream &os, double x); - - -#endif /* _QD_BITS_H */ - diff --git a/src/external/PackedCSparse/qd/c_dd.cc b/src/external/PackedCSparse/qd/c_dd.cc deleted file mode 100644 index 0a7c12ac..00000000 --- a/src/external/PackedCSparse/qd/c_dd.cc +++ /dev/null @@ -1,314 +0,0 @@ -/* - * src/c_dd.cc - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Contains the C wrapper functions for double-double precision arithmetic. - * This can be used from Fortran code. - */ -#include <cstring> - -#include "qd_config.h" -#include "dd_real.h" -#include "c_dd.h" - -#define TO_DOUBLE_PTR(a, ptr) ptr[0] = a.x[0]; ptr[1] = a.x[1]; - -extern "C" { - -/* add */ -void c_dd_add(const double *a, const double *b, double *c) { - dd_real cc; - cc = dd_real(a) + dd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_dd_add_dd_d(const double *a, double b, double *c) { - dd_real cc; - cc = dd_real(a) + b; - TO_DOUBLE_PTR(cc, c); -} -void c_dd_add_d_dd(double a, const double *b, double *c) { - dd_real cc; - cc = a + dd_real(b); - TO_DOUBLE_PTR(cc, c); -} - - -/* sub */ -void c_dd_sub(const double *a, const double *b, double *c) { - dd_real cc; - cc = dd_real(a) - dd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_dd_sub_dd_d(const double *a, double b, double *c) { - dd_real cc; - cc = dd_real(a) - b; - TO_DOUBLE_PTR(cc, c); -} -void c_dd_sub_d_dd(double a, const double *b, double *c) { - dd_real cc; - cc = a - dd_real(b); - TO_DOUBLE_PTR(cc, c); -} - - -/* mul */ -void c_dd_mul(const double *a, const double *b, double *c) { - dd_real cc; - cc = dd_real(a) * dd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_dd_mul_dd_d(const double *a, double b, double *c) { - dd_real cc; - cc = dd_real(a) * b; - TO_DOUBLE_PTR(cc, c); -} -void c_dd_mul_d_dd(double a, const double *b, double *c) { - dd_real cc; - cc = a * dd_real(b); - TO_DOUBLE_PTR(cc, c); -} - - -/* div */ -void c_dd_div(const double *a, const double *b, double *c) { - dd_real cc; - cc = dd_real(a) / dd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_dd_div_dd_d(const double *a, double b, double *c) { - dd_real cc; - cc = dd_real(a) / b; - TO_DOUBLE_PTR(cc, c); -} -void c_dd_div_d_dd(double a, const double *b, double *c) { - dd_real cc; - cc = a / dd_real(b); - TO_DOUBLE_PTR(cc, c); -} - - -/* copy */ -void c_dd_copy(const double *a, double *b) { - b[0] = a[0]; - b[1] = a[1]; -} -void c_dd_copy_d(double a, double *b) { - b[0] = a; - b[1] = 0.0; -} - - -void c_dd_sqrt(const double *a, double *b) { - dd_real bb; - bb = sqrt(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_sqr(const double *a, double *b) { - dd_real bb; - bb = sqr(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_abs(const double *a, double *b) { - dd_real bb; - bb = abs(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_npwr(const double *a, int n, double *b) { - dd_real bb; - bb = npwr(dd_real(a), n); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_nroot(const double *a, int n, double *b) { - dd_real bb; - bb = nroot(dd_real(a), n); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_nint(const double *a, double *b) { - dd_real bb; - bb = nint(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_aint(const double *a, double *b) { - dd_real bb; - bb = aint(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_floor(const double *a, double *b) { - dd_real bb; - bb = floor(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_ceil(const double *a, double *b) { - dd_real bb; - bb = ceil(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_log(const double *a, double *b) { - dd_real bb; - bb = log(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_log10(const double *a, double *b) { - dd_real bb; - bb = log10(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_exp(const double *a, double *b) { - dd_real bb; - bb = exp(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_sin(const double *a, double *b) { - dd_real bb; - bb = sin(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_cos(const double *a, double *b) { - dd_real bb; - bb = cos(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_tan(const double *a, double *b) { - dd_real bb; - bb = tan(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_asin(const double *a, double *b) { - dd_real bb; - bb = asin(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_acos(const double *a, double *b) { - dd_real bb; - bb = acos(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_atan(const double *a, double *b) { - dd_real bb; - bb = atan(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_atan2(const double *a, const double *b, double *c) { - dd_real cc; - cc = atan2(dd_real(a), dd_real(b)); - TO_DOUBLE_PTR(cc, c); -} - -void c_dd_sinh(const double *a, double *b) { - dd_real bb; - bb = sinh(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_cosh(const double *a, double *b) { - dd_real bb; - bb = cosh(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_tanh(const double *a, double *b) { - dd_real bb; - bb = tanh(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_asinh(const double *a, double *b) { - dd_real bb; - bb = asinh(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_acosh(const double *a, double *b) { - dd_real bb; - bb = acosh(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_dd_atanh(const double *a, double *b) { - dd_real bb; - bb = atanh(dd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_dd_sincos(const double *a, double *s, double *c) { - dd_real ss, cc; - sincos(dd_real(a), ss, cc); - TO_DOUBLE_PTR(ss, s); - TO_DOUBLE_PTR(cc, c); -} - -void c_dd_sincosh(const double *a, double *s, double *c) { - dd_real ss, cc; - sincosh(dd_real(a), ss, cc); - TO_DOUBLE_PTR(ss, s); - TO_DOUBLE_PTR(cc, c); -} - -void c_dd_read(const char *s, double *a) { - dd_real aa(s); - TO_DOUBLE_PTR(aa, a); -} - -void c_dd_swrite(const double *a, int precision, char *s, int len) { - dd_real(a).write(s, len, precision); -} - -void c_dd_write(const double *a) { - std::cout << dd_real(a).to_string(dd_real::_ndigits) << std::endl; -} - -void c_dd_neg(const double *a, double *b) { - b[0] = -a[0]; - b[1] = -a[1]; -} - -void c_dd_rand(double *a) { - dd_real aa; - aa = ddrand(); - TO_DOUBLE_PTR(aa, a); -} - -void c_dd_comp(const double *a, const double *b, int *result) { - dd_real aa(a), bb(b); - if (aa < bb) - *result = -1; - else if (aa > bb) - *result = 1; - else - *result = 0; -} - -void c_dd_comp_dd_d(const double *a, double b, int *result) { - dd_real aa(a), bb(b); - if (aa < bb) - *result = -1; - else if (aa > bb) - *result = 1; - else - *result = 0; -} - -void c_dd_comp_d_dd(double a, const double *b, int *result) { - dd_real aa(a), bb(b); - if (aa < bb) - *result = -1; - else if (aa > bb) - *result = 1; - else - *result = 0; -} - -void c_dd_pi(double *a) { - TO_DOUBLE_PTR(dd_real::_pi, a); -} - -} diff --git a/src/external/PackedCSparse/qd/c_dd.h b/src/external/PackedCSparse/qd/c_dd.h deleted file mode 100644 index 310162ed..00000000 --- a/src/external/PackedCSparse/qd/c_dd.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * include/c_dd.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Contains C wrapper function prototypes for double-double precision - * arithmetic. This can also be used from fortran code. - */ -#ifndef _QD_C_DD_H -#define _QD_C_DD_H - -#include "qd_config.h" -#include "fpu.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* add */ -void c_dd_add(const double *a, const double *b, double *c); -void c_dd_add_d_dd(double a, const double *b, double *c); -void c_dd_add_dd_d(const double *a, double b, double *c); - -/* sub */ -void c_dd_sub(const double *a, const double *b, double *c); -void c_dd_sub_d_dd(double a, const double *b, double *c); -void c_dd_sub_dd_d(const double *a, double b, double *c); - -/* mul */ -void c_dd_mul(const double *a, const double *b, double *c); -void c_dd_mul_d_dd(double a, const double *b, double *c); -void c_dd_mul_dd_d(const double *a, double b, double *c); - -/* div */ -void c_dd_div(const double *a, const double *b, double *c); -void c_dd_div_d_dd(double a, const double *b, double *c); -void c_dd_div_dd_d(const double *a, double b, double *c); - -/* copy */ -void c_dd_copy(const double *a, double *b); -void c_dd_copy_d(double a, double *b); - -void c_dd_sqrt(const double *a, double *b); -void c_dd_sqr(const double *a, double *b); - -void c_dd_abs(const double *a, double *b); - -void c_dd_npwr(const double *a, int b, double *c); -void c_dd_nroot(const double *a, int b, double *c); - -void c_dd_nint(const double *a, double *b); -void c_dd_aint(const double *a, double *b); -void c_dd_floor(const double *a, double *b); -void c_dd_ceil(const double *a, double *b); - -void c_dd_exp(const double *a, double *b); -void c_dd_log(const double *a, double *b); -void c_dd_log10(const double *a, double *b); - -void c_dd_sin(const double *a, double *b); -void c_dd_cos(const double *a, double *b); -void c_dd_tan(const double *a, double *b); - -void c_dd_asin(const double *a, double *b); -void c_dd_acos(const double *a, double *b); -void c_dd_atan(const double *a, double *b); -void c_dd_atan2(const double *a, const double *b, double *c); - -void c_dd_sinh(const double *a, double *b); -void c_dd_cosh(const double *a, double *b); -void c_dd_tanh(const double *a, double *b); - -void c_dd_asinh(const double *a, double *b); -void c_dd_acosh(const double *a, double *b); -void c_dd_atanh(const double *a, double *b); - -void c_dd_sincos(const double *a, double *s, double *c); -void c_dd_sincosh(const double *a, double *s, double *c); - -void c_dd_read(const char *s, double *a); -void c_dd_swrite(const double *a, int precision, char *s, int len); -void c_dd_write(const double *a); -void c_dd_neg(const double *a, double *b); -void c_dd_rand(double *a); -void c_dd_comp(const double *a, const double *b, int *result); -void c_dd_comp_dd_d(const double *a, double b, int *result); -void c_dd_comp_d_dd(double a, const double *b, int *result); -void c_dd_pi(double *a); - -#ifdef __cplusplus -} -#endif - -#endif /* _QD_C_DD_H */ diff --git a/src/external/PackedCSparse/qd/c_qd.cc b/src/external/PackedCSparse/qd/c_qd.cc deleted file mode 100644 index fd50e922..00000000 --- a/src/external/PackedCSparse/qd/c_qd.cc +++ /dev/null @@ -1,450 +0,0 @@ -/* - * src/c_qd.cc - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Contains C wrapper function for quad-double precision arithmetic. - * This can be used from fortran code. - */ -#include <cstring> - -#include "qd_config.h" -#include "qd_real.h" -#include "c_qd.h" - -#define TO_DOUBLE_PTR(a, ptr) ptr[0] = a.x[0]; ptr[1] = a.x[1]; \ - ptr[2] = a.x[2]; ptr[3] = a.x[3]; - -extern "C" { - - - -/* add */ -void c_qd_add(const double *a, const double *b, double *c) { - qd_real cc; - cc = qd_real(a) + qd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_add_qd_dd(const double *a, const double *b, double *c) { - qd_real cc; - cc = qd_real(a) + dd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_add_dd_qd(const double *a, const double *b, double *c) { - qd_real cc; - cc = dd_real(a) + qd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_add_qd_d(const double *a, double b, double *c) { - qd_real cc; - cc = qd_real(a) + b; - TO_DOUBLE_PTR(cc, c); -} -void c_qd_add_d_qd(double a, const double *b, double *c) { - qd_real cc; - cc = a + qd_real(b); - TO_DOUBLE_PTR(cc, c); -} - - - -/* sub */ -void c_qd_sub(const double *a, const double *b, double *c) { - qd_real cc; - cc = qd_real(a) - qd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_sub_qd_dd(const double *a, const double *b, double *c) { - qd_real cc; - cc = qd_real(a) - dd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_sub_dd_qd(const double *a, const double *b, double *c) { - qd_real cc; - cc = dd_real(a) - qd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_sub_qd_d(const double *a, double b, double *c) { - qd_real cc; - cc = qd_real(a) - b; - TO_DOUBLE_PTR(cc, c); -} -void c_qd_sub_d_qd(double a, const double *b, double *c) { - qd_real cc; - cc = a - qd_real(b); - TO_DOUBLE_PTR(cc, c); -} - - - -/* mul */ -void c_qd_mul(const double *a, const double *b, double *c) { - qd_real cc; - cc = qd_real(a) * qd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_mul_qd_dd(const double *a, const double *b, double *c) { - qd_real cc; - cc = qd_real(a) * dd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_mul_dd_qd(const double *a, const double *b, double *c) { - qd_real cc; - cc = dd_real(a) * qd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_mul_qd_d(const double *a, double b, double *c) { - qd_real cc; - cc = qd_real(a) * b; - TO_DOUBLE_PTR(cc, c); -} -void c_qd_mul_d_qd(double a, const double *b, double *c) { - qd_real cc; - cc = a * qd_real(b); - TO_DOUBLE_PTR(cc, c); -} - - - -/* div */ -void c_qd_div(const double *a, const double *b, double *c) { - qd_real cc; - cc = qd_real(a) / qd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_div_qd_dd(const double *a, const double *b, double *c) { - qd_real cc; - cc = qd_real(a) / dd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_div_dd_qd(const double *a, const double *b, double *c) { - qd_real cc; - cc = dd_real(a) / qd_real(b); - TO_DOUBLE_PTR(cc, c); -} -void c_qd_div_qd_d(const double *a, double b, double *c) { - qd_real cc; - cc = qd_real(a) / b; - TO_DOUBLE_PTR(cc, c); -} -void c_qd_div_d_qd(double a, const double *b, double *c) { - qd_real cc; - cc = a / qd_real(b); - TO_DOUBLE_PTR(cc, c); -} - - - - -/* selfadd */ -void c_qd_selfadd(const double *a, double *b) { - qd_real bb(b); - bb += qd_real(a); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_selfadd_dd(const double *a, double *b) { - qd_real bb(b); - bb += dd_real(a); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_selfadd_d(double a, double *b) { - qd_real bb(b); - bb += a; - TO_DOUBLE_PTR(bb, b); -} - - - -/* selfsub */ -void c_qd_selfsub(const double *a, double *b) { - qd_real bb(b); - bb -= qd_real(a); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_selfsub_dd(const double *a, double *b) { - qd_real bb(b); - bb -= dd_real(a); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_selfsub_d(double a, double *b) { - qd_real bb(b); - bb -= a; - TO_DOUBLE_PTR(bb, b); -} - - - -/* selfmul */ -void c_qd_selfmul(const double *a, double *b) { - qd_real bb(b); - bb *= qd_real(a); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_selfmul_dd(const double *a, double *b) { - qd_real bb(b); - bb *= dd_real(a); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_selfmul_d(double a, double *b) { - qd_real bb(b); - bb *= a; - TO_DOUBLE_PTR(bb, b); -} - - - -/* selfdiv */ -void c_qd_selfdiv(const double *a, double *b) { - qd_real bb(b); - bb /= qd_real(a); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_selfdiv_dd(const double *a, double *b) { - qd_real bb(b); - bb /= dd_real(a); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_selfdiv_d(double a, double *b) { - qd_real bb(b); - bb /= a; - TO_DOUBLE_PTR(bb, b); -} - - - -/* copy */ -void c_qd_copy(const double *a, double *b) { - b[0] = a[0]; - b[1] = a[1]; - b[2] = a[2]; - b[3] = a[3]; -} -void c_qd_copy_dd(const double *a, double *b) { - b[0] = a[0]; - b[1] = a[1]; - b[2] = 0.0; - b[3] = 0.0; -} -void c_qd_copy_d(double a, double *b) { - b[0] = a; - b[1] = 0.0; - b[2] = 0.0; - b[3] = 0.0; -} - - -void c_qd_sqrt(const double *a, double *b) { - qd_real bb; - bb = sqrt(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_sqr(const double *a, double *b) { - qd_real bb; - bb = sqr(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_abs(const double *a, double *b) { - qd_real bb; - bb = abs(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_npwr(const double *a, int n, double *b) { - qd_real bb; - bb = npwr(qd_real(a), n); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_nroot(const double *a, int n, double *b) { - qd_real bb; - bb = nroot(qd_real(a), n); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_nint(const double *a, double *b) { - qd_real bb; - bb = nint(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_aint(const double *a, double *b) { - qd_real bb; - bb = aint(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_floor(const double *a, double *b) { - qd_real bb; - bb = floor(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_ceil(const double *a, double *b) { - qd_real bb; - bb = ceil(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_log(const double *a, double *b) { - qd_real bb; - bb = log(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_log10(const double *a, double *b) { - qd_real bb; - bb = log10(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_exp(const double *a, double *b) { - qd_real bb; - bb = exp(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_sin(const double *a, double *b) { - qd_real bb; - bb = sin(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_cos(const double *a, double *b) { - qd_real bb; - bb = cos(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_tan(const double *a, double *b) { - qd_real bb; - bb = tan(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_asin(const double *a, double *b) { - qd_real bb; - bb = asin(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_acos(const double *a, double *b) { - qd_real bb; - bb = acos(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_atan(const double *a, double *b) { - qd_real bb; - bb = atan(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_atan2(const double *a, const double *b, double *c) { - qd_real cc; - cc = atan2(qd_real(a), qd_real(b)); - TO_DOUBLE_PTR(cc, c); -} - -void c_qd_sinh(const double *a, double *b) { - qd_real bb; - bb = sinh(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_cosh(const double *a, double *b) { - qd_real bb; - bb = cosh(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_tanh(const double *a, double *b) { - qd_real bb; - bb = tanh(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_asinh(const double *a, double *b) { - qd_real bb; - bb = asinh(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_acosh(const double *a, double *b) { - qd_real bb; - bb = acosh(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} -void c_qd_atanh(const double *a, double *b) { - qd_real bb; - bb = atanh(qd_real(a)); - TO_DOUBLE_PTR(bb, b); -} - -void c_qd_sincos(const double *a, double *s, double *c) { - qd_real ss, cc; - sincos(qd_real(a), ss, cc); - TO_DOUBLE_PTR(cc, c); - TO_DOUBLE_PTR(ss, s); -} - -void c_qd_sincosh(const double *a, double *s, double *c) { - qd_real ss, cc; - sincosh(qd_real(a), ss, cc); - TO_DOUBLE_PTR(cc, c); - TO_DOUBLE_PTR(ss, s); -} - -void c_qd_read(const char *s, double *a) { - qd_real aa(s); - TO_DOUBLE_PTR(aa, a); -} - -void c_qd_swrite(const double *a, int precision, char *s, int len) { - qd_real(a).write(s, len, precision); -} - -void c_qd_write(const double *a) { - std::cout << qd_real(a).to_string(qd_real::_ndigits) << std::endl; -} - -void c_qd_neg(const double *a, double *b) { - b[0] = -a[0]; - b[1] = -a[1]; - b[2] = -a[2]; - b[3] = -a[3]; -} - -void c_qd_rand(double *a) { - qd_real aa; - aa = qdrand(); - TO_DOUBLE_PTR(aa, a); -} - -void c_qd_comp(const double *a, const double *b, int *result) { - qd_real aa(a), bb(b); - if (aa < bb) - *result = -1; - else if (aa > bb) - *result = 1; - else - *result = 0; -} - -void c_qd_comp_qd_d(const double *a, double b, int *result) { - qd_real aa(a); - if (aa < b) - *result = -1; - else if (aa > b) - *result = 1; - else - *result = 0; -} - -void c_qd_comp_d_qd(double a, const double *b, int *result) { - qd_real bb(b); - if (a < bb) - *result = -1; - else if (a > bb) - *result = 1; - else - *result = 0; -} - -void c_qd_pi(double *a) { - TO_DOUBLE_PTR(qd_real::_pi, a); -} - -} diff --git a/src/external/PackedCSparse/qd/c_qd.h b/src/external/PackedCSparse/qd/c_qd.h deleted file mode 100644 index d11a7ff1..00000000 --- a/src/external/PackedCSparse/qd/c_qd.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * include/c_qd.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Contains C wrapper function prototypes for quad-double precision - * arithmetic. This can also be used from fortran code. - */ -#ifndef _QD_C_QD_H -#define _QD_C_QD_H - -#include "c_dd.h" -#include "qd_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* add */ -void c_qd_add(const double *a, const double *b, double *c); -void c_qd_add_dd_qd(const double *a, const double *b, double *c); -void c_qd_add_qd_dd(const double *a, const double *b, double *c); -void c_qd_add_d_qd(double a, const double *b, double *c); -void c_qd_add_qd_d(const double *a, double b, double *c); -void c_qd_selfadd(const double *a, double *b); -void c_qd_selfadd_dd(const double *a, double *b); -void c_qd_selfadd_d(double a, double *b); - -/* sub */ -void c_qd_sub(const double *a, const double *b, double *c); -void c_qd_sub_dd_qd(const double *a, const double *b, double *c); -void c_qd_sub_qd_dd(const double *a, const double *b, double *c); -void c_qd_sub_d_qd(double a, const double *b, double *c); -void c_qd_sub_qd_d(const double *a, double b, double *c); -void c_qd_selfsub(const double *a, double *b); -void c_qd_selfsub_dd(const double *a, double *b); -void c_qd_selfsub_d(double a, double *b); - -/* mul */ -void c_qd_mul(const double *a, const double *b, double *c); -void c_qd_mul_dd_qd(const double *a, const double *b, double *c); -void c_qd_mul_qd_dd(const double *a, const double *b, double *c); -void c_qd_mul_d_qd(double a, const double *b, double *c); -void c_qd_mul_qd_d(const double *a, double b, double *c); -void c_qd_selfmul(const double *a, double *b); -void c_qd_selfmul_dd(const double *a, double *b); -void c_qd_selfmul_d(double a, double *b); - -/* div */ -void c_qd_div(const double *a, const double *b, double *c); -void c_qd_div_dd_qd(const double *a, const double *b, double *c); -void c_qd_div_qd_dd(const double *a, const double *b, double *c); -void c_qd_div_d_qd(double a, const double *b, double *c); -void c_qd_div_qd_d(const double *a, double b, double *c); -void c_qd_selfdiv(const double *a, double *b); -void c_qd_selfdiv_dd(const double *a, double *b); -void c_qd_selfdiv_d(double a, double *b); - -/* copy */ -void c_qd_copy(const double *a, double *b); -void c_qd_copy_dd(const double *a, double *b); -void c_qd_copy_d(double a, double *b); - -void c_qd_sqrt(const double *a, double *b); -void c_qd_sqr(const double *a, double *b); - -void c_qd_abs(const double *a, double *b); - -void c_qd_npwr(const double *a, int b, double *c); -void c_qd_nroot(const double *a, int b, double *c); - -void c_qd_nint(const double *a, double *b); -void c_qd_aint(const double *a, double *b); -void c_qd_floor(const double *a, double *b); -void c_qd_ceil(const double *a, double *b); - -void c_qd_exp(const double *a, double *b); -void c_qd_log(const double *a, double *b); -void c_qd_log10(const double *a, double *b); - -void c_qd_sin(const double *a, double *b); -void c_qd_cos(const double *a, double *b); -void c_qd_tan(const double *a, double *b); - -void c_qd_asin(const double *a, double *b); -void c_qd_acos(const double *a, double *b); -void c_qd_atan(const double *a, double *b); -void c_qd_atan2(const double *a, const double *b, double *c); - -void c_qd_sinh(const double *a, double *b); -void c_qd_cosh(const double *a, double *b); -void c_qd_tanh(const double *a, double *b); - -void c_qd_asinh(const double *a, double *b); -void c_qd_acosh(const double *a, double *b); -void c_qd_atanh(const double *a, double *b); - -void c_qd_sincos(const double *a, double *s, double *c); -void c_qd_sincosh(const double *a, double *s, double *c); - -void c_qd_read(const char *s, double *a); -void c_qd_swrite(const double *a, int precision, char *s, int len); -void c_qd_write(const double *a); -void c_qd_neg(const double *a, double *b); -void c_qd_rand(double *a); -void c_qd_comp(const double *a, const double *b, int *result); -void c_qd_comp_qd_d(const double *a, double b, int *result); -void c_qd_comp_d_qd(double a, const double *b, int *result); -void c_qd_pi(double *a); - -#ifdef __cplusplus -} -#endif - -#endif /* _QD_C_QD_H */ diff --git a/src/external/PackedCSparse/qd/dd_const.cc b/src/external/PackedCSparse/qd/dd_const.cc deleted file mode 100644 index 38b7b5ae..00000000 --- a/src/external/PackedCSparse/qd/dd_const.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - * src/dd_const.cc - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2007 - */ -#include "qd_config.h" -#include "dd_real.h" - -const dd_real dd_real::_2pi = dd_real(6.283185307179586232e+00, - 2.449293598294706414e-16); -const dd_real dd_real::_pi = dd_real(3.141592653589793116e+00, - 1.224646799147353207e-16); -const dd_real dd_real::_pi2 = dd_real(1.570796326794896558e+00, - 6.123233995736766036e-17); -const dd_real dd_real::_pi4 = dd_real(7.853981633974482790e-01, - 3.061616997868383018e-17); -const dd_real dd_real::_3pi4 = dd_real(2.356194490192344837e+00, - 9.1848509936051484375e-17); -const dd_real dd_real::_e = dd_real(2.718281828459045091e+00, - 1.445646891729250158e-16); -const dd_real dd_real::_log2 = dd_real(6.931471805599452862e-01, - 2.319046813846299558e-17); -const dd_real dd_real::_log10 = dd_real(2.302585092994045901e+00, - -2.170756223382249351e-16); -const dd_real dd_real::_nan = dd_real(qd::_d_nan, qd::_d_nan); -const dd_real dd_real::_inf = dd_real(qd::_d_inf, qd::_d_inf); - -const double dd_real::_eps = 4.93038065763132e-32; // 2^-104 -const double dd_real::_min_normalized = 2.0041683600089728e-292; // = 2^(-1022 + 53) -const dd_real dd_real::_max = - dd_real(1.79769313486231570815e+308, 9.97920154767359795037e+291); -const dd_real dd_real::_safe_max = - dd_real(1.7976931080746007281e+308, 9.97920154767359795037e+291); -const int dd_real::_ndigits = 31; - - diff --git a/src/external/PackedCSparse/qd/dd_inline.h b/src/external/PackedCSparse/qd/dd_inline.h deleted file mode 100644 index 89bc24f2..00000000 --- a/src/external/PackedCSparse/qd/dd_inline.h +++ /dev/null @@ -1,621 +0,0 @@ -/* - * include/dd_inline.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Contains small functions (suitable for inlining) in the double-double - * arithmetic package. - */ -#ifndef _QD_DD_INLINE_H -#define _QD_DD_INLINE_H - -#include <cmath> -#include "inline.h" - -#ifndef QD_INLINE -#define inline -#endif - - -/*********** Additions ************/ -/* double-double = double + double */ -inline dd_real dd_real::add(double a, double b) { - double s, e; - s = qd::two_sum(a, b, e); - return dd_real(s, e); -} - -/* double-double + double */ -inline dd_real operator+(const dd_real &a, double b) { - double s1, s2; - s1 = qd::two_sum(a.x[0], b, s2); - s2 += a.x[1]; - s1 = qd::quick_two_sum(s1, s2, s2); - return dd_real(s1, s2); -} - -/* double-double + double-double */ -inline dd_real dd_real::ieee_add(const dd_real &a, const dd_real &b) { - /* This one satisfies IEEE style error bound, - due to K. Briggs and W. Kahan. */ - double s1, s2, t1, t2; - - s1 = qd::two_sum(a.x[0], b.x[0], s2); - t1 = qd::two_sum(a.x[1], b.x[1], t2); - s2 += t1; - s1 = qd::quick_two_sum(s1, s2, s2); - s2 += t2; - s1 = qd::quick_two_sum(s1, s2, s2); - return dd_real(s1, s2); -} - -inline dd_real dd_real::sloppy_add(const dd_real &a, const dd_real &b) { - /* This is the less accurate version ... obeys Cray-style - error bound. */ - double s, e; - - s = qd::two_sum(a.x[0], b.x[0], e); - e += (a.x[1] + b.x[1]); - s = qd::quick_two_sum(s, e, e); - return dd_real(s, e); -} - -inline dd_real operator+(const dd_real &a, const dd_real &b) { -#ifndef QD_IEEE_ADD - return dd_real::sloppy_add(a, b); -#else - return dd_real::ieee_add(a, b); -#endif -} - -/* double + double-double */ -inline dd_real operator+(double a, const dd_real &b) { - return (b + a); -} - - -/*********** Self-Additions ************/ -/* double-double += double */ -inline dd_real &dd_real::operator+=(double a) { - double s1, s2; - s1 = qd::two_sum(x[0], a, s2); - s2 += x[1]; - x[0] = qd::quick_two_sum(s1, s2, x[1]); - return *this; -} - -/* double-double += double-double */ -inline dd_real &dd_real::operator+=(const dd_real &a) { -#ifndef QD_IEEE_ADD - double s, e; - s = qd::two_sum(x[0], a.x[0], e); - e += x[1]; - e += a.x[1]; - x[0] = qd::quick_two_sum(s, e, x[1]); - return *this; -#else - double s1, s2, t1, t2; - s1 = qd::two_sum(x[0], a.x[0], s2); - t1 = qd::two_sum(x[1], a.x[1], t2); - s2 += t1; - s1 = qd::quick_two_sum(s1, s2, s2); - s2 += t2; - x[0] = qd::quick_two_sum(s1, s2, x[1]); - return *this; -#endif -} - -/*********** Subtractions ************/ -/* double-double = double - double */ -inline dd_real dd_real::sub(double a, double b) { - double s, e; - s = qd::two_diff(a, b, e); - return dd_real(s, e); -} - -/* double-double - double */ -inline dd_real operator-(const dd_real &a, double b) { - double s1, s2; - s1 = qd::two_diff(a.x[0], b, s2); - s2 += a.x[1]; - s1 = qd::quick_two_sum(s1, s2, s2); - return dd_real(s1, s2); -} - -/* double-double - double-double */ -inline dd_real operator-(const dd_real &a, const dd_real &b) { -#ifndef QD_IEEE_ADD - double s, e; - s = qd::two_diff(a.x[0], b.x[0], e); - e += a.x[1]; - e -= b.x[1]; - s = qd::quick_two_sum(s, e, e); - return dd_real(s, e); -#else - double s1, s2, t1, t2; - s1 = qd::two_diff(a.x[0], b.x[0], s2); - t1 = qd::two_diff(a.x[1], b.x[1], t2); - s2 += t1; - s1 = qd::quick_two_sum(s1, s2, s2); - s2 += t2; - s1 = qd::quick_two_sum(s1, s2, s2); - return dd_real(s1, s2); -#endif -} - -/* double - double-double */ -inline dd_real operator-(double a, const dd_real &b) { - double s1, s2; - s1 = qd::two_diff(a, b.x[0], s2); - s2 -= b.x[1]; - s1 = qd::quick_two_sum(s1, s2, s2); - return dd_real(s1, s2); -} - -/*********** Self-Subtractions ************/ -/* double-double -= double */ -inline dd_real &dd_real::operator-=(double a) { - double s1, s2; - s1 = qd::two_diff(x[0], a, s2); - s2 += x[1]; - x[0] = qd::quick_two_sum(s1, s2, x[1]); - return *this; -} - -/* double-double -= double-double */ -inline dd_real &dd_real::operator-=(const dd_real &a) { -#ifndef QD_IEEE_ADD - double s, e; - s = qd::two_diff(x[0], a.x[0], e); - e += x[1]; - e -= a.x[1]; - x[0] = qd::quick_two_sum(s, e, x[1]); - return *this; -#else - double s1, s2, t1, t2; - s1 = qd::two_diff(x[0], a.x[0], s2); - t1 = qd::two_diff(x[1], a.x[1], t2); - s2 += t1; - s1 = qd::quick_two_sum(s1, s2, s2); - s2 += t2; - x[0] = qd::quick_two_sum(s1, s2, x[1]); - return *this; -#endif -} - -/*********** Unary Minus ***********/ -inline dd_real dd_real::operator-() const { - return dd_real(-x[0], -x[1]); -} - -/*********** Multiplications ************/ -/* double-double = double * double */ -inline dd_real dd_real::mul(double a, double b) { - double p, e; - p = qd::two_prod(a, b, e); - return dd_real(p, e); -} - -/* double-double * (2.0 ^ exp) */ -inline dd_real ldexp(const dd_real &a, int exp) { - return dd_real(std::ldexp(a.x[0], exp), std::ldexp(a.x[1], exp)); -} - -/* double-double * double, where double is a power of 2. */ -inline dd_real mul_pwr2(const dd_real &a, double b) { - return dd_real(a.x[0] * b, a.x[1] * b); -} - -/* double-double * double */ -inline dd_real operator*(const dd_real &a, double b) { - double p1, p2; - - p1 = qd::two_prod(a.x[0], b, p2); - p2 += (a.x[1] * b); - p1 = qd::quick_two_sum(p1, p2, p2); - return dd_real(p1, p2); -} - -/* double-double * double-double */ -inline dd_real operator*(const dd_real &a, const dd_real &b) { - double p1, p2; - - p1 = qd::two_prod(a.x[0], b.x[0], p2); - p2 += (a.x[0] * b.x[1] + a.x[1] * b.x[0]); - p1 = qd::quick_two_sum(p1, p2, p2); - return dd_real(p1, p2); -} - -/* double * double-double */ -inline dd_real operator*(double a, const dd_real &b) { - return (b * a); -} - -/*********** Self-Multiplications ************/ -/* double-double *= double */ -inline dd_real &dd_real::operator*=(double a) { - double p1, p2; - p1 = qd::two_prod(x[0], a, p2); - p2 += x[1] * a; - x[0] = qd::quick_two_sum(p1, p2, x[1]); - return *this; -} - -/* double-double *= double-double */ -inline dd_real &dd_real::operator*=(const dd_real &a) { - double p1, p2; - p1 = qd::two_prod(x[0], a.x[0], p2); - p2 += a.x[1] * x[0]; - p2 += a.x[0] * x[1]; - x[0] = qd::quick_two_sum(p1, p2, x[1]); - return *this; -} - -/*********** Divisions ************/ -inline dd_real dd_real::div(double a, double b) { - double q1, q2; - double p1, p2; - double s, e; - - q1 = a / b; - - /* Compute a - q1 * b */ - p1 = qd::two_prod(q1, b, p2); - s = qd::two_diff(a, p1, e); - e -= p2; - - /* get next approximation */ - q2 = (s + e) / b; - - s = qd::quick_two_sum(q1, q2, e); - - return dd_real(s, e); -} - -/* double-double / double */ -inline dd_real operator/(const dd_real &a, double b) { - - double q1, q2; - double p1, p2; - double s, e; - dd_real r; - - q1 = a.x[0] / b; /* approximate quotient. */ - - /* Compute this - q1 * d */ - p1 = qd::two_prod(q1, b, p2); - s = qd::two_diff(a.x[0], p1, e); - e += a.x[1]; - e -= p2; - - /* get next approximation. */ - q2 = (s + e) / b; - - /* renormalize */ - r.x[0] = qd::quick_two_sum(q1, q2, r.x[1]); - - return r; -} - -inline dd_real dd_real::sloppy_div(const dd_real &a, const dd_real &b) { - double s1, s2; - double q1, q2; - dd_real r; - - q1 = a.x[0] / b.x[0]; /* approximate quotient */ - - /* compute this - q1 * dd */ - r = b * q1; - s1 = qd::two_diff(a.x[0], r.x[0], s2); - s2 -= r.x[1]; - s2 += a.x[1]; - - /* get next approximation */ - q2 = (s1 + s2) / b.x[0]; - - /* renormalize */ - r.x[0] = qd::quick_two_sum(q1, q2, r.x[1]); - return r; -} - -inline dd_real dd_real::accurate_div(const dd_real &a, const dd_real &b) { - double q1, q2, q3; - dd_real r; - - q1 = a.x[0] / b.x[0]; /* approximate quotient */ - - r = a - q1 * b; - - q2 = r.x[0] / b.x[0]; - r -= (q2 * b); - - q3 = r.x[0] / b.x[0]; - - q1 = qd::quick_two_sum(q1, q2, q2); - r = dd_real(q1, q2) + q3; - return r; -} - -/* double-double / double-double */ -inline dd_real operator/(const dd_real &a, const dd_real &b) { -#ifdef QD_SLOPPY_DIV - return dd_real::sloppy_div(a, b); -#else - return dd_real::accurate_div(a, b); -#endif -} - -/* double / double-double */ -inline dd_real operator/(double a, const dd_real &b) { - return dd_real(a) / b; -} - -inline dd_real inv(const dd_real &a) { - return 1.0 / a; -} - -/*********** Self-Divisions ************/ -/* double-double /= double */ -inline dd_real &dd_real::operator/=(double a) { - *this = *this / a; - return *this; -} - -/* double-double /= double-double */ -inline dd_real &dd_real::operator/=(const dd_real &a) { - *this = *this / a; - return *this; -} - -/********** Remainder **********/ -inline dd_real drem(const dd_real &a, const dd_real &b) { - dd_real n = nint(a / b); - return (a - n * b); -} - -inline dd_real divrem(const dd_real &a, const dd_real &b, dd_real &r) { - dd_real n = nint(a / b); - r = a - n * b; - return n; -} - -/*********** Squaring **********/ -inline dd_real sqr(const dd_real &a) { - double p1, p2; - double s1, s2; - p1 = qd::two_sqr(a.x[0], p2); - p2 += 2.0 * a.x[0] * a.x[1]; - p2 += a.x[1] * a.x[1]; - s1 = qd::quick_two_sum(p1, p2, s2); - return dd_real(s1, s2); -} - -inline dd_real dd_real::sqr(double a) { - double p1, p2; - p1 = qd::two_sqr(a, p2); - return dd_real(p1, p2); -} - - -/********** Exponentiation **********/ -inline dd_real dd_real::operator^(int n) { - return npwr(*this, n); -} - - -/*********** Assignments ************/ -/* double-double = double */ -inline dd_real &dd_real::operator=(double a) { - x[0] = a; - x[1] = 0.0; - return *this; -} - -/*********** Equality Comparisons ************/ -/* double-double == double */ -inline bool operator==(const dd_real &a, double b) { - return (a.x[0] == b && a.x[1] == 0.0); -} - -/* double-double == double-double */ -inline bool operator==(const dd_real &a, const dd_real &b) { - return (a.x[0] == b.x[0] && a.x[1] == b.x[1]); -} - -/* double == double-double */ -inline bool operator==(double a, const dd_real &b) { - return (a == b.x[0] && b.x[1] == 0.0); -} - -/*********** Greater-Than Comparisons ************/ -/* double-double > double */ -inline bool operator>(const dd_real &a, double b) { - return (a.x[0] > b || (a.x[0] == b && a.x[1] > 0.0)); -} - -/* double-double > double-double */ -inline bool operator>(const dd_real &a, const dd_real &b) { - return (a.x[0] > b.x[0] || (a.x[0] == b.x[0] && a.x[1] > b.x[1])); -} - -/* double > double-double */ -inline bool operator>(double a, const dd_real &b) { - return (a > b.x[0] || (a == b.x[0] && b.x[1] < 0.0)); -} - -/*********** Less-Than Comparisons ************/ -/* double-double < double */ -inline bool operator<(const dd_real &a, double b) { - return (a.x[0] < b || (a.x[0] == b && a.x[1] < 0.0)); -} - -/* double-double < double-double */ -inline bool operator<(const dd_real &a, const dd_real &b) { - return (a.x[0] < b.x[0] || (a.x[0] == b.x[0] && a.x[1] < b.x[1])); -} - -/* double < double-double */ -inline bool operator<(double a, const dd_real &b) { - return (a < b.x[0] || (a == b.x[0] && b.x[1] > 0.0)); -} - -/*********** Greater-Than-Or-Equal-To Comparisons ************/ -/* double-double >= double */ -inline bool operator>=(const dd_real &a, double b) { - return (a.x[0] > b || (a.x[0] == b && a.x[1] >= 0.0)); -} - -/* double-double >= double-double */ -inline bool operator>=(const dd_real &a, const dd_real &b) { - return (a.x[0] > b.x[0] || (a.x[0] == b.x[0] && a.x[1] >= b.x[1])); -} - -/* double >= double-double */ -inline bool operator>=(double a, const dd_real &b) { - return (b <= a); -} - -/*********** Less-Than-Or-Equal-To Comparisons ************/ -/* double-double <= double */ -inline bool operator<=(const dd_real &a, double b) { - return (a.x[0] < b || (a.x[0] == b && a.x[1] <= 0.0)); -} - -/* double-double <= double-double */ -inline bool operator<=(const dd_real &a, const dd_real &b) { - return (a.x[0] < b.x[0] || (a.x[0] == b.x[0] && a.x[1] <= b.x[1])); -} - -/* double <= double-double */ -inline bool operator<=(double a, const dd_real &b) { - return (b >= a); -} - -/*********** Not-Equal-To Comparisons ************/ -/* double-double != double */ -inline bool operator!=(const dd_real &a, double b) { - return (a.x[0] != b || a.x[1] != 0.0); -} - -/* double-double != double-double */ -inline bool operator!=(const dd_real &a, const dd_real &b) { - return (a.x[0] != b.x[0] || a.x[1] != b.x[1]); -} - -/* double != double-double */ -inline bool operator!=(double a, const dd_real &b) { - return (a != b.x[0] || b.x[1] != 0.0); -} - -/*********** Micellaneous ************/ -/* this == 0 */ -inline bool dd_real::is_zero() const { - return (x[0] == 0.0); -} - -/* this == 1 */ -inline bool dd_real::is_one() const { - return (x[0] == 1.0 && x[1] == 0.0); -} - -/* this > 0 */ -inline bool dd_real::is_positive() const { - return (x[0] > 0.0); -} - -/* this < 0 */ -inline bool dd_real::is_negative() const { - return (x[0] < 0.0); -} - -inline dd_real::operator bool() const { - return (x[0] != 0.0); -} - -inline dd_real::operator double() const { - return to_double(*this); -} - -/* Absolute value */ -inline dd_real abs(const dd_real &a) { - return (a.x[0] < 0.0) ? -a : a; -} - -inline dd_real fabs(const dd_real &a) { - return abs(a); -} - -/* Round to Nearest integer */ -inline dd_real nint(const dd_real &a) { - double hi = qd::nint(a.x[0]); - double lo; - - if (hi == a.x[0]) { - /* High word is an integer already. Round the low word.*/ - lo = qd::nint(a.x[1]); - - /* Renormalize. This is needed if x[0] = some integer, x[1] = 1/2.*/ - hi = qd::quick_two_sum(hi, lo, lo); - } else { - /* High word is not an integer. */ - lo = 0.0; - if (std::abs(hi-a.x[0]) == 0.5 && a.x[1] < 0.0) { - /* There is a tie in the high word, consult the low word - to break the tie. */ - hi -= 1.0; /* NOTE: This does not cause INEXACT. */ - } - } - - return dd_real(hi, lo); -} - -inline dd_real floor(const dd_real &a) { - double hi = std::floor(a.x[0]); - double lo = 0.0; - - if (hi == a.x[0]) { - /* High word is integer already. Round the low word. */ - lo = std::floor(a.x[1]); - hi = qd::quick_two_sum(hi, lo, lo); - } - - return dd_real(hi, lo); -} - -inline dd_real ceil(const dd_real &a) { - double hi = std::ceil(a.x[0]); - double lo = 0.0; - - if (hi == a.x[0]) { - /* High word is integer already. Round the low word. */ - lo = std::ceil(a.x[1]); - hi = qd::quick_two_sum(hi, lo, lo); - } - - return dd_real(hi, lo); -} - -inline dd_real aint(const dd_real &a) { - return (a.x[0] >= 0.0) ? floor(a) : ceil(a); -} - -/* Cast to double. */ -inline double to_double(const dd_real &a) { - return a.x[0]; -} - -/* Cast to int. */ -inline int to_int(const dd_real &a) { - return static_cast<int>(a.x[0]); -} - -/* Random number generator */ -inline dd_real dd_real::rand() { - return ddrand(); -} - -#endif /* _QD_DD_INLINE_H */ diff --git a/src/external/PackedCSparse/qd/dd_real.cc b/src/external/PackedCSparse/qd/dd_real.cc deleted file mode 100644 index ff4d5223..00000000 --- a/src/external/PackedCSparse/qd/dd_real.cc +++ /dev/null @@ -1,1303 +0,0 @@ -/* - * src/dd_real.cc - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2007 - * - * Contains implementation of non-inlined functions of double-double - * package. Inlined functions are found in dd_inline.h (in include directory). - */ -#include <cstdlib> -#include <cstdio> -#include <cmath> -#include <cstring> -#include <iostream> -#include <iomanip> -#include <string> - -#include "qd_config.h" -#include "dd_real.h" -#include "util.h" - -#include "bits.h" - -#ifndef QD_INLINE -#include "dd_inline.h" -#endif - -using std::cout; -using std::cerr; -using std::endl; -using std::ostream; -using std::istream; -using std::ios_base; -using std::string; -using std::setw; - -/* This routine is called whenever a fatal error occurs. */ -void dd_real::error(const char *msg) { - //if (msg) { cerr << "ERROR " << msg << endl; } -} - -/* Computes the square root of the double-double number dd. - NOTE: dd must be a non-negative number. */ -QD_API dd_real sqrt(const dd_real &a) { - /* Strategy: Use Karp's trick: if x is an approximation - to sqrt(a), then - - sqrt(a) = a*x + [a - (a*x)^2] * x / 2 (approx) - - The approximation is accurate to twice the accuracy of x. - Also, the multiplication (a*x) and [-]*x can be done with - only half the precision. - */ - - if (a.is_zero()) - return 0.0; - - if (a.is_negative()) { - dd_real::error("(dd_real::sqrt): Negative argument."); - return dd_real::_nan; - } - - double x = 1.0 / std::sqrt(a.x[0]); - double ax = a.x[0] * x; - return dd_real::add(ax, (a - dd_real::sqr(ax)).x[0] * (x * 0.5)); -} - -/* Computes the square root of a double in double-double precision. - NOTE: d must not be negative. */ -dd_real dd_real::sqrt(double d) { - return ::sqrt(dd_real(d)); -} - -/* Computes the n-th root of the double-double number a. - NOTE: n must be a positive integer. - NOTE: If n is even, then a must not be negative. */ -dd_real nroot(const dd_real &a, int n) { - /* Strategy: Use Newton iteration for the function - - f(x) = x^(-n) - a - - to find its root a^{-1/n}. The iteration is thus - - x' = x + x * (1 - a * x^n) / n - - which converges quadratically. We can then find - a^{1/n} by taking the reciprocal. - */ - - if (n <= 0) { - dd_real::error("(dd_real::nroot): N must be positive."); - return dd_real::_nan; - } - - if (n%2 == 0 && a.is_negative()) { - dd_real::error("(dd_real::nroot): Negative argument."); - return dd_real::_nan; - } - - if (n == 1) { - return a; - } - if (n == 2) { - return sqrt(a); - } - - if (a.is_zero()) - return 0.0; - - /* Note a^{-1/n} = exp(-log(a)/n) */ - dd_real r = abs(a); - dd_real x = std::exp(-std::log(r.x[0]) / n); - - /* Perform Newton's iteration. */ - x += x * (1.0 - r * npwr(x, n)) / static_cast<double>(n); - if (a.x[0] < 0.0) - x = -x; - return 1.0/x; -} - -/* Computes the n-th power of a double-double number. - NOTE: 0^0 causes an error. */ -dd_real npwr(const dd_real &a, int n) { - - if (n == 0) { - if (a.is_zero()) { - dd_real::error("(dd_real::npwr): Invalid argument."); - return dd_real::_nan; - } - return 1.0; - } - - dd_real r = a; - dd_real s = 1.0; - int N = std::abs(n); - - if (N > 1) { - /* Use binary exponentiation */ - while (N > 0) { - if (N % 2 == 1) { - s *= r; - } - N /= 2; - if (N > 0) - r = sqr(r); - } - } else { - s = r; - } - - /* Compute the reciprocal if n is negative. */ - if (n < 0) - return (1.0 / s); - - return s; -} - -dd_real pow(const dd_real &a, int n) { - return npwr(a, n); -} - -dd_real pow(const dd_real &a, const dd_real &b) { - return exp(b * log(a)); -} - -static const int n_inv_fact = 15; -static const double inv_fact[n_inv_fact][2] = { - { 1.66666666666666657e-01, 9.25185853854297066e-18}, - { 4.16666666666666644e-02, 2.31296463463574266e-18}, - { 8.33333333333333322e-03, 1.15648231731787138e-19}, - { 1.38888888888888894e-03, -5.30054395437357706e-20}, - { 1.98412698412698413e-04, 1.72095582934207053e-22}, - { 2.48015873015873016e-05, 2.15119478667758816e-23}, - { 2.75573192239858925e-06, -1.85839327404647208e-22}, - { 2.75573192239858883e-07, 2.37677146222502973e-23}, - { 2.50521083854417202e-08, -1.44881407093591197e-24}, - { 2.08767569878681002e-09, -1.20734505911325997e-25}, - { 1.60590438368216133e-10, 1.25852945887520981e-26}, - { 1.14707455977297245e-11, 2.06555127528307454e-28}, - { 7.64716373181981641e-13, 7.03872877733453001e-30}, - { 4.77947733238738525e-14, 4.39920548583408126e-31}, - { 2.81145725434552060e-15, 1.65088427308614326e-31} -}; - -/* Exponential. Computes exp(x) in double-double precision. */ -dd_real exp(const dd_real &a) { - /* Strategy: We first reduce the size of x by noting that - - exp(kr + m * log(2)) = 2^m * exp(r)^k - - where m and k are integers. By choosing m appropriately - we can make |kr| <= log(2) / 2 = 0.347. Then exp(r) is - evaluated using the familiar Taylor series. Reducing the - argument substantially speeds up the convergence. */ - - const double k = 512.0; - const double inv_k = 1.0 / k; - - if (a.x[0] <= -709.0) - return 0.0; - - if (a.x[0] >= 709.0) - return dd_real::_inf; - - if (a.is_zero()) - return 1.0; - - if (a.is_one()) - return dd_real::_e; - - double m = std::floor(a.x[0] / dd_real::_log2.x[0] + 0.5); - dd_real r = mul_pwr2(a - dd_real::_log2 * m, inv_k); - dd_real s, t, p; - - p = sqr(r); - s = r + mul_pwr2(p, 0.5); - p *= r; - t = p * dd_real(inv_fact[0][0], inv_fact[0][1]); - int i = 0; - do { - s += t; - p *= r; - ++i; - t = p * dd_real(inv_fact[i][0], inv_fact[i][1]); - } while (std::abs(to_double(t)) > inv_k * dd_real::_eps && i < 5); - - s += t; - - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s += 1.0; - - return ldexp(s, static_cast<int>(m)); -} - -/* Logarithm. Computes log(x) in double-double precision. - This is a natural logarithm (i.e., base e). */ -dd_real log(const dd_real &a) { - /* Strategy. The Taylor series for log converges much more - slowly than that of exp, due to the lack of the factorial - term in the denominator. Hence this routine instead tries - to determine the root of the function - - f(x) = exp(x) - a - - using Newton iteration. The iteration is given by - - x' = x - f(x)/f'(x) - = x - (1 - a * exp(-x)) - = x + a * exp(-x) - 1. - - Only one iteration is needed, since Newton's iteration - approximately doubles the number of digits per iteration. */ - - if (a.is_one()) { - return 0.0; - } - - if (a.x[0] <= 0.0) { - dd_real::error("(dd_real::log): Non-positive argument."); - return dd_real::_nan; - } - - dd_real x = std::log(a.x[0]); /* Initial approximation */ - - x = x + a * exp(-x) - 1.0; - return x; -} - -dd_real log10(const dd_real &a) { - return log(a) / dd_real::_log10; -} - -static const dd_real _pi16 = dd_real(1.963495408493620697e-01, - 7.654042494670957545e-18); - -/* Table of sin(k * pi/16) and cos(k * pi/16). */ -static const double sin_table [4][2] = { - {1.950903220161282758e-01, -7.991079068461731263e-18}, - {3.826834323650897818e-01, -1.005077269646158761e-17}, - {5.555702330196021776e-01, 4.709410940561676821e-17}, - {7.071067811865475727e-01, -4.833646656726456726e-17} -}; - -static const double cos_table [4][2] = { - {9.807852804032304306e-01, 1.854693999782500573e-17}, - {9.238795325112867385e-01, 1.764504708433667706e-17}, - {8.314696123025452357e-01, 1.407385698472802389e-18}, - {7.071067811865475727e-01, -4.833646656726456726e-17} -}; - -/* Computes sin(a) using Taylor series. - Assumes |a| <= pi/32. */ -static dd_real sin_taylor(const dd_real &a) { - const double thresh = 0.5 * std::abs(to_double(a)) * dd_real::_eps; - dd_real r, s, t, x; - - if (a.is_zero()) { - return 0.0; - } - - int i = 0; - x = -sqr(a); - s = a; - r = a; - do { - r *= x; - t = r * dd_real(inv_fact[i][0], inv_fact[i][1]); - s += t; - i += 2; - } while (i < n_inv_fact && std::abs(to_double(t)) > thresh); - - return s; -} - -static dd_real cos_taylor(const dd_real &a) { - const double thresh = 0.5 * dd_real::_eps; - dd_real r, s, t, x; - - if (a.is_zero()) { - return 1.0; - } - - x = -sqr(a); - r = x; - s = 1.0 + mul_pwr2(r, 0.5); - int i = 1; - do { - r *= x; - t = r * dd_real(inv_fact[i][0], inv_fact[i][1]); - s += t; - i += 2; - } while (i < n_inv_fact && std::abs(to_double(t)) > thresh); - - return s; -} - -static void sincos_taylor(const dd_real &a, - dd_real &sin_a, dd_real &cos_a) { - if (a.is_zero()) { - sin_a = 0.0; - cos_a = 1.0; - return; - } - - sin_a = sin_taylor(a); - cos_a = sqrt(1.0 - sqr(sin_a)); -} - - -dd_real sin(const dd_real &a) { - - /* Strategy. To compute sin(x), we choose integers a, b so that - - x = s + a * (pi/2) + b * (pi/16) - - and |s| <= pi/32. Using the fact that - - sin(pi/16) = 0.5 * sqrt(2 - sqrt(2 + sqrt(2))) - - we can compute sin(x) from sin(s), cos(s). This greatly - increases the convergence of the sine Taylor series. */ - - if (a.is_zero()) { - return 0.0; - } - - // approximately reduce modulo 2*pi - dd_real z = nint(a / dd_real::_2pi); - dd_real r = a - dd_real::_2pi * z; - - // approximately reduce modulo pi/2 and then modulo pi/16. - dd_real t; - double q = std::floor(r.x[0] / dd_real::_pi2.x[0] + 0.5); - t = r - dd_real::_pi2 * q; - int j = static_cast<int>(q); - q = std::floor(t.x[0] / _pi16.x[0] + 0.5); - t -= _pi16 * q; - int k = static_cast<int>(q); - int abs_k = std::abs(k); - - if (j < -2 || j > 2) { - dd_real::error("(dd_real::sin): Cannot reduce modulo pi/2."); - return dd_real::_nan; - } - - if (abs_k > 4) { - dd_real::error("(dd_real::sin): Cannot reduce modulo pi/16."); - return dd_real::_nan; - } - - if (k == 0) { - switch (j) { - case 0: - return sin_taylor(t); - case 1: - return cos_taylor(t); - case -1: - return -cos_taylor(t); - default: - return -sin_taylor(t); - } - } - - dd_real u(cos_table[abs_k-1][0], cos_table[abs_k-1][1]); - dd_real v(sin_table[abs_k-1][0], sin_table[abs_k-1][1]); - dd_real sin_t, cos_t; - sincos_taylor(t, sin_t, cos_t); - if (j == 0) { - if (k > 0) { - r = u * sin_t + v * cos_t; - } else { - r = u * sin_t - v * cos_t; - } - } else if (j == 1) { - if (k > 0) { - r = u * cos_t - v * sin_t; - } else { - r = u * cos_t + v * sin_t; - } - } else if (j == -1) { - if (k > 0) { - r = v * sin_t - u * cos_t; - } else if (k < 0) { - r = -u * cos_t - v * sin_t; - } - } else { - if (k > 0) { - r = -u * sin_t - v * cos_t; - } else { - r = v * cos_t - u * sin_t; - } - } - - return r; -} - -dd_real cos(const dd_real &a) { - - if (a.is_zero()) { - return 1.0; - } - - // approximately reduce modulo 2*pi - dd_real z = nint(a / dd_real::_2pi); - dd_real r = a - z * dd_real::_2pi; - - // approximately reduce modulo pi/2 and then modulo pi/16 - dd_real t; - double q = std::floor(r.x[0] / dd_real::_pi2.x[0] + 0.5); - t = r - dd_real::_pi2 * q; - int j = static_cast<int>(q); - q = std::floor(t.x[0] / _pi16.x[0] + 0.5); - t -= _pi16 * q; - int k = static_cast<int>(q); - int abs_k = std::abs(k); - - if (j < -2 || j > 2) { - dd_real::error("(dd_real::cos): Cannot reduce modulo pi/2."); - return dd_real::_nan; - } - - if (abs_k > 4) { - dd_real::error("(dd_real::cos): Cannot reduce modulo pi/16."); - return dd_real::_nan; - } - - if (k == 0) { - switch (j) { - case 0: - return cos_taylor(t); - case 1: - return -sin_taylor(t); - case -1: - return sin_taylor(t); - default: - return -cos_taylor(t); - } - } - - dd_real sin_t, cos_t; - sincos_taylor(t, sin_t, cos_t); - dd_real u(cos_table[abs_k-1][0], cos_table[abs_k-1][1]); - dd_real v(sin_table[abs_k-1][0], sin_table[abs_k-1][1]); - - if (j == 0) { - if (k > 0) { - r = u * cos_t - v * sin_t; - } else { - r = u * cos_t + v * sin_t; - } - } else if (j == 1) { - if (k > 0) { - r = - u * sin_t - v * cos_t; - } else { - r = v * cos_t - u * sin_t; - } - } else if (j == -1) { - if (k > 0) { - r = u * sin_t + v * cos_t; - } else { - r = u * sin_t - v * cos_t; - } - } else { - if (k > 0) { - r = v * sin_t - u * cos_t; - } else { - r = - u * cos_t - v * sin_t; - } - } - - return r; -} - -void sincos(const dd_real &a, dd_real &sin_a, dd_real &cos_a) { - - if (a.is_zero()) { - sin_a = 0.0; - cos_a = 1.0; - return; - } - - // approximately reduce modulo 2*pi - dd_real z = nint(a / dd_real::_2pi); - dd_real r = a - dd_real::_2pi * z; - - // approximately reduce module pi/2 and pi/16 - dd_real t; - double q = std::floor(r.x[0] / dd_real::_pi2.x[0] + 0.5); - t = r - dd_real::_pi2 * q; - int j = static_cast<int>(q); - int abs_j = std::abs(j); - q = std::floor(t.x[0] / _pi16.x[0] + 0.5); - t -= _pi16 * q; - int k = static_cast<int>(q); - int abs_k = std::abs(k); - - if (abs_j > 2) { - dd_real::error("(dd_real::sincos): Cannot reduce modulo pi/2."); - cos_a = sin_a = dd_real::_nan; - return; - } - - if (abs_k > 4) { - dd_real::error("(dd_real::sincos): Cannot reduce modulo pi/16."); - cos_a = sin_a = dd_real::_nan; - return; - } - - dd_real sin_t, cos_t; - dd_real s, c; - - sincos_taylor(t, sin_t, cos_t); - - if (abs_k == 0) { - s = sin_t; - c = cos_t; - } else { - dd_real u(cos_table[abs_k-1][0], cos_table[abs_k-1][1]); - dd_real v(sin_table[abs_k-1][0], sin_table[abs_k-1][1]); - - if (k > 0) { - s = u * sin_t + v * cos_t; - c = u * cos_t - v * sin_t; - } else { - s = u * sin_t - v * cos_t; - c = u * cos_t + v * sin_t; - } - } - - if (abs_j == 0) { - sin_a = s; - cos_a = c; - } else if (j == 1) { - sin_a = c; - cos_a = -s; - } else if (j == -1) { - sin_a = -c; - cos_a = s; - } else { - sin_a = -s; - cos_a = -c; - } - -} - -dd_real atan(const dd_real &a) { - return atan2(a, dd_real(1.0)); -} - -dd_real atan2(const dd_real &y, const dd_real &x) { - /* Strategy: Instead of using Taylor series to compute - arctan, we instead use Newton's iteration to solve - the equation - - sin(z) = y/r or cos(z) = x/r - - where r = sqrt(x^2 + y^2). - The iteration is given by - - z' = z + (y - sin(z)) / cos(z) (for equation 1) - z' = z - (x - cos(z)) / sin(z) (for equation 2) - - Here, x and y are normalized so that x^2 + y^2 = 1. - If |x| > |y|, then first iteration is used since the - denominator is larger. Otherwise, the second is used. - */ - - if (x.is_zero()) { - - if (y.is_zero()) { - /* Both x and y is zero. */ - dd_real::error("(dd_real::atan2): Both arguments zero."); - return dd_real::_nan; - } - - return (y.is_positive()) ? dd_real::_pi2 : -dd_real::_pi2; - } else if (y.is_zero()) { - return (x.is_positive()) ? dd_real(0.0) : dd_real::_pi; - } - - if (x == y) { - return (y.is_positive()) ? dd_real::_pi4 : -dd_real::_3pi4; - } - - if (x == -y) { - return (y.is_positive()) ? dd_real::_3pi4 : -dd_real::_pi4; - } - - dd_real r = sqrt(sqr(x) + sqr(y)); - dd_real xx = x / r; - dd_real yy = y / r; - - /* Compute double precision approximation to atan. */ - dd_real z = std::atan2(to_double(y), to_double(x)); - dd_real sin_z, cos_z; - - if (std::abs(xx.x[0]) > std::abs(yy.x[0])) { - /* Use Newton iteration 1. z' = z + (y - sin(z)) / cos(z) */ - sincos(z, sin_z, cos_z); - z += (yy - sin_z) / cos_z; - } else { - /* Use Newton iteration 2. z' = z - (x - cos(z)) / sin(z) */ - sincos(z, sin_z, cos_z); - z -= (xx - cos_z) / sin_z; - } - - return z; -} - -dd_real tan(const dd_real &a) { - dd_real s, c; - sincos(a, s, c); - return s/c; -} - -dd_real asin(const dd_real &a) { - dd_real abs_a = abs(a); - - if (abs_a > 1.0) { - dd_real::error("(dd_real::asin): Argument out of domain."); - return dd_real::_nan; - } - - if (abs_a.is_one()) { - return (a.is_positive()) ? dd_real::_pi2 : -dd_real::_pi2; - } - - return atan2(a, sqrt(1.0 - sqr(a))); -} - -dd_real acos(const dd_real &a) { - dd_real abs_a = abs(a); - - if (abs_a > 1.0) { - dd_real::error("(dd_real::acos): Argument out of domain."); - return dd_real::_nan; - } - - if (abs_a.is_one()) { - return (a.is_positive()) ? dd_real(0.0) : dd_real::_pi; - } - - return atan2(sqrt(1.0 - sqr(a)), a); -} - -dd_real sinh(const dd_real &a) { - if (a.is_zero()) { - return 0.0; - } - - if (abs(a) > 0.05) { - dd_real ea = exp(a); - return mul_pwr2(ea - inv(ea), 0.5); - } - - /* since a is small, using the above formula gives - a lot of cancellation. So use Taylor series. */ - dd_real s = a; - dd_real t = a; - dd_real r = sqr(t); - double m = 1.0; - double thresh = std::abs((to_double(a)) * dd_real::_eps); - - do { - m += 2.0; - t *= r; - t /= (m-1) * m; - - s += t; - } while (abs(t) > thresh); - - return s; - -} - -dd_real cosh(const dd_real &a) { - if (a.is_zero()) { - return 1.0; - } - - dd_real ea = exp(a); - return mul_pwr2(ea + inv(ea), 0.5); -} - -dd_real tanh(const dd_real &a) { - if (a.is_zero()) { - return 0.0; - } - - if (std::abs(to_double(a)) > 0.05) { - dd_real ea = exp(a); - dd_real inv_ea = inv(ea); - return (ea - inv_ea) / (ea + inv_ea); - } else { - dd_real s, c; - s = sinh(a); - c = sqrt(1.0 + sqr(s)); - return s / c; - } -} - -void sincosh(const dd_real &a, dd_real &s, dd_real &c) { - if (std::abs(to_double(a)) <= 0.05) { - s = sinh(a); - c = sqrt(1.0 + sqr(s)); - } else { - dd_real ea = exp(a); - dd_real inv_ea = inv(ea); - s = mul_pwr2(ea - inv_ea, 0.5); - c = mul_pwr2(ea + inv_ea, 0.5); - } -} - -dd_real asinh(const dd_real &a) { - return log(a + sqrt(sqr(a) + 1.0)); -} - -dd_real acosh(const dd_real &a) { - if (a < 1.0) { - dd_real::error("(dd_real::acosh): Argument out of domain."); - return dd_real::_nan; - } - - return log(a + sqrt(sqr(a) - 1.0)); -} - -dd_real atanh(const dd_real &a) { - if (abs(a) >= 1.0) { - dd_real::error("(dd_real::atanh): Argument out of domain."); - return dd_real::_nan; - } - - return mul_pwr2(log((1.0 + a) / (1.0 - a)), 0.5); -} - -QD_API dd_real fmod(const dd_real &a, const dd_real &b) { - dd_real n = aint(a / b); - return (a - b * n); -} - -QD_API dd_real ddrand() { - static const double m_const = 4.6566128730773926e-10; /* = 2^{-31} */ - double m = m_const; - dd_real r = 0.0; - double d; - - /* Strategy: Generate 31 bits at a time, using lrand48 - random number generator. Shift the bits, and reapeat - 4 times. */ - - for (int i = 0; i < 4; i++, m *= m_const) { -// d = lrand48() * m; - d = std::rand() * m; - r += d; - } - - return r; -} - -/* polyeval(c, n, x) - Evaluates the given n-th degree polynomial at x. - The polynomial is given by the array of (n+1) coefficients. */ -dd_real polyeval(const dd_real *c, int n, const dd_real &x) { - /* Just use Horner's method of polynomial evaluation. */ - dd_real r = c[n]; - - for (int i = n-1; i >= 0; i--) { - r *= x; - r += c[i]; - } - - return r; -} - -/* polyroot(c, n, x0) - Given an n-th degree polynomial, finds a root close to - the given guess x0. Note that this uses simple Newton - iteration scheme, and does not work for multiple roots. */ -QD_API dd_real polyroot(const dd_real *c, int n, - const dd_real &x0, int max_iter, double thresh) { - dd_real x = x0; - dd_real f; - dd_real *d = new dd_real[n]; - bool conv = false; - int i; - double max_c = std::abs(to_double(c[0])); - double v; - - if (thresh == 0.0) thresh = dd_real::_eps; - - /* Compute the coefficients of the derivatives. */ - for (i = 1; i <= n; i++) { - v = std::abs(to_double(c[i])); - if (v > max_c) max_c = v; - d[i-1] = c[i] * static_cast<double>(i); - } - thresh *= max_c; - - /* Newton iteration. */ - for (i = 0; i < max_iter; i++) { - f = polyeval(c, n, x); - - if (abs(f) < thresh) { - conv = true; - break; - } - x -= (f / polyeval(d, n-1, x)); - } - delete [] d; - - if (!conv) { - dd_real::error("(dd_real::polyroot): Failed to converge."); - return dd_real::_nan; - } - - return x; -} - - -/* Constructor. Reads a double-double number from the string s - and constructs a double-double number. */ -dd_real::dd_real(const char *s) { - if (dd_real::read(s, *this)) { - dd_real::error("(dd_real::dd_real): INPUT ERROR."); - *this = dd_real::_nan; - } -} - -dd_real &dd_real::operator=(const char *s) { - if (dd_real::read(s, *this)) { - dd_real::error("(dd_real::operator=): INPUT ERROR."); - *this = dd_real::_nan; - } - return *this; -} - -/* Outputs the double-double number dd. */ -ostream &operator<<(ostream &os, const dd_real &dd) { - bool showpos = (os.flags() & ios_base::showpos) != 0; - bool uppercase = (os.flags() & ios_base::uppercase) != 0; - return os << dd.to_string((int)os.precision(), (int)os.width(), os.flags(), - showpos, uppercase, os.fill()); -} - -/* Reads in the double-double number a. */ -istream &operator>>(istream &s, dd_real &a) { - char str[255]; - s >> str; - a = dd_real(str); - return s; -} - -void dd_real::to_digits(char *s, int &expn, int precision) const { - int D = precision + 1; /* number of digits to compute */ - - dd_real r = abs(*this); - int e; /* exponent */ - int i, d; - - if (x[0] == 0.0) { - /* this == 0.0 */ - expn = 0; - for (i = 0; i < precision; i++) s[i] = '0'; - return; - } - - /* First determine the (approximate) exponent. */ - e = to_int(std::floor(std::log10(std::abs(x[0])))); - - if (e < -300) { - r *= dd_real(10.0) ^ 300; - r /= dd_real(10.0) ^ (e + 300); - } else if (e > 300) { - r = ldexp(r, -53); - r /= dd_real(10.0) ^ e; - r = ldexp(r, 53); - } else { - r /= dd_real(10.0) ^ e; - } - - /* Fix exponent if we are off by one */ - if (r >= 10.0) { - r /= 10.0; - e++; - } else if (r < 1.0) { - r *= 10.0; - e--; - } - - if (r >= 10.0 || r < 1.0) { - dd_real::error("(dd_real::to_digits): can't compute exponent."); - return; - } - - /* Extract the digits */ - for (i = 0; i < D; i++) { - d = static_cast<int>(r.x[0]); - r -= d; - r *= 10.0; - - s[i] = static_cast<char>(d + '0'); - } - - /* Fix out of range digits. */ - for (i = D-1; i > 0; i--) { - if (s[i] < '0') { - s[i-1]--; - s[i] += 10; - } else if (s[i] > '9') { - s[i-1]++; - s[i] -= 10; - } - } - - if (s[0] <= '0') { - dd_real::error("(dd_real::to_digits): non-positive leading digit."); - return; - } - - /* Round, handle carry */ - if (s[D-1] >= '5') { - s[D-2]++; - - i = D-2; - while (i > 0 && s[i] > '9') { - s[i] -= 10; - s[--i]++; - } - } - - /* If first digit is 10, shift everything. */ - if (s[0] > '9') { - e++; - for (i = precision; i >= 2; i--) s[i] = s[i-1]; - s[0] = '1'; - s[1] = '0'; - } - - s[precision] = 0; - expn = e; -} - -/* Writes the double-double number into the character array s of length len. - The integer d specifies how many significant digits to write. - The string s must be able to hold at least (d+8) characters. - showpos indicates whether to use the + sign, and uppercase indicates - whether the E or e is to be used for the exponent. */ -void dd_real::write(char *s, int len, int precision, - bool showpos, bool uppercase) const { - string str = to_string(precision, 0, ios_base::scientific, showpos, uppercase); - std::strncpy(s, str.c_str(), len-1); - s[len-1] = 0; -} - - -void round_string(char *s, int precision, int *offset){ - /* - Input string must be all digits or errors will occur. - */ - - int i; - int D = precision ; - - /* Round, handle carry */ - if (D>0 && s[D] >= '5') { - s[D-1]++; - - i = D-1; - while (i > 0 && s[i] > '9') { - s[i] -= 10; - s[--i]++; - } - } - - /* If first digit is 10, shift everything. */ - if (s[0] > '9') { - // e++; // don't modify exponent here - for (i = precision; i >= 1; i--) s[i+1] = s[i]; - s[0] = '1'; - s[1] = '0'; - - (*offset)++ ; // now offset needs to be increased by one - precision++ ; - } - - s[precision] = 0; // add terminator for array -} - -string dd_real::to_string(int precision, int width, ios_base::fmtflags fmt, - bool showpos, bool uppercase, char fill) const { - string s; - bool fixed = (fmt & ios_base::fixed) != 0; - bool sgn = true; - int i, e = 0; - - if (isnan()) { - s = uppercase ? "NAN" : "nan"; - sgn = false; - } else { - if (*this < 0.0) - s += '-'; - else if (showpos) - s += '+'; - else - sgn = false; - - if (isinf()) { - s += uppercase ? "INF" : "inf"; - } else if (*this == 0.0) { - /* Zero case */ - s += '0'; - if (precision > 0) { - s += '.'; - s.append(precision, '0'); - } - } else { - /* Non-zero case */ - int off = (fixed ? (1 + to_int(floor(log10(abs(*this))))) : 1); - int d = precision + off; - - int d_with_extra = d; - if(fixed) - d_with_extra = std::max(60, d); // longer than the max accuracy for DD - - // highly special case - fixed mode, precision is zero, abs(*this) < 1.0 - // without this trap a number like 0.9 printed fixed with 0 precision prints as 0 - // should be rounded to 1. - if(fixed && (precision == 0) && (abs(*this) < 1.0)){ - if(abs(*this) >= 0.5) - s += '1'; - else - s += '0'; - - return s; - } - - // handle near zero to working precision (but not exactly zero) - if (fixed && d <= 0) { - s += '0'; - if (precision > 0) { - s += '.'; - s.append(precision, '0'); - } - } else { // default - - char *t; // = new char[d+1]; - int j; - - if(fixed){ - t = new char[d_with_extra+1]; - to_digits(t, e, d_with_extra); - } - else{ - t = new char[d+1]; - to_digits(t, e, d); - } - - off = e + 1; - - if (fixed) { - // fix the string if it's been computed incorrectly - // round here in the decimal string if required - round_string(t, d, &off); - - if (off > 0) { - for (i = 0; i < off; i++) s += t[i]; - if (precision > 0) { - s += '.'; - for (j = 0; j < precision; j++, i++) s += t[i]; - } - } else { - s += "0."; - if (off < 0) s.append(-off, '0'); - for (i = 0; i < d; i++) s += t[i]; - } - } else { - s += t[0]; - if (precision > 0) s += '.'; - - for (i = 1; i <= precision; i++) - s += t[i]; - - } - delete [] t; - } - } - - // trap for improper offset with large values - // without this trap, output of values of the for 10^j - 1 fail for j > 28 - // and are output with the point in the wrong place, leading to a dramatically off value - if(fixed && (precision > 0)){ - // make sure that the value isn't dramatically larger - double from_string = atof(s.c_str()); - - // if this ratio is large, then we've got problems - if( fabs( from_string / this->x[0] ) > 3.0 ){ - - // loop on the string, find the point, move it up one - // don't act on the first character - for(i=1; i < (int)s.length(); i++){ - if(s[i] == '.'){ - s[i] = s[i-1] ; - s[i-1] = '.' ; - break; - } - } - - from_string = atof(s.c_str()); - // if this ratio is large, then the string has not been fixed - if( fabs( from_string / this->x[0] ) > 3.0 ){ - dd_real::error("Re-rounding unsuccessful in large number fixed point trap.") ; - } - } - } - - - if (!fixed && !isinf()) { - /* Fill in exponent part */ - s += uppercase ? 'E' : 'e'; - append_expn(s, e); - } - } - - /* Fill in the blanks */ - int len = s.length(); - if (len < width) { - int delta = width - len; - if (fmt & ios_base::internal) { - if (sgn) - s.insert(static_cast<string::size_type>(1), delta, fill); - else - s.insert(static_cast<string::size_type>(0), delta, fill); - } else if (fmt & ios_base::left) { - s.append(delta, fill); - } else { - s.insert(static_cast<string::size_type>(0), delta, fill); - } - } - - return s; -} - -/* Reads in a double-double number from the string s. */ -int dd_real::read(const char *s, dd_real &a) { - const char *p = s; - char ch; - int sign = 0; - int point = -1; - int nd = 0; - int e = 0; - bool done = false; - dd_real r = 0.0; - int nread; - - /* Skip any leading spaces */ - while (*p == ' ') - p++; - - while (!done && (ch = *p) != '\0') { - if (ch >= '0' && ch <= '9') { - int d = ch - '0'; - r *= 10.0; - r += static_cast<double>(d); - nd++; - } else { - - switch (ch) { - - case '.': - if (point >= 0) - return -1; - point = nd; - break; - - case '-': - case '+': - if (sign != 0 || nd > 0) - return -1; - sign = (ch == '-') ? -1 : 1; - break; - - case 'E': - case 'e': - nread = std::sscanf(p+1, "%d", &e); - done = true; - if (nread != 1) - return -1; - break; - - default: - return -1; - } - } - - p++; - } - - if (point >= 0) { - e -= (nd - point); - } - - if (e != 0) { - r *= (dd_real(10.0) ^ e); - } - - a = (sign == -1) ? -r : r; - return 0; -} - -/* Debugging routines */ -void dd_real::dump(const string &name, std::ostream &os) const { - std::ios_base::fmtflags old_flags = os.flags(); - std::streamsize old_prec = os.precision(19); - os << std::scientific; - - if (name.length() > 0) os << name << " = "; - os << "[ " << setw(27) << x[0] << ", " << setw(27) << x[1] << " ]" << endl; - - os.precision(old_prec); - os.flags(old_flags); -} - -void dd_real::dump_bits(const string &name, std::ostream &os) const { - string::size_type len = name.length(); - if (len > 0) { - os << name << " = "; - len +=3; - } - os << "[ "; - len += 2; - print_double_info(os, x[0]); - os << endl; - for (string::size_type i = 0; i < len; i++) os << ' '; - print_double_info(os, x[1]); - os << " ]" << endl; -} - -dd_real dd_real::debug_rand() { - - if (std::rand() % 2 == 0) - return ddrand(); - - int expn = 0; - dd_real a = 0.0; - double d; - for (int i = 0; i < 2; i++) { - d = std::ldexp(static_cast<double>(std::rand()) / RAND_MAX, -expn); - a += d; - expn = expn + 54 + std::rand() % 200; - } - return a; -} diff --git a/src/external/PackedCSparse/qd/dd_real.h b/src/external/PackedCSparse/qd/dd_real.h deleted file mode 100644 index e16438aa..00000000 --- a/src/external/PackedCSparse/qd/dd_real.h +++ /dev/null @@ -1,293 +0,0 @@ -/* - * include/dd_real.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2007 - * - * Double-double precision (>= 106-bit significand) floating point - * arithmetic package based on David Bailey's Fortran-90 double-double - * package, with some changes. See - * - * http://www.nersc.gov/~dhbailey/mpdist/mpdist.html - * - * for the original Fortran-90 version. - * - * Overall structure is similar to that of Keith Brigg's C++ double-double - * package. See - * - * http://www-epidem.plansci.cam.ac.uk/~kbriggs/doubledouble.html - * - * for more details. In particular, the fix for x86 computers is borrowed - * from his code. - * - * Yozo Hida - */ - -#ifndef _QD_DD_REAL_H -#define _QD_DD_REAL_H - -#include <cmath> -#include <iostream> -#include <string> -#include <limits> -#include "qd_config.h" -#include "fpu.h" - -// Some compilers define isnan, isfinite, and isinf as macros, even for -// C++ codes, which cause havoc when overloading these functions. We undef -// them here. -#ifdef isnan -#undef isnan -#endif - -#ifdef isfinite -#undef isfinite -#endif - -#ifdef isinf -#undef isinf -#endif - -#ifdef max -#undef max -#endif - -#ifdef min -#undef min -#endif - -struct QD_API dd_real { - double x[2]; - - dd_real(double hi, double lo) { x[0] = hi; x[1] = lo; } - dd_real() {x[0] = 0.0; x[1] = 0.0; } - dd_real(double h) { x[0] = h; x[1] = 0.0; } - dd_real(int h) { - x[0] = (static_cast<double>(h)); - x[1] = 0.0; - } - - dd_real (const char *s); - explicit dd_real (const double *d) { - x[0] = d[0]; x[1] = d[1]; - } - - static void error(const char *msg); - - double _hi() const { return x[0]; } - double _lo() const { return x[1]; } - - static const dd_real _2pi; - static const dd_real _pi; - static const dd_real _3pi4; - static const dd_real _pi2; - static const dd_real _pi4; - static const dd_real _e; - static const dd_real _log2; - static const dd_real _log10; - static const dd_real _nan; - static const dd_real _inf; - - static const double _eps; - static const double _min_normalized; - static const dd_real _max; - static const dd_real _safe_max; - static const int _ndigits; - - bool isnan() const { return QD_ISNAN(x[0]) || QD_ISNAN(x[1]); } - bool isfinite() const { return QD_ISFINITE(x[0]); } - bool isinf() const { return QD_ISINF(x[0]); } - - static dd_real add(double a, double b); - static dd_real ieee_add(const dd_real &a, const dd_real &b); - static dd_real sloppy_add(const dd_real &a, const dd_real &b); - - dd_real &operator+=(double a); - dd_real &operator+=(const dd_real &a); - - static dd_real sub(double a, double b); - - dd_real &operator-=(double a); - dd_real &operator-=(const dd_real &a); - - dd_real operator-() const; - - static dd_real mul(double a, double b); - - dd_real &operator*=(double a); - dd_real &operator*=(const dd_real &a); - - static dd_real div(double a, double b); - static dd_real sloppy_div(const dd_real &a, const dd_real &b); - static dd_real accurate_div(const dd_real &a, const dd_real &b); - - dd_real &operator/=(double a); - dd_real &operator/=(const dd_real &a); - - dd_real &operator=(double a); - dd_real &operator=(const char *s); - - dd_real operator^(int n); - static dd_real sqr(double d); - - static dd_real sqrt(double a); - - bool is_zero() const; - bool is_one() const; - bool is_positive() const; - bool is_negative() const; - - explicit operator bool() const; // new - explicit operator double() const; // new - - static dd_real rand(void); - - void to_digits(char *s, int &expn, int precision = _ndigits) const; - void write(char *s, int len, int precision = _ndigits, - bool showpos = false, bool uppercase = false) const; - std::string to_string(int precision = _ndigits, int width = 0, - std::ios_base::fmtflags fmt = static_cast<std::ios_base::fmtflags>(0), - bool showpos = false, bool uppercase = false, char fill = ' ') const; - int read(const char *s, dd_real &a); - - /* Debugging Methods */ - void dump(const std::string &name, std::ostream &os = std::cerr) const; - void dump_bits(const std::string &name, - std::ostream &os = std::cerr) const; - - static dd_real debug_rand(); -}; - - -namespace std { - template <> - class numeric_limits<dd_real> : public numeric_limits<double> { - public: - inline static double epsilon() { return dd_real::_eps; } - inline static dd_real max() { return dd_real::_max; } - inline static dd_real safe_max() { return dd_real::_safe_max; } - inline static double min() { return dd_real::_min_normalized; } - static const int digits = 104; - static const int digits10 = 31; - }; -} - -QD_API dd_real ddrand(void); -QD_API dd_real sqrt(const dd_real &a); - -QD_API dd_real polyeval(const dd_real *c, int n, const dd_real &x); -QD_API dd_real polyroot(const dd_real *c, int n, - const dd_real &x0, int max_iter = 32, double thresh = 0.0); - -QD_API inline bool isnan(const dd_real &a) { return a.isnan(); } -QD_API inline bool isfinite(const dd_real &a) { return a.isfinite(); } -QD_API inline bool isinf(const dd_real &a) { return a.isinf(); } - -/* Computes dd * d where d is known to be a power of 2. */ -QD_API dd_real mul_pwr2(const dd_real &dd, double d); - -QD_API dd_real operator+(const dd_real &a, double b); -QD_API dd_real operator+(double a, const dd_real &b); -QD_API dd_real operator+(const dd_real &a, const dd_real &b); - -QD_API dd_real operator-(const dd_real &a, double b); -QD_API dd_real operator-(double a, const dd_real &b); -QD_API dd_real operator-(const dd_real &a, const dd_real &b); - -QD_API dd_real operator*(const dd_real &a, double b); -QD_API dd_real operator*(double a, const dd_real &b); -QD_API dd_real operator*(const dd_real &a, const dd_real &b); - -QD_API dd_real operator/(const dd_real &a, double b); -QD_API dd_real operator/(double a, const dd_real &b); -QD_API dd_real operator/(const dd_real &a, const dd_real &b); - -QD_API dd_real inv(const dd_real &a); - -QD_API dd_real rem(const dd_real &a, const dd_real &b); -QD_API dd_real drem(const dd_real &a, const dd_real &b); -QD_API dd_real divrem(const dd_real &a, const dd_real &b, dd_real &r); - -QD_API dd_real pow(const dd_real &a, int n); -QD_API dd_real pow(const dd_real &a, const dd_real &b); -QD_API dd_real npwr(const dd_real &a, int n); -QD_API dd_real sqr(const dd_real &a); - -QD_API dd_real sqrt(const dd_real &a); -QD_API dd_real nroot(const dd_real &a, int n); - -QD_API bool operator==(const dd_real &a, double b); -QD_API bool operator==(double a, const dd_real &b); -QD_API bool operator==(const dd_real &a, const dd_real &b); - -QD_API bool operator<=(const dd_real &a, double b); -QD_API bool operator<=(double a, const dd_real &b); -QD_API bool operator<=(const dd_real &a, const dd_real &b); - -QD_API bool operator>=(const dd_real &a, double b); -QD_API bool operator>=(double a, const dd_real &b); -QD_API bool operator>=(const dd_real &a, const dd_real &b); - -QD_API bool operator<(const dd_real &a, double b); -QD_API bool operator<(double a, const dd_real &b); -QD_API bool operator<(const dd_real &a, const dd_real &b); - -QD_API bool operator>(const dd_real &a, double b); -QD_API bool operator>(double a, const dd_real &b); -QD_API bool operator>(const dd_real &a, const dd_real &b); - -QD_API bool operator!=(const dd_real &a, double b); -QD_API bool operator!=(double a, const dd_real &b); -QD_API bool operator!=(const dd_real &a, const dd_real &b); - -QD_API dd_real nint(const dd_real &a); -QD_API dd_real floor(const dd_real &a); -QD_API dd_real ceil(const dd_real &a); -QD_API dd_real aint(const dd_real &a); - -QD_API dd_real ddrand(void); - -double to_double(const dd_real &a); -int to_int(const dd_real &a); - -QD_API dd_real exp(const dd_real &a); -QD_API dd_real ldexp(const dd_real &a, int exp); -QD_API dd_real log(const dd_real &a); -QD_API dd_real log10(const dd_real &a); - -QD_API dd_real sin(const dd_real &a); -QD_API dd_real cos(const dd_real &a); -QD_API dd_real tan(const dd_real &a); -QD_API void sincos(const dd_real &a, dd_real &sin_a, dd_real &cos_a); - -QD_API dd_real asin(const dd_real &a); -QD_API dd_real acos(const dd_real &a); -QD_API dd_real atan(const dd_real &a); -QD_API dd_real atan2(const dd_real &y, const dd_real &x); - -QD_API dd_real sinh(const dd_real &a); -QD_API dd_real cosh(const dd_real &a); -QD_API dd_real tanh(const dd_real &a); -QD_API void sincosh(const dd_real &a, - dd_real &sinh_a, dd_real &cosh_a); - -QD_API dd_real asinh(const dd_real &a); -QD_API dd_real acosh(const dd_real &a); -QD_API dd_real atanh(const dd_real &a); - -QD_API dd_real fabs(const dd_real &a); -QD_API dd_real abs(const dd_real &a); /* same as fabs */ - -QD_API dd_real fmod(const dd_real &a, const dd_real &b); - -QD_API std::ostream& operator<<(std::ostream &s, const dd_real &a); -QD_API std::istream& operator>>(std::istream &s, dd_real &a); -#ifdef QD_INLINE -#include "dd_inline.h" -#endif - -#endif /* _QD_DD_REAL_H */ - diff --git a/src/external/PackedCSparse/qd/fpu.cc b/src/external/PackedCSparse/qd/fpu.cc deleted file mode 100644 index 96ddc488..00000000 --- a/src/external/PackedCSparse/qd/fpu.cc +++ /dev/null @@ -1,124 +0,0 @@ -/* - * src/fpu.cc - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Contains functions to set and restore the round-to-double flag in the - * control word of a x86 FPU. - */ - -#include "qd_config.h" -#include "fpu.h" - -#ifdef X86 -#ifdef _WIN32 -#include <float.h> -#else - -#ifdef HAVE_FPU_CONTROL_H -#include <fpu_control.h> -#endif - -#ifndef _FPU_GETCW -#define _FPU_GETCW(x) asm volatile ("fnstcw %0":"=m" (x)); -#endif - -#ifndef _FPU_SETCW -#define _FPU_SETCW(x) asm volatile ("fldcw %0": :"m" (x)); -#endif - -#ifndef _FPU_EXTENDED -#define _FPU_EXTENDED 0x0300 -#endif - -#ifndef _FPU_DOUBLE -#define _FPU_DOUBLE 0x0200 -#endif - -#endif -#endif /* X86 */ - -extern "C" { - -void fpu_fix_start(unsigned int *old_cw) { -#ifdef X86 -#ifdef _WIN32 -#ifdef __BORLANDC__ - /* Win 32 Borland C */ - unsigned short cw = _control87(0, 0); - _control87(0x0200, 0x0300); - if (old_cw) { - *old_cw = cw; - } -#else - /* Win 32 MSVC */ - unsigned int cw = _control87(0, 0); - _control87(0x00010000, 0x00030000); - if (old_cw) { - *old_cw = cw; - } -#endif -#else - /* Linux */ - volatile unsigned short cw, new_cw; - _FPU_GETCW(cw); - - new_cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE; - _FPU_SETCW(new_cw); - - if (old_cw) { - *old_cw = cw; - } -#endif -#endif -} - -void fpu_fix_end(unsigned int *old_cw) { -#ifdef X86 -#ifdef _WIN32 - -#ifdef __BORLANDC__ - /* Win 32 Borland C */ - if (old_cw) { - unsigned short cw = (unsigned short) *old_cw; - _control87(cw, 0xFFFF); - } -#else - /* Win 32 MSVC */ - if (old_cw) { - _control87(*old_cw, 0xFFFFFFFF); - } -#endif - -#else - /* Linux */ - if (old_cw) { - int cw; - cw = *old_cw; - _FPU_SETCW(cw); - } -#endif -#endif -} - -#ifdef HAVE_FORTRAN - -#define f_fpu_fix_start FC_FUNC_(f_fpu_fix_start, F_FPU_FIX_START) -#define f_fpu_fix_end FC_FUNC_(f_fpu_fix_end, F_FPU_FIX_END) - -void f_fpu_fix_start(unsigned int *old_cw) { - fpu_fix_start(old_cw); -} - -void f_fpu_fix_end(unsigned int *old_cw) { - fpu_fix_end(old_cw); -} - -#endif - -} - diff --git a/src/external/PackedCSparse/qd/fpu.h b/src/external/PackedCSparse/qd/fpu.h deleted file mode 100644 index 35eab18c..00000000 --- a/src/external/PackedCSparse/qd/fpu.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * include/fpu.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2001 - * - * Contains functions to set and restore the round-to-double flag in the - * control word of a x86 FPU. The algorithms in the double-double and - * quad-double package does not function with the extended mode found in - * these FPU. - */ -#ifndef _QD_FPU_H -#define _QD_FPU_H - -#include "qd_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Set the round-to-double flag, and save the old control word in old_cw. - * If old_cw is NULL, the old control word is not saved. - */ -QD_API void fpu_fix_start(unsigned int *old_cw); - -/* - * Restore the control word. - */ -QD_API void fpu_fix_end(unsigned int *old_cw); - -#ifdef __cplusplus -} -#endif - -#endif /* _QD_FPU_H */ diff --git a/src/external/PackedCSparse/qd/inline.h b/src/external/PackedCSparse/qd/inline.h deleted file mode 100644 index 52425545..00000000 --- a/src/external/PackedCSparse/qd/inline.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * include/inline.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * This file contains the basic functions used both by double-double - * and quad-double package. These are declared as inline functions as - * they are the smallest building blocks of the double-double and - * quad-double arithmetic. - */ -#ifndef _QD_INLINE_H -#define _QD_INLINE_H - -#define _QD_SPLITTER 134217729.0 // = 2^27 + 1 -#define _QD_SPLIT_THRESH 6.69692879491417e+299 // = 2^996 - -#ifdef QD_VACPP_BUILTINS_H -/* For VisualAge C++ __fmadd */ -#include <builtins.h> -#endif - -#include <cmath> -#include <limits> - -namespace qd { - -static const double _d_nan = std::numeric_limits<double>::quiet_NaN(); -static const double _d_inf = std::numeric_limits<double>::infinity(); - -/*********** Basic Functions ************/ -/* Computes fl(a+b) and err(a+b). Assumes |a| >= |b|. */ -inline double quick_two_sum(double a, double b, double &err) { - double s = a + b; - err = b - (s - a); - return s; -} - -/* Computes fl(a-b) and err(a-b). Assumes |a| >= |b| */ -inline double quick_two_diff(double a, double b, double &err) { - double s = a - b; - err = (a - s) - b; - return s; -} - -/* Computes fl(a+b) and err(a+b). */ -inline double two_sum(double a, double b, double &err) { - double s = a + b; - double bb = s - a; - err = (a - (s - bb)) + (b - bb); - return s; -} - -/* Computes fl(a-b) and err(a-b). */ -inline double two_diff(double a, double b, double &err) { - double s = a - b; - double bb = s - a; - err = (a - (s - bb)) - (b + bb); - return s; -} - -#ifndef QD_FMS -/* Computes high word and lo word of a */ -inline void split(double a, double &hi, double &lo) { - double temp; - if (a > _QD_SPLIT_THRESH || a < -_QD_SPLIT_THRESH) { - a *= 3.7252902984619140625e-09; // 2^-28 - temp = _QD_SPLITTER * a; - hi = temp - (temp - a); - lo = a - hi; - hi *= 268435456.0; // 2^28 - lo *= 268435456.0; // 2^28 - } else { - temp = _QD_SPLITTER * a; - hi = temp - (temp - a); - lo = a - hi; - } -} -#endif - -/* Computes fl(a*b) and err(a*b). */ -inline double two_prod(double a, double b, double &err) { -#ifdef QD_FMS - double p = a * b; - err = QD_FMS(a, b, p); - return p; -#else - double a_hi, a_lo, b_hi, b_lo; - double p = a * b; - split(a, a_hi, a_lo); - split(b, b_hi, b_lo); - err = ((a_hi * b_hi - p) + a_hi * b_lo + a_lo * b_hi) + a_lo * b_lo; - return p; -#endif -} - -/* Computes fl(a*a) and err(a*a). Faster than the above method. */ -inline double two_sqr(double a, double &err) { -#ifdef QD_FMS - double p = a * a; - err = QD_FMS(a, a, p); - return p; -#else - double hi, lo; - double q = a * a; - split(a, hi, lo); - err = ((hi * hi - q) + 2.0 * hi * lo) + lo * lo; - return q; -#endif -} - -/* Computes the nearest integer to d. */ -inline double nint(double d) { - if (d == std::floor(d)) - return d; - return std::floor(d + 0.5); -} - -/* Computes the truncated integer. */ -inline double aint(double d) { - return (d >= 0.0) ? std::floor(d) : std::ceil(d); -} - -/* These are provided to give consistent - interface for double with double-double and quad-double. */ -inline void sincosh(double t, double &sinh_t, double &cosh_t) { - sinh_t = std::sinh(t); - cosh_t = std::cosh(t); -} - -inline double sqr(double t) { - return t * t; -} - -inline double to_double(double a) { return a; } -inline int to_int(double a) { return static_cast<int>(a); } - -} - -#endif /* _QD_INLINE_H */ diff --git a/src/external/PackedCSparse/qd/qd.pdf b/src/external/PackedCSparse/qd/qd.pdf deleted file mode 100644 index 9525b8ca..00000000 Binary files a/src/external/PackedCSparse/qd/qd.pdf and /dev/null differ diff --git a/src/external/PackedCSparse/qd/qd_config.h b/src/external/PackedCSparse/qd/qd_config.h deleted file mode 100644 index d23e33a6..00000000 --- a/src/external/PackedCSparse/qd/qd_config.h +++ /dev/null @@ -1,92 +0,0 @@ -#include <algorithm> -#include <cmath> - -/* include/qd/qd_config.h. Generated from qd_config.h.in by configure. */ -#ifndef _QD_QD_CONFIG_H -#define _QD_QD_CONFIG_H 1 - -#ifndef QD_API -#define QD_API /**/ -#endif - -/* Set to 1 if using VisualAge C++ compiler for __fmadd builtin. */ -#ifndef QD_VACPP_BUILTINS_H -/* #undef QD_VACPP_BUILTINS_H */ -#endif - -/* If fused multiply-add is available, define to correct macro for - using it. It is invoked as QD_FMA(a, b, c) to compute fl(a * b + c). - If correctly rounded multiply-add is not available (or if unsure), - keep it undefined.*/ -#ifndef QD_FMA -/* #undef QD_FMA */ -#endif - -/* If fused multiply-subtract is available, define to correct macro for - using it. It is invoked as QD_FMS(a, b, c) to compute fl(a * b - c). - If correctly rounded multiply-add is not available (or if unsure), - keep it undefined.*/ -#ifndef QD_FMS -#define QD_FMS(a, b, c) std::fma(a,b,-c) -/* #undef QD_FMS */ -#endif - -/* Set the following to 1 to define commonly used function - to be inlined. This should be set to 1 unless the compiler - does not support the "inline" keyword, or if building for - debugging purposes. */ -#ifndef QD_INLINE -#define QD_INLINE 1 -#endif - -/* Set the following to 1 to use ANSI C++ standard header files - such as cmath, iostream, etc. If set to zero, it will try to - include math.h, iostream.h, etc, instead. */ -#ifndef QD_HAVE_STD -#define QD_HAVE_STD 1 -#endif - -/* Set the following to 1 to make the addition and subtraction - to satisfy the IEEE-style error bound - - fl(a + b) = (1 + d) * (a + b) - - where |d| <= eps. If set to 0, the addition and subtraction - will satisfy the weaker Cray-style error bound - - fl(a + b) = (1 + d1) * a + (1 + d2) * b - - where |d1| <= eps and |d2| eps. */ -#ifndef QD_IEEE_ADD -/* #undef QD_IEEE_ADD */ -#endif - -/* Set the following to 1 to use slightly inaccurate but faster - version of multiplication. */ -#ifndef QD_SLOPPY_MUL -#define QD_SLOPPY_MUL 1 -#endif - -/* Set the following to 1 to use slightly inaccurate but faster - version of division. */ -#ifndef QD_SLOPPY_DIV -#define QD_SLOPPY_DIV 1 -#endif - -/* Define this macro to be the isfinite(x) function. */ -#ifndef QD_ISFINITE -#define QD_ISFINITE(x) std::isfinite(x) -#endif - -/* Define this macro to be the isinf(x) function. */ -#ifndef QD_ISINF -#define QD_ISINF(x) std::isinf(x) -#endif - -/* Define this macro to be the isnan(x) function. */ -#ifndef QD_ISNAN -#define QD_ISNAN(x) std::isnan(x) -#endif - - -#endif /* _QD_QD_CONFIG_H */ diff --git a/src/external/PackedCSparse/qd/qd_const.cc b/src/external/PackedCSparse/qd/qd_const.cc deleted file mode 100644 index 6f4e01d2..00000000 --- a/src/external/PackedCSparse/qd/qd_const.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - * src/qd_const.cc - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Defines constants used in quad-double package. - */ -#include "qd_config.h" -#include "qd_real.h" - -/* Some useful constants. */ -const qd_real qd_real::_2pi = qd_real(6.283185307179586232e+00, - 2.449293598294706414e-16, - -5.989539619436679332e-33, - 2.224908441726730563e-49); -const qd_real qd_real::_pi = qd_real(3.141592653589793116e+00, - 1.224646799147353207e-16, - -2.994769809718339666e-33, - 1.112454220863365282e-49); -const qd_real qd_real::_pi2 = qd_real(1.570796326794896558e+00, - 6.123233995736766036e-17, - -1.497384904859169833e-33, - 5.562271104316826408e-50); -const qd_real qd_real::_pi4 = qd_real(7.853981633974482790e-01, - 3.061616997868383018e-17, - -7.486924524295849165e-34, - 2.781135552158413204e-50); -const qd_real qd_real::_3pi4 = qd_real(2.356194490192344837e+00, - 9.1848509936051484375e-17, - 3.9168984647504003225e-33, - -2.5867981632704860386e-49); -const qd_real qd_real::_e = qd_real(2.718281828459045091e+00, - 1.445646891729250158e-16, - -2.127717108038176765e-33, - 1.515630159841218954e-49); -const qd_real qd_real::_log2 = qd_real(6.931471805599452862e-01, - 2.319046813846299558e-17, - 5.707708438416212066e-34, - -3.582432210601811423e-50); -const qd_real qd_real::_log10 = qd_real(2.302585092994045901e+00, - -2.170756223382249351e-16, - -9.984262454465776570e-33, - -4.023357454450206379e-49); -const qd_real qd_real::_nan = qd_real(qd::_d_nan, qd::_d_nan, - qd::_d_nan, qd::_d_nan); -const qd_real qd_real::_inf = qd_real(qd::_d_inf, qd::_d_inf, - qd::_d_inf, qd::_d_inf); - -const double qd_real::_eps = 1.21543267145725e-63; // = 2^-209 -const double qd_real::_min_normalized = 1.6259745436952323e-260; // = 2^(-1022 + 3*53) -const qd_real qd_real::_max = qd_real( - 1.79769313486231570815e+308, 9.97920154767359795037e+291, - 5.53956966280111259858e+275, 3.07507889307840487279e+259); -const qd_real qd_real::_safe_max = qd_real( - 1.7976931080746007281e+308, 9.97920154767359795037e+291, - 5.53956966280111259858e+275, 3.07507889307840487279e+259); -const int qd_real::_ndigits = 62; - diff --git a/src/external/PackedCSparse/qd/qd_inline.h b/src/external/PackedCSparse/qd/qd_inline.h deleted file mode 100644 index 89ba275b..00000000 --- a/src/external/PackedCSparse/qd/qd_inline.h +++ /dev/null @@ -1,1047 +0,0 @@ -/* - * include/qd_inline.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2001 - * - * Contains small functions (suitable for inlining) in the quad-double - * arithmetic package. - */ -#ifndef _QD_QD_INLINE_H -#define _QD_QD_INLINE_H - -#include <cmath> -#include "inline.h" - -#ifndef QD_INLINE -#define inline -#endif - -/********** Constructors **********/ -inline qd_real::qd_real(double x0, double x1, double x2, double x3) { - x[0] = x0; - x[1] = x1; - x[2] = x2; - x[3] = x3; -} - -inline qd_real::qd_real(const double *xx) { - x[0] = xx[0]; - x[1] = xx[1]; - x[2] = xx[2]; - x[3] = xx[3]; -} - -inline qd_real::qd_real(double x0) { - x[0] = x0; - x[1] = x[2] = x[3] = 0.0; -} - -inline qd_real::qd_real() { - x[0] = 0.0; - x[1] = 0.0; - x[2] = 0.0; - x[3] = 0.0; -} - -inline qd_real::qd_real(const dd_real &a) { - x[0] = a._hi(); - x[1] = a._lo(); - x[2] = x[3] = 0.0; -} - -inline qd_real::qd_real(int i) { - x[0] = static_cast<double>(i); - x[1] = x[2] = x[3] = 0.0; -} - -/********** Accessors **********/ -inline double qd_real::operator[](int i) const { - return x[i]; -} - -inline double &qd_real::operator[](int i) { - return x[i]; -} - -inline bool qd_real::isnan() const { - return QD_ISNAN(x[0]) || QD_ISNAN(x[1]) || QD_ISNAN(x[2]) || QD_ISNAN(x[3]); -} - -/********** Renormalization **********/ -namespace qd { -inline void quick_renorm(double &c0, double &c1, - double &c2, double &c3, double &c4) { - double t0, t1, t2, t3; - double s; - s = qd::quick_two_sum(c3, c4, t3); - s = qd::quick_two_sum(c2, s , t2); - s = qd::quick_two_sum(c1, s , t1); - c0 = qd::quick_two_sum(c0, s , t0); - - s = qd::quick_two_sum(t2, t3, t2); - s = qd::quick_two_sum(t1, s , t1); - c1 = qd::quick_two_sum(t0, s , t0); - - s = qd::quick_two_sum(t1, t2, t1); - c2 = qd::quick_two_sum(t0, s , t0); - - c3 = t0 + t1; -} - -inline void renorm(double &c0, double &c1, - double &c2, double &c3) { - double s0, s1, s2 = 0.0, s3 = 0.0; - - if (QD_ISINF(c0)) return; - - s0 = qd::quick_two_sum(c2, c3, c3); - s0 = qd::quick_two_sum(c1, s0, c2); - c0 = qd::quick_two_sum(c0, s0, c1); - - s0 = c0; - s1 = c1; - if (s1 != 0.0) { - s1 = qd::quick_two_sum(s1, c2, s2); - if (s2 != 0.0) - s2 = qd::quick_two_sum(s2, c3, s3); - else - s1 = qd::quick_two_sum(s1, c3, s2); - } else { - s0 = qd::quick_two_sum(s0, c2, s1); - if (s1 != 0.0) - s1 = qd::quick_two_sum(s1, c3, s2); - else - s0 = qd::quick_two_sum(s0, c3, s1); - } - - c0 = s0; - c1 = s1; - c2 = s2; - c3 = s3; -} - -inline void renorm(double &c0, double &c1, - double &c2, double &c3, double &c4) { - double s0, s1, s2 = 0.0, s3 = 0.0; - - if (QD_ISINF(c0)) return; - - s0 = qd::quick_two_sum(c3, c4, c4); - s0 = qd::quick_two_sum(c2, s0, c3); - s0 = qd::quick_two_sum(c1, s0, c2); - c0 = qd::quick_two_sum(c0, s0, c1); - - s0 = c0; - s1 = c1; - - if (s1 != 0.0) { - s1 = qd::quick_two_sum(s1, c2, s2); - if (s2 != 0.0) { - s2 = qd::quick_two_sum(s2, c3, s3); - if (s3 != 0.0) - s3 += c4; - else - s2 = qd::quick_two_sum(s2, c4, s3); - } else { - s1 = qd::quick_two_sum(s1, c3, s2); - if (s2 != 0.0) - s2 = qd::quick_two_sum(s2, c4, s3); - else - s1 = qd::quick_two_sum(s1, c4, s2); - } - } else { - s0 = qd::quick_two_sum(s0, c2, s1); - if (s1 != 0.0) { - s1 = qd::quick_two_sum(s1, c3, s2); - if (s2 != 0.0) - s2 = qd::quick_two_sum(s2, c4, s3); - else - s1 = qd::quick_two_sum(s1, c4, s2); - } else { - s0 = qd::quick_two_sum(s0, c3, s1); - if (s1 != 0.0) - s1 = qd::quick_two_sum(s1, c4, s2); - else - s0 = qd::quick_two_sum(s0, c4, s1); - } - } - - c0 = s0; - c1 = s1; - c2 = s2; - c3 = s3; -} -} - -inline void qd_real::renorm() { - qd::renorm(x[0], x[1], x[2], x[3]); -} - -inline void qd_real::renorm(double &e) { - qd::renorm(x[0], x[1], x[2], x[3], e); -} - - -/********** Additions ************/ -namespace qd { - -inline void three_sum(double &a, double &b, double &c) { - double t1, t2, t3; - t1 = qd::two_sum(a, b, t2); - a = qd::two_sum(c, t1, t3); - b = qd::two_sum(t2, t3, c); -} - -inline void three_sum2(double &a, double &b, double &c) { - double t1, t2, t3; - t1 = qd::two_sum(a, b, t2); - a = qd::two_sum(c, t1, t3); - b = t2 + t3; -} - -} - -/* quad-double + double */ -inline qd_real operator+(const qd_real &a, double b) { - double c0, c1, c2, c3; - double e; - - c0 = qd::two_sum(a[0], b, e); - c1 = qd::two_sum(a[1], e, e); - c2 = qd::two_sum(a[2], e, e); - c3 = qd::two_sum(a[3], e, e); - - qd::renorm(c0, c1, c2, c3, e); - - return qd_real(c0, c1, c2, c3); -} - -/* quad-double + double-double */ -inline qd_real operator+(const qd_real &a, const dd_real &b) { - - double s0, s1, s2, s3; - double t0, t1; - - s0 = qd::two_sum(a[0], b._hi(), t0); - s1 = qd::two_sum(a[1], b._lo(), t1); - - s1 = qd::two_sum(s1, t0, t0); - - s2 = a[2]; - qd::three_sum(s2, t0, t1); - - s3 = qd::two_sum(t0, a[3], t0); - t0 += t1; - - qd::renorm(s0, s1, s2, s3, t0); - return qd_real(s0, s1, s2, s3); -} - - -/* double + quad-double */ -inline qd_real operator+(double a, const qd_real &b) { - return (b + a); -} - -/* double-double + quad-double */ -inline qd_real operator+(const dd_real &a, const qd_real &b) { - return (b + a); -} - -namespace qd { - -/* s = quick_three_accum(a, b, c) adds c to the dd-pair (a, b). - * If the result does not fit in two doubles, then the sum is - * output into s and (a,b) contains the remainder. Otherwise - * s is zero and (a,b) contains the sum. */ -inline double quick_three_accum(double &a, double &b, double c) { - double s; - bool za, zb; - - s = qd::two_sum(b, c, b); - s = qd::two_sum(a, s, a); - - za = (a != 0.0); - zb = (b != 0.0); - - if (za && zb) - return s; - - if (!zb) { - b = a; - a = s; - } else { - a = s; - } - - return 0.0; -} - -} - -inline qd_real qd_real::ieee_add(const qd_real &a, const qd_real &b) { - int i, j, k; - double s, t; - double u, v; /* double-length accumulator */ - double x[4] = {0.0, 0.0, 0.0, 0.0}; - - i = j = k = 0; - if (std::abs(a[i]) > std::abs(b[j])) - u = a[i++]; - else - u = b[j++]; - if (std::abs(a[i]) > std::abs(b[j])) - v = a[i++]; - else - v = b[j++]; - - u = qd::quick_two_sum(u, v, v); - - while (k < 4) { - if (i >= 4 && j >= 4) { - x[k] = u; - if (k < 3) - x[++k] = v; - break; - } - - if (i >= 4) - t = b[j++]; - else if (j >= 4) - t = a[i++]; - else if (std::abs(a[i]) > std::abs(b[j])) { - t = a[i++]; - } else - t = b[j++]; - - s = qd::quick_three_accum(u, v, t); - - if (s != 0.0) { - x[k++] = s; - } - } - - /* add the rest. */ - for (k = i; k < 4; k++) - x[3] += a[k]; - for (k = j; k < 4; k++) - x[3] += b[k]; - - qd::renorm(x[0], x[1], x[2], x[3]); - return qd_real(x[0], x[1], x[2], x[3]); -} - -inline qd_real qd_real::sloppy_add(const qd_real &a, const qd_real &b) { - /* - double s0, s1, s2, s3; - double t0, t1, t2, t3; - - s0 = qd::two_sum(a[0], b[0], t0); - s1 = qd::two_sum(a[1], b[1], t1); - s2 = qd::two_sum(a[2], b[2], t2); - s3 = qd::two_sum(a[3], b[3], t3); - - s1 = qd::two_sum(s1, t0, t0); - qd::three_sum(s2, t0, t1); - qd::three_sum2(s3, t0, t2); - t0 = t0 + t1 + t3; - - qd::renorm(s0, s1, s2, s3, t0); - return qd_real(s0, s1, s2, s3, t0); - */ - - /* Same as above, but addition re-organized to minimize - data dependency ... unfortunately some compilers are - not very smart to do this automatically */ - double s0, s1, s2, s3; - double t0, t1, t2, t3; - - double v0, v1, v2, v3; - double u0, u1, u2, u3; - double w0, w1, w2, w3; - - s0 = a[0] + b[0]; - s1 = a[1] + b[1]; - s2 = a[2] + b[2]; - s3 = a[3] + b[3]; - - v0 = s0 - a[0]; - v1 = s1 - a[1]; - v2 = s2 - a[2]; - v3 = s3 - a[3]; - - u0 = s0 - v0; - u1 = s1 - v1; - u2 = s2 - v2; - u3 = s3 - v3; - - w0 = a[0] - u0; - w1 = a[1] - u1; - w2 = a[2] - u2; - w3 = a[3] - u3; - - u0 = b[0] - v0; - u1 = b[1] - v1; - u2 = b[2] - v2; - u3 = b[3] - v3; - - t0 = w0 + u0; - t1 = w1 + u1; - t2 = w2 + u2; - t3 = w3 + u3; - - s1 = qd::two_sum(s1, t0, t0); - qd::three_sum(s2, t0, t1); - qd::three_sum2(s3, t0, t2); - t0 = t0 + t1 + t3; - - /* renormalize */ - qd::renorm(s0, s1, s2, s3, t0); - return qd_real(s0, s1, s2, s3); -} - -/* quad-double + quad-double */ -inline qd_real operator+(const qd_real &a, const qd_real &b) { -#ifndef QD_IEEE_ADD - return qd_real::sloppy_add(a, b); -#else - return qd_real::ieee_add(a, b); -#endif -} - - - -/********** Self-Additions ************/ -/* quad-double += double */ -inline qd_real &qd_real::operator+=(double a) { - *this = *this + a; - return *this; -} - -/* quad-double += double-double */ -inline qd_real &qd_real::operator+=(const dd_real &a) { - *this = *this + a; - return *this; -} - -/* quad-double += quad-double */ -inline qd_real &qd_real::operator+=(const qd_real &a) { - *this = *this + a; - return *this; -} - -/********** Unary Minus **********/ -inline qd_real qd_real::operator-() const { - return qd_real(-x[0], -x[1], -x[2], -x[3]); -} - -/********** Subtractions **********/ -inline qd_real operator-(const qd_real &a, double b) { - return (a + (-b)); -} - -inline qd_real operator-(double a, const qd_real &b) { - return (a + (-b)); -} - -inline qd_real operator-(const qd_real &a, const dd_real &b) { - return (a + (-b)); -} - -inline qd_real operator-(const dd_real &a, const qd_real &b) { - return (a + (-b)); -} - -inline qd_real operator-(const qd_real &a, const qd_real &b) { - return (a + (-b)); -} - -/********** Self-Subtractions **********/ -inline qd_real &qd_real::operator-=(double a) { - return ((*this) += (-a)); -} - -inline qd_real &qd_real::operator-=(const dd_real &a) { - return ((*this) += (-a)); -} - -inline qd_real &qd_real::operator-=(const qd_real &a) { - return ((*this) += (-a)); -} - - -inline qd_real operator*(double a, const qd_real &b) { - return (b * a); -} - -inline qd_real operator*(const dd_real &a, const qd_real &b) { - return (b * a); -} - -inline qd_real mul_pwr2(const qd_real &a, double b) { - return qd_real(a[0] * b, a[1] * b, a[2] * b, a[3] * b); -} - -/********** Multiplications **********/ -inline qd_real operator*(const qd_real &a, double b) { - double p0, p1, p2, p3; - double q0, q1, q2; - double s0, s1, s2, s3, s4; - - p0 = qd::two_prod(a[0], b, q0); - p1 = qd::two_prod(a[1], b, q1); - p2 = qd::two_prod(a[2], b, q2); - p3 = a[3] * b; - - s0 = p0; - - s1 = qd::two_sum(q0, p1, s2); - - qd::three_sum(s2, q1, p2); - - qd::three_sum2(q1, q2, p3); - s3 = q1; - - s4 = q2 + p2; - - qd::renorm(s0, s1, s2, s3, s4); - return qd_real(s0, s1, s2, s3); - -} - -/* quad-double * double-double */ -/* a0 * b0 0 - a0 * b1 1 - a1 * b0 2 - a1 * b1 3 - a2 * b0 4 - a2 * b1 5 - a3 * b0 6 - a3 * b1 7 */ -inline qd_real operator*(const qd_real &a, const dd_real &b) { - double p0, p1, p2, p3, p4; - double q0, q1, q2, q3, q4; - double s0, s1, s2; - double t0, t1; - - p0 = qd::two_prod(a[0], b._hi(), q0); - p1 = qd::two_prod(a[0], b._lo(), q1); - p2 = qd::two_prod(a[1], b._hi(), q2); - p3 = qd::two_prod(a[1], b._lo(), q3); - p4 = qd::two_prod(a[2], b._hi(), q4); - - qd::three_sum(p1, p2, q0); - - /* Five-Three-Sum */ - qd::three_sum(p2, p3, p4); - q1 = qd::two_sum(q1, q2, q2); - s0 = qd::two_sum(p2, q1, t0); - s1 = qd::two_sum(p3, q2, t1); - s1 = qd::two_sum(s1, t0, t0); - s2 = t0 + t1 + p4; - p2 = s0; - - p3 = a[2] * b._hi() + a[3] * b._lo() + q3 + q4; - qd::three_sum2(p3, q0, s1); - p4 = q0 + s2; - - qd::renorm(p0, p1, p2, p3, p4); - return qd_real(p0, p1, p2, p3); -} - -/* quad-double * quad-double */ -/* a0 * b0 0 - a0 * b1 1 - a1 * b0 2 - a0 * b2 3 - a1 * b1 4 - a2 * b0 5 - a0 * b3 6 - a1 * b2 7 - a2 * b1 8 - a3 * b0 9 */ -inline qd_real qd_real::sloppy_mul(const qd_real &a, const qd_real &b) { - double p0, p1, p2, p3, p4, p5; - double q0, q1, q2, q3, q4, q5; - double t0, t1; - double s0, s1, s2; - - p0 = qd::two_prod(a[0], b[0], q0); - - p1 = qd::two_prod(a[0], b[1], q1); - p2 = qd::two_prod(a[1], b[0], q2); - - p3 = qd::two_prod(a[0], b[2], q3); - p4 = qd::two_prod(a[1], b[1], q4); - p5 = qd::two_prod(a[2], b[0], q5); - - /* Start Accumulation */ - qd::three_sum(p1, p2, q0); - - /* Six-Three Sum of p2, q1, q2, p3, p4, p5. */ - qd::three_sum(p2, q1, q2); - qd::three_sum(p3, p4, p5); - /* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */ - s0 = qd::two_sum(p2, p3, t0); - s1 = qd::two_sum(q1, p4, t1); - s2 = q2 + p5; - s1 = qd::two_sum(s1, t0, t0); - s2 += (t0 + t1); - - /* O(eps^3) order terms */ - s1 += a[0]*b[3] + a[1]*b[2] + a[2]*b[1] + a[3]*b[0] + q0 + q3 + q4 + q5; - qd::renorm(p0, p1, s0, s1, s2); - return qd_real(p0, p1, s0, s1); -} - -inline qd_real qd_real::accurate_mul(const qd_real &a, const qd_real &b) { - double p0, p1, p2, p3, p4, p5; - double q0, q1, q2, q3, q4, q5; - double p6, p7, p8, p9; - double q6, q7, q8, q9; - double r0, r1; - double t0, t1; - double s0, s1, s2; - - p0 = qd::two_prod(a[0], b[0], q0); - - p1 = qd::two_prod(a[0], b[1], q1); - p2 = qd::two_prod(a[1], b[0], q2); - - p3 = qd::two_prod(a[0], b[2], q3); - p4 = qd::two_prod(a[1], b[1], q4); - p5 = qd::two_prod(a[2], b[0], q5); - - /* Start Accumulation */ - qd::three_sum(p1, p2, q0); - - /* Six-Three Sum of p2, q1, q2, p3, p4, p5. */ - qd::three_sum(p2, q1, q2); - qd::three_sum(p3, p4, p5); - /* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */ - s0 = qd::two_sum(p2, p3, t0); - s1 = qd::two_sum(q1, p4, t1); - s2 = q2 + p5; - s1 = qd::two_sum(s1, t0, t0); - s2 += (t0 + t1); - - /* O(eps^3) order terms */ - p6 = qd::two_prod(a[0], b[3], q6); - p7 = qd::two_prod(a[1], b[2], q7); - p8 = qd::two_prod(a[2], b[1], q8); - p9 = qd::two_prod(a[3], b[0], q9); - - /* Nine-Two-Sum of q0, s1, q3, q4, q5, p6, p7, p8, p9. */ - q0 = qd::two_sum(q0, q3, q3); - q4 = qd::two_sum(q4, q5, q5); - p6 = qd::two_sum(p6, p7, p7); - p8 = qd::two_sum(p8, p9, p9); - /* Compute (t0, t1) = (q0, q3) + (q4, q5). */ - t0 = qd::two_sum(q0, q4, t1); - t1 += (q3 + q5); - /* Compute (r0, r1) = (p6, p7) + (p8, p9). */ - r0 = qd::two_sum(p6, p8, r1); - r1 += (p7 + p9); - /* Compute (q3, q4) = (t0, t1) + (r0, r1). */ - q3 = qd::two_sum(t0, r0, q4); - q4 += (t1 + r1); - /* Compute (t0, t1) = (q3, q4) + s1. */ - t0 = qd::two_sum(q3, s1, t1); - t1 += q4; - - /* O(eps^4) terms -- Nine-One-Sum */ - t1 += a[1] * b[3] + a[2] * b[2] + a[3] * b[1] + q6 + q7 + q8 + q9 + s2; - - qd::renorm(p0, p1, s0, t0, t1); - return qd_real(p0, p1, s0, t0); -} - -inline qd_real operator*(const qd_real &a, const qd_real &b) { -#ifdef QD_SLOPPY_MUL - return qd_real::sloppy_mul(a, b); -#else - return qd_real::accurate_mul(a, b); -#endif -} - -/* quad-double ^ 2 = (x0 + x1 + x2 + x3) ^ 2 - = x0 ^ 2 + 2 x0 * x1 + (2 x0 * x2 + x1 ^ 2) - + (2 x0 * x3 + 2 x1 * x2) */ -inline qd_real sqr(const qd_real &a) { - double p0, p1, p2, p3, p4, p5; - double q0, q1, q2, q3; - double s0, s1; - double t0, t1; - - p0 = qd::two_sqr(a[0], q0); - p1 = qd::two_prod(2.0 * a[0], a[1], q1); - p2 = qd::two_prod(2.0 * a[0], a[2], q2); - p3 = qd::two_sqr(a[1], q3); - - p1 = qd::two_sum(q0, p1, q0); - - q0 = qd::two_sum(q0, q1, q1); - p2 = qd::two_sum(p2, p3, p3); - - s0 = qd::two_sum(q0, p2, t0); - s1 = qd::two_sum(q1, p3, t1); - - s1 = qd::two_sum(s1, t0, t0); - t0 += t1; - - s1 = qd::quick_two_sum(s1, t0, t0); - p2 = qd::quick_two_sum(s0, s1, t1); - p3 = qd::quick_two_sum(t1, t0, q0); - - p4 = 2.0 * a[0] * a[3]; - p5 = 2.0 * a[1] * a[2]; - - p4 = qd::two_sum(p4, p5, p5); - q2 = qd::two_sum(q2, q3, q3); - - t0 = qd::two_sum(p4, q2, t1); - t1 = t1 + p5 + q3; - - p3 = qd::two_sum(p3, t0, p4); - p4 = p4 + q0 + t1; - - qd::renorm(p0, p1, p2, p3, p4); - return qd_real(p0, p1, p2, p3); - -} - -/********** Self-Multiplication **********/ -/* quad-double *= double */ -inline qd_real &qd_real::operator*=(double a) { - *this = (*this * a); - return *this; -} - -/* quad-double *= double-double */ -inline qd_real &qd_real::operator*=(const dd_real &a) { - *this = (*this * a); - return *this; -} - -/* quad-double *= quad-double */ -inline qd_real &qd_real::operator*=(const qd_real &a) { - *this = *this * a; - return *this; -} - -inline qd_real operator/ (const qd_real &a, const dd_real &b) { -#ifdef QD_SLOPPY_DIV - return qd_real::sloppy_div(a, b); -#else - return qd_real::accurate_div(a, b); -#endif -} - -inline qd_real operator/(const qd_real &a, const qd_real &b) { -#ifdef QD_SLOPPY_DIV - return qd_real::sloppy_div(a, b); -#else - return qd_real::accurate_div(a, b); -#endif -} - -/* double / quad-double */ -inline qd_real operator/(double a, const qd_real &b) { - return qd_real(a) / b; -} - -/* double-double / quad-double */ -inline qd_real operator/(const dd_real &a, const qd_real &b) { - return qd_real(a) / b; -} - -/********** Self-Divisions **********/ -/* quad-double /= double */ -inline qd_real &qd_real::operator/=(double a) { - *this = (*this / a); - return *this; -} - -/* quad-double /= double-double */ -inline qd_real &qd_real::operator/=(const dd_real &a) { - *this = (*this / a); - return *this; -} - -/* quad-double /= quad-double */ -inline qd_real &qd_real::operator/=(const qd_real &a) { - *this = (*this / a); - return *this; -} - - -/********** Exponentiation **********/ -inline qd_real qd_real::operator^(int n) const { - return pow(*this, n); -} - -/********** Miscellaneous **********/ -inline qd_real abs(const qd_real &a) { - return (a[0] < 0.0) ? -a : a; -} - -inline qd_real fabs(const qd_real &a) { - return abs(a); -} - -/* Quick version. May be off by one when qd is very close - to the middle of two integers. */ -inline qd_real quick_nint(const qd_real &a) { - qd_real r = qd_real(qd::nint(a[0]), qd::nint(a[1]), - qd::nint(a[2]), qd::nint(a[3])); - r.renorm(); - return r; -} - -/*********** Assignments ************/ -/* quad-double = double */ -inline qd_real &qd_real::operator=(double a) { - x[0] = a; - x[1] = x[2] = x[3] = 0.0; - return *this; -} - -/* quad-double = double-double */ -inline qd_real &qd_real::operator=(const dd_real &a) { - x[0] = a._hi(); - x[1] = a._lo(); - x[2] = x[3] = 0.0; - return *this; -} - -/********** Equality Comparison **********/ -inline bool operator==(const qd_real &a, double b) { - return (a[0] == b && a[1] == 0.0 && a[2] == 0.0 && a[3] == 0.0); -} - -inline bool operator==(double a, const qd_real &b) { - return (b == a); -} - -inline bool operator==(const qd_real &a, const dd_real &b) { - return (a[0] == b._hi() && a[1] == b._lo() && - a[2] == 0.0 && a[3] == 0.0); -} - -inline bool operator==(const dd_real &a, const qd_real &b) { - return (b == a); -} - -inline bool operator==(const qd_real &a, const qd_real &b) { - return (a[0] == b[0] && a[1] == b[1] && - a[2] == b[2] && a[3] == b[3]); -} - - -/********** Less-Than Comparison ***********/ -inline bool operator<(const qd_real &a, double b) { - return (a[0] < b || (a[0] == b && a[1] < 0.0)); -} - -inline bool operator<(double a, const qd_real &b) { - return (b > a); -} - -inline bool operator<(const qd_real &a, const dd_real &b) { - return (a[0] < b._hi() || - (a[0] == b._hi() && (a[1] < b._lo() || - (a[1] == b._lo() && a[2] < 0.0)))); -} - -inline bool operator<(const dd_real &a, const qd_real &b) { - return (b > a); -} - -inline bool operator<(const qd_real &a, const qd_real &b) { - return (a[0] < b[0] || - (a[0] == b[0] && (a[1] < b[1] || - (a[1] == b[1] && (a[2] < b[2] || - (a[2] == b[2] && a[3] < b[3])))))); -} - -/********** Greater-Than Comparison ***********/ -inline bool operator>(const qd_real &a, double b) { - return (a[0] > b || (a[0] == b && a[1] > 0.0)); -} - -inline bool operator>(double a, const qd_real &b) { - return (b < a); -} - -inline bool operator>(const qd_real &a, const dd_real &b) { - return (a[0] > b._hi() || - (a[0] == b._hi() && (a[1] > b._lo() || - (a[1] == b._lo() && a[2] > 0.0)))); -} - -inline bool operator>(const dd_real &a, const qd_real &b) { - return (b < a); -} - -inline bool operator>(const qd_real &a, const qd_real &b) { - return (a[0] > b[0] || - (a[0] == b[0] && (a[1] > b[1] || - (a[1] == b[1] && (a[2] > b[2] || - (a[2] == b[2] && a[3] > b[3])))))); -} - - -/********** Less-Than-Or-Equal-To Comparison **********/ -inline bool operator<=(const qd_real &a, double b) { - return (a[0] < b || (a[0] == b && a[1] <= 0.0)); -} - -inline bool operator<=(double a, const qd_real &b) { - return (b >= a); -} - -inline bool operator<=(const qd_real &a, const dd_real &b) { - return (a[0] < b._hi() || - (a[0] == b._hi() && (a[1] < b._lo() || - (a[1] == b._lo() && a[2] <= 0.0)))); -} - -inline bool operator<=(const dd_real &a, const qd_real &b) { - return (b >= a); -} - -inline bool operator<=(const qd_real &a, const qd_real &b) { - return (a[0] < b[0] || - (a[0] == b[0] && (a[1] < b[1] || - (a[1] == b[1] && (a[2] < b[2] || - (a[2] == b[2] && a[3] <= b[3])))))); -} - -/********** Greater-Than-Or-Equal-To Comparison **********/ -inline bool operator>=(const qd_real &a, double b) { - return (a[0] > b || (a[0] == b && a[1] >= 0.0)); -} - -inline bool operator>=(double a, const qd_real &b) { - return (b <= a); -} - -inline bool operator>=(const qd_real &a, const dd_real &b) { - return (a[0] > b._hi() || - (a[0] == b._hi() && (a[1] > b._lo() || - (a[1] == b._lo() && a[2] >= 0.0)))); -} - -inline bool operator>=(const dd_real &a, const qd_real &b) { - return (b <= a); -} - -inline bool operator>=(const qd_real &a, const qd_real &b) { - return (a[0] > b[0] || - (a[0] == b[0] && (a[1] > b[1] || - (a[1] == b[1] && (a[2] > b[2] || - (a[2] == b[2] && a[3] >= b[3])))))); -} - - - -/********** Not-Equal-To Comparison **********/ -inline bool operator!=(const qd_real &a, double b) { - return !(a == b); -} - -inline bool operator!=(double a, const qd_real &b) { - return !(a == b); -} - -inline bool operator!=(const qd_real &a, const dd_real &b) { - return !(a == b); -} - -inline bool operator!=(const dd_real &a, const qd_real &b) { - return !(a == b); -} - -inline bool operator!=(const qd_real &a, const qd_real &b) { - return !(a == b); -} - - - -inline qd_real aint(const qd_real &a) { - return (a[0] >= 0) ? floor(a) : ceil(a); -} - -inline bool qd_real::is_zero() const { - return (x[0] == 0.0); -} - -inline bool qd_real::is_one() const { - return (x[0] == 1.0 && x[1] == 0.0 && x[2] == 0.0 && x[3] == 0.0); -} - -inline bool qd_real::is_positive() const { - return (x[0] > 0.0); -} - -inline bool qd_real::is_negative() const { - return (x[0] < 0.0); -} - -inline qd_real::operator bool() const { - return (x[0] != 0.0); -} - -inline qd_real::operator double() const { - return to_double(*this); -} - -inline dd_real to_dd_real(const qd_real &a) { - return dd_real(a[0], a[1]); -} - -inline double to_double(const qd_real &a) { - return a[0]; -} - -inline int to_int(const qd_real &a) { - return static_cast<int>(a[0]); -} - -inline qd_real inv(const qd_real &qd) { - return 1.0 / qd; -} - -inline qd_real max(const qd_real &a, const qd_real &b) { - return (a > b) ? a : b; -} - -inline qd_real max(const qd_real &a, const qd_real &b, - const qd_real &c) { - return (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c); -} - -inline qd_real min(const qd_real &a, const qd_real &b) { - return (a < b) ? a : b; -} - -inline qd_real min(const qd_real &a, const qd_real &b, - const qd_real &c) { - return (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c); -} - -/* Random number generator */ -inline qd_real qd_real::rand() { - return qdrand(); -} - -inline qd_real ldexp(const qd_real &a, int n) { - return qd_real(std::ldexp(a[0], n), std::ldexp(a[1], n), - std::ldexp(a[2], n), std::ldexp(a[3], n)); -} - -#endif /* _QD_QD_INLINE_H */ diff --git a/src/external/PackedCSparse/qd/qd_real.cc b/src/external/PackedCSparse/qd/qd_real.cc deleted file mode 100644 index 02cb7aa3..00000000 --- a/src/external/PackedCSparse/qd/qd_real.cc +++ /dev/null @@ -1,2624 +0,0 @@ -/* - * src/qd_real.cc - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2007 - * - * Contains implementation of non-inlined functions of quad-double - * package. Inlined functions are found in qd_inline.h (in include directory). - */ -#include <cstdlib> -#include <cstdio> -#include <cstring> -#include <cmath> -#include <iostream> -#include <iomanip> -#include <string> - -#include "qd_config.h" -#include "qd_real.h" -#include "util.h" - -#include "bits.h" - -#ifndef QD_INLINE -#include "qd_inline.h" -#endif - -using std::cout; -using std::cerr; -using std::endl; -using std::istream; -using std::ostream; -using std::ios_base; -using std::string; -using std::setw; - -using namespace qd; - -void qd_real::error(const char *msg) { - //if (msg) { cerr << "ERROR " << msg << endl; } -} - -/********** Multiplications **********/ - -qd_real nint(const qd_real &a) { - double x0, x1, x2, x3; - - x0 = nint(a[0]); - x1 = x2 = x3 = 0.0; - - if (x0 == a[0]) { - /* First double is already an integer. */ - x1 = nint(a[1]); - - if (x1 == a[1]) { - /* Second double is already an integer. */ - x2 = nint(a[2]); - - if (x2 == a[2]) { - /* Third double is already an integer. */ - x3 = nint(a[3]); - } else { - if (std::abs(x2 - a[2]) == 0.5 && a[3] < 0.0) { - x2 -= 1.0; - } - } - - } else { - if (std::abs(x1 - a[1]) == 0.5 && a[2] < 0.0) { - x1 -= 1.0; - } - } - - } else { - /* First double is not an integer. */ - if (std::abs(x0 - a[0]) == 0.5 && a[1] < 0.0) { - x0 -= 1.0; - } - } - - renorm(x0, x1, x2, x3); - return qd_real(x0, x1, x2, x3); -} - -qd_real floor(const qd_real &a) { - double x0, x1, x2, x3; - x1 = x2 = x3 = 0.0; - x0 = std::floor(a[0]); - - if (x0 == a[0]) { - x1 = std::floor(a[1]); - - if (x1 == a[1]) { - x2 = std::floor(a[2]); - - if (x2 == a[2]) { - x3 = std::floor(a[3]); - } - } - - renorm(x0, x1, x2, x3); - return qd_real(x0, x1, x2, x3); - } - - return qd_real(x0, x1, x2, x3); -} - -qd_real ceil(const qd_real &a) { - double x0, x1, x2, x3; - x1 = x2 = x3 = 0.0; - x0 = std::ceil(a[0]); - - if (x0 == a[0]) { - x1 = std::ceil(a[1]); - - if (x1 == a[1]) { - x2 = std::ceil(a[2]); - - if (x2 == a[2]) { - x3 = std::ceil(a[3]); - } - } - - renorm(x0, x1, x2, x3); - return qd_real(x0, x1, x2, x3); - } - - return qd_real(x0, x1, x2, x3); -} - - - -/********** Divisions **********/ -/* quad-double / double */ -qd_real operator/(const qd_real &a, double b) { - /* Strategy: compute approximate quotient using high order - doubles, and then correct it 3 times using the remainder. - (Analogous to long division.) */ - double t0, t1; - double q0, q1, q2, q3; - qd_real r; - - q0 = a[0] / b; /* approximate quotient */ - - /* Compute the remainder a - q0 * b */ - t0 = two_prod(q0, b, t1); - r = a - dd_real(t0, t1); - - /* Compute the first correction */ - q1 = r[0] / b; - t0 = two_prod(q1, b, t1); - r -= dd_real(t0, t1); - - /* Second correction to the quotient. */ - q2 = r[0] / b; - t0 = two_prod(q2, b, t1); - r -= dd_real(t0, t1); - - /* Final correction to the quotient. */ - q3 = r[0] / b; - - renorm(q0, q1, q2, q3); - return qd_real(q0, q1, q2, q3); -} - -qd_real::qd_real(const char *s) { - if (qd_real::read(s, *this)) { - qd_real::error("(qd_real::qd_real): INPUT ERROR."); - *this = qd_real::_nan; - } -} - -qd_real &qd_real::operator=(const char *s) { - if (qd_real::read(s, *this)) { - qd_real::error("(qd_real::operator=): INPUT ERROR."); - *this = qd_real::_nan; - } - return *this; -} - -istream &operator>>(istream &s, qd_real &qd) { - char str[255]; - s >> str; - qd = qd_real(str); - return s; -} - -ostream &operator<<(ostream &os, const qd_real &qd) { - bool showpos = (os.flags() & ios_base::showpos) != 0; - bool uppercase = (os.flags() & ios_base::uppercase) != 0; - return os << qd.to_string((int)os.precision(), (int)os.width(), os.flags(), - showpos, uppercase, os.fill()); -} - -/* Read a quad-double from s. */ -int qd_real::read(const char *s, qd_real &qd) { - const char *p = s; - char ch; - int sign = 0; - int point = -1; /* location of decimal point */ - int nd = 0; /* number of digits read */ - int e = 0; /* exponent. */ - bool done = false; - qd_real r = 0.0; /* number being read */ - - /* Skip any leading spaces */ - while (*p == ' ') p++; - - while (!done && (ch = *p) != '\0') { - if (ch >= '0' && ch <= '9') { - /* It's a digit */ - int d = ch - '0'; - r *= 10.0; - r += static_cast<double>(d); - nd++; - } else { - /* Non-digit */ - switch (ch) { - case '.': - if (point >= 0) - return -1; /* we've already encountered a decimal point. */ - point = nd; - break; - case '-': - case '+': - if (sign != 0 || nd > 0) - return -1; /* we've already encountered a sign, or if its - not at first position. */ - sign = (ch == '-') ? -1 : 1; - break; - case 'E': - case 'e': - int nread; - nread = std::sscanf(p+1, "%d", &e); - done = true; - if (nread != 1) - return -1; /* read of exponent failed. */ - break; - case ' ': - done = true; - break; - default: - return -1; - - } - } - - p++; - } - - - - /* Adjust exponent to account for decimal point */ - if (point >= 0) { - e -= (nd - point); - } - - /* Multiply the the exponent */ - if (e != 0) { - r *= (qd_real(10.0) ^ e); - } - - qd = (sign < 0) ? -r : r; - return 0; -} - -void qd_real::to_digits(char *s, int &expn, int precision) const { - int D = precision + 1; /* number of digits to compute */ - - qd_real r = abs(*this); - int e; /* exponent */ - int i, d; - - if (x[0] == 0.0) { - /* this == 0.0 */ - expn = 0; - for (i = 0; i < precision; i++) s[i] = '0'; - return; - } - - /* First determine the (approximate) exponent. */ - e = static_cast<int>(std::floor(std::log10(std::abs(x[0])))); - - if (e < -300) { - r *= qd_real(10.0) ^ 300; - r /= qd_real(10.0) ^ (e + 300); - } else if (e > 300) { - r = ldexp(r, -53); - r /= qd_real(10.0) ^ e; - r = ldexp(r, 53); - } else { - r /= qd_real(10.0) ^ e; - } - - /* Fix exponent if we are off by one */ - if (r >= 10.0) { - r /= 10.0; - e++; - } else if (r < 1.0) { - r *= 10.0; - e--; - } - - if (r >= 10.0 || r < 1.0) { - qd_real::error("(qd_real::to_digits): can't compute exponent."); - return; - } - - /* Extract the digits */ - for (i = 0; i < D; i++) { - d = static_cast<int>(r[0]); - r -= d; - r *= 10.0; - - s[i] = static_cast<char>(d + '0'); - } - - /* Fix out of range digits. */ - for (i = D-1; i > 0; i--) { - if (s[i] < '0') { - s[i-1]--; - s[i] += 10; - } else if (s[i] > '9') { - s[i-1]++; - s[i] -= 10; - } - } - - if (s[0] <= '0') { - qd_real::error("(qd_real::to_digits): non-positive leading digit."); - return; - } - - /* Round, handle carry */ - if (s[D-1] >= '5') { - s[D-2]++; - - i = D-2; - while (i > 0 && s[i] > '9') { - s[i] -= 10; - s[--i]++; - } - } - - /* If first digit is 10, shift everything. */ - if (s[0] > '9') { - e++; - for (i = precision; i >= 2; i--) s[i] = s[i-1]; - s[0] = '1'; - s[1] = '0'; - } - - s[precision] = 0; - expn = e; -} - -/* Writes the quad-double number into the character array s of length len. - The integer d specifies how many significant digits to write. - The string s must be able to hold at least (d+8) characters. - showpos indicates whether to use the + sign, and uppercase indicates - whether the E or e is to be used for the exponent. */ -void qd_real::write(char *s, int len, int precision, - bool showpos, bool uppercase) const { - string str = to_string(precision, 0, ios_base::scientific, showpos, uppercase); - strncpy(s, str.c_str(), len-1); - s[len-1] = 0; -} - -void round_string_qd(char *s, int precision, int *offset){ - /* - Input string must be all digits or errors will occur. - */ - - int i; - int D = precision ; - - /* Round, handle carry */ - if (D>0 && s[D] >= '5') { - s[D-1]++; - - i = D-1; - while (i > 0 && s[i] > '9') { - s[i] -= 10; - s[--i]++; - } - } - - /* If first digit is 10, shift everything. */ - if (s[0] > '9') { - // e++; // don't modify exponent here - for (i = precision; i >= 1; i--) s[i+1] = s[i]; - s[0] = '1'; - s[1] = '0'; - - (*offset)++ ; // now offset needs to be increased by one - precision++ ; - } - - s[precision] = 0; // add terminator for array -} - - -string qd_real::to_string(int precision, int width, ios_base::fmtflags fmt, - bool showpos, bool uppercase, char fill) const { - string s; - bool fixed = (fmt & ios_base::fixed) != 0; - bool sgn = true; - int i, e = 0; - - if (isinf()) { - if (*this < 0.0) - s += '-'; - else if (showpos) - s += '+'; - else - sgn = false; - s += uppercase ? "INF" : "inf"; - } else if (isnan()) { - s = uppercase ? "NAN" : "nan"; - sgn = false; - } else { - if (*this < 0.0) - s += '-'; - else if (showpos) - s += '+'; - else - sgn = false; - - if (*this == 0.0) { - /* Zero case */ - s += '0'; - if (precision > 0) { - s += '.'; - s.append(precision, '0'); - } - } else { - /* Non-zero case */ - int off = (fixed ? (1 + to_int(floor(log10(abs(*this))))) : 1); - int d = precision + off; - - int d_with_extra = d; - if(fixed) - d_with_extra = std::max(120, d); // longer than the max accuracy for DD - - // highly special case - fixed mode, precision is zero, abs(*this) < 1.0 - // without this trap a number like 0.9 printed fixed with 0 precision prints as 0 - // should be rounded to 1. - if(fixed && (precision == 0) && (abs(*this) < 1.0)){ - if(abs(*this) >= 0.5) - s += '1'; - else - s += '0'; - - return s; - } - - // handle near zero to working precision (but not exactly zero) - if (fixed && d <= 0) { - s += '0'; - if (precision > 0) { - s += '.'; - s.append(precision, '0'); - } - } else { // default - - char *t ; // = new char[d+1]; - int j; - - if(fixed){ - t = new char[d_with_extra+1]; - to_digits(t, e, d_with_extra); - } - else{ - t = new char[d+1]; - to_digits(t, e, d); - } - - off = e + 1; - - if (fixed) { - // fix the string if it's been computed incorrectly - // round here in the decimal string if required - round_string_qd(t, d, &off); - - if (off > 0) { - for (i = 0; i < off; i++) s += t[i]; - if (precision > 0) { - s += '.'; - for (j = 0; j < precision; j++, i++) s += t[i]; - } - } else { - s += "0."; - if (off < 0) s.append(-off, '0'); - for (i = 0; i < d; i++) s += t[i]; - } - } else { - s += t[0]; - if (precision > 0) s += '.'; - - for (i = 1; i <= precision; i++) - s += t[i]; - - } - delete [] t; - } - } - - // trap for improper offset with large values - // without this trap, output of values of the for 10^j - 1 fail for j > 28 - // and are output with the point in the wrong place, leading to a dramatically off value - if(fixed && (precision > 0)){ - // make sure that the value isn't dramatically larger - double from_string = atof(s.c_str()); - - // if this ratio is large, then we've got problems - if( fabs( from_string / this->x[0] ) > 3.0 ){ - - // loop on the string, find the point, move it up one - // don't act on the first character - for(i=1; i < (int)s.length(); i++){ - if(s[i] == '.'){ - s[i] = s[i-1] ; - s[i-1] = '.' ; - break; - } - } - - from_string = atof(s.c_str()); - // if this ratio is large, then the string has not been fixed - if( fabs( from_string / this->x[0] ) > 3.0 ){ - dd_real::error("Re-rounding unsuccessful in large number fixed point trap.") ; - } - } - } - - if (!fixed) { - /* Fill in exponent part */ - s += uppercase ? 'E' : 'e'; - append_expn(s, e); - } - } - - /* Fill in the blanks */ - size_t len = s.length(); - if (len < width) { - int delta = width - len; - if (fmt & ios_base::internal) { - if (sgn) - s.insert(static_cast<string::size_type>(1), delta, fill); - else - s.insert(static_cast<string::size_type>(0), delta, fill); - } else if (fmt & ios_base::left) { - s.append(delta, fill); - } else { - s.insert(static_cast<string::size_type>(0), delta, fill); - } - } - - return s; -} - -/* Computes qd^n, where n is an integer. */ -qd_real pow(const qd_real &a, int n) { - if (n == 0) - return 1.0; - - qd_real r = a; /* odd-case multiplier */ - qd_real s = 1.0; /* current answer */ - int N = std::abs(n); - - if (N > 1) { - - /* Use binary exponentiation. */ - while (N > 0) { - if (N % 2 == 1) { - /* If odd, multiply by r. Note eventually N = 1, so this - eventually executes. */ - s *= r; - } - N /= 2; - if (N > 0) - r = sqr(r); - } - - } else { - s = r; - } - - if (n < 0) - return (1.0 / s); - - return s; -} - -qd_real pow(const qd_real &a, const qd_real &b) { - return exp(b * log(a)); -} - -qd_real npwr(const qd_real &a, int n) { - return pow(a, n); -} - -/* Debugging routines */ -void qd_real::dump_bits(const string &name, std::ostream &os) const { - string::size_type len = name.length(); - if (len > 0) { - os << name << " = "; - len += 3; - } - os << "[ "; - len += 2; - for (int j = 0; j < 4; j++) { - if (j > 0) for (string::size_type i = 0; i < len; i++) os << ' '; - print_double_info(os, x[j]); - if (j < 3) - os << endl; - else - os << " ]" << endl; - } -} - -void qd_real::dump(const string &name, std::ostream &os) const { - std::ios_base::fmtflags old_flags = os.flags(); - std::streamsize old_prec = os.precision(19); - os << std::scientific; - - string::size_type len = name.length(); - if (len > 0) { - os << name << " = "; - len += 3; - } - os << "[ "; - len += 2; - os << setw(27) << x[0] << ", " << setw(26) << x[1] << "," << endl; - for (string::size_type i = 0; i < len; i++) os << ' '; - os << setw(27) << x[2] << ", " << setw(26) << x[3] << " ]" << endl; - - os.precision(old_prec); - os.flags(old_flags); -} - -/* Divisions */ -/* quad-double / double-double */ -qd_real qd_real::sloppy_div(const qd_real &a, const dd_real &b) { - double q0, q1, q2, q3; - qd_real r; - qd_real qd_b(b); - - q0 = a[0] / b._hi(); - r = a - q0 * qd_b; - - q1 = r[0] / b._hi(); - r -= (q1 * qd_b); - - q2 = r[0] / b._hi(); - r -= (q2 * qd_b); - - q3 = r[0] / b._hi(); - - ::renorm(q0, q1, q2, q3); - return qd_real(q0, q1, q2, q3); -} - -qd_real qd_real::accurate_div(const qd_real &a, const dd_real &b) { - double q0, q1, q2, q3, q4; - qd_real r; - qd_real qd_b(b); - - q0 = a[0] / b._hi(); - r = a - q0 * qd_b; - - q1 = r[0] / b._hi(); - r -= (q1 * qd_b); - - q2 = r[0] / b._hi(); - r -= (q2 * qd_b); - - q3 = r[0] / b._hi(); - r -= (q3 * qd_b); - - q4 = r[0] / b._hi(); - - ::renorm(q0, q1, q2, q3, q4); - return qd_real(q0, q1, q2, q3); -} - -/* quad-double / quad-double */ -qd_real qd_real::sloppy_div(const qd_real &a, const qd_real &b) { - double q0, q1, q2, q3; - - qd_real r; - - q0 = a[0] / b[0]; - r = a - (b * q0); - - q1 = r[0] / b[0]; - r -= (b * q1); - - q2 = r[0] / b[0]; - r -= (b * q2); - - q3 = r[0] / b[0]; - - ::renorm(q0, q1, q2, q3); - - return qd_real(q0, q1, q2, q3); -} - -qd_real qd_real::accurate_div(const qd_real &a, const qd_real &b) { - double q0, q1, q2, q3; - - qd_real r; - - q0 = a[0] / b[0]; - r = a - (b * q0); - - q1 = r[0] / b[0]; - r -= (b * q1); - - q2 = r[0] / b[0]; - r -= (b * q2); - - q3 = r[0] / b[0]; - - r -= (b * q3); - double q4 = r[0] / b[0]; - - ::renorm(q0, q1, q2, q3, q4); - - return qd_real(q0, q1, q2, q3); -} - -QD_API qd_real sqrt(const qd_real &a) { - /* Strategy: - - Perform the following Newton iteration: - - x' = x + (1 - a * x^2) * x / 2; - - which converges to 1/sqrt(a), starting with the - double precision approximation to 1/sqrt(a). - Since Newton's iteration more or less doubles the - number of correct digits, we only need to perform it - twice. - */ - - if (a.is_zero()) - return 0.0; - - if (a.is_negative()) { - qd_real::error("(qd_real::sqrt): Negative argument."); - return qd_real::_nan; - } - - qd_real r = (1.0 / std::sqrt(a[0])); - qd_real h = mul_pwr2(a, 0.5); - - r += ((0.5 - h * sqr(r)) * r); - r += ((0.5 - h * sqr(r)) * r); - r += ((0.5 - h * sqr(r)) * r); - - r *= a; - return r; -} - - -/* Computes the n-th root of a */ -qd_real nroot(const qd_real &a, int n) { - /* Strategy: Use Newton's iteration to solve - - 1/(x^n) - a = 0 - - Newton iteration becomes - - x' = x + x * (1 - a * x^n) / n - - Since Newton's iteration converges quadratically, - we only need to perform it twice. - - */ - if (n <= 0) { - qd_real::error("(qd_real::nroot): N must be positive."); - return qd_real::_nan; - } - - if (n % 2 == 0 && a.is_negative()) { - qd_real::error("(qd_real::nroot): Negative argument."); - return qd_real::_nan; - } - - if (n == 1) { - return a; - } - if (n == 2) { - return sqrt(a); - } - if (a.is_zero()) { - return qd_real(0.0); - } - - - /* Note a^{-1/n} = exp(-log(a)/n) */ - qd_real r = abs(a); - qd_real x = std::exp(-std::log(r.x[0]) / n); - - /* Perform Newton's iteration. */ - double dbl_n = static_cast<double>(n); - x += x * (1.0 - r * npwr(x, n)) / dbl_n; - x += x * (1.0 - r * npwr(x, n)) / dbl_n; - x += x * (1.0 - r * npwr(x, n)) / dbl_n; - if (a[0] < 0.0){ - x = -x; - } - return 1.0 / x; -} - -static const int n_inv_fact = 15; -static const qd_real inv_fact[n_inv_fact] = { - qd_real( 1.66666666666666657e-01, 9.25185853854297066e-18, - 5.13581318503262866e-34, 2.85094902409834186e-50), - qd_real( 4.16666666666666644e-02, 2.31296463463574266e-18, - 1.28395329625815716e-34, 7.12737256024585466e-51), - qd_real( 8.33333333333333322e-03, 1.15648231731787138e-19, - 1.60494162032269652e-36, 2.22730392507682967e-53), - qd_real( 1.38888888888888894e-03, -5.30054395437357706e-20, - -1.73868675534958776e-36, -1.63335621172300840e-52), - qd_real( 1.98412698412698413e-04, 1.72095582934207053e-22, - 1.49269123913941271e-40, 1.29470326746002471e-58), - qd_real( 2.48015873015873016e-05, 2.15119478667758816e-23, - 1.86586404892426588e-41, 1.61837908432503088e-59), - qd_real( 2.75573192239858925e-06, -1.85839327404647208e-22, - 8.49175460488199287e-39, -5.72661640789429621e-55), - qd_real( 2.75573192239858883e-07, 2.37677146222502973e-23, - -3.26318890334088294e-40, 1.61435111860404415e-56), - qd_real( 2.50521083854417202e-08, -1.44881407093591197e-24, - 2.04267351467144546e-41, -8.49632672007163175e-58), - qd_real( 2.08767569878681002e-09, -1.20734505911325997e-25, - 1.70222792889287100e-42, 1.41609532150396700e-58), - qd_real( 1.60590438368216133e-10, 1.25852945887520981e-26, - -5.31334602762985031e-43, 3.54021472597605528e-59), - qd_real( 1.14707455977297245e-11, 2.06555127528307454e-28, - 6.88907923246664603e-45, 5.72920002655109095e-61), - qd_real( 7.64716373181981641e-13, 7.03872877733453001e-30, - -7.82753927716258345e-48, 1.92138649443790242e-64), - qd_real( 4.77947733238738525e-14, 4.39920548583408126e-31, - -4.89221204822661465e-49, 1.20086655902368901e-65), - qd_real( 2.81145725434552060e-15, 1.65088427308614326e-31, - -2.87777179307447918e-50, 4.27110689256293549e-67) -}; - -qd_real exp(const qd_real &a) { - /* Strategy: We first reduce the size of x by noting that - - exp(kr + m * log(2)) = 2^m * exp(r)^k - - where m and k are integers. By choosing m appropriately - we can make |kr| <= log(2) / 2 = 0.347. Then exp(r) is - evaluated using the familiar Taylor series. Reducing the - argument substantially speeds up the convergence. */ - - const double k = ldexp(1.0, 16); - const double inv_k = 1.0 / k; - - if (a[0] <= -709.0) - return 0.0; - - if (a[0] >= 709.0) - return qd_real::_inf; - - if (a.is_zero()) - return 1.0; - - if (a.is_one()) - return qd_real::_e; - - double m = std::floor(a.x[0] / qd_real::_log2.x[0] + 0.5); - qd_real r = mul_pwr2(a - qd_real::_log2 * m, inv_k); - qd_real s, p, t; - double thresh = inv_k * qd_real::_eps; - - p = sqr(r); - s = r + mul_pwr2(p, 0.5); - int i = 0; - do { - p *= r; - t = p * inv_fact[i++]; - s += t; - } while (std::abs(to_double(t)) > thresh && i < 9); - - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s = mul_pwr2(s, 2.0) + sqr(s); - s += 1.0; - return ldexp(s, static_cast<int>(m)); -} - -/* Logarithm. Computes log(x) in quad-double precision. - This is a natural logarithm (i.e., base e). */ -qd_real log(const qd_real &a) { - /* Strategy. The Taylor series for log converges much more - slowly than that of exp, due to the lack of the factorial - term in the denominator. Hence this routine instead tries - to determine the root of the function - - f(x) = exp(x) - a - - using Newton iteration. The iteration is given by - - x' = x - f(x)/f'(x) - = x - (1 - a * exp(-x)) - = x + a * exp(-x) - 1. - - Two iteration is needed, since Newton's iteration - approximately doubles the number of digits per iteration. */ - - if (a.is_one()) { - return 0.0; - } - - if (a[0] <= 0.0) { - qd_real::error("(qd_real::log): Non-positive argument."); - return qd_real::_nan; - } - - if (a[0] == 0.0) { - return -qd_real::_inf; - } - - qd_real x = std::log(a[0]); /* Initial approximation */ - - x = x + a * exp(-x) - 1.0; - x = x + a * exp(-x) - 1.0; - x = x + a * exp(-x) - 1.0; - - return x; -} - -qd_real log10(const qd_real &a) { - return log(a) / qd_real::_log10; -} - -static const qd_real _pi1024 = qd_real( - 3.067961575771282340e-03, 1.195944139792337116e-19, - -2.924579892303066080e-36, 1.086381075061880158e-52); - -/* Table of sin(k * pi/1024) and cos(k * pi/1024). */ -static const qd_real sin_table [] = { - qd_real( 3.0679567629659761e-03, 1.2690279085455925e-19, - 5.2879464245328389e-36, -1.7820334081955298e-52), - qd_real( 6.1358846491544753e-03, 9.0545257482474933e-20, - 1.6260113133745320e-37, -9.7492001208767410e-55), - qd_real( 9.2037547820598194e-03, -1.2136591693535934e-19, - 5.5696903949425567e-36, 1.2505635791936951e-52), - qd_real( 1.2271538285719925e-02, 6.9197907640283170e-19, - -4.0203726713435555e-36, -2.0688703606952816e-52), - qd_real( 1.5339206284988102e-02, -8.4462578865401696e-19, - 4.6535897505058629e-35, -1.3923682978570467e-51), - qd_real( 1.8406729905804820e-02, 7.4195533812833160e-19, - 3.9068476486787607e-35, 3.6393321292898614e-52), - qd_real( 2.1474080275469508e-02, -4.5407960207688566e-19, - -2.2031770119723005e-35, 1.2709814654833741e-51), - qd_real( 2.4541228522912288e-02, -9.1868490125778782e-20, - 4.8706148704467061e-36, -2.8153947855469224e-52), - qd_real( 2.7608145778965743e-02, -1.5932358831389269e-18, - -7.0475416242776030e-35, -2.7518494176602744e-51), - qd_real( 3.0674803176636626e-02, -1.6936054844107918e-20, - -2.0039543064442544e-36, -1.6267505108658196e-52), - qd_real( 3.3741171851377587e-02, -2.0096074292368340e-18, - -1.3548237016537134e-34, 6.5554881875899973e-51), - qd_real( 3.6807222941358832e-02, 6.1060088803529842e-19, - -4.0448721259852727e-35, -2.1111056765671495e-51), - qd_real( 3.9872927587739811e-02, 4.6657453481183289e-19, - 3.4119333562288684e-35, 2.4007534726187511e-51), - qd_real( 4.2938256934940820e-02, 2.8351940588660907e-18, - 1.6991309601186475e-34, 6.8026536098672629e-51), - qd_real( 4.6003182130914630e-02, -1.1182813940157788e-18, - 7.5235020270378946e-35, 4.1187304955493722e-52), - qd_real( 4.9067674327418015e-02, -6.7961037205182801e-19, - -4.4318868124718325e-35, -9.9376628132525316e-52), - qd_real( 5.2131704680283324e-02, -2.4243695291953779e-18, - -1.3675405320092298e-34, -8.3938137621145070e-51), - qd_real( 5.5195244349689941e-02, -1.3340299860891103e-18, - -3.4359574125665608e-35, 1.1911462755409369e-51), - qd_real( 5.8258264500435759e-02, 2.3299905496077492e-19, - 1.9376108990628660e-36, -5.1273775710095301e-53), - qd_real( 6.1320736302208578e-02, -5.1181134064638108e-19, - -4.2726335866706313e-35, 2.6368495557440691e-51), - qd_real( 6.4382630929857465e-02, -4.2325997000052705e-18, - 3.3260117711855937e-35, 1.4736267706718352e-51), - qd_real( 6.7443919563664065e-02, -6.9221796556983636e-18, - 1.5909286358911040e-34, -7.8828946891835218e-51), - qd_real( 7.0504573389613870e-02, -6.8552791107342883e-18, - -1.9961177630841580e-34, 2.0127129580485300e-50), - qd_real( 7.3564563599667426e-02, -2.7784941506273593e-18, - -9.1240375489852821e-35, -1.9589752023546795e-51), - qd_real( 7.6623861392031492e-02, 2.3253700287958801e-19, - -1.3186083921213440e-36, -4.9927872608099673e-53), - qd_real( 7.9682437971430126e-02, -4.4867664311373041e-18, - 2.8540789143650264e-34, 2.8491348583262741e-51), - qd_real( 8.2740264549375692e-02, 1.4735983530877760e-18, - 3.7284093452233713e-35, 2.9024430036724088e-52), - qd_real( 8.5797312344439894e-02, -3.3881893830684029e-18, - -1.6135529531508258e-34, 7.7294651620588049e-51), - qd_real( 8.8853552582524600e-02, -3.7501775830290691e-18, - 3.7543606373911573e-34, 2.2233701854451859e-50), - qd_real( 9.1908956497132724e-02, 4.7631594854274564e-18, - 1.5722874642939344e-34, -4.8464145447831456e-51), - qd_real( 9.4963495329639006e-02, -6.5885886400417564e-18, - -2.1371116991641965e-34, 1.3819370559249300e-50), - qd_real( 9.8017140329560604e-02, -1.6345823622442560e-18, - -1.3209238810006454e-35, -3.5691060049117942e-52), - qd_real( 1.0106986275482782e-01, 3.3164325719308656e-18, - -1.2004224885132282e-34, 7.2028828495418631e-51), - qd_real( 1.0412163387205457e-01, 6.5760254085385100e-18, - 1.7066246171219214e-34, -4.9499340996893514e-51), - qd_real( 1.0717242495680884e-01, 6.4424044279026198e-18, - -8.3956976499698139e-35, -4.0667730213318321e-51), - qd_real( 1.1022220729388306e-01, -5.6789503537823233e-19, - 1.0380274792383233e-35, 1.5213997918456695e-52), - qd_real( 1.1327095217756435e-01, 2.7100481012132900e-18, - 1.5323292999491619e-35, 4.9564432810360879e-52), - qd_real( 1.1631863091190477e-01, 1.0294914877509705e-18, - -9.3975734948993038e-35, 1.3534827323719708e-52), - qd_real( 1.1936521481099137e-01, -3.9500089391898506e-18, - 3.5317349978227311e-34, 1.8856046807012275e-51), - qd_real( 1.2241067519921620e-01, 2.8354501489965335e-18, - 1.8151655751493305e-34, -2.8716592177915192e-51), - qd_real( 1.2545498341154623e-01, 4.8686751763148235e-18, - 5.9878105258097936e-35, -3.3534629098722107e-51), - qd_real( 1.2849811079379317e-01, 3.8198603954988802e-18, - -1.8627501455947798e-34, -2.4308161133527791e-51), - qd_real( 1.3154002870288312e-01, -5.0039708262213813e-18, - -1.2983004159245552e-34, -4.6872034915794122e-51), - qd_real( 1.3458070850712620e-01, -9.1670359171480699e-18, - 1.5916493007073973e-34, 4.0237002484366833e-51), - qd_real( 1.3762012158648604e-01, 6.6253255866774482e-18, - -2.3746583031401459e-34, -9.3703876173093250e-52), - qd_real( 1.4065823933284924e-01, -7.9193932965524741e-18, - 6.0972464202108397e-34, 2.4566623241035797e-50), - qd_real( 1.4369503315029444e-01, 1.1472723016618666e-17, - -5.1884954557576435e-35, -4.2220684832186607e-51), - qd_real( 1.4673047445536175e-01, 3.7269471470465677e-18, - 3.7352398151250827e-34, -4.0881822289508634e-51), - qd_real( 1.4976453467732151e-01, 8.0812114131285151e-18, - 1.2979142554917325e-34, 9.9380667487736254e-51), - qd_real( 1.5279718525844344e-01, -7.6313573938416838e-18, - 5.7714690450284125e-34, -3.7731132582986687e-50), - qd_real( 1.5582839765426523e-01, 3.0351307187678221e-18, - -1.0976942315176184e-34, 7.8734647685257867e-51), - qd_real( 1.5885814333386145e-01, -4.0163200573859079e-18, - -9.2840580257628812e-35, -2.8567420029274875e-51), - qd_real( 1.6188639378011183e-01, 1.1850519643573528e-17, - -5.0440990519162957e-34, 3.0510028707928009e-50), - qd_real( 1.6491312048996992e-01, -7.0405288319166738e-19, - 3.3211107491245527e-35, 8.6663299254686031e-52), - qd_real( 1.6793829497473117e-01, 5.4284533721558139e-18, - -3.3263339336181369e-34, -1.8536367335123848e-50), - qd_real( 1.7096188876030122e-01, 9.1919980181759094e-18, - -6.7688743940982606e-34, -1.0377711384318389e-50), - qd_real( 1.7398387338746382e-01, 5.8151994618107928e-18, - -1.6751014298301606e-34, -6.6982259797164963e-51), - qd_real( 1.7700422041214875e-01, 6.7329300635408167e-18, - 2.8042736644246623e-34, 3.6786888232793599e-51), - qd_real( 1.8002290140569951e-01, 7.9701826047392143e-18, - -7.0765920110524977e-34, 1.9622512608461784e-50), - qd_real( 1.8303988795514095e-01, 7.7349918688637383e-18, - -4.4803769968145083e-34, 1.1201148793328890e-50), - qd_real( 1.8605515166344666e-01, -1.2564893007679552e-17, - 7.5953844248530810e-34, -3.8471695132415039e-51), - qd_real( 1.8906866414980622e-01, -7.6208955803527778e-18, - -4.4792298656662981e-34, -4.4136824096645007e-50), - qd_real( 1.9208039704989244e-01, 4.3348343941174903e-18, - -2.3404121848139937e-34, 1.5789970962611856e-50), - qd_real( 1.9509032201612828e-01, -7.9910790684617313e-18, - 6.1846270024220713e-34, -3.5840270918032937e-50), - qd_real( 1.9809841071795359e-01, -1.8434411800689445e-18, - 1.4139031318237285e-34, 1.0542811125343809e-50), - qd_real( 2.0110463484209190e-01, 1.1010032669300739e-17, - -3.9123576757413791e-34, 2.4084852500063531e-51), - qd_real( 2.0410896609281687e-01, 6.0941297773957752e-18, - -2.8275409970449641e-34, 4.6101008563532989e-51), - qd_real( 2.0711137619221856e-01, -1.0613362528971356e-17, - 2.2456805112690884e-34, 1.3483736125280904e-50), - qd_real( 2.1011183688046961e-01, 1.1561548476512844e-17, - 6.0355905610401254e-34, 3.3329909618405675e-50), - qd_real( 2.1311031991609136e-01, 1.2031873821063860e-17, - -3.4142699719695635e-34, -1.2436262780241778e-50), - qd_real( 2.1610679707621952e-01, -1.0111196082609117e-17, - 7.2789545335189643e-34, -2.9347540365258610e-50), - qd_real( 2.1910124015686980e-01, -3.6513812299150776e-19, - -2.3359499418606442e-35, 3.1785298198458653e-52), - qd_real( 2.2209362097320354e-01, -3.0337210995812162e-18, - 6.6654668033632998e-35, 2.0110862322656942e-51), - qd_real( 2.2508391135979283e-01, 3.9507040822556510e-18, - 2.4287993958305375e-35, 5.6662797513020322e-52), - qd_real( 2.2807208317088573e-01, 8.2361837339258012e-18, - 6.9786781316397937e-34, -6.4122962482639504e-51), - qd_real( 2.3105810828067111e-01, 1.0129787149761869e-17, - -6.9359234615816044e-34, -2.8877355604883782e-50), - qd_real( 2.3404195858354343e-01, -6.9922402696101173e-18, - -5.7323031922750280e-34, 5.3092579966872727e-51), - qd_real( 2.3702360599436720e-01, 8.8544852285039918e-18, - 1.3588480826354134e-34, 1.0381022520213867e-50), - qd_real( 2.4000302244874150e-01, -1.2137758975632164e-17, - -2.6448807731703891e-34, -1.9929733800670473e-51), - qd_real( 2.4298017990326390e-01, -8.7514315297196632e-18, - -6.5723260373079431e-34, -1.0333158083172177e-50), - qd_real( 2.4595505033579462e-01, -1.1129044052741832e-17, - 4.3805998202883397e-34, 1.2219399554686291e-50), - qd_real( 2.4892760574572018e-01, -8.1783436100020990e-18, - 5.5666875261111840e-34, 3.8080473058748167e-50), - qd_real( 2.5189781815421697e-01, -1.7591436032517039e-17, - -1.0959681232525285e-33, 5.6209426020232456e-50), - qd_real( 2.5486565960451457e-01, -1.3602299806901461e-19, - -6.0073844642762535e-36, -3.0072751311893878e-52), - qd_real( 2.5783110216215899e-01, 1.8480038630879957e-17, - 3.3201664714047599e-34, -5.5547819290576764e-51), - qd_real( 2.6079411791527551e-01, 4.2721420983550075e-18, - 5.6782126934777920e-35, 3.1428338084365397e-51), - qd_real( 2.6375467897483140e-01, -1.8837947680038700e-17, - 1.3720129045754794e-33, -8.2763406665966033e-50), - qd_real( 2.6671275747489837e-01, 2.0941222578826688e-17, - -1.1303466524727989e-33, 1.9954224050508963e-50), - qd_real( 2.6966832557291509e-01, 1.5765657618133259e-17, - -6.9696142173370086e-34, -4.0455346879146776e-50), - qd_real( 2.7262135544994898e-01, 7.8697166076387850e-18, - 6.6179388602933372e-35, -2.7642903696386267e-51), - qd_real( 2.7557181931095814e-01, 1.9320328962556582e-17, - 1.3932094180100280e-33, 1.3617253920018116e-50), - qd_real( 2.7851968938505312e-01, -1.0030273719543544e-17, - 7.2592115325689254e-34, -1.0068516296655851e-50), - qd_real( 2.8146493792575800e-01, -1.2322299641274009e-17, - -1.0564788706386435e-34, 7.5137424251265885e-51), - qd_real( 2.8440753721127182e-01, 2.2209268510661475e-17, - -9.1823095629523708e-34, -5.2192875308892218e-50), - qd_real( 2.8734745954472951e-01, 1.5461117367645717e-17, - -6.3263973663444076e-34, -2.2982538416476214e-50), - qd_real( 2.9028467725446239e-01, -1.8927978707774251e-17, - 1.1522953157142315e-33, 7.4738655654716596e-50), - qd_real( 2.9321916269425863e-01, 2.2385430811901833e-17, - 1.3662484646539680e-33, -4.2451325253996938e-50), - qd_real( 2.9615088824362384e-01, -2.0220736360876938e-17, - -7.9252212533920413e-35, -2.8990577729572470e-51), - qd_real( 2.9907982630804048e-01, 1.6701181609219447e-18, - 8.6091151117316292e-35, 3.9931286230012102e-52), - qd_real( 3.0200594931922808e-01, -1.7167666235262474e-17, - 2.3336182149008069e-34, 8.3025334555220004e-51), - qd_real( 3.0492922973540243e-01, -2.2989033898191262e-17, - -1.4598901099661133e-34, 3.7760487693121827e-51), - qd_real( 3.0784964004153487e-01, 2.7074088527245185e-17, - 1.2568858206899284e-33, 7.2931815105901645e-50), - qd_real( 3.1076715274961147e-01, 2.0887076364048513e-17, - -3.0130590791065942e-34, 1.3876739009935179e-51), - qd_real( 3.1368174039889146e-01, 1.4560447299968912e-17, - 3.6564186898011595e-34, 1.1654264734999375e-50), - qd_real( 3.1659337555616585e-01, 2.1435292512726283e-17, - 1.2338169231377316e-33, 3.3963542100989293e-50), - qd_real( 3.1950203081601569e-01, -1.3981562491096626e-17, - 8.1730000697411350e-34, -7.7671096270210952e-50), - qd_real( 3.2240767880106985e-01, -4.0519039937959398e-18, - 3.7438302780296796e-34, 8.7936731046639195e-51), - qd_real( 3.2531029216226293e-01, 7.9171249463765892e-18, - -6.7576622068146391e-35, 2.3021655066929538e-51), - qd_real( 3.2820984357909255e-01, -2.6693140719641896e-17, - 7.8928851447534788e-34, 2.5525163821987809e-51), - qd_real( 3.3110630575987643e-01, -2.7469465474778694e-17, - -1.3401245916610206e-33, 6.5531762489976163e-50), - qd_real( 3.3399965144200938e-01, 2.2598986806288142e-17, - 7.8063057192586115e-34, 2.0427600895486683e-50), - qd_real( 3.3688985339222005e-01, -4.2000940033475092e-19, - -2.9178652969985438e-36, -1.1597376437036749e-52), - qd_real( 3.3977688440682685e-01, 6.6028679499418282e-18, - 1.2575009988669683e-34, 2.5569067699008304e-51), - qd_real( 3.4266071731199438e-01, 1.9261518449306319e-17, - -9.2754189135990867e-34, 8.5439996687390166e-50), - qd_real( 3.4554132496398904e-01, 2.7251143672916123e-17, - 7.0138163601941737e-34, -1.4176292197454015e-50), - qd_real( 3.4841868024943456e-01, 3.6974420514204918e-18, - 3.5532146878499996e-34, 1.9565462544501322e-50), - qd_real( 3.5129275608556715e-01, -2.2670712098795844e-17, - -1.6994216673139631e-34, -1.2271556077284517e-50), - qd_real( 3.5416352542049040e-01, -1.6951763305764860e-17, - 1.2772331777814617e-33, -3.3703785435843310e-50), - qd_real( 3.5703096123343003e-01, -4.8218191137919166e-19, - -4.1672436994492361e-35, -7.1531167149364352e-52), - qd_real( 3.5989503653498817e-01, -1.7601687123839282e-17, - 1.3375125473046791e-33, 7.9467815593584340e-50), - qd_real( 3.6275572436739723e-01, -9.1668352663749849e-18, - -7.4317843956936735e-34, -2.0199582511804564e-50), - qd_real( 3.6561299780477385e-01, 1.6217898770457546e-17, - 1.1286970151961055e-33, -7.1825287318139010e-50), - qd_real( 3.6846682995337232e-01, 1.0463640796159268e-17, - 2.0554984738517304e-35, 1.0441861305618769e-51), - qd_real( 3.7131719395183754e-01, 3.4749239648238266e-19, - -7.5151053042866671e-37, -2.8153468438650851e-53), - qd_real( 3.7416406297145799e-01, 8.0114103761962118e-18, - 5.3429599813406052e-34, 1.0351378796539210e-50), - qd_real( 3.7700741021641826e-01, -2.7255302041956930e-18, - 6.3646586445018137e-35, 8.3048657176503559e-52), - qd_real( 3.7984720892405116e-01, 9.9151305855172370e-18, - 4.8761409697224886e-34, 1.4025084000776705e-50), - qd_real( 3.8268343236508978e-01, -1.0050772696461588e-17, - -2.0605316302806695e-34, -1.2717724698085205e-50), - qd_real( 3.8551605384391885e-01, 1.5177665396472313e-17, - 1.4198230518016535e-33, 5.8955167159904235e-50), - qd_real( 3.8834504669882630e-01, -1.0053770598398717e-17, - 7.5942999255057131e-34, -3.1967974046654219e-50), - qd_real( 3.9117038430225387e-01, 1.7997787858243995e-17, - -1.0613482402609856e-33, -5.4582148817791032e-50), - qd_real( 3.9399204006104810e-01, 9.7649241641239336e-18, - -2.1233599441284617e-34, -5.5529836795340819e-51), - qd_real( 3.9680998741671031e-01, 2.0545063670840126e-17, - 6.1347058801922842e-34, 1.0733788150636430e-50), - qd_real( 3.9962419984564684e-01, -1.5065497476189372e-17, - -9.9653258881867298e-34, -5.7524323712725355e-50), - qd_real( 4.0243465085941843e-01, 1.0902619339328270e-17, - 7.3998528125989765e-34, 2.2745784806823499e-50), - qd_real( 4.0524131400498986e-01, 9.9111401942899884e-18, - -2.5169070895434648e-34, 9.2772984818436573e-53), - qd_real( 4.0804416286497869e-01, -7.0006015137351311e-18, - -1.4108207334268228e-34, 1.5175546997577136e-52), - qd_real( 4.1084317105790397e-01, -2.4219835190355499e-17, - -1.1418902925313314e-33, -2.0996843165093468e-50), - qd_real( 4.1363831223843456e-01, -1.0393984940597871e-17, - -1.1481681174503880e-34, -2.0281052851028680e-51), - qd_real( 4.1642956009763721e-01, -2.5475580413131732e-17, - -3.4482678506112824e-34, 7.1788619351865480e-51), - qd_real( 4.1921688836322396e-01, -4.2232463750110590e-18, - -3.6053023045255790e-34, -2.2209673210025631e-50), - qd_real( 4.2200027079979968e-01, 4.3543266994128527e-18, - 3.1734310272251190e-34, -1.3573247980738668e-50), - qd_real( 4.2477968120910881e-01, 2.7462312204277281e-17, - -4.6552847802111948e-34, 6.5961781099193122e-51), - qd_real( 4.2755509343028208e-01, 9.4111898162954726e-18, - -1.7446682426598801e-34, -2.2054492626480169e-51), - qd_real( 4.3032648134008261e-01, 2.2259686974092690e-17, - 8.5972591314085075e-34, -2.9420897889003020e-50), - qd_real( 4.3309381885315196e-01, 1.1224283329847517e-17, - 5.3223748041075651e-35, 5.3926192627014212e-51), - qd_real( 4.3585707992225547e-01, 1.6230515450644527e-17, - -6.4371449063579431e-35, -6.9102436481386757e-51), - qd_real( 4.3861623853852766e-01, -2.0883315831075090e-17, - -1.4259583540891877e-34, 6.3864763590657077e-52), - qd_real( 4.4137126873171667e-01, 2.2360783886964969e-17, - 1.1864769603515770e-34, -3.8087003266189232e-51), - qd_real( 4.4412214457042926e-01, -2.4218874422178315e-17, - 2.2205230838703907e-34, 9.2133035911356258e-51), - qd_real( 4.4686884016237421e-01, -1.9222136142309382e-17, - -4.4425678589732049e-35, -1.3673609292149535e-51), - qd_real( 4.4961132965460660e-01, 4.8831924232035243e-18, - 2.7151084498191381e-34, -1.5653993171613154e-50), - qd_real( 4.5234958723377089e-01, -1.4827977472196122e-17, - -7.6947501088972324e-34, 1.7656856882031319e-50), - qd_real( 4.5508358712634384e-01, -1.2379906758116472e-17, - 5.5289688955542643e-34, -8.5382312840209386e-51), - qd_real( 4.5781330359887723e-01, -8.4554254922295949e-18, - -6.3770394246764263e-34, 3.1778253575564249e-50), - qd_real( 4.6053871095824001e-01, 1.8488777492177872e-17, - -1.0527732154209725e-33, 3.3235593490947102e-50), - qd_real( 4.6325978355186020e-01, -7.3514924533231707e-18, - 6.7175396881707035e-34, 3.9594127612123379e-50), - qd_real( 4.6597649576796618e-01, -3.3023547778235135e-18, - 3.4904677050476886e-35, 3.4483855263874246e-51), - qd_real( 4.6868882203582796e-01, -2.2949251681845054e-17, - -1.1364757641823658e-33, 6.8840522501918612e-50), - qd_real( 4.7139673682599764e-01, 6.5166781360690130e-18, - 2.9457546966235984e-34, -6.2159717738836630e-51), - qd_real( 4.7410021465055002e-01, -8.1451601548978075e-18, - -3.4789448555614422e-34, -1.1681943974658508e-50), - qd_real( 4.7679923006332214e-01, -1.0293515338305794e-17, - -3.6582045008369952e-34, 1.7424131479176475e-50), - qd_real( 4.7949375766015301e-01, 1.8419999662684771e-17, - -1.3040838621273312e-33, 1.0977131822246471e-50), - qd_real( 4.8218377207912277e-01, -2.5861500925520442e-17, - -6.2913197606500007e-36, 4.0802359808684726e-52), - qd_real( 4.8486924800079112e-01, -1.8034004203262245e-17, - -3.5244276906958044e-34, -1.7138318654749246e-50), - qd_real( 4.8755016014843594e-01, 1.4231090931273653e-17, - -1.8277733073262697e-34, -1.5208291790429557e-51), - qd_real( 4.9022648328829116e-01, -5.1496145643440404e-18, - -3.6903027405284104e-34, 1.5172940095151304e-50), - qd_real( 4.9289819222978404e-01, -1.0257831676562186e-18, - 6.9520817760885069e-35, -2.4260961214090389e-51), - qd_real( 4.9556526182577254e-01, -9.4323241942365362e-18, - 3.1212918657699143e-35, 4.2009072375242736e-52), - qd_real( 4.9822766697278187e-01, -1.6126383830540798e-17, - -1.5092897319298871e-33, 1.1049298890895917e-50), - qd_real( 5.0088538261124083e-01, -3.9604015147074639e-17, - -2.2208395201898007e-33, 1.3648202735839417e-49), - qd_real( 5.0353838372571758e-01, -1.6731308204967497e-17, - -1.0140233644074786e-33, 4.0953071937671477e-50), - qd_real( 5.0618664534515534e-01, -4.8321592986493711e-17, - 9.2858107226642252e-34, 4.2699802401037005e-50), - qd_real( 5.0883014254310699e-01, 4.7836968268014130e-17, - -1.0727022928806035e-33, 2.7309374513672757e-50), - qd_real( 5.1146885043797041e-01, -1.3088001221007579e-17, - 4.0929033363366899e-34, -3.7952190153477926e-50), - qd_real( 5.1410274419322177e-01, -4.5712707523615624e-17, - 1.5488279442238283e-33, -2.5853959305521130e-50), - qd_real( 5.1673179901764987e-01, 8.3018617233836515e-18, - 5.8251027467695202e-34, -2.2812397190535076e-50), - qd_real( 5.1935599016558964e-01, -5.5331248144171145e-17, - -3.1628375609769026e-35, -2.4091972051188571e-51), - qd_real( 5.2197529293715439e-01, -4.6555795692088883e-17, - 4.6378980936850430e-34, -3.3470542934689532e-51), - qd_real( 5.2458968267846895e-01, -4.3068869040082345e-17, - -4.2013155291932055e-34, -1.5096069926700274e-50), - qd_real( 5.2719913478190139e-01, -4.2202983480560619e-17, - 8.5585916184867295e-34, 7.9974339336732307e-50), - qd_real( 5.2980362468629472e-01, -4.8067841706482342e-17, - 5.8309721046630296e-34, -8.9740761521756660e-51), - qd_real( 5.3240312787719801e-01, -4.1020306135800895e-17, - -1.9239996374230821e-33, -1.5326987913812184e-49), - qd_real( 5.3499761988709726e-01, -5.3683132708358134e-17, - -1.3900569918838112e-33, 2.7154084726474092e-50), - qd_real( 5.3758707629564551e-01, -2.2617365388403054e-17, - -5.9787279033447075e-34, 3.1204419729043625e-51), - qd_real( 5.4017147272989285e-01, 2.7072447965935839e-17, - 1.1698799709213829e-33, -5.9094668515881500e-50), - qd_real( 5.4275078486451589e-01, 1.7148261004757101e-17, - -1.3525905925200870e-33, 4.9724411290727323e-50), - qd_real( 5.4532498842204646e-01, -4.1517817538384258e-17, - -1.5318930219385941e-33, 6.3629921101413974e-50), - qd_real( 5.4789405917310019e-01, -2.4065878297113363e-17, - -3.5639213669362606e-36, -2.6013270854271645e-52), - qd_real( 5.5045797293660481e-01, -8.3319903015807663e-18, - -2.3058454035767633e-34, -2.1611290432369010e-50), - qd_real( 5.5301670558002758e-01, -4.7061536623798204e-17, - -1.0617111545918056e-33, -1.6196316144407379e-50), - qd_real( 5.5557023301960218e-01, 4.7094109405616768e-17, - -2.0640520383682921e-33, 1.2290163188567138e-49), - qd_real( 5.5811853122055610e-01, 1.3481176324765226e-17, - -5.5016743873011438e-34, -2.3484822739335416e-50), - qd_real( 5.6066157619733603e-01, -7.3956418153476152e-18, - 3.9680620611731193e-34, 3.1995952200836223e-50), - qd_real( 5.6319934401383409e-01, 2.3835775146854829e-17, - 1.3511793173769814e-34, 9.3201311581248143e-51), - qd_real( 5.6573181078361323e-01, -3.4096079596590466e-17, - -1.7073289744303546e-33, 8.9147089975404507e-50), - qd_real( 5.6825895267013160e-01, -5.0935673642769248e-17, - -1.6274356351028249e-33, 9.8183151561702966e-51), - qd_real( 5.7078074588696726e-01, 2.4568151455566208e-17, - -1.2844481247560350e-33, -1.8037634376936261e-50), - qd_real( 5.7329716669804220e-01, 8.5176611669306400e-18, - -6.4443208788026766e-34, 2.2546105543273003e-50), - qd_real( 5.7580819141784534e-01, -3.7909495458942734e-17, - -2.7433738046854309e-33, 1.1130841524216795e-49), - qd_real( 5.7831379641165559e-01, -2.6237691512372831e-17, - 1.3679051680738167e-33, -3.1409808935335900e-50), - qd_real( 5.8081395809576453e-01, 1.8585338586613408e-17, - 2.7673843114549181e-34, 1.9605349619836937e-50), - qd_real( 5.8330865293769829e-01, 3.4516601079044858e-18, - 1.8065977478946306e-34, -6.3953958038544646e-51), - qd_real( 5.8579785745643886e-01, -3.7485501964311294e-18, - 2.7965403775536614e-34, -7.1816936024157202e-51), - qd_real( 5.8828154822264533e-01, -2.9292166725006846e-17, - -2.3744954603693934e-33, -1.1571631191512480e-50), - qd_real( 5.9075970185887428e-01, -4.7013584170659542e-17, - 2.4808417611768356e-33, 1.2598907673643198e-50), - qd_real( 5.9323229503979980e-01, 1.2892320944189053e-17, - 5.3058364776359583e-34, 4.1141674699390052e-50), - qd_real( 5.9569930449243336e-01, -1.3438641936579467e-17, - -6.7877687907721049e-35, -5.6046937531684890e-51), - qd_real( 5.9816070699634227e-01, 3.8801885783000657e-17, - -1.2084165858094663e-33, -4.0456610843430061e-50), - qd_real( 6.0061647938386897e-01, -4.6398198229461932e-17, - -1.6673493003710801e-33, 5.1982824378491445e-50), - qd_real( 6.0306659854034816e-01, 3.7323357680559650e-17, - 2.7771920866974305e-33, -1.6194229649742458e-49), - qd_real( 6.0551104140432555e-01, -3.1202672493305677e-17, - 1.2761267338680916e-33, -4.0859368598379647e-50), - qd_real( 6.0794978496777363e-01, 3.5160832362096660e-17, - -2.5546242776778394e-34, -1.4085313551220694e-50), - qd_real( 6.1038280627630948e-01, -2.2563265648229169e-17, - 1.3185575011226730e-33, 8.2316691420063460e-50), - qd_real( 6.1281008242940971e-01, -4.2693476568409685e-18, - 2.5839965886650320e-34, 1.6884412005622537e-50), - qd_real( 6.1523159058062682e-01, 2.6231417767266950e-17, - -1.4095366621106716e-33, 7.2058690491304558e-50), - qd_real( 6.1764730793780398e-01, -4.7478594510902452e-17, - -7.2986558263123996e-34, -3.0152327517439154e-50), - qd_real( 6.2005721176328921e-01, -2.7983410837681118e-17, - 1.1649951056138923e-33, -5.4539089117135207e-50), - qd_real( 6.2246127937414997e-01, 5.2940728606573002e-18, - -4.8486411215945827e-35, 1.2696527641980109e-52), - qd_real( 6.2485948814238634e-01, 3.3671846037243900e-17, - -2.7846053391012096e-33, 5.6102718120012104e-50), - qd_real( 6.2725181549514408e-01, 3.0763585181253225e-17, - 2.7068930273498138e-34, -1.1172240309286484e-50), - qd_real( 6.2963823891492698e-01, 4.1115334049626806e-17, - -1.9167473580230747e-33, 1.1118424028161730e-49), - qd_real( 6.3201873593980906e-01, -4.0164942296463612e-17, - -7.2208643641736723e-34, 3.7828920470544344e-50), - qd_real( 6.3439328416364549e-01, 1.0420901929280035e-17, - 4.1174558929280492e-34, -1.4464152986630705e-51), - qd_real( 6.3676186123628420e-01, 3.1419048711901611e-17, - -2.2693738415126449e-33, -1.6023584204297388e-49), - qd_real( 6.3912444486377573e-01, 1.2416796312271043e-17, - -6.2095419626356605e-34, 2.7762065999506603e-50), - qd_real( 6.4148101280858316e-01, -9.9883430115943310e-18, - 4.1969230376730128e-34, 5.6980543799257597e-51), - qd_real( 6.4383154288979150e-01, -3.2084798795046886e-17, - -1.2595311907053305e-33, -4.0205885230841536e-50), - qd_real( 6.4617601298331639e-01, -2.9756137382280815e-17, - -1.0275370077518259e-33, 8.0852478665893014e-51), - qd_real( 6.4851440102211244e-01, 3.9870270313386831e-18, - 1.9408388509540788e-34, -5.1798420636193190e-51), - qd_real( 6.5084668499638088e-01, 3.9714670710500257e-17, - 2.9178546787002963e-34, 3.8140635508293278e-51), - qd_real( 6.5317284295377676e-01, 8.5695642060026238e-18, - -6.9165322305070633e-34, 2.3873751224185395e-50), - qd_real( 6.5549285299961535e-01, 3.5638734426385005e-17, - 1.2695365790889811e-33, 4.3984952865412050e-50), - qd_real( 6.5780669329707864e-01, 1.9580943058468545e-17, - -1.1944272256627192e-33, 2.8556402616436858e-50), - qd_real( 6.6011434206742048e-01, -1.3960054386823638e-19, - 6.1515777931494047e-36, 5.3510498875622660e-52), - qd_real( 6.6241577759017178e-01, -2.2615508885764591e-17, - 5.0177050318126862e-34, 2.9162532399530762e-50), - qd_real( 6.6471097820334490e-01, -3.6227793598034367e-17, - -9.0607934765540427e-34, 3.0917036342380213e-50), - qd_real( 6.6699992230363747e-01, 3.5284364997428166e-17, - -1.0382057232458238e-33, 7.3812756550167626e-50), - qd_real( 6.6928258834663612e-01, -5.4592652417447913e-17, - -2.5181014709695152e-33, -1.6867875999437174e-49), - qd_real( 6.7155895484701844e-01, -4.0489037749296692e-17, - 3.1995835625355681e-34, -1.4044414655670960e-50), - qd_real( 6.7382900037875604e-01, 2.3091901236161086e-17, - 5.7428037192881319e-34, 1.1240668354625977e-50), - qd_real( 6.7609270357531592e-01, 3.7256902248049466e-17, - 1.7059417895764375e-33, 9.7326347795300652e-50), - qd_real( 6.7835004312986147e-01, 1.8302093041863122e-17, - 9.5241675746813072e-34, 5.0328101116133503e-50), - qd_real( 6.8060099779545302e-01, 2.8473293354522047e-17, - 4.1331805977270903e-34, 4.2579030510748576e-50), - qd_real( 6.8284554638524808e-01, -1.2958058061524531e-17, - 1.8292386959330698e-34, 3.4536209116044487e-51), - qd_real( 6.8508366777270036e-01, 2.5948135194645137e-17, - -8.5030743129500702e-34, -6.9572086141009930e-50), - qd_real( 6.8731534089175916e-01, -5.5156158714917168e-17, - 1.1896489854266829e-33, -7.8505896218220662e-51), - qd_real( 6.8954054473706694e-01, -1.5889323294806790e-17, - 9.1242356240205712e-34, 3.8315454152267638e-50), - qd_real( 6.9175925836415775e-01, 2.7406078472410668e-17, - 1.3286508943202092e-33, 1.0651869129580079e-51), - qd_real( 6.9397146088965400e-01, 7.4345076956280137e-18, - 7.5061528388197460e-34, -1.5928000240686583e-50), - qd_real( 6.9617713149146299e-01, -4.1224081213582889e-17, - -3.1838716762083291e-35, -3.9625587412119131e-51), - qd_real( 6.9837624940897280e-01, 4.8988282435667768e-17, - 1.9134010413244152e-33, 2.6161153243793989e-50), - qd_real( 7.0056879394324834e-01, 3.1027960192992922e-17, - 9.5638250509179997e-34, 4.5896916138107048e-51), - qd_real( 7.0275474445722530e-01, 2.5278294383629822e-18, - -8.6985561210674942e-35, -5.6899862307812990e-51), - qd_real( 7.0493408037590488e-01, 2.7608725585748502e-17, - 2.9816599471629137e-34, 1.1533044185111206e-50), - qd_real( 7.0710678118654757e-01, -4.8336466567264567e-17, - 2.0693376543497068e-33, 2.4677734957341755e-50) -}; - -static const qd_real cos_table [] = { - qd_real( 9.9999529380957619e-01, -1.9668064285322189e-17, - -6.3053955095883481e-34, 5.3266110855726731e-52), - qd_real( 9.9998117528260111e-01, 3.3568103522895585e-17, - -1.4740132559368063e-35, 9.8603097594755596e-52), - qd_real( 9.9995764455196390e-01, -3.1527836866647287e-17, - 2.6363251186638437e-33, 1.0007504815488399e-49), - qd_real( 9.9992470183914450e-01, 3.7931082512668012e-17, - -8.5099918660501484e-35, -4.9956973223295153e-51), - qd_real( 9.9988234745421256e-01, -3.5477814872408538e-17, - 1.7102001035303974e-33, -1.0725388519026542e-49), - qd_real( 9.9983058179582340e-01, 1.8825140517551119e-17, - -5.1383513457616937e-34, -3.8378827995403787e-50), - qd_real( 9.9976940535121528e-01, 4.2681177032289012e-17, - 1.9062302359737099e-33, -6.0221153262881160e-50), - qd_real( 9.9969881869620425e-01, -2.9851486403799753e-17, - -1.9084787370733737e-33, 5.5980260344029202e-51), - qd_real( 9.9961882249517864e-01, -4.1181965521424734e-17, - 2.0915365593699916e-33, 8.1403390920903734e-50), - qd_real( 9.9952941750109314e-01, 2.0517917823755591e-17, - -4.7673802585706520e-34, -2.9443604198656772e-50), - qd_real( 9.9943060455546173e-01, 3.9644497752257798e-17, - -2.3757223716722428e-34, -1.2856759011361726e-51), - qd_real( 9.9932238458834954e-01, -4.2858538440845682e-17, - 3.3235101605146565e-34, -8.3554272377057543e-51), - qd_real( 9.9920475861836389e-01, 9.1796317110385693e-18, - 5.5416208185868570e-34, 8.0267046717615311e-52), - qd_real( 9.9907772775264536e-01, 2.1419007653587032e-17, - -7.9048203318529618e-34, -5.3166296181112712e-50), - qd_real( 9.9894129318685687e-01, -2.0610641910058638e-17, - -1.2546525485913485e-33, -7.5175888806157064e-50), - qd_real( 9.9879545620517241e-01, -1.2291693337075465e-17, - 2.4468446786491271e-34, 1.0723891085210268e-50), - qd_real( 9.9864021818026527e-01, -4.8690254312923302e-17, - -2.9470881967909147e-34, -1.3000650761346907e-50), - qd_real( 9.9847558057329477e-01, -2.2002931182778795e-17, - -1.2371509454944992e-33, -2.4911225131232065e-50), - qd_real( 9.9830154493389289e-01, -5.1869402702792278e-17, - 1.0480195493633452e-33, -2.8995649143155511e-50), - qd_real( 9.9811811290014918e-01, 2.7935487558113833e-17, - 2.4423341255830345e-33, -6.7646699175334417e-50), - qd_real( 9.9792528619859600e-01, 1.7143659778886362e-17, - 5.7885840902887460e-34, -9.2601432603894597e-51), - qd_real( 9.9772306664419164e-01, -2.6394475274898721e-17, - -1.6176223087661783e-34, -9.9924942889362281e-51), - qd_real( 9.9751145614030345e-01, 5.6007205919806937e-18, - -5.9477673514685690e-35, -1.4166807162743627e-54), - qd_real( 9.9729045667869021e-01, 9.1647695371101735e-18, - 6.7824134309739296e-34, -8.6191392795543357e-52), - qd_real( 9.9706007033948296e-01, 1.6734093546241963e-17, - -1.3169951440780028e-33, 1.0311048767952477e-50), - qd_real( 9.9682029929116567e-01, 4.7062820708615655e-17, - 2.8412041076474937e-33, -8.0006155670263622e-50), - qd_real( 9.9657114579055484e-01, 1.1707179088390986e-17, - -7.5934413263024663e-34, 2.8474848436926008e-50), - qd_real( 9.9631261218277800e-01, 1.1336497891624735e-17, - 3.4002458674414360e-34, 7.7419075921544901e-52), - qd_real( 9.9604470090125197e-01, 2.2870031707670695e-17, - -3.9184839405013148e-34, -3.7081260416246375e-50), - qd_real( 9.9576741446765982e-01, -2.3151908323094359e-17, - -1.6306512931944591e-34, -1.5925420783863192e-51), - qd_real( 9.9548075549192694e-01, 3.2084621412226554e-18, - -4.9501292146013023e-36, -2.7811428850878516e-52), - qd_real( 9.9518472667219693e-01, -4.2486913678304410e-17, - 1.3315510772504614e-33, 6.7927987417051888e-50), - qd_real( 9.9487933079480562e-01, 4.2130813284943662e-18, - -4.2062597488288452e-35, 2.5157064556087620e-51), - qd_real( 9.9456457073425542e-01, 3.6745069641528058e-17, - -3.0603304105471010e-33, 1.0397872280487526e-49), - qd_real( 9.9424044945318790e-01, 4.4129423472462673e-17, - -3.0107231708238066e-33, 7.4201582906861892e-50), - qd_real( 9.9390697000235606e-01, -1.8964849471123746e-17, - -1.5980853777937752e-35, -8.5374807150597082e-52), - qd_real( 9.9356413552059530e-01, 2.9752309927797428e-17, - -4.5066707331134233e-34, -3.3548191633805036e-50), - qd_real( 9.9321194923479450e-01, 3.3096906261272262e-17, - 1.5592811973249567e-33, 1.4373977733253592e-50), - qd_real( 9.9285041445986510e-01, -1.4094517733693302e-17, - -1.1954558131616916e-33, 1.8761873742867983e-50), - qd_real( 9.9247953459870997e-01, 3.1093055095428906e-17, - -1.8379594757818019e-33, -3.9885758559381314e-51), - qd_real( 9.9209931314219180e-01, -3.9431926149588778e-17, - -6.2758062911047230e-34, -1.2960929559212390e-50), - qd_real( 9.9170975366909953e-01, -2.3372891311883661e-18, - 2.7073298824968591e-35, -1.2569459441802872e-51), - qd_real( 9.9131085984611544e-01, -2.5192111583372105e-17, - -1.2852471567380887e-33, 5.2385212584310483e-50), - qd_real( 9.9090263542778001e-01, 1.5394565094566704e-17, - -1.0799984133184567e-33, 2.7451115960133595e-51), - qd_real( 9.9048508425645709e-01, -5.5411437553780867e-17, - -1.4614017210753585e-33, -3.8339374397387620e-50), - qd_real( 9.9005821026229712e-01, -1.7055485906233963e-17, - 1.3454939685758777e-33, 7.3117589137300036e-50), - qd_real( 9.8962201746320089e-01, -5.2398217968132530e-17, - 1.3463189211456219e-33, 5.8021640554894872e-50), - qd_real( 9.8917650996478101e-01, -4.0987309937047111e-17, - -4.4857560552048437e-34, -3.9414504502871125e-50), - qd_real( 9.8872169196032378e-01, -1.0976227206656125e-17, - 3.2311342577653764e-34, 9.6367946583575041e-51), - qd_real( 9.8825756773074946e-01, 2.7030607784372632e-17, - 7.7514866488601377e-35, 2.1019644956864938e-51), - qd_real( 9.8778414164457218e-01, -2.3600693397159021e-17, - -1.2323283769707861e-33, 3.0130900716803339e-50), - qd_real( 9.8730141815785843e-01, -5.2332261255715652e-17, - -2.7937644333152473e-33, 1.2074160567958408e-49), - qd_real( 9.8680940181418553e-01, -5.0287214351061075e-17, - -2.2681526238144461e-33, 4.4003694320169133e-50), - qd_real( 9.8630809724459867e-01, -2.1520877103013341e-17, - 1.1866528054187716e-33, -7.8532199199813836e-50), - qd_real( 9.8579750916756748e-01, -5.1439452979953012e-17, - 2.6276439309996725e-33, 7.5423552783286347e-50), - qd_real( 9.8527764238894122e-01, 2.3155637027900207e-17, - -7.5275971545764833e-34, 1.0582231660456094e-50), - qd_real( 9.8474850180190421e-01, 1.0548144061829957e-17, - 2.8786145266267306e-34, -3.6782210081466112e-51), - qd_real( 9.8421009238692903e-01, 4.7983922627050691e-17, - 2.2597419645070588e-34, 1.7573875814863400e-50), - qd_real( 9.8366241921173025e-01, 1.9864948201635255e-17, - -1.0743046281211033e-35, 1.7975662796558100e-52), - qd_real( 9.8310548743121629e-01, 4.2170007522888628e-17, - 8.2396265656440904e-34, -8.0803700139096561e-50), - qd_real( 9.8253930228744124e-01, 1.5149580813777224e-17, - -4.1802771422186237e-34, -2.2150174326226160e-50), - qd_real( 9.8196386910955524e-01, 2.1108443711513084e-17, - -1.5253013442896054e-33, -6.8388082079337969e-50), - qd_real( 9.8137919331375456e-01, 1.3428163260355633e-17, - -6.5294290469962986e-34, 2.7965412287456268e-51), - qd_real( 9.8078528040323043e-01, 1.8546939997825006e-17, - -1.0696564445530757e-33, 6.6668174475264961e-50), - qd_real( 9.8018213596811743e-01, -3.6801786963856159e-17, - 6.3245171387992842e-34, 1.8600176137175971e-50), - qd_real( 9.7956976568544052e-01, 1.5573991584990420e-17, - -1.3401066029782990e-33, -1.7263702199862149e-50), - qd_real( 9.7894817531906220e-01, -2.3817727961148053e-18, - -1.0694750370381661e-34, -8.2293047196087462e-51), - qd_real( 9.7831737071962765e-01, -2.1623082233344895e-17, - 1.0970403012028032e-33, 7.7091923099369339e-50), - qd_real( 9.7767735782450993e-01, 5.0514136167059628e-17, - -1.3254751701428788e-33, 7.0161254312124538e-50), - qd_real( 9.7702814265775439e-01, -4.3353875751555997e-17, - 5.4948839831535478e-34, -9.2755263105377306e-51), - qd_real( 9.7636973133002114e-01, 9.3093931526213780e-18, - -4.1184949155685665e-34, -3.1913926031393690e-50), - qd_real( 9.7570213003852857e-01, -2.5572556081259686e-17, - -9.3174244508942223e-34, -8.3675863211646863e-51), - qd_real( 9.7502534506699412e-01, 2.6642660651899135e-17, - 1.7819392739353853e-34, -3.3159625385648947e-51), - qd_real( 9.7433938278557586e-01, 2.3041221476151512e-18, - 1.0758686005031430e-34, 5.1074116432809478e-51), - qd_real( 9.7364424965081198e-01, -5.1729808691005871e-17, - -1.5508473005989887e-33, -1.6505125917675401e-49), - qd_real( 9.7293995220556018e-01, -3.1311211122281800e-17, - -2.6874087789006141e-33, -2.1652434818822145e-51), - qd_real( 9.7222649707893627e-01, 3.6461169785938221e-17, - 3.0309636883883133e-33, -1.2702716907967306e-51), - qd_real( 9.7150389098625178e-01, -7.9865421122289046e-18, - -4.3628417211263380e-34, 3.4307517798759352e-51), - qd_real( 9.7077214072895035e-01, -4.7992163325114922e-17, - 3.0347528910975783e-33, 8.5989199506479701e-50), - qd_real( 9.7003125319454397e-01, 1.8365300348428844e-17, - -1.4311097571944918e-33, 8.5846781998740697e-51), - qd_real( 9.6928123535654853e-01, -4.5663660261927896e-17, - 9.6147526917239387e-34, 8.1267605207871330e-51), - qd_real( 9.6852209427441727e-01, 4.9475074918244771e-17, - 2.8558738351911241e-33, 6.2948422316507461e-50), - qd_real( 9.6775383709347551e-01, -4.5512132825515820e-17, - -1.4127617988719093e-33, -8.4620609089704578e-50), - qd_real( 9.6697647104485207e-01, 3.8496228837337864e-17, - -5.3881631542745647e-34, -3.5221863171458959e-50), - qd_real( 9.6619000344541250e-01, 5.1298840401665493e-17, - 1.4564075904769808e-34, 1.0095973971377432e-50), - qd_real( 9.6539444169768940e-01, -2.3745389918392156e-17, - 5.9221515590053862e-34, -3.8811192556231094e-50), - qd_real( 9.6458979328981276e-01, -3.4189470735959786e-17, - 2.2982074155463522e-33, -4.5128791045607634e-50), - qd_real( 9.6377606579543984e-01, 2.6463950561220029e-17, - -2.9073234590199323e-36, -1.2938328629395601e-52), - qd_real( 9.6295326687368388e-01, 8.9341960404313634e-18, - -3.9071244661020126e-34, 1.6212091116847394e-50), - qd_real( 9.6212140426904158e-01, 1.5236770453846305e-17, - -1.3050173525597142e-33, 7.9016122394092666e-50), - qd_real( 9.6128048581132064e-01, 2.0933955216674039e-18, - 1.0768607469015692e-34, -5.9453639304361774e-51), - qd_real( 9.6043051941556579e-01, 2.4653904815317185e-17, - -1.3792169410906322e-33, -4.7726598378506903e-51), - qd_real( 9.5957151308198452e-01, 1.1000640085000957e-17, - -4.2036030828223975e-34, 4.0023704842606573e-51), - qd_real( 9.5870347489587160e-01, -4.3685014392372053e-17, - 2.2001800662729131e-33, -1.0553721324358075e-49), - qd_real( 9.5782641302753291e-01, -1.7696710075371263e-17, - 1.9164034110382190e-34, 8.1489235071754813e-51), - qd_real( 9.5694033573220882e-01, 4.0553869861875701e-17, - -1.7147013364302149e-33, 2.5736745295329455e-50), - qd_real( 9.5604525134999641e-01, 3.7705045279589067e-17, - 1.9678699997347571e-33, 8.5093177731230180e-50), - qd_real( 9.5514116830577067e-01, 5.0088652955014668e-17, - -2.6983181838059211e-33, 1.0102323575596493e-49), - qd_real( 9.5422809510910567e-01, -3.7545901690626874e-17, - 1.4951619241257764e-33, -8.2717333151394973e-50), - qd_real( 9.5330604035419386e-01, -2.5190738779919934e-17, - -1.4272239821134379e-33, -4.6717286809283155e-50), - qd_real( 9.5237501271976588e-01, -2.0269300462299272e-17, - -1.0635956887246246e-33, -3.5514537666487619e-50), - qd_real( 9.5143502096900834e-01, 3.1350584123266695e-17, - -2.4824833452737813e-33, 9.5450335525380613e-51), - qd_real( 9.5048607394948170e-01, 1.9410097562630436e-17, - -8.1559393949816789e-34, -1.0501209720164562e-50), - qd_real( 9.4952818059303667e-01, -7.5544151928043298e-18, - -5.1260245024046686e-34, 1.8093643389040406e-50), - qd_real( 9.4856134991573027e-01, 2.0668262262333232e-17, - -5.9440730243667306e-34, 1.4268853111554300e-50), - qd_real( 9.4758559101774109e-01, 4.3417993852125991e-17, - -2.7728667889840373e-34, 5.5709160196519968e-51), - qd_real( 9.4660091308328353e-01, 3.5056800210680730e-17, - 9.8578536940318117e-34, 6.6035911064585197e-50), - qd_real( 9.4560732538052128e-01, 4.6019102478523738e-17, - -6.2534384769452059e-34, 1.5758941215779961e-50), - qd_real( 9.4460483726148026e-01, 8.8100545476641165e-18, - 5.2291695602757842e-34, -3.3487256018407123e-50), - qd_real( 9.4359345816196039e-01, -2.4093127844404214e-17, - 1.0283279856803939e-34, -2.3398232614531355e-51), - qd_real( 9.4257319760144687e-01, 1.3235564806436886e-17, - -5.7048262885386911e-35, 3.9947050442753744e-51), - qd_real( 9.4154406518302081e-01, -2.7896379547698341e-17, - 1.6273236356733898e-33, -5.3075944708471203e-51), - qd_real( 9.4050607059326830e-01, 2.8610421567116268e-17, - 2.9261501147538827e-33, -2.6849867690896925e-50), - qd_real( 9.3945922360218992e-01, -7.0152867943098655e-18, - -5.6395693818011210e-34, 3.5568142678987651e-50), - qd_real( 9.3840353406310806e-01, 5.4242545044795490e-17, - -1.9039966607859759e-33, -1.5627792988341215e-49), - qd_real( 9.3733901191257496e-01, -3.6570926284362776e-17, - -1.1902940071273247e-33, -1.1215082331583223e-50), - qd_real( 9.3626566717027826e-01, -1.3013766145497654e-17, - 5.2229870061990595e-34, -3.3972777075634108e-51), - qd_real( 9.3518350993894761e-01, -3.2609395302485065e-17, - -8.1813015218875245e-34, 5.5642140024928139e-50), - qd_real( 9.3409255040425887e-01, 4.4662824360767511e-17, - -2.5903243047396916e-33, 8.1505209004343043e-50), - qd_real( 9.3299279883473885e-01, 4.2041415555384355e-17, - 9.0285896495521276e-34, 5.3019984977661259e-50), - qd_real( 9.3188426558166815e-01, -4.0785944377318095e-17, - 1.7631450298754169e-33, 2.5776403305507453e-50), - qd_real( 9.3076696107898371e-01, 1.9703775102838329e-17, - 6.5657908718278205e-34, -1.9480347966259524e-51), - qd_real( 9.2964089584318121e-01, 5.1282530016864107e-17, - 2.3719739891916261e-34, -1.7230065426917127e-50), - qd_real( 9.2850608047321559e-01, -2.3306639848485943e-17, - -7.7799084333208503e-34, -5.8597558009300305e-50), - qd_real( 9.2736252565040111e-01, -2.7677111692155437e-17, - 2.2110293450199576e-34, 2.0349190819680613e-50), - qd_real( 9.2621024213831138e-01, -3.7303754586099054e-17, - 2.0464457809993405e-33, 1.3831799631231817e-49), - qd_real( 9.2504924078267758e-01, 6.0529447412576159e-18, - -8.8256517760278541e-35, 1.8285462122388328e-51), - qd_real( 9.2387953251128674e-01, 1.7645047084336677e-17, - -5.0442537321586818e-34, -4.0478677716823890e-50), - qd_real( 9.2270112833387852e-01, 5.2963798918539814e-17, - -5.7135699628876685e-34, 3.0163671797219087e-50), - qd_real( 9.2151403934204190e-01, 4.1639843390684644e-17, - 1.1891485604702356e-33, 2.0862437594380324e-50), - qd_real( 9.2031827670911059e-01, -2.7806888779036837e-17, - 2.7011013677071274e-33, 1.1998578792455499e-49), - qd_real( 9.1911385169005777e-01, -2.6496484622344718e-17, - 6.5403604763461920e-34, -2.8997180201186078e-50), - qd_real( 9.1790077562139050e-01, -3.9074579680849515e-17, - 2.3004636541490264e-33, 3.9851762744443107e-50), - qd_real( 9.1667905992104270e-01, -4.1733978698287568e-17, - 1.2094444804381172e-33, 4.9356916826097816e-50), - qd_real( 9.1544871608826783e-01, -1.3591056692900894e-17, - 5.9923027475594735e-34, 2.1403295925962879e-50), - qd_real( 9.1420975570353069e-01, -3.6316182527814423e-17, - -1.9438819777122554e-33, 2.8340679287728316e-50), - qd_real( 9.1296219042839821e-01, -4.7932505228039469e-17, - -1.7753551889428638e-33, 4.0607782903868160e-51), - qd_real( 9.1170603200542988e-01, -2.6913273175034130e-17, - -5.1928101916162528e-35, 1.1338175936090630e-51), - qd_real( 9.1044129225806725e-01, -5.0433041673313820e-17, - 1.0938746257404305e-33, 9.5378272084170731e-51), - qd_real( 9.0916798309052238e-01, -3.6878564091359894e-18, - 2.9951330310507693e-34, -1.2225666136919926e-50), - qd_real( 9.0788611648766626e-01, -4.9459964301225840e-17, - -1.6599682707075313e-33, -5.1925202712634716e-50), - qd_real( 9.0659570451491533e-01, 3.0506718955442023e-17, - -1.4478836557141204e-33, 1.8906373784448725e-50), - qd_real( 9.0529675931811882e-01, -4.1153099826889901e-17, - 2.9859368705184223e-33, 5.1145293917439211e-50), - qd_real( 9.0398929312344334e-01, -6.6097544687484308e-18, - 1.2728013034680357e-34, -4.3026097234014823e-51), - qd_real( 9.0267331823725883e-01, -1.9250787033961483e-17, - 1.3242128993244527e-33, -5.2971030688703665e-50), - qd_real( 9.0134884704602203e-01, -1.3524789367698682e-17, - 6.3605353115880091e-34, 3.6227400654573828e-50), - qd_real( 9.0001589201616028e-01, -5.0639618050802273e-17, - 1.0783525384031576e-33, 2.8130016326515111e-50), - qd_real( 8.9867446569395382e-01, 2.6316906461033013e-17, - 3.7003137047796840e-35, -2.3447719900465938e-51), - qd_real( 8.9732458070541832e-01, -3.6396283314867290e-17, - -2.3611649895474815e-33, 1.1837247047900082e-49), - qd_real( 8.9596624975618511e-01, 4.9025099114811813e-17, - -1.9440489814795326e-33, -1.7070486667767033e-49), - qd_real( 8.9459948563138270e-01, -1.7516226396814919e-17, - -1.3200670047246923e-33, -1.5953009884324695e-50), - qd_real( 8.9322430119551532e-01, -4.1161239151908913e-18, - 2.5380253805715999e-34, 4.2849455510516192e-51), - qd_real( 8.9184070939234272e-01, 4.6690228137124547e-18, - 1.6150254286841982e-34, -3.9617448820725012e-51), - qd_real( 8.9044872324475788e-01, 1.1781931459051803e-17, - -1.3346142209571930e-34, -9.4982373530733431e-51), - qd_real( 8.8904835585466457e-01, -1.1164514966766675e-17, - -3.4797636107798736e-34, -1.5605079997040631e-50), - qd_real( 8.8763962040285393e-01, 1.2805091918587960e-17, - 3.9948742059584459e-35, 3.8940716325338136e-51), - qd_real( 8.8622253014888064e-01, -6.7307369600274315e-18, - 1.2385593432917413e-34, 2.0364014759133320e-51), - qd_real( 8.8479709843093779e-01, -9.4331469628972690e-18, - -5.7106541478701439e-34, 1.8260134111907397e-50), - qd_real( 8.8336333866573158e-01, 1.5822643380255127e-17, - -7.8921320007588250e-34, -1.4782321016179836e-50), - qd_real( 8.8192126434835505e-01, -1.9843248405890562e-17, - -7.0412114007673834e-34, -1.0636770169389104e-50), - qd_real( 8.8047088905216075e-01, 1.6311096602996350e-17, - -5.7541360594724172e-34, -4.0128611862170021e-50), - qd_real( 8.7901222642863353e-01, -4.7356837291118011e-17, - 1.4388771297975192e-33, -2.9085554304479134e-50), - qd_real( 8.7754529020726124e-01, 5.0113311846499550e-17, - 2.8382769008739543e-34, 1.5550640393164140e-50), - qd_real( 8.7607009419540660e-01, 5.8729024235147677e-18, - 2.7941144391738458e-34, -1.8536073846509828e-50), - qd_real( 8.7458665227817611e-01, -5.7216617730397065e-19, - -2.9705811503689596e-35, 8.7389593969796752e-52), - qd_real( 8.7309497841829009e-01, 7.8424672990129903e-18, - -4.8685015839797165e-34, -2.2815570587477527e-50), - qd_real( 8.7159508665595109e-01, -5.5272998038551050e-17, - -2.2104090204984907e-33, -9.7749763187643172e-50), - qd_real( 8.7008699110871146e-01, -4.1888510868549968e-17, - 7.0900185861878415e-34, 3.7600251115157260e-50), - qd_real( 8.6857070597134090e-01, 2.7192781689782903e-19, - -1.6710140396932428e-35, -1.2625514734637969e-51), - qd_real( 8.6704624551569265e-01, 3.0267859550930567e-18, - -1.1559438782171572e-34, -5.3580556397808012e-52), - qd_real( 8.6551362409056909e-01, -6.3723113549628899e-18, - 2.3725520321746832e-34, 1.5911880348395175e-50), - qd_real( 8.6397285612158670e-01, 4.1486355957361607e-17, - 2.2709976932210266e-33, -8.1228385659479984e-50), - qd_real( 8.6242395611104050e-01, 3.7008992527383130e-17, - 5.2128411542701573e-34, 2.6945600081026861e-50), - qd_real( 8.6086693863776731e-01, -3.0050048898573656e-17, - -8.8706183090892111e-34, 1.5005320558097301e-50), - qd_real( 8.5930181835700836e-01, 4.2435655816850687e-17, - 7.6181814059912025e-34, -3.9592127850658708e-50), - qd_real( 8.5772861000027212e-01, -4.8183447936336620e-17, - -1.1044130517687532e-33, -8.7400233444645562e-50), - qd_real( 8.5614732837519447e-01, 9.1806925616606261e-18, - 5.6328649785951470e-34, 2.3326646113217378e-51), - qd_real( 8.5455798836540053e-01, -1.2991124236396092e-17, - 1.2893407722948080e-34, -3.6506925747583053e-52), - qd_real( 8.5296060493036363e-01, 2.7152984251981370e-17, - 7.4336483283120719e-34, 4.2162417622350668e-50), - qd_real( 8.5135519310526520e-01, -5.3279874446016209e-17, - 2.2281156380919942e-33, -4.0281886404138477e-50), - qd_real( 8.4974176800085244e-01, 5.1812347659974015e-17, - 3.0810626087331275e-33, -2.5931308201994965e-50), - qd_real( 8.4812034480329723e-01, 1.8762563415239981e-17, - 1.4048773307919617e-33, -2.4915221509958691e-50), - qd_real( 8.4649093877405213e-01, -4.7969419958569345e-17, - -2.7518267097886703e-33, -7.3518959727313350e-50), - qd_real( 8.4485356524970712e-01, -4.3631360296879637e-17, - -2.0307726853367547e-33, 4.3097229819851761e-50), - qd_real( 8.4320823964184544e-01, 9.6536707005959077e-19, - 2.8995142431556364e-36, 9.6715076811480284e-53), - qd_real( 8.4155497743689844e-01, -3.4095465391321557e-17, - -8.4130208607579595e-34, -4.9447283960568686e-50), - qd_real( 8.3989379419599952e-01, -1.6673694881511411e-17, - -1.4759184141750289e-33, -7.5795098161914058e-50), - qd_real( 8.3822470555483808e-01, -3.5560085052855026e-17, - 1.1689791577022643e-33, -5.8627347359723411e-50), - qd_real( 8.3654772722351201e-01, -2.0899059027066533e-17, - -9.8104097821002585e-35, -3.1609177868229853e-51), - qd_real( 8.3486287498638001e-01, 4.6048430609159657e-17, - -5.1827423265239912e-34, -7.0505343435504109e-51), - qd_real( 8.3317016470191319e-01, 1.3275129507229764e-18, - 4.8589164115370863e-35, 4.5422281300506859e-51), - qd_real( 8.3146961230254524e-01, 1.4073856984728024e-18, - 4.6951315383980830e-35, 5.1431906049905658e-51), - qd_real( 8.2976123379452305e-01, -2.9349109376485597e-18, - 1.1496917934149818e-34, 3.5186665544980233e-51), - qd_real( 8.2804504525775580e-01, -4.4196593225871532e-17, - 2.7967864855211251e-33, 1.0030777287393502e-49), - qd_real( 8.2632106284566353e-01, -5.3957485453612902e-17, - 6.8976896130138550e-34, 3.8106164274199196e-50), - qd_real( 8.2458930278502529e-01, -2.6512360488868275e-17, - 1.6916964350914386e-34, 6.7693974813562649e-51), - qd_real( 8.2284978137582632e-01, 1.5193019034505495e-17, - 9.6890547246521685e-34, 5.6994562923653264e-50), - qd_real( 8.2110251499110465e-01, 3.0715131609697682e-17, - -1.7037168325855879e-33, -1.1149862443283853e-49), - qd_real( 8.1934752007679701e-01, -4.8200736995191133e-17, - -1.5574489646672781e-35, -9.5647853614522216e-53), - qd_real( 8.1758481315158371e-01, -1.4883149812426772e-17, - -7.8273262771298917e-34, 4.1332149161031594e-50), - qd_real( 8.1581441080673378e-01, 8.2652693782130871e-18, - -2.3028778135179471e-34, 1.5102071387249843e-50), - qd_real( 8.1403632970594841e-01, -5.2127351877042624e-17, - -1.9047670611316360e-33, -1.6937269585941507e-49), - qd_real( 8.1225058658520388e-01, 3.1054545609214803e-17, - 2.2649541922707251e-34, -7.4221684154649405e-51), - qd_real( 8.1045719825259477e-01, 2.3520367349840499e-17, - -7.7530070904846341e-34, -7.2792616357197140e-50), - qd_real( 8.0865618158817498e-01, 9.3251597879721674e-18, - -7.1823301933068394e-34, 2.3925440846132106e-50), - qd_real( 8.0684755354379922e-01, 4.9220603766095546e-17, - 2.9796016899903487e-33, 1.5220754223615788e-49), - qd_real( 8.0503133114296355e-01, 5.1368289568212149e-17, - 6.3082807402256524e-34, 7.3277646085129827e-51), - qd_real( 8.0320753148064494e-01, -3.3060609804814910e-17, - -1.2242726252420433e-33, 2.8413673268630117e-50), - qd_real( 8.0137617172314024e-01, -2.0958013413495834e-17, - -4.3798162198006931e-34, 2.0235690497752515e-50), - qd_real( 7.9953726910790501e-01, 2.0356723822005431e-17, - -9.7448513696896360e-34, 5.3608109599696008e-52), - qd_real( 7.9769084094339116e-01, -4.6730759884788944e-17, - 2.3075897077191757e-33, 3.1605567774640253e-51), - qd_real( 7.9583690460888357e-01, -3.0062724851910721e-17, - -2.2496210832042235e-33, -6.5881774117183040e-50), - qd_real( 7.9397547755433717e-01, -7.4194631759921416e-18, - 2.4124341304631069e-34, -4.9956808616244972e-51), - qd_real( 7.9210657730021239e-01, -3.7087850202326467e-17, - -1.4874457267228264e-33, 2.9323097289153505e-50), - qd_real( 7.9023022143731003e-01, 2.3056905954954492e-17, - 1.4481080533260193e-33, -7.6725237057203488e-50), - qd_real( 7.8834642762660623e-01, 3.4396993154059708e-17, - 1.7710623746737170e-33, 1.7084159098417402e-49), - qd_real( 7.8645521359908577e-01, -9.7841429939305265e-18, - 3.3906063272445472e-34, 5.7269505320382577e-51), - qd_real( 7.8455659715557524e-01, -8.5627965423173476e-18, - -2.1106834459001849e-34, -1.6890322182469603e-50), - qd_real( 7.8265059616657573e-01, 9.0745866975808825e-18, - 6.7623847404278666e-34, -1.7173237731987271e-50), - qd_real( 7.8073722857209449e-01, -9.9198782066678806e-18, - -2.1265794012162715e-36, 3.0772165598957647e-54), - qd_real( 7.7881651238147598e-01, -2.4891385579973807e-17, - 6.7665497024807980e-35, -6.5218594281701332e-52), - qd_real( 7.7688846567323244e-01, 7.7418602570672864e-18, - -5.9986517872157897e-34, 3.0566548232958972e-50), - qd_real( 7.7495310659487393e-01, -5.2209083189826433e-17, - -9.6653593393686612e-34, 3.7027750076562569e-50), - qd_real( 7.7301045336273699e-01, -3.2565907033649772e-17, - 1.3860807251523929e-33, -3.9971329917586022e-50), - qd_real( 7.7106052426181382e-01, -4.4558442347769265e-17, - -2.9863565614083783e-33, -6.8795262083596236e-50), - qd_real( 7.6910333764557959e-01, 5.1546455184564817e-17, - 2.6142829553524292e-33, -1.6199023632773298e-49), - qd_real( 7.6713891193582040e-01, -1.8885903683750782e-17, - -1.3659359331495433e-33, -2.2538834962921934e-50), - qd_real( 7.6516726562245896e-01, -3.2707225612534598e-17, - 1.1177117747079528e-33, -3.7005182280175715e-50), - qd_real( 7.6318841726338127e-01, 2.6314748416750748e-18, - 1.4048039063095910e-34, 8.9601886626630321e-52), - qd_real( 7.6120238548426178e-01, 3.5315510881690551e-17, - 1.2833566381864357e-33, 8.6221435180890613e-50), - qd_real( 7.5920918897838807e-01, -3.8558842175523123e-17, - 2.9720241208332759e-34, -1.2521388928220163e-50), - qd_real( 7.5720884650648457e-01, -1.9909098777335502e-17, - 3.9409283266158482e-34, 2.0744254207802976e-50), - qd_real( 7.5520137689653655e-01, -1.9402238001823017e-17, - -3.7756206444727573e-34, -2.1212242308178287e-50), - qd_real( 7.5318679904361252e-01, -3.7937789838736540e-17, - -6.7009539920231559e-34, -6.7128562115050214e-51), - qd_real( 7.5116513190968637e-01, 4.3499761158645868e-17, - 2.5227718971102212e-33, -6.5969709212757102e-50), - qd_real( 7.4913639452345937e-01, -4.4729078447011889e-17, - -2.4206025249983768e-33, 1.1336681351116422e-49), - qd_real( 7.4710060598018013e-01, 1.1874824875965430e-17, - 2.1992523849833518e-34, 1.1025018564644483e-50), - qd_real( 7.4505778544146595e-01, 1.5078686911877863e-17, - 8.0898987212942471e-34, 8.2677958765323532e-50), - qd_real( 7.4300795213512172e-01, -2.5144629669719265e-17, - 7.1128989512526157e-34, 3.0181629077821220e-50), - qd_real( 7.4095112535495911e-01, -1.4708616952297345e-17, - -4.9550433827142032e-34, 3.1434132533735671e-50), - qd_real( 7.3888732446061511e-01, 3.4324874808225091e-17, - -1.3706639444717610e-33, -3.3520827530718938e-51), - qd_real( 7.3681656887736990e-01, -2.8932468101656295e-17, - -3.4649887126202378e-34, -1.8484474476291476e-50), - qd_real( 7.3473887809596350e-01, -3.4507595976263941e-17, - -2.3718000676666409e-33, -3.9696090387165402e-50), - qd_real( 7.3265427167241282e-01, 1.8918673481573520e-17, - -1.5123719544119886e-33, -9.7922152011625728e-51), - qd_real( 7.3056276922782759e-01, -2.9689959904476928e-17, - -1.1276871244239744e-33, -3.0531520961539007e-50), - qd_real( 7.2846439044822520e-01, 1.1924642323370718e-19, - 5.9001892316611011e-36, 1.2178089069502704e-52), - qd_real( 7.2635915508434601e-01, -3.1917502443460542e-17, - 7.7047912412039396e-34, 4.1455880160182123e-50), - qd_real( 7.2424708295146689e-01, 2.9198471334403004e-17, - 2.3027324968739464e-33, -1.2928820533892183e-51), - qd_real( 7.2212819392921535e-01, -2.3871262053452047e-17, - 1.0636125432862273e-33, -4.4598638837802517e-50), - qd_real( 7.2000250796138165e-01, -2.5689658854462333e-17, - -9.1492566948567925e-34, 4.4403780801267786e-50), - qd_real( 7.1787004505573171e-01, 2.7006476062511453e-17, - -2.2854956580215348e-34, 9.1726903890287867e-51), - qd_real( 7.1573082528381871e-01, -5.1581018476410262e-17, - -1.3736271349300259e-34, -1.2734611344111297e-50), - qd_real( 7.1358486878079364e-01, -4.2342504403133584e-17, - -4.2690366101617268e-34, -2.6352370883066522e-50), - qd_real( 7.1143219574521643e-01, 7.9643298613856813e-18, - 2.9488239510721469e-34, 1.6985236437666356e-50), - qd_real( 7.0927282643886569e-01, -3.7597359110245730e-17, - 1.0613125954645119e-34, 8.9465480185486032e-51), - qd_real( 7.0710678118654757e-01, -4.8336466567264567e-17, - 2.0693376543497068e-33, 2.4677734957341755e-50) -}; - -/* Computes sin(a) and cos(a) using Taylor series. - Assumes |a| <= pi/2048. */ -static void sincos_taylor(const qd_real &a, - qd_real &sin_a, qd_real &cos_a) { - const double thresh = 0.5 * qd_real::_eps * std::abs(to_double(a)); - qd_real p, s, t, x; - - if (a.is_zero()) { - sin_a = 0.0; - cos_a = 1.0; - return; - } - - x = -sqr(a); - s = a; - p = a; - int i = 0; - do { - p *= x; - t = p * inv_fact[i]; - s += t; - i += 2; - } while (i < n_inv_fact && std::abs(to_double(t)) > thresh); - - sin_a = s; - cos_a = sqrt(1.0 - sqr(s)); -} - -static qd_real sin_taylor(const qd_real &a) { - const double thresh = 0.5 * qd_real::_eps * std::abs(to_double(a)); - qd_real p, s, t, x; - - if (a.is_zero()) { - return 0.0; - } - - x = -sqr(a); - s = a; - p = a; - int i = 0; - do { - p *= x; - t = p * inv_fact[i]; - s += t; - i += 2; - } while (i < n_inv_fact && std::abs(to_double(t)) > thresh); - - return s; -} - -static qd_real cos_taylor(const qd_real &a) { - const double thresh = 0.5 * qd_real::_eps; - qd_real p, s, t, x; - - if (a.is_zero()) { - return 1.0; - } - - x = -sqr(a); - s = 1.0 + mul_pwr2(x, 0.5); - p = x; - int i = 1; - do { - p *= x; - t = p * inv_fact[i]; - s += t; - i += 2; - } while (i < n_inv_fact && std::abs(to_double(t)) > thresh); - - return s; -} - -qd_real sin(const qd_real &a) { - - /* Strategy. To compute sin(x), we choose integers a, b so that - - x = s + a * (pi/2) + b * (pi/1024) - - and |s| <= pi/2048. Using a precomputed table of - sin(k pi / 1024) and cos(k pi / 1024), we can compute - sin(x) from sin(s) and cos(s). This greatly increases the - convergence of the sine Taylor series. */ - - if (a.is_zero()) { - return 0.0; - } - - // approximately reduce modulo 2*pi - qd_real z = nint(a / qd_real::_2pi); - qd_real r = a - qd_real::_2pi * z; - - // approximately reduce modulo pi/2 and then modulo pi/1024 - double q = std::floor(r.x[0] / qd_real::_pi2[0] + 0.5); - qd_real t = r - qd_real::_pi2 * q; - int j = static_cast<int>(q); - q = std::floor(t.x[0] / _pi1024[0] + 0.5); - t -= _pi1024 * q; - int k = static_cast<int>(q); - int abs_k = std::abs(k); - - if (j < -2 || j > 2) { - qd_real::error("(qd_real::sin): Cannot reduce modulo pi/2."); - return qd_real::_nan; - } - - if (abs_k > 256) { - qd_real::error("(qd_real::sin): Cannot reduce modulo pi/1024."); - return qd_real::_nan; - } - - if (k == 0) { - switch (j) { - case 0: - return sin_taylor(t); - case 1: - return cos_taylor(t); - case -1: - return -cos_taylor(t); - default: - return -sin_taylor(t); - } - } - - qd_real sin_t, cos_t; - qd_real u = cos_table[abs_k-1]; - qd_real v = sin_table[abs_k-1]; - sincos_taylor(t, sin_t, cos_t); - - if (j == 0) { - if (k > 0) { - r = u * sin_t + v * cos_t; - } else { - r = u * sin_t - v * cos_t; - } - } else if (j == 1) { - if (k > 0) { - r = u * cos_t - v * sin_t; - } else { - r = u * cos_t + v * sin_t; - } - } else if (j == -1) { - if (k > 0) { - r = v * sin_t - u * cos_t; - } else { - r = - u * cos_t - v * sin_t; - } - } else { - if (k > 0) { - r = - u * sin_t - v * cos_t; - } else { - r = v * cos_t - u * sin_t; - } - } - - return r; -} - -qd_real cos(const qd_real &a) { - - if (a.is_zero()) { - return 1.0; - } - - // approximately reduce modulo 2*pi - qd_real z = nint(a / qd_real::_2pi); - qd_real r = a - qd_real::_2pi * z; - - // approximately reduce modulo pi/2 and then modulo pi/1024 - double q = std::floor(r.x[0] / qd_real::_pi2.x[0] + 0.5); - qd_real t = r - qd_real::_pi2 * q; - int j = static_cast<int>(q); - q = std::floor(t.x[0] / _pi1024.x[0] + 0.5); - t -= _pi1024 * q; - int k = static_cast<int>(q); - int abs_k = std::abs(k); - - if (j < -2 || j > 2) { - qd_real::error("(qd_real::cos): Cannot reduce modulo pi/2."); - return qd_real::_nan; - } - - if (abs_k > 256) { - qd_real::error("(qd_real::cos): Cannot reduce modulo pi/1024."); - return qd_real::_nan; - } - - if (k == 0) { - switch (j) { - case 0: - return cos_taylor(t); - case 1: - return -sin_taylor(t); - case -1: - return sin_taylor(t); - default: - return -cos_taylor(t); - } - } - - qd_real sin_t, cos_t; - sincos_taylor(t, sin_t, cos_t); - - qd_real u = cos_table[abs_k-1]; - qd_real v = sin_table[abs_k-1]; - - if (j == 0) { - if (k > 0) { - r = u * cos_t - v * sin_t; - } else { - r = u * cos_t + v * sin_t; - } - } else if (j == 1) { - if (k > 0) { - r = - u * sin_t - v * cos_t; - } else { - r = v * cos_t - u * sin_t; - } - } else if (j == -1) { - if (k > 0) { - r = u * sin_t + v * cos_t; - } else { - r = u * sin_t - v * cos_t; - } - } else { - if (k > 0) { - r = v * sin_t - u * cos_t; - } else { - r = - u * cos_t - v * sin_t; - } - } - - return r; -} - -void sincos(const qd_real &a, qd_real &sin_a, qd_real &cos_a) { - - if (a.is_zero()) { - sin_a = 0.0; - cos_a = 1.0; - return; - } - - // approximately reduce by 2*pi - qd_real z = nint(a / qd_real::_2pi); - qd_real t = a - qd_real::_2pi * z; - - // approximately reduce by pi/2 and then by pi/1024. - double q = std::floor(t.x[0] / qd_real::_pi2.x[0] + 0.5); - t -= qd_real::_pi2 * q; - int j = static_cast<int>(q); - q = std::floor(t.x[0] / _pi1024.x[0] + 0.5); - t -= _pi1024 * q; - int k = static_cast<int>(q); - int abs_k = std::abs(k); - - if (j < -2 || j > 2) { - qd_real::error("(qd_real::sincos): Cannot reduce modulo pi/2."); - cos_a = sin_a = qd_real::_nan; - return; - } - - if (abs_k > 256) { - qd_real::error("(qd_real::sincos): Cannot reduce modulo pi/1024."); - cos_a = sin_a = qd_real::_nan; - return; - } - - qd_real sin_t, cos_t; - sincos_taylor(t, sin_t, cos_t); - - if (k == 0) { - if (j == 0) { - sin_a = sin_t; - cos_a = cos_t; - } else if (j == 1) { - sin_a = cos_t; - cos_a = -sin_t; - } else if (j == -1) { - sin_a = -cos_t; - cos_a = sin_t; - } else { - sin_a = -sin_t; - cos_a = -cos_t; - } - return; - } - - qd_real u = cos_table[abs_k-1]; - qd_real v = sin_table[abs_k-1]; - - if (j == 0) { - if (k > 0) { - sin_a = u * sin_t + v * cos_t; - cos_a = u * cos_t - v * sin_t; - } else { - sin_a = u * sin_t - v * cos_t; - cos_a = u * cos_t + v * sin_t; - } - } else if (j == 1) { - if (k > 0) { - cos_a = - u * sin_t - v * cos_t; - sin_a = u * cos_t - v * sin_t; - } else { - cos_a = v * cos_t - u * sin_t; - sin_a = u * cos_t + v * sin_t; - } - } else if (j == -1) { - if (k > 0) { - cos_a = u * sin_t + v * cos_t; - sin_a = v * sin_t - u * cos_t; - } else { - cos_a = u * sin_t - v * cos_t; - sin_a = - u * cos_t - v * sin_t; - } - } else { - if (k > 0) { - sin_a = - u * sin_t - v * cos_t; - cos_a = v * sin_t - u * cos_t; - } else { - sin_a = v * cos_t - u * sin_t; - cos_a = - u * cos_t - v * sin_t; - } - } -} - -qd_real atan(const qd_real &a) { - return atan2(a, qd_real(1.0)); -} - -qd_real atan2(const qd_real &y, const qd_real &x) { - /* Strategy: Instead of using Taylor series to compute - arctan, we instead use Newton's iteration to solve - the equation - - sin(z) = y/r or cos(z) = x/r - - where r = sqrt(x^2 + y^2). - The iteration is given by - - z' = z + (y - sin(z)) / cos(z) (for equation 1) - z' = z - (x - cos(z)) / sin(z) (for equation 2) - - Here, x and y are normalized so that x^2 + y^2 = 1. - If |x| > |y|, then first iteration is used since the - denominator is larger. Otherwise, the second is used. - */ - - if (x.is_zero()) { - - if (y.is_zero()) { - /* Both x and y is zero. */ - qd_real::error("(qd_real::atan2): Both arguments zero."); - return qd_real::_nan; - } - - return (y.is_positive()) ? qd_real::_pi2 : -qd_real::_pi2; - } else if (y.is_zero()) { - return (x.is_positive()) ? qd_real(0.0) : qd_real::_pi; - } - - if (x == y) { - return (y.is_positive()) ? qd_real::_pi4 : -qd_real::_3pi4; - } - - if (x == -y) { - return (y.is_positive()) ? qd_real::_3pi4 : -qd_real::_pi4; - } - - qd_real r = sqrt(sqr(x) + sqr(y)); - qd_real xx = x / r; - qd_real yy = y / r; - - /* Compute double precision approximation to atan. */ - qd_real z = std::atan2(to_double(y), to_double(x)); - qd_real sin_z, cos_z; - - if (std::abs(xx.x[0]) > std::abs(yy.x[0])) { - /* Use Newton iteration 1. z' = z + (y - sin(z)) / cos(z) */ - sincos(z, sin_z, cos_z); - z += (yy - sin_z) / cos_z; - sincos(z, sin_z, cos_z); - z += (yy - sin_z) / cos_z; - sincos(z, sin_z, cos_z); - z += (yy - sin_z) / cos_z; - } else { - /* Use Newton iteration 2. z' = z - (x - cos(z)) / sin(z) */ - sincos(z, sin_z, cos_z); - z -= (xx - cos_z) / sin_z; - sincos(z, sin_z, cos_z); - z -= (xx - cos_z) / sin_z; - sincos(z, sin_z, cos_z); - z -= (xx - cos_z) / sin_z; - } - - return z; -} - - -qd_real drem(const qd_real &a, const qd_real &b) { - qd_real n = nint(a/b); - return (a - n * b); -} - -qd_real divrem(const qd_real &a, const qd_real &b, qd_real &r) { - qd_real n = nint(a/b); - r = a - n * b; - return n; -} - -qd_real tan(const qd_real &a) { - qd_real s, c; - sincos(a, s, c); - return s/c; -} - -qd_real asin(const qd_real &a) { - qd_real abs_a = abs(a); - - if (abs_a > 1.0) { - qd_real::error("(qd_real::asin): Argument out of domain."); - return qd_real::_nan; - } - - if (abs_a.is_one()) { - return (a.is_positive()) ? qd_real::_pi2 : -qd_real::_pi2; - } - - return atan2(a, sqrt(1.0 - sqr(a))); -} - -qd_real acos(const qd_real &a) { - qd_real abs_a = abs(a); - - if (abs_a > 1.0) { - qd_real::error("(qd_real::acos): Argument out of domain."); - return qd_real::_nan; - } - - if (abs_a.is_one()) { - return (a.is_positive()) ? qd_real(0.0) : qd_real::_pi; - } - - return atan2(sqrt(1.0 - sqr(a)), a); -} - -qd_real sinh(const qd_real &a) { - if (a.is_zero()) { - return 0.0; - } - - if (abs(a) > 0.05) { - qd_real ea = exp(a); - return mul_pwr2(ea - inv(ea), 0.5); - } - - /* Since a is small, using the above formula gives - a lot of cancellation. So use Taylor series. */ - qd_real s = a; - qd_real t = a; - qd_real r = sqr(t); - double m = 1.0; - double thresh = std::abs(to_double(a) * qd_real::_eps); - - do { - m += 2.0; - t *= r; - t /= (m-1) * m; - - s += t; - } while (abs(t) > thresh); - - return s; -} - -qd_real cosh(const qd_real &a) { - if (a.is_zero()) { - return 1.0; - } - - qd_real ea = exp(a); - return mul_pwr2(ea + inv(ea), 0.5); -} - -qd_real tanh(const qd_real &a) { - if (a.is_zero()) { - return 0.0; - } - - if (std::abs(to_double(a)) > 0.05) { - qd_real ea = exp(a); - qd_real inv_ea = inv(ea); - return (ea - inv_ea) / (ea + inv_ea); - } else { - qd_real s, c; - s = sinh(a); - c = sqrt(1.0 + sqr(s)); - return s / c; - } -} - -void sincosh(const qd_real &a, qd_real &s, qd_real &c) { - if (std::abs(to_double(a)) <= 0.05) { - s = sinh(a); - c = sqrt(1.0 + sqr(s)); - } else { - qd_real ea = exp(a); - qd_real inv_ea = inv(ea); - s = mul_pwr2(ea - inv_ea, 0.5); - c = mul_pwr2(ea + inv_ea, 0.5); - } -} - -qd_real asinh(const qd_real &a) { - return log(a + sqrt(sqr(a) + 1.0)); -} - -qd_real acosh(const qd_real &a) { - if (a < 1.0) { - qd_real::error("(qd_real::acosh): Argument out of domain."); - return qd_real::_nan; - } - - return log(a + sqrt(sqr(a) - 1.0)); -} - -qd_real atanh(const qd_real &a) { - if (abs(a) >= 1.0) { - qd_real::error("(qd_real::atanh): Argument out of domain."); - return qd_real::_nan; - } - - return mul_pwr2(log((1.0 + a) / (1.0 - a)), 0.5); -} - -QD_API qd_real fmod(const qd_real &a, const qd_real &b) { - qd_real n = aint(a / b); - return (a - b * n); -} - -QD_API qd_real qdrand() { - static const double m_const = 4.6566128730773926e-10; /* = 2^{-31} */ - double m = m_const; - qd_real r = 0.0; - double d; - - /* Strategy: Generate 31 bits at a time, using lrand48 - random number generator. Shift the bits, and repeat - 7 times. */ - - for (int i = 0; i < 7; i++, m *= m_const) { - d = std::rand() * m; - r += d; - } - - return r; -} - - -/* polyeval(c, n, x) - Evaluates the given n-th degree polynomial at x. - The polynomial is given by the array of (n+1) coefficients. */ -qd_real polyeval(const qd_real *c, int n, const qd_real &x) { - /* Just use Horner's method of polynomial evaluation. */ - qd_real r = c[n]; - - for (int i = n-1; i >= 0; i--) { - r *= x; - r += c[i]; - } - - return r; -} - -/* polyroot(c, n, x0) - Given an n-th degree polynomial, finds a root close to - the given guess x0. Note that this uses simple Newton - iteration scheme, and does not work for multiple roots. */ -QD_API qd_real polyroot(const qd_real *c, int n, - const qd_real &x0, int max_iter, double thresh) { - qd_real x = x0; - qd_real f; - qd_real *d = new qd_real[n]; - bool conv = false; - int i; - double max_c = std::abs(to_double(c[0])); - double v; - - if (thresh == 0.0) thresh = qd_real::_eps; - - /* Compute the coefficients of the derivatives. */ - for (i = 1; i <= n; i++) { - v = std::abs(to_double(c[i])); - if (v > max_c) max_c = v; - d[i-1] = c[i] * static_cast<double>(i); - } - thresh *= max_c; - - /* Newton iteration. */ - for (i = 0; i < max_iter; i++) { - f = polyeval(c, n, x); - - if (abs(f) < thresh) { - conv = true; - break; - } - x -= (f / polyeval(d, n-1, x)); - } - delete [] d; - - if (!conv) { - qd_real::error("(qd_real::polyroot): Failed to converge."); - return qd_real::_nan; - } - - return x; -} - -qd_real qd_real::debug_rand() { - if (std::rand() % 2 == 0) - return qdrand(); - - int expn = 0; - qd_real a = 0.0; - double d; - for (int i = 0; i < 4; i++) { - d = std::ldexp(std::rand() / static_cast<double>(RAND_MAX), -expn); - a += d; - expn = expn + 54 + std::rand() % 200; - } - return a; -} - diff --git a/src/external/PackedCSparse/qd/qd_real.h b/src/external/PackedCSparse/qd/qd_real.h deleted file mode 100644 index 1ecfc732..00000000 --- a/src/external/PackedCSparse/qd/qd_real.h +++ /dev/null @@ -1,296 +0,0 @@ -/* - * include/qd_real.h - * - * This work was supported by the Director, Office of Science, Division - * of Mathematical, Information, and Computational Sciences of the - * U.S. Department of Energy under contract number DE-AC03-76SF00098. - * - * Copyright (c) 2000-2007 - * - * Quad-double precision (>= 212-bit significand) floating point arithmetic - * package, written in ANSI C++, taking full advantage of operator overloading. - * Uses similar techniques as that of David Bailey's double-double package - * and that of Jonathan Shewchuk's adaptive precision floating point - * arithmetic package. See - * - * http://www.nersc.gov/~dhbailey/mpdist/mpdist.html - * http://www.cs.cmu.edu/~quake/robust.html - * - * for more details. - * - * Yozo Hida - */ -#ifndef _QD_QD_REAL_H -#define _QD_QD_REAL_H - -#include <iostream> -#include <string> -#include <limits> -#include "qd_config.h" -#include "dd_real.h" - -struct QD_API qd_real { - double x[4]; /* The Components. */ - - /* Eliminates any zeros in the middle component(s). */ - void zero_elim(); - void zero_elim(double &e); - - void renorm(); - void renorm(double &e); - - void quick_accum(double d, double &e); - void quick_prod_accum(double a, double b, double &e); - - qd_real(double x0, double x1, double x2, double x3); - explicit qd_real(const double *xx); - - static const qd_real _2pi; - static const qd_real _pi; - static const qd_real _3pi4; - static const qd_real _pi2; - static const qd_real _pi4; - static const qd_real _e; - static const qd_real _log2; - static const qd_real _log10; - static const qd_real _nan; - static const qd_real _inf; - - static const double _eps; - static const double _min_normalized; - static const qd_real _max; - static const qd_real _safe_max; - static const int _ndigits; - - qd_real(); - qd_real(const char *s); - qd_real(const dd_real &dd); - qd_real(double d); - qd_real(int i); - - double operator[](int i) const; - double &operator[](int i); - - static void error(const char *msg); - - bool isnan() const; - bool isfinite() const { return QD_ISFINITE(x[0]); } - bool isinf() const { return QD_ISINF(x[0]); } - - static qd_real ieee_add(const qd_real &a, const qd_real &b); - static qd_real sloppy_add(const qd_real &a, const qd_real &b); - - qd_real &operator+=(double a); - qd_real &operator+=(const dd_real &a); - qd_real &operator+=(const qd_real &a); - - qd_real &operator-=(double a); - qd_real &operator-=(const dd_real &a); - qd_real &operator-=(const qd_real &a); - - static qd_real sloppy_mul(const qd_real &a, const qd_real &b); - static qd_real accurate_mul(const qd_real &a, const qd_real &b); - - qd_real &operator*=(double a); - qd_real &operator*=(const dd_real &a); - qd_real &operator*=(const qd_real &a); - - static qd_real sloppy_div(const qd_real &a, const dd_real &b); - static qd_real accurate_div(const qd_real &a, const dd_real &b); - static qd_real sloppy_div(const qd_real &a, const qd_real &b); - static qd_real accurate_div(const qd_real &a, const qd_real &b); - - qd_real &operator/=(double a); - qd_real &operator/=(const dd_real &a); - qd_real &operator/=(const qd_real &a); - - qd_real operator^(int n) const; - - qd_real operator-() const; - - qd_real &operator=(double a); - qd_real &operator=(const dd_real &a); - qd_real &operator=(const char *s); - - bool is_zero() const; - bool is_one() const; - bool is_positive() const; - bool is_negative() const; - - explicit operator bool() const; // new - explicit operator double() const; // new - - static qd_real rand(void); - - void to_digits(char *s, int &expn, int precision = _ndigits) const; - void write(char *s, int len, int precision = _ndigits, - bool showpos = false, bool uppercase = false) const; - std::string to_string(int precision = _ndigits, int width = 0, - std::ios_base::fmtflags fmt = static_cast<std::ios_base::fmtflags>(0), - bool showpos = false, bool uppercase = false, char fill = ' ') const; - static int read(const char *s, qd_real &a); - - /* Debugging methods */ - void dump(const std::string &name, std::ostream &os = std::cerr) const; - void dump_bits(const std::string &name, - std::ostream &os = std::cerr) const; - - static qd_real debug_rand(); - -}; - -namespace std { - template <> - class numeric_limits<qd_real> : public numeric_limits<double> { - public: - inline static double epsilon() { return qd_real::_eps; } - inline static double min() { return qd_real::_min_normalized; } - inline static qd_real max() { return qd_real::_max; } - inline static qd_real safe_max() { return qd_real::_safe_max; } - static const int digits = 209; - static const int digits10 = 62; - }; -} - -QD_API qd_real polyeval(const qd_real *c, int n, const qd_real &x); -QD_API qd_real polyroot(const qd_real *c, int n, - const qd_real &x0, int max_iter = 64, double thresh = 0.0); - -QD_API qd_real qdrand(void); -QD_API qd_real sqrt(const qd_real &a); - -QD_API inline bool isnan(const qd_real &a) { return a.isnan(); } -QD_API inline bool isfinite(const qd_real &a) { return a.isfinite(); } -QD_API inline bool isinf(const qd_real &a) { return a.isinf(); } - -/* Computes qd * d where d is known to be a power of 2. - This can be done component wise. */ -QD_API qd_real mul_pwr2(const qd_real &qd, double d); - -QD_API qd_real operator+(const qd_real &a, const qd_real &b); -QD_API qd_real operator+(const dd_real &a, const qd_real &b); -QD_API qd_real operator+(const qd_real &a, const dd_real &b); -QD_API qd_real operator+(const qd_real &a, double b); -QD_API qd_real operator+(double a, const qd_real &b); - -QD_API qd_real operator-(const qd_real &a, const qd_real &b); -QD_API qd_real operator-(const dd_real &a, const qd_real &b); -QD_API qd_real operator-(const qd_real &a, const dd_real &b); -QD_API qd_real operator-(const qd_real &a, double b); -QD_API qd_real operator-(double a, const qd_real &b); - -QD_API qd_real operator*(const qd_real &a, const qd_real &b); -QD_API qd_real operator*(const dd_real &a, const qd_real &b); -QD_API qd_real operator*(const qd_real &a, const dd_real &b); -QD_API qd_real operator*(const qd_real &a, double b); -QD_API qd_real operator*(double a, const qd_real &b); - -QD_API qd_real operator/(const qd_real &a, const qd_real &b); -QD_API qd_real operator/(const dd_real &a, const qd_real &b); -QD_API qd_real operator/(const qd_real &a, const dd_real &b); -QD_API qd_real operator/(const qd_real &a, double b); -QD_API qd_real operator/(double a, const qd_real &b); - -QD_API qd_real sqr(const qd_real &a); -QD_API qd_real sqrt(const qd_real &a); -QD_API qd_real pow(const qd_real &a, int n); -QD_API qd_real pow(const qd_real &a, const qd_real &b); -QD_API qd_real npwr(const qd_real &a, int n); - -QD_API qd_real nroot(const qd_real &a, int n); - -QD_API qd_real rem(const qd_real &a, const qd_real &b); -QD_API qd_real drem(const qd_real &a, const qd_real &b); -QD_API qd_real divrem(const qd_real &a, const qd_real &b, qd_real &r); - -dd_real to_dd_real(const qd_real &a); -double to_double(const qd_real &a); -int to_int(const qd_real &a); - -QD_API bool operator==(const qd_real &a, const qd_real &b); -QD_API bool operator==(const qd_real &a, const dd_real &b); -QD_API bool operator==(const dd_real &a, const qd_real &b); -QD_API bool operator==(double a, const qd_real &b); -QD_API bool operator==(const qd_real &a, double b); - -QD_API bool operator<(const qd_real &a, const qd_real &b); -QD_API bool operator<(const qd_real &a, const dd_real &b); -QD_API bool operator<(const dd_real &a, const qd_real &b); -QD_API bool operator<(double a, const qd_real &b); -QD_API bool operator<(const qd_real &a, double b); - -QD_API bool operator>(const qd_real &a, const qd_real &b); -QD_API bool operator>(const qd_real &a, const dd_real &b); -QD_API bool operator>(const dd_real &a, const qd_real &b); -QD_API bool operator>(double a, const qd_real &b); -QD_API bool operator>(const qd_real &a, double b); - -QD_API bool operator<=(const qd_real &a, const qd_real &b); -QD_API bool operator<=(const qd_real &a, const dd_real &b); -QD_API bool operator<=(const dd_real &a, const qd_real &b); -QD_API bool operator<=(double a, const qd_real &b); -QD_API bool operator<=(const qd_real &a, double b); - -QD_API bool operator>=(const qd_real &a, const qd_real &b); -QD_API bool operator>=(const qd_real &a, const dd_real &b); -QD_API bool operator>=(const dd_real &a, const qd_real &b); -QD_API bool operator>=(double a, const qd_real &b); -QD_API bool operator>=(const qd_real &a, double b); - -QD_API bool operator!=(const qd_real &a, const qd_real &b); -QD_API bool operator!=(const qd_real &a, const dd_real &b); -QD_API bool operator!=(const dd_real &a, const qd_real &b); -QD_API bool operator!=(double a, const qd_real &b); -QD_API bool operator!=(const qd_real &a, double b); - -QD_API qd_real fabs(const qd_real &a); -QD_API qd_real abs(const qd_real &a); /* same as fabs */ - -QD_API qd_real ldexp(const qd_real &a, int n); - -QD_API qd_real nint(const qd_real &a); -QD_API qd_real quick_nint(const qd_real &a); -QD_API qd_real floor(const qd_real &a); -QD_API qd_real ceil(const qd_real &a); -QD_API qd_real aint(const qd_real &a); - -QD_API qd_real sin(const qd_real &a); -QD_API qd_real cos(const qd_real &a); -QD_API qd_real tan(const qd_real &a); -QD_API void sincos(const qd_real &a, qd_real &s, qd_real &c); - -QD_API qd_real asin(const qd_real &a); -QD_API qd_real acos(const qd_real &a); -QD_API qd_real atan(const qd_real &a); -QD_API qd_real atan2(const qd_real &y, const qd_real &x); - -QD_API qd_real exp(const qd_real &a); -QD_API qd_real log(const qd_real &a); -QD_API qd_real log10(const qd_real &a); - -QD_API qd_real sinh(const qd_real &a); -QD_API qd_real cosh(const qd_real &a); -QD_API qd_real tanh(const qd_real &a); -QD_API void sincosh(const qd_real &a, qd_real &sin_qd, qd_real &cos_qd); - -QD_API qd_real asinh(const qd_real &a); -QD_API qd_real acosh(const qd_real &a); -QD_API qd_real atanh(const qd_real &a); - -QD_API qd_real qdrand(void); - -QD_API qd_real max(const qd_real &a, const qd_real &b); -QD_API qd_real max(const qd_real &a, const qd_real &b, const qd_real &c); -QD_API qd_real min(const qd_real &a, const qd_real &b); -QD_API qd_real min(const qd_real &a, const qd_real &b, const qd_real &c); - -QD_API qd_real fmod(const qd_real &a, const qd_real &b); - -QD_API std::ostream &operator<<(std::ostream &s, const qd_real &a); -QD_API std::istream &operator>>(std::istream &s, qd_real &a); -#ifdef QD_INLINE -#include "qd_inline.h" -#endif - -#endif /* _QD_QD_REAL_H */ - diff --git a/src/external/PackedCSparse/qd/util.cc b/src/external/PackedCSparse/qd/util.cc deleted file mode 100644 index ab962081..00000000 --- a/src/external/PackedCSparse/qd/util.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include <cstdlib> -#include "util.h" - -void append_expn(std::string &str, int expn) { - int k; - - str += (expn < 0 ? '-' : '+'); - expn = std::abs(expn); - - if (expn >= 100) { - k = (expn / 100); - str += '0' + k; - expn -= 100*k; - } - - k = (expn / 10); - str += '0' + k; - expn -= 10*k; - - str += '0' + expn; -} - diff --git a/src/external/PackedCSparse/qd/util.h b/src/external/PackedCSparse/qd/util.h deleted file mode 100644 index 7de35836..00000000 --- a/src/external/PackedCSparse/qd/util.h +++ /dev/null @@ -1,4 +0,0 @@ -#include <string> - -void append_expn(std::string &str, int expn); - diff --git a/src/external/PackedCSparse/transpose.h b/src/external/PackedCSparse/transpose.h deleted file mode 100644 index 6e1502e3..00000000 --- a/src/external/PackedCSparse/transpose.h +++ /dev/null @@ -1,90 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis -// Copyright (c) 2022 Ioannis Iakovidis - -// This file is converted from PolytopeSamplerMatlab -//(https://github.com/ConstrainedSampler/PolytopeSamplerMatlab/blob/master/code/solver/PackedCSparse/PackedChol.h) by Ioannis Iakovidis -#pragma once -#include "SparseMatrix.h" - -// Problem: -// Compute M = A' - -// Algorithm: -// We precompute the mapping from entries of A to entries of At - -namespace PackedCSparse { - template <typename Tx, typename Ti> - struct TransposeOutput : SparseMatrix<Tx, Ti> - { - UniquePtr<Ti> forward; - - template<typename Tx2> - void initialize(const SparseMatrix<Tx2, Ti>& A) - { - pcs_assert(A.initialized(), "transpose: bad inputs."); - SparseMatrix<Tx, Ti>::initialize(A.n, A.m, A.nnz()); - - Ti Am = A.m, An = A.n, * Ap = A.p.get(), * Ai = A.i.get(); - Ti Bm = this->m, Bn = this->n, * Bp = this->p.get(), * Bi = this->i.get(); - Ti nz = A.nnz(); - - // compute row counts of A - Ti* count = new Ti[Bn + 1](); - - for (Ti p = 0; p < nz; p++) - count[Ai[p]]++; - - // compute this->p - Bp[0] = 0; - for (Ti i = 0; i < Bn; i++) - { - Bp[i + 1] = Bp[i] + count[i]; - count[i] = Bp[i]; // Now, cnt[i] stores the index of the first element in the i-th row - } - - // compute i and forward - if (!std::is_same<Tx, bool>::value) - forward.reset(new Ti[nz]); - for (Ti j = 0; j < An; j++) - { - for (Ti p = Ap[j]; p < Ap[j + 1]; p++) - { - Ti q = count[Ai[p]]; - Bi[q] = j; - if (!std::is_same<Tx, bool>::value) - forward[p] = q; - count[Ai[p]]++; - } - } - - delete[] count; - } - }; - - template <typename Tx, typename Ti, typename Tx2 = Tx> - void transpose(TransposeOutput<Tx2, Ti>& o, const SparseMatrix<Tx, Ti>& A) - { - if (!o.initialized()) - o.initialize(A); - - Tx* Ax = A.x.get(); Tx2 *Bx = o.x.get(); - Ti nz = o.nnz(), *forward = o.forward.get(); - - if (!std::is_same<Tx2, bool>::value) - { - for (Ti s = 0; s < nz; s++) - Bx[forward[s]] = Tx2(Ax[s]); - } - } - - template <typename Tx, typename Ti, typename Tx2 = Tx> - TransposeOutput<Tx2, Ti> transpose(const SparseMatrix<Tx, Ti>& A) - { - TransposeOutput<Tx2, Ti> o; - transpose(o, A); - return o; - } -} diff --git a/src/external/Padua/padua.cpp b/src/external/Padua/padua.cpp deleted file mode 100644 index 3319b637..00000000 --- a/src/external/Padua/padua.cpp +++ /dev/null @@ -1,1868 +0,0 @@ -// Credit to https://people.sc.fsu.edu/~jburkardt/cpp_src/padua/padua.cpp - -# include <cmath> -# include <cstdlib> -# include <cstring> -# include <ctime> -# include <fstream> -# include <iomanip> -# include <iostream> -# include <sstream> - - - - -#include "padua.h" - - - using std::string; - using std::cerr; - using std::ofstream; - using std::ostringstream; - using std::setprecision; - using std::cout; - using std::setw; - - -namespace padua { -//****************************************************************************80 - - void filename_inc(string *filename) - -//****************************************************************************80 -// -// Purpose: -// -// FILENAME_INC increments a partially numeric file name. -// -// Discussion: -// -// It is assumed that the digits in the name, whether scattered or -// connected, represent a number that is to be increased by 1 on -// each call. If this number is all 9's on input, the output number -// is all 0's. Non-numeric letters of the name are unaffected. -// -// If the name is empty, then the routine stops. -// -// If the name contains no digits, the empty string is returned. -// -// Example: -// -// Input Output -// ----- ------ -// "a7to11.txt" "a7to12.txt" (typical case. Last digit incremented) -// "a7to99.txt" "a8to00.txt" (last digit incremented, with carry.) -// "a9to99.txt" "a0to00.txt" (wrap around) -// "cat.txt" " " (no digits to increment) -// " " STOP! (error) -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 22 November 2011 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input/output, string *FILENAME, the filename to be incremented. -// - { - char c; - int change; - int i; - int lens; - - lens = (*filename).length(); - - if (lens <= 0) { - cerr << "\n"; - cerr << "FILENAME_INC - Fatal error!\n"; - cerr << " The input string is empty.\n"; - exit(1); - } - - change = 0; - - for (i = lens - 1; 0 <= i; i--) { - c = (*filename)[i]; - - if ('0' <= c && c <= '9') { - change = change + 1; - - if (c == '9') { - c = '0'; - (*filename)[i] = c; - } else { - c = c + 1; - (*filename)[i] = c; - return; - } - } - } -// -// No digits were found. Return blank. -// - if (change == 0) { - for (i = lens - 1; 0 <= i; i--) { - (*filename)[i] = ' '; - } - } - - return; - } -//****************************************************************************80 - - string i4_to_string(int i4) - -//****************************************************************************80 -// -// Purpose: -// -// I4_TO_STRING converts an I4 to a C++ string. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 16 January 2013 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input, int I4, an integer. -// -// Input, string FORMAT, the format string. -// -// Output, string I4_TO_STRING, the string. -// - { - ostringstream fred; - string value; - - fred << i4; - - value = fred.str(); - - return value; - } -//****************************************************************************80 - - int padua_order(int l) - -//****************************************************************************80 -// -// Purpose: -// -// PADUA_ORDER returns the size of the Padua set of given level. -// -// Discussion: -// -// The Padua sets are indexed by a level that starts at 0. -// This function returns the number of points in each level. -// -// Example: -// -// Level Size -// ----- ---- -// 0 1 -// 1 3 -// 2 6 -// 3 10 -// 4 15 -// 5 21 -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 07 April 2014 -// -// Author: -// -// John Burkardt -// -// Reference: -// -// Marco Caliari, Stefano de Marchi, Marco Vianello, -// Bivariate interpolation on the square at new nodal sets, -// Applied Mathematics and Computation, -// Volume 165, Number 2, 2005, pages 261-274. -// -// Parameters: -// -// Input, int L, the level of the set. -// 0 <= L -// -// Output, int PADUA_ORDER, the order (number of points) in the set. -// - { - int i; - int n; - - n = 0; - for (i = 0; i <= l; i++) { - n = n + (l / 2) + 1; - if ((l % 2) == 1 && (i % 2) == 1) { - n = n + 1; - } - } - - return n; - } -//****************************************************************************80 - - void padua_plot(int l, string filename) - -//****************************************************************************80 -// -// Purpose: -// -// PADUA_PLOT plots the Padua points of given level. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 09 June 2014 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input, int L, the level of the set. -// 0 <= L -// -// Input, string FILENAME, a common filename prefix for -// the files to be created. -// - { - string command_filename; - ofstream command_unit; - string data_filename; - ofstream data_unit; - int j; - int n; - string plot_filename; - double *xy; - - n = padua_order(l); - - xy = padua_points(l); -// -// Create graphics data file. -// - data_filename = filename + "_data.txt"; - data_unit.open(data_filename.c_str()); - for (j = 0; j < n; j++) { - data_unit << " " << setprecision(16) << xy[0 + j * 2] - << " " << setprecision(16) << xy[1 + j * 2] << "\n"; - } - data_unit.close(); - cout << "\n"; - cout << " Created data file '" << data_filename << "'.\n"; -// -// Create graphics command file. -// - command_filename = filename + "_commands.txt"; - command_unit.open(command_filename.c_str()); - command_unit << "# " << command_filename << "\n"; - command_unit << "#\n"; - command_unit << "# Usage:\n"; - command_unit << "# gnuplot < " << command_filename << "\n"; - command_unit << "#\n"; - command_unit << "set term png\n"; - plot_filename = filename + ".png"; - command_unit << "set output '" << plot_filename << "'\n"; - command_unit << "set xlabel '<--- X --->'\n"; - command_unit << "set ylabel '<--- Y --->'\n"; - command_unit << "set title 'Padua Points, Level " << l << "\n"; - command_unit << "set grid\n"; - command_unit << "set key off\n"; - command_unit << "set size ratio -1\n"; - command_unit << "set style data lines\n"; - command_unit << "set timestamp\n"; - command_unit << "plot [-1:+1] [-1:+1] '" << data_filename - << "' using 1:2 with points lt 3 pt 3\n"; - command_unit.close(); - - cout << " Created command file '" << command_filename << "'.\n"; -// -// Free memory. -// - delete[] xy; - - return; - } -//****************************************************************************80 - - double *padua_points(int l) - -//****************************************************************************80 -// -// Purpose: -// -// PADUA_POINTS returns the Padua points of level L. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 09 June 2014 -// -// Author: -// -// John Burkardt -// -// Reference: -// -// Marco Caliari, Stefano de Marchi, Marco Vianello, -// Bivariate interpolation on the square at new nodal sets, -// Applied Mathematics and Computation, -// Volume 165, Number 2, 2005, pages 261-274. -// -// Parameters: -// -// Input, int L, the level of the set. -// 0 <= L -// -// Output, double PADUA_POINTS[2*((L+1)*(L+2))/2)], the Padua points. -// - { - double angle1; - double angle2; - int i; - int j; - int j_hi; - int k; - int n; - const double r8_pi = 3.141592653589793; - double *xy; - - n = ((l + 1) * (l + 2)) / 2; - xy = new double[2 * n]; - - if (l == 0) { - xy[0 + 0 * 2] = 0.0; - xy[1 + 0 * 2] = 0.0; - return xy; - } - - k = 0; - - for (i = 0; i <= l; i++) { - j_hi = (l / 2) + 1; - if ((l % 2) == 1 && (i % 2) == 1) { - j_hi = j_hi + 1; - } - - for (j = 1; j <= j_hi; j++) { - if (i * 2 == l) { - xy[0 + k * 2] = 0.0; - } else { - angle1 = (double) (i) * r8_pi / (double) (l); - xy[0 + k * 2] = cos(angle1); - } - - if ((i % 2) == 0) { - if (2 * (2 * j - 1) == l + 1) { - xy[1 + k * 2] = 0.0; - } else { - angle2 = (double) (2 * j - 1) * r8_pi / (double) (l + 1); - xy[1 + k * 2] = cos(angle2); - } - } else { - if (2 * (2 * j - 2) == l + 1) { - xy[1 + k * 2] = 0.0; - } else { - angle2 = (double) (2 * j - 2) * r8_pi / (double) (l + 1); - xy[1 + k * 2] = cos(angle2); - } - } - k = k + 1; - } - } - - return xy; - } -//****************************************************************************80 - - double *padua_points_set(int l) - -//****************************************************************************80 -// -// Purpose: -// -// PADUA_POINTS_SET sets the Padua points. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 30 August 2016 -// -// Author: -// -// John Burkardt -// -// Reference: -// -// Marco Caliari, Stefano de Marchi, Marco Vianello, -// Bivariate interpolation on the square at new nodal sets, -// Applied Mathematics and Computation, -// Volume 165, Number 2, 2005, pages 261-274. -// -// Parameters: -// -// Input, int L, the level. -// 0 <= L <= 10. -// -// Output, double PADUA_POINTS_SET[2*N], the Padua points. -// - { - int j1; - int j1_hi; - int j2; - int n; - double t; - double *xy; - double xy00[2 * 1] = { - 0.000000000000000, 0.000000000000000}; - double xy01[2 * 3] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, 1.000000000000000, - 1.000000000000000, 0.000000000000000}; - double xy02[2 * 6] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, 0.5000000000000001, - 0.000000000000000, -0.4999999999999998, - 0.000000000000000, 1.000000000000000, - 1.000000000000000, -1.000000000000000, - 1.000000000000000, 0.5000000000000001}; - double xy03[2 * 10] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, 0.000000000000000, - -1.000000000000000, 1.000000000000000, - -0.4999999999999998, -0.7071067811865475, - -0.4999999999999998, 0.7071067811865476, - 0.5000000000000001, -1.000000000000000, - 0.5000000000000001, 0.000000000000000, - 0.5000000000000001, 1.000000000000000, - 1.000000000000000, -0.7071067811865475, - 1.000000000000000, 0.7071067811865476}; - double xy04[2 * 15] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, -0.3090169943749473, - -1.000000000000000, 0.8090169943749475, - -0.7071067811865475, -0.8090169943749473, - -0.7071067811865475, 0.3090169943749475, - -0.7071067811865475, 1.000000000000000, - 0.000000000000000, -1.000000000000000, - 0.000000000000000, -0.3090169943749473, - 0.000000000000000, 0.8090169943749475, - 0.7071067811865476, -0.8090169943749473, - 0.7071067811865476, 0.3090169943749475, - 0.7071067811865476, 1.000000000000000, - 1.000000000000000, -1.000000000000000, - 1.000000000000000, -0.3090169943749473, - 1.000000000000000, 0.8090169943749475}; - double xy05[2 * 21] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, -0.4999999999999998, - -1.000000000000000, 0.5000000000000001, - -1.000000000000000, 1.000000000000000, - -0.8090169943749473, -0.8660254037844387, - -0.8090169943749473, 0.000000000000000, - -0.8090169943749473, 0.8660254037844387, - -0.3090169943749473, -1.000000000000000, - -0.3090169943749473, -0.4999999999999998, - -0.3090169943749473, 0.5000000000000001, - -0.3090169943749473, 1.000000000000000, - 0.3090169943749475, -0.8660254037844387, - 0.3090169943749475, 0.000000000000000, - 0.3090169943749475, 0.8660254037844387, - 0.8090169943749475, -1.000000000000000, - 0.8090169943749475, -0.4999999999999998, - 0.8090169943749475, 0.5000000000000001, - 0.8090169943749475, 1.000000000000000, - 1.000000000000000, -0.8660254037844387, - 1.000000000000000, 0.000000000000000, - 1.000000000000000, 0.8660254037844387}; - double xy06[2 * 28] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, -0.6234898018587335, - -1.000000000000000, 0.2225209339563144, - -1.000000000000000, 0.9009688679024191, - -0.8660254037844387, -0.9009688679024190, - -0.8660254037844387, -0.2225209339563143, - -0.8660254037844387, 0.6234898018587336, - -0.8660254037844387, 1.000000000000000, - -0.4999999999999998, -1.000000000000000, - -0.4999999999999998, -0.6234898018587335, - -0.4999999999999998, 0.2225209339563144, - -0.4999999999999998, 0.9009688679024191, - 0.000000000000000, -0.9009688679024190, - 0.000000000000000, -0.2225209339563143, - 0.000000000000000, 0.6234898018587336, - 0.000000000000000, 1.000000000000000, - 0.5000000000000001, -1.000000000000000, - 0.5000000000000001, -0.6234898018587335, - 0.5000000000000001, 0.2225209339563144, - 0.5000000000000001, 0.9009688679024191, - 0.8660254037844387, -0.9009688679024190, - 0.8660254037844387, -0.2225209339563143, - 0.8660254037844387, 0.6234898018587336, - 0.8660254037844387, 1.000000000000000, - 1.000000000000000, -1.000000000000000, - 1.000000000000000, -0.6234898018587335, - 1.000000000000000, 0.2225209339563144, - 1.000000000000000, 0.9009688679024191}; - double xy07[2 * 36] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, -0.7071067811865475, - -1.000000000000000, 0.000000000000000, - -1.000000000000000, 0.7071067811865476, - -1.000000000000000, 1.000000000000000, - -0.9009688679024190, -0.9238795325112867, - -0.9009688679024190, -0.3826834323650897, - -0.9009688679024190, 0.3826834323650898, - -0.9009688679024190, 0.9238795325112867, - -0.6234898018587335, -1.000000000000000, - -0.6234898018587335, -0.7071067811865475, - -0.6234898018587335, 0.000000000000000, - -0.6234898018587335, 0.7071067811865476, - -0.6234898018587335, 1.000000000000000, - -0.2225209339563143, -0.9238795325112867, - -0.2225209339563143, -0.3826834323650897, - -0.2225209339563143, 0.3826834323650898, - -0.2225209339563143, 0.9238795325112867, - 0.2225209339563144, -1.000000000000000, - 0.2225209339563144, -0.7071067811865475, - 0.2225209339563144, 0.000000000000000, - 0.2225209339563144, 0.7071067811865476, - 0.2225209339563144, 1.000000000000000, - 0.6234898018587336, -0.9238795325112867, - 0.6234898018587336, -0.3826834323650897, - 0.6234898018587336, 0.3826834323650898, - 0.6234898018587336, 0.9238795325112867, - 0.9009688679024191, -1.000000000000000, - 0.9009688679024191, -0.7071067811865475, - 0.9009688679024191, 0.000000000000000, - 0.9009688679024191, 0.7071067811865476, - 0.9009688679024191, 1.000000000000000, - 1.000000000000000, -0.9238795325112867, - 1.000000000000000, -0.3826834323650897, - 1.000000000000000, 0.3826834323650898, - 1.000000000000000, 0.9238795325112867}; - double xy08[2 * 45] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, -0.7660444431189779, - -1.000000000000000, -0.1736481776669303, - -1.000000000000000, 0.5000000000000001, - -1.000000000000000, 0.9396926207859084, - -0.9238795325112867, -0.9396926207859083, - -0.9238795325112867, -0.4999999999999998, - -0.9238795325112867, 0.1736481776669304, - -0.9238795325112867, 0.7660444431189780, - -0.9238795325112867, 1.000000000000000, - -0.7071067811865475, -1.000000000000000, - -0.7071067811865475, -0.7660444431189779, - -0.7071067811865475, -0.1736481776669303, - -0.7071067811865475, 0.5000000000000001, - -0.7071067811865475, 0.9396926207859084, - -0.3826834323650897, -0.9396926207859083, - -0.3826834323650897, -0.4999999999999998, - -0.3826834323650897, 0.1736481776669304, - -0.3826834323650897, 0.7660444431189780, - -0.3826834323650897, 1.000000000000000, - 0.000000000000000, -1.000000000000000, - 0.000000000000000, -0.7660444431189779, - 0.000000000000000, -0.1736481776669303, - 0.000000000000000, 0.5000000000000001, - 0.000000000000000, 0.9396926207859084, - 0.3826834323650898, -0.9396926207859083, - 0.3826834323650898, -0.4999999999999998, - 0.3826834323650898, 0.1736481776669304, - 0.3826834323650898, 0.7660444431189780, - 0.3826834323650898, 1.000000000000000, - 0.7071067811865476, -1.000000000000000, - 0.7071067811865476, -0.7660444431189779, - 0.7071067811865476, -0.1736481776669303, - 0.7071067811865476, 0.5000000000000001, - 0.7071067811865476, 0.9396926207859084, - 0.9238795325112867, -0.9396926207859083, - 0.9238795325112867, -0.4999999999999998, - 0.9238795325112867, 0.1736481776669304, - 0.9238795325112867, 0.7660444431189780, - 0.9238795325112867, 1.000000000000000, - 1.000000000000000, -1.000000000000000, - 1.000000000000000, -0.7660444431189779, - 1.000000000000000, -0.1736481776669303, - 1.000000000000000, 0.5000000000000001, - 1.000000000000000, 0.9396926207859084}; - double xy09[2 * 55] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, -0.8090169943749473, - -1.000000000000000, -0.3090169943749473, - -1.000000000000000, 0.3090169943749475, - -1.000000000000000, 0.8090169943749475, - -1.000000000000000, 1.000000000000000, - -0.9396926207859083, -0.9510565162951535, - -0.9396926207859083, -0.5877852522924730, - -0.9396926207859083, 0.000000000000000, - -0.9396926207859083, 0.5877852522924731, - -0.9396926207859083, 0.9510565162951535, - -0.7660444431189779, -1.000000000000000, - -0.7660444431189779, -0.8090169943749473, - -0.7660444431189779, -0.3090169943749473, - -0.7660444431189779, 0.3090169943749475, - -0.7660444431189779, 0.8090169943749475, - -0.7660444431189779, 1.000000000000000, - -0.4999999999999998, -0.9510565162951535, - -0.4999999999999998, -0.5877852522924730, - -0.4999999999999998, 0.000000000000000, - -0.4999999999999998, 0.5877852522924731, - -0.4999999999999998, 0.9510565162951535, - -0.1736481776669303, -1.000000000000000, - -0.1736481776669303, -0.8090169943749473, - -0.1736481776669303, -0.3090169943749473, - -0.1736481776669303, 0.3090169943749475, - -0.1736481776669303, 0.8090169943749475, - -0.1736481776669303, 1.000000000000000, - 0.1736481776669304, -0.9510565162951535, - 0.1736481776669304, -0.5877852522924730, - 0.1736481776669304, 0.000000000000000, - 0.1736481776669304, 0.5877852522924731, - 0.1736481776669304, 0.9510565162951535, - 0.5000000000000001, -1.000000000000000, - 0.5000000000000001, -0.8090169943749473, - 0.5000000000000001, -0.3090169943749473, - 0.5000000000000001, 0.3090169943749475, - 0.5000000000000001, 0.8090169943749475, - 0.5000000000000001, 1.000000000000000, - 0.7660444431189780, -0.9510565162951535, - 0.7660444431189780, -0.5877852522924730, - 0.7660444431189780, 0.000000000000000, - 0.7660444431189780, 0.5877852522924731, - 0.7660444431189780, 0.9510565162951535, - 0.9396926207859084, -1.000000000000000, - 0.9396926207859084, -0.8090169943749473, - 0.9396926207859084, -0.3090169943749473, - 0.9396926207859084, 0.3090169943749475, - 0.9396926207859084, 0.8090169943749475, - 0.9396926207859084, 1.000000000000000, - 1.000000000000000, -0.9510565162951535, - 1.000000000000000, -0.5877852522924730, - 1.000000000000000, 0.000000000000000, - 1.000000000000000, 0.5877852522924731, - 1.000000000000000, 0.9510565162951535}; - double xy10[2 * 66] = { - -1.000000000000000, -1.000000000000000, - -1.000000000000000, -0.8412535328311811, - -1.000000000000000, -0.4154150130018863, - -1.000000000000000, 0.1423148382732851, - -1.000000000000000, 0.6548607339452851, - -1.000000000000000, 0.9594929736144974, - -0.9510565162951535, -0.9594929736144974, - -0.9510565162951535, -0.6548607339452850, - -0.9510565162951535, -0.1423148382732850, - -0.9510565162951535, 0.4154150130018864, - -0.9510565162951535, 0.8412535328311812, - -0.9510565162951535, 1.000000000000000, - -0.8090169943749473, -1.000000000000000, - -0.8090169943749473, -0.8412535328311811, - -0.8090169943749473, -0.4154150130018863, - -0.8090169943749473, 0.1423148382732851, - -0.8090169943749473, 0.6548607339452851, - -0.8090169943749473, 0.9594929736144974, - -0.5877852522924730, -0.9594929736144974, - -0.5877852522924730, -0.6548607339452850, - -0.5877852522924730, -0.1423148382732850, - -0.5877852522924730, 0.4154150130018864, - -0.5877852522924730, 0.8412535328311812, - -0.5877852522924730, 1.000000000000000, - -0.3090169943749473, -1.000000000000000, - -0.3090169943749473, -0.8412535328311811, - -0.3090169943749473, -0.4154150130018863, - -0.3090169943749473, 0.1423148382732851, - -0.3090169943749473, 0.6548607339452851, - -0.3090169943749473, 0.9594929736144974, - 0.000000000000000, -0.9594929736144974, - 0.000000000000000, -0.6548607339452850, - 0.000000000000000, -0.1423148382732850, - 0.000000000000000, 0.4154150130018864, - 0.000000000000000, 0.8412535328311812, - 0.000000000000000, 1.000000000000000, - 0.3090169943749475, -1.000000000000000, - 0.3090169943749475, -0.8412535328311811, - 0.3090169943749475, -0.4154150130018863, - 0.3090169943749475, 0.1423148382732851, - 0.3090169943749475, 0.6548607339452851, - 0.3090169943749475, 0.9594929736144974, - 0.5877852522924731, -0.9594929736144974, - 0.5877852522924731, -0.6548607339452850, - 0.5877852522924731, -0.1423148382732850, - 0.5877852522924731, 0.4154150130018864, - 0.5877852522924731, 0.8412535328311812, - 0.5877852522924731, 1.000000000000000, - 0.8090169943749475, -1.000000000000000, - 0.8090169943749475, -0.8412535328311811, - 0.8090169943749475, -0.4154150130018863, - 0.8090169943749475, 0.1423148382732851, - 0.8090169943749475, 0.6548607339452851, - 0.8090169943749475, 0.9594929736144974, - 0.9510565162951535, -0.9594929736144974, - 0.9510565162951535, -0.6548607339452850, - 0.9510565162951535, -0.1423148382732850, - 0.9510565162951535, 0.4154150130018864, - 0.9510565162951535, 0.8412535328311812, - 0.9510565162951535, 1.000000000000000, - 1.000000000000000, -1.000000000000000, - 1.000000000000000, -0.8412535328311811, - 1.000000000000000, -0.4154150130018863, - 1.000000000000000, 0.1423148382732851, - 1.000000000000000, 0.6548607339452851, - 1.000000000000000, 0.9594929736144974}; - - n = ((l + 1) * (l + 2)) / 2; - - if (l == 0) { - xy = r8vec_copy_new(2 * n, xy00); - } else if (l == 1) { - xy = r8vec_copy_new(2 * n, xy01); - } else if (l == 2) { - xy = r8vec_copy_new(2 * n, xy02); - } else if (l == 3) { - xy = r8vec_copy_new(2 * n, xy03); - } else if (l == 4) { - xy = r8vec_copy_new(2 * n, xy04); - } else if (l == 5) { - xy = r8vec_copy_new(2 * n, xy05); - } else if (l == 6) { - xy = r8vec_copy_new(2 * n, xy06); - } else if (l == 7) { - xy = r8vec_copy_new(2 * n, xy07); - } else if (l == 8) { - xy = r8vec_copy_new(2 * n, xy08); - } else if (l == 9) { - xy = r8vec_copy_new(2 * n, xy09); - } else if (l == 10) { - xy = r8vec_copy_new(2 * n, xy10); - } else { - cerr << "\n"; - cerr << "PADUA_POINTS_SET - Fatal error!\n"; - cerr << " Illegal value of L = " << l << "\n"; - cerr << " Legal values are 1 through 10.\n"; - exit(1); - } -// -// Reverse data to match published information. -// - j1_hi = (n - 1) / 2; - - for (j1 = 0; j1 < j1_hi; j1++) { - j2 = n - 1 - j1; - t = xy[0 + 2 * j1]; - xy[0 + 2 * j1] = xy[0 + 2 * j2]; - xy[0 + 2 * j2] = t; - t = xy[1 + 2 * j1]; - xy[1 + 2 * j1] = xy[1 + 2 * j2]; - xy[1 + 2 * j2] = t; - } - - return xy; - } -//****************************************************************************80 - - double *padua_weights_set(int l) - -//****************************************************************************80 -// -// Purpose: -// -// PADUA_WEIGHTS_SET sets quadrature weights for the Padua points. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 11 June 2014 -// -// Author: -// -// John Burkardt -// -// Reference: -// -// Marco Caliari, Stefano de Marchi, Marco Vianello, -// Bivariate interpolation on the square at new nodal sets, -// Applied Mathematics and Computation, -// Volume 165, Number 2, 2005, pages 261-274. -// -// Parameters: -// -// Input, int L, the level. -// 0 <= L <= 10. -// -// Output, double PADUA_WEIGHTS_SET[N], the quadrature weights. -// - { - int n; - double *w; - - n = ((l + 1) * (l + 2)) / 2; - w = new double[n]; - - if (l == 0) { - w[0] = 4.000000000000000E+00; - } else if (l == 1) { - w[0] = 1.000000000000000E+00; - w[1] = 1.000000000000000E+00; - w[2] = 2.000000000000000E+00; - } else if (l == 2) { - w[0] = 0.0E+00; - w[1] = 0.6666666666666663E+00; - w[2] = 2.222222222222222E+00; - w[3] = 0.4444444444444444E+00; - w[4] = 0.0E+00; - w[5] = 0.6666666666666664E+00; - } else if (l == 3) { - w[0] = -0.5555555555555480E-01; - w[1] = 0.3333333333333331E+00; - w[2] = -0.5555555555555580E-01; - w[3] = 0.8888888888888886E+00; - w[4] = 0.8888888888888893E+00; - w[5] = 0.2222222222222224E+00; - w[6] = 1.333333333333333E+00; - w[7] = 0.2222222222222220E+00; - w[8] = 0.1111111111111109E+00; - w[9] = 0.1111111111111112E+00; - } else if (l == 4) { - w[0] = -0.8888888888888932E-02; - w[1] = 0.8104919101110961E-01; - w[2] = 0.6117303121111219E-01; - w[3] = 0.3874097078666789E+00; - w[4] = 0.6259236254666545E+00; - w[5] = 0.5333333333333362E-01; - w[6] = 0.7111111111111067E-01; - w[7] = 0.9830822022444241E+00; - w[8] = 0.5458066866444642E+00; - w[9] = 0.3874097078666780E+00; - w[10] = 0.6259236254666568E+00; - w[11] = 0.5333333333333383E-01; - w[12] = -0.8888888888888703E-02; - w[13] = 0.8104919101110968E-01; - w[14] = 0.6117303121111135E-01; - } else if (l == 5) { - w[0] = -0.1037037037037093E-01; - w[1] = 0.5037037037036911E-01; - w[2] = 0.5037037037037081E-01; - w[3] = -0.1037037037036947E-01; - w[4] = 0.1876963678740801E+00; - w[5] = 0.3460933466518654E+00; - w[6] = 0.1876963678740763E+00; - w[7] = 0.4514390511851724E-01; - w[8] = 0.5541130536814713E+00; - w[9] = 0.5541130536814728E+00; - w[10] = 0.4514390511851834E-01; - w[11] = 0.2804517802740705E+00; - w[12] = 0.6376103570518378E+00; - w[13] = 0.2804517802740683E+00; - w[14] = 0.3189313191851883E-01; - w[15] = 0.3288499092814910E+00; - w[16] = 0.3288499092814925E+00; - w[17] = 0.3189313191851956E-01; - w[18] = 0.2074074074074123E-01; - w[19] = 0.3851851851851849E-01; - w[20] = 0.2074074074074051E-01; - } else if (l == 6) { - w[0] = -0.3023431594858565E-02; - w[1] = 0.1957267632451884E-01; - w[2] = 0.2633929313290840E-01; - w[3] = 0.1425431928029237E-01; - w[4] = 0.1006383046329639E+00; - w[5] = 0.2208900184526934E+00; - w[6] = 0.1743144584714012E+00; - w[7] = 0.1209372637943976E-01; - w[8] = 0.1934996220710680E-01; - w[9] = 0.3245064820875231E+00; - w[10] = 0.4027058473592984E+00; - w[11] = 0.1677234226317961E+00; - w[12] = 0.1953319357827178E+00; - w[13] = 0.4489633053035124E+00; - w[14] = 0.3721824611057551E+00; - w[15] = 0.2479213907785274E-01; - w[16] = 0.1934996220710561E-01; - w[17] = 0.3245064820875153E+00; - w[18] = 0.4027058473592959E+00; - w[19] = 0.1677234226317944E+00; - w[20] = 0.1006383046329745E+00; - w[21] = 0.2208900184526933E+00; - w[22] = 0.1743144584714027E+00; - w[23] = 0.1209372637944051E-01; - w[24] = -0.3023431594861990E-02; - w[25] = 0.1957267632451757E-01; - w[26] = 0.2633929313290797E-01; - w[27] = 0.1425431928029198E-01; - } else if (l == 7) { - w[0] = -0.3287981859413765E-02; - w[1] = 0.1337868480725671E-01; - w[2] = 0.2063492063491996E-01; - w[3] = 0.1337868480725546E-01; - w[4] = -0.3287981859408898E-02; - w[5] = 0.5949324721885513E-01; - w[6] = 0.1306477599993571E+00; - w[7] = 0.1306477599993581E+00; - w[8] = 0.5949324721885061E-01; - w[9] = 0.1263869091685831E-01; - w[10] = 0.1979944935601103E+00; - w[11] = 0.2832184784823740E+00; - w[12] = 0.1979944935601143E+00; - w[13] = 0.1263869091685747E-01; - w[14] = 0.1221817987389771E+00; - w[15] = 0.3150266070593529E+00; - w[16] = 0.3150266070593440E+00; - w[17] = 0.1221817987389802E+00; - w[18] = 0.1771365352315134E-01; - w[19] = 0.2490926964598258E+00; - w[20] = 0.3408041116306980E+00; - w[21] = 0.2490926964598291E+00; - w[22] = 0.1771365352314976E-01; - w[23] = 0.9646986307476696E-01; - w[24] = 0.2557725606433917E+00; - w[25] = 0.2557725606433927E+00; - w[26] = 0.9646986307476431E-01; - w[27] = 0.8649923133686802E-02; - w[28] = 0.1062007918394705E+00; - w[29] = 0.1505805844901012E+00; - w[30] = 0.1062007918394705E+00; - w[31] = 0.8649923133690016E-02; - w[32] = 0.6355881462931014E-02; - w[33] = 0.1405228180237514E-01; - w[34] = 0.1405228180237651E-01; - w[35] = 0.6355881462928496E-02; - } else if (l == 8) { - w[0] = -0.1269841269835311E-02; - w[1] = 0.6706089639041270E-02; - w[2] = 0.1111455441352989E-01; - w[3] = 0.1026455026455282E-01; - w[4] = 0.4930678698742625E-02; - w[5] = 0.3633146869162523E-01; - w[6] = 0.8838322767333079E-01; - w[7] = 0.9965911758463214E-01; - w[8] = 0.6400185533755555E-01; - w[9] = 0.4061629144893127E-02; - w[10] = 0.6772486772485166E-02; - w[11] = 0.1258344472781388E+00; - w[12] = 0.1927501398511116E+00; - w[13] = 0.1699470899470907E+00; - w[14] = 0.6342599488133535E-01; - w[15] = 0.8376332474107638E-01; - w[16] = 0.2170841444607031E+00; - w[17] = 0.2477307250801775E+00; - w[18] = 0.1648098048612226E+00; - w[19] = 0.1004771829779292E-01; - w[20] = 0.1015873015872910E-01; - w[21] = 0.1784328991205164E+00; - w[22] = 0.2729409493576765E+00; - w[23] = 0.2364021164021134E+00; - w[24] = 0.8936689226256009E-01; - w[25] = 0.8376332474107701E-01; - w[26] = 0.2170841444607054E+00; - w[27] = 0.2477307250801761E+00; - w[28] = 0.1648098048612200E+00; - w[29] = 0.1004771829779330E-01; - w[30] = 0.6772486772485237E-02; - w[31] = 0.1258344472781358E+00; - w[32] = 0.1927501398511135E+00; - w[33] = 0.1699470899470926E+00; - w[34] = 0.6342599488133838E-01; - w[35] = 0.3633146869162453E-01; - w[36] = 0.8838322767332588E-01; - w[37] = 0.9965911758463601E-01; - w[38] = 0.6400185533755502E-01; - w[39] = 0.4061629144888279E-02; - w[40] = -0.1269841269836355E-02; - w[41] = 0.6706089639046927E-02; - w[42] = 0.1111455441352761E-01; - w[43] = 0.1026455026454956E-01; - w[44] = 0.4930678698747173E-02; - } else if (l == 9) { - w[0] = -0.1368606701945113E-02; - w[1] = 0.4837977417140975E-02; - w[2] = 0.8876308297144902E-02; - w[3] = 0.8876308297143068E-02; - w[4] = 0.4837977417150492E-02; - w[5] = -0.1368606701935084E-02; - w[6] = 0.2425285860992349E-01; - w[7] = 0.5727330842923516E-01; - w[8] = 0.7008257906578071E-01; - w[9] = 0.5727330842922034E-01; - w[10] = 0.2425285860989794E-01; - w[11] = 0.4659404339099723E-02; - w[12] = 0.8354521980498550E-01; - w[13] = 0.1370796991940044E+00; - w[14] = 0.1370796991940248E+00; - w[15] = 0.8354521980500107E-01; - w[16] = 0.4659404339109654E-02; - w[17] = 0.5564545640233619E-01; - w[18] = 0.1524391996823315E+00; - w[19] = 0.1877107583774149E+00; - w[20] = 0.1524391996823176E+00; - w[21] = 0.5564545640232402E-01; - w[22] = 0.8186176158691754E-02; - w[23] = 0.1295355639606716E+00; - w[24] = 0.2061407656847711E+00; - w[25] = 0.2061407656847630E+00; - w[26] = 0.1295355639606894E+00; - w[27] = 0.8186176158692687E-02; - w[28] = 0.6234969028097752E-01; - w[29] = 0.1730419031522391E+00; - w[30] = 0.2169418247419051E+00; - w[31] = 0.1730419031522361E+00; - w[32] = 0.6234969028097048E-01; - w[33] = 0.7506172839505762E-02; - w[34] = 0.1142161960569350E+00; - w[35] = 0.1802176663769002E+00; - w[36] = 0.1802176663769038E+00; - w[37] = 0.1142161960569279E+00; - w[38] = 0.7506172839512260E-02; - w[39] = 0.4031900987631698E-01; - w[40] = 0.1142976211857364E+00; - w[41] = 0.1413353845521477E+00; - w[42] = 0.1142976211857414E+00; - w[43] = 0.4031900987631700E-01; - w[44] = 0.3239075586856897E-02; - w[45] = 0.4317587564913915E-01; - w[46] = 0.7015250533601934E-01; - w[47] = 0.7015250533601930E-01; - w[48] = 0.4317587564913908E-01; - w[49] = 0.3239075586852207E-02; - w[50] = 0.2550690557469151E-02; - w[51] = 0.6084230077461027E-02; - w[52] = 0.7421516754852508E-02; - w[53] = 0.6084230077458821E-02; - w[54] = 0.2550690557473353E-02; - } else if (l == 10) { - w[0] = -0.6240762604463766E-03; - w[1] = 0.2843227149025789E-02; - w[2] = 0.5250031948150784E-02; - w[3] = 0.5891746241568810E-02; - w[4] = 0.4705736485964679E-02; - w[5] = 0.2135354637732944E-02; - w[6] = 0.1610939653924566E-01; - w[7] = 0.4099595211758227E-01; - w[8] = 0.5326500934654063E-01; - w[9] = 0.4863338516658277E-01; - w[10] = 0.2843474741781434E-01; - w[11] = 0.1719619179693151E-02; - w[12] = 0.2883769745121509E-02; - w[13] = 0.5724711668876453E-01; - w[14] = 0.9659872841640438E-01; - w[15] = 0.1053210323353631E+00; - w[16] = 0.8066212502628711E-01; - w[17] = 0.2855765663647366E-01; - w[18] = 0.3981286043310814E-01; - w[19] = 0.1090390674981577E+00; - w[20] = 0.1430169021081585E+00; - w[21] = 0.1313686303763064E+00; - w[22] = 0.7932850918298831E-01; - w[23] = 0.4610696968783255E-02; - w[24] = 0.5086495679684716E-02; - w[25] = 0.9311356395361167E-01; - w[26] = 0.1562320334111262E+00; - w[27] = 0.1696057154254139E+00; - w[28] = 0.1283581371975154E+00; - w[29] = 0.4603059518094556E-01; - w[30] = 0.4894888812994630E-01; - w[31] = 0.1347281473526573E+00; - w[32] = 0.1764193542601264E+00; - w[33] = 0.1635037456303485E+00; - w[34] = 0.9822749154565460E-01; - w[35] = 0.5704840613923174E-02; - w[36] = 0.5086495679679268E-02; - w[37] = 0.9311356395362781E-01; - w[38] = 0.1562320334111511E+00; - w[39] = 0.1696057154253968E+00; - w[40] = 0.1283581371975113E+00; - w[41] = 0.4603059518094044E-01; - w[42] = 0.3981286043311782E-01; - w[43] = 0.1090390674981293E+00; - w[44] = 0.1430169021081508E+00; - w[45] = 0.1313686303763217E+00; - w[46] = 0.7932850918299997E-01; - w[47] = 0.4610696968790496E-02; - w[48] = 0.2883769745110260E-02; - w[49] = 0.5724711668875122E-01; - w[50] = 0.9659872841642343E-01; - w[51] = 0.1053210323353932E+00; - w[52] = 0.8066212502626474E-01; - w[53] = 0.2855765663644533E-01; - w[54] = 0.1610939653928420E-01; - w[55] = 0.4099595211758404E-01; - w[56] = 0.5326500934649123E-01; - w[57] = 0.4863338516656233E-01; - w[58] = 0.2843474741784810E-01; - w[59] = 0.1719619179720036E-02; - w[60] = -0.6240762604606350E-03; - w[61] = 0.2843227149011163E-02; - w[62] = 0.5250031948172295E-02; - w[63] = 0.5891746241587802E-02; - w[64] = 0.4705736485965663E-02; - w[65] = 0.2135354637703863E-02; - } else { - cerr << "\n"; - cerr << "PADUA_WEIGHTS_SET - Fatal error\n"; - cerr << " Illegal value of L = " << l << "\n"; - cerr << " Legal values are 0 through 10.\n"; - exit(1); - } -// -// Reverse order to match published data. -// - r8vec_reverse(n, w); - - return w; - } -//****************************************************************************80 - - double *padua_weights(int l) - -//****************************************************************************80 -// -// Purpose: -// -// PADUA_WEIGHTS returns quadrature weights do Padua points. -// -// Discussion: -// -// The order of the weights corresponds to the ordering used -// by the companion function padua_points(). -// -// Caliari, de Marchi and Vianello supplied a MATLAB code pdwtsMM -// which carries out this same computation in a way that makes -// more efficient use of MATLAB's vector and matrix capabilities. -// This version of the computation was painfully rewritten to display -// the individual scalar computations, so that it could be translated -// into other languages. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 11 June 2014 -// -// Author: -// -// John Burkardt -// -// Reference: -// -// Marco Caliari, Stefano de Marchi, Marco Vianello, -// Bivariate interpolation on the square at new nodal sets, -// Applied Mathematics and Computation, -// Volume 165, Number 2, 2005, pages 261-274. -// -// Parameters: -// -// Input, int L, the level of the set. -// 0 <= L -// -// Output, double PADUA_WEIGHTS[(L+1)*(L+2)/2], the quadrature weights. -// - { - double angle; - int i; - int i2; - int j; - int j2; - int lp1h; - int lp2h; - int lp3h; - double mi; - double mj; - double *mom; - int n; - const double r8_pi = 3.141592653589793; - double *te1; - double *te2; - double *tmteo; - double *tmtoe; - double *to1; - double *to2; - double *w; - double *w1; - double *w2; - - n = ((l + 1) * (l + 2)) / 2; - w = new double[n]; - - if (l == 0) { - w[0] = 4.0; - return w; - } -// -// Relatives of L/2: -// - lp1h = (l + 1) / 2; - lp2h = (l + 2) / 2; - lp3h = (l + 3) / 2; -// -// TE1, TE2, TO1, TO2: -// Even and odd Chebyshev polynomials on subgrids 1 and 2. -// - te1 = new double[lp2h * lp2h]; - - for (j = 0; j < lp2h; j++) { - for (i = 0; i < lp2h; i++) { - angle = r8_pi * (double) (2 * i * 2 * j) / (double) (l); - te1[i + j * lp2h] = cos(angle); - } - } - - for (j = 0; j < lp2h; j++) { - for (i = 1; i < lp2h; i++) { - te1[i + j * lp2h] = te1[i + j * lp2h] * sqrt(2.0); - } - } - - to1 = new double[lp2h * lp1h]; - - for (j = 0; j < lp1h; j++) { - for (i = 0; i < lp2h; i++) { - angle = r8_pi * (double) (2 * i * (2 * j + 1)) - / (double) (l); - to1[i + j * lp2h] = cos(angle); - } - } - - for (j = 0; j < lp1h; j++) { - for (i = 1; i < lp2h; i++) { - to1[i + j * lp2h] = to1[i + j * lp2h] * sqrt(2.0); - } - } - - te2 = new double[lp2h * lp3h]; - - for (j = 0; j < lp3h; j++) { - for (i = 0; i < lp2h; i++) { - angle = r8_pi * (double) (2 * i * 2 * j) / (double) (l + 1); - te2[i + j * lp2h] = cos(angle); - } - } - - for (j = 0; j < lp3h; j++) { - for (i = 1; i < lp2h; i++) { - te2[i + j * lp2h] = te2[i + j * lp2h] * sqrt(2.0); - } - } - - to2 = new double[lp2h * lp2h]; - - for (j = 0; j < lp2h; j++) { - for (i = 0; i < lp2h; i++) { - angle = r8_pi * (double) (2 * i * (2 * j + 1)) - / (double) (l + 1); - to2[i + j * lp2h] = cos(angle); - } - } - - for (j = 0; j < lp2h; j++) { - for (i = 1; i < lp2h; i++) { - to2[i + j * lp2h] = to2[i + j * lp2h] * sqrt(2.0); - } - } -// -// MOM: Moments matrix do even * even pairs. -// - mom = new double[lp2h * lp2h]; - - for (j = 0; j < lp2h; j++) { - mj = 2.0 * sqrt(2.0) / (double) (1 - pow(2 * j, 2)); - for (i = 0; i < lp2h - j; i++) { - mi = 2.0 * sqrt(2.0) / (double) (1 - pow(2 * i, 2)); - mom[i + j * lp2h] = mi * mj; - } - } - - i = 0; - for (j = 0; j < lp2h; j++) { - mom[i + j * lp2h] = mom[i + j * lp2h] / sqrt(2.0); - } - - j = 0; - for (i = 0; i < lp2h; i++) { - mom[i + j * lp2h] = mom[i + j * lp2h] / sqrt(2.0); - } - if ((l % 2) == 0) { - i = lp2h - 1; - j = 0; - mom[i + j * lp2h] = mom[i + j * lp2h] / 2.0; - } -// -// TMTOE and TMTEO: matrix products. -// - tmtoe = new double[lp2h * lp2h]; - - for (j = 0; j < lp2h; j++) { - for (i = 0; i < lp2h; i++) { - tmtoe[i + j * lp2h] = 0.0; - } - } - - for (j2 = 0; j2 < lp2h; j2++) { - for (i2 = 0; i2 < lp2h - j2; i2++) { - for (j = 0; j < lp2h; j++) { - for (i = 0; i < lp2h; i++) { - tmtoe[i + j * lp2h] = tmtoe[i + j * lp2h] - + to2[i2 + i * lp2h] * mom[j2 + i2 * lp2h] * te1[j2 + j * lp2h]; - } - } - } - } - - tmteo = new double[lp3h * lp1h]; - - for (j = 0; j < lp1h; j++) { - for (i = 0; i < lp3h; i++) { - tmteo[i + j * lp3h] = 0.0; - } - } - - for (j2 = 0; j2 < lp2h; j2++) { - for (i2 = 0; i2 < lp2h - j2; i2++) { - for (j = 0; j < lp1h; j++) { - for (i = 0; i < lp3h; i++) { - tmteo[i + j * lp3h] = tmteo[i + j * lp3h] - + te2[i2 + i * lp2h] * mom[j2 + i2 * lp2h] * to1[j2 + j * lp2h]; - } - } - } - } -// -// W1 and W2: Interpolation weight matrices. -// - w1 = new double[lp2h * lp2h]; - - for (j = 0; j < lp2h; j++) { - for (i = 0; i < lp2h; i++) { - w1[i + j * lp2h] = 2.0 / (double) (l * (l + 1)); - } - } - - j = 0; - for (i = 0; i < lp2h; i++) { - w1[i + j * lp2h] = w1[i + j * lp2h] / 2.0; - } - - if ((l % 2) == 0) { - j = lp2h - 1; - for (i = 0; i < lp2h; i++) { - w1[i + j * lp2h] = w1[i + j * lp2h] / 2.0; - } - - i = lp2h - 1; - for (j = 0; j < lp2h; j++) { - w1[i + j * lp2h] = w1[i + j * lp2h] / 2.0; - } - } - - w2 = new double[lp3h * lp1h]; - - for (j = 0; j < lp1h; j++) { - for (i = 0; i < lp3h; i++) { - w2[i + j * lp3h] = 2.0 / (double) (l * (l + 1)); - } - } - - i = 0; - for (j = 0; j < lp1h; j++) { - w2[i + j * lp3h] = w2[i + j * lp3h] / 2.0; - } - - if ((l % 2) == 1) { - i = lp3h - 1; - for (j = 0; j < lp1h; j++) { - w2[i + j * lp3h] = w2[i + j * lp3h] / 2.0; - } - j = lp1h - 1; - for (i = 0; i < lp3h; i++) { - w2[i + j * lp3h] = w2[i + j * lp3h] / 2.0; - } - } -// -// Cubature weights as matrices on the subgrids. -// - for (j = 0; j < lp2h; j++) { - for (i = 0; i < lp2h; i++) { - w1[i + j * lp2h] = w1[i + j * lp2h] * tmtoe[i + j * lp2h]; - } - } - - for (j = 0; j < lp1h; j++) { - for (i = 0; i < lp3h; i++) { - w2[i + j * lp3h] = w2[i + j * lp3h] * tmteo[i + j * lp3h]; - } - } -// -// Pack weight matrices W1 and W2 into the vector W. -// - if ((l % 2) == 0) { - for (j = 0; j < lp2h; j++) { - for (i = 0; i < lp2h; i++) { - w[i + 2 * j * lp2h] = w1[i + j * lp2h]; - } - } - - for (j = 0; j < lp1h; j++) { - for (i = 0; i < lp3h; i++) { - w[i + (2 * j + 1) * lp2h] = w2[i + j * lp3h]; - } - } - } else { - for (j = 0; j < lp1h; j++) { - for (i = 0; i < lp2h; i++) { - w[i + j * (l + 2)] = w1[i + j * lp2h]; - } - } - - for (j = 0; j < lp1h; j++) { - for (i = 0; i < lp3h; i++) { - w[i + lp2h + j * (l + 2)] = w2[i + j * lp3h]; - } - } - - } -// -// Free memory. -// - delete[] te1; - delete[] te2; - delete[] tmteo; - delete[] tmtoe; - delete[] to1; - delete[] to2; - delete[] w1; - delete[] w2; - - return w; - } -//****************************************************************************80 - - double r8_max(double x, double y) - -//****************************************************************************80 -// -// Purpose: -// -// R8_MAX returns the maximum of two R8's. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 18 August 2004 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input, double X, Y, the quantities to compare. -// -// Output, double R8_MAX, the maximum of X and Y. -// - { - double value; - - if (y < x) { - value = x; - } else { - value = y; - } - return value; - } -//****************************************************************************80 - - void r8mat_transpose_print(int m, int n, double a[], string title) - -//****************************************************************************80 -// -// Purpose: -// -// R8MAT_TRANSPOSE_PRINT prints an R8MAT, transposed. -// -// Discussion: -// -// An R8MAT is a doubly dimensioned array of R8 values, stored as a vector -// in column-major order. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 10 September 2009 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input, int M, N, the number of rows and columns. -// -// Input, double A[M*N], an M by N matrix to be printed. -// -// Input, string TITLE, a title. -// - { - r8mat_transpose_print_some(m, n, a, 1, 1, m, n, title); - - return; - } -//****************************************************************************80 - - void r8mat_transpose_print_some(int m, int n, double a[], int ilo, int jlo, - int ihi, int jhi, string title) - -//****************************************************************************80 -// -// Purpose: -// -// R8MAT_TRANSPOSE_PRINT_SOME prints some of an R8MAT, transposed. -// -// Discussion: -// -// An R8MAT is a doubly dimensioned array of R8 values, stored as a vector -// in column-major order. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 07 April 2014 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input, int M, N, the number of rows and columns. -// -// Input, double A[M*N], an M by N matrix to be printed. -// -// Input, int ILO, JLO, the first row and column to print. -// -// Input, int IHI, JHI, the last row and column to print. -// -// Input, string TITLE, a title. -// - { -# define INCX 5 - - int i; - int i2; - int i2hi; - int i2lo; - int i2lo_hi; - int i2lo_lo; - int inc; - int j; - int j2hi; - int j2lo; - - cout << "\n"; - cout << title << "\n"; - - if (m <= 0 || n <= 0) { - cout << "\n"; - cout << " (None)\n"; - return; - } - - if (ilo < 1) { - i2lo_lo = 1; - } else { - i2lo_lo = ilo; - } - - if (ihi < m) { - i2lo_hi = m; - } else { - i2lo_hi = ihi; - } - - for (i2lo = i2lo_lo; i2lo <= i2lo_hi; i2lo = i2lo + INCX) { - i2hi = i2lo + INCX - 1; - - if (m < i2hi) { - i2hi = m; - } - if (ihi < i2hi) { - i2hi = ihi; - } - - inc = i2hi + 1 - i2lo; - - cout << "\n"; - cout << " Row: "; - for (i = i2lo; i <= i2hi; i++) { - cout << setw(7) << i - 1 << " "; - } - cout << "\n"; - cout << " Col\n"; - cout << "\n"; - - if (jlo < 1) { - j2lo = 1; - } else { - j2lo = jlo; - } - if (n < jhi) { - j2hi = n; - } else { - j2hi = jhi; - } - - for (j = j2lo; j <= j2hi; j++) { - cout << setw(5) << j - 1 << ":"; - for (i2 = 1; i2 <= inc; i2++) { - i = i2lo - 1 + i2; - cout << setw(14) << a[(i - 1) + (j - 1) * m]; - } - cout << "\n"; - } - } - - return; -# undef INCX - } -//****************************************************************************80 - - double *r8vec_copy_new(int n, double a1[]) - -//****************************************************************************80 -// -// Purpose: -// -// R8VEC_COPY_NEW copies an R8VEC to a new R8VEC. -// -// Discussion: -// -// An R8VEC is a vector of R8's. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 03 July 2008 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input, int N, the number of entries in the vectors. -// -// Input, double A1[N], the vector to be copied. -// -// Output, double R8VEC_COPY_NEW[N], the copy of A1. -// - { - double *a2; - int i; - - a2 = new double[n]; - - for (i = 0; i < n; i++) { - a2[i] = a1[i]; - } - return a2; - } -//****************************************************************************80 - - void r8vec_print(int n, double a[], string title) - -//****************************************************************************80 -// -// Purpose: -// -// R8VEC_PRINT prints an R8VEC. -// -// Discussion: -// -// An R8VEC is a vector of R8's. -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 16 August 2004 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input, int N, the number of components of the vector. -// -// Input, double A[N], the vector to be printed. -// -// Input, string TITLE, a title. -// - { - int i; - - cout << "\n"; - cout << title << "\n"; - cout << "\n"; - for (i = 0; i < n; i++) { - cout << " " << setw(8) << i - << ": " << setw(14) << a[i] << "\n"; - } - - return; - } -//****************************************************************************80 - - void r8vec_reverse(int n, double a[]) - -//****************************************************************************80 -// -// Purpose: -// -// R8VEC_REVERSE reverses the elements of an R8VEC. -// -// Discussion: -// -// An R8VEC is a vector of R8's. -// -// Example: -// -// Input: -// -// N = 5, A = ( 11.0, 12.0, 13.0, 14.0, 15.0 ). -// -// Output: -// -// A = ( 15.0, 14.0, 13.0, 12.0, 11.0 ). -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 18 September 2005 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// Input, int N, the number of entries in the array. -// -// Input/output, double A[N], the array to be reversed. -// - { - int i; - int i_hi; - double temp; - - i_hi = n / 2; - - for (i = 1; i <= i_hi; i++) { - temp = a[i - 1]; - a[i - 1] = a[n - i]; - a[n - i] = temp; - } - - return; - } -//****************************************************************************80 - - void timestamp() - -//****************************************************************************80 -// -// Purpose: -// -// TIMESTAMP prints the current YMDHMS date as a time stamp. -// -// Example: -// -// 31 May 2001 09:45:54 AM -// -// Licensing: -// -// This code is distributed under the GNU LGPL license. -// -// Modified: -// -// 08 July 2009 -// -// Author: -// -// John Burkardt -// -// Parameters: -// -// None -// - { -# define TIME_SIZE 40 - - static char time_buffer[TIME_SIZE]; - const struct std::tm *tm_ptr; - std::time_t now; - - now = std::time(NULL); - tm_ptr = std::localtime(&now); - - std::strftime(time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr); - - std::cout << time_buffer << "\n"; - - return; -# undef TIME_SIZE - } -} \ No newline at end of file diff --git a/src/external/Padua/padua.h b/src/external/Padua/padua.h deleted file mode 100644 index 46374e7b..00000000 --- a/src/external/Padua/padua.h +++ /dev/null @@ -1,36 +0,0 @@ -#include <string> - -using std::string; - -namespace padua { - void filename_inc(string *filename); - - string i4_to_string(int i4); - - int padua_order(int l); - - void padua_plot(int l, string filename); - - double *padua_points(int l); - - double *padua_points_set(int l); - - double *padua_weights(int l); - - double *padua_weights_set(int l); - - double r8_max(double x, double y); - - void r8mat_transpose_print(int m, int n, double a[], string title); - - void r8mat_transpose_print_some(int m, int n, double a[], int ilo, int jlo, - int ihi, int jhi, string title); - - double *r8vec_copy_new(int n, double a1[]); - - void r8vec_print(int n, double a[], string title); - - void r8vec_reverse(int n, double a[]); - - void timestamp(); -} \ No newline at end of file diff --git a/src/external/Spectra/include/Spectra/GenEigsBase.h b/src/external/Spectra/include/Spectra/GenEigsBase.h deleted file mode 100644 index 19b12c15..00000000 --- a/src/external/Spectra/include/Spectra/GenEigsBase.h +++ /dev/null @@ -1,479 +0,0 @@ -// Copyright (C) 2018-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef GEN_EIGS_BASE_H -#define GEN_EIGS_BASE_H - -#include <Eigen/Core> -#include <vector> // std::vector -#include <cmath> // std::abs, std::pow, std::sqrt -#include <algorithm> // std::min, std::copy -#include <complex> // std::complex, std::conj, std::norm, std::abs -#include <stdexcept> // std::invalid_argument - -#include "Util/TypeTraits.h" -#include "Util/SelectionRule.h" -#include "Util/CompInfo.h" -#include "Util/SimpleRandom.h" -#include "MatOp/internal/ArnoldiOp.h" -#include "LinAlg/UpperHessenbergQR.h" -#include "LinAlg/DoubleShiftQR.h" -#include "LinAlg/UpperHessenbergEigen.h" -#include "LinAlg/Arnoldi.h" - -namespace Spectra { - - -/// -/// \ingroup EigenSolver -/// -/// This is the base class for general eigen solvers, mainly for internal use. -/// It is kept here to provide the documentation for member functions of concrete eigen solvers -/// such as GenEigsSolver and GenEigsRealShiftSolver. -/// -template < typename Scalar, - int SelectionRule, - typename OpType, - typename BOpType > -class GenEigsBase -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Array<Scalar, Eigen::Dynamic, 1> Array; - typedef Eigen::Array<bool, Eigen::Dynamic, 1> BoolArray; - typedef Eigen::Map<Matrix> MapMat; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::Map<const Vector> MapConstVec; - - typedef std::complex<Scalar> Complex; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic> ComplexMatrix; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> ComplexVector; - - typedef ArnoldiOp<Scalar, OpType, BOpType> ArnoldiOpType; - typedef Arnoldi<Scalar, ArnoldiOpType> ArnoldiFac; - -protected: - OpType* m_op; // object to conduct matrix operation, - // e.g. matrix-vector product - const Index m_n; // dimension of matrix A - const Index m_nev; // number of eigenvalues requested - const Index m_ncv; // dimension of Krylov subspace in the Arnoldi method - Index m_nmatop; // number of matrix operations called - Index m_niter; // number of restarting iterations - - ArnoldiFac m_fac; // Arnoldi factorization - - ComplexVector m_ritz_val; // Ritz values - ComplexMatrix m_ritz_vec; // Ritz vectors - ComplexVector m_ritz_est; // last row of m_ritz_vec - -private: - BoolArray m_ritz_conv; // indicator of the convergence of Ritz values - int m_info; // status of the computation - - const Scalar m_near_0; // a very small value, but 1.0 / m_near_0 does not overflow - // ~= 1e-307 for the "double" type - const Scalar m_eps; // the machine precision, ~= 1e-16 for the "double" type - const Scalar m_eps23; // m_eps^(2/3), used to test the convergence - - // Real Ritz values calculated from UpperHessenbergEigen have exact zero imaginary part - // Complex Ritz values have exact conjugate pairs - // So we use exact tests here - static bool is_complex(const Complex& v) { return v.imag() != Scalar(0); } - static bool is_conj(const Complex& v1, const Complex& v2) { return v1 == Eigen::numext::conj(v2); } - - // Implicitly restarted Arnoldi factorization - void restart(Index k) - { - using std::norm; - - if(k >= m_ncv) - return; - - DoubleShiftQR<Scalar> decomp_ds(m_ncv); - UpperHessenbergQR<Scalar> decomp_hb(m_ncv); - Matrix Q = Matrix::Identity(m_ncv, m_ncv); - - for(Index i = k; i < m_ncv; i++) - { - if(is_complex(m_ritz_val[i]) && is_conj(m_ritz_val[i], m_ritz_val[i + 1])) - { - // H - mu * I = Q1 * R1 - // H <- R1 * Q1 + mu * I = Q1' * H * Q1 - // H - conj(mu) * I = Q2 * R2 - // H <- R2 * Q2 + conj(mu) * I = Q2' * H * Q2 - // - // (H - mu * I) * (H - conj(mu) * I) = Q1 * Q2 * R2 * R1 = Q * R - const Scalar s = Scalar(2) * m_ritz_val[i].real(); - const Scalar t = norm(m_ritz_val[i]); - - decomp_ds.compute(m_fac.matrix_H(), s, t); - - // Q -> Q * Qi - decomp_ds.apply_YQ(Q); - // H -> Q'HQ - // Matrix Q = Matrix::Identity(m_ncv, m_ncv); - // decomp_ds.apply_YQ(Q); - // m_fac_H = Q.transpose() * m_fac_H * Q; - m_fac.compress_H(decomp_ds); - - i++; - } else { - // QR decomposition of H - mu * I, mu is real - decomp_hb.compute(m_fac.matrix_H(), m_ritz_val[i].real()); - - // Q -> Q * Qi - decomp_hb.apply_YQ(Q); - // H -> Q'HQ = RQ + mu * I - m_fac.compress_H(decomp_hb); - } - } - - m_fac.compress_V(Q); - m_fac.factorize_from(k, m_ncv, m_nmatop); - - retrieve_ritzpair(); - } - - // Calculates the number of converged Ritz values - Index num_converged(Scalar tol) - { - // thresh = tol * max(m_eps23, abs(theta)), theta for Ritz value - Array thresh = tol * m_ritz_val.head(m_nev).array().abs().max(m_eps23); - Array resid = m_ritz_est.head(m_nev).array().abs() * m_fac.f_norm(); - // Converged "wanted" Ritz values - m_ritz_conv = (resid < thresh); - - return m_ritz_conv.cast<Index>().sum(); - } - - // Returns the adjusted nev for restarting - Index nev_adjusted(Index nconv) - { - using std::abs; - - Index nev_new = m_nev; - for(Index i = m_nev; i < m_ncv; i++) - if(abs(m_ritz_est[i]) < m_near_0) nev_new++; - - // Adjust nev_new, according to dnaup2.f line 660~674 in ARPACK - nev_new += std::min(nconv, (m_ncv - nev_new) / 2); - if(nev_new == 1 && m_ncv >= 6) - nev_new = m_ncv / 2; - else if(nev_new == 1 && m_ncv > 3) - nev_new = 2; - - if(nev_new > m_ncv - 2) - nev_new = m_ncv - 2; - - // Increase nev by one if ritz_val[nev - 1] and - // ritz_val[nev] are conjugate pairs - if(is_complex(m_ritz_val[nev_new - 1]) && - is_conj(m_ritz_val[nev_new - 1], m_ritz_val[nev_new])) - { - nev_new++; - } - - return nev_new; - } - - // Retrieves and sorts Ritz values and Ritz vectors - void retrieve_ritzpair() - { - UpperHessenbergEigen<Scalar> decomp(m_fac.matrix_H()); - const ComplexVector& evals = decomp.eigenvalues(); - ComplexMatrix evecs = decomp.eigenvectors(); - - SortEigenvalue<Complex, SelectionRule> sorting(evals.data(), evals.size()); - std::vector<int> ind = sorting.index(); - - // Copy the Ritz values and vectors to m_ritz_val and m_ritz_vec, respectively - for(Index i = 0; i < m_ncv; i++) - { - m_ritz_val[i] = evals[ind[i]]; - m_ritz_est[i] = evecs(m_ncv - 1, ind[i]); - } - for(Index i = 0; i < m_nev; i++) - { - m_ritz_vec.col(i).noalias() = evecs.col(ind[i]); - } - } - -protected: - // Sorts the first nev Ritz pairs in the specified order - // This is used to return the final results - virtual void sort_ritzpair(int sort_rule) - { - // First make sure that we have a valid index vector - SortEigenvalue<Complex, LARGEST_MAGN> sorting(m_ritz_val.data(), m_nev); - std::vector<int> ind = sorting.index(); - - switch(sort_rule) - { - case LARGEST_MAGN: - break; - case LARGEST_REAL: - { - SortEigenvalue<Complex, LARGEST_REAL> sorting(m_ritz_val.data(), m_nev); - ind = sorting.index(); - } - break; - case LARGEST_IMAG: - { - SortEigenvalue<Complex, LARGEST_IMAG> sorting(m_ritz_val.data(), m_nev); - ind = sorting.index(); - } - break; - case SMALLEST_MAGN: - { - SortEigenvalue<Complex, SMALLEST_MAGN> sorting(m_ritz_val.data(), m_nev); - ind = sorting.index(); - } - break; - case SMALLEST_REAL: - { - SortEigenvalue<Complex, SMALLEST_REAL> sorting(m_ritz_val.data(), m_nev); - ind = sorting.index(); - } - break; - case SMALLEST_IMAG: - { - SortEigenvalue<Complex, SMALLEST_IMAG> sorting(m_ritz_val.data(), m_nev); - ind = sorting.index(); - } - break; - default: - throw std::invalid_argument("unsupported sorting rule"); - } - - ComplexVector new_ritz_val(m_ncv); - ComplexMatrix new_ritz_vec(m_ncv, m_nev); - BoolArray new_ritz_conv(m_nev); - - for(Index i = 0; i < m_nev; i++) - { - new_ritz_val[i] = m_ritz_val[ind[i]]; - new_ritz_vec.col(i).noalias() = m_ritz_vec.col(ind[i]); - new_ritz_conv[i] = m_ritz_conv[ind[i]]; - } - - m_ritz_val.swap(new_ritz_val); - m_ritz_vec.swap(new_ritz_vec); - m_ritz_conv.swap(new_ritz_conv); - } - -public: - /// \cond - - GenEigsBase(OpType* op, BOpType* Bop, Index nev, Index ncv) : - m_op(op), - m_n(m_op->rows()), - m_nev(nev), - m_ncv(ncv > m_n ? m_n : ncv), - m_nmatop(0), - m_niter(0), - m_fac(ArnoldiOpType(op, Bop), m_ncv), - m_info(NOT_COMPUTED), - m_near_0(TypeTraits<Scalar>::min() * Scalar(10)), - m_eps(Eigen::NumTraits<Scalar>::epsilon()), - m_eps23(Eigen::numext::pow(m_eps, Scalar(2.0) / 3)) - { - if(nev < 1 || nev > m_n - 2) - throw std::invalid_argument("nev must satisfy 1 <= nev <= n - 2, n is the size of matrix"); - - if(ncv < nev + 2 || ncv > m_n) - throw std::invalid_argument("ncv must satisfy nev + 2 <= ncv <= n, n is the size of matrix"); - } - - /// - /// Virtual destructor - /// - virtual ~GenEigsBase() {} - - /// \endcond - - /// - /// Initializes the solver by providing an initial residual vector. - /// - /// \param init_resid Pointer to the initial residual vector. - /// - /// **Spectra** (and also **ARPACK**) uses an iterative algorithm - /// to find eigenvalues. This function allows the user to provide the initial - /// residual vector. - /// - void init(const Scalar* init_resid) - { - // Reset all matrices/vectors to zero - m_ritz_val.resize(m_ncv); - m_ritz_vec.resize(m_ncv, m_nev); - m_ritz_est.resize(m_ncv); - m_ritz_conv.resize(m_nev); - - m_ritz_val.setZero(); - m_ritz_vec.setZero(); - m_ritz_est.setZero(); - m_ritz_conv.setZero(); - - m_nmatop = 0; - m_niter = 0; - - // Initialize the Arnoldi factorization - MapConstVec v0(init_resid, m_n); - m_fac.init(v0, m_nmatop); - } - - /// - /// Initializes the solver by providing a random initial residual vector. - /// - /// This overloaded function generates a random initial residual vector - /// (with a fixed random seed) for the algorithm. Elements in the vector - /// follow independent Uniform(-0.5, 0.5) distribution. - /// - void init() - { - SimpleRandom<Scalar> rng(0); - Vector init_resid = rng.random_vec(m_n); - init(init_resid.data()); - } - - /// - /// Conducts the major computation procedure. - /// - /// \param maxit Maximum number of iterations allowed in the algorithm. - /// \param tol Precision parameter for the calculated eigenvalues. - /// \param sort_rule Rule to sort the eigenvalues and eigenvectors. - /// Supported values are - /// `Spectra::LARGEST_MAGN`, `Spectra::LARGEST_REAL`, - /// `Spectra::LARGEST_IMAG`, `Spectra::SMALLEST_MAGN`, - /// `Spectra::SMALLEST_REAL` and `Spectra::SMALLEST_IMAG`, - /// for example `LARGEST_MAGN` indicates that eigenvalues - /// with largest magnitude come first. - /// Note that this argument is only used to - /// **sort** the final result, and the **selection** rule - /// (e.g. selecting the largest or smallest eigenvalues in the - /// full spectrum) is specified by the template parameter - /// `SelectionRule` of GenEigsSolver. - /// - /// \return Number of converged eigenvalues. - /// - Index compute(Index maxit = 1000, Scalar tol = 1e-10, int sort_rule = LARGEST_MAGN) - { - // The m-step Arnoldi factorization - m_fac.factorize_from(1, m_ncv, m_nmatop); - retrieve_ritzpair(); - // Restarting - Index i, nconv = 0, nev_adj; - for(i = 0; i < maxit; i++) - { - nconv = num_converged(tol); - if(nconv >= m_nev) - break; - - nev_adj = nev_adjusted(nconv); - restart(nev_adj); - } - // Sorting results - sort_ritzpair(sort_rule); - - m_niter += i + 1; - m_info = (nconv >= m_nev) ? SUCCESSFUL : NOT_CONVERGING; - - return std::min(m_nev, nconv); - } - - /// - /// Returns the status of the computation. - /// The full list of enumeration values can be found in \ref Enumerations. - /// - int info() const { return m_info; } - - /// - /// Returns the number of iterations used in the computation. - /// - Index num_iterations() const { return m_niter; } - - /// - /// Returns the number of matrix operations used in the computation. - /// - Index num_operations() const { return m_nmatop; } - - /// - /// Returns the converged eigenvalues. - /// - /// \return A complex-valued vector containing the eigenvalues. - /// Returned vector type will be `Eigen::Vector<std::complex<Scalar>, ...>`, depending on - /// the template parameter `Scalar` defined. - /// - ComplexVector eigenvalues() const - { - const Index nconv = m_ritz_conv.cast<Index>().sum(); - ComplexVector res(nconv); - - if(!nconv) - return res; - - Index j = 0; - for(Index i = 0; i < m_nev; i++) - { - if(m_ritz_conv[i]) - { - res[j] = m_ritz_val[i]; - j++; - } - } - - return res; - } - - /// - /// Returns the eigenvectors associated with the converged eigenvalues. - /// - /// \param nvec The number of eigenvectors to return. - /// - /// \return A complex-valued matrix containing the eigenvectors. - /// Returned matrix type will be `Eigen::Matrix<std::complex<Scalar>, ...>`, - /// depending on the template parameter `Scalar` defined. - /// - ComplexMatrix eigenvectors(Index nvec) const - { - const Index nconv = m_ritz_conv.cast<Index>().sum(); - nvec = std::min(nvec, nconv); - ComplexMatrix res(m_n, nvec); - - if(!nvec) - return res; - - ComplexMatrix ritz_vec_conv(m_ncv, nvec); - Index j = 0; - for(Index i = 0; i < m_nev && j < nvec; i++) - { - if(m_ritz_conv[i]) - { - ritz_vec_conv.col(j).noalias() = m_ritz_vec.col(i); - j++; - } - } - - res.noalias() = m_fac.matrix_V() * ritz_vec_conv; - - return res; - } - - /// - /// Returns all converged eigenvectors. - /// - ComplexMatrix eigenvectors() const - { - return eigenvectors(m_nev); - } -}; - - -} // namespace Spectra - -#endif // GEN_EIGS_BASE_H diff --git a/src/external/Spectra/include/Spectra/GenEigsComplexShiftSolver.h b/src/external/Spectra/include/Spectra/GenEigsComplexShiftSolver.h deleted file mode 100644 index 2c1aee7f..00000000 --- a/src/external/Spectra/include/Spectra/GenEigsComplexShiftSolver.h +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef GEN_EIGS_COMPLEX_SHIFT_SOLVER_H -#define GEN_EIGS_COMPLEX_SHIFT_SOLVER_H - -#include <Eigen/Core> - -#include "GenEigsBase.h" -#include "Util/SelectionRule.h" -#include "MatOp/DenseGenComplexShiftSolve.h" - -namespace Spectra { - - -/// -/// \ingroup EigenSolver -/// -/// This class implements the eigen solver for general real matrices with -/// a complex shift value in the **shift-and-invert mode**. The background -/// knowledge of the shift-and-invert mode can be found in the documentation -/// of the SymEigsShiftSolver class. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// \tparam SelectionRule An enumeration value indicating the selection rule of -/// the shifted-and-inverted eigenvalues. -/// The full list of enumeration values can be found in -/// \ref Enumerations. -/// \tparam OpType The name of the matrix operation class. Users could either -/// use the DenseGenComplexShiftSolve wrapper class, or define their -/// own that implements all the public member functions as in -/// DenseGenComplexShiftSolve. -/// -template <typename Scalar = double, - int SelectionRule = LARGEST_MAGN, - typename OpType = DenseGenComplexShiftSolve<double> > -class GenEigsComplexShiftSolver: public GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp> -{ -private: - typedef Eigen::Index Index; - typedef std::complex<Scalar> Complex; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> ComplexVector; - - const Scalar m_sigmar; - const Scalar m_sigmai; - - // First transform back the Ritz values, and then sort - void sort_ritzpair(int sort_rule) - { - using std::abs; - using std::sqrt; - using std::norm; - - // The eigenvalues we get from the iteration is - // nu = 0.5 * (1 / (lambda - sigma) + 1 / (lambda - conj(sigma))) - // So the eigenvalues of the original problem is - // 1 \pm sqrt(1 - 4 * nu^2 * sigmai^2) - // lambda = sigmar + ----------------------------------- - // 2 * nu - // We need to pick the correct root - // Let (lambdaj, vj) be the j-th eigen pair, then A * vj = lambdaj * vj - // and inv(A - r * I) * vj = 1 / (lambdaj - r) * vj - // where r is any shift value. - // We can use this identity to determine lambdaj - // - // op(v) computes Re(inv(A - r * I) * v) for any real v - // If r is real, then op(v) is also real. Let a = Re(vj), b = Im(vj), - // then op(vj) = op(a) + op(b) * i - // By comparing op(vj) and [1 / (lambdaj - r) * vj], we can determine - // which one is the correct root - - // Select a random shift value - SimpleRandom<Scalar> rng(0); - const Scalar shiftr = rng.random() * m_sigmar + rng.random(); - const Complex shift = Complex(shiftr, Scalar(0)); - this->m_op->set_shift(shiftr, Scalar(0)); - - // Calculate inv(A - r * I) * vj - Vector v_real(this->m_n), v_imag(this->m_n), OPv_real(this->m_n), OPv_imag(this->m_n); - const Scalar eps = Eigen::NumTraits<Scalar>::epsilon(); - for(Index i = 0; i < this->m_nev; i++) - { - v_real.noalias() = this->m_fac.matrix_V() * this->m_ritz_vec.col(i).real(); - v_imag.noalias() = this->m_fac.matrix_V() * this->m_ritz_vec.col(i).imag(); - this->m_op->perform_op(v_real.data(), OPv_real.data()); - this->m_op->perform_op(v_imag.data(), OPv_imag.data()); - - // Two roots computed from the quadratic equation - const Complex nu = this->m_ritz_val[i]; - const Complex root_part1 = m_sigmar + Scalar(0.5) / nu; - const Complex root_part2 = Scalar(0.5) * sqrt(Scalar(1) - Scalar(4) * m_sigmai * m_sigmai * (nu * nu)) / nu; - const Complex root1 = root_part1 + root_part2; - const Complex root2 = root_part1 - root_part2; - - // Test roots - Scalar err1 = Scalar(0), err2 = Scalar(0); - for(int k = 0; k < this->m_n; k++) - { - const Complex rhs1 = Complex(v_real[k], v_imag[k]) / (root1 - shift); - const Complex rhs2 = Complex(v_real[k], v_imag[k]) / (root2 - shift); - const Complex OPv = Complex(OPv_real[k], OPv_imag[k]); - err1 += norm(OPv - rhs1); - err2 += norm(OPv - rhs2); - } - - const Complex lambdaj = (err1 < err2) ? root1 : root2; - this->m_ritz_val[i] = lambdaj; - - if(abs(Eigen::numext::imag(lambdaj)) > eps) - { - this->m_ritz_val[i + 1] = Eigen::numext::conj(lambdaj); - i++; - } else { - this->m_ritz_val[i] = Complex(Eigen::numext::real(lambdaj), Scalar(0)); - } - } - - GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>::sort_ritzpair(sort_rule); - } -public: - /// - /// Constructor to create a eigen solver object using the shift-and-invert mode. - /// - /// \param op Pointer to the matrix operation object. This class should implement - /// the complex shift-solve operation of \f$A\f$: calculating - /// \f$\mathrm{Re}\{(A-\sigma I)^{-1}v\}\f$ for any vector \f$v\f$. Users could either - /// create the object from the DenseGenComplexShiftSolve wrapper class, or - /// define their own that implements all the public member functions - /// as in DenseGenComplexShiftSolve. - /// \param nev Number of eigenvalues requested. This should satisfy \f$1\le nev \le n-2\f$, - /// where \f$n\f$ is the size of matrix. - /// \param ncv Parameter that controls the convergence speed of the algorithm. - /// Typically a larger `ncv` means faster convergence, but it may - /// also result in greater memory use and more matrix operations - /// in each iteration. This parameter must satisfy \f$nev+2 \le ncv \le n\f$, - /// and is advised to take \f$ncv \ge 2\cdot nev + 1\f$. - /// \param sigmar The real part of the shift. - /// \param sigmai The imaginary part of the shift. - /// - GenEigsComplexShiftSolver(OpType* op, Index nev, Index ncv, const Scalar& sigmar, const Scalar& sigmai) : - GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>(op, NULL, nev, ncv), - m_sigmar(sigmar), m_sigmai(sigmai) - { - this->m_op->set_shift(m_sigmar, m_sigmai); - } -}; - - -} // namespace Spectra - -#endif // GEN_EIGS_COMPLEX_SHIFT_SOLVER_H diff --git a/src/external/Spectra/include/Spectra/GenEigsRealShiftSolver.h b/src/external/Spectra/include/Spectra/GenEigsRealShiftSolver.h deleted file mode 100644 index a7e3da8e..00000000 --- a/src/external/Spectra/include/Spectra/GenEigsRealShiftSolver.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef GEN_EIGS_REAL_SHIFT_SOLVER_H -#define GEN_EIGS_REAL_SHIFT_SOLVER_H - -#include <Eigen/Core> - -#include "GenEigsBase.h" -#include "Util/SelectionRule.h" -#include "MatOp/DenseGenRealShiftSolve.h" - -namespace Spectra { - - -/// -/// \ingroup EigenSolver -/// -/// This class implements the eigen solver for general real matrices with -/// a real shift value in the **shift-and-invert mode**. The background -/// knowledge of the shift-and-invert mode can be found in the documentation -/// of the SymEigsShiftSolver class. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// \tparam SelectionRule An enumeration value indicating the selection rule of -/// the shifted-and-inverted eigenvalues. -/// The full list of enumeration values can be found in -/// \ref Enumerations. -/// \tparam OpType The name of the matrix operation class. Users could either -/// use the wrapper classes such as DenseGenRealShiftSolve and -/// SparseGenRealShiftSolve, or define their -/// own that implements all the public member functions as in -/// DenseGenRealShiftSolve. -/// -template <typename Scalar = double, - int SelectionRule = LARGEST_MAGN, - typename OpType = DenseGenRealShiftSolve<double> > -class GenEigsRealShiftSolver: public GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp> -{ -private: - typedef Eigen::Index Index; - typedef std::complex<Scalar> Complex; - typedef Eigen::Array<Complex, Eigen::Dynamic, 1> ComplexArray; - - const Scalar m_sigma; - - // First transform back the Ritz values, and then sort - void sort_ritzpair(int sort_rule) - { - // The eigenvalues we get from the iteration is nu = 1 / (lambda - sigma) - // So the eigenvalues of the original problem is lambda = 1 / nu + sigma - ComplexArray ritz_val_org = Scalar(1.0) / this->m_ritz_val.head(this->m_nev).array() + m_sigma; - this->m_ritz_val.head(this->m_nev) = ritz_val_org; - GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>::sort_ritzpair(sort_rule); - } -public: - /// - /// Constructor to create a eigen solver object using the shift-and-invert mode. - /// - /// \param op Pointer to the matrix operation object. This class should implement - /// the shift-solve operation of \f$A\f$: calculating - /// \f$(A-\sigma I)^{-1}v\f$ for any vector \f$v\f$. Users could either - /// create the object from the wrapper class such as DenseGenRealShiftSolve, or - /// define their own that implements all the public member functions - /// as in DenseGenRealShiftSolve. - /// \param nev Number of eigenvalues requested. This should satisfy \f$1\le nev \le n-2\f$, - /// where \f$n\f$ is the size of matrix. - /// \param ncv Parameter that controls the convergence speed of the algorithm. - /// Typically a larger `ncv` means faster convergence, but it may - /// also result in greater memory use and more matrix operations - /// in each iteration. This parameter must satisfy \f$nev+2 \le ncv \le n\f$, - /// and is advised to take \f$ncv \ge 2\cdot nev + 1\f$. - /// \param sigma The real-valued shift. - /// - GenEigsRealShiftSolver(OpType* op, Index nev, Index ncv, Scalar sigma) : - GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>(op, NULL, nev, ncv), - m_sigma(sigma) - { - this->m_op->set_shift(m_sigma); - } -}; - - -} // namespace Spectra - -#endif // GEN_EIGS_REAL_SHIFT_SOLVER_H diff --git a/src/external/Spectra/include/Spectra/GenEigsSolver.h b/src/external/Spectra/include/Spectra/GenEigsSolver.h deleted file mode 100644 index a6960acf..00000000 --- a/src/external/Spectra/include/Spectra/GenEigsSolver.h +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef GEN_EIGS_SOLVER_H -#define GEN_EIGS_SOLVER_H - -#include <Eigen/Core> - -#include "GenEigsBase.h" -#include "Util/SelectionRule.h" -#include "MatOp/DenseGenMatProd.h" - -namespace Spectra { - - -/// -/// \ingroup EigenSolver -/// -/// This class implements the eigen solver for general real matrices, i.e., -/// to solve \f$Ax=\lambda x\f$ for a possibly non-symmetric \f$A\f$ matrix. -/// -/// Most of the background information documented in the SymEigsSolver class -/// also applies to the GenEigsSolver class here, except that the eigenvalues -/// and eigenvectors of a general matrix can now be complex-valued. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// \tparam SelectionRule An enumeration value indicating the selection rule of -/// the requested eigenvalues, for example `LARGEST_MAGN` -/// to retrieve eigenvalues with the largest magnitude. -/// The full list of enumeration values can be found in -/// \ref Enumerations. -/// \tparam OpType The name of the matrix operation class. Users could either -/// use the wrapper classes such as DenseGenMatProd and -/// SparseGenMatProd, or define their -/// own that implements all the public member functions as in -/// DenseGenMatProd. -/// -/// An example that illustrates the usage of GenEigsSolver is give below: -/// -/// \code{.cpp} -/// #include <Eigen/Core> -/// #include <Spectra/GenEigsSolver.h> -/// // <Spectra/MatOp/DenseGenMatProd.h> is implicitly included -/// #include <iostream> -/// -/// using namespace Spectra; -/// -/// int main() -/// { -/// // We are going to calculate the eigenvalues of M -/// Eigen::MatrixXd M = Eigen::MatrixXd::Random(10, 10); -/// -/// // Construct matrix operation object using the wrapper class -/// DenseGenMatProd<double> op(M); -/// -/// // Construct eigen solver object, requesting the largest -/// // (in magnitude, or norm) three eigenvalues -/// GenEigsSolver< double, LARGEST_MAGN, DenseGenMatProd<double> > eigs(&op, 3, 6); -/// -/// // Initialize and compute -/// eigs.init(); -/// int nconv = eigs.compute(); -/// -/// // Retrieve results -/// Eigen::VectorXcd evalues; -/// if(eigs.info() == SUCCESSFUL) -/// evalues = eigs.eigenvalues(); -/// -/// std::cout << "Eigenvalues found:\n" << evalues << std::endl; -/// -/// return 0; -/// } -/// \endcode -/// -/// And also an example for sparse matrices: -/// -/// \code{.cpp} -/// #include <Eigen/Core> -/// #include <Eigen/SparseCore> -/// #include <Spectra/GenEigsSolver.h> -/// #include <Spectra/MatOp/SparseGenMatProd.h> -/// #include <iostream> -/// -/// using namespace Spectra; -/// -/// int main() -/// { -/// // A band matrix with 1 on the main diagonal, 2 on the below-main subdiagonal, -/// // and 3 on the above-main subdiagonal -/// const int n = 10; -/// Eigen::SparseMatrix<double> M(n, n); -/// M.reserve(Eigen::VectorXi::Constant(n, 3)); -/// for(int i = 0; i < n; i++) -/// { -/// M.insert(i, i) = 1.0; -/// if(i > 0) -/// M.insert(i - 1, i) = 3.0; -/// if(i < n - 1) -/// M.insert(i + 1, i) = 2.0; -/// } -/// -/// // Construct matrix operation object using the wrapper class SparseGenMatProd -/// SparseGenMatProd<double> op(M); -/// -/// // Construct eigen solver object, requesting the largest three eigenvalues -/// GenEigsSolver< double, LARGEST_MAGN, SparseGenMatProd<double> > eigs(&op, 3, 6); -/// -/// // Initialize and compute -/// eigs.init(); -/// int nconv = eigs.compute(); -/// -/// // Retrieve results -/// Eigen::VectorXcd evalues; -/// if(eigs.info() == SUCCESSFUL) -/// evalues = eigs.eigenvalues(); -/// -/// std::cout << "Eigenvalues found:\n" << evalues << std::endl; -/// -/// return 0; -/// } -/// \endcode -template < typename Scalar = double, - int SelectionRule = LARGEST_MAGN, - typename OpType = DenseGenMatProd<double> > -class GenEigsSolver: public GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp> -{ -private: - typedef Eigen::Index Index; - -public: - /// - /// Constructor to create a solver object. - /// - /// \param op Pointer to the matrix operation object, which should implement - /// the matrix-vector multiplication operation of \f$A\f$: - /// calculating \f$Av\f$ for any vector \f$v\f$. Users could either - /// create the object from the wrapper class such as DenseGenMatProd, or - /// define their own that implements all the public member functions - /// as in DenseGenMatProd. - /// \param nev Number of eigenvalues requested. This should satisfy \f$1\le nev \le n-2\f$, - /// where \f$n\f$ is the size of matrix. - /// \param ncv Parameter that controls the convergence speed of the algorithm. - /// Typically a larger `ncv` means faster convergence, but it may - /// also result in greater memory use and more matrix operations - /// in each iteration. This parameter must satisfy \f$nev+2 \le ncv \le n\f$, - /// and is advised to take \f$ncv \ge 2\cdot nev + 1\f$. - /// - GenEigsSolver(OpType* op, Index nev, Index ncv) : - GenEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>(op, NULL, nev, ncv) - {} -}; - - -} // namespace Spectra - -#endif // GEN_EIGS_SOLVER_H diff --git a/src/external/Spectra/include/Spectra/LinAlg/Arnoldi.h b/src/external/Spectra/include/Spectra/LinAlg/Arnoldi.h deleted file mode 100644 index b9fa75b5..00000000 --- a/src/external/Spectra/include/Spectra/LinAlg/Arnoldi.h +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright (C) 2018-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef ARNOLDI_H -#define ARNOLDI_H - -#include <Eigen/Core> -#include <cmath> // std::sqrt -#include <stdexcept> // std::invalid_argument -#include <sstream> // std::stringstream - -#include "../MatOp/internal/ArnoldiOp.h" -#include "../Util/TypeTraits.h" -#include "../Util/SimpleRandom.h" -#include "UpperHessenbergQR.h" -#include "DoubleShiftQR.h" - -namespace Spectra { - - -// Arnoldi factorization A * V = V * H + f * e' -// A: n x n -// V: n x k -// H: k x k -// f: n x 1 -// e: [0, ..., 0, 1] -// V and H are allocated of dimension m, so the maximum value of k is m -template <typename Scalar, typename ArnoldiOpType> -class Arnoldi -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<Matrix> MapMat; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::Map<const Matrix> MapConstMat; - typedef Eigen::Map<const Vector> MapConstVec; - -protected: - ArnoldiOpType m_op; // Operators for the Arnoldi factorization - - const Index m_n; // dimension of A - const Index m_m; // maximum dimension of subspace V - Index m_k; // current dimension of subspace V - - Matrix m_fac_V; // V matrix in the Arnoldi factorization - Matrix m_fac_H; // H matrix in the Arnoldi factorization - Vector m_fac_f; // residual in the Arnoldi factorization - Scalar m_beta; // ||f||, B-norm of f - - const Scalar m_near_0; // a very small value, but 1.0 / m_near_0 does not overflow - // ~= 1e-307 for the "double" type - const Scalar m_eps; // the machine precision, ~= 1e-16 for the "double" type - - // Given orthonormal basis functions V, find a nonzero vector f such that V'Bf = 0 - // Assume that f has been properly allocated - void expand_basis(MapConstMat& V, const Index seed, Vector& f, Scalar& fnorm) - { - using std::sqrt; - - const Scalar thresh = m_eps * sqrt(Scalar(m_n)); - Vector Vf(V.cols()); - for(Index iter = 0; iter < 5; iter++) - { - // Randomly generate a new vector and orthogonalize it against V - SimpleRandom<Scalar> rng(seed + 123 * iter); - f.noalias() = rng.random_vec(m_n); - // f <- f - V * V'Bf, so that f is orthogonal to V in B-norm - m_op.trans_product(V, f, Vf); - f.noalias() -= V * Vf; - // fnorm <- ||f|| - fnorm = m_op.norm(f); - - // If fnorm is too close to zero, we try a new random vector, - // otherwise return the result - if(fnorm >= thresh) - return; - } - } - -public: - Arnoldi(const ArnoldiOpType& op, Index m) : - m_op(op), m_n(op.rows()), m_m(m), m_k(0), - m_near_0(TypeTraits<Scalar>::min() * Scalar(10)), - m_eps(Eigen::NumTraits<Scalar>::epsilon()) - {} - - virtual ~Arnoldi() {} - - // Const-reference to internal structures - const Matrix& matrix_V() const { return m_fac_V; } - const Matrix& matrix_H() const { return m_fac_H; } - const Vector& vector_f() const { return m_fac_f; } - Scalar f_norm() const { return m_beta; } - Index subspace_dim() const { return m_k; } - - // Initialize with an operator and an initial vector - void init(MapConstVec& v0, Index& op_counter) - { - m_fac_V.resize(m_n, m_m); - m_fac_H.resize(m_m, m_m); - m_fac_f.resize(m_n); - m_fac_H.setZero(); - - // Verify the initial vector - const Scalar v0norm = m_op.norm(v0); - if(v0norm < m_near_0) - throw std::invalid_argument("initial residual vector cannot be zero"); - - // Points to the first column of V - MapVec v(m_fac_V.data(), m_n); - - // Normalize - v.noalias() = v0 / v0norm; - - // Compute H and f - Vector w(m_n); - m_op.perform_op(v.data(), w.data()); - op_counter++; - - m_fac_H(0, 0) = m_op.inner_product(v, w); - m_fac_f.noalias() = w - v * m_fac_H(0, 0); - - // In some cases f is zero in exact arithmetics, but due to rounding errors - // it may contain tiny fluctuations. When this happens, we force f to be zero - if(m_fac_f.cwiseAbs().maxCoeff() < m_eps) - { - m_fac_f.setZero(); - m_beta = Scalar(0); - } else { - m_beta = m_op.norm(m_fac_f); - } - - // Indicate that this is a step-1 factorization - m_k = 1; - } - - // Arnoldi factorization starting from step-k - virtual void factorize_from(Index from_k, Index to_m, Index& op_counter) - { - using std::sqrt; - - if(to_m <= from_k) return; - - if(from_k > m_k) - { - std::stringstream msg; - msg << "Arnoldi: from_k (= " << from_k << - ") is larger than the current subspace dimension (= " << - m_k << ")"; - throw std::invalid_argument(msg.str()); - } - - const Scalar beta_thresh = m_eps * sqrt(Scalar(m_n)); - - // Pre-allocate vectors - Vector Vf(to_m); - Vector w(m_n); - - // Keep the upperleft k x k submatrix of H and set other elements to 0 - m_fac_H.rightCols(m_m - from_k).setZero(); - m_fac_H.block(from_k, 0, m_m - from_k, from_k).setZero(); - - for(Index i = from_k; i <= to_m - 1; i++) - { - bool restart = false; - // If beta = 0, then the next V is not full rank - // We need to generate a new residual vector that is orthogonal - // to the current V, which we call a restart - if(m_beta < m_near_0) - { - MapConstMat V(m_fac_V.data(), m_n, i); // The first i columns - expand_basis(V, 2 * i, m_fac_f, m_beta); - restart = true; - } - - // v <- f / ||f|| - m_fac_V.col(i).noalias() = m_fac_f / m_beta; // The (i+1)-th column - - // Note that H[i+1, i] equals to the unrestarted beta - m_fac_H(i, i - 1) = restart ? Scalar(0) : m_beta; - - // w <- A * v, v = m_fac_V.col(i) - m_op.perform_op(&m_fac_V(0, i), w.data()); - op_counter++; - - const Index i1 = i + 1; - // First i+1 columns of V - MapConstMat Vs(m_fac_V.data(), m_n, i1); - // h = m_fac_H(0:i, i) - MapVec h(&m_fac_H(0, i), i1); - // h <- V'Bw - m_op.trans_product(Vs, w, h); - - // f <- w - V * h - m_fac_f.noalias() = w - Vs * h; - m_beta = m_op.norm(m_fac_f); - - if(m_beta > Scalar(0.717) * m_op.norm(h)) - continue; - - // f/||f|| is going to be the next column of V, so we need to test - // whether V'B(f/||f||) ~= 0 - m_op.trans_product(Vs, m_fac_f, Vf.head(i1)); - Scalar ortho_err = Vf.head(i1).cwiseAbs().maxCoeff(); - // If not, iteratively correct the residual - int count = 0; - while(count < 5 && ortho_err > m_eps * m_beta) - { - // There is an edge case: when beta=||f|| is close to zero, f mostly consists - // of noises of rounding errors, so the test [ortho_err < eps * beta] is very - // likely to fail. In particular, if beta=0, then the test is ensured to fail. - // Hence when this happens, we force f to be zero, and then restart in the - // next iteration. - if(m_beta < beta_thresh) - { - m_fac_f.setZero(); - m_beta = Scalar(0); - break; - } - - // f <- f - V * Vf - m_fac_f.noalias() -= Vs * Vf.head(i1); - // h <- h + Vf - h.noalias() += Vf.head(i1); - // beta <- ||f|| - m_beta = m_op.norm(m_fac_f); - - m_op.trans_product(Vs, m_fac_f, Vf.head(i1)); - ortho_err = Vf.head(i1).cwiseAbs().maxCoeff(); - count++; - } - } - - // Indicate that this is a step-m factorization - m_k = to_m; - } - - // Apply H -> Q'HQ, where Q is from a double shift QR decomposition - void compress_H(const DoubleShiftQR<Scalar>& decomp) - { - decomp.matrix_QtHQ(m_fac_H); - m_k -= 2; - } - - // Apply H -> Q'HQ, where Q is from an upper Hessenberg QR decomposition - void compress_H(const UpperHessenbergQR<Scalar>& decomp) - { - decomp.matrix_QtHQ(m_fac_H); - m_k--; - } - - // Apply V -> VQ and compute the new f. - // Should be called after compress_H(), since m_k is updated there. - // Only need to update the first k+1 columns of V - // The first (m - k + i) elements of the i-th column of Q are non-zero, - // and the rest are zero - void compress_V(const Matrix& Q) - { - Matrix Vs(m_n, m_k + 1); - for(Index i = 0; i < m_k; i++) - { - const Index nnz = m_m - m_k + i + 1; - MapConstVec q(&Q(0, i), nnz); - Vs.col(i).noalias() = m_fac_V.leftCols(nnz) * q; - } - Vs.col(m_k).noalias() = m_fac_V * Q.col(m_k); - m_fac_V.leftCols(m_k + 1).noalias() = Vs; - - Vector fk = m_fac_f * Q(m_m - 1, m_k - 1) + m_fac_V.col(m_k) * m_fac_H(m_k, m_k - 1); - m_fac_f.swap(fk); - m_beta = m_op.norm(m_fac_f); - } -}; - - -} // namespace Spectra - -#endif // ARNOLDI_H diff --git a/src/external/Spectra/include/Spectra/LinAlg/BKLDLT.h b/src/external/Spectra/include/Spectra/LinAlg/BKLDLT.h deleted file mode 100644 index 5509749b..00000000 --- a/src/external/Spectra/include/Spectra/LinAlg/BKLDLT.h +++ /dev/null @@ -1,522 +0,0 @@ -// Copyright (C) 2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef BK_LDLT_H -#define BK_LDLT_H - -#include <Eigen/Core> -#include <vector> -#include <stdexcept> - -#include "../Util/CompInfo.h" - -namespace Spectra { - - -// Bunch-Kaufman LDLT decomposition -// References: -// 1. Bunch, J. R., & Kaufman, L. (1977). Some stable methods for calculating inertia and solving symmetric linear systems. -// Mathematics of computation, 31(137), 163-179. -// 2. Golub, G. H., & Van Loan, C. F. (2012). Matrix computations (Vol. 3). JHU press. Section 4.4. -// 3. Bunch-Parlett diagonal pivoting <http://oz.nthu.edu.tw/~d947207/Chap13_GE3.ppt> -// 4. Ashcraft, C., Grimes, R. G., & Lewis, J. G. (1998). Accurate symmetric indefinite linear equation solvers. -// SIAM Journal on Matrix Analysis and Applications, 20(2), 513-561. -template <typename Scalar = double> -class BKLDLT -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::Map<const Vector> MapConstVec; - - typedef Eigen::Matrix<Index, Eigen::Dynamic, 1> IntVector; - typedef Eigen::Ref<Vector> GenericVector; - typedef Eigen::Ref<Matrix> GenericMatrix; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - typedef const Eigen::Ref<const Vector> ConstGenericVector; - - Index m_n; - Vector m_data; // storage for a lower-triangular matrix - std::vector<Scalar*> m_colptr; // pointers to columns - IntVector m_perm; // [-2, -1, 3, 1, 4, 5]: 0 <-> 2, 1 <-> 1, 2 <-> 3, 3 <-> 1, 4 <-> 4, 5 <-> 5 - std::vector< std::pair<Index, Index> > m_permc; // compressed version of m_perm: [(0, 2), (2, 3), (3, 1)] - - bool m_computed; - int m_info; - - // Access to elements - // Pointer to the k-th column - Scalar* col_pointer(Index k) { return m_colptr[k]; } - // A[i, j] -> m_colptr[j][i - j], i >= j - Scalar& coeff(Index i, Index j) { return m_colptr[j][i - j]; } - const Scalar& coeff(Index i, Index j) const { return m_colptr[j][i - j]; } - // A[i, i] -> m_colptr[i][0] - Scalar& diag_coeff(Index i) { return m_colptr[i][0]; } - const Scalar& diag_coeff(Index i) const { return m_colptr[i][0]; } - - // Compute column pointers - void compute_pointer() - { - m_colptr.clear(); - m_colptr.reserve(m_n); - Scalar* head = m_data.data(); - - for(Index i = 0; i < m_n; i++) - { - m_colptr.push_back(head); - head += (m_n - i); - } - } - - // Copy mat - shift * I to m_data - void copy_data(ConstGenericMatrix& mat, int uplo, const Scalar& shift) - { - if(uplo == Eigen::Lower) - { - for(Index j = 0; j < m_n; j++) - { - const Scalar* begin = &mat.coeffRef(j, j); - const Index len = m_n - j; - std::copy(begin, begin + len, col_pointer(j)); - diag_coeff(j) -= shift; - } - } else { - Scalar* dest = m_data.data(); - for(Index i = 0; i < m_n; i++) - { - for(Index j = i; j < m_n; j++, dest++) - { - *dest = mat.coeff(i, j); - } - diag_coeff(i) -= shift; - } - } - } - - // Compute compressed permutations - void compress_permutation() - { - for(Index i = 0; i < m_n; i++) - { - // Recover the permutation action - const Index perm = (m_perm[i] >= 0) ? (m_perm[i]) : (-m_perm[i] - 1); - if(perm != i) - m_permc.push_back(std::make_pair(i, perm)); - } - } - - // Working on the A[k:end, k:end] submatrix - // Exchange k <-> r - // Assume r >= k - void pivoting_1x1(Index k, Index r) - { - // No permutation - if(k == r) - { - m_perm[k] = r; - return; - } - - // A[k, k] <-> A[r, r] - std::swap(diag_coeff(k), diag_coeff(r)); - - // A[(r+1):end, k] <-> A[(r+1):end, r] - std::swap_ranges(&coeff(r + 1, k), col_pointer(k + 1), &coeff(r + 1, r)); - - // A[(k+1):(r-1), k] <-> A[r, (k+1):(r-1)] - Scalar* src = &coeff(k + 1, k); - for(Index j = k + 1; j < r; j++, src++) - { - std::swap(*src, coeff(r, j)); - } - - m_perm[k] = r; - } - - // Working on the A[k:end, k:end] submatrix - // Exchange [k+1, k] <-> [r, p] - // Assume p >= k, r >= k+1 - void pivoting_2x2(Index k, Index r, Index p) - { - pivoting_1x1(k, p); - pivoting_1x1(k + 1, r); - - // A[k+1, k] <-> A[r, k] - std::swap(coeff(k + 1, k), coeff(r, k)); - - // Use negative signs to indicate a 2x2 block - // Also minus one to distinguish a negative zero from a positive zero - m_perm[k] = -m_perm[k] - 1; - m_perm[k + 1] = -m_perm[k + 1] - 1; - } - - // A[r1, c1:c2] <-> A[r2, c1:c2] - // Assume r2 >= r1 > c2 >= c1 - void interchange_rows(Index r1, Index r2, Index c1, Index c2) - { - if(r1 == r2) - return; - - for(Index j = c1; j <= c2; j++) - { - std::swap(coeff(r1, j), coeff(r2, j)); - } - } - - // lambda = |A[r, k]| = max{|A[k+1, k]|, ..., |A[end, k]|} - // Largest (in magnitude) off-diagonal element in the first column of the current reduced matrix - // r is the row index - // Assume k < end - Scalar find_lambda(Index k, Index& r) - { - using std::abs; - - const Scalar* head = col_pointer(k); // => A[k, k] - const Scalar* end = col_pointer(k + 1); - // Start with r=k+1, lambda=A[k+1, k] - r = k + 1; - Scalar lambda = abs(head[1]); - // Scan remaining elements - for(const Scalar* ptr = head + 2; ptr < end; ptr++) - { - const Scalar abs_elem = abs(*ptr); - if(lambda < abs_elem) - { - lambda = abs_elem; - r = k + (ptr - head); - } - } - - return lambda; - } - - // sigma = |A[p, r]| = max {|A[k, r]|, ..., |A[end, r]|} \ {A[r, r]} - // Largest (in magnitude) off-diagonal element in the r-th column of the current reduced matrix - // p is the row index - // Assume k < r < end - Scalar find_sigma(Index k, Index r, Index& p) - { - using std::abs; - - // First search A[r+1, r], ..., A[end, r], which has the same task as find_lambda() - // If r == end, we skip this search - Scalar sigma = Scalar(-1); - if(r < m_n - 1) - sigma = find_lambda(r, p); - - // Then search A[k, r], ..., A[r-1, r], which maps to A[r, k], ..., A[r, r-1] - for(Index j = k; j < r; j++) - { - const Scalar abs_elem = abs(coeff(r, j)); - if(sigma < abs_elem) - { - sigma = abs_elem; - p = j; - } - } - - return sigma; - } - - // Generate permutations and apply to A - // Return true if the resulting pivoting is 1x1, and false if 2x2 - bool permutate_mat(Index k, const Scalar& alpha) - { - using std::abs; - - Index r = k, p = k; - const Scalar lambda = find_lambda(k, r); - - // If lambda=0, no need to interchange - if(lambda > Scalar(0)) - { - const Scalar abs_akk = abs(diag_coeff(k)); - // If |A[k, k]| >= alpha * lambda, no need to interchange - if(abs_akk < alpha * lambda) - { - const Scalar sigma = find_sigma(k, r, p); - - // If sigma * |A[k, k]| >= alpha * lambda^2, no need to interchange - if(sigma * abs_akk < alpha * lambda * lambda) - { - if(abs_akk >= alpha * sigma) - { - // Permutation on A - pivoting_1x1(k, r); - - // Permutation on L - interchange_rows(k, r, 0, k - 1); - return true; - } else { - // There are two versions of permutation here - // 1. A[k+1, k] <-> A[r, k] - // 2. A[k+1, k] <-> A[r, p], where p >= k and r >= k+1 - // - // Version 1 and 2 are used by Ref[1] and Ref[2], respectively - - // Version 1 implementation - p = k; - - // Version 2 implementation - // [r, p] and [p, r] are symmetric, but we need to make sure - // p >= k and r >= k+1, so it is safe to always make r > p - // One exception is when min{r,p} == k+1, in which case we make - // r = k+1, so that only one permutation needs to be performed - /* const Index rp_min = std::min(r, p); - const Index rp_max = std::max(r, p); - if(rp_min == k + 1) - { - r = rp_min; p = rp_max; - } else { - r = rp_max; p = rp_min; - } */ - - // Right now we use Version 1 since it reduces the overhead of interchange - - // Permutation on A - pivoting_2x2(k, r, p); - // Permutation on L - interchange_rows(k, p, 0, k - 1); - interchange_rows(k + 1, r, 0, k - 1); - return false; - } - } - } - } - - return true; - } - - // E = [e11, e12] - // [e21, e22] - // Overwrite E with inv(E) - void inverse_inplace_2x2(Scalar& e11, Scalar& e21, Scalar& e22) const - { - // inv(E) = [d11, d12], d11 = e22/delta, d21 = -e21/delta, d22 = e11/delta - // [d21, d22] - const Scalar delta = e11 * e22 - e21 * e21; - std::swap(e11, e22); - e11 /= delta; - e22 /= delta; - e21 = -e21 / delta; - } - - // Return value is the status, SUCCESSFUL/NUMERICAL_ISSUE - int gaussian_elimination_1x1(Index k) - { - // D = 1 / A[k, k] - const Scalar akk = diag_coeff(k); - // Return NUMERICAL_ISSUE if not invertible - if(akk == Scalar(0)) - return NUMERICAL_ISSUE; - - diag_coeff(k) = Scalar(1) / akk; - - // B -= l * l' / A[k, k], B := A[(k+1):end, (k+1):end], l := L[(k+1):end, k] - Scalar* lptr = col_pointer(k) + 1; - const Index ldim = m_n - k - 1; - MapVec l(lptr, ldim); - for(Index j = 0; j < ldim; j++) - { - MapVec(col_pointer(j + k + 1), ldim - j).noalias() -= (lptr[j] / akk) * l.tail(ldim - j); - } - - // l /= A[k, k] - l /= akk; - - return SUCCESSFUL; - } - - // Return value is the status, SUCCESSFUL/NUMERICAL_ISSUE - int gaussian_elimination_2x2(Index k) - { - // D = inv(E) - Scalar& e11 = diag_coeff(k); - Scalar& e21 = coeff(k + 1, k); - Scalar& e22 = diag_coeff(k + 1); - // Return NUMERICAL_ISSUE if not invertible - if(e11 * e22 - e21 * e21 == Scalar(0)) - return NUMERICAL_ISSUE; - - inverse_inplace_2x2(e11, e21, e22); - - // X = l * inv(E), l := L[(k+2):end, k:(k+1)] - Scalar* l1ptr = &coeff(k + 2, k); - Scalar* l2ptr = &coeff(k + 2, k + 1); - const Index ldim = m_n - k - 2; - MapVec l1(l1ptr, ldim), l2(l2ptr, ldim); - - Eigen::Matrix<Scalar, Eigen::Dynamic, 2> X(ldim, 2); - X.col(0).noalias() = l1 * e11 + l2 * e21; - X.col(1).noalias() = l1 * e21 + l2 * e22; - - // B -= l * inv(E) * l' = X * l', B = A[(k+2):end, (k+2):end] - for(Index j = 0; j < ldim; j++) - { - MapVec(col_pointer(j + k + 2), ldim - j).noalias() -= (X.col(0).tail(ldim - j) * l1ptr[j] + X.col(1).tail(ldim - j) * l2ptr[j]); - } - - // l = X - l1.noalias() = X.col(0); - l2.noalias() = X.col(1); - - return SUCCESSFUL; - } - -public: - BKLDLT() : - m_n(0), m_computed(false), m_info(NOT_COMPUTED) - {} - - // Factorize mat - shift * I - BKLDLT(ConstGenericMatrix& mat, int uplo = Eigen::Lower, const Scalar& shift = Scalar(0)) : - m_n(mat.rows()), m_computed(false), m_info(NOT_COMPUTED) - { - compute(mat, uplo, shift); - } - - void compute(ConstGenericMatrix& mat, int uplo = Eigen::Lower, const Scalar& shift = Scalar(0)) - { - using std::abs; - - m_n = mat.rows(); - if(m_n != mat.cols()) - throw std::invalid_argument("BKLDLT: matrix must be square"); - - m_perm.setLinSpaced(m_n, 0, m_n - 1); - m_permc.clear(); - - // Copy data - m_data.resize((m_n * (m_n + 1)) / 2); - compute_pointer(); - copy_data(mat, uplo, shift); - - const Scalar alpha = (1.0 + std::sqrt(17.0)) / 8.0; - Index k = 0; - for(k = 0; k < m_n - 1; k++) - { - // 1. Interchange rows and columns of A, and save the result to m_perm - bool is_1x1 = permutate_mat(k, alpha); - - // 2. Gaussian elimination - if(is_1x1) - { - m_info = gaussian_elimination_1x1(k); - } else { - m_info = gaussian_elimination_2x2(k); - k++; - } - - // 3. Check status - if(m_info != SUCCESSFUL) - break; - } - // Invert the last 1x1 block if it exists - if(k == m_n - 1) - { - const Scalar akk = diag_coeff(k); - if(akk == Scalar(0)) - m_info = NUMERICAL_ISSUE; - - diag_coeff(k) = Scalar(1) / diag_coeff(k); - } - - compress_permutation(); - - m_computed = true; - } - - // Solve Ax=b - void solve_inplace(GenericVector b) const - { - if(!m_computed) - throw std::logic_error("BKLDLT: need to call compute() first"); - - // PAP' = LDL' - // 1. b -> Pb - Scalar* x = b.data(); - MapVec res(x, m_n); - Index npermc = m_permc.size(); - for(Index i = 0; i < npermc; i++) - { - std::swap(x[m_permc[i].first], x[m_permc[i].second]); - } - - // 2. Lz = Pb - // If m_perm[end] < 0, then end with m_n - 3, otherwise end with m_n - 2 - const Index end = (m_perm[m_n - 1] < 0) ? (m_n - 3) : (m_n - 2); - for(Index i = 0; i <= end; i++) - { - const Index b1size = m_n - i - 1; - const Index b2size = b1size - 1; - if(m_perm[i] >= 0) - { - MapConstVec l(&coeff(i + 1, i), b1size); - res.segment(i + 1, b1size).noalias() -= l * x[i]; - } else { - MapConstVec l1(&coeff(i + 2, i), b2size); - MapConstVec l2(&coeff(i + 2, i + 1), b2size); - res.segment(i + 2, b2size).noalias() -= (l1 * x[i] + l2 * x[i + 1]); - i++; - } - } - - // 3. Dw = z - for(Index i = 0; i < m_n; i++) - { - const Scalar e11 = diag_coeff(i); - if(m_perm[i] >= 0) - { - x[i] *= e11; - } else { - const Scalar e21 = coeff(i + 1, i), e22 = diag_coeff(i + 1); - const Scalar wi = x[i] * e11 + x[i + 1] * e21; - x[i + 1] = x[i] * e21 + x[i + 1] * e22; - x[i] = wi; - i++; - } - } - - // 4. L'y = w - // If m_perm[end] < 0, then start with m_n - 3, otherwise start with m_n - 2 - Index i = (m_perm[m_n - 1] < 0) ? (m_n - 3) : (m_n - 2); - for(; i >= 0; i--) - { - const Index ldim = m_n - i - 1; - MapConstVec l(&coeff(i + 1, i), ldim); - x[i] -= res.segment(i + 1, ldim).dot(l); - - if(m_perm[i] < 0) - { - MapConstVec l2(&coeff(i + 1, i - 1), ldim); - x[i - 1] -= res.segment(i + 1, ldim).dot(l2); - i--; - } - } - - // 5. x = P'y - for(Index i = npermc - 1; i >= 0; i--) - { - std::swap(x[m_permc[i].first], x[m_permc[i].second]); - } - } - - Vector solve(ConstGenericVector& b) const - { - Vector res = b; - solve_inplace(res); - return res; - } - - int info() const { return m_info; } -}; - - -} // namespace Spectra - -#endif // BK_LDLT_H diff --git a/src/external/Spectra/include/Spectra/LinAlg/DoubleShiftQR.h b/src/external/Spectra/include/Spectra/LinAlg/DoubleShiftQR.h deleted file mode 100644 index 2191909a..00000000 --- a/src/external/Spectra/include/Spectra/LinAlg/DoubleShiftQR.h +++ /dev/null @@ -1,378 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef DOUBLE_SHIFT_QR_H -#define DOUBLE_SHIFT_QR_H - -#include <Eigen/Core> -#include <vector> // std::vector -#include <algorithm> // std::min, std::fill, std::copy -#include <cmath> // std::abs, std::sqrt, std::pow -#include <stdexcept> // std::invalid_argument, std::logic_error - -#include "../Util/TypeTraits.h" - -namespace Spectra { - - -template <typename Scalar = double> -class DoubleShiftQR -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, 3, Eigen::Dynamic> Matrix3X; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Array<unsigned char, Eigen::Dynamic, 1> IntArray; - - typedef Eigen::Ref<Matrix> GenericMatrix; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - Index m_n; // Dimension of the matrix - Matrix m_mat_H; // A copy of the matrix to be factorized - Scalar m_shift_s; // Shift constant - Scalar m_shift_t; // Shift constant - Matrix3X m_ref_u; // Householder reflectors - IntArray m_ref_nr; // How many rows does each reflector affects - // 3 - A general reflector - // 2 - A Givens rotation - // 1 - An identity transformation - const Scalar m_near_0; // a very small value, but 1.0 / m_safe_min does not overflow - // ~= 1e-307 for the "double" type - const Scalar m_eps; // the machine precision, - // e.g. ~= 1e-16 for the "double" type - const Scalar m_eps_rel; - const Scalar m_eps_abs; - bool m_computed; // Whether matrix has been factorized - - void compute_reflector(const Scalar& x1, const Scalar& x2, const Scalar& x3, Index ind) - { - using std::abs; - - Scalar* u = &m_ref_u.coeffRef(0, ind); - unsigned char* nr = m_ref_nr.data(); - // In general case the reflector affects 3 rows - nr[ind] = 3; - Scalar x2x3 = Scalar(0); - // If x3 is zero, decrease nr by 1 - if(abs(x3) < m_near_0) - { - // If x2 is also zero, nr will be 1, and we can exit this function - if(abs(x2) < m_near_0) - { - nr[ind] = 1; - return; - } else { - nr[ind] = 2; - } - x2x3 = abs(x2); - } else { - x2x3 = Eigen::numext::hypot(x2, x3); - } - - // x1' = x1 - rho * ||x|| - // rho = -sign(x1), if x1 == 0, we choose rho = 1 - Scalar x1_new = x1 - ((x1 <= 0) - (x1 > 0)) * Eigen::numext::hypot(x1, x2x3); - Scalar x_norm = Eigen::numext::hypot(x1_new, x2x3); - // Double check the norm of new x - if(x_norm < m_near_0) - { - nr[ind] = 1; - return; - } - u[0] = x1_new / x_norm; - u[1] = x2 / x_norm; - u[2] = x3 / x_norm; - } - - void compute_reflector(const Scalar* x, Index ind) - { - compute_reflector(x[0], x[1], x[2], ind); - } - - // Update the block X = H(il:iu, il:iu) - void update_block(Index il, Index iu) - { - // Block size - const Index bsize = iu - il + 1; - - // If block size == 1, there is no need to apply reflectors - if(bsize == 1) - { - m_ref_nr.coeffRef(il) = 1; - return; - } - - const Scalar x00 = m_mat_H.coeff(il, il), - x01 = m_mat_H.coeff(il, il + 1), - x10 = m_mat_H.coeff(il + 1, il), - x11 = m_mat_H.coeff(il + 1, il + 1); - // m00 = x00 * (x00 - s) + x01 * x10 + t - const Scalar m00 = x00 * (x00 - m_shift_s) + x01 * x10 + m_shift_t; - // m10 = x10 * (x00 + x11 - s) - const Scalar m10 = x10 * (x00 + x11 - m_shift_s); - - // For block size == 2, do a Givens rotation on M = X * X - s * X + t * I - if(bsize == 2) - { - // This causes nr=2 - compute_reflector(m00, m10, 0, il); - // Apply the reflector to X - apply_PX(m_mat_H.block(il, il, 2, m_n - il), m_n, il); - apply_XP(m_mat_H.block(0, il, il + 2, 2), m_n, il); - - m_ref_nr.coeffRef(il + 1) = 1; - return; - } - - // For block size >=3, use the regular strategy - // m20 = x21 * x10 - const Scalar m20 = m_mat_H.coeff(il + 2, il + 1) * m_mat_H.coeff(il + 1, il); - compute_reflector(m00, m10, m20, il); - - // Apply the first reflector - apply_PX(m_mat_H.block(il, il, 3, m_n - il), m_n, il); - apply_XP(m_mat_H.block(0, il, il + std::min(bsize, Index(4)), 3), m_n, il); - - // Calculate the following reflectors - // If entering this loop, block size is at least 4. - for(Index i = 1; i < bsize - 2; i++) - { - compute_reflector(&m_mat_H.coeffRef(il + i, il + i - 1), il + i); - // Apply the reflector to X - apply_PX(m_mat_H.block(il + i, il + i - 1, 3, m_n - il - i + 1), m_n, il + i); - apply_XP(m_mat_H.block(0, il + i, il + std::min(bsize, Index(i + 4)), 3), m_n, il + i); - } - - // The last reflector - // This causes nr=2 - compute_reflector(m_mat_H.coeff(iu - 1, iu - 2), m_mat_H.coeff(iu, iu - 2), 0, iu - 1); - // Apply the reflector to X - apply_PX(m_mat_H.block(iu - 1, iu - 2, 2, m_n - iu + 2), m_n, iu - 1); - apply_XP(m_mat_H.block(0, iu - 1, il + bsize, 2), m_n, iu - 1); - - m_ref_nr.coeffRef(iu) = 1; - } - - // P = I - 2 * u * u' = P' - // PX = X - 2 * u * (u'X) - void apply_PX(GenericMatrix X, Index stride, Index u_ind) const - { - const Index nr = m_ref_nr.coeff(u_ind); - if(nr == 1) - return; - - const Scalar u0 = m_ref_u.coeff(0, u_ind), - u1 = m_ref_u.coeff(1, u_ind); - const Scalar u0_2 = Scalar(2) * u0, - u1_2 = Scalar(2) * u1; - - const Index nrow = X.rows(); - const Index ncol = X.cols(); - - Scalar* xptr = X.data(); - if(nr == 2 || nrow == 2) - { - for(Index i = 0; i < ncol; i++, xptr += stride) - { - const Scalar tmp = u0_2 * xptr[0] + u1_2 * xptr[1]; - xptr[0] -= tmp * u0; - xptr[1] -= tmp * u1; - } - } else { - const Scalar u2 = m_ref_u.coeff(2, u_ind); - const Scalar u2_2 = Scalar(2) * u2; - for(Index i = 0; i < ncol; i++, xptr += stride) - { - const Scalar tmp = u0_2 * xptr[0] + u1_2 * xptr[1] + u2_2 * xptr[2]; - xptr[0] -= tmp * u0; - xptr[1] -= tmp * u1; - xptr[2] -= tmp * u2; - } - } - } - - // x is a pointer to a vector - // Px = x - 2 * dot(x, u) * u - void apply_PX(Scalar* x, Index u_ind) const - { - const Index nr = m_ref_nr.coeff(u_ind); - if(nr == 1) - return; - - const Scalar u0 = m_ref_u.coeff(0, u_ind), - u1 = m_ref_u.coeff(1, u_ind), - u2 = m_ref_u.coeff(2, u_ind); - - // When the reflector only contains two elements, u2 has been set to zero - const bool nr_is_2 = (nr == 2); - const Scalar dot2 = Scalar(2) * (x[0] * u0 + x[1] * u1 + (nr_is_2 ? 0 : (x[2] * u2))); - x[0] -= dot2 * u0; - x[1] -= dot2 * u1; - if(!nr_is_2) - x[2] -= dot2 * u2; - } - - // XP = X - 2 * (X * u) * u' - void apply_XP(GenericMatrix X, Index stride, Index u_ind) const - { - const Index nr = m_ref_nr.coeff(u_ind); - if(nr == 1) - return; - - const Scalar u0 = m_ref_u.coeff(0, u_ind), - u1 = m_ref_u.coeff(1, u_ind); - const Scalar u0_2 = Scalar(2) * u0, - u1_2 = Scalar(2) * u1; - - const int nrow = X.rows(); - const int ncol = X.cols(); - Scalar *X0 = X.data(), *X1 = X0 + stride; // X0 => X.col(0), X1 => X.col(1) - - if(nr == 2 || ncol == 2) - { - // tmp = 2 * u0 * X0 + 2 * u1 * X1 - // X0 => X0 - u0 * tmp - // X1 => X1 - u1 * tmp - for(Index i = 0; i < nrow; i++) - { - const Scalar tmp = u0_2 * X0[i] + u1_2 * X1[i]; - X0[i] -= tmp * u0; - X1[i] -= tmp * u1; - } - } else { - Scalar* X2 = X1 + stride; // X2 => X.col(2) - const Scalar u2 = m_ref_u.coeff(2, u_ind); - const Scalar u2_2 = Scalar(2) * u2; - for(Index i = 0; i < nrow; i++) - { - const Scalar tmp = u0_2 * X0[i] + u1_2 * X1[i] + u2_2 * X2[i]; - X0[i] -= tmp * u0; - X1[i] -= tmp * u1; - X2[i] -= tmp * u2; - } - } - } - -public: - DoubleShiftQR(Index size) : - m_n(size), - m_near_0(TypeTraits<Scalar>::min() * Scalar(10)), - m_eps(Eigen::NumTraits<Scalar>::epsilon()), - m_eps_rel(m_eps), - m_eps_abs(m_near_0 * (m_n / m_eps)), - m_computed(false) - {} - - DoubleShiftQR(ConstGenericMatrix& mat, const Scalar& s, const Scalar& t) : - m_n(mat.rows()), - m_mat_H(m_n, m_n), - m_shift_s(s), - m_shift_t(t), - m_ref_u(3, m_n), - m_ref_nr(m_n), - m_near_0(TypeTraits<Scalar>::min() * Scalar(10)), - m_eps(Eigen::NumTraits<Scalar>::epsilon()), - m_eps_rel(m_eps), - m_eps_abs(m_near_0 * (m_n / m_eps)), - m_computed(false) - { - compute(mat, s, t); - } - - void compute(ConstGenericMatrix& mat, const Scalar& s, const Scalar& t) - { - using std::abs; - - m_n = mat.rows(); - if(m_n != mat.cols()) - throw std::invalid_argument("DoubleShiftQR: matrix must be square"); - - m_mat_H.resize(m_n, m_n); - m_shift_s = s; - m_shift_t = t; - m_ref_u.resize(3, m_n); - m_ref_nr.resize(m_n); - - // Make a copy of mat - std::copy(mat.data(), mat.data() + mat.size(), m_mat_H.data()); - - // Obtain the indices of zero elements in the subdiagonal, - // so that H can be divided into several blocks - std::vector<int> zero_ind; - zero_ind.reserve(m_n - 1); - zero_ind.push_back(0); - Scalar* Hii = m_mat_H.data(); - for(Index i = 0; i < m_n - 2; i++, Hii += (m_n + 1)) - { - // Hii[1] => m_mat_H(i + 1, i) - const Scalar h = abs(Hii[1]); - if(h <= 0 || h <= m_eps_rel * (abs(Hii[0]) + abs(Hii[m_n + 1]))) - { - Hii[1] = 0; - zero_ind.push_back(i + 1); - } - // Make sure m_mat_H is upper Hessenberg - // Zero the elements below m_mat_H(i + 1, i) - std::fill(Hii + 2, Hii + m_n - i, Scalar(0)); - } - zero_ind.push_back(m_n); - - for(std::vector<int>::size_type i = 0; i < zero_ind.size() - 1; i++) - { - const Index start = zero_ind[i]; - const Index end = zero_ind[i + 1] - 1; - // Compute refelctors and update each block - update_block(start, end); - } - - m_computed = true; - } - - void matrix_QtHQ(Matrix& dest) const - { - if(!m_computed) - throw std::logic_error("DoubleShiftQR: need to call compute() first"); - - dest.noalias() = m_mat_H; - } - - // Q = P0 * P1 * ... - // Q'y = P_{n-2} * ... * P1 * P0 * y - void apply_QtY(Vector& y) const - { - if(!m_computed) - throw std::logic_error("DoubleShiftQR: need to call compute() first"); - - Scalar* y_ptr = y.data(); - const Index n1 = m_n - 1; - for(Index i = 0; i < n1; i++, y_ptr++) - { - apply_PX(y_ptr, i); - } - } - - // Q = P0 * P1 * ... - // YQ = Y * P0 * P1 * ... - void apply_YQ(GenericMatrix Y) const - { - if(!m_computed) - throw std::logic_error("DoubleShiftQR: need to call compute() first"); - - const Index nrow = Y.rows(); - const Index n2 = m_n - 2; - for(Index i = 0; i < n2; i++) - { - apply_XP(Y.block(0, i, nrow, 3), nrow, i); - } - apply_XP(Y.block(0, n2, nrow, 2), nrow, n2); - } -}; - - -} // namespace Spectra - -#endif // DOUBLE_SHIFT_QR_H diff --git a/src/external/Spectra/include/Spectra/LinAlg/Lanczos.h b/src/external/Spectra/include/Spectra/LinAlg/Lanczos.h deleted file mode 100644 index 2301dd30..00000000 --- a/src/external/Spectra/include/Spectra/LinAlg/Lanczos.h +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright (C) 2018-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef LANCZOS_H -#define LANCZOS_H - -#include <Eigen/Core> -#include <cmath> // std::sqrt -#include <stdexcept> // std::invalid_argument -#include <sstream> // std::stringstream - -#include "Arnoldi.h" - -namespace Spectra { - - -// Lanczos factorization A * V = V * H + f * e' -// A: n x n -// V: n x k -// H: k x k -// f: n x 1 -// e: [0, ..., 0, 1] -// V and H are allocated of dimension m, so the maximum value of k is m -template <typename Scalar, typename ArnoldiOpType> -class Lanczos: public Arnoldi<Scalar, ArnoldiOpType> -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<Matrix> MapMat; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::Map<const Matrix> MapConstMat; - typedef Eigen::Map<const Vector> MapConstVec; - - using Arnoldi<Scalar, ArnoldiOpType>::m_op; - using Arnoldi<Scalar, ArnoldiOpType>::m_n; - using Arnoldi<Scalar, ArnoldiOpType>::m_m; - using Arnoldi<Scalar, ArnoldiOpType>::m_k; - using Arnoldi<Scalar, ArnoldiOpType>::m_fac_V; - using Arnoldi<Scalar, ArnoldiOpType>::m_fac_H; - using Arnoldi<Scalar, ArnoldiOpType>::m_fac_f; - using Arnoldi<Scalar, ArnoldiOpType>::m_beta; - using Arnoldi<Scalar, ArnoldiOpType>::m_near_0; - using Arnoldi<Scalar, ArnoldiOpType>::m_eps; - -public: - Lanczos(const ArnoldiOpType& op, Index m) : - Arnoldi<Scalar, ArnoldiOpType>(op, m) - {} - - // Lanczos factorization starting from step-k - void factorize_from(Index from_k, Index to_m, Index& op_counter) - { - using std::sqrt; - - if(to_m <= from_k) return; - - if(from_k > m_k) - { - std::stringstream msg; - msg << "Lanczos: from_k (= " << from_k << - ") is larger than the current subspace dimension (= " << - m_k << ")"; - throw std::invalid_argument(msg.str()); - } - - const Scalar beta_thresh = m_eps * sqrt(Scalar(m_n)); - - // Pre-allocate vectors - Vector Vf(to_m); - Vector w(m_n); - - // Keep the upperleft k x k submatrix of H and set other elements to 0 - m_fac_H.rightCols(m_m - from_k).setZero(); - m_fac_H.block(from_k, 0, m_m - from_k, from_k).setZero(); - - for(Index i = from_k; i <= to_m - 1; i++) - { - bool restart = false; - // If beta = 0, then the next V is not full rank - // We need to generate a new residual vector that is orthogonal - // to the current V, which we call a restart - if(m_beta < m_near_0) - { - MapConstMat V(m_fac_V.data(), m_n, i); // The first i columns - this->expand_basis(V, 2 * i, m_fac_f, m_beta); - restart = true; - } - - // v <- f / ||f|| - MapVec v(&m_fac_V(0, i), m_n); // The (i+1)-th column - v.noalias() = m_fac_f / m_beta; - - // Note that H[i+1, i] equals to the unrestarted beta - m_fac_H(i, i - 1) = restart ? Scalar(0) : m_beta; - - // w <- A * v - m_op.perform_op(v.data(), w.data()); - op_counter++; - - // H[i+1, i+1] = <v, w> = v'Bw - m_fac_H(i - 1, i) = m_fac_H(i, i - 1); // Due to symmetry - m_fac_H(i, i) = m_op.inner_product(v, w); - - // f <- w - V * V'Bw = w - H[i+1, i] * V{i} - H[i+1, i+1] * V{i+1} - // If restarting, we know that H[i+1, i] = 0 - if(restart) - m_fac_f.noalias() = w - m_fac_H(i, i) * v; - else - m_fac_f.noalias() = w - m_fac_H(i, i - 1) * m_fac_V.col(i - 1) - m_fac_H(i, i) * v; - - m_beta = m_op.norm(m_fac_f); - - // f/||f|| is going to be the next column of V, so we need to test - // whether V'B(f/||f||) ~= 0 - const Index i1 = i + 1; - MapMat Vs(m_fac_V.data(), m_n, i1); // The first (i+1) columns - m_op.trans_product(Vs, m_fac_f, Vf.head(i1)); - Scalar ortho_err = Vf.head(i1).cwiseAbs().maxCoeff(); - // If not, iteratively correct the residual - int count = 0; - while(count < 5 && ortho_err > m_eps * m_beta) - { - // There is an edge case: when beta=||f|| is close to zero, f mostly consists - // of noises of rounding errors, so the test [ortho_err < eps * beta] is very - // likely to fail. In particular, if beta=0, then the test is ensured to fail. - // Hence when this happens, we force f to be zero, and then restart in the - // next iteration. - if(m_beta < beta_thresh) - { - m_fac_f.setZero(); - m_beta = Scalar(0); - break; - } - - // f <- f - V * Vf - m_fac_f.noalias() -= Vs * Vf.head(i1); - // h <- h + Vf - m_fac_H(i - 1, i) += Vf[i - 1]; - m_fac_H(i, i - 1) = m_fac_H(i - 1, i); - m_fac_H(i, i) += Vf[i]; - // beta <- ||f|| - m_beta = m_op.norm(m_fac_f); - - m_op.trans_product(Vs, m_fac_f, Vf.head(i1)); - ortho_err = Vf.head(i1).cwiseAbs().maxCoeff(); - count++; - } - } - - // Indicate that this is a step-m factorization - m_k = to_m; - } - - // Apply H -> Q'HQ, where Q is from a tridiagonal QR decomposition - void compress_H(const TridiagQR<Scalar>& decomp) - { - decomp.matrix_QtHQ(m_fac_H); - m_k--; - } -}; - - -} // namespace Spectra - -#endif // LANCZOS_H diff --git a/src/external/Spectra/include/Spectra/LinAlg/TridiagEigen.h b/src/external/Spectra/include/Spectra/LinAlg/TridiagEigen.h deleted file mode 100644 index b79fe8d1..00000000 --- a/src/external/Spectra/include/Spectra/LinAlg/TridiagEigen.h +++ /dev/null @@ -1,219 +0,0 @@ -// The code was adapted from Eigen/src/Eigenvaleus/SelfAdjointEigenSolver.h -// -// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk> -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef TRIDIAG_EIGEN_H -#define TRIDIAG_EIGEN_H - -#include <Eigen/Core> -#include <Eigen/Jacobi> -#include <stdexcept> - -#include "../Util/TypeTraits.h" - -namespace Spectra { - - -template <typename Scalar = double> -class TridiagEigen -{ -private: - typedef Eigen::Index Index; - // For convenience in adapting the tridiagonal_qr_step() function - typedef Scalar RealScalar; - - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - typedef Eigen::Ref<Matrix> GenericMatrix; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - Index m_n; - Vector m_main_diag; // Main diagonal elements of the matrix - Vector m_sub_diag; // Sub-diagonal elements of the matrix - Matrix m_evecs; // To store eigenvectors - - bool m_computed; - const Scalar m_near_0; // a very small value, ~= 1e-307 for the "double" type - - // Adapted from Eigen/src/Eigenvaleus/SelfAdjointEigenSolver.h - static void tridiagonal_qr_step(RealScalar* diag, - RealScalar* subdiag, Index start, - Index end, Scalar* matrixQ, - Index n) - { - using std::abs; - - RealScalar td = (diag[end-1] - diag[end]) * RealScalar(0.5); - RealScalar e = subdiag[end-1]; - // Note that thanks to scaling, e^2 or td^2 cannot overflow, however they can still - // underflow thus leading to inf/NaN values when using the following commented code: - // RealScalar e2 = numext::abs2(subdiag[end-1]); - // RealScalar mu = diag[end] - e2 / (td + (td>0 ? 1 : -1) * sqrt(td*td + e2)); - // This explain the following, somewhat more complicated, version: - RealScalar mu = diag[end]; - if(td == Scalar(0)) - mu -= abs(e); - else - { - RealScalar e2 = Eigen::numext::abs2(subdiag[end-1]); - RealScalar h = Eigen::numext::hypot(td, e); - if(e2==RealScalar(0)) mu -= (e / (td + (td>RealScalar(0) ? RealScalar(1) : RealScalar(-1)))) * (e / h); - else mu -= e2 / (td + (td>RealScalar(0) ? h : -h)); - } - - RealScalar x = diag[start] - mu; - RealScalar z = subdiag[start]; - Eigen::Map<Matrix> q(matrixQ, n, n); - for(Index k = start; k < end; ++k) - { - Eigen::JacobiRotation<RealScalar> rot; - rot.makeGivens(x, z); - - const RealScalar s = rot.s(); - const RealScalar c = rot.c(); - - // do T = G' T G - RealScalar sdk = s * diag[k] + c * subdiag[k]; - RealScalar dkp1 = s * subdiag[k] + c * diag[k + 1]; - - diag[k] = c * (c * diag[k] - s * subdiag[k]) - s * (c * subdiag[k] - s * diag[k + 1]); - diag[k + 1] = s * sdk + c * dkp1; - subdiag[k] = c * sdk - s * dkp1; - - if(k > start) - subdiag[k - 1] = c * subdiag[k - 1] - s * z; - - x = subdiag[k]; - - if(k < end - 1) - { - z = -s * subdiag[k+1]; - subdiag[k + 1] = c * subdiag[k + 1]; - } - - // apply the givens rotation to the unit matrix Q = Q * G - if(matrixQ) - q.applyOnTheRight(k, k + 1, rot); - } - } - -public: - TridiagEigen() : - m_n(0), m_computed(false), - m_near_0(TypeTraits<Scalar>::min() * Scalar(10)) - {} - - TridiagEigen(ConstGenericMatrix& mat) : - m_n(mat.rows()), m_computed(false), - m_near_0(TypeTraits<Scalar>::min() * Scalar(10)) - { - compute(mat); - } - - void compute(ConstGenericMatrix& mat) - { - using std::abs; - - m_n = mat.rows(); - if(m_n != mat.cols()) - throw std::invalid_argument("TridiagEigen: matrix must be square"); - - m_main_diag.resize(m_n); - m_sub_diag.resize(m_n - 1); - m_evecs.resize(m_n, m_n); - m_evecs.setIdentity(); - - // Scale matrix to improve stability - const Scalar scale = std::max(mat.diagonal().cwiseAbs().maxCoeff(), - mat.diagonal(-1).cwiseAbs().maxCoeff()); - // If scale=0, mat is a zero matrix, so we can early stop - if(scale < m_near_0) - { - // m_main_diag contains eigenvalues - m_main_diag.setZero(); - // m_evecs has been set identity - // m_evecs.setIdentity(); - m_computed = true; - return; - } - m_main_diag.noalias() = mat.diagonal() / scale; - m_sub_diag.noalias() = mat.diagonal(-1) / scale; - - Scalar* diag = m_main_diag.data(); - Scalar* subdiag = m_sub_diag.data(); - - Index end = m_n - 1; - Index start = 0; - Index iter = 0; // total number of iterations - int info = 0; // 0 for success, 1 for failure - - const Scalar considerAsZero = TypeTraits<Scalar>::min(); - const Scalar precision = Scalar(2) * Eigen::NumTraits<Scalar>::epsilon(); - - while(end > 0) - { - for(Index i = start; i < end; i++) - if(abs(subdiag[i]) <= considerAsZero || - abs(subdiag[i]) <= (abs(diag[i]) + abs(diag[i + 1])) * precision) - subdiag[i] = 0; - - // find the largest unreduced block - while(end > 0 && subdiag[end - 1] == Scalar(0)) - end--; - - if(end <= 0) - break; - - // if we spent too many iterations, we give up - iter++; - if(iter > 30 * m_n) - { - info = 1; - break; - } - - start = end - 1; - while(start > 0 && subdiag[start - 1] != Scalar(0)) - start--; - - tridiagonal_qr_step(diag, subdiag, start, end, m_evecs.data(), m_n); - } - - if(info > 0) - throw std::runtime_error("TridiagEigen: eigen decomposition failed"); - - // Scale eigenvalues back - m_main_diag *= scale; - - m_computed = true; - } - - const Vector& eigenvalues() const - { - if(!m_computed) - throw std::logic_error("TridiagEigen: need to call compute() first"); - - // After calling compute(), main_diag will contain the eigenvalues. - return m_main_diag; - } - - const Matrix& eigenvectors() const - { - if(!m_computed) - throw std::logic_error("TridiagEigen: need to call compute() first"); - - return m_evecs; - } -}; - - -} // namespace Spectra - -#endif // TRIDIAG_EIGEN_H diff --git a/src/external/Spectra/include/Spectra/LinAlg/UpperHessenbergEigen.h b/src/external/Spectra/include/Spectra/LinAlg/UpperHessenbergEigen.h deleted file mode 100644 index 4e099f56..00000000 --- a/src/external/Spectra/include/Spectra/LinAlg/UpperHessenbergEigen.h +++ /dev/null @@ -1,317 +0,0 @@ -// The code was adapted from Eigen/src/Eigenvaleus/EigenSolver.h -// -// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> -// Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk> -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef UPPER_HESSENBERG_EIGEN_H -#define UPPER_HESSENBERG_EIGEN_H - -#include <Eigen/Core> -#include <Eigen/Eigenvalues> -#include <stdexcept> - -namespace Spectra { - - -template <typename Scalar = double> -class UpperHessenbergEigen -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - typedef Eigen::Ref<Matrix> GenericMatrix; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - typedef std::complex<Scalar> Complex; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic> ComplexMatrix; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> ComplexVector; - - Index m_n; // Size of the matrix - Eigen::RealSchur<Matrix> m_realSchur; // Schur decomposition solver - Matrix m_matT; // Schur T matrix - Matrix m_eivec; // Storing eigenvectors - ComplexVector m_eivalues; // Eigenvalues - - bool m_computed; - - void doComputeEigenvectors() - { - using std::abs; - - const Index size = m_eivec.cols(); - const Scalar eps = Eigen::NumTraits<Scalar>::epsilon(); - - // inefficient! this is already computed in RealSchur - Scalar norm(0); - for(Index j = 0; j < size; ++j) - { - norm += m_matT.row(j).segment((std::max)(j-1, Index(0)), size-(std::max)(j-1, Index(0))).cwiseAbs().sum(); - } - - // Backsubstitute to find vectors of upper triangular form - if(norm == Scalar(0)) - return; - - for(Index n = size - 1; n >= 0; n--) - { - Scalar p = m_eivalues.coeff(n).real(); - Scalar q = m_eivalues.coeff(n).imag(); - - // Scalar vector - if(q == Scalar(0)) - { - Scalar lastr(0), lastw(0); - Index l = n; - - m_matT.coeffRef(n,n) = Scalar(1); - for(Index i = n-1; i >= 0; i--) - { - Scalar w = m_matT.coeff(i,i) - p; - Scalar r = m_matT.row(i).segment(l,n-l+1).dot(m_matT.col(n).segment(l, n-l+1)); - - if(m_eivalues.coeff(i).imag() < Scalar(0)) - { - lastw = w; - lastr = r; - } else { - l = i; - if(m_eivalues.coeff(i).imag() == Scalar(0)) - { - if (w != Scalar(0)) - m_matT.coeffRef(i,n) = -r / w; - else - m_matT.coeffRef(i,n) = -r / (eps * norm); - } - else // Solve real equations - { - Scalar x = m_matT.coeff(i,i+1); - Scalar y = m_matT.coeff(i+1,i); - Scalar denom = (m_eivalues.coeff(i).real() - p) * (m_eivalues.coeff(i).real() - p) + m_eivalues.coeff(i).imag() * m_eivalues.coeff(i).imag(); - Scalar t = (x * lastr - lastw * r) / denom; - m_matT.coeffRef(i,n) = t; - if(abs(x) > abs(lastw)) - m_matT.coeffRef(i+1,n) = (-r - w * t) / x; - else - m_matT.coeffRef(i+1,n) = (-lastr - y * t) / lastw; - } - - // Overflow control - Scalar t = abs(m_matT.coeff(i,n)); - if((eps * t) * t > Scalar(1)) - m_matT.col(n).tail(size-i) /= t; - } - } - } else if(q < Scalar(0) && n > 0) { // Complex vector - Scalar lastra(0), lastsa(0), lastw(0); - Index l = n-1; - - // Last vector component imaginary so matrix is triangular - if(abs(m_matT.coeff(n,n-1)) > abs(m_matT.coeff(n-1,n))) - { - m_matT.coeffRef(n-1,n-1) = q / m_matT.coeff(n,n-1); - m_matT.coeffRef(n-1,n) = -(m_matT.coeff(n,n) - p) / m_matT.coeff(n,n-1); - } - else - { - Complex cc = Complex(Scalar(0),-m_matT.coeff(n-1,n)) / Complex(m_matT.coeff(n-1,n-1)-p,q); - m_matT.coeffRef(n-1,n-1) = Eigen::numext::real(cc); - m_matT.coeffRef(n-1,n) = Eigen::numext::imag(cc); - } - m_matT.coeffRef(n,n-1) = Scalar(0); - m_matT.coeffRef(n,n) = Scalar(1); - for(Index i = n-2; i >= 0; i--) - { - Scalar ra = m_matT.row(i).segment(l, n-l+1).dot(m_matT.col(n-1).segment(l, n-l+1)); - Scalar sa = m_matT.row(i).segment(l, n-l+1).dot(m_matT.col(n).segment(l, n-l+1)); - Scalar w = m_matT.coeff(i,i) - p; - - if(m_eivalues.coeff(i).imag() < Scalar(0)) - { - lastw = w; - lastra = ra; - lastsa = sa; - } - else - { - l = i; - if(m_eivalues.coeff(i).imag() == Scalar(0)) - { - Complex cc = Complex(-ra,-sa) / Complex(w,q); - m_matT.coeffRef(i,n-1) = Eigen::numext::real(cc); - m_matT.coeffRef(i,n) = Eigen::numext::imag(cc); - } - else - { - // Solve complex equations - Scalar x = m_matT.coeff(i,i+1); - Scalar y = m_matT.coeff(i+1,i); - Scalar vr = (m_eivalues.coeff(i).real() - p) * (m_eivalues.coeff(i).real() - p) + m_eivalues.coeff(i).imag() * m_eivalues.coeff(i).imag() - q * q; - Scalar vi = (m_eivalues.coeff(i).real() - p) * Scalar(2) * q; - if((vr == Scalar(0)) && (vi == Scalar(0))) - vr = eps * norm * (abs(w) + abs(q) + abs(x) + abs(y) + abs(lastw)); - - Complex cc = Complex(x*lastra-lastw*ra+q*sa,x*lastsa-lastw*sa-q*ra) / Complex(vr,vi); - m_matT.coeffRef(i,n-1) = Eigen::numext::real(cc); - m_matT.coeffRef(i,n) = Eigen::numext::imag(cc); - if(abs(x) > (abs(lastw) + abs(q))) - { - m_matT.coeffRef(i+1,n-1) = (-ra - w * m_matT.coeff(i,n-1) + q * m_matT.coeff(i,n)) / x; - m_matT.coeffRef(i+1,n) = (-sa - w * m_matT.coeff(i,n) - q * m_matT.coeff(i,n-1)) / x; - } - else - { - cc = Complex(-lastra-y*m_matT.coeff(i,n-1),-lastsa-y*m_matT.coeff(i,n)) / Complex(lastw,q); - m_matT.coeffRef(i+1,n-1) = Eigen::numext::real(cc); - m_matT.coeffRef(i+1,n) = Eigen::numext::imag(cc); - } - } - - // Overflow control - Scalar t = std::max(abs(m_matT.coeff(i,n-1)), abs(m_matT.coeff(i,n))); - if((eps * t) * t > Scalar(1)) - m_matT.block(i, n-1, size-i, 2) /= t; - - } - } - - // We handled a pair of complex conjugate eigenvalues, so need to skip them both - n--; - } - } - - // Back transformation to get eigenvectors of original matrix - Vector m_tmp(size); - for(Index j = size-1; j >= 0; j--) - { - m_tmp.noalias() = m_eivec.leftCols(j+1) * m_matT.col(j).segment(0, j+1); - m_eivec.col(j) = m_tmp; - } - } - -public: - - UpperHessenbergEigen() : - m_n(0), m_computed(false) - {} - - UpperHessenbergEigen(ConstGenericMatrix& mat) : - m_n(mat.rows()), m_computed(false) - { - compute(mat); - } - - void compute(ConstGenericMatrix& mat) - { - using std::abs; - using std::sqrt; - - if(mat.rows() != mat.cols()) - throw std::invalid_argument("UpperHessenbergEigen: matrix must be square"); - - m_n = mat.rows(); - // Scale matrix prior to the Schur decomposition - const Scalar scale = mat.cwiseAbs().maxCoeff(); - - // Reduce to real Schur form - Matrix Q = Matrix::Identity(m_n, m_n); - m_realSchur.computeFromHessenberg(mat / scale, Q, true); - if(m_realSchur.info() != Eigen::Success) - throw std::runtime_error("UpperHessenbergEigen: eigen decomposition failed"); - - m_matT = m_realSchur.matrixT(); - m_eivec = m_realSchur.matrixU(); - - // Compute eigenvalues from matT - m_eivalues.resize(m_n); - Index i = 0; - while(i < m_n) - { - // Real eigenvalue - if(i == m_n - 1 || m_matT.coeff(i+1, i) == Scalar(0)) - { - m_eivalues.coeffRef(i) = m_matT.coeff(i, i); - ++i; - } - else // Complex eigenvalues - { - Scalar p = Scalar(0.5) * (m_matT.coeff(i, i) - m_matT.coeff(i+1, i+1)); - Scalar z; - // Compute z = sqrt(abs(p * p + m_matT.coeff(i+1, i) * m_matT.coeff(i, i+1))); - // without overflow - { - Scalar t0 = m_matT.coeff(i+1, i); - Scalar t1 = m_matT.coeff(i, i+1); - Scalar maxval = std::max(abs(p), std::max(abs(t0), abs(t1))); - t0 /= maxval; - t1 /= maxval; - Scalar p0 = p / maxval; - z = maxval * sqrt(abs(p0 * p0 + t0 * t1)); - } - m_eivalues.coeffRef(i) = Complex(m_matT.coeff(i+1, i+1) + p, z); - m_eivalues.coeffRef(i+1) = Complex(m_matT.coeff(i+1, i+1) + p, -z); - i += 2; - } - } - - // Compute eigenvectors - doComputeEigenvectors(); - - // Scale eigenvalues back - m_eivalues *= scale; - - m_computed = true; - } - - const ComplexVector& eigenvalues() const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergEigen: need to call compute() first"); - - return m_eivalues; - } - - ComplexMatrix eigenvectors() - { - using std::abs; - - if(!m_computed) - throw std::logic_error("UpperHessenbergEigen: need to call compute() first"); - - Index n = m_eivec.cols(); - ComplexMatrix matV(n, n); - for(Index j = 0; j < n; ++j) - { - // imaginary part of real eigenvalue is already set to exact zero - if(Eigen::numext::imag(m_eivalues.coeff(j)) == Scalar(0) || j + 1 == n) - { - // we have a real eigen value - matV.col(j) = m_eivec.col(j).template cast<Complex>(); - matV.col(j).normalize(); - } else { - // we have a pair of complex eigen values - for(Index i = 0; i < n; ++i) - { - matV.coeffRef(i,j) = Complex(m_eivec.coeff(i,j), m_eivec.coeff(i,j+1)); - matV.coeffRef(i,j+1) = Complex(m_eivec.coeff(i,j), -m_eivec.coeff(i,j+1)); - } - matV.col(j).normalize(); - matV.col(j+1).normalize(); - ++j; - } - } - - return matV; - } -}; - - -} // namespace Spectra - -#endif // UPPER_HESSENBERG_EIGEN_H diff --git a/src/external/Spectra/include/Spectra/LinAlg/UpperHessenbergQR.h b/src/external/Spectra/include/Spectra/LinAlg/UpperHessenbergQR.h deleted file mode 100644 index a66d9598..00000000 --- a/src/external/Spectra/include/Spectra/LinAlg/UpperHessenbergQR.h +++ /dev/null @@ -1,670 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef UPPER_HESSENBERG_QR_H -#define UPPER_HESSENBERG_QR_H - -#include <Eigen/Core> -#include <cmath> // std::sqrt -#include <algorithm> // std::fill, std::copy -#include <stdexcept> // std::logic_error - -namespace Spectra { - - -/// -/// \defgroup Internals Internal Classes -/// -/// Classes for internal use. May be useful to developers. -/// - -/// -/// \ingroup Internals -/// @{ -/// - -/// -/// \defgroup LinearAlgebra Linear Algebra -/// -/// A number of classes for linear algebra operations. -/// - -/// -/// \ingroup LinearAlgebra -/// -/// Perform the QR decomposition of an upper Hessenberg matrix. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// -template <typename Scalar = double> -class UpperHessenbergQR -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Matrix<Scalar, 1, Eigen::Dynamic> RowVector; - typedef Eigen::Array<Scalar, Eigen::Dynamic, 1> Array; - - typedef Eigen::Ref<Matrix> GenericMatrix; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - Matrix m_mat_T; - -protected: - Index m_n; - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - // Q = G1 * G2 * ... * G_{n-1} - Scalar m_shift; - Array m_rot_cos; - Array m_rot_sin; - bool m_computed; - - // Given x and y, compute 1) r = sqrt(x^2 + y^2), 2) c = x / r, 3) s = -y / r - // If both x and y are zero, set c = 1 and s = 0 - // We must implement it in a numerically stable way - static void compute_rotation(const Scalar& x, const Scalar& y, Scalar& r, Scalar& c, Scalar& s) - { - using std::sqrt; - - const Scalar xsign = (x > Scalar(0)) - (x < Scalar(0)); - const Scalar ysign = (y > Scalar(0)) - (y < Scalar(0)); - const Scalar xabs = x * xsign; - const Scalar yabs = y * ysign; - if(xabs > yabs) - { - // In this case xabs != 0 - const Scalar ratio = yabs / xabs; // so that 0 <= ratio < 1 - const Scalar common = sqrt(Scalar(1) + ratio * ratio); - c = xsign / common; - r = xabs * common; - s = -y / r; - } else { - if(yabs == Scalar(0)) - { - r = Scalar(0); c = Scalar(1); s = Scalar(0); - return; - } - const Scalar ratio = xabs / yabs; // so that 0 <= ratio <= 1 - const Scalar common = sqrt(Scalar(1) + ratio * ratio); - s = -ysign / common; - r = yabs * common; - c = x / r; - } - } - -public: - /// - /// Constructor to preallocate memory. Computation can - /// be performed later by calling the compute() method. - /// - UpperHessenbergQR(Index size) : - m_n(size), - m_rot_cos(m_n - 1), - m_rot_sin(m_n - 1), - m_computed(false) - {} - - /// - /// Constructor to create an object that performs and stores the - /// QR decomposition of an upper Hessenberg matrix `mat`, with an - /// optional shift: \f$H-sI=QR\f$. Here \f$H\f$ stands for the matrix - /// `mat`, and \f$s\f$ is the shift. - /// - /// \param mat Matrix type can be `Eigen::Matrix<Scalar, ...>` (e.g. - /// `Eigen::MatrixXd` and `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// Only the upper triangular and the lower subdiagonal parts of - /// the matrix are used. - /// - UpperHessenbergQR(ConstGenericMatrix& mat, const Scalar& shift = Scalar(0)) : - m_n(mat.rows()), - m_shift(shift), - m_rot_cos(m_n - 1), - m_rot_sin(m_n - 1), - m_computed(false) - { - compute(mat, shift); - } - - /// - /// Virtual destructor. - /// - virtual ~UpperHessenbergQR() {}; - - /// - /// Conduct the QR factorization of an upper Hessenberg matrix with - /// an optional shift. - /// - /// \param mat Matrix type can be `Eigen::Matrix<Scalar, ...>` (e.g. - /// `Eigen::MatrixXd` and `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// Only the upper triangular and the lower subdiagonal parts of - /// the matrix are used. - /// - virtual void compute(ConstGenericMatrix& mat, const Scalar& shift = Scalar(0)) - { - m_n = mat.rows(); - if(m_n != mat.cols()) - throw std::invalid_argument("UpperHessenbergQR: matrix must be square"); - - m_shift = shift; - m_mat_T.resize(m_n, m_n); - m_rot_cos.resize(m_n - 1); - m_rot_sin.resize(m_n - 1); - - // Make a copy of mat - s * I - std::copy(mat.data(), mat.data() + mat.size(), m_mat_T.data()); - m_mat_T.diagonal().array() -= m_shift; - - Scalar xi, xj, r, c, s; - Scalar *Tii, *ptr; - const Index n1 = m_n - 1; - for(Index i = 0; i < n1; i++) - { - Tii = &m_mat_T.coeffRef(i, i); - - // Make sure mat_T is upper Hessenberg - // Zero the elements below mat_T(i + 1, i) - std::fill(Tii + 2, Tii + m_n - i, Scalar(0)); - - xi = Tii[0]; // mat_T(i, i) - xj = Tii[1]; // mat_T(i + 1, i) - compute_rotation(xi, xj, r, c, s); - m_rot_cos[i] = c; - m_rot_sin[i] = s; - - // For a complete QR decomposition, - // we first obtain the rotation matrix - // G = [ cos sin] - // [-sin cos] - // and then do T[i:(i + 1), i:(n - 1)] = G' * T[i:(i + 1), i:(n - 1)] - - // Gt << c, -s, s, c; - // m_mat_T.block(i, i, 2, m_n - i) = Gt * m_mat_T.block(i, i, 2, m_n - i); - Tii[0] = r; // m_mat_T(i, i) => r - Tii[1] = 0; // m_mat_T(i + 1, i) => 0 - ptr = Tii + m_n; // m_mat_T(i, k), k = i+1, i+2, ..., n-1 - for(Index j = i + 1; j < m_n; j++, ptr += m_n) - { - Scalar tmp = ptr[0]; - ptr[0] = c * tmp - s * ptr[1]; - ptr[1] = s * tmp + c * ptr[1]; - } - - // If we do not need to calculate the R matrix, then - // only the cos and sin sequences are required. - // In such case we only update T[i + 1, (i + 1):(n - 1)] - // m_mat_T.block(i + 1, i + 1, 1, m_n - i - 1) *= c; - // m_mat_T.block(i + 1, i + 1, 1, m_n - i - 1) += s * mat_T.block(i, i + 1, 1, m_n - i - 1); - } - - m_computed = true; - } - - /// - /// Return the \f$R\f$ matrix in the QR decomposition, which is an - /// upper triangular matrix. - /// - /// \return Returned matrix type will be `Eigen::Matrix<Scalar, ...>`, depending on - /// the template parameter `Scalar` defined. - /// - virtual Matrix matrix_R() const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergQR: need to call compute() first"); - - return m_mat_T; - } - - /// - /// Overwrite `dest` with \f$Q'HQ = RQ + sI\f$, where \f$H\f$ is the input matrix `mat`, - /// and \f$s\f$ is the shift. The result is an upper Hessenberg matrix. - /// - /// \param mat The matrix to be overwritten, whose type should be `Eigen::Matrix<Scalar, ...>`, - /// depending on the template parameter `Scalar` defined. - /// - virtual void matrix_QtHQ(Matrix& dest) const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergQR: need to call compute() first"); - - // Make a copy of the R matrix - dest.resize(m_n, m_n); - std::copy(m_mat_T.data(), m_mat_T.data() + m_mat_T.size(), dest.data()); - - // Compute the RQ matrix - const Index n1 = m_n - 1; - for(Index i = 0; i < n1; i++) - { - const Scalar c = m_rot_cos.coeff(i); - const Scalar s = m_rot_sin.coeff(i); - // RQ[, i:(i + 1)] = RQ[, i:(i + 1)] * Gi - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - Scalar *Yi, *Yi1; - Yi = &dest.coeffRef(0, i); - Yi1 = Yi + m_n; // RQ(0, i + 1) - const Index i2 = i + 2; - for(Index j = 0; j < i2; j++) - { - const Scalar tmp = Yi[j]; - Yi[j] = c * tmp - s * Yi1[j]; - Yi1[j] = s * tmp + c * Yi1[j]; - } - - /* Vector dest = RQ.block(0, i, i + 2, 1); - dest.block(0, i, i + 2, 1) = c * Yi - s * dest.block(0, i + 1, i + 2, 1); - dest.block(0, i + 1, i + 2, 1) = s * Yi + c * dest.block(0, i + 1, i + 2, 1); */ - } - - // Add the shift to the diagonal - dest.diagonal().array() += m_shift; - } - - /// - /// Apply the \f$Q\f$ matrix to a vector \f$y\f$. - /// - /// \param Y A vector that will be overwritten by the matrix product \f$Qy\f$. - /// - /// Vector type can be `Eigen::Vector<Scalar, ...>`, depending on - /// the template parameter `Scalar` defined. - /// - // Y -> QY = G1 * G2 * ... * Y - void apply_QY(Vector& Y) const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergQR: need to call compute() first"); - - for(Index i = m_n - 2; i >= 0; i--) - { - const Scalar c = m_rot_cos.coeff(i); - const Scalar s = m_rot_sin.coeff(i); - // Y[i:(i + 1)] = Gi * Y[i:(i + 1)] - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - const Scalar tmp = Y[i]; - Y[i] = c * tmp + s * Y[i + 1]; - Y[i + 1] = -s * tmp + c * Y[i + 1]; - } - } - - /// - /// Apply the \f$Q\f$ matrix to a vector \f$y\f$. - /// - /// \param Y A vector that will be overwritten by the matrix product \f$Q'y\f$. - /// - /// Vector type can be `Eigen::Vector<Scalar, ...>`, depending on - /// the template parameter `Scalar` defined. - /// - // Y -> Q'Y = G_{n-1}' * ... * G2' * G1' * Y - void apply_QtY(Vector& Y) const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergQR: need to call compute() first"); - - const Index n1 = m_n - 1; - for(Index i = 0; i < n1; i++) - { - const Scalar c = m_rot_cos.coeff(i); - const Scalar s = m_rot_sin.coeff(i); - // Y[i:(i + 1)] = Gi' * Y[i:(i + 1)] - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - const Scalar tmp = Y[i]; - Y[i] = c * tmp - s * Y[i + 1]; - Y[i + 1] = s * tmp + c * Y[i + 1]; - } - } - - /// - /// Apply the \f$Q\f$ matrix to another matrix \f$Y\f$. - /// - /// \param Y A matrix that will be overwritten by the matrix product \f$QY\f$. - /// - /// Matrix type can be `Eigen::Matrix<Scalar, ...>` (e.g. - /// `Eigen::MatrixXd` and `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - // Y -> QY = G1 * G2 * ... * Y - void apply_QY(GenericMatrix Y) const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergQR: need to call compute() first"); - - RowVector Yi(Y.cols()), Yi1(Y.cols()); - for(Index i = m_n - 2; i >= 0; i--) - { - const Scalar c = m_rot_cos.coeff(i); - const Scalar s = m_rot_sin.coeff(i); - // Y[i:(i + 1), ] = Gi * Y[i:(i + 1), ] - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - Yi.noalias() = Y.row(i); - Yi1.noalias() = Y.row(i + 1); - Y.row(i) = c * Yi + s * Yi1; - Y.row(i + 1) = -s * Yi + c * Yi1; - } - } - - /// - /// Apply the \f$Q\f$ matrix to another matrix \f$Y\f$. - /// - /// \param Y A matrix that will be overwritten by the matrix product \f$Q'Y\f$. - /// - /// Matrix type can be `Eigen::Matrix<Scalar, ...>` (e.g. - /// `Eigen::MatrixXd` and `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - // Y -> Q'Y = G_{n-1}' * ... * G2' * G1' * Y - void apply_QtY(GenericMatrix Y) const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergQR: need to call compute() first"); - - RowVector Yi(Y.cols()), Yi1(Y.cols()); - const Index n1 = m_n - 1; - for(Index i = 0; i < n1; i++) - { - const Scalar c = m_rot_cos.coeff(i); - const Scalar s = m_rot_sin.coeff(i); - // Y[i:(i + 1), ] = Gi' * Y[i:(i + 1), ] - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - Yi.noalias() = Y.row(i); - Yi1.noalias() = Y.row(i + 1); - Y.row(i) = c * Yi - s * Yi1; - Y.row(i + 1) = s * Yi + c * Yi1; - } - } - - /// - /// Apply the \f$Q\f$ matrix to another matrix \f$Y\f$. - /// - /// \param Y A matrix that will be overwritten by the matrix product \f$YQ\f$. - /// - /// Matrix type can be `Eigen::Matrix<Scalar, ...>` (e.g. - /// `Eigen::MatrixXd` and `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - // Y -> YQ = Y * G1 * G2 * ... - void apply_YQ(GenericMatrix Y) const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergQR: need to call compute() first"); - - /*Vector Yi(Y.rows()); - for(Index i = 0; i < m_n - 1; i++) - { - const Scalar c = m_rot_cos.coeff(i); - const Scalar s = m_rot_sin.coeff(i); - // Y[, i:(i + 1)] = Y[, i:(i + 1)] * Gi - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - Yi.noalias() = Y.col(i); - Y.col(i) = c * Yi - s * Y.col(i + 1); - Y.col(i + 1) = s * Yi + c * Y.col(i + 1); - }*/ - Scalar *Y_col_i, *Y_col_i1; - const Index n1 = m_n - 1; - const Index nrow = Y.rows(); - for(Index i = 0; i < n1; i++) - { - const Scalar c = m_rot_cos.coeff(i); - const Scalar s = m_rot_sin.coeff(i); - - Y_col_i = &Y.coeffRef(0, i); - Y_col_i1 = &Y.coeffRef(0, i + 1); - for(Index j = 0; j < nrow; j++) - { - Scalar tmp = Y_col_i[j]; - Y_col_i[j] = c * tmp - s * Y_col_i1[j]; - Y_col_i1[j] = s * tmp + c * Y_col_i1[j]; - } - } - } - - /// - /// Apply the \f$Q\f$ matrix to another matrix \f$Y\f$. - /// - /// \param Y A matrix that will be overwritten by the matrix product \f$YQ'\f$. - /// - /// Matrix type can be `Eigen::Matrix<Scalar, ...>` (e.g. - /// `Eigen::MatrixXd` and `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - // Y -> YQ' = Y * G_{n-1}' * ... * G2' * G1' - void apply_YQt(GenericMatrix Y) const - { - if(!m_computed) - throw std::logic_error("UpperHessenbergQR: need to call compute() first"); - - Vector Yi(Y.rows()); - for(Index i = m_n - 2; i >= 0; i--) - { - const Scalar c = m_rot_cos.coeff(i); - const Scalar s = m_rot_sin.coeff(i); - // Y[, i:(i + 1)] = Y[, i:(i + 1)] * Gi' - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - Yi.noalias() = Y.col(i); - Y.col(i) = c * Yi + s * Y.col(i + 1); - Y.col(i + 1) = -s * Yi + c * Y.col(i + 1); - } - } -}; - - - -/// -/// \ingroup LinearAlgebra -/// -/// Perform the QR decomposition of a tridiagonal matrix, a special -/// case of upper Hessenberg matrices. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// -template <typename Scalar = double> -class TridiagQR: public UpperHessenbergQR<Scalar> -{ -private: - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - typedef typename Matrix::Index Index; - - Vector m_T_diag; // diagonal elements of T - Vector m_T_lsub; // lower subdiagonal of T - Vector m_T_usub; // upper subdiagonal of T - Vector m_T_usub2; // 2nd upper subdiagonal of T - -public: - /// - /// Constructor to preallocate memory. Computation can - /// be performed later by calling the compute() method. - /// - TridiagQR(Index size) : - UpperHessenbergQR<Scalar>(size) - {} - - /// - /// Constructor to create an object that performs and stores the - /// QR decomposition of an upper Hessenberg matrix `mat`, with an - /// optional shift: \f$H-sI=QR\f$. Here \f$H\f$ stands for the matrix - /// `mat`, and \f$s\f$ is the shift. - /// - /// \param mat Matrix type can be `Eigen::Matrix<Scalar, ...>` (e.g. - /// `Eigen::MatrixXd` and `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// Only the major- and sub- diagonal parts of - /// the matrix are used. - /// - TridiagQR(ConstGenericMatrix& mat, const Scalar& shift = Scalar(0)) : - UpperHessenbergQR<Scalar>(mat.rows()) - { - this->compute(mat, shift); - } - - /// - /// Conduct the QR factorization of a tridiagonal matrix with an - /// optional shift. - /// - /// \param mat Matrix type can be `Eigen::Matrix<Scalar, ...>` (e.g. - /// `Eigen::MatrixXd` and `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// Only the major- and sub- diagonal parts of - /// the matrix are used. - /// - void compute(ConstGenericMatrix& mat, const Scalar& shift = Scalar(0)) - { - this->m_n = mat.rows(); - if(this->m_n != mat.cols()) - throw std::invalid_argument("TridiagQR: matrix must be square"); - - this->m_shift = shift; - m_T_diag.resize(this->m_n); - m_T_lsub.resize(this->m_n - 1); - m_T_usub.resize(this->m_n - 1); - m_T_usub2.resize(this->m_n - 2); - this->m_rot_cos.resize(this->m_n - 1); - this->m_rot_sin.resize(this->m_n - 1); - - m_T_diag.array() = mat.diagonal().array() - this->m_shift; - m_T_lsub.noalias() = mat.diagonal(-1); - m_T_usub.noalias() = m_T_lsub; - - // A number of pointers to avoid repeated address calculation - Scalar *c = this->m_rot_cos.data(), // pointer to the cosine vector - *s = this->m_rot_sin.data(), // pointer to the sine vector - r; - const Index n1 = this->m_n - 1; - for(Index i = 0; i < n1; i++) - { - // diag[i] == T[i, i] - // lsub[i] == T[i + 1, i] - // r = sqrt(T[i, i]^2 + T[i + 1, i]^2) - // c = T[i, i] / r, s = -T[i + 1, i] / r - this->compute_rotation(m_T_diag.coeff(i), m_T_lsub.coeff(i), r, *c, *s); - - // For a complete QR decomposition, - // we first obtain the rotation matrix - // G = [ cos sin] - // [-sin cos] - // and then do T[i:(i + 1), i:(i + 2)] = G' * T[i:(i + 1), i:(i + 2)] - - // Update T[i, i] and T[i + 1, i] - // The updated value of T[i, i] is known to be r - // The updated value of T[i + 1, i] is known to be 0 - m_T_diag.coeffRef(i) = r; - m_T_lsub.coeffRef(i) = Scalar(0); - // Update T[i, i + 1] and T[i + 1, i + 1] - // usub[i] == T[i, i + 1] - // diag[i + 1] == T[i + 1, i + 1] - const Scalar tmp = m_T_usub.coeff(i); - m_T_usub.coeffRef(i) = (*c) * tmp - (*s) * m_T_diag.coeff(i + 1); - m_T_diag.coeffRef(i + 1) = (*s) * tmp + (*c) * m_T_diag.coeff(i + 1); - // Update T[i, i + 2] and T[i + 1, i + 2] - // usub2[i] == T[i, i + 2] - // usub[i + 1] == T[i + 1, i + 2] - if(i < n1 - 1) - { - m_T_usub2.coeffRef(i) = -(*s) * m_T_usub.coeff(i + 1); - m_T_usub.coeffRef(i + 1) *= (*c); - } - - c++; - s++; - - // If we do not need to calculate the R matrix, then - // only the cos and sin sequences are required. - // In such case we only update T[i + 1, (i + 1):(i + 2)] - // T[i + 1, i + 1] = c * T[i + 1, i + 1] + s * T[i, i + 1]; - // T[i + 1, i + 2] *= c; - } - - this->m_computed = true; - } - - /// - /// Return the \f$R\f$ matrix in the QR decomposition, which is an - /// upper triangular matrix. - /// - /// \return Returned matrix type will be `Eigen::Matrix<Scalar, ...>`, depending on - /// the template parameter `Scalar` defined. - /// - Matrix matrix_R() const - { - if(!this->m_computed) - throw std::logic_error("TridiagQR: need to call compute() first"); - - Matrix R = Matrix::Zero(this->m_n, this->m_n); - R.diagonal().noalias() = m_T_diag; - R.diagonal(1).noalias() = m_T_usub; - R.diagonal(2).noalias() = m_T_usub2; - - return R; - } - - /// - /// Overwrite `dest` with \f$Q'HQ = RQ + sI\f$, where \f$H\f$ is the input matrix `mat`, - /// and \f$s\f$ is the shift. The result is a tridiagonal matrix. - /// - /// \param mat The matrix to be overwritten, whose type should be `Eigen::Matrix<Scalar, ...>`, - /// depending on the template parameter `Scalar` defined. - /// - void matrix_QtHQ(Matrix& dest) const - { - if(!this->m_computed) - throw std::logic_error("TridiagQR: need to call compute() first"); - - // Make a copy of the R matrix - dest.resize(this->m_n, this->m_n); - dest.setZero(); - dest.diagonal().noalias() = m_T_diag; - // The upper diagonal refers to m_T_usub - // The 2nd upper subdiagonal will be zero in RQ - - // Compute the RQ matrix - // [m11 m12] points to RQ[i:(i+1), i:(i+1)] - // [0 m22] - // - // Gi = [ cos[i] sin[i]] - // [-sin[i] cos[i]] - const Index n1 = this->m_n - 1; - for(Index i = 0; i < n1; i++) - { - const Scalar c = this->m_rot_cos.coeff(i); - const Scalar s = this->m_rot_sin.coeff(i); - const Scalar m11 = dest.coeff(i, i), - m12 = m_T_usub.coeff(i), - m22 = m_T_diag.coeff(i + 1); - - // Update the diagonal and the lower subdiagonal of dest - dest.coeffRef(i , i ) = c * m11 - s * m12; - dest.coeffRef(i + 1, i ) = - s * m22; - dest.coeffRef(i + 1, i + 1) = c * m22; - } - - // Copy the lower subdiagonal to upper subdiagonal - dest.diagonal(1).noalias() = dest.diagonal(-1); - - // Add the shift to the diagonal - dest.diagonal().array() += this->m_shift; - } -}; - -/// -/// @} -/// - - -} // namespace Spectra - -#endif // UPPER_HESSENBERG_QR_H diff --git a/src/external/Spectra/include/Spectra/MatOp/DenseCholesky.h b/src/external/Spectra/include/Spectra/MatOp/DenseCholesky.h deleted file mode 100644 index 354c9508..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/DenseCholesky.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef DENSE_CHOLESKY_H -#define DENSE_CHOLESKY_H - -#include <Eigen/Core> -#include <Eigen/Cholesky> -#include <stdexcept> -#include "../Util/CompInfo.h" - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the operations related to Cholesky decomposition on a -/// positive definite matrix, \f$B=LL'\f$, where \f$L\f$ is a lower triangular -/// matrix. It is mainly used in the SymGEigsSolver generalized eigen solver -/// in the Cholesky decomposition mode. -/// -template <typename Scalar, int Uplo = Eigen::Lower> -class DenseCholesky -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Matrix> MapConstMat; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - const Index m_n; - Eigen::LLT<Matrix, Uplo> m_decomp; - int m_info; // status of the decomposition - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** matrix object, whose type can be - /// `Eigen::Matrix<Scalar, ...>` (e.g. `Eigen::MatrixXd` and - /// `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - DenseCholesky(ConstGenericMatrix& mat) : - m_n(mat.rows()), m_info(NOT_COMPUTED) - { - if(mat.rows() != mat.cols()) - throw std::invalid_argument("DenseCholesky: matrix must be square"); - - m_decomp.compute(mat); - m_info = (m_decomp.info() == Eigen::Success) ? - SUCCESSFUL : - NUMERICAL_ISSUE; - } - - /// - /// Returns the number of rows of the underlying matrix. - /// - Index rows() const { return m_n; } - /// - /// Returns the number of columns of the underlying matrix. - /// - Index cols() const { return m_n; } - - /// - /// Returns the status of the computation. - /// The full list of enumeration values can be found in \ref Enumerations. - /// - int info() const { return m_info; } - - /// - /// Performs the lower triangular solving operation \f$y=L^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(L) * x_in - void lower_triangular_solve(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_decomp.matrixL().solve(x); - } - - /// - /// Performs the upper triangular solving operation \f$y=(L')^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(L') * x_in - void upper_triangular_solve(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_decomp.matrixU().solve(x); - } -}; - - -} // namespace Spectra - -#endif // DENSE_CHOLESKY_H diff --git a/src/external/Spectra/include/Spectra/MatOp/DenseGenComplexShiftSolve.h b/src/external/Spectra/include/Spectra/MatOp/DenseGenComplexShiftSolve.h deleted file mode 100644 index 7f189067..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/DenseGenComplexShiftSolve.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef DENSE_GEN_COMPLEX_SHIFT_SOLVE_H -#define DENSE_GEN_COMPLEX_SHIFT_SOLVE_H - -#include <Eigen/Core> -#include <Eigen/LU> -#include <stdexcept> - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the complex shift-solve operation on a general real matrix \f$A\f$, -/// i.e., calculating \f$y=\mathrm{Re}\{(A-\sigma I)^{-1}x\}\f$ for any complex-valued -/// \f$\sigma\f$ and real-valued vector \f$x\f$. It is mainly used in the -/// GenEigsComplexShiftSolver eigen solver. -/// -template <typename Scalar> -class DenseGenComplexShiftSolve -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - typedef std::complex<Scalar> Complex; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic> ComplexMatrix; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> ComplexVector; - - typedef Eigen::PartialPivLU<ComplexMatrix> ComplexSolver; - - ConstGenericMatrix m_mat; - const Index m_n; - ComplexSolver m_solver; - ComplexVector m_x_cache; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** matrix object, whose type can be - /// `Eigen::Matrix<Scalar, ...>` (e.g. `Eigen::MatrixXd` and - /// `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - DenseGenComplexShiftSolve(ConstGenericMatrix& mat) : - m_mat(mat), m_n(mat.rows()) - { - if(mat.rows() != mat.cols()) - throw std::invalid_argument("DenseGenComplexShiftSolve: matrix must be square"); - } - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_n; } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_n; } - - /// - /// Set the complex shift \f$\sigma\f$. - /// - /// \param sigmar Real part of \f$\sigma\f$. - /// \param sigmai Imaginary part of \f$\sigma\f$. - /// - void set_shift(Scalar sigmar, Scalar sigmai) - { - m_solver.compute(m_mat.template cast<Complex>() - Complex(sigmar, sigmai) * ComplexMatrix::Identity(m_n, m_n)); - m_x_cache.resize(m_n); - m_x_cache.setZero(); - } - - /// - /// Perform the complex shift-solve operation - /// \f$y=\mathrm{Re}\{(A-\sigma I)^{-1}x\}\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = Re( inv(A - sigma * I) * x_in ) - void perform_op(const Scalar* x_in, Scalar* y_out) - { - m_x_cache.real() = MapConstVec(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_solver.solve(m_x_cache).real(); - } -}; - - -} // namespace Spectra - -#endif // DENSE_GEN_COMPLEX_SHIFT_SOLVE_H diff --git a/src/external/Spectra/include/Spectra/MatOp/DenseGenMatProd.h b/src/external/Spectra/include/Spectra/MatOp/DenseGenMatProd.h deleted file mode 100644 index 6933dac0..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/DenseGenMatProd.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef DENSE_GEN_MAT_PROD_H -#define DENSE_GEN_MAT_PROD_H - -#include <Eigen/Core> - -namespace Spectra { - - -/// -/// \defgroup MatOp Matrix Operations -/// -/// Define matrix operations on existing matrix objects -/// - -/// -/// \ingroup MatOp -/// -/// This class defines the matrix-vector multiplication operation on a -/// general real matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector -/// \f$x\f$. It is mainly used in the GenEigsSolver and -/// SymEigsSolver eigen solvers. -/// -template <typename Scalar> -class DenseGenMatProd -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - ConstGenericMatrix m_mat; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** matrix object, whose type can be - /// `Eigen::Matrix<Scalar, ...>` (e.g. `Eigen::MatrixXd` and - /// `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - DenseGenMatProd(ConstGenericMatrix& mat) : - m_mat(mat) - {} - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_mat.rows(); } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_mat.cols(); } - - /// - /// Perform the matrix-vector multiplication operation \f$y=Ax\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = A * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_mat.cols()); - MapVec y(y_out, m_mat.rows()); - y.noalias() = m_mat * x; - } -}; - - -} // namespace Spectra - -#endif // DENSE_GEN_MAT_PROD_H diff --git a/src/external/Spectra/include/Spectra/MatOp/DenseGenRealShiftSolve.h b/src/external/Spectra/include/Spectra/MatOp/DenseGenRealShiftSolve.h deleted file mode 100644 index d7ba8f2a..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/DenseGenRealShiftSolve.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef DENSE_GEN_REAL_SHIFT_SOLVE_H -#define DENSE_GEN_REAL_SHIFT_SOLVE_H - -#include <Eigen/Core> -#include <Eigen/LU> -#include <stdexcept> - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the shift-solve operation on a general real matrix \f$A\f$, -/// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and -/// vector \f$x\f$. It is mainly used in the GenEigsRealShiftSolver eigen solver. -/// -template <typename Scalar> -class DenseGenRealShiftSolve -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - ConstGenericMatrix m_mat; - const Index m_n; - Eigen::PartialPivLU<Matrix> m_solver; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** matrix object, whose type can be - /// `Eigen::Matrix<Scalar, ...>` (e.g. `Eigen::MatrixXd` and - /// `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - DenseGenRealShiftSolve(ConstGenericMatrix& mat) : - m_mat(mat), m_n(mat.rows()) - { - if(mat.rows() != mat.cols()) - throw std::invalid_argument("DenseGenRealShiftSolve: matrix must be square"); - } - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_n; } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_n; } - - /// - /// Set the real shift \f$\sigma\f$. - /// - void set_shift(Scalar sigma) - { - m_solver.compute(m_mat - sigma * Matrix::Identity(m_n, m_n)); - } - - /// - /// Perform the shift-solve operation \f$y=(A-\sigma I)^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(A - sigma * I) * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_solver.solve(x); - } -}; - - -} // namespace Spectra - -#endif // DENSE_GEN_REAL_SHIFT_SOLVE_H diff --git a/src/external/Spectra/include/Spectra/MatOp/DenseSymMatProd.h b/src/external/Spectra/include/Spectra/MatOp/DenseSymMatProd.h deleted file mode 100644 index 23ca36e4..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/DenseSymMatProd.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef DENSE_SYM_MAT_PROD_H -#define DENSE_SYM_MAT_PROD_H - -#include <Eigen/Core> - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the matrix-vector multiplication operation on a -/// symmetric real matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector -/// \f$x\f$. It is mainly used in the SymEigsSolver eigen solver. -/// -template <typename Scalar, int Uplo = Eigen::Lower> -class DenseSymMatProd -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - ConstGenericMatrix m_mat; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** matrix object, whose type can be - /// `Eigen::Matrix<Scalar, ...>` (e.g. `Eigen::MatrixXd` and - /// `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - DenseSymMatProd(ConstGenericMatrix& mat) : - m_mat(mat) - {} - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_mat.rows(); } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_mat.cols(); } - - /// - /// Perform the matrix-vector multiplication operation \f$y=Ax\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = A * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_mat.cols()); - MapVec y(y_out, m_mat.rows()); - y.noalias() = m_mat.template selfadjointView<Uplo>() * x; - } -}; - - -} // namespace Spectra - -#endif // DENSE_SYM_MAT_PROD_H diff --git a/src/external/Spectra/include/Spectra/MatOp/DenseSymShiftSolve.h b/src/external/Spectra/include/Spectra/MatOp/DenseSymShiftSolve.h deleted file mode 100644 index 2e2c67f6..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/DenseSymShiftSolve.h +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef DENSE_SYM_SHIFT_SOLVE_H -#define DENSE_SYM_SHIFT_SOLVE_H - -#include <Eigen/Core> -#include <stdexcept> - -#include "../LinAlg/BKLDLT.h" -#include "../Util/CompInfo.h" - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the shift-solve operation on a real symmetric matrix \f$A\f$, -/// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and -/// vector \f$x\f$. It is mainly used in the SymEigsShiftSolver eigen solver. -/// -template <typename Scalar, int Uplo = Eigen::Lower> -class DenseSymShiftSolve -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef const Eigen::Ref<const Matrix> ConstGenericMatrix; - - ConstGenericMatrix m_mat; - const int m_n; - BKLDLT<Scalar> m_solver; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** matrix object, whose type can be - /// `Eigen::Matrix<Scalar, ...>` (e.g. `Eigen::MatrixXd` and - /// `Eigen::MatrixXf`), or its mapped version - /// (e.g. `Eigen::Map<Eigen::MatrixXd>`). - /// - DenseSymShiftSolve(ConstGenericMatrix& mat) : - m_mat(mat), m_n(mat.rows()) - { - if(mat.rows() != mat.cols()) - throw std::invalid_argument("DenseSymShiftSolve: matrix must be square"); - } - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_n; } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_n; } - - /// - /// Set the real shift \f$\sigma\f$. - /// - void set_shift(Scalar sigma) - { - m_solver.compute(m_mat, Uplo, sigma); - if(m_solver.info() != SUCCESSFUL) - throw std::invalid_argument("DenseSymShiftSolve: factorization failed with the given shift"); - } - - /// - /// Perform the shift-solve operation \f$y=(A-\sigma I)^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(A - sigma * I) * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_solver.solve(x); - } -}; - - -} // namespace Spectra - -#endif // DENSE_SYM_SHIFT_SOLVE_H diff --git a/src/external/Spectra/include/Spectra/MatOp/SparseCholesky.h b/src/external/Spectra/include/Spectra/MatOp/SparseCholesky.h deleted file mode 100644 index 0788596d..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/SparseCholesky.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SPARSE_CHOLESKY_H -#define SPARSE_CHOLESKY_H - -#include <Eigen/Core> -#include <Eigen/SparseCore> -#include <Eigen/SparseCholesky> -#include <stdexcept> -#include "../Util/CompInfo.h" - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the operations related to Cholesky decomposition on a -/// sparse positive definite matrix, \f$B=LL'\f$, where \f$L\f$ is a lower triangular -/// matrix. It is mainly used in the SymGEigsSolver generalized eigen solver -/// in the Cholesky decomposition mode. -/// -template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename StorageIndex = int> -class SparseCholesky -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix; - typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix; - - const Index m_n; - Eigen::SimplicialLLT<SparseMatrix, Uplo> m_decomp; - int m_info; // status of the decomposition - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** sparse matrix object, whose type can be - /// `Eigen::SparseMatrix<Scalar, ...>` or its mapped version - /// `Eigen::Map<Eigen::SparseMatrix<Scalar, ...> >`. - /// - SparseCholesky(ConstGenericSparseMatrix& mat) : - m_n(mat.rows()) - { - if(mat.rows() != mat.cols()) - throw std::invalid_argument("SparseCholesky: matrix must be square"); - - m_decomp.compute(mat); - m_info = (m_decomp.info() == Eigen::Success) ? - SUCCESSFUL : - NUMERICAL_ISSUE; - } - - /// - /// Returns the number of rows of the underlying matrix. - /// - Index rows() const { return m_n; } - /// - /// Returns the number of columns of the underlying matrix. - /// - Index cols() const { return m_n; } - - /// - /// Returns the status of the computation. - /// The full list of enumeration values can be found in \ref Enumerations. - /// - int info() const { return m_info; } - - /// - /// Performs the lower triangular solving operation \f$y=L^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(L) * x_in - void lower_triangular_solve(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_decomp.permutationP() * x; - m_decomp.matrixL().solveInPlace(y); - } - - /// - /// Performs the upper triangular solving operation \f$y=(L')^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(L') * x_in - void upper_triangular_solve(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_decomp.matrixU().solve(x); - y = m_decomp.permutationPinv() * y; - } -}; - - -} // namespace Spectra - -#endif // SPARSE_CHOLESKY_H diff --git a/src/external/Spectra/include/Spectra/MatOp/SparseGenMatProd.h b/src/external/Spectra/include/Spectra/MatOp/SparseGenMatProd.h deleted file mode 100644 index 90881395..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/SparseGenMatProd.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SPARSE_GEN_MAT_PROD_H -#define SPARSE_GEN_MAT_PROD_H - -#include <Eigen/Core> -#include <Eigen/SparseCore> - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the matrix-vector multiplication operation on a -/// sparse real matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector -/// \f$x\f$. It is mainly used in the GenEigsSolver and SymEigsSolver -/// eigen solvers. -/// -template <typename Scalar, int Flags = 0, typename StorageIndex = int> -class SparseGenMatProd -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix; - typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix; - - ConstGenericSparseMatrix m_mat; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** sparse matrix object, whose type can be - /// `Eigen::SparseMatrix<Scalar, ...>` or its mapped version - /// `Eigen::Map<Eigen::SparseMatrix<Scalar, ...> >`. - /// - SparseGenMatProd(ConstGenericSparseMatrix& mat) : - m_mat(mat) - {} - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_mat.rows(); } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_mat.cols(); } - - /// - /// Perform the matrix-vector multiplication operation \f$y=Ax\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = A * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_mat.cols()); - MapVec y(y_out, m_mat.rows()); - y.noalias() = m_mat * x; - } -}; - - -} // namespace Spectra - -#endif // SPARSE_GEN_MAT_PROD_H diff --git a/src/external/Spectra/include/Spectra/MatOp/SparseGenRealShiftSolve.h b/src/external/Spectra/include/Spectra/MatOp/SparseGenRealShiftSolve.h deleted file mode 100644 index df4ec6cf..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/SparseGenRealShiftSolve.h +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SPARSE_GEN_REAL_SHIFT_SOLVE_H -#define SPARSE_GEN_REAL_SHIFT_SOLVE_H - -#include <Eigen/Core> -#include <Eigen/SparseCore> -#include <Eigen/SparseLU> -#include <stdexcept> - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the shift-solve operation on a sparse real matrix \f$A\f$, -/// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and -/// vector \f$x\f$. It is mainly used in the GenEigsRealShiftSolver eigen solver. -/// -template <typename Scalar,int Flags = 0, typename StorageIndex = int> -class SparseGenRealShiftSolve -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix; - typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix; - - ConstGenericSparseMatrix m_mat; - const int m_n; - Eigen::SparseLU<SparseMatrix> m_solver; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** sparse matrix object, whose type can be - /// `Eigen::SparseMatrix<Scalar, ...>` or its mapped version - /// `Eigen::Map<Eigen::SparseMatrix<Scalar, ...> >`. - /// - SparseGenRealShiftSolve(ConstGenericSparseMatrix& mat) : - m_mat(mat), m_n(mat.rows()) - { - if(mat.rows() != mat.cols()) - throw std::invalid_argument("SparseGenRealShiftSolve: matrix must be square"); - } - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_n; } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_n; } - - /// - /// Set the real shift \f$\sigma\f$. - /// - void set_shift(Scalar sigma) - { - SparseMatrix I(m_n, m_n); - I.setIdentity(); - - m_solver.compute(m_mat - sigma * I); - if(m_solver.info() != Eigen::Success) - throw std::invalid_argument("SparseGenRealShiftSolve: factorization failed with the given shift"); - } - - /// - /// Perform the shift-solve operation \f$y=(A-\sigma I)^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(A - sigma * I) * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_solver.solve(x); - } -}; - - -} // namespace Spectra - -#endif // SPARSE_GEN_REAL_SHIFT_SOLVE_H diff --git a/src/external/Spectra/include/Spectra/MatOp/SparseRegularInverse.h b/src/external/Spectra/include/Spectra/MatOp/SparseRegularInverse.h deleted file mode 100644 index ec6614a5..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/SparseRegularInverse.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2017-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SPARSE_REGULAR_INVERSE_H -#define SPARSE_REGULAR_INVERSE_H - -#include <Eigen/Core> -#include <Eigen/SparseCore> -#include <Eigen/IterativeLinearSolvers> -#include <stdexcept> - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines matrix operations required by the generalized eigen solver -/// in the regular inverse mode. For a sparse and positive definite matrix \f$B\f$, -/// it implements the matrix-vector product \f$y=Bx\f$ and the linear equation -/// solving operation \f$y=B^{-1}x\f$. -/// -/// This class is intended to be used with the SymGEigsSolver generalized eigen solver -/// in the regular inverse mode. -/// -template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename StorageIndex = int> -class SparseRegularInverse -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix; - typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix; - - ConstGenericSparseMatrix m_mat; - const int m_n; - Eigen::ConjugateGradient<SparseMatrix> m_cg; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** sparse matrix object, whose type can be - /// `Eigen::SparseMatrix<Scalar, ...>` or its mapped version - /// `Eigen::Map<Eigen::SparseMatrix<Scalar, ...> >`. - /// - SparseRegularInverse(ConstGenericSparseMatrix& mat) : - m_mat(mat), m_n(mat.rows()) - { - if(mat.rows() != mat.cols()) - throw std::invalid_argument("SparseRegularInverse: matrix must be square"); - - m_cg.compute(mat); - } - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_n; } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_n; } - - /// - /// Perform the solving operation \f$y=B^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(B) * x_in - void solve(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_cg.solve(x); - } - - /// - /// Perform the matrix-vector multiplication operation \f$y=Bx\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = B * x_in - void mat_prod(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_mat.template selfadjointView<Uplo>() * x; - } -}; - - -} // namespace Spectra - -#endif // SPARSE_REGULAR_INVERSE_H diff --git a/src/external/Spectra/include/Spectra/MatOp/SparseSymMatProd.h b/src/external/Spectra/include/Spectra/MatOp/SparseSymMatProd.h deleted file mode 100644 index ef8f96ee..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/SparseSymMatProd.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SPARSE_SYM_MAT_PROD_H -#define SPARSE_SYM_MAT_PROD_H - -#include <Eigen/Core> -#include <Eigen/SparseCore> - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the matrix-vector multiplication operation on a -/// sparse real symmetric matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector -/// \f$x\f$. It is mainly used in the SymEigsSolver eigen solver. -/// -template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename StorageIndex = int> -class SparseSymMatProd -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix; - typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix; - - ConstGenericSparseMatrix m_mat; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** sparse matrix object, whose type can be - /// `Eigen::SparseMatrix<Scalar, ...>` or its mapped version - /// `Eigen::Map<Eigen::SparseMatrix<Scalar, ...> >`. - /// - SparseSymMatProd(ConstGenericSparseMatrix& mat) : - m_mat(mat) - {} - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_mat.rows(); } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_mat.cols(); } - - /// - /// Perform the matrix-vector multiplication operation \f$y=Ax\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = A * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_mat.cols()); - MapVec y(y_out, m_mat.rows()); - y.noalias() = m_mat.template selfadjointView<Uplo>() * x; - } -}; - - -} // namespace Spectra - -#endif // SPARSE_SYM_MAT_PROD_H diff --git a/src/external/Spectra/include/Spectra/MatOp/SparseSymShiftSolve.h b/src/external/Spectra/include/Spectra/MatOp/SparseSymShiftSolve.h deleted file mode 100644 index 1821cc32..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/SparseSymShiftSolve.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SPARSE_SYM_SHIFT_SOLVE_H -#define SPARSE_SYM_SHIFT_SOLVE_H - -#include <Eigen/Core> -#include <Eigen/SparseCore> -#include <Eigen/SparseLU> -#include <stdexcept> - -namespace Spectra { - - -/// -/// \ingroup MatOp -/// -/// This class defines the shift-solve operation on a sparse real symmetric matrix \f$A\f$, -/// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and -/// vector \f$x\f$. It is mainly used in the SymEigsShiftSolver eigen solver. -/// -template <typename Scalar, int Uplo = Eigen::Lower, int Flags = 0, typename StorageIndex = int> -class SparseSymShiftSolve -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::SparseMatrix<Scalar, Flags, StorageIndex> SparseMatrix; - typedef const Eigen::Ref<const SparseMatrix> ConstGenericSparseMatrix; - - ConstGenericSparseMatrix m_mat; - const int m_n; - Eigen::SparseLU<SparseMatrix> m_solver; - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param mat An **Eigen** sparse matrix object, whose type can be - /// `Eigen::SparseMatrix<Scalar, ...>` or its mapped version - /// `Eigen::Map<Eigen::SparseMatrix<Scalar, ...> >`. - /// - SparseSymShiftSolve(ConstGenericSparseMatrix& mat) : - m_mat(mat), m_n(mat.rows()) - { - if(mat.rows() != mat.cols()) - throw std::invalid_argument("SparseSymShiftSolve: matrix must be square"); - } - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_n; } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_n; } - - /// - /// Set the real shift \f$\sigma\f$. - /// - void set_shift(Scalar sigma) - { - SparseMatrix mat = m_mat.template selfadjointView<Uplo>(); - SparseMatrix identity(m_n, m_n); - identity.setIdentity(); - mat = mat - sigma * identity; - m_solver.isSymmetric(true); - m_solver.compute(mat); - if(m_solver.info() != Eigen::Success) - throw std::invalid_argument("SparseSymShiftSolve: factorization failed with the given shift"); - } - - /// - /// Perform the shift-solve operation \f$y=(A-\sigma I)^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(A - sigma * I) * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) const - { - MapConstVec x(x_in, m_n); - MapVec y(y_out, m_n); - y.noalias() = m_solver.solve(x); - } -}; - - -} // namespace Spectra - -#endif // SPARSE_SYM_SHIFT_SOLVE_H diff --git a/src/external/Spectra/include/Spectra/MatOp/internal/ArnoldiOp.h b/src/external/Spectra/include/Spectra/MatOp/internal/ArnoldiOp.h deleted file mode 100644 index b79704b5..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/internal/ArnoldiOp.h +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (C) 2018-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef ARNOLDI_OP_H -#define ARNOLDI_OP_H - -#include <Eigen/Core> -#include <cmath> // std::sqrt - -namespace Spectra { - - -/// -/// \ingroup Internals -/// @{ -/// - -/// -/// \defgroup Operators Operators -/// -/// Different types of operators. -/// - -/// -/// \ingroup Operators -/// -/// Operators used in the Arnoldi factorization. -/// -template <typename Scalar, typename OpType, typename BOpType> -class ArnoldiOp -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - OpType& m_op; - BOpType& m_Bop; - Vector m_cache; - -public: - ArnoldiOp(OpType* op, BOpType* Bop) : - m_op(*op), m_Bop(*Bop), m_cache(op->rows()) - {} - - inline Index rows() const { return m_op.rows(); } - - // In generalized eigenvalue problem Ax=lambda*Bx, define the inner product to be <x, y> = x'By. - // For regular eigenvalue problems, it is the usual inner product <x, y> = x'y - - // Compute <x, y> = x'By - // x and y are two vectors - template <typename Arg1, typename Arg2> - Scalar inner_product(const Arg1& x, const Arg2& y) - { - m_Bop.mat_prod(y.data(), m_cache.data()); - return x.dot(m_cache); - } - - // Compute res = <X, y> = X'By - // X is a matrix, y is a vector, res is a vector - template <typename Arg1, typename Arg2> - void trans_product(const Arg1& x, const Arg2& y, Eigen::Ref<Vector> res) - { - m_Bop.mat_prod(y.data(), m_cache.data()); - res.noalias() = x.transpose() * m_cache; - } - - // B-norm of a vector, ||x||_B = sqrt(x'Bx) - template <typename Arg> - Scalar norm(const Arg& x) - { - using std::sqrt; - return sqrt(inner_product<Arg, Arg>(x, x)); - } - - // The "A" operator to generate the Krylov subspace - inline void perform_op(const Scalar* x_in, Scalar* y_out) - { - m_op.perform_op(x_in, y_out); - } -}; - - - -/// -/// \ingroup Operators -/// -/// Placeholder for the B-operator when \f$B = I\f$. -/// -class IdentityBOp {}; - - - -/// -/// \ingroup Operators -/// -/// Partial specialization for the case \f$B = I\f$. -/// -template <typename Scalar, typename OpType> -class ArnoldiOp<Scalar, OpType, IdentityBOp> -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - OpType& m_op; - -public: - ArnoldiOp<Scalar, OpType, IdentityBOp>(OpType* op, IdentityBOp* /*Bop*/) : - m_op(*op) - {} - - inline Index rows() const { return m_op.rows(); } - - // Compute <x, y> = x'y - // x and y are two vectors - template <typename Arg1, typename Arg2> - Scalar inner_product(const Arg1& x, const Arg2& y) const - { - return x.dot(y); - } - - // Compute res = <X, y> = X'y - // X is a matrix, y is a vector, res is a vector - template <typename Arg1, typename Arg2> - void trans_product(const Arg1& x, const Arg2& y, Eigen::Ref<Vector> res) const - { - res.noalias() = x.transpose() * y; - } - - // B-norm of a vector. For regular eigenvalue problems it is simply the L2 norm - template <typename Arg> - Scalar norm(const Arg& x) - { - return x.norm(); - } - - // The "A" operator to generate the Krylov subspace - inline void perform_op(Scalar* x_in, Scalar* y_out) - { - m_op.perform_op(x_in, y_out); - } -}; - -/// -/// @} -/// - - -} // namespace Spectra - -#endif // ARNOLDI_OP_H diff --git a/src/external/Spectra/include/Spectra/MatOp/internal/SymGEigsCholeskyOp.h b/src/external/Spectra/include/Spectra/MatOp/internal/SymGEigsCholeskyOp.h deleted file mode 100644 index d7acdb2a..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/internal/SymGEigsCholeskyOp.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SYM_GEIGS_CHOLESKY_OP_H -#define SYM_GEIGS_CHOLESKY_OP_H - -#include <Eigen/Core> -#include "../DenseSymMatProd.h" -#include "../DenseCholesky.h" - -namespace Spectra { - - -/// -/// \ingroup Operators -/// -/// This class defines the matrix operation for generalized eigen solver in the -/// Cholesky decomposition mode. It calculates \f$y=L^{-1}A(L')^{-1}x\f$ for any -/// vector \f$x\f$, where \f$L\f$ is the Cholesky decomposition of \f$B\f$. -/// This class is intended for internal use. -/// -template < typename Scalar = double, - typename OpType = DenseSymMatProd<double>, - typename BOpType = DenseCholesky<double> > -class SymGEigsCholeskyOp -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - OpType& m_op; - BOpType& m_Bop; - Vector m_cache; // temporary working space - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param op Pointer to the \f$A\f$ matrix operation object. - /// \param Bop Pointer to the \f$B\f$ matrix operation object. - /// - SymGEigsCholeskyOp(OpType& op, BOpType& Bop) : - m_op(op), m_Bop(Bop), m_cache(op.rows()) - {} - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_Bop.rows(); } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_Bop.rows(); } - - /// - /// Perform the matrix operation \f$y=L^{-1}A(L')^{-1}x\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(L) * A * inv(L') * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) - { - m_Bop.upper_triangular_solve(x_in, y_out); - m_op.perform_op(y_out, m_cache.data()); - m_Bop.lower_triangular_solve(m_cache.data(), y_out); - } -}; - - -} // namespace Spectra - -#endif // SYM_GEIGS_CHOLESKY_OP_H diff --git a/src/external/Spectra/include/Spectra/MatOp/internal/SymGEigsRegInvOp.h b/src/external/Spectra/include/Spectra/MatOp/internal/SymGEigsRegInvOp.h deleted file mode 100644 index ac00dcb2..00000000 --- a/src/external/Spectra/include/Spectra/MatOp/internal/SymGEigsRegInvOp.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2017-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SYM_GEIGS_REG_INV_OP_H -#define SYM_GEIGS_REG_INV_OP_H - -#include <Eigen/Core> -#include "../SparseSymMatProd.h" -#include "../SparseRegularInverse.h" - -namespace Spectra { - - -/// -/// \ingroup Operators -/// -/// This class defines the matrix operation for generalized eigen solver in the -/// regular inverse mode. This class is intended for internal use. -/// -template < typename Scalar = double, - typename OpType = SparseSymMatProd<double>, - typename BOpType = SparseRegularInverse<double> > -class SymGEigsRegInvOp -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - OpType& m_op; - BOpType& m_Bop; - Vector m_cache; // temporary working space - -public: - /// - /// Constructor to create the matrix operation object. - /// - /// \param op Pointer to the \f$A\f$ matrix operation object. - /// \param Bop Pointer to the \f$B\f$ matrix operation object. - /// - SymGEigsRegInvOp(OpType& op, BOpType& Bop) : - m_op(op), m_Bop(Bop), m_cache(op.rows()) - {} - - /// - /// Return the number of rows of the underlying matrix. - /// - Index rows() const { return m_Bop.rows(); } - /// - /// Return the number of columns of the underlying matrix. - /// - Index cols() const { return m_Bop.rows(); } - - /// - /// Perform the matrix operation \f$y=B^{-1}Ax\f$. - /// - /// \param x_in Pointer to the \f$x\f$ vector. - /// \param y_out Pointer to the \f$y\f$ vector. - /// - // y_out = inv(B) * A * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) - { - m_op.perform_op(x_in, m_cache.data()); - m_Bop.solve(m_cache.data(), y_out); - } -}; - - -} // namespace Spectra - -#endif // SYM_GEIGS_REG_INV_OP_H diff --git a/src/external/Spectra/include/Spectra/SymEigsBase.h b/src/external/Spectra/include/Spectra/SymEigsBase.h deleted file mode 100644 index 24d5b505..00000000 --- a/src/external/Spectra/include/Spectra/SymEigsBase.h +++ /dev/null @@ -1,447 +0,0 @@ -// Copyright (C) 2018-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SYM_EIGS_BASE_H -#define SYM_EIGS_BASE_H - -#include <Eigen/Core> -#include <vector> // std::vector -#include <cmath> // std::abs, std::pow, std::sqrt -#include <algorithm> // std::min, std::copy -#include <stdexcept> // std::invalid_argument - -#include "Util/TypeTraits.h" -#include "Util/SelectionRule.h" -#include "Util/CompInfo.h" -#include "Util/SimpleRandom.h" -#include "MatOp/internal/ArnoldiOp.h" -#include "LinAlg/UpperHessenbergQR.h" -#include "LinAlg/TridiagEigen.h" -#include "LinAlg/Lanczos.h" - -namespace Spectra { - - -/// -/// \defgroup EigenSolver Eigen Solvers -/// -/// Eigen solvers for different types of problems. -/// - -/// -/// \ingroup EigenSolver -/// -/// This is the base class for symmetric eigen solvers, mainly for internal use. -/// It is kept here to provide the documentation for member functions of concrete eigen solvers -/// such as SymEigsSolver and SymEigsShiftSolver. -/// -template < typename Scalar, - int SelectionRule, - typename OpType, - typename BOpType > -class SymEigsBase -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Array<Scalar, Eigen::Dynamic, 1> Array; - typedef Eigen::Array<bool, Eigen::Dynamic, 1> BoolArray; - typedef Eigen::Map<Matrix> MapMat; - typedef Eigen::Map<Vector> MapVec; - typedef Eigen::Map<const Vector> MapConstVec; - - typedef ArnoldiOp<Scalar, OpType, BOpType> ArnoldiOpType; - typedef Lanczos<Scalar, ArnoldiOpType> LanczosFac; - -protected: - OpType* m_op; // object to conduct matrix operation, - // e.g. matrix-vector product - const Index m_n; // dimension of matrix A - const Index m_nev; // number of eigenvalues requested - const Index m_ncv; // dimension of Krylov subspace in the Lanczos method - Index m_nmatop; // number of matrix operations called - Index m_niter; // number of restarting iterations - - LanczosFac m_fac; // Lanczos factorization - Vector m_ritz_val; // Ritz values - -private: - Matrix m_ritz_vec; // Ritz vectors - Vector m_ritz_est; // last row of m_ritz_vec, also called the Ritz estimates - BoolArray m_ritz_conv; // indicator of the convergence of Ritz values - int m_info; // status of the computation - - const Scalar m_near_0; // a very small value, but 1.0 / m_near_0 does not overflow - // ~= 1e-307 for the "double" type - const Scalar m_eps; // the machine precision, ~= 1e-16 for the "double" type - const Scalar m_eps23; // m_eps^(2/3), used to test the convergence - - // Implicitly restarted Lanczos factorization - void restart(Index k) - { - if(k >= m_ncv) - return; - - TridiagQR<Scalar> decomp(m_ncv); - Matrix Q = Matrix::Identity(m_ncv, m_ncv); - - for(Index i = k; i < m_ncv; i++) - { - // QR decomposition of H-mu*I, mu is the shift - decomp.compute(m_fac.matrix_H(), m_ritz_val[i]); - - // Q -> Q * Qi - decomp.apply_YQ(Q); - // H -> Q'HQ - // Since QR = H - mu * I, we have H = QR + mu * I - // and therefore Q'HQ = RQ + mu * I - m_fac.compress_H(decomp); - } - - m_fac.compress_V(Q); - m_fac.factorize_from(k, m_ncv, m_nmatop); - - retrieve_ritzpair(); - } - - // Calculates the number of converged Ritz values - Index num_converged(Scalar tol) - { - // thresh = tol * max(m_eps23, abs(theta)), theta for Ritz value - Array thresh = tol * m_ritz_val.head(m_nev).array().abs().max(m_eps23); - Array resid = m_ritz_est.head(m_nev).array().abs() * m_fac.f_norm(); - // Converged "wanted" Ritz values - m_ritz_conv = (resid < thresh); - - return m_ritz_conv.cast<Index>().sum(); - } - - // Returns the adjusted nev for restarting - Index nev_adjusted(Index nconv) - { - using std::abs; - - Index nev_new = m_nev; - for(Index i = m_nev; i < m_ncv; i++) - if(abs(m_ritz_est[i]) < m_near_0) nev_new++; - - // Adjust nev_new, according to dsaup2.f line 677~684 in ARPACK - nev_new += std::min(nconv, (m_ncv - nev_new) / 2); - if(nev_new == 1 && m_ncv >= 6) - nev_new = m_ncv / 2; - else if(nev_new == 1 && m_ncv > 2) - nev_new = 2; - - if(nev_new > m_ncv - 1) - nev_new = m_ncv - 1; - - return nev_new; - } - - // Retrieves and sorts Ritz values and Ritz vectors - void retrieve_ritzpair() - { - TridiagEigen<Scalar> decomp(m_fac.matrix_H()); - const Vector& evals = decomp.eigenvalues(); - const Matrix& evecs = decomp.eigenvectors(); - - SortEigenvalue<Scalar, SelectionRule> sorting(evals.data(), evals.size()); - std::vector<int> ind = sorting.index(); - - // For BOTH_ENDS, the eigenvalues are sorted according - // to the LARGEST_ALGE rule, so we need to move those smallest - // values to the left - // The order would be - // Largest => Smallest => 2nd largest => 2nd smallest => ... - // We keep this order since the first k values will always be - // the wanted collection, no matter k is nev_updated (used in restart()) - // or is nev (used in sort_ritzpair()) - if(SelectionRule == BOTH_ENDS) - { - std::vector<int> ind_copy(ind); - for(Index i = 0; i < m_ncv; i++) - { - // If i is even, pick values from the left (large values) - // If i is odd, pick values from the right (small values) - if(i % 2 == 0) - ind[i] = ind_copy[i / 2]; - else - ind[i] = ind_copy[m_ncv - 1 - i / 2]; - } - } - - // Copy the Ritz values and vectors to m_ritz_val and m_ritz_vec, respectively - for(Index i = 0; i < m_ncv; i++) - { - m_ritz_val[i] = evals[ind[i]]; - m_ritz_est[i] = evecs(m_ncv - 1, ind[i]); - } - for(Index i = 0; i < m_nev; i++) - { - m_ritz_vec.col(i).noalias() = evecs.col(ind[i]); - } - } - -protected: - // Sorts the first nev Ritz pairs in the specified order - // This is used to return the final results - virtual void sort_ritzpair(int sort_rule) - { - // First make sure that we have a valid index vector - SortEigenvalue<Scalar, LARGEST_ALGE> sorting(m_ritz_val.data(), m_nev); - std::vector<int> ind = sorting.index(); - - switch(sort_rule) - { - case LARGEST_ALGE: - break; - case LARGEST_MAGN: - { - SortEigenvalue<Scalar, LARGEST_MAGN> sorting(m_ritz_val.data(), m_nev); - ind = sorting.index(); - } - break; - case SMALLEST_ALGE: - { - SortEigenvalue<Scalar, SMALLEST_ALGE> sorting(m_ritz_val.data(), m_nev); - ind = sorting.index(); - } - break; - case SMALLEST_MAGN: - { - SortEigenvalue<Scalar, SMALLEST_MAGN> sorting(m_ritz_val.data(), m_nev); - ind = sorting.index(); - } - break; - default: - throw std::invalid_argument("unsupported sorting rule"); - } - - Vector new_ritz_val(m_ncv); - Matrix new_ritz_vec(m_ncv, m_nev); - BoolArray new_ritz_conv(m_nev); - - for(Index i = 0; i < m_nev; i++) - { - new_ritz_val[i] = m_ritz_val[ind[i]]; - new_ritz_vec.col(i).noalias() = m_ritz_vec.col(ind[i]); - new_ritz_conv[i] = m_ritz_conv[ind[i]]; - } - - m_ritz_val.swap(new_ritz_val); - m_ritz_vec.swap(new_ritz_vec); - m_ritz_conv.swap(new_ritz_conv); - } - -public: - /// \cond - - SymEigsBase(OpType* op, BOpType* Bop, Index nev, Index ncv) : - m_op(op), - m_n(m_op->rows()), - m_nev(nev), - m_ncv(ncv > m_n ? m_n : ncv), - m_nmatop(0), - m_niter(0), - m_fac(ArnoldiOpType(op, Bop), m_ncv), - m_info(NOT_COMPUTED), - m_near_0(TypeTraits<Scalar>::min() * Scalar(10)), - m_eps(Eigen::NumTraits<Scalar>::epsilon()), - m_eps23(Eigen::numext::pow(m_eps, Scalar(2.0) / 3)) - { - if(nev < 1 || nev > m_n - 1) - throw std::invalid_argument("nev must satisfy 1 <= nev <= n - 1, n is the size of matrix"); - - if(ncv <= nev || ncv > m_n) - throw std::invalid_argument("ncv must satisfy nev < ncv <= n, n is the size of matrix"); - } - - /// - /// Virtual destructor - /// - virtual ~SymEigsBase() {} - - /// \endcond - - /// - /// Initializes the solver by providing an initial residual vector. - /// - /// \param init_resid Pointer to the initial residual vector. - /// - /// **Spectra** (and also **ARPACK**) uses an iterative algorithm - /// to find eigenvalues. This function allows the user to provide the initial - /// residual vector. - /// - void init(const Scalar* init_resid) - { - // Reset all matrices/vectors to zero - m_ritz_val.resize(m_ncv); - m_ritz_vec.resize(m_ncv, m_nev); - m_ritz_est.resize(m_ncv); - m_ritz_conv.resize(m_nev); - - m_ritz_val.setZero(); - m_ritz_vec.setZero(); - m_ritz_est.setZero(); - m_ritz_conv.setZero(); - - m_nmatop = 0; - m_niter = 0; - - // Initialize the Lanczos factorization - MapConstVec v0(init_resid, m_n); - m_fac.init(v0, m_nmatop); - } - - /// - /// Initializes the solver by providing a random initial residual vector. - /// - /// This overloaded function generates a random initial residual vector - /// (with a fixed random seed) for the algorithm. Elements in the vector - /// follow independent Uniform(-0.5, 0.5) distribution. - /// - void init() - { - SimpleRandom<Scalar> rng(0); - Vector init_resid = rng.random_vec(m_n); - init(init_resid.data()); - } - - /// - /// Conducts the major computation procedure. - /// - /// \param maxit Maximum number of iterations allowed in the algorithm. - /// \param tol Precision parameter for the calculated eigenvalues. - /// \param sort_rule Rule to sort the eigenvalues and eigenvectors. - /// Supported values are - /// `Spectra::LARGEST_ALGE`, `Spectra::LARGEST_MAGN`, - /// `Spectra::SMALLEST_ALGE` and `Spectra::SMALLEST_MAGN`, - /// for example `LARGEST_ALGE` indicates that largest eigenvalues - /// come first. Note that this argument is only used to - /// **sort** the final result, and the **selection** rule - /// (e.g. selecting the largest or smallest eigenvalues in the - /// full spectrum) is specified by the template parameter - /// `SelectionRule` of SymEigsSolver. - /// - /// \return Number of converged eigenvalues. - /// - Index compute(Index maxit = 1000, Scalar tol = 1e-10, int sort_rule = LARGEST_ALGE) - { - // The m-step Lanczos factorization - m_fac.factorize_from(1, m_ncv, m_nmatop); - retrieve_ritzpair(); - // Restarting - Index i, nconv = 0, nev_adj; - for(i = 0; i < maxit; i++) - { - nconv = num_converged(tol); - if(nconv >= m_nev) - break; - - nev_adj = nev_adjusted(nconv); - restart(nev_adj); - } - // Sorting results - sort_ritzpair(sort_rule); - - m_niter += i + 1; - m_info = (nconv >= m_nev) ? SUCCESSFUL : NOT_CONVERGING; - - return std::min(m_nev, nconv); - } - - /// - /// Returns the status of the computation. - /// The full list of enumeration values can be found in \ref Enumerations. - /// - int info() const { return m_info; } - - /// - /// Returns the number of iterations used in the computation. - /// - Index num_iterations() const { return m_niter; } - - /// - /// Returns the number of matrix operations used in the computation. - /// - Index num_operations() const { return m_nmatop; } - - /// - /// Returns the converged eigenvalues. - /// - /// \return A vector containing the eigenvalues. - /// Returned vector type will be `Eigen::Vector<Scalar, ...>`, depending on - /// the template parameter `Scalar` defined. - /// - Vector eigenvalues() const - { - const Index nconv = m_ritz_conv.cast<Index>().sum(); - Vector res(nconv); - - if(!nconv) - return res; - - Index j = 0; - for(Index i = 0; i < m_nev; i++) - { - if(m_ritz_conv[i]) - { - res[j] = m_ritz_val[i]; - j++; - } - } - - return res; - } - - /// - /// Returns the eigenvectors associated with the converged eigenvalues. - /// - /// \param nvec The number of eigenvectors to return. - /// - /// \return A matrix containing the eigenvectors. - /// Returned matrix type will be `Eigen::Matrix<Scalar, ...>`, - /// depending on the template parameter `Scalar` defined. - /// - virtual Matrix eigenvectors(Index nvec) const - { - const Index nconv = m_ritz_conv.cast<Index>().sum(); - nvec = std::min(nvec, nconv); - Matrix res(m_n, nvec); - - if(!nvec) - return res; - - Matrix ritz_vec_conv(m_ncv, nvec); - Index j = 0; - for(Index i = 0; i < m_nev && j < nvec; i++) - { - if(m_ritz_conv[i]) - { - ritz_vec_conv.col(j).noalias() = m_ritz_vec.col(i); - j++; - } - } - - res.noalias() = m_fac.matrix_V() * ritz_vec_conv; - - return res; - } - - /// - /// Returns all converged eigenvectors. - /// - virtual Matrix eigenvectors() const - { - return eigenvectors(m_nev); - } -}; - - -} // namespace Spectra - -#endif // SYM_EIGS_BASE_H diff --git a/src/external/Spectra/include/Spectra/SymEigsShiftSolver.h b/src/external/Spectra/include/Spectra/SymEigsShiftSolver.h deleted file mode 100644 index 56bd44ec..00000000 --- a/src/external/Spectra/include/Spectra/SymEigsShiftSolver.h +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SYM_EIGS_SHIFT_SOLVER_H -#define SYM_EIGS_SHIFT_SOLVER_H - -#include <Eigen/Core> - -#include "SymEigsBase.h" -#include "Util/SelectionRule.h" -#include "MatOp/DenseSymShiftSolve.h" - -namespace Spectra { - - -/// -/// \ingroup EigenSolver -/// -/// This class implements the eigen solver for real symmetric matrices using -/// the **shift-and-invert mode**. The background information of the symmetric -/// eigen solver is documented in the SymEigsSolver class. Here we focus on -/// explaining the shift-and-invert mode. -/// -/// The shift-and-invert mode is based on the following fact: -/// If \f$\lambda\f$ and \f$x\f$ are a pair of eigenvalue and eigenvector of -/// matrix \f$A\f$, such that \f$Ax=\lambda x\f$, then for any \f$\sigma\f$, -/// we have -/// \f[(A-\sigma I)^{-1}x=\nu x\f] -/// where -/// \f[\nu=\frac{1}{\lambda-\sigma}\f] -/// which indicates that \f$(\nu, x)\f$ is an eigenpair of the matrix -/// \f$(A-\sigma I)^{-1}\f$. -/// -/// Therefore, if we pass the matrix operation \f$(A-\sigma I)^{-1}y\f$ -/// (rather than \f$Ay\f$) to the eigen solver, then we would get the desired -/// values of \f$\nu\f$, and \f$\lambda\f$ can also be easily obtained by noting -/// that \f$\lambda=\sigma+\nu^{-1}\f$. -/// -/// The reason why we need this type of manipulation is that -/// the algorithm of **Spectra** (and also **ARPACK**) -/// is good at finding eigenvalues with large magnitude, but may fail in looking -/// for eigenvalues that are close to zero. However, if we really need them, we -/// can set \f$\sigma=0\f$, find the largest eigenvalues of \f$A^{-1}\f$, and then -/// transform back to \f$\lambda\f$, since in this case largest values of \f$\nu\f$ -/// implies smallest values of \f$\lambda\f$. -/// -/// To summarize, in the shift-and-invert mode, the selection rule will apply to -/// \f$\nu=1/(\lambda-\sigma)\f$ rather than \f$\lambda\f$. So a selection rule -/// of `LARGEST_MAGN` combined with shift \f$\sigma\f$ will find eigenvalues of -/// \f$A\f$ that are closest to \f$\sigma\f$. But note that the eigenvalues() -/// method will always return the eigenvalues in the original problem (i.e., -/// returning \f$\lambda\f$ rather than \f$\nu\f$), and eigenvectors are the -/// same for both the original problem and the shifted-and-inverted problem. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// \tparam SelectionRule An enumeration value indicating the selection rule of -/// the shifted-and-inverted eigenvalues. -/// The full list of enumeration values can be found in -/// \ref Enumerations. -/// \tparam OpType The name of the matrix operation class. Users could either -/// use the wrapper classes such as DenseSymShiftSolve and -/// SparseSymShiftSolve, or define their -/// own that implements all the public member functions as in -/// DenseSymShiftSolve. -/// -/// Below is an example that illustrates the use of the shift-and-invert mode: -/// -/// \code{.cpp} -/// #include <Eigen/Core> -/// #include <Spectra/SymEigsShiftSolver.h> -/// // <Spectra/MatOp/DenseSymShiftSolve.h> is implicitly included -/// #include <iostream> -/// -/// using namespace Spectra; -/// -/// int main() -/// { -/// // A size-10 diagonal matrix with elements 1, 2, ..., 10 -/// Eigen::MatrixXd M = Eigen::MatrixXd::Zero(10, 10); -/// for(int i = 0; i < M.rows(); i++) -/// M(i, i) = i + 1; -/// -/// // Construct matrix operation object using the wrapper class -/// DenseSymShiftSolve<double> op(M); -/// -/// // Construct eigen solver object with shift 0 -/// // This will find eigenvalues that are closest to 0 -/// SymEigsShiftSolver< double, LARGEST_MAGN, -/// DenseSymShiftSolve<double> > eigs(&op, 3, 6, 0.0); -/// -/// eigs.init(); -/// eigs.compute(); -/// if(eigs.info() == SUCCESSFUL) -/// { -/// Eigen::VectorXd evalues = eigs.eigenvalues(); -/// // Will get (3.0, 2.0, 1.0) -/// std::cout << "Eigenvalues found:\n" << evalues << std::endl; -/// } -/// -/// return 0; -/// } -/// \endcode -/// -/// Also an example for user-supplied matrix shift-solve operation class: -/// -/// \code{.cpp} -/// #include <Eigen/Core> -/// #include <Spectra/SymEigsShiftSolver.h> -/// #include <iostream> -/// -/// using namespace Spectra; -/// -/// // M = diag(1, 2, ..., 10) -/// class MyDiagonalTenShiftSolve -/// { -/// private: -/// double sigma_; -/// public: -/// int rows() { return 10; } -/// int cols() { return 10; } -/// void set_shift(double sigma) { sigma_ = sigma; } -/// // y_out = inv(A - sigma * I) * x_in -/// // inv(A - sigma * I) = diag(1/(1-sigma), 1/(2-sigma), ...) -/// void perform_op(double *x_in, double *y_out) -/// { -/// for(int i = 0; i < rows(); i++) -/// { -/// y_out[i] = x_in[i] / (i + 1 - sigma_); -/// } -/// } -/// }; -/// -/// int main() -/// { -/// MyDiagonalTenShiftSolve op; -/// // Find three eigenvalues that are closest to 3.14 -/// SymEigsShiftSolver<double, LARGEST_MAGN, -/// MyDiagonalTenShiftSolve> eigs(&op, 3, 6, 3.14); -/// eigs.init(); -/// eigs.compute(); -/// if(eigs.info() == SUCCESSFUL) -/// { -/// Eigen::VectorXd evalues = eigs.eigenvalues(); -/// // Will get (4.0, 3.0, 2.0) -/// std::cout << "Eigenvalues found:\n" << evalues << std::endl; -/// } -/// -/// return 0; -/// } -/// \endcode -/// -template <typename Scalar = double, - int SelectionRule = LARGEST_MAGN, - typename OpType = DenseSymShiftSolve<double> > -class SymEigsShiftSolver: public SymEigsBase<Scalar, SelectionRule, OpType, IdentityBOp> -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Array<Scalar, Eigen::Dynamic, 1> Array; - - const Scalar m_sigma; - - // First transform back the Ritz values, and then sort - void sort_ritzpair(int sort_rule) - { - Array m_ritz_val_org = Scalar(1.0) / this->m_ritz_val.head(this->m_nev).array() + m_sigma; - this->m_ritz_val.head(this->m_nev) = m_ritz_val_org; - SymEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>::sort_ritzpair(sort_rule); - } - -public: - /// - /// Constructor to create a eigen solver object using the shift-and-invert mode. - /// - /// \param op Pointer to the matrix operation object, which should implement - /// the shift-solve operation of \f$A\f$: calculating - /// \f$(A-\sigma I)^{-1}v\f$ for any vector \f$v\f$. Users could either - /// create the object from the wrapper class such as DenseSymShiftSolve, or - /// define their own that implements all the public member functions - /// as in DenseSymShiftSolve. - /// \param nev Number of eigenvalues requested. This should satisfy \f$1\le nev \le n-1\f$, - /// where \f$n\f$ is the size of matrix. - /// \param ncv Parameter that controls the convergence speed of the algorithm. - /// Typically a larger `ncv_` means faster convergence, but it may - /// also result in greater memory use and more matrix operations - /// in each iteration. This parameter must satisfy \f$nev < ncv \le n\f$, - /// and is advised to take \f$ncv \ge 2\cdot nev\f$. - /// \param sigma The value of the shift. - /// - SymEigsShiftSolver(OpType* op, Index nev, Index ncv, Scalar sigma) : - SymEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>(op, NULL, nev, ncv), - m_sigma(sigma) - { - this->m_op->set_shift(m_sigma); - } -}; - - -} // namespace Spectra - -#endif // SYM_EIGS_SHIFT_SOLVER_H diff --git a/src/external/Spectra/include/Spectra/SymEigsSolver.h b/src/external/Spectra/include/Spectra/SymEigsSolver.h deleted file mode 100644 index 8ba3e509..00000000 --- a/src/external/Spectra/include/Spectra/SymEigsSolver.h +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SYM_EIGS_SOLVER_H -#define SYM_EIGS_SOLVER_H - -#include <Eigen/Core> - -#include "SymEigsBase.h" -#include "Util/SelectionRule.h" -#include "MatOp/DenseSymMatProd.h" - -namespace Spectra { - - -/// -/// \ingroup EigenSolver -/// -/// This class implements the eigen solver for real symmetric matrices, i.e., -/// to solve \f$Ax=\lambda x\f$ where \f$A\f$ is symmetric. -/// -/// **Spectra** is designed to calculate a specified number (\f$k\f$) -/// of eigenvalues of a large square matrix (\f$A\f$). Usually \f$k\f$ is much -/// less than the size of the matrix (\f$n\f$), so that only a few eigenvalues -/// and eigenvectors are computed. -/// -/// Rather than providing the whole \f$A\f$ matrix, the algorithm only requires -/// the matrix-vector multiplication operation of \f$A\f$. Therefore, users of -/// this solver need to supply a class that computes the result of \f$Av\f$ -/// for any given vector \f$v\f$. The name of this class should be given to -/// the template parameter `OpType`, and instance of this class passed to -/// the constructor of SymEigsSolver. -/// -/// If the matrix \f$A\f$ is already stored as a matrix object in **Eigen**, -/// for example `Eigen::MatrixXd`, then there is an easy way to construct such -/// matrix operation class, by using the built-in wrapper class DenseSymMatProd -/// which wraps an existing matrix object in **Eigen**. This is also the -/// default template parameter for SymEigsSolver. For sparse matrices, the -/// wrapper class SparseSymMatProd can be used similarly. -/// -/// If the users need to define their own matrix-vector multiplication operation -/// class, it should implement all the public member functions as in DenseSymMatProd. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// \tparam SelectionRule An enumeration value indicating the selection rule of -/// the requested eigenvalues, for example `LARGEST_MAGN` -/// to retrieve eigenvalues with the largest magnitude. -/// The full list of enumeration values can be found in -/// \ref Enumerations. -/// \tparam OpType The name of the matrix operation class. Users could either -/// use the wrapper classes such as DenseSymMatProd and -/// SparseSymMatProd, or define their -/// own that implements all the public member functions as in -/// DenseSymMatProd. -/// -/// Below is an example that demonstrates the usage of this class. -/// -/// \code{.cpp} -/// #include <Eigen/Core> -/// #include <Spectra/SymEigsSolver.h> -/// // <Spectra/MatOp/DenseSymMatProd.h> is implicitly included -/// #include <iostream> -/// -/// using namespace Spectra; -/// -/// int main() -/// { -/// // We are going to calculate the eigenvalues of M -/// Eigen::MatrixXd A = Eigen::MatrixXd::Random(10, 10); -/// Eigen::MatrixXd M = A + A.transpose(); -/// -/// // Construct matrix operation object using the wrapper class DenseSymMatProd -/// DenseSymMatProd<double> op(M); -/// -/// // Construct eigen solver object, requesting the largest three eigenvalues -/// SymEigsSolver< double, LARGEST_ALGE, DenseSymMatProd<double> > eigs(&op, 3, 6); -/// -/// // Initialize and compute -/// eigs.init(); -/// int nconv = eigs.compute(); -/// -/// // Retrieve results -/// Eigen::VectorXd evalues; -/// if(eigs.info() == SUCCESSFUL) -/// evalues = eigs.eigenvalues(); -/// -/// std::cout << "Eigenvalues found:\n" << evalues << std::endl; -/// -/// return 0; -/// } -/// \endcode -/// -/// And here is an example for user-supplied matrix operation class. -/// -/// \code{.cpp} -/// #include <Eigen/Core> -/// #include <Spectra/SymEigsSolver.h> -/// #include <iostream> -/// -/// using namespace Spectra; -/// -/// // M = diag(1, 2, ..., 10) -/// class MyDiagonalTen -/// { -/// public: -/// int rows() { return 10; } -/// int cols() { return 10; } -/// // y_out = M * x_in -/// void perform_op(double *x_in, double *y_out) -/// { -/// for(int i = 0; i < rows(); i++) -/// { -/// y_out[i] = x_in[i] * (i + 1); -/// } -/// } -/// }; -/// -/// int main() -/// { -/// MyDiagonalTen op; -/// SymEigsSolver<double, LARGEST_ALGE, MyDiagonalTen> eigs(&op, 3, 6); -/// eigs.init(); -/// eigs.compute(); -/// if(eigs.info() == SUCCESSFUL) -/// { -/// Eigen::VectorXd evalues = eigs.eigenvalues(); -/// // Will get (10, 9, 8) -/// std::cout << "Eigenvalues found:\n" << evalues << std::endl; -/// } -/// -/// return 0; -/// } -/// \endcode -/// -template < typename Scalar = double, - int SelectionRule = LARGEST_MAGN, - typename OpType = DenseSymMatProd<double> > -class SymEigsSolver: public SymEigsBase<Scalar, SelectionRule, OpType, IdentityBOp> -{ -private: - typedef Eigen::Index Index; - -public: - /// - /// Constructor to create a solver object. - /// - /// \param op Pointer to the matrix operation object, which should implement - /// the matrix-vector multiplication operation of \f$A\f$: - /// calculating \f$Av\f$ for any vector \f$v\f$. Users could either - /// create the object from the wrapper class such as DenseSymMatProd, or - /// define their own that implements all the public member functions - /// as in DenseSymMatProd. - /// \param nev Number of eigenvalues requested. This should satisfy \f$1\le nev \le n-1\f$, - /// where \f$n\f$ is the size of matrix. - /// \param ncv Parameter that controls the convergence speed of the algorithm. - /// Typically a larger `ncv` means faster convergence, but it may - /// also result in greater memory use and more matrix operations - /// in each iteration. This parameter must satisfy \f$nev < ncv \le n\f$, - /// and is advised to take \f$ncv \ge 2\cdot nev\f$. - /// - SymEigsSolver(OpType* op, Index nev, Index ncv) : - SymEigsBase<Scalar, SelectionRule, OpType, IdentityBOp>(op, NULL, nev, ncv) - {} - -}; - - -} // namespace Spectra - -#endif // SYM_EIGS_SOLVER_H diff --git a/src/external/Spectra/include/Spectra/SymGEigsSolver.h b/src/external/Spectra/include/Spectra/SymGEigsSolver.h deleted file mode 100644 index 8e774284..00000000 --- a/src/external/Spectra/include/Spectra/SymGEigsSolver.h +++ /dev/null @@ -1,334 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SYM_GEIGS_SOLVER_H -#define SYM_GEIGS_SOLVER_H - -#include "SymEigsBase.h" -#include "Util/GEigsMode.h" -#include "MatOp/internal/SymGEigsCholeskyOp.h" -#include "MatOp/internal/SymGEigsRegInvOp.h" - -namespace Spectra { - - -/// -/// \defgroup GEigenSolver Generalized Eigen Solvers -/// -/// Generalized eigen solvers for different types of problems. -/// - -/// -/// \ingroup GEigenSolver -/// -/// This class implements the generalized eigen solver for real symmetric -/// matrices, i.e., to solve \f$Ax=\lambda Bx\f$ where \f$A\f$ is symmetric and -/// \f$B\f$ is positive definite. -/// -/// There are two modes of this solver, specified by the template parameter -/// GEigsMode. See the pages for the specialized classes for details. -/// - The Cholesky mode assumes that \f$B\f$ can be factorized using Cholesky -/// decomposition, which is the preferred mode when the decomposition is -/// available. (This can be easily done in Eigen using the dense or sparse -/// Cholesky solver.) -/// See \ref SymGEigsSolver<Scalar, SelectionRule, OpType, BOpType, GEIGS_CHOLESKY> "SymGEigsSolver (Cholesky mode)" for more details. -/// - The regular inverse mode requires the matrix-vector product \f$Bv\f$ and the -/// linear equation solving operation \f$B^{-1}v\f$. This mode should only be -/// used when the Cholesky decomposition of \f$B\f$ is hard to implement, or -/// when computing \f$B^{-1}v\f$ is much faster than the Cholesky decomposition. -/// See \ref SymGEigsSolver<Scalar, SelectionRule, OpType, BOpType, GEIGS_REGULAR_INVERSE> "SymGEigsSolver (Regular inverse mode)" for more details. - -// Empty class template -template < typename Scalar, - int SelectionRule, - typename OpType, - typename BOpType, - int GEigsMode > -class SymGEigsSolver -{}; - - - -/// -/// \ingroup GEigenSolver -/// -/// This class implements the generalized eigen solver for real symmetric -/// matrices using Cholesky decomposition, i.e., to solve \f$Ax=\lambda Bx\f$ -/// where \f$A\f$ is symmetric and \f$B\f$ is positive definite with the Cholesky -/// decomposition \f$B=LL'\f$. -/// -/// This solver requires two matrix operation objects: one for \f$A\f$ that implements -/// the matrix multiplication \f$Av\f$, and one for \f$B\f$ that implements the lower -/// and upper triangular solving \f$L^{-1}v\f$ and \f$(L')^{-1}v\f$. -/// -/// If \f$A\f$ and \f$B\f$ are stored as Eigen matrices, then the first operation -/// can be created using the DenseSymMatProd or SparseSymMatProd classes, and -/// the second operation can be created using the DenseCholesky or SparseCholesky -/// classes. If the users need to define their own operation classes, then they -/// should implement all the public member functions as in those built-in classes. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// \tparam SelectionRule An enumeration value indicating the selection rule of -/// the requested eigenvalues, for example `LARGEST_MAGN` -/// to retrieve eigenvalues with the largest magnitude. -/// The full list of enumeration values can be found in -/// \ref Enumerations. -/// \tparam OpType The name of the matrix operation class for \f$A\f$. Users could either -/// use the wrapper classes such as DenseSymMatProd and -/// SparseSymMatProd, or define their -/// own that implements all the public member functions as in -/// DenseSymMatProd. -/// \tparam BOpType The name of the matrix operation class for \f$B\f$. Users could either -/// use the wrapper classes such as DenseCholesky and -/// SparseCholesky, or define their -/// own that implements all the public member functions as in -/// DenseCholesky. -/// \tparam GEigsMode Mode of the generalized eigen solver. In this solver -/// it is Spectra::GEIGS_CHOLESKY. -/// -/// Below is an example that demonstrates the usage of this class. -/// -/// \code{.cpp} -/// #include <Eigen/Core> -/// #include <Eigen/SparseCore> -/// #include <Eigen/Eigenvalues> -/// #include <Spectra/SymGEigsSolver.h> -/// #include <Spectra/MatOp/DenseSymMatProd.h> -/// #include <Spectra/MatOp/SparseCholesky.h> -/// #include <iostream> -/// -/// using namespace Spectra; -/// -/// int main() -/// { -/// // We are going to solve the generalized eigenvalue problem A * x = lambda * B * x -/// const int n = 100; -/// -/// // Define the A matrix -/// Eigen::MatrixXd M = Eigen::MatrixXd::Random(n, n); -/// Eigen::MatrixXd A = M + M.transpose(); -/// -/// // Define the B matrix, a band matrix with 2 on the diagonal and 1 on the subdiagonals -/// Eigen::SparseMatrix<double> B(n, n); -/// B.reserve(Eigen::VectorXi::Constant(n, 3)); -/// for(int i = 0; i < n; i++) -/// { -/// B.insert(i, i) = 2.0; -/// if(i > 0) -/// B.insert(i - 1, i) = 1.0; -/// if(i < n - 1) -/// B.insert(i + 1, i) = 1.0; -/// } -/// -/// // Construct matrix operation object using the wrapper classes -/// DenseSymMatProd<double> op(A); -/// SparseCholesky<double> Bop(B); -/// -/// // Construct generalized eigen solver object, requesting the largest three generalized eigenvalues -/// SymGEigsSolver<double, LARGEST_ALGE, DenseSymMatProd<double>, SparseCholesky<double>, GEIGS_CHOLESKY> -/// geigs(&op, &Bop, 3, 6); -/// -/// // Initialize and compute -/// geigs.init(); -/// int nconv = geigs.compute(); -/// -/// // Retrieve results -/// Eigen::VectorXd evalues; -/// Eigen::MatrixXd evecs; -/// if(geigs.info() == SUCCESSFUL) -/// { -/// evalues = geigs.eigenvalues(); -/// evecs = geigs.eigenvectors(); -/// } -/// -/// std::cout << "Generalized eigenvalues found:\n" << evalues << std::endl; -/// std::cout << "Generalized eigenvectors found:\n" << evecs.topRows(10) << std::endl; -/// -/// // Verify results using the generalized eigen solver in Eigen -/// Eigen::MatrixXd Bdense = B; -/// Eigen::GeneralizedSelfAdjointEigenSolver<Eigen::MatrixXd> es(A, Bdense); -/// -/// std::cout << "Generalized eigenvalues:\n" << es.eigenvalues().tail(3) << std::endl; -/// std::cout << "Generalized eigenvectors:\n" << es.eigenvectors().rightCols(3).topRows(10) << std::endl; -/// -/// return 0; -/// } -/// \endcode - -// Partial specialization for GEigsMode = GEIGS_CHOLESKY -template < typename Scalar, - int SelectionRule, - typename OpType, - typename BOpType > -class SymGEigsSolver<Scalar, SelectionRule, OpType, BOpType, GEIGS_CHOLESKY>: - public SymEigsBase<Scalar, SelectionRule, SymGEigsCholeskyOp<Scalar, OpType, BOpType>, IdentityBOp> -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - BOpType* m_Bop; - -public: - /// - /// Constructor to create a solver object. - /// - /// \param op Pointer to the \f$A\f$ matrix operation object. It - /// should implement the matrix-vector multiplication operation of \f$A\f$: - /// calculating \f$Av\f$ for any vector \f$v\f$. Users could either - /// create the object from the wrapper classes such as DenseSymMatProd, or - /// define their own that implements all the public member functions - /// as in DenseSymMatProd. - /// \param Bop Pointer to the \f$B\f$ matrix operation object. It - /// represents a Cholesky decomposition of \f$B\f$, and should - /// implement the lower and upper triangular solving operations: - /// calculating \f$L^{-1}v\f$ and \f$(L')^{-1}v\f$ for any vector - /// \f$v\f$, where \f$LL'=B\f$. Users could either - /// create the object from the wrapper classes such as DenseCholesky, or - /// define their own that implements all the public member functions - /// as in DenseCholesky. - /// \param nev Number of eigenvalues requested. This should satisfy \f$1\le nev \le n-1\f$, - /// where \f$n\f$ is the size of matrix. - /// \param ncv Parameter that controls the convergence speed of the algorithm. - /// Typically a larger `ncv` means faster convergence, but it may - /// also result in greater memory use and more matrix operations - /// in each iteration. This parameter must satisfy \f$nev < ncv \le n\f$, - /// and is advised to take \f$ncv \ge 2\cdot nev\f$. - /// - SymGEigsSolver(OpType* op, BOpType* Bop, Index nev, Index ncv) : - SymEigsBase<Scalar, SelectionRule, SymGEigsCholeskyOp<Scalar, OpType, BOpType>, IdentityBOp>( - new SymGEigsCholeskyOp<Scalar, OpType, BOpType>(*op, *Bop), NULL, nev, ncv - ), - m_Bop(Bop) - {} - - /// \cond - - ~SymGEigsSolver() - { - // m_op contains the constructed SymGEigsCholeskyOp object - delete this->m_op; - } - - Matrix eigenvectors(Index nvec) const - { - Matrix res = SymEigsBase<Scalar, SelectionRule, SymGEigsCholeskyOp<Scalar, OpType, BOpType>, IdentityBOp>::eigenvectors(nvec); - Vector tmp(res.rows()); - const Index nconv = res.cols(); - for(Index i = 0; i < nconv; i++) - { - m_Bop->upper_triangular_solve(&res(0, i), tmp.data()); - res.col(i).noalias() = tmp; - } - - return res; - } - - Matrix eigenvectors() const - { - return SymGEigsSolver<Scalar, SelectionRule, OpType, BOpType, GEIGS_CHOLESKY>::eigenvectors(this->m_nev); - } - - /// \endcond -}; - - - -/// -/// \ingroup GEigenSolver -/// -/// This class implements the generalized eigen solver for real symmetric -/// matrices in the regular inverse mode, i.e., to solve \f$Ax=\lambda Bx\f$ -/// where \f$A\f$ is symmetric, and \f$B\f$ is positive definite with the operations -/// defined below. -/// -/// This solver requires two matrix operation objects: one for \f$A\f$ that implements -/// the matrix multiplication \f$Av\f$, and one for \f$B\f$ that implements the -/// matrix-vector product \f$Bv\f$ and the linear equation solving operation \f$B^{-1}v\f$. -/// -/// If \f$A\f$ and \f$B\f$ are stored as Eigen matrices, then the first operation -/// can be created using the DenseSymMatProd or SparseSymMatProd classes, and -/// the second operation can be created using the SparseRegularInverse class. There is no -/// wrapper class for a dense \f$B\f$ matrix since in this case the Cholesky mode -/// is always preferred. If the users need to define their own operation classes, then they -/// should implement all the public member functions as in those built-in classes. -/// -/// \tparam Scalar The element type of the matrix. -/// Currently supported types are `float`, `double` and `long double`. -/// \tparam SelectionRule An enumeration value indicating the selection rule of -/// the requested eigenvalues, for example `LARGEST_MAGN` -/// to retrieve eigenvalues with the largest magnitude. -/// The full list of enumeration values can be found in -/// \ref Enumerations. -/// \tparam OpType The name of the matrix operation class for \f$A\f$. Users could either -/// use the wrapper classes such as DenseSymMatProd and -/// SparseSymMatProd, or define their -/// own that implements all the public member functions as in -/// DenseSymMatProd. -/// \tparam BOpType The name of the matrix operation class for \f$B\f$. Users could either -/// use the wrapper class SparseRegularInverse, or define their -/// own that implements all the public member functions as in -/// SparseRegularInverse. -/// \tparam GEigsMode Mode of the generalized eigen solver. In this solver -/// it is Spectra::GEIGS_REGULAR_INVERSE. -/// - -// Partial specialization for GEigsMode = GEIGS_REGULAR_INVERSE -template < typename Scalar, - int SelectionRule, - typename OpType, - typename BOpType > -class SymGEigsSolver<Scalar, SelectionRule, OpType, BOpType, GEIGS_REGULAR_INVERSE>: - public SymEigsBase<Scalar, SelectionRule, SymGEigsRegInvOp<Scalar, OpType, BOpType>, BOpType> -{ -private: - typedef Eigen::Index Index; - -public: - /// - /// Constructor to create a solver object. - /// - /// \param op Pointer to the \f$A\f$ matrix operation object. It - /// should implement the matrix-vector multiplication operation of \f$A\f$: - /// calculating \f$Av\f$ for any vector \f$v\f$. Users could either - /// create the object from the wrapper classes such as DenseSymMatProd, or - /// define their own that implements all the public member functions - /// as in DenseSymMatProd. - /// \param Bop Pointer to the \f$B\f$ matrix operation object. It should - /// implement the multiplication operation \f$Bv\f$ and the linear equation - /// solving operation \f$B^{-1}v\f$ for any vector \f$v\f$. Users could either - /// create the object from the wrapper class SparseRegularInverse, or - /// define their own that implements all the public member functions - /// as in SparseRegularInverse. - /// \param nev Number of eigenvalues requested. This should satisfy \f$1\le nev \le n-1\f$, - /// where \f$n\f$ is the size of matrix. - /// \param ncv Parameter that controls the convergence speed of the algorithm. - /// Typically a larger `ncv` means faster convergence, but it may - /// also result in greater memory use and more matrix operations - /// in each iteration. This parameter must satisfy \f$nev < ncv \le n\f$, - /// and is advised to take \f$ncv \ge 2\cdot nev\f$. - /// - SymGEigsSolver(OpType* op, BOpType* Bop, Index nev, Index ncv) : - SymEigsBase<Scalar, SelectionRule, SymGEigsRegInvOp<Scalar, OpType, BOpType>, BOpType>( - new SymGEigsRegInvOp<Scalar, OpType, BOpType>(*op, *Bop), Bop, nev, ncv - ) - {} - - /// \cond - ~SymGEigsSolver() - { - // m_op contains the constructed SymGEigsRegInvOp object - delete this->m_op; - } - /// \endcond -}; - - -} // namespace Spectra - -#endif // SYM_GEIGS_SOLVER_H diff --git a/src/external/Spectra/include/Spectra/Util/CompInfo.h b/src/external/Spectra/include/Spectra/Util/CompInfo.h deleted file mode 100644 index b8e639d6..00000000 --- a/src/external/Spectra/include/Spectra/Util/CompInfo.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef COMP_INFO_H -#define COMP_INFO_H - -namespace Spectra { - - -/// -/// \ingroup Enumerations -/// -/// The enumeration to report the status of computation. -/// -enum COMPUTATION_INFO -{ - SUCCESSFUL = 0, ///< Computation was successful. - - NOT_COMPUTED, ///< Used in eigen solvers, indicating that computation - ///< has not been conducted. Users should call - ///< the `compute()` member function of solvers. - - NOT_CONVERGING, ///< Used in eigen solvers, indicating that some eigenvalues - ///< did not converge. The `compute()` - ///< function returns the number of converged eigenvalues. - - NUMERICAL_ISSUE ///< Used in Cholesky decomposition, indicating that the - ///< matrix is not positive definite. -}; - - -} // namespace Spectra - -#endif // COMP_INFO_H diff --git a/src/external/Spectra/include/Spectra/Util/GEigsMode.h b/src/external/Spectra/include/Spectra/Util/GEigsMode.h deleted file mode 100644 index d03f269d..00000000 --- a/src/external/Spectra/include/Spectra/Util/GEigsMode.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef GEIGS_MODE_H -#define GEIGS_MODE_H - -namespace Spectra { - - -/// -/// \ingroup Enumerations -/// -/// The enumeration to specify the mode of generalized eigenvalue solver. -/// -enum GEIGS_MODE -{ - GEIGS_CHOLESKY = 0, ///< Using Cholesky decomposition to solve generalized eigenvalues. - - GEIGS_REGULAR_INVERSE, ///< Regular inverse mode for generalized eigenvalue solver. - - GEIGS_SHIFT_INVERT, ///< Shift-and-invert mode for generalized eigenvalue solver. - - GEIGS_BUCKLING, ///< Buckling mode for generalized eigenvalue solver. - - GEIGS_CAYLEY ///< Cayley transformation mode for generalized eigenvalue solver. -}; - - -} // namespace Spectra - -#endif // GEIGS_MODE_H diff --git a/src/external/Spectra/include/Spectra/Util/SelectionRule.h b/src/external/Spectra/include/Spectra/Util/SelectionRule.h deleted file mode 100644 index 19f71dcf..00000000 --- a/src/external/Spectra/include/Spectra/Util/SelectionRule.h +++ /dev/null @@ -1,277 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SELECTION_RULE_H -#define SELECTION_RULE_H - -#include <vector> // std::vector -#include <cmath> // std::abs -#include <algorithm> // std::sort -#include <complex> // std::complex -#include <utility> // std::pair -#include <stdexcept> // std::invalid_argument - -namespace Spectra { - - -/// -/// \defgroup Enumerations -/// -/// Enumeration types for the selection rule of eigenvalues. -/// - -/// -/// \ingroup Enumerations -/// -/// The enumeration of selection rules of desired eigenvalues. -/// -enum SELECT_EIGENVALUE -{ - LARGEST_MAGN = 0, ///< Select eigenvalues with largest magnitude. Magnitude - ///< means the absolute value for real numbers and norm for - ///< complex numbers. Applies to both symmetric and general - ///< eigen solvers. - - LARGEST_REAL, ///< Select eigenvalues with largest real part. Only for general eigen solvers. - - LARGEST_IMAG, ///< Select eigenvalues with largest imaginary part (in magnitude). Only for general eigen solvers. - - LARGEST_ALGE, ///< Select eigenvalues with largest algebraic value, considering - ///< any negative sign. Only for symmetric eigen solvers. - - SMALLEST_MAGN, ///< Select eigenvalues with smallest magnitude. Applies to both symmetric and general - ///< eigen solvers. - - SMALLEST_REAL, ///< Select eigenvalues with smallest real part. Only for general eigen solvers. - - SMALLEST_IMAG, ///< Select eigenvalues with smallest imaginary part (in magnitude). Only for general eigen solvers. - - SMALLEST_ALGE, ///< Select eigenvalues with smallest algebraic value. Only for symmetric eigen solvers. - - BOTH_ENDS ///< Select eigenvalues half from each end of the spectrum. When - ///< `nev` is odd, compute more from the high end. Only for symmetric eigen solvers. -}; - -/// -/// \ingroup Enumerations -/// -/// The enumeration of selection rules of desired eigenvalues. Alias for `SELECT_EIGENVALUE`. -/// -enum SELECT_EIGENVALUE_ALIAS -{ - WHICH_LM = 0, ///< Alias for `LARGEST_MAGN` - WHICH_LR, ///< Alias for `LARGEST_REAL` - WHICH_LI, ///< Alias for `LARGEST_IMAG` - WHICH_LA, ///< Alias for `LARGEST_ALGE` - WHICH_SM, ///< Alias for `SMALLEST_MAGN` - WHICH_SR, ///< Alias for `SMALLEST_REAL` - WHICH_SI, ///< Alias for `SMALLEST_IMAG` - WHICH_SA, ///< Alias for `SMALLEST_ALGE` - WHICH_BE ///< Alias for `BOTH_ENDS` -}; - -/// \cond - -// Get the element type of a "scalar" -// ElemType<double> => double -// ElemType< std::complex<double> > => double -template <typename T> -class ElemType -{ -public: - typedef T type; -}; - -template <typename T> -class ElemType< std::complex<T> > -{ -public: - typedef T type; -}; - -// When comparing eigenvalues, we first calculate the "target" -// to sort. For example, if we want to choose the eigenvalues with -// largest magnitude, the target will be -abs(x). -// The minus sign is due to the fact that std::sort() sorts in ascending order. - -// Default target: throw an exception -template <typename Scalar, int SelectionRule> -class SortingTarget -{ -public: - static typename ElemType<Scalar>::type get(const Scalar& val) - { - using std::abs; - throw std::invalid_argument("incompatible selection rule"); - return -abs(val); - } -}; - -// Specialization for LARGEST_MAGN -// This covers [float, double, complex] x [LARGEST_MAGN] -template <typename Scalar> -class SortingTarget<Scalar, LARGEST_MAGN> -{ -public: - static typename ElemType<Scalar>::type get(const Scalar& val) - { - using std::abs; - return -abs(val); - } -}; - -// Specialization for LARGEST_REAL -// This covers [complex] x [LARGEST_REAL] -template <typename RealType> -class SortingTarget<std::complex<RealType>, LARGEST_REAL> -{ -public: - static RealType get(const std::complex<RealType>& val) - { - return -val.real(); - } -}; - -// Specialization for LARGEST_IMAG -// This covers [complex] x [LARGEST_IMAG] -template <typename RealType> -class SortingTarget<std::complex<RealType>, LARGEST_IMAG> -{ -public: - static RealType get(const std::complex<RealType>& val) - { - using std::abs; - return -abs(val.imag()); - } -}; - -// Specialization for LARGEST_ALGE -// This covers [float, double] x [LARGEST_ALGE] -template <typename Scalar> -class SortingTarget<Scalar, LARGEST_ALGE> -{ -public: - static Scalar get(const Scalar& val) - { - return -val; - } -}; - -// Here BOTH_ENDS is the same as LARGEST_ALGE, but -// we need some additional steps, which are done in -// SymEigsSolver.h => retrieve_ritzpair(). -// There we move the smallest values to the proper locations. -template <typename Scalar> -class SortingTarget<Scalar, BOTH_ENDS> -{ -public: - static Scalar get(const Scalar& val) - { - return -val; - } -}; - -// Specialization for SMALLEST_MAGN -// This covers [float, double, complex] x [SMALLEST_MAGN] -template <typename Scalar> -class SortingTarget<Scalar, SMALLEST_MAGN> -{ -public: - static typename ElemType<Scalar>::type get(const Scalar& val) - { - using std::abs; - return abs(val); - } -}; - -// Specialization for SMALLEST_REAL -// This covers [complex] x [SMALLEST_REAL] -template <typename RealType> -class SortingTarget<std::complex<RealType>, SMALLEST_REAL> -{ -public: - static RealType get(const std::complex<RealType>& val) - { - return val.real(); - } -}; - -// Specialization for SMALLEST_IMAG -// This covers [complex] x [SMALLEST_IMAG] -template <typename RealType> -class SortingTarget<std::complex<RealType>, SMALLEST_IMAG> -{ -public: - static RealType get(const std::complex<RealType>& val) - { - using std::abs; - return abs(val.imag()); - } -}; - -// Specialization for SMALLEST_ALGE -// This covers [float, double] x [SMALLEST_ALGE] -template <typename Scalar> -class SortingTarget<Scalar, SMALLEST_ALGE> -{ -public: - static Scalar get(const Scalar& val) - { - return val; - } -}; - -// Sort eigenvalues and return the order index -template <typename PairType> -class PairComparator -{ -public: - bool operator() (const PairType& v1, const PairType& v2) - { - return v1.first < v2.first; - } -}; - -template <typename T, int SelectionRule> -class SortEigenvalue -{ -private: - typedef typename ElemType<T>::type TargetType; // Type of the sorting target, will be - // a floating number type, e.g. "double" - typedef std::pair<TargetType, int> PairType; // Type of the sorting pair, including - // the sorting target and the index - - std::vector<PairType> pair_sort; - -public: - SortEigenvalue(const T* start, int size) : - pair_sort(size) - { - for(int i = 0; i < size; i++) - { - pair_sort[i].first = SortingTarget<T, SelectionRule>::get(start[i]); - pair_sort[i].second = i; - } - PairComparator<PairType> comp; - std::sort(pair_sort.begin(), pair_sort.end(), comp); - } - - std::vector<int> index() - { - std::vector<int> ind(pair_sort.size()); - for(unsigned int i = 0; i < ind.size(); i++) - ind[i] = pair_sort[i].second; - - return ind; - } -}; - -/// \endcond - - -} // namespace Spectra - -#endif // SELECTION_RULE_H diff --git a/src/external/Spectra/include/Spectra/Util/SimpleRandom.h b/src/external/Spectra/include/Spectra/Util/SimpleRandom.h deleted file mode 100644 index 7b1e6162..00000000 --- a/src/external/Spectra/include/Spectra/Util/SimpleRandom.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (C) 2016-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef SIMPLE_RANDOM_H -#define SIMPLE_RANDOM_H - -#include <Eigen/Core> - -/// \cond - -namespace Spectra { - - -// We need a simple pseudo random number generator here: -// 1. It is used to generate initial and restarted residual vector. -// 2. It is not necessary to be so "random" and advanced. All we hope -// is that the residual vector is not in the space spanned by the -// current Krylov space. This should be met almost surely. -// 3. We don't want to call RNG in C++, since we actually want the -// algorithm to be deterministic. Also, calling RNG in C/C++ is not -// allowed in R packages submitted to CRAN. -// 4. The method should be as simple as possible, so an LCG is enough. -// 5. Based on public domain code by Ray Gardner -// http://stjarnhimlen.se/snippets/rg_rand.c - - -template <typename Scalar = double> -class SimpleRandom -{ -private: - typedef Eigen::Index Index; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - const unsigned int m_a; // multiplier - const unsigned long m_max; // 2^31 - 1 - long m_rand; - - inline long next_long_rand(long seed) - { - unsigned long lo, hi; - - lo = m_a * (long)(seed & 0xFFFF); - hi = m_a * (long)((unsigned long)seed >> 16); - lo += (hi & 0x7FFF) << 16; - if(lo > m_max) - { - lo &= m_max; - ++lo; - } - lo += hi >> 15; - if(lo > m_max) - { - lo &= m_max; - ++lo; - } - return (long)lo; - } -public: - SimpleRandom(unsigned long init_seed) : - m_a(16807), - m_max(2147483647L), - m_rand(init_seed ? (init_seed & m_max) : 1) - {} - - Scalar random() - { - m_rand = next_long_rand(m_rand); - return Scalar(m_rand) / Scalar(m_max) - Scalar(0.5); - } - - // Vector of random numbers of type Scalar - // Ranging from -0.5 to 0.5 - Vector random_vec(const Index len) - { - Vector res(len); - for(Index i = 0; i < len; i++) - { - m_rand = next_long_rand(m_rand); - res[i] = Scalar(m_rand) / Scalar(m_max) - Scalar(0.5); - } - return res; - } -}; - - -} // namespace Spectra - -/// \endcond - -#endif // SIMPLE_RANDOM_H diff --git a/src/external/Spectra/include/Spectra/Util/TypeTraits.h b/src/external/Spectra/include/Spectra/Util/TypeTraits.h deleted file mode 100644 index a4cc05b2..00000000 --- a/src/external/Spectra/include/Spectra/Util/TypeTraits.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2018-2019 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef TYPE_TRAITS_H -#define TYPE_TRAITS_H - -#include <Eigen/Core> -#include <limits> - -/// \cond - -namespace Spectra { - - -// For a real value type "Scalar", we want to know its smallest -// positive value, i.e., std::numeric_limits<Scalar>::min(). -// However, we must take non-standard value types into account, -// so we rely on Eigen::NumTraits. -// -// Eigen::NumTraits has defined epsilon() and lowest(), but -// lowest() means negative highest(), which is a very small -// negative value. -// -// Therefore, we manually define this limit, and use eplison()^3 -// to mimic it for non-standard types. - -// Generic definition -template <typename Scalar> -struct TypeTraits -{ - static inline Scalar min() - { - return Eigen::numext::pow(Eigen::NumTraits<Scalar>::epsilon(), Scalar(3)); - } -}; - -// Full specialization -template <> -struct TypeTraits<float> -{ - static inline float min() - { - return std::numeric_limits<float>::min(); - } -}; - -template <> -struct TypeTraits<double> -{ - static inline double min() - { - return std::numeric_limits<double>::min(); - } -}; - -template <> -struct TypeTraits<long double> -{ - static inline long double min() - { - return std::numeric_limits<long double>::min(); - } -}; - - -} // namespace Spectra - -/// \endcond - -#endif // TYPE_TRAITS_H diff --git a/src/external/Spectra/include/Spectra/contrib/LOBPCGSolver.h b/src/external/Spectra/include/Spectra/contrib/LOBPCGSolver.h deleted file mode 100644 index 5ca001f6..00000000 --- a/src/external/Spectra/include/Spectra/contrib/LOBPCGSolver.h +++ /dev/null @@ -1,501 +0,0 @@ -// Written by Anna Araslanova -// Modified by Yixuan Qiu -// License: MIT - -#ifndef LOBPCG_SOLVER -#define LOBPCG_SOLVER - -#include <functional> -#include <map> - -#include <Eigen/Core> -#include <Eigen/SparseCore> -#include <Eigen/Eigenvalues> -#include <Eigen/SVD> -#include <Eigen/SparseCholesky> - -#include "../SymGEigsSolver.h" - - -namespace Spectra { - - /// - /// \ingroup EigenSolver - /// - - /// *** METHOD - /// The class represent the LOBPCG algorithm, which was invented by Andrew Knyazev - /// Theoretical background of the procedure can be found in the articles below - /// - Knyazev, A.V., 2001. Toward the optimal preconditioned eigensolver : Locally optimal block preconditioned conjugate gradient method.SIAM journal on scientific computing, 23(2), pp.517 - 541. - /// - Knyazev, A.V., Argentati, M.E., Lashuk, I. and Ovtchinnikov, E.E., 2007. Block locally optimal preconditioned eigenvalue xolvers(BLOPEX) in HYPRE and PETSc.SIAM Journal on Scientific Computing, 29(5), pp.2224 - 2239. - /// - /// *** CONDITIONS OF USE - /// Locally Optimal Block Preconditioned Conjugate Gradient(LOBPCG) is a method for finding the M smallest eigenvalues - /// and eigenvectors of a large symmetric positive definite generalized eigenvalue problem - /// \f$Ax=\lambda Bx,\f$ - /// where \f$A_{NxN}\f$ is a symmetric matrix, \f$B\f$ is symmetric and positive - definite. \f$A and B\f$ are also assumed large and sparse - /// \f$\textit{M}\f$ should be \f$\<< textit{N}\f$ (at least \f$\textit{5M} < \textit{N} \f$) - /// - /// *** ARGUMENTS - /// Eigen::SparseMatrix<long double> A; // N*N - Ax = lambda*Bx, lrage and sparse - /// Eigen::SparseMatrix<long double> X; // N*M - initial approximations to eigenvectors (random in general case) - /// Spectra::LOBPCGSolver<long double> solver(A, X); - /// *Eigen::SparseMatrix<long double> B; // N*N - Ax = lambda*Bx, sparse, positive definite - /// solver.setConstraints(B); - /// *Eigen::SparseMatrix<long double> Y; // N*K - constraints, already found eigenvectors - /// solver.setB(B); - /// *Eigen::SparseMatrix<long double> T; // N*N - preconditioner ~ A^-1 - /// solver.setPreconditioner(T); - /// - /// *** OUTCOMES - /// solver.solve(); // compute eigenpairs // void - /// solver.info(); // state of converjance // int - /// solver.residuals(); // get residuals to evaluate biases // Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> - /// solver.eigenvalues(); // get eigenvalues // Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> - /// solver.eigenvectors(); // get eigenvectors // Eigen::Matrix<Scalar, Eigen::Dynamic, 1> - /// - /// *** EXAMPLE - /// \code{.cpp} - /// #include <Spectra/contrib/SymSparseEigsSolverLOBPCG.h> - /// - /// // random A - /// Matrix a; - /// a = (Matrix::Random(10, 10).array() > 0.6).cast<long double>() * Matrix::Random(10, 10).array() * 5; - /// a = Matrix((a).triangularView<Eigen::Lower>()) + Matrix((a).triangularView<Eigen::Lower>()).transpose(); - /// for (int i = 0; i < 10; i++) - /// a(i, i) = i + 0.5; - /// std::cout << a << "\n"; - /// Eigen::SparseMatrix<long double> A(a.sparseView()); - /// // random X - /// Eigen::Matrix<long double, 10, 2> x; - /// x = Matrix::Random(10, 2).array(); - /// Eigen::SparseMatrix<long double> X(x.sparseView()); - /// // solve Ax = lambda*x - /// Spectra::LOBPCGSolver<long double> solver(A, X); - /// solver.compute(10, 1e-4); // 10 iterations, L2_tolerance = 1e-4*N - /// std::cout << "info\n" << solver.info() << std::endl; - /// std::cout << "eigenvalues\n" << solver.eigenvalues() << std::endl; - /// std::cout << "eigenvectors\n" << solver.eigenvectors() << std::endl; - /// std::cout << "residuals\n" << solver.residuals() << std::endl; - /// \endcode - /// - - template < typename Scalar = long double> - class LOBPCGSolver { - private: - - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - - typedef std::complex<Scalar> Complex; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic> ComplexMatrix; - typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> ComplexVector; - - typedef Eigen::SparseMatrix<Scalar> SparseMatrix; - typedef Eigen::SparseMatrix<Complex> SparseComplexMatrix; - - const int m_n; // dimension of matrix A - const int m_nev; // number of eigenvalues requested - SparseMatrix A, X; - SparseMatrix m_Y, m_B, m_preconditioner; - bool flag_with_constraints, flag_with_B, flag_with_preconditioner; - - public: - SparseMatrix m_residuals; - Matrix m_evectors; - Vector m_evalues; - int m_info; - - private: - - // B-orthonormalize matrix M - int orthogonalizeInPlace(SparseMatrix &M, SparseMatrix &B, \ - SparseMatrix &true_BM, bool has_true_BM = false) { - - SparseMatrix BM; - - if (has_true_BM == false) { - if (flag_with_B) { BM = B * M; } - else { BM = M; } - } - else { - BM = true_BM; - } - - Eigen::SimplicialLDLT<SparseMatrix> chol_MBM(M.transpose() * BM); - - if (chol_MBM.info() != SUCCESSFUL) { - // LDLT decomposition fail - m_info = chol_MBM.info(); - return chol_MBM.info(); - } - - SparseComplexMatrix Upper_MBM = chol_MBM.matrixU().template cast<Complex>(); - ComplexVector D_MBM_vec = chol_MBM.vectorD().template cast<Complex>(); - - D_MBM_vec = D_MBM_vec.cwiseSqrt(); - - for (int i = 0; i < D_MBM_vec.rows(); i++) { - D_MBM_vec(i) = Complex(1.0, 0.0) / D_MBM_vec(i); - } - - SparseComplexMatrix D_MBM_mat(D_MBM_vec.asDiagonal()); - - SparseComplexMatrix U_inv(Upper_MBM.rows(), Upper_MBM.cols()); - U_inv.setIdentity(); - Upper_MBM.template triangularView<Eigen::Upper>().solveInPlace(U_inv); - - SparseComplexMatrix right_product = U_inv * D_MBM_mat; - M = M*right_product.real(); - if (flag_with_B) { true_BM = B * M; } - else { true_BM = M; } - - return SUCCESSFUL; - } - - void applyConstraintsInPlace(SparseMatrix &X, SparseMatrix&Y, \ - SparseMatrix&B) { - SparseMatrix BY; - if (flag_with_B) { BY = B * Y; } - else { BY = Y; } - - SparseMatrix YBY = Y.transpose() * BY; - SparseMatrix BYX = BY.transpose() * X; - - SparseMatrix YBY_XYX = (Matrix(YBY).bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(Matrix(BYX))).sparseView(); - X = X - Y * YBY_XYX; - } - - /* - return - 'AB - CD' - */ - Matrix stack_4_matricies(Matrix A, Matrix B, \ - Matrix C, Matrix D) { - Matrix result(A.rows() + C.rows(), A.cols() + B.cols()); - result.topLeftCorner(A.rows(), A.cols()) = A; - result.topRightCorner(B.rows(), B.cols()) = B; - result.bottomLeftCorner(C.rows(), C.cols()) = C; - result.bottomRightCorner(D.rows(), D.cols()) = D; - return result; - } - - Matrix stack_9_matricies(Matrix A, Matrix B, Matrix C, \ - Matrix D, Matrix E, Matrix F, \ - Matrix G, Matrix H, Matrix I) { - - Matrix result(A.rows() + D.rows() + G.rows(), A.cols() + B.cols() + C.cols()); - result.block(0, 0, A.rows(), A.cols()) = A; - result.block(0, A.cols(), B.rows(), B.cols()) = B; - result.block(0, A.cols() + B.cols(), C.rows(), C.cols()) = C; - result.block(A.rows(), 0, D.rows(), D.cols()) = D; - result.block(A.rows(), A.cols(), E.rows(), E.cols()) = E; - result.block(A.rows(), A.cols() + B.cols(), F.rows(), F.cols()) = F; - result.block(A.rows() + D.rows(), 0, G.rows(), G.cols()) = G; - result.block(A.rows() + D.rows(), A.cols(), H.rows(), H.cols()) = H; - result.block(A.rows() + D.rows(), A.cols() + B.cols(), I.rows(), I.cols()) = I; - - return result; - } - - void sort_epairs(Vector &evalues, Matrix &evectors, int SelectionRule) { - - std::function<bool(Scalar, Scalar)> cmp; - if (SelectionRule == SMALLEST_ALGE) - cmp = std::less<Scalar>{}; - else - cmp = std::greater<Scalar>{}; - - std::map <Scalar, Vector, decltype(cmp)> epairs(cmp); - for (int i = 0; i < m_evectors.cols(); ++i) - epairs.insert(std::make_pair(evalues(i), evectors.col(i))); - - int i = 0; - for (auto& epair : epairs) { - evectors.col(i) = epair.second; - evalues(i) = epair.first; - i++; - } - } - - void removeColumns(SparseMatrix& matrix, std::vector<int>& colToRemove) - { - // remove columns through matrix multiplication - SparseMatrix new_matrix(matrix.cols(), matrix.cols() - int(colToRemove.size())); - int iCol = 0; - std::vector<Eigen::Triplet<Scalar>> tripletList; - tripletList.reserve(matrix.cols() - int(colToRemove.size())); - - for (int iRow = 0; iRow < matrix.cols(); iRow++) { - if (std::find(colToRemove.begin(), colToRemove.end(), iRow) == colToRemove.end()) { - tripletList.push_back(Eigen::Triplet<Scalar>(iRow, iCol, 1)); - iCol++; - } - } - - new_matrix.setFromTriplets(tripletList.begin(), tripletList.end()); - matrix = matrix * new_matrix; - } - - int checkConvergence_getBlocksize(SparseMatrix & m_residuals, Scalar tolerance_L2, std::vector<int> & columnsToDelete) { - // square roots from sum of squares by column - int BlockSize = m_nev; - Scalar sum, buffer; - - for (int iCol = 0; iCol < m_nev; iCol++) { - sum = 0; - for (int iRow = 0; iRow < m_n; iRow++) { - buffer = m_residuals.coeff(iRow, iCol); - sum += buffer * buffer; - } - - if (sqrt(sum) < tolerance_L2) { - BlockSize--; - columnsToDelete.push_back(iCol); - } - } - return BlockSize; - } - - - public: - - LOBPCGSolver(const SparseMatrix& A, const SparseMatrix X) : - m_n(A.rows()), - m_nev(X.cols()), - m_info(NOT_COMPUTED), - flag_with_constraints(false), - flag_with_B(false), - flag_with_preconditioner(false), - A(A), - X(X) - { - if (A.rows() != X.rows() || A.rows() != A.cols()) - throw std::invalid_argument("Wrong size"); - - //if (m_n < 5* m_nev) - // throw std::invalid_argument("The problem size is small compared to the block size. Use standard eigensolver"); - } - - void setConstraints(const SparseMatrix& Y) { - m_Y = Y; - flag_with_constraints = true; - } - - void setB(const SparseMatrix& B) { - if (B.rows() != A.rows() || B.cols() != A.cols()) - throw std::invalid_argument("Wrong size"); - m_B = B; - flag_with_B = true; - } - - void setPreconditioner(const SparseMatrix& preconditioner) { - m_preconditioner = preconditioner; - flag_with_preconditioner = true; - } - - void compute(int maxit = 10, Scalar tol_div_n = 1e-7) { - - Scalar tolerance_L2 = tol_div_n * m_n; - int BlockSize; - int max_iter = std::min(m_n, maxit); - - SparseMatrix directions, AX, AR, BX, AD, ADD, DD, BDD, BD, XAD, RAD, DAD, XBD, RBD, BR, sparse_eVecX, sparse_eVecR, sparse_eVecD, inverse_matrix; - Matrix XAR, RAR, XBR, gramA, gramB, eVecX, eVecR, eVecD; - std::vector<int> columnsToDelete; - - if (flag_with_constraints) { - // Apply the constraints Y to X - applyConstraintsInPlace(X, m_Y, m_B); - } - - // Make initial vectors orthonormal - // implicit BX declaration - if (orthogonalizeInPlace(X, m_B, BX) != SUCCESSFUL) { - max_iter = 0; - } - - AX = A * X; - // Solve the following NxN eigenvalue problem for all N eigenvalues and -vectors: - // first approximation via a dense problem - Eigen::EigenSolver<Matrix> eigs(Matrix(X.transpose() * AX)); - - if (eigs.info() != SUCCESSFUL) { - m_info = eigs.info(); - max_iter = 0; - } - else { - m_evalues = eigs.eigenvalues().real(); - m_evectors = eigs.eigenvectors().real(); - sort_epairs(m_evalues, m_evectors, SMALLEST_ALGE); - sparse_eVecX = m_evectors.sparseView(); - - X = X * sparse_eVecX; - AX = AX * sparse_eVecX; - BX = BX * sparse_eVecX; - } - - - for (int iter_num = 0; iter_num < max_iter; iter_num++) { - m_residuals.resize(m_n, m_nev); - for (int i = 0; i < m_nev; i++) { - m_residuals.col(i) = AX.col(i) - m_evalues(i) * BX.col(i); - } - BlockSize = checkConvergence_getBlocksize(m_residuals, tolerance_L2, columnsToDelete); - - if (BlockSize == 0) { - m_info = SUCCESSFUL; - break; - } - - // substitution of the original active mask - if (columnsToDelete.size() > 0) { - removeColumns(m_residuals, columnsToDelete); - if (iter_num > 0) { - removeColumns(directions, columnsToDelete); - removeColumns(AD, columnsToDelete); - removeColumns(BD, columnsToDelete); - } - columnsToDelete.clear(); // for next iteration - } - - if (flag_with_preconditioner) { - // Apply the preconditioner to the residuals - m_residuals = m_preconditioner * m_residuals; - } - - if (flag_with_constraints) { - // Apply the constraints Y to residuals - applyConstraintsInPlace(m_residuals, m_Y, m_B); - } - - if (orthogonalizeInPlace(m_residuals, m_B, BR) != SUCCESSFUL) { - break; - } - AR = A * m_residuals; - - // Orthonormalize conjugate directions - if (iter_num > 0) { - if (orthogonalizeInPlace(directions, m_B, BD, true) != SUCCESSFUL) { - break; - } - AD = A * directions; - } - - // Perform the Rayleigh Ritz Procedure - XAR = Matrix(X.transpose() * AR); - RAR = Matrix(m_residuals.transpose() * AR); - XBR = Matrix(X.transpose() * BR); - - if (iter_num > 0) { - - XAD = X.transpose() * AD; - RAD = m_residuals.transpose() * AD; - DAD = directions.transpose() * AD; - XBD = X.transpose() * BD; - RBD = m_residuals.transpose() * BD; - - gramA = stack_9_matricies(m_evalues.asDiagonal(), XAR, XAD, XAR.transpose(), RAR, RAD, XAD.transpose(), RAD.transpose(), DAD.transpose()); - gramB = stack_9_matricies(Matrix::Identity(m_nev, m_nev), XBR, XBD, XBR.transpose(), Matrix::Identity(BlockSize, BlockSize), RBD, XBD.transpose(), RBD.transpose(), Matrix::Identity(BlockSize, BlockSize)); - - } - else { - gramA = stack_4_matricies(m_evalues.asDiagonal(), XAR, XAR.transpose(), RAR); - gramB = stack_4_matricies(Matrix::Identity(m_nev, m_nev), XBR, XBR.transpose(), Matrix::Identity(BlockSize, BlockSize)); - } - - //calculate the lowest/largest m eigenpairs; Solve the generalized eigenvalue problem. - DenseSymMatProd<Scalar> Aop(gramA); - DenseCholesky<Scalar> Bop(gramB); - - SymGEigsSolver<Scalar, SMALLEST_ALGE, DenseSymMatProd<Scalar>, \ - DenseCholesky<Scalar>, GEIGS_CHOLESKY> geigs(&Aop, &Bop, m_nev, std::min(10, int(gramA.rows()) - 1)); - - geigs.init(); - int nconv = geigs.compute(); - - //Mat evecs; - if (geigs.info() == SUCCESSFUL) { - m_evalues = geigs.eigenvalues(); - m_evectors = geigs.eigenvectors(); - sort_epairs(m_evalues, m_evectors, SMALLEST_ALGE); - } - else { - // Problem With General EgenVec - m_info = geigs.info(); - break; - } - - // Compute Ritz vectors - if (iter_num > 0) { - eVecX = m_evectors.block(0, 0, m_nev, m_nev); - eVecR = m_evectors.block(m_nev, 0, BlockSize, m_nev); - eVecD = m_evectors.block(m_nev + BlockSize, 0, BlockSize, m_nev); - - sparse_eVecX = eVecX.sparseView(); - sparse_eVecR = eVecR.sparseView(); - sparse_eVecD = eVecD.sparseView(); - - DD = m_residuals * sparse_eVecR; // new conjugate directions - ADD = AR * sparse_eVecR; - BDD = BR * sparse_eVecR; - - DD = DD + directions * sparse_eVecD; - ADD = ADD + AD * sparse_eVecD; - BDD = BDD + BD * sparse_eVecD; - } - else { - eVecX = m_evectors.block(0, 0, m_nev, m_nev); - eVecR = m_evectors.block(m_nev, 0, BlockSize, m_nev); - - sparse_eVecX = eVecX.sparseView(); - sparse_eVecR = eVecR.sparseView(); - - DD = m_residuals * sparse_eVecR; - ADD = AR * sparse_eVecR; - BDD = BR * sparse_eVecR; - } - - X = X * sparse_eVecX + DD; - AX = AX * sparse_eVecX + ADD; - BX = BX * sparse_eVecX + BDD; - - directions = DD; - AD = ADD; - BD = BDD; - - } // iteration loop - - // calculate last residuals - m_residuals.resize(m_n, m_nev); - for (int i = 0; i < m_nev; i++) { - m_residuals.col(i) = AX.col(i) - m_evalues(i) * BX.col(i); - } - BlockSize = checkConvergence_getBlocksize(m_residuals, tolerance_L2, columnsToDelete); - - if (BlockSize == 0) { - m_info = SUCCESSFUL; - } - } // compute - - Vector eigenvalues() { - return m_evalues; - } - - Matrix eigenvectors() { - return m_evectors; - } - - Matrix residuals() { - return Matrix(m_residuals); - } - - int info() { return m_info; } - - }; - - -} // namespace Spectra - -#endif // LOBPCG_SOLVER diff --git a/src/external/Spectra/include/Spectra/contrib/PartialSVDSolver.h b/src/external/Spectra/include/Spectra/contrib/PartialSVDSolver.h deleted file mode 100644 index dad5b400..00000000 --- a/src/external/Spectra/include/Spectra/contrib/PartialSVDSolver.h +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (C) 2018 Yixuan Qiu <yixuan.qiu@cos.name> -// -// This Source Code Form is subject to the terms of the Mozilla -// Public License v. 2.0. If a copy of the MPL was not distributed -// with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#ifndef PARTIAL_SVD_SOLVER_H -#define PARTIAL_SVD_SOLVER_H - -#include <Eigen/Core> -#include "../SymEigsSolver.h" - - -namespace Spectra { - - -// Abstract class for matrix operation -template <typename Scalar> -class SVDMatOp -{ -public: - virtual int rows() const = 0; - virtual int cols() const = 0; - - // y_out = A' * A * x_in or y_out = A * A' * x_in - virtual void perform_op(const Scalar* x_in, Scalar* y_out) = 0; - - virtual ~SVDMatOp() {} -}; - -// Operation of a tall matrix in SVD -// We compute the eigenvalues of A' * A -// MatrixType is either Eigen::Matrix<Scalar, ...> or Eigen::SparseMatrix<Scalar, ...> -template <typename Scalar, typename MatrixType> -class SVDTallMatOp: public SVDMatOp<Scalar> -{ -private: - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef const Eigen::Ref<const MatrixType> ConstGenericMatrix; - - ConstGenericMatrix m_mat; - const int m_dim; - Vector m_cache; - -public: - // Constructor - SVDTallMatOp(ConstGenericMatrix& mat) : - m_mat(mat), - m_dim(std::min(mat.rows(), mat.cols())), - m_cache(mat.rows()) - {} - - // These are the rows and columns of A' * A - int rows() const { return m_dim; } - int cols() const { return m_dim; } - - // y_out = A' * A * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) - { - MapConstVec x(x_in, m_mat.cols()); - MapVec y(y_out, m_mat.cols()); - m_cache.noalias() = m_mat * x; - y.noalias() = m_mat.transpose() * m_cache; - } -}; - -// Operation of a wide matrix in SVD -// We compute the eigenvalues of A * A' -// MatrixType is either Eigen::Matrix<Scalar, ...> or Eigen::SparseMatrix<Scalar, ...> -template <typename Scalar, typename MatrixType> -class SVDWideMatOp: public SVDMatOp<Scalar> -{ -private: - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef Eigen::Map<const Vector> MapConstVec; - typedef Eigen::Map<Vector> MapVec; - typedef const Eigen::Ref<const MatrixType> ConstGenericMatrix; - - ConstGenericMatrix m_mat; - const int m_dim; - Vector m_cache; - -public: - // Constructor - SVDWideMatOp(ConstGenericMatrix& mat) : - m_mat(mat), - m_dim(std::min(mat.rows(), mat.cols())), - m_cache(mat.cols()) - {} - - // These are the rows and columns of A * A' - int rows() const { return m_dim; } - int cols() const { return m_dim; } - - // y_out = A * A' * x_in - void perform_op(const Scalar* x_in, Scalar* y_out) - { - MapConstVec x(x_in, m_mat.rows()); - MapVec y(y_out, m_mat.rows()); - m_cache.noalias() = m_mat.transpose() * x; - y.noalias() = m_mat * m_cache; - } -}; - -// Partial SVD solver -// MatrixType is either Eigen::Matrix<Scalar, ...> or Eigen::SparseMatrix<Scalar, ...> -template < typename Scalar = double, - typename MatrixType = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> > -class PartialSVDSolver -{ -private: - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix; - typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1> Vector; - typedef const Eigen::Ref<const MatrixType> ConstGenericMatrix; - - ConstGenericMatrix m_mat; - const int m_m; - const int m_n; - SVDMatOp<Scalar>* m_op; - SymEigsSolver< Scalar, LARGEST_ALGE, SVDMatOp<Scalar> >* m_eigs; - int m_nconv; - Matrix m_evecs; - -public: - // Constructor - PartialSVDSolver(ConstGenericMatrix& mat, int ncomp, int ncv) : - m_mat(mat), m_m(mat.rows()), m_n(mat.cols()), m_evecs(0, 0) - { - // Determine the matrix type, tall or wide - if(m_m > m_n) - { - m_op = new SVDTallMatOp<Scalar, MatrixType>(mat); - } else { - m_op = new SVDWideMatOp<Scalar, MatrixType>(mat); - } - - // Solver object - m_eigs = new SymEigsSolver< Scalar, LARGEST_ALGE, SVDMatOp<Scalar> >(m_op, ncomp, ncv); - } - - // Destructor - virtual ~PartialSVDSolver() - { - delete m_eigs; - delete m_op; - } - - // Computation - int compute(int maxit = 1000, Scalar tol = 1e-10) - { - m_eigs->init(); - m_nconv = m_eigs->compute(maxit, tol); - - return m_nconv; - } - - // The converged singular values - Vector singular_values() const - { - Vector svals = m_eigs->eigenvalues().cwiseSqrt(); - - return svals; - } - - // The converged left singular vectors - Matrix matrix_U(int nu) - { - if(m_evecs.cols() < 1) - { - m_evecs = m_eigs->eigenvectors(); - } - nu = std::min(nu, m_nconv); - if(m_m <= m_n) - { - return m_evecs.leftCols(nu); - } - - return m_mat * (m_evecs.leftCols(nu).array().rowwise() / m_eigs->eigenvalues().head(nu).transpose().array().sqrt()).matrix(); - } - - // The converged right singular vectors - Matrix matrix_V(int nv) - { - if(m_evecs.cols() < 1) - { - m_evecs = m_eigs->eigenvectors(); - } - nv = std::min(nv, m_nconv); - if(m_m > m_n) - { - return m_evecs.leftCols(nv); - } - - return m_mat.transpose() * (m_evecs.leftCols(nv).array().rowwise() / m_eigs->eigenvalues().head(nv).transpose().array().sqrt()).matrix(); - } -}; - - -} // namespace Spectra - -#endif // PARTIAL_SVD_SOLVER_H diff --git a/src/external/arpack++/include/README b/src/external/arpack++/include/README deleted file mode 100644 index dc4a33dc..00000000 --- a/src/external/arpack++/include/README +++ /dev/null @@ -1,232 +0,0 @@ -This is the ARPACK++ include directory. - -1) Files included in this directory: - - a) Files that contain ARPACK++ classes definitions: - - i) Base classes: - - file class - ---------- ---------------- - arrseig.h ARrcStdEig - arrgeig.h ARrcGenEig - arseig.h ARStdEig - argeig.h ARGenEig - armat.h ARMatrix - - - ii) Classes that require matrix-vector product functions: - - file class - ---------- ---------------- - arssym.h ARSymStdEig - arsnsym.h ARNonSymStdEig - arscomp.h ARCompStdEig - argsym.h ARSymGenEig - argnsym.h ARNonSymGenEig - argcomp.g ARCompGenEig - - - iii) Classes that require matrices in CSC format (SuperLU version): - - file class - ---------- ---------------- - arlssym.h ARluSymStdEig - arlsnsym.h ARluNonSymStdEig - arlscomp.h ARluCompStdEig - arlgsym.h ARluSymGenEig - arlgnsym.h ARluNonSymGenEig - arlgcomp.h ARluCompGenEig - - - iv) Classes that require matrices in CSC format (UMFPACK version): - - file class - ---------- ---------------- - arussym.h ARluSymStdEig - arusnsym.h ARluNonSymStdEig - aruscomp.h ARluCompStdEig - arugsym.h ARluSymGenEig - arugnsym.h ARluNonSymGenEig - arugcomp.h ARluCompGenEig - - - v) Classes that require matrices in band format: - - file class - ---------- ---------------- - arbssym.h ARluSymStdEig - arbsnsym.h ARluNonSymStdEig - arbscomp.h ARluCompStdEig - arbgsym.h ARluSymGenEig - arbgnsym.h ARluNonSymGenEig - arbgcomp.h ARluCompGenEig - - - vi) Reverse communication classes: - - file class - ---------- ---------------- - arrssym.h ARrcSymStdEig - arrsnsym.h ARrcNonSymStdEig - arrscomp.h ARrcCompStdEig - arrgsym.h ARrcSymGenEig - arrgnsym.h ARrcNonSymGenEig - arrgcomp.h ARrcCompGenEig - - - vii) Matrix classes: - - file class - ---------- ---------------- - arlsmat.h ARluSymMatrix - arlspen.h ARluSymPencil - arlnsmat.h ARluNonSymMatrix - arlnspen.h ARluNonSymPencil - arusmat.h ARumSymMatrix - aruspen.h ARumSymPencil - arunsmat.h ARumNonSymMatrix - arunspen.h ARumNonSymPencil - arbsmat.h ARbdSymMatrix - arbspen.h ARbdSymPencil - arbnsmat.h ARbdNonSymMatrix - arbnspen.h ARbdNonSymPencil - arhbmat.h ARhbMatrix - - - b) Package interface files: - - i) ARPACK FORTRAN interface: - - file Contents - ---------- ----------------------------------------------- - saupp.h Interface with dsaupd and ssaupd subroutines. - seupp.h Interface with dseupd and sseupd subroutines. - naupp.h Interface with dnaupd and snaupd subroutines. - neupp.h Interface with dneupd and sneupd subroutines. - caupp.h Interface with znaupd and cnaupd subroutines. - ceupp.h Interface with zneupd and cneupd subroutines. - debug.h Interface with ARPACK debugging variables. - arpackf.h Fortran to C function prototypes convertion. - - - ii) LAPACK and BLAS1 interface: - - file Contents - ---------- ----------------------------------------------- - lapackc.h Various LAPACK function declarations. - lapackf.h Fortran to C function prototypes convertion. - blas1c.h Various BLAS1 function declarations. - blas1f.h Fortran to C function prototypes convertion. - - - iii) SuperLU interface: - - file Contents - ---------- ----------------------------------------------- - superluc.h Various SuperLU function declarations. - arlspdef.h Altered version of ssp_defs.h, dsp_defs.h, - csp_defs.h and zsp_defs.h header files. - arlsupm.h Unaltered copy of supermatrix.h header file. - arlnames.h Unaltered copy of Cnames.h header file. - arlutil.h Unaltered copy of util.h, superlu_enum_consts.h. - arlcomp.h Unaltered copy of dcomplex.h and scomplex.h. - - - iv) UMFPACK interface: - - file Contents - ---------- ----------------------------------------------- - umfpackc.h Various UMFPACK function declarations. - umfpackf.h Fortran to C function prototypes convertion. - - - c) Other auxiliary files: - - file Contents - ---------- ----------------------------------------------- - arch.h Machine dependent functions and variable types. - arcomp.h "arcomplex" complex type definition. - arerror.h "ArpackError" class definition. - - - -2) Compiler-dependent instructions. - - Some compiler-dependent functions and data types used by arpack++ are - grouped in the file arch.h. This file should be changed to reflect the - characteristics of your system. Another file, arcomp.h, contains the - definition of a class template called arcomplex, created to emulate - the g++ complex class when another compiler is being used. This file - must also be changed if g++ (or CC) is not being used. - - a) Changing ARPACK++ parameters and definitions included in arch.h: - - All ARPACK++ parameters that are not intended to be changed frequently - were included in the arch.h file. Are defined in this file - - i) Some machine and problem-dependent umfpack parameters. - - If the umfpack is to be used, the user can modify some of its - parameters to correctly reflect the environment and the class - of problems being solved. The constants included in arch.h - correspond to a subset of the parameters generated by the um21i - umfpack function. Other relevant parameters can also be passed - to the ARumNonSymMatrix class constructor. - - ii) Some fortran to c conversion functions. - - Because fortran and c++ functions tend to have different - representations in different platforms, a function that - converts a fortran function name to the c++ format is - defined in arch.h. This function can be altered by the user - if the environment being used was not included in arch.h. - - iii) Some fortran to c type conversion rules. - - arch.h also includes the definition of some rules required - to convert INTEGER and LOGICAL FORTRAN types to c++. - - iv) The c++ bool type. - - If the c++ compiler being used does not include a bool type, - this type can also be defined in arch.h. - - - b) Redefining arcomplex class in arcomp.h: - - ARPACK++ uses a self-defined complex class called arcomplex. - Actually, arcomplex is a class template used to represent - both single and double precision complex numbers. It was created - in an effort to permit ARPACK++ to deal with different compilers, - since c++ does not define a unique complex type. - arcomplex is intended to emulate the gnu g++ complex class when - other compilers are being used (when g++ is used, ARPACK++ simply - declares arcomplex to be the standard complex type). arcomp.h - includes a complex class definition for the CC compiler only. At - the present time, no other compiler was used to generate ARPACK++ - programs, so further work must be done to permit the use of the - library with other compilers. - To define a new complex type, the user must create a class - template (called arcomplex) that contains at least three members: - - i) A default constructor; - ii) A copy constructor; and - iii) A constructor that takes two real numbers as parameters (one - is the real and other the imaginary part of the complex number). - - Naturally, all usual mathematical operations on complex numbers, - such as addition, multiplication, multiplication by a real number, - etc, should also be defined. But because most compilers include a - complex data type, the simplest way of defining arcomplex is to use - only the three constructors mentioned above to establish a relation - between the actual complex class and the gnu g++ standard. - - -5) ARPACK (fortran) authors: - - Danny Sorensen (sorensen@caam.rice.edu) - Richard Lehoucq (lehoucq@mcs.anl.gov) - Chao Yang (chao@caam.rice.edu) - Kristi Maschhoff (kristyn@caam.rice.edu) - diff --git a/src/external/arpack++/include/arbgcomp.h b/src/external/arpack++/include/arbgcomp.h deleted file mode 100644 index 93f68228..00000000 --- a/src/external/arpack++/include/arbgcomp.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBGComp.h. - Arpack++ class ARluCompGenEig definition - (band matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARBGCOMP_H -#define ARBGCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arbnsmat.h" -#include "arbnspen.h" -#include "arrseig.h" -#include "argcomp.h" - - -template<class ARFLOAT> -class ARluCompGenEig: - public virtual - ARCompGenEig<ARFLOAT, ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT >, - ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT > > { - - private: - - // a) Data structure used to store matrices. - - ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT > Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluCompGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(arcomplex<ARFLOAT> sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(arcomplex<ARFLOAT> sigmap); - - // c.2) Constructors and destructor. - - ARluCompGenEig() { } - // Short constructor. - - ARluCompGenEig(int nevp, ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluCompGenEig(int nevp, ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluCompGenEig(const ARluCompGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluCompGenEig() { } - - // d) Operators. - - ARluCompGenEig& operator=(const ARluCompGenEig& other); - // Assignment operator. - -}; // class ARluCompGenEig. - - -// ------------------------------------------------------------------------ // -// ARluCompGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -Copy(const ARluCompGenEig<ARFLOAT>& other) -{ - - ARCompGenEig<ARFLOAT, ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT >, - ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -ChangeShift(arcomplex<ARFLOAT> sigmaRp) -{ - - this->objOP->FactorAsB(sigmaRp); - ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> >::ChangeShift(sigmaRp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetRegularMode(&Pencil, - &ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -SetShiftInvertMode(arcomplex<ARFLOAT> sigmap) -{ - - ARCompGenEig<ARFLOAT, ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>, - ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, - &ARbdNonSymPencil<arcomplex<ARFLOAT>,ARFLOAT>::MultInvAsBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluCompGenEig<ARFLOAT>:: -ARluCompGenEig(int nevp, ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, - arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvBAv, - &Pencil, - &ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultBv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluCompGenEig<ARFLOAT>:: -ARluCompGenEig(int nevp, ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARbdNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvAsBv, - &Pencil, - &ARbdNonSymPencil<arcomplex<ARFLOAT>,ARFLOAT>::MultBv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - SetShiftInvertMode(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluCompGenEig<ARFLOAT>& ARluCompGenEig<ARFLOAT>:: -operator=(const ARluCompGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBGCOMP_H diff --git a/src/external/arpack++/include/arbgnsym.h b/src/external/arpack++/include/arbgnsym.h deleted file mode 100644 index 19a14130..00000000 --- a/src/external/arpack++/include/arbgnsym.h +++ /dev/null @@ -1,243 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBGNSym.h. - Arpack++ class ARluNonSymGenEig definition - (band matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARBGNSYM_H -#define ARBGNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arbnsmat.h" -#include "arbnspen.h" -#include "argnsym.h" - - -template<class ARFLOAT> -class ARluNonSymGenEig: - public virtual ARNonSymGenEig<ARFLOAT, ARbdNonSymPencil<ARFLOAT, ARFLOAT>, - ARbdNonSymPencil<ARFLOAT, ARFLOAT> > { - - private: - - // a) Data structure used to store matrices. - - ARbdNonSymPencil<ARFLOAT, ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluNonSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp = 0.0); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetComplexShiftMode(char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp); - - // c.2) Constructors and destructor. - - ARluNonSymGenEig() { } - // Short constructor. - - ARluNonSymGenEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluNonSymGenEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& B, ARFLOAT sigma, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (real shift and invert mode). - - ARluNonSymGenEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& B, char partp, - ARFLOAT sigmaRp, ARFLOAT sigmaIp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (complex shift and invert mode). - - ARluNonSymGenEig(const ARluNonSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluNonSymGenEig& operator=(const ARluNonSymGenEig& other); - // Assignment operator. - -}; // class ARluNonSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluNonSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -Copy(const ARluNonSymGenEig<ARFLOAT>& other) -{ - - ARNonSymGenEig<ARFLOAT, ARbdNonSymPencil<ARFLOAT, ARFLOAT>, - ARbdNonSymPencil<ARFLOAT, ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - if (sigmaIp == 0.0) { - this->objOP->FactorAsB(sigmaRp); - } - else { - this->objOP->FactorAsB(sigmaRp, sigmaIp, this->part); - } - ARrcNonSymGenEig<ARFLOAT>::ChangeShift(sigmaRp, sigmaIp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARbdNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetRegularMode(&Pencil, &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARNonSymGenEig<ARFLOAT, ARbdNonSymPencil<ARFLOAT, ARFLOAT>, - ARbdNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, - &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -SetComplexShiftMode(char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - ARNonSymGenEig<ARFLOAT, ARbdNonSymPencil<ARFLOAT, ARFLOAT>, - ARbdNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetComplexShiftMode(partp, sigmaRp, sigmaIp, &Pencil, - &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, - &Pencil, &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultAv); - -} // SetComplexShiftMode. - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultInvBAv, &Pencil, - &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, &Pencil, - &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - SetShiftInvertMode(sigmap); - -} // Long constructor (real shift and invert mode). - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& B, char partp, - ARFLOAT sigmaRp, ARFLOAT sigmaIp, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, &Pencil, - &ARbdNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - SetComplexShiftMode(partp, sigmaRp, sigmaIp); - -} // Long constructor (complex shift and invert mode). - - -template<class ARFLOAT> -ARluNonSymGenEig<ARFLOAT>& ARluNonSymGenEig<ARFLOAT>:: -operator=(const ARluNonSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBGNSYM_H diff --git a/src/external/arpack++/include/arbgsym.h b/src/external/arpack++/include/arbgsym.h deleted file mode 100644 index 82926bca..00000000 --- a/src/external/arpack++/include/arbgsym.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBGSym.h. - Arpack++ class ARluSymGenEig definition - (band matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARBGSYM_H -#define ARBGSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arbsmat.h" -#include "arbspen.h" -#include "argsym.h" - - -template<class ARFLOAT> -class ARluSymGenEig: - public virtual ARSymGenEig<ARFLOAT, ARbdSymPencil<ARFLOAT>, - ARbdSymPencil<ARFLOAT> > { - - private: - - // a) Data structure used to store matrices. - - ARbdSymPencil<ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmap); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetBucklingMode(ARFLOAT sigmap); - - virtual void SetCayleyMode(ARFLOAT sigmap); - - // c.2) Constructors and destructor. - - ARluSymGenEig() { } - // Short constructor. - - ARluSymGenEig(int nevp, ARbdSymMatrix<ARFLOAT>& A, - ARbdSymMatrix<ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymGenEig(char InvertModep, int nevp, ARbdSymMatrix<ARFLOAT>& A, - ARbdSymMatrix<ARFLOAT>& B, ARFLOAT sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert, buckling and Cayley modes). - - ARluSymGenEig(const ARluSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluSymGenEig& operator=(const ARluSymGenEig& other); - // Assignment operator. - -}; // class ARluSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -Copy(const ARluSymGenEig<ARFLOAT>& other) -{ - - ARSymGenEig<ARFLOAT, ARbdSymPencil<ARFLOAT>, - ARbdSymPencil<ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::ChangeShift(ARFLOAT sigmap) -{ - - this->objOP->FactorAsB(sigmap); - ARrcSymGenEig<ARFLOAT>::ChangeShift(sigmap); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARbdSymPencil<ARFLOAT> >:: - SetRegularMode(&Pencil, &ARbdSymPencil<ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARbdSymPencil<ARFLOAT>, ARbdSymPencil<ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, &ARbdSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARbdSymPencil<ARFLOAT>::MultBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetBucklingMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARbdSymPencil<ARFLOAT>, ARbdSymPencil<ARFLOAT> >:: - SetBucklingMode(sigmap, &Pencil, &ARbdSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARbdSymPencil<ARFLOAT>::MultAv); - -} // SetBucklingMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetCayleyMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARbdSymPencil<ARFLOAT>, ARbdSymPencil<ARFLOAT> >:: - SetCayleyMode(sigmap, &Pencil, &ARbdSymPencil<ARFLOAT>::MultInvAsBv, - &Pencil, &ARbdSymPencil<ARFLOAT>::MultAv); - this->ChangeMultBx(&Pencil, &ARbdSymPencil<ARFLOAT>::MultBv); - -} // SetCayleyMode. - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(int nevp, ARbdSymMatrix<ARFLOAT>& A, - ARbdSymMatrix<ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->InvertMode = 'S'; - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARbdSymPencil<ARFLOAT>::MultInvBAv, &Pencil, - &ARbdSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(char InvertModep, int nevp, ARbdSymMatrix<ARFLOAT>& A, - ARbdSymMatrix<ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARbdSymPencil<ARFLOAT>::MultInvAsBv, &Pencil, - &ARbdSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - this->InvertMode = this->CheckInvertMode(InvertModep); - switch (this->InvertMode) { - case 'B': - this->ChangeMultBx(&Pencil, &ARbdSymPencil<ARFLOAT>::MultAv); - case 'S': - ChangeShift(sigmap); - break; - case 'C': - SetCayleyMode(sigmap); - } - -} // Long constructor (shift and invert, buckling and Cayley modes). - - -template<class ARFLOAT> -ARluSymGenEig<ARFLOAT>& ARluSymGenEig<ARFLOAT>:: -operator=(const ARluSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBGSYM_H diff --git a/src/external/arpack++/include/arbnsmat.h b/src/external/arpack++/include/arbnsmat.h deleted file mode 100644 index f56069f7..00000000 --- a/src/external/arpack++/include/arbnsmat.h +++ /dev/null @@ -1,431 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBNSMat.h. - Arpack++ class ARbdNonSymMatrix definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "arbnspen.h" - -#ifndef ARBNSMAT_H -#define ARBNSMAT_H - -#include <cstddef> -#include "arch.h" -#include "armat.h" -#include "arerror.h" -#include "blas1c.h" -#include "lapackc.h" - -template<class AR_T, class AR_S> class ARbdNonSymPencil; - -template<class ARTYPE, class ARFLOAT> -class ARbdNonSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARbdNonSymPencil<ARTYPE, ARFLOAT>; - friend class ARbdNonSymPencil<ARFLOAT, ARFLOAT>; - - protected: - - bool factored; - int ndiagL; - int ndiagU; - int lda; - int info; - int* ipiv; - ARTYPE* A; - ARTYPE* Ainv; - - void ClearMem(); - - virtual void Copy(const ARbdNonSymMatrix& other); - - void ExpandA(); - - void SubtractAsI(ARTYPE sigma); - - void CreateStructure(); - - void ThrowError(); - - public: - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultMtv(ARTYPE* v, ARTYPE* w); - - void MultMtMv(ARTYPE* v, ARTYPE* w); - - void MultMMtv(ARTYPE* v, ARTYPE* w); - - void Mult0MMt0v(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, int ndiagLp, int ndiagUp, ARTYPE* Ap); - - ARbdNonSymMatrix(): ARMatrix<ARTYPE>() { factored = false; } - // Short constructor that does nothing. - - ARbdNonSymMatrix(int np, int ndiagLp, int ndiagUp, ARTYPE* Ap); - // Long constructor. - - ARbdNonSymMatrix(const ARbdNonSymMatrix& other) { Copy(other); } - // Copy constructor. - - virtual ~ARbdNonSymMatrix() { ClearMem(); } - // Destructor. - - ARbdNonSymMatrix& operator=(const ARbdNonSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARbdNonSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE, class ARFLOAT> -inline void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::ClearMem() -{ - - if (factored) { - delete[] Ainv; - delete[] ipiv; - Ainv = NULL; - ipiv = NULL; - } - -} // ClearMem. - - -template<class ARTYPE, class ARFLOAT> -inline void ARbdNonSymMatrix<ARTYPE, ARFLOAT>:: -Copy(const ARbdNonSymMatrix<ARTYPE, ARFLOAT>& other) -{ - - // Copying very fundamental variables and user-defined parameters. - - this->m = other.m; - this->n = other.n; - this->defined = other.defined; - factored = other.factored; - ndiagL = other.ndiagL; - ndiagU = other.ndiagU; - lda = other.lda; - info = other.info; - A = other.A; - - // Returning from here if "other" was not factored. - - if (!factored) return; - - // Copying vectors. - - Ainv = new ARTYPE[ this->n*lda]; - ipiv = new int[ this->n]; - - copy( this->n*lda, other.Ainv, 1, Ainv, 1); - for (int i=0; i< this->n; i++) ipiv[i] = other.ipiv[i]; - -} // Copy. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::ExpandA() -{ - - int i, inca; - - // Copying A to Ainv. - - inca = ndiagL+ndiagU+1; - for (i = 0; i < inca; i++) { - copy( this->n, &A[i], inca, &Ainv[ndiagL+i], lda); - } - -} // ExpandA. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::SubtractAsI(ARTYPE sigma) -{ - - // Copying A to Ainv. - - ExpandA(); - - // Subtracting sigma from diagonal elements. - - for (int i=(ndiagL+ndiagU); i<(lda* this->n); i+=lda) Ainv[i] -= sigma; - -} // SubtractAsI. - - -template<class ARTYPE, class ARFLOAT> -inline void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::CreateStructure() -{ - - ClearMem(); - Ainv = new ARTYPE[lda* this->n]; - ipiv = new int[ this->n]; - -} // CreateStructure. - - -template<class ARTYPE, class ARFLOAT> -inline void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::ThrowError() -{ - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARbdNonSymMatrix::FactorA"); - } - else if (info) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARbdNonSymMatrix::FactorA"); - } - -} // ThrowError. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::FactorA() -{ - - // Quitting the function if A was not defined. - - if (! this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARbdNonSymMatrix::FactorA"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Copying A to Ainv; - - ExpandA(); - - // Decomposing A. - - gbtrf( this->n, this->n, ndiagL, ndiagU, Ainv, lda, ipiv, info); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorA. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::FactorAsI(ARTYPE sigma) -{ - - // Quitting the function if A was not defined. - - if (! this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARbdNonSymMatrix::FactorAsI"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Subtracting sigma*I from A. - - SubtractAsI(sigma); - - // Decomposing AsI. - - gbtrf( this->n, this->n, ndiagL, ndiagU, Ainv, lda, ipiv, info); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorAsI. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::MultMv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE one; - ARTYPE zero; - - one = (ARTYPE)0 + 1.0; - zero = (ARTYPE)0; - - // Quitting the function if A was not defined. - - if (! this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARbdNonSymMatrix::MultMv"); - } - - // Determining w = M.v. - - gbmv("N", this->m, this->n, ndiagL, ndiagU, one, A, - ndiagL+ndiagU+1, v, 1, zero, w, 1); - -} // MultMv. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::MultMtv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE one; - ARTYPE zero; - - one = (ARTYPE)0 + 1.0; - zero = (ARTYPE)0; - - // Quitting the function if A was not defined. - - if (! this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARbdNonSymMatrix::MultMtv"); - } - - // Determining w = M'.v. - - gbmv("T", this->m, this->n, ndiagL, ndiagU, one, A, - ndiagL+ndiagU+1, v, 1, zero, w, 1); - -} // MultMtv. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::MultMtMv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE* t = new ARTYPE[ this->m]; - - MultMv(v,t); - MultMtv(t,w); - - delete[] t; - -} // MultMtMv. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::MultMMtv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE* t = new ARTYPE[ this->n]; - - MultMtv(v,t); - MultMv(t,w); - - delete[] t; - -} // MultMMtv. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::Mult0MMt0v(ARTYPE* v, ARTYPE* w) -{ - - MultMv(&v[ this->m],w); - MultMtv(v,&w[ this->m]); - -} // Mult0MMt0v. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymMatrix<ARTYPE, ARFLOAT>::MultInvv(ARTYPE* v, ARTYPE* w) -{ - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARbdNonSymMatrix::MultInvv"); - } - - // Overwritting w with v. - - copy( this->n, v, 1, w, 1); - - // Solving A.w = v (or AsI.w = v). - - gbtrs("N", this->n, ndiagL, ndiagU, 1, Ainv, lda, ipiv, w, this->m, info); - - // Handling errors. - - ThrowError(); - -} // MultInvv. - - -template<class ARTYPE, class ARFLOAT> -inline void ARbdNonSymMatrix<ARTYPE, ARFLOAT>:: -DefineMatrix(int np, int ndiagLp, int ndiagUp, ARTYPE* Ap) -{ - - // Defining member variables. - - this->m = np; - this->n = np; - ndiagL = ndiagLp; - ndiagU = ndiagUp; - lda = 2*ndiagL+ndiagU+1; - A = Ap; - this->defined = true; - Ainv = NULL; - ipiv = NULL; - info = 0; - -} // DefineMatrix. - - -template<class ARTYPE, class ARFLOAT> -inline ARbdNonSymMatrix<ARTYPE, ARFLOAT>:: -ARbdNonSymMatrix(int np, int ndiagLp, - int ndiagUp, ARTYPE* Ap) : ARMatrix<ARTYPE>(np) -{ - - factored = false; - DefineMatrix(np, ndiagLp, ndiagUp, Ap); - -} // Long constructor. - - -template<class ARTYPE, class ARFLOAT> -ARbdNonSymMatrix<ARTYPE, ARFLOAT>& ARbdNonSymMatrix<ARTYPE, ARFLOAT>:: -operator=(const ARbdNonSymMatrix<ARTYPE, ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBNSMAT_H diff --git a/src/external/arpack++/include/arbnspen.h b/src/external/arpack++/include/arbnspen.h deleted file mode 100644 index 2284ffa3..00000000 --- a/src/external/arpack++/include/arbnspen.h +++ /dev/null @@ -1,470 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBNSPen.h. - Arpack++ class ARbdNonSymPencil definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARBNSPEN_H -#define ARBNSPEN_H - -#include "arch.h" -#include "arerror.h" -#include "blas1c.h" -#include "lapackc.h" -#include "arbnsmat.h" - - -template<class ARTYPE, class ARFLOAT> -class ARbdNonSymPencil -{ - - protected: - - char part; - ARbdNonSymMatrix<ARTYPE, ARFLOAT>* A; - ARbdNonSymMatrix<ARTYPE, ARFLOAT>* B; - ARbdNonSymMatrix<ARTYPE, ARFLOAT> AsB; -#ifdef ARCOMP_H - ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> AsBc; -#endif - - int max(int a, int b) { return (a>b)?a:b; } - - int min(int a, int b) { return (a<b)?a:b; } - - void ComplexCopy(int n, ARFLOAT dx[], int incx, - arcomplex<ARFLOAT> dy[], int incy); - - void ComplexAxpy(int n, arcomplex<ARFLOAT> da, ARTYPE dx[], - int incx, arcomplex<ARFLOAT> dy[], int incy); - - virtual void Copy(const ARbdNonSymPencil& other); - - void SubtractAsB(ARTYPE sigma); - -#ifdef ARCOMP_H - void SubtractAsB(ARFLOAT sigmaR, ARFLOAT sigmaI); -#endif - - public: - -#ifdef ARCOMP_H - bool IsFactored() { return (AsB.IsFactored()||AsBc.IsFactored()); } -#else - bool IsFactored() { return AsB.IsFactored(); } -#endif - - void FactorAsB(ARTYPE sigma); - -#ifdef ARCOMP_H - void FactorAsB(ARFLOAT sigmaR, ARFLOAT sigmaI, char partp = 'R'); -#endif - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - -#ifdef ARCOMP_H - void MultInvAsBv(arcomplex<ARFLOAT>* v, arcomplex<ARFLOAT>* w); -#endif - - void MultInvAsBv(ARFLOAT* v, ARFLOAT* w); - - void DefineMatrices(ARbdNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARbdNonSymMatrix<ARTYPE, ARFLOAT>& Bp); - - ARbdNonSymPencil() { part = 'N'; } - // Short constructor that does nothing. - - ARbdNonSymPencil(ARbdNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARbdNonSymMatrix<ARTYPE, ARFLOAT>& Bp); - // Long constructor. - - ARbdNonSymPencil(const ARbdNonSymPencil& other) { Copy(other); } - // Copy constructor. - - virtual ~ARbdNonSymPencil() { } - // Destructor. - - ARbdNonSymPencil& operator=(const ARbdNonSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARbdNonSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE, class ARFLOAT> -inline void ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -Copy(const ARbdNonSymPencil<ARTYPE, ARFLOAT>& other) -{ - - part = other.part; - A = other.A; - B = other.B; - AsB = other.AsB; -#ifdef ARCOMP_H - AsBc = other.AsBc; -#endif - -} // Copy. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -ComplexCopy(int n, ARFLOAT dx[], int incx, arcomplex<ARFLOAT> dy[], int incy) -{ - - for (int ix=0, iy=0; ix<(n*incx); ix+=incx, iy+=incy) { - dy[iy] = arcomplex<ARFLOAT>(dx[ix], 0.0); - } - -} // ComplexCopy. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -ComplexAxpy(int n, arcomplex<ARFLOAT> da, ARTYPE dx[], int incx, - arcomplex<ARFLOAT> dy[], int incy) -{ - - for (int ix=0, iy=0; ix<(n*incx); ix+=incx, iy+=incy) { - dy[iy] += da*dx[ix]; - } - -} // ComplexAxpy. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>::SubtractAsB(ARTYPE sigma) -{ - - int i, inca, incb, minL, minU, begB, begAsB; - ARTYPE negsig; - - inca = A->ndiagL+A->ndiagU+1; - incb = B->ndiagL+B->ndiagU+1; - negsig = -sigma; - - // Expanding A. - - begAsB = AsB.ndiagL+AsB.ndiagU-A->ndiagU; - for (i = 0; i < inca; i++) { - copy(AsB.n, &A->A[i], inca, &AsB.Ainv[begAsB+i], AsB.lda); - } - - // Transferring part of B (*(-sigma)) if AsB.ndiagU > A->ndiagU. - - if (A->ndiagU < AsB.ndiagU) { - for (i = 0; i < AsB.ndiagU-A->ndiagU; i++) { - copy(AsB.n, &B->A[i], incb, &AsB.Ainv[AsB.ndiagL+i], AsB.lda); - scal(AsB.n, negsig, &AsB.Ainv[AsB.ndiagL+i], AsB.lda); - } - } - - // Subtracting sigma*B from A. - - minL = min(A->ndiagL, B->ndiagL); - minU = min(A->ndiagU, B->ndiagU); - begB = B->ndiagU-minU; - begAsB = AsB.ndiagL+AsB.ndiagU-minU; - - for (i = 0; i < minL+minU+1; i++) { - axpy(AsB.n, -sigma, &B->A[begB+i], incb, &AsB.Ainv[begAsB+i], AsB.lda); - } - - // Transferring part of B (*(-sigma)) if AsB.ndiagL > A->ndiagL. - - if (A->ndiagL < AsB.ndiagL) { - begB = B->ndiagU+1+minL; - begAsB = AsB.ndiagL+AsB.ndiagU+1+minL; - for (i = 0; i < AsB.ndiagL-A->ndiagL; i++) { - copy(AsB.n, &B->A[begB+i], incb, &AsB.Ainv[begAsB+i], AsB.lda); - scal(AsB.n, negsig, &AsB.Ainv[begAsB+i], AsB.lda); - } - } - -} // SubtractAsB (ARTYPE shift). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -SubtractAsB(ARFLOAT sigmaR, ARFLOAT sigmaI) -{ - - int i, inca, incb, minL, minU, begB, begAsB; - arcomplex<ARFLOAT> sigma; - - inca = A->ndiagL+A->ndiagU+1; - incb = B->ndiagL+B->ndiagU+1; - sigma = arcomplex<ARFLOAT>(sigmaR, sigmaI); - - // Expanding A. - - begAsB = AsBc.ndiagL+AsBc.ndiagU-A->ndiagU; - for (i = 0; i < inca; i++) { - ComplexCopy(AsBc.n,(ARFLOAT*)(&A->A[i]),inca,&AsBc.Ainv[begAsB+i],AsBc.lda); - } - - // Transferring part of B (*(-sigma)) if AsBc.ndiagU > A->ndiagU. - - if (A->ndiagU < AsBc.ndiagU) { - for (i = 0; i < AsBc.ndiagU-A->ndiagU; i++) { - ComplexCopy(AsBc.n, (ARFLOAT*)(&B->A[i]), incb, - &AsBc.Ainv[AsBc.ndiagL+i], AsBc.lda); - scal(AsBc.n, -sigma, &AsBc.Ainv[AsBc.ndiagL+i], AsBc.lda); - } - } - - // Subtracting sigma*B from A. - - minL = min(A->ndiagL, B->ndiagL); - minU = min(A->ndiagU, B->ndiagU); - begB = B->ndiagU-minU; - begAsB = AsBc.ndiagL+AsBc.ndiagU-minU; - - for (i = 0; i < minL+minU+1; i++) { - ComplexAxpy(AsBc.n, -sigma, &B->A[begB+i], incb, - &AsBc.Ainv[begAsB+i], AsBc.lda); - } - - // Transferring part of B (*(-sigma)) if AsBc.ndiagL > A->ndiagL. - - if (A->ndiagL < AsBc.ndiagL) { - begB = B->ndiagU+1+minL; - begAsB = AsBc.ndiagL+AsBc.ndiagU+1+minL; - for (i = 0; i < AsBc.ndiagL-A->ndiagL; i++) { - ComplexCopy(AsBc.n, (ARFLOAT*)(&B->A[begB+i]), incb, - &AsBc.Ainv[begAsB+i], AsBc.lda); - scal(AsBc.n, -sigma, &AsBc.Ainv[begAsB+i], AsBc.lda); - } - } - -} // SubtractAsB (arcomplex<ARFLOAT> shift). -#endif // ARCOMP_H - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARbdNonSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARbdNonSymPencil::FactorAsB"); - } - - // Copying A to AsB if sigma = 0. - - if (sigma == (ARTYPE)0) { - - AsB = *A; - if (!AsB.IsFactored()) AsB.FactorA(); - return; - - } - - // Defining matrix AsB. - - if (!AsB.IsDefined()) { - AsB.DefineMatrix(A->ncols(), max(A->ndiagL, B->ndiagL), - max(A->ndiagU, B->ndiagU), A->A); - } - - // Reserving memory for some vectors used in matrix decomposition. - - AsB.CreateStructure(); - - // Subtracting sigma*B from A and storing the result on AsB. - - SubtractAsB(sigma); - - // Decomposing AsB. - - gbtrf(AsB.n, AsB.n, AsB.ndiagL, AsB.ndiagU, - AsB.Ainv, AsB.lda, AsB.ipiv, AsB.info); - - // Handling errors. - - AsB.ThrowError(); - - AsB.factored = true; - -} // FactorAsB (ARTYPE shift). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -FactorAsB(ARFLOAT sigmaR, ARFLOAT sigmaI, char partp) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARbdNonSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARbdNonSymPencil::FactorAsB"); - } - - // Defining matrix AsBc. - - if (!AsBc.IsDefined()) { - part = partp; - AsBc.DefineMatrix(A->ncols(), max(A->ndiagL,B->ndiagL), - max(A->ndiagU,B->ndiagU), 0); - } - - // Reserving memory for some vectors used in matrix decomposition. - - AsBc.CreateStructure(); - - // Subtracting sigma*B from A and storing the result on AsBc. - - SubtractAsB(sigmaR, sigmaI); - - // Decomposing AsBc. - - gbtrf(AsBc.n, AsBc.n, AsBc.ndiagL, AsBc.ndiagU, - AsBc.Ainv, AsBc.lda, AsBc.ipiv, AsBc.info); - - // Handling errors. - - AsBc.ThrowError(); - - AsBc.factored = true; - -} // FactorAsB (arcomplex<ARFLOAT> shift). -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - B->MultInvv(w, w); - -} // MultInvBAv. - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -MultInvAsBv(arcomplex<ARFLOAT>* v, arcomplex<ARFLOAT>* w) -{ - - AsB.MultInvv((ARTYPE*)v, (ARTYPE*)w); - -} // MultInvAsBv (arcomplex<ARFLOAT>). -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARbdNonSymPencil<ARTYPE, ARFLOAT>::MultInvAsBv(ARFLOAT* v, ARFLOAT* w) -{ - - if (part == 'N') { // shift is real. - - AsB.MultInvv((ARTYPE*)v, (ARTYPE*)w); - - } - else { // shift is complex. - -#ifdef ARCOMP_H - - int i; - arcomplex<ARFLOAT> *tv, *tw; - - tv = new arcomplex<ARFLOAT>[AsBc.ncols()]; - tw = new arcomplex<ARFLOAT>[AsBc.ncols()]; - - for (i=0; i!=AsBc.ncols(); i++) tv[i] = arcomplex<ARFLOAT>(v[i], 0.0); - - AsBc.MultInvv(tv, tw); - - if (part=='I') { - for (i=0; i!=AsBc.ncols(); i++) w[i] = imag(tw[i]); - } - else { - for (i=0; i!=AsBc.ncols(); i++) w[i] = real(tw[i]); - } - - delete[] tv; - delete[] tw; - -#endif // ARCOMP_H. - - } - -} // MultInvAsBv (ARFLOAT). - - -template<class ARTYPE, class ARFLOAT> -inline void ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -DefineMatrices(ARbdNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARbdNonSymMatrix<ARTYPE, ARFLOAT>& Bp) -{ - - A = &Ap; - B = &Bp; - -} // DefineMatrices. - - -template<class ARTYPE, class ARFLOAT> -inline ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -ARbdNonSymPencil(ARbdNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARbdNonSymMatrix<ARTYPE, ARFLOAT>& Bp) -{ - - DefineMatrices(Ap, Bp); - -} // Long constructor. - - -template<class ARTYPE, class ARFLOAT> -ARbdNonSymPencil<ARTYPE, ARFLOAT>& ARbdNonSymPencil<ARTYPE, ARFLOAT>:: -operator=(const ARbdNonSymPencil<ARTYPE, ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBNSPEN_H diff --git a/src/external/arpack++/include/arbscomp.h b/src/external/arpack++/include/arbscomp.h deleted file mode 100644 index 334cd3a6..00000000 --- a/src/external/arpack++/include/arbscomp.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBSComp.h. - Arpack++ class ARluCompStdEig definition - (band matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARBSCOMP_H -#define ARBSCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arscomp.h" -#include "arbnsmat.h" -#include "arrseig.h" - - -template<class ARFLOAT> -class ARluCompStdEig: - public virtual ARCompStdEig<ARFLOAT, - ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(arcomplex<ARFLOAT> sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(arcomplex<ARFLOAT> sigmap); - - // a.2) Constructors and destructor. - - ARluCompStdEig() { } - // Short constructor. - - ARluCompStdEig(int nevp, ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluCompStdEig(int nevp, ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluCompStdEig(const ARluCompStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluCompStdEig() { } - // Destructor. - - - // b) Operators. - - ARluCompStdEig& operator=(const ARluCompStdEig& other); - // Assignment operator. - -}; // class ARluCompStdEig. - - -// ------------------------------------------------------------------------ // -// ARluCompStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>:: -ChangeShift(arcomplex<ARFLOAT> sigmaRp) -{ - - this->objOP->FactorAsI(sigmaRp); - ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> >::ChangeShift(sigmaRp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARbdNonSymMatrix<arcomplex<ARFLOAT>,ARFLOAT> >:: - SetRegularMode(this->objOP,&ARbdNonSymMatrix<arcomplex<ARFLOAT>,ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>:: -SetShiftInvertMode(arcomplex<ARFLOAT> sigmap) -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARbdNonSymMatrix<arcomplex<ARFLOAT>,ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, - &ARbdNonSymMatrix<arcomplex<ARFLOAT>,ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluCompStdEig<ARFLOAT>:: -ARluCompStdEig(int nevp, ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, - &ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluCompStdEig<ARFLOAT>:: -ARluCompStdEig(int nevp, ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, - &ARbdNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluCompStdEig<ARFLOAT>& ARluCompStdEig<ARFLOAT>:: -operator=(const ARluCompStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBSCOMP_H diff --git a/src/external/arpack++/include/arbsmat.h b/src/external/arpack++/include/arbsmat.h deleted file mode 100644 index e38c2ccf..00000000 --- a/src/external/arpack++/include/arbsmat.h +++ /dev/null @@ -1,378 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBSMat.h. - Arpack++ class ARbdSymMatrix definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "arbspen.h" - -#ifndef ARBSMAT_H -#define ARBSMAT_H - -#include <cstddef> -#include "arch.h" -#include "armat.h" -#include "arerror.h" -#include "blas1c.h" -#include "lapackc.h" - -template<class ARTYPE> class ARbdSymPencil; - -template<class ARTYPE> -class ARbdSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARbdSymPencil<ARTYPE>; - - protected: - - bool factored; - char uplo; - int nsdiag; - int lda; - int info; - int* ipiv; - ARTYPE* A; - ARTYPE* Ainv; - - void ClearMem(); - - virtual void Copy(const ARbdSymMatrix& other); - - void ExpandA(); - - void SubtractAsI(ARTYPE sigma); - - void CreateStructure(); - - void ThrowError(); - - public: - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, int nsdiagp, ARTYPE* Ap, char uplop = 'L'); - - ARbdSymMatrix(): ARMatrix<ARTYPE>() { factored = false; } - // Short constructor that does nothing. - - ARbdSymMatrix(int np, int nsdiagp, ARTYPE* Ap, char uplop = 'L'); - // Long constructor. - - ARbdSymMatrix(const ARbdSymMatrix& other) { Copy(other); } - // Copy constructor. - - virtual ~ARbdSymMatrix() { ClearMem(); } - // Destructor. - - ARbdSymMatrix& operator=(const ARbdSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARbdSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -inline void ARbdSymMatrix<ARTYPE>::ClearMem() -{ - - if (factored) { - delete[] Ainv; - delete[] ipiv; - Ainv = NULL; - ipiv = NULL; - } - -} // ClearMem. - - -template<class ARTYPE> -inline void ARbdSymMatrix<ARTYPE>:: -Copy(const ARbdSymMatrix<ARTYPE>& other) -{ - - // Copying very fundamental variables and user-defined parameters. - - this->m = other.m; - this->n = other.n; - this->defined = other.defined; - factored = other.factored; - uplo = other.uplo; - nsdiag = other.nsdiag; - lda = other.lda; - info = other.info; - A = other.A; - - // Returning from here if "other" was not factored. - - if (!factored) return; - - // Copying vectors. - - Ainv = new ARTYPE[this->n*lda]; - ipiv = new int[this->n]; - - copy(this->n*lda, other.Ainv, 1, Ainv, 1); - for (int i=0; i<this->n; i++) ipiv[i] = other.ipiv[i]; - -} // Copy. - - -template<class ARTYPE> -void ARbdSymMatrix<ARTYPE>::ExpandA() -{ - - int i; - - if (uplo == 'U') { - - // Copying the main diagonal of A to Ainv. - - copy(this->n, &A[nsdiag], nsdiag+1, &Ainv[2*nsdiag], lda); - - // Copying the superdiagonals of A to Ainv. - - for (i = 0; i < nsdiag; i++) { - copy(this->n, &A[i], nsdiag+1, &Ainv[nsdiag+i], lda); - copy(this->n-nsdiag+i, &A[i+(nsdiag-i)*(nsdiag+1)], nsdiag+1, - &Ainv[3*nsdiag-i], lda); - } - - } - else { - - // Copying the main diagonal of A to Ainv. - - copy(this->n, &A[0], nsdiag+1, &Ainv[2*nsdiag], lda); - - // Copying the subdiagonals of A to Ainv. - - for (i = 1; i <= nsdiag; i++) { - copy(this->n, &A[i], nsdiag+1, &Ainv[2*nsdiag+i], lda); - copy(this->n-i, &A[i], nsdiag+1, &Ainv[2*nsdiag-i+i*lda], lda); - } - - } - -} // ExpandA. - - -template<class ARTYPE> -void ARbdSymMatrix<ARTYPE>::SubtractAsI(ARTYPE sigma) -{ - - // Copying A to Ainv. - - ExpandA(); - - // Subtracting sigma from diagonal elements. - - for (int i=(2*nsdiag); i<(lda*this->n); i+=lda) Ainv[i] -= sigma; - -} // SubtractAsI. - - -template<class ARTYPE> -inline void ARbdSymMatrix<ARTYPE>::CreateStructure() -{ - - ClearMem(); - Ainv = new ARTYPE[lda*this->n]; - ipiv = new int[this->n]; - -} // CreateStructure. - - -template<class ARTYPE> -inline void ARbdSymMatrix<ARTYPE>::ThrowError() -{ - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARbdSymMatrix::FactorA"); - } - else if (info) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARbdSymMatrix::FactorA"); - } - -} // ThrowError. - - -template<class ARTYPE> -void ARbdSymMatrix<ARTYPE>::FactorA() -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARbdSymMatrix::FactorA"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Copying A to Ainv; - - ExpandA(); - - // Decomposing A. - - gbtrf(this->n, this->n, nsdiag, nsdiag, Ainv, lda, ipiv, info); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorA. - - -template<class ARTYPE> -void ARbdSymMatrix<ARTYPE>::FactorAsI(ARTYPE sigma) -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARbdSymMatrix::FactorAsI"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Subtracting sigma*I from A. - - SubtractAsI(sigma); - - // Decomposing AsI. - - gbtrf(this->n, this->n, nsdiag, nsdiag, Ainv, lda, ipiv, info); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorAsI. - - -template<class ARTYPE> -void ARbdSymMatrix<ARTYPE>::MultMv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE one = (ARTYPE)0 + 1.0; - ARTYPE zero = (ARTYPE)0; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARbdSymMatrix::MultMv"); - } - - // Determining w = M.v. - - sbmv(&uplo, this->n, nsdiag, one, A, nsdiag+1, v, 1, zero, w, 1); - -} // MultMv. - - -template<class ARTYPE> -void ARbdSymMatrix<ARTYPE>::MultInvv(ARTYPE* v, ARTYPE* w) -{ - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARbdSymMatrix::MultInvv"); - } - - // Overwritting w with v. - - copy(this->n, v, 1, w, 1); - - // Solving A.w = v (or AsI.w = v). - - gbtrs("N", this->n, nsdiag, nsdiag, 1, Ainv, lda, ipiv, w, this->m, info); - - // Handling errors. - - ThrowError(); - -} // MultInvv. - - -template<class ARTYPE> -inline void ARbdSymMatrix<ARTYPE>:: -DefineMatrix(int np, int nsdiagp, ARTYPE* Ap, char uplop) -{ - - // Defining member variables. - - this->m = np; - this->n = np; - nsdiag = nsdiagp; - lda = 3*nsdiag+1; - uplo = uplop; - A = Ap; - this->defined = true; - Ainv = NULL; - ipiv = NULL; - info = 0; - -} // DefineMatrix. - - -template<class ARTYPE> -inline ARbdSymMatrix<ARTYPE>:: -ARbdSymMatrix(int np, int nsdiagp, - ARTYPE* Ap, char uplop) : ARMatrix<ARTYPE>(np) -{ - - factored = false; - DefineMatrix(np, nsdiagp, Ap, uplop); - -} // Long constructor. - - -template<class ARTYPE> -ARbdSymMatrix<ARTYPE>& ARbdSymMatrix<ARTYPE>:: -operator=(const ARbdSymMatrix<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBSMAT_H diff --git a/src/external/arpack++/include/arbsnsym.h b/src/external/arpack++/include/arbsnsym.h deleted file mode 100644 index 808a4246..00000000 --- a/src/external/arpack++/include/arbsnsym.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBSNSym.h. - Arpack++ class ARluNonSymStdEig definition - (band matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARBSNSYM_H -#define ARBSNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arsnsym.h" -#include "arbnsmat.h" - - -template<class ARFLOAT> -class ARluNonSymStdEig: - public virtual ARNonSymStdEig<ARFLOAT, ARbdNonSymMatrix<ARFLOAT, ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // a.2) Constructors and destructor. - - ARluNonSymStdEig() { } - // Short constructor. - - ARluNonSymStdEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluNonSymStdEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluNonSymStdEig(const ARluNonSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymStdEig() { } - // Destructor. - - // b) Operators. - - ARluNonSymStdEig& operator=(const ARluNonSymStdEig& other); - // Assignment operator. - -}; // class ARluNonSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluNonSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI( this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARbdNonSymMatrix<ARFLOAT, ARFLOAT> >:: - SetRegularMode( this->objOP, &ARbdNonSymMatrix<ARFLOAT, ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARbdNonSymMatrix<ARFLOAT, ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, - &ARbdNonSymMatrix<ARFLOAT, ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluNonSymStdEig<ARFLOAT>:: -ARluNonSymStdEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, - &ARbdNonSymMatrix<ARFLOAT, ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluNonSymStdEig<ARFLOAT>:: -ARluNonSymStdEig(int nevp, ARbdNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, - &ARbdNonSymMatrix<ARFLOAT, ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluNonSymStdEig<ARFLOAT>& ARluNonSymStdEig<ARFLOAT>:: -operator=(const ARluNonSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBSNSYM_H diff --git a/src/external/arpack++/include/arbspen.h b/src/external/arpack++/include/arbspen.h deleted file mode 100644 index 0dbd73bb..00000000 --- a/src/external/arpack++/include/arbspen.h +++ /dev/null @@ -1,303 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBSPen.h. - Arpack++ class ARbdSymPencil definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARBSPEN_H -#define ARBSPEN_H - -#include "arch.h" -#include "arerror.h" -#include "blas1c.h" -#include "lapackc.h" -#include "arbsmat.h" - - -template<class ARTYPE> -class ARbdSymPencil -{ - - protected: - - ARbdSymMatrix<ARTYPE>* A; - ARbdSymMatrix<ARTYPE>* B; - ARbdSymMatrix<ARTYPE> AsB; - - int max(int a, int b) { return (a>b)?a:b; } - - int min(int a, int b) { return (a<b)?a:b; } - - virtual void Copy(const ARbdSymPencil& other); - - void SubtractAsB(ARTYPE sigma); - - public: - - bool IsFactored() { return AsB.IsFactored(); } - - void FactorAsB(ARTYPE sigma); - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - - void MultInvAsBv(ARTYPE* v, ARTYPE* w) { AsB.MultInvv(v,w); } - - void DefineMatrices(ARbdSymMatrix<ARTYPE>& Ap, ARbdSymMatrix<ARTYPE>& Bp); - - ARbdSymPencil() { AsB.factored = false; } - // Short constructor that does nothing. - - ARbdSymPencil(ARbdSymMatrix<ARTYPE>& Ap, ARbdSymMatrix<ARTYPE>& Bp); - // Long constructor. - - ARbdSymPencil(const ARbdSymPencil& other) { Copy(other); } - // Copy constructor. - - virtual ~ARbdSymPencil() { } - // Destructor. - - ARbdSymPencil& operator=(const ARbdSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARbdSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -inline void ARbdSymPencil<ARTYPE>::Copy(const ARbdSymPencil<ARTYPE>& other) -{ - - A = other.A; - B = other.B; - AsB = other.AsB; - -} // Copy. - - -template<class ARTYPE> -void ARbdSymPencil<ARTYPE>::SubtractAsB(ARTYPE sigma) -{ - - int i, n, minD, ndA, ndB, ndAsB, lda; - ARTYPE negsig; - - negsig = -sigma; - n = AsB.n; - ndA = A->nsdiag; - ndB = B->nsdiag; - ndAsB = AsB.nsdiag; - lda = AsB.lda; - - // Expanding A. - - if (A->uplo == 'U') { - - // Copying the main diagonal of A. - - copy(n, &A->A[ndA], ndA+1, &AsB.Ainv[2*ndAsB], lda); - - // Copying the superdiagonals of A. - - for (i = 0; i < ndA; i++) { - copy(n, &A->A[i], ndA+1, &AsB.Ainv[2*ndAsB-ndA+i], lda); - copy(n-ndA+i, &A->A[i+(ndA-i)*(ndA+1)], ndA+1, - &AsB.Ainv[2*ndAsB+ndA-i], lda); - } - - } - else { - - // Copying the main diagonal of A to Ainv. - - copy(n, &A->A[0], ndA+1, &AsB.Ainv[2*ndAsB], lda); - - // Copying the subdiagonals of A to Ainv. - - for (i = 1; i <= ndA; i++) { - copy(n, &A->A[i], ndA+1, &AsB.Ainv[2*ndAsB+i], lda); - copy(n-i, &A->A[i], ndA+1, &AsB.Ainv[2*ndAsB-i+i*lda], lda); - } - - } - - // Transferring part of B (*(-sigma)) if AsB.nsdiag > A->nsdiag. - - if (A->nsdiag < AsB.nsdiag) { - - if (B->uplo == 'U') { - - for (i = 0; i < ndAsB-ndA; i++) { - copy(n, &B->A[i], ndB+1, &AsB.Ainv[ndAsB+i], lda); - scal(n, negsig, &AsB.Ainv[ndAsB+i], lda); - copy(n-ndAsB+i, &AsB.Ainv[ndAsB+i+(ndAsB-i)*lda], lda, - &AsB.Ainv[lda-i-1], lda); - } - - } - else { - - for (i = ndA+1; i <= ndAsB; i++) { - copy(n, &B->A[i], ndB+1, &AsB.Ainv[2*ndAsB+i], lda); - scal(n, negsig, &AsB.Ainv[2*ndAsB+i], lda); - copy(n-i, &AsB.Ainv[2*ndAsB+i], lda, - &AsB.Ainv[2*ndAsB-i+i*lda], lda); - } - - } - - } - - // Subtracting sigma*B from A. - - minD = min(ndA, ndB); - - if (B->uplo == 'U') { - - // Subtracting the main diagonal of B. - - axpy(n, negsig, &B->A[ndB], ndB+1, &AsB.Ainv[2*ndAsB], lda); - - // Subtracting the superdiagonals. - - for (i = 0; i < minD; i++) { - axpy(n, negsig, &B->A[ndB-minD+i], ndB+1, - &AsB.Ainv[2*ndAsB-minD+i], lda); - copy(n-minD+i, &AsB.Ainv[2*ndAsB-minD+i+(minD-i)*lda], lda, - &AsB.Ainv[2*ndAsB+minD-i], lda); - } - - } - else { - - // Subtracting the main diagonal of B. - - axpy(n, negsig, &B->A[0], ndB+1, &AsB.Ainv[2*ndAsB], lda); - - // Subtracting the subdiagonals. - - for (i = 1; i <= minD; i++) { - axpy(n, negsig, &B->A[i], ndB+1, &AsB.Ainv[2*ndAsB+i], lda); - copy(n-i, &AsB.Ainv[2*ndAsB+i], lda, - &AsB.Ainv[2*ndAsB-i+i*lda], lda); - } - - } - -} // SubtractAsB (ARTYPE shift). - - -template<class ARTYPE> -void ARbdSymPencil<ARTYPE>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARbdSymPencil::FactorAsB"); - } - - // Copying A to AsB if sigma = 0. - - if (sigma == (ARTYPE)0) { - - AsB = *A; - if (!AsB.IsFactored()) AsB.FactorA(); - return; - - } - - // Defining matrix AsB. - - if (!AsB.IsDefined()) { - AsB.DefineMatrix(A->ncols(), max(A->nsdiag, B->nsdiag), A->A); - } - - // Reserving memory for some vectors used in matrix decomposition. - - AsB.CreateStructure(); - - // Subtracting sigma*B from A and storing the result on AsB. - - SubtractAsB(sigma); - - // Decomposing AsB. - - gbtrf(AsB.n, AsB.n, AsB.nsdiag, AsB.nsdiag, - AsB.Ainv, AsB.lda, AsB.ipiv, AsB.info); - - // Handling errors. - - AsB.ThrowError(); - - AsB.factored = true; - -} // FactorAsB (ARTYPE shift). - - -template<class ARTYPE> -void ARbdSymPencil<ARTYPE>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - copy(A->ncols(), w, 1, v, 1); - B->MultInvv(w, w); - -} // MultInvBAv. - - -template<class ARTYPE> -inline void ARbdSymPencil<ARTYPE>:: -DefineMatrices(ARbdSymMatrix<ARTYPE>& Ap, ARbdSymMatrix<ARTYPE>& Bp) -{ - - A = &Ap; - B = &Bp; - -} // DefineMatrices. - - -template<class ARTYPE> -inline ARbdSymPencil<ARTYPE>:: -ARbdSymPencil(ARbdSymMatrix<ARTYPE>& Ap, ARbdSymMatrix<ARTYPE>& Bp) -{ - - AsB.factored = false; - DefineMatrices(Ap, Bp); - -} // Long constructor. - - -template<class ARTYPE> -ARbdSymPencil<ARTYPE>& ARbdSymPencil<ARTYPE>:: -operator=(const ARbdSymPencil<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBSPEN_H diff --git a/src/external/arpack++/include/arbssym.h b/src/external/arpack++/include/arbssym.h deleted file mode 100644 index 94d70f68..00000000 --- a/src/external/arpack++/include/arbssym.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARBSSym.h. - Arpack++ class ARluSymStdEig definition - (band matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARBSSYM_H -#define ARBSSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arssym.h" -#include "arbsmat.h" - - -template<class ARFLOAT> -class ARluSymStdEig: - public virtual ARSymStdEig<ARFLOAT, ARbdSymMatrix<ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // a.2) Constructors and destructor. - - ARluSymStdEig() { } - // Short constructor. - - ARluSymStdEig(int nevp, ARbdSymMatrix<ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymStdEig(int nevp, ARbdSymMatrix<ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluSymStdEig(const ARluSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymStdEig() { } - // Destructor. - - // b) Operators. - - ARluSymStdEig& operator=(const ARluSymStdEig& other); - // Assignment operator. - -}; // class ARluSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI(this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARbdSymMatrix<ARFLOAT> >:: - SetRegularMode(this->objOP, &ARbdSymMatrix<ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARbdSymMatrix<ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, &ARbdSymMatrix<ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARbdSymMatrix<ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, &ARbdSymMatrix<ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARbdSymMatrix<ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, &ARbdSymMatrix<ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluSymStdEig<ARFLOAT>& ARluSymStdEig<ARFLOAT>:: -operator=(const ARluSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARBSSYM_H diff --git a/src/external/arpack++/include/arcgsym.h b/src/external/arpack++/include/arcgsym.h deleted file mode 100644 index 45c14f83..00000000 --- a/src/external/arpack++/include/arcgsym.h +++ /dev/null @@ -1,242 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARCGSym.h. - Arpack++ class ARluSymGenEig definition - (CHOLMOD version). - - Author of this class: - Martin Reuter - Date 11/05/2012 - - Arpack++ Author: - Francisco Gomes - - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Kristi Maschhoff - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARCGSYM_H -#define ARCGSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arcsmat.h" -#include "arcspen.h" -#include "argsym.h" - - -template<class ARFLOAT> -class ARluSymGenEig: - public virtual ARSymGenEig<ARFLOAT, ARchSymPencil<ARFLOAT>, - ARchSymPencil<ARFLOAT> > { - - private: - - // a) Data structure used to store matrices. - - ARchSymPencil<ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmap); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetBucklingMode(ARFLOAT sigmap); - - virtual void SetCayleyMode(ARFLOAT sigmap); - - // c.2) Constructors and destructor. - - ARluSymGenEig() { } - // Short constructor. - - ARluSymGenEig(int nevp, ARchSymMatrix<ARFLOAT>& A, - ARchSymMatrix<ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymGenEig(char InvertModep, int nevp, ARchSymMatrix<ARFLOAT>& A, - ARchSymMatrix<ARFLOAT>& B, ARFLOAT sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert, buckling and Cayley modes). - - ARluSymGenEig(const ARluSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluSymGenEig& operator=(const ARluSymGenEig& other); - // Assignment operator. - -}; // class ARluSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -Copy(const ARluSymGenEig<ARFLOAT>& other) -{ - - ARSymGenEig<ARFLOAT, ARchSymPencil<ARFLOAT>, - ARchSymPencil<ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::ChangeShift(ARFLOAT sigmap) -{ - - this->objOP->FactorAsB(sigmap); - ARrcSymGenEig<ARFLOAT>::ChangeShift(sigmap); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARchSymPencil<ARFLOAT> >:: - SetRegularMode(&Pencil, &ARchSymPencil<ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARchSymPencil<ARFLOAT>, ARchSymPencil<ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, &ARchSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARchSymPencil<ARFLOAT>::MultBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetBucklingMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARchSymPencil<ARFLOAT>, ARchSymPencil<ARFLOAT> >:: - SetBucklingMode(sigmap, &Pencil, &ARchSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARchSymPencil<ARFLOAT>::MultAv); - -} // SetBucklingMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetCayleyMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARchSymPencil<ARFLOAT>, ARchSymPencil<ARFLOAT> >:: - SetCayleyMode(sigmap, &Pencil, &ARchSymPencil<ARFLOAT>::MultInvAsBv, - &Pencil, &ARchSymPencil<ARFLOAT>::MultAv); - this->ChangeMultBx(&Pencil, &ARchSymPencil<ARFLOAT>::MultBv); - -} // SetCayleyMode. - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(int nevp, ARchSymMatrix<ARFLOAT>& A, - ARchSymMatrix<ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->InvertMode = 'S'; - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARchSymPencil<ARFLOAT>::MultInvBAv, &Pencil, - &ARchSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(char InvertModep, int nevp, ARchSymMatrix<ARFLOAT>& A, - ARchSymMatrix<ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARchSymPencil<ARFLOAT>::MultInvAsBv, &Pencil, - &ARchSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - this->InvertMode = this->CheckInvertMode(InvertModep); - switch (this->InvertMode) { - case 'B': // Buckling mode. - this->ChangeMultBx(&Pencil, &ARchSymPencil<ARFLOAT>::MultAv); - case 'S': // Shift and invert mode. - ChangeShift(sigmap); - break; - case 'C': // Cayley mode. - SetCayleyMode(sigmap); - } - -} // Long constructor (shift and invert, buckling and Cayley modes). - - -template<class ARFLOAT> -ARluSymGenEig<ARFLOAT>& ARluSymGenEig<ARFLOAT>:: -operator=(const ARluSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUGSYM_H diff --git a/src/external/arpack++/include/arch.h b/src/external/arpack++/include/arch.h deleted file mode 100644 index 13515730..00000000 --- a/src/external/arpack++/include/arch.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE arch.h - Modified version of arch.h (from LAPACK++ 1.1). - Machine dependent functions and variable types. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#ifndef ARCH_H -#define ARCH_H - -// ARPACK++ arcomplex type definition. -// If you are not using g++ (or CC) and also are not intending -// use complex variables, comment out the following line. - -#include "arcomp.h" - -// STL vector class. -// If the Standard Template Library is not available at your system -// and you do not want to install it, comment out the following line. - -#include <vector> - -// If your STL vector class defines a variable other than -// __SGI_STL_VECTOR_H, please change this variable name -// in the ifdef command below. - -#ifdef __SGI_STL_VECTOR_H - #define STL_VECTOR_H -#endif - -// UMFPACK parameters. -// These parameters are used by UMFPACK library functions. Normally -// they are not modified by the user. To use the default value, set -// the parameter to zero. For a complete description of all UMFPACK -// parameters, see the library documentation. - -#define UICNTL7 0 // icntl(7). Block size for the blas (machine-dependent). -#define UICNTL5 0 // icntl(5). Number of columns to examine during pivot search. -#define UCNTL2 0 // cntl(2). Amalgamation parameter. -#define UKEEP7 0 // keep(7). Absolute number of elements a column must have - // to be considered "dense". -#define UKEEP8 0 // keep(8). Relative number of elements a column must have - // to be considered "dense". Dense columns have more - // than max{0,UMFABDEN,UMFREDEN*sqrt(n)} elements. - -// Line length used when reading a dense matrix from a file. - -#define LINELEN 256 - -// Linkage names between C, C++, and Fortran (platform dependent) - -#if defined(RIOS) && !defined(CLAPACK) -#define F77NAME(x) x -#else -// #include <generic.h> -// #define F77NAME(x) name2(x,_) -#define F77NAME(x) x ## _ -#endif - -#if defined(SGI) && !defined(SGI_DEC) -#define SGI_DEC - -extern "C" { - void mkidxname() {} - void mkdatname() {} -} -#endif - - -// Type conversion. - -typedef int ARint; -typedef int ARlogical; - -#ifdef __SUNPRO_CC - - typedef int bool; - int true = 1; - int false = 0; - -#endif - - -#endif // ARCH_H diff --git a/src/external/arpack++/include/arcomp.h b/src/external/arpack++/include/arcomp.h deleted file mode 100644 index 6a391d02..00000000 --- a/src/external/arpack++/include/arcomp.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE arcomp.h - arcomplex complex type definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARCOMP_H -#define ARCOMP_H - -#include <complex> - -#ifdef __GNUG__ - -#define arcomplex std::complex - -#endif - -#if defined(__SUNPRO_CC) || defined(__sgi) - - template <class ARFLOAT> - class arcomplex: public complex - { - public: - - arcomplex(ARFLOAT x, ARFLOAT y): complex(x,y) { } - arcomplex(): complex() { } - arcomplex(complex x): complex(x) { } - - }; - -#endif - -#endif // ARCOMP_H - - - diff --git a/src/external/arpack++/include/arcsmat.h b/src/external/arpack++/include/arcsmat.h deleted file mode 100644 index a97e9fad..00000000 --- a/src/external/arpack++/include/arcsmat.h +++ /dev/null @@ -1,473 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARCSMat.h. - Arpack++ class ARchSymMatrix definition. - (CHOLMOD wrapper) - - Author of this class: - Martin Reuter - Date 11/05/2012 - - Arpack++ Author: - Francisco Gomes - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "arcspen.h" - -#ifndef ARCSMAT_H -#define ARCSMAT_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "armat.h" -#include "arhbmat.h" -#include "arerror.h" -#include "cholmodc.h" -//#include "blas1c.h" -//#include "superluc.h" -//#include "arlspdef.h" -//#include "arlutil.h" -#include <fstream> - -template<class ARTYPE> class ARchSymPencil; - -template<class ARTYPE> -class ARchSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARchSymPencil<ARTYPE>; - - protected: - - bool factored; - char uplo; - int nnz; - int* irow; - int* pcol; - double threshold; - ARTYPE* a; - ARhbMatrix<int, ARTYPE> mat; - cholmod_common c ; - cholmod_sparse *A ; - cholmod_factor *L ; - - bool DataOK(); - - virtual void Copy(const ARchSymMatrix& other); - - void ClearMem(); - - public: - - int nzeros() { return nnz; } - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, char uplop = 'L', double thresholdp = 0.1, - bool check = true); - - ARchSymMatrix(): ARMatrix<ARTYPE>() { factored = false; cholmod_start (&c) ;} - // Short constructor that does nothing. - - ARchSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, char uplop = 'L', double thresholdp = 0.1, - bool check = true); - // Long constructor. - - ARchSymMatrix(const std::string& name, double thresholdp = 0.1, - bool check = true); - // Long constructor (Harwell-Boeing file). - - ARchSymMatrix(const ARchSymMatrix& other) { cholmod_start (&c) ; Copy(other); } - // Copy constructor. - - virtual ~ARchSymMatrix() { ClearMem(); cholmod_finish (&c) ;} - // Destructor. - - ARchSymMatrix& operator=(const ARchSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARchSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -bool ARchSymMatrix<ARTYPE>::DataOK() -{ - - int i, j, k; - - // Checking if pcol is in ascending order. - - i = 0; - while ((i!=this->n)&&(pcol[i]<=pcol[i+1])) i++; - if (i!=this->n) return false; - - // Checking if irow components are in order and within bounds. - - for (i=0; i!=this->n; i++) { - j = pcol[i]; - k = pcol[i+1]-1; - if (j<=k) { - if (uplo == 'U') { - if ((irow[j]<0)||(irow[k]>i)) return false; - } - else { // uplo == 'L'. - if ((irow[j]<i)||(irow[k]>=this->n)) return false; - } - while ((j!=k)&&(irow[j]<irow[j+1])) j++; - if (j!=k) return false; - } - } - - return true; - -} // DataOK. - - -template<class ARTYPE> -void ARchSymMatrix<ARTYPE>::ClearMem() -{ - - if (factored) { - cholmod_free_factor (&L, &c) ; - } - if (this->defined) { - //cholmod_free_sparse (&A, &c); - //delete[] permc; - //delete[] permr; - //permc = NULL; - //permr = NULL; - - free(A); // don't delete data in A as it came from external - A = NULL; - } - -} // ClearMem. - - - -template<class ARTYPE> -inline void ARchSymMatrix<ARTYPE>::Copy(const ARchSymMatrix<ARTYPE>& other) -{ - - // Copying very fundamental variables. - ClearMem(); - - this->defined = other.defined; - // Returning from here if "other" was not initialized. - if (!this->defined) return; - - this->n = other.n; - factored = other.factored; - uplo = other.uplo; - nnz = other.nnz; - irow = other.irow; - pcol = other.pcol; - threshold = other.threshold; - a = other.a; - //c = other.c; - - A = cholmod_copy_sparse(other.A,&c); - - if (L) cholmod_free_factor(&L,&c); - if (factored) - L = cholmod_copy_factor(other.L,&c); - -} // Copy. - - - -template<class ARTYPE> -void ARchSymMatrix<ARTYPE>::FactorA() -{ - int info; - - //std::cout << "ARchSymMatrix::FactorA" << std::endl; - - // Quitting the function if A was not defined. - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARchSymMatrix::FactorA"); - } - - // Deleting previous versions of L. - if (factored) { - cholmod_free_factor (&L, &c) ; - } - - L = cholmod_analyze (A, &c) ; - info = cholmod_factorize (A, L, &c) ; - - - factored = (info != 0); - - if (c.status != CHOLMOD_OK) - { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARchSymMatrix::FactorA"); - - factored = false; - } - -// -// // Handling errors. -// -// if (info < 0) { // Illegal argument. -// throw ArpackError(ArpackError::PARAMETER_ERROR, -// "ARchSymMatrix::FactorA"); -// } -// else if (info > this->n) { // Memory is not sufficient. -// throw ArpackError(ArpackError::MEMORY_OVERFLOW, -// "ARchSymMatrix::FactorA"); -// } -// else if (info > 0) { // Matrix is singular. -// throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, -// "ARchSymMatrix::FactorA"); -// } - -} // FactorA. - - -template<class ARTYPE> -void ARchSymMatrix<ARTYPE>::FactorAsI(ARTYPE sigma) -{ - - //std::cout <<"ARchSymMatrix::FactorAsI " << std::endl; - - // Quitting the function if A was not defined. - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARchSymMatrix::FactorAsI"); - } - - - // Deleting previous versions of L. - if (factored) { - cholmod_free_factor (&L, &c) ; - } - -// FILE *fp ; -// fp = fopen ("A.mat", "w" ) ; -// cholmod_write_sparse(fp,A,NULL,NULL,&c); - - // Factorizing A-sigma*I - double sigma2[2]; - sigma2[0] = -sigma; - sigma2[1] = 0.0; - L = cholmod_analyze (A, &c) ; - int info = cholmod_factorize_p (A,sigma2,NULL,0,L,&c) ; - - factored = (info != 0); - - if (c.status != CHOLMOD_OK) - { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARchSymMatrix::FactorAsI"); - - factored = false; - } - - -} // FactorAsI. - - -template<class ARTYPE> -void ARchSymMatrix<ARTYPE>::MultMv(ARTYPE* v, ARTYPE* w) -{ - //std::cout << "ARchSymMatrix::MultMv " << std::endl; - - int i, j, k; - ARTYPE t; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARchSymMatrix::MultMv"); - } - - // Determining w = M.v. - - for (i=0; i!=this->m; i++) w[i]=(ARTYPE)0; - - if (uplo == 'U') { - - for (i=0; i!=this->n; i++) { - t = v[i]; - k = pcol[i+1]; - if ((k!=pcol[i])&&(irow[k-1]==i)) { - w[i] += t*a[k-1]; - k--; - } - for (j=pcol[i]; j<k; j++) { - w[irow[j]] += t*a[j]; - w[i] += v[irow[j]]*a[j]; - } - } - - } - else { - - for (i=0; i!=this->n; i++) { - t = v[i]; - k = pcol[i]; - if ((k!=pcol[i+1])&&(irow[k]==i)) { - w[i] += t*a[k]; - k++; - } - for (j=k; j<pcol[i+1]; j++) { - w[irow[j]] += t*a[j]; - w[i] += v[irow[j]]*a[j]; - } - } - - } - -} // MultMv. - - -template<class ARTYPE> -void ARchSymMatrix<ARTYPE>::MultInvv(ARTYPE* v, ARTYPE* w) -{ - //std::cout << "ARchSymMatrix::MultInvv " << std::endl; - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARchSymMatrix::MultInvv"); - } - - // Solving A.w = v (or AsI.w = v). - - //std::cout<< " b = [ " << v[0]; - //for(int i=1;i<this->n;i++) - // std::cout << " , " << v[i]; - //std::cout<< " ]" <<std::endl; - - //create b from v (data is not copied!!) - cholmod_dense * b = Create_Cholmod_Dense_Matrix(this->n,1,v,&c); - - cholmod_dense *x = cholmod_solve (CHOLMOD_A, L, b, &c) ; - - Get_Cholmod_Dense_Data(x, this->n, w); - - //std::cout<< " x = [ " << w[0]; - //for(int i=1;i<this->n;i++) - // std::cout << " , " << w[i]; - //std::cout<< " ]" <<std::endl; - - free(b); - cholmod_free_dense(&x,&c); - - -} // MultInvv. - - -template<class ARTYPE> -inline void ARchSymMatrix<ARTYPE>:: -DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, int* pcolp, - char uplop, double thresholdp, bool check) -{ - - this->m = np; - this->n = np; - nnz = nnzp; - a = ap; - irow = irowp; - pcol = pcolp; - pcol[this->n] = nnz; - uplo = uplop; - threshold = thresholdp; - - // Checking data. - if ((check)&&(!DataOK())) { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARchSymMatrix::DefineMatrix"); - } - - // Creating SuperMatrix A. - A = Create_Cholmod_Sparse_Matrix(this->n, this->n, nnz, a, irow, pcol, uplo, &c); - - this->defined = true; - -} // DefineMatrix. - - -template<class ARTYPE> -inline ARchSymMatrix<ARTYPE>:: -ARchSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, char uplop, double thresholdp, - bool check) : ARMatrix<ARTYPE>(np) -{ - cholmod_start (&c) ; - - factored = false; - DefineMatrix(np, nnzp, ap, irowp, pcolp, uplop, thresholdp, check); - -} // Long constructor. - - -template<class ARTYPE> -ARchSymMatrix<ARTYPE>:: -ARchSymMatrix(const std::string& file, double thresholdp, bool check) -{ - cholmod_start (&c) ; - - factored = false; - - try { - mat.Define(file); - } - catch (ArpackError) { // Returning from here if an error has occurred. - throw ArpackError(ArpackError::CANNOT_READ_FILE, "ARchSymMatrix"); - } - - if ((mat.NCols() == mat.NRows()) && (mat.IsSymmetric())) { - - DefineMatrix(mat.NCols(), mat.NonZeros(), (ARTYPE*)mat.Entries(), - mat.RowInd(), mat.ColPtr(), 'L', thresholdp, check); - } - else { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARchSymMatrix::ARchSymMatrix"); - } -} // Long constructor (Harwell-Boeing file). - - -template<class ARTYPE> -ARchSymMatrix<ARTYPE>& ARchSymMatrix<ARTYPE>:: -operator=(const ARchSymMatrix<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARCSMAT_H diff --git a/src/external/arpack++/include/arcspen.h b/src/external/arpack++/include/arcspen.h deleted file mode 100644 index 424535fa..00000000 --- a/src/external/arpack++/include/arcspen.h +++ /dev/null @@ -1,434 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARCSPen.h. - Arpack++ class ARchSymMPencil definition. - (CHOLMOD wrapper) - - Author of this class: - Martin Reuter - Date 11/05/2012 - - Arpack++ Author: - Francisco Gomes - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARCSPEN_H -#define ARCSPEN_H - -//#include "arch.h" -//#include "arerror.h" -#include "blas1c.h" -//#include "lapackc.h" -#include "arcsmat.h" - - -template<class ARTYPE> -class ARchSymPencil -{ - - protected: - - ARchSymMatrix<ARTYPE>* A; - ARchSymMatrix<ARTYPE>* B; - cholmod_factor *LAsB ; - bool factoredAsB; - cholmod_common c ; - - virtual void Copy(const ARchSymPencil& other); - -// void SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], -// int yind[], int ny, ARTYPE z[], int zind[], int& nz); - -// void ExpandAsB(); - -// void SubtractAsB(ARTYPE sigma); - - public: - - bool IsFactored() { return factoredAsB; } - - void FactorAsB(ARTYPE sigma); - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - - void MultInvAsBv(ARTYPE* v, ARTYPE* w); - - void DefineMatrices(ARchSymMatrix<ARTYPE>& Ap, ARchSymMatrix<ARTYPE>& Bp); - - ARchSymPencil() { factoredAsB = false; A=NULL; B=NULL; LAsB=NULL; cholmod_start (&c) ; } - // Short constructor that does nothing. - - ARchSymPencil(ARchSymMatrix<ARTYPE>& Ap, ARchSymMatrix<ARTYPE>& Bp); - // Long constructor. - - ARchSymPencil(const ARchSymPencil& other) { cholmod_start (&c) ; Copy(other); } - // Copy constructor. - - virtual ~ARchSymPencil() { if (LAsB) cholmod_free_factor(&LAsB,&c); cholmod_finish (&c) ;} - // Destructor. - - ARchSymPencil& operator=(const ARchSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARchSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -inline void ARchSymPencil<ARTYPE>::Copy(const ARchSymPencil<ARTYPE>& other) -{ - if (LAsB) cholmod_free_factor(&LAsB,&c); - A = other.A; - B = other.B; - factoredAsB = other.factoredAsB; - if (factoredAsB) - LAsB = cholmod_copy_factor(other.LAsB,&c); - -} // Copy. - -/* -template<class ARTYPE> -void ARchSymPencil<ARTYPE>:: -SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], - int yind[], int ny, ARTYPE z[], int zind[], int& nz) -// A strongly sequential (and inefficient) sparse saxpy algorithm. -{ - - int ix, iy; - - nz = 0; - if ((nx == 0) || (a == (ARTYPE)0)) { - copy(ny,y,1,z,1); - for (iy=0; iy!=ny; iy++) zind[iy] = yind[iy]; - nz = ny; - return; - } - if (ny == 0) { - copy(nx,x,1,z,1); - scal(nx,a,z,1); - for (ix=0; ix!=nx; ix++) zind[ix] = xind[ix]; - nz = nx; - return; - } - ix = 0; - iy = 0; - while (true) { - if (xind[ix] == yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]+y[iy++]; - if ((ix == nx)||(iy == ny)) break; - } - else if (xind[ix] < yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]; - if (ix == nx) break; - } - else { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - if (iy == ny) break; - } - } - while (iy < ny) { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - } - while (ix < nx) { - zind[nz] = xind[ix]; - z[nz++] = x[ix++]; - } - -} // SparseSaxpy. - - -template<class ARTYPE> -void ARchSymPencil<ARTYPE>::ExpandAsB() -{ - - int i, j, k, n; - int *pcol, *irow, *index, *pos; - ARTYPE *value; - - // Initializing variables. - - n = AsB.n; - index = AsB.index; - value = AsB.value; - irow = &index[n+1]; - pcol = new int[AsB.n+1]; - pos = new int[AsB.n+1]; - for (i=0; i<=n; i++) pcol[i] = index[i]; - for (i=0; i<=n; i++) pos[i] = 0; - - // Counting the elements in each column of AsB. - - if (AsB.uplo == 'U') { - - for (i=0; i!=n; i++) { - k = pcol[i+1]; - if ((k!=pcol[i])&&(irow[k-1]==i)) k--; - for (j=pcol[i]; j<k; j++) pos[irow[j]]++; - } - - } - else { // uplo == 'L' - - for (i=0; i!=n; i++) { - k = pcol[i]; - if ((k!=pcol[i+1])&&(irow[k]==i)) k++; - for (j=k; j<pcol[i+1]; j++) pos[irow[j]]++; - } - - } - - // Summing up index elements. - - for (i=0; i<n; i++) pos[i+1] += pos[i]; - for (i=n; i>0; i--) index[i] += pos[i-1]; - - // Expanding A. - - if (AsB.uplo == 'U') { - - for (i=n-1; i>=0; i--) { - pos[i] = index[i]+pcol[i+1]-pcol[i]; - k = pos[i]-1; - for (j=pcol[i+1]-1; j>=pcol[i]; j--) { - value[k] = value[j]; - irow[k--] = irow[j]; - } - } - for (i=1; i<n; i++) { - k = index[i]+pcol[i+1]-pcol[i]; - if ((k>index[i])&&(irow[k-1]==i)) k--; - for (j=index[i]; j<k; j++) { - value[pos[irow[j]]] = value[j]; - irow[pos[irow[j]]++] = i; - } - } - - } - else { // uplo == 'L' - - for (i=n-1; i>=0; i--) { - k = index[i+1]-1; - for (j=pcol[i+1]-1; j>=pcol[i]; j--) { - value[k] = value[j]; - irow[k--] = irow[j]; - } - pos[i] = index[i]; - } - for (i=0; i<(n-1); i++) { - k = index[i+1]-pcol[i+1]+pcol[i]; - if ((k<index[i+1])&&(irow[k]==i)) k++; - for (j=k; j<index[i+1]; j++) { - value[pos[irow[j]]] = value[j]; - irow[pos[irow[j]]++] = i; - } - } - - } - - AsB.nnz = index[n]; - - // Deleting temporary vectors. - - delete[] pcol; - delete[] pos; - -} // ExpandAsB. - - -template<class ARTYPE> -void ARchSymPencil<ARTYPE>::SubtractAsB(ARTYPE sigma) -{ - - int i, acol, bcol, asbcol, scol; - - // Quitting function if A->uplo is not equal to B->uplo. - - if ((A->uplo != B->uplo)&&(sigma != (ARTYPE)0)) { - throw ArpackError(ArpackError::DIFFERENT_TRIANGLES, - "ARchSymPencil::SubtractAsB"); - } - AsB.uplo = A->uplo; - - // Subtracting sigma*B from A. - - AsB.index[0] = 0; - asbcol = 0; - - for (i=0; i!=AsB.n; i++) { - bcol = B->pcol[i]; - acol = A->pcol[i]; - SparseSaxpy(-sigma, &B->a[bcol], &B->irow[bcol], B->pcol[i+1]-bcol, - &A->a[acol], &A->irow[acol], A->pcol[i+1]-acol, - &AsB.value[asbcol], &AsB.index[asbcol+AsB.n+1], scol); - asbcol += scol; - AsB.index[i+1] = asbcol; - } - - // Expanding AsB. - - ExpandAsB(); - - // Adding one to all elements of vector index - // because the decomposition function was written in FORTRAN. - - for (i=0; i<=AsB.n+AsB.nnz; i++) AsB.index[i]++; - -} // SubtractAsB. - -*/ - -template<class ARTYPE> -void ARchSymPencil<ARTYPE>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARchSymPencil::FactorAsB"); - } - - - if (LAsB) cholmod_free_factor(&LAsB,&c); - - cholmod_sparse* AsB; - if (sigma != 0.0) - { - std::cout << " Subtracting sigma B (sigma="<<sigma<<")"<<std::endl; - double alpha[2]; alpha[0]=1.0; alpha[1] = 1.0; - double beta[2]; beta[0] = -sigma; beta[1]=1.0; - AsB = cholmod_add(A->A,B->A,alpha,beta,1,0,&c); - } - else - AsB = A->A; - -//FILE *fp; -//fp=fopen("AsB.asc", "w"); -//cholmod_write_sparse(fp,AsB,NULL,NULL,&c); -//FILE *fpa; -//fpa=fopen("As.asc", "w"); -//cholmod_write_sparse(fpa,B->A,NULL,NULL,&c); -//FILE *fpb; -//fpb=fopen("Bs.asc", "w"); -//cholmod_write_sparse(fpb,A->A,NULL,NULL,&c); - - LAsB = cholmod_analyze (AsB, &c) ; - int info = cholmod_factorize (AsB, LAsB, &c) ; - - factoredAsB = (info != 0); - if (c.status != CHOLMOD_OK) - { - //std::cout << " sigma : " << sigma << std::endl; - - Write_Cholmod_Sparse_Matrix("AsB-error.asc",AsB,&c); - - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARchSymPencil::FactorAsB"); - - factoredAsB = false; - } - - if (sigma != 0.0) - cholmod_free_sparse(&AsB,&c); - - -} // FactorAsB (ARTYPE shift). - - -template<class ARTYPE> -void ARchSymPencil<ARTYPE>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - ::copy(A->ncols(), w, 1, v, 1); - B->MultInvv(w, w); - -} // MultInvBAv. - -template<class ARTYPE> -void ARchSymPencil<ARTYPE>::MultInvAsBv(ARTYPE* v, ARTYPE* w) -{ - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARchSymPencil::MultInvAsBv"); - } - - // Solving A.w = v (or AsI.w = v). - - //create b from v (data is not copied!!) - cholmod_dense * b = Create_Cholmod_Dense_Matrix(A->n,1,v,&c); - - cholmod_dense *x = cholmod_solve (CHOLMOD_A, LAsB, b, &c) ; - - Get_Cholmod_Dense_Data(x, A->n, w); - - free(b); - cholmod_free_dense(&x,&c); - - -} // MultInvAsBv - -template<class ARTYPE> -inline void ARchSymPencil<ARTYPE>:: -DefineMatrices(ARchSymMatrix<ARTYPE>& Ap, ARchSymMatrix<ARTYPE>& Bp) -{ - - A = &Ap; - B = &Bp; - - if (A->n != B->n) { - throw ArpackError(ArpackError::INCOMPATIBLE_SIZES, - "ARchSymMatrix::DefineMatrices"); - } - -} // DefineMatrices. - - -template<class ARTYPE> -inline ARchSymPencil<ARTYPE>:: -ARchSymPencil(ARchSymMatrix<ARTYPE>& Ap, ARchSymMatrix<ARTYPE>& Bp) -{ - cholmod_start (&c) ; - LAsB=NULL; - DefineMatrices(Ap, Bp); - -} // Long constructor. - - -template<class ARTYPE> -ARchSymPencil<ARTYPE>& ARchSymPencil<ARTYPE>:: -operator=(const ARchSymPencil<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUSPEN_H diff --git a/src/external/arpack++/include/arcssym.h b/src/external/arpack++/include/arcssym.h deleted file mode 100644 index 26094e93..00000000 --- a/src/external/arpack++/include/arcssym.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUSSym.h. - Arpack++ class ARluSymStdEig definition - (CHOLMOD version). - - Author of this class: - Martin Reuter - Date 11/05/2012 - - Arpack++ Author: - Francisco Gomes - - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARCSSYM_H -#define ARCSSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arssym.h" -#include "arcsmat.h" - - -template<class ARFLOAT> -class ARluSymStdEig: - public virtual ARSymStdEig<ARFLOAT, ARchSymMatrix<ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // a.2) Constructors and destructor. - - ARluSymStdEig() { } - // Short constructor. - - ARluSymStdEig(int nevp, ARchSymMatrix<ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymStdEig(int nevp, ARchSymMatrix<ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluSymStdEig(const ARluSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymStdEig() { } - // Destructor. - - // b) Operators. - - ARluSymStdEig& operator=(const ARluSymStdEig& other); - // Assignment operator. - -}; // class ARluSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI(this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARchSymMatrix<ARFLOAT> >:: - SetRegularMode(this->objOP, &ARchSymMatrix<ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARchSymMatrix<ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, &ARchSymMatrix<ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARchSymMatrix<ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, &ARchSymMatrix<ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARchSymMatrix<ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, &ARchSymMatrix<ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - this->ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluSymStdEig<ARFLOAT>& ARluSymStdEig<ARFLOAT>:: -operator=(const ARluSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUSSYM_H diff --git a/src/external/arpack++/include/ardfmat.h b/src/external/arpack++/include/ardfmat.h deleted file mode 100644 index cacf6b4c..00000000 --- a/src/external/arpack++/include/ardfmat.h +++ /dev/null @@ -1,453 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDFMat.h - Matrix template that generates a dense matrix from a file. - - ARPACK authors: - Richard Lehoucq - Kristyn Maschhoff - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#ifndef ARDFMAT_H -#define ARDFMAT_H - -#include <cstddef> -#include <fstream> -#include <cstdlib> -#include <cstring> -#include <cstdio> -#include <string> -#include "arch.h" -#include "arerror.h" - - -template<class ARTYPE> -class ARdfMatrix { - - private: - - // const int linelength = 256; - - std::string datafile; // Filename. - std::ifstream file; // File handler. - int m; // Number of rows. - int n; // Number of columns. - int blksize; // Size of each matrix block that is read at once. - int block; // Index of the matrix block that is to be read. - int nblocks; // Number of blocks the matrix contain. - int first; // First row/column stored in val. - int strows; // Number of rows actually stored in val. - int stcols; // Number of columns actually stored in val. - int headsize; // Number of lines in the heading part of the file - // (including the line that contains the matrix size). - bool roword; // A variable that indicates if the data will be read - // using a row-major or a column-major ordering. - ARTYPE* val; // Numerical values of matrix entries. - - void ConvertDouble(char* num); - - void SetComplexPointers(char* num, char* &realp, char* &imagp); - - bool ReadEntry(std::ifstream& file, double& val); - - bool ReadEntry(std::ifstream& file, float& val); - - bool ReadEntry(std::ifstream& file, arcomplex<double>& val); - - bool ReadEntry(std::ifstream& file, arcomplex<float>& val); - - public: - - bool IsDefined() const { return (m!=0); } - - bool IsOutOfCore() const { - return ((m!=0) && ((roword && (blksize<m)) || (blksize<n))); - } - - bool IsRowOrdered() const { return roword; } - - std::string Filename() const { return datafile; } - - void Rewind(); - - int BlockSize() const { return blksize; } - - int FirstIndex() const { return first; } - - int NBlocks() const { return nblocks; } - - int ColsInMemory() const { return stcols; } - - int RowsInMemory() const { return strows; } - - int NRows() const { return m; } - - int NCols() const { return n; } - - ARTYPE* Entries() const { return val; } - - void ReadBlock(); - // Function that reads a block of blksize rows/columns of the matrix. - - void Define(const std::string& filename, int blksizep = 0); - // Function that reads the matrix dimension. Define also read all - // of the matrix elements when blocksize = 0. - - ARdfMatrix(); - // Short constructor. - - ARdfMatrix(const std::string& filename, int blksizep = 0); - // Long constructor. - - ~ARdfMatrix(); - // Destructor. - -}; // Class ARdfMatrix. - - -// ------------------------------------------------------------------------ // -// ARdfMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -inline void ARdfMatrix<ARTYPE>::ConvertDouble(char* num) -{ - - char* pd; - - pd = strchr((char*)num,'D'); - if (pd) *pd = 'E'; - pd = strchr((char*)num,'d'); - if (pd) *pd = 'E'; - -} // ConvertDouble. - - -template<class ARTYPE> -inline void ARdfMatrix<ARTYPE>:: -SetComplexPointers(char* num, char* &realp, char* &imagp) -{ - - realp = num; - while (*realp == ' ') realp++; - imagp = realp; - while (*imagp != ' ') imagp++; - -} // SetComplexPointers. - - -template<class ARTYPE> -inline bool ARdfMatrix<ARTYPE>::ReadEntry(std::ifstream& file, double& val) -{ - - char num[LINELEN]; - char c; - - if (file.get((char*)num,LINELEN,'\n')) { - file.get(c); - ConvertDouble((char*)num); - val = atof((char*)num); - return true; - } - else { - return false; - } - -} // ReadEntry (double). - - -template<class ARTYPE> -inline bool ARdfMatrix<ARTYPE>::ReadEntry(std::ifstream& file, float& val) -{ - - double dval; - bool ret; - - ret = ReadEntry(file, dval); - val = (float)dval; - return ret; - -} // ReadEntry (float). - - -template<class ARTYPE> -inline bool ARdfMatrix<ARTYPE>:: -ReadEntry(std::ifstream& file, arcomplex<double>& val) -{ - - char num[LINELEN]; - char c; - char *realp, *imagp; - - if (file.get((char*)num,LINELEN,'\n')) { - file.get(c); - SetComplexPointers((char*)num, realp, imagp); - ConvertDouble((char*)realp); - ConvertDouble((char*)imagp); - val = arcomplex<double>(atof((char*)realp), atof((char*)imagp)); - return true; - } - else { - return false; - } - -} // ReadEntry (arcomplex<double>). - - -template<class ARTYPE> -inline bool ARdfMatrix<ARTYPE>:: -ReadEntry(std::ifstream& file, arcomplex<float>& val) -{ - - char num[LINELEN]; - char c; - char *realp, *imagp; - - if (file.get((char*)num,LINELEN,'\n')) { - file.get(c); - SetComplexPointers((char*)num, realp, imagp); - ConvertDouble((char*)realp); - ConvertDouble((char*)imagp); - val = arcomplex<float>(atof((char*)realp), atof((char*)imagp)); - return true; - } - else { - return false; - } - -} // ReadEntry (arcomplex<float>). - - -template<class ARTYPE> -void ARdfMatrix<ARTYPE>::Rewind() -{ - - char data[LINELEN]; - char c; - - file.seekg(0); - block = 0; - first = 0; - strows = 0; - stcols = 0; - - // Skipping the header. - - for (int i=0; i<headsize; i++) { - file.get((char*)data,LINELEN,'\n'); - file.get(c); - } - -} // Rewind. - - -template<class ARTYPE> -void ARdfMatrix<ARTYPE>::ReadBlock() -{ - - int i, j, last; - ARTYPE value; - - // Repositioning the file pointer if block == 0. - - if (block == 0) Rewind(); - - // Reading a block. - - first = (block++)*blksize; // First row/column to be read. - last = first+blksize; // First row/column of the next block. - - if (roword) { - - // Adjusting last if we are going to read the last block. - - if (last > m) { - last = m; - block = 0; - } - last -= first; - strows = last; - stcols = n; - - // Reading matrix data. - - for (i=0; i<last; i++) { - j = i; - while ((j < n*last) && (ReadEntry(file, value))) { - val[j] = value; - j+=last; - } - - // Exiting if the file is corrupted. - - if (j < (n*last)) { - throw ArpackError(ArpackError::UNEXPECTED_EOF, "ARdfMatrix"); - } - } - - } - else { - - // Adjusting last if we are going to read the last block. - - if (last > n) { - last = n; - block = 0; - } - last -= first; - strows = m; - stcols = last; - - // Reading matrix data. - - j = 0; - while ((j < m*last) && (ReadEntry(file, value))) { - val[j++] = value; - } - - // Exiting if the file is corrupted. - - if (j < m*last) { - throw ArpackError(ArpackError::UNEXPECTED_EOF, "ARdfMatrix"); - } - - } - -} // ReadBlock. - - -template<class ARTYPE> -void ARdfMatrix<ARTYPE>::Define(const std::string& filename, int blksizep) -{ - - // Declaring variables. - - char c; - char data[LINELEN]; - - // Opening the file. - - datafile = filename; - file.open(datafile.c_str()); - - if (!file) { - throw ArpackError(ArpackError::CANNOT_OPEN_FILE, "ARdfMatrix"); - } - - // Setting initial values. - - blksize = blksizep; - block = 0; - headsize = 0; - first = 0; - strows = 0; - stcols = 0; - - // Reading the file heading. - - do { - file.get((char*)data,LINELEN,'\n'); - file.get(c); - headsize++; - } - while (data[0] == '%'); - - // Reading m and n or returning if a problem was detected. - - if (sscanf(data, "%d %d", &m, &n) != 2) { - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARdfMatrix"); - } - if ((m<1) || (n<1)) { - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARdfMatrix"); - } - - // Defining roword. - - roword = ((blksize != 0) && (m > n)); - - // (Re)Dimensioning val. - - if (val != NULL) delete[] val; - - if (blksize == 0) { - - // Redefining blksize and reading the entire matrix. - - blksize = n; - nblocks = 1; - val = new ARTYPE[m*blksize]; - ReadBlock(); - - } - else if (roword) { - - // m >> n, so we will read only blksize rows (but not now). - - if (blksize > m) blksize = m; - nblocks = (m+blksize-1)/blksize; - val = new ARTYPE[blksize*n]; - if (blksize == m) ReadBlock(); - - } - else { - - // n >> m, so we will read only blksize columns (but not now). - - if (blksize > n) blksize = n; - nblocks = (n+blksize-1)/blksize; - val = new ARTYPE[m*blksize]; - if (blksize == n) ReadBlock(); - - } - -} // Define. - - -template<class ARTYPE> -ARdfMatrix<ARTYPE>::ARdfMatrix() -{ - - m = 0; - n = 0; - block = 0; - blksize = 0; - headsize = 0; - first = 0; - strows = 0; - stcols = 0; - roword = false; - val = NULL; - -} // Short constructor. - - -template<class ARTYPE> -ARdfMatrix<ARTYPE>::ARdfMatrix(const std::string& filename, int blksizep) -{ - - val = NULL; - Define(filename, blksizep); - -} // Long constructor. - - -template<class ARTYPE> -ARdfMatrix<ARTYPE>::~ARdfMatrix() -{ - - if (val != NULL) delete[] val; - -} // Destructor. - - -#endif // ARDFMAT_H - diff --git a/src/external/arpack++/include/ardgcomp.h b/src/external/arpack++/include/ardgcomp.h deleted file mode 100644 index 41240dce..00000000 --- a/src/external/arpack++/include/ardgcomp.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDGComp.h. - Arpack++ class ARluCompGenEig definition - (dense matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARDGCOMP_H -#define ARDGCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "ardnsmat.h" -#include "ardnspen.h" -#include "arrseig.h" -#include "argcomp.h" - - -template<class ARFLOAT> -class ARluCompGenEig: - public virtual - ARCompGenEig<ARFLOAT, ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT >, - ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT > > { - - private: - - // a) Data structure used to store matrices. - - ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT > Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluCompGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(arcomplex<ARFLOAT> sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(arcomplex<ARFLOAT> sigmap); - - // c.2) Constructors and destructor. - - ARluCompGenEig() { } - // Short constructor. - - ARluCompGenEig(int nevp, ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluCompGenEig(int nevp, ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluCompGenEig(const ARluCompGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluCompGenEig() { } - - // d) Operators. - - ARluCompGenEig& operator=(const ARluCompGenEig& other); - // Assignment operator. - -}; // class ARluCompGenEig. - - -// ------------------------------------------------------------------------ // -// ARluCompGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -Copy(const ARluCompGenEig<ARFLOAT>& other) -{ - - ARCompGenEig<ARFLOAT, ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT >, - ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -ChangeShift(arcomplex<ARFLOAT> sigmaRp) -{ - - this->objOP->FactorAsB(sigmaRp); - ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> >::ChangeShift(sigmaRp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetRegularMode(&Pencil, - &ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -SetShiftInvertMode(arcomplex<ARFLOAT> sigmap) -{ - - ARCompGenEig<ARFLOAT, ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>, - ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, - &ARdsNonSymPencil<arcomplex<ARFLOAT>,ARFLOAT>::MultInvAsBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluCompGenEig<ARFLOAT>:: -ARluCompGenEig(int nevp, ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, - arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvBAv, - &Pencil, - &ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultBv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluCompGenEig<ARFLOAT>:: -ARluCompGenEig(int nevp, ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvAsBv, - &Pencil, - &ARdsNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultBv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - SetShiftInvertMode(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluCompGenEig<ARFLOAT>& ARluCompGenEig<ARFLOAT>:: -operator=(const ARluCompGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDGCOMP_H diff --git a/src/external/arpack++/include/ardgnsym.h b/src/external/arpack++/include/ardgnsym.h deleted file mode 100644 index ec9c60bd..00000000 --- a/src/external/arpack++/include/ardgnsym.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDGNSym.h. - Arpack++ class ARluNonSymGenEig definition - (dense matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARDGNSYM_H -#define ARDGNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "ardnsmat.h" -#include "ardnspen.h" -#include "argnsym.h" - - -template<class ARFLOAT> -class ARluNonSymGenEig: - public virtual ARNonSymGenEig<ARFLOAT, ARdsNonSymPencil<ARFLOAT, ARFLOAT>, - ARdsNonSymPencil<ARFLOAT, ARFLOAT> > { - - private: - - // a) Data structure used to store matrices. - - ARdsNonSymPencil<ARFLOAT, ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluNonSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp = 0.0); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetComplexShiftMode(char partp, ARFLOAT sigmaRp,ARFLOAT sigmaIp); - - // c.2) Constructors and destructor. - - ARluNonSymGenEig() { } - // Short constructor. - - ARluNonSymGenEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluNonSymGenEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& B, ARFLOAT sigma, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (real shift and invert mode). - - ARluNonSymGenEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& B, char partp, - ARFLOAT sigmaRp, ARFLOAT sigmaIp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (complex shift and invert mode). - - ARluNonSymGenEig(const ARluNonSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluNonSymGenEig& operator=(const ARluNonSymGenEig& other); - // Assignment operator. - -}; // class ARluNonSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluNonSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -Copy(const ARluNonSymGenEig<ARFLOAT>& other) -{ - - ARNonSymGenEig<ARFLOAT, ARdsNonSymPencil<ARFLOAT, ARFLOAT>, - ARdsNonSymPencil<ARFLOAT, ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - if (sigmaIp == 0.0) { - this->objOP->FactorAsB(sigmaRp); - } - else { - this->objOP->FactorAsB(sigmaRp, sigmaIp, this->part); - } - ARrcNonSymGenEig<ARFLOAT>::ChangeShift(sigmaRp, sigmaIp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARdsNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetRegularMode(&Pencil, &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARNonSymGenEig<ARFLOAT, ARdsNonSymPencil<ARFLOAT, ARFLOAT>, - ARdsNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, - &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -SetComplexShiftMode(char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - ARNonSymGenEig<ARFLOAT, ARdsNonSymPencil<ARFLOAT, ARFLOAT>, - ARdsNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetComplexShiftMode(partp, sigmaRp, sigmaIp, &Pencil, - &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, - &Pencil, &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultAv); - -} // SetComplexShiftMode. - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultInvBAv, &Pencil, - &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, &Pencil, - &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - SetShiftInvertMode(sigmap); - -} // Long constructor (real shift and invert mode). - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& B, - char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp, const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, ARFLOAT* residp, - bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, &Pencil, - &ARdsNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - SetComplexShiftMode(partp, sigmaRp, sigmaIp); - -} // Long constructor (complex shift and invert mode). - - -template<class ARFLOAT> -ARluNonSymGenEig<ARFLOAT>& ARluNonSymGenEig<ARFLOAT>:: -operator=(const ARluNonSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDGNSYM_H diff --git a/src/external/arpack++/include/ardgsym.h b/src/external/arpack++/include/ardgsym.h deleted file mode 100644 index 31600802..00000000 --- a/src/external/arpack++/include/ardgsym.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDGSym.h. - Arpack++ class ARluSymGenEig definition - (dense matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARDGSYM_H -#define ARDGSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "ardsmat.h" -#include "ardspen.h" -#include "argsym.h" - - -template<class ARFLOAT> -class ARluSymGenEig: - public virtual ARSymGenEig<ARFLOAT, ARdsSymPencil<ARFLOAT>, - ARdsSymPencil<ARFLOAT> > { - - private: - - // a) Data structure used to store matrices. - - ARdsSymPencil<ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmap); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetBucklingMode(ARFLOAT sigmap); - - virtual void SetCayleyMode(ARFLOAT sigmap); - - // c.2) Constructors and destructor. - - ARluSymGenEig() { } - // Short constructor. - - ARluSymGenEig(int nevp, ARdsSymMatrix<ARFLOAT>& A, - ARdsSymMatrix<ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymGenEig(char InvertModep, int nevp, ARdsSymMatrix<ARFLOAT>& A, - ARdsSymMatrix<ARFLOAT>& B, ARFLOAT sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert, buckling and Cayley modes). - - ARluSymGenEig(const ARluSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluSymGenEig& operator=(const ARluSymGenEig& other); - // Assignment operator. - -}; // class ARluSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -Copy(const ARluSymGenEig<ARFLOAT>& other) -{ - - ARSymGenEig<ARFLOAT, ARdsSymPencil<ARFLOAT>, - ARdsSymPencil<ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::ChangeShift(ARFLOAT sigmap) -{ - - this->objOP->FactorAsB(sigmap); - ARrcSymGenEig<ARFLOAT>::ChangeShift(sigmap); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARdsSymPencil<ARFLOAT> >:: - SetRegularMode(&Pencil, &ARdsSymPencil<ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARdsSymPencil<ARFLOAT>, ARdsSymPencil<ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, &ARdsSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARdsSymPencil<ARFLOAT>::MultBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetBucklingMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARdsSymPencil<ARFLOAT>, ARdsSymPencil<ARFLOAT> >:: - SetBucklingMode(sigmap, &Pencil, &ARdsSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARdsSymPencil<ARFLOAT>::MultAv); - -} // SetBucklingMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetCayleyMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARdsSymPencil<ARFLOAT>, ARdsSymPencil<ARFLOAT> >:: - SetCayleyMode(sigmap, &Pencil, &ARdsSymPencil<ARFLOAT>::MultInvAsBv, - &Pencil, &ARdsSymPencil<ARFLOAT>::MultAv); - this->ChangeMultBx(&Pencil, &ARdsSymPencil<ARFLOAT>::MultBv); - -} // SetCayleyMode. - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(int nevp, ARdsSymMatrix<ARFLOAT>& A, - ARdsSymMatrix<ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->InvertMode = 'S'; - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARdsSymPencil<ARFLOAT>::MultInvBAv, &Pencil, - &ARdsSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(char InvertModep, int nevp, ARdsSymMatrix<ARFLOAT>& A, - ARdsSymMatrix<ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARdsSymPencil<ARFLOAT>::MultInvAsBv, &Pencil, - &ARdsSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - this->InvertMode = this->CheckInvertMode(InvertModep); - switch (this->InvertMode) { - case 'B': - this->ChangeMultBx(&Pencil, &ARdsSymPencil<ARFLOAT>::MultAv); - case 'S': - ChangeShift(sigmap); - break; - case 'C': - SetCayleyMode(sigmap); - } - -} // Long constructor (shift and invert, buckling and Cayley modes). - - -template<class ARFLOAT> -ARluSymGenEig<ARFLOAT>& ARluSymGenEig<ARFLOAT>:: -operator=(const ARluSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDGSYM_H diff --git a/src/external/arpack++/include/ardnsmat.h b/src/external/arpack++/include/ardnsmat.h deleted file mode 100644 index a2436b93..00000000 --- a/src/external/arpack++/include/ardnsmat.h +++ /dev/null @@ -1,622 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDNSMat.h. - Arpack++ class ARdsNonSymMatrix definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "ardnspen.h" - -#ifndef ARDNSMAT_H -#define ARDNSMAT_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "armat.h" -#include "arerror.h" -#include "blas1c.h" -#include "lapackc.h" -#include "ardfmat.h" - -template<class AR_T, class AR_S> class ARdsNonSymPencil; - -template<class ARTYPE, class ARFLOAT> -class ARdsNonSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARdsNonSymPencil<ARTYPE, ARFLOAT>; - friend class ARdsNonSymPencil<ARFLOAT, ARFLOAT>; - - protected: - - bool factored; - int info; - int* ipiv; - ARTYPE* A; - ARTYPE* Ainv; - ARdfMatrix<ARTYPE> mat; - - void ClearMem(); - - virtual void Copy(const ARdsNonSymMatrix& other); - - void CreateStructure(); - - void ThrowError(); - - public: - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultMtv(ARTYPE* v, ARTYPE* w); - - void MultMtMv(ARTYPE* v, ARTYPE* w); - - void MultMMtv(ARTYPE* v, ARTYPE* w); - - void Mult0MMt0v(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, ARTYPE* Ap); - - void DefineMatrix(int mp, int np, ARTYPE* Ap); - - ARdsNonSymMatrix(): ARMatrix<ARTYPE>() { factored = false; } - // Short constructor that does nothing. - - ARdsNonSymMatrix(int np, ARTYPE* Ap); - // Long constructor (square matrix). - - ARdsNonSymMatrix(int mp, int np, ARTYPE* Ap); - // Long constructor (rectangular matrix). - - ARdsNonSymMatrix(const std::string& file, int blksizep = 0); - // Long constructor (Matrix stored in a file). - - ARdsNonSymMatrix(const ARdsNonSymMatrix& other) { Copy(other); } - // Copy constructor. - - virtual ~ARdsNonSymMatrix() { ClearMem(); } - // Destructor. - - ARdsNonSymMatrix& operator=(const ARdsNonSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARdsNonSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE, class ARFLOAT> -inline void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::ClearMem() -{ - - if (factored) { - delete[] Ainv; - delete[] ipiv; - Ainv = NULL; - ipiv = NULL; - } - -} // ClearMem. - - -template<class ARTYPE, class ARFLOAT> -inline void ARdsNonSymMatrix<ARTYPE, ARFLOAT>:: -Copy(const ARdsNonSymMatrix<ARTYPE, ARFLOAT>& other) -{ - - // Copying very fundamental variables and user-defined parameters. - - this->m = other.m; - this->n = other.n; - this->defined = other.defined; - factored = other.factored; - info = other.info; - A = other.A; - - // Copying mat. - - if (other.mat.IsDefined()) { - mat.Define(other.mat.Filename(),other.mat.BlockSize()); - } - - // Returning from here if "other" was not factored. - - if (!factored) return; - - // Copying vectors. - - Ainv = new ARTYPE[this->m*this->n]; - ipiv = new int[this->n]; - - copy(this->m*this->n, other.Ainv, 1, Ainv, 1); - for (int i=0; i<this->n; i++) ipiv[i] = other.ipiv[i]; - -} // Copy. - - -template<class ARTYPE, class ARFLOAT> -inline void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::CreateStructure() -{ - - ClearMem(); - Ainv = new ARTYPE[this->m*this->n]; - ipiv = new int[this->n]; - -} // CreateStructure. - - -template<class ARTYPE, class ARFLOAT> -inline void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::ThrowError() -{ - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARdsNonSymMatrix::FactorA"); - } - else if (info) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARdsNonSymMatrix::FactorA"); - } - -} // ThrowError. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::FactorA() -{ - - // Quitting the function if A was not defined or is rectangular. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARdsNonSymMatrix::FactorA"); - } - - if (this->m!=this->n) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARdsNonSymMatrix::FactorA"); - } - - if (mat.IsOutOfCore()) { - throw ArpackError(ArpackError::INSUFICIENT_MEMORY, - "ARdsNonSymMatrix::FactorA"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Copying A to Ainv; - - ::copy(this->m*this->n, A, 1, Ainv, 1); - - // Decomposing A. - - getrf(this->m, this->n, Ainv, this->m, ipiv, info); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorA. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::FactorAsI(ARTYPE sigma) -{ - - // Quitting the function if A was not defined or is rectangular. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARdsNonSymMatrix::FactorAsI"); - } - - if (this->m!=this->n) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARdsNonSymMatrix::FactorAsI"); - } - - if (mat.IsOutOfCore()) { - throw ArpackError(ArpackError::INSUFICIENT_MEMORY, - "ARdsNonSymMatrix::FactorAsI"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Subtracting sigma*I from A. - - ::copy(this->m*this->n,A,1,Ainv,1); - for (int i=0; i<(this->m*this->n); i+=this->m+1) Ainv[i]-=sigma; - - // Decomposing AsI. - - getrf(this->m, this->n, Ainv, this->m, ipiv, info); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorAsI. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::MultMv(ARTYPE* v, ARTYPE* w) -{ - - int i; - ARTYPE* t; - ARTYPE one; - ARTYPE zero; - - one = (ARTYPE)0 + 1.0; - zero = (ARTYPE)0; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARdsNonSymMatrix::MultMv"); - } - - // Determining w = M.v. - - if (mat.IsOutOfCore()) { - - if (this->m>this->n) { - - // Matrix is "tall". - - mat.Rewind(); - for (i=0; i<mat.NBlocks(); i++) { - mat.ReadBlock(); - gemv("N", mat.RowsInMemory(), this->n, one, mat.Entries(), - mat.RowsInMemory(), v, 1, zero, &w[mat.FirstIndex()], 1); - } - - } - else { - - // Matrix is "fat". - - mat.Rewind(); - t = new ARTYPE[mat.ColsInMemory()]; - for (i=0; i<this->m; i++) w[i] = zero; - for (i=0; i<mat.NBlocks(); i++) { - mat.ReadBlock(); - gemv("N", this->m, mat.ColsInMemory(), one, mat.Entries(), - this->m, &v[mat.FirstIndex()], 1, zero, t, 1); - axpy(this->m, one, t, 1, w, 1); - } - delete[] t; - - } - - } - else { - - gemv("N", this->m, this->n, one, A, this->m, v, 1, zero, w, 1); - - } - -} // MultMv. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::MultMtv(ARTYPE* v, ARTYPE* w) -{ - - int i; - ARTYPE* t; - ARTYPE one; - ARTYPE zero; - - one = (ARTYPE)0 + 1.0; - zero = (ARTYPE)0; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARdsNonSymMatrix::MultMtv"); - } - - // Determining w = M'.v. - - if (mat.IsOutOfCore()) { - - if (this->m<=this->n) { - - // Matrix is "fat". - - mat.Rewind(); - for (i=0; i<mat.NBlocks(); i++) { - mat.ReadBlock(); - gemv("T", this->m, mat.ColsInMemory(), one, mat.Entries(), - this->m, v, 1, zero, &w[mat.FirstIndex()], 1); - } - - } - else { - - // Matrix is "tall". - - mat.Rewind(); - t = new ARTYPE[mat.ColsInMemory()]; - for (i=0; i<this->m; i++) w[i] = zero; - for (i=0; i<mat.NBlocks(); i++) { - mat.ReadBlock(); - gemv("T", mat.RowsInMemory(), this->n, one, mat.Entries(), - mat.RowsInMemory(), &v[mat.FirstIndex()], 1, zero, t, 1); - axpy(mat.RowsInMemory(), one, t, 1, w, 1); - } - delete[] t; - - } - - } - else { - - gemv("T", this->m, this->n, one, A, this->m, v, 1, zero, w, 1); - - } - - -} // MultMtv. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::MultMtMv(ARTYPE* v, ARTYPE* w) -{ - - int i; - ARTYPE *t, *s; - ARTYPE one; - ARTYPE zero; - - one = (ARTYPE)0 + 1.0; - zero = (ARTYPE)0; - - if (mat.IsOutOfCore() && (this->m>this->n)) { - - // Special code for "tall" matrices. - - t = new ARTYPE[mat.BlockSize()]; - s = new ARTYPE[this->n]; - - mat.Rewind(); - for (i=0; i<this->n; i++) w[i] = zero; - for (i=0; i<mat.NBlocks(); i++) { - mat.ReadBlock(); - gemv("N", mat.RowsInMemory(), this->n, one, mat.Entries(), - mat.RowsInMemory(), v, 1, zero, t, 1); - gemv("T", mat.RowsInMemory(), this->n, one, mat.Entries(), - mat.RowsInMemory(), t, 1, zero, s, 1); - axpy(this->n, one, s, 1, w, 1); - - } - - delete[] t; - delete[] s; - - } - else { - - t = new ARTYPE[this->m]; - - MultMv(v,t); - MultMtv(t,w); - - delete[] t; - - } - - -} // MultMtMv. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::MultMMtv(ARTYPE* v, ARTYPE* w) -{ - - int i; - ARTYPE *t, *s; - ARTYPE one; - ARTYPE zero; - - one = (ARTYPE)0 + 1.0; - zero = (ARTYPE)0; - - if (mat.IsOutOfCore() && (this->m<=this->n)) { - - // Special code for "fat" matrices. - - t = new ARTYPE[mat.BlockSize()]; - s = new ARTYPE[this->m]; - - mat.Rewind(); - for (i=0; i<this->m; i++) w[i] = zero; - for (i=0; i<mat.NBlocks(); i++) { - mat.ReadBlock(); - gemv("T", this->m, mat.ColsInMemory(), one, mat.Entries(), - this->m, v, 1, zero, t, 1); - gemv("N", this->m, mat.ColsInMemory(), one, mat.Entries(), - this->m, t, 1, zero, s, 1); - axpy(this->m, one, s, 1, w, 1); - - } - - delete[] t; - delete[] s; - - } - else { - - t = new ARTYPE[this->n]; - - MultMtv(v,t); - MultMv(t,w); - - delete[] t; - - } - -} // MultMMtv. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::Mult0MMt0v(ARTYPE* v, ARTYPE* w) -{ - - MultMv(&v[this->m],w); - MultMtv(v,&w[this->m]); - -} // Mult0MMt0v. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymMatrix<ARTYPE, ARFLOAT>::MultInvv(ARTYPE* v, ARTYPE* w) -{ - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARdsNonSymMatrix::MultInvv"); - } - - // Overwritting w with v. - - copy(this->n, v, 1, w, 1); - - // Solving A.w = v (or AsI.w = v). - - getrs("N", this->n, 1, Ainv, this->m, ipiv, w, this->m, info); - - // Handling errors. - - ThrowError(); - -} // MultInvv. - - -template<class ARTYPE, class ARFLOAT> -inline void ARdsNonSymMatrix<ARTYPE, ARFLOAT>:: -DefineMatrix(int np, ARTYPE* Ap) -{ - - // Defining member variables. - - this->n = np; - this->m = np; - A = Ap; - this->defined = true; - Ainv = NULL; - ipiv = NULL; - info = 0; - -} // DefineMatrix (square). - - -template<class ARTYPE, class ARFLOAT> -inline void ARdsNonSymMatrix<ARTYPE, ARFLOAT>:: -DefineMatrix(int mp, int np, ARTYPE* Ap) -{ - - // Defining member variables. - - this->m = mp; - this->n = np; - A = Ap; - this->defined = true; - Ainv = NULL; - ipiv = NULL; - info = 0; - -} // DefineMatrix (rectangular). - - -template<class ARTYPE, class ARFLOAT> -inline ARdsNonSymMatrix<ARTYPE, ARFLOAT>:: -ARdsNonSymMatrix(int np, ARTYPE* Ap) : ARMatrix<ARTYPE>(np) -{ - - factored = false; - DefineMatrix(np, Ap); - -} // Long constructor (square matrix). - - -template<class ARTYPE, class ARFLOAT> -inline ARdsNonSymMatrix<ARTYPE, ARFLOAT>:: -ARdsNonSymMatrix(int mp, int np, ARTYPE* Ap) : ARMatrix<ARTYPE>(mp, np) -{ - - factored = false; - DefineMatrix(mp, np, Ap); - -} // Long constructor (rectangular matrix). - - -template<class ARTYPE, class ARFLOAT> -ARdsNonSymMatrix<ARTYPE, ARFLOAT>::ARdsNonSymMatrix(const std::string& file, int blksizep) -{ - - factored = false; - - try { - mat.Define(file, blksizep); - } - catch (ArpackError) { // Returning from here if an error has occurred. - throw ArpackError(ArpackError::CANNOT_READ_FILE, "ARdsNonSymMatrix"); - } - - if (mat.NCols() == mat.NRows()) { - DefineMatrix(mat.NCols(), (ARTYPE*)mat.Entries()); - } - else { - DefineMatrix(mat.NRows(), mat.NCols(), (ARTYPE*)mat.Entries()); - } - -} // Long constructor (Matrix stored in a file). - - -template<class ARTYPE, class ARFLOAT> -ARdsNonSymMatrix<ARTYPE, ARFLOAT>& ARdsNonSymMatrix<ARTYPE, ARFLOAT>:: -operator=(const ARdsNonSymMatrix<ARTYPE, ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDNSMAT_H diff --git a/src/external/arpack++/include/ardnspen.h b/src/external/arpack++/include/ardnspen.h deleted file mode 100644 index 04d2bd41..00000000 --- a/src/external/arpack++/include/ardnspen.h +++ /dev/null @@ -1,324 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDNSPen.h. - Arpack++ class ARdsNonSymPencil definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARDNSPEN_H -#define ARDNSPEN_H - -#include "arch.h" -#include "arerror.h" -#include "blas1c.h" -#include "lapackc.h" -#include "ardnsmat.h" - - -template<class ARTYPE, class ARFLOAT> -class ARdsNonSymPencil -{ - - protected: - - char part; - ARdsNonSymMatrix<ARTYPE, ARFLOAT>* A; - ARdsNonSymMatrix<ARTYPE, ARFLOAT>* B; - ARdsNonSymMatrix<ARTYPE, ARFLOAT> AsB; -#ifdef ARCOMP_H - ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> AsBc; -#endif - - virtual void Copy(const ARdsNonSymPencil& other); - - public: - -#ifdef ARCOMP_H - bool IsFactored() { return (AsB.IsFactored()||AsBc.IsFactored()); } -#else - bool IsFactored() { return AsB.IsFactored(); } -#endif - - void FactorAsB(ARTYPE sigma); - -#ifdef ARCOMP_H - void FactorAsB(ARFLOAT sigmaR, ARFLOAT sigmaI, char partp = 'R'); -#endif - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - -#ifdef ARCOMP_H - void MultInvAsBv(arcomplex<ARFLOAT>* v, arcomplex<ARFLOAT>* w); -#endif - - void MultInvAsBv(ARFLOAT* v, ARFLOAT* w); - - void DefineMatrices(ARdsNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARdsNonSymMatrix<ARTYPE, ARFLOAT>& Bp); - - ARdsNonSymPencil() { part = 'N'; } - // Short constructor that does nothing. - - ARdsNonSymPencil(ARdsNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARdsNonSymMatrix<ARTYPE, ARFLOAT>& Bp); - // Long constructor. - - ARdsNonSymPencil(const ARdsNonSymPencil& other) { Copy(other); } - // Copy constructor. - - virtual ~ARdsNonSymPencil() { } - // Destructor. - - ARdsNonSymPencil& operator=(const ARdsNonSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARdsNonSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE, class ARFLOAT> -inline void ARdsNonSymPencil<ARTYPE, ARFLOAT>:: -Copy(const ARdsNonSymPencil<ARTYPE, ARFLOAT>& other) -{ - - part = other.part; - A = other.A; - B = other.B; - AsB = other.AsB; -#ifdef ARCOMP_H - AsBc = other.AsBc; -#endif - -} // Copy. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymPencil<ARTYPE, ARFLOAT>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARdsNonSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARdsNonSymPencil::FactorAsB"); - } - - // Copying A to AsB if sigma = 0. - - if (sigma == (ARTYPE)0) { - - AsB = *A; - if (!AsB.IsFactored()) AsB.FactorA(); - return; - - } - - // Defining matrix AsB. - - if (!AsB.IsDefined()) { - AsB.DefineMatrix(A->ncols(), A->A); - } - - // Reserving memory for some vectors used in matrix decomposition. - - AsB.CreateStructure(); - - // Subtracting sigma*B from A and storing the result on AsB. - - ::copy(A->m*A->n, A->A, 1, AsB.Ainv, 1); - axpy(A->m*A->n, -sigma, B->A, 1, AsB.Ainv, 1); - - // Decomposing AsB. - - getrf(AsB.m, AsB.n, AsB.Ainv, AsB.m, AsB.ipiv, AsB.info); - - // Handling errors. - - AsB.ThrowError(); - - AsB.factored = true; - -} // FactorAsB (ARTYPE shift). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymPencil<ARTYPE, ARFLOAT>:: -FactorAsB(ARFLOAT sigmaR, ARFLOAT sigmaI, char partp) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARdsNonSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARdsNonSymPencil::FactorAsB"); - } - - // Defining matrix AsB. - - if (!AsBc.IsDefined()) { - part = partp; - AsBc.DefineMatrix(A->ncols(), 0); - } - - // Reserving memory for some vectors used in matrix decomposition. - - AsBc.CreateStructure(); - - // Subtracting sigma*B from A and storing the result on AsBc. - - arcomplex<ARFLOAT> sigma(sigmaR, sigmaI); - for (int i=0; i<(A->m*A->n); i++) AsBc.Ainv[i] = A->A[i]-sigma*B->A[i]; - - // Decomposing AsBc. - - getrf(AsBc.m, AsBc.n, AsBc.Ainv, AsBc.m, AsBc.ipiv, AsBc.info); - - // Handling errors. - - AsBc.ThrowError(); - - AsBc.factored = true; - -} // FactorAsB (arcomplex<ARFLOAT> shift). -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymPencil<ARTYPE, ARFLOAT>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - B->MultInvv(w, w); - -} // MultInvBAv. - - -#ifdef ARCOMP_H - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymPencil<ARTYPE, ARFLOAT>:: -MultInvAsBv(arcomplex<ARFLOAT>* v, arcomplex<ARFLOAT>* w) -{ - - AsB.MultInvv((ARTYPE*)v,(ARTYPE*)w); - -} // MultInvAsBv (arcomplex<ARFLOAT>). - -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARdsNonSymPencil<ARTYPE, ARFLOAT>::MultInvAsBv(ARFLOAT* v, ARFLOAT* w) -{ - - if (part == 'N') { // shift is real. - - AsB.MultInvv((ARTYPE*)v,(ARTYPE*)w); - - } - else { // shift is complex. - -#ifdef ARCOMP_H - - int i; - arcomplex<ARFLOAT> *tv, *tw; - - tv = new arcomplex<ARFLOAT>[AsBc.ncols()]; - tw = new arcomplex<ARFLOAT>[AsBc.ncols()]; - - for (i=0; i!=AsBc.ncols(); i++) tv[i] = arcomplex<ARFLOAT>(v[i], 0.0); - - AsBc.MultInvv(tv, tw); - - if (part=='I') { - for (i=0; i!=AsBc.ncols(); i++) w[i] = imag(tw[i]); - } - else { - for (i=0; i!=AsBc.ncols(); i++) w[i] = real(tw[i]); - } - - delete[] tv; - delete[] tw; - -#endif // ARCOMP_H. - - } - -} // MultInvAsBv (ARFLOAT). - - -template<class ARTYPE, class ARFLOAT> -inline void ARdsNonSymPencil<ARTYPE, ARFLOAT>:: -DefineMatrices(ARdsNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARdsNonSymMatrix<ARTYPE, ARFLOAT>& Bp) -{ - - A = &Ap; - B = &Bp; - - if ((A->n != B->n)||(A->m != B->m)) { - throw ArpackError(ArpackError::INCOMPATIBLE_SIZES, - "ARdsNonSymMatrix::DefineMatrices"); - } - -} // DefineMatrices. - - -template<class ARTYPE, class ARFLOAT> -inline ARdsNonSymPencil<ARTYPE, ARFLOAT>:: -ARdsNonSymPencil(ARdsNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARdsNonSymMatrix<ARTYPE, ARFLOAT>& Bp) -{ - - DefineMatrices(Ap, Bp); - -} // Long constructor. - - -template<class ARTYPE, class ARFLOAT> -ARdsNonSymPencil<ARTYPE, ARFLOAT>& ARdsNonSymPencil<ARTYPE, ARFLOAT>:: -operator=(const ARdsNonSymPencil<ARTYPE, ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDNSPEN_H diff --git a/src/external/arpack++/include/ardscomp.h b/src/external/arpack++/include/ardscomp.h deleted file mode 100644 index 094f5840..00000000 --- a/src/external/arpack++/include/ardscomp.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDSComp.h. - Arpack++ class ARluCompStdEig definition - (dense matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARDSCOMP_H -#define ARDSCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arscomp.h" -#include "ardnsmat.h" -#include "arrseig.h" - - -template<class ARFLOAT> -class ARluCompStdEig: - public virtual ARCompStdEig<ARFLOAT, - ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(arcomplex<ARFLOAT> sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(arcomplex<ARFLOAT> sigmap); - - // a.2) Constructors and destructor. - - ARluCompStdEig() { } - // Short constructor. - - ARluCompStdEig(int nevp, ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluCompStdEig(int nevp, ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluCompStdEig(const ARluCompStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluCompStdEig() { } - // Destructor. - - - // b) Operators. - - ARluCompStdEig& operator=(const ARluCompStdEig& other); - // Assignment operator. - -}; // class ARluCompStdEig. - - -// ------------------------------------------------------------------------ // -// ARluCompStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>:: -ChangeShift(arcomplex<ARFLOAT> sigmaRp) -{ - - this->objOP->FactorAsI(sigmaRp); - ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> >::ChangeShift(sigmaRp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetRegularMode(this->objOP, - &ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>:: -SetShiftInvertMode(arcomplex<ARFLOAT> sigmap) -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, - &ARdsNonSymMatrix<arcomplex<ARFLOAT>,ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluCompStdEig<ARFLOAT>:: -ARluCompStdEig(int nevp, ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, - &ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluCompStdEig<ARFLOAT>:: -ARluCompStdEig(int nevp, ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, - &ARdsNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluCompStdEig<ARFLOAT>& ARluCompStdEig<ARFLOAT>:: -operator=(const ARluCompStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDSCOMP_H diff --git a/src/external/arpack++/include/ardsmat.h b/src/external/arpack++/include/ardsmat.h deleted file mode 100644 index 1b16ae23..00000000 --- a/src/external/arpack++/include/ardsmat.h +++ /dev/null @@ -1,357 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDSMat.h. - Arpack++ class ARdsSymMatrix definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "ardspen.h" - -#ifndef ARDSMAT_H -#define ARDSMAT_H - -#include <cstddef> - -#include "arch.h" -#include "armat.h" -#include "arerror.h" -#include "blas1c.h" -#include "lapackc.h" - -template<class ARTYPE> class ARdsSymPencil; - -template<class ARTYPE> -class ARdsSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARdsSymPencil<ARTYPE>; - - protected: - - bool factored; - char uplo; - int info; - int* ipiv; - ARTYPE* A; - ARTYPE* Ainv; - - void ClearMem(); - - virtual void Copy(const ARdsSymMatrix& other); - - void SubtractAsI(ARTYPE sigma); - - void CreateStructure(); - - void ThrowError(); - - public: - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, ARTYPE* Ap, char uplop = 'L'); - - ARdsSymMatrix(): ARMatrix<ARTYPE>() { factored = false; } - // Short constructor that does nothing. - - ARdsSymMatrix(int np, ARTYPE* Ap, char uplop = 'L'); - // Long constructor. - - ARdsSymMatrix(const ARdsSymMatrix& other) { Copy(other); } - // Copy constructor. - - virtual ~ARdsSymMatrix() { ClearMem(); } - // Destructor. - - ARdsSymMatrix& operator=(const ARdsSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARdsSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -inline void ARdsSymMatrix<ARTYPE>::ClearMem() -{ - - if (factored) { - delete[] Ainv; - delete[] ipiv; - Ainv = NULL; - ipiv = NULL; - } - -} // ClearMem. - - -template<class ARTYPE> -inline void ARdsSymMatrix<ARTYPE>:: -Copy(const ARdsSymMatrix<ARTYPE>& other) -{ - - // Copying very fundamental variables and user-defined parameters. - - this->m = other.m; - this->n = other.n; - this->defined = other.defined; - factored = other.factored; - uplo = other.uplo; - info = other.info; - A = other.A; - - // Returning from here if "other" was not factored. - - if (!factored) return; - - // Copying vectors. - - Ainv = new ARTYPE[(this->n*this->n+this->n)/2]; - ipiv = new int[this->n]; - - copy((this->n*this->n+this->n)/2, other.Ainv, 1, Ainv, 1); - for (int i=0; i<this->n; i++) ipiv[i] = other.ipiv[i]; - -} // Copy. - - -template<class ARTYPE> -void ARdsSymMatrix<ARTYPE>::SubtractAsI(ARTYPE sigma) -{ - - int i,j; - - // Copying A to Ainv. - - ::copy((this->n*this->n+this->n)/2 ,A, 1, Ainv, 1); - - // Subtracting sigma from diagonal elements. - - if (uplo=='L') { - for (i=0, j=0; i<this->n; j+=(this->n-(i++))) Ainv[j] -= sigma; - } - else { - for (i=0, j=0; i<this->n; j+=(++i)) Ainv[j] -= sigma; - } - -} // SubtractAsI. - - -template<class ARTYPE> -inline void ARdsSymMatrix<ARTYPE>::CreateStructure() -{ - - ClearMem(); - Ainv = new ARTYPE[(this->n*this->n+this->n)/2]; - ipiv = new int[this->n]; - -} // CreateStructure. - - -template<class ARTYPE> -inline void ARdsSymMatrix<ARTYPE>::ThrowError() -{ - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARdsSymMatrix::FactorA"); - } - else if (info) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARdsSymMatrix::FactorA"); - } - -} // ThrowError. - - -template<class ARTYPE> -void ARdsSymMatrix<ARTYPE>::FactorA() -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARdsSymMatrix::FactorA"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Copying A to Ainv; - - ::copy((this->n*this->n+this->n)/2 ,A, 1, Ainv, 1); - - // Decomposing A. - - sptrf(&uplo, this->n, Ainv, ipiv, info); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorA. - - -template<class ARTYPE> -void ARdsSymMatrix<ARTYPE>::FactorAsI(ARTYPE sigma) -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARdsSymMatrix::FactorAsI"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Subtracting sigma*I from A. - - SubtractAsI(sigma); - - // Decomposing AsI. - - sptrf(&uplo, this->n, Ainv, ipiv, info); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorAsI. - - -template<class ARTYPE> -void ARdsSymMatrix<ARTYPE>::MultMv(ARTYPE* v, ARTYPE* w) -{ - - int i, j; - - ARTYPE zero = (ARTYPE)0; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARdsSymMatrix::MultMv"); - } - - // Determining w = M.v (unfortunately, the BLAS does not - // have a routine that works with packed matrices). - - for (i=0; i<this->n; i++) w[i] = zero; - - if (uplo=='L') { - - for (i=0, j=0; i<this->n; j+=(this->n-(i++))) { - w[i] += dot(this->n-i, &A[j], 1, &v[i], 1); - axpy(this->n-i-1, v[i], &A[j+1], 1, &w[i+1], 1); - } - - } - else { // uplo = 'U' - - for (i=0, j=0; i<this->n; j+=(++i)) { - w[i] += dot(i+1, &A[j], 1, v, 1); - axpy(i, v[i], &A[j], 1, w, 1); - } - - } - -} // MultMv. - - -template<class ARTYPE> -void ARdsSymMatrix<ARTYPE>::MultInvv(ARTYPE* v, ARTYPE* w) -{ - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARdsSymMatrix::MultInvv"); - } - - // Overwritting w with v. - - copy(this->n, v, 1, w, 1); - - // Solving A.w = v (or AsI.w = v). - - sptrs(&uplo, this->n, 1, Ainv, ipiv, w, this->n, info); - - // Handling errors. - - ThrowError(); - -} // MultInvv. - - -template<class ARTYPE> -inline void ARdsSymMatrix<ARTYPE>:: -DefineMatrix(int np, ARTYPE* Ap, char uplop) -{ - - // Defining member variables. - - this->m = np; - this->n = np; - uplo = uplop; - A = Ap; - this->defined = true; - Ainv = NULL; - ipiv = NULL; - info = 0; - -} // DefineMatrix. - - -template<class ARTYPE> -inline ARdsSymMatrix<ARTYPE>:: -ARdsSymMatrix(int np, ARTYPE* Ap, char uplop) : ARMatrix<ARTYPE>(np) -{ - - factored = false; - DefineMatrix(np, Ap, uplop); - -} // Long constructor. - - -template<class ARTYPE> -ARdsSymMatrix<ARTYPE>& ARdsSymMatrix<ARTYPE>:: -operator=(const ARdsSymMatrix<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDSMAT_H diff --git a/src/external/arpack++/include/ardsnsym.h b/src/external/arpack++/include/ardsnsym.h deleted file mode 100644 index fc2afe26..00000000 --- a/src/external/arpack++/include/ardsnsym.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDSNSym.h. - Arpack++ class ARluNonSymStdEig definition - (dense matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARDSNSYM_H -#define ARDSNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arsnsym.h" -#include "ardnsmat.h" - - -template<class ARFLOAT> -class ARluNonSymStdEig: - public virtual ARNonSymStdEig<ARFLOAT, ARdsNonSymMatrix<ARFLOAT, ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // a.2) Constructors and destructor. - - ARluNonSymStdEig() { } - // Short constructor. - - ARluNonSymStdEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluNonSymStdEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluNonSymStdEig(const ARluNonSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymStdEig() { } - // Destructor. - - // b) Operators. - - ARluNonSymStdEig& operator=(const ARluNonSymStdEig& other); - // Assignment operator. - -}; // class ARluNonSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluNonSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI(this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARdsNonSymMatrix<ARFLOAT, ARFLOAT> >:: - SetRegularMode(this->objOP, &ARdsNonSymMatrix<ARFLOAT, ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARdsNonSymMatrix<ARFLOAT, ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, - &ARdsNonSymMatrix<ARFLOAT, ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluNonSymStdEig<ARFLOAT>:: -ARluNonSymStdEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, - &ARdsNonSymMatrix<ARFLOAT, ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluNonSymStdEig<ARFLOAT>:: -ARluNonSymStdEig(int nevp, ARdsNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, - &ARdsNonSymMatrix<ARFLOAT, ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluNonSymStdEig<ARFLOAT>& ARluNonSymStdEig<ARFLOAT>:: -operator=(const ARluNonSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDSNSYM_H diff --git a/src/external/arpack++/include/ardspen.h b/src/external/arpack++/include/ardspen.h deleted file mode 100644 index 4e16b82b..00000000 --- a/src/external/arpack++/include/ardspen.h +++ /dev/null @@ -1,237 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDSPen.h. - Arpack++ class ARdsSymPencil definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARDSPEN_H -#define ARDSPEN_H - -#include "arch.h" -#include "arerror.h" -#include "blas1c.h" -#include "lapackc.h" -#include "ardsmat.h" - - -template<class ARTYPE> -class ARdsSymPencil -{ - - protected: - - ARdsSymMatrix<ARTYPE>* A; - ARdsSymMatrix<ARTYPE>* B; - ARdsSymMatrix<ARTYPE> AsB; - - virtual void Copy(const ARdsSymPencil& other); - - void SubtractAsB(ARTYPE sigma); - - public: - - bool IsFactored() { return AsB.IsFactored(); } - - void FactorAsB(ARTYPE sigma); - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - - void MultInvAsBv(ARTYPE* v, ARTYPE* w) { AsB.MultInvv(v,w); } - - void DefineMatrices(ARdsSymMatrix<ARTYPE>& Ap, ARdsSymMatrix<ARTYPE>& Bp); - - ARdsSymPencil() { AsB.factored = false; } - // Short constructor that does nothing. - - ARdsSymPencil(ARdsSymMatrix<ARTYPE>& Ap, ARdsSymMatrix<ARTYPE>& Bp); - // Long constructor. - - ARdsSymPencil(const ARdsSymPencil& other) { Copy(other); } - // Copy constructor. - - virtual ~ARdsSymPencil() { } - // Destructor. - - ARdsSymPencil& operator=(const ARdsSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARdsSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -inline void ARdsSymPencil<ARTYPE>::Copy(const ARdsSymPencil<ARTYPE>& other) -{ - - A = other.A; - B = other.B; - AsB = other.AsB; - -} // Copy. - - -template<class ARTYPE> -void ARdsSymPencil<ARTYPE>::SubtractAsB(ARTYPE sigma) -{ - - int sizeA, i, j, k, l; - - // Copying A into AsB. - - sizeA = (A->ncols()*A->ncols()+A->ncols())/2; - ::copy(sizeA, A->A, 1, AsB.Ainv, 1); - - // Returning if sigma == 0. - - if (sigma == (ARTYPE)0) return; - - // Subtracting sigma*B. - - if (A->uplo == B->uplo) { - - axpy(sizeA, -sigma, B->A, 1, AsB.Ainv, 1); - - } - else if (A->uplo == 'L') { // B->uplo == 'U' - - j = 0; - for (i=0; i<A->n; i++) { - for (l=i+1, k=(l*l+l)/2-1; l<=A->n; k+=(l++)) { - AsB.Ainv[j++]-=sigma*B->A[k]; - } - } - - } - else { // A->uplo == 'U' && B->uplo == 'L' - - j = 0; - for (i=0; i<A->n; i++) { - for (l=i+1, k=(l*l+l)/2-1; l<=A->n; k+=(l++)) { - AsB.Ainv[k]-=sigma*B->A[j++]; - } - } - - } - -} // SubtractAsB (ARTYPE shift). - - -template<class ARTYPE> -void ARdsSymPencil<ARTYPE>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARdsSymPencil::FactorAsB"); - } - - // Copying A to AsB if sigma = 0. - - if (sigma == (ARTYPE)0) { - - AsB = *A; - if (!AsB.IsFactored()) AsB.FactorA(); - return; - - } - - // Defining matrix AsB. - - if (!AsB.IsDefined()) { - AsB.DefineMatrix(A->ncols(), A->A, A->uplo); - } - - // Reserving memory for some vectors used in matrix decomposition. - - AsB.CreateStructure(); - - // Subtracting sigma*B from A and storing the result on AsB. - - SubtractAsB(sigma); - - // Decomposing AsB. - - sptrf(&AsB.uplo, AsB.n, AsB.Ainv, AsB.ipiv, AsB.info); - - // Handling errors. - - AsB.ThrowError(); - - AsB.factored = true; - -} // FactorAsB (ARTYPE shift). - - -template<class ARTYPE> -void ARdsSymPencil<ARTYPE>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - copy(A->ncols(), w, 1, v, 1); - B->MultInvv(w, w); - -} // MultInvBAv. - - -template<class ARTYPE> -inline void ARdsSymPencil<ARTYPE>:: -DefineMatrices(ARdsSymMatrix<ARTYPE>& Ap, ARdsSymMatrix<ARTYPE>& Bp) -{ - - A = &Ap; - B = &Bp; - - if ((A->n != B->n)||(A->m != B->m)) { - throw ArpackError(ArpackError::INCOMPATIBLE_SIZES, - "ARdsNonSymMatrix::DefineMatrices"); - } - -} // DefineMatrices. - - -template<class ARTYPE> -inline ARdsSymPencil<ARTYPE>:: -ARdsSymPencil(ARdsSymMatrix<ARTYPE>& Ap, ARdsSymMatrix<ARTYPE>& Bp) -{ - - AsB.factored = false; - DefineMatrices(Ap, Bp); - -} // Long constructor. - - -template<class ARTYPE> -ARdsSymPencil<ARTYPE>& ARdsSymPencil<ARTYPE>:: -operator=(const ARdsSymPencil<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDSPEN_H diff --git a/src/external/arpack++/include/ardssym.h b/src/external/arpack++/include/ardssym.h deleted file mode 100644 index faee7855..00000000 --- a/src/external/arpack++/include/ardssym.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARDSSym.h. - Arpack++ class ARluSymStdEig definition - (dense matrix version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARDSSYM_H -#define ARDSSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arssym.h" -#include "ardsmat.h" - - -template<class ARFLOAT> -class ARluSymStdEig: - public virtual ARSymStdEig<ARFLOAT, ARdsSymMatrix<ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // a.2) Constructors and destructor. - - ARluSymStdEig() { } - // Short constructor. - - ARluSymStdEig(int nevp, ARdsSymMatrix<ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymStdEig(int nevp, ARdsSymMatrix<ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluSymStdEig(const ARluSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymStdEig() { } - // Destructor. - - // b) Operators. - - ARluSymStdEig& operator=(const ARluSymStdEig& other); - // Assignment operator. - -}; // class ARluSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI(this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARdsSymMatrix<ARFLOAT> >:: - SetRegularMode(this->objOP, &ARdsSymMatrix<ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARdsSymMatrix<ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, &ARdsSymMatrix<ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARdsSymMatrix<ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, &ARdsSymMatrix<ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARdsSymMatrix<ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, &ARdsSymMatrix<ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluSymStdEig<ARFLOAT>& ARluSymStdEig<ARFLOAT>:: -operator=(const ARluSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARDSSYM_H diff --git a/src/external/arpack++/include/arerror.h b/src/external/arpack++/include/arerror.h deleted file mode 100644 index 6f96b479..00000000 --- a/src/external/arpack++/include/arerror.h +++ /dev/null @@ -1,348 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARError.h. - Definition of ArpackError, a class that handles errors - occurred during Arpack execution. - - There are three ways of handling an error: - a) Declaring a variable of type ArpackError and calling - function Set with the correct ErrorCode (see codes below). - b) Calling the constructor ArpackError(ErrorCode) to define - a variable. - c) Calling ArpackError::Set(ErrorCode) directly. - - If an error occurs, a brief description of the error is - displayed on the "cerr" stream, unless the variable - ARPACK_SILENT_MODE is defined. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARERROR_H -#define ARERROR_H - -#include <iostream> -#include <cstdlib> -#include <string> - -//#include "arch.h" - -template< typename T > -struct ArpackError_static -{ - public: - - enum ErrorCode { // Listing all kinds of errors. - - // Innocuous error type. - - NO_ERRORS = 0, - - // Errors in parameter definitions. - - PARAMETER_ERROR = -101, - N_SMALLER_THAN_2 = -102, - NEV_OUT_OF_BOUNDS = -103, - WHICH_UNDEFINED = -104, - PART_UNDEFINED = -105, - INVMODE_UNDEFINED = -106, - RANGE_ERROR = -107, - - // Errors in Aupp and Eupp functions. - - LAPACK_ERROR = -201, - START_RESID_ZERO = -202, - NOT_ACCURATE_EIG = -203, - REORDERING_ERROR = -204, - ARNOLDI_NOT_BUILD = -205, - AUPP_ERROR = -291, - EUPP_ERROR = -292, - - // Errors in main functions. - - CANNOT_PREPARE = -301, - CANNOT_FIND_BASIS = -302, - CANNOT_FIND_VALUES = -303, - CANNOT_FIND_VECTORS = -304, - CANNOT_FIND_SCHUR = -305, - SCHUR_UNDEFINED = -306, - - // Errors due to incorrect function calling sequence. - - CANNOT_GET_VECTOR = -401, - CANNOT_GET_PROD = -402, - CANNOT_PUT_VECTOR = -403, - PREPARE_NOT_OK = -404, - BASIS_NOT_OK = -405, - VALUES_NOT_OK = -406, - VECTORS_NOT_OK = -407, - SCHUR_NOT_OK = -408, - RESID_NOT_OK = -409, - - // Errors in classes that perform LU decompositions. - - MATRIX_IS_SINGULAR = -501, - DATA_UNDEFINED = -502, - INSUFICIENT_MEMORY = -503, - NOT_SQUARE_MATRIX = -504, - NOT_FACTORED_MATRIX = -505, - INCOMPATIBLE_SIZES = -506, - DIFFERENT_TRIANGLES = -507, - INCONSISTENT_DATA = -508, - CANNOT_READ_FILE = -509, - - // Errors in matrix files. - - CANNOT_OPEN_FILE = -551, - WRONG_MATRIX_TYPE = -552, - WRONG_DATA_TYPE = -553, - RHS_IGNORED = -554, - UNEXPECTED_EOF = -555, - - // Other severe errors. - - NOT_IMPLEMENTED = -901, - MEMORY_OVERFLOW = -902, - GENERIC_SEVERE = -999, - - // Warnings. - - NCV_OUT_OF_BOUNDS = 101, - MAXIT_NON_POSITIVE = 102, - MAX_ITERATIONS = 201, - NO_SHIFTS_APPLIED = 202, - CHANGING_AUTOSHIFT = 301, - DISCARDING_FACTORS = 401, - GENERIC_WARNING = 999 - - }; - - protected: - - static ErrorCode code; - -}; -// trick to initialize static member code, which is allowed in template - -template< typename T > -enum ArpackError_static<T>::ErrorCode ArpackError_static<T>::code = NO_ERRORS; -// "code" initialization. - -class ArpackError: public ArpackError_static<void> { - - private: - - static void Print(const std::string& where, const std::string& message); - // Writes error messages on cerr stream. - - public: - - static void Set(ErrorCode error, const std::string& where="AREigenProblem"); - // Set error code and write error messages. - - static int Status() { return (int) code; } - // Returns current value of error code. - - ArpackError(ErrorCode error, const std::string& where="AREigenProblem") { - Set(error,where); - } - // Constructor that set error code. - - ArpackError() { code = NO_ERRORS; }; - // Constructor that does nothing. - -}; - -inline void ArpackError::Print(const std::string& where, const std::string& message) -{ - -#ifndef ARPACK_SILENT_MODE - std::cerr << "Arpack error in " << where << "." << std::endl; - std::cerr << "-> " << message << "." << std::endl; -#endif - -} // Print - -inline void ArpackError::Set(ErrorCode error, const std::string& where) -{ - - code = error; - switch (code) { - case NO_ERRORS : - return; - case NOT_IMPLEMENTED : - Print(where, "This function was not implemented yet"); - return; - case MEMORY_OVERFLOW : - Print(where, "Memory overflow"); - return; - case GENERIC_SEVERE : - Print(where, "Severe error"); - return; - case PARAMETER_ERROR : - Print(where, "Some parameters were not correctly defined"); - return; - case N_SMALLER_THAN_2 : - Print(where, "'n' must be greater than one"); - return; - case NEV_OUT_OF_BOUNDS : - Print(where, "'nev' is out of bounds"); - return; - case WHICH_UNDEFINED : - Print(where, "'which' was not correctly defined"); - return; - case PART_UNDEFINED : - Print(where, "'part' must be one of 'R' or 'I'"); - return; - case INVMODE_UNDEFINED : - Print(where, "'InvertMode' must be one of 'S' or 'B'"); - return; - case RANGE_ERROR : - Print(where, "Range error"); - return; - case LAPACK_ERROR : - Print(where, "Could not perform LAPACK eigenvalue calculation"); - return; - case START_RESID_ZERO : - Print(where, "Starting vector is zero"); - return; - case NOT_ACCURATE_EIG : - Print(where, "Could not find any eigenvalue to sufficient accuracy"); - return; - case REORDERING_ERROR : - Print(where, "Reordering of Schur form was not possible"); - return; - case ARNOLDI_NOT_BUILD : - Print(where, "Could not build an Arnoldi factorization"); - return; - case AUPP_ERROR : - Print(where, "Error in ARPACK Aupd fortran code"); - return; - case EUPP_ERROR : - Print(where, "Error in ARPACK Eupd fortran code"); - return; - case CANNOT_PREPARE : - Print(where, "Could not correctly define internal variables"); - return; - case CANNOT_FIND_BASIS : - Print(where, "Could not find an Arnoldi basis"); - return; - case CANNOT_FIND_VALUES : - Print(where, "Could not find any eigenvalue"); - return; - case CANNOT_FIND_VECTORS: - Print(where, "Could not find any eigenvector"); - return; - case CANNOT_FIND_SCHUR : - Print(where, "Could not find any Schur vector"); - return; - case SCHUR_UNDEFINED : - Print(where, "FindEigenvectors must be used instead of FindSchurVectors"); - return; - case CANNOT_GET_VECTOR : - Print(where, "Vector is not already available"); - return; - case CANNOT_GET_PROD : - Print(where, "Matrix-vector product is not already available"); - return; - case CANNOT_PUT_VECTOR : - Print(where, "Could not store vector"); - return; - case PREPARE_NOT_OK : - Print(where, "DefineParameters must be called prior to this function"); - return; - case BASIS_NOT_OK : - Print(where, "An Arnoldi basis is not available"); - return; - case VALUES_NOT_OK : - Print(where, "Eigenvalues are not available"); - return; - case VECTORS_NOT_OK : - Print(where, "Eigenvectors are not available"); - return; - case SCHUR_NOT_OK : - Print(where, "Schur vectors are not available"); - return; - case RESID_NOT_OK : - Print(where, "Residual vector is not available"); - return; - case MATRIX_IS_SINGULAR : - Print(where, "Matrix is singular and could not be factored"); - return; - case DATA_UNDEFINED : - Print(where, "Matrix data was not defined"); - return; - case INSUFICIENT_MEMORY : - Print(where, "fill-in factor must be increased"); - return; - case NOT_SQUARE_MATRIX : - Print(where, "Matrix must be square to be factored"); - return; - case NOT_FACTORED_MATRIX: - Print(where, "Matrix must be factored before solving a system"); - return; - case INCOMPATIBLE_SIZES : - Print(where, "Matrix dimensions must agree"); - return; - case DIFFERENT_TRIANGLES: - Print(where, "A.uplo and B.uplo must be equal"); - return; - case INCONSISTENT_DATA : - Print(where, "Matrix data contain inconsistencies"); - return; - case CANNOT_READ_FILE : - Print(where, "Data file could not be read"); - return; - case CANNOT_OPEN_FILE : - Print(where, "Invalid path or filename"); - return; - case WRONG_MATRIX_TYPE : - Print(where, "Wrong matrix type"); - return; - case WRONG_DATA_TYPE : - Print(where, "Wrong data type"); - return; - case RHS_IGNORED : - Print(where, "RHS vector will be ignored"); - return; - case UNEXPECTED_EOF : - Print(where, "Unexpected end of file"); - return; - case NCV_OUT_OF_BOUNDS : - Print(where, "'ncv' is out of bounds"); - return; - case MAXIT_NON_POSITIVE : - Print(where, "'maxit' must be greater than zero"); - return; - case MAX_ITERATIONS : - Print(where, "Maximum number of iterations taken"); - return; - case NO_SHIFTS_APPLIED : - Print(where, "No shifts could be applied during a cycle of IRAM iteration"); - return; - case CHANGING_AUTOSHIFT : - Print(where, "Turning to automatic selection of implicit shifts"); - return; - case DISCARDING_FACTORS : - Print(where, "Factors L and U were not copied. Matrix must be factored"); - return; - case GENERIC_WARNING : - default: ; - Print(where, "There is something wrong"); - return; - } - -} // Set. - -//ArpackError::ErrorCode ArpackError::code = NO_ERRORS; -// "code" initialization. - -#endif // ARERROR_H diff --git a/src/external/arpack++/include/argcomp.h b/src/external/arpack++/include/argcomp.h deleted file mode 100644 index bce04ea9..00000000 --- a/src/external/arpack++/include/argcomp.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARGComp.h. - Arpack++ class ARCompGenEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARGCOMP_H -#define ARGCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arscomp.h" -#include "argeig.h" - -template<class ARFLOAT, class ARFOP, class ARFB> -class ARCompGenEig: - virtual public ARGenEig<ARFLOAT, arcomplex<ARFLOAT>, ARFOP, ARFB>, - virtual public ARCompStdEig<ARFLOAT, ARFOP> { - - public: - - // a) Constructors and destructor. - - ARCompGenEig() { } - // Short constructor (Does nothing but calling base classes constructors). - - ARCompGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - ARFB* objBp, - void (ARFB::* MultBxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARCompGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - ARFB* objBp, - void (ARFB::* MultBxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - arcomplex<ARFLOAT> sigmap, - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, arcomplex<ARFLOAT>* residp = NULL, - bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARCompGenEig(const ARCompGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARCompGenEig() { } - // Destructor. - - // b) Operators. - - ARCompGenEig& operator=(const ARCompGenEig& other); - // Assignment operator. - -}; // class ARCompGenEig. - - -// ------------------------------------------------------------------------ // -// ARCompGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline ARCompGenEig<ARFLOAT, ARFOP, ARFB>:: -ARCompGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - ARFB* objBp, - void (ARFB::* MultBxp)(arcomplex<ARFLOAT>[], arcomplex<ARFLOAT>[]), - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(np, nevp, objOPp, MultOPxp, objBp, MultBxp, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline ARCompGenEig<ARFLOAT, ARFOP, ARFB>:: -ARCompGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - ARFB* objBp, - void (ARFB::* MultBxp)(arcomplex<ARFLOAT>[], arcomplex<ARFLOAT>[]), - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, objOPp, MultOPxp, objBp, MultBxp, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT, class ARFOP, class ARFB> -ARCompGenEig<ARFLOAT, ARFOP, ARFB>& ARCompGenEig<ARFLOAT, ARFOP, ARFB>:: -operator=(const ARCompGenEig<ARFLOAT, ARFOP, ARFB>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARGCOMP_H diff --git a/src/external/arpack++/include/argeig.h b/src/external/arpack++/include/argeig.h deleted file mode 100644 index 74ccc07f..00000000 --- a/src/external/arpack++/include/argeig.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARGEig.h. - Arpack++ class ARGenEig definition. - Derived from ARStdEig, this class is the - base class for all generalized eigenvalue problems definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARGEIG_H -#define ARGEIG_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arerror.h" -#include "arrgeig.h" -#include "arseig.h" - -// ARGenEig class definition. - -template<class ARFLOAT, class ARTYPE, class ARFOP, class ARFB> -class ARGenEig: - virtual public ARrcGenEig<ARFLOAT, ARTYPE>, - virtual public ARStdEig<ARFLOAT, ARTYPE, ARFOP> { - - public: - - // a) Notation. - - typedef void (ARFB::* TypeBx)(ARTYPE[], ARTYPE[]); - typedef void (ARFOP::* TypeOPx)(ARTYPE[], ARTYPE[]); - - - protected: - - // b) Protected variables: - - ARFB *objB; // Object that has MultBx as a member function. - TypeBx MultBx; // Function that evaluates the product B*x. - - // c) Protected functions: - - virtual void Copy(const ARGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // d) Public functions: - - // d.1) Function that stores user defined parameters. - - virtual void DefineParameters(int np, int nevp, ARFOP* objOPp, - TypeOPx MultOPxp, ARFB* objBp, - TypeBx MultBxp, const std::string& whichp="LM", - int ncvp=0, ARFLOAT tolp=0.0, - int maxitp=0, ARTYPE* residp=NULL, - bool ishiftp=true); - // Set values of problem parameters (also called by constructors). - - - // d.2) Function that allow changes in problem parameters. - - void ChangeMultBx(ARFB* objBp, TypeBx MultBxp); - // Changes the matrix-vector function that performs B*x. - - - // d.3) Functions that perform all calculations in one step. - - virtual int FindArnoldiBasis(); - // Determines the Arnoldi basis related to the given problem. - - - // d.4) Constructors and destructor. - - ARGenEig() { } - // Constructor that does nothing but calling base classes constructors. - - ARGenEig(const ARGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARGenEig() { } - // Destructor (presently meaningless). - - // e) Operators. - - ARGenEig& operator=(const ARGenEig& other); - // Assignment operator. - -}; // class ARGenEig. - - -// ------------------------------------------------------------------------ // -// ARGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARTYPE, class ARFOP, class ARFB> -inline void ARGenEig<ARFLOAT, ARTYPE, ARFOP, ARFB>:: -Copy(const ARGenEig<ARFLOAT, ARTYPE, ARFOP, ARFB>& other) -{ - - ARStdEig<ARFLOAT, ARTYPE, ARFOP>::Copy(other); - objB = other.objB; - MultBx = other.MultBx; - -} // Copy. - - -template<class ARFLOAT, class ARTYPE, class ARFOP, class ARFB> -void ARGenEig<ARFLOAT, ARTYPE, ARFOP, ARFB>:: -DefineParameters(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARTYPE[], ARTYPE[]), ARFB* objBp, - void (ARFB::* MultBxp)(ARTYPE[], ARTYPE[]), const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, ARTYPE* residp, - bool ishiftp) - -{ - - // Setting parameters of generalized problems. - - objB = objBp; - MultBx = MultBxp; - - // Setting common eigen-problem parameters. - - ARStdEig<ARFLOAT, ARTYPE, ARFOP>:: - DefineParameters(np, nevp, objOPp, MultOPxp, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // DefineParameters. - - -template<class ARFLOAT, class ARTYPE, class ARFOP, class ARFB> -inline void ARGenEig<ARFLOAT, ARTYPE, ARFOP, ARFB>:: -ChangeMultBx(ARFB* objBp, void (ARFB::* MultBxp)(ARTYPE[], ARTYPE[])) -{ - - objB = objBp; - MultBx = MultBxp; - this->Restart(); - -} // ChangeMultBx. - - -template<class ARFLOAT, class ARTYPE, class ARFOP, class ARFB> -int ARGenEig<ARFLOAT, ARTYPE, ARFOP, ARFB>::FindArnoldiBasis() -{ - - if (!this->BasisOK) this->Restart(); - - // Changing to auto shift mode. - - if (!this->AutoShift) { - ArpackError::Set(ArpackError::CHANGING_AUTOSHIFT, "FindArnoldiBasis"); - this->AutoShift=true; - } - - // ARPACK main loop. - - while (!this->BasisOK) { - - // Calling Aupp. - - try { this->TakeStep(); } - catch (ArpackError) { - ArpackError(ArpackError::CANNOT_FIND_BASIS, "FindArnoldiBasis"); - return 0; - } - - switch (this->ido) { - case -1: - - // Performing y <- OP*B*x for the first time when mode != 2. - - if (this->mode != 2) { - this->ipntr[3] = this->ipntr[2]+this->n; // not a clever idea, but... - (this->objB->*MultBx)(&this->workd[this->ipntr[1]],&this->workd[this->ipntr[3]]); - } - - case 1: - - // Performing y <- OP*w. - - if (this->mode == 2) { // w = x if mode = 2. - (this->objOP->*(this->MultOPx))(&this->workd[this->ipntr[1]],&this->workd[this->ipntr[2]]); - } - else { // w = B*x otherwise. - (this->objOP->*(this->MultOPx))(&this->workd[this->ipntr[3]],&this->workd[this->ipntr[2]]); - } - break; - - case 2: - - // Performing y <- B*x. - - (this->objB->*MultBx)(&this->workd[this->ipntr[1]],&this->workd[this->ipntr[2]]); - - } - } - return this->nconv; - -} // FindArnoldiBasis. - - -template<class ARFLOAT, class ARTYPE, class ARFOP, class ARFB> -ARGenEig<ARFLOAT, ARTYPE, ARFOP, ARFB>& ARGenEig<ARFLOAT, ARTYPE, ARFOP, ARFB>:: -operator=(const ARGenEig<ARFLOAT, ARTYPE, ARFOP, ARFB>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARGEIG_H - diff --git a/src/external/arpack++/include/argnsym.h b/src/external/arpack++/include/argnsym.h deleted file mode 100644 index 9590cb7b..00000000 --- a/src/external/arpack++/include/argnsym.h +++ /dev/null @@ -1,362 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARGNSym.h. - Arpack++ class ARNonSymGenEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARGNSYM_H -#define ARGNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "blas1c.h" -#include "lapackc.h" -#include "arsnsym.h" -#include "argeig.h" -#include "arrgnsym.h" - -template<class ARFLOAT, class ARFOP, class ARFB> -class ARNonSymGenEig: - virtual public ARGenEig<ARFLOAT, ARFLOAT, ARFOP, ARFB>, - virtual public ARNonSymStdEig<ARFLOAT, ARFOP>, - virtual public ARrcNonSymGenEig<ARFLOAT> { - - public: - - // a) Notation. - - typedef void (ARFB::* TypeBx)(ARFLOAT[], ARFLOAT[]); - - - protected: - - // b) Protected variables: - - ARFB *objA; // Object that has MultAx as a member function. - TypeBx MultAx; // Function that evaluates the product A*x. - - - // c) Protected functions: - - void RecoverEigenvalues(); - // Uses Rayleigh quotient to recover eigenvalues of the original - // problem when shift is complex. - - virtual void Copy(const ARNonSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // d) Public functions: - - // d.1) Functions that allow changes in problem parameters. - - virtual void SetShiftInvertMode(ARFLOAT sigmaRp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[],ARFLOAT[])); - // Turns the problem to real shift-and-invert mode with sigmaRp as shift. - - virtual void SetComplexShiftMode(char partp, ARFLOAT sigmaRp, - ARFLOAT sigmaIp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[],ARFLOAT[]), - ARFB* objAp, - void (ARFB::* MultAxp)(ARFLOAT[],ARFLOAT[])); - // Turns the problem to complex shift-and-invert mode with shift - // defined by sigmaRp and sigmaIp. MultAx is used to obtain eigenvalues. - - - // d.2) Functions that perform all calculations in one step. - - virtual int FindEigenvalues(); - // Determines nev approximated eigenvalues of the given eigen-problem. - - virtual int FindEigenvectors(bool schurp = false); - // Determines nev approximated eigenvectors of the given eigen-problem - // Optionally also determines nev Schur vectors that span the desired - // invariant subspace. - - virtual int FindSchurVectors(); - // Determines nev Schur vectors that span the desired invariant subspace. - // Redefined in ARSymEig. - - - // d.3) Constructors and destructor. - - ARNonSymGenEig() { this->part = 'R'; } - // Short constructor (Does nothing but calling base classes constructors). - - ARNonSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARNonSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigmap, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, ARFLOAT* residp = NULL, - bool ishiftp = true); - // Long constructor (real shift and invert mode). - - ARNonSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), ARFB* objAp, - void (ARFB::* MultAxp)(ARFLOAT[], ARFLOAT[]), ARFB* objBp, - void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), char partp, - ARFLOAT sigmaRp, ARFLOAT sigmaIp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (complex shift and invert mode). - - ARNonSymGenEig(const ARNonSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARNonSymGenEig() { } - // Destructor. - - // e) Operators. - - ARNonSymGenEig& operator=(const ARNonSymGenEig& other); - // Assignment operator. - -}; // class ARNonSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARNonSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline void ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>:: -Copy(const ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>& other) -{ - - ARGenEig<ARFLOAT, ARFLOAT, ARFOP, ARFB>::Copy(other); - objA = other.objA; - MultAx = other.MultAx; - this->part = other.part; - -} // Copy. - - -template<class ARFLOAT, class ARFOP, class ARFB> -void ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>::RecoverEigenvalues() -{ - - int j, ColJ, ColJp1; - ARFLOAT numr, numi, denr, deni; - ARFLOAT* Ax; - - Ax = new ARFLOAT[this->n]; - - for (j=0; j<this->nconv; j++) { - - ColJ = j*this->n; - ColJp1 = ColJ+this->n; - - if (this->EigValI[j] == (ARFLOAT)0.0) { - - // Eigenvalue is real. Computing EigVal = x'(Ax)/x'(Mx). - - (this->objB->*MultAx)(&this->EigVec[ColJ], Ax); - numr = dot(this->n, &this->EigVec[ColJ], 1, Ax, 1); - (this->objB->*(this->MultBx))(&this->EigVec[ColJ], Ax); - denr = dot(this->n, &this->EigVec[ColJ], 1, Ax, 1); - this->EigValR[j] = numr / denr; - - } - else { - - // Eigenvalue is complex. - - // Computing x'(Ax). - - (this->objB->*MultAx)(&this->EigVec[ColJ], Ax); - numr = dot(this->n, &this->EigVec[ColJ], 1, Ax, 1); - numi = dot(this->n, &this->EigVec[ColJp1], 1, Ax, 1); - (this->objB->*MultAx)(&this->EigVec[ColJp1], Ax); - numr = numr + dot(this->n, &this->EigVec[ColJp1], 1, Ax, 1); - numi = -numi + dot(this->n, &this->EigVec[ColJ], 1, Ax, 1); - - // Computing x'(Mx). - - (this->objB->*(this->MultBx))(&this->EigVec[ColJ], Ax); - denr = dot(this->n, &this->EigVec[ColJ], 1, Ax, 1); - deni = dot(this->n, &this->EigVec[ColJp1], 1, Ax, 1); - (this->objB->*(this->MultBx))(&this->EigVec[ColJp1], Ax); - denr = denr + dot(this->n, &this->EigVec[ColJp1], 1, Ax, 1); - deni = -deni + dot(this->n, &this->EigVec[ColJ], 1, Ax, 1); - - // Computing the first eigenvalue of the conjugate pair. - - this->EigValR[j] = (numr*denr+numi*deni) / lapy2(denr, deni); - this->EigValI[j] = (numi*denr-numr*deni) / lapy2(denr, deni); - - // Getting the second eigenvalue of the conjugate pair by taking - // the conjugate of the first. - - this->EigValR[j+1] = this->EigValR[j]; - this->EigValI[j+1] = -this->EigValI[j]; - j++; - - } - - } - - delete[] Ax; - -} // RecoverEigenvalues. - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline void ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>:: -SetShiftInvertMode(ARFLOAT sigmaRp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[])) -{ - - this->part = 'R'; - this->objOP = objOPp; - this->MultOPx = MultOPxp; - this->ChangeShift(sigmaRp); - -} // SetShiftInvertMode. - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline void ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>:: -SetComplexShiftMode(char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp, - ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objAp, void (ARFB::* MultAxp)(ARFLOAT[], ARFLOAT[])) -{ - - this->objOP = objOPp; - this->MultOPx = MultOPxp; - objA = objAp; - MultAx = MultAxp; - this->part = this->CheckPart(partp); - this->ChangeShift(sigmaRp, sigmaIp); - -} // SetComplexShiftMode. - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline int ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>::FindEigenvalues() -{ - - this->nconv = ARStdEig<ARFLOAT, ARFLOAT, ARFOP>::FindEigenvalues(); - if (this->sigmaI != 0.0) RecoverEigenvalues(); - return this->nconv; - -} // FindEigenvalues. - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline int ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>::FindEigenvectors(bool schurp) -{ - - this->nconv = ARStdEig<ARFLOAT, ARFLOAT, ARFOP>::FindEigenvectors(schurp); - if (this->sigmaI != 0.0) RecoverEigenvalues(); - return this->nconv; - -} // FindEigenvectors. - - -template<class ARFLOAT, class ARFOP, class ARFB> -int ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>::FindSchurVectors() -{ - - this->nconv = ARStdEig<ARFLOAT, ARFLOAT, ARFOP>::FindSchurVectors(); - if (this->sigmaI != 0.0) RecoverEigenvalues(); - return this->nconv; - -} // FindSchurVectors. - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>:: -ARNonSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - const std::string& whichp, int ncvp, ARFLOAT tolp, int maxitp, - ARFLOAT* residp, bool ishiftp) - -{ - - this->part = 'R'; // Considering mode = 3 in ChangeShift. - this->NoShift(); - this->DefineParameters(np, nevp, objOPp, MultOPxp, objBp, MultBxp, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>:: -ARNonSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - SetShiftInvertMode(sigmap, objOPp, MultOPxp); - this->DefineParameters(np, nevp, objOPp, MultOPxp, objBp, MultBxp, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - - -} // Long constructor (real shift and invert mode). - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>:: -ARNonSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objAp, void (ARFB::* MultAxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp, - const std::string& whichp, int ncvp, ARFLOAT tolp, int maxitp, - ARFLOAT* residp, bool ishiftp) - -{ - - SetComplexShiftMode(partp, sigmaRp, sigmaIp, objOPp, - MultOPxp, objAp, MultAxp); - this->DefineParameters(np, nevp, objOPp, MultOPxp, objBp, MultBxp, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT, class ARFOP, class ARFB> -ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>& ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>:: -operator=(const ARNonSymGenEig<ARFLOAT, ARFOP, ARFB>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARGNSYM_H - diff --git a/src/external/arpack++/include/argsym.h b/src/external/arpack++/include/argsym.h deleted file mode 100644 index 8191ba0a..00000000 --- a/src/external/arpack++/include/argsym.h +++ /dev/null @@ -1,326 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARGSym.h. - Arpack++ class ARSymGenEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARGSYM_H -#define ARGSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arssym.h" -#include "arrgsym.h" -#include "argeig.h" - -template<class ARFLOAT, class ARFOP, class ARFB> -class ARSymGenEig: - virtual public ARGenEig<ARFLOAT, ARFLOAT, ARFOP, ARFB>, - virtual public ARSymStdEig<ARFLOAT, ARFOP>, - virtual public ARrcSymGenEig<ARFLOAT> { - - public: - - // a) Notation. - - typedef void (ARFB::* TypeBx)(ARFLOAT[], ARFLOAT[]); - - - protected: - - // b) Protected variables: - - ARFB *objA; // Object that has MultAx as a member function. - TypeBx MultAx; // Function that evaluates the product A*x. - - // c) Protected functions: - - virtual void Copy(const ARSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // d) Public functions: - - // d.1) Functions that allow changes in problem parameters. - - void SetShiftInvertMode(ARFLOAT sigmap, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[])); - // Turns problem to shift and invert mode with shift defined by sigmap. - - void SetBucklingMode(ARFLOAT sigmap, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[])); - // Turns problem to buckling mode with shift defined by sigmap. - - void SetCayleyMode(ARFLOAT sigmap, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objAp, void (ARFB::* MultAxp)(ARFLOAT[], ARFLOAT[])); - // Turns problem to Cayley mode with shift defined by sigmap. - - - // d.2) Functions that perform all calculations in one step. - - int FindArnoldiBasis(); - // Determines the Arnoldi basis related to the given problem. - - - // d.3) Constructors and destructor. - - ARSymGenEig() { this->InvertMode = 'S'; } - // Short constructor that does almost nothing. - - ARSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), ARFB* objBp, - void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARSymGenEig(char invertmodep, int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigmap, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, ARFLOAT* residp = NULL, - bool ishiftp = true); - // Long constructor (shift-and-invert and buckling mode). - - ARSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), ARFB* objAp, - void (ARFB::* MultAxp)(ARFLOAT[], ARFLOAT[]), ARFB* objBp, - void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), ARFLOAT sigmap, - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (cayley mode). - - ARSymGenEig(const ARSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARSymGenEig() { } - // Destructor. - - // e) Operators. - - ARSymGenEig& operator=(const ARSymGenEig& other); - // Assignment operator. - -}; // class ARSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline void ARSymGenEig<ARFLOAT, ARFOP, ARFB>:: -Copy(const ARSymGenEig<ARFLOAT, ARFOP, ARFB>& other) -{ - - ARGenEig<ARFLOAT, ARFLOAT, ARFOP, ARFB>::Copy(other); - objA = other.objA; - MultAx = other.MultAx; - this->InvertMode = other.InvertMode; - -} // Copy. - - -template<class ARFLOAT, class ARFOP, class ARFB> -void ARSymGenEig<ARFLOAT, ARFOP, ARFB>:: -SetShiftInvertMode(ARFLOAT sigmap, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[])) -{ - - this->InvertMode = 'S'; - this->objOP = objOPp; - this->MultOPx = MultOPxp; - this->ChangeShift(sigmap); - -} // SetShiftInvertMode. - - -template<class ARFLOAT, class ARFOP, class ARFB> -void ARSymGenEig<ARFLOAT, ARFOP, ARFB>:: -SetBucklingMode(ARFLOAT sigmap, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[])) - -{ - - this->InvertMode = 'B'; - this->objOP = objOPp; - this->MultOPx = MultOPxp; - this->ChangeShift(sigmap); - -} // SetBucklingMode. - - -template<class ARFLOAT, class ARFOP, class ARFB> -void ARSymGenEig<ARFLOAT, ARFOP, ARFB>:: -SetCayleyMode(ARFLOAT sigmap, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), ARFB* objAp, - void (ARFB::* MultAxp)(ARFLOAT[], ARFLOAT[])) - -{ - - this->InvertMode = 'C'; - this->objOP = objOPp; - this->MultOPx = MultOPxp; - objA = objAp; - MultAx = MultAxp; - this->ChangeShift(sigmap); - -} // SetCayleyMode. - - -template<class ARFLOAT, class ARFOP, class ARFB> -int ARSymGenEig<ARFLOAT, ARFOP, ARFB>::FindArnoldiBasis() -{ - - ARFLOAT* temp; - - if (this->mode != 5) { // Using base function if not in Cayley mode. - return ARGenEig<ARFLOAT, ARFLOAT, ARFOP, ARFB>::FindArnoldiBasis(); - } - else { - - temp = new ARFLOAT[this->n+1]; - - if (!this->BasisOK) this->Restart(); - - // Changing to auto shift mode. - - if (!this->AutoShift) { - ArpackError::Set(ArpackError::CHANGING_AUTOSHIFT, "FindArnoldiBasis"); - this->AutoShift=true; - } - - // ARPACK main loop. - - while (!this->BasisOK) { - - // Calling Aupp. - - try { this->TakeStep(); } - catch (ArpackError) { - ArpackError(ArpackError::CANNOT_FIND_BASIS, "FindArnoldiBasis"); - delete[] temp; - return 0; - } - - switch (this->ido) { - case -1: - - // Performing y <- B*x for the first time. - - this->ipntr[3] = this->ipntr[2]+this->n; // not a clever idea, but... - (this->objB->*(this->MultBx))(&this->workd[this->ipntr[1]],&this->workd[this->ipntr[3]]); - - case 1: - - // Performing y <- OP*(A+sigma*B)*x, B*x is already available. - - (this->objB->*MultAx)(&this->workd[this->ipntr[1]], temp); - axpy(this->n, this->sigmaR, &this->workd[this->ipntr[3]], 1, temp, 1); - (this->objOP->*(this->MultOPx))(temp, &this->workd[this->ipntr[2]]); - break; - - case 2: - - // Performing y <- B*x. - - (this->objB->*(this->MultBx))(&this->workd[this->ipntr[1]],&this->workd[this->ipntr[2]]); - - } - } - - delete[] temp; - - return this->nconv; - } - -} // FindArnoldiBasis. - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline ARSymGenEig<ARFLOAT, ARFOP, ARFB>:: -ARSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - const std::string& whichp, int ncvp, ARFLOAT tolp, int maxitp, - ARFLOAT* residp, bool ishiftp) - -{ - - this->InvertMode = 'S'; - this->NoShift(); - this->DefineParameters(np, nevp, objOPp, MultOPxp, objBp, MultBxp, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline ARSymGenEig<ARFLOAT, ARFOP, ARFB>:: -ARSymGenEig(char InvertModep, int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->InvertMode = this->CheckInvertMode(InvertModep); // InvertMode = 'S' or 'B'. - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, objOPp, MultOPxp, objBp, MultBxp, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift-and-invert and buckling mode). - - -template<class ARFLOAT, class ARFOP, class ARFB> -inline ARSymGenEig<ARFLOAT, ARFOP, ARFB>:: -ARSymGenEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objAp, void (ARFB::* MultAxp)(ARFLOAT[], ARFLOAT[]), - ARFB* objBp, void (ARFB::* MultBxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - SetCayleyMode(sigmap, objOPp, this->MultOPx, objAp, MultAxp); - this->DefineParameters(np, nevp, objOPp, MultOPxp, objBp, MultBxp, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (cayley mode). - - -template<class ARFLOAT, class ARFOP, class ARFB> -ARSymGenEig<ARFLOAT, ARFOP, ARFB>& ARSymGenEig<ARFLOAT, ARFOP, ARFB>:: -operator=(const ARSymGenEig<ARFLOAT, ARFOP, ARFB>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARGSYM_H - diff --git a/src/external/arpack++/include/arhbmat.h b/src/external/arpack++/include/arhbmat.h deleted file mode 100644 index 97c4db40..00000000 --- a/src/external/arpack++/include/arhbmat.h +++ /dev/null @@ -1,407 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARHBMat.h - Matrix template that generates a matrix in CSC format - from a Harwell-Boing matrix file. - - ARPACK authors: - Richard Lehoucq - Kristyn Maschhoff - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#ifndef ARHBMAT_H -#define ARHBMAT_H - -#include <cstddef> -#include <fstream> -#include <cstdlib> -#include <cstring> -#include <string> -#include "arch.h" -#include "arerror.h" - - -template<class ARINT, class ARTYPE> -class ARhbMatrix { - - private: - - std::string datafile; // Filename. - std::string title; // Title. - std::string name; // Name. - std::string type; // Matrix type. - int m; // Number of rows. - int n; // Number of columns. - int nnz; // Number of nonzero variables. - ARINT* irow; // Row indices. - ARINT* pcol; // Column pointers. - ARTYPE* val; // Numerical values of matrix entries. - - void ConvertDouble(char* num); - - bool ReadEntry(std::ifstream& file, int nval, int fval, int& j, double& val); - - bool ReadEntry(std::ifstream& file, int nval, int fval, int& j, float& val); - - bool ReadEntry(std::ifstream& file, int nval, int fval, - int& j, arcomplex<double>& val); - - bool ReadEntry(std::ifstream& file, int nval, int fval, - int& j, arcomplex<float>& val); - - void ReadFormat(std::ifstream& file, int& n, int& fmt); - - public: - - bool IsDefined() { return (m!=0); } - - bool IsReal() { return (type.size() > 0 && type[0]=='R'); } - - bool IsComplex() { return (type.size() > 0 && type[0]=='C'); } - - bool IsSymmetric() { return (type.size() > 1 && type[1]=='S'); } - - bool IsUnsymmetric() { return (type.size() > 1 && type[1]=='U'); } - - bool IsHermitian() { return (type.size() > 1 && type[1]=='H'); } - - bool IsSkewSymmetric() { return (type.size() > 1 && type[1]=='Z'); } - - const std::string& Filename() { return datafile; } - - const std::string& Title() { return title; } - - const std::string& Name() { return name; } - - const std::string& Type() { return type; } - - int NRows() { return m; } - - int NCols() { return n; } - - int NonZeros() { return nnz; } - - ARINT* RowInd() { return irow; } - - ARINT* ColPtr() { return pcol; } - - ARTYPE* Entries() { return val; } - - void Define(const std::string& filename); - // Function that reads the matrix file. - - ARhbMatrix(); - // Short constructor. - - ARhbMatrix(const std::string& filename) { Define(filename); } - // Long constructor. - - ~ARhbMatrix(); - // Destructor. - -}; // Class ARhbMatrix. - - -// ------------------------------------------------------------------------ // -// ARhbMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARINT, class ARTYPE> -inline void ARhbMatrix<ARINT, ARTYPE>::ConvertDouble(char* num) -{ - - char* pd; - - pd = strchr((char*)num,'D'); - if (pd) *pd = 'E'; - pd = strchr((char*)num,'d'); - if (pd) *pd = 'E'; - - -} // ConvertDouble. - - -template<class ARINT, class ARTYPE> -inline bool ARhbMatrix<ARINT, ARTYPE>:: -ReadEntry(std::ifstream& file, int nval, int fval, int& j, double& val) -{ - - char num[81]; - char c; - - if (file.get((char*)num,fval,'\n')) { - ConvertDouble((char*)num); - val = atof((char*)num); - if (!((++j)%nval)) do file.get(c); while (c!='\n'); - return true; - } - else { - return false; - } - -} // ReadEntry (double). - - -template<class ARINT, class ARTYPE> -inline bool ARhbMatrix<ARINT, ARTYPE>:: -ReadEntry(std::ifstream& file, int nval, int fval, int& j, float& val) -{ - - double dval; - bool ret; - - ret = ReadEntry(file, nval, fval, j, dval); - val = (float)dval; - return ret; - -} // ReadEntry (float). - - -template<class ARINT, class ARTYPE> -inline bool ARhbMatrix<ARINT, ARTYPE>:: -ReadEntry(std::ifstream& file, int nval, int fval, - int& j, arcomplex<double>& val) -{ - - char num[81], img[81]; - char c; - - if (file.get((char*)num,fval,'\n')) { - ConvertDouble((char*)num); - if (!((++j)%nval)) do file.get(c); while (c!='\n'); - if (file.get((char*)img,fval,'\n')) { - ConvertDouble((char*)img); - if (!((++j)%nval)) do file.get(c); while (c!='\n'); - val = arcomplex<double>(atof((char*)num), atof((char*)img)); - return true; - } - else { - return false; - } - } - else { - return false; - } - -} // ReadEntry (arcomplex<double>). - - -template<class ARINT, class ARTYPE> -inline bool ARhbMatrix<ARINT, ARTYPE>:: -ReadEntry(std::ifstream& file, int nval, int fval, - int& j, arcomplex<float>& val) -{ - - // I hope one day c++ will have a standard complex - // class, so functions like this can be suppressed. - - char num[81], img[81]; - char c; - - if (file.get((char*)num,fval,'\n')) { - ConvertDouble((char*)num); - if (!((++j)%nval)) do file.get(c); while (c!='\n'); - if (file.get((char*)img,fval,'\n')) { - ConvertDouble((char*)img); - if (!((++j)%nval)) do file.get(c); while (c!='\n'); - val = arcomplex<float>(atof((char*)num), atof((char*)img)); - return true; - } - else { - return false; - } - } - else { - return false; - } - -} // ReadEntry (arcomplex<float>). - - -template<class ARINT, class ARTYPE> -void ARhbMatrix<ARINT, ARTYPE>::ReadFormat(std::ifstream& file, int& n, int& fmt) -{ - - char c; - - do file.get(c); while ((c != '(') && (c!='\n')); - file >> n; - file.get(c); - while ((c!='I') && (c!='i') && (c!='E') && (c!='e') && - (c!='D') && (c!='d') && (c!='\n')) { - do file.get(c); while ((c != ',') && (c!='\n')); - file >> n; - file.get(c); - } - if ((c==')')||(c=='\n')) { // Reading error! - fmt = 0; - } - else { - file >> fmt; - } - -} // ReadFormat. - - -template<class ARINT, class ARTYPE> -void ARhbMatrix<ARINT, ARTYPE>::Define(const std::string& filename) -{ - - // Declaring variables. - - int i, j; - int lintot, linptr, linind, linval, linrhs; - int npcol, fpcol, nirow, firow, nval, fval; - char c; - char num[81]; - char titlechar[73]; - char namechar[9]; - char typechar[4]; - ARTYPE value; - - // Opening file. - - datafile = filename; - std::ifstream file(datafile.c_str()); - - if (!file) { - throw ArpackError(ArpackError::CANNOT_OPEN_FILE, "ARhbMatrix"); - } - - // Reading the first line. - - file.get((char*)titlechar,73,'\n'); - title = std::string(titlechar); - file.get((char*)namechar,9,'\n'); - name = std::string(namechar); - do file.get(c); while (c!='\n'); - - // Reading the second line. - - file >> lintot >> linptr >> linind >> linval >> linrhs; - do file.get(c); while (c!='\n'); - - if ((linptr < 1) || (linind < 1)) { - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARhbMatrix"); - } - - // Reading the third line. - - file.get((char*)typechar,4,'\n'); - type = std::string(typechar); - file >> m >> n >> nnz; - do file.get(c); while (c!='\n'); - - if ( (type.size()<3) || ((type[0] != 'R') && (type[0] != 'C')) || (type[2] != 'A')) { - throw ArpackError(ArpackError::WRONG_MATRIX_TYPE, "ARhbMatrix"); - } - else if ((m < 1) || (n < 1) || (nnz < 1)) { - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARhbMatrix"); - } - - // Reading the fourth line. - - ReadFormat(file, npcol, fpcol); - ReadFormat(file, nirow, firow); - ReadFormat(file, nval, fval); - do file.get(c); while (c!='\n'); - if ((fpcol<1) || (firow<1) || (fval<1)) { - throw ArpackError(ArpackError::WRONG_DATA_TYPE, "ARhbMatrix"); - } - - // Skipping the fifth line. - - if (linrhs) { - do file.get(c); while (c!='\n'); - ArpackError(ArpackError::RHS_IGNORED, "ARhbMatrix"); - } - - // Reading column pointers. - - pcol = new ARINT[n+1]; - fpcol++; - i = 0; - while ((i <= n) && (file.get((char*)num,fpcol,'\n'))) { - pcol[i++] = atoi((char*)num)-1; - if (!(i%npcol)) do file.get(c); while (c!='\n'); - } - if (i%npcol) do file.get(c); while (c!='\n'); - - if (i <= n) { - throw ArpackError(ArpackError::UNEXPECTED_EOF, "ARhbMatrix"); - } - - // Reading row indices. - - irow = new ARINT[nnz]; - firow++; - i = 0; - while ((i < nnz) && (file.get((char*)num,firow,'\n'))) { - irow[i++] = atoi((char*)num)-1; - if (!(i%nirow)) do file.get(c); while (c!='\n'); - } - if (i%nirow) do file.get(c); while (c!='\n'); - - if (i < nnz) { - throw ArpackError(ArpackError::UNEXPECTED_EOF, "ARhbMatrix"); - } - - // Reading matrix elements. - - fval++; - val = new ARTYPE[nnz]; - i = 0; - j = 0; - while ((i < nnz) && (ReadEntry(file, nval, fval, j, value))) { - val[i++] = value; - } - if (j%nval) do file.get(c); while (c!='\n'); - - if (i < nnz) { - throw ArpackError(ArpackError::UNEXPECTED_EOF, "ARhbMatrix"); - } - - // Closing file and reporting success. - - file.close(); - -} // Define. - - -template<class ARINT, class ARTYPE> -ARhbMatrix<ARINT, ARTYPE>::ARhbMatrix() -{ - - m = n = nnz = 0; - title[0]= '\0'; - name[0] = '\0'; - type[0] = '\0'; - pcol = NULL; - irow = NULL; - val = NULL; - -} // Short constructor. - - -template<class ARINT, class ARTYPE> -ARhbMatrix<ARINT, ARTYPE>::~ARhbMatrix() -{ - - if (irow != NULL) delete[] irow; - if (pcol != NULL) delete[] pcol; - if (val != NULL) delete[] val; - -} // Destructor. - - -#endif // ARHBMAT_H - diff --git a/src/external/arpack++/include/arlcomp.h b/src/external/arpack++/include/arlcomp.h deleted file mode 100644 index 8b9b5fbc..00000000 --- a/src/external/arpack++/include/arlcomp.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLComp.h. - ALTERED copy of dcomplex.h and scomplex.h (from SuperLU package). - Structure complex was renamed to lscomplex. - Structure doublecomplex was renamed to ldcomplex. -*/ - -/* - * -- SuperLU routine (version 2.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * November 15, 1997 - * - * </pre> - */ -#ifndef __SUPERLU_DCOMPLEX /* allow multiple inclusions */ -#define __SUPERLU_DCOMPLEX - -/* - * This header file is to be included in source files z*.c - */ -#ifndef DCOMPLEX_INCLUDE -#define DCOMPLEX_INCLUDE - -typedef struct { double r, i; } ldcomplex; - - -/* Macro definitions */ - -/*! \brief Complex Addition c = a + b */ -#define z_add(c, a, b) { (c)->r = (a)->r + (b)->r; \ - (c)->i = (a)->i + (b)->i; } - -/*! \brief Complex Subtraction c = a - b */ -#define z_sub(c, a, b) { (c)->r = (a)->r - (b)->r; \ - (c)->i = (a)->i - (b)->i; } - -/*! \brief Complex-Double Multiplication */ -#define zd_mult(c, a, b) { (c)->r = (a)->r * (b); \ - (c)->i = (a)->i * (b); } - -/*! \brief Complex-Complex Multiplication */ -#define zz_mult(c, a, b) { \ - double cr, ci; \ - cr = (a)->r * (b)->r - (a)->i * (b)->i; \ - ci = (a)->i * (b)->r + (a)->r * (b)->i; \ - (c)->r = cr; \ - (c)->i = ci; \ - } - -#define zz_conj(a, b) { \ - (a)->r = (b)->r; \ - (a)->i = -((b)->i); \ - } - -/*! \brief Complex equality testing */ -#define z_eq(a, b) ( (a)->r == (b)->r && (a)->i == (b)->i ) - - -#ifdef __cplusplus -extern "C" { -#endif - -/* Prototypes for functions in dcomplex.c */ -void z_div(ldcomplex *, ldcomplex *, ldcomplex *); -double z_abs(ldcomplex *); /* exact */ -double z_abs1(ldcomplex *); /* approximate */ -void z_exp(ldcomplex *, ldcomplex *); -void d_cnjg(ldcomplex *r, ldcomplex *z); -double d_imag(ldcomplex *); -ldcomplex z_sgn(ldcomplex *); -ldcomplex z_sqrt(ldcomplex *); - - -#ifdef __cplusplus - } -#endif - -#endif - -#endif /* __SUPERLU_DCOMPLEX */ - - -#ifndef __SUPERLU_SCOMPLEX /* allow multiple inclusions */ -#define __SUPERLU_SCOMPLEX - -/* - * This header file is to be included in source files c*.c - */ -#ifndef SCOMPLEX_INCLUDE -#define SCOMPLEX_INCLUDE - -typedef struct { float r, i; } lscomplex; - - -/* Macro definitions */ - -/*! \brief Complex Addition c = a + b */ -#define c_add(c, a, b) { (c)->r = (a)->r + (b)->r; \ - (c)->i = (a)->i + (b)->i; } - -/*! \brief Complex Subtraction c = a - b */ -#define c_sub(c, a, b) { (c)->r = (a)->r - (b)->r; \ - (c)->i = (a)->i - (b)->i; } - -/*! \brief Complex-Double Multiplication */ -#define cs_mult(c, a, b) { (c)->r = (a)->r * (b); \ - (c)->i = (a)->i * (b); } - -/*! \brief Complex-Complex Multiplication */ -#define cc_mult(c, a, b) { \ - float cr, ci; \ - cr = (a)->r * (b)->r - (a)->i * (b)->i; \ - ci = (a)->i * (b)->r + (a)->r * (b)->i; \ - (c)->r = cr; \ - (c)->i = ci; \ - } - -#define cc_conj(a, b) { \ - (a)->r = (b)->r; \ - (a)->i = -((b)->i); \ - } - -/*! \brief Complex equality testing */ -#define c_eq(a, b) ( (a)->r == (b)->r && (a)->i == (b)->i ) - - -#ifdef __cplusplus -extern "C" { -#endif - -/* Prototypes for functions in scomplex.c */ -void c_div(lscomplex *, lscomplex *, lscomplex *); -double c_abs(lscomplex *); /* exact */ -double c_abs1(lscomplex *); /* approximate */ -void c_exp(lscomplex *, lscomplex *); -void r_cnjg(lscomplex *, lscomplex *); -double r_imag(lscomplex *); -lscomplex c_sgn(lscomplex *); -lscomplex c_sqrt(lscomplex *); - - -#ifdef __cplusplus - } -#endif - -#endif - -#endif /* __SUPERLU_SCOMPLEX */ - diff --git a/src/external/arpack++/include/arlgcomp.h b/src/external/arpack++/include/arlgcomp.h deleted file mode 100644 index b4692164..00000000 --- a/src/external/arpack++/include/arlgcomp.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLGComp.h. - Arpack++ class ARluCompGenEig definition - (superlu version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARLGCOMP_H -#define ARLGCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arlnsmat.h" -#include "arlnspen.h" -#include "arrseig.h" -#include "argcomp.h" - - -template<class ARFLOAT> -class ARluCompGenEig: - public virtual - ARCompGenEig<ARFLOAT, ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT >, - ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT > > { - - private: - - // a) Data structure used to store matrices. - - ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT > Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluCompGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(arcomplex<ARFLOAT> sigmap); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(arcomplex<ARFLOAT> sigmap); - - // c.2) Constructors and destructor. - - ARluCompGenEig() { } - // Short constructor. - - ARluCompGenEig(int nevp, ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluCompGenEig(int nevp, ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluCompGenEig(const ARluCompGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluCompGenEig() { } - - // d) Operators. - - ARluCompGenEig& operator=(const ARluCompGenEig& other); - // Assignment operator. - -}; // class ARluCompGenEig. - - -// ------------------------------------------------------------------------ // -// ARluCompGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -Copy(const ARluCompGenEig<ARFLOAT>& other) -{ - - ARCompGenEig<ARFLOAT, ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT >, - ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - if (this->mode > 2) this->objOP->FactorAsB(this->sigmaR); - -} // Copy. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>::ChangeShift(arcomplex<ARFLOAT> sigmap) -{ - - this->objOP->FactorAsB(sigmap); - ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> >::ChangeShift(sigmap); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetRegularMode(&Pencil, - &ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -SetShiftInvertMode(arcomplex<ARFLOAT> sigmap) -{ - - ARCompGenEig<ARFLOAT, ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>, - ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, - &ARluNonSymPencil<arcomplex<ARFLOAT>,ARFLOAT>::MultInvAsBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluCompGenEig<ARFLOAT>:: -ARluCompGenEig(int nevp, ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, - arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvBAv, - &Pencil, - &ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultBv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluCompGenEig<ARFLOAT>:: -ARluCompGenEig(int nevp, ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvAsBv, - &Pencil, - &ARluNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultBv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - SetShiftInvertMode(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluCompGenEig<ARFLOAT>& ARluCompGenEig<ARFLOAT>:: -operator=(const ARluCompGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLGCOMP_H diff --git a/src/external/arpack++/include/arlgnsym.h b/src/external/arpack++/include/arlgnsym.h deleted file mode 100644 index ea9b53e2..00000000 --- a/src/external/arpack++/include/arlgnsym.h +++ /dev/null @@ -1,252 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLGNSym.h. - Arpack++ class ARluNonSymGenEig definition - (SuperLU version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARLGNSYM_H -#define ARLGNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arlnsmat.h" -#include "arlnspen.h" -#include "argnsym.h" - - -template<class ARFLOAT> -class ARluNonSymGenEig: - public virtual ARNonSymGenEig<ARFLOAT, ARluNonSymPencil<ARFLOAT, ARFLOAT>, - ARluNonSymPencil<ARFLOAT, ARFLOAT> > { - - protected: - - // a) Data structure used to store matrices. - - ARluNonSymPencil<ARFLOAT, ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluNonSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp = 0.0); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetComplexShiftMode(char partp,ARFLOAT sigmaRp,ARFLOAT sigmaIp); - - // c.2) Constructors and destructor. - - ARluNonSymGenEig() { } - // Short constructor. - - ARluNonSymGenEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARluNonSymMatrix<ARFLOAT, ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluNonSymGenEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARluNonSymMatrix<ARFLOAT, ARFLOAT>& B, ARFLOAT sigma, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (real shift and invert mode). - - ARluNonSymGenEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARluNonSymMatrix<ARFLOAT, ARFLOAT>& B, char partp, - ARFLOAT sigmaRp, ARFLOAT sigmaIp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (complex shift and invert mode). - - ARluNonSymGenEig(const ARluNonSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluNonSymGenEig& operator=(const ARluNonSymGenEig& other); - // Assignment operator. - -}; // class ARluNonSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluNonSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -Copy(const ARluNonSymGenEig<ARFLOAT>& other) -{ - - ARNonSymGenEig<ARFLOAT, ARluNonSymPencil<ARFLOAT, ARFLOAT>, - ARluNonSymPencil<ARFLOAT, ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - if (this->mode > 2) { - if (this->sigmaI == 0.0) { - this->objOP->FactorAsB(this->sigmaR); - } - else { - this->objOP->FactorAsB(this->sigmaR, this->sigmaI, this->part); - } - } - -} // Copy. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - if (sigmaIp == 0.0) { - this->objOP->FactorAsB(sigmaRp); - } - else { - this->objOP->FactorAsB(sigmaRp, sigmaIp, this->part); - } - ARrcNonSymGenEig<ARFLOAT>::ChangeShift(sigmaRp, sigmaIp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARluNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetRegularMode(&Pencil, &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARNonSymGenEig<ARFLOAT, ARluNonSymPencil<ARFLOAT, ARFLOAT>, - ARluNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, - &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -SetComplexShiftMode(char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - ARNonSymGenEig<ARFLOAT, ARluNonSymPencil<ARFLOAT, ARFLOAT>, - ARluNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetComplexShiftMode(partp, sigmaRp, sigmaIp, &Pencil, - &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, - &Pencil, &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultAv); - -} // SetComplexShiftMode. - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARluNonSymMatrix<ARFLOAT, ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultInvBAv, &Pencil, - &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARluNonSymMatrix<ARFLOAT, ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, &Pencil, - &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - SetShiftInvertMode(sigmap); - -} // Long constructor (real shift and invert mode). - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARluNonSymMatrix<ARFLOAT, ARFLOAT>& B, - char partp, ARFLOAT sigmaRp, - ARFLOAT sigmaIp, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, &Pencil, - &ARluNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - SetComplexShiftMode(partp, sigmaRp, sigmaIp); - -} // Long constructor (complex shift and invert mode). - - -template<class ARFLOAT> -ARluNonSymGenEig<ARFLOAT>& ARluNonSymGenEig<ARFLOAT>:: -operator=(const ARluNonSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLGNSYM_H diff --git a/src/external/arpack++/include/arlgsym.h b/src/external/arpack++/include/arlgsym.h deleted file mode 100644 index 00f4a73c..00000000 --- a/src/external/arpack++/include/arlgsym.h +++ /dev/null @@ -1,235 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLGSym.h. - Arpack++ class ARluSymGenEig definition - (SuperLU version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Kristi Maschhoff - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARLGSYM_H -#define ARLGSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arlsmat.h" -#include "arlspen.h" -#include "argsym.h" - - -template<class ARFLOAT> -class ARluSymGenEig: - public virtual ARSymGenEig<ARFLOAT, ARluSymPencil<ARFLOAT>, - ARluSymPencil<ARFLOAT> > { - - private: - - // a) Data structure used to store matrices. - - ARluSymPencil<ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmap); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetBucklingMode(ARFLOAT sigmap); - - virtual void SetCayleyMode(ARFLOAT sigmap); - - // c.2) Constructors and destructor. - - ARluSymGenEig() { } - // Short constructor. - - ARluSymGenEig(int nevp, ARluSymMatrix<ARFLOAT>& A, - ARluSymMatrix<ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymGenEig(char InvertModep, int nevp, ARluSymMatrix<ARFLOAT>& A, - ARluSymMatrix<ARFLOAT>& B, ARFLOAT sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert, buckling and Cayley modes). - - ARluSymGenEig(const ARluSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluSymGenEig& operator=(const ARluSymGenEig& other); - // Assignment operator. - -}; // class ARluSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -Copy(const ARluSymGenEig<ARFLOAT>& other) -{ - - ARSymGenEig<ARFLOAT, ARluSymPencil<ARFLOAT>, - ARluSymPencil<ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - if (this->mode > 2) this->objOP->FactorAsB(this->sigmaR); - -} // Copy. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::ChangeShift(ARFLOAT sigmap) -{ - - this->objOP->FactorAsB(sigmap); - ARrcSymGenEig<ARFLOAT>::ChangeShift(sigmap); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARluSymPencil<ARFLOAT> >:: - SetRegularMode(&Pencil, &ARluSymPencil<ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARluSymPencil<ARFLOAT>, ARluSymPencil<ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, &ARluSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARluSymPencil<ARFLOAT>::MultBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetBucklingMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARluSymPencil<ARFLOAT>, ARluSymPencil<ARFLOAT> >:: - SetBucklingMode(sigmap, &Pencil, &ARluSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARluSymPencil<ARFLOAT>::MultAv); - -} // SetBucklingMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetCayleyMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARluSymPencil<ARFLOAT>, ARluSymPencil<ARFLOAT> >:: - SetCayleyMode(sigmap, &Pencil, &ARluSymPencil<ARFLOAT>::MultInvAsBv, - &Pencil, &ARluSymPencil<ARFLOAT>::MultAv); - this->ChangeMultBx(&Pencil, &ARluSymPencil<ARFLOAT>::MultBv); - -} // SetCayleyMode. - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(int nevp, ARluSymMatrix<ARFLOAT>& A, - ARluSymMatrix<ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->InvertMode = 'S'; - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARluSymPencil<ARFLOAT>::MultInvBAv, &Pencil, - &ARluSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(char InvertModep, int nevp, ARluSymMatrix<ARFLOAT>& A, - ARluSymMatrix<ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARluSymPencil<ARFLOAT>::MultInvAsBv, &Pencil, - &ARluSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - this->InvertMode = this->CheckInvertMode(InvertModep); - switch (this->InvertMode) { - case 'B': // Buckling mode. - this->ChangeMultBx(&Pencil, &ARluSymPencil<ARFLOAT>::MultAv); - case 'S': // Shift and invert mode. - ChangeShift(sigmap); - break; - case 'C': // Cayley mode. - SetCayleyMode(sigmap); - } - -} // Long constructor (shift and invert, buckling and Cayley modes). - - -template<class ARFLOAT> -ARluSymGenEig<ARFLOAT>& ARluSymGenEig<ARFLOAT>:: -operator=(const ARluSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLGSYM_H diff --git a/src/external/arpack++/include/arlnames.h b/src/external/arpack++/include/arlnames.h deleted file mode 100644 index 1664f173..00000000 --- a/src/external/arpack++/include/arlnames.h +++ /dev/null @@ -1,464 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLNames.h. - Unaltered copy of Cnames.h (from SuperLU package). -*/ - -/* - * -- SuperLU routine (version 2.0) -- - * Univ. of California Berkeley, Xerox Palo Alto Research Center, - * and Lawrence Berkeley National Lab. - * November 1, 1997 - * - */ -#ifndef __SUPERLU_CNAMES /* allow multiple inclusions */ -#define __SUPERLU_CNAMES - -/* - * These macros define how C routines will be called. ADD_ assumes that - * they will be called by fortran, which expects C routines to have an - * underscore postfixed to the name (Suns, and the Intel expect this). - * NOCHANGE indicates that fortran will be calling, and that it expects - * the name called by fortran to be identical to that compiled by the C - * (RS6K's do this). UPCASE says it expects C routines called by fortran - * to be in all upcase (CRAY wants this). - */ - -#define ADD_ 0 -#define ADD__ 1 -#define NOCHANGE 2 -#define UPCASE 3 -#define OLD_CRAY 4 -#define C_CALL 5 - -#ifdef UpCase -#define F77_CALL_C UPCASE -#endif - -#ifdef NoChange -#define F77_CALL_C NOCHANGE -#endif - -#ifdef Add_ -#define F77_CALL_C ADD_ -#endif - -#ifdef Add__ -#define F77_CALL_C ADD__ -#endif - -#ifdef _CRAY -#define F77_CALL_C OLD_CRAY -#endif - -/* Default */ -#ifndef F77_CALL_C -#define F77_CALL_C ADD_ -#endif - - -#if (F77_CALL_C == ADD_) -/* - * These defines set up the naming scheme required to have a fortran 77 - * routine call a C routine - * No redefinition necessary to have following Fortran to C interface: - * FORTRAN CALL C DECLARATION - * call dgemm(...) void dgemm_(...) - * - * This is the default. - */ - -#endif - -#if (F77_CALL_C == ADD__) -/* - * These defines set up the naming scheme required to have a fortran 77 - * routine call a C routine - * for following Fortran to C interface: - * FORTRAN CALL C DECLARATION - * call dgemm(...) void dgemm__(...) - */ -/* BLAS */ -#define sswap_ sswap__ -#define saxpy_ saxpy__ -#define sasum_ sasum__ -#define isamax_ isamax__ -#define scopy_ scopy__ -#define sscal_ sscal__ -#define sger_ sger__ -#define snrm2_ snrm2__ -#define ssymv_ ssymv__ -#define sdot_ sdot__ -#define saxpy_ saxpy__ -#define ssyr2_ ssyr2__ -#define srot_ srot__ -#define sgemv_ sgemv__ -#define strsv_ strsv__ -#define sgemm_ sgemm__ -#define strsm_ strsm__ - -#define dswap_ dswap__ -#define daxpy_ daxpy__ -#define dasum_ dasum__ -#define idamax_ idamax__ -#define dcopy_ dcopy__ -#define dscal_ dscal__ -#define dger_ dger__ -#define dnrm2_ dnrm2__ -#define dsymv_ dsymv__ -#define ddot_ ddot__ -#define dsyr2_ dsyr2__ -#define drot_ drot__ -#define dgemv_ dgemv__ -#define dtrsv_ dtrsv__ -#define dgemm_ dgemm__ -#define dtrsm_ dtrsm__ - -#define cswap_ cswap__ -#define caxpy_ caxpy__ -#define scasum_ scasum__ -#define icamax_ icamax__ -#define ccopy_ ccopy__ -#define cscal_ cscal__ -#define scnrm2_ scnrm2__ -#define caxpy_ caxpy__ -#define cgemv_ cgemv__ -#define ctrsv_ ctrsv__ -#define cgemm_ cgemm__ -#define ctrsm_ ctrsm__ -#define cgerc_ cgerc__ -#define chemv_ chemv__ -#define cher2_ cher2__ - -#define zswap_ zswap__ -#define zaxpy_ zaxpy__ -#define dzasum_ dzasum__ -#define izamax_ izamax__ -#define zcopy_ zcopy__ -#define zscal_ zscal__ -#define dznrm2_ dznrm2__ -#define zaxpy_ zaxpy__ -#define zgemv_ zgemv__ -#define ztrsv_ ztrsv__ -#define zgemm_ zgemm__ -#define ztrsm_ ztrsm__ -#define zgerc_ zgerc__ -#define zhemv_ zhemv__ -#define zher2_ zher2__ - -/* LAPACK */ -#define dlamch_ dlamch__ -#define slamch_ slamch__ -#define xerbla_ xerbla__ -#define lsame_ lsame__ -#define dlacon_ dlacon__ -#define slacon_ slacon__ -#define icmax1_ icmax1__ -#define scsum1_ scsum1__ -#define clacon_ clacon__ -#define dzsum1_ dzsum1__ -#define izmax1_ izmax1__ -#define zlacon_ zlacon__ - -/* Fortran interface */ -#define c_bridge_dgssv_ c_bridge_dgssv__ -#define c_fortran_sgssv_ c_fortran_sgssv__ -#define c_fortran_dgssv_ c_fortran_dgssv__ -#define c_fortran_cgssv_ c_fortran_cgssv__ -#define c_fortran_zgssv_ c_fortran_zgssv__ -#endif - -#if (F77_CALL_C == UPCASE) -/* - * These defines set up the naming scheme required to have a fortran 77 - * routine call a C routine - * following Fortran to C interface: - * FORTRAN CALL C DECLARATION - * call dgemm(...) void DGEMM(...) - */ -/* BLAS */ -#define sswap_ SSWAP -#define saxpy_ SAXPY -#define sasum_ SASUM -#define isamax_ ISAMAX -#define scopy_ SCOPY -#define sscal_ SSCAL -#define sger_ SGER -#define snrm2_ SNRM2 -#define ssymv_ SSYMV -#define sdot_ SDOT -#define saxpy_ SAXPY -#define ssyr2_ SSYR2 -#define srot_ SROT -#define sgemv_ SGEMV -#define strsv_ STRSV -#define sgemm_ SGEMM -#define strsm_ STRSM - -#define dswap_ DSWAP -#define daxpy_ DAXPY -#define dasum_ DASUM -#define idamax_ IDAMAX -#define dcopy_ DCOPY -#define dscal_ DSCAL -#define dger_ DGER -#define dnrm2_ DNRM2 -#define dsymv_ DSYMV -#define ddot_ DDOT -#define dsyr2_ DSYR2 -#define drot_ DROT -#define dgemv_ DGEMV -#define dtrsv_ DTRSV -#define dgemm_ DGEMM -#define dtrsm_ DTRSM - -#define cswap_ CSWAP -#define caxpy_ CAXPY -#define scasum_ SCASUM -#define icamax_ ICAMAX -#define ccopy_ CCOPY -#define cscal_ CSCAL -#define scnrm2_ SCNRM2 -#define cgemv_ CGEMV -#define ctrsv_ CTRSV -#define cgemm_ CGEMM -#define ctrsm_ CTRSM -#define cgerc_ CGERC -#define chemv_ CHEMV -#define cher2_ CHER2 - -#define zswap_ ZSWAP -#define zaxpy_ ZAXPY -#define dzasum_ DZASUM -#define izamax_ IZAMAX -#define zcopy_ ZCOPY -#define zscal_ ZSCAL -#define dznrm2_ DZNRM2 -#define zgemv_ ZGEMV -#define ztrsv_ ZTRSV -#define zgemm_ ZGEMM -#define ztrsm_ ZTRSM -#define zgerc_ ZGERC -#define zhemv_ ZHEMV -#define zher2_ ZHER2 - -/* LAPACK */ -#define dlamch_ DLAMCH -#define slamch_ SLAMCH -#define xerbla_ XERBLA -#define lsame_ LSAME -#define dlacon_ DLACON -#define slacon_ SLACON -#define icmax1_ ICMAX1 -#define scsum1_ SCSUM1 -#define clacon_ CLACON -#define dzsum1_ DZSUM1 -#define izmax1_ IZMAX1 -#define zlacon_ ZLACON - -/* Fortran interface */ -#define c_bridge_dgssv_ C_BRIDGE_DGSSV -#define c_fortran_sgssv_ C_FORTRAN_SGSSV -#define c_fortran_dgssv_ C_FORTRAN_DGSSV -#define c_fortran_cgssv_ C_FORTRAN_CGSSV -#define c_fortran_zgssv_ C_FORTRAN_ZGSSV -#endif - - -#if (F77_CALL_C == OLD_CRAY) -/* - * These defines set up the naming scheme required to have a fortran 77 - * routine call a C routine - * following Fortran to C interface: - * FORTRAN CALL C DECLARATION - * call dgemm(...) void SGEMM(...) - */ -/* BLAS */ -#define sswap_ SSWAP -#define saxpy_ SAXPY -#define sasum_ SASUM -#define isamax_ ISAMAX -#define scopy_ SCOPY -#define sscal_ SSCAL -#define sger_ SGER -#define snrm2_ SNRM2 -#define ssymv_ SSYMV -#define sdot_ SDOT -#define ssyr2_ SSYR2 -#define srot_ SROT -#define sgemv_ SGEMV -#define strsv_ STRSV -#define sgemm_ SGEMM -#define strsm_ STRSM - -#define dswap_ SSWAP -#define daxpy_ SAXPY -#define dasum_ SASUM -#define idamax_ ISAMAX -#define dcopy_ SCOPY -#define dscal_ SSCAL -#define dger_ SGER -#define dnrm2_ SNRM2 -#define dsymv_ SSYMV -#define ddot_ SDOT -#define dsyr2_ SSYR2 -#define drot_ SROT -#define dgemv_ SGEMV -#define dtrsv_ STRSV -#define dgemm_ SGEMM -#define dtrsm_ STRSM - -#define cswap_ CSWAP -#define caxpy_ CAXPY -#define scasum_ SCASUM -#define icamax_ ICAMAX -#define ccopy_ CCOPY -#define cscal_ CSCAL -#define scnrm2_ SCNRM2 -#define caxpy_ CAXPY -#define cgemv_ CGEMV -#define ctrsv_ CTRSV -#define cgemm_ CGEMM -#define ctrsm_ CTRSM -#define cgerc_ CGERC -#define chemv_ CHEMV -#define cher2_ CHER2 - -#define zswap_ ZSWAP -#define zaxpy_ ZAXPY -#define dzasum_ DZASUM -#define izamax_ IZAMAX -#define zcopy_ ZCOPY -#define zscal_ ZSCAL -#define dznrm2_ DZNRM2 -#define zgemv_ ZGEMV -#define ztrsv_ ZTRSV -#define zgemm_ ZGEMM -#define ztrsm_ ZTRSM -#define zgerc_ ZGERC -#define zhemv_ ZHEMV -#define zher2_ ZHER2 - -/* LAPACK */ -#define dlamch_ DLAMCH -#define slamch_ SLAMCH -#define xerbla_ XERBLA -#define lsame_ LSAME -#define dlacon_ DLACON -#define slacon_ SLACON -#define icmax1_ ICMAX1 -#define scsum1_ SCSUM1 -#define clacon_ CLACON -#define dzsum1_ DZSUM1 -#define izmax1_ IZMAX1 -#define zlacon_ ZLACON - -/* Fortran interface */ -#define c_bridge_dgssv_ C_BRIDGE_DGSSV -#define c_fortran_sgssv_ C_FORTRAN_SGSSV -#define c_fortran_dgssv_ C_FORTRAN_DGSSV -#define c_fortran_cgssv_ C_FORTRAN_CGSSV -#define c_fortran_zgssv_ C_FORTRAN_ZGSSV -#endif - - -#if (F77_CALL_C == NOCHANGE) -/* - * These defines set up the naming scheme required to have a fortran 77 - * routine call a C routine - * for following Fortran to C interface: - * FORTRAN CALL C DECLARATION - * call dgemm(...) void dgemm(...) - */ -/* BLAS */ -#define sswap_ sswap -#define saxpy_ saxpy -#define sasum_ sasum -#define isamax_ isamax -#define scopy_ scopy -#define sscal_ sscal -#define sger_ sger -#define snrm2_ snrm2 -#define ssymv_ ssymv -#define sdot_ sdot -#define saxpy_ saxpy -#define ssyr2_ ssyr2 -#define srot_ srot -#define sgemv_ sgemv -#define strsv_ strsv -#define sgemm_ sgemm -#define strsm_ strsm - -#define dswap_ dswap -#define daxpy_ daxpy -#define dasum_ dasum -#define idamax_ idamax -#define dcopy_ dcopy -#define dscal_ dscal -#define dger_ dger -#define dnrm2_ dnrm2 -#define dsymv_ dsymv -#define ddot_ ddot -#define dsyr2_ dsyr2 -#define drot_ drot -#define dgemv_ dgemv -#define dtrsv_ dtrsv -#define dgemm_ dgemm -#define dtrsm_ dtrsm - -#define cswap_ cswap -#define caxpy_ caxpy -#define scasum_ scasum -#define icamax_ icamax -#define ccopy_ ccopy -#define cscal_ cscal -#define scnrm2_ scnrm2 -#define cgemv_ cgemv -#define ctrsv_ ctrsv -#define cgemm_ cgemm -#define ctrsm_ ctrsm -#define cgerc_ cgerc -#define chemv_ chemv -#define cher2_ cher2 - -#define zswap_ zswap -#define zaxpy_ zaxpy -#define dzasum_ dzasum -#define izamax_ izamax -#define zcopy_ zcopy -#define zscal_ zscal -#define dznrm2_ dznrm2 -#define zgemv_ zgemv -#define ztrsv_ ztrsv -#define zgemm_ zgemm -#define ztrsm_ ztrsm -#define zgerc_ zgerc -#define zhemv_ zhemv -#define zher2_ zher2 - -/* LAPACK */ -#define dlamch_ dlamch -#define slamch_ slamch -#define xerbla_ xerbla -#define lsame_ lsame -#define dlacon_ dlacon -#define slacon_ slacon -#define icmax1_ icmax1 -#define scsum1_ scsum1 -#define clacon_ clacon -#define dzsum1_ dzsum1 -#define izmax1_ izmax1 -#define zlacon_ zlacon - -/* Fortran interface */ -#define c_bridge_dgssv_ c_bridge_dgssv -#define c_fortran_sgssv_ c_fortran_sgssv -#define c_fortran_dgssv_ c_fortran_dgssv -#define c_fortran_cgssv_ c_fortran_cgssv -#define c_fortran_zgssv_ c_fortran_zgssv -#endif - - -#endif /* __SUPERLU_CNAMES */ diff --git a/src/external/arpack++/include/arlnsmat.h b/src/external/arpack++/include/arlnsmat.h deleted file mode 100644 index 07a547f9..00000000 --- a/src/external/arpack++/include/arlnsmat.h +++ /dev/null @@ -1,753 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLNSMat.h. - Arpack++ class ARluNonSymMatrix definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "arlnspen.h" - -#ifndef ARLNSMAT_H -#define ARLNSMAT_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "armat.h" -#include "arhbmat.h" -#include "arerror.h" -#include "blas1c.h" -#include "superluc.h" -#include "arlspdef.h" -#include "arlutil.h" - -template<class AR_T, class AR_S> class ARluNonSymPencil; - -template<class ARTYPE, class ARFLOAT> -class ARluNonSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARluNonSymPencil<ARTYPE, ARFLOAT>; - friend class ARluNonSymPencil<ARFLOAT, ARFLOAT>; - - protected: - - bool factored; - int order; - int nnz; - int* irow; - int* pcol; - int* permc; - int* permr; - double threshold; - ARTYPE* a; - SuperMatrix A; - SuperMatrix L; - SuperMatrix U; - ARhbMatrix<int, ARTYPE> mat; - SuperLUStat_t stat; - - bool DataOK(); - - virtual void Copy(const ARluNonSymMatrix& other); - - void ClearMem(); - - void SubtractAsI(ARTYPE sigma, NCformat& A, NCformat& AsI); - - public: - - int nzeros() { return nnz; } - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultMtv(ARTYPE* v, ARTYPE* w); - - void MultMtMv(ARTYPE* v, ARTYPE* w); - - void MultMMtv(ARTYPE* v, ARTYPE* w); - - void Mult0MMt0v(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, double thresholdp = 0.1, - int orderp = 1, bool check = true); // Square matrix. - - void DefineMatrix(int mp, int np, int nnzp, ARTYPE* ap, - int* irowp, int* pcolp); // Rectangular matrix. - - ARluNonSymMatrix(); - // Short constructor that does nothing. - - ARluNonSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, int* pcolp, - double thresholdp = 0.1, int orderp = 1, bool check = true); - // Long constructor (square matrix). - - ARluNonSymMatrix(int mp, int np, int nnzp, ARTYPE* ap, int* irowp,int* pcolp); - // Long constructor (rectangular matrix). - - ARluNonSymMatrix(const std::string& name, double thresholdp = 0.1, - int orderp = 1, bool check = true); - // Long constructor (Harwell-Boeing file). - - ARluNonSymMatrix(const ARluNonSymMatrix& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymMatrix() { ClearMem(); } - // Destructor. - - ARluNonSymMatrix& operator=(const ARluNonSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARluNonSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE, class ARFLOAT> -bool ARluNonSymMatrix<ARTYPE, ARFLOAT>::DataOK() -{ - - int i, j, k; - - // Checking if pcol is in ascending order. - - i = 0; - while ((i!=this->n)&&(pcol[i]<=pcol[i+1])) i++; - if (i!=this->n) return false; - - // Checking if irow components are in order and within bounds. - - for (i=0; i!=this->n; i++) { - j = pcol[i]; - k = pcol[i+1]-1; - if (j<=k) { - if ((irow[j]<0)||(irow[k]>=this->n)) return false; - while ((j!=k)&&(irow[j]<irow[j+1])) j++; - if (j!=k) return false; - } - } - - return true; - -} // DataOK. - - -template<class ARTYPE, class ARFLOAT> -inline void ARluNonSymMatrix<ARTYPE, ARFLOAT>:: -Copy(const ARluNonSymMatrix<ARTYPE, ARFLOAT>& other) -{ - - // Copying very fundamental variables. - - this->defined = other.defined; - factored = other.factored; - - // Returning from here if "other" was not initialized. - - if (!this->defined) return; - - // Copying user-defined parameters. - - if (other.n == other.m) { - DefineMatrix(other.n, other.nnz, other.a, other.irow, - other.pcol, other.threshold, other.order); - } - else { - DefineMatrix(other.m, other.n, other.nnz, - other.a, other.irow, other.pcol); - } - - // Throwing the original factorization away (this procedure - // is really awkward, but it is necessary because there - // is no copy function for matrices L and U in the SuperLU - // library and it is not a good idea to do this kind of deep - // copy here). - - if (factored) { - ArpackError(ArpackError::LAPACK_ERROR, "ARluNonSymMatrix"); - factored = false; - } - -} // Copy. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::ClearMem() -{ - - if (factored) { - Destroy_SuperNode_Matrix(&L); - Destroy_CompCol_Matrix(&U); - StatFree(&stat); - } - if (this->defined) { - Destroy_SuperMatrix_Store(&A); // delete A.Store; - delete[] permc; - delete[] permr; - permc = NULL; - permr = NULL; - A.Store = NULL; - } - -} // ClearMem. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>:: -SubtractAsI(ARTYPE sigma, NCformat& A, NCformat& AsI) -{ - - // Defining local variables. - - int i, j, k, end; - ARTYPE* anzval; - ARTYPE* inzval; - - // Telling the compiler that nzval must be viewed as a vector of ARTYPE. - - anzval = (ARTYPE*)A.nzval; - inzval = (ARTYPE*)AsI.nzval; - - // Subtracting sigma from diagonal elements. - - k = 0; - AsI.colptr[0] = 0; - - for (i=0; i!=this->n; i++) { - - j = A.colptr[i]; - end = A.colptr[i+1]; - - // Copying superdiagonal elements of column i. - - while ((A.rowind[j] < i)&&(j < end)) { - inzval[k] = anzval[j]; - AsI.rowind[k++] = A.rowind[j++]; - } - - // Verifying if A(i,i) exists. - - if ((A.rowind[j] == i)&&(j < end)) { // A(i,i) exists, subtracting sigma. - inzval[k] = anzval[j++] - sigma; - } - else { // A(i,i) does not exist. - inzval[k] = -sigma; - } - AsI.rowind[k++] = i; - - // Copying subdiagonal elements of column i. - - while (j < end ) { - inzval[k] = anzval[j]; - AsI.rowind[k++] = A.rowind[j++]; - } - - AsI.colptr[i+1] = k; - - } - - AsI.nnz = AsI.colptr[this->n]; - -} // SubtractAsI. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::FactorA() -{ - - // Defining local variables. - - int info; - int* etree; - SuperMatrix AC; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARluNonSymMatrix::FactorA"); - } - - // Quitting the function if A is not square. - - if (this->m != this->n) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARluNonSymMatrix::FactorA"); - } - - // Deleting previous versions of L and U. - - if (factored) { - Destroy_SuperNode_Matrix(&L); - Destroy_CompCol_Matrix(&U); - StatFree(&stat); - } - - // Setting default values for gstrf parameters. - - int panel_size = sp_ienv(1); - int relax = sp_ienv(2); - superlu_options_t options; - - /* Set the default input options: - options.Fact = DOFACT; - options.Equil = YES; - options.ColPerm = COLAMD; - options.DiagPivotThresh = 1.0; - options.Trans = NOTRANS; - options.IterRefine = NOREFINE; - options.SymmetricMode = NO; - options.PivotGrowth = NO; - options.ConditionNumber = NO; - options.PrintStat = YES; - */ - set_default_options(&options); - options.DiagPivotThresh = threshold; - - // Reserving memory for etree (used in matrix decomposition). - - etree = new int[this->n]; - - // Defining LUStat. - - //StatInit(panel_size, relax); - StatInit(&stat); - - // Defining the column permutation of matrix A - // (using minimum degree ordering on A'*A). - - get_perm_c(order, &A, permc); - - // Permuting columns of A and - // creating the elimination tree of A'*A. - -// sp_preorder("N", &A, permc, etree, &AC); - sp_preorder(&options, &A, permc, etree, &AC); - - // Decomposing A. - -// gstrf("N",&AC, threshold, drop_tol, relax, panel_size, etree, -// NULL, 0, permr, permc, &L, &U, &info); - gstrf(&options,&AC, relax, panel_size, etree, - NULL, 0, permc, permr, &L, &U, &stat, &info); - - // Deleting AC and etree. - - Destroy_CompCol_Permuted(&AC); - delete[] etree; - - factored = (info == 0); - - // Handling errors. - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARluNonSymMatrix::FactorA"); - } - else if (info > this->n) { // Memory is not sufficient. - throw ArpackError(ArpackError::MEMORY_OVERFLOW, - "ARluNonSymMatrix::FactorA"); - } - else if (info > 0) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARluNonSymMatrix::FactorA"); - } - -} // FactorA. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::FactorAsI(ARTYPE sigma) -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARluNonSymMatrix::FactorAsI"); - } - - // Quitting the function if A is not square. - - if (this->m != this->n) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARluNonSymMatrix::FactorAsI"); - } - - // Defining local variables. - - int info; - int* etree; - int* irowi; - int* pcoli; - ARTYPE* asi; - SuperMatrix AsI; - SuperMatrix AC; - NCformat* Astore; - NCformat* AsIstore; - - // Deleting previous versions of L and U. - - if (factored) { - Destroy_SuperNode_Matrix(&L); - Destroy_CompCol_Matrix(&U); - StatFree(&stat); - } - - // Setting default values for gstrf parameters. - - int panel_size = sp_ienv(1); - int relax = sp_ienv(2); - superlu_options_t options; - - /* Set the default input options: - options.Fact = DOFACT; - options.Equil = YES; - options.ColPerm = COLAMD; - options.DiagPivotThresh = 1.0; - options.Trans = NOTRANS; - options.IterRefine = NOREFINE; - options.SymmetricMode = NO; - options.PivotGrowth = NO; - options.ConditionNumber = NO; - options.PrintStat = YES; - */ - set_default_options(&options); - options.DiagPivotThresh = threshold; - - // Creating a temporary matrix AsI. - - irowi = (int*)SUPERLU_MALLOC(sizeof(int) * (nnz+this->n)); - pcoli = (int*)SUPERLU_MALLOC(sizeof(int) * (this->n+1)); - asi = (ARTYPE*)SUPERLU_MALLOC(sizeof(ARTYPE) * (nnz+this->n)); - Create_CompCol_Matrix(&AsI, this->n, this->n, nnz, asi, irowi, pcoli, SLU_NC, SLU_GE); - - // Subtracting sigma*I from A and storing the result on AsI. - - Astore = (NCformat*)A.Store; - AsIstore = (NCformat*)AsI.Store; - SubtractAsI(sigma, *Astore, *AsIstore); - - // Reserving memory for etree (used in matrix decomposition). - - etree = new int[this->n]; - - // Defining LUStat. - - //StatInit(panel_size, relax); - StatInit(&stat); - - // Defining the column permutation of matrix AsI - // (using minimum degree ordering on AsI'*AsI). - - get_perm_c(order, &AsI, permc); - - // Permuting columns of AsI and - // creating the elimination tree of AsI'*AsI. - - //sp_preorder("N", &AsI, permc, etree, &AC); - sp_preorder(&options, &AsI, permc, etree, &AC); - - // Decomposing AsI. - -// gstrf("N",&AC, threshold, drop_tol, relax, panel_size, etree, -// NULL, 0, permr, permc, &L, &U, &info); - gstrf(&options,&AC, relax, panel_size, etree, - NULL, 0, permc, permr, &L, &U, &stat, &info); - - // Deleting AC, AsI and etree. - - Destroy_CompCol_Permuted(&AC); - Destroy_CompCol_Matrix(&AsI); - delete[] etree; - - factored = (info == 0); - - // Handling errors. - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARluNonSymMatrix::FactorAsI"); - } - else if (info > this->n) { // Memory is not sufficient. - throw ArpackError(ArpackError::MEMORY_OVERFLOW, - "ARluNonSymMatrix::FactorAsI"); - } - else if (info > 0) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARluNonSymMatrix::FactorAsI"); - } - -} // FactorAsI. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::MultMv(ARTYPE* v, ARTYPE* w) -{ - - int i,j; - ARTYPE t; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARluNonSymMatrix::MultMv"); - } - - // Determining w = M.v. - - for (i=0; i!=this->m; i++) w[i]=(ARTYPE)0; - - for (i=0; i!=this->n; i++) { - t = v[i]; - for (j=pcol[i]; j!=pcol[i+1]; j++) { - w[irow[j]] += t*a[j]; - } - } - -} // MultMv. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::MultMtv(ARTYPE* v, ARTYPE* w) -{ - - int i,j; - ARTYPE t; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARluNonSymMatrix::MultMtv"); - } - - // Determining w = M'.v. - - for (i=0; i!=this->n; i++) { - t = (ARTYPE)0; - for (j=pcol[i]; j!=pcol[i+1]; j++) { - t += v[irow[j]]*a[j]; - } - w[i] = t; - } - -} // MultMtv. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::MultMtMv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE* t = new ARTYPE[this->m]; - - MultMv(v,t); - MultMtv(t,w); - - delete[] t; - -} // MultMtMv. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::MultMMtv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE* t = new ARTYPE[this->n]; - - MultMtv(v,t); - MultMv(t,w); - - delete[] t; - -} // MultMMtv. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::Mult0MMt0v(ARTYPE* v, ARTYPE* w) -{ - - MultMv(&v[this->m],w); - MultMtv(v,&w[this->m]); - -} // Mult0MMt0v. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymMatrix<ARTYPE, ARFLOAT>::MultInvv(ARTYPE* v, ARTYPE* w) -{ - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARluNonSymMatrix::MultInvv"); - } - - // Solving A.w = v (or AsI.w = v). - - int info; - SuperMatrix B; - - if (&v != &w) copy(this->n, v, 1, w, 1); - Create_Dense_Matrix(&B, this->n, 1, w, this->n, SLU_DN, SLU_GE); -// gstrs("N", &L, &U, permr, permc, &B, &info); - StatInit(&stat); - trans_t trans = NOTRANS; - gstrs(trans, &L, &U, permc, permr, &B, &stat, &info); - Destroy_SuperMatrix_Store(&B); // delete B.Store; - -} // MultInvv. - - -template<class ARTYPE, class ARFLOAT> -inline void ARluNonSymMatrix<ARTYPE, ARFLOAT>:: -DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, int* pcolp, - double thresholdp, int orderp, bool check) -{ - - this->m = np; - this->n = np; - nnz = nnzp; - a = ap; - irow = irowp; - pcol = pcolp; - pcol[this->n] = nnz; - threshold = thresholdp; - order = orderp; - - // Checking data. - - if ((check)&&(!DataOK())) { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARluSymMatrix::DefineMatrix"); - } - - // Creating SuperMatrix A. - - Create_CompCol_Matrix(&A, this->n, this->n, nnz, a, irow, pcol, SLU_NC, SLU_GE); - - // Reserving memory for vectors used in matrix decomposition. - - permc = new int[this->n]; - permr = new int[this->n]; - - this->defined = true; - -} // DefineMatrix (square). - - -template<class ARTYPE, class ARFLOAT> -inline void ARluNonSymMatrix<ARTYPE, ARFLOAT>:: -DefineMatrix(int mp, int np, int nnzp, ARTYPE* ap, int* irowp, int* pcolp) -{ - - this->m = mp; - this->n = np; - nnz = nnzp; - a = ap; - irow = irowp; - pcol = pcolp; - pcol[this->n] = nnz; - this->defined = true; - permc = NULL; - permr = NULL; - -} // DefineMatrix (rectangular). - - -template<class ARTYPE, class ARFLOAT> -inline ARluNonSymMatrix<ARTYPE, ARFLOAT>::ARluNonSymMatrix(): ARMatrix<ARTYPE>() -{ - - factored = false; - permc = NULL; - permr = NULL; - -} // Short constructor. - - -template<class ARTYPE, class ARFLOAT> -inline ARluNonSymMatrix<ARTYPE, ARFLOAT>:: -ARluNonSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, double thresholdp, - int orderp, bool check) : ARMatrix<ARTYPE>(np) -{ - - factored = false; - DefineMatrix(np, nnzp, ap, irowp, pcolp, thresholdp, orderp, check); - -} // Long constructor (square matrix). - - -template<class ARTYPE, class ARFLOAT> -inline ARluNonSymMatrix<ARTYPE, ARFLOAT>:: -ARluNonSymMatrix(int mp, int np, int nnzp, ARTYPE* ap, - int* irowp, int* pcolp) : ARMatrix<ARTYPE>(mp, np) -{ - - factored = false; - DefineMatrix(mp, np, nnzp, ap, irowp, pcolp); - -} // Long constructor (retangular matrix). - - -template<class ARTYPE, class ARFLOAT> -ARluNonSymMatrix<ARTYPE, ARFLOAT>:: -ARluNonSymMatrix(const std::string& file, double thresholdp, int orderp, bool check) -{ - - factored = false; - - try { - mat.Define(file); - } - catch (ArpackError) { // Returning from here if an error has occurred. - throw ArpackError(ArpackError::CANNOT_READ_FILE, "ARluNonSymMatrix"); - } - - if (mat.NCols()==mat.NRows()) { - DefineMatrix(mat.NCols(), mat.NonZeros(), (ARTYPE*)mat.Entries(), - mat.RowInd(), mat.ColPtr(), thresholdp, orderp, check); - } - else { - DefineMatrix(mat.NRows(), mat.NCols(), mat.NonZeros(), - (ARTYPE*)mat.Entries(), mat.RowInd(), mat.ColPtr()); - } - -} // Long constructor (Harwell-Boeing file). - - -template<class ARTYPE, class ARFLOAT> -ARluNonSymMatrix<ARTYPE, ARFLOAT>& ARluNonSymMatrix<ARTYPE, ARFLOAT>:: -operator=(const ARluNonSymMatrix<ARTYPE, ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLNSMAT_H diff --git a/src/external/arpack++/include/arlnspen.h b/src/external/arpack++/include/arlnspen.h deleted file mode 100644 index b479ac65..00000000 --- a/src/external/arpack++/include/arlnspen.h +++ /dev/null @@ -1,774 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLNSPen.h. - Arpack++ class ARluNonSymPencil definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARLNSPEN_H -#define ARLNSPEN_H - -#include <cstddef> - -#include "arch.h" -#include "arerror.h" -#include "blas1c.h" -#include "superluc.h" -#include "arlspdef.h" -#include "arlutil.h" -#include "arlnsmat.h" - - -template<class ARTYPE, class ARFLOAT> -class ARluNonSymPencil -{ - - protected: - - bool factored; - int* permc; - int* permr; - char part; - ARluNonSymMatrix<ARTYPE, ARFLOAT>* A; - ARluNonSymMatrix<ARTYPE, ARFLOAT>* B; - SuperMatrix L; - SuperMatrix U; - SuperLUStat_t stat; - - virtual void Copy(const ARluNonSymPencil& other); - - void ClearMem(); - - void SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], - int yind[], int ny, ARTYPE z[], int zind[], int& nz); - -#ifdef ARCOMP_H - void SparseSaxpy(arcomplex<ARFLOAT> a, ARFLOAT x[], int xind[], int nx, - ARFLOAT y[], int yind[], int ny, arcomplex<ARFLOAT> z[], - int zind[], int& nz); -#endif - - void SubtractAsB(int n, ARTYPE sigma, NCformat& A, - NCformat& B, NCformat& AsB); - -#ifdef ARCOMP_H - void SubtractAsB(int n, ARFLOAT sigmaR, ARFLOAT sigmaI, - NCformat& A, NCformat& B, NCformat& AsB); -#endif - - public: - - bool IsFactored() { return factored; } - - void FactorAsB(ARTYPE sigma); - -#ifdef ARCOMP_H - void FactorAsB(ARFLOAT sigmaR, ARFLOAT sigmaI, char partp = 'R'); -#endif - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - -#ifdef ARCOMP_H - void MultInvAsBv(arcomplex<ARFLOAT>* v, arcomplex<ARFLOAT>* w); -#endif - - void MultInvAsBv(ARFLOAT* v, ARFLOAT* w); - - void DefineMatrices(ARluNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARluNonSymMatrix<ARTYPE, ARFLOAT>& Bp); - - ARluNonSymPencil(); - // Short constructor that does nothing. - - ARluNonSymPencil(ARluNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARluNonSymMatrix<ARTYPE, ARFLOAT>& Bp); - // Long constructor. - - ARluNonSymPencil(const ARluNonSymPencil& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymPencil() { ClearMem(); } - // Destructor. - - ARluNonSymPencil& operator=(const ARluNonSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARluNonSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE, class ARFLOAT> -inline void ARluNonSymPencil<ARTYPE, ARFLOAT>:: -Copy(const ARluNonSymPencil<ARTYPE, ARFLOAT>& other) -{ - - factored = other.factored; - part = other.part; - A = other.A; - B = other.B; - - // Throwing the original factorization away (this procedure - // is really awkward, but it is necessary because there - // is no copy function for matrices L and U in the SuperLU - // library and it is not a good idea to do this kind of deep - // copy here). - - if (factored) { - ArpackError(ArpackError::DISCARDING_FACTORS, "ARluNonSymPencil"); - factored = false; - } - -} // Copy. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>::ClearMem() -{ - - if (factored) { - Destroy_SuperNode_Matrix(&L); - Destroy_CompCol_Matrix(&U); - StatFree(&stat); - delete[] permc; - delete[] permr; - permc = NULL; - permr = NULL; - } - -} // ClearMem. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>:: -SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], - int yind[], int ny, ARTYPE z[], int zind[], int& nz) -// A strongly sequential (and inefficient) sparse saxpy algorithm. -{ - - int ix, iy; - - nz = 0; - if ((nx == 0) || (a == (ARTYPE)0)) { - copy(ny,y,1,z,1); - for (iy=0; iy!=ny; iy++) zind[iy] = yind[iy]; - nz = ny; - return; - } - if (ny == 0) { - copy(nx,x,1,z,1); - scal(nx,a,z,1); - for (ix=0; ix!=nx; ix++) zind[ix] = xind[ix]; - nz = nx; - return; - } - ix = 0; - iy = 0; - while (true) { - if (xind[ix] == yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]+y[iy++]; - if ((ix == nx)||(iy == ny)) break; - } - else if (xind[ix] < yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]; - if (ix == nx) break; - } - else { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - if (iy == ny) break; - } - } - while (iy < ny) { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - } - while (ix < nx) { - zind[nz] = xind[ix]; - z[nz++] = x[ix++]; - } - -} // SparseSaxpy (ARTYPE). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>:: -SparseSaxpy(arcomplex<ARFLOAT> a, ARFLOAT x[], int xind[], int nx, ARFLOAT y[], - int yind[], int ny, arcomplex<ARFLOAT> z[], int zind[], int& nz) -// A strongly sequential (and inefficient) sparse saxpy algorithm. -{ - - int ix, iy; - - nz = 0; - if ((nx == 0) || (a == arcomplex<ARFLOAT>(0.0,0.0))) { - for (iy=0; iy!=ny; iy++) { - z[iy] = arcomplex<ARFLOAT>(y[iy],0.0); - zind[iy] = yind[iy]; - } - nz = ny; - return; - } - if (ny == 0) { - for (ix=0; ix!=ny; ix++) { - z[ix] = a*arcomplex<ARFLOAT>(x[ix],0.0); - zind[ix] = xind[ix]; - } - nz = nx; - return; - } - ix = 0; - iy = 0; - while (true) { - if (xind[ix] == yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]+y[iy++]; - if ((ix == nx)||(iy == ny)) break; - } - else if (xind[ix] < yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]; - if (ix == nx) break; - } - else { - zind[nz] = yind[iy]; - z[nz++] = arcomplex<ARFLOAT>(y[iy++],0.0); - if (iy == ny) break; - } - } - while (iy < ny) { - zind[nz] = yind[iy]; - z[nz++] = arcomplex<ARFLOAT>(y[iy++],0.0); - } - while (ix < nx) { - zind[nz] = xind[ix]; - z[nz++] = arcomplex<ARFLOAT>(x[ix++],0.0); - } - -} // SparseSaxpy (arcomplex<ARFLOAT>). -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>:: -SubtractAsB(int n, ARTYPE sigma, NCformat& A, NCformat& B, NCformat& AsB) -{ - - int i, acol, bcol, asbcol, scol; - ARTYPE* anzval; - ARTYPE* bnzval; - ARTYPE* asbnzval; - - // Telling the compiler that nzval must ve viewed as a vector of ARTYPE. - - anzval = (ARTYPE*)A.nzval; - bnzval = (ARTYPE*)B.nzval; - asbnzval = (ARTYPE*)AsB.nzval; - - // Subtracting sigma*B from A. - - AsB.colptr[0] = 0; - asbcol = 0; - - for (i=0; i!=n; i++) { - bcol = B.colptr[i]; - acol = A.colptr[i]; - SparseSaxpy(-sigma, &bnzval[bcol], &B.rowind[bcol], B.colptr[i+1]-bcol, - &anzval[acol], &A.rowind[acol], A.colptr[i+1]-acol, - &asbnzval[asbcol], &AsB.rowind[asbcol], scol); - asbcol += scol; - AsB.colptr[i+1] = asbcol; - } - - AsB.nnz = AsB.colptr[n]; - -} // SubtractAsB (ARTYPE shift). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>:: -SubtractAsB(int n, ARFLOAT sigmaR, ARFLOAT sigmaI, - NCformat& A, NCformat& B, NCformat& AsB) -{ - - int i, acol, bcol, asbcol, scol; - ARTYPE* anzval; - ARTYPE* bnzval; - arcomplex<ARFLOAT>* asbnzval; - arcomplex<ARFLOAT> sigma; - - // Telling the compiler that nzval must ve viewed as a vector of ARTYPE. - - anzval = (ARTYPE*)A.nzval; - bnzval = (ARTYPE*)B.nzval; - asbnzval = (arcomplex<ARFLOAT>*)AsB.nzval; - - // Subtracting sigma*B from A. - - sigma = arcomplex<ARFLOAT>(sigmaR, sigmaI); - AsB.colptr[0] = 0; - asbcol = 0; - - for (i=0; i!=n; i++) { - bcol = B.colptr[i]; - acol = A.colptr[i]; - SparseSaxpy(-sigma, &bnzval[bcol], &B.rowind[bcol], B.colptr[i+1]-bcol, - &anzval[acol], &A.rowind[acol], A.colptr[i+1]-acol, - &asbnzval[asbcol], &AsB.rowind[asbcol], scol); - asbcol += scol; - AsB.colptr[i+1] = asbcol; - } - - AsB.nnz = AsB.colptr[n]; - -} // SubtractAsB (arcomplex<ARFLOAT> shift). -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARluNonSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARluNonSymPencil::FactorAsB"); - } - - // Defining local variables. - - int nnzi, info; - int* etree; - int* irowi; - int* pcoli; - ARTYPE* asb; - SuperMatrix AsB; - SuperMatrix AC; - NCformat* Astore; - NCformat* Bstore; - NCformat* AsBstore; - - // Deleting old versions of L, U, perm_r and perm_c. - - ClearMem(); - - // Setting default values for gstrf parameters. - - int panel_size = sp_ienv(1); - int relax = sp_ienv(2); - superlu_options_t options; - /* Set the default input options: - options.Fact = DOFACT; - options.Equil = YES; - options.ColPerm = COLAMD; - options.DiagPivotThresh = 1.0; - options.Trans = NOTRANS; - options.IterRefine = NOREFINE; - options.SymmetricMode = NO; - options.PivotGrowth = NO; - options.ConditionNumber = NO; - options.PrintStat = YES; - */ - set_default_options(&options); - options.DiagPivotThresh = A->threshold; - - // Defining A and B format. - - Astore = (NCformat*)A->A.Store; - Bstore = (NCformat*)B->A.Store; - - // Creating a temporary matrix AsB. - - nnzi = Astore->nnz+Bstore->nnz; - irowi = new int[nnzi]; - pcoli = new int[A->ncols()+1]; - asb = new ARTYPE[nnzi]; - Create_CompCol_Matrix(&AsB, A->nrows(), A->ncols(), nnzi, asb, - irowi, pcoli, SLU_NC, SLU_GE); - - // Subtracting sigma*B from A and storing the result on AsB. - - AsBstore = (NCformat*)AsB.Store; - SubtractAsB(A->ncols(), sigma, *Astore, *Bstore, *AsBstore); - - // Reserving memory for some vectors used in matrix decomposition. - - etree = new int[A->ncols()]; - if (permc == NULL) permc = new int[A->ncols()]; - if (permr == NULL) permr = new int[A->ncols()]; - - // Defining LUStat. - -// StatInit(panel_size, relax); - SuperLUStat_t stat; - StatInit(&stat); - - // Defining the column permutation of matrix AsB - // (using minimum degree ordering on AsB'*AsB). - - get_perm_c(A->order, &AsB, permc); - - // Permuting columns of AsB and - // creating the elimination tree of AsB'*AsB. - -// sp_preorder("N", &AsB, permc, etree, &AC); - sp_preorder(&options, &AsB, permc, etree, &AC); - - // Decomposing AsB. - -// gstrf("N",&AC, A->threshold, drop_tol, relax, panel_size, etree, -// NULL, 0, permr, permc, &L, &U, &info); - gstrf(&options, &AC, relax, panel_size, etree, - NULL, 0, permc, permr, &L, &U, &stat, &info); - - // Deleting AC, AsB and etree. - - Destroy_CompCol_Permuted(&AC); - Destroy_CompCol_Matrix(&AsB); - delete[] etree; - - factored = (info == 0); - - // Handling errors. - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARluNonSymPencil::FactorAsB"); - } - else if (info > A->ncols()) { // Memory is not sufficient. - throw ArpackError(ArpackError::MEMORY_OVERFLOW, - "ARluNonSymPencil::FactorAsB"); - } - else if (info > 0) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARluNonSymPencil::FactorAsB"); - } - -} // FactorAsB (ARTYPE shift). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>:: -FactorAsB(ARFLOAT sigmaR, ARFLOAT sigmaI, char partp) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARluNonSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARluNonSymPencil::FactorAsB"); - } - - // Defining local variables. - - int nnzi, info; - int* etree; - int* irowi; - int* pcoli; - arcomplex<ARFLOAT>* asb; - SuperMatrix AsB; - SuperMatrix AC; - NCformat* Astore; - NCformat* Bstore; - NCformat* AsBstore; - - // Deleting old versions of L, U, perm_r and perm_c. - - ClearMem(); - - // Setting default values for gstrf parameters. - - int panel_size = sp_ienv(1); - int relax = sp_ienv(2); - superlu_options_t options; - /* Set the default input options: - options.Fact = DOFACT; - options.Equil = YES; - options.ColPerm = COLAMD; - options.DiagPivotThresh = 1.0; - options.Trans = NOTRANS; - options.IterRefine = NOREFINE; - options.SymmetricMode = NO; - options.PivotGrowth = NO; - options.ConditionNumber = NO; - options.PrintStat = YES; - */ - set_default_options(&options); - options.DiagPivotThresh = A->threshold; - - - // Defining A and B format. - - Astore = (NCformat*)A->A.Store; - Bstore = (NCformat*)B->A.Store; - - // Creating a temporary matrix AsB. - - part = partp; - nnzi = Astore->nnz+Bstore->nnz; - irowi = new int[nnzi]; - pcoli = new int[A->ncols()+1]; - asb = new arcomplex<ARFLOAT>[nnzi]; - Create_CompCol_Matrix(&AsB, A->nrows(), A->ncols(), nnzi, asb, - irowi, pcoli, SLU_NC, SLU_GE); - - // Subtracting sigma*B from A and storing the result on AsB. - - AsBstore = (NCformat*)AsB.Store; - SubtractAsB(A->ncols(), sigmaR, sigmaI, *Astore, *Bstore, *AsBstore); - - // Reserving memory for some vectors used in matrix decomposition. - - etree = new int[A->ncols()]; - if (permc == NULL) permc = new int[A->ncols()]; - if (permr == NULL) permr = new int[A->ncols()]; - - // Defining LUStat. - -// StatInit(panel_size, relax); - SuperLUStat_t stat; - StatInit(&stat); - - // Defining the column permutation of matrix AsB - // (using minimum degree ordering on AsB'*AsB). - - get_perm_c(A->order, &AsB, permc); - - // Permuting columns of AsB and - // creating the elimination tree of AsB'*AsB. - - //sp_preorder("N", &AsB, permc, etree, &AC); - sp_preorder(&options, &AsB, permc, etree, &AC); - - // Decomposing AsB. - -// gstrf("N",&AC, A->threshold, drop_tol, relax, panel_size, etree, NULL, -// 0, permr, permc, &L, &U, &info); - gstrf(&options, &AC, relax, panel_size, etree, - NULL, 0, permc, permr, &L, &U, &stat, &info); - - // Deleting AC, AsB and etree. - - Destroy_CompCol_Permuted(&AC); - Destroy_CompCol_Matrix(&AsB); - delete[] etree; - - factored = (info == 0); - - // Handling errors. - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARluNonSymPencil::FactorAsB"); - } - else if (info > A->ncols()) { // Memory is not sufficient. - throw ArpackError(ArpackError::MEMORY_OVERFLOW, - "ARluNonSymPencil::FactorAsB"); - } - else if (info > 0) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARluNonSymPencil::FactorAsB"); - } - -} // FactorAsB (arcomplex<ARFLOAT> shift). -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - B->MultInvv(w, w); - -} // MultInvBAv. - - -#ifdef ARCOMP_H - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>:: -MultInvAsBv(arcomplex<ARFLOAT>* v, arcomplex<ARFLOAT>* w) -{ - - // Quitting the function if AsB was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARluNonSymPencil::MultInvAsBv"); - } - - // Solving AsB.w = v. - - int info; - SuperMatrix RHS; - - copy(A->nrows(), v, 1, w, 1); - Create_Dense_Matrix(&RHS, A->nrows(), 1, w, A->nrows(), SLU_DN, SLU_GE); -// gstrs("N", &L, &U, permr, permc, &RHS, &info); - trans_t trans = NOTRANS; - StatInit(&stat); - - gstrs(trans, &L, &U, permc, permr, &RHS, &stat, &info); - - Destroy_SuperMatrix_Store(&RHS); // delete RHS.Store; - -} // MultInvAsBv (arcomplex<ARFLOAT>). - -#endif - - -template<class ARTYPE, class ARFLOAT> -void ARluNonSymPencil<ARTYPE, ARFLOAT>::MultInvAsBv(ARFLOAT* v, ARFLOAT* w) -{ - - // Quitting the function if AsB was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARluNonSymPencil::MultInvAsBv"); - } - - // Solving AsB.w = v. - - int info; - SuperMatrix RHS; - - if (part == 'N') { // shift is real. - - copy(A->nrows(), v, 1, w, 1); - Create_Dense_Matrix(&RHS, A->nrows(), 1, w, A->nrows(), SLU_DN, SLU_GE); - //gstrs("N", &L, &U, permr, permc, &RHS, &info); - trans_t trans = NOTRANS; - StatInit(&stat); - gstrs(trans, &L, &U, permc, permr, &RHS, &stat, &info); - - } - else { // shift is complex. - -#ifdef ARCOMP_H - - int i; - arcomplex<ARFLOAT> *tv = new arcomplex<ARFLOAT>[A->ncols()]; - - for (i=0; i!=A->ncols(); i++) tv[i] = arcomplex<ARFLOAT>(v[i],0.0); - Create_Dense_Matrix(&RHS, A->ncols(), 1, tv, A->ncols(), SLU_DN, SLU_GE); - //gstrs("N", &L, &U, permr, permc, &RHS, &info); - trans_t trans = NOTRANS; - StatInit(&stat); - gstrs(trans, &L, &U, permc, permr, &RHS, &stat, &info); - - - if (part=='I') { - for (i=0; i!=A->ncols(); i++) w[i] = imag(tv[i]); - } - else { - for (i=0; i!=A->ncols(); i++) w[i] = real(tv[i]); - } - - delete[] tv; - -#endif - - } - - Destroy_SuperMatrix_Store(&RHS); // delete RHS.Store; - -} // MultInvAsBv (ARFLOAT). - - -template<class ARTYPE, class ARFLOAT> -inline void ARluNonSymPencil<ARTYPE, ARFLOAT>:: -DefineMatrices(ARluNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARluNonSymMatrix<ARTYPE, ARFLOAT>& Bp) -{ - - A = &Ap; - B = &Bp; - permc = NULL; - permr = NULL; - - if ((A->n != B->n)||(A->m != B->m)) { - throw ArpackError(ArpackError::INCOMPATIBLE_SIZES, - "ARluNonSymMatrix::DefineMatrices"); - } - -} // DefineMatrices. - - -template<class ARTYPE, class ARFLOAT> -inline ARluNonSymPencil<ARTYPE, ARFLOAT>::ARluNonSymPencil() -{ - - factored = false; - part = 'N'; - permr = NULL; - permc = NULL; - -} // Short constructor. - - -template<class ARTYPE, class ARFLOAT> -inline ARluNonSymPencil<ARTYPE, ARFLOAT>:: -ARluNonSymPencil(ARluNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARluNonSymMatrix<ARTYPE, ARFLOAT>& Bp) -{ - - factored = false; - DefineMatrices(Ap, Bp); - -} // Long constructor. - - -template<class ARTYPE, class ARFLOAT> -ARluNonSymPencil<ARTYPE, ARFLOAT>& ARluNonSymPencil<ARTYPE, ARFLOAT>:: -operator=(const ARluNonSymPencil<ARTYPE, ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLNSPEN_H diff --git a/src/external/arpack++/include/arlscomp.h b/src/external/arpack++/include/arlscomp.h deleted file mode 100644 index ed3b42dc..00000000 --- a/src/external/arpack++/include/arlscomp.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLSComp.h. - Arpack++ class ARluCompStdEig definition - (superlu version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARLSCOMP_H -#define ARLSCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arscomp.h" -#include "arlnsmat.h" -#include "arrseig.h" - - -template<class ARFLOAT> -class ARluCompStdEig: - public virtual ARCompStdEig<ARFLOAT, - ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> > { - - protected: - - // a) Protected function: - - virtual void Copy(const ARluCompStdEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // b) Public functions: - - // b.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(arcomplex<ARFLOAT> sigmap); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(arcomplex<ARFLOAT> sigmap); - - // b.2) Constructors and destructor. - - ARluCompStdEig() { } - // Short constructor. - - ARluCompStdEig(int nevp, ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluCompStdEig(int nevp, ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluCompStdEig(const ARluCompStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluCompStdEig() { } - // Destructor. - - - // c) Operators. - - ARluCompStdEig& operator=(const ARluCompStdEig& other); - // Assignment operator. - -}; // class ARluCompStdEig. - - -// ------------------------------------------------------------------------ // -// ARluCompStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>:: -Copy(const ARluCompStdEig<ARFLOAT>& other) -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> >:: - Copy(other); - if (this->mode > 2) this->objOP->FactorAsI(this->sigmaR); - -} // Copy. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>::ChangeShift(arcomplex<ARFLOAT> sigmap) -{ - - this->objOP->FactorAsI(sigmap); - ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> >::ChangeShift(sigmap); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetRegularMode(this->objOP, - &ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>:: -SetShiftInvertMode(arcomplex<ARFLOAT> sigmap) -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, - &ARluNonSymMatrix<arcomplex<ARFLOAT>,ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluCompStdEig<ARFLOAT>:: -ARluCompStdEig(int nevp, ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, - &ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluCompStdEig<ARFLOAT>:: -ARluCompStdEig(int nevp, ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, - &ARluNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluCompStdEig<ARFLOAT>& ARluCompStdEig<ARFLOAT>:: -operator=(const ARluCompStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLSCOMP_H diff --git a/src/external/arpack++/include/arlsmat.h b/src/external/arpack++/include/arlsmat.h deleted file mode 100644 index 3c0ce079..00000000 --- a/src/external/arpack++/include/arlsmat.h +++ /dev/null @@ -1,765 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLSMat.h. - Arpack++ class ARluSymMatrix definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "arlspen.h" - -#ifndef ARLSMAT_H -#define ARLSMAT_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "armat.h" -#include "arhbmat.h" -#include "arerror.h" -#include "blas1c.h" -#include "superluc.h" -#include "arlspdef.h" -#include "arlutil.h" - -template<class ARTYPE> class ARluSymPencil; - -template<class ARTYPE> -class ARluSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARluSymPencil<ARTYPE>; - - protected: - - bool factored; - char uplo; - int order; - int nnz; - int* irow; - int* pcol; - int* permc; - int* permr; - double threshold; - ARTYPE* a; - SuperMatrix A; - SuperMatrix L; - SuperMatrix U; - ARhbMatrix<int, ARTYPE> mat; - SuperLUStat_t stat; - - bool DataOK(); - - virtual void Copy(const ARluSymMatrix& other); - - void ClearMem(); - - void ExpandA(NCformat& A, NCformat& Aexp, ARTYPE sigma = (ARTYPE)0); - - public: - - int nzeros() { return nnz; } - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, int* pcolp, - char uplop = 'L', double thresholdp = 0.1, - int orderp = 2, bool check = true); - - ARluSymMatrix(); - // Short constructor that does nothing. - - ARluSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, int* pcolp, - char uplop = 'L', double thresholdp = 0.1, - int orderp = 2, bool check = true); - // Long constructor. - - ARluSymMatrix(const std::string& name, double thresholdp = 0.1, - int orderp = 2, bool check = true); - // Long constructor (Harwell-Boeing file). - - ARluSymMatrix(const ARluSymMatrix& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymMatrix() { ClearMem(); } - // Destructor. - - ARluSymMatrix& operator=(const ARluSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARluSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -bool ARluSymMatrix<ARTYPE>::DataOK() -{ - - int i, j, k; - - // Checking if pcol is in ascending order. - - i = 0; - while ((i!=this->n)&&(pcol[i]<=pcol[i+1])) i++; - if (i!=this->n) return false; - - // Checking if irow components are in order and within bounds. - - for (i=0; i!=this->n; i++) { - j = pcol[i]; - k = pcol[i+1]-1; - if (j<=k) { - if (uplo == 'U') { - if ((irow[j]<0)||(irow[k]>i)) return false; - } - else { // uplo == 'L'. - if ((irow[j]<i)||(irow[k]>=this->n)) return false; - } - while ((j!=k)&&(irow[j]<irow[j+1])) j++; - if (j!=k) return false; - } - } - - return true; - -} // DataOK. - - -template<class ARTYPE> -inline void ARluSymMatrix<ARTYPE>::Copy(const ARluSymMatrix<ARTYPE>& other) -{ - - // Copying very fundamental variables. - - this->defined = other.defined; - factored = other.factored; - - // Returning from here if "other" was not initialized. - - if (!this->defined) return; - - // Copying user-defined parameters. - - DefineMatrix(other.n, other.nnz, other.a, other.irow, other.pcol, - other.uplo, other.threshold, other.order); - - // Throwing the original factorization away (this procedure - // is really awkward, but it is necessary because there - // is no copy function for matrices L and U in the SuperLU - // library and it is not a good idea to do this kind of deep - // copy here). - - if (factored) { - ArpackError(ArpackError::LAPACK_ERROR, "ARluSymMatrix"); - factored = false; - } - -} // Copy. - - -template<class ARTYPE> -void ARluSymMatrix<ARTYPE>::ClearMem() -{ - - if (factored) { - Destroy_SuperNode_Matrix(&L); - Destroy_CompCol_Matrix(&U); - StatFree(&stat); - } - if (this->defined) { - Destroy_SuperMatrix_Store(&A); // delete A.Store; - delete[] permc; - delete[] permr; - permc = NULL; - permr = NULL; - A.Store = NULL; - } - -} // ClearMem. - - -template<class ARTYPE> -void ARluSymMatrix<ARTYPE>:: -ExpandA(NCformat& A, NCformat& Aexp, ARTYPE sigma) -{ - - // Defining local variables. - - bool subtract; - int i, j, k; - int *colA, *colE; - int *indA, *indE; - ARTYPE *valA, *valE; - - // Checking if sigma is zero. - - subtract = (sigma != (ARTYPE)0); - - // Simplifying the notation. - - valA = (ARTYPE*)A.nzval; - valE = (ARTYPE*)Aexp.nzval; - indA = (int*)A.rowind; - indE = (int*)Aexp.rowind; - colA = (int*)A.colptr; - colE = (int*)Aexp.colptr; - - // Filling colE with zeros. - - for (i=0; i<=this->n; i++) colE[i] = 0; - - // Counting the elements in each column of A. - - if (uplo == 'U') { - - for (i=0; i!=this->n; i++) { - k = colA[i+1]; - if ((k!=colA[i])&&(indA[k-1]==i)) { - k--; - } - else { - if (subtract) colE[i]++; - } - for (j=colA[i]; j<k; j++) colE[indA[j]]++; - } - - } - else { // uplo == 'L' - - for (i=0; i!=this->n; i++) { - k = colA[i]; - if ((k!=colA[i+1])&&(indA[k]==i)) { - k++; - } - else { - if (subtract) colE[i]++; - } - for (j=k; j<colA[i+1]; j++) colE[indA[j]]++; - } - - } - - // Summing up colE elements. - - for (i=0; i<this->n; i++) colE[i+1]+=colE[i]; - - // Adding colA to colE. - - for (i=this->n; i>0; i--) colE[i] = colE[i-1]+colA[i]; - colE[0] = colA[0]; - - // Expanding A. - - if (uplo == 'U') { - - for (i=0; i<this->n; i++) { - for (j=colA[i]; j<(colA[i+1]-1); j++) { - indE[colE[i]] = indA[j]; - indE[colE[indA[j]]] = i; - valE[colE[i]++] = valA[j]; - valE[colE[indA[j]]++] = valA[j]; - } - if ((colA[i]!=colA[i+1])&&(indA[j]==i)) { - indE[colE[i]] = i; - if (subtract) { - valE[colE[i]++] = valA[j]-sigma; - } - else { - valE[colE[i]++] = valA[j]; - } - } - else { - if (subtract) { - indE[colE[i]] = i; - valE[colE[i]++] = -sigma; - } - } - } - - } - else { // uplo == 'L' - - for (i=0; i<this->n; i++) { - k=colA[i]; - if ((k!=colA[i+1])&&(indA[k]==i)) { - indE[colE[i]] = i; - if (subtract) { - valE[colE[i]++] = valA[k]-sigma; - } - else { - valE[colE[i]++] = valA[k]; - } - k++; - } - else { - if (subtract) { - indE[colE[i]] = i; - valE[colE[i]++] = -sigma; - } - } - for (j=k; j<colA[i+1]; j++) { - indE[colE[i]] = indA[j]; - indE[colE[indA[j]]] = i; - valE[colE[i]++] = valA[j]; - valE[colE[indA[j]]++] = valA[j]; - } - } - - } - - // Adjusting index. - - for (i=this->n; i>0; i--) { - colE[i] = colE[i-1]; - } - colE[0] = 0; - - Aexp.nnz = colE[this->n]; - -} // ExpandA. - - -template<class ARTYPE> -void ARluSymMatrix<ARTYPE>::FactorA() -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARluSymMatrix::FactorA"); - } - - // Defining local variables. - - int info; - int* etree; - int* irowi; - int* pcoli; - ARTYPE* aexp; - SuperMatrix Aexp; - SuperMatrix AC; - NCformat* Astore; - NCformat* Aexpstore; - - // Deleting previous versions of L and U. - - if (factored) { - Destroy_SuperNode_Matrix(&L); - Destroy_CompCol_Matrix(&U); - StatFree(&stat); - } - - // Setting default values for gstrf parameters. - - int panel_size = sp_ienv(1); - int relax = sp_ienv(2); - superlu_options_t options; - - /* Set the default input options: - options.Fact = DOFACT; - options.Equil = YES; - options.ColPerm = COLAMD; - options.DiagPivotThresh = 1.0; - options.Trans = NOTRANS; - options.IterRefine = NOREFINE; - options.SymmetricMode = NO; - options.PivotGrowth = NO; - options.ConditionNumber = NO; - options.PrintStat = YES; - */ - set_default_options(&options); - - /* Now we modify the default options to use the symmetric mode. */ - options.SymmetricMode = YES; - options.ColPerm = MMD_AT_PLUS_A; - // options.DiagPivotThresh = 0.001; - options.DiagPivotThresh = threshold; - - // Creating a temporary matrix Aexp. - - irowi = (int*)SUPERLU_MALLOC(sizeof(int) * (nnz*2)); - pcoli = (int*)SUPERLU_MALLOC(sizeof(int) * (this->n+1)); - aexp = (ARTYPE*)SUPERLU_MALLOC(sizeof(ARTYPE) * (nnz*2)); - Create_CompCol_Matrix(&Aexp, this->n, this->n, nnz, aexp, irowi, pcoli, SLU_NC, SLU_GE); - - // Expanding A. - - Astore = (NCformat*)A.Store; - Aexpstore = (NCformat*)Aexp.Store; - ExpandA(*Astore, *Aexpstore); - - // Reserving memory for etree (used in matrix decomposition). - - etree = new int[this->n]; - - // Defining LUStat. - - //StatInit(panel_size, relax); - StatInit(&stat); - - // Defining the column permutation of matrix A - // (using minimum degree ordering). - - get_perm_c(order, &Aexp, permc); - - // Permuting columns of A and creating the elimination tree. - - //sp_preorder("N", &Aexp, permc, etree, &AC); - sp_preorder(&options, &Aexp, permc, etree, &AC); - - // Decomposing A. - -// gstrf("N",&AC, threshold, drop_tol, relax, panel_size, etree, -// NULL, 0, permr, permc, &L, &U, &info); - gstrf(&options,&AC, relax, panel_size, etree, - NULL, 0, permc, permr, &L, &U, &stat, &info); - - // Deleting AC, Aexp and etree. - - Destroy_CompCol_Permuted(&AC); - Destroy_CompCol_Matrix(&Aexp); - delete[] etree; - - factored = (info == 0); - - // Handling errors. - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARluSymMatrix::FactorA"); - } - else if (info > this->n) { // Memory is not sufficient. - throw ArpackError(ArpackError::MEMORY_OVERFLOW, - "ARluSymMatrix::FactorA"); - } - else if (info > 0) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARluSymMatrix::FactorA"); - } - -} // FactorA. - - -template<class ARTYPE> -void ARluSymMatrix<ARTYPE>::FactorAsI(ARTYPE sigma) -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARluSymMatrix::FactorAsI"); - } - - // Defining local variables. - - int info; - int* etree; - int* irowi; - int* pcoli; - ARTYPE* asi; - SuperMatrix AsI; - SuperMatrix AC; - NCformat* Astore; - NCformat* AsIstore; - - // Deleting previous versions of L and U. - - if (factored) { - Destroy_SuperNode_Matrix(&L); - Destroy_CompCol_Matrix(&U); - StatFree(&stat); - } - - // Setting default values for gstrf parameters. - - int panel_size = sp_ienv(1); - int relax = sp_ienv(2); - superlu_options_t options; - - /* Set the default input options: - options.Fact = DOFACT; - options.Equil = YES; - options.ColPerm = COLAMD; - options.DiagPivotThresh = 1.0; - options.Trans = NOTRANS; - options.IterRefine = NOREFINE; - options.SymmetricMode = NO; - options.PivotGrowth = NO; - options.ConditionNumber = NO; - options.PrintStat = YES; - */ - set_default_options(&options); - - /* Now we modify the default options to use the symmetric mode. */ - options.SymmetricMode = YES; - options.ColPerm = MMD_AT_PLUS_A; - // options.DiagPivotThresh = 0.001; - options.DiagPivotThresh = threshold; - - // Creating a temporary matrix AsI. - - irowi = (int*)SUPERLU_MALLOC(sizeof(int) * (nnz*2+this->n)); - pcoli = (int*)SUPERLU_MALLOC(sizeof(int) * (this->n+1)); - asi = (ARTYPE*)SUPERLU_MALLOC(sizeof(ARTYPE) * (nnz*2+this->n)); - Create_CompCol_Matrix(&AsI, this->n, this->n, nnz, asi, irowi, pcoli, SLU_NC, SLU_GE); - - // Subtracting sigma*I from A and storing the result on AsI. - - Astore = (NCformat*)A.Store; - AsIstore = (NCformat*)AsI.Store; - ExpandA(*Astore, *AsIstore, sigma); - - // Reserving memory for etree (used in matrix decomposition). - - etree = new int[this->n]; - - // Defining LUStat. - - //StatInit(panel_size, relax); - StatInit(&stat); - - // Defining the column permutation of matrix AsI - // (using minimum degree ordering). - - get_perm_c(order, &AsI, permc); - - // Permuting columns of AsI and creating the elimination tree. - - sp_preorder(&options, &AsI, permc, etree, &AC); - - // Decomposing AsI. - -// gstrf("N",&AC, threshold, drop_tol, relax, panel_size, etree, -// NULL, 0, permr, permc, &L, &U, &info); - gstrf(&options,&AC, relax, panel_size, etree, - NULL, 0, permc, permr, &L, &U, &stat, &info); - - // Deleting AC, AsI and etree. - - Destroy_CompCol_Permuted(&AC); - Destroy_CompCol_Matrix(&AsI); - delete[] etree; - - factored = (info == 0); - - // Handling errors. - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARluSymMatrix::FactorAsI"); - } - else if (info > this->n) { // Memory is not sufficient. - throw ArpackError(ArpackError::MEMORY_OVERFLOW, - "ARluSymMatrix::FactorAsI"); - } - else if (info > 0) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARluSymMatrix::FactorAsI"); - } - -} // FactorAsI. - - -template<class ARTYPE> -void ARluSymMatrix<ARTYPE>::MultMv(ARTYPE* v, ARTYPE* w) -{ - - int i, j, k; - ARTYPE t; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARluSymMatrix::MultMv"); - } - - // Determining w = M.v. - - for (i=0; i!=this->m; i++) w[i]=(ARTYPE)0; - - if (uplo == 'U') { - - for (i=0; i!=this->n; i++) { - t = v[i]; - k = pcol[i+1]; - if ((k!=pcol[i])&&(irow[k-1]==i)) { - w[i] += t*a[k-1]; - k--; - } - for (j=pcol[i]; j<k; j++) { - w[irow[j]] += t*a[j]; - w[i] += v[irow[j]]*a[j]; - } - } - - } - else { - - for (i=0; i!=this->n; i++) { - t = v[i]; - k = pcol[i]; - if ((k!=pcol[i+1])&&(irow[k]==i)) { - w[i] += t*a[k]; - k++; - } - for (j=k; j<pcol[i+1]; j++) { - w[irow[j]] += t*a[j]; - w[i] += v[irow[j]]*a[j]; - } - } - - } - -} // MultMv. - - -template<class ARTYPE> -void ARluSymMatrix<ARTYPE>::MultInvv(ARTYPE* v, ARTYPE* w) -{ - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARluSymMatrix::MultInvv"); - } - - // Solving A.w = v (or AsI.w = v). - - int info; - SuperMatrix B; - - if (&v != &w) copy(this->n, v, 1, w, 1); - Create_Dense_Matrix(&B, this->n, 1, w, this->n, SLU_DN, SLU_GE); -// gstrs("N", &L, &U, permr, permc, &B, &info); - StatInit(&stat); - trans_t trans = NOTRANS; - gstrs(trans, &L, &U, permc, permr, &B, &stat, &info); - Destroy_SuperMatrix_Store(&B); // delete B.Store; - -} // MultInvv. - - -template<class ARTYPE> -inline void ARluSymMatrix<ARTYPE>:: -DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, int* pcolp, - char uplop, double thresholdp, int orderp, bool check) -{ - - this->m = np; - this->n = np; - nnz = nnzp; - a = ap; - irow = irowp; - pcol = pcolp; - pcol[this->n] = nnz; - uplo = uplop; - threshold = thresholdp; - order = orderp; - - // Checking data. - - if ((check)&&(!DataOK())) { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARluSymMatrix::DefineMatrix"); - } - - // Creating SuperMatrix A. - - Create_CompCol_Matrix(&A, this->n, this->n, nnz, a, irow, pcol, SLU_NC, SLU_GE); - - // Reserving memory for vectors used in matrix decomposition. - - permc = new int[this->n]; - permr = new int[this->n]; - - this->defined = true; - -} // DefineMatrix. - - -template<class ARTYPE> -inline ARluSymMatrix<ARTYPE>::ARluSymMatrix(): ARMatrix<ARTYPE>() -{ - - factored = false; - permc = NULL; - permr = NULL; - -} // Short constructor. - - -template<class ARTYPE> -inline ARluSymMatrix<ARTYPE>:: -ARluSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, char uplop, double thresholdp, - int orderp, bool check) : ARMatrix<ARTYPE>(np) -{ - - factored = false; - DefineMatrix(np, nnzp, ap, irowp, pcolp, uplop, thresholdp, orderp, check); - -} // Long constructor. - - -template<class ARTYPE> -ARluSymMatrix<ARTYPE>:: -ARluSymMatrix(const std::string& file, double thresholdp, int orderp, bool check) -{ - - factored = false; - - try { - mat.Define(file); - } - catch (ArpackError) { // Returning from here if an error has occurred. - throw ArpackError(ArpackError::CANNOT_READ_FILE, "ARluSymMatrix"); - } - - if ((mat.NCols() == mat.NRows()) && (mat.IsSymmetric())) { - - DefineMatrix(mat.NCols(), mat.NonZeros(), (ARTYPE*)mat.Entries(), - mat.RowInd(), mat.ColPtr(), 'L', thresholdp, orderp, check); - } - else { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARluSymMatrix::ARluSymMatrix"); - } - -} // Long constructor (Harwell-Boeing file). - - -template<class ARTYPE> -ARluSymMatrix<ARTYPE>& ARluSymMatrix<ARTYPE>:: -operator=(const ARluSymMatrix<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLSMAT_H diff --git a/src/external/arpack++/include/arlsnsym.h b/src/external/arpack++/include/arlsnsym.h deleted file mode 100644 index e6369ada..00000000 --- a/src/external/arpack++/include/arlsnsym.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLSNSym.h. - Arpack++ class ARluNonSymStdEig definition - (SuperLU version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARLSNSYM_H -#define ARLSNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arsnsym.h" -#include "arlnsmat.h" - -template<class ARFLOAT> -class ARluNonSymStdEig: - public virtual ARNonSymStdEig<ARFLOAT, ARluNonSymMatrix<ARFLOAT, ARFLOAT> > { - - protected: - - // a) Protected function: - - virtual void Copy(const ARluNonSymStdEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // b) Public functions: - - // b.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // b.2) Constructors and destructor. - - ARluNonSymStdEig() { } - // Short constructor. - - ARluNonSymStdEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluNonSymStdEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluNonSymStdEig(const ARluNonSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymStdEig() { } - // Destructor. - - // c) Operators. - - ARluNonSymStdEig& operator=(const ARluNonSymStdEig& other); - // Assignment operator. - -}; // class ARluNonSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluNonSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>:: -Copy(const ARluNonSymStdEig<ARFLOAT>& other) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARluNonSymMatrix<ARFLOAT, ARFLOAT> >:: Copy(other); - if (this->mode > 2) this->objOP->FactorAsI(this->sigmaR); - -} // Copy. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI(this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARluNonSymMatrix<ARFLOAT, ARFLOAT> >:: - SetRegularMode(this->objOP, &ARluNonSymMatrix<ARFLOAT, ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARluNonSymMatrix<ARFLOAT, ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, - &ARluNonSymMatrix<ARFLOAT, ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluNonSymStdEig<ARFLOAT>:: -ARluNonSymStdEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, - &ARluNonSymMatrix<ARFLOAT, ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluNonSymStdEig<ARFLOAT>:: -ARluNonSymStdEig(int nevp, ARluNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, - &ARluNonSymMatrix<ARFLOAT, ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluNonSymStdEig<ARFLOAT>& ARluNonSymStdEig<ARFLOAT>:: -operator=(const ARluNonSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLSNSYM_H diff --git a/src/external/arpack++/include/arlspdef.h b/src/external/arpack++/include/arlspdef.h deleted file mode 100644 index 3dec1cc7..00000000 --- a/src/external/arpack++/include/arlspdef.h +++ /dev/null @@ -1,610 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLSpDef.h. - ALTERED version of slu_sdefs.h slu_ddefs.h slu_cdefs.h slu_zdefs.h - (from SuperLU 3.0 package). -*/ - - -#ifndef __SUPERLU_SP_DEFS /* allow multiple inclusions */ -#define __SUPERLU_SP_DEFS - -/* - * File name: sp_defs.h - * Purpose: Sparse matrix types and function prototypes - * History: - */ -#include "arlnames.h" -#include "arlsupm.h" -#include "arlcomp.h" -#include "arlutil.h" -#ifdef _CRAY -#include <fortran.h> -#include <string.h> -#endif - -/* Define my integer type int_t */ -typedef int int_t; /* default */ - -// /* No of marker arrays used in the symbolic factorization, -// each of size n */ -// #define NO_MARKER 3 -// #define NUM_TEMPV(m,w,t,b) ( MAX(m, (t + b)*w) ) -// -// typedef enum {LUSUP, UCOL, LSUB, USUB} MemType; -// typedef enum {HEAD, TAIL} stack_end_t; -// typedef enum {SYSTEM, USER} LU_space_t; - -/* - * Global data structures used in LU factorization - - * - * nsuper: #supernodes = nsuper + 1, numbered [0, nsuper]. - * (xsup,supno): supno[i] is the supernode no to which i belongs; - * xsup(s) points to the beginning of the s-th supernode. - * e.g. supno 0 1 2 2 3 3 3 4 4 4 4 4 (n=12) - * xsup 0 1 2 4 7 12 - * Note: dfs will be performed on supernode rep. relative to the new - * row pivoting ordering - * - * (xlsub,lsub): lsub[*] contains the compressed subscript of - * rectangular supernodes; xlsub[j] points to the starting - * location of the j-th column in lsub[*]. Note that xlsub - * is indexed by column. - * Storage: original row subscripts - * - * During the course of sparse LU factorization, we also use - * (xlsub,lsub) for the purpose of symmetric pruning. For each - * supernode {s,s+1,...,t=s+r} with first column s and last - * column t, the subscript set - * lsub[j], j=xlsub[s], .., xlsub[s+1]-1 - * is the structure of column s (i.e. structure of this supernode). - * It is used for the storage of numerical values. - * Furthermore, - * lsub[j], j=xlsub[t], .., xlsub[t+1]-1 - * is the structure of the last column t of this supernode. - * It is for the purpose of symmetric pruning. Therefore, the - * structural subscripts can be rearranged without making physical - * interchanges among the numerical values. - * - * However, if the supernode has only one column, then we - * only keep one set of subscripts. For any subscript interchange - * performed, similar interchange must be done on the numerical - * values. - * - * The last column structures (for pruning) will be removed - * after the numercial LU factorization phase. - * - * (xlusup,lusup): lusup[*] contains the numerical values of the - * rectangular supernodes; xlusup[j] points to the starting - * location of the j-th column in storage vector lusup[*] - * Note: xlusup is indexed by column. - * Each rectangular supernode is stored by column-major - * scheme, consistent with Fortran 2-dim array storage. - * - * (xusub,ucol,usub): ucol[*] stores the numerical values of - * U-columns outside the rectangular supernodes. The row - * subscript of nonzero ucol[k] is stored in usub[k]. - * xusub[i] points to the starting location of column i in ucol. - * Storage: new row subscripts; that is subscripts of PA. - */ - -typedef struct { - int *xsup; /* supernode and column mapping */ - int *supno; - int *lsub; /* compressed L subscripts */ - int *xlsub; - float *lusup; /* L supernodes */ - int *xlusup; - float *ucol; /* U columns */ - int *usub; - int *xusub; - int nzlmax; /* current max size of lsub */ - int nzumax; /* " " " ucol */ - int nzlumax; /* " " " lusup */ - int n; /* number of columns in the matrix */ - LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */ - int num_expansions; - ExpHeader *expanders; /* Array of pointers to 4 types of memory */ - LU_stack_t stack; /* use user supplied memory */ -} sGlobalLU_t; - -typedef struct { - int *xsup; /* supernode and column mapping */ - int *supno; - int *lsub; /* compressed L subscripts */ - int *xlsub; - double *lusup; /* L supernodes */ - int *xlusup; - double *ucol; /* U columns */ - int *usub; - int *xusub; - int nzlmax; /* current max size of lsub */ - int nzumax; /* " " " ucol */ - int nzlumax; /* " " " lusup */ - int n; /* number of columns in the matrix */ - LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */ - int num_expansions; - ExpHeader *expanders; /* Array of pointers to 4 types of memory */ - LU_stack_t stack; /* use user supplied memory */ -} dGlobalLU_t; - -typedef struct { - int *xsup; /* supernode and column mapping */ - int *supno; - int *lsub; /* compressed L subscripts */ - int *xlsub; - lscomplex *lusup; /* L supernodes */ - int *xlusup; - lscomplex *ucol; /* U columns */ - int *usub; - int *xusub; - int nzlmax; /* current max size of lsub */ - int nzumax; /* " " " ucol */ - int nzlumax; /* " " " lusup */ - int n; /* number of columns in the matrix */ - LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */ - int num_expansions; - ExpHeader *expanders; /* Array of pointers to 4 types of memory */ - LU_stack_t stack; /* use user supplied memory */ -} cGlobalLU_t; - -typedef struct { - int *xsup; /* supernode and column mapping */ - int *supno; - int *lsub; /* compressed L subscripts */ - int *xlsub; - ldcomplex *lusup; /* L supernodes */ - int *xlusup; - ldcomplex *ucol; /* U columns */ - int *usub; - int *xusub; - int nzlmax; /* current max size of lsub */ - int nzumax; /* " " " ucol */ - int nzlumax; /* " " " lusup */ - int n; /* number of columns in the matrix */ - LU_space_t MemModel; /* 0 - system malloc'd; 1 - user provided */ - int num_expansions; - ExpHeader *expanders; /* Array of pointers to 4 types of memory */ - LU_stack_t stack; /* use user supplied memory */ -} zGlobalLU_t; - -// typedef struct { -// int panel_size; -// int relax; -// float diag_pivot_thresh; -// float drop_tol; -// } sfactor_param_t; -// -// typedef struct { -// int panel_size; -// int relax; -// double diag_pivot_thresh; -// double drop_tol; -// } dfactor_param_t; -// -//typedef struct { -// float for_lu; -// float total_needed; -// int expansions; -//} mem_usage_t; - -#ifdef __cplusplus -extern "C" { -#endif - -/* Driver routines */ -extern void -sgssv(superlu_options_t *, SuperMatrix *, int *, int *, SuperMatrix *, - SuperMatrix *, SuperMatrix *, SuperLUStat_t *, int *); -extern void -dgssv(superlu_options_t *, SuperMatrix *, int *, int *, SuperMatrix *, - SuperMatrix *, SuperMatrix *, SuperLUStat_t *, int *); -extern void -cgssv(superlu_options_t *, SuperMatrix *, int *, int *, SuperMatrix *, - SuperMatrix *, SuperMatrix *, SuperLUStat_t *, int *); -extern void -zgssv(superlu_options_t *, SuperMatrix *, int *, int *, SuperMatrix *, - SuperMatrix *, SuperMatrix *, SuperLUStat_t *, int *); -extern void -sgssvx(superlu_options_t *, SuperMatrix *, int *, int *, int *, - char *, float *, float *, SuperMatrix *, SuperMatrix *, - void *, int, SuperMatrix *, SuperMatrix *, - float *, float *, float *, float *, - sGlobalLU_t *, mem_usage_t *, SuperLUStat_t *, int *); -extern void -dgssvx(superlu_options_t *, SuperMatrix *, int *, int *, int *, - char *, double *, double *, SuperMatrix *, SuperMatrix *, - void *, int, SuperMatrix *, SuperMatrix *, - double *, double *, double *, double *, - dGlobalLU_t *, mem_usage_t *, SuperLUStat_t *, int *); -extern void -cgssvx(superlu_options_t *, SuperMatrix *, int *, int *, int *, - char *, float *, float *, SuperMatrix *, SuperMatrix *, - void *, int, SuperMatrix *, SuperMatrix *, - float *, float *, float *, float *, - cGlobalLU_t *, mem_usage_t *, SuperLUStat_t *, int *); -extern void -zgssvx(superlu_options_t *, SuperMatrix *, int *, int *, int *, - char *, double *, double *, SuperMatrix *, SuperMatrix *, - void *, int, SuperMatrix *, SuperMatrix *, - double *, double *, double *, double *, - zGlobalLU_t *, mem_usage_t *, SuperLUStat_t *, int *); - -/* Supernodal LU factor related */ -extern void -sCreate_CompCol_Matrix(SuperMatrix *, int, int, int, float *, - int *, int *, Stype_t, Dtype_t, Mtype_t); -extern void -dCreate_CompCol_Matrix(SuperMatrix *, int, int, int, double *, - int *, int *, Stype_t, Dtype_t, Mtype_t); -extern void -cCreate_CompCol_Matrix(SuperMatrix *, int, int, int, lscomplex *, - int *, int *, Stype_t, Dtype_t, Mtype_t); -extern void -zCreate_CompCol_Matrix(SuperMatrix *, int, int, int, ldcomplex *, - int *, int *, Stype_t, Dtype_t, Mtype_t); -extern void -sCreate_CompRow_Matrix(SuperMatrix *, int, int, int, float *, - int *, int *, Stype_t, Dtype_t, Mtype_t); -extern void -dCreate_CompRow_Matrix(SuperMatrix *, int, int, int, double *, - int *, int *, Stype_t, Dtype_t, Mtype_t); -extern void -cCreate_CompRow_Matrix(SuperMatrix *, int, int, int, lscomplex *, - int *, int *, Stype_t, Dtype_t, Mtype_t); -extern void -zCreate_CompRow_Matrix(SuperMatrix *, int, int, int, ldcomplex *, - int *, int *, Stype_t, Dtype_t, Mtype_t); -extern void -sCopy_CompCol_Matrix(SuperMatrix *, SuperMatrix *); -extern void -dCopy_CompCol_Matrix(SuperMatrix *, SuperMatrix *); -extern void -cCopy_CompCol_Matrix(SuperMatrix *, SuperMatrix *); -extern void -zCopy_CompCol_Matrix(SuperMatrix *, SuperMatrix *); -extern void -sCreate_Dense_Matrix(SuperMatrix *, int, int, float *, int, - Stype_t, Dtype_t, Mtype_t); -extern void -dCreate_Dense_Matrix(SuperMatrix *, int, int, double *, int, - Stype_t, Dtype_t, Mtype_t); -extern void -cCreate_Dense_Matrix(SuperMatrix *, int, int, lscomplex *, int, - Stype_t, Dtype_t, Mtype_t); -extern void -zCreate_Dense_Matrix(SuperMatrix *, int, int, ldcomplex *, int, - Stype_t, Dtype_t, Mtype_t); -extern void -sCreate_SuperNode_Matrix(SuperMatrix *, int, int, int, float *, - int *, int *, int *, int *, int *, - Stype_t, Dtype_t, Mtype_t); -extern void -dCreate_SuperNode_Matrix(SuperMatrix *, int, int, int, double *, - int *, int *, int *, int *, int *, - Stype_t, Dtype_t, Mtype_t); -extern void -cCreate_SuperNode_Matrix(SuperMatrix *, int, int, int, lscomplex *, - int *, int *, int *, int *, int *, - Stype_t, Dtype_t, Mtype_t); -extern void -zCreate_SuperNode_Matrix(SuperMatrix *, int, int, int, ldcomplex *, - int *, int *, int *, int *, int *, - Stype_t, Dtype_t, Mtype_t); -extern void -sCopy_Dense_Matrix(int, int, float *, int, float *, int); -extern void -dCopy_Dense_Matrix(int, int, double *, int, double *, int); -extern void -cCopy_Dense_Matrix(int, int, lscomplex *, int, lscomplex *, int); -extern void -zCopy_Dense_Matrix(int, int, ldcomplex *, int, ldcomplex *, int); - -// extern void Destroy_SuperMatrix_Store(SuperMatrix *); -// extern void Destroy_CompCol_Matrix(SuperMatrix *); -// extern void Destroy_SuperNode_Matrix(SuperMatrix *); -// extern void Destroy_CompCol_Permuted(SuperMatrix *); -// extern void Destroy_Dense_Matrix(SuperMatrix *); -// extern void get_perm_c(int, SuperMatrix *, int *); -// extern void sp_preorder (char*, SuperMatrix*, int*, int*, SuperMatrix*); -// // extern void countnz (const int, int *, int *, int *, sGlobalLU_t *); -// // extern void fixupL (const int, const int *, sGlobalLU_t *); - -extern void sallocateA (int, int, float **, int **, int **); -extern void dallocateA (int, int, double **, int **, int **); -extern void callocateA (int, int, lscomplex **, int **, int **); -extern void zallocateA (int, int, ldcomplex **, int **, int **); -extern void sgstrf (superlu_options_t*, SuperMatrix*, - int, int, int*, void *, int, int *, int *, - SuperMatrix *, SuperMatrix *, sGlobalLU_t *, SuperLUStat_t*, int *); -extern void dgstrf (superlu_options_t*, SuperMatrix*, - int, int, int*, void *, int, int *, int *, - SuperMatrix *, SuperMatrix *, dGlobalLU_t *, SuperLUStat_t*, int *); -extern void cgstrf (superlu_options_t*, SuperMatrix*, - int, int, int*, void *, int, int *, int *, - SuperMatrix *, SuperMatrix *, cGlobalLU_t *, SuperLUStat_t*, int *); -extern void zgstrf (superlu_options_t*, SuperMatrix*, - int, int, int*, void *, int, int *, int *, - SuperMatrix *, SuperMatrix *, zGlobalLU_t *, SuperLUStat_t*, int *); -extern int ssnode_dfs (const int, const int, const int *, const int *, - const int *, int *, int *, sGlobalLU_t *); -extern int dsnode_dfs (const int, const int, const int *, const int *, - const int *, int *, int *, dGlobalLU_t *); -extern int csnode_dfs (const int, const int, const int *, const int *, - const int *, int *, int *, cGlobalLU_t *); -extern int zsnode_dfs (const int, const int, const int *, const int *, - const int *, int *, int *, zGlobalLU_t *); -extern int ssnode_bmod (const int, const int, const int, float *, - float *, sGlobalLU_t *, SuperLUStat_t*); -extern int dsnode_bmod (const int, const int, const int, double *, - double *, dGlobalLU_t *, SuperLUStat_t*); -extern int csnode_bmod (const int, const int, const int, lscomplex *, - lscomplex *, cGlobalLU_t *, SuperLUStat_t*); -extern int zsnode_bmod (const int, const int, const int, ldcomplex *, - ldcomplex *, zGlobalLU_t *, SuperLUStat_t*); -extern void spanel_dfs (const int, const int, const int, SuperMatrix *, - int *, int *, float *, int *, int *, int *, - int *, int *, int *, int *, sGlobalLU_t *); -extern void dpanel_dfs (const int, const int, const int, SuperMatrix *, - int *, int *, double *, int *, int *, int *, - int *, int *, int *, int *, dGlobalLU_t *); -extern void cpanel_dfs (const int, const int, const int, SuperMatrix *, - int *, int *, lscomplex *, int *, int *, int *, - int *, int *, int *, int *, cGlobalLU_t *); -extern void zpanel_dfs (const int, const int, const int, SuperMatrix *, - int *, int *, ldcomplex *, int *, int *, int *, - int *, int *, int *, int *, zGlobalLU_t *); -extern void spanel_bmod (const int, const int, const int, const int, - float *, float *, int *, int *, - sGlobalLU_t *, SuperLUStat_t*); -extern void dpanel_bmod (const int, const int, const int, const int, - double *, double *, int *, int *, - dGlobalLU_t *, SuperLUStat_t*); -extern void cpanel_bmod (const int, const int, const int, const int, - lscomplex *, lscomplex *, int *, int *, - cGlobalLU_t *, SuperLUStat_t*); -extern void zpanel_bmod (const int, const int, const int, const int, - ldcomplex *, ldcomplex *, int *, int *, - zGlobalLU_t *, SuperLUStat_t*); -extern int scolumn_dfs (const int, const int, int *, int *, int *, int *, - int *, int *, int *, int *, int *, sGlobalLU_t *); -extern int dcolumn_dfs (const int, const int, int *, int *, int *, int *, - int *, int *, int *, int *, int *, dGlobalLU_t *); -extern int ccolumn_dfs (const int, const int, int *, int *, int *, int *, - int *, int *, int *, int *, int *, cGlobalLU_t *); -extern int zcolumn_dfs (const int, const int, int *, int *, int *, int *, - int *, int *, int *, int *, int *, zGlobalLU_t *); -extern int scolumn_bmod (const int, const int, float *, - float *, int *, int *, int, sGlobalLU_t *, SuperLUStat_t*); -extern int dcolumn_bmod (const int, const int, double *, - double *, int *, int *, int, dGlobalLU_t *, SuperLUStat_t*); -extern int ccolumn_bmod (const int, const int, lscomplex *, - lscomplex *, int *, int *, int, cGlobalLU_t *, SuperLUStat_t*); -extern int zcolumn_bmod (const int, const int, ldcomplex *, - ldcomplex *, int *, int *, int, zGlobalLU_t *, SuperLUStat_t*); -extern int scopy_to_ucol (int, int, int *, int *, int *, - float *, sGlobalLU_t *); -extern int dcopy_to_ucol (int, int, int *, int *, int *, - double *, dGlobalLU_t *); -extern int ccopy_to_ucol (int, int, int *, int *, int *, - lscomplex *, cGlobalLU_t *); -extern int zcopy_to_ucol (int, int, int *, int *, int *, - ldcomplex *, zGlobalLU_t *); -extern int spivotL (const int, const float, int *, int *, - int *, int *, int *, sGlobalLU_t *, SuperLUStat_t*); -extern int dpivotL (const int, const double, int *, int *, - int *, int *, int *, dGlobalLU_t *, SuperLUStat_t*); -extern int cpivotL (const int, const float, int *, int *, - int *, int *, int *, cGlobalLU_t *, SuperLUStat_t*); -extern int zpivotL (const int, const double, int *, int *, - int *, int *, int *, zGlobalLU_t *, SuperLUStat_t*); -extern void spruneL (const int, const int *, const int, const int, - const int *, const int *, int *, sGlobalLU_t *); -extern void dpruneL (const int, const int *, const int, const int, - const int *, const int *, int *, dGlobalLU_t *); -extern void cpruneL (const int, const int *, const int, const int, - const int *, const int *, int *, cGlobalLU_t *); -extern void zpruneL (const int, const int *, const int, const int, - const int *, const int *, int *, zGlobalLU_t *); -extern void sreadmt (int *, int *, int *, float **, int **, int **); -extern void dreadmt (int *, int *, int *, double **, int **, int **); -extern void creadmt (int *, int *, int *, lscomplex **, int **, int **); -extern void zreadmt (int *, int *, int *, ldcomplex **, int **, int **); -extern void sGenXtrue (int, int, float *, int); -extern void dGenXtrue (int, int, double *, int); -extern void cGenXtrue (int, int, lscomplex *, int); -extern void zGenXtrue (int, int, ldcomplex *, int); -extern void sFillRHS (trans_t, int, float *, int, SuperMatrix *, - SuperMatrix *); -extern void dFillRHS (trans_t, int, double *, int, SuperMatrix *, - SuperMatrix *); -extern void cFillRHS (trans_t, int, lscomplex *, int, SuperMatrix *, - SuperMatrix *); -extern void zFillRHS (trans_t, int, ldcomplex *, int, SuperMatrix *, - SuperMatrix *); -extern void sgstrs (trans_t, SuperMatrix *, SuperMatrix *, int *, int *, - SuperMatrix *, SuperLUStat_t*, int *); -extern void dgstrs (trans_t, SuperMatrix *, SuperMatrix *, int *, int *, - SuperMatrix *, SuperLUStat_t*, int *); -extern void cgstrs (trans_t, SuperMatrix *, SuperMatrix *, int *, int *, - SuperMatrix *, SuperLUStat_t*, int *); -extern void zgstrs (trans_t, SuperMatrix *, SuperMatrix *, int *, int *, - SuperMatrix *, SuperLUStat_t*, int *); - - -/* Driver related */ - -extern void sgsequ (SuperMatrix *, float *, float *, float *, - float *, float *, int *); -extern void dgsequ (SuperMatrix *, double *, double *, double *, - double *, double *, int *); -extern void cgsequ (SuperMatrix *, float *, float *, float *, - float *, float *, int *); -extern void zgsequ (SuperMatrix *, double *, double *, double *, - double *, double *, int *); -extern void slaqgs (SuperMatrix *, float *, float *, float, - float, float, char *); -extern void dlaqgs (SuperMatrix *, double *, double *, double, - double, double, char *); -extern void claqgs (SuperMatrix *, float *, float *, float, - float, float, char *); -extern void zlaqgs (SuperMatrix *, double *, double *, double, - double, double, char *); -extern void sgscon (char *, SuperMatrix *, SuperMatrix *, - float, float *, SuperLUStat_t*, int *); -extern void dgscon (char *, SuperMatrix *, SuperMatrix *, - double, double *, SuperLUStat_t*, int *); -extern void cgscon (char *, SuperMatrix *, SuperMatrix *, - float, float *, SuperLUStat_t*, int *); -extern void zgscon (char *, SuperMatrix *, SuperMatrix *, - double, double *, SuperLUStat_t*, int *); - -extern float sPivotGrowth(int, SuperMatrix *, int *, - SuperMatrix *, SuperMatrix *); -extern double dPivotGrowth(int, SuperMatrix *, int *, - SuperMatrix *, SuperMatrix *); -extern float cPivotGrowth(int, SuperMatrix *, int *, - SuperMatrix *, SuperMatrix *); -extern double zPivotGrowth(int, SuperMatrix *, int *, - SuperMatrix *, SuperMatrix *); -extern void sgsrfs (trans_t, SuperMatrix *, SuperMatrix *, - SuperMatrix *, int *, int *, char *, float *, - float *, SuperMatrix *, SuperMatrix *, - float *, float *, SuperLUStat_t*, int *); -extern void dgsrfs (trans_t, SuperMatrix *, SuperMatrix *, - SuperMatrix *, int *, int *, char *, double *, - double *, SuperMatrix *, SuperMatrix *, - double *, double *, SuperLUStat_t*, int *); -extern void cgsrfs (trans_t, SuperMatrix *, SuperMatrix *, - SuperMatrix *, int *, int *, char *, float *, - float *, SuperMatrix *, SuperMatrix *, - float *, float *, SuperLUStat_t*, int *); -extern void zgsrfs (trans_t, SuperMatrix *, SuperMatrix *, - SuperMatrix *, int *, int *, char *, double *, - double *, SuperMatrix *, SuperMatrix *, - double *, double *, SuperLUStat_t*, int *); - -extern int sp_strsv (char *, char *, char *, SuperMatrix *, - SuperMatrix *, float *, SuperLUStat_t*, int *); -extern int sp_dtrsv (char *, char *, char *, SuperMatrix *, - SuperMatrix *, double *, SuperLUStat_t*, int *); -extern int sp_ctrsv (char *, char *, char *, SuperMatrix *, - SuperMatrix *, lscomplex *, SuperLUStat_t*, int *); -extern int sp_ztrsv (char *, char *, char *, SuperMatrix *, - SuperMatrix *, ldcomplex *, SuperLUStat_t*, int *); -extern int sp_sgemv (char *, float, SuperMatrix *, float *, - int, float, float *, int); -extern int sp_dgemv (char *, double, SuperMatrix *, double *, - int, double, double *, int); -extern int sp_cgemv (char *, lscomplex, SuperMatrix *, lscomplex *, - int, lscomplex, lscomplex *, int); -extern int sp_zgemv (char *, ldcomplex, SuperMatrix *, ldcomplex *, - int, ldcomplex, ldcomplex *, int); - -extern int sp_sgemm (char *, char *, int, int, int, float, - SuperMatrix *, float *, int, float, - float *, int); -extern int sp_dgemm (char *, char *, int, int, int, double, - SuperMatrix *, double *, int, double, - double *, int); -extern int sp_cgemm (char *, char *, int, int, int, lscomplex, - SuperMatrix *, lscomplex *, int, lscomplex, - lscomplex *, int); -extern int sp_zgemm (char *, char *, int, int, int, ldcomplex, - SuperMatrix *, ldcomplex *, int, ldcomplex, - ldcomplex *, int); - -/* Memory-related */ -extern int sLUMemInit (fact_t, void *, int, int, int, int, int, - float, SuperMatrix *, SuperMatrix *, - sGlobalLU_t *, int **, float **); -extern int dLUMemInit (fact_t, void *, int, int, int, int, int, - double, SuperMatrix *, SuperMatrix *, - dGlobalLU_t *, int **, double **); -extern int cLUMemInit (fact_t, void *, int, int, int, int, int, - float, SuperMatrix *, SuperMatrix *, - cGlobalLU_t *, int **, lscomplex **); -extern int zLUMemInit (fact_t, void *, int, int, int, int, int, - double, SuperMatrix *, SuperMatrix *, - zGlobalLU_t *, int **, ldcomplex **); -extern void sSetRWork (int, int, float *, float **, float **); -extern void dSetRWork (int, int, double *, double **, double **); -extern void cSetRWork (int, int, lscomplex *, lscomplex **, lscomplex **); -extern void zSetRWork (int, int, ldcomplex *, ldcomplex **, ldcomplex **); -extern void sLUWorkFree (int *, float *, sGlobalLU_t *); -extern void dLUWorkFree (int *, double *, dGlobalLU_t *); -extern void cLUWorkFree (int *, lscomplex *, cGlobalLU_t *); -extern void zLUWorkFree (int *, ldcomplex *, zGlobalLU_t *); -extern int sLUMemXpand (int, int, MemType, int *, sGlobalLU_t *); -extern int dLUMemXpand (int, int, MemType, int *, dGlobalLU_t *); -extern int cLUMemXpand (int, int, MemType, int *, cGlobalLU_t *); -extern int zLUMemXpand (int, int, MemType, int *, zGlobalLU_t *); - -extern float *floatMalloc(int); -extern double *doubleMalloc(int); -extern lscomplex *complexMalloc(int); -extern ldcomplex *doublecomplexMalloc(int); -extern float *floatCalloc(int); -extern double *doubleCalloc(int); -extern lscomplex *complexCalloc(int); -extern ldcomplex *doublecomplexCalloc(int); -extern int smemory_usage(const int, const int, const int, const int); -extern int dmemory_usage(const int, const int, const int, const int); -extern int cmemory_usage(const int, const int, const int, const int); -extern int zmemory_usage(const int, const int, const int, const int); -extern int sQuerySpace (SuperMatrix *, SuperMatrix *, mem_usage_t *); -extern int dQuerySpace (SuperMatrix *, SuperMatrix *, mem_usage_t *); -extern int cQuerySpace (SuperMatrix *, SuperMatrix *, mem_usage_t *); -extern int zQuerySpace (SuperMatrix *, SuperMatrix *, mem_usage_t *); - -/* Auxiliary routines */ -extern void sreadhb(FILE *, int *, int *, int *, float **, int **, int **); -extern void dreadhb(FILE *, int *, int *, int *, double **, int **, int **); -extern void creadhb(FILE *, int *, int *, int *, lscomplex **, int **, int **); -extern void zreadhb(FILE *, int *, int *, int *, ldcomplex **, int **, int **); -extern void sCompRow_to_CompCol(int, int, int, float*, int*, int*, - float **, int **, int **); -extern void dCompRow_to_CompCol(int, int, int, double*, int*, int*, - double **, int **, int **); -extern void cCompRow_to_CompCol(int, int, int, lscomplex*, int*, int*, - lscomplex **, int **, int **); -extern void zCompRow_to_CompCol(int, int, int, ldcomplex*, int*, int*, - ldcomplex **, int **, int **); -extern void sfill (float *, int, float); -extern void dfill (double *, int, double); -extern void cfill (lscomplex *, int, lscomplex); -extern void zfill (ldcomplex *, int, ldcomplex); -extern void sinf_norm_error (int, SuperMatrix *, float *); -extern void dinf_norm_error (int, SuperMatrix *, double *); -extern void cinf_norm_error (int, SuperMatrix *, lscomplex *); -extern void zinf_norm_error (int, SuperMatrix *, ldcomplex *); -// extern void PrintPerf (SuperMatrix *, SuperMatrix *, mem_usage_t *, -// float, float, float *, float *, char *); - -/* Routines for debugging */ -extern void sPrint_CompCol_Matrix(char *, SuperMatrix *); -extern void dPrint_CompCol_Matrix(char *, SuperMatrix *); -extern void cPrint_CompCol_Matrix(char *, SuperMatrix *); -extern void zPrint_CompCol_Matrix(char *, SuperMatrix *); -extern void sPrint_SuperNode_Matrix(char *, SuperMatrix *); -extern void dPrint_SuperNode_Matrix(char *, SuperMatrix *); -extern void cPrint_SuperNode_Matrix(char *, SuperMatrix *); -extern void zPrint_SuperNode_Matrix(char *, SuperMatrix *); -extern void sPrint_Dense_Matrix(char *, SuperMatrix *); -extern void dPrint_Dense_Matrix(char *, SuperMatrix *); -extern void cPrint_Dense_Matrix(char *, SuperMatrix *); -extern void zPrint_Dense_Matrix(char *, SuperMatrix *); -// extern void print_lu_col(char *, int, int, int *, sGlobalLU_t *); -// extern void check_tempv(int, float *); - -/* Reordering routine */ - - -#ifdef __cplusplus - } -#endif - -#endif /* __SUPERLU_SP_DEFS */ - diff --git a/src/external/arpack++/include/arlspen.h b/src/external/arpack++/include/arlspen.h deleted file mode 100644 index 52e2bb1a..00000000 --- a/src/external/arpack++/include/arlspen.h +++ /dev/null @@ -1,679 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLSPen.h. - Arpack++ class ARluSymPencil definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARLSPEN_H -#define ARLSPEN_H - -#include <cstddef> - -#include "arch.h" -#include "arerror.h" -#include "blas1c.h" -#include "superluc.h" -#include "arlspdef.h" -#include "arlutil.h" -#include "arlsmat.h" - - -template<class ARTYPE> -class ARluSymPencil -{ - - protected: - - bool factored; - int* permc; - int* permr; - char part; - char uplo; - ARluSymMatrix<ARTYPE>* A; - ARluSymMatrix<ARTYPE>* B; - SuperMatrix L; - SuperMatrix U; - SuperLUStat_t stat; - - virtual void Copy(const ARluSymPencil& other); - - void ClearMem(); - - void SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], - int yind[], int ny, ARTYPE z[], int zind[], int& nz); - - void ExpandAsB(int n, NCformat& AsB); - - void SubtractAsB(int n, ARTYPE sigma, NCformat& A, - NCformat& B, NCformat& AsB); - - public: - - bool IsFactored() { return factored; } - - void FactorAsB(ARTYPE sigma); - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - - void MultInvAsBv(ARTYPE* v, ARTYPE* w); - - void DefineMatrices(ARluSymMatrix<ARTYPE>& Ap, ARluSymMatrix<ARTYPE>& Bp); - - ARluSymPencil(); - // Short constructor that does nothing. - - ARluSymPencil(ARluSymMatrix<ARTYPE>& Ap, ARluSymMatrix<ARTYPE>& Bp); - // Long constructor. - - ARluSymPencil(const ARluSymPencil& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymPencil() { ClearMem(); } - // Destructor. - - ARluSymPencil& operator=(const ARluSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARluSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -inline void ARluSymPencil<ARTYPE>:: -Copy(const ARluSymPencil<ARTYPE>& other) -{ - - factored = other.factored; - part = other.part; - uplo = other.uplo; - A = other.A; - B = other.B; - - // Throwing the original factorization away (this procedure - // is really awkward, but it is necessary because there - // is no copy function for matrices L and U in the SuperLU - // library and it is not a good idea to do this kind of deep - // copy here). - - if (factored) { - ArpackError(ArpackError::DISCARDING_FACTORS, "ARluSymPencil"); - factored = false; - } - -} // Copy. - - -template<class ARTYPE> -void ARluSymPencil<ARTYPE>::ClearMem() -{ - - if (factored) { - Destroy_SuperNode_Matrix(&L); - Destroy_CompCol_Matrix(&U); - StatFree(&stat); - delete[] permc; - delete[] permr; - permc = NULL; - permr = NULL; - } - -} // ClearMem. - - -template<class ARTYPE> -void ARluSymPencil<ARTYPE>:: -SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], - int yind[], int ny, ARTYPE z[], int zind[], int& nz) -// A strongly sequential (and inefficient) sparse saxpy algorithm. -{ - - int ix, iy; - - nz = 0; - if ((nx == 0) || (a == (ARTYPE)0)) { - copy(ny,y,1,z,1); - for (iy=0; iy!=ny; iy++) zind[iy] = yind[iy]; - nz = ny; - return; - } - if (ny == 0) { - copy(nx,x,1,z,1); - scal(nx,a,z,1); - for (ix=0; ix!=nx; ix++) zind[ix] = xind[ix]; - nz = nx; - return; - } - ix = 0; - iy = 0; - while (true) { - if (xind[ix] == yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]+y[iy++]; - if ((ix == nx)||(iy == ny)) break; - } - else if (xind[ix] < yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]; - if (ix == nx) break; - } - else { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - if (iy == ny) break; - } - } - while (iy < ny) { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - } - while (ix < nx) { - zind[nz] = xind[ix]; - z[nz++] = x[ix++]; - } - -} // SparseSaxpy. - - -template<class ARTYPE> -void ARluSymPencil<ARTYPE>::ExpandAsB(int n, NCformat& AsB) -{ - - int i, j, k; - int *pcol, *pos, *col, *ind; - ARTYPE *val; - - // simplifying the notation. - - val = (ARTYPE*)AsB.nzval; - ind = AsB.rowind; - col = AsB.colptr; - - // Initializing vectors. - - pcol = new int[n+1]; - pos = new int[n+1]; - for (i=0; i<=n; i++) pcol[i] = col[i]; - for (i=0; i<=n; i++) pos[i] = 0; - - // Counting the elements in each column of AsB. - - if (uplo == 'U') { - - for (i=0; i!=n; i++) { - k = pcol[i+1]; - if ((k!=pcol[i])&&(ind[k-1]==i)) k--; - for (j=pcol[i]; j<k; j++) pos[ind[j]]++; - } - - } - else { // uplo == 'L' - - for (i=0; i!=n; i++) { - k = pcol[i]; - if ((k!=pcol[i+1])&&(ind[k]==i)) k++; - for (j=k; j<pcol[i+1]; j++) pos[ind[j]]++; - } - - } - - // Summing up index elements. - - for (i=0; i<n; i++) pos[i+1] += pos[i]; - for (i=n; i>0; i--) col[i] += pos[i-1]; - - // Expanding A. - - if (uplo == 'U') { - - for (i=n-1; i>=0; i--) { - pos[i] = col[i]+pcol[i+1]-pcol[i]; - k = pos[i]-1; - for (j=pcol[i+1]-1; j>=pcol[i]; j--) { - val[k] = val[j]; - ind[k--] = ind[j]; - } - } - for (i=1; i<n; i++) { - k = col[i]+pcol[i+1]-pcol[i]; - if ((k>col[i])&&(ind[k-1]==i)) k--; - for (j=col[i]; j<k; j++) { - val[pos[ind[j]]] = val[j]; - ind[pos[ind[j]]++] = i; - } - } - - } - else { // uplo == 'L' - - for (i=n-1; i>=0; i--) { - k = col[i+1]-1; - for (j=pcol[i+1]-1; j>=pcol[i]; j--) { - val[k] = val[j]; - ind[k--] = ind[j]; - } - pos[i] = col[i]; - } - for (i=0; i<(n-1); i++) { - k = col[i+1]-pcol[i+1]+pcol[i]; - if ((k<col[i+1])&&(ind[k]==i)) k++; - for (j=k; j<col[i+1]; j++) { - val[pos[ind[j]]] = val[j]; - ind[pos[ind[j]]++] = i; - } - } - - } - - AsB.nnz = col[n]; - - // Deleting temporary vectors. - - delete[] pcol; - delete[] pos; - -} // ExpandAsB. - - -template<class ARTYPE> -void ARluSymPencil<ARTYPE>:: -SubtractAsB(int n, ARTYPE sigma, NCformat& matA, NCformat& matB, NCformat& AsB) -{ - - int i, acol, bcol, asbcol, scol; - ARTYPE* anzval; - ARTYPE* bnzval; - ARTYPE* asbnzval; - - // Quitting function if A->uplo is not equal to B->uplo. - - if ((A->uplo != B->uplo)&&(sigma != (ARTYPE)0)) { - throw ArpackError(ArpackError::DIFFERENT_TRIANGLES, - "ARluSymPencil::SubtractAsB"); - } - uplo = A->uplo; - - // Telling the compiler that nzval must ve viewed as a vector of ARTYPE. - - anzval = (ARTYPE*)matA.nzval; - bnzval = (ARTYPE*)matB.nzval; - asbnzval = (ARTYPE*)AsB.nzval; - - // Subtracting sigma*B from A. - - AsB.colptr[0] = 0; - asbcol = 0; - - for (i=0; i!=n; i++) { - bcol = matB.colptr[i]; - acol = matA.colptr[i]; - SparseSaxpy(-sigma, &bnzval[bcol], &matB.rowind[bcol], - matB.colptr[i+1]-bcol, &anzval[acol], &matA.rowind[acol], - matA.colptr[i+1]-acol, &asbnzval[asbcol], - &AsB.rowind[asbcol], scol); - asbcol += scol; - AsB.colptr[i+1] = asbcol; - } - - // Expanding AsB. - - ExpandAsB(n, AsB); - -} // SubtractAsB. - - -// template<class ARTYPE> -// void ARluSymPencil<ARTYPE>::FactorAsB(ARTYPE sigma) -// { -// -// // Quitting the function if A and B were not defined. -// -// if (!(A->IsDefined()&&B->IsDefined())) { -// throw ArpackError(ArpackError::DATA_UNDEFINED, -// "ARluSymPencil::FactorAsB"); -// } -// -// // Quitting the function if A and B are not square. -// -// if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { -// throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, -// "ARluSymPencil::FactorAsB"); -// } -// -// // Defining local variables. -// -// int nnzi, info; -// int* etree; -// int* irowi; -// int* pcoli; -// ARTYPE* asb; -// SuperMatrix AsB; -// SuperMatrix AC; -// NCformat* Astore; -// NCformat* Bstore; -// NCformat* AsBstore; -// -// // Deleting old versions of L, U, perm_r and perm_c. -// -// ClearMem(); -// -// // Setting default values for gstrf parameters. -// -// ARTYPE drop_tol = (ARTYPE)0; -// int panel_size = sp_ienv(1); -// int relax = sp_ienv(2); -// -// // Defining A and B format. -// -// Astore = (NCformat*)A->A.Store; -// Bstore = (NCformat*)B->A.Store; -// -// // Creating a temporary matrix AsB. -// -// nnzi = (Astore->nnz+Bstore->nnz)*2; -// irowi = new int[nnzi]; -// pcoli = new int[A->ncols()+1]; -// asb = new ARTYPE[nnzi]; -// Create_CompCol_Matrix(&AsB, A->nrows(), A->ncols(), nnzi, asb, -// irowi, pcoli, NC, GE); -// -// // Subtracting sigma*B from A and storing the result on AsB. -// -// AsBstore = (NCformat*)AsB.Store; -// SubtractAsB(A->ncols(), sigma, *Astore, *Bstore, *AsBstore); -// -// // Reserving memory for some vectors used in matrix decomposition. -// -// etree = new int[A->ncols()]; -// if (permc == NULL) permc = new int[A->ncols()]; -// if (permr == NULL) permr = new int[A->ncols()]; -// -// // Defining LUStat. -// -// StatInit(panel_size, relax); -// -// // Defining the column permutation of matrix AsB -// // (using minimum degree ordering on AsB'*AsB). -// -// get_perm_c(A->order, &AsB, permc); -// -// // Permuting columns of AsB and -// // creating the elimination tree of AsB'*AsB. -// -// sp_preorder("N", &AsB, permc, etree, &AC); -// -// // Decomposing AsB. -// -// gstrf("N",&AC, A->threshold, drop_tol, relax, panel_size, etree, -// NULL, 0, permr, permc, &L, &U, &info); -// -// // Deleting AC, AsB and etree. -// -// Destroy_CompCol_Permuted(&AC); -// Destroy_CompCol_Matrix(&AsB); -// delete[] etree; -// -// factored = (info == 0); -// -// // Handling errors. -// -// if (info < 0) { // Illegal argument. -// throw ArpackError(ArpackError::PARAMETER_ERROR, -// "ARluSymPencil::FactorAsB"); -// } -// else if (info > A->ncols()) { // Memory is not sufficient. -// throw ArpackError(ArpackError::MEMORY_OVERFLOW, -// "ARluSymPencil::FactorAsB"); -// } -// else if (info > 0) { // Matrix is singular. -// throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, -// "ARluSymPencil::FactorAsB"); -// } -// -// } // FactorAsB. - -template<class ARTYPE> -void ARluSymPencil<ARTYPE>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARluSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARluSymPencil::FactorAsB"); - } - - // Defining local variables. - - int nnzi, info; - int* etree; - int* irowi; - int* pcoli; - ARTYPE* asb; - SuperMatrix AsB; - SuperMatrix AC; - NCformat* Astore; - NCformat* Bstore; - NCformat* AsBstore; - - // Deleting old versions of L, U, perm_r and perm_c. - - ClearMem(); - - // Setting default values for gstrf parameters. - - int panel_size = sp_ienv(1); - int relax = sp_ienv(2); - superlu_options_t options; - /* Set the default input options: - options.Fact = DOFACT; - options.Equil = YES; - options.ColPerm = COLAMD; - options.DiagPivotThresh = 1.0; - options.Trans = NOTRANS; - options.IterRefine = NOREFINE; - options.SymmetricMode = NO; - options.PivotGrowth = NO; - options.ConditionNumber = NO; - options.PrintStat = YES; - */ - set_default_options(&options); - - /* Now we modify the default options to use the symmetric mode. */ - options.SymmetricMode = YES; - options.ColPerm = MMD_AT_PLUS_A; - options.DiagPivotThresh = A->threshold; - - // Defining A and B format. - - Astore = (NCformat*)A->A.Store; - Bstore = (NCformat*)B->A.Store; - - // Creating a temporary matrix AsB. - - nnzi = (Astore->nnz+Bstore->nnz)*2; - irowi = new int[nnzi]; - pcoli = new int[A->ncols()+1]; - asb = new ARTYPE[nnzi]; - Create_CompCol_Matrix(&AsB, A->nrows(), A->ncols(), nnzi, asb, - irowi, pcoli, SLU_NC, SLU_GE); - - // Subtracting sigma*B from A and storing the result on AsB. - - AsBstore = (NCformat*)AsB.Store; - SubtractAsB(A->ncols(), sigma, *Astore, *Bstore, *AsBstore); - - // Reserving memory for some vectors used in matrix decomposition. - - etree = new int[A->ncols()]; - if (permc == NULL) permc = new int[A->ncols()]; - if (permr == NULL) permr = new int[A->ncols()]; - - // Defining LUStat. - -// StatInit(panel_size, relax); - SuperLUStat_t stat; - StatInit(&stat); - - // Defining the column permutation of matrix AsB - // (using minimum degree ordering on AsB'*AsB). - - get_perm_c(A->order, &AsB, permc); - - // Permuting columns of AsB and - // creating the elimination tree of AsB'*AsB. - - sp_preorder(&options, &AsB, permc, etree, &AC); - - // Decomposing AsB. - -// gstrf("N",&AC, A->threshold, drop_tol, relax, panel_size, etree, -// NULL, 0, permr, permc, &L, &U, &info); - gstrf(&options, &AC, relax, panel_size, etree, - NULL, 0, permc, permr, &L, &U, &stat, &info); - - // Deleting AC, AsB and etree. - - Destroy_CompCol_Permuted(&AC); - Destroy_CompCol_Matrix(&AsB); - delete[] etree; - - factored = (info == 0); - - // Handling errors. - - if (info < 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARluSymPencil::FactorAsB"); - } - else if (info > A->ncols()) { // Memory is not sufficient. - throw ArpackError(ArpackError::MEMORY_OVERFLOW, - "ARluSymPencil::FactorAsB"); - } - else if (info > 0) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARluSymPencil::FactorAsB"); - } - -} // FactorAsB. - -template<class ARTYPE> -void ARluSymPencil<ARTYPE>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - copy(A->ncols(), w, 1, v, 1); - B->MultInvv(w, w); - -} // MultInvBAv. - - -template<class ARTYPE> -void ARluSymPencil<ARTYPE>::MultInvAsBv(ARTYPE* v, ARTYPE* w) -{ - - // Quitting the function if AsB was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARluSymPencil::MultInvAsBv"); - } - - // Solving AsB.w = v. - - int info; - SuperMatrix RHS; - - copy(A->nrows(), v, 1, w, 1); - Create_Dense_Matrix(&RHS, A->nrows(), 1, w, A->nrows(), SLU_DN, SLU_GE); -// gstrs("N", &L, &U, permr, permc, &RHS, &info); - trans_t trans = NOTRANS; - StatInit(&stat); - - gstrs(trans, &L, &U, permc, permr, &RHS, &stat, &info); - - Destroy_SuperMatrix_Store(&RHS); // delete RHS.Store; - -} // MultInvAsBv. - - -template<class ARTYPE> -inline void ARluSymPencil<ARTYPE>:: -DefineMatrices(ARluSymMatrix<ARTYPE>& Ap, ARluSymMatrix<ARTYPE>& Bp) -{ - - A = &Ap; - B = &Bp; - permc = NULL; - permr = NULL; - - if ((A->n != B->n)||(A->m != B->m)) { - throw ArpackError(ArpackError::INCOMPATIBLE_SIZES, - "ARluSymMatrix::DefineMatrices"); - } - -} // DefineMatrices. - - -template<class ARTYPE> -inline ARluSymPencil<ARTYPE>::ARluSymPencil() -{ - - factored = false; - part = 'N'; - permr = NULL; - permc = NULL; - -} // Short constructor. - - -template<class ARTYPE> -inline ARluSymPencil<ARTYPE>:: -ARluSymPencil(ARluSymMatrix<ARTYPE>& Ap, ARluSymMatrix<ARTYPE>& Bp) -{ - - factored = false; - DefineMatrices(Ap, Bp); - -} // Long constructor. - - -template<class ARTYPE> -ARluSymPencil<ARTYPE>& ARluSymPencil<ARTYPE>:: -operator=(const ARluSymPencil<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLSPEN_H diff --git a/src/external/arpack++/include/arlssym.h b/src/external/arpack++/include/arlssym.h deleted file mode 100644 index fdab7e6b..00000000 --- a/src/external/arpack++/include/arlssym.h +++ /dev/null @@ -1,179 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLSSym.h. - Arpack++ class ARluSymStdEig definition - (SuperLU version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Kristi Maschhoff - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARLSSYM_H -#define ARLSSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arssym.h" -#include "arlsmat.h" - - -template<class ARFLOAT> -class ARluSymStdEig: - public virtual ARSymStdEig<ARFLOAT, ARluSymMatrix<ARFLOAT> > { - - protected: - - // a) Protected function: - - virtual void Copy(const ARluSymStdEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // b) Public functions: - - // b.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // b.2) Constructors and destructor. - - ARluSymStdEig() { } - // Short constructor. - - ARluSymStdEig(int nevp, ARluSymMatrix<ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymStdEig(int nevp, ARluSymMatrix<ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluSymStdEig(const ARluSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymStdEig() { } - // Destructor. - - // c) Operators. - - ARluSymStdEig& operator=(const ARluSymStdEig& other); - // Assignment operator. - -}; // class ARluSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::Copy(const ARluSymStdEig<ARFLOAT>& other) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARluSymMatrix<ARFLOAT> >:: Copy(other); - if (this->mode > 2) this->objOP->FactorAsI(this->sigmaR); - -} // Copy. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI(this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARluSymMatrix<ARFLOAT> >:: - SetRegularMode(this->objOP, &ARluSymMatrix<ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARluSymMatrix<ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, &ARluSymMatrix<ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARluSymMatrix<ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, &ARluSymMatrix<ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARluSymMatrix<ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, &ARluSymMatrix<ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluSymStdEig<ARFLOAT>& ARluSymStdEig<ARFLOAT>:: -operator=(const ARluSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARLSSYM_H diff --git a/src/external/arpack++/include/arlsupm.h b/src/external/arpack++/include/arlsupm.h deleted file mode 100644 index 7c8d2e8a..00000000 --- a/src/external/arpack++/include/arlsupm.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLSupM.h. - Unaltered copy of supermatrix.h (from SuperLU package). -*/ - -#ifndef __SUPERLU_SUPERMATRIX /* allow multiple inclusions */ -#define __SUPERLU_SUPERMATRIX - - -/******************************************** - * The matrix types are defined as follows. * - ********************************************/ -typedef enum { - SLU_NC, /* column-wise, no supernode */ - SLU_NCP, /* column-wise, column-permuted, no supernode - (The consecutive columns of nonzeros, after permutation, - may not be stored contiguously.) */ - SLU_NR, /* row-wize, no supernode */ - SLU_SC, /* column-wise, supernode */ - SLU_SCP, /* supernode, column-wise, permuted */ - SLU_SR, /* row-wise, supernode */ - SLU_DN, /* Fortran style column-wise storage for dense matrix */ - SLU_NR_loc /* distributed compressed row format */ -} Stype_t; - -typedef enum { - SLU_S, /* single */ - SLU_D, /* double */ - SLU_C, /* single complex */ - SLU_Z /* double complex */ -} Dtype_t; - -typedef enum { - SLU_GE, /* general */ - SLU_TRLU, /* lower triangular, unit diagonal */ - SLU_TRUU, /* upper triangular, unit diagonal */ - SLU_TRL, /* lower triangular */ - SLU_TRU, /* upper triangular */ - SLU_SYL, /* symmetric, store lower half */ - SLU_SYU, /* symmetric, store upper half */ - SLU_HEL, /* Hermitian, store lower half */ - SLU_HEU /* Hermitian, store upper half */ -} Mtype_t; - -typedef struct { - Stype_t Stype; /* Storage type: interprets the storage structure - pointed to by *Store. */ - Dtype_t Dtype; /* Data type. */ - Mtype_t Mtype; /* Matrix type: describes the mathematical property of - the matrix. */ - int nrow; /* number of rows */ - int ncol; /* number of columns */ - void *Store; /* pointer to the actual storage of the matrix */ -} SuperMatrix; - -/*********************************************** - * The storage schemes are defined as follows. * - ***********************************************/ - -/* Stype == SLU_NC (Also known as Harwell-Boeing sparse matrix format) */ -typedef struct { - int nnz; /* number of nonzeros in the matrix */ - void *nzval; /* pointer to array of nonzero values, packed by column */ - int *rowind; /* pointer to array of row indices of the nonzeros */ - int *colptr; /* pointer to array of beginning of columns in nzval[] - and rowind[] */ - /* Note: - Zero-based indexing is used; - colptr[] has ncol+1 entries, the last one pointing - beyond the last column, so that colptr[ncol] = nnz. */ -} NCformat; - -/* Stype == SLU_NR */ -typedef struct { - int nnz; /* number of nonzeros in the matrix */ - void *nzval; /* pointer to array of nonzero values, packed by raw */ - int *colind; /* pointer to array of columns indices of the nonzeros */ - int *rowptr; /* pointer to array of beginning of rows in nzval[] - and colind[] */ - /* Note: - Zero-based indexing is used; - rowptr[] has nrow+1 entries, the last one pointing - beyond the last row, so that rowptr[nrow] = nnz. */ -} NRformat; - -/* Stype == SLU_SC */ -typedef struct { - int nnz; /* number of nonzeros in the matrix */ - int nsuper; /* number of supernodes, minus 1 */ - void *nzval; /* pointer to array of nonzero values, packed by column */ - int *nzval_colptr;/* pointer to array of beginning of columns in nzval[] */ - int *rowind; /* pointer to array of compressed row indices of - rectangular supernodes */ - int *rowind_colptr;/* pointer to array of beginning of columns in rowind[] */ - int *col_to_sup; /* col_to_sup[j] is the supernode number to which column - j belongs; mapping from column to supernode number. */ - int *sup_to_col; /* sup_to_col[s] points to the start of the s-th - supernode; mapping from supernode number to column. - e.g.: col_to_sup: 0 1 2 2 3 3 3 4 4 4 4 4 4 (ncol=12) - sup_to_col: 0 1 2 4 7 12 (nsuper=4) */ - /* Note: - Zero-based indexing is used; - nzval_colptr[], rowind_colptr[], col_to_sup and - sup_to_col[] have ncol+1 entries, the last one - pointing beyond the last column. - For col_to_sup[], only the first ncol entries are - defined. For sup_to_col[], only the first nsuper+2 - entries are defined. */ -} SCformat; - -/* Stype == SLU_SCP */ -typedef struct { - int nnz; /* number of nonzeros in the matrix */ - int nsuper; /* number of supernodes */ - void *nzval; /* pointer to array of nonzero values, packed by column */ - int *nzval_colbeg;/* nzval_colbeg[j] points to beginning of column j - in nzval[] */ - int *nzval_colend;/* nzval_colend[j] points to one past the last element - of column j in nzval[] */ - int *rowind; /* pointer to array of compressed row indices of - rectangular supernodes */ - int *rowind_colbeg;/* rowind_colbeg[j] points to beginning of column j - in rowind[] */ - int *rowind_colend;/* rowind_colend[j] points to one past the last element - of column j in rowind[] */ - int *col_to_sup; /* col_to_sup[j] is the supernode number to which column - j belongs; mapping from column to supernode. */ - int *sup_to_colbeg; /* sup_to_colbeg[s] points to the start of the s-th - supernode; mapping from supernode to column.*/ - int *sup_to_colend; /* sup_to_colend[s] points to one past the end of the - s-th supernode; mapping from supernode number to - column. - e.g.: col_to_sup: 0 1 2 2 3 3 3 4 4 4 4 4 4 (ncol=12) - sup_to_colbeg: 0 1 2 4 7 (nsuper=4) - sup_to_colend: 1 2 4 7 12 */ - /* Note: - Zero-based indexing is used; - nzval_colptr[], rowind_colptr[], col_to_sup and - sup_to_col[] have ncol+1 entries, the last one - pointing beyond the last column. */ -} SCPformat; - -/* Stype == SLU_NCP */ -typedef struct { - int nnz; /* number of nonzeros in the matrix */ - void *nzval; /* pointer to array of nonzero values, packed by column */ - int *rowind;/* pointer to array of row indices of the nonzeros */ - /* Note: nzval[]/rowind[] always have the same length */ - int *colbeg;/* colbeg[j] points to the beginning of column j in nzval[] - and rowind[] */ - int *colend;/* colend[j] points to one past the last element of column - j in nzval[] and rowind[] */ - /* Note: - Zero-based indexing is used; - The consecutive columns of the nonzeros may not be - contiguous in storage, because the matrix has been - postmultiplied by a column permutation matrix. */ -} NCPformat; - -/* Stype == SLU_DN */ -typedef struct { - int lda; /* leading dimension */ - void *nzval; /* array of size lda*ncol to represent a dense matrix */ -} DNformat; - -/* Stype == SLU_NR_loc (Distributed Compressed Row Format) */ -typedef struct { - int nnz_loc; /* number of nonzeros in the local submatrix */ - int m_loc; /* number of rows local to this processor */ - int fst_row; /* global index of the first row */ - void *nzval; /* pointer to array of nonzero values, packed by row */ - int *rowptr; /* pointer to array of beginning of rows in nzval[] - and colind[] */ - int *colind; /* pointer to array of column indices of the nonzeros */ - /* Note: - Zero-based indexing is used; - rowptr[] has n_loc + 1 entries, the last one pointing - beyond the last row, so that rowptr[n_loc] = nnz_loc.*/ -} NRformat_loc; - - -#endif /* __SUPERLU_SUPERMATRIX */ diff --git a/src/external/arpack++/include/arlutil.h b/src/external/arpack++/include/arlutil.h deleted file mode 100644 index 664ca61b..00000000 --- a/src/external/arpack++/include/arlutil.h +++ /dev/null @@ -1,432 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARLUtil.h. - Unaltered copy of util.h (from SuperLU package) - and superlu_enum_consts.h -*/ - - - -#ifndef __SUPERLU_ENUM_CONSTS /* allow multiple inclusions */ -#define __SUPERLU_ENUM_CONSTS - -/*********************************************************************** - * Enumerate types - ***********************************************************************/ -typedef enum {NO, YES} yes_no_t; -typedef enum {DOFACT, SamePattern, SamePattern_SameRowPerm, FACTORED} fact_t; -typedef enum {NOROWPERM, LargeDiag, MY_PERMR} rowperm_t; -typedef enum {NATURAL, MMD_ATA, MMD_AT_PLUS_A, COLAMD, - METIS_AT_PLUS_A, PARMETIS, ZOLTAN, MY_PERMC} colperm_t; -typedef enum {NOTRANS, TRANS, CONJ} trans_t; -typedef enum {NOEQUIL, ROW, COL, BOTH} DiagScale_t; -typedef enum {NOREFINE, SLU_SINGLE=1, SLU_DOUBLE, SLU_EXTRA} IterRefine_t; -typedef enum {LUSUP, UCOL, LSUB, USUB, LLVL, ULVL} MemType; -typedef enum {HEAD, TAIL} stack_end_t; -typedef enum {SYSTEM, USER} LU_space_t; -typedef enum {ONE_NORM, TWO_NORM, INF_NORM} norm_t; -typedef enum {SILU, SMILU_1, SMILU_2, SMILU_3} milu_t; -#if 0 -typedef enum {NODROP = 0x0000, - DROP_BASIC = 0x0001, /* ILU(tau) */ - DROP_PROWS = 0x0002, /* ILUTP: keep p maximum rows */ - DROP_COLUMN = 0x0004, /* ILUTP: for j-th column, - p = gamma * nnz(A(:,j)) */ - DROP_AREA = 0x0008, /* ILUTP: for j-th column, use - nnz(F(:,1:j)) / nnz(A(:,1:j)) - to limit memory growth */ - DROP_SECONDARY = 0x000E, /* PROWS | COLUMN | AREA */ - DROP_DYNAMIC = 0x0010, - DROP_INTERP = 0x0100} rule_t; -#endif - - -/* - * The following enumerate type is used by the statistics variable - * to keep track of flop count and time spent at various stages. - * - * Note that not all of the fields are disjoint. - */ -typedef enum { - COLPERM, /* find a column ordering that minimizes fills */ - ROWPERM, /* find a row ordering maximizes diagonal. */ - RELAX, /* find artificial supernodes */ - ETREE, /* compute column etree */ - EQUIL, /* equilibrate the original matrix */ - SYMBFAC, /* symbolic factorization. */ - DIST, /* distribute matrix. */ - FACT, /* perform LU factorization */ - COMM, /* communication for factorization */ - SOL_COMM,/* communication for solve */ - RCOND, /* estimate reciprocal condition number */ - SOLVE, /* forward and back solves */ - REFINE, /* perform iterative refinement */ - TRSV, /* fraction of FACT spent in xTRSV */ - GEMV, /* fraction of FACT spent in xGEMV */ - FERR, /* estimate error bounds after iterative refinement */ - NPHASES /* total number of phases */ -} PhaseType; - - -#endif /* __SUPERLU_ENUM_CONSTS */ - - - -#ifndef __SUPERLU_UTIL /* allow multiple inclusions */ -#define __SUPERLU_UTIL - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -/* -#ifndef __STDC__ -#include <malloc.h> -#endif -*/ -#include <assert.h> - -/*********************************************************************** - * Macros - ***********************************************************************/ -#define FIRSTCOL_OF_SNODE(i) (xsup[i]) -/* No of marker arrays used in the symbolic factorization, - each of size n */ -#define NO_MARKER 3 -#define NUM_TEMPV(m,w,t,b) ( SUPERLU_MAX(m, (t + b)*w) ) - -#ifndef USER_ABORT -#define USER_ABORT(msg) superlu_abort_and_exit(msg) -#endif - -#define ABORT(err_msg) \ - { char msg[256];\ - sprintf(msg,"%s at line %d in file %s\n",err_msg,__LINE__, __FILE__);\ - USER_ABORT(msg); } - - -#ifndef USER_MALLOC -#if 1 -#define USER_MALLOC(size) superlu_malloc(size) -#else -/* The following may check out some uninitialized data */ -#define USER_MALLOC(size) memset (superlu_malloc(size), '\x0F', size) -#endif -#endif - -#define SUPERLU_MALLOC(size) USER_MALLOC(size) - -#ifndef USER_FREE -#define USER_FREE(addr) superlu_free(addr) -#endif - -#define SUPERLU_FREE(addr) USER_FREE(addr) - -#define CHECK_MALLOC(where) { \ - extern int superlu_malloc_total; \ - printf("%s: malloc_total %d Bytes\n", \ - where, superlu_malloc_total); \ -} - -#define SUPERLU_MAX(x, y) ( (x) > (y) ? (x) : (y) ) -#define SUPERLU_MIN(x, y) ( (x) < (y) ? (x) : (y) ) - -/********************************************************* - * Macros used for easy access of sparse matrix entries. * - *********************************************************/ -#define L_SUB_START(col) ( Lstore->rowind_colptr[col] ) -#define L_SUB(ptr) ( Lstore->rowind[ptr] ) -#define L_NZ_START(col) ( Lstore->nzval_colptr[col] ) -#define L_FST_SUPC(superno) ( Lstore->sup_to_col[superno] ) -#define U_NZ_START(col) ( Ustore->colptr[col] ) -#define U_SUB(ptr) ( Ustore->rowind[ptr] ) - - -/*********************************************************************** - * Constants - ***********************************************************************/ -#define EMPTY (-1) -/*#define NO (-1)*/ -#define FALSE 0 -#define TRUE 1 - -#define NO_MEMTYPE 4 /* 0: lusup; - 1: ucol; - 2: lsub; - 3: usub */ - -#define GluIntArray(n) (5 * (n) + 5) - -/* Dropping rules */ -#define NODROP ( 0x0000 ) -#define DROP_BASIC ( 0x0001 ) /* ILU(tau) */ -#define DROP_PROWS ( 0x0002 ) /* ILUTP: keep p maximum rows */ -#define DROP_COLUMN ( 0x0004 ) /* ILUTP: for j-th column, - p = gamma * nnz(A(:,j)) */ -#define DROP_AREA ( 0x0008 ) /* ILUTP: for j-th column, use - nnz(F(:,1:j)) / nnz(A(:,1:j)) - to limit memory growth */ -#define DROP_SECONDARY ( 0x000E ) /* PROWS | COLUMN | AREA */ -#define DROP_DYNAMIC ( 0x0010 ) /* adaptive tau */ -#define DROP_INTERP ( 0x0100 ) /* use interpolation */ - - -#if 1 -#define MILU_ALPHA (1.0e-2) /* multiple of drop_sum to be added to diagonal */ -#else -#define MILU_ALPHA 1.0 /* multiple of drop_sum to be added to diagonal */ -#endif - - -/*********************************************************************** - * Type definitions - ***********************************************************************/ -typedef float flops_t; -typedef unsigned char Logical; - -/* - *-- This contains the options used to control the solution process. - * - * Fact (fact_t) - * Specifies whether or not the factored form of the matrix - * A is supplied on entry, and if not, how the matrix A should - * be factorizaed. - * = DOFACT: The matrix A will be factorized from scratch, and the - * factors will be stored in L and U. - * = SamePattern: The matrix A will be factorized assuming - * that a factorization of a matrix with the same sparsity - * pattern was performed prior to this one. Therefore, this - * factorization will reuse column permutation vector - * ScalePermstruct->perm_c and the column elimination tree - * LUstruct->etree. - * = SamePattern_SameRowPerm: The matrix A will be factorized - * assuming that a factorization of a matrix with the same - * sparsity pattern and similar numerical values was performed - * prior to this one. Therefore, this factorization will reuse - * both row and column scaling factors R and C, both row and - * column permutation vectors perm_r and perm_c, and the - * data structure set up from the previous symbolic factorization. - * = FACTORED: On entry, L, U, perm_r and perm_c contain the - * factored form of A. If DiagScale is not NOEQUIL, the matrix - * A has been equilibrated with scaling factors R and C. - * - * Equil (yes_no_t) - * Specifies whether to equilibrate the system (scale A's row and - * columns to have unit norm). - * - * ColPerm (colperm_t) - * Specifies what type of column permutation to use to reduce fill. - * = NATURAL: use the natural ordering - * = MMD_ATA: use minimum degree ordering on structure of A'*A - * = MMD_AT_PLUS_A: use minimum degree ordering on structure of A'+A - * = COLAMD: use approximate minimum degree column ordering - * = MY_PERMC: use the ordering specified by the user - * - * Trans (trans_t) - * Specifies the form of the system of equations: - * = NOTRANS: A * X = B (No transpose) - * = TRANS: A**T * X = B (Transpose) - * = CONJ: A**H * X = B (Transpose) - * - * IterRefine (IterRefine_t) - * Specifies whether to perform iterative refinement. - * = NO: no iterative refinement - * = SLU_SINGLE: perform iterative refinement in single precision - * = SLU_DOUBLE: perform iterative refinement in double precision - * = SLU_EXTRA: perform iterative refinement in extra precision - * - * DiagPivotThresh (double, in [0.0, 1.0]) (only for sequential SuperLU) - * Specifies the threshold used for a diagonal entry to be an - * acceptable pivot. - * - * SymmetricMode (yest_no_t) - * Specifies whether to use symmetric mode. Symmetric mode gives - * preference to diagonal pivots, and uses an (A'+A)-based column - * permutation algorithm. - * - * PivotGrowth (yes_no_t) - * Specifies whether to compute the reciprocal pivot growth. - * - * ConditionNumber (ues_no_t) - * Specifies whether to compute the reciprocal condition number. - * - * RowPerm (rowperm_t) (only for SuperLU_DIST or ILU) - * Specifies whether to permute rows of the original matrix. - * = NO: not to permute the rows - * = LargeDiag: make the diagonal large relative to the off-diagonal - * = MY_PERMR: use the permutation given by the user - * - * ILU_DropRule (int) - * Specifies the dropping rule: - * = DROP_BASIC: Basic dropping rule, supernodal based ILUTP(tau). - * = DROP_PROWS: Supernodal based ILUTP(p,tau), p = gamma * nnz(A)/n. - * = DROP_COLUMN: Variant of ILUTP(p,tau), for j-th column, - * p = gamma * nnz(A(:,j)). - * = DROP_AREA: Variation of ILUTP, for j-th column, use - * nnz(F(:,1:j)) / nnz(A(:,1:j)) to control memory. - * = DROP_DYNAMIC: Modify the threshold tau during factorizaion: - * If nnz(L(:,1:j)) / nnz(A(:,1:j)) > gamma - * tau_L(j) := MIN(tau_0, tau_L(j-1) * 2); - * Otherwise - * tau_L(j) := MAX(tau_0, tau_L(j-1) / 2); - * tau_U(j) uses the similar rule. - * NOTE: the thresholds used by L and U are separate. - * = DROP_INTERP: Compute the second dropping threshold by - * interpolation instead of sorting (default). - * In this case, the actual fill ratio is not - * guaranteed to be smaller than gamma. - * Note: DROP_PROWS, DROP_COLUMN and DROP_AREA are mutually exclusive. - * ( Default: DROP_BASIC | DROP_AREA ) - * - * ILU_DropTol (double) - * numerical threshold for dropping. - * - * ILU_FillFactor (double) - * Gamma in the secondary dropping. - * - * ILU_Norm (norm_t) - * Specify which norm to use to measure the row size in a - * supernode: infinity-norm, 1-norm, or 2-norm. - * - * ILU_FillTol (double) - * numerical threshold for zero pivot perturbation. - * - * ILU_MILU (milu_t) - * Specifies which version of MILU to use. - * - * ILU_MILU_Dim (double) - * Dimension of the PDE if available. - * - * ReplaceTinyPivot (yes_no_t) (only for SuperLU_DIST) - * Specifies whether to replace the tiny diagonals by - * sqrt(epsilon)*||A|| during LU factorization. - * - * SolveInitialized (yes_no_t) (only for SuperLU_DIST) - * Specifies whether the initialization has been performed to the - * triangular solve. - * - * RefineInitialized (yes_no_t) (only for SuperLU_DIST) - * Specifies whether the initialization has been performed to the - * sparse matrix-vector multiplication routine needed in iterative - * refinement. - * - * PrintStat (yes_no_t) - * Specifies whether to print the solver's statistics. - */ -typedef struct { - fact_t Fact; - yes_no_t Equil; - colperm_t ColPerm; - trans_t Trans; - IterRefine_t IterRefine; - double DiagPivotThresh; - yes_no_t SymmetricMode; - yes_no_t PivotGrowth; - yes_no_t ConditionNumber; - rowperm_t RowPerm; - int ILU_DropRule; - double ILU_DropTol; /* threshold for dropping */ - double ILU_FillFactor; /* gamma in the secondary dropping */ - norm_t ILU_Norm; /* infinity-norm, 1-norm, or 2-norm */ - double ILU_FillTol; /* threshold for zero pivot perturbation */ - milu_t ILU_MILU; - double ILU_MILU_Dim; /* Dimension of PDE (if available) */ - yes_no_t ParSymbFact; - yes_no_t ReplaceTinyPivot; /* used in SuperLU_DIST */ - yes_no_t SolveInitialized; - yes_no_t RefineInitialized; - yes_no_t PrintStat; - int nnzL, nnzU; /* used to store nnzs for now */ - int num_lookaheads; /* num of levels in look-ahead */ - yes_no_t lookahead_etree; /* use etree computed from the - serial symbolic factorization */ - yes_no_t SymPattern; /* symmetric factorization */ -} superlu_options_t; - -/*! \brief Headers for 4 types of dynamatically managed memory */ -typedef struct e_node { - int size; /* length of the memory that has been used */ - void *mem; /* pointer to the new malloc'd store */ -} ExpHeader; - -typedef struct { - int size; - int used; - int top1; /* grow upward, relative to &array[0] */ - int top2; /* grow downward */ - void *array; -} LU_stack_t; - -typedef struct { - int *panel_histo; /* histogram of panel size distribution */ - double *utime; /* running time at various phases */ - flops_t *ops; /* operation count at various phases */ - int TinyPivots; /* number of tiny pivots */ - int RefineSteps; /* number of iterative refinement steps */ - int expansions; /* number of memory expansions */ -} SuperLUStat_t; - -typedef struct { - float for_lu; - float total_needed; -} mem_usage_t; - - -/*********************************************************************** - * Prototypes - ***********************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif - -extern void Destroy_SuperMatrix_Store(SuperMatrix *); -extern void Destroy_CompCol_Matrix(SuperMatrix *); -extern void Destroy_CompRow_Matrix(SuperMatrix *); -extern void Destroy_SuperNode_Matrix(SuperMatrix *); -extern void Destroy_CompCol_Permuted(SuperMatrix *); -extern void Destroy_Dense_Matrix(SuperMatrix *); -extern void get_perm_c(int, SuperMatrix *, int *); -extern void set_default_options(superlu_options_t *options); -extern void ilu_set_default_options(superlu_options_t *options); -extern void sp_preorder (superlu_options_t *, SuperMatrix*, int*, int*, - SuperMatrix*); -extern void superlu_abort_and_exit(char*); -extern void *superlu_malloc (size_t); -extern int *intMalloc (int); -extern int *intCalloc (int); -extern void superlu_free (void*); -extern void SetIWork (int, int, int, int *, int **, int **, int **, - int **, int **, int **, int **); -extern int sp_coletree (int *, int *, int *, int, int, int *); -extern void relax_snode (const int, int *, const int, int *, int *); -extern void heap_relax_snode (const int, int *, const int, int *, int *); -extern int mark_relax(int, int *, int *, int *, int *, int *, int *); -extern void ilu_relax_snode (const int, int *, const int, int *, - int *, int *); -extern void ilu_heap_relax_snode (const int, int *, const int, int *, - int *, int*); -extern void resetrep_col (const int, const int *, int *); -extern int spcoletree (int *, int *, int *, int, int, int *); -extern int *TreePostorder (int, int *); -extern double SuperLU_timer_ (); -extern int sp_ienv (int); -extern int lsame_ (char *, char *); -extern int xerbla_ (char *, int *); -extern void ifill (int *, int, int); -extern void snode_profile (int, int *); -extern void super_stats (int, int *); -extern void check_repfnz(int, int, int, int *); -extern void PrintSumm (char *, int, int, int); -extern void StatInit(SuperLUStat_t *); -extern void StatPrint (SuperLUStat_t *); -extern void StatFree(SuperLUStat_t *); -extern void print_panel_seg(int, int, int, int, int *, int *); -extern int print_int_vec(char *,int, int *); -extern int slu_PrintInt10(char *, int, int *); - -#ifdef __cplusplus - } -#endif - -#endif /* __SUPERLU_UTIL */ diff --git a/src/external/arpack++/include/armat.h b/src/external/arpack++/include/armat.h deleted file mode 100644 index 52df53e3..00000000 --- a/src/external/arpack++/include/armat.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARMat.h - Generic matrix template with a matrix-vector product. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARMAT_H -#define ARMAT_H - -template<class ARTYPE> -class ARMatrix { - - protected: - - int m, n; // Number of rows and columns. - bool defined; - - public: - - ARMatrix() { defined = false; } - // Short constructor. - - ARMatrix(int nrows, int ncols = 0) - // Long constructor. - { - m = nrows; - n = (ncols?ncols:nrows); - defined = false; - } // Constructor. - - virtual ~ARMatrix() { } - // Destructor. - - int nrows() { return m; } - - int ncols() { return n; } - - bool IsDefined() { return defined; } - - virtual void MultMv(ARTYPE* v, ARTYPE* w) = 0; - // Matrix-vector product: w = A*v. - -}; // ARMatrix. - -#endif // ARMAT_H - diff --git a/src/external/arpack++/include/arpackf.h b/src/external/arpack++/include/arpackf.h deleted file mode 100644 index 6445b469..00000000 --- a/src/external/arpack++/include/arpackf.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE arpackf.h - ARPACK FORTRAN routines. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARPACKF_H -#define ARPACKF_H - -#include "arch.h" - -extern "C" -{ - -// debug "common" statement. - - extern struct { - ARint logfil, ndigit, mgetv0; - ARint msaupd, msaup2, msaitr, mseigt, msapps, msgets, mseupd; - ARint mnaupd, mnaup2, mnaitr, mneigt, mnapps, mngets, mneupd; - ARint mcaupd, mcaup2, mcaitr, mceigt, mcapps, mcgets, mceupd; - } F77NAME(debug); - - -// double precision symmetric routines. - - void F77NAME(dsaupd)(ARint *ido, char *bmat, ARint *n, const char *which, - ARint *nev, double *tol, double *resid, - ARint *ncv, double *V, ARint *ldv, - ARint *iparam, ARint *ipntr, double *workd, - double *workl, ARint *lworkl, ARint *info); - - void F77NAME(dseupd)(ARlogical *rvec, char *HowMny, ARlogical *select, - double *d, double *Z, ARint *ldz, - double *sigma, char *bmat, ARint *n, - const char *which, ARint *nev, double *tol, - double *resid, ARint *ncv, double *V, - ARint *ldv, ARint *iparam, ARint *ipntr, - double *workd, double *workl, - ARint *lworkl, ARint *info); - -// double precision nonsymmetric routines. - - void F77NAME(dnaupd)(ARint *ido, char *bmat, ARint *n, const char *which, - ARint *nev, double *tol, double *resid, - ARint *ncv, double *V, ARint *ldv, - ARint *iparam, ARint *ipntr, double *workd, - double *workl, ARint *lworkl, ARint *info); - - void F77NAME(dneupd)(ARlogical *rvec, char *HowMny, ARlogical *select, - double *dr, double *di, double *Z, - ARint *ldz, double *sigmar, - double *sigmai, double *workev, - char *bmat, ARint *n, const char *which, - ARint *nev, double *tol, double *resid, - ARint *ncv, double *V, ARint *ldv, - ARint *iparam, ARint *ipntr, - double *workd, double *workl, - ARint *lworkl, ARint *info); - -// single precision symmetric routines. - - void F77NAME(ssaupd)(ARint *ido, char *bmat, ARint *n, const char *which, - ARint *nev, float *tol, float *resid, - ARint *ncv, float *V, ARint *ldv, - ARint *iparam, ARint *ipntr, float *workd, - float *workl, ARint *lworkl, ARint *info); - - void F77NAME(sseupd)(ARlogical *rvec, char *HowMny, ARlogical *select, - float *d, float *Z, ARint *ldz, - float *sigma, char *bmat, ARint *n, - const char *which, ARint *nev, float *tol, - float *resid, ARint *ncv, float *V, - ARint *ldv, ARint *iparam, ARint *ipntr, - float *workd, float *workl, - ARint *lworkl, ARint *info); - -// single precision nonsymmetric routines. - - void F77NAME(snaupd)(ARint *ido, char *bmat, ARint *n, const char *which, - ARint *nev, float *tol, float *resid, - ARint *ncv, float *V, ARint *ldv, - ARint *iparam, ARint *ipntr, float *workd, - float *workl, ARint *lworkl, ARint *info); - - void F77NAME(sneupd)(ARlogical *rvec, char *HowMny, ARlogical *select, - float *dr, float *di, float *Z, - ARint *ldz, float *sigmar, - float *sigmai, float *workev, char *bmat, - ARint *n, const char *which, ARint *nev, - float *tol, float *resid, ARint *ncv, - float *V, ARint *ldv, ARint *iparam, - ARint *ipntr, float *workd, float *workl, - ARint *lworkl, ARint *info); - -#ifdef ARCOMP_H - -// single precision complex routines. - - void F77NAME(cnaupd)(ARint *ido, char *bmat, ARint *n, const char *which, - ARint *nev, float *tol, arcomplex<float> *resid, - ARint *ncv, arcomplex<float> *V, ARint *ldv, - ARint *iparam, ARint *ipntr, arcomplex<float> *workd, - arcomplex<float> *workl, ARint *lworkl, - float *rwork, ARint *info); - - void F77NAME(cneupd)(ARlogical *rvec, char *HowMny, ARlogical *select, - arcomplex<float> *d, arcomplex<float> *Z, ARint *ldz, - arcomplex<float> *sigma, arcomplex<float> *workev, - char *bmat, ARint *n, const char *which, ARint *nev, - float *tol, arcomplex<float> *resid, ARint *ncv, - arcomplex<float> *V, ARint *ldv, ARint *iparam, - ARint *ipntr, arcomplex<float> *workd, - arcomplex<float> *workl, ARint *lworkl, - float *rwork, ARint *info); - -// double precision complex routines. - - void F77NAME(znaupd)(ARint *ido, char *bmat, ARint *n, const char *which, - ARint *nev, double *tol, arcomplex<double> *resid, - ARint *ncv, arcomplex<double> *V, ARint *ldv, - ARint *iparam, ARint *ipntr, arcomplex<double> *workd, - arcomplex<double> *workl, ARint *lworkl, - double *rwork, ARint *info); - - void F77NAME(zneupd)(ARlogical *rvec, char *HowMny, ARlogical *select, - arcomplex<double> *d, arcomplex<double> *Z, ARint *ldz, - arcomplex<double> *sigma, arcomplex<double> *workev, - char *bmat, ARint *n, const char *which, ARint *nev, - double *tol, arcomplex<double> *resid, ARint *ncv, - arcomplex<double> *V, ARint *ldv, ARint *iparam, - ARint *ipntr, arcomplex<double> *workd, - arcomplex<double> *workl, ARint *lworkl, - double *rwork, ARint *info); - -} - -#endif // ARCOMP_H - -#endif // ARPACKF_H diff --git a/src/external/arpack++/include/arrgcomp.h b/src/external/arpack++/include/arrgcomp.h deleted file mode 100644 index d3b2e3d0..00000000 --- a/src/external/arpack++/include/arrgcomp.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARRGComp.h. - Arpack++ class ARrcCompGenEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARRGCOMP_H -#define ARRGCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arrscomp.h" -#include "arrgeig.h" - -template<class ARFLOAT> -class ARrcCompGenEig: - virtual public ARrcGenEig<ARFLOAT, arcomplex<ARFLOAT> >, - virtual public ARrcCompStdEig<ARFLOAT> { - - public: - - // a) Constructors and destructor. - - ARrcCompGenEig() { } - // Short constructor (Does nothing but calling base classes constructors). - - ARrcCompGenEig(int np, int nevp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARrcCompGenEig(int np, int nevp, arcomplex<ARFLOAT> sigmap, - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, arcomplex<ARFLOAT>* residp = NULL, - bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARrcCompGenEig(const ARrcCompGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARrcCompGenEig() { } - // Destructor. - - // b) Operators. - - ARrcCompGenEig& operator=(const ARrcCompGenEig& other); - // Assignment operator. - -}; // class ARrcCompGenEig. - - -// ------------------------------------------------------------------------ // -// ARrcCompGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline ARrcCompGenEig<ARFLOAT>:: -ARrcCompGenEig(int np, int nevp, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARrcCompGenEig<ARFLOAT>:: -ARrcCompGenEig(int np, int nevp, arcomplex<ARFLOAT> sigmap, const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shif and invert mode). - - -template<class ARFLOAT> -ARrcCompGenEig<ARFLOAT>& ARrcCompGenEig<ARFLOAT>:: -operator=(const ARrcCompGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARRGCOMP_H - diff --git a/src/external/arpack++/include/arrgeig.h b/src/external/arpack++/include/arrgeig.h deleted file mode 100644 index d9c709ec..00000000 --- a/src/external/arpack++/include/arrgeig.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARRGEig.h. - Arpack++ class ARrcGenEig definition. - Derived from ARrcStdEig, this class implements the - reverse communication interface for generalized problems. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARRGEIG_H -#define ARRGEIG_H - -#include "arch.h" -#include "arerror.h" -#include "arrseig.h" - -// ARrcGenEig class definition. - -template<class ARFLOAT, class ARTYPE> -class ARrcGenEig: virtual public ARrcStdEig<ARFLOAT, ARTYPE> { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - void NoShift(); - // Turns the problem to regular mode. - - - // a.2) Constructors and destructor. - - ARrcGenEig(); - // Short constructor that does almost nothing. - - ARrcGenEig(const ARrcGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARrcGenEig() { } - // Destructor (presently meaningless). - - // b) Operators. - - ARrcGenEig& operator=(const ARrcGenEig& other); - // Assignment operator. - -}; // class ARrcGenEig. - - -// ------------------------------------------------------------------------ // -// ARrcGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcGenEig<ARFLOAT, ARTYPE>::NoShift() -{ - - this->sigmaR = (ARTYPE)0; - this->sigmaI = 0.0; - this->mode = 2; - this->iparam[7] = this->mode; - this->Restart(); - -} // NoShift. - - -template<class ARFLOAT, class ARTYPE> -inline ARrcGenEig<ARFLOAT, ARTYPE>::ARrcGenEig() -{ - - this->bmat = 'G'; // This is a generalized problem. - this->NoShift(); - -} // Short constructor. - - -template<class ARFLOAT, class ARTYPE> -ARrcGenEig<ARFLOAT, ARTYPE>& ARrcGenEig<ARFLOAT, ARTYPE>:: -operator=(const ARrcGenEig<ARFLOAT, ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARRGEIG_H - diff --git a/src/external/arpack++/include/arrgnsym.h b/src/external/arpack++/include/arrgnsym.h deleted file mode 100644 index 1dbd3be7..00000000 --- a/src/external/arpack++/include/arrgnsym.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARRGNSym.h. - Arpack++ class ARrcNonSymGenEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARRGNSYM_H -#define ARRGNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arrsnsym.h" -#include "arrgeig.h" - -template<class ARFLOAT> -class ARrcNonSymGenEig: - virtual public ARrcGenEig<ARFLOAT, ARFLOAT>, - virtual public ARrcNonSymStdEig<ARFLOAT> { - - protected: - - // a) Protected variables: - - char part; - - - // b) Protected functions: - - char CheckPart(char partp); - - virtual void Copy(const ARrcNonSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that provides access to internal variables' values. - - ARFLOAT GetShiftImag() { return this->sigmaI; } - // Returns the imaginary part of the shift (when in shift and invert mode). - - - // c.2) Functions that allow changes in problem parameters. - - void ChangePart(char partp); - // Changes "part" to 'R' (real) or 'I' (imaginary). - - virtual void ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp = 0.0); - // Turns the problem to shift-and-invert mode - // with shift defined by sigmaRp and sigmaIp. - - virtual void SetShiftInvertMode(ARFLOAT sigmaRp); - // Turns the problem to real shift-and-invert mode with sigmaRp as shift. - - virtual void SetComplexShiftMode(char partp, ARFLOAT sigmaRp, - ARFLOAT sigmaIp); - // Turns the problem to complex shift-and-invert mode with shift - // defined by sigmaRp and sigmaIp. - - - // c.3) Constructors and destructor. - - ARrcNonSymGenEig() { part = 'R'; } - // Short constructor that does almost nothing. - - ARrcNonSymGenEig(int np, int nevp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARrcNonSymGenEig(int np, int nevp, ARFLOAT sigmap, - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, ARFLOAT* residp = NULL, - bool ishiftp = true); - // Long constructor (real shift and invert mode). - - ARrcNonSymGenEig(int np, int nevp, - char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp, - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, ARFLOAT* residp = NULL, - bool ishiftp = true); - // Long constructor (complex shift and invert mode). - - ARrcNonSymGenEig(const ARrcNonSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARrcNonSymGenEig() { } - // Destructor. - - // d) Operators. - - ARrcNonSymGenEig& operator=(const ARrcNonSymGenEig& other); - // Assignment operator. - -}; // class ARrcNonSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARrcNonSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline char ARrcNonSymGenEig<ARFLOAT>::CheckPart(char partp) -{ - if ((partp != 'R') && (partp != 'I')) { - throw ArpackError(ArpackError::PART_UNDEFINED); - } - return partp; -} // CheckPart. - - -template<class ARFLOAT> -inline void ARrcNonSymGenEig<ARFLOAT>:: -Copy(const ARrcNonSymGenEig<ARFLOAT>& other) -{ - - ARrcStdEig<ARFLOAT, ARFLOAT>::Copy(other); - part = other.part; - -} // Copy. - - -template<class ARFLOAT> -inline void ARrcNonSymGenEig<ARFLOAT>::ChangePart(char partp) -{ - - part = CheckPart(partp); - if (part == 'R') { - this->mode = 3; // Real part. - } - else { - this->mode = 4; // Imaginary part. - } - this->iparam[7] = this->mode; - this->Restart(); - -} // ChangePart. - - -template<class ARFLOAT> -inline void ARrcNonSymGenEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = sigmaIp; - ChangePart(part); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARrcNonSymGenEig<ARFLOAT>:: -SetShiftInvertMode(ARFLOAT sigmaRp) -{ - - part = 'R'; - ChangeShift(sigmaRp); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARrcNonSymGenEig<ARFLOAT>:: -SetComplexShiftMode(char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - part = CheckPart(partp); - ChangeShift(sigmaRp, sigmaIp); - -} // SetComplexShiftMode. - - -template<class ARFLOAT> -inline ARrcNonSymGenEig<ARFLOAT>:: -ARrcNonSymGenEig(int np, int nevp, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) -{ - - part = 'R'; // Considering mode = 3 in ChangeShift. - this->NoShift(); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARrcNonSymGenEig<ARFLOAT>:: -ARrcNonSymGenEig(int np, int nevp, ARFLOAT sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) -{ - - SetShiftInvertMode(sigmap); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - - -} // Long constructor (real shift and invert mode). - - -template<class ARFLOAT> -inline ARrcNonSymGenEig<ARFLOAT>:: -ARrcNonSymGenEig(int np, int nevp, char partp, ARFLOAT sigmaRp, - ARFLOAT sigmaIp, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) -{ - - SetComplexShiftMode(partp, sigmaRp, sigmaIp); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARrcNonSymGenEig<ARFLOAT>& ARrcNonSymGenEig<ARFLOAT>:: -operator=(const ARrcNonSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARRGNSYM_H - diff --git a/src/external/arpack++/include/arrgsym.h b/src/external/arpack++/include/arrgsym.h deleted file mode 100644 index 86f110d8..00000000 --- a/src/external/arpack++/include/arrgsym.h +++ /dev/null @@ -1,236 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARRGSym.h. - Arpack++ class ARrcSymGenEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARRGSYM_H -#define ARRGSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arrssym.h" -#include "arrgeig.h" - -template<class ARFLOAT> -class ARrcSymGenEig: - virtual public ARrcGenEig<ARFLOAT, ARFLOAT>, - virtual public ARrcSymStdEig<ARFLOAT> { - - protected: - - // a) Protected variable: - - char InvertMode; - - - // b) Protected functions: - - char CheckInvertMode(char InvertModep); - - virtual void Copy(const ARrcSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - void ChangeInvertMode(char InvertModep); - // Changes "InvertMode" to 'S' (shift-and-invert), - // 'B' (buckling) or 'C' (cayley) mode. - - virtual void ChangeShift(ARFLOAT sigmap); - // Changes shift value. - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - // Turns problem to shift and invert mode with shift defined by sigmap. - - virtual void SetBucklingMode(ARFLOAT sigmap); - // Turns problem to buckling mode with shift defined by sigmap. - - virtual void SetCayleyMode(ARFLOAT sigmap); - // Turns problem to Cayley mode with shift defined by sigmap. - - - // c.2) Constructors and destructor. - - ARrcSymGenEig() { InvertMode = 'S'; } - // Short constructor that does almost nothing. - - ARrcSymGenEig(int np, int nevp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARrcSymGenEig(char invertmodep, int np, int nevp, ARFLOAT sigmap, - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift-and-invert, buckling and Cayley modes). - - ARrcSymGenEig(const ARrcSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARrcSymGenEig() { } - // Destructor. - - // d) Operators. - - ARrcSymGenEig& operator=(const ARrcSymGenEig& other); - // Assignment operator. - -}; // class ARrcSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARrcSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline char ARrcSymGenEig<ARFLOAT>::CheckInvertMode(char InvertModep) -{ - if ((InvertModep != 'S') && (InvertModep != 'B') && (InvertModep != 'C')) { - throw ArpackError(ArpackError::INVMODE_UNDEFINED); - } - return InvertModep; - -} // CheckInvertMode. - - -template<class ARFLOAT> -inline void ARrcSymGenEig<ARFLOAT>::Copy(const ARrcSymGenEig<ARFLOAT>& other) -{ - - ARrcStdEig<ARFLOAT, ARFLOAT>::Copy(other); - InvertMode = other.InvertMode; - -} // Copy. - - -template<class ARFLOAT> -inline void ARrcSymGenEig<ARFLOAT>::ChangeInvertMode(char InvertModep) -{ - - InvertMode = CheckInvertMode(InvertModep); - switch (InvertMode) { - case 'S': - this->mode = 3; // Shift and invert mode. - break; - case 'B': - this->mode = 4; // Buckling mode. - break; - case 'C': - this->mode = 5; // Cayley mode. - break; - } - this->iparam[7] = this->mode; - this->Restart(); - -} // ChangeInvertMode. - - -template<class ARFLOAT> -inline void ARrcSymGenEig<ARFLOAT>::ChangeShift(ARFLOAT sigmap) -{ - - this->sigmaR = sigmap; - this->sigmaI = 0.0; - ChangeInvertMode(InvertMode); - -} // ChangeShift. - - -template<class ARFLOAT> -void ARrcSymGenEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) - -{ - - InvertMode = 'S'; - ChangeShift(sigmap); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -void ARrcSymGenEig<ARFLOAT>::SetBucklingMode(ARFLOAT sigmap) - -{ - - InvertMode = 'B'; - ChangeShift(sigmap); - -} // SetBucklingMode. - - -template<class ARFLOAT> -void ARrcSymGenEig<ARFLOAT>::SetCayleyMode(ARFLOAT sigmap) - -{ - - InvertMode = 'C'; - ChangeShift(sigmap); - -} // SetCayleyMode. - - -template<class ARFLOAT> -inline ARrcSymGenEig<ARFLOAT>:: -ARrcSymGenEig(int np, int nevp, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - InvertMode = 'S'; // Considering mode = 3 in ChangeShift. - this->NoShift(); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARrcSymGenEig<ARFLOAT>:: -ARrcSymGenEig(char InvertModep, int np, int nevp, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - InvertMode = CheckInvertMode(InvertModep); // InvertMode = 'S', 'B', 'C'. - ChangeShift(sigmap); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift-and-invert, buckling and Cayley modes). - - -template<class ARFLOAT> -ARrcSymGenEig<ARFLOAT>& ARrcSymGenEig<ARFLOAT>:: -operator=(const ARrcSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARRGSYM_H - diff --git a/src/external/arpack++/include/arrscomp.h b/src/external/arpack++/include/arrscomp.h deleted file mode 100644 index 40977551..00000000 --- a/src/external/arpack++/include/arrscomp.h +++ /dev/null @@ -1,375 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARRSComp.h. - Arpack++ class ARrcCompStdEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARRSCOMP_H -#define ARRSCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arerror.h" -#include "debug.h" -#include "arrseig.h" -#include "caupp.h" -#include "ceupp.h" - -template<class ARFLOAT> -class ARrcCompStdEig: virtual public ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> > { - - protected: - - // a) Protected functions: - - // a.1) Memory control functions. - - void WorkspaceAllocate(); - // Allocates workspace for complex problems. - - - // a.2) Functions that handle original FORTRAN ARPACK code. - - void Aupp(); - // Interface to FORTRAN subroutines CNAUPD and ZNAUPD. - - void Eupp(); - // Interface to FORTRAN subroutines CNEUPD and ZNEUPD. - - public: - - // b) Public functions: - - // b.1) Trace functions. - - void Trace(const int digit = -5, const int getv0 = 0, const int aupd = 1, - const int aup2 = 0, const int aitr = 0, const int eigt = 0, - const int apps = 0, const int gets = 0, const int eupd = 0) - { - cTraceOn(digit, getv0, aupd, aup2, aitr, eigt, apps, gets, eupd); - } - // Turns on trace mode. - - - // b.2) Functions that perform all calculations in one step. - - int Eigenvalues(arcomplex<ARFLOAT>* &EigValp, bool ivec = false, - bool ischur = false); - // Overrides array EigValp with the eigenvalues of the problem. - // Also calculates eigenvectors and Schur vectors if requested. - - int EigenValVectors(arcomplex<ARFLOAT>* &EigVecp, - arcomplex<ARFLOAT>* &EigValp, bool ischur = false); - // Overrides array EigVecp sequentially with the eigenvectors of the - // given eigen-problem. Also stores the eigenvalues in EigValp. - // Calculates Schur vectors if requested. - - - // b.3) Functions that return elements of vectors and matrices. - - arcomplex<ARFLOAT> Eigenvalue(int i); - // Provides i-eth eigenvalue. - - arcomplex<ARFLOAT> Eigenvector(int i, int j); - // Provides element j of the i-eth eigenvector. - - - // b.4) Functions that use STL vector class. - -#ifdef STL_VECTOR_H - - vector<arcomplex<ARFLOAT> >* StlEigenvalues(bool ivec = false, - bool ischur = false); - // Calculates the eigenvalues and stores them in a single STL vector. - // Also calculates eigenvectors and Schur vectors if requested. - - vector<arcomplex<ARFLOAT> >* StlEigenvector(int i); - // Returns the i-th eigenvector in a STL vector. - -#endif // #ifdef STL_VECTOR_H. - - - // b.5) Constructors and destructor. - - ARrcCompStdEig() { } - // Short constructor. - - ARrcCompStdEig(int np, int nevp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARrcCompStdEig(int np, int nevp, arcomplex<ARFLOAT> sigma, - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, arcomplex<ARFLOAT>* residp = NULL, - bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARrcCompStdEig(const ARrcCompStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARrcCompStdEig() { } - // Destructor. - - // c) Operators. - - ARrcCompStdEig& operator=(const ARrcCompStdEig& other); - // Assignment operator. - -}; // class ARrcCompStdEig. - - -// ------------------------------------------------------------------------ // -// ARrcCompStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARrcCompStdEig<ARFLOAT>::WorkspaceAllocate() -{ - - this->lworkl = this->ncv*(3*this->ncv+6); - this->lworkv = 2*this->ncv; - this->lrwork = this->ncv; - this->workl = new arcomplex<ARFLOAT>[this->lworkl+1]; - this->workv = new arcomplex<ARFLOAT>[this->lworkv+1]; - this->rwork = new ARFLOAT[this->lrwork+1]; - -} // WorkspaceAllocate. - - -template<class ARFLOAT> -inline void ARrcCompStdEig<ARFLOAT>::Aupp() -{ - - caupp(this->ido, this->bmat, this->n, this->which, this->nev, this->tol, this->resid, this->ncv, this->V, this->n, - this->iparam, this->ipntr, this->workd, this->workl, this->lworkl, this->rwork, this->info); - -} // Aupp. - - -template<class ARFLOAT> -inline void ARrcCompStdEig<ARFLOAT>::Eupp() -{ - - ceupp(this->rvec, this->HowMny, this->EigValR, this->EigVec, this->n, this->sigmaR, this->workv, - this->bmat, this->n, this->which, this->nev, this->tol, this->resid, this->ncv, this->V, this->n, this->iparam, - this->ipntr, this->workd, this->workl, this->lworkl, this->rwork, this->info); - -} // Eupp. - - -template<class ARFLOAT> -int ARrcCompStdEig<ARFLOAT>:: -Eigenvalues(arcomplex<ARFLOAT>* &EigValp, bool ivec, bool ischur) -{ - - if (this->ValuesOK) { // Eigenvalues are available . - if (EigValp == NULL) { // Moving eigenvalues. - EigValp = this->EigValR; - this->EigValR = NULL; - this->newVal = false; - this->ValuesOK = false; - } - else { // Copying eigenvalues. - copy(this->nconv,this->EigValR,1,EigValp,1); - } - } - else { - if (this->newVal) { - delete[] this->EigValR; - this->newVal = false; - } - if (EigValp == NULL) { - try { EigValp = new arcomplex<ARFLOAT>[this->ValSize()]; } - catch (ArpackError) { return 0; } - } - this->EigValR = EigValp; - if (ivec) { // Finding eigenvalues and eigenvectors. - this->nconv = this->FindEigenvectors(ischur); - } - else { // Finding eigenvalues only. - this->nconv = this->FindEigenvalues(); - } - this->EigValR = NULL; - } - return this->nconv; - -} // Eigenvalues(EigValp, ivec, ischur). - - -template<class ARFLOAT> -int ARrcCompStdEig<ARFLOAT>:: -EigenValVectors(arcomplex<ARFLOAT>* &EigVecp, arcomplex<ARFLOAT>* &EigValp, - bool ischur) -{ - - if (this->ValuesOK) { // Eigenvalues are already available. - this->nconv = Eigenvalues(EigValp, false); - this->nconv = this->Eigenvectors(EigVecp, ischur); - } - else { // Eigenvalues and vectors are not available. - if (this->newVec) { - delete[] this->EigVec; - this->newVec = false; - } - if (this->newVal) { - delete[] this->EigValR; - this->newVal = false; - } - try { - if (EigVecp == NULL) EigVecp = new arcomplex<ARFLOAT>[this->ValSize()*this->n]; - if (EigValp == NULL) EigValp = new arcomplex<ARFLOAT>[this->ValSize()]; - } - catch (ArpackError) { return 0; } - this->EigVec = EigVecp; - this->EigValR = EigValp; - this->nconv = this->FindEigenvectors(ischur); - this->EigVec = NULL; - this->EigValR = NULL; - } - return this->nconv; - -} // EigenValVectors(EigVecp, EigValp, ischur). - - -template<class ARFLOAT> -inline arcomplex<ARFLOAT> ARrcCompStdEig<ARFLOAT>::Eigenvalue(int i) -// calcula e retorna um autovalor. - -{ - - // Returning i-eth eigenvalue. - - if (!this->ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "Eigenvalue(i)"); - } - else if ((i>=this->nconv)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "Eigenvalue(i)"); - } - return this->EigValR[i]; - -} // Eigenvalue(i). - - -template<class ARFLOAT> -inline arcomplex<ARFLOAT> ARrcCompStdEig<ARFLOAT>:: -Eigenvector(int i, int j) -{ - - // Returning element j of i-eth eigenvector. - - if (!this->VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "Eigenvector(i,j)"); - } - else if ((i>=this->nconv)||(i<0)||(j>=this->n)||(j<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "Eigenvector(i,j)"); - } - return this->EigVec[i*this->n+j]; - -} // Eigenvector(i,j). - - -#ifdef STL_VECTOR_H - -template<class ARFLOAT> -inline vector<arcomplex<ARFLOAT> >* ARrcCompStdEig<ARFLOAT>:: -StlEigenvalues(bool ivec, bool ischur) -{ - - // Returning the eigenvalues in a STL vector. - - vector<arcomplex<ARFLOAT> >* ValR; - arcomplex<ARFLOAT>* ValPtr; - - try { - ValR = new vector<arcomplex<ARFLOAT> >(ValSize()); - } - catch (ArpackError) { return NULL; } - ValPtr = ValR->begin(); - nconv = Eigenvalues(ValPtr, ivec, ischur); - return ValR; - -} // StlEigenvalues. - - -template<class ARFLOAT> -inline vector<arcomplex<ARFLOAT> >* ARrcCompStdEig<ARFLOAT>:: -StlEigenvector(int i) -{ - - // Returning the i-th eigenvector in a STL vector. - - vector<arcomplex<ARFLOAT> >* Vec; - - if (!VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "StlEigenvector(i)"); - } - else if ((i>=ValSize())||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "StlEigenvector(i)"); - } - try { - Vec = new vector<arcomplex<ARFLOAT> >(&EigVec[i*n], &EigVec[(i+1)*n]); - } - catch (ArpackError) { return NULL; } - return Vec; - -} // StlEigenvector(i). - -#endif // #ifdef STL_VECTOR_H. - - -template<class ARFLOAT> -inline ARrcCompStdEig<ARFLOAT>:: -ARrcCompStdEig(int np, int nevp, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARrcCompStdEig<ARFLOAT>:: -ARrcCompStdEig(int np, int nevp, arcomplex<ARFLOAT> sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, int maxitp, - arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARrcCompStdEig<ARFLOAT>& ARrcCompStdEig<ARFLOAT>:: -operator=(const ARrcCompStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARRSCOMP_H - diff --git a/src/external/arpack++/include/arrseig.h b/src/external/arpack++/include/arrseig.h deleted file mode 100644 index 57cba476..00000000 --- a/src/external/arpack++/include/arrseig.h +++ /dev/null @@ -1,1515 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARRSEig.h. - Arpack++ base class ARrcStdEig definition. - This class implements c++ version of the reverse - communication interface for standard problems. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARRSEIG_H -#define ARRSEIG_H - -#include <new> -#include <cstddef> -#include <string> -#include "arch.h" -#include "arerror.h" -#include "debug.h" -#include "blas1c.h" - - -// ARrcStdEig class definition. - -template<class ARFLOAT, class ARTYPE> -class ARrcStdEig { - - protected: - - // a) Protected variables: - - // a.1) User defined parameters. - - int n; // Dimension of the eigenproblem. - int nev; // Number of eigenvalues to be computed. 0 < nev < n-1. - int ncv; // Number of Arnoldi vectors generated at each iteration. - int maxit; // Maximum number of Arnoldi update iterations allowed. - std::string which; // Specify which of the Ritz values of OP to compute. - ARFLOAT tol; // Stopping criterion (relative accuracy of Ritz values). - ARFLOAT sigmaI; // Imaginary part of shift (for nonsymmetric problems). - ARTYPE sigmaR; // Shift (real part only if problem is nonsymmetric). - ARTYPE *resid; // Initial residual vector. - - - // a.2) Internal variables. - - bool rvec; // Indicates if eigenvectors/Schur vectors were - // requested (or only eigenvalues will be determined). - bool newRes; // Indicates if a new "resid" vector was created. - bool newVal; // Indicates if a new "EigValR" vector was created. - bool newVec; // Indicates if a new "EigVec" vector was created. - bool PrepareOK; // Indicates if internal variables were correctly set. - bool BasisOK; // Indicates if an Arnoldi basis was found. - bool ValuesOK; // Indicates if eigenvalues were calculated. - bool VectorsOK; // Indicates if eigenvectors were determined. - bool SchurOK; // Indicates if Schur vectors were determined. - bool AutoShift; // Indicates if implicit shifts will be generated - // internally (or will be supplied by the user). - char bmat; // Indicates if the problem is a standard ('I') or - // generalized ('G") eigenproblem. - char HowMny; // Indicates if eigenvectors ('A') or Schur vectors ('P') - // were requested (not referenced if rvec = false). - int ido; // Original ARPACK reverse communication flag. - int info; // Original ARPACK error flag. - int mode; // Indicates the type of the eigenproblem (regular, - // shift and invert, etc). - int lworkl; // Dimension of array workl. - int lworkv; // Dimension of array workv. - int lrwork; // Dimension of array rwork. - int iparam[12]; // Vector that handles original ARPACK parameters. - int ipntr[15]; // Vector that handles original ARPACK pointers. - ARFLOAT *rwork; // Original ARPACK internal vector. - ARTYPE *workl; // Original ARPACK internal vector. - ARTYPE *workd; // Original ARPACK internal vector. - ARTYPE *workv; // Original ARPACK internal vector. - ARTYPE *V; // Arnoldi basis / Schur vectors. - - - // a.3) Pure output variables. - - int nconv; // Number of "converged" Ritz values. - ARFLOAT *EigValI; // Imaginary part of eigenvalues (nonsymmetric problems). - ARTYPE *EigValR; // Eigenvalues (real part only if problem is nonsymmetric). - ARTYPE *EigVec; // Eigenvectors. - - - // b) Protected functions: - - // b.1) Memory control functions. - - bool OverV() { return (EigVec == &V[1]); } - // Indicates whether EigVec overrides V or no. - - virtual int ValSize() { return nev; } - // Provides the size of array EigVal. - // Redefined in ARrcNonSymStdEig. - - void ClearFirst(); - // Clears some boolean variables in order to define a entire new problem. - - void ClearBasis(); - // Clear some boolean variables in order to recalculate the arnoldi basis. - - void ClearMem(); - // Clears workspace. - - virtual void ValAllocate(); - // Creates arrays EigValR and EigValI. - // Redefined in ARrcNonSymStdEig. - - virtual void VecAllocate(bool newV = true); - // Creates array EigVec. - - virtual void WorkspaceAllocate(); - // Function that must be defined by a derived class. - // Redefined in ARrc[Sym|NonSym|Complex]StdEig. - - - // b.2) Functions that call the original ARPACK FORTRAN code. - - virtual void Aupp() { - throw ArpackError(ArpackError::NOT_IMPLEMENTED, "Aupp"); - } - // Interface to FORTRAN subroutines __AUPD. - // Must be defined by a derived class. - // Redefined in ARrc[Sym|NonSym|Complex]StdEig. - - void AuppError(); - // Handles errors occurred in function Aupp. - - virtual void Eupp() { - throw ArpackError(ArpackError::NOT_IMPLEMENTED, "Eupp"); - } - // Interface to FORTRAN subroutines __EUPD. - // Must be defined by a derived class. - // Redefined in ARrc[Sym|NonSym|Complex]Eig. - - void EuppError(); - // Handles errors occurred in function Eupp. - - - // b.3) Functions that check user defined parameters. - - int CheckN(int np); - // Does range checking on ncv. - - int CheckNcv(int ncvp); - // Forces ncv to conform to its ranges. - - virtual int CheckNev(int nevp); - // Does range checking on nev. - // Redefined in ARrcNonSymStdEig. - - int CheckMaxit(int maxitp); - // Forces maxit to be greater than zero. - - virtual std::string CheckWhich(const std::string& whichp); - // Determines if the value of variable "which" is valid. - // Redefined in ARrcSymStdEig. - - - // b.4) Functions that set internal variables. - - void Restart(); - - virtual void Prepare(); - // Defines internal variables and allocates working arrays. - - virtual void Copy(const ARrcStdEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - public: - - // c) Public functions: - - // c.1) Function that stores user defined parameters. - - virtual void DefineParameters(int np, int nevp, const std::string& whichp="LM", - int ncvp=0, ARFLOAT tolp=0.0, int maxitp=0, - ARTYPE* residp=NULL, bool ishiftp=true); - // Set values of problem parameters (also called by constructors). - // Redefined in ARrcStdEig and ARrcGenEig. - - - // c.2) Functions that detect if output data is ready. - - bool ParametersDefined() { return PrepareOK; } - // Indicates if all internal variables and arrays were defined. - - bool ArnoldiBasisFound() { return BasisOK; } - // Indicates if an Arnoldi basis is available. - - bool EigenvaluesFound() { return ValuesOK; } - // Indicates if the requested eigenvalues are available. - - bool EigenvectorsFound() { return VectorsOK; } - // Indicates if the requested eigenvectors are available. - - bool SchurVectorsFound() { return SchurOK; } - // Indicates if the Schur vectors are available. - - - // c.3) Functions that provides access to internal variables' values. - - int ConvergedEigenvalues() { return nconv; } - // Provides the number of "converged" eigenvalues found so far. - - int GetMaxit() { return maxit; } - // Returns the maximum number of Arnoldi update iterations allowed. - - int GetIter(); - // Returns the actual number of Arnoldi iterations taken. - - ARFLOAT GetTol() { return tol; } - // Returns the stopping criterion. - - int GetN() { return n; } - // Returns the dimension of the problem. - - int GetNev() { return nev; } - // Returns the number of eigenvalues to be computed. - - int GetNcv() { return ncv; } - // Returns the number of Arnoldi vectors generated at each iteration.. - - const std::string& GetWhich() { return which; } - // Returns "which". - - ARTYPE GetShift() { return sigmaR; } - // Returns the shift (when in shift and invert mode). - - bool GetAutoShift() { return AutoShift; } - // Returns "AutoShift". - - int GetMode() { return mode; } - // Returns the type of problem (regular, shift and invert, etc). - - - // c.4) Functions that allow changes in problem parameters. - - void ChangeMaxit(int maxitp); - // Changes the maximum number of Arnoldi update iterations allowed. - - void ChangeTol(ARFLOAT tolp); - // Changes the stopping criterion. - - virtual void ChangeNev(int nevp); - // Changes the number of eigenvalues to be computed. - - virtual void ChangeNcv(int ncvp); - // Changes the number of Arnoldi vectors generated at each iteration.. - - virtual void ChangeWhich(const std::string& whichp); - // Changes "which". - - virtual void ChangeShift(ARTYPE sigmaRp); - // Turns the problem to shift-and-invert mode with shift defined by sigmaRp. - // Redefined in many derived classes. - - virtual void NoShift(); - // Turns the problem to regular mode. - // Redefined in ARrcGenEig. - - void InvertAutoShift(); - // Inverts "AutoShift". - - virtual void SetRegularMode() { NoShift(); } - // Turns problem to regular mode. - - virtual void SetShiftInvertMode(ARTYPE sigmaRp) { ChangeShift(sigmaRp); } - // Turns problem to regular mode. - - // c.5) Trace functions. - - virtual void Trace() { - throw ArpackError(ArpackError::NOT_IMPLEMENTED, "Trace"); - } - // Turns on trace mode. - // Must be defined by a derived class. - // Redefined in ARrc[Sym|NonSym|Complex]StdEig. - - void NoTrace() { TraceOff(); } - // Turns off trace mode. - - - // c.6) Functions that permit step by step execution of ARPACK. - - int GetNp() { return iparam[8]; } - // Returns the number of shifts that must be supplied after a call to - // TakeStep() when shifts are provided by the user (AutoShift = false). - - int GetIdo() { return ido; } - // Indicates the type of operation the user must perform between two - // successive calls to function TakeStep(). - // ido = -1: compute y = OP*x, where GetVector() gives a pointer to the - // vector x, and PutVector() indicates where to store y. - // ido = 1: compute y = OP*x, where GetVector() gives a pointer to the - // vector x, and PutVector() indicates where to store y. - // When solving generalized problems, a pointer to the product - // B*x is also available by using GetProd(). - // ido = 2: compute y = B*x, where GetVector() gives a pointer to the - // vector x, and PutVector() indicates where to store y. - // ido = 3: compute shifts, where PutVector() indicates where to store them. - - virtual ARTYPE* GetVector(); - // When ido = -1, 1 or 2 and the user must perform a product in the form - // y <- M*x, this function indicates where x is stored. When ido = 3, this - // function indicates where the eigenvalues of the current Hessenberg - // matrix are located. - - ARTYPE* GetProd(); - // When ido = 1 and the user must perform a product in the form - // y <- M*B*x, this function indicates where B*x is stored. - - virtual ARTYPE* PutVector(); - // When ido = -1, 1 or 2 and the user must perform a product in the form - // y <- M*x, this function indicates where to store y. When ido = 3, this - // function indicates where to store the shifts. - // Redefined in ARrcSymStdEig. - - virtual int TakeStep(); - // Calls Aupp once if there is no Arnoldi basis available. - - - // c.7) Functions that perform final calculations. - - virtual int FindArnoldiBasis(); - // Determines the Arnoldi basis related to the given problem. - // This function has no meaning for this class. It is maintained - // here for compatibility with all derived classes. - // Redefined in ARStdEig, ARGenEig and ARSymGenEig. - - virtual int FindEigenvalues(); - // Determines nev approximated eigenvalues of the given eigen-problem. - // Redefined in ARNonSymGenEig. - - virtual int FindEigenvectors(bool schurp = false); - // Determines nev approximated eigenvectors of the given eigen-problem - // Optionally also determines nev Schur vectors that span the desired - // invariant subspace. - // Redefined in ARNonSymGenEig. - - virtual int FindSchurVectors(); - // Determines nev Schur vectors that span the desired invariant subspace. - // Redefined in ARrcSymStdEig and ARNonSymGenEig. - - - // c.8) Function that perform calculations using user supplied data structure. - - virtual int Eigenvectors(ARTYPE* &EigVecp, bool ischur = false); - // Overrides array EigVecp sequentially with the eigenvectors of the - // given eigen-problem. Also calculates Schur vectors if requested. - - - // c.9) Functions that return elements of vectors and matrices. - - ARTYPE ArnoldiBasisVector(int i, int j); - // Furnishes element j of the i-eth Arnoldi basis vector. - - ARTYPE SchurVector(int i, int j); - // Furnishes element j of the i-eth Schur vector. - - ARTYPE ResidualVector(int i); - // Furnishes element j of the residual vector. - - - // c.10) Functions that provide raw access to internal vectors and matrices. - - ARTYPE* RawArnoldiBasisVectors(); - // Provides raw access to Arnoldi basis vectors elements. - - ARTYPE* RawArnoldiBasisVector(int i); - // Provides raw access to Arnoldi basis vector i. - - ARTYPE* RawEigenvalues(); - // Provides raw access to eigenvalues. - - ARTYPE* RawEigenvectors(); - // Provides raw access to eigenvectors elements. - - ARTYPE* RawEigenvector(int i); - // Provides raw access to eigenvector i. - - ARTYPE* RawSchurVectors(); - // Provides raw access to Schur vectors elements. - - ARTYPE* RawSchurVector(int i); - // Provides raw access to Schur vector i. - - ARTYPE* RawResidualVector(); - // Provides raw access to residual vector elements. - - - // c.11) Functions that use STL vector class. - -#ifdef STL_VECTOR_H - - vector<ARTYPE>* StlArnoldiBasisVectors(); - // Returns a copy of the Arnoldi basis in a single STL vector. - - vector<ARTYPE>* StlArnoldiBasisVector(int i); - // Returns the i-th Arnoldi basis vector in a STL vector. - - vector<ARTYPE>* StlEigenvectors(bool ischur = false); - // Calculates the eigenvectors and stores them sequentially in a - // single STL vector. Also calculates Schur vectors if requested. - - vector<ARTYPE>* StlSchurVectors(); - // Returns a copy of the Schur vectors in a single STL vector. - - vector<ARTYPE>* StlSchurVector(int i); - // Returns the i-th Schur vector in a STL vector. - - vector<ARTYPE>* StlResidualVector(); - // Returns the residual vector in a STL vector. - -#endif // #ifdef STL_VECTOR_H. - - - // c.12) Constructors and destructor. - - ARrcStdEig(); - // Short constructor that does almost nothing. - - ARrcStdEig(const ARrcStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARrcStdEig() { ClearMem(); } - // Very simple destructor. - - // d) Operators: - - ARrcStdEig& operator=(const ARrcStdEig& other); - // Assignment operator. - -}; // class ARrcStdEig. - - -// ------------------------------------------------------------------------ // -// ARrcStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::ClearFirst() -{ - - PrepareOK = newVal = newVec = newRes = false; - -} // ClearFirst. - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::ClearBasis() -{ - - BasisOK = ValuesOK = VectorsOK = SchurOK = false; - -} // ClearBasis. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::ClearMem() -{ - - // Deleting working arrays. - - if (workl) delete[] workl; - if (workd) delete[] workd; - if (workv) delete[] workv; - if (rwork) delete[] rwork; - if (V) delete[] V; - - workl = NULL; - workd = NULL; - workv = NULL; - rwork = NULL; - V = NULL; - - // Deleting input and output arrays. - - if (newRes) { - delete[] resid; - newRes = false; - resid = NULL; // Salwen. Mar 3, 2000. - } - - if (newVal) { - delete[] EigValR; - delete[] EigValI; - newVal = false; - } - EigValR=NULL; - EigValI=NULL; - - if (newVec) { - delete[] EigVec; - newVec = false; - } - EigVec=NULL; - - // Adjusting boolean variables. - - ClearFirst(); - -} // ClearMem. - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::ValAllocate() -{ - - if (EigValR == NULL) { // Creating a new array EigValR. - EigValR = new ARTYPE[ValSize()]; - newVal = true; - } - -} // ValAllocate. - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::VecAllocate(bool newV) -{ - - if (EigVec == NULL) { - if (newV) { // Creating a new array EigVec. - EigVec = new ARTYPE[ValSize()*n]; - newVec = true; - } - else { // Using V to store EigVec. - EigVec = &V[1]; - } - } - -} // VecAllocate. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::WorkspaceAllocate() -{ - - lworkl = 0; - lworkv = 0; - lrwork = 0; - -} // WorkspaceAllocate. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::AuppError() -{ - - switch (info) { - case 0: - return; - case -8: - throw ArpackError(ArpackError::LAPACK_ERROR, "Aupp"); - case -9: - throw ArpackError(ArpackError::START_RESID_ZERO, "Aupp"); - case -9999: - throw ArpackError(ArpackError::ARNOLDI_NOT_BUILD, "Aupp"); - case 1: - ArpackError(ArpackError::MAX_ITERATIONS, "Aupp"); - return; - case 3: - ArpackError(ArpackError::NO_SHIFTS_APPLIED, "Aupp"); - return; - default : - throw ArpackError(ArpackError::AUPP_ERROR, "Aupp"); - } - -} // AuppError. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::EuppError() -{ - - switch (info) { - case 0: - return; - case -8: - case -9: - throw ArpackError(ArpackError::LAPACK_ERROR, "Eupp"); - case -14: - throw ArpackError(ArpackError::NOT_ACCURATE_EIG, "Eupp"); - case 1: - throw ArpackError(ArpackError::REORDERING_ERROR, "Eupp"); - default : - throw ArpackError(ArpackError::EUPP_ERROR, "Eupp"); - } - -} // EuppError. - - -template<class ARFLOAT, class ARTYPE> -inline int ARrcStdEig<ARFLOAT, ARTYPE>::CheckN(int np) -{ - - if (np < 2) { - throw ArpackError(ArpackError::N_SMALLER_THAN_2); - } - return np; - -} // CheckN. - - -template<class ARFLOAT, class ARTYPE> -inline int ARrcStdEig<ARFLOAT, ARTYPE>::CheckNcv(int ncvp) -{ - - // Adjusting ncv if ncv <= nev or ncv > n. - - if (ncvp < nev+1) { - if (ncvp) ArpackError::Set(ArpackError::NCV_OUT_OF_BOUNDS); - return ((2*nev+1)>n)?n:(2*nev+1); - } - else if (ncvp > n) { - ArpackError::Set(ArpackError::NCV_OUT_OF_BOUNDS); - return n; - } - else { - return ncvp; - } - -} // CheckNcv. - - -template<class ARFLOAT, class ARTYPE> -inline int ARrcStdEig<ARFLOAT, ARTYPE>::CheckNev(int nevp) -{ - - if ((nevp<1)||(nevp>=n)) { - throw ArpackError(ArpackError::NEV_OUT_OF_BOUNDS); - } - return nevp; - -} // CheckNev. - - -template<class ARFLOAT, class ARTYPE> -inline int ARrcStdEig<ARFLOAT, ARTYPE>::CheckMaxit(int maxitp) -{ - - if (maxitp >= 1) return maxitp; - if (maxitp < 0) ArpackError::Set(ArpackError::MAXIT_NON_POSITIVE); - return 100*nev; - -} // CheckMaxit. - -template<class ARFLOAT, class ARTYPE> -std::string ARrcStdEig<ARFLOAT, ARTYPE>::CheckWhich(const std::string& whichp) -{ - - switch (whichp[0]) { // The first ought to be S or L. - case 'S': - case 'L': - switch (whichp[1]) { // The second must be M, R or I. - case 'M': - case 'R': - case 'I': - return whichp; - } - default : - throw ArpackError(ArpackError::WHICH_UNDEFINED); - } - -} // CheckWhich. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::Restart() -{ - - nconv=0; // No eigenvalues found yet. - ido =0; // First call to AUPP. - iparam[1]=(int)AutoShift; // Shift strategy used. - iparam[3]=maxit; // Maximum number of Arnoldi iterations allowed. - iparam[4]=1; // Blocksize must be 1. - info =(int)(!newRes); // Starting vector used. - ClearBasis(); - -} // Restart. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::Prepare() -{ - - // Deleting old stuff. - - ClearMem(); - - // Defining internal variables. - - try { - - if (resid == NULL) { // Using a random starting vector. - resid = new ARTYPE[n]; - newRes = true; - } - - // Setting dimensions of working arrays. - - workd = new ARTYPE[3*n+1]; - V = new ARTYPE[n*ncv+1]; - WorkspaceAllocate(); - - } - catch (ArpackError) { // Returning from here if an error has occurred. - ArpackError(ArpackError::CANNOT_PREPARE, "Prepare"); - return; - } - - Restart(); - - // That's all. - - PrepareOK = true; - -} // Prepare. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT,ARTYPE>::Copy(const ARrcStdEig<ARFLOAT,ARTYPE>& other) -{ - - // Defining local variables. - - int i; - - // Copying variables that belong to fundamental types. - - n = other.n; - nev = other.nev; - ncv = other.ncv; - maxit = other.maxit; - which = other.which; - tol = other.tol; - sigmaI = other.sigmaI; - sigmaR = other.sigmaR; - rvec = other.rvec; - newRes = other.newRes; - newVal = other.newVal; - newVec = other.newVec; - PrepareOK = other.PrepareOK; - BasisOK = other.BasisOK; - ValuesOK = other.ValuesOK; - VectorsOK = other.VectorsOK; - SchurOK = other.SchurOK; - AutoShift = other.AutoShift; - bmat = other.bmat; - HowMny = other.HowMny; - ido = other.ido; - info = other.info; - mode = other.mode; - nconv = other.nconv; - - // Copying arrays with static dimension. - - for (i=0; i<12; i++) iparam[i] = other.iparam[i]; - for (i=0; i<15; i++) ipntr[i] = other.ipntr[i]; - - // Returning from here if "other" was not initialized. - - if (!PrepareOK) return; - - // Copying dynamic variables. - - workd = new ARTYPE[3*n+1]; // workd. - copy(3*n+1,other.workd,1,workd,1); - - V = new ARTYPE[n*ncv+1]; // V. - copy(n*ncv+1,other.V,1,V,1); - - if (newRes) { // resid. - resid = new ARTYPE[n]; - copy(n,other.resid,1,resid,1); - } - else { - resid = other.resid; - } - - if (newVec) { // EigVec. - EigVec = new ARTYPE[ValSize()*n]; - copy(ValSize()*n,other.EigVec,1,EigVec,1); - } - else if (other.EigVec == (&other.V[1])) { - EigVec = &V[1]; - } - else { - EigVec = other.EigVec; - } - - if (newVal) { // EigValR and EigValI. - EigValR = new ARTYPE[ValSize()]; - copy(ValSize(),other.EigValR,1,EigValR,1); - if (other.EigValI != NULL) { - EigValI = new ARFLOAT[ValSize()]; - copy(ValSize(),other.EigValI,1,EigValI,1); - } - else { - EigValI = NULL; - } - } - else { - EigValR = other.EigValR; - EigValI = other.EigValI; - } - - WorkspaceAllocate(); // lworkl, workl, workv and rwork. - if (lworkl) copy(lworkl+1,other.workl,1,workl,1); - if (lworkv) copy(lworkv+1,other.workv,1,workv,1); - if (lrwork) copy(lrwork+1,other.rwork,1,rwork,1); - -} // Copy. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>:: -DefineParameters(int np, int nevp, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARTYPE* residp, bool ishiftp) - -{ - - // Setting user defined parameters. - - try { - n = CheckN(np); - nev = ARrcStdEig::CheckNev(nevp); - ncv = ARrcStdEig::CheckNcv(ncvp); - which = ARrcStdEig::CheckWhich(whichp); - maxit = ARrcStdEig::CheckMaxit(maxitp); - tol = tolp; - resid = residp; - AutoShift = ishiftp; - } - - // Returning from here if an error has occurred. - - catch (ArpackError) { - ArpackError(ArpackError::PARAMETER_ERROR, "DefineParameter"); - return; - } - - // Setting internal variables. - - ClearFirst(); - Prepare(); - -} // DefineParameters. - - -template<class ARFLOAT, class ARTYPE> -int ARrcStdEig<ARFLOAT, ARTYPE>::GetIter() -{ - - if (BasisOK || ValuesOK || VectorsOK || SchurOK) { - return iparam[3]; - } - else { - return 0; - } - -} // GetIter. - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::ChangeMaxit(int maxitp) -{ - - maxit = CheckMaxit(maxitp); - Restart(); - -} // ChangeMaxit. - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::ChangeTol(ARFLOAT tolp) -{ - - if (tolp < tol) Restart(); - tol = tolp; - -} // ChangeTol. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::ChangeNev(int nevp) -{ - - try { - nev = CheckNev(nevp); - ncv = CheckNcv(ncv); - } - catch (ArpackError) { return; } - if (PrepareOK) Prepare(); - -} // ChangeNev. - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::ChangeNcv(int ncvp) -{ - - ncv = CheckNcv(ncvp); - if (PrepareOK) Prepare(); - -} // ChangeNcv. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::ChangeWhich(const std::string& whichp) -{ - - try { which = CheckWhich(whichp); } - catch (ArpackError) { return; } - Restart(); - -} // ChangeWhich. - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::ChangeShift(ARTYPE sigmaRp) -{ - - sigmaR = sigmaRp; - sigmaI = 0.0; - mode = 3; - iparam[7] = mode; - Restart(); - -} // ChangeShift. - - -template<class ARFLOAT, class ARTYPE> -inline void ARrcStdEig<ARFLOAT, ARTYPE>::NoShift() -{ - - sigmaR = (ARTYPE)0; - sigmaI = 0.0; - mode = 1; - iparam[7] = mode; - Restart(); - -} // NoShift. - - -template<class ARFLOAT, class ARTYPE> -void ARrcStdEig<ARFLOAT, ARTYPE>::InvertAutoShift() -{ - - AutoShift = !AutoShift; - Restart(); - -} // InvertAutoShift. - - -template<class ARFLOAT, class ARTYPE> -ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::GetVector() -{ - - switch (ido) { - case -1: - case 1: - case 2: - return &workd[ipntr[1]]; - case 3: - return &workl[ipntr[6]]; - default: - throw ArpackError(ArpackError::CANNOT_GET_VECTOR, "GetVector"); - } - -} // GetVector. - - -template<class ARFLOAT, class ARTYPE> -ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::GetProd() -{ - - if (ido != 1) { - throw ArpackError(ArpackError::CANNOT_GET_PROD, "GetProd"); - } - return &workd[ipntr[3]]; - -} // GetProd. - - -template<class ARFLOAT, class ARTYPE> -ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::PutVector() -{ - - switch (ido) { - case -1: - case 1: - case 2: - return &workd[ipntr[2]]; - case 3: - return &workl[ipntr[14]]; - default: - throw ArpackError(ArpackError::CANNOT_PUT_VECTOR, "PutVector"); - } - -} // PutVector. - - -template<class ARFLOAT, class ARTYPE> -int ARrcStdEig<ARFLOAT, ARTYPE>::TakeStep() -{ - - // Requiring the definition of all internal variables. - - if (!PrepareOK) { - - throw ArpackError(ArpackError::PREPARE_NOT_OK, "TakeStep"); - - } - else if (!BasisOK) { - - // Taking a step if the Arnoldi basis is not available. - - Aupp(); - - // Checking if convergence was obtained. - - if (ido==99) { - nconv = iparam[5]; - AuppError(); - if (info >= 0) BasisOK = true; - } - } - - return ido; - -} // TakeStep. - - -template<class ARFLOAT, class ARTYPE> -inline int ARrcStdEig<ARFLOAT, ARTYPE>::FindArnoldiBasis() -{ - - if (!BasisOK) { - throw ArpackError(ArpackError::CANNOT_FIND_BASIS, "FindArnoldiBasis"); - } - return nconv; - -} // FindArnoldiBasis. - - -template<class ARFLOAT, class ARTYPE> -int ARrcStdEig<ARFLOAT, ARTYPE>::FindEigenvalues() -{ - - // Determining eigenvalues if they are not available. - - if (!ValuesOK) { - try { - ValAllocate(); - nconv = FindArnoldiBasis(); - rvec = false; - HowMny = 'A'; - if (nconv>0) { - Eupp(); - EuppError(); - } - } - catch (ArpackError) { - ArpackError(ArpackError::CANNOT_FIND_VALUES, "FindEigenvalues"); - return 0; - } - if (newVal) ValuesOK = true; - } - return nconv; - -} // FindEigenvalues. - - -template<class ARFLOAT, class ARTYPE> -int ARrcStdEig<ARFLOAT, ARTYPE>::FindEigenvectors(bool schurp) -{ - - // Determining eigenvectors if they are not available. - - if (!VectorsOK) { - try { - ValAllocate(); - VecAllocate(schurp); - nconv = FindArnoldiBasis(); - rvec = true; - HowMny = 'A'; - if (nconv>0) { - Eupp(); - EuppError(); - } - } - catch (ArpackError) { - ArpackError(ArpackError::CANNOT_FIND_VECTORS, "FindEigenvectors"); - return 0; - } - BasisOK = false; - if (newVal) ValuesOK = true; - if (newVec || OverV()) VectorsOK = true; - if (!OverV()) SchurOK = true; - } - return nconv; - -} // FindEigenvectors. - - -template<class ARFLOAT, class ARTYPE> -int ARrcStdEig<ARFLOAT, ARTYPE>::FindSchurVectors() -{ - - // Determining Schur vectors if they are not available. - - if (!SchurOK) { - try { - ValAllocate(); - nconv = FindArnoldiBasis(); - rvec = true; - HowMny = 'P'; - if (nconv>0) { - Eupp(); - EuppError(); - } - } - catch (ArpackError) { - ArpackError(ArpackError::CANNOT_FIND_SCHUR, "FindSchurVectors"); - return 0; - } - BasisOK = false; - if (newVal) ValuesOK = true; - SchurOK =true; - } - return nconv; - -} // FindSchurVectors. - - -template<class ARFLOAT, class ARTYPE> -int ARrcStdEig<ARFLOAT, ARTYPE>:: -Eigenvectors(ARTYPE* &EigVecp, bool ischur) -{ - - // Overriding EigVecp with the converged eigenvectors. - - if (VectorsOK) { // Eigenvectors are available. - if ((EigVecp == NULL) && (newVec)) { // Moving eigenvectors. - EigVecp = EigVec; - EigVec = NULL; - newVec = false; - VectorsOK = false; - } - else { // Copying eigenvectors. - if (EigVecp == NULL) { - try { EigVecp = new ARTYPE[ValSize()*n]; } - catch (ArpackError) { return 0; } - } - copy(ValSize()*n,EigVec,1,EigVecp,1); - } - } - else { // Eigenvectors are not available. - if (newVec) { - delete[] EigVec; - newVec = false; - } - if (EigVecp == NULL) { - try { EigVecp = new ARTYPE[ValSize()*n]; } - catch (ArpackError) { return 0; } - } - EigVec = EigVecp; - nconv = FindEigenvectors(ischur); - EigVec = NULL; - } - return nconv; - -} // Eigenvectors(EigVecp, ischur). - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE ARrcStdEig<ARFLOAT, ARTYPE>::ArnoldiBasisVector(int i, int j) -{ - - // Returning element j of Arnoldi basis vector i. - - if (!BasisOK) { - throw ArpackError(ArpackError::BASIS_NOT_OK, "ArnoldiBasisVector(i,j)"); - } - else if ((i>=ncv)||(i<0)||(j>=n)||(j<0)) { - throw ArpackError(ArpackError::RANGE_ERROR,"ArnoldiBasisVector(i,j)"); - } - return V[i*n+j+1]; - -} // ArnoldiBasisVector(i,j). - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE ARrcStdEig<ARFLOAT, ARTYPE>::SchurVector(int i, int j) -{ - - // Returning element j of Schur vector i. - - if (!SchurOK) { - throw ArpackError(ArpackError::SCHUR_NOT_OK, "SchurVector(i,j)"); - } - else if ((i>=nconv)||(i<0)||(j>=n)||(j<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "SchurVector(i,j)"); - } - return V[i*n+j+1]; - -} // SchurVector(i,j). - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE ARrcStdEig<ARFLOAT, ARTYPE>::ResidualVector(int i) -{ - - // Returning element i of the residual vector. - - if ((!newRes)||(!(BasisOK||ValuesOK||VectorsOK||SchurOK))) { - throw ArpackError(ArpackError::RESID_NOT_OK, "ResidualVector(i)"); - } - else if ((i>=n)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "ResidualVector(i)"); - } - return resid[i]; - -} // ResidualVector(i). - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::RawArnoldiBasisVectors() -{ - - // Returning a constant pointer to Arnoldi basis. - - if (!BasisOK) { - throw ArpackError(ArpackError::BASIS_NOT_OK, "RawArnoldiBasisVectors"); - } - return &V[1]; - -} // RawArnoldiBasisVectors. - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::RawArnoldiBasisVector(int i) -{ - - // Returning a constant pointer to Arnoldi basis vector i. - - if (!BasisOK) { - throw ArpackError(ArpackError::BASIS_NOT_OK, "RawArnoldiBasisVector(i)"); - } - else if ((i>=ncv)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR,"RawArnoldiBasisVector(i)"); - } - return &V[i*n+1]; - -} // RawArnoldiBasisVector(i). - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::RawEigenvalues() -{ - - if (!ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "RawEigenvalues"); - } - return EigValR; - -} // RawEigenvalues. - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::RawEigenvectors() -{ - - if (!VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "RawEigenvectors"); - } - return EigVec; - -} // RawEigenvectors. - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::RawEigenvector(int i) -{ - - // Returning a constant pointer to eigenvector i. - - if (!VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "RawEigenvector(i)"); - } - else if ((i>=ValSize())||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "RawEigenvector(i)"); - } - return &EigVec[i*n]; - -} // RawEigenvector(i). - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::RawSchurVectors() -{ - - if (!SchurOK) { - throw ArpackError(ArpackError::SCHUR_NOT_OK, "RawSchurVectors"); - } - return &V[1]; - -} // RawSchurVectors. - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::RawSchurVector(int i) -{ - - // Returning a constant pointer to Schur vector i. - - if (!SchurOK) { - throw ArpackError(ArpackError::SCHUR_NOT_OK, "RawSchurVector(i)"); - } - else if ((i>=nev)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "RawSchurVector(i)"); - } - return &V[i*n+1]; - -} // RawSchurVector(i). - - -template<class ARFLOAT, class ARTYPE> -inline ARTYPE* ARrcStdEig<ARFLOAT, ARTYPE>::RawResidualVector() -{ - - if (!newRes) { - throw ArpackError(ArpackError::RESID_NOT_OK, "RawResidualVector"); - } - return resid; - -} // RawResidualVector. - - -#ifdef STL_VECTOR_H // Defining some functions that use STL vector class. - -template<class ARFLOAT, class ARTYPE> -inline vector<ARTYPE>* ARrcStdEig<ARFLOAT, ARTYPE>::StlArnoldiBasisVectors() -{ - - // Returning the Arnoldi basis in a single STL vector. - - vector<ARTYPE>* StlBasis; - - if (!BasisOK) { - nconv = FindArnoldiBasis(); - } - try { - StlBasis = new vector<ARTYPE>(&V[1], &V[n*ncv+1]); - } - catch (ArpackError) { return NULL; } - return StlBasis; - -} // StlArnoldiBasisVectors. - - -template<class ARFLOAT, class ARTYPE> -inline vector<ARTYPE>* ARrcStdEig<ARFLOAT,ARTYPE>::StlArnoldiBasisVector(int i) -{ - - // Returning the i-th Arnoldi basis vector in a STL vector. - - vector<ARTYPE>* StlBasis; - - if (!BasisOK) { - throw ArpackError(ArpackError::BASIS_NOT_OK, "StlArnoldiBasisVector(i)"); - } - else if ((i>=ncv)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR,"StlArnoldiBasisVector(i)"); - } - try { - StlBasis = new vector<ARTYPE>(&V[i*n+1], &V[(i+1)*n+1]); - } - catch (ArpackError) { return NULL; } - return StlBasis; - -} // StlArnoldiBasisVector(i). - - -template<class ARFLOAT, class ARTYPE> -inline vector<ARTYPE>* ARrcStdEig<ARFLOAT,ARTYPE>::StlEigenvectors(bool ischur) -{ - - // Returning the eigenvector in a single STL vector. - - vector<ARTYPE>* StlEigVec; - ARTYPE* VecPtr; - - try { StlEigVec = new vector<ARTYPE>(ValSize()*n); } - catch (ArpackError) { return NULL; } - VecPtr = StlEigVec->begin(); - nconv = Eigenvectors(VecPtr, ischur); - return StlEigVec; - -} // StlEigenvectors. - - -template<class ARFLOAT, class ARTYPE> -inline vector<ARTYPE>* ARrcStdEig<ARFLOAT, ARTYPE>::StlSchurVectors() -{ - - vector<ARTYPE>* StlSchurVec; - - if (!SchurOK) { - nconv = FindSchurVectors(); - } - try { - StlSchurVec = new vector<ARTYPE>(&V[1], &V[nev*n+1]); - } - catch (ArpackError) { return NULL; } - return StlSchurVec; - -} // StlSchurVectors. - - -template<class ARFLOAT, class ARTYPE> -inline vector<ARTYPE>* ARrcStdEig<ARFLOAT, ARTYPE>::StlSchurVector(int i) -{ - - // Returning the i-th Schur vector in a STL vector. - - vector<ARTYPE>* StlSchurVec; - - if (!SchurOK) { - throw ArpackError(ArpackError::SCHUR_NOT_OK, "StlSchurVector(i)"); - } - else if ((i>=nev)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "StlSchurVector(i)"); - } - try { - StlSchurVec = new vector<ARTYPE>(&V[i*n+1], &V[(i+1)*n+1]); - } - catch (ArpackError) { return NULL; } - return StlSchurVec; - -} // StlSchurVector(i). - - -template<class ARFLOAT, class ARTYPE> -inline vector<ARTYPE>* ARrcStdEig<ARFLOAT, ARTYPE>::StlResidualVector() -{ - - // Returning the residual vector in a STL vector. - - vector<ARTYPE>* StlResid; - - if (!newRes) { - throw ArpackError(ArpackError::RESID_NOT_OK, "StlResidualVector"); - } - try { - StlResid = new vector<ARTYPE>(resid, &resid[n]); - } - catch (ArpackError) { return NULL; } - return StlResid; - -} // StlResidualVector. - -#endif // #ifdef STL_VECTOR_H. - - -template<class ARFLOAT, class ARTYPE> -inline ARrcStdEig<ARFLOAT, ARTYPE>::ARrcStdEig() -{ - - resid = NULL; - rwork = NULL; - workl = NULL; - workd = NULL; - workv = NULL; - V = NULL; - EigValR = NULL; - EigValI = NULL; - EigVec = NULL; - bmat = 'I'; // This is a standard problem. - ClearFirst(); - NoShift(); - NoTrace(); - -} // Short constructor. - - -template<class ARFLOAT, class ARTYPE> -ARrcStdEig<ARFLOAT, ARTYPE>& ARrcStdEig<ARFLOAT, ARTYPE>:: -operator=(const ARrcStdEig<ARFLOAT, ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARRSEIG_H - diff --git a/src/external/arpack++/include/arrsnsym.h b/src/external/arpack++/include/arrsnsym.h deleted file mode 100644 index 106b10df..00000000 --- a/src/external/arpack++/include/arrsnsym.h +++ /dev/null @@ -1,861 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARRSNSym.h. - Arpack++ class ARrcNonSymStdEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARRSNSYM_H -#define ARRSNSYM_H - -#include <cstddef> - -#include "arch.h" -#include "arerror.h" -#include "debug.h" -#include "arrseig.h" -#include "naupp.h" -#include "neupp.h" - - -template<class ARFLOAT> -class ARrcNonSymStdEig: public virtual ARrcStdEig<ARFLOAT, ARFLOAT> { - - protected: - - // a) Protected functions: - - // a.1) Memory control functions. - - int ValSize() { return this->nev+1; } - // Provides the size of array EigVal. - - void ValAllocate(); - // Creates arrays EigValR and EigValI. - - void WorkspaceAllocate(); - // Allocates workspace for nonsymmetric problems. - - - // a.2) Functions that handle original FORTRAN ARPACK code. - - void Aupp(); - // Interface to FORTRAN subroutines SNAUPD and DNAUPD. - - void Eupp(); - // Interface to FORTRAN subroutines SNEUPD and DNEUPD. - - - // a.3) Functions that check user defined parameters. - - int CheckNev(int nevp); - // Does Range checking on nev. - - - // a.4) Auxiliary functions required when using STL vector class. - - bool ConjEigVec(int i); - // Indicates if EigVec[i] is the second eigenvector in - // a complex conjugate pair. - -#ifdef ARCOMP_H -#ifdef STL_VECTOR_H - - vector<arcomplex<ARFLOAT> >* GenComplex(vector<ARFLOAT>* RealPart, - vector<ARFLOAT>* ImagPart, - bool conj = false); - // Generates a complex vector Complex = RealPart + I*ImagPart - // (or Complex = RealPart - I*ImagPart, if conj = true). - - vector<arcomplex<ARFLOAT> >* GenComplex(int dim, ARFLOAT* RealPart, - ARFLOAT* ImagPart, - bool conj = false); - // Generates a complex vector Complex = RealPart + I*ImagPart - // (or Complex = RealPart - I*ImagPart, if conj = true). dim - // is the length of RealPart and ImagPart. - - vector<arcomplex<ARFLOAT> >* GenComplex(int dim, ARFLOAT* RealPart); - // Generates a complex vector from a real vector. dim is the - // length of RealPart. - -#endif // STL_VECTOR_H. -#endif // ARCOMP_H. - - public: - - // b) Public functions: - - // b.1) Trace functions. - - void Trace(const int digit = -5, const int getv0 = 0, const int aupd = 1, - const int aup2 = 0, const int aitr = 0, const int eigt = 0, - const int apps = 0, const int gets = 0, const int eupd = 0) - { - nTraceOn(digit, getv0, aupd, aup2, aitr, eigt, apps, gets, eupd); - } - // Turns on trace mode. - - - // b.2) Functions that permit step by step execution of ARPACK. - - ARFLOAT* GetVectorImag(); - // When ido = 3, this function indicates where the imaginary part - // of the eigenvalues of the current Hessenberg matrix are located. - - - // b.3) Functions that perform all calculations in one step. - - int Eigenvalues(ARFLOAT* &EigValRp, ARFLOAT* &EigValIp, - bool ivec = false, bool ischur = false); - // Overrides arrays EigValRp with the real part and EigValIp - // with the imaginary part of the eigenvalues of the problem. - // Calculates eigenvectors and Schur vectors if requested. - - int EigenValVectors(ARFLOAT* &EigVecp, ARFLOAT* &EigValRp, - ARFLOAT* &EigValIp, bool ischur = false); - // Overrides array EigVecp sequentially with the eigenvectors of the - // given eigen-problem. Also stores the eigenvalues in EigValRp and - // EigValIp. Calculates Schur vectors if requested. - - - // b.4) Functions that return elements of vectors and matrices. - -#ifdef ARCOMP_H - arcomplex<ARFLOAT> Eigenvalue(int i); - // Furnishes i-eth eigenvalue. -#endif // ARCOMP_H. - - ARFLOAT EigenvalueReal(int i); - // Provides the real part of the i-eth eigenvalue. - - ARFLOAT EigenvalueImag(int i); - // Provides the imaginary part of the i-eth eigenvalue. - -#ifdef ARCOMP_H - arcomplex<ARFLOAT> Eigenvector(int i, int j); - // Furnishes element j of the i-eth eigenvector. -#endif // ARCOMP_H. - - ARFLOAT EigenvectorReal(int i, int j); - // Provides the real part of element j of the i-eth eigenvector. - - ARFLOAT EigenvectorImag(int i, int j); - // Provides the imaginary part of element j of the i-eth eigenvector. - - - // b.5) Functions that provide raw access to internal vectors and matrices. - - ARFLOAT* RawEigenvaluesImag(); - // Provides raw access to the imaginary part of eigenvalues. - - - // b.6) Functions that use STL vector class. - -#ifdef STL_VECTOR_H - -#ifdef ARCOMP_H - vector<arcomplex<ARFLOAT> >* StlEigenvalues(bool ivec = false, - bool ischur = false); - // Calculates the eigenvalues and stores them in a single STL vector. - // Also calculates eigenvectors and Schur vectors if requested. -#endif // ARCOMP_H. - - vector<ARFLOAT>* StlEigenvaluesReal(); - // Returns the real part of the eigenvalues. - - vector<ARFLOAT>* StlEigenvaluesImag(); - // Returns the imaginary part of the eigenvalues. - -#ifdef ARCOMP_H - vector<arcomplex<ARFLOAT> >* StlEigenvector(int i); - // Returns the i-th eigenvector. -#endif // ARCOMP_H. - - vector<ARFLOAT>* StlEigenvectorReal(int i); - // Returns the real part of the i-th eigenvector. - - vector<ARFLOAT>* StlEigenvectorImag(int i); - // Returns the imaginary part of the i-th eigenvector. - -#endif // STL_VECTOR_H. - - - // b.7) Constructors and destructor. - - ARrcNonSymStdEig() { } - // Short constructor. - - ARrcNonSymStdEig(int np, int nevp, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, ARFLOAT* residp = NULL, - bool ishiftp = true); - // Long constructor (regular mode). - - ARrcNonSymStdEig(int np, int nevp, ARFLOAT sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARrcNonSymStdEig(const ARrcNonSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARrcNonSymStdEig() { } - // Destructor. - - // c) Operators. - - ARrcNonSymStdEig& operator=(const ARrcNonSymStdEig& other); - // Assignment operator. - -}; // class ARrcNonSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARrcNonSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARrcNonSymStdEig<ARFLOAT>::ValAllocate() -{ - - if (this->EigValR == NULL) { - this->EigValR = new ARFLOAT[ValSize()]; - this->EigValI = new ARFLOAT[ValSize()]; - this->newVal = true; - } - -} // ValAllocate. - - -template<class ARFLOAT> -inline void ARrcNonSymStdEig<ARFLOAT>::WorkspaceAllocate() -{ - - this->lworkl = 3*this->ncv*(this->ncv+2); - this->lworkv = 3*this->ncv; - this->lrwork = 0; - this->workl = new ARFLOAT[this->lworkl+1]; - this->workv = new ARFLOAT[this->lworkv+1]; - -} // WorkspaceAllocate. - - -template<class ARFLOAT> -inline void ARrcNonSymStdEig<ARFLOAT>::Aupp() -{ - - naupp(this->ido,this-> bmat, this->n, this->which, this->nev, this->tol, this->resid, this->ncv, this->V, this->n, - this->iparam, this->ipntr, this->workd, this->workl, this->lworkl, this->info); - -} // Aupp. - - -template<class ARFLOAT> -inline void ARrcNonSymStdEig<ARFLOAT>::Eupp() -{ - - neupp(this->rvec, this->HowMny, this->EigValR, this->EigValI, this->EigVec, this->n, this->sigmaR, - this->sigmaI, this->workv, this->bmat, this->n, this->which, this->nev, this->tol, this->resid, this->ncv, this->V, - this->n, this->iparam, this->ipntr, this->workd, this->workl, this->lworkl, this->info); - -} // Eupp. - - -template<class ARFLOAT> -inline int ARrcNonSymStdEig<ARFLOAT>::CheckNev(int nevp) -{ - std::cout << nevp << "ddddd22g\n";fflush(stdout); - if ((nevp<=1)||(nevp>=(this->n-1))) { // nev must satisfy 1 < nev < n-1. - std::cout << nevp << "dddd21d22g\n";fflush(stdout); - throw ArpackError(ArpackError::NEV_OUT_OF_BOUNDS); - } - return nevp; - -} // CheckNev. - - -template<class ARFLOAT> -bool ARrcNonSymStdEig<ARFLOAT>::ConjEigVec(int i) -{ - - if (this->EigValI[i] == (ARFLOAT)0.0) return false; - int j = i-1; - while ((j >= 0) && (this->EigValI[j] != (ARFLOAT)0.0)) j--; - if (((i-j)%2) == 0) { - return true; - } - else { - return false; - } - -} // ConjEigVec. - - -#ifdef STL_VECTOR_H // Defining functions that use STL vector class. -#ifdef ARCOMP_H - -template<class ARFLOAT> -vector<arcomplex<ARFLOAT> >* ARrcNonSymStdEig<ARFLOAT>:: -GenComplex(vector<ARFLOAT>* RealPart, vector<ARFLOAT>* ImagPart, bool conj) -{ - - // Defining variables. - - vector<arcomplex<ARFLOAT> >* Result; - try { - Result = new vector<arcomplex<ARFLOAT> >(ValSize()); - } - catch (ArpackError) { return NULL; } - ARFLOAT* rp = RealPart->begin(); - ARFLOAT* ip = ImagPart->begin(); - ARFLOAT* end = RealPart->end(); - arcomplex<ARFLOAT>* s = Result->begin(); - - // Creating a complex vector. - - if (!conj) { - while (rp != end) *s++ = arcomplex<ARFLOAT>(*rp++, *ip++); - } - else { - while (rp != end) *s++ = arcomplex<ARFLOAT>(*rp++, -(*ip++)); - } - - return Result; - -} // GenComplex (vector<ARFLOAT> version). - - -template<class ARFLOAT> -vector<arcomplex<ARFLOAT> >* ARrcNonSymStdEig<ARFLOAT>:: -GenComplex(int dim, ARFLOAT* RealPart, ARFLOAT* ImagPart, bool conj) -{ - - // Defining variables. - - vector<arcomplex<ARFLOAT> >* Result; - try { - Result = new vector<arcomplex<ARFLOAT> >(dim); - } - catch (ArpackError) { return NULL; } - ARFLOAT* rp = RealPart; - ARFLOAT* ip = ImagPart; - ARFLOAT* end = &RealPart[dim]; - arcomplex<ARFLOAT>* s = Result->begin(); - - // Creating a complex vector. - - if (!conj) { - while (rp != end) *s++ = arcomplex<ARFLOAT>(*rp++, *ip++); - } - else { - while (rp != end) *s++ = arcomplex<ARFLOAT>(*rp++, -(*ip++)); - } - - return Result; - -} // GenComplex (ARFLOAT* version). - - -template<class ARFLOAT> -vector<arcomplex<ARFLOAT> >* ARrcNonSymStdEig<ARFLOAT>:: -GenComplex(int dim, ARFLOAT* RealPart) -{ - - // Defining variables. - - vector<arcomplex<ARFLOAT> >* Result; - try { - Result = new vector<arcomplex<ARFLOAT> >(dim); - } - catch (ArpackError) { return NULL; } - ARFLOAT* rp = RealPart; - ARFLOAT* end = &RealPart[dim]; - arcomplex<ARFLOAT>* s = Result->begin(); - - // Copying a real vector into a complex vector. - - while (rp != end) *s++ = *rp++; - - return Result; - -} // GenComplex. - -#endif // ARCOMP_H. -#endif // STL_VECTOR_H. - - -template<class ARFLOAT> -ARFLOAT* ARrcNonSymStdEig<ARFLOAT>::GetVectorImag() -{ - - if (this->ido != 3) { - throw ArpackError(ArpackError::CANNOT_GET_VECTOR, "GetVectorImag"); - } - return &this->workl[this->ipntr[6]]; - -} // GetVectorImag. - - -template<class ARFLOAT> -int ARrcNonSymStdEig<ARFLOAT>:: -Eigenvalues(ARFLOAT* &EigValRp, ARFLOAT* &EigValIp, bool ivec, bool ischur) -{ - - if (this->ValuesOK) { // Eigenvalues are available. - if ((EigValRp == NULL)&&(EigValIp == NULL)) { // Moving eigenvalues. - EigValRp = this->EigValR; - EigValIp = this->EigValI; - this->EigValR = NULL; - this->EigValI = NULL; - this->newVal = false; - this->ValuesOK = false; - } - else { // Copying eigenvalues. - try { - if (EigValRp == NULL) EigValRp = new ARFLOAT[ValSize()]; - if (EigValIp == NULL) EigValIp = new ARFLOAT[ValSize()]; - } - catch (ArpackError) { return 0; } - copy(this->nconv,this->EigValR,1,EigValRp,1); - copy(this->nconv,this->EigValI,1,EigValIp,1); - } - } - else { - if (this->newVal) { - delete[] this->EigValR; - delete[] this->EigValI; - this->newVal = false; - } - try { - if (EigValRp == NULL) EigValRp = new ARFLOAT[ValSize()]; - if (EigValIp == NULL) EigValIp = new ARFLOAT[ValSize()]; - } - catch (ArpackError) { return 0; } - this->EigValR = EigValRp; - this->EigValI = EigValIp; - if (ivec) { // Finding eigenvalues and vectors. - this->nconv = this->FindEigenvectors(ischur); - } - else { // Finding eigenvalues only. - this->nconv = this->FindEigenvalues(); - } - this->EigValR = NULL; - this->EigValI = NULL; - } - return this->nconv; - -} // Eigenvalues(EigValRp, EigValIp, ivec, ischur). - - -template<class ARFLOAT> -int ARrcNonSymStdEig<ARFLOAT>:: -EigenValVectors(ARFLOAT* &EigVecp, ARFLOAT* &EigValRp, - ARFLOAT* &EigValIp, bool ischur) -{ - - if (this->ValuesOK) { // Eigenvalues are already available . - this->nconv = Eigenvalues(EigValRp, EigValIp, false); - this->nconv = this->Eigenvectors(EigVecp, ischur); - } - else { // Eigenvalues ans vectors are not available. - if (this->newVec) { - delete[] this->EigVec; - this->newVec = false; - } - if (this->newVal) { - delete[] this->EigValR; - delete[] this->EigValI; - this->newVal = false; - } - try { - if (EigVecp == NULL) EigVecp = new ARFLOAT[ValSize()*this->n]; - if (EigValRp == NULL) EigValRp = new ARFLOAT[ValSize()]; - if (EigValIp == NULL) EigValIp = new ARFLOAT[ValSize()]; - } - catch (ArpackError) { return 0; } - this->EigVec = EigVecp; - this->EigValR = EigValRp; - this->EigValI = EigValIp; - this->nconv = this->FindEigenvectors(ischur); - this->EigVec = NULL; - this->EigValR = NULL; - this->EigValI = NULL; - } - return this->nconv; - -} // EigenValVectors(EigVecp, EigValRp, EigValIp, ischur). - - -#ifdef ARCOMP_H -template<class ARFLOAT> -inline arcomplex<ARFLOAT> ARrcNonSymStdEig<ARFLOAT>::Eigenvalue(int i) -{ - - // Returning i-eth eigenvalue. - - if (!this->ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "Eigenvalue(i)"); - } - else if ((i>=this->nconv)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "Eigenvalue(i)"); - } - return arcomplex<ARFLOAT>(this->EigValR[i],this->EigValI[i]); - -} // Eigenvalue(i). -#endif // ARCOMP_H - - -template<class ARFLOAT> -inline ARFLOAT ARrcNonSymStdEig<ARFLOAT>::EigenvalueReal(int i) -{ - - // Returning the real part of i-eth eigenvalue. - - if (!this->ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "EigenvalueReal(i)"); - } - else if ((i>=this->nconv)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "EigenvalueReal(i)"); - } - return this->EigValR[i]; - -} // EigenvalueReal(i). - - -template<class ARFLOAT> -inline ARFLOAT ARrcNonSymStdEig<ARFLOAT>::EigenvalueImag(int i) -{ - - // Returning the imaginary part of i-eth eigenvalue. - - if (!this->ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "EigenvalueImag(i)"); - } - else if ((i>=this->nconv)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "EigenvalueImag(i)"); - } - return this->EigValI[i]; - -} // EigenvalueImag(i). - - -#ifdef ARCOMP_H -template<class ARFLOAT> -inline arcomplex<ARFLOAT> ARrcNonSymStdEig<ARFLOAT>:: -Eigenvector(int i, int j) -{ - - // Returning element j of i-eth eigenvector. - - if ((!this->VectorsOK)||(!this->ValuesOK)) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "Eigenvector(i,j)"); - } - else if ((i>=this->nconv)||(i<0)||(j>=this->n)||(j<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "Eigenvector(i,j)"); - } - if (this->EigValI[i]==(ARFLOAT)0.0) { // Real eigenvalue. - return arcomplex<ARFLOAT>(this->EigVec[i*this->n+j],(ARFLOAT)0.0); - } - else { // Complex eigenvalue. - if (this->EigValI[i]>(ARFLOAT)0.0) { // with positive imaginary part. - return arcomplex<ARFLOAT>(this->EigVec[i*this->n+j], this->EigVec[(i+1)*this->n+j]); - } - else { // with negative imaginary part. - return arcomplex<ARFLOAT>(this->EigVec[(i-1)*this->n+j], -this->EigVec[i*this->n+j]); - } - } - -} // Eigenvector(i,j). -#endif // ARCOMP_H - - -template<class ARFLOAT> -inline ARFLOAT ARrcNonSymStdEig<ARFLOAT>::EigenvectorReal(int i, int j) -{ - - // Returning the real part of element j of i-eth eigenvector. - - if (!this->VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "EigenvectorReal(i,j)"); - } - else if ((i>=this->nconv)||(i<0)||(j>=this->n)||(j<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "EigenvectorReal(i,j)"); - } - return this->EigVec[i*this->n+j]; - -} // EigenvectorReal(i,j). - - -template<class ARFLOAT> -inline ARFLOAT ARrcNonSymStdEig<ARFLOAT>::EigenvectorImag(int i, int j) -{ - - // Returning the imaginary part of element j of i-eth eigenvector. - - if ((!this->VectorsOK)||(!this->ValuesOK)) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "EigenvectorImag(i,j)"); - } - else if ((i>=this->nconv)||(i<0)||(j>=this->n)||(j<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "EigenvectorImag(i,j)"); - } - if (this->EigValI[i]==(ARFLOAT)0.0) { // Real eigenvalue. - return (ARFLOAT)0.0; - } - else { // Complex eigenvalue. - if (this->EigValI[i]>(ARFLOAT)0.0) { // with positive imaginary part. - return this->EigVec[(i+1)*this->n+j]; - } - else { // with negative imaginary part. - return -this->EigVec[i*this->n+j]; - } - } - -} // EigenvectorImag(i,j). - - -template<class ARFLOAT> -inline ARFLOAT* ARrcNonSymStdEig<ARFLOAT>::RawEigenvaluesImag() -{ - - if (!this->ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "RawEigenvaluesImag"); - } - return this->EigValI; - -} // RawEigenvaluesImag. - - -#ifdef STL_VECTOR_H // Defining some functions that use STL vector class. - -#ifdef ARCOMP_H -template<class ARFLOAT> -inline vector<arcomplex<ARFLOAT> >* ARrcNonSymStdEig<ARFLOAT>:: -StlEigenvalues(bool ivec, bool ischur) -{ - - // Returning the eigenvalues in a STL vector. - - // Defining temporary variables. - - vector<ARFLOAT>* StlEigValR; - vector<ARFLOAT>* StlEigValI; - ARFLOAT* ValRPtr; - ARFLOAT* ValIPtr; - - try { - StlEigValR = new vector<ARFLOAT>(ValSize()); - StlEigValI = new vector<ARFLOAT>(ValSize()); - } - catch (ArpackError) { return NULL; } - - // Finding Eigenvalues. - - ValRPtr = StlEigValR->begin(); - ValIPtr = StlEigValI->begin(); - nconv = Eigenvalues(ValRPtr, ValIPtr, ivec, ischur); - vector<arcomplex<ARFLOAT> >* Val = GenComplex(StlEigValR, StlEigValI); - - // Deleting temporary variables. - - delete StlEigValR; - delete StlEigValI; - - return Val; - -} // StlEigenvalues. -#endif // ARCOMP_H. - - -template<class ARFLOAT> -inline vector<ARFLOAT>* ARrcNonSymStdEig<ARFLOAT>::StlEigenvaluesReal() -{ - - // Returning the real part of the eigenvalues in a STL vector. - - vector<ARFLOAT>* StlEigValR; - - if (!ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "StlEigenvaluesReal"); - } - try { - StlEigValR = new vector<ARFLOAT>(EigValR, &EigValR[ValSize()]); - } - catch (ArpackError) { return NULL; } - return StlEigValR; - -} // StlEigenvaluesReal. - - -template<class ARFLOAT> -inline vector<ARFLOAT>* ARrcNonSymStdEig<ARFLOAT>::StlEigenvaluesImag() -{ - - // Returning the imaginary part of the eigenvalues in a STL vector. - - vector<ARFLOAT>* StlEigValI; - - if (!ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "StlEigenvaluesImag"); - } - try { - StlEigValI = new vector<ARFLOAT>(EigValI, &EigValI[ValSize()]); - } - catch (ArpackError) { return NULL; } - return StlEigValI; - -} // StlEigenvaluesImag. - - -#ifdef ARCOMP_H -template<class ARFLOAT> -inline vector<arcomplex<ARFLOAT> >* ARrcNonSymStdEig<ARFLOAT>:: -StlEigenvector(int i) -{ - - // Returning the i-th eigenvector in a STL vector. - - if (!VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "StlEigenvector(i)"); - } - else if ((i>=ValSize())||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "StlEigenvector(i)"); - } - if (EigValI[i] == (ARFLOAT)0.0) { // Real eigenvector. - return GenComplex(n, &EigVec[i*n]); - } - else if (!ConjEigVec(i)) { // First eigenvector in a conjugate pair. - return GenComplex(n, &EigVec[i*n], &EigVec[(i+1)*n]); - } - else { // Second eigenvector in a conjugate pair. - return GenComplex(n, &EigVec[(i-1)*n], &EigVec[i*n], true); - } - -} // StlEigenvector(i). -#endif // ARCOMP_H. - - -template<class ARFLOAT> -inline vector<ARFLOAT>* ARrcNonSymStdEig<ARFLOAT>::StlEigenvectorReal(int i) -{ - - // Returning the real part of the i-th eigenvector in a STL vector. - - vector<ARFLOAT>* Vec; - - if (!VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "StlEigenvectorReal(i)"); - } - else if ((i>=ValSize())||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "StlEigenvectorReal(i)"); - } - if (!ConjEigVec(i)) { // Real eigenvector or first in a conj. pair. - try { - Vec = new vector<ARFLOAT>(&EigVec[i*n], &EigVec[(i+1)*n]); - } - catch (ArpackError) { return NULL; } - return Vec; - } - else { // Second eigenvector in a conjugate pair. - try { - Vec = new vector<ARFLOAT>(&EigVec[(i-1)*n], &EigVec[i*n]); - } - catch (ArpackError) { return NULL; } - return Vec; - } - -} // StlEigenvectorReal(i). - - -template<class ARFLOAT> -inline vector<ARFLOAT>* ARrcNonSymStdEig<ARFLOAT>::StlEigenvectorImag(int i) -{ - - // Returning the imaginary part of the i-th eigenvector in a STL vector. - - vector<ARFLOAT>* Vec; - - if (!VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "StlEigenvectorImag(i)"); - } - else if ((i>=ValSize())||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "StlEigenvectorImag(i)"); - } - if (EigValI[i] == (ARFLOAT)0.0) { // Real eigenvector. - try { - Vec = new vector<ARFLOAT>(ValSize(), (ARFLOAT)0.0); - } - catch (ArpackError) { return NULL; } - return Vec; - } - else if (!ConjEigVec(i)) { // First eigenvector in a conjugate pair. - try { - Vec = new vector<ARFLOAT>(&EigVec[(i+1)*n], &EigVec[(i+2)*n]); - } - catch (ArpackError) { return NULL; } - return Vec; - } - else { // Second eigenvector in a conjugate pair. - try { - Vec = new vector<ARFLOAT>(&EigVec[i*n], &EigVec[(i+1)*n]); - } - catch (ArpackError) { return NULL; } - for (ARFLOAT* s = Vec->begin(); s != Vec->end(); s++) *s = -(*s); - return Vec; - } - -} // StlEigenvectorImag(i). - -#endif // STL_VECTOR_H. - - -template<class ARFLOAT> -inline ARrcNonSymStdEig<ARFLOAT>:: -ARrcNonSymStdEig(int np, int nevp, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARrcNonSymStdEig<ARFLOAT>:: -ARrcNonSymStdEig(int np, int nevp, ARFLOAT sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARrcNonSymStdEig<ARFLOAT>& ARrcNonSymStdEig<ARFLOAT>:: -operator=(const ARrcNonSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARRSNSYM_H - diff --git a/src/external/arpack++/include/arrssym.h b/src/external/arpack++/include/arrssym.h deleted file mode 100644 index 1a38fdd1..00000000 --- a/src/external/arpack++/include/arrssym.h +++ /dev/null @@ -1,424 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARRSSym.h. - Arpack++ class ARrcSymStdEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARRSSYM_H -#define ARRSSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arerror.h" -#include "debug.h" -#include "arrseig.h" -#include "saupp.h" -#include "seupp.h" - - -template<class ARFLOAT> -class ARrcSymStdEig: public virtual ARrcStdEig<ARFLOAT, ARFLOAT> { - - protected: - - // a) Protected functions: - - // a.1) Memory control functions. - - void WorkspaceAllocate(); - // Allocates workspace for symmetric problems. - - - // a.2) Functions that handle original FORTRAN ARPACK code. - - void Aupp(); - // Interface to FORTRAN subroutines SSAUPD and DSAUPD. - - void Eupp(); - // Interface to FORTRAN subroutines SSEUPD and DSEUPD. - - - // a.3) Functions that check user defined parameters. - - std::string CheckWhich(const std::string& whichp); - // Determines if the value of variable "which" is valid. - - - public: - - // b) Public functions: - - // b.1) Trace functions. - - void Trace(const int digit = -5, const int getv0 = 0, const int aupd = 1, - const int aup2 = 0, const int aitr = 0, const int eigt = 0, - const int apps = 0, const int gets = 0, const int eupd = 0) - { - sTraceOn(digit, getv0, aupd, aup2, aitr, eigt, apps, gets, eupd); - } - // Turns on trace mode. - - - // b.2) Functions that permit step by step execution of ARPACK. - - ARFLOAT* PutVector(); - // When ido = -1, 1 or 2 and the user must perform a product in the form - // y <- M*x, this function indicates where to store y. When ido = 3, this - // function indicates where to store the shifts. - - - // b.3) Functions that perform all calculations in one step. - - int FindSchurVectors() { - throw ArpackError(ArpackError::SCHUR_UNDEFINED, "FindSchurVectors"); - return 0; // Only to avoid warning messages emitted by some compilers. - } - // For symmetric problems, Schur vectors are eigenvectors. - - int Eigenvalues(ARFLOAT* &EigValp, bool ivec = false, bool ischur = false); - // Overrides array EigValp with the eigenvalues of the problem. - // Also calculates eigenvectors and Schur vectors if requested. - - int EigenValVectors(ARFLOAT* &EigVecp, ARFLOAT* &EigValp, - bool ischur = false); - // Overrides array EigVecp sequentially with the eigenvectors of the - // given eigen-problem. Also stores the eigenvalues in EigValp. - // Calculates Schur vectors if requested. - - - // b.4) Functions that return elements of vectors and matrices. - - ARFLOAT Eigenvalue(int i); - // Provides i-eth eigenvalue. - - ARFLOAT Eigenvector(int i, int j); - // Provides element j of the i-eth eigenvector. - - - // b.5) Functions that use STL vector class. - -#ifdef STL_VECTOR_H - - vector<ARFLOAT>* StlEigenvalues(bool ivec = false, bool ischur = false); - // Calculates the eigenvalues and stores them in a single STL vector. - // Also calculates eigenvectors and Schur vectors if requested. - - vector<ARFLOAT>* StlEigenvector(int i); - // Returns the i-th eigenvector in a STL vector. - -#endif // #ifdef STL_VECTOR_H. - - - // b.6) Constructors and destructor. - - ARrcSymStdEig() { } - // Short constructor. - - ARrcSymStdEig(int np, int nevp, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, ARFLOAT* residp = NULL, - bool ishiftp = true); - // Long constructor (regular mode). - - ARrcSymStdEig(int np, int nevp, ARFLOAT sigmap, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARrcSymStdEig(const ARrcSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARrcSymStdEig() { } - // Destructor. - - // c) Operators. - - ARrcSymStdEig& operator=(const ARrcSymStdEig& other); - // Assignment operator. - -}; // class ARrcSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARrcSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARrcSymStdEig<ARFLOAT>::WorkspaceAllocate() -{ - - this->lworkl = this->ncv*(this->ncv+9); - this->lworkv = 0; - this->lrwork = 0; - this->workl = new ARFLOAT[this->lworkl+1]; - -} // WorkspaceAllocate. - - -template<class ARFLOAT> -inline void ARrcSymStdEig<ARFLOAT>::Aupp() -{ - - saupp(this->ido, this->bmat, this->n, this->which, this->nev, this->tol, this->resid, this->ncv, this->V, this->n, - this->iparam, this->ipntr, this->workd, this->workl, this->lworkl, this->info); - -} // Aupp. - - -template<class ARFLOAT> -inline void ARrcSymStdEig<ARFLOAT>::Eupp() -{ - - seupp(this->rvec, this->HowMny, this->EigValR, this->EigVec, this->n, this->sigmaR, this->bmat, - this->n, this->which, this->nev, this->tol, this->resid, this->ncv, this->V, this->n, this->iparam, - this->ipntr, this->workd, this->workl, this->lworkl, this->info); - -} // Eupp. - - -template<class ARFLOAT> -std::string ARrcSymStdEig<ARFLOAT>::CheckWhich(const std::string& whichp) -{ - - switch (whichp[0]) { - case 'B': // The options are: BE, ... - return "BE"; - case 'L': // LA, LM, ... - case 'S': // SA, SM. - switch (whichp[1]){ - case 'A': - case 'M': - return whichp; - } - default: - throw ArpackError(ArpackError::WHICH_UNDEFINED); - } - -} // CheckWhich. - - -template<class ARFLOAT> -ARFLOAT* ARrcSymStdEig<ARFLOAT>::PutVector() -{ - - switch (this->ido) { - case -1: - case 1: // Returning OP*x. - case 2: - return &this->workd[this->ipntr[2]]; // Returning B*x. - case 3: - return &this->workl[this->ipntr[11]]; // Returning shifts. - default: - throw ArpackError(ArpackError::CANNOT_PUT_VECTOR, "PutVector"); - } - -} // PutVector. - - -template<class ARFLOAT> -int ARrcSymStdEig<ARFLOAT>:: -Eigenvalues(ARFLOAT* &EigValp, bool ivec, bool ischur) -{ - - if (this->ValuesOK) { // Eigenvalues are available. - if (EigValp == NULL) { // Moving eigenvalues. - EigValp = this->EigValR; - this->EigValR = NULL; - this->newVal = false; - this->ValuesOK = false; - } - else { // Copying eigenvalues. - copy(this->nconv,this->EigValR,1,EigValp,1); - } - } - else { // Eigenvalues are not available. - if (this->newVal) { - delete[] this->EigValR; - this->newVal = false; - } - if (EigValp == NULL) { - try { EigValp = new ARFLOAT[this->ValSize()]; } - catch (ArpackError) { return 0; } - } - this->EigValR = EigValp; - if (ivec) { // Finding eigenvalues and eigenvectors. - this->nconv = this->FindEigenvectors(ischur); - } - else { // Finding eigenvalues only. - this->nconv = this->FindEigenvalues(); - } - this->EigValR = NULL; - } - return this->nconv; - -} // Eigenvalues(EigValp, ivec, ischur). - - -template<class ARFLOAT> -int ARrcSymStdEig<ARFLOAT>:: -EigenValVectors(ARFLOAT* &EigVecp, ARFLOAT* &EigValp, bool ischur) -{ - - if (this->ValuesOK) { // Eigenvalues are already available . - this->nconv = Eigenvalues(EigValp, false); - this->nconv = this->Eigenvectors(EigVecp, ischur); - } - else { // Eigenvalues and vectors are not available. - try { - if (EigVecp == NULL) EigVecp = new ARFLOAT[this->ValSize()*this->n]; - if (EigValp == NULL) EigValp = new ARFLOAT[this->ValSize()]; - } - catch (ArpackError) { return 0; } - if (this->newVec) { - delete[] this->EigVec; - this->newVec = false; - } - if (this->newVal) { - delete[] this->EigValR; - this->newVal = false; - } - this->EigVec = EigVecp; - this->EigValR = EigValp; - this->nconv = this->FindEigenvectors(ischur); - this->EigVec = NULL; - this->EigValR = NULL; - } - return this->nconv; - -} // EigenValVectors(EigVecp, EigValp, ischur). - - -template<class ARFLOAT> -inline ARFLOAT ARrcSymStdEig<ARFLOAT>::Eigenvalue(int i) -{ - - // Returning i-eth eigenvalue. - - if (!this->ValuesOK) { - throw ArpackError(ArpackError::VALUES_NOT_OK, "Eigenvalue(i)"); - } - else if ((i>=this->nconv)||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "Eigenvalue(i)"); - } - return this->EigValR[i]; - -} // Eigenvalue(i). - - -template<class ARFLOAT> -inline ARFLOAT ARrcSymStdEig<ARFLOAT>::Eigenvector(int i, int j) -{ - - // Returning element j of i-eth eigenvector. - - if (!this->VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "Eigenvector(i,j)"); - } - else if ((i>=this->nconv)||(i<0)||(j>=this->n)||(j<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "Eigenvector(i,j)"); - } - return this->EigVec[i*this->n+j]; - -} // Eigenvector(i,j). - - -#ifdef STL_VECTOR_H - -template<class ARFLOAT> -inline vector<ARFLOAT>* ARrcSymStdEig<ARFLOAT>:: -StlEigenvalues(bool ivec, bool ischur) -{ - - // Returning the eigenvalues in a STL vector. - - vector<ARFLOAT>* StlEigValR; - ARFLOAT* ValPtr; - - try { StlEigValR = new vector<ARFLOAT>(ValSize()); } - catch (ArpackError) { return NULL; } - ValPtr = StlEigValR->begin(); - nconv = Eigenvalues(ValPtr, ivec, ischur); - return StlEigValR; - -} // StlEigenvalues. - - -template<class ARFLOAT> -inline vector<ARFLOAT>* ARrcSymStdEig<ARFLOAT>::StlEigenvector(int i) -{ - - // Returning the i-th eigenvector in a STL vector. - - vector<ARFLOAT>* Vec; - - if (!VectorsOK) { - throw ArpackError(ArpackError::VECTORS_NOT_OK, "StlEigenvector(i)"); - } - else if ((i>=ValSize())||(i<0)) { - throw ArpackError(ArpackError::RANGE_ERROR, "StlEigenvector(i)"); - } - try { - Vec = new vector<ARFLOAT>(&EigVec[i*n], &EigVec[(i+1)*n]); - } - catch (ArpackError) { return NULL; } - return Vec; - -} // StlEigenvector(i). - -#endif // #ifdef STL_VECTOR_H. - - -template<class ARFLOAT> -inline ARrcSymStdEig<ARFLOAT>:: -ARrcSymStdEig(int np, int nevp, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARrcSymStdEig<ARFLOAT>:: -ARrcSymStdEig(int np, int nevp, ARFLOAT sigmap, const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, ARFLOAT* residp, - bool ishiftp) - -{ - - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARrcSymStdEig<ARFLOAT>& ARrcSymStdEig<ARFLOAT>:: -operator=(const ARrcSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARRSSYM_H - diff --git a/src/external/arpack++/include/arscomp.h b/src/external/arpack++/include/arscomp.h deleted file mode 100644 index 709833d7..00000000 --- a/src/external/arpack++/include/arscomp.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARSComp.h. - Arpack++ class ARCompStdEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARSCOMP_H -#define ARSCOMP_H - -#include <cstddef> - -#include "arch.h" -#include "arseig.h" -#include "arrscomp.h" - -template<class ARFLOAT, class ARFOP> -class ARCompStdEig: - virtual public ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, ARFOP>, - virtual public ARrcCompStdEig<ARFLOAT> { - - public: - - // a) Constructors and destructor. - - ARCompStdEig() { } - // Short constructor. - - ARCompStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARCompStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARCompStdEig(const ARCompStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARCompStdEig() { } - // Destructor. - - // b) Operators. - - ARCompStdEig& operator=(const ARCompStdEig& other); - // Assignment operator. - -}; // class ARCompStdEig. - - -// ------------------------------------------------------------------------ // -// ARCompStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARFOP> -inline ARCompStdEig<ARFLOAT, ARFOP>:: -ARCompStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - const std::string& whichp, int ncvp, ARFLOAT tolp, int maxitp, - arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(np, nevp, objOPp, MultOPxp, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT, class ARFOP> -inline ARCompStdEig<ARFLOAT, ARFOP>:: -ARCompStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(arcomplex<ARFLOAT>[],arcomplex<ARFLOAT>[]), - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, objOPp, MultOPxp, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT, class ARFOP> -ARCompStdEig<ARFLOAT, ARFOP>& ARCompStdEig<ARFLOAT, ARFOP>:: -operator=(const ARCompStdEig<ARFLOAT, ARFOP>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARSCOMP_H diff --git a/src/external/arpack++/include/arseig.h b/src/external/arpack++/include/arseig.h deleted file mode 100644 index edac9661..00000000 --- a/src/external/arpack++/include/arseig.h +++ /dev/null @@ -1,237 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARSEig.h. - Arpack++ class ARStdEig definition. - This class is the base class for all - standard and generalized problem templates. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARSEIG_H -#define ARSEIG_H - -#include <cstddef> -#include "arch.h" -#include "arerror.h" -#include "arrseig.h" - -// ARStdEig class definition. - -template<class ARFLOAT, class ARTYPE, class ARFOP> -class ARStdEig: virtual public ARrcStdEig<ARFLOAT, ARTYPE> { - - public: - - // a) Notation. - - typedef void (ARFOP::* TypeOPx)(ARTYPE[], ARTYPE[]); - - - protected: - - // b) User defined parameters. - - ARFOP *objOP; // Object that has MultOPx as a member function. - TypeOPx MultOPx; // Function that evaluates the product OP*x. - - // c) Protected functions. - - virtual void Copy(const ARStdEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // d) Public functions: - - // d.1) Function that stores user defined parameters. - - virtual void DefineParameters(int np, int nevp, ARFOP* objOPp, - TypeOPx MultOPxp, const std::string& whichp="LM", - int ncvp=0, ARFLOAT tolp=0.0, int maxitp=0, - ARTYPE* residp=NULL, bool ishiftp=true); - // Set values of problem parameters (also called by constructors). - // Redefined in ARGenEigenProblem. - - // d.2) Function that allow changes in problem parameters. - - void ChangeMultOPx(ARFOP* objOPp, TypeOPx MultOPxp); - // Changes the matrix-vector function that performs OP*x. - - virtual void SetRegularMode(ARFOP* objOPp, TypeOPx MultOPxp); - // Turns problem to regular mode. - - virtual void SetShiftInvertMode(ARTYPE sigmap, ARFOP* objOPp, - TypeOPx MultOPxp); - // Turns problem to shift and invert mode with shift defined by sigmap. - - // d.3) Function that permits step by step execution of ARPACK. - - virtual void Iterate() { - throw ArpackError(ArpackError::NOT_IMPLEMENTED, "Iterate"); - } - // Takes one iteration of IRA method. - - - // d.4) Function that performs all calculations in one step. - - virtual int FindArnoldiBasis(); - // Determines the Arnoldi basis related to the given problem. - // Redefined in ARGenEigenProblem and ARSymGenEigenProblem. - - - // d.5) Constructor and destructor. - - ARStdEig() { } - // Constructor that does nothing but calling base class constructor. - - ARStdEig(const ARStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARStdEig() { } - // Very simple destructor. - - // e) Operators. - - ARStdEig& operator=(const ARStdEig& other); - // Assignment operator. - -}; // class ARStdEig. - - -// ------------------------------------------------------------------------ // -// ARStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARTYPE, class ARFOP> -inline void ARStdEig<ARFLOAT, ARTYPE, ARFOP>:: -Copy(const ARStdEig<ARFLOAT, ARTYPE, ARFOP>& other) -{ - - ARrcStdEig<ARFLOAT, ARTYPE>::Copy(other); - objOP = other.objOP; - MultOPx = other.MultOPx; - -} // Copy. - - -template<class ARFLOAT, class ARTYPE, class ARFOP> -void ARStdEig<ARFLOAT, ARTYPE, ARFOP>:: -DefineParameters(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARTYPE[], ARTYPE[]), const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, ARTYPE* residp, - bool ishiftp) - - -{ - - ARrcStdEig<ARFLOAT, ARTYPE>::DefineParameters(np, nevp, whichp, ncvp, tolp, - maxitp, residp, ishiftp); - objOP = objOPp; - MultOPx = MultOPxp; - -} // DefineParameters. - - -template<class ARFLOAT, class ARTYPE, class ARFOP> -inline void ARStdEig<ARFLOAT, ARTYPE, ARFOP>:: -ChangeMultOPx(ARFOP* objOPp, void (ARFOP::* MultOPxp)(ARTYPE[], ARTYPE[])) -{ - - objOP = objOPp; - MultOPx = MultOPxp; - this->Restart(); - -} // ChangeMultOPx. - - -template<class ARFLOAT, class ARTYPE, class ARFOP> -inline void ARStdEig<ARFLOAT, ARTYPE, ARFOP>:: -SetRegularMode(ARFOP* objOPp, void (ARFOP::* MultOPxp)(ARTYPE[], ARTYPE[])) -{ - - ChangeMultOPx(objOPp, MultOPxp); - this->NoShift(); - -} // SetRegularMode. - - -template<class ARFLOAT, class ARTYPE, class ARFOP> -inline void ARStdEig<ARFLOAT, ARTYPE, ARFOP>:: -SetShiftInvertMode(ARTYPE sigmap, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARTYPE[], ARTYPE[])) -{ - - ChangeMultOPx(objOPp, MultOPxp); - this->ChangeShift(sigmap); - -} // SetShiftInvertMode. - - -template<class ARFLOAT, class ARTYPE, class ARFOP> -int ARStdEig<ARFLOAT, ARTYPE, ARFOP>::FindArnoldiBasis() -{ - - if (!this->BasisOK) this->Restart(); - - // Changing to auto shift mode. - - if (!this->AutoShift) { - ArpackError::Set(ArpackError::CHANGING_AUTOSHIFT, "FindArnoldiBasis"); - this->AutoShift=true; - } - - // ARPACK main loop. - - while (!this->BasisOK) { - - // Calling Aupp. - - try { this->TakeStep(); } - catch (ArpackError) { - ArpackError(ArpackError::CANNOT_FIND_BASIS, "FindArnoldiBasis"); - return 0; - } - - if ((this->ido == -1) || (this->ido == 1)) { - - // Performing Matrix vector multiplication: y <- OP*x. - - (objOP->*MultOPx)(&this->workd[this->ipntr[1]],&this->workd[this->ipntr[2]]); - - } - - } - return this->nconv; - -} // FindArnoldiBasis. - - -template<class ARFLOAT, class ARTYPE, class ARFOP> -ARStdEig<ARFLOAT, ARTYPE, ARFOP>& ARStdEig<ARFLOAT, ARTYPE, ARFOP>:: -operator=(const ARStdEig<ARFLOAT, ARTYPE, ARFOP>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARSEIG_H - diff --git a/src/external/arpack++/include/arsnsym.h b/src/external/arpack++/include/arsnsym.h deleted file mode 100644 index 4bb9d512..00000000 --- a/src/external/arpack++/include/arsnsym.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARSNSym.h. - Arpack++ class ARNonSymStdEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARSNSYM_H -#define ARSNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arseig.h" -#include "arrsnsym.h" - - -template<class ARFLOAT, class ARFOP> -class ARNonSymStdEig: - public virtual ARStdEig<ARFLOAT, ARFLOAT, ARFOP>, - public virtual ARrcNonSymStdEig<ARFLOAT> { - - public: - - // a) Constructors and destructor. - - ARNonSymStdEig() { } - // Short constructor. - - ARNonSymStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARNonSymStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, ARFLOAT* residp = NULL, - bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARNonSymStdEig(const ARNonSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARNonSymStdEig() { } - // Destructor. - - // b) Operators. - - ARNonSymStdEig& operator=(const ARNonSymStdEig& other); - // Assignment operator. - -}; // class ARNonSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARNonSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARFOP> -inline ARNonSymStdEig<ARFLOAT, ARFOP>:: -ARNonSymStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - const std::string& whichp, int ncvp, ARFLOAT tolp, int maxitp, - ARFLOAT* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(np, nevp, objOPp, MultOPxp, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT, class ARFOP> -inline ARNonSymStdEig<ARFLOAT, ARFOP>:: -ARNonSymStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, objOPp, MultOPxp, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT, class ARFOP> -ARNonSymStdEig<ARFLOAT, ARFOP>& ARNonSymStdEig<ARFLOAT, ARFOP>:: -operator=(const ARNonSymStdEig<ARFLOAT, ARFOP>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARSNSYM_H diff --git a/src/external/arpack++/include/arssym.h b/src/external/arpack++/include/arssym.h deleted file mode 100644 index 41c46e8c..00000000 --- a/src/external/arpack++/include/arssym.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARSSym.h. - Arpack++ class ARSymStdEig definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARSSYM_H -#define ARSSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arseig.h" -#include "arrssym.h" - - -template<class ARFLOAT, class ARFOP> -class ARSymStdEig: - public virtual ARStdEig<ARFLOAT, ARFLOAT, ARFOP>, - public virtual ARrcSymStdEig<ARFLOAT> { - - public: - - // a) Constructors and destructor. - - ARSymStdEig() { } - // Short constructor. - - ARSymStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - const std::string& whichp = "LM", int ncvp = 0, ARFLOAT tolp = 0.0, - int maxitp = 0, ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARSymStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigmap, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, ARFLOAT* residp = NULL, - bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARSymStdEig(const ARSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARSymStdEig() { } - // Destructor. - - // b) Operators. - - ARSymStdEig& operator=(const ARSymStdEig& other); - // Assignment operator. - -}; // class ARSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT, class ARFOP> -inline ARSymStdEig<ARFLOAT, ARFOP>:: -ARSymStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->NoShift(); - this->DefineParameters(np, nevp, objOPp, MultOPxp, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT, class ARFOP> -inline ARSymStdEig<ARFLOAT, ARFOP>:: -ARSymStdEig(int np, int nevp, ARFOP* objOPp, - void (ARFOP::* MultOPxp)(ARFLOAT[], ARFLOAT[]), - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->ChangeShift(sigmap); - this->DefineParameters(np, nevp, objOPp, MultOPxp, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT, class ARFOP> -ARSymStdEig<ARFLOAT, ARFOP>& ARSymStdEig<ARFLOAT, ARFOP>:: -operator=(const ARSymStdEig<ARFLOAT, ARFOP>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARSSYM_H - diff --git a/src/external/arpack++/include/arugcomp.h b/src/external/arpack++/include/arugcomp.h deleted file mode 100644 index 7f34ca0d..00000000 --- a/src/external/arpack++/include/arugcomp.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUGComp.h. - Arpack++ class ARluCompGenEig definition - (umfpack version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARUGCOMP_H -#define ARUGCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arunsmat.h" -#include "arunspen.h" -#include "arrseig.h" -#include "argcomp.h" - - -template<class ARFLOAT> -class ARluCompGenEig: - public virtual - ARCompGenEig<ARFLOAT, ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT >, - ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT > > { - - private: - - // a) Data structure used to store matrices. - - ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT > Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluCompGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(arcomplex<ARFLOAT> sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(arcomplex<ARFLOAT> sigmap); - - // c.2) Constructors and destructor. - - ARluCompGenEig() { } - // Short constructor. - - ARluCompGenEig(int nevp, ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluCompGenEig(int nevp, ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluCompGenEig(const ARluCompGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluCompGenEig() { } - - // d) Operators. - - ARluCompGenEig& operator=(const ARluCompGenEig& other); - // Assignment operator. - -}; // class ARluCompGenEig. - - -// ------------------------------------------------------------------------ // -// ARluCompGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -Copy(const ARluCompGenEig<ARFLOAT>& other) -{ - - ARCompGenEig<ARFLOAT, ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT >, - ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -ChangeShift(arcomplex<ARFLOAT> sigmaRp) -{ - - this->objOP->FactorAsB(sigmaRp); - ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> >::ChangeShift(sigmaRp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetRegularMode(&Pencil, - &ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluCompGenEig<ARFLOAT>:: -SetShiftInvertMode(arcomplex<ARFLOAT> sigmap) -{ - - ARCompGenEig<ARFLOAT, ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>, - ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, - &ARumNonSymPencil<arcomplex<ARFLOAT>,ARFLOAT>::MultInvAsBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluCompGenEig<ARFLOAT>:: -ARluCompGenEig(int nevp, ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, const std::string& whichp, - int ncvp, ARFLOAT tolp, int maxitp, - arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->NoShift(); - DefineParameters(A.ncols(), nevp, &Pencil, - &ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvBAv, - &Pencil, - &ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultBv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluCompGenEig<ARFLOAT>:: -ARluCompGenEig(int nevp, ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& B, - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - DefineParameters(A.ncols(), nevp, &Pencil, - &ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultInvAsBv, - &Pencil, - &ARumNonSymPencil<arcomplex<ARFLOAT>, ARFLOAT>::MultBv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - SetShiftInvertMode(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluCompGenEig<ARFLOAT>& ARluCompGenEig<ARFLOAT>:: -operator=(const ARluCompGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUGCOMP_H diff --git a/src/external/arpack++/include/arugnsym.h b/src/external/arpack++/include/arugnsym.h deleted file mode 100644 index 3061e68b..00000000 --- a/src/external/arpack++/include/arugnsym.h +++ /dev/null @@ -1,245 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUGNSym.h. - Arpack++ class ARluNonSymGenEig definition - (umfpack version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARUGNSYM_H -#define ARUGNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arunsmat.h" -#include "arunspen.h" -#include "argnsym.h" - - -template<class ARFLOAT> -class ARluNonSymGenEig: - public virtual ARNonSymGenEig<ARFLOAT, ARumNonSymPencil<ARFLOAT, ARFLOAT>, - ARumNonSymPencil<ARFLOAT, ARFLOAT> > { - - protected: - - // a) Data structure used to store matrices. - - ARumNonSymPencil<ARFLOAT, ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluNonSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp = 0.0); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetComplexShiftMode(char partp, ARFLOAT sigmaRp, - ARFLOAT sigmaIp); - - // c.2) Constructors and destructor. - - ARluNonSymGenEig() { } - // Short constructor. - - ARluNonSymGenEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARumNonSymMatrix<ARFLOAT, ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluNonSymGenEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARumNonSymMatrix<ARFLOAT, ARFLOAT>& B, ARFLOAT sigma, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (real shift and invert mode). - - ARluNonSymGenEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARumNonSymMatrix<ARFLOAT, ARFLOAT>& B, char partp, - ARFLOAT sigmaRp, ARFLOAT sigmaIp, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (complex shift and invert mode). - - ARluNonSymGenEig(const ARluNonSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluNonSymGenEig& operator=(const ARluNonSymGenEig& other); - // Assignment operator. - -}; // class ARluNonSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluNonSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -Copy(const ARluNonSymGenEig<ARFLOAT>& other) -{ - - ARNonSymGenEig<ARFLOAT, ARumNonSymPencil<ARFLOAT, ARFLOAT>, - ARumNonSymPencil<ARFLOAT, ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -ChangeShift(ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - if (sigmaIp == 0.0) { - this->objOP->FactorAsB(sigmaRp); - } - else { - this->objOP->FactorAsB(sigmaRp, sigmaIp, this->part); - } - ARrcNonSymGenEig<ARFLOAT>::ChangeShift(sigmaRp, sigmaIp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARumNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetRegularMode(&Pencil, &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARNonSymGenEig<ARFLOAT, ARumNonSymPencil<ARFLOAT, ARFLOAT>, - ARumNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, - &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluNonSymGenEig<ARFLOAT>:: -SetComplexShiftMode(char partp, ARFLOAT sigmaRp, ARFLOAT sigmaIp) -{ - - ARNonSymGenEig<ARFLOAT, ARumNonSymPencil<ARFLOAT, ARFLOAT>, - ARumNonSymPencil<ARFLOAT, ARFLOAT> >:: - SetComplexShiftMode(partp, sigmaRp, sigmaIp, &Pencil, - &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, - &Pencil, &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultAv); - -} // SetComplexShiftMode. - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARumNonSymMatrix<ARFLOAT, ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->NoShift(); - DefineParameters(A.ncols(), nevp, &Pencil, - &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultInvBAv, &Pencil, - &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARumNonSymMatrix<ARFLOAT, ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - DefineParameters(A.ncols(), nevp, &Pencil, - &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, &Pencil, - &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - SetShiftInvertMode(sigmap); - -} // Long constructor (real shift and invert mode). - - -template<class ARFLOAT> -inline ARluNonSymGenEig<ARFLOAT>:: -ARluNonSymGenEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARumNonSymMatrix<ARFLOAT, ARFLOAT>& B, - char partp, ARFLOAT sigmaRp, - ARFLOAT sigmaIp, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - DefineParameters(A.ncols(), nevp, &Pencil, - &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultInvAsBv, &Pencil, - &ARumNonSymPencil<ARFLOAT, ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - SetComplexShiftMode(partp, sigmaRp, sigmaIp); - -} // Long constructor (complex shift and invert mode). - - -template<class ARFLOAT> -ARluNonSymGenEig<ARFLOAT>& ARluNonSymGenEig<ARFLOAT>:: -operator=(const ARluNonSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUGNSYM_H diff --git a/src/external/arpack++/include/arugsym.h b/src/external/arpack++/include/arugsym.h deleted file mode 100644 index d57dc451..00000000 --- a/src/external/arpack++/include/arugsym.h +++ /dev/null @@ -1,234 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUGSym.h. - Arpack++ class ARluSymGenEig definition - (UMFPACK version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Kristi Maschhoff - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARUGSYM_H -#define ARUGSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arusmat.h" -#include "aruspen.h" -#include "argsym.h" - - -template<class ARFLOAT> -class ARluSymGenEig: - public virtual ARSymGenEig<ARFLOAT, ARumSymPencil<ARFLOAT>, - ARumSymPencil<ARFLOAT> > { - - private: - - // a) Data structure used to store matrices. - - ARumSymPencil<ARFLOAT> Pencil; - - // b) Protected functions: - - virtual void Copy(const ARluSymGenEig& other); - // Makes a deep copy of "other" over "this" object. - // Old values are not deleted (this function is to be used - // by the copy constructor and the assignment operator only). - - - public: - - // c) Public functions: - - // c.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmap); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - virtual void SetBucklingMode(ARFLOAT sigmap); - - virtual void SetCayleyMode(ARFLOAT sigmap); - - // c.2) Constructors and destructor. - - ARluSymGenEig() { } - // Short constructor. - - ARluSymGenEig(int nevp, ARumSymMatrix<ARFLOAT>& A, - ARumSymMatrix<ARFLOAT>& B, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymGenEig(char InvertModep, int nevp, ARumSymMatrix<ARFLOAT>& A, - ARumSymMatrix<ARFLOAT>& B, ARFLOAT sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert, buckling and Cayley modes). - - ARluSymGenEig(const ARluSymGenEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymGenEig() { } - // Destructor. - - // d) Operators. - - ARluSymGenEig& operator=(const ARluSymGenEig& other); - // Assignment operator. - -}; // class ARluSymGenEig. - - -// ------------------------------------------------------------------------ // -// ARluSymGenEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -Copy(const ARluSymGenEig<ARFLOAT>& other) -{ - - ARSymGenEig<ARFLOAT, ARumSymPencil<ARFLOAT>, - ARumSymPencil<ARFLOAT> >:: Copy(other); - Pencil = other.Pencil; - this->objOP = &Pencil; - this->objB = &Pencil; - this->objA = &Pencil; - -} // Copy. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::ChangeShift(ARFLOAT sigmap) -{ - - this->objOP->FactorAsB(sigmap); - ARrcSymGenEig<ARFLOAT>::ChangeShift(sigmap); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARumSymPencil<ARFLOAT> >:: - SetRegularMode(&Pencil, &ARumSymPencil<ARFLOAT>::MultInvBAv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARumSymPencil<ARFLOAT>, ARumSymPencil<ARFLOAT> >:: - SetShiftInvertMode(sigmap, &Pencil, &ARumSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARumSymPencil<ARFLOAT>::MultBv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetBucklingMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARumSymPencil<ARFLOAT>, ARumSymPencil<ARFLOAT> >:: - SetBucklingMode(sigmap, &Pencil, &ARumSymPencil<ARFLOAT>::MultInvAsBv); - this->ChangeMultBx(&Pencil, &ARumSymPencil<ARFLOAT>::MultAv); - -} // SetBucklingMode. - - -template<class ARFLOAT> -inline void ARluSymGenEig<ARFLOAT>:: -SetCayleyMode(ARFLOAT sigmap) -{ - - ARSymGenEig<ARFLOAT, ARumSymPencil<ARFLOAT>, ARumSymPencil<ARFLOAT> >:: - SetCayleyMode(sigmap, &Pencil, &ARumSymPencil<ARFLOAT>::MultInvAsBv, - &Pencil, &ARumSymPencil<ARFLOAT>::MultAv); - this->ChangeMultBx(&Pencil, &ARumSymPencil<ARFLOAT>::MultBv); - -} // SetCayleyMode. - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(int nevp, ARumSymMatrix<ARFLOAT>& A, - ARumSymMatrix<ARFLOAT>& B, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->InvertMode = 'S'; - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARumSymPencil<ARFLOAT>::MultInvBAv, &Pencil, - &ARumSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymGenEig<ARFLOAT>:: -ARluSymGenEig(char InvertModep, int nevp, ARumSymMatrix<ARFLOAT>& A, - ARumSymMatrix<ARFLOAT>& B, ARFLOAT sigmap, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - Pencil.DefineMatrices(A, B); - this->DefineParameters(A.ncols(), nevp, &Pencil, - &ARumSymPencil<ARFLOAT>::MultInvAsBv, &Pencil, - &ARumSymPencil<ARFLOAT>::MultBv, whichp, - ncvp, tolp, maxitp, residp, ishiftp); - this->InvertMode = this->CheckInvertMode(InvertModep); - switch (this->InvertMode) { - case 'B': // Buckling mode. - this->ChangeMultBx(&Pencil, &ARumSymPencil<ARFLOAT>::MultAv); - case 'S': // Shift and invert mode. - this->ChangeShift(sigmap); - break; - case 'C': // Cayley mode. - this->SetCayleyMode(sigmap); - } - -} // Long constructor (shift and invert, buckling and Cayley modes). - - -template<class ARFLOAT> -ARluSymGenEig<ARFLOAT>& ARluSymGenEig<ARFLOAT>:: -operator=(const ARluSymGenEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUGSYM_H diff --git a/src/external/arpack++/include/arunsmat.h b/src/external/arpack++/include/arunsmat.h deleted file mode 100644 index 801b02e3..00000000 --- a/src/external/arpack++/include/arunsmat.h +++ /dev/null @@ -1,646 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUNSMat.h. - Arpack++ class ARumNonSymMatrix definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "arunspen.h" - -#ifndef ARUNSMAT_H -#define ARUNSMAT_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "armat.h" -#include "arhbmat.h" -#include "arerror.h" -#include "blas1c.h" -#include "umfpackc.h" - -template<class AR_T, class AR_S> class ARumNonSymPencil; - -template<class ARTYPE, class ARFLOAT> -class ARumNonSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARumNonSymPencil<ARTYPE, ARFLOAT>; - friend class ARumNonSymPencil<ARFLOAT, ARFLOAT>; - - protected: - - bool factored; - int fillin; - int nnz; - int lvalue; - int lindex; - int keep[20]; - int icntl[20]; - int info[40]; - int* irow; - int* pcol; - int* index; - double threshold; - ARTYPE cntl[10]; - ARTYPE rinfo[20]; - ARTYPE* a; - ARTYPE* value; - ARhbMatrix<int, ARTYPE> mat; - - bool DataOK(); - - void ClearMem(); - - virtual void Copy(const ARumNonSymMatrix& other); - - void SubtractAsI(ARTYPE sigma); - - void CreateStructure(); - - void ThrowError(); - - public: - - int nzeros() { return nnz; } - - int FillFact() { return fillin; } - - bool IsSymmetric() { return bool(icntl[5]); } - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultMtv(ARTYPE* v, ARTYPE* w); - - void MultMtMv(ARTYPE* v, ARTYPE* w); - - void MultMMtv(ARTYPE* v, ARTYPE* w); - - void Mult0MMt0v(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, double thresholdp = 0.1, - int fillinp = 9, bool simest = false, - bool reducible = true, bool check = true); // Square. - - void DefineMatrix(int mp, int np, int nnzp, ARTYPE* ap, - int* irowp, int* pcolp); // Rectangular. - - ARumNonSymMatrix(): ARMatrix<ARTYPE>() { factored = false; } - // Short constructor that does nothing. - - ARumNonSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, double thresholdp = 0.1, - int fillinp = 9, bool simest = false, - bool reducible = true, bool check = true); - // Long constructor (square matrix). - - ARumNonSymMatrix(int mp, int np, int nnzp, ARTYPE* ap, - int* irowp, int* pcolp); - // Long constructor (rectangular matrix). - - ARumNonSymMatrix(const std::string& name, double thresholdp = 0.1, - int fillinp = 9, bool simest = false, - bool reducible = true, bool check = true); - // Long constructor (Harwell-Boeing file). - - ARumNonSymMatrix(const ARumNonSymMatrix& other) { Copy(other); } - // Copy constructor. - - virtual ~ARumNonSymMatrix() { ClearMem(); } - // Destructor. - - ARumNonSymMatrix& operator=(const ARumNonSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARumNonSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE, class ARFLOAT> -bool ARumNonSymMatrix<ARTYPE, ARFLOAT>::DataOK() -{ - - int i, j, k; - - // Checking if pcol is in ascending order. - - i = 0; - while ((i!=this->n)&&(pcol[i]<=pcol[i+1])) i++; - if (i!=this->n) return false; - - // Checking if irow components are in order and within bounds. - - for (i=0; i!=this->n; i++) { - j = pcol[i]; - k = pcol[i+1]-1; - if (j<=k) { - if ((irow[j]<0)||(irow[k]>=this->n)) return false; - while ((j!=k)&&(irow[j]<irow[j+1])) j++; - if (j!=k) return false; - } - } - - return true; - -} // DataOK. - - -template<class ARTYPE, class ARFLOAT> -inline void ARumNonSymMatrix<ARTYPE, ARFLOAT>::ClearMem() -{ - - if (factored) { - delete[] value; - delete[] index; - value = NULL; - index = NULL; - } - -} // ClearMem. - - -template<class ARTYPE, class ARFLOAT> -inline void ARumNonSymMatrix<ARTYPE, ARFLOAT>:: -Copy(const ARumNonSymMatrix<ARTYPE, ARFLOAT>& other) -{ - - // Local variable. - - int i; - - // Copying very fundamental variables and user-defined parameters. - - this->m = other.m; - this->n = other.n; - this->defined = other.defined; - factored = other.factored; - fillin = other.fillin; - nnz = other.nnz; - lvalue = other.lvalue; - lindex = other.lindex; - irow = other.irow; - pcol = other.pcol; - a = other.a; - threshold = other.threshold; - - // Returning from here if "other" was not initialized. - - if (!this->defined) return; - - // Copying arrays with static dimension. - - for (i=0; i<20; i++) keep[i] = other.keep[i]; - for (i=0; i<20; i++) icntl[i] = other.icntl[i]; - for (i=0; i<40; i++) info[i] = other.info[i]; - for (i=0; i<10; i++) cntl[i] = other.cntl[i]; - for (i=0; i<20; i++) rinfo[i] = other.rinfo[i]; - - // Returning from here if "other" was not factored. - - if (!factored) return; - - value = new ARTYPE[lvalue]; - index = new int[lindex]; - - for (i=0; i<lindex; i++) index[i] = other.index[i]; - copy(lvalue, other.value, 1, value, 1); - -} // Copy. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::SubtractAsI(ARTYPE sigma) -{ - - int i, j, k, ki, end; - - // Subtracting sigma from diagonal elements. - - k = 0; - ki = this->n+1; - index[0] = 1; - - for (i=0; i!=this->n; i++) { - - j = pcol[i]; - end = pcol[i+1]; - - // Copying superdiagonal elements of column i. - - while ((irow[j] < i)&&(j < end)) { - value[k++] = a[j]; - index[ki++] = irow[j++]+1; - } - - // Verifying if A(i,i) exists. - - if ((irow[j] == i)&&(j < end)) { // A(i,i) exists, subtracting sigma. - value[k++] = a[j++] - sigma; - } - else { // A(i,i) does not exist. - value[k++] = -sigma; - } - index[ki++] = i+1; - - // Copying subdiagonal elements of column i. - - while (j < end ) { - value[k++] = a[j]; - index[ki++] = irow[j++]+1; - } - - index[i+1] = k+1; - - } - -} // SubtractAsI. - - -template<class ARTYPE, class ARFLOAT> -inline void ARumNonSymMatrix<ARTYPE, ARFLOAT>::CreateStructure() -{ - - int dimfact = (((fillin+1)*nnz)<(this->n*this->n)) ? (fillin+1)*nnz : this->n*this->n; - - this->ClearMem(); - - lindex = 30*this->n+dimfact; // ????? - lvalue = dimfact; - - value = new ARTYPE[lvalue]; - index = new int[lindex]; - -} // CreateStructure. - - -template<class ARTYPE, class ARFLOAT> -inline void ARumNonSymMatrix<ARTYPE, ARFLOAT>::ThrowError() -{ - - if (info[0] < -2) { // Memory is not suficient. - throw ArpackError(ArpackError::INSUFICIENT_MEMORY, - "ARumNonSymMatrix::FactorA"); - } - else if (info[0] > 3) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARumNonSymMatrix::FactorA"); - } - else if (info[0] != 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARumNonSymMatrix::FactorA"); - } - -} // ThrowError. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::FactorA() -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED,"ARumNonSymMatrix::FactorA"); - } - - // Quitting the function if A is not square. - - if (this->m != this->n) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARumNonSymMatrix::FactorA"); - } - - // Defining local variables. - - int i; - int *pi, *pj; - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Copying A to (value, index); - - copy(nnz, a, 1, value, 1); - pi=pcol; - pj=index; - for (i=0; i<=this->n; i++) *pj++ = (*pi++)+1; - pi=irow; - for (i=0; i<nnz; i++) *pj++ = (*pi++)+1; - - // Decomposing A. - - um2fa(this->n, nnz, 0, false, lvalue, lindex, value, - index, keep, cntl, icntl, info, rinfo); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorA. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::FactorAsI(ARTYPE sigma) -{ - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARumNonSymMatrix::FactorAsI"); - } - - // Quitting the function if A is not square. - - if (this->m != this->n) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARumNonSymMatrix::FactorAsI"); - } - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Subtracting sigma*I from A. - - SubtractAsI(sigma); - - // Decomposing AsI. - - um2fa(this->n, nnz, 0, false, lvalue, lindex, value, - index, keep, cntl, icntl, info, rinfo); - - // Handling errors. - - ThrowError(); - - factored = true; - -} // FactorAsI. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::MultMv(ARTYPE* v, ARTYPE* w) -{ - - int i,j; - ARTYPE t; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARumNonSymMatrix::MultMv"); - } - - // Determining w = M.v. - - for (i=0; i!=this->m; i++) w[i]=(ARTYPE)0; - - for (i=0; i!=this->n; i++) { - t = v[i]; - for (j=pcol[i]; j!=pcol[i+1]; j++) { - w[irow[j]] += t*a[j]; - } - } - -} // MultMv. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::MultMtv(ARTYPE* v, ARTYPE* w) -{ - - int i,j; - ARTYPE t; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED,"ARumNonSymMatrix::MultMtv"); - } - - // Determining w = M'.v. - - for (i=0; i!=this->n; i++) { - t = (ARTYPE)0; - for (j=pcol[i]; j!=pcol[i+1]; j++) { - t += v[irow[j]]*a[j]; - } - w[i] = t; - } - -} // MultMtv. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::MultMtMv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE* t = new ARTYPE[this->m]; - - MultMv(v,t); - MultMtv(t,w); - - delete[] t; - -} // MultMtMv. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::MultMMtv(ARTYPE* v, ARTYPE* w) -{ - - ARTYPE* t = new ARTYPE[this->n]; - - MultMtv(v,t); - MultMv(t,w); - - delete[] t; - -} // MultMMtv. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::Mult0MMt0v(ARTYPE* v, ARTYPE* w) -{ - - MultMv(&v[this->m],w); - MultMtv(v,&w[this->m]); - -} // Mult0MMt0v. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymMatrix<ARTYPE, ARFLOAT>::MultInvv(ARTYPE* v, ARTYPE* w) -{ - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARumNonSymMatrix::MultInvv"); - } - - // Solving A.w = v (or AsI.w = v). - - ARTYPE* space = new ARTYPE[2*this->n]; - - um2so(this->n, 0, false, lvalue, lindex, value, index, - keep, v, w, space, cntl, icntl, info, rinfo); - - delete[] space; - -} // MultInvv. - - -template<class ARTYPE, class ARFLOAT> -inline void ARumNonSymMatrix<ARTYPE, ARFLOAT>:: -DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, double thresholdp, int fillinp, - bool simest, bool reducible, bool check) -{ - - // Defining member variables. - - this->m = np; - this->n = np; - nnz = nnzp; - a = ap; - irow = irowp; - pcol = pcolp; - pcol[this->n] = nnz; - fillin = (fillinp>2) ? fillinp : 2; - threshold = thresholdp; - value = NULL; - index = NULL; - - // Preparing umfpack. - - um21i(keep, cntl, icntl, threshold, simest, reducible); - - // Checking data. - - if ((check)&&(!DataOK())) { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARumNonSymMatrix::DefineMatrix"); - } - else { - this->defined = true; - } - -} // DefineMatrix (square). - - -template<class ARTYPE, class ARFLOAT> -inline void ARumNonSymMatrix<ARTYPE, ARFLOAT>:: -DefineMatrix(int mp, int np, int nnzp, ARTYPE* ap, int* irowp, int* pcolp) -{ - - // Defining member variables. - - this->m = mp; - this->n = np; - nnz = nnzp; - a = ap; - irow = irowp; - pcol = pcolp; - pcol[this->n] = nnz; - fillin = 0; - this->defined = true; - -} // DefineMatrix (rectangular). - - -template<class ARTYPE, class ARFLOAT> -inline ARumNonSymMatrix<ARTYPE, ARFLOAT>:: -ARumNonSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, double thresholdp, int fillinp, - bool simest, bool reducible, bool check): ARMatrix<ARTYPE>(np) -{ - - factored = false; - DefineMatrix(np, nnzp, ap, irowp, pcolp, thresholdp, - fillinp, simest, reducible, check); - -} // Long constructor (square matrix). - - -template<class ARTYPE, class ARFLOAT> -inline ARumNonSymMatrix<ARTYPE, ARFLOAT>:: -ARumNonSymMatrix(int mp, int np, int nnzp, ARTYPE* ap, - int* irowp, int* pcolp) : ARMatrix<ARTYPE>(mp, np) -{ - - factored = false; - DefineMatrix(mp, np, nnzp, ap, irowp, pcolp); - -} // Long constructor (rectangular matrix). - - -template<class ARTYPE, class ARFLOAT> -ARumNonSymMatrix<ARTYPE, ARFLOAT>:: -ARumNonSymMatrix(const std::string& name, double thresholdp, int fillinp, - bool simest, bool reducible, bool check) -{ - - factored = false; - - try { - mat.Define(name); - } - catch (ArpackError) { // Returning from here if an error has occurred. - throw ArpackError(ArpackError::CANNOT_READ_FILE, "ARumNonSymMatrix"); - } - - if (mat.NCols()==mat.NRows()) { - DefineMatrix(mat.NCols(), mat.NonZeros(), (ARTYPE*)mat.Entries(), - mat.RowInd(), mat.ColPtr(), thresholdp, - fillinp, simest, reducible, check); - } - else { - DefineMatrix(mat.NRows(), mat.NCols(), mat.NonZeros(), - (ARTYPE*)mat.Entries(), mat.RowInd(), mat.ColPtr()); - } - -} // Long constructor (Harwell-Boeing file). - - -template<class ARTYPE, class ARFLOAT> -ARumNonSymMatrix<ARTYPE, ARFLOAT>& ARumNonSymMatrix<ARTYPE, ARFLOAT>:: -operator=(const ARumNonSymMatrix<ARTYPE, ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUNSMAT_H diff --git a/src/external/arpack++/include/arunspen.h b/src/external/arpack++/include/arunspen.h deleted file mode 100644 index 771b3746..00000000 --- a/src/external/arpack++/include/arunspen.h +++ /dev/null @@ -1,527 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUNSPen.h. - Arpack++ class ARumNonSymPencil definition. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARUNSPEN_H -#define ARUNSPEN_H - -#include "arch.h" -#include "arerror.h" -#include "blas1c.h" -#include "umfpackc.h" -#include "arunsmat.h" - - -template<class ARTYPE, class ARFLOAT> -class ARumNonSymPencil -{ - - protected: - - char part; - ARumNonSymMatrix<ARTYPE, ARFLOAT>* A; - ARumNonSymMatrix<ARTYPE, ARFLOAT>* B; - ARumNonSymMatrix<ARTYPE, ARFLOAT> AsB; -#ifdef ARCOMP_H - ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> AsBc; -#endif - - virtual void Copy(const ARumNonSymPencil& other); - - void SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], - int yind[], int ny, ARTYPE z[], int zind[], int& nz); - -#ifdef ARCOMP_H - void SparseSaxpy(arcomplex<ARFLOAT> a, ARFLOAT x[], int xind[], int nx, - ARFLOAT y[], int yind[], int ny, - arcomplex<ARFLOAT> z[], int zind[], int& nz); -#endif - - void SubtractAsB(ARTYPE sigma); - -#ifdef ARCOMP_H - void SubtractAsB(ARFLOAT sigmaR, ARFLOAT sigmaI); -#endif - - public: - -#ifdef ARCOMP_H - bool IsFactored() { return (AsB.IsFactored()||AsBc.IsFactored()); } -#else - bool IsFactored() { return AsB.IsFactored(); } -#endif - - bool IsSymmetric() { return AsB.IsSymmetric(); } - - void FactorAsB(ARTYPE sigma); - -#ifdef ARCOMP_H - void FactorAsB(ARFLOAT sigmaR, ARFLOAT sigmaI, char partp = 'R'); -#endif - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - -#ifdef ARCOMP_H - void MultInvAsBv(arcomplex<ARFLOAT>* v, arcomplex<ARFLOAT>* w); -#endif - - void MultInvAsBv(ARFLOAT* v, ARFLOAT* w); - - void DefineMatrices(ARumNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARumNonSymMatrix<ARTYPE, ARFLOAT>& Bp); - - ARumNonSymPencil() { part = 'N'; } - // Short constructor that does nothing. - - ARumNonSymPencil(ARumNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARumNonSymMatrix<ARTYPE, ARFLOAT>& Bp); - // Long constructor. - - ARumNonSymPencil(const ARumNonSymPencil& other) { Copy(other); } - // Copy constructor. - - virtual ~ARumNonSymPencil() { } - // Destructor. - - ARumNonSymPencil& operator=(const ARumNonSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARumNonSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE, class ARFLOAT> -inline void ARumNonSymPencil<ARTYPE, ARFLOAT>:: -Copy(const ARumNonSymPencil<ARTYPE, ARFLOAT>& other) -{ - - part = other.part; - A = other.A; - B = other.B; - AsB = other.AsB; -#ifdef ARCOMP_H - AsBc = other.AsBc; -#endif - -} // Copy. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>:: -SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], - int yind[], int ny, ARTYPE z[], int zind[], int& nz) -// A strongly sequential (and inefficient) sparse saxpy algorithm. -{ - - int ix, iy; - - nz = 0; - if ((nx == 0) || (a == (ARTYPE)0)) { - copy(ny,y,1,z,1); - for (iy=0; iy!=ny; iy++) zind[iy] = yind[iy]; - nz = ny; - return; - } - if (ny == 0) { - copy(nx,x,1,z,1); - scal(nx,a,z,1); - for (ix=0; ix!=nx; ix++) zind[ix] = xind[ix]; - nz = nx; - return; - } - ix = 0; - iy = 0; - while (true) { - if (xind[ix] == yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]+y[iy++]; - if ((ix == nx)||(iy == ny)) break; - } - else if (xind[ix] < yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]; - if (ix == nx) break; - } - else { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - if (iy == ny) break; - } - } - while (iy < ny) { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - } - while (ix < nx) { - zind[nz] = xind[ix]; - z[nz++] = x[ix++]; - } - -} // SparseSaxpy (ARTYPE). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>:: -SparseSaxpy(arcomplex<ARFLOAT> a, ARFLOAT x[], int xind[], int nx, - ARFLOAT y[], int yind[], int ny, - arcomplex<ARFLOAT> z[], int zind[], int& nz) -// A strongly sequential (and inefficient) sparse saxpy algorithm. -{ - - int ix, iy; - - nz = 0; - if ((nx == 0) || (a == arcomplex<ARFLOAT>(0.0,0.0))) { - for (iy=0; iy!=ny; iy++) { - z[iy] = arcomplex<ARFLOAT>(y[iy],0.0); - zind[iy] = yind[iy]; - } - nz = ny; - return; - } - if (ny == 0) { - for (ix=0; ix!=ny; ix++) { - z[ix] = a*arcomplex<ARFLOAT>(x[ix],0.0); - zind[ix] = xind[ix]; - } - nz = nx; - return; - } - ix = 0; - iy = 0; - while (true) { - if (xind[ix] == yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]+y[iy++]; - if ((ix == nx)||(iy == ny)) break; - } - else if (xind[ix] < yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]; - if (ix == nx) break; - } - else { - zind[nz] = yind[iy]; - z[nz++] = arcomplex<ARFLOAT>(y[iy++], 0.0); - if (iy == ny) break; - } - } - while (iy < ny) { - zind[nz] = yind[iy]; - z[nz++] = arcomplex<ARFLOAT>(y[iy++], 0.0); - } - while (ix < nx) { - zind[nz] = xind[ix]; - z[nz++] = arcomplex<ARFLOAT>(x[ix++], 0.0); - } - -} // SparseSaxpy (arcomplex<ARFLOAT>). -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>::SubtractAsB(ARTYPE sigma) -{ - - int i, acol, bcol, asbcol, scol; - - // Subtracting sigma*B from A. - - AsB.index[0] = 0; - asbcol = 0; - - for (i=0; i!=AsB.n; i++) { - bcol = B->pcol[i]; - acol = A->pcol[i]; - SparseSaxpy(-sigma, &B->a[bcol], &B->irow[bcol], B->pcol[i+1]-bcol, - &A->a[acol], &A->irow[acol], A->pcol[i+1]-acol, - &AsB.value[asbcol], &AsB.index[asbcol+AsB.n+1], scol); - asbcol += scol; - AsB.index[i+1] = asbcol; - } - - AsB.nnz = asbcol; - - // Adding one to all elements of vector index - // because the decomposition function was written in FORTRAN. - - for (i=0; i<=AsB.n+AsB.nnz; i++) AsB.index[i]++; - -} // SubtractAsB (ARTYPE shift). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>:: -SubtractAsB(ARFLOAT sigmaR, ARFLOAT sigmaI) -{ - - int i, acol, bcol, asbcol, scol; - arcomplex<ARFLOAT> sigma; - - // Subtracting sigma*B from A. - - sigma = arcomplex<ARFLOAT>(sigmaR, sigmaI); - AsBc.index[0] = 0; - asbcol = 0; - - for (i=0; i!=AsBc.n; i++) { - bcol = B->pcol[i]; - acol = A->pcol[i]; - SparseSaxpy(-sigma, &B->a[bcol], &B->irow[bcol], B->pcol[i+1]-bcol, - &A->a[acol], &A->irow[acol], A->pcol[i+1]-acol, - &AsBc.value[asbcol], &AsBc.index[asbcol+AsBc.n+1], scol); - asbcol += scol; - AsBc.index[i+1] = asbcol; - } - - AsBc.nnz = asbcol; - - // Adding one to all elements of vector index - // because the decomposition function was written in FORTRAN. - - for (i=0; i<=AsBc.n+AsBc.nnz; i++) AsBc.index[i]++; - -} // SubtractAsB (arcomplex<ARFLOAT> shift). -#endif // ARCOMP_H - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARumNonSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARumNonSymPencil::FactorAsB"); - } - - // Defining matrix AsB. - - if (!AsB.IsDefined()) { - - int fillin = A->fillin > B->fillin ? A->fillin : B->fillin; - AsB.DefineMatrix(A->ncols(), A->nzeros(), A->a, A->irow, - A->pcol, A->threshold, fillin, - (A->IsSymmetric() && B->IsSymmetric()), - A->icntl[3], false); - AsB.nnz = A->nzeros()+B->nzeros(); // temporary value. - - } - - // Reserving memory for some vectors used in matrix decomposition. - - AsB.CreateStructure(); // AsB.nnz must be set to A->nzeros()+B->nzeros(). - - // Subtracting sigma*B from A and storing the result on AsB. - - SubtractAsB(sigma); - - // Decomposing AsB. - - um2fa(AsB.n, AsB.index[AsB.n], 0, false, AsB.lvalue, AsB.lindex, AsB.value, - AsB.index, AsB.keep, AsB.cntl, AsB.icntl, AsB.info, AsB.rinfo); - - // Handling errors. - - AsB.ThrowError(); - - AsB.factored = true; - -} // FactorAsB (ARTYPE shift). - - -#ifdef ARCOMP_H -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>:: -FactorAsB(ARFLOAT sigmaR, ARFLOAT sigmaI, char partp) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARumNonSymPencil::FactorAsB"); - } - - // Quitting the function if A and B are not square. - - if ((A->nrows() != A->ncols()) || (B->nrows() != B->ncols())) { - throw ArpackError(ArpackError::NOT_SQUARE_MATRIX, - "ARumNonSymPencil::FactorAsB"); - } - - // Defining matrix AsB. - - if (!AsBc.IsDefined()) { - - part = partp; - int fillin = A->fillin > B->fillin ? A->fillin : B->fillin; - AsBc.DefineMatrix(A->ncols(), A->nzeros(), 0, 0, - A->pcol, A->threshold, fillin, - (A->IsSymmetric() && B->IsSymmetric()), - A->icntl[3], false); - AsBc.nnz = A->nzeros()+B->nzeros(); // temporary value. - - } - - // Reserving memory for some vectors used in matrix decomposition. - - AsBc.CreateStructure(); // AsBc.nnz must be set to A->nzeros()+B->nzeros(). - - // Subtracting sigma*B from A and storing the result on AsBc. - - SubtractAsB(sigmaR, sigmaI); - - // Decomposing AsB. - - um2fa(AsBc.n, AsBc.index[AsBc.n], 0, false, AsBc.lvalue, AsBc.lindex, - AsBc.value, AsBc.index, AsBc.keep, AsBc.cntl, AsBc.icntl, - AsBc.info, AsBc.rinfo); - - // Handling errors. - - AsBc.ThrowError(); - - AsBc.factored = true; - -} // FactorAsB (arcomplex<ARFLOAT> shift). -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - B->MultInvv(w, w); - -} // MultInvBAv. - - -#ifdef ARCOMP_H - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>:: -MultInvAsBv(arcomplex<ARFLOAT>* v, arcomplex<ARFLOAT>* w) -{ - - AsB.MultInvv((ARTYPE*)v,(ARTYPE*)w); - -} // MultInvAsBv (arcomplex<ARFLOAT>). - -#endif // ARCOMP_H. - - -template<class ARTYPE, class ARFLOAT> -void ARumNonSymPencil<ARTYPE, ARFLOAT>::MultInvAsBv(ARFLOAT* v, ARFLOAT* w) -{ - - if (part == 'N') { // shift is real. - - AsB.MultInvv((ARTYPE*)v,(ARTYPE*)w); - - } - else { // shift is complex. - -#ifdef ARCOMP_H - - int i; - arcomplex<ARFLOAT> *tv, *tw; - - tv = new arcomplex<ARFLOAT>[AsBc.ncols()]; - tw = new arcomplex<ARFLOAT>[AsBc.ncols()]; - - for (i=0; i!=AsBc.ncols(); i++) tv[i] = arcomplex<ARFLOAT>(v[i], 0.0); - - AsBc.MultInvv(tv, tw); - - if (part=='I') { - for (i=0; i!=AsBc.ncols(); i++) w[i] = imag(tw[i]); - } - else { - for (i=0; i!=AsBc.ncols(); i++) w[i] = real(tw[i]); - } - - delete[] tv; - delete[] tw; - -#endif // ARCOMP_H. - - } - -} // MultInvAsBv (ARFLOAT). - - -template<class ARTYPE, class ARFLOAT> -inline void ARumNonSymPencil<ARTYPE, ARFLOAT>:: -DefineMatrices(ARumNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARumNonSymMatrix<ARTYPE, ARFLOAT>& Bp) -{ - - A = &Ap; - B = &Bp; - - if ((A->n != B->n)||(A->m != B->m)) { - throw ArpackError(ArpackError::INCOMPATIBLE_SIZES, - "ARumNonSymMatrix::DefineMatrices"); - } - -} // DefineMatrices. - - -template<class ARTYPE, class ARFLOAT> -inline ARumNonSymPencil<ARTYPE, ARFLOAT>:: -ARumNonSymPencil(ARumNonSymMatrix<ARTYPE, ARFLOAT>& Ap, - ARumNonSymMatrix<ARTYPE, ARFLOAT>& Bp) -{ - - DefineMatrices(Ap, Bp); - -} // Long constructor. - - -template<class ARTYPE, class ARFLOAT> -ARumNonSymPencil<ARTYPE, ARFLOAT>& ARumNonSymPencil<ARTYPE, ARFLOAT>:: -operator=(const ARumNonSymPencil<ARTYPE, ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUNSPEN_H diff --git a/src/external/arpack++/include/aruscomp.h b/src/external/arpack++/include/aruscomp.h deleted file mode 100644 index 13ddff71..00000000 --- a/src/external/arpack++/include/aruscomp.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUSComp.h. - Arpack++ class ARluCompStdEig definition - (umfpack version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARUSCOMP_H -#define ARUSCOMP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arscomp.h" -#include "arunsmat.h" -#include "arrseig.h" - - -template<class ARFLOAT> -class ARluCompStdEig: - public virtual ARCompStdEig<ARFLOAT, - ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(arcomplex<ARFLOAT> sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(arcomplex<ARFLOAT> sigmap); - - // a.2) Constructors and destructor. - - ARluCompStdEig() { } - // Short constructor. - - ARluCompStdEig(int nevp, ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluCompStdEig(int nevp, ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - arcomplex<ARFLOAT> sigma, const std::string& whichp = "LM", - int ncvp = 0, ARFLOAT tolp = 0.0, int maxitp = 0, - arcomplex<ARFLOAT>* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluCompStdEig(const ARluCompStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluCompStdEig() { } - // Destructor. - - - // b) Operators. - - ARluCompStdEig& operator=(const ARluCompStdEig& other); - // Assignment operator. - -}; // class ARluCompStdEig. - - -// ------------------------------------------------------------------------ // -// ARluCompStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>:: -ChangeShift(arcomplex<ARFLOAT> sigmaRp) -{ - - this->objOP->FactorAsI(sigmaRp); - ARrcStdEig<ARFLOAT, arcomplex<ARFLOAT> >::ChangeShift(sigmaRp); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetRegularMode(this->objOP, - &ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluCompStdEig<ARFLOAT>:: -SetShiftInvertMode(arcomplex<ARFLOAT> sigmap) -{ - - ARStdEig<ARFLOAT, arcomplex<ARFLOAT>, - ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, - &ARumNonSymMatrix<arcomplex<ARFLOAT>,ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluCompStdEig<ARFLOAT>:: -ARluCompStdEig(int nevp, ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, arcomplex<ARFLOAT>* residp, bool ishiftp) - -{ - - this->NoShift(); - DefineParameters(A.ncols(), nevp, &A, - &ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluCompStdEig<ARFLOAT>:: -ARluCompStdEig(int nevp, ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>& A, - arcomplex<ARFLOAT> sigmap, const std::string& whichp, int ncvp, - ARFLOAT tolp, int maxitp, arcomplex<ARFLOAT>* residp, - bool ishiftp) - -{ - - DefineParameters(A.ncols(), nevp, &A, - &ARumNonSymMatrix<arcomplex<ARFLOAT>, ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluCompStdEig<ARFLOAT>& ARluCompStdEig<ARFLOAT>:: -operator=(const ARluCompStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUSCOMP_H diff --git a/src/external/arpack++/include/arusmat.h b/src/external/arpack++/include/arusmat.h deleted file mode 100644 index f5dae63a..00000000 --- a/src/external/arpack++/include/arusmat.h +++ /dev/null @@ -1,743 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUSMat.h. - Arpack++ class ARumSymMatrix definition. - - Modified to work with Umfpack v5.?? - Martin Reuter - Date 02/28/2013 - - Arpack++ Author: - Francisco Gomes - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - - -#include "aruspen.h" - -#ifndef ARUSMAT_H -#define ARUSMAT_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "armat.h" -#include "arhbmat.h" -#include "arerror.h" -//#include "blas1c.h" -#include "umfpackc.h" - -template<class ARTYPE> class ARumSymPencil; - -template<class ARTYPE> -class ARumSymMatrix: public ARMatrix<ARTYPE> { - - friend class ARumSymPencil<ARTYPE>; - - protected: - - bool factored; - char uplo; - int nnz; - /* int fillin; - int lvalue; - int lindex; - int keep[20]; - int icntl[20]; - int info[40]; - ARTYPE cntl[10]; - ARTYPE rinfo[20]; - int* index; - ARTYPE* value;*/ - int* irow; - int* pcol; - int status; - double threshold; - ARTYPE* a; - ARhbMatrix<int, ARTYPE> mat; - void* Numeric; - int* Ap; - int* Ai; - ARTYPE* Ax; - - bool DataOK(); - - virtual void Copy(const ARumSymMatrix& other); - - void ClearMem(); - - void ExpandA(ARTYPE sigma = (ARTYPE)0); - -// void CreateStructure(); - - void ThrowError(); - - public: - - int nzeros() { return nnz; } - -// int FillFact() { return fillin; } - - bool IsFactored() { return factored; } - - void FactorA(); - - void FactorAsI(ARTYPE sigma); - - void MultMv(ARTYPE* v, ARTYPE* w); - - void MultInvv(ARTYPE* v, ARTYPE* w); - - void DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, char uplop = 'L', double thresholdp = 0.1, - int fillinp = 9, bool reducible = true, bool check = true); - - ARumSymMatrix(): ARMatrix<ARTYPE>() - { - factored = false; - Numeric = NULL; - Ap = NULL; - Ai = NULL; - Ax = NULL; - } - // Short constructor that does nothing. - - ARumSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, char uplop = 'L', double thresholdp = 0.1, - int fillinp = 9, bool reducible = true, bool check = true); - // Long constructor. - - ARumSymMatrix(const std::string& name, double thresholdp = 0.1, int fillinp = 9, - bool reducible = true, bool check = true); - // Long constructor (Harwell-Boeing file). - - ARumSymMatrix(const ARumSymMatrix& other) { Copy(other); } - // Copy constructor. - - virtual ~ARumSymMatrix() { ClearMem(); } - // Destructor. - - ARumSymMatrix& operator=(const ARumSymMatrix& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARumSymMatrix member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -bool ARumSymMatrix<ARTYPE>::DataOK() -{ - - int i, j, k; - - // Checking if pcol is in ascending order. - - i = 0; - while ((i!=this->n)&&(pcol[i]<=pcol[i+1])) i++; - if (i!=this->n) return false; - - // Checking if irow components are in order and within bounds. - - for (i=0; i!=this->n; i++) { - j = pcol[i]; - k = pcol[i+1]-1; - if (j<=k) { - if (uplo == 'U') { - if ((irow[j]<0)||(irow[k]>i)) return false; - } - else { // uplo == 'L'. - if ((irow[j]<i)||(irow[k]>=this->n)) return false; - } - while ((j!=k)&&(irow[j]<irow[j+1])) j++; - if (j!=k) return false; - } - } - - return true; - -} // DataOK. - - -template<class ARTYPE> -inline void ARumSymMatrix<ARTYPE>::ClearMem() -{ - - if (factored) - { - if (Numeric) umfpack_di_free_numeric (&Numeric); - //if (value) delete[] value; - //if (index) delete[] index; - //value = NULL; - //index = NULL; - if (Ai) delete [] Ai; - Ai = NULL; - if (Ap) delete [] Ap; - Ap = NULL; - if (Ax) delete [] Ax; - Ax = NULL; - } - -} // ClearMem. - - - -template<class ARTYPE> -void ARumSymMatrix<ARTYPE>::Copy(const ARumSymMatrix<ARTYPE>& other) -{ - - // Copying very fundamental variables. - ClearMem(); - - // Copying very fundamental variables and user-defined parameters. - - this->m = other.m; - this->n = other.n; - this->defined = other.defined; - factored = other.factored; - //fillin = other.fillin; - nnz = other.nnz; - //lvalue = other.lvalue; - //lindex = other.lindex; - irow = other.irow; - pcol = other.pcol; - a = other.a; - threshold = other.threshold; - uplo = other.uplo; - - // Returning from here if "other" was not initialized. - - if (!this->defined) return; - - // Returning from here if "other" was not factored. - - if (!factored) return; - - factored = false; - -} // Copy. - -template<class ARTYPE> -void ARumSymMatrix<ARTYPE>::ExpandA(ARTYPE sigma) -{ -std::cout <<"ARumSymMatrix::ExpandA(" << sigma << ") ..." << std::flush; - - ClearMem(); - - // Checking if sigma is zero. - bool subtract = (sigma != (ARTYPE)0); - - int mynnz = 2*nnz; - if (subtract) mynnz = 2*nnz + this->n; // some space for the diag entries just in case - - // create triples (i,j,value) - int * tripi = new int[mynnz]; - int * tripj = new int[mynnz]; - ARTYPE* tripx = new ARTYPE[mynnz]; - int count = 0; - int i,j; -// if (uplo == 'U') - { - for (i=0; i != this->n; i++) - { - bool founddiag = false; - for (j=pcol[i]; j<(pcol[i+1]); j++) - { - - if (i == irow[j]) // on diag - { - tripi[count] = i; - tripj[count] = irow[j]; - if (subtract) - { - tripx[count] = a[j]-sigma; - founddiag = true; - } - else tripx[count] = a[j]; - count++; - } - else - { - - tripi[count] = i; - tripj[count] = irow[j]; - tripx[count] = a[j]; - count++; - tripj[count] = i; - tripi[count] = irow[j]; - tripx[count] = a[j]; - count++; - } - } - if (subtract && ! founddiag) - { - tripi[count] = i; - tripj[count] = i; - tripx[count] = -sigma; - count++; - } - } - } - - // convert triples to Ax Ap Ai - Ap = new int[this->n+1]; - Ai = new int[count]; - Ax = new ARTYPE[count]; - status = umfpack_di_triplet_to_col (this->n, this->n, count, tripi, tripj, tripx, Ap, Ai, Ax, (int *)NULL) ; - if (status != UMFPACK_OK) - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymMatrix::ExpandA"); - if (Ap[this->n] != count) - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymMatrix::ExpandA"); - - - // cleanup - delete [] tripi; - delete [] tripj; - delete [] tripx; - - //std::cout << std::endl << std::endl; - //double Control [UMFPACK_CONTROL]; - //Control [UMFPACK_PRL] = 3; - //status = umfpack_di_report_matrix(this->n, this->n,Ap, Ai, Ax,0,Control); - //std::cout << " status: " << status << std::endl; - //std::cout << std::endl << std::endl; - - std::cout <<" done!" << std::endl; - -} - -/*template<class ARTYPE> -void ARumSymMatrix<ARTYPE>::ExpandA(ARTYPE sigma) -{ - - bool subtract; - int i, j, k, ki; - - // Checking if sigma is zero. - - subtract = (sigma != (ARTYPE)0); - - // Filling index with zeros. - - for (i=0; i<=this->n; i++) index[i] = 0; - - // Counting the elements in each column of A. - - if (uplo == 'U') { - - for (i=0; i!=this->n; i++) { - k = pcol[i+1]; - if ((k!=pcol[i])&&(irow[k-1]==i)) { - k--; - } - else { - if (subtract) index[i]++; - } - for (j=pcol[i]; j<k; j++) index[irow[j]]++; - } - - } - else { // uplo == 'L' - - for (i=0; i!=this->n; i++) { - k = pcol[i]; - if ((k!=pcol[i+1])&&(irow[k]==i)) { - k++; - } - else { - if (subtract) index[i]++; - } - for (j=k; j<pcol[i+1]; j++) index[irow[j]]++; - } - - } - - // Summing up index elements. - - for (i=0; i<this->n; i++) index[i+1]+=index[i]; - - // Adding pcol to index. - - for (i=this->n; i>0; i--) index[i] = index[i-1]+pcol[i]; - index[0] = pcol[0]; - - // Expanding A. - - ki = this->n+1; - - if (uplo == 'U') { - - for (i=0; i<this->n; i++) { - for (j=pcol[i]; j<(pcol[i+1]-1); j++) { - index[ki+index[i]] = irow[j]+1; - index[ki+index[irow[j]]] = i+1; - value[index[i]++] = a[j]; - value[index[irow[j]]++] = a[j]; - } - if ((pcol[i]!=pcol[i+1])&&(irow[j]==i)) { - index[ki+index[i]] = i+1; - if (subtract) { - value[index[i]++] = a[j]-sigma; - } - else { - value[index[i]++] = a[j]; - } - } - else { - if (subtract) { - index[ki+index[i]] = i+1; - value[index[i]++] = -sigma; - } - } - } - - } - else { // uplo == 'L' - - for (i=0; i<this->n; i++) { - k=pcol[i]; - if ((k!=pcol[i+1])&&(irow[k]==i)) { - index[ki+index[i]] = i+1; - if (subtract) { - value[index[i]++] = a[k]-sigma; - } - else { - value[index[i]++] = a[k]; - } - k++; - } - else { - if (subtract) { - index[ki+index[i]] = i+1; - value[index[i]++] = -sigma; - } - } - for (j=k; j<pcol[i+1]; j++) { - index[ki+index[i]] = irow[j]+1; - index[ki+index[irow[j]]] = i+1; - value[index[i]++] = a[j]; - value[index[irow[j]]++] = a[j]; - } - } - - } - - // Adjusting index. - - for (i=this->n; i>0; i--) { - index[i] = index[i-1]+1; - } - index[0] = 1; - -} // ExpandA.*/ - - -/*template<class ARTYPE> -inline void ARumSymMatrix<ARTYPE>::CreateStructure() -{ - - int dimfact = (((fillin+1)*nnz*2)<(this->n*this->n)) ? (fillin+1)*nnz*2 : this->n*this->n; - - ClearMem(); - - lindex = 30*this->n+dimfact; // ????? - lvalue = dimfact; - - value = new ARTYPE[lvalue]; - index = new int[lindex]; - -} // CreateStructure. -*/ - -template<class ARTYPE> -inline void ARumSymMatrix<ARTYPE>::ThrowError() -{ - - if (status== -1) { // Memory is not suficient. - throw ArpackError(ArpackError::INSUFICIENT_MEMORY, - "ARumSymMatrix::FactorA"); - } - else if (status == 1) { // Matrix is singular. - throw ArpackError(ArpackError::MATRIX_IS_SINGULAR, - "ARumSymMatrix::FactorA"); - } - else if (status != 0) { // Illegal argument. - throw ArpackError(ArpackError::PARAMETER_ERROR, - "ARumSymMatrix::FactorA"); - } - -} // ThrowError. - - -template<class ARTYPE> -void ARumSymMatrix<ARTYPE>::FactorA() -{ - -std::cout <<"ARumSymMatrix::FactorA " << std::endl; - - // Quitting the function if A was not defined. - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARumSymMatrix::FactorA"); - } - - ExpandA(); // create Ap Ai Ax - - void *Symbolic ; - status = umfpack_di_symbolic (this->n, this->n, Ap, Ai, Ax, &Symbolic, NULL, NULL) ; - ThrowError(); - status = umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, NULL, NULL) ; - ThrowError(); - umfpack_di_free_symbolic (&Symbolic) ; - -/* - - // Reserving memory for some vectors used in matrix decomposition. - - CreateStructure(); - - // Copying A to (value, index); - - ExpandA(); - - // Decomposing A. - - um2fa(this->n, index[this->n], 0, false, lvalue, lindex, value, - index, keep, cntl, icntl, info, rinfo); -*/ - - factored = true; - -} // FactorA. - - -template<class ARTYPE> -void ARumSymMatrix<ARTYPE>::FactorAsI(ARTYPE sigma) -{ -std::cout <<"ARumSymMatrix::FactorAsI " << sigma << std::endl; - - // Quitting the function if A was not defined. - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARumSymMatrix::FactorAsI"); - } - - // Reserving memory for some vectors used in matrix decomposition. - //CreateStructure(); - - // Subtracting sigma*I from A. - ExpandA(sigma); - - // Decomposing AsI. - double Info [UMFPACK_INFO], Control [UMFPACK_CONTROL]; - umfpack_di_defaults (Control) ; - //std::cout << " Ap[n] = " << Ap[this->n] << std::flush; - - void *Symbolic ; - status = umfpack_di_symbolic (this->n, this->n, Ap, Ai, Ax, &Symbolic, Control, Info) ; - //std::cout << " symbolic status: " << status << std::endl; - ThrowError(); - status = umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, NULL, NULL) ; - //std::cout << " numeric status: " << status << std::endl; - ThrowError(); - umfpack_di_free_symbolic (&Symbolic) ; - -// // Decomposing AsI. -// um2fa(this->n, index[this->n], 0, false, lvalue, lindex, value, -// index, keep, cntl, icntl, info, rinfo); - - - factored = true; - -} // FactorAsI. - - -template<class ARTYPE> -void ARumSymMatrix<ARTYPE>::MultMv(ARTYPE* v, ARTYPE* w) -{ -//std::cout <<"ARumSymMatrix::MultMv ..." << std::flush; - - int i,j,k; - ARTYPE t; - - // Quitting the function if A was not defined. - - if (!this->IsDefined()) { - throw ArpackError(ArpackError::DATA_UNDEFINED, "ARumSymMatrix::MultMv"); - } - - // Determining w = M.v. - - for (i=0; i!=this->m; i++) w[i]=(ARTYPE)0; - - if (uplo == 'U') { - - for (i=0; i!=this->n; i++) { - t = v[i]; - k = pcol[i+1]; - if ((k!=pcol[i])&&(irow[k-1]==i)) { - w[i] += t*a[k-1]; - k--; - } - for (j=pcol[i]; j<k; j++) { - w[irow[j]] += t*a[j]; - w[i] += v[irow[j]]*a[j]; - } - } - - } - else { - - for (i=0; i!=this->n; i++) { - t = v[i]; - k = pcol[i]; - if ((k!=pcol[i+1])&&(irow[k]==i)) { - w[i] += t*a[k]; - k++; - } - for (j=k; j<pcol[i+1]; j++) { - w[irow[j]] += t*a[j]; - w[i] += v[irow[j]]*a[j]; - } - } - - } - -} // MultMv. - - -template<class ARTYPE> -void ARumSymMatrix<ARTYPE>::MultInvv(ARTYPE* v, ARTYPE* w) -{ -//std::cout <<"ARumSymMatrix::MultInvv ..." << std::flush; - - // Quitting the function if A (or AsI) was not factored. - - if (!IsFactored()) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARumSymMatrix::MultInvv"); - } - - // Solving A.w = v (or AsI.w = v). - -// ARTYPE* space = new ARTYPE[2*this->n]; -// um2so(this->n, 0, false, lvalue, lindex, value, index, -// keep, v, w, space, cntl, icntl, info, rinfo); -// delete[] space; - - status = umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, w, v, Numeric, NULL, NULL) ; - if (status != UMFPACK_OK) - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymMatrix::MultInvv"); - -} // MultInvv. - - -template<class ARTYPE> -inline void ARumSymMatrix<ARTYPE>:: -DefineMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, char uplop, double thresholdp, - int fillinp, bool reducible, bool check) -{ - - this->m = np; - this->n = np; - nnz = nnzp; - a = ap; - irow = irowp; - pcol = pcolp; - pcol[this->n] = nnz; - uplo = uplop; -// fillin = (fillinp>2) ? fillinp : 2; - threshold = thresholdp; -// value = NULL; -// index = NULL; - -// // Preparing umfpack. -// -// um21i(keep, cntl, icntl, threshold, true, reducible); - - // Checking data. - if ((check)&&(!DataOK())) { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARumSymMatrix::DefineMatrix"); - } - - this->defined = true; - -} // DefineMatrix. - - -template<class ARTYPE> -inline ARumSymMatrix<ARTYPE>:: -ARumSymMatrix(int np, int nnzp, ARTYPE* ap, int* irowp, - int* pcolp, char uplop, double thresholdp, - int fillinp, bool reducible, bool check) : ARMatrix<ARTYPE>(np) -{ - Numeric = NULL; - Ap = NULL; - Ai = NULL; - Ax = NULL; - factored = false; - DefineMatrix(np, nnzp, ap, irowp, pcolp, uplop, - thresholdp, fillinp, reducible, check); - -} // Long constructor. - - -template<class ARTYPE> -ARumSymMatrix<ARTYPE>:: -ARumSymMatrix(const std::string& file, double thresholdp, int fillinp, - bool reducible, bool check) -{ - Numeric = NULL; - Ap = NULL; - Ai = NULL; - Ax = NULL; - - factored = false; - - try { - mat.Define(file); - } - catch (ArpackError) { // Returning from here if an error has occurred. - throw ArpackError(ArpackError::CANNOT_READ_FILE, "ARumSymMatrix"); - } - - if ((mat.NCols() == mat.NRows()) && (mat.IsSymmetric())) { - - DefineMatrix(mat.NCols(), mat.NonZeros(), (ARTYPE*)mat.Entries(), - mat.RowInd(), mat.ColPtr(), 'L', thresholdp, - fillinp, reducible, check); - } - else { - throw ArpackError(ArpackError::INCONSISTENT_DATA, - "ARumSymMatrix::ARluSymMatrix"); - } - -} // Long constructor (Harwell-Boeing file). - - -template<class ARTYPE> -ARumSymMatrix<ARTYPE>& ARumSymMatrix<ARTYPE>:: -operator=(const ARumSymMatrix<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUSMAT_H diff --git a/src/external/arpack++/include/arusnsym.h b/src/external/arpack++/include/arusnsym.h deleted file mode 100644 index 644ee27d..00000000 --- a/src/external/arpack++/include/arusnsym.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUSNSym.h. - Arpack++ class ARluNonSymStdEig definition - (umfpack version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARUSNSYM_H -#define ARUSNSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arsnsym.h" -#include "arunsmat.h" - - -template<class ARFLOAT> -class ARluNonSymStdEig: - public virtual ARNonSymStdEig<ARFLOAT, ARumNonSymMatrix<ARFLOAT, ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // a.2) Constructors and destructor. - - ARluNonSymStdEig() { } - // Short constructor. - - ARluNonSymStdEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluNonSymStdEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluNonSymStdEig(const ARluNonSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluNonSymStdEig() { } - // Destructor. - - // b) Operators. - - ARluNonSymStdEig& operator=(const ARluNonSymStdEig& other); - // Assignment operator. - -}; // class ARluNonSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluNonSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI(this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARumNonSymMatrix<ARFLOAT, ARFLOAT> >:: - SetRegularMode(this->objOP, &ARumNonSymMatrix<ARFLOAT, ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluNonSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARumNonSymMatrix<ARFLOAT, ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, - &ARumNonSymMatrix<ARFLOAT, ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluNonSymStdEig<ARFLOAT>:: -ARluNonSymStdEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->NoShift(); - DefineParameters(A.ncols(), nevp, &A, - &ARumNonSymMatrix<ARFLOAT, ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluNonSymStdEig<ARFLOAT>:: -ARluNonSymStdEig(int nevp, ARumNonSymMatrix<ARFLOAT, ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - DefineParameters(A.ncols(), nevp, &A, - &ARumNonSymMatrix<ARFLOAT, ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluNonSymStdEig<ARFLOAT>& ARluNonSymStdEig<ARFLOAT>:: -operator=(const ARluNonSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUSNSYM_H diff --git a/src/external/arpack++/include/aruspen.h b/src/external/arpack++/include/aruspen.h deleted file mode 100644 index bd2a5994..00000000 --- a/src/external/arpack++/include/aruspen.h +++ /dev/null @@ -1,543 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUSPen.h. - Arpack++ class ARumSymPencil definition. - - Modified to work with Umfpack v5.?? - Martin Reuter - Date 02/28/2013 - - Arpack++ Author: - Francisco Gomes - - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARUSPEN_H -#define ARUSPEN_H - -//#include "arch.h" -//#include "arerror.h" -//#include "lapackc.h" -#include "arusmat.h" -#include "blas1c.h" - - -template<class ARTYPE> -class ARumSymPencil -{ - - protected: - - ARumSymMatrix<ARTYPE>* A; - ARumSymMatrix<ARTYPE>* B; - //ARumSymMatrix<ARTYPE> AsB; - void* Numeric; - int* Ap; - int* Ai; - ARTYPE* Ax; - - virtual void Copy(const ARumSymPencil& other); - -// void SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], -// int yind[], int ny, ARTYPE z[], int zind[], int& nz); - - void ExpandAsB(ARTYPE sigma); - -// void SubtractAsB(ARTYPE sigma); - void ClearMem(); - - public: - - bool IsFactored() { return (Numeric != NULL); } - - void FactorAsB(ARTYPE sigma); - - void MultAv(ARTYPE* v, ARTYPE* w) { A->MultMv(v,w); } - - void MultBv(ARTYPE* v, ARTYPE* w) { B->MultMv(v,w); } - - void MultInvBAv(ARTYPE* v, ARTYPE* w); - - //void MultInvAsBv(ARTYPE* v, ARTYPE* w) { AsB.MultInvv(v,w); } - void MultInvAsBv(ARTYPE* v, ARTYPE* w); - - void DefineMatrices(ARumSymMatrix<ARTYPE>& Ap, ARumSymMatrix<ARTYPE>& Bp); - - //ARumSymPencil() { AsB.factored = false; } - ARumSymPencil() { Numeric = NULL; Ap = NULL; Ai = NULL; Ax = NULL; } - // Short constructor that does nothing. - - ARumSymPencil(ARumSymMatrix<ARTYPE>& Ap, ARumSymMatrix<ARTYPE>& Bp); - // Long constructor. - - ARumSymPencil(const ARumSymPencil& other) { Copy(other); } - // Copy constructor. - - virtual ~ARumSymPencil() { } - // Destructor. - - ARumSymPencil& operator=(const ARumSymPencil& other); - // Assignment operator. - -}; - -// ------------------------------------------------------------------------ // -// ARumSymPencil member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARTYPE> -inline void ARumSymPencil<ARTYPE>::ClearMem() -{ - - if (Numeric) umfpack_di_free_numeric (&Numeric); - if (Ai) delete [] Ai; - Ai = NULL; - if (Ap) delete [] Ap; - Ap = NULL; - if (Ax) delete [] Ax; - Ax = NULL; - -} // ClearMem. - - - -template<class ARTYPE> -inline void ARumSymPencil<ARTYPE>::Copy(const ARumSymPencil<ARTYPE>& other) -{ - ClearMem(); - A = other.A; - B = other.B; -// AsB = other.AsB; - -} // Copy. - - -/*template<class ARTYPE> -void ARumSymPencil<ARTYPE>:: -SparseSaxpy(ARTYPE a, ARTYPE x[], int xind[], int nx, ARTYPE y[], - int yind[], int ny, ARTYPE z[], int zind[], int& nz) -// A strongly sequential (and inefficient) sparse saxpy algorithm. -{ - - int ix, iy; - - nz = 0; - if ((nx == 0) || (a == (ARTYPE)0)) { - copy(ny,y,1,z,1); - for (iy=0; iy!=ny; iy++) zind[iy] = yind[iy]; - nz = ny; - return; - } - if (ny == 0) { - copy(nx,x,1,z,1); - scal(nx,a,z,1); - for (ix=0; ix!=nx; ix++) zind[ix] = xind[ix]; - nz = nx; - return; - } - ix = 0; - iy = 0; - while (true) { - if (xind[ix] == yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]+y[iy++]; - if ((ix == nx)||(iy == ny)) break; - } - else if (xind[ix] < yind[iy]) { - zind[nz] = xind[ix]; - z[nz++] = a*x[ix++]; - if (ix == nx) break; - } - else { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - if (iy == ny) break; - } - } - while (iy < ny) { - zind[nz] = yind[iy]; - z[nz++] = y[iy++]; - } - while (ix < nx) { - zind[nz] = xind[ix]; - z[nz++] = x[ix++]; - } - -} // SparseSaxpy. - - -template<class ARTYPE> -void ARumSymPencil<ARTYPE>::ExpandAsB() -{ - - int i, j, k, n; - int *pcol, *irow, *index, *pos; - ARTYPE *value; - - // Initializing variables. - - n = AsB.n; - index = AsB.index; - value = AsB.value; - irow = &index[n+1]; - pcol = new int[AsB.n+1]; - pos = new int[AsB.n+1]; - for (i=0; i<=n; i++) pcol[i] = index[i]; - for (i=0; i<=n; i++) pos[i] = 0; - - // Counting the elements in each column of AsB. - - if (AsB.uplo == 'U') { - - for (i=0; i!=n; i++) { - k = pcol[i+1]; - if ((k!=pcol[i])&&(irow[k-1]==i)) k--; - for (j=pcol[i]; j<k; j++) pos[irow[j]]++; - } - - } - else { // uplo == 'L' - - for (i=0; i!=n; i++) { - k = pcol[i]; - if ((k!=pcol[i+1])&&(irow[k]==i)) k++; - for (j=k; j<pcol[i+1]; j++) pos[irow[j]]++; - } - - } - - // Summing up index elements. - - for (i=0; i<n; i++) pos[i+1] += pos[i]; - for (i=n; i>0; i--) index[i] += pos[i-1]; - - // Expanding A. - - if (AsB.uplo == 'U') { - - for (i=n-1; i>=0; i--) { - pos[i] = index[i]+pcol[i+1]-pcol[i]; - k = pos[i]-1; - for (j=pcol[i+1]-1; j>=pcol[i]; j--) { - value[k] = value[j]; - irow[k--] = irow[j]; - } - } - for (i=1; i<n; i++) { - k = index[i]+pcol[i+1]-pcol[i]; - if ((k>index[i])&&(irow[k-1]==i)) k--; - for (j=index[i]; j<k; j++) { - value[pos[irow[j]]] = value[j]; - irow[pos[irow[j]]++] = i; - } - } - - } - else { // uplo == 'L' - - for (i=n-1; i>=0; i--) { - k = index[i+1]-1; - for (j=pcol[i+1]-1; j>=pcol[i]; j--) { - value[k] = value[j]; - irow[k--] = irow[j]; - } - pos[i] = index[i]; - } - for (i=0; i<(n-1); i++) { - k = index[i+1]-pcol[i+1]+pcol[i]; - if ((k<index[i+1])&&(irow[k]==i)) k++; - for (j=k; j<index[i+1]; j++) { - value[pos[irow[j]]] = value[j]; - irow[pos[irow[j]]++] = i; - } - } - - } - - AsB.nnz = index[n]; - - // Deleting temporary vectors. - - delete[] pcol; - delete[] pos; - -} // ExpandAsB. - - -template<class ARTYPE> -void ARumSymPencil<ARTYPE>::SubtractAsB(ARTYPE sigma) -{ - - int i, acol, bcol, asbcol, scol; - - // Quitting function if A->uplo is not equal to B->uplo. - - if ((A->uplo != B->uplo)&&(sigma != (ARTYPE)0)) { - throw ArpackError(ArpackError::DIFFERENT_TRIANGLES, - "ARumSymPencil::SubtractAsB"); - } - AsB.uplo = A->uplo; - - // Subtracting sigma*B from A. - - AsB.index[0] = 0; - asbcol = 0; - - for (i=0; i!=AsB.n; i++) { - bcol = B->pcol[i]; - acol = A->pcol[i]; - SparseSaxpy(-sigma, &B->a[bcol], &B->irow[bcol], B->pcol[i+1]-bcol, - &A->a[acol], &A->irow[acol], A->pcol[i+1]-acol, - &AsB.value[asbcol], &AsB.index[asbcol+AsB.n+1], scol); - asbcol += scol; - AsB.index[i+1] = asbcol; - } - - // Expanding AsB. - - ExpandAsB(); - - // Adding one to all elements of vector index - // because the decomposition function was written in FORTRAN. - - for (i=0; i<=AsB.n+AsB.nnz; i++) AsB.index[i]++; - -} // SubtractAsB. */ - - -template<class ARTYPE> -void ARumSymPencil<ARTYPE>::ExpandAsB(ARTYPE sigma) -{ -std::cout <<"ARumSymPencil::ExpandAsB(" << sigma << ") ..." << std::flush; - - ClearMem(); - - int mynnz = 2*A->nnz+2*B->nnz; - if (sigma == 0.0) - mynnz = 2*A->nnz; - - // create triples (i,j,value) - int * tripi = new int[mynnz]; - int * tripj = new int[mynnz]; - ARTYPE* tripx = new ARTYPE[mynnz]; - if (tripi == NULL || tripj == NULL || tripx ==NULL) - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymPencil::ExpandAsB out of memory (1)"); - - int count = 0; - int i,j; - for (i=0; i < A->n; i++) - { - // create triplets from A - for (j=A->pcol[i]; j<(A->pcol[i+1]); j++) - { - tripi[count] = i; - tripj[count] = A->irow[j]; - tripx[count] = A->a[j]; - count++; - if (i != A->irow[j]) // not on diag - { - tripj[count] = i; - tripi[count] = A->irow[j]; - tripx[count] = A->a[j]; - count++; - } - } - - if (sigma != 0.0) - { - // create triplets from -sigma B - for (j=B->pcol[i]; j<(B->pcol[i+1]); j++) - { - tripi[count] = i; - tripj[count] = B->irow[j]; - tripx[count] = -sigma * B->a[j]; - count++; - if (i != B->irow[j]) // not on diag - { - tripj[count] = i; - tripi[count] = B->irow[j]; - tripx[count] = tripx[count-1]; - count++; - } - } - } - - } - - //Write_Triplet_Matrix("A-aruspen.asc",tripi,tripj,tripx,count); - - std::cout<< " ( N = " << A->n << " NNZ = " << count << " )" << std::flush; - //std::cout<< " size double " << sizeof(double) << " size ARTYPE " << sizeof(ARTYPE) << std::endl; - // convert triples (A-sigma B) to Ax Ap Ai - Ap = new int[A->n + 1]; - Ai = new int[count]; - Ax = new ARTYPE[count]; - if (!Ap || !Ai || !Ax ) - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymPencil::ExpandAsB out of memory (2)"); - - int status = umfpack_di_triplet_to_col (A->n, A->n, count, tripi, tripj, tripx, Ap, Ai, Ax, (int *)NULL) ; - if (status != UMFPACK_OK) - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymPencil::ExpandAsB triplet to col"); - - // cleanup - delete [] tripi; - delete [] tripj; - delete [] tripx; - - //std::cout << std::endl << std::endl; - //double Control [UMFPACK_CONTROL]; - //Control [UMFPACK_PRL] = 3; - //status = umfpack_di_report_matrix(A->n, A->n,Ap, Ai, Ax,0,Control); - //std::cout << " status: " << status << std::endl; - //std::cout << std::endl << std::endl; - - std::cout <<" done!" << std::endl; -} - -template<class ARTYPE> -void ARumSymPencil<ARTYPE>::FactorAsB(ARTYPE sigma) -{ - - // Quitting the function if A and B were not defined. - - if (!(A->IsDefined()&&B->IsDefined())) { - throw ArpackError(ArpackError::DATA_UNDEFINED, - "ARumSymPencil::FactorAsB"); - } - - - // Subtracting sigma*B from A and storing the result - ExpandAsB(sigma); - - // Decomposing AsB. - double Info [UMFPACK_INFO], Control [UMFPACK_CONTROL]; - umfpack_di_defaults (Control) ; - //std::cout <<" loaded defaults" << std::endl; - void *Symbolic ; - int status = umfpack_di_symbolic (A->n, A->n, Ap, Ai, Ax, &Symbolic, Control, Info) ; - std::cout << " symbolic status: " << status << std::endl; - if (status != UMFPACK_OK) - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymPencil::FactorAsB symbolic"); - status = umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, Control, Info) ; - std::cout << " numeric status: " << status << std::endl; - if (status == 1) - { - std::cout << " WARNING: MATRIX IS SINGULAR " << std::endl; - //throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymPencil::FactorAsB numeric (matrix singular)"); - } - if (status < UMFPACK_OK) - { - std::cout << " ERROR CODE: " << status << std::endl; - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymPencil::FactorAsB numeric"); - } - umfpack_di_free_symbolic (&Symbolic) ; - -//exit(0); - - // Decomposing AsB. - - //um2fa(AsB.n, AsB.index[AsB.n], 0, false, AsB.lvalue, AsB.lindex, AsB.value, - // AsB.index, AsB.keep, AsB.cntl, AsB.icntl, AsB.info, AsB.rinfo); - - // Handling errors. - - // AsB.ThrowError(); - - // AsB.factored = true; - -} // FactorAsB (ARTYPE shift). - - -template<class ARTYPE> -void ARumSymPencil<ARTYPE>::MultInvBAv(ARTYPE* v, ARTYPE* w) -{ - - if (!B->IsFactored()) B->FactorA(); - - A->MultMv(v, w); - copy(A->ncols(), w, 1, v, 1); - B->MultInvv(w, w); - -} // MultInvBAv. - -template<class ARTYPE> -void ARumSymPencil<ARTYPE>::MultInvAsBv(ARTYPE* v, ARTYPE* w) -{ - if (!Numeric) { - throw ArpackError(ArpackError::NOT_FACTORED_MATRIX, - "ARchSymPencil::MultInvAsBv"); - } - - // Solving A.w = v (or AsI.w = v). - int status = umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, w, v, Numeric, NULL, NULL) ; - if (status == 1) - { - std::cout << " WARNING: MATRIX IS SINGULAR " << std::endl; - //throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymPencil::FactorAsB numeric (matrix singular)"); - } - if (status < UMFPACK_OK) - { - std::cout << " ERROR CODE: " << status << std::endl; - throw ArpackError(ArpackError::PARAMETER_ERROR, "ARumSymPencil::MultInvAsBv"); - - } - -} // MultInvAsBv - -template<class ARTYPE> -inline void ARumSymPencil<ARTYPE>:: -DefineMatrices(ARumSymMatrix<ARTYPE>& Ap, ARumSymMatrix<ARTYPE>& Bp) -{ - - A = &Ap; - B = &Bp; - - if (A->n != B->n) { - throw ArpackError(ArpackError::INCOMPATIBLE_SIZES, - "ARumSymMatrix::DefineMatrices"); - } - -} // DefineMatrices. - - -template<class ARTYPE> -inline ARumSymPencil<ARTYPE>:: -ARumSymPencil(ARumSymMatrix<ARTYPE>& Ap, ARumSymMatrix<ARTYPE>& Bp) -{ - Numeric = NULL; - Ap = NULL; - Ai = NULL; - Ax = NULL; - - //AsB.factored = false; - DefineMatrices(Ap, Bp); - - -} // Long constructor. - - -template<class ARTYPE> -ARumSymPencil<ARTYPE>& ARumSymPencil<ARTYPE>:: -operator=(const ARumSymPencil<ARTYPE>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUSPEN_H diff --git a/src/external/arpack++/include/arussym.h b/src/external/arpack++/include/arussym.h deleted file mode 100644 index f1a53cf8..00000000 --- a/src/external/arpack++/include/arussym.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ARUSSym.h. - Arpack++ class ARluSymStdEig definition - (UMFPACK version). - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef ARUSSYM_H -#define ARUSSYM_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arssym.h" -#include "arusmat.h" - - -template<class ARFLOAT> -class ARluSymStdEig: - public virtual ARSymStdEig<ARFLOAT, ARumSymMatrix<ARFLOAT> > { - - public: - - // a) Public functions: - - // a.1) Functions that allow changes in problem parameters. - - virtual void ChangeShift(ARFLOAT sigmaRp); - - virtual void SetRegularMode(); - - virtual void SetShiftInvertMode(ARFLOAT sigmap); - - // a.2) Constructors and destructor. - - ARluSymStdEig() { } - // Short constructor. - - ARluSymStdEig(int nevp, ARumSymMatrix<ARFLOAT>& A, - const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (regular mode). - - ARluSymStdEig(int nevp, ARumSymMatrix<ARFLOAT>& A, - ARFLOAT sigma, const std::string& whichp = "LM", int ncvp = 0, - ARFLOAT tolp = 0.0, int maxitp = 0, - ARFLOAT* residp = NULL, bool ishiftp = true); - // Long constructor (shift and invert mode). - - ARluSymStdEig(const ARluSymStdEig& other) { Copy(other); } - // Copy constructor. - - virtual ~ARluSymStdEig() { } - // Destructor. - - // b) Operators. - - ARluSymStdEig& operator=(const ARluSymStdEig& other); - // Assignment operator. - -}; // class ARluSymStdEig. - - -// ------------------------------------------------------------------------ // -// ARluSymStdEig member functions definition. // -// ------------------------------------------------------------------------ // - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::ChangeShift(ARFLOAT sigmaRp) -{ - - this->sigmaR = sigmaRp; - this->sigmaI = 0.0; - this->mode = 3; - this->iparam[7] = this->mode; - - this->objOP->FactorAsI(this->sigmaR); - this->Restart(); - -} // ChangeShift. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetRegularMode() -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARumSymMatrix<ARFLOAT> >:: - SetRegularMode(this->objOP, &ARumSymMatrix<ARFLOAT>::MultMv); - -} // SetRegularMode. - - -template<class ARFLOAT> -inline void ARluSymStdEig<ARFLOAT>::SetShiftInvertMode(ARFLOAT sigmap) -{ - - ARStdEig<ARFLOAT, ARFLOAT, ARumSymMatrix<ARFLOAT> >:: - SetShiftInvertMode(sigmap, this->objOP, &ARumSymMatrix<ARFLOAT>::MultInvv); - -} // SetShiftInvertMode. - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARumSymMatrix<ARFLOAT>& A, - const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) -{ - - this->NoShift(); - this->DefineParameters(A.ncols(), nevp, &A, &ARumSymMatrix<ARFLOAT>::MultMv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - -} // Long constructor (regular mode). - - -template<class ARFLOAT> -inline ARluSymStdEig<ARFLOAT>:: -ARluSymStdEig(int nevp, ARumSymMatrix<ARFLOAT>& A, - ARFLOAT sigmap, const std::string& whichp, int ncvp, ARFLOAT tolp, - int maxitp, ARFLOAT* residp, bool ishiftp) - -{ - - this->DefineParameters(A.ncols(), nevp, &A, &ARumSymMatrix<ARFLOAT>::MultInvv, - whichp, ncvp, tolp, maxitp, residp, ishiftp); - ChangeShift(sigmap); - -} // Long constructor (shift and invert mode). - - -template<class ARFLOAT> -ARluSymStdEig<ARFLOAT>& ARluSymStdEig<ARFLOAT>:: -operator=(const ARluSymStdEig<ARFLOAT>& other) -{ - - if (this != &other) { // Stroustrup suggestion. - this->ClearMem(); - Copy(other); - } - return *this; - -} // operator=. - - -#endif // ARUSSYM_H diff --git a/src/external/arpack++/include/blas1c.h b/src/external/arpack++/include/blas1c.h deleted file mode 100644 index b24fca52..00000000 --- a/src/external/arpack++/include/blas1c.h +++ /dev/null @@ -1,367 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE blas1c.h. - Interface to blas 1 and blas 2 FORTRAN routines. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#include "arch.h" -#include "blas1f.h" - -#ifndef BLAS1C_H -#define BLAS1C_H - -// ASSUM - -inline float assum(const ARint &n, const float dx[], const ARint &incx) { - return F77NAME(sasum)(&n, dx, &incx); -} // assum (float) - -inline double assum(const ARint &n, const double dx[], const ARint &incx) { - return F77NAME(dasum)(&n, dx, &incx); -} // assum (double) - -#ifdef ARCOMP_H -inline float assum(const ARint &n, const arcomplex<float> dx[], - const ARint &incx) { - return F77NAME(scasum)(&n, dx, &incx); -} // assum (arcomplex<float>) - -inline double assum(const ARint &n, const arcomplex<double> dx[], - const ARint &incx) { - return F77NAME(dzasum)(&n, dx, &incx); -} // assum (arcomplex<double>) -#endif - -// AXPY - -inline void axpy(const ARint &n, const float &da, const float dx[], - const ARint &incx, float dy[], const ARint &incy) { - F77NAME(saxpy)(&n, &da, dx, &incx, dy, &incy); -} // axpy (float) - -inline void axpy(const ARint &n, const double &da, const double dx[], - const ARint &incx, double dy[], const ARint &incy) { - F77NAME(daxpy)(&n, &da, dx, &incx, dy, &incy); -} // axpy (double) - -#ifdef ARCOMP_H -inline void axpy(const ARint &n, const arcomplex<float> &da, - const arcomplex<float> dx[], const ARint &incx, - arcomplex<float> dy[], const ARint &incy) { - F77NAME(caxpy)(&n, &da, dx, &incx, dy, &incy); -} // axpy (arcomplex<float>) - -inline void axpy(const ARint &n, const arcomplex<double> &da, - const arcomplex<double> dx[], const ARint &incx, - arcomplex<double> dy[], const ARint &incy) { - F77NAME(zaxpy)(&n, &da, dx, &incx, dy, &incy); -} // axpy (arcomplex<double>) -#endif - -// COPY - -inline void copy(const ARint &n, const float dx[], const ARint &incx, - float dy[], const ARint &incy) { - if (dx != dy) F77NAME(scopy)(&n, dx, &incx, dy, &incy); -} // copy (float) - -inline void copy(const ARint &n, const double dx[], const ARint &incx, - double dy[], const ARint &incy) { - if (dx != dy) F77NAME(dcopy)(&n, dx, &incx, dy, &incy); -} // copy (double) - -#ifdef ARCOMP_H -inline void copy(const ARint &n, const arcomplex<float> dx[], - const ARint &incx, arcomplex<float> dy[], - const ARint &incy) { - if (dx != dy) F77NAME(ccopy)(&n, dx, &incx, dy, &incy); -} // copy (arcomplex<float>) - -inline void copy(const ARint &n, const arcomplex<double> dx[], - const ARint &incx, arcomplex<double> dy[], - const ARint &incy) { - if (dx != dy) F77NAME(zcopy)(&n, dx, &incx, dy, &incy); -} // copy (arcomplex<double>) -#endif - -// DOT - -inline float dot(const ARint &n, const float dx[], const ARint &incx, - const float dy[], const ARint &incy) { - return F77NAME(sdot)(&n, dx, &incx, dy, &incy); -} // dot (float) - -inline double dot(const ARint &n, const double dx[], const ARint &incx, - const double dy[], const ARint &incy) { - return F77NAME(ddot)(&n, dx, &incx, dy, &incy); -} // dot (double) - -#ifdef ARCOMP_H -inline arcomplex<float> dotc(const ARint &n, const arcomplex<float> dx[], - const ARint &incx,const arcomplex<float> dy[], - const ARint &incy) { - arcomplex<float> tmp; - F77NAME(cdotc)(&tmp, &n, dx, &incx, dy, &incy); - return tmp; -} // dotc (arcomplex<float>) - -inline arcomplex<double> dotc(const ARint &n, const arcomplex<double> dx[], - const ARint &incx, const arcomplex<double> dy[], - const ARint &incy) { - arcomplex<double> tmp; - F77NAME(zdotc)(&tmp, &n, dx, &incx, dy, &incy); - return tmp; -} // dotc (arcomplex<double>) - -inline arcomplex<float> dotu(const ARint &n, const arcomplex<float> dx[], - const ARint &incx, const arcomplex<float> dy[], - const ARint &incy) { - arcomplex<float> tmp; - F77NAME(cdotu)(&tmp, &n, dx, &incx, dy, &incy); - return tmp; -} // dotu (arcomplex<float>) - -inline arcomplex<double> dotu(const ARint &n, const arcomplex<double> dx[], - const ARint &incx, const arcomplex<double> dy[], - const ARint &incy) { - arcomplex<double> tmp; - F77NAME(zdotu)(&tmp, &n, dx, &incx, dy, &incy); - return tmp; -} // dotu (arcomplex<double>) -#endif - -// NRM2 - -inline float nrm2(const ARint &n, const float dx[], const ARint &incx) { - return F77NAME(snrm2)(&n, dx, &incx); -} // nrm2 (float) - -inline double nrm2(const ARint &n, const double dx[], const ARint &incx) { - return F77NAME(dnrm2)(&n, dx, &incx); -} // nrm2 (double) - -#ifdef ARCOMP_H -inline float nrm2(const ARint &n, const arcomplex<float> dx[], - const ARint &incx) { - return F77NAME(scnrm2)(&n, dx, &incx); -} // nrm2 (complex <float>) - -inline double nrm2(const ARint &n, const arcomplex<double> dx[], - const ARint &incx) { - return F77NAME(dznrm2)(&n, dx, &incx); -} // nrm2 (complex <double>) -#endif - -// ROT - -inline void rot(const ARint &n, float dx[], const ARint &incx, float dy[], - const ARint &incy, const float &c, const float &s) { - F77NAME(srot)(&n, dx, &incx, dy, &incy, &c, &s); -} // rot (float) - -inline void rot(const ARint &n, double dx[], const ARint &incx, - double dy[], const ARint &incy, const double &c, - const double &s) { - F77NAME(drot)(&n, dx, &incx, dy, &incy, &c, &s); -} // rot (double) - -// ROTG - -inline void rotg(float &da, float &db, float &c, float &s) { - F77NAME(srotg)(&da, &db, &c, &s); -} // rotg (float) - -inline void rotg(double &da, double &db, double &c, double &s) { - F77NAME(drotg)(&da, &db, &c, &s); -} // rotg (double) - -// SCAL - -inline void scal(const ARint &n, float &da, float dx[], const ARint &incx) { - F77NAME(sscal)(&n, &da, dx, &incx); -} // scal (float) - -inline void scal(const ARint &n, double &da, double dx[], const ARint &incx) { - F77NAME(dscal)(&n, &da, dx, &incx); -} // scal (double) - -#ifdef ARCOMP_H -inline void scal(const ARint &n, const arcomplex<float> &da, - arcomplex<float> dx[], const ARint &incx) { - F77NAME(cscal)(&n, &da, dx, &incx); -} // scal (arcomplex<float>) - -inline void scal(const ARint &n, const arcomplex<double> &da, - arcomplex<double> dx[], const ARint &incx) { - F77NAME(zscal)(&n, &da, dx, &incx); -} // scal (arcomplex<double>) - -inline void sscal(const ARint &n, const float &da, arcomplex<float> dx[], - const ARint &incx) { - F77NAME(csscal)(&n, &da, dx, &incx); -} // sscal (arcomplex<float>) - -inline void sscal(const ARint &n, const double &da, arcomplex<double> dx[], - const ARint &incx) { - F77NAME(zdscal)(&n, &da, dx, &incx); -} // sscal (arcomplex<double>) -#endif - -// SWAP - -inline void swap(const ARint &n, float dx[], const ARint &incx, - float dy[], const ARint &incy) { - F77NAME(sswap)(&n, dx, &incx, dy, &incy); -} // swap (float) - -inline void swap(const ARint &n, double dx[], const ARint &incx, - double dy[], const ARint &incy) { - F77NAME(dswap)(&n, dx, &incx, dy, &incy); -} // swap (double) - -#ifdef ARCOMP_H -inline void swap(const ARint &n, arcomplex<float> dx[], const ARint &incx, - arcomplex<float> dy[], const ARint &incy) { - F77NAME(cswap)(&n, dx, &incx, dy, &incy); -} // swap (arcomplex<float>) - -inline void swap(const ARint &n, arcomplex<double> dx[], const ARint &incx, - arcomplex<double> dy[], const ARint &incy) { - F77NAME(zswap)(&n, dx, &incx, dy, &incy); -} // swap (arcomplex<double>) -#endif - -// AMAX - -inline ARint amax(const ARint &n, const float dx[], const ARint &incx) { - return F77NAME(isamax)(&n, dx, &incx); -} // amax (float) - -inline ARint amax(const ARint &n, const double dx[], const ARint &incx) { - return F77NAME(idamax)(&n, dx, &incx); -} // amax (double) - -#ifdef ARCOMP_H -inline ARint amax(const ARint &n, const arcomplex<float> dx[], - const ARint &incx) { - return F77NAME(icamax)(&n, dx, &incx); -} // amax (arcomplex<float>) - -inline ARint amax(const ARint &n, const arcomplex<double> dx[], - const ARint &incx) { - return F77NAME(izamax)(&n, dx, &incx); -} // amax (arcomplex<double>) -#endif - -// GEMV - -inline void gemv(const char* trans, const ARint &m, const ARint &n, - const float &alpha, const float a[], const ARint &lda, - const float x[], const ARint &incx, const float &beta, - float y[], const ARint &incy) { - F77NAME(sgemv)(trans, &m, &n, &alpha, a, &lda, - x, &incx, &beta, y, &incy); -} // gemv (float) - -inline void gemv(const char* trans, const ARint &m, const ARint &n, - const double &alpha, const double a[], const ARint &lda, - const double x[], const ARint &incx, const double &beta, - double y[], const ARint &incy) { - F77NAME(dgemv)(trans, &m, &n, &alpha, a, &lda, - x, &incx, &beta, y, &incy); -} // gemv (double) - -#ifdef ARCOMP_H -inline void gemv(const char* trans, const ARint &m, - const ARint &n, const arcomplex<float> &alpha, - const arcomplex<float> a[], const ARint &lda, - const arcomplex<float> x[], const ARint &incx, - const arcomplex<float> &beta, arcomplex<float> y[], - const ARint &incy) { - F77NAME(cgemv)(trans, &m, &n, &alpha, a, &lda, - x, &incx, &beta, y, &incy); -} // gemv (arcomplex<float>) - -inline void gemv(const char* trans, const ARint &m, - const ARint &n, const arcomplex<double> &alpha, - const arcomplex<double> a[], const ARint &lda, - const arcomplex<double> x[], const ARint &incx, - const arcomplex<double> &beta, arcomplex<double> y[], - const ARint &incy) { - F77NAME(zgemv)(trans, &m, &n, &alpha, a, &lda, - x, &incx, &beta, y, &incy); -} // gemv (arcomplex<double>) -#endif - -// GBMV - -inline void gbmv(const char* trans, const ARint &m, const ARint &n, - const ARint &kl, const ARint &ku, const float &alpha, - const float a[], const ARint &lda, const float x[], - const ARint &incx, const float &beta, float y[], - const ARint &incy) { - F77NAME(sgbmv)(trans, &m, &n, &kl, &ku, &alpha, a, &lda, - x, &incx, &beta, y, &incy); -} // gbmv (float) - -inline void gbmv(const char* trans, const ARint &m, const ARint &n, - const ARint &kl, const ARint &ku, const double &alpha, - const double a[], const ARint &lda, const double x[], - const ARint &incx, const double &beta, double y[], - const ARint &incy) { - F77NAME(dgbmv)(trans, &m, &n, &kl, &ku, &alpha, a, &lda, - x, &incx, &beta, y, &incy); -} // gbmv (double) - -#ifdef ARCOMP_H -inline void gbmv(const char* trans, const ARint &m, - const ARint &n, const ARint &kl, - const ARint &ku, const arcomplex<float> &alpha, - const arcomplex<float> a[], const ARint &lda, - const arcomplex<float> x[], const ARint &incx, - const arcomplex<float> &beta, arcomplex<float> y[], - const ARint &incy) { - F77NAME(cgbmv)(trans, &m, &n, &kl, &ku, &alpha, a, &lda, - x, &incx, &beta, y, &incy); -} // gbmv (arcomplex<float>) - -inline void gbmv(const char* trans, const ARint &m, - const ARint &n, const ARint &kl, - const ARint &ku, const arcomplex<double> &alpha, - const arcomplex<double> a[], const ARint &lda, - const arcomplex<double> x[], const ARint &incx, - const arcomplex<double> &beta, arcomplex<double> y[], - const ARint &incy) { - F77NAME(zgbmv)(trans, &m, &n, &kl, &ku, &alpha, a, &lda, - x, &incx, &beta, y, &incy); -} // gbmv (arcomplex<double>) -#endif - -// SBMV - -inline void sbmv(const char* uplo, const ARint &n, const ARint &k, - const float &alpha, const float a[], const ARint &lda, - const float x[], const ARint &incx, const float &beta, - float y[], const ARint &incy) { - F77NAME(ssbmv)(uplo, &n, &k, &alpha, a, &lda, x, &incx, &beta, y, &incy); -} // sbmv (float) - -inline void sbmv(const char* uplo, const ARint &n, const ARint &k, - const double &alpha, const double a[], const ARint &lda, - const double x[], const ARint &incx, const double &beta, - double y[], const ARint &incy) { - F77NAME(dsbmv)(uplo, &n, &k, &alpha, a, &lda, x, &incx, &beta, y, &incy); -} // sbmv (double) - - -#endif // BLAS1C_H diff --git a/src/external/arpack++/include/blas1f.h b/src/external/arpack++/include/blas1f.h deleted file mode 100644 index ad0dcaeb..00000000 --- a/src/external/arpack++/include/blas1f.h +++ /dev/null @@ -1,221 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE blas1f.h - BLAS 1 and BLAS 2 FORTRAN routines. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef BLAS1F_H -#define BLAS1F_H - -#include "arch.h" - -extern "C" -{ - - // Single precision real routines. - - float F77NAME(sasum)(const ARint *n, const float *dx, const ARint *incx); - - void F77NAME(saxpy)(const ARint *n, const float *da, const float *dx, - const ARint *incx, float *dy, const ARint *incy); - - void F77NAME(scopy)(const ARint *n, const float *dx, const ARint *incx, - float *dy, const ARint *incy); - - float F77NAME(sdot)(const ARint *n, const float *dx, const ARint *incx, - const float *dy, const ARint *incy); - - float F77NAME(snrm2)(const ARint *n, const float *dx, const ARint *incx); - - void F77NAME(srot)(const ARint *n, float *dx, const ARint *incx, float *dy, - const ARint *incy, const float *c, const float *s); - - void F77NAME(srotg)(float *da, float *db, float *c, float *s); - - void F77NAME(sscal)(const ARint *n, float *da, float *dx, const ARint *incx); - - void F77NAME(sswap)(const ARint *n, float *dx, const ARint *incx, - float *dy, const ARint *incy); - - ARint F77NAME(isamax)(const ARint *n, const float *dx, const ARint *incx); - - void F77NAME(sgemv)(const char* trans, const ARint *m, const ARint *n, - const float *alpha, const float *a, const ARint *lda, - const float *x, const ARint *incx, const float *beta, - float *y, const ARint *incy); - - void F77NAME(sgbmv)(const char* trans, const ARint *m, const ARint *n, - const ARint *kl, const ARint *ku, const float *alpha, - const float *a, const ARint *lda, const float *x, - const ARint *incx, const float *beta, float *y, - const ARint *incy); - - void F77NAME(ssbmv)(const char* uplo, const ARint *n, const ARint *k, - const float *alpha, const float *a, const ARint *lda, - const float *x, const ARint *incx, const float *beta, - float *y, const ARint *incy); - -// Double precision real routines. - - double F77NAME(dasum)(const ARint *n, const double *dx, const ARint *incx); - - void F77NAME(daxpy)(const ARint *n, const double *da, const double *dx, - const ARint *incx, double *dy, const ARint *incy); - - void F77NAME(dcopy)(const ARint *n, const double *dx, const ARint *incx, - double *dy, const ARint *incy); - - double F77NAME(ddot)(const ARint *n, const double *dx, const ARint *incx, - const double *dy, const ARint *incy); - - double F77NAME(dnrm2)(const ARint *n, const double *dx, const ARint *incx); - - void F77NAME(drot)(const ARint *n, double *dx, const ARint *incx, double *dy, - const ARint *incy, const double *c, const double *s); - - void F77NAME(drotg)(double *da, double *db, double *c, double *s); - - void F77NAME(dscal)(const ARint *n, double *da, double *dx, const ARint *incx); - - void F77NAME(dswap)(const ARint *n, double *dx, const ARint *incx, - double *dy, const ARint *incy); - - ARint F77NAME(idamax)(const ARint *n, const double *dx, const ARint *incx); - - void F77NAME(dgemv)(const char* trans, const ARint *m, const ARint *n, - const double *alpha, const double *a, const ARint *lda, - const double *x, const ARint *incx, const double *beta, - double *y, const ARint *incy); - - void F77NAME(dgbmv)(const char* trans, const ARint *m, const ARint *n, - const ARint *kl, const ARint *ku, const double *alpha, - const double *a, const ARint *lda, const double *x, - const ARint *incx, const double *beta, double *y, - const ARint *incy); - - void F77NAME(dsbmv)(const char* uplo, const ARint *n, const ARint *k, - const double *alpha, const double *a, const ARint *lda, - const double *x, const ARint *incx, const double *beta, - double *y, const ARint *incy); - - // Single precision complex routines. - -#ifdef ARCOMP_H - - void F77NAME(cdotc)(arcomplex<float> *c, const ARint *n, - const arcomplex<float> *cx, const ARint *incx, - const arcomplex<float> *cy, const ARint *incy); - - void F77NAME(cdotu)(arcomplex<float> *c, const ARint *n, - const arcomplex<float> *cx, const ARint *incx, - const arcomplex<float> *cy, const ARint *incy); - - void F77NAME(caxpy)(const ARint *n, const arcomplex<float> *da, - const arcomplex<float> *dx, const ARint *incx, - arcomplex<float> *dy, const ARint *incy); - - void F77NAME(ccopy)(const ARint *n, const arcomplex<float> *dx, - const ARint *incx, arcomplex<float> *dy, - const ARint *incy); - - float F77NAME(scasum)(const ARint *n, const arcomplex<float> *dx, - const ARint *incx); - - float F77NAME(scnrm2)(const ARint *n, const arcomplex<float> *dx, - const ARint *incx); - - void F77NAME(csscal)(const ARint *n, const float *da, arcomplex<float> *dx, - const ARint *incx); - - void F77NAME(cscal)(const ARint *n, const arcomplex<float> *da, - arcomplex<float> *dx, const ARint *incx); - - ARint F77NAME(icamax)(const ARint *n, const arcomplex<float> *dx, - const ARint *incx); - - void F77NAME(cswap)(const ARint *n, arcomplex<float> *dx, - const ARint *incx, arcomplex<float> *dy, - const ARint *incy); - - void F77NAME(cgemv)(const char* trans, const ARint *m, - const ARint *n, const arcomplex<float> *alpha, - const arcomplex<float> *a, const ARint *lda, - const arcomplex<float> *x, const ARint *incx, - const arcomplex<float> *beta, arcomplex<float> *y, - const ARint *incy); - - void F77NAME(cgbmv)(const char* trans, const ARint *m, - const ARint *n, const ARint *kl, - const ARint *ku, const arcomplex<float> *alpha, - const arcomplex<float> *a, const ARint *lda, - const arcomplex<float> *x, const ARint *incx, - const arcomplex<float> *beta, arcomplex<float> *y, - const ARint *incy); - - // Double precision complex routines. - - void F77NAME(zdotc)(arcomplex<double> *c, const ARint *n, - const arcomplex<double> *cx, const ARint *incx, - const arcomplex<double> *cy, const ARint *incy); - - void F77NAME(zdotu)(arcomplex<double> *c, const ARint *n, - const arcomplex<double> *cx, const ARint *incx, - const arcomplex<double> *cy, const ARint *incy); - - void F77NAME(zaxpy)(const ARint *n, const arcomplex<double> *da, - const arcomplex<double> *dx, const ARint *incx, - arcomplex<double> *dy, const ARint *incy); - - void F77NAME(zcopy)(const ARint *n, const arcomplex<double> *dx, - const ARint *incx, arcomplex<double> *dy, - const ARint *incy); - - double F77NAME(dzasum)(const ARint *n, const arcomplex<double> *dx, - const ARint *incx); - - double F77NAME(dznrm2)(const ARint *n, const arcomplex<double> *dx, - const ARint *incx); - - void F77NAME(zdscal)(const ARint *n, const double *da, arcomplex<double> *dx, - const ARint *incx); - - void F77NAME(zscal)(const ARint *n, const arcomplex<double> *da, - arcomplex<double> *dx, const ARint *incx); - - ARint F77NAME(izamax)(const ARint *n, const arcomplex<double> *dx, - const ARint *incx); - - void F77NAME(zswap)(const ARint *n, arcomplex<double> *dx, - const ARint *incx, arcomplex<double> *dy, - const ARint *incy); - - void F77NAME(zgemv)(const char* trans, const ARint *m, - const ARint *n, const arcomplex<double> *alpha, - const arcomplex<double> *a, const ARint *lda, - const arcomplex<double> *x, const ARint *incx, - const arcomplex<double> *beta, arcomplex<double> *y, - const ARint *incy); - - void F77NAME(zgbmv)(const char* trans, const ARint *m, - const ARint *n, const ARint *kl, - const ARint *ku, const arcomplex<double> *alpha, - const arcomplex<double> *a, const ARint *lda, - const arcomplex<double> *x, const ARint *incx, - const arcomplex<double> *beta, arcomplex<double> *y, - const ARint *incy); - -#endif // ARCOMP_H - -} -#endif // BLAS1F_H - diff --git a/src/external/arpack++/include/caupp.h b/src/external/arpack++/include/caupp.h deleted file mode 100644 index 3bc97c28..00000000 --- a/src/external/arpack++/include/caupp.h +++ /dev/null @@ -1,320 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE caupp.h. - Interface to ARPACK subroutines znaupd and cnaupd. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef CAUPP_H -#define CAUPP_H - -#include <string> -#include "arch.h" -#include "arpackf.h" - -inline void caupp(ARint& ido, char bmat, ARint n, const std::string& which, ARint nev, - double& tol, arcomplex<double> resid[], ARint ncv, - arcomplex<double> V[], ARint ldv, ARint iparam[], - ARint ipntr[], arcomplex<double> workd[], - arcomplex<double> workl[], ARint lworkl, double rwork[], - ARint& info) - -/* - c++ version of ARPACK routine znaupd that implements the - Reverse communication interface for the Implicitly Restarted Arnoldi - iteration. This is intended to be used to find a few eigenpairs of a - complex linear operator OP with respect to a semi-inner product defined - by a hermitian positive semi-definite real matrix B. B may be the - identity matrix. NOTE: if both OP and B are real, then naupp should - be used. - - The computed approximate eigenvalues are called Ritz values and - the corresponding approximate eigenvectors are called Ritz vectors. - - caupp is usually called iteratively to solve one of the - following problems: - - Mode 1: A*x = lambda*x. - ===> OP = A and B = I. - - Mode 2: A*x = lambda*M*x, M symmetric positive definite - ===> OP = inv[M]*A and B = M. - ===> (If M can be factored see remark 3 below) - - Mode 3: A*x = lambda*M*x, M symmetric semi-definite - ===> OP = inv[A - sigma*M]*M and B = M. - ===> shift-and-invert mode - If OP*x = amu*x, then lambda = sigma + 1/amu. - - - NOTE: The action of w <- inv[A - sigma*M]*v or w <- inv[M]*v - should be accomplished either by a direct method - using a sparse matrix factorization and solving - - [A - sigma*M]*w = v or M*w = v, - - or through an iterative method for solving these systems. If - an iterative method is used, the convergence test must be more - stringent than the accuracy requirements for the eigenvalue - approximations. - - Parameters: - - ido (Input / Output) Reverse communication flag. ido must be - zero on the first call to caupp. ido will be set - internally to indicate the type of operation to be - performed. Control is then given back to the calling - routine which has the responsibility to carry out the - requested operation and call caupp with the result. The - operand is given in workd[ipntr[1]], the result must be - put in workd[ipntr[2]]. - ido = 0: first call to the reverse communication interface. - ido = -1: compute Y = OP * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - This is for the initialization phase to force the - starting vector into the range of OP. - ido = 1: compute Y = OP * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - In mode 3 and 4, the vector B * X is already - available in workd[ipntr[3]]. It does not - need to be recomputed in forming OP * X. - ido = 2: compute Y = B * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - ido = 3: compute the iparam[8] real and imaginary parts - of the shifts where inptr[14] is the pointer - into workl for placing the shifts. See Remark - 5 below. - ido = 99: done. - bmat (Input) bmat specifies the type of the matrix B that defines - the semi-inner product for the operator OP. - bmat = 'I' -> standard eigenvalue problem A*x = lambda*x; - bmat = 'G' -> generalized eigenvalue problem A*x = lambda*M*x. - n (Input) Dimension of the eigenproblem. - nev (Input) Number of eigenvalues to be computed. 0 < nev <= n-1. - which (Input) Specify which of the Ritz values of OP to compute. - 'LM' - compute the nev eigenvalues of largest magnitude. - 'SM' - compute the nev eigenvalues of smallest magnitude. - 'LR' - compute the nev eigenvalues of largest real part. - 'SR' - compute the nev eigenvalues of smallest real part. - 'LI' - compute the nev eigenvalues of largest imaginary part. - 'SI' - compute the nev eigenvalues of smallest imaginary part. - tol (Input) Stopping criterion: the relative accuracy of the - Ritz value is considered acceptable if BOUNDS[i] <= - tol*abs(RITZ[i]),where ABS(RITZ[i]) is the magnitude when - RITZ[i] is complex. If tol<=0.0 is passed, the machine - precision as computed by the LAPACK auxiliary subroutine - _LAMCH is used. - resid (Input / Output) Array of length n. - On input: - If info==0, a random initial residual vector is used. - If info!=0, resid contains the initial residual vector, - possibly from a previous run. - On output: - resid contains the final residual vector. - ncv (Input) Number of Arnoldi vectors that are generated at each - iteration. After the startup phase in which nev Arnoldi - vectors are generated, the algorithm generates ncv-nev - Arnoldi vectors at each subsequent update iteration. Most of - the cost in generating each Arnoldi vector is in the - matrix-vector product OP*x. - NOTE: ncv must satisfy nev+1 <= ncv <= n. - V (Output) Array of length ncv*n+1. V contains the ncv Arnoldi - basis vectors. The first element V[0] is never referenced. - ldv (Input) Dimension of the basis vectors contained in V. This - parameter MUST be set to n. - iparam (Input / Output) Array of length 12. - iparam[1] = ISHIFT: method for selecting the implicit shifts. - The shifts selected at each iteration are used to restart - the Arnoldi iteration in an implicit fashion. - ------------------------------------------------------------- - ISHIFT = 0: the shifts are to be provided by the user via - reverse communication. The ncv eigenvalues of - the Hessenberg matrix H are returned in the part - of workl array corresponding to RITZ. - ISHIFT = 1: exact shifts with respect to the current - Hessenberg matrix H. This is equivalent to - restarting the iteration from the beginning - after updating the starting vector with a linear - combination of Ritz vectors associated with the - "wanted" eigenvalues. - ISHIFT = 2: other choice of internal shift to be defined. - ------------------------------------------------------------- - iparam[2] is no longer referenced. - iparam[3] = MXITER - On INPUT: maximum number of Arnoldi update iterations allowed. - On OUTPUT: actual number of Arnoldi update iterations taken. - iparam[4] = NB: blocksize to be used in the recurrence. - The code currently works only for NB = 1. - iparam[5] = NCONV: number of "converged" Ritz values. - This represents the number of Ritz values that satisfy - the convergence criterion. - iparam[6] is no longer referenced. - iparam[7] = MODE. On input determines what type of - eigenproblem is being solved. Must be 1, 2 or 3. - iparam[8] = NP. When ido = 3 and the user provides shifts - through reverse communication (iparam[1]=0), caupp returns - NP, the number of shifts the user is to provide. - 0 < NP <=ncv-nev. See Remark 5 below. - iparam[9] = total number of OP*x operations. - iparam[10] = total number of B*x operations if bmat='G'. - iparam[11] = total number of steps of re-orthogonalization. - ipntr (Output) Array of length 15. Pointer to mark the starting - locations in the workd and workl arrays for matrices/vectors - used by the Arnoldi iteration. - ipntr[1] : pointer to the current operand vector X in workd. - ipntr[2] : pointer to the current result vector Y in workd. - ipntr[3] : pointer to the vector B * X in workd when used in - the shift-and-invert mode. - ipntr[4] : pointer to the next available location in workl - that is untouched by the program. - ipntr[5] : pointer to the ncv by ncv upper Hessenberg matrix - H in workl. - ipntr[6] : pointer to the ritz value array RITZ. - ipntr[7] : pointer to the (projected) ritz vector array Q. - ipntr[8] : pointer to the error BOUNDS array in workl. - ipntr[14]: pointer to the NP shifts in workl. See Remark 5. - Note: ipntr[9:13] is only referenced by ceupp. See Remark 2. - ipntr[9] : pointer to the ncv RITZ values of the - original system. - ipntr[10]: Not Used - ipntr[11]: pointer to the ncv corresponding error bounds. - ipntr[12]: pointer to the ncv by ncv upper triangular - Schur matrix for H. - ipntr[13]: pointer to the ncv by ncv matrix of eigenvectors - of the upper Hessenberg matrix H. Only referenced by - ceupp if RVEC = true. See Remark 2 below. - workd (Input / Output) Array of length 3*n+1. - Distributed array to be used in the basic Arnoldi iteration - for reverse communication. The user should not use workd as - temporary workspace during the iteration. - workl (Output) Array of length lworkl+1. Private (replicated) array - on each PE or array allocated on the front end. - lworkl (Input) lworkl must be at least 3*ncv*ncv+5*ncv. - RWORK (Workspace) Array of length ncv. Private (replicated) array on - each PE or array allocated on the front end. - info (Input / Output) On input, if info = 0, a randomly initial - residual vector is used, otherwise resid contains the initial - residual vector, possibly from a previous run. - On output, info works as a error flag: - = 0 : Normal exit. - = 1 : Maximum number of iterations taken. All possible - eigenvalues of OP has been found. iparam[5] - returns the number of wanted converged Ritz values. - = 3 : No shifts could be applied during a cycle of the - Implicitly restarted Arnoldi iteration. One - possibility is to increase the size of ncv relative - to nev. See remark 4 below. - = -1 : n must be positive. - = -2 : nev must be positive. - = -3 : ncv must satisfy nev+1 <= ncv <= n. - = -4 : The maximum number of Arnoldi update iterations - allowed must be greater than zero. - = -5 : which must be one of 'LM','SM','LR','SR','LI','SI'. - = -6 : bmat must be one of 'I' or 'G'. - = -7 : Length of private work array is not sufficient. - = -8 : Error return from LAPACK eigenvalue calculation. - = -9 : Starting vector is zero. - = -10 : iparam[7] must be 1, 2 or 3. - = -11 : iparam[7] = 1 and bmat = 'G' are incompatible. - = -12 : iparam[1] must be equal to 0 or 1. - = -13 : nev and which = 'BE' are incompatible. - = -9999: Could not build an Arnoldi factorization. iparam[5] - returns the size of the current Arnoldi factorization. - The user is advised to check that enough workspace - and array storage has been allocated. - - Remarks: - 1. The computed Ritz values are approximate eigenvalues of OP. The - selection of "which" should be made with this in mind when using - Mode = 3. When operating in Mode = 3 setting which = 'LM' will - compute the nev eigenvalues of the original problem that are - closest to the shift sigma . After convergence, approximate - eigenvalues of the original problem may be obtained with the - ARPACK subroutine ceupp. - 2. If a basis for the invariant subspace corresponding to the converged - Ritz values is needed, the user must call ceupp immediately following - completion of caupp. This is new starting with release 2 of ARPACK. - 3. If M can be factored into a Cholesky factorization M = LL' - then Mode = 2 should not be selected. Instead one should use - Mode = 1 with OP = inv(L)*A*inv(L'). Appropriate triangular - linear systems should be solved with L and L' rather - than computing inverses. After convergence, an approximate - eigenvector z of the original problem is recovered by solving - L'z = x where x is a Ritz vector of OP. - 4. At present there is no a-priori analysis to guide the selection - of ncv relative to nev. The only formal requrement is that ncv - >= nev + 1. However, it is recommended that ncv >= 2*nev. If many - problems of the same type are to be solved, one should experiment - with increasing ncv while keeping nev fixed for a given test - problem. This will usually decrease the required number of OP*x - operations but it also increases the work and storage required to - maintain the orthogonal basis vectors. The optimal "cross-over" - with respect to CPU time is problem dependent and must be - determined empirically. - 5. When iparam[1] = 0, and ido = 3, the user needs to provide the - NP = iparam[8] complex shifts in locations - workl[ipntr[14]], workl[ipntr[14]+1], ... , workl[ipntr[14]+NP]. - Eigenvalues of the current upper Hessenberg matrix are located in - workl[ipntr[6]] through workl[ipntr[6]+ncv-1]. They are ordered - according to the order defined by "which". The associated Ritz - estimates are located in workl[ipntr[8]], workl[ipntr[8]+1], ..., - workl[ipntr[8]+ncv-1]. - - References: - 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in - a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), - pp 357-385. - 2. R.B. Lehoucq, "Analysis and Implementation of an Implicitly - Restarted Arnoldi Iteration", Rice University Technical Report - TR95-13, Department of Computational and Applied Mathematics. - 3. B.N. Parlett & Y. Saad, "_Complex_ Shift and Invert Strategies for - Double precision Matrices", Linear Algebra and its Applications, - vol 88/89, pp 575-595, (1987). -*/ - -{ - - F77NAME(znaupd)(&ido, &bmat, &n, which.c_str(), &nev, &tol, resid, &ncv, - &V[1], &ldv, &iparam[1], &ipntr[1], &workd[1], - &workl[1], &lworkl, &rwork[1], &info); - -} // caupp (arcomplex<double>). - -inline void caupp(ARint& ido, char bmat, ARint n, const std::string& which, ARint nev, - float& tol, arcomplex<float> resid[], ARint ncv, - arcomplex<float> V[], ARint ldv, ARint iparam[], - ARint ipntr[], arcomplex<float> workd[], - arcomplex<float> workl[], ARint lworkl, float rwork[], - ARint& info) - -/* - c++ version of ARPACK routine cnaupd. The only difference between - cnaupd and znaupd is that in the former function all vectors have - single precision elements and in the latter all vectors have double - precision elements. -*/ - -{ - - F77NAME(cnaupd)(&ido, &bmat, &n, which.c_str(), &nev, &tol, resid, &ncv, - &V[1], &ldv, &iparam[1], &ipntr[1], &workd[1], - &workl[1], &lworkl, &rwork[1], &info); - -} // caupp (arcomplex<float>). - -#endif // CAUPP_H - - - diff --git a/src/external/arpack++/include/ceupp.h b/src/external/arpack++/include/ceupp.h deleted file mode 100644 index b8dc8865..00000000 --- a/src/external/arpack++/include/ceupp.h +++ /dev/null @@ -1,224 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE ceupp.h. - Interface to ARPACK subroutines zneupd and cneupd. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef CEUPP_H -#define CEUPP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arpackf.h" - -inline void ceupp(bool rvec, char HowMny, arcomplex<double> d[], - arcomplex<double> Z[], ARint ldz, arcomplex<double> sigma, - arcomplex<double> workev[], char bmat, ARint n, const std::string& which, - ARint nev, double tol, arcomplex<double> resid[], ARint ncv, - arcomplex<double> V[], ARint ldv, ARint iparam[], - ARint ipntr[], arcomplex<double> workd[], - arcomplex<double> workl[], ARint lworkl, double rwork[], - ARint& info) - -/* - c++ version of ARPACK routine zneupd. - This subroutine returns the converged approximations to eigenvalues - of A*z = lambda*B*z and (optionally): - - (1) the corresponding approximate eigenvectors, - (2) an orthonormal basis for the associated approximate - invariant subspace, - - There is negligible additional cost to obtain eigenvectors. An - orthonormal basis is always computed. There is an additional storage cost - of n*nev if both are requested (in this case a separate array Z must be - supplied). - The approximate eigenvalues and eigenvectors of A*z = lambda*B*z - are derived from approximate eigenvalues and eigenvectors of - of the linear operator OP prescribed by the MODE selection in the - call to caupp. caupp must be called before this routine is called. - These approximate eigenvalues and vectors are commonly called Ritz - values and Ritz vectors respectively. They are referred to as such - in the comments that follow. The computed orthonormal basis for the - invariant subspace corresponding to these Ritz values is referred to - as a Schur basis. - See documentation in the header of the subroutine caupp for - definition of OP as well as other terms and the relation of computed - Ritz values and Ritz vectors of OP with respect to the given problem - A*z = lambda*B*z. For a brief description, see definitions of - iparam[7], MODE and which in the documentation of caupp. - - Parameters: - - rvec (Input) Specifies whether a basis for the invariant subspace - corresponding to the converged Ritz value approximations for - the eigenproblem A*z = lambda*B*z is computed. - rvec = false: Compute Ritz values only. - rvec = true : Compute the Ritz vectors or Schur vectors. - See Remarks below. - HowMny (Input) Specifies the form of the basis for the invariant - subspace corresponding to the converged Ritz values that - is to be computed. - = 'A': Compute nev Ritz vectors; - = 'P': Compute nev Schur vectors; - d (Output) Array of dimension nev+1. D contains the Ritz - approximations to the eigenvalues lambda for A*z = lambda*B*z. - Z (Output) Array of dimension nev*n. If rvec = TRUE. and - HowMny = 'A', then Z contains approximate eigenvectors (Ritz - vectors) corresponding to the NCONV=iparam[5] Ritz values for - eigensystem A*z = lambda*B*z. - If rvec = .FALSE. or HowMny = 'P', then Z is not referenced. - NOTE: If if rvec = .TRUE. and a Schur basis is not required, - the array Z may be set equal to first nev+1 columns of - the Arnoldi basis array V computed by caupp. In this - case the Arnoldi basis will be destroyed and overwritten - with the eigenvector basis. - ldz (Input) Dimension of the vectors contained in Z. This - parameter MUST be set to n. - sigma (Input) If iparam[7] = 3, sigma represents the shift. Not - referenced if iparam[7] = 1 or 2. - workv (Workspace) Array of dimension 2*ncv. - V (Input/Output) Array of dimension n*ncv+1. - Upon Input: V contains the ncv vectors of the Arnoldi basis - for OP as constructed by caupp. - Upon Output: If rvec = TRUE the first NCONV=iparam[5] columns - contain approximate Schur vectors that span the - desired invariant subspace. - NOTE: If the array Z has been set equal to first nev+1 columns - of the array V and rvec = TRUE. and HowMny = 'A', then - the Arnoldi basis held by V has been overwritten by the - desired Ritz vectors. If a separate array Z has been - passed then the first NCONV=iparam[5] columns of V will - contain approximate Schur vectors that span the desired - invariant subspace. - workl (Input / Output) Array of length lworkl+1. - workl[1:ncv*ncv+3*ncv] contains information obtained in - caupp. They are not changed by ceupp. - workl[ncv*ncv+3*ncv+1:3*ncv*ncv+4*ncv] holds the untransformed - Ritz values, the untransformed error estimates of the Ritz - values, the upper triangular matrix for H, and the associated - matrix representation of the invariant subspace for H. - ipntr (Input / Output) Array of length 14. Pointer to mark the - starting locations in the workl array for matrices/vectors - used by caupp and ceupp. - ipntr[9]: pointer to the ncv RITZ values of the original - system. - ipntr[11]: pointer to the ncv corresponding error estimates. - ipntr[12]: pointer to the ncv by ncv upper triangular - Schur matrix for H. - ipntr[13]: pointer to the ncv by ncv matrix of eigenvectors - of the upper Hessenberg matrix H. Only referenced - by ceupp if rvec = TRUE. See Remark 2 below. - info (Output) Error flag. - = 0 : Normal exit. - = 1 : The Schur form computed by LAPACK routine csheqr - could not be reordered by LAPACK routine ztrsen. - Re-enter subroutine ceupp with iparam[5] = ncv and - increase the size of the array D to have - dimension at least dimension ncv and allocate at least - ncv columns for Z. NOTE: Not necessary if Z and V share - the same space. Please notify the authors if this error - occurs. - = -1 : n must be positive. - = -2 : nev must be positive. - = -3 : ncv must satisfy nev+1 <= ncv <= n. - = -5 : which must be one of 'LM','SM','LR','SR','LI','SI'. - = -6 : bmat must be one of 'I' or 'G'. - = -7 : Length of private work workl array is not sufficient. - = -8 : Error return from LAPACK eigenvalue calculation. - This should never happened. - = -9 : Error return from calculation of eigenvectors. - Informational error from LAPACK routine ztrevc. - = -10: iparam[7] must be 1, 2 or 3. - = -11: iparam[7] = 1 and bmat = 'G' are incompatible. - = -12: HowMny = 'S' not yet implemented. - = -13: HowMny must be one of 'A' or 'P' if rvec = TRUE. - = -14: caupp did not find any eigenvalues to sufficient - accuracy. - - NOTE: The following arguments - - bmat, n, which, nev, tol, resid, ncv, V, ldv, iparam, - ipntr, workd, workl, lworkl, rwork, info - - must be passed directly to ceupp following the last call - to caupp. These arguments MUST NOT BE MODIFIED between - the the last call to caupp and the call to ceupp. - - Remarks - 1. Currently only HowMny = 'A' and 'P' are implemented. - 2. Schur vectors are an orthogonal representation for the basis of - Ritz vectors. Thus, their numerical properties are often superior. - Let X' denote the transpose of X. If rvec = .TRUE. then the - relationship A * V[:,1:iparam[5]] = V[:,1:iparam[5]] * T, and - V[:,1:iparam[5]]' * V[:,1:iparam[5]] = I are approximately satisfied. - Here T is the leading submatrix of order iparam[5] of the real - upper quasi-triangular matrix stored workl[ipntr[12]]. -*/ - -{ - - ARint irvec; - ARlogical* iselect; - arcomplex<double>* iZ; - - irvec = (ARint) rvec; - iselect = new ARlogical[ncv]; - iZ = (Z == NULL) ? &V[1] : Z; - - F77NAME(zneupd)(&irvec, &HowMny, iselect, d, iZ, &ldz, &sigma, - &workev[1], &bmat, &n, which.c_str(), &nev, &tol, resid, - &ncv, &V[1], &ldv, &iparam[1], &ipntr[1], - &workd[1], &workl[1], &lworkl, &rwork[1], &info); - - delete[] iselect; - -} // ceupp (arcomplex<double>). - -inline void ceupp(bool rvec, char HowMny, arcomplex<float> d[], - arcomplex<float> Z[], ARint ldz, arcomplex<float> sigma, - arcomplex<float> workev[], char bmat, ARint n, const std::string& which, - ARint nev, float tol, arcomplex<float> resid[], ARint ncv, - arcomplex<float> V[], ARint ldv, ARint iparam[], - ARint ipntr[], arcomplex<float> workd[], - arcomplex<float> workl[], ARint lworkl, float rwork[], - ARint& info) - -/* - c++ version of ARPACK routine cneupd. The only difference between - cneupd and zneupd is that in the former function all vectors have - single precision elements and in the latter all vectors have double - precision elements. -*/ - -{ - - ARint irvec; - ARlogical* iselect; - arcomplex<float>* iZ; - - irvec = (ARint) rvec; - iselect = new ARlogical[ncv]; - iZ = (Z == NULL) ? &V[1] : Z; - - F77NAME(cneupd)(&irvec, &HowMny, iselect, d, iZ, &ldz, &sigma, - &workev[1], &bmat, &n, which.c_str(), &nev, &tol, resid, - &ncv, &V[1], &ldv, &iparam[1], &ipntr[1], - &workd[1], &workl[1], &lworkl, &rwork[1], &info); - - delete[] iselect; - -} // ceupp (arcomplex<float>). - -#endif // CEUPP_H diff --git a/src/external/arpack++/include/cholmodc.h b/src/external/arpack++/include/cholmodc.h deleted file mode 100644 index f1300cbb..00000000 --- a/src/external/arpack++/include/cholmodc.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE CHOLMODc.h. - Interface to CHOLMOD routines. - - Author of this class: - Martin Reuter - Date 11/05/2012 - - Arpack++ Author: - Francisco Gomes - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef CHOLMODC_H -#define CHOLMODC_H - -#include "cholmod.h" -#include <fstream> - -inline void Write_Cholmod_Sparse_Matrix(const std::string & fname, - cholmod_sparse* A, cholmod_common *c) -{ - std::ofstream myfile; - myfile.open ( fname.c_str() ); - cholmod_triplet * T = cholmod_sparse_to_triplet(A,c); - //std::cout << " [ " << std::endl; - myfile.precision(20); - for (unsigned int i=0;i<T->nnz;i++) - { - myfile << ((int*)T->i)[i]+1 << " " << ((int*)T->j)[i]+1 << " " << ((double*)T->x)[i] << std::endl; - } - //std::cout << " ] " << std::endl; - myfile.close(); - - cholmod_free_triplet(&T,c); - -} - -// Create_Cholmod_Sparse_Matrix -inline cholmod_sparse* Create_Cholmod_Sparse_Matrix(int m, int n, int nnz, - double* a, int* irow, int* pcol, char uplo, cholmod_common *c) -{ - - cholmod_sparse* A = new cholmod_sparse; - A->nrow = m; - A->ncol = n; - A->nzmax = nnz; - A->p = pcol; - A->i = irow; - A->nz = NULL; - A->x = a; - A->z = NULL; - if (uplo == 'L') A->stype = -1; - else A->stype = 1; - A->itype = CHOLMOD_INT; - A->xtype = CHOLMOD_REAL; // real - A->dtype = CHOLMOD_DOUBLE; // double - A->sorted = 0; - A->packed = 1; - - return A; - - -/* double* hd = new double[nnz]; - int* hi = new int[nnz]; - int* hp = new int[n+1]; - - int col,j; - int counter=0; - int counter2=0; - for (col=0;col<n;col++) // column - { - hp[col] = counter2; - for (j=pcol[col];j<pcol[col+1];j++) - { - int & row = irow[counter]; - if ((uplo == 'L' && row >= col) ||(uplo == 'U' && row <= col)) - { - hd[counter2] = a[counter]; - hi[counter2] = irow[counter]; - counter2++; - //std::cout << " In : " << std::flush; - } - //else std::cout << " Out : " << std::flush; - - //std::cout << row+1 << " " << col+1 << " " << a[counter] << std::endl; - counter++; - } - - } - hp[n] = counter2; - - - cholmod_sparse* A = new cholmod_sparse; - A->nrow = m; - A->ncol = n; - A->nzmax = counter2; - A->p = hp; - A->i = hi; - A->nz = NULL; - A->x = hd; - A->z = NULL; - if (uplo == 'L') A->stype = -1; - else A->stype = 1; - A->itype = CHOLMOD_INT; - A->xtype = CHOLMOD_REAL; // real - A->dtype = CHOLMOD_DOUBLE; // double - A->sorted = 0; - A->packed = 1; - - //cholmod_sparse* As = cholmod_copy_sparse(A,c); - - return A;*/ - -} // Create_Cholmod_Sparse_Matrix (double). - -// Create_Cholmod_Dense_Matrix (from Triplet) -inline cholmod_dense* Create_Cholmod_Dense_Matrix(int m, int n, - double* a, cholmod_common *c) -{ - - - cholmod_dense* A = new cholmod_dense; - A->nrow = m; - A->ncol = n; - A->nzmax = m*n; - A->d = m; - A->x = a; - A->z = NULL; - A->xtype = CHOLMOD_REAL; // real - A->dtype = CHOLMOD_DOUBLE; // double - -// cholmod_dense* As = cholmod_copy_dense(A,c); - - return A; - -} // Create_Cholmod_Dense_Matrix (double). - -// Create_Cholmod_Dense_Matrix (from Triplet) -inline void Get_Cholmod_Dense_Data(cholmod_dense* A, int n, double* a) -{ - memcpy(a,A->x,n*sizeof(double)); - -// for (int i = 0;i<n;i++) -// a[i] = ((double*)A->x)[i]; - -} // Create_Cholmod_Dense_Matrix (double). - - - -#endif // CHOLMODC_H diff --git a/src/external/arpack++/include/debug.h b/src/external/arpack++/include/debug.h deleted file mode 100644 index 2ceab437..00000000 --- a/src/external/arpack++/include/debug.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE debug.h. - Interface to ARPACK FORTRAN debugging facilities. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef DEBUG_H -#define DEBUG_H - -#include "arch.h" -#include "arpackf.h" - - -inline void TraceOff() - -/* - This function sets all ARPACK FORTRAN debug variables to zero. -*/ - -{ - - F77NAME(debug).logfil = 6; - F77NAME(debug).ndigit = 0; - F77NAME(debug).mgetv0 = 0; - F77NAME(debug).msaupd = 0; - F77NAME(debug).msaup2 = 0; - F77NAME(debug).msaitr = 0; - F77NAME(debug).mseigt = 0; - F77NAME(debug).msapps = 0; - F77NAME(debug).msgets = 0; - F77NAME(debug).mseupd = 0; - F77NAME(debug).mnaupd = 0; - F77NAME(debug).mnaup2 = 0; - F77NAME(debug).mnaitr = 0; - F77NAME(debug).mneigt = 0; - F77NAME(debug).mnapps = 0; - F77NAME(debug).mngets = 0; - F77NAME(debug).mneupd = 0; - F77NAME(debug).mcaupd = 0; - F77NAME(debug).mcaup2 = 0; - F77NAME(debug).mcaitr = 0; - F77NAME(debug).mceigt = 0; - F77NAME(debug).mcapps = 0; - F77NAME(debug).mcgets = 0; - F77NAME(debug).mceupd = 0; - -} // TraceOff. - - -inline void sTraceOn(const ARint digit, const ARint getv0, const ARint aupd, - const ARint aup2, const ARint aitr, const ARint eigt, - const ARint apps, const ARint gets, const ARint eupd) - -/* - This function sets the values of all ARPACK FORTRAN debug - variables corresponding to real symmetric eigenvalue problems. -*/ - -{ - - F77NAME(debug).logfil = 6; - F77NAME(debug).ndigit = digit; - F77NAME(debug).mgetv0 = getv0; - F77NAME(debug).msaupd = aupd; - F77NAME(debug).msaup2 = aup2; - F77NAME(debug).msaitr = aitr; - F77NAME(debug).mseigt = eigt; - F77NAME(debug).msapps = apps; - F77NAME(debug).msgets = gets; - F77NAME(debug).mseupd = eupd; - -} // sTraceOn. - - -inline void nTraceOn(const ARint digit, const ARint getv0, const ARint aupd, - const ARint aup2, const ARint aitr, const ARint eigt, - const ARint apps, const ARint gets, const ARint eupd) - -/* - This function sets the values of all ARPACK FORTRAN debug - variables corresponding to real nonsymmetric eigenvalue problems. -*/ - -{ - - F77NAME(debug).logfil = 6; - F77NAME(debug).ndigit = digit; - F77NAME(debug).mgetv0 = getv0; - F77NAME(debug).mnaupd = aupd; - F77NAME(debug).mnaup2 = aup2; - F77NAME(debug).mnaitr = aitr; - F77NAME(debug).mneigt = eigt; - F77NAME(debug).mnapps = apps; - F77NAME(debug).mngets = gets; - F77NAME(debug).mneupd = eupd; - -} // nTraceOn. - - -inline void cTraceOn(const ARint digit, const ARint getv0, const ARint aupd, - const ARint aup2, const ARint aitr, const ARint eigt, - const ARint apps, const ARint gets, const ARint eupd) - -/* - This function sets the values of all ARPACK FORTRAN debug - variables corresponding to complex eigenvalue problems. -*/ - -{ - - F77NAME(debug).logfil = 6; - F77NAME(debug).ndigit = digit; - F77NAME(debug).mgetv0 = getv0; - F77NAME(debug).mcaupd = aupd; - F77NAME(debug).mcaup2 = aup2; - F77NAME(debug).mcaitr = aitr; - F77NAME(debug).mceigt = eigt; - F77NAME(debug).mcapps = apps; - F77NAME(debug).mcgets = gets; - F77NAME(debug).mceupd = eupd; - -} // cTraceOn. - - -#endif // DEBUG_H diff --git a/src/external/arpack++/include/lapackc.h b/src/external/arpack++/include/lapackc.h deleted file mode 100644 index 47dd05bc..00000000 --- a/src/external/arpack++/include/lapackc.h +++ /dev/null @@ -1,306 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE lapackc.h. - Interface to LAPACK FORTRAN routines. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#include "arch.h" -#include "lapackf.h" - -#ifndef LAPACKC_H -#define LAPACKC_H - - -// LAPY2 - -inline float lapy2(const float &x, const float &y) { - return F77NAME(slapy2)(&x, &y); -} // lapy2 (float) - -inline double lapy2(const double &x, const double &y) { - return F77NAME(dlapy2)(&x, &y); -} // lapy2 (double) - - -// LACPY - -inline void lacpy(const char* uplo, const ARint &m, const ARint &n, - const float a[], const ARint &lda, float b[], - const ARint &ldb) { - F77NAME(slacpy)(uplo, &m, &n, a, &lda, b, &ldb); -} // lacpy (float) - -inline void lacpy(const char* uplo, const ARint &m, const ARint &n, - const double a[], const ARint &lda, double b[], - const ARint &ldb) { - F77NAME(dlacpy)(uplo, &m, &n, a, &lda, b, &ldb); -} // lacpy (double) - -#ifdef ARCOMP_H -inline void lacpy(const char* uplo, const ARint &m, const ARint &n, - const arcomplex<float> a[], const ARint &lda, - arcomplex<float> b[], const ARint &ldb) { - F77NAME(clacpy)(uplo, &m, &n, a, &lda, b, &ldb); -} // lacpy (arcomplex<float>) - -inline void lacpy(const char* uplo, const ARint &m, const ARint &n, - const arcomplex<double> a[], const ARint &lda, - arcomplex<double> b[], const ARint &ldb) { - F77NAME(zlacpy)(uplo, &m, &n, a, &lda, b, &ldb); -} // lacpy (arcomplex<double>) -#endif - - -// GTTRF - -inline void gttrf(const ARint &n, float dl[], float d[], float du[], - float du2[], ARint ipiv[], ARint &info) { - F77NAME(sgttrf)(&n, dl, d, du, du2, ipiv, &info); -} // gttrf (float) - -inline void gttrf(const ARint &n, double dl[], double d[], double du[], - double du2[], ARint ipiv[], ARint &info) { - F77NAME(dgttrf)(&n, dl, d, du, du2, ipiv, &info); -} // gttrf (double) - -#ifdef ARCOMP_H -inline void gttrf(const ARint &n, arcomplex<float> dl[], arcomplex<float> d[], - arcomplex<float> du[], arcomplex<float> du2[], ARint ipiv[], - ARint &info) { - F77NAME(cgttrf)(&n, dl, d, du, du2, ipiv, &info); -} // gttrf (arcomplex<float>) - -inline void gttrf(const ARint &n, arcomplex<double> dl[], arcomplex<double> d[], - arcomplex<double> du[], arcomplex<double> du2[], ARint ipiv[], - ARint &info) { - F77NAME(zgttrf)(&n, dl, d, du, du2, ipiv, &info); -} // gttrf (arcomplex<double>) -#endif - - -// GTTRS - -inline void gttrs(const char* trans, const ARint &n, const ARint &nrhs, - const float dl[], const float d[], const float du[], - const float du2[], const ARint ipiv[], float b[], - const ARint &ldb, ARint &info) { - F77NAME(sgttrs)(trans, &n, &nrhs, dl, d, du, du2, ipiv, b, &ldb, &info); -} // gttrs (float) - -inline void gttrs(const char* trans, const ARint &n, const ARint &nrhs, - const double dl[], const double d[], const double du[], - const double du2[], const ARint ipiv[], double b[], - const ARint &ldb, ARint &info) { - F77NAME(dgttrs)(trans, &n, &nrhs, dl, d, du, du2, ipiv, b, &ldb, &info); -} // gttrs (double) - -#ifdef ARCOMP_H - -inline void gttrs(const char* trans, const ARint &n, const ARint &nrhs, - const arcomplex<float> dl[], const arcomplex<float> d[], - const arcomplex<float> du[], const arcomplex<float> du2[], - const ARint ipiv[], arcomplex<float> b[], - const ARint &ldb, ARint &info) { - F77NAME(cgttrs)(trans, &n, &nrhs, dl, d, du, du2, ipiv, b, &ldb, &info); -} // gttrs (arcomplex<float>) - -inline void gttrs(const char* trans, const ARint &n, const ARint &nrhs, - const arcomplex<double> dl[], const arcomplex<double> d[], - const arcomplex<double> du[], const arcomplex<double> du2[], - const ARint ipiv[], arcomplex<double> b[], - const ARint &ldb, ARint &info) { - F77NAME(zgttrs)(trans, &n, &nrhs, dl, d, du, du2, ipiv, b, &ldb, &info); -} // gttrs (arcomplex<double>) -#endif - - -// GBTRF - -inline void gbtrf(const ARint &m, const ARint &n, const ARint &kl, - const ARint &ku, float ab[], const ARint &ldab, - ARint ipiv[], ARint &info) { - F77NAME(sgbtrf)(&m, &n, &kl, &ku, ab, &ldab, ipiv, &info); -} // gbtrf (float) - -inline void gbtrf(const ARint &m, const ARint &n, const ARint &kl, - const ARint &ku, double ab[], const ARint &ldab, - ARint ipiv[], ARint &info) { - F77NAME(dgbtrf)(&m, &n, &kl, &ku, ab, &ldab, ipiv, &info); -} // gbtrf (double) - -#ifdef ARCOMP_H -inline void gbtrf(const ARint &m, const ARint &n, const ARint &kl, - const ARint &ku, arcomplex<float> ab[], - const ARint &ldab, ARint ipiv[], ARint &info) { - F77NAME(cgbtrf)(&m, &n, &kl, &ku, ab, &ldab, ipiv, &info); -} // gbtrf (arcomplex<float>) - -inline void gbtrf(const ARint &m, const ARint &n, const ARint &kl, - const ARint &ku, arcomplex<double> ab[], - const ARint &ldab, ARint ipiv[], ARint &info) { - F77NAME(zgbtrf)(&m, &n, &kl, &ku, ab, &ldab, ipiv, &info); -} // gbtrf (arcomplex<double>) -#endif - - -// GBTRS - -inline void gbtrs(const char* trans, const ARint &n, const ARint &kl, - const ARint &ku, const ARint &nrhs, const float ab[], - const ARint &ldab, const ARint ipiv[], float b[], - const ARint &ldb, ARint &info) { - F77NAME(sgbtrs)(trans, &n, &kl, &ku, &nrhs, ab, &ldab, ipiv, b, &ldb, &info); -} // gbtrs (float) - -inline void gbtrs(const char* trans, const ARint &n, const ARint &kl, - const ARint &ku, const ARint &nrhs, const double ab[], - const ARint &ldab, const ARint ipiv[], double b[], - const ARint &ldb, ARint &info) { - F77NAME(dgbtrs)(trans, &n, &kl, &ku, &nrhs, ab, &ldab, ipiv, b, &ldb, &info); -} // gbtrs (double) - -#ifdef ARCOMP_H -inline void gbtrs(const char* trans, const ARint &n, const ARint &kl, - const ARint &ku, const ARint &nrhs, - const arcomplex<float> ab[], const ARint &ldab, - const ARint ipiv[], arcomplex<float> b[], - const ARint &ldb, ARint &info) { - F77NAME(cgbtrs)(trans, &n, &kl, &ku, &nrhs, ab, &ldab, ipiv, b, &ldb, &info); -} // gbtrs (arcomplex<float>) - -inline void gbtrs(const char* trans, const ARint &n, const ARint &kl, - const ARint &ku, const ARint &nrhs, - const arcomplex<double> ab[], const ARint &ldab, - const ARint ipiv[], arcomplex<double> b[], - const ARint &ldb, ARint &info) { - F77NAME(zgbtrs)(trans, &n, &kl, &ku, &nrhs, ab, &ldab, ipiv, b, &ldb, &info); -} // gbtrs (arcomplex<double>) -#endif - - -// GETRF - -inline void getrf(const ARint &m, const ARint &n, float A[], - const ARint &lda, ARint ipiv[], ARint &info) { - F77NAME(sgetrf)(&m, &n, A, &lda, ipiv, &info); -} // getrf (float) - -inline void getrf(const ARint &m, const ARint &n, double A[], - const ARint &lda, ARint ipiv[], ARint &info) { - F77NAME(dgetrf)(&m, &n, A, &lda, ipiv, &info); -} // getrf (double) - -#ifdef ARCOMP_H -inline void getrf(const ARint &m, const ARint &n, arcomplex<float> A[], - const ARint &lda, ARint ipiv[], ARint &info) { - F77NAME(cgetrf)(&m, &n, A, &lda, ipiv, &info); -} // getrf (arcomplex<float>) - -inline void getrf(const ARint &m, const ARint &n, arcomplex<double> A[], - const ARint &lda, ARint ipiv[], ARint &info) { - F77NAME(zgetrf)(&m, &n, A, &lda, ipiv, &info); -} // getrf (arcomplex<double>) -#endif - -// GETRS - -inline void getrs(const char* trans, const ARint &n, const ARint &nrhs, - const float A[], const ARint &lda, const ARint ipiv[], - float b[], const ARint &ldb, ARint &info) { - F77NAME(sgetrs)(trans, &n, &nrhs, A, &lda, ipiv, b, &ldb, &info); -} // getrs (float) - -inline void getrs(const char* trans, const ARint &n, const ARint &nrhs, - const double A[], const ARint &lda, const ARint ipiv[], - double b[], const ARint &ldb, ARint &info) { - F77NAME(dgetrs)(trans, &n, &nrhs, A, &lda, ipiv, b, &ldb, &info); -} // getrs (double) - -#ifdef ARCOMP_H -inline void getrs(const char* trans, const ARint &n, const ARint &nrhs, - const arcomplex<float> A[], const ARint &lda, - const ARint ipiv[], arcomplex<float> b[], - const ARint &ldb, ARint &info) { - F77NAME(cgetrs)(trans, &n, &nrhs, A, &lda, ipiv, b, &ldb, &info); -} // getrs (arcomplex<float>) - -inline void getrs(const char* trans, const ARint &n, const ARint &nrhs, - const arcomplex<double> A[], const ARint &lda, - const ARint ipiv[], arcomplex<double> b[], - const ARint &ldb, ARint &info) { - F77NAME(zgetrs)(trans, &n, &nrhs, A, &lda, ipiv, b, &ldb, &info); -} // getrs (arcomplex<double>) -#endif - -// PTTRF - -inline void pttrf(const ARint &n, float d[], float e[], ARint &info) { - F77NAME(spttrf)(&n, d, e, &info); -} // pttrf (float) - -inline void pttrf(const ARint &n, double d[], double e[], ARint &info) { - F77NAME(dpttrf)(&n, d, e, &info); -} // pttrf (double) - -// PTTRS - -inline void pttrs(const ARint &n, const ARint &nrhs, - const float d[], const float e[], float b[], - const ARint &ldb, ARint &info) { - F77NAME(spttrs)(&n, &nrhs, d, e, b, &ldb, &info); -} // pttrs (float) - -inline void pttrs(const ARint &n, const ARint &nrhs, - const double d[], const double e[], double b[], - const ARint &ldb, ARint &info) { - F77NAME(dpttrs)(&n, &nrhs, d, e, b, &ldb, &info); -} // pttrs (double) - - -// SPTRF - -inline void sptrf(const char* trans, const ARint &n, float ap[], - ARint ipiv[], ARint &info) { - F77NAME(ssptrf)(trans, &n, ap, ipiv, &info); -} // sptrf (float) - -inline void sptrf(const char* trans, const ARint &n, double ap[], - ARint ipiv[], ARint &info) { - F77NAME(dsptrf)(trans, &n, ap, ipiv, &info); -} // sptrf (double) - - -// SPTRS - -inline void sptrs(const char* trans, const ARint &n, const ARint &nrhs, - float ap[], ARint ipiv[], float b[], - const ARint &ldb, ARint &info) { - F77NAME(ssptrs)(trans, &n, &nrhs, ap, ipiv, b, &ldb, &info); -} // sptrs (float) - -inline void sptrs(const char* trans, const ARint &n, const ARint &nrhs, - double ap[], ARint ipiv[], double b[], - const ARint &ldb, ARint &info) { - F77NAME(dsptrs)(trans, &n, &nrhs, ap, ipiv, b, &ldb, &info); -} // sptrs (double) - - -inline void second(const float &t) { - F77NAME(second)(&t); -} - -#endif // LAPACKC_H - - - - diff --git a/src/external/arpack++/include/lapackf.h b/src/external/arpack++/include/lapackf.h deleted file mode 100644 index 2d6209b0..00000000 --- a/src/external/arpack++/include/lapackf.h +++ /dev/null @@ -1,207 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE lapackf.h. - Interface to LAPACK FORTRAN routines. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef LAPACKF_H -#define LAPACKF_H - -#include "arch.h" - -extern "C" -{ - - // Single precision real routines. - - float F77NAME(slapy2)(const float *x, const float *y); - - void F77NAME(slacpy)(const char* uplo, const ARint *m, const ARint *n, - const float *a, const ARint *lda, float *b, - const ARint *ldb); - - void F77NAME(sgttrf)(const ARint *n, float *dl, float *d, float *du, - float *du2, ARint *ipiv, ARint *info); - - void F77NAME(sgbtrf)(const ARint *m, const ARint *n, const ARint *kl, - const ARint *ku, float *ab, const ARint *ldab, - ARint *ipiv, ARint *info); - - void F77NAME(sgetrf)(const ARint *m, const ARint *n, float *A, - const ARint *lda, ARint *ipiv, ARint *info); - - void F77NAME(sgttrs)(const char* trans, const ARint *n, - const ARint *nrhs, const float *dl, - const float *d, const float *du, - const float *du2, const ARint *ipiv, - float* b, const ARint *ldb, ARint *info); - - void F77NAME(sgbtrs)(const char* trans, const ARint *n, - const ARint *kl, const ARint *ku, - const ARint *nrhs, const float *ab, - const ARint *ldab, const ARint *ipiv, - float *b, const ARint *ldb, ARint *info); - - void F77NAME(sgetrs)(const char* trans, const ARint *n, - const ARint *nrhs, const float *A, - const ARint *lda, const ARint *ipiv, - float* b, const ARint *ldb, ARint *info); - - void F77NAME(spttrf)(const ARint *n, float *d, float *e, ARint *info); - - void F77NAME(spttrs)(const ARint *n, const ARint *nrhs, - const float *d, const float *e, float *b, - const ARint *ldb, ARint *info); - - void F77NAME(ssptrf)(const char* trans, const ARint *n, - float *ap, ARint *ipiv, ARint *info); - - void F77NAME(ssptrs)(const char* trans, const ARint *n, - const ARint *nrhs, float *ap, ARint *ipiv, - float *b, const ARint *ldb, ARint *info); - - // Double precision real routines. - - double F77NAME(dlapy2)(const double *x, const double *y); - - void F77NAME(dlacpy)(const char* uplo, const ARint *m, const ARint *n, - const double *a, const ARint *lda, double *b, - const ARint *ldb); - - void F77NAME(dgttrf)(const ARint *n, double *dl, double *d, double *du, - double *du2, ARint *ipiv, ARint *info); - - void F77NAME(dgbtrf)(const ARint *m, const ARint *n, const ARint *kl, - const ARint *ku, double *ab, const ARint *ldab, - ARint *ipiv, ARint *info); - - void F77NAME(dgetrf)(const ARint *m, const ARint *n, double *A, - const ARint *lda, ARint *ipiv, ARint *info); - - void F77NAME(dgttrs)(const char* trans, const ARint *n, - const ARint *nrhs, const double *dl, - const double *d, const double *du, - const double *du2, const ARint *ipiv, - double* b, const ARint *ldb, ARint *info); - - void F77NAME(dgbtrs)(const char* trans, const ARint *n, - const ARint *kl, const ARint *ku, - const ARint *nrhs, const double *ab, - const ARint *ldab, const ARint *ipiv, - double *b, const ARint *ldb, ARint *info); - - void F77NAME(dgetrs)(const char* trans, const ARint *n, - const ARint *nrhs, const double *A, - const ARint *lda, const ARint *ipiv, - double* b, const ARint *ldb, ARint *info); - - void F77NAME(dpttrf)(const ARint *n, double *d, double *e, ARint *info); - - void F77NAME(dpttrs)(const ARint *n, const ARint *nrhs, - const double *d, const double *e, double *b, - const ARint *ldb, ARint *info); - - void F77NAME(dsptrf)(const char* trans, const ARint *n, - double *ap, ARint *ipiv, ARint *info); - - void F77NAME(dsptrs)(const char* trans, const ARint *n, - const ARint *nrhs, double *ap, ARint *ipiv, - double *b, const ARint *ldb, ARint *info); - -#ifdef ARCOMP_H - - // Single precision complex routines. - - void F77NAME(clacpy)(const char* uplo, const ARint *m, const ARint *n, - const arcomplex<float> *a, const ARint *lda, - arcomplex<float> *b, const ARint *ldb); - - void F77NAME(cgttrf)(const ARint *n, arcomplex<float> *dl, - arcomplex<float> *d, arcomplex<float> *du, - arcomplex<float> *du2, ARint *ipiv, - ARint *info); - - void F77NAME(cgbtrf)(const ARint *m, const ARint *n, const ARint *kl, - const ARint *ku, arcomplex<float> *ab, - const ARint *ldab, ARint *ipiv, ARint *info); - - void F77NAME(cgetrf)(const ARint *m, const ARint *n, arcomplex<float> *A, - const ARint *lda, ARint *ipiv, ARint *info); - - void F77NAME(cgttrs)(const char *trans, const ARint *n, - const ARint *nrhs, const arcomplex<float> *dl, - const arcomplex<float> *d, const arcomplex<float> *du, - const arcomplex<float> *du2, const ARint *ipiv, - arcomplex<float>* b, const ARint *ldb, - ARint *info); - - void F77NAME(cgbtrs)(const char* trans, const ARint *n, - const ARint *kl, const ARint *ku, - const ARint *nrhs, const arcomplex<float> *ab, - const ARint *ldab, const ARint *ipiv, - arcomplex<float> *b, const ARint *ldb, - ARint *info); - - void F77NAME(cgetrs)(const char* trans, const ARint *n, - const ARint *nrhs, const arcomplex<float> *A, - const ARint *lda, const ARint *ipiv, - arcomplex<float>* b, const ARint *ldb, ARint *info); - - // Double precision complex routines. - - void F77NAME(zlacpy)(const char* uplo, const ARint *m, const ARint *n, - const arcomplex<double> *a, const ARint *lda, - arcomplex<double> *b, const ARint *ldb); - - void F77NAME(zgttrf)(const ARint *n, arcomplex<double> *dl, - arcomplex<double> *d, arcomplex<double> *du, - arcomplex<double> *du2, ARint *ipiv, - ARint *info); - - void F77NAME(zgbtrf)(const ARint *m, const ARint *n, const ARint *kl, - const ARint *ku, arcomplex<double> *ab, - const ARint *ldab, ARint *ipiv, ARint *info); - - void F77NAME(zgetrf)(const ARint *m, const ARint *n, arcomplex<double> *A, - const ARint *lda, ARint *ipiv, ARint *info); - - void F77NAME(zgttrs)(const char *trans, const ARint *n, - const ARint *nrhs, const arcomplex<double> *dl, - const arcomplex<double> *d, const arcomplex<double> *du, - const arcomplex<double> *du2, const ARint *ipiv, - arcomplex<double>* b, const ARint *ldb, - ARint *info); - - void F77NAME(zgbtrs)(const char* trans, const ARint *n, - const ARint *kl, const ARint *ku, - const ARint *nrhs, const arcomplex<double> *ab, - const ARint *ldab, const ARint *ipiv, - arcomplex<double> *b, const ARint *ldb, - ARint *info); - - void F77NAME(zgetrs)(const char* trans, const ARint *n, - const ARint *nrhs, const arcomplex<double> *A, - const ARint *lda, const ARint *ipiv, - arcomplex<double>* b, const ARint *ldb, ARint *info); - -#endif // ARCOMP_H - - void F77NAME(second)(const float *T); - -} -#endif // LAPACKF_H - - - - - diff --git a/src/external/arpack++/include/naupp.h b/src/external/arpack++/include/naupp.h deleted file mode 100644 index d29b258c..00000000 --- a/src/external/arpack++/include/naupp.h +++ /dev/null @@ -1,333 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE naupp.h. - Interface to ARPACK subroutines dnaupd and snaupd. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef NAUPP_H -#define NAUPP_H - -#include <string> -#include "arch.h" -#include "arpackf.h" - -inline void naupp(ARint& ido, char bmat, ARint n, const std::string& which, ARint nev, - double& tol, double resid[], ARint ncv, double V[], - ARint ldv, ARint iparam[], ARint ipntr[], double workd[], - double workl[], ARint lworkl, ARint& info) - -/* - c++ version of ARPACK routine dnaupd that implements a variant of - the Arnoldi method. This routine computes approximations to a few - eigenpairs of a linear operator "OP" with respect to a semi-inner - product defined by a symmetric positive semi-definite real matrix - B. B may be the identity matrix. NOTE: If the linear operator "OP" - is real and symmetric with respect to the real positive semi-definite - symmetric matrix B, i.e. B*OP = (OP')*B, then subroutine saupp - should be used instead. - - The computed approximate eigenvalues are called Ritz values and - the corresponding approximate eigenvectors are called Ritz vectors. - - naupp is usually called iteratively to solve one of the - following problems: - - Mode 1: A*x = lambda*x. - ===> OP = A and B = I. - - Mode 2: A*x = lambda*M*x, M symmetric positive definite - ===> OP = inv[M]*A and B = M. - ===> (If M can be factored see remark 3 below) - - Mode 3: A*x = lambda*M*x, M symmetric semi-definite - ===> OP = Real_Part{ inv[A - sigma*M]*M } and B = M. - ===> shift-and-invert mode (in real arithmetic) - If OP*x = amu*x, then - amu = 1/2 * [ 1/(lambda-sigma) + 1/(lambda-conjg(sigma)) ]. - Note: If sigma is real, i.e. imaginary part of sigma is zero; - Real_Part{ inv[A - sigma*M]*M } == inv[A - sigma*M]*M - amu == 1/(lambda-sigma). - - Mode 4: A*x = lambda*M*x, M symmetric semi-definite - ===> OP = Imaginary_Part{ inv[A - sigma*M]*M } and B = M. - ===> shift-and-invert mode (in real arithmetic) - If OP*x = amu*x, then - amu = 1/2i * [ 1/(lambda-sigma) - 1/(lambda-conjg(sigma)) ]. - - Both mode 3 and 4 give the same enhancement to eigenvalues close to - the (complex) shift sigma. However, as lambda goes to infinity, - the operator OP in mode 4 dampens the eigenvalues more strongly than - does OP defined in mode 3. - - NOTE: The action of w <- inv[A - sigma*M]*v or w <- inv[M]*v should - be accomplished either by a direct method using a sparse matrix - factorization and solving - - [A - sigma*M]*w = v or M*w = v, - - or through an iterative method for solving these systems. If an - iterative method is used, the convergence test must be more - stringent than the accuracy requirements for the eigenvalue - approximations. - - Parameters: - - ido (Input / Output) Reverse communication flag. ido must be - zero on the first call to naupp. ido will be set - internally to indicate the type of operation to be - performed. Control is then given back to the calling - routine which has the responsibility to carry out the - requested operation and call naupp with the result. The - operand is given in workd[ipntr[1]], the result must be - put in workd[ipntr[2]]. - ido = 0: first call to the reverse communication interface. - ido = -1: compute Y = OP * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - This is for the initialization phase to force the - starting vector into the range of OP. - ido = 1: compute Y = OP * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - In mode 3 and 4, the vector B * X is already - available in workd[ipntr[3]]. It does not - need to be recomputed in forming OP * X. - ido = 2: compute Y = B * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - ido = 3: compute the iparam[8] real and imaginary parts - of the shifts where inptr[14] is the pointer - into workl for placing the shifts. See Remark - 5 below. - ido = 99: done. - bmat (Input) bmat specifies the type of the matrix B that defines - the semi-inner product for the operator OP. - bmat = 'I' -> standard eigenvalue problem A*x = lambda*x; - bmat = 'G' -> generalized eigenvalue problem A*x = lambda*M*x. - n (Input) Dimension of the eigenproblem. - nev (Input) Number of eigenvalues to be computed. 0 < nev < n-1. - which (Input) Specify which of the Ritz values of OP to compute. - 'LM' - compute the NEV eigenvalues of largest magnitude. - 'SM' - compute the NEV eigenvalues of smallest magnitude. - 'LR' - compute the NEV eigenvalues of largest real part. - 'SR' - compute the NEV eigenvalues of smallest real part. - 'LI' - compute the NEV eigenvalues of largest imaginary part. - 'SI' - compute the NEV eigenvalues of smallest imaginary part. - tol (Input) Stopping criterion: the relative accuracy of the - Ritz value is considered acceptable if BOUNDS[i] <= - tol*abs(RITZ[i]),where ABS(RITZ[i]) is the magnitude when - RITZ[i] is complex. If tol<=0.0 is passed, the machine - precision as computed by the LAPACK auxiliary subroutine - _LAMCH is used. - resid (Input / Output) Array of length n. - On input: - If info==0, a random initial residual vector is used. - If info!=0, resid contains the initial residual vector, - possibly from a previous run. - On output: - resid contains the final residual vector. - ncv (Input) Number of Arnoldi vectors that are generated at each - iteration. After the startup phase in which nev Arnoldi - vectors are generated, the algorithm generates ncv-nev - Arnoldi vectors at each subsequent update iteration. Most of - the cost in generating each Arnoldi vector is in the - matrix-vector product OP*x. - NOTE: 2 <= NCV-NEV in order that complex conjugate pairs of - Ritz values are kept together (see remark 4 below). - V (Output) Double precision array of length ncv*n+1. V contains - the ncv Arnoldi basis vectors. The first element V[0] is never - referenced. - ldv (Input) Dimension of the basis vectors contianed in V. This - parameter MUST be set to n. - iparam (Input / Output) Array of length 12. - iparam[1] = ISHIFT: method for selecting the implicit shifts. - The shifts selected at each iteration are used to restart - the Arnoldi iteration in an implicit fashion. - ------------------------------------------------------------- - ISHIFT = 0: the shifts are provided by the user via - reverse communication. The real and imaginary - parts of the NCV eigenvalues of the Hessenberg - matrix H are returned in the part of the WORKL - array corresponding to RITZR and RITZI. See remark - 5 below. - ISHIFT = 1: exact shifts with respect to the current - Hessenberg matrix H. This is equivalent to - restarting the iteration with a starting vector - that is a linear combination of approximate Schur - vectors associated with the "wanted" Ritz values. - ------------------------------------------------------------- - iparam[2] is no longer referenced. - iparam[3] = MXITER - On INPUT: maximum number of Arnoldi update iterations allowed. - On OUTPUT: actual number of Arnoldi update iterations taken. - iparam[4] = NB: blocksize to be used in the recurrence. - The code currently works only for NB = 1. - iparam[5] = NCONV: number of "converged" Ritz values. - This represents the number of Ritz values that satisfy - the convergence criterion. - iparam[6] is no longer referenced. - iparam[7] = MODE. On INPUT determines what type of - eigenproblem is being solved. Must be 1,2,3,4. - iparam[8] = NP. When ido = 3 and the user provides shifts - through reverse communication (iparam[1]=0), naupp returns - NP, the number of shifts the user is to provide. - 0 < NP <=ncv-nev. See Remark 5 below. - iparam[9] = total number of OP*x operations. - iparam[10] = total number of B*x operations if bmat='G'. - iparam[11] = total number of steps of re-orthogonalization. - ipntr (Output) Array of length 14. Pointer to mark the starting - locations in the workd and workl arrays for matrices/vectors - used by the Arnoldi iteration. - ipntr[1] : pointer to the current operand vector X in workd. - ipntr[2] : pointer to the current result vector Y in workd. - ipntr[3] : pointer to the vector B * X in workd when used in - the shift-and-invert mode. - ipntr[4] : pointer to the next available location in workl - that is untouched by the program. - ipntr[5] : pointer to the ncv by ncv upper Hessenberg matrix - H in workl. - ipntr[6] : pointer to the real part of the ritz value array - RITZR in workl. - ipntr[7] : pointer to the imaginary part of the ritz value - array RITZI in workl. - ipntr[8] : pointer to the Ritz estimates in array workl - associated with the Ritz values located in RITZR - and RITZI in workl. - ipntr[14]: pointer to the np shifts in workl. See Remark 6. - Note: ipntr[9:13] is only referenced by neupp. See Remark 2. - ipntr[9] : pointer to the real part of the ncv RITZ values of - the original system. - ipntr[10]: pointer to the imaginary part of the ncv RITZ values - of the original system. - ipntr[11]: pointer to the ncv corresponding error bounds. - ipntr[12]: pointer to the ncv by ncv upper quasi-triangular - Schur matrix for H. - ipntr[13]: pointer to the ncv by ncv matrix of eigenvectors - of the upper Hessenberg matrix H. Only referenced by - neupp if rvec == TRUE. See Remark 2 below. - workd (Input / Output) Array of length 3*N+1. - Distributed array to be used in the basic Arnoldi iteration - for reverse communication. The user should not use workd as - temporary workspace during the iteration. Upon termination - workd[1:n] contains B*resid[1:n]. If the Ritz vectors are - desired subroutine neupp uses this output. - workl (Output) Array of length lworkl+1. Private (replicated) array - on each PE or array allocated on the front end. - lworkl (Input) lworkl must be at least 3*ncv*(ncv+2). - info (Input / Output) On input, if info = 0, a randomly initial - residual vector is used, otherwise resid contains the initial - residual vector, possibly from a previous run. - On output, info works as a error flag: - = 0 : Normal exit. - = 1 : Maximum number of iterations taken. All possible - eigenvalues of OP has been found. iparam[5] - returns the number of wanted converged Ritz values. - = 3 : No shifts could be applied during a cycle of the - Implicitly restarted Arnoldi iteration. One - possibility is to increase the size of NCV relative - to nev. See remark 4 below. - = -1 : n must be positive. - = -2 : nev must be positive. - = -3 : ncv must satisfy nev+2 <= ncv <= n. - = -4 : The maximum number of Arnoldi update iterations - allowed must be greater than zero. - = -5 : which must be one of 'LM','SM','LR','SR','LI','SI'. - = -6 : bmat must be one of 'I' or 'G'. - = -7 : Length of private work array workl is not sufficient. - = -8 : Error return from LAPACK eigenvalue calculation. - = -9 : Starting vector is zero. - = -10 : iparam[7] must be 1,2,3,4. - = -11 : iparam[7] = 1 and bmat = 'G' are incompatible. - = -12 : iparam[1] must be equal to 0 or 1. - = -13 : nev and which = 'BE' are incompatible. - = -9999: Could not build an Arnoldi factorization. iparam[5] - returns the size of the current Arnoldi factorization. - The user is advised to check that enough workspace - and array storage has been allocated. - - Remarks: - 1. The computed Ritz values are approximate eigenvalues of OP. The - selection of "which" should be made with this in mind when - Mode = 3 and 4. After convergence, approximate eigenvalues of the - original problem may be obtained with the ARPACK subroutine neupp. - 2. If a basis for the invariant subspace corresponding to the converged - Ritz values is needed, the user must call neupp immediately following - completion of naupp. This is new starting with release 2 of ARPACK. - 3. If M can be factored into a Cholesky factorization M = LL' - then Mode = 2 should not be selected. Instead one should use - Mode = 1 with OP = inv(L)*A*inv(L'). Appropriate triangular - linear systems should be solved with L and L' rather - than computing inverses. After convergence, an approximate - eigenvector z of the original problem is recovered by solving - L'z = x where x is a Ritz vector of OP. - 4. At present there is no a-priori analysis to guide the selection - of ncv relative to nev. The only formal requrement is that ncv - >= nev+2. However, it is recommended that ncv >= 2*nev+1. If many - problems of the same type are to be solved, one should experiment - with increasing ncv while keeping ncv fixed for a given test - problem. This will usually decrease the required number of OP*x - operations but it also increases the work and storage required to - maintain the orthogonal basis vectors. The optimal "cross-over" - with respect to CPU time is problem dependent and must be - determined empirically. - 5. When iparam[1] = 0, and ido = 3, the user needs to provide the - NP = iparam[8] real and imaginary parts of the shifts in locations - real part imaginary part - ----------------------- -------------- - 1 workl[ipntr[14]] workl[ipntr[14]+NP] - 2 workl[ipntr[14]+1] workl[ipntr[14]+NP+1] - . . - . . - . . - NP workl[ipntr[14]+NP-1] workl[ipntr[14]+2*NP-1]. - - Only complex conjugate pairs of shifts may be applied and the pairs - must be placed in consecutive locations. The real part of the - eigenvalues of the current upper Hessenberg matrix are located in - workl[ipntr[6]] through workl[ipntr[6]+ncv-1] and the imaginary part - in workl[ipntr[7]] through workl[ipntr[7]+ncv-1]. They are ordered - according to the order defined by which. The complex conjugate pairs - are kept together and the associated Ritz estimates are located in - workl[ipntr[8]], workl[ipntr[8]+1], ... , workl[ipntr[8]+ncv-1]. -*/ - -{ - - F77NAME(dnaupd)(&ido, &bmat, &n, which.c_str(), &nev, &tol, resid, &ncv, - &V[1], &ldv, &iparam[1], &ipntr[1], &workd[1], &workl[1], - &lworkl, &info); - -} // naupp (double). - -inline void naupp(ARint& ido, char bmat, ARint n, const std::string& which, ARint nev, - float& tol, float resid[], ARint ncv, float V[], - ARint ldv, ARint iparam[], ARint ipntr[], float workd[], - float workl[], ARint lworkl, ARint& info) - -/* - c++ version of ARPACK routine snaupd. The only difference between - snaupd and dnaupd is that in the former function all vectors have - single precision elements and in the latter all vectors have double - precision elements. -*/ - -{ - - F77NAME(snaupd)(&ido, &bmat, &n, which.c_str(), &nev, &tol, resid, &ncv, - &V[1], &ldv, &iparam[1], &ipntr[1], &workd[1], &workl[1], - &lworkl, &info); - -} // naupp (float). - -#endif // NAUPP_H - diff --git a/src/external/arpack++/include/neupp.h b/src/external/arpack++/include/neupp.h deleted file mode 100644 index 2b102d77..00000000 --- a/src/external/arpack++/include/neupp.h +++ /dev/null @@ -1,270 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE neupp.h. - Interface to ARPACK subroutines dneupd and sneupd. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef NEUPP_H -#define NEUPP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arpackf.h" - -inline void neupp(bool rvec, char HowMny, double dr[], - double di[], double Z[], ARint ldz, double sigmar, - double sigmai, double workv[], char bmat, ARint n, - const std::string& which, ARint nev, double tol, double resid[], - ARint ncv, double V[], ARint ldv, ARint iparam[], - ARint ipntr[], double workd[], double workl[], - ARint lworkl, ARint& info) - -/* - c++ version of ARPACK routine dneupd. - This subroutine returns the converged approximations to eigenvalues - of A*z = lambda*B*z and (optionally): - - (1) the corresponding approximate eigenvectors, - (2) an orthonormal basis for the associated approximate - invariant subspace, - - There is negligible additional cost to obtain eigenvectors. An - orthonormal basis is always computed. There is an additional storage cost - of n*nev if both are requested (in this case a separate array Z must be - supplied). - The approximate eigenvalues and eigenvectors of A*z = lambda*B*z - are derived from approximate eigenvalues and eigenvectors of - of the linear operator OP prescribed by the MODE selection in the - call to naupp. naupp must be called before this routine is called. - These approximate eigenvalues and vectors are commonly called Ritz - values and Ritz vectors respectively. They are referred to as such - in the comments that follow. The computed orthonormal basis for the - invariant subspace corresponding to these Ritz values is referred to - as a Schur basis. - See documentation in the header of the subroutine naupp for - definition of OP as well as other terms and the relation of computed - Ritz values and Ritz vectors of OP with respect to the given problem - A*z = lambda*B*z. For a brief description, see definitions of - iparam[7], MODE and which in the documentation of naupp. - - Parameters: - - rvec (Input) Specifies whether Ritz vectors corresponding to the - Ritz value approximations to the eigenproblem A*z = lambda*B*z - are computed. - rvec = false: Compute Ritz values only. - rvec = true : Compute the Ritz vectors or Schur vectors. - See Remarks below. - HowMny (Input) Specifies the form of the basis for the invariant - subspace corresponding to the converged Ritz values that - is to be computed. - = 'A': Compute nev Ritz vectors; - = 'P': Compute nev Schur vectors; - dr (Output) Array of dimension nev+1. - If iparam[7] = 1,2 or 3 and sigmai=0.0 then on exit: dr - contains the real part of the Ritz approximations to the - eigenvalues of A*z = lambda*B*z. - If iparam[7] = 3, 4 and sigmai is not equal to zero, then on - exit: dr contains the real part of the Ritz values of OP - computed by naupp. A further computation must be performed by - the user to transform the Ritz values computed for OP by naupp - to those of the original system A*z = lambda*B*z. See remark 3. - di (Output) Array of dimension nev+1. - On exit, di contains the imaginary part of the Ritz value - approximations to the eigenvalues of A*z = lambda*B*z - associated with dr. - NOTE: When Ritz values are complex, they will come in complex - conjugate pairs. If eigenvectors are requested, the - corresponding Ritz vectors will also come in conjugate - pairs and the real and imaginary parts of these are - represented in two consecutive columns of the array Z - (see below). - Z (Output) Array of dimension nev*n if rvec = TRUE and HowMny = - 'A'. if rvec = TRUE. and HowMny = 'A', then the contains - approximate eigenvectors (Ritz vectors) corresponding to the - NCONV=iparam[5] Ritz values for eigensystem A*z = lambda*B*z. - The complex Ritz vector associated with the Ritz value - with positive imaginary part is stored in two consecutive - columns. The first column holds the real part of the Ritz - vector and the second column holds the imaginary part. The - Ritz vector associated with the Ritz value with negative - imaginary part is simply the complex conjugate of the Ritz - vector associated with the positive imaginary part. - If rvec = .FALSE. or HowMny = 'P', then Z is not referenced. - NOTE: If if rvec = .TRUE. and a Schur basis is not required, - the array Z may be set equal to first nev+1 columns of - the Arnoldi basis array V computed by naupp. In this - case the Arnoldi basis will be destroyed and overwritten - with the eigenvector basis. - ldz (Input) Dimension of the vectors contained in Z. This - parameter MUST be set to n. - sigmar (Input) If iparam[7] = 3 or 4, represents the real part of - the shift. Not referenced if iparam[7] = 1 or 2. - sigmai (Input) If iparam[7] = 3 or 4, represents the imaginary part - of the shift. Not referenced if iparam[7] = 1 or 2. See - remark 3 below. - workv (Workspace) Array of dimension 3*ncv. - V (Input/Output) Array of dimension n*ncv+1. - Upon Input: V contains the ncv vectors of the Arnoldi basis - for OP as constructed by naupp. - Upon Output: If rvec = TRUE the first NCONV=iparam[5] columns - contain approximate Schur vectors that span the - desired invariant subspace. See Remark 2 below. - NOTE: If the array Z has been set equal to first nev+1 columns - of the array V and rvec = TRUE. and HowMny = 'A', then - the Arnoldi basis held by V has been overwritten by the - desired Ritz vectors. If a separate array Z has been - passed then the first NCONV=iparam[5] columns of V will - contain approximate Schur vectors that span the desired - invariant subspace. - workl (Input / Output) Array of length lworkl+1. - workl[1:ncv*ncv+3*ncv] contains information obtained in - naupp. They are not changed by neupp. - workl[ncv*ncv+3*ncv+1:3*ncv*ncv+6*ncv] holds the real and - imaginary part of the untransformed Ritz values, the upper - quasi-triangular matrix for H, and the associated matrix - representation of the invariant subspace for H. - ipntr (Input / Output) Array of length 14. Pointer to mark the - starting locations in the workl array for matrices/vectors - used by naupp and neupp. - ipntr[9]: pointer to the real part of the ncv RITZ values - of the original system. - ipntr[10]: pointer to the imaginary part of the ncv RITZ - values of the original system. - ipntr[11]: pointer to the ncv corresponding error bounds. - ipntr[12]: pointer to the ncv by ncv upper quasi-triangular - Schur matrix for H. - ipntr[13]: pointer to the ncv by ncv matrix of eigenvectors - of the upper Hessenberg matrix H. Only referenced - by neupp if rvec = TRUE. See Remark 2 below. - info (Output) Error flag. - = 0 : Normal exit. - = 1 : The Schur form computed by LAPACK routine dlahqr - could not be reordered by LAPACK routine dtrsen. - Re-enter subroutine neupp with iparam[5] = ncv and - increase the size of the arrays DR and DI to have - dimension at least dimension ncv and allocate at least - ncv columns for Z. NOTE: Not necessary if Z and V share - the same space. Please notify the authors if this error - occurs. - = -1 : n must be positive. - = -2 : nev must be positive. - = -3 : ncv must satisfy nev+2 <= ncv <= n. - = -5 : which must be one of 'LM','SM','LR','SR','LI','SI'. - = -6 : bmat must be one of 'I' or 'G'. - = -7 : Length of private work workl array is not sufficient. - = -8 : Error return from calculation of a real Schur form. - Informational error from LAPACK routine dlahqr. - = -9 : Error return from calculation of eigenvectors. - Informational error from LAPACK routine dtrevc. - = -10: iparam[7] must be 1,2,3,4. - = -11: iparam[7] = 1 and bmat = 'G' are incompatible. - = -12: HowMny = 'S' not yet implemented - = -13: HowMny must be one of 'A' or 'P' if rvec = TRUE. - = -14: naupp did not find any eigenvalues to sufficient - accuracy. - - NOTE: The following arguments - - bmat, n, which, nev, tol, resid, ncv, V, ldv, iparam, - ipntr, workd, workl, lworkl, info - - must be passed directly to neupp following the last call - to naupp. These arguments MUST NOT BE MODIFIED between - the the last call to naupp and the call to neupp. - - Remarks - 1. Currently only HowMny = 'A' and 'P' are implemented. - 2. Schur vectors are an orthogonal representation for the basis of - Ritz vectors. Thus, their numerical properties are often superior. - Let X' denote the transpose of X. If rvec = .TRUE. then the - relationship A * V[:,1:iparam[5]] = V[:,1:iparam[5]] * T, and - V[:,1:iparam[5]]' * V[:,1:iparam[5]] = I are approximately satisfied. - Here T is the leading submatrix of order iparam[5] of the real - upper quasi-triangular matrix stored workl[ipntr[12]]. That is, - T is block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; - each 2-by-2 diagonal block has its diagonal elements equal and its - off-diagonal elements of opposite sign. Corresponding to each - 2-by-2 diagonal block is a complex conjugate pair of Ritz values. - The real Ritz values are stored on the diagonal of T. - 3. If iparam[7] = 3 or 4 and sigmai is not equal zero, then the user - must form the iparam[5] Rayleigh quotients in order to transform the - Ritz values computed by naupp for OP to those of A*z = lambda*B*z. - Set rvec = TRUE. and HowMny = 'A', and compute - Z[:,I]' * A * Z[:,I] if di[I] = 0. - If di[I] is not equal to zero and di[I+1] = - D[I], - then the desired real and imaginary parts of the Ritz value are - Z[:,I]' * A * Z[:,I] + Z[:,I+1]' * A * Z[:,I+1], - Z[:,I]' * A * Z[:,I+1] - Z[:,I+1]' * A * Z[:,I], respectively. - Another possibility is to set rvec = .true. and HowMny = 'P' and - compute V[:,1:iparam[5]]' * A * V[:,1:iparam[5]] and then an upper - quasi-triangular matrix of order iparam[5] is computed. See remark - 2 above. -*/ - -{ - - ARint irvec; - ARlogical* iselect; - double* iZ; - - irvec = (ARint) rvec; - iselect = new ARlogical[ncv]; - iZ = (Z == NULL) ? &V[1] : Z; - - F77NAME(dneupd)(&irvec, &HowMny, iselect, dr, di, iZ, &ldz, &sigmar, - &sigmai, &workv[1], &bmat, &n, which.c_str(), &nev, &tol, - resid, &ncv, &V[1], &ldv, &iparam[1], &ipntr[1], - &workd[1], &workl[1], &lworkl, &info); - - delete[] iselect; - -} // neupp (double). - -inline void neupp(bool rvec, char HowMny, float dr[], - float di[], float Z[], ARint ldz, float sigmar, - float sigmai, float workv[], char bmat, ARint n, - const std::string& which, ARint nev, float tol, float resid[], - ARint ncv, float V[], ARint ldv, ARint iparam[], - ARint ipntr[], float workd[], float workl[], - ARint lworkl, ARint& info) - -/* - c++ version of ARPACK routine sneupd. The only difference between - sneupd and dneupd is that in the former function all vectors have - single precision elements and in the latter all vectors have double - precision elements. -*/ - -{ - - ARint irvec; - ARlogical* iselect; - float* iZ; - - irvec = (ARint) rvec; - iselect = new ARlogical[ncv]; - iZ = (Z == NULL) ? &V[1] : Z; - - F77NAME(sneupd)(&irvec, &HowMny, iselect, dr, di, iZ, &ldz, &sigmar, - &sigmai, &workv[1], &bmat, &n, which.c_str(), &nev, &tol, - resid, &ncv, &V[1], &ldv, &iparam[1], &ipntr[1], - &workd[1], &workl[1], &lworkl, &info ); - - delete[] iselect; - -} // neupp (float). - -#endif // NEUPP_H - diff --git a/src/external/arpack++/include/saupp.h b/src/external/arpack++/include/saupp.h deleted file mode 100644 index a0c256cb..00000000 --- a/src/external/arpack++/include/saupp.h +++ /dev/null @@ -1,321 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE saupp.h. - Interface to ARPACK subroutines dsaupd and ssaupd. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef SAUPP_H -#define SAUPP_H - -#include <string> -#include "arch.h" -#include "arpackf.h" - -inline void saupp(ARint& ido, char bmat, ARint n, const std::string& which, ARint nev, - double& tol, double resid[], ARint ncv, double V[], - ARint ldv, ARint iparam[], ARint ipntr[], double workd[], - double workl[], ARint lworkl, ARint& info) - -/* - c++ version of ARPACK routine dsaupd that implements a variant of - the Lanczos method. This method has been designed to compute - approximations to a few eigenpairs of a linear operator OP that is - real and symmetric with respect to a real positive semi-definite - symmetric matrix B, i.e. - - B*OP = (OP')*B. - - where A' denotes transpose of A. In the standard eigenproblem B is - the identity matrix. Another way to express this condition is - - < x,OPy > = < OPx,y > where < z,w > = z'Bw. - - The computed approximate eigenvalues are called Ritz values and - the corresponding approximate eigenvectors are called Ritz vectors. - - saupp is usually called iteratively to solve one of the - following problems: - - Mode 1: A*x = lambda*x, A symmetric - ===> OP = A and B = I. - - Mode 2: A*x = lambda*M*x, A symmetric, M symmetric positive definite - ===> OP = inv[M]*A and B = M. - ===> (If M can be factored see remark 3 below) - - Mode 3: K*x = lambda*M*x, K symmetric, M symmetric positive semi-definite - ===> OP = (inv[K - sigma*M])*M and B = M. - ===> Shift-and-Invert mode - - Mode 4: K*x = lambda*KG*x, K symmetric positive semi-definite, - KG symmetric indefinite - ===> OP = (inv[K - sigma*KG])*K and B = K. - ===> Buckling mode - - Mode 5: A*x = lambda*M*x, A symmetric, M symmetric positive semi-definite - ===> OP = inv[A - sigma*M]*[A + sigma*M] and B = M. - ===> Cayley transformed mode - - NOTE: The action of w <- inv[A - sigma*M]*v or w <- inv[M]*v should be - accomplished either by a direct method using a sparse matrix - factorization and solving - - [A - sigma*M]*w = v or M*w = v, - - or through an iterative method for solving these systems. If an - iterative method is used, the convergence test must be more - stringent than the accuracy requirements for the eigenvalue - approximations. - - Parameters: - - ido (Input / Output) Reverse communication flag. ido must be - zero on the first call to saupp. ido will be set - internally to indicate the type of operation to be - performed. Control is then given back to the calling - routine which has the responsibility to carry out the - requested operation and call saupp with the result. The - operand is given in workd[ipntr[1]], the result must be - put in workd[ipntr[2]]. (If Mode = 2 see remark 5 below). - ido = 0: first call to the reverse communication interface. - ido = -1: compute Y = OP * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - This is for the initialization phase to force the - starting vector into the range of OP. - ido = 1: compute Y = OP * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - In mode 3,4 and 5, the vector B * X is already - available in workd[ipntr[3]]. It does not - need to be recomputed in forming OP * X. - ido = 2: compute Y = B * X where - ipntr[1] is the pointer into workd for X, - ipntr[2] is the pointer into workd for Y. - ido = 3: compute the iparam[8] shifts where - ipntr[11] is the pointer into workl for - placing the shifts. See remark 6 below. - ido = 99: done. - bmat (Input) bmat specifies the type of the matrix B that defines - the semi-inner product for the operator OP. - bmat = 'I' -> standard eigenvalue problem A*x = lambda*x; - bmat = 'G' -> generalized eigenvalue problem A*x = lambda*B*x. - n (Input) Dimension of the eigenproblem. - nev (Input) Number of eigenvalues to be computed. 0 < nev < n. - which (Input) Specify which of the Ritz values of OP to compute. - 'LA' - compute the nev largest (algebraic) eigenvalues. - 'SA' - compute the nev smallest (algebraic) eigenvalues. - 'LM' - compute the nev largest (in magnitude) eigenvalues. - 'SM' - compute the nev smallest (in magnitude) eigenvalues. - 'BE' - compute nev eigenvalues, half from each end of the - spectrum. When NEV is odd, compute one more from the - high end than from the low end. - (see remark 1 below) - tol (Input) Stopping criterion: the relative accuracy of the - Ritz value is considered acceptable if BOUNDS[i] <= - tol*abs(RITZ[i]). If tol<=0.0 is passed, the machine - precision as computed by the LAPACK auxiliary subroutine - _LAMCH is used. - resid (Input / Output) Array of length n. - On input: - If info==0, a random initial residual vector is used. - If info!=0, resid contains the initial residual vector, - possibly from a previous run. - On output: - resid contains the final residual vector. - ncv (Input) Number of Lanczos vectors that are generated at each - iteration. After the startup phase in which nev Lanczos - vectors are generated, the algorithm generates ncv-nev - Lanczos vectors at each subsequent update iteration. Most of - the cost in generating each Lanczos vector is in the - matrix-vector product OP*x. (See remark 4 below). - V (Output) Double precision array of length ncv*n+1. V contains - the ncv Lanczos basis vectors. The first element V[0] is never - referenced. - ldv (Input) Dimension of the basis vectors contianed in V. This - parameter MUST be set to n. - iparam (Input / Output) Array of length 12. - iparam[1] = ISHIFT: method for selecting the implicit shifts. - The shifts selected at each iteration are used to restart - the Arnoldi iteration in an implicit fashion. - ------------------------------------------------------------- - ISHIFT = 0: the shifts are provided by the user via - reverse communication. The NCV eigenvalues of - the current tridiagonal matrix T are returned in - the part of workl array corresponding to RITZ. - See remark 6 below. - ISHIFT = 1: exact shifts with respect to the reduced - tridiagonal matrix T. This is equivalent to - restarting the iteration with a starting vector - that is a linear combination of Ritz vectors - associated with the "wanted" Ritz values. - ------------------------------------------------------------- - iparam[2] is no longer referenced. - iparam[3] = MXITER - On INPUT: maximum number of Arnoldi update iterations allowed. - On OUTPUT: actual number of Arnoldi update iterations taken. - iparam[4] = NB: blocksize to be used in the recurrence. - The code currently works only for NB = 1. - iparam[5] = NCONV: number of "converged" Ritz values. - This represents the number of Ritz values that satisfy - the convergence criterion. - iparam[6] is no longer referenced. - iparam[7] = MODE. On INPUT determines what type of - eigenproblem is being solved. Must be 1,2,3,4,5. - iparam[8] = NP. When ido = 3 and the user provides shifts - through reverse communication (iparam[1]=0), saupp returns - NP, the number of shifts the user is to provide. - 0 < NP <=ncv-nev. See Remark 6 below. - iparam[9] = total number of OP*x operations. - iparam[10] = total number of B*x operations if bmat='G'. - iparam[11] = total number of steps of re-orthogonalization. - ipntr (Output) Array of length 12. Pointer to mark the starting - locations in the workd and workl arrays for matrices/vectors - used by the Lanczos iteration. - ipntr[1] : pointer to the current operand vector X in workd. - ipntr[2] : pointer to the current result vector Y in workd. - ipntr[3] : pointer to the vector B * X in workd when used in - the shift-and-invert mode. - ipntr[4] : pointer to the next available location in workl - that is untouched by the program. - ipntr[5] : pointer to the ncv by 2 tridiagonal matrix T in - workl. - ipntr[6] : pointer to the ncv RITZ values array in workl. - ipntr[7] : pointer to the Ritz estimates in array workl - associated with the Ritz values located in RITZ - in workl. - ipntr[11]: pointer to the np shifts in workl. See Remark 6. - Note: ipntr[8:10] is only referenced by seupp. See Remark 2. - ipntr[8] : pointer to the ncv RITZ values of the original - system. - ipntr[9] : pointer to the ncv corresponding error bounds. - ipntr[10]: pointer to the ncv by ncv matrix of eigenvectors - of the tridiagonal matrix T. Only referenced by - seupp if RVEC = TRUE. See Remarks. - workd (Input / Output) Array of length 3*N+1. - Distributed array to be used in the basic Arnoldi iteration - for reverse communication. The user should not use workd as - temporary workspace during the iteration. Upon termination - workd[1:n] contains B*resid[1:n]. If the Ritz vectors are - desired subroutine seupp uses this output. - workl (Output) Array of length lworkl+1. Private (replicated) array - on each PE or array allocated on the front end. - lworkl (Input) lworkl must be at least ncv*(ncv+8). - info (Input / Output) On input, if info = 0, a randomly initial - residual vector is used, otherwise resid contains the initial - residual vector, possibly from a previous run. - On output, info works as a error flag: - = 0 : Normal exit. - = 1 : Maximum number of iterations taken. All possible - eigenvalues of OP has been found. iparam[5] - returns the number of wanted converged Ritz values. - = 3 : No shifts could be applied during a cycle of the - Implicitly restarted Arnoldi iteration. One - possibility is to increase the size of NCV relative - to nev. See remark 4 below. - = -1 : n must be positive. - = -2 : nev must be positive. - = -3 : ncv must satisfy nev < ncv <= n. - = -4 : The maximum number of Arnoldi update iterations allowed - must be greater than zero. - = -5 : which must be one of 'LM', 'SM', 'LA', 'SA' or 'BE'. - = -6 : bmat must be one of 'I' or 'G'. - = -7 : Length of private work array workl is not sufficient. - = -8 : Error return from trid. eigenvalue calculation; - Informational error from LAPACK routine dsteqr. - = -9 : Starting vector is zero. - = -10 : iparam[7] must be 1,2,3,4,5. - = -11 : iparam[7] = 1 and bmat = 'G' are incompatible. - = -12 : iparam[1] must be equal to 0 or 1. - = -13 : nev and which = 'BE' are incompatible. - = -9999: Could not build an Arnoldi factorization. iparam[5] - returns the size of the current Arnoldi factorization. - The user is advised to check that enough workspace - and array storage has been allocated. - - Remarks: - 1. The converged Ritz values are always returned in ascending - algebraic order. The computed Ritz values are approximate - eigenvalues of OP. The selection of "which" should be made - with this in mind when Mode = 3,4,5. After convergence, - approximate eigenvalues of the original problem may be obtained - with the ARPACK subroutine seupp. - 2. If the Ritz vectors corresponding to the converged Ritz values are - needed, the user must call seupp immediately following completion - of saupp. This is new starting with version 2.1 of ARPACK. - 3. If M can be factored into a Cholesky factorization M = LL' - then Mode = 2 should not be selected. Instead one should use - Mode = 1 with OP = inv(L)*A*inv(L'). Appropriate triangular - linear systems should be solved with L and L' rather - than computing inverses. After convergence, an approximate - eigenvector z of the original problem is recovered by solving - L'z = x where x is a Ritz vector of OP. - 4. At present there is no a-priori analysis to guide the selection - of ncv relative to nev. The only formal requrement is that - ncv > nev. However, it is recommended that ncv >= 2*nev. If many - problems of the same type are to be solved, one should experiment - with increasing ncv while keeping nev fixed for a given test - problem. This will usually decrease the required number of OP*x - operations but it also increases the work and storage required to - maintain the orthogonal basis vectors. The optimal "cross-over" - with respect to CPU time is problem dependent and must be - determined empirically. - 5. If iparam[7] = 2 then in the Reverse commuication interface the - user must do the following. When ido = 1, Y = OP * X is to be - computed. When iparam[7] = 2 OP = inv(B)*A. After computing A*X - the user must overwrite X with A*X. Y is then the solution to the - linear set of equations B*Y = A*X. - 6. When iparam[1] = 0, and ido = 3, the user needs to provide the - NP = iparam[8] shifts in locations: - 1 workl[ipntr[11]] - 2 workl[ipntr[11]+1] - . - . - . - NP workl[ipntr[11]+NP-1]. - The eigenvalues of the current tridiagonal matrix are located in - workl[ipntr[6]] through workl[ipntr[6]+ncv]. They are in the - order defined by which. The associated Ritz estimates are located in - workl[ipntr[8]], workl[ipntr[8]+1], ... , workl[ipntr[8]+ncv-1]. -*/ - -{ - - F77NAME(dsaupd)(&ido, &bmat, &n, which.c_str(), &nev, &tol, resid, &ncv, - &V[1], &ldv, &iparam[1], &ipntr[1], &workd[1], &workl[1], - &lworkl, &info); - -} // saupp (double). - -inline void saupp(ARint& ido, char bmat, ARint n, const std::string& which, ARint nev, - float& tol, float resid[], ARint ncv, float V[], - ARint ldv, ARint iparam[], ARint ipntr[], float workd[], - float workl[], ARint lworkl, ARint& info) - -/* - c++ version of ARPACK routine ssaupd. The only difference between - ssaupd and dsaupd is that in the former function all vectors have - single precision elements and in the latter all vectors have double - precision elements. -*/ - -{ - - F77NAME(ssaupd)(&ido, &bmat, &n, which.c_str(), &nev, &tol, resid, &ncv, - &V[1], &ldv, &iparam[1], &ipntr[1], &workd[1], &workl[1], - &lworkl, &info); - -} // saupp (float). - -#endif // SAUPP_H - diff --git a/src/external/arpack++/include/seupp.h b/src/external/arpack++/include/seupp.h deleted file mode 100644 index 5e5c6051..00000000 --- a/src/external/arpack++/include/seupp.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE seupp.h. - Interface to ARPACK subroutines dseupd and sseupd. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef SEUPP_H -#define SEUPP_H - -#include <cstddef> -#include <string> -#include "arch.h" -#include "arpackf.h" - -inline void seupp(bool rvec, char HowMny, double d[], double Z[], - ARint ldz, double sigma, char bmat, ARint n, - const std::string& which, ARint nev, double tol, double resid[], - ARint ncv, double V[], ARint ldv, ARint iparam[], - ARint ipntr[], double workd[], double workl[], - ARint lworkl, ARint& info) - -/* - c++ version of ARPACK routine dseupd. - This subroutine returns the converged approximations to eigenvalues - of A*z = lambda*B*z and (optionally): - - (1) the corresponding approximate eigenvectors, - (2) an orthonormal (Lanczos) basis for the associated approximate - invariant subspace, - - There is negligible additional cost to obtain eigenvectors. An orthonormal - (Lanczos) basis is always computed. There is an additional storage cost - of n*nev if both are requested (in this case a separate array Z must be - supplied). - These quantities are obtained from the Lanczos factorization computed - by saupp for the linear operator OP prescribed by the MODE selection - (see IPARAM[7] in saupp documentation). saupp must be called before - this routine is called. These approximate eigenvalues and vectors are - commonly called Ritz values and Ritz vectors respectively. They are - referred to as such in the comments that follow. The computed orthonormal - basis for the invariant subspace corresponding to these Ritz values is - referred to as a Lanczos basis. - See documentation in the header of the subroutine dsaupp for a definition - of OP as well as other terms and the relation of computed Ritz values - and vectors of OP with respect to the given problem A*z = lambda*B*z. - The approximate eigenvalues of the original problem are returned in - ascending algebraic order. The user may elect to call this routine - once for each desired Ritz vector and store it peripherally if desired. - There is also the option of computing a selected set of these vectors - with a single call. - - Parameters: - - rvec (Input) Specifies whether Ritz vectors corresponding to the - Ritz value approximations to the eigenproblem A*z = lambda*B*z - are computed. - rvec = false: Compute Ritz values only. - rvec = true : Compute Ritz vectors. - HowMny (Input) Specifies how many Ritz vectors are wanted and the - form of Z, the matrix of Ritz vectors. See remark 1 below. - The only option already implemented is HowMny = 'A'. - d (Output) Array of dimension nev. On exit, d contains the Ritz - value approximations to the eigenvalues of A*z = lambda*B*z. - The values are returned in ascending order. If iparam[7] = - 3, 4, 5 then d represents the Ritz values of OP computed by - dsaupp transformed to those of the original eigensystem A*z = - lambda*B*z. If iparam[7] = 1,2 then the Ritz values of OP are - the same as the those of A*z = lambda*B*z. - Z (Output) Array of dimension nev*n if HowMny = 'A'. On - exit, Z contains the B-orthonormal Ritz vectors of the - eigensystem A*z = lambda*B*z corresponding to the Ritz value - approximations. If rvec = false then Z is not referenced. - NOTE: The array Z may be set equal to first nev columns of - the Arnoldi/Lanczos basis array V computed by dsaupp. - ldz (Input) Dimension of the vectors contained in Z. This - parameter MUST be set to n. - sigma (Input) If iparam[7] = 3,4,5 represents the shift. Not - referenced if iparam[7] = 1 or 2. - workl (Input / Output) Array of length lworkl+1. - workl[1:4*ncv] contains information obtained in saupp. - They are not changed by seupp. workl[4*ncv+1:ncv*(ncv+8)] - holds the untransformed Ritz values, the computed error - estimates, and the associated eigenvector matrix of H. - Note: ipntr[8:10] contains the pointer into workl for - addresses of the above information computed by seupp. - ipntr (Input / Output) Array of length 12. Pointer to mark the - starting locations in the workl array for matrices/vectors - used by dsaupp and seupp. - ipntr[8] : pointer to the RITZ values of the original system. - ipntr[9] : pointer to the ncv corresponding error bounds. - ipntr[10]: pointer to the ncv by ncv matrix of eigenvectors - of the tridiagonal matrix T. Only referenced by - seupp if rvec = true. See Remarks. - info (Output) Error flag. - = 0 : Normal exit. - = -1 : n must be positive. - = -2 : nev must be positive. - = -3 : ncv must satisfy nev < ncv <= n. - = -5 : which must be one of 'LM', 'SM', 'LA', 'SA' or 'BE'. - = -6 : bmat must be one of 'I' or 'G'. - = -7 : Length of private work workl array is not sufficient. - = -8 : Error return from trid. eigenvalue calculation; - Information error from LAPACK routine dsteqr. - = -9 : Starting vector is zero. - = -10: iparam[7] must be 1,2,3,4,5. - = -11: iparam[7] = 1 and bmat = 'G' are incompatible. - = -12: nev and which = 'BE' are incompatible. - = -14: dsaupp did not find any eigenvalues to sufficient - accuracy. - = -15: HowMny must be one of 'A' or 'S' if rvec = true. - = -16: HowMny = 'S' not yet implemented. - - NOTE: The following arguments - - bmat, n, which, nev, tol, resid, ncv, V, ldv, iparam, - ipntr, workd, workl, lworkl, info - - must be passed directly to seupp following the last call - to saupp. These arguments MUST NOT BE MODIFIED between - the the last call to saupp and the call to seupp. - - Remarks - 1. The converged Ritz values are always returned in increasing - (algebraic) order. - 2. Currently only HowMny = 'A' is implemented. It is included at - this stage for the user who wants to incorporate it. -*/ - -{ - - ARint irvec; - ARlogical* iselect; - double* iZ; - - irvec = (ARint) rvec; - iselect = new ARlogical[ncv]; - iZ = (Z == NULL) ? &V[1] : Z; - - F77NAME(dseupd)(&irvec, &HowMny, iselect, d, iZ, &ldz, &sigma, &bmat, - &n, which.c_str(), &nev, &tol, resid, &ncv, &V[1], &ldv, &iparam[1], - &ipntr[1], &workd[1], &workl[1], &lworkl, &info ); - - delete[] iselect; - -} // seupp (double). - -inline void seupp(bool rvec, char HowMny, float d[], float Z[], - ARint ldz, float sigma, char bmat, ARint n, - const std::string& which, ARint nev, float tol, float resid[], - ARint ncv, float V[], ARint ldv, ARint iparam[], - ARint ipntr[], float workd[], float workl[], - ARint lworkl, ARint& info) - -/* - c++ version of ARPACK routine sseupd. The only difference between - sseupd and dseupd is that in the former function all vectors have - single precision elements and in the latter all vectors have double - precision elements. -*/ - -{ - - ARint irvec; - ARlogical* iselect; - float* iZ; - - irvec = (ARint) rvec; - iselect = new ARlogical[ncv]; - iZ = (Z == NULL) ? &V[1] : Z; - - F77NAME(sseupd)(&irvec, &HowMny, iselect, d, iZ, &ldz, &sigma, &bmat, - &n, which.c_str(), &nev, &tol, resid, &ncv, &V[1], &ldv, &iparam[1], - &ipntr[1], &workd[1], &workl[1], &lworkl, &info ); - - delete[] iselect; - -} // seupp (float). - -#endif // SEUPP_H - diff --git a/src/external/arpack++/include/superluc.h b/src/external/arpack++/include/superluc.h deleted file mode 100644 index cdc7085d..00000000 --- a/src/external/arpack++/include/superluc.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE SuperLUc.h. - Interface to SuperLU routines. - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef SUPERLUC_H -#define SUPERLUC_H - -#include "arch.h" -#include "arlspdef.h" -#include "arlsupm.h" -#include "arlcomp.h" - -// gstrf. - -inline void gstrf(superlu_options_t *options, SuperMatrix *A, - int relax, int panel_size, int *etree, void *work, int lwork, - int *perm_c, int *perm_r, SuperMatrix *L, SuperMatrix *U, - SuperLUStat_t *stat, int *info) -{ - if (A->Dtype == SLU_D) { // calling the double precision routine. - dGlobalLU_t Glu; - dgstrf(options,A,relax, - panel_size,etree,work,lwork,perm_c,perm_r,L,U,&Glu,stat,info); - } - else if (A->Dtype == SLU_S) { // calling the single precision routine. - sGlobalLU_t Glu; - sgstrf(options,A,relax, - panel_size,etree,work,lwork,perm_c,perm_r,L,U,&Glu,stat,info); - } - else if (A->Dtype == SLU_Z) { // calling the double precision complex routine. -#ifdef ARCOMP_H - zGlobalLU_t Glu; - zgstrf(options,A,relax, - panel_size,etree,work,lwork,perm_c,perm_r,L,U,&Glu,stat,info); -#endif - } - else { // calling the single precision complex routine. -#ifdef ARCOMP_H - cGlobalLU_t Glu; - cgstrf(options,A,relax, - panel_size,etree,work,lwork,perm_c,perm_r,L,U,&Glu,stat,info); -#endif - } - -} // gstrf. - - -inline void gstrs(trans_t trans, SuperMatrix *L, SuperMatrix *U, - int *perm_c, int *perm_r, SuperMatrix *B, SuperLUStat_t* stat, int *info) -{ - - if (L->Dtype == SLU_D) { // calling the double precision routine. - dgstrs(trans,L,U,perm_c,perm_r,B,stat,info); - } - else if (L->Dtype == SLU_S) { // calling the single precision routine. - sgstrs(trans,L,U,perm_c,perm_r,B,stat,info); - } - else if (L->Dtype == SLU_Z) { // calling the double precision complex routine. -#ifdef ARCOMP_H - zgstrs(trans,L,U,perm_c,perm_r,B,stat,info); -#endif - } - else { // calling the single precision complex routine. -#ifdef ARCOMP_H - cgstrs(trans,L,U,perm_c,perm_r,B,stat,info); -#endif - } - -} // gstrs. - - -// Create_CompCol_Matrix. - -inline void Create_CompCol_Matrix(SuperMatrix* A, int m, int n, int nnz, - double* a, int* irow, int* pcol, - Stype_t S, Mtype_t M) -{ - - dCreate_CompCol_Matrix(A,m,n,nnz,a,irow,pcol,S,SLU_D,M); - -} // Create_CompCol_Matrix (double). - -inline void Create_CompCol_Matrix(SuperMatrix* A, int m, int n, int nnz, - float* a, int* irow, int* pcol, - Stype_t S, Mtype_t M) -{ - - sCreate_CompCol_Matrix(A,m,n,nnz,a,irow,pcol,S,SLU_S,M); - -} // Create_CompCol_Matrix (float). - -#ifdef ARCOMP_H - -inline void Create_CompCol_Matrix(SuperMatrix* A, int m, int n, int nnz, - arcomplex<double>* a, int* irow, int* pcol, - Stype_t S, Mtype_t M) -{ - - zCreate_CompCol_Matrix(A,m,n,nnz,(ldcomplex*)a,irow,pcol,S,SLU_Z,M); - -} // Create_CompCol_Matrix (complex<double>). - -inline void Create_CompCol_Matrix(SuperMatrix* A, int m, int n, int nnz, - arcomplex<float>* a, int* irow, int* pcol, - Stype_t S, Mtype_t M) -{ - - cCreate_CompCol_Matrix(A,m,n,nnz,(lscomplex*)a,irow,pcol,S,SLU_C,M); - -} // Create_CompCol_Matrix (complex<float>). - -#endif // ARCOMP_H. - - -// Create_Dense_Matrix. - -inline void Create_Dense_Matrix(SuperMatrix* A, int m, int n, double* x, - int ldx, Stype_t S, Mtype_t M) -{ - - dCreate_Dense_Matrix(A,m,n,x,ldx,S,SLU_D,M); - -} // Create_Dense_Matrix (double). - -inline void Create_Dense_Matrix(SuperMatrix* A, int m, int n, float* x, - int ldx, Stype_t S, Mtype_t M) -{ - - sCreate_Dense_Matrix(A,m,n,x,ldx,S,SLU_S,M); - -} // Create_Dense_Matrix (float). - -#ifdef ARCOMP_H - -inline void Create_Dense_Matrix(SuperMatrix* A, int m, int n, arcomplex<double>* x, - int ldx, Stype_t S, Mtype_t M) -{ - - zCreate_Dense_Matrix(A,m,n,(ldcomplex*)x,ldx,S,SLU_Z,M); - -} // Create_Dense_Matrix (complex<double>). - -inline void Create_Dense_Matrix(SuperMatrix* A, int m, int n, arcomplex<float>* x, - int ldx, Stype_t S, Mtype_t M) -{ - - cCreate_Dense_Matrix(A,m,n,(lscomplex*)x,ldx,S,SLU_C,M); - -} // Create_Dense_Matrix (complex<float>). - -#endif // ARCOMP_H. - -#endif // SUPERLUC_H diff --git a/src/external/arpack++/include/umfpackc.h b/src/external/arpack++/include/umfpackc.h deleted file mode 100644 index 8c084ad0..00000000 --- a/src/external/arpack++/include/umfpackc.h +++ /dev/null @@ -1,216 +0,0 @@ -/* - ARPACK++ v1.2 2/20/2000 - c++ interface to ARPACK code. - - MODULE UMFPACKc.h. - Interface to UMFPACK routines. - - Author of this class: - Martin Reuter - Date 2/28/2013 - - Arpack++ Author: - Francisco Gomes - - ARPACK Authors - Richard Lehoucq - Danny Sorensen - Chao Yang - Dept. of Computational & Applied Mathematics - Rice University - Houston, Texas -*/ - -#ifndef UMFPACKC_H -#define UMFPACKC_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define UMFPACK_INFO 90 -#define UMFPACK_CONTROL 20 -#define UMFPACK_OK (0) -#define UMFPACK_A (0) /* Ax=b */ -#define UMFPACK_PRL 0 /* print level */ - -void umfpack_di_defaults -( - double Control [UMFPACK_CONTROL] -) ; - - -int umfpack_di_symbolic -( - int n_row, - int n_col, - const int Ap [ ], - const int Ai [ ], - const double Ax [ ], - void **Symbolic, - const double Control [UMFPACK_CONTROL], - double Info [UMFPACK_INFO] -) ; - -int umfpack_di_numeric -( - const int Ap [ ], - const int Ai [ ], - const double Ax [ ], - void *Symbolic, - void **Numeric, - const double Control [UMFPACK_CONTROL], - double Info [UMFPACK_INFO] -) ; - -void umfpack_di_free_symbolic -( - void **Symbolic -) ; - -void umfpack_di_free_numeric -( - void **Numeric -) ; - -int umfpack_di_triplet_to_col -( - int n_row, - int n_col, - int nz, - const int Ti [ ], - const int Tj [ ], - const double Tx [ ], - int Ap [ ], - int Ai [ ], - double Ax [ ], - int Map [ ] -) ; - -int umfpack_di_solve -( - int sys, - const int Ap [ ], - const int Ai [ ], - const double Ax [ ], - double X [ ], - const double B [ ], - void *Numeric, - const double Control [UMFPACK_CONTROL], - double Info [UMFPACK_INFO] -) ; - -int umfpack_di_report_matrix -( - int n_row, - int n_col, - const int Ap [ ], - const int Ai [ ], - const double Ax [ ], - int col_form, - const double Control [UMFPACK_CONTROL] -) ; - -#ifdef __cplusplus - } -#endif - -//#include "umfpack.h" -#include <fstream> - -inline void Write_Triplet_Matrix(const std::string & fname, int * tripi, - int * tripj, double* tripx, unsigned int nnz) -{ - std::ofstream myfile; - myfile.open ( fname.c_str() ); - myfile.precision(20); - for (unsigned int i=0;i<nnz;i++) - { - myfile << tripi[i]+1 << " " << tripj[i]+1 << " " << tripx[i] << std::endl; - } - myfile.close(); -} - -/*inline void Write_Cholmod_Sparse_Matrix(const std::string & fname, - cholmod_sparse* A, cholmod_common *c) -{ - std::ofstream myfile; - myfile.open ( fname.c_str() ); - cholmod_triplet * T = cholmod_sparse_to_triplet(A,c); - //std::cout << " [ " << std::endl; - myfile.precision(20); - for (unsigned int i=0;i<T->nnz;i++) - { - myfile << ((int*)T->i)[i]+1 << " " << ((int*)T->j)[i]+1 << " " << ((double*)T->x)[i] << std::endl; - } - //std::cout << " ] " << std::endl; - myfile.close(); - - cholmod_free_triplet(&T,c); - -} - -// Create_Cholmod_Sparse_Matrix -inline cholmod_sparse* Create_Cholmod_Sparse_Matrix(int m, int n, int nnz, - double* a, int* irow, int* pcol, char uplo, cholmod_common *c) -{ - - cholmod_sparse* A = new cholmod_sparse; - A->nrow = m; - A->ncol = n; - A->nzmax = nnz; - A->p = pcol; - A->i = irow; - A->nz = NULL; - A->x = a; - A->z = NULL; - if (uplo == 'L') A->stype = -1; - else A->stype = 1; - A->itype = CHOLMOD_INT; - A->xtype = CHOLMOD_REAL; // real - A->dtype = CHOLMOD_DOUBLE; // double - A->sorted = 0; - A->packed = 1; - - return A; - - - - -} // Create_Cholmod_Sparse_Matrix (double). - -// Create_Cholmod_Dense_Matrix (from Triplet) -inline cholmod_dense* Create_Cholmod_Dense_Matrix(int m, int n, - double* a, cholmod_common *c) -{ - - - cholmod_dense* A = new cholmod_dense; - A->nrow = m; - A->ncol = n; - A->nzmax = m*n; - A->d = m; - A->x = a; - A->z = NULL; - A->xtype = CHOLMOD_REAL; // real - A->dtype = CHOLMOD_DOUBLE; // double - -// cholmod_dense* As = cholmod_copy_dense(A,c); - - return A; - -} // Create_Cholmod_Dense_Matrix (double). - -// Create_Cholmod_Dense_Matrix (from Triplet) -inline void Get_Cholmod_Dense_Data(cholmod_dense* A, int n, double* a) -{ - memcpy(a,A->x,n*sizeof(double)); - -// for (int i = 0;i<n;i++) -// a[i] = ((double*)A->x)[i]; - -} // Create_Cholmod_Dense_Matrix (double). - -*/ - -#endif // UMFPACKC_H diff --git a/src/external/cmake-files/Boost.cmake b/src/external/cmake-files/Boost.cmake deleted file mode 100644 index 48dad5e6..00000000 --- a/src/external/cmake-files/Boost.cmake +++ /dev/null @@ -1,36 +0,0 @@ -set(BOOST_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}) -function(GetBoost) - find_path(BOOST_DIR NAMES boost PATHS ${BOOST_CMAKE_DIR}/../_deps/boost-src) - - if (NOT BOOST_DIR) - - set(BOOST_URL "https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2" CACHE STRING "Boost download URL") - set(BOOST_URL_SHA256 "f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41" CACHE STRING "Boost download URL SHA256 checksum") - - include(FetchContent) - set(FETCHCONTENT_BASE_DIR "${BOOST_CMAKE_DIR}/../_deps") - FetchContent_Declare( - Boost - URL ${BOOST_URL} - URL_HASH SHA256=${BOOST_URL_SHA256} - ) - FetchContent_GetProperties(Boost) - - if(NOT Boost_POPULATED) - message(STATUS "Fetching Boost") - FetchContent_Populate(Boost) - message(STATUS "Fetching Boost - done") - set(BOOST_DIR ${boost_SOURCE_DIR}) - endif() - - message(STATUS "Using downloaded Boost library at ${BOOST_DIR}") - - else () - message(STATUS "Boost Library found: ${BOOST_DIR}") - - endif() - - include_directories(${BOOST_DIR}) - include_directories(${BOOST_DIR}/boost) - -endfunction() diff --git a/src/external/cmake-files/Eigen.cmake b/src/external/cmake-files/Eigen.cmake deleted file mode 100644 index 974a6f18..00000000 --- a/src/external/cmake-files/Eigen.cmake +++ /dev/null @@ -1,32 +0,0 @@ -set(EIGEN_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}) -function(GetEigen) - find_path(EIGEN_DIR NAMES Eigen PATHS ${EIGEN_CMAKE_DIR}/../_deps/eigen-src) - - if (NOT EIGEN_DIR) - include(FetchContent) - set(FETCHCONTENT_BASE_DIR "${EIGEN_CMAKE_DIR}/../_deps") - FetchContent_Declare( - eigen - GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git - GIT_TAG 3.4.0 - ) - - FetchContent_GetProperties(eigen) - - if(NOT eigen_POPULATED) - message(STATUS "Eigen library not found locally, downloading it.") - FetchContent_Populate(eigen) - endif() - - set(EIGEN_DIR ${eigen_SOURCE_DIR}) - message(STATUS "Using downloaded Eigen library at: ${EIGEN_DIR}") - - else () - - message(STATUS "Eigen Library found: ${EIGEN_DIR}") - - endif() - - include_directories(${EIGEN_DIR}) - -endfunction() diff --git a/src/external/cmake-files/LPSolve.cmake b/src/external/cmake-files/LPSolve.cmake deleted file mode 100644 index b3f3cf98..00000000 --- a/src/external/cmake-files/LPSolve.cmake +++ /dev/null @@ -1,32 +0,0 @@ -set(LP_SOLVE_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}) -function(GetLPSolve) - find_path(LP_SOLVE_DIR NAMES lpsolve.h PATHS ${LP_SOLVE_CMAKE_DIR}/../_deps/lpsolve-src) - - if (NOT LP_SOLVE_DIR) - include(FetchContent) - set(FETCHCONTENT_BASE_DIR "${LP_SOLVE_CMAKE_DIR}/../_deps") - FetchContent_Declare( - lpsolve - URL https://webwerks.dl.sourceforge.net/project/lpsolve/lpsolve/5.5.2.11/lp_solve_5.5.2.11_source.tar.gz - URL_HASH MD5=a829a8d9c60ff81dc72ff52363703886 - ) - - FetchContent_GetProperties(lpsolve) - - if(NOT lpsolve_POPULATED) - message(STATUS "lp_solve library not found locally, downloading it.") - FetchContent_Populate(lpsolve) - endif() - - set(LP_SOLVE_DIR "${lpsolve_SOURCE_DIR}") - message(STATUS "Using downloaded lp_solve at: ${LP_SOLVE_DIR}") - - else() - - message(STATUS "lp_solve library found: ${LP_SOLVE_DIR}") - - endif() - - include_directories(${LP_SOLVE_DIR}) - -endfunction() diff --git a/src/external/cmake-files/QD.cmake b/src/external/cmake-files/QD.cmake deleted file mode 100644 index b65e4f51..00000000 --- a/src/external/cmake-files/QD.cmake +++ /dev/null @@ -1,54 +0,0 @@ -set(QD_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}) -function(GetQD) - find_path(QD_DIR NAMES config.h PATHS ${QD_CMAKE_DIR}/../_deps/qd-src/) - - if (NOT QD_DIR) - include(FetchContent) - set(FETCHCONTENT_BASE_DIR "${QD_CMAKE_DIR}/../_deps") - FetchContent_Declare( - qd - URL https://www.davidhbailey.com/dhbsoftware/qd-2.3.23.tar.gz - ) - - FetchContent_GetProperties(qd) - - if(NOT qd_POPULATED) - message(STATUS "QD library not found locally, downloading it.") - FetchContent_Populate(qd) - endif() - - set(QD_DIR "${qd_SOURCE_DIR}") - message(STATUS "Using downloaded QD at: ${QD_DIR}") - - else() - - message(STATUS "QD library found: ${QD_DIR}") - - endif() - - include_directories(BEFORE "${QD_DIR}/include/") - message(STATUS "configuring the QD library") - execute_process( - COMMAND ./configure - WORKING_DIRECTORY ${QD_DIR} - OUTPUT_FILE CMD_OUTPUT - RESULT_VARIABLE EXECUTE - ) - if(NOT ${EXECUTE} EQUAL "0") - message(FATAL_ERROR "./configure QD library failed") - endif() - - execute_process( - COMMAND make - WORKING_DIRECTORY ${QD_DIR} - OUTPUT_FILE qd_compilation.txt - RESULT_VARIABLE EXECUTE_MAKE - ) - - if(NOT ${EXECUTE_MAKE} EQUAL "0") - message(FATAL_ERROR "building the QD library failed") - endif() - - find_library(QD_LIB NAMES libqd.a PATHS "${QD_DIR}/src/.libs") - -endfunction() diff --git a/src/external/minimum_ellipsoid/bnmin_main.h b/src/external/minimum_ellipsoid/bnmin_main.h deleted file mode 100644 index fec751a2..00000000 --- a/src/external/minimum_ellipsoid/bnmin_main.h +++ /dev/null @@ -1,87 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis - -// This file is converted from BNMin1 (https://www.mrao.cam.ac.uk/~bn204/oof/bnmin1.html) by Apostolos Chalkis - -// Original copyright notice: - -/** - Bojan Nikolic <bojan@bnikolic.co.uk> - Initial version 2008 - - This file is part of BNMin1 and is licensed under GNU General - Public License version 2. - - \file bnmin_main.cxx - -*/ -#ifndef BNMIN_MAIN_H -#define BNMIN_MAIN_H - -#include <string> -#include <stdexcept> - -#include <boost/format.hpp> - -//#include "bnmin_main1.h" -//#include "config.h" - -//namespace Minim { - - inline const char * version(void) - { - //return PACKAGE_VERSION; - return "11"; - } - - class BaseErr: - public std::runtime_error - { - public: - BaseErr(const std::string &s): - std::runtime_error(s) - { - } - - }; - - class NParsErr: - public BaseErr - { - public: - NParsErr(const std::string &fname, - size_t expected, - size_t received): - BaseErr( (boost::format("In function %s expected %i but received %i pars ") - % fname - % expected - % received).str()) - { - } - - - }; - - /*BaseErr::BaseErr(const std::string &s): - std::runtime_error(s) - { - } - - NParsErr::NParsErr(const std::string &fname, - size_t expected, - size_t received): - BaseErr( (boost::format("In function %s expected %i but received %i pars ") - % fname - % expected - % received).str()) - { - }*/ - - -#endif - -//} - - diff --git a/src/external/minimum_ellipsoid/khach.h b/src/external/minimum_ellipsoid/khach.h deleted file mode 100644 index 7718673a..00000000 --- a/src/external/minimum_ellipsoid/khach.h +++ /dev/null @@ -1,220 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis - -// This file is converted from BNMin1 (https://www.mrao.cam.ac.uk/~bn204/oof/bnmin1.html) by Apostolos Chalkis - -// Original copyright notice: - -/** - Bojan Nikolic <bojan@bnikolic.co.uk> - Initial version 2010 - - This file is part of BNMin1 and is licensed under GNU General - Public License version 2 - - \file ellipsoids.cxx - - Computation and use of ellipsoids releated to sets of points -*/ -#ifndef KHACH_H -#define KHACH_H - -#include <set> -#include <iostream> -#include <Eigen/Eigen> - -//#include "khach1.h" -//#include "mcpoint1.h" -#include "mcpoint.h" -//#include "bnmin_main1.h" -//#include "bnmin_main2.h" - -//#include "../bnmin_main.hxx" - -//namespace Minim { - - template <class NT> - using MTT = Eigen::Matrix<NT, Eigen::Dynamic, Eigen::Dynamic>; - - template <class NT> - using VTT = Eigen::Matrix<NT, Eigen::Dynamic, 1>; - - struct KhachiyanEllipsoid - { - Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> Q; - Eigen::Matrix<double, Eigen::Dynamic, 1> c; - }; - - template<typename Derived> - inline bool is_nan(const Eigen::MatrixBase<Derived>& x) - { - return ((x.array() == x.array())).all(); - } - - template<class T> - bool InvertMatrix(const MTT<T> &input, - MTT<T> &inverse) - { - inverse = input.inverse(); - return !is_nan(inverse); - } - - - inline void InvertLP(const MTT<double> &Lambdap, - MTT<double> &LpInv) - { - bool res = InvertMatrix(Lambdap, LpInv); - if (not res) - { - // throw an error of your choice here! - // throw MatrixErr("Could not invert matrix: ", - // Lambdap); - } - } - - inline void Lift(const MTT<double> &A, MTT<double> &Ap) - { - Ap.resize(A.rows()+1, A.cols()); - Ap.topLeftCorner(A.rows(), A.cols()) = A; - Ap.row(Ap.rows()-1).setConstant(1.0); - } - - inline void genDiag(const VTT<double> &p, MTT<double> &res) - { - res.setZero(p.size(), p.size()); - - for(size_t i=0; i<p.size(); ++i) - { - res(i,i)=p(i); - } - } - - inline void KaLambda(const MTT<double> &Ap, - const VTT<double> &p, - MTT<double> &Lambdap) - { - - MTT<double> dp(p.size(), p.size()); - genDiag(p, dp); - - dp = dp * Ap.transpose(); - Lambdap.noalias() = Ap * dp; - } - - inline double KhachiyanIter(const MTT<double> &Ap, VTT<double> &p) - { - /// Dimensionality of the problem - const size_t d = Ap.rows()-1; - - MTT<double> Lp; - MTT<double> M; - KaLambda(Ap, p, Lp); - MTT<double> ILp(Lp.rows(), Lp.cols()); - InvertLP(Lp, ILp); - M.noalias() = ILp * Ap; - M = Ap.transpose() * M; - - double maxval=0; - size_t maxi=0; - for(size_t i=0; i<M.rows(); ++i) - { - if (M(i,i) > maxval) - { - maxval=M(i,i); - maxi=i; - } - } - const double step_size=(maxval -d - 1)/((d+1)*(maxval-1)); - VTT<double> newp = p*(1-step_size); - newp(maxi) += step_size; - - const double err= (newp-p).norm(); - p = newp; - return err; - - } - - inline void KaInvertDual(const MTT<double> &A, - const VTT<double> &p, - MTT<double> &Q, - VTT<double> &c) - { - const size_t d = A.rows(); - MTT<double> dp(p.size(), p.size()); - genDiag(p, dp); - - MTT<double> PN; - PN.noalias() = dp * A.transpose(); - PN = A * PN; - - VTT<double> M2; - M2.noalias() = A * p; - - MTT<double> M3; - M3.noalias() = M2 * M2.transpose(); - - MTT<double> invert(PN.rows(), PN.cols()); - InvertLP(PN- M3, invert); - Q.noalias() = (invert/d); - c.noalias() = A * p; - - } - - inline double KhachiyanAlgo(const MTT<double> &A, - double eps, - size_t maxiter, - MTT<double> &Q, - VTT<double> &c) - { - VTT<double> p(A.cols()); - p.setConstant(1.0/A.cols()); - - MTT<double> Ap; - Lift(A, Ap); - - double ceps=eps*2; - for (size_t i=0; i<maxiter && ceps>eps; ++i) - { - ceps=KhachiyanIter(Ap, p); - } - - KaInvertDual(A, p, Q, c); - - return ceps; - - - } - - inline double KhachiyanAlgo(const std::set<MCPoint> &ss, - double eps, - size_t maxiter, - KhachiyanEllipsoid &res) - { - const size_t d=ss.begin()->p.size(); - MTT<double> A(d, ss.size()); - - size_t j=0; - for (std::set<MCPoint>::const_iterator i=ss.begin(); - i != ss.end(); - ++i) - { - for(size_t k=0; k <d ;++k) - A(k,j)=i->p[k]; - ++j; - } - - MTT<double> Q(d,d); - VTT<double> c(d); - - const double ceps=KhachiyanAlgo(A, eps, maxiter, - Q, c); - res.Q=Q; - res.c=c; - return ceps; - } - -#endif - -//} diff --git a/src/external/minimum_ellipsoid/mcpoint.h b/src/external/minimum_ellipsoid/mcpoint.h deleted file mode 100644 index 0b9c7c5d..00000000 --- a/src/external/minimum_ellipsoid/mcpoint.h +++ /dev/null @@ -1,477 +0,0 @@ -// VolEsti (volume computation and sampling library) - -// Copyright (c) 2012-2018 Vissarion Fisikopoulos -// Copyright (c) 2018 Apostolos Chalkis - -// This file is converted from BNMin1 (https://www.mrao.cam.ac.uk/~bn204/oof/bnmin1.html) by Apostolos Chalkis - -// Original copyright notice: - -/** - Bojan Nikolic <bojan@bnikolic.co.uk> - Initial version 2009 - - This file is part of BNMin1 and is licensed under GNU General - Public License version 2 - - \file mcpoint.cxx -*/ -#ifndef MCPOINT_H -#define MCPOINT_H - -#include <vector> -#include <list> -#include <set> - -#include <cmath> -#include <algorithm> - -//exclude gsl library Apostolos Chalkis -//#include <gsl/gsl_math.h> -//#include <gsl/gsl_eigen.h> - -//#include "mcpoint1.h" -//#include "mcpoint2.h" -#include "bnmin_main.h" -//#include "bnmin_main2.h" - -//namespace Minim { - struct MCPoint - { - /// The actual parameters - std::vector<double> p; - /// Log-likelihood of this point - double ll; - /// A vector to store derived quantities at sample of the - /// distribution - std::vector<double> fval; - - /// Default constructor allowed, fill in the data later - MCPoint(void): - p(0), - ll(-9999), - fval(0) - { - } - - /** \Construct with supplied position vector - */ - MCPoint(const std::vector<double> &p): - p(p), - ll(-9999), - fval(0) - { - } - - /** \brief The parameter vector has n values - */ - MCPoint(size_t np): - p(np), - ll(-9999), - fval(0) - { - } - - MCPoint(const MCPoint &other): - p(other.p), - ll(other.ll), - fval(other.fval) - { - } - - MCPoint & operator=(const MCPoint &other) - { - p=other.p; - ll=other.ll; - fval=other.fval; - return *this; - } - - - }; - - inline bool operator< (const MCPoint &a, const MCPoint &b) - { - return a.ll < b.ll; - } - - struct WPPoint: - public MCPoint - { - /** \brief Weight factor - */ - double w; - - WPPoint(void): - w(0.0) - { - } - - WPPoint(const std::vector<double> &p, - double w): - MCPoint(p), - w(w) - { - } - - /** \brief Construct from MCPoint and a supplied weight - */ - WPPoint(const MCPoint &mp, - double w): - MCPoint(mp), - w(w) - { - } - - }; - - /* - MCPoint::MCPoint(void): - p(0), - ll(-9999), - fval(0) - { - } - - MCPoint::MCPoint(const std::vector<double> &p): - p(p), - ll(-9999), - fval(0) - { - } - - MCPoint::MCPoint(size_t np): - p(np), - ll(-9999), - fval(0) - { - } - - MCPoint::MCPoint(const MCPoint &other): - p(other.p), - ll(other.ll), - fval(other.fval) - { - } - - MCPoint &MCPoint::operator=(const MCPoint &other) - { - p=other.p; - ll=other.ll; - fval=other.fval; - return *this; - }*/ - - - inline void moment1(const std::list<WPPoint> &l, - std::vector<double > &res) - { - const size_t n=l.begin()->p.size(); - res=std::vector<double>(n, 0.0); - for(std::list<WPPoint>::const_iterator i=l.begin(); - i!= l.end(); - ++i) - { - for (size_t j=0; j<n; ++j) - { - res[j]+= (i->p[j] * i->w * exp(- i->ll)); - } - } - } - - inline void moment1(const std::list<WPPoint> &l, - double Z, - std::vector<double> &res) - { - moment1(l,res); - for(size_t j=0; j<res.size(); ++j) - res[j] /= Z; - } - - - inline void moment2(const std::list<WPPoint> &l, - const std::vector<double > &m1, - std::vector<double > &res) - { - const size_t n=m1.size(); - res=std::vector<double>(n, 0.0); - for(std::list<WPPoint>::const_iterator i=l.begin(); - i!= l.end(); - ++i) - { - for (size_t j=0; j<n; ++j) - { - res[j]+= ( pow(i->p[j]-m1[j],2.0) * i->w * exp(- i->ll)); - } - } - } - - inline void moment2(const std::list<WPPoint> &l, - const std::vector<double> &m1, - double Z, - std::vector<double> &res) - { - moment2(l, m1, res); - for(size_t j=0; j<res.size(); ++j) - res[j] /= Z; - } - - inline void moment1(const std::set<MCPoint> &s, - std::vector<double> &res) - { - const size_t n=s.begin()->p.size(); - res=std::vector<double>(n, 0.0); - - size_t N=0; - for(std::set<MCPoint>::const_iterator i=s.begin(); - i!= s.end(); - ++i) - { - if(i->p.size() != n) - { - throw NParsErr("moment1", n, i->p.size()); - } - for (size_t j=0; j<n; ++j) - { - res[j]+= (i->p[j]); - } - ++N; - } - - for(size_t j=0; j<res.size(); ++j) - { - res[j]/=N; - } - } - - inline void moment2(const std::set<MCPoint> &s, - const std::vector<double> &m1, - std::vector<double> &res) - { - const size_t n=m1.size(); - res=std::vector<double>(n, 0.0); - - size_t N=0; - for(std::set<MCPoint>::const_iterator i=s.begin(); - i!= s.end(); - ++i) - { - for (size_t j=0; j<n; ++j) - { - res[j]+= pow(i->p[j]-m1[j], 2); - } - ++N; - } - - for(size_t j=0; j<res.size(); ++j) - { - res[j]/=N; - } - } - - - inline void omoment2(const std::set<MCPoint> &s, - const std::vector<double > &m1, - std::vector<double > &res) - { - const size_t n=m1.size(); - res=std::vector<double>(n*n, 0.0); - - size_t N=0; - for(std::set<MCPoint>::const_iterator i=s.begin(); - i!= s.end(); - ++i) - { - for (size_t j=0; j<n; ++j) - { - for(size_t k=0; k<n; ++k) - { - res[j*n+k] += (i->p[j]-m1[j])*(i->p[k]-m1[k]); - } - } - ++N; - } - - for(size_t j=0; j<res.size(); ++j) - { - res[j]/=N; - } - - } - - inline void omoment2(const std::set<MCPoint> &s, - std::vector<double> &res) - { - std::vector<double> m1; - moment1(s, m1); - omoment2(s, m1, res); - } - - - inline void StdDev(const std::set<MCPoint> &s, - std::vector<double > &res) - { - std::vector<double> m1, m2; - moment1(s, m1); - moment2(s, m1, m2); - res.resize(m2.size()); - for(size_t j=0; j<res.size(); ++j) - { - res[j]=pow(m2[j],0.5); - } - } - - //exlude principalCV function. Not needed + exclude gsl lib. Apostolos Chalkis -/* void principalCV(const std::vector<double> &cv, - std::vector<double> &eigvals, - std::vector<double> &eigvects) - { - const size_t n=sqrt(cv.size()); - gsl_matrix_view m - = gsl_matrix_view_array (const_cast<double*>(&cv[0]), n, n); - - gsl_vector *eval = gsl_vector_alloc (n); - gsl_matrix *evec = gsl_matrix_alloc (n, n); - - gsl_eigen_symmv_workspace * w = - gsl_eigen_symmv_alloc (n); - - gsl_eigen_symmv (&m.matrix, - eval, - evec, - w); - - gsl_eigen_symmv_free (w); - - gsl_eigen_symmv_sort (eval, - evec, - GSL_EIGEN_SORT_ABS_ASC); - - eigvals.resize(n); - eigvects.resize(n*n); - for(size_t j=0; j<n; ++j) - { - eigvals[j]=gsl_vector_get (eval, j); - for(size_t i=0; i<n; ++i) - { - eigvects[j*n+i]= gsl_matrix_get(evec, i,j); - } - } - - gsl_vector_free (eval); - gsl_matrix_free (evec); - }*/ - - inline void postHist(const std::list<WPPoint> &l, - double Z, - const std::vector<double> &low, - const std::vector<double> &high, - size_t nbins, - std::vector<double> &res) - { - const size_t ndim=low.size(); - - //res.resize(pow(nbins, static_cast<size_t>(ndim))); - res.resize( static_cast<int>( pow(static_cast<long double>(nbins), static_cast<long double>(ndim)) ) ); - std::fill(res.begin(), res.end(), 0.0); - - - std::vector<double> deltas(ndim); - for(size_t i=0; i<ndim; ++i) - { - deltas[i]=(high[i]-low[i])/nbins; - } - - for(std::list<WPPoint>::const_iterator i=l.begin(); - i!= l.end(); - ++i) - { - bool inside=true; - size_t k=0; - for (size_t j=0; j<ndim; ++j) - { - int dimi = int((i->p[j]-low[j])/deltas[j]); - if (dimi >= 0 and dimi < (int)nbins) - { - k+= dimi * static_cast<int>( pow(static_cast<long double>(nbins), static_cast<long double>(ndim-j-1)) ); - } - else - { - inside=false; - } - } - if (inside) - { - res[k]+= i->w * exp(- i->ll); - } - } - } - - - inline void marginHist(const std::list<WPPoint> &l, - size_t pi, - double Z, - double low, - double high, - size_t nbins, - std::vector<double > &res) - { - res.resize(nbins); - std::fill(res.begin(), res.end(), - 0.0); - - const double d=(high-low)/nbins; - for(std::list<WPPoint>::const_iterator i=l.begin(); - i!= l.end(); - ++i) - { - int k=int((i->p[pi]-low)/d); - if (k > 0 and k < (int)nbins) - { - res[k]+= i->w * exp(- i->ll); - } - } - - for(size_t i=0; i<res.size(); ++i) - { - res[i]/=Z; - } - } - - inline void marginHist2D(const std::list<WPPoint> &l, - double Z, - size_t i, - double ilow, - double ihigh, - size_t j, - double jlow, - double jhigh, - size_t nbins, - std::vector<double> &res) - { - // Two dimensions only - res.resize( static_cast<int>( pow(static_cast<long double>(nbins), static_cast<long double>(2)) ) ); - std::fill(res.begin(), res.end(), - 0.0); - const double idelta=(ihigh-ilow)/nbins; - const double jdelta=(jhigh-jlow)/nbins; - - for(std::list<WPPoint>::const_iterator p=l.begin(); - p!= l.end(); - ++p) - { - - int dimi = int((p->p[i]-ilow)/idelta); - int dimj = int((p->p[j]-jlow)/jdelta); - - if (dimi >= 0 and dimi<((int)nbins) and dimj >= 0 and dimj < ((int)nbins)) - { - const size_t k= dimi*nbins + dimj; - res[k]+= p->w * exp(- p->ll); - } - - } - } -//} - -#endif diff --git a/src/include b/src/include deleted file mode 160000 index 5f9d5661..00000000 --- a/src/include +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5f9d5661fe4fa24ee818205fdbd700e3d41381eb diff --git a/src/external/lpsolve/build/lp_solve/Makefile b/src/lpsolve/build/lp_solve/Makefile similarity index 100% rename from src/external/lpsolve/build/lp_solve/Makefile rename to src/lpsolve/build/lp_solve/Makefile diff --git a/src/external/lpsolve/build/lp_solve/colamd.c b/src/lpsolve/build/lp_solve/colamd.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/colamd.c rename to src/lpsolve/build/lp_solve/colamd.c diff --git a/src/external/lpsolve/build/lp_solve/commonlib.c b/src/lpsolve/build/lp_solve/commonlib.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/commonlib.c rename to src/lpsolve/build/lp_solve/commonlib.c diff --git a/src/external/lpsolve/build/lp_solve/ini.c b/src/lpsolve/build/lp_solve/ini.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/ini.c rename to src/lpsolve/build/lp_solve/ini.c diff --git a/src/lpsolve/build/lp_solve/liblp_solve.a b/src/lpsolve/build/lp_solve/liblp_solve.a new file mode 100644 index 00000000..f60b49d5 Binary files /dev/null and b/src/lpsolve/build/lp_solve/liblp_solve.a differ diff --git a/src/external/lpsolve/build/lp_solve/lp_BFP1.c b/src/lpsolve/build/lp_solve/lp_BFP1.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_BFP1.c rename to src/lpsolve/build/lp_solve/lp_BFP1.c diff --git a/src/external/lpsolve/build/lp_solve/lp_BFP2.c b/src/lpsolve/build/lp_solve/lp_BFP2.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_BFP2.c rename to src/lpsolve/build/lp_solve/lp_BFP2.c diff --git a/src/external/lpsolve/build/lp_solve/lp_Hash.c b/src/lpsolve/build/lp_solve/lp_Hash.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_Hash.c rename to src/lpsolve/build/lp_solve/lp_Hash.c diff --git a/src/external/lpsolve/build/lp_solve/lp_LUSOL.c b/src/lpsolve/build/lp_solve/lp_LUSOL.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_LUSOL.c rename to src/lpsolve/build/lp_solve/lp_LUSOL.c diff --git a/src/external/lpsolve/build/lp_solve/lp_MDO.c b/src/lpsolve/build/lp_solve/lp_MDO.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_MDO.c rename to src/lpsolve/build/lp_solve/lp_MDO.c diff --git a/src/external/lpsolve/build/lp_solve/lp_MPS.c b/src/lpsolve/build/lp_solve/lp_MPS.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_MPS.c rename to src/lpsolve/build/lp_solve/lp_MPS.c diff --git a/src/external/lpsolve/build/lp_solve/lp_SOS.c b/src/lpsolve/build/lp_solve/lp_SOS.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_SOS.c rename to src/lpsolve/build/lp_solve/lp_SOS.c diff --git a/src/external/lpsolve/build/lp_solve/lp_crash.c b/src/lpsolve/build/lp_solve/lp_crash.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_crash.c rename to src/lpsolve/build/lp_solve/lp_crash.c diff --git a/src/external/lpsolve/build/lp_solve/lp_lib.c b/src/lpsolve/build/lp_solve/lp_lib.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_lib.c rename to src/lpsolve/build/lp_solve/lp_lib.c diff --git a/src/external/lpsolve/build/lp_solve/lp_matrix.c b/src/lpsolve/build/lp_solve/lp_matrix.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_matrix.c rename to src/lpsolve/build/lp_solve/lp_matrix.c diff --git a/src/external/lpsolve/build/lp_solve/lp_mipbb.c b/src/lpsolve/build/lp_solve/lp_mipbb.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_mipbb.c rename to src/lpsolve/build/lp_solve/lp_mipbb.c diff --git a/src/external/lpsolve/build/lp_solve/lp_params.c b/src/lpsolve/build/lp_solve/lp_params.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_params.c rename to src/lpsolve/build/lp_solve/lp_params.c diff --git a/src/external/lpsolve/build/lp_solve/lp_presolve.c b/src/lpsolve/build/lp_solve/lp_presolve.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_presolve.c rename to src/lpsolve/build/lp_solve/lp_presolve.c diff --git a/src/external/lpsolve/build/lp_solve/lp_price.c b/src/lpsolve/build/lp_solve/lp_price.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_price.c rename to src/lpsolve/build/lp_solve/lp_price.c diff --git a/src/external/lpsolve/build/lp_solve/lp_pricePSE.c b/src/lpsolve/build/lp_solve/lp_pricePSE.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_pricePSE.c rename to src/lpsolve/build/lp_solve/lp_pricePSE.c diff --git a/src/external/lpsolve/build/lp_solve/lp_report.c b/src/lpsolve/build/lp_solve/lp_report.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_report.c rename to src/lpsolve/build/lp_solve/lp_report.c diff --git a/src/external/lpsolve/build/lp_solve/lp_rlp.c b/src/lpsolve/build/lp_solve/lp_rlp.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_rlp.c rename to src/lpsolve/build/lp_solve/lp_rlp.c diff --git a/src/external/lpsolve/build/lp_solve/lp_scale.c b/src/lpsolve/build/lp_solve/lp_scale.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_scale.c rename to src/lpsolve/build/lp_solve/lp_scale.c diff --git a/src/external/lpsolve/build/lp_solve/lp_simplex.c b/src/lpsolve/build/lp_solve/lp_simplex.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_simplex.c rename to src/lpsolve/build/lp_solve/lp_simplex.c diff --git a/src/external/lpsolve/build/lp_solve/lp_utils.c b/src/lpsolve/build/lp_solve/lp_utils.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_utils.c rename to src/lpsolve/build/lp_solve/lp_utils.c diff --git a/src/external/lpsolve/build/lp_solve/lp_wlp.c b/src/lpsolve/build/lp_solve/lp_wlp.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lp_wlp.c rename to src/lpsolve/build/lp_solve/lp_wlp.c diff --git a/src/external/lpsolve/build/lp_solve/lusol.c b/src/lpsolve/build/lp_solve/lusol.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lusol.c rename to src/lpsolve/build/lp_solve/lusol.c diff --git a/src/external/lpsolve/build/lp_solve/lusol1.c b/src/lpsolve/build/lp_solve/lusol1.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lusol1.c rename to src/lpsolve/build/lp_solve/lusol1.c diff --git a/src/external/lpsolve/build/lp_solve/lusol2.c b/src/lpsolve/build/lp_solve/lusol2.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lusol2.c rename to src/lpsolve/build/lp_solve/lusol2.c diff --git a/src/external/lpsolve/build/lp_solve/lusol6a.c b/src/lpsolve/build/lp_solve/lusol6a.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lusol6a.c rename to src/lpsolve/build/lp_solve/lusol6a.c diff --git a/src/external/lpsolve/build/lp_solve/lusol6l0.c b/src/lpsolve/build/lp_solve/lusol6l0.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lusol6l0.c rename to src/lpsolve/build/lp_solve/lusol6l0.c diff --git a/src/external/lpsolve/build/lp_solve/lusol6u.c b/src/lpsolve/build/lp_solve/lusol6u.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lusol6u.c rename to src/lpsolve/build/lp_solve/lusol6u.c diff --git a/src/external/lpsolve/build/lp_solve/lusol7a.c b/src/lpsolve/build/lp_solve/lusol7a.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lusol7a.c rename to src/lpsolve/build/lp_solve/lusol7a.c diff --git a/src/external/lpsolve/build/lp_solve/lusol8a.c b/src/lpsolve/build/lp_solve/lusol8a.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/lusol8a.c rename to src/lpsolve/build/lp_solve/lusol8a.c diff --git a/src/external/lpsolve/build/lp_solve/mmio.c b/src/lpsolve/build/lp_solve/mmio.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/mmio.c rename to src/lpsolve/build/lp_solve/mmio.c diff --git a/src/external/lpsolve/build/lp_solve/myblas.c b/src/lpsolve/build/lp_solve/myblas.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/myblas.c rename to src/lpsolve/build/lp_solve/myblas.c diff --git a/src/external/lpsolve/build/lp_solve/yacc_read.c b/src/lpsolve/build/lp_solve/yacc_read.c similarity index 100% rename from src/external/lpsolve/build/lp_solve/yacc_read.c rename to src/lpsolve/build/lp_solve/yacc_read.c diff --git a/src/external/lpsolve/headers/include/RlpSolve.h b/src/lpsolve/headers/include/RlpSolve.h similarity index 100% rename from src/external/lpsolve/headers/include/RlpSolve.h rename to src/lpsolve/headers/include/RlpSolve.h diff --git a/src/external/lpsolve/headers/include/RlpSolveLink.h b/src/lpsolve/headers/include/RlpSolveLink.h similarity index 100% rename from src/external/lpsolve/headers/include/RlpSolveLink.h rename to src/lpsolve/headers/include/RlpSolveLink.h diff --git a/src/external/lpsolve/headers/include/colamd.h b/src/lpsolve/headers/include/colamd.h similarity index 100% rename from src/external/lpsolve/headers/include/colamd.h rename to src/lpsolve/headers/include/colamd.h diff --git a/src/external/lpsolve/headers/include/commonlib.h b/src/lpsolve/headers/include/commonlib.h similarity index 100% rename from src/external/lpsolve/headers/include/commonlib.h rename to src/lpsolve/headers/include/commonlib.h diff --git a/src/external/lpsolve/headers/include/ini.h b/src/lpsolve/headers/include/ini.h similarity index 100% rename from src/external/lpsolve/headers/include/ini.h rename to src/lpsolve/headers/include/ini.h diff --git a/src/external/lpsolve/headers/include/lp_BFP.h b/src/lpsolve/headers/include/lp_BFP.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_BFP.h rename to src/lpsolve/headers/include/lp_BFP.h diff --git a/src/external/lpsolve/headers/include/lp_Hash.h b/src/lpsolve/headers/include/lp_Hash.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_Hash.h rename to src/lpsolve/headers/include/lp_Hash.h diff --git a/src/external/lpsolve/headers/include/lp_LUSOL.h b/src/lpsolve/headers/include/lp_LUSOL.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_LUSOL.h rename to src/lpsolve/headers/include/lp_LUSOL.h diff --git a/src/external/lpsolve/headers/include/lp_MDO.h b/src/lpsolve/headers/include/lp_MDO.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_MDO.h rename to src/lpsolve/headers/include/lp_MDO.h diff --git a/src/external/lpsolve/headers/include/lp_MPS.h b/src/lpsolve/headers/include/lp_MPS.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_MPS.h rename to src/lpsolve/headers/include/lp_MPS.h diff --git a/src/external/lpsolve/headers/include/lp_SOS.h b/src/lpsolve/headers/include/lp_SOS.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_SOS.h rename to src/lpsolve/headers/include/lp_SOS.h diff --git a/src/external/lpsolve/headers/include/lp_bit.h b/src/lpsolve/headers/include/lp_bit.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_bit.h rename to src/lpsolve/headers/include/lp_bit.h diff --git a/src/external/lpsolve/headers/include/lp_crash.h b/src/lpsolve/headers/include/lp_crash.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_crash.h rename to src/lpsolve/headers/include/lp_crash.h diff --git a/src/external/lpsolve/headers/include/lp_lib.h b/src/lpsolve/headers/include/lp_lib.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_lib.h rename to src/lpsolve/headers/include/lp_lib.h diff --git a/src/external/lpsolve/headers/include/lp_matrix.h b/src/lpsolve/headers/include/lp_matrix.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_matrix.h rename to src/lpsolve/headers/include/lp_matrix.h diff --git a/src/external/lpsolve/headers/include/lp_mipbb.h b/src/lpsolve/headers/include/lp_mipbb.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_mipbb.h rename to src/lpsolve/headers/include/lp_mipbb.h diff --git a/src/external/lpsolve/headers/include/lp_presolve.h b/src/lpsolve/headers/include/lp_presolve.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_presolve.h rename to src/lpsolve/headers/include/lp_presolve.h diff --git a/src/external/lpsolve/headers/include/lp_price.h b/src/lpsolve/headers/include/lp_price.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_price.h rename to src/lpsolve/headers/include/lp_price.h diff --git a/src/external/lpsolve/headers/include/lp_pricePSE.h b/src/lpsolve/headers/include/lp_pricePSE.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_pricePSE.h rename to src/lpsolve/headers/include/lp_pricePSE.h diff --git a/src/external/lpsolve/headers/include/lp_report.h b/src/lpsolve/headers/include/lp_report.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_report.h rename to src/lpsolve/headers/include/lp_report.h diff --git a/src/external/lpsolve/headers/include/lp_rlp.h b/src/lpsolve/headers/include/lp_rlp.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_rlp.h rename to src/lpsolve/headers/include/lp_rlp.h diff --git a/src/external/lpsolve/headers/include/lp_scale.h b/src/lpsolve/headers/include/lp_scale.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_scale.h rename to src/lpsolve/headers/include/lp_scale.h diff --git a/src/external/lpsolve/headers/include/lp_simplex.h b/src/lpsolve/headers/include/lp_simplex.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_simplex.h rename to src/lpsolve/headers/include/lp_simplex.h diff --git a/src/external/lpsolve/headers/include/lp_types.h b/src/lpsolve/headers/include/lp_types.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_types.h rename to src/lpsolve/headers/include/lp_types.h diff --git a/src/external/lpsolve/headers/include/lp_utils.h b/src/lpsolve/headers/include/lp_utils.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_utils.h rename to src/lpsolve/headers/include/lp_utils.h diff --git a/src/external/lpsolve/headers/include/lp_wlp.h b/src/lpsolve/headers/include/lp_wlp.h similarity index 100% rename from src/external/lpsolve/headers/include/lp_wlp.h rename to src/lpsolve/headers/include/lp_wlp.h diff --git a/src/external/lpsolve/headers/include/lpkit.h b/src/lpsolve/headers/include/lpkit.h similarity index 100% rename from src/external/lpsolve/headers/include/lpkit.h rename to src/lpsolve/headers/include/lpkit.h diff --git a/src/external/lpsolve/headers/include/lusol.h b/src/lpsolve/headers/include/lusol.h similarity index 100% rename from src/external/lpsolve/headers/include/lusol.h rename to src/lpsolve/headers/include/lusol.h diff --git a/src/external/lpsolve/headers/include/mmio.h b/src/lpsolve/headers/include/mmio.h similarity index 100% rename from src/external/lpsolve/headers/include/mmio.h rename to src/lpsolve/headers/include/mmio.h diff --git a/src/external/lpsolve/headers/include/myblas.h b/src/lpsolve/headers/include/myblas.h similarity index 100% rename from src/external/lpsolve/headers/include/myblas.h rename to src/lpsolve/headers/include/myblas.h diff --git a/src/external/lpsolve/headers/include/yacc_read.h b/src/lpsolve/headers/include/yacc_read.h similarity index 100% rename from src/external/lpsolve/headers/include/yacc_read.h rename to src/lpsolve/headers/include/yacc_read.h diff --git a/src/external/lpsolve/headers/run_headers/colamd.h b/src/lpsolve/headers/run_headers/colamd.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/colamd.h rename to src/lpsolve/headers/run_headers/colamd.h diff --git a/src/external/lpsolve/headers/run_headers/commonlib.h b/src/lpsolve/headers/run_headers/commonlib.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/commonlib.h rename to src/lpsolve/headers/run_headers/commonlib.h diff --git a/src/external/lpsolve/headers/run_headers/declare.h b/src/lpsolve/headers/run_headers/declare.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/declare.h rename to src/lpsolve/headers/run_headers/declare.h diff --git a/src/external/lpsolve/headers/run_headers/fortify.h b/src/lpsolve/headers/run_headers/fortify.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/fortify.h rename to src/lpsolve/headers/run_headers/fortify.h diff --git a/src/external/lpsolve/headers/run_headers/hbio.h b/src/lpsolve/headers/run_headers/hbio.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/hbio.h rename to src/lpsolve/headers/run_headers/hbio.h diff --git a/src/external/lpsolve/headers/run_headers/ini.h b/src/lpsolve/headers/run_headers/ini.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/ini.h rename to src/lpsolve/headers/run_headers/ini.h diff --git a/src/external/lpsolve/headers/run_headers/lp_BFP.h b/src/lpsolve/headers/run_headers/lp_BFP.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_BFP.h rename to src/lpsolve/headers/run_headers/lp_BFP.h diff --git a/src/external/lpsolve/headers/run_headers/lp_BFP1.h b/src/lpsolve/headers/run_headers/lp_BFP1.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_BFP1.h rename to src/lpsolve/headers/run_headers/lp_BFP1.h diff --git a/src/external/lpsolve/headers/run_headers/lp_BFP2.h b/src/lpsolve/headers/run_headers/lp_BFP2.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_BFP2.h rename to src/lpsolve/headers/run_headers/lp_BFP2.h diff --git a/src/external/lpsolve/headers/run_headers/lp_Hash.c b/src/lpsolve/headers/run_headers/lp_Hash.c similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_Hash.c rename to src/lpsolve/headers/run_headers/lp_Hash.c diff --git a/src/external/lpsolve/headers/run_headers/lp_Hash.h b/src/lpsolve/headers/run_headers/lp_Hash.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_Hash.h rename to src/lpsolve/headers/run_headers/lp_Hash.h diff --git a/src/external/lpsolve/headers/run_headers/lp_LUSOL.h b/src/lpsolve/headers/run_headers/lp_LUSOL.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_LUSOL.h rename to src/lpsolve/headers/run_headers/lp_LUSOL.h diff --git a/src/external/lpsolve/headers/run_headers/lp_MDO.h b/src/lpsolve/headers/run_headers/lp_MDO.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_MDO.h rename to src/lpsolve/headers/run_headers/lp_MDO.h diff --git a/src/external/lpsolve/headers/run_headers/lp_MPS.h b/src/lpsolve/headers/run_headers/lp_MPS.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_MPS.h rename to src/lpsolve/headers/run_headers/lp_MPS.h diff --git a/src/external/lpsolve/headers/run_headers/lp_SOS.h b/src/lpsolve/headers/run_headers/lp_SOS.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_SOS.h rename to src/lpsolve/headers/run_headers/lp_SOS.h diff --git a/src/external/lpsolve/headers/run_headers/lp_crash.c b/src/lpsolve/headers/run_headers/lp_crash.c similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_crash.c rename to src/lpsolve/headers/run_headers/lp_crash.c diff --git a/src/external/lpsolve/headers/run_headers/lp_crash.h b/src/lpsolve/headers/run_headers/lp_crash.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_crash.h rename to src/lpsolve/headers/run_headers/lp_crash.h diff --git a/src/external/lpsolve/headers/run_headers/lp_explicit.h b/src/lpsolve/headers/run_headers/lp_explicit.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_explicit.h rename to src/lpsolve/headers/run_headers/lp_explicit.h diff --git a/src/external/lpsolve/headers/run_headers/lp_fortify.h b/src/lpsolve/headers/run_headers/lp_fortify.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_fortify.h rename to src/lpsolve/headers/run_headers/lp_fortify.h diff --git a/src/external/lpsolve/headers/run_headers/lp_lib.h b/src/lpsolve/headers/run_headers/lp_lib.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_lib.h rename to src/lpsolve/headers/run_headers/lp_lib.h diff --git a/src/external/lpsolve/headers/run_headers/lp_matrix.h b/src/lpsolve/headers/run_headers/lp_matrix.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_matrix.h rename to src/lpsolve/headers/run_headers/lp_matrix.h diff --git a/src/external/lpsolve/headers/run_headers/lp_mipbb.h b/src/lpsolve/headers/run_headers/lp_mipbb.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_mipbb.h rename to src/lpsolve/headers/run_headers/lp_mipbb.h diff --git a/src/external/lpsolve/headers/run_headers/lp_presolve.h b/src/lpsolve/headers/run_headers/lp_presolve.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_presolve.h rename to src/lpsolve/headers/run_headers/lp_presolve.h diff --git a/src/external/lpsolve/headers/run_headers/lp_price.h b/src/lpsolve/headers/run_headers/lp_price.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_price.h rename to src/lpsolve/headers/run_headers/lp_price.h diff --git a/src/external/lpsolve/headers/run_headers/lp_pricePSE.h b/src/lpsolve/headers/run_headers/lp_pricePSE.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_pricePSE.h rename to src/lpsolve/headers/run_headers/lp_pricePSE.h diff --git a/src/external/lpsolve/headers/run_headers/lp_report.h b/src/lpsolve/headers/run_headers/lp_report.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_report.h rename to src/lpsolve/headers/run_headers/lp_report.h diff --git a/src/external/lpsolve/headers/run_headers/lp_rlp.h b/src/lpsolve/headers/run_headers/lp_rlp.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_rlp.h rename to src/lpsolve/headers/run_headers/lp_rlp.h diff --git a/src/external/lpsolve/headers/run_headers/lp_scale.h b/src/lpsolve/headers/run_headers/lp_scale.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_scale.h rename to src/lpsolve/headers/run_headers/lp_scale.h diff --git a/src/external/lpsolve/headers/run_headers/lp_simplex.h b/src/lpsolve/headers/run_headers/lp_simplex.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_simplex.h rename to src/lpsolve/headers/run_headers/lp_simplex.h diff --git a/src/external/lpsolve/headers/run_headers/lp_types.h b/src/lpsolve/headers/run_headers/lp_types.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_types.h rename to src/lpsolve/headers/run_headers/lp_types.h diff --git a/src/external/lpsolve/headers/run_headers/lp_utils.h b/src/lpsolve/headers/run_headers/lp_utils.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_utils.h rename to src/lpsolve/headers/run_headers/lp_utils.h diff --git a/src/external/lpsolve/headers/run_headers/lp_wlp.h b/src/lpsolve/headers/run_headers/lp_wlp.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lp_wlp.h rename to src/lpsolve/headers/run_headers/lp_wlp.h diff --git a/src/external/lpsolve/headers/run_headers/lpkit.h b/src/lpsolve/headers/run_headers/lpkit.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lpkit.h rename to src/lpsolve/headers/run_headers/lpkit.h diff --git a/src/external/lpsolve/headers/run_headers/lpsolve.h b/src/lpsolve/headers/run_headers/lpsolve.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lpsolve.h rename to src/lpsolve/headers/run_headers/lpsolve.h diff --git a/src/external/lpsolve/headers/run_headers/lusol.h b/src/lpsolve/headers/run_headers/lusol.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusol.h rename to src/lpsolve/headers/run_headers/lusol.h diff --git a/src/external/lpsolve/headers/run_headers/lusol1.h b/src/lpsolve/headers/run_headers/lusol1.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusol1.h rename to src/lpsolve/headers/run_headers/lusol1.h diff --git a/src/external/lpsolve/headers/run_headers/lusol2.h b/src/lpsolve/headers/run_headers/lusol2.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusol2.h rename to src/lpsolve/headers/run_headers/lusol2.h diff --git a/src/external/lpsolve/headers/run_headers/lusol6a.h b/src/lpsolve/headers/run_headers/lusol6a.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusol6a.h rename to src/lpsolve/headers/run_headers/lusol6a.h diff --git a/src/external/lpsolve/headers/run_headers/lusol6l0.h b/src/lpsolve/headers/run_headers/lusol6l0.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusol6l0.h rename to src/lpsolve/headers/run_headers/lusol6l0.h diff --git a/src/external/lpsolve/headers/run_headers/lusol6u.h b/src/lpsolve/headers/run_headers/lusol6u.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusol6u.h rename to src/lpsolve/headers/run_headers/lusol6u.h diff --git a/src/external/lpsolve/headers/run_headers/lusol7a.h b/src/lpsolve/headers/run_headers/lusol7a.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusol7a.h rename to src/lpsolve/headers/run_headers/lusol7a.h diff --git a/src/external/lpsolve/headers/run_headers/lusol8a.h b/src/lpsolve/headers/run_headers/lusol8a.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusol8a.h rename to src/lpsolve/headers/run_headers/lusol8a.h diff --git a/src/external/lpsolve/headers/run_headers/lusolio.h b/src/lpsolve/headers/run_headers/lusolio.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/lusolio.h rename to src/lpsolve/headers/run_headers/lusolio.h diff --git a/src/external/lpsolve/headers/run_headers/mmio.h b/src/lpsolve/headers/run_headers/mmio.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/mmio.h rename to src/lpsolve/headers/run_headers/mmio.h diff --git a/src/external/lpsolve/headers/run_headers/myblas.h b/src/lpsolve/headers/run_headers/myblas.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/myblas.h rename to src/lpsolve/headers/run_headers/myblas.h diff --git a/src/external/lpsolve/headers/run_headers/sparselib.h b/src/lpsolve/headers/run_headers/sparselib.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/sparselib.h rename to src/lpsolve/headers/run_headers/sparselib.h diff --git a/src/external/lpsolve/headers/run_headers/ufortify.h b/src/lpsolve/headers/run_headers/ufortify.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/ufortify.h rename to src/lpsolve/headers/run_headers/ufortify.h diff --git a/src/external/lpsolve/headers/run_headers/yacc_read.h b/src/lpsolve/headers/run_headers/yacc_read.h similarity index 100% rename from src/external/lpsolve/headers/run_headers/yacc_read.h rename to src/lpsolve/headers/run_headers/yacc_read.h diff --git a/src/volesti b/src/volesti new file mode 160000 index 00000000..5bf9188f --- /dev/null +++ b/src/volesti @@ -0,0 +1 @@ +Subproject commit 5bf9188fb11fddab17de98fabc505e993216ca5f